Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH 0/4] Add more styling of error messages
@ 2026-04-05 11:28 Tom Tromey
  2026-04-05 11:28 ` [PATCH 1/4] Add command styling to " Tom Tromey
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Tom Tromey @ 2026-04-05 11:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This series adds more styling of error messages.  I searched through
error messages for common patterns to find the places to edit.  So, I
have probably missed a few.

I fixed up some quoting in the "command style" patch, but in other
spots I left it alone.

I didn't write new tests.  I don't know how anyone else feels about
this but I tend to think that testing the styling of error messages is
overkill.

There are still more styles that could be applied, for instance line
numbers.  Also I discovered that the previous fix to allow error() to
be styled did not apply to throw_error et al.  So, some more work
there is needed.

Regression tested on x86-64 Fedora 40.

Signed-off-by: Tom Tromey <tom@tromey.com>
---
Tom Tromey (4):
      Add command styling to error messages
      Add filename styling to error messages
      Add variable styling to error messages
      Add function styling to error messages

 gdb/ada-exp.y                       |  8 +++--
 gdb/ada-tasks.c                     | 10 ++++---
 gdb/amd64-linux-tdep.c              |  5 ++--
 gdb/breakpoint.c                    | 50 +++++++++++++++++++++-----------
 gdb/c-exp.y                         | 10 +++++--
 gdb/cli/cli-cmds.c                  | 35 ++++++++++++++--------
 gdb/cli/cli-dump.c                  | 21 +++++++++-----
 gdb/cli/cli-script.c                | 33 ++++++++++++++-------
 gdb/cli/cli-utils.c                 | 18 ++++++++----
 gdb/coffread.c                      | 19 ++++++++----
 gdb/compile/compile-object-load.c   | 36 +++++++++++++----------
 gdb/compile/compile.c               |  6 ++--
 gdb/corelow.c                       | 10 ++++---
 gdb/ctfread.c                       | 16 ++++++----
 gdb/d-exp.y                         |  4 ++-
 gdb/dwarf2/ada-imported.c           |  6 ++--
 gdb/dwarf2/dwz.c                    |  9 +++---
 gdb/eval.c                          |  9 ++++--
 gdb/exec.c                          | 14 +++++----
 gdb/findvar.c                       |  4 ++-
 gdb/gcore.c                         |  9 ++++--
 gdb/gdb_bfd.c                       | 12 +++++---
 gdb/guile/guile.c                   |  4 ++-
 gdb/inf-child.c                     |  3 +-
 gdb/infcall.c                       | 58 ++++++++++++++++++++++---------------
 gdb/infcmd.c                        |  6 ++--
 gdb/linespec.c                      |  1 +
 gdb/linux-nat.c                     |  4 ++-
 gdb/maint.c                         |  3 +-
 gdb/parse.c                         |  4 ++-
 gdb/printcmd.c                      | 11 +++----
 gdb/python/python.c                 |  3 +-
 gdb/record-btrace.c                 |  4 ++-
 gdb/record-full.c                   | 25 +++++++++-------
 gdb/record.c                        |  6 ++--
 gdb/remote-fileio.c                 | 11 +++++--
 gdb/remote.c                        | 20 +++++++++----
 gdb/rust-lang.c                     |  6 ++--
 gdb/skip.c                          |  5 ++--
 gdb/solib-aix.c                     | 16 ++++++----
 gdb/solib-darwin.c                  |  7 +++--
 gdb/solib.c                         | 14 +++++----
 gdb/symfile-mem.c                   | 16 +++++++---
 gdb/symfile.c                       | 30 +++++++++++--------
 gdb/symmisc.c                       |  3 +-
 gdb/symtab.c                        |  3 +-
 gdb/target.c                        | 41 +++++++++++++++++---------
 gdb/testsuite/gdb.base/commands.exp |  3 +-
 gdb/testsuite/gdb.base/default.exp  |  2 +-
 gdb/tracectf.c                      | 16 ++++++----
 gdb/tracefile-tfile.c               |  6 ++--
 gdb/utils.c                         |  4 ++-
 gdb/valops.c                        | 29 +++++++++++--------
 gdb/xcoffread.c                     |  6 ++--
 gdb/xml-support.c                   |  5 +++-
 55 files changed, 465 insertions(+), 254 deletions(-)
---
base-commit: 2ec5e53d96e3def7ee11966fd07ae215be84515a
change-id: 20260405-more-error-style-0c3bb6e1b9ad

Best regards,
-- 
Tom Tromey <tom@tromey.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4] Add command styling to error messages
  2026-04-05 11:28 [PATCH 0/4] Add more styling of error messages Tom Tromey
@ 2026-04-05 11:28 ` Tom Tromey
  2026-04-05 11:28 ` [PATCH 2/4] Add filename " Tom Tromey
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2026-04-05 11:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/4] Add filename styling to error messages
  2026-04-05 11:28 [PATCH 0/4] Add more styling of error messages Tom Tromey
  2026-04-05 11:28 ` [PATCH 1/4] Add command styling to " Tom Tromey
@ 2026-04-05 11:28 ` Tom Tromey
  2026-04-05 11:28 ` [PATCH 3/4] Add variable " Tom Tromey
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2026-04-05 11:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes a number of error messages in gdb to use file_name_style.
---
 gdb/amd64-linux-tdep.c            |  5 +++--
 gdb/breakpoint.c                  | 12 ++++++++----
 gdb/cli/cli-cmds.c                |  5 +++--
 gdb/cli/cli-dump.c                | 21 ++++++++++++++-------
 gdb/coffread.c                    | 19 +++++++++++++------
 gdb/compile/compile-object-load.c | 36 +++++++++++++++++++++---------------
 gdb/corelow.c                     | 10 ++++++----
 gdb/ctfread.c                     | 16 ++++++++++------
 gdb/dwarf2/dwz.c                  |  9 +++++----
 gdb/exec.c                        | 10 +++++-----
 gdb/gcore.c                       |  9 ++++++---
 gdb/gdb_bfd.c                     | 12 ++++++++----
 gdb/linespec.c                    |  1 +
 gdb/linux-nat.c                   |  4 +++-
 gdb/record-full.c                 | 25 +++++++++++++++----------
 gdb/remote.c                      |  3 ++-
 gdb/skip.c                        |  5 +++--
 gdb/solib-aix.c                   | 16 ++++++++++------
 gdb/solib-darwin.c                |  7 +++++--
 gdb/solib.c                       | 14 +++++++++-----
 gdb/symfile.c                     | 30 ++++++++++++++++++------------
 gdb/symmisc.c                     |  3 ++-
 gdb/target.c                      | 34 ++++++++++++++++++++++------------
 gdb/tracectf.c                    | 16 ++++++++++------
 gdb/tracefile-tfile.c             |  6 ++++--
 gdb/utils.c                       |  4 +++-
 gdb/xcoffread.c                   |  6 ++++--
 gdb/xml-support.c                 |  5 ++++-
 28 files changed, 217 insertions(+), 126 deletions(-)

diff --git a/gdb/amd64-linux-tdep.c b/gdb/amd64-linux-tdep.c
index 17d9f78f32d..a5ac26654cf 100644
--- a/gdb/amd64-linux-tdep.c
+++ b/gdb/amd64-linux-tdep.c
@@ -50,6 +50,7 @@
 #include "x86-tdep.h"
 #include "dwarf2/frame.h"
 #include "frame-unwind.h"
+#include "cli/cli-style.h"
 
 /* The syscall's XML filename for i386.  */
 #define XML_SYSCALL_FILENAME_AMD64 "syscalls/amd64-linux.xml"
@@ -1868,8 +1869,8 @@ amd64_linux_lam_untag_mask ()
       errno = 0;
       unsigned long long result = std::strtoul (start, &endptr, 0);
       if (errno != 0 || endptr == start)
-	error (_("Failed to parse untag_mask from file %s."),
-	       std::string (filename).c_str ());
+	error (_("Failed to parse untag_mask from file %ps."),
+	       styled_string (file_name_style.style (), filename.c_str ()));
 
       return result;
     }
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index fdff6e8fc94..13e25067056 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -9498,8 +9498,10 @@ resolve_sal_pc (struct symtab_and_line *sal)
   if (sal->pc == 0 && sal->symtab != NULL)
     {
       if (!find_pc_for_line (sal->symtab, sal->line, &pc))
-	error (_("No line %d in file \"%s\"."),
-	       sal->line, symtab_to_filename_for_display (sal->symtab));
+	error (_("No line %d in file \"%ps\"."),
+	       sal->line,
+	       styled_string (file_name_style.style (),
+			      symtab_to_filename_for_display (sal->symtab)));
       sal->pc = pc;
 
       /* If this SAL corresponds to a breakpoint inserted using a line
@@ -14543,8 +14545,10 @@ save_breakpoints (const char *filename, int from_tty,
   stdio_file fp;
 
   if (!fp.open (expanded_filename.get (), "w"))
-    error (_("Unable to open file '%s' for saving (%s)"),
-	   expanded_filename.get (), safe_strerror (errno));
+    error (_("Unable to open file '%ps' for saving (%s)"),
+	   styled_string (file_name_style.style (),
+			  expanded_filename.get ()),
+	   safe_strerror (errno));
 
   if (extra_trace_bits)
     save_trace_state_variables (&fp);
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 761158f2ae9..63f5a637697 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -1902,8 +1902,9 @@ save_user_command (const char *filename, int from_tty)
   std::string expanded_filename = gdb_tilde_expand (filename);
   stdio_file fp;
   if (!fp.open (expanded_filename.c_str (), "w"))
-    error (_("Unable to open file '%s' for saving (%s)"),
-	   expanded_filename.c_str (), safe_strerror (errno));
+    error (_("Unable to open file '%ps' for saving (%s)"),
+	   styled_string (file_name_style.style (), expanded_filename.c_str ()),
+	   safe_strerror (errno));
 
   cli_ui_out uiout (&fp);
   for (struct cmd_list_element *c = cmdlist; c != nullptr; c = c->next)
diff --git a/gdb/cli/cli-dump.c b/gdb/cli/cli-dump.c
index 59c5827c093..66ab5922693 100644
--- a/gdb/cli/cli-dump.c
+++ b/gdb/cli/cli-dump.c
@@ -31,6 +31,7 @@
 #include "gdbsupport/byte-vector.h"
 #include "gdbarch.h"
 #include "inferior.h"
+#include "cli/cli-style.h"
 
 static gdb::unique_xmalloc_ptr<char>
 scan_expression (const char **cmd, const char *def)
@@ -84,11 +85,13 @@ bfd_openr_or_error (const char *filename, const char *target)
 {
   gdb_bfd_ref_ptr ibfd (gdb_bfd_openr (filename, target));
   if (ibfd == NULL)
-    error (_("Failed to open %s: %s."), filename,
+    error (_("Failed to open %ps: %s."),
+	   styled_string (file_name_style.style (), filename),
 	   bfd_errmsg (bfd_get_error ()));
 
   if (!bfd_check_format (ibfd.get (), bfd_object))
-    error (_("'%s' is not a recognized file format."), filename);
+    error (_("'%ps' is not a recognized file format."),
+	   styled_string (file_name_style.style (), filename));
 
   return ibfd;
 }
@@ -102,7 +105,8 @@ bfd_openw_or_error (const char *filename, const char *target, const char *mode)
     {
       obfd = gdb_bfd_openw (filename, target);
       if (obfd == NULL)
-	error (_("Failed to open %s: %s."), filename,
+	error (_("Failed to open %ps: %s."),
+	       styled_string (file_name_style.style (), filename),
 	       bfd_errmsg (bfd_get_error ()));
       if (!bfd_set_format (obfd.get (), bfd_object))
 	error (_("bfd_openw_or_error: %s."), bfd_errmsg (bfd_get_error ()));
@@ -414,7 +418,8 @@ restore_one_section (bfd *ibfd, asection *isec,
   /* Get the data.  */
   gdb::byte_vector buf (size);
   if (!bfd_get_section_contents (ibfd, isec, buf.data (), 0, size))
-    error (_("Failed to read bfd file %s: '%s'."), bfd_get_filename (ibfd),
+    error (_("Failed to read bfd file %ps: '%s'."),
+	   styled_string (file_name_style.style (), bfd_get_filename (ibfd)),
 	   bfd_errmsg (bfd_get_error ()));
 
   gdb_printf ("Restoring section %s (0x%lx to 0x%lx)",
@@ -449,7 +454,9 @@ restore_binary_file (const char *filename, CORE_ADDR load_offset,
   long len;
 
   if (file == NULL)
-    error (_("Failed to open %s: %s"), filename, safe_strerror (errno));
+    error (_("Failed to open %ps: %s"),
+	   styled_string (file_name_style.style (), filename),
+	   safe_strerror (errno));
 
   /* Get the file size for reading.  */
   if (fseek (file.get (), 0, SEEK_END) == 0)
@@ -462,8 +469,8 @@ restore_binary_file (const char *filename, CORE_ADDR load_offset,
     perror_with_name (filename);
 
   if (len <= load_start)
-    error (_("Start address is greater than length of binary file %s."),
-	   filename);
+    error (_("Start address is greater than length of binary file %ps."),
+	   styled_string (file_name_style.style (), filename));
 
   /* Chop off "len" if it exceeds the requested load_end addr.  */
   if (load_end != 0 && load_end < len)
diff --git a/gdb/coffread.c b/gdb/coffread.c
index f45b5efd5b3..0a5da42e563 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -27,6 +27,7 @@
 #include "target.h"
 #include "dwarf2/public.h"
 #include "coff-pe-read.h"
+#include "cli/cli-style.h"
 
 /* Simplified internal version of coff symbol table information.  */
 
@@ -324,7 +325,8 @@ coff_reader::symfile_read (symfile_add_flags symfile_flags)
   gdb::unique_xmalloc_ptr<char> stringtab_storage;
   val = init_stringtab (stringtab_offset, &stringtab_storage);
   if (val < 0)
-    error (_("\"%s\": can't get string table"), filename);
+    error (_("\"%ps\": can't get string table"),
+	   styled_string (file_name_style.style (), filename));
 
   read_minsyms (symtab_offset, num_symbols);
 
@@ -386,8 +388,10 @@ coff_reader::symtab_read (minimal_symbol_reader &reader,
   /* Position to read the symbol table.  */
   val = bfd_seek (symfile_bfd, symtab_offset, 0);
   if (val < 0)
-    error (_("Error reading symbols from %s: %s"),
-	   objfile_name (coffread_objfile), bfd_errmsg (bfd_get_error ()));
+    error (_("Error reading symbols from %ps: %s"),
+	   styled_string (file_name_style.style (),
+			  objfile_name (coffread_objfile)),
+	   bfd_errmsg (bfd_get_error ()));
 
   while (symnum < nsyms)
     {
@@ -530,7 +534,9 @@ coff_reader::read_one_sym (struct coff_symbol *cs)
 
   bytes = bfd_read (temp_sym, local_symesz, symfile_bfd);
   if (bytes != local_symesz)
-    error (_("%s: error reading symbols"), objfile_name (coffread_objfile));
+    error (_("%ps: error reading symbols"),
+	   styled_string (file_name_style.style (),
+			  objfile_name (coffread_objfile)));
   bfd_coff_swap_sym_in (symfile_bfd, temp_sym, &sym);
   cs->c_naux = sym.n_numaux & 0xff;
   if (cs->c_naux >= 1)
@@ -540,8 +546,9 @@ coff_reader::read_one_sym (struct coff_symbol *cs)
 	{
 	  bytes = bfd_read (temp_aux, local_auxesz, symfile_bfd);
 	  if (bytes != local_auxesz)
-	    error (_("%s: error reading symbols"),
-		   objfile_name (coffread_objfile));
+	    error (_("%ps: error reading symbols"),
+		   styled_string (file_name_style.style (),
+				  objfile_name (coffread_objfile)));
 	}
     }
   cs->c_name = getsymname (&sym);
diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c
index fe48979e4f6..4ea924582fb 100644
--- a/gdb/compile/compile-object-load.c
+++ b/gdb/compile/compile-object-load.c
@@ -31,6 +31,7 @@
 #include "block.h"
 #include "arch-utils.h"
 #include <algorithm>
+#include "cli/cli-style.h"
 
 /* Add inferior mmap memory range ADDR..ADDR+SIZE (exclusive) to the
    list.  */
@@ -616,16 +617,18 @@ compile_object_load (const compile_file_names &file_names,
 
   gdb_bfd_ref_ptr abfd (gdb_bfd_open (filename.get (), gnutarget));
   if (abfd == NULL)
-    error (_("\"%s\": could not open as compiled module: %s"),
-	  filename.get (), bfd_errmsg (bfd_get_error ()));
+    error (_("\"%ps\": could not open as compiled module: %s"),
+	   styled_string (file_name_style.style (), filename.get ()),
+	   bfd_errmsg (bfd_get_error ()));
 
   if (!bfd_check_format_matches (abfd.get (), bfd_object, &matching))
-    error (_("\"%s\": not in loadable format: %s"),
-	   filename.get (),
+    error (_("\"%ps\": not in loadable format: %s"),
+	   styled_string (file_name_style.style (), filename.get ()),
 	   gdb_bfd_errmsg (bfd_get_error (), matching).c_str ());
 
   if ((bfd_get_file_flags (abfd.get ()) & (EXEC_P | DYNAMIC)) != 0)
-    error (_("\"%s\": not in object format."), filename.get ());
+    error (_("\"%ps\": not in object format."),
+	   styled_string (file_name_style.style (), filename.get ()));
 
   struct setup_sections_data setup_sections_data (abfd.get ());
   for (asection *sect : gdb_bfd_sections (abfd))
@@ -644,14 +647,15 @@ compile_object_load (const compile_file_names &file_names,
 						GCC_FE_WRAPPER_FUNCTION,
 						SEARCH_VFT).symbol;
   if (func_sym == NULL)
-    error (_("Cannot find function \"%s\" in compiled module \"%s\"."),
-	   GCC_FE_WRAPPER_FUNCTION, objfile_name (objfile));
+    error (_("Cannot find function \"%s\" in compiled module \"%ps\"."),
+	   GCC_FE_WRAPPER_FUNCTION,
+	   styled_string (file_name_style.style (), objfile_name (objfile)));
   func_type = func_sym->type ();
   if (func_type->code () != TYPE_CODE_FUNC)
     error (_("Invalid type code %d of function \"%s\" in compiled "
-	     "module \"%s\"."),
+	     "module \"%ps\"."),
 	   func_type->code (), GCC_FE_WRAPPER_FUNCTION,
-	   objfile_name (objfile));
+	   styled_string (file_name_style.style (), objfile_name (objfile)));
 
   switch (scope)
     {
@@ -676,13 +680,14 @@ compile_object_load (const compile_file_names &file_names,
     }
   if (func_type->num_fields () != expect_parameters)
     error (_("Invalid %d parameters of function \"%s\" in compiled "
-	     "module \"%s\"."),
+	     "module \"%ps\"."),
 	   func_type->num_fields (), GCC_FE_WRAPPER_FUNCTION,
-	   objfile_name (objfile));
+	   styled_string (file_name_style.style (), objfile_name (objfile)));
   if (!types_deeply_equal (expect_return_type, func_type->target_type ()))
     error (_("Invalid return type of function \"%s\" in compiled "
-	     "module \"%s\"."),
-	   GCC_FE_WRAPPER_FUNCTION, objfile_name (objfile));
+	     "module \"%ps\"."),
+	   GCC_FE_WRAPPER_FUNCTION,
+	   styled_string (file_name_style.style (), objfile_name (objfile)));
 
   gdb::array_view<asymbol *> symbol_table
     = gdb_bfd_canonicalize_symtab (abfd.get ());
@@ -774,8 +779,9 @@ compile_object_load (const compile_file_names &file_names,
 	  break;
 	default:
 	  warning (_("Could not find symbol \"%s\" "
-		     "for compiled module \"%s\"."),
-		   sym->name, filename.get ());
+		     "for compiled module \"%ps\"."),
+		   sym->name,
+		   styled_string (file_name_style.style (), filename.get ()));
 	  missing_symbols++;
 	}
     }
diff --git a/gdb/corelow.c b/gdb/corelow.c
index 954607134f4..8548311b906 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -377,8 +377,9 @@ core_target::core_target (gdb_bfd_ref_ptr cbfd_ref)
 
   if (!m_core_gdbarch
       || !gdbarch_iterate_over_regset_sections_p (m_core_gdbarch))
-    error (_("\"%s\": Core file format not supported"),
-	   bfd_get_filename (this->core_bfd ()));
+    error (_("\"%ps\": Core file format not supported"),
+	   styled_string (file_name_style.style (),
+			  bfd_get_filename (this->core_bfd ())));
 
   /* Find the data section */
   m_core_section_table = build_section_table (this->core_bfd ());
@@ -1041,8 +1042,9 @@ core_target_open (const char *arg, int from_tty)
       /* FIXME: should be checking for errors from bfd_close (for one
 	 thing, on error it does not free all the storage associated
 	 with the bfd).  */
-      error (_("\"%s\" is not a core dump: %s"),
-	     filename.c_str (), bfd_errmsg (bfd_get_error ()));
+      error (_("\"%ps\" is not a core dump: %s"),
+	     styled_string (file_name_style.style (), filename.c_str ()),
+	     bfd_errmsg (bfd_get_error ()));
     }
 
   core_target *target = new core_target (std::move (temp_bfd));
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index b95cdbed33c..0ddb2325344 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -84,6 +84,7 @@
 #include "maint.h"
 #include "objfiles.h"
 #include "progspace.h"
+#include "cli/cli-style.h"
 
 /* When true, print debug messages related to CTF reading.  */
 static bool debug_ctf = false;
@@ -1305,13 +1306,15 @@ elfctf_build_symtabs (objfile *objfile)
 
   ctf_archive_up archive (ctf_bfdopen (abfd, &err));
   if (archive == nullptr)
-    error (_("ctf_bfdopen failed on %s - %s"),
-	   bfd_get_filename (abfd), ctf_errmsg (err));
+    error (_("ctf_bfdopen failed on %ps - %s"),
+	   styled_string (file_name_style.style (), bfd_get_filename (abfd)),
+	   ctf_errmsg (err));
 
   ctf_dict_up dict (ctf_dict_open (archive.get (), NULL, &err));
   if (dict == nullptr)
-    error (_("ctf_dict_open failed on %s - %s"),
-	   bfd_get_filename (abfd), ctf_errmsg (err));
+    error (_("ctf_dict_open failed on %ps - %s"),
+	   styled_string (file_name_style.style (), bfd_get_filename (abfd)),
+	   ctf_errmsg (err));
 
   ctf_per_objfile &per_objfile
     = ctf_per_objfile_key.emplace (objfile, objfile, std::move (archive),
@@ -1321,8 +1324,9 @@ elfctf_build_symtabs (objfile *objfile)
   if (ctf_archive_iter (per_objfile.archive.get (), build_ctf_archive_member,
 			&iter_data)
       < 0)
-    error (_("ctf_archive_iter failed in input file %s: - %s"),
-	   bfd_get_filename (abfd), ctf_errmsg (err));
+    error (_("ctf_archive_iter failed in input file %ps: - %s"),
+	   styled_string (file_name_style.style (), bfd_get_filename (abfd)),
+	   ctf_errmsg (err));
 
   objfile->qf.emplace_front (std::make_unique<expanded_symbols_functions>
 			     (std::move (iter_data.compunit_symtabs)));
diff --git a/gdb/dwarf2/dwz.c b/gdb/dwarf2/dwz.c
index b403265a18d..8f3d52567ec 100644
--- a/gdb/dwarf2/dwz.c
+++ b/gdb/dwarf2/dwz.c
@@ -97,7 +97,8 @@ locate_dwz_sections (objfile *objfile, dwz_file &dwz_file)
 static void
 debug_sup_failure (const char *text, bfd *abfd)
 {
-  error (_("%s [in modules %s]"), text, bfd_get_filename (abfd));
+  error (_("%s [in modules %ps]"), text,
+	 styled_string (file_name_style.style (), bfd_get_filename (abfd)));
 }
 
 /* Look for the .debug_sup section and read it.  If the section does
@@ -390,9 +391,9 @@ dwz_file::read_dwz_file (dwarf2_per_objfile *per_objfile)
     }
 
   if (dwz_bfd == NULL)
-    error (_("could not find supplementary DWARF file (%s) for %s"),
-	   filename.c_str (),
-	   per_bfd->filename ());
+    error (_("could not find supplementary DWARF file (%ps) for %ps"),
+	   styled_string (file_name_style.style (), filename.c_str ()),
+	   styled_string (file_name_style.style (), per_bfd->filename ()));
 
   dwz_file_up result (new dwz_file (std::move (dwz_bfd)));
 
diff --git a/gdb/exec.c b/gdb/exec.c
index b1b2d2d190d..873686e6286 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -463,10 +463,9 @@ exec_file_attach (const char *filename, int from_tty)
       current_program_space->set_exec_bfd (std::move (temp));
 
       if (!current_program_space->exec_bfd ())
-	{
-	  error (_("\"%s\": could not open as an executable file: %s."),
-		 scratch_pathname, bfd_errmsg (bfd_get_error ()));
-	}
+	error (_("\"%ps\": could not open as an executable file: %s."),
+	       styled_string (file_name_style.style (), scratch_pathname),
+	       bfd_errmsg (bfd_get_error ()));
 
       /* gdb_realpath_keepfile resolves symlinks on the local
 	 filesystem and so cannot be used for "target:" files.  */
@@ -486,7 +485,8 @@ exec_file_attach (const char *filename, int from_tty)
 	  /* Make sure to close exec_bfd, or else "run" might try to use
 	     it.  */
 	  current_program_space->exec_close ();
-	  error (_("\"%s\": not in executable format: %s"), scratch_pathname,
+	  error (_("\"%ps\": not in executable format: %s"),
+		 styled_string (file_name_style.style (), scratch_pathname),
 		 gdb_bfd_errmsg (bfd_get_error (), matching).c_str ());
 	}
 
diff --git a/gdb/gcore.c b/gdb/gcore.c
index 48e431ed8f9..ff429098b7e 100644
--- a/gdb/gcore.c
+++ b/gdb/gcore.c
@@ -37,6 +37,7 @@
 #include "gdbsupport/byte-vector.h"
 #include "gdbsupport/scope-exit.h"
 #include "auxv.h"
+#include "cli/cli-style.h"
 
 /* To generate sparse cores, we look at the data to write in chunks of
    this size when considering whether to skip the write.  Only if we
@@ -67,7 +68,8 @@ create_gcore_bfd (const char *filename)
   gdb_bfd_ref_ptr obfd (gdb_bfd_openw (filename, default_gcore_target ()));
 
   if (obfd == NULL)
-    error (_("Failed to open '%s' for output."), filename);
+    error (_("Failed to open '%ps' for output."),
+	   styled_string (file_name_style.style (), filename));
   bfd_set_format (obfd.get (), bfd_core);
   bfd_set_arch_mach (obfd.get (), default_gcore_arch (), 0);
   return obfd;
@@ -101,8 +103,9 @@ write_gcore_file_1 (bfd *obfd)
 						 | SEC_READONLY
 						 | SEC_ALLOC);
   if (note_sec == NULL)
-    error (_("Failed to create 'note' section for corefile: %s"),
-	   bfd_errmsg (bfd_get_error ()));
+    error (_("Failed to create 'note' section for corefile: %ps"),
+	   styled_string (file_name_style.style (),
+			  bfd_errmsg (bfd_get_error ())));
 
   bfd_set_section_vma (note_sec, 0);
   bfd_set_section_alignment (note_sec, 0);
diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
index 342957273cd..952875955ad 100644
--- a/gdb/gdb_bfd.c
+++ b/gdb/gdb_bfd.c
@@ -834,8 +834,10 @@ get_file_crc (bfd *abfd, unsigned long *file_crc_return)
 
   if (bfd_seek (abfd, 0, SEEK_SET) != 0)
     {
-      warning (_("Problem reading \"%s\" for CRC: %s"),
-	       bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
+      warning (_("Problem reading \"%ps\" for CRC: %s"),
+	       styled_string (file_name_style.style (),
+			      bfd_get_filename (abfd)),
+	       bfd_errmsg (bfd_get_error ()));
       return 0;
     }
 
@@ -847,8 +849,10 @@ get_file_crc (bfd *abfd, unsigned long *file_crc_return)
       count = bfd_read (buffer, sizeof (buffer), abfd);
       if (count == (bfd_size_type) -1)
 	{
-	  warning (_("Problem reading \"%s\" for CRC: %s"),
-		   bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
+	  warning (_("Problem reading \"%ps\" for CRC: %s"),
+		   styled_string (file_name_style.style (),
+				  bfd_get_filename (abfd)),
+		   bfd_errmsg (bfd_get_error ()));
 	  return 0;
 	}
       if (count == 0)
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 7624c92ab25..981bd5faa4f 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -45,6 +45,7 @@
 #include <algorithm>
 #include "inferior.h"
 #include "gdbsupport/unordered_set.h"
+#include "cli/cli-style.h"
 
 /* An enumeration of the various things a user might attempt to
    complete for a linespec location.  */
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 1d0a4609a3a..218ead00136 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -63,6 +63,7 @@
 #include "gdbsupport/scope-exit.h"
 #include "gdbsupport/gdb-sigmask.h"
 #include "gdbsupport/common-debug.h"
+#include "cli/cli-style.h"
 
 /* This comment documents high-level logic of this file.
 
@@ -4305,7 +4306,8 @@ linux_proc_pending_signals (int pid, sigset_t *pending,
   xsnprintf (fname, sizeof fname, "/proc/%d/status", pid);
   gdb_file_up procfile = gdb_fopen_cloexec (fname, "r");
   if (procfile == NULL)
-    error (_("Could not open %s"), fname);
+    error (_("Could not open %ps"),
+	   styled_string (file_name_style.style () ,fname));
 
   while (fgets (buffer, PATH_MAX, procfile.get ()) != NULL)
     {
diff --git a/gdb/record-full.c b/gdb/record-full.c
index e0af376f3eb..942bf983792 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -45,6 +45,7 @@
 #include "top.h"
 #include "valprint.h"
 #include "interps.h"
+#include "cli/cli-style.h"
 
 #include <signal.h>
 
@@ -2310,8 +2311,9 @@ bfdcore_read (bfd *obfd, asection *osec, void *buf, int len, int *offset)
   if (ret)
     *offset += len;
   else
-    error (_("Failed to read %d bytes from core file %s ('%s')."),
-	   len, bfd_get_filename (obfd),
+    error (_("Failed to read %d bytes from core file %ps ('%s')."),
+	   len, styled_string (file_name_style.style (),
+			       bfd_get_filename (obfd)),
 	   bfd_errmsg (bfd_get_error ()));
 }
 
@@ -2366,8 +2368,9 @@ record_full_restore (struct bfd &cbfd)
   /* Check the magic code.  */
   bfdcore_read (&cbfd, osec, &magic, sizeof (magic), &bfd_offset);
   if (magic != RECORD_FULL_FILE_MAGIC)
-    error (_("Version mismatch or file format error in core file %s."),
-	   bfd_get_filename (&cbfd));
+    error (_("Version mismatch or file format error in core file %ps."),
+	   styled_string (file_name_style.style (),
+			  bfd_get_filename (&cbfd)));
   if (record_debug)
     gdb_printf (gdb_stdlog,
 		"  Reading 4-byte magic cookie "
@@ -2470,8 +2473,9 @@ record_full_restore (struct bfd &cbfd)
 	      break;
 
 	    default:
-	      error (_("Bad entry type in core file %s."),
-		     bfd_get_filename (&cbfd));
+	      error (_("Bad entry type in core file %ps."),
+		     styled_string (file_name_style.style (),
+				    bfd_get_filename (&cbfd)));
 	      break;
 	    }
 
@@ -2516,8 +2520,9 @@ bfdcore_write (bfd *obfd, asection *osec, void *buf, int len, int *offset)
   if (ret)
     *offset += len;
   else
-    error (_("Failed to write %d bytes to core file %s ('%s')."),
-	   len, bfd_get_filename (obfd),
+    error (_("Failed to write %d bytes to core file %ps ('%s')."),
+	   len, styled_string (file_name_style.style (),
+			       bfd_get_filename (obfd)),
 	   bfd_errmsg (bfd_get_error ()));
 }
 
@@ -2601,8 +2606,8 @@ record_full_base_target::save_record (const char *recfilename)
 					     SEC_HAS_CONTENTS
 					     | SEC_READONLY);
   if (osec == NULL)
-    error (_("Failed to create 'precord' section for corefile %s: %s"),
-	   recfilename,
+    error (_("Failed to create 'precord' section for corefile %ps: %s"),
+	   styled_string (file_name_style.style (), recfilename),
 	   bfd_errmsg (bfd_get_error ()));
   bfd_set_section_size (osec, save_size);
   bfd_set_section_vma (osec, 0);
diff --git a/gdb/remote.c b/gdb/remote.c
index 23ef6145620..0317119f292 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -13998,7 +13998,8 @@ remote_target::remote_file_put (const char *local_file, const char *remote_file,
 	  if (bytes == 0)
 	    {
 	      if (ferror (file.get ()))
-		error (_("Error reading %s."), local_file);
+		error (_("Error reading %ps."),
+		       styled_string (file_name_style.style (), local_file));
 	      else
 		{
 		  /* EOF.  Unless there is something still in the
diff --git a/gdb/skip.c b/gdb/skip.c
index eb47cee9e34..917b084860d 100644
--- a/gdb/skip.c
+++ b/gdb/skip.c
@@ -1373,8 +1373,9 @@ save_skip_command (const char *filename, int from_tty)
   gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename));
   stdio_file fp;
   if (!fp.open (expanded_filename.get (), "w"))
-    error (_("Unable to open file '%s' for saving (%s)"),
-	   expanded_filename.get (), safe_strerror (errno));
+    error (_("Unable to open file '%ps' for saving (%s)"),
+	   styled_string (file_name_style.style (), expanded_filename.get ()),
+	   safe_strerror (errno));
 
   for (const auto &entry : skiplist_entries)
     entry.print_recreate (&fp);
diff --git a/gdb/solib-aix.c b/gdb/solib-aix.c
index d4367973ad5..4f029529106 100644
--- a/gdb/solib-aix.c
+++ b/gdb/solib-aix.c
@@ -23,6 +23,7 @@
 #include "symtab.h"
 #include "xcoffread.h"
 #include "observable.h"
+#include "cli/cli-style.h"
 
 /* solib_ops for AIX systems.  */
 
@@ -540,8 +541,9 @@ aix_solib_ops::bfd_open (const char *pathname) const
 						found_file));
   if (archive_bfd == NULL)
     {
-      warning (_("Could not open `%s' as an executable file: %s"),
-	       filename.c_str (), bfd_errmsg (bfd_get_error ()));
+      warning (_("Could not open `%ps' as an executable file: %s"),
+	       styled_string (file_name_style.style (), filename.c_str ()),
+	       bfd_errmsg (bfd_get_error ()));
       return NULL;
     }
 
@@ -550,8 +552,9 @@ aix_solib_ops::bfd_open (const char *pathname) const
 
   if (! bfd_check_format (archive_bfd.get (), bfd_archive))
     {
-      warning (_("\"%s\": not in executable format: %s."),
-	       filename.c_str (), bfd_errmsg (bfd_get_error ()));
+      warning (_("\"%ps\": not in executable format: %s."),
+	       styled_string (file_name_style.style (), filename.c_str ()),
+	       bfd_errmsg (bfd_get_error ()));
       return NULL;
     }
 
@@ -589,8 +592,9 @@ aix_solib_ops::bfd_open (const char *pathname) const
 
   if (! bfd_check_format (object_bfd.get (), bfd_object))
     {
-      warning (_("%s(%s): not in object format: %s."),
-	       filename.c_str (), member_name.c_str (),
+      warning (_("%ps(%s): not in object format: %s."),
+	       styled_string (file_name_style.style (), filename.c_str ()),
+	       member_name.c_str (),
 	       bfd_errmsg (bfd_get_error ()));
       return NULL;
     }
diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
index 3412f662910..6e2535ca427 100644
--- a/gdb/solib-darwin.c
+++ b/gdb/solib-darwin.c
@@ -26,6 +26,7 @@
 #include "inferior.h"
 #include "regcache.h"
 #include "gdb_bfd.h"
+#include "cli/cli-style.h"
 
 #include "solib.h"
 #include "solib-darwin.h"
@@ -623,8 +624,10 @@ darwin_solib_ops::bfd_open (const char *pathname) const
        (abfd.get (), bfd_object,
 	gdbarch_bfd_arch_info (current_inferior ()->arch ())));
   if (res == NULL)
-    error (_("`%s': not a shared-library: %s"),
-	   bfd_get_filename (abfd.get ()), bfd_errmsg (bfd_get_error ()));
+    error (_("`%ps': not a shared-library: %s"),
+	   styled_string (file_name_style.style (),
+			  bfd_get_filename (abfd.get ())),
+	   bfd_errmsg (bfd_get_error ()));
 
   /* The current filename for fat-binary BFDs is a name generated
      by BFD, usually a string containing the name of the architecture.
diff --git a/gdb/solib.c b/gdb/solib.c
index 2cf9e17738d..782b844aa2f 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -387,7 +387,8 @@ solib_bfd_fopen (const char *pathname, int fd)
   gdb_bfd_ref_ptr abfd (gdb_bfd_open (pathname, gnutarget, fd));
 
   if (abfd == NULL)
-    error (_("Could not open `%s' as an executable file: %s"), pathname,
+    error (_("Could not open `%ps' as an executable file: %s"),
+	   styled_string (file_name_style.style (), pathname),
 	   bfd_errmsg (bfd_get_error ()));
 
   return abfd;
@@ -419,15 +420,18 @@ solib_bfd_open (const char *pathname)
 
   /* Check bfd format.  */
   if (!bfd_check_format (abfd.get (), bfd_object))
-    error (_("`%s': not in executable format: %s"),
-	   bfd_get_filename (abfd.get ()), bfd_errmsg (bfd_get_error ()));
+    error (_("`%ps': not in executable format: %s"),
+	   styled_string (file_name_style.style (),
+			  bfd_get_filename (abfd.get ())),
+	   bfd_errmsg (bfd_get_error ()));
 
   /* Check bfd arch.  */
   b = gdbarch_bfd_arch_info (current_inferior ()->arch ());
   if (!b->compatible (b, bfd_get_arch_info (abfd.get ())))
-    error (_("`%s': Shared library architecture %s is not compatible "
+    error (_("`%ps': Shared library architecture %s is not compatible "
 	     "with target architecture %s."),
-	   bfd_get_filename (abfd.get ()),
+	   styled_string (file_name_style.style (),
+			  bfd_get_filename (abfd.get ())),
 	   bfd_get_arch_info (abfd.get ())->printable_name, b->printable_name);
 
   return abfd;
diff --git a/gdb/symfile.c b/gdb/symfile.c
index e3aa81fbc0c..d0ea9506c63 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1699,11 +1699,13 @@ symfile_bfd_open (const char *name)
 
   gdb_bfd_ref_ptr sym_bfd (gdb_bfd_open (name, gnutarget, desc));
   if (sym_bfd == NULL)
-    error (_("`%s': can't open to read symbols: %s."), name,
+    error (_("`%ps': can't open to read symbols: %s."),
+	   styled_string (file_name_style.style (), name),
 	   bfd_errmsg (bfd_get_error ()));
 
   if (!bfd_check_format (sym_bfd.get (), bfd_object))
-    error (_("`%s': can't read symbols: %s."), name,
+    error (_("`%ps': can't read symbols: %s."),
+	   styled_string (file_name_style.style (), name),
 	   bfd_errmsg (bfd_get_error ()));
 
   return sym_bfd;
@@ -1766,8 +1768,9 @@ find_sym_fns (bfd *abfd)
       iter != symtab_fns.end ())
     return iter->second;
 
-  error (_("Object file %s could not be read.  Symbol format `%s' unknown."),
-	 abfd->filename, bfd_get_target (abfd));
+  error (_("Object file %ps could not be read.  Symbol format `%s' unknown."),
+	 styled_string (file_name_style.style (), abfd->filename),
+	 bfd_get_target (abfd));
 }
 \f
 
@@ -2013,10 +2016,9 @@ generic_load (const char *args, int from_tty)
     perror_with_name (filename.get ());
 
   if (!bfd_check_format (loadfile_bfd.get (), bfd_object))
-    {
-      error (_("\"%s\" is not an object file: %s"), filename.get (),
-	     bfd_errmsg (bfd_get_error ()));
-    }
+    error (_("\"%ps\" is not an object file: %s"),
+	   styled_string (file_name_style.style (), filename.get ()),
+	   bfd_errmsg (bfd_get_error ()));
 
   for (asection *asec : gdb_bfd_sections (loadfile_bfd))
     total_progress.total_size += bfd_section_size (asec);
@@ -2436,8 +2438,9 @@ remove_symbol_file_command (const char *args, int from_tty)
     error (_("No symbol file found"));
 
   if (from_tty
-      && !query (_("Remove symbol table from file \"%s\"? "),
-		 objfile_name (objf)))
+      && !query (_("Remove symbol table from file \"%ps\"? "),
+		 styled_string (file_name_style.style (),
+				objfile_name (objf))))
     error (_("Not confirmed."));
 
   objf->unlink ();
@@ -2551,14 +2554,17 @@ reread_symbols (int from_tty)
 	    gdb_bfd_ref_ptr temp (gdb_bfd_open (obfd_filename, gnutarget));
 	    objfile.obfd = std::move (temp);
 	    if (objfile.obfd == NULL)
-	      error (_("Can't open %s to read symbols."), obfd_filename);
+	      error (_("Can't open %ps to read symbols."),
+		     styled_string (file_name_style.style (), obfd_filename));
 	  }
 
 	  std::string original_name = objfile.original_name;
 
 	  /* bfd_openr sets cacheable to true, which is what we want.  */
 	  if (!bfd_check_format (objfile.obfd.get (), bfd_object))
-	    error (_("Can't read symbols from %s: %s."), objfile_name (&objfile),
+	    error (_("Can't read symbols from %ps: %s."),
+		   styled_string (file_name_style.style (),
+				  objfile_name (&objfile)),
 		   bfd_errmsg (bfd_get_error ()));
 
 	  objfile.compunit_symtabs.clear ();
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index a6dbb3b0603..b586f8fdb00 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -499,7 +499,8 @@ maintenance_print_symbols (const char *args, int from_tty)
 	}
 
       if (source_arg != NULL && !found)
-	error (_("No symtab for source file: %s"), source_arg);
+	error (_("No symtab for source file: %ps"),
+	       styled_string (file_name_style.style (), source_arg));
     }
 }
 
diff --git a/gdb/target.c b/gdb/target.c
index 60c04b04b01..c7a6a318c8f 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -1314,39 +1314,49 @@ target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset,
 	      break;
 	    case TLS_LOAD_MODULE_NOT_FOUND_ERROR:
 	      if (objfile_is_library)
-		error (_("Cannot find shared library `%s' in dynamic"
-			 " linker's load module list"), objfile_name (objfile));
+		error (_("Cannot find shared library `%ps' in dynamic"
+			 " linker's load module list"),
+		       styled_string (file_name_style.style (),
+				      objfile_name (objfile)));
 	      else
-		error (_("Cannot find executable file `%s' in dynamic"
-			 " linker's load module list"), objfile_name (objfile));
+		error (_("Cannot find executable file `%ps' in dynamic"
+			 " linker's load module list"),
+		       styled_string (file_name_style.style (),
+				      objfile_name (objfile)));
 	      break;
 	    case TLS_NOT_ALLOCATED_YET_ERROR:
 	      if (objfile_is_library)
 		error (_("The inferior has not yet allocated storage for"
 			 " thread-local variables in\n"
-			 "the shared library `%s'\n"
+			 "the shared library `%ps'\n"
 			 "for %s"),
-		       objfile_name (objfile),
+		       styled_string (file_name_style.style (),
+				      objfile_name (objfile)),
 		       target_pid_to_str (ptid).c_str ());
 	      else
 		error (_("The inferior has not yet allocated storage for"
 			 " thread-local variables in\n"
-			 "the executable `%s'\n"
+			 "the executable `%ps'\n"
 			 "for %s"),
-		       objfile_name (objfile),
+		       styled_string (file_name_style.style (),
+				      objfile_name (objfile)),
 		       target_pid_to_str (ptid).c_str ());
 	      break;
 	    case TLS_GENERIC_ERROR:
 	      if (objfile_is_library)
 		error (_("Cannot find thread-local storage for %s, "
-			 "shared library %s:\n%s"),
+			 "shared library %ps:\n%s"),
 		       target_pid_to_str (ptid).c_str (),
-		       objfile_name (objfile), ex.what ());
+		       styled_string (file_name_style.style (),
+				      objfile_name (objfile)),
+		       ex.what ());
 	      else
 		error (_("Cannot find thread-local storage for %s, "
-			 "executable file %s:\n%s"),
+			 "executable file %ps:\n%s"),
 		       target_pid_to_str (ptid).c_str (),
-		       objfile_name (objfile), ex.what ());
+		       styled_string (file_name_style.style (),
+				      objfile_name (objfile)),
+		       ex.what ());
 	      break;
 	    default:
 	      throw;
diff --git a/gdb/tracectf.c b/gdb/tracectf.c
index aff2da55d66..9246022b517 100644
--- a/gdb/tracectf.c
+++ b/gdb/tracectf.c
@@ -31,6 +31,7 @@
 #include <algorithm>
 #include "gdbsupport/filestuff.h"
 #include "gdbarch.h"
+#include "cli/cli-style.h"
 
 /* GDB saves trace buffers and other information (such as trace
    status) got from the remote target into Common Trace Format (CTF).
@@ -317,8 +318,9 @@ ctf_start (struct trace_file_writer *self, const char *dirname)
 
   /* Create DIRNAME.  */
   if (mkdir (dirname, hmode) && errno != EEXIST)
-    error (_("Unable to open directory '%s' for saving trace data (%s)"),
-	   dirname, safe_strerror (errno));
+    error (_("Unable to open directory '%ps' for saving trace data (%s)"),
+	   styled_string (file_name_style.style (), dirname),
+	   safe_strerror (errno));
 
   memset (&writer->tcs, '\0', sizeof (writer->tcs));
 
@@ -327,8 +329,9 @@ ctf_start (struct trace_file_writer *self, const char *dirname)
   writer->tcs.metadata_fd
     = gdb_fopen_cloexec (file_name.c_str (), "w").release ();
   if (writer->tcs.metadata_fd == NULL)
-    error (_("Unable to open file '%s' for saving trace data (%s)"),
-	   file_name.c_str (), safe_strerror (errno));
+    error (_("Unable to open file '%ps' for saving trace data (%s)"),
+	   styled_string (file_name_style.style (), file_name.c_str ()),
+	   safe_strerror (errno));
 
   ctf_save_metadata_header (&writer->tcs);
 
@@ -336,8 +339,9 @@ ctf_start (struct trace_file_writer *self, const char *dirname)
   writer->tcs.datastream_fd
     = gdb_fopen_cloexec (file_name.c_str (), "w").release ();
   if (writer->tcs.datastream_fd == NULL)
-    error (_("Unable to open file '%s' for saving trace data (%s)"),
-	   file_name.c_str (), safe_strerror (errno));
+    error (_("Unable to open file '%ps' for saving trace data (%s)"),
+	   styled_string (file_name_style.style (), file_name.c_str ()),
+	   safe_strerror (errno));
 }
 
 /* This is the implementation of trace_file_write_ops method
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index a6f5ae16b91..289e00ff531 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -32,6 +32,7 @@
 #include "target-descriptions.h"
 #include "gdbsupport/pathstuff.h"
 #include <algorithm>
+#include "cli/cli-style.h"
 
 #ifndef O_LARGEFILE
 #define O_LARGEFILE 0
@@ -123,8 +124,9 @@ tfile_start (struct trace_file_writer *self, const char *filename)
   writer->pathname = gdb_rl_tilde_expand (filename).release ();
   writer->fp = gdb_fopen_cloexec (writer->pathname, "wb").release ();
   if (writer->fp == NULL)
-    error (_("Unable to open file '%s' for saving trace data (%s)"),
-	   writer->pathname, safe_strerror (errno));
+    error (_("Unable to open file '%ps' for saving trace data (%s)"),
+	   styled_string (file_name_style.style (), writer->pathname),
+	   safe_strerror (errno));
 }
 
 /* This is the implementation of trace_file_write_ops method
diff --git a/gdb/utils.c b/gdb/utils.c
index b073bb9fdf3..f5f19301460 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -3727,7 +3727,9 @@ extract_single_filename_arg (const char *args)
   std::string filename = extract_string_maybe_quoted (&args);
   args = skip_spaces (args);
   if (*args != '\0')
-    error (_("Junk after filename \"%s\": %s"), filename.c_str (), args);
+    error (_("Junk after filename \"%ps\": %s"),
+	   styled_string (file_name_style.style (), filename.c_str ()),
+	   args);
   if (!filename.empty ())
     filename = gdb_tilde_expand (filename.c_str ());
   return filename;
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index fb223416240..73662c47c3d 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -35,6 +35,7 @@
 #include "complaints.h"
 #include "dwarf2/sect-names.h"
 #include "dwarf2/public.h"
+#include "cli/cli-style.h"
 
 struct xcoff_symfile_info
 {
@@ -134,8 +135,9 @@ xcoff_find_toc_offset (objfile *objfile)
 
   /* Seek to symbol table location.  */
   if (bfd_seek (abfd, symtab_offset, SEEK_SET) < 0)
-    error (_("Error reading symbols from %s: %s"),
-	   objfile_name (objfile), bfd_errmsg (bfd_get_error ()));
+    error (_("Error reading symbols from %ps: %s"),
+	   styled_string (file_name_style.style (), objfile_name (objfile)),
+	   bfd_errmsg (bfd_get_error ()));
 
   unsigned int num_symbols = bfd_get_symcount (abfd);
   size_t size = coff_data (abfd)->local_symesz * num_symbols;
diff --git a/gdb/xml-support.c b/gdb/xml-support.c
index a538c16f926..d806b53c9fa 100644
--- a/gdb/xml-support.c
+++ b/gdb/xml-support.c
@@ -23,6 +23,8 @@
 #include "gdbsupport/filestuff.h"
 #include <vector>
 #include <string>
+#include "cli/cli-style.h"
+#include "ui-out.h"
 
 /* Debugging flag.  */
 static bool debug_xml;
@@ -990,7 +992,8 @@ xml_fetch_content_from_file (const char *filename, const char *dirname)
   if (fread (text.data (), 1, len, file.get ()) != len
       || ferror (file.get ()))
     {
-      warning (_("Read error from \"%s\""), filename);
+      warning (_("Read error from \"%ps\""),
+	       styled_string (file_name_style.style (), filename));
       return {};
     }
 

-- 
2.49.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/4] Add variable styling to error messages
  2026-04-05 11:28 [PATCH 0/4] Add more styling of error messages Tom Tromey
  2026-04-05 11:28 ` [PATCH 1/4] Add command styling to " Tom Tromey
  2026-04-05 11:28 ` [PATCH 2/4] Add filename " Tom Tromey
@ 2026-04-05 11:28 ` 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
  4 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2026-04-05 11:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes some error messages in gdb to use variable_name_style.
---
 gdb/ada-exp.y       | 4 +++-
 gdb/cli/cli-utils.c | 5 +++--
 gdb/eval.c          | 4 +++-
 gdb/findvar.c       | 4 +++-
 gdb/valops.c        | 6 ++++--
 5 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index 0262ce74c85..5c5d4675eb6 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -1349,7 +1349,9 @@ write_object_renaming (struct parser_state *par_state,
   block_symbol sym_info = ada_lookup_encoded_symbol (name, orig_left_context,
 						     SEARCH_VFT);
   if (sym_info.symbol == NULL)
-    error (_("Could not find renamed variable: %s"), ada_decode (name).c_str ());
+    error (_("Could not find renamed variable: %ps"),
+	   styled_string (variable_name_style.style (),
+			  ada_decode (name).c_str ()));
   else if (sym_info.symbol->loc_class () == LOC_TYPEDEF)
     /* We have a renaming of an old-style renaming symbol.  Don't
        trust the block information.  */
diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c
index 18f112c1aad..856768f38f4 100644
--- a/gdb/cli/cli-utils.c
+++ b/gdb/cli/cli-utils.c
@@ -52,8 +52,9 @@ get_ulongest (const char **pp, int trailer)
 	  std::string varname (start, p - start);
 	  if (!get_internalvar_integer (lookup_internalvar (varname.c_str ()),
 				       &retval))
-	    error (_("Convenience variable $%s does not have integer value."),
-		   varname.c_str ());
+	    error (_("Convenience variable %p[$%s%p] does not have integer value."),
+		   variable_name_style.style ().ptr (),
+		   varname.c_str (), nullptr);
 	}
     }
   else
diff --git a/gdb/eval.c b/gdb/eval.c
index 7beff554ed4..1ea7b4d17b4 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -41,6 +41,7 @@
 #include "expop.h"
 #include "c-exp.h"
 #include "inferior.h"
+#include "cli/cli-style.h"
 
 \f
 /* Parse the string EXP as a C expression, evaluate it,
@@ -1119,7 +1120,8 @@ eval_op_func_static_var (struct type *expect_type, struct expression *exp,
   struct block_symbol sym = lookup_symbol (var, blk, SEARCH_VAR_DOMAIN,
 					   nullptr);
   if (sym.symbol == NULL)
-    error (_("No symbol \"%s\" in specified context."), var);
+    error (_("No symbol \"%ps\" in specified context."),
+	   styled_string (variable_name_style.style (), var));
   return evaluate_var_value (noside, sym.block, sym.symbol);
 }
 
diff --git a/gdb/findvar.c b/gdb/findvar.c
index 99b0d31d9d4..98351143e79 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -32,6 +32,7 @@
 #include "block.h"
 #include "objfiles.h"
 #include "language.h"
+#include "cli/cli-style.h"
 
 /* Basic byte-swapping routines.  All 'extract' functions return a
    host-format integer from a target-format integer at ADDR which is
@@ -299,7 +300,8 @@ language_defn::read_var_value (struct symbol *var,
   if (sym_need == SYMBOL_NEEDS_FRAME)
     gdb_assert (frame != NULL);
   else if (sym_need == SYMBOL_NEEDS_REGISTERS && !target_has_registers ())
-    error (_("Cannot read `%s' without registers"), var->print_name ());
+    error (_("Cannot read `%ps' without registers"),
+	   styled_string (variable_name_style.style (), var->print_name ()));
 
   if (frame != NULL)
     frame = get_hosting_frame (var, var_block, frame);
diff --git a/gdb/valops.c b/gdb/valops.c
index a5f16dc88f0..207f7d878ef 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -40,6 +40,7 @@
 #include "extension.h"
 #include "gdbsupport/byte-vector.h"
 #include "typeprint.h"
+#include "cli/cli-style.h"
 
 /* Local functions.  */
 
@@ -3985,8 +3986,9 @@ value_of_this (const struct language_defn *lang)
 
   sym = lookup_language_this (lang, b);
   if (sym.symbol == NULL)
-    error (_("current stack frame does not contain a variable named `%s'"),
-	   lang->name_of_this ());
+    error (_("current stack frame does not contain a variable named `%ps'"),
+	   styled_string (variable_name_style.style (),
+			  lang->name_of_this ()));
 
   return read_var_value (sym.symbol, sym.block, frame);
 }

-- 
2.49.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 4/4] Add function styling to error messages
  2026-04-05 11:28 [PATCH 0/4] Add more styling of error messages Tom Tromey
                   ` (2 preceding siblings ...)
  2026-04-05 11:28 ` [PATCH 3/4] Add variable " Tom Tromey
@ 2026-04-05 11:28 ` Tom Tromey
  2026-04-05 12:55 ` [PATCH 0/4] Add more styling of " Andrew Burgess
  4 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2026-04-05 11:28 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes a number of error messages in gdb to use
function_name_style.
---
 gdb/c-exp.y               |  5 ++--
 gdb/dwarf2/ada-imported.c |  6 +++--
 gdb/eval.c                |  5 ++--
 gdb/infcall.c             | 58 +++++++++++++++++++++++++++--------------------
 gdb/rust-lang.c           |  6 +++--
 gdb/valops.c              | 23 +++++++++++--------
 6 files changed, 61 insertions(+), 42 deletions(-)

diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index b036e13d188..2829d8bccba 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -1079,8 +1079,9 @@ block	:	block COLONCOLON name
 					     nullptr).symbol;
 
 			  if (tem == nullptr)
-			    error (_("No function \"%s\" in specified context."),
-				   copy.c_str ());
+			    error (_("No function \"%ps\" in specified context."),
+				   styled_string (function_name_style.style (),
+						  copy.c_str ()));
 			  $$ = tem->value_block (); }
 	;
 
diff --git a/gdb/dwarf2/ada-imported.c b/gdb/dwarf2/ada-imported.c
index 0511c9a34b7..7cdaffef886 100644
--- a/gdb/dwarf2/ada-imported.c
+++ b/gdb/dwarf2/ada-imported.c
@@ -21,6 +21,7 @@
 #include "value.h"
 #include "dwarf2/loc.h"
 #include "objfiles.h"
+#include "cli/cli-style.h"
 
 /* Helper to get the imported symbol's real name.  */
 static const char *
@@ -107,8 +108,9 @@ ada_alias_get_block_value (const struct symbol *sym)
   block_symbol real_symbol = lookup_global_symbol (name, nullptr,
 						   SEARCH_FUNCTION_DOMAIN);
   if (real_symbol.symbol == nullptr)
-    error (_("could not find alias '%s' for function '%s'"),
-	   name, sym->print_name ());
+    error (_("could not find alias '%s' for function '%ps'"),
+	   name,
+	   styled_string (function_name_style.style (), sym->print_name ()));
   if (real_symbol.symbol->loc_class () != LOC_BLOCK)
     error (_("alias '%s' for function '%s' is not a function"),
 	   name, sym->print_name ());
diff --git a/gdb/eval.c b/gdb/eval.c
index 1ea7b4d17b4..a00774bda3d 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -784,9 +784,10 @@ scope_operation::evaluate_funcall (struct type *expect_type,
       if (!static_memfuncp)
 	{
 	  /* For the time being, we don't handle this.  */
-	  error (_("Call to overloaded function %s requires "
+	  error (_("Call to overloaded function %ps requires "
 		   "`this' pointer"),
-		 function_name);
+		 styled_string (function_name_style.style (),
+				function_name));
 	}
 
       arg_view = arg_view.slice (1);
diff --git a/gdb/infcall.c b/gdb/infcall.c
index 941b0a95c5b..9af605d721a 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -43,6 +43,7 @@
 #include <algorithm>
 #include "gdbsupport/scope-exit.h"
 #include <list>
+#include "cli/cli-style.h"
 
 /* True if we are debugging inferior calls.  */
 
@@ -1100,9 +1101,11 @@ call_function_by_hand_dummy (struct value *function,
   CORE_ADDR funaddr = find_function_addr (function, &values_type, &ftype);
 
   if (is_nocall_function (ftype))
-    error (_("Cannot call the function '%s' which does not follow the "
+    error (_("Cannot call the function '%ps' which does not follow the "
 	     "target calling convention."),
-	   get_function_name (funaddr, name_buf, sizeof (name_buf)));
+	   styled_string (function_name_style.style (),
+			  get_function_name (funaddr, name_buf,
+					     sizeof (name_buf))));
 
   if (values_type == NULL || values_type->is_stub ())
     values_type = default_return_type;
@@ -1110,9 +1113,9 @@ call_function_by_hand_dummy (struct value *function,
     {
       const char *name = get_function_name (funaddr,
 					    name_buf, sizeof (name_buf));
-      error (_("'%s' has unknown return type; "
+      error (_("'%ps' has unknown return type; "
 	       "cast the call to its declared return type"),
-	     name);
+	     styled_string (function_name_style.style (), name));
     }
 
   values_type = check_typedef (values_type);
@@ -1675,9 +1678,10 @@ call_function_by_hand_dummy (struct value *function,
 	  throw_error (e.error, _("%s\n\
 An error occurred while in a function called from GDB.\n\
 Evaluation of the expression containing the function\n\
-(%s) will be abandoned.\n\
+(%ps) will be abandoned.\n\
 When the function is done executing, GDB will silently stop."),
-		       e.what (), name);
+		       e.what (),
+		       styled_string (function_name_style.style (), name));
 	case RETURN_QUIT:
 	default:
 	  throw_exception (std::move (e));
@@ -1703,8 +1707,8 @@ When the function is done executing, GDB will silently stop."),
       error (_("The program being debugged exited while in a function "
 	       "called from GDB.\n"
 	       "Evaluation of the expression containing the function\n"
-	       "(%s) will be abandoned."),
-	     name);
+	       "(%ps) will be abandoned."),
+	     styled_string (function_name_style.style (), name));
     }
 
   if (call_thread_ptid != inferior_ptid)
@@ -1724,16 +1728,16 @@ When the function is done executing, GDB will silently stop."),
 The program received a signal in another thread while\n\
 making a function call from GDB.\n\
 Evaluation of the expression containing the function\n\
-(%s) will be abandoned.\n\
+(%ps) will be abandoned.\n\
 When the function is done executing, GDB will silently stop."),
-	       name);
+	       styled_string (function_name_style.style (), name));
       else
 	error (_("\
 The program stopped in another thread while making a function call from GDB.\n\
 Evaluation of the expression containing the function\n\
-(%s) will be abandoned.\n\
+(%ps) will be abandoned.\n\
 When the function is done executing, GDB will silently stop."),
-	       name);
+	       styled_string (function_name_style.style (), name));
     }
 
     {
@@ -1774,10 +1778,11 @@ The program being debugged received signal %s, %s\n\
 while in a function called from GDB.  GDB has restored the context\n\
 to what it was before the call.  To change this behavior use\n\
 \"set unwind-on-signal off\".  Evaluation of the expression containing\n\
-the function (%s) will be abandoned."),
+the function (%ps) will be abandoned."),
 		     gdb_signal_to_name (stop_signal),
 		     gdb_signal_to_string (stop_signal),
-		     name.c_str ());
+		     styled_string (function_name_style.style (),
+				    name.c_str ()));
 	    }
 	  else
 	    {
@@ -1794,9 +1799,10 @@ The program being debugged was signaled while in a function called from GDB.\n\
 GDB remains in the frame where the signal was received.\n\
 To change this behavior use \"set unwind-on-signal on\".\n\
 Evaluation of the expression containing the function\n\
-(%s) will be abandoned.\n\
+(%ps) will be abandoned.\n\
 When the function is done executing, GDB will silently stop."),
-		     name.c_str ());
+		     styled_string (function_name_style.style (),
+				    name.c_str ()));
 	    }
 	}
 
@@ -1822,8 +1828,9 @@ The program being debugged timed out while in a function called from GDB.\n\
 GDB has restored the context to what it was before the call.\n\
 To change this behavior use \"set unwind-on-timeout off\".\n\
 Evaluation of the expression containing the function\n\
-(%s) will be abandoned."),
-		     name.c_str ());
+(%ps) will be abandoned."),
+		     styled_string (function_name_style.style (),
+				    name.c_str ()));
 	    }
 	  else
 	    {
@@ -1837,9 +1844,10 @@ The program being debugged timed out while in a function called from GDB.\n\
 GDB remains in the frame where the timeout occurred.\n\
 To change this behavior use \"set unwind-on-timeout on\".\n\
 Evaluation of the expression containing the function\n\
-(%s) will be abandoned.\n\
+(%ps) will be abandoned.\n\
 When the function is done executing, GDB will silently stop."),
-		     name.c_str ());
+		     styled_string (function_name_style.style (),
+				    name.c_str ()));
 	    }
 	}
 
@@ -1859,9 +1867,10 @@ caused by an unhandled C++ exception.  GDB blocked this call in order\n\
 to prevent the program from being terminated, and has restored the\n\
 context to its original state before the call.\n\
 To change this behavior use \"set unwind-on-terminating-exception off\".\n\
-Evaluation of the expression containing the function (%s)\n\
+Evaluation of the expression containing the function (%ps)\n\
 will be abandoned."),
-		 name.c_str ());
+		 styled_string (function_name_style.style (),
+				name.c_str ()));
 	}
       else if (stop_stack_dummy == STOP_NONE)
 	{
@@ -1883,9 +1892,10 @@ will be abandoned."),
 	  error (_("\
 The program being debugged stopped while in a function called from GDB.\n\
 Evaluation of the expression containing the function\n\
-(%s) will be abandoned.\n\
+(%ps) will be abandoned.\n\
 When the function is done executing, GDB will silently stop."),
-		 name.c_str ());
+		 styled_string (function_name_style.style (),
+				name.c_str ()));
 	}
 
     }
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 522b20c97ff..517d6333d12 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1751,11 +1751,13 @@ rust_structop::evaluate_funcall (struct type *expect_type,
 					   SEARCH_FUNCTION_DOMAIN,
 					   nullptr);
   if (sym.symbol == NULL)
-    error (_("Could not find function named '%s'"), name.c_str ());
+    error (_("Could not find function named '%ps'"),
+	   styled_string (function_name_style.style (), name.c_str ()));
 
   struct type *fn_type = sym.symbol->type ();
   if (fn_type->num_fields () == 0)
-    error (_("Function '%s' takes no arguments"), name.c_str ());
+    error (_("Function '%ps' takes no arguments"),
+	   styled_string (function_name_style.style (), name.c_str ()));
 
   if (fn_type->field (0).type ()->code () == TYPE_CODE_PTR)
     args[0] = value_addr (args[0]);
diff --git a/gdb/valops.c b/gdb/valops.c
index 207f7d878ef..515e43ccdfa 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -2963,26 +2963,29 @@ find_overload_match (gdb::array_view<value *> args,
     {
       std::string hint = incomplete_type_hint (args);
       if (method == METHOD)
-	error (_("Cannot resolve method %s%s%s to any overloaded instance%s"),
+	error (_("Cannot resolve method %p[%s%s%s%p] to any overloaded instance%s"),
+	       function_name_style.style ().ptr (),
 	       obj_type_name,
 	       (obj_type_name && *obj_type_name) ? "::" : "",
-	       name, hint.c_str ());
+	       name, nullptr, hint.c_str ());
       else
-	error (_("Cannot resolve function %s to any overloaded instance%s"),
-	       func_name, hint.c_str ());
+	error (_("Cannot resolve function %ps to any overloaded instance%s"),
+	       styled_string (function_name_style.style (), func_name),
+	       hint.c_str ());
     }
   else if (match_quality == NON_STANDARD)
     {
       if (method == METHOD)
 	warning (_("Using non-standard conversion to match "
-		   "method %s%s%s to supplied arguments"),
+		   "method %p[%s%s%s%p] to supplied arguments"),
+		 function_name_style.style ().ptr (),
 		 obj_type_name,
 		 (obj_type_name && *obj_type_name) ? "::" : "",
-		 name);
+		 name, nullptr);
       else
 	warning (_("Using non-standard conversion to match "
-		   "function %s to supplied arguments"),
-		 func_name);
+		   "function %ps to supplied arguments"),
+		 styled_string (function_name_style.style (), func_name));
     }
 
   if (staticp != NULL)
@@ -3726,8 +3729,8 @@ value_struct_elt_for_reference (struct type *domain, int offset,
 	      else if (noside == EVAL_AVOID_SIDE_EFFECTS)
 		return value::allocate (TYPE_FN_FIELD_TYPE (f, j));
 	      else
-		error (_("Cannot reference virtual member function \"%s\""),
-		       name);
+		error (_("Cannot reference virtual member function \"%ps\""),
+		       styled_string (function_name_style.style (), name));
 	    }
 	  else
 	    {

-- 
2.49.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/4] Add more styling of error messages
  2026-04-05 11:28 [PATCH 0/4] Add more styling of error messages Tom Tromey
                   ` (3 preceding siblings ...)
  2026-04-05 11:28 ` [PATCH 4/4] Add function " Tom Tromey
@ 2026-04-05 12:55 ` Andrew Burgess
  2026-04-09  1:10   ` Tom Tromey
  4 siblings, 1 reply; 7+ messages in thread
From: Andrew Burgess @ 2026-04-05 12:55 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches; +Cc: Tom Tromey

Tom Tromey <tom@tromey.com> writes:

> This series adds more styling of error messages.  I searched through
> error messages for common patterns to find the places to edit.  So, I
> have probably missed a few.
>
> I fixed up some quoting in the "command style" patch, but in other
> spots I left it alone.
>
> I didn't write new tests.  I don't know how anyone else feels about
> this but I tend to think that testing the styling of error messages is
> overkill.
>
> There are still more styles that could be applied, for instance line
> numbers.  Also I discovered that the previous fix to allow error() to
> be styled did not apply to throw_error et al.  So, some more work
> there is needed.
>
> Regression tested on x86-64 Fedora 40.

I've not checked every single change, but I looked through a random
sampling, and it all looks good.  Nice to see more styling being added.

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew



>
> Signed-off-by: Tom Tromey <tom@tromey.com>
> ---
> Tom Tromey (4):
>       Add command styling to error messages
>       Add filename styling to error messages
>       Add variable styling to error messages
>       Add function styling to error messages
>
>  gdb/ada-exp.y                       |  8 +++--
>  gdb/ada-tasks.c                     | 10 ++++---
>  gdb/amd64-linux-tdep.c              |  5 ++--
>  gdb/breakpoint.c                    | 50 +++++++++++++++++++++-----------
>  gdb/c-exp.y                         | 10 +++++--
>  gdb/cli/cli-cmds.c                  | 35 ++++++++++++++--------
>  gdb/cli/cli-dump.c                  | 21 +++++++++-----
>  gdb/cli/cli-script.c                | 33 ++++++++++++++-------
>  gdb/cli/cli-utils.c                 | 18 ++++++++----
>  gdb/coffread.c                      | 19 ++++++++----
>  gdb/compile/compile-object-load.c   | 36 +++++++++++++----------
>  gdb/compile/compile.c               |  6 ++--
>  gdb/corelow.c                       | 10 ++++---
>  gdb/ctfread.c                       | 16 ++++++----
>  gdb/d-exp.y                         |  4 ++-
>  gdb/dwarf2/ada-imported.c           |  6 ++--
>  gdb/dwarf2/dwz.c                    |  9 +++---
>  gdb/eval.c                          |  9 ++++--
>  gdb/exec.c                          | 14 +++++----
>  gdb/findvar.c                       |  4 ++-
>  gdb/gcore.c                         |  9 ++++--
>  gdb/gdb_bfd.c                       | 12 +++++---
>  gdb/guile/guile.c                   |  4 ++-
>  gdb/inf-child.c                     |  3 +-
>  gdb/infcall.c                       | 58 ++++++++++++++++++++++---------------
>  gdb/infcmd.c                        |  6 ++--
>  gdb/linespec.c                      |  1 +
>  gdb/linux-nat.c                     |  4 ++-
>  gdb/maint.c                         |  3 +-
>  gdb/parse.c                         |  4 ++-
>  gdb/printcmd.c                      | 11 +++----
>  gdb/python/python.c                 |  3 +-
>  gdb/record-btrace.c                 |  4 ++-
>  gdb/record-full.c                   | 25 +++++++++-------
>  gdb/record.c                        |  6 ++--
>  gdb/remote-fileio.c                 | 11 +++++--
>  gdb/remote.c                        | 20 +++++++++----
>  gdb/rust-lang.c                     |  6 ++--
>  gdb/skip.c                          |  5 ++--
>  gdb/solib-aix.c                     | 16 ++++++----
>  gdb/solib-darwin.c                  |  7 +++--
>  gdb/solib.c                         | 14 +++++----
>  gdb/symfile-mem.c                   | 16 +++++++---
>  gdb/symfile.c                       | 30 +++++++++++--------
>  gdb/symmisc.c                       |  3 +-
>  gdb/symtab.c                        |  3 +-
>  gdb/target.c                        | 41 +++++++++++++++++---------
>  gdb/testsuite/gdb.base/commands.exp |  3 +-
>  gdb/testsuite/gdb.base/default.exp  |  2 +-
>  gdb/tracectf.c                      | 16 ++++++----
>  gdb/tracefile-tfile.c               |  6 ++--
>  gdb/utils.c                         |  4 ++-
>  gdb/valops.c                        | 29 +++++++++++--------
>  gdb/xcoffread.c                     |  6 ++--
>  gdb/xml-support.c                   |  5 +++-
>  55 files changed, 465 insertions(+), 254 deletions(-)
> ---
> base-commit: 2ec5e53d96e3def7ee11966fd07ae215be84515a
> change-id: 20260405-more-error-style-0c3bb6e1b9ad
>
> Best regards,
> -- 
> Tom Tromey <tom@tromey.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/4] Add more styling of error messages
  2026-04-05 12:55 ` [PATCH 0/4] Add more styling of " Andrew Burgess
@ 2026-04-09  1:10   ` Tom Tromey
  0 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2026-04-09  1:10 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: Tom Tromey, gdb-patches

>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:

Andrew> I've not checked every single change, but I looked through a random
Andrew> sampling, and it all looks good.  Nice to see more styling being added.

Andrew> Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks.

I went through the patches again and found one typo which I've fixed:

-	       styled_string (command_style.style (), "while-steppinge"));
+	       styled_string (command_style.style (), "while-stepping"));

I'm going to check it in now.

Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-04-09  1:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-05 11:28 [PATCH 0/4] Add more styling of error messages Tom Tromey
2026-04-05 11:28 ` [PATCH 1/4] Add command styling to " Tom Tromey
2026-04-05 11:28 ` [PATCH 2/4] Add filename " 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox