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.
26 if ![info exists GDB] then {
27 set GDB [transform gdb]
29 if ![info exists GDBFLAGS] then {
34 # gdb_version -- extract and print the version number of gcc
36 proc default_gdb_version {} {
39 if {[which $GDB] != 0} then {
40 set tmp [exec echo "q" | $GDB]
41 regexp " \[0-9\.\]+" $tmp version
42 clone_output "[which $GDB] version$version $GDBFLAGS\n"
44 warning "$GDB does not exist"
49 # gdb_unload -- unload a file if one is loaded
58 -re "No exec file now\.\r" { continue -expect }
59 -re "No symbol file now\.\r" { continue -expect }
60 -re "A program is being debugged already..*Kill it\? \(y or n\) $"\
62 verbose "\t\tKilling previous program being debugged"
65 -re "Discard symbol table from .*\? \(y or n\) $" {
71 perror "couldn't unload file in $GDB (timed out)."
77 # Many of the tests depend on setting breakpoints at various places and
78 # running until that breakpoint is reached. At times, we want to start
79 # with a clean-slate with respect to breakpoints, so this utility proc
80 # lets us do this without duplicating this code everywhere.
83 proc delete_breakpoints {} {
86 send "delete breakpoints\n"
88 -re "Delete all breakpoints\? \(y or n\) $" {
92 -re "y\r\n$prompt $" {}
93 -re ".*$prompt $" { fail "Delete all breakpoints" ; return }
94 timeout { fail "Delete all breakpoints (timeout)" ; return }
96 send "info breakpoints\n"
98 -re "No breakpoints or watchpoints..*$prompt $" {}
99 -re ".*$prompt $" { fail "breakpoints not deleted" ; return }
100 timeout { fail "info breakpoints (timeout)" ; return }
106 # Set breakpoint at function and run gdb until it breaks there.
107 # Since this is the only breakpoint that will be set, if it stops
108 # at a breakpoint, we will assume it is the one we want. We can't
109 # just compare to "function" because it might be a fully qualified,
110 # single quoted C++ function specifier.
113 proc runto { function } {
119 -re "Delete all breakpoints\? \(y or n\) $" {
123 timeout { fail "deleting breakpoints (timeout)" ; return 0 }
127 timeout { fail "deleting breakpoints (timeout)" ; return 0 }
130 send "break $function\n"
131 # The first regexp is what we get with -g, the second without -g.
133 -re "Break.* at .*: file .*, line $decimal.\r\n$prompt $" {}
134 -re "Breakpoint \[0-9\]* at 0x\[0-9a-f\]*.*$prompt $" {}
135 -re "$prompt $" { fail "setting breakpoint at $function" ; return 0 }
136 timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
140 # the "at foo.c:36" output we get with -g.
141 # the "in func" output we get without -g.
143 -re "The program .* has been started already.* \(y or n\) $" {
147 -re "Starting.*Break.* at .*:$decimal.*$prompt $" { return 1 }
148 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in $function.*$prompt $" {
151 -re "$prompt $" { fail "running to $function" ; return 0 }
152 timeout { fail "running to $function (timeout)" ; return 0 }
157 # gdb_test -- send a command to gdb and test the result.
158 # Takes three parameters.
160 # First one is the command to execute,
161 # Second one is the pattern to match for a PASS,
162 # Third one is an optional message to be printed. If this
163 # a null string "", then the pass/fail messages are not printed.
165 # 1 if the test failed,
166 # 0 if the test passes,
167 # -1 if there was an internal error.
169 proc gdb_test { args } {
175 if [llength $args]==3 then {
176 set message [lindex $args 2]
178 set message [lindex $args 0]
180 set command [lindex $args 0]
181 set pattern [lindex $args 1]
184 send_user "Sending \"$command\" to gdb\n"
185 send_user "Looking to match \"$pattern\"\n"
186 send_user "Message is \"$message\"\n"
191 # trap the send so any problems don't crash things
192 catch "send \"$command\n\"" errmess
193 if [string match "write\(spawn_id=\[0-9\]+\):" $errmess] then {
194 perror "sent \"$command\" got expect error \"$errmess\""
201 -re ".*Ending remote debugging.*$prompt$" {
202 if ![isnative] then {
203 warning "Can`t communicate to remote target."
209 -re "$pattern.*$prompt $" {
210 if ![string match "" $message] then {
215 -re "Undefined command:.*$prompt" {
216 perror "Undefined command \"$command\"."
219 -re "Ambiguous command.*$prompt $" {
220 perror "\"$command\" is not a unique command name."
224 if ![string match "" $message] then {
231 perror "Window too small."
235 perror "Got interactive prompt."
238 perror "Process no longer exists"
242 perror "internal buffer is full."
245 fail "(timeout) $message"
252 proc gdb_reinitialize_dir { subdir } {
257 -re "Reinitialize source path to empty.*" {
260 -re "Source directories searched.*$prompt $" {
263 -re "Source directories searched.*$prompt $" {
264 verbose "Dir set to $subdir"
267 perror "Dir \"$subdir\" failed."
272 perror "Dir \"$subdir\" failed."
277 perror "Dir \"$subdir\" failed."
283 # gdb_exit -- exit the GDB, killing the target program if necessary
285 proc default_gdb_exit {} {
290 verbose "Quitting $GDB $GDBFLAGS" 1
292 # This used to be 1 for unix-gdb.exp
295 catch "send \"quit\n\"" result
296 # If the process has gone away (e.g. gdb dumped core), deal with it.
297 if [string match "write\(spawn_id=\[0-9\]+\):" $result] then {
299 # FIXME: Shouldn't we call "wait" too?
302 # FIXME: What is this catch statement doing here? Won't it prevent us
303 # from getting errors that we'd rather see?
307 verbose "Got EOF from $GDB" 2
310 verbose "Got TIMEOUT from $GDB" 2
312 -re "The program is running. Quit anyway.*(y or n) $" {
314 verbose "Killing program being debugged" 2
319 # Before this was here sometimes "uit" would get sent to the next GDB
320 # (assuming this is immediately followed by gdb_start), which would
321 # cause a loss of syncronization (i.e. all the stuff that swallows a
322 # prompt would swallow the wrong one).
327 # gdb_load -- load a file into the debugger.
328 # return a -1 if anything goes wrong.
330 proc gdb_file_cmd { arg } {
339 -re "Reading symbols from.*done.*$prompt $" {
340 verbose "\t\tLoaded $arg into the $GDB"
343 -re "has no symbol-table.*$prompt $" {
344 perror "$arg wasn't compiled with \"-g\""
347 -re "A program is being debugged already..*Kill it\? \(y or n\) $" {
349 verbose "\t\tKilling previous program being debugged"
352 -re "Load new symbol table from.*\? \(y or n\) $" {
355 -re "Reading symbols from.*done.*$prompt $" {
356 verbose "\t\tLoaded $arg with new symbol table into $GDB"
360 perror "(timeout) Couldn't load $arg, other program already l
366 -re ".*No such file or directory.*$prompt $" {
367 perror "($arg) No such file or directory\n"
371 perror "couldn't load $arg into $GDB."
375 error "couldn't load $arg into $GDB (timed out)."
379 # This is an attempt to detect a core dump, but seems not to
380 # work. Perhaps we need to match .* followed by eof, in which
381 # expect does not seem to have a way to do that.
382 error "couldn't load $arg into $GDB (end of file)."