From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 395 invoked by alias); 27 Feb 2014 14:31:43 -0000 Mailing-List: contact gdb-prs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-prs-owner@sourceware.org Received: (qmail 360 invoked by uid 55); 27 Feb 2014 14:31:43 -0000 From: "cvs-commit at gcc dot gnu.org" To: gdb-prs@sourceware.org Subject: [Bug gdb/12702] gdb can hang waiting for thread group leader Date: Thu, 27 Feb 2014 14:31:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: gdb X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-q1/txt/msg00306.txt.bz2 http://sourceware.org/bugzilla/show_bug.cgi?id=12702 --- Comment #9 from cvs-commit at gcc dot gnu.org --- This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "gdb and binutils". The branch, master has been updated via fa96cb382c12b099675c5cc238aaa7352a3fd3d7 (commit) via d632a0971cf9c8044e2b59da45ba6bbc27714c84 (commit) via 2ebd5a35208e40dab7df46c7d6d58f4d614c6e21 (commit) from 5063daf7357ccdc2c9e899ca0421c2e8e580c88d (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=fa96cb382c12b099675c5cc238aaa7352a3fd3d7 commit fa96cb382c12b099675c5cc238aaa7352a3fd3d7 Author: Pedro Alves Date: Thu Feb 27 14:30:08 2014 +0000 Teach GDBserver's Linux backend about no unwaited-for children (TARGET_WAITKIND_NO_RESUMED). GDBserver currently hangs forever in waitpid if the leader thread exits before other threads, or if all resumed threads exit - e.g., next over a thread exit with sched-locking on. This is exposed by leader-exit.exp. leader-exit.exp is part of a series of tests for a set of related problems. See : " To recap, on the Linux kernel, ptrace/waitpid don't allow reaping the leader thread until all other threads in the group are reaped. When the leader exits, it goes zombie, but waitpid will not return an exit status until the other threads are gone. This is presently exercised by the gdb.threads/leader-exit.exp test. The fix for that test, in linux-nat.c:wait_lwp, handles the case where we see the leader gone when we're stopping all threads to report an event to some other thread to the core. (...) The latter bit about not blocking if there no resumed threads in the process also applies to some other thread exiting, not just the main thread. E.g., this test starts a thread, and runs to a breakpoint in that thread: ... (gdb) c Continuing. [New Thread 0x7ffff75a4700 (LWP 23397)] [Switching to Thread 0x7ffff75a4700 (LWP 23397)] Breakpoint 2, thread_a (arg=0x0) at ../../../src/gdb/testsuite/gdb.threads/no-unwaited-for-left.c:28 28 return 0; /* break-here */ (gdb) info threads * 2 Thread 0x7ffff75a4700 (LWP 23397) thread_a (arg=0x0) at ../../../src/gdb/testsuite/gdb.threads/no-unwaited-for-left.c:28 1 Thread 0x7ffff7fcb720 (LWP 23391) 0x00007ffff7bc606d in pthread_join (threadid=140737343276800, thread_return=0x0) at pthread_join.c:89 The thread will exit as soon as we resume it. But if we only resume that thread, leaving the rest of the threads stopped: (gdb) set scheduler-locking on (gdb) c Continuing. ^C^C^C^C^C^C^C^C " This patch fixes the issues by implementing TARGET_WAITKIND_NO_RESUMED on GDBserver, similarly to what the patch above did for native Linux GDB. gdb.threads/leader-exit.exp now passes. gdb.threads/no-unwaited-for-left.exp now at least errors out instead of hanging: continue Continuing. warning: Remote failure reply: E.No unwaited-for children left. [Thread 15454] #1 stopped. 0x00000034cf408e60 in pthread_join (threadid=140737353922368, thread_return=0x0) at pthread_join.c:93 93 lll_wait_tid (pd->tid); (gdb) FAIL: gdb.threads/no-unwaited-for-left.exp: continue stops when the main thread exits The gdb.threads/non-ldr-exc-*.exp tests are skipped because GDBserver unfortunately doesn't support fork/exec yet, but I'm confident this fixes the related issues. I'm leaving modeling TARGET_WAITKIND_NO_RESUMED in the RSP for a separate pass. (BTW, in case of error in response to a vCont, it would be better for GDB to query the target for the current thread, or re-select one, instead of assuming current inferior_ptid is still the selected thread.) This implementation is a little different from GDB's, because I'm avoiding bringing in more of this broken use of waitpid(PID) into GDBserver. Specifically, this avoids waitpid(PID) when stopping all threads. There's really no need for wait_for_sigstop to wait for each LWP in turn. Instead, with some refactoring, we make it reuse linux_wait_for_event. gdb/gdbserver/ 2014-02-27 Pedro Alves PR 12702 * inferiors.h (A_I_NEXT, ALL_INFERIORS_TYPE, ALL_PROCESSES): New macros. * linux-low.c (delete_lwp, handle_extended_wait): Add debug output. (last_thread_of_process_p): Take a PID argument instead of a thread pointer. (linux_wait_for_lwp): Delete. (num_lwps, check_zombie_leaders, not_stopped_callback): New functions. (linux_low_filter_event): New function, party factored out from linux_wait_for_event. (linux_wait_for_event): Rename to ... (linux_wait_for_event_filtered): ... this. Add new filter ptid argument. Partly rewrite. Always use waitpid(-1, WNOHANG) and sigsuspend. Check for zombie leaders. (linux_wait_for_event): Reimplement as wrapper around linux_wait_for_event_filtered. (linux_wait_1): Handle TARGET_WAITKIND_NO_RESUMED. Assume that if a normal or signal exit is seen, it's the whole process exiting. (wait_for_sigstop): No longer a for_each_inferior callback. Rewrite on top of linux_wait_for_event_filtered. (stop_all_lwps): Call wait_for_sigstop directly. * server.c (resume, handle_target_event): Handle TARGET_WAITKIND_NO_RESUMED. https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d632a0971cf9c8044e2b59da45ba6bbc27714c84 commit d632a0971cf9c8044e2b59da45ba6bbc27714c84 Author: Pedro Alves Date: Thu Feb 27 14:30:08 2014 +0000 Move linux-nat.c:status_to_str to nat/linux-waitpid.c. So that gdbserver's Linux backend can use it too. gdb/ 2014-02-27 Pedro Alves PR 12702 * linux-nat.c (status_to_str): Moved to nat/linux-waitpid.c. * nat/linux-waitpid.c: Include string.h. (status_to_str): Moved here and made extern. * nat/linux-waitpid.h (status_to_str): New declaration. https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2ebd5a35208e40dab7df46c7d6d58f4d614c6e21 commit 2ebd5a35208e40dab7df46c7d6d58f4d614c6e21 Author: Hui Zhu Date: Thu Feb 27 14:30:07 2014 +0000 Move ptid_match to common/ptid.c. So that gdbserver can use it too. gdb/ 2014-02-27 Hui Zhu PR 12702 * infrun.c (ptid_match): Move ... * common/ptid.c (ptid_match): ... here. * inferior.h (ptid_match): Move ... * common/ptid.h (ptid_match): ... here. ----------------------------------------------------------------------- Summary of changes: gdb/ChangeLog | 16 + gdb/common/ptid.c | 14 + gdb/common/ptid.h | 10 + gdb/gdbserver/ChangeLog | 28 ++ gdb/gdbserver/inferiors.h | 22 ++ gdb/gdbserver/linux-low.c | 852 ++++++++++++++++++++++++++------------------- gdb/gdbserver/server.c | 18 +- gdb/inferior.h | 10 - gdb/infrun.c | 14 - gdb/linux-nat.c | 25 -- gdb/nat/linux-waitpid.c | 28 ++ gdb/nat/linux-waitpid.h | 4 + 12 files changed, 640 insertions(+), 401 deletions(-) -- You are receiving this mail because: You are on the CC list for the bug.