Make TRY/CATCH use real C++ try/catch in C++ mode
[deliverable/binutils-gdb.git] / gdb / common / common-exceptions.h
index d2c0beef9def1fa98d13d92f4b277699085f98cb..2e6a6d94db0cd637b47801c91a43d5452a8844c5 100644 (file)
@@ -121,10 +121,16 @@ struct gdb_exception
    the exceptions subsystem and not used other than via the TRY/CATCH
    macros defined below.  */
 
+#ifndef __cplusplus
 extern SIGJMP_BUF *exceptions_state_mc_init (void);
 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);
+#else
+extern void *exception_try_scope_entry (void);
+extern void exception_try_scope_exit (void *saved_state);
+extern void exception_rethrow (void);
+#endif
 
 /* Macro to wrap up standard try/catch behavior.
 
@@ -151,6 +157,8 @@ extern int exceptions_state_mc_catch (struct gdb_exception *, int);
 
   */
 
+#ifndef __cplusplus
+
 #define TRY \
      { \
        SIGJMP_BUF *buf = \
@@ -168,6 +176,65 @@ extern int exceptions_state_mc_catch (struct gdb_exception *, int);
 #define END_CATCH                              \
   }
 
+#else
+
+/* 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.  The TRY blocked is wrapped in a
+   do/while(0) so that break/continue within the block works the same
+   as in C.  */
+#define TRY                                                            \
+  try                                                                  \
+    {                                                                  \
+      exception_try_scope exception_try_scope_instance;                        \
+      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.  */
+
+struct gdb_exception_RETURN_MASK_ALL : public gdb_exception
+{
+};
+
+struct gdb_exception_RETURN_MASK_ERROR : public gdb_exception_RETURN_MASK_ALL
+{
+};
+
+struct gdb_exception_RETURN_MASK_QUIT : public gdb_exception_RETURN_MASK_ALL
+{
+};
+
+#endif
+
 /* *INDENT-ON* */
 
 /* Hook to allow client-specific actions to be performed prior to
This page took 0.025755 seconds and 4 git commands to generate.