This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Fix threads vs. fork following


Daniel Jacobowitz wrote:
On Mon, Mar 22, 2004 at 12:12:18PM -0500, Daniel Jacobowitz wrote:

On Thu, Mar 11, 2004 at 01:08:40AM +0000, Michael Snyder wrote:

Hey Daniel,

Got a question concerning the code in linux-nat.c::linux_handle_extended_wait.

You've got a PTRACE_EVENT_FORK event, and now you're going to call waitpid. You pull a pid out of a list of stopped pids, and wait for
it using waitpid. In your comment, you explain that you don't have to
worry about the pid being a clone, because you didn't ask for pids in
the event mask.


But how is this affected by threads, especially NPTL threads?
I've got a fairly simple test-case (modified from pthreads.c,
I'll attach it), in which a child thread calls fork -- but gdb
apparently tries to wait on the main thread (or perhaps the most
recent event thread).  Since that's not the thread that called
fork, waitpid returns -1 with "no child".  Gdb reports:
	waiting for new child: No child processes.

FWIW, I've tried this on both a single-processor and an SMP machine.


Here's what happened: I was using ptid_get_pid, which gave me the
_process_ ID rather than the _lwp_ ID.  I've committed this fix for
HEAD.  Should I fix this on the 6.1 branch also?


I don't see why not.


FYI, I've had feedback from one user who says this patch helped get
him past the point at which he was stuck before -- but he's seeing
a new problem which may or may not be related.  He has one thread
which calls system("/bin/ls"), and system ("cd <...>").  He can now
get past at least the first few such calls under GDB, but eventually
(and non-deterministically), he sees something like:

    Detaching after fork from child process 22087.
    ---Type <return> to continue, or q <return> to quit---

And then for some unknown percent of the times when the
above occurs, it goes more like this:

Detaching after fork from child process 21502.

    Suspended (tty output)
    [msnyder@reddwarf gdb]$ fg
    /export/msnyder/03r1-2/bin/gdb  ...
    ---Type <return> to continue, or q <return> to quit---
    Detaching after fork from child process 21510.

Any thoughts?



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]