]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.trace/strace.exp
2012-02-21 Pedro Alves <palves@redhat.com>
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.trace / strace.exp
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.
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 if {[skip_shlib_tests]} {
18 return 0
19 }
20
21 set testfile "strace"
22 set srcfile $testfile.c
23 set binfile $objdir/$subdir/$testfile
24 set executable $testfile
25
26 set libipa $objdir/../gdbserver/libinproctrace.so
27
28 set lib_opts debug
29
30 if [get_compiler_info ${binfile}] {
31 return -1
32 }
33
34 set additional_flags [list debug shlib=$libipa shlib_load "additional_flags=-lust -lurcu-bp" ]
35
36 if { [gdb_compile $srcdir/$subdir/$srcfile $binfile executable $additional_flags] != ""} {
37 untested "UST library or headers are not installed"
38 return -1
39 }
40
41 clean_restart $executable
42
43 if ![runto_main] {
44 fail "Can't run to main to check for trace support"
45 return -1
46 }
47
48 if { ![gdb_target_supports_trace] } then {
49 unsupported "Current target does not support trace"
50 return -1;
51 }
52
53 gdb_load_shlibs $libipa
54
55 proc strace_info_marker { } { with_test_prefix "info_marker" {
56 global executable
57 global gdb_prompt
58
59 # Restart with a fresh gdb.
60 clean_restart $executable
61 if ![runto_main] {
62 fail "Can't run to main"
63 return -1
64 }
65
66 # List the markers in program. They should be disabled.
67 gdb_test "info static-tracepoint-markers" \
68 ".*ust/bar\[\t \]+n\[\t \]+.*ust/bar2\[\t \]+n\[\t \]+.*"
69
70 # List all the thread. It is expected to get three threads without
71 # any errors.
72 gdb_test_multiple "info threads 3 2 1" "info threads" {
73 -re "3\[ \t\]+Thread .*2\[ \t\]+Thread .*1\[ \t\]+Thread .*${gdb_prompt} $" {
74 pass "info threads"
75 }
76 }
77 }}
78
79 proc strace_probe_marker { } { with_test_prefix "probe_marker" {
80 global executable
81 global expect_out
82 global gdb_prompt
83 global hex
84
85 # Restart with a fresh gdb.
86 clean_restart $executable
87 if ![runto_main] {
88 fail "Can't run to main"
89 return -1
90 }
91
92 gdb_test "strace -m ust/bar" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
93 gdb_test "strace -m ust/bar2" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
94 # Two trace markers should be enabled.
95 gdb_test "info static-tracepoint-markers" "ust/bar\[\t \]+y\[\t \]+$hex .*ust/bar2\[\t \]+y\[\t \]+$hex.*"
96
97 gdb_test "break end" "Breakpoint \[0-9\]+ at.*"
98
99 gdb_test_no_output "tstart"
100 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
101 gdb_test_no_output "tstop"
102
103 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
104 gdb_test "tfind" "Found trace frame 1, tracepoint .*" "tfind frame 1"
105 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
106 }}
107
108 proc strace_trace_on_same_addr { type } { with_test_prefix "trace_same_addr $type" {
109 global executable
110 global expect_out
111 global gdb_prompt
112 global hex
113
114 # Restart with a fresh gdb.
115 clean_restart $executable
116 if ![runto_main] {
117 fail "Can't run to main"
118 return -1
119 }
120
121 set marker_bar_addr ""
122 set marker_bar2_addr ""
123
124 # List the markers in program. They should be disabled.
125 gdb_test_multiple "info static-tracepoint-markers" "info static-tracepoint-markers 1" {
126 -re ".*ust/bar\[\t \]+n.*${gdb_prompt} $" {
127 set ignore ""
128
129 regexp "ust/bar\[\t \]+n\[\t \]+($hex) .*ust/bar2\[\t \]+n\[\t \]+($hex) " \
130 "$expect_out(0,string)" ignore marker_bar_addr marker_bar2_addr
131
132 pass "info static-tracepoint-markers 1"
133 }
134 -re ".*${gdb_prompt} $" {
135 fail "info static-tracepoint-markers 1"
136 }
137 }
138
139 gdb_test "strace -m ust/bar" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
140 gdb_test "strace -m ust/bar2" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
141 # Two trace markers should be enabled.
142 gdb_test "info static-tracepoint-markers" \
143 "ust/bar\[\t \]+y\[\t \]+$hex .*ust/bar2\[\t \]+y\[\t \]+$hex.*" \
144 "info static-tracepoint-markers 2"
145
146 # Set breapoints or tracepoints.
147 set test "${type} on marker bar"
148 gdb_test_multiple "${type} *${marker_bar_addr}" $test {
149 -re "\(Fast trace|Trace|Break\)point \[0-9\]+ at ${hex}: file.*\r\n$gdb_prompt $" {
150 pass $test
151 }
152 -re ".*\r\n$gdb_prompt $" {
153 if [string equal $type "ftrace"] {
154 # The instruction may be not long enough to set a fast tracepoint.
155 # Skip the rest of this test.
156 return -1;
157 } else {
158 fail $test
159 }
160 }
161 }
162 set test "${type} on marker bar2"
163 gdb_test_multiple "${type} *${marker_bar2_addr}" $test {
164 -re "\(Fast trace|Trace|Break\)point \[0-9\]+ at ${hex}: file.*" {
165 pass $test
166 }
167 -re ".*\r\n$gdb_prompt $" {
168 if [string equal $type "ftrace"] {
169 # The instruction may be not long enough to set a fast tracepoint.
170 # Skip the rest of this test.
171 return -1;
172 } else {
173 fail $test
174 }
175 }
176 }
177
178 gdb_test "break end" "Breakpoint \[0-9\]+ at.*"
179
180 if [string equal $type "break"] {
181 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to bar"
182 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to bar2"
183 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
184 } else {
185
186 gdb_test_no_output "tstart"
187 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
188 gdb_test_no_output "tstop"
189
190 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
191 gdb_test "tfind" "Found trace frame 1, tracepoint .*" "tfind frame 1"
192 gdb_test "tfind" "Found trace frame 2, tracepoint .*" "tfind frame 2"
193 gdb_test "tfind" "Found trace frame 3, tracepoint .*" "tfind frame 3"
194 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
195 }
196 }}
197
198 proc strace_trace_on_diff_addr { } { with_test_prefix "trace_diff_addr" {
199
200 global executable
201 global expect_out
202 global gdb_prompt
203 global hex
204
205 # Restart with a fresh gdb.
206 clean_restart $executable
207 if ![runto_main] {
208 fail "Can't run to main"
209 return -1
210 }
211
212 set marker_bar_addr ""
213 set marker_bar2_addr ""
214
215 # List the markers in program. They should be disabled.
216 gdb_test_multiple "info static-tracepoint-markers" "info static-tracepoint-markers 1" {
217 -re ".*ust/bar\[\t \]+n.*${gdb_prompt} $" {
218 set ignore ""
219
220 regexp "ust/bar\[\t \]+n\[\t \]+($hex) .*ust/bar2\[\t \]+n\[\t \]+($hex) " \
221 "$expect_out(0,string)" ignore marker_bar_addr marker_bar2_addr
222
223 pass "info static-tracepoint-markers 1"
224 }
225 -re ".*${gdb_prompt} $" {
226 fail "info static-tracepoint-markers 1"
227 }
228 }
229
230 gdb_test "strace -m ust/bar" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
231
232 gdb_test "info static-tracepoint-markers" \
233 "ust/bar\[\t \]+y\[\t \]+$hex .*ust/bar2\[\t \]+n\[\t \]+$hex.*" \
234 "info static-tracepoint-markers 2"
235
236
237 # Set common tracepoint.
238 gdb_test "trace *${marker_bar2_addr}" "Tracepoint \[0-9\]+ at ${hex}: file.*"
239
240 gdb_test "break end" "Breakpoint \[0-9\]+ at.*"
241
242 gdb_test_no_output "tstart"
243 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
244 gdb_test_no_output "tstop"
245
246 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
247 gdb_test "tfind" "Found trace frame 1, tracepoint .*" "tfind frame 1"
248 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
249 }}
250
251 strace_info_marker
252 strace_probe_marker
253
254 strace_trace_on_same_addr "trace"
255 strace_trace_on_same_addr "ftrace"
256 strace_trace_on_same_addr "break"
257 strace_trace_on_diff_addr