public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 03/20] Change displaced_step_clear_cleanup with a forward_scope_exit
  2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
  2019-02-13 21:29 ` [PATCH 12/20] Remove free_current_contents Tom Tromey
  2019-02-13 21:29 ` [PATCH 05/20] Remove last cleanup from gdbserver Tom Tromey
@ 2019-02-13 21:29 ` Tom Tromey
  2019-02-13 21:29 ` [PATCH 17/20] Make exception throwing a bit more efficient Tom Tromey
                   ` (17 subsequent siblings)
  20 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-13 21:29 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-13  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] 28+ messages in thread

* [PATCH 14/20] Make exceptions use std::string and be self-managing
  2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
                   ` (9 preceding siblings ...)
  2019-02-13 21:29 ` [PATCH 01/20] Remove cleanups from coffread.c Tom Tromey
@ 2019-02-13 21:29 ` Tom Tromey
  2019-02-13 21:30 ` [PATCH 13/20] Simplify exception handling Tom Tromey
                   ` (9 subsequent siblings)
  20 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-13 21:29 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-13  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-13  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                |   2 +-
 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, 196 insertions(+), 230 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index a878d4d1af2..3c99894309f 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
@@ -12477,7 +12477,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 67d83e6f465..478c61b5af4 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;
@@ -13541,7 +13541,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 aaead00a101..16f71273894 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -1552,7 +1552,7 @@ 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, source_line_number, e.message);
+		   source_file_name, 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 26a55533ff6..5547d07f115 100644
--- a/gdb/gdbserver/gdbreplay.c
+++ b/gdb/gdbserver/gdbreplay.c
@@ -518,7 +518,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 0f96aab718a..b43690e8293 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 a250a4e0625..f7158ded42f 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -13804,8 +13804,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 fb5e2c59e0c..2b52ce1a401 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 c1ab07f7608..22caab134dc 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -745,12 +745,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] 28+ messages in thread

* [PATCH 06/20] Remove cleanup from solib-svr4.c
  2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
                   ` (3 preceding siblings ...)
  2019-02-13 21:29 ` [PATCH 17/20] Make exception throwing a bit more efficient Tom Tromey
@ 2019-02-13 21:29 ` Tom Tromey
  2019-02-13 21:29 ` [PATCH 11/20] Remove basic cleanup code Tom Tromey
                   ` (15 subsequent siblings)
  20 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-13 21:29 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-13  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] 28+ messages in thread

* [PATCH 11/20] Remove basic cleanup code
  2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
                   ` (4 preceding siblings ...)
  2019-02-13 21:29 ` [PATCH 06/20] Remove cleanup from solib-svr4.c Tom Tromey
@ 2019-02-13 21:29 ` Tom Tromey
  2019-02-13 21:29 ` [PATCH 20/20] Introduce and use bcache_up Tom Tromey
                   ` (14 subsequent siblings)
  20 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-13 21:29 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-13  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 a7283902fe2..92c0c6d4e0f 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -329,14 +329,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 c756a6978e8..abe8c2159bf 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] 28+ messages in thread

* [PATCH 00/20] Remove cleanups
@ 2019-02-13 21:29 Tom Tromey
  2019-02-13 21:29 ` [PATCH 12/20] Remove free_current_contents Tom Tromey
                   ` (20 more replies)
  0 siblings, 21 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-13 21:29 UTC (permalink / raw)
  To: gdb-patches

This series removes the remaining uses of make_cleanup from the tree,
then removes make_cleanup and some related functions (but note that
final cleanups remain).

Then, it removes the TRY/CATCH macros in favor of ordinary C++ code.

Finally, it cleans up a few spots that currently use TRY/CATCH but
that are more succinctly written using SCOPE_EXIT or RAII.

Regression tested by the buildbot.

Tom


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

* [PATCH 16/20] Remove some now-dead exception code
  2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
                   ` (7 preceding siblings ...)
  2019-02-13 21:29 ` [PATCH 07/20] Remove last cleanups from solib-svr4.c Tom Tromey
@ 2019-02-13 21:29 ` Tom Tromey
  2019-02-13 21:29 ` [PATCH 01/20] Remove cleanups from coffread.c Tom Tromey
                   ` (11 subsequent siblings)
  20 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-13 21:29 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-13  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 15b59f4dd94..d2ec1994844 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 d4b30104239..245807c68d6 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] 28+ messages in thread

* [PATCH 20/20] Introduce and use bcache_up
  2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
                   ` (5 preceding siblings ...)
  2019-02-13 21:29 ` [PATCH 11/20] Remove basic cleanup code Tom Tromey
@ 2019-02-13 21:29 ` Tom Tromey
  2019-02-13 21:29 ` [PATCH 07/20] Remove last cleanups from solib-svr4.c Tom Tromey
                   ` (13 subsequent siblings)
  20 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-13 21:29 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-13  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 a473da1cad6..9e32c22c74f 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -3745,9 +3745,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);
@@ -3756,30 +3753,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 (struct gdb_exception_RETURN_MASK_ALL &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 f7eae7e5f9b..082f10028f5 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] 28+ messages in thread

* [PATCH 12/20] Remove free_current_contents
  2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
@ 2019-02-13 21:29 ` Tom Tromey
  2019-02-13 21:29 ` [PATCH 05/20] Remove last cleanup from gdbserver Tom Tromey
                   ` (19 subsequent siblings)
  20 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-13 21:29 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-13  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 6fb5736abb5..272fe268fef 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -126,35 +126,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] 28+ messages in thread

* [PATCH 01/20] Remove cleanups from coffread.c
  2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
                   ` (8 preceding siblings ...)
  2019-02-13 21:29 ` [PATCH 16/20] Remove some now-dead exception code Tom Tromey
@ 2019-02-13 21:29 ` Tom Tromey
  2019-02-13 21:29 ` [PATCH 14/20] Make exceptions use std::string and be self-managing Tom Tromey
                   ` (10 subsequent siblings)
  20 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-13 21:29 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-13  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] 28+ messages in thread

* [PATCH 05/20] Remove last cleanup from gdbserver
  2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
  2019-02-13 21:29 ` [PATCH 12/20] Remove free_current_contents Tom Tromey
@ 2019-02-13 21:29 ` Tom Tromey
  2019-02-13 21:29 ` [PATCH 03/20] Change displaced_step_clear_cleanup with a forward_scope_exit Tom Tromey
                   ` (18 subsequent siblings)
  20 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-13 21:29 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-13  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] 28+ messages in thread

* [PATCH 07/20] Remove last cleanups from solib-svr4.c
  2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
                   ` (6 preceding siblings ...)
  2019-02-13 21:29 ` [PATCH 20/20] Introduce and use bcache_up Tom Tromey
@ 2019-02-13 21:29 ` Tom Tromey
  2019-02-13 21:29 ` [PATCH 16/20] Remove some now-dead exception code Tom Tromey
                   ` (12 subsequent siblings)
  20 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-13 21:29 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-13  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] 28+ messages in thread

* [PATCH 17/20] Make exception throwing a bit more efficient
  2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
                   ` (2 preceding siblings ...)
  2019-02-13 21:29 ` [PATCH 03/20] Change displaced_step_clear_cleanup with a forward_scope_exit Tom Tromey
@ 2019-02-13 21:29 ` Tom Tromey
  2019-02-13 21:29 ` [PATCH 06/20] Remove cleanup from solib-svr4.c Tom Tromey
                   ` (16 subsequent siblings)
  20 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-13 21:29 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-13  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 d2ec1994844..b6a386bad24 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_RETURN_MASK_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_RETURN_MASK_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 245807c68d6..25cfc7247bc 100644
--- a/gdb/common/common-exceptions.h
+++ b/gdb/common/common-exceptions.h
@@ -209,7 +209,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] 28+ messages in thread

* [PATCH 13/20] Simplify exception handling
  2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
                   ` (10 preceding siblings ...)
  2019-02-13 21:29 ` [PATCH 14/20] Make exceptions use std::string and be self-managing Tom Tromey
@ 2019-02-13 21:30 ` Tom Tromey
  2019-02-13 21:30 ` [PATCH 04/20] C++ify remote notification code Tom Tromey
                   ` (8 subsequent siblings)
  20 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-13 21:30 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-13  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] 28+ messages in thread

* [PATCH 18/20] Replace throw_exception with throw in some cases
  2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
                   ` (15 preceding siblings ...)
  2019-02-13 21:30 ` [PATCH 02/20] Update two cleanup comments Tom Tromey
@ 2019-02-13 21:30 ` Tom Tromey
  2019-02-13 21:30 ` [PATCH 15/20] Rewrite TRY/CATCH Tom Tromey
                   ` (3 subsequent siblings)
  20 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-13 21:30 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-13  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-13  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 01dbb21610b..5a6d9777ed8 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 (struct gdb_exception_RETURN_MASK_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 (struct gdb_exception_RETURN_MASK_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 0f1b097c26e..1c27c08d919 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 (struct gdb_exception_RETURN_MASK_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 (struct gdb_exception_RETURN_MASK_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 (struct gdb_exception_RETURN_MASK_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 e2029fc892a..0d5b4258703 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 08360d621e3..32581dd9189 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -9247,7 +9247,7 @@ create_breakpoint (struct gdbarch *gdbarch,
 	     error.  */
 
 	  if (pending_break_support == AUTO_BOOLEAN_FALSE)
-	    throw_exception (e);
+	    throw;
 
 	  exception_print (gdb_stderr, e);
 
@@ -9265,7 +9265,7 @@ create_breakpoint (struct gdbarch *gdbarch,
 	  pending = 1;
 	}
       else
-	throw_exception (e);
+	throw;
     }
 
   if (!pending && canonical.lsals.empty ())
@@ -13637,7 +13637,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;
 	}
     }
 
@@ -15036,7 +15036,7 @@ save_breakpoints (const char *filename, int from_tty,
 	catch (struct gdb_exception_RETURN_MASK_ALL &ex)
 	  {
 	  current_uiout->redirect (NULL);
-	    throw_exception (ex);
+	    throw;
 	  }
 
 	current_uiout->redirect (NULL);
diff --git a/gdb/btrace.c b/gdb/btrace.c
index 595d7097ab4..9daf4ff0ae8 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 80ded7fe8d8..91c563b5628 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 (struct gdb_exception_RETURN_MASK_ALL &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 7926594c180..87a26ad4ae9 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 3cd2677e135..3158b33259e 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -1451,7 +1451,7 @@ complete_line_internal (completion_tracker &tracker,
   catch (struct gdb_exception_RETURN_MASK_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 a2f67b25584..ef4e3e62df9 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 (struct gdb_exception_RETURN_MASK_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 73ee7006a0c..73e1e1ece1c 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 52679c75479..624db9485da 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 67df3e79bd2..e46b7b545d0 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 acea09362e6..61ab232e448 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 (struct gdb_exception_RETURN_MASK_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 ff9bddfb735..df6fdb89a1b 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 79ec5d14ae9..066d938abf5 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 (struct gdb_exception_RETURN_MASK_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 e7d28203865..30f6f2e0b7e 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 (struct gdb_exception_RETURN_MASK_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 (struct gdb_exception_RETURN_MASK_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 ae2c9eae977..b9e8b01acb1 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 (struct gdb_exception_RETURN_MASK_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 (struct gdb_exception_RETURN_MASK_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 (struct gdb_exception_RETURN_MASK_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 5ccd31b7328..47d73e7e18f 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 840dad91d23..e1d53611d3b 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -454,7 +454,7 @@ post_create_inferior (struct target_ops *target, int from_tty)
   catch (struct gdb_exception_RETURN_MASK_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 1bad6575bf1..14717b7848d 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 0de1fa9eb44..07f491f7fa3 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -3160,7 +3160,7 @@ event_location_to_sals (linespec_parser *parser,
 	  }
 	catch (struct gdb_exception_RETURN_MASK_ERROR &except)
 	  {
-	    throw_exception (except);
+	    throw;
 	  }
       }
       break;
@@ -3974,7 +3974,7 @@ find_linespec_symbols (struct linespec_state *state,
 	  catch (struct gdb_exception_RETURN_MASK_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 607fd4fc3b8..2f4ea13b013 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 (struct gdb_exception_RETURN_MASK_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 (struct gdb_exception_RETURN_MASK_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 (struct gdb_exception_RETURN_MASK_ERROR &ex)
 	{
 	  if (!check_ptrace_stopped_lwp_gone (lp))
-	    throw_exception (ex);
+	    throw;
 	}
     }
 
diff --git a/gdb/parse.c b/gdb/parse.c
index bb712799818..0072af5ec9d 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 f0a5f6d0497..b6aba415285 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -1484,7 +1484,7 @@ record_btrace_target::insert_breakpoint (struct gdbarch *gdbarch,
   catch (struct gdb_exception_RETURN_MASK_ALL &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 (struct gdb_exception_RETURN_MASK_ALL &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 (struct gdb_exception_RETURN_MASK_ALL &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 (struct gdb_exception_RETURN_MASK_ALL &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 (struct gdb_exception_RETURN_MASK_ALL &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 18655499f77..7e0294251e1 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 (struct gdb_exception_RETURN_MASK_ALL &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 (struct gdb_exception_RETURN_MASK_ALL &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 83006f0ed64..1d81ec86fcf 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -5611,7 +5611,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;
       }
   }
 
@@ -9785,7 +9785,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;
     }
 }
 
@@ -13151,7 +13151,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 575e3f4b83a..634aa6e8f68 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 (struct gdb_exception_RETURN_MASK_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 (struct gdb_exception_RETURN_MASK_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 ca09ea87f20..48ab79a9c4d 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 (struct gdb_exception_RETURN_MASK_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 65a73d91a79..c483ae3fc6a 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 160f61eeb89..afe42e78ba3 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 b28b30152c0..e6e56c3c9d3 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -753,7 +753,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 66a032e2614..73b950201ef 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 c79c6874c90..024054c8841 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 8c7060ad72f..8d699e4b429 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] 28+ messages in thread

* [PATCH 15/20] Rewrite TRY/CATCH
  2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
                   ` (16 preceding siblings ...)
  2019-02-13 21:30 ` [PATCH 18/20] Replace throw_exception with throw in some cases Tom Tromey
@ 2019-02-13 21:30 ` Tom Tromey
  2019-02-13 21:30 ` [PATCH 08/20] Remove last cleanup solib-aix.c Tom Tromey
                   ` (2 subsequent siblings)
  20 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-13 21:30 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-13  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-13  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 bc928e14e9f..01dbb21610b 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 (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 (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 3c99894309f..2d4746860f5 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 (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 (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 (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 (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 (struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       warning (_("failed to get exception name: %s"), e.message.c_str ());
       return 0;
     }
-  END_CATCH
 
   return result;
 }
@@ -12467,19 +12462,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 (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);
@@ -12537,7 +12531,7 @@ should_stop_exception (const struct bp_location *bl)
     }
 
   stop = 1;
-  TRY
+  try
     {
       struct value *mark;
 
@@ -12545,12 +12539,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 (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..2a94ada1389 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 (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..886011d85ee 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 (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..0f1b097c26e 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 (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 (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 (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 d2e27d95558..7ab6a57e6b8 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 (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..e2029fc892a 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 (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 (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 (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 478c61b5af4..08360d621e3 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 (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 (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 (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 (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 (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 (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 (struct gdb_exception_RETURN_MASK_ALL &ex)
 	    {
 	      exception_fprintf (gdb_stderr, ex,
 				 "Error in testing breakpoint condition:\n");
 	    }
-	  END_CATCH
 	}
       else
 	{
@@ -9240,11 +9233,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 (struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       /* If caller is interested in rc value from parse, set
 	 value.  */
@@ -9274,7 +9267,6 @@ create_breakpoint (struct gdbarch *gdbarch,
       else
 	throw_exception (e);
     }
-  END_CATCH
 
   if (!pending && canonical.lsals.empty ())
     return 0;
@@ -12054,14 +12046,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 (struct gdb_exception_RETURN_MASK_ERROR &e)
     {
     }
-  END_CATCH
 }
 
 /* Clear BKP from a BPS.  */
@@ -13531,20 +13522,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 (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 ())
@@ -13611,11 +13601,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 (struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       int not_found_and_ok = 0;
 
@@ -13650,7 +13640,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)
     {
@@ -13822,17 +13811,16 @@ breakpoint_re_set (void)
 
     ALL_BREAKPOINTS_SAFE (b, b_tmp)
       {
-	TRY
+	try
 	  {
 	    breakpoint_re_set_one (b);
 	  }
-	CATCH (ex, RETURN_MASK_ALL)
+	catch (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 ();
@@ -14299,7 +14287,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;
 
@@ -14307,14 +14295,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 (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;
@@ -15042,16 +15029,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 (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..595d7097ab4 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 (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 (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 (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 (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 (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 (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 (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..4f1432835c5 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 (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 (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 (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 (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..f2b3a41b30c 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 (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..6cc37d1325d 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 (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 16f71273894..80ded7fe8d8 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 (struct gdb_exception_RETURN_MASK_ALL &ex)
 	{
 	  free_command_lines (command);
 	  throw_exception (ex);
 	}
-      END_CATCH
     }
 
   /* Nothing special.  */
@@ -1542,11 +1541,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 (struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       /* Re-throw the error, but with the file name information
 	 prepended.  */
@@ -1554,7 +1553,6 @@ script_from_file (FILE *stream, const char *file)
 		   _("%s:%d: Error in sourced command file:\n%s"),
 		   source_file_name, 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..734143eab63 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 (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..c7ac3603a08 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 (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..bf682e2f3c0 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 (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 (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 (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..25c10748e56 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 (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 (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..a8ef0e4eb9b 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 (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..7926594c180 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 (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..3cd2677e135 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 (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 (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 (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 (struct gdb_exception_RETURN_MASK_ALL &ex)
     {
     }
-  END_CATCH
 
   return NULL;
 }
diff --git a/gdb/corelow.c b/gdb/corelow.c
index 52d6d95b3c0..d4a99327926 100644
--- a/gdb/corelow.c
+++ b/gdb/corelow.c
@@ -462,16 +462,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 (struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       exception_print (gdb_stderr, except);
     }
-  END_CATCH
 
   p = bfd_core_file_failing_command (core_bfd);
   if (p)
@@ -518,15 +517,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 (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..a2f67b25584 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 (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 (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..6624a6e72c5 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 (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 (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 (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..cd74594e4f6 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 (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 (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..73ee7006a0c 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 (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 (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..c739760d78e 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 (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..41e85a54240 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 (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..7cc60b87aaa 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 (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 (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..33fed761cf0 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 (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..b7a966abf24 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 (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..52679c75479 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 (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 (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 (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..67df3e79bd2 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 (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 (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 (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 98f46e04162..b1ae74c1601 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 (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..acea09362e6 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 (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 (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 (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 (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 (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..28d61dcfb74 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 (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..f19bdf71ba3 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 (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 (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 (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..137a90faf1b 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 (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 (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..ac8c2a47bde 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 (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..8fe1741ef28 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 (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..ff9bddfb735 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 (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..79ec5d14ae9 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 (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 (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 (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 (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 (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 (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..0684ac17c33 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 (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 5547d07f115..a0848e0f979 100644
--- a/gdb/gdbserver/gdbreplay.c
+++ b/gdb/gdbserver/gdbreplay.c
@@ -509,11 +509,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 (struct gdb_exception_RETURN_MASK_ALL &exception)
     {
       if (exception.reason == RETURN_ERROR)
 	{
@@ -523,7 +523,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..e7d28203865 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 (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 (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..6f7bc65d66c 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 (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 (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 (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 (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 (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 (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 d1ca304a924..a473da1cad6 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 (struct gdb_exception_RETURN_MASK_ERROR &except)
     {
       type = builtin_type (gdbarch)->builtin_void;
     }
-  END_CATCH
 
   /* Stop suppressing error messages.  */
   gdb_stderr = saved_gdb_stderr;
@@ -3765,15 +3764,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 (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..4f2ae771133 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 (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..a5a99250d1d 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 (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..c47c99840ce 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 (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..e29f45257d9 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 (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 (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 (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 (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 (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 (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 (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 (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..c355bdee6e2 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 (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..bc04999180e 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 (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..c715e19cd63 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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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..3eb56387809 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 (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..7a800d82f5d 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 (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..9dc60594a08 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 (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 (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..e3b2939e567 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 (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..fb886154743 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 (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..24062624caa 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 (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 (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 (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 (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 (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..5da1b713653 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 (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..eed39d125da 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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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..0ea6fb71ee3 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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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..d14714eaa42 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 (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 663d510a915..ae2c9eae977 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 (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 (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 (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..5ccd31b7328 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 (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..bb4e5cfa308 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 (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..840dad91d23 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 (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 (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..1bad6575bf1 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 (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 (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 (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 (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 (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 (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 (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..9599f0760dc 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 (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..c109354af54 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 (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 cedbd39bd77..0de1fa9eb44 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -2391,16 +2391,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 (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
@@ -2616,17 +2615,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 (struct gdb_exception_RETURN_MASK_ERROR &ex)
 	{
 	  file_exception = ex;
 	}
-      END_CATCH
 
       if (file_exception.reason >= 0)
 	{
@@ -2931,7 +2929,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),
@@ -2940,11 +2938,10 @@ linespec_complete_label (completion_tracker &tracker,
 					     func_name_match_type,
 					     NULL, unknown_offset);
     }
-  CATCH (ex, RETURN_MASK_ERROR)
+  catch (struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       return;
     }
-  END_CATCH
 
   complete_label (tracker, &parser, label_name);
 }
@@ -2967,14 +2964,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 (struct gdb_exception_RETURN_MASK_ERROR &except)
     {
     }
-  END_CATCH
 
   if (parser.completion_quote_char != '\0'
       && parser.completion_quote_end != NULL
@@ -3156,17 +3152,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 (struct gdb_exception_RETURN_MASK_ERROR &except)
 	  {
 	    throw_exception (except);
 	  }
-	END_CATCH
       }
       break;
 
@@ -3967,7 +3962,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 (),
@@ -3976,12 +3971,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 (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..938d12b3918 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 (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..607fd4fc3b8 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 (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 (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 (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 (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..89ff49a3141 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 (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..04a5a930489 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 (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 (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 (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 92c0c6d4e0f..0a256df20d9 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -364,7 +364,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;
 
@@ -372,11 +372,10 @@ catch_command_errors (catch_command_errors_const_ftype command,
 
       maybe_wait_sync_command_done (was_sync);
     }
-  CATCH (e, RETURN_MASK_ALL)
+  catch (struct gdb_exception_RETURN_MASK_ALL &e)
     {
       return handle_command_errors (e);
     }
-  END_CATCH
 
   return 1;
 }
@@ -1163,15 +1162,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 (struct gdb_exception_RETURN_MASK_ALL &ex)
 	{
 	  exception_print (gdb_stderr, ex);
 	}
-      END_CATCH
     }
   /* No exit -- exit is through quit_command.  */
 }
@@ -1179,15 +1177,14 @@ captured_main (void *data)
 int
 gdb_main (struct captured_main_args *args)
 {
-  TRY
+  try
     {
       captured_main (args);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (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..b52242ee73d 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 (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..4a9b4afadd6 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 (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..e6c283bcd95 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 (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..cd78f8c446e 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 (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 (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..c2ac53c00e9 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 (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..7c74fb9871a 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 (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..bb712799818 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 (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 (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..475d2ee89db 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 (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..068258351ed 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 (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 (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 (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 (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..7814c69b687 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 (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 f41d88dbf51..b597d2dd311 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 (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 (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 (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 (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 (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 (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 (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 (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..46b7986d1a9 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 (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..48cdc58611a 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 (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 (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 (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 (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 (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 (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..e4f53589a32 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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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..35478c0d1a5 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 (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 (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..287491a748a 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 (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 24fc5e69fef..b5c7fb62fb8 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 (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 (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));
@@ -580,15 +578,14 @@ infpy_write_memory (PyObject *self, PyObject *args, PyObject *kw)
   else if (get_addr_from_python (length_obj, &length) < 0)
     goto fail;
 
-  TRY
+  try
     {
       write_memory_with_notification (addr, buffer, length);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       except = ex;
     }
-  END_CATCH
 
 #ifdef IS_PY3K
   PyBuffer_Release (&pybuf);
@@ -764,17 +761,16 @@ infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw)
       goto fail;
     }
 
-  TRY
+  try
     {
       found = target_search_memory (start_addr, length,
 				    buffer, pattern_size,
 				    &found_addr);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       except = ex;
     }
-  END_CATCH
 
 #ifdef IS_PY3K
   PyBuffer_Release (&pybuf);
@@ -830,7 +826,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);
@@ -839,11 +835,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 (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..ac3599190b7 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 (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..400c2fcc83f 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 (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..4c0fbcb291c 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 (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..25d884c6d90 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 (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 (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..36a9dad4f95 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 (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 8effa81d5b0..420d9d9c5a0 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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
     }
-  END_CATCH
 
   return result;
 }
@@ -736,15 +735,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 (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..e734c51ed07 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 (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 (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..f8106871e84 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 (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 (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 (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 (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..a30319b358f 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 (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 (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..9172aa2a060 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 (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 (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 (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 (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 (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 7ad1a0c70e8..6f5fcd6afdc 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -314,15 +314,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   gdbpy_ref<> type_holder;
   if (checked_type != type)
@@ -422,15 +421,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return type_to_type_object (type);
 }
@@ -444,15 +442,14 @@ typy_get_composite (struct type *type)
 
   for (;;)
     {
-      TRY
+      try
 	{
 	  type = check_typedef (type);
 	}
-      CATCH (except, RETURN_MASK_ALL)
+      catch (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;
@@ -512,17 +509,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return type_to_type_object (array);
 }
@@ -549,15 +545,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return type_to_type_object (type);
 }
@@ -618,15 +613,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return type_to_type_object (type);
 }
@@ -653,15 +647,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return type_to_type_object (type);
 }
@@ -672,15 +665,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return type_to_type_object (type);
 }
@@ -691,15 +683,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return type_to_type_object (type);
 }
@@ -710,14 +701,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
     }
-  END_CATCH
 
   /* Ignore exceptions.  */
 
@@ -731,15 +721,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       align = 0;
     }
-  END_CATCH
 
   /* Ignore exceptions.  */
 
@@ -751,7 +740,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);
@@ -763,11 +752,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return type;
 }
@@ -793,7 +781,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
@@ -818,11 +806,10 @@ typy_lookup_type (struct demangle_component *demangled,
 	      break;
 	    }
 	}
-      CATCH (except, RETURN_MASK_ALL)
+      catch (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
@@ -856,16 +843,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (! info)
     {
@@ -936,17 +922,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 (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 --
@@ -971,15 +956,14 @@ typy_template_argument (PyObject *self, PyObject *args)
       return NULL;
     }
 
-  TRY
+  try
     {
       val = value_of_variable (sym, block);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return value_to_value_object (val);
 }
@@ -989,16 +973,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 (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);
@@ -1025,17 +1008,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 (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..1bc763b45dd 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 (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 (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 (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 (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 b43690e8293..90d676b78a8 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 (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 20ef5822f8e..373296acffc 100644
--- a/gdb/python/py-value.c
+++ b/gdb/python/py-value.c
@@ -164,7 +164,7 @@ valpy_dereference (PyObject *self, PyObject *args)
 {
   PyObject *result = NULL;
 
-  TRY
+  try
     {
       struct value *res_val;
       scoped_value_mark free_values;
@@ -172,11 +172,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return result;
 }
@@ -194,7 +193,7 @@ valpy_referenced_value (PyObject *self, PyObject *args)
 {
   PyObject *result = NULL;
 
-  TRY
+  try
     {
       struct value *self_val, *res_val;
       scoped_value_mark free_values;
@@ -216,11 +215,10 @@ valpy_referenced_value (PyObject *self, PyObject *args)
 
       result = value_to_value_object (res_val);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return result;
 }
@@ -232,7 +230,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;
@@ -240,11 +238,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return result;
 }
@@ -268,7 +265,7 @@ valpy_const_value (PyObject *self, PyObject *args)
 {
   PyObject *result = NULL;
 
-  TRY
+  try
     {
       struct value *self_val, *res_val;
       scoped_value_mark free_values;
@@ -277,11 +274,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return result;
 }
@@ -294,7 +290,7 @@ valpy_get_address (PyObject *self, void *closure)
 
   if (!val_obj->address)
     {
-      TRY
+      try
 	{
 	  struct value *res_val;
 	  scoped_value_mark free_values;
@@ -302,12 +298,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 (struct gdb_exception_RETURN_MASK_ALL &except)
 	{
 	  val_obj->address = Py_None;
 	  Py_INCREF (Py_None);
 	}
-      END_CATCH
     }
 
   Py_XINCREF (val_obj->address);
@@ -345,7 +340,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;
@@ -381,11 +376,10 @@ valpy_get_dynamic_type (PyObject *self, void *closure)
 	  type = NULL;
 	}
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (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);
@@ -433,7 +427,7 @@ valpy_lazy_string (PyObject *self, PyObject *args, PyObject *kw)
       return NULL;
     }
 
-  TRY
+  try
     {
       scoped_value_mark free_values;
       struct type *type, *realtype;
@@ -488,11 +482,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return str_obj;
 }
@@ -520,15 +513,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 (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 (),
@@ -555,7 +547,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;
@@ -573,11 +565,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return result;
 }
@@ -638,7 +629,7 @@ value_has_field (struct value *v, PyObject *field)
       return -1;
     }
 
-  TRY
+  try
     {
       val_type = value_type (v);
       val_type = check_typedef (val_type);
@@ -652,11 +643,10 @@ value_has_field (struct value *v, PyObject *field)
       else
 	has_field = 0;
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_SET_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return has_field;
 }
@@ -777,7 +767,7 @@ valpy_getitem (PyObject *self, PyObject *key)
 	}
     }
 
-  TRY
+  try
     {
       struct value *tmp = self_value->value;
       struct value *res_val = NULL;
@@ -831,11 +821,10 @@ valpy_getitem (PyObject *self, PyObject *key)
       if (res_val)
 	result = value_to_value_object (res_val);
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (struct gdb_exception_RETURN_MASK_ALL &ex)
     {
       except = ex;
     }
-  END_CATCH
 
   GDB_PY_HANDLE_EXCEPTION (except);
 
@@ -861,15 +850,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (TYPE_CODE (ftype) != TYPE_CODE_FUNC)
     {
@@ -904,7 +892,7 @@ valpy_call (PyObject *self, PyObject *args, PyObject *keywords)
 	}
     }
 
-  TRY
+  try
     {
       scoped_value_mark free_values;
 
@@ -913,11 +901,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return result;
 }
@@ -934,16 +921,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 (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);
 }
@@ -955,15 +941,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (opt)
     Py_RETURN_TRUE;
@@ -978,15 +963,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (opt)
     Py_RETURN_TRUE;
@@ -1000,16 +984,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   Py_RETURN_NONE;
 }
@@ -1173,15 +1156,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return result;
 }
@@ -1237,7 +1219,7 @@ valpy_negative (PyObject *self)
 {
   PyObject *result = NULL;
 
-  TRY
+  try
     {
       /* Perhaps overkill, but consistency has some virtue.  */
       scoped_value_mark free_values;
@@ -1246,11 +1228,10 @@ valpy_negative (PyObject *self)
       val = value_neg (((value_object *) self)->value);
       result = value_to_value_object (val);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return result;
 }
@@ -1267,18 +1248,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (isabs)
     return valpy_positive (self);
@@ -1295,7 +1275,7 @@ valpy_nonzero (PyObject *self)
   struct type *type;
   int nonzero = 0; /* Appease GCC warning.  */
 
-  TRY
+  try
     {
       type = check_typedef (value_type (self_value->value));
 
@@ -1308,11 +1288,10 @@ valpy_nonzero (PyObject *self)
 	/* All other values are True.  */
 	nonzero = 1;
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (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
@@ -1328,15 +1307,14 @@ valpy_invert (PyObject *self)
 {
   struct value *val = NULL;
 
-  TRY
+  try
     {
       val = value_complement (((value_object *) self)->value);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return value_to_value_object (val);
 }
@@ -1456,15 +1434,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 (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)
@@ -1485,7 +1462,7 @@ valpy_int (PyObject *self)
   struct type *type = value_type (value);
   LONGEST l = 0;
 
-  TRY
+  try
     {
       if (is_floating_value (value))
 	{
@@ -1499,11 +1476,10 @@ valpy_int (PyObject *self)
 
       l = value_as_long (value);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (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 ();
@@ -1520,7 +1496,7 @@ valpy_long (PyObject *self)
   struct type *type = value_type (value);
   LONGEST l = 0;
 
-  TRY
+  try
     {
       if (is_floating_value (value))
 	{
@@ -1536,11 +1512,10 @@ valpy_long (PyObject *self)
 
       l = value_as_long (value);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (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);
@@ -1556,7 +1531,7 @@ valpy_float (PyObject *self)
   struct type *type = value_type (value);
   double d = 0;
 
-  TRY
+  try
     {
       type = check_typedef (type);
 
@@ -1572,11 +1547,10 @@ valpy_float (PyObject *self)
       else
 	error (_("Cannot convert value to float."));
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return PyFloat_FromDouble (d);
 }
@@ -1626,7 +1600,7 @@ convert_value_from_python (PyObject *obj)
 
   gdb_assert (obj != NULL);
 
-  TRY
+  try
     {
       if (PyBool_Check (obj))
 	{
@@ -1720,12 +1694,11 @@ convert_value_from_python (PyObject *obj)
 		      PyString_AsString (PyObject_Str (obj)));
 #endif
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       gdbpy_convert_exception (except);
       return NULL;
     }
-  END_CATCH
 
   return value;
 }
@@ -1740,15 +1713,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 (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   return value_to_value_object (res_val);
 }
@@ -1763,7 +1735,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);
 
@@ -1774,11 +1746,10 @@ gdbpy_convenience_variable (PyObject *self, PyObject *args)
 	    res_val = NULL;
 	}
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (struct gdb_exception_RETURN_MASK_ALL &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (res_val == NULL)
     Py_RETURN_NONE;
@@ -1805,7 +1776,7 @@ gdbpy_set_convenience_variable (PyObject *self, PyObject *args)
 	return NULL;
     }
 
-  TRY
+  try
     {
       if (value == NULL)
 	{
@@ -1821,11 +1792,10 @@ gdbpy_set_convenience_variable (PyObject *self, PyObject *args)
 	  set_internalvar (var, value);
 	}
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (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 c23db2c1261..66e01c5e054 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 (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 (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 (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 (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 (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 (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 (struct gdb_exception_RETURN_MASK_ALL &except)
 	{
 	}
-      END_CATCH
     }
 }
 
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index da2d246f723..f0a5f6d0497 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 (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 (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 (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 (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 (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 (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 (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 (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 (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..18655499f77 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 (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 (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 (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 (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..825645c9854 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 (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 f7158ded42f..83006f0ed64 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 (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)
 	    {
@@ -5602,11 +5601,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 (struct gdb_exception_RETURN_MASK_ALL &ex)
       {
 	/* Pop the partially set up target - unless something else did
 	   already before throwing the exception.  */
@@ -5614,7 +5613,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);
@@ -9767,11 +9765,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 (struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error == TARGET_CLOSE_ERROR)
 	{
@@ -9789,7 +9787,6 @@ remote_target::remote_kill_k ()
 	 user or higher layers decide what to do.  */
       throw_exception (ex);
     }
-  END_CATCH
 }
 
 void
@@ -13143,11 +13140,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 (struct gdb_exception_RETURN_MASK_ERROR &ex)
     {
       if (ex.error != TARGET_CLOSE_ERROR)
 	{
@@ -13156,7 +13153,6 @@ remote_target::get_trace_status (struct trace_status *ts)
 	}
       throw_exception (ex);
     }
-  END_CATCH
 
   result = packet_ok (p, &remote_protocol_packets[PACKET_qTStatus]);
 
@@ -13798,16 +13794,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 (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 2b52ce1a401..2f3db1c5130 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 (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));
@@ -2826,17 +2825,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 (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..e14b3969d5d 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 (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..575e3f4b83a 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 (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 (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..f354a2fb48b 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 (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..b269d389d01 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 (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..ca09ea87f20 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 (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..94038cd6f57 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 (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..04002211984 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 (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..c8f9105314d 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 (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..65a73d91a79 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 (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..78104808331 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 (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 (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 (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 (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 (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 (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..e62dfb0c557 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 (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 (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 (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 (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..479adeb8159 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 (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..160f61eeb89 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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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 (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..7dc4d7f02c3 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 (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..f7eae7e5f9b 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 (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 22caab134dc..b28b30152c0 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -696,7 +696,7 @@ target_translate_tls_address (struct objfile *objfile, CORE_ADDR offset)
     {
       ptid_t ptid = inferior_ptid;
 
-      TRY
+      try
 	{
 	  CORE_ADDR lm_addr;
 	  
@@ -708,7 +708,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 (struct gdb_exception_RETURN_MASK_ALL &ex)
 	{
 	  int objfile_is_library = (objfile->flags & OBJF_SHARED);
 
@@ -757,7 +757,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..66a032e2614 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 (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 abe8c2159bf..5977abde0eb 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 (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 (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 (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 (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..c79c6874c90 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 (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..24ffdf723fc 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 (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..e72ca505b09 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 (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..6bbc63647d9 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 (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 (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..1e4d0a6d3de 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 (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..8c7060ad72f 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 (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 (struct gdb_exception_RETURN_MASK_ERROR &except)
     {
     }
-  END_CATCH
 
   return ret;
 }
diff --git a/gdb/valprint.c b/gdb/valprint.c
index a079c0025a7..5185b06aa54 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 (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..3c773681733 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 (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 (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..5a80cd0ba88 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 (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 (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 (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 (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 (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 (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 2894b208f58..6fb02babfcf 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -912,15 +912,14 @@ handle_unload_dll ()
 static void
 catch_errors (void (*func) ())
 {
-  TRY
+  try
     {
       func ();
     }
-  CATCH (ex, RETURN_MASK_ALL)
+  catch (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..66985385ee2 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 (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..82ac1a16bcf 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 (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 (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] 28+ messages in thread

* [PATCH 09/20] Remove last cleanup from linux-namespaces.c
  2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
                   ` (13 preceding siblings ...)
  2019-02-13 21:30 ` [PATCH 10/20] Remove last cleanups from stabsread.c Tom Tromey
@ 2019-02-13 21:30 ` Tom Tromey
  2019-02-13 21:30 ` [PATCH 02/20] Update two cleanup comments Tom Tromey
                   ` (5 subsequent siblings)
  20 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-13 21:30 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-13  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] 28+ messages in thread

* [PATCH 02/20] Update two cleanup comments
  2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
                   ` (14 preceding siblings ...)
  2019-02-13 21:30 ` [PATCH 09/20] Remove last cleanup from linux-namespaces.c Tom Tromey
@ 2019-02-13 21:30 ` Tom Tromey
  2019-02-13 21:30 ` [PATCH 18/20] Replace throw_exception with throw in some cases Tom Tromey
                   ` (4 subsequent siblings)
  20 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-13 21:30 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-13  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] 28+ messages in thread

* [PATCH 04/20] C++ify remote notification code
  2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
                   ` (11 preceding siblings ...)
  2019-02-13 21:30 ` [PATCH 13/20] Simplify exception handling Tom Tromey
@ 2019-02-13 21:30 ` Tom Tromey
  2019-02-13 21:30 ` [PATCH 10/20] Remove last cleanups from stabsread.c Tom Tromey
                   ` (7 subsequent siblings)
  20 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-13 21:30 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-13  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 18e678d07af..a250a4e0625 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
@@ -6817,11 +6807,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;
@@ -6840,20 +6828,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.  */
 
@@ -6905,30 +6887,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.  */
@@ -7071,7 +7039,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;
     }
 
@@ -7215,7 +7183,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] 28+ messages in thread

* [PATCH 08/20] Remove last cleanup solib-aix.c
  2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
                   ` (17 preceding siblings ...)
  2019-02-13 21:30 ` [PATCH 15/20] Rewrite TRY/CATCH Tom Tromey
@ 2019-02-13 21:30 ` Tom Tromey
  2019-02-13 21:49 ` [PATCH 00/20] Remove cleanups John Baldwin
  2019-02-13 21:53 ` [PATCH 19/20] Use SCOPE_EXIT in write_gcore_file Tom Tromey
  20 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-13 21:30 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-13  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] 28+ messages in thread

* [PATCH 10/20] Remove last cleanups from stabsread.c
  2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
                   ` (12 preceding siblings ...)
  2019-02-13 21:30 ` [PATCH 04/20] C++ify remote notification code Tom Tromey
@ 2019-02-13 21:30 ` Tom Tromey
  2019-02-13 21:30 ` [PATCH 09/20] Remove last cleanup from linux-namespaces.c Tom Tromey
                   ` (6 subsequent siblings)
  20 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-13 21:30 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-13  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] 28+ messages in thread

* Re: [PATCH 00/20] Remove cleanups
  2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
                   ` (18 preceding siblings ...)
  2019-02-13 21:30 ` [PATCH 08/20] Remove last cleanup solib-aix.c Tom Tromey
@ 2019-02-13 21:49 ` John Baldwin
  2019-02-14 14:48   ` Tom Tromey
  2019-02-14 15:34   ` Pedro Alves
  2019-02-13 21:53 ` [PATCH 19/20] Use SCOPE_EXIT in write_gcore_file Tom Tromey
  20 siblings, 2 replies; 28+ messages in thread
From: John Baldwin @ 2019-02-13 21:49 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 2/13/19 1:29 PM, Tom Tromey wrote:
> This series removes the remaining uses of make_cleanup from the tree,
> then removes make_cleanup and some related functions (but note that
> final cleanups remain).
> 
> Then, it removes the TRY/CATCH macros in favor of ordinary C++ code.
> 
> Finally, it cleans up a few spots that currently use TRY/CATCH but
> that are more succinctly written using SCOPE_EXIT or RAII.
> 
> Regression tested by the buildbot.

Yay!

The only comment I have is that the structure names for exceptions look a
bit awkward in code now with the mix of lower and upper case, e.g.:

   try
     {
       e_msg = ada_exception_message_1 ();
     }
   catch (struct gdb_exception_RETURN_MASK_ERROR &e)
     {
       e_msg.reset (nullptr);
     }

We could drop the 'struct' perhaps, but not sure if we could simplify the
classes a bit to something like:

struct gdb_exception_error : public gdb_exception
{
};

struct gdb_exception_quit : public gdb_exception
{
};

And use 'gdb_execption' instead of 'struct gdb_exception_RETURN_MASK_ALL',
'gdb_exception_error' instead of 'struct gdb_exception_RETURN_MASK_ERROR',
and 'gdb_exception_quit' instead of 'struct gdb_exception_RETURN_MASK_QUIT'?

-- 
John Baldwin

                                                                            

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

* [PATCH 19/20] Use SCOPE_EXIT in write_gcore_file
  2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
                   ` (19 preceding siblings ...)
  2019-02-13 21:49 ` [PATCH 00/20] Remove cleanups John Baldwin
@ 2019-02-13 21:53 ` Tom Tromey
  20 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-13 21:53 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-13  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 0684ac17c33..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 (struct gdb_exception_RETURN_MASK_ALL &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] 28+ messages in thread

* Re: [PATCH 00/20] Remove cleanups
  2019-02-13 21:49 ` [PATCH 00/20] Remove cleanups John Baldwin
@ 2019-02-14 14:48   ` Tom Tromey
  2019-02-14 20:38     ` John Baldwin
  2019-02-14 15:34   ` Pedro Alves
  1 sibling, 1 reply; 28+ messages in thread
From: Tom Tromey @ 2019-02-14 14:48 UTC (permalink / raw)
  To: John Baldwin; +Cc: Tom Tromey, gdb-patches

>>>>> "John" == John Baldwin <jhb@FreeBSD.org> writes:

John> The only comment I have is that the structure names for exceptions look a
John> bit awkward in code now with the mix of lower and upper case, e.g.:

That is a good point.  I think I can easily update the exception
rewriter to also rename these classes.  I will take a look.  Plan B is
to just have a second patch to do the renaming.

thanks,
Tom

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

* Re: [PATCH 00/20] Remove cleanups
  2019-02-13 21:49 ` [PATCH 00/20] Remove cleanups John Baldwin
  2019-02-14 14:48   ` Tom Tromey
@ 2019-02-14 15:34   ` Pedro Alves
  2019-02-14 16:35     ` Tom Tromey
  1 sibling, 1 reply; 28+ messages in thread
From: Pedro Alves @ 2019-02-14 15:34 UTC (permalink / raw)
  To: John Baldwin, Tom Tromey, gdb-patches

On 02/13/2019 09:48 PM, John Baldwin wrote:
> On 2/13/19 1:29 PM, Tom Tromey wrote:
>> This series removes the remaining uses of make_cleanup from the tree,
>> then removes make_cleanup and some related functions (but note that
>> final cleanups remain).
>>
>> Then, it removes the TRY/CATCH macros in favor of ordinary C++ code.
>>
>> Finally, it cleans up a few spots that currently use TRY/CATCH but
>> that are more succinctly written using SCOPE_EXIT or RAII.
>>
>> Regression tested by the buildbot.
> 
> Yay!
> 
> The only comment I have is that the structure names for exceptions look a
> bit awkward in code now with the mix of lower and upper case, e.g.:
> 
>    try
>      {
>        e_msg = ada_exception_message_1 ();
>      }
>    catch (struct gdb_exception_RETURN_MASK_ERROR &e)
>      {
>        e_msg.reset (nullptr);
>      }
> 
> We could drop the 'struct' perhaps, but not sure if we could simplify the
> classes a bit to something like:
> 
> struct gdb_exception_error : public gdb_exception
> {
> };
> 
> struct gdb_exception_quit : public gdb_exception
> {
> };
> 
> And use 'gdb_execption' instead of 'struct gdb_exception_RETURN_MASK_ALL',
> 'gdb_exception_error' instead of 'struct gdb_exception_RETURN_MASK_ERROR',
> and 'gdb_exception_quit' instead of 'struct gdb_exception_RETURN_MASK_QUIT'?

Yes please.  The only reason I originally named those structs that way
was to make the CATCH macro simpler to map in the C++ variant:

 #define CATCH(EXCEPTION, MASK)                                          \
           } while (0);                                                  \
         }                                                               \
     catch (struct gdb_exception ## _ ## MASK &EXCEPTION)

We should also catch by const reference, IMO.  Is there a good reason
for the non-const-ness?

Thanks,
Pedro Alves

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

* Re: [PATCH 00/20] Remove cleanups
  2019-02-14 15:34   ` Pedro Alves
@ 2019-02-14 16:35     ` Tom Tromey
  0 siblings, 0 replies; 28+ messages in thread
From: Tom Tromey @ 2019-02-14 16:35 UTC (permalink / raw)
  To: Pedro Alves; +Cc: John Baldwin, Tom Tromey, gdb-patches

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

Pedro> We should also catch by const reference, IMO.  Is there a good reason
Pedro> for the non-const-ness?

Just conservatism on my part, but it is easy to do the experiment.

Tom

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

* Re: [PATCH 00/20] Remove cleanups
  2019-02-14 14:48   ` Tom Tromey
@ 2019-02-14 20:38     ` John Baldwin
  2019-02-14 22:49       ` Tom Tromey
  0 siblings, 1 reply; 28+ messages in thread
From: John Baldwin @ 2019-02-14 20:38 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On 2/14/19 6:48 AM, Tom Tromey wrote:
>>>>>> "John" == John Baldwin <jhb@FreeBSD.org> writes:
> 
> John> The only comment I have is that the structure names for exceptions look a
> John> bit awkward in code now with the mix of lower and upper case, e.g.:
> 
> That is a good point.  I think I can easily update the exception
> rewriter to also rename these classes.  I will take a look.  Plan B is
> to just have a second patch to do the renaming.

I think a second pass is fine unless its trivial to re-run the script.  I
second Pedro's suggestion about trying 'const' as well.

-- 
John Baldwin

                                                                            

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

* Re: [PATCH 00/20] Remove cleanups
  2019-02-14 20:38     ` John Baldwin
@ 2019-02-14 22:49       ` Tom Tromey
  2019-02-14 22:55         ` John Baldwin
  0 siblings, 1 reply; 28+ messages in thread
From: Tom Tromey @ 2019-02-14 22:49 UTC (permalink / raw)
  To: John Baldwin; +Cc: Tom Tromey, gdb-patches

>>>>> "John" == John Baldwin <jhb@FreeBSD.org> writes:

John> I think a second pass is fine unless its trivial to re-run the script.  I
John> second Pedro's suggestion about trying 'const' as well.

"const" worked fine.

For the renaming I've opted for a second patch, since it was simpler to
deal with the ChangeLog this way.

I don't plan to check this in until after other things have landed and
the 8.3 branch has been made.

Tom

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

* Re: [PATCH 00/20] Remove cleanups
  2019-02-14 22:49       ` Tom Tromey
@ 2019-02-14 22:55         ` John Baldwin
  0 siblings, 0 replies; 28+ messages in thread
From: John Baldwin @ 2019-02-14 22:55 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On 2/14/19 2:49 PM, Tom Tromey wrote:
>>>>>> "John" == John Baldwin <jhb@FreeBSD.org> writes:
> 
> John> I think a second pass is fine unless its trivial to re-run the script.  I
> John> second Pedro's suggestion about trying 'const' as well.
> 
> "const" worked fine.

\o/

> For the renaming I've opted for a second patch, since it was simpler to
> deal with the ChangeLog this way.
> 
> I don't plan to check this in until after other things have landed and
> the 8.3 branch has been made.

Sounds good to me.

-- 
John Baldwin

                                                                            

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

end of thread, other threads:[~2019-02-14 22:55 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-13 21:29 [PATCH 00/20] Remove cleanups Tom Tromey
2019-02-13 21:29 ` [PATCH 12/20] Remove free_current_contents Tom Tromey
2019-02-13 21:29 ` [PATCH 05/20] Remove last cleanup from gdbserver Tom Tromey
2019-02-13 21:29 ` [PATCH 03/20] Change displaced_step_clear_cleanup with a forward_scope_exit Tom Tromey
2019-02-13 21:29 ` [PATCH 17/20] Make exception throwing a bit more efficient Tom Tromey
2019-02-13 21:29 ` [PATCH 06/20] Remove cleanup from solib-svr4.c Tom Tromey
2019-02-13 21:29 ` [PATCH 11/20] Remove basic cleanup code Tom Tromey
2019-02-13 21:29 ` [PATCH 20/20] Introduce and use bcache_up Tom Tromey
2019-02-13 21:29 ` [PATCH 07/20] Remove last cleanups from solib-svr4.c Tom Tromey
2019-02-13 21:29 ` [PATCH 16/20] Remove some now-dead exception code Tom Tromey
2019-02-13 21:29 ` [PATCH 01/20] Remove cleanups from coffread.c Tom Tromey
2019-02-13 21:29 ` [PATCH 14/20] Make exceptions use std::string and be self-managing Tom Tromey
2019-02-13 21:30 ` [PATCH 13/20] Simplify exception handling Tom Tromey
2019-02-13 21:30 ` [PATCH 04/20] C++ify remote notification code Tom Tromey
2019-02-13 21:30 ` [PATCH 10/20] Remove last cleanups from stabsread.c Tom Tromey
2019-02-13 21:30 ` [PATCH 09/20] Remove last cleanup from linux-namespaces.c Tom Tromey
2019-02-13 21:30 ` [PATCH 02/20] Update two cleanup comments Tom Tromey
2019-02-13 21:30 ` [PATCH 18/20] Replace throw_exception with throw in some cases Tom Tromey
2019-02-13 21:30 ` [PATCH 15/20] Rewrite TRY/CATCH Tom Tromey
2019-02-13 21:30 ` [PATCH 08/20] Remove last cleanup solib-aix.c Tom Tromey
2019-02-13 21:49 ` [PATCH 00/20] Remove cleanups John Baldwin
2019-02-14 14:48   ` Tom Tromey
2019-02-14 20:38     ` John Baldwin
2019-02-14 22:49       ` Tom Tromey
2019-02-14 22:55         ` John Baldwin
2019-02-14 15:34   ` Pedro Alves
2019-02-14 16:35     ` Tom Tromey
2019-02-13 21:53 ` [PATCH 19/20] Use SCOPE_EXIT in write_gcore_file 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).