Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH RFA] lin-lwp.c: Block SIGCHLD events when attaching
@ 2001-11-07 15:07 Kevin Buettner
  2001-11-07 15:15 ` H . J . Lu
  2001-11-08 13:03 ` Mark Kettenis
  0 siblings, 2 replies; 12+ messages in thread
From: Kevin Buettner @ 2001-11-07 15:07 UTC (permalink / raw)
  To: gdb-patches

When doing a lin_lwp_attach_lwp(), it is sometimes possible to receive
a SIGCHLD signal thus causing the waitpid() call to fail with EINTR. 
This in turn causes the second assert() in lin_lwp_attach_lwp() to
fail.

Reproducing this problem can be somewhat difficult.  I've only been
able to reproduce it on a dual processor Linux/x86 machine.  I did
manage to reproduce it using the linux-dp program as follows:

    1) Start linux-dp (again, running on an SMP machine).

    2) Determine the process id.  Let's call it PID.  (Make appropriate
       substitution below.)

    3) Invoke gdb:

	    gdb linux-dp

    4) Do:

	    set height 0
	    break print_philosopher

    5) Do:
	    while 1
	     attach PID
	     continue
	     detach
	    end
    6) Go get a cup of coffee, take a nap, etc.  When you come back, you
       may be fortunate enough to see the following:

	    ...
	    Breakpoint 1, print_philosopher (n=2, left=95 '_', right=95 '_')
		at ../../../src/gdb/testsuite/gdb.threads/linux-dp.c:105
	    105       shared_printf ("%*s%c %d %c\n", (n * 4) + 2, "", left, n, right);
	    ../../src/gdb/lin-lwp.c:416: gdb-internal-error: lin_lwp_attach: Assertion `pid == GET_PID (inferior_ptid) && WIFSTOPPED (status) && WSTOPSIG (status) == SIGSTOP' failed.
	    An internal GDB error was detected.  This may make further
	    debugging unreliable.  Continue this debugging session? (y or n) 

Jim Blandy deserves credit for arriving at the above procedure for
reproducing this bug.  (The actual test case that we used for tracking
down this problem is different and is able to demonstrate it in a very
short period of time.  Having *lots* of running threads greatly
increases the chances of being able to reproduce it quickly.)

The fix is below.  Okay to commit?

	    * lin-lwp.c (lin_lwp_attach_lwp): Make sure SIGCHLD is in set of
	    blocked signals.

Index: lin-lwp.c
===================================================================
RCS file: /cvs/src/src/gdb/lin-lwp.c,v
retrieving revision 1.30
diff -u -p -r1.30 lin-lwp.c
--- lin-lwp.c	2001/10/14 11:30:37	1.30
+++ lin-lwp.c	2001/11/19 19:08:10
@@ -352,6 +352,14 @@ lin_lwp_attach_lwp (ptid_t ptid, int ver
 
   gdb_assert (is_lwp (ptid));
 
+  /* Make sure SIGCHLD is blocked.  We don't want SIGCHLD events
+     to interrupt either the ptrace() or waitpid() calls below.  */
+  if (! sigismember (&blocked_mask, SIGCHLD))
+    {
+      sigaddset (&blocked_mask, SIGCHLD);
+      sigprocmask (SIG_BLOCK, &blocked_mask, NULL);
+    }
+
   if (verbose)
     printf_filtered ("[New %s]\n", target_pid_to_str (ptid));
 


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2001-11-21 22:27 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-07 15:07 [PATCH RFA] lin-lwp.c: Block SIGCHLD events when attaching Kevin Buettner
2001-11-07 15:15 ` H . J . Lu
2001-11-07 19:05   ` Kevin Buettner
2001-11-07 19:37     ` Kevin Buettner
2001-11-07 20:26       ` H . J . Lu
2001-11-07 22:45         ` Kevin Buettner
2001-11-07 22:48           ` Kevin Buettner
2001-11-07 23:21             ` H . J . Lu
2001-11-08 10:55               ` Kevin Buettner
2001-11-08 10:25                 ` H . J . Lu
2001-11-08 13:03 ` Mark Kettenis
2001-11-08 19:19   ` Kevin Buettner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox