Skip to content

Commit 4618ef8

Browse files
authored
Allow the dumping of .dwo files contents to show up when dumping an executable with split DWARF. (#66726)
Allow the dumping of .dwo files contents to show up when dumping an executable with split DWARF. Currently if you run llvm-dwarfdump on a binary that has skeleton compile units, you only see the skeleton compile units. Since the main binary has the linked addresses it would be nice to be able to dump DWARF from the .dwo files and how the resolved addresses instead of showing the address index and "<unresolved>" in the output. This patch adds an option that can be specified to dump the non skeleton DIEs named --dwo. Added the ability to use the following options with split dwarf as well: --name <name> --lookup <addr> --debug-info <die-offset>
1 parent e27561f commit 4618ef8

File tree

8 files changed

+512
-11
lines changed

8 files changed

+512
-11
lines changed

llvm/include/llvm/DebugInfo/DIContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ struct DIDumpOptions {
204204
bool Verbose = false;
205205
bool DisplayRawContents = false;
206206
bool IsEH = false;
207+
bool DumpNonSkeleton = false;
207208
std::function<llvm::StringRef(uint64_t DwarfRegNum, bool IsEH)>
208209
GetNameForDWARFReg;
209210

llvm/include/llvm/DebugInfo/DWARF/DWARFContext.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,13 @@ class DWARFContext : public DIContext {
372372
/// given address where applicable.
373373
/// TODO: change input parameter from "uint64_t Address"
374374
/// into "SectionedAddress Address"
375-
DIEsForAddress getDIEsForAddress(uint64_t Address);
375+
/// \param[in] CheckDWO If this is false then only search for address matches
376+
/// in the current context's DIEs. If this is true, then each
377+
/// DWARFUnit that has a DWO file will have the debug info in the
378+
/// DWO file searched as well. This allows for lookups to succeed
379+
/// by searching the split DWARF debug info when using the main
380+
/// executable's debug info.
381+
DIEsForAddress getDIEsForAddress(uint64_t Address, bool CheckDWO = false);
376382

377383
DILineInfo getLineInfoForAddress(
378384
object::SectionedAddress Address,

llvm/lib/DebugInfo/DWARF/DWARFCompileUnit.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,16 @@ void DWARFCompileUnit::dump(raw_ostream &OS, DIDumpOptions DumpOpts) {
3535
OS << " (next unit at " << format("0x%08" PRIx64, getNextUnitOffset())
3636
<< ")\n";
3737

38-
if (DWARFDie CUDie = getUnitDIE(false))
38+
if (DWARFDie CUDie = getUnitDIE(false)) {
3939
CUDie.dump(OS, 0, DumpOpts);
40-
else
40+
if (DumpOpts.DumpNonSkeleton) {
41+
DWARFDie NonSkeletonCUDie = getNonSkeletonUnitDIE(false);
42+
if (NonSkeletonCUDie && CUDie != NonSkeletonCUDie)
43+
NonSkeletonCUDie.dump(OS, 0, DumpOpts);
44+
}
45+
} else {
4146
OS << "<compile unit can't be parsed!>\n\n";
47+
}
4248
}
4349

4450
// VTable anchor.

llvm/lib/DebugInfo/DWARF/DWARFContext.cpp

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,9 +1024,17 @@ void DWARFContext::dump(
10241024
auto dumpDebugInfo = [&](const char *Name, unit_iterator_range Units) {
10251025
OS << '\n' << Name << " contents:\n";
10261026
if (auto DumpOffset = DumpOffsets[DIDT_ID_DebugInfo])
1027-
for (const auto &U : Units)
1027+
for (const auto &U : Units) {
10281028
U->getDIEForOffset(*DumpOffset)
10291029
.dump(OS, 0, DumpOpts.noImplicitRecursion());
1030+
DWARFDie CUDie = U->getUnitDIE(false);
1031+
DWARFDie CUNonSkeletonDie = U->getNonSkeletonUnitDIE(false);
1032+
if (CUNonSkeletonDie && CUDie != CUNonSkeletonDie) {
1033+
CUNonSkeletonDie.getDwarfUnit()
1034+
->getDIEForOffset(*DumpOffset)
1035+
.dump(OS, 0, DumpOpts.noImplicitRecursion());
1036+
}
1037+
}
10301038
else
10311039
for (const auto &U : Units)
10321040
U->dump(OS, DumpOpts);
@@ -1537,15 +1545,38 @@ DWARFCompileUnit *DWARFContext::getCompileUnitForDataAddress(uint64_t Address) {
15371545
return nullptr;
15381546
}
15391547

1540-
DWARFContext::DIEsForAddress DWARFContext::getDIEsForAddress(uint64_t Address) {
1548+
DWARFContext::DIEsForAddress DWARFContext::getDIEsForAddress(uint64_t Address,
1549+
bool CheckDWO) {
15411550
DIEsForAddress Result;
15421551

15431552
DWARFCompileUnit *CU = getCompileUnitForCodeAddress(Address);
15441553
if (!CU)
15451554
return Result;
15461555

1547-
Result.CompileUnit = CU;
1548-
Result.FunctionDIE = CU->getSubroutineForAddress(Address);
1556+
if (CheckDWO) {
1557+
// We were asked to check the DWO file and this debug information is more
1558+
// complete that any information in the skeleton compile unit, so search the
1559+
// DWO first to see if we have a match.
1560+
DWARFDie CUDie = CU->getUnitDIE(false);
1561+
DWARFDie CUDwoDie = CU->getNonSkeletonUnitDIE(false);
1562+
if (CheckDWO && CUDwoDie && CUDie != CUDwoDie) {
1563+
// We have a DWO file, lets search it.
1564+
DWARFCompileUnit *CUDwo =
1565+
dyn_cast_or_null<DWARFCompileUnit>(CUDwoDie.getDwarfUnit());
1566+
if (CUDwo) {
1567+
Result.FunctionDIE = CUDwo->getSubroutineForAddress(Address);
1568+
if (Result.FunctionDIE)
1569+
Result.CompileUnit = CUDwo;
1570+
}
1571+
}
1572+
}
1573+
1574+
// Search the normal DWARF if we didn't find a match in the DWO file or if
1575+
// we didn't check the DWO file above.
1576+
if (!Result) {
1577+
Result.CompileUnit = CU;
1578+
Result.FunctionDIE = CU->getSubroutineForAddress(Address);
1579+
}
15491580

15501581
std::vector<DWARFDie> Worklist;
15511582
Worklist.push_back(Result.FunctionDIE);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--- !ELF
2+
FileHeader:
3+
Class: ELFCLASS64
4+
Data: ELFDATA2LSB
5+
Type: ET_REL
6+
Machine: EM_X86_64
7+
SectionHeaderStringTable: .strtab
8+
Sections:
9+
- Name: .debug_str_offsets.dwo
10+
Type: SHT_PROGBITS
11+
Flags: [ SHF_EXCLUDE ]
12+
AddressAlign: 0x1
13+
Content: 2C0000000500000000000000080000000C00000010000000150000001A0000001F000000240000005400000061000000
14+
- Name: .debug_str.dwo
15+
Type: SHT_PROGBITS
16+
Flags: [ SHF_EXCLUDE, SHF_MERGE, SHF_STRINGS ]
17+
AddressAlign: 0x1
18+
EntSize: 0x1
19+
Content: 5F5A33666F6F7600666F6F00696E74006D61696E006172676300617267760063686172004170706C6520636C616E672076657273696F6E2031352E302E302028636C616E672D313530302E312E302E322E35290064756D705F64776F2E637070002E2F64756D705F64776F2E64776F00
20+
- Name: .debug_info.dwo
21+
Type: SHT_PROGBITS
22+
Flags: [ SHF_EXCLUDE ]
23+
AddressAlign: 0x1
24+
Content: 64000000050005080000000036C1C3A75DD36D37010704000809020008000000015600010002500000000301230000000156030006500000000402917804000650000000040291700500065400000000050205040659000000065E00000007630000000506060100
25+
- Name: .debug_abbrev.dwo
26+
Type: SHT_PROGBITS
27+
Flags: [ SHF_EXCLUDE ]
28+
AddressAlign: 0x1
29+
Content: 01110125251305032576250000022E00111B120640186E2503253A0B3B0B49133F190000032E01111B1206401803253A0B3B0B49133F190000040500021803253A0B3B0B4913000005240003253E0B0B0B0000060F00491300000726004913000000
30+
- Type: SectionHeaderTable
31+
Sections:
32+
- Name: .strtab
33+
- Name: .debug_str_offsets.dwo
34+
- Name: .debug_str.dwo
35+
- Name: .debug_info.dwo
36+
- Name: .debug_abbrev.dwo
37+
...
Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
--- !ELF
2+
FileHeader:
3+
Class: ELFCLASS64
4+
Data: ELFDATA2LSB
5+
Type: ET_REL
6+
Machine: EM_X86_64
7+
SectionHeaderStringTable: .strtab
8+
Sections:
9+
- Name: .text
10+
Type: SHT_PROGBITS
11+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
12+
AddressAlign: 0x10
13+
Content: 554889E531C05DC30F1F840000000000554889E54883EC10C745FC00000000897DF8488975F0E80000000031C04883C4105DC3
14+
- Name: .debug_abbrev
15+
Type: SHT_PROGBITS
16+
AddressAlign: 0x1
17+
Content: 014A00101772171B25B442197625111B12067317000000
18+
- Name: .debug_info
19+
Type: SHT_PROGBITS
20+
AddressAlign: 0x1
21+
Content: 24000000050004080000000036C1C3A75DD36D370100000000000000000001003300000000000000
22+
- Name: .debug_str_offsets
23+
Type: SHT_PROGBITS
24+
AddressAlign: 0x1
25+
Content: 0C000000050000000000000000000000
26+
- Name: .debug_gnu_pubnames
27+
Type: SHT_PROGBITS
28+
AddressAlign: 0x1
29+
Content: 21000000020000000000280000001A00000030666F6F002A000000306D61696E0000000000
30+
- Name: .debug_gnu_pubtypes
31+
Type: SHT_PROGBITS
32+
AddressAlign: 0x1
33+
Content: '21000000020000000000280000005000000090696E74006300000090636861720000000000'
34+
- Name: .comment
35+
Type: SHT_PROGBITS
36+
Flags: [ SHF_MERGE, SHF_STRINGS ]
37+
AddressAlign: 0x1
38+
EntSize: 0x1
39+
Content: 004170706C6520636C616E672076657273696F6E2031352E302E302028636C616E672D313530302E312E302E322E352900
40+
- Name: .note.GNU-stack
41+
Type: SHT_PROGBITS
42+
AddressAlign: 0x1
43+
- Name: .eh_frame
44+
Type: SHT_X86_64_UNWIND
45+
Flags: [ SHF_ALLOC ]
46+
AddressAlign: 0x8
47+
Content: 1400000000000000017A5200017810011B0C0708900100001C0000001C000000000000000800000000410E108602430D06430C07080000001C0000003C000000000000002300000000410E108602430D065E0C0708000000
48+
- Name: .debug_line
49+
Type: SHT_PROGBITS
50+
AddressAlign: 0x1
51+
Content: 5F0000000500080037000000010101FB0E0D00010101010000000100000101011F010000000003011F020F051E0100000000004000920BB47E0DDA24E8521F209EDB37040000090200000000000000001305020A4B0500BD05030A0859590208000101
52+
- Name: .debug_line_str
53+
Type: SHT_PROGBITS
54+
Flags: [ SHF_MERGE, SHF_STRINGS ]
55+
AddressAlign: 0x1
56+
EntSize: 0x1
57+
Content: 2E2F0064756D705F64776F2E63707000
58+
- Name: .rela.text
59+
Type: SHT_RELA
60+
Flags: [ SHF_INFO_LINK ]
61+
Link: .symtab
62+
AddressAlign: 0x8
63+
Info: .text
64+
Relocations:
65+
- Offset: 0x27
66+
Symbol: _Z3foov
67+
Type: R_X86_64_PLT32
68+
Addend: -4
69+
- Name: .rela.debug_info
70+
Type: SHT_RELA
71+
Flags: [ SHF_INFO_LINK ]
72+
Link: .symtab
73+
AddressAlign: 0x8
74+
Info: .debug_info
75+
Relocations:
76+
- Offset: 0x8
77+
Symbol: .debug_abbrev
78+
Type: R_X86_64_32
79+
- Offset: 0x15
80+
Symbol: .debug_line
81+
Type: R_X86_64_32
82+
- Offset: 0x19
83+
Symbol: .debug_str_offsets
84+
Type: R_X86_64_32
85+
Addend: 8
86+
- Offset: 0x24
87+
Symbol: .debug_addr
88+
Type: R_X86_64_32
89+
Addend: 8
90+
- Name: .rela.debug_str_offsets
91+
Type: SHT_RELA
92+
Flags: [ SHF_INFO_LINK ]
93+
Link: .symtab
94+
AddressAlign: 0x8
95+
Info: .debug_str_offsets
96+
Relocations:
97+
- Offset: 0x8
98+
Symbol: .debug_str
99+
Type: R_X86_64_32
100+
- Offset: 0xC
101+
Symbol: .debug_str
102+
Type: R_X86_64_32
103+
Addend: 3
104+
- Name: .rela.debug_addr
105+
Type: SHT_RELA
106+
Flags: [ SHF_INFO_LINK ]
107+
Link: .symtab
108+
AddressAlign: 0x8
109+
Info: .debug_addr
110+
Relocations:
111+
- Offset: 0x8
112+
Symbol: .text
113+
Type: R_X86_64_64
114+
- Offset: 0x10
115+
Symbol: .text
116+
Type: R_X86_64_64
117+
Addend: 16
118+
- Name: .rela.debug_gnu_pubnames
119+
Type: SHT_RELA
120+
Flags: [ SHF_INFO_LINK ]
121+
Link: .symtab
122+
AddressAlign: 0x8
123+
Info: .debug_gnu_pubnames
124+
Relocations:
125+
- Offset: 0x6
126+
Symbol: .debug_info
127+
Type: R_X86_64_32
128+
- Name: .rela.debug_gnu_pubtypes
129+
Type: SHT_RELA
130+
Flags: [ SHF_INFO_LINK ]
131+
Link: .symtab
132+
AddressAlign: 0x8
133+
Info: .debug_gnu_pubtypes
134+
Relocations:
135+
- Offset: 0x6
136+
Symbol: .debug_info
137+
Type: R_X86_64_32
138+
- Name: .rela.eh_frame
139+
Type: SHT_RELA
140+
Flags: [ SHF_INFO_LINK ]
141+
Link: .symtab
142+
AddressAlign: 0x8
143+
Info: .eh_frame
144+
Relocations:
145+
- Offset: 0x20
146+
Symbol: .text
147+
Type: R_X86_64_PC32
148+
- Offset: 0x40
149+
Symbol: .text
150+
Type: R_X86_64_PC32
151+
Addend: 16
152+
- Name: .rela.debug_line
153+
Type: SHT_RELA
154+
Flags: [ SHF_INFO_LINK ]
155+
Link: .symtab
156+
AddressAlign: 0x8
157+
Info: .debug_line
158+
Relocations:
159+
- Offset: 0x22
160+
Symbol: .debug_line_str
161+
Type: R_X86_64_32
162+
- Offset: 0x2E
163+
Symbol: .debug_line_str
164+
Type: R_X86_64_32
165+
Addend: 3
166+
- Offset: 0x48
167+
Symbol: .text
168+
Type: R_X86_64_64
169+
- Name: .llvm_addrsig
170+
Type: SHT_LLVM_ADDRSIG
171+
Flags: [ SHF_EXCLUDE ]
172+
Link: .symtab
173+
AddressAlign: 0x1
174+
Symbols: [ _Z3foov ]
175+
- Type: SectionHeaderTable
176+
Sections:
177+
- Name: .strtab
178+
- Name: .text
179+
- Name: .rela.text
180+
- Name: .debug_abbrev
181+
- Name: .debug_info
182+
- Name: .rela.debug_info
183+
- Name: .debug_str_offsets
184+
- Name: .rela.debug_str_offsets
185+
- Name: .debug_str
186+
- Name: .debug_addr
187+
- Name: .rela.debug_addr
188+
- Name: .debug_gnu_pubnames
189+
- Name: .rela.debug_gnu_pubnames
190+
- Name: .debug_gnu_pubtypes
191+
- Name: .rela.debug_gnu_pubtypes
192+
- Name: .comment
193+
- Name: .note.GNU-stack
194+
- Name: .eh_frame
195+
- Name: .rela.eh_frame
196+
- Name: .debug_line
197+
- Name: .rela.debug_line
198+
- Name: .debug_line_str
199+
- Name: .llvm_addrsig
200+
- Name: .symtab
201+
Symbols:
202+
- Name: dump_dwo.cpp
203+
Type: STT_FILE
204+
Index: SHN_ABS
205+
- Name: .text
206+
Type: STT_SECTION
207+
Section: .text
208+
- Name: .debug_abbrev
209+
Type: STT_SECTION
210+
Section: .debug_abbrev
211+
- Name: .debug_info
212+
Type: STT_SECTION
213+
Section: .debug_info
214+
- Name: .debug_str_offsets
215+
Type: STT_SECTION
216+
Section: .debug_str_offsets
217+
- Name: .debug_str
218+
Type: STT_SECTION
219+
Section: .debug_str
220+
- Name: .debug_addr
221+
Type: STT_SECTION
222+
Section: .debug_addr
223+
- Name: .debug_line
224+
Type: STT_SECTION
225+
Section: .debug_line
226+
- Name: .debug_line_str
227+
Type: STT_SECTION
228+
Section: .debug_line_str
229+
- Name: _Z3foov
230+
Type: STT_FUNC
231+
Section: .text
232+
Binding: STB_GLOBAL
233+
Size: 0x8
234+
- Name: main
235+
Type: STT_FUNC
236+
Section: .text
237+
Binding: STB_GLOBAL
238+
Value: 0x10
239+
Size: 0x23
240+
DWARF:
241+
debug_str:
242+
- './'
243+
- './dump_dwo.dwo'
244+
debug_addr:
245+
- Length: 0x14
246+
Version: 0x5
247+
AddressSize: 0x8
248+
Entries:
249+
- {}
250+
- Address: 0x10
251+
...

0 commit comments

Comments
 (0)