X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fpbd%2Fstacktrace.cc;h=805b9a2e840e211fd1dac478e364db0071c776f3;hb=cd28d62b26214770cfc269aafe666ec2fb3f2607;hp=dc9a5e18abca108db3a2c314680cfa7d566b2041;hpb=f3cf31009a3b52fa126356b6f826958393c6a956;p=ardour.git diff --git a/libs/pbd/stacktrace.cc b/libs/pbd/stacktrace.cc index dc9a5e18ab..805b9a2e84 100644 --- a/libs/pbd/stacktrace.cc +++ b/libs/pbd/stacktrace.cc @@ -17,7 +17,10 @@ */ -#include +#include "libpbd-config.h" + +#include "pbd/stacktrace.h" +#include #include void @@ -30,7 +33,40 @@ PBD::trace_twb () #ifdef HAVE_EXECINFO #include -#include +#include + +std::string demangle (std::string const & l) +{ + std::string::size_type const b = l.find_first_of ("("); + if (b == std::string::npos) { + return l; + } + + std::string::size_type const p = l.find_last_of ("+"); + if (p == std::string::npos) { + return l; + } + + if ((p - b) <= 1) { + return l; + } + + std::string const fn = l.substr (b + 1, p - b - 1); + + int status; + try { + + char* realname = abi::__cxa_demangle (fn.c_str(), 0, 0, &status); + std::string d (realname); + free (realname); + return d; + + } catch (std::exception) { + + } + + return l; +} void PBD::stacktrace (std::ostream& out, int levels) @@ -41,24 +77,27 @@ PBD::stacktrace (std::ostream& out, int levels) size_t i; size = backtrace (array, 200); - strings = backtrace_symbols (array, size); - - if (strings) { - printf ("Obtained %zd stack frames.\n", size); - - for (i = 0; i < size && (levels == 0 || i < size_t(levels)); i++) { - out << strings[i] << std::endl; + if (size) { + strings = backtrace_symbols (array, size); + + if (strings) { + + for (i = 0; i < size && (levels == 0 || i < size_t(levels)); i++) { + out << " " << demangle (strings[i]) << std::endl; + } + + free (strings); } - - free (strings); + } else { + out << "no stacktrace available!" << std::endl; } } #else void -PBD::stacktrace (std::ostream& out, int levels) +PBD::stacktrace (std::ostream& out, int /*levels*/) { out << "stack tracing is not enabled on this platform" << std::endl; }