Skip to content

Commit 04c203e

Browse files
committed
llvm-symbolizer: Fix "start file" to work with Split DWARF
A followup to the feature added in 69da27c that added the optional "start file name" to match "start line" - but this didn't work with Split DWARF because of the need for the decl file number resolution code to refer back to the skeleton unit to find its .debug_line contribution. So this patch adds the necessary infrastructure to track the skeleton unit corresponding to a split full unit for the purpose of this lookup.
1 parent 882ee7f commit 04c203e

File tree

4 files changed

+229
-4
lines changed

4 files changed

+229
-4
lines changed

llvm/include/llvm/DebugInfo/DWARF/DWARFUnit.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ class DWARFUnit {
218218
StringRef StringSection;
219219
const DWARFSection &StringOffsetSection;
220220
const DWARFSection *AddrOffsetSection;
221+
DWARFUnit *SU;
221222
Optional<uint64_t> AddrOffsetSectionBase;
222223
bool isLittleEndian;
223224
bool IsDWO;
@@ -301,6 +302,12 @@ class DWARFUnit {
301302
return StringOffsetSection;
302303
}
303304

305+
void setSkeletonUnit(DWARFUnit *SU) { this->SU = SU; }
306+
// Returns itself if not using Split DWARF, or if the unit is a skeleton unit
307+
// - otherwise returns the split full unit's corresponding skeleton, if
308+
// available.
309+
DWARFUnit *getLinkedUnit() { return IsDWO ? SU : this; }
310+
304311
void setAddrOffsetSection(const DWARFSection *AOS, uint64_t Base) {
305312
AddrOffsetSection = AOS;
306313
AddrOffsetSectionBase = Base;

llvm/lib/DebugInfo/DWARF/DWARFDie.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,11 +571,16 @@ uint64_t DWARFDie::getDeclLine() const {
571571

572572
std::string
573573
DWARFDie::getDeclFile(DILineInfoSpecifier::FileLineInfoKind Kind) const {
574+
auto D = getAttributeValueAsReferencedDie(DW_AT_abstract_origin);
575+
if (!D)
576+
D = *this;
574577
std::string FileName;
575-
if (auto DeclFile = toUnsigned(findRecursively(DW_AT_decl_file))) {
576-
if (const auto *LT = U->getContext().getLineTableForUnit(U)) {
577-
LT->getFileNameByIndex(*DeclFile, U->getCompilationDir(), Kind, FileName);
578-
}
578+
if (auto DeclFile = toUnsigned(D.find(DW_AT_decl_file))) {
579+
if (const auto *LineTable =
580+
getDwarfUnit()->getContext().getLineTableForUnit(
581+
D.getDwarfUnit()->getLinkedUnit()))
582+
LineTable->getFileNameByIndex(
583+
*DeclFile, D.getDwarfUnit()->getCompilationDir(), Kind, FileName);
579584
}
580585
return FileName;
581586
}

llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ void DWARFUnit::clear() {
388388
RangeSectionBase = 0;
389389
LocSectionBase = 0;
390390
AddrOffsetSectionBase = None;
391+
SU = nullptr;
391392
clearDIEs(false);
392393
DWO.reset();
393394
}
@@ -586,6 +587,7 @@ bool DWARFUnit::parseDWO() {
586587
if (!DWOCU)
587588
return false;
588589
DWO = std::shared_ptr<DWARFCompileUnit>(std::move(DWOContext), DWOCU);
590+
DWO->setSkeletonUnit(this);
589591
// Share .debug_addr and .debug_ranges section with compile unit in .dwo
590592
if (AddrOffsetSectionBase)
591593
DWO->setAddrOffsetSection(AddrOffsetSection, *AddrOffsetSectionBase);
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
# RUN: rm -rf %t
2+
# RUN: mkdir %t
3+
# RUN: llvm-mc -filetype=obj -triple=x86_64 -dwarf-version=4 %s -o %t/test.o
4+
# RUN: cd %t
5+
# RUN: llvm-symbolizer -verbose 0x0 -obj=test.o | FileCheck --check-prefix=SYM %s
6+
# RUN: llvm-dwarfdump -lookup=0x1 test.o | FileCheck --check-prefix=LOOKUP %s
7+
8+
# SYM: Filename: ./././test.h
9+
# SYM: Function start filename: ./test.cpp
10+
11+
# LOOKUP: Line info: line 0, column 0, start file 'test.cpp', start line 1
12+
13+
14+
.text
15+
.file "test.cpp"
16+
.globl _Z2f1v # -- Begin function _Z2f1v
17+
.p2align 4, 0x90
18+
.type _Z2f1v,@function
19+
_Z2f1v: # @_Z2f1v
20+
.Lfunc_begin0:
21+
.file 1 "." "test.cpp"
22+
.loc 1 1 0 # test.cpp:1:0
23+
.cfi_startproc
24+
# %bb.0: # %entry
25+
.file 2 "." "./test.h"
26+
.loc 2 1 1 prologue_end # ./test.h:1:1
27+
xorl %eax, %eax
28+
retq
29+
.Ltmp0:
30+
.Lfunc_end0:
31+
.size _Z2f1v, .Lfunc_end0-_Z2f1v
32+
.cfi_endproc
33+
# -- End function
34+
.section .debug_abbrev,"",@progbits
35+
.byte 1 # Abbreviation Code
36+
.byte 17 # DW_TAG_compile_unit
37+
.byte 0 # DW_CHILDREN_no
38+
.byte 16 # DW_AT_stmt_list
39+
.byte 23 # DW_FORM_sec_offset
40+
.byte 27 # DW_AT_comp_dir
41+
.byte 14 # DW_FORM_strp
42+
.ascii "\264B" # DW_AT_GNU_pubnames
43+
.byte 25 # DW_FORM_flag_present
44+
.ascii "\260B" # DW_AT_GNU_dwo_name
45+
.byte 14 # DW_FORM_strp
46+
.ascii "\261B" # DW_AT_GNU_dwo_id
47+
.byte 7 # DW_FORM_data8
48+
.byte 17 # DW_AT_low_pc
49+
.byte 1 # DW_FORM_addr
50+
.byte 18 # DW_AT_high_pc
51+
.byte 6 # DW_FORM_data4
52+
.ascii "\263B" # DW_AT_GNU_addr_base
53+
.byte 23 # DW_FORM_sec_offset
54+
.byte 0 # EOM(1)
55+
.byte 0 # EOM(2)
56+
.byte 0 # EOM(3)
57+
.section .debug_info,"",@progbits
58+
.Lcu_begin0:
59+
.long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
60+
.Ldebug_info_start0:
61+
.short 4 # DWARF version number
62+
.long .debug_abbrev # Offset Into Abbrev. Section
63+
.byte 8 # Address Size (in bytes)
64+
.byte 1 # Abbrev [1] 0xb:0x25 DW_TAG_compile_unit
65+
.long .Lline_table_start0 # DW_AT_stmt_list
66+
.long .Lskel_string0 # DW_AT_comp_dir
67+
# DW_AT_GNU_pubnames
68+
.long .Lskel_string1 # DW_AT_GNU_dwo_name
69+
.quad 7198491773836599109 # DW_AT_GNU_dwo_id
70+
.quad .Lfunc_begin0 # DW_AT_low_pc
71+
.long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
72+
.long .Laddr_table_base0 # DW_AT_GNU_addr_base
73+
.Ldebug_info_end0:
74+
.section .debug_str,"MS",@progbits,1
75+
.Lskel_string0:
76+
.asciz "." # string offset=0
77+
.Lskel_string1:
78+
.asciz "test.o" # string offset=2
79+
.section .debug_str.dwo,"eMS",@progbits,1
80+
.Linfo_string0:
81+
.asciz "_Z2f1v" # string offset=0
82+
.Linfo_string1:
83+
.asciz "f1" # string offset=7
84+
.Linfo_string2:
85+
.asciz "int" # string offset=10
86+
.Linfo_string3:
87+
.asciz "clang version 13.0.0 ([email protected]:llvm/llvm-project.git 882ee7fbd6fc989fba53f3d9672440771feb80f5)" # string offset=14
88+
.Linfo_string4:
89+
.asciz "test.cpp" # string offset=115
90+
.Linfo_string5:
91+
.asciz "test.o" # string offset=124
92+
.section .debug_str_offsets.dwo,"e",@progbits
93+
.long 0
94+
.long 7
95+
.long 10
96+
.long 14
97+
.long 115
98+
.long 124
99+
.section .debug_info.dwo,"e",@progbits
100+
.long .Ldebug_info_dwo_end0-.Ldebug_info_dwo_start0 # Length of Unit
101+
.Ldebug_info_dwo_start0:
102+
.short 4 # DWARF version number
103+
.long 0 # Offset Into Abbrev. Section
104+
.byte 8 # Address Size (in bytes)
105+
.byte 1 # Abbrev [1] 0xb:0x23 DW_TAG_compile_unit
106+
.byte 3 # DW_AT_producer
107+
.short 33 # DW_AT_language
108+
.byte 4 # DW_AT_name
109+
.byte 5 # DW_AT_GNU_dwo_name
110+
.quad 7198491773836599109 # DW_AT_GNU_dwo_id
111+
.byte 2 # Abbrev [2] 0x19:0x10 DW_TAG_subprogram
112+
.byte 0 # DW_AT_low_pc
113+
.long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
114+
.byte 1 # DW_AT_frame_base
115+
.byte 87
116+
# DW_AT_GNU_all_call_sites
117+
.byte 0 # DW_AT_linkage_name
118+
.byte 1 # DW_AT_name
119+
.byte 1 # DW_AT_decl_file
120+
.byte 1 # DW_AT_decl_line
121+
.long 41 # DW_AT_type
122+
# DW_AT_external
123+
.byte 3 # Abbrev [3] 0x29:0x4 DW_TAG_base_type
124+
.byte 2 # DW_AT_name
125+
.byte 5 # DW_AT_encoding
126+
.byte 4 # DW_AT_byte_size
127+
.byte 0 # End Of Children Mark
128+
.Ldebug_info_dwo_end0:
129+
.section .debug_abbrev.dwo,"e",@progbits
130+
.byte 1 # Abbreviation Code
131+
.byte 17 # DW_TAG_compile_unit
132+
.byte 1 # DW_CHILDREN_yes
133+
.byte 37 # DW_AT_producer
134+
.ascii "\202>" # DW_FORM_GNU_str_index
135+
.byte 19 # DW_AT_language
136+
.byte 5 # DW_FORM_data2
137+
.byte 3 # DW_AT_name
138+
.ascii "\202>" # DW_FORM_GNU_str_index
139+
.ascii "\260B" # DW_AT_GNU_dwo_name
140+
.ascii "\202>" # DW_FORM_GNU_str_index
141+
.ascii "\261B" # DW_AT_GNU_dwo_id
142+
.byte 7 # DW_FORM_data8
143+
.byte 0 # EOM(1)
144+
.byte 0 # EOM(2)
145+
.byte 2 # Abbreviation Code
146+
.byte 46 # DW_TAG_subprogram
147+
.byte 0 # DW_CHILDREN_no
148+
.byte 17 # DW_AT_low_pc
149+
.ascii "\201>" # DW_FORM_GNU_addr_index
150+
.byte 18 # DW_AT_high_pc
151+
.byte 6 # DW_FORM_data4
152+
.byte 64 # DW_AT_frame_base
153+
.byte 24 # DW_FORM_exprloc
154+
.ascii "\227B" # DW_AT_GNU_all_call_sites
155+
.byte 25 # DW_FORM_flag_present
156+
.byte 110 # DW_AT_linkage_name
157+
.ascii "\202>" # DW_FORM_GNU_str_index
158+
.byte 3 # DW_AT_name
159+
.ascii "\202>" # DW_FORM_GNU_str_index
160+
.byte 58 # DW_AT_decl_file
161+
.byte 11 # DW_FORM_data1
162+
.byte 59 # DW_AT_decl_line
163+
.byte 11 # DW_FORM_data1
164+
.byte 73 # DW_AT_type
165+
.byte 19 # DW_FORM_ref4
166+
.byte 63 # DW_AT_external
167+
.byte 25 # DW_FORM_flag_present
168+
.byte 0 # EOM(1)
169+
.byte 0 # EOM(2)
170+
.byte 3 # Abbreviation Code
171+
.byte 36 # DW_TAG_base_type
172+
.byte 0 # DW_CHILDREN_no
173+
.byte 3 # DW_AT_name
174+
.ascii "\202>" # DW_FORM_GNU_str_index
175+
.byte 62 # DW_AT_encoding
176+
.byte 11 # DW_FORM_data1
177+
.byte 11 # DW_AT_byte_size
178+
.byte 11 # DW_FORM_data1
179+
.byte 0 # EOM(1)
180+
.byte 0 # EOM(2)
181+
.byte 0 # EOM(3)
182+
.section .debug_addr,"",@progbits
183+
.Laddr_table_base0:
184+
.quad .Lfunc_begin0
185+
.section .debug_gnu_pubnames,"",@progbits
186+
.long .LpubNames_end0-.LpubNames_start0 # Length of Public Names Info
187+
.LpubNames_start0:
188+
.short 2 # DWARF Version
189+
.long .Lcu_begin0 # Offset of Compilation Unit Info
190+
.long 48 # Compilation Unit Length
191+
.long 25 # DIE offset
192+
.byte 48 # Attributes: FUNCTION, EXTERNAL
193+
.asciz "f1" # External Name
194+
.long 0 # End Mark
195+
.LpubNames_end0:
196+
.section .debug_gnu_pubtypes,"",@progbits
197+
.long .LpubTypes_end0-.LpubTypes_start0 # Length of Public Types Info
198+
.LpubTypes_start0:
199+
.short 2 # DWARF Version
200+
.long .Lcu_begin0 # Offset of Compilation Unit Info
201+
.long 48 # Compilation Unit Length
202+
.long 41 # DIE offset
203+
.byte 144 # Attributes: TYPE, STATIC
204+
.asciz "int" # External Name
205+
.long 0 # End Mark
206+
.LpubTypes_end0:
207+
.ident "clang version 13.0.0 ([email protected]:llvm/llvm-project.git 882ee7fbd6fc989fba53f3d9672440771feb80f5)"
208+
.section ".note.GNU-stack","",@progbits
209+
.addrsig
210+
.section .debug_line,"",@progbits
211+
.Lline_table_start0:

0 commit comments

Comments
 (0)