gdb: restore thread after detaching or killing an inferior
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.