1 # Copyright 1998, 2005, 2007, 2008, 2009, 2010 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 load_lib "trace-support.exp"
25 set testfile "collection"
26 set srcfile ${testfile}.c
27 set binfile $objdir/$subdir/$testfile
29 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
30 executable {debug nowarnings}] != "" } {
31 untested collection.exp
37 # 2) function args by name
39 # 4) function locals by name
41 # 6) registers by name ($sp, $fp?)
43 # 8) expressions (lots of different kinds: local and global)
52 proc test_register { reg test_id } {
56 send_gdb "print $reg\n"
58 -re "\\$\[0-9\]+ = \[x0\]+$cr$gdb_prompt " {
59 fail "collect $test_id: collected $reg (zero)"
61 -re "\\$\[0-9\]+ = \[x0-9a-fA-F\]+$cr$gdb_prompt " {
62 pass "collect $test_id: collected $reg"
64 -re "\[Ee\]rror.*$gdb_prompt " {
65 fail "collect $test_id: collected $reg (error)"
68 fail "collect $test_id: collected $reg (timeout)"
73 proc run_trace_experiment { msg test_func } {
77 -re ".*Breakpoint \[0-9\]+, begin .*$gdb_prompt $" {
79 -re ".*$gdb_prompt $" {
80 fail "collect $msg: advance to go"
83 fail "collect $msg: advance to go (timeout)"
88 "collect $msg: start trace experiment"
90 "Continuing.*Breakpoint \[0-9\]+, end.*" \
91 "collect $msg: run trace experiment"
94 "collect $msg: stop trace experiment"
95 gdb_test "tfind start" \
97 "collect $msg: tfind test frame"
105 proc gdb_collect_args_test { myargs msg } {
109 # Make sure we're in a sane starting state.
110 gdb_test "tstop" "" ""
111 gdb_test "tfind none" "" ""
112 gdb_delete_tracepoints
114 gdb_test "trace args_test_func" \
115 "Tracepoint \[0-9\]+ at .*" \
116 "collect $msg: set tracepoint"
117 gdb_trace_setactions "collect $msg: define actions" \
119 "collect $myargs" "^$"
122 run_trace_experiment $msg args_test_func
124 gdb_test "print argc" \
125 "\\$\[0-9\]+ = 1 '.001'$cr" \
126 "collect $msg: collected arg char"
127 gdb_test "print argi" \
128 "\\$\[0-9\]+ = 2$cr" \
129 "collect $msg: collected arg int"
130 gdb_test "print argf" \
131 "\\$\[0-9\]+ = 3.\[23\]\[0-9\]*$cr" \
132 "collect $msg: collected arg float"
133 gdb_test "print argd" \
134 "\\$\[0-9\]+ = 4.\[34\]\[0-9\]*$cr" \
135 "collect $msg: collected arg double"
137 # struct arg as one of several args (near end of list)
138 gdb_test "print argstruct.memberc" \
139 "\\$\[0-9\]+ = 101 'e'$cr" \
140 "collect $msg: collected arg struct member char"
141 gdb_test "print argstruct.memberi" \
142 "\\$\[0-9\]+ = 102$cr" \
143 "collect $msg: collected arg struct member int"
144 gdb_test "print argstruct.memberf" \
145 "\\$\[0-9\]+ = 103.\[23\]\[0-9\]*$cr" \
146 "collect $msg: collected arg struct member float"
147 gdb_test "print argstruct.memberd" \
148 "\\$\[0-9\]+ = 104.\[34\]\[0-9\]*$cr" \
149 "collect $msg: collected arg struct member double"
151 # array arg as one of several args (near end of list)
152 gdb_test "print argarray\[0\]" \
153 "\\$\[0-9\]+ = 111$cr" \
154 "collect $msg: collected argarray #0"
155 gdb_test "print argarray\[1\]" \
156 "\\$\[0-9\]+ = 112$cr" \
157 "collect $msg: collected argarray #1"
158 gdb_test "print argarray\[2\]" \
159 "\\$\[0-9\]+ = 113$cr" \
160 "collect $msg: collected argarray #2"
161 gdb_test "print argarray\[3\]" \
162 "\\$\[0-9\]+ = 114$cr" \
163 "collect $msg: collected argarray #3"
165 gdb_test "tfind none" \
167 "collect $msg: cease trace debugging"
170 proc gdb_collect_argstruct_test { myargs msg } {
174 # Make sure we're in a sane starting state.
175 gdb_test "tstop" "" ""
176 gdb_test "tfind none" "" ""
177 gdb_delete_tracepoints
179 gdb_test "trace argstruct_test_func" \
180 "Tracepoint \[0-9\]+ at .*" \
181 "collect $msg: set tracepoint"
182 gdb_trace_setactions "collect $msg: define actions" \
184 "collect $myargs" "^$"
187 run_trace_experiment $msg argstruct_test_func
189 # struct argument as only argument
190 gdb_test "print argstruct.memberc" \
191 "\\$\[0-9\]+ = 101 'e'$cr" \
192 "collect $msg: collected arg struct member char"
193 gdb_test "print argstruct.memberi" \
194 "\\$\[0-9\]+ = 102$cr" \
195 "collect $msg: collected arg struct member int"
196 gdb_test "print argstruct.memberf" \
197 "\\$\[0-9\]+ = 103.\[23\]\[0-9\]*$cr" \
198 "collect $msg: collected arg struct member float"
199 gdb_test "print argstruct.memberd" \
200 "\\$\[0-9\]+ = 104.\[34\]\[0-9\]*$cr" \
201 "collect $msg: collected arg struct member double"
203 gdb_test "tfind none" \
205 "collect $msg: cease trace debugging"
209 proc gdb_collect_argarray_test { myargs msg } {
213 # Make sure we're in a sane starting state.
214 gdb_test "tstop" "" ""
215 gdb_test "tfind none" "" ""
216 gdb_delete_tracepoints
218 gdb_test "trace argarray_test_func" \
219 "Tracepoint \[0-9\]+ at .*" \
220 "collect $msg: set tracepoint"
221 gdb_trace_setactions "collect $msg: define actions" \
223 "collect $myargs" "^$"
226 run_trace_experiment $msg argarray_test_func
228 # array arg as only argument
229 gdb_test "print argarray\[0\]" \
230 "\\$\[0-9\]+ = 111$cr" \
231 "collect $msg: collected argarray #0"
232 gdb_test "print argarray\[1\]" \
233 "\\$\[0-9\]+ = 112$cr" \
234 "collect $msg: collected argarray #1"
235 gdb_test "print argarray\[2\]" \
236 "\\$\[0-9\]+ = 113$cr" \
237 "collect $msg: collected argarray #2"
238 gdb_test "print argarray\[3\]" \
239 "\\$\[0-9\]+ = 114$cr" \
240 "collect $msg: collected argarray #3"
242 gdb_test "tfind none" \
244 "collect $msg: cease trace debugging"
248 proc gdb_collect_locals_test { func mylocs msg } {
252 # Make sure we're in a sane starting state.
253 gdb_test "tstop" "" ""
254 gdb_test "tfind none" "" ""
255 gdb_delete_tracepoints
257 # Find the comment-identified line for setting this tracepoint.
259 send_gdb "list $func, +30\n"
261 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
262 set testline $expect_out(1,string)
263 pass "collect $msg: find tracepoint line"
265 -re ".*$gdb_prompt " {
266 fail "collect $msg: find tracepoint line (skipping locals test)"
270 fail "collect $msg: find tracepoint line (skipping locals test)"
275 gdb_test "trace $testline" \
276 "Tracepoint \[0-9\]+ at .*" \
277 "collect $msg: set tracepoint"
278 gdb_trace_setactions "collect $msg: define actions" \
280 "collect $mylocs" "^$"
283 run_trace_experiment $msg $func
285 gdb_test "print locc" \
286 "\\$\[0-9\]+ = 11 '.\[a-z0-7\]+'$cr" \
287 "collect $msg: collected local char"
288 gdb_test "print loci" \
289 "\\$\[0-9\]+ = 12$cr" \
290 "collect $msg: collected local int"
291 gdb_test "print locf" \
292 "\\$\[0-9\]+ = 13.\[23\]\[0-9\]*$cr" \
293 "collect $msg: collected local float"
294 gdb_test "print locd" \
295 "\\$\[0-9\]+ = 14.\[34\]\[0-9\]*$cr" \
296 "collect $msg: collected local double"
298 gdb_test "print locst.memberc" \
299 "\\$\[0-9\]+ = 15 '.017'$cr" \
300 "collect $msg: collected local member char"
301 gdb_test "print locst.memberi" \
302 "\\$\[0-9\]+ = 16$cr" \
303 "collect $msg: collected local member int"
304 gdb_test "print locst.memberf" \
305 "\\$\[0-9\]+ = 17.\[67\]\[0-9\]*$cr" \
306 "collect $msg: collected local member float"
307 gdb_test "print locst.memberd" \
308 "\\$\[0-9\]+ = 18.\[78\]\[0-9\]*$cr" \
309 "collect $msg: collected local member double"
311 gdb_test "print locar\[0\]" \
312 "\\$\[0-9\]+ = 121$cr" \
313 "collect $msg: collected locarray #0"
314 gdb_test "print locar\[1\]" \
315 "\\$\[0-9\]+ = 122$cr" \
316 "collect $msg: collected locarray #1"
317 gdb_test "print locar\[2\]" \
318 "\\$\[0-9\]+ = 123$cr" \
319 "collect $msg: collected locarray #2"
320 gdb_test "print locar\[3\]" \
321 "\\$\[0-9\]+ = 124$cr" \
322 "collect $msg: collected locarray #3"
325 gdb_test "tfind none" \
327 "collect $msg: cease trace debugging"
330 proc gdb_collect_registers_test { myregs } {
334 # Make sure we're in a sane starting state.
335 gdb_test "tstop" "" ""
336 gdb_test "tfind none" "" ""
337 gdb_delete_tracepoints
339 # We'll simply re-use the args_test_function for this test
340 gdb_test "trace args_test_func" \
341 "Tracepoint \[0-9\]+ at .*" \
342 "collect $myregs: set tracepoint"
343 gdb_trace_setactions "collect $myregs: define actions" \
345 "collect $myregs" "^$"
348 run_trace_experiment $myregs args_test_func
350 test_register "\$fp" $myregs
351 test_register "\$sp" $myregs
352 test_register "\$pc" $myregs
354 gdb_test "tfind none" \
356 "collect $myregs: cease trace debugging"
359 proc gdb_collect_expression_test { func expr val msg } {
363 # Make sure we're in a sane starting state.
364 gdb_test "tstop" "" ""
365 gdb_test "tfind none" "" ""
366 gdb_delete_tracepoints
368 # Find the comment-identified line for setting this tracepoint.
370 send_gdb "list $func, +30\n"
372 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
373 set testline $expect_out(1,string)
374 pass "collect $msg: find tracepoint line"
376 -re ".*$gdb_prompt " {
377 fail "collect $msg: find tracepoint line (skipping locals test)"
381 fail "collect $msg: find tracepoint line (skipping locals test)"
386 gdb_test "trace $testline" \
387 "Tracepoint \[0-9\]+ at .*" \
388 "collect $msg: set tracepoint"
389 gdb_trace_setactions "collect $msg: define actions" \
394 run_trace_experiment $msg $func
396 gdb_test "print $expr" \
397 "\\$\[0-9\]+ = $val$cr" \
398 "collect $msg: got expected value '$val'"
400 gdb_test "tfind none" \
402 "collect $msg: cease trace debugging"
405 proc gdb_collect_globals_test { } {
409 # Make sure we're in a sane starting state.
410 gdb_test "tstop" "" ""
411 gdb_test "tfind none" "" ""
412 gdb_delete_tracepoints
414 # Find the comment-identified line for setting this tracepoint.
416 send_gdb "list globals_test_func, +30\n"
418 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
419 set testline $expect_out(1,string)
420 pass "collect globals: find tracepoint line"
422 -re ".*$gdb_prompt " {
423 fail "collect globals: find tracepoint line (skipping global test)"
427 fail "collect globals: find tracepoint line (skipping global test)"
432 gdb_test "trace $testline" \
433 "Tracepoint \[0-9\]+ at .*" \
434 "collect globals: set tracepoint"
435 gdb_trace_setactions "collect globals: define actions" \
437 "collect globalc, globali, globalf, globald" "^$" \
438 "collect globalstruct, globalp, globalarr" "^$"
441 run_trace_experiment "globals" globals_test_func
443 gdb_test "print globalc" \
444 "\\$\[0-9\]+ = 71 'G'$cr" \
445 "collect globals: collected global char"
446 gdb_test "print globali" \
447 "\\$\[0-9\]+ = 72$cr" \
448 "collect globals: collected global int"
449 gdb_test "print globalf" \
450 "\\$\[0-9\]+ = 73.\[23\]\[0-9\]*$cr" \
451 "collect globals: collected global float"
452 gdb_test "print globald" \
453 "\\$\[0-9\]+ = 74.\[34\]\[0-9\]*$cr" \
454 "collect globals: collected global double"
456 gdb_test "print globalstruct.memberc" \
457 "\\$\[0-9\]+ = 81 'Q'$cr" \
458 "collect globals: collected struct char member"
459 gdb_test "print globalstruct.memberi" \
460 "\\$\[0-9\]+ = 82$cr" \
461 "collect globals: collected struct member int"
462 gdb_test "print globalstruct.memberf" \
463 "\\$\[0-9\]+ = 83.\[23\]\[0-9\]*$cr" \
464 "collect globals: collected struct member float"
465 gdb_test "print globalstruct.memberd" \
466 "\\$\[0-9\]+ = 84.\[34\]\[0-9\]*$cr" \
467 "collect globals: collected struct member double"
469 gdb_test "print globalp == &globalstruct" \
470 "\\$\[0-9\]+ = 1$cr" \
471 "collect globals: collected global pointer"
473 gdb_test "print globalarr\[1\]" \
474 "\\$\[0-9\]+ = 1$cr" \
475 "collect globals: collected global array element #1"
476 gdb_test "print globalarr\[2\]" \
477 "\\$\[0-9\]+ = 2$cr" \
478 "collect globals: collected global array element #2"
479 gdb_test "print globalarr\[3\]" \
480 "\\$\[0-9\]+ = 3$cr" \
481 "collect globals: collected global array element #3"
483 gdb_test "tfind none" \
485 "collect globals: cease trace debugging"
488 proc gdb_trace_collection_test { } {
491 gdb_test "set width 0" "" ""
494 # We generously give ourselves one "pass" if we successfully
495 # detect that this test cannot be run on this target!
496 if { ![gdb_target_supports_trace] } then {
497 pass "Current target does not support trace"
501 gdb_test "break begin" "" ""
502 gdb_test "break end" "" ""
503 gdb_collect_args_test "\$args" \
505 gdb_collect_args_test "argc, argi, argf, argd, argstruct, argarray" \
507 gdb_collect_argstruct_test "\$args" \
508 "argstruct collectively"
509 gdb_collect_argstruct_test "argstruct" \
510 "argstruct individually"
511 gdb_collect_argarray_test "\$args" \
512 "argarray collectively"
513 gdb_collect_argarray_test "argarray" \
514 "argarray individually"
515 gdb_collect_locals_test local_test_func "\$locals" \
516 "auto locals collectively"
517 gdb_collect_locals_test local_test_func \
518 "locc, loci, locf, locd, locst, locar" \
519 "auto locals individually"
520 gdb_collect_locals_test reglocal_test_func "\$locals" \
521 "register locals collectively"
522 gdb_collect_locals_test reglocal_test_func \
523 "locc, loci, locf, locd, locst, locar" \
524 "register locals individually"
525 gdb_collect_locals_test statlocal_test_func "\$locals" \
526 "static locals collectively"
527 gdb_collect_locals_test statlocal_test_func \
528 "locc, loci, locf, locd, locst, locar" \
529 "static locals individually"
531 gdb_collect_registers_test "\$regs"
532 gdb_collect_registers_test "\$fp, \$sp, \$pc"
533 gdb_collect_globals_test
540 # x->y (x->y->z, ...)
541 # x[2] (x[2][3], ...) (const index)
542 # x[y] (x[y][z], ...) (index to be char, short, long, float, double)
544 # We test the following operators by using them in an array index
545 # expression -- because the naked result of an operator is not really
546 # collected. To be sure the operator was evaluated correctly on the
547 # target, we have to actually use the result eg. in an array offset
549 # x[y + z] (tests addition: y and z various combos of types, sclasses)
550 # x[y - z] (tests subtraction) (ditto)
551 # x[y * z] (tests multiplication) (ditto)
552 # x[y / z] (tests division) (ditto)
553 # x[y % z] (tests modulo division) (ditto)
554 # x[y == z] (tests equality relation) (ditto) UNSUPPORTED
555 # x[y != z] (tests inequality relation) (ditto) UNSUPPORTED
556 # x[y > z] (tests greater-than relation) (ditto) UNSUPPORTED
557 # x[y < z] (tests less-than relation) (ditto) UNSUPPORTED
558 # x[y >= z] (tests greater-than-or-equal relation) (ditto) UNSUPPORTED
559 # x[y <= z] (tests less-than-or-equal relation) (ditto) UNSUPPORTED
560 # x[y && z] (tests logical and) (ditto) UNSUPPORTED
561 # x[y || z] (tests logical or) (ditto) UNSUPPORTED
562 # x[y & z] (tests binary and) (ditto) UNSUPPORTED
563 # x[y | z] (tests binary or) (ditto) UNSUPPORTED
564 # x[y ^ z] (tests binary xor) (ditto) UNSUPPORTED
565 # x[y ? z1 : z2] (tests ternary operator) (ditto) UNSUPPORTED
566 # x[y << z] (tests shift-left) (ditto) UNSUPPORTED
567 # x[y >> z] (tests shift-right) (ditto) UNSUPPORTED
568 # x[y = z] (tests assignment operator) (ditto) UNSUPPORTED
569 # x[++y] (tests pre-increment operator) (ditto) UNSUPPORTED
570 # x[--y] (tests pre-decrement operator) (ditto) UNSUPPORTED
571 # x[y++] (tests post-increment operator) (ditto) UNSUPPORTED
572 # x[y--] (tests post-decrement operator) (ditto) UNSUPPORTED
573 # x[+y] (tests unary plus) (ditto)
574 # x[-y] (tests unary minus) (ditto)
575 # x[!y] (tests logical not) (ditto) UNSUPPORTED
576 # x[~y] (tests binary not) (ditto) UNSUPPORTED
577 # x[(y, z)] (tests comma expression) (ditto)
581 gdb_collect_expression_test globals_test_func \
582 "globalstruct.memberi" "82" "a.b"
583 gdb_collect_expression_test globals_test_func \
584 "globalp->memberc" "81 'Q'" "a->b"
585 gdb_collect_expression_test globals_test_func \
586 "globalarr\[2\]" "2" "a\[2\]"
587 gdb_collect_expression_test globals_test_func \
588 "globalarr\[l3\]" "3" "a\[b\]"
589 gdb_collect_expression_test globals_test_func \
590 "globalarr\[l3 + l2\]" "5" "a\[b + c\]"
591 gdb_collect_expression_test globals_test_func \
592 "globalarr\[l3 - l2\]" "1" "a\[b - c\]"
593 gdb_collect_expression_test globals_test_func \
594 "globalarr\[l3 * l2\]" "6" "a\[b * c\]"
595 gdb_collect_expression_test globals_test_func \
596 "globalarr\[l6 / l3\]" "2" "a\[b / c\]"
597 gdb_collect_expression_test globals_test_func \
598 "globalarr\[l7 % l3\]" "1" "a\[b % c\]"
599 gdb_collect_expression_test globals_test_func \
600 "globalarr\[+l1\]" "1" "a\[+b\]"
601 gdb_collect_expression_test globals_test_func \
602 "globalarr\[-lminus\]" "2" "a\[-b\]"
603 gdb_collect_expression_test globals_test_func \
604 "globalarr\[\(l6, l7\)\]" "7" "a\[\(b, c\)\]"
608 # Start with a fresh gdb.
612 gdb_reinitialize_dir $srcdir/$subdir
615 if [target_info exists gdb_stub] {
619 # Body of test encased in a proc so we can return prematurely.
620 gdb_trace_collection_test
623 gdb_test "tfind none" "" ""