public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: restore thread after detaching from an inferior
@ 2020-10-06 16:05 Tankut Baris Aktemur
  2020-10-21  6:58 ` Aktemur, Tankut Baris
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Tankut Baris Aktemur @ 2020-10-06 16:05 UTC (permalink / raw)
  To: gdb-patches

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)

Prevent this by restoring the current thread.

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

	* inferior.c (detach_inferior_command): Restore the current thread.

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

	* gdb.base/kill-detach-inferiors-cmd.exp: Check that 'detach
	inferiors' does not change the current inferior.
---
 gdb/inferior.c                                       | 2 ++
 gdb/testsuite/gdb.base/kill-detach-inferiors-cmd.exp | 1 +
 2 files changed, 3 insertions(+)

diff --git a/gdb/inferior.c b/gdb/inferior.c
index f775938721d..040ebc59354 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -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 ())
     {
diff --git a/gdb/testsuite/gdb.base/kill-detach-inferiors-cmd.exp b/gdb/testsuite/gdb.base/kill-detach-inferiors-cmd.exp
index 82e0c712c8f..d7e490ce8c1 100644
--- a/gdb/testsuite/gdb.base/kill-detach-inferiors-cmd.exp
+++ b/gdb/testsuite/gdb.base/kill-detach-inferiors-cmd.exp
@@ -49,6 +49,7 @@ gdb_test_no_output "kill inferiors 1 2"
 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    <null> .*" "inf 1 is still current"
 
 # No inferiors should be running anymore.
 gdb_test "kill inferiors 1 2 3" \
-- 
2.17.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-10-29 14:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-06 16:05 [PATCH] gdb: restore thread after detaching from an inferior Tankut Baris Aktemur
2020-10-21  6:58 ` Aktemur, Tankut Baris
2020-10-22 15:35 ` Pedro Alves
2020-10-28 17:11   ` Aktemur, Tankut Baris
2020-10-28 17:12 ` [PATCH v2] gdb: restore thread after detaching or killing " Tankut Baris Aktemur
2020-10-29 14:26   ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).