-NORETURN static void
-throw_it (enum return_reason reason, enum errors error, const char *fmt,
- va_list ap) ATTR_NORETURN;
-NORETURN static void
+/* 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)