1 # Copyright 1997, 1998, 1999, 2003 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
27 # test running programs
32 # This test exists solely to exercise the "environment" commands for
33 # code-coverage on HP-UX.
35 if ![istarget "hppa*-*-hpux*"] then {
40 set srcfile ${testfile}.c
41 set srcfile1 ${testfile}1.c
42 set binfile ${objdir}/${subdir}/${testfile}
44 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
49 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
54 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
61 gdb_reinitialize_dir $srcdir/$subdir
64 if ![runto_main] then { fail "environment command tests suppressed" }
66 # (No, this is not really related to the environment commands. But it's
67 # a convenient place to verify that this command works.)
69 send_gdb "info program\n"
71 -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 $"\
75 timeout {fail "(timeout) info program"}
78 # We don't really care where this step lands, so long as it gets
79 # the inferior pushed off the breakpoint it's currently on...
83 -re ".*$gdb_prompt $"\
84 {pass "step before info program"}
85 timeout {fail "(timeout) step before info program"}
87 send_gdb "info program\n"
89 -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 $"\
90 {pass "info program after step"}
92 {fail "info program after step"}
93 timeout {fail "(timeout) info program after step"}
96 if ![runto_main] then { fail "environment command tests suppressed" }
103 -re ".*$gdb_prompt $"\
104 {pass "delete breakpoint before info program"}
105 timeout {fail "(timeout) delete breakpoint before info program"}
109 {fail "delete breakpoint before info program"}
110 timeout {fail "(timeout) delete breakpoint before info program"}
112 send_gdb "info program\n"
114 -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 $"\
115 {pass "info program after deleted breakpoint"}
117 {fail "info program after deleted breakpoint"}
118 timeout {fail "(timeout) info program after deleted breakpoint"}
121 # Verify that we can show all currently-set environment variables.
122 # (It's a bit hacky, but nonetheless probably safe to check for at
123 # least the SHELL variable.)
125 # need to increase timeout because of very long output
126 set oldtimeout $timeout
127 set timeout [expr "$timeout + 300"]
129 send_gdb "show environment\n"
131 -re ".*SHELL=(\[a-zA-Z0-9\]*).*$gdb_prompt $"\
132 {pass "show environment"}
134 {fail "show environment"}
135 timeout {fail "(timeout) show environment"}
137 set timeout $oldtimeout
139 # Verify that we can unset a specific environment variable.
141 send_gdb "unset environment EDITOR\n"
144 {pass "issue unset environment"}
145 timeout {fail "(timeout) issue unset environment"}
147 send_gdb "show environment EDITOR\n"
149 -re "Environment variable \"EDITOR\" not defined.\r\n$gdb_prompt $"\
150 {pass "unset environment"}
152 {fail "unset environment"}
153 timeout {fail "(timeout) unset environment"}
156 # Verify that we can unset all environment variables.
158 send_gdb "unset environment\n"
160 -re "Delete all environment variables.*y or n. $"\
164 {pass "unset entire environment"}
165 timeout {fail "(timeout) unset entire environment"}
169 {fail "unset entire environment"}
170 timeout {fail "(timeout) unset entire environment"}
173 # Verify that we can set a specific environment variable.
175 send_gdb "set environment EDITOR emacs\n"
178 {pass "issue set environment"}
179 timeout {fail "(timeout) issue set environment"}
181 send_gdb "show environment EDITOR\n"
183 -re "EDITOR = emacs\r\n$gdb_prompt $"\
184 {pass "set environment"}
186 {fail "set environment"}
187 timeout {fail "(timeout) set environment"}
190 # Verify that GDB responds gracefully to a request to set environment,
191 # with no variable name.
193 send_gdb "set environment\n"
195 -re "Argument required .environment variable and value..*$gdb_prompt $"\
196 {pass "set environment without variable disallowed"}
198 {fail "set environment without variable disallowed"}
199 timeout {fail "(timeout) set environment without variable disallowed"}
202 # I'm not sure just what GDB has in mind in explicitly checking
203 # for this variant, but since GDB handles it, test it.
205 send_gdb "set environment =\n"
207 -re "Argument required .environment variable to set..*$gdb_prompt $"\
208 {pass "set environment equals without variable disallowed"}
210 {fail "set environment equals without variable disallowed"}
211 timeout {fail "(timeout) set environment equals without variable disallowed"}
214 # Setting an environment variable without a value sets it to a NULL
217 send_gdb "set environment EDITOR\n"
219 -re "Setting environment variable \"EDITOR\" to null value..*$gdb_prompt $"\
220 {pass "issue set environment without variable value"}
222 {fail "issue set environment without variable value"}
223 timeout {fail "(timeout) issue set environment without variable value"}
225 send_gdb "show environment EDITOR\n"
227 -re "EDITOR = \r\n$gdb_prompt $"\
228 {pass "set environment without variable value"}
230 {fail "set environment without variable value"}
231 timeout {fail "(timeout) set environment without variable value"}
234 # Verify that GDB responds gracefully to an attempt to show a
235 # non-existent environment variable. (We hope this variable is
238 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
240 -re "Environment variable \"FOOBARBAZGRUNGESPAZBALL\" not defined..*$gdb_prompt $"\
241 {pass "show non-existent environment variable disallowed"}
243 {fail "show non-existent environment variable disallowed"}
244 timeout {fail "(timeout) show non-existent environment variable disallowed"}
247 # Verify that GDB can set an environment variable hitherto undefined.
249 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t\n"
252 {pass "issue set environment for previously undefined variable"}
253 timeout {fail "(timeout) issue set environment for previously undefined variable"}
255 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
257 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
258 {pass "set environment for previously undefined variable"}
260 {fail "set environment for previously undefined variable"}
261 timeout {fail "(timeout) set environment for previously undefined variable"}
264 # Verify that GDB can also set an environment variable using the "="
267 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = t\n"
270 {pass "issue set environment with equals"}
271 timeout {fail "(timeout) issue set environment with equals"}
273 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
275 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
276 {pass "set environment with equals"}
278 {fail "set environment with equals"}
279 timeout {fail "(timeout) set environment with equals"}
282 # Verify that GDB can set an environment variable to a value that has
283 # an embedded (trailing, in this case) equals.
285 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t=\n"
288 {pass "issue set environment with trailing equals"}
289 timeout {fail "(timeout) issue set environment with trailing equals"}
291 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
293 -re "FOOBARBAZGRUNGESPAZBALL = t=\r\n$gdb_prompt $"\
294 {pass "set environment with trailing equals"}
296 {fail "set environment with trailing equals"}
297 timeout {fail "(timeout) set environment with trailing equals"}
300 # Verify that GDB can set an environment variable to a value preceded
301 # by whitespace, and that such whitespace is ignored (not included
304 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = foo\n"
307 {pass "issue set environment with preceding whitespace"}
308 timeout {fail "(timeout) issue set environment with preceding whitespace"}
310 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
312 -re "FOOBARBAZGRUNGESPAZBALL = foo\r\n$gdb_prompt $"\
313 {pass "set environment with preceding whitespace"}
315 {fail "set environment with preceding whitespace"}
316 timeout {fail "(timeout) set environment with preceding whitespace"}
319 # Verify that GDB can manipulate the distinguished PATH variable.
321 send_gdb "path /tmp/FOOBARBAZGRUNGESPAZBALL\n"
323 -re ".*Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
327 timeout {fail "(timeout) issue path"}
329 send_gdb "show paths\n"
331 -re "Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
335 timeout {fail "(timeout) show paths"}