1 # Copyright (C) 1988, 1990, 1991, 1992, 1994 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 Rob Savoye. (rob@cygnus.com)
29 # are we on a target board
31 warning "These test cases can't run on a target system."
34 if [istarget "m68k*-*-hpux*"] then {
35 # The top-level makefile passes CFLAGS= (no -g) for hp300. This probably
36 # should be fixed (it is only needed for gcc bootstrapping, not gdb),
39 fail "cannot test self if compiled without debug info"
43 proc test_with_self {} {
50 # load yourself into the debugger
51 # This can take a relatively long time, particularly for testing where
52 # the executable is being accessed over a network, or where gdb does not
53 # support partial symbols for a particular target and has to load the
54 # entire symbol table. Set the timeout to 10 minutes, which should be
55 # adequate for most environments (it *has* timed out with 5 min on a
56 # SPARCstation SLC under moderate load, so this isn't unreasonable).
57 # After gdb is loaded, set the timeout to 30 seconds for the duration
58 # of this test, and then back to the original value.
60 set oldtimeout $timeout
62 if {[gdb_load "./x$tool"] <0} then {
68 # disassemble yourself
71 -re "x/10i.*main.*main.$decimal.*main.$decimal.*$prompt $"\
72 { pass "Disassemble main" }
73 -re ".*$prompt $" { fail "Disassemble main" }
74 timeout { fail "(timeout) Disassemble main" }
77 set description "set breakpoint at main"
80 -re "Breakpoint.*at.* file.*, line.*$prompt $" {
87 fail "$description (timeout)"
91 # We'll need this when we send a ^C to GDB. Need to do it before we
92 # run the program and gdb starts saving and restoring tty states.
93 # On Ultrix, we don't need it and it is really slow (because shell_escape
95 if ![istarget "*-*-ultrix*"] then {
96 gdb_test "shell stty intr '^C'" "" \
97 "set interrupt character in test_with_self"
101 set description "run until breakpoint at main"
104 -re "Starting program.*Breakpoint \[0-9\]+,.*main .argc.*argv.* at .*main.c:.*$prompt $" {
107 -re "Starting program.*Breakpoint \[0-9\]+,.*main .argc.*argv.*$prompt $" {
108 xfail "$description (line numbers scrambled?)"
110 -re "vfork: No more processes.*$prompt $" {
111 fail "$description (out of virtual memory)"
119 fail "$description (timeout)"
123 # do we have a version number ?
124 send "print version\n"
126 -re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$prompt $" {
127 pass "printed version"
129 -re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$prompt $" {
130 pass "printed version with cast"
132 -re ".*$prompt $" { fail "printed version" }
133 timeout { fail "(timeout) printed version" }
136 # lets do a few single steps
138 set description "step over symarg initialization"
141 -re "char \[*\]+execarg = NULL;.*$prompt $" {
144 -re ".*No such file or directory.\r\n$prompt $" {
145 pass "$description (no source available)"
147 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
148 pass "$description (no source available)"
154 fail "$description (timeout)"
158 set description "step over execarg initialization"
161 -re "char \[*\]corearg = NULL;.*$prompt $" {
164 -re ".*No such file or directory.\r\n$prompt $" {
165 pass "$description (no source available)"
167 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
168 pass "$description (no source available)"
174 fail "$description" (timeout)"
178 set description "step over corearg initialization"
181 -re "char \[*\]cdarg = NULL;.*$prompt $" {
184 -re ".*No such file or directory.\r\n$prompt $" {
185 pass "$description (no source available)"
187 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
188 pass "$description (no source available)"
194 fail "$description" (timeout)"
198 set description "step over cdarg initialization"
201 -re "char \[*\]ttyarg = NULL;.*$prompt $" {
204 -re ".*No such file or directory.\r\n$prompt $" {
205 pass "$description (no source available)"
207 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
208 pass "$description (no source available)"
214 fail "$description" (timeout)"
218 set description "step over ttyarg initialization"
221 -re ".*time_at_startup = get_run_time .*$prompt $" {
224 -re ".*No such file or directory.\r\n$prompt $" {
225 pass "$description (no source available)"
227 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
228 pass "$description (no source available)"
234 fail "$description" (timeout)"
238 # now jump over a few functions
240 set description "next over get_run_time and everything it calls"
241 set got_over_get_run_time 0
244 -re ".*init_malloc.*$prompt $" {
246 set got_over_get_run_time 1
248 -re ".*No such file or directory.\r\n$prompt $" {
249 pass "$description (no source available)"
250 set got_over_get_run_time 1
252 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
253 pass "$description (no source available)"
254 set got_over_get_run_time 1
260 fail "$description (timeout)"
263 # -re "if \(setmp \(to_top_level\)\).*$prompt $" { pass "first next" }
265 if $got_over_get_run_time then {
266 set description "next over init_malloc and everything it calls"
269 -re "if.*SET_TOP_LEVEL.*$prompt $" {
272 -re "i = .*count.*$prompt $" {
274 set description "next over ALIGN_STACK_ON_STARTUP code"
277 -re "if.*i != 0.*$prompt $" {
281 -re "if.*SET_TOP_LEVEL.*$prompt $" {
284 -re "alloca.*$prompt $" {
287 -re "if.*level.*$prompt $" {
296 -re ".*No such file or directory.\r\n$prompt $" {
297 pass "$description (no source available)"
299 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
300 pass "$description (no source available)"
306 fail "$description (timeout or eof)"
311 # This one fails on Solaris (for some versions of gdb) because you
312 # can't next over library functions
313 setup_xfail "sparc-sun-solaris2" 1817
315 set need_to_step_over_cmdsize 1
316 set description "next over SET_TOP_LEVEL call"
319 -re "cmdsize = 1;.*$prompt $" {
322 -re "cmdarg = .*xmalloc.*$prompt $" {
323 # This can happen in optimized code where the "cmdsize = 1" line
324 # is basically removed.
326 set need_to_step_over_cmdsize 0
328 -re ".*No such file or directory.\r\n$prompt $" {
329 pass "$description (no source available)"
331 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
332 pass "$description (no source available)"
339 fail "$description (timeout)"
344 set description "print a string"
345 send "print \"foo\"\n"
347 -re ".\[0-9\]+ = \"foo\".*$prompt $" {
354 fail "$description (timeout)"
358 if $need_to_step_over_cmdsize {
359 set description "step over cmdsize initialization"
362 -re "cmdarg = .*xmalloc.*$prompt $" {
365 -re ".*No such file or directory.\r\n$prompt $" {
366 pass "$description (no source available)"
368 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
369 pass "$description (no source available)"
375 fail "$description" (timeout)"
380 # and another step for good luck
381 # This one fails on Solaris (for some versions of gdb) because you
382 # can't step into library functions
384 set description "step into xmalloc call"
387 -re "xmalloc.*size=.*at.*utils.c.*$prompt $" {
390 -re ".*No such file or directory.\r\n$prompt $" {
391 pass "$description (no source available)"
393 -re "A file or directory .* does not exist..\r\n$prompt $" {
394 pass "$description (no source available)"
400 fail "$description (timeout)"
405 # start the "xgdb" process
408 -re "GDB is free software and you are welcome to distribute copies of it.*
409 under certain conditions; type \"show copying\" to see the conditions..*
410 There is absolutely no warranty for GDB; type \"show warranty\" for details..*
411 GDB.*Copyright \[0-9\]+ Free Software Foundation, Inc..*$prompt $"\
412 { pass "xgdb is at prompt" }
413 -re ".*$prompt $" { fail "xgdb is at prompt" }
414 timeout { fail "(timeout) xgdb is at prompt" }
417 # set xgdb prompt so we can tell which is which
418 send "set prompt (xgdb) \n"
420 -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" { pass "Set xgdb prompt" }
421 -re ".*$prompt $" { fail "Set xgdb prompt" }
422 default { fail "(timeout) Set xgdb prompt" }
425 # kill the xgdb process
426 set description "send ^C to child process"
429 -re "Program received signal SIGINT.*$prompt $" {
436 fail "$description (timeout)"
440 set description "send SIGINT signal to child process"
441 send "signal SIGINT\n"
443 -re "Continuing with signal SIGINT.*$prompt $" {
450 fail "$description (timeout)"
455 setup_xfail "i486-*-sysv4"
456 set description "backtrace through signal handler"
459 -re "#0.*read.*#\[1-9\].*main.c.*$prompt $" {
466 fail "$description (timeout)"
472 # Set the timeout back to the value it had when we were called.
473 set timeout $oldtimeout
475 # Restart gdb in case next test expects it to be started already.
480 # Find a pathname to a file that we would execute if the shell was asked
481 # to run $arg using the current PATH.
483 proc find_gdb { arg } {
485 # If the arg directly specifies an existing executable file, then
488 if [file executable $arg] then {
492 set result [which $arg]
493 if [string match "/" [ string range $result 0 0 ]] then {
497 # If everything fails, just return the unqualified pathname as default
503 # Run the test with self.
504 # Copy the file executable file in case this OS doesn't like to edit it's own
507 set GDB_FULLPATH [find_gdb $GDB]
509 # Remove any old copy lying around.
510 catch "exec rm -f ./x$tool"
512 if ![file executable $GDB_FULLPATH] then {
513 fail "couldn't convert $GDB to absolute pathname to make local copy"
515 if [catch "exec cp $GDB_FULLPATH ./x$tool"] then {
516 fail "couldn't copy $GDB_FULLPATH to current directory"
518 verbose "\t\tCopied $GDB_FULLPATH to ./x$tool"
519 if {[test_with_self] <0} then {
520 warning "Couldn't test self"
521 catch "exec rm -f ./x$tool"
524 catch "exec rm -f ./x$tool"