PR threads/18600: Threads left stopped after fork+thread spawn
authorPedro Alves <palves@redhat.com>
Thu, 30 Jul 2015 17:50:29 +0000 (18:50 +0100)
committerPedro Alves <palves@redhat.com>
Thu, 30 Jul 2015 17:50:29 +0000 (18:50 +0100)
commit4dd63d488a76482543517c4c4cde699ee6fa33ef
tree64654e97e7cfdb2a4816a4e333fd41cdc7fecdad
parent6b940e6a063ac13372b44a03a54b6be33d22a183
PR threads/18600: Threads left stopped after fork+thread spawn

When a program forks and another process start threads while gdb is
handling the fork event, newly created threads are left stuck stopped
by gdb, even though gdb presents them as "running", to the user.

This can be seen with the test added by this patch.  The test has the
inferior fork a certain number of times and waits for all children to
exit.  Each fork child spawns a number of threads that do nothing and
joins them immediately.  Normally, the program should run unimpeded
(from the point of view of the user) and exit very quickly.  Without
this fix, it doesn't because of some threads left stopped by gdb, so
inferior 1 never exits.

The program triggers when a new clone thread is found while inside the
linux_stop_and_wait_all_lwps call in linux-thread-db.c:

      linux_stop_and_wait_all_lwps ();

      ALL_LWPS (lp)
if (ptid_get_pid (lp->ptid) == pid)
  thread_from_lwp (lp->ptid);

      linux_unstop_all_lwps ();

Within linux_stop_and_wait_all_lwps, we reach
linux_handle_extended_wait with the "stopping" parameter set to 1, and
because of that we don't mark the new lwp as resumed.  As consequence,
the subsequent resume_stopped_resumed_lwps, called from
linux_unstop_all_lwps, never resumes the new LWP.

There's lots of cruft in linux_handle_extended_wait that no longer
makes sense.  On systems with CLONE events support, we don't rely on
libthread_db for thread listing anymore, so the code that preserves
stop_requested and the handling of last_resume_kind is all dead.

So the fix is to remove all that, and simply always mark the new LWP
as resumed, so that resume_stopped_resumed_lwps re-resumes it.

gdb/ChangeLog:
2015-07-30  Pedro Alves  <palves@redhat.com>
    Simon Marchi  <simon.marchi@ericsson.com>

PR threads/18600
* linux-nat.c (linux_handle_extended_wait): On CLONE event, always
mark the new thread as resumed.  Remove STOPPING parameter.
(wait_lwp): Adjust call to linux_handle_extended_wait.
(linux_nat_filter_event): Adjust call to
linux_handle_extended_wait.
(resume_stopped_resumed_lwps): Add debug output.

gdb/testsuite/ChangeLog:
2015-07-30  Simon Marchi  <simon.marchi@ericsson.com>
    Pedro Alves  <palves@redhat.com>

PR threads/18600
* gdb.threads/fork-plus-threads.c: New file.
* gdb.threads/fork-plus-threads.exp: New file.
gdb/ChangeLog
gdb/linux-nat.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.threads/fork-plus-threads.c [new file with mode: 0644]
gdb/testsuite/gdb.threads/fork-plus-threads.exp [new file with mode: 0644]
This page took 0.026555 seconds and 4 git commands to generate.