|
Revision 5, 1.5 kB
(checked in by qbert, 3 years ago)
|
Initial ( and last :( ) commit
|
| Line | |
|---|
| 1 |
#include "dmd_specifics.h" |
|---|
| 2 |
|
|---|
| 3 |
bool isMangled( string& buf ) { |
|---|
| 4 |
if ( buf.substr(0,2) == "_D" ) { |
|---|
| 5 |
buf = buf.substr(2 ); |
|---|
| 6 |
return true; |
|---|
| 7 |
} |
|---|
| 8 |
return false; |
|---|
| 9 |
} |
|---|
| 10 |
|
|---|
| 11 |
int readNumber (string& buf ) { |
|---|
| 12 |
|
|---|
| 13 |
if ( !isdigit(buf[0 ] ) ) return -1; //return error if not a digit |
|---|
| 14 |
|
|---|
| 15 |
int n = 0, i = 0; |
|---|
| 16 |
while ( isdigit(buf[i]) && i < buf.length() ) { |
|---|
| 17 |
n = 10 * n + (buf[i++] - '0'); |
|---|
| 18 |
} |
|---|
| 19 |
buf = buf.substr(i); |
|---|
| 20 |
return n; |
|---|
| 21 |
} |
|---|
| 22 |
|
|---|
| 23 |
string readString(int number, string& buf ) { |
|---|
| 24 |
string ret = buf.substr(0,number ); |
|---|
| 25 |
buf = buf.substr(number); |
|---|
| 26 |
return ret; |
|---|
| 27 |
} |
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
void demangle(const string& sym, string& moduleName, string& className, string& functionName ) { |
|---|
| 32 |
string buf = sym; |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
if ( buf.length() < 2 ) { |
|---|
| 36 |
return; |
|---|
| 37 |
} |
|---|
| 38 |
else |
|---|
| 39 |
{ |
|---|
| 40 |
if ( isMangled (buf) ) { // if its a mangled name, demangle it |
|---|
| 41 |
|
|---|
| 42 |
string cname = ""; |
|---|
| 43 |
int modSize = readNumber(buf); |
|---|
| 44 |
moduleName = readString(modSize,buf); |
|---|
| 45 |
|
|---|
| 46 |
int num = 0; |
|---|
| 47 |
num = readNumber(buf); |
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
string temp = readString(num,buf); |
|---|
| 51 |
num = readNumber(buf); |
|---|
| 52 |
if ( num == -1 ) { // then its not part of class, no class name |
|---|
| 53 |
className = ""; |
|---|
| 54 |
functionName = temp; |
|---|
| 55 |
} |
|---|
| 56 |
else { |
|---|
| 57 |
cname = temp; |
|---|
| 58 |
while ( num != -1 ) { |
|---|
| 59 |
temp = readString(num,buf); |
|---|
| 60 |
cname += "." + temp; |
|---|
| 61 |
num = readNumber(buf); |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
className = cname.substr(0,cname.length() - ( temp.length() + 1 ) ); |
|---|
| 65 |
//cname[0 .. cname.length - (temp.length + 1)]; |
|---|
| 66 |
functionName = temp; |
|---|
| 67 |
|
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
} |
|---|
| 72 |
else { |
|---|
| 73 |
return; |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
} |
|---|