4d6ea1013765b4abeca2154c02959656c784e316
[deliverable/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 { } {
56 global executable
57 global pf_prefix
58
59 set old_pf_prefix $pf_prefix
60 lappend pf_prefix "info_marker"
61
62 # Restart with a fresh gdb.
63 clean_restart $executable
64 if ![runto_main] {
65 fail "Can't run to main"
66 set pf_prefix $old_pf_prefix
67 return -1
68 }
69
70 # List the markers in program. They should be disabled.
71 gdb_test "info static-tracepoint-markers" \
72 ".*ust/bar\[\t \]+n\[\t \]+.*ust/bar2\[\t \]+n\[\t \]+.*"
73
74 set pf_prefix $old_pf_prefix
75 }
76
77 proc strace_probe_marker { } {
78 global executable
79 global pf_prefix
80 global expect_out
81 global gdb_prompt
82 global hex
83
84 set old_pf_prefix $pf_prefix
85 lappend pf_prefix "probe_marker"
86
87 # Restart with a fresh gdb.
88 clean_restart $executable
89 if ![runto_main] {
90 fail "Can't run to main"
91 set pf_prefix $old_pf_prefix
92 return -1
93 }
94
95 gdb_test "strace -m ust/bar" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
96 gdb_test "strace -m ust/bar2" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
97 # Two trace markers should be enabled.
98 gdb_test "info static-tracepoint-markers" "ust/bar\[\t \]+y\[\t \]+$hex .*ust/bar2\[\t \]+y\[\t \]+$hex.*"
99
100 gdb_test "break end" "Breakpoint \[0-9\]+ at.*"
101
102 gdb_test_no_output "tstart"
103 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
104 gdb_test_no_output "tstop"
105
106 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
107 gdb_test "tfind" "Found trace frame 1, tracepoint .*" "tfind frame 1"
108 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
109
110 set pf_prefix $old_pf_prefix
111 }
112
113 proc strace_trace_on_same_addr { type } {
114 global executable
115 global pf_prefix
116 global expect_out
117 global gdb_prompt
118 global hex
119
120 set old_pf_prefix $pf_prefix
121 lappend pf_prefix "trace_same_addr" "$type"
122
123 # Restart with a fresh gdb.
124 clean_restart $executable
125 if ![runto_main] {
126 fail "Can't run to main"
127 set pf_prefix $old_pf_prefix
128 return -1
129 }
130
131 set marker_bar_addr ""
132 set marker_bar2_addr ""
133
134 # List the markers in program. They should be disabled.
135 gdb_test_multiple "info static-tracepoint-markers" "info static-tracepoint-markers 1" {
136 -re ".*ust/bar\[\t \]+n.*${gdb_prompt} $" {
137 set ignore ""
138
139 regexp "ust/bar\[\t \]+n\[\t \]+($hex) .*ust/bar2\[\t \]+n\[\t \]+($hex) " \
140 "$expect_out(0,string)" ignore marker_bar_addr marker_bar2_addr
141
142 pass "info static-tracepoint-markers 1"
143 }
144 -re ".*${gdb_prompt} $" {
145 fail "info static-tracepoint-markers 1"
146 }
147 }
148
149 gdb_test "strace -m ust/bar" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
150 gdb_test "strace -m ust/bar2" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
151 # Two trace markers should be enabled.
152 gdb_test "info static-tracepoint-markers" \
153 "ust/bar\[\t \]+y\[\t \]+$hex .*ust/bar2\[\t \]+y\[\t \]+$hex.*" \
154 "info static-tracepoint-markers 2"
155
156 # Set breapoints or tracepoints.
157 set test "${type} on marker bar"
158 gdb_test_multiple "${type} *${marker_bar_addr}" $test {
159 -re "\(Fast trace|Trace|Break\)point \[0-9\]+ at ${hex}: file.*\r\n$gdb_prompt $" {
160 pass $test
161 }
162 -re ".*\r\n$gdb_prompt $" {
163 if [string equal $type "ftrace"] {
164 # The instruction may be not long enough to set a fast tracepoint.
165 # Skip the rest of this test.
166 return -1;
167 } else {
168 fail $test
169 }
170 }
171 }
172 set test "${type} on marker bar2"
173 gdb_test_multiple "${type} *${marker_bar2_addr}" $test {
174 -re "\(Fast trace|Trace|Break\)point \[0-9\]+ at ${hex}: file.*" {
175 pass $test
176 }
177 -re ".*\r\n$gdb_prompt $" {
178 if [string equal $type "ftrace"] {
179 # The instruction may be not long enough to set a fast tracepoint.
180 # Skip the rest of this test.
181 return -1;
182 } else {
183 fail $test
184 }
185 }
186 }
187
188 gdb_test "break end" "Breakpoint \[0-9\]+ at.*"
189
190 if [string equal $type "break"] {
191 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to bar"
192 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to bar2"
193 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
194 } else {
195
196 gdb_test_no_output "tstart"
197 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
198 gdb_test_no_output "tstop"
199
200 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
201 gdb_test "tfind" "Found trace frame 1, tracepoint .*" "tfind frame 1"
202 gdb_test "tfind" "Found trace frame 2, tracepoint .*" "tfind frame 2"
203 gdb_test "tfind" "Found trace frame 3, tracepoint .*" "tfind frame 3"
204 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
205 }
206 set pf_prefix $old_pf_prefix
207 }
208
209 proc strace_trace_on_diff_addr { } {
210 global executable
211 global pf_prefix
212 global expect_out
213 global gdb_prompt
214 global hex
215
216 set old_pf_prefix $pf_prefix
217 lappend pf_prefix "trace_diff_addr"
218
219 # Restart with a fresh gdb.
220 clean_restart $executable
221 if ![runto_main] {
222 fail "Can't run to main"
223 set pf_prefix $old_pf_prefix
224 return -1
225 }
226
227 set marker_bar_addr ""
228 set marker_bar2_addr ""
229
230 # List the markers in program. They should be disabled.
231 gdb_test_multiple "info static-tracepoint-markers" "info static-tracepoint-markers 1" {
232 -re ".*ust/bar\[\t \]+n.*${gdb_prompt} $" {
233 set ignore ""
234
235 regexp "ust/bar\[\t \]+n\[\t \]+($hex) .*ust/bar2\[\t \]+n\[\t \]+($hex) " \
236 "$expect_out(0,string)" ignore marker_bar_addr marker_bar2_addr
237
238 pass "info static-tracepoint-markers 1"
239 }
240 -re ".*${gdb_prompt} $" {
241 fail "info static-tracepoint-markers 1"
242 }
243 }
244
245 gdb_test "strace -m ust/bar" "Static tracepoint \[0-9\]+ at ${hex}: file.*"
246
247 gdb_test "info static-tracepoint-markers" \
248 "ust/bar\[\t \]+y\[\t \]+$hex .*ust/bar2\[\t \]+n\[\t \]+$hex.*" \
249 "info static-tracepoint-markers 2"
250
251
252 # Set common tracepoint.
253 gdb_test "trace *${marker_bar2_addr}" "Tracepoint \[0-9\]+ at ${hex}: file.*"
254
255 gdb_test "break end" "Breakpoint \[0-9\]+ at.*"
256
257 gdb_test_no_output "tstart"
258 gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*" "continue to end"
259 gdb_test_no_output "tstop"
260
261 gdb_test "tfind" "Found trace frame 0, tracepoint .*" "tfind frame 0"
262 gdb_test "tfind" "Found trace frame 1, tracepoint .*" "tfind frame 1"
263 gdb_test "tfind" "Target failed to find requested trace frame\\..*"
264
265 set pf_prefix $old_pf_prefix
266 }
267
268 strace_info_marker
269 strace_probe_marker
270
271 strace_trace_on_same_addr "trace"
272 strace_trace_on_same_addr "ftrace"
273 strace_trace_on_same_addr "break"
274 strace_trace_on_diff_addr
This page took 0.035554 seconds and 4 git commands to generate.