This is the mail archive of the
mailing list for the GDB project.
Re: process attaching gdb to itself
- From: Andrew Cagney <ac131313 at redhat dot com>
- To: Michael Elizabeth Chastain <mec at shout dot net>,aurelien dot chanudet at enst dot fr
- Cc: gdb at sources dot redhat dot com
- Date: Sun, 28 Sep 2003 18:35:24 -0400
- Subject: Re: process attaching gdb to itself
- References: <200309282225.h8SMP9Rf026649@duracef.shout.net>
char cmd ;
sprintf (cmd, "gdb attach %d", getpid ());
'system' waits for the program that it calls to finish.
Thus, your program is waiting for gdb to finish before it
Try the appended program which uses raw fork/exec.
It works for me on red hat linux 8, native i686-pc-linux-gnu.
If you try to do this in production code then you are likely
to run into a blizzard of race conditions, error cases,
and signal handling problems. If you are doing this as a learning
experience, that's great -- read up on 'man fork' and
'man execlp', and check out a book on Linux systems programming.
Is the kernel Linux? JeffJ and I just discovered that:
$ sleep 1000
PID 1234 suspended
$ gdb sleep 1234
works on BSD but fails on GNU/Linux. When doing an attach, BSD always
generates something for wait4 to consume. GNU/Linux does not, leaving
GDB stuck in wait4 :-(