]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/lib/trace-support.exp
gdb/testsuite/
[thirdparty/binutils-gdb.git] / gdb / testsuite / lib / trace-support.exp
CommitLineData
8acc9f48 1# Copyright (C) 1998-2013 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
16
17#
18# Support procedures for trace testing
19#
20
21
22#
23# Procedure: gdb_target_supports_trace
24# Returns true if GDB is connected to a target that supports tracing.
25# Allows tests to abort early if not running on a trace-aware target.
26#
27
28proc gdb_target_supports_trace { } {
29 global gdb_prompt
30
31 send_gdb "tstatus\n"
32 gdb_expect {
33 -re "\[Tt\]race can only be run on.*$gdb_prompt $" {
34 return 0
35 }
36 -re "\[Tt\]race can not be run on.*$gdb_prompt $" {
37 return 0
38 }
39 -re "\[Tt\]arget does not support.*$gdb_prompt $" {
40 return 0
41 }
42 -re ".*\[Ee\]rror.*$gdb_prompt $" {
43 return 0
44 }
45 -re ".*\[Ww\]arning.*$gdb_prompt $" {
46 return 0
47 }
48 -re ".*$gdb_prompt $" {
49 return 1
50 }
51 timeout {
52 return 0
53 }
54 }
55}
56
57
58#
59# Procedure: gdb_delete_tracepoints
60# Many of the tests depend on setting tracepoints at various places and
61# running until that tracepoint is reached. At times, we want to start
62# with a clean slate with respect to tracepoints, so this utility proc
63# lets us do this without duplicating this code everywhere.
64#
65
66proc gdb_delete_tracepoints {} {
67 global gdb_prompt
68
69 send_gdb "delete tracepoints\n"
70 gdb_expect 30 {
71 -re "Delete all tracepoints.*y or n.*$" {
72 send_gdb "y\n";
73 exp_continue
74 }
75 -re ".*$gdb_prompt $" { # This happens if there were no tracepoints }
76 timeout {
77 perror "Delete all tracepoints in delete_tracepoints (timeout)"
78 return
79 }
80 }
81 send_gdb "info tracepoints\n"
82 gdb_expect 30 {
83 -re "No tracepoints.*$gdb_prompt $" {}
84 -re "$gdb_prompt $" { perror "tracepoints not deleted" ; return }
85 timeout { perror "info tracepoints (timeout)" ; return }
86 }
87}
88
89#
90# Procedure: gdb_trace_setactions
91# Define actions for a tracepoint.
92# Arguments:
93# testname -- identifying string for pass/fail output
94# tracepoint -- to which tracepoint do these actions apply? (optional)
95# args -- list of actions to be defined.
96# Returns:
97# zero -- success
98# non-zero -- failure
99
100proc gdb_trace_setactions { testname tracepoint args } {
101 global gdb_prompt;
102
103 set state 0;
104 set passfail "pass";
105 send_gdb "actions $tracepoint\n";
106 set expected_result "";
107 gdb_expect 5 {
108 -re "No tracepoint number .*$gdb_prompt $" {
109 fail $testname
ae59b1da 110 return 1
c906108c
SS
111 }
112 -re "Enter actions for tracepoint $tracepoint.*>" {
113 if { [llength $args] > 0 } {
114 set lastcommand "[lindex $args $state]";
115 send_gdb "[lindex $args $state]\n";
116 incr state;
117 set expected_result [lindex $args $state];
118 incr state;
119 } else {
120 send_gdb "end\n";
121 }
122 exp_continue;
123 }
a7bdde9e 124 -re "\(.*\)\[\r\n\]+\[ \t]*>$" {
c906108c
SS
125 if { $expected_result != "" } {
126 regsub "^\[^\r\n\]+\[\r\n\]+" "$expect_out(1,string)" "" out;
127 if ![regexp $expected_result $out] {
128 set passfail "fail";
129 }
130 set expected_result "";
131 }
132 if { $state < [llength $args] } {
133 send_gdb "[lindex $args $state]\n";
134 incr state;
135 set expected_result [lindex $args $state];
136 incr state;
137 } else {
138 send_gdb "end\n";
139 set expected_result "";
140 }
141 exp_continue;
142 }
143 -re "\(.*\)$gdb_prompt $" {
144 if { $expected_result != "" } {
145 if ![regexp $expected_result $expect_out(1,string)] {
146 set passfail "fail";
147 }
148 set expected_result "";
149 }
150 if { [llength $args] < $state } {
151 set passfail "fail";
152 }
153 }
154 default {
155 set passfail "fail";
156 }
157 }
158 if { $testname != "" } {
159 $passfail $testname;
160 }
161 if { $passfail == "pass" } then {
ae59b1da 162 return 0
c906108c 163 } else {
ae59b1da 164 return 1
c906108c
SS
165 }
166}
167
168#
169# Procedure: gdb_tfind_test
170# Find a specified trace frame.
171# Arguments:
172# testname -- identifying string for pass/fail output
173# tfind_arg -- frame (line, PC, etc.) identifier
174# exp_res -- Expected result of frame test
175# args -- Test expression
176# Returns:
177# zero -- success
178# non-zero -- failure
179#
180
181proc gdb_tfind_test { testname tfind_arg exp_res args } {
182 global gdb_prompt;
183
184 if { "$args" != "" } {
185 set expr "$exp_res";
186 set exp_res "$args";
187 } else {
188 set expr "(int) \$trace_frame";
189 }
190 set passfail "fail";
191
192 gdb_test "tfind $tfind_arg" "" ""
193 send_gdb "printf \"x \%d x\\n\", $expr\n";
194 gdb_expect 10 {
195 -re "x (-*\[0-9\]+) x" {
196 if { $expect_out(1,string) == $exp_res } {
197 set passfail "pass";
198 }
199 exp_continue;
200 }
201 -re "$gdb_prompt $" { }
202 }
203 $passfail "$testname";
204 if { $passfail == "pass" } then {
ae59b1da 205 return 0
c906108c 206 } else {
ae59b1da 207 return 1
c906108c
SS
208 }
209}
210
211#
212# Procedure: gdb_readexpr
213# Arguments:
214# gdb_expr -- the expression whose value is desired
215# Returns:
216# the value of gdb_expr, as evaluated by gdb.
217# [FIXME: returns -1 on error, which is sometimes a legit value]
218#
219
220proc gdb_readexpr { gdb_expr } {
221 global gdb_prompt;
222
223 set result -1;
224 send_gdb "print $gdb_expr\n"
225 gdb_expect 5 {
226 -re "\[$\].*= (\[0-9\]+).*$gdb_prompt $" {
227 set result $expect_out(1,string);
228 }
229 -re "$gdb_prompt $" { }
230 default { }
231 }
ae59b1da 232 return $result
c906108c
SS
233}
234
235#
236# Procedure: gdb_gettpnum
237# Arguments:
238# tracepoint (optional): if supplied, set a tracepoint here.
239# Returns:
240# the tracepoint ID of the most recently set tracepoint.
241#
242
243proc gdb_gettpnum { tracepoint } {
244 global gdb_prompt;
245
246 if { $tracepoint != "" } {
247 gdb_test "trace $tracepoint" "" ""
248 }
ae59b1da 249 return [gdb_readexpr "\$tpnum"]
c906108c
SS
250}
251
252
253#
254# Procedure: gdb_find_function_baseline
255# Arguments:
256# func_name -- name of source function
257# Returns:
258# Sourcefile line of function definition (open curly brace),
259# or -1 on failure. Caller must check return value.
260# Note:
261# Works only for open curly brace at beginning of source line!
262#
263
264proc gdb_find_function_baseline { func_name } {
265 global gdb_prompt;
266
267 set baseline -1;
268
269 send_gdb "list $func_name\n"
270# gdb_expect {
271# -re "\[\r\n\]\[\{\].*$gdb_prompt $" {
272# set baseline 1
273# }
274# }
275}
276
277#
278# Procedure: gdb_find_function_baseline
279# Arguments:
280# filename: name of source file of desired function.
281# Returns:
282# Sourcefile line of function definition (open curly brace),
283# or -1 on failure. Caller must check return value.
284# Note:
285# Works only for open curly brace at beginning of source line!
286#
287
288proc gdb_find_recursion_test_baseline { filename } {
289 global gdb_prompt;
290
291 set baseline -1;
292
293 gdb_test "list $filename:1" "" ""
294 send_gdb "search gdb_recursion_test line 0\n"
295 gdb_expect {
296 -re "(\[0-9\]+)\[\t \]+\{.*line 0.*$gdb_prompt $" {
297 set baseline $expect_out(1,string);
298 }
299 -re "$gdb_prompt $" { }
300 default { }
301 }
ae59b1da 302 return $baseline
c906108c 303}
c0d4d1c0
YQ
304
305# Return the location of the IPA library.
306
307proc get_in_proc_agent {} {
308 global objdir
309
310 if [target_info exists in_proc_agent] {
311 return [target_info in_proc_agent]
312 } else {
313 return $objdir/../gdbserver/libinproctrace.so
314 }
315}