Bug 24066 - gdb(1) can't detach from programs linked with libc_r
Summary: gdb(1) can't detach from programs linked with libc_r
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-01-04 09:00 UTC by mheffner
Modified: 2014-06-04 17:37 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mheffner 2001-01-04 09:00:01 UTC
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.

Fix: 

Don't know.
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.
Comment 1 Sheldon Hearn freebsd_committer freebsd_triage 2002-01-30 13:21:27 UTC
Responsible Changed
From-To: freebsd-bugs->mp

Over to maintainer.
Comment 2 kmacy 2002-02-10 00:57:29 UTC
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/
Comment 3 Marcel Moolenaar freebsd_committer freebsd_triage 2004-07-17 02:56:27 UTC
Responsible Changed
From-To: mp->marcel

Still has relevance with gdb6. Keep an eye on it...
Comment 4 Alexander Best freebsd_committer freebsd_triage 2010-11-18 20:44:11 UTC
State Changed
From-To: open->feedback

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.
Comment 5 Marcel Moolenaar freebsd_committer freebsd_triage 2011-02-21 18:49:06 UTC
Responsible Changed
From-To: marcel->freebsd-bugs

Assign back to the pool. I haven't been working on it and it's unlikely 
I will in the near future.
Comment 6 Eitan Adler freebsd_committer freebsd_triage 2012-11-13 20:49:23 UTC
State Changed
From-To: feedback->open

feedback is the wrong state
Comment 7 Baptiste Daroussin freebsd_committer freebsd_triage 2014-06-04 17:37:28 UTC
libc_r has gone long ago