public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Bruno Larsen <blarsen@redhat.com>
To: Keith Seitz <keiths@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH v3 3/4] gdb/cli: add '.' as an argument for 'list' command
Date: Thu, 22 Jun 2023 12:52:53 +0200	[thread overview]
Message-ID: <0e9e8f1a-3a02-113f-5144-0c8b660060d5@redhat.com> (raw)
In-Reply-To: <311c8e10-ae51-aab1-820d-d849b4a2f6fc@redhat.com>

On 21/06/2023 19:25, Keith Seitz wrote:
> On 6/21/23 03:45, Bruno Larsen via Gdb-patches wrote:
>> Currently, after the user has used the list command once, there is no
>> way to ask GDB to print the location where the inferior is stopped.
>> This commit adds a way to do that using '.' as a new argument for the
>> 'list' command.  If the inferior isn't running, the command throws an
>> error.  The test gdb.base/list.exp was updated to test this new 
>> argument.
>
> I'm not entirely sure how I feel about throwing an error when using
> "list ." with no running inferior. Can you explain why that might be
> preferable to, say, just mimicking "list" with no argument or some other
> fallback?
>
> [I'm not going to NACK this patch for this, of course. I am just normally
> cautious about adding errors when logical, convenient fallbacks could
> be used instead.]
My logic was that '.' is supposed to be 'current location', so if the 
inferior is not running, there is no current location. I'm changing it, 
no problem :)
>
> However, there is a problem that specifically needs addressing IMO.
>
> Compare (using gdb debugging gdb):
>
> (top-gdb) list 10
> 5
> 6       This program is free software; you can redistribute it and/or 
> modify
> 7       it under the terms of the GNU General Public License as 
> published by
> 8       the Free Software Foundation; either version 3 of the License, or
> 9       (at your option) any later version.
> 10
> 11       This program is distributed in the hope that it will be useful,
> 12       but WITHOUT ANY WARRANTY; without even the implied warranty of
> 13       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> 14       GNU General Public License for more details.
> (top-gdb)
> 15
> 16       You should have received a copy of the GNU General Public 
> License
> 17       along with this program.  If not, see 
> <http://www.gnu.org/licenses/>.  */
> 18
> 19    #include "defs.h"
> 20    #include "main.h"
> 21    #include "interps.h"
> 22
> 23    int
> 24    main (int argc, char **argv)
> (top-gdb)
> 25    {
> 26      struct captured_main_args args;
> 27
> 28      memset (&args, 0, sizeof args);
> 29      args.argc = argc;
> 30      args.argv = argv;
> 31      args.interpreter_p = INTERP_CONSOLE;
> 32      return gdb_main (&args);
> 33    }
> (top-gdb)
>
>
> With (after "start"):
>
> (top-gdb) list .
> 23    int
> 24    main (int argc, char **argv)
> 25    {
> 26      struct captured_main_args args;
> 27
> 28      memset (&args, 0, sizeof args);
> 29      args.argc = argc;
> 30      args.argv = argv;
> 31      args.interpreter_p = INTERP_CONSOLE;
> 32      return gdb_main (&args);
> (top-gdb)
> 23    int
> 24    main (int argc, char **argv)
> 25    {
> 26      struct captured_main_args args;
> 27
> 28      memset (&args, 0, sizeof args);
> 29      args.argc = argc;
> 30      args.argv = argv;
> 31      args.interpreter_p = INTERP_CONSOLE;
> 32      return gdb_main (&args);
> (top-gdb)
> 23    int
> 24    main (int argc, char **argv)
> 25    {
> 26      struct captured_main_args args;
> 27
> 28      memset (&args, 0, sizeof args);
> 29      args.argc = argc;
> 30      args.argv = argv;
> 31      args.interpreter_p = INTERP_CONSOLE;
> 32      return gdb_main (&args);
> (top-gdb)
>
> I don't think this is particularly user-friendly. Is it possible to make
> the two use cases behave similarly?

Today I learned about GDB dealing with command arguments! TL;DR yes, 
I'll do that in v4

For future reference (probably for myself) if you advance the arg 
pointer when handling the command, the next command invocation is going 
to use the advanced argument pointer. When handling the number, 
list_command advances the arg, so everything after the first line is 
literally a no arg invocation.

>
> Keith
>

-- 
Cheers,
Bruno


  reply	other threads:[~2023-06-22 10:53 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-21 10:45 [PATCH v3 0/4] Small changes to "list" command Bruno Larsen
2023-06-21 10:45 ` [PATCH v3 1/4] gdb/cli: Factor out code to list lines for the first time Bruno Larsen
2023-06-22 13:25   ` Andrew Burgess
2023-06-21 10:45 ` [PATCH v3 2/4] gdb/cli: Improve UX when using list with no args Bruno Larsen
2023-06-21 16:07   ` Keith Seitz
2023-06-22  9:54     ` Bruno Larsen
2023-06-22 13:46   ` Andrew Burgess
2023-06-27 11:35     ` Bruno Larsen
2023-06-21 10:45 ` [PATCH v3 3/4] gdb/cli: add '.' as an argument for 'list' command Bruno Larsen
2023-06-21 17:25   ` Keith Seitz
2023-06-22 10:52     ` Bruno Larsen [this message]
2023-06-22 13:51   ` Andrew Burgess
2023-06-21 10:45 ` [PATCH v3 4/4] gdb/doc: document '+' " Bruno Larsen
2023-06-21 11:13   ` Eli Zaretskii
2023-06-21 11:20     ` Bruno Larsen
2023-06-21 12:44       ` Eli Zaretskii
2023-06-21 12:55         ` Bruno Larsen
2023-06-21 14:11           ` Eli Zaretskii

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=0e9e8f1a-3a02-113f-5144-0c8b660060d5@redhat.com \
    --to=blarsen@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=keiths@redhat.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).