1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[llvm-objdump] Add ability to demangle COFF symbols.

llvm-svn: 340221
This commit is contained in:
Zachary Turner 2018-08-20 22:18:21 +00:00
parent 51c8c71034
commit 0e0b1410ae
4 changed files with 33 additions and 24 deletions

View File

@ -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

View File

@ -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 COFFObjectFile *coff) {
<< "(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()) {

View File

@ -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 ObjectFile *Obj, bool InlineRelocs) {
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

View File

@ -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;