[patch] gdbserver: Fix harmless crash for current-lwp-dead.exp

Jan Kratochvil jan.kratochvil@redhat.com
Fri Dec 2 22:11:00 GMT 2011


Hi,

gdb.threads/current-lwp-dead.exp with local/native gdbserver will make
crash/coredump of gdbserver on its shutdown.

#0  in linux_kill (pid=20071) at linux-low.c:871
#1  in kill_inferior_callback (entry=0xf49470) at server.c:2439
#2  in for_each_inferior (list=0x64e250, action=0x40bea9 <kill_inferior_callback>) at inferiors.c:59
#3  in process_serial_event () at server.c:3142
#4  in handle_serial_event (err=0, client_data=0x0) at server.c:3252
#5  in handle_file_event (event_file_desc=5) at event-loop.c:489
#6  in process_event () at event-loop.c:244
#7  in start_event_loop () at event-loop.c:607
#8  in main (argc=4, argv=0x7fffbd50eda8) at server.c:2749

It is because gdbserver wants to kill the thread group leader - but in this
case there is no thread group leader, that is the purpose of the testcase.

The fix is definitely safe.  I will check it with no comments.
Tested on x86_64-fedora16-linux-gnu with gdbserver.


Thanks,
Jan


gdb/gdbserver/
2011-12-02  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* linux-low.c (linux_kill): Skip PTRACE_KILL if LWP does not exist.
	Print new debug message for such case.

--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -862,17 +862,26 @@ linux_kill (int pid)
      thread in the list, so do so now.  */
   lwp = find_lwp_pid (pid_to_ptid (pid));
 
-  if (debug_threads)
-    fprintf (stderr, "lk_1: killing lwp %ld, for pid: %d\n",
-	     lwpid_of (lwp), pid);
-
-  do
+  if (lwp == NULL)
     {
-      ptrace (PTRACE_KILL, lwpid_of (lwp), 0, 0);
+      if (debug_threads)
+	fprintf (stderr, "lk_1: cannot find lwp %ld, for pid: %d\n",
+		 lwpid_of (lwp), pid);
+    }
+  else
+    {
+      if (debug_threads)
+	fprintf (stderr, "lk_1: killing lwp %ld, for pid: %d\n",
+		 lwpid_of (lwp), pid);
 
-      /* Make sure it died.  The loop is most likely unnecessary.  */
-      lwpid = linux_wait_for_event (lwp->head.id, &wstat, __WALL);
-    } while (lwpid > 0 && WIFSTOPPED (wstat));
+      do
+	{
+	  ptrace (PTRACE_KILL, lwpid_of (lwp), 0, 0);
+
+	  /* Make sure it died.  The loop is most likely unnecessary.  */
+	  lwpid = linux_wait_for_event (lwp->head.id, &wstat, __WALL);
+	} while (lwpid > 0 && WIFSTOPPED (wstat));
+    }
 
   the_target->mourn (process);
 



More information about the Gdb-patches mailing list