Bug 8153 - attach impossible on Cygwin if main thread exits
Summary: attach impossible on Cygwin if main thread exits
Status: CLOSED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: threads (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-02-11 23:48 UTC by Brian Ford
Modified: 2024-04-13 23:05 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Ford 2003-02-11 23:48:00 UTC
[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;
}
Comment 1 Brian Ford 2003-02-11 23:48:00 UTC
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.
Comment 2 Christopher G. Faylor 2003-02-21 09:13:33 UTC
Responsible-Changed-From-To: unassigned->cgf
Responsible-Changed-Why: assign to myself
Comment 3 Christopher G. Faylor 2003-12-26 04:29:22 UTC
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
 
Comment 4 Christopher G. Faylor 2003-12-26 11:30:28 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Windows brain dead behavior.
Comment 5 Christopher G. Faylor 2003-12-26 11:40:36 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: See patches.
Comment 6 Sourceware Commits 2024-04-12 17:45:18 UTC
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