Skip to content

Commit 7cdd262

Browse files
committed
DebugInfo: Fix incorrect line table lookup when resolving decl_file from a split unit
Specifically in DWARFv5 the unit for the line table entry was correct but the context was incorrect - leading to looking up .debug_line_str in the dwp instead of the executable. (perhaps we could/should remove the context pointer entirely, and rely on the one in the unit... I might try that as a separate follow-up commit)
1 parent c0d9bf2 commit 7cdd262

File tree

3 files changed

+209
-7
lines changed

3 files changed

+209
-7
lines changed

llvm/lib/DebugInfo/DWARF/DWARFFormValue.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -767,10 +767,10 @@ Optional<std::string>
767767
DWARFFormValue::getAsFile(DILineInfoSpecifier::FileLineInfoKind Kind) const {
768768
if (U == nullptr || !isFormClass(FC_Constant))
769769
return None;
770-
DWARFUnit *DU = const_cast<DWARFUnit *>(U);
771-
if (auto *LT = U->getContext().getLineTableForUnit(DU->getLinkedUnit())) {
770+
DWARFUnit *DLU = const_cast<DWARFUnit *>(U)->getLinkedUnit();
771+
if (auto *LT = DLU->getContext().getLineTableForUnit(DLU)) {
772772
std::string FileName;
773-
if (LT->getFileNameByIndex(Value.uval, DU->getCompilationDir(), Kind,
773+
if (LT->getFileNameByIndex(Value.uval, DLU->getCompilationDir(), Kind,
774774
FileName))
775775
return FileName;
776776
}

llvm/test/DebugInfo/X86/symbolize_function_start.s

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# RUN: rm -rf %t
22
# RUN: mkdir %t
3-
# RUN: llvm-mc -filetype=obj -triple=x86_64 -dwarf-version=4 %s -o %t/test.o
3+
# RUN: llvm-mc -filetype=obj -triple=x86_64 -dwarf-version=4 %s -o %t/test.o -split-dwarf-file %t/test.dwo
44
# RUN: cd %t
55
# RUN: llvm-symbolizer --verbose 0x0 --obj=test.o | FileCheck --check-prefix=SYM %s
66
# RUN: llvm-dwarfdump -lookup=0x1 test.o | FileCheck --check-prefix=LOOKUP %s
77

88
# SYM: Filename: .{{[/\\]}}.{{[/\\]}}./test.h
9-
# SYM: Function start filename: .{{[/\\]}}test.cpp
9+
# SYM: Function start filename: .{{[/\\]}}.{{[/\\]}}test.cpp
1010

1111
# LOOKUP: Line info: line 0, column 0, start file 'test.cpp', start line 1
1212

@@ -75,7 +75,7 @@ _Z2f1v: # @_Z2f1v
7575
.Lskel_string0:
7676
.asciz "." # string offset=0
7777
.Lskel_string1:
78-
.asciz "test.o" # string offset=2
78+
.asciz "test.dwo" # string offset=2
7979
.section .debug_str.dwo,"eMS",@progbits,1
8080
.Linfo_string0:
8181
.asciz "_Z2f1v" # string offset=0
@@ -88,7 +88,7 @@ _Z2f1v: # @_Z2f1v
8888
.Linfo_string4:
8989
.asciz "test.cpp" # string offset=115
9090
.Linfo_string5:
91-
.asciz "test.o" # string offset=124
91+
.asciz "test.dwo" # string offset=124
9292
.section .debug_str_offsets.dwo,"e",@progbits
9393
.long 0
9494
.long 7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
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 -split-dwarf-file %t/test.dwo
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.c
9+
# SYM: Function start filename: .{{[/\\]}}.{{[/\\]}}test.c
10+
11+
# LOOKUP: Line info: line 0, column 0, start file 'test.c', start line 1
12+
13+
.text
14+
.file "test.c"
15+
.globl f1 # -- Begin function f1
16+
.p2align 4, 0x90
17+
.type f1,@function
18+
f1: # @f1
19+
.Lfunc_begin0:
20+
.file 0 "./" "test.c" md5 0xde4c8c8bd673cd6151beb4570168727a
21+
.loc 0 1 0 # test.c:1:0
22+
.cfi_startproc
23+
# %bb.0: # %entry
24+
pushq %rbp
25+
.cfi_def_cfa_offset 16
26+
.cfi_offset %rbp, -16
27+
movq %rsp, %rbp
28+
.cfi_def_cfa_register %rbp
29+
.Ltmp0:
30+
.loc 0 1 13 prologue_end # test.c:1:13
31+
popq %rbp
32+
.cfi_def_cfa %rsp, 8
33+
retq
34+
.Ltmp1:
35+
.Lfunc_end0:
36+
.size f1, .Lfunc_end0-f1
37+
.cfi_endproc
38+
# -- End function
39+
.section .debug_abbrev,"",@progbits
40+
.byte 1 # Abbreviation Code
41+
.byte 74 # DW_TAG_skeleton_unit
42+
.byte 0 # DW_CHILDREN_no
43+
.byte 16 # DW_AT_stmt_list
44+
.byte 23 # DW_FORM_sec_offset
45+
.byte 114 # DW_AT_str_offsets_base
46+
.byte 23 # DW_FORM_sec_offset
47+
.byte 27 # DW_AT_comp_dir
48+
.byte 37 # DW_FORM_strx1
49+
.ascii "\264B" # DW_AT_GNU_pubnames
50+
.byte 25 # DW_FORM_flag_present
51+
.byte 118 # DW_AT_dwo_name
52+
.byte 37 # DW_FORM_strx1
53+
.byte 17 # DW_AT_low_pc
54+
.byte 27 # DW_FORM_addrx
55+
.byte 18 # DW_AT_high_pc
56+
.byte 6 # DW_FORM_data4
57+
.byte 115 # DW_AT_addr_base
58+
.byte 23 # DW_FORM_sec_offset
59+
.byte 0 # EOM(1)
60+
.byte 0 # EOM(2)
61+
.byte 0 # EOM(3)
62+
.section .debug_info,"",@progbits
63+
.Lcu_begin0:
64+
.long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
65+
.Ldebug_info_start0:
66+
.short 5 # DWARF version number
67+
.byte 4 # DWARF Unit Type
68+
.byte 8 # Address Size (in bytes)
69+
.long .debug_abbrev # Offset Into Abbrev. Section
70+
.quad -2320906069171721424
71+
.byte 1 # Abbrev [1] 0x14:0x14 DW_TAG_skeleton_unit
72+
.long .Lline_table_start0 # DW_AT_stmt_list
73+
.long .Lstr_offsets_base0 # DW_AT_str_offsets_base
74+
.byte 0 # DW_AT_comp_dir
75+
# DW_AT_GNU_pubnames
76+
.byte 1 # DW_AT_dwo_name
77+
.byte 0 # DW_AT_low_pc
78+
.long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
79+
.long .Laddr_table_base0 # DW_AT_addr_base
80+
.Ldebug_info_end0:
81+
.section .debug_str_offsets,"",@progbits
82+
.long 12 # Length of String Offsets Set
83+
.short 5
84+
.short 0
85+
.Lstr_offsets_base0:
86+
.section .debug_str,"MS",@progbits,1
87+
.Lskel_string0:
88+
.asciz "./" # string offset=0
89+
.Lskel_string1:
90+
.asciz "./test.dwo" # string offset=3
91+
.section .debug_str_offsets,"",@progbits
92+
.long .Lskel_string0
93+
.long .Lskel_string1
94+
.section .debug_str_offsets.dwo,"e",@progbits
95+
.long 20 # Length of String Offsets Set
96+
.short 5
97+
.short 0
98+
.section .debug_str.dwo,"eMS",@progbits,1
99+
.Linfo_string0:
100+
.asciz "f1" # string offset=0
101+
.Linfo_string1:
102+
.asciz "clang version 14.0.0 (git@github.com:llvm/llvm-project.git e7fdff403e849b18d93cd4a5cb760cba66a92c0b)" # string offset=3
103+
.Linfo_string2:
104+
.asciz "test.c" # string offset=104
105+
.Linfo_string3:
106+
.asciz "./test.dwo" # string offset=111
107+
.section .debug_str_offsets.dwo,"e",@progbits
108+
.long 0
109+
.long 3
110+
.long 104
111+
.long 111
112+
.section .debug_info.dwo,"e",@progbits
113+
.long .Ldebug_info_dwo_end0-.Ldebug_info_dwo_start0 # Length of Unit
114+
.Ldebug_info_dwo_start0:
115+
.short 5 # DWARF version number
116+
.byte 5 # DWARF Unit Type
117+
.byte 8 # Address Size (in bytes)
118+
.long 0 # Offset Into Abbrev. Section
119+
.quad -2320906069171721424
120+
.byte 1 # Abbrev [1] 0x14:0x12 DW_TAG_compile_unit
121+
.byte 1 # DW_AT_producer
122+
.short 12 # DW_AT_language
123+
.byte 2 # DW_AT_name
124+
.byte 3 # DW_AT_dwo_name
125+
.byte 2 # Abbrev [2] 0x1a:0xb DW_TAG_subprogram
126+
.byte 0 # DW_AT_low_pc
127+
.long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
128+
.byte 1 # DW_AT_frame_base
129+
.byte 86
130+
.byte 0 # DW_AT_name
131+
.byte 0 # DW_AT_decl_file
132+
.byte 1 # DW_AT_decl_line
133+
# DW_AT_external
134+
.byte 0 # End Of Children Mark
135+
.Ldebug_info_dwo_end0:
136+
.section .debug_abbrev.dwo,"e",@progbits
137+
.byte 1 # Abbreviation Code
138+
.byte 17 # DW_TAG_compile_unit
139+
.byte 1 # DW_CHILDREN_yes
140+
.byte 37 # DW_AT_producer
141+
.byte 37 # DW_FORM_strx1
142+
.byte 19 # DW_AT_language
143+
.byte 5 # DW_FORM_data2
144+
.byte 3 # DW_AT_name
145+
.byte 37 # DW_FORM_strx1
146+
.byte 118 # DW_AT_dwo_name
147+
.byte 37 # DW_FORM_strx1
148+
.byte 0 # EOM(1)
149+
.byte 0 # EOM(2)
150+
.byte 2 # Abbreviation Code
151+
.byte 46 # DW_TAG_subprogram
152+
.byte 0 # DW_CHILDREN_no
153+
.byte 17 # DW_AT_low_pc
154+
.byte 27 # DW_FORM_addrx
155+
.byte 18 # DW_AT_high_pc
156+
.byte 6 # DW_FORM_data4
157+
.byte 64 # DW_AT_frame_base
158+
.byte 24 # DW_FORM_exprloc
159+
.byte 3 # DW_AT_name
160+
.byte 37 # DW_FORM_strx1
161+
.byte 58 # DW_AT_decl_file
162+
.byte 11 # DW_FORM_data1
163+
.byte 59 # DW_AT_decl_line
164+
.byte 11 # DW_FORM_data1
165+
.byte 63 # DW_AT_external
166+
.byte 25 # DW_FORM_flag_present
167+
.byte 0 # EOM(1)
168+
.byte 0 # EOM(2)
169+
.byte 0 # EOM(3)
170+
.section .debug_addr,"",@progbits
171+
.long .Ldebug_addr_end0-.Ldebug_addr_start0 # Length of contribution
172+
.Ldebug_addr_start0:
173+
.short 5 # DWARF version number
174+
.byte 8 # Address size
175+
.byte 0 # Segment selector size
176+
.Laddr_table_base0:
177+
.quad .Lfunc_begin0
178+
.Ldebug_addr_end0:
179+
.section .debug_gnu_pubnames,"",@progbits
180+
.long .LpubNames_end0-.LpubNames_start0 # Length of Public Names Info
181+
.LpubNames_start0:
182+
.short 2 # DWARF Version
183+
.long .Lcu_begin0 # Offset of Compilation Unit Info
184+
.long 40 # Compilation Unit Length
185+
.long 26 # DIE offset
186+
.byte 48 # Attributes: FUNCTION, EXTERNAL
187+
.asciz "f1" # External Name
188+
.long 0 # End Mark
189+
.LpubNames_end0:
190+
.section .debug_gnu_pubtypes,"",@progbits
191+
.long .LpubTypes_end0-.LpubTypes_start0 # Length of Public Types Info
192+
.LpubTypes_start0:
193+
.short 2 # DWARF Version
194+
.long .Lcu_begin0 # Offset of Compilation Unit Info
195+
.long 40 # Compilation Unit Length
196+
.long 0 # End Mark
197+
.LpubTypes_end0:
198+
.ident "clang version 14.0.0 (git@github.com:llvm/llvm-project.git e7fdff403e849b18d93cd4a5cb760cba66a92c0b)"
199+
.section ".note.GNU-stack","",@progbits
200+
.addrsig
201+
.section .debug_line,"",@progbits
202+
.Lline_table_start0:

0 commit comments

Comments
 (0)