From ae484f0ed2fa754abee322a4f0621a3f707e13e5 Mon Sep 17 00:00:00 2001 From: Jeremy <51220084+jeremy-rifkin@users.noreply.github.com> Date: Sun, 8 Oct 2023 14:55:21 -0400 Subject: [PATCH] Improve terminate handler behavior when there's no active exception and also try to print a trace for non-cpptrace terminates --- include/cpptrace/cpptrace.hpp | 3 ++- src/cpptrace.cpp | 34 ++++++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/include/cpptrace/cpptrace.hpp b/include/cpptrace/cpptrace.hpp index 9d75d74..2a189d0 100644 --- a/include/cpptrace/cpptrace.hpp +++ b/include/cpptrace/cpptrace.hpp @@ -114,7 +114,8 @@ namespace cpptrace { inline const_iterator cbegin() const noexcept { return frames.cbegin(); } inline const_iterator cend() const noexcept { return frames.cend(); } private: - CPPTRACE_API void print(std::ostream& stream, bool color, bool newline_at_end) const; + CPPTRACE_API void print(std::ostream& stream, bool color, bool newline_at_end, const char* header) const; + friend void print_terminate_trace(); }; CPPTRACE_API raw_trace generate_raw_trace(std::uint_least32_t skip = 0); diff --git a/src/cpptrace.cpp b/src/cpptrace.cpp index 47ca4f1..96d94fa 100644 --- a/src/cpptrace.cpp +++ b/src/cpptrace.cpp @@ -160,15 +160,15 @@ namespace cpptrace { CPPTRACE_API void stacktrace::print(std::ostream& stream, bool color) const { - print(stream, color, true); + print(stream, color, true, nullptr); } CPPTRACE_API - void stacktrace::print(std::ostream& stream, bool color, bool newline_at_end) const { + void stacktrace::print(std::ostream& stream, bool color, bool newline_at_end, const char* header) const { if(color) { detail::enable_virtual_terminal_processing_if_needed(); } - stream<<"Stack trace (most recent call first):"<"<