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
33 if [istarget "m68k*-*-hpux*"] then {
34 # The top-level makefile passes CFLAGS= (no -g) for hp300. This probably
35 # should be fixed (it is only needed for gcc bootstrapping, not gdb),
38 fail "cannot test self if compiled without debug info"
42 proc test_with_self {} {
49 # load yourself into the debugger
50 # This can take a relatively long time, particularly for testing where
51 # the executable is being accessed over a network, or where gdb does not
52 # support partial symbols for a particular target and has to load the
53 # entire symbol table. Set the timeout to 10 minutes, which should be
54 # adequate for most environments (it *has* timed out with 5 min on a
55 # SPARCstation SLC under moderate load, so this isn't unreasonable).
56 # After gdb is loaded, set the timeout to 30 seconds for the duration
57 # of this test, and then back to the original value.
59 set oldtimeout $timeout
61 if {[gdb_load "./x$tool"] <0} then {
67 # disassemble yourself
70 -re "x/10i.*main.*main.$decimal.*main.$decimal.*$prompt $"\
71 { pass "Disassemble main" }
72 -re ".*$prompt $" { fail "Disassemble main" }
73 timeout { fail "(timeout) Disassemble main" }
76 set description "set breakpoint at main"
79 -re "Breakpoint.*at.* file.*, line.*$prompt $" {
86 fail "$description (timeout)"
90 # We'll need this when we send a ^C to GDB. Need to do it before we
91 # run the program and gdb starts saving and restoring tty states.
92 # On Ultrix, we don't need it and it is really slow (because shell_escape
94 if ![istarget "*-*-ultrix*"] then {
95 gdb_test "shell stty intr '^C'" "" \
96 "set interrupt character in test_with_self"
100 set description "run until breakpoint at main"
103 -re "Starting program.*Breakpoint \[0-9\]+,.*main .argc.*argv.* at .*main.c:.*$prompt $" {
106 -re "Starting program.*Breakpoint \[0-9\]+,.*main .argc.*argv.*$prompt $" {
107 xfail "$description (line numbers scrambled?)"
109 -re "vfork: No more processes.*$prompt $" {
110 fail "$description (out of virtual memory)"
118 fail "$description (timeout)"
122 # do we have a version number ?
123 send "print version\n"
125 -re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$prompt $" {
126 pass "printed version"
128 -re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$prompt $" {
129 pass "printed version with cast"
131 -re ".*$prompt $" { fail "printed version" }
132 timeout { fail "(timeout) printed version" }
135 # lets do a few single steps
137 set description "step over symarg initialization"
140 -re "char \[*\]+execarg = NULL;.*$prompt $" {
143 -re ".*No such file or directory.\r\n$prompt $" {
144 pass "$description (no source available)"
146 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
147 pass "$description (no source available)"
153 fail "$description (timeout)"
157 set description "step over execarg initialization"
160 -re "char \[*\]corearg = NULL;.*$prompt $" {
163 -re ".*No such file or directory.\r\n$prompt $" {
164 pass "$description (no source available)"
166 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
167 pass "$description (no source available)"
173 fail "$description" (timeout)"
177 set description "step over corearg initialization"
180 -re "char \[*\]cdarg = NULL;.*$prompt $" {
183 -re ".*No such file or directory.\r\n$prompt $" {
184 pass "$description (no source available)"
186 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
187 pass "$description (no source available)"
193 fail "$description" (timeout)"
197 set description "step over cdarg initialization"
200 -re "char \[*\]ttyarg = NULL;.*$prompt $" {
203 -re ".*No such file or directory.\r\n$prompt $" {
204 pass "$description (no source available)"
206 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
207 pass "$description (no source available)"
213 fail "$description" (timeout)"
217 set description "step over ttyarg initialization"
220 -re ".*time_at_startup = get_run_time .*$prompt $" {
223 -re ".*No such file or directory.\r\n$prompt $" {
224 pass "$description (no source available)"
226 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
227 pass "$description (no source available)"
233 fail "$description" (timeout)"
237 # now jump over a few functions
239 set description "next over get_run_time and everything it calls"
240 set got_over_get_run_time 0
243 -re ".*init_malloc.*$prompt $" {
245 set got_over_get_run_time 1
247 -re ".*No such file or directory.\r\n$prompt $" {
248 pass "$description (no source available)"
249 set got_over_get_run_time 1
251 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
252 pass "$description (no source available)"
253 set got_over_get_run_time 1
259 fail "$description (timeout)"
262 # -re "if \(setmp \(to_top_level\)\).*$prompt $" { pass "first next" }
264 if $got_over_get_run_time then {
265 set description "next over init_malloc and everything it calls"
268 -re "if.*SET_TOP_LEVEL.*$prompt $" {
271 -re "i = .*count.*$prompt $" {
273 set description "next over ALIGN_STACK_ON_STARTUP code"
276 -re "if.*i != 0.*$prompt $" {
280 -re "if.*SET_TOP_LEVEL.*$prompt $" {
283 -re "alloca.*$prompt $" {
286 -re "if.*level.*$prompt $" {
295 -re ".*No such file or directory.\r\n$prompt $" {
296 pass "$description (no source available)"
298 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
299 pass "$description (no source available)"
305 fail "$description (timeout or eof)"
311 set need_to_step_over_cmdsize 1
312 set description "next over SET_TOP_LEVEL call"
315 -re "cmdsize = 1;.*$prompt $" {
318 -re "cmdarg = .*xmalloc.*$prompt $" {
319 # This can happen in optimized code where the "cmdsize = 1" line
320 # is basically removed.
322 set need_to_step_over_cmdsize 0
324 -re ".*No such file or directory.\r\n$prompt $" {
325 pass "$description (no source available)"
327 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
328 pass "$description (no source available)"
335 fail "$description (timeout)"
340 set description "print a string"
341 send "print \"foo\"\n"
343 -re ".\[0-9\]+ = \"foo\".*$prompt $" {
350 fail "$description (timeout)"
354 if $need_to_step_over_cmdsize {
355 set description "step over cmdsize initialization"
358 -re "cmdarg = .*xmalloc.*$prompt $" {
361 -re ".*No such file or directory.\r\n$prompt $" {
362 pass "$description (no source available)"
364 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
365 pass "$description (no source available)"
371 fail "$description" (timeout)"
376 # and another step for good luck
377 # This one fails on Solaris (for some versions of gdb) because you
378 # can't step into library functions
380 set description "step into xmalloc call"
383 -re "xmalloc.*size=.*at.*utils.c.*$prompt $" {
386 -re ".*No such file or directory.\r\n$prompt $" {
387 pass "$description (no source available)"
389 -re "A file or directory .* does not exist..\r\n$prompt $" {
390 pass "$description (no source available)"
396 fail "$description (timeout)"
401 # start the "xgdb" process
404 -re "GDB is free software and you are welcome to distribute copies of it.*
405 under certain conditions; type \"show copying\" to see the conditions..*
406 There is absolutely no warranty for GDB; type \"show warranty\" for details..*
407 GDB.*Copyright \[0-9\]+ Free Software Foundation, Inc..*$prompt $"\
408 { pass "xgdb is at prompt" }
409 -re ".*$prompt $" { fail "xgdb is at prompt" }
410 timeout { fail "(timeout) xgdb is at prompt" }
413 # set xgdb prompt so we can tell which is which
414 send "set prompt (xgdb) \n"
416 -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" { pass "Set xgdb prompt" }
417 -re ".*$prompt $" { fail "Set xgdb prompt" }
418 default { fail "(timeout) Set xgdb prompt" }
421 # kill the xgdb process
422 set description "send ^C to child process"
425 -re "Program received signal SIGINT.*$prompt $" {
432 fail "$description (timeout)"
436 set description "send SIGINT signal to child process"
437 send "signal SIGINT\n"
439 -re "Continuing with signal SIGINT.*$prompt $" {
446 fail "$description (timeout)"
451 setup_xfail "i486-*-sysv4"
452 set description "backtrace through signal handler"
455 -re "#0.*read.*#\[1-9\].*main.c.*$prompt $" {
462 fail "$description (timeout)"
468 # Set the timeout back to the value it had when we were called.
469 set timeout $oldtimeout
471 # Restart gdb in case next test expects it to be started already.
476 # Find a pathname to a file that we would execute if the shell was asked
477 # to run $arg using the current PATH.
479 proc find_gdb { arg } {
481 # If the arg directly specifies an existing executable file, then
484 if [file executable $arg] then {
488 set result [which $arg]
489 if [string match "/" [ string range $result 0 0 ]] then {
493 # If everything fails, just return the unqualified pathname as default
499 # Run the test with self.
500 # Copy the file executable file in case this OS doesn't like to edit it's own
503 set GDB_FULLPATH [find_gdb $GDB]
505 # Remove any old copy lying around.
506 catch "exec rm -f ./x$tool"
508 if ![file executable $GDB_FULLPATH] then {
509 fail "couldn't convert $GDB to absolute pathname to make local copy"
511 if [catch "exec cp $GDB_FULLPATH ./x$tool"] then {
512 fail "couldn't copy $GDB_FULLPATH to current directory"
514 verbose "\t\tCopied $GDB_FULLPATH to ./x$tool"
515 if {[test_with_self] <0} then {
516 warning "Couldn't test self"
517 catch "exec rm -f ./x$tool"
520 catch "exec rm -f ./x$tool"