This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: process attaching gdb to itself
On Mon, Sep 29, 2003 at 09:21:55AM -0400, Andrew Cagney wrote:
>
> >>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 :-(
> >
> >
> >Yes, I've known about this problem for a long time. We've [I, Roland,
>
> This explains something.
I beg your pardon?
> >a couple of other people I can't recall] talked about changing it and
> >decided that, really, the current behavior makes more sense.
>
> Not to me.
>
> GDB sends a message to the kernel asking for the process to stop. The
> kernel sends a message back indicating that the request has completed.
The kernel generates a message at each change of the program's state.
It isn't changing state; it was already stopped. This behavior allows
the debugger to determine if the program was stopped before attach; I
can easily picture a multi-threaded daemon design that leaves parts of
itself SIGSTOP'd and would get confused if unexpectedly wakened.
> >It's not at all hard to make GDB work in the current system anyway.
> >Just have to do it. It goes something like:
> > - attach
> > - wait4 WNOHANG, break if succeeds (optimistic, not necessary)
> > - check in /proc to make sure the process is in a stopped state
> > - If it was:
> > - wait4 WNOHANG
> > - If we get a status, then the process was running when we attached
> > - If no status is available then the process was stopped when
> > we attached
> > - If it wasn't:
> > - The process was running when we attached and hasn't stopped yet
> > - wait4 without WNOHANG
>
> I feel ill. What happens, for instance, if /proc isn't there?
At this point in its life, Linux can just assume the /proc filesystem
is available. Linus has repeatedly refused to duplicate information
available via /proc through another interface.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer