From 7a333478ff7acb36cb25b24e09fb7274f64463bf Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Mon, 19 Aug 2024 09:04:05 -0400 Subject: [PATCH] Create new string when demangling stacktraces --- source/base/exceptions.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/source/base/exceptions.cc b/source/base/exceptions.cc index f20d577be1..91900a1cd2 100644 --- a/source/base/exceptions.cc +++ b/source/base/exceptions.cc @@ -285,8 +285,9 @@ ExceptionBase::print_stack_trace(std::ostream &out) const std::string functionname = stacktrace_entry.substr(pos_start + 1, pos_end - pos_start - 1); - stacktrace_entry.resize(pos_start); - stacktrace_entry += ": "; + std::string demangled_stacktrace_entry = + stacktrace_entry.substr(0, pos_start); + demangled_stacktrace_entry += ": "; // demangle, and if successful replace old mangled string by // unmangled one (skipping address and offset). treat "main" @@ -311,20 +312,20 @@ ExceptionBase::print_stack_trace(std::ostream &out) const realname.erase(realname.find(", boost::tuples::null_type>"), std::string(", boost::tuples::null_type").size()); - stacktrace_entry += realname; + demangled_stacktrace_entry += realname; } else - stacktrace_entry += functionname; + demangled_stacktrace_entry += functionname; free(p); #else - stacktrace_entry += functionname; + demangled_stacktrace_entry += functionname; #endif // then output what we have - out << stacktrace_entry << std::endl; + out << demangled_stacktrace_entry << std::endl; // stop if we're in main() if (functionname == "main") -- 2.39.5