1 # Copyright 1997, 1998, 1999, 2003, 2007, 2008, 2009, 2010, 2011
2 # 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/>. */
24 # test running programs
27 # This test exists solely to exercise the "environment" commands for
28 # code-coverage on HP-UX.
30 if ![istarget "hppa*-*-hpux*"] then {
35 set srcfile ${testfile}.c
36 set srcfile1 ${testfile}1.c
37 set binfile ${objdir}/${subdir}/${testfile}
39 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
44 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
49 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
56 gdb_reinitialize_dir $srcdir/$subdir
59 if ![runto_main] then { fail "environment command tests suppressed" }
61 # (No, this is not really related to the environment commands. But it's
62 # a convenient place to verify that this command works.)
64 send_gdb "info program\n"
66 -re ".*Using the running image of child process \[0-9\]*.\r\nProgram stopped at 0x\[0-9a-fA-F\]*.\r\nIt stopped at breakpoint 1..*$gdb_prompt $"\
70 timeout {fail "(timeout) info program"}
73 # We don't really care where this step lands, so long as it gets
74 # the inferior pushed off the breakpoint it's currently on...
78 -re ".*$gdb_prompt $"\
79 {pass "step before info program"}
80 timeout {fail "(timeout) step before info program"}
82 send_gdb "info program\n"
84 -re ".*Using the running image of child process \[0-9\]*.\r\nProgram stopped at 0x\[0-9a-fA-F\]*.\r\nIt stopped after being stepped..*$gdb_prompt $"\
85 {pass "info program after step"}
87 {fail "info program after step"}
88 timeout {fail "(timeout) info program after step"}
91 if ![runto_main] then { fail "environment command tests suppressed" }
98 -re ".*$gdb_prompt $"\
99 {pass "delete breakpoint before info program"}
100 timeout {fail "(timeout) delete breakpoint before info program"}
104 {fail "delete breakpoint before info program"}
105 timeout {fail "(timeout) delete breakpoint before info program"}
107 send_gdb "info program\n"
109 -re ".*Using the running image of child process \[0-9\]*.\r\nProgram stopped at 0x\[0-9a-fA-F\]*.\r\nIt stopped at a breakpoint that has since been deleted..*$gdb_prompt $"\
110 {pass "info program after deleted breakpoint"}
112 {fail "info program after deleted breakpoint"}
113 timeout {fail "(timeout) info program after deleted breakpoint"}
116 # Verify that we can show all currently-set environment variables.
117 # (It's a bit hacky, but nonetheless probably safe to check for at
118 # least the SHELL variable.)
120 # need to increase timeout because of very long output
121 set oldtimeout $timeout
122 set timeout [expr "$timeout + 300"]
124 send_gdb "show environment\n"
126 -re ".*SHELL=(\[a-zA-Z0-9\]*).*$gdb_prompt $"\
127 {pass "show environment"}
129 {fail "show environment"}
130 timeout {fail "(timeout) show environment"}
132 set timeout $oldtimeout
134 # Verify that we can unset a specific environment variable.
136 send_gdb "unset environment EDITOR\n"
139 {pass "issue unset environment"}
140 timeout {fail "(timeout) issue unset environment"}
142 send_gdb "show environment EDITOR\n"
144 -re "Environment variable \"EDITOR\" not defined.\r\n$gdb_prompt $"\
145 {pass "unset environment"}
147 {fail "unset environment"}
148 timeout {fail "(timeout) unset environment"}
151 # Verify that we can unset all environment variables.
153 send_gdb "unset environment\n"
155 -re "Delete all environment variables.*y or n. $"\
159 {pass "unset entire environment"}
160 timeout {fail "(timeout) unset entire environment"}
164 {fail "unset entire environment"}
165 timeout {fail "(timeout) unset entire environment"}
168 # Verify that we can set a specific environment variable.
170 send_gdb "set environment EDITOR emacs\n"
173 {pass "issue set environment"}
174 timeout {fail "(timeout) issue set environment"}
176 send_gdb "show environment EDITOR\n"
178 -re "EDITOR = emacs\r\n$gdb_prompt $"\
179 {pass "set environment"}
181 {fail "set environment"}
182 timeout {fail "(timeout) set environment"}
185 # Verify that GDB responds gracefully to a request to set environment,
186 # with no variable name.
188 send_gdb "set environment\n"
190 -re "Argument required .environment variable and value..*$gdb_prompt $"\
191 {pass "set environment without variable disallowed"}
193 {fail "set environment without variable disallowed"}
194 timeout {fail "(timeout) set environment without variable disallowed"}
197 # I'm not sure just what GDB has in mind in explicitly checking
198 # for this variant, but since GDB handles it, test it.
200 send_gdb "set environment =\n"
202 -re "Argument required .environment variable to set..*$gdb_prompt $"\
203 {pass "set environment equals without variable disallowed"}
205 {fail "set environment equals without variable disallowed"}
206 timeout {fail "(timeout) set environment equals without variable disallowed"}
209 # Setting an environment variable without a value sets it to a NULL
212 send_gdb "set environment EDITOR\n"
214 -re "Setting environment variable \"EDITOR\" to null value..*$gdb_prompt $"\
215 {pass "issue set environment without variable value"}
217 {fail "issue set environment without variable value"}
218 timeout {fail "(timeout) issue set environment without variable value"}
220 send_gdb "show environment EDITOR\n"
222 -re "EDITOR = \r\n$gdb_prompt $"\
223 {pass "set environment without variable value"}
225 {fail "set environment without variable value"}
226 timeout {fail "(timeout) set environment without variable value"}
229 # Verify that GDB responds gracefully to an attempt to show a
230 # non-existent environment variable. (We hope this variable is
233 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
235 -re "Environment variable \"FOOBARBAZGRUNGESPAZBALL\" not defined..*$gdb_prompt $"\
236 {pass "show non-existent environment variable disallowed"}
238 {fail "show non-existent environment variable disallowed"}
239 timeout {fail "(timeout) show non-existent environment variable disallowed"}
242 # Verify that GDB can set an environment variable hitherto undefined.
244 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t\n"
247 {pass "issue set environment for previously undefined variable"}
248 timeout {fail "(timeout) issue set environment for previously undefined variable"}
250 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
252 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
253 {pass "set environment for previously undefined variable"}
255 {fail "set environment for previously undefined variable"}
256 timeout {fail "(timeout) set environment for previously undefined variable"}
259 # Verify that GDB can also set an environment variable using the "="
262 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = t\n"
265 {pass "issue set environment with equals"}
266 timeout {fail "(timeout) issue set environment with equals"}
268 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
270 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
271 {pass "set environment with equals"}
273 {fail "set environment with equals"}
274 timeout {fail "(timeout) set environment with equals"}
277 # Verify that GDB can set an environment variable to a value that has
278 # an embedded (trailing, in this case) equals.
280 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t=\n"
283 {pass "issue set environment with trailing equals"}
284 timeout {fail "(timeout) issue set environment with trailing equals"}
286 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
288 -re "FOOBARBAZGRUNGESPAZBALL = t=\r\n$gdb_prompt $"\
289 {pass "set environment with trailing equals"}
291 {fail "set environment with trailing equals"}
292 timeout {fail "(timeout) set environment with trailing equals"}
295 # Verify that GDB can set an environment variable to a value preceded
296 # by whitespace, and that such whitespace is ignored (not included
299 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = foo\n"
302 {pass "issue set environment with preceding whitespace"}
303 timeout {fail "(timeout) issue set environment with preceding whitespace"}
305 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
307 -re "FOOBARBAZGRUNGESPAZBALL = foo\r\n$gdb_prompt $"\
308 {pass "set environment with preceding whitespace"}
310 {fail "set environment with preceding whitespace"}
311 timeout {fail "(timeout) set environment with preceding whitespace"}
314 # Verify that GDB can manipulate the distinguished PATH variable.
316 send_gdb "path /tmp/FOOBARBAZGRUNGESPAZBALL\n"
318 -re ".*Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
322 timeout {fail "(timeout) issue path"}
324 send_gdb "show paths\n"
326 -re "Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
330 timeout {fail "(timeout) show paths"}