1 # Copyright (C) 1998-2017 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] {
39 } elseif [istarget "powerpc*-*-*"] {
43 } elseif { [istarget "s390*-*-*"] } {
54 # Procedure: gdb_target_supports_trace
55 # Returns true if GDB is connected to a target that supports tracing.
56 # Allows tests to abort early if not running on a trace-aware target.
59 proc gdb_target_supports_trace { } {
64 -re "\[Tt\]race can only be run on.*$gdb_prompt $" {
67 -re "\[Tt\]race can not be run on.*$gdb_prompt $" {
70 -re "\[Tt\]arget does not support.*$gdb_prompt $" {
73 -re ".*\[Ee\]rror.*$gdb_prompt $" {
76 -re ".*\[Ww\]arning.*$gdb_prompt $" {
79 -re ".*$gdb_prompt $" {
90 # Procedure: gdb_delete_tracepoints
91 # Many of the tests depend on setting tracepoints at various places and
92 # running until that tracepoint is reached. At times, we want to start
93 # with a clean slate with respect to tracepoints, so this utility proc
94 # lets us do this without duplicating this code everywhere.
97 proc gdb_delete_tracepoints {} {
100 send_gdb "delete tracepoints\n"
102 -re "Delete all tracepoints.*y or n.*$" {
106 -re ".*$gdb_prompt $" { # This happens if there were no tracepoints }
108 perror "Delete all tracepoints in delete_tracepoints (timeout)"
112 send_gdb "info tracepoints\n"
114 -re "No tracepoints.*$gdb_prompt $" {}
115 -re "$gdb_prompt $" { perror "tracepoints not deleted" ; return }
116 timeout { perror "info tracepoints (timeout)" ; return }
120 # Define actions for a tracepoint.
122 # actions_command -- the command used to create the actions.
123 # either "actions" or "commands".
124 # testname -- identifying string for pass/fail output
125 # tracepoint -- to which tracepoint(s) do these actions apply? (optional)
126 # args -- list of actions to be defined.
129 # non-zero -- failure
131 proc gdb_trace_setactions_command { actions_command testname tracepoint args } {
136 send_gdb "$actions_command $tracepoint\n"
137 set expected_result ""
139 -re "No tracepoint number .*$gdb_prompt $" {
143 -re "Enter actions for tracepoint $tracepoint.*>" {
144 if { [llength $args] > 0 } {
145 set lastcommand "[lindex $args $state]"
146 send_gdb "[lindex $args $state]\n"
148 set expected_result [lindex $args $state]
155 -re "\(.*\)\[\r\n\]+\[ \t]*>$" {
156 if { $expected_result != "" } {
157 regsub "^\[^\r\n\]+\[\r\n\]+" "$expect_out(1,string)" "" out
158 if ![regexp $expected_result $out] {
161 set expected_result ""
163 if { $state < [llength $args] } {
164 send_gdb "[lindex $args $state]\n"
166 set expected_result [lindex $args $state]
170 set expected_result ""
174 -re "\(.*\)$gdb_prompt $" {
175 if { $expected_result != "" } {
176 if ![regexp $expected_result $expect_out(1,string)] {
179 set expected_result ""
181 if { [llength $args] < $state } {
189 if { $testname != "" } {
192 if { $passfail == "pass" } then {
199 # Define actions for a tracepoint, using the "actions" command. See
200 # gdb_trace_setactions_command.
202 proc gdb_trace_setactions { testname tracepoint args } {
203 eval gdb_trace_setactions_command "actions" {$testname} {$tracepoint} $args
206 # Define actions for a tracepoint, using the "commands" command. See
207 # gdb_trace_setactions_command.
209 proc gdb_trace_setcommands { testname tracepoint args } {
210 eval gdb_trace_setactions_command "commands" {$testname} {$tracepoint} $args
214 # Procedure: gdb_tfind_test
215 # Find a specified trace frame.
217 # testname -- identifying string for pass/fail output
218 # tfind_arg -- frame (line, PC, etc.) identifier
219 # exp_res -- Expected result of frame test
220 # args -- Test expression
223 # non-zero -- failure
226 proc gdb_tfind_test { testname tfind_arg exp_res args } {
229 if { "$args" != "" } {
233 set expr "(int) \$trace_frame"
237 gdb_test "tfind $tfind_arg" "" ""
238 send_gdb "printf \"x \%d x\\n\", $expr\n"
240 -re "x (-*\[0-9\]+) x" {
241 if { $expect_out(1,string) == $exp_res } {
246 -re "$gdb_prompt $" { }
248 $passfail "$testname"
249 if { $passfail == "pass" } then {
257 # Procedure: gdb_readexpr
259 # gdb_expr -- the expression whose value is desired
261 # the value of gdb_expr, as evaluated by gdb.
262 # [FIXME: returns -1 on error, which is sometimes a legit value]
265 proc gdb_readexpr { gdb_expr } {
269 send_gdb "print $gdb_expr\n"
271 -re "\[$\].*= (\[0-9\]+).*$gdb_prompt $" {
272 set result $expect_out(1,string)
274 -re "$gdb_prompt $" { }
281 # Procedure: gdb_gettpnum
283 # tracepoint (optional): if supplied, set a tracepoint here.
285 # the tracepoint ID of the most recently set tracepoint.
288 proc gdb_gettpnum { tracepoint } {
291 if { $tracepoint != "" } {
292 gdb_test "trace $tracepoint" "" ""
294 return [gdb_readexpr "\$tpnum"]
299 # Procedure: gdb_find_function_baseline
301 # func_name -- name of source function
303 # Sourcefile line of function definition (open curly brace),
304 # or -1 on failure. Caller must check return value.
306 # Works only for open curly brace at beginning of source line!
309 proc gdb_find_function_baseline { func_name } {
314 send_gdb "list $func_name\n"
316 # -re "\[\r\n\]\[\{\].*$gdb_prompt $" {
323 # Procedure: gdb_find_function_baseline
325 # filename: name of source file of desired function.
327 # Sourcefile line of function definition (open curly brace),
328 # or -1 on failure. Caller must check return value.
330 # Works only for open curly brace at beginning of source line!
333 proc gdb_find_recursion_test_baseline { filename } {
338 gdb_test "list $filename:1" "" ""
339 send_gdb "search gdb_recursion_test line 0\n"
341 -re "(\[0-9\]+)\[\t \]+\{.*line 0.*$gdb_prompt $" {
342 set baseline $expect_out(1,string)
344 -re "$gdb_prompt $" { }
350 # Return the location of the IPA library.
352 proc get_in_proc_agent {} {
355 if [target_info exists in_proc_agent] {
356 return [target_info in_proc_agent]
358 return $objdir/../gdbserver/libinproctrace.so
362 # Execute BINFILE on target to generate tracefile. Return 1 if
363 # tracefile is generated successfully, return 0 otherwise.
365 proc generate_tracefile { binfile } {
366 set status [remote_exec target "$binfile"]
368 if { [lindex $status 0] != 0 } {
369 # Failed to execute $binfile, for example on bare metal targets.
370 # Alternatively, load the binary and run it. If target doesn't
371 # have fileio capabilities, tracefile can't be generated. Skip
373 if [target_info exists gdb,nofileio] {
377 clean_restart $binfile
379 if ![runto_main] then {
382 gdb_continue_to_end "" continue 1