diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/demangler/DemangledObject.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/demangler/DemangledObject.java index cf1b01e898..efdcf1f967 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/demangler/DemangledObject.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/demangler/DemangledObject.java @@ -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 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 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, something like: - + 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; diff --git a/Ghidra/Features/GnuDemangler/src/main/java/ghidra/app/util/demangler/gnu/GnuDemanglerParser.java b/Ghidra/Features/GnuDemangler/src/main/java/ghidra/app/util/demangler/gnu/GnuDemanglerParser.java index a4683cc6a8..bdc59032e7 100644 --- a/Ghidra/Features/GnuDemangler/src/main/java/ghidra/app/util/demangler/gnu/GnuDemanglerParser.java +++ b/Ghidra/Features/GnuDemangler/src/main/java/ghidra/app/util/demangler/gnu/GnuDemanglerParser.java @@ -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) { diff --git a/Ghidra/Features/GnuDemangler/src/test/java/ghidra/app/util/demangler/gnu/GnuDemanglerTest.java b/Ghidra/Features/GnuDemangler/src/test/java/ghidra/app/util/demangler/gnu/GnuDemanglerTest.java index 9fd5aceee8..86b77b3416 100644 --- a/Ghidra/Features/GnuDemangler/src/test/java/ghidra/app/util/demangler/gnu/GnuDemanglerTest.java +++ b/Ghidra/Features/GnuDemangler/src/test/java/ghidra/app/util/demangler/gnu/GnuDemanglerTest.java @@ -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, pool_allocator >::~basic_ostringstream()", + dobj.getRawDemangled()); + // // Now disable demangled string replacement //