]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.trace/circ.exp
2012-02-15 Pedro Alves <palves@redhat.com>
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.trace / circ.exp
1 # Copyright 1998, 2007-2012 Free Software Foundation, Inc.
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
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
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.
12 #
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/>.
15
16 load_lib "trace-support.exp"
17
18
19 set testfile "circ"
20 set srcfile ${testfile}.c
21 set binfile $objdir/$subdir/$testfile
22
23 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
24 executable {debug nowarnings}] != "" } {
25 untested circ.exp
26 return -1
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
43 proc 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
59 proc 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
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; }
86 return 0;
87 }
88
89 # return 0 for success, 1 for failure
90 proc trace_buffer_normal { } {
91 global gdb_prompt
92
93 set ok 0
94 set test "maint packet QTBuffer:size:ffffffff"
95 gdb_test_multiple $test $test {
96 -re "received: .OK.\r\n$gdb_prompt $" {
97 set ok 1
98 pass $test
99 }
100 -re "\r\n$gdb_prompt $" {
101 }
102 }
103 if { !$ok } {
104 unsupported $test
105 return 1;
106 }
107
108 set ok 0
109 set test "maint packet QTBuffer:circular:0"
110 gdb_test_multiple $test $test {
111 -re "received: .OK.\r\n$gdb_prompt $" {
112 set ok 1
113 pass $test
114 }
115 -re "\r\n$gdb_prompt $" {
116 }
117 }
118 if { !$ok } {
119 unsupported $test
120 return 1;
121 }
122
123 return 0;
124 }
125
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"
130 return 1;
131 }
132
133 if [trace_buffer_normal] then { return 1; }
134
135 gdb_test "break begin" ".*" ""
136 gdb_test "break end" ".*" ""
137 gdb_test "tstop" ".*" ""
138 gdb_test "tfind none" ".*" ""
139
140 if [setup_tracepoints] then { return 1; }
141
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" \
146 "#0 func0 .*" \
147 "find frame zero, pass 1"] then { return 1; }
148
149 if [gdb_test "tfind 9" \
150 "#0 func9 .*" \
151 "find frame nine, pass 1"] then { return 1; }
152
153 if [gdb_test "tfind none" \
154 "#0 end .*" \
155 "quit trace debugging, pass 1"] then { return 1; }
156
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 {
162 return 1;
163 }
164 if [run_trace_experiment 2] then { return 1; }
165 if [gdb_test "tfind start" \
166 "#0 func0 .*" \
167 "find frame zero, pass 2"] then { return 1; }
168
169 if [gdb_test "tfind 9" \
170 ".* failed to find .*" \
171 "fail to find frame nine, pass 2"] then { return 1; }
172
173 if [gdb_test "tfind none" \
174 "#0 end .*" \
175 "quit trace debugging, pass 2"] then { return 1; }
176
177 # Finally, make the buffer circular. Now when it runs out of
178 # space, it should wrap around and overwrite the earliest frames.
179 # This means that:
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 {
185 return 1;
186 }
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; }
191
192 if [gdb_test "tfind 9" \
193 "#0 func9 .*" \
194 "find frame nine, pass 3"] then { return 1; }
195
196 if [gdb_test "tfind none" \
197 "#0 end .*" \
198 "quit trace debugging, pass 3"] then { return 1; }
199
200 return 0;
201 }
202
203 # Start with a fresh gdb.
204
205 gdb_exit
206 gdb_start
207 gdb_reinitialize_dir $srcdir/$subdir
208 gdb_load $binfile
209
210 gdb_test_no_output "set circular-trace-buffer on" \
211 "set circular-trace-buffer on"
212
213 gdb_test "show circular-trace-buffer" "Target's use of circular trace buffer is on." "show circular-trace-buffer (on)"
214
215 gdb_test_no_output "set circular-trace-buffer off" \
216 "set circular-trace-buffer off"
217
218 gdb_test "show circular-trace-buffer" "Target's use of circular trace buffer is off." "show circular-trace-buffer (off)"
219
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
223 trace_buffer_normal;
224 }
225
226 # Finished!
227 gdb_test "tfind none" ".*" ""