From 15a16b23d9b6bb630bd3c79b64ec023426d1f1de Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Tue, 20 Oct 2020 11:18:34 +0200 Subject: [PATCH] Pass fallback stacktrace to DiagnosticInformation in terminate handler By default, DiagnosticInformation uses the stack trace saved when the exception was thrown, but this mechanism is not in use on Windows. Gathering a stacktrace in the terminate handler serves as a fallback. --- lib/base/application.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/base/application.cpp b/lib/base/application.cpp index 78af235cb..85f0b5e81 100644 --- a/lib/base/application.cpp +++ b/lib/base/application.cpp @@ -877,8 +877,19 @@ void Application::ExceptionHandler() << "\n" << "Additional information is available in '" << fname << "'" << "\n"; + /* On platforms where HAVE_CXXABI_H is defined, we prefer to print the stack trace that was saved + * when the last exception was thrown. Everywhere else, we do not have this information so we + * collect a stack trace here, which might lack some information, for example when an exception + * is rethrown, but this is still better than nothing. + */ + boost::stacktrace::stacktrace *stack = nullptr; +#ifndef HAVE_CXXABI_H + boost::stacktrace::stacktrace local_stack; + stack = &local_stack; +#endif /* HAVE_CXXABI_H */ + ofs << "\n" - << DiagnosticInformation(ex) + << DiagnosticInformation(ex, true, stack) << "\n"; }