adjust demangling code a bit so that it can easily be used with typenames and not just functions in stacktraces
This commit is contained in:
parent
19bd641915
commit
7db5d68cdb
@ -37,6 +37,7 @@
|
||||
namespace PBD {
|
||||
void stacktrace (std::ostream& out, int levels = 0);
|
||||
void trace_twb();
|
||||
std::string demangle (const std::string&);
|
||||
|
||||
template<typename T>
|
||||
class thing_with_backtrace
|
||||
|
@ -35,32 +35,17 @@ PBD::trace_twb ()
|
||||
#include <execinfo.h>
|
||||
#include <cxxabi.h>
|
||||
|
||||
std::string demangle (std::string const & l)
|
||||
static std::string
|
||||
symbol_demangle (const std::string& 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);
|
||||
char* realname = abi::__cxa_demangle (l.c_str(), 0, 0, &status);
|
||||
std::string d (realname);
|
||||
free (realname);
|
||||
return d;
|
||||
|
||||
} catch (std::exception) {
|
||||
|
||||
}
|
||||
@ -68,6 +53,29 @@ std::string demangle (std::string const & l)
|
||||
return l;
|
||||
}
|
||||
|
||||
std::string
|
||||
PBD::demangle (std::string const & l)
|
||||
{
|
||||
std::string::size_type const b = l.find_first_of ("(");
|
||||
|
||||
if (b == std::string::npos) {
|
||||
return symbol_demangle (l);
|
||||
}
|
||||
|
||||
std::string::size_type const p = l.find_last_of ("+");
|
||||
if (p == std::string::npos) {
|
||||
return symbol_demangle (l);
|
||||
}
|
||||
|
||||
if ((p - b) <= 1) {
|
||||
return symbol_demangle (l);
|
||||
}
|
||||
|
||||
std::string const fn = l.substr (b + 1, p - b - 1);
|
||||
|
||||
return symbol_demangle (fn);
|
||||
}
|
||||
|
||||
void
|
||||
PBD::stacktrace (std::ostream& out, int levels)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user