public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 00/22] Remove cleanups
@ 2019-02-27 20:18 Tom Tromey
  2019-02-27 20:18 ` [PATCH v2 08/22] Remove last cleanup solib-aix.c Tom Tromey
                   ` (21 more replies)
  0 siblings, 22 replies; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:18 UTC (permalink / raw)
  To: gdb-patches

Here's version 2 of the series to remove (non-final) cleanups.

Version 1 was here:

    https://sourceware.org/ml/gdb-patches/2019-02/msg00193.html

This version changes the code to catch exceptions by const reference,
and also adds a new patch to rename the exception classes.  This
turned out to be a bit simpler to do separately.

Tested by the buildbot.  Let me know what you think.

Tom


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

* [PATCH v2 05/22] Remove last cleanup from gdbserver
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
  2019-02-27 20:18 ` [PATCH v2 08/22] Remove last cleanup solib-aix.c Tom Tromey
@ 2019-02-27 20:18 ` Tom Tromey
  2019-03-06 19:23   ` Pedro Alves
  2019-02-27 20:19 ` [PATCH v2 01/22] Remove cleanups from coffread.c Tom Tromey
                   ` (19 subsequent siblings)
  21 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:18 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes the last cleanup from gdbserver, replacing it with
SCOPE_EXIT.  This could perhaps be done in a different way, but this
approach was direct and obviously correct.

gdb/gdbserver/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* server.c (detach_or_kill_for_exit_cleanup): Remove parameter.
	(captured_main): Use SCOPE_EXIT.
---
 gdb/gdbserver/ChangeLog |  5 +++++
 gdb/gdbserver/server.c  | 11 ++++++-----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index e960c10d402..25c62aad830 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -43,6 +43,7 @@
 #include "common/pathstuff.h"
 
 #include "common/selftest.h"
+#include "common/scope-exit.h"
 
 #define require_running_or_return(BUF)		\
   if (!target_running ())			\
@@ -3545,17 +3546,16 @@ detach_or_kill_for_exit (void)
 /* Value that will be passed to exit(3) when gdbserver exits.  */
 static int exit_code;
 
-/* Cleanup version of detach_or_kill_for_exit.  */
+/* Wrapper for detach_or_kill_for_exit that catches and prints
+   errors.  */
 
 static void
-detach_or_kill_for_exit_cleanup (void *ignore)
+detach_or_kill_for_exit_cleanup ()
 {
-
   TRY
     {
       detach_or_kill_for_exit ();
     }
-
   CATCH (exception, RETURN_MASK_ALL)
     {
       fflush (stdout);
@@ -3832,7 +3832,8 @@ captured_main (int argc, char *argv[])
       cs.last_status.value.integer = 0;
       cs.last_ptid = minus_one_ptid;
     }
-  make_cleanup (detach_or_kill_for_exit_cleanup, NULL);
+
+  SCOPE_EXIT { detach_or_kill_for_exit_cleanup (); };
 
   /* Don't report shared library events on the initial connection,
      even if some libraries are preloaded.  Avoids the "stopped by
-- 
2.17.2

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

* [PATCH v2 08/22] Remove last cleanup solib-aix.c
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
@ 2019-02-27 20:18 ` Tom Tromey
  2019-03-06 19:34   ` Pedro Alves
  2019-02-27 20:18 ` [PATCH v2 05/22] Remove last cleanup from gdbserver Tom Tromey
                   ` (20 subsequent siblings)
  21 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:18 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes the last cleanup solib-aix.c, replacing it with a use of
make_scope_exit.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* solib-aix.c: Use make_scope_exit.
---
 gdb/ChangeLog   |  4 ++++
 gdb/solib-aix.c | 10 ++++++----
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/gdb/solib-aix.c b/gdb/solib-aix.c
index 85c05a42ebf..c5fb7d58525 100644
--- a/gdb/solib-aix.c
+++ b/gdb/solib-aix.c
@@ -26,6 +26,7 @@
 #include "xcoffread.h"
 #include "observable.h"
 #include "gdbcmd.h"
+#include "common/scope-exit.h"
 
 /* Variable controlling the output of the debugging traces for
    this module.  */
@@ -242,18 +243,19 @@ static VEC (lm_info_aix_p) *
 solib_aix_parse_libraries (const char *library)
 {
   VEC (lm_info_aix_p) *result = NULL;
-  struct cleanup *back_to = make_cleanup (solib_aix_free_library_list,
-                                          &result);
+  auto cleanup = make_scope_exit ([&] ()
+				  {
+				    solib_aix_free_library_list (&result);
+				  });
 
   if (gdb_xml_parse_quick (_("aix library list"), "library-list-aix.dtd",
                            library_list_elements, library, &result) == 0)
     {
       /* Parsed successfully, keep the result.  */
-      discard_cleanups (back_to);
+      cleanup.release ();
       return result;
     }
 
-  do_cleanups (back_to);
   return NULL;
 }
 
-- 
2.17.2

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

* [PATCH v2 14/22] Simplify exception handling
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
                   ` (15 preceding siblings ...)
  2019-02-27 20:19 ` [PATCH v2 20/22] Replace throw_exception with throw in some cases Tom Tromey
@ 2019-02-27 20:19 ` Tom Tromey
  2019-04-02 22:07   ` Pedro Alves
  2019-02-27 20:19 ` [PATCH v2 18/22] Remove some now-dead exception code Tom Tromey
                   ` (4 subsequent siblings)
  21 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Now that cleanups have been removed, TRY/CATCH can't be SJLJ-based any
more.  This patch simplifies the exception handling code, by removing
the non-working variants.

Note that the "pure" C++ exception handling code is removed as well; I
think the route forward must be to change exceptions to be
self-destructing, so that try_scope_depth can simply be removed.

Some longjmp-based code remains, as it is needed to throw an exception
through readline.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* common/common-exceptions.h (GDB_XCPT_SJMP, GDB_XCPT_TRY)
	(GDB_XCPT_RAW_TRY, GDB_XCPT): Remove.
	(TRY, CATCH, END_CATCH): Remove some definitions.
	* common/common-exceptions.c: Don't use GDB_XCPT.
	(catcher_list_size): Remove.
	(throw_exception, throw_it): Simplify.
---
 gdb/ChangeLog                  |  9 +++++++
 gdb/common/common-exceptions.c | 36 --------------------------
 gdb/common/common-exceptions.h | 46 +---------------------------------
 3 files changed, 10 insertions(+), 81 deletions(-)

diff --git a/gdb/common/common-exceptions.c b/gdb/common/common-exceptions.c
index 4e67e898bda..c3529c989fd 100644
--- a/gdb/common/common-exceptions.c
+++ b/gdb/common/common-exceptions.c
@@ -54,26 +54,6 @@ struct catcher
 /* Where to go for throw_exception().  */
 static struct catcher *current_catcher;
 
-#if GDB_XCPT == GDB_XCPT_SJMP
-
-/* Return length of current_catcher list.  */
-
-static int
-catcher_list_size (void)
-{
-  int size;
-  struct catcher *catcher;
-
-  for (size = 0, catcher = current_catcher;
-       catcher != NULL;
-       catcher = catcher->prev)
-    ++size;
-
-  return size;
-}
-
-#endif
-
 jmp_buf *
 exceptions_state_mc_init (void)
 {
@@ -205,8 +185,6 @@ exceptions_state_mc_action_iter_1 (void)
   return exceptions_state_mc (CATCH_ITER_1);
 }
 
-#if GDB_XCPT != GDB_XCPT_SJMP
-
 /* How many nested TRY blocks we have.  See exception_messages and
    throw_it.  */
 
@@ -248,8 +226,6 @@ gdb_exception_sliced_copy (struct gdb_exception *to, const struct gdb_exception
   *to = *from;
 }
 
-#endif /* !GDB_XCPT_SJMP */
-
 /* Return EXCEPTION to the nearest containing CATCH_SJLJ block.  */
 
 void
@@ -263,8 +239,6 @@ throw_exception_sjlj (struct gdb_exception exception)
   longjmp (current_catcher->buf, exception.reason);
 }
 
-#if GDB_XCPT != GDB_XCPT_SJMP
-
 /* Implementation of throw_exception that uses C++ try/catch.  */
 
 static ATTRIBUTE_NORETURN void
@@ -288,16 +262,10 @@ throw_exception_cxx (struct gdb_exception exception)
     gdb_assert_not_reached ("invalid return reason");
 }
 
-#endif
-
 void
 throw_exception (struct gdb_exception exception)
 {
-#if GDB_XCPT == GDB_XCPT_SJMP
-  throw_exception_sjlj (exception);
-#else
   throw_exception_cxx (exception);
-#endif
 }
 
 /* A stack of exception messages.
@@ -321,11 +289,7 @@ throw_it (enum return_reason reason, enum errors error, const char *fmt,
 {
   struct gdb_exception e;
   char *new_message;
-#if GDB_XCPT == GDB_XCPT_SJMP
-  int depth = catcher_list_size ();
-#else
   int depth = try_scope_depth;
-#endif
 
   gdb_assert (depth > 0);
 
diff --git a/gdb/common/common-exceptions.h b/gdb/common/common-exceptions.h
index 471e7c5cf81..6cc09eab938 100644
--- a/gdb/common/common-exceptions.h
+++ b/gdb/common/common-exceptions.h
@@ -115,22 +115,6 @@ struct gdb_exception
   const char *message;
 };
 
-/* The different exception mechanisms that TRY/CATCH can map to.  */
-
-/* Make GDB exceptions use setjmp/longjmp behind the scenes.  */
-#define GDB_XCPT_SJMP 1
-
-/* Make GDB exceptions use try/catch behind the scenes.  */
-#define GDB_XCPT_TRY 2
-
-/* Specify this mode to build with TRY/CATCH mapped directly to raw
-   try/catch.  GDB won't work correctly, but building that way catches
-   code tryin to break/continue out of the try block, along with
-   spurious code between the TRY and the CATCH block.  */
-#define GDB_XCPT_RAW_TRY 3
-
-#define GDB_XCPT GDB_XCPT_TRY
-
 /* Functions to drive the sjlj-based exceptions state machine.  Though
    declared here by necessity, these functions should be considered
    internal to the exceptions subsystem and not used other than via
@@ -141,13 +125,11 @@ extern int exceptions_state_mc_action_iter (void);
 extern int exceptions_state_mc_action_iter_1 (void);
 extern int exceptions_state_mc_catch (struct gdb_exception *, int);
 
-/* Same, but for the C++ try/catch-based TRY/CATCH mechanism.  */
+/* For the C++ try/catch-based TRY/CATCH mechanism.  */
 
-#if GDB_XCPT != GDB_XCPT_SJMP
 extern void *exception_try_scope_entry (void);
 extern void exception_try_scope_exit (void *saved_state);
 extern void exception_rethrow (void) ATTRIBUTE_NORETURN;
-#endif
 
 /* Macro to wrap up standard try/catch behavior.
 
@@ -196,19 +178,6 @@ extern void exception_rethrow (void) ATTRIBUTE_NORETURN;
 #define END_CATCH_SJLJ				\
   }
 
-#if GDB_XCPT == GDB_XCPT_SJMP
-
-/* If using SJLJ-based exceptions for all exceptions, then provide
-   standard aliases.  */
-
-#define TRY TRY_SJLJ
-#define CATCH CATCH_SJLJ
-#define END_CATCH END_CATCH_SJLJ
-
-#endif /* GDB_XCPT_SJMP */
-
-#if GDB_XCPT == GDB_XCPT_TRY || GDB_XCPT == GDB_XCPT_RAW_TRY
-
 /* Prevent error/quit during TRY from calling cleanups established
    prior to here.  This pops out the scope in either case of normal
    exit or exception exit.  */
@@ -226,8 +195,6 @@ struct exception_try_scope
   void *saved_state;
 };
 
-#if GDB_XCPT == GDB_XCPT_TRY
-
 /* We still need to wrap TRY/CATCH in C++ so that cleanups and C++
    exceptions can coexist.
 
@@ -263,15 +230,6 @@ struct exception_try_scope
       }						\
   }
 
-#else
-
-#define TRY try
-#define CATCH(EXCEPTION, MASK) \
-  catch (struct gdb_exception ## _ ## MASK &EXCEPTION)
-#define END_CATCH
-
-#endif
-
 /* The exception types client code may catch.  They're just shims
    around gdb_exception that add nothing but type info.  Which is used
    is selected depending on the MASK argument passed to CATCH.  */
@@ -288,8 +246,6 @@ struct gdb_exception_RETURN_MASK_QUIT : public gdb_exception_RETURN_MASK_ALL
 {
 };
 
-#endif /* GDB_XCPT_TRY || GDB_XCPT_RAW_TRY */
-
 /* 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.17.2

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

* [PATCH v2 20/22] Replace throw_exception with throw in some cases
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
                   ` (14 preceding siblings ...)
  2019-02-27 20:19 ` [PATCH v2 11/22] Use unique_xmalloc_ptr in remote.c Tom Tromey
@ 2019-02-27 20:19 ` Tom Tromey
  2019-04-03 17:05   ` Pedro Alves
  2019-02-27 20:19 ` [PATCH v2 14/22] Simplify exception handling Tom Tromey
                   ` (5 subsequent siblings)
  21 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This replaces throw_exception with "throw;" when possible.  This was
written by script.  The rule that is followed is that uses of the
form:

   catch (... &name)
     {
       ...
       throw_exception (name);
     }

... can be rewritten.  It's possible (though IMO unlikely) that such a
case could be wrong, if the exception object is rewritten in the body
of the catch.  (One option here might be to catch a const & instead.)

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* valops.c (value_rtti_indirect_type): Replace throw_exception
	with throw.
	* tracefile-tfile.c (tfile_target_open): Replace throw_exception
	with throw.
	* thread.c (thr_try_catch_cmd): Replace throw_exception with
	throw.
	* target.c (target_translate_tls_address): Replace throw_exception
	with throw.
	* stack.c (frame_apply_command_count): Replace throw_exception
	with throw.
	* solib-spu.c (append_ocl_sos): Replace throw_exception with
	throw.
	* s390-tdep.c (s390_frame_unwind_cache): Replace throw_exception
	with throw.
	* rs6000-tdep.c (rs6000_frame_cache)
	(rs6000_epilogue_frame_cache): Replace throw_exception with throw.
	* remote.c: Replace throw_exception with throw.
	* record-full.c (record_full_message, record_full_wait_1)
	(record_full_restore): Replace throw_exception with throw.
	* record-btrace.c:
	(get_thread_current_frame_id, record_btrace_start_replaying)
	(cmd_record_btrace_bts_start, cmd_record_btrace_pt_start)
	(cmd_record_btrace_start): Replace throw_exception with throw.
	* parse.c (parse_exp_in_context_1): Replace throw_exception with
	throw.
	* linux-nat.c (detach_one_lwp, linux_resume_one_lwp)
	(resume_stopped_resumed_lwps): Replace throw_exception with throw.
	* linespec.c:
	(find_linespec_symbols): Replace throw_exception with throw.
	* infrun.c (displaced_step_prepare, resume): Replace
	throw_exception with throw.
	* infcmd.c (post_create_inferior): Replace throw_exception with
	throw.
	* inf-loop.c (inferior_event_handler): Replace throw_exception
	with throw.
	* i386-tdep.c (i386_frame_cache, i386_epilogue_frame_cache)
	(i386_sigtramp_frame_cache): Replace throw_exception with throw.
	* frame.c (frame_unwind_pc, get_prev_frame_if_no_cycle)
	(get_prev_frame_always, get_frame_pc_if_available)
	(get_frame_address_in_block_if_available, get_frame_language):
	Replace throw_exception with throw.
	* frame-unwind.c (frame_unwind_try_unwinder): Replace
	throw_exception with throw.
	* eval.c (fetch_subexp_value, evaluate_var_value)
	(evaluate_funcall, evaluate_subexp_standard): Replace
	throw_exception with throw.
	* dwarf2loc.c (call_site_find_chain)
	(dwarf2_evaluate_loc_desc_full, dwarf2_locexpr_baton_eval):
	Replace throw_exception with throw.
	* dwarf2-frame.c (dwarf2_frame_cache): Replace throw_exception
	with throw.
	* darwin-nat.c (darwin_attach_pid): Replace throw_exception with
	throw.
	* cp-abi.c (baseclass_offset): Replace throw_exception with throw.
	* completer.c (complete_line_internal): Replace throw_exception
	with throw.
	* compile/compile-object-run.c (compile_object_run): Replace
	throw_exception with throw.
	* cli/cli-script.c (process_next_line): Replace throw_exception
	with throw.
	* btrace.c (btrace_compute_ftrace_pt, btrace_compute_ftrace)
	(btrace_enable, btrace_maint_update_pt_packets): Replace
	throw_exception with throw.
	* breakpoint.c (create_breakpoint, save_breakpoints): Replace
	throw_exception with throw.
	* break-catch-throw.c (re_set_exception_catchpoint): Replace
	throw_exception with throw.
	* amd64-tdep.c (amd64_frame_cache, amd64_sigtramp_frame_cache)
	(amd64_epilogue_frame_cache): Replace throw_exception with throw.
	* aarch64-tdep.c (aarch64_make_prologue_cache)
	(aarch64_make_stub_cache): Replace throw_exception with throw.

gdb/gdbserver/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* linux-low.c (linux_detach_one_lwp): Replace throw_exception with
	throw.
	(linux_resume_one_lwp): Likewise.
---
 gdb/ChangeLog                    | 74 ++++++++++++++++++++++++++++++++
 gdb/aarch64-tdep.c               |  4 +-
 gdb/amd64-tdep.c                 |  6 +--
 gdb/break-catch-throw.c          |  2 +-
 gdb/breakpoint.c                 |  8 ++--
 gdb/btrace.c                     |  8 ++--
 gdb/cli/cli-script.c             |  2 +-
 gdb/compile/compile-object-run.c |  2 +-
 gdb/completer.c                  |  2 +-
 gdb/cp-abi.c                     |  2 +-
 gdb/darwin-nat.c                 |  2 +-
 gdb/dwarf2-frame.c               |  2 +-
 gdb/dwarf2loc.c                  |  6 +--
 gdb/eval.c                       |  8 ++--
 gdb/frame-unwind.c               |  2 +-
 gdb/frame.c                      | 12 +++---
 gdb/gdbserver/ChangeLog          |  6 +++
 gdb/gdbserver/linux-low.c        |  4 +-
 gdb/i386-tdep.c                  |  6 +--
 gdb/inf-loop.c                   |  2 +-
 gdb/infcmd.c                     |  2 +-
 gdb/infrun.c                     |  4 +-
 gdb/linespec.c                   |  4 +-
 gdb/linux-nat.c                  |  6 +--
 gdb/parse.c                      |  2 +-
 gdb/record-btrace.c              | 14 +++---
 gdb/record-full.c                |  6 +--
 gdb/remote.c                     |  6 +--
 gdb/rs6000-tdep.c                |  4 +-
 gdb/s390-tdep.c                  |  2 +-
 gdb/solib-spu.c                  |  2 +-
 gdb/stack.c                      |  2 +-
 gdb/target.c                     |  2 +-
 gdb/thread.c                     |  2 +-
 gdb/tracefile-tfile.c            |  2 +-
 gdb/valops.c                     |  2 +-
 36 files changed, 151 insertions(+), 71 deletions(-)

diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index bee1e7ed93b..bd7252d5566 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -783,7 +783,7 @@ aarch64_make_prologue_cache (struct frame_info *this_frame, void **this_cache)
   catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
-	throw_exception (ex);
+	throw;
     }
 
   return cache;
@@ -909,7 +909,7 @@ aarch64_make_stub_cache (struct frame_info *this_frame, void **this_cache)
   catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
-	throw_exception (ex);
+	throw;
     }
 
   return cache;
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index cff1d2419b8..1101d30d39c 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -2588,7 +2588,7 @@ amd64_frame_cache (struct frame_info *this_frame, void **this_cache)
   catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
-	throw_exception (ex);
+	throw;
     }
 
   return cache;
@@ -2715,7 +2715,7 @@ amd64_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
   catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
-	throw_exception (ex);
+	throw;
     }
 
   *this_cache = cache;
@@ -2895,7 +2895,7 @@ amd64_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
   catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
-	throw_exception (ex);
+	throw;
     }
 
   return cache;
diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c
index ca1d7c71bd7..a1d67afffe3 100644
--- a/gdb/break-catch-throw.c
+++ b/gdb/break-catch-throw.c
@@ -214,7 +214,7 @@ re_set_exception_catchpoint (struct breakpoint *self)
 	  /* NOT_FOUND_ERROR just means the breakpoint will be
 	     pending, so let it through.  */
 	  if (ex.error != NOT_FOUND_ERROR)
-	    throw_exception (ex);
+	    throw;
 	}
     }
 
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 35dbc867f7a..2013064e96c 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -9243,7 +9243,7 @@ create_breakpoint (struct gdbarch *gdbarch,
 	     error.  */
 
 	  if (pending_break_support == AUTO_BOOLEAN_FALSE)
-	    throw_exception (e);
+	    throw;
 
 	  exception_print (gdb_stderr, e);
 
@@ -9261,7 +9261,7 @@ create_breakpoint (struct gdbarch *gdbarch,
 	  pending = 1;
 	}
       else
-	throw_exception (e);
+	throw;
     }
 
   if (!pending && canonical.lsals.empty ())
@@ -13625,7 +13625,7 @@ location_to_sals (struct breakpoint *b, struct event_location *location,
 	     happens only when a binary has changed, I don't know
 	     which approach is better.  */
 	  b->enable_state = bp_disabled;
-	  throw_exception (e);
+	  throw;
 	}
     }
 
@@ -15024,7 +15024,7 @@ save_breakpoints (const char *filename, int from_tty,
 	catch (const struct gdb_exception &ex)
 	  {
 	  current_uiout->redirect (NULL);
-	    throw_exception (ex);
+	    throw;
 	  }
 
 	current_uiout->redirect (NULL);
diff --git a/gdb/btrace.c b/gdb/btrace.c
index 26a6ede4dd5..3c4d3501902 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -1484,7 +1484,7 @@ btrace_compute_ftrace_pt (struct thread_info *tp,
 
       btrace_finalize_ftrace_pt (decoder, tp, level);
 
-      throw_exception (error);
+      throw;
     }
 
   btrace_finalize_ftrace_pt (decoder, tp, level);
@@ -1560,7 +1560,7 @@ btrace_compute_ftrace (struct thread_info *tp, struct btrace_data *btrace,
     {
       btrace_finalize_ftrace (tp, gaps);
 
-      throw_exception (error);
+      throw;
     }
 
   btrace_finalize_ftrace (tp, gaps);
@@ -1631,7 +1631,7 @@ btrace_enable (struct thread_info *tp, const struct btrace_config *conf)
     {
       btrace_disable (tp);
 
-      throw_exception (exception);
+      throw;
     }
 }
 
@@ -3065,7 +3065,7 @@ btrace_maint_update_pt_packets (struct btrace_thread_info *btinfo)
       pt_pkt_free_decoder (decoder);
 
       if (except.reason < 0)
-	throw_exception (except);
+	throw;
     }
 
   pt_pkt_free_decoder (decoder);
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 3730827d9b4..600ed84f078 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -1057,7 +1057,7 @@ process_next_line (const char *p, struct command_line **command,
       catch (const struct gdb_exception &ex)
 	{
 	  free_command_lines (command);
-	  throw_exception (ex);
+	  throw;
 	}
     }
 
diff --git a/gdb/compile/compile-object-run.c b/gdb/compile/compile-object-run.c
index ea24eee73b8..6462d286f88 100644
--- a/gdb/compile/compile-object-run.c
+++ b/gdb/compile/compile-object-run.c
@@ -183,7 +183,7 @@ compile_object_run (struct compile_module *module)
       gdb_assert (!(dtor_found && executed));
       if (!dtor_found && !executed)
 	do_module_cleanup (data, 0);
-      throw_exception (ex);
+      throw;
     }
 
   dtor_found = find_dummy_frame_dtor (do_module_cleanup, data);
diff --git a/gdb/completer.c b/gdb/completer.c
index 748198500c1..c2ae2aac6ed 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -1451,7 +1451,7 @@ complete_line_internal (completion_tracker &tracker,
   catch (const struct gdb_exception_error &except)
     {
       if (except.error != MAX_COMPLETIONS_REACHED_ERROR)
-	throw_exception (except);
+	throw;
     }
 }
 
diff --git a/gdb/cp-abi.c b/gdb/cp-abi.c
index 23dad4b1748..8a9a284ab6c 100644
--- a/gdb/cp-abi.c
+++ b/gdb/cp-abi.c
@@ -82,7 +82,7 @@ baseclass_offset (struct type *type, int index, const gdb_byte *valaddr,
   catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
-	throw_exception (ex);
+	throw;
 
       throw_error (NOT_AVAILABLE_ERROR,
 		   _("Cannot determine virtual baseclass offset "
diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c
index 1d4c267e074..4f1bac1b45f 100644
--- a/gdb/darwin-nat.c
+++ b/gdb/darwin-nat.c
@@ -1693,7 +1693,7 @@ darwin_attach_pid (struct inferior *inf)
       exit_inferior (inf);
       inferior_ptid = null_ptid;
 
-      throw_exception (ex);
+      throw;
     }
 
   target_ops *darwin_ops = get_native_target ();
diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c
index 5067b94f834..c96594c7c0c 100644
--- a/gdb/dwarf2-frame.c
+++ b/gdb/dwarf2-frame.c
@@ -1076,7 +1076,7 @@ dwarf2_frame_cache (struct frame_info *this_frame, void **this_cache)
 	  return cache;
 	}
 
-      throw_exception (ex);
+      throw;
     }
 
   /* Initialize the register state.  */
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index 263d9c55e37..4251ee13d66 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -1209,7 +1209,7 @@ call_site_find_chain (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
 	  return NULL;
 	}
       else
-	throw_exception (e);
+	throw;
     }
 
   return retval;
@@ -2186,7 +2186,7 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
 	  return allocate_optimized_out_value (subobj_type);
 	}
       else
-	throw_exception (ex);
+	throw;
     }
 
   if (ctx.pieces.size () > 0)
@@ -2398,7 +2398,7 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
 	  return 0;
 	}
       else
-	throw_exception (ex);
+	throw;
     }
 
   switch (ctx.location)
diff --git a/gdb/eval.c b/gdb/eval.c
index f46222d920a..a337d9dd4b2 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -217,7 +217,7 @@ fetch_subexp_value (struct expression *exp, int *pc, struct value **valp,
 	    break;
 	  /* Fall through.  */
 	default:
-	  throw_exception (ex);
+	  throw;
 	  break;
 	}
     }
@@ -722,7 +722,7 @@ evaluate_var_value (enum noside noside, const block *blk, symbol *var)
   catch (const struct gdb_exception_error &except)
     {
       if (noside != EVAL_AVOID_SIDE_EFFECTS)
-	throw_exception (except);
+	throw;
 
       ret = value_zero (SYMBOL_TYPE (var), not_lval);
     }
@@ -964,7 +964,7 @@ evaluate_funcall (type *expect_type, expression *exp, int *pos,
 		  if (except.error == NOT_FOUND_ERROR)
 		    break;
 		  else
-		    throw_exception (except);
+		    throw;
 		}
 
 		arg2 = value;
@@ -2036,7 +2036,7 @@ evaluate_subexp_standard (struct type *expect_type,
 	      if (except.error == NOT_FOUND_ERROR)
 		break;
 	      else
-		throw_exception (except);
+		throw;
 	    }
 
 	  arg1 = value;
diff --git a/gdb/frame-unwind.c b/gdb/frame-unwind.c
index 714e44475ac..de559d02991 100644
--- a/gdb/frame-unwind.c
+++ b/gdb/frame-unwind.c
@@ -120,7 +120,7 @@ frame_unwind_try_unwinder (struct frame_info *this_frame, void **this_cache,
 	     should always accept the frame.  */
 	  return 0;
 	}
-      throw_exception (ex);
+      throw;
     }
 
   if (res)
diff --git a/gdb/frame.c b/gdb/frame.c
index 8665817658e..3a2f55b9ccb 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -922,7 +922,7 @@ frame_unwind_pc (struct frame_info *this_frame)
 				    this_frame->level);
 	    }
 	  else
-	    throw_exception (ex);
+	    throw;
 	}
 
       if (pc_p)
@@ -1918,7 +1918,7 @@ get_prev_frame_if_no_cycle (struct frame_info *this_frame)
       prev_frame->next = NULL;
       this_frame->prev = NULL;
 
-      throw_exception (ex);
+      throw;
     }
 
   return prev_frame;
@@ -2116,7 +2116,7 @@ get_prev_frame_always (struct frame_info *this_frame)
 	  prev_frame = NULL;
 	}
       else
-	throw_exception (ex);
+	throw;
     }
 
   return prev_frame;
@@ -2385,7 +2385,7 @@ get_frame_pc_if_available (struct frame_info *frame, CORE_ADDR *pc)
       if (ex.error == NOT_AVAILABLE_ERROR)
 	return 0;
       else
-	throw_exception (ex);
+	throw;
     }
 
   return 1;
@@ -2466,7 +2466,7 @@ get_frame_address_in_block_if_available (struct frame_info *this_frame,
     {
       if (ex.error == NOT_AVAILABLE_ERROR)
 	return 0;
-      throw_exception (ex);
+      throw;
     }
 
   return 1;
@@ -2750,7 +2750,7 @@ get_frame_language (struct frame_info *frame)
   catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
-	throw_exception (ex);
+	throw;
     }
 
   if (pc_p)
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 71eb5145ec0..62a67b60d77 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -1539,7 +1539,7 @@ linux_detach_one_lwp (struct lwp_info *lwp)
   catch (const struct gdb_exception_error &ex)
     {
       if (!check_ptrace_stopped_lwp_gone (lwp))
-	throw_exception (ex);
+	throw;
     }
 
   lwpid = lwpid_of (thread);
@@ -4511,7 +4511,7 @@ linux_resume_one_lwp (struct lwp_info *lwp,
   catch (const struct gdb_exception_error &ex)
     {
       if (!check_ptrace_stopped_lwp_gone (lwp))
-	throw_exception (ex);
+	throw;
     }
 }
 
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 35ad62b4d3b..d57d14e58f1 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -2089,7 +2089,7 @@ i386_frame_cache (struct frame_info *this_frame, void **this_cache)
   catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
-	throw_exception (ex);
+	throw;
     }
 
   return cache;
@@ -2268,7 +2268,7 @@ i386_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
   catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
-	throw_exception (ex);
+	throw;
     }
 
   return cache;
@@ -2463,7 +2463,7 @@ i386_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
   catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
-	throw_exception (ex);
+	throw;
     }
 
   *this_cache = cache;
diff --git a/gdb/inf-loop.c b/gdb/inf-loop.c
index 4cd179abfcf..d07c8f31295 100644
--- a/gdb/inf-loop.c
+++ b/gdb/inf-loop.c
@@ -79,7 +79,7 @@ inferior_event_handler (enum inferior_event_type event_type,
 		 the prompt and is typing some unrelated command, so
 		 just inform the user and swallow the exception.  */
 	      if (current_ui->prompt_state == PROMPT_BLOCKED)
-		throw_exception (e);
+		throw;
 	      else
 		exception_print (gdb_stderr, e);
 	    }
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 024c5b832da..f943452ce82 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -454,7 +454,7 @@ post_create_inferior (struct target_ops *target, int from_tty)
   catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
-	throw_exception (ex);
+	throw;
     }
 
   if (exec_bfd)
diff --git a/gdb/infrun.c b/gdb/infrun.c
index ed245133e9f..011c6525449 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -1784,7 +1784,7 @@ displaced_step_prepare (thread_info *thread)
 
       if (ex.error != MEMORY_ERROR
 	  && ex.error != NOT_SUPPORTED_ERROR)
-	throw_exception (ex);
+	throw;
 
       if (debug_infrun)
 	{
@@ -2620,7 +2620,7 @@ resume (gdb_signal sig)
 	 we're running in non-stop mode.  */
       if (inferior_ptid != null_ptid)
 	delete_single_step_breakpoints (inferior_thread ());
-      throw_exception (ex);
+      throw;
     }
 }
 
diff --git a/gdb/linespec.c b/gdb/linespec.c
index dcf0b5ea4ec..b9c14ec53ad 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -3158,7 +3158,7 @@ event_location_to_sals (linespec_parser *parser,
 	  }
 	catch (const struct gdb_exception_error &except)
 	  {
-	    throw_exception (except);
+	    throw;
 	  }
       }
       break;
@@ -3972,7 +3972,7 @@ find_linespec_symbols (struct linespec_state *state,
 	  catch (const struct gdb_exception_error &except)
 	    {
 	      if (except.error != NOT_FOUND_ERROR)
-		throw_exception (except);
+		throw;
 	    }
 	}
     }
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 72cad8880e6..45435b6113e 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -1409,7 +1409,7 @@ detach_one_lwp (struct lwp_info *lp, int *signo_p)
   catch (const struct gdb_exception_error &ex)
     {
       if (!check_ptrace_stopped_lwp_gone (lp))
-	throw_exception (ex);
+	throw;
     }
 
   if (ptrace (PTRACE_DETACH, lwpid, 0, signo) < 0)
@@ -1590,7 +1590,7 @@ linux_resume_one_lwp (struct lwp_info *lp, int step, enum gdb_signal signo)
   catch (const struct gdb_exception_error &ex)
     {
       if (!check_ptrace_stopped_lwp_gone (lp))
-	throw_exception (ex);
+	throw;
     }
 }
 
@@ -3542,7 +3542,7 @@ resume_stopped_resumed_lwps (struct lwp_info *lp, void *data)
       catch (const struct gdb_exception_error &ex)
 	{
 	  if (!check_ptrace_stopped_lwp_gone (lp))
-	    throw_exception (ex);
+	    throw;
 	}
     }
 
diff --git a/gdb/parse.c b/gdb/parse.c
index 627ae580105..4531fbaf4b3 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -1210,7 +1210,7 @@ parse_exp_in_context_1 (const char **stringptr, CORE_ADDR pc,
 	 expression elements have been written, then there's nothing
 	 to do, so fail.  */
       if (! parse_completion || ps.expout_ptr == 0)
-	throw_exception (except);
+	throw;
     }
 
   /* We have to operate on an "expression *", due to la_post_parser,
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index ec45cb4aada..c505a2bf1ef 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -1484,7 +1484,7 @@ record_btrace_target::insert_breakpoint (struct gdbarch *gdbarch,
   catch (const struct gdb_exception &except)
     {
       replay_memory_access = old;
-      throw_exception (except);
+      throw;
     }
   replay_memory_access = old;
 
@@ -1514,7 +1514,7 @@ record_btrace_target::remove_breakpoint (struct gdbarch *gdbarch,
   catch (const struct gdb_exception &except)
     {
       replay_memory_access = old;
-      throw_exception (except);
+      throw;
     }
   replay_memory_access = old;
 
@@ -1992,7 +1992,7 @@ get_thread_current_frame_id (struct thread_info *tp)
       /* Restore the previous execution state.  */
       set_executing (inferior_ptid, executing);
 
-      throw_exception (except);
+      throw;
     }
 
   /* Restore the previous execution state.  */
@@ -2073,7 +2073,7 @@ record_btrace_start_replaying (struct thread_info *tp)
 
       registers_changed_thread (tp);
 
-      throw_exception (except);
+      throw;
     }
 
   return replay;
@@ -2894,7 +2894,7 @@ cmd_record_btrace_bts_start (const char *args, int from_tty)
   catch (const struct gdb_exception &exception)
     {
       record_btrace_conf.format = BTRACE_FORMAT_NONE;
-      throw_exception (exception);
+      throw;
     }
 }
 
@@ -2915,7 +2915,7 @@ cmd_record_btrace_pt_start (const char *args, int from_tty)
   catch (const struct gdb_exception &exception)
     {
       record_btrace_conf.format = BTRACE_FORMAT_NONE;
-      throw_exception (exception);
+      throw;
     }
 }
 
@@ -2944,7 +2944,7 @@ cmd_record_btrace_start (const char *args, int from_tty)
       catch (const struct gdb_exception &ex)
 	{
 	  record_btrace_conf.format = BTRACE_FORMAT_NONE;
-	  throw_exception (ex);
+	  throw;
 	}
     }
 }
diff --git a/gdb/record-full.c b/gdb/record-full.c
index 6b68e51ded5..4d0535bccbc 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -764,7 +764,7 @@ record_full_message (struct regcache *regcache, enum gdb_signal signal)
   catch (const struct gdb_exception &ex)
     {
       record_full_list_release (record_full_arch_list_tail);
-      throw_exception (ex);
+      throw;
     }
 
   record_full_list->next = record_full_arch_list_head;
@@ -1444,7 +1444,7 @@ record_full_wait_1 (struct target_ops *ops,
 	  else
 	    record_full_list = record_full_list->prev;
 
-	  throw_exception (ex);
+	  throw;
 	}
     }
 
@@ -2476,7 +2476,7 @@ record_full_restore (void)
   catch (const struct gdb_exception &ex)
     {
       record_full_list_release (record_full_arch_list_tail);
-      throw_exception (ex);
+      throw;
     }
 
   /* Add record_full_arch_list_head to the end of record list.  */
diff --git a/gdb/remote.c b/gdb/remote.c
index c4d384f9bb7..c9402bebde1 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -5609,7 +5609,7 @@ remote_target::open_1 (const char *name, int from_tty, int extended_p)
 	   already before throwing the exception.  */
 	if (ex.error != TARGET_CLOSE_ERROR)
 	  remote_unpush_target ();
-	throw_exception (ex);
+	throw;
       }
   }
 
@@ -9784,7 +9784,7 @@ remote_target::remote_kill_k ()
       /* Otherwise, something went wrong.  We didn't actually kill
 	 the target.  Just propagate the exception, and let the
 	 user or higher layers decide what to do.  */
-      throw_exception (ex);
+      throw;
     }
 }
 
@@ -13150,7 +13150,7 @@ remote_target::get_trace_status (struct trace_status *ts)
 	  exception_fprintf (gdb_stderr, ex, "qTStatus: ");
 	  return -1;
 	}
-      throw_exception (ex);
+      throw;
     }
 
   result = packet_ok (p, &remote_protocol_packets[PACKET_qTStatus]);
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index 5fc841d630b..d0c54ba475c 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -3471,7 +3471,7 @@ rs6000_frame_cache (struct frame_info *this_frame, void **this_cache)
   catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
-	throw_exception (ex);
+	throw;
       return (struct rs6000_frame_cache *) (*this_cache);
     }
 
@@ -3700,7 +3700,7 @@ rs6000_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
   catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
-	throw_exception (ex);
+	throw;
     }
 
   return cache;
diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
index 2bef8293d96..9e0a3647e0c 100644
--- a/gdb/s390-tdep.c
+++ b/gdb/s390-tdep.c
@@ -2557,7 +2557,7 @@ s390_frame_unwind_cache (struct frame_info *this_frame,
   catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
-	throw_exception (ex);
+	throw;
     }
 
   return info;
diff --git a/gdb/solib-spu.c b/gdb/solib-spu.c
index 31b66fa52d5..efbd9177292 100644
--- a/gdb/solib-spu.c
+++ b/gdb/solib-spu.c
@@ -141,7 +141,7 @@ append_ocl_sos (struct so_list **link_ptr)
 		case MEMORY_ERROR:
 		  break;
 		default:
-		  throw_exception (ex);
+		  throw;
 		  break;
 		}
 	    }
diff --git a/gdb/stack.c b/gdb/stack.c
index 0f8f4369043..b08fba759d9 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -2717,7 +2717,7 @@ frame_apply_command_count (const char *which_command,
 	      if (flags.cont)
 		printf_filtered ("%s\n", ex.message.c_str ());
 	      else
-		throw_exception (ex);
+		throw;
 	    }
 	}
     }
diff --git a/gdb/target.c b/gdb/target.c
index 605383eeee8..ca25de0656d 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -762,7 +762,7 @@ target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset)
 		       objfile_name (objfile), ex.message.c_str ());
 	      break;
 	    default:
-	      throw_exception (ex);
+	      throw;
 	      break;
 	    }
 	}
diff --git a/gdb/thread.c b/gdb/thread.c
index 2b84facbc27..b483e996e40 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -1481,7 +1481,7 @@ thr_try_catch_cmd (thread_info *thr, const char *cmd, int from_tty,
 	  if (flags.cont)
 	    printf_filtered ("%s\n", ex.message.c_str ());
 	  else
-	    throw_exception (ex);
+	    throw;
 	}
     }
 }
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index 95cd831a30d..c9e1f24df14 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -551,7 +551,7 @@ tfile_target_open (const char *arg, int from_tty)
     {
       /* Remove the partially set up target.  */
       unpush_target (&tfile_ops);
-      throw_exception (ex);
+      throw;
     }
 
   inferior_appeared (current_inferior (), TFILE_PID);
diff --git a/gdb/valops.c b/gdb/valops.c
index d5efbc6abbb..0fc247e2b72 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3634,7 +3634,7 @@ value_rtti_indirect_type (struct value *v, int *full,
 	         type.  */
 	      return NULL;
 	    }
-	  throw_exception (except);
+	  throw;
 	}
     }
   else
-- 
2.17.2

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

* [PATCH v2 17/22] Rename gdb exception types
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
                   ` (12 preceding siblings ...)
  2019-02-27 20:19 ` [PATCH v2 15/22] Make exceptions use std::string and be self-managing Tom Tromey
@ 2019-02-27 20:19 ` Tom Tromey
  2019-02-27 20:19 ` [PATCH v2 11/22] Use unique_xmalloc_ptr in remote.c Tom Tromey
                   ` (7 subsequent siblings)
  21 siblings, 0 replies; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This renames the gdb exception types.  The old types were only needed
due to the macros in common-exception.h that are now gone.

The intermediate layer of gdb_exception_RETURN_MASK_ALL did not seem
needed, so this patch removes it entirely.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* aarch64-tdep.c: Update.
	* ada-lang.c: Update.
	* ada-typeprint.c: Update.
	* ada-valprint.c: Update.
	* amd64-tdep.c: Update.
	* arch-utils.c: Update.
	* break-catch-throw.c: Update.
	* breakpoint.c: Update.
	* btrace.c: Update.
	* c-varobj.c: Update.
	* cli/cli-cmds.c: Update.
	* cli/cli-interp.c: Update.
	* cli/cli-script.c: Update.
	* common/common-exceptions.c: Update.
	* common/common-exceptions.h (gdb_exception_RETURN_MASK_ALL):
	Remove.
	(gdb_exception_error): Rename from
	gdb_exception_RETURN_MASK_ERROR.
	(gdb_exception_quit): Rename from gdb_exception_RETURN_MASK_QUIT.
	(gdb_quit_bad_alloc): Update.
	* common/new-op.c: Update.
	* common/selftest.c: Update.
	* compile/compile-c-symbols.c: Update.
	* compile/compile-cplus-symbols.c: Update.
	* compile/compile-object-load.c: Update.
	* compile/compile-object-run.c: Update.
	* completer.c: Update.
	* corelow.c: Update.
	* cp-abi.c: Update.
	* cp-support.c: Update.
	* cp-valprint.c: Update.
	* darwin-nat.c: Update.
	* disasm-selftests.c: Update.
	* dtrace-probe.c: Update.
	* dwarf-index-cache.c: Update.
	* dwarf-index-write.c: Update.
	* dwarf2-frame-tailcall.c: Update.
	* dwarf2-frame.c: Update.
	* dwarf2loc.c: Update.
	* dwarf2read.c: Update.
	* eval.c: Update.
	* event-loop.c: Update.
	* event-top.c: Update.
	* exec.c: Update.
	* f-valprint.c: Update.
	* fbsd-tdep.c: Update.
	* frame-unwind.c: Update.
	* frame.c: Update.
	* gcore.c: Update.
	* gdbtypes.c: Update.
	* gnu-v3-abi.c: Update.
	* guile/guile-internal.h: Update.
	* guile/scm-block.c: Update.
	* guile/scm-breakpoint.c: Update.
	* guile/scm-cmd.c: Update.
	* guile/scm-disasm.c: Update.
	* guile/scm-frame.c: Update.
	* guile/scm-lazy-string.c: Update.
	* guile/scm-math.c: Update.
	* guile/scm-param.c: Update.
	* guile/scm-ports.c: Update.
	* guile/scm-pretty-print.c: Update.
	* guile/scm-symbol.c: Update.
	* guile/scm-symtab.c: Update.
	* guile/scm-type.c: Update.
	* guile/scm-value.c: Update.
	* i386-linux-tdep.c: Update.
	* i386-tdep.c: Update.
	* inf-loop.c: Update.
	* infcall.c: Update.
	* infcmd.c: Update.
	* infrun.c: Update.
	* jit.c: Update.
	* language.c: Update.
	* linespec.c: Update.
	* linux-fork.c: Update.
	* linux-nat.c: Update.
	* linux-tdep.c: Update.
	* linux-thread-db.c: Update.
	* main.c: Update.
	* mi/mi-cmd-break.c: Update.
	* mi/mi-cmd-stack.c: Update.
	* mi/mi-interp.c: Update.
	* mi/mi-main.c: Update.
	* objc-lang.c: Update.
	* p-valprint.c: Update.
	* parse.c: Update.
	* ppc-linux-tdep.c: Update.
	* printcmd.c: Update.
	* python/py-arch.c: Update.
	* python/py-breakpoint.c: Update.
	* python/py-cmd.c: Update.
	* python/py-finishbreakpoint.c: Update.
	* python/py-frame.c: Update.
	* python/py-framefilter.c: Update.
	* python/py-gdb-readline.c: Update.
	* python/py-inferior.c: Update.
	* python/py-infthread.c: Update.
	* python/py-lazy-string.c: Update.
	* python/py-linetable.c: Update.
	* python/py-objfile.c: Update.
	* python/py-param.c: Update.
	* python/py-prettyprint.c: Update.
	* python/py-progspace.c: Update.
	* python/py-record-btrace.c: Update.
	* python/py-record.c: Update.
	* python/py-symbol.c: Update.
	* python/py-type.c: Update.
	* python/py-unwind.c: Update.
	* python/py-utils.c: Update.
	* python/py-value.c: Update.
	* python/python.c: Update.
	* record-btrace.c: Update.
	* record-full.c: Update.
	* remote-fileio.c: Update.
	* remote.c: Update.
	* riscv-tdep.c: Update.
	* rs6000-aix-tdep.c: Update.
	* rs6000-tdep.c: Update.
	* rust-exp.y: Update.
	* rust-lang.c: Update.
	* s390-tdep.c: Update.
	* selftest-arch.c: Update.
	* solib-dsbt.c: Update.
	* solib-frv.c: Update.
	* solib-spu.c: Update.
	* solib-svr4.c: Update.
	* solib.c: Update.
	* sparc64-linux-tdep.c: Update.
	* stack.c: Update.
	* symfile-mem.c: Update.
	* symmisc.c: Update.
	* target.c: Update.
	* thread.c: Update.
	* top.c: Update.
	* tracefile-tfile.c: Update.
	* tui/tui.c: Update.
	* typeprint.c: Update.
	* unittests/cli-utils-selftests.c: Update.
	* unittests/parse-connection-spec-selftests.c: Update.
	* valops.c: Update.
	* valprint.c: Update.
	* value.c: Update.
	* varobj.c: Update.
	* windows-nat.c: Update.
	* x86-linux-nat.c: Update.
	* xml-support.c: Update.

gdb/gdbserver/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* gdbreplay.c: Update.
	* linux-low.c: Update.
	* server.c: Update.
---
 gdb/ChangeLog                                 | 150 ++++++++++++++++++
 gdb/aarch64-tdep.c                            |   4 +-
 gdb/ada-lang.c                                |  14 +-
 gdb/ada-typeprint.c                           |   2 +-
 gdb/ada-valprint.c                            |   2 +-
 gdb/amd64-tdep.c                              |   6 +-
 gdb/arch-utils.c                              |   2 +-
 gdb/break-catch-throw.c                       |   6 +-
 gdb/breakpoint.c                              |  28 ++--
 gdb/btrace.c                                  |  14 +-
 gdb/c-varobj.c                                |   8 +-
 gdb/cli/cli-cmds.c                            |   2 +-
 gdb/cli/cli-interp.c                          |   2 +-
 gdb/cli/cli-script.c                          |   4 +-
 gdb/common/common-exceptions.c                |   4 +-
 gdb/common/common-exceptions.h                |  10 +-
 gdb/common/new-op.c                           |   2 +-
 gdb/common/selftest.c                         |   2 +-
 gdb/compile/compile-c-symbols.c               |   6 +-
 gdb/compile/compile-cplus-symbols.c           |   4 +-
 gdb/compile/compile-object-load.c             |   2 +-
 gdb/compile/compile-object-run.c              |   2 +-
 gdb/completer.c                               |   8 +-
 gdb/corelow.c                                 |   4 +-
 gdb/cp-abi.c                                  |   4 +-
 gdb/cp-support.c                              |   6 +-
 gdb/cp-valprint.c                             |   4 +-
 gdb/darwin-nat.c                              |   4 +-
 gdb/disasm-selftests.c                        |   2 +-
 gdb/dtrace-probe.c                            |   2 +-
 gdb/dwarf-index-cache.c                       |   4 +-
 gdb/dwarf-index-write.c                       |   2 +-
 gdb/dwarf2-frame-tailcall.c                   |   2 +-
 gdb/dwarf2-frame.c                            |   6 +-
 gdb/dwarf2loc.c                               |   6 +-
 gdb/dwarf2read.c                              |   2 +-
 gdb/eval.c                                    |  10 +-
 gdb/event-loop.c                              |   2 +-
 gdb/event-top.c                               |   6 +-
 gdb/exec.c                                    |   4 +-
 gdb/f-valprint.c                              |   2 +-
 gdb/fbsd-tdep.c                               |   2 +-
 gdb/frame-unwind.c                            |   2 +-
 gdb/frame.c                                   |  12 +-
 gdb/gcore.c                                   |   2 +-
 gdb/gdbserver/ChangeLog                       |   6 +
 gdb/gdbserver/gdbreplay.c                     |   2 +-
 gdb/gdbserver/linux-low.c                     |   4 +-
 gdb/gdbserver/server.c                        |  12 +-
 gdb/gdbtypes.c                                |   4 +-
 gdb/gnu-v3-abi.c                              |   2 +-
 gdb/guile/guile-internal.h                    |   2 +-
 gdb/guile/scm-block.c                         |   2 +-
 gdb/guile/scm-breakpoint.c                    |  16 +-
 gdb/guile/scm-cmd.c                           |   2 +-
 gdb/guile/scm-disasm.c                        |   2 +-
 gdb/guile/scm-frame.c                         |  38 ++---
 gdb/guile/scm-lazy-string.c                   |   2 +-
 gdb/guile/scm-math.c                          |   2 +-
 gdb/guile/scm-param.c                         |   4 +-
 gdb/guile/scm-ports.c                         |   2 +-
 gdb/guile/scm-pretty-print.c                  |   2 +-
 gdb/guile/scm-symbol.c                        |  10 +-
 gdb/guile/scm-symtab.c                        |   2 +-
 gdb/guile/scm-type.c                          |  24 +--
 gdb/guile/scm-value.c                         |  30 ++--
 gdb/i386-linux-tdep.c                         |   2 +-
 gdb/i386-tdep.c                               |   6 +-
 gdb/inf-loop.c                                |   2 +-
 gdb/infcall.c                                 |   2 +-
 gdb/infcmd.c                                  |   4 +-
 gdb/infrun.c                                  |  14 +-
 gdb/jit.c                                     |   2 +-
 gdb/language.c                                |   2 +-
 gdb/linespec.c                                |  12 +-
 gdb/linux-fork.c                              |   2 +-
 gdb/linux-nat.c                               |   8 +-
 gdb/linux-tdep.c                              |   2 +-
 gdb/linux-thread-db.c                         |   6 +-
 gdb/main.c                                    |   6 +-
 gdb/mi/mi-cmd-break.c                         |   2 +-
 gdb/mi/mi-cmd-stack.c                         |   2 +-
 gdb/mi/mi-interp.c                            |   2 +-
 gdb/mi/mi-main.c                              |   4 +-
 gdb/objc-lang.c                               |   2 +-
 gdb/p-valprint.c                              |   2 +-
 gdb/parse.c                                   |   4 +-
 gdb/ppc-linux-tdep.c                          |   2 +-
 gdb/printcmd.c                                |   8 +-
 gdb/python/py-arch.c                          |   2 +-
 gdb/python/py-breakpoint.c                    |  16 +-
 gdb/python/py-cmd.c                           |   2 +-
 gdb/python/py-finishbreakpoint.c              |  12 +-
 gdb/python/py-frame.c                         |  36 ++---
 gdb/python/py-framefilter.c                   |   4 +-
 gdb/python/py-gdb-readline.c                  |   2 +-
 gdb/python/py-inferior.c                      |  10 +-
 gdb/python/py-infthread.c                     |   2 +-
 gdb/python/py-lazy-string.c                   |   2 +-
 gdb/python/py-linetable.c                     |   2 +-
 gdb/python/py-objfile.c                       |   4 +-
 gdb/python/py-param.c                         |   2 +-
 gdb/python/py-prettyprint.c                   |   4 +-
 gdb/python/py-progspace.c                     |   4 +-
 gdb/python/py-record-btrace.c                 |   8 +-
 gdb/python/py-record.c                        |   4 +-
 gdb/python/py-symbol.c                        |  10 +-
 gdb/python/py-type.c                          |  36 ++---
 gdb/python/py-unwind.c                        |   8 +-
 gdb/python/py-utils.c                         |   2 +-
 gdb/python/py-value.c                         |  60 +++----
 gdb/python/python.c                           |  14 +-
 gdb/record-btrace.c                           |  18 +--
 gdb/record-full.c                             |   8 +-
 gdb/remote-fileio.c                           |   2 +-
 gdb/remote.c                                  |  10 +-
 gdb/riscv-tdep.c                              |   4 +-
 gdb/rs6000-aix-tdep.c                         |   2 +-
 gdb/rs6000-tdep.c                             |   4 +-
 gdb/rust-exp.y                                |   2 +-
 gdb/rust-lang.c                               |   2 +-
 gdb/s390-tdep.c                               |   2 +-
 gdb/selftest-arch.c                           |   2 +-
 gdb/solib-dsbt.c                              |   2 +-
 gdb/solib-frv.c                               |   2 +-
 gdb/solib-spu.c                               |   2 +-
 gdb/solib-svr4.c                              |  12 +-
 gdb/solib.c                                   |   8 +-
 gdb/sparc64-linux-tdep.c                      |   2 +-
 gdb/stack.c                                   |  22 +--
 gdb/symfile-mem.c                             |   2 +-
 gdb/symmisc.c                                 |   2 +-
 gdb/target.c                                  |   2 +-
 gdb/thread.c                                  |   2 +-
 gdb/top.c                                     |   8 +-
 gdb/tracefile-tfile.c                         |   2 +-
 gdb/tui/tui.c                                 |   2 +-
 gdb/typeprint.c                               |   2 +-
 gdb/unittests/cli-utils-selftests.c           |   4 +-
 .../parse-connection-spec-selftests.c         |   2 +-
 gdb/valops.c                                  |   4 +-
 gdb/valprint.c                                |   2 +-
 gdb/value.c                                   |   4 +-
 gdb/varobj.c                                  |  12 +-
 gdb/windows-nat.c                             |   2 +-
 gdb/x86-linux-nat.c                           |   2 +-
 gdb/xml-support.c                             |   4 +-
 147 files changed, 602 insertions(+), 450 deletions(-)

diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index b4f1cf895a5..bee1e7ed93b 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -780,7 +780,7 @@ aarch64_make_prologue_cache (struct frame_info *this_frame, void **this_cache)
     {
       aarch64_make_prologue_cache_1 (this_frame, cache);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
@@ -906,7 +906,7 @@ aarch64_make_stub_cache (struct frame_info *this_frame, void **this_cache)
       cache->prev_pc = get_frame_pc (this_frame);
       cache->available_p = 1;
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 61fef64a488..17a11842634 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -6717,7 +6717,7 @@ ada_tag_value_at_base_address (struct value *obj)
       offset_to_top = value_as_long (value_ind (value_ptradd (val, -2)));
     }
 
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+  catch (const struct gdb_exception_error &e)
     {
       return obj;
     }
@@ -6864,7 +6864,7 @@ ada_tag_name (struct value *tag)
       if (tsd != NULL)
 	name = ada_tag_name_from_tsd (tsd);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+  catch (const struct gdb_exception_error &e)
     {
     }
 
@@ -9045,7 +9045,7 @@ ada_to_fixed_type_1 (struct type *type, const gdb_byte *valaddr,
 	      {
 		xvz_found = get_int_var_value (xvz_name, size);
 	      }
-	    catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+	    catch (const struct gdb_exception_error &except)
 	      {
 		/* We found the variable, but somehow failed to read
 		   its value.  Rethrow the same error, but with a little
@@ -12335,7 +12335,7 @@ ada_exception_message (void)
     {
       e_msg = ada_exception_message_1 ();
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+  catch (const struct gdb_exception_error &e)
     {
       e_msg.reset (nullptr);
     }
@@ -12359,7 +12359,7 @@ ada_exception_name_addr (enum ada_exception_catchpoint_kind ex,
       result = ada_exception_name_addr_1 (ex, b);
     }
 
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+  catch (const struct gdb_exception_error &e)
     {
       warning (_("failed to get exception name: %s"), e.message.c_str ());
       return 0;
@@ -12450,7 +12450,7 @@ create_excep_cond_exprs (struct ada_catchpoint *c,
 				 block_for_pc (bl->address),
 				 0);
 	    }
-	  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+	  catch (const struct gdb_exception_error &e)
 	    {
 	      warning (_("failed to reevaluate internal exception condition "
 			 "for catchpoint %d: %s"),
@@ -12521,7 +12521,7 @@ should_stop_exception (const struct bp_location *bl)
       stop = value_true (evaluate_expression (ada_loc->excep_cond_expr.get ()));
       value_free_to_mark (mark);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       exception_fprintf (gdb_stderr, ex,
 			 _("Error in testing exception condition:\n"));
diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c
index d3008cd2d96..2b50bc6b21c 100644
--- a/gdb/ada-typeprint.c
+++ b/gdb/ada-typeprint.c
@@ -168,7 +168,7 @@ print_range (struct type *type, struct ui_file *stream,
 	    lo = ada_discrete_type_low_bound (type);
 	    hi = ada_discrete_type_high_bound (type);
 	  }
-	catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+	catch (const struct gdb_exception_error &e)
 	  {
 	    /* This can happen when the range is dynamic.  Sometimes,
 	       resolving dynamic property values requires us to have
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index 57336ed6c3a..7a3ad46fa0a 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -1210,7 +1210,7 @@ ada_val_print (struct type *type,
 		       stream, recurse, val, options,
 		       current_language);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
       fprintf_filtered (stream, _("<error reading variable: %s>"),
 			except.message.c_str ());
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index eeb0a9dd73c..cff1d2419b8 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -2585,7 +2585,7 @@ amd64_frame_cache (struct frame_info *this_frame, void **this_cache)
     {
       amd64_frame_cache_1 (this_frame, cache);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
@@ -2712,7 +2712,7 @@ amd64_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 
       cache->base_p = 1;
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
@@ -2892,7 +2892,7 @@ amd64_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
 
       cache->base_p = 1;
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index 442ab89db81..e274d7820b7 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -973,7 +973,7 @@ gdbarch_skip_prologue_noexcept (gdbarch *gdbarch, CORE_ADDR pc) noexcept
     {
       new_pc = gdbarch_skip_prologue (gdbarch, pc);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {}
 
   return new_pc;
diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c
index b7c72f0a755..ca1d7c71bd7 100644
--- a/gdb/break-catch-throw.c
+++ b/gdb/break-catch-throw.c
@@ -166,7 +166,7 @@ check_status_exception_catchpoint (struct bpstats *bs)
       if (!canon.empty ())
 	std::swap (type_name, canon);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+  catch (const struct gdb_exception_error &e)
     {
       exception_print (gdb_stderr, e);
     }
@@ -194,7 +194,7 @@ re_set_exception_catchpoint (struct breakpoint *self)
 	= new_probe_location (exception_functions[kind].probe);
       sals = parse_probes (location.get (), filter_pspace, NULL);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+  catch (const struct gdb_exception_error &e)
     {
       /* Using the probe interface failed.  Let's fallback to the normal
 	 catchpoint mode.  */
@@ -209,7 +209,7 @@ re_set_exception_catchpoint (struct breakpoint *self)
 	  sals = self->ops->decode_location (self, location.get (),
 					     filter_pspace);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+      catch (const struct gdb_exception_error &ex)
 	{
 	  /* NOT_FOUND_ERROR just means the breakpoint will be
 	     pending, so let it through.  */
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 50555bb38ce..35dbc867f7a 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -2101,7 +2101,7 @@ parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
       aexpr = gen_eval_for_expr (scope, cond);
     }
 
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       /* If we got here, it means the condition could not be parsed to a valid
 	 bytecode expression and thus can't be evaluated on the target's side.
@@ -2276,7 +2276,7 @@ parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
 			  format_start, format_end - format_start,
 			  argvec.size (), argvec.data ());
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       /* If we got here, it means the command could not be parsed to a valid
 	 bytecode expression and thus can't be evaluated on the target's side.
@@ -2544,7 +2544,7 @@ insert_bp_location (struct bp_location *bl,
 	      if (val)
 		bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
 	    }
-	  catch (const struct gdb_exception_RETURN_MASK_ALL &e)
+	  catch (const struct gdb_exception &e)
 	    {
 	      bp_excpt = e;
 	    }
@@ -2583,7 +2583,7 @@ insert_bp_location (struct bp_location *bl,
 			bp_excpt
 			  = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
 		    }
-		  catch (const struct gdb_exception_RETURN_MASK_ALL &e)
+		  catch (const struct gdb_exception &e)
 		    {
 		      bp_excpt = e;
 		    }
@@ -2607,7 +2607,7 @@ insert_bp_location (struct bp_location *bl,
 		  if (val)
 		    bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
 	        }
-	      catch (const struct gdb_exception_RETURN_MASK_ALL &e)
+	      catch (const struct gdb_exception &e)
 	        {
 		  bp_excpt = e;
 	        }
@@ -5015,7 +5015,7 @@ bpstat_check_watchpoint (bpstat bs)
 	    {
 	      e = watchpoint_check (bs);
 	    }
-	  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+	  catch (const struct gdb_exception &ex)
 	    {
 	      exception_fprintf (gdb_stderr, ex,
 				 "Error evaluating expression "
@@ -5252,7 +5252,7 @@ bpstat_check_breakpoint_conditions (bpstat bs, thread_info *thread)
 	    {
 	      condition_result = breakpoint_cond_eval (cond);
 	    }
-	  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+	  catch (const struct gdb_exception &ex)
 	    {
 	      exception_fprintf (gdb_stderr, ex,
 				 "Error in testing breakpoint condition:\n");
@@ -9233,7 +9233,7 @@ create_breakpoint (struct gdbarch *gdbarch,
     {
       ops->create_sals_from_location (location, &canonical, type_wanted);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+  catch (const struct gdb_exception_error &e)
     {
       /* If caller is interested in rc value from parse, set
 	 value.  */
@@ -12046,7 +12046,7 @@ update_global_location_list_nothrow (enum ugll_insert_mode insert_mode)
     {
       update_global_location_list (insert_mode);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+  catch (const struct gdb_exception_error &e)
     {
     }
 }
@@ -13516,7 +13516,7 @@ update_breakpoint_locations (struct breakpoint *b,
 					   block_for_pc (sal.pc),
 					   0);
 	    }
-	  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+	  catch (const struct gdb_exception_error &e)
 	    {
 	      warning (_("failed to reevaluate condition "
 			 "for breakpoint %d: %s"), 
@@ -13593,7 +13593,7 @@ location_to_sals (struct breakpoint *b, struct event_location *location,
     {
       sals = b->ops->decode_location (b, location, search_pspace);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+  catch (const struct gdb_exception_error &e)
     {
       int not_found_and_ok = 0;
 
@@ -13803,7 +13803,7 @@ breakpoint_re_set (void)
 	  {
 	    breakpoint_re_set_one (b);
 	  }
-	catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+	catch (const struct gdb_exception &ex)
 	  {
 	    exception_fprintf (gdb_stderr, ex,
 			       "Error in re-setting breakpoint %d: ",
@@ -14283,7 +14283,7 @@ enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
 	  bpt->enable_state = bp_enabled;
 	  update_watchpoint (w, 1 /* reparse */);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &e)
+      catch (const struct gdb_exception &e)
 	{
 	  bpt->enable_state = orig_enable_state;
 	  exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
@@ -15021,7 +15021,7 @@ save_breakpoints (const char *filename, int from_tty,
 	  {
 	    print_command_lines (current_uiout, tp->commands.get (), 2);
 	  }
-	catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+	catch (const struct gdb_exception &ex)
 	  {
 	  current_uiout->redirect (NULL);
 	    throw_exception (ex);
diff --git a/gdb/btrace.c b/gdb/btrace.c
index d978b5d206d..26a6ede4dd5 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -687,7 +687,7 @@ ftrace_classify_insn (struct gdbarch *gdbarch, CORE_ADDR pc)
       else if (gdbarch_insn_is_jump (gdbarch, pc))
 	iclass = BTRACE_INSN_JUMP;
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &error)
+  catch (const struct gdb_exception_error &error)
     {
     }
 
@@ -1106,7 +1106,7 @@ btrace_compute_ftrace_bts (struct thread_info *tp,
 	    {
 	      size = gdb_insn_length (gdbarch, pc);
 	    }
-	  catch (const struct gdb_exception_RETURN_MASK_ERROR &error)
+	  catch (const struct gdb_exception_error &error)
 	    {
 	    }
 
@@ -1374,7 +1374,7 @@ btrace_pt_readmem_callback (gdb_byte *buffer, size_t size,
       if (errcode != 0)
 	result = -pte_nomap;
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &error)
+  catch (const struct gdb_exception_error &error)
     {
       result = -pte_nomap;
     }
@@ -1476,7 +1476,7 @@ btrace_compute_ftrace_pt (struct thread_info *tp,
 
       ftrace_add_pt (btinfo, decoder, &level, gaps);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &error)
+  catch (const struct gdb_exception &error)
     {
       /* Indicate a gap in the trace if we quit trace processing.  */
       if (error.reason == RETURN_QUIT && !btinfo->functions.empty ())
@@ -1556,7 +1556,7 @@ btrace_compute_ftrace (struct thread_info *tp, struct btrace_data *btrace,
     {
       btrace_compute_ftrace_1 (tp, btrace, cpu, gaps);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &error)
+  catch (const struct gdb_exception &error)
     {
       btrace_finalize_ftrace (tp, gaps);
 
@@ -1627,7 +1627,7 @@ btrace_enable (struct thread_info *tp, const struct btrace_config *conf)
 	  && can_access_registers_thread (tp))
 	btrace_add_pc (tp);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
+  catch (const struct gdb_exception &exception)
     {
       btrace_disable (tp);
 
@@ -3060,7 +3060,7 @@ btrace_maint_update_pt_packets (struct btrace_thread_info *btinfo)
     {
       btrace_maint_decode_pt (&btinfo->maint, decoder);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       pt_pkt_free_decoder (decoder);
 
diff --git a/gdb/c-varobj.c b/gdb/c-varobj.c
index df06caacb32..c7f841694b7 100644
--- a/gdb/c-varobj.c
+++ b/gdb/c-varobj.c
@@ -97,7 +97,7 @@ adjust_value_for_child_access (struct value **value,
 		  *value = value_ind (*value);
 		}
 
-	      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+	      catch (const struct gdb_exception_error &except)
 		{
 		  *value = NULL;
 		}
@@ -259,7 +259,7 @@ value_struct_element_index (struct value *value, int type_index)
       else
 	result = value_primitive_field (value, 0, type_index, type);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+  catch (const struct gdb_exception_error &e)
     {
       return NULL;
     }
@@ -318,7 +318,7 @@ c_describe_child (const struct varobj *parent, int index,
 	    {
 	      *cvalue = value_subscript (value, real_index);
 	    }
-	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+	  catch (const struct gdb_exception_error &except)
 	    {
 	    }
 	}
@@ -395,7 +395,7 @@ c_describe_child (const struct varobj *parent, int index,
 	      *cvalue = value_ind (value);
 	    }
 
-	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+	  catch (const struct gdb_exception_error &except)
 	    {
 	      *cvalue = NULL;
 	    }
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 4cf2a5919cf..1611362158d 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -267,7 +267,7 @@ complete_command (const char *arg, int from_tty)
 	  tracker = &tracker_handle_completions;
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       return;
     }
diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index 15373be77f1..02c956affd2 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -367,7 +367,7 @@ safe_execute_command (struct ui_out *command_uiout, const char *command,
     {
       execute_command (command, from_tty);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
+  catch (const struct gdb_exception &exception)
     {
       e = exception;
     }
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index f0080f950f1..3730827d9b4 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -1054,7 +1054,7 @@ process_next_line (const char *p, struct command_line **command,
 	{
 	  validator ((*command)->line);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+      catch (const struct gdb_exception &ex)
 	{
 	  free_command_lines (command);
 	  throw_exception (ex);
@@ -1546,7 +1546,7 @@ script_from_file (FILE *stream, const char *file)
     {
       read_command_file (stream);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+  catch (const struct gdb_exception_error &e)
     {
       /* Re-throw the error, but with the file name information
 	 prepended.  */
diff --git a/gdb/common/common-exceptions.c b/gdb/common/common-exceptions.c
index 15b59f4dd94..c2275fe6382 100644
--- a/gdb/common/common-exceptions.c
+++ b/gdb/common/common-exceptions.c
@@ -203,14 +203,14 @@ throw_exception_cxx (struct gdb_exception exception)
 {
   if (exception.reason == RETURN_QUIT)
     {
-      gdb_exception_RETURN_MASK_QUIT ex;
+      gdb_exception_quit ex;
 
       gdb_exception_sliced_copy (&ex, &exception);
       throw ex;
     }
   else if (exception.reason == RETURN_ERROR)
     {
-      gdb_exception_RETURN_MASK_ERROR ex;
+      gdb_exception_error ex;
 
       gdb_exception_sliced_copy (&ex, &exception);
       throw ex;
diff --git a/gdb/common/common-exceptions.h b/gdb/common/common-exceptions.h
index d4b30104239..e3ceb52553c 100644
--- a/gdb/common/common-exceptions.h
+++ b/gdb/common/common-exceptions.h
@@ -214,15 +214,11 @@ extern void exception_rethrow (void) ATTRIBUTE_NORETURN;
    around gdb_exception that add nothing but type info.  Which is used
    is selected depending on the MASK argument passed to CATCH.  */
 
-struct gdb_exception_RETURN_MASK_ALL : public gdb_exception
+struct gdb_exception_error : public gdb_exception
 {
 };
 
-struct gdb_exception_RETURN_MASK_ERROR : public gdb_exception_RETURN_MASK_ALL
-{
-};
-
-struct gdb_exception_RETURN_MASK_QUIT : public gdb_exception_RETURN_MASK_ALL
+struct gdb_exception_quit : public gdb_exception
 {
 };
 
@@ -233,7 +229,7 @@ struct gdb_exception_RETURN_MASK_QUIT : public gdb_exception_RETURN_MASK_ALL
    spread around the codebase.  */
 
 struct gdb_quit_bad_alloc
-  : public gdb_exception_RETURN_MASK_QUIT,
+  : public gdb_exception_quit,
     public std::bad_alloc
 {
   explicit gdb_quit_bad_alloc (gdb_exception ex)
diff --git a/gdb/common/new-op.c b/gdb/common/new-op.c
index b6c13afca19..9461e7eaa34 100644
--- a/gdb/common/new-op.c
+++ b/gdb/common/new-op.c
@@ -64,7 +64,7 @@ operator new (std::size_t sz)
 	{
 	  malloc_failure (sz);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+      catch (const struct gdb_exception &ex)
 	{
 	  throw gdb_quit_bad_alloc (ex);
 	}
diff --git a/gdb/common/selftest.c b/gdb/common/selftest.c
index cd43b2740c8..37f6d02efd1 100644
--- a/gdb/common/selftest.c
+++ b/gdb/common/selftest.c
@@ -87,7 +87,7 @@ run_tests (const char *filter)
 	  ++ran;
 	  (*test) ();
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+      catch (const struct gdb_exception_error &ex)
 	{
 	  ++failed;
 	  debug_printf ("Self test failed: %s\n", ex.message.c_str ());
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index a75161c5ca4..9b33c7df43b 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -367,7 +367,7 @@ gcc_convert_symbol (void *datum,
 	}
     }
 
-  catch (const struct gdb_exception_RETURN_MASK_ALL &e)
+  catch (const struct gdb_exception &e)
     {
       context->plugin ().error (e.message.c_str ());
     }
@@ -429,7 +429,7 @@ gcc_symbol_address (void *datum, struct gcc_c_context *gcc_context,
 	}
     }
 
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+  catch (const struct gdb_exception_error &e)
     {
       context->plugin ().error (e.message.c_str ());
     }
@@ -598,7 +598,7 @@ generate_c_for_for_one_variable (compile_instance *compiler,
 	}
     }
 
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+  catch (const struct gdb_exception_error &e)
     {
       compiler->insert_symbol_error (sym, e.message.c_str ());
     }
diff --git a/gdb/compile/compile-cplus-symbols.c b/gdb/compile/compile-cplus-symbols.c
index cc8f6ee3176..dcf0cdc7113 100644
--- a/gdb/compile/compile-cplus-symbols.c
+++ b/gdb/compile/compile-cplus-symbols.c
@@ -388,7 +388,7 @@ gcc_cplus_convert_symbol (void *datum,
 	    }
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &e)
+  catch (const struct gdb_exception &e)
     {
       /* We can't allow exceptions to escape out of this callback.  Safest
 	 is to simply emit a gcc error.  */
@@ -466,7 +466,7 @@ gcc_cplus_symbol_address (void *datum, struct gcc_cp_context *gcc_context,
 	}
     }
 
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+  catch (const struct gdb_exception_error &e)
     {
       instance->plugin ().error (e.message.c_str ());
     }
diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c
index 4885929d608..588e31aa3ef 100644
--- a/gdb/compile/compile-object-load.c
+++ b/gdb/compile/compile-object-load.c
@@ -54,7 +54,7 @@ munmap_list::~munmap_list ()
 	{
 	  gdbarch_infcall_munmap (target_gdbarch (), item.addr, item.size);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+      catch (const struct gdb_exception_error &ex)
 	{
 	  /* There's not much the user can do, so just ignore
 	     this.  */
diff --git a/gdb/compile/compile-object-run.c b/gdb/compile/compile-object-run.c
index 3639efd4179..ea24eee73b8 100644
--- a/gdb/compile/compile-object-run.c
+++ b/gdb/compile/compile-object-run.c
@@ -173,7 +173,7 @@ compile_object_run (struct compile_module *module)
       call_function_by_hand_dummy (func_val, NULL, args,
 				   do_module_cleanup, data);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       /* In the case of DTOR_FOUND or in the case of EXECUTED nothing
 	 needs to be done.  */
diff --git a/gdb/completer.c b/gdb/completer.c
index b946c696f23..748198500c1 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -1025,7 +1025,7 @@ complete_expression (completion_tracker &tracker,
     {
       type = parse_expression_for_completion (text, &fieldname, &code);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
       return;
     }
@@ -1448,7 +1448,7 @@ complete_line_internal (completion_tracker &tracker,
     {
       complete_line_internal_1 (tracker, text, line_buffer, point, reason);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
       if (except.error != MAX_COMPLETIONS_REACHED_ERROR)
 	throw_exception (except);
@@ -1861,7 +1861,7 @@ gdb_completion_word_break_characters ()
     {
       return gdb_completion_word_break_characters_throw ();
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       /* Set this to that gdb_rl_attempted_completion_function knows
 	 to abort early.  */
@@ -2208,7 +2208,7 @@ gdb_rl_attempted_completion_function (const char *text, int start, int end)
     {
       return gdb_rl_attempted_completion_function_throw (text, start, end);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
     }
 
diff --git a/gdb/corelow.c b/gdb/corelow.c
index f162ff9606c..e2d35e5604d 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -466,7 +466,7 @@ core_target_open (const char *arg, int from_tty)
       target_update_thread_list ();
     }
 
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
       exception_print (gdb_stderr, except);
     }
@@ -520,7 +520,7 @@ core_target_open (const char *arg, int from_tty)
 	{
 	  thread_command (NULL, from_tty);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+      catch (const struct gdb_exception_error &except)
 	{
 	  exception_print (gdb_stderr, except);
 	}
diff --git a/gdb/cp-abi.c b/gdb/cp-abi.c
index 800a3b41322..23dad4b1748 100644
--- a/gdb/cp-abi.c
+++ b/gdb/cp-abi.c
@@ -79,7 +79,7 @@ baseclass_offset (struct type *type, int index, const gdb_byte *valaddr,
 						embedded_offset,
 						address, val);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
@@ -115,7 +115,7 @@ value_rtti_type (struct value *v, int *full,
     {
       ret = (*current_cp_abi.rtti_type) (v, full, top, using_enc);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+  catch (const struct gdb_exception_error &e)
     {
       return NULL;
     }
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index 87ae5361ebd..79457f991fa 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -155,7 +155,7 @@ inspect_type (struct demangle_parse_info *info,
     {
       sym = lookup_symbol (name, 0, VAR_DOMAIN, 0).symbol;
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       return 0;
     }
@@ -228,7 +228,7 @@ inspect_type (struct demangle_parse_info *info,
 	    }
 	  /* If type_print threw an exception, there is little point
 	     in continuing, so just bow out gracefully.  */
-	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+	  catch (const struct gdb_exception_error &except)
 	    {
 	      return 0;
 	    }
@@ -427,7 +427,7 @@ replace_typedefs (struct demangle_parse_info *info,
 		  sym = lookup_symbol (local_name.get (), 0,
 				       VAR_DOMAIN, 0).symbol;
 		}
-	      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+	      catch (const struct gdb_exception &except)
 		{
 		}
 
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index 0d4cd49683a..0978bb7b21e 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -321,7 +321,7 @@ cp_print_value_fields (struct type *type, struct type *real_type,
 		      v = value_static_field (type, i);
 		    }
 
-		  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+		  catch (const struct gdb_exception_error &ex)
 		    {
 		      fprintf_filtered (stream,
 					_("<error reading variable: %s>"),
@@ -508,7 +508,7 @@ cp_print_value (struct type *type, struct type *real_type,
 	{
 	  boffset = baseclass_offset (type, i, valaddr, offset, address, val);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+      catch (const struct gdb_exception_error &ex)
 	{
 	  if (ex.error == NOT_AVAILABLE_ERROR)
 	    skip = -1;
diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c
index 7ac1df0c90f..1d4c267e074 100644
--- a/gdb/darwin-nat.c
+++ b/gdb/darwin-nat.c
@@ -1688,7 +1688,7 @@ darwin_attach_pid (struct inferior *inf)
 
       darwin_setup_exceptions (inf);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       exit_inferior (inf);
       inferior_ptid = null_ptid;
@@ -1952,7 +1952,7 @@ The error was: %s"),
 	{
 	  copy_shell_to_cache (shell, new_name);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+      catch (const struct gdb_exception_error &ex)
 	{
 	  warning (_("This version of macOS has System Integrity Protection.\n\
 Because `startup-with-shell' is enabled, gdb tried to work around SIP by\n\
diff --git a/gdb/disasm-selftests.c b/gdb/disasm-selftests.c
index 8d2bb2e79ef..93e5f39e08c 100644
--- a/gdb/disasm-selftests.c
+++ b/gdb/disasm-selftests.c
@@ -196,7 +196,7 @@ memory_error_test (struct gdbarch *gdbarch)
     {
       di.print_insn (0);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error == MEMORY_ERROR)
 	saw_memory_error = true;
diff --git a/gdb/dtrace-probe.c b/gdb/dtrace-probe.c
index 075eb2725d2..6ebab2289d1 100644
--- a/gdb/dtrace-probe.c
+++ b/gdb/dtrace-probe.c
@@ -489,7 +489,7 @@ dtrace_process_dof_probe (struct objfile *objfile,
 	      expr = parse_expression_with_language (type_str.c_str (),
 						     language_c);
 	    }
-	  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+	  catch (const struct gdb_exception_error &ex)
 	    {
 	    }
 
diff --git a/gdb/dwarf-index-cache.c b/gdb/dwarf-index-cache.c
index 5057d5e744b..e295f865cff 100644
--- a/gdb/dwarf-index-cache.c
+++ b/gdb/dwarf-index-cache.c
@@ -129,7 +129,7 @@ index_cache::store (struct dwarf2_per_objfile *dwarf2_per_objfile)
       write_psymtabs_to_index (dwarf2_per_objfile, m_dir.c_str (),
 			       build_id_str.c_str (), dw_index_kind::GDB_INDEX);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
       if (debug_index_cache)
 	printf_unfiltered ("index cache: couldn't store index cache for objfile "
@@ -188,7 +188,7 @@ index_cache::lookup_gdb_index (const bfd_build_id *build_id,
 	  ((const gdb_byte *) mmap_resource->mapping.get (),
 	   mmap_resource->mapping.size ());
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
       if (debug_index_cache)
 	printf_unfiltered ("index cache: couldn't read %s: %s\n",
diff --git a/gdb/dwarf-index-write.c b/gdb/dwarf-index-write.c
index 89cafdc8585..db036b1f922 100644
--- a/gdb/dwarf-index-write.c
+++ b/gdb/dwarf-index-write.c
@@ -1681,7 +1681,7 @@ save_gdb_index_command (const char *arg, int from_tty)
 	      write_psymtabs_to_index (dwarf2_per_objfile, arg, basename,
 				       index_kind);
 	    }
-	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+	  catch (const struct gdb_exception_error &except)
 	    {
 	      exception_fprintf (gdb_stderr, except,
 				 _("Error while writing index for `%s': "),
diff --git a/gdb/dwarf2-frame-tailcall.c b/gdb/dwarf2-frame-tailcall.c
index adb38b9cf84..0a31f4ada40 100644
--- a/gdb/dwarf2-frame-tailcall.c
+++ b/gdb/dwarf2-frame-tailcall.c
@@ -399,7 +399,7 @@ dwarf2_tailcall_sniffer_first (struct frame_info *this_frame,
 	    }
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
       if (entry_values_debug)
 	exception_print (gdb_stdout, except);
diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c
index ca5ced7135e..5067b94f834 100644
--- a/gdb/dwarf2-frame.c
+++ b/gdb/dwarf2-frame.c
@@ -1068,7 +1068,7 @@ dwarf2_frame_cache (struct frame_info *this_frame, void **this_cache)
 	  internal_error (__FILE__, __LINE__, _("Unknown CFA rule."));
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error == NOT_AVAILABLE_ERROR)
 	{
@@ -2253,7 +2253,7 @@ dwarf2_build_frame_info (struct objfile *objfile)
 						EH_CIE_OR_FDE_TYPE_ID);
 	    }
 
-	  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+	  catch (const struct gdb_exception_error &e)
 	    {
 	      warning (_("skipping .eh_frame info of %s: %s"),
 		       objfile_name (objfile), e.message.c_str ());
@@ -2293,7 +2293,7 @@ dwarf2_build_frame_info (struct objfile *objfile)
 					    &cie_table, &fde_table,
 					    EH_CIE_OR_FDE_TYPE_ID);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+      catch (const struct gdb_exception_error &e)
 	{
 	  warning (_("skipping .debug_frame info of %s: %s"),
 		   objfile_name (objfile), e.message.c_str ());
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index 80d0b44306f..263d9c55e37 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -1199,7 +1199,7 @@ call_site_find_chain (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
     {
       retval = call_site_find_chain_1 (gdbarch, caller_pc, callee_pc);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+  catch (const struct gdb_exception_error &e)
     {
       if (e.error == NO_ENTRY_VALUE_ERROR)
 	{
@@ -2168,7 +2168,7 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
     {
       ctx.eval (data, size);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error == NOT_AVAILABLE_ERROR)
 	{
@@ -2385,7 +2385,7 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
     {
       ctx.eval (dlbaton->data, dlbaton->size);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error == NOT_AVAILABLE_ERROR)
 	{
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 0d6f84c59a6..20c930bb4f8 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -6345,7 +6345,7 @@ dwarf2_build_psymtabs (struct objfile *objfile)
       /* (maybe) store an index in the cache.  */
       global_index_cache.store (dwarf2_per_objfile);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
       exception_print (gdb_stderr, except);
     }
diff --git a/gdb/eval.c b/gdb/eval.c
index 7a1efbe25fd..f46222d920a 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -205,7 +205,7 @@ fetch_subexp_value (struct expression *exp, int *pc, struct value **valp,
     {
       result = evaluate_subexp (NULL_TYPE, exp, pc, EVAL_NORMAL);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       /* Ignore memory errors if we want watchpoints pointing at
 	 inaccessible memory to still be created; otherwise, throw the
@@ -242,7 +242,7 @@ fetch_subexp_value (struct expression *exp, int *pc, struct value **valp,
 	      value_fetch_lazy (result);
 	      *valp = result;
 	    }
-	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+	  catch (const struct gdb_exception_error &except)
 	    {
 	    }
 	}
@@ -719,7 +719,7 @@ evaluate_var_value (enum noside noside, const block *blk, symbol *var)
       ret = value_of_variable (var, blk);
     }
 
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
       if (noside != EVAL_AVOID_SIDE_EFFECTS)
 	throw_exception (except);
@@ -959,7 +959,7 @@ evaluate_funcall (type *expect_type, expression *exp, int *pos,
 		  value = value_x_unop (arg2, op, noside);
 		}
 
-	      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+	      catch (const struct gdb_exception_error &except)
 		{
 		  if (except.error == NOT_FOUND_ERROR)
 		    break;
@@ -2031,7 +2031,7 @@ evaluate_subexp_standard (struct type *expect_type,
 	      value = value_x_unop (arg1, op, noside);
 	    }
 
-	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+	  catch (const struct gdb_exception_error &except)
 	    {
 	      if (except.error == NOT_FOUND_ERROR)
 		break;
diff --git a/gdb/event-loop.c b/gdb/event-loop.c
index e73443ed779..aa334fed156 100644
--- a/gdb/event-loop.c
+++ b/gdb/event-loop.c
@@ -370,7 +370,7 @@ start_event_loop (void)
 	{
 	  result = gdb_do_one_event ();
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+      catch (const struct gdb_exception &ex)
 	{
 	  exception_print (gdb_stderr, ex);
 
diff --git a/gdb/event-top.c b/gdb/event-top.c
index ea056dd99e2..6e4031165c7 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -212,7 +212,7 @@ gdb_rl_callback_handler (char *rl) noexcept
     {
       ui->input_handler (gdb::unique_xmalloc_ptr<char> (rl));
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       gdb_rl_expt = ex;
     }
@@ -1086,7 +1086,7 @@ async_disconnect (gdb_client_data arg)
       quit_cover ();
     }
 
-  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
+  catch (const struct gdb_exception &exception)
     {
       fputs_filtered ("Could not kill the program being debugged",
 		      gdb_stderr);
@@ -1097,7 +1097,7 @@ async_disconnect (gdb_client_data arg)
     {
       pop_all_targets ();
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
+  catch (const struct gdb_exception &exception)
     {
     }
 
diff --git a/gdb/exec.c b/gdb/exec.c
index fcee12da87b..c31ece2fa17 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -167,7 +167,7 @@ try_open_exec_file (const char *exec_file_host, struct inferior *inf,
 	 exec_file_attach will clear state.  */
       exec_file_attach (exec_file_host, add_flags & SYMFILE_VERBOSE);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &err)
+  catch (const struct gdb_exception_error &err)
     {
       if (!err.message.empty ())
 	warning ("%s", err.message.c_str ());
@@ -181,7 +181,7 @@ try_open_exec_file (const char *exec_file_host, struct inferior *inf,
 	{
 	  symbol_file_add_main (exec_file_host, add_flags);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &err)
+      catch (const struct gdb_exception_error &err)
 	{
 	  if (!exception_print_same (prev_err, err))
 	    warning ("%s", err.message.c_str ());
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index c82d7f3d749..757f188d591 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -414,7 +414,7 @@ info_common_command_for_block (const struct block *block, const char *comname,
 		value_print (val, gdb_stdout, &opts);
 	      }
 
-	    catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+	    catch (const struct gdb_exception_error &except)
 	      {
 		printf_filtered ("<error reading variable: %s>",
 				 except.message.c_str ());
diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
index eeac945e713..9df6841a765 100644
--- a/gdb/fbsd-tdep.c
+++ b/gdb/fbsd-tdep.c
@@ -719,7 +719,7 @@ fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
     {
       update_thread_list ();
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+  catch (const struct gdb_exception_error &e)
     {
       exception_print (gdb_stderr, e);
     }
diff --git a/gdb/frame-unwind.c b/gdb/frame-unwind.c
index 5ef11d50cf0..714e44475ac 100644
--- a/gdb/frame-unwind.c
+++ b/gdb/frame-unwind.c
@@ -105,7 +105,7 @@ frame_unwind_try_unwinder (struct frame_info *this_frame, void **this_cache,
     {
       res = unwinder->sniffer (unwinder, this_frame, this_cache);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       /* Catch all exceptions, caused by either interrupt or error.
 	 Reset *THIS_CACHE.  */
diff --git a/gdb/frame.c b/gdb/frame.c
index 43cc168b841..8665817658e 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -899,7 +899,7 @@ frame_unwind_pc (struct frame_info *this_frame)
 	  pc = gdbarch_unwind_pc (prev_gdbarch, this_frame);
 	  pc_p = 1;
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+      catch (const struct gdb_exception_error &ex)
 	{
 	  if (ex.error == NOT_AVAILABLE_ERROR)
 	    {
@@ -1913,7 +1913,7 @@ get_prev_frame_if_no_cycle (struct frame_info *this_frame)
 	  prev_frame = NULL;
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       prev_frame->next = NULL;
       this_frame->prev = NULL;
@@ -2094,7 +2094,7 @@ get_prev_frame_always (struct frame_info *this_frame)
     {
       prev_frame = get_prev_frame_always_1 (this_frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error == MEMORY_ERROR)
 	{
@@ -2380,7 +2380,7 @@ get_frame_pc_if_available (struct frame_info *frame, CORE_ADDR *pc)
     {
       *pc = frame_unwind_pc (frame->next);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error == NOT_AVAILABLE_ERROR)
 	return 0;
@@ -2462,7 +2462,7 @@ get_frame_address_in_block_if_available (struct frame_info *this_frame,
     {
       *pc = get_frame_address_in_block (this_frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error == NOT_AVAILABLE_ERROR)
 	return 0;
@@ -2747,7 +2747,7 @@ get_frame_language (struct frame_info *frame)
       pc = get_frame_address_in_block (frame);
       pc_p = 1;
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
diff --git a/gdb/gcore.c b/gdb/gcore.c
index e15ed7f44fb..0e4596241b7 100644
--- a/gdb/gcore.c
+++ b/gdb/gcore.c
@@ -122,7 +122,7 @@ write_gcore_file (bfd *obfd)
     {
       write_gcore_file_1 (obfd);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &e)
+  catch (const struct gdb_exception &e)
     {
       except = e;
     }
diff --git a/gdb/gdbserver/gdbreplay.c b/gdb/gdbserver/gdbreplay.c
index bc465b64dd8..496afce71f5 100644
--- a/gdb/gdbserver/gdbreplay.c
+++ b/gdb/gdbserver/gdbreplay.c
@@ -529,7 +529,7 @@ main (int argc, char *argv[])
     {
       captured_main (argc, argv);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
+  catch (const struct gdb_exception &exception)
     {
       if (exception.reason == RETURN_ERROR)
 	{
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index c42a2b56b13..71eb5145ec0 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -1536,7 +1536,7 @@ linux_detach_one_lwp (struct lwp_info *lwp)
       if (the_low_target.prepare_to_resume != NULL)
 	the_low_target.prepare_to_resume (lwp);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (!check_ptrace_stopped_lwp_gone (lwp))
 	throw_exception (ex);
@@ -4508,7 +4508,7 @@ linux_resume_one_lwp (struct lwp_info *lwp,
     {
       linux_resume_one_lwp_throw (lwp, step, signal, info);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (!check_ptrace_stopped_lwp_gone (lwp))
 	throw_exception (ex);
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 58a7d6bd0f3..c547fcaaac2 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -472,7 +472,7 @@ handle_btrace_general_set (char *own_buf)
 
       write_ok (own_buf);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &exception)
+  catch (const struct gdb_exception_error &exception)
     {
       sprintf (own_buf, "E.%s", exception.message.c_str ());
     }
@@ -1881,7 +1881,7 @@ handle_qxfer_btrace (const char *annex,
 	  if (result != 0)
 	    memcpy (cs.own_buf, cache.buffer, cache.used_size);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &exception)
+      catch (const struct gdb_exception_error &exception)
 	{
 	  sprintf (cs.own_buf, "E.%s", exception.message.c_str ());
 	  result = -1;
@@ -1952,7 +1952,7 @@ handle_qxfer_btrace_conf (const char *annex,
 	  if (result != 0)
 	    memcpy (cs.own_buf, cache.buffer, cache.used_size);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &exception)
+      catch (const struct gdb_exception_error &exception)
 	{
 	  sprintf (cs.own_buf, "E.%s", exception.message.c_str ());
 	  result = -1;
@@ -3553,7 +3553,7 @@ detach_or_kill_for_exit_cleanup ()
     {
       detach_or_kill_for_exit ();
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
+  catch (const struct gdb_exception &exception)
     {
       fflush (stdout);
       fprintf (stderr, "Detach or kill failed: %s\n",
@@ -3927,7 +3927,7 @@ captured_main (int argc, char *argv[])
 		}
 	    }
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &exception)
+      catch (const struct gdb_exception_error &exception)
 	{
 	  fflush (stdout);
 	  fprintf (stderr, "gdbserver: %s\n", exception.message.c_str ());
@@ -3954,7 +3954,7 @@ main (int argc, char *argv[])
     {
       captured_main (argc, argv);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
+  catch (const struct gdb_exception &exception)
     {
       if (exception.reason == RETURN_ERROR)
 	{
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 53995685db3..08c292457d2 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2591,7 +2591,7 @@ safe_parse_type (struct gdbarch *gdbarch, char *p, int length)
     {
       type = parse_and_eval_type (p, length);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
       type = builtin_type (gdbarch)->builtin_void;
     }
@@ -3771,7 +3771,7 @@ types_deeply_equal (struct type *type1, struct type *type2)
     {
       result = check_types_worklist (&worklist, cache);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       except = ex;
     }
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index ae19f13d118..9dc5d782ae8 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -910,7 +910,7 @@ print_one_vtable (struct gdbarch *gdbarch, struct value *value,
 	{
 	  addr = value_as_address (vfn);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+      catch (const struct gdb_exception_error &ex)
 	{
 	  printf_filtered (_("<error: %s>"), ex.message.c_str ());
 	  got_error = 1;
diff --git a/gdb/guile/guile-internal.h b/gdb/guile/guile-internal.h
index 122668da52f..dae135eb249 100644
--- a/gdb/guile/guile-internal.h
+++ b/gdb/guile/guile-internal.h
@@ -681,7 +681,7 @@ gdbscm_wrap (Function &&func, Args &&... args)
     {
       result = func (std::forward<Args> (args)...);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
diff --git a/gdb/guile/scm-block.c b/gdb/guile/scm-block.c
index e3d7005cd66..5bda9dc99cd 100644
--- a/gdb/guile/scm-block.c
+++ b/gdb/guile/scm-block.c
@@ -687,7 +687,7 @@ gdbscm_lookup_block (SCM pc_scm)
       if (cust != NULL && COMPUNIT_OBJFILE (cust) != NULL)
 	block = block_for_pc (pc);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
diff --git a/gdb/guile/scm-breakpoint.c b/gdb/guile/scm-breakpoint.c
index 07aebdf80ef..9b7cff6682b 100644
--- a/gdb/guile/scm-breakpoint.c
+++ b/gdb/guile/scm-breakpoint.c
@@ -465,7 +465,7 @@ gdbscm_register_breakpoint_x (SCM self)
 	  gdb_assert_not_reached ("invalid breakpoint type");
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       except = ex;
     }
@@ -493,7 +493,7 @@ gdbscm_delete_breakpoint_x (SCM self)
     {
       delete_breakpoint (bp_smob->bp);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -593,7 +593,7 @@ gdbscm_set_breakpoint_enabled_x (SCM self, SCM newvalue)
       else
 	disable_breakpoint (bp_smob->bp);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -627,7 +627,7 @@ gdbscm_set_breakpoint_silent_x (SCM self, SCM newvalue)
     {
       breakpoint_set_silent (bp_smob->bp, gdbscm_is_true (newvalue));
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -667,7 +667,7 @@ gdbscm_set_breakpoint_ignore_count_x (SCM self, SCM newvalue)
     {
       set_ignore_count (bp_smob->number, (int) value, 0);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -787,7 +787,7 @@ gdbscm_set_breakpoint_task_x (SCM self, SCM newvalue)
 	{
 	  valid_id = valid_task_id (id);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+      catch (const struct gdb_exception &except)
 	{
 	  GDBSCM_HANDLE_GDB_EXCEPTION (except);
 	}
@@ -807,7 +807,7 @@ gdbscm_set_breakpoint_task_x (SCM self, SCM newvalue)
     {
       breakpoint_set_task (bp_smob->bp, id);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -972,7 +972,7 @@ gdbscm_breakpoint_commands (SCM self)
     {
       print_command_lines (current_uiout, breakpoint_commands (bp), 0);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       current_uiout->redirect (NULL);
       gdbscm_throw_gdb_exception (except);
diff --git a/gdb/guile/scm-cmd.c b/gdb/guile/scm-cmd.c
index d5b4473a88e..0543ca72fa7 100644
--- a/gdb/guile/scm-cmd.c
+++ b/gdb/guile/scm-cmd.c
@@ -776,7 +776,7 @@ gdbscm_register_command_x (SCM self)
 			 c_smob->doc, cmd_list);
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
diff --git a/gdb/guile/scm-disasm.c b/gdb/guile/scm-disasm.c
index 8d0462b31df..63899c80c82 100644
--- a/gdb/guile/scm-disasm.c
+++ b/gdb/guile/scm-disasm.c
@@ -257,7 +257,7 @@ gdbscm_arch_disassemble (SCM self, SCM start_scm, SCM rest)
 	  else
 	    insn_len = gdb_print_insn (gdbarch, pc, &buf, NULL);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+      catch (const struct gdb_exception &except)
 	{
 	  GDBSCM_HANDLE_GDB_EXCEPTION (except);
 	}
diff --git a/gdb/guile/scm-frame.c b/gdb/guile/scm-frame.c
index 282cd000242..132cb869b1b 100644
--- a/gdb/guile/scm-frame.c
+++ b/gdb/guile/scm-frame.c
@@ -248,7 +248,7 @@ frscm_scm_from_frame (struct frame_info *frame, struct inferior *inferior)
 	}
       gdbarch = get_frame_arch (frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       return gdbscm_scm_from_gdb_exception (except);
     }
@@ -400,7 +400,7 @@ gdbscm_frame_valid_p (SCM self)
     {
       frame = frscm_frame_smob_to_frame (f_smob);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -429,7 +429,7 @@ gdbscm_frame_name (SCM self)
       if (frame != NULL)
 	name = find_frame_funname (frame, &lang, NULL);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -466,7 +466,7 @@ gdbscm_frame_type (SCM self)
       if (frame != NULL)
 	type = get_frame_type (frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -495,7 +495,7 @@ gdbscm_frame_arch (SCM self)
     {
       frame = frscm_frame_smob_to_frame (f_smob);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -525,7 +525,7 @@ gdbscm_frame_unwind_stop_reason (SCM self)
     {
       frame = frscm_frame_smob_to_frame (f_smob);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -559,7 +559,7 @@ gdbscm_frame_pc (SCM self)
       if (frame != NULL)
 	pc = get_frame_pc (frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -591,7 +591,7 @@ gdbscm_frame_block (SCM self)
       if (frame != NULL)
 	block = get_frame_block (frame, NULL);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -641,7 +641,7 @@ gdbscm_frame_function (SCM self)
       if (frame != NULL)
 	sym = find_pc_function (get_frame_address_in_block (frame));
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -677,7 +677,7 @@ gdbscm_frame_older (SCM self)
       if (frame != NULL)
 	prev = get_prev_frame (frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -713,7 +713,7 @@ gdbscm_frame_newer (SCM self)
       if (frame != NULL)
 	next = get_next_frame (frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -748,7 +748,7 @@ gdbscm_frame_sal (SCM self)
       if (frame != NULL)
 	sal = find_frame_sal (frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -793,7 +793,7 @@ gdbscm_frame_read_register (SCM self, SCM register_scm)
 	    value = value_of_register (regnum, frame);
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       except = ex;
     }
@@ -842,7 +842,7 @@ gdbscm_frame_read_var (SCM self, SCM symbol_scm, SCM rest)
     {
       frame = frscm_frame_smob_to_frame (f_smob);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -894,7 +894,7 @@ gdbscm_frame_read_var (SCM self, SCM symbol_scm, SCM rest)
 	    var = lookup_sym.symbol;
 	    block = lookup_sym.block;
 	  }
-	catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+	catch (const struct gdb_exception &ex)
 	  {
 	    except = ex;
 	  }
@@ -917,7 +917,7 @@ gdbscm_frame_read_var (SCM self, SCM symbol_scm, SCM rest)
     {
       value = read_var_value (var, block, frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -942,7 +942,7 @@ gdbscm_frame_select (SCM self)
       if (frame != NULL)
 	select_frame (frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -968,7 +968,7 @@ gdbscm_newest_frame (void)
     {
       frame = get_current_frame ();
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -988,7 +988,7 @@ gdbscm_selected_frame (void)
     {
       frame = get_selected_frame (_("No frame is currently selected"));
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
diff --git a/gdb/guile/scm-lazy-string.c b/gdb/guile/scm-lazy-string.c
index ad04123c187..26ec16badc5 100644
--- a/gdb/guile/scm-lazy-string.c
+++ b/gdb/guile/scm-lazy-string.c
@@ -336,7 +336,7 @@ lsscm_safe_lazy_string_to_value (SCM string, int arg_pos,
 	  break;
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       *except_scmp = gdbscm_scm_from_gdb_exception (except);
       return NULL;
diff --git a/gdb/guile/scm-math.c b/gdb/guile/scm-math.c
index a49b93629d1..fc53c916447 100644
--- a/gdb/guile/scm-math.c
+++ b/gdb/guile/scm-math.c
@@ -836,7 +836,7 @@ vlscm_convert_typed_value_from_scheme (const char *func_name,
 	  value = NULL;
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       except_scm = gdbscm_scm_from_gdb_exception (except);
     }
diff --git a/gdb/guile/scm-param.c b/gdb/guile/scm-param.c
index e5c064f337c..a060bf8c1e8 100644
--- a/gdb/guile/scm-param.c
+++ b/gdb/guile/scm-param.c
@@ -1018,7 +1018,7 @@ gdbscm_register_parameter_x (SCM self)
 			   set_list, show_list,
 			   &p_smob->set_command, &p_smob->show_command);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -1067,7 +1067,7 @@ gdbscm_parameter_value (SCM self)
 	{
 	  found = lookup_cmd_composition (newarg, &alias, &prefix, &cmd);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+      catch (const struct gdb_exception &ex)
 	{
 	  except = ex;
 	}
diff --git a/gdb/guile/scm-ports.c b/gdb/guile/scm-ports.c
index 649c12439f1..711d6044a97 100644
--- a/gdb/guile/scm-ports.c
+++ b/gdb/guile/scm-ports.c
@@ -279,7 +279,7 @@ ioscm_write (SCM port, const void *data, size_t size)
       else
 	fputsn_filtered ((const char *) data, size, gdb_stdout);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
diff --git a/gdb/guile/scm-pretty-print.c b/gdb/guile/scm-pretty-print.c
index c0680d2bd5d..ced79b49c27 100644
--- a/gdb/guile/scm-pretty-print.c
+++ b/gdb/guile/scm-pretty-print.c
@@ -558,7 +558,7 @@ ppscm_pretty_print_one_value (SCM printer, struct value **out_value,
 	    (_("invalid result from pretty-printer to-string"), result);
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
     }
 
diff --git a/gdb/guile/scm-symbol.c b/gdb/guile/scm-symbol.c
index 609bba1b1ed..792aa450fcb 100644
--- a/gdb/guile/scm-symbol.c
+++ b/gdb/guile/scm-symbol.c
@@ -490,7 +490,7 @@ gdbscm_symbol_needs_frame_p (SCM self)
     {
       result = symbol_read_needs_frame (symbol);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -556,7 +556,7 @@ gdbscm_symbol_value (SCM self, SCM rest)
 	 can happen with nested functions).  */
       value = read_var_value (symbol, NULL, frame_info);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -607,7 +607,7 @@ gdbscm_lookup_symbol (SCM name_scm, SCM rest)
 	  selected_frame = get_selected_frame (_("no frame selected"));
 	  block = get_frame_block (selected_frame, NULL);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+      catch (const struct gdb_exception &ex)
 	{
 	  xfree (name);
 	  GDBSCM_HANDLE_GDB_EXCEPTION (ex);
@@ -620,7 +620,7 @@ gdbscm_lookup_symbol (SCM name_scm, SCM rest)
       symbol = lookup_symbol (name, block, (domain_enum) domain,
 			      &is_a_field_of_this).symbol;
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       except = ex;
     }
@@ -656,7 +656,7 @@ gdbscm_lookup_global_symbol (SCM name_scm, SCM rest)
     {
       symbol = lookup_global_symbol (name, NULL, (domain_enum) domain).symbol;
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       except = ex;
     }
diff --git a/gdb/guile/scm-symtab.c b/gdb/guile/scm-symtab.c
index c83c48dfe0d..e8fe1c4e037 100644
--- a/gdb/guile/scm-symtab.c
+++ b/gdb/guile/scm-symtab.c
@@ -597,7 +597,7 @@ gdbscm_find_pc_line (SCM pc_scm)
 
       sal = find_pc_line (pc, 0);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c
index 7efad975be9..0c2f0813c14 100644
--- a/gdb/guile/scm-type.c
+++ b/gdb/guile/scm-type.c
@@ -112,7 +112,7 @@ tyscm_type_name (struct type *type)
       LA_PRINT_TYPE (type, "", &stb, -1, 0, &type_print_raw_options);
       return std::move (stb.string ());
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       SCM excp = gdbscm_scm_from_gdb_exception (except);
       gdbscm_throw (excp);
@@ -238,7 +238,7 @@ tyscm_equal_p_type_smob (SCM type1_scm, SCM type2_scm)
     {
       result = types_deeply_equal (type1, type2);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -631,7 +631,7 @@ gdbscm_type_sizeof (SCM self)
     {
       check_typedef (type);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
     }
 
@@ -654,7 +654,7 @@ gdbscm_type_strip_typedefs (SCM self)
     {
       type = check_typedef (type);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -675,7 +675,7 @@ tyscm_get_composite (struct type *type)
 	{
 	  type = check_typedef (type);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+      catch (const struct gdb_exception &except)
 	{
 	  GDBSCM_HANDLE_GDB_EXCEPTION (except);
 	}
@@ -731,7 +731,7 @@ tyscm_array_1 (SCM self, SCM n1_scm, SCM n2_scm, int is_vector,
       if (is_vector)
 	make_vector_type (array);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -785,7 +785,7 @@ gdbscm_type_pointer (SCM self)
     {
       type = lookup_pointer_type (type);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -846,7 +846,7 @@ gdbscm_type_reference (SCM self)
     {
       type = lookup_lvalue_reference_type (type);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -883,7 +883,7 @@ gdbscm_type_const (SCM self)
     {
       type = make_cv_type (1, 0, type, NULL);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -905,7 +905,7 @@ gdbscm_type_volatile (SCM self)
     {
       type = make_cv_type (0, 1, type, NULL);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -927,7 +927,7 @@ gdbscm_type_unqualified (SCM self)
     {
       type = make_cv_type (0, 0, type, NULL);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -1231,7 +1231,7 @@ tyscm_lookup_typename (const char *type_name, const struct block *block)
 	type = lookup_typename (current_language, get_current_arch (),
 				type_name, block, 0);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       return NULL;
     }
diff --git a/gdb/guile/scm-value.c b/gdb/guile/scm-value.c
index 9aa250bfc8f..5ee48b7ac4a 100644
--- a/gdb/guile/scm-value.c
+++ b/gdb/guile/scm-value.c
@@ -163,7 +163,7 @@ vlscm_print_value_smob (SCM self, SCM port, scm_print_state *pstate)
       common_val_print (v_smob->value, &stb, 0, &opts, current_language);
       scm_puts (stb.c_str (), port);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -190,7 +190,7 @@ vlscm_equal_p_value_smob (SCM v1, SCM v2)
     {
       result = value_equal (v1_smob->value, v2_smob->value);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -394,7 +394,7 @@ gdbscm_value_address (SCM self)
 	    {
 	      address = vlscm_scm_from_value (value_addr (value));
 	    }
-	  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+	  catch (const struct gdb_exception &except)
 	    {
 	    }
 
@@ -529,7 +529,7 @@ gdbscm_value_dynamic_type (SCM self)
 	  type = NULL;
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -684,7 +684,7 @@ gdbscm_value_call (SCM self, SCM args)
     {
       ftype = check_typedef (value_type (function));
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -752,7 +752,7 @@ gdbscm_value_to_bytevector (SCM self)
       length = TYPE_LENGTH (type);
       contents = value_contents (value);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -793,7 +793,7 @@ gdbscm_value_to_bool (SCM self)
     {
       type = check_typedef (type);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -808,7 +808,7 @@ gdbscm_value_to_bool (SCM self)
       else
 	l = value_as_long (value);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -834,7 +834,7 @@ gdbscm_value_to_integer (SCM self)
     {
       type = check_typedef (type);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -849,7 +849,7 @@ gdbscm_value_to_integer (SCM self)
       else
 	l = value_as_long (value);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -879,7 +879,7 @@ gdbscm_value_to_real (SCM self)
     {
       type = check_typedef (type);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -906,7 +906,7 @@ gdbscm_value_to_real (SCM self)
 	  check = value_from_longest (type, (LONGEST) d);
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
@@ -999,7 +999,7 @@ gdbscm_value_to_string (SCM self, SCM rest)
       LA_GET_STRING (value, &buffer, &length, &char_type, &la_encoding);
       buffer_contents = buffer.release ();
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       xfree (encoding);
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
@@ -1120,7 +1120,7 @@ gdbscm_value_to_lazy_string (SCM self, SCM rest)
 
       result = lsscm_make_lazy_string (addr, length, encoding, type);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       except = ex;
     }
@@ -1182,7 +1182,7 @@ gdbscm_value_print (SCM self)
     {
       common_val_print (value, &stb, 0, &opts, current_language);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c
index 85f761df669..41b8fd149cd 100644
--- a/gdb/i386-linux-tdep.c
+++ b/gdb/i386-linux-tdep.c
@@ -414,7 +414,7 @@ i386_linux_handle_segmentation_fault (struct gdbarch *gdbarch,
       access
         = parse_and_eval_long ("$_siginfo._sifields._sigfault.si_addr");
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
+  catch (const struct gdb_exception &exception)
     {
       return;
     }
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 5dee63dec23..35ad62b4d3b 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -2086,7 +2086,7 @@ i386_frame_cache (struct frame_info *this_frame, void **this_cache)
     {
       i386_frame_cache_1 (this_frame, cache);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
@@ -2265,7 +2265,7 @@ i386_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
 
       cache->base_p = 1;
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
@@ -2460,7 +2460,7 @@ i386_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 
       cache->base_p = 1;
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
diff --git a/gdb/inf-loop.c b/gdb/inf-loop.c
index 86e45babe37..4cd179abfcf 100644
--- a/gdb/inf-loop.c
+++ b/gdb/inf-loop.c
@@ -71,7 +71,7 @@ inferior_event_handler (enum inferior_event_type event_type,
 	    {
 	      bpstat_do_actions ();
 	    }
-	  catch (const struct gdb_exception_RETURN_MASK_ALL &e)
+	  catch (const struct gdb_exception &e)
 	    {
 	      /* If the user was running a foreground execution
 		 command, then propagate the error so that the prompt
diff --git a/gdb/infcall.c b/gdb/infcall.c
index ee63d33384b..659e6ad2cd5 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -602,7 +602,7 @@ run_inferior_call (struct call_thread_fsm *sm,
 	 target supports asynchronous execution.  */
       wait_sync_command_done ();
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &e)
+  catch (const struct gdb_exception &e)
     {
       caught_error = e;
     }
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 590f9dcaabe..024c5b832da 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -451,7 +451,7 @@ post_create_inferior (struct target_ops *target, int from_tty)
     {
       thr->suspend.stop_pc = regcache_read_pc (get_current_regcache ());
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
@@ -1652,7 +1652,7 @@ print_return_value (struct ui_out *uiout, struct return_value_info *rv)
 	 delete the breakpoint.  */
       print_return_value_1 (uiout, rv);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       exception_print (gdb_stdout, ex);
     }
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 3e6eaa3f511..ed245133e9f 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -1778,7 +1778,7 @@ displaced_step_prepare (thread_info *thread)
     {
       prepared = displaced_step_prepare_throw (thread);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       struct displaced_step_inferior_state *displaced_state;
 
@@ -2611,7 +2611,7 @@ resume (gdb_signal sig)
     {
       resume_1 (sig);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       /* If resuming is being aborted for any reason, delete any
 	 single-step breakpoint resume_1 may have created, to avoid
@@ -7351,7 +7351,7 @@ insert_exception_resume_breakpoint (struct thread_info *tp,
 	  inferior_thread ()->control.exception_resume_breakpoint = bp;
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+  catch (const struct gdb_exception_error &e)
     {
       /* We want to ignore errors here.  */
     }
@@ -7450,7 +7450,7 @@ check_exception_resume (struct execution_control_state *ecs,
 	    }
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+  catch (const struct gdb_exception_error &e)
     {
     }
 }
@@ -7583,7 +7583,7 @@ keep_going_pass_signal (struct execution_control_state *ecs)
 	{
 	  insert_breakpoints ();
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+      catch (const struct gdb_exception_error &e)
 	{
 	  exception_print (gdb_stderr, e);
 	  stop_waiting (ecs);
@@ -8114,7 +8114,7 @@ normal_stop (void)
 	{
 	  execute_cmd_pre_hook (stop_command);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+      catch (const struct gdb_exception &ex)
 	{
 	  exception_fprintf (gdb_stderr, ex,
 			     "Error while running hook_stop:\n");
@@ -8821,7 +8821,7 @@ restore_infcall_control_state (struct infcall_control_state *inf_status)
 	{
 	  restore_selected_frame (inf_status->selected_frame_id);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+      catch (const struct gdb_exception_error &ex)
 	{
 	  exception_fprintf (gdb_stderr, ex,
 			     "Unable to restore previously selected frame:\n");
diff --git a/gdb/jit.c b/gdb/jit.c
index 26675f41142..4e9050cdf27 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -857,7 +857,7 @@ jit_reader_try_read_symtab (struct jit_code_entry *code_entry,
 			      code_entry->symfile_size))
 	status = 0;
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &e)
+  catch (const struct gdb_exception &e)
     {
       status = 0;
     }
diff --git a/gdb/language.c b/gdb/language.c
index 7e62bace0d1..615c984985f 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -179,7 +179,7 @@ set_language_command (const char *ignore,
 		  frame = get_selected_frame (NULL);
 		  flang = get_frame_language (frame);
 		}
-	      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+	      catch (const struct gdb_exception_error &ex)
 		{
 		  flang = language_unknown;
 		}
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 93a3d2f9507..dcf0b5ea4ec 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -2394,7 +2394,7 @@ convert_explicit_location_to_linespec (struct linespec_state *self,
 	  *result->file_symtabs
 	    = symtabs_from_filename (source_filename, self->search_pspace);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+      catch (const struct gdb_exception_error &except)
 	{
 	  source_file_not_found_error (source_filename);
 	}
@@ -2619,7 +2619,7 @@ parse_linespec (linespec_parser *parser, const char *arg,
 	    = symtabs_from_filename (user_filename.get (),
 				     PARSER_STATE (parser)->search_pspace);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+      catch (const struct gdb_exception_error &ex)
 	{
 	  file_exception = ex;
 	}
@@ -2936,7 +2936,7 @@ linespec_complete_label (completion_tracker &tracker,
 					     func_name_match_type,
 					     NULL, unknown_offset);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       return;
     }
@@ -2966,7 +2966,7 @@ linespec_complete (completion_tracker &tracker, const char *text,
     {
       parse_linespec (&parser, text, match_type);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
     }
 
@@ -3156,7 +3156,7 @@ event_location_to_sals (linespec_parser *parser,
 	    result = parse_linespec (parser,
 				     ls->spec_string, ls->match_type);
 	  }
-	catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+	catch (const struct gdb_exception_error &except)
 	  {
 	    throw_exception (except);
 	  }
@@ -3969,7 +3969,7 @@ find_linespec_symbols (struct linespec_state *state,
 
 	  /* If successful, we're done.  If NOT_FOUND_ERROR
 	     was not thrown, rethrow the exception that we did get.  */
-	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+	  catch (const struct gdb_exception_error &except)
 	    {
 	      if (except.error != NOT_FOUND_ERROR)
 		throw_exception (except);
diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c
index 317bac45f13..71284ddb31b 100644
--- a/gdb/linux-fork.c
+++ b/gdb/linux-fork.c
@@ -478,7 +478,7 @@ public:
 	    fork_load_infrun_state (m_oldfp);
 	    insert_breakpoints ();
 	  }
-	catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+	catch (const struct gdb_exception &ex)
 	  {
 	    warning (_("Couldn't restore checkpoint state in %s: %s"),
 		     target_pid_to_str (m_oldfp->ptid), ex.message.c_str ());
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index ea460dea258..72cad8880e6 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -1193,7 +1193,7 @@ linux_nat_target::attach (const char *args, int from_tty)
     {
       inf_ptrace_target::attach (args, from_tty);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       pid_t pid = parse_pid_to_attach (args);
       std::string reason = linux_ptrace_attach_fail_reason (pid);
@@ -1406,7 +1406,7 @@ detach_one_lwp (struct lwp_info *lp, int *signo_p)
     {
       linux_target->low_prepare_to_resume (lp);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (!check_ptrace_stopped_lwp_gone (lp))
 	throw_exception (ex);
@@ -1587,7 +1587,7 @@ linux_resume_one_lwp (struct lwp_info *lp, int step, enum gdb_signal signo)
     {
       linux_resume_one_lwp_throw (lp, step, signo);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (!check_ptrace_stopped_lwp_gone (lp))
 	throw_exception (ex);
@@ -3539,7 +3539,7 @@ resume_stopped_resumed_lwps (struct lwp_info *lp, void *data)
 	      linux_resume_one_lwp_throw (lp, lp->step, GDB_SIGNAL_0);
 	    }
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+      catch (const struct gdb_exception_error &ex)
 	{
 	  if (!check_ptrace_stopped_lwp_gone (lp))
 	    throw_exception (ex);
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index a4c0b790e98..83282c2da05 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -1935,7 +1935,7 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
     {
       update_thread_list ();
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+  catch (const struct gdb_exception_error &e)
     {
       exception_print (gdb_stderr, e);
     }
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index eaaf55fd3e8..1671537c364 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -502,7 +502,7 @@ thread_db_find_new_threads_silently (thread_info *stopped)
       thread_db_find_new_threads_2 (stopped, true);
     }
 
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
       if (libthread_db_debug)
 	exception_fprintf (gdb_stdlog, except,
@@ -772,7 +772,7 @@ check_thread_db (struct thread_db_info *info, bool log_progress)
       if (!tdb_testinfo->threads_seen)
 	error (_("no threads seen"));
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
       if (warning_pre_print)
 	fputs_unfiltered (warning_pre_print, gdb_stderr);
@@ -1518,7 +1518,7 @@ find_new_threads_once (struct thread_db_info *info, int iteration,
 				    TD_SIGNO_MASK,
 				    TD_THR_ANY_USER_FLAGS);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
       if (libthread_db_debug)
 	{
diff --git a/gdb/main.c b/gdb/main.c
index e5d93bf4065..85b7f7629de 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -373,7 +373,7 @@ catch_command_errors (catch_command_errors_const_ftype command,
 
       maybe_wait_sync_command_done (was_sync);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &e)
+  catch (const struct gdb_exception &e)
     {
       return handle_command_errors (e);
     }
@@ -1172,7 +1172,7 @@ captured_main (void *data)
 	{
 	  captured_command_loop ();
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+      catch (const struct gdb_exception &ex)
 	{
 	  exception_print (gdb_stderr, ex);
 	}
@@ -1187,7 +1187,7 @@ gdb_main (struct captured_main_args *args)
     {
       captured_main (args);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       exception_print (gdb_stderr, ex);
     }
diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c
index d8bed92d858..968e0806f5a 100644
--- a/gdb/mi/mi-cmd-break.c
+++ b/gdb/mi/mi-cmd-break.c
@@ -58,7 +58,7 @@ breakpoint_notify (struct breakpoint *b)
 	{
 	  print_breakpoint (b);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+      catch (const struct gdb_exception &ex)
 	{
 	  exception_print (gdb_stderr, ex);
 	}
diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index 457712bbeaf..4ac7cd1cf3b 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -542,7 +542,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
 	      common_val_print (arg->val, &stb, 0, &opts,
 				language_def (SYMBOL_LANGUAGE (arg->sym)));
 	    }
-	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+	  catch (const struct gdb_exception_error &except)
 	    {
 	      error_message = std::move (except.message);
 	    }
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index 75b581be5c2..c6b273c9da7 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -842,7 +842,7 @@ mi_print_breakpoint_for_event (struct mi_interp *mi, breakpoint *bp)
 
       print_breakpoint (bp);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       exception_print (gdb_stderr, ex);
     }
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 0997f6e10b9..10f185e29ce 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1942,7 +1942,7 @@ mi_execute_command (const char *cmd, int from_tty)
     {
       command = mi_parse (cmd, &token);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
+  catch (const struct gdb_exception &exception)
     {
       mi_print_exception (token, exception);
       xfree (token);
@@ -1969,7 +1969,7 @@ mi_execute_command (const char *cmd, int from_tty)
 	{
 	  captured_mi_execute_command (current_uiout, command.get ());
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &result)
+      catch (const struct gdb_exception &result)
 	{
 	  /* Like in start_event_loop, enable input and force display
 	     of the prompt.  Otherwise, any command that calls
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 4b3a0d4f62b..44164449979 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -1302,7 +1302,7 @@ find_objc_msgcall_submethod (int (*f) (CORE_ADDR, CORE_ADDR *),
       if (f (pc, new_pc) == 0)
 	return 1;
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       exception_fprintf (gdb_stderr, ex,
 			 "Unable to determine target of "
diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
index 473773f279e..c90b68df79d 100644
--- a/gdb/p-valprint.c
+++ b/gdb/p-valprint.c
@@ -758,7 +758,7 @@ pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
 	{
 	  boffset = baseclass_offset (type, i, valaddr, offset, address, val);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+      catch (const struct gdb_exception_error &ex)
 	{
 	  if (ex.error == NOT_AVAILABLE_ERROR)
 	    skip = -1;
diff --git a/gdb/parse.c b/gdb/parse.c
index fcdc2c2d54e..627ae580105 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -1204,7 +1204,7 @@ parse_exp_in_context_1 (const char **stringptr, CORE_ADDR pc,
     {
       lang->la_parser (&ps);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       /* If parsing for completion, allow this to succeed; but if no
 	 expression elements have been written, then there's nothing
@@ -1286,7 +1286,7 @@ parse_expression_for_completion (const char *string,
       parse_completion = 1;
       exp = parse_exp_in_context (&string, 0, 0, 0, 0, &subexp);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
       /* Nothing, EXP remains NULL.  */
     }
diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
index c0b7505dda4..96503b02d2b 100644
--- a/gdb/ppc-linux-tdep.c
+++ b/gdb/ppc-linux-tdep.c
@@ -1845,7 +1845,7 @@ ppc_linux_spe_context (int wordsize, enum bfd_endian byte_order,
 	  spe_context_cache_ptid = inferior_ptid;
 	}
 
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+      catch (const struct gdb_exception_error &ex)
 	{
 	  return 0;
 	}
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index dc506250d4b..ecff90256a8 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1888,7 +1888,7 @@ do_one_display (struct display *d)
 	  d->exp = parse_expression (d->exp_string);
 	  d->block = innermost_block.block ();
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+      catch (const struct gdb_exception &ex)
 	{
 	  /* Can't re-parse the expression.  Disable this display item.  */
 	  d->enabled_p = 0;
@@ -1953,7 +1953,7 @@ do_one_display (struct display *d)
 	    addr = gdbarch_addr_bits_remove (d->exp->gdbarch, addr);
 	  do_examine (d->format, d->exp->gdbarch, addr);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+      catch (const struct gdb_exception_error &ex)
 	{
 	  fprintf_filtered (gdb_stdout, _("<error: %s>\n"),
 			    ex.message.c_str ());
@@ -1987,7 +1987,7 @@ do_one_display (struct display *d)
 	  val = evaluate_expression (d->exp.get ());
 	  print_formatted (val, d->format.size, &opts, gdb_stdout);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+      catch (const struct gdb_exception_error &ex)
 	{
 	  fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message.c_str ());
 	}
@@ -2191,7 +2191,7 @@ print_variable_and_value (const char *name, struct symbol *var,
 	 function.  */
       frame = NULL;
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
       fprintf_filtered (stream, "<error reading variable %s (%s)>", name,
 			except.message.c_str ());
diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index 9b234577594..471a3e941b1 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -203,7 +203,7 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
         {
           insn_len = gdb_print_insn (gdbarch, pc, &stb, NULL);
         }
-      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+      catch (const struct gdb_exception &except)
         {
 	  gdbpy_convert_exception (except);
 	  return NULL;
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 835d3d9dd45..04982221d68 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -145,7 +145,7 @@ bppy_set_enabled (PyObject *self, PyObject *newvalue, void *closure)
       else
 	disable_breakpoint (self_bp->bp);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_SET_HANDLE_EXCEPTION (except);
     }
@@ -250,7 +250,7 @@ bppy_set_task (PyObject *self, PyObject *newvalue, void *closure)
 	{
 	  valid_id = valid_task_id (id);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+      catch (const struct gdb_exception &except)
 	{
 	  GDB_PY_SET_HANDLE_EXCEPTION (except);
 	}
@@ -292,7 +292,7 @@ bppy_delete_breakpoint (PyObject *self, PyObject *args)
     {
       delete_breakpoint (self_bp->bp);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -333,7 +333,7 @@ bppy_set_ignore_count (PyObject *self, PyObject *newvalue, void *closure)
     {
       set_ignore_count (self_bp->number, (int) value, 0);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_SET_HANDLE_EXCEPTION (except);
     }
@@ -469,7 +469,7 @@ bppy_set_condition (PyObject *self, PyObject *newvalue, void *closure)
     {
       set_breakpoint_condition (self_bp->bp, exp, 0);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       except = ex;
     }
@@ -498,7 +498,7 @@ bppy_get_commands (PyObject *self, void *closure)
     {
       print_command_lines (current_uiout, breakpoint_commands (bp), 0);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       current_uiout->redirect (NULL);
       gdbpy_convert_exception (except);
@@ -540,7 +540,7 @@ bppy_set_commands (PyObject *self, PyObject *newvalue, void *closure)
       counted_command_line lines = read_command_lines_1 (reader, 1, nullptr);
       breakpoint_set_commands (self_bp->bp, std::move (lines));
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       except = ex;
     }
@@ -864,7 +864,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 	  error(_("Do not understand breakpoint type to set."));
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       bppy_pending_object = NULL;
       gdbpy_convert_exception (except);
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index 4812c6acca0..339a608b0fa 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -572,7 +572,7 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
 	set_cmd_completer_handle_brkchars (cmd,
 					   cmdpy_completer_handle_brkchars);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       xfree (cmd_name);
       xfree (docstring);
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index e23f5c18ea1..73a92990d8c 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -121,7 +121,7 @@ bpfinishpy_pre_stop_hook (struct gdbpy_breakpoint_object *bp_obj)
           self_finishbp->return_value = Py_None;
         }
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       gdbpy_convert_exception (except);
       gdbpy_print_stack ();
@@ -141,7 +141,7 @@ bpfinishpy_post_stop_hook (struct gdbpy_breakpoint_object *bp_obj)
       disable_breakpoint (bp_obj->bp);
       gdb_assert (bp_obj->bp->disposition == disp_del);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       gdbpy_convert_exception (except);
       gdbpy_print_stack ();
@@ -208,7 +208,7 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 	    }
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       gdbpy_convert_exception (except);
       return -1;
@@ -267,7 +267,7 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
             }
         }
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       /* Just swallow.  Either the return type or the function value
 	 remain NULL.  */
@@ -302,7 +302,7 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
                          &bkpt_breakpoint_ops,
                          0, 1, internal_bp, 0);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_SET_HANDLE_EXCEPTION (except);
     }
@@ -364,7 +364,7 @@ bpfinishpy_detect_out_scope_cb (struct breakpoint *b, void *args)
                       || frame_find_by_id (b->frame_id) == NULL))
                 bpfinishpy_out_of_scope (finish_bp);
             }
-          catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+          catch (const struct gdb_exception &except)
             {
               gdbpy_convert_exception (except);
               gdbpy_print_stack ();
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 32891dc048a..862874cf92a 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -99,7 +99,7 @@ frapy_is_valid (PyObject *self, PyObject *args)
     {
       frame = frame_object_to_frame_info (self);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -127,7 +127,7 @@ frapy_name (PyObject *self, PyObject *args)
 
       name = find_frame_funname (frame, &lang, NULL);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -161,7 +161,7 @@ frapy_type (PyObject *self, PyObject *args)
 
       type = get_frame_type (frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -182,7 +182,7 @@ frapy_arch (PyObject *self, PyObject *args)
     {
       FRAPY_REQUIRE_VALID (self, frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -203,7 +203,7 @@ frapy_unwind_stop_reason (PyObject *self, PyObject *args)
     {
       FRAPY_REQUIRE_VALID (self, frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -228,7 +228,7 @@ frapy_pc (PyObject *self, PyObject *args)
 
       pc = get_frame_pc (frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -264,7 +264,7 @@ frapy_read_register (PyObject *self, PyObject *args)
       if (val == NULL)
         PyErr_SetString (PyExc_ValueError, _("Unknown register."));
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -286,7 +286,7 @@ frapy_block (PyObject *self, PyObject *args)
       FRAPY_REQUIRE_VALID (self, frame);
       block = get_frame_block (frame, NULL);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -331,7 +331,7 @@ frapy_function (PyObject *self, PyObject *args)
       gdb::unique_xmalloc_ptr<char> funname
 	= find_frame_funname (frame, &funlang, &sym);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -373,7 +373,7 @@ frame_info_to_frame_object (struct frame_info *frame)
 	}
       frame_obj->gdbarch = get_frame_arch (frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       gdbpy_convert_exception (except);
       return NULL;
@@ -398,7 +398,7 @@ frapy_older (PyObject *self, PyObject *args)
 
       prev = get_prev_frame (frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -430,7 +430,7 @@ frapy_newer (PyObject *self, PyObject *args)
 
       next = get_next_frame (frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -462,7 +462,7 @@ frapy_find_sal (PyObject *self, PyObject *args)
       symtab_and_line sal = find_frame_sal (frame);
       sal_obj = symtab_and_line_to_sal_object (sal);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -521,7 +521,7 @@ frapy_read_var (PyObject *self, PyObject *args)
 	  var = lookup_sym.symbol;
 	  block = lookup_sym.block;
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+      catch (const struct gdb_exception &except)
 	{
 	  gdbpy_convert_exception (except);
 	  return NULL;
@@ -548,7 +548,7 @@ frapy_read_var (PyObject *self, PyObject *args)
 
       val = read_var_value (var, block, frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -569,7 +569,7 @@ frapy_select (PyObject *self, PyObject *args)
 
       select_frame (fi);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -589,7 +589,7 @@ gdbpy_newest_frame (PyObject *self, PyObject *args)
     {
       frame = get_current_frame ();
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -609,7 +609,7 @@ gdbpy_selected_frame (PyObject *self, PyObject *args)
     {
       frame = get_selected_frame ("No frame is currently selected.");
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 545ed713efd..672c324c2bf 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -1085,7 +1085,7 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang,
     {
       gdbarch = get_frame_arch (frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
       /* Let gdb try to print the stack trace.  */
       return EXT_LANG_BT_NO_FILTERS;
@@ -1170,7 +1170,7 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang,
 	  success = py_print_frame (item.get (), flags, args_type, out, 0,
 				    levels_printed.get ());
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+      catch (const struct gdb_exception_error &except)
 	{
 	  gdbpy_convert_exception (except);
 	  success = EXT_LANG_BT_ERROR;
diff --git a/gdb/python/py-gdb-readline.c b/gdb/python/py-gdb-readline.c
index 6fefc470df9..c4764b7ac65 100644
--- a/gdb/python/py-gdb-readline.c
+++ b/gdb/python/py-gdb-readline.c
@@ -44,7 +44,7 @@ gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout,
       p = command_line_input (prompt, "python");
     }
   /* Handle errors by raising Python exceptions.  */
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       /* Detect user interrupt (Ctrl-C).  */
       if (except.reason == RETURN_QUIT)
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 082c7b1aeec..602ebbe3a99 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -393,7 +393,7 @@ infpy_threads (PyObject *self, PyObject *args)
     {
       update_thread_list ();
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -513,7 +513,7 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
 
       read_memory (addr, buffer.get (), length);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -574,7 +574,7 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
     {
       write_memory_with_notification (addr, buffer, length);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       except = ex;
     }
@@ -728,7 +728,7 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
 				    buffer, pattern_size,
 				    &found_addr);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       except = ex;
     }
@@ -787,7 +787,7 @@ infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw)
       if (thread_info != NULL)
 	return thread_to_thread_object (thread_info).release ();
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index 66a3b3ef014..99ac6b03e61 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -185,7 +185,7 @@ thpy_switch (PyObject *self, PyObject *args)
     {
       switch_to_thread (thread_obj->thread);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c
index 24beac3bb75..7559c75b837 100644
--- a/gdb/python/py-lazy-string.c
+++ b/gdb/python/py-lazy-string.c
@@ -142,7 +142,7 @@ stpy_convert_to_value (PyObject *self, PyObject *args)
 	  break;
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
diff --git a/gdb/python/py-linetable.c b/gdb/python/py-linetable.c
index 9cabec788ba..1a09a497da3 100644
--- a/gdb/python/py-linetable.c
+++ b/gdb/python/py-linetable.c
@@ -168,7 +168,7 @@ ltpy_get_pcs_for_line (PyObject *self, PyObject *args)
     {
       pcs = find_pcs_for_symtab_line (symtab, py_line, &best_entry);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index fc2fefbaea1..be6e93741da 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -134,7 +134,7 @@ objfpy_get_build_id (PyObject *self, void *closure)
     {
       build_id = build_id_bfd_get (objfile->obfd);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -426,7 +426,7 @@ objfpy_add_separate_debug_file (PyObject *self, PyObject *args, PyObject *kw)
 
       symbol_file_add_separate (abfd.get (), file_name, 0, obj->objfile);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index b6da0d102e2..0074546d902 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -733,7 +733,7 @@ parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
 			   set_doc.get (), show_doc.get (),
 			   doc.get (), set_list, show_list);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       xfree (cmd_name);
       Py_DECREF (self);
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index 09e7dcf8ed4..63f0d9173b3 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -212,7 +212,7 @@ pretty_print_one_value (PyObject *printer, struct value **out_value)
 	    }
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
     }
 
@@ -645,7 +645,7 @@ gdbpy_get_varobj_pretty_printer (struct value *value)
     {
       value = value_copy (value);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c
index 58440e9b26a..bea614a69c6 100644
--- a/gdb/python/py-progspace.c
+++ b/gdb/python/py-progspace.c
@@ -391,7 +391,7 @@ pspy_block_for_pc (PyObject *o, PyObject *args)
       if (cust != NULL && COMPUNIT_OBJFILE (cust) != NULL)
 	block = block_for_pc (pc);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -436,7 +436,7 @@ pspy_find_pc_line (PyObject *o, PyObject *args)
       sal = find_pc_line (pc, 0);
       result = symtab_and_line_to_sal_object (sal);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c
index 10509885a5a..4cfefce59da 100644
--- a/gdb/python/py-record-btrace.c
+++ b/gdb/python/py-record-btrace.c
@@ -212,7 +212,7 @@ recpy_bt_insn_sal (PyObject *self, void *closure)
     {
       result = symtab_and_line_to_sal_object (find_pc_line (insn->pc, 0));
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -283,7 +283,7 @@ recpy_bt_insn_data (PyObject *self, void *closure)
       buffer.resize (insn->size);
       read_memory (insn->pc, buffer.data (), insn->size);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -318,7 +318,7 @@ recpy_bt_insn_decoded (PyObject *self, void *closure)
     {
       gdb_print_insn (target_gdbarch (), insn->pc, &strfile, NULL);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       gdbpy_convert_exception (except);
       return NULL;
@@ -795,7 +795,7 @@ recpy_bt_goto (PyObject *self, PyObject *args)
       else
 	target_goto_record (obj->number);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
diff --git a/gdb/python/py-record.c b/gdb/python/py-record.c
index ee4a32f4aeb..05c24e540c4 100644
--- a/gdb/python/py-record.c
+++ b/gdb/python/py-record.c
@@ -607,7 +607,7 @@ gdbpy_start_recording (PyObject *self, PyObject *args)
       record_start (method, format, 0);
       ret = gdbpy_current_recording (self, args);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       gdbpy_convert_exception (except);
     }
@@ -641,7 +641,7 @@ gdbpy_stop_recording (PyObject *self, PyObject *args)
     {
       record_stop (0);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index 3ec526ad7bc..7b4b51b566b 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -200,7 +200,7 @@ sympy_needs_frame (PyObject *self, void *closure)
     {
       result = symbol_read_needs_frame (symbol);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -283,7 +283,7 @@ sympy_value (PyObject *self, PyObject *args)
 	 can happen with nested functions).  */
       value = read_var_value (symbol, NULL, frame_info);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -391,7 +391,7 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
 	  selected_frame = get_selected_frame (_("No frame selected."));
 	  block = get_frame_block (selected_frame, NULL);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+      catch (const struct gdb_exception &except)
 	{
 	  GDB_PY_HANDLE_EXCEPTION (except);
 	}
@@ -402,7 +402,7 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
       symbol = lookup_symbol (name, block, (domain_enum) domain,
 			      &is_a_field_of_this).symbol;
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -451,7 +451,7 @@ gdbpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw)
     {
       symbol = lookup_global_symbol (name, NULL, (domain_enum) domain).symbol;
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 27c8126827e..effbddb4c88 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -316,7 +316,7 @@ typy_fields_items (PyObject *self, enum gdbpy_iter_kind kind)
     {
       checked_type = check_typedef (checked_type);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -423,7 +423,7 @@ typy_strip_typedefs (PyObject *self, PyObject *args)
     {
       type = check_typedef (type);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -444,7 +444,7 @@ typy_get_composite (struct type *type)
 	{
 	  type = check_typedef (type);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+      catch (const struct gdb_exception &except)
 	{
 	  GDB_PY_HANDLE_EXCEPTION (except);
 	}
@@ -513,7 +513,7 @@ typy_array_1 (PyObject *self, PyObject *args, int is_vector)
       if (is_vector)
 	make_vector_type (array);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -547,7 +547,7 @@ typy_pointer (PyObject *self, PyObject *args)
     {
       type = lookup_pointer_type (type);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -615,7 +615,7 @@ typy_reference (PyObject *self, PyObject *args)
     {
       type = lookup_lvalue_reference_type (type);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -649,7 +649,7 @@ typy_const (PyObject *self, PyObject *args)
     {
       type = make_cv_type (1, 0, type, NULL);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -667,7 +667,7 @@ typy_volatile (PyObject *self, PyObject *args)
     {
       type = make_cv_type (0, 1, type, NULL);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -685,7 +685,7 @@ typy_unqualified (PyObject *self, PyObject *args)
     {
       type = make_cv_type (0, 0, type, NULL);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -703,7 +703,7 @@ typy_get_sizeof (PyObject *self, void *closure)
     {
       check_typedef (type);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
     }
 
@@ -723,7 +723,7 @@ typy_get_alignof (PyObject *self, void *closure)
     {
       align = type_align (type);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       align = 0;
     }
@@ -750,7 +750,7 @@ typy_lookup_typename (const char *type_name, const struct block *block)
 	type = lookup_typename (python_language, python_gdbarch,
 				type_name, block, 0);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -804,7 +804,7 @@ typy_lookup_type (struct demangle_component *demangled,
 	      break;
 	    }
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+      catch (const struct gdb_exception &except)
 	{
 	  GDB_PY_HANDLE_EXCEPTION (except);
 	}
@@ -846,7 +846,7 @@ typy_legacy_template_argument (struct type *type, const struct block *block,
       /* Note -- this is not thread-safe.  */
       info = cp_demangled_name_to_comp (TYPE_NAME (type), &err);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -926,7 +926,7 @@ typy_template_argument (PyObject *self, PyObject *args)
       if (TYPE_IS_REFERENCE (type))
 	type = check_typedef (TYPE_TARGET_TYPE (type));
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -958,7 +958,7 @@ typy_template_argument (PyObject *self, PyObject *args)
     {
       val = value_of_variable (sym, block);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -976,7 +976,7 @@ typy_str (PyObject *self)
       LA_PRINT_TYPE (type_object_to_type (self), "", &thetype, -1, 0,
 		     &type_print_raw_options);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -1010,7 +1010,7 @@ typy_richcompare (PyObject *self, PyObject *other, int op)
 	{
 	  result = types_deeply_equal (type1, type2);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+      catch (const struct gdb_exception &except)
 	{
 	  /* If there is a GDB exception, a comparison is not capable
 	     (or trusted), so exit.  */
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index 135863cd417..c6d48181d7d 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -150,7 +150,7 @@ pyuw_value_obj_to_pointer (PyObject *pyo_value, CORE_ADDR *addr)
           rc = 1;
         }
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       gdbpy_convert_exception (except);
     }
@@ -215,7 +215,7 @@ unwind_infopy_str (PyObject *self)
                 value_print (value, &stb, &opts);
                 stb.puts (")");
               }
-            catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+            catch (const struct gdb_exception &except)
               {
                 GDB_PY_HANDLE_EXCEPTION (except);
               }
@@ -349,7 +349,7 @@ pending_framepy_str (PyObject *self)
       sp_str = core_addr_to_string_nz (get_frame_sp (frame));
       pc_str = core_addr_to_string_nz (get_frame_pc (frame));
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -395,7 +395,7 @@ pending_framepy_read_register (PyObject *self, PyObject *args)
                       "Cannot read register %d from frame.",
                       regnum);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index 4e510c97a0d..ab733ae3b19 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -265,7 +265,7 @@ get_addr_from_python (PyObject *obj, CORE_ADDR *addr)
 	{
 	  *addr = value_as_address (value_object_to_value (obj));
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+      catch (const struct gdb_exception &except)
 	{
 	  GDB_PY_SET_HANDLE_EXCEPTION (except);
 	}
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 44231ee92d8..88fd6c85372 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -224,7 +224,7 @@ valpy_dereference (PyObject *self, PyObject *args)
       res_val = value_ind (((value_object *) self)->value);
       result = value_to_value_object (res_val);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -267,7 +267,7 @@ valpy_referenced_value (PyObject *self, PyObject *args)
 
       result = value_to_value_object (res_val);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -290,7 +290,7 @@ valpy_reference_value (PyObject *self, PyObject *args, enum type_code refcode)
       self_val = ((value_object *) self)->value;
       result = value_to_value_object (value_ref (self_val, refcode));
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -326,7 +326,7 @@ valpy_const_value (PyObject *self, PyObject *args)
       res_val = make_cv_value (1, 0, self_val);
       result = value_to_value_object (res_val);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -350,7 +350,7 @@ valpy_get_address (PyObject *self, void *closure)
 	  res_val = value_addr (val_obj->value);
 	  val_obj->address = value_to_value_object (res_val);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+      catch (const struct gdb_exception &except)
 	{
 	  val_obj->address = Py_None;
 	  Py_INCREF (Py_None);
@@ -428,7 +428,7 @@ valpy_get_dynamic_type (PyObject *self, void *closure)
 	  type = NULL;
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -534,7 +534,7 @@ valpy_lazy_string (PyObject *self, PyObject *args, PyObject *kw)
       str_obj = gdbpy_create_lazy_string_object (addr, length, user_encoding,
 						 type);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -569,7 +569,7 @@ valpy_string (PyObject *self, PyObject *args, PyObject *kw)
     {
       LA_GET_STRING (value, &buffer, &length, &char_type, &la_encoding);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -617,7 +617,7 @@ valpy_do_cast (PyObject *self, PyObject *args, enum exp_opcode op)
 
       result = value_to_value_object (res_val);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -695,7 +695,7 @@ value_has_field (struct value *v, PyObject *field)
       else
 	has_field = 0;
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_SET_HANDLE_EXCEPTION (except);
     }
@@ -873,7 +873,7 @@ valpy_getitem (PyObject *self, PyObject *key)
       if (res_val)
 	result = value_to_value_object (res_val);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       except = ex;
     }
@@ -906,7 +906,7 @@ valpy_call (PyObject *self, PyObject *args, PyObject *keywords)
     {
       ftype = check_typedef (value_type (function));
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -953,7 +953,7 @@ valpy_call (PyObject *self, PyObject *args, PyObject *keywords)
 				 gdb::make_array_view (vargs, args_count));
       result = value_to_value_object (return_value);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -978,7 +978,7 @@ valpy_str (PyObject *self)
       common_val_print (((value_object *) self)->value, &stb, 0,
 			&opts, python_language);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -997,7 +997,7 @@ valpy_get_is_optimized_out (PyObject *self, void *closure)
     {
       opt = value_optimized_out (value);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -1019,7 +1019,7 @@ valpy_get_is_lazy (PyObject *self, void *closure)
     {
       opt = value_lazy (value);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -1041,7 +1041,7 @@ valpy_fetch_lazy (PyObject *self, PyObject *args)
       if (value_lazy (value))
 	value_fetch_lazy (value);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -1212,7 +1212,7 @@ valpy_binop (enum valpy_opcode opcode, PyObject *self, PyObject *other)
     {
       result = valpy_binop_throw (opcode, self, other);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -1280,7 +1280,7 @@ valpy_negative (PyObject *self)
       val = value_neg (((value_object *) self)->value);
       result = value_to_value_object (val);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -1307,7 +1307,7 @@ valpy_absolute (PyObject *self)
       if (value_less (value, value_zero (value_type (value), not_lval)))
 	isabs = 0;
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -1340,7 +1340,7 @@ valpy_nonzero (PyObject *self)
 	/* All other values are True.  */
 	nonzero = 1;
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       except = ex;
     }
@@ -1363,7 +1363,7 @@ valpy_invert (PyObject *self)
     {
       val = value_complement (((value_object *) self)->value);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -1490,7 +1490,7 @@ valpy_richcompare (PyObject *self, PyObject *other, int op)
     {
       result = valpy_richcompare_throw (self, other, op);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -1528,7 +1528,7 @@ valpy_int (PyObject *self)
 
       l = value_as_long (value);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -1564,7 +1564,7 @@ valpy_long (PyObject *self)
 
       l = value_as_long (value);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -1599,7 +1599,7 @@ valpy_float (PyObject *self)
       else
 	error (_("Cannot convert value to float."));
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -1746,7 +1746,7 @@ convert_value_from_python (PyObject *obj)
 		      PyString_AsString (PyObject_Str (obj)));
 #endif
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       gdbpy_convert_exception (except);
       return NULL;
@@ -1769,7 +1769,7 @@ gdbpy_history (PyObject *self, PyObject *args)
     {
       res_val = access_value_history (i);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -1798,7 +1798,7 @@ gdbpy_convenience_variable (PyObject *self, PyObject *args)
 	    res_val = NULL;
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -1844,7 +1844,7 @@ gdbpy_set_convenience_variable (PyObject *self, PyObject *args)
 	  set_internalvar (var, value);
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
diff --git a/gdb/python/python.c b/gdb/python/python.c
index a923794bccd..ff03f85a60a 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -501,7 +501,7 @@ gdbpy_parameter (PyObject *self, PyObject *args)
     {
       found = lookup_cmd_composition (newarg.c_str (), &alias, &prefix, &cmd);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       GDB_PY_HANDLE_EXCEPTION (ex);
     }
@@ -614,7 +614,7 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
       /* Do any commands attached to breakpoint we stopped at.  */
       bpstat_do_actions ();
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -842,7 +842,7 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
 	  sals = def_sal;
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       /* We know this will always throw.  */
       gdbpy_convert_exception (ex);
@@ -900,7 +900,7 @@ gdbpy_parse_and_eval (PyObject *self, PyObject *args)
       gdbpy_allow_threads allow_threads;
       result = parse_and_eval (expr_str);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -1150,7 +1150,7 @@ gdbpy_write (PyObject *self, PyObject *args, PyObject *kw)
           fprintf_filtered (gdb_stdout, "%s", arg);
         }
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -1223,7 +1223,7 @@ gdbpy_print_stack (void)
 	{
 	  begin_line ();
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+      catch (const struct gdb_exception &except)
 	{
 	}
     }
@@ -1254,7 +1254,7 @@ gdbpy_print_stack (void)
 	    fprintf_filtered (gdb_stderr, "Python Exception %s %s: \n",
 			      type.get (), msg.get ());
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+      catch (const struct gdb_exception &except)
 	{
 	}
     }
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index 8fa1b58feaf..ec45cb4aada 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -286,7 +286,7 @@ record_btrace_enable_warn (struct thread_info *tp)
     {
       btrace_enable (tp, &record_btrace_conf);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &error)
+  catch (const struct gdb_exception_error &error)
     {
       warning ("%s", error.message.c_str ());
     }
@@ -1481,7 +1481,7 @@ record_btrace_target::insert_breakpoint (struct gdbarch *gdbarch,
     {
       ret = this->beneath ()->insert_breakpoint (gdbarch, bp_tgt);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       replay_memory_access = old;
       throw_exception (except);
@@ -1511,7 +1511,7 @@ record_btrace_target::remove_breakpoint (struct gdbarch *gdbarch,
     {
       ret = this->beneath ()->remove_breakpoint (gdbarch, bp_tgt, reason);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       replay_memory_access = old;
       throw_exception (except);
@@ -1987,7 +1987,7 @@ get_thread_current_frame_id (struct thread_info *tp)
     {
       id = get_frame_id (get_current_frame ());
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       /* Restore the previous execution state.  */
       set_executing (inferior_ptid, executing);
@@ -2066,7 +2066,7 @@ record_btrace_start_replaying (struct thread_info *tp)
       if (upd_step_stack_frame_id)
 	tp->control.step_stack_frame_id = frame_id;
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
       xfree (btinfo->replay);
       btinfo->replay = NULL;
@@ -2891,7 +2891,7 @@ cmd_record_btrace_bts_start (const char *args, int from_tty)
     {
       execute_command ("target record-btrace", from_tty);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
+  catch (const struct gdb_exception &exception)
     {
       record_btrace_conf.format = BTRACE_FORMAT_NONE;
       throw_exception (exception);
@@ -2912,7 +2912,7 @@ cmd_record_btrace_pt_start (const char *args, int from_tty)
     {
       execute_command ("target record-btrace", from_tty);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
+  catch (const struct gdb_exception &exception)
     {
       record_btrace_conf.format = BTRACE_FORMAT_NONE;
       throw_exception (exception);
@@ -2933,7 +2933,7 @@ cmd_record_btrace_start (const char *args, int from_tty)
     {
       execute_command ("target record-btrace", from_tty);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
+  catch (const struct gdb_exception &exception)
     {
       record_btrace_conf.format = BTRACE_FORMAT_BTS;
 
@@ -2941,7 +2941,7 @@ cmd_record_btrace_start (const char *args, int from_tty)
 	{
 	  execute_command ("target record-btrace", from_tty);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+      catch (const struct gdb_exception &ex)
 	{
 	  record_btrace_conf.format = BTRACE_FORMAT_NONE;
 	  throw_exception (ex);
diff --git a/gdb/record-full.c b/gdb/record-full.c
index c6d63354dd7..6b68e51ded5 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -761,7 +761,7 @@ record_full_message (struct regcache *regcache, enum gdb_signal signal)
       if (ret < 0)
 	error (_("Process record: failed to record execution log."));
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       record_full_list_release (record_full_arch_list_tail);
       throw_exception (ex);
@@ -785,7 +785,7 @@ record_full_message_wrapper_safe (struct regcache *regcache,
     {
       record_full_message (regcache, signal);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       exception_print (gdb_stderr, ex);
       return false;
@@ -1434,7 +1434,7 @@ record_full_wait_1 (struct target_ops *ops,
 	  else
 	    status->value.sig = GDB_SIGNAL_TRAP;
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+      catch (const struct gdb_exception &ex)
 	{
 	  if (execution_direction == EXEC_REVERSE)
 	    {
@@ -2473,7 +2473,7 @@ record_full_restore (void)
 	  record_full_arch_list_add (rec);
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       record_full_list_release (record_full_arch_list_tail);
       throw_exception (ex);
diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c
index 2e2dc157599..2040f85dd9a 100644
--- a/gdb/remote-fileio.c
+++ b/gdb/remote-fileio.c
@@ -1189,7 +1189,7 @@ remote_fileio_request (remote_target *remote, char *buf, int ctrlc_pending_p)
 	{
 	  do_remote_fileio_request (remote, buf);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+      catch (const struct gdb_exception &ex)
 	{
 	  if (ex.reason == RETURN_QUIT)
 	    remote_fileio_reply (remote, -1, FILEIO_EINTR);
diff --git a/gdb/remote.c b/gdb/remote.c
index ed4cdd9e22a..c4d384f9bb7 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -1151,7 +1151,7 @@ remote_target::remote_get_noisy_reply ()
 	      gdbarch_relocate_instruction (target_gdbarch (), &to, from);
 	      relocated = 1;
 	    }
-	  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+	  catch (const struct gdb_exception &ex)
 	    {
 	      if (ex.error == MEMORY_ERROR)
 		{
@@ -5603,7 +5603,7 @@ remote_target::open_1 (const char *name, int from_tty, int extended_p)
       {
 	remote->start_remote (from_tty, extended_p);
       }
-    catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+    catch (const struct gdb_exception &ex)
       {
 	/* Pop the partially set up target - unless something else did
 	   already before throwing the exception.  */
@@ -9768,7 +9768,7 @@ remote_target::remote_kill_k ()
     {
       putpkt ("k");
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error == TARGET_CLOSE_ERROR)
 	{
@@ -13143,7 +13143,7 @@ remote_target::get_trace_status (struct trace_status *ts)
     {
       p = remote_get_noisy_reply ();
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != TARGET_CLOSE_ERROR)
 	{
@@ -13797,7 +13797,7 @@ remote_target::enable_btrace (ptid_t ptid, const struct btrace_config *conf)
     {
       btrace_read_config (&tinfo->conf);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &err)
+  catch (const struct gdb_exception_error &err)
     {
       if (!err.message.empty ())
 	warning ("%s", err.message.c_str ());
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index e23e0814201..691dd2deb9d 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -656,7 +656,7 @@ riscv_print_one_register_info (struct gdbarch *gdbarch,
       val = value_of_register (regnum, frame);
       regtype = value_type (val);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       /* Handle failure to read a register without interrupting the entire
          'info registers' flow.  */
@@ -2806,7 +2806,7 @@ riscv_frame_this_id (struct frame_info *this_frame,
       cache = riscv_frame_cache (this_frame, prologue_cache);
       *this_id = cache->this_id;
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       /* Ignore errors, this leaves the frame id as the predefined outer
          frame id which terminates the backtrace at this point.  */
diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c
index 05055a4a872..7303c2a95f2 100644
--- a/gdb/rs6000-aix-tdep.c
+++ b/gdb/rs6000-aix-tdep.c
@@ -674,7 +674,7 @@ rs6000_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
         {
           pc = read_memory_unsigned_integer (addr, tdep->wordsize, byte_order);
         }
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+      catch (const struct gdb_exception_error &e)
         {
           /* An error occured during reading.  Probably a memory error
              due to the section not being loaded yet.  This address
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index 4213438c841..5fc841d630b 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -3468,7 +3468,7 @@ rs6000_frame_cache (struct frame_info *this_frame, void **this_cache)
       cache->base = get_frame_register_unsigned
 	(this_frame, gdbarch_sp_regnum (gdbarch));
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
@@ -3697,7 +3697,7 @@ rs6000_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
       trad_frame_set_value (cache->saved_regs,
 			    gdbarch_pc_regnum (gdbarch), lr);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
index 97c1b5edd2d..b266bc3696e 100644
--- a/gdb/rust-exp.y
+++ b/gdb/rust-exp.y
@@ -2602,7 +2602,7 @@ rust_lex_exception_test (rust_parser *parser, const char *input,
       rust_lex_test_one (parser, input, DECIMAL_INTEGER);
       SELF_CHECK (0);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
       SELF_CHECK (except.message == err);
     }
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 228684a6cc5..6f69a8ea525 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1748,7 +1748,7 @@ tuple structs, and tuple-like enum variants"));
 		result = value_struct_elt (&lhs, NULL, field_name,
 					   NULL, "structure");
 	      }
-	    catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+	    catch (const struct gdb_exception_error &except)
 	      {
 		error (_("Could not find field %s of struct variant %s::%s"),
 		       field_name, TYPE_NAME (outer_type),
diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
index 09946a9e531..2bef8293d96 100644
--- a/gdb/s390-tdep.c
+++ b/gdb/s390-tdep.c
@@ -2554,7 +2554,7 @@ s390_frame_unwind_cache (struct frame_info *this_frame,
       if (!s390_prologue_frame_unwind_cache (this_frame, info))
 	s390_backchain_frame_unwind_cache (this_frame, info);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
diff --git a/gdb/selftest-arch.c b/gdb/selftest-arch.c
index 063ff8d74fa..6a7688b8f26 100644
--- a/gdb/selftest-arch.c
+++ b/gdb/selftest-arch.c
@@ -72,7 +72,7 @@ struct gdbarch_selftest : public selftest
 
 	    function (gdbarch);
 	  }
-	catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+	catch (const struct gdb_exception_error &ex)
 	  {
 	    pass = false;
 	    exception_fprintf (gdb_stderr, ex,
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 9b7f3ecb382..a78417edbe1 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -834,7 +834,7 @@ enable_break (void)
 	{
 	  tmp_bfd = solib_bfd_open (buf);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+      catch (const struct gdb_exception &ex)
 	{
 	}
 
diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
index 70a9f5fdba6..036f905fd6c 100644
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -565,7 +565,7 @@ enable_break2 (void)
         {
           tmp_bfd = solib_bfd_open (buf);
         }
-      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+      catch (const struct gdb_exception &ex)
 	{
 	}
 
diff --git a/gdb/solib-spu.c b/gdb/solib-spu.c
index a36f84b5a72..31b66fa52d5 100644
--- a/gdb/solib-spu.c
+++ b/gdb/solib-spu.c
@@ -133,7 +133,7 @@ append_ocl_sos (struct so_list **link_ptr)
 		  link_ptr = &newobj->next;
 		}
 	    }
-	  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+	  catch (const struct gdb_exception &ex)
 	    {
 	      /* Ignore memory errors.  */
 	      switch (ex.error)
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index e25618d1f26..a1a782e37ad 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -874,7 +874,7 @@ solib_svr4_r_map (struct svr4_info *info)
       addr = read_memory_typed_address (info->debug_base + lmo->r_map_offset,
                                         ptr_type);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       exception_print (gdb_stderr, ex);
     }
@@ -913,7 +913,7 @@ solib_svr4_r_ldsomap (struct svr4_info *info)
 	= read_memory_unsigned_integer (info->debug_base + lmo->r_version_offset,
 					lmo->r_version_size, byte_order);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       exception_print (gdb_stderr, ex);
     }
@@ -1729,7 +1729,7 @@ solib_event_probe_action (struct probe_and_action *pa)
     {
       probe_argc = pa->prob->get_argument_count (frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       exception_print (gdb_stderr, ex);
       probe_argc = 0;
@@ -1892,7 +1892,7 @@ svr4_handle_solib_event (void)
       {
 	val = pa->prob->evaluate_argument (1, frame);
       }
-    catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+    catch (const struct gdb_exception_error &ex)
       {
 	exception_print (gdb_stderr, ex);
 	val = NULL;
@@ -1923,7 +1923,7 @@ svr4_handle_solib_event (void)
 	  {
 	    val = pa->prob->evaluate_argument (2, frame);
 	  }
-	catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+	catch (const struct gdb_exception_error &ex)
 	  {
 	    exception_print (gdb_stderr, ex);
 	    return;
@@ -2273,7 +2273,7 @@ enable_break (struct svr4_info *info, int from_tty)
         {
 	  tmp_bfd = solib_bfd_open (interp_name);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+      catch (const struct gdb_exception &ex)
 	{
 	}
 
diff --git a/gdb/solib.c b/gdb/solib.c
index 37c218e18eb..998e2f7efbb 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -700,7 +700,7 @@ solib_read_symbols (struct so_list *so, symfile_add_flags flags)
 
 	  so->symbols_loaded = 1;
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+      catch (const struct gdb_exception_error &e)
 	{
 	  exception_fprintf (gdb_stderr, e, _("Error while reading shared"
 					      " library symbols for %s:\n"),
@@ -751,7 +751,7 @@ update_solib_list (int from_tty)
 	    {
 	      ops->open_symbol_file_object (from_tty);
 	    }
-	  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+	  catch (const struct gdb_exception &ex)
 	    {
 	      exception_fprintf (gdb_stderr, ex,
 				 "Error reading attached "
@@ -877,7 +877,7 @@ update_solib_list (int from_tty)
 		}
 	    }
 
-	  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+	  catch (const struct gdb_exception_error &e)
 	    {
 	      exception_fprintf (gdb_stderr, e,
 				 _("Error while mapping shared "
@@ -1335,7 +1335,7 @@ reload_shared_libraries_1 (int from_tty)
 	      solib_map_sections (so);
 	    }
 
-	  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+	  catch (const struct gdb_exception_error &e)
 	    {
 	      exception_fprintf (gdb_stderr, e,
 				 _("Error while mapping "
diff --git a/gdb/sparc64-linux-tdep.c b/gdb/sparc64-linux-tdep.c
index 551a26d816b..ef49244a549 100644
--- a/gdb/sparc64-linux-tdep.c
+++ b/gdb/sparc64-linux-tdep.c
@@ -138,7 +138,7 @@ sparc64_linux_handle_segmentation_fault (struct gdbarch *gdbarch,
       if (si_code >= SEGV_ACCADI && si_code <= SEGV_ADIPERR)
         addr = parse_and_eval_long ("$_siginfo._sifields._sigfault.si_addr");
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
+  catch (const struct gdb_exception &exception)
     {
       return;
     }
diff --git a/gdb/stack.c b/gdb/stack.c
index 056ce716810..0f8f4369043 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -182,7 +182,7 @@ print_stack_frame (struct frame_info *frame, int print_level,
       if (set_current_sal)
 	set_current_sal_from_frame (frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+  catch (const struct gdb_exception_error &e)
     {
     }
 }
@@ -296,7 +296,7 @@ print_frame_arg (const struct frame_arg *arg)
 
 	      common_val_print (arg->val, &stb, 2, &opts, language);
 	    }
-	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+	  catch (const struct gdb_exception_error &except)
 	    {
 	      error_message = std::move (except.message);
 	    }
@@ -324,7 +324,7 @@ read_frame_local (struct symbol *sym, struct frame_info *frame,
     {
       argp->val = read_var_value (sym, NULL, frame);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
       argp->error = xstrdup (except.message.c_str ());
     }
@@ -349,7 +349,7 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame,
 	{
 	  val = read_var_value (sym, NULL, frame);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+      catch (const struct gdb_exception_error &except)
 	{
 	  val_error = (char *) alloca (except.message.size () + 1);
 	  strcpy (val_error, except.message.c_str ());
@@ -369,7 +369,7 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame,
 	  ops = SYMBOL_COMPUTED_OPS (sym);
 	  entryval = ops->read_variable_at_entry (sym, frame);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+      catch (const struct gdb_exception_error &except)
 	{
 	  if (except.error != NO_ENTRY_VALUE_ERROR)
 	    {
@@ -425,7 +425,7 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame,
 						TYPE_LENGTH (type_deref)))
 			val_equal = 1;
 		    }
-		  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+		  catch (const struct gdb_exception_error &except)
 		    {
 		      /* If the dereferenced content could not be
 			 fetched do not display anything.  */
@@ -473,7 +473,7 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame,
 	    {
 	      val = read_var_value (sym, NULL, frame);
 	    }
-	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+	  catch (const struct gdb_exception_error &except)
 	    {
 	      val_error = (char *) alloca (except.message.size () + 1);
 	      strcpy (val_error, except.message.c_str ());
@@ -760,7 +760,7 @@ do_gdb_disassembly (struct gdbarch *gdbarch,
 		       DISASSEMBLY_RAW_INSN, how_many,
 		       low, high);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &exception)
+  catch (const struct gdb_exception_error &exception)
     {
       /* If an exception was thrown while doing the disassembly, print
 	 the error message, to give the user a clue of what happened.  */
@@ -1202,7 +1202,7 @@ print_frame (struct frame_info *frame, int print_level,
 	    {
 	      print_frame_args (func, frame, numargs, gdb_stdout);
 	    }
-	  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
+	  catch (const struct gdb_exception_error &e)
 	    {
 	    }
 
@@ -1391,7 +1391,7 @@ info_frame_command_core (struct frame_info *fi, bool selected_frame_p)
 	  caller_pc = frame_unwind_caller_pc (fi);
 	  caller_pc_p = 1;
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+      catch (const struct gdb_exception_error &ex)
 	{
 	  switch (ex.error)
 	    {
@@ -2706,7 +2706,7 @@ frame_apply_command_count (const char *which_command,
 	      printf_filtered ("%s", cmd_result.c_str ());
 	    }
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+      catch (const struct gdb_exception_error &ex)
 	{
 	  fi = get_selected_frame (_("frame apply "
 				     "unable to get selected frame."));
diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c
index 5287e280a91..04b0bdd477d 100644
--- a/gdb/symfile-mem.c
+++ b/gdb/symfile-mem.c
@@ -198,7 +198,7 @@ add_vsyscall_page (struct target_ops *target, int from_tty)
 				       name,
 				       0 /* from_tty */);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+      catch (const struct gdb_exception &ex)
 	{
 	  exception_print (gdb_stderr, ex);
 	}
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 2efa447733d..9025217a106 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -356,7 +356,7 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
 		{
 		  print_symbol (gdbarch, sym, depth + 1, outfile);
 		}
-	      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+	      catch (const struct gdb_exception_error &ex)
 		{
 		  exception_fprintf (gdb_stderr, ex,
 				     "Error printing symbol:\n");
diff --git a/gdb/target.c b/gdb/target.c
index ccad0031458..605383eeee8 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -717,7 +717,7 @@ target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset)
 	}
       /* If an error occurred, print TLS related messages here.  Otherwise,
          throw the error to some higher catcher.  */
-      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+      catch (const struct gdb_exception &ex)
 	{
 	  int objfile_is_library = (objfile->flags & OBJF_SHARED);
 
diff --git a/gdb/thread.c b/gdb/thread.c
index c1928c25402..2b84facbc27 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -1470,7 +1470,7 @@ thr_try_catch_cmd (thread_info *thr, const char *cmd, int from_tty,
 	  printf_filtered ("%s", cmd_result.c_str ());
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       if (!flags.silent)
 	{
diff --git a/gdb/top.c b/gdb/top.c
index 285927f5712..6bffea93764 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1625,7 +1625,7 @@ quit_force (int *exit_arg, int from_tty)
       disconnect_tracing ();
       iterate_over_inferiors (kill_or_detach, &qt);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       exception_print (gdb_stderr, ex);
     }
@@ -1636,7 +1636,7 @@ quit_force (int *exit_arg, int from_tty)
     {
       pop_all_targets ();
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       exception_print (gdb_stderr, ex);
     }
@@ -1664,7 +1664,7 @@ quit_force (int *exit_arg, int from_tty)
 	    gdb_safe_append_history ();
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       exception_print (gdb_stderr, ex);
     }
@@ -1674,7 +1674,7 @@ quit_force (int *exit_arg, int from_tty)
     {
       do_final_cleanups ();
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       exception_print (gdb_stderr, ex);
     }
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index 53e85fc13f5..95cd831a30d 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -547,7 +547,7 @@ tfile_target_open (const char *arg, int from_tty)
       if (trace_regblock_size == 0)
 	error (_("No register block size recorded in trace file"));
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       /* Remove the partially set up target.  */
       unpush_target (&tfile_ops);
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index 52f6bc39c44..5284751714a 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -110,7 +110,7 @@ tui_rl_switch_mode (int notused1, int notused2)
 	  tui_enable ();
 	}
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       exception_print (gdb_stderr, ex);
 
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index 42d344ea8f6..4dc95229b88 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -419,7 +419,7 @@ type_to_string (struct type *type)
       type_print (type, "", &stb, -1);
       return std::move (stb.string ());
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
+  catch (const struct gdb_exception &except)
     {
     }
 
diff --git a/gdb/unittests/cli-utils-selftests.c b/gdb/unittests/cli-utils-selftests.c
index 7c1d135ecc8..f26a6d1adef 100644
--- a/gdb/unittests/cli-utils-selftests.c
+++ b/gdb/unittests/cli-utils-selftests.c
@@ -83,7 +83,7 @@ test_number_or_range_parser ()
 	minus_one.get_number ();
 	SELF_CHECK (false);
       }
-    catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+    catch (const struct gdb_exception_error &ex)
       {
 	SELF_CHECK (ex.reason == RETURN_ERROR);
 	SELF_CHECK (ex.error == GENERIC_ERROR);
@@ -219,7 +219,7 @@ test_parse_flags_qcs ()
 				&flags);
 	SELF_CHECK (false);
       }
-    catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+    catch (const struct gdb_exception_error &ex)
       {
 	SELF_CHECK (ex.reason == RETURN_ERROR);
 	SELF_CHECK (ex.error == GENERIC_ERROR);
diff --git a/gdb/unittests/parse-connection-spec-selftests.c b/gdb/unittests/parse-connection-spec-selftests.c
index 7376a53d427..de9f7ea287e 100644
--- a/gdb/unittests/parse-connection-spec-selftests.c
+++ b/gdb/unittests/parse-connection-spec-selftests.c
@@ -213,7 +213,7 @@ test_conn (const parse_conn_test &c)
     {
       ret = parse_connection_spec (c.connspec, &hint);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+  catch (const struct gdb_exception_error &ex)
     {
       /* If we caught an error, we should check if this connection
 	 spec was supposed to fail.  */
diff --git a/gdb/valops.c b/gdb/valops.c
index 117b080c70c..d5efbc6abbb 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3625,7 +3625,7 @@ value_rtti_indirect_type (struct value *v, int *full,
         {
 	  target = value_ind (v);
         }
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+      catch (const struct gdb_exception_error &except)
 	{
 	  if (except.error == MEMORY_ERROR)
 	    {
@@ -3777,7 +3777,7 @@ value_of_this_silent (const struct language_defn *lang)
     {
       ret = value_of_this (lang);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
     }
 
diff --git a/gdb/valprint.c b/gdb/valprint.c
index e4e8fbb857b..958c20ec379 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -1062,7 +1062,7 @@ val_print (struct type *type, LONGEST embedded_offset,
 			      stream, recurse, val,
 			      &local_opts);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
       fprintf_filtered (stream, _("<error reading variable>"));
     }
diff --git a/gdb/value.c b/gdb/value.c
index f9e3d65f19d..033eae5a5b9 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1409,7 +1409,7 @@ value_optimized_out (struct value *value)
 	{
 	  value_fetch_lazy (value);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+      catch (const struct gdb_exception_error &ex)
 	{
 	  /* Fall back to checking value->optimized_out.  */
 	}
@@ -2541,7 +2541,7 @@ show_convenience (const char *ignore, int from_tty)
 	  val = value_of_internalvar (gdbarch, var);
 	  value_print (val, gdb_stdout, &opts);
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
+      catch (const struct gdb_exception_error &ex)
 	{
 	  fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message.c_str ());
 	}
diff --git a/gdb/varobj.c b/gdb/varobj.c
index 4dfc816d835..1d2fa96f5f8 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -318,7 +318,7 @@ varobj_create (const char *objname,
 	  var->root->exp = parse_exp_1 (&p, pc, block, 0);
 	}
 
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+      catch (const struct gdb_exception_error &except)
 	{
 	  return NULL;
 	}
@@ -366,7 +366,7 @@ varobj_create (const char *objname,
 	{
 	  value = evaluate_expression (var->root->exp.get ());
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+      catch (const struct gdb_exception_error &except)
 	{
 	  /* Error getting the value.  Try to at least get the
 	     right type.  */
@@ -1036,7 +1036,7 @@ varobj_set_value (struct varobj *var, const char *expression)
       value = evaluate_expression (exp.get ());
     }
 
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
       /* We cannot proceed without a valid expression.  */
       return false;
@@ -1064,7 +1064,7 @@ varobj_set_value (struct varobj *var, const char *expression)
       val = value_assign (var->value.get (), value);
     }
 
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+  catch (const struct gdb_exception_error &except)
     {
       return false;
     }
@@ -1311,7 +1311,7 @@ install_new_value (struct varobj *var, struct value *value, bool initial)
 	      value_fetch_lazy (value);
 	    }
 
-	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+	  catch (const struct gdb_exception_error &except)
 	    {
 	      /* Set the value to NULL, so that for the next -var-update,
 		 we don't try to compare the new value with this value,
@@ -2137,7 +2137,7 @@ value_of_root_1 (struct varobj **var_handle)
 	{
 	  new_val = evaluate_expression (var->root->exp.get ());
 	}
-      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
+      catch (const struct gdb_exception_error &except)
 	{
 	}
     }
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index f15aef0e369..17e0210287f 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -947,7 +947,7 @@ catch_errors (void (*func) ())
     {
       func ();
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       exception_print (gdb_stderr, ex);
     }
diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c
index 2ee93e7f410..94781e85b09 100644
--- a/gdb/x86-linux-nat.c
+++ b/gdb/x86-linux-nat.c
@@ -221,7 +221,7 @@ x86_linux_nat_target::enable_btrace (ptid_t ptid,
     {
       tinfo = linux_enable_btrace (ptid, conf);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ERROR &exception)
+  catch (const struct gdb_exception_error &exception)
     {
       error (_("Could not enable branch tracing for %s: %s"),
 	     target_pid_to_str (ptid), exception.message.c_str ());
diff --git a/gdb/xml-support.c b/gdb/xml-support.c
index 97cafa623d7..e6dfe8e07c4 100644
--- a/gdb/xml-support.c
+++ b/gdb/xml-support.c
@@ -387,7 +387,7 @@ gdb_xml_start_element_wrapper (void *data, const XML_Char *name,
     {
       parser->start_element (name, attrs);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       parser->set_error (ex);
     }
@@ -459,7 +459,7 @@ gdb_xml_end_element_wrapper (void *data, const XML_Char *name)
     {
       parser->end_element (name);
     }
-  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
+  catch (const struct gdb_exception &ex)
     {
       parser->set_error (ex);
     }
-- 
2.17.2

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

* [PATCH v2 21/22] Use SCOPE_EXIT in write_gcore_file
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
                   ` (20 preceding siblings ...)
  2019-02-27 20:19 ` [PATCH v2 12/22] Remove basic cleanup code Tom Tromey
@ 2019-02-27 20:19 ` Tom Tromey
  2019-03-06 22:01   ` Pedro Alves
  21 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This replaces a try/catch in write_gcore_file with a use of SCOPE_EXIT
instead.  I find that this is simpler to understand.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* gcore.c (write_gcore_file): Use SCOPE_EXIT.
---
 gdb/ChangeLog |  4 ++++
 gdb/gcore.c   | 19 +++----------------
 2 files changed, 7 insertions(+), 16 deletions(-)

diff --git a/gdb/gcore.c b/gdb/gcore.c
index 0e4596241b7..21d9ee88671 100644
--- a/gdb/gcore.c
+++ b/gdb/gcore.c
@@ -37,6 +37,7 @@
 #include <algorithm>
 #include "common/gdb_unlinker.h"
 #include "common/byte-vector.h"
+#include "common/scope-exit.h"
 
 /* The largest amount of memory to read from the target at once.  We
    must throttle it to limit the amount of memory used by GDB during
@@ -114,23 +115,9 @@ write_gcore_file_1 (bfd *obfd)
 void
 write_gcore_file (bfd *obfd)
 {
-  struct gdb_exception except = exception_none;
-
   target_prepare_to_generate_core ();
-
-  try
-    {
-      write_gcore_file_1 (obfd);
-    }
-  catch (const struct gdb_exception &e)
-    {
-      except = e;
-    }
-
-  target_done_generating_core ();
-
-  if (except.reason < 0)
-    throw_exception (except);
+  SCOPE_EXIT { target_done_generating_core (); };
+  write_gcore_file_1 (obfd);
 }
 
 /* gcore_command -- implements the 'gcore' command.
-- 
2.17.2

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

* [PATCH v2 11/22] Use unique_xmalloc_ptr in remote.c
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
                   ` (13 preceding siblings ...)
  2019-02-27 20:19 ` [PATCH v2 17/22] Rename gdb exception types Tom Tromey
@ 2019-02-27 20:19 ` Tom Tromey
  2019-03-06 21:17   ` Pedro Alves
  2019-02-27 20:19 ` [PATCH v2 20/22] Replace throw_exception with throw in some cases Tom Tromey
                   ` (6 subsequent siblings)
  21 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes a cleanup from remote.c, replacing it with
unique_xmalloc_ptr.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* remote.c (remote_target::remote_parse_stop_reply): Use
	unique_xmalloc_ptr.
---
 gdb/ChangeLog |  5 +++++
 gdb/remote.c  | 11 +++++------
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/gdb/remote.c b/gdb/remote.c
index f80dcdaee94..5f658deefaa 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -7314,14 +7314,13 @@ Packet: '%s'\n"),
 
 	      /* Save the pathname for event reporting and for
 		 the next run command.  */
-	      char *pathname = (char *) xmalloc (pathlen + 1);
-	      struct cleanup *old_chain = make_cleanup (xfree, pathname);
-	      hex2bin (p1, (gdb_byte *) pathname, pathlen);
-	      pathname[pathlen] = '\0';
-	      discard_cleanups (old_chain);
+	      gdb::unique_xmalloc_ptr<char> pathname
+		((char *) xmalloc (pathlen + 1));
+	      hex2bin (p1, (gdb_byte *) pathname.get (), pathlen);
+	      pathname.get ()[pathlen] = '\0';
 
 	      /* This is freed during event handling.  */
-	      event->ws.value.execd_pathname = pathname;
+	      event->ws.value.execd_pathname = pathname.release ();
 	      event->ws.kind = TARGET_WAITKIND_EXECD;
 
 	      /* Skip the registers included in this packet, since
-- 
2.17.2

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

* [PATCH v2 06/22] Remove cleanup from solib-svr4.c
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
                   ` (17 preceding siblings ...)
  2019-02-27 20:19 ` [PATCH v2 18/22] Remove some now-dead exception code Tom Tromey
@ 2019-02-27 20:19 ` Tom Tromey
  2019-03-06 19:24   ` Pedro Alves
  2019-02-27 20:19 ` [PATCH v2 10/22] Remove last cleanups from stabsread.c Tom Tromey
                   ` (2 subsequent siblings)
  21 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes a cleanup from solib-svr4.c, replacing it with
make_scope_exit.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* solib-svr4.c (disable_probes_interface): Remove parameter.
	(svr4_handle_solib_event): Use make_scope_exit.
---
 gdb/ChangeLog    |  5 +++++
 gdb/solib-svr4.c | 40 ++++++++++------------------------------
 2 files changed, 15 insertions(+), 30 deletions(-)

diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 787b98ba266..2b370ef96d0 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -1826,7 +1826,7 @@ solist_update_incremental (struct svr4_info *info, CORE_ADDR lm)
    ones set up for the probes-based interface are adequate.  */
 
 static void
-disable_probes_interface_cleanup (void *arg)
+disable_probes_interface ()
 {
   struct svr4_info *info = get_svr4_info ();
 
@@ -1847,7 +1847,6 @@ svr4_handle_solib_event (void)
   struct svr4_info *info = get_svr4_info ();
   struct probe_and_action *pa;
   enum probe_action action;
-  struct cleanup *old_chain;
   struct value *val = NULL;
   CORE_ADDR pc, debug_base, lm = 0;
   struct frame_info *frame = get_current_frame ();
@@ -1858,26 +1857,20 @@ svr4_handle_solib_event (void)
 
   /* If anything goes wrong we revert to the original linker
      interface.  */
-  old_chain = make_cleanup (disable_probes_interface_cleanup, NULL);
+  auto cleanup = make_scope_exit (disable_probes_interface);
 
   pc = regcache_read_pc (get_current_regcache ());
   pa = solib_event_probe_at (info, pc);
   if (pa == NULL)
-    {
-      do_cleanups (old_chain);
-      return;
-    }
+    return;
 
   action = solib_event_probe_action (pa);
   if (action == PROBES_INTERFACE_FAILED)
-    {
-      do_cleanups (old_chain);
-      return;
-    }
+    return;
 
   if (action == DO_NOTHING)
     {
-      discard_cleanups (old_chain);
+      cleanup.release ();
       return;
     }
 
@@ -1907,25 +1900,16 @@ svr4_handle_solib_event (void)
     END_CATCH
 
     if (val == NULL)
-      {
-	do_cleanups (old_chain);
-	return;
-      }
+      return;
 
     debug_base = value_as_address (val);
     if (debug_base == 0)
-      {
-	do_cleanups (old_chain);
-	return;
-      }
+      return;
 
     /* Always locate the debug struct, in case it moved.  */
     info->debug_base = 0;
     if (locate_base (info) == 0)
-      {
-	do_cleanups (old_chain);
-	return;
-      }
+      return;
 
     /* GDB does not currently support libraries loaded via dlmopen
        into namespaces other than the initial one.  We must ignore
@@ -1943,7 +1927,6 @@ svr4_handle_solib_event (void)
 	CATCH (ex, RETURN_MASK_ERROR)
 	  {
 	    exception_print (gdb_stderr, ex);
-	    do_cleanups (old_chain);
 	    return;
 	  }
 	END_CATCH
@@ -1968,13 +1951,10 @@ svr4_handle_solib_event (void)
   if (action == FULL_RELOAD)
     {
       if (!solist_update_full (info))
-	{
-	  do_cleanups (old_chain);
-	  return;
-	}
+	return;
     }
 
-  discard_cleanups (old_chain);
+  cleanup.release ();
 }
 
 /* Helper function for svr4_update_solib_event_breakpoints.  */
-- 
2.17.2

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

* [PATCH v2 02/22] Update two cleanup comments
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
                   ` (6 preceding siblings ...)
  2019-02-27 20:19 ` [PATCH v2 22/22] Introduce and use bcache_up Tom Tromey
@ 2019-02-27 20:19 ` Tom Tromey
  2019-03-06 19:23   ` Pedro Alves
  2019-02-27 20:19 ` [PATCH v2 07/22] Remove last cleanups from solib-svr4.c Tom Tromey
                   ` (13 subsequent siblings)
  21 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This updates another couple of comments to remove a mentions of
cleanups.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* inferior.h (class inferior): Update comment.
	* gdbthread.h (class thread_info): Update comment.
---
 gdb/ChangeLog   | 5 +++++
 gdb/gdbthread.h | 2 +-
 gdb/inferior.h  | 2 +-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h
index 3b9d56904d3..2d497d51cf5 100644
--- a/gdb/gdbthread.h
+++ b/gdb/gdbthread.h
@@ -235,7 +235,7 @@ struct private_thread_info
    reverting back (e.g., due to a "kill" command).  If the thread
    meanwhile exits before being re-selected, then the thread object is
    left listed in the thread list, but marked with state
-   THREAD_EXITED.  (See make_cleanup_restore_current_thread and
+   THREAD_EXITED.  (See scoped_restore_current_thread and
    delete_thread).  All other thread references are considered weak
    references.  Placing a thread in the thread list is an implicit
    strong reference, and is thus not accounted for in the thread's
diff --git a/gdb/inferior.h b/gdb/inferior.h
index 2d1bb97a283..f98e67d33f4 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -335,7 +335,7 @@ extern void set_current_inferior (inferior *);
    the inferior object's refcount, to prevent something deleting the
    inferior object before reverting back (e.g., due to a
    "remove-inferiors" command (see
-   make_cleanup_restore_current_thread).  All other inferior
+   scoped_restore_current_inferior).  All other inferior
    references are considered weak references.  Inferiors are always
    listed exactly once in the inferior list, so placing an inferior in
    the inferior list is an implicit, not counted strong reference.  */
-- 
2.17.2

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

* [PATCH v2 07/22] Remove last cleanups from solib-svr4.c
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
                   ` (7 preceding siblings ...)
  2019-02-27 20:19 ` [PATCH v2 02/22] Update two cleanup comments Tom Tromey
@ 2019-02-27 20:19 ` Tom Tromey
  2019-03-06 19:32   ` Pedro Alves
  2019-02-27 20:19 ` [PATCH v2 13/22] Remove free_current_contents Tom Tromey
                   ` (12 subsequent siblings)
  21 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes the last cleanups from solib-svr4.c, replacing them with
uses of make_scope_exit.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* solib-svr4.c (svr4_parse_libraries, svr4_current_sos_direct):
	Use make_scope_exit.
---
 gdb/ChangeLog    |  5 +++++
 gdb/solib-svr4.c | 17 ++++++++++-------
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 2b370ef96d0..2301cf94c2f 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -1198,8 +1198,10 @@ static const struct gdb_xml_element svr4_library_list_elements[] =
 static int
 svr4_parse_libraries (const char *document, struct svr4_library_list *list)
 {
-  struct cleanup *back_to = make_cleanup (svr4_free_library_list,
-					  &list->head);
+  auto cleanup = make_scope_exit ([&] ()
+				  {
+				    svr4_free_library_list (&list->head);
+				  });
 
   memset (list, 0, sizeof (*list));
   list->tailp = &list->head;
@@ -1207,11 +1209,10 @@ svr4_parse_libraries (const char *document, struct svr4_library_list *list)
 			   svr4_library_list_elements, document, list) == 0)
     {
       /* Parsed successfully, keep the result.  */
-      discard_cleanups (back_to);
+      cleanup.release ();
       return 1;
     }
 
-  do_cleanups (back_to);
   return 0;
 }
 
@@ -1374,7 +1375,6 @@ svr4_current_sos_direct (struct svr4_info *info)
   CORE_ADDR lm;
   struct so_list *head = NULL;
   struct so_list **link_ptr = &head;
-  struct cleanup *back_to;
   int ignore_first;
   struct svr4_library_list library_list;
 
@@ -1412,7 +1412,10 @@ svr4_current_sos_direct (struct svr4_info *info)
   else
     ignore_first = 1;
 
-  back_to = make_cleanup (svr4_free_library_list, &head);
+  auto cleanup = make_scope_exit ([&] ()
+				  {
+				    svr4_free_library_list (&head);
+				  });
 
   /* Walk the inferior's link map list, and build our list of
      `struct so_list' nodes.  */
@@ -1428,7 +1431,7 @@ svr4_current_sos_direct (struct svr4_info *info)
   if (lm)
     svr4_read_so_list (lm, 0, &link_ptr, 0);
 
-  discard_cleanups (back_to);
+  cleanup.release ();
 
   if (head == NULL)
     return svr4_default_sos ();
-- 
2.17.2

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

* [PATCH v2 09/22] Remove last cleanup from linux-namespaces.c
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
                   ` (2 preceding siblings ...)
  2019-02-27 20:19 ` [PATCH v2 01/22] Remove cleanups from coffread.c Tom Tromey
@ 2019-02-27 20:19 ` Tom Tromey
  2019-03-06 21:07   ` Pedro Alves
  2019-02-27 20:19 ` [PATCH v2 16/22] Rewrite TRY/CATCH Tom Tromey
                   ` (17 subsequent siblings)
  21 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes the last cleanup from linux-namespaces.c, replacing it
with a use of SCOPE_EXIT.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* nat/linux-namespaces.c (linux_mntns_access_fs): Use SCOPE_EXIT.
	* common/filestuff.h (make_cleanup_close): Don't declare.
	* common/filestuff.c (do_close_cleanup, make_cleanup_close):
	Remove.
---
 gdb/ChangeLog              |  7 +++++++
 gdb/common/filestuff.c     | 21 -------------------
 gdb/common/filestuff.h     |  4 ----
 gdb/nat/linux-namespaces.c | 41 ++++++++++++++------------------------
 4 files changed, 22 insertions(+), 51 deletions(-)

diff --git a/gdb/common/filestuff.c b/gdb/common/filestuff.c
index 0d2fa8d6336..1ca62482a7e 100644
--- a/gdb/common/filestuff.c
+++ b/gdb/common/filestuff.c
@@ -426,27 +426,6 @@ gdb_pipe_cloexec (int filedes[2])
   return result;
 }
 
-/* Helper function which does the work for make_cleanup_close.  */
-
-static void
-do_close_cleanup (void *arg)
-{
-  int *fd = (int *) arg;
-
-  close (*fd);
-}
-
-/* See filestuff.h.  */
-
-struct cleanup *
-make_cleanup_close (int fd)
-{
-  int *saved_fd = XNEW (int);
-
-  *saved_fd = fd;
-  return make_cleanup_dtor (do_close_cleanup, saved_fd, xfree);
-}
-
 /* See common/filestuff.h.  */
 
 bool
diff --git a/gdb/common/filestuff.h b/gdb/common/filestuff.h
index 7e95b9ca2d4..c50781da01c 100644
--- a/gdb/common/filestuff.h
+++ b/gdb/common/filestuff.h
@@ -112,10 +112,6 @@ extern int gdb_socket_cloexec (int domain, int style, int protocol);
 
 extern int gdb_pipe_cloexec (int filedes[2]);
 
-/* Return a new cleanup that closes FD.  */
-
-extern struct cleanup *make_cleanup_close (int fd);
-
 struct gdb_dir_deleter
 {
   void operator() (DIR *dir) const
diff --git a/gdb/nat/linux-namespaces.c b/gdb/nat/linux-namespaces.c
index 812f8c19767..c0f326b9a1e 100644
--- a/gdb/nat/linux-namespaces.c
+++ b/gdb/nat/linux-namespaces.c
@@ -28,6 +28,7 @@
 #include "common/gdb_wait.h"
 #include <signal.h>
 #include <sched.h>
+#include "common/scope-exit.h"
 
 /* See nat/linux-namespaces.h.  */
 int debug_linux_namespaces;
@@ -887,12 +888,11 @@ enum mnsh_fs_code
 static enum mnsh_fs_code
 linux_mntns_access_fs (pid_t pid)
 {
-  struct cleanup *old_chain;
   struct linux_ns *ns;
   struct stat sb;
   struct linux_mnsh *helper;
   ssize_t size;
-  int fd, saved_errno;
+  int fd;
 
   if (pid == getpid ())
     return MNSH_FS_DIRECT;
@@ -901,27 +901,26 @@ linux_mntns_access_fs (pid_t pid)
   if (ns == NULL)
     return MNSH_FS_DIRECT;
 
-  old_chain = make_cleanup (null_cleanup, NULL);
-
   fd = gdb_open_cloexec (linux_ns_filename (ns, pid), O_RDONLY, 0);
   if (fd < 0)
-    goto error;
+    return MNSH_FS_ERROR;
 
-  make_cleanup_close (fd);
+  SCOPE_EXIT
+    {
+      int save_errno = errno;
+      close (fd);
+      errno = save_errno;
+    };
 
   if (fstat (fd, &sb) != 0)
-    goto error;
+    return MNSH_FS_ERROR;
 
   if (sb.st_ino == ns->id)
-    {
-      do_cleanups (old_chain);
-
-      return MNSH_FS_DIRECT;
-    }
+    return MNSH_FS_DIRECT;
 
   helper = linux_mntns_get_helper ();
   if (helper == NULL)
-    goto error;
+    return MNSH_FS_ERROR;
 
   if (sb.st_ino != helper->nsid)
     {
@@ -929,10 +928,10 @@ linux_mntns_access_fs (pid_t pid)
 
       size = mnsh_send_setns (helper, fd, 0);
       if (size < 0)
-	goto error;
+	return MNSH_FS_ERROR;
 
       if (mnsh_recv_int (helper, &result, &error) != 0)
-	goto error;
+	return MNSH_FS_ERROR;
 
       if (result != 0)
 	{
@@ -945,23 +944,13 @@ linux_mntns_access_fs (pid_t pid)
 	    error = ENOTSUP;
 
 	  errno = error;
-	  goto error;
+	  return MNSH_FS_ERROR;
 	}
 
       helper->nsid = sb.st_ino;
     }
 
-  do_cleanups (old_chain);
-
   return MNSH_FS_HELPER;
-
-error:
-  saved_errno = errno;
-
-  do_cleanups (old_chain);
-
-  errno = saved_errno;
-  return MNSH_FS_ERROR;
 }
 
 /* See nat/linux-namespaces.h.  */
-- 
2.17.2

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

* [PATCH v2 12/22] Remove basic cleanup code
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
                   ` (19 preceding siblings ...)
  2019-02-27 20:19 ` [PATCH v2 10/22] Remove last cleanups from stabsread.c Tom Tromey
@ 2019-02-27 20:19 ` Tom Tromey
  2019-03-06 21:33   ` Pedro Alves
  2019-02-27 20:19 ` [PATCH v2 21/22] Use SCOPE_EXIT in write_gcore_file Tom Tromey
  21 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes the basic cleanup code: make_cleanups, do_cleanups,
discard_cleanups, and friends.  This code is no longer needed, as
nothing in gdb makes an ordinary cleanup.  Final cleanups are still
needed.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* top.c (quit_force): Update.
	* main.c (captured_command_loop): Update.
	* common/new-op.c (operator new): Update.
	* common/common-exceptions.c (struct catcher)
	<save_cleanup_chain>: Remove member.
	(exceptions_state_mc_init): Update.
	(exception_try_scope_entry): Return nullptr.
	(exception_try_scope_exit, exception_rethrow)
	(throw_exception_sjlj, throw_exception_cxx): Update.
	* common/cleanups.h (make_cleanup, make_cleanup_dtor)
	(all_cleanups, do_cleanups, discard_cleanups)
	(discard_final_cleanups, save_cleanups, save_final_cleanups)
	(restore_cleanups, restore_final_cleanups): Don't declare.
	(do_final_cleanups): Remove parameter.
	* common/cleanups.c (cleanup_chain, make_cleanup)
	(make_cleanup_dtor, all_cleanups, do_cleanups)
	(discard_my_cleanups, discard_cleanups)
	(discard_final_cleanups, save_my_cleanups, save_cleanups)
	(save_final_cleanups, restore_my_cleanups, restore_cleanups)
	(null_cleanup): Remove.
	(do_final_cleanups): Remove parameter.
---
 gdb/ChangeLog                  |  24 +++++
 gdb/common/cleanups.c          | 160 +--------------------------------
 gdb/common/cleanups.h          |  32 +------
 gdb/common/common-exceptions.c |  20 +----
 gdb/common/new-op.c            |   2 -
 gdb/main.c                     |   8 --
 gdb/top.c                      |   2 +-
 7 files changed, 31 insertions(+), 217 deletions(-)

diff --git a/gdb/common/cleanups.c b/gdb/common/cleanups.c
index 086371a7c96..121720d3c0f 100644
--- a/gdb/common/cleanups.c
+++ b/gdb/common/cleanups.c
@@ -58,10 +58,6 @@ static const struct cleanup sentinel_cleanup = { 0, 0, 0, 0 };
 /* Handy macro to use when referring to sentinel_cleanup.  */
 #define SENTINEL_CLEANUP ((struct cleanup *) &sentinel_cleanup)
 
-/* Chain of cleanup actions established with make_cleanup,
-   to be executed if an error happens.  */
-static struct cleanup *cleanup_chain = SENTINEL_CLEANUP;
-
 /* Chain of cleanup actions established with make_final_cleanup,
    to be executed when gdb exits.  */
 static struct cleanup *final_cleanup_chain = SENTINEL_CLEANUP;
@@ -107,30 +103,11 @@ make_my_cleanup (struct cleanup **pmy_chain, make_cleanup_ftype *function,
   return make_my_cleanup2 (pmy_chain, function, arg, NULL);
 }
 
-/* Add a new cleanup to the cleanup_chain,
+/* Add a new cleanup to the final cleanup_chain,
    and return the previous chain pointer
    to be passed later to do_cleanups or discard_cleanups.
    Args are FUNCTION to clean up with, and ARG to pass to it.  */
 
-struct cleanup *
-make_cleanup (make_cleanup_ftype *function, void *arg)
-{
-  return make_my_cleanup (&cleanup_chain, function, arg);
-}
-
-/* Same as make_cleanup except also includes DTOR, a destructor to free ARG.
-   DTOR is invoked when the cleanup is performed or when it is discarded.  */
-
-struct cleanup *
-make_cleanup_dtor (make_cleanup_ftype *function, void *arg,
-		   make_cleanup_dtor_ftype *dtor)
-{
-  return make_my_cleanup2 (&cleanup_chain,
-			   function, arg, dtor);
-}
-
-/* Same as make_cleanup except the cleanup is added to final_cleanup_chain.  */
-
 struct cleanup *
 make_final_cleanup (make_cleanup_ftype *function, void *arg)
 {
@@ -158,139 +135,10 @@ do_my_cleanups (struct cleanup **pmy_chain,
     }
 }
 
-/* Return a value that can be passed to do_cleanups, do_final_cleanups to
-   indicate perform all cleanups.  */
-
-struct cleanup *
-all_cleanups (void)
-{
-  return SENTINEL_CLEANUP;
-}
-
-/* Discard cleanups and do the actions they describe
-   until we get back to the point OLD_CHAIN in the cleanup_chain.  */
-
-void
-do_cleanups (struct cleanup *old_chain)
-{
-  do_my_cleanups (&cleanup_chain, old_chain);
-}
-
-/* Discard cleanups and do the actions they describe
-   until we get back to the point OLD_CHAIN in the final_cleanup_chain.  */
-
-void
-do_final_cleanups (struct cleanup *old_chain)
-{
-  do_my_cleanups (&final_cleanup_chain, old_chain);
-}
-
-/* Main worker routine to discard cleanups.
-   PMY_CHAIN is a pointer to either cleanup_chain or final_cleanup_chain.
-   OLD_CHAIN is the result of a "make" cleanup routine.
-   Cleanups are discarded until we get back to the old end of the chain.  */
-
-static void
-discard_my_cleanups (struct cleanup **pmy_chain,
-		     struct cleanup *old_chain)
-{
-  struct cleanup *ptr;
-
-  while ((ptr = *pmy_chain) != old_chain)
-    {
-      *pmy_chain = ptr->next;
-      if (ptr->free_arg)
-	(*ptr->free_arg) (ptr->arg);
-      xfree (ptr);
-    }
-}
-
-/* Discard cleanups, not doing the actions they describe,
-   until we get back to the point OLD_CHAIN in the cleanup chain.  */
-
-void
-discard_cleanups (struct cleanup *old_chain)
-{
-  discard_my_cleanups (&cleanup_chain, old_chain);
-}
-
-/* Discard final cleanups, not doing the actions they describe,
-   until we get back to the point OLD_CHAIN in the final cleanup chain.  */
-
-void
-discard_final_cleanups (struct cleanup *old_chain)
-{
-  discard_my_cleanups (&final_cleanup_chain, old_chain);
-}
-
-/* Main worker routine to save cleanups.
-   PMY_CHAIN is a pointer to either cleanup_chain or final_cleanup_chain.
-   The chain is emptied and the result is a pointer to the old chain.  */
-
-static struct cleanup *
-save_my_cleanups (struct cleanup **pmy_chain)
-{
-  struct cleanup *old_chain = *pmy_chain;
-
-  *pmy_chain = SENTINEL_CLEANUP;
-  return old_chain;
-}
-
-/* Set the cleanup_chain to 0, and return the old cleanup_chain.  */
-
-struct cleanup *
-save_cleanups (void)
-{
-  return save_my_cleanups (&cleanup_chain);
-}
-
-/* Set the final_cleanup_chain to 0, and return the old
-   final_cleanup_chain.  */
-
-struct cleanup *
-save_final_cleanups (void)
-{
-  return save_my_cleanups (&final_cleanup_chain);
-}
-
-/* Main worker routine to save cleanups.
-   PMY_CHAIN is a pointer to either cleanup_chain or final_cleanup_chain.
-   The chain is restored from CHAIN.  */
-
-static void
-restore_my_cleanups (struct cleanup **pmy_chain, struct cleanup *chain)
-{
-  if (*pmy_chain != SENTINEL_CLEANUP)
-    internal_warning (__FILE__, __LINE__,
-		      _("restore_my_cleanups has found a stale cleanup"));
-
-  *pmy_chain = chain;
-}
-
-/* Restore the cleanup chain from a previously saved chain.  */
-
-void
-restore_cleanups (struct cleanup *chain)
-{
-  restore_my_cleanups (&cleanup_chain, chain);
-}
-
-/* Restore the final cleanup chain from a previously saved chain.  */
-
-void
-restore_final_cleanups (struct cleanup *chain)
-{
-  restore_my_cleanups (&final_cleanup_chain, chain);
-}
-
-/* Provide a known function that does nothing, to use as a base for
-   a possibly long chain of cleanups.  This is useful where we
-   use the cleanup chain for handling normal cleanups as well as dealing
-   with cleanups that need to be done as a result of a call to error().
-   In such cases, we may not be certain where the first cleanup is, unless
-   we have a do-nothing one to always use as the base.  */
+/* Discard final cleanups and do the actions they describe.  */
 
 void
-null_cleanup (void *arg)
+do_final_cleanups ()
 {
+  do_my_cleanups (&final_cleanup_chain, SENTINEL_CLEANUP);
 }
diff --git a/gdb/common/cleanups.h b/gdb/common/cleanups.h
index f49bcb40d14..e676076a16d 100644
--- a/gdb/common/cleanups.h
+++ b/gdb/common/cleanups.h
@@ -32,38 +32,8 @@ typedef void (make_cleanup_ftype) (void *);
 /* Function type for the dtor in make_cleanup_dtor.  */
 typedef void (make_cleanup_dtor_ftype) (void *);
 
-/* WARNING: The result of the "make cleanup" routines is not the intuitive
-   choice of being a handle on the just-created cleanup.  Instead it is an
-   opaque handle of the cleanup mechanism and represents all cleanups created
-   from that point onwards.
-   The result is guaranteed to be non-NULL though.  */
-
-extern struct cleanup *make_cleanup (make_cleanup_ftype *, void *);
-
-extern struct cleanup *make_cleanup_dtor (make_cleanup_ftype *, void *,
-					  make_cleanup_dtor_ftype *);
-
 extern struct cleanup *make_final_cleanup (make_cleanup_ftype *, void *);
 
-/* A special value to pass to do_cleanups and do_final_cleanups
-   to tell them to do all cleanups.  */
-extern struct cleanup *all_cleanups (void);
-
-extern void do_cleanups (struct cleanup *);
-extern void do_final_cleanups (struct cleanup *);
-
-extern void discard_cleanups (struct cleanup *);
-extern void discard_final_cleanups (struct cleanup *);
-
-extern struct cleanup *save_cleanups (void);
-extern struct cleanup *save_final_cleanups (void);
-
-extern void restore_cleanups (struct cleanup *);
-extern void restore_final_cleanups (struct cleanup *);
-
-/* A no-op cleanup.
-   This is useful when you want to establish a known reference point
-   to pass to do_cleanups.  */
-extern void null_cleanup (void *);
+extern void do_final_cleanups ();
 
 #endif /* COMMON_CLEANUPS_H */
diff --git a/gdb/common/common-exceptions.c b/gdb/common/common-exceptions.c
index 5e86c7b4260..4e67e898bda 100644
--- a/gdb/common/common-exceptions.c
+++ b/gdb/common/common-exceptions.c
@@ -47,7 +47,6 @@ struct catcher
   jmp_buf buf;
   /* Status buffer belonging to the exception handler.  */
   struct gdb_exception exception;
-  struct cleanup *saved_cleanup_chain;
   /* Back link.  */
   struct catcher *prev;
 };
@@ -83,10 +82,6 @@ exceptions_state_mc_init (void)
   /* Start with no exception.  */
   new_catcher->exception = exception_none;
 
-  /* Prevent error/quit during FUNC from calling cleanups established
-     prior to here.  */
-  new_catcher->saved_cleanup_chain = save_cleanups ();
-
   /* Push this new catcher on the top.  */
   new_catcher->prev = current_catcher;
   current_catcher = new_catcher;
@@ -102,11 +97,6 @@ catcher_pop (void)
 
   current_catcher = old_catcher->prev;
 
-  /* Restore the cleanup chain, the error/quit messages, and the uiout
-     builder, to their original states.  */
-
-  restore_cleanups (old_catcher->saved_cleanup_chain);
-
   xfree (old_catcher);
 }
 
@@ -228,7 +218,7 @@ void *
 exception_try_scope_entry (void)
 {
   ++try_scope_depth;
-  return (void *) save_cleanups ();
+  return nullptr;
 }
 
 /* Called on exit of a TRY scope, either normal exit or exception
@@ -237,7 +227,6 @@ exception_try_scope_entry (void)
 void
 exception_try_scope_exit (void *saved_state)
 {
-  restore_cleanups ((struct cleanup *) saved_state);
   --try_scope_depth;
 }
 
@@ -248,9 +237,6 @@ exception_try_scope_exit (void *saved_state)
 void
 exception_rethrow (void)
 {
-  /* Run this scope's cleanups before re-throwing to the next
-     outermost scope.  */
-  do_cleanups (all_cleanups ());
   throw;
 }
 
@@ -269,8 +255,6 @@ gdb_exception_sliced_copy (struct gdb_exception *to, const struct gdb_exception
 void
 throw_exception_sjlj (struct gdb_exception exception)
 {
-  do_cleanups (all_cleanups ());
-
   /* Jump to the nearest CATCH_SJLJ block, communicating REASON to
      that call via setjmp's return value.  Note that REASON can't be
      zero, by definition in common-exceptions.h.  */
@@ -286,8 +270,6 @@ throw_exception_sjlj (struct gdb_exception exception)
 static ATTRIBUTE_NORETURN void
 throw_exception_cxx (struct gdb_exception exception)
 {
-  do_cleanups (all_cleanups ());
-
   if (exception.reason == RETURN_QUIT)
     {
       gdb_exception_RETURN_MASK_QUIT ex;
diff --git a/gdb/common/new-op.c b/gdb/common/new-op.c
index 8c07ffac23b..cff6686ef12 100644
--- a/gdb/common/new-op.c
+++ b/gdb/common/new-op.c
@@ -66,8 +66,6 @@ operator new (std::size_t sz)
 	}
       CATCH (ex, RETURN_MASK_ALL)
 	{
-	  do_cleanups (all_cleanups ());
-
 	  throw gdb_quit_bad_alloc (ex);
 	}
       END_CATCH
diff --git a/gdb/main.c b/gdb/main.c
index e14dd06fa8c..97ffc3fba48 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -330,14 +330,6 @@ captured_command_loop ()
   /* Now it's time to start the event loop.  */
   start_event_loop ();
 
-  /* FIXME: cagney/1999-11-05: A correct command_loop() implementaton
-     would clean things up (restoring the cleanup chain) to the state
-     they were just prior to the call.  Technically, this means that
-     the do_cleanups() below is redundant.  Unfortunately, many FUNCs
-     are not that well behaved.  do_cleanups should either be replaced
-     with a do_cleanups call (to cover the problem) or an assertion
-     check to detect bad FUNCs code.  */
-  do_cleanups (all_cleanups ());
   /* If the command_loop returned, normally (rather than threw an
      error) we try to quit.  If the quit is aborted, our caller
      catches the signal and restarts the command loop.  */
diff --git a/gdb/top.c b/gdb/top.c
index 22e6f7e29ab..4065df70815 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1675,7 +1675,7 @@ quit_force (int *exit_arg, int from_tty)
   /* Do any final cleanups before exiting.  */
   TRY
     {
-      do_final_cleanups (all_cleanups ());
+      do_final_cleanups ();
     }
   CATCH (ex, RETURN_MASK_ALL)
     {
-- 
2.17.2

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

* [PATCH v2 16/22] Rewrite TRY/CATCH
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
                   ` (3 preceding siblings ...)
  2019-02-27 20:19 ` [PATCH v2 09/22] Remove last cleanup from linux-namespaces.c Tom Tromey
@ 2019-02-27 20:19 ` Tom Tromey
  2019-04-03 17:03   ` Pedro Alves
  2019-02-27 20:19 ` [PATCH v2 04/22] C++ify remote notification code Tom Tromey
                   ` (16 subsequent siblings)
  21 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This rewrites gdb's TRY/CATCH to plain C++ try/catch.  The patch was
largely written by script, though one change (to a comment in
common-exceptions.h) was reverted by hand.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* xml-support.c: Use C++ exception handling.
	* x86-linux-nat.c: Use C++ exception handling.
	* windows-nat.c: Use C++ exception handling.
	* varobj.c: Use C++ exception handling.
	* value.c: Use C++ exception handling.
	* valprint.c: Use C++ exception handling.
	* valops.c: Use C++ exception handling.
	* unittests/parse-connection-spec-selftests.c: Use C++ exception
	handling.
	* unittests/cli-utils-selftests.c: Use C++ exception handling.
	* typeprint.c: Use C++ exception handling.
	* tui/tui.c: Use C++ exception handling.
	* tracefile-tfile.c: Use C++ exception handling.
	* top.c: Use C++ exception handling.
	* thread.c: Use C++ exception handling.
	* target.c: Use C++ exception handling.
	* symmisc.c: Use C++ exception handling.
	* symfile-mem.c: Use C++ exception handling.
	* stack.c: Use C++ exception handling.
	* sparc64-linux-tdep.c: Use C++ exception handling.
	* solib.c: Use C++ exception handling.
	* solib-svr4.c: Use C++ exception handling.
	* solib-spu.c: Use C++ exception handling.
	* solib-frv.c: Use C++ exception handling.
	* solib-dsbt.c: Use C++ exception handling.
	* selftest-arch.c: Use C++ exception handling.
	* s390-tdep.c: Use C++ exception handling.
	* rust-lang.c: Use C++ exception handling.
	* rust-exp.y: Use C++ exception handling.
	* rs6000-tdep.c: Use C++ exception handling.
	* rs6000-aix-tdep.c: Use C++ exception handling.
	* riscv-tdep.c: Use C++ exception handling.
	* remote.c: Use C++ exception handling.
	* remote-fileio.c: Use C++ exception handling.
	* record-full.c: Use C++ exception handling.
	* record-btrace.c: Use C++ exception handling.
	* python/python.c: Use C++ exception handling.
	* python/py-value.c: Use C++ exception handling.
	* python/py-utils.c: Use C++ exception handling.
	* python/py-unwind.c: Use C++ exception handling.
	* python/py-type.c: Use C++ exception handling.
	* python/py-symbol.c: Use C++ exception handling.
	* python/py-record.c: Use C++ exception handling.
	* python/py-record-btrace.c: Use C++ exception handling.
	* python/py-progspace.c: Use C++ exception handling.
	* python/py-prettyprint.c: Use C++ exception handling.
	* python/py-param.c: Use C++ exception handling.
	* python/py-objfile.c: Use C++ exception handling.
	* python/py-linetable.c: Use C++ exception handling.
	* python/py-lazy-string.c: Use C++ exception handling.
	* python/py-infthread.c: Use C++ exception handling.
	* python/py-inferior.c: Use C++ exception handling.
	* python/py-gdb-readline.c: Use C++ exception handling.
	* python/py-framefilter.c: Use C++ exception handling.
	* python/py-frame.c: Use C++ exception handling.
	* python/py-finishbreakpoint.c: Use C++ exception handling.
	* python/py-cmd.c: Use C++ exception handling.
	* python/py-breakpoint.c: Use C++ exception handling.
	* python/py-arch.c: Use C++ exception handling.
	* printcmd.c: Use C++ exception handling.
	* ppc-linux-tdep.c: Use C++ exception handling.
	* parse.c: Use C++ exception handling.
	* p-valprint.c: Use C++ exception handling.
	* objc-lang.c: Use C++ exception handling.
	* mi/mi-main.c: Use C++ exception handling.
	* mi/mi-interp.c: Use C++ exception handling.
	* mi/mi-cmd-stack.c: Use C++ exception handling.
	* mi/mi-cmd-break.c: Use C++ exception handling.
	* main.c: Use C++ exception handling.
	* linux-thread-db.c: Use C++ exception handling.
	* linux-tdep.c: Use C++ exception handling.
	* linux-nat.c: Use C++ exception handling.
	* linux-fork.c: Use C++ exception handling.
	* linespec.c: Use C++ exception handling.
	* language.c: Use C++ exception handling.
	* jit.c: Use C++ exception handling.
	* infrun.c: Use C++ exception handling.
	* infcmd.c: Use C++ exception handling.
	* infcall.c: Use C++ exception handling.
	* inf-loop.c: Use C++ exception handling.
	* i386-tdep.c: Use C++ exception handling.
	* i386-linux-tdep.c: Use C++ exception handling.
	* guile/scm-value.c: Use C++ exception handling.
	* guile/scm-type.c: Use C++ exception handling.
	* guile/scm-symtab.c: Use C++ exception handling.
	* guile/scm-symbol.c: Use C++ exception handling.
	* guile/scm-pretty-print.c: Use C++ exception handling.
	* guile/scm-ports.c: Use C++ exception handling.
	* guile/scm-param.c: Use C++ exception handling.
	* guile/scm-math.c: Use C++ exception handling.
	* guile/scm-lazy-string.c: Use C++ exception handling.
	* guile/scm-frame.c: Use C++ exception handling.
	* guile/scm-disasm.c: Use C++ exception handling.
	* guile/scm-cmd.c: Use C++ exception handling.
	* guile/scm-breakpoint.c: Use C++ exception handling.
	* guile/scm-block.c: Use C++ exception handling.
	* guile/guile-internal.h: Use C++ exception handling.
	* gnu-v3-abi.c: Use C++ exception handling.
	* gdbtypes.c: Use C++ exception handling.
	* gcore.c: Use C++ exception handling.
	* frame.c: Use C++ exception handling.
	* frame-unwind.c: Use C++ exception handling.
	* fbsd-tdep.c: Use C++ exception handling.
	* f-valprint.c: Use C++ exception handling.
	* exec.c: Use C++ exception handling.
	* event-top.c: Use C++ exception handling.
	* event-loop.c: Use C++ exception handling.
	* eval.c: Use C++ exception handling.
	* dwarf2read.c: Use C++ exception handling.
	* dwarf2loc.c: Use C++ exception handling.
	* dwarf2-frame.c: Use C++ exception handling.
	* dwarf2-frame-tailcall.c: Use C++ exception handling.
	* dwarf-index-write.c: Use C++ exception handling.
	* dwarf-index-cache.c: Use C++ exception handling.
	* dtrace-probe.c: Use C++ exception handling.
	* disasm-selftests.c: Use C++ exception handling.
	* darwin-nat.c: Use C++ exception handling.
	* cp-valprint.c: Use C++ exception handling.
	* cp-support.c: Use C++ exception handling.
	* cp-abi.c: Use C++ exception handling.
	* corelow.c: Use C++ exception handling.
	* completer.c: Use C++ exception handling.
	* compile/compile-object-run.c: Use C++ exception handling.
	* compile/compile-object-load.c: Use C++ exception handling.
	* compile/compile-cplus-symbols.c: Use C++ exception handling.
	* compile/compile-c-symbols.c: Use C++ exception handling.
	* common/selftest.c: Use C++ exception handling.
	* common/new-op.c: Use C++ exception handling.
	* common/common-exceptions.h: Use C++ exception handling.
	* cli/cli-script.c: Use C++ exception handling.
	* cli/cli-interp.c: Use C++ exception handling.
	* cli/cli-cmds.c: Use C++ exception handling.
	* c-varobj.c: Use C++ exception handling.
	* btrace.c: Use C++ exception handling.
	* breakpoint.c: Use C++ exception handling.
	* break-catch-throw.c: Use C++ exception handling.
	* arch-utils.c: Use C++ exception handling.
	* amd64-tdep.c: Use C++ exception handling.
	* ada-valprint.c: Use C++ exception handling.
	* ada-typeprint.c: Use C++ exception handling.
	* ada-lang.c: Use C++ exception handling.
	* aarch64-tdep.c: Use C++ exception handling.

gdb/gdbserver/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* server.c: Use C++ exception handling.
	* linux-low.c: Use C++ exception handling.
	* gdbreplay.c: Use C++ exception handling.
---
 gdb/ChangeLog                                 | 145 +++++++++++++++++
 gdb/aarch64-tdep.c                            |  10 +-
 gdb/ada-lang.c                                |  35 ++--
 gdb/ada-typeprint.c                           |   5 +-
 gdb/ada-valprint.c                            |   5 +-
 gdb/amd64-tdep.c                              |  15 +-
 gdb/arch-utils.c                              |   5 +-
 gdb/break-catch-throw.c                       |  15 +-
 gdb/breakpoint.c                              |  70 ++++----
 gdb/btrace.c                                  |  35 ++--
 gdb/c-varobj.c                                |  20 +--
 gdb/cli/cli-cmds.c                            |   5 +-
 gdb/cli/cli-interp.c                          |   5 +-
 gdb/cli/cli-script.c                          |  10 +-
 gdb/common/new-op.c                           |   5 +-
 gdb/common/selftest.c                         |   5 +-
 gdb/compile/compile-c-symbols.c               |  15 +-
 gdb/compile/compile-cplus-symbols.c           |  10 +-
 gdb/compile/compile-object-load.c             |   5 +-
 gdb/compile/compile-object-run.c              |   5 +-
 gdb/completer.c                               |  20 +--
 gdb/corelow.c                                 |  10 +-
 gdb/cp-abi.c                                  |  10 +-
 gdb/cp-support.c                              |  15 +-
 gdb/cp-valprint.c                             |  10 +-
 gdb/darwin-nat.c                              |  10 +-
 gdb/disasm-selftests.c                        |   5 +-
 gdb/dtrace-probe.c                            |   5 +-
 gdb/dwarf-index-cache.c                       |  10 +-
 gdb/dwarf-index-write.c                       |   5 +-
 gdb/dwarf2-frame-tailcall.c                   |   5 +-
 gdb/dwarf2-frame.c                            |  15 +-
 gdb/dwarf2loc.c                               |  15 +-
 gdb/dwarf2read.c                              |   5 +-
 gdb/eval.c                                    |  25 ++-
 gdb/event-loop.c                              |   5 +-
 gdb/event-top.c                               |  15 +-
 gdb/exec.c                                    |  10 +-
 gdb/f-valprint.c                              |   5 +-
 gdb/fbsd-tdep.c                               |   5 +-
 gdb/frame-unwind.c                            |   5 +-
 gdb/frame.c                                   |  30 ++--
 gdb/gcore.c                                   |   5 +-
 gdb/gdbserver/ChangeLog                       |   6 +
 gdb/gdbserver/gdbreplay.c                     |   5 +-
 gdb/gdbserver/linux-low.c                     |  10 +-
 gdb/gdbserver/server.c                        |  30 ++--
 gdb/gdbtypes.c                                |  10 +-
 gdb/gnu-v3-abi.c                              |   5 +-
 gdb/guile/guile-internal.h                    |   5 +-
 gdb/guile/scm-block.c                         |   5 +-
 gdb/guile/scm-breakpoint.c                    |  40 ++---
 gdb/guile/scm-cmd.c                           |   5 +-
 gdb/guile/scm-disasm.c                        |   5 +-
 gdb/guile/scm-frame.c                         |  95 +++++------
 gdb/guile/scm-lazy-string.c                   |   5 +-
 gdb/guile/scm-math.c                          |   5 +-
 gdb/guile/scm-param.c                         |  10 +-
 gdb/guile/scm-ports.c                         |   5 +-
 gdb/guile/scm-pretty-print.c                  |   5 +-
 gdb/guile/scm-symbol.c                        |  25 ++-
 gdb/guile/scm-symtab.c                        |   5 +-
 gdb/guile/scm-type.c                          |  60 +++----
 gdb/guile/scm-value.c                         |  75 ++++-----
 gdb/i386-linux-tdep.c                         |   5 +-
 gdb/i386-tdep.c                               |  15 +-
 gdb/inf-loop.c                                |   5 +-
 gdb/infcall.c                                 |   5 +-
 gdb/infcmd.c                                  |  10 +-
 gdb/infrun.c                                  |  35 ++--
 gdb/jit.c                                     |   5 +-
 gdb/language.c                                |   5 +-
 gdb/linespec.c                                |  30 ++--
 gdb/linux-fork.c                              |   5 +-
 gdb/linux-nat.c                               |  20 +--
 gdb/linux-tdep.c                              |   5 +-
 gdb/linux-thread-db.c                         |  15 +-
 gdb/main.c                                    |  15 +-
 gdb/mi/mi-cmd-break.c                         |   5 +-
 gdb/mi/mi-cmd-stack.c                         |   5 +-
 gdb/mi/mi-interp.c                            |   5 +-
 gdb/mi/mi-main.c                              |  10 +-
 gdb/objc-lang.c                               |   5 +-
 gdb/p-valprint.c                              |   5 +-
 gdb/parse.c                                   |  10 +-
 gdb/ppc-linux-tdep.c                          |   5 +-
 gdb/printcmd.c                                |  20 +--
 gdb/python/py-arch.c                          |   5 +-
 gdb/python/py-breakpoint.c                    |  40 ++---
 gdb/python/py-cmd.c                           |   5 +-
 gdb/python/py-finishbreakpoint.c              |  30 ++--
 gdb/python/py-frame.c                         |  90 +++++------
 gdb/python/py-framefilter.c                   |  10 +-
 gdb/python/py-gdb-readline.c                  |   5 +-
 gdb/python/py-inferior.c                      |  25 ++-
 gdb/python/py-infthread.c                     |   5 +-
 gdb/python/py-lazy-string.c                   |   5 +-
 gdb/python/py-linetable.c                     |   5 +-
 gdb/python/py-objfile.c                       |  10 +-
 gdb/python/py-param.c                         |   5 +-
 gdb/python/py-prettyprint.c                   |  10 +-
 gdb/python/py-progspace.c                     |  10 +-
 gdb/python/py-record-btrace.c                 |  20 +--
 gdb/python/py-record.c                        |  10 +-
 gdb/python/py-symbol.c                        |  25 ++-
 gdb/python/py-type.c                          |  90 +++++------
 gdb/python/py-unwind.c                        |  20 +--
 gdb/python/py-utils.c                         |   5 +-
 gdb/python/py-value.c                         | 150 +++++++-----------
 gdb/python/python.c                           |  35 ++--
 gdb/record-btrace.c                           |  45 +++---
 gdb/record-full.c                             |  20 +--
 gdb/remote-fileio.c                           |   5 +-
 gdb/remote.c                                  |  25 ++-
 gdb/riscv-tdep.c                              |  10 +-
 gdb/rs6000-aix-tdep.c                         |   5 +-
 gdb/rs6000-tdep.c                             |  10 +-
 gdb/rust-exp.y                                |   5 +-
 gdb/rust-lang.c                               |   5 +-
 gdb/s390-tdep.c                               |   5 +-
 gdb/selftest-arch.c                           |   5 +-
 gdb/solib-dsbt.c                              |   5 +-
 gdb/solib-frv.c                               |   5 +-
 gdb/solib-spu.c                               |   5 +-
 gdb/solib-svr4.c                              |  30 ++--
 gdb/solib.c                                   |  20 +--
 gdb/sparc64-linux-tdep.c                      |   5 +-
 gdb/stack.c                                   |  55 +++----
 gdb/symfile-mem.c                             |   5 +-
 gdb/symmisc.c                                 |   5 +-
 gdb/target.c                                  |   5 +-
 gdb/thread.c                                  |   5 +-
 gdb/top.c                                     |  20 +--
 gdb/tracefile-tfile.c                         |   5 +-
 gdb/tui/tui.c                                 |   5 +-
 gdb/typeprint.c                               |   5 +-
 gdb/unittests/cli-utils-selftests.c           |  10 +-
 .../parse-connection-spec-selftests.c         |   5 +-
 gdb/valops.c                                  |  10 +-
 gdb/valprint.c                                |   5 +-
 gdb/value.c                                   |  10 +-
 gdb/varobj.c                                  |  30 ++--
 gdb/windows-nat.c                             |   5 +-
 gdb/x86-linux-nat.c                           |   5 +-
 gdb/xml-support.c                             |  10 +-
 145 files changed, 1033 insertions(+), 1323 deletions(-)

diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index dd57ef98739..b4f1cf895a5 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -776,16 +776,15 @@ aarch64_make_prologue_cache (struct frame_info *this_frame, void **this_cache)
   cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
   *this_cache = cache;
 
-  TRY
+  try
     {
       aarch64_make_prologue_cache_1 (this_frame, cache);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
     }
-  END_CATCH
 
   return cache;
 }
@@ -900,19 +899,18 @@ aarch64_make_stub_cache (struct frame_info *this_frame, void **this_cache)
   cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
   *this_cache = cache;
 
-  TRY
+  try
     {
       cache->prev_sp = get_frame_register_unsigned (this_frame,
 						    AARCH64_SP_REGNUM);
       cache->prev_pc = get_frame_pc (this_frame);
       cache->available_p = 1;
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
     }
-  END_CATCH
 
   return cache;
 }
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 9c23d8e0d5f..61fef64a488 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -6712,16 +6712,15 @@ ada_tag_value_at_base_address (struct value *obj)
      see ada_tag_name for more details.  We do not print the error
      message for the same reason.  */
 
-  TRY
+  try
     {
       offset_to_top = value_as_long (value_ind (value_ptradd (val, -2)));
     }
 
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       return obj;
     }
-  END_CATCH
 
   /* If offset is null, nothing to do.  */
 
@@ -6858,17 +6857,16 @@ ada_tag_name (struct value *tag)
      We also do not print the error message either (which often is very
      low-level (Eg: "Cannot read memory at 0x[...]"), but instead let
      the caller print a more meaningful message if necessary.  */
-  TRY
+  try
     {
       struct value *tsd = ada_get_tsd_from_tag (tag);
 
       if (tsd != NULL)
 	name = ada_tag_name_from_tsd (tsd);
     }
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
     {
     }
-  END_CATCH
 
   return name;
 }
@@ -9043,11 +9041,11 @@ ada_to_fixed_type_1 (struct type *type, const gdb_byte *valaddr,
             LONGEST size;
 
             xsnprintf (xvz_name, strlen (name) + 7, "%s___XVZ", name);
-	    TRY
+	    try
 	      {
 		xvz_found = get_int_var_value (xvz_name, size);
 	      }
-	    CATCH (except, RETURN_MASK_ERROR)
+	    catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	      {
 		/* We found the variable, but somehow failed to read
 		   its value.  Rethrow the same error, but with a little
@@ -9058,7 +9056,6 @@ ada_to_fixed_type_1 (struct type *type, const gdb_byte *valaddr,
 			     _("unable to read value of %s (%s)"),
 			     xvz_name, except.message.c_str ());
 	      }
-	    END_CATCH
 
             if (xvz_found && TYPE_LENGTH (fixed_record_type) != size)
               {
@@ -12334,15 +12331,14 @@ ada_exception_message (void)
 {
   gdb::unique_xmalloc_ptr<char> e_msg;
 
-  TRY
+  try
     {
       e_msg = ada_exception_message_1 ();
     }
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       e_msg.reset (nullptr);
     }
-  END_CATCH
 
   return e_msg;
 }
@@ -12358,17 +12354,16 @@ ada_exception_name_addr (enum ada_exception_catchpoint_kind ex,
 {
   CORE_ADDR result = 0;
 
-  TRY
+  try
     {
       result = ada_exception_name_addr_1 (ex, b);
     }
 
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       warning (_("failed to get exception name: %s"), e.message.c_str ());
       return 0;
     }
-  END_CATCH
 
   return result;
 }
@@ -12449,19 +12444,18 @@ create_excep_cond_exprs (struct ada_catchpoint *c,
 	  const char *s;
 
 	  s = cond_string.c_str ();
-	  TRY
+	  try
 	    {
 	      exp = parse_exp_1 (&s, bl->address,
 				 block_for_pc (bl->address),
 				 0);
 	    }
-	  CATCH (e, RETURN_MASK_ERROR)
+	  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
 	    {
 	      warning (_("failed to reevaluate internal exception condition "
 			 "for catchpoint %d: %s"),
 		       c->number, e.message.c_str ());
 	    }
-	  END_CATCH
 	}
 
       ada_loc->excep_cond_expr = std::move (exp);
@@ -12519,7 +12513,7 @@ should_stop_exception (const struct bp_location *bl)
     }
 
   stop = 1;
-  TRY
+  try
     {
       struct value *mark;
 
@@ -12527,12 +12521,11 @@ should_stop_exception (const struct bp_location *bl)
       stop = value_true (evaluate_expression (ada_loc->excep_cond_expr.get ()));
       value_free_to_mark (mark);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       exception_fprintf (gdb_stderr, ex,
 			 _("Error in testing exception condition:\n"));
     }
-  END_CATCH
 
   return stop;
 }
diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c
index 8c42e8140de..d3008cd2d96 100644
--- a/gdb/ada-typeprint.c
+++ b/gdb/ada-typeprint.c
@@ -163,12 +163,12 @@ print_range (struct type *type, struct ui_file *stream,
 	LONGEST lo = 0, hi = 0; /* init for gcc -Wall */
 	int got_error = 0;
 
-	TRY
+	try
 	  {
 	    lo = ada_discrete_type_low_bound (type);
 	    hi = ada_discrete_type_high_bound (type);
 	  }
-	CATCH (e, RETURN_MASK_ERROR)
+	catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
 	  {
 	    /* This can happen when the range is dynamic.  Sometimes,
 	       resolving dynamic property values requires us to have
@@ -178,7 +178,6 @@ print_range (struct type *type, struct ui_file *stream,
 	    fprintf_filtered (stream, "<>");
 	    got_error = 1;
 	  }
-	END_CATCH
 
 	if (!got_error)
 	  {
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index 72cae3b7f47..57336ed6c3a 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -1204,18 +1204,17 @@ ada_val_print (struct type *type,
 	       struct value *val,
 	       const struct value_print_options *options)
 {
-  TRY
+  try
     {
       ada_val_print_1 (type, embedded_offset, address,
 		       stream, recurse, val, options,
 		       current_language);
     }
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       fprintf_filtered (stream, _("<error reading variable: %s>"),
 			except.message.c_str ());
     }
-  END_CATCH
 }
 
 void
diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index 3f61997d663..eeb0a9dd73c 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -2581,16 +2581,15 @@ amd64_frame_cache (struct frame_info *this_frame, void **this_cache)
   cache = amd64_alloc_frame_cache ();
   *this_cache = cache;
 
-  TRY
+  try
     {
       amd64_frame_cache_1 (this_frame, cache);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
     }
-  END_CATCH
 
   return cache;
 }
@@ -2699,7 +2698,7 @@ amd64_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 
   cache = amd64_alloc_frame_cache ();
 
-  TRY
+  try
     {
       get_frame_register (this_frame, AMD64_RSP_REGNUM, buf);
       cache->base = extract_unsigned_integer (buf, 8, byte_order) - 8;
@@ -2713,12 +2712,11 @@ amd64_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 
       cache->base_p = 1;
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
     }
-  END_CATCH
 
   *this_cache = cache;
   return cache;
@@ -2876,7 +2874,7 @@ amd64_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
   cache = amd64_alloc_frame_cache ();
   *this_cache = cache;
 
-  TRY
+  try
     {
       /* Cache base will be %esp plus cache->sp_offset (-8).  */
       get_frame_register (this_frame, AMD64_RSP_REGNUM, buf);
@@ -2894,12 +2892,11 @@ amd64_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
 
       cache->base_p = 1;
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
     }
-  END_CATCH
 
   return cache;
 }
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index 52a08daa3b9..442ab89db81 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -969,13 +969,12 @@ gdbarch_skip_prologue_noexcept (gdbarch *gdbarch, CORE_ADDR pc) noexcept
 {
   CORE_ADDR new_pc = pc;
 
-  TRY
+  try
     {
       new_pc = gdbarch_skip_prologue (gdbarch, pc);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {}
-  END_CATCH
 
   return new_pc;
 }
diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c
index c8d66e0737c..b7c72f0a755 100644
--- a/gdb/break-catch-throw.c
+++ b/gdb/break-catch-throw.c
@@ -154,7 +154,7 @@ check_status_exception_catchpoint (struct bpstats *bs)
   if (self->pattern == NULL)
     return;
 
-  TRY
+  try
     {
       struct value *typeinfo_arg;
       std::string canon;
@@ -166,11 +166,10 @@ check_status_exception_catchpoint (struct bpstats *bs)
       if (!canon.empty ())
 	std::swap (type_name, canon);
     }
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       exception_print (gdb_stderr, e);
     }
-  END_CATCH
 
   if (!type_name.empty ())
     {
@@ -189,17 +188,17 @@ re_set_exception_catchpoint (struct breakpoint *self)
   struct program_space *filter_pspace = current_program_space;
 
   /* We first try to use the probe interface.  */
-  TRY
+  try
     {
       event_location_up location
 	= new_probe_location (exception_functions[kind].probe);
       sals = parse_probes (location.get (), filter_pspace, NULL);
     }
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       /* Using the probe interface failed.  Let's fallback to the normal
 	 catchpoint mode.  */
-      TRY
+      try
 	{
 	  struct explicit_location explicit_loc;
 
@@ -210,16 +209,14 @@ re_set_exception_catchpoint (struct breakpoint *self)
 	  sals = self->ops->decode_location (self, location.get (),
 					     filter_pspace);
 	}
-      CATCH (ex, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 	{
 	  /* NOT_FOUND_ERROR just means the breakpoint will be
 	     pending, so let it through.  */
 	  if (ex.error != NOT_FOUND_ERROR)
 	    throw_exception (ex);
 	}
-      END_CATCH
     }
-  END_CATCH
 
   update_breakpoint_locations (self, filter_pspace, sals, {});
 }
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 17b4d643613..50555bb38ce 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -2096,18 +2096,17 @@ parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond)
 
   /* We don't want to stop processing, so catch any errors
      that may show up.  */
-  TRY
+  try
     {
       aexpr = gen_eval_for_expr (scope, cond);
     }
 
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       /* If we got here, it means the condition could not be parsed to a valid
 	 bytecode expression and thus can't be evaluated on the target's side.
 	 It's no use iterating through the conditions.  */
     }
-  END_CATCH
 
   /* We have a valid agent expression.  */
   return aexpr;
@@ -2271,19 +2270,18 @@ parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd)
 
   /* We don't want to stop processing, so catch any errors
      that may show up.  */
-  TRY
+  try
     {
       aexpr = gen_printf (scope, gdbarch, 0, 0,
 			  format_start, format_end - format_start,
 			  argvec.size (), argvec.data ());
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       /* If we got here, it means the command could not be parsed to a valid
 	 bytecode expression and thus can't be evaluated on the target's side.
 	 It's no use iterating through the other commands.  */
     }
-  END_CATCH
 
   /* We have a valid agent expression, return it.  */
   return aexpr;
@@ -2538,7 +2536,7 @@ insert_bp_location (struct bp_location *bl,
 	  || !(section_is_overlay (bl->section)))
 	{
 	  /* No overlay handling: just set the breakpoint.  */
-	  TRY
+	  try
 	    {
 	      int val;
 
@@ -2546,11 +2544,10 @@ insert_bp_location (struct bp_location *bl,
 	      if (val)
 		bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
 	    }
-	  CATCH (e, RETURN_MASK_ALL)
+	  catch (const struct gdb_exception_RETURN_MASK_ALL &e)
 	    {
 	      bp_excpt = e;
 	    }
-	  END_CATCH
 	}
       else
 	{
@@ -2573,7 +2570,7 @@ insert_bp_location (struct bp_location *bl,
 		  bl->overlay_target_info.reqstd_address = addr;
 
 		  /* No overlay handling: just set the breakpoint.  */
-		  TRY
+		  try
 		    {
 		      int val;
 
@@ -2586,11 +2583,10 @@ insert_bp_location (struct bp_location *bl,
 			bp_excpt
 			  = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
 		    }
-		  CATCH (e, RETURN_MASK_ALL)
+		  catch (const struct gdb_exception_RETURN_MASK_ALL &e)
 		    {
 		      bp_excpt = e;
 		    }
-		  END_CATCH
 
 		  if (bp_excpt.reason != 0)
 		    fprintf_unfiltered (tmp_error_stream,
@@ -2603,7 +2599,7 @@ insert_bp_location (struct bp_location *bl,
 	  if (section_is_mapped (bl->section))
 	    {
 	      /* Yes.  This overlay section is mapped into memory.  */
-	      TRY
+	      try
 	        {
 		  int val;
 
@@ -2611,11 +2607,10 @@ insert_bp_location (struct bp_location *bl,
 		  if (val)
 		    bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR};
 	        }
-	      CATCH (e, RETURN_MASK_ALL)
+	      catch (const struct gdb_exception_RETURN_MASK_ALL &e)
 	        {
 		  bp_excpt = e;
 	        }
-	      END_CATCH
 	    }
 	  else
 	    {
@@ -5016,11 +5011,11 @@ bpstat_check_watchpoint (bpstat bs)
 	{
 	  wp_check_result e;
 
-	  TRY
+	  try
 	    {
 	      e = watchpoint_check (bs);
 	    }
-	  CATCH (ex, RETURN_MASK_ALL)
+	  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	    {
 	      exception_fprintf (gdb_stderr, ex,
 				 "Error evaluating expression "
@@ -5035,7 +5030,6 @@ bpstat_check_watchpoint (bpstat bs)
 	      watchpoint_del_at_next_stop (b);
 	      e = WP_DELETED;
 	    }
-	  END_CATCH
 
 	  switch (e)
 	    {
@@ -5254,16 +5248,15 @@ bpstat_check_breakpoint_conditions (bpstat bs, thread_info *thread)
 	}
       if (within_current_scope)
 	{
-	  TRY
+	  try
 	    {
 	      condition_result = breakpoint_cond_eval (cond);
 	    }
-	  CATCH (ex, RETURN_MASK_ALL)
+	  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	    {
 	      exception_fprintf (gdb_stderr, ex,
 				 "Error in testing breakpoint condition:\n");
 	    }
-	  END_CATCH
 	}
       else
 	{
@@ -9236,11 +9229,11 @@ create_breakpoint (struct gdbarch *gdbarch,
   if (extra_string != NULL && *extra_string == '\0')
     extra_string = NULL;
 
-  TRY
+  try
     {
       ops->create_sals_from_location (location, &canonical, type_wanted);
     }
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       /* If caller is interested in rc value from parse, set
 	 value.  */
@@ -9270,7 +9263,6 @@ create_breakpoint (struct gdbarch *gdbarch,
       else
 	throw_exception (e);
     }
-  END_CATCH
 
   if (!pending && canonical.lsals.empty ())
     return 0;
@@ -12050,14 +12042,13 @@ static void
 update_global_location_list_nothrow (enum ugll_insert_mode insert_mode)
 {
 
-  TRY
+  try
     {
       update_global_location_list (insert_mode);
     }
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
     {
     }
-  END_CATCH
 }
 
 /* Clear BKP from a BPS.  */
@@ -13519,20 +13510,19 @@ update_breakpoint_locations (struct breakpoint *b,
 	  const char *s;
 
 	  s = b->cond_string;
-	  TRY
+	  try
 	    {
 	      new_loc->cond = parse_exp_1 (&s, sal.pc,
 					   block_for_pc (sal.pc),
 					   0);
 	    }
-	  CATCH (e, RETURN_MASK_ERROR)
+	  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
 	    {
 	      warning (_("failed to reevaluate condition "
 			 "for breakpoint %d: %s"), 
 		       b->number, e.message.c_str ());
 	      new_loc->enabled = 0;
 	    }
-	  END_CATCH
 	}
 
       if (!sals_end.empty ())
@@ -13599,11 +13589,11 @@ location_to_sals (struct breakpoint *b, struct event_location *location,
 
   std::vector<symtab_and_line> sals;
 
-  TRY
+  try
     {
       sals = b->ops->decode_location (b, location, search_pspace);
     }
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       int not_found_and_ok = 0;
 
@@ -13638,7 +13628,6 @@ location_to_sals (struct breakpoint *b, struct event_location *location,
 	  throw_exception (e);
 	}
     }
-  END_CATCH
 
   if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR)
     {
@@ -13810,17 +13799,16 @@ breakpoint_re_set (void)
 
     ALL_BREAKPOINTS_SAFE (b, b_tmp)
       {
-	TRY
+	try
 	  {
 	    breakpoint_re_set_one (b);
 	  }
-	CATCH (ex, RETURN_MASK_ALL)
+	catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	  {
 	    exception_fprintf (gdb_stderr, ex,
 			       "Error in re-setting breakpoint %d: ",
 			       b->number);
 	  }
-	END_CATCH
       }
 
     jit_breakpoint_re_set ();
@@ -14287,7 +14275,7 @@ enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
       /* Initialize it just to avoid a GCC false warning.  */
       enum enable_state orig_enable_state = bp_disabled;
 
-      TRY
+      try
 	{
 	  struct watchpoint *w = (struct watchpoint *) bpt;
 
@@ -14295,14 +14283,13 @@ enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition,
 	  bpt->enable_state = bp_enabled;
 	  update_watchpoint (w, 1 /* reparse */);
 	}
-      CATCH (e, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &e)
 	{
 	  bpt->enable_state = orig_enable_state;
 	  exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "),
 			     bpt->number);
 	  return;
 	}
-      END_CATCH
     }
 
   bpt->enable_state = bp_enabled;
@@ -15030,16 +15017,15 @@ save_breakpoints (const char *filename, int from_tty,
 	fp.puts ("  commands\n");
 	
 	current_uiout->redirect (&fp);
-	TRY
+	try
 	  {
 	    print_command_lines (current_uiout, tp->commands.get (), 2);
 	  }
-	CATCH (ex, RETURN_MASK_ALL)
+	catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	  {
 	  current_uiout->redirect (NULL);
 	    throw_exception (ex);
 	  }
-	END_CATCH
 
 	current_uiout->redirect (NULL);
 	fp.puts ("  end\n");
diff --git a/gdb/btrace.c b/gdb/btrace.c
index 000db4260e2..d978b5d206d 100644
--- a/gdb/btrace.c
+++ b/gdb/btrace.c
@@ -678,7 +678,7 @@ ftrace_classify_insn (struct gdbarch *gdbarch, CORE_ADDR pc)
   enum btrace_insn_class iclass;
 
   iclass = BTRACE_INSN_OTHER;
-  TRY
+  try
     {
       if (gdbarch_insn_is_call (gdbarch, pc))
 	iclass = BTRACE_INSN_CALL;
@@ -687,10 +687,9 @@ ftrace_classify_insn (struct gdbarch *gdbarch, CORE_ADDR pc)
       else if (gdbarch_insn_is_jump (gdbarch, pc))
 	iclass = BTRACE_INSN_JUMP;
     }
-  CATCH (error, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &error)
     {
     }
-  END_CATCH
 
   return iclass;
 }
@@ -1103,14 +1102,13 @@ btrace_compute_ftrace_bts (struct thread_info *tp,
 	    level = std::min (level, bfun->level);
 
 	  size = 0;
-	  TRY
+	  try
 	    {
 	      size = gdb_insn_length (gdbarch, pc);
 	    }
-	  CATCH (error, RETURN_MASK_ERROR)
+	  catch (const struct gdb_exception_RETURN_MASK_ERROR &error)
 	    {
 	    }
-	  END_CATCH
 
 	  insn.pc = pc;
 	  insn.size = size;
@@ -1370,17 +1368,16 @@ btrace_pt_readmem_callback (gdb_byte *buffer, size_t size,
   int result, errcode;
 
   result = (int) size;
-  TRY
+  try
     {
       errcode = target_read_code ((CORE_ADDR) pc, buffer, size);
       if (errcode != 0)
 	result = -pte_nomap;
     }
-  CATCH (error, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &error)
     {
       result = -pte_nomap;
     }
-  END_CATCH
 
   return result;
 }
@@ -1464,7 +1461,7 @@ btrace_compute_ftrace_pt (struct thread_info *tp,
   if (decoder == NULL)
     error (_("Failed to allocate the Intel Processor Trace decoder."));
 
-  TRY
+  try
     {
       struct pt_image *image;
 
@@ -1479,7 +1476,7 @@ btrace_compute_ftrace_pt (struct thread_info *tp,
 
       ftrace_add_pt (btinfo, decoder, &level, gaps);
     }
-  CATCH (error, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &error)
     {
       /* Indicate a gap in the trace if we quit trace processing.  */
       if (error.reason == RETURN_QUIT && !btinfo->functions.empty ())
@@ -1489,7 +1486,6 @@ btrace_compute_ftrace_pt (struct thread_info *tp,
 
       throw_exception (error);
     }
-  END_CATCH
 
   btrace_finalize_ftrace_pt (decoder, tp, level);
 }
@@ -1556,17 +1552,16 @@ btrace_compute_ftrace (struct thread_info *tp, struct btrace_data *btrace,
 {
   std::vector<unsigned int> gaps;
 
-  TRY
+  try
     {
       btrace_compute_ftrace_1 (tp, btrace, cpu, gaps);
     }
-  CATCH (error, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &error)
     {
       btrace_finalize_ftrace (tp, gaps);
 
       throw_exception (error);
     }
-  END_CATCH
 
   btrace_finalize_ftrace (tp, gaps);
 }
@@ -1617,7 +1612,7 @@ btrace_enable (struct thread_info *tp, const struct btrace_config *conf)
     return;
 
   /* We need to undo the enable in case of errors.  */
-  TRY
+  try
     {
       /* Add an entry for the current PC so we start tracing from where we
 	 enabled it.
@@ -1632,13 +1627,12 @@ btrace_enable (struct thread_info *tp, const struct btrace_config *conf)
 	  && can_access_registers_thread (tp))
 	btrace_add_pc (tp);
     }
-  CATCH (exception, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
     {
       btrace_disable (tp);
 
       throw_exception (exception);
     }
-  END_CATCH
 }
 
 /* See btrace.h.  */
@@ -3062,18 +3056,17 @@ btrace_maint_update_pt_packets (struct btrace_thread_info *btinfo)
   if (decoder == NULL)
     error (_("Failed to allocate the Intel Processor Trace decoder."));
 
-  TRY
+  try
     {
       btrace_maint_decode_pt (&btinfo->maint, decoder);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       pt_pkt_free_decoder (decoder);
 
       if (except.reason < 0)
 	throw_exception (except);
     }
-  END_CATCH
 
   pt_pkt_free_decoder (decoder);
 }
diff --git a/gdb/c-varobj.c b/gdb/c-varobj.c
index 2d247745c04..df06caacb32 100644
--- a/gdb/c-varobj.c
+++ b/gdb/c-varobj.c
@@ -92,16 +92,15 @@ adjust_value_for_child_access (struct value **value,
 	  if (value && *value)
 	    {
 
-	      TRY
+	      try
 		{
 		  *value = value_ind (*value);
 		}
 
-	      CATCH (except, RETURN_MASK_ERROR)
+	      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 		{
 		  *value = NULL;
 		}
-	      END_CATCH
 	    }
 	  *type = target_type;
 	  if (was_ptr)
@@ -253,18 +252,17 @@ value_struct_element_index (struct value *value, int type_index)
   gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
 	      || TYPE_CODE (type) == TYPE_CODE_UNION);
 
-  TRY
+  try
     {
       if (field_is_static (&TYPE_FIELD (type, type_index)))
 	result = value_static_field (type, type_index);
       else
 	result = value_primitive_field (value, 0, type_index, type);
     }
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       return NULL;
     }
-  END_CATCH
 
   return result;
 }
@@ -316,14 +314,13 @@ c_describe_child (const struct varobj *parent, int index,
 	{
 	  int real_index = index + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
 
-	  TRY
+	  try
 	    {
 	      *cvalue = value_subscript (value, real_index);
 	    }
-	  CATCH (except, RETURN_MASK_ERROR)
+	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	    {
 	    }
-	  END_CATCH
 	}
 
       if (ctype)
@@ -393,16 +390,15 @@ c_describe_child (const struct varobj *parent, int index,
 
       if (cvalue && value)
 	{
-	  TRY
+	  try
 	    {
 	      *cvalue = value_ind (value);
 	    }
 
-	  CATCH (except, RETURN_MASK_ERROR)
+	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	    {
 	      *cvalue = NULL;
 	    }
-	  END_CATCH
 	}
 
       /* Don't use get_target_type because it calls
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index fa99503b0ca..4cf2a5919cf 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -250,7 +250,7 @@ complete_command (const char *arg, int from_tty)
   int quote_char = '\0';
   const char *word;
 
-  TRY
+  try
     {
       word = completion_find_completion_word (tracker_handle_brkchars,
 					      arg, &quote_char);
@@ -267,11 +267,10 @@ complete_command (const char *arg, int from_tty)
 	  tracker = &tracker_handle_completions;
 	}
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       return;
     }
-  END_CATCH
 
   std::string arg_prefix (arg, word - arg);
 
diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index 088f4f1f89c..15373be77f1 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -363,15 +363,14 @@ safe_execute_command (struct ui_out *command_uiout, const char *command,
   scoped_restore saved_uiout = make_scoped_restore (&current_uiout,
 						    command_uiout);
 
-  TRY
+  try
     {
       execute_command (command, from_tty);
     }
-  CATCH (exception, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
     {
       e = exception;
     }
-  END_CATCH
 
   /* FIXME: cagney/2005-01-13: This shouldn't be needed.  Instead the
      caller should print the exception.  */
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index c02c7880648..f0080f950f1 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -1050,16 +1050,15 @@ process_next_line (const char *p, struct command_line **command,
 
   if (validator)
     {
-      TRY
+      try
 	{
 	  validator ((*command)->line);
 	}
-      CATCH (ex, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	{
 	  free_command_lines (command);
 	  throw_exception (ex);
 	}
-      END_CATCH
     }
 
   /* Nothing special.  */
@@ -1543,11 +1542,11 @@ script_from_file (FILE *stream, const char *file)
 
   scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
 
-  TRY
+  try
     {
       read_command_file (stream);
     }
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       /* Re-throw the error, but with the file name information
 	 prepended.  */
@@ -1556,7 +1555,6 @@ script_from_file (FILE *stream, const char *file)
 		   source_file_name.c_str (), source_line_number,
 		   e.message.c_str ());
     }
-  END_CATCH
 }
 
 /* Print the definition of user command C to STREAM.  Or, if C is a
diff --git a/gdb/common/new-op.c b/gdb/common/new-op.c
index cff6686ef12..b6c13afca19 100644
--- a/gdb/common/new-op.c
+++ b/gdb/common/new-op.c
@@ -60,15 +60,14 @@ operator new (std::size_t sz)
 	 QUIT gdb_exception.  This is necessary because operator new
 	 can only ever throw std::bad_alloc, or something that extends
 	 it.  */
-      TRY
+      try
 	{
 	  malloc_failure (sz);
 	}
-      CATCH (ex, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	{
 	  throw gdb_quit_bad_alloc (ex);
 	}
-      END_CATCH
     }
   return p;
 }
diff --git a/gdb/common/selftest.c b/gdb/common/selftest.c
index 6f972e17910..cd43b2740c8 100644
--- a/gdb/common/selftest.c
+++ b/gdb/common/selftest.c
@@ -81,18 +81,17 @@ run_tests (const char *filter)
 	  && name.find (filter) == std::string::npos)
 	continue;
 
-      TRY
+      try
 	{
 	  debug_printf (_("Running selftest %s.\n"), name.c_str ());
 	  ++ran;
 	  (*test) ();
 	}
-      CATCH (ex, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 	{
 	  ++failed;
 	  debug_printf ("Self test failed: %s\n", ex.message.c_str ());
 	}
-      END_CATCH
 
       reset ();
     }
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index 1a1c10e9308..a75161c5ca4 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -344,7 +344,7 @@ gcc_convert_symbol (void *datum,
 
   /* We can't allow exceptions to escape out of this callback.  Safest
      is to simply emit a gcc error.  */
-  TRY
+  try
     {
       struct block_symbol sym;
 
@@ -367,11 +367,10 @@ gcc_convert_symbol (void *datum,
 	}
     }
 
-  CATCH (e, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &e)
     {
       context->plugin ().error (e.message.c_str ());
     }
-  END_CATCH
 
   if (compile_debug && !found)
     fprintf_unfiltered (gdb_stdlog,
@@ -393,7 +392,7 @@ gcc_symbol_address (void *datum, struct gcc_c_context *gcc_context,
 
   /* We can't allow exceptions to escape out of this callback.  Safest
      is to simply emit a gcc error.  */
-  TRY
+  try
     {
       struct symbol *sym;
 
@@ -430,11 +429,10 @@ gcc_symbol_address (void *datum, struct gcc_c_context *gcc_context,
 	}
     }
 
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       context->plugin ().error (e.message.c_str ());
     }
-  END_CATCH
 
   if (compile_debug && !found)
     fprintf_unfiltered (gdb_stdlog,
@@ -548,7 +546,7 @@ generate_c_for_for_one_variable (compile_instance *compiler,
 				 struct symbol *sym)
 {
 
-  TRY
+  try
     {
       if (is_dynamic_type (SYMBOL_TYPE (sym)))
 	{
@@ -600,11 +598,10 @@ generate_c_for_for_one_variable (compile_instance *compiler,
 	}
     }
 
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       compiler->insert_symbol_error (sym, e.message.c_str ());
     }
-  END_CATCH
 }
 
 /* See compile-c.h.  */
diff --git a/gdb/compile/compile-cplus-symbols.c b/gdb/compile/compile-cplus-symbols.c
index 83289e37cdd..cc8f6ee3176 100644
--- a/gdb/compile/compile-cplus-symbols.c
+++ b/gdb/compile/compile-cplus-symbols.c
@@ -343,7 +343,7 @@ gcc_cplus_convert_symbol (void *datum,
   bool found = false;
   compile_cplus_instance *instance = (compile_cplus_instance *) datum;
 
-  TRY
+  try
     {
       /* Symbol searching is a three part process unfortunately.  */
 
@@ -388,13 +388,12 @@ gcc_cplus_convert_symbol (void *datum,
 	    }
 	}
     }
-  CATCH (e, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &e)
     {
       /* We can't allow exceptions to escape out of this callback.  Safest
 	 is to simply emit a gcc error.  */
       instance->plugin ().error (e.message.c_str ());
     }
-  END_CATCH
 
   if (compile_debug && !found)
     fprintf_unfiltered (gdb_stdlog,
@@ -431,7 +430,7 @@ gcc_cplus_symbol_address (void *datum, struct gcc_cp_context *gcc_context,
 
   /* We can't allow exceptions to escape out of this callback.  Safest
      is to simply emit a gcc error.  */
-  TRY
+  try
     {
       struct symbol *sym
 	= lookup_symbol (identifier, nullptr, VAR_DOMAIN, nullptr).symbol;
@@ -467,11 +466,10 @@ gcc_cplus_symbol_address (void *datum, struct gcc_cp_context *gcc_context,
 	}
     }
 
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       instance->plugin ().error (e.message.c_str ());
     }
-  END_CATCH
 
   if (compile_debug && !found)
     fprintf_unfiltered (gdb_stdlog,
diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c
index db8238dc1e1..4885929d608 100644
--- a/gdb/compile/compile-object-load.c
+++ b/gdb/compile/compile-object-load.c
@@ -50,16 +50,15 @@ munmap_list::~munmap_list ()
 {
   for (auto &item : items)
     {
-      TRY
+      try
 	{
 	  gdbarch_infcall_munmap (target_gdbarch (), item.addr, item.size);
 	}
-      CATCH (ex, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 	{
 	  /* There's not much the user can do, so just ignore
 	     this.  */
 	}
-      END_CATCH
     }
 }
 
diff --git a/gdb/compile/compile-object-run.c b/gdb/compile/compile-object-run.c
index 82b839336ba..3639efd4179 100644
--- a/gdb/compile/compile-object-run.c
+++ b/gdb/compile/compile-object-run.c
@@ -137,7 +137,7 @@ compile_object_run (struct compile_module *module)
   xfree (module);
   module = NULL;
 
-  TRY
+  try
     {
       struct type *func_type = SYMBOL_TYPE (func_sym);
       htab_t copied_types;
@@ -173,7 +173,7 @@ compile_object_run (struct compile_module *module)
       call_function_by_hand_dummy (func_val, NULL, args,
 				   do_module_cleanup, data);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       /* In the case of DTOR_FOUND or in the case of EXECUTED nothing
 	 needs to be done.  */
@@ -185,7 +185,6 @@ compile_object_run (struct compile_module *module)
 	do_module_cleanup (data, 0);
       throw_exception (ex);
     }
-  END_CATCH
 
   dtor_found = find_dummy_frame_dtor (do_module_cleanup, data);
   gdb_assert (!dtor_found && executed);
diff --git a/gdb/completer.c b/gdb/completer.c
index d7cf4fd1203..b946c696f23 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -1021,15 +1021,14 @@ complete_expression (completion_tracker &tracker,
 
   /* Perform a tentative parse of the expression, to see whether a
      field completion is required.  */
-  TRY
+  try
     {
       type = parse_expression_for_completion (text, &fieldname, &code);
     }
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       return;
     }
-  END_CATCH
 
   if (fieldname != nullptr && type)
     {
@@ -1445,16 +1444,15 @@ complete_line_internal (completion_tracker &tracker,
 			const char *line_buffer, int point,
 			complete_line_internal_reason reason)
 {
-  TRY
+  try
     {
       complete_line_internal_1 (tracker, text, line_buffer, point, reason);
     }
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       if (except.error != MAX_COMPLETIONS_REACHED_ERROR)
 	throw_exception (except);
     }
-  END_CATCH
 }
 
 /* See completer.h.  */
@@ -1859,17 +1857,16 @@ gdb_completion_word_break_characters ()
   /* New completion starting.  */
   current_completion.aborted = false;
 
-  TRY
+  try
     {
       return gdb_completion_word_break_characters_throw ();
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       /* Set this to that gdb_rl_attempted_completion_function knows
 	 to abort early.  */
       current_completion.aborted = true;
     }
-  END_CATCH
 
   return NULL;
 }
@@ -2207,14 +2204,13 @@ gdb_rl_attempted_completion_function (const char *text, int start, int end)
   if (current_completion.aborted)
     return NULL;
 
-  TRY
+  try
     {
       return gdb_rl_attempted_completion_function_throw (text, start, end);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
     }
-  END_CATCH
 
   return NULL;
 }
diff --git a/gdb/corelow.c b/gdb/corelow.c
index 6a29d6a2328..f162ff9606c 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -461,16 +461,15 @@ core_target_open (const char *arg, int from_tty)
      may be a thread_stratum target loaded on top of target core by
      now.  The layer above should claim threads found in the BFD
      sections.  */
-  TRY
+  try
     {
       target_update_thread_list ();
     }
 
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       exception_print (gdb_stderr, except);
     }
-  END_CATCH
 
   p = bfd_core_file_failing_command (core_bfd);
   if (p)
@@ -517,15 +516,14 @@ core_target_open (const char *arg, int from_tty)
      anything about threads.  That is why the test is >= 2.  */
   if (thread_count () >= 2)
     {
-      TRY
+      try
 	{
 	  thread_command (NULL, from_tty);
 	}
-      CATCH (except, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	{
 	  exception_print (gdb_stderr, except);
 	}
-      END_CATCH
     }
 }
 
diff --git a/gdb/cp-abi.c b/gdb/cp-abi.c
index b858b190668..800a3b41322 100644
--- a/gdb/cp-abi.c
+++ b/gdb/cp-abi.c
@@ -73,13 +73,13 @@ baseclass_offset (struct type *type, int index, const gdb_byte *valaddr,
 
   gdb_assert (current_cp_abi.baseclass_offset != NULL);
 
-  TRY
+  try
     {
       res = (*current_cp_abi.baseclass_offset) (type, index, valaddr,
 						embedded_offset,
 						address, val);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
@@ -88,7 +88,6 @@ baseclass_offset (struct type *type, int index, const gdb_byte *valaddr,
 		   _("Cannot determine virtual baseclass offset "
 		     "of incomplete object"));
     }
-  END_CATCH
 
   return res;
 }
@@ -112,15 +111,14 @@ value_rtti_type (struct value *v, int *full,
 
   if ((current_cp_abi.rtti_type) == NULL)
     return NULL;
-  TRY
+  try
     {
       ret = (*current_cp_abi.rtti_type) (v, full, top, using_enc);
     }
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       return NULL;
     }
-  END_CATCH
 
   return ret;
 }
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index e3d6112f23e..87ae5361ebd 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -151,15 +151,14 @@ inspect_type (struct demangle_parse_info *info,
 
   sym = NULL;
 
-  TRY
+  try
     {
       sym = lookup_symbol (name, 0, VAR_DOMAIN, 0).symbol;
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       return 0;
     }
-  END_CATCH
 
   if (sym != NULL)
     {
@@ -223,17 +222,16 @@ inspect_type (struct demangle_parse_info *info,
 	    }
 
 	  string_file buf;
-	  TRY
+	  try
 	    {
 	      type_print (type, "", &buf, -1);
 	    }
 	  /* If type_print threw an exception, there is little point
 	     in continuing, so just bow out gracefully.  */
-	  CATCH (except, RETURN_MASK_ERROR)
+	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	    {
 	      return 0;
 	    }
-	  END_CATCH
 
 	  len = buf.size ();
 	  name = (char *) obstack_copy0 (&info->obstack, buf.c_str (), len);
@@ -424,15 +422,14 @@ replace_typedefs (struct demangle_parse_info *info,
 	      struct symbol *sym = NULL;
 
 	      sym = NULL;
-	      TRY
+	      try
 		{
 		  sym = lookup_symbol (local_name.get (), 0,
 				       VAR_DOMAIN, 0).symbol;
 		}
-	      CATCH (except, RETURN_MASK_ALL)
+	      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
 		{
 		}
-	      END_CATCH
 
 	      if (sym != NULL)
 		{
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index b4478ee644c..0d4cd49683a 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -316,18 +316,17 @@ cp_print_value_fields (struct type *type, struct type *real_type,
 		{
 		  struct value *v = NULL;
 
-		  TRY
+		  try
 		    {
 		      v = value_static_field (type, i);
 		    }
 
-		  CATCH (ex, RETURN_MASK_ERROR)
+		  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 		    {
 		      fprintf_filtered (stream,
 					_("<error reading variable: %s>"),
 					ex.message.c_str ());
 		    }
-		  END_CATCH
 
 		  cp_print_static_field (TYPE_FIELD_TYPE (type, i),
 					 v, stream, recurse + 1,
@@ -505,18 +504,17 @@ cp_print_value (struct type *type, struct type *real_type,
       thisoffset = offset;
       thistype = real_type;
 
-      TRY
+      try
 	{
 	  boffset = baseclass_offset (type, i, valaddr, offset, address, val);
 	}
-      CATCH (ex, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 	{
 	  if (ex.error == NOT_AVAILABLE_ERROR)
 	    skip = -1;
 	  else
 	    skip = 1;
 	}
-      END_CATCH
 
       if (skip == 0)
 	{
diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c
index 0a75ad3e484..7ac1df0c90f 100644
--- a/gdb/darwin-nat.c
+++ b/gdb/darwin-nat.c
@@ -1611,7 +1611,7 @@ darwin_attach_pid (struct inferior *inf)
   darwin_inferior *priv = new darwin_inferior;
   inf->priv.reset (priv);
 
-  TRY
+  try
     {
       kret = task_for_pid (gdb_task, inf->pid, &priv->task);
       if (kret != KERN_SUCCESS)
@@ -1688,14 +1688,13 @@ darwin_attach_pid (struct inferior *inf)
 
       darwin_setup_exceptions (inf);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       exit_inferior (inf);
       inferior_ptid = null_ptid;
 
       throw_exception (ex);
     }
-  END_CATCH
 
   target_ops *darwin_ops = get_native_target ();
   if (!target_is_pushed (darwin_ops))
@@ -1949,11 +1948,11 @@ The error was: %s"),
   /* Maybe it was cached by some earlier gdb.  */
   if (stat (new_name.c_str (), &sb) != 0 || !S_ISREG (sb.st_mode))
     {
-      TRY
+      try
 	{
 	  copy_shell_to_cache (shell, new_name);
 	}
-      CATCH (ex, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 	{
 	  warning (_("This version of macOS has System Integrity Protection.\n\
 Because `startup-with-shell' is enabled, gdb tried to work around SIP by\n\
@@ -1965,7 +1964,6 @@ you \"run\".  To prevent these attempts, you can use:\n\
 		   ex.message.c_str ());
 	  return false;
 	}
-      END_CATCH
 
       printf_filtered (_("Note: this version of macOS has System Integrity Protection.\n\
 Because `startup-with-shell' is enabled, gdb has worked around this by\n\
diff --git a/gdb/disasm-selftests.c b/gdb/disasm-selftests.c
index 48b466baf13..8d2bb2e79ef 100644
--- a/gdb/disasm-selftests.c
+++ b/gdb/disasm-selftests.c
@@ -192,16 +192,15 @@ memory_error_test (struct gdbarch *gdbarch)
   gdb_disassembler_test di (gdbarch);
   bool saw_memory_error = false;
 
-  TRY
+  try
     {
       di.print_insn (0);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error == MEMORY_ERROR)
 	saw_memory_error = true;
     }
-  END_CATCH
 
   /* Expect MEMORY_ERROR.  */
   SELF_CHECK (saw_memory_error);
diff --git a/gdb/dtrace-probe.c b/gdb/dtrace-probe.c
index 527e0f0cd57..075eb2725d2 100644
--- a/gdb/dtrace-probe.c
+++ b/gdb/dtrace-probe.c
@@ -484,15 +484,14 @@ dtrace_process_dof_probe (struct objfile *objfile,
 	     int'.  */
           struct type *type = builtin_type (gdbarch)->builtin_long;
 
-	  TRY
+	  try
 	    {
 	      expr = parse_expression_with_language (type_str.c_str (),
 						     language_c);
 	    }
-	  CATCH (ex, RETURN_MASK_ERROR)
+	  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 	    {
 	    }
-	  END_CATCH
 
 	  if (expr != NULL && expr.get ()->elts[0].opcode == OP_TYPE)
 	    type = expr.get ()->elts[1].type;
diff --git a/gdb/dwarf-index-cache.c b/gdb/dwarf-index-cache.c
index ab5b6aa9419..5057d5e744b 100644
--- a/gdb/dwarf-index-cache.c
+++ b/gdb/dwarf-index-cache.c
@@ -110,7 +110,7 @@ index_cache::store (struct dwarf2_per_objfile *dwarf2_per_objfile)
 
   std::string build_id_str = build_id_to_string (build_id);
 
-  TRY
+  try
     {
       /* Try to create the containing directory.  */
       if (!mkdir_recursive (m_dir.c_str ()))
@@ -129,13 +129,12 @@ index_cache::store (struct dwarf2_per_objfile *dwarf2_per_objfile)
       write_psymtabs_to_index (dwarf2_per_objfile, m_dir.c_str (),
 			       build_id_str.c_str (), dw_index_kind::GDB_INDEX);
     }
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       if (debug_index_cache)
 	printf_unfiltered ("index cache: couldn't store index cache for objfile "
 			   "%s: %s", objfile_name (obj), except.message.c_str ());
     }
-  END_CATCH
 }
 
 #if HAVE_SYS_MMAN_H
@@ -172,7 +171,7 @@ index_cache::lookup_gdb_index (const bfd_build_id *build_id,
   /* Compute where we would expect a gdb index file for this build id to be.  */
   std::string filename = make_index_filename (build_id, INDEX4_SUFFIX);
 
-  TRY
+  try
     {
       if (debug_index_cache)
         printf_unfiltered ("index cache: trying to read %s\n",
@@ -189,13 +188,12 @@ index_cache::lookup_gdb_index (const bfd_build_id *build_id,
 	  ((const gdb_byte *) mmap_resource->mapping.get (),
 	   mmap_resource->mapping.size ());
     }
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       if (debug_index_cache)
 	printf_unfiltered ("index cache: couldn't read %s: %s\n",
 			   filename.c_str (), except.message.c_str ());
     }
-  END_CATCH
 
   return {};
 }
diff --git a/gdb/dwarf-index-write.c b/gdb/dwarf-index-write.c
index 01c1256bcb6..89cafdc8585 100644
--- a/gdb/dwarf-index-write.c
+++ b/gdb/dwarf-index-write.c
@@ -1675,19 +1675,18 @@ save_gdb_index_command (const char *arg, int from_tty)
 
       if (dwarf2_per_objfile != NULL)
 	{
-	  TRY
+	  try
 	    {
 	      const char *basename = lbasename (objfile_name (objfile));
 	      write_psymtabs_to_index (dwarf2_per_objfile, arg, basename,
 				       index_kind);
 	    }
-	  CATCH (except, RETURN_MASK_ERROR)
+	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	    {
 	      exception_fprintf (gdb_stderr, except,
 				 _("Error while writing index for `%s': "),
 				 objfile_name (objfile));
 	    }
-	  END_CATCH
 	    }
 
     }
diff --git a/gdb/dwarf2-frame-tailcall.c b/gdb/dwarf2-frame-tailcall.c
index 4cf7f5ff63a..adb38b9cf84 100644
--- a/gdb/dwarf2-frame-tailcall.c
+++ b/gdb/dwarf2-frame-tailcall.c
@@ -377,7 +377,7 @@ dwarf2_tailcall_sniffer_first (struct frame_info *this_frame,
   this_pc = get_frame_address_in_block (this_frame);
 
   /* Catch any unwinding errors.  */
-  TRY
+  try
     {
       int sp_regnum;
 
@@ -399,13 +399,12 @@ dwarf2_tailcall_sniffer_first (struct frame_info *this_frame,
 	    }
 	}
     }
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       if (entry_values_debug)
 	exception_print (gdb_stdout, except);
       return;
     }
-  END_CATCH
 
   /* Ambiguous unwind or unambiguous unwind verified as matching.  */
   if (chain == NULL || chain->length == 0)
diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c
index 21d826b012e..ca5ced7135e 100644
--- a/gdb/dwarf2-frame.c
+++ b/gdb/dwarf2-frame.c
@@ -1044,7 +1044,7 @@ dwarf2_frame_cache (struct frame_info *this_frame, void **this_cache)
   execute_cfa_program (fde, instr, fde->end, gdbarch,
 		       get_frame_address_in_block (this_frame), &fs);
 
-  TRY
+  try
     {
       /* Calculate the CFA.  */
       switch (fs.regs.cfa_how)
@@ -1068,7 +1068,7 @@ dwarf2_frame_cache (struct frame_info *this_frame, void **this_cache)
 	  internal_error (__FILE__, __LINE__, _("Unknown CFA rule."));
 	}
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error == NOT_AVAILABLE_ERROR)
 	{
@@ -1078,7 +1078,6 @@ dwarf2_frame_cache (struct frame_info *this_frame, void **this_cache)
 
       throw_exception (ex);
     }
-  END_CATCH
 
   /* Initialize the register state.  */
   {
@@ -2245,7 +2244,7 @@ dwarf2_build_frame_info (struct objfile *objfile)
           if (txt)
             unit->tbase = txt->vma;
 
-	  TRY
+	  try
 	    {
 	      frame_ptr = unit->dwarf_frame_buffer;
 	      while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_size)
@@ -2254,7 +2253,7 @@ dwarf2_build_frame_info (struct objfile *objfile)
 						EH_CIE_OR_FDE_TYPE_ID);
 	    }
 
-	  CATCH (e, RETURN_MASK_ERROR)
+	  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
 	    {
 	      warning (_("skipping .eh_frame info of %s: %s"),
 		       objfile_name (objfile), e.message.c_str ());
@@ -2267,7 +2266,6 @@ dwarf2_build_frame_info (struct objfile *objfile)
 		}
 	      /* The cie_table is discarded by the next if.  */
 	    }
-	  END_CATCH
 
           if (cie_table.num_entries != 0)
             {
@@ -2287,7 +2285,7 @@ dwarf2_build_frame_info (struct objfile *objfile)
     {
       int num_old_fde_entries = fde_table.num_entries;
 
-      TRY
+      try
 	{
 	  frame_ptr = unit->dwarf_frame_buffer;
 	  while (frame_ptr < unit->dwarf_frame_buffer + unit->dwarf_frame_size)
@@ -2295,7 +2293,7 @@ dwarf2_build_frame_info (struct objfile *objfile)
 					    &cie_table, &fde_table,
 					    EH_CIE_OR_FDE_TYPE_ID);
 	}
-      CATCH (e, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
 	{
 	  warning (_("skipping .debug_frame info of %s: %s"),
 		   objfile_name (objfile), e.message.c_str ());
@@ -2318,7 +2316,6 @@ dwarf2_build_frame_info (struct objfile *objfile)
 	  fde_table.num_entries = num_old_fde_entries;
 	  /* The cie_table is discarded by the next if.  */
 	}
-      END_CATCH
     }
 
   /* Discard the cie_table, it is no longer needed.  */
diff --git a/gdb/dwarf2loc.c b/gdb/dwarf2loc.c
index 9c974a11133..80d0b44306f 100644
--- a/gdb/dwarf2loc.c
+++ b/gdb/dwarf2loc.c
@@ -1195,11 +1195,11 @@ call_site_find_chain (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
 {
   struct call_site_chain *retval = NULL;
 
-  TRY
+  try
     {
       retval = call_site_find_chain_1 (gdbarch, caller_pc, callee_pc);
     }
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       if (e.error == NO_ENTRY_VALUE_ERROR)
 	{
@@ -1211,7 +1211,6 @@ call_site_find_chain (struct gdbarch *gdbarch, CORE_ADDR caller_pc,
       else
 	throw_exception (e);
     }
-  END_CATCH
 
   return retval;
 }
@@ -2165,11 +2164,11 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
   ctx.ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu);
   ctx.offset = dwarf2_per_cu_text_offset (per_cu);
 
-  TRY
+  try
     {
       ctx.eval (data, size);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error == NOT_AVAILABLE_ERROR)
 	{
@@ -2189,7 +2188,6 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
       else
 	throw_exception (ex);
     }
-  END_CATCH
 
   if (ctx.pieces.size () > 0)
     {
@@ -2383,11 +2381,11 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
   ctx.ref_addr_size = dwarf2_per_cu_ref_addr_size (dlbaton->per_cu);
   ctx.offset = dwarf2_per_cu_text_offset (dlbaton->per_cu);
 
-  TRY
+  try
     {
       ctx.eval (dlbaton->data, dlbaton->size);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error == NOT_AVAILABLE_ERROR)
 	{
@@ -2402,7 +2400,6 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
       else
 	throw_exception (ex);
     }
-  END_CATCH
 
   switch (ctx.location)
     {
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 2d6cb353fbb..0d6f84c59a6 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -6333,7 +6333,7 @@ dwarf2_build_psymtabs (struct objfile *objfile)
 
   init_psymbol_list (objfile, 1024);
 
-  TRY
+  try
     {
       /* This isn't really ideal: all the data we allocate on the
 	 objfile's obstack is still uselessly kept around.  However,
@@ -6345,11 +6345,10 @@ dwarf2_build_psymtabs (struct objfile *objfile)
       /* (maybe) store an index in the cache.  */
       global_index_cache.store (dwarf2_per_objfile);
     }
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       exception_print (gdb_stderr, except);
     }
-  END_CATCH
 }
 
 /* Return the total length of the CU described by HEADER.  */
diff --git a/gdb/eval.c b/gdb/eval.c
index 47d08a656c0..7a1efbe25fd 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -201,11 +201,11 @@ fetch_subexp_value (struct expression *exp, int *pc, struct value **valp,
   mark = value_mark ();
   result = NULL;
 
-  TRY
+  try
     {
       result = evaluate_subexp (NULL_TYPE, exp, pc, EVAL_NORMAL);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       /* Ignore memory errors if we want watchpoints pointing at
 	 inaccessible memory to still be created; otherwise, throw the
@@ -221,7 +221,6 @@ fetch_subexp_value (struct expression *exp, int *pc, struct value **valp,
 	  break;
 	}
     }
-  END_CATCH
 
   new_mark = value_mark ();
   if (mark == new_mark)
@@ -238,15 +237,14 @@ fetch_subexp_value (struct expression *exp, int *pc, struct value **valp,
       else
 	{
 
-	  TRY
+	  try
 	    {
 	      value_fetch_lazy (result);
 	      *valp = result;
 	    }
-	  CATCH (except, RETURN_MASK_ERROR)
+	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	    {
 	    }
-	  END_CATCH
 	}
     }
 
@@ -716,19 +714,18 @@ evaluate_var_value (enum noside noside, const block *blk, symbol *var)
 
   struct value *ret = NULL;
 
-  TRY
+  try
     {
       ret = value_of_variable (var, blk);
     }
 
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       if (noside != EVAL_AVOID_SIDE_EFFECTS)
 	throw_exception (except);
 
       ret = value_zero (SYMBOL_TYPE (var), not_lval);
     }
-  END_CATCH
 
   return ret;
 }
@@ -957,19 +954,18 @@ evaluate_funcall (type *expect_type, expression *exp, int *pos,
 	  while (unop_user_defined_p (op, arg2))
 	    {
 	      struct value *value = NULL;
-	      TRY
+	      try
 		{
 		  value = value_x_unop (arg2, op, noside);
 		}
 
-	      CATCH (except, RETURN_MASK_ERROR)
+	      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 		{
 		  if (except.error == NOT_FOUND_ERROR)
 		    break;
 		  else
 		    throw_exception (except);
 		}
-	      END_CATCH
 
 		arg2 = value;
 	    }
@@ -2030,19 +2026,18 @@ evaluate_subexp_standard (struct type *expect_type,
       while (unop_user_defined_p (op, arg1))
 	{
 	  struct value *value = NULL;
-	  TRY
+	  try
 	    {
 	      value = value_x_unop (arg1, op, noside);
 	    }
 
-	  CATCH (except, RETURN_MASK_ERROR)
+	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	    {
 	      if (except.error == NOT_FOUND_ERROR)
 		break;
 	      else
 		throw_exception (except);
 	    }
-	  END_CATCH
 
 	  arg1 = value;
 	}
diff --git a/gdb/event-loop.c b/gdb/event-loop.c
index 28e81646fbd..e73443ed779 100644
--- a/gdb/event-loop.c
+++ b/gdb/event-loop.c
@@ -366,11 +366,11 @@ start_event_loop (void)
     {
       int result = 0;
 
-      TRY
+      try
 	{
 	  result = gdb_do_one_event ();
 	}
-      CATCH (ex, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	{
 	  exception_print (gdb_stderr, ex);
 
@@ -394,7 +394,6 @@ start_event_loop (void)
 	  /* Maybe better to set a flag to be checked somewhere as to
 	     whether display the prompt or not.  */
 	}
-      END_CATCH
 
       if (result < 0)
 	break;
diff --git a/gdb/event-top.c b/gdb/event-top.c
index fb5d51c6e10..ea056dd99e2 100644
--- a/gdb/event-top.c
+++ b/gdb/event-top.c
@@ -208,15 +208,14 @@ gdb_rl_callback_handler (char *rl) noexcept
   struct gdb_exception gdb_rl_expt = exception_none;
   struct ui *ui = current_ui;
 
-  TRY
+  try
     {
       ui->input_handler (gdb::unique_xmalloc_ptr<char> (rl));
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       gdb_rl_expt = ex;
     }
-  END_CATCH
 
   /* If we caught a GDB exception, longjmp out of the readline
      callback.  There's no other way for the callback to signal to
@@ -1082,27 +1081,25 @@ static void
 async_disconnect (gdb_client_data arg)
 {
 
-  TRY
+  try
     {
       quit_cover ();
     }
 
-  CATCH (exception, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
     {
       fputs_filtered ("Could not kill the program being debugged",
 		      gdb_stderr);
       exception_print (gdb_stderr, exception);
     }
-  END_CATCH
 
-  TRY
+  try
     {
       pop_all_targets ();
     }
-  CATCH (exception, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
     {
     }
-  END_CATCH
 
   signal (SIGHUP, SIG_DFL);	/*FIXME: ???????????  */
   raise (SIGHUP);
diff --git a/gdb/exec.c b/gdb/exec.c
index 706de9e32f0..fcee12da87b 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -161,33 +161,31 @@ try_open_exec_file (const char *exec_file_host, struct inferior *inf,
      Even without a symbol file, the remote-based debugging session should
      continue normally instead of ending abruptly.  Hence we catch thrown
      errors/exceptions in the following code.  */
-  TRY
+  try
     {
       /* We must do this step even if exec_file_host is NULL, so that
 	 exec_file_attach will clear state.  */
       exec_file_attach (exec_file_host, add_flags & SYMFILE_VERBOSE);
     }
-  CATCH (err, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &err)
     {
       if (!err.message.empty ())
 	warning ("%s", err.message.c_str ());
 
       prev_err = err;
     }
-  END_CATCH
 
   if (exec_file_host != NULL)
     {
-      TRY
+      try
 	{
 	  symbol_file_add_main (exec_file_host, add_flags);
 	}
-      CATCH (err, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &err)
 	{
 	  if (!exception_print_same (prev_err, err))
 	    warning ("%s", err.message.c_str ());
 	}
-      END_CATCH
     }
 }
 
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index d67aad20ba7..c82d7f3d749 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -408,18 +408,17 @@ info_common_command_for_block (const struct block *block, const char *comname,
 	    printf_filtered ("%s = ",
 			     SYMBOL_PRINT_NAME (common->contents[index]));
 
-	    TRY
+	    try
 	      {
 		val = value_of_variable (common->contents[index], block);
 		value_print (val, gdb_stdout, &opts);
 	      }
 
-	    CATCH (except, RETURN_MASK_ERROR)
+	    catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	      {
 		printf_filtered ("<error reading variable: %s>",
 				 except.message.c_str ());
 	      }
-	    END_CATCH
 
 	    putchar_filtered ('\n');
 	  }
diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
index d971d3a6533..eeac945e713 100644
--- a/gdb/fbsd-tdep.c
+++ b/gdb/fbsd-tdep.c
@@ -715,15 +715,14 @@ fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
     }
 
   /* Thread register information.  */
-  TRY
+  try
     {
       update_thread_list ();
     }
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       exception_print (gdb_stderr, e);
     }
-  END_CATCH
 
   /* Like the kernel, prefer dumping the signalled thread first.
      "First thread" is what tools use to infer the signalled thread.
diff --git a/gdb/frame-unwind.c b/gdb/frame-unwind.c
index e5ddeba9077..5ef11d50cf0 100644
--- a/gdb/frame-unwind.c
+++ b/gdb/frame-unwind.c
@@ -101,11 +101,11 @@ frame_unwind_try_unwinder (struct frame_info *this_frame, void **this_cache,
 
   frame_prepare_for_sniffer (this_frame, unwinder);
 
-  TRY
+  try
     {
       res = unwinder->sniffer (unwinder, this_frame, this_cache);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       /* Catch all exceptions, caused by either interrupt or error.
 	 Reset *THIS_CACHE.  */
@@ -122,7 +122,6 @@ frame_unwind_try_unwinder (struct frame_info *this_frame, void **this_cache,
 	}
       throw_exception (ex);
     }
-  END_CATCH
 
   if (res)
     return 1;
diff --git a/gdb/frame.c b/gdb/frame.c
index 20721204d5e..43cc168b841 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -894,12 +894,12 @@ frame_unwind_pc (struct frame_info *this_frame)
 	 different ways that a PC could be unwound.  */
       prev_gdbarch = frame_unwind_arch (this_frame);
 
-      TRY
+      try
 	{
 	  pc = gdbarch_unwind_pc (prev_gdbarch, this_frame);
 	  pc_p = 1;
 	}
-      CATCH (ex, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 	{
 	  if (ex.error == NOT_AVAILABLE_ERROR)
 	    {
@@ -924,7 +924,6 @@ frame_unwind_pc (struct frame_info *this_frame)
 	  else
 	    throw_exception (ex);
 	}
-      END_CATCH
 
       if (pc_p)
 	{
@@ -1894,7 +1893,7 @@ get_prev_frame_if_no_cycle (struct frame_info *this_frame)
   if (prev_frame->level == 0)
     return prev_frame;
 
-  TRY
+  try
     {
       compute_frame_id (prev_frame);
       if (!frame_stash_add (prev_frame))
@@ -1914,14 +1913,13 @@ get_prev_frame_if_no_cycle (struct frame_info *this_frame)
 	  prev_frame = NULL;
 	}
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       prev_frame->next = NULL;
       this_frame->prev = NULL;
 
       throw_exception (ex);
     }
-  END_CATCH
 
   return prev_frame;
 }
@@ -2092,11 +2090,11 @@ get_prev_frame_always (struct frame_info *this_frame)
 {
   struct frame_info *prev_frame = NULL;
 
-  TRY
+  try
     {
       prev_frame = get_prev_frame_always_1 (this_frame);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error == MEMORY_ERROR)
 	{
@@ -2120,7 +2118,6 @@ get_prev_frame_always (struct frame_info *this_frame)
       else
 	throw_exception (ex);
     }
-  END_CATCH
 
   return prev_frame;
 }
@@ -2379,18 +2376,17 @@ get_frame_pc_if_available (struct frame_info *frame, CORE_ADDR *pc)
 
   gdb_assert (frame->next != NULL);
 
-  TRY
+  try
     {
       *pc = frame_unwind_pc (frame->next);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error == NOT_AVAILABLE_ERROR)
 	return 0;
       else
 	throw_exception (ex);
     }
-  END_CATCH
 
   return 1;
 }
@@ -2462,17 +2458,16 @@ get_frame_address_in_block_if_available (struct frame_info *this_frame,
 					 CORE_ADDR *pc)
 {
 
-  TRY
+  try
     {
       *pc = get_frame_address_in_block (this_frame);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error == NOT_AVAILABLE_ERROR)
 	return 0;
       throw_exception (ex);
     }
-  END_CATCH
 
   return 1;
 }
@@ -2747,17 +2742,16 @@ get_frame_language (struct frame_info *frame)
        a PC that is guaranteed to be inside the frame's code
        block.  */
 
-  TRY
+  try
     {
       pc = get_frame_address_in_block (frame);
       pc_p = 1;
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
     }
-  END_CATCH
 
   if (pc_p)
     {
diff --git a/gdb/gcore.c b/gdb/gcore.c
index d47b2baec4e..e15ed7f44fb 100644
--- a/gdb/gcore.c
+++ b/gdb/gcore.c
@@ -118,15 +118,14 @@ write_gcore_file (bfd *obfd)
 
   target_prepare_to_generate_core ();
 
-  TRY
+  try
     {
       write_gcore_file_1 (obfd);
     }
-  CATCH (e, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &e)
     {
       except = e;
     }
-  END_CATCH
 
   target_done_generating_core ();
 
diff --git a/gdb/gdbserver/gdbreplay.c b/gdb/gdbserver/gdbreplay.c
index 8b192361504..bc465b64dd8 100644
--- a/gdb/gdbserver/gdbreplay.c
+++ b/gdb/gdbserver/gdbreplay.c
@@ -525,11 +525,11 @@ captured_main (int argc, char *argv[])
 int
 main (int argc, char *argv[])
 {
-  TRY
+  try
     {
       captured_main (argc, argv);
     }
-  CATCH (exception, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
     {
       if (exception.reason == RETURN_ERROR)
 	{
@@ -539,7 +539,6 @@ main (int argc, char *argv[])
 
       exit (1);
     }
-  END_CATCH
 
   gdb_assert_not_reached ("captured_main should never return");
 }
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 8c5a51f23c6..c42a2b56b13 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -1527,7 +1527,7 @@ linux_detach_one_lwp (struct lwp_info *lwp)
   /* Preparing to resume may try to write registers, and fail if the
      lwp is zombie.  If that happens, ignore the error.  We'll handle
      it below, when detach fails with ESRCH.  */
-  TRY
+  try
     {
       /* Flush any pending changes to the process's registers.  */
       regcache_invalidate_thread (thread);
@@ -1536,12 +1536,11 @@ linux_detach_one_lwp (struct lwp_info *lwp)
       if (the_low_target.prepare_to_resume != NULL)
 	the_low_target.prepare_to_resume (lwp);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (!check_ptrace_stopped_lwp_gone (lwp))
 	throw_exception (ex);
     }
-  END_CATCH
 
   lwpid = lwpid_of (thread);
   if (ptrace (PTRACE_DETACH, lwpid, (PTRACE_TYPE_ARG3) 0,
@@ -4505,16 +4504,15 @@ static void
 linux_resume_one_lwp (struct lwp_info *lwp,
 		      int step, int signal, siginfo_t *info)
 {
-  TRY
+  try
     {
       linux_resume_one_lwp_throw (lwp, step, signal, info);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (!check_ptrace_stopped_lwp_gone (lwp))
 	throw_exception (ex);
     }
-  END_CATCH
 }
 
 /* This function is called once per thread via for_each_thread.
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 57570f97d98..58a7d6bd0f3 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -459,7 +459,7 @@ handle_btrace_general_set (char *own_buf)
       return -1;
     }
 
-  TRY
+  try
     {
       if (strcmp (op, "bts") == 0)
 	handle_btrace_enable_bts (thread);
@@ -472,11 +472,10 @@ handle_btrace_general_set (char *own_buf)
 
       write_ok (own_buf);
     }
-  CATCH (exception, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &exception)
     {
       sprintf (own_buf, "E.%s", exception.message.c_str ());
     }
-  END_CATCH
 
   return 1;
 }
@@ -1876,18 +1875,17 @@ handle_qxfer_btrace (const char *annex,
     {
       buffer_free (&cache);
 
-      TRY
+      try
 	{
 	  result = target_read_btrace (thread->btrace, &cache, type);
 	  if (result != 0)
 	    memcpy (cs.own_buf, cache.buffer, cache.used_size);
 	}
-      CATCH (exception, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &exception)
 	{
 	  sprintf (cs.own_buf, "E.%s", exception.message.c_str ());
 	  result = -1;
 	}
-      END_CATCH
 
       if (result != 0)
 	return -3;
@@ -1948,18 +1946,17 @@ handle_qxfer_btrace_conf (const char *annex,
     {
       buffer_free (&cache);
 
-      TRY
+      try
 	{
 	  result = target_read_btrace_conf (thread->btrace, &cache);
 	  if (result != 0)
 	    memcpy (cs.own_buf, cache.buffer, cache.used_size);
 	}
-      CATCH (exception, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &exception)
 	{
 	  sprintf (cs.own_buf, "E.%s", exception.message.c_str ());
 	  result = -1;
 	}
-      END_CATCH
 
       if (result != 0)
 	return -3;
@@ -3552,18 +3549,17 @@ static int exit_code;
 static void
 detach_or_kill_for_exit_cleanup ()
 {
-  TRY
+  try
     {
       detach_or_kill_for_exit ();
     }
-  CATCH (exception, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
     {
       fflush (stdout);
       fprintf (stderr, "Detach or kill failed: %s\n",
 	       exception.message.c_str ());
       exit_code = 1;
     }
-  END_CATCH
 }
 
 /* Main function.  This is called by the real "main" function,
@@ -3866,7 +3862,7 @@ captured_main (int argc, char *argv[])
 
       remote_open (port);
 
-      TRY
+      try
 	{
 	  /* Wait for events.  This will return when all event sources
 	     are removed from the event loop.  */
@@ -3931,7 +3927,7 @@ captured_main (int argc, char *argv[])
 		}
 	    }
 	}
-      CATCH (exception, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &exception)
 	{
 	  fflush (stdout);
 	  fprintf (stderr, "gdbserver: %s\n", exception.message.c_str ());
@@ -3945,7 +3941,6 @@ captured_main (int argc, char *argv[])
 	  if (run_once)
 	    throw_quit ("Quit");
 	}
-      END_CATCH
     }
 }
 
@@ -3955,11 +3950,11 @@ int
 main (int argc, char *argv[])
 {
 
-  TRY
+  try
     {
       captured_main (argc, argv);
     }
-  CATCH (exception, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
     {
       if (exception.reason == RETURN_ERROR)
 	{
@@ -3971,7 +3966,6 @@ main (int argc, char *argv[])
 
       exit (exit_code);
     }
-  END_CATCH
 
   gdb_assert_not_reached ("captured_main should never return");
 }
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index b5f269241c4..53995685db3 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2587,15 +2587,14 @@ safe_parse_type (struct gdbarch *gdbarch, char *p, int length)
   gdb_stderr = &null_stream;
 
   /* Call parse_and_eval_type() without fear of longjmp()s.  */
-  TRY
+  try
     {
       type = parse_and_eval_type (p, length);
     }
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       type = builtin_type (gdbarch)->builtin_void;
     }
-  END_CATCH
 
   /* Stop suppressing error messages.  */
   gdb_stderr = saved_gdb_stderr;
@@ -3768,15 +3767,14 @@ types_deeply_equal (struct type *type1, struct type *type2)
      of which can raise a GDB exception, so we just check and rethrow
      here.  If there is a GDB exception, a comparison is not capable
      (or trusted), so exit.  */
-  TRY
+  try
     {
       result = check_types_worklist (&worklist, cache);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       except = ex;
     }
-  END_CATCH
 
   bcache_xfree (cache);
 
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index 952553f43ab..ae19f13d118 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -906,16 +906,15 @@ print_one_vtable (struct gdbarch *gdbarch, struct value *value,
       if (gdbarch_vtable_function_descriptors (gdbarch))
 	vfn = value_addr (vfn);
 
-      TRY
+      try
 	{
 	  addr = value_as_address (vfn);
 	}
-      CATCH (ex, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 	{
 	  printf_filtered (_("<error: %s>"), ex.message.c_str ());
 	  got_error = 1;
 	}
-      END_CATCH
 
       if (!got_error)
 	print_function_pointer_address (opts, gdbarch, addr, gdb_stdout);
diff --git a/gdb/guile/guile-internal.h b/gdb/guile/guile-internal.h
index d05f4680adf..122668da52f 100644
--- a/gdb/guile/guile-internal.h
+++ b/gdb/guile/guile-internal.h
@@ -677,15 +677,14 @@ gdbscm_wrap (Function &&func, Args &&... args)
 {
   SCM result = SCM_BOOL_F;
 
-  TRY
+  try
     {
       result = func (std::forward<Args> (args)...);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   if (gdbscm_is_exception (result))
     gdbscm_throw (result);
diff --git a/gdb/guile/scm-block.c b/gdb/guile/scm-block.c
index df1dfe57526..e3d7005cd66 100644
--- a/gdb/guile/scm-block.c
+++ b/gdb/guile/scm-block.c
@@ -680,18 +680,17 @@ gdbscm_lookup_block (SCM pc_scm)
 
   gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, NULL, "U", pc_scm, &pc);
 
-  TRY
+  try
     {
       cust = find_pc_compunit_symtab (pc);
 
       if (cust != NULL && COMPUNIT_OBJFILE (cust) != NULL)
 	block = block_for_pc (pc);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   if (cust == NULL || COMPUNIT_OBJFILE (cust) == NULL)
     {
diff --git a/gdb/guile/scm-breakpoint.c b/gdb/guile/scm-breakpoint.c
index d052748dd40..07aebdf80ef 100644
--- a/gdb/guile/scm-breakpoint.c
+++ b/gdb/guile/scm-breakpoint.c
@@ -429,7 +429,7 @@ gdbscm_register_breakpoint_x (SCM self)
 				      current_language,
 				      symbol_name_match_type::WILD);
 
-  TRY
+  try
     {
       int internal = bp_smob->spec.is_internal;
 
@@ -465,11 +465,10 @@ gdbscm_register_breakpoint_x (SCM self)
 	  gdb_assert_not_reached ("invalid breakpoint type");
 	}
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       except = ex;
     }
-  END_CATCH
 
   /* Ensure this gets reset, even if there's an error.  */
   pending_breakpoint_scm = SCM_BOOL_F;
@@ -490,15 +489,14 @@ gdbscm_delete_breakpoint_x (SCM self)
   breakpoint_smob *bp_smob
     = bpscm_get_valid_breakpoint_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
 
-  TRY
+  try
     {
       delete_breakpoint (bp_smob->bp);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return SCM_UNSPECIFIED;
 }
@@ -588,18 +586,17 @@ gdbscm_set_breakpoint_enabled_x (SCM self, SCM newvalue)
   SCM_ASSERT_TYPE (gdbscm_is_bool (newvalue), newvalue, SCM_ARG2, FUNC_NAME,
 		   _("boolean"));
 
-  TRY
+  try
     {
       if (gdbscm_is_true (newvalue))
 	enable_breakpoint (bp_smob->bp);
       else
 	disable_breakpoint (bp_smob->bp);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return SCM_UNSPECIFIED;
 }
@@ -626,15 +623,14 @@ gdbscm_set_breakpoint_silent_x (SCM self, SCM newvalue)
   SCM_ASSERT_TYPE (gdbscm_is_bool (newvalue), newvalue, SCM_ARG2, FUNC_NAME,
 		   _("boolean"));
 
-  TRY
+  try
     {
       breakpoint_set_silent (bp_smob->bp, gdbscm_is_true (newvalue));
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return SCM_UNSPECIFIED;
 }
@@ -667,15 +663,14 @@ gdbscm_set_breakpoint_ignore_count_x (SCM self, SCM newvalue)
   if (value < 0)
     value = 0;
 
-  TRY
+  try
     {
       set_ignore_count (bp_smob->number, (int) value, 0);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return SCM_UNSPECIFIED;
 }
@@ -788,15 +783,14 @@ gdbscm_set_breakpoint_task_x (SCM self, SCM newvalue)
     {
       id = scm_to_long (newvalue);
 
-      TRY
+      try
 	{
 	  valid_id = valid_task_id (id);
 	}
-      CATCH (except, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
 	{
 	  GDBSCM_HANDLE_GDB_EXCEPTION (except);
 	}
-      END_CATCH
 
       if (! valid_id)
 	{
@@ -809,15 +803,14 @@ gdbscm_set_breakpoint_task_x (SCM self, SCM newvalue)
   else
     SCM_ASSERT_TYPE (0, newvalue, SCM_ARG2, FUNC_NAME, _("integer or #f"));
 
-  TRY
+  try
     {
       breakpoint_set_task (bp_smob->bp, id);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return SCM_UNSPECIFIED;
 }
@@ -975,16 +968,15 @@ gdbscm_breakpoint_commands (SCM self)
   string_file buf;
 
   current_uiout->redirect (&buf);
-  TRY
+  try
     {
       print_command_lines (current_uiout, breakpoint_commands (bp), 0);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       current_uiout->redirect (NULL);
       gdbscm_throw_gdb_exception (except);
     }
-  END_CATCH
 
   current_uiout->redirect (NULL);
   result = gdbscm_scm_from_c_string (buf.c_str ());
diff --git a/gdb/guile/scm-cmd.c b/gdb/guile/scm-cmd.c
index 1266a790947..d5b4473a88e 100644
--- a/gdb/guile/scm-cmd.c
+++ b/gdb/guile/scm-cmd.c
@@ -758,7 +758,7 @@ gdbscm_register_command_x (SCM self)
   c_smob->cmd_name = gdbscm_gc_xstrdup (cmd_name);
   xfree (cmd_name);
 
-  TRY
+  try
     {
       if (c_smob->is_prefix)
 	{
@@ -776,11 +776,10 @@ gdbscm_register_command_x (SCM self)
 			 c_smob->doc, cmd_list);
 	}
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   /* Note: At this point the command exists in gdb.
      So no more errors after this point.  */
diff --git a/gdb/guile/scm-disasm.c b/gdb/guile/scm-disasm.c
index e4a9c92a56b..8d0462b31df 100644
--- a/gdb/guile/scm-disasm.c
+++ b/gdb/guile/scm-disasm.c
@@ -247,7 +247,7 @@ gdbscm_arch_disassemble (SCM self, SCM start_scm, SCM rest)
       int insn_len = 0;
       string_file buf;
 
-      TRY
+      try
 	{
 	  if (using_port)
 	    {
@@ -257,11 +257,10 @@ gdbscm_arch_disassemble (SCM self, SCM start_scm, SCM rest)
 	  else
 	    insn_len = gdb_print_insn (gdbarch, pc, &buf, NULL);
 	}
-      CATCH (except, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
 	{
 	  GDBSCM_HANDLE_GDB_EXCEPTION (except);
 	}
-      END_CATCH
 
       result = scm_cons (dascm_make_insn (pc, buf.c_str (), insn_len),
 			 result);
diff --git a/gdb/guile/scm-frame.c b/gdb/guile/scm-frame.c
index 22c78928adf..282cd000242 100644
--- a/gdb/guile/scm-frame.c
+++ b/gdb/guile/scm-frame.c
@@ -229,7 +229,7 @@ frscm_scm_from_frame (struct frame_info *frame, struct inferior *inferior)
   if (*slot != NULL)
     return (*slot)->containing_scm;
 
-  TRY
+  try
     {
       /* Try to get the previous frame, to determine if this is the last frame
 	 in a corrupt stack.  If so, we need to store the frame_id of the next
@@ -248,11 +248,10 @@ frscm_scm_from_frame (struct frame_info *frame, struct inferior *inferior)
 	}
       gdbarch = get_frame_arch (frame);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       return gdbscm_scm_from_gdb_exception (except);
     }
-  END_CATCH
 
   f_scm = frscm_make_frame_smob ();
   f_smob = (frame_smob *) SCM_SMOB_DATA (f_scm);
@@ -397,15 +396,14 @@ gdbscm_frame_valid_p (SCM self)
 
   f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
 
-  TRY
+  try
     {
       frame = frscm_frame_smob_to_frame (f_smob);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return scm_from_bool (frame != NULL);
 }
@@ -425,17 +423,16 @@ gdbscm_frame_name (SCM self)
 
   f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
 
-  TRY
+  try
     {
       frame = frscm_frame_smob_to_frame (f_smob);
       if (frame != NULL)
 	name = find_frame_funname (frame, &lang, NULL);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   if (frame == NULL)
     {
@@ -463,17 +460,16 @@ gdbscm_frame_type (SCM self)
 
   f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
 
-  TRY
+  try
     {
       frame = frscm_frame_smob_to_frame (f_smob);
       if (frame != NULL)
 	type = get_frame_type (frame);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   if (frame == NULL)
     {
@@ -495,15 +491,14 @@ gdbscm_frame_arch (SCM self)
 
   f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
 
-  TRY
+  try
     {
       frame = frscm_frame_smob_to_frame (f_smob);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   if (frame == NULL)
     {
@@ -526,15 +521,14 @@ gdbscm_frame_unwind_stop_reason (SCM self)
 
   f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
 
-  TRY
+  try
     {
       frame = frscm_frame_smob_to_frame (f_smob);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   if (frame == NULL)
     {
@@ -559,17 +553,16 @@ gdbscm_frame_pc (SCM self)
 
   f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
 
-  TRY
+  try
     {
       frame = frscm_frame_smob_to_frame (f_smob);
       if (frame != NULL)
 	pc = get_frame_pc (frame);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   if (frame == NULL)
     {
@@ -592,17 +585,16 @@ gdbscm_frame_block (SCM self)
 
   f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
 
-  TRY
+  try
     {
       frame = frscm_frame_smob_to_frame (f_smob);
       if (frame != NULL)
 	block = get_frame_block (frame, NULL);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   if (frame == NULL)
     {
@@ -643,17 +635,16 @@ gdbscm_frame_function (SCM self)
 
   f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
 
-  TRY
+  try
     {
       frame = frscm_frame_smob_to_frame (f_smob);
       if (frame != NULL)
 	sym = find_pc_function (get_frame_address_in_block (frame));
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   if (frame == NULL)
     {
@@ -680,17 +671,16 @@ gdbscm_frame_older (SCM self)
 
   f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
 
-  TRY
+  try
     {
       frame = frscm_frame_smob_to_frame (f_smob);
       if (frame != NULL)
 	prev = get_prev_frame (frame);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   if (frame == NULL)
     {
@@ -717,17 +707,16 @@ gdbscm_frame_newer (SCM self)
 
   f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
 
-  TRY
+  try
     {
       frame = frscm_frame_smob_to_frame (f_smob);
       if (frame != NULL)
 	next = get_next_frame (frame);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   if (frame == NULL)
     {
@@ -753,17 +742,16 @@ gdbscm_frame_sal (SCM self)
 
   f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
 
-  TRY
+  try
     {
       frame = frscm_frame_smob_to_frame (f_smob);
       if (frame != NULL)
 	sal = find_frame_sal (frame);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   if (frame == NULL)
     {
@@ -791,7 +779,7 @@ gdbscm_frame_read_register (SCM self, SCM register_scm)
 
   struct gdb_exception except = exception_none;
 
-  TRY
+  try
     {
       int regnum;
 
@@ -805,11 +793,10 @@ gdbscm_frame_read_register (SCM self, SCM register_scm)
 	    value = value_of_register (regnum, frame);
 	}
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       except = ex;
     }
-  END_CATCH
 
   xfree (register_str);
   GDBSCM_HANDLE_GDB_EXCEPTION (except);
@@ -851,15 +838,14 @@ gdbscm_frame_read_var (SCM self, SCM symbol_scm, SCM rest)
 
   f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
 
-  TRY
+  try
     {
       frame = frscm_frame_smob_to_frame (f_smob);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   if (frame == NULL)
     {
@@ -897,7 +883,7 @@ gdbscm_frame_read_var (SCM self, SCM symbol_scm, SCM rest)
 	/* N.B. Between here and the end of the scope, don't do anything
 	   to cause a Scheme exception.  */
 
-	TRY
+	try
 	  {
 	    struct block_symbol lookup_sym;
 
@@ -908,11 +894,10 @@ gdbscm_frame_read_var (SCM self, SCM symbol_scm, SCM rest)
 	    var = lookup_sym.symbol;
 	    block = lookup_sym.block;
 	  }
-	CATCH (ex, RETURN_MASK_ALL)
+	catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	  {
 	    except = ex;
 	  }
-	END_CATCH
       }
 
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
@@ -928,15 +913,14 @@ gdbscm_frame_read_var (SCM self, SCM symbol_scm, SCM rest)
 		       _("gdb:symbol or string"));
     }
 
-  TRY
+  try
     {
       value = read_var_value (var, block, frame);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return vlscm_scm_from_value (value);
 }
@@ -952,17 +936,16 @@ gdbscm_frame_select (SCM self)
 
   f_smob = frscm_get_frame_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
 
-  TRY
+  try
     {
       frame = frscm_frame_smob_to_frame (f_smob);
       if (frame != NULL)
 	select_frame (frame);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   if (frame == NULL)
     {
@@ -981,15 +964,14 @@ gdbscm_newest_frame (void)
 {
   struct frame_info *frame = NULL;
 
-  TRY
+  try
     {
       frame = get_current_frame ();
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return frscm_scm_from_frame_unsafe (frame, current_inferior ());
 }
@@ -1002,15 +984,14 @@ gdbscm_selected_frame (void)
 {
   struct frame_info *frame = NULL;
 
-  TRY
+  try
     {
       frame = get_selected_frame (_("No frame is currently selected"));
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return frscm_scm_from_frame_unsafe (frame, current_inferior ());
 }
diff --git a/gdb/guile/scm-lazy-string.c b/gdb/guile/scm-lazy-string.c
index a874e685c0c..ad04123c187 100644
--- a/gdb/guile/scm-lazy-string.c
+++ b/gdb/guile/scm-lazy-string.c
@@ -309,7 +309,7 @@ lsscm_safe_lazy_string_to_value (SCM string, int arg_pos,
       return NULL;
     }
 
-  TRY
+  try
     {
       struct type *type = tyscm_scm_to_type (ls_smob->type);
       struct type *realtype = check_typedef (type);
@@ -336,12 +336,11 @@ lsscm_safe_lazy_string_to_value (SCM string, int arg_pos,
 	  break;
 	}
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       *except_scmp = gdbscm_scm_from_gdb_exception (except);
       return NULL;
     }
-  END_CATCH
 
   return value;
 }
diff --git a/gdb/guile/scm-math.c b/gdb/guile/scm-math.c
index a31a1455487..a49b93629d1 100644
--- a/gdb/guile/scm-math.c
+++ b/gdb/guile/scm-math.c
@@ -735,7 +735,7 @@ vlscm_convert_typed_value_from_scheme (const char *func_name,
 
   *except_scmp = SCM_BOOL_F;
 
-  TRY
+  try
     {
       if (vlscm_is_value (obj))
 	{
@@ -836,11 +836,10 @@ vlscm_convert_typed_value_from_scheme (const char *func_name,
 	  value = NULL;
 	}
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       except_scm = gdbscm_scm_from_gdb_exception (except);
     }
-  END_CATCH
 
   if (gdbscm_is_true (except_scm))
     {
diff --git a/gdb/guile/scm-param.c b/gdb/guile/scm-param.c
index 69bc97eddc7..e5c064f337c 100644
--- a/gdb/guile/scm-param.c
+++ b/gdb/guile/scm-param.c
@@ -1006,7 +1006,7 @@ gdbscm_register_parameter_x (SCM self)
 		_("parameter exists, \"show\" command is already defined"));
     }
 
-  TRY
+  try
     {
       add_setshow_generic (p_smob->type, p_smob->cmd_class,
 			   p_smob->cmd_name, p_smob,
@@ -1018,11 +1018,10 @@ gdbscm_register_parameter_x (SCM self)
 			   set_list, show_list,
 			   &p_smob->set_command, &p_smob->show_command);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   /* Note: At this point the parameter exists in gdb.
      So no more errors after this point.  */
@@ -1064,15 +1063,14 @@ gdbscm_parameter_value (SCM self)
       if (name == NULL)
 	gdbscm_throw (except_scm);
       newarg = concat ("show ", name.get (), (char *) NULL);
-      TRY
+      try
 	{
 	  found = lookup_cmd_composition (newarg, &alias, &prefix, &cmd);
 	}
-      CATCH (ex, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	{
 	  except = ex;
 	}
-      END_CATCH
 
       xfree (newarg);
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
diff --git a/gdb/guile/scm-ports.c b/gdb/guile/scm-ports.c
index 2950b1e39ec..649c12439f1 100644
--- a/gdb/guile/scm-ports.c
+++ b/gdb/guile/scm-ports.c
@@ -272,18 +272,17 @@ ioscm_write (SCM port, const void *data, size_t size)
   if (scm_is_eq (port, input_port_scm))
     return;
 
-  TRY
+  try
     {
       if (scm_is_eq (port, error_port_scm))
 	fputsn_filtered ((const char *) data, size, gdb_stderr);
       else
 	fputsn_filtered ((const char *) data, size, gdb_stdout);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 }
 
 /* Flush gdb's stdout or stderr.  */
diff --git a/gdb/guile/scm-pretty-print.c b/gdb/guile/scm-pretty-print.c
index e5096944b68..c0680d2bd5d 100644
--- a/gdb/guile/scm-pretty-print.c
+++ b/gdb/guile/scm-pretty-print.c
@@ -524,7 +524,7 @@ ppscm_pretty_print_one_value (SCM printer, struct value **out_value,
   SCM result = SCM_BOOL_F;
 
   *out_value = NULL;
-  TRY
+  try
     {
       pretty_printer_worker_smob *w_smob
 	= (pretty_printer_worker_smob *) SCM_SMOB_DATA (printer);
@@ -558,10 +558,9 @@ ppscm_pretty_print_one_value (SCM printer, struct value **out_value,
 	    (_("invalid result from pretty-printer to-string"), result);
 	}
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
     }
-  END_CATCH
 
   return result;
 }
diff --git a/gdb/guile/scm-symbol.c b/gdb/guile/scm-symbol.c
index de3a1589e46..609bba1b1ed 100644
--- a/gdb/guile/scm-symbol.c
+++ b/gdb/guile/scm-symbol.c
@@ -486,15 +486,14 @@ gdbscm_symbol_needs_frame_p (SCM self)
   struct symbol *symbol = s_smob->symbol;
   int result = 0;
 
-  TRY
+  try
     {
       result = symbol_read_needs_frame (symbol);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return scm_from_bool (result);
 }
@@ -539,7 +538,7 @@ gdbscm_symbol_value (SCM self, SCM rest)
 				 _("cannot get the value of a typedef"));
     }
 
-  TRY
+  try
     {
       if (f_smob != NULL)
 	{
@@ -557,11 +556,10 @@ gdbscm_symbol_value (SCM self, SCM rest)
 	 can happen with nested functions).  */
       value = read_var_value (symbol, NULL, frame_info);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return vlscm_scm_from_value (value);
 }
@@ -604,30 +602,28 @@ gdbscm_lookup_symbol (SCM name_scm, SCM rest)
     {
       struct frame_info *selected_frame;
 
-      TRY
+      try
 	{
 	  selected_frame = get_selected_frame (_("no frame selected"));
 	  block = get_frame_block (selected_frame, NULL);
 	}
-      CATCH (ex, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	{
 	  xfree (name);
 	  GDBSCM_HANDLE_GDB_EXCEPTION (ex);
 	}
-      END_CATCH
     }
 
   struct gdb_exception except = exception_none;
-  TRY
+  try
     {
       symbol = lookup_symbol (name, block, (domain_enum) domain,
 			      &is_a_field_of_this).symbol;
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       except = ex;
     }
-  END_CATCH
 
   xfree (name);
   GDBSCM_HANDLE_GDB_EXCEPTION (except);
@@ -656,15 +652,14 @@ gdbscm_lookup_global_symbol (SCM name_scm, SCM rest)
 			      name_scm, &name, rest,
 			      &domain_arg_pos, &domain);
 
-  TRY
+  try
     {
       symbol = lookup_global_symbol (name, NULL, (domain_enum) domain).symbol;
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       except = ex;
     }
-  END_CATCH
 
   xfree (name);
   GDBSCM_HANDLE_GDB_EXCEPTION (except);
diff --git a/gdb/guile/scm-symtab.c b/gdb/guile/scm-symtab.c
index 5ba77557439..c83c48dfe0d 100644
--- a/gdb/guile/scm-symtab.c
+++ b/gdb/guile/scm-symtab.c
@@ -591,17 +591,16 @@ gdbscm_find_pc_line (SCM pc_scm)
 
   gdbscm_parse_function_args (FUNC_NAME, SCM_ARG1, NULL, "U", pc_scm, &pc_ull);
 
-  TRY
+  try
     {
       CORE_ADDR pc = (CORE_ADDR) pc_ull;
 
       sal = find_pc_line (pc, 0);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return stscm_scm_from_sal (sal);
 }
diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c
index 2d2e3ddb3e1..7efad975be9 100644
--- a/gdb/guile/scm-type.c
+++ b/gdb/guile/scm-type.c
@@ -105,19 +105,18 @@ tyscm_type_smob_type (type_smob *t_smob)
 static std::string
 tyscm_type_name (struct type *type)
 {
-  TRY
+  try
     {
       string_file stb;
 
       LA_PRINT_TYPE (type, "", &stb, -1, 0, &type_print_raw_options);
       return std::move (stb.string ());
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       SCM excp = gdbscm_scm_from_gdb_exception (except);
       gdbscm_throw (excp);
     }
-  END_CATCH
 
   gdb_assert_not_reached ("no way to get here");
 }
@@ -235,15 +234,14 @@ tyscm_equal_p_type_smob (SCM type1_scm, SCM type2_scm)
   type1 = type1_smob->type;
   type2 = type2_smob->type;
 
-  TRY
+  try
     {
       result = types_deeply_equal (type1, type2);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return scm_from_bool (result);
 }
@@ -629,14 +627,13 @@ gdbscm_type_sizeof (SCM self)
     = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
   struct type *type = t_smob->type;
 
-  TRY
+  try
     {
       check_typedef (type);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
     }
-  END_CATCH
 
   /* Ignore exceptions.  */
 
@@ -653,15 +650,14 @@ gdbscm_type_strip_typedefs (SCM self)
     = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
   struct type *type = t_smob->type;
 
-  TRY
+  try
     {
       type = check_typedef (type);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return tyscm_scm_from_type (type);
 }
@@ -675,15 +671,14 @@ tyscm_get_composite (struct type *type)
 
   for (;;)
     {
-      TRY
+      try
 	{
 	  type = check_typedef (type);
 	}
-      CATCH (except, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
 	{
 	  GDBSCM_HANDLE_GDB_EXCEPTION (except);
 	}
-      END_CATCH
 
       if (TYPE_CODE (type) != TYPE_CODE_PTR
 	  && TYPE_CODE (type) != TYPE_CODE_REF)
@@ -730,17 +725,16 @@ tyscm_array_1 (SCM self, SCM n1_scm, SCM n2_scm, int is_vector,
 				 _("Array length must not be negative"));
     }
 
-  TRY
+  try
     {
       array = lookup_array_range_type (type, n1, n2);
       if (is_vector)
 	make_vector_type (array);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return tyscm_scm_from_type (array);
 }
@@ -787,15 +781,14 @@ gdbscm_type_pointer (SCM self)
     = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
   struct type *type = t_smob->type;
 
-  TRY
+  try
     {
       type = lookup_pointer_type (type);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return tyscm_scm_from_type (type);
 }
@@ -849,15 +842,14 @@ gdbscm_type_reference (SCM self)
     = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
   struct type *type = t_smob->type;
 
-  TRY
+  try
     {
       type = lookup_lvalue_reference_type (type);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return tyscm_scm_from_type (type);
 }
@@ -887,15 +879,14 @@ gdbscm_type_const (SCM self)
     = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
   struct type *type = t_smob->type;
 
-  TRY
+  try
     {
       type = make_cv_type (1, 0, type, NULL);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return tyscm_scm_from_type (type);
 }
@@ -910,15 +901,14 @@ gdbscm_type_volatile (SCM self)
     = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
   struct type *type = t_smob->type;
 
-  TRY
+  try
     {
       type = make_cv_type (0, 1, type, NULL);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return tyscm_scm_from_type (type);
 }
@@ -933,15 +923,14 @@ gdbscm_type_unqualified (SCM self)
     = tyscm_get_type_smob_arg_unsafe (self, SCM_ARG1, FUNC_NAME);
   struct type *type = t_smob->type;
 
-  TRY
+  try
     {
       type = make_cv_type (0, 0, type, NULL);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return tyscm_scm_from_type (type);
 }
@@ -1230,7 +1219,7 @@ tyscm_lookup_typename (const char *type_name, const struct block *block)
 {
   struct type *type = NULL;
 
-  TRY
+  try
     {
       if (startswith (type_name, "struct "))
 	type = lookup_struct (type_name + 7, NULL);
@@ -1242,11 +1231,10 @@ tyscm_lookup_typename (const char *type_name, const struct block *block)
 	type = lookup_typename (current_language, get_current_arch (),
 				type_name, block, 0);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       return NULL;
     }
-  END_CATCH
 
   return type;
 }
diff --git a/gdb/guile/scm-value.c b/gdb/guile/scm-value.c
index 294e3e7cafc..9aa250bfc8f 100644
--- a/gdb/guile/scm-value.c
+++ b/gdb/guile/scm-value.c
@@ -156,18 +156,17 @@ vlscm_print_value_smob (SCM self, SCM port, scm_print_state *pstate)
      instead of writingp.  */
   opts.raw = !!pstate->writingp;
 
-  TRY
+  try
     {
       string_file stb;
 
       common_val_print (v_smob->value, &stb, 0, &opts, current_language);
       scm_puts (stb.c_str (), port);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   if (pstate->writingp)
     scm_puts (">", port);
@@ -187,15 +186,14 @@ vlscm_equal_p_value_smob (SCM v1, SCM v2)
   const value_smob *v2_smob = (value_smob *) SCM_SMOB_DATA (v2);
   int result = 0;
 
-  TRY
+  try
     {
       result = value_equal (v1_smob->value, v2_smob->value);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return scm_from_bool (result);
 }
@@ -392,14 +390,13 @@ gdbscm_value_address (SCM self)
 
 	  SCM address = SCM_BOOL_F;
 
-	  TRY
+	  try
 	    {
 	      address = vlscm_scm_from_value (value_addr (value));
 	    }
-	  CATCH (except, RETURN_MASK_ALL)
+	  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
 	    {
 	    }
-	  END_CATCH
 
 	  if (gdbscm_is_exception (address))
 	    return address;
@@ -496,7 +493,7 @@ gdbscm_value_dynamic_type (SCM self)
   if (! SCM_UNBNDP (v_smob->dynamic_type))
     return v_smob->dynamic_type;
 
-  TRY
+  try
     {
       scoped_value_mark free_values;
 
@@ -532,11 +529,10 @@ gdbscm_value_dynamic_type (SCM self)
 	  type = NULL;
 	}
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   if (type == NULL)
     v_smob->dynamic_type = gdbscm_value_type (self);
@@ -684,15 +680,14 @@ gdbscm_value_call (SCM self, SCM args)
   long args_count;
   struct value **vargs = NULL;
 
-  TRY
+  try
     {
       ftype = check_typedef (value_type (function));
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   SCM_ASSERT_TYPE (TYPE_CODE (ftype) == TYPE_CODE_FUNC, self,
 		   SCM_ARG1, FUNC_NAME,
@@ -751,17 +746,16 @@ gdbscm_value_to_bytevector (SCM self)
 
   type = value_type (value);
 
-  TRY
+  try
     {
       type = check_typedef (type);
       length = TYPE_LENGTH (type);
       contents = value_contents (value);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   bv = scm_c_make_bytevector (length);
   memcpy (SCM_BYTEVECTOR_CONTENTS (bv), contents, length);
@@ -795,31 +789,29 @@ gdbscm_value_to_bool (SCM self)
 
   type = value_type (value);
 
-  TRY
+  try
     {
       type = check_typedef (type);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   SCM_ASSERT_TYPE (is_intlike (type, 1), self, SCM_ARG1, FUNC_NAME,
 		   _("integer-like gdb value"));
 
-  TRY
+  try
     {
       if (TYPE_CODE (type) == TYPE_CODE_PTR)
 	l = value_as_address (value);
       else
 	l = value_as_long (value);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   return scm_from_bool (l != 0);
 }
@@ -838,31 +830,29 @@ gdbscm_value_to_integer (SCM self)
 
   type = value_type (value);
 
-  TRY
+  try
     {
       type = check_typedef (type);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   SCM_ASSERT_TYPE (is_intlike (type, 1), self, SCM_ARG1, FUNC_NAME,
 		   _("integer-like gdb value"));
 
-  TRY
+  try
     {
       if (TYPE_CODE (type) == TYPE_CODE_PTR)
 	l = value_as_address (value);
       else
 	l = value_as_long (value);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   if (TYPE_UNSIGNED (type))
     return gdbscm_scm_from_ulongest (l);
@@ -885,20 +875,19 @@ gdbscm_value_to_real (SCM self)
 
   type = value_type (value);
 
-  TRY
+  try
     {
       type = check_typedef (type);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   SCM_ASSERT_TYPE (is_intlike (type, 0) || TYPE_CODE (type) == TYPE_CODE_FLT,
 		   self, SCM_ARG1, FUNC_NAME, _("number"));
 
-  TRY
+  try
     {
       if (is_floating_value (value))
 	{
@@ -917,11 +906,10 @@ gdbscm_value_to_real (SCM self)
 	  check = value_from_longest (type, (LONGEST) d);
 	}
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   /* TODO: Is there a better way to check if the value fits?  */
   if (!value_equal (value, check))
@@ -1005,18 +993,17 @@ gdbscm_value_to_string (SCM self, SCM rest)
   /* We don't assume anything about the result of scm_port_conversion_strategy.
      From this point on, if errors is not 'errors, use 'substitute.  */
 
-  TRY
+  try
     {
       gdb::unique_xmalloc_ptr<gdb_byte> buffer;
       LA_GET_STRING (value, &buffer, &length, &char_type, &la_encoding);
       buffer_contents = buffer.release ();
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       xfree (encoding);
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   /* If errors is "error", scm_from_stringn may throw a Scheme exception.
      Make sure we don't leak.  This is done via scm_dynwind_begin, et.al.  */
@@ -1078,7 +1065,7 @@ gdbscm_value_to_lazy_string (SCM self, SCM rest)
 				 _("invalid length"));
     }
 
-  TRY
+  try
     {
       scoped_value_mark free_values;
 
@@ -1133,11 +1120,10 @@ gdbscm_value_to_lazy_string (SCM self, SCM rest)
 
       result = lsscm_make_lazy_string (addr, length, encoding, type);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       except = ex;
     }
-  END_CATCH
 
   xfree (encoding);
   GDBSCM_HANDLE_GDB_EXCEPTION (except);
@@ -1192,15 +1178,14 @@ gdbscm_value_print (SCM self)
 
   string_file stb;
 
-  TRY
+  try
     {
       common_val_print (value, &stb, 0, &opts, current_language);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDBSCM_HANDLE_GDB_EXCEPTION (except);
     }
-  END_CATCH
 
   /* Use SCM_FAILED_CONVERSION_QUESTION_MARK to ensure this doesn't
      throw an error if the encoding fails.
diff --git a/gdb/i386-linux-tdep.c b/gdb/i386-linux-tdep.c
index da81715061e..85f761df669 100644
--- a/gdb/i386-linux-tdep.c
+++ b/gdb/i386-linux-tdep.c
@@ -402,7 +402,7 @@ i386_linux_handle_segmentation_fault (struct gdbarch *gdbarch,
   if (!i386_mpx_enabled ())
     return;
 
-  TRY
+  try
     {
       /* Sigcode evaluates if the actual segfault is a boundary violation.  */
       sig_code = parse_and_eval_long ("$_siginfo.si_code\n");
@@ -414,11 +414,10 @@ i386_linux_handle_segmentation_fault (struct gdbarch *gdbarch,
       access
         = parse_and_eval_long ("$_siginfo._sifields._sigfault.si_addr");
     }
-  CATCH (exception, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
     {
       return;
     }
-  END_CATCH
 
   /* If this is not a boundary violation just return.  */
   if (sig_code != SIG_CODE_BONDARY_FAULT)
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index bc9ba752edf..5dee63dec23 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -2082,16 +2082,15 @@ i386_frame_cache (struct frame_info *this_frame, void **this_cache)
   cache = i386_alloc_frame_cache ();
   *this_cache = cache;
 
-  TRY
+  try
     {
       i386_frame_cache_1 (this_frame, cache);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
     }
-  END_CATCH
 
   return cache;
 }
@@ -2252,7 +2251,7 @@ i386_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
   cache = i386_alloc_frame_cache ();
   *this_cache = cache;
 
-  TRY
+  try
     {
       cache->pc = get_frame_func (this_frame);
 
@@ -2266,12 +2265,11 @@ i386_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
 
       cache->base_p = 1;
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
     }
-  END_CATCH
 
   return cache;
 }
@@ -2438,7 +2436,7 @@ i386_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 
   cache = i386_alloc_frame_cache ();
 
-  TRY
+  try
     {
       get_frame_register (this_frame, I386_ESP_REGNUM, buf);
       cache->base = extract_unsigned_integer (buf, 4, byte_order) - 4;
@@ -2462,12 +2460,11 @@ i386_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 
       cache->base_p = 1;
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
     }
-  END_CATCH
 
   *this_cache = cache;
   return cache;
diff --git a/gdb/inf-loop.c b/gdb/inf-loop.c
index d0e19d5f824..86e45babe37 100644
--- a/gdb/inf-loop.c
+++ b/gdb/inf-loop.c
@@ -67,11 +67,11 @@ inferior_event_handler (enum inferior_event_type event_type,
 	  /* Don't propagate breakpoint commands errors.  Either we're
 	     stopping or some command resumes the inferior.  The user will
 	     be informed.  */
-	  TRY
+	  try
 	    {
 	      bpstat_do_actions ();
 	    }
-	  CATCH (e, RETURN_MASK_ALL)
+	  catch (const struct gdb_exception_RETURN_MASK_ALL &e)
 	    {
 	      /* If the user was running a foreground execution
 		 command, then propagate the error so that the prompt
@@ -83,7 +83,6 @@ inferior_event_handler (enum inferior_event_type event_type,
 	      else
 		exception_print (gdb_stderr, e);
 	    }
-	  END_CATCH
 	}
       break;
 
diff --git a/gdb/infcall.c b/gdb/infcall.c
index 45cf24f6393..ee63d33384b 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -594,7 +594,7 @@ run_inferior_call (struct call_thread_fsm *sm,
   /* We want to print return value, please...  */
   call_thread->control.proceed_to_finish = 1;
 
-  TRY
+  try
     {
       proceed (real_pc, GDB_SIGNAL_0);
 
@@ -602,11 +602,10 @@ run_inferior_call (struct call_thread_fsm *sm,
 	 target supports asynchronous execution.  */
       wait_sync_command_done ();
     }
-  CATCH (e, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &e)
     {
       caught_error = e;
     }
-  END_CATCH
 
   /* If GDB has the prompt blocked before, then ensure that it remains
      so.  normal_stop calls async_enable_stdin, so reset the prompt
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index c5977c48a90..590f9dcaabe 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -447,16 +447,15 @@ post_create_inferior (struct target_ops *target, int from_tty)
   thread_info *thr = inferior_thread ();
 
   thr->suspend.stop_pc = 0;
-  TRY
+  try
     {
       thr->suspend.stop_pc = regcache_read_pc (get_current_regcache ());
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
     }
-  END_CATCH
 
   if (exec_bfd)
     {
@@ -1646,18 +1645,17 @@ print_return_value (struct ui_out *uiout, struct return_value_info *rv)
       || TYPE_CODE (check_typedef (rv->type)) == TYPE_CODE_VOID)
     return;
 
-  TRY
+  try
     {
       /* print_return_value_1 can throw an exception in some
 	 circumstances.  We need to catch this so that we still
 	 delete the breakpoint.  */
       print_return_value_1 (uiout, rv);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       exception_print (gdb_stdout, ex);
     }
-  END_CATCH
 }
 
 /* Data for the FSM that manages the finish command.  */
diff --git a/gdb/infrun.c b/gdb/infrun.c
index b8e1e1fbfd8..3e6eaa3f511 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -1774,11 +1774,11 @@ displaced_step_prepare (thread_info *thread)
 {
   int prepared = -1;
 
-  TRY
+  try
     {
       prepared = displaced_step_prepare_throw (thread);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       struct displaced_step_inferior_state *displaced_state;
 
@@ -1806,7 +1806,6 @@ displaced_step_prepare (thread_info *thread)
 	= get_displaced_stepping_state (thread->inf);
       displaced_state->failed_before = 1;
     }
-  END_CATCH
 
   return prepared;
 }
@@ -2608,11 +2607,11 @@ resume_1 (enum gdb_signal sig)
 static void
 resume (gdb_signal sig)
 {
-  TRY
+  try
     {
       resume_1 (sig);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       /* If resuming is being aborted for any reason, delete any
 	 single-step breakpoint resume_1 may have created, to avoid
@@ -2623,7 +2622,6 @@ resume (gdb_signal sig)
 	delete_single_step_breakpoints (inferior_thread ());
       throw_exception (ex);
     }
-  END_CATCH
 }
 
 \f
@@ -7322,7 +7320,7 @@ insert_exception_resume_breakpoint (struct thread_info *tp,
 				    struct frame_info *frame,
 				    struct symbol *sym)
 {
-  TRY
+  try
     {
       struct block_symbol vsym;
       struct value *value;
@@ -7353,11 +7351,10 @@ insert_exception_resume_breakpoint (struct thread_info *tp,
 	  inferior_thread ()->control.exception_resume_breakpoint = bp;
 	}
     }
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       /* We want to ignore errors here.  */
     }
-  END_CATCH
 }
 
 /* A helper for check_exception_resume that sets an
@@ -7416,7 +7413,7 @@ check_exception_resume (struct execution_control_state *ecs,
   if (!func)
     return;
 
-  TRY
+  try
     {
       const struct block *b;
       struct block_iterator iter;
@@ -7453,10 +7450,9 @@ check_exception_resume (struct execution_control_state *ecs,
 	    }
 	}
     }
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
     {
     }
-  END_CATCH
 }
 
 static void
@@ -7583,18 +7579,17 @@ keep_going_pass_signal (struct execution_control_state *ecs)
 	stop_all_threads ();
 
       /* Stop stepping if inserting breakpoints fails.  */
-      TRY
+      try
 	{
 	  insert_breakpoints ();
 	}
-      CATCH (e, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
 	{
 	  exception_print (gdb_stderr, e);
 	  stop_waiting (ecs);
 	  clear_step_over_info ();
 	  return;
 	}
-      END_CATCH
 
       ecs->event_thread->control.trap_expected = (remove_bp || remove_wps);
 
@@ -8115,16 +8110,15 @@ normal_stop (void)
     {
       stop_context saved_context;
 
-      TRY
+      try
 	{
 	  execute_cmd_pre_hook (stop_command);
 	}
-      CATCH (ex, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	{
 	  exception_fprintf (gdb_stderr, ex,
 			     "Error while running hook_stop:\n");
 	}
-      END_CATCH
 
       /* If the stop hook resumes the target, then there's no point in
 	 trying to notify about the previous stop; its context is
@@ -8823,11 +8817,11 @@ restore_infcall_control_state (struct infcall_control_state *inf_status)
       /* The point of the try/catch is that if the stack is clobbered,
          walking the stack might encounter a garbage pointer and
          error() trying to dereference it.  */
-      TRY
+      try
 	{
 	  restore_selected_frame (inf_status->selected_frame_id);
 	}
-      CATCH (ex, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 	{
 	  exception_fprintf (gdb_stderr, ex,
 			     "Unable to restore previously selected frame:\n");
@@ -8835,7 +8829,6 @@ restore_infcall_control_state (struct infcall_control_state *inf_status)
 	     innermost frame.  */
 	  select_frame (get_current_frame ());
 	}
-      END_CATCH
     }
 
   delete inf_status;
diff --git a/gdb/jit.c b/gdb/jit.c
index 81c4af40f92..26675f41142 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -851,17 +851,16 @@ jit_reader_try_read_symtab (struct jit_code_entry *code_entry,
   gdb_mem = (gdb_byte *) xmalloc (code_entry->symfile_size);
 
   status = 1;
-  TRY
+  try
     {
       if (target_read_memory (code_entry->symfile_addr, gdb_mem,
 			      code_entry->symfile_size))
 	status = 0;
     }
-  CATCH (e, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &e)
     {
       status = 0;
     }
-  END_CATCH
 
   if (status)
     {
diff --git a/gdb/language.c b/gdb/language.c
index ea294e670b6..7e62bace0d1 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -172,18 +172,17 @@ set_language_command (const char *ignore,
 	      /* Enter auto mode.  Set to the current frame's language, if
                  known, or fallback to the initial language.  */
 	      language_mode = language_mode_auto;
-	      TRY
+	      try
 		{
 		  struct frame_info *frame;
 
 		  frame = get_selected_frame (NULL);
 		  flang = get_frame_language (frame);
 		}
-	      CATCH (ex, RETURN_MASK_ERROR)
+	      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 		{
 		  flang = language_unknown;
 		}
-	      END_CATCH
 
 	      if (flang != language_unknown)
 		set_language (flang);
diff --git a/gdb/linespec.c b/gdb/linespec.c
index e902b11c8e8..93a3d2f9507 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -2389,16 +2389,15 @@ convert_explicit_location_to_linespec (struct linespec_state *self,
 
   if (source_filename != NULL)
     {
-      TRY
+      try
 	{
 	  *result->file_symtabs
 	    = symtabs_from_filename (source_filename, self->search_pspace);
 	}
-      CATCH (except, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	{
 	  source_file_not_found_error (source_filename);
 	}
-      END_CATCH
       result->explicit_loc.source_filename = xstrdup (source_filename);
     }
   else
@@ -2614,17 +2613,16 @@ parse_linespec (linespec_parser *parser, const char *arg,
       gdb::unique_xmalloc_ptr<char> user_filename = copy_token_string (token);
 
       /* Check if the input is a filename.  */
-      TRY
+      try
 	{
 	  *PARSER_RESULT (parser)->file_symtabs
 	    = symtabs_from_filename (user_filename.get (),
 				     PARSER_STATE (parser)->search_pspace);
 	}
-      CATCH (ex, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 	{
 	  file_exception = ex;
 	}
-      END_CATCH
 
       if (file_exception.reason >= 0)
 	{
@@ -2929,7 +2927,7 @@ linespec_complete_label (completion_tracker &tracker,
 
   line_offset unknown_offset = { 0, LINE_OFFSET_UNKNOWN };
 
-  TRY
+  try
     {
       convert_explicit_location_to_linespec (PARSER_STATE (&parser),
 					     PARSER_RESULT (&parser),
@@ -2938,11 +2936,10 @@ linespec_complete_label (completion_tracker &tracker,
 					     func_name_match_type,
 					     NULL, unknown_offset);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       return;
     }
-  END_CATCH
 
   complete_label (tracker, &parser, label_name);
 }
@@ -2965,14 +2962,13 @@ linespec_complete (completion_tracker &tracker, const char *text,
 
   /* Parse as much as possible.  parser.completion_word will hold
      furthest completion point we managed to parse to.  */
-  TRY
+  try
     {
       parse_linespec (&parser, text, match_type);
     }
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
     }
-  END_CATCH
 
   if (parser.completion_quote_char != '\0'
       && parser.completion_quote_end != NULL
@@ -3154,17 +3150,16 @@ event_location_to_sals (linespec_parser *parser,
     case LINESPEC_LOCATION:
       {
 	PARSER_STATE (parser)->is_linespec = 1;
-	TRY
+	try
 	  {
 	    const linespec_location *ls = get_linespec_location (location);
 	    result = parse_linespec (parser,
 				     ls->spec_string, ls->match_type);
 	  }
-	CATCH (except, RETURN_MASK_ERROR)
+	catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	  {
 	    throw_exception (except);
 	  }
-	END_CATCH
       }
       break;
 
@@ -3965,7 +3960,7 @@ find_linespec_symbols (struct linespec_state *state,
       if (!classes.empty ())
 	{
 	  /* Now locate a list of suitable methods named METHOD.  */
-	  TRY
+	  try
 	    {
 	      find_method (state, file_symtabs,
 			   klass.c_str (), method.c_str (),
@@ -3974,12 +3969,11 @@ find_linespec_symbols (struct linespec_state *state,
 
 	  /* If successful, we're done.  If NOT_FOUND_ERROR
 	     was not thrown, rethrow the exception that we did get.  */
-	  CATCH (except, RETURN_MASK_ERROR)
+	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	    {
 	      if (except.error != NOT_FOUND_ERROR)
 		throw_exception (except);
 	    }
-	  END_CATCH
 	}
     }
 }
diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c
index 5a97dfa23dc..317bac45f13 100644
--- a/gdb/linux-fork.c
+++ b/gdb/linux-fork.c
@@ -472,18 +472,17 @@ public:
     if (m_oldfp != nullptr)
       {
 	/* Switch back to inferior_ptid.  */
-	TRY
+	try
 	  {
 	    remove_breakpoints ();
 	    fork_load_infrun_state (m_oldfp);
 	    insert_breakpoints ();
 	  }
-	CATCH (ex, RETURN_MASK_ALL)
+	catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	  {
 	    warning (_("Couldn't restore checkpoint state in %s: %s"),
 		     target_pid_to_str (m_oldfp->ptid), ex.message.c_str ());
 	  }
-	END_CATCH
       }
   }
 
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 875e6f66cc1..ea460dea258 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -1189,11 +1189,11 @@ linux_nat_target::attach (const char *args, int from_tty)
   /* Make sure we report all signals during attach.  */
   pass_signals ({});
 
-  TRY
+  try
     {
       inf_ptrace_target::attach (args, from_tty);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       pid_t pid = parse_pid_to_attach (args);
       std::string reason = linux_ptrace_attach_fail_reason (pid);
@@ -1204,7 +1204,6 @@ linux_nat_target::attach (const char *args, int from_tty)
       else
 	throw_error (ex.error, "%s", ex.message.c_str ());
     }
-  END_CATCH
 
   /* The ptrace base target adds the main thread with (pid,0,0)
      format.  Decorate it with lwp info.  */
@@ -1403,16 +1402,15 @@ detach_one_lwp (struct lwp_info *lp, int *signo_p)
   /* Preparing to resume may try to write registers, and fail if the
      lwp is zombie.  If that happens, ignore the error.  We'll handle
      it below, when detach fails with ESRCH.  */
-  TRY
+  try
     {
       linux_target->low_prepare_to_resume (lp);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (!check_ptrace_stopped_lwp_gone (lp))
 	throw_exception (ex);
     }
-  END_CATCH
 
   if (ptrace (PTRACE_DETACH, lwpid, 0, signo) < 0)
     {
@@ -1585,16 +1583,15 @@ check_ptrace_stopped_lwp_gone (struct lwp_info *lp)
 static void
 linux_resume_one_lwp (struct lwp_info *lp, int step, enum gdb_signal signo)
 {
-  TRY
+  try
     {
       linux_resume_one_lwp_throw (lp, step, signo);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (!check_ptrace_stopped_lwp_gone (lp))
 	throw_exception (ex);
     }
-  END_CATCH
 }
 
 /* Resume LP.  */
@@ -3516,7 +3513,7 @@ resume_stopped_resumed_lwps (struct lwp_info *lp, void *data)
       struct regcache *regcache = get_thread_regcache (lp->ptid);
       struct gdbarch *gdbarch = regcache->arch ();
 
-      TRY
+      try
 	{
 	  CORE_ADDR pc = regcache_read_pc (regcache);
 	  int leave_stopped = 0;
@@ -3542,12 +3539,11 @@ resume_stopped_resumed_lwps (struct lwp_info *lp, void *data)
 	      linux_resume_one_lwp_throw (lp, lp->step, GDB_SIGNAL_0);
 	    }
 	}
-      CATCH (ex, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 	{
 	  if (!check_ptrace_stopped_lwp_gone (lp))
 	    throw_exception (ex);
 	}
-      END_CATCH
     }
 
   return 0;
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index 8d594138e55..a4c0b790e98 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -1931,15 +1931,14 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size)
     }
 
   /* Thread register information.  */
-  TRY
+  try
     {
       update_thread_list ();
     }
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       exception_print (gdb_stderr, e);
     }
-  END_CATCH
 
   /* Like the kernel, prefer dumping the signalled thread first.
      "First thread" is what tools use to infer the signalled thread.
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index fd67dcb17b2..eaaf55fd3e8 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -497,12 +497,12 @@ static int
 thread_db_find_new_threads_silently (thread_info *stopped)
 {
 
-  TRY
+  try
     {
       thread_db_find_new_threads_2 (stopped, true);
     }
 
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       if (libthread_db_debug)
 	exception_fprintf (gdb_stdlog, except,
@@ -532,7 +532,6 @@ thread_db_find_new_threads_silently (thread_info *stopped)
 	  return 1;
 	}
     }
-  END_CATCH
 
   return 0;
 }
@@ -757,7 +756,7 @@ check_thread_db (struct thread_db_info *info, bool log_progress)
      fail.  */
   linux_stop_and_wait_all_lwps ();
 
-  TRY
+  try
     {
       td_err_e err = td_ta_thr_iter_p (info->thread_agent,
 				       check_thread_db_callback,
@@ -773,7 +772,7 @@ check_thread_db (struct thread_db_info *info, bool log_progress)
       if (!tdb_testinfo->threads_seen)
 	error (_("no threads seen"));
     }
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       if (warning_pre_print)
 	fputs_unfiltered (warning_pre_print, gdb_stderr);
@@ -783,7 +782,6 @@ check_thread_db (struct thread_db_info *info, bool log_progress)
 
       test_passed = false;
     }
-  END_CATCH
 
   if (test_passed && log_progress)
     debug_printf (_("libthread_db integrity checks passed.\n"));
@@ -1509,7 +1507,7 @@ find_new_threads_once (struct thread_db_info *info, int iteration,
   /* See comment in thread_db_update_thread_list.  */
   gdb_assert (info->td_ta_thr_iter_p != NULL);
 
-  TRY
+  try
     {
       /* Iterate over all user-space threads to discover new threads.  */
       err = info->td_ta_thr_iter_p (info->thread_agent,
@@ -1520,7 +1518,7 @@ find_new_threads_once (struct thread_db_info *info, int iteration,
 				    TD_SIGNO_MASK,
 				    TD_THR_ANY_USER_FLAGS);
     }
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       if (libthread_db_debug)
 	{
@@ -1528,7 +1526,6 @@ find_new_threads_once (struct thread_db_info *info, int iteration,
 			     "Warning: find_new_threads_once: ");
 	}
     }
-  END_CATCH
 
   if (libthread_db_debug)
     {
diff --git a/gdb/main.c b/gdb/main.c
index 97ffc3fba48..e5d93bf4065 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -365,7 +365,7 @@ static int
 catch_command_errors (catch_command_errors_const_ftype command,
 		      const char *arg, int from_tty)
 {
-  TRY
+  try
     {
       int was_sync = current_ui->prompt_state == PROMPT_BLOCKED;
 
@@ -373,11 +373,10 @@ catch_command_errors (catch_command_errors_const_ftype command,
 
       maybe_wait_sync_command_done (was_sync);
     }
-  CATCH (e, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &e)
     {
       return handle_command_errors (e);
     }
-  END_CATCH
 
   return 1;
 }
@@ -1169,15 +1168,14 @@ captured_main (void *data)
      change - SET_TOP_LEVEL() - has been eliminated.  */
   while (1)
     {
-      TRY
+      try
 	{
 	  captured_command_loop ();
 	}
-      CATCH (ex, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	{
 	  exception_print (gdb_stderr, ex);
 	}
-      END_CATCH
     }
   /* No exit -- exit is through quit_command.  */
 }
@@ -1185,15 +1183,14 @@ captured_main (void *data)
 int
 gdb_main (struct captured_main_args *args)
 {
-  TRY
+  try
     {
       captured_main (args);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       exception_print (gdb_stderr, ex);
     }
-  END_CATCH
 
   /* The only way to end up here is by an error (normal exit is
      handled by quit_force()), hence always return an error status.  */
diff --git a/gdb/mi/mi-cmd-break.c b/gdb/mi/mi-cmd-break.c
index 4f25977311d..d8bed92d858 100644
--- a/gdb/mi/mi-cmd-break.c
+++ b/gdb/mi/mi-cmd-break.c
@@ -54,15 +54,14 @@ breakpoint_notify (struct breakpoint *b)
 {
   if (mi_can_breakpoint_notify)
     {
-      TRY
+      try
 	{
 	  print_breakpoint (b);
 	}
-      CATCH (ex, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	{
 	  exception_print (gdb_stderr, ex);
 	}
-      END_CATCH
     }
 }
 
diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index e55c835a75f..457712bbeaf 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -533,7 +533,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
 	error_message = arg->error;
       else
 	{
-	  TRY
+	  try
 	    {
 	      struct value_print_options opts;
 
@@ -542,11 +542,10 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
 	      common_val_print (arg->val, &stb, 0, &opts,
 				language_def (SYMBOL_LANGUAGE (arg->sym)));
 	    }
-	  CATCH (except, RETURN_MASK_ERROR)
+	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	    {
 	      error_message = std::move (except.message);
 	    }
-	  END_CATCH
 	}
       if (!error_message.empty ())
 	stb.printf (_("<error reading variable: %s>"), error_message.c_str ());
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index b3a8094f425..75b581be5c2 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -835,18 +835,17 @@ mi_print_breakpoint_for_event (struct mi_interp *mi, breakpoint *bp)
      ui_out_redirect.  */
   mi_uiout->redirect (mi->event_channel);
 
-  TRY
+  try
     {
       scoped_restore restore_uiout
 	= make_scoped_restore (&current_uiout, mi_uiout);
 
       print_breakpoint (bp);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       exception_print (gdb_stderr, ex);
     }
-  END_CATCH
 
   mi_uiout->redirect (NULL);
 }
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 4f12218ea69..0997f6e10b9 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1938,16 +1938,15 @@ mi_execute_command (const char *cmd, int from_tty)
 
   target_log_command (cmd);
 
-  TRY
+  try
     {
       command = mi_parse (cmd, &token);
     }
-  CATCH (exception, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
     {
       mi_print_exception (token, exception);
       xfree (token);
     }
-  END_CATCH
 
   if (command != NULL)
     {
@@ -1966,11 +1965,11 @@ mi_execute_command (const char *cmd, int from_tty)
 	  timestamp (command->cmd_start);
 	}
 
-      TRY
+      try
 	{
 	  captured_mi_execute_command (current_uiout, command.get ());
 	}
-      CATCH (result, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &result)
 	{
 	  /* Like in start_event_loop, enable input and force display
 	     of the prompt.  Otherwise, any command that calls
@@ -1984,7 +1983,6 @@ mi_execute_command (const char *cmd, int from_tty)
 	  mi_print_exception (command->token, result);
 	  mi_out_rewind (current_uiout);
 	}
-      END_CATCH
 
       bpstat_do_actions ();
 
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index ceef482ae35..4b3a0d4f62b 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -1297,18 +1297,17 @@ find_objc_msgcall_submethod (int (*f) (CORE_ADDR, CORE_ADDR *),
 			     CORE_ADDR pc, 
 			     CORE_ADDR *new_pc)
 {
-  TRY
+  try
     {
       if (f (pc, new_pc) == 0)
 	return 1;
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       exception_fprintf (gdb_stderr, ex,
 			 "Unable to determine target of "
 			 "Objective-C method call (ignoring):\n");
     }
-  END_CATCH
 
   return 0;
 }
diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
index 713a2889493..473773f279e 100644
--- a/gdb/p-valprint.c
+++ b/gdb/p-valprint.c
@@ -754,18 +754,17 @@ pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
 
       thisoffset = offset;
 
-      TRY
+      try
 	{
 	  boffset = baseclass_offset (type, i, valaddr, offset, address, val);
 	}
-      CATCH (ex, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 	{
 	  if (ex.error == NOT_AVAILABLE_ERROR)
 	    skip = -1;
 	  else
 	    skip = 1;
 	}
-      END_CATCH
 
       if (skip == 0)
 	{
diff --git a/gdb/parse.c b/gdb/parse.c
index e7168acf7ab..fcdc2c2d54e 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -1200,11 +1200,11 @@ parse_exp_in_context_1 (const char **stringptr, CORE_ADDR pc,
   scoped_restore_current_language lang_saver;
   set_language (lang->la_language);
 
-  TRY
+  try
     {
       lang->la_parser (&ps);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       /* If parsing for completion, allow this to succeed; but if no
 	 expression elements have been written, then there's nothing
@@ -1212,7 +1212,6 @@ parse_exp_in_context_1 (const char **stringptr, CORE_ADDR pc,
       if (! parse_completion || ps.expout_ptr == 0)
 	throw_exception (except);
     }
-  END_CATCH
 
   /* We have to operate on an "expression *", due to la_post_parser,
      which explains this funny-looking double release.  */
@@ -1282,16 +1281,15 @@ parse_expression_for_completion (const char *string,
   struct value *val;
   int subexp;
 
-  TRY
+  try
     {
       parse_completion = 1;
       exp = parse_exp_in_context (&string, 0, 0, 0, 0, &subexp);
     }
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       /* Nothing, EXP remains NULL.  */
     }
-  END_CATCH
 
   parse_completion = 0;
   if (exp == NULL)
diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
index df44ad826e7..c0b7505dda4 100644
--- a/gdb/ppc-linux-tdep.c
+++ b/gdb/ppc-linux-tdep.c
@@ -1830,7 +1830,7 @@ ppc_linux_spe_context (int wordsize, enum bfd_endian byte_order,
     {
       struct target_ops *target = current_top_target ();
 
-      TRY
+      try
 	{
 	  /* We do not call target_translate_tls_address here, because
 	     svr4_fetch_objfile_link_map may invalidate the frame chain,
@@ -1845,11 +1845,10 @@ ppc_linux_spe_context (int wordsize, enum bfd_endian byte_order,
 	  spe_context_cache_ptid = inferior_ptid;
 	}
 
-      CATCH (ex, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 	{
 	  return 0;
 	}
-      END_CATCH
     }
 
   /* Read variable value.  */
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 46d242ddb11..dc506250d4b 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1882,13 +1882,13 @@ do_one_display (struct display *d)
   if (d->exp == NULL)
     {
 
-      TRY
+      try
 	{
 	  innermost_block.reset ();
 	  d->exp = parse_expression (d->exp_string);
 	  d->block = innermost_block.block ();
 	}
-      CATCH (ex, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	{
 	  /* Can't re-parse the expression.  Disable this display item.  */
 	  d->enabled_p = 0;
@@ -1896,7 +1896,6 @@ do_one_display (struct display *d)
 		   d->exp_string, ex.message.c_str ());
 	  return;
 	}
-      END_CATCH
     }
 
   if (d->block)
@@ -1943,7 +1942,7 @@ do_one_display (struct display *d)
 
       annotate_display_value ();
 
-      TRY
+      try
         {
 	  struct value *val;
 	  CORE_ADDR addr;
@@ -1954,12 +1953,11 @@ do_one_display (struct display *d)
 	    addr = gdbarch_addr_bits_remove (d->exp->gdbarch, addr);
 	  do_examine (d->format, d->exp->gdbarch, addr);
 	}
-      CATCH (ex, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 	{
 	  fprintf_filtered (gdb_stdout, _("<error: %s>\n"),
 			    ex.message.c_str ());
 	}
-      END_CATCH
     }
   else
     {
@@ -1982,18 +1980,17 @@ do_one_display (struct display *d)
       get_formatted_print_options (&opts, d->format.format);
       opts.raw = d->format.raw;
 
-      TRY
+      try
         {
 	  struct value *val;
 
 	  val = evaluate_expression (d->exp.get ());
 	  print_formatted (val, d->format.size, &opts, gdb_stdout);
 	}
-      CATCH (ex, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 	{
 	  fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message.c_str ());
 	}
-      END_CATCH
 
       printf_filtered ("\n");
     }
@@ -2176,7 +2173,7 @@ print_variable_and_value (const char *name, struct symbol *var,
   fputs_styled (name, variable_name_style.style (), stream);
   fputs_filtered (" = ", stream);
 
-  TRY
+  try
     {
       struct value *val;
       struct value_print_options opts;
@@ -2194,12 +2191,11 @@ print_variable_and_value (const char *name, struct symbol *var,
 	 function.  */
       frame = NULL;
     }
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       fprintf_filtered (stream, "<error reading variable %s (%s)>", name,
 			except.message.c_str ());
     }
-  END_CATCH
 
   fprintf_filtered (stream, "\n");
 }
diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c
index 23cb2c58326..9b234577594 100644
--- a/gdb/python/py-arch.c
+++ b/gdb/python/py-arch.c
@@ -199,16 +199,15 @@ archpy_disassemble (PyObject *self, PyObject *args, PyObject *kw)
 
       string_file stb;
 
-      TRY
+      try
         {
           insn_len = gdb_print_insn (gdbarch, pc, &stb, NULL);
         }
-      CATCH (except, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
         {
 	  gdbpy_convert_exception (except);
 	  return NULL;
         }
-      END_CATCH
 
       if (PyDict_SetItemString (insn_dict.get (), "addr",
                                 gdb_py_long_from_ulongest (pc))
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index ba3b4f0fc38..835d3d9dd45 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -138,18 +138,17 @@ bppy_set_enabled (PyObject *self, PyObject *newvalue, void *closure)
   if (cmp < 0)
     return -1;
 
-  TRY
+  try
     {
       if (cmp == 1)
 	enable_breakpoint (self_bp->bp);
       else
 	disable_breakpoint (self_bp->bp);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_SET_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return 0;
 }
@@ -247,15 +246,14 @@ bppy_set_task (PyObject *self, PyObject *newvalue, void *closure)
       if (! gdb_py_int_as_long (newvalue, &id))
 	return -1;
 
-      TRY
+      try
 	{
 	  valid_id = valid_task_id (id);
 	}
-      CATCH (except, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
 	{
 	  GDB_PY_SET_HANDLE_EXCEPTION (except);
 	}
-      END_CATCH
 
       if (! valid_id)
 	{
@@ -290,15 +288,14 @@ bppy_delete_breakpoint (PyObject *self, PyObject *args)
 
   BPPY_REQUIRE_VALID (self_bp);
 
-  TRY
+  try
     {
       delete_breakpoint (self_bp->bp);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   Py_RETURN_NONE;
 }
@@ -332,15 +329,14 @@ bppy_set_ignore_count (PyObject *self, PyObject *newvalue, void *closure)
   if (value < 0)
     value = 0;
 
-  TRY
+  try
     {
       set_ignore_count (self_bp->number, (int) value, 0);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_SET_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return 0;
 }
@@ -469,15 +465,14 @@ bppy_set_condition (PyObject *self, PyObject *newvalue, void *closure)
       exp = exp_holder.get ();
     }
 
-  TRY
+  try
     {
       set_breakpoint_condition (self_bp->bp, exp, 0);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       except = ex;
     }
-  END_CATCH
 
   GDB_PY_SET_HANDLE_EXCEPTION (except);
 
@@ -499,17 +494,16 @@ bppy_get_commands (PyObject *self, void *closure)
   string_file stb;
 
   current_uiout->redirect (&stb);
-  TRY
+  try
     {
       print_command_lines (current_uiout, breakpoint_commands (bp), 0);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       current_uiout->redirect (NULL);
       gdbpy_convert_exception (except);
       return NULL;
     }
-  END_CATCH
 
   current_uiout->redirect (NULL);
   return host_string_to_python_string (stb.c_str ()).release ();
@@ -530,7 +524,7 @@ bppy_set_commands (PyObject *self, PyObject *newvalue, void *closure)
   if (commands == nullptr)
     return -1;
 
-  TRY
+  try
     {
       bool first = true;
       char *save_ptr = nullptr;
@@ -546,11 +540,10 @@ bppy_set_commands (PyObject *self, PyObject *newvalue, void *closure)
       counted_command_line lines = read_command_lines_1 (reader, 1, nullptr);
       breakpoint_set_commands (self_bp->bp, std::move (lines));
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       except = ex;
     }
-  END_CATCH
 
   GDB_PY_SET_HANDLE_EXCEPTION (except);
 
@@ -801,7 +794,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
   bppy_pending_object->number = -1;
   bppy_pending_object->bp = NULL;
 
-  TRY
+  try
     {
       switch (type)
 	{
@@ -871,13 +864,12 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 	  error(_("Do not understand breakpoint type to set."));
 	}
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       bppy_pending_object = NULL;
       gdbpy_convert_exception (except);
       return -1;
     }
-  END_CATCH
 
   BPPY_SET_REQUIRE_VALID ((gdbpy_breakpoint_object *) self);
   return 0;
diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c
index 1677c3dcec9..4812c6acca0 100644
--- a/gdb/python/py-cmd.c
+++ b/gdb/python/py-cmd.c
@@ -541,7 +541,7 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
 
   gdbpy_ref<> self_ref = gdbpy_ref<>::new_reference (self);
 
-  TRY
+  try
     {
       struct cmd_list_element *cmd;
 
@@ -572,7 +572,7 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
 	set_cmd_completer_handle_brkchars (cmd,
 					   cmdpy_completer_handle_brkchars);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       xfree (cmd_name);
       xfree (docstring);
@@ -580,7 +580,6 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
       gdbpy_convert_exception (except);
       return -1;
     }
-  END_CATCH
 
   return 0;
 }
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index f3affbd0f43..e23f5c18ea1 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -101,7 +101,7 @@ bpfinishpy_pre_stop_hook (struct gdbpy_breakpoint_object *bp_obj)
   if (!self_finishbp->return_type)
     return;
 
-  TRY
+  try
     {
       struct value *function =
         value_object_to_value (self_finishbp->function_value);
@@ -121,12 +121,11 @@ bpfinishpy_pre_stop_hook (struct gdbpy_breakpoint_object *bp_obj)
           self_finishbp->return_value = Py_None;
         }
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       gdbpy_convert_exception (except);
       gdbpy_print_stack ();
     }
-  END_CATCH
 }
 
 /* Triggered when gdbpy_should_stop has triggered the `stop' callback
@@ -136,18 +135,17 @@ void
 bpfinishpy_post_stop_hook (struct gdbpy_breakpoint_object *bp_obj)
 {
 
-  TRY
+  try
     {
       /* Can't delete it here, but it will be removed at the next stop.  */
       disable_breakpoint (bp_obj->bp);
       gdb_assert (bp_obj->bp->disposition == disp_del);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       gdbpy_convert_exception (except);
       gdbpy_print_stack ();
     }
-  END_CATCH
 }
 
 /* Python function to create a new breakpoint.  */
@@ -172,7 +170,7 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 					&frame_obj, &internal))
     return -1;
 
-  TRY
+  try
     {
       /* Default frame to newest frame if necessary.  */
       if (frame_obj == NULL)
@@ -210,12 +208,11 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 	    }
 	}
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       gdbpy_convert_exception (except);
       return -1;
     }
-  END_CATCH
 
   if (PyErr_Occurred ())
     return -1;
@@ -244,7 +241,7 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
   self_bpfinish->return_type = NULL;
   self_bpfinish->function_value = NULL;
 
-  TRY
+  try
     {
       if (get_frame_pc_if_available (frame, &pc))
         {
@@ -270,12 +267,11 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
             }
         }
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       /* Just swallow.  Either the return type or the function value
 	 remain NULL.  */
     }
-  END_CATCH
 
   if (self_bpfinish->return_type == NULL || self_bpfinish->function_value == NULL)
     {
@@ -291,7 +287,7 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
   bppy_pending_object->number = -1;
   bppy_pending_object->bp = NULL;
 
-  TRY
+  try
     {
       /* Set a breakpoint on the return address.  */
       event_location_up location
@@ -306,11 +302,10 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
                          &bkpt_breakpoint_ops,
                          0, 1, internal_bp, 0);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_SET_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   self_bpfinish->py_bp.bp->frame_id = frame_id;
   self_bpfinish->py_bp.is_finish_bp = 1;
@@ -362,19 +357,18 @@ bpfinishpy_detect_out_scope_cb (struct breakpoint *b, void *args)
       /* Check scope if not currently stopped at the FinishBreakpoint.  */
       if (b != bp_stopped)
         {
-          TRY
+          try
             {
               if (b->pspace == current_inferior ()->pspace
                   && (!target_has_registers
                       || frame_find_by_id (b->frame_id) == NULL))
                 bpfinishpy_out_of_scope (finish_bp);
             }
-          CATCH (except, RETURN_MASK_ALL)
+          catch (const struct gdb_exception_RETURN_MASK_ALL &except)
             {
               gdbpy_convert_exception (except);
               gdbpy_print_stack ();
             }
-	  END_CATCH
         }
     }
 
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 0eef6543f84..32891dc048a 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -95,15 +95,14 @@ frapy_is_valid (PyObject *self, PyObject *args)
 {
   struct frame_info *frame = NULL;
 
-  TRY
+  try
     {
       frame = frame_object_to_frame_info (self);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (frame == NULL)
     Py_RETURN_FALSE;
@@ -122,17 +121,16 @@ frapy_name (PyObject *self, PyObject *args)
   enum language lang;
   PyObject *result;
 
-  TRY
+  try
     {
       FRAPY_REQUIRE_VALID (self, frame);
 
       name = find_frame_funname (frame, &lang, NULL);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (name)
     {
@@ -157,17 +155,16 @@ frapy_type (PyObject *self, PyObject *args)
   struct frame_info *frame;
   enum frame_type type = NORMAL_FRAME;/* Initialize to appease gcc warning.  */
 
-  TRY
+  try
     {
       FRAPY_REQUIRE_VALID (self, frame);
 
       type = get_frame_type (frame);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return PyInt_FromLong (type);
 }
@@ -181,15 +178,14 @@ frapy_arch (PyObject *self, PyObject *args)
   struct frame_info *frame = NULL;    /* Initialize to appease gcc warning.  */
   frame_object *obj = (frame_object *) self;
 
-  TRY
+  try
     {
       FRAPY_REQUIRE_VALID (self, frame);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return gdbarch_to_arch_object (obj->gdbarch);
 }
@@ -203,15 +199,14 @@ frapy_unwind_stop_reason (PyObject *self, PyObject *args)
   struct frame_info *frame = NULL;    /* Initialize to appease gcc warning.  */
   enum unwind_stop_reason stop_reason;
 
-  TRY
+  try
     {
       FRAPY_REQUIRE_VALID (self, frame);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   stop_reason = get_frame_unwind_stop_reason (frame);
 
@@ -227,17 +222,16 @@ frapy_pc (PyObject *self, PyObject *args)
   CORE_ADDR pc = 0;	      /* Initialize to appease gcc warning.  */
   struct frame_info *frame;
 
-  TRY
+  try
     {
       FRAPY_REQUIRE_VALID (self, frame);
 
       pc = get_frame_pc (frame);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return gdb_py_long_from_ulongest (pc);
 }
@@ -254,7 +248,7 @@ frapy_read_register (PyObject *self, PyObject *args)
   if (!PyArg_ParseTuple (args, "s", &regnum_str))
     return NULL;
 
-  TRY
+  try
     {
       struct frame_info *frame;
       int regnum;
@@ -270,11 +264,10 @@ frapy_read_register (PyObject *self, PyObject *args)
       if (val == NULL)
         PyErr_SetString (PyExc_ValueError, _("Unknown register."));
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return val == NULL ? NULL : value_to_value_object (val);
 }
@@ -288,16 +281,15 @@ frapy_block (PyObject *self, PyObject *args)
   struct frame_info *frame;
   const struct block *block = NULL, *fn_block;
 
-  TRY
+  try
     {
       FRAPY_REQUIRE_VALID (self, frame);
       block = get_frame_block (frame, NULL);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   for (fn_block = block;
        fn_block != NULL && BLOCK_FUNCTION (fn_block) == NULL;
@@ -330,7 +322,7 @@ frapy_function (PyObject *self, PyObject *args)
   struct symbol *sym = NULL;
   struct frame_info *frame;
 
-  TRY
+  try
     {
       enum language funlang;
 
@@ -339,11 +331,10 @@ frapy_function (PyObject *self, PyObject *args)
       gdb::unique_xmalloc_ptr<char> funname
 	= find_frame_funname (frame, &funlang, &sym);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (sym)
     return symbol_to_symbol_object (sym);
@@ -362,7 +353,7 @@ frame_info_to_frame_object (struct frame_info *frame)
   if (frame_obj == NULL)
     return NULL;
 
-  TRY
+  try
     {
 
       /* Try to get the previous frame, to determine if this is the last frame
@@ -382,12 +373,11 @@ frame_info_to_frame_object (struct frame_info *frame)
 	}
       frame_obj->gdbarch = get_frame_arch (frame);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       gdbpy_convert_exception (except);
       return NULL;
     }
-  END_CATCH
 
   return (PyObject *) frame_obj.release ();
 }
@@ -402,17 +392,16 @@ frapy_older (PyObject *self, PyObject *args)
   struct frame_info *frame, *prev = NULL;
   PyObject *prev_obj = NULL;   /* Initialize to appease gcc warning.  */
 
-  TRY
+  try
     {
       FRAPY_REQUIRE_VALID (self, frame);
 
       prev = get_prev_frame (frame);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (prev)
     prev_obj = frame_info_to_frame_object (prev);
@@ -435,17 +424,16 @@ frapy_newer (PyObject *self, PyObject *args)
   struct frame_info *frame, *next = NULL;
   PyObject *next_obj = NULL;   /* Initialize to appease gcc warning.  */
 
-  TRY
+  try
     {
       FRAPY_REQUIRE_VALID (self, frame);
 
       next = get_next_frame (frame);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (next)
     next_obj = frame_info_to_frame_object (next);
@@ -467,18 +455,17 @@ frapy_find_sal (PyObject *self, PyObject *args)
   struct frame_info *frame;
   PyObject *sal_obj = NULL;   /* Initialize to appease gcc warning.  */
 
-  TRY
+  try
     {
       FRAPY_REQUIRE_VALID (self, frame);
 
       symtab_and_line sal = find_frame_sal (frame);
       sal_obj = symtab_and_line_to_sal_object (sal);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return sal_obj;
 }
@@ -523,7 +510,7 @@ frapy_read_var (PyObject *self, PyObject *args)
 	    }
 	}
 
-      TRY
+      try
 	{
 	  struct block_symbol lookup_sym;
 	  FRAPY_REQUIRE_VALID (self, frame);
@@ -534,12 +521,11 @@ frapy_read_var (PyObject *self, PyObject *args)
 	  var = lookup_sym.symbol;
 	  block = lookup_sym.block;
 	}
-      CATCH (except, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
 	{
 	  gdbpy_convert_exception (except);
 	  return NULL;
 	}
-      END_CATCH
 
       if (!var)
 	{
@@ -556,17 +542,16 @@ frapy_read_var (PyObject *self, PyObject *args)
       return NULL;
     }
 
-  TRY
+  try
     {
       FRAPY_REQUIRE_VALID (self, frame);
 
       val = read_var_value (var, block, frame);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return value_to_value_object (val);
 }
@@ -578,17 +563,16 @@ frapy_select (PyObject *self, PyObject *args)
 {
   struct frame_info *fi;
 
-  TRY
+  try
     {
       FRAPY_REQUIRE_VALID (self, fi);
 
       select_frame (fi);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   Py_RETURN_NONE;
 }
@@ -601,15 +585,14 @@ gdbpy_newest_frame (PyObject *self, PyObject *args)
 {
   struct frame_info *frame = NULL;
 
-  TRY
+  try
     {
       frame = get_current_frame ();
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return frame_info_to_frame_object (frame);
 }
@@ -622,15 +605,14 @@ gdbpy_selected_frame (PyObject *self, PyObject *args)
 {
   struct frame_info *frame = NULL;
 
-  TRY
+  try
     {
       frame = get_selected_frame ("No frame is currently selected.");
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return frame_info_to_frame_object (frame);
 }
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index 7f416cb6d30..545ed713efd 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -1081,16 +1081,15 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang,
   if (!gdb_python_initialized)
     return EXT_LANG_BT_NO_FILTERS;
 
-  TRY
+  try
     {
       gdbarch = get_frame_arch (frame);
     }
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       /* Let gdb try to print the stack trace.  */
       return EXT_LANG_BT_NO_FILTERS;
     }
-  END_CATCH
 
   gdbpy_enter enter_py (gdbarch, current_language);
 
@@ -1166,17 +1165,16 @@ gdbpy_apply_frame_filter (const struct extension_language_defn *extlang,
 	    }
 	}
 
-      TRY
+      try
 	{
 	  success = py_print_frame (item.get (), flags, args_type, out, 0,
 				    levels_printed.get ());
 	}
-      CATCH (except, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	{
 	  gdbpy_convert_exception (except);
 	  success = EXT_LANG_BT_ERROR;
 	}
-      END_CATCH
 
       /* Do not exit on error printing a single frame.  Print the
 	 error and continue with other frames.  */
diff --git a/gdb/python/py-gdb-readline.c b/gdb/python/py-gdb-readline.c
index 1e6cd739d6a..6fefc470df9 100644
--- a/gdb/python/py-gdb-readline.c
+++ b/gdb/python/py-gdb-readline.c
@@ -39,12 +39,12 @@ gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout,
   int n;
   char *p = NULL, *q;
 
-  TRY
+  try
     {
       p = command_line_input (prompt, "python");
     }
   /* Handle errors by raising Python exceptions.  */
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       /* Detect user interrupt (Ctrl-C).  */
       if (except.reason == RETURN_QUIT)
@@ -59,7 +59,6 @@ gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout,
       PyEval_SaveThread ();
       return NULL;
     }
-  END_CATCH
 
   /* Detect EOF (Ctrl-D).  */
   if (p == NULL)
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index 72fbf6d90b9..082c7b1aeec 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -389,15 +389,14 @@ infpy_threads (PyObject *self, PyObject *args)
 
   INFPY_REQUIRE_VALID (inf_obj);
 
-  TRY
+  try
     {
       update_thread_list ();
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   tuple = PyTuple_New (inf_obj->nthreads);
   if (!tuple)
@@ -508,17 +507,16 @@ infpy_read_memory (PyObject *self, PyObject *args, PyObject *kw)
       || get_addr_from_python (length_obj, &length) < 0)
     return NULL;
 
-  TRY
+  try
     {
       buffer.reset ((gdb_byte *) xmalloc (length));
 
       read_memory (addr, buffer.get (), length);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   gdbpy_ref<membuf_object> membuf_obj (PyObject_New (membuf_object,
 						     &membuf_object_type));
@@ -572,15 +570,14 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
   else if (get_addr_from_python (length_obj, &length) < 0)
     return nullptr;
 
-  TRY
+  try
     {
       write_memory_with_notification (addr, buffer, length);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       except = ex;
     }
-  END_CATCH
 
   GDB_PY_HANDLE_EXCEPTION (except);
 
@@ -725,17 +722,16 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
       return nullptr;
     }
 
-  TRY
+  try
     {
       found = target_search_memory (start_addr, length,
 				    buffer, pattern_size,
 				    &found_addr);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       except = ex;
     }
-  END_CATCH
 
   GDB_PY_HANDLE_EXCEPTION (except);
 
@@ -782,7 +778,7 @@ infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw)
       return NULL;
     }
 
-  TRY
+  try
     {
       struct thread_info *thread_info;
       struct value *val = value_object_to_value (handle_obj);
@@ -791,11 +787,10 @@ infpy_thread_from_thread_handle (PyObject *self, PyObject *args, PyObject *kw)
       if (thread_info != NULL)
 	return thread_to_thread_object (thread_info).release ();
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   Py_RETURN_NONE;
 }
diff --git a/gdb/python/py-infthread.c b/gdb/python/py-infthread.c
index bf90d08ae6e..66a3b3ef014 100644
--- a/gdb/python/py-infthread.c
+++ b/gdb/python/py-infthread.c
@@ -181,15 +181,14 @@ thpy_switch (PyObject *self, PyObject *args)
 
   THPY_REQUIRE_VALID (thread_obj);
 
-  TRY
+  try
     {
       switch_to_thread (thread_obj->thread);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   Py_RETURN_NONE;
 }
diff --git a/gdb/python/py-lazy-string.c b/gdb/python/py-lazy-string.c
index 443aeb7f45b..24beac3bb75 100644
--- a/gdb/python/py-lazy-string.c
+++ b/gdb/python/py-lazy-string.c
@@ -113,7 +113,7 @@ stpy_convert_to_value (PyObject *self, PyObject *args)
       return NULL;
     }
 
-  TRY
+  try
     {
       struct type *type = type_object_to_type (self_string->type);
       struct type *realtype;
@@ -142,11 +142,10 @@ stpy_convert_to_value (PyObject *self, PyObject *args)
 	  break;
 	}
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return value_to_value_object (val);
 }
diff --git a/gdb/python/py-linetable.c b/gdb/python/py-linetable.c
index b9d74b8aa3d..9cabec788ba 100644
--- a/gdb/python/py-linetable.c
+++ b/gdb/python/py-linetable.c
@@ -164,15 +164,14 @@ ltpy_get_pcs_for_line (PyObject *self, PyObject *args)
   if (! PyArg_ParseTuple (args, GDB_PY_LL_ARG, &py_line))
     return NULL;
 
-  TRY
+  try
     {
       pcs = find_pcs_for_symtab_line (symtab, py_line, &best_entry);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return build_line_table_tuple_from_pcs (py_line, pcs);
 }
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index 67f63b314e3..fc2fefbaea1 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -130,15 +130,14 @@ objfpy_get_build_id (PyObject *self, void *closure)
 
   OBJFPY_REQUIRE_VALID (obj);
 
-  TRY
+  try
     {
       build_id = build_id_bfd_get (objfile->obfd);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (build_id != NULL)
     {
@@ -421,17 +420,16 @@ objfpy_add_separate_debug_file (PyObject *self, PyObject *args, PyObject *kw)
   if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s", keywords, &file_name))
     return NULL;
 
-  TRY
+  try
     {
       gdb_bfd_ref_ptr abfd (symfile_bfd_open (file_name));
 
       symbol_file_add_separate (abfd.get (), file_name, 0, obj->objfile);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   Py_RETURN_NONE;
 }
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index 3b79a5c4fd7..b6da0d102e2 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -726,21 +726,20 @@ parmpy_init (PyObject *self, PyObject *args, PyObject *kwds)
 
   Py_INCREF (self);
 
-  TRY
+  try
     {
       add_setshow_generic (parmclass, (enum command_class) cmdtype,
 			   cmd_name, obj,
 			   set_doc.get (), show_doc.get (),
 			   doc.get (), set_list, show_list);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       xfree (cmd_name);
       Py_DECREF (self);
       gdbpy_convert_exception (except);
       return -1;
     }
-  END_CATCH
 
   return 0;
 }
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index b069ca3a9f9..09e7dcf8ed4 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -190,7 +190,7 @@ pretty_print_one_value (PyObject *printer, struct value **out_value)
   gdbpy_ref<> result;
 
   *out_value = NULL;
-  TRY
+  try
     {
       if (!PyObject_HasAttr (printer, gdbpy_to_string_cst))
 	result = gdbpy_ref<>::new_reference (Py_None);
@@ -212,10 +212,9 @@ pretty_print_one_value (PyObject *printer, struct value **out_value)
 	    }
 	}
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
     }
-  END_CATCH
 
   return result;
 }
@@ -642,15 +641,14 @@ apply_varobj_pretty_printer (PyObject *printer_obj,
 gdbpy_ref<>
 gdbpy_get_varobj_pretty_printer (struct value *value)
 {
-  TRY
+  try
     {
       value = value_copy (value);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   gdbpy_ref<> val_obj (value_to_value_object (value));
   if (val_obj == NULL)
diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c
index b82a91b44d5..58440e9b26a 100644
--- a/gdb/python/py-progspace.c
+++ b/gdb/python/py-progspace.c
@@ -381,7 +381,7 @@ pspy_block_for_pc (PyObject *o, PyObject *args)
   if (!PyArg_ParseTuple (args, GDB_PY_LLU_ARG, &pc))
     return NULL;
 
-  TRY
+  try
     {
       scoped_restore_current_program_space saver;
 
@@ -391,11 +391,10 @@ pspy_block_for_pc (PyObject *o, PyObject *args)
       if (cust != NULL && COMPUNIT_OBJFILE (cust) != NULL)
 	block = block_for_pc (pc);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (cust == NULL || COMPUNIT_OBJFILE (cust) == NULL)
     {
@@ -425,7 +424,7 @@ pspy_find_pc_line (PyObject *o, PyObject *args)
   if (!PyArg_ParseTuple (args, GDB_PY_LLU_ARG, &pc_llu))
     return NULL;
 
-  TRY
+  try
     {
       struct symtab_and_line sal;
       CORE_ADDR pc;
@@ -437,11 +436,10 @@ pspy_find_pc_line (PyObject *o, PyObject *args)
       sal = find_pc_line (pc, 0);
       result = symtab_and_line_to_sal_object (sal);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return result;
 }
diff --git a/gdb/python/py-record-btrace.c b/gdb/python/py-record-btrace.c
index 229a3b8756b..10509885a5a 100644
--- a/gdb/python/py-record-btrace.c
+++ b/gdb/python/py-record-btrace.c
@@ -208,15 +208,14 @@ recpy_bt_insn_sal (PyObject *self, void *closure)
   if (insn == NULL)
     return NULL;
 
-  TRY
+  try
     {
       result = symtab_and_line_to_sal_object (find_pc_line (insn->pc, 0));
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return result;
 }
@@ -279,16 +278,15 @@ recpy_bt_insn_data (PyObject *self, void *closure)
   if (insn == NULL)
     return NULL;
 
-  TRY
+  try
     {
       buffer.resize (insn->size);
       read_memory (insn->pc, buffer.data (), insn->size);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   object = PyBytes_FromStringAndSize ((const char *) buffer.data (),
 				      insn->size);
@@ -316,16 +314,15 @@ recpy_bt_insn_decoded (PyObject *self, void *closure)
   if (insn == NULL)
     return NULL;
 
-  TRY
+  try
     {
       gdb_print_insn (target_gdbarch (), insn->pc, &strfile, NULL);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       gdbpy_convert_exception (except);
       return NULL;
     }
-  END_CATCH
 
 
   return PyBytes_FromString (strfile.string ().c_str ());
@@ -787,7 +784,7 @@ recpy_bt_goto (PyObject *self, PyObject *args)
     return PyErr_Format (PyExc_TypeError, _("Argument must be instruction."));
   obj = (const recpy_element_object *) parse_obj;
 
-  TRY
+  try
     {
       struct btrace_insn_iterator iter;
 
@@ -798,11 +795,10 @@ recpy_bt_goto (PyObject *self, PyObject *args)
       else
 	target_goto_record (obj->number);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   Py_RETURN_NONE;
 }
diff --git a/gdb/python/py-record.c b/gdb/python/py-record.c
index e818560174e..ee4a32f4aeb 100644
--- a/gdb/python/py-record.c
+++ b/gdb/python/py-record.c
@@ -602,16 +602,15 @@ gdbpy_start_recording (PyObject *self, PyObject *args)
   if (!PyArg_ParseTuple (args, "|ss", &method, &format))
     return NULL;
 
-  TRY
+  try
     {
       record_start (method, format, 0);
       ret = gdbpy_current_recording (self, args);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       gdbpy_convert_exception (except);
     }
-  END_CATCH
 
   return ret;
 }
@@ -638,15 +637,14 @@ gdbpy_current_recording (PyObject *self, PyObject *args)
 PyObject *
 gdbpy_stop_recording (PyObject *self, PyObject *args)
 {
-  TRY
+  try
     {
       record_stop (0);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   Py_RETURN_NONE;
 }
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index afff9950689..3ec526ad7bc 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -196,15 +196,14 @@ sympy_needs_frame (PyObject *self, void *closure)
 
   SYMPY_REQUIRE_VALID (self, symbol);
 
-  TRY
+  try
     {
       result = symbol_read_needs_frame (symbol);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (result)
     Py_RETURN_TRUE;
@@ -266,7 +265,7 @@ sympy_value (PyObject *self, PyObject *args)
       return NULL;
     }
 
-  TRY
+  try
     {
       if (frame_obj != NULL)
 	{
@@ -284,11 +283,10 @@ sympy_value (PyObject *self, PyObject *args)
 	 can happen with nested functions).  */
       value = read_var_value (symbol, NULL, frame_info);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return value_to_value_object (value);
 }
@@ -388,28 +386,26 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
     {
       struct frame_info *selected_frame;
 
-      TRY
+      try
 	{
 	  selected_frame = get_selected_frame (_("No frame selected."));
 	  block = get_frame_block (selected_frame, NULL);
 	}
-      CATCH (except, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
 	{
 	  GDB_PY_HANDLE_EXCEPTION (except);
 	}
-      END_CATCH
     }
 
-  TRY
+  try
     {
       symbol = lookup_symbol (name, block, (domain_enum) domain,
 			      &is_a_field_of_this).symbol;
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   gdbpy_ref<> ret_tuple (PyTuple_New (2));
   if (ret_tuple == NULL)
@@ -451,15 +447,14 @@ gdbpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw)
 					&domain))
     return NULL;
 
-  TRY
+  try
     {
       symbol = lookup_global_symbol (name, NULL, (domain_enum) domain).symbol;
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (symbol)
     {
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index c908ec62de6..27c8126827e 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -312,15 +312,14 @@ typy_fields_items (PyObject *self, enum gdbpy_iter_kind kind)
   struct type *type = ((type_object *) py_type)->type;
   struct type *checked_type = type;
 
-  TRY
+  try
     {
       checked_type = check_typedef (checked_type);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   gdbpy_ref<> type_holder;
   if (checked_type != type)
@@ -420,15 +419,14 @@ typy_strip_typedefs (PyObject *self, PyObject *args)
 {
   struct type *type = ((type_object *) self)->type;
 
-  TRY
+  try
     {
       type = check_typedef (type);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return type_to_type_object (type);
 }
@@ -442,15 +440,14 @@ typy_get_composite (struct type *type)
 
   for (;;)
     {
-      TRY
+      try
 	{
 	  type = check_typedef (type);
 	}
-      CATCH (except, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
 	{
 	  GDB_PY_HANDLE_EXCEPTION (except);
 	}
-      END_CATCH
 
       if (TYPE_CODE (type) != TYPE_CODE_PTR && !TYPE_IS_REFERENCE (type))
 	break;
@@ -510,17 +507,16 @@ typy_array_1 (PyObject *self, PyObject *args, int is_vector)
       return NULL;
     }
 
-  TRY
+  try
     {
       array = lookup_array_range_type (type, n1, n2);
       if (is_vector)
 	make_vector_type (array);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return type_to_type_object (array);
 }
@@ -547,15 +543,14 @@ typy_pointer (PyObject *self, PyObject *args)
 {
   struct type *type = ((type_object *) self)->type;
 
-  TRY
+  try
     {
       type = lookup_pointer_type (type);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return type_to_type_object (type);
 }
@@ -616,15 +611,14 @@ typy_reference (PyObject *self, PyObject *args)
 {
   struct type *type = ((type_object *) self)->type;
 
-  TRY
+  try
     {
       type = lookup_lvalue_reference_type (type);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return type_to_type_object (type);
 }
@@ -651,15 +645,14 @@ typy_const (PyObject *self, PyObject *args)
 {
   struct type *type = ((type_object *) self)->type;
 
-  TRY
+  try
     {
       type = make_cv_type (1, 0, type, NULL);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return type_to_type_object (type);
 }
@@ -670,15 +663,14 @@ typy_volatile (PyObject *self, PyObject *args)
 {
   struct type *type = ((type_object *) self)->type;
 
-  TRY
+  try
     {
       type = make_cv_type (0, 1, type, NULL);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return type_to_type_object (type);
 }
@@ -689,15 +681,14 @@ typy_unqualified (PyObject *self, PyObject *args)
 {
   struct type *type = ((type_object *) self)->type;
 
-  TRY
+  try
     {
       type = make_cv_type (0, 0, type, NULL);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return type_to_type_object (type);
 }
@@ -708,14 +699,13 @@ typy_get_sizeof (PyObject *self, void *closure)
 {
   struct type *type = ((type_object *) self)->type;
 
-  TRY
+  try
     {
       check_typedef (type);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
     }
-  END_CATCH
 
   /* Ignore exceptions.  */
 
@@ -729,15 +719,14 @@ typy_get_alignof (PyObject *self, void *closure)
   struct type *type = ((type_object *) self)->type;
 
   ULONGEST align = 0;
-  TRY
+  try
     {
       align = type_align (type);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       align = 0;
     }
-  END_CATCH
 
   /* Ignore exceptions.  */
 
@@ -749,7 +738,7 @@ typy_lookup_typename (const char *type_name, const struct block *block)
 {
   struct type *type = NULL;
 
-  TRY
+  try
     {
       if (startswith (type_name, "struct "))
 	type = lookup_struct (type_name + 7, NULL);
@@ -761,11 +750,10 @@ typy_lookup_typename (const char *type_name, const struct block *block)
 	type = lookup_typename (python_language, python_gdbarch,
 				type_name, block, 0);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return type;
 }
@@ -791,7 +779,7 @@ typy_lookup_type (struct demangle_component *demangled,
       if (! type)
 	return NULL;
 
-      TRY
+      try
 	{
 	  /* If the demangled_type matches with one of the types
 	     below, run the corresponding function and save the type
@@ -816,11 +804,10 @@ typy_lookup_type (struct demangle_component *demangled,
 	      break;
 	    }
 	}
-      CATCH (except, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
 	{
 	  GDB_PY_HANDLE_EXCEPTION (except);
 	}
-      END_CATCH
     }
 
   /* If we have a type from the switch statement above, just return
@@ -854,16 +841,15 @@ typy_legacy_template_argument (struct type *type, const struct block *block,
       return NULL;
     }
 
-  TRY
+  try
     {
       /* Note -- this is not thread-safe.  */
       info = cp_demangled_name_to_comp (TYPE_NAME (type), &err);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (! info)
     {
@@ -934,17 +920,16 @@ typy_template_argument (PyObject *self, PyObject *args)
 	}
     }
 
-  TRY
+  try
     {
       type = check_typedef (type);
       if (TYPE_IS_REFERENCE (type))
 	type = check_typedef (TYPE_TARGET_TYPE (type));
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   /* We might not have DW_TAG_template_*, so try to parse the type's
      name.  This is inefficient if we do not have a template type --
@@ -969,15 +954,14 @@ typy_template_argument (PyObject *self, PyObject *args)
       return NULL;
     }
 
-  TRY
+  try
     {
       val = value_of_variable (sym, block);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return value_to_value_object (val);
 }
@@ -987,16 +971,15 @@ typy_str (PyObject *self)
 {
   string_file thetype;
 
-  TRY
+  try
     {
       LA_PRINT_TYPE (type_object_to_type (self), "", &thetype, -1, 0,
 		     &type_print_raw_options);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return PyUnicode_Decode (thetype.c_str (), thetype.size (),
 			   host_charset (), NULL);
@@ -1023,17 +1006,16 @@ typy_richcompare (PyObject *self, PyObject *other, int op)
     result = true;
   else
     {
-      TRY
+      try
 	{
 	  result = types_deeply_equal (type1, type2);
 	}
-      CATCH (except, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
 	{
 	  /* If there is a GDB exception, a comparison is not capable
 	     (or trusted), so exit.  */
 	  GDB_PY_HANDLE_EXCEPTION (except);
 	}
-      END_CATCH
     }
 
   if (op == (result ? Py_EQ : Py_NE))
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index f07a8d8fa20..135863cd417 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -141,7 +141,7 @@ pyuw_value_obj_to_pointer (PyObject *pyo_value, CORE_ADDR *addr)
   int rc = 0;
   struct value *value;
 
-  TRY
+  try
     {
       if ((value = value_object_to_value (pyo_value)) != NULL)
         {
@@ -150,11 +150,10 @@ pyuw_value_obj_to_pointer (PyObject *pyo_value, CORE_ADDR *addr)
           rc = 1;
         }
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       gdbpy_convert_exception (except);
     }
-  END_CATCH
   return rc;
 }
 
@@ -211,16 +210,15 @@ unwind_infopy_str (PyObject *self)
         stb.printf ("%s(%d, ", sep, reg.number);
         if (value != NULL)
           {
-            TRY
+            try
               {
                 value_print (value, &stb, &opts);
                 stb.puts (")");
               }
-            CATCH (except, RETURN_MASK_ALL)
+            catch (const struct gdb_exception_RETURN_MASK_ALL &except)
               {
                 GDB_PY_HANDLE_EXCEPTION (except);
               }
-            END_CATCH
           }
         else
           stb.puts ("<BAD>)");
@@ -346,16 +344,15 @@ pending_framepy_str (PyObject *self)
 
   if (frame == NULL)
     return PyString_FromString ("Stale PendingFrame instance");
-  TRY
+  try
     {
       sp_str = core_addr_to_string_nz (get_frame_sp (frame));
       pc_str = core_addr_to_string_nz (get_frame_pc (frame));
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return PyString_FromFormat ("SP=%s,PC=%s", sp_str, pc_str);
 }
@@ -385,7 +382,7 @@ pending_framepy_read_register (PyObject *self, PyObject *args)
       return NULL;
     }
 
-  TRY
+  try
     {
       /* Fetch the value associated with a register, whether it's
 	 a real register or a so called "user" register, like "pc",
@@ -398,11 +395,10 @@ pending_framepy_read_register (PyObject *self, PyObject *args)
                       "Cannot read register %d from frame.",
                       regnum);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return val == NULL ? NULL : value_to_value_object (val);
 }
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index e482f90a1d9..4e510c97a0d 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -261,15 +261,14 @@ get_addr_from_python (PyObject *obj, CORE_ADDR *addr)
   if (gdbpy_is_value_object (obj))
     {
 
-      TRY
+      try
 	{
 	  *addr = value_as_address (value_object_to_value (obj));
 	}
-      CATCH (except, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
 	{
 	  GDB_PY_SET_HANDLE_EXCEPTION (except);
 	}
-      END_CATCH
     }
   else
     {
diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c
index 63a9952e513..44231ee92d8 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -216,7 +216,7 @@ valpy_dereference (PyObject *self, PyObject *args)
 {
   PyObject *result = NULL;
 
-  TRY
+  try
     {
       struct value *res_val;
       scoped_value_mark free_values;
@@ -224,11 +224,10 @@ valpy_dereference (PyObject *self, PyObject *args)
       res_val = value_ind (((value_object *) self)->value);
       result = value_to_value_object (res_val);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return result;
 }
@@ -246,7 +245,7 @@ valpy_referenced_value (PyObject *self, PyObject *args)
 {
   PyObject *result = NULL;
 
-  TRY
+  try
     {
       struct value *self_val, *res_val;
       scoped_value_mark free_values;
@@ -268,11 +267,10 @@ valpy_referenced_value (PyObject *self, PyObject *args)
 
       result = value_to_value_object (res_val);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return result;
 }
@@ -284,7 +282,7 @@ valpy_reference_value (PyObject *self, PyObject *args, enum type_code refcode)
 {
   PyObject *result = NULL;
 
-  TRY
+  try
     {
       struct value *self_val;
       scoped_value_mark free_values;
@@ -292,11 +290,10 @@ valpy_reference_value (PyObject *self, PyObject *args, enum type_code refcode)
       self_val = ((value_object *) self)->value;
       result = value_to_value_object (value_ref (self_val, refcode));
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return result;
 }
@@ -320,7 +317,7 @@ valpy_const_value (PyObject *self, PyObject *args)
 {
   PyObject *result = NULL;
 
-  TRY
+  try
     {
       struct value *self_val, *res_val;
       scoped_value_mark free_values;
@@ -329,11 +326,10 @@ valpy_const_value (PyObject *self, PyObject *args)
       res_val = make_cv_value (1, 0, self_val);
       result = value_to_value_object (res_val);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return result;
 }
@@ -346,7 +342,7 @@ valpy_get_address (PyObject *self, void *closure)
 
   if (!val_obj->address)
     {
-      TRY
+      try
 	{
 	  struct value *res_val;
 	  scoped_value_mark free_values;
@@ -354,12 +350,11 @@ valpy_get_address (PyObject *self, void *closure)
 	  res_val = value_addr (val_obj->value);
 	  val_obj->address = value_to_value_object (res_val);
 	}
-      CATCH (except, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
 	{
 	  val_obj->address = Py_None;
 	  Py_INCREF (Py_None);
 	}
-      END_CATCH
     }
 
   Py_XINCREF (val_obj->address);
@@ -397,7 +392,7 @@ valpy_get_dynamic_type (PyObject *self, void *closure)
       return obj->dynamic_type;
     }
 
-  TRY
+  try
     {
       struct value *val = obj->value;
       scoped_value_mark free_values;
@@ -433,11 +428,10 @@ valpy_get_dynamic_type (PyObject *self, void *closure)
 	  type = NULL;
 	}
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (type == NULL)
     obj->dynamic_type = valpy_get_type (self, NULL);
@@ -485,7 +479,7 @@ valpy_lazy_string (PyObject *self, PyObject *args, PyObject *kw)
       return NULL;
     }
 
-  TRY
+  try
     {
       scoped_value_mark free_values;
       struct type *type, *realtype;
@@ -540,11 +534,10 @@ valpy_lazy_string (PyObject *self, PyObject *args, PyObject *kw)
       str_obj = gdbpy_create_lazy_string_object (addr, length, user_encoding,
 						 type);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return str_obj;
 }
@@ -572,15 +565,14 @@ valpy_string (PyObject *self, PyObject *args, PyObject *kw)
 					&user_encoding, &errors, &length))
     return NULL;
 
-  TRY
+  try
     {
       LA_GET_STRING (value, &buffer, &length, &char_type, &la_encoding);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   encoding = (user_encoding && *user_encoding) ? user_encoding : la_encoding;
   return PyUnicode_Decode ((const char *) buffer.get (),
@@ -607,7 +599,7 @@ valpy_do_cast (PyObject *self, PyObject *args, enum exp_opcode op)
       return NULL;
     }
 
-  TRY
+  try
     {
       struct value *val = ((value_object *) self)->value;
       struct value *res_val;
@@ -625,11 +617,10 @@ valpy_do_cast (PyObject *self, PyObject *args, enum exp_opcode op)
 
       result = value_to_value_object (res_val);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return result;
 }
@@ -690,7 +681,7 @@ value_has_field (struct value *v, PyObject *field)
       return -1;
     }
 
-  TRY
+  try
     {
       val_type = value_type (v);
       val_type = check_typedef (val_type);
@@ -704,11 +695,10 @@ value_has_field (struct value *v, PyObject *field)
       else
 	has_field = 0;
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_SET_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return has_field;
 }
@@ -829,7 +819,7 @@ valpy_getitem (PyObject *self, PyObject *key)
 	}
     }
 
-  TRY
+  try
     {
       struct value *tmp = self_value->value;
       struct value *res_val = NULL;
@@ -883,11 +873,10 @@ valpy_getitem (PyObject *self, PyObject *key)
       if (res_val)
 	result = value_to_value_object (res_val);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       except = ex;
     }
-  END_CATCH
 
   GDB_PY_HANDLE_EXCEPTION (except);
 
@@ -913,15 +902,14 @@ valpy_call (PyObject *self, PyObject *args, PyObject *keywords)
   struct type *ftype = NULL;
   PyObject *result = NULL;
 
-  TRY
+  try
     {
       ftype = check_typedef (value_type (function));
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (TYPE_CODE (ftype) != TYPE_CODE_FUNC)
     {
@@ -956,7 +944,7 @@ valpy_call (PyObject *self, PyObject *args, PyObject *keywords)
 	}
     }
 
-  TRY
+  try
     {
       scoped_value_mark free_values;
 
@@ -965,11 +953,10 @@ valpy_call (PyObject *self, PyObject *args, PyObject *keywords)
 				 gdb::make_array_view (vargs, args_count));
       result = value_to_value_object (return_value);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return result;
 }
@@ -986,16 +973,15 @@ valpy_str (PyObject *self)
 
   string_file stb;
 
-  TRY
+  try
     {
       common_val_print (((value_object *) self)->value, &stb, 0,
 			&opts, python_language);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return PyUnicode_Decode (stb.c_str (), stb.size (), host_charset (), NULL);
 }
@@ -1007,15 +993,14 @@ valpy_get_is_optimized_out (PyObject *self, void *closure)
   struct value *value = ((value_object *) self)->value;
   int opt = 0;
 
-  TRY
+  try
     {
       opt = value_optimized_out (value);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (opt)
     Py_RETURN_TRUE;
@@ -1030,15 +1015,14 @@ valpy_get_is_lazy (PyObject *self, void *closure)
   struct value *value = ((value_object *) self)->value;
   int opt = 0;
 
-  TRY
+  try
     {
       opt = value_lazy (value);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (opt)
     Py_RETURN_TRUE;
@@ -1052,16 +1036,15 @@ valpy_fetch_lazy (PyObject *self, PyObject *args)
 {
   struct value *value = ((value_object *) self)->value;
 
-  TRY
+  try
     {
       if (value_lazy (value))
 	value_fetch_lazy (value);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   Py_RETURN_NONE;
 }
@@ -1225,15 +1208,14 @@ valpy_binop (enum valpy_opcode opcode, PyObject *self, PyObject *other)
 {
   PyObject *result = NULL;
 
-  TRY
+  try
     {
       result = valpy_binop_throw (opcode, self, other);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return result;
 }
@@ -1289,7 +1271,7 @@ valpy_negative (PyObject *self)
 {
   PyObject *result = NULL;
 
-  TRY
+  try
     {
       /* Perhaps overkill, but consistency has some virtue.  */
       scoped_value_mark free_values;
@@ -1298,11 +1280,10 @@ valpy_negative (PyObject *self)
       val = value_neg (((value_object *) self)->value);
       result = value_to_value_object (val);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return result;
 }
@@ -1319,18 +1300,17 @@ valpy_absolute (PyObject *self)
   struct value *value = ((value_object *) self)->value;
   int isabs = 1;
 
-  TRY
+  try
     {
       scoped_value_mark free_values;
 
       if (value_less (value, value_zero (value_type (value), not_lval)))
 	isabs = 0;
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (isabs)
     return valpy_positive (self);
@@ -1347,7 +1327,7 @@ valpy_nonzero (PyObject *self)
   struct type *type;
   int nonzero = 0; /* Appease GCC warning.  */
 
-  TRY
+  try
     {
       type = check_typedef (value_type (self_value->value));
 
@@ -1360,11 +1340,10 @@ valpy_nonzero (PyObject *self)
 	/* All other values are True.  */
 	nonzero = 1;
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       except = ex;
     }
-  END_CATCH
 
   /* This is not documented in the Python documentation, but if this
      function fails, return -1 as slot_nb_nonzero does (the default
@@ -1380,15 +1359,14 @@ valpy_invert (PyObject *self)
 {
   struct value *val = NULL;
 
-  TRY
+  try
     {
       val = value_complement (((value_object *) self)->value);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return value_to_value_object (val);
 }
@@ -1508,15 +1486,14 @@ valpy_richcompare (PyObject *self, PyObject *other, int op)
 	return NULL;
     }
 
-  TRY
+  try
     {
       result = valpy_richcompare_throw (self, other, op);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   /* In this case, the Python exception has already been set.  */
   if (result < 0)
@@ -1537,7 +1514,7 @@ valpy_int (PyObject *self)
   struct type *type = value_type (value);
   LONGEST l = 0;
 
-  TRY
+  try
     {
       if (is_floating_value (value))
 	{
@@ -1551,11 +1528,10 @@ valpy_int (PyObject *self)
 
       l = value_as_long (value);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (TYPE_UNSIGNED (type))
     return gdb_py_object_from_ulongest (l).release ();
@@ -1572,7 +1548,7 @@ valpy_long (PyObject *self)
   struct type *type = value_type (value);
   LONGEST l = 0;
 
-  TRY
+  try
     {
       if (is_floating_value (value))
 	{
@@ -1588,11 +1564,10 @@ valpy_long (PyObject *self)
 
       l = value_as_long (value);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (TYPE_UNSIGNED (type))
     return gdb_py_long_from_ulongest (l);
@@ -1608,7 +1583,7 @@ valpy_float (PyObject *self)
   struct type *type = value_type (value);
   double d = 0;
 
-  TRY
+  try
     {
       type = check_typedef (type);
 
@@ -1624,11 +1599,10 @@ valpy_float (PyObject *self)
       else
 	error (_("Cannot convert value to float."));
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return PyFloat_FromDouble (d);
 }
@@ -1678,7 +1652,7 @@ convert_value_from_python (PyObject *obj)
 
   gdb_assert (obj != NULL);
 
-  TRY
+  try
     {
       if (PyBool_Check (obj))
 	{
@@ -1772,12 +1746,11 @@ convert_value_from_python (PyObject *obj)
 		      PyString_AsString (PyObject_Str (obj)));
 #endif
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       gdbpy_convert_exception (except);
       return NULL;
     }
-  END_CATCH
 
   return value;
 }
@@ -1792,15 +1765,14 @@ gdbpy_history (PyObject *self, PyObject *args)
   if (!PyArg_ParseTuple (args, "i", &i))
     return NULL;
 
-  TRY
+  try
     {
       res_val = access_value_history (i);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return value_to_value_object (res_val);
 }
@@ -1815,7 +1787,7 @@ gdbpy_convenience_variable (PyObject *self, PyObject *args)
   if (!PyArg_ParseTuple (args, "s", &varname))
     return NULL;
 
-  TRY
+  try
     {
       struct internalvar *var = lookup_only_internalvar (varname);
 
@@ -1826,11 +1798,10 @@ gdbpy_convenience_variable (PyObject *self, PyObject *args)
 	    res_val = NULL;
 	}
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (res_val == NULL)
     Py_RETURN_NONE;
@@ -1857,7 +1828,7 @@ gdbpy_set_convenience_variable (PyObject *self, PyObject *args)
 	return NULL;
     }
 
-  TRY
+  try
     {
       if (value == NULL)
 	{
@@ -1873,11 +1844,10 @@ gdbpy_set_convenience_variable (PyObject *self, PyObject *args)
 	  set_internalvar (var, value);
 	}
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   Py_RETURN_NONE;
 }
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 0d9415ce807..a923794bccd 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -497,15 +497,14 @@ gdbpy_parameter (PyObject *self, PyObject *args)
 
   std::string newarg = std::string ("show ") + arg;
 
-  TRY
+  try
     {
       found = lookup_cmd_composition (newarg.c_str (), &alias, &prefix, &cmd);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       GDB_PY_HANDLE_EXCEPTION (ex);
     }
-  END_CATCH
 
   if (!found)
     return PyErr_Format (PyExc_RuntimeError,
@@ -574,7 +573,7 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
 
   scoped_restore preventer = prevent_dont_repeat ();
 
-  TRY
+  try
     {
       gdbpy_allow_threads allow_threads;
 
@@ -615,11 +614,10 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
       /* Do any commands attached to breakpoint we stopped at.  */
       bpstat_do_actions ();
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (to_string)
     return PyString_FromString (to_string_res.c_str ());
@@ -830,7 +828,7 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
   std::vector<symtab_and_line> decoded_sals;
   symtab_and_line def_sal;
   gdb::array_view<symtab_and_line> sals;
-  TRY
+  try
     {
       if (location != NULL)
 	{
@@ -844,13 +842,12 @@ gdbpy_decode_line (PyObject *self, PyObject *args)
 	  sals = def_sal;
 	}
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       /* We know this will always throw.  */
       gdbpy_convert_exception (ex);
       return NULL;
     }
-  END_CATCH
 
   if (!sals.empty ())
     {
@@ -898,16 +895,15 @@ gdbpy_parse_and_eval (PyObject *self, PyObject *args)
   if (!PyArg_ParseTuple (args, "s", &expr_str))
     return NULL;
 
-  TRY
+  try
     {
       gdbpy_allow_threads allow_threads;
       result = parse_and_eval (expr_str);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return value_to_value_object (result);
 }
@@ -1136,7 +1132,7 @@ gdbpy_write (PyObject *self, PyObject *args, PyObject *kw)
 					&stream_type))
     return NULL;
 
-  TRY
+  try
     {
       switch (stream_type)
         {
@@ -1154,11 +1150,10 @@ gdbpy_write (PyObject *self, PyObject *args, PyObject *kw)
           fprintf_filtered (gdb_stdout, "%s", arg);
         }
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   Py_RETURN_NONE;
 }
@@ -1224,14 +1219,13 @@ gdbpy_print_stack (void)
       /* PyErr_Print doesn't necessarily end output with a newline.
 	 This works because Python's stdout/stderr is fed through
 	 printf_filtered.  */
-      TRY
+      try
 	{
 	  begin_line ();
 	}
-      CATCH (except, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
 	{
 	}
-      END_CATCH
     }
   /* Print "message", just error print message.  */
   else
@@ -1245,7 +1239,7 @@ gdbpy_print_stack (void)
       if (msg != NULL)
 	type = fetched_error.type_to_string ();
 
-      TRY
+      try
 	{
 	  if (msg == NULL || type == NULL)
 	    {
@@ -1260,10 +1254,9 @@ gdbpy_print_stack (void)
 	    fprintf_filtered (gdb_stderr, "Python Exception %s %s: \n",
 			      type.get (), msg.get ());
 	}
-      CATCH (except, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &except)
 	{
 	}
-      END_CATCH
     }
 }
 
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index da2d246f723..8fa1b58feaf 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -282,15 +282,14 @@ require_btrace (void)
 static void
 record_btrace_enable_warn (struct thread_info *tp)
 {
-  TRY
+  try
     {
       btrace_enable (tp, &record_btrace_conf);
     }
-  CATCH (error, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &error)
     {
       warning ("%s", error.message.c_str ());
     }
-  END_CATCH
 }
 
 /* Enable automatic tracing of new threads.  */
@@ -1478,16 +1477,15 @@ record_btrace_target::insert_breakpoint (struct gdbarch *gdbarch,
   replay_memory_access = replay_memory_access_read_write;
 
   ret = 0;
-  TRY
+  try
     {
       ret = this->beneath ()->insert_breakpoint (gdbarch, bp_tgt);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       replay_memory_access = old;
       throw_exception (except);
     }
-  END_CATCH
   replay_memory_access = old;
 
   return ret;
@@ -1509,16 +1507,15 @@ record_btrace_target::remove_breakpoint (struct gdbarch *gdbarch,
   replay_memory_access = replay_memory_access_read_write;
 
   ret = 0;
-  TRY
+  try
     {
       ret = this->beneath ()->remove_breakpoint (gdbarch, bp_tgt, reason);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       replay_memory_access = old;
       throw_exception (except);
     }
-  END_CATCH
   replay_memory_access = old;
 
   return ret;
@@ -1986,18 +1983,17 @@ get_thread_current_frame_id (struct thread_info *tp)
   set_executing (inferior_ptid, false);
 
   id = null_frame_id;
-  TRY
+  try
     {
       id = get_frame_id (get_current_frame ());
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       /* Restore the previous execution state.  */
       set_executing (inferior_ptid, executing);
 
       throw_exception (except);
     }
-  END_CATCH
 
   /* Restore the previous execution state.  */
   set_executing (inferior_ptid, executing);
@@ -2025,7 +2021,7 @@ record_btrace_start_replaying (struct thread_info *tp)
      Since frames are computed differently when we're replaying, we need to
      recompute those stored frames and fix them up so we can still detect
      subroutines after we started replaying.  */
-  TRY
+  try
     {
       struct frame_id frame_id;
       int upd_step_frame_id, upd_step_stack_frame_id;
@@ -2070,7 +2066,7 @@ record_btrace_start_replaying (struct thread_info *tp)
       if (upd_step_stack_frame_id)
 	tp->control.step_stack_frame_id = frame_id;
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
       xfree (btinfo->replay);
       btinfo->replay = NULL;
@@ -2079,7 +2075,6 @@ record_btrace_start_replaying (struct thread_info *tp)
 
       throw_exception (except);
     }
-  END_CATCH
 
   return replay;
 }
@@ -2892,16 +2887,15 @@ cmd_record_btrace_bts_start (const char *args, int from_tty)
 
   record_btrace_conf.format = BTRACE_FORMAT_BTS;
 
-  TRY
+  try
     {
       execute_command ("target record-btrace", from_tty);
     }
-  CATCH (exception, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
     {
       record_btrace_conf.format = BTRACE_FORMAT_NONE;
       throw_exception (exception);
     }
-  END_CATCH
 }
 
 /* Start recording in Intel Processor Trace format.  */
@@ -2914,16 +2908,15 @@ cmd_record_btrace_pt_start (const char *args, int from_tty)
 
   record_btrace_conf.format = BTRACE_FORMAT_PT;
 
-  TRY
+  try
     {
       execute_command ("target record-btrace", from_tty);
     }
-  CATCH (exception, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
     {
       record_btrace_conf.format = BTRACE_FORMAT_NONE;
       throw_exception (exception);
     }
-  END_CATCH
 }
 
 /* Alias for "target record".  */
@@ -2936,26 +2929,24 @@ cmd_record_btrace_start (const char *args, int from_tty)
 
   record_btrace_conf.format = BTRACE_FORMAT_PT;
 
-  TRY
+  try
     {
       execute_command ("target record-btrace", from_tty);
     }
-  CATCH (exception, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
     {
       record_btrace_conf.format = BTRACE_FORMAT_BTS;
 
-      TRY
+      try
 	{
 	  execute_command ("target record-btrace", from_tty);
 	}
-      CATCH (ex, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	{
 	  record_btrace_conf.format = BTRACE_FORMAT_NONE;
 	  throw_exception (ex);
 	}
-      END_CATCH
     }
-  END_CATCH
 }
 
 /* The "set record btrace" command.  */
diff --git a/gdb/record-full.c b/gdb/record-full.c
index ea0eddb536d..c6d63354dd7 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -708,7 +708,7 @@ record_full_message (struct regcache *regcache, enum gdb_signal signal)
   int ret;
   struct gdbarch *gdbarch = regcache->arch ();
 
-  TRY
+  try
     {
       record_full_arch_list_head = NULL;
       record_full_arch_list_tail = NULL;
@@ -761,12 +761,11 @@ record_full_message (struct regcache *regcache, enum gdb_signal signal)
       if (ret < 0)
 	error (_("Process record: failed to record execution log."));
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       record_full_list_release (record_full_arch_list_tail);
       throw_exception (ex);
     }
-  END_CATCH
 
   record_full_list->next = record_full_arch_list_head;
   record_full_arch_list_head->prev = record_full_list;
@@ -782,16 +781,15 @@ static bool
 record_full_message_wrapper_safe (struct regcache *regcache,
 				  enum gdb_signal signal)
 {
-  TRY
+  try
     {
       record_full_message (regcache, signal);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       exception_print (gdb_stderr, ex);
       return false;
     }
-  END_CATCH
 
   return true;
 }
@@ -1293,7 +1291,7 @@ record_full_wait_1 (struct target_ops *ops,
       int continue_flag = 1;
       int first_record_full_end = 1;
 
-      TRY
+      try
 	{
 	  CORE_ADDR tmp_pc;
 
@@ -1436,7 +1434,7 @@ record_full_wait_1 (struct target_ops *ops,
 	  else
 	    status->value.sig = GDB_SIGNAL_TRAP;
 	}
-      CATCH (ex, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	{
 	  if (execution_direction == EXEC_REVERSE)
 	    {
@@ -1448,7 +1446,6 @@ record_full_wait_1 (struct target_ops *ops,
 
 	  throw_exception (ex);
 	}
-      END_CATCH
     }
 
   signal (SIGINT, handle_sigint);
@@ -2374,7 +2371,7 @@ record_full_restore (void)
   record_full_arch_list_tail = NULL;
   record_full_insn_num = 0;
 
-  TRY
+  try
     {
       regcache = get_current_regcache ();
 
@@ -2476,12 +2473,11 @@ record_full_restore (void)
 	  record_full_arch_list_add (rec);
 	}
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       record_full_list_release (record_full_arch_list_tail);
       throw_exception (ex);
     }
-  END_CATCH
 
   /* Add record_full_arch_list_head to the end of record list.  */
   record_full_first.next = record_full_arch_list_head;
diff --git a/gdb/remote-fileio.c b/gdb/remote-fileio.c
index 91caa2b0726..2e2dc157599 100644
--- a/gdb/remote-fileio.c
+++ b/gdb/remote-fileio.c
@@ -1185,18 +1185,17 @@ remote_fileio_request (remote_target *remote, char *buf, int ctrlc_pending_p)
     }
   else
     {
-      TRY
+      try
 	{
 	  do_remote_fileio_request (remote, buf);
 	}
-      CATCH (ex, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	{
 	  if (ex.reason == RETURN_QUIT)
 	    remote_fileio_reply (remote, -1, FILEIO_EINTR);
 	  else
 	    remote_fileio_reply (remote, -1, FILEIO_EIO);
 	}
-      END_CATCH
     }
 
   quit_handler = remote_fileio_o_quit_handler;
diff --git a/gdb/remote.c b/gdb/remote.c
index eb74c23520a..ed4cdd9e22a 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -1146,12 +1146,12 @@ remote_target::remote_get_noisy_reply ()
 
 	  org_to = to;
 
-	  TRY
+	  try
 	    {
 	      gdbarch_relocate_instruction (target_gdbarch (), &to, from);
 	      relocated = 1;
 	    }
-	  CATCH (ex, RETURN_MASK_ALL)
+	  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	    {
 	      if (ex.error == MEMORY_ERROR)
 		{
@@ -1170,7 +1170,6 @@ remote_target::remote_get_noisy_reply ()
 		}
 	      putpkt ("E01");
 	    }
-	  END_CATCH
 
 	  if (relocated)
 	    {
@@ -5600,11 +5599,11 @@ remote_target::open_1 (const char *name, int from_tty, int extended_p)
      function.  See cli-dump.c.  */
   {
 
-    TRY
+    try
       {
 	remote->start_remote (from_tty, extended_p);
       }
-    CATCH (ex, RETURN_MASK_ALL)
+    catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
       {
 	/* Pop the partially set up target - unless something else did
 	   already before throwing the exception.  */
@@ -5612,7 +5611,6 @@ remote_target::open_1 (const char *name, int from_tty, int extended_p)
 	  remote_unpush_target ();
 	throw_exception (ex);
       }
-    END_CATCH
   }
 
   remote_btrace_reset (rs);
@@ -9766,11 +9764,11 @@ remote_target::remote_kill_k ()
 {
   /* Catch errors so the user can quit from gdb even when we
      aren't on speaking terms with the remote system.  */
-  TRY
+  try
     {
       putpkt ("k");
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error == TARGET_CLOSE_ERROR)
 	{
@@ -9788,7 +9786,6 @@ remote_target::remote_kill_k ()
 	 user or higher layers decide what to do.  */
       throw_exception (ex);
     }
-  END_CATCH
 }
 
 void
@@ -13142,11 +13139,11 @@ remote_target::get_trace_status (struct trace_status *ts)
 
   putpkt ("qTStatus");
 
-  TRY
+  try
     {
       p = remote_get_noisy_reply ();
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error != TARGET_CLOSE_ERROR)
 	{
@@ -13155,7 +13152,6 @@ remote_target::get_trace_status (struct trace_status *ts)
 	}
       throw_exception (ex);
     }
-  END_CATCH
 
   result = packet_ok (p, &remote_protocol_packets[PACKET_qTStatus]);
 
@@ -13797,16 +13793,15 @@ remote_target::enable_btrace (ptid_t ptid, const struct btrace_config *conf)
 
   /* If we fail to read the configuration, we lose some information, but the
      tracing itself is not impacted.  */
-  TRY
+  try
     {
       btrace_read_config (&tinfo->conf);
     }
-  CATCH (err, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &err)
     {
       if (!err.message.empty ())
 	warning ("%s", err.message.c_str ());
     }
-  END_CATCH
 
   return tinfo;
 }
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index d93e52c412b..e23e0814201 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -651,19 +651,18 @@ riscv_print_one_register_info (struct gdbarch *gdbarch,
   fputs_filtered (name, file);
   print_spaces_filtered (value_column_1 - strlen (name), file);
 
-  TRY
+  try
     {
       val = value_of_register (regnum, frame);
       regtype = value_type (val);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       /* Handle failure to read a register without interrupting the entire
          'info registers' flow.  */
       fprintf_filtered (file, "%s\n", ex.message.c_str ());
       return;
     }
-  END_CATCH
 
   print_raw_format = (value_entirely_available (val)
 		      && !value_optimized_out (val));
@@ -2802,17 +2801,16 @@ riscv_frame_this_id (struct frame_info *this_frame,
 {
   struct riscv_unwind_cache *cache;
 
-  TRY
+  try
     {
       cache = riscv_frame_cache (this_frame, prologue_cache);
       *this_id = cache->this_id;
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       /* Ignore errors, this leaves the frame id as the predefined outer
          frame id which terminates the backtrace at this point.  */
     }
-  END_CATCH
 }
 
 /* Implement the prev_register callback for RiscV frame unwinder.  */
diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c
index 2a5271cd530..05055a4a872 100644
--- a/gdb/rs6000-aix-tdep.c
+++ b/gdb/rs6000-aix-tdep.c
@@ -670,18 +670,17 @@ rs6000_convert_from_func_ptr_addr (struct gdbarch *gdbarch,
       CORE_ADDR pc = 0;
       struct obj_section *pc_section;
 
-      TRY
+      try
         {
           pc = read_memory_unsigned_integer (addr, tdep->wordsize, byte_order);
         }
-      CATCH (e, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
         {
           /* An error occured during reading.  Probably a memory error
              due to the section not being loaded yet.  This address
              cannot be a function descriptor.  */
           return addr;
         }
-      END_CATCH
 
       pc_section = find_pc_section (pc);
 
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index e875ad95366..4213438c841 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -3451,7 +3451,7 @@ rs6000_frame_cache (struct frame_info *this_frame, void **this_cache)
   cache->pc = 0;
   cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
 
-  TRY
+  try
     {
       func = get_frame_func (this_frame);
       cache->pc = func;
@@ -3468,13 +3468,12 @@ rs6000_frame_cache (struct frame_info *this_frame, void **this_cache)
       cache->base = get_frame_register_unsigned
 	(this_frame, gdbarch_sp_regnum (gdbarch));
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
       return (struct rs6000_frame_cache *) (*this_cache);
     }
-  END_CATCH
 
   /* If the function appears to be frameless, check a couple of likely
      indicators that we have simply failed to find the frame setup.
@@ -3683,7 +3682,7 @@ rs6000_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
   (*this_cache) = cache;
   cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
 
-  TRY
+  try
     {
       /* At this point the stack looks as if we just entered the
 	 function, and the return address is stored in LR.  */
@@ -3698,12 +3697,11 @@ rs6000_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
       trad_frame_set_value (cache->saved_regs,
 			    gdbarch_pc_regnum (gdbarch), lr);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
     }
-  END_CATCH
 
   return cache;
 }
diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
index 51a6fdd5b10..97c1b5edd2d 100644
--- a/gdb/rust-exp.y
+++ b/gdb/rust-exp.y
@@ -2596,17 +2596,16 @@ static void
 rust_lex_exception_test (rust_parser *parser, const char *input,
 			 const char *err)
 {
-  TRY
+  try
     {
       /* The "kind" doesn't matter.  */
       rust_lex_test_one (parser, input, DECIMAL_INTEGER);
       SELF_CHECK (0);
     }
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       SELF_CHECK (except.message == err);
     }
-  END_CATCH
 }
 
 /* Test that INPUT lexes as the identifier, string, or byte-string
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 1cd92ff47a8..228684a6cc5 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1743,18 +1743,17 @@ tuple structs, and tuple-like enum variants"));
 		       field_name, TYPE_NAME (outer_type),
 		       rust_last_path_segment (TYPE_NAME (type)));
 
-	    TRY
+	    try
 	      {
 		result = value_struct_elt (&lhs, NULL, field_name,
 					   NULL, "structure");
 	      }
-	    CATCH (except, RETURN_MASK_ERROR)
+	    catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	      {
 		error (_("Could not find field %s of struct variant %s::%s"),
 		       field_name, TYPE_NAME (outer_type),
 		       rust_last_path_segment (TYPE_NAME (type)));
 	      }
-	    END_CATCH
 	  }
 	else
 	  result = value_struct_elt (&lhs, NULL, field_name, NULL, "structure");
diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
index 90aba995036..09946a9e531 100644
--- a/gdb/s390-tdep.c
+++ b/gdb/s390-tdep.c
@@ -2547,19 +2547,18 @@ s390_frame_unwind_cache (struct frame_info *this_frame,
   info->frame_base = -1;
   info->local_base = -1;
 
-  TRY
+  try
     {
       /* Try to use prologue analysis to fill the unwind cache.
 	 If this fails, fall back to reading the stack backchain.  */
       if (!s390_prologue_frame_unwind_cache (this_frame, info))
 	s390_backchain_frame_unwind_cache (this_frame, info);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error != NOT_AVAILABLE_ERROR)
 	throw_exception (ex);
     }
-  END_CATCH
 
   return info;
 }
diff --git a/gdb/selftest-arch.c b/gdb/selftest-arch.c
index 7a64295efa8..063ff8d74fa 100644
--- a/gdb/selftest-arch.c
+++ b/gdb/selftest-arch.c
@@ -60,7 +60,7 @@ struct gdbarch_selftest : public selftest
 
 	QUIT;
 
-	TRY
+	try
 	  {
 	    struct gdbarch_info info;
 
@@ -72,13 +72,12 @@ struct gdbarch_selftest : public selftest
 
 	    function (gdbarch);
 	  }
-	CATCH (ex, RETURN_MASK_ERROR)
+	catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 	  {
 	    pass = false;
 	    exception_fprintf (gdb_stderr, ex,
 			       _("Self test failed: arch %s: "), arches[i]);
 	  }
-	END_CATCH
 
 	reset ();
       }
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 20310144f32..9b7f3ecb382 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -830,14 +830,13 @@ enable_break (void)
 	 in the dynamic linker itself.  */
 
       gdb_bfd_ref_ptr tmp_bfd;
-      TRY
+      try
 	{
 	  tmp_bfd = solib_bfd_open (buf);
 	}
-      CATCH (ex, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	{
 	}
-      END_CATCH
 
       if (tmp_bfd == NULL)
 	{
diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
index 1b330b8f97f..70a9f5fdba6 100644
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -561,14 +561,13 @@ enable_break2 (void)
          mechanism to find the dynamic linker's base address.  */
 
       gdb_bfd_ref_ptr tmp_bfd;
-      TRY
+      try
         {
           tmp_bfd = solib_bfd_open (buf);
         }
-      CATCH (ex, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	{
 	}
-      END_CATCH
 
       if (tmp_bfd == NULL)
 	{
diff --git a/gdb/solib-spu.c b/gdb/solib-spu.c
index 4f5e8e0c75b..a36f84b5a72 100644
--- a/gdb/solib-spu.c
+++ b/gdb/solib-spu.c
@@ -110,7 +110,7 @@ append_ocl_sos (struct so_list **link_ptr)
         {
 	  enum bfd_endian byte_order = bfd_big_endian (objfile->obfd)?
 					 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
-	  TRY
+	  try
 	    {
 	      CORE_ADDR data =
 		read_memory_unsigned_integer (*ocl_program_addr_base,
@@ -133,7 +133,7 @@ append_ocl_sos (struct so_list **link_ptr)
 		  link_ptr = &newobj->next;
 		}
 	    }
-	  CATCH (ex, RETURN_MASK_ALL)
+	  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	    {
 	      /* Ignore memory errors.  */
 	      switch (ex.error)
@@ -145,7 +145,6 @@ append_ocl_sos (struct so_list **link_ptr)
 		  break;
 		}
 	    }
-	  END_CATCH
 	}
     }
 }
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 2301cf94c2f..e25618d1f26 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -869,16 +869,15 @@ solib_svr4_r_map (struct svr4_info *info)
   struct type *ptr_type = builtin_type (target_gdbarch ())->builtin_data_ptr;
   CORE_ADDR addr = 0;
 
-  TRY
+  try
     {
       addr = read_memory_typed_address (info->debug_base + lmo->r_map_offset,
                                         ptr_type);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       exception_print (gdb_stderr, ex);
     }
-  END_CATCH
 
   return addr;
 }
@@ -906,7 +905,7 @@ solib_svr4_r_ldsomap (struct svr4_info *info)
   enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
   ULONGEST version = 0;
 
-  TRY
+  try
     {
       /* Check version, and return zero if `struct r_debug' doesn't have
 	 the r_ldsomap member.  */
@@ -914,11 +913,10 @@ solib_svr4_r_ldsomap (struct svr4_info *info)
 	= read_memory_unsigned_integer (info->debug_base + lmo->r_version_offset,
 					lmo->r_version_size, byte_order);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       exception_print (gdb_stderr, ex);
     }
-  END_CATCH
 
   if (version < 2 || lmo->r_ldsomap_offset == -1)
     return 0;
@@ -1727,16 +1725,15 @@ solib_event_probe_action (struct probe_and_action *pa)
        arg0: Lmid_t lmid (mandatory)
        arg1: struct r_debug *debug_base (mandatory)
        arg2: struct link_map *new (optional, for incremental updates)  */
-  TRY
+  try
     {
       probe_argc = pa->prob->get_argument_count (frame);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       exception_print (gdb_stderr, ex);
       probe_argc = 0;
     }
-  END_CATCH
 
   /* If get_argument_count throws an exception, probe_argc will be set
      to zero.  However, if pa->prob does not have arguments, then
@@ -1891,16 +1888,15 @@ svr4_handle_solib_event (void)
     scoped_restore inhibit_updates
       = inhibit_section_map_updates (current_program_space);
 
-    TRY
+    try
       {
 	val = pa->prob->evaluate_argument (1, frame);
       }
-    CATCH (ex, RETURN_MASK_ERROR)
+    catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
       {
 	exception_print (gdb_stderr, ex);
 	val = NULL;
       }
-    END_CATCH
 
     if (val == NULL)
       return;
@@ -1923,16 +1919,15 @@ svr4_handle_solib_event (void)
 
     if (action == UPDATE_OR_RELOAD)
       {
-	TRY
+	try
 	  {
 	    val = pa->prob->evaluate_argument (2, frame);
 	  }
-	CATCH (ex, RETURN_MASK_ERROR)
+	catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 	  {
 	    exception_print (gdb_stderr, ex);
 	    return;
 	  }
-	END_CATCH
 
 	if (val != NULL)
 	  lm = value_as_address (val);
@@ -2274,14 +2269,13 @@ enable_break (struct svr4_info *info, int from_tty)
          mechanism to find the dynamic linker's base address.  */
 
       gdb_bfd_ref_ptr tmp_bfd;
-      TRY
+      try
         {
 	  tmp_bfd = solib_bfd_open (interp_name);
 	}
-      CATCH (ex, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	{
 	}
-      END_CATCH
 
       if (tmp_bfd == NULL)
 	goto bkpt_at_symbol;
diff --git a/gdb/solib.c b/gdb/solib.c
index 791b94bc93a..37c218e18eb 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -674,7 +674,7 @@ solib_read_symbols (struct so_list *so, symfile_add_flags flags)
 
       flags |= current_inferior ()->symfile_flags;
 
-      TRY
+      try
 	{
 	  /* Have we already loaded this shared object?  */
 	  so->objfile = nullptr;
@@ -700,13 +700,12 @@ solib_read_symbols (struct so_list *so, symfile_add_flags flags)
 
 	  so->symbols_loaded = 1;
 	}
-      CATCH (e, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
 	{
 	  exception_fprintf (gdb_stderr, e, _("Error while reading shared"
 					      " library symbols for %s:\n"),
 			     so->so_name);
 	}
-      END_CATCH
 
       return 1;
     }
@@ -748,17 +747,16 @@ update_solib_list (int from_tty)
 	 symbols now!  */
       if (inf->attach_flag && symfile_objfile == NULL)
 	{
-	  TRY
+	  try
 	    {
 	      ops->open_symbol_file_object (from_tty);
 	    }
-	  CATCH (ex, RETURN_MASK_ALL)
+	  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	    {
 	      exception_fprintf (gdb_stderr, ex,
 				 "Error reading attached "
 				 "process's symbol file.\n");
 	    }
-	  END_CATCH
 	}
     }
 
@@ -868,7 +866,7 @@ update_solib_list (int from_tty)
 	  i->pspace = current_program_space;
 	  current_program_space->added_solibs.push_back (i);
 
-	  TRY
+	  try
 	    {
 	      /* Fill in the rest of the `struct so_list' node.  */
 	      if (!solib_map_sections (i))
@@ -879,13 +877,12 @@ update_solib_list (int from_tty)
 		}
 	    }
 
-	  CATCH (e, RETURN_MASK_ERROR)
+	  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
 	    {
 	      exception_fprintf (gdb_stderr, e,
 				 _("Error while mapping shared "
 				   "library sections:\n"));
 	    }
-	  END_CATCH
 
 	  /* Notify any observer that the shared object has been
 	     loaded now that we've added it to GDB's tables.  */
@@ -1333,19 +1330,18 @@ reload_shared_libraries_1 (int from_tty)
 	{
 	  int got_error = 0;
 
-	  TRY
+	  try
 	    {
 	      solib_map_sections (so);
 	    }
 
-	  CATCH (e, RETURN_MASK_ERROR)
+	  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
 	    {
 	      exception_fprintf (gdb_stderr, e,
 				 _("Error while mapping "
 				   "shared library sections:\n"));
 	      got_error = 1;
 	    }
-	  END_CATCH
 
 	    if (!got_error
 		&& (auto_solib_add || was_loaded || libpthread_solib_p (so)))
diff --git a/gdb/sparc64-linux-tdep.c b/gdb/sparc64-linux-tdep.c
index 33170f23675..551a26d816b 100644
--- a/gdb/sparc64-linux-tdep.c
+++ b/gdb/sparc64-linux-tdep.c
@@ -130,7 +130,7 @@ sparc64_linux_handle_segmentation_fault (struct gdbarch *gdbarch,
   CORE_ADDR addr = 0;
   long si_code = 0;
 
-  TRY
+  try
     {
       /* Evaluate si_code to see if the segfault is ADI related.  */
       si_code = parse_and_eval_long ("$_siginfo.si_code\n");
@@ -138,11 +138,10 @@ sparc64_linux_handle_segmentation_fault (struct gdbarch *gdbarch,
       if (si_code >= SEGV_ACCADI && si_code <= SEGV_ADIPERR)
         addr = parse_and_eval_long ("$_siginfo._sifields._sigfault.si_addr");
     }
-  CATCH (exception, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &exception)
     {
       return;
     }
-  END_CATCH
 
   /* Print out ADI event based on sig_code value */
   switch (si_code)
diff --git a/gdb/stack.c b/gdb/stack.c
index bce46392909..056ce716810 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -175,17 +175,16 @@ print_stack_frame (struct frame_info *frame, int print_level,
   if (current_uiout->is_mi_like_p ())
     print_what = LOC_AND_ADDRESS;
 
-  TRY
+  try
     {
       print_frame_info (frame, print_level, print_what, 1 /* print_args */,
 			set_current_sal);
       if (set_current_sal)
 	set_current_sal_from_frame (frame);
     }
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
     {
     }
-  END_CATCH
 }
 
 /* Print nameless arguments of frame FRAME on STREAM, where START is
@@ -268,7 +267,7 @@ print_frame_arg (const struct frame_arg *arg)
 	error_message = arg->error;
       else
 	{
-	  TRY
+	  try
 	    {
 	      const struct language_defn *language;
 	      struct value_print_options opts;
@@ -297,11 +296,10 @@ print_frame_arg (const struct frame_arg *arg)
 
 	      common_val_print (arg->val, &stb, 2, &opts, language);
 	    }
-	  CATCH (except, RETURN_MASK_ERROR)
+	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	    {
 	      error_message = std::move (except.message);
 	    }
-	  END_CATCH
 	}
       if (!error_message.empty ())
 	stb.printf (_("<error reading variable: %s>"), error_message.c_str ());
@@ -322,15 +320,14 @@ read_frame_local (struct symbol *sym, struct frame_info *frame,
   argp->val = NULL;
   argp->error = NULL;
 
-  TRY
+  try
     {
       argp->val = read_var_value (sym, NULL, frame);
     }
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       argp->error = xstrdup (except.message.c_str ());
     }
-  END_CATCH
 }
 
 /* Read in inferior function parameter SYM at FRAME into ARGP.  Caller is
@@ -348,16 +345,15 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame,
   if (print_entry_values != print_entry_values_only
       && print_entry_values != print_entry_values_preferred)
     {
-      TRY
+      try
 	{
 	  val = read_var_value (sym, NULL, frame);
 	}
-      CATCH (except, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	{
 	  val_error = (char *) alloca (except.message.size () + 1);
 	  strcpy (val_error, except.message.c_str ());
 	}
-      END_CATCH
     }
 
   if (SYMBOL_COMPUTED_OPS (sym) != NULL
@@ -366,14 +362,14 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame,
       && (print_entry_values != print_entry_values_if_needed
 	  || !val || value_optimized_out (val)))
     {
-      TRY
+      try
 	{
 	  const struct symbol_computed_ops *ops;
 
 	  ops = SYMBOL_COMPUTED_OPS (sym);
 	  entryval = ops->read_variable_at_entry (sym, frame);
 	}
-      CATCH (except, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	{
 	  if (except.error != NO_ENTRY_VALUE_ERROR)
 	    {
@@ -381,7 +377,6 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame,
 	      strcpy (entryval_error, except.message.c_str ());
 	    }
 	}
-      END_CATCH
 
       if (entryval != NULL && value_optimized_out (entryval))
 	entryval = NULL;
@@ -409,7 +404,7 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame,
 		     value.  If it is a reference still try to verify if
 		     dereferenced DW_AT_call_data_value does not differ.  */
 
-		  TRY
+		  try
 		    {
 		      struct type *type_deref;
 
@@ -430,7 +425,7 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame,
 						TYPE_LENGTH (type_deref)))
 			val_equal = 1;
 		    }
-		  CATCH (except, RETURN_MASK_ERROR)
+		  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 		    {
 		      /* If the dereferenced content could not be
 			 fetched do not display anything.  */
@@ -443,7 +438,6 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame,
 			  strcpy (entryval_error, except.message.c_str ());
 			}
 		    }
-		  END_CATCH
 
 		  /* Value was not a reference; and its content matches.  */
 		  if (val == val_deref)
@@ -475,16 +469,15 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame,
 	{
 	  gdb_assert (val == NULL);
 
-	  TRY
+	  try
 	    {
 	      val = read_var_value (sym, NULL, frame);
 	    }
-	  CATCH (except, RETURN_MASK_ERROR)
+	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	    {
 	      val_error = (char *) alloca (except.message.size () + 1);
 	      strcpy (val_error, except.message.c_str ());
 	    }
-	  END_CATCH
 	}
       if (print_entry_values == print_entry_values_only
 	  || print_entry_values == print_entry_values_both
@@ -761,19 +754,18 @@ do_gdb_disassembly (struct gdbarch *gdbarch,
 		    int how_many, CORE_ADDR low, CORE_ADDR high)
 {
 
-  TRY
+  try
     {
       gdb_disassembly (gdbarch, current_uiout,
 		       DISASSEMBLY_RAW_INSN, how_many,
 		       low, high);
     }
-  CATCH (exception, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &exception)
     {
       /* If an exception was thrown while doing the disassembly, print
 	 the error message, to give the user a clue of what happened.  */
       exception_print (gdb_stderr, exception);
     }
-  END_CATCH
 }
 
 /* Print information about frame FRAME.  The output is format according
@@ -1206,14 +1198,13 @@ print_frame (struct frame_info *frame, int print_level,
     
 	{
 	  ui_out_emit_list list_emitter (uiout, "args");
-	  TRY
+	  try
 	    {
 	      print_frame_args (func, frame, numargs, gdb_stdout);
 	    }
-	  CATCH (e, RETURN_MASK_ERROR)
+	  catch (const struct gdb_exception_RETURN_MASK_ERROR &e)
 	    {
 	    }
-	  END_CATCH
 
 	    /* FIXME: ARGS must be a list.  If one argument is a string it
 	       will have " that will not be properly escaped.  */
@@ -1395,12 +1386,12 @@ info_frame_command_core (struct frame_info *fi, bool selected_frame_p)
     val_print_not_saved (gdb_stdout);
   else
     {
-      TRY
+      try
 	{
 	  caller_pc = frame_unwind_caller_pc (fi);
 	  caller_pc_p = 1;
 	}
-      CATCH (ex, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 	{
 	  switch (ex.error)
 	    {
@@ -1416,7 +1407,6 @@ info_frame_command_core (struct frame_info *fi, bool selected_frame_p)
 	      break;
 	    }
 	}
-      END_CATCH
     }
 
   if (caller_pc_p)
@@ -2696,7 +2686,7 @@ frame_apply_command_count (const char *which_command,
       QUIT;
 
       select_frame (fi);
-      TRY
+      try
 	{
 	  std::string cmd_result;
 	  {
@@ -2716,7 +2706,7 @@ frame_apply_command_count (const char *which_command,
 	      printf_filtered ("%s", cmd_result.c_str ());
 	    }
 	}
-      CATCH (ex, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 	{
 	  fi = get_selected_frame (_("frame apply "
 				     "unable to get selected frame."));
@@ -2730,7 +2720,6 @@ frame_apply_command_count (const char *which_command,
 		throw_exception (ex);
 	    }
 	}
-      END_CATCH;
     }
 }
 
diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c
index 1029c012438..5287e280a91 100644
--- a/gdb/symfile-mem.c
+++ b/gdb/symfile-mem.c
@@ -187,7 +187,7 @@ add_vsyscall_page (struct target_ops *target, int from_tty)
 
       char *name = xstrprintf ("system-supplied DSO at %s",
 			       paddress (target_gdbarch (), vsyscall_range.start));
-      TRY
+      try
 	{
 	  /* Pass zero for FROM_TTY, because the action of loading the
 	     vsyscall DSO was not triggered by the user, even if the
@@ -198,11 +198,10 @@ add_vsyscall_page (struct target_ops *target, int from_tty)
 				       name,
 				       0 /* from_tty */);
 	}
-      CATCH (ex, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	{
 	  exception_print (gdb_stderr, ex);
 	}
-      END_CATCH
     }
 }
 
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index bb4fdfd1ed9..2efa447733d 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -352,16 +352,15 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
 	     block, not any blocks from included symtabs.  */
 	  ALL_DICT_SYMBOLS (BLOCK_MULTIDICT (b), miter, sym)
 	    {
-	      TRY
+	      try
 		{
 		  print_symbol (gdbarch, sym, depth + 1, outfile);
 		}
-	      CATCH (ex, RETURN_MASK_ERROR)
+	      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 		{
 		  exception_fprintf (gdb_stderr, ex,
 				     "Error printing symbol:\n");
 		}
-	      END_CATCH
 	    }
 	}
       fprintf_filtered (outfile, "\n");
diff --git a/gdb/target.c b/gdb/target.c
index b27ecb49e0e..ccad0031458 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -705,7 +705,7 @@ target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset)
     {
       ptid_t ptid = inferior_ptid;
 
-      TRY
+      try
 	{
 	  CORE_ADDR lm_addr;
 	  
@@ -717,7 +717,7 @@ target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset)
 	}
       /* If an error occurred, print TLS related messages here.  Otherwise,
          throw the error to some higher catcher.  */
-      CATCH (ex, RETURN_MASK_ALL)
+      catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
 	{
 	  int objfile_is_library = (objfile->flags & OBJF_SHARED);
 
@@ -766,7 +766,6 @@ target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset)
 	      break;
 	    }
 	}
-      END_CATCH
     }
   /* It wouldn't be wrong here to try a gdbarch method, too; finding
      TLS is an ABI-specific thing.  But we don't do that yet.  */
diff --git a/gdb/thread.c b/gdb/thread.c
index 5ec898838f0..c1928c25402 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -1458,7 +1458,7 @@ thr_try_catch_cmd (thread_info *thr, const char *cmd, int from_tty,
 		   const qcs_flags &flags)
 {
   switch_to_thread (thr);
-  TRY
+  try
     {
       std::string cmd_result = execute_command_to_string (cmd, from_tty);
       if (!flags.silent || cmd_result.length () > 0)
@@ -1470,7 +1470,7 @@ thr_try_catch_cmd (thread_info *thr, const char *cmd, int from_tty,
 	  printf_filtered ("%s", cmd_result.c_str ());
 	}
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (!flags.silent)
 	{
@@ -1484,7 +1484,6 @@ thr_try_catch_cmd (thread_info *thr, const char *cmd, int from_tty,
 	    throw_exception (ex);
 	}
     }
-  END_CATCH;
 }
 
 /* Apply a GDB command to a list of threads.  List syntax is a whitespace
diff --git a/gdb/top.c b/gdb/top.c
index 4065df70815..285927f5712 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1620,31 +1620,29 @@ quit_force (int *exit_arg, int from_tty)
   /* We want to handle any quit errors and exit regardless.  */
 
   /* Get out of tfind mode, and kill or detach all inferiors.  */
-  TRY
+  try
     {
       disconnect_tracing ();
       iterate_over_inferiors (kill_or_detach, &qt);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       exception_print (gdb_stderr, ex);
     }
-  END_CATCH
 
   /* Give all pushed targets a chance to do minimal cleanup, and pop
      them all out.  */
-  TRY
+  try
     {
       pop_all_targets ();
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       exception_print (gdb_stderr, ex);
     }
-  END_CATCH
 
   /* Save the history information if it is appropriate to do so.  */
-  TRY
+  try
     {
       if (write_history_p && history_filename)
 	{
@@ -1666,22 +1664,20 @@ quit_force (int *exit_arg, int from_tty)
 	    gdb_safe_append_history ();
 	}
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       exception_print (gdb_stderr, ex);
     }
-  END_CATCH
 
   /* Do any final cleanups before exiting.  */
-  TRY
+  try
     {
       do_final_cleanups ();
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       exception_print (gdb_stderr, ex);
     }
-  END_CATCH
 
   exit (exit_code);
 }
diff --git a/gdb/tracefile-tfile.c b/gdb/tracefile-tfile.c
index 020a6be69b5..53e85fc13f5 100644
--- a/gdb/tracefile-tfile.c
+++ b/gdb/tracefile-tfile.c
@@ -511,7 +511,7 @@ tfile_target_open (const char *arg, int from_tty)
   ts->disconnected_tracing = 0;
   ts->circular_buffer = 0;
 
-  TRY
+  try
     {
       /* Read through a section of newline-terminated lines that
 	 define things like tracepoints.  */
@@ -547,13 +547,12 @@ tfile_target_open (const char *arg, int from_tty)
       if (trace_regblock_size == 0)
 	error (_("No register block size recorded in trace file"));
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       /* Remove the partially set up target.  */
       unpush_target (&tfile_ops);
       throw_exception (ex);
     }
-  END_CATCH
 
   inferior_appeared (current_inferior (), TFILE_PID);
   inferior_ptid = ptid_t (TFILE_PID);
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index b99e8a0e107..52f6bc39c44 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -96,7 +96,7 @@ tui_rl_switch_mode (int notused1, int notused2)
 
   /* Don't let exceptions escape.  We're in the middle of a readline
      callback that isn't prepared for that.  */
-  TRY
+  try
     {
       if (tui_active)
 	{
@@ -110,14 +110,13 @@ tui_rl_switch_mode (int notused1, int notused2)
 	  tui_enable ();
 	}
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       exception_print (gdb_stderr, ex);
 
       if (!tui_active)
 	rl_prep_terminal (0);
     }
-  END_CATCH
 
   /* Clear the readline in case switching occurred in middle of
      something.  */
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index 6c499b6467e..42d344ea8f6 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -412,17 +412,16 @@ type_print (struct type *type, const char *varstring, struct ui_file *stream,
 std::string
 type_to_string (struct type *type)
 {
-  TRY
+  try
     {
       string_file stb;
 
       type_print (type, "", &stb, -1);
       return std::move (stb.string ());
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &except)
     {
     }
-  END_CATCH
 
   return {};
 }
diff --git a/gdb/unittests/cli-utils-selftests.c b/gdb/unittests/cli-utils-selftests.c
index 1aaa6e2b00d..7c1d135ecc8 100644
--- a/gdb/unittests/cli-utils-selftests.c
+++ b/gdb/unittests/cli-utils-selftests.c
@@ -78,19 +78,18 @@ test_number_or_range_parser ()
     number_or_range_parser minus_one ("-1");
 
     SELF_CHECK (!minus_one.finished ());
-    TRY
+    try
       {
 	minus_one.get_number ();
 	SELF_CHECK (false);
       }
-    CATCH (ex, RETURN_MASK_ERROR)
+    catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
       {
 	SELF_CHECK (ex.reason == RETURN_ERROR);
 	SELF_CHECK (ex.error == GENERIC_ERROR);
 	SELF_CHECK (ex.message == "negative value");
 	SELF_CHECK (strcmp (minus_one.cur_tok (), "-1") == 0);
       }
-    END_CATCH;
   }
 
   /* Test that a - followed by not a number does not give an error.  */
@@ -209,7 +208,7 @@ test_parse_flags_qcs ()
     const char *t4 = "-c -s non flags args";
     qcs_flags flags;
 
-    TRY
+    try
       {
 	SELF_CHECK (parse_flags_qcs ("test_parse_flags_qcs.t4.cs",
 				     &t4,
@@ -220,7 +219,7 @@ test_parse_flags_qcs ()
 				&flags);
 	SELF_CHECK (false);
       }
-    CATCH (ex, RETURN_MASK_ERROR)
+    catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
       {
 	SELF_CHECK (ex.reason == RETURN_ERROR);
 	SELF_CHECK (ex.error == GENERIC_ERROR);
@@ -229,7 +228,6 @@ test_parse_flags_qcs ()
 	   == "test_parse_flags_qcs.t4.cs: "
 	   "-c and -s are mutually exclusive");
       }
-    END_CATCH;
   }
 
 }
diff --git a/gdb/unittests/parse-connection-spec-selftests.c b/gdb/unittests/parse-connection-spec-selftests.c
index ac7cd41e212..7376a53d427 100644
--- a/gdb/unittests/parse-connection-spec-selftests.c
+++ b/gdb/unittests/parse-connection-spec-selftests.c
@@ -209,18 +209,17 @@ test_conn (const parse_conn_test &c)
 
   memset (&hint, 0, sizeof (hint));
 
-  TRY
+  try
     {
       ret = parse_connection_spec (c.connspec, &hint);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       /* If we caught an error, we should check if this connection
 	 spec was supposed to fail.  */
       SELF_CHECK (c.should_fail);
       return;
     }
-  END_CATCH
 
   SELF_CHECK (!c.should_fail);
   SELF_CHECK (ret.host_str == c.expected_result.host_str);
diff --git a/gdb/valops.c b/gdb/valops.c
index 3d1f39f8c95..117b080c70c 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -3621,11 +3621,11 @@ value_rtti_indirect_type (struct value *v, int *full,
   else if (TYPE_CODE (type) == TYPE_CODE_PTR)
     {
 
-      TRY
+      try
         {
 	  target = value_ind (v);
         }
-      CATCH (except, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	{
 	  if (except.error == MEMORY_ERROR)
 	    {
@@ -3636,7 +3636,6 @@ value_rtti_indirect_type (struct value *v, int *full,
 	    }
 	  throw_exception (except);
 	}
-      END_CATCH
     }
   else
     return NULL;
@@ -3774,14 +3773,13 @@ value_of_this_silent (const struct language_defn *lang)
 {
   struct value *ret = NULL;
 
-  TRY
+  try
     {
       ret = value_of_this (lang);
     }
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
     }
-  END_CATCH
 
   return ret;
 }
diff --git a/gdb/valprint.c b/gdb/valprint.c
index a079c0025a7..e4e8fbb857b 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -1056,17 +1056,16 @@ val_print (struct type *type, LONGEST embedded_offset,
       return;
     }
 
-  TRY
+  try
     {
       language->la_val_print (type, embedded_offset, address,
 			      stream, recurse, val,
 			      &local_opts);
     }
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       fprintf_filtered (stream, _("<error reading variable>"));
     }
-  END_CATCH
 }
 
 /* Check whether the value VAL is printable.  Return 1 if it is;
diff --git a/gdb/value.c b/gdb/value.c
index 9bbffbd9a9c..f9e3d65f19d 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1405,15 +1405,14 @@ value_optimized_out (struct value *value)
      fetch it.  */
   if (value->optimized_out.empty () && value->lazy)
     {
-      TRY
+      try
 	{
 	  value_fetch_lazy (value);
 	}
-      CATCH (ex, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 	{
 	  /* Fall back to checking value->optimized_out.  */
 	}
-      END_CATCH
     }
 
   return !value->optimized_out.empty ();
@@ -2535,18 +2534,17 @@ show_convenience (const char *ignore, int from_tty)
 	}
       printf_filtered (("$%s = "), var->name);
 
-      TRY
+      try
 	{
 	  struct value *val;
 
 	  val = value_of_internalvar (gdbarch, var);
 	  value_print (val, gdb_stdout, &opts);
 	}
-      CATCH (ex, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &ex)
 	{
 	  fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message.c_str ());
 	}
-      END_CATCH
 
       printf_filtered (("\n"));
     }
diff --git a/gdb/varobj.c b/gdb/varobj.c
index b03307068f3..4dfc816d835 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -313,16 +313,15 @@ varobj_create (const char *objname,
 			     | INNERMOST_BLOCK_FOR_REGISTERS);
       /* Wrap the call to parse expression, so we can 
          return a sensible error.  */
-      TRY
+      try
 	{
 	  var->root->exp = parse_exp_1 (&p, pc, block, 0);
 	}
 
-      CATCH (except, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	{
 	  return NULL;
 	}
-      END_CATCH
 
       /* Don't allow variables to be created for types.  */
       if (var->root->exp->elts[0].opcode == OP_TYPE
@@ -363,11 +362,11 @@ varobj_create (const char *objname,
       /* We definitely need to catch errors here.
          If evaluate_expression succeeds we got the value we wanted.
          But if it fails, we still go on with a call to evaluate_type().  */
-      TRY
+      try
 	{
 	  value = evaluate_expression (var->root->exp.get ());
 	}
-      CATCH (except, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	{
 	  /* Error getting the value.  Try to at least get the
 	     right type.  */
@@ -375,7 +374,6 @@ varobj_create (const char *objname,
 
 	  var->type = value_type (type_only_value);
 	}
-      END_CATCH
 
       if (value != NULL)
 	{
@@ -1033,17 +1031,16 @@ varobj_set_value (struct varobj *var, const char *expression)
 
   input_radix = 10;		/* ALWAYS reset to decimal temporarily.  */
   expression_up exp = parse_exp_1 (&s, 0, 0, 0);
-  TRY
+  try
     {
       value = evaluate_expression (exp.get ());
     }
 
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       /* We cannot proceed without a valid expression.  */
       return false;
     }
-  END_CATCH
 
   /* All types that are editable must also be changeable.  */
   gdb_assert (varobj_value_is_changeable_p (var));
@@ -1062,16 +1059,15 @@ varobj_set_value (struct varobj *var, const char *expression)
 
   /* The new value may be lazy.  value_assign, or
      rather value_contents, will take care of this.  */
-  TRY
+  try
     {
       val = value_assign (var->value.get (), value);
     }
 
-  CATCH (except, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       return false;
     }
-  END_CATCH
 
   /* If the value has changed, record it, so that next -var-update can
      report this change.  If a variable had a value of '1', we've set it
@@ -1310,19 +1306,18 @@ install_new_value (struct varobj *var, struct value *value, bool initial)
       else
 	{
 
-	  TRY
+	  try
 	    {
 	      value_fetch_lazy (value);
 	    }
 
-	  CATCH (except, RETURN_MASK_ERROR)
+	  catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	    {
 	      /* Set the value to NULL, so that for the next -var-update,
 		 we don't try to compare the new value with this value,
 		 that we couldn't even read.  */
 	      value = NULL;
 	    }
-	  END_CATCH
 	}
     }
 
@@ -2138,14 +2133,13 @@ value_of_root_1 (struct varobj **var_handle)
 
       /* We need to catch errors here, because if evaluate
          expression fails we want to just return NULL.  */
-      TRY
+      try
 	{
 	  new_val = evaluate_expression (var->root->exp.get ());
 	}
-      CATCH (except, RETURN_MASK_ERROR)
+      catch (const struct gdb_exception_RETURN_MASK_ERROR &except)
 	{
 	}
-      END_CATCH
     }
 
   return new_val;
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index e47fcb1b40a..f15aef0e369 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -943,15 +943,14 @@ handle_unload_dll ()
 static void
 catch_errors (void (*func) ())
 {
-  TRY
+  try
     {
       func ();
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       exception_print (gdb_stderr, ex);
     }
-  END_CATCH
 }
 
 /* Clear list of loaded DLLs.  */
diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c
index f1d63bf8bff..2ee93e7f410 100644
--- a/gdb/x86-linux-nat.c
+++ b/gdb/x86-linux-nat.c
@@ -217,16 +217,15 @@ x86_linux_nat_target::enable_btrace (ptid_t ptid,
 				     const struct btrace_config *conf)
 {
   struct btrace_target_info *tinfo = nullptr;
-  TRY
+  try
     {
       tinfo = linux_enable_btrace (ptid, conf);
     }
-  CATCH (exception, RETURN_MASK_ERROR)
+  catch (const struct gdb_exception_RETURN_MASK_ERROR &exception)
     {
       error (_("Could not enable branch tracing for %s: %s"),
 	     target_pid_to_str (ptid), exception.message.c_str ());
     }
-  END_CATCH
 
   return tinfo;
 }
diff --git a/gdb/xml-support.c b/gdb/xml-support.c
index a176a0a54fb..97cafa623d7 100644
--- a/gdb/xml-support.c
+++ b/gdb/xml-support.c
@@ -383,15 +383,14 @@ gdb_xml_start_element_wrapper (void *data, const XML_Char *name,
 {
   struct gdb_xml_parser *parser = (struct gdb_xml_parser *) data;
 
-  TRY
+  try
     {
       parser->start_element (name, attrs);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       parser->set_error (ex);
     }
-  END_CATCH
 }
 
 /* Handle the end of an element.  NAME is the current element.  */
@@ -456,15 +455,14 @@ gdb_xml_end_element_wrapper (void *data, const XML_Char *name)
 {
   struct gdb_xml_parser *parser = (struct gdb_xml_parser *) data;
 
-  TRY
+  try
     {
       parser->end_element (name);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (const struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       parser->set_error (ex);
     }
-  END_CATCH
 }
 
 /* Free a parser and all its associated state.  */
-- 
2.17.2

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

* [PATCH v2 15/22] Make exceptions use std::string and be self-managing
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
                   ` (11 preceding siblings ...)
  2019-02-27 20:19 ` [PATCH v2 03/22] Change displaced_step_clear_cleanup with a forward_scope_exit Tom Tromey
@ 2019-02-27 20:19 ` Tom Tromey
  2019-04-03 16:20   ` Pedro Alves
  2019-02-27 20:19 ` [PATCH v2 17/22] Rename gdb exception types Tom Tromey
                   ` (8 subsequent siblings)
  21 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes the exception's "message" member to be a std::string.
This allows removing the stack of exception messages, because now
exceptions will self-destruct when needed.

Note that this does increase the cost of copying an exception.  This
will be somewhat addressed in a subsequent patch.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* xml-support.c (gdb_xml_parser::parse): Update.
	* x86-linux-nat.c (x86_linux_nat_target::enable_btrace): Update.
	* value.c (show_convenience): Update.
	* unittests/cli-utils-selftests.c (test_number_or_range_parser)
	(test_parse_flags_qcs): Update.
	* thread.c (thr_try_catch_cmd): Update.
	* target.c (target_translate_tls_address): Update.
	* stack.c (print_frame_arg, read_frame_local, read_frame_arg)
	(info_frame_command_core, frame_apply_command_count): Update.
	* rust-exp.y (rust_lex_exception_test): Update.
	* riscv-tdep.c (riscv_print_one_register_info): Update.
	* remote.c (remote_target::enable_btrace): Update.
	* record-btrace.c (record_btrace_enable_warn): Update.
	* python/py-utils.c (gdbpy_convert_exception): Update.
	* printcmd.c (do_one_display, print_variable_and_value): Update.
	* mi/mi-main.c (mi_print_exception): Update.
	* mi/mi-interp.c (mi_cmd_interpreter_exec): Update.
	* mi/mi-cmd-stack.c (list_arg_or_local): Update.
	* linux-nat.c (linux_nat_target::attach): Update.
	* linux-fork.c (class scoped_switch_fork_info): Update.
	* infrun.c (displaced_step_prepare): Update.
	* infcall.c (call_function_by_hand_dummy): Update.
	* guile/scm-exception.c (gdbscm_scm_from_gdb_exception): Update.
	* gnu-v3-abi.c (print_one_vtable): Update.
	* frame.c (get_prev_frame_always): Update.
	* f-valprint.c (info_common_command_for_block): Update.
	* exec.c (try_open_exec_file): Update.
	* exceptions.c (print_exception, exception_print)
	(exception_fprintf, exception_print_same): Update.
	* dwarf2-frame.c (dwarf2_build_frame_info): Update.
	* dwarf-index-cache.c (index_cache::store)
	(index_cache::lookup_gdb_index): Update.
	* darwin-nat.c (maybe_cache_shell): Update.
	* cp-valprint.c (cp_print_value_fields): Update.
	* compile/compile-cplus-symbols.c (gcc_cplus_convert_symbol)
	(gcc_cplus_symbol_address): Update.
	* compile/compile-c-symbols.c (gcc_convert_symbol)
	(gcc_symbol_address, generate_c_for_for_one_variable): Update.
	* common/selftest.c: Update.
	* common/common-exceptions.h (struct gdb_exception) <message>: Now
	a std::string.
	(exception_try_scope_entry, exception_try_scope_exit): Don't
	declare.
	(struct exception_try_scope): Remove.
	(TRY): Don't use exception_try_scope.
	* common/common-exceptions.c (exception_none): Change
	initializer.
	(struct catcher) <state, exception>: Initialize inline.
	<prev>: Remove member.
	(current_catcher): Remove.
	(catchers): New global.
	(exceptions_state_mc_init): Simplify.
	(catcher_pop): Remove.
	(exceptions_state_mc, exceptions_state_mc_catch): Update.
	(try_scope_depth, exception_try_scope_entry)
	(exception_try_scope_exit): Remove.
	(throw_exception_sjlj): Update.
	(exception_messages, exception_messages_size): Remove.
	(throw_it): Simplify.
	* cli/cli-script.c (script_from_file): Update.
	* breakpoint.c (insert_bp_location, update_breakpoint_locations):
	Update.
	* ada-valprint.c (ada_val_print): Update.
	* ada-lang.c (ada_to_fixed_type_1, ada_exception_name_addr)
	(create_excep_cond_exprs): Update.

gdb/gdbserver/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* server.c (handle_btrace_general_set, handle_qxfer_btrace)
	(handle_qxfer_btrace_conf, detach_or_kill_for_exit_cleanup)
	(captured_main, main): Update.
	* gdbreplay.c (main): Update.
---
 gdb/ChangeLog                       |  68 ++++++++++++++++
 gdb/ada-lang.c                      |   6 +-
 gdb/ada-valprint.c                  |   2 +-
 gdb/breakpoint.c                    |  14 ++--
 gdb/cli/cli-script.c                |   3 +-
 gdb/common/common-exceptions.c      | 117 +++++-----------------------
 gdb/common/common-exceptions.h      |  22 +-----
 gdb/common/selftest.c               |   2 +-
 gdb/compile/compile-c-symbols.c     |   6 +-
 gdb/compile/compile-cplus-symbols.c |   4 +-
 gdb/cp-valprint.c                   |   2 +-
 gdb/darwin-nat.c                    |   2 +-
 gdb/dwarf-index-cache.c             |   4 +-
 gdb/dwarf2-frame.c                  |   4 +-
 gdb/exceptions.c                    |  16 +---
 gdb/exec.c                          |  14 +---
 gdb/f-valprint.c                    |   3 +-
 gdb/frame.c                         |   6 +-
 gdb/gdbserver/ChangeLog             |   7 ++
 gdb/gdbserver/gdbreplay.c           |   2 +-
 gdb/gdbserver/server.c              |  13 ++--
 gdb/gnu-v3-abi.c                    |   2 +-
 gdb/guile/scm-exception.c           |   2 +-
 gdb/infcall.c                       |   2 +-
 gdb/infrun.c                        |   4 +-
 gdb/linux-fork.c                    |   2 +-
 gdb/linux-nat.c                     |   5 +-
 gdb/mi/mi-cmd-stack.c               |   8 +-
 gdb/mi/mi-interp.c                  |   2 +-
 gdb/mi/mi-main.c                    |   4 +-
 gdb/printcmd.c                      |  11 +--
 gdb/python/py-utils.c               |   2 +-
 gdb/record-btrace.c                 |   2 +-
 gdb/remote.c                        |   4 +-
 gdb/riscv-tdep.c                    |   2 +-
 gdb/rust-exp.y                      |   2 +-
 gdb/stack.c                         |  34 ++++----
 gdb/target.c                        |   4 +-
 gdb/thread.c                        |   2 +-
 gdb/unittests/cli-utils-selftests.c |   8 +-
 gdb/value.c                         |   2 +-
 gdb/x86-linux-nat.c                 |   2 +-
 gdb/xml-support.c                   |   4 +-
 43 files changed, 197 insertions(+), 230 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index a6fadc846e3..9c23d8e0d5f 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -9056,7 +9056,7 @@ ada_to_fixed_type_1 (struct type *type, const gdb_byte *valaddr,
 		   optimized out).  */
 		throw_error (except.error,
 			     _("unable to read value of %s (%s)"),
-			     xvz_name, except.message);
+			     xvz_name, except.message.c_str ());
 	      }
 	    END_CATCH
 
@@ -12365,7 +12365,7 @@ ada_exception_name_addr (enum ada_exception_catchpoint_kind ex,
 
   CATCH (e, RETURN_MASK_ERROR)
     {
-      warning (_("failed to get exception name: %s"), e.message);
+      warning (_("failed to get exception name: %s"), e.message.c_str ());
       return 0;
     }
   END_CATCH
@@ -12459,7 +12459,7 @@ create_excep_cond_exprs (struct ada_catchpoint *c,
 	    {
 	      warning (_("failed to reevaluate internal exception condition "
 			 "for catchpoint %d: %s"),
-		       c->number, e.message);
+		       c->number, e.message.c_str ());
 	    }
 	  END_CATCH
 	}
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index f2aed32cc86..72cae3b7f47 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -1213,7 +1213,7 @@ ada_val_print (struct type *type,
   CATCH (except, RETURN_MASK_ERROR)
     {
       fprintf_filtered (stream, _("<error reading variable: %s>"),
-			except.message);
+			except.message.c_str ());
     }
   END_CATCH
 }
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 9be99ff4efa..17b4d643613 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -2667,18 +2667,18 @@ insert_bp_location (struct bp_location *bl,
 	      if (bl->loc_type == bp_loc_hardware_breakpoint)
 		{
 		  *hw_breakpoint_error = 1;
-		  *hw_bp_error_explained_already = bp_excpt.message != NULL;
+		  *hw_bp_error_explained_already = !bp_excpt.message.empty ();
                   fprintf_unfiltered (tmp_error_stream,
                                       "Cannot insert hardware breakpoint %d%s",
                                       bl->owner->number,
-				      bp_excpt.message ? ":" : ".\n");
-                  if (bp_excpt.message != NULL)
+				      !bp_excpt.message.empty () ? ":" : ".\n");
+                  if (!bp_excpt.message.empty ())
                     fprintf_unfiltered (tmp_error_stream, "%s.\n",
-					bp_excpt.message);
+					bp_excpt.message.c_str ());
 		}
 	      else
 		{
-		  if (bp_excpt.message == NULL)
+		  if (bp_excpt.message.empty ())
 		    {
 		      std::string message
 			= memory_error_message (TARGET_XFER_E_IO,
@@ -2694,7 +2694,7 @@ insert_bp_location (struct bp_location *bl,
 		      fprintf_unfiltered (tmp_error_stream,
 					  "Cannot insert breakpoint %d: %s\n",
 					  bl->owner->number,
-					  bp_excpt.message);
+					  bp_excpt.message.c_str ());
 		    }
 		}
 	      return 1;
@@ -13529,7 +13529,7 @@ update_breakpoint_locations (struct breakpoint *b,
 	    {
 	      warning (_("failed to reevaluate condition "
 			 "for breakpoint %d: %s"), 
-		       b->number, e.message);
+		       b->number, e.message.c_str ());
 	      new_loc->enabled = 0;
 	    }
 	  END_CATCH
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 85f00c75b3f..c02c7880648 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -1553,7 +1553,8 @@ script_from_file (FILE *stream, const char *file)
 	 prepended.  */
       throw_error (e.error,
 		   _("%s:%d: Error in sourced command file:\n%s"),
-		   source_file_name.c_str (), source_line_number, e.message);
+		   source_file_name.c_str (), source_line_number,
+		   e.message.c_str ());
     }
   END_CATCH
 }
diff --git a/gdb/common/common-exceptions.c b/gdb/common/common-exceptions.c
index c3529c989fd..15b59f4dd94 100644
--- a/gdb/common/common-exceptions.c
+++ b/gdb/common/common-exceptions.c
@@ -19,8 +19,9 @@
 
 #include "common-defs.h"
 #include "common-exceptions.h"
+#include <forward_list>
 
-const struct gdb_exception exception_none = { (enum return_reason) 0, GDB_NO_ERROR, NULL };
+const struct gdb_exception exception_none {};
 
 /* Possible catcher states.  */
 enum catcher_state {
@@ -42,42 +43,21 @@ enum catcher_action {
 
 struct catcher
 {
-  enum catcher_state state;
+  enum catcher_state state = CATCHER_CREATED;
   /* Jump buffer pointing back at the exception handler.  */
   jmp_buf buf;
   /* Status buffer belonging to the exception handler.  */
-  struct gdb_exception exception;
-  /* Back link.  */
-  struct catcher *prev;
+  struct gdb_exception exception = exception_none;
 };
 
 /* Where to go for throw_exception().  */
-static struct catcher *current_catcher;
+static std::forward_list<struct catcher> catchers;
 
 jmp_buf *
-exceptions_state_mc_init (void)
+exceptions_state_mc_init ()
 {
-  struct catcher *new_catcher = XCNEW (struct catcher);
-
-  /* Start with no exception.  */
-  new_catcher->exception = exception_none;
-
-  /* Push this new catcher on the top.  */
-  new_catcher->prev = current_catcher;
-  current_catcher = new_catcher;
-  new_catcher->state = CATCHER_CREATED;
-
-  return &new_catcher->buf;
-}
-
-static void
-catcher_pop (void)
-{
-  struct catcher *old_catcher = current_catcher;
-
-  current_catcher = old_catcher->prev;
-
-  xfree (old_catcher);
+  catchers.emplace_front ();
+  return &catchers.front ().buf;
 }
 
 /* Catcher state machine.  Returns non-zero if the m/c should be run
@@ -86,14 +66,14 @@ catcher_pop (void)
 static int
 exceptions_state_mc (enum catcher_action action)
 {
-  switch (current_catcher->state)
+  switch (catchers.front ().state)
     {
     case CATCHER_CREATED:
       switch (action)
 	{
 	case CATCH_ITER:
 	  /* Allow the code to run the catcher.  */
-	  current_catcher->state = CATCHER_RUNNING;
+	  catchers.front ().state = CATCHER_RUNNING;
 	  return 1;
 	default:
 	  internal_error (__FILE__, __LINE__, _("bad state"));
@@ -105,10 +85,10 @@ exceptions_state_mc (enum catcher_action action)
 	  /* No error/quit has occured.  */
 	  return 0;
 	case CATCH_ITER_1:
-	  current_catcher->state = CATCHER_RUNNING_1;
+	  catchers.front ().state = CATCHER_RUNNING_1;
 	  return 1;
 	case CATCH_THROWING:
-	  current_catcher->state = CATCHER_ABORTING;
+	  catchers.front ().state = CATCHER_ABORTING;
 	  /* See also throw_exception.  */
 	  return 1;
 	default:
@@ -121,10 +101,10 @@ exceptions_state_mc (enum catcher_action action)
 	  /* The did a "break" from the inner while loop.  */
 	  return 0;
 	case CATCH_ITER_1:
-	  current_catcher->state = CATCHER_RUNNING;
+	  catchers.front ().state = CATCHER_RUNNING;
 	  return 0;
 	case CATCH_THROWING:
-	  current_catcher->state = CATCHER_ABORTING;
+	  catchers.front ().state = CATCHER_ABORTING;
 	  /* See also throw_exception.  */
 	  return 1;
 	default:
@@ -152,8 +132,8 @@ int
 exceptions_state_mc_catch (struct gdb_exception *exception,
 			   int mask)
 {
-  *exception = current_catcher->exception;
-  catcher_pop ();
+  *exception = std::move (catchers.front ().exception);
+  catchers.pop_front ();
 
   if (exception->reason < 0)
     {
@@ -185,29 +165,6 @@ exceptions_state_mc_action_iter_1 (void)
   return exceptions_state_mc (CATCH_ITER_1);
 }
 
-/* How many nested TRY blocks we have.  See exception_messages and
-   throw_it.  */
-
-static int try_scope_depth;
-
-/* Called on entry to a TRY scope.  */
-
-void *
-exception_try_scope_entry (void)
-{
-  ++try_scope_depth;
-  return nullptr;
-}
-
-/* Called on exit of a TRY scope, either normal exit or exception
-   exit.  */
-
-void
-exception_try_scope_exit (void *saved_state)
-{
-  --try_scope_depth;
-}
-
 /* Called by the default catch block.  IOW, we'll get here before
    jumping out to the next outermost scope an exception if a GDB
    exception is not caught.  */
@@ -235,8 +192,8 @@ throw_exception_sjlj (struct gdb_exception exception)
      that call via setjmp's return value.  Note that REASON can't be
      zero, by definition in common-exceptions.h.  */
   exceptions_state_mc (CATCH_THROWING);
-  current_catcher->exception = exception;
-  longjmp (current_catcher->buf, exception.reason);
+  catchers.front ().exception = exception;
+  longjmp (catchers.front ().buf, exception.reason);
 }
 
 /* Implementation of throw_exception that uses C++ try/catch.  */
@@ -268,52 +225,16 @@ throw_exception (struct gdb_exception exception)
   throw_exception_cxx (exception);
 }
 
-/* A stack of exception messages.
-   This is needed to handle nested calls to throw_it: we don't want to
-   xfree space for a message before it's used.
-   This can happen if we throw an exception during a cleanup:
-   An outer TRY_CATCH may have an exception message it wants to print,
-   but while doing cleanups further calls to throw_it are made.
-
-   This is indexed by the size of the current_catcher list.
-   It is a dynamically allocated array so that we don't care how deeply
-   GDB nests its TRY_CATCHs.  */
-static char **exception_messages;
-
-/* The number of currently allocated entries in exception_messages.  */
-static int exception_messages_size;
-
 static void ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (3, 0)
 throw_it (enum return_reason reason, enum errors error, const char *fmt,
 	  va_list ap)
 {
   struct gdb_exception e;
-  char *new_message;
-  int depth = try_scope_depth;
-
-  gdb_assert (depth > 0);
-
-  /* Note: The new message may use an old message's text.  */
-  new_message = xstrvprintf (fmt, ap);
-
-  if (depth > exception_messages_size)
-    {
-      int old_size = exception_messages_size;
-
-      exception_messages_size = depth + 10;
-      exception_messages = XRESIZEVEC (char *, exception_messages,
-				       exception_messages_size);
-      memset (exception_messages + old_size, 0,
-	      (exception_messages_size - old_size) * sizeof (char *));
-    }
-
-  xfree (exception_messages[depth - 1]);
-  exception_messages[depth - 1] = new_message;
 
   /* Create the exception.  */
   e.reason = reason;
   e.error = error;
-  e.message = new_message;
+  e.message = string_vprintf (fmt, ap);
 
   /* Throw the exception.  */
   throw_exception (e);
diff --git a/gdb/common/common-exceptions.h b/gdb/common/common-exceptions.h
index 6cc09eab938..d4b30104239 100644
--- a/gdb/common/common-exceptions.h
+++ b/gdb/common/common-exceptions.h
@@ -112,7 +112,7 @@ struct gdb_exception
 {
   enum return_reason reason;
   enum errors error;
-  const char *message;
+  std::string message;
 };
 
 /* Functions to drive the sjlj-based exceptions state machine.  Though
@@ -127,8 +127,6 @@ extern int exceptions_state_mc_catch (struct gdb_exception *, int);
 
 /* For the C++ try/catch-based TRY/CATCH mechanism.  */
 
-extern void *exception_try_scope_entry (void);
-extern void exception_try_scope_exit (void *saved_state);
 extern void exception_rethrow (void) ATTRIBUTE_NORETURN;
 
 /* Macro to wrap up standard try/catch behavior.
@@ -178,23 +176,6 @@ extern void exception_rethrow (void) ATTRIBUTE_NORETURN;
 #define END_CATCH_SJLJ				\
   }
 
-/* Prevent error/quit during TRY from calling cleanups established
-   prior to here.  This pops out the scope in either case of normal
-   exit or exception exit.  */
-struct exception_try_scope
-{
-  exception_try_scope ()
-  {
-    saved_state = exception_try_scope_entry ();
-  }
-  ~exception_try_scope ()
-  {
-    exception_try_scope_exit (saved_state);
-  }
-
-  void *saved_state;
-};
-
 /* We still need to wrap TRY/CATCH in C++ so that cleanups and C++
    exceptions can coexist.
 
@@ -214,7 +195,6 @@ struct exception_try_scope
   {									\
     try									\
       {									\
-	exception_try_scope exception_try_scope_instance;		\
 	do								\
 	  {
 
diff --git a/gdb/common/selftest.c b/gdb/common/selftest.c
index fe060ff64f1..6f972e17910 100644
--- a/gdb/common/selftest.c
+++ b/gdb/common/selftest.c
@@ -90,7 +90,7 @@ run_tests (const char *filter)
       CATCH (ex, RETURN_MASK_ERROR)
 	{
 	  ++failed;
-	  debug_printf ("Self test failed: %s\n", ex.message);
+	  debug_printf ("Self test failed: %s\n", ex.message.c_str ());
 	}
       END_CATCH
 
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index a0f833e6f01..1a1c10e9308 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -369,7 +369,7 @@ gcc_convert_symbol (void *datum,
 
   CATCH (e, RETURN_MASK_ALL)
     {
-      context->plugin ().error (e.message);
+      context->plugin ().error (e.message.c_str ());
     }
   END_CATCH
 
@@ -432,7 +432,7 @@ gcc_symbol_address (void *datum, struct gcc_c_context *gcc_context,
 
   CATCH (e, RETURN_MASK_ERROR)
     {
-      context->plugin ().error (e.message);
+      context->plugin ().error (e.message.c_str ());
     }
   END_CATCH
 
@@ -602,7 +602,7 @@ generate_c_for_for_one_variable (compile_instance *compiler,
 
   CATCH (e, RETURN_MASK_ERROR)
     {
-      compiler->insert_symbol_error (sym, e.message);
+      compiler->insert_symbol_error (sym, e.message.c_str ());
     }
   END_CATCH
 }
diff --git a/gdb/compile/compile-cplus-symbols.c b/gdb/compile/compile-cplus-symbols.c
index 0979784466e..83289e37cdd 100644
--- a/gdb/compile/compile-cplus-symbols.c
+++ b/gdb/compile/compile-cplus-symbols.c
@@ -392,7 +392,7 @@ gcc_cplus_convert_symbol (void *datum,
     {
       /* We can't allow exceptions to escape out of this callback.  Safest
 	 is to simply emit a gcc error.  */
-      instance->plugin ().error (e.message);
+      instance->plugin ().error (e.message.c_str ());
     }
   END_CATCH
 
@@ -469,7 +469,7 @@ gcc_cplus_symbol_address (void *datum, struct gcc_cp_context *gcc_context,
 
   CATCH (e, RETURN_MASK_ERROR)
     {
-      instance->plugin ().error (e.message);
+      instance->plugin ().error (e.message.c_str ());
     }
   END_CATCH
 
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index 7124da42ec9..b4478ee644c 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -325,7 +325,7 @@ cp_print_value_fields (struct type *type, struct type *real_type,
 		    {
 		      fprintf_filtered (stream,
 					_("<error reading variable: %s>"),
-					ex.message);
+					ex.message.c_str ());
 		    }
 		  END_CATCH
 
diff --git a/gdb/darwin-nat.c b/gdb/darwin-nat.c
index 8c34aa8a3f2..0a75ad3e484 100644
--- a/gdb/darwin-nat.c
+++ b/gdb/darwin-nat.c
@@ -1962,7 +1962,7 @@ caching a copy of your shell.  However, this failed:\n\
 If you correct the problem, gdb will automatically try again the next time\n\
 you \"run\".  To prevent these attempts, you can use:\n\
     set startup-with-shell off"),
-		   ex.message);
+		   ex.message.c_str ());
 	  return false;
 	}
       END_CATCH
diff --git a/gdb/dwarf-index-cache.c b/gdb/dwarf-index-cache.c
index 445f8b199e6..ab5b6aa9419 100644
--- a/gdb/dwarf-index-cache.c
+++ b/gdb/dwarf-index-cache.c
@@ -133,7 +133,7 @@ index_cache::store (struct dwarf2_per_objfile *dwarf2_per_objfile)
     {
       if (debug_index_cache)
 	printf_unfiltered ("index cache: couldn't store index cache for objfile "
-			 "%s: %s", objfile_name (obj), except.message);
+			   "%s: %s", objfile_name (obj), except.message.c_str ());
     }
   END_CATCH
 }
@@ -193,7 +193,7 @@ index_cache::lookup_gdb_index (const bfd_build_id *build_id,
     {
       if (debug_index_cache)
 	printf_unfiltered ("index cache: couldn't read %s: %s\n",
-			 filename.c_str (), except.message);
+			   filename.c_str (), except.message.c_str ());
     }
   END_CATCH
 
diff --git a/gdb/dwarf2-frame.c b/gdb/dwarf2-frame.c
index 178ac44ecbe..21d826b012e 100644
--- a/gdb/dwarf2-frame.c
+++ b/gdb/dwarf2-frame.c
@@ -2257,7 +2257,7 @@ dwarf2_build_frame_info (struct objfile *objfile)
 	  CATCH (e, RETURN_MASK_ERROR)
 	    {
 	      warning (_("skipping .eh_frame info of %s: %s"),
-		       objfile_name (objfile), e.message);
+		       objfile_name (objfile), e.message.c_str ());
 
 	      if (fde_table.num_entries != 0)
 		{
@@ -2298,7 +2298,7 @@ dwarf2_build_frame_info (struct objfile *objfile)
       CATCH (e, RETURN_MASK_ERROR)
 	{
 	  warning (_("skipping .debug_frame info of %s: %s"),
-		   objfile_name (objfile), e.message);
+		   objfile_name (objfile), e.message.c_str ());
 
 	  if (fde_table.num_entries != 0)
 	    {
diff --git a/gdb/exceptions.c b/gdb/exceptions.c
index a29ef0cde50..3341354ad9d 100644
--- a/gdb/exceptions.c
+++ b/gdb/exceptions.c
@@ -81,7 +81,7 @@ print_exception (struct ui_file *file, struct gdb_exception e)
   const char *start;
   const char *end;
 
-  for (start = e.message; start != NULL; start = end)
+  for (start = e.message.c_str (); start != NULL; start = end)
     {
       end = strchr (start, '\n');
       if (end == NULL)
@@ -112,7 +112,7 @@ print_exception (struct ui_file *file, struct gdb_exception e)
 void
 exception_print (struct ui_file *file, struct gdb_exception e)
 {
-  if (e.reason < 0 && e.message != NULL)
+  if (e.reason < 0 && !e.message.empty ())
     {
       print_flush ();
       print_exception (file, e);
@@ -123,7 +123,7 @@ void
 exception_fprintf (struct ui_file *file, struct gdb_exception e,
 		   const char *prefix, ...)
 {
-  if (e.reason < 0 && e.message != NULL)
+  if (e.reason < 0 && !e.message.empty ())
     {
       va_list args;
 
@@ -143,15 +143,7 @@ exception_fprintf (struct ui_file *file, struct gdb_exception e,
 int
 exception_print_same (struct gdb_exception e1, struct gdb_exception e2)
 {
-  const char *msg1 = e1.message;
-  const char *msg2 = e2.message;
-
-  if (msg1 == NULL)
-    msg1 = "";
-  if (msg2 == NULL)
-    msg2 = "";
-
   return (e1.reason == e2.reason
 	  && e1.error == e2.error
-	  && strcmp (msg1, msg2) == 0);
+	  && e1.message == e2.message);
 }
diff --git a/gdb/exec.c b/gdb/exec.c
index 77bd140a8e8..706de9e32f0 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -161,7 +161,6 @@ try_open_exec_file (const char *exec_file_host, struct inferior *inf,
      Even without a symbol file, the remote-based debugging session should
      continue normally instead of ending abruptly.  Hence we catch thrown
      errors/exceptions in the following code.  */
-  std::string saved_message;
   TRY
     {
       /* We must do this step even if exec_file_host is NULL, so that
@@ -170,17 +169,10 @@ try_open_exec_file (const char *exec_file_host, struct inferior *inf,
     }
   CATCH (err, RETURN_MASK_ERROR)
     {
-      if (err.message != NULL)
-	warning ("%s", err.message);
+      if (!err.message.empty ())
+	warning ("%s", err.message.c_str ());
 
       prev_err = err;
-
-      /* Save message so it doesn't get trashed by the catch below.  */
-      if (err.message != NULL)
-	{
-	  saved_message = err.message;
-	  prev_err.message = saved_message.c_str ();
-	}
     }
   END_CATCH
 
@@ -193,7 +185,7 @@ try_open_exec_file (const char *exec_file_host, struct inferior *inf,
       CATCH (err, RETURN_MASK_ERROR)
 	{
 	  if (!exception_print_same (prev_err, err))
-	    warning ("%s", err.message);
+	    warning ("%s", err.message.c_str ());
 	}
       END_CATCH
     }
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index d9fe26f1d6a..d67aad20ba7 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -416,7 +416,8 @@ info_common_command_for_block (const struct block *block, const char *comname,
 
 	    CATCH (except, RETURN_MASK_ERROR)
 	      {
-		printf_filtered ("<error reading variable: %s>", except.message);
+		printf_filtered ("<error reading variable: %s>",
+				 except.message.c_str ());
 	      }
 	    END_CATCH
 
diff --git a/gdb/frame.c b/gdb/frame.c
index d8b5f819f1d..20721204d5e 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -2101,7 +2101,7 @@ get_prev_frame_always (struct frame_info *this_frame)
       if (ex.error == MEMORY_ERROR)
 	{
 	  this_frame->stop_reason = UNWIND_MEMORY_ERROR;
-	  if (ex.message != NULL)
+	  if (!ex.message.empty ())
 	    {
 	      char *stop_string;
 	      size_t size;
@@ -2110,9 +2110,9 @@ get_prev_frame_always (struct frame_info *this_frame)
 	         Allocate using stack local STOP_STRING then assign the
 	         pointer to the frame, this allows the STOP_STRING on the
 	         frame to be of type 'const char *'.  */
-	      size = strlen (ex.message) + 1;
+	      size = ex.message.size () + 1;
 	      stop_string = (char *) frame_obstack_zalloc (size);
-	      memcpy (stop_string, ex.message, size);
+	      memcpy (stop_string, ex.message.c_str (), size);
 	      this_frame->stop_string = stop_string;
 	    }
 	  prev_frame = NULL;
diff --git a/gdb/gdbserver/gdbreplay.c b/gdb/gdbserver/gdbreplay.c
index bda8095839c..8b192361504 100644
--- a/gdb/gdbserver/gdbreplay.c
+++ b/gdb/gdbserver/gdbreplay.c
@@ -534,7 +534,7 @@ main (int argc, char *argv[])
       if (exception.reason == RETURN_ERROR)
 	{
 	  fflush (stdout);
-	  fprintf (stderr, "%s\n", exception.message);
+	  fprintf (stderr, "%s\n", exception.message.c_str ());
 	}
 
       exit (1);
diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c
index 25c62aad830..57570f97d98 100644
--- a/gdb/gdbserver/server.c
+++ b/gdb/gdbserver/server.c
@@ -474,7 +474,7 @@ handle_btrace_general_set (char *own_buf)
     }
   CATCH (exception, RETURN_MASK_ERROR)
     {
-      sprintf (own_buf, "E.%s", exception.message);
+      sprintf (own_buf, "E.%s", exception.message.c_str ());
     }
   END_CATCH
 
@@ -1884,7 +1884,7 @@ handle_qxfer_btrace (const char *annex,
 	}
       CATCH (exception, RETURN_MASK_ERROR)
 	{
-	  sprintf (cs.own_buf, "E.%s", exception.message);
+	  sprintf (cs.own_buf, "E.%s", exception.message.c_str ());
 	  result = -1;
 	}
       END_CATCH
@@ -1956,7 +1956,7 @@ handle_qxfer_btrace_conf (const char *annex,
 	}
       CATCH (exception, RETURN_MASK_ERROR)
 	{
-	  sprintf (cs.own_buf, "E.%s", exception.message);
+	  sprintf (cs.own_buf, "E.%s", exception.message.c_str ());
 	  result = -1;
 	}
       END_CATCH
@@ -3559,7 +3559,8 @@ detach_or_kill_for_exit_cleanup ()
   CATCH (exception, RETURN_MASK_ALL)
     {
       fflush (stdout);
-      fprintf (stderr, "Detach or kill failed: %s\n", exception.message);
+      fprintf (stderr, "Detach or kill failed: %s\n",
+	       exception.message.c_str ());
       exit_code = 1;
     }
   END_CATCH
@@ -3933,7 +3934,7 @@ captured_main (int argc, char *argv[])
       CATCH (exception, RETURN_MASK_ERROR)
 	{
 	  fflush (stdout);
-	  fprintf (stderr, "gdbserver: %s\n", exception.message);
+	  fprintf (stderr, "gdbserver: %s\n", exception.message.c_str ());
 
 	  if (response_needed)
 	    {
@@ -3963,7 +3964,7 @@ main (int argc, char *argv[])
       if (exception.reason == RETURN_ERROR)
 	{
 	  fflush (stdout);
-	  fprintf (stderr, "%s\n", exception.message);
+	  fprintf (stderr, "%s\n", exception.message.c_str ());
 	  fprintf (stderr, "Exiting\n");
 	  exit_code = 1;
 	}
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index 15c7c667001..952553f43ab 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -912,7 +912,7 @@ print_one_vtable (struct gdbarch *gdbarch, struct value *value,
 	}
       CATCH (ex, RETURN_MASK_ERROR)
 	{
-	  printf_filtered (_("<error: %s>"), ex.message);
+	  printf_filtered (_("<error: %s>"), ex.message.c_str ());
 	  got_error = 1;
 	}
       END_CATCH
diff --git a/gdb/guile/scm-exception.c b/gdb/guile/scm-exception.c
index e37edd01787..d502ae06435 100644
--- a/gdb/guile/scm-exception.c
+++ b/gdb/guile/scm-exception.c
@@ -446,7 +446,7 @@ gdbscm_scm_from_gdb_exception (struct gdb_exception exception)
 
   return gdbscm_make_error (key, NULL, "~A",
 			    scm_list_1 (gdbscm_scm_from_c_string
-					(exception.message)),
+					(exception.message.c_str ())),
 			    SCM_BOOL_F);
 }
 
diff --git a/gdb/infcall.c b/gdb/infcall.c
index e58ba849031..45cf24f6393 100644
--- a/gdb/infcall.c
+++ b/gdb/infcall.c
@@ -1190,7 +1190,7 @@ An error occurred while in a function called from GDB.\n\
 Evaluation of the expression containing the function\n\
 (%s) will be abandoned.\n\
 When the function is done executing, GDB will silently stop."),
-		       e.message, name);
+		       e.message.c_str (), name);
 	case RETURN_QUIT:
 	default:
 	  throw_exception (e);
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 582c1f77008..b8e1e1fbfd8 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -1790,7 +1790,7 @@ displaced_step_prepare (thread_info *thread)
 	{
 	  fprintf_unfiltered (gdb_stdlog,
 			      "infrun: disabling displaced stepping: %s\n",
-			      ex.message);
+			      ex.message.c_str ());
 	}
 
       /* Be verbose if "set displaced-stepping" is "on", silent if
@@ -1798,7 +1798,7 @@ displaced_step_prepare (thread_info *thread)
       if (can_use_displaced_stepping == AUTO_BOOLEAN_TRUE)
 	{
 	  warning (_("disabling displaced stepping: %s"),
-		   ex.message);
+		   ex.message.c_str ());
 	}
 
       /* Disable further displaced stepping attempts.  */
diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c
index b1b390c5c6e..5a97dfa23dc 100644
--- a/gdb/linux-fork.c
+++ b/gdb/linux-fork.c
@@ -481,7 +481,7 @@ public:
 	CATCH (ex, RETURN_MASK_ALL)
 	  {
 	    warning (_("Couldn't restore checkpoint state in %s: %s"),
-		     target_pid_to_str (m_oldfp->ptid), ex.message);
+		     target_pid_to_str (m_oldfp->ptid), ex.message.c_str ());
 	  }
 	END_CATCH
       }
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 063afe26666..875e6f66cc1 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -1199,9 +1199,10 @@ linux_nat_target::attach (const char *args, int from_tty)
       std::string reason = linux_ptrace_attach_fail_reason (pid);
 
       if (!reason.empty ())
-	throw_error (ex.error, "warning: %s\n%s", reason.c_str (), ex.message);
+	throw_error (ex.error, "warning: %s\n%s", reason.c_str (),
+		     ex.message.c_str ());
       else
-	throw_error (ex.error, "%s", ex.message);
+	throw_error (ex.error, "%s", ex.message.c_str ());
     }
   END_CATCH
 
diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index 119e887e6b3..e55c835a75f 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -527,7 +527,7 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
 
   if (arg->val || arg->error)
     {
-      const char *error_message = NULL;
+      std::string error_message;
 
       if (arg->error)
 	error_message = arg->error;
@@ -544,12 +544,12 @@ list_arg_or_local (const struct frame_arg *arg, enum what_to_list what,
 	    }
 	  CATCH (except, RETURN_MASK_ERROR)
 	    {
-	      error_message = except.message;
+	      error_message = std::move (except.message);
 	    }
 	  END_CATCH
 	}
-      if (error_message != NULL)
-	stb.printf (_("<error reading variable: %s>"), error_message);
+      if (!error_message.empty ())
+	stb.printf (_("<error reading variable: %s>"), error_message.c_str ());
       uiout->field_stream ("value", stb);
     }
 }
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index 3e9f36897a8..b3a8094f425 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -232,7 +232,7 @@ mi_cmd_interpreter_exec (const char *command, char **argv, int argc)
 
       if (e.reason < 0)
 	{
-	  mi_error_message = e.message;
+	  mi_error_message = std::move (e.message);
 	  break;
 	}
     }
diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 46bc928d9fe..4f12218ea69 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1881,10 +1881,10 @@ mi_print_exception (const char *token, struct gdb_exception exception)
 
   fputs_unfiltered (token, mi->raw_stdout);
   fputs_unfiltered ("^error,msg=\"", mi->raw_stdout);
-  if (exception.message == NULL)
+  if (exception.message.empty ())
     fputs_unfiltered ("unknown error", mi->raw_stdout);
   else
-    fputstr_unfiltered (exception.message, '"', mi->raw_stdout);
+    fputstr_unfiltered (exception.message.c_str (), '"', mi->raw_stdout);
   fputs_unfiltered ("\"", mi->raw_stdout);
 
   switch (exception.error)
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 03763d577ab..46d242ddb11 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1893,7 +1893,7 @@ do_one_display (struct display *d)
 	  /* Can't re-parse the expression.  Disable this display item.  */
 	  d->enabled_p = 0;
 	  warning (_("Unable to display \"%s\": %s"),
-		   d->exp_string, ex.message);
+		   d->exp_string, ex.message.c_str ());
 	  return;
 	}
       END_CATCH
@@ -1956,7 +1956,8 @@ do_one_display (struct display *d)
 	}
       CATCH (ex, RETURN_MASK_ERROR)
 	{
-	  fprintf_filtered (gdb_stdout, _("<error: %s>\n"), ex.message);
+	  fprintf_filtered (gdb_stdout, _("<error: %s>\n"),
+			    ex.message.c_str ());
 	}
       END_CATCH
     }
@@ -1990,7 +1991,7 @@ do_one_display (struct display *d)
 	}
       CATCH (ex, RETURN_MASK_ERROR)
 	{
-	  fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message);
+	  fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message.c_str ());
 	}
       END_CATCH
 
@@ -2195,8 +2196,8 @@ print_variable_and_value (const char *name, struct symbol *var,
     }
   CATCH (except, RETURN_MASK_ERROR)
     {
-      fprintf_filtered(stream, "<error reading variable %s (%s)>", name,
-		       except.message);
+      fprintf_filtered (stream, "<error reading variable %s (%s)>", name,
+			except.message.c_str ());
     }
   END_CATCH
 
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c
index a380b34afe8..e482f90a1d9 100644
--- a/gdb/python/py-utils.c
+++ b/gdb/python/py-utils.c
@@ -247,7 +247,7 @@ gdbpy_convert_exception (struct gdb_exception exception)
   else
     exc_class = gdbpy_gdb_error;
 
-  PyErr_Format (exc_class, "%s", exception.message);
+  PyErr_Format (exc_class, "%s", exception.message.c_str ());
 }
 
 /* Converts OBJ to a CORE_ADDR value.
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index dc26938f0b9..da2d246f723 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -288,7 +288,7 @@ record_btrace_enable_warn (struct thread_info *tp)
     }
   CATCH (error, RETURN_MASK_ERROR)
     {
-      warning ("%s", error.message);
+      warning ("%s", error.message.c_str ());
     }
   END_CATCH
 }
diff --git a/gdb/remote.c b/gdb/remote.c
index 5f658deefaa..eb74c23520a 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -13803,8 +13803,8 @@ remote_target::enable_btrace (ptid_t ptid, const struct btrace_config *conf)
     }
   CATCH (err, RETURN_MASK_ERROR)
     {
-      if (err.message != NULL)
-	warning ("%s", err.message);
+      if (!err.message.empty ())
+	warning ("%s", err.message.c_str ());
     }
   END_CATCH
 
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index 8a996f32d39..d93e52c412b 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -660,7 +660,7 @@ riscv_print_one_register_info (struct gdbarch *gdbarch,
     {
       /* Handle failure to read a register without interrupting the entire
          'info registers' flow.  */
-      fprintf_filtered (file, "%s\n", ex.message);
+      fprintf_filtered (file, "%s\n", ex.message.c_str ());
       return;
     }
   END_CATCH
diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
index 9b9735a5d03..51a6fdd5b10 100644
--- a/gdb/rust-exp.y
+++ b/gdb/rust-exp.y
@@ -2604,7 +2604,7 @@ rust_lex_exception_test (rust_parser *parser, const char *input,
     }
   CATCH (except, RETURN_MASK_ERROR)
     {
-      SELF_CHECK (strcmp (except.message, err) == 0);
+      SELF_CHECK (except.message == err);
     }
   END_CATCH
 }
diff --git a/gdb/stack.c b/gdb/stack.c
index bce8d58f543..bce46392909 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -229,7 +229,6 @@ static void
 print_frame_arg (const struct frame_arg *arg)
 {
   struct ui_out *uiout = current_uiout;
-  const char *error_message = NULL;
 
   string_file stb;
 
@@ -264,6 +263,7 @@ print_frame_arg (const struct frame_arg *arg)
     uiout->text ("...");
   else
     {
+      std::string error_message;
       if (arg->error)
 	error_message = arg->error;
       else
@@ -299,12 +299,12 @@ print_frame_arg (const struct frame_arg *arg)
 	    }
 	  CATCH (except, RETURN_MASK_ERROR)
 	    {
-	      error_message = except.message;
+	      error_message = std::move (except.message);
 	    }
 	  END_CATCH
 	}
-      if (error_message != NULL)
-	stb.printf (_("<error reading variable: %s>"), error_message);
+      if (!error_message.empty ())
+	stb.printf (_("<error reading variable: %s>"), error_message.c_str ());
     }
 
   uiout->field_stream ("value", stb);
@@ -328,7 +328,7 @@ read_frame_local (struct symbol *sym, struct frame_info *frame,
     }
   CATCH (except, RETURN_MASK_ERROR)
     {
-      argp->error = xstrdup (except.message);
+      argp->error = xstrdup (except.message.c_str ());
     }
   END_CATCH
 }
@@ -354,8 +354,8 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame,
 	}
       CATCH (except, RETURN_MASK_ERROR)
 	{
-	  val_error = (char *) alloca (strlen (except.message) + 1);
-	  strcpy (val_error, except.message);
+	  val_error = (char *) alloca (except.message.size () + 1);
+	  strcpy (val_error, except.message.c_str ());
 	}
       END_CATCH
     }
@@ -377,8 +377,8 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame,
 	{
 	  if (except.error != NO_ENTRY_VALUE_ERROR)
 	    {
-	      entryval_error = (char *) alloca (strlen (except.message) + 1);
-	      strcpy (entryval_error, except.message);
+	      entryval_error = (char *) alloca (except.message.size () + 1);
+	      strcpy (entryval_error, except.message.c_str ());
 	    }
 	}
       END_CATCH
@@ -436,10 +436,11 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame,
 			 fetched do not display anything.  */
 		      if (except.error == NO_ENTRY_VALUE_ERROR)
 			val_equal = 1;
-		      else if (except.message != NULL)
+		      else if (!except.message.empty ())
 			{
-			  entryval_error = (char *) alloca (strlen (except.message) + 1);
-			  strcpy (entryval_error, except.message);
+			  entryval_error
+			    = (char *) alloca (except.message.size () + 1);
+			  strcpy (entryval_error, except.message.c_str ());
 			}
 		    }
 		  END_CATCH
@@ -480,8 +481,8 @@ read_frame_arg (struct symbol *sym, struct frame_info *frame,
 	    }
 	  CATCH (except, RETURN_MASK_ERROR)
 	    {
-	      val_error = (char *) alloca (strlen (except.message) + 1);
-	      strcpy (val_error, except.message);
+	      val_error = (char *) alloca (except.message.size () + 1);
+	      strcpy (val_error, except.message.c_str ());
 	    }
 	  END_CATCH
 	}
@@ -1410,7 +1411,8 @@ info_frame_command_core (struct frame_info *fi, bool selected_frame_p)
 	      val_print_not_saved (gdb_stdout);
 	      break;
 	    default:
-	      fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message);
+	      fprintf_filtered (gdb_stdout, _("<error: %s>"),
+				ex.message.c_str ());
 	      break;
 	    }
 	}
@@ -2723,7 +2725,7 @@ frame_apply_command_count (const char *which_command,
 	      if (!flags.quiet)
 		print_stack_frame (fi, 1, LOCATION, 0);
 	      if (flags.cont)
-		printf_filtered ("%s\n", ex.message);
+		printf_filtered ("%s\n", ex.message.c_str ());
 	      else
 		throw_exception (ex);
 	    }
diff --git a/gdb/target.c b/gdb/target.c
index 116510e8cb8..b27ecb49e0e 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -754,12 +754,12 @@ target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset)
 		error (_("Cannot find thread-local storage for %s, "
 		         "shared library %s:\n%s"),
 		       target_pid_to_str (ptid),
-		       objfile_name (objfile), ex.message);
+		       objfile_name (objfile), ex.message.c_str ());
 	      else
 		error (_("Cannot find thread-local storage for %s, "
 		         "executable file %s:\n%s"),
 		       target_pid_to_str (ptid),
-		       objfile_name (objfile), ex.message);
+		       objfile_name (objfile), ex.message.c_str ());
 	      break;
 	    default:
 	      throw_exception (ex);
diff --git a/gdb/thread.c b/gdb/thread.c
index 6c232529646..5ec898838f0 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -1479,7 +1479,7 @@ thr_try_catch_cmd (thread_info *thr, const char *cmd, int from_tty,
 			     print_thread_id (thr),
 			     target_pid_to_str (inferior_ptid));
 	  if (flags.cont)
-	    printf_filtered ("%s\n", ex.message);
+	    printf_filtered ("%s\n", ex.message.c_str ());
 	  else
 	    throw_exception (ex);
 	}
diff --git a/gdb/unittests/cli-utils-selftests.c b/gdb/unittests/cli-utils-selftests.c
index dd4a7a0f0f9..1aaa6e2b00d 100644
--- a/gdb/unittests/cli-utils-selftests.c
+++ b/gdb/unittests/cli-utils-selftests.c
@@ -87,7 +87,7 @@ test_number_or_range_parser ()
       {
 	SELF_CHECK (ex.reason == RETURN_ERROR);
 	SELF_CHECK (ex.error == GENERIC_ERROR);
-	SELF_CHECK (strcmp (ex.message, "negative value") == 0);
+	SELF_CHECK (ex.message == "negative value");
 	SELF_CHECK (strcmp (minus_one.cur_tok (), "-1") == 0);
       }
     END_CATCH;
@@ -225,9 +225,9 @@ test_parse_flags_qcs ()
 	SELF_CHECK (ex.reason == RETURN_ERROR);
 	SELF_CHECK (ex.error == GENERIC_ERROR);
 	SELF_CHECK
-	  (strcmp (ex.message,
-		   "test_parse_flags_qcs.t4.cs: "
-		   "-c and -s are mutually exclusive") == 0);
+	  (ex.message
+	   == "test_parse_flags_qcs.t4.cs: "
+	   "-c and -s are mutually exclusive");
       }
     END_CATCH;
   }
diff --git a/gdb/value.c b/gdb/value.c
index 95b6a56f32e..9bbffbd9a9c 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -2544,7 +2544,7 @@ show_convenience (const char *ignore, int from_tty)
 	}
       CATCH (ex, RETURN_MASK_ERROR)
 	{
-	  fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message);
+	  fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.message.c_str ());
 	}
       END_CATCH
 
diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c
index fd15dc9b872..f1d63bf8bff 100644
--- a/gdb/x86-linux-nat.c
+++ b/gdb/x86-linux-nat.c
@@ -224,7 +224,7 @@ x86_linux_nat_target::enable_btrace (ptid_t ptid,
   CATCH (exception, RETURN_MASK_ERROR)
     {
       error (_("Could not enable branch tracing for %s: %s"),
-	     target_pid_to_str (ptid), exception.message);
+	     target_pid_to_str (ptid), exception.message.c_str ());
     }
   END_CATCH
 
diff --git a/gdb/xml-support.c b/gdb/xml-support.c
index 2b19a000471..a176a0a54fb 100644
--- a/gdb/xml-support.c
+++ b/gdb/xml-support.c
@@ -594,8 +594,8 @@ gdb_xml_parser::parse (const char *buffer)
   if (m_error.reason == RETURN_ERROR
       && m_error.error == XML_PARSE_ERROR)
     {
-      gdb_assert (m_error.message != NULL);
-      error_string = m_error.message;
+      gdb_assert (!m_error.message.empty ());
+      error_string = m_error.message.c_str ();
     }
   else if (status == XML_STATUS_ERROR)
     {
-- 
2.17.2

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

* [PATCH v2 13/22] Remove free_current_contents
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
                   ` (8 preceding siblings ...)
  2019-02-27 20:19 ` [PATCH v2 07/22] Remove last cleanups from solib-svr4.c Tom Tromey
@ 2019-02-27 20:19 ` Tom Tromey
  2019-03-06 21:34   ` Pedro Alves
  2019-02-27 20:19 ` [PATCH v2 19/22] Make exception throwing a bit more efficient Tom Tromey
                   ` (11 subsequent siblings)
  21 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

free_current_contents is no longer used, so this patch removes it.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* utils.h (free_current_contents): Don't declare.
	* utils.c (free_current_contents): Remove.
---
 gdb/ChangeLog |  5 +++++
 gdb/utils.c   | 29 -----------------------------
 gdb/utils.h   |  2 --
 3 files changed, 5 insertions(+), 31 deletions(-)

diff --git a/gdb/utils.c b/gdb/utils.c
index 60af31f2e4f..9334860a9a0 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -127,35 +127,6 @@ show_pagination_enabled (struct ui_file *file, int from_tty,
 }
 
 \f
-/* Cleanup utilities.
-
-   These are not defined in cleanups.c (nor declared in cleanups.h)
-   because while they use the "cleanup API" they are not part of the
-   "cleanup API".  */
-
-/* This function is useful for cleanups.
-   Do
-
-   foo = xmalloc (...);
-   old_chain = make_cleanup (free_current_contents, &foo);
-
-   to arrange to free the object thus allocated.  */
-
-void
-free_current_contents (void *ptr)
-{
-  void **location = (void **) ptr;
-
-  if (location == NULL)
-    internal_error (__FILE__, __LINE__,
-		    _("free_current_contents: NULL pointer"));
-  if (*location != NULL)
-    {
-      xfree (*location);
-      *location = NULL;
-    }
-}
-\f
 
 
 /* Print a warning message.  The first argument STRING is the warning
diff --git a/gdb/utils.h b/gdb/utils.h
index 896feb973c9..30cf02f16c4 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -260,8 +260,6 @@ struct htab_deleter
 /* A unique_ptr wrapper for htab_t.  */
 typedef std::unique_ptr<htab, htab_deleter> htab_up;
 
-extern void free_current_contents (void *);
-
 extern void init_page_info (void);
 
 /* Temporarily set BATCH_FLAG and the associated unlimited terminal size.
-- 
2.17.2

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

* [PATCH v2 22/22] Introduce and use bcache_up
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
                   ` (5 preceding siblings ...)
  2019-02-27 20:19 ` [PATCH v2 04/22] C++ify remote notification code Tom Tromey
@ 2019-02-27 20:19 ` Tom Tromey
  2019-03-06 22:03   ` Pedro Alves
  2019-02-27 20:19 ` [PATCH v2 02/22] Update two cleanup comments Tom Tromey
                   ` (14 subsequent siblings)
  21 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This introduces a new bcache_up typedef, which is a unique_ptr
specialization for managing a bcache.  Then, this changes various
spots to use this object, rather than manually calling bcache_xfree.
This lets us remove a try/catch that only existed to call
bcache_xfree.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* symmisc.c (print_symbol_bcache_statistics)
	(print_objfile_statistics): Update.
	* symfile.c (allocate_symtab): Update.
	* psymtab.c (allocate_psymtab): Update.
	* objfiles.h (struct objfile_per_bfd_storage) <filename_cache,
	macro_cache>: Change type to bcache_up.
	* objfiles.c (get_objfile_bfd_data): Update.
	(free_objfile_per_bfd_storage): Don't call bcache_xfree.
	* gdbtypes.c (types_deeply_equal): Use bcache_up.
	* elfread.c (elf_symtab_read): Update.
	* buildsym.c (buildsym_compunit::get_macro_table): Update.
	* bcache.h (struct bcache_deleter): New.
	(bcache_up): New typedef.
---
 gdb/ChangeLog  | 16 ++++++++++++++++
 gdb/bcache.h   | 12 ++++++++++++
 gdb/buildsym.c |  2 +-
 gdb/elfread.c  |  2 +-
 gdb/gdbtypes.c | 26 ++------------------------
 gdb/objfiles.c |  6 ++----
 gdb/objfiles.h |  6 +++---
 gdb/psymtab.c  |  2 +-
 gdb/symfile.c  |  2 +-
 gdb/symmisc.c  |  8 ++++----
 10 files changed, 43 insertions(+), 39 deletions(-)

diff --git a/gdb/bcache.h b/gdb/bcache.h
index aa0147926c6..9c1f71b6018 100644
--- a/gdb/bcache.h
+++ b/gdb/bcache.h
@@ -156,6 +156,18 @@ extern const void *bcache_full (const void *addr, int length,
 /* Free all the storage used by BCACHE.  */
 extern void bcache_xfree (struct bcache *bcache);
 
+/* A deleter that calls bcache_xfree.  */
+struct bcache_deleter
+{
+  void operator() (struct bcache *bcache)
+  {
+    bcache_xfree (bcache);
+  }
+};
+
+/* A unique pointer specialization for bcache.  */
+typedef std::unique_ptr<struct bcache, bcache_deleter> bcache_up;
+
 /* Create a new bcache object.  */
 extern struct bcache *bcache_xmalloc (
     unsigned long (*hash_function)(const void *, int length),
diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index bd0f25e061e..2b70d43e3a0 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -122,7 +122,7 @@ buildsym_compunit::get_macro_table ()
 {
   if (m_pending_macros == nullptr)
     m_pending_macros = new_macro_table (&m_objfile->per_bfd->storage_obstack,
-					m_objfile->per_bfd->macro_cache,
+					m_objfile->per_bfd->macro_cache.get (),
 					m_compunit_symtab);
   return m_pending_macros;
 }
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 8fc6692b112..2f274692348 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -335,7 +335,7 @@ elf_symtab_read (minimal_symbol_reader &reader,
 	{
 	  filesymname
 	    = (const char *) bcache (sym->name, strlen (sym->name) + 1,
-				     objfile->per_bfd->filename_cache);
+				     objfile->per_bfd->filename_cache.get ());
 	}
       else if (sym->flags & BSF_SECTION_SYM)
 	continue;
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 08c292457d2..defefeabb21 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -3748,9 +3748,6 @@ check_types_worklist (std::vector<type_equality_entry> *worklist,
 bool
 types_deeply_equal (struct type *type1, struct type *type2)
 {
-  struct gdb_exception except = exception_none;
-  bool result = false;
-  struct bcache *cache;
   std::vector<type_equality_entry> worklist;
 
   gdb_assert (type1 != NULL && type2 != NULL);
@@ -3759,30 +3756,11 @@ types_deeply_equal (struct type *type1, struct type *type2)
   if (type1 == type2)
     return true;
 
-  cache = bcache_xmalloc (NULL, NULL);
+  bcache_up cache (bcache_xmalloc (NULL, NULL));
 
   worklist.emplace_back (type1, type2);
 
-  /* check_types_worklist calls several nested helper functions, some
-     of which can raise a GDB exception, so we just check and rethrow
-     here.  If there is a GDB exception, a comparison is not capable
-     (or trusted), so exit.  */
-  try
-    {
-      result = check_types_worklist (&worklist, cache);
-    }
-  catch (const struct gdb_exception &ex)
-    {
-      except = ex;
-    }
-
-  bcache_xfree (cache);
-
-  /* Rethrow if there was a problem.  */
-  if (except.reason < 0)
-    throw_exception (except);
-
-  return result;
+  return check_types_worklist (&worklist, cache.get ());
 }
 
 /* Allocated status of type TYPE.  Return zero if type TYPE is allocated.
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 34b271e86de..47bb5a83538 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -157,8 +157,8 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
       if (abfd != NULL)
 	storage->gdbarch = gdbarch_from_bfd (abfd);
 
-      storage->filename_cache = bcache_xmalloc (NULL, NULL);
-      storage->macro_cache = bcache_xmalloc (NULL, NULL);
+      storage->filename_cache.reset (bcache_xmalloc (NULL, NULL));
+      storage->macro_cache.reset (bcache_xmalloc (NULL, NULL));
       storage->language_of_main = language_unknown;
     }
 
@@ -170,8 +170,6 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
 static void
 free_objfile_per_bfd_storage (struct objfile_per_bfd_storage *storage)
 {
-  bcache_xfree (storage->filename_cache);
-  bcache_xfree (storage->macro_cache);
   if (storage->demangled_names_hash)
     htab_delete (storage->demangled_names_hash);
   storage->~objfile_per_bfd_storage ();
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index a10781f598e..272fd6a6204 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -31,8 +31,8 @@
 #include <vector>
 #include "common/next-iterator.h"
 #include "common/safe-iterator.h"
+#include "bcache.h"
 
-struct bcache;
 struct htab;
 struct objfile_data;
 struct partial_symbol;
@@ -240,11 +240,11 @@ struct objfile_per_bfd_storage
 
   /* Byte cache for file names.  */
 
-  struct bcache *filename_cache = NULL;
+  bcache_up filename_cache;
 
   /* Byte cache for macros.  */
 
-  struct bcache *macro_cache = NULL;
+  bcache_up macro_cache;
 
   /* The gdbarch associated with the BFD.  Note that this gdbarch is
      determined solely from BFD information, without looking at target
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 17db29759c4..d6a5db47188 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1742,7 +1742,7 @@ allocate_psymtab (const char *filename, struct objfile *objfile)
 
   psymtab->filename
     = (const char *) bcache (filename, strlen (filename) + 1,
-			     objfile->per_bfd->filename_cache);
+			     objfile->per_bfd->filename_cache.get ());
   psymtab->compunit_symtab = NULL;
 
   if (symtab_create_debug)
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 61483824f63..7ea060c437c 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2796,7 +2796,7 @@ allocate_symtab (struct compunit_symtab *cust, const char *filename)
 
   symtab->filename
     = (const char *) bcache (filename, strlen (filename) + 1,
-			     objfile->per_bfd->filename_cache);
+			     objfile->per_bfd->filename_cache.get ());
   symtab->fullname = NULL;
   symtab->language = deduce_language_from_filename (filename);
 
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index 9025217a106..5967d19d16b 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -72,9 +72,9 @@ print_symbol_bcache_statistics (void)
 	print_bcache_statistics
 	  (psymbol_bcache_get_bcache (objfile->partial_symtabs->psymbol_cache),
 	   "partial symbol cache");
-	print_bcache_statistics (objfile->per_bfd->macro_cache,
+	print_bcache_statistics (objfile->per_bfd->macro_cache.get (),
 				 "preprocessor macro cache");
-	print_bcache_statistics (objfile->per_bfd->filename_cache,
+	print_bcache_statistics (objfile->per_bfd->filename_cache.get (),
 				 "file name cache");
       }
 }
@@ -139,9 +139,9 @@ print_objfile_statistics (void)
 	 bcache_memory_used (psymbol_bcache_get_bcache
 			     (objfile->partial_symtabs->psymbol_cache)));
       printf_filtered (_("  Total memory used for macro cache: %d\n"),
-		       bcache_memory_used (objfile->per_bfd->macro_cache));
+		       bcache_memory_used (objfile->per_bfd->macro_cache.get ()));
       printf_filtered (_("  Total memory used for file name cache: %d\n"),
-		       bcache_memory_used (objfile->per_bfd->filename_cache));
+		       bcache_memory_used (objfile->per_bfd->filename_cache.get ()));
     }
 }
 
-- 
2.17.2

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

* [PATCH v2 18/22] Remove some now-dead exception code
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
                   ` (16 preceding siblings ...)
  2019-02-27 20:19 ` [PATCH v2 14/22] Simplify exception handling Tom Tromey
@ 2019-02-27 20:19 ` Tom Tromey
  2019-04-03 17:04   ` Pedro Alves
  2019-02-27 20:19 ` [PATCH v2 06/22] Remove cleanup from solib-svr4.c Tom Tromey
                   ` (3 subsequent siblings)
  21 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

After the rewriting to use try/catch, some of the exception code is
now unused.  This patch removes that code.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* common/common-exceptions.h (exception_rethrow): Don't declare.
	(TRY_SJLJ): Update comment.
	(TRY, CATCH, END_CATCH): Remove.
	* common/common-exceptions.c (exception_rethrow): Remove.
---
 gdb/ChangeLog                  |  7 +++++
 gdb/common/common-exceptions.c | 10 -------
 gdb/common/common-exceptions.h | 53 ++++------------------------------
 3 files changed, 13 insertions(+), 57 deletions(-)

diff --git a/gdb/common/common-exceptions.c b/gdb/common/common-exceptions.c
index c2275fe6382..4feb80731ac 100644
--- a/gdb/common/common-exceptions.c
+++ b/gdb/common/common-exceptions.c
@@ -165,16 +165,6 @@ exceptions_state_mc_action_iter_1 (void)
   return exceptions_state_mc (CATCH_ITER_1);
 }
 
-/* Called by the default catch block.  IOW, we'll get here before
-   jumping out to the next outermost scope an exception if a GDB
-   exception is not caught.  */
-
-void
-exception_rethrow (void)
-{
-  throw;
-}
-
 /* Copy the 'gdb_exception' portion of FROM to TO.  */
 
 static void
diff --git a/gdb/common/common-exceptions.h b/gdb/common/common-exceptions.h
index e3ceb52553c..c6a8fa66ad6 100644
--- a/gdb/common/common-exceptions.h
+++ b/gdb/common/common-exceptions.h
@@ -125,10 +125,6 @@ extern int exceptions_state_mc_action_iter (void);
 extern int exceptions_state_mc_action_iter_1 (void);
 extern int exceptions_state_mc_catch (struct gdb_exception *, int);
 
-/* For the C++ try/catch-based TRY/CATCH mechanism.  */
-
-extern void exception_rethrow (void) ATTRIBUTE_NORETURN;
-
 /* Macro to wrap up standard try/catch behavior.
 
    The double loop lets us correctly handle code "break"ing out of the
@@ -140,24 +136,21 @@ extern void exception_rethrow (void) ATTRIBUTE_NORETURN;
 
    *INDENT-OFF*
 
-   TRY
+   TRY_SJLJ
      {
      }
-   CATCH (e, RETURN_MASK_ERROR)
+   CATCH_SJLJ (e, RETURN_MASK_ERROR)
      {
        switch (e.reason)
          {
            case RETURN_ERROR: ...
          }
      }
-   END_CATCH
+   END_CATCH_SJLJ
 
-  Note that the SJLJ version of the macros are actually named
-  TRY_SJLJ/CATCH_SJLJ in order to make it possible to call them even
-  when TRY/CATCH are mapped to C++ try/catch.  The SJLJ variants are
-  needed in some cases where gdb exceptions need to cross third-party
-  library code compiled without exceptions support (e.g.,
-  readline).  */
+   The SJLJ variants are needed in some cases where gdb exceptions
+   need to cross third-party library code compiled without exceptions
+   support (e.g., readline).  */
 
 #define TRY_SJLJ \
      { \
@@ -176,40 +169,6 @@ extern void exception_rethrow (void) ATTRIBUTE_NORETURN;
 #define END_CATCH_SJLJ				\
   }
 
-/* We still need to wrap TRY/CATCH in C++ so that cleanups and C++
-   exceptions can coexist.
-
-   The TRY blocked is wrapped in a do/while(0) so that break/continue
-   within the block works the same as in C.
-
-   END_CATCH makes sure that even if the CATCH block doesn't want to
-   catch the exception, we stop at every frame in the unwind chain to
-   run its cleanups, which may e.g., have pointers to stack variables
-   that are going to be destroyed.
-
-   There's an outer scope around the whole TRY/END_CATCH in order to
-   cause a compilation error if you forget to add the END_CATCH at the
-   end a TRY/CATCH construct.  */
-
-#define TRY								\
-  {									\
-    try									\
-      {									\
-	do								\
-	  {
-
-#define CATCH(EXCEPTION, MASK)						\
-	  } while (0);							\
-	}								\
-    catch (struct gdb_exception ## _ ## MASK &EXCEPTION)
-
-#define END_CATCH				\
-    catch (...)					\
-      {						\
-	exception_rethrow ();			\
-      }						\
-  }
-
 /* The exception types client code may catch.  They're just shims
    around gdb_exception that add nothing but type info.  Which is used
    is selected depending on the MASK argument passed to CATCH.  */
-- 
2.17.2

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

* [PATCH v2 03/22] Change displaced_step_clear_cleanup with a forward_scope_exit
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
                   ` (10 preceding siblings ...)
  2019-02-27 20:19 ` [PATCH v2 19/22] Make exception throwing a bit more efficient Tom Tromey
@ 2019-02-27 20:19 ` Tom Tromey
  2019-03-06 19:23   ` Pedro Alves
  2019-02-27 20:19 ` [PATCH v2 15/22] Make exceptions use std::string and be self-managing Tom Tromey
                   ` (9 subsequent siblings)
  21 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes displaced_step_clear_cleanup to be a forward_scope_exit
and updates the callers.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* infrun.c (displaced_step_clear_cleanup): Now a
	forward_scope_exit type.
	(displaced_step_prepare_throw): Update.
	(displaced_step_fixup): Update.
---
 gdb/ChangeLog |  7 +++++++
 gdb/infrun.c  | 30 +++++++++++-------------------
 2 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/gdb/infrun.c b/gdb/infrun.c
index b32635fc422..582c1f77008 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -68,6 +68,7 @@
 #include "common/gdb_optional.h"
 #include "arch-utils.h"
 #include "common/scope-exit.h"
+#include "common/forward-scope-exit.h"
 
 /* Prototypes for local functions */
 
@@ -1598,14 +1599,9 @@ displaced_step_clear (struct displaced_step_inferior_state *displaced)
   displaced->step_closure = NULL;
 }
 
-static void
-displaced_step_clear_cleanup (void *arg)
-{
-  struct displaced_step_inferior_state *state
-    = (struct displaced_step_inferior_state *) arg;
-
-  displaced_step_clear (state);
-}
+/* A cleanup that wraps displaced_step_clear.  */
+using displaced_step_clear_cleanup
+    = FORWARD_SCOPE_EXIT (displaced_step_clear);
 
 /* Dump LEN bytes at BUF in hex to FILE, followed by a newline.  */
 void
@@ -1754,13 +1750,14 @@ displaced_step_prepare_throw (thread_info *tp)
   displaced->step_original = original;
   displaced->step_copy = copy;
 
-  cleanup *ignore_cleanups
-    = make_cleanup (displaced_step_clear_cleanup, displaced);
+  {
+    displaced_step_clear_cleanup cleanup (displaced);
 
-  /* Resume execution at the copy.  */
-  regcache_write_pc (regcache, copy);
+    /* Resume execution at the copy.  */
+    regcache_write_pc (regcache, copy);
 
-  discard_cleanups (ignore_cleanups);
+    cleanup.release ();
+  }
 
   if (debug_displaced)
     fprintf_unfiltered (gdb_stdlog, "displaced: displaced pc to %s\n",
@@ -1850,7 +1847,6 @@ displaced_step_restore (struct displaced_step_inferior_state *displaced,
 static int
 displaced_step_fixup (thread_info *event_thread, enum gdb_signal signal)
 {
-  struct cleanup *old_cleanups;
   struct displaced_step_inferior_state *displaced
     = get_displaced_stepping_state (event_thread->inf);
   int ret;
@@ -1859,7 +1855,7 @@ displaced_step_fixup (thread_info *event_thread, enum gdb_signal signal)
   if (displaced->step_thread != event_thread)
     return 0;
 
-  old_cleanups = make_cleanup (displaced_step_clear_cleanup, displaced);
+  displaced_step_clear_cleanup cleanup (displaced);
 
   displaced_step_restore (displaced, displaced->step_thread->ptid);
 
@@ -1894,10 +1890,6 @@ displaced_step_fixup (thread_info *event_thread, enum gdb_signal signal)
       ret = -1;
     }
 
-  do_cleanups (old_cleanups);
-
-  displaced->step_thread = nullptr;
-
   return ret;
 }
 
-- 
2.17.2

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

* [PATCH v2 10/22] Remove last cleanups from stabsread.c
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
                   ` (18 preceding siblings ...)
  2019-02-27 20:19 ` [PATCH v2 06/22] Remove cleanup from solib-svr4.c Tom Tromey
@ 2019-02-27 20:19 ` Tom Tromey
  2019-03-06 21:14   ` Pedro Alves
  2019-02-27 20:19 ` [PATCH v2 12/22] Remove basic cleanup code Tom Tromey
  2019-02-27 20:19 ` [PATCH v2 21/22] Use SCOPE_EXIT in write_gcore_file Tom Tromey
  21 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes the last cleanups from stabsread.c.  Similar code in
dwarf2read.c was C++-ified, but considering that stabs are deprecated,
it seemed simpler to just change these allocations to use an obstack
and leave the data structures in place.

This patch renames field_info to stabs_field_info -- adding a
constructor here provoked a bug due to the resulting ODR violation.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* stabsread.c (struct stabs_field_info): Rename from field_info.
	<list, fnlist>: Add initializers.
	<obstack>: New member.
	(read_member_functions, read_struct_fields, read_baseclasses):
	Allocate on obstack.  Don't use cleanups.
	(read_one_struct_field, read_member_functions, read_struct_fields)
	(read_baseclasses, read_tilde_fields, attach_fn_fields_to_type)
	(attach_fields_to_type, read_cpp_abbrev, read_member_functions)
	(read_struct_type): Update.
---
 gdb/ChangeLog   | 12 ++++++++
 gdb/stabsread.c | 81 +++++++++++++++++++++----------------------------
 2 files changed, 47 insertions(+), 46 deletions(-)

diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index fc3db8f19b4..ac33465c13b 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -85,14 +85,16 @@ struct next_fnfieldlist
    This is part of some reorganization of low level C++ support and is
    expected to eventually go away...  (FIXME) */
 
-struct field_info
+struct stab_field_info
   {
-    struct nextfield *list;
-    struct next_fnfieldlist *fnlist;
+    struct nextfield *list = nullptr;
+    struct next_fnfieldlist *fnlist = nullptr;
+
+    auto_obstack obstack;
   };
 
 static void
-read_one_struct_field (struct field_info *, const char **, const char *,
+read_one_struct_field (struct stab_field_info *, const char **, const char *,
 		       struct type *, struct objfile *);
 
 static struct type *dbx_alloc_type (int[2], struct objfile *);
@@ -125,24 +127,24 @@ static struct type *read_enum_type (const char **, struct type *, struct objfile
 static struct type *rs6000_builtin_type (int, struct objfile *);
 
 static int
-read_member_functions (struct field_info *, const char **, struct type *,
+read_member_functions (struct stab_field_info *, const char **, struct type *,
 		       struct objfile *);
 
 static int
-read_struct_fields (struct field_info *, const char **, struct type *,
+read_struct_fields (struct stab_field_info *, const char **, struct type *,
 		    struct objfile *);
 
 static int
-read_baseclasses (struct field_info *, const char **, struct type *,
+read_baseclasses (struct stab_field_info *, const char **, struct type *,
 		  struct objfile *);
 
 static int
-read_tilde_fields (struct field_info *, const char **, struct type *,
+read_tilde_fields (struct stab_field_info *, const char **, struct type *,
 		   struct objfile *);
 
-static int attach_fn_fields_to_type (struct field_info *, struct type *);
+static int attach_fn_fields_to_type (struct stab_field_info *, struct type *);
 
-static int attach_fields_to_type (struct field_info *, struct type *,
+static int attach_fields_to_type (struct stab_field_info *, struct type *,
 				  struct objfile *);
 
 static struct type *read_struct_type (const char **, struct type *,
@@ -158,7 +160,7 @@ static struct field *read_args (const char **, int, struct objfile *,
 static void add_undefined_type (struct type *, int[2]);
 
 static int
-read_cpp_abbrev (struct field_info *, const char **, struct type *,
+read_cpp_abbrev (struct stab_field_info *, const char **, struct type *,
 		 struct objfile *);
 
 static const char *find_name_end (const char *name);
@@ -2277,7 +2279,7 @@ stabs_method_name_from_physname (const char *physname)
    Returns 1 for success, 0 for failure.  */
 
 static int
-read_member_functions (struct field_info *fip, const char **pp,
+read_member_functions (struct stab_field_info *fip, const char **pp,
 		       struct type *type, struct objfile *objfile)
 {
   int nfn_fields = 0;
@@ -2317,8 +2319,7 @@ read_member_functions (struct field_info *fip, const char **pp,
       look_ahead_type = NULL;
       length = 0;
 
-      new_fnlist = XCNEW (struct next_fnfieldlist);
-      make_cleanup (xfree, new_fnlist);
+      new_fnlist = OBSTACK_ZALLOC (&fip->obstack, struct next_fnfieldlist);
 
       if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2]))
 	{
@@ -2357,8 +2358,7 @@ read_member_functions (struct field_info *fip, const char **pp,
 
       do
 	{
-	  new_sublist = XCNEW (struct next_fnfield);
-	  make_cleanup (xfree, new_sublist);
+	  new_sublist = OBSTACK_ZALLOC (&fip->obstack, struct next_fnfield);
 
 	  /* Check for and handle cretinous dbx symbol name continuation!  */
 	  if (look_ahead_type == NULL)
@@ -2642,8 +2642,8 @@ read_member_functions (struct field_info *fip, const char **pp,
 
 	      /* Create a new fn_fieldlist for the destructors.  */
 
-	      destr_fnlist = XCNEW (struct next_fnfieldlist);
-	      make_cleanup (xfree, destr_fnlist);
+	      destr_fnlist = OBSTACK_ZALLOC (&fip->obstack,
+					     struct next_fnfieldlist);
 
 	      destr_fnlist->fn_fieldlist.name
 		= obconcat (&objfile->objfile_obstack, "~",
@@ -2743,8 +2743,8 @@ read_member_functions (struct field_info *fip, const char **pp,
    keep parsing and it's time for error_type().  */
 
 static int
-read_cpp_abbrev (struct field_info *fip, const char **pp, struct type *type,
-		 struct objfile *objfile)
+read_cpp_abbrev (struct stab_field_info *fip, const char **pp,
+		 struct type *type, struct objfile *objfile)
 {
   const char *p;
   const char *name;
@@ -2838,8 +2838,9 @@ read_cpp_abbrev (struct field_info *fip, const char **pp, struct type *type,
 }
 
 static void
-read_one_struct_field (struct field_info *fip, const char **pp, const char *p,
-		       struct type *type, struct objfile *objfile)
+read_one_struct_field (struct stab_field_info *fip, const char **pp,
+		       const char *p, struct type *type,
+		       struct objfile *objfile)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
 
@@ -2981,8 +2982,8 @@ read_one_struct_field (struct field_info *fip, const char **pp, const char *p,
    Returns 1 for success, 0 for failure.  */
 
 static int
-read_struct_fields (struct field_info *fip, const char **pp, struct type *type,
-		    struct objfile *objfile)
+read_struct_fields (struct stab_field_info *fip, const char **pp,
+		    struct type *type, struct objfile *objfile)
 {
   const char *p;
   struct nextfield *newobj;
@@ -3001,8 +3002,7 @@ read_struct_fields (struct field_info *fip, const char **pp, struct type *type,
     {
       STABS_CONTINUE (pp, objfile);
       /* Get space to record the next field's data.  */
-      newobj = XCNEW (struct nextfield);
-      make_cleanup (xfree, newobj);
+      newobj = OBSTACK_ZALLOC (&fip->obstack, struct nextfield);
 
       newobj->next = fip->list;
       fip->list = newobj;
@@ -3079,8 +3079,8 @@ read_struct_fields (struct field_info *fip, const char **pp, struct type *type,
 
 
 static int
-read_baseclasses (struct field_info *fip, const char **pp, struct type *type,
-		  struct objfile *objfile)
+read_baseclasses (struct stab_field_info *fip, const char **pp,
+		  struct type *type, struct objfile *objfile)
 {
   int i;
   struct nextfield *newobj;
@@ -3123,8 +3123,7 @@ read_baseclasses (struct field_info *fip, const char **pp, struct type *type,
 
   for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
     {
-      newobj = XCNEW (struct nextfield);
-      make_cleanup (xfree, newobj);
+      newobj = OBSTACK_ZALLOC (&fip->obstack, struct nextfield);
 
       newobj->next = fip->list;
       fip->list = newobj;
@@ -3203,8 +3202,8 @@ read_baseclasses (struct field_info *fip, const char **pp, struct type *type,
    so we can look for the vptr base class info.  */
 
 static int
-read_tilde_fields (struct field_info *fip, const char **pp, struct type *type,
-		   struct objfile *objfile)
+read_tilde_fields (struct stab_field_info *fip, const char **pp,
+		   struct type *type, struct objfile *objfile)
 {
   const char *p;
 
@@ -3286,7 +3285,7 @@ read_tilde_fields (struct field_info *fip, const char **pp, struct type *type,
 }
 
 static int
-attach_fn_fields_to_type (struct field_info *fip, struct type *type)
+attach_fn_fields_to_type (struct stab_field_info *fip, struct type *type)
 {
   int n;
 
@@ -3305,7 +3304,7 @@ attach_fn_fields_to_type (struct field_info *fip, struct type *type)
    for this class's virtual functions.  */
 
 static int
-attach_fields_to_type (struct field_info *fip, struct type *type,
+attach_fields_to_type (struct stab_field_info *fip, struct type *type,
 		       struct objfile *objfile)
 {
   int nfields = 0;
@@ -3474,11 +3473,7 @@ static struct type *
 read_struct_type (const char **pp, struct type *type, enum type_code type_code,
                   struct objfile *objfile)
 {
-  struct cleanup *back_to;
-  struct field_info fi;
-
-  fi.list = NULL;
-  fi.fnlist = NULL;
+  struct stab_field_info fi;
 
   /* When describing struct/union/class types in stabs, G++ always drops
      all qualifications from the name.  So if you've got:
@@ -3500,8 +3495,6 @@ read_struct_type (const char **pp, struct type *type, enum type_code type_code,
       return type;
     }
 
-  back_to = make_cleanup (null_cleanup, 0);
-
   INIT_CPLUS_SPECIFIC (type);
   TYPE_CODE (type) = type_code;
   TYPE_STUB (type) = 0;
@@ -3513,10 +3506,7 @@ read_struct_type (const char **pp, struct type *type, enum type_code type_code,
 
     TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits, 0);
     if (nbits != 0)
-      {
-	do_cleanups (back_to);
-	return error_type (pp, objfile);
-      }
+      return error_type (pp, objfile);
     set_length_in_type_chain (type);
   }
 
@@ -3535,7 +3525,6 @@ read_struct_type (const char **pp, struct type *type, enum type_code type_code,
       type = error_type (pp, objfile);
     }
 
-  do_cleanups (back_to);
   return (type);
 }
 
-- 
2.17.2

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

* [PATCH v2 04/22] C++ify remote notification code
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
                   ` (4 preceding siblings ...)
  2019-02-27 20:19 ` [PATCH v2 16/22] Rewrite TRY/CATCH Tom Tromey
@ 2019-02-27 20:19 ` Tom Tromey
  2019-03-06 19:23   ` Pedro Alves
  2019-02-27 20:19 ` [PATCH v2 22/22] Introduce and use bcache_up Tom Tromey
                   ` (15 subsequent siblings)
  21 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This C++ifies the remote notification code -- replacing function
pointers with virtual methods and using unique_ptr.  This allows for
the removal of some cleanups.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* remote.c (struct stop_reply_deleter): Remove.
	(stop_reply_up): Update.
	(struct stop_reply): Derive from notif_event.  Don't typedef.
	<regcache>: Now a std::vector.
	(stop_reply_xfree): Remove.
	(stop_reply::~stop_reply): Rename from stop_reply_dtr.
	(remote_notif_stop_alloc_reply): Return a unique_ptr.  Use new.
	(remote_target::discard_pending_stop_replies): Use delete.
	(remote_target::remote_parse_stop_reply): Update.
	(remote_target::process_stop_reply): Update.
	* remote-notif.h (struct notif_event): Add virtual destructor.
	Remove "dtr" member.
	(struct notif_client) <alloc_event>: Return a unique_ptr.
	(notif_event_xfree): Don't declare.
	* remote-notif.c (remote_notif_ack, remote_notif_parse): Update.
	(notif_event_xfree, do_notif_event_xfree): Remove.
	(remote_notif_state_xfree): Update.
---
 gdb/ChangeLog      | 20 ++++++++++++
 gdb/remote-notif.c | 42 ++++--------------------
 gdb/remote-notif.h | 11 +++----
 gdb/remote.c       | 80 +++++++++++++---------------------------------
 4 files changed, 54 insertions(+), 99 deletions(-)

diff --git a/gdb/remote-notif.c b/gdb/remote-notif.c
index ae9a94d9c94..5a70ca128d5 100644
--- a/gdb/remote-notif.c
+++ b/gdb/remote-notif.c
@@ -52,8 +52,6 @@ static struct notif_client *notifs[] =
 
 gdb_static_assert (ARRAY_SIZE (notifs) == REMOTE_NOTIF_LAST);
 
-static void do_notif_event_xfree (void *arg);
-
 /* Parse the BUF for the expected notification NC, and send packet to
    acknowledge.  */
 
@@ -61,18 +59,14 @@ void
 remote_notif_ack (remote_target *remote,
 		  struct notif_client *nc, const char *buf)
 {
-  struct notif_event *event = nc->alloc_event ();
-  struct cleanup *old_chain
-    = make_cleanup (do_notif_event_xfree, event);
+  std::unique_ptr<struct notif_event> event = nc->alloc_event ();
 
   if (notif_debug)
     fprintf_unfiltered (gdb_stdlog, "notif: ack '%s'\n",
 			nc->ack_command);
 
-  nc->parse (remote, nc, buf, event);
-  nc->ack (remote, nc, buf, event);
-
-  discard_cleanups (old_chain);
+  nc->parse (remote, nc, buf, event.get ());
+  nc->ack (remote, nc, buf, event.release ());
 }
 
 /* Parse the BUF for the expected notification NC.  */
@@ -81,17 +75,14 @@ struct notif_event *
 remote_notif_parse (remote_target *remote,
 		    struct notif_client *nc, const char *buf)
 {
-  struct notif_event *event = nc->alloc_event ();
-  struct cleanup *old_chain
-    = make_cleanup (do_notif_event_xfree, event);
+  std::unique_ptr<struct notif_event> event = nc->alloc_event ();
 
   if (notif_debug)
     fprintf_unfiltered (gdb_stdlog, "notif: parse '%s'\n", nc->name);
 
-  nc->parse (remote, nc, buf, event);
+  nc->parse (remote, nc, buf, event.get ());
 
-  discard_cleanups (old_chain);
-  return event;
+  return event.release ();
 }
 
 DEFINE_QUEUE_P (notif_client_p);
@@ -216,25 +207,6 @@ handle_notification (struct remote_notif_state *state, const char *buf)
     }
 }
 
-/* Invoke destructor of EVENT and xfree it.  */
-
-void
-notif_event_xfree (struct notif_event *event)
-{
-  if (event != NULL && event->dtr != NULL)
-    event->dtr (event);
-
-  xfree (event);
-}
-
-/* Cleanup wrapper.  */
-
-static void
-do_notif_event_xfree (void *arg)
-{
-  notif_event_xfree ((struct notif_event *) arg);
-}
-
 /* Return an allocated remote_notif_state.  */
 
 struct remote_notif_state *
@@ -269,7 +241,7 @@ remote_notif_state_xfree (struct remote_notif_state *state)
     delete_async_event_handler (&state->get_pending_events_token);
 
   for (i = 0; i < REMOTE_NOTIF_LAST; i++)
-    notif_event_xfree (state->pending_event[i]);
+    delete state->pending_event[i];
 
   xfree (state);
 }
diff --git a/gdb/remote-notif.h b/gdb/remote-notif.h
index d7663274a4a..cb698626cec 100644
--- a/gdb/remote-notif.h
+++ b/gdb/remote-notif.h
@@ -20,15 +20,16 @@
 #ifndef REMOTE_NOTIF_H
 #define REMOTE_NOTIF_H
 
+#include <memory>
 #include "common/queue.h"
 
 /* An event of a type of async remote notification.  */
 
 struct notif_event
 {
-  /* Destructor.  Release everything from SELF, but not SELF
-     itself.  */
-  void (*dtr) (struct notif_event *self);
+  virtual ~notif_event ()
+  {
+  }
 };
 
 /* ID of the notif_client.  */
@@ -70,7 +71,7 @@ typedef struct notif_client
 				 struct notif_client *self);
 
   /* Allocate an event.  */
-  struct notif_event *(*alloc_event) (void);
+  std::unique_ptr<struct notif_event> (*alloc_event) ();
 
   /* Id of this notif_client.  */
   const enum REMOTE_NOTIF_ID id;
@@ -112,8 +113,6 @@ struct notif_event *remote_notif_parse (remote_target *remote,
 					notif_client *nc,
 					const char *buf);
 
-void notif_event_xfree (struct notif_event *event);
-
 void handle_notification (struct remote_notif_state *notif_state,
 			  const char *buf);
 
diff --git a/gdb/remote.c b/gdb/remote.c
index 36136e3e3ee..f80dcdaee94 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -96,17 +96,7 @@ struct protocol_feature;
 struct packet_reg;
 
 struct stop_reply;
-static void stop_reply_xfree (struct stop_reply *);
-
-struct stop_reply_deleter
-{
-  void operator() (stop_reply *r) const
-  {
-    stop_reply_xfree (r);
-  }
-};
-
-typedef std::unique_ptr<stop_reply, stop_reply_deleter> stop_reply_up;
+typedef std::unique_ptr<struct stop_reply> stop_reply_up;
 
 /* Generic configuration support for packets the stub optionally
    supports.  Allows the user to specify the use of the packet as well
@@ -6815,11 +6805,9 @@ remote_console_output (const char *msg)
   gdb_flush (gdb_stdtarg);
 }
 
-DEF_VEC_O(cached_reg_t);
-
-typedef struct stop_reply
+struct stop_reply : public notif_event
 {
-  struct notif_event base;
+  ~stop_reply ();
 
   /* The identifier of the thread about this event  */
   ptid_t ptid;
@@ -6838,20 +6826,14 @@ typedef struct stop_reply
      efficient for those targets that provide critical registers as
      part of their normal status mechanism (as another roundtrip to
      fetch them is avoided).  */
-  VEC(cached_reg_t) *regcache;
+  std::vector<cached_reg_t> regcache;
 
   enum target_stop_reason stop_reason;
 
   CORE_ADDR watch_data_address;
 
   int core;
-} *stop_reply_p;
-
-static void
-stop_reply_xfree (struct stop_reply *r)
-{
-  notif_event_xfree ((struct notif_event *) r);
-}
+};
 
 /* Return the length of the stop reply queue.  */
 
@@ -6903,30 +6885,16 @@ remote_notif_stop_can_get_pending_events (remote_target *remote,
   return 0;
 }
 
-static void
-stop_reply_dtr (struct notif_event *event)
+stop_reply::~stop_reply ()
 {
-  struct stop_reply *r = (struct stop_reply *) event;
-  cached_reg_t *reg;
-  int ix;
-
-  for (ix = 0;
-       VEC_iterate (cached_reg_t, r->regcache, ix, reg);
-       ix++)
-    xfree (reg->data);
-
-  VEC_free (cached_reg_t, r->regcache);
+  for (cached_reg_t &reg : regcache)
+    xfree (reg.data);
 }
 
-static struct notif_event *
-remote_notif_stop_alloc_reply (void)
+static std::unique_ptr<struct notif_event>
+remote_notif_stop_alloc_reply ()
 {
-  /* We cast to a pointer to the "base class".  */
-  struct notif_event *r = (struct notif_event *) XNEW (struct stop_reply);
-
-  r->dtr = stop_reply_dtr;
-
-  return r;
+  return std::unique_ptr<struct notif_event> (new struct stop_reply ());
 }
 
 /* A client of notification Stop.  */
@@ -7069,7 +7037,7 @@ remote_target::discard_pending_stop_replies (struct inferior *inf)
   /* Discard the in-flight notification.  */
   if (reply != NULL && reply->ptid.pid () == inf->pid)
     {
-      stop_reply_xfree (reply);
+      delete reply;
       rns->pending_event[notif_client_stop.id] = NULL;
     }
 
@@ -7213,7 +7181,7 @@ remote_target::remote_parse_stop_reply (const char *buf, stop_reply *event)
   event->ws.kind = TARGET_WAITKIND_IGNORE;
   event->ws.value.integer = 0;
   event->stop_reason = TARGET_STOPPED_BY_NO_REASON;
-  event->regcache = NULL;
+  event->regcache.clear ();
   event->core = -1;
 
   switch (buf[0])
@@ -7449,7 +7417,7 @@ Packet: '%s'\n"),
 		  if (fieldsize < register_size (event->arch, reg->regnum))
 		    warning (_("Remote reply is too short: %s"), buf);
 
-		  VEC_safe_push (cached_reg_t, event->regcache, &cached_reg);
+		  event->regcache.push_back (cached_reg);
 		}
 	      else
 		{
@@ -7665,22 +7633,18 @@ remote_target::process_stop_reply (struct stop_reply *stop_reply,
       && status->kind != TARGET_WAITKIND_NO_RESUMED)
     {
       /* Expedited registers.  */
-      if (stop_reply->regcache)
+      if (!stop_reply->regcache.empty ())
 	{
 	  struct regcache *regcache
 	    = get_thread_arch_regcache (ptid, stop_reply->arch);
-	  cached_reg_t *reg;
-	  int ix;
 
-	  for (ix = 0;
-	       VEC_iterate (cached_reg_t, stop_reply->regcache, ix, reg);
-	       ix++)
-	  {
-	    regcache->raw_supply (reg->num, reg->data);
-	    xfree (reg->data);
-	  }
+	  for (cached_reg_t &reg : stop_reply->regcache)
+	    {
+	      regcache->raw_supply (reg.num, reg.data);
+	      xfree (reg.data);
+	    }
 
-	  VEC_free (cached_reg_t, stop_reply->regcache);
+	  stop_reply->regcache.clear ();
 	}
 
       remote_notice_new_inferior (ptid, 0);
@@ -7691,7 +7655,7 @@ remote_target::process_stop_reply (struct stop_reply *stop_reply,
       remote_thr->vcont_resumed = 0;
     }
 
-  stop_reply_xfree (stop_reply);
+  delete stop_reply;
   return ptid;
 }
 
-- 
2.17.2

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

* [PATCH v2 19/22] Make exception throwing a bit more efficient
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
                   ` (9 preceding siblings ...)
  2019-02-27 20:19 ` [PATCH v2 13/22] Remove free_current_contents Tom Tromey
@ 2019-02-27 20:19 ` Tom Tromey
  2019-04-03 17:04   ` Pedro Alves
  2019-02-27 20:19 ` [PATCH v2 03/22] Change displaced_step_clear_cleanup with a forward_scope_exit Tom Tromey
                   ` (10 subsequent siblings)
  21 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This makes exception throwing a bit more efficient, by removing some
copies.  This is good now that exceptions are more expensive to copy.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* common/common-exceptions.c (throw_exception): Rename from
	throw_exception_cxx.  Remove old copy.  Make argument const.
	(throw_it): Create and throw exception objects directly.
	* common/common-exceptions.h (throw_exception): Make argument
	const.
---
 gdb/ChangeLog                  |  8 ++++++++
 gdb/common/common-exceptions.c | 37 ++++++++++++++++++++--------------
 gdb/common/common-exceptions.h |  2 +-
 3 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/gdb/common/common-exceptions.c b/gdb/common/common-exceptions.c
index 4feb80731ac..99a6267c163 100644
--- a/gdb/common/common-exceptions.c
+++ b/gdb/common/common-exceptions.c
@@ -188,8 +188,8 @@ throw_exception_sjlj (struct gdb_exception exception)
 
 /* Implementation of throw_exception that uses C++ try/catch.  */
 
-static ATTRIBUTE_NORETURN void
-throw_exception_cxx (struct gdb_exception exception)
+void
+throw_exception (const struct gdb_exception &exception)
 {
   if (exception.reason == RETURN_QUIT)
     {
@@ -209,25 +209,32 @@ throw_exception_cxx (struct gdb_exception exception)
     gdb_assert_not_reached ("invalid return reason");
 }
 
-void
-throw_exception (struct gdb_exception exception)
-{
-  throw_exception_cxx (exception);
-}
-
 static void ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (3, 0)
 throw_it (enum return_reason reason, enum errors error, const char *fmt,
 	  va_list ap)
 {
-  struct gdb_exception e;
+  if (reason == RETURN_QUIT)
+    {
+      gdb_exception_quit ex;
 
-  /* Create the exception.  */
-  e.reason = reason;
-  e.error = error;
-  e.message = string_vprintf (fmt, ap);
+      ex.reason = reason;
+      ex.error = error;
+      ex.message = string_vprintf (fmt, ap);
 
-  /* Throw the exception.  */
-  throw_exception (e);
+      throw ex;
+    }
+  else if (reason == RETURN_ERROR)
+    {
+      gdb_exception_error ex;
+
+      ex.reason = reason;
+      ex.error = error;
+      ex.message = string_vprintf (fmt, ap);
+
+      throw ex;
+    }
+  else
+    gdb_assert_not_reached ("invalid return reason");
 }
 
 void
diff --git a/gdb/common/common-exceptions.h b/gdb/common/common-exceptions.h
index c6a8fa66ad6..9d83cad6bec 100644
--- a/gdb/common/common-exceptions.h
+++ b/gdb/common/common-exceptions.h
@@ -205,7 +205,7 @@ struct gdb_quit_bad_alloc
 /* Throw an exception (as described by "struct gdb_exception"),
    landing in the inner most containing exception handler established
    using TRY/CATCH.  */
-extern void throw_exception (struct gdb_exception exception)
+extern void throw_exception (const struct gdb_exception &exception)
      ATTRIBUTE_NORETURN;
 
 /* Throw an exception by executing a LONG JUMP to the inner most
-- 
2.17.2

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

* [PATCH v2 01/22] Remove cleanups from coffread.c
  2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
  2019-02-27 20:18 ` [PATCH v2 08/22] Remove last cleanup solib-aix.c Tom Tromey
  2019-02-27 20:18 ` [PATCH v2 05/22] Remove last cleanup from gdbserver Tom Tromey
@ 2019-02-27 20:19 ` Tom Tromey
  2019-03-06 19:23   ` Pedro Alves
  2019-02-27 20:19 ` [PATCH v2 09/22] Remove last cleanup from linux-namespaces.c Tom Tromey
                   ` (18 subsequent siblings)
  21 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-02-27 20:19 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes the remaining cleanups from coffread.c.

Tested by the buildbot.  However, I don't think the buildbot really
tests these code paths, and TBH I am not sure how to do it manually.
I did manage to crash an earlier version of the patch using a mingw
.exe file, though I would have thought that was only going to test
coff-pe-read.c.

This version includes the fix provided by Joel.

gdb/ChangeLog
2019-02-27  Joel Brobecker  <brobecker@adacore.com>
	    Tom Tromey  <tom@tromey.com>

	* stabsread.h (struct stab_section_list): Remove.
	(coffstab_build_psymtabs): Update.
	* dbxread.c (symbuf_sections): Now a std::vector.
	(sect_idx): New global.
	(fill_symbuf): Update.
	(coffstab_build_psymtabs): Change type of stabsects parameter.
	Update.
	* coffread.c (struct coff_symfile_info) <stabsects>: Now a
	std::vector.
	(linetab, linetab_offset, linetab_size, stringtab): Move earlier.
	(coff_locate_sections): Update.
	(coff_symfile_read): Remove cleanups.  Update.
	(init_stringtab): Add storage parameter.
	(free_stringtab, free_stringtab_cleanup): Remove.
	(init_lineno): Add storage parameter.
	(free_linetab, free_linetab_cleanup): Remove.
---
 gdb/ChangeLog   |  20 +++++++++
 gdb/coffread.c  | 115 ++++++++++++++----------------------------------
 gdb/dbxread.c   |  32 +++++++-------
 gdb/stabsread.h |  14 +-----
 4 files changed, 72 insertions(+), 109 deletions(-)

diff --git a/gdb/coffread.c b/gdb/coffread.c
index 6381cd3f370..4fbeece5fb7 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -58,7 +58,7 @@ struct coff_symfile_info
 
     CORE_ADDR textaddr;		/* Addr of .text section.  */
     unsigned int textsize;	/* Size of .text section.  */
-    struct stab_section_list *stabsects;	/* .stab sections.  */
+    std::vector<asection *> *stabsects;	/* .stab sections.  */
     asection *stabstrsect;	/* Section pointer for .stab section.  */
     char *stabstrdata;
   };
@@ -155,6 +155,12 @@ static int type_vector_length;
 
 #define INITIAL_TYPE_VECTOR_LENGTH 160
 
+static char *linetab = NULL;
+static long linetab_offset;
+static unsigned long linetab_size;
+
+static char *stringtab = NULL;
+
 extern void stabsread_clear_cache (void);
 
 static struct type *coff_read_struct_type (int, int, int,
@@ -185,21 +191,13 @@ static void patch_opaque_types (struct symtab *);
 
 static void enter_linenos (long, int, int, struct objfile *);
 
-static void free_linetab (void);
-
-static void free_linetab_cleanup (void *ignore);
-
-static int init_lineno (bfd *, long, int);
+static int init_lineno (bfd *, long, int, gdb::unique_xmalloc_ptr<char> *);
 
 static char *getsymname (struct internal_syment *);
 
 static const char *coff_getfilename (union internal_auxent *);
 
-static void free_stringtab (void);
-
-static void free_stringtab_cleanup (void *ignore);
-
-static int init_stringtab (bfd *, long);
+static int init_stringtab (bfd *, long, gdb::unique_xmalloc_ptr<char> *);
 
 static void read_one_sym (struct coff_symbol *,
 			  struct internal_syment *,
@@ -249,21 +247,7 @@ coff_locate_sections (bfd *abfd, asection *sectp, void *csip)
 	if (!isdigit (*s))
 	  break;
       if (*s == '\0')
-	{
-	  struct stab_section_list *n, **pn;
-
-	  n = XNEW (struct stab_section_list);
-	  n->section = sectp;
-	  n->next = NULL;
-	  for (pn = &csi->stabsects; *pn != NULL; pn = &(*pn)->next)
-	    ;
-	  *pn = n;
-
-	  /* This will be run after coffstab_build_psymtabs is called
-	     in coff_symfile_read, at which point we no longer need
-	     the information.  */
-	  make_cleanup (xfree, n);
-	}
+	csi->stabsects->push_back (sectp);
     }
 }
 
@@ -570,13 +554,16 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
   unsigned int num_symbols;
   int symtab_offset;
   int stringtab_offset;
-  struct cleanup *back_to;
   int stabstrsize;
   
   info = (struct coff_symfile_info *) objfile_data (objfile,
 						    coff_objfile_data_key);
   symfile_bfd = abfd;		/* Kludge for swap routines.  */
 
+  std::vector<asection *> stabsects;
+  scoped_restore restore_stabsects
+    = make_scoped_restore (&info->stabsects, &stabsects);
+
 /* WARNING WILL ROBINSON!  ACCESSING BFD-PRIVATE DATA HERE!  FIXME!  */
   num_symbols = bfd_get_symcount (abfd);	/* How many syms */
   symtab_offset = cdata->sym_filepos;	/* Symbol table file offset */
@@ -595,10 +582,10 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 
   /* Allocate space for raw symbol and aux entries, based on their
      space requirements as reported by BFD.  */
-  temp_sym = (char *) xmalloc
-    (cdata->local_symesz + cdata->local_auxesz);
+  gdb::def_vector<char> temp_storage (cdata->local_symesz
+				      + cdata->local_auxesz);
+  temp_sym = temp_storage.data ();
   temp_aux = temp_sym + cdata->local_symesz;
-  back_to = make_cleanup (free_current_contents, &temp_sym);
 
   /* We need to know whether this is a PE file, because in PE files,
      unlike standard COFF files, symbol values are stored as offsets
@@ -628,22 +615,25 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
      can avoid spurious error messages (and maybe run a little
      faster!) by not even reading the line number table unless we have
      symbols.  */
+  scoped_restore restore_linetab = make_scoped_restore (&linetab);
+  gdb::unique_xmalloc_ptr<char> linetab_storage;
   if (num_symbols > 0)
     {
       /* Read the line number table, all at once.  */
       bfd_map_over_sections (abfd, find_linenos, (void *) info);
 
-      make_cleanup (free_linetab_cleanup, 0 /*ignore*/);
       val = init_lineno (abfd, info->min_lineno_offset,
-                         info->max_lineno_offset - info->min_lineno_offset);
+                         info->max_lineno_offset - info->min_lineno_offset,
+			 &linetab_storage);
       if (val < 0)
         error (_("\"%s\": error reading line numbers."), filename);
     }
 
   /* Now read the string table, all at once.  */
 
-  make_cleanup (free_stringtab_cleanup, 0 /*ignore*/);
-  val = init_stringtab (abfd, stringtab_offset);
+  scoped_restore restore_stringtab = make_scoped_restore (&stringtab);
+  gdb::unique_xmalloc_ptr<char> stringtab_storage;
+  val = init_stringtab (abfd, stringtab_offset, &stringtab_storage);
   if (val < 0)
     error (_("\"%s\": can't get string table"), filename);
 
@@ -701,7 +691,7 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
   if (!(objfile->flags & OBJF_READNEVER))
     bfd_map_over_sections (abfd, coff_locate_sections, (void *) info);
 
-  if (info->stabsects)
+  if (! info->stabsects->empty())
     {
       if (!info->stabstrsect)
 	{
@@ -718,7 +708,7 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 
       coffstab_build_psymtabs (objfile,
 			       info->textaddr, info->textsize,
-			       info->stabsects,
+			       *info->stabsects,
 			       info->stabstrsect->filepos, stabstrsize);
     }
   if (dwarf2_has_info (objfile, NULL))
@@ -745,8 +735,6 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
 				    symfile_flags, objfile);
 	}
     }
-
-  do_cleanups (back_to);
 }
 
 static void
@@ -1298,17 +1286,13 @@ read_one_sym (struct coff_symbol *cs,
 \f
 /* Support for string table handling.  */
 
-static char *stringtab = NULL;
-
 static int
-init_stringtab (bfd *abfd, long offset)
+init_stringtab (bfd *abfd, long offset, gdb::unique_xmalloc_ptr<char> *storage)
 {
   long length;
   int val;
   unsigned char lengthbuf[4];
 
-  free_stringtab ();
-
   /* If the file is stripped, the offset might be zero, indicating no
      string table.  Just return with `stringtab' set to null.  */
   if (offset == 0)
@@ -1325,7 +1309,8 @@ init_stringtab (bfd *abfd, long offset)
   if (val != sizeof lengthbuf || length < sizeof lengthbuf)
     return 0;
 
-  stringtab = (char *) xmalloc (length);
+  storage->reset ((char *) xmalloc (length));
+  stringtab = storage->get ();
   /* This is in target format (probably not very useful, and not
      currently used), not host format.  */
   memcpy (stringtab, lengthbuf, sizeof lengthbuf);
@@ -1340,20 +1325,6 @@ init_stringtab (bfd *abfd, long offset)
   return 0;
 }
 
-static void
-free_stringtab (void)
-{
-  if (stringtab)
-    xfree (stringtab);
-  stringtab = NULL;
-}
-
-static void
-free_stringtab_cleanup (void *ignore)
-{
-  free_stringtab ();
-}
-
 static char *
 getsymname (struct internal_syment *symbol_entry)
 {
@@ -1407,24 +1378,19 @@ coff_getfilename (union internal_auxent *aux_entry)
 \f
 /* Support for line number handling.  */
 
-static char *linetab = NULL;
-static long linetab_offset;
-static unsigned long linetab_size;
-
 /* Read in all the line numbers for fast lookups later.  Leave them in
    external (unswapped) format in memory; we'll swap them as we enter
    them into GDB's data structures.  */
 
 static int
-init_lineno (bfd *abfd, long offset, int size)
+init_lineno (bfd *abfd, long offset, int size,
+	     gdb::unique_xmalloc_ptr<char> *storage)
 {
   int val;
 
   linetab_offset = offset;
   linetab_size = size;
 
-  free_linetab ();
-
   if (size == 0)
     return 0;
 
@@ -1432,9 +1398,10 @@ init_lineno (bfd *abfd, long offset, int size)
     return -1;
 
   /* Allocate the desired table, plus a sentinel.  */
-  linetab = (char *) xmalloc (size + local_linesz);
+  storage->reset ((char *) xmalloc (size + local_linesz));
+  linetab = storage->get ();
 
-  val = bfd_bread (linetab, size, abfd);
+  val = bfd_bread (storage->get (), size, abfd);
   if (val != size)
     return -1;
 
@@ -1444,20 +1411,6 @@ init_lineno (bfd *abfd, long offset, int size)
   return 0;
 }
 
-static void
-free_linetab (void)
-{
-  if (linetab)
-    xfree (linetab);
-  linetab = NULL;
-}
-
-static void
-free_linetab_cleanup (void *ignore)
-{
-  free_linetab ();
-}
-
 #if !defined (L_LNNO32)
 #define L_LNNO32(lp) ((lp)->l_lnno)
 #endif
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index 60d384b27fe..ad2edc3ff4b 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -747,7 +747,8 @@ static char *stringtab_global;
 /* These variables are used to control fill_symbuf when the stabs
    symbols are not contiguous (as may be the case when a COFF file is
    linked using --split-by-reloc).  */
-static struct stab_section_list *symbuf_sections;
+static const std::vector<asection *> *symbuf_sections;
+static size_t sect_idx;
 static unsigned int symbuf_left;
 static unsigned int symbuf_read;
 
@@ -783,13 +784,13 @@ fill_symbuf (bfd *sym_bfd)
     {
       if (symbuf_left <= 0)
 	{
-	  file_ptr filepos = symbuf_sections->section->filepos;
+	  file_ptr filepos = (*symbuf_sections)[sect_idx]->filepos;
 
 	  if (bfd_seek (sym_bfd, filepos, SEEK_SET) != 0)
 	    perror_with_name (bfd_get_filename (sym_bfd));
-	  symbuf_left = bfd_section_size (sym_bfd, symbuf_sections->section);
+	  symbuf_left = bfd_section_size (sym_bfd, (*symbuf_sections)[sect_idx]);
 	  symbol_table_offset = filepos - symbuf_read;
-	  symbuf_sections = symbuf_sections->next;
+	  ++sect_idx;
 	}
 
       count = symbuf_left;
@@ -2942,7 +2943,7 @@ process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name,
 void
 coffstab_build_psymtabs (struct objfile *objfile,
 			 CORE_ADDR textaddr, unsigned int textsize,
-			 struct stab_section_list *stabsects,
+			 const std::vector<asection *> &stabsects,
 			 file_ptr stabstroffset, unsigned int stabstrsize)
 {
   int val;
@@ -2981,27 +2982,28 @@ coffstab_build_psymtabs (struct objfile *objfile,
   /* In a coff file, we've already installed the minimal symbols that came
      from the coff (non-stab) symbol table, so always act like an
      incremental load here.  */
-  if (stabsects->next == NULL)
+  scoped_restore save_symbuf_sections
+    = make_scoped_restore (&symbuf_sections);
+  if (stabsects.size () == 1)
     {
-      stabsize = bfd_section_size (sym_bfd, stabsects->section);
+      stabsize = bfd_section_size (sym_bfd, stabsects[0]);
       DBX_SYMCOUNT (objfile) = stabsize / DBX_SYMBOL_SIZE (objfile);
-      DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos;
+      DBX_SYMTAB_OFFSET (objfile) = stabsects[0]->filepos;
     }
   else
     {
-      struct stab_section_list *stabsect;
-
       DBX_SYMCOUNT (objfile) = 0;
-      for (stabsect = stabsects; stabsect != NULL; stabsect = stabsect->next)
+      for (asection *section : stabsects)
 	{
-	  stabsize = bfd_section_size (sym_bfd, stabsect->section);
+	  stabsize = bfd_section_size (sym_bfd, section);
 	  DBX_SYMCOUNT (objfile) += stabsize / DBX_SYMBOL_SIZE (objfile);
 	}
 
-      DBX_SYMTAB_OFFSET (objfile) = stabsects->section->filepos;
+      DBX_SYMTAB_OFFSET (objfile) = stabsects[0]->filepos;
 
-      symbuf_sections = stabsects->next;
-      symbuf_left = bfd_section_size (sym_bfd, stabsects->section);
+      sect_idx = 1;
+      symbuf_sections = &stabsects;
+      symbuf_left = bfd_section_size (sym_bfd, stabsects[0]);
       symbuf_read = 0;
     }
 
diff --git a/gdb/stabsread.h b/gdb/stabsread.h
index fc989bc8994..f6928083d7c 100644
--- a/gdb/stabsread.h
+++ b/gdb/stabsread.h
@@ -167,18 +167,6 @@ extern void end_stabs (void);
 
 extern void finish_global_stabs (struct objfile *objfile);
 \f
-/* COFF files can have multiple .stab sections, if they are linked
-   using --split-by-reloc.  This linked list is used to pass the
-   information into the functions in dbxread.c.  */
-struct stab_section_list
-  {
-    /* Next in list.  */
-    struct stab_section_list *next;
-
-    /* Stab section.  */
-    asection *section;
-  };
-\f
 /* Functions exported by dbxread.c.  These are not in stabsread.c because
    they are only used by some stabs readers.  */
 
@@ -201,7 +189,7 @@ extern void elfstab_build_psymtabs (struct objfile *objfile,
 extern void coffstab_build_psymtabs
   (struct objfile *objfile,
    CORE_ADDR textaddr, unsigned int textsize,
-   struct stab_section_list *stabs,
+   const std::vector<asection *> &stabs,
    file_ptr stabstroffset, unsigned int stabstrsize);
 
 extern void stabsect_build_psymtabs (struct objfile *objfile, char *stab_name,
-- 
2.17.2

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

* Re: [PATCH v2 02/22] Update two cleanup comments
  2019-02-27 20:19 ` [PATCH v2 02/22] Update two cleanup comments Tom Tromey
@ 2019-03-06 19:23   ` Pedro Alves
  0 siblings, 0 replies; 58+ messages in thread
From: Pedro Alves @ 2019-03-06 19:23 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/27/2019 08:18 PM, Tom Tromey wrote:
> This updates another couple of comments to remove a mentions of
> cleanups.

s/a mention/mensions/ ?

> 
> gdb/ChangeLog
> 2019-02-27  Tom Tromey  <tom@tromey.com>
> 
> 	* inferior.h (class inferior): Update comment.
> 	* gdbthread.h (class thread_info): Update comment.

OK.

Thanks,
Pedro Alves

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

* Re: [PATCH v2 04/22] C++ify remote notification code
  2019-02-27 20:19 ` [PATCH v2 04/22] C++ify remote notification code Tom Tromey
@ 2019-03-06 19:23   ` Pedro Alves
  2019-03-06 21:12     ` Tom Tromey
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2019-03-06 19:23 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/27/2019 08:18 PM, Tom Tromey wrote:
> This C++ifies the remote notification code -- replacing function
> pointers with virtual methods and using unique_ptr.  This allows for
> the removal of some cleanups.
> 
> gdb/ChangeLog
> 2019-02-27  Tom Tromey  <tom@tromey.com>
> 
> 	* remote.c (struct stop_reply_deleter): Remove.
> 	(stop_reply_up): Update.
> 	(struct stop_reply): Derive from notif_event.  Don't typedef.
> 	<regcache>: Now a std::vector.
> 	(stop_reply_xfree): Remove.
> 	(stop_reply::~stop_reply): Rename from stop_reply_dtr.
> 	(remote_notif_stop_alloc_reply): Return a unique_ptr.  Use new.
> 	(remote_target::discard_pending_stop_replies): Use delete.
> 	(remote_target::remote_parse_stop_reply): Update.
> 	(remote_target::process_stop_reply): Update.
> 	* remote-notif.h (struct notif_event): Add virtual destructor.
> 	Remove "dtr" member.
> 	(struct notif_client) <alloc_event>: Return a unique_ptr.
> 	(notif_event_xfree): Don't declare.
> 	* remote-notif.c (remote_notif_ack, remote_notif_parse): Update.
> 	(notif_event_xfree, do_notif_event_xfree): Remove.
> 	(remote_notif_state_xfree): Update.
> ---
>  gdb/ChangeLog      | 20 ++++++++++++
>  gdb/remote-notif.c | 42 ++++--------------------
>  gdb/remote-notif.h | 11 +++----
>  gdb/remote.c       | 80 +++++++++++++---------------------------------
>  4 files changed, 54 insertions(+), 99 deletions(-)
> 
> diff --git a/gdb/remote-notif.c b/gdb/remote-notif.c
> index ae9a94d9c94..5a70ca128d5 100644
> --- a/gdb/remote-notif.c
> +++ b/gdb/remote-notif.c
> @@ -52,8 +52,6 @@ static struct notif_client *notifs[] =
>  
>  gdb_static_assert (ARRAY_SIZE (notifs) == REMOTE_NOTIF_LAST);
>  
> -static void do_notif_event_xfree (void *arg);
> -
>  /* Parse the BUF for the expected notification NC, and send packet to
>     acknowledge.  */
>  
> @@ -61,18 +59,14 @@ void
>  remote_notif_ack (remote_target *remote,
>  		  struct notif_client *nc, const char *buf)
>  {
> -  struct notif_event *event = nc->alloc_event ();
> -  struct cleanup *old_chain
> -    = make_cleanup (do_notif_event_xfree, event);
> +  std::unique_ptr<struct notif_event> event = nc->alloc_event ();

"std::unique_ptr<struct notif_event>" appears in a number of places
in the patch.  Did you consider adding a "notif_event_up" typedef ?

> -typedef std::unique_ptr<stop_reply, stop_reply_deleter> stop_reply_up;
> +typedef std::unique_ptr<struct stop_reply> stop_reply_up;

Odd that you added the "struct".  I tend to remove it when touching
code instead. :-)

Anyway, patch is OK.

Thanks,
Pedro Alves

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

* Re: [PATCH v2 03/22] Change displaced_step_clear_cleanup with a forward_scope_exit
  2019-02-27 20:19 ` [PATCH v2 03/22] Change displaced_step_clear_cleanup with a forward_scope_exit Tom Tromey
@ 2019-03-06 19:23   ` Pedro Alves
  0 siblings, 0 replies; 58+ messages in thread
From: Pedro Alves @ 2019-03-06 19:23 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/27/2019 08:18 PM, Tom Tromey wrote:
> +/* A cleanup that wraps displaced_step_clear.  */
> +using displaced_step_clear_cleanup
> +    = FORWARD_SCOPE_EXIT (displaced_step_clear);

The '=' should be indented with two spaces instead of four.

Otherwise OK.

Thanks,
Pedro Alves

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

* Re: [PATCH v2 05/22] Remove last cleanup from gdbserver
  2019-02-27 20:18 ` [PATCH v2 05/22] Remove last cleanup from gdbserver Tom Tromey
@ 2019-03-06 19:23   ` Pedro Alves
  0 siblings, 0 replies; 58+ messages in thread
From: Pedro Alves @ 2019-03-06 19:23 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/27/2019 08:18 PM, Tom Tromey wrote:
> This removes the last cleanup from gdbserver, replacing it with
> SCOPE_EXIT.  This could perhaps be done in a different way, but this
> approach was direct and obviously correct.

LGTM.

Thanks,
Pedro Alves

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

* Re: [PATCH v2 01/22] Remove cleanups from coffread.c
  2019-02-27 20:19 ` [PATCH v2 01/22] Remove cleanups from coffread.c Tom Tromey
@ 2019-03-06 19:23   ` Pedro Alves
  0 siblings, 0 replies; 58+ messages in thread
From: Pedro Alves @ 2019-03-06 19:23 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/27/2019 08:18 PM, Tom Tromey wrote:
> This removes the remaining cleanups from coffread.c.
> 
> Tested by the buildbot.  However, I don't think the buildbot really
> tests these code paths, and TBH I am not sure how to do it manually.
> I did manage to crash an earlier version of the patch using a mingw
> .exe file, though I would have thought that was only going to test
> coff-pe-read.c.

PE files are coff files with extra sauce.  coff-pe-read.c only takes
care of the PE export tables (extra sauce).

> @@ -701,7 +691,7 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
>    if (!(objfile->flags & OBJF_READNEVER))
>      bfd_map_over_sections (abfd, coff_locate_sections, (void *) info);
>  
> -  if (info->stabsects)
> +  if (! info->stabsects->empty())

No space after '!'.

Thanks,
Pedro Alves

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

* Re: [PATCH v2 06/22] Remove cleanup from solib-svr4.c
  2019-02-27 20:19 ` [PATCH v2 06/22] Remove cleanup from solib-svr4.c Tom Tromey
@ 2019-03-06 19:24   ` Pedro Alves
  0 siblings, 0 replies; 58+ messages in thread
From: Pedro Alves @ 2019-03-06 19:24 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/27/2019 08:18 PM, Tom Tromey wrote:
> This removes a cleanup from solib-svr4.c, replacing it with
> make_scope_exit.
> 
> gdb/ChangeLog
> 2019-02-27  Tom Tromey  <tom@tromey.com>
> 
> 	* solib-svr4.c (disable_probes_interface): Remove parameter.
> 	(svr4_handle_solib_event): Use make_scope_exit.

OK.

Thanks,
Pedro Alves

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

* Re: [PATCH v2 07/22] Remove last cleanups from solib-svr4.c
  2019-02-27 20:19 ` [PATCH v2 07/22] Remove last cleanups from solib-svr4.c Tom Tromey
@ 2019-03-06 19:32   ` Pedro Alves
  2019-03-06 19:39     ` John Baldwin
  2019-03-06 21:18     ` Tom Tromey
  0 siblings, 2 replies; 58+ messages in thread
From: Pedro Alves @ 2019-03-06 19:32 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/27/2019 08:18 PM, Tom Tromey wrote:
> This removes the last cleanups from solib-svr4.c, replacing them with
> uses of make_scope_exit.
> 
> gdb/ChangeLog
> 2019-02-27  Tom Tromey  <tom@tromey.com>
> 
> 	* solib-svr4.c (svr4_parse_libraries, svr4_current_sos_direct):
> 	Use make_scope_exit.
> ---
>  gdb/ChangeLog    |  5 +++++
>  gdb/solib-svr4.c | 17 ++++++++++-------
>  2 files changed, 15 insertions(+), 7 deletions(-)
> 
> diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
> index 2b370ef96d0..2301cf94c2f 100644
> --- a/gdb/solib-svr4.c
> +++ b/gdb/solib-svr4.c
> @@ -1198,8 +1198,10 @@ static const struct gdb_xml_element svr4_library_list_elements[] =
>  static int
>  svr4_parse_libraries (const char *document, struct svr4_library_list *list)
>  {
> -  struct cleanup *back_to = make_cleanup (svr4_free_library_list,
> -					  &list->head);
> +  auto cleanup = make_scope_exit ([&] ()
> +				  {
> +				    svr4_free_library_list (&list->head);
> +				  });
>  

When passing lambdas as last argument to a function, I think indenting
like this reads clearer:

  auto cleanup = make_scope_exit ([&] ()
    {
      svr4_free_library_list (&list->head);
    });

Makes it read more like an if/for scope block, and of course,
avoids aligning things too much to the right side.  Examples of
this can be found throughout gdbserver, for example:

	  for_each_thread ([] (thread_info *thread)
	    {
	      thread->status_pending_p = 0;
	    });

and, also, that's how you'd indent if you used SCOPE_EXIT instead:

  SCOPE_EXIT
    {
      svr4_free_library_list (&list->head);
    }

LLVM has a written rule for this:

 https://llvm.org/docs/CodingStandards.html#format-lambdas-like-blocks-of-code

If others agree, I'd vote for having a similar rule of our own.

Otherwise, LGTM.

Thanks,
Pedro Alves

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

* Re: [PATCH v2 08/22] Remove last cleanup solib-aix.c
  2019-02-27 20:18 ` [PATCH v2 08/22] Remove last cleanup solib-aix.c Tom Tromey
@ 2019-03-06 19:34   ` Pedro Alves
  2019-03-06 21:19     ` Tom Tromey
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2019-03-06 19:34 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/27/2019 08:18 PM, Tom Tromey wrote:
> This removes the last cleanup solib-aix.c, replacing it with a use of
> make_scope_exit.

Other than the indentation thing, which I'll stop mentioning in
following patches, LGTM.

Thanks,
Pedro Alves

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

* Re: [PATCH v2 07/22] Remove last cleanups from solib-svr4.c
  2019-03-06 19:32   ` Pedro Alves
@ 2019-03-06 19:39     ` John Baldwin
  2019-03-06 21:18     ` Tom Tromey
  1 sibling, 0 replies; 58+ messages in thread
From: John Baldwin @ 2019-03-06 19:39 UTC (permalink / raw)
  To: Pedro Alves, Tom Tromey, gdb-patches

On 3/6/19 11:32 AM, Pedro Alves wrote:
> On 02/27/2019 08:18 PM, Tom Tromey wrote:
>> This removes the last cleanups from solib-svr4.c, replacing them with
>> uses of make_scope_exit.
>>
>> gdb/ChangeLog
>> 2019-02-27  Tom Tromey  <tom@tromey.com>
>>
>> 	* solib-svr4.c (svr4_parse_libraries, svr4_current_sos_direct):
>> 	Use make_scope_exit.
>> ---
>>  gdb/ChangeLog    |  5 +++++
>>  gdb/solib-svr4.c | 17 ++++++++++-------
>>  2 files changed, 15 insertions(+), 7 deletions(-)
>>
>> diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
>> index 2b370ef96d0..2301cf94c2f 100644
>> --- a/gdb/solib-svr4.c
>> +++ b/gdb/solib-svr4.c
>> @@ -1198,8 +1198,10 @@ static const struct gdb_xml_element svr4_library_list_elements[] =
>>  static int
>>  svr4_parse_libraries (const char *document, struct svr4_library_list *list)
>>  {
>> -  struct cleanup *back_to = make_cleanup (svr4_free_library_list,
>> -					  &list->head);
>> +  auto cleanup = make_scope_exit ([&] ()
>> +				  {
>> +				    svr4_free_library_list (&list->head);
>> +				  });
>>  
> 
> When passing lambdas as last argument to a function, I think indenting
> like this reads clearer:
> 
>   auto cleanup = make_scope_exit ([&] ()
>     {
>       svr4_free_library_list (&list->head);
>     });
> 
> Makes it read more like an if/for scope block, and of course,
> avoids aligning things too much to the right side.  Examples of
> this can be found throughout gdbserver, for example:
> 
> 	  for_each_thread ([] (thread_info *thread)
> 	    {
> 	      thread->status_pending_p = 0;
> 	    });
> 
> and, also, that's how you'd indent if you used SCOPE_EXIT instead:
> 
>   SCOPE_EXIT
>     {
>       svr4_free_library_list (&list->head);
>     }
> 
> LLVM has a written rule for this:
> 
>  https://llvm.org/docs/CodingStandards.html#format-lambdas-like-blocks-of-code
> 
> If others agree, I'd vote for having a similar rule of our own.

I'd +1 that rule FWIW.

-- 
John Baldwin

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

* Re: [PATCH v2 09/22] Remove last cleanup from linux-namespaces.c
  2019-02-27 20:19 ` [PATCH v2 09/22] Remove last cleanup from linux-namespaces.c Tom Tromey
@ 2019-03-06 21:07   ` Pedro Alves
  0 siblings, 0 replies; 58+ messages in thread
From: Pedro Alves @ 2019-03-06 21:07 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/27/2019 08:18 PM, Tom Tromey wrote:
> This removes the last cleanup from linux-namespaces.c, replacing it
> with a use of SCOPE_EXIT.
> 
> gdb/ChangeLog
> 2019-02-27  Tom Tromey  <tom@tromey.com>
> 
> 	* nat/linux-namespaces.c (linux_mntns_access_fs): Use SCOPE_EXIT.
> 	* common/filestuff.h (make_cleanup_close): Don't declare.
> 	* common/filestuff.c (do_close_cleanup, make_cleanup_close):
> 	Remove.

Nice.  Much simpler than the previous attempts using custom RAII types.

OK.

Thanks,
Pedro Alves

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

* Re: [PATCH v2 04/22] C++ify remote notification code
  2019-03-06 19:23   ` Pedro Alves
@ 2019-03-06 21:12     ` Tom Tromey
  0 siblings, 0 replies; 58+ messages in thread
From: Tom Tromey @ 2019-03-06 21:12 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, gdb-patches

>> +  std::unique_ptr<struct notif_event> event = nc->alloc_event ();

Pedro> "std::unique_ptr<struct notif_event>" appears in a number of places
Pedro> in the patch.  Did you consider adding a "notif_event_up" typedef ?

Nope, but I've added it now.

>> -typedef std::unique_ptr<stop_reply, stop_reply_deleter> stop_reply_up;
>> +typedef std::unique_ptr<struct stop_reply> stop_reply_up;

Pedro> Odd that you added the "struct".  I tend to remove it when touching
Pedro> code instead. :-)

I changed this back.

Tom

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

* Re: [PATCH v2 10/22] Remove last cleanups from stabsread.c
  2019-02-27 20:19 ` [PATCH v2 10/22] Remove last cleanups from stabsread.c Tom Tromey
@ 2019-03-06 21:14   ` Pedro Alves
  0 siblings, 0 replies; 58+ messages in thread
From: Pedro Alves @ 2019-03-06 21:14 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/27/2019 08:18 PM, Tom Tromey wrote:
> This removes the last cleanups from stabsread.c.  Similar code in
> dwarf2read.c was C++-ified, but considering that stabs are deprecated,
> it seemed simpler to just change these allocations to use an obstack
> and leave the data structures in place.
> 
> This patch renames field_info to stabs_field_info -- adding a
> constructor here provoked a bug due to the resulting ODR violation.
> 
> gdb/ChangeLog
> 2019-02-27  Tom Tromey  <tom@tromey.com>
> 
> 	* stabsread.c (struct stabs_field_info): Rename from field_info.
> 	<list, fnlist>: Add initializers.
> 	<obstack>: New member.
> 	(read_member_functions, read_struct_fields, read_baseclasses):
> 	Allocate on obstack.  Don't use cleanups.
> 	(read_one_struct_field, read_member_functions, read_struct_fields)
> 	(read_baseclasses, read_tilde_fields, attach_fn_fields_to_type)
> 	(attach_fields_to_type, read_cpp_abbrev, read_member_functions)
> 	(read_struct_type): Update.

LGTM.

Thanks,
Pedro Alves

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

* Re: [PATCH v2 11/22] Use unique_xmalloc_ptr in remote.c
  2019-02-27 20:19 ` [PATCH v2 11/22] Use unique_xmalloc_ptr in remote.c Tom Tromey
@ 2019-03-06 21:17   ` Pedro Alves
  0 siblings, 0 replies; 58+ messages in thread
From: Pedro Alves @ 2019-03-06 21:17 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/27/2019 08:18 PM, Tom Tromey wrote:
> This removes a cleanup from remote.c, replacing it with
> unique_xmalloc_ptr.
> 
> gdb/ChangeLog
> 2019-02-27  Tom Tromey  <tom@tromey.com>
> 
> 	* remote.c (remote_target::remote_parse_stop_reply): Use
> 	unique_xmalloc_ptr.
> ---
>  gdb/ChangeLog |  5 +++++
>  gdb/remote.c  | 11 +++++------
>  2 files changed, 10 insertions(+), 6 deletions(-)
> 
> diff --git a/gdb/remote.c b/gdb/remote.c
> index f80dcdaee94..5f658deefaa 100644
> --- a/gdb/remote.c
> +++ b/gdb/remote.c
> @@ -7314,14 +7314,13 @@ Packet: '%s'\n"),
>  
>  	      /* Save the pathname for event reporting and for
>  		 the next run command.  */
> -	      char *pathname = (char *) xmalloc (pathlen + 1);
> -	      struct cleanup *old_chain = make_cleanup (xfree, pathname);
> -	      hex2bin (p1, (gdb_byte *) pathname, pathlen);
> -	      pathname[pathlen] = '\0';
> -	      discard_cleanups (old_chain);
> +	      gdb::unique_xmalloc_ptr<char> pathname
> +		((char *) xmalloc (pathlen + 1));

Use:

	      gdb::unique_xmalloc_ptr<char[]>


> +	      hex2bin (p1, (gdb_byte *) pathname.get (), pathlen);
> +	      pathname.get ()[pathlen] = '\0';

Then here write:

	      pathname[pathlen] = '\0';

Otherwise OK.

Thanks,
Pedro Alves

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

* Re: [PATCH v2 07/22] Remove last cleanups from solib-svr4.c
  2019-03-06 19:32   ` Pedro Alves
  2019-03-06 19:39     ` John Baldwin
@ 2019-03-06 21:18     ` Tom Tromey
  1 sibling, 0 replies; 58+ messages in thread
From: Tom Tromey @ 2019-03-06 21:18 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, gdb-patches

>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Pedro> When passing lambdas as last argument to a function, I think indenting
Pedro> like this reads clearer:

Pedro>   auto cleanup = make_scope_exit ([&] ()
Pedro>     {
Pedro>       svr4_free_library_list (&list->head);
Pedro>     });

I agree.  I made this change here & in another patch in the series.

Pedro> If others agree, I'd vote for having a similar rule of our own.

Let's do it.

Tom

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

* Re: [PATCH v2 08/22] Remove last cleanup solib-aix.c
  2019-03-06 19:34   ` Pedro Alves
@ 2019-03-06 21:19     ` Tom Tromey
  0 siblings, 0 replies; 58+ messages in thread
From: Tom Tromey @ 2019-03-06 21:19 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, gdb-patches

>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Pedro> On 02/27/2019 08:18 PM, Tom Tromey wrote:
>> This removes the last cleanup solib-aix.c, replacing it with a use of
>> make_scope_exit.

Pedro> Other than the indentation thing, which I'll stop mentioning in
Pedro> following patches, LGTM.

I wasn't totally sure from this mail if you were intending to look at
the rest of the series, so just to be clear, I'll hold off on pushing
anything until you've given the go-ahead.

thanks,
Tom

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

* Re: [PATCH v2 12/22] Remove basic cleanup code
  2019-02-27 20:19 ` [PATCH v2 12/22] Remove basic cleanup code Tom Tromey
@ 2019-03-06 21:33   ` Pedro Alves
  0 siblings, 0 replies; 58+ messages in thread
From: Pedro Alves @ 2019-03-06 21:33 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/27/2019 08:18 PM, Tom Tromey wrote:
> This removes the basic cleanup code: make_cleanups, do_cleanups,
> discard_cleanups, and friends.  This code is no longer needed, as
> nothing in gdb makes an ordinary cleanup.  Final cleanups are still
> needed.

Hurray!

OK.

Thanks,
Pedro Alves

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

* Re: [PATCH v2 13/22] Remove free_current_contents
  2019-02-27 20:19 ` [PATCH v2 13/22] Remove free_current_contents Tom Tromey
@ 2019-03-06 21:34   ` Pedro Alves
  0 siblings, 0 replies; 58+ messages in thread
From: Pedro Alves @ 2019-03-06 21:34 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/27/2019 08:18 PM, Tom Tromey wrote:
> free_current_contents is no longer used, so this patch removes it.
> 
> gdb/ChangeLog
> 2019-02-27  Tom Tromey  <tom@tromey.com>
> 
> 	* utils.h (free_current_contents): Don't declare.
> 	* utils.c (free_current_contents): Remove.

Obviously OK.

Thanks,
Pedro Alves

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

* Re: [PATCH v2 21/22] Use SCOPE_EXIT in write_gcore_file
  2019-02-27 20:19 ` [PATCH v2 21/22] Use SCOPE_EXIT in write_gcore_file Tom Tromey
@ 2019-03-06 22:01   ` Pedro Alves
  2019-03-06 22:31     ` Tom Tromey
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2019-03-06 22:01 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/27/2019 08:18 PM, Tom Tromey wrote:
> This replaces a try/catch in write_gcore_file with a use of SCOPE_EXIT
> instead.  I find that this is simpler to understand.
> 
> gdb/ChangeLog
> 2019-02-27  Tom Tromey  <tom@tromey.com>
> 
> 	* gcore.c (write_gcore_file): Use SCOPE_EXIT.

You could rebase this on current master and push it in, to get it
out of the way.

You could also merge patches #1-#13, the cleanup-elimination patches
until the TRY/CATCH parts.  I'll need a bit more time to comment
on those TRY/CATCH parts, so I've skipped them tonight.

Thanks,
Pedro Alves

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

* Re: [PATCH v2 22/22] Introduce and use bcache_up
  2019-02-27 20:19 ` [PATCH v2 22/22] Introduce and use bcache_up Tom Tromey
@ 2019-03-06 22:03   ` Pedro Alves
  2019-03-07 16:54     ` Tom Tromey
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2019-03-06 22:03 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/27/2019 08:18 PM, Tom Tromey wrote:
> This introduces a new bcache_up typedef, which is a unique_ptr
> specialization for managing a bcache.  Then, this changes various
> spots to use this object, rather than manually calling bcache_xfree.
> This lets us remove a try/catch that only existed to call
> bcache_xfree.

I won't object, but is seems to me that it'd be better to
make bcache_xmalloc / bcache_free ctors/dtors of struct bcache,
and then we'd allocate a bcache object on the stack (and likewise
hold bcache objects in structures instead of bcache pointers).

Thanks,
Pedro Alves

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

* Re: [PATCH v2 21/22] Use SCOPE_EXIT in write_gcore_file
  2019-03-06 22:01   ` Pedro Alves
@ 2019-03-06 22:31     ` Tom Tromey
  2019-03-06 22:54       ` Pedro Alves
  0 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-03-06 22:31 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, gdb-patches

>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Pedro> You could rebase this on current master and push it in, to get it
Pedro> out of the way.

Unless there's a need, I'd rather leave it as-is, since rebasing it
earlier means tweaking other patches earlier in the series.

Pedro> You could also merge patches #1-#13, the cleanup-elimination patches
Pedro> until the TRY/CATCH parts.  I'll need a bit more time to comment
Pedro> on those TRY/CATCH parts, so I've skipped them tonight.

I don't mind waiting, it's not a super rush to get this in.
Thanks for looking through these.

Tom

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

* Re: [PATCH v2 21/22] Use SCOPE_EXIT in write_gcore_file
  2019-03-06 22:31     ` Tom Tromey
@ 2019-03-06 22:54       ` Pedro Alves
  2019-03-06 22:56         ` Tom Tromey
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2019-03-06 22:54 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches


-- 
Thanks,
Pedro Alves
On 03/06/2019 10:31 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
> 
> Pedro> You could rebase this on current master and push it in, to get it
> Pedro> out of the way.
> 
> Unless there's a need, I'd rather leave it as-is, since rebasing it
> earlier means tweaking other patches earlier in the series.

The only tweak othe other patches would need would be to not touch
the file at all.  This patch eliminates the need for any of the
previous changes to the same code.

> 
> Pedro> You could also merge patches #1-#13, the cleanup-elimination patches
> Pedro> until the TRY/CATCH parts.  I'll need a bit more time to comment
> Pedro> on those TRY/CATCH parts, so I've skipped them tonight.
> 
> I don't mind waiting, it's not a super rush to get this in.
> Thanks for looking through these.
I'd think getting the cleanups elimination patches in would be
good for the fact that it makes it impossible for anyone else to
end up adding new cleanups meanwhile.  And, it makes the remainder
patches a smaller self-contained series; any new repost would be
much smaller.

Thanks,
Pedro Alves

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

* Re: [PATCH v2 21/22] Use SCOPE_EXIT in write_gcore_file
  2019-03-06 22:54       ` Pedro Alves
@ 2019-03-06 22:56         ` Tom Tromey
  2019-03-06 23:08           ` Tom Tromey
  0 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-03-06 22:56 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, gdb-patches

>> I don't mind waiting, it's not a super rush to get this in.
>> Thanks for looking through these.

Pedro> I'd think getting the cleanups elimination patches in would be
Pedro> good for the fact that it makes it impossible for anyone else to
Pedro> end up adding new cleanups meanwhile.  And, it makes the remainder
Pedro> patches a smaller self-contained series; any new repost would be
Pedro> much smaller.

Ok, I will try to do that either tonight or tomorrow.

Tom

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

* Re: [PATCH v2 21/22] Use SCOPE_EXIT in write_gcore_file
  2019-03-06 22:56         ` Tom Tromey
@ 2019-03-06 23:08           ` Tom Tromey
  0 siblings, 0 replies; 58+ messages in thread
From: Tom Tromey @ 2019-03-06 23:08 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Pedro Alves, gdb-patches

Tom> Ok, I will try to do that either tonight or tomorrow.

Those are in now, let me know if there are problems.

thanks,
Tom

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

* Re: [PATCH v2 22/22] Introduce and use bcache_up
  2019-03-06 22:03   ` Pedro Alves
@ 2019-03-07 16:54     ` Tom Tromey
  2019-03-07 17:09       ` Pedro Alves
  0 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-03-07 16:54 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, gdb-patches

>> This introduces a new bcache_up typedef, which is a unique_ptr
>> specialization for managing a bcache.  Then, this changes various
>> spots to use this object, rather than manually calling bcache_xfree.
>> This lets us remove a try/catch that only existed to call
>> bcache_xfree.

Pedro> I won't object, but is seems to me that it'd be better to
Pedro> make bcache_xmalloc / bcache_free ctors/dtors of struct bcache,
Pedro> and then we'd allocate a bcache object on the stack (and likewise
Pedro> hold bcache objects in structures instead of bcache pointers).

I broke this one out from the series.  Let me know what you think.

Tom

commit 64ade377efa115d64318be2dbbf40df9d58b9d42
Author: Tom Tromey <tom@tromey.com>
Date:   Thu Mar 7 04:20:19 2019 -0700

    C++-ify bcache
    
    This somewhat C++-ifies bcache.  It replaces bcache_xmalloc and
    bcache_xfree with constructors; changes some functions into methods;
    and changes various structures to include a bcache directly (as
    opposed to a pointer to a bcache).
    
    Tested by the buildbot.
    
    gdb/ChangeLog
    2019-03-07  Tom Tromey  <tom@tromey.com>
    
            * symmisc.c (print_symbol_bcache_statistics): Update.
            (print_objfile_statistics): Update.
            * symfile.c (allocate_symtab): Update.
            * stabsread.c: Don't include bcache.h.
            * psymtab.h (struct psymbol_bcache): Don't declare.
            (class psymtab_storage) <psymbol_cache>: Now a bcache.
            (psymbol_bcache_init, psymbol_bcache_free)
            (psymbol_bcache_get_bcache): Don't declare.
            * psymtab.c (struct psymbol_bcache): Remove.
            (psymtab_storage::psymtab_storage): Update.
            (psymtab_storage::~psymtab_storage): Update.
            (psymbol_bcache_init, psymbol_bcache_free)
            (psymbol_bcache_get_bcache, psymbol_bcache_full): Remove.
            (add_psymbol_to_bcache): Update.
            (allocate_psymtab): Update.
            * objfiles.h (struct objfile_per_bfd_storage) <filename_cache,
            macro_cache>: No longer pointers.
            * objfiles.c (get_objfile_bfd_data): Don't call bcache_xmalloc.
            (free_objfile_per_bfd_storage): Don't call bcache_xfree.
            * macrotab.c (macro_bcache): Update.
            * macroexp.c: Don't include bcache.h.
            * gdbtypes.c (check_types_worklist): Update.
            (types_deeply_equal): Remove TRY/CATCH.  Update.
            * elfread.c (elf_symtab_read): Update.
            * dwarf2read.c: Don't include bcache.h.
            * buildsym.c (buildsym_compunit::get_macro_table): Update.
            * bcache.h (bcache, bcache_full, bcache_xffree, bcache_xmalloc)
            (print_bcache_statistics, bcache_memory_used): Don't declare.
            (struct bcache): Move from bcache.c.  Add constructor, destructor,
            methods.
            * bcache.c (struct bcache): Move to bcache.h.
            (bcache::expand_hash_table): Rename from expand_hash_table.
            (bcache): Remove.
            (bcache::insert): Rename from bcache_full.
            (bcache::compare): Rename from bcache_compare.
            (bcache_xmalloc): Remove.
            (bcache::~bcache): Rename from bcache_xfree.
            (bcache::print_statistics): Rename from print_bcache_statistics.
            (bcache::memory_used): Rename from bcache_memory_used.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d3d6e5b4ee6..88fe03cc2e7 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,45 @@
+2019-03-07  Tom Tromey  <tom@tromey.com>
+
+	* symmisc.c (print_symbol_bcache_statistics): Update.
+	(print_objfile_statistics): Update.
+	* symfile.c (allocate_symtab): Update.
+	* stabsread.c: Don't include bcache.h.
+	* psymtab.h (struct psymbol_bcache): Don't declare.
+	(class psymtab_storage) <psymbol_cache>: Now a bcache.
+	(psymbol_bcache_init, psymbol_bcache_free)
+	(psymbol_bcache_get_bcache): Don't declare.
+	* psymtab.c (struct psymbol_bcache): Remove.
+	(psymtab_storage::psymtab_storage): Update.
+	(psymtab_storage::~psymtab_storage): Update.
+	(psymbol_bcache_init, psymbol_bcache_free)
+	(psymbol_bcache_get_bcache, psymbol_bcache_full): Remove.
+	(add_psymbol_to_bcache): Update.
+	(allocate_psymtab): Update.
+	* objfiles.h (struct objfile_per_bfd_storage) <filename_cache,
+	macro_cache>: No longer pointers.
+	* objfiles.c (get_objfile_bfd_data): Don't call bcache_xmalloc.
+	(free_objfile_per_bfd_storage): Don't call bcache_xfree.
+	* macrotab.c (macro_bcache): Update.
+	* macroexp.c: Don't include bcache.h.
+	* gdbtypes.c (check_types_worklist): Update.
+	(types_deeply_equal): Remove TRY/CATCH.  Update.
+	* elfread.c (elf_symtab_read): Update.
+	* dwarf2read.c: Don't include bcache.h.
+	* buildsym.c (buildsym_compunit::get_macro_table): Update.
+	* bcache.h (bcache, bcache_full, bcache_xffree, bcache_xmalloc)
+	(print_bcache_statistics, bcache_memory_used): Don't declare.
+	(struct bcache): Move from bcache.c.  Add constructor, destructor,
+	methods.
+	* bcache.c (struct bcache): Move to bcache.h.
+	(bcache::expand_hash_table): Rename from expand_hash_table.
+	(bcache): Remove.
+	(bcache::insert): Rename from bcache_full.
+	(bcache::compare): Rename from bcache_compare.
+	(bcache_xmalloc): Remove.
+	(bcache::~bcache): Rename from bcache_xfree.
+	(bcache::print_statistics): Rename from print_bcache_statistics.
+	(bcache::memory_used): Rename from bcache_memory_used.
+
 2019-03-07  Andrew Burgess  <andrew.burgess@embecosm.com>
 
 	* f-lang.c (value_from_host_double): Moved to...
diff --git a/gdb/bcache.c b/gdb/bcache.c
index 1430953ac62..17593c42d27 100644
--- a/gdb/bcache.c
+++ b/gdb/bcache.c
@@ -49,48 +49,6 @@ struct bstring
   d;
 };
 
-
-/* The structure for a bcache itself.  The bcache is initialized, in
-   bcache_xmalloc(), by filling it with zeros and then setting the
-   corresponding obstack's malloc() and free() methods.  */
-
-struct bcache
-{
-  /* All the bstrings are allocated here.  */
-  struct obstack cache;
-
-  /* How many hash buckets we're using.  */
-  unsigned int num_buckets;
-  
-  /* Hash buckets.  This table is allocated using malloc, so when we
-     grow the table we can return the old table to the system.  */
-  struct bstring **bucket;
-
-  /* Statistics.  */
-  unsigned long unique_count;	/* number of unique strings */
-  long total_count;	/* total number of strings cached, including dups */
-  long unique_size;	/* size of unique strings, in bytes */
-  long total_size;      /* total number of bytes cached, including dups */
-  long structure_size;	/* total size of bcache, including infrastructure */
-  /* Number of times that the hash table is expanded and hence
-     re-built, and the corresponding number of times that a string is
-     [re]hashed as part of entering it into the expanded table.  The
-     total number of hashes can be computed by adding TOTAL_COUNT to
-     expand_hash_count.  */
-  unsigned long expand_count;
-  unsigned long expand_hash_count;
-  /* Number of times that the half-hash compare hit (compare the upper
-     16 bits of hash values) hit, but the corresponding combined
-     length/data compare missed.  */
-  unsigned long half_hash_miss_count;
-
-  /* Hash function to be used for this bcache object.  */
-  unsigned long (*hash_function)(const void *addr, int length);
-
-  /* Compare function to be used for this bcache object.  */
-  int (*compare_function)(const void *, const void *, int length);
-};
-
 /* The old hash function was stolen from SDBM. This is what DB 3.0
    uses now, and is better than the old one.  */
 \f
@@ -123,8 +81,8 @@ hash_continue (const void *addr, int length, unsigned long h)
    resize our hash table.  */
 #define CHAIN_LENGTH_THRESHOLD (5)
 
-static void
-expand_hash_table (struct bcache *bcache)
+void
+bcache::expand_hash_table ()
 {
   /* A table of good hash table sizes.  Whenever we grow, we pick the
      next larger size from this table.  sizes[i] is close to 1 << (i+10),
@@ -143,13 +101,13 @@ expand_hash_table (struct bcache *bcache)
 
   /* Count the stats.  Every unique item needs to be re-hashed and
      re-entered.  */
-  bcache->expand_count++;
-  bcache->expand_hash_count += bcache->unique_count;
+  expand_count++;
+  expand_hash_count += unique_count;
 
   /* Find the next size.  */
-  new_num_buckets = bcache->num_buckets * 2;
+  new_num_buckets = num_buckets * 2;
   for (i = 0; i < (sizeof (sizes) / sizeof (sizes[0])); i++)
-    if (sizes[i] > bcache->num_buckets)
+    if (sizes[i] > num_buckets)
       {
 	new_num_buckets = sizes[i];
 	break;
@@ -162,23 +120,21 @@ expand_hash_table (struct bcache *bcache)
     new_buckets = (struct bstring **) xmalloc (new_size);
     memset (new_buckets, 0, new_size);
 
-    bcache->structure_size -= (bcache->num_buckets
-			       * sizeof (bcache->bucket[0]));
-    bcache->structure_size += new_size;
+    structure_size -= num_buckets * sizeof (bucket[0]);
+    structure_size += new_size;
   }
 
   /* Rehash all existing strings.  */
-  for (i = 0; i < bcache->num_buckets; i++)
+  for (i = 0; i < num_buckets; i++)
     {
       struct bstring *s, *next;
 
-      for (s = bcache->bucket[i]; s; s = next)
+      for (s = bucket[i]; s; s = next)
 	{
 	  struct bstring **new_bucket;
 	  next = s->next;
 
-	  new_bucket = &new_buckets[(bcache->hash_function (&s->d.data,
-							    s->length)
+	  new_bucket = &new_buckets[(hash_function (&s->d.data, s->length)
 				     % new_num_buckets)];
 	  s->next = *new_bucket;
 	  *new_bucket = s;
@@ -186,10 +142,9 @@ expand_hash_table (struct bcache *bcache)
     }
 
   /* Plug in the new table.  */
-  if (bcache->bucket)
-    xfree (bcache->bucket);
-  bcache->bucket = new_buckets;
-  bcache->num_buckets = new_num_buckets;
+  xfree (bucket);
+  bucket = new_buckets;
+  num_buckets = new_num_buckets;
 }
 
 \f
@@ -199,15 +154,6 @@ expand_hash_table (struct bcache *bcache)
    is N bytes long.  */
 #define BSTRING_SIZE(n) (offsetof (struct bstring, d.data) + (n))
 
-/* Find a copy of the LENGTH bytes at ADDR in BCACHE.  If BCACHE has
-   never seen those bytes before, add a copy of them to BCACHE.  In
-   either case, return a pointer to BCACHE's copy of that string.  */
-const void *
-bcache (const void *addr, int length, struct bcache *cache)
-{
-  return bcache_full (addr, length, cache, NULL);
-}
-
 /* Find a copy of the LENGTH bytes at ADDR in BCACHE.  If BCACHE has
    never seen those bytes before, add a copy of them to BCACHE.  In
    either case, return a pointer to BCACHE's copy of that string.  If
@@ -215,7 +161,7 @@ bcache (const void *addr, int length, struct bcache *cache)
    returning an old entry.  */
 
 const void *
-bcache_full (const void *addr, int length, struct bcache *bcache, int *added)
+bcache::insert (const void *addr, int length, int *added)
 {
   unsigned long full_hash;
   unsigned short half_hash;
@@ -227,56 +173,56 @@ bcache_full (const void *addr, int length, struct bcache *bcache, int *added)
 
   /* Lazily initialize the obstack.  This can save quite a bit of
      memory in some cases.  */
-  if (bcache->total_count == 0)
+  if (total_count == 0)
     {
       /* We could use obstack_specify_allocation here instead, but
 	 gdb_obstack.h specifies the allocation/deallocation
 	 functions.  */
-      obstack_init (&bcache->cache);
+      obstack_init (&cache);
     }
 
   /* If our average chain length is too high, expand the hash table.  */
-  if (bcache->unique_count >= bcache->num_buckets * CHAIN_LENGTH_THRESHOLD)
-    expand_hash_table (bcache);
+  if (unique_count >= num_buckets * CHAIN_LENGTH_THRESHOLD)
+    expand_hash_table ();
 
-  bcache->total_count++;
-  bcache->total_size += length;
+  total_count++;
+  total_size += length;
 
-  full_hash = bcache->hash_function (addr, length);
+  full_hash = hash_function (addr, length);
 
   half_hash = (full_hash >> 16);
-  hash_index = full_hash % bcache->num_buckets;
+  hash_index = full_hash % num_buckets;
 
   /* Search the hash bucket for a string identical to the caller's.
      As a short-circuit first compare the upper part of each hash
      values.  */
-  for (s = bcache->bucket[hash_index]; s; s = s->next)
+  for (s = bucket[hash_index]; s; s = s->next)
     {
       if (s->half_hash == half_hash)
 	{
 	  if (s->length == length
-	      && bcache->compare_function (&s->d.data, addr, length))
+	      && compare_function (&s->d.data, addr, length))
 	    return &s->d.data;
 	  else
-	    bcache->half_hash_miss_count++;
+	    half_hash_miss_count++;
 	}
     }
 
   /* The user's string isn't in the list.  Insert it after *ps.  */
   {
     struct bstring *newobj
-      = (struct bstring *) obstack_alloc (&bcache->cache,
+      = (struct bstring *) obstack_alloc (&cache,
 					  BSTRING_SIZE (length));
 
     memcpy (&newobj->d.data, addr, length);
     newobj->length = length;
-    newobj->next = bcache->bucket[hash_index];
+    newobj->next = bucket[hash_index];
     newobj->half_hash = half_hash;
-    bcache->bucket[hash_index] = newobj;
+    bucket[hash_index] = newobj;
 
-    bcache->unique_count++;
-    bcache->unique_size += length;
-    bcache->structure_size += BSTRING_SIZE (length);
+    unique_count++;
+    unique_size += length;
+    structure_size += BSTRING_SIZE (length);
 
     if (added)
       *added = 1;
@@ -289,51 +235,19 @@ bcache_full (const void *addr, int length, struct bcache *bcache, int *added)
 /* Compare the byte string at ADDR1 of lenght LENGHT to the
    string at ADDR2.  Return 1 if they are equal.  */
 
-static int
-bcache_compare (const void *addr1, const void *addr2, int length)
+int
+bcache::compare (const void *addr1, const void *addr2, int length)
 {
   return memcmp (addr1, addr2, length) == 0;
 }
 
-/* Allocating and freeing bcaches.  */
-
-/* Allocated a bcache.  HASH_FUNCTION and COMPARE_FUNCTION can be used
-   to pass in custom hash, and compare functions to be used by this
-   bcache.  If HASH_FUNCTION is NULL hash() is used and if
-   COMPARE_FUNCTION is NULL memcmp() is used.  */
-
-struct bcache *
-bcache_xmalloc (unsigned long (*hash_function)(const void *, int length),
-                int (*compare_function)(const void *, 
-					const void *, 
-					int length))
-{
-  /* Allocate the bcache pre-zeroed.  */
-  struct bcache *b = XCNEW (struct bcache);
-
-  if (hash_function)
-    b->hash_function = hash_function;
-  else
-    b->hash_function = hash;
-
-  if (compare_function)
-    b->compare_function = compare_function;
-  else
-    b->compare_function = bcache_compare;
-  return b;
-}
-
 /* Free all the storage associated with BCACHE.  */
-void
-bcache_xfree (struct bcache *bcache)
+bcache::~bcache ()
 {
-  if (bcache == NULL)
-    return;
   /* Only free the obstack if we actually initialized it.  */
-  if (bcache->total_count > 0)
-    obstack_free (&bcache->cache, 0);
-  xfree (bcache->bucket);
-  xfree (bcache);
+  if (total_count > 0)
+    obstack_free (&cache, 0);
+  xfree (bucket);
 }
 
 
@@ -356,7 +270,7 @@ print_percentage (int portion, int total)
    BCACHE holds.  Statistics are printed using `printf_filtered' and
    its ilk.  */
 void
-print_bcache_statistics (struct bcache *c, const char *type)
+bcache::print_statistics (const char *type)
 {
   int occupied_buckets;
   int max_chain_length;
@@ -368,15 +282,15 @@ print_bcache_statistics (struct bcache *c, const char *type)
      lengths, and measure chain lengths.  */
   {
     unsigned int b;
-    int *chain_length = XCNEWVEC (int, c->num_buckets + 1);
-    int *entry_size = XCNEWVEC (int, c->unique_count + 1);
+    int *chain_length = XCNEWVEC (int, num_buckets + 1);
+    int *entry_size = XCNEWVEC (int, unique_count + 1);
     int stringi = 0;
 
     occupied_buckets = 0;
 
-    for (b = 0; b < c->num_buckets; b++)
+    for (b = 0; b < num_buckets; b++)
       {
-	struct bstring *s = c->bucket[b];
+	struct bstring *s = bucket[b];
 
 	chain_length[b] = 0;
 
@@ -386,9 +300,9 @@ print_bcache_statistics (struct bcache *c, const char *type)
 	    
 	    while (s)
 	      {
-		gdb_assert (b < c->num_buckets);
+		gdb_assert (b < num_buckets);
 		chain_length[b]++;
-		gdb_assert (stringi < c->unique_count);
+		gdb_assert (stringi < unique_count);
 		entry_size[stringi++] = s->length;
 		s = s->next;
 	      }
@@ -397,25 +311,25 @@ print_bcache_statistics (struct bcache *c, const char *type)
 
     /* To compute the median, we need the set of chain lengths
        sorted.  */
-    qsort (chain_length, c->num_buckets, sizeof (chain_length[0]),
+    qsort (chain_length, num_buckets, sizeof (chain_length[0]),
 	   compare_positive_ints);
-    qsort (entry_size, c->unique_count, sizeof (entry_size[0]),
+    qsort (entry_size, unique_count, sizeof (entry_size[0]),
 	   compare_positive_ints);
 
-    if (c->num_buckets > 0)
+    if (num_buckets > 0)
       {
-	max_chain_length = chain_length[c->num_buckets - 1];
-	median_chain_length = chain_length[c->num_buckets / 2];
+	max_chain_length = chain_length[num_buckets - 1];
+	median_chain_length = chain_length[num_buckets / 2];
       }
     else
       {
 	max_chain_length = 0;
 	median_chain_length = 0;
       }
-    if (c->unique_count > 0)
+    if (unique_count > 0)
       {
-	max_entry_size = entry_size[c->unique_count - 1];
-	median_entry_size = entry_size[c->unique_count / 2];
+	max_entry_size = entry_size[unique_count - 1];
+	median_entry_size = entry_size[unique_count / 2];
       }
     else
       {
@@ -428,22 +342,22 @@ print_bcache_statistics (struct bcache *c, const char *type)
   }
 
   printf_filtered (_("  Cached '%s' statistics:\n"), type);
-  printf_filtered (_("    Total object count:  %ld\n"), c->total_count);
-  printf_filtered (_("    Unique object count: %lu\n"), c->unique_count);
+  printf_filtered (_("    Total object count:  %ld\n"), total_count);
+  printf_filtered (_("    Unique object count: %lu\n"), unique_count);
   printf_filtered (_("    Percentage of duplicates, by count: "));
-  print_percentage (c->total_count - c->unique_count, c->total_count);
+  print_percentage (total_count - unique_count, total_count);
   printf_filtered ("\n");
 
-  printf_filtered (_("    Total object size:   %ld\n"), c->total_size);
-  printf_filtered (_("    Unique object size:  %ld\n"), c->unique_size);
+  printf_filtered (_("    Total object size:   %ld\n"), total_size);
+  printf_filtered (_("    Unique object size:  %ld\n"), unique_size);
   printf_filtered (_("    Percentage of duplicates, by size:  "));
-  print_percentage (c->total_size - c->unique_size, c->total_size);
+  print_percentage (total_size - unique_size, total_size);
   printf_filtered ("\n");
 
   printf_filtered (_("    Max entry size:     %d\n"), max_entry_size);
   printf_filtered (_("    Average entry size: "));
-  if (c->unique_count > 0)
-    printf_filtered ("%ld\n", c->unique_size / c->unique_count);
+  if (unique_count > 0)
+    printf_filtered ("%ld\n", unique_size / unique_count);
   else
     /* i18n: "Average entry size: (not applicable)".  */
     printf_filtered (_("(not applicable)\n"));    
@@ -452,28 +366,28 @@ print_bcache_statistics (struct bcache *c, const char *type)
 
   printf_filtered (_("    \
 Total memory used by bcache, including overhead: %ld\n"),
-		   c->structure_size);
+		   structure_size);
   printf_filtered (_("    Percentage memory overhead: "));
-  print_percentage (c->structure_size - c->unique_size, c->unique_size);
+  print_percentage (structure_size - unique_size, unique_size);
   printf_filtered (_("    Net memory savings:         "));
-  print_percentage (c->total_size - c->structure_size, c->total_size);
+  print_percentage (total_size - structure_size, total_size);
   printf_filtered ("\n");
 
   printf_filtered (_("    Hash table size:           %3d\n"), 
-		   c->num_buckets);
+		   num_buckets);
   printf_filtered (_("    Hash table expands:        %lu\n"),
-		   c->expand_count);
+		   expand_count);
   printf_filtered (_("    Hash table hashes:         %lu\n"),
-		   c->total_count + c->expand_hash_count);
+		   total_count + expand_hash_count);
   printf_filtered (_("    Half hash misses:          %lu\n"),
-		   c->half_hash_miss_count);
+		   half_hash_miss_count);
   printf_filtered (_("    Hash table population:     "));
-  print_percentage (occupied_buckets, c->num_buckets);
+  print_percentage (occupied_buckets, num_buckets);
   printf_filtered (_("    Median hash chain length:  %3d\n"),
 		   median_chain_length);
   printf_filtered (_("    Average hash chain length: "));
-  if (c->num_buckets > 0)
-    printf_filtered ("%3lu\n", c->unique_count / c->num_buckets);
+  if (num_buckets > 0)
+    printf_filtered ("%3lu\n", unique_count / num_buckets);
   else
     /* i18n: "Average hash chain length: (not applicable)".  */
     printf_filtered (_("(not applicable)\n"));
@@ -483,9 +397,9 @@ Total memory used by bcache, including overhead: %ld\n"),
 }
 
 int
-bcache_memory_used (struct bcache *bcache)
+bcache::memory_used ()
 {
-  if (bcache->total_count == 0)
+  if (total_count == 0)
     return 0;
-  return obstack_memory_used (&bcache->cache);
+  return obstack_memory_used (&cache);
 }
diff --git a/gdb/bcache.h b/gdb/bcache.h
index aa0147926c6..2725a994533 100644
--- a/gdb/bcache.h
+++ b/gdb/bcache.h
@@ -136,41 +136,89 @@
   
 */
 
-
-struct bcache;
-
-/* Find a copy of the LENGTH bytes at ADDR in BCACHE.  If BCACHE has
-   never seen those bytes before, add a copy of them to BCACHE.  In
-   either case, return a pointer to BCACHE's copy of that string.
-   Since the cached value is ment to be read-only, return a const
-   buffer.  */
-extern const void *bcache (const void *addr, int length,
-			   struct bcache *bcache);
-
-/* Like bcache, but if ADDED is not NULL, set *ADDED to true if the
-   bytes were newly added to the cache, or to false if the bytes were
-   found in the cache.  */
-extern const void *bcache_full (const void *addr, int length,
-				struct bcache *bcache, int *added);
-
-/* Free all the storage used by BCACHE.  */
-extern void bcache_xfree (struct bcache *bcache);
-
-/* Create a new bcache object.  */
-extern struct bcache *bcache_xmalloc (
-    unsigned long (*hash_function)(const void *, int length),
-    int (*compare_function)(const void *, const void *, int length));
-
-/* Print statistics on BCACHE's memory usage and efficacity at
-   eliminating duplication.  TYPE should be a string describing the
-   kind of data BCACHE holds.  Statistics are printed using
-   `printf_filtered' and its ilk.  */
-extern void print_bcache_statistics (struct bcache *bcache, const char *type);
-extern int bcache_memory_used (struct bcache *bcache);
+struct bstring;
 
 /* The hash functions */
-extern unsigned long hash(const void *addr, int length);
+extern unsigned long hash (const void *addr, int length);
 extern unsigned long hash_continue (const void *addr, int length,
                                     unsigned long h);
 
+struct bcache
+{
+  /* Allocate a bcache.  HASH_FN and COMPARE_FN can be used to pass in
+     custom hash, and compare functions to be used by this bcache.  If
+     HASH_FUNCTION is NULL hash() is used and if COMPARE_FUNCTION is
+     NULL memcmp() is used.  */
+
+  explicit bcache (unsigned long (*hash_fn)(const void *,
+					    int length) = nullptr,
+		   int (*compare_fn)(const void *, const void *,
+				     int length) = nullptr)
+    : hash_function (hash_fn == nullptr ? hash : hash_fn),
+      compare_function (compare_fn == nullptr ? compare : compare_fn)
+  {
+  }
+
+  ~bcache ();
+
+  /* Find a copy of the LENGTH bytes at ADDR in BCACHE.  If BCACHE has
+     never seen those bytes before, add a copy of them to BCACHE.  In
+     either case, return a pointer to BCACHE's copy of that string.
+     Since the cached value is ment to be read-only, return a const
+     buffer.  If ADDED is not NULL, set *ADDED to true if the bytes
+     were newly added to the cache, or to false if the bytes were
+     found in the cache.  */
+
+  const void *insert (const void *addr, int length, int *added = nullptr);
+
+  /* Print statistics on this bcache's memory usage and efficacity at
+     eliminating duplication.  TYPE should be a string describing the
+     kind of data this bcache holds.  Statistics are printed using
+     `printf_filtered' and its ilk.  */
+  void print_statistics (const char *type);
+  int memory_used ();
+
+private:
+
+  /* All the bstrings are allocated here.  */
+  struct obstack cache {};
+
+  /* How many hash buckets we're using.  */
+  unsigned int num_buckets = 0;
+
+  /* Hash buckets.  This table is allocated using malloc, so when we
+     grow the table we can return the old table to the system.  */
+  struct bstring **bucket = nullptr;
+
+  /* Statistics.  */
+  unsigned long unique_count = 0;	/* number of unique strings */
+  long total_count = 0;	/* total number of strings cached, including dups */
+  long unique_size = 0;	/* size of unique strings, in bytes */
+  long total_size = 0;      /* total number of bytes cached, including dups */
+  long structure_size = 0;	/* total size of bcache, including infrastructure */
+  /* Number of times that the hash table is expanded and hence
+     re-built, and the corresponding number of times that a string is
+     [re]hashed as part of entering it into the expanded table.  The
+     total number of hashes can be computed by adding TOTAL_COUNT to
+     expand_hash_count.  */
+  unsigned long expand_count = 0;
+  unsigned long expand_hash_count = 0;
+  /* Number of times that the half-hash compare hit (compare the upper
+     16 bits of hash values) hit, but the corresponding combined
+     length/data compare missed.  */
+  unsigned long half_hash_miss_count = 0;
+
+  /* Hash function to be used for this bcache object.  */
+  unsigned long (*hash_function)(const void *addr, int length);
+
+  /* Compare function to be used for this bcache object.  */
+  int (*compare_function)(const void *, const void *, int length);
+
+  /* Default compare function.  */
+  static int compare (const void *addr1, const void *addr2, int length);
+
+  /* Expand the hash table.  */
+  void expand_hash_table ();
+};
+
 #endif /* BCACHE_H */
diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index bd0f25e061e..9a23c8f5254 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -122,7 +122,7 @@ buildsym_compunit::get_macro_table ()
 {
   if (m_pending_macros == nullptr)
     m_pending_macros = new_macro_table (&m_objfile->per_bfd->storage_obstack,
-					m_objfile->per_bfd->macro_cache,
+					&m_objfile->per_bfd->macro_cache,
 					m_compunit_symtab);
   return m_pending_macros;
 }
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 2d6cb353fbb..0c59dcd2042 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -46,7 +46,6 @@
 #include "macrotab.h"
 #include "language.h"
 #include "complaints.h"
-#include "bcache.h"
 #include "dwarf2expr.h"
 #include "dwarf2loc.h"
 #include "cp-support.h"
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 8fc6692b112..55a16bb2f8e 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -334,8 +334,8 @@ elf_symtab_read (minimal_symbol_reader &reader,
       if (sym->flags & BSF_FILE)
 	{
 	  filesymname
-	    = (const char *) bcache (sym->name, strlen (sym->name) + 1,
-				     objfile->per_bfd->filename_cache);
+	    = ((const char *) objfile->per_bfd->filename_cache.insert
+	       (sym->name, strlen (sym->name) + 1));
 	}
       else if (sym->flags & BSF_SECTION_SYM)
 	continue;
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index b5f269241c4..8e48587caa4 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -3732,7 +3732,7 @@ check_types_worklist (std::vector<type_equality_entry> *worklist,
 
       /* If the type pair has already been visited, we know it is
 	 ok.  */
-      bcache_full (&entry, sizeof (entry), cache, &added);
+      cache->insert (&entry, sizeof (entry), &added);
       if (!added)
 	continue;
 
@@ -3749,9 +3749,6 @@ check_types_worklist (std::vector<type_equality_entry> *worklist,
 bool
 types_deeply_equal (struct type *type1, struct type *type2)
 {
-  struct gdb_exception except = exception_none;
-  bool result = false;
-  struct bcache *cache;
   std::vector<type_equality_entry> worklist;
 
   gdb_assert (type1 != NULL && type2 != NULL);
@@ -3760,31 +3757,9 @@ types_deeply_equal (struct type *type1, struct type *type2)
   if (type1 == type2)
     return true;
 
-  cache = bcache_xmalloc (NULL, NULL);
-
+  struct bcache cache (nullptr, nullptr);
   worklist.emplace_back (type1, type2);
-
-  /* check_types_worklist calls several nested helper functions, some
-     of which can raise a GDB exception, so we just check and rethrow
-     here.  If there is a GDB exception, a comparison is not capable
-     (or trusted), so exit.  */
-  TRY
-    {
-      result = check_types_worklist (&worklist, cache);
-    }
-  CATCH (ex, RETURN_MASK_ALL)
-    {
-      except = ex;
-    }
-  END_CATCH
-
-  bcache_xfree (cache);
-
-  /* Rethrow if there was a problem.  */
-  if (except.reason < 0)
-    throw_exception (except);
-
-  return result;
+  return check_types_worklist (&worklist, &cache);
 }
 
 /* Allocated status of type TYPE.  Return zero if type TYPE is allocated.
diff --git a/gdb/macroexp.c b/gdb/macroexp.c
index a588cc836fe..33a72a7271f 100644
--- a/gdb/macroexp.c
+++ b/gdb/macroexp.c
@@ -19,7 +19,6 @@
 
 #include "defs.h"
 #include "gdb_obstack.h"
-#include "bcache.h"
 #include "macrotab.h"
 #include "macroexp.h"
 #include "c-lang.h"
diff --git a/gdb/macrotab.c b/gdb/macrotab.c
index fa3061616bd..90f29439c09 100644
--- a/gdb/macrotab.c
+++ b/gdb/macrotab.c
@@ -113,7 +113,7 @@ static const void *
 macro_bcache (struct macro_table *t, const void *addr, int len)
 {
   if (t->bcache)
-    return bcache (addr, len, t->bcache);
+    return t->bcache->insert (addr, len);
   else
     {
       void *copy = xmalloc (len);
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 34b271e86de..4091b42dbf1 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -157,8 +157,6 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
       if (abfd != NULL)
 	storage->gdbarch = gdbarch_from_bfd (abfd);
 
-      storage->filename_cache = bcache_xmalloc (NULL, NULL);
-      storage->macro_cache = bcache_xmalloc (NULL, NULL);
       storage->language_of_main = language_unknown;
     }
 
@@ -170,8 +168,6 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
 static void
 free_objfile_per_bfd_storage (struct objfile_per_bfd_storage *storage)
 {
-  bcache_xfree (storage->filename_cache);
-  bcache_xfree (storage->macro_cache);
   if (storage->demangled_names_hash)
     htab_delete (storage->demangled_names_hash);
   storage->~objfile_per_bfd_storage ();
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index a10781f598e..c5ce9eec955 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -240,11 +240,11 @@ struct objfile_per_bfd_storage
 
   /* Byte cache for file names.  */
 
-  struct bcache *filename_cache = NULL;
+  struct bcache filename_cache;
 
   /* Byte cache for macros.  */
 
-  struct bcache *macro_cache = NULL;
+  struct bcache macro_cache;
 
   /* The gdbarch associated with the BFD.  Note that this gdbarch is
      determined solely from BFD information, without looking at target
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 17db29759c4..96b4fa0bf88 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -26,7 +26,6 @@
 #include "source.h"
 #include "addrmap.h"
 #include "gdbtypes.h"
-#include "bcache.h"
 #include "ui-out.h"
 #include "command.h"
 #include "readline/readline.h"
@@ -38,11 +37,6 @@
 #include <algorithm>
 #include <set>
 
-struct psymbol_bcache
-{
-  struct bcache *bcache;
-};
-
 static struct partial_symbol *match_partial_symbol (struct objfile *,
 						    struct partial_symtab *,
 						    int,
@@ -67,14 +61,16 @@ static struct compunit_symtab *psymtab_to_symtab (struct objfile *objfile,
 
 \f
 
+static unsigned long psymbol_hash (const void *addr, int length);
+static int psymbol_compare (const void *addr1, const void *addr2, int length);
+
 psymtab_storage::psymtab_storage ()
-  : psymbol_cache (psymbol_bcache_init ())
+  : psymbol_cache (psymbol_hash, psymbol_compare)
 {
 }
 
 psymtab_storage::~psymtab_storage ()
 {
-  psymbol_bcache_free (psymbol_cache);
 }
 
 /* See psymtab.h.  */
@@ -1589,52 +1585,6 @@ psymbol_compare (const void *addr1, const void *addr2, int length)
           && sym1->name == sym2->name);
 }
 
-/* Initialize a partial symbol bcache.  */
-
-struct psymbol_bcache *
-psymbol_bcache_init (void)
-{
-  struct psymbol_bcache *bcache = XCNEW (struct psymbol_bcache);
-
-  bcache->bcache = bcache_xmalloc (psymbol_hash, psymbol_compare);
-  return bcache;
-}
-
-/* Free a partial symbol bcache.  */
-
-void
-psymbol_bcache_free (struct psymbol_bcache *bcache)
-{
-  if (bcache == NULL)
-    return;
-
-  bcache_xfree (bcache->bcache);
-  xfree (bcache);
-}
-
-/* Return the internal bcache of the psymbol_bcache BCACHE.  */
-
-struct bcache *
-psymbol_bcache_get_bcache (struct psymbol_bcache *bcache)
-{
-  return bcache->bcache;
-}
-
-/* Find a copy of the SYM in BCACHE.  If BCACHE has never seen this
-   symbol before, add a copy to BCACHE.  In either case, return a pointer
-   to BCACHE's copy of the symbol.  If optional ADDED is not NULL, return
-   1 in case of new entry or 0 if returning an old entry.  */
-
-static struct partial_symbol *
-psymbol_bcache_full (struct partial_symbol *sym,
-                     struct psymbol_bcache *bcache,
-                     int *added)
-{
-  return ((struct partial_symbol *)
-	  bcache_full (sym, sizeof (struct partial_symbol), bcache->bcache,
-		       added));
-}
-
 /* Helper function, initialises partial symbol structure and stashes
    it into objfile's bcache.  Note that our caching mechanism will
    use all fields of struct partial_symbol to determine hash value of the
@@ -1664,9 +1614,9 @@ add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
   symbol_set_names (&psymbol, name, namelength, copy_name, objfile->per_bfd);
 
   /* Stash the partial symbol away in the cache.  */
-  return psymbol_bcache_full (&psymbol,
-			      objfile->partial_symtabs->psymbol_cache,
-			      added);
+  return ((struct partial_symbol *)
+	  objfile->partial_symtabs->psymbol_cache.insert
+	  (&psymbol, sizeof (struct partial_symbol), added));
 }
 
 /* Helper function, adds partial symbol to the given partial symbol list.  */
@@ -1741,8 +1691,8 @@ allocate_psymtab (const char *filename, struct objfile *objfile)
     = objfile->partial_symtabs->allocate_psymtab ();
 
   psymtab->filename
-    = (const char *) bcache (filename, strlen (filename) + 1,
-			     objfile->per_bfd->filename_cache);
+    = ((const char *) objfile->per_bfd->filename_cache.insert
+       (filename, strlen (filename) + 1));
   psymtab->compunit_symtab = NULL;
 
   if (symtab_create_debug)
diff --git a/gdb/psymtab.h b/gdb/psymtab.h
index 3ee5eee0b65..c761fa72222 100644
--- a/gdb/psymtab.h
+++ b/gdb/psymtab.h
@@ -23,13 +23,10 @@
 #include "gdb_obstack.h"
 #include "symfile.h"
 #include "common/next-iterator.h"
+#include "bcache.h"
 
 struct partial_symbol;
 
-/* A bcache for partial symbols.  */
-
-struct psymbol_bcache;
-
 /* An instance of this class manages the partial symbol tables and
    partial symbols for a given objfile.
 
@@ -119,7 +116,7 @@ public:
   /* A byte cache where we can stash arbitrary "chunks" of bytes that
      will not change.  */
 
-  struct psymbol_bcache *psymbol_cache;
+  struct bcache psymbol_cache;
 
   /* Vectors of all partial symbols read in from file.  The actual data
      is stored in the objfile_obstack.  */
@@ -140,10 +137,6 @@ private:
 };
 
 
-extern struct psymbol_bcache *psymbol_bcache_init (void);
-extern void psymbol_bcache_free (struct psymbol_bcache *);
-extern struct bcache *psymbol_bcache_get_bcache (struct psymbol_bcache *);
-
 extern const struct quick_symbol_functions psym_functions;
 
 extern const struct quick_symbol_functions dwarf2_gdb_index_functions;
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index ac33465c13b..3f340dbf20d 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -44,7 +44,6 @@
 #include "target-float.h"
 #include "cp-abi.h"
 #include "cp-support.h"
-#include "bcache.h"
 #include <ctype.h>
 
 #include "stabsread.h"
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 61483824f63..2214f16b431 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2795,8 +2795,8 @@ allocate_symtab (struct compunit_symtab *cust, const char *filename)
     = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symtab);
 
   symtab->filename
-    = (const char *) bcache (filename, strlen (filename) + 1,
-			     objfile->per_bfd->filename_cache);
+    = ((const char *) objfile->per_bfd->filename_cache.insert
+       (filename, strlen (filename) + 1));
   symtab->fullname = NULL;
   symtab->language = deduce_language_from_filename (filename);
 
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index bb4fdfd1ed9..cb0b5a52e47 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -69,13 +69,11 @@ print_symbol_bcache_statistics (void)
 	QUIT;
 	printf_filtered (_("Byte cache statistics for '%s':\n"),
 			 objfile_name (objfile));
-	print_bcache_statistics
-	  (psymbol_bcache_get_bcache (objfile->partial_symtabs->psymbol_cache),
-	   "partial symbol cache");
-	print_bcache_statistics (objfile->per_bfd->macro_cache,
-				 "preprocessor macro cache");
-	print_bcache_statistics (objfile->per_bfd->filename_cache,
-				 "file name cache");
+	objfile->partial_symtabs->psymbol_cache.print_statistics
+	  ("partial symbol cache");
+	objfile->per_bfd->macro_cache.print_statistics
+	  ("preprocessor macro cache");
+	objfile->per_bfd->filename_cache.print_statistics ("file name cache");
       }
 }
 
@@ -136,12 +134,11 @@ print_objfile_statistics (void)
 						       ->storage_obstack)));
       printf_filtered
 	(_("  Total memory used for psymbol cache: %d\n"),
-	 bcache_memory_used (psymbol_bcache_get_bcache
-			     (objfile->partial_symtabs->psymbol_cache)));
+	 objfile->partial_symtabs->psymbol_cache.memory_used ());
       printf_filtered (_("  Total memory used for macro cache: %d\n"),
-		       bcache_memory_used (objfile->per_bfd->macro_cache));
+		       objfile->per_bfd->macro_cache.memory_used ());
       printf_filtered (_("  Total memory used for file name cache: %d\n"),
-		       bcache_memory_used (objfile->per_bfd->filename_cache));
+		       objfile->per_bfd->filename_cache.memory_used ());
     }
 }
 

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

* Re: [PATCH v2 22/22] Introduce and use bcache_up
  2019-03-07 16:54     ` Tom Tromey
@ 2019-03-07 17:09       ` Pedro Alves
  2019-03-07 17:42         ` Tom Tromey
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2019-03-07 17:09 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On 03/07/2019 04:53 PM, Tom Tromey wrote:
>>> This introduces a new bcache_up typedef, which is a unique_ptr
>>> specialization for managing a bcache.  Then, this changes various
>>> spots to use this object, rather than manually calling bcache_xfree.
>>> This lets us remove a try/catch that only existed to call
>>> bcache_xfree.
> 
> Pedro> I won't object, but is seems to me that it'd be better to
> Pedro> make bcache_xmalloc / bcache_free ctors/dtors of struct bcache,
> Pedro> and then we'd allocate a bcache object on the stack (and likewise
> Pedro> hold bcache objects in structures instead of bcache pointers).
> 
> I broke this one out from the series.  Let me know what you think.

Thanks!

Almost perfect.  On a quick skim, the only thing missing is
renaming the now-private fields of struct bcache to have
an "m_" prefix.  I think it's worth doing here since it'll
end up touching many of the same same lines you're already
touching in bcache.c.  LGTM with that change.

Thanks,
Pedro Alves

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

* Re: [PATCH v2 22/22] Introduce and use bcache_up
  2019-03-07 17:09       ` Pedro Alves
@ 2019-03-07 17:42         ` Tom Tromey
  0 siblings, 0 replies; 58+ messages in thread
From: Tom Tromey @ 2019-03-07 17:42 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, gdb-patches

>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Pedro> Almost perfect.  On a quick skim, the only thing missing is
Pedro> renaming the now-private fields of struct bcache to have
Pedro> an "m_" prefix.  I think it's worth doing here since it'll
Pedro> end up touching many of the same same lines you're already
Pedro> touching in bcache.c.  LGTM with that change.

Thanks.  Here is what I am checking in.

Tom

commit a99eb1e73b1b66143d670322ebeb639c82468aed
Author: Tom Tromey <tom@tromey.com>
Date:   Thu Mar 7 04:20:19 2019 -0700

    C++-ify bcache
    
    This somewhat C++-ifies bcache.  It replaces bcache_xmalloc and
    bcache_xfree with constructors; changes some functions into methods;
    and changes various structures to include a bcache directly (as
    opposed to a pointer to a bcache).
    
    Tested by the buildbot.
    
    gdb/ChangeLog
    2019-03-07  Tom Tromey  <tom@tromey.com>
    
            * symmisc.c (print_symbol_bcache_statistics): Update.
            (print_objfile_statistics): Update.
            * symfile.c (allocate_symtab): Update.
            * stabsread.c: Don't include bcache.h.
            * psymtab.h (struct psymbol_bcache): Don't declare.
            (class psymtab_storage) <psymbol_cache>: Now a bcache.
            (psymbol_bcache_init, psymbol_bcache_free)
            (psymbol_bcache_get_bcache): Don't declare.
            * psymtab.c (struct psymbol_bcache): Remove.
            (psymtab_storage::psymtab_storage): Update.
            (psymtab_storage::~psymtab_storage): Update.
            (psymbol_bcache_init, psymbol_bcache_free)
            (psymbol_bcache_get_bcache, psymbol_bcache_full): Remove.
            (add_psymbol_to_bcache): Update.
            (allocate_psymtab): Update.
            * objfiles.h (struct objfile_per_bfd_storage) <filename_cache,
            macro_cache>: No longer pointers.
            * objfiles.c (get_objfile_bfd_data): Don't call bcache_xmalloc.
            (free_objfile_per_bfd_storage): Don't call bcache_xfree.
            * macrotab.c (macro_bcache): Update.
            * macroexp.c: Don't include bcache.h.
            * gdbtypes.c (check_types_worklist): Update.
            (types_deeply_equal): Remove TRY/CATCH.  Update.
            * elfread.c (elf_symtab_read): Update.
            * dwarf2read.c: Don't include bcache.h.
            * buildsym.c (buildsym_compunit::get_macro_table): Update.
            * bcache.h (bcache, bcache_full, bcache_xffree, bcache_xmalloc)
            (print_bcache_statistics, bcache_memory_used): Don't declare.
            (struct bcache): Move from bcache.c.  Add constructor, destructor,
            methods.  Rename all data members.
            * bcache.c (struct bcache): Move to bcache.h.
            (bcache::expand_hash_table): Rename from expand_hash_table.
            (bcache): Remove.
            (bcache::insert): Rename from bcache_full.
            (bcache::compare): Rename from bcache_compare.
            (bcache_xmalloc): Remove.
            (bcache::~bcache): Rename from bcache_xfree.
            (bcache::print_statistics): Rename from print_bcache_statistics.
            (bcache::memory_used): Rename from bcache_memory_used.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d3d6e5b4ee6..331bc740c6f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,45 @@
+2019-03-07  Tom Tromey  <tom@tromey.com>
+
+	* symmisc.c (print_symbol_bcache_statistics): Update.
+	(print_objfile_statistics): Update.
+	* symfile.c (allocate_symtab): Update.
+	* stabsread.c: Don't include bcache.h.
+	* psymtab.h (struct psymbol_bcache): Don't declare.
+	(class psymtab_storage) <psymbol_cache>: Now a bcache.
+	(psymbol_bcache_init, psymbol_bcache_free)
+	(psymbol_bcache_get_bcache): Don't declare.
+	* psymtab.c (struct psymbol_bcache): Remove.
+	(psymtab_storage::psymtab_storage): Update.
+	(psymtab_storage::~psymtab_storage): Update.
+	(psymbol_bcache_init, psymbol_bcache_free)
+	(psymbol_bcache_get_bcache, psymbol_bcache_full): Remove.
+	(add_psymbol_to_bcache): Update.
+	(allocate_psymtab): Update.
+	* objfiles.h (struct objfile_per_bfd_storage) <filename_cache,
+	macro_cache>: No longer pointers.
+	* objfiles.c (get_objfile_bfd_data): Don't call bcache_xmalloc.
+	(free_objfile_per_bfd_storage): Don't call bcache_xfree.
+	* macrotab.c (macro_bcache): Update.
+	* macroexp.c: Don't include bcache.h.
+	* gdbtypes.c (check_types_worklist): Update.
+	(types_deeply_equal): Remove TRY/CATCH.  Update.
+	* elfread.c (elf_symtab_read): Update.
+	* dwarf2read.c: Don't include bcache.h.
+	* buildsym.c (buildsym_compunit::get_macro_table): Update.
+	* bcache.h (bcache, bcache_full, bcache_xffree, bcache_xmalloc)
+	(print_bcache_statistics, bcache_memory_used): Don't declare.
+	(struct bcache): Move from bcache.c.  Add constructor, destructor,
+	methods.  Rename all data members.
+	* bcache.c (struct bcache): Move to bcache.h.
+	(bcache::expand_hash_table): Rename from expand_hash_table.
+	(bcache): Remove.
+	(bcache::insert): Rename from bcache_full.
+	(bcache::compare): Rename from bcache_compare.
+	(bcache_xmalloc): Remove.
+	(bcache::~bcache): Rename from bcache_xfree.
+	(bcache::print_statistics): Rename from print_bcache_statistics.
+	(bcache::memory_used): Rename from bcache_memory_used.
+
 2019-03-07  Andrew Burgess  <andrew.burgess@embecosm.com>
 
 	* f-lang.c (value_from_host_double): Moved to...
diff --git a/gdb/bcache.c b/gdb/bcache.c
index 1430953ac62..14a78474962 100644
--- a/gdb/bcache.c
+++ b/gdb/bcache.c
@@ -49,48 +49,6 @@ struct bstring
   d;
 };
 
-
-/* The structure for a bcache itself.  The bcache is initialized, in
-   bcache_xmalloc(), by filling it with zeros and then setting the
-   corresponding obstack's malloc() and free() methods.  */
-
-struct bcache
-{
-  /* All the bstrings are allocated here.  */
-  struct obstack cache;
-
-  /* How many hash buckets we're using.  */
-  unsigned int num_buckets;
-  
-  /* Hash buckets.  This table is allocated using malloc, so when we
-     grow the table we can return the old table to the system.  */
-  struct bstring **bucket;
-
-  /* Statistics.  */
-  unsigned long unique_count;	/* number of unique strings */
-  long total_count;	/* total number of strings cached, including dups */
-  long unique_size;	/* size of unique strings, in bytes */
-  long total_size;      /* total number of bytes cached, including dups */
-  long structure_size;	/* total size of bcache, including infrastructure */
-  /* Number of times that the hash table is expanded and hence
-     re-built, and the corresponding number of times that a string is
-     [re]hashed as part of entering it into the expanded table.  The
-     total number of hashes can be computed by adding TOTAL_COUNT to
-     expand_hash_count.  */
-  unsigned long expand_count;
-  unsigned long expand_hash_count;
-  /* Number of times that the half-hash compare hit (compare the upper
-     16 bits of hash values) hit, but the corresponding combined
-     length/data compare missed.  */
-  unsigned long half_hash_miss_count;
-
-  /* Hash function to be used for this bcache object.  */
-  unsigned long (*hash_function)(const void *addr, int length);
-
-  /* Compare function to be used for this bcache object.  */
-  int (*compare_function)(const void *, const void *, int length);
-};
-
 /* The old hash function was stolen from SDBM. This is what DB 3.0
    uses now, and is better than the old one.  */
 \f
@@ -123,8 +81,8 @@ hash_continue (const void *addr, int length, unsigned long h)
    resize our hash table.  */
 #define CHAIN_LENGTH_THRESHOLD (5)
 
-static void
-expand_hash_table (struct bcache *bcache)
+void
+bcache::expand_hash_table ()
 {
   /* A table of good hash table sizes.  Whenever we grow, we pick the
      next larger size from this table.  sizes[i] is close to 1 << (i+10),
@@ -143,13 +101,13 @@ expand_hash_table (struct bcache *bcache)
 
   /* Count the stats.  Every unique item needs to be re-hashed and
      re-entered.  */
-  bcache->expand_count++;
-  bcache->expand_hash_count += bcache->unique_count;
+  m_expand_count++;
+  m_expand_hash_count += m_unique_count;
 
   /* Find the next size.  */
-  new_num_buckets = bcache->num_buckets * 2;
+  new_num_buckets = m_num_buckets * 2;
   for (i = 0; i < (sizeof (sizes) / sizeof (sizes[0])); i++)
-    if (sizes[i] > bcache->num_buckets)
+    if (sizes[i] > m_num_buckets)
       {
 	new_num_buckets = sizes[i];
 	break;
@@ -162,23 +120,21 @@ expand_hash_table (struct bcache *bcache)
     new_buckets = (struct bstring **) xmalloc (new_size);
     memset (new_buckets, 0, new_size);
 
-    bcache->structure_size -= (bcache->num_buckets
-			       * sizeof (bcache->bucket[0]));
-    bcache->structure_size += new_size;
+    m_structure_size -= m_num_buckets * sizeof (m_bucket[0]);
+    m_structure_size += new_size;
   }
 
   /* Rehash all existing strings.  */
-  for (i = 0; i < bcache->num_buckets; i++)
+  for (i = 0; i < m_num_buckets; i++)
     {
       struct bstring *s, *next;
 
-      for (s = bcache->bucket[i]; s; s = next)
+      for (s = m_bucket[i]; s; s = next)
 	{
 	  struct bstring **new_bucket;
 	  next = s->next;
 
-	  new_bucket = &new_buckets[(bcache->hash_function (&s->d.data,
-							    s->length)
+	  new_bucket = &new_buckets[(m_hash_function (&s->d.data, s->length)
 				     % new_num_buckets)];
 	  s->next = *new_bucket;
 	  *new_bucket = s;
@@ -186,10 +142,9 @@ expand_hash_table (struct bcache *bcache)
     }
 
   /* Plug in the new table.  */
-  if (bcache->bucket)
-    xfree (bcache->bucket);
-  bcache->bucket = new_buckets;
-  bcache->num_buckets = new_num_buckets;
+  xfree (m_bucket);
+  m_bucket = new_buckets;
+  m_num_buckets = new_num_buckets;
 }
 
 \f
@@ -199,15 +154,6 @@ expand_hash_table (struct bcache *bcache)
    is N bytes long.  */
 #define BSTRING_SIZE(n) (offsetof (struct bstring, d.data) + (n))
 
-/* Find a copy of the LENGTH bytes at ADDR in BCACHE.  If BCACHE has
-   never seen those bytes before, add a copy of them to BCACHE.  In
-   either case, return a pointer to BCACHE's copy of that string.  */
-const void *
-bcache (const void *addr, int length, struct bcache *cache)
-{
-  return bcache_full (addr, length, cache, NULL);
-}
-
 /* Find a copy of the LENGTH bytes at ADDR in BCACHE.  If BCACHE has
    never seen those bytes before, add a copy of them to BCACHE.  In
    either case, return a pointer to BCACHE's copy of that string.  If
@@ -215,7 +161,7 @@ bcache (const void *addr, int length, struct bcache *cache)
    returning an old entry.  */
 
 const void *
-bcache_full (const void *addr, int length, struct bcache *bcache, int *added)
+bcache::insert (const void *addr, int length, int *added)
 {
   unsigned long full_hash;
   unsigned short half_hash;
@@ -227,56 +173,56 @@ bcache_full (const void *addr, int length, struct bcache *bcache, int *added)
 
   /* Lazily initialize the obstack.  This can save quite a bit of
      memory in some cases.  */
-  if (bcache->total_count == 0)
+  if (m_total_count == 0)
     {
       /* We could use obstack_specify_allocation here instead, but
 	 gdb_obstack.h specifies the allocation/deallocation
 	 functions.  */
-      obstack_init (&bcache->cache);
+      obstack_init (&m_cache);
     }
 
   /* If our average chain length is too high, expand the hash table.  */
-  if (bcache->unique_count >= bcache->num_buckets * CHAIN_LENGTH_THRESHOLD)
-    expand_hash_table (bcache);
+  if (m_unique_count >= m_num_buckets * CHAIN_LENGTH_THRESHOLD)
+    expand_hash_table ();
 
-  bcache->total_count++;
-  bcache->total_size += length;
+  m_total_count++;
+  m_total_size += length;
 
-  full_hash = bcache->hash_function (addr, length);
+  full_hash = m_hash_function (addr, length);
 
   half_hash = (full_hash >> 16);
-  hash_index = full_hash % bcache->num_buckets;
+  hash_index = full_hash % m_num_buckets;
 
-  /* Search the hash bucket for a string identical to the caller's.
+  /* Search the hash m_bucket for a string identical to the caller's.
      As a short-circuit first compare the upper part of each hash
      values.  */
-  for (s = bcache->bucket[hash_index]; s; s = s->next)
+  for (s = m_bucket[hash_index]; s; s = s->next)
     {
       if (s->half_hash == half_hash)
 	{
 	  if (s->length == length
-	      && bcache->compare_function (&s->d.data, addr, length))
+	      && m_compare_function (&s->d.data, addr, length))
 	    return &s->d.data;
 	  else
-	    bcache->half_hash_miss_count++;
+	    m_half_hash_miss_count++;
 	}
     }
 
   /* The user's string isn't in the list.  Insert it after *ps.  */
   {
     struct bstring *newobj
-      = (struct bstring *) obstack_alloc (&bcache->cache,
+      = (struct bstring *) obstack_alloc (&m_cache,
 					  BSTRING_SIZE (length));
 
     memcpy (&newobj->d.data, addr, length);
     newobj->length = length;
-    newobj->next = bcache->bucket[hash_index];
+    newobj->next = m_bucket[hash_index];
     newobj->half_hash = half_hash;
-    bcache->bucket[hash_index] = newobj;
+    m_bucket[hash_index] = newobj;
 
-    bcache->unique_count++;
-    bcache->unique_size += length;
-    bcache->structure_size += BSTRING_SIZE (length);
+    m_unique_count++;
+    m_unique_size += length;
+    m_structure_size += BSTRING_SIZE (length);
 
     if (added)
       *added = 1;
@@ -289,51 +235,19 @@ bcache_full (const void *addr, int length, struct bcache *bcache, int *added)
 /* Compare the byte string at ADDR1 of lenght LENGHT to the
    string at ADDR2.  Return 1 if they are equal.  */
 
-static int
-bcache_compare (const void *addr1, const void *addr2, int length)
+int
+bcache::compare (const void *addr1, const void *addr2, int length)
 {
   return memcmp (addr1, addr2, length) == 0;
 }
 
-/* Allocating and freeing bcaches.  */
-
-/* Allocated a bcache.  HASH_FUNCTION and COMPARE_FUNCTION can be used
-   to pass in custom hash, and compare functions to be used by this
-   bcache.  If HASH_FUNCTION is NULL hash() is used and if
-   COMPARE_FUNCTION is NULL memcmp() is used.  */
-
-struct bcache *
-bcache_xmalloc (unsigned long (*hash_function)(const void *, int length),
-                int (*compare_function)(const void *, 
-					const void *, 
-					int length))
-{
-  /* Allocate the bcache pre-zeroed.  */
-  struct bcache *b = XCNEW (struct bcache);
-
-  if (hash_function)
-    b->hash_function = hash_function;
-  else
-    b->hash_function = hash;
-
-  if (compare_function)
-    b->compare_function = compare_function;
-  else
-    b->compare_function = bcache_compare;
-  return b;
-}
-
 /* Free all the storage associated with BCACHE.  */
-void
-bcache_xfree (struct bcache *bcache)
+bcache::~bcache ()
 {
-  if (bcache == NULL)
-    return;
   /* Only free the obstack if we actually initialized it.  */
-  if (bcache->total_count > 0)
-    obstack_free (&bcache->cache, 0);
-  xfree (bcache->bucket);
-  xfree (bcache);
+  if (m_total_count > 0)
+    obstack_free (&m_cache, 0);
+  xfree (m_bucket);
 }
 
 
@@ -356,7 +270,7 @@ print_percentage (int portion, int total)
    BCACHE holds.  Statistics are printed using `printf_filtered' and
    its ilk.  */
 void
-print_bcache_statistics (struct bcache *c, const char *type)
+bcache::print_statistics (const char *type)
 {
   int occupied_buckets;
   int max_chain_length;
@@ -368,15 +282,15 @@ print_bcache_statistics (struct bcache *c, const char *type)
      lengths, and measure chain lengths.  */
   {
     unsigned int b;
-    int *chain_length = XCNEWVEC (int, c->num_buckets + 1);
-    int *entry_size = XCNEWVEC (int, c->unique_count + 1);
+    int *chain_length = XCNEWVEC (int, m_num_buckets + 1);
+    int *entry_size = XCNEWVEC (int, m_unique_count + 1);
     int stringi = 0;
 
     occupied_buckets = 0;
 
-    for (b = 0; b < c->num_buckets; b++)
+    for (b = 0; b < m_num_buckets; b++)
       {
-	struct bstring *s = c->bucket[b];
+	struct bstring *s = m_bucket[b];
 
 	chain_length[b] = 0;
 
@@ -386,9 +300,9 @@ print_bcache_statistics (struct bcache *c, const char *type)
 	    
 	    while (s)
 	      {
-		gdb_assert (b < c->num_buckets);
+		gdb_assert (b < m_num_buckets);
 		chain_length[b]++;
-		gdb_assert (stringi < c->unique_count);
+		gdb_assert (stringi < m_unique_count);
 		entry_size[stringi++] = s->length;
 		s = s->next;
 	      }
@@ -397,25 +311,25 @@ print_bcache_statistics (struct bcache *c, const char *type)
 
     /* To compute the median, we need the set of chain lengths
        sorted.  */
-    qsort (chain_length, c->num_buckets, sizeof (chain_length[0]),
+    qsort (chain_length, m_num_buckets, sizeof (chain_length[0]),
 	   compare_positive_ints);
-    qsort (entry_size, c->unique_count, sizeof (entry_size[0]),
+    qsort (entry_size, m_unique_count, sizeof (entry_size[0]),
 	   compare_positive_ints);
 
-    if (c->num_buckets > 0)
+    if (m_num_buckets > 0)
       {
-	max_chain_length = chain_length[c->num_buckets - 1];
-	median_chain_length = chain_length[c->num_buckets / 2];
+	max_chain_length = chain_length[m_num_buckets - 1];
+	median_chain_length = chain_length[m_num_buckets / 2];
       }
     else
       {
 	max_chain_length = 0;
 	median_chain_length = 0;
       }
-    if (c->unique_count > 0)
+    if (m_unique_count > 0)
       {
-	max_entry_size = entry_size[c->unique_count - 1];
-	median_entry_size = entry_size[c->unique_count / 2];
+	max_entry_size = entry_size[m_unique_count - 1];
+	median_entry_size = entry_size[m_unique_count / 2];
       }
     else
       {
@@ -427,23 +341,23 @@ print_bcache_statistics (struct bcache *c, const char *type)
     xfree (entry_size);
   }
 
-  printf_filtered (_("  Cached '%s' statistics:\n"), type);
-  printf_filtered (_("    Total object count:  %ld\n"), c->total_count);
-  printf_filtered (_("    Unique object count: %lu\n"), c->unique_count);
+  printf_filtered (_("  M_Cached '%s' statistics:\n"), type);
+  printf_filtered (_("    Total object count:  %ld\n"), m_total_count);
+  printf_filtered (_("    Unique object count: %lu\n"), m_unique_count);
   printf_filtered (_("    Percentage of duplicates, by count: "));
-  print_percentage (c->total_count - c->unique_count, c->total_count);
+  print_percentage (m_total_count - m_unique_count, m_total_count);
   printf_filtered ("\n");
 
-  printf_filtered (_("    Total object size:   %ld\n"), c->total_size);
-  printf_filtered (_("    Unique object size:  %ld\n"), c->unique_size);
+  printf_filtered (_("    Total object size:   %ld\n"), m_total_size);
+  printf_filtered (_("    Unique object size:  %ld\n"), m_unique_size);
   printf_filtered (_("    Percentage of duplicates, by size:  "));
-  print_percentage (c->total_size - c->unique_size, c->total_size);
+  print_percentage (m_total_size - m_unique_size, m_total_size);
   printf_filtered ("\n");
 
   printf_filtered (_("    Max entry size:     %d\n"), max_entry_size);
   printf_filtered (_("    Average entry size: "));
-  if (c->unique_count > 0)
-    printf_filtered ("%ld\n", c->unique_size / c->unique_count);
+  if (m_unique_count > 0)
+    printf_filtered ("%ld\n", m_unique_size / m_unique_count);
   else
     /* i18n: "Average entry size: (not applicable)".  */
     printf_filtered (_("(not applicable)\n"));    
@@ -452,28 +366,28 @@ print_bcache_statistics (struct bcache *c, const char *type)
 
   printf_filtered (_("    \
 Total memory used by bcache, including overhead: %ld\n"),
-		   c->structure_size);
+		   m_structure_size);
   printf_filtered (_("    Percentage memory overhead: "));
-  print_percentage (c->structure_size - c->unique_size, c->unique_size);
+  print_percentage (m_structure_size - m_unique_size, m_unique_size);
   printf_filtered (_("    Net memory savings:         "));
-  print_percentage (c->total_size - c->structure_size, c->total_size);
+  print_percentage (m_total_size - m_structure_size, m_total_size);
   printf_filtered ("\n");
 
   printf_filtered (_("    Hash table size:           %3d\n"), 
-		   c->num_buckets);
+		   m_num_buckets);
   printf_filtered (_("    Hash table expands:        %lu\n"),
-		   c->expand_count);
+		   m_expand_count);
   printf_filtered (_("    Hash table hashes:         %lu\n"),
-		   c->total_count + c->expand_hash_count);
+		   m_total_count + m_expand_hash_count);
   printf_filtered (_("    Half hash misses:          %lu\n"),
-		   c->half_hash_miss_count);
+		   m_half_hash_miss_count);
   printf_filtered (_("    Hash table population:     "));
-  print_percentage (occupied_buckets, c->num_buckets);
+  print_percentage (occupied_buckets, m_num_buckets);
   printf_filtered (_("    Median hash chain length:  %3d\n"),
 		   median_chain_length);
   printf_filtered (_("    Average hash chain length: "));
-  if (c->num_buckets > 0)
-    printf_filtered ("%3lu\n", c->unique_count / c->num_buckets);
+  if (m_num_buckets > 0)
+    printf_filtered ("%3lu\n", m_unique_count / m_num_buckets);
   else
     /* i18n: "Average hash chain length: (not applicable)".  */
     printf_filtered (_("(not applicable)\n"));
@@ -483,9 +397,9 @@ Total memory used by bcache, including overhead: %ld\n"),
 }
 
 int
-bcache_memory_used (struct bcache *bcache)
+bcache::memory_used ()
 {
-  if (bcache->total_count == 0)
+  if (m_total_count == 0)
     return 0;
-  return obstack_memory_used (&bcache->cache);
+  return obstack_memory_used (&m_cache);
 }
diff --git a/gdb/bcache.h b/gdb/bcache.h
index aa0147926c6..15dcc63440f 100644
--- a/gdb/bcache.h
+++ b/gdb/bcache.h
@@ -136,41 +136,89 @@
   
 */
 
-
-struct bcache;
-
-/* Find a copy of the LENGTH bytes at ADDR in BCACHE.  If BCACHE has
-   never seen those bytes before, add a copy of them to BCACHE.  In
-   either case, return a pointer to BCACHE's copy of that string.
-   Since the cached value is ment to be read-only, return a const
-   buffer.  */
-extern const void *bcache (const void *addr, int length,
-			   struct bcache *bcache);
-
-/* Like bcache, but if ADDED is not NULL, set *ADDED to true if the
-   bytes were newly added to the cache, or to false if the bytes were
-   found in the cache.  */
-extern const void *bcache_full (const void *addr, int length,
-				struct bcache *bcache, int *added);
-
-/* Free all the storage used by BCACHE.  */
-extern void bcache_xfree (struct bcache *bcache);
-
-/* Create a new bcache object.  */
-extern struct bcache *bcache_xmalloc (
-    unsigned long (*hash_function)(const void *, int length),
-    int (*compare_function)(const void *, const void *, int length));
-
-/* Print statistics on BCACHE's memory usage and efficacity at
-   eliminating duplication.  TYPE should be a string describing the
-   kind of data BCACHE holds.  Statistics are printed using
-   `printf_filtered' and its ilk.  */
-extern void print_bcache_statistics (struct bcache *bcache, const char *type);
-extern int bcache_memory_used (struct bcache *bcache);
+struct bstring;
 
 /* The hash functions */
-extern unsigned long hash(const void *addr, int length);
+extern unsigned long hash (const void *addr, int length);
 extern unsigned long hash_continue (const void *addr, int length,
                                     unsigned long h);
 
+struct bcache
+{
+  /* Allocate a bcache.  HASH_FN and COMPARE_FN can be used to pass in
+     custom hash, and compare functions to be used by this bcache.  If
+     HASH_FUNCTION is NULL hash() is used and if COMPARE_FUNCTION is
+     NULL memcmp() is used.  */
+
+  explicit bcache (unsigned long (*hash_fn)(const void *,
+					    int length) = nullptr,
+		   int (*compare_fn)(const void *, const void *,
+				     int length) = nullptr)
+    : m_hash_function (hash_fn == nullptr ? hash : hash_fn),
+      m_compare_function (compare_fn == nullptr ? compare : compare_fn)
+  {
+  }
+
+  ~bcache ();
+
+  /* Find a copy of the LENGTH bytes at ADDR in BCACHE.  If BCACHE has
+     never seen those bytes before, add a copy of them to BCACHE.  In
+     either case, return a pointer to BCACHE's copy of that string.
+     Since the cached value is ment to be read-only, return a const
+     buffer.  If ADDED is not NULL, set *ADDED to true if the bytes
+     were newly added to the cache, or to false if the bytes were
+     found in the cache.  */
+
+  const void *insert (const void *addr, int length, int *added = nullptr);
+
+  /* Print statistics on this bcache's memory usage and efficacity at
+     eliminating duplication.  TYPE should be a string describing the
+     kind of data this bcache holds.  Statistics are printed using
+     `printf_filtered' and its ilk.  */
+  void print_statistics (const char *type);
+  int memory_used ();
+
+private:
+
+  /* All the bstrings are allocated here.  */
+  struct obstack m_cache {};
+
+  /* How many hash buckets we're using.  */
+  unsigned int m_num_buckets = 0;
+
+  /* Hash buckets.  This table is allocated using malloc, so when we
+     grow the table we can return the old table to the system.  */
+  struct bstring **m_bucket = nullptr;
+
+  /* Statistics.  */
+  unsigned long m_unique_count = 0;	/* number of unique strings */
+  long m_total_count = 0;	/* total number of strings cached, including dups */
+  long m_unique_size = 0;	/* size of unique strings, in bytes */
+  long m_total_size = 0;      /* total number of bytes cached, including dups */
+  long m_structure_size = 0;	/* total size of bcache, including infrastructure */
+  /* Number of times that the hash table is expanded and hence
+     re-built, and the corresponding number of times that a string is
+     [re]hashed as part of entering it into the expanded table.  The
+     total number of hashes can be computed by adding TOTAL_COUNT to
+     expand_hash_count.  */
+  unsigned long m_expand_count = 0;
+  unsigned long m_expand_hash_count = 0;
+  /* Number of times that the half-hash compare hit (compare the upper
+     16 bits of hash values) hit, but the corresponding combined
+     length/data compare missed.  */
+  unsigned long m_half_hash_miss_count = 0;
+
+  /* Hash function to be used for this bcache object.  */
+  unsigned long (*m_hash_function)(const void *addr, int length);
+
+  /* Compare function to be used for this bcache object.  */
+  int (*m_compare_function)(const void *, const void *, int length);
+
+  /* Default compare function.  */
+  static int compare (const void *addr1, const void *addr2, int length);
+
+  /* Expand the hash table.  */
+  void expand_hash_table ();
+};
+
 #endif /* BCACHE_H */
diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index bd0f25e061e..9a23c8f5254 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -122,7 +122,7 @@ buildsym_compunit::get_macro_table ()
 {
   if (m_pending_macros == nullptr)
     m_pending_macros = new_macro_table (&m_objfile->per_bfd->storage_obstack,
-					m_objfile->per_bfd->macro_cache,
+					&m_objfile->per_bfd->macro_cache,
 					m_compunit_symtab);
   return m_pending_macros;
 }
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 2d6cb353fbb..0c59dcd2042 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -46,7 +46,6 @@
 #include "macrotab.h"
 #include "language.h"
 #include "complaints.h"
-#include "bcache.h"
 #include "dwarf2expr.h"
 #include "dwarf2loc.h"
 #include "cp-support.h"
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 8fc6692b112..55a16bb2f8e 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -334,8 +334,8 @@ elf_symtab_read (minimal_symbol_reader &reader,
       if (sym->flags & BSF_FILE)
 	{
 	  filesymname
-	    = (const char *) bcache (sym->name, strlen (sym->name) + 1,
-				     objfile->per_bfd->filename_cache);
+	    = ((const char *) objfile->per_bfd->filename_cache.insert
+	       (sym->name, strlen (sym->name) + 1));
 	}
       else if (sym->flags & BSF_SECTION_SYM)
 	continue;
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index b5f269241c4..8e48587caa4 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -3732,7 +3732,7 @@ check_types_worklist (std::vector<type_equality_entry> *worklist,
 
       /* If the type pair has already been visited, we know it is
 	 ok.  */
-      bcache_full (&entry, sizeof (entry), cache, &added);
+      cache->insert (&entry, sizeof (entry), &added);
       if (!added)
 	continue;
 
@@ -3749,9 +3749,6 @@ check_types_worklist (std::vector<type_equality_entry> *worklist,
 bool
 types_deeply_equal (struct type *type1, struct type *type2)
 {
-  struct gdb_exception except = exception_none;
-  bool result = false;
-  struct bcache *cache;
   std::vector<type_equality_entry> worklist;
 
   gdb_assert (type1 != NULL && type2 != NULL);
@@ -3760,31 +3757,9 @@ types_deeply_equal (struct type *type1, struct type *type2)
   if (type1 == type2)
     return true;
 
-  cache = bcache_xmalloc (NULL, NULL);
-
+  struct bcache cache (nullptr, nullptr);
   worklist.emplace_back (type1, type2);
-
-  /* check_types_worklist calls several nested helper functions, some
-     of which can raise a GDB exception, so we just check and rethrow
-     here.  If there is a GDB exception, a comparison is not capable
-     (or trusted), so exit.  */
-  TRY
-    {
-      result = check_types_worklist (&worklist, cache);
-    }
-  CATCH (ex, RETURN_MASK_ALL)
-    {
-      except = ex;
-    }
-  END_CATCH
-
-  bcache_xfree (cache);
-
-  /* Rethrow if there was a problem.  */
-  if (except.reason < 0)
-    throw_exception (except);
-
-  return result;
+  return check_types_worklist (&worklist, &cache);
 }
 
 /* Allocated status of type TYPE.  Return zero if type TYPE is allocated.
diff --git a/gdb/macroexp.c b/gdb/macroexp.c
index a588cc836fe..33a72a7271f 100644
--- a/gdb/macroexp.c
+++ b/gdb/macroexp.c
@@ -19,7 +19,6 @@
 
 #include "defs.h"
 #include "gdb_obstack.h"
-#include "bcache.h"
 #include "macrotab.h"
 #include "macroexp.h"
 #include "c-lang.h"
diff --git a/gdb/macrotab.c b/gdb/macrotab.c
index fa3061616bd..90f29439c09 100644
--- a/gdb/macrotab.c
+++ b/gdb/macrotab.c
@@ -113,7 +113,7 @@ static const void *
 macro_bcache (struct macro_table *t, const void *addr, int len)
 {
   if (t->bcache)
-    return bcache (addr, len, t->bcache);
+    return t->bcache->insert (addr, len);
   else
     {
       void *copy = xmalloc (len);
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 34b271e86de..4091b42dbf1 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -157,8 +157,6 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
       if (abfd != NULL)
 	storage->gdbarch = gdbarch_from_bfd (abfd);
 
-      storage->filename_cache = bcache_xmalloc (NULL, NULL);
-      storage->macro_cache = bcache_xmalloc (NULL, NULL);
       storage->language_of_main = language_unknown;
     }
 
@@ -170,8 +168,6 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
 static void
 free_objfile_per_bfd_storage (struct objfile_per_bfd_storage *storage)
 {
-  bcache_xfree (storage->filename_cache);
-  bcache_xfree (storage->macro_cache);
   if (storage->demangled_names_hash)
     htab_delete (storage->demangled_names_hash);
   storage->~objfile_per_bfd_storage ();
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index a10781f598e..c5ce9eec955 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -240,11 +240,11 @@ struct objfile_per_bfd_storage
 
   /* Byte cache for file names.  */
 
-  struct bcache *filename_cache = NULL;
+  struct bcache filename_cache;
 
   /* Byte cache for macros.  */
 
-  struct bcache *macro_cache = NULL;
+  struct bcache macro_cache;
 
   /* The gdbarch associated with the BFD.  Note that this gdbarch is
      determined solely from BFD information, without looking at target
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 17db29759c4..96b4fa0bf88 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -26,7 +26,6 @@
 #include "source.h"
 #include "addrmap.h"
 #include "gdbtypes.h"
-#include "bcache.h"
 #include "ui-out.h"
 #include "command.h"
 #include "readline/readline.h"
@@ -38,11 +37,6 @@
 #include <algorithm>
 #include <set>
 
-struct psymbol_bcache
-{
-  struct bcache *bcache;
-};
-
 static struct partial_symbol *match_partial_symbol (struct objfile *,
 						    struct partial_symtab *,
 						    int,
@@ -67,14 +61,16 @@ static struct compunit_symtab *psymtab_to_symtab (struct objfile *objfile,
 
 \f
 
+static unsigned long psymbol_hash (const void *addr, int length);
+static int psymbol_compare (const void *addr1, const void *addr2, int length);
+
 psymtab_storage::psymtab_storage ()
-  : psymbol_cache (psymbol_bcache_init ())
+  : psymbol_cache (psymbol_hash, psymbol_compare)
 {
 }
 
 psymtab_storage::~psymtab_storage ()
 {
-  psymbol_bcache_free (psymbol_cache);
 }
 
 /* See psymtab.h.  */
@@ -1589,52 +1585,6 @@ psymbol_compare (const void *addr1, const void *addr2, int length)
           && sym1->name == sym2->name);
 }
 
-/* Initialize a partial symbol bcache.  */
-
-struct psymbol_bcache *
-psymbol_bcache_init (void)
-{
-  struct psymbol_bcache *bcache = XCNEW (struct psymbol_bcache);
-
-  bcache->bcache = bcache_xmalloc (psymbol_hash, psymbol_compare);
-  return bcache;
-}
-
-/* Free a partial symbol bcache.  */
-
-void
-psymbol_bcache_free (struct psymbol_bcache *bcache)
-{
-  if (bcache == NULL)
-    return;
-
-  bcache_xfree (bcache->bcache);
-  xfree (bcache);
-}
-
-/* Return the internal bcache of the psymbol_bcache BCACHE.  */
-
-struct bcache *
-psymbol_bcache_get_bcache (struct psymbol_bcache *bcache)
-{
-  return bcache->bcache;
-}
-
-/* Find a copy of the SYM in BCACHE.  If BCACHE has never seen this
-   symbol before, add a copy to BCACHE.  In either case, return a pointer
-   to BCACHE's copy of the symbol.  If optional ADDED is not NULL, return
-   1 in case of new entry or 0 if returning an old entry.  */
-
-static struct partial_symbol *
-psymbol_bcache_full (struct partial_symbol *sym,
-                     struct psymbol_bcache *bcache,
-                     int *added)
-{
-  return ((struct partial_symbol *)
-	  bcache_full (sym, sizeof (struct partial_symbol), bcache->bcache,
-		       added));
-}
-
 /* Helper function, initialises partial symbol structure and stashes
    it into objfile's bcache.  Note that our caching mechanism will
    use all fields of struct partial_symbol to determine hash value of the
@@ -1664,9 +1614,9 @@ add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
   symbol_set_names (&psymbol, name, namelength, copy_name, objfile->per_bfd);
 
   /* Stash the partial symbol away in the cache.  */
-  return psymbol_bcache_full (&psymbol,
-			      objfile->partial_symtabs->psymbol_cache,
-			      added);
+  return ((struct partial_symbol *)
+	  objfile->partial_symtabs->psymbol_cache.insert
+	  (&psymbol, sizeof (struct partial_symbol), added));
 }
 
 /* Helper function, adds partial symbol to the given partial symbol list.  */
@@ -1741,8 +1691,8 @@ allocate_psymtab (const char *filename, struct objfile *objfile)
     = objfile->partial_symtabs->allocate_psymtab ();
 
   psymtab->filename
-    = (const char *) bcache (filename, strlen (filename) + 1,
-			     objfile->per_bfd->filename_cache);
+    = ((const char *) objfile->per_bfd->filename_cache.insert
+       (filename, strlen (filename) + 1));
   psymtab->compunit_symtab = NULL;
 
   if (symtab_create_debug)
diff --git a/gdb/psymtab.h b/gdb/psymtab.h
index 3ee5eee0b65..c761fa72222 100644
--- a/gdb/psymtab.h
+++ b/gdb/psymtab.h
@@ -23,13 +23,10 @@
 #include "gdb_obstack.h"
 #include "symfile.h"
 #include "common/next-iterator.h"
+#include "bcache.h"
 
 struct partial_symbol;
 
-/* A bcache for partial symbols.  */
-
-struct psymbol_bcache;
-
 /* An instance of this class manages the partial symbol tables and
    partial symbols for a given objfile.
 
@@ -119,7 +116,7 @@ public:
   /* A byte cache where we can stash arbitrary "chunks" of bytes that
      will not change.  */
 
-  struct psymbol_bcache *psymbol_cache;
+  struct bcache psymbol_cache;
 
   /* Vectors of all partial symbols read in from file.  The actual data
      is stored in the objfile_obstack.  */
@@ -140,10 +137,6 @@ private:
 };
 
 
-extern struct psymbol_bcache *psymbol_bcache_init (void);
-extern void psymbol_bcache_free (struct psymbol_bcache *);
-extern struct bcache *psymbol_bcache_get_bcache (struct psymbol_bcache *);
-
 extern const struct quick_symbol_functions psym_functions;
 
 extern const struct quick_symbol_functions dwarf2_gdb_index_functions;
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index ac33465c13b..3f340dbf20d 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -44,7 +44,6 @@
 #include "target-float.h"
 #include "cp-abi.h"
 #include "cp-support.h"
-#include "bcache.h"
 #include <ctype.h>
 
 #include "stabsread.h"
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 61483824f63..2214f16b431 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2795,8 +2795,8 @@ allocate_symtab (struct compunit_symtab *cust, const char *filename)
     = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symtab);
 
   symtab->filename
-    = (const char *) bcache (filename, strlen (filename) + 1,
-			     objfile->per_bfd->filename_cache);
+    = ((const char *) objfile->per_bfd->filename_cache.insert
+       (filename, strlen (filename) + 1));
   symtab->fullname = NULL;
   symtab->language = deduce_language_from_filename (filename);
 
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index bb4fdfd1ed9..cb0b5a52e47 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -69,13 +69,11 @@ print_symbol_bcache_statistics (void)
 	QUIT;
 	printf_filtered (_("Byte cache statistics for '%s':\n"),
 			 objfile_name (objfile));
-	print_bcache_statistics
-	  (psymbol_bcache_get_bcache (objfile->partial_symtabs->psymbol_cache),
-	   "partial symbol cache");
-	print_bcache_statistics (objfile->per_bfd->macro_cache,
-				 "preprocessor macro cache");
-	print_bcache_statistics (objfile->per_bfd->filename_cache,
-				 "file name cache");
+	objfile->partial_symtabs->psymbol_cache.print_statistics
+	  ("partial symbol cache");
+	objfile->per_bfd->macro_cache.print_statistics
+	  ("preprocessor macro cache");
+	objfile->per_bfd->filename_cache.print_statistics ("file name cache");
       }
 }
 
@@ -136,12 +134,11 @@ print_objfile_statistics (void)
 						       ->storage_obstack)));
       printf_filtered
 	(_("  Total memory used for psymbol cache: %d\n"),
-	 bcache_memory_used (psymbol_bcache_get_bcache
-			     (objfile->partial_symtabs->psymbol_cache)));
+	 objfile->partial_symtabs->psymbol_cache.memory_used ());
       printf_filtered (_("  Total memory used for macro cache: %d\n"),
-		       bcache_memory_used (objfile->per_bfd->macro_cache));
+		       objfile->per_bfd->macro_cache.memory_used ());
       printf_filtered (_("  Total memory used for file name cache: %d\n"),
-		       bcache_memory_used (objfile->per_bfd->filename_cache));
+		       objfile->per_bfd->filename_cache.memory_used ());
     }
 }
 

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

* Re: [PATCH v2 14/22] Simplify exception handling
  2019-02-27 20:19 ` [PATCH v2 14/22] Simplify exception handling Tom Tromey
@ 2019-04-02 22:07   ` Pedro Alves
  0 siblings, 0 replies; 58+ messages in thread
From: Pedro Alves @ 2019-04-02 22:07 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/27/2019 08:18 PM, Tom Tromey wrote:
> Now that cleanups have been removed, TRY/CATCH can't be SJLJ-based any
> more.  This patch simplifies the exception handling code, by removing
> the non-working variants.
> 
> Note that the "pure" C++ exception handling code is removed as well; 

That's fine, if we're getting rid of TRY/CATCH.

That mode is/was useful to catch issues like these:
 https://sourceware.org/ml/gdb-patches/2017-10/msg00080.html
but if we're getting rid of TRY/CATCH, then it won't be
needed anymore, of course.

> I
> think the route forward must be to change exceptions to be
> self-destructing, so that try_scope_depth can simply be removed.

Agreed.

> 
> Some longjmp-based code remains, as it is needed to throw an exception
> through readline.
> 
> gdb/ChangeLog
> 2019-02-27  Tom Tromey  <tom@tromey.com>
> 
> 	* common/common-exceptions.h (GDB_XCPT_SJMP, GDB_XCPT_TRY)
> 	(GDB_XCPT_RAW_TRY, GDB_XCPT): Remove.
> 	(TRY, CATCH, END_CATCH): Remove some definitions.
> 	* common/common-exceptions.c: Don't use GDB_XCPT.
> 	(catcher_list_size): Remove.
> 	(throw_exception, throw_it): Simplify.

Looks fine.  I spotted a few comments that need updating,
even after the whole series is in, but no need to stress about it.
It's fine to tackle it with a final pass after the series.

I have comments for the other patches, will send them as soon
as possible.

Thanks,
Pedro Alves

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

* Re: [PATCH v2 15/22] Make exceptions use std::string and be self-managing
  2019-02-27 20:19 ` [PATCH v2 15/22] Make exceptions use std::string and be self-managing Tom Tromey
@ 2019-04-03 16:20   ` Pedro Alves
  2019-04-03 17:58     ` Tom Tromey
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2019-04-03 16:20 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/27/2019 08:18 PM, Tom Tromey wrote:
> This changes the exception's "message" member to be a std::string.
> This allows removing the stack of exception messages, because now
> exceptions will self-destruct when needed.
> 
> Note that this does increase the cost of copying an exception.  This
> will be somewhat addressed in a subsequent patch.

I have a concern about this patch, something that I alluded to
at the Cauldron.

I think it'd be better if we followed what the C++ standard library
does, and make copy constructor/assignment op nothrow:

  "Each standard library class T that derives from class exception shall have
  a publicly accessible copy constructor and a publicly accessible copy
  assignment operator that do not exit with an exception." (N4659/21.8.2)

See: 
  https://stackoverflow.com/questions/21644735/should-i-declare-the-copy-constructor-of-my-exceptions-noexcept

I believe that rule exists because throwing an exception copies
the exception object, and if that copy operation throws, then the process
is terminated with std::terminate().  Copying a std::string may require
a heap allocation, which likely doesn't throw on most OSs with
over-commit enabled, but it pedantically can.

I think fixing this isn't hard, so I think we should do it from the
start -- instead of gdb_exception holding a std::string, hold a
reference counted immutable heap-allocated C string.

>  		throw_error (except.error,
>  			     _("unable to read value of %s (%s)"),
> -			     xvz_name, except.message);
> +			     xvz_name, except.message.c_str ());

Since you're touching most (all?) lines that refer to "message",
did you consider adding a "what()" method, to model what
std::exception has?

  const char *what() const noexcept;

Maybe that helps with newcomers' familiarity?

Thanks,
Pedro Alves

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

* Re: [PATCH v2 16/22] Rewrite TRY/CATCH
  2019-02-27 20:19 ` [PATCH v2 16/22] Rewrite TRY/CATCH Tom Tromey
@ 2019-04-03 17:03   ` Pedro Alves
  2019-04-03 18:02     ` Tom Tromey
  0 siblings, 1 reply; 58+ messages in thread
From: Pedro Alves @ 2019-04-03 17:03 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/27/2019 08:18 PM, Tom Tromey wrote:
> This rewrites gdb's TRY/CATCH to plain C++ try/catch.  The patch was
> largely written by script, though one change (to a comment in
> common-exceptions.h) was reverted by hand.

I reviewed this one and the next as a squashed view (any reason you
didn't squash them?), and it looks OK to me, though personally
I'd much prefer to see the explicit "struct" in:

 -  CATCH (e, RETURN_MASK_ERROR)
 +  catch (const struct gdb_exception_error &e)

go away, and end up with just:

   catch (const gdb_exception_error &e)

Thanks,
Pedro Alves

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

* Re: [PATCH v2 19/22] Make exception throwing a bit more efficient
  2019-02-27 20:19 ` [PATCH v2 19/22] Make exception throwing a bit more efficient Tom Tromey
@ 2019-04-03 17:04   ` Pedro Alves
  0 siblings, 0 replies; 58+ messages in thread
From: Pedro Alves @ 2019-04-03 17:04 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/27/2019 08:18 PM, Tom Tromey wrote:
> This makes exception throwing a bit more efficient, by removing some
> copies.  This is good now that exceptions are more expensive to copy.

It will no longer be expensive if we follow the idea of
refcounting the message, but seems fine anyway.

> -static ATTRIBUTE_NORETURN void
> -throw_exception_cxx (struct gdb_exception exception)
> +void
> +throw_exception (const struct gdb_exception &exception)

 throw_exception (const gdb_exception &exception)

?

> --- a/gdb/common/common-exceptions.h
> +++ b/gdb/common/common-exceptions.h
> @@ -205,7 +205,7 @@ struct gdb_quit_bad_alloc
>  /* Throw an exception (as described by "struct gdb_exception"),
>     landing in the inner most containing exception handler established
>     using TRY/CATCH.  */
> -extern void throw_exception (struct gdb_exception exception)
> +extern void throw_exception (const struct gdb_exception &exception)
>       ATTRIBUTE_NORETURN;
Ditto.

Thanks,
Pedro Alves

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

* Re: [PATCH v2 18/22] Remove some now-dead exception code
  2019-02-27 20:19 ` [PATCH v2 18/22] Remove some now-dead exception code Tom Tromey
@ 2019-04-03 17:04   ` Pedro Alves
  0 siblings, 0 replies; 58+ messages in thread
From: Pedro Alves @ 2019-04-03 17:04 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/27/2019 08:18 PM, Tom Tromey wrote:
> After the rewriting to use try/catch, some of the exception code is
> now unused.  This patch removes that code.
> 
> gdb/ChangeLog
> 2019-02-27  Tom Tromey  <tom@tromey.com>
> 
> 	* common/common-exceptions.h (exception_rethrow): Don't declare.
> 	(TRY_SJLJ): Update comment.
> 	(TRY, CATCH, END_CATCH): Remove.
> 	* common/common-exceptions.c (exception_rethrow): Remove.

OK.

Thanks,
Pedro Alves

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

* Re: [PATCH v2 20/22] Replace throw_exception with throw in some cases
  2019-02-27 20:19 ` [PATCH v2 20/22] Replace throw_exception with throw in some cases Tom Tromey
@ 2019-04-03 17:05   ` Pedro Alves
  0 siblings, 0 replies; 58+ messages in thread
From: Pedro Alves @ 2019-04-03 17:05 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 02/27/2019 08:18 PM, Tom Tromey wrote:
> This replaces throw_exception with "throw;" when possible.  This was
> written by script.  The rule that is followed is that uses of the
> form:
> 
>    catch (... &name)
>      {
>        ...
>        throw_exception (name);
>      }
> 
> ... can be rewritten.  It's possible (though IMO unlikely) that such a
> case could be wrong, if the exception object is rewritten in the body
> of the catch.  (One option here might be to catch a const & instead.)

I think this paragraph is stale, given that the current patchset catches
by "const &" already.  LGTM with that striped out.

Thanks,
Pedro Alves

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

* Re: [PATCH v2 15/22] Make exceptions use std::string and be self-managing
  2019-04-03 16:20   ` Pedro Alves
@ 2019-04-03 17:58     ` Tom Tromey
  2019-04-03 18:28       ` Pedro Alves
  0 siblings, 1 reply; 58+ messages in thread
From: Tom Tromey @ 2019-04-03 17:58 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, gdb-patches

>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:

Pedro> I think fixing this isn't hard, so I think we should do it from the
Pedro> start -- instead of gdb_exception holding a std::string, hold a
Pedro> reference counted immutable heap-allocated C string.

I'll do this.

How about just a std::shared_ptr<std::string>?  Or would you rather
plain std::shared_ptr<char>?  I don't recall offhand if having a real
string was handy anywhere or not.

Pedro> Since you're touching most (all?) lines that refer to "message",
Pedro> did you consider adding a "what()" method, to model what
Pedro> std::exception has?

Pedro>   const char *what() const noexcept;

Pedro> Maybe that helps with newcomers' familiarity?

I didn't think of it, but I can do this.

Tom

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

* Re: [PATCH v2 16/22] Rewrite TRY/CATCH
  2019-04-03 17:03   ` Pedro Alves
@ 2019-04-03 18:02     ` Tom Tromey
  0 siblings, 0 replies; 58+ messages in thread
From: Tom Tromey @ 2019-04-03 18:02 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Tom Tromey, gdb-patches

Pedro> I reviewed this one and the next as a squashed view (any reason you
Pedro> didn't squash them?)

IIRC both of these patches were written by script, and not squashing
meant that I didn't have to fix the scripts to understand how to write
the combined ChangeLog correctly.

Tom

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

* Re: [PATCH v2 15/22] Make exceptions use std::string and be self-managing
  2019-04-03 17:58     ` Tom Tromey
@ 2019-04-03 18:28       ` Pedro Alves
  0 siblings, 0 replies; 58+ messages in thread
From: Pedro Alves @ 2019-04-03 18:28 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On 04/03/2019 06:58 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
> 
> Pedro> I think fixing this isn't hard, so I think we should do it from the
> Pedro> start -- instead of gdb_exception holding a std::string, hold a
> Pedro> reference counted immutable heap-allocated C string.
> 
> I'll do this.
> 
> How about just a std::shared_ptr<std::string>?  

That should be fine.

Thanks,
Pedro Alves

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

end of thread, other threads:[~2019-04-03 18:28 UTC | newest]

Thread overview: 58+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-27 20:18 [PATCH v2 00/22] Remove cleanups Tom Tromey
2019-02-27 20:18 ` [PATCH v2 08/22] Remove last cleanup solib-aix.c Tom Tromey
2019-03-06 19:34   ` Pedro Alves
2019-03-06 21:19     ` Tom Tromey
2019-02-27 20:18 ` [PATCH v2 05/22] Remove last cleanup from gdbserver Tom Tromey
2019-03-06 19:23   ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 01/22] Remove cleanups from coffread.c Tom Tromey
2019-03-06 19:23   ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 09/22] Remove last cleanup from linux-namespaces.c Tom Tromey
2019-03-06 21:07   ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 16/22] Rewrite TRY/CATCH Tom Tromey
2019-04-03 17:03   ` Pedro Alves
2019-04-03 18:02     ` Tom Tromey
2019-02-27 20:19 ` [PATCH v2 04/22] C++ify remote notification code Tom Tromey
2019-03-06 19:23   ` Pedro Alves
2019-03-06 21:12     ` Tom Tromey
2019-02-27 20:19 ` [PATCH v2 22/22] Introduce and use bcache_up Tom Tromey
2019-03-06 22:03   ` Pedro Alves
2019-03-07 16:54     ` Tom Tromey
2019-03-07 17:09       ` Pedro Alves
2019-03-07 17:42         ` Tom Tromey
2019-02-27 20:19 ` [PATCH v2 02/22] Update two cleanup comments Tom Tromey
2019-03-06 19:23   ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 07/22] Remove last cleanups from solib-svr4.c Tom Tromey
2019-03-06 19:32   ` Pedro Alves
2019-03-06 19:39     ` John Baldwin
2019-03-06 21:18     ` Tom Tromey
2019-02-27 20:19 ` [PATCH v2 13/22] Remove free_current_contents Tom Tromey
2019-03-06 21:34   ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 19/22] Make exception throwing a bit more efficient Tom Tromey
2019-04-03 17:04   ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 03/22] Change displaced_step_clear_cleanup with a forward_scope_exit Tom Tromey
2019-03-06 19:23   ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 15/22] Make exceptions use std::string and be self-managing Tom Tromey
2019-04-03 16:20   ` Pedro Alves
2019-04-03 17:58     ` Tom Tromey
2019-04-03 18:28       ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 17/22] Rename gdb exception types Tom Tromey
2019-02-27 20:19 ` [PATCH v2 11/22] Use unique_xmalloc_ptr in remote.c Tom Tromey
2019-03-06 21:17   ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 20/22] Replace throw_exception with throw in some cases Tom Tromey
2019-04-03 17:05   ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 14/22] Simplify exception handling Tom Tromey
2019-04-02 22:07   ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 18/22] Remove some now-dead exception code Tom Tromey
2019-04-03 17:04   ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 06/22] Remove cleanup from solib-svr4.c Tom Tromey
2019-03-06 19:24   ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 10/22] Remove last cleanups from stabsread.c Tom Tromey
2019-03-06 21:14   ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 12/22] Remove basic cleanup code Tom Tromey
2019-03-06 21:33   ` Pedro Alves
2019-02-27 20:19 ` [PATCH v2 21/22] Use SCOPE_EXIT in write_gcore_file Tom Tromey
2019-03-06 22:01   ` Pedro Alves
2019-03-06 22:31     ` Tom Tromey
2019-03-06 22:54       ` Pedro Alves
2019-03-06 22:56         ` Tom Tromey
2019-03-06 23:08           ` Tom Tromey

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).