gdb/testsuite/gdb.trace: Deduplicate pcreg/spreg/fpreg.
[deliverable/binutils-gdb.git] / gdb / testsuite / lib / trace-support.exp
1 # Copyright (C) 1998-2015 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 # Program counter / stack pointer / frame pointer for supported targets.
24 # Used in many tests, kept here to avoid duplication.
25 #
26
27 if [is_amd64_regs_target] {
28 set fpreg "rbp"
29 set spreg "rsp"
30 set pcreg "rip"
31 } elseif [is_x86_like_target] {
32 set fpreg "ebp"
33 set spreg "esp"
34 set pcreg "eip"
35 } elseif [is_aarch64_target] {
36 set fpreg "x29"
37 set spreg "sp"
38 set pcreg "pc"
39 } else {
40 set fpreg "fp"
41 set spreg "sp"
42 set pcreg "pc"
43 }
44
45 #
46 # Procedure: gdb_target_supports_trace
47 # Returns true if GDB is connected to a target that supports tracing.
48 # Allows tests to abort early if not running on a trace-aware target.
49 #
50
51 proc gdb_target_supports_trace { } {
52 global gdb_prompt
53
54 send_gdb "tstatus\n"
55 gdb_expect {
56 -re "\[Tt\]race can only be run on.*$gdb_prompt $" {
57 return 0
58 }
59 -re "\[Tt\]race can not be run on.*$gdb_prompt $" {
60 return 0
61 }
62 -re "\[Tt\]arget does not support.*$gdb_prompt $" {
63 return 0
64 }
65 -re ".*\[Ee\]rror.*$gdb_prompt $" {
66 return 0
67 }
68 -re ".*\[Ww\]arning.*$gdb_prompt $" {
69 return 0
70 }
71 -re ".*$gdb_prompt $" {
72 return 1
73 }
74 timeout {
75 return 0
76 }
77 }
78 }
79
80
81 #
82 # Procedure: gdb_delete_tracepoints
83 # Many of the tests depend on setting tracepoints at various places and
84 # running until that tracepoint is reached. At times, we want to start
85 # with a clean slate with respect to tracepoints, so this utility proc
86 # lets us do this without duplicating this code everywhere.
87 #
88
89 proc gdb_delete_tracepoints {} {
90 global gdb_prompt
91
92 send_gdb "delete tracepoints\n"
93 gdb_expect 30 {
94 -re "Delete all tracepoints.*y or n.*$" {
95 send_gdb "y\n"
96 exp_continue
97 }
98 -re ".*$gdb_prompt $" { # This happens if there were no tracepoints }
99 timeout {
100 perror "Delete all tracepoints in delete_tracepoints (timeout)"
101 return
102 }
103 }
104 send_gdb "info tracepoints\n"
105 gdb_expect 30 {
106 -re "No tracepoints.*$gdb_prompt $" {}
107 -re "$gdb_prompt $" { perror "tracepoints not deleted" ; return }
108 timeout { perror "info tracepoints (timeout)" ; return }
109 }
110 }
111
112 # Define actions for a tracepoint.
113 # Arguments:
114 # actions_command -- the command used to create the actions.
115 # either "actions" or "commands".
116 # testname -- identifying string for pass/fail output
117 # tracepoint -- to which tracepoint(s) do these actions apply? (optional)
118 # args -- list of actions to be defined.
119 # Returns:
120 # zero -- success
121 # non-zero -- failure
122
123 proc gdb_trace_setactions_command { actions_command testname tracepoint args } {
124 global gdb_prompt
125
126 set state 0
127 set passfail "pass"
128 send_gdb "$actions_command $tracepoint\n"
129 set expected_result ""
130 gdb_expect 5 {
131 -re "No tracepoint number .*$gdb_prompt $" {
132 fail $testname
133 return 1
134 }
135 -re "Enter actions for tracepoint $tracepoint.*>" {
136 if { [llength $args] > 0 } {
137 set lastcommand "[lindex $args $state]"
138 send_gdb "[lindex $args $state]\n"
139 incr state
140 set expected_result [lindex $args $state]
141 incr state
142 } else {
143 send_gdb "end\n"
144 }
145 exp_continue
146 }
147 -re "\(.*\)\[\r\n\]+\[ \t]*>$" {
148 if { $expected_result != "" } {
149 regsub "^\[^\r\n\]+\[\r\n\]+" "$expect_out(1,string)" "" out
150 if ![regexp $expected_result $out] {
151 set passfail "fail"
152 }
153 set expected_result ""
154 }
155 if { $state < [llength $args] } {
156 send_gdb "[lindex $args $state]\n"
157 incr state
158 set expected_result [lindex $args $state]
159 incr state
160 } else {
161 send_gdb "end\n"
162 set expected_result ""
163 }
164 exp_continue
165 }
166 -re "\(.*\)$gdb_prompt $" {
167 if { $expected_result != "" } {
168 if ![regexp $expected_result $expect_out(1,string)] {
169 set passfail "fail"
170 }
171 set expected_result ""
172 }
173 if { [llength $args] < $state } {
174 set passfail "fail"
175 }
176 }
177 default {
178 set passfail "fail"
179 }
180 }
181 if { $testname != "" } {
182 $passfail $testname
183 }
184 if { $passfail == "pass" } then {
185 return 0
186 } else {
187 return 1
188 }
189 }
190
191 # Define actions for a tracepoint, using the "actions" command. See
192 # gdb_trace_setactions_command.
193 #
194 proc gdb_trace_setactions { testname tracepoint args } {
195 eval gdb_trace_setactions_command "actions" {$testname} {$tracepoint} $args
196 }
197
198 # Define actions for a tracepoint, using the "commands" command. See
199 # gdb_trace_setactions_command.
200 #
201 proc gdb_trace_setcommands { testname tracepoint args } {
202 eval gdb_trace_setactions_command "commands" {$testname} {$tracepoint} $args
203 }
204
205 #
206 # Procedure: gdb_tfind_test
207 # Find a specified trace frame.
208 # Arguments:
209 # testname -- identifying string for pass/fail output
210 # tfind_arg -- frame (line, PC, etc.) identifier
211 # exp_res -- Expected result of frame test
212 # args -- Test expression
213 # Returns:
214 # zero -- success
215 # non-zero -- failure
216 #
217
218 proc gdb_tfind_test { testname tfind_arg exp_res args } {
219 global gdb_prompt
220
221 if { "$args" != "" } {
222 set expr "$exp_res"
223 set exp_res "$args"
224 } else {
225 set expr "(int) \$trace_frame"
226 }
227 set passfail "fail"
228
229 gdb_test "tfind $tfind_arg" "" ""
230 send_gdb "printf \"x \%d x\\n\", $expr\n"
231 gdb_expect 10 {
232 -re "x (-*\[0-9\]+) x" {
233 if { $expect_out(1,string) == $exp_res } {
234 set passfail "pass"
235 }
236 exp_continue
237 }
238 -re "$gdb_prompt $" { }
239 }
240 $passfail "$testname"
241 if { $passfail == "pass" } then {
242 return 0
243 } else {
244 return 1
245 }
246 }
247
248 #
249 # Procedure: gdb_readexpr
250 # Arguments:
251 # gdb_expr -- the expression whose value is desired
252 # Returns:
253 # the value of gdb_expr, as evaluated by gdb.
254 # [FIXME: returns -1 on error, which is sometimes a legit value]
255 #
256
257 proc gdb_readexpr { gdb_expr } {
258 global gdb_prompt
259
260 set result -1
261 send_gdb "print $gdb_expr\n"
262 gdb_expect 5 {
263 -re "\[$\].*= (\[0-9\]+).*$gdb_prompt $" {
264 set result $expect_out(1,string)
265 }
266 -re "$gdb_prompt $" { }
267 default { }
268 }
269 return $result
270 }
271
272 #
273 # Procedure: gdb_gettpnum
274 # Arguments:
275 # tracepoint (optional): if supplied, set a tracepoint here.
276 # Returns:
277 # the tracepoint ID of the most recently set tracepoint.
278 #
279
280 proc gdb_gettpnum { tracepoint } {
281 global gdb_prompt
282
283 if { $tracepoint != "" } {
284 gdb_test "trace $tracepoint" "" ""
285 }
286 return [gdb_readexpr "\$tpnum"]
287 }
288
289
290 #
291 # Procedure: gdb_find_function_baseline
292 # Arguments:
293 # func_name -- name of source function
294 # Returns:
295 # Sourcefile line of function definition (open curly brace),
296 # or -1 on failure. Caller must check return value.
297 # Note:
298 # Works only for open curly brace at beginning of source line!
299 #
300
301 proc gdb_find_function_baseline { func_name } {
302 global gdb_prompt
303
304 set baseline -1
305
306 send_gdb "list $func_name\n"
307 # gdb_expect {
308 # -re "\[\r\n\]\[\{\].*$gdb_prompt $" {
309 # set baseline 1
310 # }
311 # }
312 }
313
314 #
315 # Procedure: gdb_find_function_baseline
316 # Arguments:
317 # filename: name of source file of desired function.
318 # Returns:
319 # Sourcefile line of function definition (open curly brace),
320 # or -1 on failure. Caller must check return value.
321 # Note:
322 # Works only for open curly brace at beginning of source line!
323 #
324
325 proc gdb_find_recursion_test_baseline { filename } {
326 global gdb_prompt
327
328 set baseline -1
329
330 gdb_test "list $filename:1" "" ""
331 send_gdb "search gdb_recursion_test line 0\n"
332 gdb_expect {
333 -re "(\[0-9\]+)\[\t \]+\{.*line 0.*$gdb_prompt $" {
334 set baseline $expect_out(1,string)
335 }
336 -re "$gdb_prompt $" { }
337 default { }
338 }
339 return $baseline
340 }
341
342 # Return the location of the IPA library.
343
344 proc get_in_proc_agent {} {
345 global objdir
346
347 if [target_info exists in_proc_agent] {
348 return [target_info in_proc_agent]
349 } else {
350 return $objdir/../gdbserver/libinproctrace.so
351 }
352 }
353
354 # Execute BINFILE on target to generate tracefile. Return 1 if
355 # tracefile is generated successfully, return 0 otherwise.
356
357 proc generate_tracefile { binfile } {
358 set status [remote_exec target "$binfile"]
359
360 if { [lindex $status 0] != 0 } {
361 # Failed to execute $binfile, for example on bare metal targets.
362 # Alternatively, load the binary and run it. If target doesn't
363 # have fileio capabilities, tracefile can't be generated. Skip
364 # the test.
365 if [target_info exists gdb,nofileio] {
366 return 0
367 }
368
369 clean_restart $binfile
370
371 if ![runto_main] then {
372 return 0
373 }
374 gdb_continue_to_end "" continue 1
375 gdb_exit
376 }
377
378 return 1
379 }
This page took 0.038019 seconds and 4 git commands to generate.