1 # Copyright 1998, 2005, 2007, 2008, 2009 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/>.
16 if [istarget "m68k-*-elf"] then {
17 pass "Test not supported on this target"
21 load_lib "trace-support.exp"
30 set testfile "collection"
31 set srcfile ${testfile}.c
32 set binfile $objdir/$subdir/$testfile
34 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
35 executable {debug nowarnings}] != "" } {
36 untested collection.exp
42 # 2) function args by name
44 # 4) function locals by name
46 # 6) registers by name ($sp, $fp?)
48 # 8) expressions (lots of different kinds: local and global)
57 proc test_register { reg test_id } {
61 send_gdb "print $reg\n"
63 -re "\\$\[0-9\]+ = \[x0\]+$cr$gdb_prompt " {
64 fail "collect $test_id: collected $reg (zero)"
66 -re "\\$\[0-9\]+ = \[x0-9a-fA-F\]+$cr$gdb_prompt " {
67 pass "collect $test_id: collected $reg"
69 -re "\[Ee\]rror.*$gdb_prompt " {
70 fail "collect $test_id: collected $reg (error)"
73 fail "collect $test_id: collected $reg (timeout)"
78 proc run_trace_experiment { msg test_func } {
82 -re ".*Breakpoint \[0-9\]+, begin .*$gdb_prompt $" {
84 -re ".*$gdb_prompt $" {
85 fail "collect $msg: advance to go"
88 fail "collect $msg: advance to go (timeout)"
93 "collect $msg: start trace experiment"
95 "Continuing.*Breakpoint \[0-9\]+, end.*" \
96 "collect $msg: run trace experiment"
99 "collect $msg: stop trace experiment"
100 gdb_test "tfind start" \
102 "collect $msg: tfind test frame"
110 proc gdb_collect_args_test { myargs msg } {
114 # Make sure we're in a sane starting state.
115 gdb_test "tstop" "" ""
116 gdb_test "tfind none" "" ""
117 gdb_delete_tracepoints
119 gdb_test "trace args_test_func" \
120 "Tracepoint \[0-9\]+ at .*" \
121 "collect $msg: set tracepoint"
122 gdb_trace_setactions "collect $msg: define actions" \
124 "collect $myargs" "^$"
127 run_trace_experiment $msg args_test_func
129 gdb_test "print argc" \
130 "\\$\[0-9\]+ = 1 '.001'$cr" \
131 "collect $msg: collected arg char"
132 gdb_test "print argi" \
133 "\\$\[0-9\]+ = 2$cr" \
134 "collect $msg: collected arg int"
135 gdb_test "print argf" \
136 "\\$\[0-9\]+ = 3.\[23\]\[0-9\]*$cr" \
137 "collect $msg: collected arg float"
138 gdb_test "print argd" \
139 "\\$\[0-9\]+ = 4.\[34\]\[0-9\]*$cr" \
140 "collect $msg: collected arg double"
142 # struct arg as one of several args (near end of list)
143 gdb_test "print argstruct.memberc" \
144 "\\$\[0-9\]+ = 101 'e'$cr" \
145 "collect $msg: collected arg struct member char"
146 gdb_test "print argstruct.memberi" \
147 "\\$\[0-9\]+ = 102$cr" \
148 "collect $msg: collected arg struct member int"
149 gdb_test "print argstruct.memberf" \
150 "\\$\[0-9\]+ = 103.\[23\]\[0-9\]*$cr" \
151 "collect $msg: collected arg struct member float"
152 gdb_test "print argstruct.memberd" \
153 "\\$\[0-9\]+ = 104.\[34\]\[0-9\]*$cr" \
154 "collect $msg: collected arg struct member double"
156 # array arg as one of several args (near end of list)
157 gdb_test "print argarray\[0\]" \
158 "\\$\[0-9\]+ = 111$cr" \
159 "collect $msg: collected argarray #0"
160 gdb_test "print argarray\[1\]" \
161 "\\$\[0-9\]+ = 112$cr" \
162 "collect $msg: collected argarray #1"
163 gdb_test "print argarray\[2\]" \
164 "\\$\[0-9\]+ = 113$cr" \
165 "collect $msg: collected argarray #2"
166 gdb_test "print argarray\[3\]" \
167 "\\$\[0-9\]+ = 114$cr" \
168 "collect $msg: collected argarray #3"
170 gdb_test "tfind none" \
172 "collect $msg: cease trace debugging"
175 proc gdb_collect_argstruct_test { myargs msg } {
179 # Make sure we're in a sane starting state.
180 gdb_test "tstop" "" ""
181 gdb_test "tfind none" "" ""
182 gdb_delete_tracepoints
184 gdb_test "trace argstruct_test_func" \
185 "Tracepoint \[0-9\]+ at .*" \
186 "collect $msg: set tracepoint"
187 gdb_trace_setactions "collect $msg: define actions" \
189 "collect $myargs" "^$"
192 run_trace_experiment $msg argstruct_test_func
194 # struct argument as only argument
195 gdb_test "print argstruct.memberc" \
196 "\\$\[0-9\]+ = 101 'e'$cr" \
197 "collect $msg: collected arg struct member char"
198 gdb_test "print argstruct.memberi" \
199 "\\$\[0-9\]+ = 102$cr" \
200 "collect $msg: collected arg struct member int"
201 gdb_test "print argstruct.memberf" \
202 "\\$\[0-9\]+ = 103.\[23\]\[0-9\]*$cr" \
203 "collect $msg: collected arg struct member float"
204 gdb_test "print argstruct.memberd" \
205 "\\$\[0-9\]+ = 104.\[34\]\[0-9\]*$cr" \
206 "collect $msg: collected arg struct member double"
208 gdb_test "tfind none" \
210 "collect $msg: cease trace debugging"
214 proc gdb_collect_argarray_test { myargs msg } {
218 # Make sure we're in a sane starting state.
219 gdb_test "tstop" "" ""
220 gdb_test "tfind none" "" ""
221 gdb_delete_tracepoints
223 gdb_test "trace argarray_test_func" \
224 "Tracepoint \[0-9\]+ at .*" \
225 "collect $msg: set tracepoint"
226 gdb_trace_setactions "collect $msg: define actions" \
228 "collect $myargs" "^$"
231 run_trace_experiment $msg argarray_test_func
233 # array arg as only argument
234 gdb_test "print argarray\[0\]" \
235 "\\$\[0-9\]+ = 111$cr" \
236 "collect $msg: collected argarray #0"
237 gdb_test "print argarray\[1\]" \
238 "\\$\[0-9\]+ = 112$cr" \
239 "collect $msg: collected argarray #1"
240 gdb_test "print argarray\[2\]" \
241 "\\$\[0-9\]+ = 113$cr" \
242 "collect $msg: collected argarray #2"
243 gdb_test "print argarray\[3\]" \
244 "\\$\[0-9\]+ = 114$cr" \
245 "collect $msg: collected argarray #3"
247 gdb_test "tfind none" \
249 "collect $msg: cease trace debugging"
253 proc gdb_collect_locals_test { func mylocs msg } {
257 # Make sure we're in a sane starting state.
258 gdb_test "tstop" "" ""
259 gdb_test "tfind none" "" ""
260 gdb_delete_tracepoints
262 # Find the comment-identified line for setting this tracepoint.
264 send_gdb "list $func, +30\n"
266 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
267 set testline $expect_out(1,string)
268 pass "collect $msg: find tracepoint line"
270 -re ".*$gdb_prompt " {
271 fail "collect $msg: find tracepoint line (skipping locals test)"
275 fail "collect $msg: find tracepoint line (skipping locals test)"
280 gdb_test "trace $testline" \
281 "Tracepoint \[0-9\]+ at .*" \
282 "collect $msg: set tracepoint"
283 gdb_trace_setactions "collect $msg: define actions" \
285 "collect $mylocs" "^$"
288 run_trace_experiment $msg $func
290 gdb_test "print locc" \
291 "\\$\[0-9\]+ = 11 '.\[a-z0-7\]+'$cr" \
292 "collect $msg: collected local char"
293 gdb_test "print loci" \
294 "\\$\[0-9\]+ = 12$cr" \
295 "collect $msg: collected local int"
296 gdb_test "print locf" \
297 "\\$\[0-9\]+ = 13.\[23\]\[0-9\]*$cr" \
298 "collect $msg: collected local float"
299 gdb_test "print locd" \
300 "\\$\[0-9\]+ = 14.\[34\]\[0-9\]*$cr" \
301 "collect $msg: collected local double"
303 gdb_test "print locst.memberc" \
304 "\\$\[0-9\]+ = 15 '.017'$cr" \
305 "collect $msg: collected local member char"
306 gdb_test "print locst.memberi" \
307 "\\$\[0-9\]+ = 16$cr" \
308 "collect $msg: collected local member int"
309 gdb_test "print locst.memberf" \
310 "\\$\[0-9\]+ = 17.\[67\]\[0-9\]*$cr" \
311 "collect $msg: collected local member float"
312 gdb_test "print locst.memberd" \
313 "\\$\[0-9\]+ = 18.\[78\]\[0-9\]*$cr" \
314 "collect $msg: collected local member double"
316 gdb_test "print locar\[0\]" \
317 "\\$\[0-9\]+ = 121$cr" \
318 "collect $msg: collected locarray #0"
319 gdb_test "print locar\[1\]" \
320 "\\$\[0-9\]+ = 122$cr" \
321 "collect $msg: collected locarray #1"
322 gdb_test "print locar\[2\]" \
323 "\\$\[0-9\]+ = 123$cr" \
324 "collect $msg: collected locarray #2"
325 gdb_test "print locar\[3\]" \
326 "\\$\[0-9\]+ = 124$cr" \
327 "collect $msg: collected locarray #3"
330 gdb_test "tfind none" \
332 "collect $msg: cease trace debugging"
335 proc gdb_collect_registers_test { myregs } {
339 # Make sure we're in a sane starting state.
340 gdb_test "tstop" "" ""
341 gdb_test "tfind none" "" ""
342 gdb_delete_tracepoints
344 # We'll simply re-use the args_test_function for this test
345 gdb_test "trace args_test_func" \
346 "Tracepoint \[0-9\]+ at .*" \
347 "collect $myregs: set tracepoint"
348 gdb_trace_setactions "collect $myregs: define actions" \
350 "collect $myregs" "^$"
353 run_trace_experiment $myregs args_test_func
355 test_register "\$fp" $myregs
356 test_register "\$sp" $myregs
357 test_register "\$pc" $myregs
359 gdb_test "tfind none" \
361 "collect $myregs: cease trace debugging"
364 proc gdb_collect_expression_test { func expr val msg } {
368 # Make sure we're in a sane starting state.
369 gdb_test "tstop" "" ""
370 gdb_test "tfind none" "" ""
371 gdb_delete_tracepoints
373 # Find the comment-identified line for setting this tracepoint.
375 send_gdb "list $func, +30\n"
377 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
378 set testline $expect_out(1,string)
379 pass "collect $msg: find tracepoint line"
381 -re ".*$gdb_prompt " {
382 fail "collect $msg: find tracepoint line (skipping locals test)"
386 fail "collect $msg: find tracepoint line (skipping locals test)"
391 gdb_test "trace $testline" \
392 "Tracepoint \[0-9\]+ at .*" \
393 "collect $msg: set tracepoint"
394 gdb_trace_setactions "collect $msg: define actions" \
399 run_trace_experiment $msg $func
401 gdb_test "print $expr" \
402 "\\$\[0-9\]+ = $val$cr" \
403 "collect $msg: got expected value '$val'"
405 gdb_test "tfind none" \
407 "collect $msg: cease trace debugging"
410 proc gdb_collect_globals_test { } {
414 # Make sure we're in a sane starting state.
415 gdb_test "tstop" "" ""
416 gdb_test "tfind none" "" ""
417 gdb_delete_tracepoints
419 # Find the comment-identified line for setting this tracepoint.
421 send_gdb "list globals_test_func, +30\n"
423 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
424 set testline $expect_out(1,string)
425 pass "collect globals: find tracepoint line"
427 -re ".*$gdb_prompt " {
428 fail "collect globals: find tracepoint line (skipping global test)"
432 fail "collect globals: find tracepoint line (skipping global test)"
437 gdb_test "trace $testline" \
438 "Tracepoint \[0-9\]+ at .*" \
439 "collect globals: set tracepoint"
440 gdb_trace_setactions "collect globals: define actions" \
442 "collect globalc, globali, globalf, globald" "^$" \
443 "collect globalstruct, globalp, globalarr" "^$"
446 run_trace_experiment "globals" globals_test_func
448 gdb_test "print globalc" \
449 "\\$\[0-9\]+ = 71 'G'$cr" \
450 "collect globals: collected global char"
451 gdb_test "print globali" \
452 "\\$\[0-9\]+ = 72$cr" \
453 "collect globals: collected global int"
454 gdb_test "print globalf" \
455 "\\$\[0-9\]+ = 73.\[23\]\[0-9\]*$cr" \
456 "collect globals: collected global float"
457 gdb_test "print globald" \
458 "\\$\[0-9\]+ = 74.\[34\]\[0-9\]*$cr" \
459 "collect globals: collected global double"
461 gdb_test "print globalstruct.memberc" \
462 "\\$\[0-9\]+ = 81 'Q'$cr" \
463 "collect globals: collected struct char member"
464 gdb_test "print globalstruct.memberi" \
465 "\\$\[0-9\]+ = 82$cr" \
466 "collect globals: collected struct member int"
467 gdb_test "print globalstruct.memberf" \
468 "\\$\[0-9\]+ = 83.\[23\]\[0-9\]*$cr" \
469 "collect globals: collected struct member float"
470 gdb_test "print globalstruct.memberd" \
471 "\\$\[0-9\]+ = 84.\[34\]\[0-9\]*$cr" \
472 "collect globals: collected struct member double"
474 gdb_test "print globalp == &globalstruct" \
475 "\\$\[0-9\]+ = 1$cr" \
476 "collect globals: collected global pointer"
478 gdb_test "print globalarr\[1\]" \
479 "\\$\[0-9\]+ = 1$cr" \
480 "collect globals: collected global array element #1"
481 gdb_test "print globalarr\[2\]" \
482 "\\$\[0-9\]+ = 2$cr" \
483 "collect globals: collected global array element #2"
484 gdb_test "print globalarr\[3\]" \
485 "\\$\[0-9\]+ = 3$cr" \
486 "collect globals: collected global array element #3"
488 gdb_test "tfind none" \
490 "collect globals: cease trace debugging"
493 proc gdb_trace_collection_test { } {
496 gdb_test "set width 0" "" ""
499 # We generously give ourselves one "pass" if we successfully
500 # detect that this test cannot be run on this target!
501 if { ![gdb_target_supports_trace] } then {
502 pass "Current target does not support trace"
506 gdb_test "break begin" "" ""
507 gdb_test "break end" "" ""
508 gdb_collect_args_test "\$args" \
510 gdb_collect_args_test "argc, argi, argf, argd, argstruct, argarray" \
512 gdb_collect_argstruct_test "\$args" \
513 "argstruct collectively"
514 gdb_collect_argstruct_test "argstruct" \
515 "argstruct individually"
516 gdb_collect_argarray_test "\$args" \
517 "argarray collectively"
518 gdb_collect_argarray_test "argarray" \
519 "argarray individually"
520 gdb_collect_locals_test local_test_func "\$locals" \
521 "auto locals collectively"
522 gdb_collect_locals_test local_test_func \
523 "locc, loci, locf, locd, locst, locar" \
524 "auto locals individually"
525 gdb_collect_locals_test reglocal_test_func "\$locals" \
526 "register locals collectively"
527 gdb_collect_locals_test reglocal_test_func \
528 "locc, loci, locf, locd, locst, locar" \
529 "register locals individually"
530 gdb_collect_locals_test statlocal_test_func "\$locals" \
531 "static locals collectively"
532 gdb_collect_locals_test statlocal_test_func \
533 "locc, loci, locf, locd, locst, locar" \
534 "static locals individually"
536 gdb_collect_registers_test "\$regs"
537 gdb_collect_registers_test "\$fp, \$sp, \$pc"
538 gdb_collect_globals_test
545 # x->y (x->y->z, ...)
546 # x[2] (x[2][3], ...) (const index)
547 # x[y] (x[y][z], ...) (index to be char, short, long, float, double)
549 # We test the following operators by using them in an array index
550 # expression -- because the naked result of an operator is not really
551 # collected. To be sure the operator was evaluated correctly on the
552 # target, we have to actually use the result eg. in an array offset
554 # x[y + z] (tests addition: y and z various combos of types, sclasses)
555 # x[y - z] (tests subtraction) (ditto)
556 # x[y * z] (tests multiplication) (ditto)
557 # x[y / z] (tests division) (ditto)
558 # x[y % z] (tests modulo division) (ditto)
559 # x[y == z] (tests equality relation) (ditto) UNSUPPORTED
560 # x[y != z] (tests inequality relation) (ditto) UNSUPPORTED
561 # x[y > z] (tests greater-than relation) (ditto) UNSUPPORTED
562 # x[y < z] (tests less-than relation) (ditto) UNSUPPORTED
563 # x[y >= z] (tests greater-than-or-equal relation) (ditto) UNSUPPORTED
564 # x[y <= z] (tests less-than-or-equal relation) (ditto) UNSUPPORTED
565 # x[y && z] (tests logical and) (ditto) UNSUPPORTED
566 # x[y || z] (tests logical or) (ditto) UNSUPPORTED
567 # x[y & z] (tests binary and) (ditto) UNSUPPORTED
568 # x[y | z] (tests binary or) (ditto) UNSUPPORTED
569 # x[y ^ z] (tests binary xor) (ditto) UNSUPPORTED
570 # x[y ? z1 : z2] (tests ternary operator) (ditto) UNSUPPORTED
571 # x[y << z] (tests shift-left) (ditto) UNSUPPORTED
572 # x[y >> z] (tests shift-right) (ditto) UNSUPPORTED
573 # x[y = z] (tests assignment operator) (ditto) UNSUPPORTED
574 # x[++y] (tests pre-increment operator) (ditto) UNSUPPORTED
575 # x[--y] (tests pre-decrement operator) (ditto) UNSUPPORTED
576 # x[y++] (tests post-increment operator) (ditto) UNSUPPORTED
577 # x[y--] (tests post-decrement operator) (ditto) UNSUPPORTED
578 # x[+y] (tests unary plus) (ditto)
579 # x[-y] (tests unary minus) (ditto)
580 # x[!y] (tests logical not) (ditto) UNSUPPORTED
581 # x[~y] (tests binary not) (ditto) UNSUPPORTED
582 # x[(y, z)] (tests comma expression) (ditto)
586 gdb_collect_expression_test globals_test_func \
587 "globalstruct.memberi" "82" "a.b"
588 gdb_collect_expression_test globals_test_func \
589 "globalp->memberc" "81 'Q'" "a->b"
590 gdb_collect_expression_test globals_test_func \
591 "globalarr\[2\]" "2" "a\[2\]"
592 gdb_collect_expression_test globals_test_func \
593 "globalarr\[l3\]" "3" "a\[b\]"
594 gdb_collect_expression_test globals_test_func \
595 "globalarr\[l3 + l2\]" "5" "a\[b + c\]"
596 gdb_collect_expression_test globals_test_func \
597 "globalarr\[l3 - l2\]" "1" "a\[b - c\]"
598 gdb_collect_expression_test globals_test_func \
599 "globalarr\[l3 * l2\]" "6" "a\[b * c\]"
600 gdb_collect_expression_test globals_test_func \
601 "globalarr\[l6 / l3\]" "2" "a\[b / c\]"
602 gdb_collect_expression_test globals_test_func \
603 "globalarr\[l7 % l3\]" "1" "a\[b % c\]"
604 gdb_collect_expression_test globals_test_func \
605 "globalarr\[+l1\]" "1" "a\[+b\]"
606 gdb_collect_expression_test globals_test_func \
607 "globalarr\[-lminus\]" "2" "a\[-b\]"
608 gdb_collect_expression_test globals_test_func \
609 "globalarr\[\(l6, l7\)\]" "7" "a\[\(b, c\)\]"
613 # Start with a fresh gdb.
617 gdb_reinitialize_dir $srcdir/$subdir
620 if [target_info exists gdb_stub] {
624 # Body of test encased in a proc so we can return prematurely.
625 gdb_trace_collection_test
628 gdb_test "tfind none" "" ""