1 # Copyright 2002-2004, 2007-2012 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.
24 # are we on a target board
25 if { [is_remote target] || ![isnative] } then {
29 proc setup_test { executable } {
33 # load yourself into the debugger
34 # This can take a relatively long time, particularly for testing where
35 # the executable is being accessed over a network, or where gdb does not
36 # support partial symbols for a particular target and has to load the
37 # entire symbol table. Set the timeout to 10 minutes, which should be
38 # adequate for most environments (it *has* timed out with 5 min on a
39 # SPARCstation SLC under moderate load, so this isn't unreasonable).
40 # After gdb is started, set the timeout to 30 seconds for the duration
41 # of this test, and then back to the original value.
43 set oldtimeout $timeout
45 verbose "Timeout is now $timeout seconds" 2
47 global gdb_file_cmd_debug_info
48 set gdb_file_cmd_debug_info "unset"
50 set result [gdb_load $executable]
51 set timeout $oldtimeout
52 verbose "Timeout is now $timeout seconds" 2
54 if { $result != 0 } then {
58 if { $gdb_file_cmd_debug_info != "debug" } then {
59 untested "No debug information, skipping testcase."
63 # Set a breakpoint at main
64 gdb_test "break captured_main" \
65 "Breakpoint.*at.* file.*, line.*" \
66 "breakpoint in captured_main"
69 # It may take a very long time for the inferior gdb to start (lynx),
70 # so we bump it back up for the duration of this command.
73 set description "run until breakpoint at captured_main"
74 gdb_test_multiple "run -nw" "$description" {
75 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.* at .*main.c:.*$gdb_prompt $" {
78 -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" {
79 xfail "$description (line numbers scrambled?)"
81 -re "vfork: No more processes.*$gdb_prompt $" {
82 fail "$description (out of virtual memory)"
83 set timeout $oldtimeout
84 verbose "Timeout is now $timeout seconds" 2
87 -re ".*$gdb_prompt $" {
89 set timeout $oldtimeout
90 verbose "Timeout is now $timeout seconds" 2
95 set timeout $oldtimeout
96 verbose "Timeout is now $timeout seconds" 2
101 proc test_with_self { executable } {
103 set setup_result [setup_test $executable]
104 if {$setup_result <0} then {
108 # A file which contains a directory prefix
109 gdb_test "print xfullpath (\"./xfullpath.exp\")" \
110 ".\[0-9\]+ =.*\".*/xfullpath.exp\"" \
111 "A filename with ./ as the directory prefix"
113 # A file which contains a directory prefix
114 gdb_test "print xfullpath (\"../../defs.h\")" \
115 ".\[0-9\]+ =.*\".*/defs.h\"" \
116 "A filename with ../ in the directory prefix"
118 # A one-character filename
119 gdb_test "print xfullpath (\"./a\")" \
120 ".\[0-9\]+ =.*\".*/a\"" \
121 "A one-char filename in the current directory"
123 # A file in the root directory
124 gdb_test "print xfullpath (\"/root_file_which_should_exist\")" \
125 ".\[0-9\]+ =.*\"/root_file_which_should_exist\"" \
126 "A filename in the root directory"
128 # A file which does not have a directory prefix
129 gdb_test "print xfullpath (\"xfullpath.exp\")" \
130 ".\[0-9\]+ =.*\"xfullpath.exp\"" \
131 "A filename without any directory prefix"
133 # A one-char filename without any directory prefix
134 gdb_test "print xfullpath (\"a\")" \
135 ".\[0-9\]+ =.*\"a\"" \
136 "A one-char filename without any directory prefix"
139 gdb_test "print xfullpath (\"\")" \
140 ".\[0-9\]+ =.*\"\"" \
146 # Find a pathname to a file that we would execute if the shell was asked
147 # to run $arg using the current PATH.
149 proc find_gdb { arg } {
151 # If the arg directly specifies an existing executable file, then
154 if [file executable $arg] then {
158 set result [which $arg]
159 if [string match "/" [ string range $result 0 0 ]] then {
163 # If everything fails, just return the unqualified pathname as default
169 # Run the test with self.
170 # Copy the file executable file in case this OS doesn't like to edit its own
173 set GDB_FULLPATH [find_gdb $GDB]
175 # Remove any old copy lying around.
176 remote_file host delete x$tool
179 set file [remote_download host $GDB_FULLPATH x$tool]
180 set result [test_with_self $file];
182 catch "remote_file host delete $file";
184 if {$result <0} then {
185 warning "Couldn't test self"