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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 started, 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 {
63 # disassemble yourself
66 -re "x/10i.*main.*main.$decimal.*main.$decimal.*$prompt $"\
67 { pass "Disassemble main" }
68 -re ".*$prompt $" { fail "Disassemble main" }
69 timeout { fail "(timeout) Disassemble main" }
72 set description "set breakpoint at main"
75 -re "Breakpoint.*at.* file.*, line.*$prompt $" {
82 fail "$description (timeout)"
86 # We'll need this when we send a ^C to GDB. Need to do it before we
87 # run the program and gdb starts saving and restoring tty states.
88 # On Ultrix, we don't need it and it is really slow (because shell_escape
90 if ![istarget "*-*-ultrix*"] then {
91 gdb_test "shell stty intr '^C'" "" \
92 "set interrupt character in test_with_self"
96 set description "run until breakpoint at main"
99 -re "Starting program.*Breakpoint \[0-9\]+,.*main .argc.*argv.* at .*main.c:.*$prompt $" {
102 -re "Starting program.*Breakpoint \[0-9\]+,.*main .argc.*argv.*$prompt $" {
103 xfail "$description (line numbers scrambled?)"
105 -re "vfork: No more processes.*$prompt $" {
106 fail "$description (out of virtual memory)"
114 fail "$description (timeout)"
118 # It may take a very long time for the inferior gdb to start (lynx),
119 # so we wait until after it's started to reset the timeout value.
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 setup_xfail "alpha-dec-osf2*"
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 setup_xfail "alpha-dec-osf2*"
179 set description "step over corearg initialization"
182 -re "char \[*\]cdarg = NULL;.*$prompt $" {
185 -re ".*No such file or directory.\r\n$prompt $" {
186 pass "$description (no source available)"
188 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
189 pass "$description (no source available)"
195 fail "$description (timeout)"
199 set description "step over cdarg initialization"
202 -re "char \[*\]ttyarg = NULL;.*$prompt $" {
205 -re ".*No such file or directory.\r\n$prompt $" {
206 pass "$description (no source available)"
208 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
209 pass "$description (no source available)"
215 fail "$description (timeout)"
219 set description "step over ttyarg initialization"
222 -re ".*time_at_startup = get_run_time .*$prompt $" {
225 -re ".*No such file or directory.\r\n$prompt $" {
226 pass "$description (no source available)"
228 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
229 pass "$description (no source available)"
235 fail "$description (timeout)"
239 # now jump over a few functions
241 set description "next over get_run_time and everything it calls"
242 set got_over_get_run_time 0
245 -re ".*init_malloc.*$prompt $" {
247 set got_over_get_run_time 1
249 -re ".*No such file or directory.\r\n$prompt $" {
250 pass "$description (no source available)"
251 set got_over_get_run_time 1
253 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
254 pass "$description (no source available)"
255 set got_over_get_run_time 1
261 fail "$description (timeout)"
264 # -re "if \(setmp \(to_top_level\)\).*$prompt $" { pass "first next" }
266 if $got_over_get_run_time then {
267 set description "next over init_malloc and everything it calls"
270 -re "if.*SET_TOP_LEVEL.*$prompt $" {
273 -re "i = .*count.*$prompt $" {
275 set description "next over ALIGN_STACK_ON_STARTUP code"
278 -re "if.*i != 0.*$prompt $" {
282 -re "if.*SET_TOP_LEVEL.*$prompt $" {
285 -re "alloca.*$prompt $" {
288 -re "if.*level.*$prompt $" {
297 -re ".*No such file or directory.\r\n$prompt $" {
298 pass "$description (no source available)"
300 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
301 pass "$description (no source available)"
307 fail "$description (timeout or eof)"
313 set need_to_step_over_cmdsize 1
314 set description "next over SET_TOP_LEVEL call"
317 -re "cmdsize = 1;.*$prompt $" {
320 -re "cmdarg = .*xmalloc.*$prompt $" {
321 # This can happen in optimized code where the "cmdsize = 1" line
322 # is basically removed.
324 set need_to_step_over_cmdsize 0
326 -re ".*No such file or directory.\r\n$prompt $" {
327 pass "$description (no source available)"
329 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
330 pass "$description (no source available)"
337 fail "$description (timeout)"
342 set description "print a string"
343 send "print \"foo\"\n"
345 -re ".\[0-9\]+ = \"foo\".*$prompt $" {
352 fail "$description (timeout)"
356 if $need_to_step_over_cmdsize {
357 set description "step over cmdsize initialization"
360 -re "cmdarg = .*xmalloc.*$prompt $" {
363 -re ".*No such file or directory.\r\n$prompt $" {
364 pass "$description (no source available)"
366 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
367 pass "$description (no source available)"
373 fail "$description (timeout)"
378 # and another step for good luck
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 "i*86-*-linuxaout"
452 set description "backtrace through signal handler"
455 -re "#0.*read.*in main \\(.*\\) at .*main\\.c.*$prompt $" {
459 # On the alpha, we hit the infamous problem about gdb
460 # being unable to get the frame pointer (mentioned in
461 # gdb/README). As it is intermittent, there is no way to
462 # XFAIL it which will give us an XPASS if the problem goes
464 setup_xfail "alpha*-*-osf*"
468 fail "$description (timeout)"
474 # Set the timeout back to the value it had when we were called.
476 # Restart gdb in case next test expects it to be started already.
481 # Find a pathname to a file that we would execute if the shell was asked
482 # to run $arg using the current PATH.
484 proc find_gdb { arg } {
486 # If the arg directly specifies an existing executable file, then
489 if [file executable $arg] then {
493 set result [which $arg]
494 if [string match "/" [ string range $result 0 0 ]] then {
498 # If everything fails, just return the unqualified pathname as default
504 # Run the test with self.
505 # Copy the file executable file in case this OS doesn't like to edit it's own
508 set GDB_FULLPATH [find_gdb $GDB]
510 # Remove any old copy lying around.
511 catch "exec rm -f ./x$tool"
513 if ![file executable $GDB_FULLPATH] then {
514 fail "couldn't convert $GDB to absolute pathname to make local copy"
516 if [catch "exec cp $GDB_FULLPATH ./x$tool"] then {
517 fail "couldn't copy $GDB_FULLPATH to current directory"
519 verbose "\t\tCopied $GDB_FULLPATH to ./x$tool"
520 if {[test_with_self] <0} then {
521 warning "Couldn't test self"
522 catch "exec rm -f ./x$tool"
525 catch "exec rm -f ./x$tool"