1 # Copyright 1998, 2005, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 load_lib "trace-support.exp"
24 set testfile "collection"
25 set srcfile ${testfile}.c
26 set executable $testfile
27 set binfile $objdir/$subdir/$executable
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)
48 if [istarget "x86_64-*"] then {
52 } elseif [istarget "i?86-*"] then {
66 proc test_register { reg test_id } {
70 gdb_test_multiple "print /x $reg" "" {
71 -re "\\$\[0-9\]+ = \[x0\]+$cr$gdb_prompt $" {
72 fail "collect $test_id: collected $reg (zero)"
74 -re "\\$\[0-9\]+ = \[x0-9a-fA-F\]+$cr$gdb_prompt $" {
75 pass "collect $test_id: collected $reg"
77 -re "\[Ee\]rror.*$gdb_prompt $" {
78 fail "collect $test_id: collected $reg (error)"
83 proc prepare_for_trace_test {} {
86 clean_restart $executable
90 gdb_test "break begin" ".*" ""
91 gdb_test "break end" ".*" ""
94 proc run_trace_experiment { msg test_func } {
98 ".*Breakpoint \[0-9\]+, begin .*" \
99 "collect $msg: advance to begin"
101 set test "collect $msg: start trace experiment"
102 gdb_test_multiple "tstart" "$test" {
103 -re "^tstart\r\n$gdb_prompt $" {
108 gdb_test "continue" \
109 "Continuing.*Breakpoint \[0-9\]+, end.*" \
110 "collect $msg: run trace experiment"
113 "collect $msg: stop trace experiment"
114 gdb_test "tfind start" \
116 "collect $msg: tfind test frame"
124 proc gdb_collect_args_test { myargs msg } {
128 prepare_for_trace_test
130 gdb_test "trace args_test_func" \
131 "Tracepoint \[0-9\]+ at .*" \
132 "collect $msg: set tracepoint"
133 gdb_trace_setactions "collect $msg: define actions" \
135 "collect $myargs" "^$"
138 run_trace_experiment $msg args_test_func
140 gdb_test "print argc" \
141 "\\$\[0-9\]+ = 1 '.001'$cr" \
142 "collect $msg: collected arg char"
143 gdb_test "print argi" \
144 "\\$\[0-9\]+ = 2$cr" \
145 "collect $msg: collected arg int"
146 gdb_test "print argf" \
147 "\\$\[0-9\]+ = 3.\[23\]\[0-9\]*$cr" \
148 "collect $msg: collected arg float"
149 gdb_test "print argd" \
150 "\\$\[0-9\]+ = 4.\[34\]\[0-9\]*$cr" \
151 "collect $msg: collected arg double"
153 # struct arg as one of several args (near end of list)
154 gdb_test "print argstruct.memberc" \
155 "\\$\[0-9\]+ = 101 'e'$cr" \
156 "collect $msg: collected arg struct member char"
157 gdb_test "print argstruct.memberi" \
158 "\\$\[0-9\]+ = 102$cr" \
159 "collect $msg: collected arg struct member int"
160 gdb_test "print argstruct.memberf" \
161 "\\$\[0-9\]+ = 103.\[23\]\[0-9\]*$cr" \
162 "collect $msg: collected arg struct member float"
163 gdb_test "print argstruct.memberd" \
164 "\\$\[0-9\]+ = 104.\[34\]\[0-9\]*$cr" \
165 "collect $msg: collected arg struct member double"
167 # array arg as one of several args (near end of list)
169 # It isn't clear why is the test assuming the array's elements are
170 # collected. In C, an array as function parameters is a special
171 # case; it's just a pointer into the caller's array, and as such,
172 # that's what normally the debug info describes. Maybe this was
173 # originaly written for a compiler where array parameters were
174 # really described as arrays in debug info.
177 gdb_test "print argarray\[0\]" \
178 "\\$\[0-9\]+ = 111$cr" \
179 "collect $msg: collected argarray #0"
182 gdb_test "print argarray\[1\]" \
183 "\\$\[0-9\]+ = 112$cr" \
184 "collect $msg: collected argarray #1"
187 gdb_test "print argarray\[2\]" \
188 "\\$\[0-9\]+ = 113$cr" \
189 "collect $msg: collected argarray #2"
192 gdb_test "print argarray\[3\]" \
193 "\\$\[0-9\]+ = 114$cr" \
194 "collect $msg: collected argarray #3"
196 gdb_test "tfind none" \
198 "collect $msg: cease trace debugging"
201 proc gdb_collect_argstruct_test { myargs msg } {
205 prepare_for_trace_test
207 gdb_test "trace argstruct_test_func" \
208 "Tracepoint \[0-9\]+ at .*" \
209 "collect $msg: set tracepoint"
210 gdb_trace_setactions "collect $msg: define actions" \
212 "collect $myargs" "^$"
215 run_trace_experiment $msg argstruct_test_func
217 # struct argument as only argument
218 gdb_test "print argstruct.memberc" \
219 "\\$\[0-9\]+ = 101 'e'$cr" \
220 "collect $msg: collected arg struct member char"
221 gdb_test "print argstruct.memberi" \
222 "\\$\[0-9\]+ = 102$cr" \
223 "collect $msg: collected arg struct member int"
224 gdb_test "print argstruct.memberf" \
225 "\\$\[0-9\]+ = 103.\[23\]\[0-9\]*$cr" \
226 "collect $msg: collected arg struct member float"
227 gdb_test "print argstruct.memberd" \
228 "\\$\[0-9\]+ = 104.\[34\]\[0-9\]*$cr" \
229 "collect $msg: collected arg struct member double"
231 gdb_test "tfind none" \
233 "collect $msg: cease trace debugging"
237 proc gdb_collect_argarray_test { myargs msg } {
241 prepare_for_trace_test
243 gdb_test "trace argarray_test_func" \
244 "Tracepoint \[0-9\]+ at .*" \
245 "collect $msg: set tracepoint"
246 gdb_trace_setactions "collect $msg: define actions" \
248 "collect $myargs" "^$"
251 run_trace_experiment $msg argarray_test_func
253 # array arg as only argument
255 # It isn't clear why is the test assuming the array's elements are
256 # collected. In C, an array as function parameters is a special
257 # case; it's just a pointer into the caller's array, and as such,
258 # that's what normally the debug info describes. Maybe this was
259 # originaly written for a compiler where array parameters were
260 # really described as arrays in debug info.
263 gdb_test "print argarray\[0\]" \
264 "\\$\[0-9\]+ = 111$cr" \
265 "collect $msg: collected argarray #0"
268 gdb_test "print argarray\[1\]" \
269 "\\$\[0-9\]+ = 112$cr" \
270 "collect $msg: collected argarray #1"
273 gdb_test "print argarray\[2\]" \
274 "\\$\[0-9\]+ = 113$cr" \
275 "collect $msg: collected argarray #2"
278 gdb_test "print argarray\[3\]" \
279 "\\$\[0-9\]+ = 114$cr" \
280 "collect $msg: collected argarray #3"
282 gdb_test "tfind none" \
284 "collect $msg: cease trace debugging"
288 proc gdb_collect_locals_test { func mylocs msg } {
292 prepare_for_trace_test
294 # Find the comment-identified line for setting this tracepoint.
296 gdb_test_multiple "list $func, +30" "collect $msg: find tracepoint line" {
297 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
298 set testline $expect_out(1,string)
299 pass "collect $msg: find tracepoint line"
301 -re ".*$gdb_prompt " {
302 fail "collect $msg: find tracepoint line (skipping locals test)"
306 fail "collect $msg: find tracepoint line (skipping locals test)"
311 gdb_test "trace $testline" \
312 "Tracepoint \[0-9\]+ at .*" \
313 "collect $msg: set tracepoint"
314 gdb_trace_setactions "collect $msg: define actions" \
316 "collect $mylocs" "^$"
319 run_trace_experiment $msg $func
321 gdb_test "print locc" \
322 "\\$\[0-9\]+ = 11 '.\[a-z0-7\]+'$cr" \
323 "collect $msg: collected local char"
324 gdb_test "print loci" \
325 "\\$\[0-9\]+ = 12$cr" \
326 "collect $msg: collected local int"
327 gdb_test "print locf" \
328 "\\$\[0-9\]+ = 13.\[23\]\[0-9\]*$cr" \
329 "collect $msg: collected local float"
330 gdb_test "print locd" \
331 "\\$\[0-9\]+ = 14.\[34\]\[0-9\]*$cr" \
332 "collect $msg: collected local double"
334 gdb_test "print locst.memberc" \
335 "\\$\[0-9\]+ = 15 '.017'$cr" \
336 "collect $msg: collected local member char"
337 gdb_test "print locst.memberi" \
338 "\\$\[0-9\]+ = 16$cr" \
339 "collect $msg: collected local member int"
340 gdb_test "print locst.memberf" \
341 "\\$\[0-9\]+ = 17.\[67\]\[0-9\]*$cr" \
342 "collect $msg: collected local member float"
343 gdb_test "print locst.memberd" \
344 "\\$\[0-9\]+ = 18.\[78\]\[0-9\]*$cr" \
345 "collect $msg: collected local member double"
347 gdb_test "print locar\[0\]" \
348 "\\$\[0-9\]+ = 121$cr" \
349 "collect $msg: collected locarray #0"
350 gdb_test "print locar\[1\]" \
351 "\\$\[0-9\]+ = 122$cr" \
352 "collect $msg: collected locarray #1"
353 gdb_test "print locar\[2\]" \
354 "\\$\[0-9\]+ = 123$cr" \
355 "collect $msg: collected locarray #2"
356 gdb_test "print locar\[3\]" \
357 "\\$\[0-9\]+ = 124$cr" \
358 "collect $msg: collected locarray #3"
361 gdb_test "tfind none" \
363 "collect $msg: cease trace debugging"
366 proc gdb_collect_registers_test { myregs } {
373 prepare_for_trace_test
375 # We'll simply re-use the args_test_function for this test
376 gdb_test "trace args_test_func" \
377 "Tracepoint \[0-9\]+ at .*" \
378 "collect $myregs: set tracepoint"
379 gdb_trace_setactions "collect $myregs: define actions" \
381 "collect $myregs" "^$"
384 run_trace_experiment $myregs args_test_func
386 test_register "\$$fpreg" $myregs
387 test_register "\$$spreg" $myregs
388 test_register "\$$pcreg" $myregs
390 gdb_test "tfind none" \
392 "collect $myregs: cease trace debugging"
395 proc gdb_collect_expression_test { func expr val msg } {
399 prepare_for_trace_test
401 # Find the comment-identified line for setting this tracepoint.
403 gdb_test_multiple "list $func, +30" "collect $msg: find tracepoint line" {
404 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
405 set testline $expect_out(1,string)
406 pass "collect $msg: find tracepoint line"
408 -re ".*$gdb_prompt " {
409 fail "collect $msg: find tracepoint line (skipping locals test)"
413 fail "collect $msg: find tracepoint line (skipping locals test)"
418 gdb_test "trace $testline" \
419 "Tracepoint \[0-9\]+ at .*" \
420 "collect $msg: set tracepoint"
421 gdb_trace_setactions "collect $msg: define actions" \
426 run_trace_experiment $msg $func
428 gdb_test "print $expr" \
429 "\\$\[0-9\]+ = $val$cr" \
430 "collect $msg: got expected value '$val'"
432 gdb_test "tfind none" \
434 "collect $msg: cease trace debugging"
437 proc gdb_collect_globals_test { } {
441 prepare_for_trace_test
443 # Find the comment-identified line for setting this tracepoint.
445 gdb_test_multiple "list globals_test_func, +30" "collect globals: find tracepoint line" {
446 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
447 set testline $expect_out(1,string)
448 pass "collect globals: find tracepoint line"
450 -re ".*$gdb_prompt " {
451 fail "collect globals: find tracepoint line (skipping global test)"
455 fail "collect globals: find tracepoint line (skipping global test)"
460 # Use use this to test collecting overlapping memory ranges
461 # (making use of UNOP_MEMVAL, as objects don't usually overlap
462 # other objects). Note that globalarr2 should not be collected in
463 # any other way so that a regression test below can be effective.
465 set globalarr2_addr ""
466 set test "get address of globalarr2"
467 gdb_test_multiple "p /x &globalarr2" $test {
468 -re " = (0x\[0-9a-f\]+)\r\n$gdb_prompt $" {
469 set globalarr2_addr $expect_out(1,string)
474 gdb_test "trace $testline" \
475 "Tracepoint \[0-9\]+ at .*" \
476 "collect globals: set tracepoint"
477 gdb_trace_setactions "collect globals: define actions" \
479 "collect globalc, globali, globalf, globald" "^$" \
480 "collect globalstruct, globalp, globalarr" "^$" \
481 "collect \{int \[4\]\}$globalarr2_addr" "^$" \
482 "collect \{int \[2\]\}$globalarr2_addr" "^$"
485 run_trace_experiment "globals" globals_test_func
487 gdb_test "print globalc" \
488 "\\$\[0-9\]+ = 71 'G'$cr" \
489 "collect globals: collected global char"
490 gdb_test "print globali" \
491 "\\$\[0-9\]+ = 72$cr" \
492 "collect globals: collected global int"
493 gdb_test "print globalf" \
494 "\\$\[0-9\]+ = 73.\[23\]\[0-9\]*$cr" \
495 "collect globals: collected global float"
496 gdb_test "print globald" \
497 "\\$\[0-9\]+ = 74.\[34\]\[0-9\]*$cr" \
498 "collect globals: collected global double"
500 gdb_test "print globalstruct.memberc" \
501 "\\$\[0-9\]+ = 81 'Q'$cr" \
502 "collect globals: collected struct char member"
503 gdb_test "print globalstruct.memberi" \
504 "\\$\[0-9\]+ = 82$cr" \
505 "collect globals: collected struct member int"
506 gdb_test "print globalstruct.memberf" \
507 "\\$\[0-9\]+ = 83.\[23\]\[0-9\]*$cr" \
508 "collect globals: collected struct member float"
509 gdb_test "print globalstruct.memberd" \
510 "\\$\[0-9\]+ = 84.\[34\]\[0-9\]*$cr" \
511 "collect globals: collected struct member double"
513 gdb_test "print globalp == &globalstruct" \
514 "\\$\[0-9\]+ = 1$cr" \
515 "collect globals: collected global pointer"
517 gdb_test "print globalarr\[1\]" \
518 "\\$\[0-9\]+ = 1$cr" \
519 "collect globals: collected global array element #1"
520 gdb_test "print globalarr\[2\]" \
521 "\\$\[0-9\]+ = 2$cr" \
522 "collect globals: collected global array element #2"
523 gdb_test "print globalarr\[3\]" \
524 "\\$\[0-9\]+ = 3$cr" \
525 "collect globals: collected global array element #3"
527 # Check that we didn't mess up sort&merging memory ranges to
529 gdb_test "print globalarr2" \
530 "\\$\[0-9\]+ = \\{0, 1, 2, 3\\}$cr" \
531 "collect globals: collected global array 2"
533 gdb_test "tfind none" \
535 "collect globals: cease trace debugging"
538 # Test that when we've collected all fields of a structure
539 # individually, we can print the whole structure in one go.
540 proc gdb_collect_global_in_pieces_test { } {
543 prepare_for_trace_test
545 # Find the comment-identified line for setting this tracepoint.
547 set msg "collect global in pieces: find tracepoint line"
548 gdb_test_multiple "list globals_test_func, +30" "$msg" {
549 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
550 set testline $expect_out(1,string)
555 if {$testline == 0} {
559 gdb_test "trace $testline" \
560 "Tracepoint \[0-9\]+ at .*" \
561 "collect global in pieces: set tracepoint"
562 gdb_trace_setactions "collect global in pieces: define actions" \
564 "collect global_pieces.a, global_pieces.b" \
568 run_trace_experiment "global in pieces" globals_test_func
570 gdb_test "print /x global_pieces.a" " = 0x12345678" \
571 "collect global in pieces: print piece a"
572 gdb_test "print /x global_pieces.b" " = 0x87654321" \
573 "collect global in pieces: print piece b"
575 gdb_test "print /x global_pieces" " = \{a = 0x12345678, b = 0x87654321\}" \
576 "collect global in pieces: print whole object"
578 gdb_test "tfind none" "#0 end .*" \
579 "collect global in pieces: cease trace debugging"
582 proc gdb_trace_collection_test {} {
587 gdb_collect_args_test "\$args" \
589 gdb_collect_args_test "argc, argi, argf, argd, argstruct, argarray" \
591 gdb_collect_argstruct_test "\$args" \
592 "argstruct collectively"
593 gdb_collect_argstruct_test "argstruct" \
594 "argstruct individually"
595 gdb_collect_argarray_test "\$args" \
596 "argarray collectively"
597 gdb_collect_argarray_test "argarray" \
598 "argarray individually"
599 gdb_collect_locals_test local_test_func "\$locals" \
600 "auto locals collectively"
601 gdb_collect_locals_test local_test_func \
602 "locc, loci, locf, locd, locst, locar" \
603 "auto locals individually"
604 gdb_collect_locals_test reglocal_test_func "\$locals" \
605 "register locals collectively"
606 gdb_collect_locals_test reglocal_test_func \
607 "locc, loci, locf, locd, locst, locar" \
608 "register locals individually"
609 gdb_collect_locals_test statlocal_test_func "\$locals" \
610 "static locals collectively"
611 gdb_collect_locals_test statlocal_test_func \
612 "locc, loci, locf, locd, locst, locar" \
613 "static locals individually"
614 gdb_collect_registers_test "\$regs"
615 gdb_collect_registers_test "\$$fpreg, \$$spreg, \$$pcreg"
616 gdb_collect_globals_test
617 gdb_collect_global_in_pieces_test
624 # x->y (x->y->z, ...)
625 # x[2] (x[2][3], ...) (const index)
626 # x[y] (x[y][z], ...) (index to be char, short, long, float, double)
628 # We test the following operators by using them in an array index
629 # expression -- because the naked result of an operator is not really
630 # collected. To be sure the operator was evaluated correctly on the
631 # target, we have to actually use the result eg. in an array offset
633 # x[y + z] (tests addition: y and z various combos of types, sclasses)
634 # x[y - z] (tests subtraction) (ditto)
635 # x[y * z] (tests multiplication) (ditto)
636 # x[y / z] (tests division) (ditto)
637 # x[y % z] (tests modulo division) (ditto)
638 # x[y == z] (tests equality relation) (ditto) UNSUPPORTED
639 # x[y != z] (tests inequality relation) (ditto) UNSUPPORTED
640 # x[y > z] (tests greater-than relation) (ditto) UNSUPPORTED
641 # x[y < z] (tests less-than relation) (ditto) UNSUPPORTED
642 # x[y >= z] (tests greater-than-or-equal relation) (ditto) UNSUPPORTED
643 # x[y <= z] (tests less-than-or-equal relation) (ditto) UNSUPPORTED
644 # x[y && z] (tests logical and) (ditto) UNSUPPORTED
645 # x[y || z] (tests logical or) (ditto) UNSUPPORTED
646 # x[y & z] (tests binary and) (ditto) UNSUPPORTED
647 # x[y | z] (tests binary or) (ditto) UNSUPPORTED
648 # x[y ^ z] (tests binary xor) (ditto) UNSUPPORTED
649 # x[y ? z1 : z2] (tests ternary operator) (ditto) UNSUPPORTED
650 # x[y << z] (tests shift-left) (ditto) UNSUPPORTED
651 # x[y >> z] (tests shift-right) (ditto) UNSUPPORTED
652 # x[y = z] (tests assignment operator) (ditto) UNSUPPORTED
653 # x[++y] (tests pre-increment operator) (ditto) UNSUPPORTED
654 # x[--y] (tests pre-decrement operator) (ditto) UNSUPPORTED
655 # x[y++] (tests post-increment operator) (ditto) UNSUPPORTED
656 # x[y--] (tests post-decrement operator) (ditto) UNSUPPORTED
657 # x[+y] (tests unary plus) (ditto)
658 # x[-y] (tests unary minus) (ditto)
659 # x[!y] (tests logical not) (ditto) UNSUPPORTED
660 # x[~y] (tests binary not) (ditto) UNSUPPORTED
661 # x[(y, z)] (tests comma expression) (ditto)
665 gdb_collect_expression_test globals_test_func \
666 "globalstruct.memberi" "82" "a.b"
667 gdb_collect_expression_test globals_test_func \
668 "globalp->memberc" "81 'Q'" "a->b"
669 gdb_collect_expression_test globals_test_func \
670 "globalarr\[2\]" "2" "a\[2\]"
671 gdb_collect_expression_test globals_test_func \
672 "globalarr\[l3\]" "3" "a\[b\]"
673 gdb_collect_expression_test globals_test_func \
674 "globalarr\[l3 + l2\]" "5" "a\[b + c\]"
675 gdb_collect_expression_test globals_test_func \
676 "globalarr\[l3 - l2\]" "1" "a\[b - c\]"
677 gdb_collect_expression_test globals_test_func \
678 "globalarr\[l3 * l2\]" "6" "a\[b * c\]"
679 gdb_collect_expression_test globals_test_func \
680 "globalarr\[l6 / l3\]" "2" "a\[b / c\]"
681 gdb_collect_expression_test globals_test_func \
682 "globalarr\[l7 % l3\]" "1" "a\[b % c\]"
683 gdb_collect_expression_test globals_test_func \
684 "globalarr\[+l1\]" "1" "a\[+b\]"
685 gdb_collect_expression_test globals_test_func \
686 "globalarr\[-lminus\]" "2" "a\[-b\]"
687 gdb_collect_expression_test globals_test_func \
688 "globalarr\[\(l6, l7\)\]" "7" "a\[\(b, c\)\]"
692 clean_restart $executable
695 # We generously give ourselves one "pass" if we successfully
696 # detect that this test cannot be run on this target!
697 if { ![gdb_target_supports_trace] } then {
698 pass "Current target does not support trace"
702 # Body of test encased in a proc so we can return prematurely.
703 gdb_trace_collection_test
706 gdb_test "tfind none" ".*" ""