Re: [patch] Fix for internal-error: linux_nat_post_attach_wait: Assertion `pid == new_pid && WIFSTOPPED (status)' failed.

Paul Pluzhnikov
2009-10-14T21:01:18Z

[-- Attachment #1: Type: text/plain, Size: 1259 bytes --]

On Wed, Oct 14, 2009 at 12:07 PM, Pedro Alves <pedro@codesourcery.com> wrote:

> Ugh. Happened much more often for me, like 1 in 5...

It's racy. I've seen different frequency of problems depending on
whether I run kernel 2.6.24 or 2.6.30.

> I don't think you needed the interface change.

Indeed.

> Back to the "simple" variant: The inferior just added is
> always inferior_ptid/current_inferior(). If you look
> at fork-child.c:startup_inferior, you'll see bits of
> code doing exactly what you'd need to do. E.g.:
>
> target_terminal_ours ();
> target_mourn_inferior ();
> if (WIFEXITED (status))
> error (_("During startup program exited with code %d."),
> WIFEXITCODE (status));
> else if (WIFSIGNALED (status))
> error (_("During startup program exited with signal ..."),
> ...);

I don't see above code in fork-child.c (or anywhere else for that
matter). Are you looking at a local patch?

Anyway, here is try #3.

Thanks,
--
Paul Pluzhnikov

2009-10-14 Paul Pluzhnikov <ppluzhnikov@google.com>

* linux-nat.c (linux_nat_post_attach_wait): Adjust assert.
(lin_lwp_attach_lwp, linux_nat_attach): Handle disappearing LWP.

[-- Attachment #2: gdb-assert-10757-20091014-2.txt --]
[-- Type: text/plain, Size: 2106 bytes --]

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 20:41:46 -0000
@@ -1338,7 +1338,16 @@ linux_nat_post_attach_wait (ptid_t ptid,
*cloned = 1;
}

- gdb_assert (pid == new_pid && WIFSTOPPED (status));
+ gdb_assert (pid == new_pid);
+
+ 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 status;
+ }

if (WSTOPSIG (status) != SIGSTOP)
{
@@ -1396,6 +1405,9 @@ lin_lwp_attach_lwp (ptid_t ptid)
target_pid_to_str (ptid));

status = linux_nat_post_attach_wait (ptid, 0, &cloned, &signalled);
+ if (!WIFSTOPPED (status))
+ return -1;
+
lp = add_lwp (ptid);
lp->stopped = 1;
lp->cloned = cloned;
@@ -1495,6 +1507,37 @@ linux_nat_attach (struct target_ops *ops

status = linux_nat_post_attach_wait (lp->ptid, 1, &lp->cloned,
&lp->signalled);
+ if (!WIFSTOPPED (status))
+ {
+ delete_lwp (ptid);
+ if (WIFEXITED (status))
+ {
+ int exit_code = WEXITSTATUS (status);
+
+ target_terminal_ours ();
+ target_mourn_inferior ();
+ if (exit_code == 0)
+ error (_("During startup program exited normally."));
+ else
+ error (_("During startup program exited with code %d."),
+ exit_code);
+ }
+ else if (WIFSIGNALED (status))
+ {
+ int signo = WTERMSIG (status);
+
+ target_terminal_ours ();
+ target_mourn_inferior ();
+ error (_("During startup program terminated with signal %s, %s."),
+ target_signal_to_name (signo),
+ target_signal_to_string (signo));
+ }
+
+ internal_error (__FILE__, __LINE__,
+ _("unexpected status %d for PID %ld"),
+ status, (long) GET_LWP (ptid));
+ }
+
lp->stopped = 1;

/* Save the wait status to report later. */