]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.trace/strace.exp
x86: Add -z isa-level-report=[none|all|needed|used]
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.trace / strace.exp
CommitLineData
1d506c26 1# Copyright 2011-2024 Free Software Foundation, Inc.
1576bd00
YQ
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
4ec70201 15load_lib "trace-support.exp"
1576bd00 16
d6195dc9 17require allow_shlib_tests
1576bd00 18
497a5eb0 19standard_testfile
1576bd00
YQ
20set executable $testfile
21
c0d4d1c0 22set libipa [get_in_proc_agent]
1576bd00
YQ
23
24set lib_opts debug
25
8efd7788
YQ
26set additional_flags [list quiet debug shlib=$libipa shlib_load \
27 "additional_flags=-lust -lurcu-bp" ]
1576bd00
YQ
28
29if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $additional_flags] != ""} {
30 untested "UST library or headers are not installed"
31 return -1
32}
33
7255706c
YQ
34# Test that the socket file is removed when GDB quits, detaches or
35# resumes the inferior until it exits.
36
37proc 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
d9019901 46 gdb_load_shlib $libipa
7255706c 47 if ![runto_main] {
7255706c
YQ
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
0a251e08
YQ
122proc strace_info_marker { } {
123 with_test_prefix "info_marker" {
124 global executable
125 global gdb_prompt
126 global libipa
61ced226 127 global tdlabel_re
0a251e08
YQ
128
129 # Restart with a fresh gdb.
130 clean_restart $executable
d9019901 131 gdb_load_shlib $libipa
0a251e08 132 if ![runto_main] {
0a251e08
YQ
133 return -1
134 }
1576bd00 135
0a251e08
YQ
136 # List the markers in program. They should be disabled.
137 gdb_test "info static-tracepoint-markers" \
138 ".*ust/bar\[\t \]+n\[\t \]+.*ust/bar2\[\t \]+n\[\t \]+.*"
1576bd00 139
0a251e08
YQ
140 # List all the thread. It is expected to get three threads without
141 # any errors.
142 gdb_test_multiple "info threads 3 2 1" "info threads" {
467a34bb 143 -re "3\[ \t\]+${tdlabel_re} .*2\[ \t\]+${tdlabel_re} .*1\[ \t\]+${tdlabel_re} .*${gdb_prompt} $" {
0a251e08
YQ
144 pass "info threads"
145 }
9e507076 146 }
7255706c 147
0a251e08
YQ
148 # GDB detaches inferior so that the socket file can be removed.
149 gdb_test_multiple "detach" "detach" {
150 -re "Detaching .*, process .*${gdb_prompt} $" {
151 pass "detach"
152 }
7255706c
YQ
153 }
154 }
0a251e08 155}
1576bd00 156
0a251e08
YQ
157proc strace_probe_marker { } {
158 with_test_prefix "probe_marker" {
159 global executable
160 global expect_out
161 global gdb_prompt
162 global hex
163 global libipa
164
165 # Restart with a fresh gdb.
166 clean_restart $executable
d9019901 167 gdb_load_shlib $libipa
0a251e08 168 if ![runto_main] {
0a251e08
YQ
169 return -1
170 }
1576bd00 171
0a251e08
YQ
172 gdb_test "strace -m ust/bar" \
173 "Static tracepoint \[0-9\]+ at ${hex}: file.*"
174 gdb_test "strace -m ust/bar2" \
175 "Static tracepoint \[0-9\]+ at ${hex}: file.*"
176 # Two trace markers should be enabled.
177 gdb_test "info static-tracepoint-markers" \
178 "ust/bar\[\t \]+y\[\t \]+$hex .*ust/bar2\[\t \]+y\[\t \]+$hex.*"
1576bd00 179
194ed413 180 gdb_breakpoint "end" qualified
1576bd00 181
0a251e08
YQ
182 gdb_test_no_output "tstart"
183 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
184 "continue to end"
185 gdb_test_no_output "tstop"
1576bd00 186
0a251e08
YQ
187 gdb_test "tfind" "Found trace frame 0, tracepoint .*" \
188 "tfind frame 0"
189 gdb_test "tfind" "Found trace frame 1, tracepoint .*" \
190 "tfind frame 1"
191 gdb_test "tfind" \
192 "Target failed to find requested trace frame\\..*"
193 }
194}
1576bd00 195
8efd7788 196proc strace_trace_on_same_addr { type } {
0a251e08
YQ
197 with_test_prefix "trace_same_addr $type" {
198 global executable
199 global expect_out
200 global gdb_prompt
201 global hex
202 global libipa
203
204 # Restart with a fresh gdb.
205 clean_restart $executable
d9019901 206 gdb_load_shlib $libipa
0a251e08 207 if ![runto_main] {
0a251e08
YQ
208 return -1
209 }
3c2d6aff 210
0a251e08
YQ
211 set marker_bar_addr ""
212 set marker_bar2_addr ""
3c2d6aff 213
0a251e08
YQ
214 # List the markers in program. They should be disabled.
215 gdb_test_multiple "info static-tracepoint-markers" "info static-tracepoint-markers 1" {
216 -re ".*ust/bar\[\t \]+n.*${gdb_prompt} $" {
217 set ignore ""
3c2d6aff 218
0a251e08
YQ
219 regexp "ust/bar\[\t \]+n\[\t \]+($hex) .*ust/bar2\[\t \]+n\[\t \]+($hex) " \
220 "$expect_out(0,string)" ignore marker_bar_addr marker_bar2_addr
3c2d6aff 221
0a251e08
YQ
222 pass "info static-tracepoint-markers 1"
223 }
224 -re ".*${gdb_prompt} $" {
225 fail "info static-tracepoint-markers 1"
226 }
3c2d6aff 227 }
3c2d6aff 228
0a251e08
YQ
229 gdb_test "strace -m ust/bar" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
230 gdb_test "strace -m ust/bar2" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
231 # Two trace markers should be enabled.
232 gdb_test "info static-tracepoint-markers" \
233 "ust/bar\[\t \]+y\[\t \]+$hex .*ust/bar2\[\t \]+y\[\t \]+$hex.*" \
234 "info static-tracepoint-markers 2"
235
33bf4c5c 236 # Set breakpoints or tracepoints.
0a251e08
YQ
237 set test "${type} on marker bar"
238 gdb_test_multiple "${type} *${marker_bar_addr}" $test {
239 -re "\(Fast trace|Trace|Break\)point \[0-9\]+ at ${hex}: file.*\r\n$gdb_prompt $" {
240 pass $test
241 }
242 -re ".*\r\n$gdb_prompt $" {
243 if [string equal $type "ftrace"] {
244 # The instruction may be not long enough to set a fast
245 # tracepoint. Skip the rest of this test.
246 return -1
247 } else {
248 fail $test
249 }
3c2d6aff
YQ
250 }
251 }
0a251e08
YQ
252 set test "${type} on marker bar2"
253 gdb_test_multiple "${type} *${marker_bar2_addr}" $test {
254 -re "\(Fast trace|Trace|Break\)point \[0-9\]+ at ${hex}: file.*" {
255 pass $test
256 }
257 -re ".*\r\n$gdb_prompt $" {
258 if [string equal $type "ftrace"] {
259 # The instruction may be not long enough to set a fast
260 # tracepoint. Skip the rest of this test.
261 return -1
262 } else {
263 fail $test
264 }
3c2d6aff
YQ
265 }
266 }
3c2d6aff 267
194ed413 268 gdb_breakpoint "end" qualified
0a251e08
YQ
269
270 if [string equal $type "break"] {
271 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
272 "continue to bar"
273 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
274 "continue to bar2"
275 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
276 "continue to end"
277 } else {
278
279 gdb_test_no_output "tstart"
280 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
281 "continue to end"
282 gdb_test_no_output "tstop"
283
284 gdb_test "tfind" "Found trace frame 0, tracepoint .*" \
285 "tfind frame 0"
286 gdb_test "tfind" "Found trace frame 1, tracepoint .*" \
287 "tfind frame 1"
288 gdb_test "tfind" "Found trace frame 2, tracepoint .*" \
289 "tfind frame 2"
290 gdb_test "tfind" "Found trace frame 3, tracepoint .*" \
291 "tfind frame 3"
292 gdb_test "tfind" \
293 "Target failed to find requested trace frame\\..*"
294 }
3c2d6aff 295 }
0a251e08 296}
3c2d6aff 297
0a251e08
YQ
298proc strace_trace_on_diff_addr { } {
299 with_test_prefix "trace_diff_addr" {
300
301 global executable
302 global expect_out
303 global gdb_prompt
304 global hex
305 global libipa
306
307 # Restart with a fresh gdb.
308 clean_restart $executable
d9019901 309 gdb_load_shlib $libipa
0a251e08 310 if ![runto_main] {
0a251e08
YQ
311 return -1
312 }
3c2d6aff 313
0a251e08
YQ
314 set marker_bar_addr ""
315 set marker_bar2_addr ""
3c2d6aff 316
0a251e08
YQ
317 # List the markers in program. They should be disabled.
318 gdb_test_multiple "info static-tracepoint-markers" "info static-tracepoint-markers 1" {
319 -re ".*ust/bar\[\t \]+n.*${gdb_prompt} $" {
320 set ignore ""
3c2d6aff 321
0a251e08
YQ
322 regexp "ust/bar\[\t \]+n\[\t \]+($hex) .*ust/bar2\[\t \]+n\[\t \]+($hex) " \
323 "$expect_out(0,string)" ignore marker_bar_addr marker_bar2_addr
3c2d6aff 324
0a251e08
YQ
325 pass "info static-tracepoint-markers 1"
326 }
327 -re ".*${gdb_prompt} $" {
328 fail "info static-tracepoint-markers 1"
329 }
3c2d6aff 330 }
3c2d6aff 331
0a251e08 332 gdb_test "strace -m ust/bar" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
3c2d6aff 333
0a251e08
YQ
334 gdb_test "info static-tracepoint-markers" \
335 "ust/bar\[\t \]+y\[\t \]+$hex .*ust/bar2\[\t \]+n\[\t \]+$hex.*" \
336 "info static-tracepoint-markers 2"
3c2d6aff
YQ
337
338
0a251e08
YQ
339 # Set common tracepoint.
340 gdb_test "trace *${marker_bar2_addr}" \
341 "Tracepoint \[0-9\]+ at ${hex}: file.*"
3c2d6aff 342
194ed413 343 gdb_breakpoint "end" qualified
3c2d6aff 344
0a251e08
YQ
345 gdb_test_no_output "tstart"
346 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
347 "continue to end"
348 gdb_test_no_output "tstop"
3c2d6aff 349
0a251e08
YQ
350 gdb_test "tfind" "Found trace frame 0, tracepoint .*" \
351 "tfind frame 0"
352 gdb_test "tfind" "Found trace frame 1, tracepoint .*" \
353 "tfind frame 1"
354 gdb_test "tfind" \
355 "Target failed to find requested trace frame\\..*"
356 }
357}
3c2d6aff 358
7255706c
YQ
359# Run it on x86/x86_64 linux.
360if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"] } {
361 strace_info_marker
362 strace_remove_socket "quit"
363 strace_remove_socket "detach"
364 strace_remove_socket "continue"
365}
5808517f 366
7255706c 367clean_restart $executable
d9019901 368gdb_load_shlib $libipa
5808517f 369if ![runto_main] {
5808517f
YQ
370 return -1
371}
89c6d320 372if {![gdb_target_supports_trace]} {
7255706c
YQ
373 # At this point, the socket file has been created. We must make sure it is
374 # removed when we return here. GDB detaches inferior so that the socket
375 # file can be removed. Note that GDB simply kill inferior doesn't remove
376 # the socket file.
377 gdb_test "detach" "Detaching .*, process .*"
bc6c7af4 378 unsupported "current target does not support trace"
ae59b1da 379 return -1
5808517f
YQ
380}
381
ad89c2aa
KS
382# Double-check that marker ID ("-m") is not mistaken for an explicit location
383# flag.
384gdb_test "strace -m gdbfoobarbaz" \
385 "No known static tracepoint marker named gdbfoobarbaz"
386
1576bd00 387strace_probe_marker
3c2d6aff
YQ
388
389strace_trace_on_same_addr "trace"
390strace_trace_on_same_addr "ftrace"
391strace_trace_on_same_addr "break"
392strace_trace_on_diff_addr