]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add function styling to error messages
authorTom Tromey <tom@tromey.com>
Wed, 1 Apr 2026 22:28:02 +0000 (16:28 -0600)
committerTom Tromey <tom@tromey.com>
Thu, 9 Apr 2026 01:12:45 +0000 (19:12 -0600)
This changes a number of error messages in gdb to use
function_name_style.

Approved-By: Andrew Burgess <aburgess@redhat.com>
gdb/c-exp.y
gdb/dwarf2/ada-imported.c
gdb/eval.c
gdb/infcall.c
gdb/rust-lang.c
gdb/valops.c

index b036e13d1882dc050901eabb5b0107f07c0de737..2829d8bccba2db08c84b0c285284d71ba997cb2f 100644 (file)
@@ -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 (); }
        ;
 
index 0511c9a34b74426b10fb1a9e27cc4284d23886b8..7cdaffef886ecc2f553d2dcbc098180d47dac0f4 100644 (file)
@@ -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 ());
index 1ea7b4d17b4dcd45b97bda0e029aa6c63adfe3c7..a00774bda3dd99cdf2884743eac008d951972b71 100644 (file)
@@ -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);
index f16a1f376b36221453bb1e0c817a5d5b3be4983b..a1328479d0a86906d30c04674dc9932f8cfe5b3a 100644 (file)
@@ -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 ()));
        }
 
     }
index 522b20c97ff491658d230254daca50254a5da205..517d6333d12c7460e80858096bc08835b264f45d 100644 (file)
@@ -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]);
index 207f7d878efe87a8a4788f01cc68774c08d25151..515e43ccdfabcd2a6e205f9ffef3a93df4d40011 100644 (file)
@@ -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
            {