diff options
author | Lancelot SIX <lsix@lancelotsix.com> | 2021-01-06 20:58:04 +0000 |
---|---|---|
committer | Lancelot SIX <lsix@lancelotsix.com> | 2021-02-02 22:37:39 +0000 |
commit | 2e3773ff548f068bddfc6d060524730fcf6823a1 (patch) | |
tree | 977640ce31c5cc8c14afb91955cecdb47ba4bc8f /gdb/inferior.c | |
parent | e0bd9202fb13262101550d788db536ad5ca55c26 (diff) | |
download | gdb-2e3773ff548f068bddfc6d060524730fcf6823a1.zip gdb-2e3773ff548f068bddfc6d060524730fcf6823a1.tar.gz gdb-2e3773ff548f068bddfc6d060524730fcf6823a1.tar.bz2 |
Inferior without argument prints detail of current inferior.
This patch makes the inferior command display information about the
current inferior when called with no argument. This behavior is similar
to the one of the thread command.
Before patch:
(gdb) info inferior
Num Description Connection Executable
* 1 process 19221 1 (native) /home/lsix/tmp/a.out
2 process 19239 1 (native) /home/lsix/tmp/a.out
(gdb) inferior 2
[Switching to inferior 2 [process 19239] (/home/lsix/tmp/a.out)]
[Switching to thread 2.1 (process 19239)]
#0 0x0000000000401146 in main ()
(gdb) inferior
Argument required (expression to compute).
After patch:
(gdb) info inferior
Num Description Connection Executable
* 1 process 18699 1 (native) /home/lsix/tmp/a.out
2 process 18705 1 (native) /home/lsix/tmp/a.out
(gdb) inferior 2
[Switching to inferior 2 [process 18705] (/home/lsix/tmp/a.out)]
[Switching to thread 2.1 (process 18705)]
#0 0x0000000000401146 in main ()
(gdb) inferior
[Current inferior is 2 [process 18705] (/home/lsix/tmp/a.out)]
gdb/doc/ChangeLog:
* gdb.texinfo (Inferiors Connections and Programs): Document the
inferior command when used without argument.
gdb/ChangeLog:
* NEWS: Add entry for the behavior change of the inferior command.
* inferior.c (inferior_command): When no argument is given to the
inferior command, display info about the currently selected
inferior.
gdb/testsuite/ChangeLog:
* gdb.base/inferior-noarg.c: New test.
* gdb.base/inferior-noarg.exp: New test.
Diffstat (limited to 'gdb/inferior.c')
-rw-r--r-- | gdb/inferior.c | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/gdb/inferior.c b/gdb/inferior.c index 3ff0512..49f869a 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -635,34 +635,50 @@ inferior_command (const char *args, int from_tty) struct inferior *inf; int num; - num = parse_and_eval_long (args); - - inf = find_inferior_id (num); - if (inf == NULL) - error (_("Inferior ID %d not known."), num); - - if (inf->pid != 0) + if (args == nullptr) { - if (inf != current_inferior ()) - { - thread_info *tp = any_thread_of_inferior (inf); - if (tp == NULL) - error (_("Inferior has no threads.")); + inf = current_inferior (); + gdb_assert (inf != nullptr); + const char *filename = inf->pspace->exec_filename.get (); - switch_to_thread (tp); - } + if (filename == nullptr) + filename = _("<noexec>"); - gdb::observers::user_selected_context_changed.notify - (USER_SELECTED_INFERIOR - | USER_SELECTED_THREAD - | USER_SELECTED_FRAME); + printf_filtered (_("[Current inferior is %d [%s] (%s)]\n"), + inf->num, inferior_pid_to_str (inf->pid).c_str (), + filename); } else { - switch_to_inferior_no_thread (inf); + num = parse_and_eval_long (args); + + inf = find_inferior_id (num); + if (inf == NULL) + error (_("Inferior ID %d not known."), num); + + if (inf->pid != 0) + { + if (inf != current_inferior ()) + { + thread_info *tp = any_thread_of_inferior (inf); + if (tp == NULL) + error (_("Inferior has no threads.")); - gdb::observers::user_selected_context_changed.notify - (USER_SELECTED_INFERIOR); + switch_to_thread (tp); + } + + gdb::observers::user_selected_context_changed.notify + (USER_SELECTED_INFERIOR + | USER_SELECTED_THREAD + | USER_SELECTED_FRAME); + } + else + { + switch_to_inferior_no_thread (inf); + + gdb::observers::user_selected_context_changed.notify + (USER_SELECTED_INFERIOR); + } } } |