1 # Copyright 2012-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 load_lib trace-support.exp
17 load_lib mi-support.exp
19 standard_testfile actions.c
21 if ![gdb_trace_common_supports_arch] {
22 unsupported "no trace-common.h support for arch"
26 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
27 executable {debug nowarnings}] != "" } {
28 untested "failed to compile"
32 # Test notifications on creating, deleting and modifying TSV.
34 proc test_create_delete_modify_tsv { } {
35 with_test_prefix "create delete modify" {
45 mi_gdb_load ${binfile}
47 mi_gdb_test "tvariable \$tvar1" \
48 ".*=tsv-created,name=\"tvar1\",initial=\"0\"\\\\n.*\\^done" \
50 mi_gdb_test "tvariable \$tvar1 = 1" \
51 ".*=tsv-modified,name=\"tvar1\",initial=\"1\".*\\^done" \
52 "tvariable \$tvar1 modified"
53 # No "=tsv-modified" notification is emitted, because the initial
54 # value is not changed.
55 mi_gdb_test "tvariable \$tvar1 = 1" \
56 ".*\\\$tvar1 = 1\\\\n\"\r\n~\"Trace state .*\\\\n.*\\^done" \
57 "tvariable \$tvar1 modified without notification"
58 mi_gdb_test "tvariable \$tvar2 = 45" \
59 ".*=tsv-created,name=\"tvar2\",initial=\"45\"\\\\n.*\\^done" \
62 mi_gdb_test "delete tvariable \$tvar2" \
63 ".*=tsv-deleted,name=\"tvar2\"\\\\n.*\\^done" \
64 "delete tvariable \$tvar2"
66 mi_gdb_test "delete tvariable" \
67 ".*=tsv-deleted\\\\n.*\\^done" \
68 "delete all tvariables"
70 # Test target supports tracepoints or not.
71 clean_restart $testfile
74 fail "can't run to main to check for trace support"
78 if ![gdb_target_supports_trace] {
79 unsupported "current target does not support trace"
87 mi_gdb_reinitialize_dir $srcdir/$subdir
88 mi_gdb_load ${binfile}
90 mi_gdb_test "tvariable \$tvar3 = 3" \
91 ".*=tsv-created,name=\"tvar3\",initial=\"3\".*\\^done" \
92 "tvariable \$tvar3 modified"
93 mi_gdb_test "-break-insert -a gdb_c_test" \
95 "insert tracepoint on gdb_c_test"
96 # Define an action that increases $tvar3
102 send_gdb "collect \$tvar3 += 3\nend\n"
103 set test "define actions"
105 -re ".*${mi_gdb_prompt}$" {
109 fail "$test (timeout)"
113 mi_gdb_test "-break-insert begin" \
115 "insert tracepoint on begin"
116 mi_gdb_test "-break-insert end" \
118 "insert tracepoint on end"
121 mi_expect_stop "breakpoint-hit" "begin" ""\
122 ".*" ".*" {"" "disp=\"keep\""} \
123 "continue to begin breakpoint"
124 mi_gdb_test "-trace-start" {.*\^done} "trace start"
125 mi_send_resuming_command "exec-continue" "continuing to end"
126 mi_gdb_test "-trace-stop" {.*} "trace stop"
127 # Force GDB to get the current value of trace state variable.
128 mi_gdb_test "-trace-list-variables" ".*" "list trace variables"
129 mi_gdb_test "tvariable \$tvar3 = 2" \
130 ".*=tsv-modified,name=\"tvar3\",initial=\"2\",current=\"6\".*\\^done" \
131 "tvariable \$tvar3 modified"
137 # Test when GDB connects to a disconnected stub, existing TSVs in
138 # remote stub can be uploaded to GDB, and GDB emits MI notification
139 # for new uploaded TSVs.
141 proc test_upload_tsv { } {
142 with_test_prefix "upload" {
144 global gdbserver_reconnect_p
149 set gdbserver_reconnect_p 1
150 if { [info proc gdb_reconnect] == "" } {
154 clean_restart $testfile
155 if ![runto_main] then {
156 fail "can't run to main"
160 gdb_test "tvariable \$tvar1" \
161 "Trace state variable \\\$tvar1 created, with initial value 0." \
162 "create a trace state variable"
164 gdb_test "tvariable \$tvar2 = 45" \
165 "Trace state variable \\\$tvar2 created, with initial value 45." \
166 "Create a trace state variable with initial value"
167 # Define a tracepoint otherwise tracing cannot be started.
168 gdb_test "trace main" "Tracepoint $decimal at .*"
169 gdb_test_no_output "tstart" "start trace experiment"
171 set test "disconnect"
172 gdb_test_multiple "disconnect" $test {
173 -re "Trace is running but will stop on detach; detach anyway\\? \\(y or n\\) $" {
176 set test "disconnected"
177 gdb_test_multiple "y" $test {
178 -re "$gdb_prompt $" {
195 mi_gdb_reinitialize_dir $srcdir/$subdir
196 mi_gdb_load ${binfile}
198 global gdbserver_protocol
199 global gdbserver_gdbport
201 send_gdb "47-target-select $gdbserver_protocol $gdbserver_gdbport\n"
207 -re "=tsv-created,name=\"tvar1\",initial=\"0\"" {
211 -re "=tsv-created,name=\"tvar2\",initial=\"45\"" {
215 -re ".*${mi_gdb_prompt}" {
231 set gdbserver_reconnect_p 0
235 test_create_delete_modify_tsv
237 # Test target supports tracepoints or not.
239 clean_restart $testfile
242 fail "can't run to main to check for trace support"
246 if ![gdb_target_supports_trace] {
247 unsupported "current target does not support trace"