]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.trace/strace.exp
Update years in copyright notice for the GDB files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.trace / strace.exp
1 # Copyright 2011-2013 Free Software Foundation, Inc.
2 # This program is free software; you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation; either version 3 of the License, or
5 # (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
11 #
12 # You should have received a copy of the GNU General Public License
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14
15 load_lib "trace-support.exp";
16
17 if {[skip_shlib_tests]} {
18 return 0
19 }
20
21 standard_testfile
22 set executable $testfile
23
24 set libipa [get_in_proc_agent]
25
26 set lib_opts debug
27
28 if [get_compiler_info] {
29 return -1
30 }
31
32 set additional_flags [list quiet debug shlib=$libipa shlib_load \
33 "additional_flags=-lust -lurcu-bp" ]
34
35 if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $additional_flags] != ""} {
36 untested "UST library or headers are not installed"
37 return -1
38 }
39
40 # Test that the socket file is removed when GDB quits, detaches or
41 # resumes the inferior until it exits.
42
43 proc strace_remove_socket { action } {
44 with_test_prefix "remove_socket_after_${action}" {
45
46 global executable
47 global gdb_prompt
48 global libipa
49
50 # Restart with a fresh gdb.
51 clean_restart $executable
52 gdb_load_shlibs $libipa
53 if ![runto_main] {
54 fail "Can't run to main"
55 return -1
56 }
57
58 # List the markers in program.
59 gdb_test "info static-tracepoint-markers" \
60 ".*ust/bar\[\t \]+n\[\t \]+.*ust/bar2\[\t \]+n\[\t \]+.*"
61
62 set pid ""
63 set test "collect pid"
64 gdb_test_multiple "info inferiors" $test {
65 -re "process (\[-0-9a-fx\]+) \[^\n\]*\n.*${gdb_prompt} $" {
66 set pid $expect_out(1,string)
67 pass $test
68 }
69 -re ".*${gdb_prompt} $" {
70 fail $test
71 }
72 }
73
74 set test "socket file exists"
75 set socket_file "/tmp/gdb_ust${pid}"
76 set status [remote_exec target "sh -c { \[ -S $socket_file \] }"]
77
78 if { [lindex $status 0] == 0 } {
79 pass $test
80 } else {
81 fail $test
82 }
83
84 send_gdb "${action}\n"
85 gdb_expect {
86 -re "A debugging session is active.\r\n.*\r\nQuit anyway\\? \\(y or n\\) $" {
87 send_gdb "y\n"
88 }
89 -re "Detaching .*, process .*$" {
90 }
91 -re "Continuing.*$" {
92 }
93 }
94
95 set exists 1
96
97 for {set i 1} {$i <= 5} {incr i} {
98 set status [remote_exec target "sh -c { \[ -S $socket_file \] }"]
99 if { [lindex $status 0] != 0 } {
100 set exists 0
101 break
102 }
103 sleep 1
104 }
105
106 if { ![is_remote target] && ![string equal $action "detach"] } {
107 setup_kfail gdb/14161 *-*-*
108 }
109
110 set test "socket file removed"
111
112 if { $exists } {
113 fail $test
114 # Since $socket_file is a socket file instead of a regular file, we
115 # can't use 'remote_file target delete $socket_file' here.
116 remote_exec target "sh -c \"rm -r $socket_file\""
117 } else {
118 pass $test
119 }
120
121 if { [string equal $action "quit"] && [is_remote host] } {
122 global gdb_spawn_id
123 # unset gdb_spawn_id here to avoid sending command 'quit' to GDB
124 # later in default_gdb_exit.
125 unset gdb_spawn_id
126 }
127 }}
128
129 proc strace_info_marker { } { with_test_prefix "info_marker" {
130 global executable
131 global gdb_prompt
132 global libipa
133
134 # Restart with a fresh gdb.
135 clean_restart $executable
136 gdb_load_shlibs $libipa
137 if ![runto_main] {
138 fail "Can't run to main"
139 return -1
140 }
141
142 # List the markers in program. They should be disabled.
143 gdb_test "info static-tracepoint-markers" \
144 ".*ust/bar\[\t \]+n\[\t \]+.*ust/bar2\[\t \]+n\[\t \]+.*"
145
146 # List all the thread. It is expected to get three threads without
147 # any errors.
148 gdb_test_multiple "info threads 3 2 1" "info threads" {
149 -re "3\[ \t\]+Thread .*2\[ \t\]+Thread .*1\[ \t\]+Thread .*${gdb_prompt} $" {
150 pass "info threads"
151 }
152 }
153
154 # GDB detaches inferior so that the socket file can be removed.
155 gdb_test_multiple "detach" "detach" {
156 -re "Detaching .*, process .*${gdb_prompt} $" {
157 pass "detach"
158 }
159 }
160 }}
161
162 proc strace_probe_marker { } { with_test_prefix "probe_marker" {
163 global executable
164 global expect_out
165 global gdb_prompt
166 global hex
167 global libipa
168
169 # Restart with a fresh gdb.
170 clean_restart $executable
171 gdb_load_shlibs $libipa
172 if ![runto_main] {
173 fail "Can't run to main"
174 return -1
175 }
176
177 gdb_test "strace -m ust/bar" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
178 gdb_test "strace -m ust/bar2" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
179 # Two trace markers should be enabled.
180 gdb_test "info static-tracepoint-markers" \
181 "ust/bar\[\t \]+y\[\t \]+$hex .*ust/bar2\[\t \]+y\[\t \]+$hex.*"
182
183 gdb_test "break end" "Breakpoint \[0-9\]+ at.*"
184
185 gdb_test_no_output "tstart"
186 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
187 gdb_test_no_output "tstop"
188
189 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
190 gdb_test "tfind" "Found trace frame 1, tracepoint .*" "tfind frame 1"
191 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
192 }}
193
194 proc strace_trace_on_same_addr { type } {
195 with_test_prefix "trace_same_addr $type" {
196 global executable
197 global expect_out
198 global gdb_prompt
199 global hex
200 global libipa
201
202 # Restart with a fresh gdb.
203 clean_restart $executable
204 gdb_load_shlibs $libipa
205 if ![runto_main] {
206 fail "Can't run to main"
207 return -1
208 }
209
210 set marker_bar_addr ""
211 set marker_bar2_addr ""
212
213 # List the markers in program. They should be disabled.
214 gdb_test_multiple "info static-tracepoint-markers" "info static-tracepoint-markers 1" {
215 -re ".*ust/bar\[\t \]+n.*${gdb_prompt} $" {
216 set ignore ""
217
218 regexp "ust/bar\[\t \]+n\[\t \]+($hex) .*ust/bar2\[\t \]+n\[\t \]+($hex) " \
219 "$expect_out(0,string)" ignore marker_bar_addr marker_bar2_addr
220
221 pass "info static-tracepoint-markers 1"
222 }
223 -re ".*${gdb_prompt} $" {
224 fail "info static-tracepoint-markers 1"
225 }
226 }
227
228 gdb_test "strace -m ust/bar" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
229 gdb_test "strace -m ust/bar2" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
230 # Two trace markers should be enabled.
231 gdb_test "info static-tracepoint-markers" \
232 "ust/bar\[\t \]+y\[\t \]+$hex .*ust/bar2\[\t \]+y\[\t \]+$hex.*" \
233 "info static-tracepoint-markers 2"
234
235 # Set breapoints or tracepoints.
236 set test "${type} on marker bar"
237 gdb_test_multiple "${type} *${marker_bar_addr}" $test {
238 -re "\(Fast trace|Trace|Break\)point \[0-9\]+ at ${hex}: file.*\r\n$gdb_prompt $" {
239 pass $test
240 }
241 -re ".*\r\n$gdb_prompt $" {
242 if [string equal $type "ftrace"] {
243 # The instruction may be not long enough to set a fast
244 # tracepoint. Skip the rest of this test.
245 return -1;
246 } else {
247 fail $test
248 }
249 }
250 }
251 set test "${type} on marker bar2"
252 gdb_test_multiple "${type} *${marker_bar2_addr}" $test {
253 -re "\(Fast trace|Trace|Break\)point \[0-9\]+ at ${hex}: file.*" {
254 pass $test
255 }
256 -re ".*\r\n$gdb_prompt $" {
257 if [string equal $type "ftrace"] {
258 # The instruction may be not long enough to set a fast
259 # tracepoint. Skip the rest of this test.
260 return -1;
261 } else {
262 fail $test
263 }
264 }
265 }
266
267 gdb_test "break end" "Breakpoint \[0-9\]+ at.*"
268
269 if [string equal $type "break"] {
270 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
271 "continue to bar"
272 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
273 "continue to bar2"
274 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
275 "continue to end"
276 } else {
277
278 gdb_test_no_output "tstart"
279 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
280 "continue to end"
281 gdb_test_no_output "tstop"
282
283 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
284 gdb_test "tfind" "Found trace frame 1, tracepoint .*" "tfind frame 1"
285 gdb_test "tfind" "Found trace frame 2, tracepoint .*" "tfind frame 2"
286 gdb_test "tfind" "Found trace frame 3, tracepoint .*" "tfind frame 3"
287 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
288 }
289 }}
290
291 proc strace_trace_on_diff_addr { } { with_test_prefix "trace_diff_addr" {
292
293 global executable
294 global expect_out
295 global gdb_prompt
296 global hex
297 global libipa
298
299 # Restart with a fresh gdb.
300 clean_restart $executable
301 gdb_load_shlibs $libipa
302 if ![runto_main] {
303 fail "Can't run to main"
304 return -1
305 }
306
307 set marker_bar_addr ""
308 set marker_bar2_addr ""
309
310 # List the markers in program. They should be disabled.
311 gdb_test_multiple "info static-tracepoint-markers" "info static-tracepoint-markers 1" {
312 -re ".*ust/bar\[\t \]+n.*${gdb_prompt} $" {
313 set ignore ""
314
315 regexp "ust/bar\[\t \]+n\[\t \]+($hex) .*ust/bar2\[\t \]+n\[\t \]+($hex) " \
316 "$expect_out(0,string)" ignore marker_bar_addr marker_bar2_addr
317
318 pass "info static-tracepoint-markers 1"
319 }
320 -re ".*${gdb_prompt} $" {
321 fail "info static-tracepoint-markers 1"
322 }
323 }
324
325 gdb_test "strace -m ust/bar" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
326
327 gdb_test "info static-tracepoint-markers" \
328 "ust/bar\[\t \]+y\[\t \]+$hex .*ust/bar2\[\t \]+n\[\t \]+$hex.*" \
329 "info static-tracepoint-markers 2"
330
331
332 # Set common tracepoint.
333 gdb_test "trace *${marker_bar2_addr}" \
334 "Tracepoint \[0-9\]+ at ${hex}: file.*"
335
336 gdb_test "break end" "Breakpoint \[0-9\]+ at.*"
337
338 gdb_test_no_output "tstart"
339 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
340 gdb_test_no_output "tstop"
341
342 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
343 gdb_test "tfind" "Found trace frame 1, tracepoint .*" "tfind frame 1"
344 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
345 }}
346
347 # Run it on x86/x86_64 linux.
348 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"] } {
349 strace_info_marker
350 strace_remove_socket "quit"
351 strace_remove_socket "detach"
352 strace_remove_socket "continue"
353 }
354
355 clean_restart $executable
356 gdb_load_shlibs $libipa
357 if ![runto_main] {
358 fail "Can't run to main to check for trace support"
359 return -1
360 }
361 if { ![gdb_target_supports_trace] } then {
362 # At this point, the socket file has been created. We must make sure it is
363 # removed when we return here. GDB detaches inferior so that the socket
364 # file can be removed. Note that GDB simply kill inferior doesn't remove
365 # the socket file.
366 gdb_test "detach" "Detaching .*, process .*"
367 unsupported "Current target does not support trace"
368 return -1;
369 }
370
371 strace_probe_marker
372
373 strace_trace_on_same_addr "trace"
374 strace_trace_on_same_addr "ftrace"
375 strace_trace_on_same_addr "break"
376 strace_trace_on_diff_addr