diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 78922021681..4163c869afe 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2020-01-10 Pedro Alves + + * remote.c (remote_target::remote_add_inferior): Don't bind a + process to the current inferior if the current inferior is already + bound to a process. + 2020-01-10 Tankut Baris Aktemur Pedro Alves diff --git a/gdb/remote.c b/gdb/remote.c index ffdeede7af5..751769ea7fc 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -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); } diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 52d52d15f6c..0ff75954b1a 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-01-10 Pedro Alves + + * gdb.server/extended-remote-restart.exp (test_reload): Explicitly + disconnect before reconnecting. + 2020-01-10 Tankut Baris Aktemur Pedro Alves diff --git a/gdb/testsuite/gdb.server/extended-remote-restart.exp b/gdb/testsuite/gdb.server/extended-remote-restart.exp index b34027348ef..3ce0f0b076a 100644 --- a/gdb/testsuite/gdb.server/extended-remote-restart.exp +++ b/gdb/testsuite/gdb.server/extended-remote-restart.exp @@ -113,7 +113,9 @@ proc test_reload { do_kill_p follow_child_p } { "Check inferior was killed" } - # Reconnect to the target. + # Disconnect, and reconnect to the target. + gdb_test "disconnect" ".*" + if { [gdb_reconnect] == 0 } { pass "reconnect after fork" } else {