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