2012-04-02 Siva Chandra Reddy <sivachandra@google.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-explore.exp
1 # Copyright 2012 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
16 set testfile "py-explore"
17 set srcfile ${testfile}.c
18 set binfile ${objdir}/${subdir}/${testfile}
19 if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } {
20 return -1
21 }
22
23 # Skip all tests if Python scripting is not enabled.
24 if { [skip_python_tests] } { continue }
25
26 set SS "struct SimpleStruct"
27 set SU "union SimpleUnion"
28 set CS "struct ComplexStruct"
29 set CU "union ComplexUnion"
30 set enter_field_number_prompt {Enter the field number of choice: }
31 set return_to_parent_prompt {Press enter to return to parent value: }
32 set array_index_prompt {Enter the index of the element you want to explore in .*: }
33
34 proc compound_description { value_name type_desc type_name } {
35 return "The value of '$value_name' is a $type_desc of type '$type_name' with the following fields:\[\r\n\]+"
36 }
37
38 proc typedef_description { value_name typedef_name type_name } {
39 return "The value of '$value_name' is of type '$typedef_name' which is a typedef of type '$type_name'\.\[\r\n\]+"
40 }
41
42 proc scalar_description { value_name type } {
43 return "'$value_name' is a scalar value of type '$type'\.\[\r\n\]+"
44 }
45
46 proc array_description { value_name type } {
47 return "'$value_name' is an array of '$type'\.\[\r\n\]+"
48 }
49
50 proc pointer_description { value_name type_name } {
51 set type_description "'$value_name' is a pointer to a value of type '$type_name'\.\[\r\n\]+"
52 set prompt "Continue exploring it as a pointer to a single value \[\[\]y/n\[\]\]: "
53 return "$type_description$prompt"
54 }
55
56 proc field_values { args } {
57 set result ""
58 foreach field $args {
59 set result "$result\[ \]*$field \[\.\]\[\.\] \[\(\]Value of type .*\[\)\]\[\r\n\]+"
60 }
61 return $result
62 }
63
64 proc field_choices { args } {
65 set result ""
66 set field_num 0
67 foreach field $args {
68 set result "$result$field\[ \]+=\[ \]+<Enter $field_num to explore this field of type .*"
69 incr field_num
70 }
71 return $result
72 }
73
74 proc scalar_value { value_name value } {
75 return "$value_name = $value\[r\n\]+"
76 }
77
78 set SS_fields [field_values {a = 10} {d = 100[.].*}]
79
80 if ![runto_main] {
81 return -1
82 }
83
84 gdb_breakpoint [gdb_get_line_number "Break here."]
85 gdb_continue_to_breakpoint "Break here" ".*Break here.*"
86
87 #########################
88 # Value exploration tests
89 #########################
90
91 gdb_test "explore i" "[scalar_description {i} {int}].*i = .*"
92 gdb_test "explore ss" "[compound_description {ss} {struct/class} $SS].*$SS_fields"
93 gdb_test "explore *ss_ptr" "[compound_description {\*ss_ptr} {struct/class} $SS].*$SS_fields"
94 gdb_test "explore ss_t" "[typedef_description {ss_t} {SS} $SS].*[compound_description {ss_t} {struct/class} $SS].*$SS_fields"
95
96 gdb_test_multiple "explore ss_ptr" "" {
97 -re "[pointer_description {ss_ptr} $SS].*" {
98 pass "explore ss_ptr"
99 gdb_test_multiple "y" "explore_as_single_value_pointer" {
100 -re "$SS_fields" {
101 pass "explore ss_ptr as single value pointer"
102 }
103 }
104 }
105 }
106
107 gdb_test_multiple "explore darray_ref" "" {
108 -re "[pointer_description {darray_ref} {double}].*" {
109 pass "explore darray_ref"
110 gdb_test_multiple "n" "no_to_explore_as_pointer" {
111 -re "Continue exploring it as a pointer to an array \[\[\]y/n\[\]\]: " {
112 pass "no_to_explore_as_pointer"
113 gdb_test_multiple "y" "explore_as_array" {
114 -re ".*Enter the index of the element you want to explore in 'darray_ref':.*" {
115 pass "explore_as_array"
116 gdb_test_multiple "2" "explore_as_array_index_2" {
117 -re ".*'darray_ref\\\[2\\\]' is a scalar value of type 'double'\..*darray_ref\\\[2\\\] = 0.*" {
118 pass "explore_as_array_index_2"
119 gdb_test_multiple "\0" "end explore_as_array_index_2" {
120 -re ".*Returning to parent value.*Enter the index of the element you want to explore in 'darray_ref':.*" {
121 pass "end explore_as_array_index_2"
122 gdb_test_multiple "\0" "end explore_as_array" {
123 -re "\[\n\r\]+" {
124 pass "end explore_as_array"
125 }
126 }
127 }
128 }
129 }
130 }
131 }
132 }
133 }
134 }
135 }
136 }
137
138 gdb_test_multiple "explore su" "" {
139 -re "[compound_description {su} {union} {union SimpleUnion}].*[field_choices {i} {c} {f} {d}].*$enter_field_number_prompt" {
140 pass "explore su"
141 gdb_test_multiple "3" "explore su.d" {
142 -re "[scalar_description {su.d} {double}].*[scalar_value {su.d} {100[.].*}].*$return_to_parent_prompt" {
143 pass "explore su.d"
144 gdb_test_multiple " " "end su.d exploration" {
145 -re ".*[compound_description {su} {union} {union SimpleUnion}].*[field_choices {i} {c} {f} {d}].*$enter_field_number_prompt" {
146 pass "end su.d exploration"
147 gdb_test_multiple "\0" "end su exploration" {
148 -re "$gdb_prompt" {
149 pass "end su exploration"
150 }
151 }
152 }
153 }
154 }
155 }
156 }
157 }
158
159 gdb_test_multiple "explore cs" "" {
160 -re "[compound_description {cs} {struct/class} {struct ComplexStruct}].*[field_choices {s} {u} {sa}].*$enter_field_number_prompt" {
161 pass "explore cs"
162 gdb_test_multiple "0" "explore cs.s" {
163 -re "[compound_description {cs.s} {struct/class} {struct SimpleStruct}].*[field_values {a = 10} {d = 100[.].*}].*$return_to_parent_prompt" {
164 pass "explore cs.s"
165 gdb_test_multiple " " "end cs.s exploration" {
166 -re ".*$enter_field_number_prompt" {
167 pass "end cs.s exploration"
168 gdb_test_multiple "\0" "end cs exploration" {
169 -re "$gdb_prompt" {
170 pass "end cs exploration"
171 }
172 }
173 }
174 }
175 }
176 }
177 }
178 }
179
180 gdb_test_multiple "explore cu" "" {
181 -re "[compound_description {cu} {union} {union ComplexUnion}].*[field_choices {s} {sa}].*$enter_field_number_prompt" {
182 pass "explore cu"
183 gdb_test_multiple "1" "explore cu.sa" {
184 -re ".*[array_description {cu.sa} $SS].*$array_index_prompt" {
185 pass "explore cu.sa"
186 gdb_test_multiple "0" "explore cu.sa\[0\]" {
187 -re "[compound_description {\(cu.sa\)\[0\]} {struct/class} {struct SimpleStruct}].*[field_values {a = 0} {d = 100[.].*}].*$return_to_parent_prompt" {
188 pass "explore cu.sa\[0\]"
189 gdb_test_multiple "\0" "end cu.sa\[0\] exploration" {
190 -re "[array_description {cu.sa} $SS]$array_index_prompt" {
191 pass "end cu.sa\[0\] exploration"
192 }
193 }
194 }
195 }
196 gdb_test_multiple "\0" "end cu.sa exploration" {
197 -re ".*$enter_field_number_prompt" {
198 pass "end cu.sa exploration"
199 gdb_test_multiple "\0" "end cu exploration" {
200 -re "$gdb_prompt" {
201 pass "end cu exploration"
202 }
203 }
204 }
205 }
206 }
207 }
208 }
209 }
210
211 ########################
212 # Type exploration tests
213 ########################
214
215 proc scalar_type_decsription {type} {
216 return "'$type' is a scalar type\."
217 }
218
219 proc child_scalar_type_description {path type} {
220 return "$path is of a scalar type '$type'\."
221 }
222
223 proc compound_type_description { type_name type_desc } {
224 return "'$type_name' is a $type_desc with the following fields:"
225 }
226
227 proc child_compound_type_description { path type_name type_desc } {
228 return "$path is a $type_desc of type '$type_name' with the following fields:"
229 }
230
231 proc child_array_type_description { path target_type_name } {
232 return "$path is an array of '$target_type_name'\."
233 }
234
235 proc typedef_type_description { type_name target_name } {
236 return "The type '$type_name' is a typedef of type '$target_name'\."
237 }
238
239 set SS_fields_types [field_choices {a} {d}]
240 set SU_fields_types [field_choices {i} {c} {f} {d}]
241 set CS_fields_types [field_choices {s} {u} {sa}]
242 set CU_fields_types [field_choices {s} {sa}]
243
244 set CS_field_0 "field 's' of 'struct ComplexStruct'"
245 set CS_field_1 "field 'u' of 'struct ComplexStruct'"
246 set CS_field_2 "field 'sa' of 'struct ComplexStruct'"
247 set CS_field_2_array_element "an array element of $CS_field_2"
248
249 set CU_field_0 "field 's' of 'union ComplexUnion'"
250 set CU_field_1 "field 'sa' of 'union ComplexUnion'"
251 set CU_field_1_array_element "an array element of $CU_field_1"
252
253 gdb_test "explore int" ".*[scalar_type_decsription {int}].*"
254
255 gdb_test_multiple "explore struct SimpleStruct" "" {
256 -re ".*[compound_type_description $SS {struct/class}].*$SS_fields_types.*" {
257 pass "explore struct SimpleStruct"
258 gdb_test_multiple "0" "explore type struct SimpleStruct feild 0" {
259 -re ".*[child_scalar_type_description {field 'a' of 'struct SimpleStruct'} {int}].*" {
260 pass "explore type struct SimpleStruct feild 0"
261 gdb_test_multiple "\0" "return to struct SimpleStruct from field 0" {
262 -re ".*[compound_type_description $SS {struct/class}].*$SS_fields_types.*" {
263 pass "return to struct SimpleStruct from field 0"
264 }
265 }
266 }
267 }
268 gdb_test_multiple "1" "explore type struct SimpleStruct feild 1" {
269 -re ".*[child_scalar_type_description {field 'd' of 'struct SimpleStruct'} {double}].*" {
270 pass "explore type struct SimpleStruct feild 1"
271 gdb_test_multiple "\0" "return to struct SimpleStruct from field 1" {
272 -re ".*[compound_type_description $SS {struct/class}].*$SS_fields_types.*" {
273 pass "return to struct SimpleStruct from field 1"
274 }
275 }
276 }
277 }
278 gdb_test_multiple "\0" "return to GDB prompt from struct SimpleStruct" {
279 -re "$gdb_prompt" {
280 pass "return to GDB prompt from struct SimpleStruct"
281 }
282 }
283 }
284 }
285
286 gdb_test_multiple "explore union SimpleUnion" "" {
287 -re ".*[compound_type_description $SU {union}].*$SU_fields_types.*" {
288 pass "explore union SimpleUnion"
289 gdb_test_multiple "0" "explore type union SimpleUnion feild 0" {
290 -re ".*[child_scalar_type_description {field 'i' of 'union SimpleUnion'} {int}].*" {
291 pass "explore type union SimpleUnion feild 0"
292 gdb_test_multiple "\0" "return to union SimpleUnion from field 0" {
293 -re ".*[compound_type_description $SU {union}].*$SU_fields_types.*" {
294 pass "return to union SimpleUnion from field 0"
295 }
296 }
297 }
298 }
299 gdb_test_multiple "1" "explore type union SimpleUnion feild 1" {
300 -re ".*[child_scalar_type_description {field 'c' of 'union SimpleUnion'} {char}].*" {
301 pass "explore type union SimpleUnion feild 1"
302 gdb_test_multiple "\0" "return to union SimpleUnion from field 1" {
303 -re ".*[compound_type_description $SU {union}].*$SU_fields_types.*" {
304 pass "return to union SimpleUnion from field 1"
305 }
306 }
307 }
308 }
309 gdb_test_multiple "2" "explore type union SimpleUnion feild 2" {
310 -re ".*[child_scalar_type_description {field 'f' of 'union SimpleUnion'} {float}].*" {
311 pass "explore type union SimpleUnion feild 2"
312 gdb_test_multiple "\0" "return to union SimpleUnion from field 2" {
313 -re ".*[compound_type_description $SU {union}].*$SU_fields_types.*" {
314 pass "return to union SimpleUnion from field 2"
315 }
316 }
317 }
318 }
319 gdb_test_multiple "3" "explore type union SimpleUnion feild 3" {
320 -re ".*[child_scalar_type_description {field 'd' of 'union SimpleUnion'} {double}].*" {
321 pass "explore type union SimpleUnion feild 3"
322 gdb_test_multiple "\0" "return to union SimpleUnion from field 3" {
323 -re ".*[compound_type_description $SU {union}].*$SU_fields_types.*" {
324 pass "return to union SimpleUnion from field 3"
325 }
326 }
327 }
328 }
329 gdb_test_multiple "\0" "return to GDB prompt from union SimpleUnion" {
330 -re "$gdb_prompt" {
331 pass "return to GDB prompt from union SimpleUnion"
332 }
333 }
334 }
335 }
336
337 gdb_test_multiple "explore SS" "" {
338 -re ".*[typedef_type_description {SS} $SS].*[compound_type_description {SS} {struct/class}].*$SS_fields_types.*" {
339 pass "explore SS"
340 gdb_test_multiple "0" "explore type SS feild 0" {
341 -re ".*[child_scalar_type_description {field 'a' of 'SS'} {int}].*" {
342 pass "explore type SS feild 0"
343 gdb_test_multiple "\0" "return to SS from field 0" {
344 -re ".*[compound_type_description {SS} {struct/class}].*$SS_fields_types.*" {
345 pass "return to SS from field 0"
346 }
347 }
348 }
349 }
350 gdb_test_multiple "1" "explore type SS feild 1" {
351 -re ".*[child_scalar_type_description {field 'd' of 'SS'} {double}].*" {
352 pass "explore type SS feild 1"
353 gdb_test_multiple "\0" "return to struct SimpleStruct from field 1" {
354 -re ".*[compound_type_description {SS} {struct/class}].*$SS_fields_types.*" {
355 pass "return to SS field 1"
356 }
357 }
358 }
359 }
360 gdb_test_multiple "\0" "return to GDB prompt from SS" {
361 -re "$gdb_prompt" {
362 pass "return to GDB prompt from SS"
363 }
364 }
365 }
366 }
367
368 gdb_test_multiple "explore type struct ComplexStruct" "" {
369 -re ".*[compound_type_description $CS {struct/class}].*$CS_fields_types.*" {
370 pass "explore type struct ComplexStruct"
371 gdb_test_multiple "0" "explore type struct ComplexStruct field 0" {
372 -re ".*[child_compound_type_description $CS_field_0 $SS {struct/class}].*$SS_fields_types.*" {
373 pass "explore type struct ComplexStruct field 0"
374 gdb_test_multiple "\0" "return to ComplexStruct from field 0" {
375 -re ".*[compound_type_description $CS {struct/class}].*$CS_fields_types.*" {
376 pass "return to ComplexStruct from field 0"
377 }
378 }
379 }
380 }
381 gdb_test_multiple "1" "explore type struct ComplexStruct field 1" {
382 -re ".*[child_compound_type_description $CS_field_1 $SU {union}].*$SU_fields_types.*" {
383 pass "explore type struct ComplexStruct field 1"
384 gdb_test_multiple "\0" "return to ComplexStruct from field 1" {
385 -re ".*[compound_type_description $CS {struct/class}].*$CS_fields_types.*" {
386 pass "return to ComplexStruct from field 1"
387 }
388 }
389 }
390 }
391 gdb_test_multiple "2" "explore type struct ComplexStruct field 2" {
392 -re ".*[child_array_type_description $CS_field_2 {SS}].*" {
393 pass "explore type struct ComplexStruct field 2"
394 gdb_test_multiple "\0" "return to ComplexStruct from field 2" {
395 -re ".*[compound_type_description $CS {struct/class}].*$CS_fields_types.*" {
396 pass "return to ComplexStruct from field 2"
397 }
398 }
399 }
400 }
401 gdb_test_multiple "\0" "return to GDB prompt from ComplexStruct type exploration" {
402 -re "$gdb_prompt" {
403 pass "return to GDB prompt from ComplexStruct type exploration"
404 }
405 }
406 }
407 }
408
409 gdb_test_multiple "explore type union ComplexUnion" "" {
410 -re ".*[compound_type_description $CU {union}].*$CU_fields_types.*" {
411 pass "explore type union ComplexUnion"
412 gdb_test_multiple "0" "explore type union ComplexStruct field 0" {
413 -re ".*[child_compound_type_description $CU_field_0 $SS {struct/class}].*$SS_fields_types.*" {
414 pass "explore type union ComplexUnion field 0"
415 gdb_test_multiple "\0" "return to ComplexUnion from field 0" {
416 -re ".*[compound_type_description $CU {union}].*$CU_fields_types.*" {
417 pass "return to ComplexUnion from field 0"
418 }
419 }
420 }
421 }
422 gdb_test_multiple "1" "explore type union ComplexUnion field 1" {
423 -re ".*[child_array_type_description $CU_field_1 $SS].*" {
424 pass "explore type union ComplexUnion field 1"
425 gdb_test_multiple "\0" "return to ComplexUnion array" {
426 -re ".*[compound_type_description $CU {union}].*$CU_fields_types.*" {
427 pass "return to ComplexUnion from field 1"
428 }
429 }
430 }
431 }
432 gdb_test_multiple "\0" "return to GDB prompt from ComplexUnion type exploration" {
433 -re "$gdb_prompt" {
434 pass "return to GDB prompt from ComplexUnion type exploration"
435 }
436 }
437 }
438 }
439
440 gdb_test_multiple "explore type cu" "" {
441 -re "'cu' is of type 'union ComplexUnion'.*[compound_type_description $CU {union}].*$CU_fields_types.*" {
442 pass "explore type union ComplexUnion"
443 gdb_test_multiple "0" "explore type union ComplexStruct field 0" {
444 -re ".*[child_compound_type_description $CU_field_0 $SS {struct/class}].*$SS_fields_types.*" {
445 pass "explore type union ComplexUnion field 0"
446 gdb_test_multiple "\0" "return to ComplexUnion from field 0" {
447 -re ".*[compound_type_description $CU {union}].*$CU_fields_types.*" {
448 pass "return to ComplexUnion from field 0"
449 }
450 }
451 }
452 }
453 gdb_test_multiple "1" "explore type union ComplexUnion field 1" {
454 -re ".*[child_array_type_description $CU_field_1 $SS].*" {
455 pass "explore type union ComplexUnion field 1"
456 gdb_test_multiple "\0" "return to ComplexUnion array" {
457 -re ".*[compound_type_description $CU {union}].*$CU_fields_types.*" {
458 pass "return to ComplexUnion from field 1"
459 }
460 }
461 }
462 }
463 gdb_test_multiple "\0" "return to GDB prompt from ComplexUnion type exploration" {
464 -re "$gdb_prompt" {
465 pass "return to GDB prompt from ComplexUnion type exploration"
466 }
467 }
468 }
469 }
This page took 0.050384 seconds and 5 git commands to generate.