[binutils-gdb] Add function styling to error messages

Tom Tromey via Gdb-cvs <[email protected]>
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=433917ca0ac06fd20d4a97e21447d1536eb80e5a

commit 433917ca0ac06fd20d4a97e21447d1536eb80e5a
Author: Tom Tromey <[email protected]>
Date:   Wed Apr 1 16:28:02 2026 -0600

    Add function styling to error messages
    
    This changes a number of error messages in gdb to use
    function_name_style.
    
    Approved-By: Andrew Burgess <[email protected]>

Diff:
---
 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 f16a1f376b3..a1328479d0a 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
 	    {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.