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"
21 if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug nowarnings}]} {
26 # 1) Set up a trace experiment that will collect approximately 10 frames,
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.
30 # 2) Artificially limit the trace buffer to 512 bytes, and rerun the
31 # experiment. Confirm that the first several frames are collected,
32 # but that the last several are not.
33 # 3) Set trace buffer to circular mode, still with the artificial limit
34 # of 512 bytes, and rerun the experiment. Confirm that the last
35 # several frames are collected, but the first several are not.
38 # return 0 for success, 1 for failure
39 proc run_trace_experiment { pass } {
42 if [gdb_test "tstart" \
44 "start trace experiment, pass $pass"] then { return 1; }
45 if [gdb_test "continue" \
46 "Continuing.*Breakpoint \[0-9\]+, end.*" \
47 "run to end, pass $pass"] then { return 1; }
48 if [gdb_test "tstop" \
50 "stop trace experiment, pass $pass"] then { return 1; }
54 # return 0 for success, 1 for failure
55 proc set_a_tracepoint { func } {
56 if [gdb_test "trace $func" \
57 "Tracepoint \[0-9\]+ at .*" \
58 "set tracepoint at $func"] then {
61 if [gdb_trace_setactions "set actions for $func" \
63 "collect testload" "^$"] then {
69 # return 0 for success, 1 for failure
70 proc setup_tracepoints { } {
71 gdb_delete_tracepoints
72 if [set_a_tracepoint func0] then { return 1; }
73 if [set_a_tracepoint func1] then { return 1; }
74 if [set_a_tracepoint func2] then { return 1; }
75 if [set_a_tracepoint func3] then { return 1; }
76 if [set_a_tracepoint func4] then { return 1; }
77 if [set_a_tracepoint func5] then { return 1; }
78 if [set_a_tracepoint func6] then { return 1; }
79 if [set_a_tracepoint func7] then { return 1; }
80 if [set_a_tracepoint func8] then { return 1; }
81 if [set_a_tracepoint func9] then { return 1; }
85 # return 0 for success, 1 for failure
86 proc trace_buffer_normal { } {
90 set test "maint packet QTBuffer:size:ffffffff"
91 gdb_test_multiple $test $test {
92 -re "received: .OK.\r\n$gdb_prompt $" {
96 -re "\r\n$gdb_prompt $" {
105 set test "maint packet QTBuffer:circular:0"
106 gdb_test_multiple $test $test {
107 -re "received: .OK.\r\n$gdb_prompt $" {
111 -re "\r\n$gdb_prompt $" {
122 # return 0 for success, 1 for failure
123 proc gdb_trace_circular_tests { } {
124 if { ![gdb_target_supports_trace] } then {
125 unsupported "Current target does not support trace"
129 if [trace_buffer_normal] then { return 1; }
131 gdb_test "break begin" ".*" ""
132 gdb_test "break end" ".*" ""
133 gdb_test "tstop" ".*" ""
134 gdb_test "tfind none" ".*" ""
136 if [setup_tracepoints] then { return 1; }
138 # First, run the trace experiment with default attributes:
139 # Make sure it behaves as expected.
140 if [run_trace_experiment 1] then { return 1; }
141 if [gdb_test "tfind start" \
143 "find frame zero, pass 1"] then { return 1; }
145 if [gdb_test "tfind 9" \
147 "find frame nine, pass 1"] then { return 1; }
149 if [gdb_test "tfind none" \
151 "quit trace debugging, pass 1"] then { return 1; }
153 # Then, shrink the trace buffer so that it will not hold
154 # all ten trace frames. Verify that frame zero is still
155 # collected, but frame nine is not.
156 if [gdb_test "maint packet QTBuffer:size:200" \
157 "received: .OK." "shrink the target trace buffer"] then {
160 if [run_trace_experiment 2] then { return 1; }
161 if [gdb_test "tfind start" \
163 "find frame zero, pass 2"] then { return 1; }
165 if [gdb_test "tfind 9" \
166 ".* failed to find .*" \
167 "fail to find frame nine, pass 2"] then { return 1; }
169 if [gdb_test "tfind none" \
171 "quit trace debugging, pass 2"] then { return 1; }
173 # Finally, make the buffer circular. Now when it runs out of
174 # space, it should wrap around and overwrite the earliest frames.
176 # 1) frame zero will be overwritten and therefore unavailable
177 # 2) the earliest frame in the buffer will be other-than-zero
178 # 3) frame nine will be available (unlike on pass 2).
179 if [gdb_test "maint packet QTBuffer:circular:1" \
180 "received: .OK." "make the target trace buffer circular"] then {
183 if [run_trace_experiment 3] then { return 1; }
184 if [gdb_test "tfind start" \
185 "#0 func\[1-9\] .*" \
186 "first frame is NOT frame zero, pass 3"] then { return 1; }
188 if [gdb_test "tfind 9" \
190 "find frame nine, pass 3"] then { return 1; }
192 if [gdb_test "tfind none" \
194 "quit trace debugging, pass 3"] then { return 1; }
199 gdb_test_no_output "set circular-trace-buffer on" \
200 "set circular-trace-buffer on"
202 gdb_test "show circular-trace-buffer" "Target's use of circular trace buffer is on." "show circular-trace-buffer (on)"
204 gdb_test_no_output "set circular-trace-buffer off" \
205 "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" ".*" ""