Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 1/4] Add command styling to error messages
Date: Sun, 05 Apr 2026 05:28:38 -0600	[thread overview]
Message-ID: <20260405-more-error-style-v1-1-6c04da718875@tromey.com> (raw)
In-Reply-To: <20260405-more-error-style-v1-0-6c04da718875@tromey.com>

This changes a number of error messages in gdb to use command_style.
In some places I've added double quotes around the command name for
consistency with other messages.
---
 gdb/ada-exp.y                       |  4 +++-
 gdb/ada-tasks.c                     | 10 ++++++----
 gdb/breakpoint.c                    | 38 ++++++++++++++++++++++++-------------
 gdb/c-exp.y                         |  5 ++++-
 gdb/cli/cli-cmds.c                  | 30 +++++++++++++++++++----------
 gdb/cli/cli-script.c                | 33 +++++++++++++++++++++-----------
 gdb/cli/cli-utils.c                 | 13 +++++++++----
 gdb/compile/compile.c               |  6 ++++--
 gdb/d-exp.y                         |  4 +++-
 gdb/exec.c                          |  4 +++-
 gdb/guile/guile.c                   |  4 +++-
 gdb/inf-child.c                     |  3 ++-
 gdb/infcmd.c                        |  6 ++++--
 gdb/maint.c                         |  3 ++-
 gdb/parse.c                         |  4 +++-
 gdb/printcmd.c                      | 11 ++++++-----
 gdb/python/python.c                 |  3 ++-
 gdb/record-btrace.c                 |  4 +++-
 gdb/record.c                        |  6 ++++--
 gdb/remote-fileio.c                 | 11 ++++++++---
 gdb/remote.c                        | 17 +++++++++++++----
 gdb/symfile-mem.c                   | 16 ++++++++++++----
 gdb/symtab.c                        |  3 ++-
 gdb/target.c                        |  7 +++++--
 gdb/testsuite/gdb.base/commands.exp |  3 ++-
 gdb/testsuite/gdb.base/default.exp  |  2 +-
 26 files changed, 171 insertions(+), 79 deletions(-)

diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index 7c691d5a099..0262ce74c85 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -44,6 +44,7 @@
 #include "frame.h"
 #include "block.h"
 #include "ada-exp.h"
+#include "cli/cli-style.h"
 
 #define parse_type(ps) builtin_type (ps->gdbarch ())
 
@@ -1873,7 +1874,8 @@ write_var_or_type (struct parser_state *par_state,
       if (!current_program_space->has_full_symbols ()
 	  && !current_program_space->has_partial_symbols ()
 	  && block == NULL)
-	error (_("No symbol table is loaded.  Use the \"file\" command."));
+	error (_("No symbol table is loaded.  Use the \"%ps\" command."),
+	       styled_string (command_style.style (), "file"));
       if (block == par_state->expression_context_block)
 	error (_("No definition of \"%s\" in current context."), name0.ptr);
       else
diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c
index 848c832785e..6bd6600b802 100644
--- a/gdb/ada-tasks.c
+++ b/gdb/ada-tasks.c
@@ -1227,8 +1227,9 @@ info_task (struct ui_out *uiout, const char *taskno_str, struct inferior *inf)
     }
 
   if (taskno <= 0 || taskno > data->task_list.size ())
-    error (_("Task ID %d not known.  Use the \"info tasks\" command to\n"
-	     "see the IDs of currently known tasks"), taskno);
+    error (_("Task ID %d not known.  Use the \"%ps\" command to\n"
+	     "see the IDs of currently known tasks"),
+	   taskno, styled_string (command_style.style (), "info tasks"));
   task_info = &data->task_list[taskno - 1];
 
   /* Print the Ada task ID.  */
@@ -1348,8 +1349,9 @@ task_command_1 (const char *taskno_str, int from_tty, struct inferior *inf)
   struct ada_tasks_inferior_data *data = get_ada_tasks_inferior_data (inf);
 
   if (taskno <= 0 || taskno > data->task_list.size ())
-    error (_("Task ID %d not known.  Use the \"info tasks\" command to\n"
-	     "see the IDs of currently known tasks"), taskno);
+    error (_("Task ID %d not known.  Use the \"%ps\" command to\n"
+	     "see the IDs of currently known tasks"),
+	   taskno, styled_string (command_style.style (), "info tasks"));
   task_info = &data->task_list[taskno - 1];
 
   if (!ada_task_is_alive (task_info))
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index d7be1b44229..fdff6e8fc94 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -1363,8 +1363,9 @@ check_no_tracepoint_commands (struct command_line *commands)
   for (c = commands; c; c = c->next)
     {
       if (c->control_type == while_stepping_control)
-	error (_("The 'while-stepping' command can "
-		 "only be used for tracepoints"));
+	error (_("The \"%ps\" command can "
+		 "only be used for tracepoints"),
+	       styled_string (command_style.style (), "while-steppinge"));
 
       check_no_tracepoint_commands (c->body_list_0.get ());
       check_no_tracepoint_commands (c->body_list_1.get ());
@@ -1373,10 +1374,12 @@ check_no_tracepoint_commands (struct command_line *commands)
 	 lines and also empty lines.  So, we only need to check for
 	 command directly.  */
       if (strstr (c->line, "collect ") == c->line)
-	error (_("The 'collect' command can only be used for tracepoints"));
+	error (_("The \"%ps\" command can only be used for tracepoints"),
+	       styled_string (command_style.style (), "collect"));
 
       if (strstr (c->line, "teval ") == c->line)
-	error (_("The 'teval' command can only be used for tracepoints"));
+	error (_("The \"%ps\" command can only be used for tracepoints"),
+	       styled_string (command_style.style (), "teval"));
     }
 }
 
@@ -1482,16 +1485,22 @@ validate_commands_for_breakpoint (struct breakpoint *b,
 	  if (c->control_type == while_stepping_control)
 	    {
 	      if (b->type == bp_fast_tracepoint)
-		error (_("The 'while-stepping' command "
-			 "cannot be used for fast tracepoint"));
+		error (_("The \"%ps\" command "
+			 "cannot be used for fast tracepoint"),
+		       styled_string (command_style.style (),
+				      "while-stepping"));
 	      else if (b->type == bp_static_tracepoint
 		       || b->type == bp_static_marker_tracepoint)
-		error (_("The 'while-stepping' command "
-			 "cannot be used for static tracepoint"));
+		error (_("The \"%ps\" command "
+			 "cannot be used for static tracepoint"),
+		       styled_string (command_style.style (),
+				      "while-stepping"));
 
 	      if (while_stepping)
-		error (_("The 'while-stepping' command "
-			 "can be used only once"));
+		error (_("The \"%ps\" command "
+			 "can be used only once"),
+		       styled_string (command_style.style (),
+				      "while-stepping"));
 	      else
 		while_stepping = c;
 	    }
@@ -1507,7 +1516,9 @@ validate_commands_for_breakpoint (struct breakpoint *b,
 	  for (; c2; c2 = c2->next)
 	    {
 	      if (c2->control_type == while_stepping_control)
-		error (_("The 'while-stepping' command cannot be nested"));
+		error (_("The \"%ps\" command cannot be nested"),
+		       styled_string (command_style.style (),
+				      "while-stepping"));
 	    }
 	}
     }
@@ -14363,8 +14374,9 @@ trace_pass_command (const char *args, int from_tty)
   ULONGEST count;
 
   if (args == 0 || *args == 0)
-    error (_("passcount command requires an "
-	     "argument (count + optional TP num)"));
+    error (_("\"%ps\" command requires an "
+	     "argument (count + optional TP num)"),
+	   styled_string (command_style.style (), "passcount"));
 
   count = strtoulst (args, &args, 10);	/* Count comes first, then TP num.  */
 
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index a4a910df712..b036e13d188 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -52,6 +52,7 @@
 #include "target-float.h"
 #include "c-exp.h"
 #include "macroexp.h"
+#include "cli/cli-style.h"
 
 #define parse_type(ps) builtin_type (ps->gdbarch ())
 
@@ -1203,7 +1204,9 @@ variable:	name_not_typename
 				{
 				  if (!current_program_space->has_full_symbols ()
 				      && !current_program_space->has_partial_symbols ())
-				    error (_("No symbol table is loaded.  Use the \"file\" command."));
+				    error (_("No symbol table is loaded.  Use the \"%ps\" command."),
+					   styled_string (command_style.style (),
+							  "file"));
 				  else
 				    error (_("No symbol \"%s\" in current context."),
 					   arg.c_str ());
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index e58553245b3..761158f2ae9 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -245,7 +245,8 @@ with_command_1 (const char *set_cmd_prefix,
   gdb_assert (set_cmd != nullptr);
 
   if (!set_cmd->var.has_value ())
-    error (_("Cannot use this setting with the \"with\" command"));
+    error (_("Cannot use this setting with the \"%ps\" command"),
+	   styled_string (command_style.style (), "with"));
 
   std::string temp_value
     = (delim == nullptr ? args : std::string (args, delim - args));
@@ -489,7 +490,9 @@ static void
 pwd_command (const char *args, int from_tty)
 {
   if (args)
-    error (_("The \"pwd\" command does not take an argument: %s"), args);
+    error (_("The \"%ps\" command does not take an argument: %s"),
+	   styled_string (command_style.style (), "pwd"),
+	   args);
 
   gdb::unique_xmalloc_ptr<char> cwd (getcwd (NULL, 0));
 
@@ -718,7 +721,8 @@ source_script_with_search (const char *file, int from_tty, int search_path)
 {
 
   if (file == NULL || *file == 0)
-    error (_("source command requires file name of file to source."));
+    error (_("\"%ps\" command requires file name of file to source."),
+	   styled_string (command_style.style (), "source"));
 
   std::optional<open_script> opened = find_and_open_script (file, search_path);
   if (!opened)
@@ -1276,8 +1280,9 @@ list_command (const char *arg, int from_tty)
 	    print_source_lines (cursal.symtab,
 				source_lines_range (cursal.line), 0);
 	  else
-	    error (_("End of the file was already reached, use \"list .\" to"
-		     " list the current location again"));
+	    error (_("End of the file was already reached, use \"%ps\" to"
+		     " list the current location again"),
+		   styled_string (command_style.style (), "list ."));
 	}
 
       /* "l -" lists previous ten lines, the ones before the ten just
@@ -1354,7 +1359,8 @@ list_command (const char *arg, int from_tty)
 
   if (!current_program_space->has_full_symbols ()
       && !current_program_space->has_partial_symbols ())
-    error (_("No symbol table is loaded.  Use the \"file\" command."));
+    error (_("No symbol table is loaded.  Use the \"%ps\" command."),
+	   styled_string (command_style.style (), "file"));
 
   std::vector<symtab_and_line> sals;
   symtab_and_line sal, sal_end;
@@ -1535,7 +1541,8 @@ list_command (const char *arg, int from_tty)
     set_repeat_arguments ("");
 
   if (dummy_beg && sal_end.symtab == nullptr)
-    error (_("No default source file yet.  Do \"help list\"."));
+    error (_("No default source file yet.  Do \"%ps\"."),
+	   styled_string (command_style.style (), "help list"));
   if (dummy_beg)
     {
       source_lines_range range (sal_end.line + 1,
@@ -1543,7 +1550,8 @@ list_command (const char *arg, int from_tty)
       print_source_lines (sal_end.symtab, range, 0);
     }
   else if (sal.symtab == nullptr)
-    error (_("No default source file yet.  Do \"help list\"."));
+    error (_("No default source file yet.  Do \"%ps\"."),
+	   styled_string (command_style.style (), "help list"));
   else if (no_end)
     {
       for (const symtab_and_line &s : sals)
@@ -2101,7 +2109,8 @@ validate_aliased_command (const char *command)
     = lookup_cmd_1 (& command, cmdlist, NULL, &default_args, 1);
 
   if (c == NULL || c == (struct cmd_list_element *) -1)
-    error (_("Invalid command to alias to: %s"), command);
+    error (_("Invalid command to alias to: %ps"),
+	   styled_string (command_style.style (), command));
 
   if (!default_args.empty ())
     error (_("Cannot define an alias of an alias that has default args"));
@@ -2199,7 +2208,8 @@ alias_command (const char *args, int from_tty)
 	/* Check ALIAS differs from the found CMD.  */
 
 	if (cmd->prefix == prefix_cmd && streq (alias_name, cmd->name))
-	  error (_("Alias %s is the name of an existing command"), alias);
+	  error (_("Alias \"%ps\" is the name of an existing command"),
+		 styled_string (command_style.style (), alias));
       }
   }
 
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 253e63af570..13ef2fb03ce 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -160,13 +160,17 @@ build_command_line (enum command_control_type type, const char *args)
   if (args == NULL || *args == '\0')
     {
       if (type == if_control)
-	error (_("if command requires an argument."));
+	error (_("\"%ps\" command requires an argument."),
+	       styled_string (command_style.style (), "if"));
       else if (type == while_control)
-	error (_("while command requires an argument."));
+	error (_("\"%ps\" command requires an argument."),
+	       styled_string (command_style.style (), "while"));
       else if (type == define_control)
-	error (_("define command requires an argument."));
+	error (_("\"%ps\" command requires an argument."),
+	       styled_string (command_style.style (), "define"));
       else if (type == document_control)
-	error (_("document command requires an argument."));
+	error (_("\"%ps\" command requires an argument."),
+	       styled_string (command_style.style (), "document"));
     }
   gdb_assert (args != NULL);
 
@@ -1338,7 +1342,8 @@ validate_comname (const char **comname)
 
       c = lookup_cmd (&tem, cmdlist, "", NULL, 0, 1);
       if (!c->is_prefix ())
-	error (_("\"%s\" is not a prefix command."), prefix.c_str ());
+	error (_("\"%ps\" is not a prefix command."),
+	       styled_string (command_style.style (), prefix.c_str ()));
 
       list = c->subcommands;
       *comname = last_word;
@@ -1411,7 +1416,8 @@ do_define_command (const char *comname, int from_tty,
       else
 	q = query (_("Really redefine built-in command \"%s\"? "), c->name);
       if (!q)
-	error (_("Command \"%s\" not redefined."), c->name);
+	error (_("Command \"%ps\" not redefined."),
+	       styled_string (command_style.style (), c->name));
     }
 
   /* If this new command is a hook, then mark the command which it
@@ -1520,17 +1526,21 @@ do_document_command (const char *comname, int from_tty,
 
   lookup_cmd_composition (comfull, &alias, &prefix_cmd, &c);
   if (c == nullptr)
-    error (_("Undefined command: \"%s\"."), comfull);
+    error (_("Undefined command: \"%ps\"."),
+	   styled_string (command_style.style (), comfull));
   else if (c == CMD_LIST_AMBIGUOUS)
-    error (_("Ambiguous command: \"%s\"."), comfull);
+    error (_("Ambiguous command: \"%ps\"."),
+	   styled_string (command_style.style (), comfull));
 
   if (c->theclass != class_user
       && (alias == nullptr || alias->theclass != class_alias))
     {
       if (alias == nullptr)
-	error (_("Command \"%s\" is built-in."), comfull);
+	error (_("Command \"%ps\" is built-in."),
+	       styled_string (command_style.style (), comfull));
       else
-	error (_("Alias \"%s\" is built-in."), comfull);
+	error (_("Alias \"%ps\" is built-in."),
+	       styled_string (command_style.style (), comfull));
     }
 
   /* If we found an alias of class_alias, the user is documenting this
@@ -1595,7 +1605,8 @@ define_prefix_command (const char *comname, int from_tty)
   c = lookup_cmd_exact (comname, *list);
 
   if (c != nullptr && c->theclass != class_user)
-    error (_("Command \"%s\" is built-in."), comfull);
+    error (_("Command \"%ps\" is built-in."),
+	   styled_string (command_style.style (), comfull));
 
   if (c != nullptr && c->is_prefix ())
     {
diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c
index 347e2918dfe..18f112c1aad 100644
--- a/gdb/cli/cli-utils.c
+++ b/gdb/cli/cli-utils.c
@@ -17,7 +17,9 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+#include "cli/cli-style.h"
 #include "cli/cli-utils.h"
+#include "ui-out.h"
 #include "value.h"
 
 
@@ -183,9 +185,11 @@ report_unrecognized_option_error (const char *command, const char *args)
 {
   std::string option = extract_arg (&args);
 
-  error (_("Unrecognized option '%s' to %s command.  "
-	   "Try \"help %s\"."), option.c_str (),
-	 command, command);
+  error (_("Unrecognized option '%s' to \"%ps\" command.  "
+	   "Try \"%p[help %s%p]\"."),
+	 option.c_str (),
+	 styled_string (command_style.style (), command),
+	 command_style.style ().ptr (), command, nullptr);
 }
 
 /* See documentation in cli-utils.h.  */
@@ -434,5 +438,6 @@ void
 validate_flags_qcs (const char *which_command, qcs_flags *flags)
 {
   if (flags->cont && flags->silent)
-    error (_("%s: -c and -s are mutually exclusive"), which_command);
+    error (_("%ps: -c and -s are mutually exclusive"),
+	   styled_string (command_style.style (), which_command));
 }
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index a64297bcbe1..c0b548fefd8 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -22,6 +22,7 @@
 #include "ui-out.h"
 #include "command.h"
 #include "cli/cli-script.h"
+#include "cli/cli-style.h"
 #include "cli/cli-utils.h"
 #include "cli/cli-option.h"
 #include "completer.h"
@@ -630,8 +631,9 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
   if (!compile_gcc.empty ())
     {
       if (compiler->version () < GCC_FE_VERSION_1)
-	error (_("Command 'set compile-gcc' requires GCC version 6 or higher "
-		 "(libcc1 interface version 1 or higher)"));
+	error (_("Command \"%ps\" requires GCC version 6 or higher "
+		 "(libcc1 interface version 1 or higher)"),
+	       styled_string (command_style.style (), "set compile-gcc"));
 
       compiler->set_driver_filename (compile_gcc.c_str ());
     }
diff --git a/gdb/d-exp.y b/gdb/d-exp.y
index a3b1b507ef9..1031eb1ecca 100644
--- a/gdb/d-exp.y
+++ b/gdb/d-exp.y
@@ -48,6 +48,7 @@
 #include "block.h"
 #include "type-stack.h"
 #include "expop.h"
+#include "cli/cli-style.h"
 
 #define parse_type(ps) builtin_type (ps->gdbarch ())
 #define parse_d_type(ps) builtin_d_type (ps->gdbarch ())
@@ -468,7 +469,8 @@ PrimaryExpression:
 			pstate->push_new<var_msym_value_operation> (msymbol);
 		      else if (!current_program_space->has_full_symbols ()
 			       && !current_program_space->has_partial_symbols ())
-			error (_("No symbol table is loaded.  Use the \"file\" command"));
+			error (_("No symbol table is loaded.  Use the \"%ps\" command"),
+			       styled_string (command_style.style (), "file"));
 		      else
 			error (_("No symbol \"%s\" in current context."),
 			       copy.c_str ());
diff --git a/gdb/exec.c b/gdb/exec.c
index 0ad3944004d..b1b2d2d190d 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -524,7 +524,9 @@ void
 no_executable_specified_error ()
 {
   error (_("No executable file specified.\n\
-Use the \"file\" or \"exec-file\" command."));
+Use the \"%ps\" or \"%ps\" command."),
+	 styled_string (command_style.style (), "file"),
+	 styled_string (command_style.style (), "exec-file"));
 }
 
 /*  Process the first arg in ARGS as the new exec file.
diff --git a/gdb/guile/guile.c b/gdb/guile/guile.c
index 3e876f9386b..ec5f6d08951 100644
--- a/gdb/guile/guile.c
+++ b/gdb/guile/guile.c
@@ -23,6 +23,7 @@
 #include "breakpoint.h"
 #include "cli/cli-cmds.h"
 #include "cli/cli-script.h"
+#include "cli/cli-style.h"
 #include "cli/cli-utils.h"
 #include "command.h"
 #include "top.h"
@@ -256,7 +257,8 @@ gdbscm_eval_from_control_command
   char *script;
 
   if (cmd->body_list_1 != nullptr)
-    error (_("Invalid \"guile\" block structure."));
+    error (_("Invalid \"%ps\" block structure."),
+	   styled_string (command_style.style (), "guile"));
 
   script = compute_scheme_string (cmd->body_list_0.get ());
   gdb::unique_xmalloc_ptr<char> msg = gdbscm_safe_eval_string (script, 0);
diff --git a/gdb/inf-child.c b/gdb/inf-child.c
index 7983ecb0d92..a87aa925133 100644
--- a/gdb/inf-child.c
+++ b/gdb/inf-child.c
@@ -171,7 +171,8 @@ void
 inf_child_target::disconnect (const char *args, int from_tty)
 {
   if (args != NULL)
-    error (_("Argument given to \"disconnect\"."));
+    error (_("Argument given to \"%ps\"."),
+	   styled_string (command_style.style (), "disconnect"));
 
   /* This offers to detach/kill current inferiors, and then pops all
      targets.  */
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 98b45f884b1..7bb9e1a22eb 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -1949,11 +1949,13 @@ finish_command (const char *arg, int from_tty)
   prepare_execution_command (current_inferior ()->top_target (), async_exec);
 
   if (arg)
-    error (_("The \"finish\" command does not take any arguments."));
+    error (_("The \"%ps\" command does not take any arguments."),
+	   styled_string (command_style.style (), "finish"));
 
   frame = get_prev_frame (get_selected_frame (_("No selected frame.")));
   if (frame == 0)
-    error (_("\"finish\" not meaningful in the outermost frame."));
+    error (_("\"%ps\" not meaningful in the outermost frame."),
+	   styled_string (command_style.style (), "finish"));
 
   clear_proceed_status (0);
 
diff --git a/gdb/maint.c b/gdb/maint.c
index b29da2b48f8..1daa6ce1d2e 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -1141,7 +1141,8 @@ set_per_command_cmd (const char *args, int from_tty)
 
   val = parse_cli_boolean_value (args);
   if (val < 0)
-    error (_("Bad value for 'mt set per-command no'."));
+    error (_("Bad value for \"%ps\"."),
+	   styled_string (command_style.style (), "mt set per-command no"));
 
   for (list = per_command_setlist; list != NULL; list = list->next)
     if (list->var->type () == var_boolean)
diff --git a/gdb/parse.c b/gdb/parse.c
index 9769150a134..fd190d6e15e 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -39,6 +39,7 @@
 #include "language.h"
 #include "parser-defs.h"
 #include "cli/cli-cmds.h"
+#include "cli/cli-style.h"
 #include "symfile.h"
 #include "inferior.h"
 #include "target-float.h"
@@ -150,7 +151,8 @@ parser_state::push_symbol (const char *name, block_symbol sym)
 	push_new<expr::var_msym_value_operation> (msymbol);
       else if (!current_program_space->has_full_symbols ()
 	       && !current_program_space->has_partial_symbols ())
-	error (_("No symbol table is loaded.  Use the \"file\" command."));
+	error (_("No symbol table is loaded.  Use the \"%ps\" command."),
+	       styled_string (command_style.style (), "file"));
       else
 	error (_("No symbol \"%s\" in current context."), name);
     }
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 38a2e231d88..ae498395436 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1232,13 +1232,14 @@ static void
 validate_format (struct format_data fmt, const char *cmdname)
 {
   if (fmt.size != 0)
-    error (_("Size letters are meaningless in \"%s\" command."), cmdname);
+    error (_("Size letters are meaningless in \"%ps\" command."),
+	   styled_string (command_style.style (), cmdname));
   if (fmt.count != 1)
-    error (_("Item count other than 1 is meaningless in \"%s\" command."),
-	   cmdname);
+    error (_("Item count other than 1 is meaningless in \"%ps\" command."),
+	   styled_string (command_style.style (), cmdname));
   if (fmt.format == 'i')
-    error (_("Format letter \"%c\" is meaningless in \"%s\" command."),
-	   fmt.format, cmdname);
+    error (_("Format letter \"%c\" is meaningless in \"%ps\" command."),
+	   fmt.format, styled_string (command_style.style (), cmdname));
 }
 
 /* Parse print command format string into *OPTS and update *EXPP.
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 6e13ab5bb3f..f981817f0be 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -452,7 +452,8 @@ gdbpy_eval_from_control_command (const struct extension_language_defn *extlang,
 				 struct command_line *cmd)
 {
   if (cmd->body_list_1 != nullptr)
-    error (_("Invalid \"python\" block structure."));
+    error (_("Invalid \"%ps\" block structure."),
+	   styled_string (command_style.style (), "python"));
 
   gdbpy_enter enter_py;
 
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index bded22af8e6..90a6346a467 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -3035,7 +3035,9 @@ cmd_set_record_btrace_cpu (const char *args, int from_tty)
       stepping = 0;
     }
   else
-    error (_("Bad format.  See \"help set record btrace cpu\"."));
+    error (_("Bad format.  See \"%ps\"."),
+	   styled_string (command_style.style (),
+			  "help set record btrace cpu"));
 
   if (USHRT_MAX < family)
     error (_("Cpu family too big."));
diff --git a/gdb/record.c b/gdb/record.c
index c01a1fd2bcf..35f9f0eb1e4 100644
--- a/gdb/record.c
+++ b/gdb/record.c
@@ -23,6 +23,7 @@
 #include "observable.h"
 #include "inferior.h"
 #include "gdbsupport/common-utils.h"
+#include "cli/cli-style.h"
 #include "cli/cli-utils.h"
 #include "disasm.h"
 #include "interps.h"
@@ -87,8 +88,9 @@ record_preopen (void)
 {
   /* Check if a record target is already running.  */
   if (find_record_target () != NULL)
-    error (_("The process is already being recorded.  Use \"record stop\" to "
-	     "stop recording first."));
+    error (_("The process is already being recorded.  Use \"%ps\" to "
+	     "stop recording first."),
+	   styled_string (command_style.style (), "record stop"));
 }
 
 /* See record.h.  */
diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c
index 0b56e1ddca9..ef608cabfab 100644
--- a/gdb/remote-fileio.c
+++ b/gdb/remote-fileio.c
@@ -22,6 +22,7 @@
 #include "event-top.h"
 #include "extract-store-integer.h"
 #include "cli/cli-cmds.h"
+#include "cli/cli-style.h"
 #include "remote.h"
 #include "gdbsupport/gdb_wait.h"
 #include <sys/stat.h>
@@ -1226,15 +1227,19 @@ set_system_call_allowed (const char *args, int from_tty)
 	  return;
 	}
     }
-  error (_("Illegal argument for \"set remote system-call-allowed\" command"));
+  error (_("Illegal argument for \"%ps\" command"),
+	 styled_string (command_style.style (),
+			"set remote system-call-allowed"));
 }
 
 static void
 show_system_call_allowed (const char *args, int from_tty)
 {
   if (args)
-    error (_("Garbage after \"show remote "
-	     "system-call-allowed\" command: `%s'"), args);
+    error (_("Garbage after \"%ps\" command: `%s'"),
+	   styled_string (command_style.style (),
+			  "show remote system-call-allowed"),
+	   args);
   gdb_printf ("Calling host system(3) call from target is %sallowed\n",
 	      remote_fio_system_call_allowed ? "" : "not ");
 }
diff --git a/gdb/remote.c b/gdb/remote.c
index 3ec56a6d61b..23ef6145620 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -7038,7 +7038,8 @@ void
 remote_target::disconnect (const char *args, int from_tty)
 {
   if (args)
-    error (_("Argument given to \"disconnect\" when remotely debugging."));
+    error (_("Argument given to \"%ps\" when remotely debugging."),
+	   styled_string (command_style.style (), "disconnect"));
 
   /* Make sure we unpush even the extended remote targets.  Calling
      target_mourn_inferior won't unpush, and
@@ -11546,9 +11547,15 @@ Remote replied unexpectedly while setting startup-with-shell: %s"),
       /* vRun was not supported.  Fail if we need it to do what the
 	 user requested.  */
       if (remote_exec_file[0])
-	error (_("Remote target does not support \"set remote exec-file\""));
+	error (_("Remote target does not support \"%ps\""),
+	       styled_string (command_style.style (),
+			      "set remote exec-file"));
       if (!args.empty ())
-	error (_("Remote target does not support \"set args\" or run ARGS"));
+	error (_("Remote target does not support \"%ps\" or \"%ps\""),
+	       styled_string (command_style.style (),
+			      "set args"),
+	       styled_string (command_style.style (),
+			      "run ARGS"));
 
       /* Fall back to "R".  */
       extended_remote_restart ();
@@ -12594,7 +12601,9 @@ remote_target::rcmd (const char *command, struct ui_file *outbuf)
 
   if ((strlen (rs->buf.data ()) + strlen (command) * 2 + 8/*misc*/)
       > get_remote_packet_size ())
-    error (_("\"monitor\" command ``%s'' is too long."), command);
+    error (_("\"%ps\" command ``%s'' is too long."),
+	   styled_string (command_style.style (), "monitor"),
+	   command);
 
   /* Encode the actual command.  */
   bin2hex ((const gdb_byte *) command, p, strlen (command));
diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c
index b749c90afd2..941292d3128 100644
--- a/gdb/symfile-mem.c
+++ b/gdb/symfile-mem.c
@@ -54,6 +54,7 @@
 #include "elf/common.h"
 #include "gdb_bfd.h"
 #include "inferior.h"
+#include "cli/cli-style.h"
 
 /* Verify parameters of target_read_memory_bfd and target_read_memory are
    compatible.  */
@@ -91,7 +92,9 @@ symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR addr,
   symfile_add_flags add_flags = SYMFILE_NOT_FILENAME;
 
   if (bfd_get_flavour (templ) != bfd_target_elf_flavour)
-    error (_("add-symbol-file-from-memory not supported for this target"));
+    error (_("\"%ps\" not supported for this target"),
+	   styled_string (command_style.style (),
+			  "add-symbol-file-from-memory"));
 
   nbfd = bfd_elf_bfd_from_remote_memory (templ, addr, size, &loadbase,
 					 target_read_memory_bfd);
@@ -138,7 +141,9 @@ add_symbol_file_from_memory_command (const char *args, int from_tty)
   struct bfd *templ;
 
   if (args == NULL)
-    error (_("add-symbol-file-from-memory requires an expression argument"));
+    error (_("\"%ps\" requires an expression argument"),
+	   styled_string (command_style.style (),
+			  "add-symbol-file-from-memory"));
 
   addr = parse_and_eval_address (args);
 
@@ -148,8 +153,11 @@ add_symbol_file_from_memory_command (const char *args, int from_tty)
   else
     templ = current_program_space->exec_bfd ();
   if (templ == NULL)
-    error (_("Must use symbol-file or exec-file "
-	     "before add-symbol-file-from-memory."));
+    error (_("Must use \"%ps\" or \"%ps\" before \"%ps\"."),
+	   styled_string (command_style.style (), "symbol-file"),
+	   styled_string (command_style.style (), "exec-file"),
+	   styled_string (command_style.style (),
+			  "add-symbol-file-from-memory"));
 
   symbol_file_add_from_memory (templ, addr, 0, NULL, from_tty);
 }
diff --git a/gdb/symtab.c b/gdb/symtab.c
index e02744331c6..a6b145e5331 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4541,7 +4541,8 @@ info_sources_command (const char *args, int from_tty)
 {
   if (!current_program_space->has_full_symbols ()
       && !current_program_space->has_partial_symbols ())
-    error (_("No symbol table is loaded.  Use the \"file\" command."));
+    error (_("No symbol table is loaded.  Use the \"%ps\" command."),
+	   styled_string (command_style.style (), "file"));
 
   filename_partial_match_opts match_opts;
   auto group = make_info_sources_options_def_group (&match_opts);
diff --git a/gdb/target.c b/gdb/target.c
index 359618e800f..60c04b04b01 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -2899,7 +2899,9 @@ find_default_run_target (const char *do_mesg)
     return the_native_target;
 
   if (do_mesg != NULL)
-    error (_("Don't know how to %s.  Try \"help target\"."), do_mesg);
+    error (_("Don't know how to %s.  Try \"%ps\"."),
+	   do_mesg,
+	   styled_string (command_style.style (), "help target"));
   return NULL;
 }
 
@@ -4244,7 +4246,8 @@ static void
 default_rcmd (struct target_ops *self, const char *command,
 	      struct ui_file *output)
 {
-  error (_("\"monitor\" command not supported by this target."));
+  error (_("\"%ps\" command not supported by this target."),
+	 styled_string (command_style.style (), "monitor"));
 }
 
 static void
diff --git a/gdb/testsuite/gdb.base/commands.exp b/gdb/testsuite/gdb.base/commands.exp
index 77da367b2ac..b8b44d8f874 100644
--- a/gdb/testsuite/gdb.base/commands.exp
+++ b/gdb/testsuite/gdb.base/commands.exp
@@ -1108,7 +1108,8 @@ proc define_if_without_arg_test {} {
 	    }
 	}
 
-	gdb_test "$cmd" "$cmd command requires an argument." "type $cmd without args"
+	gdb_test "$cmd" "\"$cmd\" command requires an argument." \
+	    "type $cmd without args"
     }
 }
 
diff --git a/gdb/testsuite/gdb.base/default.exp b/gdb/testsuite/gdb.base/default.exp
index 5917181effb..002f6354e7a 100644
--- a/gdb/testsuite/gdb.base/default.exp
+++ b/gdb/testsuite/gdb.base/default.exp
@@ -951,7 +951,7 @@ gdb_test "stepi" "The program is not being run."
 #test signal
 gdb_test "signal" "The program is not being run."
 #test source
-gdb_test "source" "source command requires file name of file to source..*|No such file or directory.*"
+gdb_test "source" "\"source\" command requires file name of file to source..*|No such file or directory.*"
 #test step "s" abbreviation
 gdb_test "s" "The program is not being run." "step \"s\" abbreviation #2"
 #test step

-- 
2.49.0


  reply	other threads:[~2026-04-05 11:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-05 11:28 [PATCH 0/4] Add more styling of " Tom Tromey
2026-04-05 11:28 ` Tom Tromey [this message]
2026-04-05 11:28 ` [PATCH 2/4] Add filename styling to " Tom Tromey
2026-04-05 11:28 ` [PATCH 3/4] Add variable " Tom Tromey
2026-04-05 11:28 ` [PATCH 4/4] Add function " Tom Tromey
2026-04-05 12:55 ` [PATCH 0/4] Add more styling of " Andrew Burgess
2026-04-09  1:10   ` 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=20260405-more-error-style-v1-1-6c04da718875@tromey.com \
    --to=tom@tromey.com \
    --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