summaryrefslogtreecommitdiff
path: root/plugins/rtti/rtti.cpp
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-03-19 23:20:09 -0400
committerMason Reed <mason@vector35.com>2025-03-19 23:20:09 -0400
commit038e625e0acecd64e4445cf42f154967735db1fd (patch)
tree05743ac3dd24cbca3e7faaeccf64c908497c7b62 /plugins/rtti/rtti.cpp
parent1aa0bd3b0e15113c90f87744a1c3bae4ae79a283 (diff)
Fallback to GNU3 demangler in Itanium RTTI
Diffstat (limited to 'plugins/rtti/rtti.cpp')
-rw-r--r--plugins/rtti/rtti.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/plugins/rtti/rtti.cpp b/plugins/rtti/rtti.cpp
index 91d3481c..57cd52cf 100644
--- a/plugins/rtti/rtti.cpp
+++ b/plugins/rtti/rtti.cpp
@@ -14,6 +14,27 @@ std::optional<std::string> RTTI::DemangleNameMS(BinaryView* view, bool allowMang
}
+std::optional<std::string> RTTI::DemangleNameGNU3(BinaryView* view, bool allowMangled, const std::string &mangledName)
+{
+ QualifiedName demangledName = {};
+ Ref<Type> outType = {};
+
+ // TODO: This is disabled because most of the uses of this were making the problem worse by demangling
+ // TODO: To a very generic string that dozens of classes would then look like. We likely need to add some extra
+ // TODO: sauce to the demangler to pickup strings like:
+ // TODO: REAL: PackageListGui::PackageListGui(Filesystem::Path&&, PackageListGui::UnderSubheader, bool)::$_1[0x0]
+ // TODO: OURS: PackageListGui::PackageListGui
+ // TODO: OURS MANGLED: ZN14PackageListGuiC1EON10Filesystem4PathENS_14UnderSubheaderEbE3$_1
+ // For some reason some of the names that start with ZN are not prefixed by `_`.
+ // if (mangled.find("ZN") == 0)
+ // mangled = "_" + mangled;
+
+ if (!DemangleGNU3(view->GetDefaultArchitecture(), mangledName, outType, demangledName, true))
+ return allowMangled ? std::optional(mangledName) : std::nullopt;
+ return demangledName.GetString();
+}
+
+
std::string RemoveItaniumPrefix(std::string &name)
{
// Remove numerical prefixes.
@@ -26,7 +47,10 @@ std::string RemoveItaniumPrefix(std::string &name)
std::optional<std::string> RTTI::DemangleNameItanium(BinaryView* view, bool allowMangled, const std::string &mangledName)
{
- if (auto demangledName = DemangleNameLLVM(allowMangled, mangledName))
+ // NOTE: Passing false to allowMangled to fallthrough to GNU3 demangler.
+ if (auto demangledName = DemangleNameLLVM(false, mangledName))
+ return RemoveItaniumPrefix(demangledName.value());
+ if (auto demangledName = DemangleNameGNU3(view, allowMangled, mangledName))
return RemoveItaniumPrefix(demangledName.value());
return std::nullopt;
}