Commit | Line | Data |
---|---|---|
32d0add0 | 1 | # Copyright 1998-2015 Free Software Foundation, Inc. |
c906108c SS |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
c906108c SS |
8 | # This program is distributed in the hope that it will be useful, |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
e22f8b7c | 12 | # |
c906108c | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c | 15 | |
c906108c SS |
16 | load_lib "trace-support.exp" |
17 | ||
497a5eb0 | 18 | standard_testfile |
c906108c | 19 | |
497a5eb0 | 20 | if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug nowarnings}]} { |
b60f0898 | 21 | return -1 |
c906108c SS |
22 | } |
23 | ||
24 | # Tests: | |
993654a9 HAQ |
25 | # 1) Calculate the size taken by one trace frame. |
26 | # 2) Set up a trace experiment that will collect approximately 10 frames, | |
c906108c SS |
27 | # requiring more than 512 but less than 1024 bytes of cache buffer. |
28 | # (most targets should have at least 1024 bytes of cache buffer!) | |
29 | # Run and confirm that it collects all 10 frames. | |
993654a9 HAQ |
30 | # 3) Artificially limit the trace buffer to 4x + a bytes. Here x is the size |
31 | # of single trace frame and a is a small constant. Rerun the | |
32 | # experiment. Confirm that the frame for the first tracepoint is collected, | |
33 | # but frames for the last several tracepoints are not. | |
34 | # 4) Set trace buffer to circular mode, with the buffer size as in | |
35 | # step 3 above. Rerun the experiment. Confirm that the frame for the last | |
36 | # tracepoint is collected but not for the first one. | |
c906108c SS |
37 | # |
38 | ||
993654a9 HAQ |
39 | # Set a tracepoint on given func. The tracepoint is set at entry |
40 | # address and not 'after prologue' address because we use | |
41 | # 'tfind pc func' to find the corresponding trace frame afterwards, | |
42 | # and that looks for entry address. | |
43 | proc set_a_tracepoint { func } { | |
44 | gdb_test "trace \*$func" "Tracepoint \[0-9\]+ at .*" \ | |
45 | "set tracepoint at $func" | |
46 | gdb_trace_setactions "set actions for $func" "" "collect testload" "^$" | |
47 | } | |
c906108c | 48 | |
993654a9 HAQ |
49 | # Sets the tracepoints from func0 to func9 using set_a_tracepoint. |
50 | proc setup_tracepoints { } { | |
51 | gdb_delete_tracepoints | |
52 | set_a_tracepoint func0 | |
53 | set_a_tracepoint func1 | |
54 | set_a_tracepoint func2 | |
55 | set_a_tracepoint func3 | |
56 | set_a_tracepoint func4 | |
57 | set_a_tracepoint func5 | |
58 | set_a_tracepoint func6 | |
59 | set_a_tracepoint func7 | |
60 | set_a_tracepoint func8 | |
61 | set_a_tracepoint func9 | |
c906108c SS |
62 | } |
63 | ||
993654a9 HAQ |
64 | # Start the trace, run to end and then stop the trace. |
65 | proc run_trace_experiment { } { | |
66 | global decimal | |
67 | ||
68 | setup_tracepoints | |
69 | gdb_test "break end" "Breakpoint $decimal.*" "breakpoint at end" | |
70 | gdb_test "tstart" "\[\r\n\]*" "start trace experiment" | |
71 | gdb_test "continue" "Continuing.*Breakpoint \[0-9\]+, end.*" \ | |
72 | "run to end" | |
73 | gdb_test "tstop" "\[\r\n\]*" "stop trace experiment" | |
74 | } | |
75 | ||
76 | if { ![runto_main] } { | |
77 | fail "can't run to main to check for trace support" | |
78 | return -1 | |
79 | } | |
80 | ||
81 | if { ![gdb_target_supports_trace] } { | |
82 | unsupported "target does not support trace" | |
83 | return 1 | |
84 | } | |
85 | ||
86 | set test "set circular-trace-buffer on" | |
87 | gdb_test_multiple "set circular-trace-buffer on" $test { | |
88 | -re ".*Target does not support this command.*$gdb_prompt $" { | |
89 | unsupported "target does not support circular trace buffer" | |
ae59b1da | 90 | return 1 |
c906108c | 91 | } |
993654a9 HAQ |
92 | -re "$gdb_prompt $" { |
93 | pass $test | |
94 | } | |
95 | } | |
96 | ||
97 | set circular_supported -1 | |
98 | set test "check whether circular buffer is supported" | |
99 | ||
100 | gdb_test_multiple "tstatus" $test { | |
101 | -re ".*Trace buffer is circular.*$gdb_prompt $" { | |
102 | set circular_supported 1 | |
103 | pass $test | |
104 | } | |
105 | -re "$gdb_prompt $" { | |
106 | pass $test | |
107 | } | |
108 | } | |
109 | ||
110 | if { $circular_supported < 0 } { | |
111 | unsupported "target does not support circular trace buffer" | |
112 | return 1 | |
113 | } | |
114 | ||
115 | gdb_test "show circular-trace-buffer" \ | |
116 | "Target's use of circular trace buffer is on." \ | |
117 | "show circular-trace-buffer (on)" | |
118 | ||
119 | # Check if changing the trace buffer size is supported. This step is | |
120 | # repeated twice. This helps in case the trace buffer size is 100. | |
121 | set test_size 100 | |
122 | set test "change buffer size to $test_size" | |
123 | gdb_test_multiple "set trace-buffer-size $test_size" $test { | |
124 | -re ".*Target does not support this command.*$gdb_prompt $" { | |
125 | unsupported "target does not support changing trace buffer size" | |
ae59b1da | 126 | return 1 |
c906108c | 127 | } |
993654a9 HAQ |
128 | -re "$gdb_prompt $" { |
129 | pass $test | |
130 | } | |
c906108c SS |
131 | } |
132 | ||
993654a9 HAQ |
133 | set test "check whether setting trace buffer size is supported" |
134 | gdb_test_multiple "tstatus" $test { | |
135 | -re ".*Trace buffer has ($decimal) bytes of ($decimal) bytes free.*$gdb_prompt $" { | |
136 | set total_size $expect_out(2,string) | |
137 | if { $test_size != $total_size } { | |
138 | unsupported "target does not support changing trace buffer size" | |
139 | return 1 | |
a2e0062d | 140 | } |
993654a9 | 141 | pass $test |
a2e0062d | 142 | } |
993654a9 HAQ |
143 | } |
144 | ||
145 | set test_size 400 | |
146 | gdb_test_no_output "set trace-buffer-size $test_size" \ | |
147 | "change buffer size to $test_size" | |
148 | ||
149 | gdb_test_multiple "tstatus" $test { | |
150 | -re ".*Trace buffer has ($decimal) bytes of ($decimal) bytes free.*$gdb_prompt $" { | |
151 | set total_size $expect_out(2,string) | |
152 | if { $test_size != $total_size } { | |
153 | unsupported "target does not support changing trace buffer size" | |
154 | return 1 | |
155 | } | |
156 | pass $test | |
c906108c | 157 | } |
993654a9 HAQ |
158 | } |
159 | ||
160 | gdb_test_no_output "set circular-trace-buffer off" \ | |
161 | "set circular-trace-buffer off" | |
162 | ||
163 | gdb_test "show circular-trace-buffer" \ | |
164 | "Target's use of circular trace buffer is off." \ | |
165 | "show circular-trace-buffer (off)" | |
166 | ||
167 | set total_size -1 | |
168 | set free_size -1 | |
169 | set frame_size -1 | |
a2e0062d | 170 | |
993654a9 HAQ |
171 | # Determine the size used by a single frame. Set a single tracepoint, |
172 | # run and then check the total and free size using the tstatus command. | |
173 | # Then subtracting free from total gives us the size of a frame. | |
174 | with_test_prefix "frame size" { | |
175 | set_a_tracepoint func0 | |
176 | ||
177 | gdb_test "break end" "Breakpoint $decimal.*" "breakpoint at end" | |
178 | ||
179 | gdb_test "tstart" "\[\r\n\]*" "start trace" | |
180 | ||
181 | gdb_test "continue" "Continuing.*Breakpoint \[0-9\]+, end.*" \ | |
182 | "run to end" | |
183 | ||
184 | gdb_test "tstop" "\[\r\n\]*" "stop trace" | |
185 | ||
186 | set test "get buffer size" | |
187 | ||
188 | gdb_test_multiple "tstatus" $test { | |
189 | -re ".*Trace buffer has ($decimal) bytes of ($decimal) bytes free.*$gdb_prompt $" { | |
190 | set free_size $expect_out(1,string) | |
191 | set total_size $expect_out(2,string) | |
a2e0062d PA |
192 | pass $test |
193 | } | |
a2e0062d | 194 | } |
993654a9 HAQ |
195 | |
196 | # Check that we get the total_size and free_size. | |
197 | if { $total_size < 0 } { | |
ae59b1da | 198 | return 1 |
c906108c | 199 | } |
a2e0062d | 200 | |
993654a9 HAQ |
201 | if { $free_size < 0 } { |
202 | return 1 | |
203 | } | |
c906108c SS |
204 | } |
205 | ||
993654a9 HAQ |
206 | # Calculate the size of a single frame. |
207 | set frame_size "($total_size - $free_size)" | |
208 | ||
209 | with_test_prefix "normal buffer" { | |
210 | clean_restart $testfile | |
211 | ||
212 | if { ![runto_main] } { | |
213 | fail "can't run to main" | |
ae59b1da | 214 | return 1 |
c906108c SS |
215 | } |
216 | ||
993654a9 | 217 | run_trace_experiment |
c906108c | 218 | |
993654a9 HAQ |
219 | # Check that the first frame is actually at func0. |
220 | gdb_test "tfind start" ".*#0 func0 .*" \ | |
221 | "first frame is at func0" | |
c906108c | 222 | |
993654a9 | 223 | gdb_test "tfind pc func9" \ |
5ce0145d | 224 | ".*Found trace frame $decimal, tracepoint $decimal\r\n#0 func9 .*" \ |
993654a9 HAQ |
225 | "find frame for func9" |
226 | } | |
c906108c | 227 | |
993654a9 HAQ |
228 | # Shrink the trace buffer so that it will not hold |
229 | # all ten trace frames. Verify that the frame for func0 is still | |
230 | # collected, but the frame for func9 is not. | |
c906108c | 231 | |
993654a9 HAQ |
232 | set buffer_size "((4 * $frame_size) + 10)" |
233 | with_test_prefix "small buffer" { | |
234 | clean_restart $testfile | |
c906108c | 235 | |
993654a9 HAQ |
236 | if { ![runto_main] } { |
237 | fail "can't run to main" | |
ae59b1da | 238 | return 1 |
c906108c | 239 | } |
c906108c | 240 | |
993654a9 HAQ |
241 | gdb_test_no_output "set trace-buffer-size $buffer_size" \ |
242 | "shrink the target trace buffer" | |
c906108c | 243 | |
993654a9 | 244 | run_trace_experiment |
c906108c | 245 | |
993654a9 HAQ |
246 | gdb_test "tfind start" ".*#0 func0 .*" \ |
247 | "first frame is at func0" | |
248 | ||
249 | gdb_test "tfind pc func9" ".* failed to find .*" \ | |
250 | "find frame for func9" | |
c906108c SS |
251 | } |
252 | ||
993654a9 HAQ |
253 | # Finally, make the buffer circular. Now when it runs out of |
254 | # space, it should wrap around and overwrite the earliest frames. | |
255 | # This means that: | |
256 | # 1) the first frame will be overwritten and therefore unavailable. | |
257 | # 2) the earliest frame in the buffer will not be for func0. | |
258 | # 3) the frame for func9 will be available (unlike "small buffer" case). | |
259 | with_test_prefix "circular buffer" { | |
260 | clean_restart $testfile | |
261 | ||
262 | if { ![runto_main] } { | |
263 | fail "can't run to main" | |
264 | return 1 | |
265 | } | |
4daf5ac0 | 266 | |
993654a9 HAQ |
267 | gdb_test_no_output "set trace-buffer-size $buffer_size" \ |
268 | "shrink the target trace buffer" | |
4daf5ac0 | 269 | |
993654a9 HAQ |
270 | gdb_test_no_output "set circular-trace-buffer on" \ |
271 | "make the target trace buffer circular" | |
4daf5ac0 | 272 | |
993654a9 | 273 | run_trace_experiment |
4daf5ac0 | 274 | |
993654a9 HAQ |
275 | gdb_test "tstatus" \ |
276 | ".*Buffer contains $decimal trace frames \\(of $decimal created total\\).*Trace buffer is circular.*" \ | |
277 | "trace buffer is circular" | |
c906108c | 278 | |
993654a9 HAQ |
279 | # The first frame should not be at func0. |
280 | gdb_test "tfind start" ".*#0 func\[1-9\] .*" \ | |
281 | "first frame is NOT at func0" | |
282 | ||
283 | gdb_test \ | |
284 | "tfind pc func9" \ | |
5ce0145d | 285 | ".*Found trace frame $decimal, tracepoint $decimal\r\n#0 func9 .*" \ |
993654a9 HAQ |
286 | "find frame for func9" |
287 | } |