From: Pedro Alves <palves@redhat.com>
To: "Aktemur, Tankut Baris" <tankut.baris.aktemur@intel.com>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: [PATCH] Switch the inferior before outputting its id in "info inferiors" (Re: [PATCH v2 00/24] Multi-target support)
Date: Fri, 10 Jan 2020 15:40:00 -0000 [thread overview]
Message-ID: <c7b5792f-1cdb-5edb-d6e6-052b432e45df@redhat.com> (raw)
In-Reply-To: <BYAPR11MB3030C360CB7E30E64B7AF6F2C4380@BYAPR11MB3030.namprd11.prod.outlook.com>
On 1/10/20 1:49 PM, Aktemur, Tankut Baris wrote:
> There is one more minor thing, I think. The "info inferiors" command
> iterates over the list of inferiors and prints their info. One piece of
> information is the inferior id, which is printed through the target.
> This means that for each inferior, the target of the current inferior is
> used, potentially yielding incorrect output. To fix, inferior can be switched
> temporarily before printing its id. Please see the patches below for details.
> The second one attempts to modify the multi-target.exp test to check correct
> output.
Excellent, thanks! These look great. I squashed them into a single patch,
added ChangeLog entries, and put it on the multi-target branch. I'll take care
of pushing it to master along the rest so it all goes together.
Small comment, which I've addressed:
> + gdb_test "info connections" \...
> + ] "info connections ($inf)"
> +
> + gdb_test "info inferiors" \
...
> + ] "info inferiors ($inf)"
> + }
See:
https://sourceware.org/gdb/wiki/GDBTestcaseCookbook#Do_not_use_.22tail_parentheses.22_on_test_messages
And:
https://sourceware.org/gdb/wiki/GDBTestcaseCookbook#Make_sure_test_messages_are_unique
I fixed it using with_test_prefix. Actually, the multi-target.exp testcase had another
case of non-unique messages, which I've fixed too.
Here's the version of your patch that I put in the branch.
From 2168664e216d9637b89fcc0e3c577d0aad89edcf Mon Sep 17 00:00:00 2001
From: Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Date: Fri, 10 Jan 2020 15:15:36 +0000
Subject: [PATCH] Switch the inferior before outputting its id in "info
inferiors"
GDB uses the 'current_top_target' when displaying the description of
an inferior. This leads to same target being used for each inferior
and, in turn, yields incorrect output when the inferior has a target
that is supposed to give a specialized output. For instance, the
remote target outputs "Remote target" instead of "process XYZ" as the
description if the multi-process feature is not supported or turned
off.
E.g.: Suppose we have a native and a remote target, and the native is
the current inferior. The remote target does not support multi-process.
For "info inferiors", we would expect to see:
~~~
(gdb) i inferiors
Num Description Connection Executable
* 1 process 29060 1 (native) /a/path
2 Remote target 2 (remote ...)
~~~
but instead we get
~~~
(gdb) i inferiors
Num Description Connection Executable
* 1 process 29060 1 (native) /a/path
2 process 42000 2 (remote ...)
~~~
Similarly, if the current inferior is the remote one, we would expect
to see
~~~
(gdb) i inferiors
Num Description Connection Executable
1 process 29060 1 (native) /a/path
* 2 Remote target 2 (remote ...)
~~~
but we get
~~~
(gdb) i inferiors
Num Description Connection Executable
* 1 Remote target 1 (native) /a/path
2 Remote target 2 (remote ...)
~~~
With this patch, we switch to the inferior when outputting its
description, so that the current_top_target will be aligned to the
inferior we are displaying.
For testing, this patch expands the "info inferiors" test for the
multi-target feature. The test was checking for the output of the
info commands after setup, only when the current inferior is the last
added inferior.
This patch does the following to the testcase:
1. The "info inferiors" and "info connections" test is extracted out
from the "setup" procedure to a separate procedure.
2. The test is enriched to check the output after switching to each
inferior, not just the last one.
3. The test is performed twice; one for when the multi-process feature
is turned on, one for off.
gdb/ChangeLog:
yyyy-mm-dd Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
* inferior.c (print_inferior): Switch inferior before printing it.
gdb/testsuite/ChangeLog:
yyyy-mm-dd Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
* gdb.multi/multi-target.exp (setup): Factor out "info
connections" and "info inferiors" tests to ...
(test_info_inferiors): ... this new procedure.
(top level): Run new "info-inferiors" tests.
---
gdb/inferior.c | 11 ++-
gdb/testsuite/gdb.multi/multi-target.exp | 113 +++++++++++++++++++++++--------
2 files changed, 96 insertions(+), 28 deletions(-)
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 3ce43860f7..eb090dfde1 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -494,6 +494,11 @@ print_inferior (struct ui_out *uiout, const char *requested_inferiors)
uiout->table_header (17, ui_left, "exec", "Executable");
uiout->table_body ();
+
+ /* Restore the current thread after the loop because we switch the
+ inferior in the loop. */
+ scoped_restore_current_pspace_and_thread restore_pspace_thread;
+ inferior *current_inf = current_inferior ();
for (inferior *inf : all_inferiors ())
{
if (!number_is_in_list (requested_inferiors, inf->num))
@@ -501,13 +506,17 @@ print_inferior (struct ui_out *uiout, const char *requested_inferiors)
ui_out_emit_tuple tuple_emitter (uiout, NULL);
- if (inf == current_inferior ())
+ if (inf == current_inf)
uiout->field_string ("current", "*");
else
uiout->field_skip ("current");
uiout->field_signed ("number", inf->num);
+ /* Because target_pid_to_str uses current_top_target,
+ switch the inferior. */
+ switch_to_inferior_no_thread (inf);
+
uiout->field_string ("target-id", inferior_pid_to_str (inf->pid));
std::string conn = uiout_field_connection (inf->process_target ());
diff --git a/gdb/testsuite/gdb.multi/multi-target.exp b/gdb/testsuite/gdb.multi/multi-target.exp
index 257b9c62ad..602a734342 100644
--- a/gdb/testsuite/gdb.multi/multi-target.exp
+++ b/gdb/testsuite/gdb.multi/multi-target.exp
@@ -137,33 +137,6 @@ proc setup {non-stop} {
return 0
}
- set ws "\[ \t\]+"
- global decimal
-
- # Test "info connections" and "info inferior"'s "Connection"
- # column, while at it.
-
- gdb_test "info connections" \
- [multi_line \
- "Num${ws}What${ws}Description${ws}" \
- " 1${ws}native${ws}Native process${ws}" \
- " 2${ws}extended-remote localhost:$decimal${ws}Extended remote serial target in gdb-specific protocol${ws}" \
- " 3${ws}core${ws}Local core dump file${ws}" \
- " 4${ws}extended-remote localhost:$decimal${ws}Extended remote serial target in gdb-specific protocol${ws}" \
- "\\* 5${ws}core${ws}Local core dump file${ws}" \
- ]
-
- gdb_test "info inferiors" \
- [multi_line \
- "Num${ws}Description${ws}Connection${ws}Executable${ws}" \
- " 1${ws}process ${decimal}${ws}1 \\(native\\)${ws}${binfile}${ws}" \
- " 2${ws}process ${decimal}${ws}2 \\(extended-remote localhost:$decimal\\)${ws}${binfile}${ws}" \
- " 3${ws}process ${decimal}${ws}3 \\(core\\)${ws}${binfile}${ws}" \
- " 4${ws}process ${decimal}${ws}1 \\(native\\)${ws}${binfile}${ws}" \
- " 5${ws}process ${decimal}${ws}4 \\(extended-remote localhost:$decimal\\)${ws}${binfile}${ws}" \
- "\\* 6${ws}process ${decimal}${ws}5 \\(core\\)${ws}${binfile}${ws}" \
- ]
-
# For debugging.
gdb_test "info threads" ".*"
@@ -365,6 +338,85 @@ proc test_ping_pong_next {} {
}
}
+# Test "info inferiors" and "info connections". MULTI_PROCESS
+# indicates whether the multi-process feature of remote targets is
+# turned off or on.
+proc test_info_inferiors {multi_process} {
+ setup "off"
+
+ gdb_test_no_output \
+ "set remote multiprocess-feature-packet $multi_process"
+
+ # Get the description for inferior INF for when the current
+ # inferior id is CURRENT.
+ proc inf_desc {inf current} {
+ set ws "\[ \t\]+"
+ global decimal
+ upvar multi_process multi_process
+
+ if {($multi_process == "off") && ($inf == 2 || $inf == 5)} {
+ set desc "Remote target"
+ } else {
+ set desc "process ${decimal}"
+ }
+
+ set desc "${inf}${ws}${desc}${ws}"
+ if {$inf == $current} {
+ return "\\* $desc"
+ } else {
+ return " $desc"
+ }
+ }
+
+ # Get the "Num" column for CONNECTION for when the current
+ # inferior id is CURRENT_INF.
+ proc connection_num {connection current_inf} {
+ switch $current_inf {
+ "4" { set current_connection "1"}
+ "5" { set current_connection "4"}
+ "6" { set current_connection "5"}
+ default { set current_connection $current_inf}
+ }
+ if {$connection == $current_connection} {
+ return "\\* $connection"
+ } else {
+ return " $connection"
+ }
+ }
+
+ set ws "\[ \t\]+"
+ global decimal binfile
+
+ # Test "info connections" and "info inferior" by switching to each
+ # inferior one by one.
+ for {set inf 1} {$inf <= 6} {incr inf} {
+ with_test_prefix "inferior $inf" {
+ gdb_test "inferior $inf" "Switching to inferior $inf.*"
+
+ gdb_test "info connections" \
+ [multi_line \
+ "Num${ws}What${ws}Description${ws}" \
+ "[connection_num 1 $inf]${ws}native${ws}Native process${ws}" \
+ "[connection_num 2 $inf]${ws}extended-remote localhost:$decimal${ws}Extended remote serial target in gdb-specific protocol${ws}" \
+ "[connection_num 3 $inf]${ws}core${ws}Local core dump file${ws}" \
+ "[connection_num 4 $inf]${ws}extended-remote localhost:$decimal${ws}Extended remote serial target in gdb-specific protocol${ws}" \
+ "[connection_num 5 $inf]${ws}core${ws}Local core dump file${ws}" \
+ ]
+
+ gdb_test "info inferiors" \
+ [multi_line \
+ "Num${ws}Description${ws}Connection${ws}Executable${ws}" \
+ "[inf_desc 1 $inf]1 \\(native\\)${ws}${binfile}${ws}" \
+ "[inf_desc 2 $inf]2 \\(extended-remote localhost:$decimal\\)${ws}${binfile}${ws}" \
+ "[inf_desc 3 $inf]3 \\(core\\)${ws}${binfile}${ws}" \
+ "[inf_desc 4 $inf]1 \\(native\\)${ws}${binfile}${ws}" \
+ "[inf_desc 5 $inf]4 \\(extended-remote localhost:$decimal\\)${ws}${binfile}${ws}" \
+ "[inf_desc 6 $inf]5 \\(core\\)${ws}${binfile}${ws}" \
+ ]
+ }
+ }
+}
+
# Make a core file with two threads upfront. Several tests load the
# same core file.
prepare_core
@@ -385,3 +437,10 @@ with_test_prefix "interrupt" {
with_test_prefix "ping-pong" {
test_ping_pong_next
}
+
+# Test "info inferiors" and "info connections" commands
+with_test_prefix "info-inferiors" {
+ foreach_with_prefix multi_process {"on" "off"} {
+ test_info_inferiors $multi_process
+ }
+}
--
2.14.5
next prev parent reply other threads:[~2020-01-10 15:40 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-17 22:50 [PATCH v2 00/24] Multi-target support Pedro Alves
2019-10-17 22:50 ` [PATCH v2 15/24] Avoid another inferior_ptid reference in gdb/remote.c Pedro Alves
2019-10-17 22:50 ` [PATCH v2 11/24] tfile_target::close: trace_fd can't be -1 Pedro Alves
2019-10-17 22:50 ` [PATCH v2 02/24] Don't rely on inferior_ptid in record_full_wait Pedro Alves
2019-11-01 14:54 ` Tom Tromey
2019-12-20 17:49 ` Pedro Alves
2019-12-20 18:57 ` Tom Tromey
2019-10-17 22:50 ` [PATCH v2 10/24] Some get_last_target_status tweaks Pedro Alves
2019-10-17 22:50 ` [PATCH v2 03/24] Make "show remote exec-file" inferior-aware Pedro Alves
2019-10-17 22:50 ` [PATCH v2 21/24] Revert 'Remove unused struct serial::name field' Pedro Alves
2019-10-17 22:50 ` [PATCH v2 09/24] switch inferior/thread before calling target methods Pedro Alves
2019-10-17 22:50 ` [PATCH v2 12/24] Use all_non_exited_inferiors in infrun.c Pedro Alves
2019-10-17 22:50 ` [PATCH v2 17/24] Fix reconnecting to a gdbserver already debugging multiple processes, II Pedro Alves
2019-10-17 22:50 ` [PATCH v2 06/24] Don't check target is running in remote_target::mourn_inferior Pedro Alves
2019-10-17 22:50 ` [PATCH v2 16/24] Fix reconnecting to a gdbserver already debugging multiple processes, I Pedro Alves
2019-10-17 22:50 ` [PATCH v2 01/24] Preserve selected thread in all-stop w/ background execution Pedro Alves
2019-11-01 13:20 ` Tom Tromey
2019-12-20 17:22 ` Pedro Alves
2019-12-20 18:54 ` Tom Tromey
2019-12-20 18:57 ` Pedro Alves
2019-12-20 18:57 ` Tom Tromey
2019-10-17 22:51 ` [PATCH v2 18/24] Multi-target support Pedro Alves
2020-01-11 3:12 ` Simon Marchi
2020-01-12 1:58 ` [pushed] Remove last traces of discard_all_inferiors (Re: [PATCH v2 18/24] Multi-target support) Pedro Alves
2020-01-12 20:17 ` [PATCH v2 18/24] Multi-target support Simon Marchi
2020-01-13 15:19 ` Pedro Alves
2020-01-13 16:37 ` Simon Marchi
2020-01-12 22:30 ` Simon Marchi
2020-01-13 15:59 ` Pedro Alves
2020-01-17 4:03 ` Simon Marchi
2020-01-17 16:19 ` Simon Marchi
2020-01-17 15:18 ` Simon Marchi
2020-05-16 8:16 ` Andreas Schwab
2020-05-16 11:33 ` Fix IA-64 GNU/Linux build (Re: [PATCH v2 18/24] Multi-target support) Pedro Alves
2019-10-17 22:51 ` [PATCH v2 04/24] exceptions.c:print_flush: Remove obsolete check Pedro Alves
2019-10-17 22:51 ` [PATCH v2 22/24] Add "info connections" command, "info inferiors" connection number/string Pedro Alves
2019-10-17 22:51 ` [PATCH v2 19/24] Add multi-target tests Pedro Alves
2019-10-17 22:57 ` [PATCH v2 05/24] Make target_ops::has_execution take an 'inferior *' instead of a ptid_t Pedro Alves
2019-10-17 22:57 ` [PATCH v2 23/24] Require always-non-stop for multi-target resumptions Pedro Alves
2019-11-01 14:51 ` Tom Tromey
2019-12-30 18:30 ` Pedro Alves
2019-12-31 20:06 ` Tom Tromey
2019-10-17 22:57 ` [PATCH v2 07/24] Delete unnecessary code from kill_command Pedro Alves
2019-10-17 22:59 ` [PATCH v2 08/24] Introduce switch_to_inferior_no_thread Pedro Alves
2019-11-07 9:14 ` Paunovic, Aleksandar
2019-12-20 18:50 ` Pedro Alves
2019-12-23 19:30 ` [PATCH] Switch the inferior too in switch_to_program_space_and_thread (Re: [PATCH v2 08/24] Introduce switch_to_inferior_no_thread) Pedro Alves
2020-01-08 15:48 ` Aktemur, Tankut Baris
2020-01-10 2:03 ` Pedro Alves
[not found] ` <BYAPR11MB30305218B921F31040FE4C1EC4380@BYAPR11MB3030.namprd11.prod.outlook.com>
2020-01-10 12:18 ` Pedro Alves
2020-01-10 14:41 ` Tom Tromey
2020-01-10 20:03 ` Pedro Alves
2019-10-17 22:59 ` [PATCH v2 20/24] gdbarch-selftests.c: No longer error out if debugging something Pedro Alves
2019-10-17 22:59 ` [PATCH v2 13/24] Delete exit_inferior_silent(int pid) Pedro Alves
2019-10-17 22:59 ` [PATCH v2 24/24] Multi-target: NEWS and user manual Pedro Alves
2019-10-17 23:00 ` [PATCH v2 14/24] Tweak handling of remote errors in response to resumption packet Pedro Alves
2019-10-18 20:23 ` [PATCH v2 00/24] Multi-target support John Baldwin
2019-10-29 19:13 ` Pedro Alves
2020-01-09 19:32 ` John Baldwin
2020-01-09 19:50 ` Pedro Alves
2020-01-10 13:49 ` Aktemur, Tankut Baris
2020-01-10 15:40 ` Pedro Alves [this message]
2019-10-20 11:41 ` Philippe Waroquiers
2019-10-29 19:56 ` Pedro Alves
2019-11-01 14:56 ` Tom Tromey
2020-01-10 20:13 ` Pedro Alves
2020-08-04 3:30 ` Kevin Buettner
2020-08-06 15:16 ` Pedro Alves
2020-08-06 17:49 ` Tom Tromey
2020-08-07 22:43 ` Kevin Buettner
2020-08-12 18:45 ` Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c7b5792f-1cdb-5edb-d6e6-052b432e45df@redhat.com \
--to=palves@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=tankut.baris.aktemur@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox