1 # Copyright 1988, 1990, 1991, 1992, 1994, 1997, 1999, 2000, 2002, 2003
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 # Not all of the lines of code near the start of main are executed for
36 # every machine. Also, optimization may reorder some of the lines.
37 # So all we do is try to step or next over everything until we get
38 # to a line that we know is always executed.
40 proc do_steps_and_nexts {} {
44 gdb_reinitialize_dir $srcdir/..
46 for {set count 0} {$count < 32} {incr count} {
48 # NOTE: carlton/2002-12-11: The "initial brace" and
49 # "current_directory initialization" possibilities happen to
50 # me with GCC 3.1 on i686-pc-linux-gnu when I compile with
53 -re ".*context = data.*$gdb_prompt $" {
54 set description "step over context initialization"
57 -re ".*argc = context->argc.*$gdb_prompt $" {
58 set description "step over argc initialization"
61 -re ".*argv = context->argv.*$gdb_prompt $" {
62 set description "step over argv initialization"
65 -re ".*quiet = 0.*$gdb_prompt $" {
66 set description "step over quiet initialization"
69 -re ".*batch = 0.*$gdb_prompt $" {
70 set description "step over batch initialization"
73 -re ".*symarg = NULL.*$gdb_prompt $" {
74 set description "step over symarg initialization"
77 -re ".*execarg = NULL.*$gdb_prompt $" {
78 set description "step over execarg initialization"
81 -re ".*corearg = NULL.*$gdb_prompt $" {
82 set description "step over corearg initialization"
85 -re ".*cdarg = NULL.*$gdb_prompt $" {
86 set description "step over cdarg initialization"
89 -re ".*ttyarg = NULL.*$gdb_prompt $" {
90 set description "step over ttyarg initialization"
93 -re ".*time_at_startup = get_run_time.*$gdb_prompt $" {
94 set description "next over get_run_time and everything it calls"
97 -re ".*START_PROGRESS.*$gdb_prompt $" {
98 set description "next over START_PROGRESS and everything it calls"
101 -re ".*mac_init.*$gdb_prompt $" {
102 set description "next over mac_init and everything it calls"
105 -re ".*init_malloc.*$gdb_prompt $" {
106 set description "next over init_malloc and everything it calls"
109 -re ".*lim_at_start.*$gdb_prompt $" {
110 set description "next over lim_at_start initialization"
113 -re ".*count . 0x3.*$gdb_prompt $" {
114 set description "next over conditional stack alignment code 1"
117 -re ".*if .i != 0.*$gdb_prompt $" {
118 set description "next over conditional stack alignment code 2"
121 -re ".*alloca .i - 4.*$gdb_prompt $" {
122 set description "next over conditional stack alignment alloca"
125 -re ".*cmdsize = 1.*$gdb_prompt $" {
126 set description "step over cmdsize initialization"
129 -re ".*cmdarg = .* xmalloc.*$gdb_prompt $" {
130 set description "next over cmdarg initialization via xmalloc"
133 -re ".*ncmd = 0.*$gdb_prompt $" {
134 set description "next over ncmd initialization"
137 -re ".*dirsize = 1.*$gdb_prompt $" {
138 set description "next over dirsize initialization"
141 -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
144 -re ".*setlocale .LC_MESSAGES,.*$gdb_prompt $" {
145 set description "next over setlocale LC_MESSAGES"
148 -re ".*setlocale .LC_CTYPE,.*$gdb_prompt $" {
149 set description "next over setlocale LC_CTYPE"
152 -re ".*bindtextdomain .PACKAGE, LOCALEDIR.;.*$gdb_prompt $" {
153 set description "next over bindtextdomain"
156 -re ".*textdomain .PACKAGE.;.*$gdb_prompt $" {
157 set description "next over textdomain PACKAGE"
160 -re "\[0-9\]*\t\{\r\n$gdb_prompt $" {
161 set description "step over initial brace"
164 -re ".*current_directory = gdb_dirbuf.*$gdb_prompt $" {
165 set description "step over current_directory initialization"
168 -re ".*gdb_sysroot = .*$gdb_prompt $" {
169 # NOTE: carlton/2003-01-15: More optimization reordering,
170 # observed on GCC 3.1.
171 set description "step over gdb_sysroot initialization"
174 -re ".*ndir = 0.*$gdb_prompt $" {
175 set description "step over ndir initialization"
178 -re ".*instream = stdin.*$gdb_prompt $" {
179 set description "step over instream initialization"
182 -re ".*getcwd .gdb_dirbuf, sizeof .gdb_dirbuf..;.*$gdb_prompt $" {
183 set description "next over getcwd"
186 -re "\[ \t\]+\{\r\n$gdb_prompt $" {
187 setup_xfail "mips-*-irix5*"
188 fail "$description ended up at odd location"
190 -re ".*main.c.*No such file or directory.*$gdb_prompt $" {
191 setup_xfail "rs6000-*-aix3*"
192 fail "must be able to list source lines"
195 -re ".*$gdb_prompt $" {
196 fail "unknown source line after $description"
200 fail "unknown source line near main"
204 send_gdb "$command\n"
206 -re ".*No such file or directory.\r\n$gdb_prompt $" {
207 fail "$description (no source available)"
209 -re ".*A file or directory .* does not exist..\r\n$gdb_prompt $" {
210 fail "$description (no source available)"
212 -re ".*$gdb_prompt $" {
216 fail "$description (timeout)"
222 proc test_with_self { executable } {
229 # load yourself into the debugger
230 # This can take a relatively long time, particularly for testing where
231 # the executable is being accessed over a network, or where gdb does not
232 # support partial symbols for a particular target and has to load the
233 # entire symbol table. Set the timeout to 10 minutes, which should be
234 # adequate for most environments (it *has* timed out with 5 min on a
235 # SPARCstation SLC under moderate load, so this isn't unreasonable).
236 # After gdb is started, set the timeout to 30 seconds for the duration
237 # of this test, and then back to the original value.
239 set oldtimeout $timeout
241 verbose "Timeout is now $timeout seconds" 2
242 if {[gdb_load $executable] <0} then {
243 set timeout $oldtimeout
244 verbose "Timeout is now $timeout seconds" 2
247 set timeout $oldtimeout
248 verbose "Timeout is now $timeout seconds" 2
250 # disassemble yourself
251 gdb_test "x/10i main" \
252 "x/10i.*main.*main.$decimal.*main.$decimal.*" \
255 # Set a breakpoint at main
256 gdb_test "break captured_main" \
257 "Breakpoint.*at.* file.*, line.*" \
258 "breakpoint in captured_main"
260 # We'll need this when we send a ^C to GDB. Need to do it before we
261 # run the program and gdb starts saving and restoring tty states.
262 # On Ultrix, we don't need it and it is really slow (because shell_escape
263 # doesn't use vfork).
264 if ![istarget "*-*-ultrix*"] then {
265 gdb_test "shell stty intr '^C'" "" \
266 "set interrupt character in test_with_self"
269 # FIXME: If we put this after the run to main, the first list
270 # command doesn't print the same line as the current line where
272 gdb_test "set listsize 1" "" "set listsize to 1"
275 # It may take a very long time for the inferior gdb to start (lynx),
276 # so we bump it back up for the duration of this command.
279 set description "run until breakpoint at captured_main"
282 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.* at .*main.c:.*$gdb_prompt $" {
285 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" {
286 xfail "$description (line numbers scrambled?)"
288 -re "vfork: No more processes.*$gdb_prompt $" {
289 fail "$description (out of virtual memory)"
290 set timeout $oldtimeout
291 verbose "Timeout is now $timeout seconds" 2
294 -re ".*$gdb_prompt $" {
296 set timeout $oldtimeout
297 verbose "Timeout is now $timeout seconds" 2
301 fail "$description (timeout)"
305 set timeout $oldtimeout
306 verbose "Timeout is now $timeout seconds" 2
308 # do we have a version number ?
309 send_gdb "print version\n"
311 -re ".\[0-9\]+ = .\[0-9.\]+.*$gdb_prompt $" {
312 pass "printed version as string"
314 -re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$gdb_prompt $" {
315 pass "printed version as pointer"
317 -re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$gdb_prompt $" {
318 pass "printed version with cast"
320 -re ".*$gdb_prompt $" { fail "printed version" }
321 timeout { fail "(timeout) printed version" }
326 gdb_test "print \"foo\"" ".\[0-9\]+ = \"foo\"" "print a string"
328 # do_steps_and_nexts left us ready to execute an xmalloc call,
329 # so give that a try.
330 # If we don't actually enter the xmalloc call when we give a
331 # step command that seems like a genuine bug. It seems to happen
332 # on most RISC processors.
333 # NOTE drow/2003-06-22: However, if we step back to the preceding two
334 # lines, just keep stepping until we enter.
336 setup_xfail "alpha-*-*" "mips-*-*"
337 set description "step into xmalloc call"
340 -re "ncmd = 0;.*$gdb_prompt $" {
345 -re "dirsize = 1;.*$gdb_prompt $" {
350 -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
351 if { $stepped_back == 1 } {
358 -re "xmalloc.*size=.*at.*utils.c.*$gdb_prompt $" {
361 -re ".*No such file or directory.\r\n$gdb_prompt $" {
362 pass "$description (no source available)"
364 -re "A file or directory .* does not exist..\r\n$gdb_prompt $" {
365 pass "$description (no source available)"
367 -re ".*$gdb_prompt $" {
371 fail "$description (timeout)"
375 # start the "xgdb" process
376 send_gdb "continue\n"
378 -re "GNU gdb \[0-9\.\]*.*
379 Copyright \[0-9\]* Free Software Foundation, Inc.*
380 GDB is free software, covered by the GNU General Public License, and you are.*
381 welcome to change it and/or distribute copies of it under certain conditions.*
382 Type \"show copying\" to see the conditions.*
383 There is absolutely no warranty for GDB. Type \"show warranty\" for details.*
384 This GDB was configured as .*$gdb_prompt $"\
385 { pass "xgdb is at prompt" }
386 -re "GDB is free software and you are welcome to distribute copies of it.*
387 under certain conditions; type \"show copying\" to see the conditions..*
388 There is absolutely no warranty for GDB; type \"show warranty\" for details..*
389 GDB.*Copyright \[0-9\]+ Free Software Foundation, Inc..*$gdb_prompt $"\
390 { pass "xgdb is at prompt (obsolescent gdb)" }
391 -re ".*$gdb_prompt $" { fail "xgdb is at prompt" }
392 timeout { fail "(timeout) xgdb is at prompt" }
395 # set xgdb prompt so we can tell which is which
396 send_gdb "set prompt (xgdb) \n"
398 -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" { pass "Set xgdb prompt" }
399 -re ".*$gdb_prompt $" { fail "Set xgdb prompt" }
400 default { fail "(timeout) Set xgdb prompt" }
403 # kill the xgdb process
404 set description "send ^C to child process"
407 -re "Program received signal SIGINT.*$gdb_prompt $" {
410 -re ".*$gdb_prompt $" {
414 fail "$description (timeout)"
418 set description "send SIGINT signal to child process"
419 send_gdb "signal SIGINT\n"
421 -re "Continuing with signal SIGINT.*$gdb_prompt $" {
424 -re ".*$gdb_prompt $" {
428 fail "$description (timeout)"
434 # This fails on some linux systems for unknown reasons. On the
435 # systems where it fails, sometimes it works fine when run manually.
436 # The testsuite failures may not be limited to just aout systems.
437 setup_xfail "i*86-pc-linuxaout-gnu"
438 set description "backtrace through signal handler"
439 send_gdb "backtrace\n"
441 -re "#0.*(read|poll).*in main \\(.*\\) at .*gdb\\.c.*$gdb_prompt $" {
444 -re ".*$gdb_prompt $" {
445 # On the alpha, we hit the infamous problem about gdb
446 # being unable to get the frame pointer (mentioned in
447 # gdb/README). As it is intermittent, there is no way to
448 # XFAIL it which will give us an XPASS if the problem goes
450 setup_xfail "alpha*-*-osf*"
454 fail "$description (timeout)"
459 # Set the timeout back to the value it had when we were called.
460 set timeout $oldtimeout
461 verbose "Timeout is now $timeout seconds" 2
463 # Restart gdb in case next test expects it to be started already.
467 # Find a pathname to a file that we would execute if the shell was asked
468 # to run $arg using the current PATH.
470 proc find_gdb { arg } {
472 # If the arg directly specifies an existing executable file, then
475 if [file executable $arg] then {
479 set result [which $arg]
480 if [string match "/" [ string range $result 0 0 ]] then {
484 # If everything fails, just return the unqualified pathname as default
490 # Run the test with self.
491 # Copy the file executable file in case this OS doesn't like to edit its own
494 set GDB_FULLPATH [find_gdb $GDB]
496 # Remove any old copy lying around.
497 remote_file host delete x$tool
500 set file [remote_download host $GDB_FULLPATH x$tool]
501 set result [test_with_self $file];
503 catch "remote_file host delete $file";
505 if {$result <0} then {
506 warning "Couldn't test self"