1 # Copyright 1988, 1990, 1991, 1992, 1994, 1997, 1999, 2000
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
21 # This file was written by Rob Savoye. (rob@cygnus.com)
30 # are we on a target board
31 if [is_remote target] {
35 if [istarget "m68k*-*-hpux*"] then {
36 # The top-level makefile passes CFLAGS= (no -g) for hp300. This probably
37 # should be fixed (it is only needed for gcc bootstrapping, not gdb),
40 fail "cannot test self if compiled without debug info"
44 # Not all of the lines of code near the start of main are executed for
45 # every machine. Also, optimization may reorder some of the lines.
46 # So all we do is try to step or next over everything until we get
47 # to a line that we know is always executed.
49 proc do_steps_and_nexts {} {
53 gdb_reinitialize_dir $srcdir/..
55 for {set count 0} {$count < 22} {incr count} {
58 -re ".*context = data.*$gdb_prompt $" {
59 set description "step over context initialization"
62 -re ".*argc = context->argc.*$gdb_prompt $" {
63 set description "step over argc initialization"
66 -re ".*argv = context->argv.*$gdb_prompt $" {
67 set description "step over argv initialization"
70 -re ".*quiet = 0.*$gdb_prompt $" {
71 set description "step over quiet initialization"
74 -re ".*batch = 0.*$gdb_prompt $" {
75 set description "step over batch initialization"
78 -re ".*symarg = NULL.*$gdb_prompt $" {
79 set description "step over symarg initialization"
82 -re ".*execarg = NULL.*$gdb_prompt $" {
83 set description "step over execarg initialization"
86 -re ".*corearg = NULL.*$gdb_prompt $" {
87 set description "step over corearg initialization"
90 -re ".*cdarg = NULL.*$gdb_prompt $" {
91 set description "step over cdarg initialization"
94 -re ".*ttyarg = NULL.*$gdb_prompt $" {
95 set description "step over ttyarg initialization"
98 -re ".*time_at_startup = get_run_time.*$gdb_prompt $" {
99 set description "next over get_run_time and everything it calls"
102 -re ".*START_PROGRESS.*$gdb_prompt $" {
103 set description "next over START_PROGRESS and everything it calls"
106 -re ".*mac_init.*$gdb_prompt $" {
107 set description "next over mac_init and everything it calls"
110 -re ".*init_malloc.*$gdb_prompt $" {
111 set description "next over init_malloc and everything it calls"
114 -re ".*count . 0x3.*$gdb_prompt $" {
115 set description "next over conditional stack alignment code 1"
118 -re ".*if .i != 0.*$gdb_prompt $" {
119 set description "next over conditional stack alignment code 2"
122 -re ".*alloca .i - 4.*$gdb_prompt $" {
123 set description "next over conditional stack alignment alloca"
126 -re ".*cmdsize = 1.*$gdb_prompt $" {
127 set description "step over cmdsize initialization"
130 -re ".*cmdarg = .* xmalloc.*$gdb_prompt $" {
131 set description "next over cmdarg initialization via xmalloc"
134 -re ".*ncmd = 0.*$gdb_prompt $" {
135 set description "next over ncmd initialization"
138 -re ".*dirsize = 1.*$gdb_prompt $" {
139 set description "next over dirsize initialization"
142 -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
145 -re "\[ \t\]+\{\r\n$gdb_prompt $" {
146 setup_xfail "mips-*-irix5*"
147 fail "$description ended up at odd location"
149 -re ".*main.c.*No such file or directory.*$gdb_prompt $" {
150 setup_xfail "rs6000-*-aix3*"
151 fail "must be able to list source lines"
154 -re ".*$gdb_prompt $" {
155 fail "unknown source line after $description"
159 fail "unknown source line near main"
163 send_gdb "$command\n"
165 -re ".*No such file or directory.\r\n$gdb_prompt $" {
166 fail "$description (no source available)"
168 -re ".*A file or directory .* does not exist..\r\n$gdb_prompt $" {
169 fail "$description (no source available)"
171 -re ".*$gdb_prompt $" {
175 fail "$description (timeout)"
181 proc test_with_self { executable } {
188 # load yourself into the debugger
189 # This can take a relatively long time, particularly for testing where
190 # the executable is being accessed over a network, or where gdb does not
191 # support partial symbols for a particular target and has to load the
192 # entire symbol table. Set the timeout to 10 minutes, which should be
193 # adequate for most environments (it *has* timed out with 5 min on a
194 # SPARCstation SLC under moderate load, so this isn't unreasonable).
195 # After gdb is started, set the timeout to 30 seconds for the duration
196 # of this test, and then back to the original value.
198 set oldtimeout $timeout
200 verbose "Timeout is now $timeout seconds" 2
201 if {[gdb_load $executable] <0} then {
202 set timeout $oldtimeout
203 verbose "Timeout is now $timeout seconds" 2
206 set timeout $oldtimeout
207 verbose "Timeout is now $timeout seconds" 2
209 # disassemble yourself
210 gdb_test "x/10i main" \
211 "x/10i.*main.*main.$decimal.*main.$decimal.*" \
214 # Set a breakpoint at main
215 gdb_test "break captured_main" \
216 "Breakpoint.*at.* file.*, line.*" \
217 "breakpoint in captured_main"
219 # We'll need this when we send a ^C to GDB. Need to do it before we
220 # run the program and gdb starts saving and restoring tty states.
221 # On Ultrix, we don't need it and it is really slow (because shell_escape
222 # doesn't use vfork).
223 if ![istarget "*-*-ultrix*"] then {
224 gdb_test "shell stty intr '^C'" "" \
225 "set interrupt character in test_with_self"
228 # FIXME: If we put this after the run to main, the first list
229 # command doesn't print the same line as the current line where
231 gdb_test "set listsize 1" "" "set listsize to 1"
234 # It may take a very long time for the inferior gdb to start (lynx),
235 # so we bump it back up for the duration of this command.
238 set description "run until breakpoint at captured_main"
241 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.* at .*main.c:.*$gdb_prompt $" {
244 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" {
245 xfail "$description (line numbers scrambled?)"
247 -re "vfork: No more processes.*$gdb_prompt $" {
248 fail "$description (out of virtual memory)"
249 set timeout $oldtimeout
250 verbose "Timeout is now $timeout seconds" 2
253 -re ".*$gdb_prompt $" {
255 set timeout $oldtimeout
256 verbose "Timeout is now $timeout seconds" 2
260 fail "$description (timeout)"
264 set timeout $oldtimeout
265 verbose "Timeout is now $timeout seconds" 2
267 # do we have a version number ?
268 send_gdb "print version\n"
270 -re ".\[0-9\]+ = .\[0-9.\]+.*$gdb_prompt $" {
271 pass "printed version as string"
273 -re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$gdb_prompt $" {
274 pass "printed version as pointer"
276 -re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$gdb_prompt $" {
277 pass "printed version with cast"
279 -re ".*$gdb_prompt $" { fail "printed version" }
280 timeout { fail "(timeout) printed version" }
285 gdb_test "print \"foo\"" ".\[0-9\]+ = \"foo\"" "print a string"
287 # do_steps_and_nexts left us ready to execute an xmalloc call,
288 # so give that a try.
289 # If we don't actually enter the xmalloc call when we give a
290 # step command that seems like a genuine bug. It seems to happen
291 # on most RISC processors.
292 setup_xfail "alpha-*-*" "mips-*-*"
293 set description "step into xmalloc call"
296 -re "xmalloc.*size=.*at.*utils.c.*$gdb_prompt $" {
299 -re ".*No such file or directory.\r\n$gdb_prompt $" {
300 pass "$description (no source available)"
302 -re "A file or directory .* does not exist..\r\n$gdb_prompt $" {
303 pass "$description (no source available)"
305 -re ".*$gdb_prompt $" {
309 fail "$description (timeout)"
313 # start the "xgdb" process
314 send_gdb "continue\n"
316 -re "GNU gdb \[0-9\.\]*.*
317 Copyright \[0-9\]* Free Software Foundation, Inc.*
318 GDB is free software, covered by the GNU General Public License, and you are.*
319 welcome to change it and/or distribute copies of it under certain conditions.*
320 Type \"show copying\" to see the conditions.*
321 There is absolutely no warranty for GDB. Type \"show warranty\" for details.*
322 This GDB was configured as .*$gdb_prompt $"\
323 { pass "xgdb is at prompt" }
324 -re "GDB is free software and you are welcome to distribute copies of it.*
325 under certain conditions; type \"show copying\" to see the conditions..*
326 There is absolutely no warranty for GDB; type \"show warranty\" for details..*
327 GDB.*Copyright \[0-9\]+ Free Software Foundation, Inc..*$gdb_prompt $"\
328 { pass "xgdb is at prompt (obsolescent gdb)" }
329 -re ".*$gdb_prompt $" { fail "xgdb is at prompt" }
330 timeout { fail "(timeout) xgdb is at prompt" }
333 # set xgdb prompt so we can tell which is which
334 send_gdb "set prompt (xgdb) \n"
336 -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" { pass "Set xgdb prompt" }
337 -re ".*$gdb_prompt $" { fail "Set xgdb prompt" }
338 default { fail "(timeout) Set xgdb prompt" }
341 # kill the xgdb process
342 set description "send ^C to child process"
345 -re "Program received signal SIGINT.*$gdb_prompt $" {
348 -re ".*$gdb_prompt $" {
352 fail "$description (timeout)"
356 set description "send SIGINT signal to child process"
357 send_gdb "signal SIGINT\n"
359 -re "Continuing with signal SIGINT.*$gdb_prompt $" {
362 -re ".*$gdb_prompt $" {
366 fail "$description (timeout)"
372 # This fails on some linux systems for unknown reasons. On the
373 # systems where it fails, sometimes it works fine when run manually.
374 # The testsuite failures may not be limited to just aout systems.
375 setup_xfail "i*86-pc-linuxaout-gnu"
376 set description "backtrace through signal handler"
377 send_gdb "backtrace\n"
379 -re "#0.*read.*in main \\(.*\\) at .*main\\.c.*$gdb_prompt $" {
382 -re ".*$gdb_prompt $" {
383 # On the alpha, we hit the infamous problem about gdb
384 # being unable to get the frame pointer (mentioned in
385 # gdb/README). As it is intermittent, there is no way to
386 # XFAIL it which will give us an XPASS if the problem goes
388 setup_xfail "alpha*-*-osf*"
392 fail "$description (timeout)"
397 # Set the timeout back to the value it had when we were called.
398 set timeout $oldtimeout
399 verbose "Timeout is now $timeout seconds" 2
401 # Restart gdb in case next test expects it to be started already.
405 # Find a pathname to a file that we would execute if the shell was asked
406 # to run $arg using the current PATH.
408 proc find_gdb { arg } {
410 # If the arg directly specifies an existing executable file, then
413 if [file executable $arg] then {
417 set result [which $arg]
418 if [string match "/" [ string range $result 0 0 ]] then {
422 # If everything fails, just return the unqualified pathname as default
428 # Run the test with self.
429 # Copy the file executable file in case this OS doesn't like to edit its own
432 set GDB_FULLPATH [find_gdb $GDB]
434 # Remove any old copy lying around.
435 remote_file host delete x$tool
438 set file [remote_download host $GDB_FULLPATH x$tool]
439 set result [test_with_self $file];
441 catch "remote_file host delete $file";
443 if {$result <0} then {
444 warning "Couldn't test self"