1 # Copyright 2002-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 Joel Brobecker. (brobecker@gnat.com), derived
17 # from selftest.exp, written by Rob Savoye.
20 # are we on a target board
21 if { [is_remote target] || ![isnative] } then {
25 proc setup_test { executable } {
28 global INTERNAL_GDBFLAGS
30 # load yourself into the debugger
31 # This can take a relatively long time, particularly for testing where
32 # the executable is being accessed over a network, or where gdb does not
33 # support partial symbols for a particular target and has to load the
34 # entire symbol table. Set the timeout to 10 minutes, which should be
35 # adequate for most environments (it *has* timed out with 5 min on a
36 # SPARCstation SLC under moderate load, so this isn't unreasonable).
37 # After gdb is started, set the timeout to 30 seconds for the duration
38 # of this test, and then back to the original value.
40 set oldtimeout $timeout
42 verbose "Timeout is now $timeout seconds" 2
44 global gdb_file_cmd_debug_info
45 set gdb_file_cmd_debug_info "unset"
47 set result [gdb_load $executable]
48 set timeout $oldtimeout
49 verbose "Timeout is now $timeout seconds" 2
51 if { $result != 0 } then {
55 if { $gdb_file_cmd_debug_info != "debug" } then {
56 untested "No debug information, skipping testcase."
60 # Set a breakpoint at main
61 gdb_test "break captured_main" \
62 "Breakpoint.*at.* file.*, line.*" \
63 "breakpoint in captured_main"
66 # It may take a very long time for the inferior gdb to start (lynx),
67 # so we bump it back up for the duration of this command.
70 set description "run until breakpoint at captured_main"
71 gdb_test_multiple "run $INTERNAL_GDBFLAGS" "$description" {
72 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.* at .*main.c:.*$gdb_prompt $" {
75 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" {
76 xfail "$description (line numbers scrambled?)"
78 -re "vfork: No more processes.*$gdb_prompt $" {
79 fail "$description (out of virtual memory)"
80 set timeout $oldtimeout
81 verbose "Timeout is now $timeout seconds" 2
84 -re ".*$gdb_prompt $" {
86 set timeout $oldtimeout
87 verbose "Timeout is now $timeout seconds" 2
92 set timeout $oldtimeout
93 verbose "Timeout is now $timeout seconds" 2
98 proc test_with_self { executable } {
100 set setup_result [setup_test $executable]
101 if {$setup_result <0} then {
105 # A file which contains a directory prefix
106 gdb_test "print xfullpath (\"./xfullpath.exp\")" \
107 ".\[0-9\]+ =.*\".*/xfullpath.exp\"" \
108 "A filename with ./ as the directory prefix"
110 # A file which contains a directory prefix
111 gdb_test "print xfullpath (\"../../defs.h\")" \
112 ".\[0-9\]+ =.*\".*/defs.h\"" \
113 "A filename with ../ in the directory prefix"
115 # A one-character filename
116 gdb_test "print xfullpath (\"./a\")" \
117 ".\[0-9\]+ =.*\".*/a\"" \
118 "A one-char filename in the current directory"
120 # A file in the root directory
121 gdb_test "print xfullpath (\"/root_file_which_should_exist\")" \
122 ".\[0-9\]+ =.*\"/root_file_which_should_exist\"" \
123 "A filename in the root directory"
125 # A file which does not have a directory prefix
126 gdb_test "print xfullpath (\"xfullpath.exp\")" \
127 ".\[0-9\]+ =.*\"xfullpath.exp\"" \
128 "A filename without any directory prefix"
130 # A one-char filename without any directory prefix
131 gdb_test "print xfullpath (\"a\")" \
132 ".\[0-9\]+ =.*\"a\"" \
133 "A one-char filename without any directory prefix"
136 gdb_test "print xfullpath (\"\")" \
137 ".\[0-9\]+ =.*\"\"" \
143 # Find a pathname to a file that we would execute if the shell was asked
144 # to run $arg using the current PATH.
146 proc find_gdb { arg } {
148 # If the arg directly specifies an existing executable file, then
151 if [file executable $arg] then {
155 set result [which $arg]
156 if [string match "/" [ string range $result 0 0 ]] then {
160 # If everything fails, just return the unqualified pathname as default
166 # Run the test with self.
167 # Copy the file executable file in case this OS doesn't like to edit its own
170 set GDB_FULLPATH [find_gdb $GDB]
172 # Remove any old copy lying around.
173 remote_file host delete x$tool
176 set file [remote_download host $GDB_FULLPATH x$tool]
177 set result [test_with_self $file];
179 catch "remote_file host delete $file";
181 if {$result <0} then {
182 warning "Couldn't test self"