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) 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 AllHeaders; extern cl::opt Disassemble; extern cl::opt DisassembleAll; +extern cl::opt Demangle; extern cl::opt NoShowRawInsn; extern cl::opt NoLeadingAddr; extern cl::opt 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 llvm::Demangle("demangle", cl::desc("Demangle symbols names")); +static cl::alias DemangleShort("C", cl::desc("Alias for --demangle"), + cl::aliasopt(Demangle)); + static cl::list 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.