1 # Copyright 2011-2012 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_shlibs $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 { } { with_test_prefix "info_marker" {
134 # Restart with a fresh gdb.
135 clean_restart $executable
136 gdb_load_shlibs $libipa
138 fail "Can't run to main"
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 \]+.*"
146 # List all the thread. It is expected to get three threads without
148 gdb_test_multiple "info threads 3 2 1" "info threads" {
149 -re "3\[ \t\]+Thread .*2\[ \t\]+Thread .*1\[ \t\]+Thread .*${gdb_prompt} $" {
154 # GDB detaches inferior so that the socket file can be removed.
155 gdb_test_multiple "detach" "detach" {
156 -re "Detaching .*, process .*${gdb_prompt} $" {
162 proc strace_probe_marker { } { with_test_prefix "probe_marker" {
169 # Restart with a fresh gdb.
170 clean_restart $executable
171 gdb_load_shlibs $libipa
173 fail "Can't run to main"
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.*"
183 gdb_test "break end" "Breakpoint \[0-9\]+ at.*"
185 gdb_test_no_output "tstart"
186 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
187 gdb_test_no_output "tstop"
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\\..*"
194 proc strace_trace_on_same_addr { type } {
195 with_test_prefix "trace_same_addr $type" {
202 # Restart with a fresh gdb.
203 clean_restart $executable
204 gdb_load_shlibs $libipa
206 fail "Can't run to main"
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 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 $" {
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_test "break end" "Breakpoint \[0-9\]+ at.*"
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 .*" "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\\..*"
291 proc strace_trace_on_diff_addr { } { with_test_prefix "trace_diff_addr" {
299 # Restart with a fresh gdb.
300 clean_restart $executable
301 gdb_load_shlibs $libipa
303 fail "Can't run to main"
307 set marker_bar_addr ""
308 set marker_bar2_addr ""
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} $" {
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
318 pass "info static-tracepoint-markers 1"
320 -re ".*${gdb_prompt} $" {
321 fail "info static-tracepoint-markers 1"
325 gdb_test "strace -m ust/bar" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
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"
332 # Set common tracepoint.
333 gdb_test "trace *${marker_bar2_addr}" \
334 "Tracepoint \[0-9\]+ at ${hex}: file.*"
336 gdb_test "break end" "Breakpoint \[0-9\]+ at.*"
338 gdb_test_no_output "tstart"
339 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
340 gdb_test_no_output "tstop"
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\\..*"
347 # Run it on x86/x86_64 linux.
348 if { [istarget "x86_64-*-linux*"] || [istarget "i\[34567\]86-*-linux*"] } {
350 strace_remove_socket "quit"
351 strace_remove_socket "detach"
352 strace_remove_socket "continue"
355 clean_restart $executable
356 gdb_load_shlibs $libipa
358 fail "Can't run to main to check for trace support"
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
366 gdb_test "detach" "Detaching .*, process .*"
367 unsupported "Current target does not support trace"
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