5d510abc75bde5909473280ee04d9ff513a2ee10
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.trace / collection.exp
1 # Copyright 1998, 2005, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 load_lib "trace-support.exp"
17
18 if $tracelevel then {
19 strace $tracelevel
20 }
21
22 set prms_id 0
23 set bug_id 0
24
25 set testfile "collection"
26 set srcfile ${testfile}.c
27 set executable $testfile
28 set binfile $objdir/$subdir/$executable
29
30 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
31 executable {debug nowarnings}] != "" } {
32 untested collection.exp
33 return -1
34 }
35
36 # Tests:
37 # 1) $args
38 # 2) function args by name
39 # 3) $locs
40 # 4) function locals by name
41 # 5) $regs
42 # 6) registers by name ($sp, $fp?)
43 # 7) globals by name
44 # 8) expressions (lots of different kinds: local and global)
45
46 set ws "\[\r\n\t \]+"
47 set cr "\[\r\n\]+"
48
49 if [istarget "x86_64-*"] then {
50 set fpreg "rbp"
51 set spreg "rsp"
52 set pcreg "rip"
53 } elseif [istarget "i?86-*"] then {
54 set fpreg "ebp"
55 set spreg "esp"
56 set pcreg "eip"
57 } else {
58 set fpreg "fp"
59 set spreg "sp"
60 set pcreg "pc"
61 }
62
63 #
64 # Utility procs
65 #
66
67 proc test_register { reg test_id } {
68 global cr
69 global gdb_prompt
70
71 gdb_test_multiple "print /x $reg" "" {
72 -re "\\$\[0-9\]+ = \[x0\]+$cr$gdb_prompt $" {
73 fail "collect $test_id: collected $reg (zero)"
74 }
75 -re "\\$\[0-9\]+ = \[x0-9a-fA-F\]+$cr$gdb_prompt $" {
76 pass "collect $test_id: collected $reg"
77 }
78 -re "\[Ee\]rror.*$gdb_prompt $" {
79 fail "collect $test_id: collected $reg (error)"
80 }
81 }
82 }
83
84 proc prepare_for_trace_test {} {
85 global executable
86
87 clean_restart $executable
88
89 runto_main
90
91 gdb_test "break begin" "" ""
92 gdb_test "break end" "" ""
93 }
94
95 proc run_trace_experiment { msg test_func } {
96 global gdb_prompt
97
98 gdb_test "continue" \
99 ".*Breakpoint \[0-9\]+, begin .*" \
100 "collect $msg: advance to begin"
101
102 set test "collect $msg: start trace experiment"
103 gdb_test_multiple "tstart" "$test" {
104 -re "^tstart\r\n$gdb_prompt $" {
105 pass "$test"
106 }
107 }
108
109 gdb_test "continue" \
110 "Continuing.*Breakpoint \[0-9\]+, end.*" \
111 "collect $msg: run trace experiment"
112 gdb_test "tstop" \
113 "\[\r\n\]+" \
114 "collect $msg: stop trace experiment"
115 gdb_test "tfind start" \
116 "#0 $test_func .*" \
117 "collect $msg: tfind test frame"
118 }
119
120
121 #
122 # Test procs
123 #
124
125 proc gdb_collect_args_test { myargs msg } {
126 global cr
127 global gdb_prompt
128
129 prepare_for_trace_test
130
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" \
135 "" \
136 "collect $myargs" "^$"
137
138 # Begin the test.
139 run_trace_experiment $msg args_test_func
140
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"
153
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"
167
168 # array arg as one of several args (near end of list)
169 gdb_test "print argarray\[0\]" \
170 "\\$\[0-9\]+ = 111$cr" \
171 "collect $msg: collected argarray #0"
172 gdb_test "print argarray\[1\]" \
173 "\\$\[0-9\]+ = 112$cr" \
174 "collect $msg: collected argarray #1"
175 gdb_test "print argarray\[2\]" \
176 "\\$\[0-9\]+ = 113$cr" \
177 "collect $msg: collected argarray #2"
178 gdb_test "print argarray\[3\]" \
179 "\\$\[0-9\]+ = 114$cr" \
180 "collect $msg: collected argarray #3"
181
182 gdb_test "tfind none" \
183 "#0 end .*" \
184 "collect $msg: cease trace debugging"
185 }
186
187 proc gdb_collect_argstruct_test { myargs msg } {
188 global cr
189 global gdb_prompt
190
191 prepare_for_trace_test
192
193 gdb_test "trace argstruct_test_func" \
194 "Tracepoint \[0-9\]+ at .*" \
195 "collect $msg: set tracepoint"
196 gdb_trace_setactions "collect $msg: define actions" \
197 "" \
198 "collect $myargs" "^$"
199
200 # Begin the test.
201 run_trace_experiment $msg argstruct_test_func
202
203 # struct argument as only argument
204 gdb_test "print argstruct.memberc" \
205 "\\$\[0-9\]+ = 101 'e'$cr" \
206 "collect $msg: collected arg struct member char"
207 gdb_test "print argstruct.memberi" \
208 "\\$\[0-9\]+ = 102$cr" \
209 "collect $msg: collected arg struct member int"
210 gdb_test "print argstruct.memberf" \
211 "\\$\[0-9\]+ = 103.\[23\]\[0-9\]*$cr" \
212 "collect $msg: collected arg struct member float"
213 gdb_test "print argstruct.memberd" \
214 "\\$\[0-9\]+ = 104.\[34\]\[0-9\]*$cr" \
215 "collect $msg: collected arg struct member double"
216
217 gdb_test "tfind none" \
218 "#0 end .*" \
219 "collect $msg: cease trace debugging"
220 }
221
222
223 proc gdb_collect_argarray_test { myargs msg } {
224 global cr
225 global gdb_prompt
226
227 prepare_for_trace_test
228
229 gdb_test "trace argarray_test_func" \
230 "Tracepoint \[0-9\]+ at .*" \
231 "collect $msg: set tracepoint"
232 gdb_trace_setactions "collect $msg: define actions" \
233 "" \
234 "collect $myargs" "^$"
235
236 # Begin the test.
237 run_trace_experiment $msg argarray_test_func
238
239 # array arg as only argument
240 gdb_test "print argarray\[0\]" \
241 "\\$\[0-9\]+ = 111$cr" \
242 "collect $msg: collected argarray #0"
243 gdb_test "print argarray\[1\]" \
244 "\\$\[0-9\]+ = 112$cr" \
245 "collect $msg: collected argarray #1"
246 gdb_test "print argarray\[2\]" \
247 "\\$\[0-9\]+ = 113$cr" \
248 "collect $msg: collected argarray #2"
249 gdb_test "print argarray\[3\]" \
250 "\\$\[0-9\]+ = 114$cr" \
251 "collect $msg: collected argarray #3"
252
253 gdb_test "tfind none" \
254 "#0 end .*" \
255 "collect $msg: cease trace debugging"
256 }
257
258
259 proc gdb_collect_locals_test { func mylocs msg } {
260 global cr
261 global gdb_prompt
262
263 prepare_for_trace_test
264
265 # Find the comment-identified line for setting this tracepoint.
266 set testline 0
267 send_gdb "list $func, +30\n"
268 gdb_expect {
269 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
270 set testline $expect_out(1,string)
271 pass "collect $msg: find tracepoint line"
272 }
273 -re ".*$gdb_prompt " {
274 fail "collect $msg: find tracepoint line (skipping locals test)"
275 return
276 }
277 timeout {
278 fail "collect $msg: find tracepoint line (skipping locals test)"
279 return
280 }
281 }
282
283 gdb_test "trace $testline" \
284 "Tracepoint \[0-9\]+ at .*" \
285 "collect $msg: set tracepoint"
286 gdb_trace_setactions "collect $msg: define actions" \
287 "" \
288 "collect $mylocs" "^$"
289
290 # Begin the test.
291 run_trace_experiment $msg $func
292
293 gdb_test "print locc" \
294 "\\$\[0-9\]+ = 11 '.\[a-z0-7\]+'$cr" \
295 "collect $msg: collected local char"
296 gdb_test "print loci" \
297 "\\$\[0-9\]+ = 12$cr" \
298 "collect $msg: collected local int"
299 gdb_test "print locf" \
300 "\\$\[0-9\]+ = 13.\[23\]\[0-9\]*$cr" \
301 "collect $msg: collected local float"
302 gdb_test "print locd" \
303 "\\$\[0-9\]+ = 14.\[34\]\[0-9\]*$cr" \
304 "collect $msg: collected local double"
305
306 gdb_test "print locst.memberc" \
307 "\\$\[0-9\]+ = 15 '.017'$cr" \
308 "collect $msg: collected local member char"
309 gdb_test "print locst.memberi" \
310 "\\$\[0-9\]+ = 16$cr" \
311 "collect $msg: collected local member int"
312 gdb_test "print locst.memberf" \
313 "\\$\[0-9\]+ = 17.\[67\]\[0-9\]*$cr" \
314 "collect $msg: collected local member float"
315 gdb_test "print locst.memberd" \
316 "\\$\[0-9\]+ = 18.\[78\]\[0-9\]*$cr" \
317 "collect $msg: collected local member double"
318
319 gdb_test "print locar\[0\]" \
320 "\\$\[0-9\]+ = 121$cr" \
321 "collect $msg: collected locarray #0"
322 gdb_test "print locar\[1\]" \
323 "\\$\[0-9\]+ = 122$cr" \
324 "collect $msg: collected locarray #1"
325 gdb_test "print locar\[2\]" \
326 "\\$\[0-9\]+ = 123$cr" \
327 "collect $msg: collected locarray #2"
328 gdb_test "print locar\[3\]" \
329 "\\$\[0-9\]+ = 124$cr" \
330 "collect $msg: collected locarray #3"
331
332
333 gdb_test "tfind none" \
334 "#0 end .*" \
335 "collect $msg: cease trace debugging"
336 }
337
338 proc gdb_collect_registers_test { myregs } {
339 global cr
340 global gdb_prompt
341 global fpreg
342 global spreg
343 global pcreg
344
345 prepare_for_trace_test
346
347 # We'll simply re-use the args_test_function for this test
348 gdb_test "trace args_test_func" \
349 "Tracepoint \[0-9\]+ at .*" \
350 "collect $myregs: set tracepoint"
351 gdb_trace_setactions "collect $myregs: define actions" \
352 "" \
353 "collect $myregs" "^$"
354
355 # Begin the test.
356 run_trace_experiment $myregs args_test_func
357
358 test_register "\$$fpreg" $myregs
359 test_register "\$$spreg" $myregs
360 test_register "\$$pcreg" $myregs
361
362 gdb_test "tfind none" \
363 "#0 end .*" \
364 "collect $myregs: cease trace debugging"
365 }
366
367 proc gdb_collect_expression_test { func expr val msg } {
368 global cr
369 global gdb_prompt
370
371 prepare_for_trace_test
372
373 # Find the comment-identified line for setting this tracepoint.
374 set testline 0
375 send_gdb "list $func, +30\n"
376 gdb_expect {
377 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
378 set testline $expect_out(1,string)
379 pass "collect $msg: find tracepoint line"
380 }
381 -re ".*$gdb_prompt " {
382 fail "collect $msg: find tracepoint line (skipping locals test)"
383 return
384 }
385 timeout {
386 fail "collect $msg: find tracepoint line (skipping locals test)"
387 return
388 }
389 }
390
391 gdb_test "trace $testline" \
392 "Tracepoint \[0-9\]+ at .*" \
393 "collect $msg: set tracepoint"
394 gdb_trace_setactions "collect $msg: define actions" \
395 "" \
396 "collect $expr" "^$"
397
398 # Begin the test.
399 run_trace_experiment $msg $func
400
401 gdb_test "print $expr" \
402 "\\$\[0-9\]+ = $val$cr" \
403 "collect $msg: got expected value '$val'"
404
405 gdb_test "tfind none" \
406 "#0 end .*" \
407 "collect $msg: cease trace debugging"
408 }
409
410 proc gdb_collect_globals_test { } {
411 global cr
412 global gdb_prompt
413
414 prepare_for_trace_test
415
416 # Find the comment-identified line for setting this tracepoint.
417 set testline 0
418 send_gdb "list globals_test_func, +30\n"
419 gdb_expect {
420 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
421 set testline $expect_out(1,string)
422 pass "collect globals: find tracepoint line"
423 }
424 -re ".*$gdb_prompt " {
425 fail "collect globals: find tracepoint line (skipping global test)"
426 return
427 }
428 timeout {
429 fail "collect globals: find tracepoint line (skipping global test)"
430 return
431 }
432 }
433
434 gdb_test "trace $testline" \
435 "Tracepoint \[0-9\]+ at .*" \
436 "collect globals: set tracepoint"
437 gdb_trace_setactions "collect globals: define actions" \
438 "" \
439 "collect globalc, globali, globalf, globald" "^$" \
440 "collect globalstruct, globalp, globalarr" "^$"
441
442 # Begin the test.
443 run_trace_experiment "globals" globals_test_func
444
445 gdb_test "print globalc" \
446 "\\$\[0-9\]+ = 71 'G'$cr" \
447 "collect globals: collected global char"
448 gdb_test "print globali" \
449 "\\$\[0-9\]+ = 72$cr" \
450 "collect globals: collected global int"
451 gdb_test "print globalf" \
452 "\\$\[0-9\]+ = 73.\[23\]\[0-9\]*$cr" \
453 "collect globals: collected global float"
454 gdb_test "print globald" \
455 "\\$\[0-9\]+ = 74.\[34\]\[0-9\]*$cr" \
456 "collect globals: collected global double"
457
458 gdb_test "print globalstruct.memberc" \
459 "\\$\[0-9\]+ = 81 'Q'$cr" \
460 "collect globals: collected struct char member"
461 gdb_test "print globalstruct.memberi" \
462 "\\$\[0-9\]+ = 82$cr" \
463 "collect globals: collected struct member int"
464 gdb_test "print globalstruct.memberf" \
465 "\\$\[0-9\]+ = 83.\[23\]\[0-9\]*$cr" \
466 "collect globals: collected struct member float"
467 gdb_test "print globalstruct.memberd" \
468 "\\$\[0-9\]+ = 84.\[34\]\[0-9\]*$cr" \
469 "collect globals: collected struct member double"
470
471 gdb_test "print globalp == &globalstruct" \
472 "\\$\[0-9\]+ = 1$cr" \
473 "collect globals: collected global pointer"
474
475 gdb_test "print globalarr\[1\]" \
476 "\\$\[0-9\]+ = 1$cr" \
477 "collect globals: collected global array element #1"
478 gdb_test "print globalarr\[2\]" \
479 "\\$\[0-9\]+ = 2$cr" \
480 "collect globals: collected global array element #2"
481 gdb_test "print globalarr\[3\]" \
482 "\\$\[0-9\]+ = 3$cr" \
483 "collect globals: collected global array element #3"
484
485 gdb_test "tfind none" \
486 "#0 end .*" \
487 "collect globals: cease trace debugging"
488 }
489
490 proc gdb_trace_collection_test {} {
491 global fpreg
492 global spreg
493 global pcreg
494
495 gdb_collect_args_test "\$args" \
496 "args collectively"
497 gdb_collect_args_test "argc, argi, argf, argd, argstruct, argarray" \
498 "args individually"
499 gdb_collect_argstruct_test "\$args" \
500 "argstruct collectively"
501 gdb_collect_argstruct_test "argstruct" \
502 "argstruct individually"
503 gdb_collect_argarray_test "\$args" \
504 "argarray collectively"
505 gdb_collect_argarray_test "argarray" \
506 "argarray individually"
507 gdb_collect_locals_test local_test_func "\$locals" \
508 "auto locals collectively"
509 gdb_collect_locals_test local_test_func \
510 "locc, loci, locf, locd, locst, locar" \
511 "auto locals individually"
512 gdb_collect_locals_test reglocal_test_func "\$locals" \
513 "register locals collectively"
514 gdb_collect_locals_test reglocal_test_func \
515 "locc, loci, locf, locd, locst, locar" \
516 "register locals individually"
517 gdb_collect_locals_test statlocal_test_func "\$locals" \
518 "static locals collectively"
519 gdb_collect_locals_test statlocal_test_func \
520 "locc, loci, locf, locd, locst, locar" \
521 "static locals individually"
522 gdb_collect_registers_test "\$regs"
523 gdb_collect_registers_test "\$$fpreg, \$$spreg, \$$pcreg"
524 gdb_collect_globals_test
525
526 #
527 # Expression tests:
528 #
529 # *x (**x, ...)
530 # x.y (x.y.z, ...)
531 # x->y (x->y->z, ...)
532 # x[2] (x[2][3], ...) (const index)
533 # x[y] (x[y][z], ...) (index to be char, short, long, float, double)
534 # NOTE:
535 # We test the following operators by using them in an array index
536 # expression -- because the naked result of an operator is not really
537 # collected. To be sure the operator was evaluated correctly on the
538 # target, we have to actually use the result eg. in an array offset
539 # calculation.
540 # x[y + z] (tests addition: y and z various combos of types, sclasses)
541 # x[y - z] (tests subtraction) (ditto)
542 # x[y * z] (tests multiplication) (ditto)
543 # x[y / z] (tests division) (ditto)
544 # x[y % z] (tests modulo division) (ditto)
545 # x[y == z] (tests equality relation) (ditto) UNSUPPORTED
546 # x[y != z] (tests inequality relation) (ditto) UNSUPPORTED
547 # x[y > z] (tests greater-than relation) (ditto) UNSUPPORTED
548 # x[y < z] (tests less-than relation) (ditto) UNSUPPORTED
549 # x[y >= z] (tests greater-than-or-equal relation) (ditto) UNSUPPORTED
550 # x[y <= z] (tests less-than-or-equal relation) (ditto) UNSUPPORTED
551 # x[y && z] (tests logical and) (ditto) UNSUPPORTED
552 # x[y || z] (tests logical or) (ditto) UNSUPPORTED
553 # x[y & z] (tests binary and) (ditto) UNSUPPORTED
554 # x[y | z] (tests binary or) (ditto) UNSUPPORTED
555 # x[y ^ z] (tests binary xor) (ditto) UNSUPPORTED
556 # x[y ? z1 : z2] (tests ternary operator) (ditto) UNSUPPORTED
557 # x[y << z] (tests shift-left) (ditto) UNSUPPORTED
558 # x[y >> z] (tests shift-right) (ditto) UNSUPPORTED
559 # x[y = z] (tests assignment operator) (ditto) UNSUPPORTED
560 # x[++y] (tests pre-increment operator) (ditto) UNSUPPORTED
561 # x[--y] (tests pre-decrement operator) (ditto) UNSUPPORTED
562 # x[y++] (tests post-increment operator) (ditto) UNSUPPORTED
563 # x[y--] (tests post-decrement operator) (ditto) UNSUPPORTED
564 # x[+y] (tests unary plus) (ditto)
565 # x[-y] (tests unary minus) (ditto)
566 # x[!y] (tests logical not) (ditto) UNSUPPORTED
567 # x[~y] (tests binary not) (ditto) UNSUPPORTED
568 # x[(y, z)] (tests comma expression) (ditto)
569 # cast expr
570 # stack data
571
572 gdb_collect_expression_test globals_test_func \
573 "globalstruct.memberi" "82" "a.b"
574 gdb_collect_expression_test globals_test_func \
575 "globalp->memberc" "81 'Q'" "a->b"
576 gdb_collect_expression_test globals_test_func \
577 "globalarr\[2\]" "2" "a\[2\]"
578 gdb_collect_expression_test globals_test_func \
579 "globalarr\[l3\]" "3" "a\[b\]"
580 gdb_collect_expression_test globals_test_func \
581 "globalarr\[l3 + l2\]" "5" "a\[b + c\]"
582 gdb_collect_expression_test globals_test_func \
583 "globalarr\[l3 - l2\]" "1" "a\[b - c\]"
584 gdb_collect_expression_test globals_test_func \
585 "globalarr\[l3 * l2\]" "6" "a\[b * c\]"
586 gdb_collect_expression_test globals_test_func \
587 "globalarr\[l6 / l3\]" "2" "a\[b / c\]"
588 gdb_collect_expression_test globals_test_func \
589 "globalarr\[l7 % l3\]" "1" "a\[b % c\]"
590 gdb_collect_expression_test globals_test_func \
591 "globalarr\[+l1\]" "1" "a\[+b\]"
592 gdb_collect_expression_test globals_test_func \
593 "globalarr\[-lminus\]" "2" "a\[-b\]"
594 gdb_collect_expression_test globals_test_func \
595 "globalarr\[\(l6, l7\)\]" "7" "a\[\(b, c\)\]"
596
597 }
598
599 clean_restart $executable
600 runto_main
601
602 # We generously give ourselves one "pass" if we successfully
603 # detect that this test cannot be run on this target!
604 if { ![gdb_target_supports_trace] } then {
605 pass "Current target does not support trace"
606 return 1;
607 }
608
609 # Body of test encased in a proc so we can return prematurely.
610 gdb_trace_collection_test
611
612 # Finished!
613 gdb_test "tfind none" "" ""
This page took 0.051227 seconds and 3 git commands to generate.