From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 1/5] Allow styling when using throw_* functions
Date: Fri, 10 Apr 2026 16:59:41 -0600 [thread overview]
Message-ID: <20260410-unify-exceptions-v1-1-ea64dae971a8@tromey.com> (raw)
In-Reply-To: <20260410-unify-exceptions-v1-0-ea64dae971a8@tromey.com>
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
next prev parent reply other threads:[~2026-04-10 23:01 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 ` Tom Tromey [this message]
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
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-1-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