gdb/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.trace / circ.exp
CommitLineData
0fb0cc75 1# Copyright 1998, 2007, 2008, 2009 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
16if [istarget "m68k-*-elf"] then {
17 pass "Test not supported on this target"
18 return;
19}
20
21load_lib "trace-support.exp"
22
23if $tracelevel then {
24 strace $tracelevel
25}
26
27set prms_id 0
28set bug_id 0
29
30set testfile "circ"
31set srcfile ${testfile}.c
32set binfile $objdir/$subdir/$testfile
33
34if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
fc91c6c2 35 executable {debug nowarnings}] != "" } {
b60f0898
JB
36 untested circ.exp
37 return -1
c906108c
SS
38}
39
40# Tests:
41# 1) Set up a trace experiment that will collect approximately 10 frames,
42# requiring more than 512 but less than 1024 bytes of cache buffer.
43# (most targets should have at least 1024 bytes of cache buffer!)
44# Run and confirm that it collects all 10 frames.
45# 2) Artificially limit the trace buffer to 512 bytes, and rerun the
46# experiment. Confirm that the first several frames are collected,
47# but that the last several are not.
48# 3) Set trace buffer to circular mode, still with the artificial limit
49# of 512 bytes, and rerun the experiment. Confirm that the last
50# several frames are collected, but the first several are not.
51#
52
53# return 0 for success, 1 for failure
54proc run_trace_experiment { pass } {
55 gdb_run_cmd
56
57 if [gdb_test "tstart" \
58 "\[\r\n\]*" \
59 "start trace experiment, pass $pass"] then { return 1; }
60 if [gdb_test "continue" \
61 "Continuing.*Breakpoint \[0-9\]+, end.*" \
62 "run to end, pass $pass"] then { return 1; }
63 if [gdb_test "tstop" \
64 "\[\r\n\]*" \
65 "stop trace experiment, pass $pass"] then { return 1; }
66 return 0;
67}
68
69# return 0 for success, 1 for failure
70proc set_a_tracepoint { func } {
71 if [gdb_test "trace $func" \
72 "Tracepoint \[0-9\]+ at .*" \
73 "set tracepoint at $func"] then {
74 return 1;
75 }
76 if [gdb_trace_setactions "set actions for $func" \
77 "" \
78 "collect testload" "^$"] then {
79 return 1;
80 }
81 return 0;
82}
83
84# return 0 for success, 1 for failure
85proc setup_tracepoints { } {
86 gdb_delete_tracepoints
87 if [set_a_tracepoint func0] then { return 1; }
88 if [set_a_tracepoint func1] then { return 1; }
89 if [set_a_tracepoint func2] then { return 1; }
90 if [set_a_tracepoint func3] then { return 1; }
91 if [set_a_tracepoint func4] then { return 1; }
92 if [set_a_tracepoint func5] then { return 1; }
93 if [set_a_tracepoint func6] then { return 1; }
94 if [set_a_tracepoint func7] then { return 1; }
95 if [set_a_tracepoint func8] then { return 1; }
96 if [set_a_tracepoint func9] then { return 1; }
97 return 0;
98}
99
100# return 0 for success, 1 for failure
101proc trace_buffer_normal { } {
102 if [gdb_test "maint packet QTBuffer:size:ffffffff" \
103 "received: .OK." ""] then {
104 pass "This test cannot be run on this target"
105 return 1;
106 }
107 if [gdb_test "maint packet QTBuffer:circular:0" \
108 "received: .OK." ""] then {
109 pass "This test cannot be run on this target"
110 return 1;
111 }
112 return 0;
113}
114
115# return 0 for success, 1 for failure
116proc gdb_trace_circular_tests { } {
117
118 # We generously give ourselves one "pass" if we successfully
119 # detect that this test cannot be run on this target!
120 if { ![gdb_target_supports_trace] } then {
0ef2251b 121 pass "Current target does not support trace"
c906108c
SS
122 return 1;
123 }
124
125 if [trace_buffer_normal] then { return 1; }
126
127 gdb_test "break begin" "" ""
128 gdb_test "break end" "" ""
129 gdb_test "tstop" "" ""
130 gdb_test "tfind none" "" ""
131
132 if [setup_tracepoints] then { return 1; }
133
134 # First, run the trace experiment with default attributes:
135 # Make sure it behaves as expected.
136 if [run_trace_experiment 1] then { return 1; }
137 if [gdb_test "tfind start" \
138 "#0 func0 .*" \
139 "find frame zero, pass 1"] then { return 1; }
140
141 if [gdb_test "tfind 9" \
142 "#0 func9 .*" \
143 "find frame nine, pass 1"] then { return 1; }
144
145 if [gdb_test "tfind none" \
146 "#0 end .*" \
147 "quit trace debugging, pass 1"] then { return 1; }
148
149 # Then, shrink the trace buffer so that it will not hold
150 # all ten trace frames. Verify that frame zero is still
151 # collected, but frame nine is not.
152 if [gdb_test "maint packet QTBuffer:size:200" \
153 "received: .OK." "shrink the target trace buffer"] then {
154 return 1;
155 }
156 if [run_trace_experiment 2] then { return 1; }
157 if [gdb_test "tfind start" \
158 "#0 func0 .*" \
159 "find frame zero, pass 2"] then { return 1; }
160
161 if [gdb_test "tfind 9" \
162 ".* failed to find .*" \
163 "fail to find frame nine, pass 2"] then { return 1; }
164
165 if [gdb_test "tfind none" \
166 "#0 end .*" \
167 "quit trace debugging, pass 2"] then { return 1; }
168
169 # Finally, make the buffer circular. Now when it runs out of
170 # space, it should wrap around and overwrite the earliest frames.
171 # This means that:
172 # 1) frame zero will be overwritten and therefore unavailable
173 # 2) the earliest frame in the buffer will be other-than-zero
174 # 3) frame nine will be available (unlike on pass 2).
175 if [gdb_test "maint packet QTBuffer:circular:1" \
176 "received: .OK." "make the target trace buffer circular"] then {
177 return 1;
178 }
179 if [run_trace_experiment 3] then { return 1; }
180 if [gdb_test "tfind start" \
181 "#0 func\[1-9\] .*" \
182 "first frame is NOT frame zero, pass 3"] then { return 1; }
183
184 if [gdb_test "tfind 9" \
185 "#0 func9 .*" \
186 "find frame nine, pass 3"] then { return 1; }
187
188 if [gdb_test "tfind none" \
189 "#0 end .*" \
190 "quit trace debugging, pass 3"] then { return 1; }
191
192 return 0;
193}
194
195# Start with a fresh gdb.
196
197gdb_exit
198gdb_start
199gdb_reinitialize_dir $srcdir/$subdir
200gdb_load $binfile
201
202if [target_info exists gdb_stub] {
203 gdb_step_for_stub;
204}
205# Body of test encased in a proc so we can return prematurely.
206if { ![gdb_trace_circular_tests] } then {
207 # Set trace buffer attributes back to normal
208 trace_buffer_normal;
209}
210
211# Finished!
212gdb_test "tfind none" "" ""
This page took 0.848192 seconds and 4 git commands to generate.