]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.trace/strace.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.trace / strace.exp
1 # Copyright 2011-2024 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 require allow_shlib_tests
18
19 standard_testfile
20 set executable $testfile
21
22 set libipa [get_in_proc_agent]
23
24 set lib_opts debug
25
26 set additional_flags [list quiet debug shlib=$libipa shlib_load \
27 "additional_flags=-lust -lurcu-bp" ]
28
29 if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $additional_flags] != ""} {
30 untested "UST library or headers are not installed"
31 return -1
32 }
33
34 # Test that the socket file is removed when GDB quits, detaches or
35 # resumes the inferior until it exits.
36
37 proc strace_remove_socket { action } {
38 with_test_prefix "remove_socket_after_${action}" {
39
40 global executable
41 global gdb_prompt
42 global libipa
43
44 # Restart with a fresh gdb.
45 clean_restart $executable
46 gdb_load_shlib $libipa
47 if ![runto_main] {
48 return -1
49 }
50
51 # List the markers in program.
52 gdb_test "info static-tracepoint-markers" \
53 ".*ust/bar\[\t \]+n\[\t \]+.*ust/bar2\[\t \]+n\[\t \]+.*"
54
55 set pid ""
56 set test "collect pid"
57 gdb_test_multiple "info inferiors" $test {
58 -re "process (\[-0-9a-fx\]+) \[^\n\]*\n.*${gdb_prompt} $" {
59 set pid $expect_out(1,string)
60 pass $test
61 }
62 -re ".*${gdb_prompt} $" {
63 fail $test
64 }
65 }
66
67 set test "socket file exists"
68 set socket_file "/tmp/gdb_ust${pid}"
69 set status [remote_exec target "sh -c { \[ -S $socket_file \] }"]
70
71 if { [lindex $status 0] == 0 } {
72 pass $test
73 } else {
74 fail $test
75 }
76
77 send_gdb "${action}\n"
78 gdb_expect {
79 -re "A debugging session is active.\r\n.*\r\nQuit anyway\\? \\(y or n\\) $" {
80 send_gdb "y\n"
81 }
82 -re "Detaching .*, process .*$" {
83 }
84 -re "Continuing.*$" {
85 }
86 }
87
88 set exists 1
89
90 for {set i 1} {$i <= 5} {incr i} {
91 set status [remote_exec target "sh -c { \[ -S $socket_file \] }"]
92 if { [lindex $status 0] != 0 } {
93 set exists 0
94 break
95 }
96 sleep 1
97 }
98
99 if { ![is_remote target] && ![string equal $action "detach"] } {
100 setup_kfail gdb/14161 *-*-*
101 }
102
103 set test "socket file removed"
104
105 if { $exists } {
106 fail $test
107 # Since $socket_file is a socket file instead of a regular file, we
108 # can't use 'remote_file target delete $socket_file' here.
109 remote_exec target "sh -c \"rm -r $socket_file\""
110 } else {
111 pass $test
112 }
113
114 if { [string equal $action "quit"] && [is_remote host] } {
115 global gdb_spawn_id
116 # unset gdb_spawn_id here to avoid sending command 'quit' to GDB
117 # later in default_gdb_exit.
118 unset gdb_spawn_id
119 }
120 }}
121
122 proc strace_info_marker { } {
123 with_test_prefix "info_marker" {
124 global executable
125 global gdb_prompt
126 global libipa
127
128 # Restart with a fresh gdb.
129 clean_restart $executable
130 gdb_load_shlib $libipa
131 if ![runto_main] {
132 return -1
133 }
134
135 # List the markers in program. They should be disabled.
136 gdb_test "info static-tracepoint-markers" \
137 ".*ust/bar\[\t \]+n\[\t \]+.*ust/bar2\[\t \]+n\[\t \]+.*"
138
139 # List all the thread. It is expected to get three threads without
140 # any errors.
141 gdb_test_multiple "info threads 3 2 1" "info threads" {
142 -re "3\[ \t\]+Thread .*2\[ \t\]+Thread .*1\[ \t\]+Thread .*${gdb_prompt} $" {
143 pass "info threads"
144 }
145 }
146
147 # GDB detaches inferior so that the socket file can be removed.
148 gdb_test_multiple "detach" "detach" {
149 -re "Detaching .*, process .*${gdb_prompt} $" {
150 pass "detach"
151 }
152 }
153 }
154 }
155
156 proc strace_probe_marker { } {
157 with_test_prefix "probe_marker" {
158 global executable
159 global expect_out
160 global gdb_prompt
161 global hex
162 global libipa
163
164 # Restart with a fresh gdb.
165 clean_restart $executable
166 gdb_load_shlib $libipa
167 if ![runto_main] {
168 return -1
169 }
170
171 gdb_test "strace -m ust/bar" \
172 "Static tracepoint \[0-9\]+ at ${hex}: file.*"
173 gdb_test "strace -m ust/bar2" \
174 "Static tracepoint \[0-9\]+ at ${hex}: file.*"
175 # Two trace markers should be enabled.
176 gdb_test "info static-tracepoint-markers" \
177 "ust/bar\[\t \]+y\[\t \]+$hex .*ust/bar2\[\t \]+y\[\t \]+$hex.*"
178
179 gdb_breakpoint "end" qualified
180
181 gdb_test_no_output "tstart"
182 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
183 "continue to end"
184 gdb_test_no_output "tstop"
185
186 gdb_test "tfind" "Found trace frame 0, tracepoint .*" \
187 "tfind frame 0"
188 gdb_test "tfind" "Found trace frame 1, tracepoint .*" \
189 "tfind frame 1"
190 gdb_test "tfind" \
191 "Target failed to find requested trace frame\\..*"
192 }
193 }
194
195 proc strace_trace_on_same_addr { type } {
196 with_test_prefix "trace_same_addr $type" {
197 global executable
198 global expect_out
199 global gdb_prompt
200 global hex
201 global libipa
202
203 # Restart with a fresh gdb.
204 clean_restart $executable
205 gdb_load_shlib $libipa
206 if ![runto_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 breakpoints 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_breakpoint "end" qualified
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 .*" \
284 "tfind frame 0"
285 gdb_test "tfind" "Found trace frame 1, tracepoint .*" \
286 "tfind frame 1"
287 gdb_test "tfind" "Found trace frame 2, tracepoint .*" \
288 "tfind frame 2"
289 gdb_test "tfind" "Found trace frame 3, tracepoint .*" \
290 "tfind frame 3"
291 gdb_test "tfind" \
292 "Target failed to find requested trace frame\\..*"
293 }
294 }
295 }
296
297 proc strace_trace_on_diff_addr { } {
298 with_test_prefix "trace_diff_addr" {
299
300 global executable
301 global expect_out
302 global gdb_prompt
303 global hex
304 global libipa
305
306 # Restart with a fresh gdb.
307 clean_restart $executable
308 gdb_load_shlib $libipa
309 if ![runto_main] {
310 return -1
311 }
312
313 set marker_bar_addr ""
314 set marker_bar2_addr ""
315
316 # List the markers in program. They should be disabled.
317 gdb_test_multiple "info static-tracepoint-markers" "info static-tracepoint-markers 1" {
318 -re ".*ust/bar\[\t \]+n.*${gdb_prompt} $" {
319 set ignore ""
320
321 regexp "ust/bar\[\t \]+n\[\t \]+($hex) .*ust/bar2\[\t \]+n\[\t \]+($hex) " \
322 "$expect_out(0,string)" ignore marker_bar_addr marker_bar2_addr
323
324 pass "info static-tracepoint-markers 1"
325 }
326 -re ".*${gdb_prompt} $" {
327 fail "info static-tracepoint-markers 1"
328 }
329 }
330
331 gdb_test "strace -m ust/bar" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
332
333 gdb_test "info static-tracepoint-markers" \
334 "ust/bar\[\t \]+y\[\t \]+$hex .*ust/bar2\[\t \]+n\[\t \]+$hex.*" \
335 "info static-tracepoint-markers 2"
336
337
338 # Set common tracepoint.
339 gdb_test "trace *${marker_bar2_addr}" \
340 "Tracepoint \[0-9\]+ at ${hex}: file.*"
341
342 gdb_breakpoint "end" qualified
343
344 gdb_test_no_output "tstart"
345 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
346 "continue to end"
347 gdb_test_no_output "tstop"
348
349 gdb_test "tfind" "Found trace frame 0, tracepoint .*" \
350 "tfind frame 0"
351 gdb_test "tfind" "Found trace frame 1, tracepoint .*" \
352 "tfind frame 1"
353 gdb_test "tfind" \
354 "Target failed to find requested trace frame\\..*"
355 }
356 }
357
358 # Run it on x86/x86_64 linux.
359 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"] } {
360 strace_info_marker
361 strace_remove_socket "quit"
362 strace_remove_socket "detach"
363 strace_remove_socket "continue"
364 }
365
366 clean_restart $executable
367 gdb_load_shlib $libipa
368 if ![runto_main] {
369 return -1
370 }
371 if {![gdb_target_supports_trace]} {
372 # At this point, the socket file has been created. We must make sure it is
373 # removed when we return here. GDB detaches inferior so that the socket
374 # file can be removed. Note that GDB simply kill inferior doesn't remove
375 # the socket file.
376 gdb_test "detach" "Detaching .*, process .*"
377 unsupported "current target does not support trace"
378 return -1
379 }
380
381 # Double-check that marker ID ("-m") is not mistaken for an explicit location
382 # flag.
383 gdb_test "strace -m gdbfoobarbaz" \
384 "No known static tracepoint marker named gdbfoobarbaz"
385
386 strace_probe_marker
387
388 strace_trace_on_same_addr "trace"
389 strace_trace_on_same_addr "ftrace"
390 strace_trace_on_same_addr "break"
391 strace_trace_on_diff_addr