Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@codesourcery.com>
To: gdb-patches@sourceware.org
Cc: Mark Kettenis <mark.kettenis@xs4all.nl>,
	 drow@false.org,  nickrob@snap.net.nz,
	 vladimir@codesourcery.com
Subject: Re: [RFA] Report the main thread.
Date: Mon, 28 Apr 2008 03:31:00 -0000	[thread overview]
Message-ID: <200804271925.18032.pedro@codesourcery.com> (raw)
In-Reply-To: <200804271547.m3RFlgfc014771@brahms.sibelius.xs4all.nl>

A Sunday 27 April 2008 16:47:42, Mark Kettenis wrote:
> > From: Pedro Alves <pedro@codesourcery.com>
> > Date: Sun, 27 Apr 2008 16:03:27 +0100
> >
> > A Sunday 27 April 2008 15:22:59, Mark Kettenis wrote:
> > > Seriously though, in GDB we've always only populated the threads list
> > > if a program actually has threads.
> >
> > Would that be true if threads had been implemented in GDB from the
> > ground up, instead of being an afterthought?
>
> Hard to tell.  But things like the application thread ID are simply
> not defined for programs that are not linked with a threads library.
>

True, but we're talking about a GDB thread id, which is made by GDB, not
by the thread library.  It is on the same arbitrary level as the
thread library coming up with a thread id for the "main thread" in
a MT app.

> Not showing anything in response to the "info threads" command for
> non-threaded applications has been quite a conscious decision.  We
> don't want to confront users with the complication of threads if they
> don't need it.
>

I don't know what complication is this.

> We do populate the threads lists for multi-threaded applications that
> have only one thread running.
>

Exactly, and that is confusing, and unconsistent.  The main thread is
not pthread_create'd (or equivalent), yet it is listed as a thread.

> > > An MI client will have to deal
> > > with that fact.  If it insists on providing a threaded view of the
> > > world, it needs to fake up a main thread.  Since it already has to do
> > > that for non-threaded programs, why would having a false thread create
> > > event for the main thread help?
> >
> > If a command is defined to take --thread=$gdb_thread_id as a parameter,
> > it is awkward for the frontend to have to do something different
> > on single-threaded apps.  E.g., no --thread parameter means all
> > threads, or the main thread in ST apps?
>
> Well, there is no main thread in a non-threaded application; it isn't
> threaded, you can't ask the program for some sort of thread ID.
>

I can ask GDB because GDB is providing an abstraction.

> Specifying a --thread parameter for such applications doesn't make
> sense, because issuing such a command means that the front-end (and
> probably the user) thinks the application is multi-threaded when it
> really isn't.  I would consider it completely reasonable for gdb to
> warn about this.
>
> > A GDB thread id is also what can be made constant even though
> > the ptid of the main thread may change due to loading
> > thread support.
>

> Well, the GDB thread IDs depend on the order in which the threads are
> created.  

That is new to me, and seems to be depending on a thread library
implementation detail.  What if the thread library doesn't report
the main thread first when GDB queries the thread list?

> I suppose GDB will always see the main thread of a threaded 
> applicatication first if you start it from GDB, but what if you attach
> GDB to an existing process?  The main thread at that point might not
> even exist anymore.

When we attach to a ST app, we'll add the thread that
had the stop event to the thread list -- that will be always the
"main thread" by definition.  If we're attaching to a MT app, the
thread that got the event will still exist, of course, otherwise
it wouldn't report the event, so we can add it.  Then we query the
thread library for the rest of the threads -- we never add a ptid
to the thread list if it is already listed.  If the main thread is
gone, then it  won't be the thread that reports the SIGSTOP, and
it won't the returned by the thread library.

-- 
Pedro Alves


  reply	other threads:[~2008-04-27 18:25 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-26 16:44 Vladimir Prus
2008-04-26 17:16 ` Mark Kettenis
2008-04-26 17:22   ` Daniel Jacobowitz
2008-04-26 17:31   ` Vladimir Prus
2008-04-26 21:05     ` Daniel Jacobowitz
2008-04-26 22:36       ` Vladimir Prus
2008-04-27  4:27         ` Nick Roberts
2008-04-27  9:03           ` Vladimir Prus
2008-04-27 11:14           ` Daniel Jacobowitz
2008-04-27 14:24             ` Nick Roberts
2008-04-27 13:53               ` Nick Roberts
2008-04-27 15:50               ` Daniel Jacobowitz
2008-04-27 16:07                 ` Mark Kettenis
2008-04-27 16:07                   ` Pedro Alves
2008-04-27 21:46                     ` Mark Kettenis
2008-04-28  3:31                       ` Pedro Alves [this message]
2008-04-27 18:25                   ` Daniel Jacobowitz
2008-04-30 10:11         ` Vladimir Prus
2008-04-30 13:28           ` Daniel Jacobowitz
2008-05-10 18:00 Nick Roberts
2008-05-10 19:26 ` Vladimir Prus
2008-05-11 14:10   ` Nick Roberts
2008-05-11 14:45     ` Vladimir Prus
2008-05-11 15:52       ` Nick Roberts
2008-05-11 16:00         ` Vladimir Prus
2008-05-11 16:13           ` Nick Roberts
2008-05-11 16:41             ` Vladimir Prus
2008-05-11 22:19               ` Nick Roberts
2008-05-12 22:22         ` Michael Snyder
2008-05-11 20:19       ` Joel Brobecker
2008-05-11 21:10         ` Vladimir Prus
2008-05-11 22:33         ` Nick Roberts
2008-05-12  3:18           ` Daniel Jacobowitz
2008-05-12 16:11             ` Nick Roberts
2008-05-12 18:19               ` Daniel Jacobowitz
2008-05-10 19:42 ` Vladimir Prus
2008-05-10 22:12 ` Joel Brobecker
2008-05-11 14:29   ` Nick Roberts

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200804271925.18032.pedro@codesourcery.com \
    --to=pedro@codesourcery.com \
    --cc=drow@false.org \
    --cc=gdb-patches@sourceware.org \
    --cc=mark.kettenis@xs4all.nl \
    --cc=nickrob@snap.net.nz \
    --cc=vladimir@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox