1 # Copyright (C) 1992 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 2 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, write to the Free Software
15 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Fred Fish. (fnf@cygnus.com)
22 # Generic gdb subroutines that should work for any target. If these
23 # need to be modified for any target, it can be done with a variable
24 # or by passing arguments.
27 # gdb_unload -- unload a file if one is loaded
36 -re "No exec file now\.\r" { continue -expect }
37 -re "No symbol file now\.\r" { continue -expect }
38 -re "A program is being debugged already..*Kill it\? \(y or n\) $"\
41 send_user "\t\tKilling previous program being debugged\n"
45 -re "Discard symbol table from .*\? \(y or n\) $" {
51 error "couldn't unload file in $GDB (timed out)."
57 # Many of the tests depend on setting breakpoints at various places and
58 # running until that breakpoint is reached. At times, we want to start
59 # with a clean-slate with respect to breakpoints, so this utility proc
60 # lets us do this without duplicating this code everywhere.
63 proc delete_breakpoints {} {
66 send "delete breakpoints\n"
68 -re "Delete all breakpoints\? \(y or n\) $" {
72 -re "y\r\n$prompt $" {}
73 -re ".*$prompt $" { fail "Delete all breakpoints" ; return }
74 timeout { fail "Delete all breakpoints (timeout)" ; return }
76 send "info breakpoints\n"
78 -re "No breakpoints or watchpoints..*$prompt $" {}
79 -re ".*$prompt $" { fail "breakpoints not deleted" ; return }
80 timeout { fail "info breakpoints (timeout)" ; return }
86 # Set breakpoint at function and run gdb until it breaks there.
87 # Since this is the only breakpoint that will be set, if it stops
88 # at a breakpoint, we will assume it is the one we want. We can't
89 # just compare to "function" because it might be a fully qualified,
90 # single quoted C++ function specifier.
93 proc runto { function } {
99 -re "Delete all breakpoints\? \(y or n\) $" {
103 timeout { fail "deleting breakpoints (timeout)" ; return 0 }
107 timeout { fail "deleting breakpoints (timeout)" ; return 0 }
110 send "break $function\n"
111 # The first regexp is what we get with -g, the second without -g.
113 -re "Break.* at .*: file .*, line $decimal.\r\n$prompt $" {}
114 -re "Breakpoint \[0-9\]* at 0x\[0-9a-f\]*.*$prompt $" {}
115 -re "$prompt $" { fail "setting breakpoint at $function" ; return 0 }
116 timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
120 # the "at foo.c:36" output we get with -g.
121 # the "in func" output we get without -g.
123 -re "The program .* has been started already.* \(y or n\) $" {
127 -re "Starting.*Break.* at .*:$decimal.*$prompt $" { return 1 }
128 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in $function.*$prompt $" {
131 -re "$prompt $" { fail "running to $function" ; return 0 }
132 timeout { fail "running to $function (timeout)" ; return 0 }
137 # gdb_test -- send a command to gdb and test the result.
138 # Takes three parameters.
140 # First one is the command to execute,
141 # Second one is the pattern to match for a PASS,
142 # Third one is an optional message to be printed. If this
143 # a null string "", then the pass/fail messages are not printed.
145 # 1 if the test failed,
146 # 0 if the test passes,
147 # -1 if there was an internal error.
149 proc gdb_test { args } {
155 if [llength $args]==3 then {
156 set message [lindex $args 2]
158 set message [lindex $args 0]
160 set command [lindex $args 0]
161 set pattern [lindex $args 1]
164 send_user "Sending \"$command\" to gdb\n"
165 send_user "Looking to match \"$pattern\"\n"
166 send_user "Message is \"$message\"\n"
171 # trap the send so any problems don't crash things
172 catch "send \"$command\n\"" errmess
173 if [string match "write\(spawn_id=\[0-9\]+\):" $errmess] then {
174 error "sent \"$command\" got expect error \"$errmess\""
181 -re ".*Ending remote debugging.*$prompt$" {
182 if ![isnative] then {
183 warning "Can`t communicate to remote target."
189 -re "$pattern.*$prompt $" {
190 if ![string match "" $message] then {
195 -re "Undefined command:.*$prompt" {
196 error "Undefined command \"$command\"."
199 -re "Ambiguous command.*$prompt $" {
200 error "\"$command\" is not a unique command name."
204 if ![string match "" $message] then {
211 error "Window too small."
215 error "Got interactive prompt."
218 error "Process no longer exists"
222 error "internal buffer is full."
225 fail "(timeout) $message"
232 proc gdb_reinitialize_dir { subdir } {
238 -re "Reinitialize source path to empty.*" {
241 -re "Source directories searched.*$prompt $" {
244 -re "Source directories searched.*$prompt $" {
246 send_user "Dir set to $subdir\n"
250 error "Dir \"$subdir\" failed."
255 error "Dir \"$subdir\" failed."
260 error "Dir \"$subdir\" failed."
267 # gdb_exit -- exit the GDB, killing the target program if necessary
269 proc default_gdb_exit {} {
274 verbose "Quitting $GDB $GDBFLAGS" 1
276 # This used to be 1 for unix-gdb.exp
279 catch "send \"quit\n\"" result
280 # If the process has gone away (e.g. gdb dumped core), deal with it.
281 if [string match "write\(spawn_id=\[0-9\]+\):" $result] then {
283 # FIXME: Shouldn't we call "wait" too?
286 # FIXME: What is this catch statement doing here? Won't it prevent us
287 # from getting errors that we'd rather see?
291 verbose "Got EOF from $GDB" 2
294 verbose "Got TIMEOUT from $GDB" 2
296 -re "The program is running. Quit anyway.*(y or n) $" {
298 verbose "Killing program being debugged" 2
303 # FIXME: Does the catch prevent us from getting errors that we'd rather
304 # see? the old gdb_exit in unix-gdb.exp had "close" without catch
305 # in the above expect statement (for the timeout and -re "The
306 # program... cases) (as well as a catch "close" here).
309 # Before this was here sometimes "uit" would get sent to the next GDB
310 # (assuming this is immediately followed by gdb_start), which would
311 # cause a loss of syncronization (i.e. all the stuff that swallows a
312 # prompt would swallow the wrong one).