137780268d56ea564c28a3c412b01ab3e0509c59
[platform/upstream/binutils.git] / gdb / testsuite / gdb.gdb / xfullpath.exp
1 # Copyright 2002-2004, 2007-2012 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 # This file was written by Joel Brobecker. (brobecker@gnat.com), derived
17 # from selftest.exp, written by Rob Savoye.
18
19 if $tracelevel then {
20     strace $tracelevel
21 }
22
23
24 # are we on a target board
25 if { [is_remote target] || ![isnative] } then {
26     return
27 }
28
29 proc setup_test { executable } {
30     global gdb_prompt
31     global timeout
32
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.
42
43     set oldtimeout $timeout
44     set timeout 600
45     verbose "Timeout is now $timeout seconds" 2
46
47     global gdb_file_cmd_debug_info
48     set gdb_file_cmd_debug_info "unset"
49
50     set result [gdb_load $executable]
51     set timeout $oldtimeout
52     verbose "Timeout is now $timeout seconds" 2
53
54     if { $result != 0 } then {
55         return -1
56     }
57
58     if { $gdb_file_cmd_debug_info != "debug" } then {
59         untested "No debug information, skipping testcase."
60         return -1
61     }
62
63     # Set a breakpoint at main
64     gdb_test "break captured_main" \
65             "Breakpoint.*at.* file.*, line.*" \
66             "breakpoint in captured_main"
67
68     # run yourself
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.
71     set timeout 600
72
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 $" {
76             pass "$description"
77         }
78         -re "Starting program.*Breakpoint \[0-9\]+,.*captured_main .data.*$gdb_prompt $" {
79             xfail "$description (line numbers scrambled?)"
80         }
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
85             return -1
86         }
87         -re ".*$gdb_prompt $" {
88             fail "$description"
89             set timeout $oldtimeout
90             verbose "Timeout is now $timeout seconds" 2
91             return -1
92         }
93     }
94
95     set timeout $oldtimeout
96     verbose "Timeout is now $timeout seconds" 2
97
98     return 0
99 }
100
101 proc test_with_self { executable } {
102
103     set setup_result [setup_test $executable]
104     if {$setup_result <0} then {
105         return -1
106     }
107
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"
112
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"
117
118     # A one-character filename
119     gdb_test "print xfullpath (\"./a\")" \
120              ".\[0-9\]+ =.*\".*/a\"" \
121              "A one-char filename in the current directory"
122           
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"
127           
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"
132
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"
137
138     # An empty filename
139     gdb_test "print xfullpath (\"\")" \
140              ".\[0-9\]+ =.*\"\"" \
141              "An empty filename"
142
143     return 0
144 }
145
146 # Find a pathname to a file that we would execute if the shell was asked
147 # to run $arg using the current PATH.
148
149 proc find_gdb { arg } {
150
151     # If the arg directly specifies an existing executable file, then
152     # simply use it.
153
154     if [file executable $arg] then {
155         return $arg
156     }
157
158     set result [which $arg]
159     if [string match "/" [ string range $result 0 0 ]] then {
160         return $result
161     }
162
163     # If everything fails, just return the unqualified pathname as default
164     # and hope for best.
165
166     return $arg
167 }
168
169 # Run the test with self.
170 # Copy the file executable file in case this OS doesn't like to edit its own
171 # text space.
172
173 set GDB_FULLPATH [find_gdb $GDB]
174
175 # Remove any old copy lying around.
176 remote_file host delete x$tool
177
178 gdb_start
179 set file [remote_download host $GDB_FULLPATH x$tool]
180 set result [test_with_self $file];
181 gdb_exit;
182 catch "remote_file host delete $file";
183
184 if {$result <0} then {
185     warning "Couldn't test self"
186     return -1
187 }