1 # Copyright 2012-2024 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 require allow_python_tests
20 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
24 set SS "struct SimpleStruct"
25 set SU "union SimpleUnion"
26 set CS "struct ComplexStruct"
27 set CU "union ComplexUnion"
28 set enter_field_number_prompt {Enter the field number of choice: }
29 set return_to_parent_prompt {Press enter to return to parent value: }
30 set array_index_prompt {Enter the index of the element you want to explore in .*: }
32 proc compound_description { value_name type_desc type_name } {
33 return "The value of '$value_name' is a $type_desc of type '$type_name' with the following fields:\[\r\n\]+"
36 proc typedef_description { value_name typedef_name type_name } {
37 return "The value of '$value_name' is of type '$typedef_name' which is a typedef of type '$type_name'\.\[\r\n\]+"
40 proc scalar_description { value_name type } {
41 return "'$value_name' is a scalar value of type '$type'\.\[\r\n\]+"
44 proc array_description { value_name type } {
45 return "'$value_name' is an array of '$type'\.\[\r\n\]+"
48 proc pointer_description { value_name type_name } {
49 set type_description "'$value_name' is a pointer to a value of type '$type_name'\.\[\r\n\]+"
50 set prompt "Continue exploring it as a pointer to a single value \[\[\]y/n\[\]\]: "
51 return "$type_description$prompt"
54 proc field_values { args } {
57 set result "$result\[ \]*$field \[\.\]\[\.\] \[\(\]Value of type .*\[\)\]\[\r\n\]+"
62 proc field_choices { args } {
66 set result "$result$field\[ \]+=\[ \]+<Enter $field_num to explore this field of type .*"
72 proc scalar_value { value_name value } {
73 return "$value_name = $value\[r\n\]+"
76 set SS_fields [field_values {a = 10} {d = 100[.].*}]
82 gdb_breakpoint [gdb_get_line_number "Break here."]
83 gdb_continue_to_breakpoint "Break here" ".*Break here.*"
85 #########################
86 # Value exploration tests
87 #########################
89 gdb_test "explore i" "[scalar_description {i} {int}].*i = .*"
90 gdb_test "explore ss" "[compound_description {ss} {struct/class} $SS].*$SS_fields"
91 gdb_test "explore *ss_ptr" "[compound_description {\*ss_ptr} {struct/class} $SS].*$SS_fields"
92 gdb_test "explore ss_t" "[typedef_description {ss_t} {SS} $SS].*[compound_description {ss_t} {struct/class} $SS].*$SS_fields"
94 gdb_test_multiple "explore ss_ptr" "" {
95 -re "[pointer_description {ss_ptr} $SS].*" {
97 gdb_test_multiple "y" "explore_as_single_value_pointer" {
98 -re "$SS_fields.*$gdb_prompt" {
99 pass "explore ss_ptr as single value pointer"
105 gdb_test_multiple "explore darray_ref" "" {
106 -re "[pointer_description {darray_ref} {double}].*" {
107 pass "explore darray_ref"
108 gdb_test_multiple "n" "no_to_explore_as_pointer" {
109 -re "Continue exploring it as a pointer to an array \[\[\]y/n\[\]\]: " {
110 pass "no_to_explore_as_pointer"
111 gdb_test_multiple "y" "explore_as_array" {
112 -re ".*Enter the index of the element you want to explore in 'darray_ref':.*" {
113 pass "explore_as_array"
114 gdb_test_multiple "2" "explore_as_array_index_2" {
115 -re ".*'darray_ref\\\[2\\\]' is a scalar value of type 'double'\..*darray_ref\\\[2\\\] = 0.*" {
116 pass "explore_as_array_index_2"
117 gdb_test_multiple "\0" "end explore_as_array_index_2" {
118 -re ".*Returning to parent value.*Enter the index of the element you want to explore in 'darray_ref':.*" {
119 pass "end explore_as_array_index_2"
120 gdb_test_multiple "\0" "end explore_as_array" {
121 -re "\[\n\r\]+$gdb_prompt" {
122 pass "end explore_as_array"
136 gdb_test_multiple "explore su" "" {
137 -re "[compound_description {su} {union} {union SimpleUnion}].*[field_choices {i} {c} {f} {d}].*$enter_field_number_prompt" {
139 gdb_test_multiple "3" "explore su.d" {
140 -re "[scalar_description {su.d} {double}].*[scalar_value {su.d} {100[.].*}].*$return_to_parent_prompt" {
142 gdb_test_multiple " " "end su.d exploration" {
143 -re ".*[compound_description {su} {union} {union SimpleUnion}].*[field_choices {i} {c} {f} {d}].*$enter_field_number_prompt" {
144 pass "end su.d exploration"
145 gdb_test_multiple "\0" "end su exploration" {
147 pass "end su exploration"
157 gdb_test_multiple "explore cs" "" {
158 -re "[compound_description {cs} {struct/class} {struct ComplexStruct}].*[field_choices {s} {u} {sa}].*$enter_field_number_prompt" {
160 gdb_test_multiple "0" "explore cs.s" {
161 -re "[compound_description {cs.s} {struct/class} {struct SimpleStruct}].*[field_values {a = 10} {d = 100[.].*}].*$return_to_parent_prompt" {
163 gdb_test_multiple " " "end cs.s exploration" {
164 -re ".*$enter_field_number_prompt" {
165 pass "end cs.s exploration"
170 gdb_test_multiple "1" "explore cs.u" {
171 -re "[compound_description {cs.u} {union} {union SimpleUnion}].*.*[field_choices {i} {c} {f} {d}].*$enter_field_number_prompt" {
173 gdb_test_multiple " " "end cs.u exploration" {
174 -re ".*$enter_field_number_prompt" {
175 pass "end cs.u exploration"
180 gdb_test_multiple "\0" "explore cs.u" {
182 pass "end cs exploration"
188 gdb_test_multiple "explore cu" "" {
189 -re "[compound_description {cu} {union} {union ComplexUnion}].*[field_choices {s} {sa}].*$enter_field_number_prompt" {
191 gdb_test_multiple "1" "explore cu.sa" {
192 -re ".*[array_description {cu.sa} $SS].*$array_index_prompt" {
194 gdb_test_multiple "0" "explore cu.sa\[0\]" {
195 -re "[compound_description {\(cu.sa\)\[0\]} {struct/class} {struct SimpleStruct}].*[field_values {a = 0} {d = 100[.].*}].*$return_to_parent_prompt" {
196 pass "explore cu.sa\[0\]"
197 gdb_test_multiple "\0" "end cu.sa\[0\] exploration" {
198 -re "[array_description {cu.sa} $SS]$array_index_prompt" {
199 pass "end cu.sa\[0\] exploration"
204 gdb_test_multiple "\0" "end cu.sa exploration" {
205 -re ".*$enter_field_number_prompt" {
206 pass "end cu.sa exploration"
207 gdb_test_multiple "\0" "end cu exploration" {
209 pass "end cu exploration"
219 ########################
220 # Type exploration tests
221 ########################
223 proc scalar_type_decsription {type} {
224 return "'$type' is a scalar type\."
227 proc child_scalar_type_description {path type} {
228 return "$path is of a scalar type '$type'\."
231 proc compound_type_description { type_name type_desc } {
232 return "'$type_name' is a $type_desc with the following fields:"
235 proc child_compound_type_description { path type_name type_desc } {
236 return "$path is a $type_desc of type '$type_name' with the following fields:"
239 proc child_array_type_description { path target_type_name } {
240 return "$path is an array of '$target_type_name'\."
243 proc typedef_type_description { type_name target_name } {
244 return "The type '$type_name' is a typedef of type '$target_name'\."
247 set SS_fields_types [field_choices {a} {d}]
248 set SU_fields_types [field_choices {i} {c} {f} {d}]
249 set CS_fields_types [field_choices {s} {u} {sa}]
250 set CU_fields_types [field_choices {s} {sa}]
252 set CS_field_0 "field 's' of 'struct ComplexStruct'"
253 set CS_field_1 "field 'u' of 'struct ComplexStruct'"
254 set CS_field_2 "field 'sa' of 'struct ComplexStruct'"
255 set CS_field_2_array_element "an array element of $CS_field_2"
257 set CU_field_0 "field 's' of 'union ComplexUnion'"
258 set CU_field_1 "field 'sa' of 'union ComplexUnion'"
259 set CU_field_1_array_element "an array element of $CU_field_1"
261 gdb_test "explore int" ".*[scalar_type_decsription {int}].*"
263 gdb_test_multiple "explore struct SimpleStruct" "" {
264 -re ".*[compound_type_description $SS {struct/class}].*$SS_fields_types.*" {
265 pass "explore struct SimpleStruct"
266 gdb_test_multiple "0" "explore type struct SimpleStruct feild 0" {
267 -re ".*[child_scalar_type_description {field 'a' of 'struct SimpleStruct'} {int}].*" {
268 pass "explore type struct SimpleStruct feild 0"
269 gdb_test_multiple "\0" "return to struct SimpleStruct from field 0" {
270 -re ".*[compound_type_description $SS {struct/class}].*$SS_fields_types.*" {
271 pass "return to struct SimpleStruct from field 0"
276 gdb_test_multiple "1" "explore type struct SimpleStruct feild 1" {
277 -re ".*[child_scalar_type_description {field 'd' of 'struct SimpleStruct'} {double}].*" {
278 pass "explore type struct SimpleStruct feild 1"
279 gdb_test_multiple "\0" "return to struct SimpleStruct from field 1" {
280 -re ".*[compound_type_description $SS {struct/class}].*$SS_fields_types.*" {
281 pass "return to struct SimpleStruct from field 1"
286 gdb_test_multiple "\0" "return to GDB prompt from struct SimpleStruct" {
288 pass "return to GDB prompt from struct SimpleStruct"
294 gdb_test_multiple "explore union SimpleUnion" "" {
295 -re ".*[compound_type_description $SU {union}].*$SU_fields_types.*" {
296 pass "explore union SimpleUnion"
297 gdb_test_multiple "0" "explore type union SimpleUnion feild 0" {
298 -re ".*[child_scalar_type_description {field 'i' of 'union SimpleUnion'} {int}].*" {
299 pass "explore type union SimpleUnion feild 0"
300 gdb_test_multiple "\0" "return to union SimpleUnion from field 0" {
301 -re ".*[compound_type_description $SU {union}].*$SU_fields_types.*" {
302 pass "return to union SimpleUnion from field 0"
307 gdb_test_multiple "1" "explore type union SimpleUnion feild 1" {
308 -re ".*[child_scalar_type_description {field 'c' of 'union SimpleUnion'} {char}].*" {
309 pass "explore type union SimpleUnion feild 1"
310 gdb_test_multiple "\0" "return to union SimpleUnion from field 1" {
311 -re ".*[compound_type_description $SU {union}].*$SU_fields_types.*" {
312 pass "return to union SimpleUnion from field 1"
317 gdb_test_multiple "2" "explore type union SimpleUnion feild 2" {
318 -re ".*[child_scalar_type_description {field 'f' of 'union SimpleUnion'} {float}].*" {
319 pass "explore type union SimpleUnion feild 2"
320 gdb_test_multiple "\0" "return to union SimpleUnion from field 2" {
321 -re ".*[compound_type_description $SU {union}].*$SU_fields_types.*" {
322 pass "return to union SimpleUnion from field 2"
327 gdb_test_multiple "3" "explore type union SimpleUnion feild 3" {
328 -re ".*[child_scalar_type_description {field 'd' of 'union SimpleUnion'} {double}].*" {
329 pass "explore type union SimpleUnion feild 3"
330 gdb_test_multiple "\0" "return to union SimpleUnion from field 3" {
331 -re ".*[compound_type_description $SU {union}].*$SU_fields_types.*" {
332 pass "return to union SimpleUnion from field 3"
337 gdb_test_multiple "\0" "return to GDB prompt from union SimpleUnion" {
339 pass "return to GDB prompt from union SimpleUnion"
345 gdb_test_multiple "explore SS" "" {
346 -re ".*[typedef_type_description {SS} $SS].*[compound_type_description {SS} {struct/class}].*$SS_fields_types.*" {
348 gdb_test_multiple "0" "explore type SS feild 0" {
349 -re ".*[child_scalar_type_description {field 'a' of 'SS'} {int}].*" {
350 pass "explore type SS feild 0"
351 gdb_test_multiple "\0" "return to SS from field 0" {
352 -re ".*[compound_type_description {SS} {struct/class}].*$SS_fields_types.*" {
353 pass "return to SS from field 0"
358 gdb_test_multiple "1" "explore type SS feild 1" {
359 -re ".*[child_scalar_type_description {field 'd' of 'SS'} {double}].*" {
360 pass "explore type SS feild 1"
361 gdb_test_multiple "\0" "return to struct SimpleStruct from field 1" {
362 -re ".*[compound_type_description {SS} {struct/class}].*$SS_fields_types.*" {
363 pass "return to SS field 1"
368 gdb_test_multiple "\0" "return to GDB prompt from SS" {
370 pass "return to GDB prompt from SS"
376 gdb_test_multiple "explore type struct ComplexStruct" "" {
377 -re ".*[compound_type_description $CS {struct/class}].*$CS_fields_types.*" {
378 pass "explore type struct ComplexStruct"
379 gdb_test_multiple "0" "explore type struct ComplexStruct field 0" {
380 -re ".*[child_compound_type_description $CS_field_0 $SS {struct/class}].*$SS_fields_types.*" {
381 pass "explore type struct ComplexStruct field 0"
382 gdb_test_multiple "\0" "return to ComplexStruct from field 0" {
383 -re ".*[compound_type_description $CS {struct/class}].*$CS_fields_types.*" {
384 pass "return to ComplexStruct from field 0"
389 gdb_test_multiple "1" "explore type struct ComplexStruct field 1" {
390 -re ".*[child_compound_type_description $CS_field_1 $SU {union}].*$SU_fields_types.*" {
391 pass "explore type struct ComplexStruct field 1"
392 gdb_test_multiple "\0" "return to ComplexStruct from field 1" {
393 -re ".*[compound_type_description $CS {struct/class}].*$CS_fields_types.*" {
394 pass "return to ComplexStruct from field 1"
399 gdb_test_multiple "2" "explore type struct ComplexStruct field 2" {
400 -re ".*[child_array_type_description $CS_field_2 {SS}].*" {
401 pass "explore type struct ComplexStruct field 2"
402 gdb_test_multiple "\0" "return to ComplexStruct from field 2" {
403 -re ".*[compound_type_description $CS {struct/class}].*$CS_fields_types.*" {
404 pass "return to ComplexStruct from field 2"
409 gdb_test_multiple "\0" "return to GDB prompt from ComplexStruct type exploration" {
411 pass "return to GDB prompt from ComplexStruct type exploration"
417 gdb_test_multiple "explore type union ComplexUnion" "" {
418 -re ".*[compound_type_description $CU {union}].*$CU_fields_types.*" {
419 pass "explore type union ComplexUnion"
420 gdb_test_multiple "0" "explore type union ComplexStruct field 0" {
421 -re ".*[child_compound_type_description $CU_field_0 $SS {struct/class}].*$SS_fields_types.*" {
422 pass "explore type union ComplexUnion field 0"
423 gdb_test_multiple "\0" "return to ComplexUnion from field 0" {
424 -re ".*[compound_type_description $CU {union}].*$CU_fields_types.*" {
425 pass "return to ComplexUnion from field 0"
430 gdb_test_multiple "1" "explore type union ComplexUnion field 1" {
431 -re ".*[child_array_type_description $CU_field_1 $SS].*" {
432 pass "explore type union ComplexUnion field 1"
433 gdb_test_multiple "\0" "return to ComplexUnion array" {
434 -re ".*[compound_type_description $CU {union}].*$CU_fields_types.*" {
435 pass "return to ComplexUnion from field 1"
440 gdb_test_multiple "\0" "return to GDB prompt from ComplexUnion type exploration" {
442 pass "return to GDB prompt from ComplexUnion type exploration"
448 with_test_prefix "using 'cu'" {
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"