diff options
author | Andrew Burgess <aburgess@redhat.com> | 2022-02-14 14:40:52 +0000 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2022-07-11 12:02:54 +0100 |
commit | 4cbe4ca5da5cd7e1e6331ce11f024bf3c07b9744 (patch) | |
tree | 8c0bf2715ee9bc1c477005ba81c50cc22c59990e /gdb/disasm.h | |
parent | 81384924cdcc9eb2676dd9084b76845d7d0e0759 (diff) | |
download | gdb-4cbe4ca5da5cd7e1e6331ce11f024bf3c07b9744.zip gdb-4cbe4ca5da5cd7e1e6331ce11f024bf3c07b9744.tar.gz gdb-4cbe4ca5da5cd7e1e6331ce11f024bf3c07b9744.tar.bz2 |
gdb: add support for disassembler styling using libopcodes
This commit extends GDB to make use of libopcodes styling support
where available, currently this is just i386 based architectures, and
RISC-V.
For architectures that don't support styling using libopcodes GDB will
fall back to using the Python Pygments package, when the package is
available.
The new libopcodes based styling has the disassembler identify parts
of the disassembled instruction, e.g. registers, immediates,
mnemonics, etc, and can style these components differently.
Additionally, as the styling is now done in GDB we can add settings to
allow the user to configure which colours are used right from the GDB
CLI.
There's some new maintenance commands:
maintenance set libopcodes-styling enabled on|off
maintenance show libopcodes-styling
These can be used to manually disable use of libopcodes styling. This
is a maintenance command as it's not anticipated that a user should
need to do this. But, this could be useful for testing, or, in some
rare cases, a user might want to override the Python hook used for
disassembler styling, and then disable libopcode styling so that GDB
falls back to using Python. Right now I would consider this second
use case a rare situation, which is why I think a maintenance command
is appropriate.
When libopcodes is being used for styling then the user can make use
of the following new styles:
set/show style disassembler comment
set/show style disassembler immediate
set/show style disassembler mnemonic
set/show style disassembler register
The disassembler also makes use of the 'address' and 'function'
styles to style some parts of the disassembler output. I have also
added the following aliases though:
set/show style disassembler address
set/show style disassembler symbol
these are aliases for:
set/show style address
set/show style function
respectively, and exist to make it easier for users to discover
disassembler related style settings. The 'address' style is used to
style numeric addresses in the disassembler output, while the 'symbol'
or 'function' style is used to style the names of symbols in
disassembler output.
As not every architecture supports libopcodes styling, the maintenance
setting 'libopcodes-styling enabled' has an "auto-off" type behaviour.
Consider this GDB session:
(gdb) show architecture
The target architecture is set to "auto" (currently "i386:x86-64").
(gdb) maintenance show libopcodes-styling enabled
Use of libopcodes styling support is "on".
the setting defaults to "on" for architectures that support libopcodes
based styling.
(gdb) set architecture sparc
The target architecture is set to "sparc".
(gdb) maintenance show libopcodes-styling enabled
Use of libopcodes styling support is "off" (not supported on architecture "sparc")
the setting will show as "off" if the user switches to an architecture
that doesn't support libopcodes styling. The underlying setting is
still "on" at this point though, if the user switches back to
i386:x86-64 then the setting would go back to being "on".
(gdb) maintenance set libopcodes-styling enabled off
(gdb) maintenance show libopcodes-styling enabled
Use of libopcodes styling support is "off".
now the setting is "off" for everyone, even if the user switches back
to i386:x86-64 the setting will still show as "off".
(gdb) maintenance set libopcodes-styling enabled on
Use of libopcodes styling not supported on architecture "sparc".
(gdb) maintenance show libopcodes-styling enabled
Use of libopcodes styling support is "off".
attempting to switch the setting "on" for an unsupported architecture
will give an error, and the setting will remain "off".
(gdb) set architecture auto
The target architecture is set to "auto" (currently "i386:x86-64").
(gdb) maintenance show libopcodes-styling enabled
Use of libopcodes styling support is "off".
(gdb) maintenance set libopcodes-styling enabled on
(gdb) maintenance show libopcodes-styling enabled
Use of libopcodes styling support is "on".
the user will need to switch back to a supported architecture before
they can one again turn this setting "on".
Diffstat (limited to 'gdb/disasm.h')
-rw-r--r-- | gdb/disasm.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/gdb/disasm.h b/gdb/disasm.h index 54176eb..2921d53 100644 --- a/gdb/disasm.h +++ b/gdb/disasm.h @@ -138,6 +138,16 @@ protected: const char *format, ...) ATTRIBUTE_PRINTF(3,4); + /* Return true if the disassembler is considered inside a comment, false + otherwise. */ + bool in_comment_p () const + { return m_in_comment; } + + /* Set whether the disassembler should be considered as within comment + text or not. */ + void set_in_comment (bool c) + { m_in_comment = c; } + private: /* When libopcodes calls the fprintf_func and fprintf_styled_func @@ -151,6 +161,12 @@ private: /* The stream to which output should be sent. */ struct ui_file *m_stream; + + /* Are we inside a comment? This will be set true if the disassembler + uses styled output and emits a start of comment character. It is up + to the code that uses this disassembler class to reset this flag back + to false at a suitable time (e.g. at the end of every line). */ + bool m_in_comment; }; /* A basic disassembler that doesn't actually print anything. */ |