]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit - gdb/inferior.c
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)
commitcfaa8f76928803afda1e1862bcd0ab5f7febd647
treeb57f35792d6f47559304da193f7069c6d7622214
parent00c19b8e7879b5e256e7852bdac667466d7a42c2
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.
gdb/ChangeLog
gdb/inferior.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/kill-detach-inferiors-cmd.exp