aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/cli/cli-cmds.c1
-rw-r--r--gdb/common/common-exceptions.h41
-rw-r--r--gdb/completer.c1
3 files changed, 29 insertions, 14 deletions
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index dad5ffa..51271ad 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -296,6 +296,7 @@ complete_command (char *arg_entry, int from_tty)
{
return;
}
+ END_CATCH
std::string arg_prefix (arg, word - arg);
diff --git a/gdb/common/common-exceptions.h b/gdb/common/common-exceptions.h
index 49f309f..b39abc0 100644
--- a/gdb/common/common-exceptions.h
+++ b/gdb/common/common-exceptions.h
@@ -231,25 +231,38 @@ struct exception_try_scope
#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
- do/while(0) so that break/continue within the block works the same
- as in 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 \
- { \
- exception_try_scope exception_try_scope_instance; \
- do \
- {
+ { \
+ try \
+ { \
+ exception_try_scope exception_try_scope_instance; \
+ do \
+ {
#define CATCH(EXCEPTION, MASK) \
- } while (0); \
- } \
- catch (struct gdb_exception ## _ ## MASK &EXCEPTION)
+ } while (0); \
+ } \
+ catch (struct gdb_exception ## _ ## MASK &EXCEPTION)
#define END_CATCH \
- catch (...) \
- { \
- exception_rethrow (); \
+ catch (...) \
+ { \
+ exception_rethrow (); \
+ } \
}
#else
diff --git a/gdb/completer.c b/gdb/completer.c
index 3022333..cd0ecc3 100644
--- a/gdb/completer.c
+++ b/gdb/completer.c
@@ -1447,6 +1447,7 @@ complete_line_internal (completion_tracker &tracker,
if (except.error != MAX_COMPLETIONS_REACHED_ERROR)
throw_exception (except);
}
+ END_CATCH
}
/* See completer.h. */