From: Tom Tromey Date: Sat, 18 May 2024 17:35:32 +0000 (-0600) Subject: Introduce "command" styling X-Git-Tag: gdb-16-branchpoint~116 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9e69a2e127940cc577d4e0c6eefdfe33a31ea397;p=thirdparty%2Fbinutils-gdb.git 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 Reviewed-By: Keith Seitz Approved-By: Andrew Burgess --- diff --git a/gdb/NEWS b/gdb/NEWS index 7f0bd7edfc8..49a3bc10cf1 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -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 diff --git a/gdb/auto-load.c b/gdb/auto-load.c index 513c1df4b7b..a8f3a8d5fdd 100644 --- a/gdb/auto-load.c +++ b/gdb/auto-load.c @@ -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; } diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index 8dafb0a0c75..60100fbe54d 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -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; } diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index 163012a6bec..295119494ce 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -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", diff --git a/gdb/cli/cli-style.c b/gdb/cli/cli-style.c index 36a8bd9c526..fa582a7d4d0 100644 --- a/gdb/cli/cli-style.c +++ b/gdb/cli/cli-style.c @@ -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\ diff --git a/gdb/cli/cli-style.h b/gdb/cli/cli-style.h index 5052b867cfa..24ec2ce0ad4 100644 --- a/gdb/cli/cli-style.h +++ b/gdb/cli/cli-style.h @@ -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; diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c index 7f6b72bde49..e1ea020bd5c 100644 --- a/gdb/darwin-nat.c +++ b/gdb/darwin-nat.c @@ -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 ()); } diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 85ac3d9aab6..0254b5aa815 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -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. diff --git a/gdb/dwarf2/read-gdb-index.c b/gdb/dwarf2/read-gdb-index.c index c0a33a0c969..4dea5595734 100644 --- a/gdb/dwarf2/read-gdb-index.c +++ b/gdb/dwarf2/read-gdb-index.c @@ -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; diff --git a/gdb/exec.c b/gdb/exec.c index 73280ad59e7..a1fed7794fb 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -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; } diff --git a/gdb/inf-child.c b/gdb/inf-child.c index df993b624dd..b6b3750fbb8 100644 --- a/gdb/inf-child.c +++ b/gdb/inf-child.c @@ -33,6 +33,7 @@ #include "gdbsupport/agent.h" #include "gdbsupport/gdb_wait.h" #include "gdbsupport/filestuff.h" +#include "cli/cli-style.h" #include #include @@ -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. */ diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 5c0e3f51162..9fcbadbe023 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -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 diff --git a/gdb/infrun.c b/gdb/infrun.c index 43eca814e29..8a10119487c 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -19,6 +19,7 @@ along with this program. If not, see . */ #include "cli/cli-cmds.h" +#include "cli/cli-style.h" #include "displaced-stepping.h" #include "infrun.h" #include @@ -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 diff --git a/gdb/main.c b/gdb/main.c index 14337fbda22..33cdd900994 100644 --- a/gdb/main.c +++ b/gdb/main.c @@ -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\ diff --git a/gdb/maint.c b/gdb/maint.c index 237c9d8c8a3..4fc70d7d0d8 100644 --- a/gdb/maint.c +++ b/gdb/maint.c @@ -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); diff --git a/gdb/memattr.c b/gdb/memattr.c index 2df8769742d..34999293c44 100644 --- a/gdb/memattr.c +++ b/gdb/memattr.c @@ -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. */ diff --git a/gdb/remote.c b/gdb/remote.c index f4112991568..8e3819bdb75 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -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; } } diff --git a/gdb/solib.c b/gdb/solib.c index fdefdf0b142..4a04f1ddb1f 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -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")); + } } diff --git a/gdb/top.c b/gdb/top.c index d750f3305f2..c7a62c15ae2 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -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. */ diff --git a/gdb/tui/tui-regs.c b/gdb/tui/tui-regs.c index 927b11fce4f..5158c0662ea 100644 --- a/gdb/tui/tui-regs.c +++ b/gdb/tui/tui-regs.c @@ -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)) diff --git a/gdb/value.c b/gdb/value.c index a18491602a8..e498632fe3c 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -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")); } } diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index f2d0633b32f..828334e9f5f 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -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")); } }