From badd100c260da2cb4ec6f82e1c68c7e203082511 Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Fri, 18 May 2012 00:13:56 +0000 Subject: Fixed a bug in llvm-objdump when disassembling using -macho option for a binary containing no symbols. Fixed the crash and fixed it not disassembling anything. llvm-svn: 157031 --- llvm/tools/llvm-objdump/MachODump.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'llvm/tools/llvm-objdump/MachODump.cpp') diff --git a/llvm/tools/llvm-objdump/MachODump.cpp b/llvm/tools/llvm-objdump/MachODump.cpp index 60c33f27892..5e175a004d4 100644 --- a/llvm/tools/llvm-objdump/MachODump.cpp +++ b/llvm/tools/llvm-objdump/MachODump.cpp @@ -286,8 +286,10 @@ void llvm::DisassembleInputMachO(StringRef Filename) { // Read and register the symbol table data. InMemoryStruct SymtabLC; - MachOObj->ReadSymtabLoadCommand(*SymtabLCI, SymtabLC); - MachOObj->RegisterStringTable(*SymtabLC); + if (SymtabLCI) { + MachOObj->ReadSymtabLoadCommand(*SymtabLCI, SymtabLC); + MachOObj->RegisterStringTable(*SymtabLC); + } std::vector Sections; std::vector Symbols; @@ -498,6 +500,31 @@ 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) { -- cgit v1.2.3