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."
35 proc test_with_self {} {
42 # load yourself into the debugger
43 # This can take a relatively long time, particularly for testing where
44 # the executable is being accessed over a network, or where gdb does not
45 # support partial symbols for a particular target and has to load the
46 # entire symbol table. Set the timeout to 10 minutes, which should be
47 # adequate for most environments (it *has* timed out with 5 min on a
48 # SPARCstation SLC under moderate load, so this isn't unreasonable).
49 # After gdb is loaded, set the timeout to 30 seconds for the duration
50 # of this test, and then back to the original value.
52 set oldtimeout $timeout
54 if {[gdb_load "./x$tool"] <0} then {
60 # disassemble yourself
63 -re "x/10i.*main.*main.$decimal.*main.$decimal.*$prompt $"\
64 { pass "Disassemble main" }
65 -re ".*$prompt $" { fail "Disassemble main" }
66 timeout { fail "(timeout) Disassemble main" }
69 set description "set breakpoint at main"
72 -re "Breakpoint.*at.* file.*, line.*$prompt $" {
79 fail "$description (timeout)"
84 set description "run until breakpoint at main"
87 -re "Starting program.*Breakpoint \[0-9\]+,.*main .argc.*argv.* at .*main.c:.*$prompt $" {
90 -re "Starting program.*Breakpoint \[0-9\]+,.*main .argc.*argv.*$prompt $" {
91 xfail "$description (line numbers scrambled?)"
93 -re "vfork: No more processes.*$prompt $" {
94 fail "$description (out of virtual memory)"
102 fail "$description (timeout)"
106 # do we have a version number ?
107 send "print version\n"
109 -re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$prompt $" {
110 pass "printed version"
112 -re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$prompt $" {
113 pass "printed version with cast"
115 -re ".*$prompt $" { fail "printed version" }
116 timeout { fail "(timeout) printed version" }
119 # lets do a few single steps
121 set description "step over symarg initialization"
124 -re "char \[*\]+execarg = NULL;.*$prompt $" {
127 -re ".*No such file or directory.\r\n$prompt $" {
128 pass "$description (no source available)"
130 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
131 pass "$description (no source available)"
137 fail "$description (timeout)"
141 set description "step over execarg initialization"
144 -re "char \[*\]corearg = NULL;.*$prompt $" {
147 -re ".*No such file or directory.\r\n$prompt $" {
148 pass "$description (no source available)"
150 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
151 pass "$description (no source available)"
157 fail "$description" (timeout)"
161 set description "step over corearg initialization"
164 -re "char \[*\]cdarg = NULL;.*$prompt $" {
167 -re ".*No such file or directory.\r\n$prompt $" {
168 pass "$description (no source available)"
170 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
171 pass "$description (no source available)"
177 fail "$description" (timeout)"
181 set description "step over cdarg initialization"
184 -re "char \[*\]ttyarg = NULL;.*$prompt $" {
187 -re ".*No such file or directory.\r\n$prompt $" {
188 pass "$description (no source available)"
190 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
191 pass "$description (no source available)"
197 fail "$description" (timeout)"
201 set description "step over ttyarg initialization"
204 -re "init_malloc.* NULL.*$prompt $" {
207 -re ".*No such file or directory.\r\n$prompt $" {
208 pass "$description (no source available)"
210 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
211 pass "$description (no source available)"
217 fail "$description" (timeout)"
221 # now jump over a few functions
223 set description "next over init_malloc and everything it calls"
226 -re "if.*SET_TOP_LEVEL.*$prompt $" {
229 -re "i = .*count.*$prompt $" {
231 set description "next over ALIGN_STACK_ON_STARTUP code"
234 -re "if.*i != 0.*$prompt $" {
238 -re "if.*SET_TOP_LEVEL.*$prompt $" {
241 -re "alloca.*$prompt $" {
244 -re "if.*level.*$prompt $" {
253 -re ".*No such file or directory.\r\n$prompt $" {
254 pass "$description (no source available)"
256 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
257 pass "$description (no source available)"
263 fail "$description (timeout)"
266 # -re "if \(setmp \(to_top_level\)\).*$prompt $" { pass "first next" }
269 # This one fails on Solaris (for some versions of gdb) because you
270 # can't next over library functions
271 setup_xfail "sparc-sun-solaris2" 1817
273 set need_to_step_over_cmdsize 1
274 set description "next over SET_TOP_LEVEL call"
277 -re "cmdsize = 1;.*$prompt $" {
280 -re "cmdarg = .*xmalloc.*$prompt $" {
281 # This can happen in optimized code where the "cmdsize = 1" line
282 # is basically removed.
284 set need_to_step_over_cmdsize 0
286 -re ".*No such file or directory.\r\n$prompt $" {
287 pass "$description (no source available)"
289 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
290 pass "$description (no source available)"
297 fail "$description (timeout)"
302 set description "print a string"
303 send "print \"foo\"\n"
305 -re ".\[0-9\]+ = \"foo\".*$prompt $" {
312 fail "$description (timeout)"
316 if $need_to_step_over_cmdsize {
317 set description "step over cmdsize initialization"
320 -re "cmdarg = .*xmalloc.*$prompt $" {
323 -re ".*No such file or directory.\r\n$prompt $" {
324 pass "$description (no source available)"
326 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
327 pass "$description (no source available)"
333 fail "$description" (timeout)"
338 # and another step for good luck
339 # This one fails on Solaris (for some versions of gdb) because you
340 # can't step into library functions
342 set description "step into xmalloc call"
345 -re "xmalloc.*size=.*at.*utils.c.*$prompt $" {
348 -re ".*No such file or directory.\r\n$prompt $" {
349 pass "$description (no source available)"
351 -re "A file or directory .* does not exist..\r\n$prompt $" {
352 pass "$description (no source available)"
358 fail "$description (timeout)"
363 # start the "xgdb" process
366 -re "GDB is free software and you are welcome to distribute copies of it.*
367 under certain conditions; type \"show copying\" to see the conditions..*
368 There is absolutely no warranty for GDB; type \"show warranty\" for details..*
369 GDB.*Copyright \[0-9\]+ Free Software Foundation, Inc..*$prompt $"\
370 { pass "xgdb is at prompt" }
371 -re ".*$prompt $" { fail "xgdb is at prompt" }
372 timeout { fail "(timeout) xgdb is at prompt" }
375 # set xgdb prompt so we can tell which is which
376 send "set prompt (xgdb) \n"
378 -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" { pass "Set xgdb prompt" }
379 -re ".*$prompt $" { fail "Set xgdb prompt" }
380 default { fail "(timeout) Set xgdb prompt" }
383 # kill the xgdb process
384 set description "send ^C to child process"
387 -re "Program received signal SIGINT.*$prompt $" {
394 fail "$description (timeout)"
398 set description "send SIGINT signal to child process"
399 send "signal SIGINT\n"
401 -re "Continuing with signal SIGINT.*$prompt $" {
408 fail "$description (timeout)"
413 setup_xfail "i486-*-sysv4"
414 set description "backtrace through signal handler"
417 -re "#0.*read.*#\[1-9\].*main.c.*$prompt $" {
424 fail "$description (timeout)"
428 # force GDB to dump core. On Solaris expect seems to not see the
429 # final message, even if gdb did dump core, so we check for the
430 # core dump explicitly if we time out.
432 # Some systems append "core" to the name of the program; others
433 # append the name of the program to "core".
434 system rm -f core core.gdb gdb.core
435 send "maint dump-me\n"
437 -re "maint dump-me.*Should GDB dump core.*y or n. $" {
440 -re "Quit.*core dumped.*" { pass "GDB dumped core" }
441 -re "Program received signal SIGQUIT.*$prompt $" {
442 pass "GDB dumped core"
443 # This means we just told xgdb, not gdb, to dump core.
444 # Get out of gdb so that removing xgdb doesn't get
448 -re "$prompt $" { fail "GDB dumped core" }
450 if {[file exists core] || [file exists core.gdb] || [file exists gdb.core]} then {
451 pass "GDB dumped core"
453 fail "GDB dumped core"
458 -re ".*$prompt $" { fail "GDB dumped core" }
459 timeout { fail "(timeout) GDB dumped core" }
461 system rm -f core core.gdb gdb.core
463 # Set the timeout back to the value it had when we were called.
464 set timeout $oldtimeout
466 # Restart gdb in case next test expects it to be started already.
471 # Find a pathname to a file that we would execute if the shell was asked
472 # to run $arg using the current PATH.
474 proc find_gdb { arg } {
476 # If the arg directly specifies an existing executable file, then
479 if [file executable $arg] then {
483 set result [which $arg]
484 if [string match "/" [ string range $result 0 0 ]] then {
488 # If everything fails, just return the unqualified pathname as default
494 # Run the test with self.
495 # Copy the file executable file in case this OS doesn't like to edit it's own
498 set GDB_FULLPATH [find_gdb $GDB]
500 # Remove any old copy lying around.
501 catch "exec rm -f ./x$tool"
503 if ![file executable $GDB_FULLPATH] then {
504 fail "couldn't convert $GDB to absolute pathname to make local copy"
506 if [catch "exec cp $GDB_FULLPATH ./x$tool"] then {
507 fail "couldn't copy $GDB_FULLPATH to current directory"
509 verbose "\t\tCopied $GDB_FULLPATH to ./x$tool"
510 if {[test_with_self] <0} then {
511 warning "Couldn't test self"
512 catch "exec rm -f ./x$tool"
515 catch "exec rm -f ./x$tool"