1# Copyright 2014-2024 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/>.
15load_lib dwarf.exp
16
17# This test can only be run on targets which support DWARF-2 and use gas.
18require dwarf2_support
19
20standard_testfile .c -dw.S
21
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.
24#
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.
28
29if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
30    return -1
31}
32
33# Make some DWARF for the test.
34set asm_file [standard_output_file $srcfile2]
35Dwarf::assemble $asm_file {
36    cu {} {
37          DW_TAG_compile_unit {
38                {DW_AT_language @DW_LANG_Ada95}
39                {DW_AT_name     foo.adb}
40                {DW_AT_comp_dir /tmp}
41        } {
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]
45
46            integer_label: DW_TAG_base_type {
47                {DW_AT_byte_size $int_size DW_FORM_sdata}
48                {DW_AT_encoding  @DW_ATE_signed}
49                {DW_AT_name      integer}
50            }
51
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
57                    DW_OP_deref
58                } SPECIAL_expr}
59                {external 1 flag}
60              } {
61                    DW_TAG_subrange_type {
62                        {DW_AT_type        :$integer_label}
63                    {DW_AT_lower_bound {
64                        DW_OP_push_object_address
65                        DW_OP_plus_uconst $voidp_size
66                        DW_OP_deref
67                        DW_OP_deref_size $int_size
68                    } SPECIAL_expr}
69                    {DW_AT_upper_bound {
70                        DW_OP_push_object_address
71                        DW_OP_plus_uconst $voidp_size
72                        DW_OP_deref
73                        DW_OP_plus_uconst $int_size
74                        DW_OP_deref_size $int_size
75                    } SPECIAL_expr}
76                    }
77              }
78            array_ptr_label: DW_TAG_typedef {
79                {DW_AT_name foo__array_type}
80                {DW_AT_type :$array_label}
81            }
82            DW_TAG_variable {
83                {DW_AT_name foo__three}
84                {DW_AT_type :$array_label}
85                {DW_AT_location {
86                    DW_OP_addr [gdb_target_symbol table_1]
87                } SPECIAL_expr}
88                {external 1 flag}
89            }
90            DW_TAG_variable {
91                {DW_AT_name foo__three_tdef}
92                {DW_AT_type :$array_ptr_label}
93                {DW_AT_location {
94                    DW_OP_addr [gdb_target_symbol table_1]
95                } SPECIAL_expr}
96                {external 1 flag}
97            }
98            DW_TAG_variable {
99                {DW_AT_name foo__five}
100                {DW_AT_type :$array_label}
101                {DW_AT_location {
102                    DW_OP_addr [gdb_target_symbol table_2]
103                } SPECIAL_expr}
104                {external 1 flag}
105            }
106            DW_TAG_variable {
107                {DW_AT_name foo__five_tdef}
108                {DW_AT_type :$array_ptr_label}
109                {DW_AT_location {
110                    DW_OP_addr [gdb_target_symbol table_2]
111                } SPECIAL_expr}
112                {external 1 flag}
113            }
114          }
115    }
116}
117
118# Now that we've generated the DWARF debugging info, rebuild our
119# program using our debug info instead of the info generated by
120# the compiler.
121
122if { [prepare_for_testing "failed to prepare" ${testfile} \
123            [list $srcfile $asm_file] {nodebug}] } {
124    return -1
125}
126
127if ![runto_main] {
128    return -1
129}
130
131gdb_test_no_output "set language ada"
132
133# foo.three
134
135gdb_test "print foo.three" \
136         " = \\(1, 2, 3\\)"
137
138gdb_test "ptype foo.three" \
139         "type = array \\(<>\\) of integer"
140
141gdb_test "print foo.three(1)" \
142         " = 1"
143
144gdb_test "print foo.three(2)" \
145         " = 2"
146
147gdb_test "print foo.three(3)" \
148         " = 3"
149
150gdb_test "print foo.three'first" \
151         " = 1"
152
153gdb_test "print foo.three'last" \
154         " = 3"
155
156gdb_test "print foo.three'length" \
157         " = 3"
158
159# foo.three_tdef
160
161gdb_test "print foo.three_tdef.all" \
162         " = \\(1, 2, 3\\)"
163
164gdb_test "ptype foo.three_tdef" \
165         "type = access array \\(<>\\) of integer"
166
167gdb_test "print foo.three_tdef(1)" \
168         " = 1"
169
170gdb_test "print foo.three_tdef(2)" \
171         " = 2"
172
173gdb_test "print foo.three_tdef(3)" \
174         " = 3"
175
176gdb_test "print foo.three_tdef'first" \
177         " = 1"
178
179gdb_test "print foo.three_tdef'last" \
180         " = 3"
181
182gdb_test "print foo.three_tdef'length" \
183         " = 3"
184
185gdb_test "print foo.five" \
186         " = \\(2 => 5, 8, 13, 21, 34\\)"
187
188gdb_test "ptype foo.five" \
189         "type = array \\(<>\\) of integer"
190
191gdb_test "ptype foo.array_type" \
192         "type = array \\(<>\\) of integer"
193
194# foo.five
195
196gdb_test "print foo.five(2)" \
197         " = 5"
198
199gdb_test "print foo.five(3)" \
200         " = 8"
201
202gdb_test "print foo.five(4)" \
203         " = 13"
204
205gdb_test "print foo.five(5)" \
206         " = 21"
207
208gdb_test "print foo.five(6)" \
209         " = 34"
210
211gdb_test "print foo.five'first" \
212         " = 2"
213
214gdb_test "print foo.five'last" \
215         " = 6"
216
217gdb_test "print foo.five'length" \
218         " = 5"
219
220# foo.five_tdef
221
222gdb_test "print foo.five_tdef.all" \
223         " = \\(2 => 5, 8, 13, 21, 34\\)"
224
225gdb_test "ptype foo.five_tdef" \
226         "type = access array \\(<>\\) of integer"
227
228gdb_test "print foo.five_tdef(2)" \
229         " = 5"
230
231gdb_test "print foo.five_tdef(3)" \
232         " = 8"
233
234gdb_test "print foo.five_tdef(4)" \
235         " = 13"
236
237gdb_test "print foo.five_tdef(5)" \
238         " = 21"
239
240gdb_test "print foo.five_tdef(6)" \
241         " = 34"
242
243gdb_test "print foo.five_tdef'first" \
244         " = 2"
245
246gdb_test "print foo.five_tdef'last" \
247         " = 6"
248
249gdb_test "print foo.five_tdef'length" \
250         " = 5"
251