]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.python/py-explore.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-explore.exp
1 # Copyright 2012-2024 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 standard_testfile
17
18 require allow_python_tests
19
20 if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
21 return -1
22 }
23
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 .*: }
31
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\]+"
34 }
35
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\]+"
38 }
39
40 proc scalar_description { value_name type } {
41 return "'$value_name' is a scalar value of type '$type'\.\[\r\n\]+"
42 }
43
44 proc array_description { value_name type } {
45 return "'$value_name' is an array of '$type'\.\[\r\n\]+"
46 }
47
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"
52 }
53
54 proc field_values { args } {
55 set result ""
56 foreach field $args {
57 set result "$result\[ \]*$field \[\.\]\[\.\] \[\(\]Value of type .*\[\)\]\[\r\n\]+"
58 }
59 return $result
60 }
61
62 proc field_choices { args } {
63 set result ""
64 set field_num 0
65 foreach field $args {
66 set result "$result$field\[ \]+=\[ \]+<Enter $field_num to explore this field of type .*"
67 incr field_num
68 }
69 return $result
70 }
71
72 proc scalar_value { value_name value } {
73 return "$value_name = $value\[r\n\]+"
74 }
75
76 set SS_fields [field_values {a = 10} {d = 100[.].*}]
77
78 if ![runto_main] {
79 return -1
80 }
81
82 gdb_breakpoint [gdb_get_line_number "Break here."]
83 gdb_continue_to_breakpoint "Break here" ".*Break here.*"
84
85 #########################
86 # Value exploration tests
87 #########################
88
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"
93
94 gdb_test_multiple "explore ss_ptr" "" {
95 -re "[pointer_description {ss_ptr} $SS].*" {
96 pass "explore ss_ptr"
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"
100 }
101 }
102 }
103 }
104
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"
123 }
124 }
125 }
126 }
127 }
128 }
129 }
130 }
131 }
132 }
133 }
134 }
135
136 gdb_test_multiple "explore su" "" {
137 -re "[compound_description {su} {union} {union SimpleUnion}].*[field_choices {i} {c} {f} {d}].*$enter_field_number_prompt" {
138 pass "explore su"
139 gdb_test_multiple "3" "explore su.d" {
140 -re "[scalar_description {su.d} {double}].*[scalar_value {su.d} {100[.].*}].*$return_to_parent_prompt" {
141 pass "explore su.d"
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" {
146 -re "$gdb_prompt" {
147 pass "end su exploration"
148 }
149 }
150 }
151 }
152 }
153 }
154 }
155 }
156
157 gdb_test_multiple "explore cs" "" {
158 -re "[compound_description {cs} {struct/class} {struct ComplexStruct}].*[field_choices {s} {u} {sa}].*$enter_field_number_prompt" {
159 pass "explore cs"
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" {
162 pass "explore cs.s"
163 gdb_test_multiple " " "end cs.s exploration" {
164 -re ".*$enter_field_number_prompt" {
165 pass "end cs.s exploration"
166 }
167 }
168 }
169 }
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" {
172 pass "explore cs.u"
173 gdb_test_multiple " " "end cs.u exploration" {
174 -re ".*$enter_field_number_prompt" {
175 pass "end cs.u exploration"
176 }
177 }
178 }
179 }
180 gdb_test_multiple "\0" "explore cs.u" {
181 -re "$gdb_prompt" {
182 pass "end cs exploration"
183 }
184 }
185 }
186 }
187
188 gdb_test_multiple "explore cu" "" {
189 -re "[compound_description {cu} {union} {union ComplexUnion}].*[field_choices {s} {sa}].*$enter_field_number_prompt" {
190 pass "explore cu"
191 gdb_test_multiple "1" "explore cu.sa" {
192 -re ".*[array_description {cu.sa} $SS].*$array_index_prompt" {
193 pass "explore cu.sa"
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"
200 }
201 }
202 }
203 }
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" {
208 -re "$gdb_prompt" {
209 pass "end cu exploration"
210 }
211 }
212 }
213 }
214 }
215 }
216 }
217 }
218
219 ########################
220 # Type exploration tests
221 ########################
222
223 proc scalar_type_decsription {type} {
224 return "'$type' is a scalar type\."
225 }
226
227 proc child_scalar_type_description {path type} {
228 return "$path is of a scalar type '$type'\."
229 }
230
231 proc compound_type_description { type_name type_desc } {
232 return "'$type_name' is a $type_desc with the following fields:"
233 }
234
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:"
237 }
238
239 proc child_array_type_description { path target_type_name } {
240 return "$path is an array of '$target_type_name'\."
241 }
242
243 proc typedef_type_description { type_name target_name } {
244 return "The type '$type_name' is a typedef of type '$target_name'\."
245 }
246
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}]
251
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"
256
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"
260
261 gdb_test "explore int" ".*[scalar_type_decsription {int}].*"
262
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"
272 }
273 }
274 }
275 }
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"
282 }
283 }
284 }
285 }
286 gdb_test_multiple "\0" "return to GDB prompt from struct SimpleStruct" {
287 -re "$gdb_prompt" {
288 pass "return to GDB prompt from struct SimpleStruct"
289 }
290 }
291 }
292 }
293
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"
303 }
304 }
305 }
306 }
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"
313 }
314 }
315 }
316 }
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"
323 }
324 }
325 }
326 }
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"
333 }
334 }
335 }
336 }
337 gdb_test_multiple "\0" "return to GDB prompt from union SimpleUnion" {
338 -re "$gdb_prompt" {
339 pass "return to GDB prompt from union SimpleUnion"
340 }
341 }
342 }
343 }
344
345 gdb_test_multiple "explore SS" "" {
346 -re ".*[typedef_type_description {SS} $SS].*[compound_type_description {SS} {struct/class}].*$SS_fields_types.*" {
347 pass "explore SS"
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"
354 }
355 }
356 }
357 }
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"
364 }
365 }
366 }
367 }
368 gdb_test_multiple "\0" "return to GDB prompt from SS" {
369 -re "$gdb_prompt" {
370 pass "return to GDB prompt from SS"
371 }
372 }
373 }
374 }
375
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"
385 }
386 }
387 }
388 }
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"
395 }
396 }
397 }
398 }
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"
405 }
406 }
407 }
408 }
409 gdb_test_multiple "\0" "return to GDB prompt from ComplexStruct type exploration" {
410 -re "$gdb_prompt" {
411 pass "return to GDB prompt from ComplexStruct type exploration"
412 }
413 }
414 }
415 }
416
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"
426 }
427 }
428 }
429 }
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"
436 }
437 }
438 }
439 }
440 gdb_test_multiple "\0" "return to GDB prompt from ComplexUnion type exploration" {
441 -re "$gdb_prompt" {
442 pass "return to GDB prompt from ComplexUnion type exploration"
443 }
444 }
445 }
446 }
447
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"
458 }
459 }
460 }
461 }
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"
468 }
469 }
470 }
471 }
472 gdb_test_multiple "\0" "return to GDB prompt from ComplexUnion type exploration" {
473 -re "$gdb_prompt" {
474 pass "return to GDB prompt from ComplexUnion type exploration"
475 }
476 }
477 }
478 }
479 }