Introduce "command" styling

This adds a new "command" style that is used when styling the name of
a gdb command.

Note that not every instance of a command name that is output by gdb
is changed here.  There is currently no way to style error() strings,
and there is no way to mark up command help strings.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31747
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Reviewed-By: Keith Seitz <keiths@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
This commit is contained in:
Tom Tromey 2024-05-18 11:35:32 -06:00
parent 62e4d4d3ad
commit 9e69a2e127
22 changed files with 143 additions and 65 deletions

View file

@ -119,6 +119,11 @@ set style line-number background COLOR
set style line-number intensity VALUE
Control the styling of line numbers printed by GDB.
set style command foreground COLOR
set style command background COLOR
set style command intensity VALUE
Control the styling of GDB commands when displayed by GDB.
set warn-language-frame-mismatch [on|off]
show warn-language-frame-mismatch
Control the warning that is emitted when specifying a language that

View file

@ -477,19 +477,23 @@ file_is_auto_load_safe (const char *filename)
gdb_printf (_("\
To enable execution of this file add\n\
\tadd-auto-load-safe-path %s\n\
\t%p[add-auto-load-safe-path %s%p]\n\
line to your configuration file \"%ps\".\n\
To completely disable this security protection add\n\
\tset auto-load safe-path /\n\
\t%ps\n\
line to your configuration file \"%ps\".\n\
For more information about this security protection see the\n\
\"Auto-loading safe path\" section in the GDB manual. E.g., run from the shell:\n\
\tinfo \"(gdb)Auto-loading safe path\"\n"),
filename_real.get (),
styled_string (file_name_style.style (),
home_config.c_str ()),
styled_string (file_name_style.style (),
home_config.c_str ()));
command_style.style ().ptr (),
filename_real.get (),
nullptr,
styled_string (file_name_style.style (),
home_config.c_str ()),
styled_string (command_style.style (),
"set auto-load safe-path /"),
styled_string (file_name_style.style (),
home_config.c_str ()));
advice_printed = true;
}

View file

@ -9377,7 +9377,8 @@ create_breakpoint (struct gdbarch *gdbarch,
if (canonical.lsals.size () > 1)
{
warning (_("Multiple breakpoints were set.\nUse the "
"\"delete\" command to delete unwanted breakpoints."));
"\"%ps\" command to delete unwanted breakpoints."),
styled_string (command_style.style (), "delete"));
prev_breakpoint_count = prev_bkpt_count;
}

View file

@ -1869,26 +1869,33 @@ help_list (struct cmd_list_element *list, const char *cmdtype,
if (theclass == all_classes)
{
gdb_printf (stream, "\n\
Type \"help%s\" followed by a class name for a list of commands in ",
cmdtype1);
Type \"%p[help%s%p]\" followed by a class name for a list of commands in ",
command_style.style ().ptr (),
cmdtype1,
nullptr);
stream->wrap_here (0);
gdb_printf (stream, "that class.");
gdb_printf (stream, "\n\
Type \"help all\" for the list of all commands.");
Type \"%ps\" for the list of all commands.",
styled_string (command_style.style (), "help all"));
}
gdb_printf (stream, "\nType \"help%s\" followed by %scommand name ",
cmdtype1, cmdtype2);
gdb_printf (stream, "\nType \"%p[help%s%p]\" followed by %scommand name ",
command_style.style ().ptr (), cmdtype1, nullptr,
cmdtype2);
stream->wrap_here (0);
gdb_puts ("for ", stream);
stream->wrap_here (0);
gdb_puts ("full ", stream);
stream->wrap_here (0);
gdb_puts ("documentation.\n", stream);
gdb_puts ("Type \"apropos word\" to search "
"for commands related to \"word\".\n", stream);
gdb_puts ("Type \"apropos -v word\" for full documentation", stream);
gdb_printf (stream,
"Type \"%ps\" to search "
"for commands related to \"word\".\n",
styled_string (command_style.style (), "apropos word"));
gdb_printf (stream, "Type \"%ps\" for full documentation",
styled_string (command_style.style (), "apropos -v word"));
stream->wrap_here (0);
gdb_puts (" of commands related to \"word\".\n", stream);
gdb_puts ("Command name abbreviations are allowed if unambiguous.\n",

View file

@ -91,6 +91,10 @@ cli_style_option title_style ("title", ui_file_style::BOLD);
/* See cli-style.h. */
cli_style_option command_style ("command", ui_file_style::BOLD);
/* See cli-style.h. */
cli_style_option tui_border_style ("tui-border", ui_file_style::CYAN);
/* See cli-style.h. */
@ -439,6 +443,13 @@ readability."),
&style_set_list, &style_show_list,
false);
command_style.add_setshow_commands (no_class, _("\
Command display styling.\n\
Configure the colors and display intensity for GDB commands mentioned\n\
in the output."),
&style_set_list, &style_show_list,
false);
highlight_style.add_setshow_commands (no_class, _("\
Highlight display styling.\n\
Configure highlight colors and display intensity\n\

View file

@ -118,6 +118,9 @@ extern cli_style_option highlight_style;
/* The title style. */
extern cli_style_option title_style;
/* Style used for commands. */
extern cli_style_option command_style;
/* The metadata style. */
extern cli_style_option metadata_style;

View file

@ -1943,16 +1943,20 @@ Because `startup-with-shell' is enabled, gdb tried to work around SIP by\n\
caching a copy of your shell. However, this failed:\n\
%s\n\
If you correct the problem, gdb will automatically try again the next time\n\
you \"run\". To prevent these attempts, you can use:\n\
set startup-with-shell off"),
ex.what ());
you \"%ps\". To prevent these attempts, you can use:\n\
%ps"),
ex.what (),
styled_string (command_style.style (), "run"),
styled_string (command_style.style (),
"set startup-with-shell off"));
return false;
}
gdb_printf (_("Note: this version of macOS has System Integrity Protection.\n\
Because `startup-with-shell' is enabled, gdb has worked around this by\n\
caching a copy of your shell. The shell used by \"run\" is now:\n\
caching a copy of your shell. The shell used by \"%ps\" is now:\n\
%s\n"),
styled_string (command_style.style (), "run"),
new_name.c_str ());
}

View file

@ -27864,6 +27864,10 @@ their characteristics and the visual aspect of each style.
The style-able objects are:
@table @code
@item command
Control the styling of any @value{GDBN} commands that are displayed by
@value{GDBN}. By default, this style's intensity is bold.
@item filename
Control the styling of file names and URLs. By default, this style's
foreground color is green.

View file

@ -20,6 +20,7 @@
#include "read-gdb-index.h"
#include "cli/cli-cmds.h"
#include "cli/cli-style.h"
#include "complaints.h"
#include "dwz.h"
#include "event-top.h"
@ -392,9 +393,11 @@ read_gdb_index_from_buffer (const char *filename,
{
warning (_("\
Skipping deprecated .gdb_index section in %s.\n\
Do \"set use-deprecated-index-sections on\" before the file is read\n\
Do \"%ps\" before the file is read\n\
to use the section anyway."),
filename);
filename,
styled_string (command_style.style (),
"set use-deprecated-index-sections on"));
warning_printed = 1;
}
return 0;

View file

@ -327,7 +327,8 @@ exec_file_locate_attach (int pid, int defer_bp_reset, int from_tty)
warning (_("No executable has been specified and target does not "
"support\n"
"determining executable automatically. "
"Try using the \"file\" command."));
"Try using the \"%ps\" command."),
styled_string (command_style.style (), "file"));
return;
}

View file

@ -33,6 +33,7 @@
#include "gdbsupport/agent.h"
#include "gdbsupport/gdb_wait.h"
#include "gdbsupport/filestuff.h"
#include "cli/cli-style.h"
#include <sys/types.h>
#include <fcntl.h>
@ -160,7 +161,8 @@ inf_child_open_target (const char *arg, int from_tty)
current_inferior ()->push_target (target);
inf_child_explicitly_opened = 1;
if (from_tty)
gdb_printf ("Done. Use the \"run\" command to start a process.\n");
gdb_printf ("Done. Use the \"%ps\" command to start a process.\n",
styled_string (command_style.style (), "run"));
}
/* Implement the to_disconnect target_ops method. */

View file

@ -27,6 +27,7 @@
#include "gdbsupport/environ.h"
#include "value.h"
#include "cli/cli-cmds.h"
#include "cli/cli-style.h"
#include "symfile.h"
#include "gdbcore.h"
#include "target.h"
@ -1999,10 +2000,9 @@ info_program_command (const char *args, int from_tty)
}
if (from_tty)
{
gdb_printf (_("Type \"info stack\" or \"info "
"registers\" for more information.\n"));
}
gdb_printf (_("Type \"%ps\" or \"%ps\" for more information.\n"),
styled_string (command_style.style (), "info stack"),
styled_string (command_style.style (), "info registers"));
}
static void

View file

@ -19,6 +19,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "cli/cli-cmds.h"
#include "cli/cli-style.h"
#include "displaced-stepping.h"
#include "infrun.h"
#include <ctype.h>
@ -463,8 +464,10 @@ follow_fork_inferior (bool follow_child, bool detach_fork)
back the terminal, effectively hanging the debug session. */
gdb_printf (gdb_stderr, _("\
Can not resume the parent process over vfork in the foreground while\n\
holding the child stopped. Try \"set detach-on-fork\" or \
\"set schedule-multiple\".\n"));
holding the child stopped. Try \"set %ps\" or \"%ps\".\n"),
styled_string (command_style.style (), "set detach-on-fork"),
styled_string (command_style.style (),
"set schedule-multiple"));
return true;
}
@ -1308,8 +1311,9 @@ follow_exec (ptid_t ptid, const char *exec_file_target)
so that the user can specify a file manually before continuing. */
if (exec_file_host == nullptr)
warning (_("Could not load symbols for executable %s.\n"
"Do you need \"set sysroot\"?"),
exec_file_target);
"Do you need \"%ps\"?"),
exec_file_target,
styled_string (command_style.style (), "set sysroot"));
/* Reset the shared library package. This ensures that we get a
shlib event when the child reaches "_start", at which point the
@ -10039,8 +10043,8 @@ info_signals_command (const char *signum_exp, int from_tty)
sig_print_info (oursig);
}
gdb_printf (_("\nUse the \"handle\" command "
"to change these tables.\n"));
gdb_printf (_("\nUse the \"%ps\" command to change these tables.\n"),
styled_string (command_style.style (), "handle"));
}
/* The $_siginfo convenience variable is a bit special. We don't know

View file

@ -1496,10 +1496,11 @@ At startup, GDB reads the following init files and executes their commands:\n\
&& local_gdbinit.empty ())
gdb_printf (stream, _("\
None found.\n"));
gdb_puts (_("\n\
For more information, type \"help\" from within GDB, or consult the\n\
gdb_printf (stream, _("\n\
For more information, type \"%ps\" from within GDB, or consult the\n\
GDB manual (available as on-line info or a printed manual).\n\
"), stream);
"),
styled_string (command_style.style (), "stream"));
if (REPORT_BUGS_TO[0] && stream == gdb_stdout)
gdb_printf (stream, _("\n\
Report bugs to %ps.\n\

View file

@ -44,6 +44,7 @@
#include "cli/cli-decode.h"
#include "cli/cli-utils.h"
#include "cli/cli-setshow.h"
#include "cli/cli-style.h"
#include "cli/cli-cmds.h"
static void maintenance_do_deprecate (const char *, int);
@ -104,14 +105,16 @@ maintenance_demangler_warning (const char *args, int from_tty)
static void
maintenance_demangle (const char *args, int from_tty)
{
gdb_printf (_("This command has been moved to \"demangle\".\n"));
gdb_printf (_("This command has been moved to \"%ps\".\n"),
styled_string (command_style.style (), "demangle"));
}
static void
maintenance_time_display (const char *args, int from_tty)
{
if (args == NULL || *args == '\0')
gdb_printf (_("\"maintenance time\" takes a numeric argument.\n"));
gdb_printf (_("\"%ps\" takes a numeric argument.\n"),
styled_string (command_style.style (), "maintenance time"));
else
set_per_command_time (strtol (args, NULL, 10));
}
@ -120,7 +123,8 @@ static void
maintenance_space_display (const char *args, int from_tty)
{
if (args == NULL || *args == '\0')
gdb_printf ("\"maintenance space\" takes a numeric argument.\n");
gdb_printf ("\"%ps\" takes a numeric argument.\n",
styled_string (command_style.style (), "maintenance space"));
else
set_per_command_space (strtol (args, NULL, 10));
}
@ -630,9 +634,11 @@ maintenance_deprecate (const char *args, int from_tty)
{
if (args == NULL || *args == '\0')
{
gdb_printf (_("\"maintenance deprecate\" takes an argument,\n\
gdb_printf (_("\"%ps\" takes an argument,\n\
the command you want to deprecate, and optionally the replacement command\n\
enclosed in quotes.\n"));
enclosed in quotes.\n"),
styled_string (command_style.style (),
"maintenance deprecate"));
}
maintenance_do_deprecate (args, 1);
@ -644,8 +650,10 @@ maintenance_undeprecate (const char *args, int from_tty)
{
if (args == NULL || *args == '\0')
{
gdb_printf (_("\"maintenance undeprecate\" takes an argument, \n\
the command you want to undeprecate.\n"));
gdb_printf (_("\"%ps\" takes an argument, \n\
the command you want to undeprecate.\n"),
styled_string (command_style.style (),
"maintenance undeprecate"));
}
maintenance_do_deprecate (args, 0);

View file

@ -19,6 +19,7 @@
#include "command.h"
#include "cli/cli-cmds.h"
#include "cli/cli-style.h"
#include "memattr.h"
#include "target.h"
#include "target-dcache.h"
@ -91,7 +92,8 @@ require_user_regions (int from_tty)
/* Otherwise, let the user know how to get back. */
if (from_tty)
warning (_("Switching to manual control of memory regions; use "
"\"mem auto\" to fetch regions from the target again."));
"\"%ps\" to fetch regions from the target again."),
styled_string (command_style.style (), "mem auto"));
/* And create a new list (copy of the target-supplied regions) for the user
to modify. */

View file

@ -39,6 +39,7 @@
#include "solib.h"
#include "cli/cli-decode.h"
#include "cli/cli-setshow.h"
#include "cli/cli-style.h"
#include "target-descriptions.h"
#include "gdb_bfd.h"
#include "gdbsupport/filestuff.h"
@ -12814,8 +12815,9 @@ remote_target::remote_hostio_open (inferior *inf, const char *filename,
if (!warning_issued)
{
warning (_("File transfers from remote targets can be slow."
" Use \"set sysroot\" to access files locally"
" instead."));
" Use \"%ps\" to access files locally"
" instead."),
styled_string (command_style.style (), "set sysroot"));
warning_issued = 1;
}
}

View file

@ -860,18 +860,27 @@ update_solib_list (int from_tty)
if (not_found == 1)
warning (_ ("Could not load shared library symbols for %ps.\n"
"Do you need \"set solib-search-path\" "
"or \"set sysroot\"?"),
"Do you need \"%ps\" or \"%ps\"?"),
styled_string (file_name_style.style (),
not_found_filename));
not_found_filename),
styled_string (command_style.style (),
"set solib-search-path"),
styled_string (command_style.style (), "set sysroot"));
else if (not_found > 1)
warning (_ ("\
Could not load shared library symbols for %d libraries, e.g. %ps.\n\
Use the \"info sharedlibrary\" command to see the complete listing.\n\
Do you need \"set solib-search-path\" or \"set sysroot\"?"),
Use the \"%ps\" command to see the complete listing.\n\
Do you need \"%ps\" or \"%ps\"?"),
not_found,
styled_string (file_name_style.style (),
not_found_filename));
not_found_filename),
styled_string (command_style.style (),
"info sharedlibrary"),
styled_string (command_style.style (),
"set solib-search-path"),
styled_string (command_style.style (),
"set sysroot"));
}
}

View file

@ -1330,8 +1330,9 @@ There is NO WARRANTY, to the extent permitted by law.",
if (!interactive)
return;
gdb_printf (stream, ("\nType \"show copying\" and "
"\"show warranty\" for details.\n"));
gdb_printf (stream, ("\nType \"%ps\" and \"%ps\" for details.\n"),
styled_string (command_style.style (), "show copying"),
styled_string (command_style.style (), "show warranty"));
/* After the required info we print the configuration information. */
@ -1347,8 +1348,8 @@ There is NO WARRANTY, to the extent permitted by law.",
}
gdb_printf (stream, "\".\n");
gdb_printf (stream, _("Type \"show configuration\" "
"for configuration details.\n"));
gdb_printf (stream, _("Type \"%ps\" for configuration details.\n"),
styled_string (command_style.style (), "show configuration"));
if (REPORT_BUGS_TO[0])
{
@ -1364,10 +1365,11 @@ resources online at:\n <%ps>."),
styled_string (file_name_style.style (),
"http://www.gnu.org/software/gdb/documentation/"));
gdb_printf (stream, "\n\n");
gdb_printf (stream, _("For help, type \"help\".\n"));
gdb_printf (stream, _("For help, type \"%ps\".\n"),
styled_string (command_style.style (), "help"));
gdb_printf (stream,
_("Type \"apropos word\" to search for commands \
related to \"word\"."));
_("Type \"%ps\" to search for commands related to \"word\"."),
styled_string (command_style.style (), "apropos word"));
}
/* Print the details of GDB build-time configuration. */

View file

@ -22,6 +22,7 @@
#include "arch-utils.h"
#include "tui/tui.h"
#include "symtab.h"
#include "cli/cli-style.h"
#include "frame.h"
#include "regcache.h"
#include "inferior.h"
@ -532,9 +533,10 @@ tui_reg_command (const char *args, int from_tty)
}
else
{
gdb_printf (_("\"tui reg\" must be followed by the name of "
gdb_printf (_("\"%ps\" must be followed by the name of "
"either a register group,\nor one of 'next' "
"or 'prev'. Known register groups are:\n"));
"or 'prev'. Known register groups are:\n"),
styled_string (command_style.style (), "tui reg"));
bool first = true;
for (const struct reggroup *group : gdbarch_reggroups (gdbarch))

View file

@ -2587,8 +2587,9 @@ show_convenience (const char *ignore, int from_tty)
gdb_printf (_("No debugger convenience variables now defined.\n"
"Convenience variables have "
"names starting with \"$\";\n"
"use \"set\" as in \"set "
"$foo = 5\" to define them.\n"));
"use \"%ps\" as in \"%ps\" to define them.\n"),
styled_string (command_style.style (), "set"),
styled_string (command_style.style (), "set $foo = 5"));
}
}

View file

@ -3190,7 +3190,9 @@ Show whether to display kernel exceptions in child process."), NULL,
that we're missing some functionality. */
warning(_("\
cannot automatically find executable file or library to read symbols.\n\
Use \"file\" or \"dll\" command to load executable/libraries directly."));
Use \"%ps\" or \"%ps\" command to load executable/libraries directly.")
styled_string (command_style.style (), "file"),
styled_string (command_style.style (), "dll"));
}
}