Fix reconnecting to a gdbserver already debugging multiple processes, I
[deliverable/binutils-gdb.git] / gdb / remote.c
index ffdeede7af5330777f60c3f5136863eb13be7f1f..751769ea7fc517013a3931df7ef0452a321f61d8 100644 (file)
@@ -2367,6 +2367,26 @@ remote_target::remote_add_inferior (bool fake_pid_p, int pid, int attached,
         between program/address spaces.  We simply bind the inferior
         to the program space's address space.  */
       inf = current_inferior ();
+
+      /* However, if the current inferior is already bound to a
+        process, find some other empty inferior.  */
+      if (inf->pid != 0)
+       {
+         inf = nullptr;
+         for (inferior *it : all_inferiors ())
+           if (it->pid == 0)
+             {
+               inf = it;
+               break;
+             }
+       }
+      if (inf == nullptr)
+       {
+         /* Since all inferiors were already bound to a process, add
+            a new inferior.  */
+         inf = add_inferior_with_spaces ();
+       }
+      switch_to_inferior_no_thread (inf);
       inferior_appeared (inf, pid);
     }
 
This page took 0.024221 seconds and 4 git commands to generate.