1 # Copyright 2014-2019 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 if {![dwarf2_support]} {
22 standard_testfile dynarr-ptr.c dynarr-ptr-dw.S
24 # We need to know the size of integer and address types in order
25 # to write some of the debugging info we'd like to generate.
27 # For that, we ask GDB by debugging our dynarr-ptr.c program.
28 # Any program would do, but since we already have dynarr-ptr.c
29 # specifically for this testcase, might as well use that.
31 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
35 # Make some DWARF for the test.
36 set asm_file [standard_output_file $srcfile2]
37 Dwarf::assemble $asm_file {
40 {DW_AT_language @DW_LANG_Ada95}
44 declare_labels integer_label array_label array_ptr_label \
46 set ptr_size [get_sizeof "void *" 96]
47 set int_size [get_sizeof "int" 4]
49 integer_label: DW_TAG_base_type {
50 {DW_AT_byte_size $int_size DW_FORM_sdata}
51 {DW_AT_encoding @DW_ATE_signed}
55 array_label: DW_TAG_array_type {
56 {DW_AT_name foo__array_type}
57 {DW_AT_type :$integer_label}
60 DW_TAG_subrange_type {
61 {DW_AT_type :$integer_label}
63 DW_OP_push_object_address
64 DW_OP_const1u [expr {2 * $int_size}]
66 DW_OP_deref_size $int_size
69 DW_OP_push_object_address
70 DW_OP_const1u $int_size
72 DW_OP_deref_size $int_size
76 array_ptr_label: DW_TAG_pointer_type {
77 {DW_AT_byte_size $ptr_size DW_FORM_data1}
78 {DW_AT_type :$array_label}
80 array_typedef_label: DW_TAG_typedef {
81 {DW_AT_name "foo__array_ptr"}
82 {DW_AT_type :$array_ptr_label}
85 {DW_AT_name foo__three_ptr}
86 {DW_AT_type :$array_ptr_label}
88 DW_OP_addr [gdb_target_symbol table_1_ptr]
93 {DW_AT_name foo__three_ptr_tdef}
94 {DW_AT_type :$array_typedef_label}
96 DW_OP_addr [gdb_target_symbol table_1_ptr]
101 {DW_AT_name foo__five_ptr}
102 {DW_AT_type :$array_ptr_label}
104 DW_OP_addr [gdb_target_symbol table_2_ptr]
109 {DW_AT_name foo__five_ptr_tdef}
110 {DW_AT_type :$array_typedef_label}
112 DW_OP_addr [gdb_target_symbol table_2_ptr]
120 # Now that we've generated the DWARF debugging info, rebuild our
121 # program using our debug info instead of the info generated by
124 if { [prepare_for_testing "failed to prepare" ${testfile} \
125 [list $srcfile $asm_file] {nodebug}] } {
133 gdb_test_no_output "set language ada"
137 gdb_test "print foo.three_ptr.all" \
140 gdb_test "print foo.three_ptr.all(1)" \
143 gdb_test "print foo.three_ptr.all(2)" \
146 gdb_test "print foo.three_ptr.all(3)" \
149 gdb_test "print foo.three_ptr.all'first" \
152 gdb_test "print foo.three_ptr.all'last" \
155 gdb_test "print foo.three_ptr.all'length" \
158 gdb_test "ptype foo.three_ptr.all" \
159 " = array \\(<>\\) of integer"
163 gdb_test "print foo.three_ptr(1)" \
166 gdb_test "print foo.three_ptr(2)" \
169 gdb_test "print foo.three_ptr(3)" \
172 gdb_test "print foo.three_ptr'first" \
175 gdb_test "print foo.three_ptr'last" \
178 gdb_test "print foo.three_ptr'length" \
181 gdb_test "ptype foo.three_ptr" \
182 " = access array \\(<>\\) of integer"
184 # foo.three_ptr_tdef.all
186 gdb_test "print foo.three_ptr_tdef.all" \
189 gdb_test "print foo.three_ptr_tdef.all(1)" \
192 gdb_test "print foo.three_ptr_tdef.all(2)" \
195 gdb_test "print foo.three_ptr_tdef.all(3)" \
198 gdb_test "print foo.three_ptr_tdef.all'first" \
201 gdb_test "print foo.three_ptr_tdef.all'last" \
204 gdb_test "print foo.three_ptr_tdef.all'length" \
207 gdb_test "ptype foo.three_ptr_tdef.all" \
208 " = array \\(<>\\) of integer"
212 gdb_test "print foo.three_ptr_tdef(1)" \
215 gdb_test "print foo.three_ptr_tdef(2)" \
218 gdb_test "print foo.three_ptr_tdef(3)" \
221 gdb_test "print foo.three_ptr_tdef'first" \
224 gdb_test "print foo.three_ptr_tdef'last" \
227 gdb_test "print foo.three_ptr_tdef'length" \
230 gdb_test "ptype foo.three_ptr_tdef" \
231 " = access array \\(<>\\) of integer"
235 gdb_test "print foo.five_ptr.all" \
236 " = \\(2 => 5, 8, 13, 21, 34\\)"
238 gdb_test "print foo.five_ptr.all(2)" \
241 gdb_test "print foo.five_ptr.all(3)" \
244 gdb_test "print foo.five_ptr.all(4)" \
247 gdb_test "print foo.five_ptr.all(5)" \
250 gdb_test "print foo.five_ptr.all(6)" \
253 gdb_test "print foo.five_ptr.all'first" \
256 gdb_test "print foo.five_ptr.all'last" \
259 gdb_test "print foo.five_ptr.all'length" \
262 gdb_test "ptype foo.five_ptr.all" \
263 " = array \\(<>\\) of integer"
267 gdb_test "print foo.five_ptr(2)" \
270 gdb_test "print foo.five_ptr(3)" \
273 gdb_test "print foo.five_ptr(4)" \
276 gdb_test "print foo.five_ptr(5)" \
279 gdb_test "print foo.five_ptr(6)" \
282 gdb_test "print foo.five_ptr'first" \
285 gdb_test "print foo.five_ptr'last" \
288 gdb_test "print foo.five_ptr'length" \
291 gdb_test "ptype foo.five_ptr" \
292 " = access array \\(<>\\) of integer"
294 # foo.five_ptr_tdef.all
296 gdb_test "print foo.five_ptr_tdef.all" \
297 " = \\(2 => 5, 8, 13, 21, 34\\)"
299 gdb_test "print foo.five_ptr_tdef.all(2)" \
302 gdb_test "print foo.five_ptr_tdef.all(3)" \
305 gdb_test "print foo.five_ptr_tdef.all(4)" \
308 gdb_test "print foo.five_ptr_tdef.all(5)" \
311 gdb_test "print foo.five_ptr_tdef.all(6)" \
314 gdb_test "print foo.five_ptr_tdef.all'first" \
317 gdb_test "print foo.five_ptr_tdef.all'last" \
320 gdb_test "print foo.five_ptr_tdef.all'length" \
323 gdb_test "ptype foo.five_ptr_tdef.all" \
324 " = array \\(<>\\) of integer"
328 gdb_test "print foo.five_ptr_tdef(2)" \
331 gdb_test "print foo.five_ptr_tdef(3)" \
334 gdb_test "print foo.five_ptr_tdef(4)" \
337 gdb_test "print foo.five_ptr_tdef(5)" \
340 gdb_test "print foo.five_ptr_tdef(6)" \
343 gdb_test "print foo.five_ptr_tdef'first" \
346 gdb_test "print foo.five_ptr_tdef'last" \
349 gdb_test "print foo.five_ptr_tdef'length" \
352 gdb_test "ptype foo.five_ptr_tdef" \
353 " = access array \\(<>\\) of integer"