1 # Copyright (C) 1998-2023 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_trace_common_supports_arch
55 # Returns true if gdb.trace/trace-common.h knows about this target.
56 # Allows skipping tests that depend on being able to include this file.
57 # Please keep this in sync with the supported targets in the header.
60 proc gdb_trace_common_supports_arch { } {
61 if { [istarget "x86_64*-*-*"]
62 || [istarget "i386*-*-*"]
63 || [istarget "aarch64*-*-*"]
64 || [istarget "powerpc*-*-*"]
65 || [istarget "s390*-*-*"] } {
73 # Procedure: gdb_target_supports_trace
74 # Returns true if GDB is connected to a target that supports tracing.
75 # Allows tests to abort early if not running on a trace-aware target.
78 proc gdb_target_supports_trace { } {
83 -re "\[Tt\]race can only be run on.*$gdb_prompt $" {
86 -re "\[Tt\]race can not be run on.*$gdb_prompt $" {
89 -re "\[Tt\]arget does not support.*$gdb_prompt $" {
92 -re ".*\[Ee\]rror.*$gdb_prompt $" {
95 -re ".*\[Ww\]arning.*$gdb_prompt $" {
98 -re ".*$gdb_prompt $" {
109 # Procedure: gdb_delete_tracepoints
110 # Many of the tests depend on setting tracepoints at various places and
111 # running until that tracepoint is reached. At times, we want to start
112 # with a clean slate with respect to tracepoints, so this utility proc
113 # lets us do this without duplicating this code everywhere.
116 proc gdb_delete_tracepoints {} {
119 send_gdb "delete tracepoints\n"
121 -re "Delete all tracepoints.*y or n.*$" {
125 -re ".*$gdb_prompt $" { # This happens if there were no tracepoints }
127 perror "Delete all tracepoints in delete_tracepoints (timeout)"
131 send_gdb "info tracepoints\n"
133 -re "No tracepoints.*$gdb_prompt $" {}
134 -re "$gdb_prompt $" { perror "tracepoints not deleted" ; return }
135 timeout { perror "info tracepoints (timeout)" ; return }
139 # Define actions for a tracepoint.
141 # actions_command -- the command used to create the actions.
142 # either "actions" or "commands".
143 # testname -- identifying string for pass/fail output
144 # tracepoint -- to which tracepoint(s) do these actions apply? (optional)
145 # args -- list of actions to be defined.
148 # non-zero -- failure
150 proc gdb_trace_setactions_command { actions_command testname tracepoint args } {
155 send_gdb "$actions_command $tracepoint\n"
156 set expected_result ""
158 -re "No tracepoint number .*$gdb_prompt $" {
162 -re "Enter actions for tracepoint $tracepoint.*>" {
163 if { [llength $args] > 0 } {
164 set lastcommand "[lindex $args $state]"
165 send_gdb "[lindex $args $state]\n"
167 set expected_result [lindex $args $state]
174 -re "\(.*\)\[\r\n\]+\[ \t]*>$" {
175 if { $expected_result != "" } {
176 regsub "^\[^\r\n\]+\[\r\n\]+" "$expect_out(1,string)" "" out
177 if ![regexp $expected_result $out] {
180 set expected_result ""
182 if { $state < [llength $args] } {
183 send_gdb "[lindex $args $state]\n"
185 set expected_result [lindex $args $state]
189 set expected_result ""
193 -re "\(.*\)$gdb_prompt $" {
194 if { $expected_result != "" } {
195 if ![regexp $expected_result $expect_out(1,string)] {
198 set expected_result ""
200 if { [llength $args] < $state } {
208 if { $testname != "" } {
211 if {$passfail == "pass"} {
218 # Define actions for a tracepoint, using the "actions" command. See
219 # gdb_trace_setactions_command.
221 proc gdb_trace_setactions { testname tracepoint args } {
222 eval gdb_trace_setactions_command "actions" {$testname} {$tracepoint} $args
225 # Define actions for a tracepoint, using the "commands" command. See
226 # gdb_trace_setactions_command.
228 proc gdb_trace_setcommands { testname tracepoint args } {
229 eval gdb_trace_setactions_command "commands" {$testname} {$tracepoint} $args
233 # Procedure: gdb_tfind_test
234 # Find a specified trace frame.
236 # testname -- identifying string for pass/fail output
237 # tfind_arg -- frame (line, PC, etc.) identifier
238 # exp_res -- Expected result of frame test
239 # args -- Test expression
242 # non-zero -- failure
245 proc gdb_tfind_test { testname tfind_arg exp_res args } {
248 if { "$args" != "" } {
252 set expr "(int) \$trace_frame"
256 gdb_test -nopass "tfind $tfind_arg" ""
257 send_gdb "printf \"x \%d x\\n\", $expr\n"
259 -re "x (-*\[0-9\]+) x" {
260 if { $expect_out(1,string) == $exp_res } {
265 -re "$gdb_prompt $" { }
267 $passfail "$testname"
268 if {$passfail == "pass"} {
276 # Procedure: gdb_readexpr
278 # gdb_expr -- the expression whose value is desired
280 # the value of gdb_expr, as evaluated by gdb.
281 # [FIXME: returns -1 on error, which is sometimes a legit value]
284 proc gdb_readexpr { gdb_expr } {
288 send_gdb "print $gdb_expr\n"
290 -re "\[$\].*= (\[0-9\]+).*$gdb_prompt $" {
291 set result $expect_out(1,string)
293 -re "$gdb_prompt $" { }
300 # Procedure: gdb_gettpnum
302 # tracepoint (optional): if supplied, set a tracepoint here.
304 # the tracepoint ID of the most recently set tracepoint.
307 proc gdb_gettpnum { tracepoint } {
310 if { $tracepoint != "" } {
311 gdb_test -nopass "trace $tracepoint"
313 return [gdb_readexpr "\$tpnum"]
318 # Procedure: gdb_find_function_baseline
320 # func_name -- name of source function
322 # Sourcefile line of function definition (open curly brace),
323 # or -1 on failure. Caller must check return value.
325 # Works only for open curly brace at beginning of source line!
328 proc gdb_find_function_baseline { func_name } {
333 send_gdb "list $func_name\n"
335 # -re "\[\r\n\]\[\{\].*$gdb_prompt $" {
342 # Procedure: gdb_find_function_baseline
344 # filename: name of source file of desired function.
346 # Sourcefile line of function definition (open curly brace),
347 # or -1 on failure. Caller must check return value.
349 # Works only for open curly brace at beginning of source line!
352 proc gdb_find_recursion_test_baseline { filename } {
357 gdb_test "list $filename:1" "" ""
358 send_gdb "search gdb_recursion_test line 0\n"
360 -re "(\[0-9\]+)\[\t \]+\{.*line 0.*$gdb_prompt $" {
361 set baseline $expect_out(1,string)
363 -re "$gdb_prompt $" { }
369 # Return the location of the IPA library.
371 proc get_in_proc_agent {} {
374 if [target_info exists in_proc_agent] {
375 return [target_info in_proc_agent]
377 return $objdir/../../gdbserver/libinproctrace.so
381 # Execute BINFILE on target to generate tracefile. Return 1 if
382 # tracefile is generated successfully, return 0 otherwise.
384 proc generate_tracefile { binfile } {
385 set status [remote_exec target "$binfile"]
387 if { [lindex $status 0] != 0 } {
388 # Failed to execute $binfile, for example on bare metal targets.
389 # Alternatively, load the binary and run it. If target doesn't
390 # have fileio capabilities, tracefile can't be generated. Skip
392 if [target_info exists gdb,nofileio] {
396 clean_restart $binfile
401 gdb_continue_to_end "" continue 1