[PATCH] fbsd-nat: Don't use '%jd' and '%ju' with printf_filtered.

John Baldwin jhb@FreeBSD.org
Mon Aug 30 16:16:45 GMT 2021


On 8/27/21 1:23 PM, Tom Tromey wrote:
>>>>>> "John" == John Baldwin <jhb@FreeBSD.org> writes:
> 
> John> The code around this in
> John> utils.c is a bit confusing to me.
> 
> Yeah, the gdb formatting code is not great, and the pager and wrapping
> code work in an especially obscure way.
> 
> John> However, vprintf_filtered() does not set gdbfmt to true:
> 
> John> void
> John> vprintf_filtered (const char *format, va_list args)
> John> {
> John>   vfprintf_maybe_filtered (gdb_stdout, format, args, true, false);
> John> }
> 
> John> This seems inconsistent.  I wonder if printf_filtered should be
> John> implemented in terms of vprintf_filtered, but that is probably a
> John> bit of a behavior change now, and I wonder if gdbfmt should always
> John> be true instead?
> 
> Changing vprintf_filtered to pass 'true' passes regression testing here.
> So maybe we ought to make that change.  It certainly seems less
> confusing.
> 
> I don't recall why this is written the way it is.  Perhaps there was a
> reason and it was obsoleted by some other change.

It looks like it was added in this commit as vfprintf_maybe_filtered
always used string_vprintf() before:

commit 2a3c1174c3c0db1140180fb3fc56ac324d1c0a7c
Author: Pedro Alves <palves@redhat.com>
Date:   Wed Jun 5 09:17:16 2019 +0100

     Introduce gdb-specific %p format suffixes
     
     This introduces a few gdb-specific %p format suffixes.  This is useful
     for emitting gdb-specific output in an ergonomic way.  It also yields
     code that is more i18n-friendly.
     
     The comment before ui_out::message explains the details.
     
     Note that the tests had to change a little.  When using one of the gdb
     printf functions with styling, there can be spurious style changes
     emitted to the output.  This did not seem worthwhile to fix, as the
     low-level output functions are rather spaghetti-ish already, and I
     didn't want to make them even worse.

I suspect that we probably want gdbfmt to always be true as otherwise
the custom suffixes won't work with vprintf_filtered.

The fact that printf_filtered() uses vfprintf_filtered() directly
instead of vprintf_filtered() seems to go back to the first commit
in 1999.

I'll still push this fbsd-nat change but will post a change in a bit to
always use gdbfmt for vfprintf_maybe_filtered.

-- 
John Baldwin


More information about the Gdb-patches mailing list