[binutils-gdb] Style some error messages in source.c

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=b7feb63aa7d1bf44beba5fec756069133a09c46f

commit b7feb63aa7d1bf44beba5fec756069133a09c46f
Author: Tom Tromey <[email protected]>
Date:   Thu Jan 15 13:24:14 2026 -0700

    Style some error messages in source.c
    
    This applies some CLI styling to error messages in source.c.

Diff:
---
 gdb/source.c                     | 9 ++++++---
 gdb/testsuite/gdb.base/style.exp | 4 ++++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/gdb/source.c b/gdb/source.c
index a4bced1296f..6f8afb560d2 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -256,7 +256,8 @@ set_default_source_symtab_and_line (void)
 {
   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"));
 
   /* Pull in a current source symtab if necessary.  */
   current_source_location *loc = get_source_location (current_program_space);
@@ -1343,8 +1344,10 @@ print_source_lines_base (struct symtab *s, int line, int stopline,
   if (!g_source_cache.get_source_lines (s, line, stopline - 1, &lines))
     {
       std::optional<int> last_lineno = last_symtab_line (s);
-      error (_("Line number %d out of range; %s has %d lines."),
-	     line, symtab_to_filename_for_display (s),
+      error (_("Line number %ps out of range; %ps has %d lines."),
+	     styled_string (line_number_style.style (), plongest (line)),
+	     styled_string (file_name_style.style (),
+			    symtab_to_filename_for_display (s)),
 	     !last_lineno.has_value () ? 0 : last_lineno.value ());
     }
 
diff --git a/gdb/testsuite/gdb.base/style.exp b/gdb/testsuite/gdb.base/style.exp
index 040e399e72d..a12f6188479 100644
--- a/gdb/testsuite/gdb.base/style.exp
+++ b/gdb/testsuite/gdb.base/style.exp
@@ -1080,6 +1080,10 @@ proc test_logging_styling {} {
     gdb_test "set logging enabled off" \
 	"Done logging to [style $filename file]\\." \
 	"filename styled when logging disabled"
+
+    # Test that error messages are styled.
+    gdb_test "list" \
+	"No symbol table is loaded\\.  Use the \"[style file command]\" command\\."
 }
 
 # Check to see if the Python styling of disassembler output is
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.