Skip to content

Commit 3b47bd3

Browse files
committed
[lldb] Fix handling of DW_AT_decl_file according to D91014 (attempt #2)
Apply changes from https://reviews.llvm.org/D91014 to other places where DWARF entries are being processed. Test case is provided by @jankratochvil. The test is marked to run only on x64 and exclude Windows and Darwin, because the assembly is not OS-independent. (First attempt https://reviews.llvm.org/D96778 broke the build bots) Reviewed By: jankratochvil Differential Revision: https://reviews.llvm.org/D97765
1 parent c3ce7ba commit 3b47bd3

File tree

4 files changed

+335
-3
lines changed

4 files changed

+335
-3
lines changed

lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -2201,7 +2201,8 @@ size_t DWARFASTParserClang::ParseChildEnumerators(
22012201
case DW_AT_description:
22022202
default:
22032203
case DW_AT_decl_file:
2204-
decl.SetFile(die.GetCU()->GetFile(form_value.Unsigned()));
2204+
decl.SetFile(attributes.CompileUnitAtIndex(i)->GetFile(
2205+
form_value.Unsigned()));
22052206
break;
22062207
case DW_AT_decl_line:
22072208
decl.SetLine(form_value.Unsigned());

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3126,8 +3126,8 @@ VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc,
31263126
continue;
31273127
switch (attr) {
31283128
case DW_AT_decl_file:
3129-
decl.SetFile(sc.comp_unit->GetSupportFiles().GetFileSpecAtIndex(
3130-
form_value.Unsigned()));
3129+
decl.SetFile(
3130+
attributes.CompileUnitAtIndex(i)->GetFile(form_value.Unsigned()));
31313131
break;
31323132
case DW_AT_decl_line:
31333133
decl.SetLine(form_value.Unsigned());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# Check that DW_AT_decl_file of DW_AT_variable which is inherited by
2+
# DW_AT_abstract_origin from a different DW_TAG_compile_unit is using the
3+
# DW_TAG_compile_unit->DW_AT_stmt_list where the DW_AT_decl_file is located (and
4+
# not where the DW_AT_abstract_origin is located).
5+
# DW_TAG_variable in CU 1 is using DW_AT_decl_file 3.
6+
# CU 1 has files:
7+
# file_names[ 1]: name: "inlinevarother.h"
8+
# file_names[ 2]: name: "inlinevar1.c"
9+
# file_names[ 3]: name: "inlinevar.h"
10+
# CU 2 has files:
11+
# file_names[ 1]: name: "inlinevar2.c"
12+
# file_names[ 2]: name: "inlinevar.h"
13+
14+
# UNSUPPORTED: system-darwin, system-windows
15+
# REQUIRES: target-x86_64
16+
17+
# RUN: %clang_host -o %t %s \
18+
# RUN: %S/Inputs/DW_TAG_variable-DW_AT_decl_file-DW_AT_abstract_origin-crosscu2.s
19+
20+
# RUN: %lldb %t \
21+
# RUN: -o 'b other' -o r -o disas -o 'frame variable --show-declaration' \
22+
# RUN: -o exit | FileCheck %s
23+
24+
# CHECK: inlinevar.h:2: (int) var = {{.*}}
25+
# Unfixed LLDB did show only: (int) var = {{.*}}
26+
27+
.text
28+
.file "inlinevar1.c"
29+
.file 1 "" "./inlinevarother.h"
30+
.globl main # -- Begin function main
31+
.type main,@function
32+
main: # @main
33+
.Lfunc_begin1:
34+
.file 2 "" "inlinevar1.c"
35+
.loc 2 4 0 # inlinevar1.c:4:0
36+
.Ltmp2:
37+
.file 3 "" "./inlinevar.h"
38+
.loc 3 2 16 prologue_end # ./inlinevar.h:2:16
39+
movl $42, %eax
40+
pushq %rax
41+
.loc 3 3 10 # ./inlinevar.h:3:10
42+
.Ltmp3:
43+
.loc 2 5 20 # inlinevar1.c:5:20
44+
callq other
45+
popq %rcx
46+
.loc 2 5 19 # inlinevar1.c:5:19
47+
addl %ecx, %eax
48+
.loc 2 5 3 # inlinevar1.c:5:3
49+
retq
50+
.Ltmp4:
51+
.Lfunc_end1:
52+
.size main, .Lfunc_end1-main
53+
# -- End function
54+
.section .debug_abbrev,"",@progbits
55+
.byte 1 # Abbreviation Code
56+
.byte 17 # DW_TAG_compile_unit
57+
.byte 1 # DW_CHILDREN_yes
58+
.byte 37 # DW_AT_producer
59+
.byte 14 # DW_FORM_strp
60+
.byte 19 # DW_AT_language
61+
.byte 5 # DW_FORM_data2
62+
.byte 3 # DW_AT_name
63+
.byte 14 # DW_FORM_strp
64+
.byte 16 # DW_AT_stmt_list
65+
.byte 23 # DW_FORM_sec_offset
66+
.byte 27 # DW_AT_comp_dir
67+
.byte 14 # DW_FORM_strp
68+
.byte 17 # DW_AT_low_pc
69+
.byte 1 # DW_FORM_addr
70+
.byte 18 # DW_AT_high_pc
71+
.byte 6 # DW_FORM_data4
72+
.byte 0 # EOM(1)
73+
.byte 0 # EOM(2)
74+
.byte 3 # Abbreviation Code
75+
.byte 46 # DW_TAG_subprogram
76+
.byte 1 # DW_CHILDREN_yes
77+
.byte 3 # DW_AT_name
78+
.byte 14 # DW_FORM_strp
79+
.byte 58 # DW_AT_decl_file
80+
.byte 11 # DW_FORM_data1
81+
.byte 59 # DW_AT_decl_line
82+
.byte 11 # DW_FORM_data1
83+
.byte 73 # DW_AT_type
84+
.byte 19 # DW_FORM_ref4
85+
.byte 32 # DW_AT_inline
86+
.byte 11 # DW_FORM_data1
87+
.byte 0 # EOM(1)
88+
.byte 0 # EOM(2)
89+
.byte 4 # Abbreviation Code
90+
.byte 52 # DW_TAG_variable
91+
.byte 0 # DW_CHILDREN_no
92+
.byte 3 # DW_AT_name
93+
.byte 14 # DW_FORM_strp
94+
.byte 58 # DW_AT_decl_file
95+
.byte 11 # DW_FORM_data1
96+
.byte 59 # DW_AT_decl_line
97+
.byte 11 # DW_FORM_data1
98+
.byte 73 # DW_AT_type
99+
.byte 19 # DW_FORM_ref4
100+
.byte 0 # EOM(1)
101+
.byte 0 # EOM(2)
102+
.byte 5 # Abbreviation Code
103+
.byte 36 # DW_TAG_base_type
104+
.byte 0 # DW_CHILDREN_no
105+
.byte 3 # DW_AT_name
106+
.byte 14 # DW_FORM_strp
107+
.byte 62 # DW_AT_encoding
108+
.byte 11 # DW_FORM_data1
109+
.byte 11 # DW_AT_byte_size
110+
.byte 11 # DW_FORM_data1
111+
.byte 0 # EOM(1)
112+
.byte 0 # EOM(2)
113+
.byte 0 # EOM(3)
114+
.section .debug_info,"",@progbits
115+
.Lcu_begin0:
116+
.long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
117+
.Ldebug_info_start0:
118+
.short 4 # DWARF version number
119+
.long .debug_abbrev # Offset Into Abbrev. Section
120+
.byte 8 # Address Size (in bytes)
121+
.byte 1 # Abbrev [1] DW_TAG_compile_unit
122+
.long .Linfo_string0 # DW_AT_producer
123+
.short 0xc # DW_AT_language
124+
.long .Linfo_string1 # DW_AT_name
125+
.long .Lline_table_start0 # DW_AT_stmt_list
126+
.long .Linfo_string2 # DW_AT_comp_dir
127+
.quad .Lfunc_begin1 # DW_AT_low_pc
128+
.long .Lfunc_end1-.Lfunc_begin1 # DW_AT_high_pc
129+
.globl debuginfo_func_inlined
130+
debuginfo_func_inlined:
131+
.Lfunc_inlined:
132+
.byte 3 # Abbrev [3] DW_TAG_subprogram
133+
.long .Linfo_string4 # DW_AT_name
134+
.byte 3 # DW_AT_decl_file
135+
.byte 1 # DW_AT_decl_line
136+
.long .Ltype_int-.Lcu_begin0 # DW_AT_type
137+
.byte 1 # DW_AT_inline
138+
.globl debuginfo_var_var
139+
debuginfo_var_var:
140+
.Lvar_var:
141+
.byte 4 # Abbrev [4] DW_TAG_variable
142+
.long .Linfo_string6 # DW_AT_name
143+
.byte 3 # DW_AT_decl_file
144+
.byte 2 # DW_AT_decl_line
145+
.long .Ltype_int-.Lcu_begin0 # DW_AT_type
146+
.byte 0 # End Of Children Mark
147+
.Ltype_int:
148+
.byte 5 # Abbrev [5] DW_TAG_base_type
149+
.long .Linfo_string5 # DW_AT_name
150+
.byte 5 # DW_AT_encoding
151+
.byte 4 # DW_AT_byte_size
152+
.byte 0 # End Of Children Mark
153+
.Ldebug_info_end0:
154+
.section .debug_str,"MS",@progbits,1
155+
.Linfo_string0:
156+
.asciz "clang version 11.0.0 + hand coding"
157+
.Linfo_string1:
158+
.asciz "inlinevar1.c"
159+
.Linfo_string2:
160+
.asciz ""
161+
.Linfo_string4:
162+
.asciz "inlined"
163+
.Linfo_string5:
164+
.asciz "int"
165+
.Linfo_string6:
166+
.asciz "var"
167+
.section ".note.GNU-stack","",@progbits
168+
.addrsig
169+
.addrsig_sym other
170+
.section .debug_line,"",@progbits
171+
.Lline_table_start0:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
.text
2+
.file "inlinevar2.c"
3+
.globl other # -- Begin function other
4+
.type other,@function
5+
other: # @other
6+
.Lfunc_begin0:
7+
.file 1 "" "inlinevar2.c"
8+
.loc 1 3 0 # inlinevar2.c:3:0
9+
.Ltmp0:
10+
.file 2 "" "./inlinevar.h"
11+
.loc 2 2 16 prologue_end # ./inlinevar.h:2:16
12+
movl $42, %eax
13+
.loc 2 3 10 # ./inlinevar.h:3:10
14+
.loc 1 3 41 # inlinevar2.c:3:41
15+
retq
16+
.Ltmp1:
17+
.Ltmp2:
18+
.Lfunc_end0:
19+
.size other, .Lfunc_end0-other
20+
# -- End function
21+
.section .debug_abbrev,"",@progbits
22+
.byte 1 # Abbreviation Code
23+
.byte 17 # DW_TAG_compile_unit
24+
.byte 1 # DW_CHILDREN_yes
25+
.byte 37 # DW_AT_producer
26+
.byte 14 # DW_FORM_strp
27+
.byte 19 # DW_AT_language
28+
.byte 5 # DW_FORM_data2
29+
.byte 3 # DW_AT_name
30+
.byte 14 # DW_FORM_strp
31+
.byte 16 # DW_AT_stmt_list
32+
.byte 23 # DW_FORM_sec_offset
33+
.byte 27 # DW_AT_comp_dir
34+
.byte 14 # DW_FORM_strp
35+
.byte 17 # DW_AT_low_pc
36+
.byte 1 # DW_FORM_addr
37+
.byte 18 # DW_AT_high_pc
38+
.byte 6 # DW_FORM_data4
39+
.byte 0 # EOM(1)
40+
.byte 0 # EOM(2)
41+
.byte 4 # Abbreviation Code
42+
.byte 36 # DW_TAG_base_type
43+
.byte 0 # DW_CHILDREN_no
44+
.byte 3 # DW_AT_name
45+
.byte 14 # DW_FORM_strp
46+
.byte 62 # DW_AT_encoding
47+
.byte 11 # DW_FORM_data1
48+
.byte 11 # DW_AT_byte_size
49+
.byte 11 # DW_FORM_data1
50+
.byte 0 # EOM(1)
51+
.byte 0 # EOM(2)
52+
.byte 6 # Abbreviation Code
53+
.byte 46 # DW_TAG_subprogram
54+
.byte 1 # DW_CHILDREN_yes
55+
.byte 17 # DW_AT_low_pc
56+
.byte 1 # DW_FORM_addr
57+
.byte 18 # DW_AT_high_pc
58+
.byte 6 # DW_FORM_data4
59+
.byte 64 # DW_AT_frame_base
60+
.byte 24 # DW_FORM_exprloc
61+
.byte 3 # DW_AT_name
62+
.byte 14 # DW_FORM_strp
63+
.byte 58 # DW_AT_decl_file
64+
.byte 11 # DW_FORM_data1
65+
.byte 59 # DW_AT_decl_line
66+
.byte 11 # DW_FORM_data1
67+
.byte 73 # DW_AT_type
68+
.byte 19 # DW_FORM_ref4
69+
.byte 63 # DW_AT_external
70+
.byte 25 # DW_FORM_flag_present
71+
.byte 0 # EOM(1)
72+
.byte 0 # EOM(2)
73+
.byte 7 # Abbreviation Code
74+
.byte 29 # DW_TAG_inlined_subroutine
75+
.byte 1 # DW_CHILDREN_yes
76+
.byte 49 # DW_AT_abstract_origin
77+
.byte 0x10 # DW_FORM_ref_addr
78+
.byte 17 # DW_AT_low_pc
79+
.byte 1 # DW_FORM_addr
80+
.byte 18 # DW_AT_high_pc
81+
.byte 6 # DW_FORM_data4
82+
.byte 88 # DW_AT_call_file
83+
.byte 11 # DW_FORM_data1
84+
.byte 89 # DW_AT_call_line
85+
.byte 11 # DW_FORM_data1
86+
.byte 87 # DW_AT_call_column
87+
.byte 11 # DW_FORM_data1
88+
.byte 0 # EOM(1)
89+
.byte 0 # EOM(2)
90+
.byte 8 # Abbreviation Code
91+
.byte 52 # DW_TAG_variable
92+
.byte 0 # DW_CHILDREN_no
93+
.byte 2 # DW_AT_location
94+
.byte 24 # DW_FORM_exprloc
95+
.byte 49 # DW_AT_abstract_origin
96+
.byte 0x10 # DW_FORM_ref_addr
97+
.byte 0 # EOM(1)
98+
.byte 0 # EOM(2)
99+
.byte 0 # EOM(3)
100+
.section .debug_info,"",@progbits
101+
.Lcu_begin0:
102+
.long .Ldebug_info_end0-.Ldebug_info_start0 # Length of Unit
103+
.Ldebug_info_start0:
104+
.short 4 # DWARF version number
105+
.long .debug_abbrev # Offset Into Abbrev. Section
106+
.byte 8 # Address Size (in bytes)
107+
.byte 1 # Abbrev [1] DW_TAG_compile_unit
108+
.long .Linfo_string0 # DW_AT_producer
109+
.short 0xc # DW_AT_language
110+
.long .Linfo_string1 # DW_AT_name
111+
.long .Lline_table_start0 # DW_AT_stmt_list
112+
.long .Linfo_string2 # DW_AT_comp_dir
113+
.quad .Lfunc_begin0 # DW_AT_low_pc
114+
.long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
115+
.Ltype_int:
116+
.byte 4 # Abbrev [4] DW_TAG_base_type
117+
.long .Linfo_string5 # DW_AT_name
118+
.byte 5 # DW_AT_encoding
119+
.byte 4 # DW_AT_byte_size
120+
.byte 6 # Abbrev [6] DW_TAG_subprogram
121+
.quad .Lfunc_begin0 # DW_AT_low_pc
122+
.long .Lfunc_end0-.Lfunc_begin0 # DW_AT_high_pc
123+
.byte 1 # DW_AT_frame_base
124+
.byte 86
125+
.long .Linfo_string8 # DW_AT_name
126+
.byte 1 # DW_AT_decl_file
127+
.byte 3 # DW_AT_decl_line
128+
.long .Ltype_int-.Lcu_begin0 # DW_AT_type
129+
# DW_AT_external
130+
.byte 7 # Abbrev [7] DW_TAG_inlined_subroutine
131+
.long debuginfo_func_inlined # DW_AT_abstract_origin
132+
.quad .Ltmp0 # DW_AT_low_pc
133+
.long .Ltmp1-.Ltmp0 # DW_AT_high_pc
134+
.byte 1 # DW_AT_call_file
135+
.byte 3 # DW_AT_call_line
136+
.byte 48 # DW_AT_call_column
137+
.byte 8 # Abbrev [8] DW_TAG_variable
138+
.byte 2 # DW_AT_location
139+
.byte 145
140+
.byte 124
141+
.long debuginfo_var_var # DW_AT_abstract_origin
142+
.byte 0 # End Of Children Mark
143+
.byte 0 # End Of Children Mark
144+
.byte 0 # End Of Children Mark
145+
.Ldebug_info_end0:
146+
.section .debug_str,"MS",@progbits,1
147+
.Linfo_string0:
148+
.asciz "clang version 11.0.0 + hand coding"
149+
.Linfo_string1:
150+
.asciz "inlinevar2.c"
151+
.Linfo_string2:
152+
.asciz ""
153+
.Linfo_string5:
154+
.asciz "int"
155+
.Linfo_string8:
156+
.asciz "other"
157+
.section ".note.GNU-stack","",@progbits
158+
.addrsig
159+
.section .debug_line,"",@progbits
160+
.Lline_table_start0:

0 commit comments

Comments
 (0)