* gdb.trace/tfind.exp: Adjust expected disassembly output.
[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
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.
176
177 setup_xfail "*-*-*"
178 gdb_test "print argarray\[0\]" \
179 "\\$\[0-9\]+ = 111$cr" \
180 "collect $msg: collected argarray #0"
181
182 setup_xfail "*-*-*"
183 gdb_test "print argarray\[1\]" \
184 "\\$\[0-9\]+ = 112$cr" \
185 "collect $msg: collected argarray #1"
186
187 setup_xfail "*-*-*"
188 gdb_test "print argarray\[2\]" \
189 "\\$\[0-9\]+ = 113$cr" \
190 "collect $msg: collected argarray #2"
191
192 setup_xfail "*-*-*"
193 gdb_test "print argarray\[3\]" \
194 "\\$\[0-9\]+ = 114$cr" \
195 "collect $msg: collected argarray #3"
196
197 gdb_test "tfind none" \
198 "#0 end .*" \
199 "collect $msg: cease trace debugging"
200 }
201
202 proc gdb_collect_argstruct_test { myargs msg } {
203 global cr
204 global gdb_prompt
205
206 prepare_for_trace_test
207
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" \
212 "" \
213 "collect $myargs" "^$"
214
215 # Begin the test.
216 run_trace_experiment $msg argstruct_test_func
217
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"
231
232 gdb_test "tfind none" \
233 "#0 end .*" \
234 "collect $msg: cease trace debugging"
235 }
236
237
238 proc gdb_collect_argarray_test { myargs msg } {
239 global cr
240 global gdb_prompt
241
242 prepare_for_trace_test
243
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" \
248 "" \
249 "collect $myargs" "^$"
250
251 # Begin the test.
252 run_trace_experiment $msg argarray_test_func
253
254 # array arg as only argument
255
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.
262
263 setup_xfail "*-*-*"
264 gdb_test "print argarray\[0\]" \
265 "\\$\[0-9\]+ = 111$cr" \
266 "collect $msg: collected argarray #0"
267
268 setup_xfail "*-*-*"
269 gdb_test "print argarray\[1\]" \
270 "\\$\[0-9\]+ = 112$cr" \
271 "collect $msg: collected argarray #1"
272
273 setup_xfail "*-*-*"
274 gdb_test "print argarray\[2\]" \
275 "\\$\[0-9\]+ = 113$cr" \
276 "collect $msg: collected argarray #2"
277
278 setup_xfail "*-*-*"
279 gdb_test "print argarray\[3\]" \
280 "\\$\[0-9\]+ = 114$cr" \
281 "collect $msg: collected argarray #3"
282
283 gdb_test "tfind none" \
284 "#0 end .*" \
285 "collect $msg: cease trace debugging"
286 }
287
288
289 proc gdb_collect_locals_test { func mylocs msg } {
290 global cr
291 global gdb_prompt
292
293 prepare_for_trace_test
294
295 # Find the comment-identified line for setting this tracepoint.
296 set testline 0
297 send_gdb "list $func, +30\n"
298 gdb_expect {
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"
302 }
303 -re ".*$gdb_prompt " {
304 fail "collect $msg: find tracepoint line (skipping locals test)"
305 return
306 }
307 timeout {
308 fail "collect $msg: find tracepoint line (skipping locals test)"
309 return
310 }
311 }
312
313 gdb_test "trace $testline" \
314 "Tracepoint \[0-9\]+ at .*" \
315 "collect $msg: set tracepoint"
316 gdb_trace_setactions "collect $msg: define actions" \
317 "" \
318 "collect $mylocs" "^$"
319
320 # Begin the test.
321 run_trace_experiment $msg $func
322
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"
335
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"
348
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"
361
362
363 gdb_test "tfind none" \
364 "#0 end .*" \
365 "collect $msg: cease trace debugging"
366 }
367
368 proc gdb_collect_registers_test { myregs } {
369 global cr
370 global gdb_prompt
371 global fpreg
372 global spreg
373 global pcreg
374
375 prepare_for_trace_test
376
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" \
382 "" \
383 "collect $myregs" "^$"
384
385 # Begin the test.
386 run_trace_experiment $myregs args_test_func
387
388 test_register "\$$fpreg" $myregs
389 test_register "\$$spreg" $myregs
390 test_register "\$$pcreg" $myregs
391
392 gdb_test "tfind none" \
393 "#0 end .*" \
394 "collect $myregs: cease trace debugging"
395 }
396
397 proc gdb_collect_expression_test { func expr val msg } {
398 global cr
399 global gdb_prompt
400
401 prepare_for_trace_test
402
403 # Find the comment-identified line for setting this tracepoint.
404 set testline 0
405 send_gdb "list $func, +30\n"
406 gdb_expect {
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"
410 }
411 -re ".*$gdb_prompt " {
412 fail "collect $msg: find tracepoint line (skipping locals test)"
413 return
414 }
415 timeout {
416 fail "collect $msg: find tracepoint line (skipping locals test)"
417 return
418 }
419 }
420
421 gdb_test "trace $testline" \
422 "Tracepoint \[0-9\]+ at .*" \
423 "collect $msg: set tracepoint"
424 gdb_trace_setactions "collect $msg: define actions" \
425 "" \
426 "collect $expr" "^$"
427
428 # Begin the test.
429 run_trace_experiment $msg $func
430
431 gdb_test "print $expr" \
432 "\\$\[0-9\]+ = $val$cr" \
433 "collect $msg: got expected value '$val'"
434
435 gdb_test "tfind none" \
436 "#0 end .*" \
437 "collect $msg: cease trace debugging"
438 }
439
440 proc gdb_collect_globals_test { } {
441 global cr
442 global gdb_prompt
443
444 prepare_for_trace_test
445
446 # Find the comment-identified line for setting this tracepoint.
447 set testline 0
448 send_gdb "list globals_test_func, +30\n"
449 gdb_expect {
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"
453 }
454 -re ".*$gdb_prompt " {
455 fail "collect globals: find tracepoint line (skipping global test)"
456 return
457 }
458 timeout {
459 fail "collect globals: find tracepoint line (skipping global test)"
460 return
461 }
462 }
463
464 gdb_test "trace $testline" \
465 "Tracepoint \[0-9\]+ at .*" \
466 "collect globals: set tracepoint"
467 gdb_trace_setactions "collect globals: define actions" \
468 "" \
469 "collect globalc, globali, globalf, globald" "^$" \
470 "collect globalstruct, globalp, globalarr" "^$"
471
472 # Begin the test.
473 run_trace_experiment "globals" globals_test_func
474
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"
487
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"
500
501 gdb_test "print globalp == &globalstruct" \
502 "\\$\[0-9\]+ = 1$cr" \
503 "collect globals: collected global pointer"
504
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"
514
515 gdb_test "tfind none" \
516 "#0 end .*" \
517 "collect globals: cease trace debugging"
518 }
519
520 proc gdb_trace_collection_test {} {
521 global fpreg
522 global spreg
523 global pcreg
524
525 gdb_collect_args_test "\$args" \
526 "args collectively"
527 gdb_collect_args_test "argc, argi, argf, argd, argstruct, argarray" \
528 "args individually"
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
555
556 #
557 # Expression tests:
558 #
559 # *x (**x, ...)
560 # x.y (x.y.z, ...)
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)
564 # NOTE:
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
569 # calculation.
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)
599 # cast expr
600 # stack data
601
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\)\]"
626
627 }
628
629 clean_restart $executable
630 runto_main
631
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"
636 return 1;
637 }
638
639 # Body of test encased in a proc so we can return prematurely.
640 gdb_trace_collection_test
641
642 # Finished!
643 gdb_test "tfind none" "" ""
This page took 0.043239 seconds and 4 git commands to generate.