[commit] Handle LWPs that have died without leaving a status

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[commit] Handle LWPs that have died without leaving a status

Kevin Buettner
I've just committed the patch below.  It's been sitting in one of my
trees for a while and I don't remember all that much about it.  I do
know that without this code, RDA will error out when using certain
linux kernel versions with the message:

    <<< ERROR -- tkill (680, Stopped (signal)) failed: No such process >>>

I believe that this would occur because RDA was attempting to stop a
process which had already exited.  Apparently, there were certain (buggy)
kernels which would fail to leave an exit status.

        * lwp-pool.c (mark_lwp_as_dead_but_interesting): New function.
        (wait_and_handle): Replace lines of code implementing guts of
        new function mark_lwp_as_dead_but_interesting() with call to
        that function.  Make a new call to this function after it
        has been determined that an lwp has exited without leaving a
        status.

Index: lwp-pool.c
===================================================================
RCS file: /cvs/src/src/rda/unix/lwp-pool.c,v
retrieving revision 1.4
diff -u -p -r1.4 lwp-pool.c
--- lwp-pool.c 9 Nov 2005 02:16:46 -0000 1.4
+++ lwp-pool.c 10 Nov 2005 21:26:30 -0000
@@ -796,6 +796,17 @@ debug_report_state_change (struct gdbser
     }
 }
 
+/* Remove (dead) LWP from the hash table and put it on the `interesting'
+   queue.  */
+static void
+mark_lwp_as_dead_but_interesting (struct lwp *l)
+{
+  hash_delete (l);
+  l->state = lwp_state_dead_interesting;
+  if (l->next)
+    queue_delete (l);
+  queue_enqueue (&interesting_queue, l);
+}
 
 /* Wait for a status from the LWP L (or any LWP, if L is NULL),
    passing FLAGS to waitpid, and record the resulting wait status in
@@ -868,15 +879,7 @@ wait_and_handle (struct gdbserv *serv, s
   l->status = status;
 
   if (WIFEXITED (status) || WIFSIGNALED (status))
-    {
-      /* Remove dead LWP's from the hash table, and put them in the
- interesting queue.  */
-      hash_delete (l);
-      l->state = lwp_state_dead_interesting;
-      if (l->next)
- queue_delete (l);
-      queue_enqueue (&interesting_queue, l);
-    }
+    mark_lwp_as_dead_but_interesting (l);
   else
     {
       int stopsig;
@@ -1143,9 +1146,24 @@ lwp_pool_stop_all (struct gdbserv *serv)
     case lwp_state_running:
       /* A 'no such process' error here indicates an NPTL thread
  that has exited.  */
-      kill_lwp (l->pid, SIGSTOP);
-      l->state = lwp_state_running_stop_pending;
-      queue_enqueue (&stopping_queue, l);
+      if (kill_lwp (l->pid, SIGSTOP) < 0)
+ {
+  /* Thread has exited.  See if a status is available.  */
+  if (wait_and_handle (serv, l, WNOHANG) < 0)
+    {
+      /* Nope, it's truly gone without providing a status.
+         Put it on the interesting queue so that GDB is
+ notified that it's gone.  */
+      l->status = 0;
+      mark_lwp_as_dead_but_interesting (l);
+    }
+ }
+      else
+ {
+  l->state = lwp_state_running_stop_pending;
+  queue_enqueue (&stopping_queue, l);
+ }
+
       break;
 
     case lwp_state_stopped: