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/>.
18 if { [prepare_for_testing ${testfile}.exp ${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" {
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" {
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"
167 gdb_test_multiple "\0" "end cs exploration" {
169 pass "end cs exploration"
179 gdb_test_multiple "explore cu" "" {
180 -re "[compound_description {cu} {union} {union ComplexUnion}].*[field_choices {s} {sa}].*$enter_field_number_prompt" {
182 gdb_test_multiple "1" "explore cu.sa" {
183 -re ".*[array_description {cu.sa} $SS].*$array_index_prompt" {
185 gdb_test_multiple "0" "explore cu.sa\[0\]" {
186 -re "[compound_description {\(cu.sa\)\[0\]} {struct/class} {struct SimpleStruct}].*[field_values {a = 0} {d = 100[.].*}].*$return_to_parent_prompt" {
187 pass "explore cu.sa\[0\]"
188 gdb_test_multiple "\0" "end cu.sa\[0\] exploration" {
189 -re "[array_description {cu.sa} $SS]$array_index_prompt" {
190 pass "end cu.sa\[0\] exploration"
195 gdb_test_multiple "\0" "end cu.sa exploration" {
196 -re ".*$enter_field_number_prompt" {
197 pass "end cu.sa exploration"
198 gdb_test_multiple "\0" "end cu exploration" {
200 pass "end cu exploration"
210 ########################
211 # Type exploration tests
212 ########################
214 proc scalar_type_decsription {type} {
215 return "'$type' is a scalar type\."
218 proc child_scalar_type_description {path type} {
219 return "$path is of a scalar type '$type'\."
222 proc compound_type_description { type_name type_desc } {
223 return "'$type_name' is a $type_desc with the following fields:"
226 proc child_compound_type_description { path type_name type_desc } {
227 return "$path is a $type_desc of type '$type_name' with the following fields:"
230 proc child_array_type_description { path target_type_name } {
231 return "$path is an array of '$target_type_name'\."
234 proc typedef_type_description { type_name target_name } {
235 return "The type '$type_name' is a typedef of type '$target_name'\."
238 set SS_fields_types [field_choices {a} {d}]
239 set SU_fields_types [field_choices {i} {c} {f} {d}]
240 set CS_fields_types [field_choices {s} {u} {sa}]
241 set CU_fields_types [field_choices {s} {sa}]
243 set CS_field_0 "field 's' of 'struct ComplexStruct'"
244 set CS_field_1 "field 'u' of 'struct ComplexStruct'"
245 set CS_field_2 "field 'sa' of 'struct ComplexStruct'"
246 set CS_field_2_array_element "an array element of $CS_field_2"
248 set CU_field_0 "field 's' of 'union ComplexUnion'"
249 set CU_field_1 "field 'sa' of 'union ComplexUnion'"
250 set CU_field_1_array_element "an array element of $CU_field_1"
252 gdb_test "explore int" ".*[scalar_type_decsription {int}].*"
254 gdb_test_multiple "explore struct SimpleStruct" "" {
255 -re ".*[compound_type_description $SS {struct/class}].*$SS_fields_types.*" {
256 pass "explore struct SimpleStruct"
257 gdb_test_multiple "0" "explore type struct SimpleStruct feild 0" {
258 -re ".*[child_scalar_type_description {field 'a' of 'struct SimpleStruct'} {int}].*" {
259 pass "explore type struct SimpleStruct feild 0"
260 gdb_test_multiple "\0" "return to struct SimpleStruct from field 0" {
261 -re ".*[compound_type_description $SS {struct/class}].*$SS_fields_types.*" {
262 pass "return to struct SimpleStruct from field 0"
267 gdb_test_multiple "1" "explore type struct SimpleStruct feild 1" {
268 -re ".*[child_scalar_type_description {field 'd' of 'struct SimpleStruct'} {double}].*" {
269 pass "explore type struct SimpleStruct feild 1"
270 gdb_test_multiple "\0" "return to struct SimpleStruct from field 1" {
271 -re ".*[compound_type_description $SS {struct/class}].*$SS_fields_types.*" {
272 pass "return to struct SimpleStruct from field 1"
277 gdb_test_multiple "\0" "return to GDB prompt from struct SimpleStruct" {
279 pass "return to GDB prompt from struct SimpleStruct"
285 gdb_test_multiple "explore union SimpleUnion" "" {
286 -re ".*[compound_type_description $SU {union}].*$SU_fields_types.*" {
287 pass "explore union SimpleUnion"
288 gdb_test_multiple "0" "explore type union SimpleUnion feild 0" {
289 -re ".*[child_scalar_type_description {field 'i' of 'union SimpleUnion'} {int}].*" {
290 pass "explore type union SimpleUnion feild 0"
291 gdb_test_multiple "\0" "return to union SimpleUnion from field 0" {
292 -re ".*[compound_type_description $SU {union}].*$SU_fields_types.*" {
293 pass "return to union SimpleUnion from field 0"
298 gdb_test_multiple "1" "explore type union SimpleUnion feild 1" {
299 -re ".*[child_scalar_type_description {field 'c' of 'union SimpleUnion'} {char}].*" {
300 pass "explore type union SimpleUnion feild 1"
301 gdb_test_multiple "\0" "return to union SimpleUnion from field 1" {
302 -re ".*[compound_type_description $SU {union}].*$SU_fields_types.*" {
303 pass "return to union SimpleUnion from field 1"
308 gdb_test_multiple "2" "explore type union SimpleUnion feild 2" {
309 -re ".*[child_scalar_type_description {field 'f' of 'union SimpleUnion'} {float}].*" {
310 pass "explore type union SimpleUnion feild 2"
311 gdb_test_multiple "\0" "return to union SimpleUnion from field 2" {
312 -re ".*[compound_type_description $SU {union}].*$SU_fields_types.*" {
313 pass "return to union SimpleUnion from field 2"
318 gdb_test_multiple "3" "explore type union SimpleUnion feild 3" {
319 -re ".*[child_scalar_type_description {field 'd' of 'union SimpleUnion'} {double}].*" {
320 pass "explore type union SimpleUnion feild 3"
321 gdb_test_multiple "\0" "return to union SimpleUnion from field 3" {
322 -re ".*[compound_type_description $SU {union}].*$SU_fields_types.*" {
323 pass "return to union SimpleUnion from field 3"
328 gdb_test_multiple "\0" "return to GDB prompt from union SimpleUnion" {
330 pass "return to GDB prompt from union SimpleUnion"
336 gdb_test_multiple "explore SS" "" {
337 -re ".*[typedef_type_description {SS} $SS].*[compound_type_description {SS} {struct/class}].*$SS_fields_types.*" {
339 gdb_test_multiple "0" "explore type SS feild 0" {
340 -re ".*[child_scalar_type_description {field 'a' of 'SS'} {int}].*" {
341 pass "explore type SS feild 0"
342 gdb_test_multiple "\0" "return to SS from field 0" {
343 -re ".*[compound_type_description {SS} {struct/class}].*$SS_fields_types.*" {
344 pass "return to SS from field 0"
349 gdb_test_multiple "1" "explore type SS feild 1" {
350 -re ".*[child_scalar_type_description {field 'd' of 'SS'} {double}].*" {
351 pass "explore type SS feild 1"
352 gdb_test_multiple "\0" "return to struct SimpleStruct from field 1" {
353 -re ".*[compound_type_description {SS} {struct/class}].*$SS_fields_types.*" {
354 pass "return to SS field 1"
359 gdb_test_multiple "\0" "return to GDB prompt from SS" {
361 pass "return to GDB prompt from SS"
367 gdb_test_multiple "explore type struct ComplexStruct" "" {
368 -re ".*[compound_type_description $CS {struct/class}].*$CS_fields_types.*" {
369 pass "explore type struct ComplexStruct"
370 gdb_test_multiple "0" "explore type struct ComplexStruct field 0" {
371 -re ".*[child_compound_type_description $CS_field_0 $SS {struct/class}].*$SS_fields_types.*" {
372 pass "explore type struct ComplexStruct field 0"
373 gdb_test_multiple "\0" "return to ComplexStruct from field 0" {
374 -re ".*[compound_type_description $CS {struct/class}].*$CS_fields_types.*" {
375 pass "return to ComplexStruct from field 0"
380 gdb_test_multiple "1" "explore type struct ComplexStruct field 1" {
381 -re ".*[child_compound_type_description $CS_field_1 $SU {union}].*$SU_fields_types.*" {
382 pass "explore type struct ComplexStruct field 1"
383 gdb_test_multiple "\0" "return to ComplexStruct from field 1" {
384 -re ".*[compound_type_description $CS {struct/class}].*$CS_fields_types.*" {
385 pass "return to ComplexStruct from field 1"
390 gdb_test_multiple "2" "explore type struct ComplexStruct field 2" {
391 -re ".*[child_array_type_description $CS_field_2 {SS}].*" {
392 pass "explore type struct ComplexStruct field 2"
393 gdb_test_multiple "\0" "return to ComplexStruct from field 2" {
394 -re ".*[compound_type_description $CS {struct/class}].*$CS_fields_types.*" {
395 pass "return to ComplexStruct from field 2"
400 gdb_test_multiple "\0" "return to GDB prompt from ComplexStruct type exploration" {
402 pass "return to GDB prompt from ComplexStruct type exploration"
408 gdb_test_multiple "explore type union ComplexUnion" "" {
409 -re ".*[compound_type_description $CU {union}].*$CU_fields_types.*" {
410 pass "explore type union ComplexUnion"
411 gdb_test_multiple "0" "explore type union ComplexStruct field 0" {
412 -re ".*[child_compound_type_description $CU_field_0 $SS {struct/class}].*$SS_fields_types.*" {
413 pass "explore type union ComplexUnion field 0"
414 gdb_test_multiple "\0" "return to ComplexUnion from field 0" {
415 -re ".*[compound_type_description $CU {union}].*$CU_fields_types.*" {
416 pass "return to ComplexUnion from field 0"
421 gdb_test_multiple "1" "explore type union ComplexUnion field 1" {
422 -re ".*[child_array_type_description $CU_field_1 $SS].*" {
423 pass "explore type union ComplexUnion field 1"
424 gdb_test_multiple "\0" "return to ComplexUnion array" {
425 -re ".*[compound_type_description $CU {union}].*$CU_fields_types.*" {
426 pass "return to ComplexUnion from field 1"
431 gdb_test_multiple "\0" "return to GDB prompt from ComplexUnion type exploration" {
433 pass "return to GDB prompt from ComplexUnion type exploration"
439 gdb_test_multiple "explore type cu" "" {
440 -re "'cu' is of type 'union ComplexUnion'.*[compound_type_description $CU {union}].*$CU_fields_types.*" {
441 pass "explore type union ComplexUnion"
442 gdb_test_multiple "0" "explore type union ComplexStruct field 0" {
443 -re ".*[child_compound_type_description $CU_field_0 $SS {struct/class}].*$SS_fields_types.*" {
444 pass "explore type union ComplexUnion field 0"
445 gdb_test_multiple "\0" "return to ComplexUnion from field 0" {
446 -re ".*[compound_type_description $CU {union}].*$CU_fields_types.*" {
447 pass "return to ComplexUnion from field 0"
452 gdb_test_multiple "1" "explore type union ComplexUnion field 1" {
453 -re ".*[child_array_type_description $CU_field_1 $SS].*" {
454 pass "explore type union ComplexUnion field 1"
455 gdb_test_multiple "\0" "return to ComplexUnion array" {
456 -re ".*[compound_type_description $CU {union}].*$CU_fields_types.*" {
457 pass "return to ComplexUnion from field 1"
462 gdb_test_multiple "\0" "return to GDB prompt from ComplexUnion type exploration" {
464 pass "return to GDB prompt from ComplexUnion type exploration"