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