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

This changes a number of error messages in gdb to use
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


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

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-05 11:28 [PATCH 0/4] Add more styling of " Tom Tromey
2026-04-05 11:28 ` [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 ` Tom Tromey [this message]
2026-04-05 12:55 ` [PATCH 0/4] Add more styling of " Andrew Burgess
2026-04-09  1:10   ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260405-more-error-style-v1-4-6c04da718875@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox