Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] gdb/python: allow Architecture.disassemble to give styled output
Date: Mon, 23 Mar 2026 10:17:40 +0000	[thread overview]
Message-ID: <87se9q4zp7.fsf@redhat.com> (raw)
In-Reply-To: <86h5qacxif.fsf@gnu.org>

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Andrew Burgess <aburgess@redhat.com>
>> Cc: Andrew Burgess <aburgess@redhat.com>
>> Date: Fri, 20 Mar 2026 15:31:11 +0000
>> 
>> Extend the Architecture.disassemble API to allow the user to request
>> styled disassembler output via a new styling argument.  A user can now
>> write:
>> 
>>   insn = arch.disassemble(address, styling = True)
>> 
>> The instruction strings returned within INSN will contain ANSI escape
>> sequences so long as 'set style enabled on' is in effect.  This means
>> that the user's personal settings (disabling styling) will override a
>> GDB extension that requests styled disassembler output.  I think this
>> makes sense.
>> 
>> The default for the styling argument is False, this maintains the
>> current unstyled output as default.
>> ---
>>  gdb/NEWS                                      |   5 +
>>  gdb/doc/python.texi                           |   7 +-
>>  gdb/python/py-arch.c                          |  11 +-
>>  .../gdb.python/py-arch-disasm-style.c         |  52 ++++++++
>>  .../gdb.python/py-arch-disasm-style.exp       | 119 ++++++++++++++++++
>>  5 files changed, 189 insertions(+), 5 deletions(-)
>>  create mode 100644 gdb/testsuite/gdb.python/py-arch-disasm-style.c
>>  create mode 100644 gdb/testsuite/gdb.python/py-arch-disasm-style.exp
>> 
>> diff --git a/gdb/NEWS b/gdb/NEWS
>> index e46a5108272..da74c248c54 100644
>> --- a/gdb/NEWS
>> +++ b/gdb/NEWS
>> @@ -229,6 +229,11 @@ qExecAndArgs
>>       the appropriate user setting is enabled, and GDB knows how to
>>       style this source file.
>>  
>> +  ** The Architecture.disassemble method accepts a new 'styling'
>> +     argument, which defaults to False.  When set to True the 'asm'
>> +     strings in the disassembler output can contain ANSI escape
>> +     sequences to indicate styling.
>> +
>>  * Guile API
>
> This part is okay.
>
>> --- a/gdb/doc/python.texi
>> +++ b/gdb/doc/python.texi
>> @@ -7632,7 +7632,7 @@ Architectures In Python
>>  Return the name (string value) of the architecture.
>>  @end defun
>>  
>> -@defun Architecture.disassemble (start_pc @r{[}, end_pc @r{[}, count@r{]]})
>> +@defun Architecture.disassemble (start_pc @r{[}, end_pc @r{[}, count@r{]]} @w{@r{[}, styling = @code{False}@r{]}})
>>  Return a list of disassembled instructions starting from the memory
>>  address @var{start_pc}.  The optional arguments @var{end_pc} and
>>  @var{count} determine the number of instructions in the returned list.
>> @@ -7661,6 +7661,11 @@ Architectures In Python
>>  language flavor used is the same as that specified by the current CLI
>>  variable @code{disassembly-flavor}.  @xref{Machine Code}.
>>  
>> +When the optional argument @var{styling} is @code{True} the @var{asm}
>> +string can contain ANSI terminal escape sequences if styling is
>> +enabled (@pxref{Output Styling}).  When @var{styling} is @code{False},
>> +which is the default, then no styling will be applied to @var{asm}.
>> +
>
> This is also okay, but I don't think @var is correct for "asm", since
> those are literal strings, not symbols that stand for something else.

I changed to use @samp{...}, this seemed like the most appropriate
option, and pushed this patch.

Thanks,
Andrew


  reply	other threads:[~2026-03-23 10:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-20 15:31 Andrew Burgess
2026-03-20 15:48 ` Eli Zaretskii
2026-03-23 10:17   ` Andrew Burgess [this message]
2026-03-20 17:54 ` Tom Tromey

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=87se9q4zp7.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=eliz@gnu.org \
    --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