2012-02-15 Pedro Alves <palves@redhat.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.trace / circ.exp
CommitLineData
c5a57081 1# Copyright 1998, 2007-2012 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
16load_lib "trace-support.exp"
17
c906108c
SS
18
19set testfile "circ"
20set srcfile ${testfile}.c
21set binfile $objdir/$subdir/$testfile
22
23if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
fc91c6c2 24 executable {debug nowarnings}] != "" } {
b60f0898
JB
25 untested circ.exp
26 return -1
c906108c
SS
27}
28
29# Tests:
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.
40#
41
42# return 0 for success, 1 for failure
43proc run_trace_experiment { pass } {
44 gdb_run_cmd
45
46 if [gdb_test "tstart" \
47 "\[\r\n\]*" \
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" \
53 "\[\r\n\]*" \
54 "stop trace experiment, pass $pass"] then { return 1; }
55 return 0;
56}
57
58# return 0 for success, 1 for failure
59proc set_a_tracepoint { func } {
60 if [gdb_test "trace $func" \
61 "Tracepoint \[0-9\]+ at .*" \
62 "set tracepoint at $func"] then {
63 return 1;
64 }
65 if [gdb_trace_setactions "set actions for $func" \
66 "" \
67 "collect testload" "^$"] then {
68 return 1;
69 }
70 return 0;
71}
72
73# return 0 for success, 1 for failure
74proc 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; }
86 return 0;
87}
88
89# return 0 for success, 1 for failure
90proc trace_buffer_normal { } {
91 if [gdb_test "maint packet QTBuffer:size:ffffffff" \
92 "received: .OK." ""] then {
93 pass "This test cannot be run on this target"
94 return 1;
95 }
96 if [gdb_test "maint packet QTBuffer:circular:0" \
97 "received: .OK." ""] then {
98 pass "This test cannot be run on this target"
99 return 1;
100 }
101 return 0;
102}
103
104# return 0 for success, 1 for failure
105proc gdb_trace_circular_tests { } {
106
107 # We generously give ourselves one "pass" if we successfully
108 # detect that this test cannot be run on this target!
109 if { ![gdb_target_supports_trace] } then {
0ef2251b 110 pass "Current target does not support trace"
c906108c
SS
111 return 1;
112 }
113
114 if [trace_buffer_normal] then { return 1; }
115
de7ff789
MS
116 gdb_test "break begin" ".*" ""
117 gdb_test "break end" ".*" ""
118 gdb_test "tstop" ".*" ""
119 gdb_test "tfind none" ".*" ""
c906108c
SS
120
121 if [setup_tracepoints] then { return 1; }
122
123 # First, run the trace experiment with default attributes:
124 # Make sure it behaves as expected.
125 if [run_trace_experiment 1] then { return 1; }
126 if [gdb_test "tfind start" \
127 "#0 func0 .*" \
128 "find frame zero, pass 1"] then { return 1; }
129
130 if [gdb_test "tfind 9" \
131 "#0 func9 .*" \
132 "find frame nine, pass 1"] then { return 1; }
133
134 if [gdb_test "tfind none" \
135 "#0 end .*" \
136 "quit trace debugging, pass 1"] then { return 1; }
137
138 # Then, shrink the trace buffer so that it will not hold
139 # all ten trace frames. Verify that frame zero is still
140 # collected, but frame nine is not.
141 if [gdb_test "maint packet QTBuffer:size:200" \
142 "received: .OK." "shrink the target trace buffer"] then {
143 return 1;
144 }
145 if [run_trace_experiment 2] then { return 1; }
146 if [gdb_test "tfind start" \
147 "#0 func0 .*" \
148 "find frame zero, pass 2"] then { return 1; }
149
150 if [gdb_test "tfind 9" \
151 ".* failed to find .*" \
152 "fail to find frame nine, pass 2"] then { return 1; }
153
154 if [gdb_test "tfind none" \
155 "#0 end .*" \
156 "quit trace debugging, pass 2"] then { return 1; }
157
158 # Finally, make the buffer circular. Now when it runs out of
159 # space, it should wrap around and overwrite the earliest frames.
160 # This means that:
161 # 1) frame zero will be overwritten and therefore unavailable
162 # 2) the earliest frame in the buffer will be other-than-zero
163 # 3) frame nine will be available (unlike on pass 2).
164 if [gdb_test "maint packet QTBuffer:circular:1" \
165 "received: .OK." "make the target trace buffer circular"] then {
166 return 1;
167 }
168 if [run_trace_experiment 3] then { return 1; }
169 if [gdb_test "tfind start" \
170 "#0 func\[1-9\] .*" \
171 "first frame is NOT frame zero, pass 3"] then { return 1; }
172
173 if [gdb_test "tfind 9" \
174 "#0 func9 .*" \
175 "find frame nine, pass 3"] then { return 1; }
176
177 if [gdb_test "tfind none" \
178 "#0 end .*" \
179 "quit trace debugging, pass 3"] then { return 1; }
180
181 return 0;
182}
183
184# Start with a fresh gdb.
185
186gdb_exit
187gdb_start
188gdb_reinitialize_dir $srcdir/$subdir
189gdb_load $binfile
190
e68d8fd4
MS
191gdb_test_no_output "set circular-trace-buffer on" \
192 "set circular-trace-buffer on"
4daf5ac0
SS
193
194gdb_test "show circular-trace-buffer" "Target's use of circular trace buffer is on." "show circular-trace-buffer (on)"
195
e68d8fd4
MS
196gdb_test_no_output "set circular-trace-buffer off" \
197 "set circular-trace-buffer off"
4daf5ac0
SS
198
199gdb_test "show circular-trace-buffer" "Target's use of circular trace buffer is off." "show circular-trace-buffer (off)"
200
c906108c
SS
201# Body of test encased in a proc so we can return prematurely.
202if { ![gdb_trace_circular_tests] } then {
203 # Set trace buffer attributes back to normal
204 trace_buffer_normal;
205}
206
207# Finished!
de7ff789 208gdb_test "tfind none" ".*" ""
This page took 1.166823 seconds and 4 git commands to generate.