Index: linux-nat.c =================================================================== RCS file: /cvs/src/src/gdb/linux-nat.c,v retrieving revision 1.151 diff -u -p -u -r1.151 linux-nat.c --- linux-nat.c 9 Oct 2009 01:57:12 -0000 1.151 +++ linux-nat.c 14 Oct 2009 18:06:26 -0000 @@ -1289,14 +1289,13 @@ pid_is_stopped (pid_t pid) } /* Wait for the LWP specified by LP, which we have just attached to. - Returns a wait status for that LWP, to cache. */ + Returns 1 if LWP has been stopped, else 0. */ static int -linux_nat_post_attach_wait (ptid_t ptid, int first, int *cloned, - int *signalled) +linux_nat_post_attach_wait (ptid_t ptid, int first, int *status, + int *cloned, int *signalled) { pid_t new_pid, pid = GET_LWP (ptid); - int status; if (pid_is_stopped (pid)) { @@ -1327,29 +1326,38 @@ linux_nat_post_attach_wait (ptid_t ptid, /* Make sure the initial process is stopped. The user-level threads layer might want to poke around in the inferior, and that won't work if things haven't stabilized yet. */ - new_pid = my_waitpid (pid, &status, 0); + new_pid = my_waitpid (pid, status, 0); if (new_pid == -1 && errno == ECHILD) { if (first) warning (_("%s is a cloned process"), target_pid_to_str (ptid)); /* Try again with __WCLONE to check cloned processes. */ - new_pid = my_waitpid (pid, &status, __WCLONE); + new_pid = my_waitpid (pid, status, __WCLONE); *cloned = 1; } - gdb_assert (pid == new_pid && WIFSTOPPED (status)); + gdb_assert (pid == new_pid); - if (WSTOPSIG (status) != SIGSTOP) + if (!WIFSTOPPED (*status)) + { + /* The pid we tried to attach has apparently just exited. */ + if (debug_linux_nat) + fprintf_unfiltered (gdb_stdlog, "LNPAW: Failed to stop %d: %s", + pid, status_to_str (*status)); + return 0; + } + + if (WSTOPSIG (*status) != SIGSTOP) { *signalled = 1; if (debug_linux_nat) fprintf_unfiltered (gdb_stdlog, "LNPAW: Received %s after attaching\n", - status_to_str (status)); + status_to_str (*status)); } - return status; + return 1; } /* Attach to the LWP specified by PID. Return 0 if successful or -1 @@ -1395,7 +1403,9 @@ lin_lwp_attach_lwp (ptid_t ptid) "LLAL: PTRACE_ATTACH %s, 0, 0 (OK)\n", target_pid_to_str (ptid)); - status = linux_nat_post_attach_wait (ptid, 0, &cloned, &signalled); + if (!linux_nat_post_attach_wait (ptid, 0, &status, &cloned, &signalled)) + return -1; + lp = add_lwp (ptid); lp->stopped = 1; lp->cloned = cloned; @@ -1493,8 +1503,13 @@ linux_nat_attach (struct target_ops *ops /* Add the initial process as the first LWP to the list. */ lp = add_lwp (ptid); - status = linux_nat_post_attach_wait (lp->ptid, 1, &lp->cloned, - &lp->signalled); + if (!linux_nat_post_attach_wait (lp->ptid, 1, &status, &lp->cloned, + &lp->signalled)) + { + store_waitstatus (&lp->waitstatus, status); + return; + } + lp->stopped = 1; /* Save the wait status to report later. */