1 # Copyright 2012-2013 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
18 if {[skip_shlib_tests]} {
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]
31 set lib_opts [gdb_target_symbol_prefix_flags]
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"
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"
45 load_lib mi-support.exp
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.
52 proc test_reconnect { } { with_test_prefix "reconnect" {
54 global gdbserver_reconnect_p
57 global lib_sl1 lib_sl2
59 set gdbserver_reconnect_p 1
60 if { [info proc gdb_reconnect] == "" } {
64 clean_restart $executable
65 gdb_load_shlibs $lib_sl1
66 gdb_load_shlibs $lib_sl2
67 if ![runto_main] then {
68 fail "Can't run to main"
71 # Create tracepoints on marker and main, and leave them in the
73 gdb_test "trace marker" "Tracepoint.*at.* file .*" \
74 "tracepoint on marker"
75 gdb_test "trace main" "Tracepoint.*at.* file .*" \
77 gdb_test_no_output "tstart" "start trace experiment"
80 gdb_test_multiple "disconnect" $test {
81 -re "Trace is running but will stop on detach; detach anyway\\? \\(y or n\\) $" {
84 set test "disconnected"
85 gdb_test_multiple "y" $test {
103 mi_gdb_reinitialize_dir $srcdir/$subdir
104 mi_gdb_load ${binfile}
106 global gdbserver_protocol
107 global gdbserver_gdbport
109 # Create tracepoints on marker and pendfunc2.
110 mi_gdb_test "-break-insert -a -f pendfunc2" \
111 {.*\^done,bkpt=.*addr=\"<PENDING>\".*} \
112 "insert tracepoint on pendfunc2"
113 mi_gdb_test "-break-insert -a marker" {.*\^done,bkpt=.*\".*} \
114 "insert tracepoint on marker"
116 # Connect to the remote stub again, and make sure GDB merges the
117 # tracepoints of both sides correctly.
118 send_gdb "47-target-select $gdbserver_protocol $gdbserver_gdbport\n"
121 set test "tracepoint created"
123 -re "=breakpoint-created,bkpt=\{number=\"1\",type=\"tracepoint\"" {
124 # Tracepoint 1 in GDB, which has already existed before
125 # connecting, should have been merged with a tracepoint on
126 # the target, so we shouldn't see a =breakpoint-created
127 # notification for it.
131 -re "=breakpoint-created,bkpt=\{number=\"2\",type=\"tracepoint\"" {
136 -re "=breakpoint-created,bkpt=\{number=\"3\",type=\"tracepoint\",disp=\"keep\",enabled=\"y\",\[^\n\]+,func=\"main\"\[^\n\]+,installed=\"y\"" {
137 # A tracepoint on main was defined in the stub, not in GDB,
138 # so we should see a =breakpoint-created notification.
142 # Tracepoint on marker is defined. After the sync, we know that
143 # the tracepoint is in remote stub. Mark it 'installed'.
144 set test "tracepoint on marker is installed"
146 -re "=breakpoint-modified,bkpt=\{number=\"2\".*,func=\"marker\".*installed=\"y\".*${mi_gdb_prompt}$" {
150 # Check that tracepoint 1 is still pending.
151 mi_gdb_test "-break-info 1" \
152 {.*\^done,BreakpointTable=.*addr=\"<PENDING>\".*} \
155 set gdbserver_reconnect_p 0
159 # Test 'breakpoint-modified' notification is emited when pending tracepoints are
162 proc test_pending_resolved { } { with_test_prefix "pending resolved" {
168 global lib_sl1 lib_sl2
176 mi_gdb_reinitialize_dir $srcdir/$subdir
177 mi_gdb_load ${binfile}
178 mi_load_shlibs $lib_sl1 $lib_sl2
180 # Create a pending tracepoint on pendfunc2
181 mi_gdb_test "-break-insert -a -f pendfunc2" \
182 {.*\^done,bkpt=.*addr=\"<PENDING>\".*} \
183 "insert breakpoint on pendfunc2"
184 # Insert breakpoint on marker
185 mi_gdb_test "-break-insert marker" {.*\^done,bkpt=.*} \
186 "insert breakpoint on marker"
189 mi_expect_stop "breakpoint-hit" "marker" ""\
190 ".*" ".*" {"" "disp=\"keep\""} \
191 "continue to marker breakpoint"
192 mi_gdb_test "-trace-start" {\^done} "trace start"
194 mi_send_resuming_command "exec-continue" "continuing execution to marker 1"
196 # It is expected to get two "=breakpoint-modified" notifications.
197 # Pending tracepoint is resolved.
198 set test "tracepoint on pendfunc2 resolved"
200 -re "=breakpoint-modified,bkpt=\{number=\"1\",type=\"tracepoint\".*.*times=\"0\".*installed=\"n\"" {
204 # Resolved tracepoint is installed.
205 set test "tracepoint on pendfunc2 installed"
207 -re "=breakpoint-modified,bkpt=\{number=\"1\",type=\"tracepoint\".*.*times=\"0\".*installed=\"y\"" {
212 mi_expect_stop "breakpoint-hit" "marker" ".*" ".*" ".*" \
213 {"" "disp=\"keep\""} "continue to marker"
216 mi_gdb_test "-trace-stop" {\^done,.*} "trace stop"
217 mi_gdb_test "-trace-find frame-number 0" \
218 "-trace-find frame-number 0\r\n\\^done,found=\"1\",tracepoint=\"${decimal}\",traceframe=\"0\",frame=\{.*" \
219 "-trace-find frame-number 0"
220 mi_gdb_test "-trace-find none" {\^done,found="0"} "back to live inferior"
222 mi_send_resuming_command "exec-continue" "continuing to exit"
223 set test "tracepoint on pendfunc2 becomes pending again"
225 -re ".*=breakpoint-modified,bkpt=\{number=\"1\",type=\"tracepoint\".*addr=\"<PENDING>\",.*times=\"0\"" {
228 -re ".*${mi_gdb_prompt}$" {
232 fail "$test (timeout)"
236 mi_expect_stop "exited-normally" "" "" "" "" "" ""
239 # Test target supports tracepoints or not.
241 clean_restart $executable
243 gdb_load_shlibs $lib_sl1
244 gdb_load_shlibs $lib_sl2
247 fail "Can't run to main to check for trace support"
251 if ![gdb_target_supports_trace] {
252 unsupported "Current target does not support trace"
260 test_pending_resolved