diff options
author | Pedro Alves <palves@redhat.com> | 2015-11-17 15:17:46 +0000 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2015-11-17 15:23:15 +0000 |
commit | eec461d0a8e7ae14c7fe8f0196ab8d0e30285d83 (patch) | |
tree | 5daba190a7a9e2e54b413e69ffefdb18cd7f315d /gdb/common/common-exceptions.h | |
parent | 91ee7171d0886731900ab0238ce3795241d877a4 (diff) | |
download | binutils-eec461d0a8e7ae14c7fe8f0196ab8d0e30285d83.zip binutils-eec461d0a8e7ae14c7fe8f0196ab8d0e30285d83.tar.gz binutils-eec461d0a8e7ae14c7fe8f0196ab8d0e30285d83.tar.bz2 |
[C++] Always use setjmp/longjmp for exceptions
We currently throw exceptions from signal handlers (e.g., for
Quit/ctrl-c). But throwing C++ exceptions from signal handlers is
undefined. (That doesn't restore signal masks, like siglongjmp does,
and, because asynchronous signals can arrive at any instruction, we'd
have to build _everything_ with -fasync-unwind-tables to make it
reliable.) It happens to work on x86_64 GNU/Linux at least, but it's
likely broken on other ports.
Until we stop throwing from signal handlers, use setjmp/longjmp based
exceptions in C++ mode as well.
gdb/ChangeLog:
2015-11-17 Pedro Alves <palves@redhat.com>
* common/common-exceptions.h (GDB_XCPT_SJMP, GDB_XCPT_TRY)
(GDB_XCPT_RAW_TRY, GDB_XCPT): Define.
Replace __cplusplus checks with GDB_XCPT checks throughout.
* common/common-exceptions.c: Replace __cplusplus checks with
GDB_XCPT checks throughout.
Diffstat (limited to 'gdb/common/common-exceptions.h')
-rw-r--r-- | gdb/common/common-exceptions.h | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/gdb/common/common-exceptions.h b/gdb/common/common-exceptions.h index 51795b1..def08b1 100644 --- a/gdb/common/common-exceptions.h +++ b/gdb/common/common-exceptions.h @@ -116,12 +116,32 @@ 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. This is + the only mode supported when GDB is built as a C program. */ +#define GDB_XCPT_SJMP 1 + +/* Make GDB exceptions use try/catch behind the scenes. Can't be made + the default until we stop throwing exceptions from signal + handlers. */ +#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 + +/* Always use setjmp/longmp, even in C++ mode. */ +#define GDB_XCPT GDB_XCPT_SJMP + /* Functions to drive the exceptions state machine. Though declared here by necessity, these functions should be considered internal to the exceptions subsystem and not used other than via the TRY/CATCH macros defined below. */ -#ifndef __cplusplus +#if GDB_XCPT == GDB_XCPT_SJMP 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); @@ -157,7 +177,7 @@ extern void exception_rethrow (void); */ -#ifndef __cplusplus +#if GDB_XCPT == GDB_XCPT_SJMP #define TRY \ { \ @@ -176,7 +196,9 @@ extern void exception_rethrow (void); #define END_CATCH \ } -#else +#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 @@ -195,13 +217,7 @@ struct exception_try_scope void *saved_state; }; -/* Define this 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 USE_RAW_CXX_TRY - -#ifndef USE_RAW_CXX_TRY +#if GDB_XCPT == GDB_XCPT_TRY /* We still need to wrap TRY/CATCH in C++ so that cleanups and C++ exceptions can coexist. The TRY blocked is wrapped in a @@ -224,6 +240,7 @@ struct exception_try_scope { \ exception_rethrow (); \ } + #else #define TRY try @@ -249,7 +266,7 @@ struct gdb_exception_RETURN_MASK_QUIT : public gdb_exception_RETURN_MASK_ALL { }; -#endif +#endif /* GDB_XCPT_TRY || GDB_XCPT_RAW_TRY */ /* *INDENT-ON* */ |