[Converted from Gnats 1048] gdb on Cygwin can not attach to a running process if the main thread has exited via a call to pthread_exit(). The attach just hangs. Release: GNU gdb all How-To-Repeat: Here is the test case: w/o GDB_HANG defined, all is well; with GDB_HANG defined, attaching is not possible. #include <pthread.h> #include <unistd.h> void * spinner(void *v) { for (;;) sleep(500); return NULL; } int main(void) { pthread_t tid; pthread_create(&tid, NULL, spinner, NULL); #ifdef GDB_HANG pthread_exit(NULL); #else for (;;) sleep(500); #endif return 0; }
Fix: I have checked in some fixes for other mainthread-exits problems where gdb crashes if the main thread exits while the process is running. However, I'm unable to duplicate this problem with any recent version of gdb.
Responsible-Changed-From-To: unassigned->cgf Responsible-Changed-Why: assign to myself
From: cgf@sources.redhat.com To: gdb-gnats@sourceware.org Cc: Subject: threads/1048 Date: 26 Dec 2003 04:29:22 -0000 CVSROOT: /cvs/uberbaum Module name: gdb Changes by: cgf@sourceware.org 2003-12-26 04:29:22 Modified files: . : ChangeLog win32-nat.c Log message: Fix for PR threads/1048 * win32-nat.c (thread_info_struct): Add reload_context flag. (thread_rec): Don't reload thread context here. Just set a flag. (do_child_fetch_inferior_registers): Reload thread context here if appropriate. Avoid doing anything if current_thread is NULL thanks to strange Windows behavior. (child_fetch_inferior_registers): Avoid doing anything if current_thread is NULL. (do_child_store_inferior_registers): Ditto. (child_store_inferior_registers): Ditto. (child_kill_inferior): Ditto. (fake_create_process): Pretend to create a process for pathological windows attach situation. (get_child_debug_event): Call fake_create_process when the first event noticed is thread creation rather than process creation. (child_attach): Always set attach_flag when attaching. (child_create_inferior): Set attach_flag to zero since we're not attaching. Patches: http://sources.redhat.com/cgi-bin/cvsweb.cgi/gdb/ChangeLog.diff?cvsroot=uberbaum&r1=1.5117&r2=1.5118 http://sources.redhat.com/cgi-bin/cvsweb.cgi/gdb/win32-nat.c.diff?cvsroot=uberbaum&r1=1.84&r2=1.85
State-Changed-From-To: open->analyzed State-Changed-Why: Windows brain dead behavior.
State-Changed-From-To: analyzed->closed State-Changed-Why: See patches.
The master branch has been updated by Pedro Alves <palves@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ec48903170926f3827144525b50ddd3c6ae3fbf0 commit ec48903170926f3827144525b50ddd3c6ae3fbf0 Author: Pedro Alves <pedro@palves.net> Date: Mon Mar 25 15:17:02 2024 +0000 New testcase gdb.threads/leader-exit-attach.exp (PR threads/8153) Add a new testcase for exercising attaching to a process after its main thread has exited. This is not possible on Linux, the kernel does not allow attaching to a zombie task, so the test is kfailed there. It is possible however on Windows at least, and was the scenario addressed by the Windows backend fix in https://sourceware.org/legacy-ml/gdb-patches/2003-12/msg00479.html, nowadays PR threads/8153, back in 2003. Passes cleanly on Cygwin. KFAILed on GNU/Linux native and gdbserver. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=8153 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31554 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31555 Change-Id: Ib554f92f68c965bb4603cdf2aadb55ca45ded53b