gdb: restore thread after detaching or killing an inferior
authorTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Thu, 29 Oct 2020 14:33:39 +0000 (15:33 +0100)
committerTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Thu, 29 Oct 2020 14:33:39 +0000 (15:33 +0100)
The "detach inferiors N" command causes the current inferior to
switch.  E.g.:

  $ gdb a.out
  Reading symbols from a.out...
  (gdb) start
  ...
  (gdb) add-inferior
  [New inferior 2]
  Added inferior 2 on connection 1 (native)
  (gdb) inferior 2
  [Switching to inferior 2 [<null>] (<noexec>)]
  (gdb) info inferiors
    Num  Description       Connection           Executable
    1    process 18242     1 (native)           /path/to/a.out
  * 2    <null>            1 (native)
  (gdb) detach inferiors 1
  Detaching from program: /path/to/a.out, process 18242
  [Inferior 1 (process 18242) detached]
  (gdb) info inferiors
    Num  Description       Connection           Executable
  * 1    <null>                                 /path/to/a.out
    2    <null>            1 (native)
  (gdb)

The same switch happens with the "kill inferiors N" command.  Prevent
it by restoring the current thread.

gdb/ChangeLog:
2020-10-29  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

PR gdb/19318
* inferior.c (detach_inferior_command): Restore the current thread.
(kill_inferior_command): Ditto.

gdb/testsuite/ChangeLog:
2020-10-29  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>

* gdb.base/kill-detach-inferiors-cmd.exp: Check that 'kill
inferiors' and 'detach inferiors' do not change the current
inferior.

gdb/ChangeLog
gdb/inferior.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/kill-detach-inferiors-cmd.exp

index 9dd5c0b6b22aa4d4a442cd501803801692e05809..3cef0093300cdb96a209ae636d9665371f1237b5 100644 (file)
@@ -1,3 +1,9 @@
+2020-10-29  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
+
+       PR gdb/19318
+       * inferior.c (detach_inferior_command): Restore the current thread.
+       (kill_inferior_command): Ditto.
+
 2020-10-28  Tom de Vries  <tdevries@suse.de>
 
        PR symtab/26772
index f775938721db5f5136b5693f095d20c6e05c3a56..f06c13bbca448ab88cae4d5f33429542673cee65 100644 (file)
@@ -547,6 +547,8 @@ detach_inferior_command (const char *args, int from_tty)
   if (!args || !*args)
     error (_("Requires argument (inferior id(s) to detach)"));
 
+  scoped_restore_current_thread restore_thread;
+
   number_or_range_parser parser (args);
   while (!parser.finished ())
     {
@@ -584,6 +586,8 @@ kill_inferior_command (const char *args, int from_tty)
   if (!args || !*args)
     error (_("Requires argument (inferior id(s) to kill)"));
 
+  scoped_restore_current_thread restore_thread;
+
   number_or_range_parser parser (args);
   while (!parser.finished ())
     {
index 24bc0d82c4721743cb0623f849b3c7077e36b193..0c162bc3d8cc4fbdc3a07da872eb84a179d446d2 100644 (file)
@@ -1,3 +1,9 @@
+2020-10-29  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
+
+       * gdb.base/kill-detach-inferiors-cmd.exp: Check that 'kill
+       inferiors' and 'detach inferiors' do not change the current
+       inferior.
+
 2020-10-29  Tom de Vries  <tdevries@suse.de>
 
        * gdb.threads/tls.exp: Fix DUPLICATEs.
index 82e0c712c8f0e90b6bc99dd1aa7594cceee51701..06887601de4222840f7e68cd7c79e88448121472 100644 (file)
@@ -46,9 +46,11 @@ gdb_test "attach $test_pid" "Attaching to process.*" "attach to pid"
 
 # Kill the first two inferiors, and detach the third.
 gdb_test_no_output "kill inferiors 1 2"
+gdb_test "info inferiors 3" "\r\n\\* 3 \[^\r\n\]+" "inf 3 is still current"
 gdb_test "inferior 1" "Switching to inferior 1.*"
 gdb_test "kill" "The program is not being run.*"
 gdb_test "detach inferiors 3" "Detaching from program.*process $test_pid.*"
+gdb_test "info inferiors 1" "\r\n\\* 1 \[^\r\n\]+" "inf 1 is still current"
 
 # No inferiors should be running anymore.
 gdb_test "kill inferiors 1 2 3" \
This page took 0.044312 seconds and 4 git commands to generate.