]> git.tdb.fi Git - libs/core.git/blobdiff - source/debug/demangle.cpp
Add missing includes
[libs/core.git] / source / debug / demangle.cpp
index 58e05cefd58e687fb22928ea02c6fc602a1bca2e..5c348514fd9bffa57ec0d7cbf6acb4539d198880 100644 (file)
@@ -4,6 +4,9 @@ This file is part of libmspcore
 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
 Distributed under the LGPL
 */
+
+#include <cstdlib>
+#include <cxxabi.h>
 #include "demangle.h"
 
 using namespace std;
@@ -11,39 +14,24 @@ using namespace std;
 namespace Msp {
 namespace Debug {
 
-string demangle_gcc3(const string &sym)
+string demangle(const string &sym)
 {
+#ifdef __GNUC__
+       int status;
+       char *dm=abi::__cxa_demangle(sym.c_str(), 0, 0, &status);
+       
        string result;
-
-       if(sym.compare(0, 2, "_Z"))
-               return result;
-
-       string::const_iterator i=sym.begin()+2;
-
-       bool nested=(*i=='N');
-       bool first=true;
-       while(first || (nested && *i!='E'))
-       {
-               unsigned len=0;
-               for(; isdigit(*i); ++i)
-                       len=len*10+(*i-'0');
-               string::const_iterator j=i+len;
-
-               if(!first)
-                       result.append("::");
-               result.append(i, j);
-
-               first=false;
-       }
-
-       if(nested)
-               ++i;
-
-       for(; i!=sym.end(); ++i)
-       {
-               bool ref=(*i=='R');
-               if(ref) ++i;
-       }
+       if(status==0)
+               result=dm;
+       else
+               result=sym;
+       
+       free(dm);
+
+       return result;
+#else
+       return sym;
+#endif
 }
 
 } // namespace Debug