xref: /netbsd-src/external/gpl3/gdb/dist/gdb/testsuite/gdb.trace/while-stepping.exp (revision 924795e69c8bb3f17afd8fcbb799710cc1719dc4)
1#   Copyright 1998-2023 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
16# This file was written by Michael Snyder (msnyder@cygnus.com)
17
18load_lib "trace-support.exp"
19
20
21gdb_exit
22gdb_start
23
24standard_testfile actions.c
25if ![gdb_trace_common_supports_arch] {
26    unsupported "no trace-common.h support for arch"
27    return -1
28}
29if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" $binfile \
30	  executable {debug nowarnings}] != "" } {
31    untested "failed to compile"
32    return -1
33}
34gdb_reinitialize_dir $srcdir/$subdir
35
36# If testing on a remote host, download the source file.
37# remote_download host $srcdir/$subdir/$srcfile
38
39gdb_file_cmd $binfile
40
41#
42# test while-stepping command
43#
44
45gdb_delete_tracepoints
46set trcpt1 [gdb_gettpnum gdb_c_test]
47if {$trcpt1 <= 0} {
48    fail "could not find gdb_c_test function"
49    return
50}
51
52# 5.12 basic while-stepping command (collect regs)
53
54gdb_test "info tracepoints" \
55    "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
56\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_c_test at .*$srcfile:\[0-9\]+.
57\[\t \]+not installed on target." \
58	"5.12: set a tracepoint, stepcount is zero"
59
60set stepcount 12
61
62gdb_trace_setactions "5.12: set stepcount to $stepcount" \
63	"" \
64	"while-stepping $stepcount" "" \
65	"collect \$regs" "^$" \
66	"end" ""
67
68gdb_test "info tracepoints" \
69    "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
70\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_c_test at .*$srcfile:\[0-9\]+.
71\[\t \]+while-stepping 12.*" \
72	"5.12: info trace shows \"while-stepping\""
73
74# 5.13 step out of context while collecting local variable
75#      [deferred to dynamic test section]
76
77proc while_stepping_bogus_arg { bogus msgstring } {
78    global gdb_prompt
79
80    gdb_trace_setactions "$msgstring" \
81	    "" \
82	    "while-stepping $bogus" ".*while-stepping step count"
83}
84
85# 5.14 while-stepping (no argument)
86
87while_stepping_bogus_arg "" "5.14: while-stepping null stepcount"
88
89# 5.15 while-stepping (zero stepcount)
90
91while_stepping_bogus_arg "0" "5.15: while-stepping rejects zero stepcount"
92
93# 5.16 while-stepping without collecting anything
94gdb_trace_setactions "5.16: step without collecting anything" \
95	"" \
96	"while-stepping $stepcount" "^$" \
97	"end" ""
98
99gdb_test "info tracepoints" \
100    "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
101\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_c_test at .*$srcfile:\[0-9\]+.
102.*while-stepping $stepcount.*
103.*end.*" \
104	"5.16: confirm actions, step without collecting anything"
105
106# Can't use runto_main here, because that would delete the tracepoints
107# created above.
108
109# Load the binary to the target too.
110gdb_load $binfile
111
112gdb_breakpoint "main"
113gdb_run_cmd
114if {[gdb_test "" "Breakpoint .*" "run to main"] != 0} {
115    return -1
116}
117
118if ![gdb_target_supports_trace] {
119    unsupported "target does not support trace"
120    return -1
121}
122
123gdb_trace_setactions "set stepcount to $stepcount" \
124	"" \
125	"while-stepping $stepcount" "" \
126	"collect \$regs " "^$" \
127	"collect \$locals " "^$" \
128	"end" ""
129
130proc check_tracepoint { data_source } {
131    with_test_prefix "$data_source" {
132	global srcfile
133	global stepcount
134
135	gdb_test "info tracepoints" \
136	    "Num     Type\[ \]+Disp Enb Address\[ \]+What.*
137\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_c_test at .*$srcfile:\[0-9\]+.
138\[\t \]+while-stepping $stepcount.*
139\[\t \]+collect \\\$regs.*
140\[\t \]+collect \\\$locals.*
141\[\t \]+end.*"
142    }
143}
144
145gdb_test_no_output "tstart"
146check_tracepoint "live"
147gdb_test_no_output "tstop"
148set tracefile [standard_output_file ${testfile}]
149gdb_test "tsave ${tracefile}.tf" \
150    "Trace data saved to file '${tracefile}.tf'\.\\r" \
151    "save tfile trace file"
152gdb_test "tsave -ctf ${tracefile}.ctf" \
153    "Trace data saved to directory '${tracefile}.ctf'\.\\r" \
154    "save ctf trace file"
155
156# Restart GDB and read the trace data in tfile target.
157gdb_exit
158gdb_start
159gdb_reinitialize_dir $srcdir/$subdir
160gdb_file_cmd $binfile
161gdb_test "target tfile ${tracefile}.tf" ".*" \
162    "change to tfile target"
163check_tracepoint "tfile"
164
165# Try to read ctf data if GDB supports.
166set gdb_can_read_ctf_data 0
167gdb_test_multiple "target ctf" "" {
168    -re "Undefined target command: \"ctf\"\.  Try \"help target\"\.\r\n$gdb_prompt $" {
169	set gdb_can_read_ctf_data 0
170    }
171    -re "No CTF directory specified.*\r\n$gdb_prompt $" {
172	set gdb_can_read_ctf_data 1
173    }
174}
175
176if { $gdb_can_read_ctf_data } {
177    gdb_exit
178    gdb_start
179    gdb_reinitialize_dir $srcdir/$subdir
180    gdb_file_cmd $binfile
181    gdb_test "target ctf ${tracefile}.ctf" ".*" \
182	"change to ctf target"
183    check_tracepoint "ctf"
184}
185