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 executable $testfile
28 set binfile $objdir/$subdir/$executable
30 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
31 executable {debug nowarnings}] != "" } {
32 untested collection.exp
38 # 2) function args by name
40 # 4) function locals by name
42 # 6) registers by name ($sp, $fp?)
44 # 8) expressions (lots of different kinds: local and global)
49 if [istarget "x86_64-*"] then {
53 } elseif [istarget "i?86-*"] then {
67 proc test_register { reg test_id } {
71 gdb_test_multiple "print /x $reg" "" {
72 -re "\\$\[0-9\]+ = \[x0\]+$cr$gdb_prompt $" {
73 fail "collect $test_id: collected $reg (zero)"
75 -re "\\$\[0-9\]+ = \[x0-9a-fA-F\]+$cr$gdb_prompt $" {
76 pass "collect $test_id: collected $reg"
78 -re "\[Ee\]rror.*$gdb_prompt $" {
79 fail "collect $test_id: collected $reg (error)"
84 proc prepare_for_trace_test {} {
87 clean_restart $executable
91 gdb_test "break begin" "" ""
92 gdb_test "break end" "" ""
95 proc run_trace_experiment { msg test_func } {
99 ".*Breakpoint \[0-9\]+, begin .*" \
100 "collect $msg: advance to begin"
102 set test "collect $msg: start trace experiment"
103 gdb_test_multiple "tstart" "$test" {
104 -re "^tstart\r\n$gdb_prompt $" {
109 gdb_test "continue" \
110 "Continuing.*Breakpoint \[0-9\]+, end.*" \
111 "collect $msg: run trace experiment"
114 "collect $msg: stop trace experiment"
115 gdb_test "tfind start" \
117 "collect $msg: tfind test frame"
125 proc gdb_collect_args_test { myargs msg } {
129 prepare_for_trace_test
131 gdb_test "trace args_test_func" \
132 "Tracepoint \[0-9\]+ at .*" \
133 "collect $msg: set tracepoint"
134 gdb_trace_setactions "collect $msg: define actions" \
136 "collect $myargs" "^$"
139 run_trace_experiment $msg args_test_func
141 gdb_test "print argc" \
142 "\\$\[0-9\]+ = 1 '.001'$cr" \
143 "collect $msg: collected arg char"
144 gdb_test "print argi" \
145 "\\$\[0-9\]+ = 2$cr" \
146 "collect $msg: collected arg int"
147 gdb_test "print argf" \
148 "\\$\[0-9\]+ = 3.\[23\]\[0-9\]*$cr" \
149 "collect $msg: collected arg float"
150 gdb_test "print argd" \
151 "\\$\[0-9\]+ = 4.\[34\]\[0-9\]*$cr" \
152 "collect $msg: collected arg double"
154 # struct arg as one of several args (near end of list)
155 gdb_test "print argstruct.memberc" \
156 "\\$\[0-9\]+ = 101 'e'$cr" \
157 "collect $msg: collected arg struct member char"
158 gdb_test "print argstruct.memberi" \
159 "\\$\[0-9\]+ = 102$cr" \
160 "collect $msg: collected arg struct member int"
161 gdb_test "print argstruct.memberf" \
162 "\\$\[0-9\]+ = 103.\[23\]\[0-9\]*$cr" \
163 "collect $msg: collected arg struct member float"
164 gdb_test "print argstruct.memberd" \
165 "\\$\[0-9\]+ = 104.\[34\]\[0-9\]*$cr" \
166 "collect $msg: collected arg struct member double"
168 # array arg as one of several args (near end of list)
170 # It isn't clear why is the test assuming the array's elements are
171 # collected. In C, an array as function parameters is a special
172 # case; it's just a pointer into the caller's array, and as such,
173 # that's what normally the debug info describes. Maybe this was
174 # originaly written for a compiler where array parameters were
175 # really described as arrays in debug info.
178 gdb_test "print argarray\[0\]" \
179 "\\$\[0-9\]+ = 111$cr" \
180 "collect $msg: collected argarray #0"
183 gdb_test "print argarray\[1\]" \
184 "\\$\[0-9\]+ = 112$cr" \
185 "collect $msg: collected argarray #1"
188 gdb_test "print argarray\[2\]" \
189 "\\$\[0-9\]+ = 113$cr" \
190 "collect $msg: collected argarray #2"
193 gdb_test "print argarray\[3\]" \
194 "\\$\[0-9\]+ = 114$cr" \
195 "collect $msg: collected argarray #3"
197 gdb_test "tfind none" \
199 "collect $msg: cease trace debugging"
202 proc gdb_collect_argstruct_test { myargs msg } {
206 prepare_for_trace_test
208 gdb_test "trace argstruct_test_func" \
209 "Tracepoint \[0-9\]+ at .*" \
210 "collect $msg: set tracepoint"
211 gdb_trace_setactions "collect $msg: define actions" \
213 "collect $myargs" "^$"
216 run_trace_experiment $msg argstruct_test_func
218 # struct argument as only argument
219 gdb_test "print argstruct.memberc" \
220 "\\$\[0-9\]+ = 101 'e'$cr" \
221 "collect $msg: collected arg struct member char"
222 gdb_test "print argstruct.memberi" \
223 "\\$\[0-9\]+ = 102$cr" \
224 "collect $msg: collected arg struct member int"
225 gdb_test "print argstruct.memberf" \
226 "\\$\[0-9\]+ = 103.\[23\]\[0-9\]*$cr" \
227 "collect $msg: collected arg struct member float"
228 gdb_test "print argstruct.memberd" \
229 "\\$\[0-9\]+ = 104.\[34\]\[0-9\]*$cr" \
230 "collect $msg: collected arg struct member double"
232 gdb_test "tfind none" \
234 "collect $msg: cease trace debugging"
238 proc gdb_collect_argarray_test { myargs msg } {
242 prepare_for_trace_test
244 gdb_test "trace argarray_test_func" \
245 "Tracepoint \[0-9\]+ at .*" \
246 "collect $msg: set tracepoint"
247 gdb_trace_setactions "collect $msg: define actions" \
249 "collect $myargs" "^$"
252 run_trace_experiment $msg argarray_test_func
254 # array arg as only argument
256 # It isn't clear why is the test assuming the array's elements are
257 # collected. In C, an array as function parameters is a special
258 # case; it's just a pointer into the caller's array, and as such,
259 # that's what normally the debug info describes. Maybe this was
260 # originaly written for a compiler where array parameters were
261 # really described as arrays in debug info.
264 gdb_test "print argarray\[0\]" \
265 "\\$\[0-9\]+ = 111$cr" \
266 "collect $msg: collected argarray #0"
269 gdb_test "print argarray\[1\]" \
270 "\\$\[0-9\]+ = 112$cr" \
271 "collect $msg: collected argarray #1"
274 gdb_test "print argarray\[2\]" \
275 "\\$\[0-9\]+ = 113$cr" \
276 "collect $msg: collected argarray #2"
279 gdb_test "print argarray\[3\]" \
280 "\\$\[0-9\]+ = 114$cr" \
281 "collect $msg: collected argarray #3"
283 gdb_test "tfind none" \
285 "collect $msg: cease trace debugging"
289 proc gdb_collect_locals_test { func mylocs msg } {
293 prepare_for_trace_test
295 # Find the comment-identified line for setting this tracepoint.
297 send_gdb "list $func, +30\n"
299 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
300 set testline $expect_out(1,string)
301 pass "collect $msg: find tracepoint line"
303 -re ".*$gdb_prompt " {
304 fail "collect $msg: find tracepoint line (skipping locals test)"
308 fail "collect $msg: find tracepoint line (skipping locals test)"
313 gdb_test "trace $testline" \
314 "Tracepoint \[0-9\]+ at .*" \
315 "collect $msg: set tracepoint"
316 gdb_trace_setactions "collect $msg: define actions" \
318 "collect $mylocs" "^$"
321 run_trace_experiment $msg $func
323 gdb_test "print locc" \
324 "\\$\[0-9\]+ = 11 '.\[a-z0-7\]+'$cr" \
325 "collect $msg: collected local char"
326 gdb_test "print loci" \
327 "\\$\[0-9\]+ = 12$cr" \
328 "collect $msg: collected local int"
329 gdb_test "print locf" \
330 "\\$\[0-9\]+ = 13.\[23\]\[0-9\]*$cr" \
331 "collect $msg: collected local float"
332 gdb_test "print locd" \
333 "\\$\[0-9\]+ = 14.\[34\]\[0-9\]*$cr" \
334 "collect $msg: collected local double"
336 gdb_test "print locst.memberc" \
337 "\\$\[0-9\]+ = 15 '.017'$cr" \
338 "collect $msg: collected local member char"
339 gdb_test "print locst.memberi" \
340 "\\$\[0-9\]+ = 16$cr" \
341 "collect $msg: collected local member int"
342 gdb_test "print locst.memberf" \
343 "\\$\[0-9\]+ = 17.\[67\]\[0-9\]*$cr" \
344 "collect $msg: collected local member float"
345 gdb_test "print locst.memberd" \
346 "\\$\[0-9\]+ = 18.\[78\]\[0-9\]*$cr" \
347 "collect $msg: collected local member double"
349 gdb_test "print locar\[0\]" \
350 "\\$\[0-9\]+ = 121$cr" \
351 "collect $msg: collected locarray #0"
352 gdb_test "print locar\[1\]" \
353 "\\$\[0-9\]+ = 122$cr" \
354 "collect $msg: collected locarray #1"
355 gdb_test "print locar\[2\]" \
356 "\\$\[0-9\]+ = 123$cr" \
357 "collect $msg: collected locarray #2"
358 gdb_test "print locar\[3\]" \
359 "\\$\[0-9\]+ = 124$cr" \
360 "collect $msg: collected locarray #3"
363 gdb_test "tfind none" \
365 "collect $msg: cease trace debugging"
368 proc gdb_collect_registers_test { myregs } {
375 prepare_for_trace_test
377 # We'll simply re-use the args_test_function for this test
378 gdb_test "trace args_test_func" \
379 "Tracepoint \[0-9\]+ at .*" \
380 "collect $myregs: set tracepoint"
381 gdb_trace_setactions "collect $myregs: define actions" \
383 "collect $myregs" "^$"
386 run_trace_experiment $myregs args_test_func
388 test_register "\$$fpreg" $myregs
389 test_register "\$$spreg" $myregs
390 test_register "\$$pcreg" $myregs
392 gdb_test "tfind none" \
394 "collect $myregs: cease trace debugging"
397 proc gdb_collect_expression_test { func expr val msg } {
401 prepare_for_trace_test
403 # Find the comment-identified line for setting this tracepoint.
405 send_gdb "list $func, +30\n"
407 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
408 set testline $expect_out(1,string)
409 pass "collect $msg: find tracepoint line"
411 -re ".*$gdb_prompt " {
412 fail "collect $msg: find tracepoint line (skipping locals test)"
416 fail "collect $msg: find tracepoint line (skipping locals test)"
421 gdb_test "trace $testline" \
422 "Tracepoint \[0-9\]+ at .*" \
423 "collect $msg: set tracepoint"
424 gdb_trace_setactions "collect $msg: define actions" \
429 run_trace_experiment $msg $func
431 gdb_test "print $expr" \
432 "\\$\[0-9\]+ = $val$cr" \
433 "collect $msg: got expected value '$val'"
435 gdb_test "tfind none" \
437 "collect $msg: cease trace debugging"
440 proc gdb_collect_globals_test { } {
444 prepare_for_trace_test
446 # Find the comment-identified line for setting this tracepoint.
448 send_gdb "list globals_test_func, +30\n"
450 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
451 set testline $expect_out(1,string)
452 pass "collect globals: find tracepoint line"
454 -re ".*$gdb_prompt " {
455 fail "collect globals: find tracepoint line (skipping global test)"
459 fail "collect globals: find tracepoint line (skipping global test)"
464 gdb_test "trace $testline" \
465 "Tracepoint \[0-9\]+ at .*" \
466 "collect globals: set tracepoint"
467 gdb_trace_setactions "collect globals: define actions" \
469 "collect globalc, globali, globalf, globald" "^$" \
470 "collect globalstruct, globalp, globalarr" "^$"
473 run_trace_experiment "globals" globals_test_func
475 gdb_test "print globalc" \
476 "\\$\[0-9\]+ = 71 'G'$cr" \
477 "collect globals: collected global char"
478 gdb_test "print globali" \
479 "\\$\[0-9\]+ = 72$cr" \
480 "collect globals: collected global int"
481 gdb_test "print globalf" \
482 "\\$\[0-9\]+ = 73.\[23\]\[0-9\]*$cr" \
483 "collect globals: collected global float"
484 gdb_test "print globald" \
485 "\\$\[0-9\]+ = 74.\[34\]\[0-9\]*$cr" \
486 "collect globals: collected global double"
488 gdb_test "print globalstruct.memberc" \
489 "\\$\[0-9\]+ = 81 'Q'$cr" \
490 "collect globals: collected struct char member"
491 gdb_test "print globalstruct.memberi" \
492 "\\$\[0-9\]+ = 82$cr" \
493 "collect globals: collected struct member int"
494 gdb_test "print globalstruct.memberf" \
495 "\\$\[0-9\]+ = 83.\[23\]\[0-9\]*$cr" \
496 "collect globals: collected struct member float"
497 gdb_test "print globalstruct.memberd" \
498 "\\$\[0-9\]+ = 84.\[34\]\[0-9\]*$cr" \
499 "collect globals: collected struct member double"
501 gdb_test "print globalp == &globalstruct" \
502 "\\$\[0-9\]+ = 1$cr" \
503 "collect globals: collected global pointer"
505 gdb_test "print globalarr\[1\]" \
506 "\\$\[0-9\]+ = 1$cr" \
507 "collect globals: collected global array element #1"
508 gdb_test "print globalarr\[2\]" \
509 "\\$\[0-9\]+ = 2$cr" \
510 "collect globals: collected global array element #2"
511 gdb_test "print globalarr\[3\]" \
512 "\\$\[0-9\]+ = 3$cr" \
513 "collect globals: collected global array element #3"
515 gdb_test "tfind none" \
517 "collect globals: cease trace debugging"
520 proc gdb_trace_collection_test {} {
525 gdb_collect_args_test "\$args" \
527 gdb_collect_args_test "argc, argi, argf, argd, argstruct, argarray" \
529 gdb_collect_argstruct_test "\$args" \
530 "argstruct collectively"
531 gdb_collect_argstruct_test "argstruct" \
532 "argstruct individually"
533 gdb_collect_argarray_test "\$args" \
534 "argarray collectively"
535 gdb_collect_argarray_test "argarray" \
536 "argarray individually"
537 gdb_collect_locals_test local_test_func "\$locals" \
538 "auto locals collectively"
539 gdb_collect_locals_test local_test_func \
540 "locc, loci, locf, locd, locst, locar" \
541 "auto locals individually"
542 gdb_collect_locals_test reglocal_test_func "\$locals" \
543 "register locals collectively"
544 gdb_collect_locals_test reglocal_test_func \
545 "locc, loci, locf, locd, locst, locar" \
546 "register locals individually"
547 gdb_collect_locals_test statlocal_test_func "\$locals" \
548 "static locals collectively"
549 gdb_collect_locals_test statlocal_test_func \
550 "locc, loci, locf, locd, locst, locar" \
551 "static locals individually"
552 gdb_collect_registers_test "\$regs"
553 gdb_collect_registers_test "\$$fpreg, \$$spreg, \$$pcreg"
554 gdb_collect_globals_test
561 # x->y (x->y->z, ...)
562 # x[2] (x[2][3], ...) (const index)
563 # x[y] (x[y][z], ...) (index to be char, short, long, float, double)
565 # We test the following operators by using them in an array index
566 # expression -- because the naked result of an operator is not really
567 # collected. To be sure the operator was evaluated correctly on the
568 # target, we have to actually use the result eg. in an array offset
570 # x[y + z] (tests addition: y and z various combos of types, sclasses)
571 # x[y - z] (tests subtraction) (ditto)
572 # x[y * z] (tests multiplication) (ditto)
573 # x[y / z] (tests division) (ditto)
574 # x[y % z] (tests modulo division) (ditto)
575 # x[y == z] (tests equality relation) (ditto) UNSUPPORTED
576 # x[y != z] (tests inequality relation) (ditto) UNSUPPORTED
577 # x[y > z] (tests greater-than relation) (ditto) UNSUPPORTED
578 # x[y < z] (tests less-than relation) (ditto) UNSUPPORTED
579 # x[y >= z] (tests greater-than-or-equal relation) (ditto) UNSUPPORTED
580 # x[y <= z] (tests less-than-or-equal relation) (ditto) UNSUPPORTED
581 # x[y && z] (tests logical and) (ditto) UNSUPPORTED
582 # x[y || z] (tests logical or) (ditto) UNSUPPORTED
583 # x[y & z] (tests binary and) (ditto) UNSUPPORTED
584 # x[y | z] (tests binary or) (ditto) UNSUPPORTED
585 # x[y ^ z] (tests binary xor) (ditto) UNSUPPORTED
586 # x[y ? z1 : z2] (tests ternary operator) (ditto) UNSUPPORTED
587 # x[y << z] (tests shift-left) (ditto) UNSUPPORTED
588 # x[y >> z] (tests shift-right) (ditto) UNSUPPORTED
589 # x[y = z] (tests assignment operator) (ditto) UNSUPPORTED
590 # x[++y] (tests pre-increment operator) (ditto) UNSUPPORTED
591 # x[--y] (tests pre-decrement operator) (ditto) UNSUPPORTED
592 # x[y++] (tests post-increment operator) (ditto) UNSUPPORTED
593 # x[y--] (tests post-decrement operator) (ditto) UNSUPPORTED
594 # x[+y] (tests unary plus) (ditto)
595 # x[-y] (tests unary minus) (ditto)
596 # x[!y] (tests logical not) (ditto) UNSUPPORTED
597 # x[~y] (tests binary not) (ditto) UNSUPPORTED
598 # x[(y, z)] (tests comma expression) (ditto)
602 gdb_collect_expression_test globals_test_func \
603 "globalstruct.memberi" "82" "a.b"
604 gdb_collect_expression_test globals_test_func \
605 "globalp->memberc" "81 'Q'" "a->b"
606 gdb_collect_expression_test globals_test_func \
607 "globalarr\[2\]" "2" "a\[2\]"
608 gdb_collect_expression_test globals_test_func \
609 "globalarr\[l3\]" "3" "a\[b\]"
610 gdb_collect_expression_test globals_test_func \
611 "globalarr\[l3 + l2\]" "5" "a\[b + c\]"
612 gdb_collect_expression_test globals_test_func \
613 "globalarr\[l3 - l2\]" "1" "a\[b - c\]"
614 gdb_collect_expression_test globals_test_func \
615 "globalarr\[l3 * l2\]" "6" "a\[b * c\]"
616 gdb_collect_expression_test globals_test_func \
617 "globalarr\[l6 / l3\]" "2" "a\[b / c\]"
618 gdb_collect_expression_test globals_test_func \
619 "globalarr\[l7 % l3\]" "1" "a\[b % c\]"
620 gdb_collect_expression_test globals_test_func \
621 "globalarr\[+l1\]" "1" "a\[+b\]"
622 gdb_collect_expression_test globals_test_func \
623 "globalarr\[-lminus\]" "2" "a\[-b\]"
624 gdb_collect_expression_test globals_test_func \
625 "globalarr\[\(l6, l7\)\]" "7" "a\[\(b, c\)\]"
629 clean_restart $executable
632 # We generously give ourselves one "pass" if we successfully
633 # detect that this test cannot be run on this target!
634 if { ![gdb_target_supports_trace] } then {
635 pass "Current target does not support trace"
639 # Body of test encased in a proc so we can return prematurely.
640 gdb_trace_collection_test
643 gdb_test "tfind none" "" ""