Merge remote-tracking branch 'origin/GP-4885-dragonmacher-gnu-demangler-keep-raw-demangled--SQUASHED'

This commit is contained in:
Ryan Kurtz 2024-11-19 13:11:55 -05:00
commit 9421ec0ab0
3 changed files with 56 additions and 18 deletions

View File

@ -44,41 +44,48 @@ public abstract class DemangledObject implements Demangled {
/* /*
The following names probably need to be refactored. Until then, this is how the following The following names probably need to be refactored. Until then, this is how the following
fields are used. fields are used.
mangled - mangled -
Source: The original mangled string as seen in the program Source: The original mangled string as seen in the program
Usage: Can be used to see if a program symbol has already been demangled 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 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 Usage: for display
demangledName - demangledName -
Source: The name as created by the parser which may transform or even replace the Source: The name as created by the parser which may transform or even replace the
string returned from the demangler string returned from the demangler
Usage: for display Usage: for display
name - name -
Source: This is derived from the 'demangledName' This is updated to be suitable 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 for use as a symbol name. This may be null while building, but is
expected to be non-null when applyTo() is called expected to be non-null when applyTo() is called
Usage: The name that will be applied when applyTo() is called. Usage: The name that will be applied when applyTo() is called.
Future: These variables should be refactored and renamed to be clearer and more cohesive, Future: These variables should be refactored and renamed to be clearer and more cohesive,
something like: something like:
mangled mangled
rawDemangled rawDemangled
escapedDemangled simplifiedDemangled --| These two could be combined into 'transformedDemangled'
escapedDemangled --|
symbolName symbolName
*/ */
protected MangledContext mangledContext; // the mangled context, which includes mangled string protected MangledContext mangledContext; // the mangled context, which includes mangled string
protected final String mangled; // original mangled string protected final String mangled; // original mangled string
protected String originalDemangled; // raw demangled string protected String rawDemangled; // demangled string from the demangler without any simplifications
private String demangledName; // updated demangled string 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 private String name; // version of demangled name suitable for symbols
protected String specialPrefix; protected String specialPrefix;
@ -120,6 +127,7 @@ public abstract class DemangledObject implements Demangled {
DemangledObject(String mangled, String originalDemangled) { DemangledObject(String mangled, String originalDemangled) {
this.mangled = mangled; this.mangled = mangled;
this.originalDemangled = originalDemangled; this.originalDemangled = originalDemangled;
this.rawDemangled = originalDemangled;
} }
/** /**
@ -132,6 +140,7 @@ public abstract class DemangledObject implements Demangled {
this.mangledContext = mangledContext; this.mangledContext = mangledContext;
this.mangled = mangledContext.getMangled(); this.mangled = mangledContext.getMangled();
this.originalDemangled = originalDemangled; this.originalDemangled = originalDemangled;
this.rawDemangled = originalDemangled;
} }
@Override @Override
@ -280,6 +289,24 @@ public abstract class DemangledObject implements Demangled {
this.originalDemangled = originalDemangled; 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 @Override
public Demangled getNamespace() { public Demangled getNamespace() {
return namespace; return namespace;

View File

@ -412,6 +412,7 @@ public class GnuDemanglerParser {
demangled = cleanupRustLegacySymbol(demangled); demangled = cleanupRustLegacySymbol(demangled);
String rawDemangled = demangled;
if (simplify) { if (simplify) {
demangled = replaceStdLibraryTypes(demangled); demangled = replaceStdLibraryTypes(demangled);
} }
@ -421,10 +422,16 @@ public class GnuDemanglerParser {
DemangledObjectBuilder builder = getSpecializedBuilder(demangled); DemangledObjectBuilder builder = getSpecializedBuilder(demangled);
if (builder != null) { 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) { 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)", "virtual thunk to undefined __thiscall std::ostringstream::~ostringstream(void)",
signature); 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 // Now disable demangled string replacement
// //