1 # Copyright 1988-2013 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 3 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, see <http://www.gnu.org/licenses/>.
16 # This file was written by Rob Savoye. (rob@cygnus.com)
19 # are we on a target board
20 if { [is_remote target] || ![isnative] } then {
24 # Not all of the lines of code near the start of main are executed for
25 # every machine. Also, optimization may reorder some of the lines.
26 # So all we do is try to step or next over everything until we get
27 # to a line that we know is always executed.
29 proc do_steps_and_nexts {} {
33 gdb_reinitialize_dir $srcdir/..
36 for {set count 0} {$count < 32} {incr count} {
37 # NOTE: carlton/2002-12-11: The "initial brace" and
38 # "current_directory initialization" possibilities happen to
39 # me with GCC 3.1 on i686-pc-linux-gnu when I compile with
41 gdb_test_multiple "list" "list" {
42 -re ".*context = data.*$gdb_prompt $" {
43 set description "step over context initialization"
46 -re ".*argc = context->argc.*$gdb_prompt $" {
47 set description "step over argc initialization"
50 -re ".*argv = context->argv.*$gdb_prompt $" {
51 set description "step over argv initialization"
54 -re ".*quiet = 0.*$gdb_prompt $" {
55 set description "step over quiet initialization"
58 -re ".*batch = 0.*$gdb_prompt $" {
59 set description "step over batch initialization"
62 -re ".*symarg = NULL.*$gdb_prompt $" {
63 set description "step over symarg initialization"
66 -re ".*execarg = NULL.*$gdb_prompt $" {
67 set description "step over execarg initialization"
70 -re ".*pidarg = NULL.*$gdb_prompt $" {
71 set description "step over pidarg initialization"
74 -re ".*corearg = NULL.*$gdb_prompt $" {
75 set description "step over corearg initialization"
78 -re ".*pid_or_core_arg = NULL.*$gdb_prompt $" {
79 set description "step over pid_or_core_arg initialization"
82 -re ".*cdarg = NULL.*$gdb_prompt $" {
83 set description "step over cdarg initialization"
86 -re ".*ttyarg = NULL.*$gdb_prompt $" {
87 set description "step over ttyarg initialization"
90 -re ".*cmdarg_vec = NULL.*$gdb_prompt $" {
91 set description "step over cmdarg_vec initialization"
94 -re ".*pre_stat_chain = make_command_stats_cleanup.*$gdb_prompt $" {
95 set description "next over make_command_stats_cleanup and everything it calls"
98 -re ".*START_PROGRESS.*$gdb_prompt $" {
99 # Note: ezannoni/2004/02/17: This check should be
100 # removed, since as of today that source line is not
102 set description "next over START_PROGRESS and everything it calls"
105 -re ".*mac_init.*$gdb_prompt $" {
106 set description "next over mac_init and everything it calls"
109 -re ".*init_malloc.*$gdb_prompt $" {
110 # gdb 6.2.X is the last gdb which called init_malloc
111 set description "next over init_malloc and everything it calls"
114 -re ".*lim_at_start.*$gdb_prompt $" {
115 set description "next over lim_at_start initialization"
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 ".*dirsize = 1.*$gdb_prompt $" {
131 set description "next over dirsize initialization"
134 -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
137 -re ".*setlocale .LC_MESSAGES,.*$gdb_prompt $" {
138 set description "next over setlocale LC_MESSAGES"
141 -re ".*setlocale .LC_CTYPE,.*$gdb_prompt $" {
142 set description "next over setlocale LC_CTYPE"
145 -re ".*bindtextdomain .PACKAGE, LOCALEDIR.;.*$gdb_prompt $" {
146 set description "next over bindtextdomain"
149 -re ".*textdomain .PACKAGE.;.*$gdb_prompt $" {
150 set description "next over textdomain PACKAGE"
153 -re ".*VEC_cleanup .cmdarg_s.*$gdb_prompt $" {
154 set description "next over cmdarg_s VEC_cleanup"
157 -re "\[0-9\]+\[\t \]+\{\r\n$gdb_prompt $" {
158 set description "step over initial brace"
161 -re ".*current_directory = gdb_dirbuf.*$gdb_prompt $" {
162 set description "step over current_directory initialization"
165 -re ".*gdb_sysroot = .*$gdb_prompt $" {
166 # NOTE: carlton/2003-01-15: More optimization reordering,
167 # observed on GCC 3.1.
168 set description "step over gdb_sysroot initialization"
171 -re ".*ndir = 0.*$gdb_prompt $" {
172 set description "step over ndir initialization"
175 -re ".*instream = stdin.*$gdb_prompt $" {
176 set description "step over instream initialization"
179 -re ".*getcwd .gdb_dirbuf, sizeof .gdb_dirbuf.*$gdb_prompt $" {
180 set description "next over getcwd"
183 -re ".*gdb_program_name = xstrdup.*$gdb_prompt $" {
184 set description "next over xstrdup"
187 -re ".*quit_flag = 0.*$gdb_prompt $" {
188 set description "step over quit_flag initialization"
191 -re ".*gdb_stdout = stdio_fileopen .stdout.;.*$gdb_prompt $" {
192 set description "step over gdb_stdout initialization"
195 -re ".*gdb_stderr = stdio_fileopen .stderr.;.*$gdb_prompt $" {
196 set description "step over gdb_stderr initialization"
199 -re ".*main.c.*No such file or directory.*$gdb_prompt $" {
200 setup_xfail "rs6000-*-aix3*"
201 fail "must be able to list source lines"
204 -re ".*interpreter_p = xstrdup.*$gdb_prompt $" {
205 if { $unlikely_line == 0 } {
206 # This is a GCC optimization bug; a constant has been
207 # associated with the wrong line number.
208 setup_xfail "*-*-*" gcc/26475
209 fail "$description (unlikely line from gcc)"
212 set description "next over xstrdup"
215 -re ".*$gdb_prompt $" {
216 fail "unknown source line after $description"
220 fail "unknown source line near main"
224 gdb_test_multiple "$command" "$description" {
225 -re ".*No such file or directory.\r\n$gdb_prompt $" {
226 fail "$description (no source available)"
228 -re ".*A file or directory .* does not exist..\r\n$gdb_prompt $" {
229 fail "$description (no source available)"
231 -re ".*$gdb_prompt $" {
238 proc test_with_self { executable } {
244 global INTERNAL_GDBFLAGS
246 # load yourself into the debugger
247 # This can take a relatively long time, particularly for testing where
248 # the executable is being accessed over a network, or where gdb does not
249 # support partial symbols for a particular target and has to load the
250 # entire symbol table. Set the timeout to 10 minutes, which should be
251 # adequate for most environments (it *has* timed out with 5 min on a
252 # SPARCstation SLC under moderate load, so this isn't unreasonable).
253 # After gdb is started, set the timeout to 30 seconds for the duration
254 # of this test, and then back to the original value.
256 set oldtimeout $timeout
258 verbose "Timeout is now $timeout seconds" 2
260 global gdb_file_cmd_debug_info
261 set gdb_file_cmd_debug_info "unset"
263 set result [gdb_load $executable]
264 set timeout $oldtimeout
265 verbose "Timeout is now $timeout seconds" 2
267 if { $result != 0 } then {
271 if { $gdb_file_cmd_debug_info != "debug" } then {
272 untested "No debug information, skipping testcase."
276 # disassemble yourself
277 gdb_test "x/10i main" \
278 "x/10i.*main.*main.$decimal.*main.$decimal.*" \
281 # Set a breakpoint at main
282 gdb_test "break captured_main" \
283 "Breakpoint.*at.* file.*, line.*" \
284 "breakpoint in captured_main"
286 # We'll need this when we send a ^C to GDB. Need to do it before we
287 # run the program and gdb starts saving and restoring tty states.
288 # On Ultrix, we don't need it and it is really slow (because shell_escape
289 # doesn't use vfork).
290 if ![istarget "*-*-ultrix*"] then {
291 gdb_test "shell stty intr '^C'" ".*" \
292 "set interrupt character in test_with_self"
295 # FIXME: If we put this after the run to main, the first list
296 # command doesn't print the same line as the current line where
298 gdb_test_no_output "set listsize 1" "set listsize to 1"
301 # It may take a very long time for the inferior gdb to start (lynx),
302 # so we bump it back up for the duration of this command.
305 set description "run until breakpoint at captured_main"
306 gdb_test_multiple "run $INTERNAL_GDBFLAGS" "$description" {
307 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.* at .*main.c:.*$gdb_prompt $" {
310 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" {
311 xfail "$description (line numbers scrambled?)"
313 -re "vfork: No more processes.*$gdb_prompt $" {
314 fail "$description (out of virtual memory)"
315 set timeout $oldtimeout
316 verbose "Timeout is now $timeout seconds" 2
319 -re ".*$gdb_prompt $" {
321 set timeout $oldtimeout
322 verbose "Timeout is now $timeout seconds" 2
327 set timeout $oldtimeout
328 verbose "Timeout is now $timeout seconds" 2
330 # do we have a version number ?
331 gdb_test_multiple "print version" "printed version" {
332 -re ".\[0-9\]+ = .\[0-9.\]+.*$gdb_prompt $" {
333 pass "printed version as string"
335 -re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$gdb_prompt $" {
336 pass "printed version as pointer"
338 -re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$gdb_prompt $" {
339 pass "printed version with cast"
345 gdb_test "print \"foo\"" ".\[0-9\]+ = \"foo\"" "print a string"
347 # do_steps_and_nexts left us ready to execute an xmalloc call,
348 # so give that a try.
349 # If we don't actually enter the xmalloc call when we give a
350 # step command that seems like a genuine bug. It seems to happen
351 # on most RISC processors.
352 # NOTE drow/2003-06-22: However, if we step back to the preceding two
353 # lines, just keep stepping until we enter.
355 setup_xfail "alpha-*-*" "mips-*-*"
356 set description "step into xmalloc call"
357 gdb_test_multiple "step" "$description" {
358 -re "ncmd = 0;.*$gdb_prompt $" {
363 -re ".*cmdarg = .* xmalloc.*$gdb_prompt $" {
368 -re "dirsize = 1;.*$gdb_prompt $" {
373 -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
374 if { $stepped_back == 1 } {
381 -re "xmalloc.*size=.*at.*utils.c.*$gdb_prompt $" {
384 -re ".*No such file or directory.\r\n$gdb_prompt $" {
385 pass "$description (no source available)"
387 -re "A file or directory .* does not exist..\r\n$gdb_prompt $" {
388 pass "$description (no source available)"
392 # start the "xgdb" process
393 if [target_info exists gdb,noinferiorio] {
394 # Maybe testing with a local extended-remote gdbserver. With
395 # no way to interact with inferior GDB, all we can do is let
397 send_gdb "continue\n"
398 # Wait a bit while the inferior gdb gets to its prompt.
401 set test "xgdb is at prompt"
402 gdb_test_multiple "continue" $test {
403 -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 $" {
408 # set xgdb prompt so we can tell which is which
409 gdb_test_multiple "set prompt (xgdb) " "Set xgdb_prompt" {
410 -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" {
411 pass "Set xgdb prompt"
416 # kill the xgdb process
417 set description "send ^C to child process"
420 -re "Program received signal SIGINT.*$gdb_prompt $" {
423 -re ".*$gdb_prompt $" {
427 fail "$description (timeout)"
431 set description "send SIGINT signal to child process"
432 gdb_test "signal SIGINT" \
433 "Continuing with signal SIGINT.*" \
438 # This fails on some linux systems for unknown reasons. On the
439 # systems where it fails, sometimes it works fine when run manually.
440 # The testsuite failures may not be limited to just aout systems.
441 setup_xfail "i*86-pc-linuxaout-gnu"
442 set description "backtrace through signal handler"
443 gdb_test_multiple "backtrace" "$description" {
444 -re "#0.*(read|poll).*in main \\(.*\\) at .*gdb\\.c.*$gdb_prompt $" {
447 -re ".*$gdb_prompt $" {
448 # On the alpha, we hit the infamous problem about gdb
449 # being unable to get the frame pointer (mentioned in
450 # gdb/README). As it is intermittent, there is no way to
451 # XFAIL it which will give us an XPASS if the problem goes
453 setup_xfail "alpha*-*-osf*"
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"