Automatic date update in version.in
[binutils-gdb.git] / gdb / testsuite / gdb.trace / actions.exp
blob9455103c5ab3991b884ba87329dc36112caf2deb
1 #   Copyright 1998-2024 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"
20 standard_testfile
21 require gdb_trace_common_supports_arch
22 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
23           executable {debug nowarnings}] != "" } {
24     untested "failed to compile"
25     return -1
28 clean_restart
29 gdb_file_cmd $binfile
31 # define relative source line numbers:
32 # all subsequent line numbers are relative to this first one (baseline)
34 set baseline  [gdb_find_recursion_test_baseline $srcfile]
35 if {$baseline == -1} {
36     fail "could not find gdb_recursion_test function"
37     return
40 set testline1 [expr $baseline + 7]
43 # test actions command
46 gdb_delete_tracepoints
47 set trcpt1 [gdb_gettpnum gdb_c_test]
48 set trcpt2 [gdb_gettpnum gdb_asm_test]
49 set trcpt3 [gdb_gettpnum $testline1]
50 if {$trcpt1 <= 0 || $trcpt2 <= 0 || $trcpt3 <= 0} {
51     fail "setting tracepoints"
52     return
55 # 5.1 actions of specified tracepoint
57 gdb_test_multiple "info tracepoints" "5.1a: set three tracepoints, no actions" {
58     -re "Actions for tracepoint \[0-9\]+:.*$gdb_prompt $" {
59         fail "5.1a: testsuite failure (tracepoint already has action)!"
60     }
61     -re "No tracepoints.*$gdb_prompt $" {
62         fail "5.1a: set three tracepoints, no actions (No tracepoints!)"
63     }
64     -re "$gdb_prompt $" {
65         pass "5.1a: set three tracepoints, no actions"
66     }
69 gdb_trace_setactions "5.1b: set actions for first tracepoint" \
70         "$trcpt1" \
71         "collect gdb_char_test" "^$"
73 gdb_test "info tracepoints" \
74     [multi_line \
75          "Num     Type\[ \]+Disp Enb Address\[ \]+What\\s*" \
76          "\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_c_test at .*$srcfile:\[0-9\]+" \
77          "\[\t \]+collect gdb_char_test" \
78          "\[\t \]+not installed on target" \
79          "\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_asm_test at .*$srcfile:\[0-9\]+" \
80          "\[\t \]+not installed on target" \
81          "\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_recursion_test at .*$srcfile:\[0-9\]+" \
82          "\[\t \]+not installed on target"] \
83     "5.1c: verify actions set for first tracepoint"
85 gdb_trace_setactions "5.1d: set actions for second tracepoint" \
86         "$trcpt2" \
87         "collect gdb_short_test" "^$"
89 gdb_test "info tracepoints" \
90     [multi_line \
91          "Num     Type\[ \]+Disp Enb Address\[ \]+What\\s*" \
92          "\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_c_test at .*$srcfile:\[0-9\]+" \
93          "\[\t \]+collect gdb_char_test" \
94          "\[\t \]+not installed on target" \
95          "\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_asm_test at .*$srcfile:\[0-9\]+" \
96          "\[\t \]+collect gdb_short_test" \
97          "\[\t \]+not installed on target" \
98          "\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_recursion_test at .*$srcfile:\[0-9\]+" \
99          "\[\t \]+not installed on target"] \
100     "5.1e: verify actions set for second tracepoint"
102 gdb_trace_setactions "5.2a: set actions for last (default) tracepoint" \
103         "" \
104         "collect gdb_long_test" "^$"
106 gdb_test "info tracepoints" \
107     [multi_line \
108          "Num     Type\[ \]+Disp Enb Address\[ \]+What\\s*" \
109          "\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_c_test at .*$srcfile:\[0-9\]+" \
110          "\[\t \]+collect gdb_char_test" \
111          "\[\t \]+not installed on target" \
112          "\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_asm_test at .*$srcfile:\[0-9\]+" \
113          "\[\t \]+collect gdb_short_test" \
114          "\[\t \]+not installed on target" \
115          "\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_recursion_test at .*$srcfile:\[0-9\]+" \
116          "\[\t \]+collect gdb_long_test" \
117          "\[\t \]+not installed on target"] \
118     "5.2b: verify actions set for second tracepoint"
120 # 5.3 replace actions set earlier
122 gdb_trace_setactions "5.3a: reset actions for first tracepoint" \
123         "$trcpt1" \
124         "collect gdb_struct1_test" "^$"
126 gdb_test "info tracepoints" \
127     [multi_line \
128          "Num     Type\[ \]+Disp Enb Address\[ \]+What\\s*" \
129          "\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_c_test at .*$srcfile:\[0-9\]+" \
130          "\[\t \]+collect gdb_struct1_test" \
131          "\[\t \]+not installed on target" \
132          "\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_asm_test at .*$srcfile:\[0-9\]+" \
133          "\[\t \]+collect gdb_short_test" \
134          "\[\t \]+not installed on target" \
135          "\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_recursion_test at .*$srcfile:\[0-9\]+" \
136          "\[\t \]+collect gdb_long_test" \
137          "\[\t \]+not installed on target"] \
138     "5.3b: verify actions set for first tracepoint"
141 # test end command (all by itself)
144 # 5.4 end outside of context
146 gdb_test "end" "This command cannot be used at the top level." \
147                         "5.4: 'end' command out of context"
149 # 5.5 empty actions (just an end with no other actions)
151 gdb_trace_setactions "5.5a: set empty actions for first tracepoint" \
152         "$trcpt1"
154 gdb_test_multiple "info tracepoints" "5.5c: verify NO actions for first tracepoint" {
155     -re "No tracepoints.*$gdb_prompt $" {
156         fail "5.5c: verify NO actions for first tracepoint"
157     }
158     -re "Actions for.* $trcpt1:.*$gdb_prompt $" {
159         fail "5.5c: verify NO actions for first tracepoint"
160     }
161     -re "$gdb_prompt $" {
162         pass "5.5c: verify NO actions for first tracepoint"
163     }
166 # 5.6 actions for invalid tracepoint number
168 gdb_test "actions [expr $trcpt2 + $trcpt3]" \
169     "No tracepoint number [expr $trcpt2 + $trcpt3]." \
170                         "5.6: actions for invalid tracepoint number"
172 # 5.7 invalid action (other than 'collect', 'while-stepping' or 'end')
173 #           "warning: .print gdb_c_test. is not a supported trace.*> $" \
175 gdb_trace_setactions "5.7: invalid action" \
176         "$trcpt1" \
177         "print gdb_c_test" \
178         "`print gdb_c_test' is not a supported tracepoint action"
180 # 5.8 help actions (collect, while-stepping, end)
182 gdb_test "help actions" \
183     "Specify the actions to be taken at a tracepoint.*" \
184                         "5.8a: help actions"
186 gdb_test "help collect" \
187     "Specify one or more data items to be collected at a tracepoint.*" \
188                         "5.8b: help collect"
190 gdb_test "help while-stepping" \
191     "Specify single-stepping behavior at a tracepoint.*" \
192                         "5.8c: help while-stepping"
194 gdb_test "help end" "Ends a list of commands or actions.*" \
195                         "5.8d: help end"
197 # 5.9 default-collect
199 gdb_test_no_output "set default-collect gdb_char_test, gdb_long_test - 100" \
200     "5.9a: set default-collect"
202 gdb_test "show default-collect" \
203     "The list of expressions to collect by default is \"gdb_char_test, gdb_long_test - 100\"..*" \
204     "5.9b: show default-collect"
206 gdb_test_no_output "set default-collect" \
207     "5.9c: set default-collect"
209 # 5.10 teval
211 gdb_test "tvariable \$tsv" \
212   "Trace state variable \\\$tsv created, with initial value 0." \
213   "create a trace state variable"
215 gdb_trace_setactions "5.10a: set teval action for first tracepoint" \
216         "$trcpt1" \
217         "teval gdb_char_test" "^$"
219 gdb_trace_setactions "5.10a: set teval action for second tracepoint" \
220         "$trcpt2" \
221         "teval \$tsv += 1" "^$"
223 gdb_test "info tracepoints" \
224     [multi_line \
225          "Num     Type\[ \]+Disp Enb Address\[ \]+What\\s*" \
226          "\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_c_test at .*$srcfile:\[0-9\]+" \
227          "\[\t \]+teval gdb_char_test" \
228          "\[\t \]+not installed on target" \
229          "\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_asm_test at .*$srcfile:\[0-9\]+" \
230          "\[\t \]+teval \\\$tsv \\\+= 1" \
231          "\[\t \]+not installed on target" \
232          "\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_recursion_test at .*$srcfile:\[0-9\]+" \
233          "\[\t \]+collect gdb_long_test" \
234          "\[\t \]+not installed on target"] \
235     "5.10a: verify teval actions set for two tracepoints"
237 # Load the binary to the target too.
238 gdb_load $binfile
240 # Can't use runto_main here, because that would delete the tracepoints
241 # created above.
242 gdb_breakpoint "main"
243 gdb_run_cmd
244 if {[gdb_test "" "Breakpoint .*" "run to main"] != 0} {
245     return -1
248 if ![gdb_target_supports_trace] {
249     unsupported "target does not support trace"
250     return -1
253 gdb_trace_setactions "set actions for first tracepoint" \
254     "$trcpt1" \
255     "collect \$regs" "^$" \
256     "end" ""
258 # Check the definition of tracepoints.  These tracepoints may have
259 # different number in different runs.
261 proc check_tracepoint { data_source } {
262     with_test_prefix "$data_source" {
263         global gdb_prompt
264         global srcfile
266         set tp_on_gdb_c_test 0
267         set tp_on_gdb_asm_test 0
268         set tp_on_gdb_recursion_test 0
270         # Since the three tracepoints may appear in different orders, so
271         # we can't do 'info tracepoints' to match the output.  Instead, we
272         # show each tracepoint one by one and record the number of each
273         # tracepoint shown up the output.  Check the number finally.
274         for {set i 1} {$i < 4} {incr i 1} {
275             set test "info tracepoints $i"
276             gdb_test_multiple "info tracepoints $i" $test {
277                 -re "\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_c_test at .*$srcfile:\[0-9\]+\\r\\n\[\t \]+collect \\\$regs\\r\\n\[\t \]+installed on target" {
278                     incr tp_on_gdb_c_test
279                     exp_continue
280                 }
281                 -re "\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_asm_test at .*$srcfile:\[0-9\]+\\r\\n\[\t \]+teval \\\$tsv \\+= 1\\r\\n\[\t \]+installed on target" {
282                     incr tp_on_gdb_asm_test
283                     exp_continue
284                 }
285                 -re "\[0-9\]+\[\t \]+tracepoint     keep y.* in gdb_recursion_test at .*$srcfile:\[0-9\]+\\r\\n\[\t \]+collect gdb_long_test\\r\\n\[\t \]+installed on target" {
286                     incr tp_on_gdb_recursion_test
287                     exp_continue
288                 }
289                 -re "${gdb_prompt} $" {
290                 }
291             }
292         }
294         if {$tp_on_gdb_c_test == 1} {
295             pass "tracepoint on gdb_c_test"
296         } else {
297             fail "tracepoint on gdb_c_test"
298         }
299         if {$tp_on_gdb_asm_test == 1} {
300             pass "tracepoint on gdb_asm_test"
301         } else {
302             fail "tracepoint on gdb_asm_test"
303         }
304         if {$tp_on_gdb_recursion_test == 1} {
305             pass "tracepoint on gdb_recursion_test"
306         } else {
307             fail "tracepoint on gdb_recursion_test $tp_on_gdb_recursion_test"
308         }
309     }
312 # Start and stop the tracing, so that we can save tracepoints
313 # definitions to trace file.
314 gdb_test_no_output "tstart" ""
315 check_tracepoint "live"
316 gdb_test_no_output "tstop" ""
317 set tracefile [standard_output_file ${testfile}]
318 gdb_test "tsave ${tracefile}.tf" \
319     "Trace data saved to file '${tracefile}.tf'\." \
320     "tsave ${testfile}.tf"
321 gdb_test "tsave -ctf ${tracefile}.ctf" \
322     "Trace data saved to directory '${tracefile}.ctf'\\." \
323     "save ctf trace file"
325 # Restart GDB and read the trace data in tfile target.
326 clean_restart
327 gdb_file_cmd $binfile
328 gdb_test "target tfile ${tracefile}.tf" ".*" \
329     "change to tfile target"
330 check_tracepoint "tfile"
332 # Try to read ctf data if GDB supports.
333 set gdb_can_read_ctf_data 0
334 gdb_test_multiple "target ctf" "" {
335     -re "Undefined target command: \"ctf\"\.  Try \"help target\"\.\r\n$gdb_prompt $" {
336         set gdb_can_read_ctf_data 0
337     }
338     -re "No CTF directory specified.*\r\n$gdb_prompt $" {
339         set gdb_can_read_ctf_data 1
340     }
343 if { $gdb_can_read_ctf_data } {
344     clean_restart
345     gdb_file_cmd $binfile
346     gdb_test "target ctf ${tracefile}.ctf" ".*" \
347         "change to ctf target"
348     check_tracepoint "ctf"