]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2014-2024 Free Software Foundation, Inc. |
3c8c5dcc JB |
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/>. | |
15 | load_lib dwarf.exp | |
16 | ||
17 | # This test can only be run on targets which support DWARF-2 and use gas. | |
ce8d533e | 18 | require dwarf2_support |
3c8c5dcc | 19 | |
d1c8a76d | 20 | standard_testfile .c -dw.S |
3c8c5dcc JB |
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 | ||
5b362f04 | 29 | if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { |
3c8c5dcc JB |
30 | return -1 |
31 | } | |
32 | ||
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 | } { | |
d36430db | 42 | declare_labels integer_label array_label array_ptr_label |
c6f0b406 | 43 | set int_size [get_sizeof "int" 4] |
111b33f0 | 44 | set voidp_size [get_sizeof "void *" 96] |
3c8c5dcc JB |
45 | |
46 | integer_label: DW_TAG_base_type { | |
c6f0b406 | 47 | {DW_AT_byte_size $int_size DW_FORM_sdata} |
3c8c5dcc JB |
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 | |
111b33f0 | 65 | DW_OP_plus_uconst $voidp_size |
3c8c5dcc | 66 | DW_OP_deref |
111b33f0 | 67 | DW_OP_deref_size $int_size |
3c8c5dcc JB |
68 | } SPECIAL_expr} |
69 | {DW_AT_upper_bound { | |
70 | DW_OP_push_object_address | |
111b33f0 | 71 | DW_OP_plus_uconst $voidp_size |
3c8c5dcc | 72 | DW_OP_deref |
111b33f0 TV |
73 | DW_OP_plus_uconst $int_size |
74 | DW_OP_deref_size $int_size | |
3c8c5dcc | 75 | } SPECIAL_expr} |
3c8c5dcc JB |
76 | } |
77 | } | |
d36430db | 78 | array_ptr_label: DW_TAG_typedef { |
3c8c5dcc JB |
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 { | |
2223449a | 86 | DW_OP_addr [gdb_target_symbol table_1] |
3c8c5dcc JB |
87 | } SPECIAL_expr} |
88 | {external 1 flag} | |
89 | } | |
d36430db JB |
90 | DW_TAG_variable { |
91 | {DW_AT_name foo__three_tdef} | |
92 | {DW_AT_type :$array_ptr_label} | |
93 | {DW_AT_location { | |
2223449a | 94 | DW_OP_addr [gdb_target_symbol table_1] |
d36430db JB |
95 | } SPECIAL_expr} |
96 | {external 1 flag} | |
97 | } | |
3c8c5dcc JB |
98 | DW_TAG_variable { |
99 | {DW_AT_name foo__five} | |
100 | {DW_AT_type :$array_label} | |
101 | {DW_AT_location { | |
2223449a | 102 | DW_OP_addr [gdb_target_symbol table_2] |
3c8c5dcc JB |
103 | } SPECIAL_expr} |
104 | {external 1 flag} | |
105 | } | |
d36430db JB |
106 | DW_TAG_variable { |
107 | {DW_AT_name foo__five_tdef} | |
108 | {DW_AT_type :$array_ptr_label} | |
109 | {DW_AT_location { | |
2223449a | 110 | DW_OP_addr [gdb_target_symbol table_2] |
d36430db JB |
111 | } SPECIAL_expr} |
112 | {external 1 flag} | |
113 | } | |
3c8c5dcc JB |
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 | ||
5b362f04 | 122 | if { [prepare_for_testing "failed to prepare" ${testfile} \ |
3c8c5dcc JB |
123 | [list $srcfile $asm_file] {nodebug}] } { |
124 | return -1 | |
125 | } | |
126 | ||
127 | if ![runto_main] { | |
128 | return -1 | |
129 | } | |
130 | ||
131 | gdb_test_no_output "set language ada" | |
132 | ||
d36430db JB |
133 | # foo.three |
134 | ||
3c8c5dcc JB |
135 | gdb_test "print foo.three" \ |
136 | " = \\(1, 2, 3\\)" | |
137 | ||
138 | gdb_test "ptype foo.three" \ | |
119e99bb | 139 | "type = array \\(<>\\) of integer" |
3c8c5dcc JB |
140 | |
141 | gdb_test "print foo.three(1)" \ | |
142 | " = 1" | |
143 | ||
144 | gdb_test "print foo.three(2)" \ | |
145 | " = 2" | |
146 | ||
147 | gdb_test "print foo.three(3)" \ | |
148 | " = 3" | |
149 | ||
150 | gdb_test "print foo.three'first" \ | |
151 | " = 1" | |
152 | ||
153 | gdb_test "print foo.three'last" \ | |
154 | " = 3" | |
155 | ||
156 | gdb_test "print foo.three'length" \ | |
157 | " = 3" | |
158 | ||
d36430db JB |
159 | # foo.three_tdef |
160 | ||
119e99bb | 161 | gdb_test "print foo.three_tdef.all" \ |
d36430db JB |
162 | " = \\(1, 2, 3\\)" |
163 | ||
164 | gdb_test "ptype foo.three_tdef" \ | |
119e99bb | 165 | "type = access array \\(<>\\) of integer" |
d36430db JB |
166 | |
167 | gdb_test "print foo.three_tdef(1)" \ | |
168 | " = 1" | |
169 | ||
170 | gdb_test "print foo.three_tdef(2)" \ | |
171 | " = 2" | |
172 | ||
173 | gdb_test "print foo.three_tdef(3)" \ | |
174 | " = 3" | |
175 | ||
176 | gdb_test "print foo.three_tdef'first" \ | |
177 | " = 1" | |
178 | ||
179 | gdb_test "print foo.three_tdef'last" \ | |
180 | " = 3" | |
181 | ||
182 | gdb_test "print foo.three_tdef'length" \ | |
183 | " = 3" | |
184 | ||
3c8c5dcc JB |
185 | gdb_test "print foo.five" \ |
186 | " = \\(2 => 5, 8, 13, 21, 34\\)" | |
187 | ||
188 | gdb_test "ptype foo.five" \ | |
119e99bb | 189 | "type = array \\(<>\\) of integer" |
3c8c5dcc JB |
190 | |
191 | gdb_test "ptype foo.array_type" \ | |
192 | "type = array \\(<>\\) of integer" | |
193 | ||
d36430db JB |
194 | # foo.five |
195 | ||
3c8c5dcc JB |
196 | gdb_test "print foo.five(2)" \ |
197 | " = 5" | |
198 | ||
199 | gdb_test "print foo.five(3)" \ | |
200 | " = 8" | |
201 | ||
202 | gdb_test "print foo.five(4)" \ | |
203 | " = 13" | |
204 | ||
205 | gdb_test "print foo.five(5)" \ | |
206 | " = 21" | |
207 | ||
208 | gdb_test "print foo.five(6)" \ | |
209 | " = 34" | |
210 | ||
211 | gdb_test "print foo.five'first" \ | |
212 | " = 2" | |
213 | ||
214 | gdb_test "print foo.five'last" \ | |
215 | " = 6" | |
216 | ||
217 | gdb_test "print foo.five'length" \ | |
218 | " = 5" | |
219 | ||
d36430db JB |
220 | # foo.five_tdef |
221 | ||
119e99bb | 222 | gdb_test "print foo.five_tdef.all" \ |
d36430db JB |
223 | " = \\(2 => 5, 8, 13, 21, 34\\)" |
224 | ||
225 | gdb_test "ptype foo.five_tdef" \ | |
119e99bb | 226 | "type = access array \\(<>\\) of integer" |
d36430db | 227 | |
d36430db JB |
228 | gdb_test "print foo.five_tdef(2)" \ |
229 | " = 5" | |
230 | ||
231 | gdb_test "print foo.five_tdef(3)" \ | |
232 | " = 8" | |
233 | ||
234 | gdb_test "print foo.five_tdef(4)" \ | |
235 | " = 13" | |
236 | ||
237 | gdb_test "print foo.five_tdef(5)" \ | |
238 | " = 21" | |
239 | ||
240 | gdb_test "print foo.five_tdef(6)" \ | |
241 | " = 34" | |
242 | ||
243 | gdb_test "print foo.five_tdef'first" \ | |
244 | " = 2" | |
245 | ||
246 | gdb_test "print foo.five_tdef'last" \ | |
247 | " = 6" | |
248 | ||
249 | gdb_test "print foo.five_tdef'length" \ | |
250 | " = 5" |