[binutils-gdb] Add variable 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=0a54ab47aa9be5d542672afe1b5cffb79cd0df81

commit 0a54ab47aa9be5d542672afe1b5cffb79cd0df81
Author: Tom Tromey <[email protected]>
Date:   Wed Apr 1 16:17:33 2026 -0600

    Add variable styling to error messages
    
    This changes some error messages in gdb to use variable_name_style.
    
    Approved-By: Andrew Burgess <[email protected]>

Diff:
---
 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"
 
 
 /* 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);
 }
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.