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)"
310 # This one fails on Solaris (for some versions of gdb) because you
311 # can't next over library functions
312 setup_xfail "sparc-sun-solaris2" 1817
314 set need_to_step_over_cmdsize 1
315 set description "next over SET_TOP_LEVEL call"
318 -re "cmdsize = 1;.*$prompt $" {
321 -re "cmdarg = .*xmalloc.*$prompt $" {
322 # This can happen in optimized code where the "cmdsize = 1" line
323 # is basically removed.
325 set need_to_step_over_cmdsize 0
327 -re ".*No such file or directory.\r\n$prompt $" {
328 pass "$description (no source available)"
330 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
331 pass "$description (no source available)"
338 fail "$description (timeout)"
343 set description "print a string"
344 send "print \"foo\"\n"
346 -re ".\[0-9\]+ = \"foo\".*$prompt $" {
353 fail "$description (timeout)"
357 if $need_to_step_over_cmdsize {
358 set description "step over cmdsize initialization"
361 -re "cmdarg = .*xmalloc.*$prompt $" {
364 -re ".*No such file or directory.\r\n$prompt $" {
365 pass "$description (no source available)"
367 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
368 pass "$description (no source available)"
374 fail "$description" (timeout)"
379 # and another step for good luck
380 # This one fails on Solaris (for some versions of gdb) because you
381 # can't step into library functions
383 set description "step into xmalloc call"
386 -re "xmalloc.*size=.*at.*utils.c.*$prompt $" {
389 -re ".*No such file or directory.\r\n$prompt $" {
390 pass "$description (no source available)"
392 -re "A file or directory .* does not exist..\r\n$prompt $" {
393 pass "$description (no source available)"
399 fail "$description (timeout)"
404 # start the "xgdb" process
407 -re "GDB is free software and you are welcome to distribute copies of it.*
408 under certain conditions; type \"show copying\" to see the conditions..*
409 There is absolutely no warranty for GDB; type \"show warranty\" for details..*
410 GDB.*Copyright \[0-9\]+ Free Software Foundation, Inc..*$prompt $"\
411 { pass "xgdb is at prompt" }
412 -re ".*$prompt $" { fail "xgdb is at prompt" }
413 timeout { fail "(timeout) xgdb is at prompt" }
416 # set xgdb prompt so we can tell which is which
417 send "set prompt (xgdb) \n"
419 -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" { pass "Set xgdb prompt" }
420 -re ".*$prompt $" { fail "Set xgdb prompt" }
421 default { fail "(timeout) Set xgdb prompt" }
424 # kill the xgdb process
425 set description "send ^C to child process"
428 -re "Program received signal SIGINT.*$prompt $" {
435 fail "$description (timeout)"
439 set description "send SIGINT signal to child process"
440 send "signal SIGINT\n"
442 -re "Continuing with signal SIGINT.*$prompt $" {
449 fail "$description (timeout)"
454 setup_xfail "i486-*-sysv4"
455 set description "backtrace through signal handler"
458 -re "#0.*read.*#\[1-9\].*main.c.*$prompt $" {
465 fail "$description (timeout)"
471 # Set the timeout back to the value it had when we were called.
472 set timeout $oldtimeout
474 # Restart gdb in case next test expects it to be started already.
479 # Find a pathname to a file that we would execute if the shell was asked
480 # to run $arg using the current PATH.
482 proc find_gdb { arg } {
484 # If the arg directly specifies an existing executable file, then
487 if [file executable $arg] then {
491 set result [which $arg]
492 if [string match "/" [ string range $result 0 0 ]] then {
496 # If everything fails, just return the unqualified pathname as default
502 # Run the test with self.
503 # Copy the file executable file in case this OS doesn't like to edit it's own
506 set GDB_FULLPATH [find_gdb $GDB]
508 # Remove any old copy lying around.
509 catch "exec rm -f ./x$tool"
511 if ![file executable $GDB_FULLPATH] then {
512 fail "couldn't convert $GDB to absolute pathname to make local copy"
514 if [catch "exec cp $GDB_FULLPATH ./x$tool"] then {
515 fail "couldn't copy $GDB_FULLPATH to current directory"
517 verbose "\t\tCopied $GDB_FULLPATH to ./x$tool"
518 if {[test_with_self] <0} then {
519 warning "Couldn't test self"
520 catch "exec rm -f ./x$tool"
523 catch "exec rm -f ./x$tool"