Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH 0/5] Allow throw_* functions to style message
@ 2026-04-10 22:59 Tom Tromey
  2026-04-10 22:59 ` [PATCH 1/5] Allow styling when using throw_* functions Tom Tromey
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Tom Tromey @ 2026-04-10 22:59 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Like the earlier series to style error messages, this series adds
styling to various throw_* calls in gdb.  This required a small change
enable this in gdbsupport.

Regression tested on x86-64 Fedora 40

Signed-off-by: Tom Tromey <tom@tromey.com>
---
Tom Tromey (5):
      Allow styling when using throw_* functions
      Use file- and line-styling with throw_error
      Use command style with throw_error
      Use function style with throw_error
      Use address style with throw_error

 gdb/cli/cli-script.c           |  7 +++++--
 gdb/displaced-stepping.c       |  7 +++++--
 gdb/infcall.c                  |  1 +
 gdb/linespec.c                 | 38 +++++++++++++++++++++++++-------------
 gdb/utils.c                    | 10 ++++++++++
 gdb/valarith.c                 |  7 +++++--
 gdbserver/utils.cc             | 12 ++++++++++++
 gdbsupport/common-exceptions.h |  7 ++++++-
 8 files changed, 69 insertions(+), 20 deletions(-)
---
base-commit: b90e5339140ee1ff0ff454098c882bf7dcf9bbf9
change-id: 20260410-unify-exceptions-fab2c7f53b35

Best regards,
-- 
Tom Tromey <tom@tromey.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/5] Allow styling when using throw_* functions
  2026-04-10 22:59 [PATCH 0/5] Allow throw_* functions to style message Tom Tromey
@ 2026-04-10 22:59 ` Tom Tromey
  2026-04-10 22:59 ` [PATCH 2/5] Use file- and line-styling with throw_error Tom Tromey
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2026-04-10 22:59 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

The throw_* family of functions use the varargs constructor for
gdb_exception, which then calls string_vprintf.  This means that
styling cannot be applied here by gdb.

This patch changes this code to use a client-supplied formatting
function.  For gdbserver this remains string_vprintf, but for gdb it
now allows styling.

I did look at unifying 'error' and the throw_* functions a bit more,
but this would have meant unravelling some IPA code.
---
 gdb/utils.c                    | 10 ++++++++++
 gdbserver/utils.cc             | 12 ++++++++++++
 gdbsupport/common-exceptions.h |  7 ++++++-
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/gdb/utils.c b/gdb/utils.c
index f5f19301460..988f2d876d1 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -182,6 +182,16 @@ vwarning (const char *string, va_list args)
     }
 }
 
+/* See common-exceptions.h.  */
+
+std::string
+vformat_exception (const char *fmt, va_list args)
+{
+  string_file text (true);
+  text.vprintf (fmt, args);
+  return text.release ();
+}
+
 /* Print an error message and return to command level.
    The first argument STRING is the error message, used as a fprintf string,
    and the remaining args are passed as arguments to it.  */
diff --git a/gdbserver/utils.cc b/gdbserver/utils.cc
index 9bc3fc4477e..468e803e34d 100644
--- a/gdbserver/utils.cc
+++ b/gdbserver/utils.cc
@@ -104,3 +104,15 @@ paddress (CORE_ADDR addr)
 {
   return phex_nz (addr);
 }
+
+#ifndef IN_PROCESS_AGENT
+
+/* See common-exceptions.h.  */
+
+std::string
+vformat_exception (const char *fmt, va_list args)
+{
+  return string_vprintf (fmt, args);
+}
+
+#endif /* IN_PROCESS_AGENT */
diff --git a/gdbsupport/common-exceptions.h b/gdbsupport/common-exceptions.h
index 5a50ff44c31..1f3bc84216e 100644
--- a/gdbsupport/common-exceptions.h
+++ b/gdbsupport/common-exceptions.h
@@ -116,6 +116,11 @@ enum errors {
   NR_ERRORS
 };
 
+/* The client application must provide this.  It is a printf-like that
+   formats a string for an exception.  */
+std::string vformat_exception (const char *fmt, va_list args)
+  ATTRIBUTE_PRINTF (1, 0);
+
 struct gdb_exception
 {
   gdb_exception ()
@@ -142,7 +147,7 @@ struct gdb_exception
     ATTRIBUTE_PRINTF (4, 0)
     : reason (r),
       error (e),
-      message (std::make_shared<std::string> (string_vprintf (fmt, ap)))
+      message (std::make_shared<std::string> (vformat_exception (fmt, ap)))
   {
   }
 

-- 
2.49.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/5] Use file- and line-styling with throw_error
  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
  2026-04-10 22:59 ` [PATCH 3/5] Use command style " Tom Tromey
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2026-04-10 22:59 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/5] Use command style with throw_error
  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 ` [PATCH 2/5] Use file- and line-styling with throw_error Tom Tromey
@ 2026-04-10 22:59 ` Tom Tromey
  2026-04-10 22:59 ` [PATCH 4/5] Use function " Tom Tromey
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2026-04-10 22:59 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes some calls to throw_error to use command_style.
---
 gdb/linespec.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gdb/linespec.c b/gdb/linespec.c
index 435b4fbcd2f..493ad47e76a 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -1530,7 +1530,8 @@ symbol_not_found_error (const char *symbol, const char *filename)
       && !current_program_space->has_partial_symbols ()
       && !current_program_space->has_minimal_symbols ())
     throw_error (NOT_FOUND_ERROR,
-		 _("No symbol table is loaded.  Use the \"file\" command."));
+		 _("No symbol table is loaded.  Use the \"%ps\" command."),
+		 styled_string (command_style.style (), "file"));
 
   /* If SYMBOL starts with '$', the user attempted to either lookup
      a function/variable in his code starting with '$' or an internal
@@ -3660,7 +3661,8 @@ symtabs_from_filename (const char *filename,
 	  && !current_program_space->has_partial_symbols ())
 	throw_error (NOT_FOUND_ERROR,
 		     _("No symbol table is loaded.  "
-		       "Use the \"file\" command."));
+		       "Use the \"%ps\" command."),
+		     styled_string (command_style.style (), "file"));
       source_file_not_found_error (filename);
     }
 

-- 
2.49.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 4/5] Use function style with throw_error
  2026-04-10 22:59 [PATCH 0/5] Allow throw_* functions to style message Tom Tromey
                   ` (2 preceding siblings ...)
  2026-04-10 22:59 ` [PATCH 3/5] Use command style " Tom Tromey
@ 2026-04-10 22:59 ` 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
  5 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2026-04-10 22:59 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes some calls to throw_error to use function_name_style.
---
 gdb/infcall.c  |  1 +
 gdb/linespec.c | 12 +++++++-----
 gdb/valarith.c |  7 +++++--
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/gdb/infcall.c b/gdb/infcall.c
index a1328479d0a..8b26f541de6 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -29,6 +29,7 @@
 #include "language.h"
 #include "objfiles.h"
 #include "cli/cli-cmds.h"
+#include "cli/cli-style.h"
 #include "command.h"
 #include "dummy-frame.h"
 #include "ada-lang.h"
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 493ad47e76a..bd3b1c9386a 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -1553,12 +1553,13 @@ symbol_not_found_error (const char *symbol, const char *filename)
     {
       if (filename)
 	throw_error (NOT_FOUND_ERROR,
-		     _("Function \"%s\" not defined in \"%ps\"."),
-		     symbol,
+		     _("Function \"%ps\" not defined in \"%ps\"."),
+		     styled_string (function_name_style.style (), symbol),
 		     styled_string (file_name_style.style (), filename));
       else
 	throw_error (NOT_FOUND_ERROR,
-		     _("Function \"%s\" not defined."), symbol);
+		     _("Function \"%ps\" not defined."),
+		     styled_string (function_name_style.style (), symbol));
     }
 }
 
@@ -1597,8 +1598,9 @@ undefined_label_error (const char *function, const char *label)
 {
   if (function != NULL)
     throw_error (NOT_FOUND_ERROR,
-		_("No label \"%s\" defined in function \"%s\"."),
-		label, function);
+		 _("No label \"%s\" defined in function \"%ps\"."),
+		 label,
+		 styled_string (function_name_style.style (), function));
   else
     throw_error (NOT_FOUND_ERROR,
 		_("No label \"%s\" defined in current function."),
diff --git a/gdb/valarith.c b/gdb/valarith.c
index 673bdee2d11..ed5b5d8adf9 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -30,6 +30,7 @@
 #include "gdbarch.h"
 #include "rust-lang.h"
 #include "ada-lang.h"
+#include "cli/cli-style.h"
 
 /* Forward declarations.  */
 static struct value *value_subscripted_rvalue (struct value *array,
@@ -559,7 +560,8 @@ value_x_binop (struct value *arg1, struct value *arg2, enum exp_opcode op,
 				    argvec.slice (1, 2 - static_memfuncp));
     }
   throw_error (NOT_FOUND_ERROR,
-	       _("member function %s not found"), tstr);
+	       _("member function %ps not found"),
+	       styled_string (function_name_style.style (), tstr));
 }
 
 /* We know that arg1 is a structure, so try to find a unary user
@@ -672,7 +674,8 @@ value_x_unop (struct value *arg1, enum exp_opcode op, enum noside noside)
 				    argvec.slice (1, nargs));
     }
   throw_error (NOT_FOUND_ERROR,
-	       _("member function %s not found"), tstr);
+	       _("member function %ps not found"),
+	       styled_string (function_name_style.style (), tstr));
 }
 \f
 

-- 
2.49.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 5/5] Use address style with throw_error
  2026-04-10 22:59 [PATCH 0/5] Allow throw_* functions to style message Tom Tromey
                   ` (3 preceding siblings ...)
  2026-04-10 22:59 ` [PATCH 4/5] Use function " Tom Tromey
@ 2026-04-10 22:59 ` Tom Tromey
  2026-05-08 19:02 ` [PATCH 0/5] Allow throw_* functions to style message Tom Tromey
  5 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2026-04-10 22:59 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes a call to throw_error to use address_style.
---
 gdb/displaced-stepping.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/gdb/displaced-stepping.c b/gdb/displaced-stepping.c
index 7d2ebf2b7d0..caff9aa99fa 100644
--- a/gdb/displaced-stepping.c
+++ b/gdb/displaced-stepping.c
@@ -20,6 +20,7 @@
 #include "displaced-stepping.h"
 
 #include "cli/cli-cmds.h"
+#include "cli/cli-style.h"
 #include "command.h"
 #include "gdbarch.h"
 #include "gdbcore.h"
@@ -115,9 +116,11 @@ displaced_step_buffers::prepare (thread_info *thread, CORE_ADDR &displaced_pc)
 				    buffer->saved_copy.data (), len);
   if (status != 0)
     throw_error (MEMORY_ERROR,
-		 _("Error accessing memory address %s (%s) for "
+		 _("Error accessing memory address %ps (%s) for "
 		   "displaced-stepping scratch space."),
-		 paddress (arch, buffer->addr), safe_strerror (status));
+		 styled_string (address_style.style (),
+				paddress (arch, buffer->addr)),
+		 safe_strerror (status));
 
   displaced_debug_printf ("saved %s: %s",
 			  paddress (arch, buffer->addr),

-- 
2.49.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/5] Allow throw_* functions to style message
  2026-04-10 22:59 [PATCH 0/5] Allow throw_* functions to style message Tom Tromey
                   ` (4 preceding siblings ...)
  2026-04-10 22:59 ` [PATCH 5/5] Use address " Tom Tromey
@ 2026-05-08 19:02 ` Tom Tromey
  5 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2026-05-08 19:02 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> Like the earlier series to style error messages, this series adds
Tom> styling to various throw_* calls in gdb.  This required a small change
Tom> enable this in gdbsupport.

Tom> Regression tested on x86-64 Fedora 40

I'm checking these in now.

Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-05-08 19:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/5] Use file- and line-styling with throw_error Tom Tromey
2026-04-10 22:59 ` [PATCH 3/5] Use command style " 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox