Commit | Line | Data |
---|---|---|
06fc020f SCR |
1 | # Copyright 2012 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 | ||
b4a58790 TT |
16 | standard_testfile |
17 | ||
06fc020f SCR |
18 | if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { |
19 | return -1 | |
20 | } | |
21 | ||
22 | # Skip all tests if Python scripting is not enabled. | |
23 | if { [skip_python_tests] } { continue } | |
24 | ||
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 .*: } | |
32 | ||
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\]+" | |
35 | } | |
36 | ||
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\]+" | |
39 | } | |
40 | ||
41 | proc scalar_description { value_name type } { | |
42 | return "'$value_name' is a scalar value of type '$type'\.\[\r\n\]+" | |
43 | } | |
44 | ||
45 | proc array_description { value_name type } { | |
46 | return "'$value_name' is an array of '$type'\.\[\r\n\]+" | |
47 | } | |
48 | ||
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" | |
53 | } | |
54 | ||
55 | proc field_values { args } { | |
56 | set result "" | |
57 | foreach field $args { | |
58 | set result "$result\[ \]*$field \[\.\]\[\.\] \[\(\]Value of type .*\[\)\]\[\r\n\]+" | |
59 | } | |
60 | return $result | |
61 | } | |
62 | ||
63 | proc field_choices { args } { | |
64 | set result "" | |
65 | set field_num 0 | |
66 | foreach field $args { | |
67 | set result "$result$field\[ \]+=\[ \]+<Enter $field_num to explore this field of type .*" | |
68 | incr field_num | |
69 | } | |
70 | return $result | |
71 | } | |
72 | ||
73 | proc scalar_value { value_name value } { | |
74 | return "$value_name = $value\[r\n\]+" | |
75 | } | |
76 | ||
77 | set SS_fields [field_values {a = 10} {d = 100[.].*}] | |
78 | ||
79 | if ![runto_main] { | |
80 | return -1 | |
81 | } | |
82 | ||
83 | gdb_breakpoint [gdb_get_line_number "Break here."] | |
84 | gdb_continue_to_breakpoint "Break here" ".*Break here.*" | |
85 | ||
86 | ######################### | |
87 | # Value exploration tests | |
88 | ######################### | |
89 | ||
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" | |
94 | ||
95 | gdb_test_multiple "explore ss_ptr" "" { | |
96 | -re "[pointer_description {ss_ptr} $SS].*" { | |
97 | pass "explore ss_ptr" | |
98 | gdb_test_multiple "y" "explore_as_single_value_pointer" { | |
99 | -re "$SS_fields" { | |
100 | pass "explore ss_ptr as single value pointer" | |
101 | } | |
102 | } | |
103 | } | |
104 | } | |
105 | ||
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\]+" { | |
123 | pass "end explore_as_array" | |
124 | } | |
125 | } | |
126 | } | |
127 | } | |
128 | } | |
129 | } | |
130 | } | |
131 | } | |
132 | } | |
133 | } | |
134 | } | |
135 | } | |
136 | ||
137 | gdb_test_multiple "explore su" "" { | |
138 | -re "[compound_description {su} {union} {union SimpleUnion}].*[field_choices {i} {c} {f} {d}].*$enter_field_number_prompt" { | |
139 | pass "explore su" | |
140 | gdb_test_multiple "3" "explore su.d" { | |
141 | -re "[scalar_description {su.d} {double}].*[scalar_value {su.d} {100[.].*}].*$return_to_parent_prompt" { | |
142 | pass "explore su.d" | |
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" { | |
147 | -re "$gdb_prompt" { | |
148 | pass "end su exploration" | |
149 | } | |
150 | } | |
151 | } | |
152 | } | |
153 | } | |
154 | } | |
155 | } | |
156 | } | |
157 | ||
158 | gdb_test_multiple "explore cs" "" { | |
159 | -re "[compound_description {cs} {struct/class} {struct ComplexStruct}].*[field_choices {s} {u} {sa}].*$enter_field_number_prompt" { | |
160 | pass "explore cs" | |
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" { | |
163 | pass "explore cs.s" | |
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" { | |
168 | -re "$gdb_prompt" { | |
169 | pass "end cs exploration" | |
170 | } | |
171 | } | |
172 | } | |
173 | } | |
174 | } | |
175 | } | |
176 | } | |
177 | } | |
178 | ||
179 | gdb_test_multiple "explore cu" "" { | |
180 | -re "[compound_description {cu} {union} {union ComplexUnion}].*[field_choices {s} {sa}].*$enter_field_number_prompt" { | |
181 | pass "explore cu" | |
182 | gdb_test_multiple "1" "explore cu.sa" { | |
183 | -re ".*[array_description {cu.sa} $SS].*$array_index_prompt" { | |
184 | pass "explore cu.sa" | |
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" | |
191 | } | |
192 | } | |
193 | } | |
194 | } | |
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" { | |
199 | -re "$gdb_prompt" { | |
200 | pass "end cu exploration" | |
201 | } | |
202 | } | |
203 | } | |
204 | } | |
205 | } | |
206 | } | |
207 | } | |
208 | } | |
209 | ||
210 | ######################## | |
211 | # Type exploration tests | |
212 | ######################## | |
213 | ||
214 | proc scalar_type_decsription {type} { | |
215 | return "'$type' is a scalar type\." | |
216 | } | |
217 | ||
218 | proc child_scalar_type_description {path type} { | |
219 | return "$path is of a scalar type '$type'\." | |
220 | } | |
221 | ||
222 | proc compound_type_description { type_name type_desc } { | |
223 | return "'$type_name' is a $type_desc with the following fields:" | |
224 | } | |
225 | ||
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:" | |
228 | } | |
229 | ||
230 | proc child_array_type_description { path target_type_name } { | |
231 | return "$path is an array of '$target_type_name'\." | |
232 | } | |
233 | ||
234 | proc typedef_type_description { type_name target_name } { | |
235 | return "The type '$type_name' is a typedef of type '$target_name'\." | |
236 | } | |
237 | ||
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}] | |
242 | ||
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" | |
247 | ||
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" | |
251 | ||
252 | gdb_test "explore int" ".*[scalar_type_decsription {int}].*" | |
253 | ||
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" | |
263 | } | |
264 | } | |
265 | } | |
266 | } | |
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" | |
273 | } | |
274 | } | |
275 | } | |
276 | } | |
277 | gdb_test_multiple "\0" "return to GDB prompt from struct SimpleStruct" { | |
278 | -re "$gdb_prompt" { | |
279 | pass "return to GDB prompt from struct SimpleStruct" | |
280 | } | |
281 | } | |
282 | } | |
283 | } | |
284 | ||
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" | |
294 | } | |
295 | } | |
296 | } | |
297 | } | |
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" | |
304 | } | |
305 | } | |
306 | } | |
307 | } | |
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" | |
314 | } | |
315 | } | |
316 | } | |
317 | } | |
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" | |
324 | } | |
325 | } | |
326 | } | |
327 | } | |
328 | gdb_test_multiple "\0" "return to GDB prompt from union SimpleUnion" { | |
329 | -re "$gdb_prompt" { | |
330 | pass "return to GDB prompt from union SimpleUnion" | |
331 | } | |
332 | } | |
333 | } | |
334 | } | |
335 | ||
336 | gdb_test_multiple "explore SS" "" { | |
337 | -re ".*[typedef_type_description {SS} $SS].*[compound_type_description {SS} {struct/class}].*$SS_fields_types.*" { | |
338 | pass "explore SS" | |
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" | |
345 | } | |
346 | } | |
347 | } | |
348 | } | |
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" | |
355 | } | |
356 | } | |
357 | } | |
358 | } | |
359 | gdb_test_multiple "\0" "return to GDB prompt from SS" { | |
360 | -re "$gdb_prompt" { | |
361 | pass "return to GDB prompt from SS" | |
362 | } | |
363 | } | |
364 | } | |
365 | } | |
366 | ||
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" | |
376 | } | |
377 | } | |
378 | } | |
379 | } | |
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" | |
386 | } | |
387 | } | |
388 | } | |
389 | } | |
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" | |
396 | } | |
397 | } | |
398 | } | |
399 | } | |
400 | gdb_test_multiple "\0" "return to GDB prompt from ComplexStruct type exploration" { | |
401 | -re "$gdb_prompt" { | |
402 | pass "return to GDB prompt from ComplexStruct type exploration" | |
403 | } | |
404 | } | |
405 | } | |
406 | } | |
407 | ||
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" | |
417 | } | |
418 | } | |
419 | } | |
420 | } | |
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" | |
427 | } | |
428 | } | |
429 | } | |
430 | } | |
431 | gdb_test_multiple "\0" "return to GDB prompt from ComplexUnion type exploration" { | |
432 | -re "$gdb_prompt" { | |
433 | pass "return to GDB prompt from ComplexUnion type exploration" | |
434 | } | |
435 | } | |
436 | } | |
437 | } | |
438 | ||
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" | |
448 | } | |
449 | } | |
450 | } | |
451 | } | |
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" | |
458 | } | |
459 | } | |
460 | } | |
461 | } | |
462 | gdb_test_multiple "\0" "return to GDB prompt from ComplexUnion type exploration" { | |
463 | -re "$gdb_prompt" { | |
464 | pass "return to GDB prompt from ComplexUnion type exploration" | |
465 | } | |
466 | } | |
467 | } | |
468 | } |