adjust demangling code a bit so that it can easily be used with typenames and not...
authorPaul Davis <paul@linuxaudiosystems.com>
Fri, 5 Apr 2013 15:26:39 +0000 (11:26 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Fri, 5 Apr 2013 15:26:39 +0000 (11:26 -0400)
libs/pbd/pbd/stacktrace.h
libs/pbd/stacktrace.cc

index 94d07cab96ba82bea8d948dad9c1e027698874aa..f3c7baf7d78fb6bb72dfec10d2b1ac2f5460244a 100644 (file)
@@ -37,6 +37,7 @@
 namespace PBD {
        void stacktrace (std::ostream& out, int levels = 0);
        void trace_twb();
 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 
 
 template<typename T>
 class thing_with_backtrace 
index ca614509a5196c6b30a883ea8dcd50c126af1179..ead7e33e4bf7814e06bcdf858d4ccd830438e06d 100644 (file)
@@ -35,37 +35,45 @@ PBD::trace_twb ()
 #include <execinfo.h>
 #include <cxxabi.h>
 
 #include <execinfo.h>
 #include <cxxabi.h>
 
-std::string demangle (std::string const & l)
+static std::string 
+symbol_demangle (const std::string& l)
+{
+       int status;
+
+       try {
+               
+               char* realname = abi::__cxa_demangle (l.c_str(), 0, 0, &status);
+               std::string d (realname);
+               free (realname);
+               return d;
+       } catch (std::exception) {
+               
+       }
+
+       return l;
+}
+
+std::string 
+PBD::demangle (std::string const & l)
 {
        std::string::size_type const b = l.find_first_of ("(");
 {
        std::string::size_type const b = l.find_first_of ("(");
+
        if (b == std::string::npos) {
        if (b == std::string::npos) {
-               return l;
+               return symbol_demangle (l);
        }
 
        std::string::size_type const p = l.find_last_of ("+");
        if (p == std::string::npos) {
        }
 
        std::string::size_type const p = l.find_last_of ("+");
        if (p == std::string::npos) {
-               return l;
+               return symbol_demangle (l);
        }
 
        if ((p - b) <= 1) {
        }
 
        if ((p - b) <= 1) {
-               return l;
+               return symbol_demangle (l);
        }
        
        std::string const fn = l.substr (b + 1, p - b - 1);
 
        }
        
        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;
+       return symbol_demangle (fn);
 }
 
 void
 }
 
 void