1 # Copyright 1998-2020 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file was written by Michael Snyder (msnyder@cygnus.com)
18 load_lib "trace-support.exp"
24 standard_testfile actions.c
25 if ![gdb_trace_common_supports_arch] {
26 unsupported "no trace-common.h support for arch"
29 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
30 executable {debug nowarnings nopie}] != "" } {
31 untested "failed to compile"
35 gdb_test "tstop" ".*" ""
36 gdb_test "tfind none" ".*" ""
38 gdb_reinitialize_dir $srcdir/$subdir
40 if { ![gdb_target_supports_trace] } then {
41 unsupported "current target does not support trace"
48 # If testing on a remote host, download the source file.
49 # remote_download host $srcdir/$subdir/$srcfile
52 # test general reporting of trace experiment results
69 set gdb_recursion_test_baseline [gdb_find_recursion_test_baseline $srcfile]
70 if { $gdb_recursion_test_baseline == -1 } {
71 fail "could not find gdb_recursion_test function"
77 gdb_test_multiple "list $gdb_recursion_test_baseline, +12" "" {
78 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+gdbtestline 1 " {
79 set testline1 $expect_out(1,string)
82 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+gdbtestline 2 " {
83 set testline2 $expect_out(1,string)
86 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+gdbtestline 3 " {
87 set testline3 $expect_out(1,string)
90 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+gdbtestline 4 " {
91 set testline4 $expect_out(1,string)
94 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+gdbtestline 5 " {
95 set testline5 $expect_out(1,string)
98 -re "\[\r\n\](\[0-9\]+)\[^\r\n\]+gdbtestline 6 " {
99 set testline6 $expect_out(1,string)
102 -re ".*$gdb_prompt $" {
103 if { ($testline1 == 0) || ($testline2 == 0) || ($testline3 == 0) || ($testline4 == 0) || ($testline5 == 0) || ($testline6 == 0) } {
104 untested "unexpected testline values"
106 all tests in this module will fail."
110 untested "couldn't match pattern"
112 all tests in this module will fail."
116 if { $return_me == 1 } then {
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.
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]
138 if { $tdp1 <= 0 || $tdp2 <= 0 || $tdp3 <= 0 || \
139 $tdp4 <= 0 || $tdp5 <= 0 || $tdp6 <= 0 } then {
140 fail "setting tracepoints failed"
144 gdb_trace_setactions "9.x: setup TP to collect regs" \
146 "collect \$regs" "^$"
149 gdb_trace_setactions "9.x: setup TP to collect args" \
151 "collect \$args" "^$"
153 gdb_trace_setactions "9.x: setup TP to collect locals" \
155 "collect \$locs" "^$"
157 gdb_trace_setactions "9.x: setup TP to collect stack memory" \
159 "collect \$$fpreg, \*\(void \*\*\) \$$spreg @ 64" "^$"
161 gdb_trace_setactions "9.x: setup TP to collect expressions" \
163 "collect gdb_char_test, gdb_short_test, gdb_long_test" "^$"
165 gdb_test "tstart" ".*" ""
167 gdb_breakpoint "end" qualified
168 gdb_test "continue" \
169 "Continuing.*Breakpoint $decimal, end.*" \
170 "run trace experiment"
172 gdb_test "tstop" ".*" ""
174 gdb_tfind_test "9.1: init: make sure not debugging any trace frame" \
179 gdb_test "help tdump" "Print everything collected at the current.*" \
182 # Check the collected trace data from different sources, such as live
183 # inferior and tfile.
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
190 global srcfile srcdir subdir binfile
192 global decimal hex gdb_prompt
194 # 9.1 test the tdump command
199 gdb_tfind_test "9.1: find frame for TP $tdp1" "tracepoint $tdp1" \
200 "\$tracepoint" "$tdp1"
202 # Nothing was collected at tdp1, so this tdump should be empty.
204 "Data collected at tracepoint $tdp1, trace frame $decimal:" \
205 "9.1: tdump, nothing collected"
207 gdb_tfind_test "9.1: find frame for TP $tdp2" "tracepoint $tdp2" \
208 "\$tracepoint" "$tdp2"
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".
215 "\[\r\n\]$pcreg .*" \
216 "9.1: tdump, regs collected"
218 gdb_tfind_test "9.1: find frame for TP $tdp3" "tracepoint $tdp3" \
219 "\$tracepoint" "$tdp3"
221 # args were collected at tdp3
223 "depth = 3.*q1 = 2.*q2 = 2.*q3 = 3.*q4 = 4.*q5 = 5.*q6 = 6" \
224 "9.1: tdump, args collected"
226 gdb_tfind_test "9.1: find frame for TP $tdp4" "tracepoint $tdp4" \
227 "\$tracepoint" "$tdp4"
229 # locals were collected at tdp4
232 "9.1: tdump, locals collected"
234 gdb_tfind_test "9.1: find frame for TP $tdp5" "tracepoint $tdp5" \
235 "\$tracepoint" "$tdp5"
237 # stack was collected at tdp5, plus the frame pointer
239 ".$fpreg = .*$spreg @ 64 = .*" \
240 "9.1: tdump, memrange collected"
242 gdb_tfind_test "9.1: find frame for TP $tdp6" "tracepoint $tdp6" \
243 "\$tracepoint" "$tdp6"
245 # globals were collected at tdp6
247 "gdb_char_test = 1.*gdb_short_test = 2.*gdb_long_test = 3" \
248 "9.1: tdump, global variables collected"
250 # 9.2 test tdump with arguments
251 # [no go, tdump doesn't have any arguments]
260 gdb_tfind_test "11.x, 12.1: find start frame" "start" "0"
263 # 11.x test built-in trace variables $trace_frame, $trace_line etc.
266 gdb_test "printf \"x %d x\\n\", \$trace_frame" "x 0 x" \
267 "11.1: test \$trace_frame"
269 gdb_test "printf \"x %d x\\n\", \$tracepoint" "x $tdp1 x" \
270 "11.2: test \$tracepoint"
272 gdb_test "printf \"x %d x\\n\", \$trace_line" "x $testline1 x" \
273 "11.3: test \$trace_line"
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"
279 -re "\\$\[0-9\]+ = \"$srcdir/$subdir/$srcfile\"\[\r\n\]+$gdb_prompt $" {
280 pass "11.4: test \$trace_file"
284 #gdb_test "print \$trace_file" "\"$srcdir/$subdir/$srcfile\"" \
285 # "11.4: test \$trace_file"
288 # 12.x test report generation using arbitrary GDB commands, loops etc.
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" {
295 -re "^Found trace frame \[0-9\]+, tracepoint \[0-9\]+\r\n" {
298 -re "^\[^\r\n\]* line $testline1 .tracepoint .$tdp1\\)\r\n" {
299 set linecount1 [expr $linecount1 + 1]
302 -re "^\[^\r\n\]* line $testline2 .tracepoint .$tdp2\\)\r\n" {
303 set linecount2 [expr $linecount2 + 1]
306 -re "^\[^\r\n\]* line $testline3 .tracepoint .$tdp3\\)\r\n" {
307 set linecount3 [expr $linecount3 + 1]
310 -re "^\[^\r\n\]* line $testline4 .tracepoint .$tdp4\\)\r\n" {
311 set linecount4 [expr $linecount4 + 1]
314 -re "^\[^\r\n\]* line $testline5 .tracepoint .$tdp5\\)\r\n" {
315 set linecount5 [expr $linecount5 + 1]
318 -re "^\[^\r\n\]* line $testline6 .tracepoint .$tdp6\\)\r\n" {
319 set linecount6 [expr $linecount6 + 1]
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"
326 pass "12.1: trace report #1"
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"
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]
342 -re ".*$gdb_prompt $" {
343 if { ($linecount2 < 4) } {
344 fail "12.2: trace report #2"
346 pass "12.2: trace report #2"
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"
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]
362 -re ".*$gdb_prompt $" {
363 if { ($linecount3 < 4) } {
364 fail "12.3: trace report #3"
366 pass "12.3: trace report #3"
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"
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]
382 -re ".*$gdb_prompt $" {
383 if { ($linecount6 < 4) } {
384 fail "12.4: trace report #4"
386 pass "12.4: trace report #4"
391 # There is always a thread of an inferior, either a live one or
393 gdb_test "info threads" "\\* ${decimal} (process|Thread) \[0-9\.\]+\[ \t\].*"
394 gdb_test "info inferiors" "\\* 1 process ${decimal} \[ \t\]+\[^\r\n\]*\[ \t\]+${binfile}.*"
398 use_collected_data "live"
401 gdb_tfind_test "finished: make sure not debugging any trace frame" \
404 # Save trace frames to tfile.
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"
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"
415 # Change target to tfile.
416 set test "change to tfile target"
417 gdb_test_multiple "target tfile ${tracefile}.tf" "$test" {
418 -re "A program is being debugged already. Kill it. .y or n. " {
422 -re "$gdb_prompt $" {
426 # Test the collected trace frames from tfile.
427 use_collected_data "tfile"
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 $" {
433 -re ".*\r\n$gdb_prompt $" {
434 use_collected_data "ctf"