1 # Copyright 2014-2024 Free Software Foundation, Inc.
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.
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.
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/>.
17 # This test can only be run on targets which support DWARF-2 and use gas.
18 require dwarf2_support
20 standard_testfile .c -dw.S
22 # We need to know the size of integer and address types in order
23 # to write some of the debugging info we'd like to generate.
25 # For that, we ask GDB by debugging our dynarr-ptr.c program.
26 # Any program would do, but since we already have dynarr-ptr.c
27 # specifically for this testcase, might as well use that.
29 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
33 # Make some DWARF for the test.
34 set asm_file [standard_output_file $srcfile2]
35 Dwarf::assemble $asm_file {
38 {DW_AT_language @DW_LANG_Ada95}
42 declare_labels integer_label array_label array_ptr_label \
44 set ptr_size [get_sizeof "void *" 96]
45 set int_size [get_sizeof "int" 4]
47 integer_label: DW_TAG_base_type {
48 {DW_AT_byte_size $int_size DW_FORM_sdata}
49 {DW_AT_encoding @DW_ATE_signed}
53 array_label: DW_TAG_array_type {
54 {DW_AT_name foo__array_type}
55 {DW_AT_type :$integer_label}
58 DW_TAG_subrange_type {
59 {DW_AT_type :$integer_label}
61 DW_OP_push_object_address
62 DW_OP_const1u [expr {2 * $int_size}]
64 DW_OP_deref_size $int_size
67 DW_OP_push_object_address
68 DW_OP_const1u $int_size
70 DW_OP_deref_size $int_size
74 array_ptr_label: DW_TAG_pointer_type {
75 {DW_AT_byte_size $ptr_size DW_FORM_data1}
76 {DW_AT_type :$array_label}
78 array_typedef_label: DW_TAG_typedef {
79 {DW_AT_name "foo__array_ptr"}
80 {DW_AT_type :$array_ptr_label}
83 {DW_AT_name foo__three_ptr}
84 {DW_AT_type :$array_ptr_label}
86 DW_OP_addr [gdb_target_symbol table_1_ptr]
91 {DW_AT_name foo__three_ptr_tdef}
92 {DW_AT_type :$array_typedef_label}
94 DW_OP_addr [gdb_target_symbol table_1_ptr]
99 {DW_AT_name foo__five_ptr}
100 {DW_AT_type :$array_ptr_label}
102 DW_OP_addr [gdb_target_symbol table_2_ptr]
107 {DW_AT_name foo__five_ptr_tdef}
108 {DW_AT_type :$array_typedef_label}
110 DW_OP_addr [gdb_target_symbol table_2_ptr]
118 # Now that we've generated the DWARF debugging info, rebuild our
119 # program using our debug info instead of the info generated by
122 if { [prepare_for_testing "failed to prepare" ${testfile} \
123 [list $srcfile $asm_file] {nodebug}] } {
131 gdb_test_no_output "set language ada"
135 gdb_test "print foo.three_ptr.all" \
138 gdb_test "print foo.three_ptr.all(1)" \
141 gdb_test "print foo.three_ptr.all(2)" \
144 gdb_test "print foo.three_ptr.all(3)" \
147 gdb_test "print foo.three_ptr.all'first" \
150 gdb_test "print foo.three_ptr.all'last" \
153 gdb_test "print foo.three_ptr.all'length" \
156 gdb_test "ptype foo.three_ptr.all" \
157 " = array \\(1 \\.\\. 3\\) of integer"
161 gdb_test "print foo.three_ptr(1)" \
164 gdb_test "print foo.three_ptr(2)" \
167 gdb_test "print foo.three_ptr(3)" \
170 gdb_test "print foo.three_ptr'first" \
173 gdb_test "print foo.three_ptr'last" \
176 gdb_test "print foo.three_ptr'length" \
179 gdb_test "ptype foo.three_ptr" \
180 " = access array \\(1 \\.\\. 3\\) of integer"
182 # foo.three_ptr_tdef.all
184 gdb_test "print foo.three_ptr_tdef.all" \
187 gdb_test "print foo.three_ptr_tdef.all(1)" \
190 gdb_test "print foo.three_ptr_tdef.all(2)" \
193 gdb_test "print foo.three_ptr_tdef.all(3)" \
196 gdb_test "print foo.three_ptr_tdef.all'first" \
199 gdb_test "print foo.three_ptr_tdef.all'last" \
202 gdb_test "print foo.three_ptr_tdef.all'length" \
205 gdb_test "ptype foo.three_ptr_tdef.all" \
206 " = array \\(1 \\.\\. 3\\) of integer"
210 gdb_test "print foo.three_ptr_tdef(1)" \
213 gdb_test "print foo.three_ptr_tdef(2)" \
216 gdb_test "print foo.three_ptr_tdef(3)" \
219 gdb_test "print foo.three_ptr_tdef'first" \
222 gdb_test "print foo.three_ptr_tdef'last" \
225 gdb_test "print foo.three_ptr_tdef'length" \
228 gdb_test "ptype foo.three_ptr_tdef" \
229 " = access array \\(1 \\.\\. 3\\) of integer"
233 gdb_test "print foo.five_ptr.all" \
234 " = \\(2 => 5, 8, 13, 21, 34\\)"
236 gdb_test "print foo.five_ptr.all(2)" \
239 gdb_test "print foo.five_ptr.all(3)" \
242 gdb_test "print foo.five_ptr.all(4)" \
245 gdb_test "print foo.five_ptr.all(5)" \
248 gdb_test "print foo.five_ptr.all(6)" \
251 gdb_test "print foo.five_ptr.all'first" \
254 gdb_test "print foo.five_ptr.all'last" \
257 gdb_test "print foo.five_ptr.all'length" \
260 gdb_test "ptype foo.five_ptr.all" \
261 " = array \\(2 \\.\\. 6\\) of integer"
265 gdb_test "print foo.five_ptr(2)" \
268 gdb_test "print foo.five_ptr(3)" \
271 gdb_test "print foo.five_ptr(4)" \
274 gdb_test "print foo.five_ptr(5)" \
277 gdb_test "print foo.five_ptr(6)" \
280 gdb_test "print foo.five_ptr'first" \
283 gdb_test "print foo.five_ptr'last" \
286 gdb_test "print foo.five_ptr'length" \
289 gdb_test "ptype foo.five_ptr" \
290 " = access array \\(2 \\.\\. 6\\) of integer"
292 # foo.five_ptr_tdef.all
294 gdb_test "print foo.five_ptr_tdef.all" \
295 " = \\(2 => 5, 8, 13, 21, 34\\)"
297 gdb_test "print foo.five_ptr_tdef.all(2)" \
300 gdb_test "print foo.five_ptr_tdef.all(3)" \
303 gdb_test "print foo.five_ptr_tdef.all(4)" \
306 gdb_test "print foo.five_ptr_tdef.all(5)" \
309 gdb_test "print foo.five_ptr_tdef.all(6)" \
312 gdb_test "print foo.five_ptr_tdef.all'first" \
315 gdb_test "print foo.five_ptr_tdef.all'last" \
318 gdb_test "print foo.five_ptr_tdef.all'length" \
321 gdb_test "ptype foo.five_ptr_tdef.all" \
322 " = array \\(2 \\.\\. 6\\) of integer"
326 gdb_test "print foo.five_ptr_tdef(2)" \
329 gdb_test "print foo.five_ptr_tdef(3)" \
332 gdb_test "print foo.five_ptr_tdef(4)" \
335 gdb_test "print foo.five_ptr_tdef(5)" \
338 gdb_test "print foo.five_ptr_tdef(6)" \
341 gdb_test "print foo.five_ptr_tdef'first" \
344 gdb_test "print foo.five_ptr_tdef'last" \
347 gdb_test "print foo.five_ptr_tdef'length" \
350 gdb_test "ptype foo.five_ptr_tdef" \
351 " = access array \\(2 \\.\\. 6\\) of integer"