1 # Copyright 1998, 2007-2012 Free Software Foundation, Inc.
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
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 load_lib "trace-support.exp"
20 set srcfile ${testfile}.c
21 set binfile $objdir/$subdir/$testfile
23 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
24 executable {debug nowarnings}] != "" } {
30 # 1) Set up a trace experiment that will collect approximately 10 frames,
31 # requiring more than 512 but less than 1024 bytes of cache buffer.
32 # (most targets should have at least 1024 bytes of cache buffer!)
33 # Run and confirm that it collects all 10 frames.
34 # 2) Artificially limit the trace buffer to 512 bytes, and rerun the
35 # experiment. Confirm that the first several frames are collected,
36 # but that the last several are not.
37 # 3) Set trace buffer to circular mode, still with the artificial limit
38 # of 512 bytes, and rerun the experiment. Confirm that the last
39 # several frames are collected, but the first several are not.
42 # return 0 for success, 1 for failure
43 proc run_trace_experiment { pass } {
46 if [gdb_test "tstart" \
48 "start trace experiment, pass $pass"] then { return 1; }
49 if [gdb_test "continue" \
50 "Continuing.*Breakpoint \[0-9\]+, end.*" \
51 "run to end, pass $pass"] then { return 1; }
52 if [gdb_test "tstop" \
54 "stop trace experiment, pass $pass"] then { return 1; }
58 # return 0 for success, 1 for failure
59 proc set_a_tracepoint { func } {
60 if [gdb_test "trace $func" \
61 "Tracepoint \[0-9\]+ at .*" \
62 "set tracepoint at $func"] then {
65 if [gdb_trace_setactions "set actions for $func" \
67 "collect testload" "^$"] then {
73 # return 0 for success, 1 for failure
74 proc setup_tracepoints { } {
75 gdb_delete_tracepoints
76 if [set_a_tracepoint func0] then { return 1; }
77 if [set_a_tracepoint func1] then { return 1; }
78 if [set_a_tracepoint func2] then { return 1; }
79 if [set_a_tracepoint func3] then { return 1; }
80 if [set_a_tracepoint func4] then { return 1; }
81 if [set_a_tracepoint func5] then { return 1; }
82 if [set_a_tracepoint func6] then { return 1; }
83 if [set_a_tracepoint func7] then { return 1; }
84 if [set_a_tracepoint func8] then { return 1; }
85 if [set_a_tracepoint func9] then { return 1; }
89 # return 0 for success, 1 for failure
90 proc trace_buffer_normal { } {
94 set test "maint packet QTBuffer:size:ffffffff"
95 gdb_test_multiple $test $test {
96 -re "received: .OK.\r\n$gdb_prompt $" {
100 -re "\r\n$gdb_prompt $" {
109 set test "maint packet QTBuffer:circular:0"
110 gdb_test_multiple $test $test {
111 -re "received: .OK.\r\n$gdb_prompt $" {
115 -re "\r\n$gdb_prompt $" {
126 # return 0 for success, 1 for failure
127 proc gdb_trace_circular_tests { } {
128 if { ![gdb_target_supports_trace] } then {
129 unsupported "Current target does not support trace"
133 if [trace_buffer_normal] then { return 1; }
135 gdb_test "break begin" ".*" ""
136 gdb_test "break end" ".*" ""
137 gdb_test "tstop" ".*" ""
138 gdb_test "tfind none" ".*" ""
140 if [setup_tracepoints] then { return 1; }
142 # First, run the trace experiment with default attributes:
143 # Make sure it behaves as expected.
144 if [run_trace_experiment 1] then { return 1; }
145 if [gdb_test "tfind start" \
147 "find frame zero, pass 1"] then { return 1; }
149 if [gdb_test "tfind 9" \
151 "find frame nine, pass 1"] then { return 1; }
153 if [gdb_test "tfind none" \
155 "quit trace debugging, pass 1"] then { return 1; }
157 # Then, shrink the trace buffer so that it will not hold
158 # all ten trace frames. Verify that frame zero is still
159 # collected, but frame nine is not.
160 if [gdb_test "maint packet QTBuffer:size:200" \
161 "received: .OK." "shrink the target trace buffer"] then {
164 if [run_trace_experiment 2] then { return 1; }
165 if [gdb_test "tfind start" \
167 "find frame zero, pass 2"] then { return 1; }
169 if [gdb_test "tfind 9" \
170 ".* failed to find .*" \
171 "fail to find frame nine, pass 2"] then { return 1; }
173 if [gdb_test "tfind none" \
175 "quit trace debugging, pass 2"] then { return 1; }
177 # Finally, make the buffer circular. Now when it runs out of
178 # space, it should wrap around and overwrite the earliest frames.
180 # 1) frame zero will be overwritten and therefore unavailable
181 # 2) the earliest frame in the buffer will be other-than-zero
182 # 3) frame nine will be available (unlike on pass 2).
183 if [gdb_test "maint packet QTBuffer:circular:1" \
184 "received: .OK." "make the target trace buffer circular"] then {
187 if [run_trace_experiment 3] then { return 1; }
188 if [gdb_test "tfind start" \
189 "#0 func\[1-9\] .*" \
190 "first frame is NOT frame zero, pass 3"] then { return 1; }
192 if [gdb_test "tfind 9" \
194 "find frame nine, pass 3"] then { return 1; }
196 if [gdb_test "tfind none" \
198 "quit trace debugging, pass 3"] then { return 1; }
203 # Start with a fresh gdb.
207 gdb_reinitialize_dir $srcdir/$subdir
210 gdb_test_no_output "set circular-trace-buffer on" \
211 "set circular-trace-buffer on"
213 gdb_test "show circular-trace-buffer" "Target's use of circular trace buffer is on." "show circular-trace-buffer (on)"
215 gdb_test_no_output "set circular-trace-buffer off" \
216 "set circular-trace-buffer off"
218 gdb_test "show circular-trace-buffer" "Target's use of circular trace buffer is off." "show circular-trace-buffer (off)"
220 # Body of test encased in a proc so we can return prematurely.
221 if { ![gdb_trace_circular_tests] } then {
222 # Set trace buffer attributes back to normal
227 gdb_test "tfind none" ".*" ""