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 gdb_test "trace $testline" \
461 "Tracepoint \[0-9\]+ at .*" \
462 "collect globals: set tracepoint"
463 gdb_trace_setactions "collect globals: define actions" \
465 "collect globalc, globali, globalf, globald" "^$" \
466 "collect globalstruct, globalp, globalarr" "^$"
469 run_trace_experiment "globals" globals_test_func
471 gdb_test "print globalc" \
472 "\\$\[0-9\]+ = 71 'G'$cr" \
473 "collect globals: collected global char"
474 gdb_test "print globali" \
475 "\\$\[0-9\]+ = 72$cr" \
476 "collect globals: collected global int"
477 gdb_test "print globalf" \
478 "\\$\[0-9\]+ = 73.\[23\]\[0-9\]*$cr" \
479 "collect globals: collected global float"
480 gdb_test "print globald" \
481 "\\$\[0-9\]+ = 74.\[34\]\[0-9\]*$cr" \
482 "collect globals: collected global double"
484 gdb_test "print globalstruct.memberc" \
485 "\\$\[0-9\]+ = 81 'Q'$cr" \
486 "collect globals: collected struct char member"
487 gdb_test "print globalstruct.memberi" \
488 "\\$\[0-9\]+ = 82$cr" \
489 "collect globals: collected struct member int"
490 gdb_test "print globalstruct.memberf" \
491 "\\$\[0-9\]+ = 83.\[23\]\[0-9\]*$cr" \
492 "collect globals: collected struct member float"
493 gdb_test "print globalstruct.memberd" \
494 "\\$\[0-9\]+ = 84.\[34\]\[0-9\]*$cr" \
495 "collect globals: collected struct member double"
497 gdb_test "print globalp == &globalstruct" \
498 "\\$\[0-9\]+ = 1$cr" \
499 "collect globals: collected global pointer"
501 gdb_test "print globalarr\[1\]" \
502 "\\$\[0-9\]+ = 1$cr" \
503 "collect globals: collected global array element #1"
504 gdb_test "print globalarr\[2\]" \
505 "\\$\[0-9\]+ = 2$cr" \
506 "collect globals: collected global array element #2"
507 gdb_test "print globalarr\[3\]" \
508 "\\$\[0-9\]+ = 3$cr" \
509 "collect globals: collected global array element #3"
511 gdb_test "tfind none" \
513 "collect globals: cease trace debugging"
516 proc gdb_trace_collection_test {} {
521 gdb_collect_args_test "\$args" \
523 gdb_collect_args_test "argc, argi, argf, argd, argstruct, argarray" \
525 gdb_collect_argstruct_test "\$args" \
526 "argstruct collectively"
527 gdb_collect_argstruct_test "argstruct" \
528 "argstruct individually"
529 gdb_collect_argarray_test "\$args" \
530 "argarray collectively"
531 gdb_collect_argarray_test "argarray" \
532 "argarray individually"
533 gdb_collect_locals_test local_test_func "\$locals" \
534 "auto locals collectively"
535 gdb_collect_locals_test local_test_func \
536 "locc, loci, locf, locd, locst, locar" \
537 "auto locals individually"
538 gdb_collect_locals_test reglocal_test_func "\$locals" \
539 "register locals collectively"
540 gdb_collect_locals_test reglocal_test_func \
541 "locc, loci, locf, locd, locst, locar" \
542 "register locals individually"
543 gdb_collect_locals_test statlocal_test_func "\$locals" \
544 "static locals collectively"
545 gdb_collect_locals_test statlocal_test_func \
546 "locc, loci, locf, locd, locst, locar" \
547 "static locals individually"
548 gdb_collect_registers_test "\$regs"
549 gdb_collect_registers_test "\$$fpreg, \$$spreg, \$$pcreg"
550 gdb_collect_globals_test
557 # x->y (x->y->z, ...)
558 # x[2] (x[2][3], ...) (const index)
559 # x[y] (x[y][z], ...) (index to be char, short, long, float, double)
561 # We test the following operators by using them in an array index
562 # expression -- because the naked result of an operator is not really
563 # collected. To be sure the operator was evaluated correctly on the
564 # target, we have to actually use the result eg. in an array offset
566 # x[y + z] (tests addition: y and z various combos of types, sclasses)
567 # x[y - z] (tests subtraction) (ditto)
568 # x[y * z] (tests multiplication) (ditto)
569 # x[y / z] (tests division) (ditto)
570 # x[y % z] (tests modulo division) (ditto)
571 # x[y == z] (tests equality relation) (ditto) UNSUPPORTED
572 # x[y != z] (tests inequality relation) (ditto) UNSUPPORTED
573 # x[y > z] (tests greater-than relation) (ditto) UNSUPPORTED
574 # x[y < z] (tests less-than relation) (ditto) UNSUPPORTED
575 # x[y >= z] (tests greater-than-or-equal relation) (ditto) UNSUPPORTED
576 # x[y <= z] (tests less-than-or-equal relation) (ditto) UNSUPPORTED
577 # x[y && z] (tests logical and) (ditto) UNSUPPORTED
578 # x[y || z] (tests logical or) (ditto) UNSUPPORTED
579 # x[y & z] (tests binary and) (ditto) UNSUPPORTED
580 # x[y | z] (tests binary or) (ditto) UNSUPPORTED
581 # x[y ^ z] (tests binary xor) (ditto) UNSUPPORTED
582 # x[y ? z1 : z2] (tests ternary operator) (ditto) UNSUPPORTED
583 # x[y << z] (tests shift-left) (ditto) UNSUPPORTED
584 # x[y >> z] (tests shift-right) (ditto) UNSUPPORTED
585 # x[y = z] (tests assignment operator) (ditto) UNSUPPORTED
586 # x[++y] (tests pre-increment operator) (ditto) UNSUPPORTED
587 # x[--y] (tests pre-decrement operator) (ditto) UNSUPPORTED
588 # x[y++] (tests post-increment operator) (ditto) UNSUPPORTED
589 # x[y--] (tests post-decrement operator) (ditto) UNSUPPORTED
590 # x[+y] (tests unary plus) (ditto)
591 # x[-y] (tests unary minus) (ditto)
592 # x[!y] (tests logical not) (ditto) UNSUPPORTED
593 # x[~y] (tests binary not) (ditto) UNSUPPORTED
594 # x[(y, z)] (tests comma expression) (ditto)
598 gdb_collect_expression_test globals_test_func \
599 "globalstruct.memberi" "82" "a.b"
600 gdb_collect_expression_test globals_test_func \
601 "globalp->memberc" "81 'Q'" "a->b"
602 gdb_collect_expression_test globals_test_func \
603 "globalarr\[2\]" "2" "a\[2\]"
604 gdb_collect_expression_test globals_test_func \
605 "globalarr\[l3\]" "3" "a\[b\]"
606 gdb_collect_expression_test globals_test_func \
607 "globalarr\[l3 + l2\]" "5" "a\[b + c\]"
608 gdb_collect_expression_test globals_test_func \
609 "globalarr\[l3 - l2\]" "1" "a\[b - c\]"
610 gdb_collect_expression_test globals_test_func \
611 "globalarr\[l3 * l2\]" "6" "a\[b * c\]"
612 gdb_collect_expression_test globals_test_func \
613 "globalarr\[l6 / l3\]" "2" "a\[b / c\]"
614 gdb_collect_expression_test globals_test_func \
615 "globalarr\[l7 % l3\]" "1" "a\[b % c\]"
616 gdb_collect_expression_test globals_test_func \
617 "globalarr\[+l1\]" "1" "a\[+b\]"
618 gdb_collect_expression_test globals_test_func \
619 "globalarr\[-lminus\]" "2" "a\[-b\]"
620 gdb_collect_expression_test globals_test_func \
621 "globalarr\[\(l6, l7\)\]" "7" "a\[\(b, c\)\]"
625 clean_restart $executable
628 # We generously give ourselves one "pass" if we successfully
629 # detect that this test cannot be run on this target!
630 if { ![gdb_target_supports_trace] } then {
631 pass "Current target does not support trace"
635 # Body of test encased in a proc so we can return prematurely.
636 gdb_trace_collection_test
639 gdb_test "tfind none" ".*" ""