Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.trace / tstatus.exp
blob8b55a7492f7ca920fef5cb35e153ec0af0171b77
1 # Copyright 2011-2023 Free Software Foundation, Inc.
2 # This program is free software; you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation; either version 3 of the License, or
5 # (at your option) any later version.
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 # GNU General Public License for more details.
12 # You should have received a copy of the GNU General Public License
13 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
15 load_lib "trace-support.exp"
17 standard_testfile actions.c
18 set executable $testfile
19 set expfile tstatus.exp
21 if ![gdb_trace_common_supports_arch] {
22     unsupported "no trace-common.h support for arch"
23     return -1
26 if [prepare_for_testing "failed to prepare" $executable $srcfile \
27         [list debug]] {
28     return -1
31 if ![runto_main] {
32     return -1
35 if ![gdb_target_supports_trace] {
36     unsupported "target does not support trace"
37     return -1
40 set tstatus_output ""
42 proc run_trace_experiment {} {
43     global gdb_prompt
44     global decimal
45     global tstatus_output
47 #    gdb_test_no_output "set debug remote 1" ""
49     gdb_test "continue" \
50         ".*Breakpoint \[0-9\]+, begin .*" \
51         "advance to trace begin"
53     gdb_test_no_output "tstart my tracing note" "start trace experiment"
55     gdb_test "continue" \
56         ".*Breakpoint \[0-9\]+, end .*" \
57         "advance through tracing"
59     # Now play with tstatus a bit.
61     # Since support for notes, user, stop reason, etc. is optional, we
62     # need to match both with and without cases.
64     set test "tstatus reports trace note"
65     gdb_test_multiple "tstatus" $test {
66         -re "Trace is running.*Trace will stop if GDB disconnects\.\[\r\n\]+Trace notes: my tracing note\.\[\r\n\]+Not looking at any trace frame\..*\r\n$gdb_prompt $" {
67             pass $test
68         }
69         -re "Trace is running.*Trace will stop if GDB disconnects\.\[\r\n\]+Not looking at any trace frame.*\r\n$gdb_prompt $" {
70             unsupported $test
71         }
72     }
74     gdb_test "set trace-notes different note" "" "change tracing note"
76     set test "tstatus reports different trace note"
77     gdb_test_multiple "tstatus" $test {
78         -re "Trace is running.*Trace will stop if GDB disconnects\.\[\r\n\]+Trace notes: different note\.\[\r\n\]+Not looking at any trace frame\..*\r\n$gdb_prompt $" {
79             pass $test
80         }
81         -re "Trace is running.*Trace will stop if GDB disconnects\.\[\r\n\]+Not looking at any trace frame.*\r\n$gdb_prompt $" {
82             unsupported $test
83         }
84     }
86     gdb_test "set trace-user me me me" "" "change tracing user"
88     set test "tstatus reports trace user"
89     gdb_test_multiple "tstatus" $test {
90         -re "Trace is running.*Trace will stop if GDB disconnects\.\[\r\n\]+Trace user is me me me\.\[\r\n\]+Trace notes: different note\.\[\r\n\]+Not looking at any trace frame\..*\r\n$gdb_prompt $" {
91             pass $test
92         }
93         -re "Trace is running.*Trace will stop if GDB disconnects\.\[\r\n\]+Not looking at any trace frame.*\r\n$gdb_prompt $" {
94             unsupported $test
95         }
96     }
98     gdb_test_no_output "tstop because I can" "trace stopped with note"
100     set test "tstatus reports trace stop reason"
101     gdb_test_multiple "tstatus" $test {
102         -re "(Trace stopped by a tstop command \\(because I can\\)\..*Trace will stop if GDB disconnects\.\[\r\n\]+Trace user is me me me\.\[\r\n\]+Trace notes: different note\.\[\r\n\]+Not looking at any trace frame\.).*\r\n$gdb_prompt $" {
103             set tstatus_output $expect_out(1,string)
104             pass $test
105         }
106         -re "(Trace stopped by a tstop command\.).*\r\n$gdb_prompt $" {
107             set tstatus_output $expect_out(1,string)
108             unsupported $test
109         }
110     }
112     set test "info trace reports tracepoint hit count and traceframe usage"
113     gdb_test_multiple "info trace" $test {
114         -re "actions\.c:\[0-9\]+\[\r\n\]+\[\t ]+tracepoint already hit 1 time\[\r\n\]+\[\t ]+trace buffer usage ${decimal} bytes\.\[\r\n\]+\[\t ]+collect parm.*\r\n$gdb_prompt $" {
115             pass $test
116         }
117         -re "actions\.c:\[0-9\]+\[\r\n\]+\[\t ]+collect parm.*\r\n$gdb_prompt $" {
118             unsupported $test
119         }
120     }
123 proc test_tracepoints {} {
124     global gdb_prompt
126     gdb_breakpoint "begin" qualified
128     gdb_breakpoint "end" qualified
130     gdb_test "trace gdb_c_test" "Tracepoint .*" \
131         "tracepoint at gdb_c_test"
133     gdb_trace_setactions "collect at set_point: define actions" \
134         "" \
135         "collect parm" "^$"
137     run_trace_experiment
141 test_tracepoints
143 set tracefile [standard_output_file ${testfile}]
144 # Save trace frames to tfile.
145 gdb_test "tsave ${tracefile}.tf" \
146     "Trace data saved to file '${tracefile}.tf'.*" \
147     "save tfile trace file"
148 # Save trace frames to CTF.
149 gdb_test "tsave -ctf ${tracefile}.ctf" \
150     "Trace data saved to directory '${tracefile}.ctf'.*" \
151     "save ctf trace file"
153 # Change target to tfile.
154 set test "change to tfile target"
155 gdb_test_multiple "target tfile ${tracefile}.tf" "$test" {
156     -re "A program is being debugged already.  Kill it. .y or n. " {
157         send_gdb "y\n"
158         exp_continue
159     }
160     -re "$gdb_prompt $" {
161         pass "$test"
162     }
165 # Convert "(because I can) to "\(because I can\)"
166 set tstatus_output [string map {\( \\(} $tstatus_output]
167 set tstatus_output [string map {\) \\)} $tstatus_output]
169 # The status should be identical to the status of live inferior.
170 gdb_test "tstatus" "Using a trace file\.\r\n${tstatus_output}.*" \
171     "tstatus on tfile target"
173 # Change target to ctf if GDB supports.
174 gdb_test_multiple "target ctf ${tracefile}.ctf" "" {
175     -re "Undefined target command: \"ctf ${tracefile}.ctf\"\.  Try \"help target\"\.\r\n$gdb_prompt $" {
176     }
177     -re ".*\r\n$gdb_prompt $" {
178         gdb_test "tstatus" "Using a trace file\.\r\n${tstatus_output}.*" \
179             "tstatus on ctf target"
180     }