From cffc3bbc46357fe7a1a5931a65e954f4097e7663 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 14 Sep 2018 13:50:14 +1000 Subject: [PATCH] debug: print more extensive errors during abort_with_trace --- debug.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/debug.cpp b/debug.cpp index cb56a585..725436dd 100644 --- a/debug.cpp +++ b/debug.cpp @@ -70,7 +70,23 @@ warn (const char *msg) //////////////////////////////////////////////////////////////////////////////// static void abort_with_trace (void) { - LOG_EMERGENCY ("aborting: %!", debug::backtrace {}); + // If this is because of an exception we may as well rethrow and hope that + // the system will print exception data during the abort process. + // + // But we can at least try to print anything derived from std::exception + // (which is a likely guess) before we self-destruct. + if (auto ptr = std::current_exception (); ptr) { + try { + std::rethrow_exception (ptr); + } catch (std::exception const &x) { + LOG_EMERGENCY ("unhandled exception: %!\n%!", x.what (), debug::backtrace {}); + } catch (...) { + LOG_EMERGENCY ("unhandled exception: %!\n", debug::backtrace {}); + } + } else { + LOG_EMERGENCY ("aborting: %!", debug::backtrace {}); + } + std::abort (); }