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 data-loc.c program.
26 # Any program would do, but since we already have data-loc.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
43 set int_size [get_sizeof "int" 4]
44 set voidp_size [get_sizeof "void *" 96]
46 integer_label: DW_TAG_base_type {
47 {DW_AT_byte_size $int_size DW_FORM_sdata}
48 {DW_AT_encoding @DW_ATE_signed}
52 array_label: DW_TAG_array_type {
53 {DW_AT_name foo__array_type}
54 {DW_AT_type :$integer_label}
55 {DW_AT_data_location {
56 DW_OP_push_object_address
61 DW_TAG_subrange_type {
62 {DW_AT_type :$integer_label}
64 DW_OP_push_object_address
65 DW_OP_plus_uconst $voidp_size
67 DW_OP_deref_size $int_size
70 DW_OP_push_object_address
71 DW_OP_plus_uconst $voidp_size
73 DW_OP_plus_uconst $int_size
74 DW_OP_deref_size $int_size
78 array_ptr_label: DW_TAG_typedef {
79 {DW_AT_name foo__array_type}
80 {DW_AT_type :$array_label}
83 {DW_AT_name foo__three}
84 {DW_AT_type :$array_label}
86 DW_OP_addr [gdb_target_symbol table_1]
91 {DW_AT_name foo__three_tdef}
92 {DW_AT_type :$array_ptr_label}
94 DW_OP_addr [gdb_target_symbol table_1]
99 {DW_AT_name foo__five}
100 {DW_AT_type :$array_label}
102 DW_OP_addr [gdb_target_symbol table_2]
107 {DW_AT_name foo__five_tdef}
108 {DW_AT_type :$array_ptr_label}
110 DW_OP_addr [gdb_target_symbol table_2]
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" \
138 gdb_test "ptype foo.three" \
139 "type = array \\(<>\\) of integer"
141 gdb_test "print foo.three(1)" \
144 gdb_test "print foo.three(2)" \
147 gdb_test "print foo.three(3)" \
150 gdb_test "print foo.three'first" \
153 gdb_test "print foo.three'last" \
156 gdb_test "print foo.three'length" \
161 gdb_test "print foo.three_tdef.all" \
164 gdb_test "ptype foo.three_tdef" \
165 "type = access array \\(<>\\) of integer"
167 gdb_test "print foo.three_tdef(1)" \
170 gdb_test "print foo.three_tdef(2)" \
173 gdb_test "print foo.three_tdef(3)" \
176 gdb_test "print foo.three_tdef'first" \
179 gdb_test "print foo.three_tdef'last" \
182 gdb_test "print foo.three_tdef'length" \
185 gdb_test "print foo.five" \
186 " = \\(2 => 5, 8, 13, 21, 34\\)"
188 gdb_test "ptype foo.five" \
189 "type = array \\(<>\\) of integer"
191 gdb_test "ptype foo.array_type" \
192 "type = array \\(<>\\) of integer"
196 gdb_test "print foo.five(2)" \
199 gdb_test "print foo.five(3)" \
202 gdb_test "print foo.five(4)" \
205 gdb_test "print foo.five(5)" \
208 gdb_test "print foo.five(6)" \
211 gdb_test "print foo.five'first" \
214 gdb_test "print foo.five'last" \
217 gdb_test "print foo.five'length" \
222 gdb_test "print foo.five_tdef.all" \
223 " = \\(2 => 5, 8, 13, 21, 34\\)"
225 gdb_test "ptype foo.five_tdef" \
226 "type = access array \\(<>\\) of integer"
228 gdb_test "print foo.five_tdef(2)" \
231 gdb_test "print foo.five_tdef(3)" \
234 gdb_test "print foo.five_tdef(4)" \
237 gdb_test "print foo.five_tdef(5)" \
240 gdb_test "print foo.five_tdef(6)" \
243 gdb_test "print foo.five_tdef'first" \
246 gdb_test "print foo.five_tdef'last" \
249 gdb_test "print foo.five_tdef'length" \