GP-4885 - Gnu Demangler - Save the raw demangled string

This commit is contained in:
dragonmacher 2024-11-19 09:21:42 -05:00
parent 058ecb5eef
commit 8f08f2730d
3 changed files with 56 additions and 18 deletions

View File

@ -45,20 +45,25 @@ public abstract class DemangledObject implements Demangled {
The following names probably need to be refactored. Until then, this is how the following
fields are used.
mangled -
mangled -
Source: The original mangled string as seen in the program
Usage: Can be used to see if a program symbol has already been demangled
originalDemangled -
rawDemangled -
Source: The raw demangled string returned from the demangler
Usage: for debugging
originalDemangled -
Source: The starting demangled string. This will usually be the same as the raw
demangled string. This may have simplifications applied.
Usage: for display
demangledName -
demangledName -
Source: The name as created by the parser which may transform or even replace the
string returned from the demangler
Usage: for display
name -
name -
Source: This is derived from the 'demangledName' This is updated to be suitable
for use as a symbol name. This may be null while building, but is
expected to be non-null when applyTo() is called
@ -71,14 +76,16 @@ public abstract class DemangledObject implements Demangled {
mangled
rawDemangled
escapedDemangled
simplifiedDemangled --| These two could be combined into 'transformedDemangled'
escapedDemangled --|
symbolName
*/
protected MangledContext mangledContext; // the mangled context, which includes mangled string
protected final String mangled; // original mangled string
protected String originalDemangled; // raw demangled string
private String demangledName; // updated demangled string
protected String rawDemangled; // demangled string from the demangler without any simplifications
protected String originalDemangled; // starting demangled string that may have been simplified
private String demangledName; // updated demangled string, possibly with changes made while building
private String name; // version of demangled name suitable for symbols
protected String specialPrefix;
@ -120,6 +127,7 @@ public abstract class DemangledObject implements Demangled {
DemangledObject(String mangled, String originalDemangled) {
this.mangled = mangled;
this.originalDemangled = originalDemangled;
this.rawDemangled = originalDemangled;
}
/**
@ -132,6 +140,7 @@ public abstract class DemangledObject implements Demangled {
this.mangledContext = mangledContext;
this.mangled = mangledContext.getMangled();
this.originalDemangled = originalDemangled;
this.rawDemangled = originalDemangled;
}
@Override
@ -280,6 +289,24 @@ public abstract class DemangledObject implements Demangled {
this.originalDemangled = originalDemangled;
}
/**
* Returns the raw demangled string. This is the value returned from the demangler before any
* simplifications or transformations have been made.
* @return the string
*/
public String getRawDemangled() {
return rawDemangled;
}
/**
* Sets the raw demangled string. This is the value returned from the demangler before any
* simplifications or transformations have been made.
* @param s the string
*/
public void setRawDemangledString(String s) {
this.rawDemangled = s;
}
@Override
public Demangled getNamespace() {
return namespace;

View File

@ -412,6 +412,7 @@ public class GnuDemanglerParser {
demangled = cleanupRustLegacySymbol(demangled);
String rawDemangled = demangled;
if (simplify) {
demangled = replaceStdLibraryTypes(demangled);
}
@ -421,10 +422,16 @@ public class GnuDemanglerParser {
DemangledObjectBuilder builder = getSpecializedBuilder(demangled);
if (builder != null) {
return builder.build();
DemangledObject dobj = builder.build();
// note: the raw demangled is before any simplifications
dobj.setRawDemangledString(rawDemangled);
return dobj;
}
return parseFunctionOrVariable(demangled);
DemangledObject dobj = parseFunctionOrVariable(demangled);
// note: the raw demangled is before any simplifications
dobj.setRawDemangledString(rawDemangled);
return dobj;
}
private DemangledObjectBuilder getSpecializedBuilder(String demangled) {

View File

@ -115,6 +115,10 @@ public class GnuDemanglerTest extends AbstractGenericTest {
"virtual thunk to undefined __thiscall std::ostringstream::~ostringstream(void)",
signature);
assertEquals(
"virtual thunk to std::basic_ostringstream<char, std::char_traits<char>, pool_allocator<char> >::~basic_ostringstream()",
dobj.getRawDemangled());
//
// Now disable demangled string replacement
//