1 # Copyright 1988, 1990, 1991, 1992, 1994, 1997, 1999, 2000, 2002
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 < 26} {incr count} {
57 # NOTE: carlton/2002-12-11: The "initial brace" and
58 # "current_directory initialization" possibilities happen to
59 # me with GCC 3.1 on i686-pc-linux-gnu when I compile with
62 -re ".*context = data.*$gdb_prompt $" {
63 set description "step over context initialization"
66 -re ".*argc = context->argc.*$gdb_prompt $" {
67 set description "step over argc initialization"
70 -re ".*argv = context->argv.*$gdb_prompt $" {
71 set description "step over argv initialization"
74 -re ".*quiet = 0.*$gdb_prompt $" {
75 set description "step over quiet initialization"
78 -re ".*batch = 0.*$gdb_prompt $" {
79 set description "step over batch initialization"
82 -re ".*symarg = NULL.*$gdb_prompt $" {
83 set description "step over symarg initialization"
86 -re ".*execarg = NULL.*$gdb_prompt $" {
87 set description "step over execarg initialization"
90 -re ".*corearg = NULL.*$gdb_prompt $" {
91 set description "step over corearg initialization"
94 -re ".*cdarg = NULL.*$gdb_prompt $" {
95 set description "step over cdarg initialization"
98 -re ".*ttyarg = NULL.*$gdb_prompt $" {
99 set description "step over ttyarg initialization"
102 -re ".*time_at_startup = get_run_time.*$gdb_prompt $" {
103 set description "next over get_run_time and everything it calls"
106 -re ".*START_PROGRESS.*$gdb_prompt $" {
107 set description "next over START_PROGRESS and everything it calls"
110 -re ".*mac_init.*$gdb_prompt $" {
111 set description "next over mac_init and everything it calls"
114 -re ".*init_malloc.*$gdb_prompt $" {
115 set description "next over init_malloc and everything it calls"
118 -re ".*count . 0x3.*$gdb_prompt $" {
119 set description "next over conditional stack alignment code 1"
122 -re ".*if .i != 0.*$gdb_prompt $" {
123 set description "next over conditional stack alignment code 2"
126 -re ".*alloca .i - 4.*$gdb_prompt $" {
127 set description "next over conditional stack alignment alloca"
130 -re ".*cmdsize = 1.*$gdb_prompt $" {
131 set description "step over cmdsize initialization"
134 -re ".*cmdarg = .* xmalloc.*$gdb_prompt $" {
135 set description "next over cmdarg initialization via xmalloc"
138 -re ".*ncmd = 0.*$gdb_prompt $" {
139 set description "next over ncmd initialization"
142 -re ".*dirsize = 1.*$gdb_prompt $" {
143 set description "next over dirsize initialization"
146 -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
149 -re ".*setlocale .LC_MESSAGES,.*$gdb_prompt $" {
150 set description "next over setlocale LC_MESSAGES"
153 -re ".*setlocale .LC_CTYPE,.*$gdb_prompt $" {
154 set description "next over setlocale LC_CTYPE"
157 -re ".*bindtextdomain .PACKAGE, LOCALEDIR.;.*$gdb_prompt $" {
158 set description "next over bindtextdomain"
161 -re ".*textdomain .PACKAGE.;.*$gdb_prompt $" {
162 set description "next over textdomain PACKAGE"
165 -re "\[0-9\]*\t\{\r\n$gdb_prompt $" {
166 set description "step over initial brace"
169 -re ".*current_directory = gdb_dirbuf.*$gdb_prompt $" {
170 set description "step over current_directory initialization"
173 -re ".*gdb_sysroot = .*$gdb_prompt $" {
174 # NOTE: carlton/2003-01-15: More optimization reordering,
175 # observed on GCC 3.1.
176 set description "step over gdb_sysroot initialization"
179 -re "\[ \t\]+\{\r\n$gdb_prompt $" {
180 setup_xfail "mips-*-irix5*"
181 fail "$description ended up at odd location"
183 -re ".*main.c.*No such file or directory.*$gdb_prompt $" {
184 setup_xfail "rs6000-*-aix3*"
185 fail "must be able to list source lines"
188 -re ".*$gdb_prompt $" {
189 fail "unknown source line after $description"
193 fail "unknown source line near main"
197 send_gdb "$command\n"
199 -re ".*No such file or directory.\r\n$gdb_prompt $" {
200 fail "$description (no source available)"
202 -re ".*A file or directory .* does not exist..\r\n$gdb_prompt $" {
203 fail "$description (no source available)"
205 -re ".*$gdb_prompt $" {
209 fail "$description (timeout)"
215 proc test_with_self { executable } {
222 # load yourself into the debugger
223 # This can take a relatively long time, particularly for testing where
224 # the executable is being accessed over a network, or where gdb does not
225 # support partial symbols for a particular target and has to load the
226 # entire symbol table. Set the timeout to 10 minutes, which should be
227 # adequate for most environments (it *has* timed out with 5 min on a
228 # SPARCstation SLC under moderate load, so this isn't unreasonable).
229 # After gdb is started, set the timeout to 30 seconds for the duration
230 # of this test, and then back to the original value.
232 set oldtimeout $timeout
234 verbose "Timeout is now $timeout seconds" 2
235 if {[gdb_load $executable] <0} then {
236 set timeout $oldtimeout
237 verbose "Timeout is now $timeout seconds" 2
240 set timeout $oldtimeout
241 verbose "Timeout is now $timeout seconds" 2
243 # disassemble yourself
244 gdb_test "x/10i main" \
245 "x/10i.*main.*main.$decimal.*main.$decimal.*" \
248 # Set a breakpoint at main
249 gdb_test "break captured_main" \
250 "Breakpoint.*at.* file.*, line.*" \
251 "breakpoint in captured_main"
253 # We'll need this when we send a ^C to GDB. Need to do it before we
254 # run the program and gdb starts saving and restoring tty states.
255 # On Ultrix, we don't need it and it is really slow (because shell_escape
256 # doesn't use vfork).
257 if ![istarget "*-*-ultrix*"] then {
258 gdb_test "shell stty intr '^C'" "" \
259 "set interrupt character in test_with_self"
262 # FIXME: If we put this after the run to main, the first list
263 # command doesn't print the same line as the current line where
265 gdb_test "set listsize 1" "" "set listsize to 1"
268 # It may take a very long time for the inferior gdb to start (lynx),
269 # so we bump it back up for the duration of this command.
272 set description "run until breakpoint at captured_main"
275 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.* at .*main.c:.*$gdb_prompt $" {
278 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" {
279 xfail "$description (line numbers scrambled?)"
281 -re "vfork: No more processes.*$gdb_prompt $" {
282 fail "$description (out of virtual memory)"
283 set timeout $oldtimeout
284 verbose "Timeout is now $timeout seconds" 2
287 -re ".*$gdb_prompt $" {
289 set timeout $oldtimeout
290 verbose "Timeout is now $timeout seconds" 2
294 fail "$description (timeout)"
298 set timeout $oldtimeout
299 verbose "Timeout is now $timeout seconds" 2
301 # do we have a version number ?
302 send_gdb "print version\n"
304 -re ".\[0-9\]+ = .\[0-9.\]+.*$gdb_prompt $" {
305 pass "printed version as string"
307 -re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$gdb_prompt $" {
308 pass "printed version as pointer"
310 -re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$gdb_prompt $" {
311 pass "printed version with cast"
313 -re ".*$gdb_prompt $" { fail "printed version" }
314 timeout { fail "(timeout) printed version" }
319 gdb_test "print \"foo\"" ".\[0-9\]+ = \"foo\"" "print a string"
321 # do_steps_and_nexts left us ready to execute an xmalloc call,
322 # so give that a try.
323 # If we don't actually enter the xmalloc call when we give a
324 # step command that seems like a genuine bug. It seems to happen
325 # on most RISC processors.
326 setup_xfail "alpha-*-*" "mips-*-*"
327 set description "step into xmalloc call"
330 -re "xmalloc.*size=.*at.*utils.c.*$gdb_prompt $" {
333 -re ".*No such file or directory.\r\n$gdb_prompt $" {
334 pass "$description (no source available)"
336 -re "A file or directory .* does not exist..\r\n$gdb_prompt $" {
337 pass "$description (no source available)"
339 -re ".*$gdb_prompt $" {
343 fail "$description (timeout)"
347 # start the "xgdb" process
348 send_gdb "continue\n"
350 -re "GNU gdb \[0-9\.\]*.*
351 Copyright \[0-9\]* Free Software Foundation, Inc.*
352 GDB is free software, covered by the GNU General Public License, and you are.*
353 welcome to change it and/or distribute copies of it under certain conditions.*
354 Type \"show copying\" to see the conditions.*
355 There is absolutely no warranty for GDB. Type \"show warranty\" for details.*
356 This GDB was configured as .*$gdb_prompt $"\
357 { pass "xgdb is at prompt" }
358 -re "GDB is free software and you are welcome to distribute copies of it.*
359 under certain conditions; type \"show copying\" to see the conditions..*
360 There is absolutely no warranty for GDB; type \"show warranty\" for details..*
361 GDB.*Copyright \[0-9\]+ Free Software Foundation, Inc..*$gdb_prompt $"\
362 { pass "xgdb is at prompt (obsolescent gdb)" }
363 -re ".*$gdb_prompt $" { fail "xgdb is at prompt" }
364 timeout { fail "(timeout) xgdb is at prompt" }
367 # set xgdb prompt so we can tell which is which
368 send_gdb "set prompt (xgdb) \n"
370 -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" { pass "Set xgdb prompt" }
371 -re ".*$gdb_prompt $" { fail "Set xgdb prompt" }
372 default { fail "(timeout) Set xgdb prompt" }
375 # kill the xgdb process
376 set description "send ^C to child process"
379 -re "Program received signal SIGINT.*$gdb_prompt $" {
382 -re ".*$gdb_prompt $" {
386 fail "$description (timeout)"
390 set description "send SIGINT signal to child process"
391 send_gdb "signal SIGINT\n"
393 -re "Continuing with signal SIGINT.*$gdb_prompt $" {
396 -re ".*$gdb_prompt $" {
400 fail "$description (timeout)"
406 # This fails on some linux systems for unknown reasons. On the
407 # systems where it fails, sometimes it works fine when run manually.
408 # The testsuite failures may not be limited to just aout systems.
409 setup_xfail "i*86-pc-linuxaout-gnu"
410 set description "backtrace through signal handler"
411 send_gdb "backtrace\n"
413 -re "#0.*(read|poll).*in main \\(.*\\) at .*gdb\\.c.*$gdb_prompt $" {
416 -re ".*$gdb_prompt $" {
417 # On the alpha, we hit the infamous problem about gdb
418 # being unable to get the frame pointer (mentioned in
419 # gdb/README). As it is intermittent, there is no way to
420 # XFAIL it which will give us an XPASS if the problem goes
422 setup_xfail "alpha*-*-osf*"
426 fail "$description (timeout)"
431 # Set the timeout back to the value it had when we were called.
432 set timeout $oldtimeout
433 verbose "Timeout is now $timeout seconds" 2
435 # Restart gdb in case next test expects it to be started already.
439 # Find a pathname to a file that we would execute if the shell was asked
440 # to run $arg using the current PATH.
442 proc find_gdb { arg } {
444 # If the arg directly specifies an existing executable file, then
447 if [file executable $arg] then {
451 set result [which $arg]
452 if [string match "/" [ string range $result 0 0 ]] then {
456 # If everything fails, just return the unqualified pathname as default
462 # Run the test with self.
463 # Copy the file executable file in case this OS doesn't like to edit its own
466 set GDB_FULLPATH [find_gdb $GDB]
468 # Remove any old copy lying around.
469 remote_file host delete x$tool
472 set file [remote_download host $GDB_FULLPATH x$tool]
473 set result [test_with_self $file];
475 catch "remote_file host delete $file";
477 if {$result <0} then {
478 warning "Couldn't test self"