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

* RE: [PATCH] gdb: restore thread after detaching from an inferior
  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:12 ` [PATCH v2] gdb: restore thread after detaching or killing " Tankut Baris Aktemur
  2 siblings, 0 replies; 6+ messages in thread
From: Aktemur, Tankut Baris @ 2020-10-21  6:58 UTC (permalink / raw)
  To: gdb-patches

Kindly pinging.

Thanks
-Baris

On Tuesday, October 6, 2020 6:06 PM, Aktemur, Tankut Baris wrote:
> 
> 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



Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

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

* Re: [PATCH] gdb: restore thread after detaching from an inferior
  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
  2 siblings, 1 reply; 6+ messages in thread
From: Pedro Alves @ 2020-10-22 15:35 UTC (permalink / raw)
  To: Tankut Baris Aktemur, gdb-patches

On 10/6/20 5:05 PM, Tankut Baris Aktemur via Gdb-patches wrote:
> 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)

This is:

 https://sourceware.org/bugzilla/show_bug.cgi?id=19318

So I agree with your patch.  But what about "kill inferior" ?

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

* RE: [PATCH] gdb: restore thread after detaching from an inferior
  2020-10-22 15:35 ` Pedro Alves
@ 2020-10-28 17:11   ` Aktemur, Tankut Baris
  0 siblings, 0 replies; 6+ messages in thread
From: Aktemur, Tankut Baris @ 2020-10-28 17:11 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

On Thursday, October 22, 2020 5:36 PM, Pedro Alves wrote:
> On 10/6/20 5:05 PM, Tankut Baris Aktemur via Gdb-patches wrote:
> > 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)
> 
> This is:
> 
>  https://sourceware.org/bugzilla/show_bug.cgi?id=19318
> 
> So I agree with your patch.  But what about "kill inferior" ?

Thanks for the pointer.  I'll send a v2 of the patch in a few minutes
that also prevents the switch for 'kill inferiors'.

-Baris


Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928

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

* [PATCH v2] gdb: restore thread after detaching or killing an inferior
  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:12 ` Tankut Baris Aktemur
  2020-10-29 14:26   ` Pedro Alves
  2 siblings, 1 reply; 6+ messages in thread
From: Tankut Baris Aktemur @ 2020-10-28 17:12 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)

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

gdb/ChangeLog:
2020-10-06  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-06  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/inferior.c                                       | 4 ++++
 gdb/testsuite/gdb.base/kill-detach-inferiors-cmd.exp | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/gdb/inferior.c b/gdb/inferior.c
index f775938721d..f06c13bbca4 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 ())
     {
@@ -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 ())
     {
diff --git a/gdb/testsuite/gdb.base/kill-detach-inferiors-cmd.exp b/gdb/testsuite/gdb.base/kill-detach-inferiors-cmd.exp
index 82e0c712c8f..06887601de4 100644
--- a/gdb/testsuite/gdb.base/kill-detach-inferiors-cmd.exp
+++ b/gdb/testsuite/gdb.base/kill-detach-inferiors-cmd.exp
@@ -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" \
-- 
2.17.1


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

* Re: [PATCH v2] gdb: restore thread after detaching or killing an inferior
  2020-10-28 17:12 ` [PATCH v2] gdb: restore thread after detaching or killing " Tankut Baris Aktemur
@ 2020-10-29 14:26   ` Pedro Alves
  0 siblings, 0 replies; 6+ messages in thread
From: Pedro Alves @ 2020-10-29 14:26 UTC (permalink / raw)
  To: Tankut Baris Aktemur, gdb-patches

On 10/28/20 5:12 PM, Tankut Baris Aktemur wrote:
> 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-06  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-06  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.

OK.

^ 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).