diff options
author | dim <dim@FreeBSD.org> | 2012-08-15 19:34:23 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2012-08-15 19:34:23 +0000 |
commit | 721c201bd55ffb73cb2ba8d39e0570fa38c44e15 (patch) | |
tree | eacfc83d988e4b9d11114387ae7dc41243f2a363 /tools/llvm-objdump/MachODump.cpp | |
parent | 2b2816e083a455f7a656ae88b0fd059d1688bb36 (diff) | |
download | FreeBSD-src-721c201bd55ffb73cb2ba8d39e0570fa38c44e15.zip FreeBSD-src-721c201bd55ffb73cb2ba8d39e0570fa38c44e15.tar.gz |
Vendor import of llvm trunk r161861:
http://llvm.org/svn/llvm-project/llvm/trunk@161861
Diffstat (limited to 'tools/llvm-objdump/MachODump.cpp')
-rw-r--r-- | tools/llvm-objdump/MachODump.cpp | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index 0e7f3fd..1feea42 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -44,7 +44,7 @@ using namespace object; static cl::opt<bool> CFG("cfg", cl::desc("Create a CFG for every symbol in the object file and" - "write it to a graphviz file (MachO-only)")); + " write it to a graphviz file (MachO-only)")); static cl::opt<bool> UseDbg("g", cl::desc("Print line information from debug info if available")); @@ -286,8 +286,10 @@ void llvm::DisassembleInputMachO(StringRef Filename) { // Read and register the symbol table data. InMemoryStruct<macho::SymtabLoadCommand> SymtabLC; - MachOObj->ReadSymtabLoadCommand(*SymtabLCI, SymtabLC); - MachOObj->RegisterStringTable(*SymtabLC); + if (SymtabLCI) { + MachOObj->ReadSymtabLoadCommand(*SymtabLCI, SymtabLC); + MachOObj->RegisterStringTable(*SymtabLC); + } std::vector<SectionRef> Sections; std::vector<SymbolRef> Symbols; @@ -430,7 +432,7 @@ void llvm::DisassembleInputMachO(StringRef Filename) { // Stop disassembling either at the beginning of the next symbol or at // the end of the section. - bool containsNextSym = true; + bool containsNextSym = false; uint64_t NextSym = 0; uint64_t NextSymIdx = SymIdx+1; while (Symbols.size() > NextSymIdx) { @@ -498,6 +500,29 @@ void llvm::DisassembleInputMachO(StringRef Filename) { InstrAnalysis.get(), Start, DebugOut, FunctionMap, Functions); } } + if (!CFG && !symbolTableWorked) { + // Reading the symbol table didn't work, disassemble the whole section. + uint64_t SectAddress; + Sections[SectIdx].getAddress(SectAddress); + uint64_t SectSize; + Sections[SectIdx].getSize(SectSize); + uint64_t InstSize; + for (uint64_t Index = 0; Index < SectSize; Index += InstSize) { + MCInst Inst; + + if (DisAsm->getInstruction(Inst, InstSize, memoryObject, Index, + DebugOut, nulls())) { + outs() << format("%8" PRIx64 ":\t", SectAddress + Index); + DumpBytes(StringRef(Bytes.data() + Index, InstSize)); + IP->printInst(&Inst, outs(), ""); + outs() << "\n"; + } else { + errs() << "llvm-objdump: warning: invalid instruction encoding\n"; + if (InstSize == 0) + InstSize = 1; // skip illegible bytes + } + } + } if (CFG) { if (!symbolTableWorked) { |