run copyright.sh for 2011.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.trace / collection.exp
1 # Copyright 1998, 2005, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
3
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.
8 #
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.
13 #
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/>.
16
17 load_lib "trace-support.exp"
18
19 if $tracelevel then {
20 strace $tracelevel
21 }
22
23
24 set testfile "collection"
25 set srcfile ${testfile}.c
26 set executable $testfile
27 set binfile $objdir/$subdir/$executable
28
29 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
30 executable {debug nowarnings}] != "" } {
31 untested collection.exp
32 return -1
33 }
34
35 # Tests:
36 # 1) $args
37 # 2) function args by name
38 # 3) $locs
39 # 4) function locals by name
40 # 5) $regs
41 # 6) registers by name ($sp, $fp?)
42 # 7) globals by name
43 # 8) expressions (lots of different kinds: local and global)
44
45 set ws "\[\r\n\t \]+"
46 set cr "\[\r\n\]+"
47
48 if [istarget "x86_64-*"] then {
49 set fpreg "rbp"
50 set spreg "rsp"
51 set pcreg "rip"
52 } elseif [istarget "i?86-*"] then {
53 set fpreg "ebp"
54 set spreg "esp"
55 set pcreg "eip"
56 } else {
57 set fpreg "fp"
58 set spreg "sp"
59 set pcreg "pc"
60 }
61
62 #
63 # Utility procs
64 #
65
66 proc test_register { reg test_id } {
67 global cr
68 global gdb_prompt
69
70 gdb_test_multiple "print /x $reg" "" {
71 -re "\\$\[0-9\]+ = \[x0\]+$cr$gdb_prompt $" {
72 fail "collect $test_id: collected $reg (zero)"
73 }
74 -re "\\$\[0-9\]+ = \[x0-9a-fA-F\]+$cr$gdb_prompt $" {
75 pass "collect $test_id: collected $reg"
76 }
77 -re "\[Ee\]rror.*$gdb_prompt $" {
78 fail "collect $test_id: collected $reg (error)"
79 }
80 }
81 }
82
83 proc prepare_for_trace_test {} {
84 global executable
85
86 clean_restart $executable
87
88 runto_main
89
90 gdb_test "break begin" ".*" ""
91 gdb_test "break end" ".*" ""
92 }
93
94 proc run_trace_experiment { msg test_func } {
95 global gdb_prompt
96
97 gdb_test "continue" \
98 ".*Breakpoint \[0-9\]+, begin .*" \
99 "collect $msg: advance to begin"
100
101 set test "collect $msg: start trace experiment"
102 gdb_test_multiple "tstart" "$test" {
103 -re "^tstart\r\n$gdb_prompt $" {
104 pass "$test"
105 }
106 }
107
108 gdb_test "continue" \
109 "Continuing.*Breakpoint \[0-9\]+, end.*" \
110 "collect $msg: run trace experiment"
111 gdb_test "tstop" \
112 "\[\r\n\]+" \
113 "collect $msg: stop trace experiment"
114 gdb_test "tfind start" \
115 "#0 $test_func .*" \
116 "collect $msg: tfind test frame"
117 }
118
119
120 #
121 # Test procs
122 #
123
124 proc gdb_collect_args_test { myargs msg } {
125 global cr
126 global gdb_prompt
127
128 prepare_for_trace_test
129
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" \
134 "" \
135 "collect $myargs" "^$"
136
137 # Begin the test.
138 run_trace_experiment $msg args_test_func
139
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"
152
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"
166
167 # array arg as one of several args (near end of list)
168
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.
175
176 setup_xfail "*-*-*"
177 gdb_test "print argarray\[0\]" \
178 "\\$\[0-9\]+ = 111$cr" \
179 "collect $msg: collected argarray #0"
180
181 setup_xfail "*-*-*"
182 gdb_test "print argarray\[1\]" \
183 "\\$\[0-9\]+ = 112$cr" \
184 "collect $msg: collected argarray #1"
185
186 setup_xfail "*-*-*"
187 gdb_test "print argarray\[2\]" \
188 "\\$\[0-9\]+ = 113$cr" \
189 "collect $msg: collected argarray #2"
190
191 setup_xfail "*-*-*"
192 gdb_test "print argarray\[3\]" \
193 "\\$\[0-9\]+ = 114$cr" \
194 "collect $msg: collected argarray #3"
195
196 gdb_test "tfind none" \
197 "#0 end .*" \
198 "collect $msg: cease trace debugging"
199 }
200
201 proc gdb_collect_argstruct_test { myargs msg } {
202 global cr
203 global gdb_prompt
204
205 prepare_for_trace_test
206
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" \
211 "" \
212 "collect $myargs" "^$"
213
214 # Begin the test.
215 run_trace_experiment $msg argstruct_test_func
216
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"
230
231 gdb_test "tfind none" \
232 "#0 end .*" \
233 "collect $msg: cease trace debugging"
234 }
235
236
237 proc gdb_collect_argarray_test { myargs msg } {
238 global cr
239 global gdb_prompt
240
241 prepare_for_trace_test
242
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" \
247 "" \
248 "collect $myargs" "^$"
249
250 # Begin the test.
251 run_trace_experiment $msg argarray_test_func
252
253 # array arg as only argument
254
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.
261
262 setup_xfail "*-*-*"
263 gdb_test "print argarray\[0\]" \
264 "\\$\[0-9\]+ = 111$cr" \
265 "collect $msg: collected argarray #0"
266
267 setup_xfail "*-*-*"
268 gdb_test "print argarray\[1\]" \
269 "\\$\[0-9\]+ = 112$cr" \
270 "collect $msg: collected argarray #1"
271
272 setup_xfail "*-*-*"
273 gdb_test "print argarray\[2\]" \
274 "\\$\[0-9\]+ = 113$cr" \
275 "collect $msg: collected argarray #2"
276
277 setup_xfail "*-*-*"
278 gdb_test "print argarray\[3\]" \
279 "\\$\[0-9\]+ = 114$cr" \
280 "collect $msg: collected argarray #3"
281
282 gdb_test "tfind none" \
283 "#0 end .*" \
284 "collect $msg: cease trace debugging"
285 }
286
287
288 proc gdb_collect_locals_test { func mylocs msg } {
289 global cr
290 global gdb_prompt
291
292 prepare_for_trace_test
293
294 # Find the comment-identified line for setting this tracepoint.
295 set testline 0
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"
300 }
301 -re ".*$gdb_prompt " {
302 fail "collect $msg: find tracepoint line (skipping locals test)"
303 return
304 }
305 timeout {
306 fail "collect $msg: find tracepoint line (skipping locals test)"
307 return
308 }
309 }
310
311 gdb_test "trace $testline" \
312 "Tracepoint \[0-9\]+ at .*" \
313 "collect $msg: set tracepoint"
314 gdb_trace_setactions "collect $msg: define actions" \
315 "" \
316 "collect $mylocs" "^$"
317
318 # Begin the test.
319 run_trace_experiment $msg $func
320
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"
333
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"
346
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"
359
360
361 gdb_test "tfind none" \
362 "#0 end .*" \
363 "collect $msg: cease trace debugging"
364 }
365
366 proc gdb_collect_registers_test { myregs } {
367 global cr
368 global gdb_prompt
369 global fpreg
370 global spreg
371 global pcreg
372
373 prepare_for_trace_test
374
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" \
380 "" \
381 "collect $myregs" "^$"
382
383 # Begin the test.
384 run_trace_experiment $myregs args_test_func
385
386 test_register "\$$fpreg" $myregs
387 test_register "\$$spreg" $myregs
388 test_register "\$$pcreg" $myregs
389
390 gdb_test "tfind none" \
391 "#0 end .*" \
392 "collect $myregs: cease trace debugging"
393 }
394
395 proc gdb_collect_expression_test { func expr val msg } {
396 global cr
397 global gdb_prompt
398
399 prepare_for_trace_test
400
401 # Find the comment-identified line for setting this tracepoint.
402 set testline 0
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"
407 }
408 -re ".*$gdb_prompt " {
409 fail "collect $msg: find tracepoint line (skipping locals test)"
410 return
411 }
412 timeout {
413 fail "collect $msg: find tracepoint line (skipping locals test)"
414 return
415 }
416 }
417
418 gdb_test "trace $testline" \
419 "Tracepoint \[0-9\]+ at .*" \
420 "collect $msg: set tracepoint"
421 gdb_trace_setactions "collect $msg: define actions" \
422 "" \
423 "collect $expr" "^$"
424
425 # Begin the test.
426 run_trace_experiment $msg $func
427
428 gdb_test "print $expr" \
429 "\\$\[0-9\]+ = $val$cr" \
430 "collect $msg: got expected value '$val'"
431
432 gdb_test "tfind none" \
433 "#0 end .*" \
434 "collect $msg: cease trace debugging"
435 }
436
437 proc gdb_collect_globals_test { } {
438 global cr
439 global gdb_prompt
440
441 prepare_for_trace_test
442
443 # Find the comment-identified line for setting this tracepoint.
444 set testline 0
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"
449 }
450 -re ".*$gdb_prompt " {
451 fail "collect globals: find tracepoint line (skipping global test)"
452 return
453 }
454 timeout {
455 fail "collect globals: find tracepoint line (skipping global test)"
456 return
457 }
458 }
459
460 gdb_test "trace $testline" \
461 "Tracepoint \[0-9\]+ at .*" \
462 "collect globals: set tracepoint"
463 gdb_trace_setactions "collect globals: define actions" \
464 "" \
465 "collect globalc, globali, globalf, globald" "^$" \
466 "collect globalstruct, globalp, globalarr" "^$"
467
468 # Begin the test.
469 run_trace_experiment "globals" globals_test_func
470
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"
483
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"
496
497 gdb_test "print globalp == &globalstruct" \
498 "\\$\[0-9\]+ = 1$cr" \
499 "collect globals: collected global pointer"
500
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"
510
511 gdb_test "tfind none" \
512 "#0 end .*" \
513 "collect globals: cease trace debugging"
514 }
515
516 proc gdb_trace_collection_test {} {
517 global fpreg
518 global spreg
519 global pcreg
520
521 gdb_collect_args_test "\$args" \
522 "args collectively"
523 gdb_collect_args_test "argc, argi, argf, argd, argstruct, argarray" \
524 "args individually"
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
551
552 #
553 # Expression tests:
554 #
555 # *x (**x, ...)
556 # x.y (x.y.z, ...)
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)
560 # NOTE:
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
565 # calculation.
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)
595 # cast expr
596 # stack data
597
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\)\]"
622
623 }
624
625 clean_restart $executable
626 runto_main
627
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"
632 return 1;
633 }
634
635 # Body of test encased in a proc so we can return prematurely.
636 gdb_trace_collection_test
637
638 # Finished!
639 gdb_test "tfind none" ".*" ""
This page took 0.070208 seconds and 4 git commands to generate.