[PATCH] gdb/python: new styled argument to gdb.execute

Andrew Burgess aburgess@redhat.com
Fri Feb 14 21:18:19 GMT 2025


Tom Tromey <tom@tromey.com> writes:

>>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
>
> Andrew> Currently, gdb.execute emits styled output when the command is sending
> Andrew> its output to GDB's stdout, and produces unstyled output when the
> Andrew> output is going to a string.
>
> Thanks for doing this.
>
> I actually implemented something close to this once but never polished
> and sent it.  Can't remember why now.
>
> Andrew> There are some additional issues with capturing source code; GDB
> Andrew> caches the source code in the source code cache.  However, GDB doesn't
> Andrew> check if the cached content is styled or not.  As a consequence, if
> Andrew> the first time the source of a file is shown it is unstyled, then the
> Andrew> cached will hold the unstyled source code, and future requests will
> Andrew> return that unstyled source.  I'll address this issue in a separate
> Andrew> patch.
>
> Wanted to bookmark this for a note later on...
>
> Andrew> +  ** gdb.execute has an additional 'styled' argument.  When True, then
>
> This says "styled" ...
>
> Andrew> +@defun gdb.execute (command @r{[}, from_tty @r{[}, to_string @w{@r{[}, styled @r{]]]}})
>
> ... same here, but ...
>
> Andrew> +    = { "command", "from_tty", "to_string", "styling", nullptr };
>
> Here it is called "styling".

Gah!  It started as 'styled', but then I realised I should check what
other API methods use, and they all use 'styling', so I switched.  But I
think my brain was still stuck on 'styled' when I wrote the docs :/

I'll get this cleaned up.  It'll be 'styling' as that matches other API calls.

>
> Andrew> +	scoped_restore save_styling
> Andrew> +	  = make_scoped_restore (&cli_styling, cli_styling && styling_p);
>
> Andrew> +	  {
> Andrew> +	    bool term_out = gdb_stdout->can_emit_style_escape ();
> Andrew> +	    to_string_res
> Andrew> +	      = execute_control_commands_to_string (lines.get (), from_tty,
> Andrew> +						    term_out);
>
> I wonder if this is needed, since the above will entirely disable
> styling when styling_p==false.  Like maybe term_out could always be
> true?

I'll clean this up.  I'll post a new version next week.

Thanks,
Andrew



More information about the Gdb-patches mailing list