Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the dumping of .dwo files contents to show up when dumping an e… #66726

Merged
merged 5 commits into from Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions llvm/include/llvm/DebugInfo/DIContext.h
Expand Up @@ -204,6 +204,7 @@ struct DIDumpOptions {
bool Verbose = false;
bool DisplayRawContents = false;
bool IsEH = false;
bool DumpNonSkeleton = false;
std::function<llvm::StringRef(uint64_t DwarfRegNum, bool IsEH)>
GetNameForDWARFReg;

Expand Down
8 changes: 7 additions & 1 deletion llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h
Expand Up @@ -372,7 +372,13 @@ class DWARFContext : public DIContext {
/// given address where applicable.
/// TODO: change input parameter from "uint64_t Address"
/// into "SectionedAddress Address"
DIEsForAddress getDIEsForAddress(uint64_t Address);
/// \param[in] CheckDWO If this is false then only search for address matches
/// in the current context's DIEs. If this is true, then each
/// DWARFUnit that has a DWO file will have the debug info in the
/// DWO file searched as well. This allows for lookups to succeed
/// by searching the split DWARF debug info when using the main
/// executable's debug info.
DIEsForAddress getDIEsForAddress(uint64_t Address, bool CheckDWO = false);

DILineInfo getLineInfoForAddress(
object::SectionedAddress Address,
Expand Down
10 changes: 8 additions & 2 deletions llvm/lib/DebugInfo/DWARF/DWARFCompileUnit.cpp
Expand Up @@ -35,10 +35,16 @@ void DWARFCompileUnit::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
OS << " (next unit at " << format("0x%08" PRIx64, getNextUnitOffset())
<< ")\n";

if (DWARFDie CUDie = getUnitDIE(false))
if (DWARFDie CUDie = getUnitDIE(false)) {
CUDie.dump(OS, 0, DumpOpts);
else
if (DumpOpts.DumpNonSkeleton) {
DWARFDie NonSkeletonCUDie = getNonSkeletonUnitDIE(false);
if (NonSkeletonCUDie && CUDie != NonSkeletonCUDie)
NonSkeletonCUDie.dump(OS, 0, DumpOpts);
}
} else {
OS << "<compile unit can't be parsed!>\n\n";
}
}

// VTable anchor.
Expand Down
39 changes: 35 additions & 4 deletions llvm/lib/DebugInfo/DWARF/DWARFContext.cpp
Expand Up @@ -1024,9 +1024,17 @@ void DWARFContext::dump(
auto dumpDebugInfo = [&](const char *Name, unit_iterator_range Units) {
OS << '\n' << Name << " contents:\n";
if (auto DumpOffset = DumpOffsets[DIDT_ID_DebugInfo])
for (const auto &U : Units)
for (const auto &U : Units) {
U->getDIEForOffset(*DumpOffset)
.dump(OS, 0, DumpOpts.noImplicitRecursion());
DWARFDie CUDie = U->getUnitDIE(false);
DWARFDie CUNonSkeletonDie = U->getNonSkeletonUnitDIE(false);
if (CUNonSkeletonDie && CUDie != CUNonSkeletonDie) {
CUNonSkeletonDie.getDwarfUnit()
->getDIEForOffset(*DumpOffset)
.dump(OS, 0, DumpOpts.noImplicitRecursion());
}
}
else
for (const auto &U : Units)
U->dump(OS, DumpOpts);
Expand Down Expand Up @@ -1537,15 +1545,38 @@ DWARFCompileUnit *DWARFContext::getCompileUnitForDataAddress(uint64_t Address) {
return nullptr;
}

DWARFContext::DIEsForAddress DWARFContext::getDIEsForAddress(uint64_t Address) {
DWARFContext::DIEsForAddress DWARFContext::getDIEsForAddress(uint64_t Address,
bool CheckDWO) {
DIEsForAddress Result;

DWARFCompileUnit *CU = getCompileUnitForCodeAddress(Address);
if (!CU)
return Result;

Result.CompileUnit = CU;
Result.FunctionDIE = CU->getSubroutineForAddress(Address);
if (CheckDWO) {
// We were asked to check the DWO file and this debug information is more
// complete that any information in the skeleton compile unit, so search the
// DWO first to see if we have a match.
DWARFDie CUDie = CU->getUnitDIE(false);
DWARFDie CUDwoDie = CU->getNonSkeletonUnitDIE(false);
if (CheckDWO && CUDwoDie && CUDie != CUDwoDie) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to CheckDWO again here, as we're inside an if (CheckDWO) at this point.

// We have a DWO file, lets search it.
DWARFCompileUnit *CUDwo =
dyn_cast_or_null<DWARFCompileUnit>(CUDwoDie.getDwarfUnit());
if (CUDwo) {
Result.FunctionDIE = CUDwo->getSubroutineForAddress(Address);
if (Result.FunctionDIE)
Result.CompileUnit = CUDwo;
}
}
}

// Search the normal DWARF if we didn't find a match in the DWO file or if
// we didn't check the DWO file above.
if (!Result) {
Result.CompileUnit = CU;
Result.FunctionDIE = CU->getSubroutineForAddress(Address);
}

std::vector<DWARFDie> Worklist;
Worklist.push_back(Result.FunctionDIE);
Expand Down
37 changes: 37 additions & 0 deletions llvm/test/tools/llvm-dwarfdump/Inputs/dump_dwo.dwo.yaml
@@ -0,0 +1,37 @@
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
SectionHeaderStringTable: .strtab
Sections:
- Name: .debug_str_offsets.dwo
Type: SHT_PROGBITS
Flags: [ SHF_EXCLUDE ]
AddressAlign: 0x1
Content: 2C0000000500000000000000080000000C00000010000000150000001A0000001F000000240000005400000061000000
- Name: .debug_str.dwo
Type: SHT_PROGBITS
Flags: [ SHF_EXCLUDE, SHF_MERGE, SHF_STRINGS ]
AddressAlign: 0x1
EntSize: 0x1
Content: 5F5A33666F6F7600666F6F00696E74006D61696E006172676300617267760063686172004170706C6520636C616E672076657273696F6E2031352E302E302028636C616E672D313530302E312E302E322E35290064756D705F64776F2E637070002E2F64756D705F64776F2E64776F00
- Name: .debug_info.dwo
Type: SHT_PROGBITS
Flags: [ SHF_EXCLUDE ]
AddressAlign: 0x1
Content: 64000000050005080000000036C1C3A75DD36D37010704000809020008000000015600010002500000000301230000000156030006500000000402917804000650000000040291700500065400000000050205040659000000065E00000007630000000506060100
- Name: .debug_abbrev.dwo
Type: SHT_PROGBITS
Flags: [ SHF_EXCLUDE ]
AddressAlign: 0x1
Content: 01110125251305032576250000022E00111B120640186E2503253A0B3B0B49133F190000032E01111B1206401803253A0B3B0B49133F190000040500021803253A0B3B0B4913000005240003253E0B0B0B0000060F00491300000726004913000000
- Type: SectionHeaderTable
Sections:
- Name: .strtab
- Name: .debug_str_offsets.dwo
- Name: .debug_str.dwo
- Name: .debug_info.dwo
- Name: .debug_abbrev.dwo
...
251 changes: 251 additions & 0 deletions llvm/test/tools/llvm-dwarfdump/Inputs/dump_dwo.o.yaml
@@ -0,0 +1,251 @@
--- !ELF
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_X86_64
SectionHeaderStringTable: .strtab
Sections:
- Name: .text
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
AddressAlign: 0x10
Content: 554889E531C05DC30F1F840000000000554889E54883EC10C745FC00000000897DF8488975F0E80000000031C04883C4105DC3
- Name: .debug_abbrev
Type: SHT_PROGBITS
AddressAlign: 0x1
Content: 014A00101772171B25B442197625111B12067317000000
- Name: .debug_info
Type: SHT_PROGBITS
AddressAlign: 0x1
Content: 24000000050004080000000036C1C3A75DD36D370100000000000000000001003300000000000000
- Name: .debug_str_offsets
Type: SHT_PROGBITS
AddressAlign: 0x1
Content: 0C000000050000000000000000000000
- Name: .debug_gnu_pubnames
Type: SHT_PROGBITS
AddressAlign: 0x1
Content: 21000000020000000000280000001A00000030666F6F002A000000306D61696E0000000000
- Name: .debug_gnu_pubtypes
Type: SHT_PROGBITS
AddressAlign: 0x1
Content: '21000000020000000000280000005000000090696E74006300000090636861720000000000'
- Name: .comment
Type: SHT_PROGBITS
Flags: [ SHF_MERGE, SHF_STRINGS ]
AddressAlign: 0x1
EntSize: 0x1
Content: 004170706C6520636C616E672076657273696F6E2031352E302E302028636C616E672D313530302E312E302E322E352900
- Name: .note.GNU-stack
Type: SHT_PROGBITS
AddressAlign: 0x1
- Name: .eh_frame
Type: SHT_X86_64_UNWIND
Flags: [ SHF_ALLOC ]
AddressAlign: 0x8
Content: 1400000000000000017A5200017810011B0C0708900100001C0000001C000000000000000800000000410E108602430D06430C07080000001C0000003C000000000000002300000000410E108602430D065E0C0708000000
- Name: .debug_line
Type: SHT_PROGBITS
AddressAlign: 0x1
Content: 5F0000000500080037000000010101FB0E0D00010101010000000100000101011F010000000003011F020F051E0100000000004000920BB47E0DDA24E8521F209EDB37040000090200000000000000001305020A4B0500BD05030A0859590208000101
- Name: .debug_line_str
Type: SHT_PROGBITS
Flags: [ SHF_MERGE, SHF_STRINGS ]
AddressAlign: 0x1
EntSize: 0x1
Content: 2E2F0064756D705F64776F2E63707000
- Name: .rela.text
Type: SHT_RELA
Flags: [ SHF_INFO_LINK ]
Link: .symtab
AddressAlign: 0x8
Info: .text
Relocations:
- Offset: 0x27
Symbol: _Z3foov
Type: R_X86_64_PLT32
Addend: -4
- Name: .rela.debug_info
Type: SHT_RELA
Flags: [ SHF_INFO_LINK ]
Link: .symtab
AddressAlign: 0x8
Info: .debug_info
Relocations:
- Offset: 0x8
Symbol: .debug_abbrev
Type: R_X86_64_32
- Offset: 0x15
Symbol: .debug_line
Type: R_X86_64_32
- Offset: 0x19
Symbol: .debug_str_offsets
Type: R_X86_64_32
Addend: 8
- Offset: 0x24
Symbol: .debug_addr
Type: R_X86_64_32
Addend: 8
- Name: .rela.debug_str_offsets
Type: SHT_RELA
Flags: [ SHF_INFO_LINK ]
Link: .symtab
AddressAlign: 0x8
Info: .debug_str_offsets
Relocations:
- Offset: 0x8
Symbol: .debug_str
Type: R_X86_64_32
- Offset: 0xC
Symbol: .debug_str
Type: R_X86_64_32
Addend: 3
- Name: .rela.debug_addr
Type: SHT_RELA
Flags: [ SHF_INFO_LINK ]
Link: .symtab
AddressAlign: 0x8
Info: .debug_addr
Relocations:
- Offset: 0x8
Symbol: .text
Type: R_X86_64_64
- Offset: 0x10
Symbol: .text
Type: R_X86_64_64
Addend: 16
- Name: .rela.debug_gnu_pubnames
Type: SHT_RELA
Flags: [ SHF_INFO_LINK ]
Link: .symtab
AddressAlign: 0x8
Info: .debug_gnu_pubnames
Relocations:
- Offset: 0x6
Symbol: .debug_info
Type: R_X86_64_32
- Name: .rela.debug_gnu_pubtypes
Type: SHT_RELA
Flags: [ SHF_INFO_LINK ]
Link: .symtab
AddressAlign: 0x8
Info: .debug_gnu_pubtypes
Relocations:
- Offset: 0x6
Symbol: .debug_info
Type: R_X86_64_32
- Name: .rela.eh_frame
Type: SHT_RELA
Flags: [ SHF_INFO_LINK ]
Link: .symtab
AddressAlign: 0x8
Info: .eh_frame
Relocations:
- Offset: 0x20
Symbol: .text
Type: R_X86_64_PC32
- Offset: 0x40
Symbol: .text
Type: R_X86_64_PC32
Addend: 16
- Name: .rela.debug_line
Type: SHT_RELA
Flags: [ SHF_INFO_LINK ]
Link: .symtab
AddressAlign: 0x8
Info: .debug_line
Relocations:
- Offset: 0x22
Symbol: .debug_line_str
Type: R_X86_64_32
- Offset: 0x2E
Symbol: .debug_line_str
Type: R_X86_64_32
Addend: 3
- Offset: 0x48
Symbol: .text
Type: R_X86_64_64
- Name: .llvm_addrsig
Type: SHT_LLVM_ADDRSIG
Flags: [ SHF_EXCLUDE ]
Link: .symtab
AddressAlign: 0x1
Symbols: [ _Z3foov ]
- Type: SectionHeaderTable
Sections:
- Name: .strtab
- Name: .text
- Name: .rela.text
- Name: .debug_abbrev
- Name: .debug_info
- Name: .rela.debug_info
- Name: .debug_str_offsets
- Name: .rela.debug_str_offsets
- Name: .debug_str
- Name: .debug_addr
- Name: .rela.debug_addr
- Name: .debug_gnu_pubnames
- Name: .rela.debug_gnu_pubnames
- Name: .debug_gnu_pubtypes
- Name: .rela.debug_gnu_pubtypes
- Name: .comment
- Name: .note.GNU-stack
- Name: .eh_frame
- Name: .rela.eh_frame
- Name: .debug_line
- Name: .rela.debug_line
- Name: .debug_line_str
- Name: .llvm_addrsig
- Name: .symtab
Symbols:
- Name: dump_dwo.cpp
Type: STT_FILE
Index: SHN_ABS
- Name: .text
Type: STT_SECTION
Section: .text
- Name: .debug_abbrev
Type: STT_SECTION
Section: .debug_abbrev
- Name: .debug_info
Type: STT_SECTION
Section: .debug_info
- Name: .debug_str_offsets
Type: STT_SECTION
Section: .debug_str_offsets
- Name: .debug_str
Type: STT_SECTION
Section: .debug_str
- Name: .debug_addr
Type: STT_SECTION
Section: .debug_addr
- Name: .debug_line
Type: STT_SECTION
Section: .debug_line
- Name: .debug_line_str
Type: STT_SECTION
Section: .debug_line_str
- Name: _Z3foov
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
Size: 0x8
- Name: main
Type: STT_FUNC
Section: .text
Binding: STB_GLOBAL
Value: 0x10
Size: 0x23
DWARF:
debug_str:
- './'
- './dump_dwo.dwo'
debug_addr:
- Length: 0x14
Version: 0x5
AddressSize: 0x8
Entries:
- {}
- Address: 0x10
...