From: Pedro Alves <palves@redhat.com>
To: Simon Marchi <simon.marchi@ericsson.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 4/5] Linux: Skip thread_db thread event reporting if PTRACE_EVENT_CLONE is supported
Date: Wed, 17 Dec 2014 13:04:00 -0000 [thread overview]
Message-ID: <54917F5F.3020005@redhat.com> (raw)
In-Reply-To: <5490A306.3060002@ericsson.com>
On 12/16/2014 09:24 PM, Simon Marchi wrote:
>> Before PTRACE_EVENT_CLONE (Linux 2.6), the only way to learn about new
>> threads in the inferior (to attach to them) or to learn about thread
>> exit was to coordinate with the inferior's glibc/runtime, using
>> libthread_db. That works by putting a breakpoint at a magic address
>> which is called when a new thread is spawned, or when a thread is
>> about to exit. When that breakpoint is hit, all threads are stopped,
>> and then GDB coordinates with libthread_db to read data structures out
>> of the inferior to learn about what happened.
>
> That is libthread_db's TD_CREATE event? Could you point out where that is
> done (stopping all the threads)?
When we're using libthread_db, the linux-thread-db.c target is pushed on
top of the target stack. So a target_wait call ends up in
linux-thread-db.c:thread_db_wait:
static ptid_t
thread_db_wait (struct target_ops *ops,
ptid_t ptid, struct target_waitstatus *ourstatus,
int options)
{
...
ptid = beneath->to_wait (beneath, ptid, ourstatus, options);
...
if (ourstatus->kind == TARGET_WAITKIND_STOPPED
&& ourstatus->value.sig == GDB_SIGNAL_TRAP)
/* Check for a thread event. */
check_event (ptid);
...
return ptid;
}
and the beneath->to_wait call ends up in linux_nat_wait -- _that_ is
what stops all threads just before returning to thread_db_wait.
> From the previous discussion with you, I
> was thinking that those breakpoints did not affect execution. I don't find
> any code in linux-thread-db.c that would do such a thing.
I think you're thinking of https://sourceware.org/ml/gdb-patches/2014-12/msg00210.html
What I was saying is that although the TD_DEATH event results in all
threads stopping and then gdb core resuming the target, it's not when the
TD_DEATH event breakpoint is hit that we call delete_thread, so that's
not when mi_thread_exit ends up called. Instead, after TD_DEATH, the
thread that is exiting actually still exists and is resumed (it still has
a few instructions to run inside glibc/pthread before actually calling
the exit syscall), and then later when the thread actually does the exit
syscall, waitpid returns an WIFEXITED status for it, and gdb _then_ calls
delete_thread, all within linux-nat.c, without stopping all threads.
>> This is exactly the same behavior as when debugging against remote
>> targets / gdbserver. I actually think that's a good thing (and as
>> such have listed this in the local/remote parity wiki page a while
>> ago), as the printing slows down the inferior. It's also a
>> distraction to keep bothering the user about short-lived threads that
>> she won't be able to interact with anyway. Instead, the user (and
>> frontend) will be informed about new threads that currently exist in
>> the program when the program next stops:
>
> Is this a consequence of the change of algorithm, or did you actively changed
> the behavior?
Both. :-) I made GDB do an implicit "info threads" just before
presenting a user-visible stop to the user a while ago. See the
update_thread_list call in normal_stop, added in git b57bacecd5 -- see
also references to local/remote parity in that commit's log.
And it's a consequence in that stopping linux-thread-db.c from calling
add_thread results in that update_thread_list call finding new and dead
threads then.
> From what I understand, gdb still attaches to the new thread as soon as it spawns
> (when it receives the PTRACE_EVENT_CLONE event),
Close, with PTRACE_EVENT_CLONE, gdb is automatically attached to the
new clone; the kernel does that for us.
> so it could print the notice when the event happens.
Right, see the code in linux_handle_extended_wait that does that,
in non-stop mode, only. I'd like to remove that bit soon enough
though. I've mentioned before that I regret having added it.
> Not that I mind, but I just want to understand.
Hope I made things a little clearer.
Thanks,
Pedro Alves
next prev parent reply other threads:[~2014-12-17 13:04 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-16 16:54 [PATCH 0/5] GNU/Linux, fix attach races/problems Pedro Alves
2014-12-16 16:54 ` [PATCH 3/5] libthread_db: Skip attaching to terminated and joined threads Pedro Alves
2014-12-16 16:54 ` [PATCH 4/5] Linux: Skip thread_db thread event reporting if PTRACE_EVENT_CLONE is supported Pedro Alves
2014-12-16 21:24 ` Simon Marchi
2014-12-17 13:04 ` Pedro Alves [this message]
2014-12-16 16:54 ` [PATCH 2/5] Linux: on attach, attach to lwps listed under /proc/$pid/task/ Pedro Alves
2014-12-16 20:52 ` Simon Marchi
2014-12-17 13:35 ` Pedro Alves
2014-12-16 16:54 ` [PATCH 1/5] libthread_db: debug output should go to gdb_stdlog Pedro Alves
2014-12-17 8:02 ` Yao Qi
2014-12-17 13:45 ` Pedro Alves
2014-12-17 14:09 ` Yao Qi
2014-12-16 17:35 ` [PATCH 5/5] Test attaching to a program that constantly spawns short-lived threads Pedro Alves
2014-12-17 11:10 ` Yao Qi
2014-12-18 0:02 ` Pedro Alves
2015-01-05 19:02 ` Breazeal, Don
2015-01-07 16:17 ` [PATCH] skip "attach" tests when testing against stub-like targets (was: Re: [PATCH 5/5] Test attaching to a program that constantly spawns short-lived threads) Pedro Alves
2015-01-09 11:24 ` [PATCH] skip "attach" tests when testing against stub-like targets Pedro Alves
2015-01-12 4:43 ` [regression/native-gdbserver][buildbot] Python testscases get staled (was: Re: [PATCH] skip "attach" tests when testing against stub-like targets) Sergio Durigan Junior
2015-01-12 11:15 ` [regression/native-gdbserver][buildbot] Python testscases get staled Pedro Alves
2015-01-12 16:55 ` Sergio Durigan Junior
2015-01-12 17:01 ` Pedro Alves
2015-01-12 17:13 ` [PATCH] gdb.python/py-prompt.exp: restore GDBFLAGS Pedro Alves
2015-01-09 12:03 ` [PATCH 0/5] GNU/Linux, fix attach races/problems Pedro Alves
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=54917F5F.3020005@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@ericsson.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