This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: ui_out format strings for fields and styles (Re: [PATCH] Style "pwd" output)
On 6/5/19 9:47 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
>
> Pedro> Also, since gcc expects a pointer for %p, and we want to pass an
> Pedro> enum for the style, I added a small pointer-wrapper hack -- see the
> Pedro> ptr function. Yay C++.
>
> We could just remove the enum, move to passing pointers everywhere, and
> convert the *_style objects to be pointers. This would streamline
> things a bit;
...
> and we could use nullptr to mean "keep the default".
Yeah, that would %pN / %p] redundant/unnecessary...
>
> Another option would be to just add a ptr method to the _style objects,
> so instead of ui_out_style_kind::VARIABLE you'd write variable_style.ptr ().
... and could thus end up with something like:
current_uiout->message (_("%pS%s%pS %pS%s%pS\n"),
address_style.style ().ptr (),
tmp,
nullptr,
(msymbol.minsym->text_p ()
? function_name_style.style ().ptr ()
: nullptr),
MSYMBOL_PRINT_NAME (msymbol.minsym),
nullptr);
If you'd like to give this a try, please do feel free to push to
the branch.
>
> Pedro> I've not been paying much attention to the styling patches, so I can't
> Pedro> off hand tell which places would benefit the most from this. So I just
> Pedro> grepped for _styled and replaced a couple spots. Likely there are better
> Pedro> examples.
>
> There's my new patch and I have one more along those lines as well, but
> a good existing one that was already deconstructed is in symfile.c:
>
> puts_filtered (_("Reading symbols from "));
> fputs_styled (name, file_name_style.style (), gdb_stdout);
> puts_filtered ("...\n");
So that could be either:
current_uiout->message (_("Reading symbols from %pS%s%pS...\n"),
file_name_style.style ().ptr (),
name,
nullptr);
or:
current_uiout->message (_("Reading symbols from %ps...\n"),
styled_string (ui_out_style_kind::FILENAME, name).ptr ());
or even:
current_uiout->message (_("Reading symbols from %ps...\n"),
styled_string (file_name_style.style (), name).ptr ());
>
> Pedro> For the seemingly common case of printing a string variable
> Pedro> with a style, I'm thinking that a specific formatter would
> Pedro> be better. I'll post a follow up patch for that.
>
> I'm interested to see it.
>
Thanks,
Pedro Alves