1 # Copyright 1998, 2007, 2008, 2009, 2010 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"
26 set srcfile ${testfile}.c
27 set binfile $objdir/$subdir/$testfile
29 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
30 executable {debug nowarnings}] != "" } {
36 # 1) Set up a trace experiment that will collect approximately 10 frames,
37 # requiring more than 512 but less than 1024 bytes of cache buffer.
38 # (most targets should have at least 1024 bytes of cache buffer!)
39 # Run and confirm that it collects all 10 frames.
40 # 2) Artificially limit the trace buffer to 512 bytes, and rerun the
41 # experiment. Confirm that the first several frames are collected,
42 # but that the last several are not.
43 # 3) Set trace buffer to circular mode, still with the artificial limit
44 # of 512 bytes, and rerun the experiment. Confirm that the last
45 # several frames are collected, but the first several are not.
48 # return 0 for success, 1 for failure
49 proc run_trace_experiment { pass } {
52 if [gdb_test "tstart" \
54 "start trace experiment, pass $pass"] then { return 1; }
55 if [gdb_test "continue" \
56 "Continuing.*Breakpoint \[0-9\]+, end.*" \
57 "run to end, pass $pass"] then { return 1; }
58 if [gdb_test "tstop" \
60 "stop trace experiment, pass $pass"] then { return 1; }
64 # return 0 for success, 1 for failure
65 proc set_a_tracepoint { func } {
66 if [gdb_test "trace $func" \
67 "Tracepoint \[0-9\]+ at .*" \
68 "set tracepoint at $func"] then {
71 if [gdb_trace_setactions "set actions for $func" \
73 "collect testload" "^$"] then {
79 # return 0 for success, 1 for failure
80 proc setup_tracepoints { } {
81 gdb_delete_tracepoints
82 if [set_a_tracepoint func0] then { return 1; }
83 if [set_a_tracepoint func1] then { return 1; }
84 if [set_a_tracepoint func2] then { return 1; }
85 if [set_a_tracepoint func3] then { return 1; }
86 if [set_a_tracepoint func4] then { return 1; }
87 if [set_a_tracepoint func5] then { return 1; }
88 if [set_a_tracepoint func6] then { return 1; }
89 if [set_a_tracepoint func7] then { return 1; }
90 if [set_a_tracepoint func8] then { return 1; }
91 if [set_a_tracepoint func9] then { return 1; }
95 # return 0 for success, 1 for failure
96 proc trace_buffer_normal { } {
97 if [gdb_test "maint packet QTBuffer:size:ffffffff" \
98 "received: .OK." ""] then {
99 pass "This test cannot be run on this target"
102 if [gdb_test "maint packet QTBuffer:circular:0" \
103 "received: .OK." ""] then {
104 pass "This test cannot be run on this target"
110 # return 0 for success, 1 for failure
111 proc gdb_trace_circular_tests { } {
113 # We generously give ourselves one "pass" if we successfully
114 # detect that this test cannot be run on this target!
115 if { ![gdb_target_supports_trace] } then {
116 pass "Current target does not support trace"
120 if [trace_buffer_normal] then { return 1; }
122 gdb_test "break begin" "" ""
123 gdb_test "break end" "" ""
124 gdb_test "tstop" "" ""
125 gdb_test "tfind none" "" ""
127 if [setup_tracepoints] then { return 1; }
129 # First, run the trace experiment with default attributes:
130 # Make sure it behaves as expected.
131 if [run_trace_experiment 1] then { return 1; }
132 if [gdb_test "tfind start" \
134 "find frame zero, pass 1"] then { return 1; }
136 if [gdb_test "tfind 9" \
138 "find frame nine, pass 1"] then { return 1; }
140 if [gdb_test "tfind none" \
142 "quit trace debugging, pass 1"] then { return 1; }
144 # Then, shrink the trace buffer so that it will not hold
145 # all ten trace frames. Verify that frame zero is still
146 # collected, but frame nine is not.
147 if [gdb_test "maint packet QTBuffer:size:200" \
148 "received: .OK." "shrink the target trace buffer"] then {
151 if [run_trace_experiment 2] then { return 1; }
152 if [gdb_test "tfind start" \
154 "find frame zero, pass 2"] then { return 1; }
156 if [gdb_test "tfind 9" \
157 ".* failed to find .*" \
158 "fail to find frame nine, pass 2"] then { return 1; }
160 if [gdb_test "tfind none" \
162 "quit trace debugging, pass 2"] then { return 1; }
164 # Finally, make the buffer circular. Now when it runs out of
165 # space, it should wrap around and overwrite the earliest frames.
167 # 1) frame zero will be overwritten and therefore unavailable
168 # 2) the earliest frame in the buffer will be other-than-zero
169 # 3) frame nine will be available (unlike on pass 2).
170 if [gdb_test "maint packet QTBuffer:circular:1" \
171 "received: .OK." "make the target trace buffer circular"] then {
174 if [run_trace_experiment 3] then { return 1; }
175 if [gdb_test "tfind start" \
176 "#0 func\[1-9\] .*" \
177 "first frame is NOT frame zero, pass 3"] then { return 1; }
179 if [gdb_test "tfind 9" \
181 "find frame nine, pass 3"] then { return 1; }
183 if [gdb_test "tfind none" \
185 "quit trace debugging, pass 3"] then { return 1; }
190 # Start with a fresh gdb.
194 gdb_reinitialize_dir $srcdir/$subdir
197 if [target_info exists gdb_stub] {
201 gdb_test "set circular-trace-buffer on" "" "set circular-trace-buffer on"
203 gdb_test "show circular-trace-buffer" "Target's use of circular trace buffer is on." "show circular-trace-buffer (on)"
205 gdb_test "set circular-trace-buffer off" "" "set circular-trace-buffer off"
207 gdb_test "show circular-trace-buffer" "Target's use of circular trace buffer is off." "show circular-trace-buffer (off)"
209 # Body of test encased in a proc so we can return prematurely.
210 if { ![gdb_trace_circular_tests] } then {
211 # Set trace buffer attributes back to normal
216 gdb_test "tfind none" "" ""