1 # Copyright 1988, 1990, 1991, 1992, 1994, 1997, 1999, 2000, 2002, 2003, 2004,
2 # 2005, 2006, 2007, 2008, 2009, 2010 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 3 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, see <http://www.gnu.org/licenses/>.
17 # This file was written by Rob Savoye. (rob@cygnus.com)
24 # are we on a target board
25 if { [is_remote target] || ![isnative] } then {
29 # Not all of the lines of code near the start of main are executed for
30 # every machine. Also, optimization may reorder some of the lines.
31 # So all we do is try to step or next over everything until we get
32 # to a line that we know is always executed.
34 proc do_steps_and_nexts {} {
38 gdb_reinitialize_dir $srcdir/..
41 for {set count 0} {$count < 32} {incr count} {
42 # NOTE: carlton/2002-12-11: The "initial brace" and
43 # "current_directory initialization" possibilities happen to
44 # me with GCC 3.1 on i686-pc-linux-gnu when I compile with
46 gdb_test_multiple "list" "list" {
47 -re ".*context = data.*$gdb_prompt $" {
48 set description "step over context initialization"
51 -re ".*argc = context->argc.*$gdb_prompt $" {
52 set description "step over argc initialization"
55 -re ".*argv = context->argv.*$gdb_prompt $" {
56 set description "step over argv initialization"
59 -re ".*quiet = 0.*$gdb_prompt $" {
60 set description "step over quiet initialization"
63 -re ".*batch = 0.*$gdb_prompt $" {
64 set description "step over batch initialization"
67 -re ".*symarg = NULL.*$gdb_prompt $" {
68 set description "step over symarg initialization"
71 -re ".*execarg = NULL.*$gdb_prompt $" {
72 set description "step over execarg initialization"
75 -re ".*pidarg = NULL.*$gdb_prompt $" {
76 set description "step over pidarg initialization"
79 -re ".*corearg = NULL.*$gdb_prompt $" {
80 set description "step over corearg initialization"
83 -re ".*pid_or_core_arg = NULL.*$gdb_prompt $" {
84 set description "step over pid_or_core_arg initialization"
87 -re ".*cdarg = NULL.*$gdb_prompt $" {
88 set description "step over cdarg initialization"
91 -re ".*ttyarg = NULL.*$gdb_prompt $" {
92 set description "step over ttyarg initialization"
95 -re ".*pre_stat_chain = make_command_stats_cleanup.*$gdb_prompt $" {
96 set description "next over make_command_stats_cleanup and everything it calls"
99 -re ".*START_PROGRESS.*$gdb_prompt $" {
100 # Note: ezannoni/2004/02/17: This check should be
101 # removed, since as of today that source line is not
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 # gdb 6.2.X is the last gdb which called init_malloc
112 set description "next over init_malloc and everything it calls"
115 -re ".*lim_at_start.*$gdb_prompt $" {
116 set description "next over lim_at_start initialization"
119 -re ".*count . 0x3.*$gdb_prompt $" {
120 set description "next over conditional stack alignment code 1"
123 -re ".*if .i != 0.*$gdb_prompt $" {
124 set description "next over conditional stack alignment code 2"
127 -re ".*alloca .i - 4.*$gdb_prompt $" {
128 set description "next over conditional stack alignment alloca"
131 -re ".*cmdsize = 1.*$gdb_prompt $" {
132 set description "step over cmdsize initialization"
135 -re ".*cmdarg = .* xmalloc.*$gdb_prompt $" {
136 set description "next over cmdarg initialization via xmalloc"
139 -re ".*ncmd = 0.*$gdb_prompt $" {
140 set description "next over ncmd initialization"
143 -re ".*dirsize = 1.*$gdb_prompt $" {
144 set description "next over dirsize initialization"
147 -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
150 -re ".*setlocale .LC_MESSAGES,.*$gdb_prompt $" {
151 set description "next over setlocale LC_MESSAGES"
154 -re ".*setlocale .LC_CTYPE,.*$gdb_prompt $" {
155 set description "next over setlocale LC_CTYPE"
158 -re ".*bindtextdomain .PACKAGE, LOCALEDIR.;.*$gdb_prompt $" {
159 set description "next over bindtextdomain"
162 -re ".*textdomain .PACKAGE.;.*$gdb_prompt $" {
163 set description "next over textdomain PACKAGE"
166 -re "\[0-9\]+\[\t \]+\{\r\n$gdb_prompt $" {
167 set description "step over initial brace"
170 -re ".*current_directory = gdb_dirbuf.*$gdb_prompt $" {
171 set description "step over current_directory initialization"
174 -re ".*gdb_sysroot = .*$gdb_prompt $" {
175 # NOTE: carlton/2003-01-15: More optimization reordering,
176 # observed on GCC 3.1.
177 set description "step over gdb_sysroot initialization"
180 -re ".*ndir = 0.*$gdb_prompt $" {
181 set description "step over ndir initialization"
184 -re ".*instream = stdin.*$gdb_prompt $" {
185 set description "step over instream initialization"
188 -re ".*getcwd .gdb_dirbuf, sizeof .gdb_dirbuf.*$gdb_prompt $" {
189 set description "next over getcwd"
192 -re ".*gdb_program_name = xstrdup.*$gdb_prompt $" {
193 set description "next over xstrdup"
196 -re ".*quit_flag = 0.*$gdb_prompt $" {
197 set description "step over quit_flag initialization"
200 -re ".*gdb_stdout = stdio_fileopen .stdout.;.*$gdb_prompt $" {
201 set description "step over gdb_stdout initialization"
204 -re ".*gdb_stderr = stdio_fileopen .stderr.;.*$gdb_prompt $" {
205 set description "step over gdb_stderr initialization"
208 -re ".*main.c.*No such file or directory.*$gdb_prompt $" {
209 setup_xfail "rs6000-*-aix3*"
210 fail "must be able to list source lines"
213 -re ".*interpreter_p = xstrdup.*$gdb_prompt $" {
214 if { $unlikely_line == 0 } {
215 # This is a GCC optimization bug; a constant has been
216 # associated with the wrong line number.
217 setup_xfail "*-*-*" gcc/26475
218 fail "$description (unlikely line from gcc)"
221 set description "next over xstrdup"
224 -re ".*$gdb_prompt $" {
225 fail "unknown source line after $description"
229 fail "unknown source line near main"
233 gdb_test_multiple "$command" "$description" {
234 -re ".*No such file or directory.\r\n$gdb_prompt $" {
235 fail "$description (no source available)"
237 -re ".*A file or directory .* does not exist..\r\n$gdb_prompt $" {
238 fail "$description (no source available)"
240 -re ".*$gdb_prompt $" {
247 proc test_with_self { executable } {
254 # load yourself into the debugger
255 # This can take a relatively long time, particularly for testing where
256 # the executable is being accessed over a network, or where gdb does not
257 # support partial symbols for a particular target and has to load the
258 # entire symbol table. Set the timeout to 10 minutes, which should be
259 # adequate for most environments (it *has* timed out with 5 min on a
260 # SPARCstation SLC under moderate load, so this isn't unreasonable).
261 # After gdb is started, set the timeout to 30 seconds for the duration
262 # of this test, and then back to the original value.
264 set oldtimeout $timeout
266 verbose "Timeout is now $timeout seconds" 2
268 global gdb_file_cmd_debug_info
269 set gdb_file_cmd_debug_info "unset"
271 set result [gdb_load $executable]
272 set timeout $oldtimeout
273 verbose "Timeout is now $timeout seconds" 2
275 if { $result != 0 } then {
279 if { $gdb_file_cmd_debug_info != "debug" } then {
280 untested "No debug information, skipping testcase."
284 # disassemble yourself
285 gdb_test "x/10i main" \
286 "x/10i.*main.*main.$decimal.*main.$decimal.*" \
289 # Set a breakpoint at main
290 gdb_test "break captured_main" \
291 "Breakpoint.*at.* file.*, line.*" \
292 "breakpoint in captured_main"
294 # We'll need this when we send a ^C to GDB. Need to do it before we
295 # run the program and gdb starts saving and restoring tty states.
296 # On Ultrix, we don't need it and it is really slow (because shell_escape
297 # doesn't use vfork).
298 if ![istarget "*-*-ultrix*"] then {
299 gdb_test "shell stty intr '^C'" ".*" \
300 "set interrupt character in test_with_self"
303 # FIXME: If we put this after the run to main, the first list
304 # command doesn't print the same line as the current line where
306 gdb_test_no_output "set listsize 1" "set listsize to 1"
309 # It may take a very long time for the inferior gdb to start (lynx),
310 # so we bump it back up for the duration of this command.
313 set description "run until breakpoint at captured_main"
314 gdb_test_multiple "run -nw" "$description" {
315 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.* at .*main.c:.*$gdb_prompt $" {
318 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" {
319 xfail "$description (line numbers scrambled?)"
321 -re "vfork: No more processes.*$gdb_prompt $" {
322 fail "$description (out of virtual memory)"
323 set timeout $oldtimeout
324 verbose "Timeout is now $timeout seconds" 2
327 -re ".*$gdb_prompt $" {
329 set timeout $oldtimeout
330 verbose "Timeout is now $timeout seconds" 2
335 set timeout $oldtimeout
336 verbose "Timeout is now $timeout seconds" 2
338 # do we have a version number ?
339 gdb_test_multiple "print version" "printed version" {
340 -re ".\[0-9\]+ = .\[0-9.\]+.*$gdb_prompt $" {
341 pass "printed version as string"
343 -re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$gdb_prompt $" {
344 pass "printed version as pointer"
346 -re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$gdb_prompt $" {
347 pass "printed version with cast"
353 gdb_test "print \"foo\"" ".\[0-9\]+ = \"foo\"" "print a string"
355 # do_steps_and_nexts left us ready to execute an xmalloc call,
356 # so give that a try.
357 # If we don't actually enter the xmalloc call when we give a
358 # step command that seems like a genuine bug. It seems to happen
359 # on most RISC processors.
360 # NOTE drow/2003-06-22: However, if we step back to the preceding two
361 # lines, just keep stepping until we enter.
363 setup_xfail "alpha-*-*" "mips-*-*"
364 set description "step into xmalloc call"
365 gdb_test_multiple "step" "$description" {
366 -re "ncmd = 0;.*$gdb_prompt $" {
371 -re ".*cmdarg = .* xmalloc.*$gdb_prompt $" {
376 -re "dirsize = 1;.*$gdb_prompt $" {
381 -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
382 if { $stepped_back == 1 } {
389 -re "xmalloc.*size=.*at.*utils.c.*$gdb_prompt $" {
392 -re ".*No such file or directory.\r\n$gdb_prompt $" {
393 pass "$description (no source available)"
395 -re "A file or directory .* does not exist..\r\n$gdb_prompt $" {
396 pass "$description (no source available)"
400 # start the "xgdb" process
401 gdb_test_multiple "continue" "xgdb is at prompt" {
402 -re "GNU gdb \[0-9\.\]*.*Copyright \\(C\\) \[0-9\]* Free Software Foundation, Inc.*License GPLv3\\+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.*This is free software: you are free to change and redistribute it.*There is NO WARRANTY, to the extent permitted by law. Type \"show copying\".*and \"show warranty\" for details.*This GDB was configured as .*$gdb_prompt $" {
403 pass "xgdb is at prompt"
407 # set xgdb prompt so we can tell which is which
408 gdb_test_multiple "set prompt (xgdb) " "Set xgdb_prompt" {
409 -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" {
410 pass "Set xgdb prompt"
414 # kill the xgdb process
415 set description "send ^C to child process"
418 -re "Program received signal SIGINT.*$gdb_prompt $" {
421 -re ".*$gdb_prompt $" {
425 fail "$description (timeout)"
429 set description "send SIGINT signal to child process"
430 gdb_test "signal SIGINT" \
431 "Continuing with signal SIGINT.*" \
436 # This fails on some linux systems for unknown reasons. On the
437 # systems where it fails, sometimes it works fine when run manually.
438 # The testsuite failures may not be limited to just aout systems.
439 setup_xfail "i*86-pc-linuxaout-gnu"
440 set description "backtrace through signal handler"
441 gdb_test_multiple "backtrace" "$description" {
442 -re "#0.*(read|poll).*in main \\(.*\\) at .*gdb\\.c.*$gdb_prompt $" {
445 -re ".*$gdb_prompt $" {
446 # On the alpha, we hit the infamous problem about gdb
447 # being unable to get the frame pointer (mentioned in
448 # gdb/README). As it is intermittent, there is no way to
449 # XFAIL it which will give us an XPASS if the problem goes
451 setup_xfail "alpha*-*-osf*"
457 # Set the timeout back to the value it had when we were called.
458 set timeout $oldtimeout
459 verbose "Timeout is now $timeout seconds" 2
461 # Restart gdb in case next test expects it to be started already.
465 # Find a pathname to a file that we would execute if the shell was asked
466 # to run $arg using the current PATH.
468 proc find_gdb { arg } {
470 # If the arg directly specifies an existing executable file, then
473 if [file executable $arg] then {
477 set result [which $arg]
478 if [string match "/" [ string range $result 0 0 ]] then {
482 # If everything fails, just return the unqualified pathname as default
488 # Run the test with self.
489 # Copy the file executable file in case this OS doesn't like to edit its own
492 set GDB_FULLPATH [find_gdb $GDB]
494 # Remove any old copy lying around.
495 remote_file host delete x$tool
498 set file [remote_download host $GDB_FULLPATH x$tool]
499 set result [test_with_self $file];
501 catch "remote_file host delete $file";
503 if {$result <0} then {
504 warning "Couldn't test self"