1 # Copyright (C) 1998-2015 Free Software Foundation, Inc.
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.
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.
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/>.
18 # Support procedures for trace testing
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.
28 proc gdb_target_supports_trace { } {
33 -re "\[Tt\]race can only be run on.*$gdb_prompt $" {
36 -re "\[Tt\]race can not be run on.*$gdb_prompt $" {
39 -re "\[Tt\]arget does not support.*$gdb_prompt $" {
42 -re ".*\[Ee\]rror.*$gdb_prompt $" {
45 -re ".*\[Ww\]arning.*$gdb_prompt $" {
48 -re ".*$gdb_prompt $" {
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.
66 proc gdb_delete_tracepoints {} {
69 send_gdb "delete tracepoints\n"
71 -re "Delete all tracepoints.*y or n.*$" {
75 -re ".*$gdb_prompt $" { # This happens if there were no tracepoints }
77 perror "Delete all tracepoints in delete_tracepoints (timeout)"
81 send_gdb "info tracepoints\n"
83 -re "No tracepoints.*$gdb_prompt $" {}
84 -re "$gdb_prompt $" { perror "tracepoints not deleted" ; return }
85 timeout { perror "info tracepoints (timeout)" ; return }
89 # Define actions for a tracepoint.
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.
100 proc gdb_trace_setactions_command { actions_command testname tracepoint args } {
105 send_gdb "$actions_command $tracepoint\n"
106 set expected_result ""
108 -re "No tracepoint number .*$gdb_prompt $" {
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"
117 set expected_result [lindex $args $state]
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] {
130 set expected_result ""
132 if { $state < [llength $args] } {
133 send_gdb "[lindex $args $state]\n"
135 set expected_result [lindex $args $state]
139 set expected_result ""
143 -re "\(.*\)$gdb_prompt $" {
144 if { $expected_result != "" } {
145 if ![regexp $expected_result $expect_out(1,string)] {
148 set expected_result ""
150 if { [llength $args] < $state } {
158 if { $testname != "" } {
161 if { $passfail == "pass" } then {
168 # Define actions for a tracepoint, using the "actions" command. See
169 # gdb_trace_setactions_command.
171 proc gdb_trace_setactions { testname tracepoint args } {
172 eval gdb_trace_setactions_command "actions" {$testname} {$tracepoint} $args
175 # Define actions for a tracepoint, using the "commands" command. See
176 # gdb_trace_setactions_command.
178 proc gdb_trace_setcommands { testname tracepoint args } {
179 eval gdb_trace_setactions_command "commands" {$testname} {$tracepoint} $args
183 # Procedure: gdb_tfind_test
184 # Find a specified trace frame.
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
192 # non-zero -- failure
195 proc gdb_tfind_test { testname tfind_arg exp_res args } {
198 if { "$args" != "" } {
202 set expr "(int) \$trace_frame"
206 gdb_test "tfind $tfind_arg" "" ""
207 send_gdb "printf \"x \%d x\\n\", $expr\n"
209 -re "x (-*\[0-9\]+) x" {
210 if { $expect_out(1,string) == $exp_res } {
215 -re "$gdb_prompt $" { }
217 $passfail "$testname"
218 if { $passfail == "pass" } then {
226 # Procedure: gdb_readexpr
228 # gdb_expr -- the expression whose value is desired
230 # the value of gdb_expr, as evaluated by gdb.
231 # [FIXME: returns -1 on error, which is sometimes a legit value]
234 proc gdb_readexpr { gdb_expr } {
238 send_gdb "print $gdb_expr\n"
240 -re "\[$\].*= (\[0-9\]+).*$gdb_prompt $" {
241 set result $expect_out(1,string)
243 -re "$gdb_prompt $" { }
250 # Procedure: gdb_gettpnum
252 # tracepoint (optional): if supplied, set a tracepoint here.
254 # the tracepoint ID of the most recently set tracepoint.
257 proc gdb_gettpnum { tracepoint } {
260 if { $tracepoint != "" } {
261 gdb_test "trace $tracepoint" "" ""
263 return [gdb_readexpr "\$tpnum"]
268 # Procedure: gdb_find_function_baseline
270 # func_name -- name of source function
272 # Sourcefile line of function definition (open curly brace),
273 # or -1 on failure. Caller must check return value.
275 # Works only for open curly brace at beginning of source line!
278 proc gdb_find_function_baseline { func_name } {
283 send_gdb "list $func_name\n"
285 # -re "\[\r\n\]\[\{\].*$gdb_prompt $" {
292 # Procedure: gdb_find_function_baseline
294 # filename: name of source file of desired function.
296 # Sourcefile line of function definition (open curly brace),
297 # or -1 on failure. Caller must check return value.
299 # Works only for open curly brace at beginning of source line!
302 proc gdb_find_recursion_test_baseline { filename } {
307 gdb_test "list $filename:1" "" ""
308 send_gdb "search gdb_recursion_test line 0\n"
310 -re "(\[0-9\]+)\[\t \]+\{.*line 0.*$gdb_prompt $" {
311 set baseline $expect_out(1,string)
313 -re "$gdb_prompt $" { }
319 # Return the location of the IPA library.
321 proc get_in_proc_agent {} {
324 if [target_info exists in_proc_agent] {
325 return [target_info in_proc_agent]
327 return $objdir/../gdbserver/libinproctrace.so
331 # Execute BINFILE on target to generate tracefile. Return 1 if
332 # tracefile is generated successfully, return 0 otherwise.
334 proc generate_tracefile { binfile } {
335 set status [remote_exec target "$binfile"]
337 if { [lindex $status 0] != 0 } {
338 # Failed to execute $binfile, for example on bare metal targets.
339 # Alternatively, load the binary and run it. If target doesn't
340 # have fileio capabilities, tracefile can't be generated. Skip
342 if [target_info exists gdb,nofileio] {
346 clean_restart $binfile
348 if ![runto_main] then {
351 gdb_continue_to_end "" continue 1