aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.trace/circ.exp
blob: 13dfdb0d0e47e3b2a87488c2adbc93a1609152ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# Copyright 1998, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

load_lib "trace-support.exp"

if $tracelevel then {
	strace $tracelevel
}


set testfile "circ"
set srcfile ${testfile}.c
set binfile $objdir/$subdir/$testfile

if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
	executable {debug nowarnings}] != "" } {
    untested circ.exp
    return -1
}

# Tests:
# 1) Set up a trace experiment that will collect approximately 10 frames,
#    requiring more than 512 but less than 1024 bytes of cache buffer.
#    (most targets should have at least 1024 bytes of cache buffer!)
#    Run and confirm that it collects all 10 frames.
# 2) Artificially limit the trace buffer to 512 bytes, and rerun the
#    experiment.  Confirm that the first several frames are collected,
#    but that the last several are not.
# 3) Set trace buffer to circular mode, still with the artificial limit
#    of 512 bytes, and rerun the experiment.  Confirm that the last 
#    several frames are collected, but the first several are not.
#

# return 0 for success, 1 for failure
proc run_trace_experiment { pass } {
    gdb_run_cmd 

    if [gdb_test "tstart" \
	    "\[\r\n\]*" \
	    "start trace experiment, pass $pass"] then { return 1; }
    if [gdb_test "continue" \
	    "Continuing.*Breakpoint \[0-9\]+, end.*" \
	    "run to end, pass $pass"] then { return 1; }
    if [gdb_test "tstop" \
	    "\[\r\n\]*" \
	    "stop trace experiment, pass $pass"] then { return 1; }
    return 0;
}

# return 0 for success, 1 for failure
proc set_a_tracepoint { func } {
    if [gdb_test "trace $func" \
	    "Tracepoint \[0-9\]+ at .*" \
	    "set tracepoint at $func"] then {
	return 1;
    }
    if [gdb_trace_setactions "set actions for $func" \
	    "" \
	    "collect testload" "^$"] then {
	return 1;
    }
    return 0;
}

# return 0 for success, 1 for failure
proc setup_tracepoints { } {
    gdb_delete_tracepoints
    if [set_a_tracepoint func0] then { return 1; }
    if [set_a_tracepoint func1] then { return 1; }
    if [set_a_tracepoint func2] then { return 1; }
    if [set_a_tracepoint func3] then { return 1; }
    if [set_a_tracepoint func4] then { return 1; }
    if [set_a_tracepoint func5] then { return 1; }
    if [set_a_tracepoint func6] then { return 1; }
    if [set_a_tracepoint func7] then { return 1; }
    if [set_a_tracepoint func8] then { return 1; }
    if [set_a_tracepoint func9] then { return 1; }
    return 0;
}

# return 0 for success, 1 for failure
proc trace_buffer_normal { } {
    if [gdb_test "maint packet QTBuffer:size:ffffffff" \
	    "received: .OK." ""] then { 
	pass "This test cannot be run on this target"
	return 1;
    }
    if [gdb_test "maint packet QTBuffer:circular:0" \
	    "received: .OK." ""] then { 
	pass "This test cannot be run on this target"
	return 1;
    }
    return 0;
}

# return 0 for success, 1 for failure
proc gdb_trace_circular_tests { } {

    # We generously give ourselves one "pass" if we successfully 
    # detect that this test cannot be run on this target!
    if { ![gdb_target_supports_trace] } then { 
	pass "Current target does not support trace"
	return 1;
    }

    if [trace_buffer_normal] then { return 1; }

    gdb_test "break begin" ".*" ""
    gdb_test "break end"   ".*" ""
    gdb_test "tstop"       ".*" ""
    gdb_test "tfind none"  ".*" ""

    if [setup_tracepoints] then { return 1; }

    # First, run the trace experiment with default attributes:
    # Make sure it behaves as expected.
    if [run_trace_experiment 1] then { return 1; }
    if [gdb_test "tfind start" \
	    "#0  func0 .*" \
	    "find frame zero, pass 1"] then { return 1; }

    if [gdb_test "tfind 9" \
	    "#0  func9 .*" \
	    "find frame nine, pass 1"] then { return 1; }

    if [gdb_test "tfind none" \
	    "#0  end .*" \
	    "quit trace debugging, pass 1"] then { return 1; }

    # Then, shrink the trace buffer so that it will not hold
    # all ten trace frames.  Verify that frame zero is still
    # collected, but frame nine is not.
    if [gdb_test "maint packet QTBuffer:size:200" \
	    "received: .OK." "shrink the target trace buffer"] then { 
	return 1;
    }
    if [run_trace_experiment 2] then { return 1; }
    if [gdb_test "tfind start" \
	    "#0  func0 .*" \
	    "find frame zero, pass 2"] then { return 1; }

    if [gdb_test "tfind 9" \
	    ".* failed to find .*" \
	    "fail to find frame nine, pass 2"] then { return 1; }

    if [gdb_test "tfind none" \
	    "#0  end .*" \
	    "quit trace debugging, pass 2"] then { return 1; }

    # Finally, make the buffer circular.  Now when it runs out of
    # space, it should wrap around and overwrite the earliest frames.
    # This means that:
    #   1) frame zero will be overwritten and therefore unavailable
    #   2) the earliest frame in the buffer will be other-than-zero
    #   3) frame nine will be available (unlike on pass 2).
    if [gdb_test "maint packet QTBuffer:circular:1" \
	    "received: .OK." "make the target trace buffer circular"] then { 
	return 1;
    }
    if [run_trace_experiment 3] then { return 1; }
    if [gdb_test "tfind start" \
	    "#0  func\[1-9\] .*" \
	    "first frame is NOT frame zero, pass 3"] then { return 1; }

    if [gdb_test "tfind 9" \
	    "#0  func9 .*" \
	    "find frame nine, pass 3"] then { return 1; }

    if [gdb_test "tfind none" \
	    "#0  end .*" \
	    "quit trace debugging, pass 3"] then { return 1; }

    return 0;
}

# Start with a fresh gdb.

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load $binfile
 
gdb_test_no_output "set circular-trace-buffer on" \
    "set circular-trace-buffer on"

gdb_test "show circular-trace-buffer" "Target's use of circular trace buffer is on." "show circular-trace-buffer (on)"

gdb_test_no_output "set circular-trace-buffer off" \
    "set circular-trace-buffer off"

gdb_test "show circular-trace-buffer" "Target's use of circular trace buffer is off." "show circular-trace-buffer (off)"

# Body of test encased in a proc so we can return prematurely.
if { ![gdb_trace_circular_tests] } then {
    # Set trace buffer attributes back to normal
    trace_buffer_normal;
}

# Finished!
gdb_test "tfind none" ".*" ""