Add translations for various sub-directories
[binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / dynarr-ptr.exp
blob3b7fb72a927671fcdf053b29f6faddca51b4db52
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/>.
15 load_lib dwarf.exp
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}] } {
30     return -1
33 # Make some DWARF for the test.
34 set asm_file [standard_output_file $srcfile2]
35 Dwarf::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                 array_typedef_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}
50                 {DW_AT_name      integer}
51             }
53             array_label: DW_TAG_array_type {
54                 {DW_AT_name foo__array_type}
55                 {DW_AT_type :$integer_label}
56                 {external 1 flag}
57             } {
58                 DW_TAG_subrange_type {
59                     {DW_AT_type        :$integer_label}
60                     {DW_AT_lower_bound {
61                         DW_OP_push_object_address
62                         DW_OP_const1u [expr {2 * $int_size}]
63                         DW_OP_minus
64                         DW_OP_deref_size $int_size
65                     } SPECIAL_expr}
66                     {DW_AT_upper_bound {
67                         DW_OP_push_object_address
68                         DW_OP_const1u $int_size
69                         DW_OP_minus
70                         DW_OP_deref_size $int_size
71                     } SPECIAL_expr}
72                 }
73             }
74             array_ptr_label: DW_TAG_pointer_type {
75                 {DW_AT_byte_size $ptr_size DW_FORM_data1}
76                 {DW_AT_type :$array_label}
77             }
78             array_typedef_label: DW_TAG_typedef {
79                 {DW_AT_name "foo__array_ptr"}
80                 {DW_AT_type :$array_ptr_label}
81             }
82             DW_TAG_variable {
83                 {DW_AT_name foo__three_ptr}
84                 {DW_AT_type :$array_ptr_label}
85                 {DW_AT_location {
86                     DW_OP_addr [gdb_target_symbol table_1_ptr]
87                 } SPECIAL_expr}
88                 {external 1 flag}
89             }
90             DW_TAG_variable {
91                 {DW_AT_name foo__three_ptr_tdef}
92                 {DW_AT_type :$array_typedef_label}
93                 {DW_AT_location {
94                     DW_OP_addr [gdb_target_symbol table_1_ptr]
95                 } SPECIAL_expr}
96                 {external 1 flag}
97             }
98             DW_TAG_variable {
99                 {DW_AT_name foo__five_ptr}
100                 {DW_AT_type :$array_ptr_label}
101                 {DW_AT_location {
102                     DW_OP_addr [gdb_target_symbol table_2_ptr]
103                 } SPECIAL_expr}
104                 {external 1 flag}
105             }
106             DW_TAG_variable {
107                 {DW_AT_name foo__five_ptr_tdef}
108                 {DW_AT_type :$array_typedef_label}
109                 {DW_AT_location {
110                     DW_OP_addr [gdb_target_symbol table_2_ptr]
111                 } SPECIAL_expr}
112                 {external 1 flag}
113             }
114         }
115     }
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.
122 if { [prepare_for_testing "failed to prepare" ${testfile} \
123           [list $srcfile $asm_file] {nodebug}] } {
124     return -1
127 if ![runto_main] {
128     return -1
131 gdb_test_no_output "set language ada"
133 # foo.three_ptr.all
135 gdb_test "print foo.three_ptr.all" \
136     " = \\(1, 2, 3\\)"
138 gdb_test "print foo.three_ptr.all(1)" \
139     " = 1"
141 gdb_test "print foo.three_ptr.all(2)" \
142     " = 2"
144 gdb_test "print foo.three_ptr.all(3)" \
145     " = 3"
147 gdb_test "print foo.three_ptr.all'first" \
148     " = 1"
150 gdb_test "print foo.three_ptr.all'last" \
151     " = 3"
153 gdb_test "print foo.three_ptr.all'length" \
154     " = 3"
156 gdb_test "ptype foo.three_ptr.all" \
157     " = array \\(1 \\.\\. 3\\) of integer"
159 # foo.three_ptr
161 gdb_test "print foo.three_ptr(1)" \
162     " = 1"
164 gdb_test "print foo.three_ptr(2)" \
165     " = 2"
167 gdb_test "print foo.three_ptr(3)" \
168     " = 3"
170 gdb_test "print foo.three_ptr'first" \
171     " = 1"
173 gdb_test "print foo.three_ptr'last" \
174     " = 3"
176 gdb_test "print foo.three_ptr'length" \
177     " = 3"
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" \
185     " = \\(1, 2, 3\\)"
187 gdb_test "print foo.three_ptr_tdef.all(1)" \
188     " = 1"
190 gdb_test "print foo.three_ptr_tdef.all(2)" \
191     " = 2"
193 gdb_test "print foo.three_ptr_tdef.all(3)" \
194     " = 3"
196 gdb_test "print foo.three_ptr_tdef.all'first" \
197     " = 1"
199 gdb_test "print foo.three_ptr_tdef.all'last" \
200     " = 3"
202 gdb_test "print foo.three_ptr_tdef.all'length" \
203     " = 3"
205 gdb_test "ptype foo.three_ptr_tdef.all" \
206     " = array \\(1 \\.\\. 3\\) of integer"
208 # foo.three_ptr_tdef
210 gdb_test "print foo.three_ptr_tdef(1)" \
211     " = 1"
213 gdb_test "print foo.three_ptr_tdef(2)" \
214     " = 2"
216 gdb_test "print foo.three_ptr_tdef(3)" \
217     " = 3"
219 gdb_test "print foo.three_ptr_tdef'first" \
220     " = 1"
222 gdb_test "print foo.three_ptr_tdef'last" \
223     " = 3"
225 gdb_test "print foo.three_ptr_tdef'length" \
226     " = 3"
228 gdb_test "ptype foo.three_ptr_tdef" \
229     " = access array \\(1 \\.\\. 3\\) of integer"
231 # foo.five_ptr.all
233 gdb_test "print foo.five_ptr.all" \
234     " = \\(2 => 5, 8, 13, 21, 34\\)"
236 gdb_test "print foo.five_ptr.all(2)" \
237     " = 5"
239 gdb_test "print foo.five_ptr.all(3)" \
240     " = 8"
242 gdb_test "print foo.five_ptr.all(4)" \
243     " = 13"
245 gdb_test "print foo.five_ptr.all(5)" \
246     " = 21"
248 gdb_test "print foo.five_ptr.all(6)" \
249     " = 34"
251 gdb_test "print foo.five_ptr.all'first" \
252     " = 2"
254 gdb_test "print foo.five_ptr.all'last" \
255     " = 6"
257 gdb_test "print foo.five_ptr.all'length" \
258     " = 5"
260 gdb_test "ptype foo.five_ptr.all" \
261     " = array \\(2 \\.\\. 6\\) of integer"
263 # foo.five_ptr
265 gdb_test "print foo.five_ptr(2)" \
266     " = 5"
268 gdb_test "print foo.five_ptr(3)" \
269     " = 8"
271 gdb_test "print foo.five_ptr(4)" \
272     " = 13"
274 gdb_test "print foo.five_ptr(5)" \
275     " = 21"
277 gdb_test "print foo.five_ptr(6)" \
278     " = 34"
280 gdb_test "print foo.five_ptr'first" \
281     " = 2"
283 gdb_test "print foo.five_ptr'last" \
284     " = 6"
286 gdb_test "print foo.five_ptr'length" \
287     " = 5"
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)" \
298     " = 5"
300 gdb_test "print foo.five_ptr_tdef.all(3)" \
301     " = 8"
303 gdb_test "print foo.five_ptr_tdef.all(4)" \
304     " = 13"
306 gdb_test "print foo.five_ptr_tdef.all(5)" \
307     " = 21"
309 gdb_test "print foo.five_ptr_tdef.all(6)" \
310     " = 34"
312 gdb_test "print foo.five_ptr_tdef.all'first" \
313     " = 2"
315 gdb_test "print foo.five_ptr_tdef.all'last" \
316     " = 6"
318 gdb_test "print foo.five_ptr_tdef.all'length" \
319     " = 5"
321 gdb_test "ptype foo.five_ptr_tdef.all" \
322     " = array \\(2 \\.\\. 6\\) of integer"
324 # foo.five_ptr_tdef
326 gdb_test "print foo.five_ptr_tdef(2)" \
327     " = 5"
329 gdb_test "print foo.five_ptr_tdef(3)" \
330     " = 8"
332 gdb_test "print foo.five_ptr_tdef(4)" \
333     " = 13"
335 gdb_test "print foo.five_ptr_tdef(5)" \
336     " = 21"
338 gdb_test "print foo.five_ptr_tdef(6)" \
339     " = 34"
341 gdb_test "print foo.five_ptr_tdef'first" \
342     " = 2"
344 gdb_test "print foo.five_ptr_tdef'last" \
345     " = 6"
347 gdb_test "print foo.five_ptr_tdef'length" \
348     " = 5"
350 gdb_test "ptype foo.five_ptr_tdef" \
351     " = access array \\(2 \\.\\. 6\\) of integer"