--- /dev/null
+# 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 %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:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .text1
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Address: 0x1000
+ AddressAlign: 0x0000000000000010
+ Content: "0000000000000000"
+ - Name: .text2
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Address: 0x1010
+ AddressAlign: 0x0000000000000010
+ Content: "0000000000000000"
+Symbols:
+ Local:
+ - Name: _Z3fooi
+ Type: STT_FUNC
+ Section: .text1
+ Value: 0x1000
+ - Name: _Z3foov
+ Type: STT_FUNC
+ Section: .text2
+ Value: 0x1010
+
+# We just want to check that the symbols are demangled
+# DEMANGLE: foo(int)
+# DEMANGLE: foo()
+
+# NO-DEMANGLE: _Z3fooi
+# NO-DEMANGLE: _Z3foov
+
+# BAD-STYLE: warning: Unsupported demangling style.
+# BAD-STYLE: _Z3fooi
+# BAD-STYLE: _Z3foov
#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"
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"));
+
+static cl::alias DemangleShort("C", cl::desc("Alias for --demangle"),
+ cl::aliasopt(Demangle));
+
static cl::list<std::string>
DisassembleFunctions("df",
cl::CommaSeparated,
exit(1);
}
+void llvm::warn(StringRef Message) {
+ errs() << ToolName << ": warning: " << Message << ".\n";
+ errs().flush();
+}
+
LLVM_ATTRIBUTE_NORETURN void llvm::report_error(StringRef File,
Twine Message) {
errs() << ToolName << ": '" << File << "': " << Message << ".\n";
}
}
- outs() << '\n' << std::get<1>(Symbols[si]) << ":\n";
+ auto PrintSymbol = [](StringRef Name) {
+ outs() << '\n' << Name << ":\n";
+ };
+ StringRef SymbolName = std::get<1>(Symbols[si]);
+ if (Demangle.getValue() == "" || Demangle.getValue() == "itanium") {
+ char *DemangledSymbol = nullptr;
+ size_t Size = 0;
+ int Status;
+ DemangledSymbol =
+ itaniumDemangle(SymbolName.data(), DemangledSymbol, &Size, &Status);
+ if (Status == 0)
+ PrintSymbol(StringRef(DemangledSymbol));
+ else
+ PrintSymbol(SymbolName);
+
+ if (Size != 0)
+ free(DemangledSymbol);
+ } else
+ PrintSymbol(SymbolName);
// Don't print raw contents of a virtual section. A virtual section
// doesn't have any contents in the file.
if (DisassembleAll || PrintSource || PrintLines)
Disassemble = true;
+
+ if (Demangle.getValue() != "none" && Demangle.getValue() != "" &&
+ Demangle.getValue() != "itanium")
+ warn("Unsupported demangling style");
+
if (!Disassemble
&& !Relocations
&& !DynamicRelocations
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;
void PrintSectionContents(const object::ObjectFile *o);
void PrintSymbolTable(const object::ObjectFile *o, StringRef ArchiveName,
StringRef ArchitectureName = StringRef());
+void warn(StringRef Message);
LLVM_ATTRIBUTE_NORETURN void error(Twine Message);
LLVM_ATTRIBUTE_NORETURN void report_error(StringRef File, Twine Message);
LLVM_ATTRIBUTE_NORETURN void report_error(StringRef File, std::error_code EC);