Skip to content

Commit d4329e2

Browse files
committed
Use abi::__cxx_demangle for symbol demangling on darwin
1 parent aaffaa4 commit d4329e2

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

library/Process-darwin.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ distribution.
3737
#include <set>
3838
#include <cstdio>
3939
#include <cstring>
40+
#include <cxxabi.h>
4041
using namespace std;
4142

4243
#include <md5wrapper.h>
@@ -111,13 +112,18 @@ Process::~Process()
111112

112113
string Process::doReadClassName (void * vptr)
113114
{
114-
//FIXME: BAD!!!!!
115-
char * typeinfo = Process::readPtr(((char *)vptr - sizeof(void*)));
116-
char * typestring = Process::readPtr(typeinfo + sizeof(void*));
117-
string raw = readCString(typestring);
118-
size_t start = raw.find_first_of("abcdefghijklmnopqrstuvwxyz");// trim numbers
119-
size_t end = raw.length();
120-
return raw.substr(start,end-start);
115+
char* typeinfo = Process:readPtr(((char*)vptr - sizeof(void*)));
116+
char* typestring = Process::readPtr(typeinfo + sizeof(void*));
117+
118+
int status = -1;
119+
char* demangledRaw = abi::__cxa_demangle(typestring, nullptr, nullptr, &status);
120+
if (status != 0)
121+
return "dummy"; // Failed to demangle, return dummy name
122+
123+
string demangled(demangledRaw);
124+
free(demangledRaw);
125+
126+
return demangled;
121127
}
122128

123129
#include <mach/mach.h>

0 commit comments

Comments
 (0)