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

Simon Marchi via Gdb-patches
2020-12-18T22:25:56Z

On 2020-12-18 5:04 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)]
>
> My copyright assignment request is currently in progress.
>
> gdb/doc/ChangeLog:
>
> 2020-12-16 Lancelot SIX <lsix@lancelotsix.com>
>
> * gdb.texinfo: Document the inferior command when used without
> argument

For the ChangeLog entity in the entry here, find the nearest @node
that contains the change.

>
> gdb/ChangeLog:
>
> 2020-12-16 Lancelot SIX <lsix@lancelotsix.com>
>
> * inferior.c (inferior_command): When no argument is given to the
> inferior command, display info about the currently selected
> inferior.
>
> gdb/testsuite/ChangeLog:
>
> 2020-12-16 Lancelot SIX <lsix@lancelotsix.com>
>
> * gdb.base/inferior-noarg.c: New test.
> * gdb.base/inferior-noarg.exp: New test.
> ---
> 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 ++++++++++++++
> 4 files changed, 111 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/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 5b6ac8549b..c9ee0b87f2 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -3202,6 +3202,22 @@ For example,
> 2 process 2307 2 (extended-remote host:10000) hello
> @end smallexample
>
> +To get informations about the current inferior, use @code{inferior}:
> +
> +@table @code
> +@kindex inferior
> +@item inferior
> +Shows information about the current inferior.
> +
> +For example,
> +@end table
> +@c end table here to get a little more width for example
> +
> +@smallexample
> +(@value{GDBP}) inferior
> +[Current inferior is 1 [process 3401] (helloworld)]
> +@end smallexample
> +
> To find out what open target connections exist at any moment, use
> @w{@code{info connections}}:

The documentation bits will have to be reviewed by Eli.

> diff --git a/gdb/testsuite/gdb.base/inferior-noarg.c b/gdb/testsuite/gdb.base/inferior-noarg.c
> new file mode 100644
> index 0000000000..9d7b2f1a4c
> --- /dev/null
> +++ b/gdb/testsuite/gdb.base/inferior-noarg.c
> @@ -0,0 +1,22 @@
> +/* This testcase is part of GDB, the GNU debugger.
> +
> + Copyright 2020 Free Software Foundation, Inc.
> +
> + This program is free software; you can redistribute it and/or modify
> + it under the terms of the GNU General Public License as published by
> + the Free Software Foundation; either version 3 of the License, or
> + (at your option) any later version.
> +
> + This program is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + GNU General Public License for more details.
> +
> + You should have received a copy of the GNU General Public License
> + along with this program. If not, see <http://www.gnu.org/licenses/>. */
> +
> +int
> +main (void)
> +{
> + return 0;
> +}

I kinda recall that we had one dummy C file that we re-used instead of
creating more trivial ones like that. But I can't find it, so this LGTM
unless someone finds it.

Otherwise, let's patiently wait for your copyright assignment.

Simon