public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org>
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: Re: [PATCH] gdb: add support for %V to printf command
Date: Mon, 17 Apr 2023 09:47:39 -0600	[thread overview]
Message-ID: <87bkjm4ijo.fsf@tromey.com> (raw)
In-Reply-To: <775f2ae1297bff92b09c3b6a58596a5e65f212eb.1680178345.git.aburgess@redhat.com> (Andrew Burgess via Gdb-patches's message of "Thu, 30 Mar 2023 13:22:10 +0100")

>>>>> "Andrew" == Andrew Burgess via Gdb-patches <gdb-patches@sourceware.org> writes:

Andrew> This commit adds a new format for the printf and dprintf commands:
Andrew> '%V'.  This new format takes any GDB expression and formats it as a
Andrew> string, just as GDB would for a 'print' command, e.g.:

Thank you for doing this.  I'm definitely a fan of the idea.

Andrew> --- a/gdb/printcmd.c
Andrew> +++ b/gdb/printcmd.c
Andrew> @@ -2733,7 +2733,7 @@ ui_printf (const char *arg, struct ui_file *stream)
Andrew>    if (*s++ != '"')
Andrew>      error (_("Bad format string, missing '\"'."));
 
Andrew> -  format_pieces fpieces (&s);
Andrew> +  format_pieces fpieces (&s, false, true);

I was going to ask if there is a spot that sets gdb_extensions=false and
the new flag=true.  This setting seems odd to me, but I didn't dig
through to find out why it's needed.

Andrew> +	      string_file buffer;
Andrew> +	      print_formatted (val_args[i], 0, &print_opts, &buffer);
Andrew> +	      gdb_puts (buffer.string ().c_str ());

Why is a second stream needed here?  Like, couldn't print_formatted be
called with 'stream'?  Wouldn't that preserve any styling done by
print_formatted?  Or is the intention to strip styling?

Andrew> +	    if (f[1] == '[')
Andrew> +	      {
Andrew> +		const char *tmp;
Andrew> +		for (tmp = f; *tmp != ']' && *tmp != '\0'; ++tmp)
Andrew> +		  ;
Andrew> +		if (*tmp == ']')
Andrew> +		  f = tmp;

strchr if it simplifies things.

I didn't dig into this either, but I don't think %V could work in
dprintf's call or agent modes.  So, maybe gdb should reject this
somewhere.  Or maybe this is already done by the default setting in the
constructor?

Tom

  parent reply	other threads:[~2023-04-17 15:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-30 12:22 Andrew Burgess
2023-03-30 14:20 ` Eli Zaretskii
2023-04-11 12:34   ` Andrew Burgess
2023-04-17 15:47 ` Tom Tromey [this message]
2023-04-28 13:14   ` [PATCHv2] " Andrew Burgess
2023-04-28 15:34     ` Eli Zaretskii
2023-05-12 13:01     ` [PATCHv3] " Andrew Burgess
2023-05-12 13:47       ` Simon Marchi
2023-05-26 20:44       ` Tom Tromey
2023-05-30 20:56         ` Andrew Burgess

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=87bkjm4ijo.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /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).