]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Style some error messages in source.c
authorTom Tromey <tom@tromey.com>
Thu, 15 Jan 2026 20:24:14 +0000 (13:24 -0700)
committerTom Tromey <tom@tromey.com>
Mon, 23 Mar 2026 18:51:57 +0000 (12:51 -0600)
This applies some CLI styling to error messages in source.c.

gdb/source.c
gdb/testsuite/gdb.base/style.exp

index a4bced1296fcdba6cae7892bfb449bea4153bbf0..6f8afb560d29a7ad2834bfb94e6e1ccb66a950c6 100644 (file)
@@ -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 ());
     }
 
index 040e399e72dd6ec8822136b78a087fcf1226e47f..a12f61884798c1f14ac53d6a1faba260100f5385 100644 (file)
@@ -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