]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/lib/trace-support.exp
4ffd01cdb75f5eb4a442193788353ade72d19494
[thirdparty/binutils-gdb.git] / gdb / testsuite / lib / trace-support.exp
1 # Copyright (C) 1998-2013 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
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
28 proc 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
66 proc 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 # Define actions for a tracepoint.
90 # Arguments:
91 # actions_command -- the command used to create the actions.
92 # either "actions" or "commands".
93 # testname -- identifying string for pass/fail output
94 # tracepoint -- to which tracepoint(s) do these actions apply? (optional)
95 # args -- list of actions to be defined.
96 # Returns:
97 # zero -- success
98 # non-zero -- failure
99
100 proc gdb_trace_setactions_command { actions_command testname tracepoint args } {
101 global gdb_prompt
102
103 set state 0
104 set passfail "pass"
105 send_gdb "$actions_command $tracepoint\n"
106 set expected_result ""
107 gdb_expect 5 {
108 -re "No tracepoint number .*$gdb_prompt $" {
109 fail $testname
110 return 1
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 }
124 -re "\(.*\)\[\r\n\]+\[ \t]*>$" {
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 {
162 return 0
163 } else {
164 return 1
165 }
166 }
167
168 # Define actions for a tracepoint, using the "actions" command. See
169 # gdb_trace_setactions_command.
170 #
171 proc gdb_trace_setactions { testname tracepoint args } {
172 eval gdb_trace_setactions_command "actions" {$testname} {$tracepoint} $args
173 }
174
175 # Define actions for a tracepoint, using the "commands" command. See
176 # gdb_trace_setactions_command.
177 #
178 proc gdb_trace_setcommands { testname tracepoint args } {
179 eval gdb_trace_setactions_command "commands" {$testname} {$tracepoint} $args
180 }
181
182 #
183 # Procedure: gdb_tfind_test
184 # Find a specified trace frame.
185 # Arguments:
186 # testname -- identifying string for pass/fail output
187 # tfind_arg -- frame (line, PC, etc.) identifier
188 # exp_res -- Expected result of frame test
189 # args -- Test expression
190 # Returns:
191 # zero -- success
192 # non-zero -- failure
193 #
194
195 proc gdb_tfind_test { testname tfind_arg exp_res args } {
196 global gdb_prompt
197
198 if { "$args" != "" } {
199 set expr "$exp_res"
200 set exp_res "$args"
201 } else {
202 set expr "(int) \$trace_frame"
203 }
204 set passfail "fail"
205
206 gdb_test "tfind $tfind_arg" "" ""
207 send_gdb "printf \"x \%d x\\n\", $expr\n"
208 gdb_expect 10 {
209 -re "x (-*\[0-9\]+) x" {
210 if { $expect_out(1,string) == $exp_res } {
211 set passfail "pass"
212 }
213 exp_continue
214 }
215 -re "$gdb_prompt $" { }
216 }
217 $passfail "$testname"
218 if { $passfail == "pass" } then {
219 return 0
220 } else {
221 return 1
222 }
223 }
224
225 #
226 # Procedure: gdb_readexpr
227 # Arguments:
228 # gdb_expr -- the expression whose value is desired
229 # Returns:
230 # the value of gdb_expr, as evaluated by gdb.
231 # [FIXME: returns -1 on error, which is sometimes a legit value]
232 #
233
234 proc gdb_readexpr { gdb_expr } {
235 global gdb_prompt
236
237 set result -1
238 send_gdb "print $gdb_expr\n"
239 gdb_expect 5 {
240 -re "\[$\].*= (\[0-9\]+).*$gdb_prompt $" {
241 set result $expect_out(1,string)
242 }
243 -re "$gdb_prompt $" { }
244 default { }
245 }
246 return $result
247 }
248
249 #
250 # Procedure: gdb_gettpnum
251 # Arguments:
252 # tracepoint (optional): if supplied, set a tracepoint here.
253 # Returns:
254 # the tracepoint ID of the most recently set tracepoint.
255 #
256
257 proc gdb_gettpnum { tracepoint } {
258 global gdb_prompt
259
260 if { $tracepoint != "" } {
261 gdb_test "trace $tracepoint" "" ""
262 }
263 return [gdb_readexpr "\$tpnum"]
264 }
265
266
267 #
268 # Procedure: gdb_find_function_baseline
269 # Arguments:
270 # func_name -- name of source function
271 # Returns:
272 # Sourcefile line of function definition (open curly brace),
273 # or -1 on failure. Caller must check return value.
274 # Note:
275 # Works only for open curly brace at beginning of source line!
276 #
277
278 proc gdb_find_function_baseline { func_name } {
279 global gdb_prompt
280
281 set baseline -1
282
283 send_gdb "list $func_name\n"
284 # gdb_expect {
285 # -re "\[\r\n\]\[\{\].*$gdb_prompt $" {
286 # set baseline 1
287 # }
288 # }
289 }
290
291 #
292 # Procedure: gdb_find_function_baseline
293 # Arguments:
294 # filename: name of source file of desired function.
295 # Returns:
296 # Sourcefile line of function definition (open curly brace),
297 # or -1 on failure. Caller must check return value.
298 # Note:
299 # Works only for open curly brace at beginning of source line!
300 #
301
302 proc gdb_find_recursion_test_baseline { filename } {
303 global gdb_prompt
304
305 set baseline -1
306
307 gdb_test "list $filename:1" "" ""
308 send_gdb "search gdb_recursion_test line 0\n"
309 gdb_expect {
310 -re "(\[0-9\]+)\[\t \]+\{.*line 0.*$gdb_prompt $" {
311 set baseline $expect_out(1,string)
312 }
313 -re "$gdb_prompt $" { }
314 default { }
315 }
316 return $baseline
317 }
318
319 # Return the location of the IPA library.
320
321 proc get_in_proc_agent {} {
322 global objdir
323
324 if [target_info exists in_proc_agent] {
325 return [target_info in_proc_agent]
326 } else {
327 return $objdir/../gdbserver/libinproctrace.so
328 }
329 }