1 # Copyright 2012 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/>.
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}] } {
23 # Skip all tests if Python scripting is not enabled.
24 if { [skip_python_tests] } { continue }
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 .*: }
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\]+"
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\]+"
42 proc scalar_description { value_name type } {
43 return "'$value_name' is a scalar value of type '$type'\.\[\r\n\]+"
46 proc array_description { value_name type } {
47 return "'$value_name' is an array of '$type'\.\[\r\n\]+"
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"
56 proc field_values { args } {
59 set result "$result\[ \]*$field \[\.\]\[\.\] \[\(\]Value of type .*\[\)\]\[\r\n\]+"
64 proc field_choices { args } {
68 set result "$result$field\[ \]+=\[ \]+<Enter $field_num to explore this field of type .*"
74 proc scalar_value { value_name value } {
75 return "$value_name = $value\[r\n\]+"
78 set SS_fields [field_values {a = 10} {d = 100[.].*}]
84 gdb_breakpoint [gdb_get_line_number "Break here."]
85 gdb_continue_to_breakpoint "Break here" ".*Break here.*"
87 #########################
88 # Value exploration tests
89 #########################
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"
96 gdb_test_multiple "explore ss_ptr" "" {
97 -re "[pointer_description {ss_ptr} $SS].*" {
99 gdb_test_multiple "y" "explore_as_single_value_pointer" {
101 pass "explore ss_ptr as single value pointer"
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" {
124 pass "end explore_as_array"
138 gdb_test_multiple "explore su" "" {
139 -re "[compound_description {su} {union} {union SimpleUnion}].*[field_choices {i} {c} {f} {d}].*$enter_field_number_prompt" {
141 gdb_test_multiple "3" "explore su.d" {
142 -re "[scalar_description {su.d} {double}].*[scalar_value {su.d} {100[.].*}].*$return_to_parent_prompt" {
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" {
149 pass "end su exploration"
159 gdb_test_multiple "explore cs" "" {
160 -re "[compound_description {cs} {struct/class} {struct ComplexStruct}].*[field_choices {s} {u} {sa}].*$enter_field_number_prompt" {
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" {
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" {
170 pass "end cs exploration"
180 gdb_test_multiple "explore cu" "" {
181 -re "[compound_description {cu} {union} {union ComplexUnion}].*[field_choices {s} {sa}].*$enter_field_number_prompt" {
183 gdb_test_multiple "1" "explore cu.sa" {
184 -re ".*[array_description {cu.sa} $SS].*$array_index_prompt" {
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"
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" {
201 pass "end cu exploration"
211 ########################
212 # Type exploration tests
213 ########################
215 proc scalar_type_decsription {type} {
216 return "'$type' is a scalar type\."
219 proc child_scalar_type_description {path type} {
220 return "$path is of a scalar type '$type'\."
223 proc compound_type_description { type_name type_desc } {
224 return "'$type_name' is a $type_desc with the following fields:"
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:"
231 proc child_array_type_description { path target_type_name } {
232 return "$path is an array of '$target_type_name'\."
235 proc typedef_type_description { type_name target_name } {
236 return "The type '$type_name' is a typedef of type '$target_name'\."
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}]
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"
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"
253 gdb_test "explore int" ".*[scalar_type_decsription {int}].*"
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"
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"
278 gdb_test_multiple "\0" "return to GDB prompt from struct SimpleStruct" {
280 pass "return to GDB prompt from struct SimpleStruct"
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"
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"
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"
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"
329 gdb_test_multiple "\0" "return to GDB prompt from union SimpleUnion" {
331 pass "return to GDB prompt from union SimpleUnion"
337 gdb_test_multiple "explore SS" "" {
338 -re ".*[typedef_type_description {SS} $SS].*[compound_type_description {SS} {struct/class}].*$SS_fields_types.*" {
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"
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"
360 gdb_test_multiple "\0" "return to GDB prompt from SS" {
362 pass "return to GDB prompt from SS"
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"
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"
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"
401 gdb_test_multiple "\0" "return to GDB prompt from ComplexStruct type exploration" {
403 pass "return to GDB prompt from ComplexStruct type exploration"
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"
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"
432 gdb_test_multiple "\0" "return to GDB prompt from ComplexUnion type exploration" {
434 pass "return to GDB prompt from ComplexUnion type exploration"
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"
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"
463 gdb_test_multiple "\0" "return to GDB prompt from ComplexUnion type exploration" {
465 pass "return to GDB prompt from ComplexUnion type exploration"