1 # Copyright 1997, 1998, 1999, 2003, 2007, 2008, 2009
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
29 # This test exists solely to exercise the "environment" commands for
30 # code-coverage on HP-UX.
32 if ![istarget "hppa*-*-hpux*"] then {
37 set srcfile ${testfile}.c
38 set srcfile1 ${testfile}1.c
39 set binfile ${objdir}/${subdir}/${testfile}
41 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
46 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
51 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
58 gdb_reinitialize_dir $srcdir/$subdir
61 if ![runto_main] then { fail "environment command tests suppressed" }
63 # (No, this is not really related to the environment commands. But it's
64 # a convenient place to verify that this command works.)
66 send_gdb "info program\n"
68 -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 $"\
72 timeout {fail "(timeout) info program"}
75 # We don't really care where this step lands, so long as it gets
76 # the inferior pushed off the breakpoint it's currently on...
80 -re ".*$gdb_prompt $"\
81 {pass "step before info program"}
82 timeout {fail "(timeout) step before info program"}
84 send_gdb "info program\n"
86 -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 $"\
87 {pass "info program after step"}
89 {fail "info program after step"}
90 timeout {fail "(timeout) info program after step"}
93 if ![runto_main] then { fail "environment command tests suppressed" }
100 -re ".*$gdb_prompt $"\
101 {pass "delete breakpoint before info program"}
102 timeout {fail "(timeout) delete breakpoint before info program"}
106 {fail "delete breakpoint before info program"}
107 timeout {fail "(timeout) delete breakpoint before info program"}
109 send_gdb "info program\n"
111 -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 $"\
112 {pass "info program after deleted breakpoint"}
114 {fail "info program after deleted breakpoint"}
115 timeout {fail "(timeout) info program after deleted breakpoint"}
118 # Verify that we can show all currently-set environment variables.
119 # (It's a bit hacky, but nonetheless probably safe to check for at
120 # least the SHELL variable.)
122 # need to increase timeout because of very long output
123 set oldtimeout $timeout
124 set timeout [expr "$timeout + 300"]
126 send_gdb "show environment\n"
128 -re ".*SHELL=(\[a-zA-Z0-9\]*).*$gdb_prompt $"\
129 {pass "show environment"}
131 {fail "show environment"}
132 timeout {fail "(timeout) show environment"}
134 set timeout $oldtimeout
136 # Verify that we can unset a specific environment variable.
138 send_gdb "unset environment EDITOR\n"
141 {pass "issue unset environment"}
142 timeout {fail "(timeout) issue unset environment"}
144 send_gdb "show environment EDITOR\n"
146 -re "Environment variable \"EDITOR\" not defined.\r\n$gdb_prompt $"\
147 {pass "unset environment"}
149 {fail "unset environment"}
150 timeout {fail "(timeout) unset environment"}
153 # Verify that we can unset all environment variables.
155 send_gdb "unset environment\n"
157 -re "Delete all environment variables.*y or n. $"\
161 {pass "unset entire environment"}
162 timeout {fail "(timeout) unset entire environment"}
166 {fail "unset entire environment"}
167 timeout {fail "(timeout) unset entire environment"}
170 # Verify that we can set a specific environment variable.
172 send_gdb "set environment EDITOR emacs\n"
175 {pass "issue set environment"}
176 timeout {fail "(timeout) issue set environment"}
178 send_gdb "show environment EDITOR\n"
180 -re "EDITOR = emacs\r\n$gdb_prompt $"\
181 {pass "set environment"}
183 {fail "set environment"}
184 timeout {fail "(timeout) set environment"}
187 # Verify that GDB responds gracefully to a request to set environment,
188 # with no variable name.
190 send_gdb "set environment\n"
192 -re "Argument required .environment variable and value..*$gdb_prompt $"\
193 {pass "set environment without variable disallowed"}
195 {fail "set environment without variable disallowed"}
196 timeout {fail "(timeout) set environment without variable disallowed"}
199 # I'm not sure just what GDB has in mind in explicitly checking
200 # for this variant, but since GDB handles it, test it.
202 send_gdb "set environment =\n"
204 -re "Argument required .environment variable to set..*$gdb_prompt $"\
205 {pass "set environment equals without variable disallowed"}
207 {fail "set environment equals without variable disallowed"}
208 timeout {fail "(timeout) set environment equals without variable disallowed"}
211 # Setting an environment variable without a value sets it to a NULL
214 send_gdb "set environment EDITOR\n"
216 -re "Setting environment variable \"EDITOR\" to null value..*$gdb_prompt $"\
217 {pass "issue set environment without variable value"}
219 {fail "issue set environment without variable value"}
220 timeout {fail "(timeout) issue set environment without variable value"}
222 send_gdb "show environment EDITOR\n"
224 -re "EDITOR = \r\n$gdb_prompt $"\
225 {pass "set environment without variable value"}
227 {fail "set environment without variable value"}
228 timeout {fail "(timeout) set environment without variable value"}
231 # Verify that GDB responds gracefully to an attempt to show a
232 # non-existent environment variable. (We hope this variable is
235 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
237 -re "Environment variable \"FOOBARBAZGRUNGESPAZBALL\" not defined..*$gdb_prompt $"\
238 {pass "show non-existent environment variable disallowed"}
240 {fail "show non-existent environment variable disallowed"}
241 timeout {fail "(timeout) show non-existent environment variable disallowed"}
244 # Verify that GDB can set an environment variable hitherto undefined.
246 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t\n"
249 {pass "issue set environment for previously undefined variable"}
250 timeout {fail "(timeout) issue set environment for previously undefined variable"}
252 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
254 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
255 {pass "set environment for previously undefined variable"}
257 {fail "set environment for previously undefined variable"}
258 timeout {fail "(timeout) set environment for previously undefined variable"}
261 # Verify that GDB can also set an environment variable using the "="
264 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = t\n"
267 {pass "issue set environment with equals"}
268 timeout {fail "(timeout) issue set environment with equals"}
270 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
272 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
273 {pass "set environment with equals"}
275 {fail "set environment with equals"}
276 timeout {fail "(timeout) set environment with equals"}
279 # Verify that GDB can set an environment variable to a value that has
280 # an embedded (trailing, in this case) equals.
282 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t=\n"
285 {pass "issue set environment with trailing equals"}
286 timeout {fail "(timeout) issue set environment with trailing equals"}
288 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
290 -re "FOOBARBAZGRUNGESPAZBALL = t=\r\n$gdb_prompt $"\
291 {pass "set environment with trailing equals"}
293 {fail "set environment with trailing equals"}
294 timeout {fail "(timeout) set environment with trailing equals"}
297 # Verify that GDB can set an environment variable to a value preceded
298 # by whitespace, and that such whitespace is ignored (not included
301 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = foo\n"
304 {pass "issue set environment with preceding whitespace"}
305 timeout {fail "(timeout) issue set environment with preceding whitespace"}
307 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
309 -re "FOOBARBAZGRUNGESPAZBALL = foo\r\n$gdb_prompt $"\
310 {pass "set environment with preceding whitespace"}
312 {fail "set environment with preceding whitespace"}
313 timeout {fail "(timeout) set environment with preceding whitespace"}
316 # Verify that GDB can manipulate the distinguished PATH variable.
318 send_gdb "path /tmp/FOOBARBAZGRUNGESPAZBALL\n"
320 -re ".*Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
324 timeout {fail "(timeout) issue path"}
326 send_gdb "show paths\n"
328 -re "Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
332 timeout {fail "(timeout) show paths"}