diff options
author | Jim Radford <jradford@apple.com> | 2022-10-04 10:40:35 -0700 |
---|---|---|
committer | Francis Visoiu Mistrih <francisvm@yahoo.com> | 2022-10-04 11:15:51 -0700 |
commit | ffecb643ee2c49e55e0689339b6d5921b5e6ff8b (patch) | |
tree | 8010bc8e0443b058308da83cd5d996dead7542a8 /llvm/tools/llvm-objdump/llvm-objdump.cpp | |
parent | 02fd0e5de4c10b1db16dafc4a442ee8fc12a2098 (diff) | |
download | llvm-ffecb643ee2c49e55e0689339b6d5921b5e6ff8b.zip llvm-ffecb643ee2c49e55e0689339b6d5921b5e6ff8b.tar.gz llvm-ffecb643ee2c49e55e0689339b6d5921b5e6ff8b.tar.bz2 |
[objdump] Support finding --source via --dsym files
Add support for auto-detecting or specifying dSYM files/directories to
allow interleaving source with disassembly.
Differential Revision: https://reviews.llvm.org/D135117
Patch by Jim Radford.
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) { |