1 # Copyright (C) 1992, 1994, 1995 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 if ![info exists GDB] then {
28 if [file exists $base_dir/../gdb] then {
29 set GDB $base_dir/../gdb
31 set GDB [transform gdb]
36 if ![info exists GDBFLAGS] then {
40 # set the prompt if it doesn't exist
42 if ![info exists prompt] then {
43 set prompt "\[(\]gdb\[)\]"
47 # gdb_version -- extract and print the version number of GDB
49 proc default_gdb_version {} {
52 if {[which $GDB] != 0} then {
53 set tmp [exec echo "q" | $GDB -nw $GDBFLAGS]
54 regexp " \[0-9\.\]+" $tmp version
55 clone_output "[which $GDB] version$version -nw $GDBFLAGS \n"
57 warning "$GDB does not exist"
62 # gdb_unload -- unload a file if one is loaded
71 -re "No exec file now.*\r" { exp_continue }
72 -re "No symbol file now.*\r" { exp_continue }
73 -re "A program is being debugged already..*Kill it.*y or n. $"\
75 verbose "\t\tKilling previous program being debugged"
78 -re "Discard symbol table from .*y or n. $" {
84 perror "couldn't unload file in $GDB (timed out)."
90 # Many of the tests depend on setting breakpoints at various places and
91 # running until that breakpoint is reached. At times, we want to start
92 # with a clean-slate with respect to breakpoints, so this utility proc
93 # lets us do this without duplicating this code everywhere.
96 proc delete_breakpoints {} {
99 send "delete breakpoints\n"
101 -re "Delete all breakpoints.*y or n. $" {
105 -re "y\r\n$prompt $" {}
106 -re ".*$prompt $" { # This happens if there were no breakpoints
108 timeout { perror "Delete all breakpoints (timeout)" ; return }
110 send "info breakpoints\n"
112 -re "No breakpoints or watchpoints..*$prompt $" {}
113 -re ".*$prompt $" { perror "breakpoints not deleted" ; return }
114 timeout { perror "info breakpoints (timeout)" ; return }
120 # Generic run command.
122 # The second pattern below matches up to the first newline *only*.
123 # Using ``.*$'' could swallow up output that we attempt to match
126 proc gdb_run_cmd {} {
129 -re "The program .* has been started already.*y or n. $" {
133 -re "Starting program: \[^\n\]*" {}
138 # Set breakpoint at function and run gdb until it breaks there.
139 # Since this is the only breakpoint that will be set, if it stops
140 # at a breakpoint, we will assume it is the one we want. We can't
141 # just compare to "function" because it might be a fully qualified,
142 # single quoted C++ function specifier.
144 proc runto { function } {
150 -re "delete.*Delete all breakpoints.*y or n. $" {
154 timeout { fail "deleting breakpoints (timeout)" ; return 0 }
158 timeout { fail "deleting breakpoints (timeout)" ; return 0 }
161 send "break $function\n"
162 # The first two regexps are what we get with -g, the third is without -g.
164 -re "Breakpoint \[0-9\]* at .*: file .*, line $decimal.\r\n$prompt $" {}
165 -re "Breakpoint \[0-9\]*: file .*, line $decimal.\r\n$prompt $" {}
166 -re "Breakpoint \[0-9\]* at .*$prompt $" {}
167 -re "$prompt $" { fail "setting breakpoint at $function" ; return 0 }
168 timeout { fail "setting breakpoint at $function (timeout)" ; return 0 }
173 # the "at foo.c:36" output we get with -g.
174 # the "in func" output we get without -g.
176 -re "Break.* at .*:$decimal.*$prompt $" {
179 -re "Breakpoint \[0-9\]*, \[0-9xa-f\]* in $function.*$prompt $" {
183 fail "running to $function"
187 fail "running to $function (timeout)"
194 # gdb_test -- send a command to gdb and test the result.
195 # Takes three parameters.
197 # First one is the command to execute,
198 # Second one is the pattern to match for a PASS,
199 # Third one is an optional message to be printed. If this
200 # a null string "", then the pass/fail messages are not printed.
202 # 1 if the test failed,
203 # 0 if the test passes,
204 # -1 if there was an internal error.
206 proc gdb_test { args } {
212 if [llength $args]==3 then {
213 set message [lindex $args 2]
215 set message [lindex $args 0]
217 set command [lindex $args 0]
218 set pattern [lindex $args 1]
221 send_user "Sending \"$command\" to gdb\n"
222 send_user "Looking to match \"$pattern\"\n"
223 send_user "Message is \"$message\"\n"
227 if ![string match $command ""] {
232 -re ".*Ending remote debugging.*$prompt$" {
233 if ![isnative] then {
234 warning "Can`t communicate to remote target."
240 -re "$pattern\r\n$prompt $" {
241 if ![string match "" $message] then {
246 -re "Undefined command:.*$prompt" {
247 perror "Undefined command \"$command\"."
250 -re "Ambiguous command.*$prompt $" {
251 perror "\"$command\" is not a unique command name."
255 if ![string match "" $message] then {
262 perror "Window too small."
264 -re "\[(\]+y or n\[)\]+ " {
266 perror "Got interactive prompt."
269 perror "Process no longer exists"
273 perror "internal buffer is full."
276 if ![string match "" $message] then {
277 fail "(timeout) $message"
285 # Test that a command gives an error. For pass or fail, return
286 # a 1 to indicate that more tests can proceed. However a timeout
287 # is a serious error, generates a special fail message, and causes
288 # a 0 to be returned to indicate that more tests are likely to fail
291 proc test_print_reject { args } {
295 if [llength $args]==2 then {
296 set expectthis [lindex $args 1]
298 set expectthis "should never match this bogus string"
300 set sendthis [lindex $args 0]
302 send_user "Sending \"$sendthis\" to gdb\n"
303 send_user "Looking to match \"$expectthis\"\n"
307 -re ".*A .* in expression.*\\.*$prompt $" {
308 pass "reject $sendthis"
311 -re ".*Invalid syntax in expression.*$prompt $" {
312 pass "reject $sendthis"
315 -re ".*Junk after end of expression.*$prompt $" {
316 pass "reject $sendthis"
319 -re ".*Invalid number.*$prompt $" {
320 pass "reject $sendthis"
323 -re ".*Invalid character constant.*$prompt $" {
324 pass "reject $sendthis"
327 -re ".*No symbol table is loaded.*$prompt $" {
328 pass "reject $sendthis"
331 -re ".*No symbol .* in current context.*$prompt $" {
332 pass "reject $sendthis"
335 -re ".*$expectthis.*$prompt $" {
336 pass "reject $sendthis"
340 fail "reject $sendthis"
344 fail "reject $sendthis (eof or timeout)"
350 # Given an input string, adds backslashes as needed to create a
351 # regexp that will match the string.
353 proc string_to_regexp {str} {
355 regsub -all {[]*+.|()^$\[]} $str {\\&} result
359 # Same as gdb_test, but the second parameter is not a regexp,
360 # but a string that must match exactly.
362 proc gdb_test_exact { args } {
363 set command [lindex $args 0]
364 set pattern [string_to_regexp [lindex $args 1]]
365 if [llength $args]==3 then {
366 set message [lindex $args 2]
370 return [gdb_test $command $pattern $message]
373 proc gdb_reinitialize_dir { subdir } {
378 -re "Reinitialize source path to empty.*" {
381 -re "Source directories searched.*$prompt $" {
384 -re "Source directories searched.*$prompt $" {
385 verbose "Dir set to $subdir"
388 perror "Dir \"$subdir\" failed."
393 perror "Dir \"$subdir\" failed."
398 perror "Dir \"$subdir\" failed."
404 # gdb_exit -- exit the GDB, killing the target program if necessary
406 proc default_gdb_exit {} {
411 verbose "Quitting $GDB $GDBFLAGS"
413 # This used to be 1 for unix-gdb.exp
416 # We used to try to send "quit" to GDB, and wait for it to die.
417 # Dealing with all the cases and errors got pretty hairy. Just close it,
421 # Omitting this probably would cause strange timing-dependent failures.
426 # gdb_load -- load a file into the debugger.
427 # return a -1 if anything goes wrong.
429 proc gdb_file_cmd { arg } {
439 -re "Reading symbols from.*done.*$prompt $" {
440 verbose "\t\tLoaded $arg into the $GDB"
443 -re "has no symbol-table.*$prompt $" {
444 perror "$arg wasn't compiled with \"-g\""
447 -re "A program is being debugged already.*Kill it.*y or n. $" {
449 verbose "\t\tKilling previous program being debugged"
452 -re "Load new symbol table from \".*\".*y or n. $" {
455 -re "Reading symbols from.*done.*$prompt $" {
456 verbose "\t\tLoaded $arg with new symbol table into $GDB"
460 perror "(timeout) Couldn't load $arg, other program already l
466 -re ".*No such file or directory.*$prompt $" {
467 perror "($arg) No such file or directory\n"
471 perror "couldn't load $arg into $GDB."
475 perror "couldn't load $arg into $GDB (timed out)."
479 # This is an attempt to detect a core dump, but seems not to
480 # work. Perhaps we need to match .* followed by eof, in which
481 # expect does not seem to have a way to do that.
482 perror "couldn't load $arg into $GDB (end of file)."
489 # start gdb -- start gdb running, default procedure
491 proc default_gdb_start { } {
498 verbose "Spawning $GDB -nw $GDBFLAGS"
500 if { [which $GDB] == 0 } then {
501 perror "$GDB does not exist."
505 set oldtimeout $timeout
506 set timeout [expr "$timeout + 60"]
507 eval "spawn $GDB -nw $GDBFLAGS"
509 -re ".*\r\n$prompt $" {
510 verbose "GDB initialized."
513 perror "GDB never initialized."
517 perror "(timeout) GDB never initialized."
521 set timeout $oldtimeout
522 # force the height to "unlimited", so no pagers get used
523 send "set height 0\n"
526 verbose "Setting height to 0." 2
529 warning "Couldn't set the height to 0."
532 # force the width to "unlimited", so no wraparound occurs
536 verbose "Seting width to 0." 2
539 warning "Couldn't set the width to 0."
545 # FIXME: this is a copy of the new library procedure, but it's here too
546 # till the new dejagnu gets installed everywhere. I'd hate to break the
550 if ![info exists argv0] then {
551 proc exp_continue { } {
556 proc skip_chill_tests {} {
557 # For crosses, the CHILL runtime doesn't build because it can't find
558 # setjmp.h, stdio.h, etc.
559 # For AIX (as of 16 Mar 95), (a) there is no language code for
560 # CHILL in output_epilog in gcc/config/rs6000/rs6000.c, (b) collect2
561 # does not get along with AIX's too-clever linker.
562 return ![isnative] || [istarget "*-*-aix*"]