Skip to content

Commit

Permalink
fix duplicate Windows demangle code
Browse files Browse the repository at this point in the history
* remove the 2 duplicate cplus_demangle and stripAtSuffix functions
  to the common library in ntKludges.C

* change signature of cplus_demangle name param to be const char*
  • Loading branch information
kupsch committed Oct 21, 2020
1 parent cdb007f commit 30e8e38
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 116 deletions.
2 changes: 1 addition & 1 deletion common/src/ntHeaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ inline int P_mkdir(const char *pathname, int) {
inline int P_unlink(const char *pathname) {
return _unlink(pathname);
}
extern char *cplus_demangle(char *, int, bool );
extern char *cplus_demangle(const char *, int, bool);
/* We can't export this, it's inline. */
inline std::string P_cplus_demangle( const std::string &symbol, bool includeTypes = false ) {
char *demangled = cplus_demangle( symbol.c_str(), 0, includeTypes );
Expand Down
58 changes: 58 additions & 0 deletions common/src/ntKludges.C
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,61 @@ int P_getopt(int argc, char *argv[], const char *optstring)
return EOF;
return arg_found;
}


/*
* stripAtSuffix
*
* Strips off of a string any suffix that consists of an @ sign followed by
* decimal digits.
*
* str The string to strip the suffix from. The string is altered in place.
*/
static void stripAtSuffix(char *str)
{
// many symbols have a name like foo@4, we must remove the @4
// just searching for an @ is not enough,
// as it may occur on other positions. We search for the last one
// and check that it is followed only by digits.
char *p = strrchr(str, '@');
if (p) {
char *q = p+1;
strtoul(p+1, &q, 10);
if (q > p+1 && *q == '\0') {
*p = '\0';
}
}
}

char *cplus_demangle(const char *c, int, bool includeTypes) {
char buf[1000];
if (c[0]=='_') {
// VC++ 5.0 seems to decorate C symbols differently to C++ symbols
// and the UnDecorateSymbolName() function provided by imagehlp.lib
// doesn't manage (or want) to undecorate them, so it has to be done
// manually, removing a leading underscore from functions & variables
// and the trailing "$stuff" from variables (actually "$Sstuff")
unsigned i;
for (i=1; i<sizeof(buf) && c[i]!='$' && c[i]!='\0'; i++)
buf[i-1]=c[i];
buf[i-1]='\0';
stripAtSuffix(buf);
if (buf[0] == '\0')
return 0; // avoid null names which seem to annoy Paradyn
return P_strdup(buf);
} else {
if (includeTypes) {
if (UnDecorateSymbolName(c, buf, 1000, UNDNAME_COMPLETE| UNDNAME_NO_ACCESS_SPECIFIERS|UNDNAME_NO_MEMBER_TYPE|UNDNAME_NO_MS_KEYWORDS)) {
// printf("Undecorate with types: %s = %s\n", c, buf);
stripAtSuffix(buf);
return P_strdup(buf);
}
} else if (UnDecorateSymbolName(c, buf, 1000, UNDNAME_NAME_ONLY)) {
// else if (UnDecorateSymbolName(c, buf, 1000, UNDNAME_COMPLETE|UNDNAME_32_BIT_DECODE)) {
// printf("Undecorate: %s = %s\n", c, buf);
stripAtSuffix(buf);
return P_strdup(buf);
}
}
return 0;
}
56 changes: 0 additions & 56 deletions dyninstAPI/src/pdwinnt.C
Original file line number Diff line number Diff line change
Expand Up @@ -235,62 +235,6 @@ ReleaseSymbolHandler( HANDLE hPCProcess )
}


/*
* stripAtSuffix
*
* Strips off of a string any suffix that consists of an @ sign followed by
* decimal digits.
*
* str The string to strip the suffix from. The string is altered in place.
*/
static void stripAtSuffix(char *str)
{
// many symbols have a name like foo@4, we must remove the @4
// just searching for an @ is not enough,
// as it may occur on other positions. We search for the last one
// and check that it is followed only by digits.
char *p = strrchr(str, '@');
if (p) {
char *q = p+1;
strtoul(p+1, &q, 10);
if (q > p+1 && *q == '\0') {
*p = '\0';
}
}
}

char *cplus_demangle(char *c, int, bool includeTypes) {
char buf[1000];
if (c[0]=='_') {
// VC++ 5.0 seems to decorate C symbols differently to C++ symbols
// and the UnDecorateSymbolName() function provided by imagehlp.lib
// doesn't manage (or want) to undecorate them, so it has to be done
// manually, removing a leading underscore from functions & variables
// and the trailing "$stuff" from variables (actually "$Sstuff")
unsigned i;
for (i=1; i<sizeof(buf) && c[i]!='$' && c[i]!='\0'; i++)
buf[i-1]=c[i];
buf[i-1]='\0';
stripAtSuffix(buf);
if (buf[0] == '\0') return 0; // avoid null names which seem to annoy Paradyn
return P_strdup(buf);
} else {
if (includeTypes) {
if (UnDecorateSymbolName(c, buf, 1000, UNDNAME_COMPLETE| UNDNAME_NO_ACCESS_SPECIFIERS|UNDNAME_NO_MEMBER_TYPE|UNDNAME_NO_MS_KEYWORDS)) {
// printf("Undecorate with types: %s = %s\n", c, buf);
stripAtSuffix(buf);
return P_strdup(buf);
}
} else if (UnDecorateSymbolName(c, buf, 1000, UNDNAME_NAME_ONLY)) {
// else if (UnDecorateSymbolName(c, buf, 1000, UNDNAME_COMPLETE|UNDNAME_32_BIT_DECODE)) {
// printf("Undecorate: %s = %s\n", c, buf);
stripAtSuffix(buf);
return P_strdup(buf);
}
}
return 0;
}

bool OS::osKill(int pid) {
bool res;
HANDLE h = OpenProcess(PROCESS_ALL_ACCESS, false, pid);
Expand Down
59 changes: 0 additions & 59 deletions symtabAPI/src/Object-nt.C
Original file line number Diff line number Diff line change
Expand Up @@ -91,65 +91,6 @@ static void printSysError(unsigned errNo) {
BOOL CALLBACK SymEnumSymbolsCallback( PSYMBOL_INFO pSymInfo,
ULONG symSize,
PVOID userContext );
/*
* stripAtSuffix
*
* Strips off of a string any suffix that consists of an @ sign followed by
* decimal digits.
*
* str The string to strip the suffix from. The string is altered in place.
*/
static void stripAtSuffix(char *str)
{
// many symbols have a name like foo@4, we must remove the @4
// just searching for an @ is not enough,
// as it may occur on other positions. We search for the last one
// and check that it is followed only by digits.
char *p = strrchr(str, '@');
if (p) {
char *q = p+1;
strtoul(p+1, &q, 10);
if (q > p+1 && *q == '\0') {
*p = '\0';
}
}
}

char *cplus_demangle(char *c, int, bool includeTypes) {

char buf[1000];
if (c[0]=='_') {
// VC++ 5.0 seems to decorate C symbols differently to C++ symbols
// and the UnDecorateSymbolName() function provided by imagehlp.lib
// doesn't manage (or want) to undecorate them, so it has to be done
// manually, removing a leading underscore from functions & variables
// and the trailing "$stuff" from variables (actually "$Sstuff")
unsigned i;
for (i=1; i<sizeof(buf) && c[i]!='$' && c[i]!='\0'; i++)
buf[i-1]=c[i];
buf[i-1]='\0';
stripAtSuffix(buf);
if (buf[0] == '\0')
return 0; // avoid null names which seem to annoy Paradyn
return P_strdup(buf);
}
else {
if (includeTypes) {
if (UnDecorateSymbolName(c, buf, 1000, UNDNAME_COMPLETE| UNDNAME_NO_ACCESS_SPECIFIERS|UNDNAME_NO_MEMBER_TYPE|UNDNAME_NO_MS_KEYWORDS)) {
// printf("Undecorate with types: %s = %s\n", c, buf);
stripAtSuffix(buf);
return P_strdup(buf);
}
}
else if (UnDecorateSymbolName(c, buf, 1000, UNDNAME_NAME_ONLY)) {
//else if (UnDecorateSymbolName(c, buf, 1000, UNDNAME_COMPLETE|UNDNAME_32_BIT_DECODE)) {
//printf("Undecorate: %s = %s\n", c, buf);
stripAtSuffix(buf);
return P_strdup(buf);
}
}
return 0;
}

//---------------------------------------------------------------------------
// Object method implementation
Expand Down

0 comments on commit 30e8e38

Please sign in to comment.