gdb, gdbserver: detach fork child when detaching from fork parent
[deliverable/binutils-gdb.git] / gdb / remote.c
index f2271ad3b5066e5b14feae995b3e487d17be738c..c09d714087596fcfdcdc07f0c136120d9d98b687 100644 (file)
@@ -5835,6 +5835,8 @@ remote_target::remote_detach_pid (int pid)
 void
 remote_target::remote_detach_1 (inferior *inf, int from_tty)
 {
+  REMOTE_SCOPED_DEBUG_ENTER_EXIT;
+
   int pid = inferior_ptid.pid ();
   struct remote_state *rs = get_remote_state ();
   int is_fork_parent;
@@ -5857,6 +5859,24 @@ remote_target::remote_detach_1 (inferior *inf, int from_tty)
   /* Tell the remote target to detach.  */
   remote_detach_pid (pid);
 
+  for (thread_info *thread : inf->threads ())
+    {
+      if (!thread->suspend.waitstatus_pending_p)
+       continue;
+
+      const target_waitstatus &ws = thread->suspend.waitstatus;
+      if (ws.kind != TARGET_WAITKIND_FORKED
+         && ws.kind != TARGET_WAITKIND_VFORKED)
+       continue;
+
+      remote_debug_printf ("Detached thread %s has a pending fork event, "
+                          "detaching fork child %d",
+                          thread->ptid.to_string ().c_str (),
+                          ws.value.related_pid.pid ());
+
+      remote_detach_pid (ws.value.related_pid.pid ());
+    }
+
   /* Exit only if this is the only active inferior.  */
   if (from_tty && !rs->extended && number_of_live_inferiors (this) == 1)
     puts_filtered (_("Ending remote debugging.\n"));
This page took 0.025025 seconds and 4 git commands to generate.