]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.trace/mi-tracepoint-changed.exp
Update year range in copyright notice of all files owned by the GDB project.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.trace / mi-tracepoint-changed.exp
1 # Copyright 2012-2015 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
18 if {[skip_shlib_tests]} {
19 return 0
20 }
21
22 standard_testfile pending.c
23 set libfile1 "pendshr1"
24 set libfile2 "pendshr2"
25 set executable $testfile
26 set libsrc1 $srcdir/$subdir/$libfile1.c
27 set libsrc2 $srcdir/$subdir/$libfile2.c
28 set lib_sl1 [standard_output_file pendshr1.sl]
29 set lib_sl2 [standard_output_file pendshr2.sl]
30
31 set lib_opts [gdb_target_symbol_prefix_flags]
32
33 if { [gdb_compile_shlib $libsrc1 $lib_sl1 $lib_opts] != ""
34 || [gdb_compile_shlib $libsrc2 $lib_sl2 $lib_opts] != ""} {
35 untested "Could not compile either $libsrc1 or $libsrc2"
36 return -1
37 }
38
39 set exec_opts [list debug shlib=$lib_sl1 shlib_load]
40 if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $exec_opts] != "" } {
41 untested "Failed to compile $srcfile"
42 return -1
43 }
44
45 load_lib mi-support.exp
46 set MIFLAGS "-i=mi"
47
48 # Test when GDB connects to a disconnected stub, existing tracepoints in
49 # remote stub can be uploaded to GDB, and GDB emits MI notification if
50 # new tracepoints are created.
51
52 proc test_reconnect { } {
53 with_test_prefix "reconnect" {
54
55 global gdbserver_reconnect_p
56 global gdb_prompt
57 global executable
58 global lib_sl1 lib_sl2
59
60 set gdbserver_reconnect_p 1
61 if { [info proc gdb_reconnect] == "" } {
62 return 0
63 }
64
65 clean_restart $executable
66 gdb_load_shlibs $lib_sl1
67 gdb_load_shlibs $lib_sl2
68 if ![runto_main] then {
69 fail "Can't run to main"
70 return 0
71 }
72 # Create tracepoints on marker and main, and leave them in the
73 # remote stub.
74 gdb_test "trace marker" "Tracepoint.*at.* file .*" \
75 "tracepoint on marker"
76 gdb_test "trace main" "Tracepoint.*at.* file .*" \
77 "tracepoint on main"
78 gdb_test_no_output "tstart" "start trace experiment"
79
80 set test "disconnect"
81 gdb_test_multiple "disconnect" $test {
82 -re "Trace is running but will stop on detach; detach anyway\\? \\(y or n\\) $" {
83 pass $test
84
85 set test "disconnected"
86 gdb_test_multiple "y" $test {
87 -re "$gdb_prompt $" {
88 pass "$test"
89 }
90 }
91 }
92 }
93
94 gdb_exit
95
96 if [mi_gdb_start] {
97 return
98 }
99
100 global srcdir
101 global subdir
102 global binfile
103
104 mi_gdb_reinitialize_dir $srcdir/$subdir
105 mi_gdb_load ${binfile}
106
107 global gdbserver_protocol
108 global gdbserver_gdbport
109
110 # Create tracepoints on marker and pendfunc2.
111 mi_gdb_test "-break-insert -a -f pendfunc2" \
112 {.*\^done,bkpt=.*addr=\"<PENDING>\".*} \
113 "insert tracepoint on pendfunc2"
114 mi_gdb_test "-break-insert -a marker" {.*\^done,bkpt=.*\".*} \
115 "insert tracepoint on marker"
116
117 # Connect to the remote stub again, and make sure GDB merges the
118 # tracepoints of both sides correctly.
119 send_gdb "47-target-select $gdbserver_protocol $gdbserver_gdbport\n"
120
121 global mi_gdb_prompt
122 set test "tracepoint created"
123 gdb_expect {
124 -re "=breakpoint-created,bkpt=\{number=\"1\",type=\"tracepoint\"" {
125 # Tracepoint 1 in GDB, which has already existed before
126 # connecting, should have been merged with a tracepoint on
127 # the target, so we shouldn't see a =breakpoint-created
128 # notification for it.
129 fail "$test: 1"
130 exp_continue
131 }
132 -re "=breakpoint-created,bkpt=\{number=\"2\",type=\"tracepoint\"" {
133 # Similar to above.
134 fail "$test: 2"
135 exp_continue
136 }
137 -re "=breakpoint-created,bkpt=\{number=\"3\",type=\"tracepoint\",disp=\"keep\",enabled=\"y\",\[^\n\]+,func=\"main\"\[^\n\]+,installed=\"y\"" {
138 # A tracepoint on main was defined in the stub, not in GDB,
139 # so we should see a =breakpoint-created notification.
140 pass $test
141 }
142 }
143 # Tracepoint on marker is defined. After the sync, we know that
144 # the tracepoint is in remote stub. Mark it 'installed'.
145 set test "tracepoint on marker is installed"
146 gdb_expect {
147 -re "=breakpoint-modified,bkpt=\{number=\"2\".*,func=\"marker\".*installed=\"y\".*${mi_gdb_prompt}$" {
148 pass "$test"
149 }
150 }
151 # Check that tracepoint 1 is still pending.
152 mi_gdb_test "-break-info 1" \
153 {.*\^done,BreakpointTable=.*addr=\"<PENDING>\".*} \
154 "break-info 1"
155
156 set gdbserver_reconnect_p 0
157 }
158 }
159
160 # Test 'breakpoint-modified' notification is emited when pending tracepoints are
161 # resolved.
162
163 proc test_pending_resolved { } {
164 with_test_prefix "pending resolved" {
165 global decimal hex
166 global executable
167 global srcdir
168 global subdir
169 global binfile
170 global lib_sl1 lib_sl2
171 global mi_gdb_prompt
172
173 gdb_exit
174 if [mi_gdb_start] {
175 continue
176 }
177
178 mi_gdb_reinitialize_dir $srcdir/$subdir
179 mi_gdb_load ${binfile}
180 mi_load_shlibs $lib_sl1 $lib_sl2
181
182 # Create a pending tracepoint on pendfunc2
183 mi_gdb_test "-break-insert -a -f pendfunc2" \
184 {.*\^done,bkpt=.*addr=\"<PENDING>\".*} \
185 "insert breakpoint on pendfunc2"
186 # Insert breakpoint on marker
187 mi_gdb_test "-break-insert marker" {.*\^done,bkpt=.*} \
188 "insert breakpoint on marker"
189
190 mi_run_cmd
191 mi_expect_stop "breakpoint-hit" "marker" ""\
192 ".*" ".*" {"" "disp=\"keep\""} \
193 "continue to marker breakpoint"
194 mi_gdb_test "-trace-start" {\^done} "trace start"
195
196 mi_send_resuming_command "exec-continue" "continuing execution to marker 1"
197
198 # It is expected to get two "=breakpoint-modified" notifications.
199 # Pending tracepoint is resolved.
200 set test "tracepoint on pendfunc2 resolved"
201 gdb_expect {
202 -re "=breakpoint-modified,bkpt=\{number=\"1\",type=\"tracepoint\".*.*times=\"0\".*installed=\"n\"" {
203 pass "$test"
204 }
205 }
206 # Resolved tracepoint is installed.
207 set test "tracepoint on pendfunc2 installed"
208 gdb_expect {
209 -re "=breakpoint-modified,bkpt=\{number=\"1\",type=\"tracepoint\".*.*times=\"0\".*installed=\"y\"" {
210 pass "$test"
211 }
212 }
213
214 mi_expect_stop "breakpoint-hit" "marker" ".*" ".*" ".*" \
215 {"" "disp=\"keep\""} "continue to marker"
216
217
218 mi_gdb_test "-trace-stop" {\^done,.*} "trace stop"
219 mi_gdb_test "-trace-find frame-number 0" \
220 "-trace-find frame-number 0\r\n\\^done,found=\"1\",tracepoint=\"${decimal}\",traceframe=\"0\",frame=\{.*" \
221 "-trace-find frame-number 0"
222 mi_gdb_test "-trace-find none" {\^done,found="0"} "back to live inferior"
223
224 mi_send_resuming_command "exec-continue" "continuing to exit"
225 set test "tracepoint on pendfunc2 becomes pending again"
226 gdb_expect {
227 -re ".*=breakpoint-modified,bkpt=\{number=\"1\",type=\"tracepoint\".*addr=\"<PENDING>\",.*times=\"0\"" {
228 pass "$test"
229 }
230 -re ".*${mi_gdb_prompt}$" {
231 fail $test
232 }
233 timeout {
234 fail "$test (timeout)"
235 }
236 }
237
238 mi_expect_stop "exited-normally" "" "" "" "" "" ""
239 }
240 }
241
242 # Test target supports tracepoints or not.
243
244 clean_restart $executable
245
246 gdb_load_shlibs $lib_sl1
247 gdb_load_shlibs $lib_sl2
248
249 if ![runto_main] {
250 fail "Can't run to main to check for trace support"
251 return -1
252 }
253
254 if ![gdb_target_supports_trace] {
255 unsupported "Current target does not support trace"
256 return -1
257 }
258
259 gdb_exit
260
261 test_reconnect
262
263 test_pending_resolved
264
265 return 0