mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-03-01 13:26:47 +08:00
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".
154 lines
4.8 KiB
C++
154 lines
4.8 KiB
C++
/* CLI stylizing
|
|
|
|
Copyright (C) 2018-2022 Free Software Foundation, Inc.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef CLI_CLI_STYLE_H
|
|
#define CLI_CLI_STYLE_H
|
|
|
|
#include "ui-file.h"
|
|
#include "command.h"
|
|
#include "gdbsupport/observable.h"
|
|
|
|
/* A single CLI style option. */
|
|
class cli_style_option
|
|
{
|
|
public:
|
|
|
|
/* Construct a CLI style option with a foreground color. */
|
|
cli_style_option (const char *name, ui_file_style::basic_color fg,
|
|
ui_file_style::intensity = ui_file_style::NORMAL);
|
|
|
|
/* Construct a CLI style option with an intensity. */
|
|
cli_style_option (const char *name, ui_file_style::intensity i);
|
|
|
|
/* Return a ui_file_style corresponding to the settings in this CLI
|
|
style. */
|
|
ui_file_style style () const;
|
|
|
|
/* Return the style name. */
|
|
const char *name () { return m_name; };
|
|
|
|
/* Call once to register this CLI style with the CLI engine. Returns
|
|
the set/show prefix commands for the style. */
|
|
set_show_commands add_setshow_commands (enum command_class theclass,
|
|
const char *prefix_doc,
|
|
struct cmd_list_element **set_list,
|
|
struct cmd_list_element **show_list,
|
|
bool skip_intensity);
|
|
|
|
/* Return the 'set style NAME' command list, that can be used
|
|
to build a lambda DO_SET to call add_setshow_commands. */
|
|
struct cmd_list_element *set_list () { return m_set_list; };
|
|
|
|
/* Same as SET_LIST but for the show command list. */
|
|
struct cmd_list_element *show_list () { return m_show_list; };
|
|
|
|
/* This style can be observed for any changes. */
|
|
gdb::observers::observable<> changed;
|
|
|
|
private:
|
|
|
|
/* The style name. */
|
|
const char *m_name;
|
|
|
|
/* The foreground. */
|
|
const char *m_foreground;
|
|
/* The background. */
|
|
const char *m_background;
|
|
/* The intensity. */
|
|
const char *m_intensity;
|
|
|
|
/* Storage for command lists needed when registering
|
|
subcommands. */
|
|
struct cmd_list_element *m_set_list = nullptr;
|
|
struct cmd_list_element *m_show_list = nullptr;
|
|
|
|
/* Callback to notify the observable. */
|
|
static void do_set_value (const char *ignore, int from_tty,
|
|
struct cmd_list_element *cmd);
|
|
|
|
/* Callback to show the foreground. */
|
|
static void do_show_foreground (struct ui_file *file, int from_tty,
|
|
struct cmd_list_element *cmd,
|
|
const char *value);
|
|
/* Callback to show the background. */
|
|
static void do_show_background (struct ui_file *file, int from_tty,
|
|
struct cmd_list_element *cmd,
|
|
const char *value);
|
|
/* Callback to show the intensity. */
|
|
static void do_show_intensity (struct ui_file *file, int from_tty,
|
|
struct cmd_list_element *cmd,
|
|
const char *value);
|
|
};
|
|
|
|
/* The file name style. */
|
|
extern cli_style_option file_name_style;
|
|
|
|
/* The function name style. */
|
|
extern cli_style_option function_name_style;
|
|
|
|
/* The variable name style. */
|
|
extern cli_style_option variable_name_style;
|
|
|
|
/* The address style. */
|
|
extern cli_style_option address_style;
|
|
|
|
/* The highlight style. */
|
|
extern cli_style_option highlight_style;
|
|
|
|
/* The title style. */
|
|
extern cli_style_option title_style;
|
|
|
|
/* The metadata style. */
|
|
extern cli_style_option metadata_style;
|
|
|
|
/* The disassembler style for mnemonics or assembler directives
|
|
(e.g. '.byte', etc). */
|
|
extern cli_style_option disasm_mnemonic_style;
|
|
|
|
/* The disassembler style for register names. */
|
|
extern cli_style_option disasm_register_style;
|
|
|
|
/* The disassembler style for numerical values that are not addresses, this
|
|
includes immediate operands (e.g. in, an add instruction), but also
|
|
address offsets (e.g. in a load instruction). */
|
|
extern cli_style_option disasm_immediate_style;
|
|
|
|
/* The disassembler style for comments. */
|
|
extern cli_style_option disasm_comment_style;
|
|
|
|
/* The border style of a TUI window that does not have the focus. */
|
|
extern cli_style_option tui_border_style;
|
|
|
|
/* The border style of a TUI window that does have the focus. */
|
|
extern cli_style_option tui_active_border_style;
|
|
|
|
/* The style to use for the GDB version string. */
|
|
extern cli_style_option version_style;
|
|
|
|
/* True if source styling is enabled. */
|
|
extern bool source_styling;
|
|
|
|
/* True if disassembler styling is enabled. */
|
|
extern bool disassembler_styling;
|
|
|
|
/* True if styling is enabled. */
|
|
extern bool cli_styling;
|
|
|
|
#endif /* CLI_CLI_STYLE_H */
|