573324af3d17ea2e84330c54ed77710feb6cf5a0
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / loclists-sec-offset.exp
1 # Copyright 2020 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 # Test DW_AT_location attributes referencing the .debug_loclists section using
17 # the DW_FORM_sec_offset form.
18
19 load_lib dwarf.exp
20
21 if {![dwarf2_support]} {
22 return 0
23 }
24
25 # Test with 32-bit and 64-bit DWARF.
26 foreach_with_prefix is_64 {false true} {
27 if { $is_64 } {
28 standard_testfile .c -dw64.S
29 set testfile ${testfile}-dw64
30 } else {
31 standard_testfile .c -dw32.S
32 set testfile ${testfile}-dw32
33 }
34
35 # Get the addresses / lengths of functions.
36 lassign [function_range func1 $srcdir/$subdir/$srcfile] func1_addr func1_len
37 lassign [function_range func2 $srcdir/$subdir/$srcfile] func2_addr func2_len
38 lassign [function_range func3 $srcdir/$subdir/$srcfile] func3_addr func3_len
39 lassign [function_range func4 $srcdir/$subdir/$srcfile] func4_addr func4_len
40 lassign [function_range func5 $srcdir/$subdir/$srcfile] func5_addr func5_len
41 lassign [function_range func6 $srcdir/$subdir/$srcfile] func6_addr func6_len
42
43 set asm_file [standard_output_file $srcfile2]
44 Dwarf::assemble $asm_file {
45 global func1_addr func1_len
46 global func2_addr func2_len
47 global func3_addr func3_len
48 global func4_addr func4_len
49 global func5_addr func5_len
50 global func6_addr func6_len
51 global is_64
52
53 declare_labels cu_range_list foo_range_list
54
55 # This CU uses the DW_FORM_sec_offset form to refer to the .debug_rnglists
56 # section.
57 cu {
58 version 5
59 is_64 $is_64
60 } {
61 declare_labels int_type1
62 declare_labels int_type2
63 declare_labels int_type3
64 declare_labels foo_location_list
65 declare_labels bar_location_list
66 declare_labels baz_location_list
67
68 DW_TAG_compile_unit {
69 } {
70 int_type1: DW_TAG_base_type {
71 {DW_AT_byte_size 4 DW_FORM_data1}
72 {DW_AT_encoding @DW_ATE_signed}
73 {DW_AT_name "int"}
74 }
75
76 DW_TAG_variable {
77 {DW_AT_name "foo"}
78 {DW_AT_location $foo_location_list DW_FORM_sec_offset}
79 {DW_AT_type :$int_type1}
80 }
81
82 DW_TAG_subprogram {
83 {DW_AT_name "func1"}
84 {DW_AT_low_pc $func1_addr}
85 {DW_AT_high_pc $func1_len DW_FORM_udata}
86 }
87
88 DW_TAG_subprogram {
89 {DW_AT_name "func2"}
90 {DW_AT_low_pc $func2_addr}
91 {DW_AT_high_pc $func2_len DW_FORM_udata}
92 }
93 }
94 }
95
96 # This CU uses the DW_FORM_sec_offset form to refer to the
97 # .debug_loclists section, but also has the DW_AT_loclists_base
98 # attribute present. The DW_AT_loclists_base is not used to interpret
99 # the DW_AT_location value, but it should also do no harm.
100 cu {
101 version 5
102 is_64 $is_64
103 } {
104 DW_TAG_compile_unit {
105 {DW_AT_loclists_base cu2_table DW_FORM_sec_offset}
106 } {
107 int_type2: DW_TAG_base_type {
108 {DW_AT_byte_size 4 DW_FORM_data1}
109 {DW_AT_encoding @DW_ATE_signed}
110 {DW_AT_name "int"}
111 }
112
113 DW_TAG_variable {
114 {DW_AT_name "bar"}
115 {DW_AT_location $bar_location_list DW_FORM_sec_offset}
116 {DW_AT_type :$int_type2}
117 }
118
119 DW_TAG_subprogram {
120 {DW_AT_name "func3"}
121 {DW_AT_low_pc $func3_addr}
122 {DW_AT_high_pc $func3_len DW_FORM_udata}
123 }
124
125 DW_TAG_subprogram {
126 {DW_AT_name "func4"}
127 {DW_AT_low_pc $func4_addr}
128 {DW_AT_high_pc $func4_len DW_FORM_udata}
129 }
130 }
131 }
132
133 # This CU uses the DW_FORM_sec_offset form to refer to the
134 # .debug_loclists section. The corresponding contribution in the
135 # .debug_loclists section has no offset array.
136 cu {
137 version 5
138 is_64 $is_64
139 } {
140 DW_TAG_compile_unit {
141 } {
142 int_type3: DW_TAG_base_type {
143 {DW_AT_byte_size 4 DW_FORM_data1}
144 {DW_AT_encoding @DW_ATE_signed}
145 {DW_AT_name "int"}
146 }
147
148 DW_TAG_variable {
149 {DW_AT_name "baz"}
150 {DW_AT_location $baz_location_list DW_FORM_sec_offset}
151 {DW_AT_type :$int_type3}
152 }
153
154 DW_TAG_subprogram {
155 {DW_AT_name "func5"}
156 {DW_AT_low_pc $func5_addr}
157 {DW_AT_high_pc $func5_len DW_FORM_udata}
158 }
159
160 DW_TAG_subprogram {
161 {DW_AT_name "func6"}
162 {DW_AT_low_pc $func6_addr}
163 {DW_AT_high_pc $func6_len DW_FORM_udata}
164 }
165 }
166 }
167
168 loclists -is-64 $is_64 {
169 # The lists in this table are accessed by direct offset
170 # (DW_FORM_sec_offset).
171 table {
172 foo_location_list: list_ {
173 start_length $func1_addr $func1_len {
174 DW_OP_constu 0x123456
175 DW_OP_stack_value
176 }
177
178 start_length $func2_addr $func2_len {
179 DW_OP_constu 0x234567
180 DW_OP_stack_value
181 }
182 }
183 }
184
185 table -post-header-label cu2_table {
186 bar_location_list: list_ {
187 start_length $func3_addr $func3_len {
188 DW_OP_constu 0x345678
189 DW_OP_stack_value
190 }
191
192 start_length $func4_addr $func4_len {
193 DW_OP_constu 0x456789
194 DW_OP_stack_value
195 }
196 }
197 }
198
199 table -with-offset-array false {
200 baz_location_list: list_ {
201 start_length $func5_addr $func5_len {
202 DW_OP_constu 0x567890
203 DW_OP_stack_value
204 }
205
206 start_length $func6_addr $func6_len {
207 DW_OP_constu 0x678901
208 DW_OP_stack_value
209 }
210 }
211 }
212 }
213 }
214
215 if { [prepare_for_testing "failed to prepare" ${testfile} \
216 [list $srcfile $asm_file] {nodebug}] } {
217 return -1
218 }
219
220 if { ![runto_main] } {
221 fail "can't run to main"
222 return
223 }
224
225 gdb_breakpoint "func1"
226 gdb_breakpoint "func2"
227 gdb_breakpoint "func3"
228 gdb_breakpoint "func4"
229 gdb_breakpoint "func5"
230 gdb_breakpoint "func6"
231
232 gdb_continue_to_breakpoint "func1"
233 with_test_prefix "at func1" {
234 gdb_test "print /x foo" " = 0x123456"
235 }
236
237 gdb_continue_to_breakpoint "func2"
238 with_test_prefix "at func2" {
239 gdb_test "print /x foo" " = 0x234567"
240 }
241
242 gdb_continue_to_breakpoint "func3"
243 with_test_prefix "at func3" {
244 gdb_test "print /x bar" " = 0x345678"
245 }
246
247 gdb_continue_to_breakpoint "func4"
248 with_test_prefix "at func4" {
249 gdb_test "print /x bar" " = 0x456789"
250 }
251
252 gdb_continue_to_breakpoint "func5"
253 with_test_prefix "at func5" {
254 gdb_test "print /x baz" " = 0x567890"
255 }
256
257 gdb_continue_to_breakpoint "func6"
258 with_test_prefix "at func6" {
259 gdb_test "print /x baz" " = 0x678901"
260 }
261 }
This page took 0.036052 seconds and 3 git commands to generate.