public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [RFC 2/5] [gdbsupport] Add CATCH_ERROR and CATCH_ERROR_QUIT
Date: Tue, 25 Oct 2022 13:19:42 +0200	[thread overview]
Message-ID: <20221025111945.23886-3-tdevries@suse.de> (raw)
In-Reply-To: <20221025111945.23886-1-tdevries@suse.de>

Add convenience macros CATCH_ERROR and CATCH_ERROR_QUIT, that can be used to
rewrite catch clauses of try/catch statements.

More concretely, this:
...
  catch (const gdb_exception &VAR)
    {
      BODY;
    }
...
into:
...
  CATCH_ERROR_QUIT (VAR, {
      BODY;
    }
...
and this:
...
  catch (const gdb_exception_error &VAR)
    {
      BODY;
    }
...
into:
...
  CATCH_ERROR (VAR, {
      BODY;
    }
...
---
 gdbsupport/common-exceptions.h | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/gdbsupport/common-exceptions.h b/gdbsupport/common-exceptions.h
index 543afda508a..ea998652edc 100644
--- a/gdbsupport/common-exceptions.h
+++ b/gdbsupport/common-exceptions.h
@@ -294,6 +294,37 @@ struct gdb_exception_quit : public gdb_exception
   }
 };
 
+#define CATCH_ERROR_QUIT(VAR, BODY)		\
+  catch (const gdb_exception_error &VAR)	\
+    {						\
+      BODY;					\
+    }						\
+  catch (const gdb_exception_quit &VAR)		\
+    {						\
+      BODY;					\
+    }						\
+  catch (const gdb_exception &)			\
+    {						\
+      /* Exception slicing occurred.  */	\
+      gdb_assert (0);				\
+    }
+
+#define CATCH_ERROR(VAR, BODY)			\
+  catch (const gdb_exception_error &VAR)	\
+    {						\
+      BODY;					\
+    }						\
+  catch (const gdb_exception_quit &)		\
+    {						\
+      throw;					\
+    }						\
+  catch (const gdb_exception &)			\
+    {						\
+      /* Exception slicing occurred.  */	\
+      gdb_assert (0);				\
+    }
+
+
 /* An exception type that inherits from both std::bad_alloc and a gdb
    exception.  This is necessary because operator new can only throw
    std::bad_alloc, and OTOH, we want exceptions thrown due to memory
-- 
2.35.3


  parent reply	other threads:[~2022-10-25 11:19 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-25 11:19 [RFC 0/5] [gdb] Catch rethrow exception slicing Tom de Vries
2022-10-25 11:19 ` [RFC 1/5] [gdb] Catch gdb_exception_quit in munmap_list::~munmap_list Tom de Vries
2022-10-25 11:19 ` Tom de Vries [this message]
2022-10-25 11:19 ` [RFC 3/5] [gdb/contrib] Add refactor.py Tom de Vries
2022-10-25 11:19 ` [RFC 4/5] [gdb/contrib] Add refactor_gdb_exception.py Tom de Vries
2022-10-25 11:19 ` [RFC 5/5] [gdb] Do refactor_gdb_exception refactoring Tom de Vries

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=20221025111945.23886-3-tdevries@suse.de \
    --to=tdevries@suse.de \
    --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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).