1 # Copyright (C) 1998-2016 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 # Program counter / stack pointer / frame pointer for supported targets.
24 # Used in many tests, kept here to avoid duplication.
27 if [is_amd64_regs_target] {
31 } elseif [is_x86_like_target] {
35 } elseif [is_aarch64_target] {
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.
51 proc gdb_target_supports_trace { } {
56 -re "\[Tt\]race can only be run on.*$gdb_prompt $" {
59 -re "\[Tt\]race can not be run on.*$gdb_prompt $" {
62 -re "\[Tt\]arget does not support.*$gdb_prompt $" {
65 -re ".*\[Ee\]rror.*$gdb_prompt $" {
68 -re ".*\[Ww\]arning.*$gdb_prompt $" {
71 -re ".*$gdb_prompt $" {
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.
89 proc gdb_delete_tracepoints {} {
92 send_gdb "delete tracepoints\n"
94 -re "Delete all tracepoints.*y or n.*$" {
98 -re ".*$gdb_prompt $" { # This happens if there were no tracepoints }
100 perror "Delete all tracepoints in delete_tracepoints (timeout)"
104 send_gdb "info tracepoints\n"
106 -re "No tracepoints.*$gdb_prompt $" {}
107 -re "$gdb_prompt $" { perror "tracepoints not deleted" ; return }
108 timeout { perror "info tracepoints (timeout)" ; return }
112 # Define actions for a tracepoint.
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.
121 # non-zero -- failure
123 proc gdb_trace_setactions_command { actions_command testname tracepoint args } {
128 send_gdb "$actions_command $tracepoint\n"
129 set expected_result ""
131 -re "No tracepoint number .*$gdb_prompt $" {
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"
140 set expected_result [lindex $args $state]
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] {
153 set expected_result ""
155 if { $state < [llength $args] } {
156 send_gdb "[lindex $args $state]\n"
158 set expected_result [lindex $args $state]
162 set expected_result ""
166 -re "\(.*\)$gdb_prompt $" {
167 if { $expected_result != "" } {
168 if ![regexp $expected_result $expect_out(1,string)] {
171 set expected_result ""
173 if { [llength $args] < $state } {
181 if { $testname != "" } {
184 if { $passfail == "pass" } then {
191 # Define actions for a tracepoint, using the "actions" command. See
192 # gdb_trace_setactions_command.
194 proc gdb_trace_setactions { testname tracepoint args } {
195 eval gdb_trace_setactions_command "actions" {$testname} {$tracepoint} $args
198 # Define actions for a tracepoint, using the "commands" command. See
199 # gdb_trace_setactions_command.
201 proc gdb_trace_setcommands { testname tracepoint args } {
202 eval gdb_trace_setactions_command "commands" {$testname} {$tracepoint} $args
206 # Procedure: gdb_tfind_test
207 # Find a specified trace frame.
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
215 # non-zero -- failure
218 proc gdb_tfind_test { testname tfind_arg exp_res args } {
221 if { "$args" != "" } {
225 set expr "(int) \$trace_frame"
229 gdb_test "tfind $tfind_arg" "" ""
230 send_gdb "printf \"x \%d x\\n\", $expr\n"
232 -re "x (-*\[0-9\]+) x" {
233 if { $expect_out(1,string) == $exp_res } {
238 -re "$gdb_prompt $" { }
240 $passfail "$testname"
241 if { $passfail == "pass" } then {
249 # Procedure: gdb_readexpr
251 # gdb_expr -- the expression whose value is desired
253 # the value of gdb_expr, as evaluated by gdb.
254 # [FIXME: returns -1 on error, which is sometimes a legit value]
257 proc gdb_readexpr { gdb_expr } {
261 send_gdb "print $gdb_expr\n"
263 -re "\[$\].*= (\[0-9\]+).*$gdb_prompt $" {
264 set result $expect_out(1,string)
266 -re "$gdb_prompt $" { }
273 # Procedure: gdb_gettpnum
275 # tracepoint (optional): if supplied, set a tracepoint here.
277 # the tracepoint ID of the most recently set tracepoint.
280 proc gdb_gettpnum { tracepoint } {
283 if { $tracepoint != "" } {
284 gdb_test "trace $tracepoint" "" ""
286 return [gdb_readexpr "\$tpnum"]
291 # Procedure: gdb_find_function_baseline
293 # func_name -- name of source function
295 # Sourcefile line of function definition (open curly brace),
296 # or -1 on failure. Caller must check return value.
298 # Works only for open curly brace at beginning of source line!
301 proc gdb_find_function_baseline { func_name } {
306 send_gdb "list $func_name\n"
308 # -re "\[\r\n\]\[\{\].*$gdb_prompt $" {
315 # Procedure: gdb_find_function_baseline
317 # filename: name of source file of desired function.
319 # Sourcefile line of function definition (open curly brace),
320 # or -1 on failure. Caller must check return value.
322 # Works only for open curly brace at beginning of source line!
325 proc gdb_find_recursion_test_baseline { filename } {
330 gdb_test "list $filename:1" "" ""
331 send_gdb "search gdb_recursion_test line 0\n"
333 -re "(\[0-9\]+)\[\t \]+\{.*line 0.*$gdb_prompt $" {
334 set baseline $expect_out(1,string)
336 -re "$gdb_prompt $" { }
342 # Return the location of the IPA library.
344 proc get_in_proc_agent {} {
347 if [target_info exists in_proc_agent] {
348 return [target_info in_proc_agent]
350 return $objdir/../gdbserver/libinproctrace.so
354 # Execute BINFILE on target to generate tracefile. Return 1 if
355 # tracefile is generated successfully, return 0 otherwise.
357 proc generate_tracefile { binfile } {
358 set status [remote_exec target "$binfile"]
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
365 if [target_info exists gdb,nofileio] {
369 clean_restart $binfile
371 if ![runto_main] then {
374 gdb_continue_to_end "" continue 1