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 ".*time_at_startup = get_run_time .*$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 get_run_time and everything it calls"
224 set got_over_get_run_time 0
227 -re ".*init_malloc.*$prompt $" {
229 set got_over_get_run_time 1
231 -re ".*No such file or directory.\r\n$prompt $" {
232 pass "$description (no source available)"
233 set got_over_get_run_time 1
235 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
236 pass "$description (no source available)"
237 set got_over_get_run_time 1
243 fail "$description (timeout)"
246 # -re "if \(setmp \(to_top_level\)\).*$prompt $" { pass "first next" }
248 if $got_over_get_run_time then {
249 set description "next over init_malloc and everything it calls"
252 -re "if.*SET_TOP_LEVEL.*$prompt $" {
255 -re "i = .*count.*$prompt $" {
257 set description "next over ALIGN_STACK_ON_STARTUP code"
260 -re "if.*i != 0.*$prompt $" {
264 -re "if.*SET_TOP_LEVEL.*$prompt $" {
267 -re "alloca.*$prompt $" {
270 -re "if.*level.*$prompt $" {
279 -re ".*No such file or directory.\r\n$prompt $" {
280 pass "$description (no source available)"
282 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
283 pass "$description (no source available)"
289 fail "$description (timeout or eof)"
294 # This one fails on Solaris (for some versions of gdb) because you
295 # can't next over library functions
296 setup_xfail "sparc-sun-solaris2" 1817
298 set need_to_step_over_cmdsize 1
299 set description "next over SET_TOP_LEVEL call"
302 -re "cmdsize = 1;.*$prompt $" {
305 -re "cmdarg = .*xmalloc.*$prompt $" {
306 # This can happen in optimized code where the "cmdsize = 1" line
307 # is basically removed.
309 set need_to_step_over_cmdsize 0
311 -re ".*No such file or directory.\r\n$prompt $" {
312 pass "$description (no source available)"
314 -re ".*A file or directory .* does not exist..\r\n$prompt $" {
315 pass "$description (no source available)"
322 fail "$description (timeout)"
327 set description "print a string"
328 send "print \"foo\"\n"
330 -re ".\[0-9\]+ = \"foo\".*$prompt $" {
337 fail "$description (timeout)"
341 if $need_to_step_over_cmdsize {
342 set description "step over cmdsize initialization"
345 -re "cmdarg = .*xmalloc.*$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 # and another step for good luck
364 # This one fails on Solaris (for some versions of gdb) because you
365 # can't step into library functions
367 set description "step into xmalloc call"
370 -re "xmalloc.*size=.*at.*utils.c.*$prompt $" {
373 -re ".*No such file or directory.\r\n$prompt $" {
374 pass "$description (no source available)"
376 -re "A file or directory .* does not exist..\r\n$prompt $" {
377 pass "$description (no source available)"
383 fail "$description (timeout)"
388 # start the "xgdb" process
391 -re "GDB is free software and you are welcome to distribute copies of it.*
392 under certain conditions; type \"show copying\" to see the conditions..*
393 There is absolutely no warranty for GDB; type \"show warranty\" for details..*
394 GDB.*Copyright \[0-9\]+ Free Software Foundation, Inc..*$prompt $"\
395 { pass "xgdb is at prompt" }
396 -re ".*$prompt $" { fail "xgdb is at prompt" }
397 timeout { fail "(timeout) xgdb is at prompt" }
400 # set xgdb prompt so we can tell which is which
401 send "set prompt (xgdb) \n"
403 -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" { pass "Set xgdb prompt" }
404 -re ".*$prompt $" { fail "Set xgdb prompt" }
405 default { fail "(timeout) Set xgdb prompt" }
408 # kill the xgdb process
409 set description "send ^C to child process"
412 -re "Program received signal SIGINT.*$prompt $" {
419 fail "$description (timeout)"
423 set description "send SIGINT signal to child process"
424 send "signal SIGINT\n"
426 -re "Continuing with signal SIGINT.*$prompt $" {
433 fail "$description (timeout)"
438 setup_xfail "i486-*-sysv4"
439 set description "backtrace through signal handler"
442 -re "#0.*read.*#\[1-9\].*main.c.*$prompt $" {
449 fail "$description (timeout)"
455 # Set the timeout back to the value it had when we were called.
456 set timeout $oldtimeout
458 # Restart gdb in case next test expects it to be started already.
463 # Find a pathname to a file that we would execute if the shell was asked
464 # to run $arg using the current PATH.
466 proc find_gdb { arg } {
468 # If the arg directly specifies an existing executable file, then
471 if [file executable $arg] then {
475 set result [which $arg]
476 if [string match "/" [ string range $result 0 0 ]] then {
480 # If everything fails, just return the unqualified pathname as default
486 # Run the test with self.
487 # Copy the file executable file in case this OS doesn't like to edit it's own
490 set GDB_FULLPATH [find_gdb $GDB]
492 # Remove any old copy lying around.
493 catch "exec rm -f ./x$tool"
495 if ![file executable $GDB_FULLPATH] then {
496 fail "couldn't convert $GDB to absolute pathname to make local copy"
498 if [catch "exec cp $GDB_FULLPATH ./x$tool"] then {
499 fail "couldn't copy $GDB_FULLPATH to current directory"
501 verbose "\t\tCopied $GDB_FULLPATH to ./x$tool"
502 if {[test_with_self] <0} then {
503 warning "Couldn't test self"
504 catch "exec rm -f ./x$tool"
507 catch "exec rm -f ./x$tool"