1 # Copyright 1997-1999, 2003, 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/>. */
21 # test running programs
24 # This test exists solely to exercise the "environment" commands for
25 # code-coverage on HP-UX.
27 if ![istarget "hppa*-*-hpux*"] then {
32 set srcfile ${testfile}.c
33 set srcfile1 ${testfile}1.c
34 set binfile ${objdir}/${subdir}/${testfile}
36 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
41 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
46 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
53 gdb_reinitialize_dir $srcdir/$subdir
56 if ![runto_main] then { fail "environment command tests suppressed" }
58 # (No, this is not really related to the environment commands. But it's
59 # a convenient place to verify that this command works.)
61 send_gdb "info program\n"
63 -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 $"\
67 timeout {fail "(timeout) info program"}
70 # We don't really care where this step lands, so long as it gets
71 # the inferior pushed off the breakpoint it's currently on...
75 -re ".*$gdb_prompt $"\
76 {pass "step before info program"}
77 timeout {fail "(timeout) step before info program"}
79 send_gdb "info program\n"
81 -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 $"\
82 {pass "info program after step"}
84 {fail "info program after step"}
85 timeout {fail "(timeout) info program after step"}
88 if ![runto_main] then { fail "environment command tests suppressed" }
95 -re ".*$gdb_prompt $"\
96 {pass "delete breakpoint before info program"}
97 timeout {fail "(timeout) delete breakpoint before info program"}
101 {fail "delete breakpoint before info program"}
102 timeout {fail "(timeout) delete breakpoint before info program"}
104 send_gdb "info program\n"
106 -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 $"\
107 {pass "info program after deleted breakpoint"}
109 {fail "info program after deleted breakpoint"}
110 timeout {fail "(timeout) info program after deleted breakpoint"}
113 # Verify that we can show all currently-set environment variables.
114 # (It's a bit hacky, but nonetheless probably safe to check for at
115 # least the SHELL variable.)
117 # need to increase timeout because of very long output
118 set oldtimeout $timeout
119 set timeout [expr "$timeout + 300"]
121 send_gdb "show environment\n"
123 -re ".*SHELL=(\[a-zA-Z0-9\]*).*$gdb_prompt $"\
124 {pass "show environment"}
126 {fail "show environment"}
127 timeout {fail "(timeout) show environment"}
129 set timeout $oldtimeout
131 # Verify that we can unset a specific environment variable.
133 send_gdb "unset environment EDITOR\n"
136 {pass "issue unset environment"}
137 timeout {fail "(timeout) issue unset environment"}
139 send_gdb "show environment EDITOR\n"
141 -re "Environment variable \"EDITOR\" not defined.\r\n$gdb_prompt $"\
142 {pass "unset environment"}
144 {fail "unset environment"}
145 timeout {fail "(timeout) unset environment"}
148 # Verify that we can unset all environment variables.
150 send_gdb "unset environment\n"
152 -re "Delete all environment variables.*y or n. $"\
156 {pass "unset entire environment"}
157 timeout {fail "(timeout) unset entire environment"}
161 {fail "unset entire environment"}
162 timeout {fail "(timeout) unset entire environment"}
165 # Verify that we can set a specific environment variable.
167 send_gdb "set environment EDITOR emacs\n"
170 {pass "issue set environment"}
171 timeout {fail "(timeout) issue set environment"}
173 send_gdb "show environment EDITOR\n"
175 -re "EDITOR = emacs\r\n$gdb_prompt $"\
176 {pass "set environment"}
178 {fail "set environment"}
179 timeout {fail "(timeout) set environment"}
182 # Verify that GDB responds gracefully to a request to set environment,
183 # with no variable name.
185 send_gdb "set environment\n"
187 -re "Argument required .environment variable and value..*$gdb_prompt $"\
188 {pass "set environment without variable disallowed"}
190 {fail "set environment without variable disallowed"}
191 timeout {fail "(timeout) set environment without variable disallowed"}
194 # I'm not sure just what GDB has in mind in explicitly checking
195 # for this variant, but since GDB handles it, test it.
197 send_gdb "set environment =\n"
199 -re "Argument required .environment variable to set..*$gdb_prompt $"\
200 {pass "set environment equals without variable disallowed"}
202 {fail "set environment equals without variable disallowed"}
203 timeout {fail "(timeout) set environment equals without variable disallowed"}
206 # Setting an environment variable without a value sets it to a NULL
209 send_gdb "set environment EDITOR\n"
211 -re "Setting environment variable \"EDITOR\" to null value..*$gdb_prompt $"\
212 {pass "issue set environment without variable value"}
214 {fail "issue set environment without variable value"}
215 timeout {fail "(timeout) issue set environment without variable value"}
217 send_gdb "show environment EDITOR\n"
219 -re "EDITOR = \r\n$gdb_prompt $"\
220 {pass "set environment without variable value"}
222 {fail "set environment without variable value"}
223 timeout {fail "(timeout) set environment without variable value"}
226 # Verify that GDB responds gracefully to an attempt to show a
227 # non-existent environment variable. (We hope this variable is
230 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
232 -re "Environment variable \"FOOBARBAZGRUNGESPAZBALL\" not defined..*$gdb_prompt $"\
233 {pass "show non-existent environment variable disallowed"}
235 {fail "show non-existent environment variable disallowed"}
236 timeout {fail "(timeout) show non-existent environment variable disallowed"}
239 # Verify that GDB can set an environment variable hitherto undefined.
241 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t\n"
244 {pass "issue set environment for previously undefined variable"}
245 timeout {fail "(timeout) issue set environment for previously undefined variable"}
247 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
249 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
250 {pass "set environment for previously undefined variable"}
252 {fail "set environment for previously undefined variable"}
253 timeout {fail "(timeout) set environment for previously undefined variable"}
256 # Verify that GDB can also set an environment variable using the "="
259 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = t\n"
262 {pass "issue set environment with equals"}
263 timeout {fail "(timeout) issue set environment with equals"}
265 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
267 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
268 {pass "set environment with equals"}
270 {fail "set environment with equals"}
271 timeout {fail "(timeout) set environment with equals"}
274 # Verify that GDB can set an environment variable to a value that has
275 # an embedded (trailing, in this case) equals.
277 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t=\n"
280 {pass "issue set environment with trailing equals"}
281 timeout {fail "(timeout) issue set environment with trailing equals"}
283 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
285 -re "FOOBARBAZGRUNGESPAZBALL = t=\r\n$gdb_prompt $"\
286 {pass "set environment with trailing equals"}
288 {fail "set environment with trailing equals"}
289 timeout {fail "(timeout) set environment with trailing equals"}
292 # Verify that GDB can set an environment variable to a value preceded
293 # by whitespace, and that such whitespace is ignored (not included
296 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = foo\n"
299 {pass "issue set environment with preceding whitespace"}
300 timeout {fail "(timeout) issue set environment with preceding whitespace"}
302 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
304 -re "FOOBARBAZGRUNGESPAZBALL = foo\r\n$gdb_prompt $"\
305 {pass "set environment with preceding whitespace"}
307 {fail "set environment with preceding whitespace"}
308 timeout {fail "(timeout) set environment with preceding whitespace"}
311 # Verify that GDB can manipulate the distinguished PATH variable.
313 send_gdb "path /tmp/FOOBARBAZGRUNGESPAZBALL\n"
315 -re ".*Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
319 timeout {fail "(timeout) issue path"}
321 send_gdb "show paths\n"
323 -re "Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
327 timeout {fail "(timeout) show paths"}