* [PATCH] gdbsupport: assert upon an unhandled exception in scope_exit
@ 2026-10-07 12:27 Stephan Rohr
2026-10-09 10:32 ` Andrew Burgess
0 siblings, 1 reply; 3+ messages in thread
From: Stephan Rohr @ 2026-10-07 12:27 UTC (permalink / raw)
To: gdb-patches
From: Mihails Strasuns <mihails.strasuns@intel.com>
Add a catch-all statement in a scope_exit_base class destructor to turn
any unhandled exception from "POLICY::on_exit ()" into a GDB assertion -
any such case is a programming error, because it is not legal in C++ to
throw from a destructor.
Co-Authored-By: Rohr, Stephan <stephan.rohr@intel.com>
---
gdbsupport/scope-exit.h | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/gdbsupport/scope-exit.h b/gdbsupport/scope-exit.h
index c90b3194cb5..1dfdb1ef695 100644
--- a/gdbsupport/scope-exit.h
+++ b/gdbsupport/scope-exit.h
@@ -68,7 +68,17 @@ class scope_exit_base : private POLICY
~scope_exit_base ()
{
if (!m_released)
- POLICY::on_exit ();
+ {
+ try
+ {
+ POLICY::on_exit ();
+ }
+ catch (const gdb_exception &ex)
+ {
+ gdb_assert_not_reached ("unhandled exception in scope exit: %s",
+ ex.message != nullptr ? ex.what () : "");
+ }
+ }
}
DISABLE_COPY_AND_ASSIGN (scope_exit_base);
--
2.43.0
________________________________________
Intel Deutschland GmbH
Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 (89) 99143-0
www.intel.de
Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman
Chairperson of the Supervisory Board: Sonja Pierer
Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928
This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gdbsupport: assert upon an unhandled exception in scope_exit
2026-10-07 12:27 [PATCH] gdbsupport: assert upon an unhandled exception in scope_exit Stephan Rohr
@ 2026-10-09 10:32 ` Andrew Burgess
2026-10-14 13:11 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Burgess @ 2026-10-09 10:32 UTC (permalink / raw)
To: Stephan Rohr, gdb-patches
Stephan Rohr <stephan.rohr@intel.com> writes:
> From: Mihails Strasuns <mihails.strasuns@intel.com>
>
> Add a catch-all statement in a scope_exit_base class destructor to turn
> any unhandled exception from "POLICY::on_exit ()" into a GDB assertion -
> any such case is a programming error, because it is not legal in C++ to
> throw from a destructor.
>
> Co-Authored-By: Rohr, Stephan <stephan.rohr@intel.com>
> ---
> gdbsupport/scope-exit.h | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/gdbsupport/scope-exit.h b/gdbsupport/scope-exit.h
> index c90b3194cb5..1dfdb1ef695 100644
> --- a/gdbsupport/scope-exit.h
> +++ b/gdbsupport/scope-exit.h
> @@ -68,7 +68,17 @@ class scope_exit_base : private POLICY
> ~scope_exit_base ()
> {
> if (!m_released)
> - POLICY::on_exit ();
> + {
> + try
> + {
> + POLICY::on_exit ();
> + }
> + catch (const gdb_exception &ex)
> + {
> + gdb_assert_not_reached ("unhandled exception in scope exit: %s",
> + ex.message != nullptr ? ex.what () : "");
I was originally going to write ex.message cannot be nullptr as we never
guard calls to ex.what anywhere else in GDB. But after checking, it is
possible to create a gdb_exception with a nullptr message. I guess in
practice though this never happens as any exception thrown vie
error(...) will always have been give a message, you'd have to work hard
to throw an exception without a message.
I wonder if we should make the what() function handle this case? But I
suspect that's for another day. I think this commit is fine as is, so:
Approved-By: Andrew Burgess <aburgess@redhat.com>
Thanks,
Andrew
> + }
> + }
> }
>
> DISABLE_COPY_AND_ASSIGN (scope_exit_base);
> --
> 2.43.0
>
> ________________________________________
> Intel Deutschland GmbH
>
> Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
>
> Tel: +49 (89) 99143-0
>
> www.intel.de
>
> Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman
>
> Chairperson of the Supervisory Board: Sonja Pierer
>
> Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928
>
> This e-mail and any attachments may contain confidential material for
> the sole use of the intended recipient(s). Any review or distribution
> by others is strictly prohibited. If you are not the intended
> recipient, please contact the sender and delete all copies.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gdbsupport: assert upon an unhandled exception in scope_exit
2026-10-09 10:32 ` Andrew Burgess
@ 2026-10-14 13:11 ` Tom Tromey
0 siblings, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2026-10-14 13:11 UTC (permalink / raw)
To: Andrew Burgess; +Cc: Stephan Rohr, gdb-patches
>>>>> "Andrew" == Andrew Burgess <aburgess@redhat.com> writes:
Andrew> I was originally going to write ex.message cannot be nullptr as we never
Andrew> guard calls to ex.what anywhere else in GDB. But after checking, it is
Andrew> possible to create a gdb_exception with a nullptr message. I guess in
Andrew> practice though this never happens as any exception thrown vie
Andrew> error(...) will always have been give a message, you'd have to work hard
Andrew> to throw an exception without a message.
Andrew> I wonder if we should make the what() function handle this case?
Yeah, I think we should not allow making a message-less gdb exception.
IIUC.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-14 13:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-07 12:27 [PATCH] gdbsupport: assert upon an unhandled exception in scope_exit Stephan Rohr
2026-10-09 10:32 ` Andrew Burgess
2026-10-14 13:11 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox