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