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.
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.
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/>.
15 load_lib "trace-support.exp"
17 require allow_shlib_tests
20 set executable $testfile
22 set libipa [get_in_proc_agent]
26 set additional_flags [list quiet debug shlib=$libipa shlib_load \
27 "additional_flags=-lust -lurcu-bp" ]
29 if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $additional_flags] != ""} {
30 untested "UST library or headers are not installed"
34 # Test that the socket file is removed when GDB quits, detaches or
35 # resumes the inferior until it exits.
37 proc strace_remove_socket { action } {
38 with_test_prefix "remove_socket_after_${action}" {
44 # Restart with a fresh gdb.
45 clean_restart $executable
46 gdb_load_shlib $libipa
51 # List the markers in program.
52 gdb_test "info static-tracepoint-markers" \
53 ".*ust/bar\[\t \]+n\[\t \]+.*ust/bar2\[\t \]+n\[\t \]+.*"
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)
62 -re ".*${gdb_prompt} $" {
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 \] }"]
71 if { [lindex $status 0] == 0 } {
77 send_gdb "${action}\n"
79 -re "A debugging session is active.\r\n.*\r\nQuit anyway\\? \\(y or n\\) $" {
82 -re "Detaching .*, process .*$" {
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 } {
99 if { ![is_remote target] && ![string equal $action "detach"] } {
100 setup_kfail gdb/14161 *-*-*
103 set test "socket file removed"
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\""
114 if { [string equal $action "quit"] && [is_remote host] } {
116 # unset gdb_spawn_id here to avoid sending command 'quit' to GDB
117 # later in default_gdb_exit.
122 proc strace_info_marker { } {
123 with_test_prefix "info_marker" {
128 # Restart with a fresh gdb.
129 clean_restart $executable
130 gdb_load_shlib $libipa
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 \]+.*"
139 # List all the thread. It is expected to get three threads without
141 gdb_test_multiple "info threads 3 2 1" "info threads" {
142 -re "3\[ \t\]+Thread .*2\[ \t\]+Thread .*1\[ \t\]+Thread .*${gdb_prompt} $" {
147 # GDB detaches inferior so that the socket file can be removed.
148 gdb_test_multiple "detach" "detach" {
149 -re "Detaching .*, process .*${gdb_prompt} $" {
156 proc strace_probe_marker { } {
157 with_test_prefix "probe_marker" {
164 # Restart with a fresh gdb.
165 clean_restart $executable
166 gdb_load_shlib $libipa
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.*"
179 gdb_breakpoint "end" qualified
181 gdb_test_no_output "tstart"
182 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
184 gdb_test_no_output "tstop"
186 gdb_test "tfind" "Found trace frame 0, tracepoint .*" \
188 gdb_test "tfind" "Found trace frame 1, tracepoint .*" \
191 "Target failed to find requested trace frame\\..*"
195 proc strace_trace_on_same_addr { type } {
196 with_test_prefix "trace_same_addr $type" {
203 # Restart with a fresh gdb.
204 clean_restart $executable
205 gdb_load_shlib $libipa
210 set marker_bar_addr ""
211 set marker_bar2_addr ""
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} $" {
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
221 pass "info static-tracepoint-markers 1"
223 -re ".*${gdb_prompt} $" {
224 fail "info static-tracepoint-markers 1"
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"
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 $" {
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.
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.*" {
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.
267 gdb_breakpoint "end" qualified
269 if [string equal $type "break"] {
270 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
272 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
274 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
278 gdb_test_no_output "tstart"
279 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
281 gdb_test_no_output "tstop"
283 gdb_test "tfind" "Found trace frame 0, tracepoint .*" \
285 gdb_test "tfind" "Found trace frame 1, tracepoint .*" \
287 gdb_test "tfind" "Found trace frame 2, tracepoint .*" \
289 gdb_test "tfind" "Found trace frame 3, tracepoint .*" \
292 "Target failed to find requested trace frame\\..*"
297 proc strace_trace_on_diff_addr { } {
298 with_test_prefix "trace_diff_addr" {
306 # Restart with a fresh gdb.
307 clean_restart $executable
308 gdb_load_shlib $libipa
313 set marker_bar_addr ""
314 set marker_bar2_addr ""
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} $" {
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
324 pass "info static-tracepoint-markers 1"
326 -re ".*${gdb_prompt} $" {
327 fail "info static-tracepoint-markers 1"
331 gdb_test "strace -m ust/bar" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
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"
338 # Set common tracepoint.
339 gdb_test "trace *${marker_bar2_addr}" \
340 "Tracepoint \[0-9\]+ at ${hex}: file.*"
342 gdb_breakpoint "end" qualified
344 gdb_test_no_output "tstart"
345 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
347 gdb_test_no_output "tstop"
349 gdb_test "tfind" "Found trace frame 0, tracepoint .*" \
351 gdb_test "tfind" "Found trace frame 1, tracepoint .*" \
354 "Target failed to find requested trace frame\\..*"
358 # Run it on x86/x86_64 linux.
359 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"] } {
361 strace_remove_socket "quit"
362 strace_remove_socket "detach"
363 strace_remove_socket "continue"
366 clean_restart $executable
367 gdb_load_shlib $libipa
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
376 gdb_test "detach" "Detaching .*, process .*"
377 unsupported "current target does not support trace"
381 # Double-check that marker ID ("-m") is not mistaken for an explicit location
383 gdb_test "strace -m gdbfoobarbaz" \
384 "No known static tracepoint marker named gdbfoobarbaz"
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