|
13 | 13 | #include "MachODump.h" |
14 | 14 |
|
15 | 15 | #include "ObjdumpOptID.h" |
| 16 | +#include "SourcePrinter.h" |
16 | 17 | #include "llvm-objdump.h" |
17 | 18 | #include "llvm/ADT/STLExtras.h" |
18 | 19 | #include "llvm/ADT/StringExtras.h" |
@@ -7411,18 +7412,28 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF, |
7411 | 7412 | std::unique_ptr<DIContext> diContext; |
7412 | 7413 | std::unique_ptr<Binary> DSYMBinary; |
7413 | 7414 | std::unique_ptr<MemoryBuffer> DSYMBuf; |
7414 | | - if (UseDbg) { |
7415 | | - // If separate DSym file path was specified, parse it as a macho file, |
7416 | | - // get the sections and supply it to the section name parsing machinery. |
7417 | | - if (const ObjectFile *DbgObj = |
7418 | | - getMachODSymObject(MachOOF, Filename, DSYMBinary, DSYMBuf)) { |
| 7415 | + const ObjectFile *DbgObj = MachOOF; |
| 7416 | + if (UseDbg || PrintSource || PrintLines) { |
| 7417 | + // Look for debug info in external dSYM file or embedded in the object. |
| 7418 | + // getMachODSymObject returns MachOOF by default if no external dSYM found. |
| 7419 | + const ObjectFile *DSym = |
| 7420 | + getMachODSymObject(MachOOF, Filename, DSYMBinary, DSYMBuf); |
| 7421 | + if (!DSym) |
| 7422 | + return; |
| 7423 | + DbgObj = DSym; |
| 7424 | + if (UseDbg || PrintLines) { |
7419 | 7425 | // Setup the DIContext |
7420 | 7426 | diContext = DWARFContext::create(*DbgObj); |
7421 | | - } else { |
7422 | | - return; |
7423 | 7427 | } |
7424 | 7428 | } |
7425 | 7429 |
|
| 7430 | + std::optional<SourcePrinter> SP; |
| 7431 | + std::optional<LiveVariablePrinter> LVP; |
| 7432 | + if (PrintSource || PrintLines) { |
| 7433 | + SP.emplace(DbgObj, TheTarget->getName()); |
| 7434 | + LVP.emplace(*MRI.get(), *STI.get()); |
| 7435 | + } |
| 7436 | + |
7426 | 7437 | if (FilterSections.empty()) |
7427 | 7438 | outs() << "(" << DisSegName << "," << DisSectName << ") section\n"; |
7428 | 7439 |
|
@@ -7601,6 +7612,12 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF, |
7601 | 7612 | outs() << SymName << ":\n"; |
7602 | 7613 |
|
7603 | 7614 | uint64_t PC = SectAddress + Index; |
| 7615 | + |
| 7616 | + if (PrintSource || PrintLines) { |
| 7617 | + formatted_raw_ostream FOS(outs()); |
| 7618 | + SP->printSourceLine(FOS, {PC, SectIdx}, Filename, *LVP); |
| 7619 | + } |
| 7620 | + |
7604 | 7621 | if (LeadingAddr) { |
7605 | 7622 | if (FullLeadingAddr) { |
7606 | 7623 | if (MachOOF->is64Bit()) |
@@ -7692,6 +7709,11 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF, |
7692 | 7709 |
|
7693 | 7710 | uint64_t PC = SectAddress + Index; |
7694 | 7711 |
|
| 7712 | + if (PrintSource || PrintLines) { |
| 7713 | + formatted_raw_ostream FOS(outs()); |
| 7714 | + SP->printSourceLine(FOS, {PC, SectIdx}, Filename, *LVP); |
| 7715 | + } |
| 7716 | + |
7695 | 7717 | if (DumpAndSkipDataInCode(PC, Bytes.data() + Index, Dices, InstSize)) |
7696 | 7718 | continue; |
7697 | 7719 |
|
|
0 commit comments