1 # Copyright (C) 1998, 2007, 2008, 2009, 2010 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 }
90 # Procedure: gdb_trace_setactions
91 # Define actions for a tracepoint.
93 # testname -- identifying string for pass/fail output
94 # tracepoint -- to which tracepoint do these actions apply? (optional)
95 # args -- list of actions to be defined.
100 proc gdb_trace_setactions { testname tracepoint args } {
105 send_gdb "actions $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 {
169 # Procedure: gdb_tfind_test
170 # Find a specified trace frame.
172 # testname -- identifying string for pass/fail output
173 # tfind_arg -- frame (line, PC, etc.) identifier
174 # exp_res -- Expected result of frame test
175 # args -- Test expression
178 # non-zero -- failure
181 proc gdb_tfind_test { testname tfind_arg exp_res args } {
184 if { "$args" != "" } {
188 set expr "(int) \$trace_frame";
192 gdb_test "tfind $tfind_arg" "" ""
193 send_gdb "printf \"x \%d x\\n\", $expr\n";
195 -re "x (-*\[0-9\]+) x" {
196 if { $expect_out(1,string) == $exp_res } {
201 -re "$gdb_prompt $" { }
203 $passfail "$testname";
204 if { $passfail == "pass" } then {
212 # Procedure: gdb_readexpr
214 # gdb_expr -- the expression whose value is desired
216 # the value of gdb_expr, as evaluated by gdb.
217 # [FIXME: returns -1 on error, which is sometimes a legit value]
220 proc gdb_readexpr { gdb_expr } {
224 send_gdb "print $gdb_expr\n"
226 -re "\[$\].*= (\[0-9\]+).*$gdb_prompt $" {
227 set result $expect_out(1,string);
229 -re "$gdb_prompt $" { }
236 # Procedure: gdb_gettpnum
238 # tracepoint (optional): if supplied, set a tracepoint here.
240 # the tracepoint ID of the most recently set tracepoint.
243 proc gdb_gettpnum { tracepoint } {
246 if { $tracepoint != "" } {
247 gdb_test "trace $tracepoint" "" ""
249 return [gdb_readexpr "\$tpnum"];
254 # Procedure: gdb_find_function_baseline
256 # func_name -- name of source function
258 # Sourcefile line of function definition (open curly brace),
259 # or -1 on failure. Caller must check return value.
261 # Works only for open curly brace at beginning of source line!
264 proc gdb_find_function_baseline { func_name } {
269 send_gdb "list $func_name\n"
271 # -re "\[\r\n\]\[\{\].*$gdb_prompt $" {
278 # Procedure: gdb_find_function_baseline
280 # filename: name of source file of desired function.
282 # Sourcefile line of function definition (open curly brace),
283 # or -1 on failure. Caller must check return value.
285 # Works only for open curly brace at beginning of source line!
288 proc gdb_find_recursion_test_baseline { filename } {
293 gdb_test "list $filename:1" "" ""
294 send_gdb "search gdb_recursion_test line 0\n"
296 -re "(\[0-9\]+)\[\t \]+\{.*line 0.*$gdb_prompt $" {
297 set baseline $expect_out(1,string);
299 -re "$gdb_prompt $" { }