home *** CD-ROM | disk | FTP | other *** search
- # Copyright (C) 1988, 1990, 1991, 1992 Free Software Foundation, Inc.
-
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-
- # Please email any bugs, comments, and/or additions to this file to:
- # bug-gdb@prep.ai.mit.edu
-
- # This file was written by Rob Savoye. (rob@cygnus.com)
-
- if $tracelevel then {
- strace $tracelevel
- }
-
- set prms_id 0
- set bug_id 0
-
- # are we on a target board
- if [string first $target_alias $host_alias]==-1 then {
- warning "These test cases can't run on a target system."
- continue
- }
-
- proc test_with_self {} {
- global prompt
- global tool
- global det_file
- global timeout
- global decimal
-
- # load yourself into the debugger
- # This can take a relatively long time, particularly for testing where
- # the executable is being accessed over a network, or where gdb does not
- # support partial symbols for a particular target and has to load the
- # entire symbol table. Set the timeout to 10 minutes, which should be
- # adequate for most environments (it *has* timed out with 5 min on a
- # SPARCstation SLC under moderate load, so this isn't unreasonable).
- # After gdb is loaded, set the timeout to 30 seconds for the duration
- # of this test, and then back to the original value.
-
- set oldtimeout $timeout
- set timeout 600
- if {[gdb_load "./x$tool"] <0} then {
- return -1
- }
-
- set timeout 30
-
- # disassemble yourself
- send "x/10i main\n"
- expect {
- -re "x/10i.*main.*main\+$decimal.*main\+$decimal.*$prompt $"\
- { pass "Disassemble main" }
- -re ".*$prompt $" { fail "Disassemble main" }
- timeout { fail "(timeout) Disassemble main" }
- }
-
-
- # do we have a version number ?
- send "print version\n"
- expect {
- -re ".\[0-9\]+ = 0x.*\[0-9.\]+.*$prompt $"\
- { pass "printed version" }
- -re ".*$prompt $" { fail "printed version" }
- timeout { fail "(timeout) printed version" }
- }
-
-
- # set a breakpoint at main()
- send "break main\n"
- expect {
- -re "Breakpoint.*at.* file.*, line.*$prompt $" { pass "Set breakpoint at main" }
- -re ".*$prompt $" { fail "Set breakpoint at main" }
- timeout { fail "(timeout) Set breakpoint at main" }
- }
-
-
- # run yourself
- send "run\n"
- expect {
- -re "Starting program.*Breakpoint \[0-9\]+,.*main \(argc.*argv.*\) at .*main.c:.*$prompt $"\
- { pass "run until breakpoint at main" }
- -re ".*$prompt $" { fail "run until breakpoint at main" }
- timeout { fail "(timeout) run until breakpoint at main" }
- }
-
-
- # lets do a few single steps
- send "step\n"
- expect {
- -re "char \*execarg = NULL;.*$prompt $" { pass "first single step" }
- -re ".*No such file or directory.\r\n$prompt $" {
- pass "first single step (no source available)"
- }
- -re ".*A file or directory in the path name does not exist..\r\n$prompt $" {
- pass "first single step (no source available)"
- }
- -re ".*$prompt $" { fail "first single step" }
- timeout { fail "(timeout) first single step" }
- }
-
-
- send "step\n"
- expect {
- -re "char \*corearg = NULL;.*$prompt $" { pass "second single step" }
- -re ".*No such file or directory.\r\n$prompt $" {
- pass "second single step (no source available)"
- }
- -re ".*A file or directory in the path name does not exist..\r\n$prompt $" {
- pass "second single step (no source available)"
- }
- -re ".*$prompt $" { fail "second single step" }
- timeout { fail "(timeout) second single step" }
- }
-
-
- send "step\n"
- expect {
- -re "char \*cdarg = NULL;.*$prompt $" { pass "third single step" }
- -re ".*No such file or directory.\r\n$prompt $" {
- pass "third step (no source available)"
- }
- -re ".*A file or directory in the path name does not exist..\r\n$prompt $" {
- pass "third step (no source available)"
- }
- -re ".*$prompt $" { fail "third single step" }
- timeout { fail "(timeout) third single step" }
- }
-
-
- send "step\n"
- expect {
- -re "char \*ttyarg = NULL;.*$prompt $" { pass "forth single step" }
- -re ".*No such file or directory.\r\n$prompt $" {
- pass "fourth single step (no source available)"
- }
- -re ".*A file or directory in the path name does not exist..\r\n$prompt $" {
- pass "fourth single step (no source available)"
- }
- -re ".*$prompt $" { fail "forth single step" }
- timeout { fail "(timeout) forth single step" }
- }
-
-
- send "step\n"
- expect {
- -re "init_malloc.* NULL.*$prompt $" { pass "fifth single step" }
- -re ".*No such file or directory.\r\n$prompt $" {
- pass "fifth single step (no source available)"
- }
- -re ".*A file or directory in the path name does not exist..\r\n$prompt $" {
- pass "fifth single step (no source available)"
- }
- -re ".*$prompt $" { fail "fifth single step" }
- timeout { fail "(timeout) fifth single step" }
- }
-
-
- # now jump over a few functions
- send "next\n"
- expect {
- -re "if.*level.*$prompt $" { pass "first next" }
- -re "i = .*count.*$prompt $" { pass "first next" }
- -re ".*No such file or directory.\r\n$prompt $" {
- pass "first next (no source available)"
- }
- -re ".*A file or directory in the path name does not exist..\r\n$prompt $" {
- pass "first next (no source available)"
- }
- -re ".*$prompt $" { fail "first next" }
- timeout { fail "(timeout) first next" }
- }
- # -re "if \(setmp \(to_top_level\)\).*$prompt $" { pass "first next" }
-
-
- # This one fails on Solaris (for some versions of gdb) because you
- # can't next over library functions
- setup_xfail "sparc-sun-solaris2" 1817
- # The mips assembler rearranges jumps so that gdb lands in the
- # middle of the next source line and then steps to the next line.
- # We would have to pass -O0 from gcc to mips-as to fix that xfail.
- setup_xfail "mips-*-*"
- set next_ok 1
- send "next\n"
- expect {
- -re "cmdsize = 1;.*$prompt $" { pass "second next" }
- -re "if \(i.*$prompt $" { pass "second next" }
- -re ".*No such file or directory.\r\n$prompt $" {
- pass "second next (no source available)"
- }
- -re ".*A file or directory in the path name does not exist..\r\n$prompt $" {
- pass "second next (no source available)"
- }
- -re ".*$prompt $" { fail "second next"; set next_ok 0 }
- timeout { fail "(timeout) second next"; set next_ok 0 }
- }
-
-
- # print something
- # On the RS/6000 malloc is pulled in from a shared library, and gdb
- # doesn't know how to find it.
- setup_xfail "rs6000-*-*"
- # On the Sun4 the value happens to be allocated near the sbrk, and
- # gdb doesn't know how to handle that.
- setup_xfail "sparc-sun-sunos4*" 1823
- send "print \"foo\"\n"
- expect {
- -re ".\[0-9\]+ = 0x\[0-9a-f\]+ \"foo\".*$prompt $"\
- { pass "print \"foo\"" }
- -re ".*$prompt $" { fail "print \"foo\"" }
- timeout { fail "(timeout) print \"foo\"" }
- }
-
-
- # and another step for good luck
- # This one fails on Solaris (for some versions of gdb) because you
- # can't step into library functions
- if $next_ok {
- send "step\n"
- expect {
- -re "cmdarg = .*xmalloc.*$prompt $" { pass "Another single step" }
- -re "if \(setjmp.*$prompt $" { pass "Another single step" }
- -re ".*No such file or directory.\r\n$prompt $" {
- pass "Another single step (no source available)"
- }
- -re ".*A file or directory in the path name does not exist..\r\n$prompt $" {
- pass "Another single step (no source available)"
- }
- -re ".*$prompt $" { fail "Another single step" }
- timeout { fail "(timeout) Another single step" }
- }
- }
-
- # start the "xgdb" process
- send "continue\n"
- expect {
- -re "GDB is free software and you are welcome to distribute copies of it.*
- under certain conditions; type \"show copying\" to see the conditions..*
- There is absolutely no warranty for GDB; type \"show warranty\" for details..*
- GDB.*Copyright \[0-9\]+ Free Software Foundation, Inc..*$prompt $"\
- { pass "xgdb is at prompt" }
- -re ".*$prompt $" { fail "xgdb is at prompt" }
- timeout { fail "(timeout) xgdb is at prompt" }
- }
-
- # set xgdb prompt so we can tell which is which
- send "set prompt (xgdb) \n"
- expect {
- -re "\(xgdb\) $" { pass "Set xgdb prompt" }
- -re ".*$prompt $" { fail "Set xgdb prompt" }
- timeout { fail "(timeout) Set xgdb prompt" }
- }
-
- # kill the xgdb process
- send "\Cc"
- expect {
- -re "Program received signal 2, Interrupt.*$prompt $" { pass "Sent ^C to xgdb" }
- -re ".*$prompt $" { fail "Sent ^C to xgdb" }
- timeout { fail "(timeout) Sent ^C to xgdb" }
- }
-
- send "signal 2\n"
- expect {
- -re "Continuing with signal 2.*$prompt $" { pass "Continuing with signal 2" }
- -re ".*$prompt $" { fail "Continuing with signal 2" }
- timeout { fail "(timeout) Continuing with signal 2" }
- }
-
- # get a stack trace
- setup_xfail "rs6000-*-*"
- send "backtrace\n"
- expect {
- -re "#0.*read.*#\[1-9\].*main.c.*$prompt $"\
- { pass "Got a stack trace" }
- -re ".*$prompt $" { fail "Got a stack trace" }
- timeout { fail "(timeout) Got a stack trace" }
- }
-
- # force GDB to dump core. On Solaris expect seems to not see the
- # final message, even if gdb did dump core, so we check for the
- # core dump explicitly if we time out.
- system rm -f core
- send "maint dump-me\n"
- expect {
- -re "Should GDB dump core\? \(y or n\) $" {
- send "y\n"
- expect {
- -re "Quit.*core dumped.*" { pass "GDB dumped core" }
- -re "Program received signal 3, Quit.* in kill.*$prompt $" {
- pass "GDB dumped core"
- }
- -re "$prompt $" { fail "GDB dumped core" }
- default {
- if [file exists core] then {
- pass "GDB dumped core"
- } else {
- fail "GDB dumped core"
- }
- }
- }
- }
- -re ".*$prompt $" { fail "GDB dumped core" }
- timeout { fail "(timeout) GDB dumped core" }
- }
- system rm -f core
-
- # Set the timeout back to the value it had when we were called.
- set timeout $oldtimeout
-
- # Restart gdb in case next text expects it to be started already.
- gdb_start
- return 0
- }
-
- # Find a pathname to a file that we would execute if the shell was asked
- # to run $arg using the current PATH.
-
- proc find_gdb { arg } {
-
- # If the arg directly specifies an existing executable file, then
- # simply use it.
-
- if [file executable $arg] then {
- return $arg
- }
-
- set result [which $arg]
- if [string match "/" [ string range $result 0 0 ]] then {
- return $result
- }
-
- # If everything fails, just return the unqualified pathname as default
- # and hope for best.
-
- return $arg
- }
-
- # Run the test with self.
- # Copy the file executable file in case this OS doesn't like to edit it's own
- # text space.
-
- set GDB_FULLPATH [find_gdb $GDB]
-
- if ![file executable $GDB_FULLPATH] then {
- fail "couldn't convert $GDB to absolute pathname to make local copy"
- } else {
- if [catch "exec cp $GDB_FULLPATH ./x$tool"] then {
- fail "couldn't copy $GDB_FULLPATH to current directory"
- } else {
- if $verbose>1 then {
- send_user "\t\tCopied $GDB_FULLPATH to ./x$tool\n"
- }
- if {[test_with_self] <0} then {
- warning "Couldn't test self"
- catch "exec rm -f ./x$tool"
- return -1
- }
- catch "exec rm -f ./x$tool"
- }
- }
-