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