|
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" |
@@ -7415,18 +7416,28 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF, |
7415 | 7416 | std::unique_ptr<DIContext> diContext; |
7416 | 7417 | std::unique_ptr<Binary> DSYMBinary; |
7417 | 7418 | std::unique_ptr<MemoryBuffer> DSYMBuf; |
7418 | | - if (UseDbg) { |
7419 | | - // If separate DSym file path was specified, parse it as a macho file, |
7420 | | - // get the sections and supply it to the section name parsing machinery. |
7421 | | - if (const ObjectFile *DbgObj = |
7422 | | - getMachODSymObject(MachOOF, Filename, DSYMBinary, DSYMBuf)) { |
| 7419 | + const ObjectFile *DbgObj = MachOOF; |
| 7420 | + if (UseDbg || PrintSource || PrintLines) { |
| 7421 | + // Look for debug info in external dSYM file or embedded in the object. |
| 7422 | + // getMachODSymObject returns MachOOF by default if no external dSYM found. |
| 7423 | + const ObjectFile *DSym = |
| 7424 | + getMachODSymObject(MachOOF, Filename, DSYMBinary, DSYMBuf); |
| 7425 | + if (!DSym) |
| 7426 | + return; |
| 7427 | + DbgObj = DSym; |
| 7428 | + if (UseDbg || PrintLines) { |
7423 | 7429 | // Setup the DIContext |
7424 | 7430 | diContext = DWARFContext::create(*DbgObj); |
7425 | | - } else { |
7426 | | - return; |
7427 | 7431 | } |
7428 | 7432 | } |
7429 | 7433 |
|
| 7434 | + std::optional<SourcePrinter> SP; |
| 7435 | + std::optional<LiveElementPrinter> LEP; |
| 7436 | + if (PrintSource || PrintLines) { |
| 7437 | + SP.emplace(DbgObj, TheTarget->getName()); |
| 7438 | + LEP.emplace(*MRI, *STI); |
| 7439 | + } |
| 7440 | + |
7430 | 7441 | if (FilterSections.empty()) |
7431 | 7442 | outs() << "(" << DisSegName << "," << DisSectName << ") section\n"; |
7432 | 7443 |
|
@@ -7605,6 +7616,12 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF, |
7605 | 7616 | outs() << SymName << ":\n"; |
7606 | 7617 |
|
7607 | 7618 | uint64_t PC = SectAddress + Index; |
| 7619 | + |
| 7620 | + if (PrintSource || PrintLines) { |
| 7621 | + formatted_raw_ostream FOS(outs()); |
| 7622 | + SP->printSourceLine(FOS, {PC, SectIdx}, Filename, *LEP); |
| 7623 | + } |
| 7624 | + |
7608 | 7625 | if (LeadingAddr) { |
7609 | 7626 | if (FullLeadingAddr) { |
7610 | 7627 | if (MachOOF->is64Bit()) |
@@ -7696,6 +7713,11 @@ static void DisassembleMachO(StringRef Filename, MachOObjectFile *MachOOF, |
7696 | 7713 |
|
7697 | 7714 | uint64_t PC = SectAddress + Index; |
7698 | 7715 |
|
| 7716 | + if (PrintSource || PrintLines) { |
| 7717 | + formatted_raw_ostream FOS(outs()); |
| 7718 | + SP->printSourceLine(FOS, {PC, SectIdx}, Filename, *LEP); |
| 7719 | + } |
| 7720 | + |
7699 | 7721 | if (DumpAndSkipDataInCode(PC, Bytes.data() + Index, Dices, InstSize)) |
7700 | 7722 | continue; |
7701 | 7723 |
|
|
0 commit comments