Non-working threaded version.
[debugger.git] / debugger.c-childhandler.patch
1 --- debugger.c  2007-04-07 10:17:12.000000000 +0200
2 +++ debugger.c-childhandler     2007-04-07 10:16:39.000000000 +0200
3 @@ -26,6 +26,13 @@
4  #endif
5  }
6  
7 +static int attach_handler_count;
8 +
9 +static void attach_handler (int signo)
10 +{
11 +  attach_handler_count++;
12 +}
13 +
14  /* Debugging only: Number of signal needing redelivery on PTRACE_ATTACH.  */
15  int attach_redelivered;
16  
17 @@ -40,6 +47,17 @@
18  
19    delay ();
20  
21 +  attach_handler_count = 0;
22 +  /* Fill SA_SIGACTION _before_ SA_HANDLER as they may be in union!  */
23 +  act.sa_sigaction = NULL;
24 +  act.sa_handler = attach_handler;
25 +  i = sigemptyset (&act.sa_mask);
26 +  assert (i == 0);
27 +  act.sa_flags = 
28 +  act.sa_restorer = NULL;
29 +
30 +  attach_handler_orig = signal (SIGCHLD, attach_handler);
31 +
32    i = ptrace (PTRACE_ATTACH, pid, NULL, NULL);
33    assert (i == 0);
34  
35 @@ -84,6 +102,22 @@
36        assert (i == 0);
37      }
38  
39 +  attach_handler_orig = signal (SIGCHLD, attach_handler_orig);
40 +  assert (attach_handler_orig == attach_handler);
41 +
42 +  if (stopped == 1 && attach_handler_count == 2)
43 +    stopped = 0;
44 +  else if (stopped == 1 && attach_handler_count == 1)
45 +    stopped = 1;
46 +  else if (stopped == 0 && attach_handler_count == 1)
47 +    stopped = 0;
48 +  else
49 +    {
50 +      fprintf (stderr, "stopped = %d, attach_handler_count = %d\n", stopped,
51 +              attach_handler_count);
52 +      abort ();
53 +    }
54 +
55    delay ();
56  
57    return stopped;