@@ -14,6 +14,27 @@ std::optional<std::string> RTTI::DemangleNameMS(BinaryView* view, bool allowMang
1414}
1515
1616
17+ std::optional<std::string> RTTI::DemangleNameGNU3 (BinaryView* view, bool allowMangled, const std::string &mangledName)
18+ {
19+ QualifiedName demangledName = {};
20+ Ref<Type> outType = {};
21+
22+ // TODO: This is disabled because most of the uses of this were making the problem worse by demangling
23+ // TODO: To a very generic string that dozens of classes would then look like. We likely need to add some extra
24+ // TODO: sauce to the demangler to pickup strings like:
25+ // TODO: REAL: PackageListGui::PackageListGui(Filesystem::Path&&, PackageListGui::UnderSubheader, bool)::$_1[0x0]
26+ // TODO: OURS: PackageListGui::PackageListGui
27+ // TODO: OURS MANGLED: ZN14PackageListGuiC1EON10Filesystem4PathENS_14UnderSubheaderEbE3$_1
28+ // For some reason some of the names that start with ZN are not prefixed by `_`.
29+ // if (mangled.find("ZN") == 0)
30+ // mangled = "_" + mangled;
31+
32+ if (!DemangleGNU3 (view->GetDefaultArchitecture (), mangledName, outType, demangledName, true ))
33+ return allowMangled ? std::optional (mangledName) : std::nullopt ;
34+ return demangledName.GetString ();
35+ }
36+
37+
1738std::string RemoveItaniumPrefix (std::string &name)
1839{
1940 // Remove numerical prefixes.
@@ -26,7 +47,10 @@ std::string RemoveItaniumPrefix(std::string &name)
2647
2748std::optional<std::string> RTTI::DemangleNameItanium (BinaryView* view, bool allowMangled, const std::string &mangledName)
2849{
29- if (auto demangledName = DemangleNameLLVM (allowMangled, mangledName))
50+ // NOTE: Passing false to allowMangled to fallthrough to GNU3 demangler.
51+ if (auto demangledName = DemangleNameLLVM (false , mangledName))
52+ return RemoveItaniumPrefix (demangledName.value ());
53+ if (auto demangledName = DemangleNameGNU3 (view, allowMangled, mangledName))
3054 return RemoveItaniumPrefix (demangledName.value ());
3155 return std::nullopt ;
3256}
0 commit comments