diff options
author | Chris Wilson <chris+github@qwirx.com> | 2008-05-28 14:35:20 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2008-05-28 14:35:20 +0000 |
commit | 264d2e659aae9662df898443816cf5418013a37e (patch) | |
tree | e1458a058d252d03ec7e3d1d316e7215bb0d1cb8 | |
parent | 852ad3dfa3cd883faea2819827627a4fface5c47 (diff) |
Demangle C++ names in backtrace on GCC using C++ ABI routines.
-rw-r--r-- | lib/common/Utils.cpp | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/lib/common/Utils.cpp b/lib/common/Utils.cpp index 90421299..6c3d07f9 100644 --- a/lib/common/Utils.cpp +++ b/lib/common/Utils.cpp @@ -18,6 +18,10 @@ #include <stdlib.h> #endif +#ifdef HAVE_CXXABI_H + #include <cxxabi.h> +#endif + #include "Utils.h" #include "CommonException.h" #include "Logging.h" @@ -76,7 +80,67 @@ void DumpStackBacktrace() for(i = 0; i < size; i++) { - BOX_TRACE(strings[i]); + // Demangling code copied from + // cctbx_sources/boost_adaptbx/meta_ext.cpp, BSD license + + std::string mangled_frame = strings[i]; + std::string output_frame = strings[i]; // default + + #ifdef HAVE_CXXABI_H + int start = mangled_frame.find('('); + int end = mangled_frame.find('+', start); + std::string mangled_func = mangled_frame.substr(start + 1, + end - start - 1); + + size_t len = 256; + std::auto_ptr<char> output_buf(new char [len]); + int status; + + if (abi::__cxa_demangle(mangled_func.c_str(), output_buf.get(), + &len, &status) == NULL) + { + if (status == 0) + { + BOX_WARNING("Demangle failed but no error: " << + mangled_func); + } + else if (status == -1) + { + BOX_WARNING("Demangle failed with " + "memory allocation error: " << + mangled_func); + } + else if (status == -2) + { + /* + BOX_WARNING("Demangle failed with " + "with invalid name: " << + mangled_func); + */ + } + else if (status == -3) + { + BOX_WARNING("Demangle failed with " + "with invalid argument: " << + mangled_func); + } + else + { + BOX_WARNING("Demangle failed with " + "with unknown error " << status << + ": " << mangled_func); + } + } + else + { + output_frame = mangled_frame.substr(0, start + 1) + + // std::string(output_buf.get()) + + output_buf.get() + + mangled_frame.substr(end); + } + #endif // HAVE_CXXABI_H + + BOX_TRACE("Stack frame " << i << ": " << output_frame); } #include "MemLeakFindOff.h" |