[llvm] r340221 - [llvm-objdump] Add ability to demangle COFF symbols.
Zachary Turner via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 20 15:18:22 PDT 2018
Author: zturner
Date: Mon Aug 20 15:18:21 2018
New Revision: 340221
URL: http://llvm.org/viewvc/llvm-project?rev=340221&view=rev
Log:
[llvm-objdump] Add ability to demangle COFF symbols.
Modified:
llvm/trunk/test/tools/llvm-objdump/X86/disassemble-demangle.test
llvm/trunk/tools/llvm-objdump/COFFDump.cpp
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
llvm/trunk/tools/llvm-objdump/llvm-objdump.h
Modified: llvm/trunk/test/tools/llvm-objdump/X86/disassemble-demangle.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/X86/disassemble-demangle.test?rev=340221&r1=340220&r2=340221&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/X86/disassemble-demangle.test (original)
+++ llvm/trunk/test/tools/llvm-objdump/X86/disassemble-demangle.test Mon Aug 20 15:18:21 2018
@@ -1,9 +1,7 @@
# RUN: yaml2obj %s > %t
# RUN: llvm-objdump -d -C %t | FileCheck --check-prefix=DEMANGLE %s
-# RUN: llvm-objdump -d --demangle=itanium %t | FileCheck --check-prefix=DEMANGLE %s
+# RUN: llvm-objdump -d --demangle %t | FileCheck --check-prefix=DEMANGLE %s
# RUN: llvm-objdump -d %t | FileCheck --check-prefix=NO-DEMANGLE %s
-# RUN: llvm-objdump -d --demangle=none %t | FileCheck --check-prefix=NO-DEMANGLE %s
-# RUN: llvm-objdump -d -C=wrong-style %t 2>&1 | FileCheck --check-prefix=BAD-STYLE %s
!ELF
FileHeader:
@@ -41,7 +39,3 @@ Symbols:
# NO-DEMANGLE: _Z3fooi
# NO-DEMANGLE: _Z3foov
-
-# BAD-STYLE: warning: Unsupported demangling style.
-# BAD-STYLE: _Z3fooi
-# BAD-STYLE: _Z3foov
Modified: llvm/trunk/tools/llvm-objdump/COFFDump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/COFFDump.cpp?rev=340221&r1=340220&r2=340221&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/COFFDump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/COFFDump.cpp Mon Aug 20 15:18:21 2018
@@ -16,6 +16,7 @@
//===----------------------------------------------------------------------===//
#include "llvm-objdump.h"
+#include "llvm/Demangle/Demangle.h"
#include "llvm/Object/COFF.h"
#include "llvm/Object/COFFImportFile.h"
#include "llvm/Object/ObjectFile.h"
@@ -646,10 +647,24 @@ void llvm::printCOFFSymbolTable(const CO
<< "(sec " << format("%2d", int(Symbol->getSectionNumber())) << ")"
<< "(fl 0x00)" // Flag bits, which COFF doesn't have.
<< "(ty " << format("%3x", unsigned(Symbol->getType())) << ")"
- << "(scl " << format("%3x", unsigned(Symbol->getStorageClass())) << ") "
+ << "(scl " << format("%3x", unsigned(Symbol->getStorageClass()))
+ << ") "
<< "(nx " << unsigned(Symbol->getNumberOfAuxSymbols()) << ") "
<< "0x" << format("%08x", unsigned(Symbol->getValue())) << " "
- << Name << "\n";
+ << Name;
+ if (Demangle && Name.startswith("?")) {
+ char *DemangledSymbol = nullptr;
+ size_t Size = 0;
+ int Status = -1;
+ DemangledSymbol =
+ microsoftDemangle(Name.data(), DemangledSymbol, &Size, &Status);
+
+ if (Status == 0 && DemangledSymbol) {
+ outs() << " (" << StringRef(DemangledSymbol) << ")";
+ std::free(DemangledSymbol);
+ }
+ }
+ outs() << "\n";
for (unsigned AI = 0, AE = Symbol->getNumberOfAuxSymbols(); AI < AE; ++AI, ++SI) {
if (Symbol->isSectionDefinition()) {
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=340221&r1=340220&r2=340221&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Mon Aug 20 15:18:21 2018
@@ -92,12 +92,11 @@ static cl::alias
DisassembleAlld("D", cl::desc("Alias for --disassemble-all"),
cl::aliasopt(DisassembleAll));
-cl::opt<std::string> llvm::Demangle("demangle",
- cl::desc("Demangle symbols names"),
- cl::ValueOptional, cl::init("none"));
+cl::opt<bool> llvm::Demangle("demangle", cl::desc("Demangle symbols names"),
+ cl::init(false));
static cl::alias DemangleShort("C", cl::desc("Alias for --demangle"),
- cl::aliasopt(Demangle));
+ cl::aliasopt(llvm::Demangle));
static cl::list<std::string>
DisassembleFunctions("df",
@@ -1529,18 +1528,23 @@ static void DisassembleObject(const Obje
outs() << '\n' << Name << ":\n";
};
StringRef SymbolName = std::get<1>(Symbols[si]);
- if (Demangle.getValue() == "" || Demangle.getValue() == "itanium") {
+ if (Demangle) {
char *DemangledSymbol = nullptr;
size_t Size = 0;
- int Status;
- DemangledSymbol =
- itaniumDemangle(SymbolName.data(), DemangledSymbol, &Size, &Status);
- if (Status == 0)
+ int Status = -1;
+ if (SymbolName.startswith("_Z"))
+ DemangledSymbol = itaniumDemangle(SymbolName.data(), DemangledSymbol,
+ &Size, &Status);
+ else if (SymbolName.startswith("?"))
+ DemangledSymbol = microsoftDemangle(SymbolName.data(),
+ DemangledSymbol, &Size, &Status);
+
+ if (Status == 0 && DemangledSymbol)
PrintSymbol(StringRef(DemangledSymbol));
else
PrintSymbol(SymbolName);
- if (Size != 0)
+ if (DemangledSymbol)
free(DemangledSymbol);
} else
PrintSymbol(SymbolName);
@@ -2395,10 +2399,6 @@ int main(int argc, char **argv) {
if (DisassembleAll || PrintSource || PrintLines)
Disassemble = true;
- if (Demangle.getValue() != "none" && Demangle.getValue() != "" &&
- Demangle.getValue() != "itanium")
- warn("Unsupported demangling style");
-
if (!Disassemble
&& !Relocations
&& !DynamicRelocations
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.h?rev=340221&r1=340220&r2=340221&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.h (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.h Mon Aug 20 15:18:21 2018
@@ -31,10 +31,10 @@ namespace object {
extern cl::opt<std::string> TripleName;
extern cl::opt<std::string> ArchName;
extern cl::opt<std::string> MCPU;
-extern cl::opt<std::string> Demangle;
extern cl::list<std::string> MAttrs;
extern cl::list<std::string> FilterSections;
extern cl::opt<bool> AllHeaders;
+extern cl::opt<bool> Demangle;
extern cl::opt<bool> Disassemble;
extern cl::opt<bool> DisassembleAll;
extern cl::opt<bool> NoShowRawInsn;
More information about the llvm-commits
mailing list