1 # Copyright 2011-2020 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 if {[skip_shlib_tests]} {
22 set executable $testfile
24 set libipa [get_in_proc_agent]
28 if [get_compiler_info] {
32 set additional_flags [list quiet debug shlib=$libipa shlib_load \
33 "additional_flags=-lust -lurcu-bp" ]
35 if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $additional_flags] != ""} {
36 untested "UST library or headers are not installed"
40 # Test that the socket file is removed when GDB quits, detaches or
41 # resumes the inferior until it exits.
43 proc strace_remove_socket { action } {
44 with_test_prefix "remove_socket_after_${action}" {
50 # Restart with a fresh gdb.
51 clean_restart $executable
52 gdb_load_shlib $libipa
54 fail "can't run to main"
58 # List the markers in program.
59 gdb_test "info static-tracepoint-markers" \
60 ".*ust/bar\[\t \]+n\[\t \]+.*ust/bar2\[\t \]+n\[\t \]+.*"
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)
69 -re ".*${gdb_prompt} $" {
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 \] }"]
78 if { [lindex $status 0] == 0 } {
84 send_gdb "${action}\n"
86 -re "A debugging session is active.\r\n.*\r\nQuit anyway\\? \\(y or n\\) $" {
89 -re "Detaching .*, process .*$" {
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 } {
106 if { ![is_remote target] && ![string equal $action "detach"] } {
107 setup_kfail gdb/14161 *-*-*
110 set test "socket file removed"
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\""
121 if { [string equal $action "quit"] && [is_remote host] } {
123 # unset gdb_spawn_id here to avoid sending command 'quit' to GDB
124 # later in default_gdb_exit.
129 proc strace_info_marker { } {
130 with_test_prefix "info_marker" {
135 # Restart with a fresh gdb.
136 clean_restart $executable
137 gdb_load_shlib $libipa
139 fail "can't run to main"
143 # List the markers in program. They should be disabled.
144 gdb_test "info static-tracepoint-markers" \
145 ".*ust/bar\[\t \]+n\[\t \]+.*ust/bar2\[\t \]+n\[\t \]+.*"
147 # List all the thread. It is expected to get three threads without
149 gdb_test_multiple "info threads 3 2 1" "info threads" {
150 -re "3\[ \t\]+Thread .*2\[ \t\]+Thread .*1\[ \t\]+Thread .*${gdb_prompt} $" {
155 # GDB detaches inferior so that the socket file can be removed.
156 gdb_test_multiple "detach" "detach" {
157 -re "Detaching .*, process .*${gdb_prompt} $" {
164 proc strace_probe_marker { } {
165 with_test_prefix "probe_marker" {
172 # Restart with a fresh gdb.
173 clean_restart $executable
174 gdb_load_shlib $libipa
176 fail "can't run to main"
180 gdb_test "strace -m ust/bar" \
181 "Static tracepoint \[0-9\]+ at ${hex}: file.*"
182 gdb_test "strace -m ust/bar2" \
183 "Static tracepoint \[0-9\]+ at ${hex}: file.*"
184 # Two trace markers should be enabled.
185 gdb_test "info static-tracepoint-markers" \
186 "ust/bar\[\t \]+y\[\t \]+$hex .*ust/bar2\[\t \]+y\[\t \]+$hex.*"
188 gdb_breakpoint "end" qualified
190 gdb_test_no_output "tstart"
191 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
193 gdb_test_no_output "tstop"
195 gdb_test "tfind" "Found trace frame 0, tracepoint .*" \
197 gdb_test "tfind" "Found trace frame 1, tracepoint .*" \
200 "Target failed to find requested trace frame\\..*"
204 proc strace_trace_on_same_addr { type } {
205 with_test_prefix "trace_same_addr $type" {
212 # Restart with a fresh gdb.
213 clean_restart $executable
214 gdb_load_shlib $libipa
216 fail "can't run to main"
220 set marker_bar_addr ""
221 set marker_bar2_addr ""
223 # List the markers in program. They should be disabled.
224 gdb_test_multiple "info static-tracepoint-markers" "info static-tracepoint-markers 1" {
225 -re ".*ust/bar\[\t \]+n.*${gdb_prompt} $" {
228 regexp "ust/bar\[\t \]+n\[\t \]+($hex) .*ust/bar2\[\t \]+n\[\t \]+($hex) " \
229 "$expect_out(0,string)" ignore marker_bar_addr marker_bar2_addr
231 pass "info static-tracepoint-markers 1"
233 -re ".*${gdb_prompt} $" {
234 fail "info static-tracepoint-markers 1"
238 gdb_test "strace -m ust/bar" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
239 gdb_test "strace -m ust/bar2" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
240 # Two trace markers should be enabled.
241 gdb_test "info static-tracepoint-markers" \
242 "ust/bar\[\t \]+y\[\t \]+$hex .*ust/bar2\[\t \]+y\[\t \]+$hex.*" \
243 "info static-tracepoint-markers 2"
245 # Set breapoints or tracepoints.
246 set test "${type} on marker bar"
247 gdb_test_multiple "${type} *${marker_bar_addr}" $test {
248 -re "\(Fast trace|Trace|Break\)point \[0-9\]+ at ${hex}: file.*\r\n$gdb_prompt $" {
251 -re ".*\r\n$gdb_prompt $" {
252 if [string equal $type "ftrace"] {
253 # The instruction may be not long enough to set a fast
254 # tracepoint. Skip the rest of this test.
261 set test "${type} on marker bar2"
262 gdb_test_multiple "${type} *${marker_bar2_addr}" $test {
263 -re "\(Fast trace|Trace|Break\)point \[0-9\]+ at ${hex}: file.*" {
266 -re ".*\r\n$gdb_prompt $" {
267 if [string equal $type "ftrace"] {
268 # The instruction may be not long enough to set a fast
269 # tracepoint. Skip the rest of this test.
277 gdb_breakpoint "end" qualified
279 if [string equal $type "break"] {
280 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
282 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
284 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
288 gdb_test_no_output "tstart"
289 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
291 gdb_test_no_output "tstop"
293 gdb_test "tfind" "Found trace frame 0, tracepoint .*" \
295 gdb_test "tfind" "Found trace frame 1, tracepoint .*" \
297 gdb_test "tfind" "Found trace frame 2, tracepoint .*" \
299 gdb_test "tfind" "Found trace frame 3, tracepoint .*" \
302 "Target failed to find requested trace frame\\..*"
307 proc strace_trace_on_diff_addr { } {
308 with_test_prefix "trace_diff_addr" {
316 # Restart with a fresh gdb.
317 clean_restart $executable
318 gdb_load_shlib $libipa
320 fail "can't run to main"
324 set marker_bar_addr ""
325 set marker_bar2_addr ""
327 # List the markers in program. They should be disabled.
328 gdb_test_multiple "info static-tracepoint-markers" "info static-tracepoint-markers 1" {
329 -re ".*ust/bar\[\t \]+n.*${gdb_prompt} $" {
332 regexp "ust/bar\[\t \]+n\[\t \]+($hex) .*ust/bar2\[\t \]+n\[\t \]+($hex) " \
333 "$expect_out(0,string)" ignore marker_bar_addr marker_bar2_addr
335 pass "info static-tracepoint-markers 1"
337 -re ".*${gdb_prompt} $" {
338 fail "info static-tracepoint-markers 1"
342 gdb_test "strace -m ust/bar" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
344 gdb_test "info static-tracepoint-markers" \
345 "ust/bar\[\t \]+y\[\t \]+$hex .*ust/bar2\[\t \]+n\[\t \]+$hex.*" \
346 "info static-tracepoint-markers 2"
349 # Set common tracepoint.
350 gdb_test "trace *${marker_bar2_addr}" \
351 "Tracepoint \[0-9\]+ at ${hex}: file.*"
353 gdb_breakpoint "end" qualified
355 gdb_test_no_output "tstart"
356 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" \
358 gdb_test_no_output "tstop"
360 gdb_test "tfind" "Found trace frame 0, tracepoint .*" \
362 gdb_test "tfind" "Found trace frame 1, tracepoint .*" \
365 "Target failed to find requested trace frame\\..*"
369 # Run it on x86/x86_64 linux.
370 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"] } {
372 strace_remove_socket "quit"
373 strace_remove_socket "detach"
374 strace_remove_socket "continue"
377 clean_restart $executable
378 gdb_load_shlib $libipa
380 fail "can't run to main to check for trace support"
383 if { ![gdb_target_supports_trace] } then {
384 # At this point, the socket file has been created. We must make sure it is
385 # removed when we return here. GDB detaches inferior so that the socket
386 # file can be removed. Note that GDB simply kill inferior doesn't remove
388 gdb_test "detach" "Detaching .*, process .*"
389 unsupported "current target does not support trace"
393 # Double-check that marker ID ("-m") is not mistaken for an explicit location
395 gdb_test "strace -m gdbfoobarbaz" \
396 "No known static tracepoint marker named gdbfoobarbaz"
400 strace_trace_on_same_addr "trace"
401 strace_trace_on_same_addr "ftrace"
402 strace_trace_on_same_addr "break"
403 strace_trace_on_diff_addr