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 {} {
48 # load yourself into the debugger
49 # This can take a relatively long time, particularly for testing where
50 # the executable is being accessed over a network, or where gdb does not
51 # support partial symbols for a particular target and has to load the
52 # entire symbol table. Set the timeout to 10 minutes, which should be
53 # adequate for most environments (it *has* timed out with 5 min on a
54 # SPARCstation SLC under moderate load, so this isn't unreasonable).
55 # After gdb is loaded, set the timeout to 30 seconds for the duration
56 # of this test, and then back to the original value.
59 if {[gdb_load "./x$tool"] <0} then {
65 # disassemble yourself
68 -re "x/10i.*main.*main.$decimal.*main.$decimal.*$prompt $"\
69 { pass "Disassemble main" }
70 -re ".*$prompt $" { fail "Disassemble main" }
71 timeout { fail "(timeout) Disassemble main" }
74 set description "set breakpoint at main"
77 -re "Breakpoint.*at.* file.*, line.*$prompt $" {
84 fail "$description (timeout)"
88 # We'll need this when we send a ^C to GDB. Need to do it before we
89 # run the program and gdb starts saving and restoring tty states.
90 # On Ultrix, we don't need it and it is really slow (because shell_escape
92 if ![istarget "*-*-ultrix*"] then {
93 gdb_test "shell stty intr '^C'" "" \
94 "set interrupt character in test_with_self"
98 set description "run until breakpoint at main"
101 -re "Starting program.*Breakpoint \[0-9\]+,.*main .argc.*argv.* at .*main.c:.*$prompt $" {
104 -re "Starting program.*Breakpoint \[0-9\]+,.*main .argc.*argv.*$prompt $" {
105 xfail "$description (line numbers scrambled?)"
107 -re "vfork: No more processes.*$prompt $" {
108 fail "$description (out of virtual memory)"
116 fail "$description (timeout)"
120 # do we have a version number ?
121 send "print version\n"
123 -re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$prompt $" {
124 pass "printed version"
126 -re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$prompt $" {
127 pass "printed version with cast"
129 -re ".*$prompt $" { fail "printed version" }
130 timeout { fail "(timeout) printed version" }
133 # lets do a few single steps
135 set description "step over symarg initialization"
138 -re "char \[*\]+execarg = NULL;.*$prompt $" {
141 -re ".*No such file or directory.\r\n$prompt $" {
142 pass "$description (no source available)"
144 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
145 pass "$description (no source available)"
151 fail "$description (timeout)"
155 set description "step over execarg initialization"
158 -re "char \[*\]corearg = NULL;.*$prompt $" {
161 -re ".*No such file or directory.\r\n$prompt $" {
162 pass "$description (no source available)"
164 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
165 pass "$description (no source available)"
171 fail "$description" (timeout)"
175 set description "step over corearg initialization"
178 -re "char \[*\]cdarg = NULL;.*$prompt $" {
181 -re ".*No such file or directory.\r\n$prompt $" {
182 pass "$description (no source available)"
184 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
185 pass "$description (no source available)"
191 fail "$description" (timeout)"
195 set description "step over cdarg initialization"
198 -re "char \[*\]ttyarg = NULL;.*$prompt $" {
201 -re ".*No such file or directory.\r\n$prompt $" {
202 pass "$description (no source available)"
204 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
205 pass "$description (no source available)"
211 fail "$description" (timeout)"
215 set description "step over ttyarg initialization"
218 -re ".*time_at_startup = get_run_time .*$prompt $" {
221 -re ".*No such file or directory.\r\n$prompt $" {
222 pass "$description (no source available)"
224 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
225 pass "$description (no source available)"
231 fail "$description" (timeout)"
235 # now jump over a few functions
237 set description "next over get_run_time and everything it calls"
238 set got_over_get_run_time 0
241 -re ".*init_malloc.*$prompt $" {
243 set got_over_get_run_time 1
245 -re ".*No such file or directory.\r\n$prompt $" {
246 pass "$description (no source available)"
247 set got_over_get_run_time 1
249 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
250 pass "$description (no source available)"
251 set got_over_get_run_time 1
257 fail "$description (timeout)"
260 # -re "if \(setmp \(to_top_level\)\).*$prompt $" { pass "first next" }
262 if $got_over_get_run_time then {
263 set description "next over init_malloc and everything it calls"
266 -re "if.*SET_TOP_LEVEL.*$prompt $" {
269 -re "i = .*count.*$prompt $" {
271 set description "next over ALIGN_STACK_ON_STARTUP code"
274 -re "if.*i != 0.*$prompt $" {
278 -re "if.*SET_TOP_LEVEL.*$prompt $" {
281 -re "alloca.*$prompt $" {
284 -re "if.*level.*$prompt $" {
293 -re ".*No such file or directory.\r\n$prompt $" {
294 pass "$description (no source available)"
296 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
297 pass "$description (no source available)"
303 fail "$description (timeout or eof)"
309 set need_to_step_over_cmdsize 1
310 set description "next over SET_TOP_LEVEL call"
313 -re "cmdsize = 1;.*$prompt $" {
316 -re "cmdarg = .*xmalloc.*$prompt $" {
317 # This can happen in optimized code where the "cmdsize = 1" line
318 # is basically removed.
320 set need_to_step_over_cmdsize 0
322 -re ".*No such file or directory.\r\n$prompt $" {
323 pass "$description (no source available)"
325 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
326 pass "$description (no source available)"
333 fail "$description (timeout)"
338 set description "print a string"
339 send "print \"foo\"\n"
341 -re ".\[0-9\]+ = \"foo\".*$prompt $" {
348 fail "$description (timeout)"
352 if $need_to_step_over_cmdsize {
353 set description "step over cmdsize initialization"
356 -re "cmdarg = .*xmalloc.*$prompt $" {
359 -re ".*No such file or directory.\r\n$prompt $" {
360 pass "$description (no source available)"
362 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
363 pass "$description (no source available)"
369 fail "$description" (timeout)"
374 # and another step for good luck
376 set description "step into xmalloc call"
379 -re "xmalloc.*size=.*at.*utils.c.*$prompt $" {
382 -re ".*No such file or directory.\r\n$prompt $" {
383 pass "$description (no source available)"
385 -re "A file or directory .* does not exist..\r\n$prompt $" {
386 pass "$description (no source available)"
392 fail "$description (timeout)"
397 # start the "xgdb" process
400 -re "GDB is free software and you are welcome to distribute copies of it.*
401 under certain conditions; type \"show copying\" to see the conditions..*
402 There is absolutely no warranty for GDB; type \"show warranty\" for details..*
403 GDB.*Copyright \[0-9\]+ Free Software Foundation, Inc..*$prompt $"\
404 { pass "xgdb is at prompt" }
405 -re ".*$prompt $" { fail "xgdb is at prompt" }
406 timeout { fail "(timeout) xgdb is at prompt" }
409 # set xgdb prompt so we can tell which is which
410 send "set prompt (xgdb) \n"
412 -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" { pass "Set xgdb prompt" }
413 -re ".*$prompt $" { fail "Set xgdb prompt" }
414 default { fail "(timeout) Set xgdb prompt" }
417 # kill the xgdb process
418 set description "send ^C to child process"
421 -re "Program received signal SIGINT.*$prompt $" {
428 fail "$description (timeout)"
432 set description "send SIGINT signal to child process"
433 send "signal SIGINT\n"
435 -re "Continuing with signal SIGINT.*$prompt $" {
442 fail "$description (timeout)"
447 setup_xfail "i486-*-sysv4"
448 set description "backtrace through signal handler"
451 -re "#0.*read.*in main \\(.*\\) at .*main\\.c.*$prompt $" {
455 # On the alpha, we hit the infamous problem about gdb
456 # being unable to get the frame pointer (mentioned in
457 # gdb/README). As it is intermittent, there is no way to
458 # XFAIL it which will give us an XPASS if the problem goes
460 setup_xfail "alpha*-*-osf*"
464 fail "$description (timeout)"
470 # Set the timeout back to the value it had when we were called.
472 # Restart gdb in case next test expects it to be started already.
477 # Find a pathname to a file that we would execute if the shell was asked
478 # to run $arg using the current PATH.
480 proc find_gdb { arg } {
482 # If the arg directly specifies an existing executable file, then
485 if [file executable $arg] then {
489 set result [which $arg]
490 if [string match "/" [ string range $result 0 0 ]] then {
494 # If everything fails, just return the unqualified pathname as default
500 # Run the test with self.
501 # Copy the file executable file in case this OS doesn't like to edit it's own
504 set GDB_FULLPATH [find_gdb $GDB]
506 # Remove any old copy lying around.
507 catch "exec rm -f ./x$tool"
509 if ![file executable $GDB_FULLPATH] then {
510 fail "couldn't convert $GDB to absolute pathname to make local copy"
512 if [catch "exec cp $GDB_FULLPATH ./x$tool"] then {
513 fail "couldn't copy $GDB_FULLPATH to current directory"
515 verbose "\t\tCopied $GDB_FULLPATH to ./x$tool"
516 if {[test_with_self] <0} then {
517 warning "Couldn't test self"
518 catch "exec rm -f ./x$tool"
521 catch "exec rm -f ./x$tool"