2e460ca34559cb8b4e1bf0719585f3037ed05f34
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / data-loc.exp
1 # Copyright 2014-2016 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/>.
15 load_lib dwarf.exp
16
17 # This test can only be run on targets which support DWARF-2 and use gas.
18 if {![dwarf2_support]} {
19 return 0
20 }
21
22 standard_testfile data-loc.c data-loc-dw.S
23
24 # We need to know the size of integer and address types in order
25 # to write some of the debugging info we'd like to generate.
26 #
27 # For that, we ask GDB by debugging our data-loc.c program.
28 # Any program would do, but since we already have data-loc.c
29 # specifically for this testcase, might as well use that.
30
31 if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
32 untested ${testfile}.exp
33 return -1
34 }
35
36 # Make some DWARF for the test.
37 set asm_file [standard_output_file $srcfile2]
38 Dwarf::assemble $asm_file {
39 cu {} {
40 DW_TAG_compile_unit {
41 {DW_AT_language @DW_LANG_Ada95}
42 {DW_AT_name foo.adb}
43 {DW_AT_comp_dir /tmp}
44 } {
45 declare_labels integer_label array_label array_ptr_label
46 set int_size [get_sizeof "int" 4]
47
48 integer_label: DW_TAG_base_type {
49 {DW_AT_byte_size $int_size DW_FORM_sdata}
50 {DW_AT_encoding @DW_ATE_signed}
51 {DW_AT_name integer}
52 }
53
54 array_label: DW_TAG_array_type {
55 {DW_AT_name foo__array_type}
56 {DW_AT_type :$integer_label}
57 {DW_AT_data_location {
58 DW_OP_push_object_address
59 DW_OP_deref
60 } SPECIAL_expr}
61 {external 1 flag}
62 } {
63 DW_TAG_subrange_type {
64 {DW_AT_type :$integer_label}
65 {DW_AT_lower_bound {
66 DW_OP_push_object_address
67 DW_OP_plus_uconst [get_sizeof "void *" 96]
68 DW_OP_deref
69 DW_OP_deref_size [get_sizeof "int" 4]
70 } SPECIAL_expr}
71 {DW_AT_upper_bound {
72 DW_OP_push_object_address
73 DW_OP_plus_uconst [get_sizeof "void *" 96]
74 DW_OP_deref
75 DW_OP_plus_uconst [get_sizeof "int" 4]
76 DW_OP_deref_size [get_sizeof "int" 4]
77 } SPECIAL_expr}
78 }
79 }
80 array_ptr_label: DW_TAG_typedef {
81 {DW_AT_name foo__array_type}
82 {DW_AT_type :$array_label}
83 }
84 DW_TAG_variable {
85 {DW_AT_name foo__three}
86 {DW_AT_type :$array_label}
87 {DW_AT_location {
88 DW_OP_addr [gdb_target_symbol table_1]
89 } SPECIAL_expr}
90 {external 1 flag}
91 }
92 DW_TAG_variable {
93 {DW_AT_name foo__three_tdef}
94 {DW_AT_type :$array_ptr_label}
95 {DW_AT_location {
96 DW_OP_addr [gdb_target_symbol table_1]
97 } SPECIAL_expr}
98 {external 1 flag}
99 }
100 DW_TAG_variable {
101 {DW_AT_name foo__five}
102 {DW_AT_type :$array_label}
103 {DW_AT_location {
104 DW_OP_addr [gdb_target_symbol table_2]
105 } SPECIAL_expr}
106 {external 1 flag}
107 }
108 DW_TAG_variable {
109 {DW_AT_name foo__five_tdef}
110 {DW_AT_type :$array_ptr_label}
111 {DW_AT_location {
112 DW_OP_addr [gdb_target_symbol table_2]
113 } SPECIAL_expr}
114 {external 1 flag}
115 }
116 }
117 }
118 }
119
120 # Now that we've generated the DWARF debugging info, rebuild our
121 # program using our debug info instead of the info generated by
122 # the compiler.
123
124 if { [prepare_for_testing ${testfile}.exp ${testfile} \
125 [list $srcfile $asm_file] {nodebug}] } {
126 return -1
127 }
128
129 if ![runto_main] {
130 return -1
131 }
132
133 gdb_test_no_output "set language ada"
134
135 # foo.three
136
137 gdb_test "print foo.three" \
138 " = \\(1, 2, 3\\)"
139
140 gdb_test "ptype foo.three" \
141 "type = array \\(1 .. 3\\) of integer"
142
143 gdb_test "print foo.three(1)" \
144 " = 1"
145
146 gdb_test "print foo.three(2)" \
147 " = 2"
148
149 gdb_test "print foo.three(3)" \
150 " = 3"
151
152 gdb_test "print foo.three'first" \
153 " = 1"
154
155 gdb_test "print foo.three'last" \
156 " = 3"
157
158 gdb_test "print foo.three'length" \
159 " = 3"
160
161 # foo.three_tdef
162
163 gdb_test "print foo.three_tdef" \
164 " = \\(1, 2, 3\\)"
165
166 gdb_test "ptype foo.three_tdef" \
167 "type = array \\(1 .. 3\\) of integer"
168
169 gdb_test "print foo.three_tdef(1)" \
170 " = 1"
171
172 gdb_test "print foo.three_tdef(2)" \
173 " = 2"
174
175 gdb_test "print foo.three_tdef(3)" \
176 " = 3"
177
178 gdb_test "print foo.three_tdef'first" \
179 " = 1"
180
181 gdb_test "print foo.three_tdef'last" \
182 " = 3"
183
184 gdb_test "print foo.three_tdef'length" \
185 " = 3"
186
187 gdb_test "print foo.five" \
188 " = \\(2 => 5, 8, 13, 21, 34\\)"
189
190 gdb_test "ptype foo.five" \
191 "type = array \\(2 .. 6\\) of integer"
192
193 gdb_test "ptype foo.array_type" \
194 "type = array \\(<>\\) of integer"
195
196 # foo.five
197
198 gdb_test "print foo.five(2)" \
199 " = 5"
200
201 gdb_test "print foo.five(3)" \
202 " = 8"
203
204 gdb_test "print foo.five(4)" \
205 " = 13"
206
207 gdb_test "print foo.five(5)" \
208 " = 21"
209
210 gdb_test "print foo.five(6)" \
211 " = 34"
212
213 gdb_test "print foo.five'first" \
214 " = 2"
215
216 gdb_test "print foo.five'last" \
217 " = 6"
218
219 gdb_test "print foo.five'length" \
220 " = 5"
221
222 # foo.five_tdef
223
224 gdb_test "print foo.five_tdef" \
225 " = \\(2 => 5, 8, 13, 21, 34\\)"
226
227 gdb_test "ptype foo.five_tdef" \
228 "type = array \\(2 .. 6\\) of integer"
229
230 gdb_test "ptype foo.array_type" \
231 "type = array \\(<>\\) of integer"
232
233 gdb_test "print foo.five_tdef(2)" \
234 " = 5"
235
236 gdb_test "print foo.five_tdef(3)" \
237 " = 8"
238
239 gdb_test "print foo.five_tdef(4)" \
240 " = 13"
241
242 gdb_test "print foo.five_tdef(5)" \
243 " = 21"
244
245 gdb_test "print foo.five_tdef(6)" \
246 " = 34"
247
248 gdb_test "print foo.five_tdef'first" \
249 " = 2"
250
251 gdb_test "print foo.five_tdef'last" \
252 " = 6"
253
254 gdb_test "print foo.five_tdef'length" \
255 " = 5"
256
257 gdb_test_no_output "set lang c"
258
259 # foo__three
260
261 gdb_test "print foo__three" \
262 " = \\{1, 2, 3\\}"
263
264 gdb_test "ptype foo__three" \
265 "type = integer \\\[3\\\]"
266
267 # foo__three_tdef
268
269 gdb_test "print foo__three_tdef" \
270 " = \\{1, 2, 3\\}"
271
272 gdb_test "ptype foo__three_tdef" \
273 "type = integer \\\[3\\\]"
274
275 # foo__five
276
277 gdb_test "print foo__five" \
278 " = \\{5, 8, 13, 21, 34\\}"
279
280 gdb_test "ptype foo__five" \
281 "type = integer \\\[5\\\]"
282
283 # foo__five_tdef
284
285 gdb_test "print foo__five_tdef" \
286 " = \\{5, 8, 13, 21, 34\\}"
287
288 gdb_test "ptype foo__five_tdef" \
289 "type = integer \\\[5\\\]"
290
291 gdb_test "ptype foo__array_type" \
292 "type = integer \\\[variable length\\\]"
This page took 0.052274 seconds and 3 git commands to generate.