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