diff options
author | Tankut Baris Aktemur <tankut.baris.aktemur@intel.com> | 2020-01-10 20:06:17 +0000 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2020-01-10 20:06:17 +0000 |
commit | d9ebdab754fac0e9a4e4046a550a3e89cf5c2699 (patch) | |
tree | 163dfc559621fb159f80a3ae2e067c517fd9456f /gdb/inferior.c | |
parent | f3c469b95b9f1f635668660c5041df9513a47a02 (diff) | |
download | gdb-d9ebdab754fac0e9a4e4046a550a3e89cf5c2699.zip gdb-d9ebdab754fac0e9a4e4046a550a3e89cf5c2699.tar.gz gdb-d9ebdab754fac0e9a4e4046a550a3e89cf5c2699.tar.bz2 |
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:
2020-01-10 Tankut Baris Aktemur <tankut.baris.aktemur@intel.com>
* inferior.c (print_inferior): Switch inferior before printing it.
gdb/testsuite/ChangeLog:
2020-01-10 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.
Diffstat (limited to 'gdb/inferior.c')
-rw-r--r-- | gdb/inferior.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/gdb/inferior.c b/gdb/inferior.c index 3ce4386..eb090df 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 ()); |