diff options
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index a06e644..0c1bb0b 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -1287,7 +1287,8 @@ fetchBinaryByBuildID(const ObjectFile &Obj) { } static void disassembleObject(const Target *TheTarget, ObjectFile &Obj, - MCContext &Ctx, MCDisassembler *PrimaryDisAsm, + const ObjectFile &DbgObj, MCContext &Ctx, + MCDisassembler *PrimaryDisAsm, MCDisassembler *SecondaryDisAsm, const MCInstrAnalysis *MIA, MCInstPrinter *IP, const MCSubtargetInfo *PrimarySTI, @@ -1412,7 +1413,7 @@ static void disassembleObject(const Target *TheTarget, ObjectFile &Obj, LiveVariablePrinter LVP(*Ctx.getRegisterInfo(), *STI); if (DbgVariables != DVDisabled) { - DICtx = DWARFContext::create(Obj); + DICtx = DWARFContext::create(DbgObj); for (const std::unique_ptr<DWARFUnit> &CU : DICtx->compile_units()) LVP.addCompileUnit(CU->getUnitDIE(false)); } @@ -2071,13 +2072,14 @@ static void disassembleObject(ObjectFile *Obj, bool InlineRelocs) { IP->setMCInstrAnalysis(MIA.get()); PrettyPrinter &PIP = selectPrettyPrinter(Triple(TripleName)); - ObjectFile *DbgObj = Obj; + + const ObjectFile *DbgObj = Obj; OwningBinary<Binary> DebugBinary; - if (!Obj->hasDebugInfo()) { + if (!DbgObj->hasDebugInfo()) { if (Optional<OwningBinary<Binary>> DebugBinaryOpt = fetchBinaryByBuildID(*Obj)) { - if (ObjectFile *FetchedObj = - dyn_cast<ObjectFile>(DebugBinaryOpt->getBinary())) { + if (auto *FetchedObj = + dyn_cast<const ObjectFile>(DebugBinaryOpt->getBinary())) { if (FetchedObj->hasDebugInfo()) { DebugBinary = std::move(*DebugBinaryOpt); DbgObj = FetchedObj; @@ -2085,6 +2087,18 @@ static void disassembleObject(ObjectFile *Obj, bool InlineRelocs) { } } } + + std::unique_ptr<object::Binary> DSYMBinary; + std::unique_ptr<MemoryBuffer> DSYMBuf; + if (!DbgObj->hasDebugInfo()) { + if (const MachOObjectFile *MachOOF = dyn_cast<MachOObjectFile>(&*Obj)) { + DbgObj = objdump::getMachODSymObject(MachOOF, Obj->getFileName(), + DSYMBinary, DSYMBuf); + if (!DbgObj) + return; + } + } + SourcePrinter SP(DbgObj, TheTarget->getName()); for (StringRef Opt : DisassemblerOptions) @@ -2092,9 +2106,9 @@ static void disassembleObject(ObjectFile *Obj, bool InlineRelocs) { reportError(Obj->getFileName(), "Unrecognized disassembler option: " + Opt); - disassembleObject(TheTarget, *Obj, Ctx, DisAsm.get(), SecondaryDisAsm.get(), - MIA.get(), IP.get(), STI.get(), SecondarySTI.get(), PIP, SP, - InlineRelocs); + disassembleObject(TheTarget, *Obj, *DbgObj, Ctx, DisAsm.get(), + SecondaryDisAsm.get(), MIA.get(), IP.get(), STI.get(), + SecondarySTI.get(), PIP, SP, InlineRelocs); } void objdump::printRelocations(const ObjectFile *Obj) { |