1 # Copyright (C) 1998, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Support procedures for trace testing
24 # Procedure: gdb_target_supports_trace
25 # Returns true if GDB is connected to a target that supports tracing.
26 # Allows tests to abort early if not running on a trace-aware target.
29 proc gdb_target_supports_trace { } {
34 -re "\[Tt\]race can only be run on.*$gdb_prompt $" {
37 -re "\[Tt\]race can not be run on.*$gdb_prompt $" {
40 -re "\[Tt\]arget does not support.*$gdb_prompt $" {
43 -re ".*\[Ee\]rror.*$gdb_prompt $" {
46 -re ".*\[Ww\]arning.*$gdb_prompt $" {
49 -re ".*$gdb_prompt $" {
60 # Procedure: gdb_delete_tracepoints
61 # Many of the tests depend on setting tracepoints at various places and
62 # running until that tracepoint is reached. At times, we want to start
63 # with a clean slate with respect to tracepoints, so this utility proc
64 # lets us do this without duplicating this code everywhere.
67 proc gdb_delete_tracepoints {} {
70 send_gdb "delete tracepoints\n"
72 -re "Delete all tracepoints.*y or n.*$" {
76 -re ".*$gdb_prompt $" { # This happens if there were no tracepoints }
78 perror "Delete all tracepoints in delete_tracepoints (timeout)"
82 send_gdb "info tracepoints\n"
84 -re "No tracepoints.*$gdb_prompt $" {}
85 -re "$gdb_prompt $" { perror "tracepoints not deleted" ; return }
86 timeout { perror "info tracepoints (timeout)" ; return }
91 # Procedure: gdb_trace_setactions
92 # Define actions for a tracepoint.
94 # testname -- identifying string for pass/fail output
95 # tracepoint -- to which tracepoint do these actions apply? (optional)
96 # args -- list of actions to be defined.
101 proc gdb_trace_setactions { testname tracepoint args } {
106 send_gdb "actions $tracepoint\n";
107 set expected_result "";
109 -re "No tracepoint number .*$gdb_prompt $" {
113 -re "Enter actions for tracepoint $tracepoint.*>" {
114 if { [llength $args] > 0 } {
115 set lastcommand "[lindex $args $state]";
116 send_gdb "[lindex $args $state]\n";
118 set expected_result [lindex $args $state];
125 -re "\(.*\)\[\r\n\]+\[ \t]*>$" {
126 if { $expected_result != "" } {
127 regsub "^\[^\r\n\]+\[\r\n\]+" "$expect_out(1,string)" "" out;
128 if ![regexp $expected_result $out] {
131 set expected_result "";
133 if { $state < [llength $args] } {
134 send_gdb "[lindex $args $state]\n";
136 set expected_result [lindex $args $state];
140 set expected_result "";
144 -re "\(.*\)$gdb_prompt $" {
145 if { $expected_result != "" } {
146 if ![regexp $expected_result $expect_out(1,string)] {
149 set expected_result "";
151 if { [llength $args] < $state } {
159 if { $testname != "" } {
162 if { $passfail == "pass" } then {
170 # Procedure: gdb_tfind_test
171 # Find a specified trace frame.
173 # testname -- identifying string for pass/fail output
174 # tfind_arg -- frame (line, PC, etc.) identifier
175 # exp_res -- Expected result of frame test
176 # args -- Test expression
179 # non-zero -- failure
182 proc gdb_tfind_test { testname tfind_arg exp_res args } {
185 if { "$args" != "" } {
189 set expr "(int) \$trace_frame";
193 gdb_test "tfind $tfind_arg" "" ""
194 send_gdb "printf \"x \%d x\\n\", $expr\n";
196 -re "x (-*\[0-9\]+) x" {
197 if { $expect_out(1,string) == $exp_res } {
202 -re "$gdb_prompt $" { }
204 $passfail "$testname";
205 if { $passfail == "pass" } then {
213 # Procedure: gdb_readexpr
215 # gdb_expr -- the expression whose value is desired
217 # the value of gdb_expr, as evaluated by gdb.
218 # [FIXME: returns -1 on error, which is sometimes a legit value]
221 proc gdb_readexpr { gdb_expr } {
225 send_gdb "print $gdb_expr\n"
227 -re "\[$\].*= (\[0-9\]+).*$gdb_prompt $" {
228 set result $expect_out(1,string);
230 -re "$gdb_prompt $" { }
237 # Procedure: gdb_gettpnum
239 # tracepoint (optional): if supplied, set a tracepoint here.
241 # the tracepoint ID of the most recently set tracepoint.
244 proc gdb_gettpnum { tracepoint } {
247 if { $tracepoint != "" } {
248 gdb_test "trace $tracepoint" "" ""
250 return [gdb_readexpr "\$tpnum"];
255 # Procedure: gdb_find_function_baseline
257 # func_name -- name of source function
259 # Sourcefile line of function definition (open curly brace),
260 # or -1 on failure. Caller must check return value.
262 # Works only for open curly brace at beginning of source line!
265 proc gdb_find_function_baseline { func_name } {
270 send_gdb "list $func_name\n"
272 # -re "\[\r\n\]\[\{\].*$gdb_prompt $" {
279 # Procedure: gdb_find_function_baseline
281 # filename: name of source file of desired function.
283 # Sourcefile line of function definition (open curly brace),
284 # or -1 on failure. Caller must check return value.
286 # Works only for open curly brace at beginning of source line!
289 proc gdb_find_recursion_test_baseline { filename } {
294 gdb_test "list $filename:1" "" ""
295 send_gdb "search gdb_recursion_test line 0\n"
297 -re "(\[0-9\]+)\[\t \]+\{.*line 0.*$gdb_prompt $" {
298 set baseline $expect_out(1,string);
300 -re "$gdb_prompt $" { }