Re: [PATCH v4] inferior without argument prints detail of current inferior

Simon Marchi via Gdb-patches
2021-01-11T01:15:34Z

On 2021-01-10 12:58 p.m., Lancelot SIX via Gdb-patches wrote:
> 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.
>
> This contribution is inspired by an item in
> https://sourceware.org/gdb/wiki/ProjectIdeas
>
> 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)]
>
> Changes from V1:
> * Add test.
>
> Change from V2:
> * Fix gdb/doc/ChangeLog entry.
>
> Change from V3:
> * Add entry in the NEWS file.
> * Improve inferior-noarg.expr and remove assumptions particular
> format in pid_to_str.
> * Fix copyright year in new files.
>
> 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.
>
> ---
> ---
> gdb/NEWS | 6 +++
> gdb/doc/gdb.texinfo | 16 +++++++
> gdb/inferior.c | 58 +++++++++++++++--------
> gdb/testsuite/gdb.base/inferior-noarg.c | 22 +++++++++
> gdb/testsuite/gdb.base/inferior-noarg.exp | 36 ++++++++++++++
> 5 files changed, 117 insertions(+), 21 deletions(-)
> create mode 100644 gdb/testsuite/gdb.base/inferior-noarg.c
> create mode 100644 gdb/testsuite/gdb.base/inferior-noarg.exp
>
> diff --git a/gdb/NEWS b/gdb/NEWS
> index 66702862ef..d9788f6733 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -75,6 +75,12 @@ maintenance flush-symbol-cache
> 'maintenance flush register-cache' and 'maintenance flush
> symbol-cache' respectively.
>
> +inferior [ID]
> + When the ID parameter is omitted, then this command prints information
> + about the current inferior. When the ID parameter is present, the
> + behavior of the command is unchanged and have the inferior ID become
> + the current inferior.

I'll let Eli review the NEWS entry, otherwise the patch LGTM. Let us know
when you have your sourceware account.

Simon