]>
Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 1998-2020 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 | # This file was written by Michael Snyder (msnyder@cygnus.com) |
17 | ||
4ec70201 | 18 | load_lib "trace-support.exp" |
c906108c | 19 | |
c906108c SS |
20 | |
21 | gdb_exit | |
22 | gdb_start | |
23 | ||
497a5eb0 | 24 | standard_testfile actions.c |
8bca2978 SL |
25 | if ![gdb_trace_common_supports_arch] { |
26 | unsupported "no trace-common.h support for arch" | |
27 | return -1 | |
28 | } | |
f8b7eaf3 | 29 | if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \ |
ba22ff86 | 30 | executable {debug nowarnings nopie}] != "" } { |
84c93cd5 | 31 | untested "failed to compile" |
f8b7eaf3 | 32 | return -1 |
c906108c | 33 | } |
f8b7eaf3 | 34 | gdb_load $binfile |
de7ff789 MS |
35 | gdb_test "tstop" ".*" "" |
36 | gdb_test "tfind none" ".*" "" | |
f8b7eaf3 | 37 | runto_main |
c906108c SS |
38 | gdb_reinitialize_dir $srcdir/$subdir |
39 | ||
c906108c | 40 | if { ![gdb_target_supports_trace] } then { |
bc6c7af4 | 41 | unsupported "current target does not support trace" |
ae59b1da | 42 | return 1 |
c906108c SS |
43 | |
44 | } | |
45 | ||
46 | set cr "\[\r\n\]+" | |
47 | ||
48 | # If testing on a remote host, download the source file. | |
49 | # remote_download host $srcdir/$subdir/$srcfile | |
50 | ||
51 | # | |
52 | # test general reporting of trace experiment results | |
53 | # | |
54 | ||
55 | set testline1 0 | |
56 | set testline2 0 | |
57 | set testline3 0 | |
58 | set testline4 0 | |
59 | set testline5 0 | |
60 | set testline6 0 | |
61 | ||
62 | set arg1 1 | |
63 | set arg2 2 | |
64 | set arg3 3 | |
65 | set arg4 4 | |
66 | set arg5 5 | |
67 | set arg6 6 | |
68 | ||
4ec70201 | 69 | set gdb_recursion_test_baseline [gdb_find_recursion_test_baseline $srcfile] |
c906108c | 70 | if { $gdb_recursion_test_baseline == -1 } { |
bc6c7af4 | 71 | fail "could not find gdb_recursion_test function" |
4ec70201 | 72 | return |
c906108c SS |
73 | } |
74 | ||
0ab48859 MS |
75 | set return_me 0 |
76 | ||
77 | gdb_test_multiple "list $gdb_recursion_test_baseline, +12" "" { | |
c906108c SS |
78 | -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+gdbtestline 1 " { |
79 | set testline1 $expect_out(1,string) | |
80 | exp_continue | |
81 | } | |
82 | -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+gdbtestline 2 " { | |
83 | set testline2 $expect_out(1,string) | |
84 | exp_continue | |
85 | } | |
86 | -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+gdbtestline 3 " { | |
87 | set testline3 $expect_out(1,string) | |
88 | exp_continue | |
89 | } | |
90 | -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+gdbtestline 4 " { | |
91 | set testline4 $expect_out(1,string) | |
92 | exp_continue | |
93 | } | |
94 | -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+gdbtestline 5 " { | |
95 | set testline5 $expect_out(1,string) | |
96 | exp_continue | |
97 | } | |
98 | -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+gdbtestline 6 " { | |
99 | set testline6 $expect_out(1,string) | |
100 | exp_continue | |
101 | } | |
102 | -re ".*$gdb_prompt $" { | |
103 | if { ($testline1 == 0) || ($testline2 == 0) || ($testline3 == 0) || ($testline4 == 0) || ($testline5 == 0) || ($testline6 == 0) } { | |
84c93cd5 | 104 | untested "unexpected testline values" |
0ab48859 | 105 | set return_me 1 |
c906108c SS |
106 | all tests in this module will fail." |
107 | } | |
108 | } | |
109 | default { | |
84c93cd5 | 110 | untested "couldn't match pattern" |
0ab48859 | 111 | set return_me 1 |
c906108c SS |
112 | all tests in this module will fail." |
113 | } | |
114 | } | |
115 | ||
0ab48859 | 116 | if { $return_me == 1 } then { |
ae59b1da | 117 | return -1 |
0ab48859 MS |
118 | } |
119 | ||
c906108c SS |
120 | # |
121 | # Setup trace experiment. This will involve: | |
122 | # 1) a tracepoint where nothing is collected | |
123 | # 2) a tracepoint where only regs are collected | |
124 | # 3) a tracepoint where only args are collected | |
125 | # 4) a tracepoint where only locals are collected | |
126 | # 5) a tracepoint where some amount of stack memory is collected. | |
127 | # 6) a tracepoint where some expressions are collected. | |
128 | # | |
129 | ||
130 | gdb_delete_tracepoints | |
131 | set tdp1 [gdb_gettpnum $testline1] | |
132 | set tdp2 [gdb_gettpnum $testline2] | |
133 | set tdp3 [gdb_gettpnum $testline3] | |
134 | set tdp4 [gdb_gettpnum $testline4] | |
135 | set tdp5 [gdb_gettpnum $testline5] | |
136 | set tdp6 [gdb_gettpnum $testline6] | |
137 | ||
138 | if { $tdp1 <= 0 || $tdp2 <= 0 || $tdp3 <= 0 || \ | |
139 | $tdp4 <= 0 || $tdp5 <= 0 || $tdp6 <= 0 } then { | |
140 | fail "setting tracepoints failed" | |
4ec70201 | 141 | return |
c906108c SS |
142 | } |
143 | ||
144 | gdb_trace_setactions "9.x: setup TP to collect regs" \ | |
145 | "$tdp2" \ | |
146 | "collect \$regs" "^$" | |
147 | ||
148 | ||
149 | gdb_trace_setactions "9.x: setup TP to collect args" \ | |
150 | "$tdp3" \ | |
151 | "collect \$args" "^$" | |
152 | ||
153 | gdb_trace_setactions "9.x: setup TP to collect locals" \ | |
154 | "$tdp4" \ | |
155 | "collect \$locs" "^$" | |
156 | ||
157 | gdb_trace_setactions "9.x: setup TP to collect stack memory" \ | |
158 | "$tdp5" \ | |
6a8f2671 | 159 | "collect \$$fpreg, \*\(void \*\*\) \$$spreg @ 64" "^$" |
c906108c SS |
160 | |
161 | gdb_trace_setactions "9.x: setup TP to collect expressions" \ | |
162 | "$tdp6" \ | |
163 | "collect gdb_char_test, gdb_short_test, gdb_long_test" "^$" | |
164 | ||
de7ff789 | 165 | gdb_test "tstart" ".*" "" |
c906108c | 166 | |
194ed413 | 167 | gdb_breakpoint "end" qualified |
f8b7eaf3 DJ |
168 | gdb_test "continue" \ |
169 | "Continuing.*Breakpoint $decimal, end.*" \ | |
170 | "run trace experiment" | |
c906108c | 171 | |
de7ff789 | 172 | gdb_test "tstop" ".*" "" |
c906108c | 173 | |
1c942fb9 YQ |
174 | gdb_tfind_test "9.1: init: make sure not debugging any trace frame" \ |
175 | "none" "-1" | |
c906108c | 176 | |
1c942fb9 | 177 | # 9.3 help tdump |
c906108c | 178 | |
1c942fb9 YQ |
179 | gdb_test "help tdump" "Print everything collected at the current.*" \ |
180 | "9.3: help tdump" | |
c906108c | 181 | |
1c942fb9 YQ |
182 | # Check the collected trace data from different sources, such as live |
183 | # inferior and tfile. | |
184 | ||
0a251e08 YQ |
185 | proc use_collected_data { data_source } { |
186 | with_test_prefix "${data_source}" { | |
187 | global tdp1 tdp2 tdp3 tdp4 tdp5 tdp6 | |
188 | global testline1 testline2 testline3 testline4 testline5 testline6 | |
189 | global pcreg fpreg spreg | |
de7b2893 | 190 | global srcfile srcdir subdir binfile |
0a251e08 YQ |
191 | global arg1 arg3 |
192 | global decimal hex gdb_prompt | |
193 | # | |
194 | # 9.1 test the tdump command | |
195 | # | |
196 | ||
197 | set timeout 60 | |
198 | ||
199 | gdb_tfind_test "9.1: find frame for TP $tdp1" "tracepoint $tdp1" \ | |
200 | "\$tracepoint" "$tdp1" | |
201 | ||
202 | # Nothing was collected at tdp1, so this tdump should be empty. | |
203 | gdb_test "tdump" \ | |
204 | "Data collected at tracepoint $tdp1, trace frame $decimal:" \ | |
205 | "9.1: tdump, nothing collected" | |
206 | ||
207 | gdb_tfind_test "9.1: find frame for TP $tdp2" "tracepoint $tdp2" \ | |
208 | "\$tracepoint" "$tdp2" | |
209 | ||
210 | # regs were collected at tdp2. | |
211 | # How to match for the output of "info registers" on an unknown architecture? | |
212 | # For now, assume that most architectures have a register called "pc". | |
213 | ||
214 | gdb_test "tdump" \ | |
215 | "\[\r\n\]$pcreg .*" \ | |
216 | "9.1: tdump, regs collected" | |
217 | ||
218 | gdb_tfind_test "9.1: find frame for TP $tdp3" "tracepoint $tdp3" \ | |
219 | "\$tracepoint" "$tdp3" | |
220 | ||
221 | # args were collected at tdp3 | |
222 | gdb_test "tdump" \ | |
223 | "depth = 3.*q1 = 2.*q2 = 2.*q3 = 3.*q4 = 4.*q5 = 5.*q6 = 6" \ | |
224 | "9.1: tdump, args collected" | |
225 | ||
226 | gdb_tfind_test "9.1: find frame for TP $tdp4" "tracepoint $tdp4" \ | |
227 | "\$tracepoint" "$tdp4" | |
228 | ||
229 | # locals were collected at tdp4 | |
230 | gdb_test "tdump" \ | |
231 | "q = 1" \ | |
232 | "9.1: tdump, locals collected" | |
233 | ||
234 | gdb_tfind_test "9.1: find frame for TP $tdp5" "tracepoint $tdp5" \ | |
235 | "\$tracepoint" "$tdp5" | |
236 | ||
237 | # stack was collected at tdp5, plus the frame pointer | |
238 | gdb_test "tdump" \ | |
239 | ".$fpreg = .*$spreg @ 64 = .*" \ | |
240 | "9.1: tdump, memrange collected" | |
241 | ||
242 | gdb_tfind_test "9.1: find frame for TP $tdp6" "tracepoint $tdp6" \ | |
243 | "\$tracepoint" "$tdp6" | |
244 | ||
245 | # globals were collected at tdp6 | |
246 | gdb_test "tdump" \ | |
247 | "gdb_char_test = 1.*gdb_short_test = 2.*gdb_long_test = 3" \ | |
248 | "9.1: tdump, global variables collected" | |
249 | ||
250 | # 9.2 test tdump with arguments | |
251 | # [no go, tdump doesn't have any arguments] | |
252 | ||
253 | set linecount1 0 | |
254 | set linecount2 0 | |
255 | set linecount3 0 | |
256 | set linecount4 0 | |
257 | set linecount5 0 | |
258 | set linecount6 0 | |
259 | ||
260 | gdb_tfind_test "11.x, 12.1: find start frame" "start" "0" | |
261 | ||
262 | # | |
263 | # 11.x test built-in trace variables $trace_frame, $trace_line etc. | |
264 | # | |
265 | ||
266 | gdb_test "printf \"x %d x\\n\", \$trace_frame" "x 0 x" \ | |
267 | "11.1: test \$trace_frame" | |
268 | ||
269 | gdb_test "printf \"x %d x\\n\", \$tracepoint" "x $tdp1 x" \ | |
270 | "11.2: test \$tracepoint" | |
271 | ||
272 | gdb_test "printf \"x %d x\\n\", \$trace_line" "x $testline1 x" \ | |
273 | "11.3: test \$trace_line" | |
274 | ||
275 | gdb_test_multiple "print \$trace_file" "11.4: test \$trace_file" { | |
276 | -re "\\$\[0-9\]+ = \"$srcfile\"\[\r\n\]+$gdb_prompt $" { | |
277 | pass "11.4: test \$trace_file" | |
278 | } | |
279 | -re "\\$\[0-9\]+ = \"$srcdir/$subdir/$srcfile\"\[\r\n\]+$gdb_prompt $" { | |
280 | pass "11.4: test \$trace_file" | |
281 | } | |
1c942fb9 | 282 | } |
c906108c | 283 | |
0a251e08 YQ |
284 | #gdb_test "print \$trace_file" "\"$srcdir/$subdir/$srcfile\"" \ |
285 | # "11.4: test \$trace_file" | |
c906108c | 286 | |
0a251e08 YQ |
287 | # |
288 | # 12.x test report generation using arbitrary GDB commands, loops etc. | |
289 | # | |
c906108c | 290 | |
0a251e08 YQ |
291 | gdb_test_multiple "while \$trace_frame != -1\n output \$trace_file\n printf \", line \%d \(tracepoint #\%d\)\\n\", \$trace_line, \$tracepoint\n tfind\n end" "12.1: trace report #1" { |
292 | -re "> end\r\n" { | |
293 | exp_continue | |
294 | } | |
295 | -re "^Found trace frame \[0-9\]+, tracepoint \[0-9\]+\r\n" { | |
296 | exp_continue | |
297 | } | |
298 | -re "^\[^\r\n\]* line $testline1 .tracepoint .$tdp1\\)\r\n" { | |
299 | set linecount1 [expr $linecount1 + 1] | |
300 | exp_continue | |
301 | } | |
302 | -re "^\[^\r\n\]* line $testline2 .tracepoint .$tdp2\\)\r\n" { | |
303 | set linecount2 [expr $linecount2 + 1] | |
304 | exp_continue | |
305 | } | |
306 | -re "^\[^\r\n\]* line $testline3 .tracepoint .$tdp3\\)\r\n" { | |
307 | set linecount3 [expr $linecount3 + 1] | |
308 | exp_continue | |
309 | } | |
310 | -re "^\[^\r\n\]* line $testline4 .tracepoint .$tdp4\\)\r\n" { | |
311 | set linecount4 [expr $linecount4 + 1] | |
312 | exp_continue | |
313 | } | |
314 | -re "^\[^\r\n\]* line $testline5 .tracepoint .$tdp5\\)\r\n" { | |
315 | set linecount5 [expr $linecount5 + 1] | |
316 | exp_continue | |
317 | } | |
318 | -re "^\[^\r\n\]* line $testline6 .tracepoint .$tdp6\\)\r\n" { | |
319 | set linecount6 [expr $linecount6 + 1] | |
320 | exp_continue | |
321 | } | |
322 | -re "^No trace frame found\r\n$gdb_prompt $" { | |
323 | if { ($linecount1 < 4) || ($linecount2 < 4) || ($linecount3 < 4) || ($linecount4 < 4) || ($linecount5 < 4) || ($linecount6 < 4) } { | |
324 | fail "12.1: trace report #1" | |
325 | } else { | |
326 | pass "12.1: trace report #1" | |
327 | } | |
1c942fb9 | 328 | } |
c906108c | 329 | } |
c906108c | 330 | |
0a251e08 YQ |
331 | gdb_tfind_test "12.2: tfind end, selects no frame" "end" "-1" |
332 | gdb_tfind_test "12.2: find first TDP #2 frame" "tracepoint $tdp2" \ | |
333 | "\$tracepoint" "$tdp2" | |
c906108c | 334 | |
0a251e08 | 335 | set linecount2 0 |
c906108c | 336 | |
0a251e08 YQ |
337 | gdb_test_multiple "while \$trace_frame != -1\n printf \"tracepoint #\%d, FP 0x\%08x, SP 0x\%08x, PC 0x%08x\\n\", \$tracepoint, \$fp, \$sp, \$pc\n tfind tracepoint\n end" "12.2: trace report #2" { |
338 | -re "tracepoint #$tdp2, FP $hex, SP $hex, PC $hex" { | |
339 | set linecount2 [expr $linecount2 + 1] | |
340 | exp_continue | |
341 | } | |
342 | -re ".*$gdb_prompt $" { | |
343 | if { ($linecount2 < 4) } { | |
344 | fail "12.2: trace report #2" | |
345 | } else { | |
346 | pass "12.2: trace report #2" | |
347 | } | |
1c942fb9 | 348 | } |
c906108c | 349 | } |
c906108c | 350 | |
0a251e08 YQ |
351 | gdb_tfind_test "12.3: tfind end, selects no frame" "end" "-1" |
352 | gdb_tfind_test "12.3: find first TDP #3 frame" "tracepoint $tdp3" \ | |
353 | "\$tracepoint" "$tdp3" | |
c906108c | 354 | |
0a251e08 | 355 | set linecount3 0 |
c906108c | 356 | |
0a251e08 YQ |
357 | gdb_test_multiple "while \$trace_frame != -1\n printf \"TDP #\%d, frame \%d: depth = \%d, q1 = \%d\\n\", \$tracepoint, \$trace_frame, depth, q1\n tfind tracepoint\n end" "12.3: trace report #3" { |
358 | -re "TDP #$tdp3, frame $decimal: depth = $decimal, q1 = $decimal" { | |
359 | set linecount3 [expr $linecount3 + 1] | |
360 | exp_continue | |
361 | } | |
362 | -re ".*$gdb_prompt $" { | |
363 | if { ($linecount3 < 4) } { | |
364 | fail "12.3: trace report #3" | |
365 | } else { | |
366 | pass "12.3: trace report #3" | |
367 | } | |
1c942fb9 | 368 | } |
c906108c | 369 | } |
c906108c | 370 | |
0a251e08 YQ |
371 | gdb_tfind_test "12.4: tfind end, selects no frame" "end" "-1" |
372 | gdb_tfind_test "12.4: find first TDP #6 frame" "tracepoint $tdp6" \ | |
373 | "\$tracepoint" "$tdp6" | |
c906108c | 374 | |
0a251e08 | 375 | set linecount6 0 |
c906108c | 376 | |
0a251e08 YQ |
377 | gdb_test_multiple "while \$trace_frame != -1\n printf \"TDP #\%d, frame %d: char_test = \%d, long_test = \%d\\n\", \$tracepoint, \$trace_frame, gdb_char_test, gdb_long_test\n tfind tracepoint\n end" "12.4: trace report #4" { |
378 | -re "TDP #$tdp6, frame $decimal: char_test = $arg1, long_test = $arg3" { | |
379 | set linecount6 [expr $linecount6 + 1] | |
380 | exp_continue | |
381 | } | |
382 | -re ".*$gdb_prompt $" { | |
383 | if { ($linecount6 < 4) } { | |
384 | fail "12.4: trace report #4" | |
385 | } else { | |
386 | pass "12.4: trace report #4" | |
387 | } | |
1c942fb9 | 388 | } |
c906108c | 389 | } |
de7b2893 YQ |
390 | |
391 | # There is always a thread of an inferior, either a live one or | |
392 | # a faked one. | |
a8f077dc | 393 | gdb_test "info threads" "\\* ${decimal} (process|Thread) \[0-9\.\]+\[ \t\].*" |
de7b2893 | 394 | gdb_test "info inferiors" "\\* 1 process ${decimal} \[ \t\]+${binfile}.*" |
c906108c | 395 | } |
c906108c | 396 | } |
1c942fb9 YQ |
397 | |
398 | use_collected_data "live" | |
c906108c SS |
399 | |
400 | # Finished! | |
1c942fb9 YQ |
401 | gdb_tfind_test "finished: make sure not debugging any trace frame" \ |
402 | "none" "-1" | |
403 | ||
404 | # Save trace frames to tfile. | |
f3786771 YQ |
405 | set tracefile [standard_output_file ${testfile}] |
406 | gdb_test "tsave ${tracefile}.tf" \ | |
407 | "Trace data saved to file '${tracefile}.tf'.*" \ | |
408 | "save tfile trace file" | |
1c942fb9 | 409 | |
393fd4c3 YQ |
410 | # Save trace frames to ctf. |
411 | gdb_test "tsave -ctf ${tracefile}.ctf" \ | |
412 | "Trace data saved to directory '${tracefile}.ctf'.*" \ | |
413 | "save ctf trace file" | |
414 | ||
1c942fb9 YQ |
415 | # Change target to tfile. |
416 | set test "change to tfile target" | |
f3786771 | 417 | gdb_test_multiple "target tfile ${tracefile}.tf" "$test" { |
1c942fb9 YQ |
418 | -re "A program is being debugged already. Kill it. .y or n. " { |
419 | send_gdb "y\n" | |
420 | exp_continue | |
421 | } | |
422 | -re "$gdb_prompt $" { | |
423 | pass "$test" | |
424 | } | |
425 | } | |
426 | # Test the collected trace frames from tfile. | |
427 | use_collected_data "tfile" | |
393fd4c3 YQ |
428 | |
429 | # Try to read ctf data if GDB supports. | |
430 | gdb_test_multiple "target ctf ${tracefile}.ctf" "" { | |
431 | -re "Undefined target command: \"ctf ${tracefile}.ctf\"\. Try \"help target\"\.\r\n$gdb_prompt $" { | |
432 | } | |
433 | -re ".*\r\n$gdb_prompt $" { | |
434 | use_collected_data "ctf" | |
435 | } | |
436 | } |