From nobody@FreeBSD.org  Thu Jan  4 00:50:45 2001
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id 8754637B400
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  4 Jan 2001 00:50:45 -0800 (PST)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.1/8.11.1) id f048ojJ64795;
	Thu, 4 Jan 2001 00:50:45 -0800 (PST)
	(envelope-from nobody)
Message-Id: <200101040850.f048ojJ64795@freefall.freebsd.org>
Date: Thu, 4 Jan 2001 00:50:45 -0800 (PST)
From: mheffner@vt.edu
Sender: nobody@FreeBSD.org
To: freebsd-gnats-submit@FreeBSD.org
Subject: gdb can't detach from programs linked with libc_r
X-Send-Pr-Version: www-1.0

>Number:         24066
>Category:       bin
>Synopsis:       gdb(1) can't detach from programs linked with libc_r
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jan 04 01:00:01 PST 2001
>Closed-Date:    
>Last-Modified:  Tue Nov 13 20:49:24 UTC 2012
>Originator:     Mike Heffner
>Release:        5-current
>Organization:
>Environment:
5.0-CURRENT #0: Tue Jan  2 19:45:37 EST 2001 i386
>Description:
Gdb can't detach from a program that's linked with libc_r. It gives the
message "ptrace: No such process". The same program linked with libc
can be attached/detached fine. The only way to quit gdb is to kill
it.

By sprinkling the code with printf()s it looks like variable
`inferior_pid' (which is passed to ptrace() when detaching) is getting
changed. For example, it'll go from say 41694 -> 172766. I tracked
it down to a location in gnu/usr.bin/binutils/gdb/freebsd-uthread.c
line 429:
	inferior_pid = find_active_thread ();

Unfortunately, after that point it's over my head so I can't really
figure out where it's going wrong.
>How-To-Repeat:
Compile the following program:

main(){
	printf("pid: %d\n", getpid());
	while(1)
		sleep(1);
}

twice with:

gcc -o test1 test.c
gcc -o test2 test.c -pthread

and try attaching/detaching from it, the first one will succeed, the
second won't.
>Fix:
Don't know.

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->mp 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Wed Jan 30 05:21:27 PST 2002 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=24066 

From: Kip Macy <kmacy@netapp.com>
To: freebsd-gnats-submit@FreeBSD.org, mheffner@vt.edu
Cc: mp@FreeBSD.org
Subject: Re: bin/24066: gdb can't detach from programs linked with libc_r
Date: Sat, 9 Feb 2002 16:57:29 -0800 (PST)

 This is also trivial to fix. child_ops won't recognize the pid of thread, so it
 has to be set to default pid.
 
 diff -c /usr/src/gnu/usr.bin/binutils/gdb/freebsd-uthread.c.bak
 /usr/src/gnu/usr.bin/binutils/gdb/freebsd-uthread.c
 *** /usr/src/gnu/usr.bin/binutils/gdb/freebsd-uthread.c.bakSat Jan 12 16:35:14
 2002
 --- /usr/src/gnu/usr.bin/binutils/gdb/freebsd-uthread.c Sat Feb  9 16:56:54 2002
 ***************
 *** 452,457 ****
 --- 452,462 ----
        char *args;
        int from_tty;
   {
 +   struct cleanup *old_chain;
 +   old_chain = save_inferior_pid ();
 + 
 +   inferior_pid = main_pid;
 + 
     child_ops.to_detach (args, from_tty);
   }
   
 
 
 =========================================================================
 For RAIDANT status see: 
 http://cranford.eng.netapp.com:8015/ant3/index.cgi
 To submit RAIDANT test descriptions go to:
 http://web.netapp.com/engineering/projects/raidv2/testing/ 
 Ontap on the web:
 http://web.netapp.com/engineering/projects/raidv2/testing/global/ 
 
Responsible-Changed-From-To: mp->marcel 
Responsible-Changed-By: marcel 
Responsible-Changed-When: Sat Jul 17 01:56:27 GMT 2004 
Responsible-Changed-Why:  
Still has relevance with gdb6. Keep an eye on it... 

http://www.freebsd.org/cgi/query-pr.cgi?pr=24066 
State-Changed-From-To: open->feedback 
State-Changed-By: arundel 
State-Changed-When: Thu Nov 18 20:44:11 UTC 2010 
State-Changed-Why:  
Can somebody please verify or falsify, whether this issue still exists with 
libthread on recent FreeBSD versions? I was able to compile the example code, 
but when trying to attach to it via gdb i get this error: 

/usr/src/gnu/usr.bin/gdb/libgdb/../../../../contrib/gdb/gdb/solib-svr4.c:1444: internal-error: legacy_fetch_link_map_offsets called without legacy link_map support enabled. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=24066 
Responsible-Changed-From-To: marcel->freebsd-bugs 
Responsible-Changed-By: marcel 
Responsible-Changed-When: Mon Feb 21 18:49:06 UTC 2011 
Responsible-Changed-Why:  
Assign back to the pool. I haven't been working on it and it's unlikely 
I will in the near future.  

http://www.freebsd.org/cgi/query-pr.cgi?pr=24066 
State-Changed-From-To: feedback->open 
State-Changed-By: eadler 
State-Changed-When: Tue Nov 13 20:49:23 UTC 2012 
State-Changed-Why:  
feedback is the wrong state 

http://www.freebsd.org/cgi/query-pr.cgi?pr=24066 
>Unformatted:
