1 # Copyright (C) 1998, 2007, 2008 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/>.
16 # Please email any bugs, comments, and/or additions to this file to:
17 # bug-gdb@prep.ai.mit.edu
21 # Support procedures for trace testing
26 # Procedure: gdb_target_supports_trace
27 # Returns true if GDB is connected to a target that supports tracing.
28 # Allows tests to abort early if not running on a trace-aware target.
31 proc gdb_target_supports_trace { } {
36 -re "\[Tt\]race can only be run on.*$gdb_prompt $" {
39 -re "\[Tt\]race can not be run on.*$gdb_prompt $" {
42 -re "\[Tt\]arget does not support.*$gdb_prompt $" {
45 -re ".*\[Ee\]rror.*$gdb_prompt $" {
48 -re ".*\[Ww\]arning.*$gdb_prompt $" {
51 -re ".*$gdb_prompt $" {
62 # Procedure: gdb_delete_tracepoints
63 # Many of the tests depend on setting tracepoints at various places and
64 # running until that tracepoint is reached. At times, we want to start
65 # with a clean slate with respect to tracepoints, so this utility proc
66 # lets us do this without duplicating this code everywhere.
69 proc gdb_delete_tracepoints {} {
72 send_gdb "delete tracepoints\n"
74 -re "Delete all tracepoints.*y or n.*$" {
78 -re ".*$gdb_prompt $" { # This happens if there were no tracepoints }
80 perror "Delete all tracepoints in delete_tracepoints (timeout)"
84 send_gdb "info tracepoints\n"
86 -re "No tracepoints.*$gdb_prompt $" {}
87 -re "$gdb_prompt $" { perror "tracepoints not deleted" ; return }
88 timeout { perror "info tracepoints (timeout)" ; return }
93 # Procedure: gdb_trace_setactions
94 # Define actions for a tracepoint.
96 # testname -- identifying string for pass/fail output
97 # tracepoint -- to which tracepoint do these actions apply? (optional)
98 # args -- list of actions to be defined.
101 # non-zero -- failure
103 proc gdb_trace_setactions { testname tracepoint args } {
108 send_gdb "actions $tracepoint\n";
109 set expected_result "";
111 -re "No tracepoint number .*$gdb_prompt $" {
115 -re "Enter actions for tracepoint $tracepoint.*>" {
116 if { [llength $args] > 0 } {
117 set lastcommand "[lindex $args $state]";
118 send_gdb "[lindex $args $state]\n";
120 set expected_result [lindex $args $state];
127 -re "\(.*\)\[\r\n\]+\[ \t]*> $" {
128 if { $expected_result != "" } {
129 regsub "^\[^\r\n\]+\[\r\n\]+" "$expect_out(1,string)" "" out;
130 if ![regexp $expected_result $out] {
133 set expected_result "";
135 if { $state < [llength $args] } {
136 send_gdb "[lindex $args $state]\n";
138 set expected_result [lindex $args $state];
142 set expected_result "";
146 -re "\(.*\)$gdb_prompt $" {
147 if { $expected_result != "" } {
148 if ![regexp $expected_result $expect_out(1,string)] {
151 set expected_result "";
153 if { [llength $args] < $state } {
161 if { $testname != "" } {
164 if { $passfail == "pass" } then {
172 # Procedure: gdb_tfind_test
173 # Find a specified trace frame.
175 # testname -- identifying string for pass/fail output
176 # tfind_arg -- frame (line, PC, etc.) identifier
177 # exp_res -- Expected result of frame test
178 # args -- Test expression
181 # non-zero -- failure
184 proc gdb_tfind_test { testname tfind_arg exp_res args } {
187 if { "$args" != "" } {
191 set expr "(int) \$trace_frame";
195 gdb_test "tfind $tfind_arg" "" ""
196 send_gdb "printf \"x \%d x\\n\", $expr\n";
198 -re "x (-*\[0-9\]+) x" {
199 if { $expect_out(1,string) == $exp_res } {
204 -re "$gdb_prompt $" { }
206 $passfail "$testname";
207 if { $passfail == "pass" } then {
215 # Procedure: gdb_readexpr
217 # gdb_expr -- the expression whose value is desired
219 # the value of gdb_expr, as evaluated by gdb.
220 # [FIXME: returns -1 on error, which is sometimes a legit value]
223 proc gdb_readexpr { gdb_expr } {
227 send_gdb "print $gdb_expr\n"
229 -re "\[$\].*= (\[0-9\]+).*$gdb_prompt $" {
230 set result $expect_out(1,string);
232 -re "$gdb_prompt $" { }
239 # Procedure: gdb_gettpnum
241 # tracepoint (optional): if supplied, set a tracepoint here.
243 # the tracepoint ID of the most recently set tracepoint.
246 proc gdb_gettpnum { tracepoint } {
249 if { $tracepoint != "" } {
250 gdb_test "trace $tracepoint" "" ""
252 return [gdb_readexpr "\$tpnum"];
257 # Procedure: gdb_find_function_baseline
259 # func_name -- name of source function
261 # Sourcefile line of function definition (open curly brace),
262 # or -1 on failure. Caller must check return value.
264 # Works only for open curly brace at beginning of source line!
267 proc gdb_find_function_baseline { func_name } {
272 send_gdb "list $func_name\n"
274 # -re "\[\r\n\]\[\{\].*$gdb_prompt $" {
281 # Procedure: gdb_find_function_baseline
283 # filename: name of source file of desired function.
285 # Sourcefile line of function definition (open curly brace),
286 # or -1 on failure. Caller must check return value.
288 # Works only for open curly brace at beginning of source line!
291 proc gdb_find_recursion_test_baseline { filename } {
296 gdb_test "list $filename:1" "" ""
297 send_gdb "search gdb_recursion_test line 0\n"
299 -re "(\[0-9\]+)\[\t \]+\{.*line 0.*$gdb_prompt $" {
300 set baseline $expect_out(1,string);
302 -re "$gdb_prompt $" { }