]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.trace/mi-tsv-changed.exp
gdb/testsuite/
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.trace / mi-tsv-changed.exp
1 # Copyright 2012-2013 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 load_lib trace-support.exp
17 load_lib mi-support.exp
18
19 standard_testfile actions.c
20 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
21 executable {debug nowarnings}] != "" } {
22 untested mi-tsv-changed.exp
23 return -1
24 }
25
26 # Test notifications on creating, deleting and modifying TSV.
27
28 proc test_create_delete_modify_tsv { } {with_test_prefix "create delete modify" {
29 global binfile
30 global decimal
31 global testfile
32 global srcdir subdir
33 global mi_gdb_prompt
34
35 if [mi_gdb_start] {
36 return
37 }
38 mi_gdb_load ${binfile}
39
40 mi_gdb_test "tvariable \$tvar1" \
41 ".*=tsv-created,name=\"tvar1\",initial=\"0\"\\\\n.*\\^done" \
42 "tvariable \$tvar1"
43 mi_gdb_test "tvariable \$tvar1 = 1" \
44 ".*=tsv-modified,name=\"tvar1\",initial=\"1\".*\\^done" \
45 "tvariable \$tvar1 modified"
46 # No "=tsv-modified" notification is emitted, because the initial
47 # value is not changed.
48 mi_gdb_test "tvariable \$tvar1 = 1" \
49 ".*\\\$tvar1 = 1\\\\n\"\r\n~\"Trace state .*\\\\n.*\\^done" \
50 "tvariable \$tvar1 modified without notification"
51 mi_gdb_test "tvariable \$tvar2 = 45" \
52 ".*=tsv-created,name=\"tvar2\",initial=\"45\"\\\\n.*\\^done" \
53 "tvariable \$tvar2"
54
55 mi_gdb_test "delete tvariable \$tvar2" \
56 ".*=tsv-deleted,name=\"tvar2\"\\\\n.*\\^done" \
57 "delete tvariable \$tvar2"
58
59 mi_gdb_test "delete tvariable" \
60 ".*=tsv-deleted\\\\n.*\\^done" \
61 "delete all tvariables"
62
63 # Test target supports tracepoints or not.
64 clean_restart $testfile
65
66 if ![runto_main] {
67 fail "Can't run to main to check for trace support"
68 return -1
69 }
70
71 if ![gdb_target_supports_trace] {
72 unsupported "Current target does not support trace"
73 return -1
74 }
75 gdb_exit
76 if [mi_gdb_start] {
77 continue
78 }
79
80 mi_gdb_reinitialize_dir $srcdir/$subdir
81 mi_gdb_load ${binfile}
82
83 mi_gdb_test "tvariable \$tvar3 = 3" \
84 ".*=tsv-created,name=\"tvar3\",initial=\"3\".*\\^done" \
85 "tvariable \$tvar3 modified"
86 mi_gdb_test "-break-insert -a gdb_c_test" \
87 {.*\^done,bkpt=.*} \
88 "insert tracepoint on gdb_c_test"
89 # Define an action that increases $tvar3
90 send_gdb "actions\n"
91 gdb_expect {
92 -re "End with" {
93 }
94 }
95 send_gdb "collect \$tvar3 += 3\nend\n"
96 set test "define actions"
97 gdb_expect {
98 -re ".*${mi_gdb_prompt}$" {
99 pass $test
100 }
101 timeout {
102 fail "$test (timeout)"
103 }
104 }
105
106 mi_gdb_test "-break-insert begin" \
107 {.*\^done,bkpt=.*} \
108 "insert tracepoint on begin"
109 mi_gdb_test "-break-insert end" \
110 {.*\^done,bkpt=.*} \
111 "insert tracepoint on end"
112 mi_run_cmd
113
114 mi_expect_stop "breakpoint-hit" "begin" ""\
115 ".*" ".*" {"" "disp=\"keep\""} \
116 "continue to begin breakpoint"
117 mi_gdb_test "-trace-start" {.*\^done} "trace start"
118 mi_send_resuming_command "exec-continue" "continuing to end"
119 mi_gdb_test "-trace-stop" {.*} "trace stop"
120 # Force GDB to get the current value of trace state variable.
121 mi_gdb_test "-trace-list-variables" ".*" "list trace variables"
122 mi_gdb_test "tvariable \$tvar3 = 2" \
123 ".*=tsv-modified,name=\"tvar3\",initial=\"2\",current=\"6\".*\\^done" \
124 "tvariable \$tvar3 modified"
125
126 }}
127
128
129 # Test when GDB connects to a disconnected stub, existing TSVs in
130 # remote stub can be uploaded to GDB, and GDB emits MI notification
131 # for new uploaded TSVs.
132
133 proc test_upload_tsv { } { with_test_prefix "upload" {
134
135 global gdbserver_reconnect_p
136 global gdb_prompt
137 global testfile
138 global decimal
139
140 set gdbserver_reconnect_p 1
141 if { [info proc gdb_reconnect] == "" } {
142 return 0
143 }
144
145 clean_restart $testfile
146 if ![runto_main] then {
147 fail "Can't run to main"
148 return 0
149 }
150
151 gdb_test "tvariable \$tvar1" \
152 "Trace state variable \\\$tvar1 created, with initial value 0." \
153 "Create a trace state variable"
154
155 gdb_test "tvariable \$tvar2 = 45" \
156 "Trace state variable \\\$tvar2 created, with initial value 45." \
157 "Create a trace state variable with initial value"
158 # Define a tracepoint otherwise tracing cannot be started.
159 gdb_test "trace main" "Tracepoint $decimal at .*"
160 gdb_test_no_output "tstart" "start trace experiment"
161
162 set test "disconnect"
163 gdb_test_multiple "disconnect" $test {
164 -re "Trace is running but will stop on detach; detach anyway\\? \\(y or n\\) $" {
165 pass $test
166
167 set test "disconnected"
168 gdb_test_multiple "y" $test {
169 -re "$gdb_prompt $" {
170 pass "$test"
171 }
172 }
173 }
174 }
175
176 gdb_exit
177
178 if [mi_gdb_start] {
179 return
180 }
181
182 global srcdir
183 global subdir
184 global binfile
185
186 mi_gdb_reinitialize_dir $srcdir/$subdir
187 mi_gdb_load ${binfile}
188
189 global gdbserver_protocol
190 global gdbserver_gdbport
191
192 send_gdb "47-target-select $gdbserver_protocol $gdbserver_gdbport\n"
193
194 global mi_gdb_prompt
195 set tsv1_created 0
196 set tsv2_created 0
197 gdb_expect {
198 -re "=tsv-created,name=\"tvar1\",initial=\"0\"" {
199 set tsv1_created 1
200 exp_continue
201 }
202 -re "=tsv-created,name=\"tvar2\",initial=\"45\"" {
203 set tsv2_created 1
204 exp_continue
205 }
206 -re ".*${mi_gdb_prompt}" {
207
208 }
209 }
210
211 if $tsv1_created {
212 pass "tsv1 created"
213 } else {
214 fail "tsv1 created"
215 }
216 if $tsv2_created {
217 pass "tsv2 created"
218 } else {
219 fail "tsv2 created"
220 }
221
222 set gdbserver_reconnect_p 0
223 }}
224
225 test_create_delete_modify_tsv
226
227 # Test target supports tracepoints or not.
228
229 clean_restart $testfile
230
231 if ![runto_main] {
232 fail "Can't run to main to check for trace support"
233 return -1
234 }
235
236 if ![gdb_target_supports_trace] {
237 unsupported "Current target does not support trace"
238 return -1
239 }
240
241 gdb_exit
242
243 test_upload_tsv
244
245 return 0