[llvm] [NFC] refactor demangle of llvm-nm (PR #67481)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 26 12:58:25 PDT 2023
https://github.com/diggerlin created https://github.com/llvm/llvm-project/pull/67481
since we landed the patch `https://reviews.llvm.org/D139864 [llvm-cxxfilt] Do not consider the prefix dot as part of the demangled symbol name`. we can simply the code on the llvm-nm demanlge by using the llvm::demangle directly.
>From 61a16874e56048814b68ed49fdea58362551d9be Mon Sep 17 00:00:00 2001
From: zhijian <zhijian at ca.ibm.com>
Date: Tue, 26 Sep 2023 15:38:11 -0400
Subject: [PATCH] [NFC] refactor demangle of llvm-nm
---
llvm/tools/llvm-nm/llvm-nm.cpp | 35 ++--------------------------------
1 file changed, 2 insertions(+), 33 deletions(-)
diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp
index 051fa3e5bfa5a98..6812a90c4cfaeb6 100644
--- a/llvm/tools/llvm-nm/llvm-nm.cpp
+++ b/llvm/tools/llvm-nm/llvm-nm.cpp
@@ -629,30 +629,6 @@ static void darwinPrintStab(MachOObjectFile *MachO, const NMSymbol &S) {
outs() << format(" %02x", NType);
}
-static std::optional<std::string> demangle(StringRef Name) {
- std::string Demangled;
- if (nonMicrosoftDemangle(Name, Demangled))
- return Demangled;
- return std::nullopt;
-}
-
-static std::optional<std::string> demangleXCOFF(StringRef Name) {
- if (Name.empty() || Name[0] != '.')
- return demangle(Name);
-
- Name = Name.drop_front();
- std::optional<std::string> DemangledName = demangle(Name);
- if (DemangledName)
- return "." + *DemangledName;
- return std::nullopt;
-}
-
-static std::optional<std::string> demangleMachO(StringRef Name) {
- if (!Name.empty() && Name[0] == '_')
- Name = Name.drop_front();
- return demangle(Name);
-}
-
static bool symbolIsDefined(const NMSymbol &Sym) {
return Sym.TypeChar != 'U' && Sym.TypeChar != 'w' && Sym.TypeChar != 'v';
}
@@ -822,15 +798,8 @@ static void printSymbolList(SymbolicFile &Obj,
std::string Name = S.Name;
MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(&Obj);
- if (Demangle) {
- function_ref<std::optional<std::string>(StringRef)> Fn = ::demangle;
- if (Obj.isXCOFF())
- Fn = demangleXCOFF;
- if (Obj.isMachO())
- Fn = demangleMachO;
- if (std::optional<std::string> Opt = Fn(S.Name))
- Name = *Opt;
- }
+ if (Demangle)
+ Name = llvm::demangle(Name);
if (PrintFileName)
writeFileName(outs(), ArchiveName, ArchitectureName);
More information about the llvm-commits
mailing list