GDB: trad-frame: Store length of value_bytes in trad_frame_saved_reg
[binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / data-loc.exp
blobc409f1e40029986399dcb601437d4c48f10dfd68
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 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}] } {
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 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}
49 {DW_AT_name integer}
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}
78 array_ptr_label: DW_TAG_typedef {
79 {DW_AT_name foo__array_type}
80 {DW_AT_type :$array_label}
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}
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}
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}
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}
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
135 gdb_test "print foo.three" \
136 " = \\(1, 2, 3\\)"
138 gdb_test "ptype foo.three" \
139 "type = array \\(<>\\) of integer"
141 gdb_test "print foo.three(1)" \
142 " = 1"
144 gdb_test "print foo.three(2)" \
145 " = 2"
147 gdb_test "print foo.three(3)" \
148 " = 3"
150 gdb_test "print foo.three'first" \
151 " = 1"
153 gdb_test "print foo.three'last" \
154 " = 3"
156 gdb_test "print foo.three'length" \
157 " = 3"
159 # foo.three_tdef
161 gdb_test "print foo.three_tdef.all" \
162 " = \\(1, 2, 3\\)"
164 gdb_test "ptype foo.three_tdef" \
165 "type = access array \\(<>\\) of integer"
167 gdb_test "print foo.three_tdef(1)" \
168 " = 1"
170 gdb_test "print foo.three_tdef(2)" \
171 " = 2"
173 gdb_test "print foo.three_tdef(3)" \
174 " = 3"
176 gdb_test "print foo.three_tdef'first" \
177 " = 1"
179 gdb_test "print foo.three_tdef'last" \
180 " = 3"
182 gdb_test "print foo.three_tdef'length" \
183 " = 3"
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"
194 # foo.five
196 gdb_test "print foo.five(2)" \
197 " = 5"
199 gdb_test "print foo.five(3)" \
200 " = 8"
202 gdb_test "print foo.five(4)" \
203 " = 13"
205 gdb_test "print foo.five(5)" \
206 " = 21"
208 gdb_test "print foo.five(6)" \
209 " = 34"
211 gdb_test "print foo.five'first" \
212 " = 2"
214 gdb_test "print foo.five'last" \
215 " = 6"
217 gdb_test "print foo.five'length" \
218 " = 5"
220 # foo.five_tdef
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)" \
229 " = 5"
231 gdb_test "print foo.five_tdef(3)" \
232 " = 8"
234 gdb_test "print foo.five_tdef(4)" \
235 " = 13"
237 gdb_test "print foo.five_tdef(5)" \
238 " = 21"
240 gdb_test "print foo.five_tdef(6)" \
241 " = 34"
243 gdb_test "print foo.five_tdef'first" \
244 " = 2"
246 gdb_test "print foo.five_tdef'last" \
247 " = 6"
249 gdb_test "print foo.five_tdef'length" \
250 " = 5"