Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 2/5] Use file- and line-styling with throw_error
Date: Fri, 10 Apr 2026 16:59:42 -0600	[thread overview]
Message-ID: <20260410-unify-exceptions-v1-2-ea64dae971a8@tromey.com> (raw)
In-Reply-To: <20260410-unify-exceptions-v1-0-ea64dae971a8@tromey.com>

This changes some throw_error calls to apply file_name_style and
line_number_style.  This patch does both at the same time because the
two styles often appear in the same message.
---
 gdb/cli/cli-script.c |  7 +++++--
 gdb/linespec.c       | 24 ++++++++++++++++--------
 2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 13ef2fb03ce..e081f0454b3 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -1718,8 +1718,11 @@ script_from_file (FILE *stream, const char *file)
       /* Re-throw the error, but with the file name information
 	 prepended.  */
       throw_error (e.error,
-		   _("%s:%d: Error in sourced command file:\n%s"),
-		   source_file_name.c_str (), source_line_number,
+		   _("%ps:%ps: Error in sourced command file:\n%s"),
+		   styled_string (file_name_style.style (),
+				  source_file_name.c_str ()),
+		   styled_string (line_number_style.style (),
+				  plongest (source_line_number)),
 		   e.what ());
     }
 }
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 981bd5faa4f..435b4fbcd2f 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -35,6 +35,7 @@
 #include "interps.h"
 #include "target.h"
 #include "arch-utils.h"
+#include "cli/cli-style.h"
 #include "cli/cli-utils.h"
 #include "filenames.h"
 #include "ada-lang.h"
@@ -1540,7 +1541,8 @@ symbol_not_found_error (const char *symbol, const char *filename)
       if (filename)
 	throw_error (NOT_FOUND_ERROR,
 		     _("Undefined convenience variable or function \"%s\" "
-		       "not defined in \"%s\"."), symbol, filename);
+		       "not defined in \"%ps\"."), symbol,
+		     styled_string (file_name_style.style (), filename));
       else
 	throw_error (NOT_FOUND_ERROR,
 		     _("Undefined convenience variable or function \"%s\" "
@@ -1550,8 +1552,9 @@ symbol_not_found_error (const char *symbol, const char *filename)
     {
       if (filename)
 	throw_error (NOT_FOUND_ERROR,
-		     _("Function \"%s\" not defined in \"%s\"."),
-		     symbol, filename);
+		     _("Function \"%s\" not defined in \"%ps\"."),
+		     symbol,
+		     styled_string (file_name_style.style (), filename));
       else
 	throw_error (NOT_FOUND_ERROR,
 		     _("Function \"%s\" not defined."), symbol);
@@ -1606,7 +1609,8 @@ undefined_label_error (const char *function, const char *label)
 [[noreturn]] static void
 source_file_not_found_error (const char *name)
 {
-  throw_error (NOT_FOUND_ERROR, _("No source file named %s."), name);
+  throw_error (NOT_FOUND_ERROR, _("No source file named %ps."),
+	       styled_string (file_name_style.style (), name));
 }
 
 /* Unless at EIO, save the current stream position as completion word
@@ -2145,12 +2149,16 @@ create_sals_line_offset (struct linespec_state *self,
     {
       if (ls->explicit_loc.source_filename)
 	throw_error (NOT_FOUND_ERROR,
-		     _("No compiled code for line %d in file \"%s\"."),
-		     line, ls->explicit_loc.source_filename.get ());
+		     _("No compiled code for line %ps in file \"%ps\"."),
+		     styled_string (line_number_style.style (),
+				    plongest (line)),
+		     styled_string (file_name_style.style (),
+				    ls->explicit_loc.source_filename.get ()));
       else
 	throw_error (NOT_FOUND_ERROR,
-		     _("No compiled code for line %d in the current file."),
-		     line);
+		     _("No compiled code for line %ps in the current file."),
+		     styled_string (line_number_style.style (),
+				    plongest (line)));
     }
 
   return values;

-- 
2.49.0


  parent reply	other threads:[~2026-04-10 23:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-10 22:59 [PATCH 0/5] Allow throw_* functions to style message Tom Tromey
2026-04-10 22:59 ` [PATCH 1/5] Allow styling when using throw_* functions Tom Tromey
2026-04-10 22:59 ` Tom Tromey [this message]
2026-04-10 22:59 ` [PATCH 3/5] Use command style with throw_error Tom Tromey
2026-04-10 22:59 ` [PATCH 4/5] Use function " Tom Tromey
2026-04-10 22:59 ` [PATCH 5/5] Use address " Tom Tromey
2026-05-08 19:02 ` [PATCH 0/5] Allow throw_* functions to style message Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260410-unify-exceptions-v1-2-ea64dae971a8@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox