xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.trace/collection.exp (revision 4b004442778f1201b2161e87fd65ba87aae6601a)
1# Copyright 1998-2020 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
16load_lib "trace-support.exp"
17
18
19standard_testfile
20set executable $testfile
21
22if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug nowarnings nopie}]} {
23    return -1
24}
25
26# Tests:
27# 1) $args
28# 2) function args by name
29# 3) $locs
30# 4) function locals by name
31# 5) $regs
32# 6) registers by name ($sp, $fp?)
33# 7) globals by name
34# 8) expressions (lots of different kinds: local and global)
35
36set ws "\[\r\n\t \]+"
37set cr "\[\r\n\]+"
38
39#
40# Utility procs
41#
42
43proc test_register { reg test_id } {
44    global cr
45    global gdb_prompt
46
47    gdb_test_multiple "print /x $reg" "" {
48	-re "\\$\[0-9\]+ = \[x0\]+$cr$gdb_prompt $" {
49	    fail "collect $test_id: collected $reg (zero)"
50	}
51	-re "\\$\[0-9\]+ = \[x0-9a-fA-F\]+$cr$gdb_prompt $" {
52	    pass "collect $test_id: collected $reg"
53	}
54	-re "\[Ee\]rror.*$gdb_prompt $" {
55	    fail "collect $test_id: collected $reg (error)"
56	}
57    }
58}
59
60proc prepare_for_trace_test {} {
61    global executable
62
63    clean_restart $executable
64
65    runto_main
66
67    gdb_breakpoint "begin" qualified
68    gdb_breakpoint "end" qualified
69}
70
71proc run_trace_experiment { msg test_func } {
72    global gdb_prompt
73
74    gdb_test "continue" \
75	".*Breakpoint \[0-9\]+, begin .*" \
76	"collect $msg: advance to begin"
77
78    set test "collect $msg: start trace experiment"
79    gdb_test_multiple "tstart" "$test" {
80	-re "^tstart\r\n$gdb_prompt $" {
81	    pass "$test"
82	}
83    }
84
85    gdb_test "continue" \
86	    "Continuing.*Breakpoint \[0-9\]+, end.*" \
87	    "collect $msg: run trace experiment"
88    gdb_test "tstop" \
89	    "\[\r\n\]+" \
90	    "collect $msg: stop trace experiment"
91    gdb_test "tfind start" \
92	    "#0  $test_func .*" \
93	    "collect $msg: tfind test frame"
94}
95
96
97#
98# Test procs
99#
100
101proc gdb_collect_args_test { myargs msg } {
102    global cr
103    global gdb_prompt
104
105    prepare_for_trace_test
106
107    gdb_test "trace args_test_func" \
108	    "Tracepoint \[0-9\]+ at .*" \
109	    "collect $msg: set tracepoint"
110    gdb_trace_setactions "collect $msg: define actions" \
111	    "" \
112	    "collect $myargs" "^$"
113
114    # Begin the test.
115    run_trace_experiment $msg args_test_func
116
117    # Frame arguments and their entry values are displayed correctly with
118    # various values of "print entry-values" when a trace frame is
119    # selected.
120
121    gdb_test "tfind -1" ".*" ""
122    gdb_test_no_output "set print entry-values only" ""
123    gdb_test "tfind 0" \
124	" \\(argc@entry=\[^,\]*, argi@entry=\[^,\]*, argf@entry=\[^,\]*, argd@entry=\[^,\]*, argstruct@entry=\[^,\]*, argarray@entry=\[^,\]*\\) .*" \
125	"collect $msg: tfind 0 with entry-values only"
126
127    gdb_test "tfind -1" ".*" ""
128    gdb_test_no_output "set print entry-values both" ""
129    gdb_test "tfind 0" \
130	" \\(argc=\[^,\]*, argc@entry=\[^,\]*, argi=\[^,\]*, argi@entry=\[^,\]*, argf=\[^,\]*, argf@entry=\[^,\]*, argd=\[^,\]*, argd@entry=\[^,\]*, argstruct=\[^,\]*, argstruct@entry=\[^,\]*, argarray=\[^,\]*, argarray@entry=\[^,\]*\\) .*" \
131	"collect $msg: tfind 0 with entry-values both"
132
133    gdb_test "print argc" \
134	    "\\$\[0-9\]+ = 1 '.001'$cr" \
135	    "collect $msg: collected arg char"
136    gdb_test "print argi" \
137	    "\\$\[0-9\]+ = 2$cr" \
138	    "collect $msg: collected arg int"
139    gdb_test "print argf" \
140	    "\\$\[0-9\]+ = 3.\[23\]\[0-9\]*$cr" \
141	    "collect $msg: collected arg float"
142    gdb_test "print argd" \
143	    "\\$\[0-9\]+ = 4.\[34\]\[0-9\]*$cr" \
144	    "collect $msg: collected arg double"
145
146    # struct arg as one of several args (near end of list)
147    gdb_test "print argstruct.memberc" \
148	    "\\$\[0-9\]+ = 101 'e'$cr" \
149	    "collect $msg: collected arg struct member char"
150    gdb_test "print argstruct.memberi" \
151	    "\\$\[0-9\]+ = 102$cr" \
152	    "collect $msg: collected arg struct member int"
153    gdb_test "print argstruct.memberf" \
154	    "\\$\[0-9\]+ = 103.\[23\]\[0-9\]*$cr" \
155	    "collect $msg: collected arg struct member float"
156    gdb_test "print argstruct.memberd" \
157	    "\\$\[0-9\]+ = 104.\[34\]\[0-9\]*$cr" \
158	    "collect $msg: collected arg struct member double"
159
160    # array arg as one of several args (near end of list)
161
162    # It isn't clear why is the test assuming the array's elements are
163    # collected.  In C, an array as function parameters is a special
164    # case; it's just a pointer into the caller's array, and as such,
165    # that's what normally the debug info describes.  Maybe this was
166    # originaly written for a compiler where array parameters were
167    # really described as arrays in debug info.
168
169    setup_xfail "*-*-*"
170    gdb_test "print argarray\[0\]" \
171	    "\\$\[0-9\]+ = 111$cr" \
172	    "collect $msg: collected argarray #0"
173
174    setup_xfail "*-*-*"
175    gdb_test "print argarray\[1\]" \
176	    "\\$\[0-9\]+ = 112$cr" \
177	    "collect $msg: collected argarray #1"
178
179    setup_xfail "*-*-*"
180    gdb_test "print argarray\[2\]" \
181	    "\\$\[0-9\]+ = 113$cr" \
182	    "collect $msg: collected argarray #2"
183
184    setup_xfail "*-*-*"
185    gdb_test "print argarray\[3\]" \
186	    "\\$\[0-9\]+ = 114$cr" \
187	    "collect $msg: collected argarray #3"
188
189    gdb_test "tfind none" \
190	    "#0  end .*" \
191	    "collect $msg: cease trace debugging"
192}
193
194proc gdb_collect_argstruct_test { myargs msg } {
195    global cr
196    global gdb_prompt
197
198    prepare_for_trace_test
199
200    gdb_test "trace argstruct_test_func" \
201	    "Tracepoint \[0-9\]+ at .*" \
202	    "collect $msg: set tracepoint"
203    gdb_trace_setactions "collect $msg: define actions" \
204	    "" \
205	    "collect $myargs" "^$"
206
207    # Begin the test.
208    run_trace_experiment $msg argstruct_test_func
209
210    # struct argument as only argument
211    gdb_test "print argstruct.memberc" \
212	    "\\$\[0-9\]+ = 101 'e'$cr" \
213	    "collect $msg: collected arg struct member char"
214    gdb_test "print argstruct.memberi" \
215	    "\\$\[0-9\]+ = 102$cr" \
216	    "collect $msg: collected arg struct member int"
217    gdb_test "print argstruct.memberf" \
218	    "\\$\[0-9\]+ = 103.\[23\]\[0-9\]*$cr" \
219	    "collect $msg: collected arg struct member float"
220    gdb_test "print argstruct.memberd" \
221	    "\\$\[0-9\]+ = 104.\[34\]\[0-9\]*$cr" \
222	    "collect $msg: collected arg struct member double"
223
224    gdb_test "tfind none" \
225	    "#0  end .*" \
226	    "collect $msg: cease trace debugging"
227}
228
229
230proc gdb_collect_argarray_test { myargs msg } {
231    global cr
232    global gdb_prompt
233
234    prepare_for_trace_test
235
236    gdb_test "trace argarray_test_func" \
237	    "Tracepoint \[0-9\]+ at .*" \
238	    "collect $msg: set tracepoint"
239    gdb_trace_setactions "collect $msg: define actions" \
240	    "" \
241	    "collect $myargs" "^$"
242
243    # Begin the test.
244    run_trace_experiment $msg argarray_test_func
245
246    # array arg as only argument
247
248    # It isn't clear why is the test assuming the array's elements are
249    # collected.  In C, an array as function parameters is a special
250    # case; it's just a pointer into the caller's array, and as such,
251    # that's what normally the debug info describes.  Maybe this was
252    # originaly written for a compiler where array parameters were
253    # really described as arrays in debug info.
254
255    setup_xfail "*-*-*"
256    gdb_test "print argarray\[0\]" \
257	    "\\$\[0-9\]+ = 111$cr" \
258	    "collect $msg: collected argarray #0"
259
260    setup_xfail "*-*-*"
261    gdb_test "print argarray\[1\]" \
262	    "\\$\[0-9\]+ = 112$cr" \
263	    "collect $msg: collected argarray #1"
264
265    setup_xfail "*-*-*"
266    gdb_test "print argarray\[2\]" \
267	    "\\$\[0-9\]+ = 113$cr" \
268	    "collect $msg: collected argarray #2"
269
270    setup_xfail "*-*-*"
271    gdb_test "print argarray\[3\]" \
272	    "\\$\[0-9\]+ = 114$cr" \
273	    "collect $msg: collected argarray #3"
274
275    gdb_test "tfind none" \
276	    "#0  end .*" \
277	    "collect $msg: cease trace debugging"
278}
279
280
281proc gdb_collect_locals_test { func mylocs msg } {
282    global cr
283    global gdb_prompt
284
285    prepare_for_trace_test
286
287    # Find the comment-identified line for setting this tracepoint.
288    set testline 0
289    gdb_test_multiple "list $func, +30" "collect $msg: find tracepoint line" {
290	-re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
291	    set testline $expect_out(1,string)
292	    pass "collect $msg: find tracepoint line"
293	}
294	-re ".*$gdb_prompt " {
295	    fail "collect $msg: find tracepoint line (skipping locals test)"
296	    return
297	}
298	timeout {
299	    fail "collect $msg: find tracepoint line (skipping locals test)"
300	    return
301	}
302    }
303
304    gdb_test "trace $testline" \
305	    "Tracepoint \[0-9\]+ at .*" \
306	    "collect $msg: set tracepoint"
307    gdb_trace_setactions "collect $msg: define actions" \
308	    "" \
309	    "collect $mylocs" "^$"
310
311    # Begin the test.
312    run_trace_experiment $msg $func
313
314    gdb_test "print locc" \
315	"\\$\[0-9\]+ = 11 '.\[a-z0-7\]+'$cr" \
316	    "collect $msg: collected local char"
317    gdb_test "print loci" \
318	    "\\$\[0-9\]+ = 12$cr" \
319	    "collect $msg: collected local int"
320    gdb_test "print locf" \
321	    "\\$\[0-9\]+ = 13.\[23\]\[0-9\]*$cr" \
322	    "collect $msg: collected local float"
323    gdb_test "print locd" \
324	    "\\$\[0-9\]+ = 14.\[34\]\[0-9\]*$cr" \
325	    "collect $msg: collected local double"
326
327    gdb_test "print locst.memberc" \
328	    "\\$\[0-9\]+ = 15 '.017'$cr" \
329	    "collect $msg: collected local member char"
330    gdb_test "print locst.memberi" \
331	    "\\$\[0-9\]+ = 16$cr" \
332	    "collect $msg: collected local member int"
333    gdb_test "print locst.memberf" \
334	    "\\$\[0-9\]+ = 17.\[67\]\[0-9\]*$cr" \
335	    "collect $msg: collected local member float"
336    gdb_test "print locst.memberd" \
337	    "\\$\[0-9\]+ = 18.\[78\]\[0-9\]*$cr" \
338	    "collect $msg: collected local member double"
339
340    gdb_test "print locar\[0\]" \
341	    "\\$\[0-9\]+ = 121$cr" \
342	    "collect $msg: collected locarray #0"
343    gdb_test "print locar\[1\]" \
344	    "\\$\[0-9\]+ = 122$cr" \
345	    "collect $msg: collected locarray #1"
346    gdb_test "print locar\[2\]" \
347	    "\\$\[0-9\]+ = 123$cr" \
348	    "collect $msg: collected locarray #2"
349    gdb_test "print locar\[3\]" \
350	    "\\$\[0-9\]+ = 124$cr" \
351	    "collect $msg: collected locarray #3"
352
353
354    gdb_test "tfind none" \
355	    "#0  end .*" \
356	    "collect $msg: cease trace debugging"
357}
358
359proc gdb_collect_registers_test { myregs } {
360    global cr
361    global gdb_prompt
362    global fpreg
363    global spreg
364    global pcreg
365
366    prepare_for_trace_test
367
368    # We'll simply re-use the args_test_function for this test
369    gdb_test "trace args_test_func" \
370	    "Tracepoint \[0-9\]+ at .*" \
371	    "collect $myregs: set tracepoint"
372    gdb_trace_setactions "collect $myregs: define actions" \
373	    "" \
374	    "collect $myregs" "^$"
375
376    # Begin the test.
377    run_trace_experiment $myregs args_test_func
378
379    test_register "\$$fpreg" $myregs
380    test_register "\$$spreg" $myregs
381    test_register "\$$pcreg" $myregs
382
383    gdb_test "tfind none" \
384	    "#0  end .*" \
385	    "collect $myregs: cease trace debugging"
386}
387
388proc gdb_collect_expression_test { func expr val msg } {
389    global cr
390    global gdb_prompt
391
392    prepare_for_trace_test
393
394    # Find the comment-identified line for setting this tracepoint.
395    set testline 0
396    gdb_test_multiple "list $func, +30" "collect $msg: find tracepoint line" {
397	-re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
398	    set testline $expect_out(1,string)
399	    pass "collect $msg: find tracepoint line"
400	}
401	-re ".*$gdb_prompt " {
402	    fail "collect $msg: find tracepoint line (skipping locals test)"
403	    return
404	}
405	timeout {
406	    fail "collect $msg: find tracepoint line (skipping locals test)"
407	    return
408	}
409    }
410
411    gdb_test "trace $testline" \
412	    "Tracepoint \[0-9\]+ at .*" \
413	    "collect $msg: set tracepoint"
414    gdb_trace_setactions "collect $msg: define actions" \
415	    "" \
416	    "collect $expr" "^$"
417
418    # Begin the test.
419    run_trace_experiment $msg $func
420
421    gdb_test "print $expr" \
422	    "\\$\[0-9\]+ = $val$cr" \
423	    "collect $msg: got expected value '$val'"
424
425    gdb_test "tfind none" \
426	    "#0  end .*" \
427	    "collect $msg: cease trace debugging"
428}
429
430proc gdb_collect_globals_test { } {
431    global cr
432    global gdb_prompt
433
434    prepare_for_trace_test
435
436    # Find the comment-identified line for setting this tracepoint.
437    set testline 0
438    gdb_test_multiple "list globals_test_func, +30" "collect globals: find tracepoint line" {
439	-re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
440	    set testline $expect_out(1,string)
441	    pass "collect globals: find tracepoint line"
442	}
443	-re ".*$gdb_prompt " {
444	    fail "collect globals: find tracepoint line (skipping global test)"
445	    return
446	}
447	timeout {
448	    fail "collect globals: find tracepoint line (skipping global test)"
449	    return
450	}
451    }
452
453    # Use use this to test collecting overlapping memory ranges
454    # (making use of UNOP_MEMVAL, as objects don't usually overlap
455    # other objects).  Note that globalarr2 should not be collected in
456    # any other way so that a regression test below can be effective.
457
458    set globalarr2_addr ""
459    set test "get address of globalarr2"
460    gdb_test_multiple "p /x &globalarr2" $test {
461	-re " = (0x\[0-9a-f\]+)\r\n$gdb_prompt $" {
462	    set globalarr2_addr $expect_out(1,string)
463	    pass $test
464	}
465    }
466
467    gdb_test "trace $testline" \
468	    "Tracepoint \[0-9\]+ at .*" \
469	    "collect globals: set tracepoint"
470    gdb_trace_setactions "collect globals: define actions" \
471	    "" \
472	    "collect globalc, globali, globalf, globald" "^$" \
473	    "collect globalstruct, globalp, globalarr" "^$" \
474	    "collect \{int \[4\]\}$globalarr2_addr" "^$" \
475	    "collect \{int \[2\]\}$globalarr2_addr" "^$" \
476	    "collect \{int \[4\]\}globalarr3" "^$"
477
478    # Begin the test.
479    run_trace_experiment "globals" globals_test_func
480
481    gdb_test "print globalc" \
482	    "\\$\[0-9\]+ = 71 'G'$cr" \
483	    "collect globals: collected global char"
484    gdb_test "print globali" \
485	    "\\$\[0-9\]+ = 72$cr" \
486	    "collect globals: collected global int"
487    gdb_test "print globalf" \
488	    "\\$\[0-9\]+ = 73.\[23\]\[0-9\]*$cr" \
489	    "collect globals: collected global float"
490    gdb_test "print globald" \
491	    "\\$\[0-9\]+ = 74.\[34\]\[0-9\]*$cr" \
492	    "collect globals: collected global double"
493
494    gdb_test "print globalstruct.memberc" \
495	    "\\$\[0-9\]+ = 81 'Q'$cr" \
496	    "collect globals: collected struct char member"
497    gdb_test "print globalstruct.memberi" \
498	    "\\$\[0-9\]+ = 82$cr" \
499	    "collect globals: collected struct member int"
500    gdb_test "print globalstruct.memberf" \
501	    "\\$\[0-9\]+ = 83.\[23\]\[0-9\]*$cr" \
502	    "collect globals: collected struct member float"
503    gdb_test "print globalstruct.memberd" \
504	    "\\$\[0-9\]+ = 84.\[34\]\[0-9\]*$cr" \
505	    "collect globals: collected struct member double"
506
507    gdb_test "print globalp == &globalstruct" \
508	    "\\$\[0-9\]+ = 1$cr" \
509	    "collect globals: collected global pointer"
510
511    gdb_test "print globalarr\[1\]" \
512	    "\\$\[0-9\]+ = 1$cr" \
513	    "collect globals: collected global array element #1"
514    gdb_test "print globalarr\[2\]" \
515	    "\\$\[0-9\]+ = 2$cr" \
516	    "collect globals: collected global array element #2"
517    gdb_test "print globalarr\[3\]" \
518	    "\\$\[0-9\]+ = 3$cr" \
519	    "collect globals: collected global array element #3"
520
521    # Check that we didn't mess up sort&merging memory ranges to
522    # collect.
523    gdb_test "print globalarr2" \
524	"\\$\[0-9\]+ = \\{0, 1, 2, 3\\}$cr" \
525	"collect globals: collected global array 2"
526
527    # GDB would internal error collecting UNOP_MEMVAL's whose address
528    # expression wasn't an rvalue (that's regtested in the
529    # corresponding 'collect' action above).  This just double checks
530    # we actually did collect what we wanted.
531    gdb_test "print globalarr3" \
532	"\\$\[0-9\]+ = \\{3, 2, 1, 0\\}$cr" \
533	"collect globals: collected global array 3"
534
535    gdb_test "tfind none" \
536	    "#0  end .*" \
537	    "collect globals: cease trace debugging"
538}
539
540# Test that when we've collected all fields of a structure
541# individually, we can print the whole structure in one go.
542proc gdb_collect_global_in_pieces_test { } {
543    global gdb_prompt
544
545    prepare_for_trace_test
546
547    # Find the comment-identified line for setting this tracepoint.
548    set testline 0
549    set msg "collect global in pieces: find tracepoint line"
550    gdb_test_multiple "list globals_test_func, +30" "$msg" {
551	-re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
552	    set testline $expect_out(1,string)
553	    pass "$msg"
554	}
555    }
556
557    if {$testline == 0} {
558	return
559    }
560
561    gdb_test "trace $testline" \
562	"Tracepoint \[0-9\]+ at .*" \
563	"collect global in pieces: set tracepoint"
564    gdb_trace_setactions "collect global in pieces: define actions" \
565	    "" \
566	    "collect global_pieces.a, global_pieces.b" \
567	    "^$"
568
569    # Begin the test.
570    run_trace_experiment "global in pieces" globals_test_func
571
572    gdb_test "print /x global_pieces.a" " = 0x12345678" \
573	"collect global in pieces: print piece a"
574    gdb_test "print /x global_pieces.b" " = 0x87654321" \
575	"collect global in pieces: print piece b"
576
577    gdb_test "print /x global_pieces" " = \{a = 0x12345678, b = 0x87654321\}" \
578	"collect global in pieces: print whole object"
579
580    gdb_test "tfind none" "#0  end .*" \
581	"collect global in pieces: cease trace debugging"
582}
583
584proc gdb_collect_return_test { } {
585    global gdb_prompt
586
587    prepare_for_trace_test
588
589    # We'll simply re-use the args_test_function for this test
590    gdb_test "trace args_test_func" \
591	    "Tracepoint \[0-9\]+ at .*" \
592	    "collect \$_ret: set tracepoint"
593    gdb_trace_setactions "collect \$_ret: define actions" \
594	    "" \
595	    "collect \$_ret" "^$"
596
597    # Begin the test.
598    run_trace_experiment \$_ret args_test_func
599
600    # Since we can't guarantee that $_ret will give us the caller,
601    # pass either way, but giving different messages.
602    gdb_test_multiple "backtrace" "" {
603	-re ".*#1 .* in main .*\r\n$gdb_prompt $" {
604	    pass "collect \$_ret: backtrace lists main"
605	}
606	-re ".*#1 .* in ?? .*\r\n$gdb_prompt $" {
607	    pass "collect \$_ret: backtrace not listing main"
608	}
609    }
610
611    gdb_test "tfind none" \
612	    "#0  end .*" \
613	    "collect \$_ret: cease trace debugging"
614}
615
616proc gdb_collect_strings_test { func mystr myrslt mylim msg } {
617    global hex
618    global cr
619    global gdb_prompt
620
621    prepare_for_trace_test
622
623    # Find the comment-identified line for setting this tracepoint.
624    set testline 0
625    gdb_test_multiple "list $func, +30" "collect $msg: find tracepoint line" {
626	-re "\[\r\n\](\[0-9\]+)\[^\r\n\]+ Set_Tracepoint_Here .*$gdb_prompt" {
627	    set testline $expect_out(1,string)
628	    pass "collect $msg: find tracepoint line"
629	}
630	-re ".*$gdb_prompt " {
631	    fail "collect $msg: find tracepoint line (skipping strings test)"
632	    return
633	}
634	timeout {
635	    fail "collect $msg: find tracepoint line (skipping strings test)"
636	    return
637	}
638    }
639
640    gdb_test "trace $testline" \
641	    "Tracepoint \[0-9\]+ at .*" \
642	    "collect $msg: set tracepoint"
643    gdb_trace_setactions "collect $msg: define actions" \
644	    "" \
645	    "collect/s$mylim $mystr" "^$"
646
647    # Begin the test.
648    run_trace_experiment $msg $func
649
650    gdb_test "print $mystr" \
651	"\\$\[0-9\]+ = $hex \"$myrslt\".*$cr" \
652	    "collect $msg: collected local string"
653
654    gdb_test "tfind none" \
655	    "#0  end .*" \
656	    "collect $msg: cease trace debugging"
657}
658
659proc gdb_trace_collection_test {} {
660    global fpreg
661    global spreg
662    global pcreg
663
664    gdb_collect_args_test "\$args" \
665	    "args collectively"
666    gdb_collect_args_test "argc, argi, argf, argd, argstruct, argarray" \
667	    "args individually"
668    gdb_collect_argstruct_test "\$args" \
669	    "argstruct collectively"
670    gdb_collect_argstruct_test "argstruct" \
671	    "argstruct individually"
672    gdb_collect_argarray_test "\$args" \
673	    "argarray collectively"
674    gdb_collect_argarray_test "argarray" \
675	    "argarray individually"
676    gdb_collect_locals_test local_test_func "\$locals" \
677	    "auto locals collectively"
678    gdb_collect_locals_test local_test_func \
679	    "locc, loci, locf, locd, locst, locar" \
680	    "auto locals individually"
681    gdb_collect_locals_test reglocal_test_func "\$locals" \
682	    "register locals collectively"
683    gdb_collect_locals_test reglocal_test_func \
684	    "locc, loci, locf, locd, locst, locar" \
685	    "register locals individually"
686    gdb_collect_locals_test statlocal_test_func "\$locals" \
687	    "static locals collectively"
688    gdb_collect_locals_test statlocal_test_func \
689	    "locc, loci, locf, locd, locst, locar" \
690	    "static locals individually"
691    gdb_collect_registers_test "\$regs"
692    gdb_collect_registers_test "\$$fpreg, \$$spreg, \$$pcreg"
693    gdb_collect_globals_test
694    gdb_collect_global_in_pieces_test
695
696    #
697    # Expression tests:
698    #
699    # *x	(**x, ...)
700    # x.y	(x.y.z, ...)
701    # x->y	(x->y->z, ...)
702    # x[2]	(x[2][3], ...) (const index)
703    # x[y]	(x[y][z], ...) (index to be char, short, long, float, double)
704    #  NOTE:
705    #  We test the following operators by using them in an array index
706    #  expression -- because the naked result of an operator is not really
707    #  collected.  To be sure the operator was evaluated correctly on the
708    #  target, we have to actually use the result eg. in an array offset
709    #  calculation.
710    # x[y +  z] (tests addition: y and z various combos of types, sclasses)
711    # x[y -  z] (tests subtraction) (ditto)
712    # x[y *  z] (tests multiplication) (ditto)
713    # x[y /  z] (tests division) (ditto)
714    # x[y %  z] (tests modulo division) (ditto)
715    # x[y == z] (tests equality relation) (ditto)              UNSUPPORTED
716    # x[y != z] (tests inequality relation) (ditto)            UNSUPPORTED
717    # x[y >  z] (tests greater-than relation) (ditto)          UNSUPPORTED
718    # x[y <  z] (tests less-than relation) (ditto)             UNSUPPORTED
719    # x[y >= z] (tests greater-than-or-equal relation) (ditto) UNSUPPORTED
720    # x[y <= z] (tests less-than-or-equal relation) (ditto)    UNSUPPORTED
721    # x[y && z] (tests logical and) (ditto)                    UNSUPPORTED
722    # x[y || z] (tests logical or) (ditto)                     UNSUPPORTED
723    # x[y &  z] (tests binary and) (ditto)                     UNSUPPORTED
724    # x[y |  z] (tests binary or) (ditto)                      UNSUPPORTED
725    # x[y ^  z] (tests binary xor) (ditto)                     UNSUPPORTED
726    # x[y ? z1 : z2] (tests ternary operator) (ditto)          UNSUPPORTED
727    # x[y << z] (tests shift-left) (ditto)                     UNSUPPORTED
728    # x[y >> z] (tests shift-right) (ditto)                    UNSUPPORTED
729    # x[y =  z] (tests assignment operator) (ditto)            UNSUPPORTED
730    # x[++y]    (tests pre-increment operator) (ditto)         UNSUPPORTED
731    # x[--y]    (tests pre-decrement operator) (ditto)         UNSUPPORTED
732    # x[y++]    (tests post-increment operator) (ditto)        UNSUPPORTED
733    # x[y--]    (tests post-decrement operator) (ditto)        UNSUPPORTED
734    # x[+y]     (tests unary plus) (ditto)
735    # x[-y]     (tests unary minus) (ditto)
736    # x[!y]     (tests logical not) (ditto)                    UNSUPPORTED
737    # x[~y]     (tests binary not) (ditto)                     UNSUPPORTED
738    # x[(y, z)] (tests comma expression) (ditto)
739    # cast expr
740    # stack data
741
742    gdb_collect_expression_test globals_test_func \
743	    "globalstruct.memberi"  "82"     "a.b"
744    gdb_collect_expression_test globals_test_func \
745	    "globalp->memberc"      "81 'Q'" "a->b"
746    gdb_collect_expression_test globals_test_func \
747	    "globalarr\[2\]"        "2"      "a\[2\]"
748    gdb_collect_expression_test globals_test_func \
749	    "globalarr\[l3\]"       "3"      "a\[b\]"
750    gdb_collect_expression_test globals_test_func \
751	    "globalarr\[l3 + l2\]"  "5"      "a\[b + c\]"
752    gdb_collect_expression_test globals_test_func \
753	    "globalarr\[l3 - l2\]"  "1"      "a\[b - c\]"
754    gdb_collect_expression_test globals_test_func \
755	    "globalarr\[l3 * l2\]"  "6"      "a\[b * c\]"
756    gdb_collect_expression_test globals_test_func \
757	    "globalarr\[l6 / l3\]"  "2"      "a\[b / c\]"
758    gdb_collect_expression_test globals_test_func \
759	    "globalarr\[l7 % l3\]"  "1"      "a\[b % c\]"
760    gdb_collect_expression_test globals_test_func \
761	    "globalarr\[+l1\]"      "1"      "a\[+b\]"
762    gdb_collect_expression_test globals_test_func \
763	    "globalarr\[-lminus\]"  "2"      "a\[-b\]"
764    gdb_collect_expression_test globals_test_func \
765	    "globalarr\[\(l6, l7\)\]" "7"    "a\[\(b, c\)\]"
766
767    gdb_collect_return_test
768
769    gdb_collect_strings_test strings_test_func "locstr" "abcdef" "" \
770	    "local string"
771
772    gdb_collect_strings_test strings_test_func "longloc" "how now brown c" 15 \
773	    "long local string"
774
775}
776
777runto_main
778
779if { ![gdb_target_supports_trace] } then {
780    unsupported "current target does not support trace"
781    return 1
782}
783
784# Body of test encased in a proc so we can return prematurely.
785gdb_trace_collection_test
786
787# Finished!
788gdb_test "tfind none" ".*" ""
789