1 # Copyright 2012-2019 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/>.
18 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
22 # Skip all tests if Python scripting is not enabled.
23 if { [skip_python_tests] } { continue }
25 set SS "struct SimpleStruct"
26 set SU "union SimpleUnion"
27 set CS "struct ComplexStruct"
28 set CU "union ComplexUnion"
29 set enter_field_number_prompt {Enter the field number of choice: }
30 set return_to_parent_prompt {Press enter to return to parent value: }
31 set array_index_prompt {Enter the index of the element you want to explore in .*: }
33 proc compound_description { value_name type_desc type_name } {
34 return "The value of '$value_name' is a $type_desc of type '$type_name' with the following fields:\[\r\n\]+"
37 proc typedef_description { value_name typedef_name type_name } {
38 return "The value of '$value_name' is of type '$typedef_name' which is a typedef of type '$type_name'\.\[\r\n\]+"
41 proc scalar_description { value_name type } {
42 return "'$value_name' is a scalar value of type '$type'\.\[\r\n\]+"
45 proc array_description { value_name type } {
46 return "'$value_name' is an array of '$type'\.\[\r\n\]+"
49 proc pointer_description { value_name type_name } {
50 set type_description "'$value_name' is a pointer to a value of type '$type_name'\.\[\r\n\]+"
51 set prompt "Continue exploring it as a pointer to a single value \[\[\]y/n\[\]\]: "
52 return "$type_description$prompt"
55 proc field_values { args } {
58 set result "$result\[ \]*$field \[\.\]\[\.\] \[\(\]Value of type .*\[\)\]\[\r\n\]+"
63 proc field_choices { args } {
67 set result "$result$field\[ \]+=\[ \]+<Enter $field_num to explore this field of type .*"
73 proc scalar_value { value_name value } {
74 return "$value_name = $value\[r\n\]+"
77 set SS_fields [field_values {a = 10} {d = 100[.].*}]
83 gdb_breakpoint [gdb_get_line_number "Break here."]
84 gdb_continue_to_breakpoint "Break here" ".*Break here.*"
86 #########################
87 # Value exploration tests
88 #########################
90 gdb_test "explore i" "[scalar_description {i} {int}].*i = .*"
91 gdb_test "explore ss" "[compound_description {ss} {struct/class} $SS].*$SS_fields"
92 gdb_test "explore *ss_ptr" "[compound_description {\*ss_ptr} {struct/class} $SS].*$SS_fields"
93 gdb_test "explore ss_t" "[typedef_description {ss_t} {SS} $SS].*[compound_description {ss_t} {struct/class} $SS].*$SS_fields"
95 gdb_test_multiple "explore ss_ptr" "" {
96 -re "[pointer_description {ss_ptr} $SS].*" {
98 gdb_test_multiple "y" "explore_as_single_value_pointer" {
99 -re "$SS_fields.*$gdb_prompt" {
100 pass "explore ss_ptr as single value pointer"
106 gdb_test_multiple "explore darray_ref" "" {
107 -re "[pointer_description {darray_ref} {double}].*" {
108 pass "explore darray_ref"
109 gdb_test_multiple "n" "no_to_explore_as_pointer" {
110 -re "Continue exploring it as a pointer to an array \[\[\]y/n\[\]\]: " {
111 pass "no_to_explore_as_pointer"
112 gdb_test_multiple "y" "explore_as_array" {
113 -re ".*Enter the index of the element you want to explore in 'darray_ref':.*" {
114 pass "explore_as_array"
115 gdb_test_multiple "2" "explore_as_array_index_2" {
116 -re ".*'darray_ref\\\[2\\\]' is a scalar value of type 'double'\..*darray_ref\\\[2\\\] = 0.*" {
117 pass "explore_as_array_index_2"
118 gdb_test_multiple "\0" "end explore_as_array_index_2" {
119 -re ".*Returning to parent value.*Enter the index of the element you want to explore in 'darray_ref':.*" {
120 pass "end explore_as_array_index_2"
121 gdb_test_multiple "\0" "end explore_as_array" {
122 -re "\[\n\r\]+$gdb_prompt" {
123 pass "end explore_as_array"
137 gdb_test_multiple "explore su" "" {
138 -re "[compound_description {su} {union} {union SimpleUnion}].*[field_choices {i} {c} {f} {d}].*$enter_field_number_prompt" {
140 gdb_test_multiple "3" "explore su.d" {
141 -re "[scalar_description {su.d} {double}].*[scalar_value {su.d} {100[.].*}].*$return_to_parent_prompt" {
143 gdb_test_multiple " " "end su.d exploration" {
144 -re ".*[compound_description {su} {union} {union SimpleUnion}].*[field_choices {i} {c} {f} {d}].*$enter_field_number_prompt" {
145 pass "end su.d exploration"
146 gdb_test_multiple "\0" "end su exploration" {
148 pass "end su exploration"
158 gdb_test_multiple "explore cs" "" {
159 -re "[compound_description {cs} {struct/class} {struct ComplexStruct}].*[field_choices {s} {u} {sa}].*$enter_field_number_prompt" {
161 gdb_test_multiple "0" "explore cs.s" {
162 -re "[compound_description {cs.s} {struct/class} {struct SimpleStruct}].*[field_values {a = 10} {d = 100[.].*}].*$return_to_parent_prompt" {
164 gdb_test_multiple " " "end cs.s exploration" {
165 -re ".*$enter_field_number_prompt" {
166 pass "end cs.s exploration"
171 gdb_test_multiple "1" "explore cs.u" {
172 -re "[compound_description {cs.u} {union} {union SimpleUnion}].*.*[field_choices {i} {c} {f} {d}].*$enter_field_number_prompt" {
174 gdb_test_multiple " " "end cs.u exploration" {
175 -re ".*$enter_field_number_prompt" {
176 pass "end cs.u exploration"
181 gdb_test_multiple "\0" "explore cs.u" {
183 pass "end cs exploration"
189 gdb_test_multiple "explore cu" "" {
190 -re "[compound_description {cu} {union} {union ComplexUnion}].*[field_choices {s} {sa}].*$enter_field_number_prompt" {
192 gdb_test_multiple "1" "explore cu.sa" {
193 -re ".*[array_description {cu.sa} $SS].*$array_index_prompt" {
195 gdb_test_multiple "0" "explore cu.sa\[0\]" {
196 -re "[compound_description {\(cu.sa\)\[0\]} {struct/class} {struct SimpleStruct}].*[field_values {a = 0} {d = 100[.].*}].*$return_to_parent_prompt" {
197 pass "explore cu.sa\[0\]"
198 gdb_test_multiple "\0" "end cu.sa\[0\] exploration" {
199 -re "[array_description {cu.sa} $SS]$array_index_prompt" {
200 pass "end cu.sa\[0\] exploration"
205 gdb_test_multiple "\0" "end cu.sa exploration" {
206 -re ".*$enter_field_number_prompt" {
207 pass "end cu.sa exploration"
208 gdb_test_multiple "\0" "end cu exploration" {
210 pass "end cu exploration"
220 ########################
221 # Type exploration tests
222 ########################
224 proc scalar_type_decsription {type} {
225 return "'$type' is a scalar type\."
228 proc child_scalar_type_description {path type} {
229 return "$path is of a scalar type '$type'\."
232 proc compound_type_description { type_name type_desc } {
233 return "'$type_name' is a $type_desc with the following fields:"
236 proc child_compound_type_description { path type_name type_desc } {
237 return "$path is a $type_desc of type '$type_name' with the following fields:"
240 proc child_array_type_description { path target_type_name } {
241 return "$path is an array of '$target_type_name'\."
244 proc typedef_type_description { type_name target_name } {
245 return "The type '$type_name' is a typedef of type '$target_name'\."
248 set SS_fields_types [field_choices {a} {d}]
249 set SU_fields_types [field_choices {i} {c} {f} {d}]
250 set CS_fields_types [field_choices {s} {u} {sa}]
251 set CU_fields_types [field_choices {s} {sa}]
253 set CS_field_0 "field 's' of 'struct ComplexStruct'"
254 set CS_field_1 "field 'u' of 'struct ComplexStruct'"
255 set CS_field_2 "field 'sa' of 'struct ComplexStruct'"
256 set CS_field_2_array_element "an array element of $CS_field_2"
258 set CU_field_0 "field 's' of 'union ComplexUnion'"
259 set CU_field_1 "field 'sa' of 'union ComplexUnion'"
260 set CU_field_1_array_element "an array element of $CU_field_1"
262 gdb_test "explore int" ".*[scalar_type_decsription {int}].*"
264 gdb_test_multiple "explore struct SimpleStruct" "" {
265 -re ".*[compound_type_description $SS {struct/class}].*$SS_fields_types.*" {
266 pass "explore struct SimpleStruct"
267 gdb_test_multiple "0" "explore type struct SimpleStruct feild 0" {
268 -re ".*[child_scalar_type_description {field 'a' of 'struct SimpleStruct'} {int}].*" {
269 pass "explore type struct SimpleStruct feild 0"
270 gdb_test_multiple "\0" "return to struct SimpleStruct from field 0" {
271 -re ".*[compound_type_description $SS {struct/class}].*$SS_fields_types.*" {
272 pass "return to struct SimpleStruct from field 0"
277 gdb_test_multiple "1" "explore type struct SimpleStruct feild 1" {
278 -re ".*[child_scalar_type_description {field 'd' of 'struct SimpleStruct'} {double}].*" {
279 pass "explore type struct SimpleStruct feild 1"
280 gdb_test_multiple "\0" "return to struct SimpleStruct from field 1" {
281 -re ".*[compound_type_description $SS {struct/class}].*$SS_fields_types.*" {
282 pass "return to struct SimpleStruct from field 1"
287 gdb_test_multiple "\0" "return to GDB prompt from struct SimpleStruct" {
289 pass "return to GDB prompt from struct SimpleStruct"
295 gdb_test_multiple "explore union SimpleUnion" "" {
296 -re ".*[compound_type_description $SU {union}].*$SU_fields_types.*" {
297 pass "explore union SimpleUnion"
298 gdb_test_multiple "0" "explore type union SimpleUnion feild 0" {
299 -re ".*[child_scalar_type_description {field 'i' of 'union SimpleUnion'} {int}].*" {
300 pass "explore type union SimpleUnion feild 0"
301 gdb_test_multiple "\0" "return to union SimpleUnion from field 0" {
302 -re ".*[compound_type_description $SU {union}].*$SU_fields_types.*" {
303 pass "return to union SimpleUnion from field 0"
308 gdb_test_multiple "1" "explore type union SimpleUnion feild 1" {
309 -re ".*[child_scalar_type_description {field 'c' of 'union SimpleUnion'} {char}].*" {
310 pass "explore type union SimpleUnion feild 1"
311 gdb_test_multiple "\0" "return to union SimpleUnion from field 1" {
312 -re ".*[compound_type_description $SU {union}].*$SU_fields_types.*" {
313 pass "return to union SimpleUnion from field 1"
318 gdb_test_multiple "2" "explore type union SimpleUnion feild 2" {
319 -re ".*[child_scalar_type_description {field 'f' of 'union SimpleUnion'} {float}].*" {
320 pass "explore type union SimpleUnion feild 2"
321 gdb_test_multiple "\0" "return to union SimpleUnion from field 2" {
322 -re ".*[compound_type_description $SU {union}].*$SU_fields_types.*" {
323 pass "return to union SimpleUnion from field 2"
328 gdb_test_multiple "3" "explore type union SimpleUnion feild 3" {
329 -re ".*[child_scalar_type_description {field 'd' of 'union SimpleUnion'} {double}].*" {
330 pass "explore type union SimpleUnion feild 3"
331 gdb_test_multiple "\0" "return to union SimpleUnion from field 3" {
332 -re ".*[compound_type_description $SU {union}].*$SU_fields_types.*" {
333 pass "return to union SimpleUnion from field 3"
338 gdb_test_multiple "\0" "return to GDB prompt from union SimpleUnion" {
340 pass "return to GDB prompt from union SimpleUnion"
346 gdb_test_multiple "explore SS" "" {
347 -re ".*[typedef_type_description {SS} $SS].*[compound_type_description {SS} {struct/class}].*$SS_fields_types.*" {
349 gdb_test_multiple "0" "explore type SS feild 0" {
350 -re ".*[child_scalar_type_description {field 'a' of 'SS'} {int}].*" {
351 pass "explore type SS feild 0"
352 gdb_test_multiple "\0" "return to SS from field 0" {
353 -re ".*[compound_type_description {SS} {struct/class}].*$SS_fields_types.*" {
354 pass "return to SS from field 0"
359 gdb_test_multiple "1" "explore type SS feild 1" {
360 -re ".*[child_scalar_type_description {field 'd' of 'SS'} {double}].*" {
361 pass "explore type SS feild 1"
362 gdb_test_multiple "\0" "return to struct SimpleStruct from field 1" {
363 -re ".*[compound_type_description {SS} {struct/class}].*$SS_fields_types.*" {
364 pass "return to SS field 1"
369 gdb_test_multiple "\0" "return to GDB prompt from SS" {
371 pass "return to GDB prompt from SS"
377 gdb_test_multiple "explore type struct ComplexStruct" "" {
378 -re ".*[compound_type_description $CS {struct/class}].*$CS_fields_types.*" {
379 pass "explore type struct ComplexStruct"
380 gdb_test_multiple "0" "explore type struct ComplexStruct field 0" {
381 -re ".*[child_compound_type_description $CS_field_0 $SS {struct/class}].*$SS_fields_types.*" {
382 pass "explore type struct ComplexStruct field 0"
383 gdb_test_multiple "\0" "return to ComplexStruct from field 0" {
384 -re ".*[compound_type_description $CS {struct/class}].*$CS_fields_types.*" {
385 pass "return to ComplexStruct from field 0"
390 gdb_test_multiple "1" "explore type struct ComplexStruct field 1" {
391 -re ".*[child_compound_type_description $CS_field_1 $SU {union}].*$SU_fields_types.*" {
392 pass "explore type struct ComplexStruct field 1"
393 gdb_test_multiple "\0" "return to ComplexStruct from field 1" {
394 -re ".*[compound_type_description $CS {struct/class}].*$CS_fields_types.*" {
395 pass "return to ComplexStruct from field 1"
400 gdb_test_multiple "2" "explore type struct ComplexStruct field 2" {
401 -re ".*[child_array_type_description $CS_field_2 {SS}].*" {
402 pass "explore type struct ComplexStruct field 2"
403 gdb_test_multiple "\0" "return to ComplexStruct from field 2" {
404 -re ".*[compound_type_description $CS {struct/class}].*$CS_fields_types.*" {
405 pass "return to ComplexStruct from field 2"
410 gdb_test_multiple "\0" "return to GDB prompt from ComplexStruct type exploration" {
412 pass "return to GDB prompt from ComplexStruct type exploration"
418 gdb_test_multiple "explore type union ComplexUnion" "" {
419 -re ".*[compound_type_description $CU {union}].*$CU_fields_types.*" {
420 pass "explore type union ComplexUnion"
421 gdb_test_multiple "0" "explore type union ComplexStruct field 0" {
422 -re ".*[child_compound_type_description $CU_field_0 $SS {struct/class}].*$SS_fields_types.*" {
423 pass "explore type union ComplexUnion field 0"
424 gdb_test_multiple "\0" "return to ComplexUnion from field 0" {
425 -re ".*[compound_type_description $CU {union}].*$CU_fields_types.*" {
426 pass "return to ComplexUnion from field 0"
431 gdb_test_multiple "1" "explore type union ComplexUnion field 1" {
432 -re ".*[child_array_type_description $CU_field_1 $SS].*" {
433 pass "explore type union ComplexUnion field 1"
434 gdb_test_multiple "\0" "return to ComplexUnion array" {
435 -re ".*[compound_type_description $CU {union}].*$CU_fields_types.*" {
436 pass "return to ComplexUnion from field 1"
441 gdb_test_multiple "\0" "return to GDB prompt from ComplexUnion type exploration" {
443 pass "return to GDB prompt from ComplexUnion type exploration"
449 gdb_test_multiple "explore type cu" "" {
450 -re "'cu' is of type 'union ComplexUnion'.*[compound_type_description $CU {union}].*$CU_fields_types.*" {
451 pass "explore type union ComplexUnion"
452 gdb_test_multiple "0" "explore type union ComplexStruct field 0" {
453 -re ".*[child_compound_type_description $CU_field_0 $SS {struct/class}].*$SS_fields_types.*" {
454 pass "explore type union ComplexUnion field 0"
455 gdb_test_multiple "\0" "return to ComplexUnion from field 0" {
456 -re ".*[compound_type_description $CU {union}].*$CU_fields_types.*" {
457 pass "return to ComplexUnion from field 0"
462 gdb_test_multiple "1" "explore type union ComplexUnion field 1" {
463 -re ".*[child_array_type_description $CU_field_1 $SS].*" {
464 pass "explore type union ComplexUnion field 1"
465 gdb_test_multiple "\0" "return to ComplexUnion array" {
466 -re ".*[compound_type_description $CU {union}].*$CU_fields_types.*" {
467 pass "return to ComplexUnion from field 1"
472 gdb_test_multiple "\0" "return to GDB prompt from ComplexUnion type exploration" {
474 pass "return to GDB prompt from ComplexUnion type exploration"