[PATCH] D49043: [llvm-objdump] Add -demangle (-C) option
Paul Semel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 6 14:01:25 PDT 2018
paulsemel created this revision.
paulsemel added reviewers: echristo, jhenderson.
Repository:
rL LLVM
https://reviews.llvm.org/D49043
Files:
test/tools/llvm-objdump/Inputs/mangled.x86_64
test/tools/llvm-objdump/disassemble-demangle.test
tools/llvm-objdump/llvm-objdump.cpp
tools/llvm-objdump/llvm-objdump.h
Index: tools/llvm-objdump/llvm-objdump.h
===================================================================
--- tools/llvm-objdump/llvm-objdump.h
+++ tools/llvm-objdump/llvm-objdump.h
@@ -35,6 +35,7 @@
extern cl::opt<bool> AllHeaders;
extern cl::opt<bool> Disassemble;
extern cl::opt<bool> DisassembleAll;
+extern cl::opt<bool> Demangle;
extern cl::opt<bool> NoShowRawInsn;
extern cl::opt<bool> NoLeadingAddr;
extern cl::opt<bool> PrivateHeaders;
Index: tools/llvm-objdump/llvm-objdump.cpp
===================================================================
--- tools/llvm-objdump/llvm-objdump.cpp
+++ tools/llvm-objdump/llvm-objdump.cpp
@@ -25,6 +25,7 @@
#include "llvm/CodeGen/FaultMaps.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/Symbolize/Symbolize.h"
+#include "llvm/Demangle/Demangle.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
@@ -90,6 +91,10 @@
DisassembleAlld("D", cl::desc("Alias for --disassemble-all"),
cl::aliasopt(DisassembleAll));
+cl::opt<bool> llvm::Demangle("demangle", cl::desc("Demangle symbols names"));
+static cl::alias DemangleShort("C", cl::desc("Alias for --demangle"),
+ cl::aliasopt(Demangle));
+
static cl::list<std::string>
DisassembleFunctions("df",
cl::CommaSeparated,
@@ -1511,7 +1516,22 @@
}
}
- outs() << '\n' << std::get<1>(Symbols[si]) << ":\n";
+ StringRef SymbolName = std::get<1>(Symbols[si]);
+ if (Demangle) {
+ char *DemangledSymbol = nullptr;
+ size_t Size = 0;
+ int Status;
+ DemangledSymbol =
+ itaniumDemangle(SymbolName.data(), DemangledSymbol, &Size, &Status);
+ if (Status == 0) // Success
+ outs() << '\n' << DemangledSymbol << ":\n";
+ else
+ outs() << '\n' << SymbolName << ":\n";
+
+ if (Size != 0)
+ free(DemangledSymbol);
+ } else
+ outs() << '\n' << SymbolName << ":\n";
// Don't print raw contents of a virtual section. A virtual section
// doesn't have any contents in the file.
Index: test/tools/llvm-objdump/disassemble-demangle.test
===================================================================
--- /dev/null
+++ test/tools/llvm-objdump/disassemble-demangle.test
@@ -0,0 +1,5 @@
+# RUN: llvm-objdump -d -C %p/Inputs/mangled.x86_64 | FileCheck %s
+
+# We just want to check that the symbols are demangled
+# CHECK: foo()
+# CHECK: foo(int)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49043.154452.patch
Type: text/x-patch
Size: 2543 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180706/ff76809f/attachment.bin>
More information about the llvm-commits
mailing list