1 # Copyright 1997, 1998, 1999, 2003, 2007, 2008 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/>. */
16 # Please email any bugs, comments, and/or additions to this file to:
17 # bug-gdb@prep.ai.mit.edu
26 # test running programs
31 # This test exists solely to exercise the "environment" commands for
32 # code-coverage on HP-UX.
34 if ![istarget "hppa*-*-hpux*"] then {
39 set srcfile ${testfile}.c
40 set srcfile1 ${testfile}1.c
41 set binfile ${objdir}/${subdir}/${testfile}
43 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
48 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
53 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
60 gdb_reinitialize_dir $srcdir/$subdir
63 if ![runto_main] then { fail "environment command tests suppressed" }
65 # (No, this is not really related to the environment commands. But it's
66 # a convenient place to verify that this command works.)
68 send_gdb "info program\n"
70 -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 $"\
74 timeout {fail "(timeout) info program"}
77 # We don't really care where this step lands, so long as it gets
78 # the inferior pushed off the breakpoint it's currently on...
82 -re ".*$gdb_prompt $"\
83 {pass "step before info program"}
84 timeout {fail "(timeout) step before info program"}
86 send_gdb "info program\n"
88 -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 $"\
89 {pass "info program after step"}
91 {fail "info program after step"}
92 timeout {fail "(timeout) info program after step"}
95 if ![runto_main] then { fail "environment command tests suppressed" }
102 -re ".*$gdb_prompt $"\
103 {pass "delete breakpoint before info program"}
104 timeout {fail "(timeout) delete breakpoint before info program"}
108 {fail "delete breakpoint before info program"}
109 timeout {fail "(timeout) delete breakpoint before info program"}
111 send_gdb "info program\n"
113 -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 $"\
114 {pass "info program after deleted breakpoint"}
116 {fail "info program after deleted breakpoint"}
117 timeout {fail "(timeout) info program after deleted breakpoint"}
120 # Verify that we can show all currently-set environment variables.
121 # (It's a bit hacky, but nonetheless probably safe to check for at
122 # least the SHELL variable.)
124 # need to increase timeout because of very long output
125 set oldtimeout $timeout
126 set timeout [expr "$timeout + 300"]
128 send_gdb "show environment\n"
130 -re ".*SHELL=(\[a-zA-Z0-9\]*).*$gdb_prompt $"\
131 {pass "show environment"}
133 {fail "show environment"}
134 timeout {fail "(timeout) show environment"}
136 set timeout $oldtimeout
138 # Verify that we can unset a specific environment variable.
140 send_gdb "unset environment EDITOR\n"
143 {pass "issue unset environment"}
144 timeout {fail "(timeout) issue unset environment"}
146 send_gdb "show environment EDITOR\n"
148 -re "Environment variable \"EDITOR\" not defined.\r\n$gdb_prompt $"\
149 {pass "unset environment"}
151 {fail "unset environment"}
152 timeout {fail "(timeout) unset environment"}
155 # Verify that we can unset all environment variables.
157 send_gdb "unset environment\n"
159 -re "Delete all environment variables.*y or n. $"\
163 {pass "unset entire environment"}
164 timeout {fail "(timeout) unset entire environment"}
168 {fail "unset entire environment"}
169 timeout {fail "(timeout) unset entire environment"}
172 # Verify that we can set a specific environment variable.
174 send_gdb "set environment EDITOR emacs\n"
177 {pass "issue set environment"}
178 timeout {fail "(timeout) issue set environment"}
180 send_gdb "show environment EDITOR\n"
182 -re "EDITOR = emacs\r\n$gdb_prompt $"\
183 {pass "set environment"}
185 {fail "set environment"}
186 timeout {fail "(timeout) set environment"}
189 # Verify that GDB responds gracefully to a request to set environment,
190 # with no variable name.
192 send_gdb "set environment\n"
194 -re "Argument required .environment variable and value..*$gdb_prompt $"\
195 {pass "set environment without variable disallowed"}
197 {fail "set environment without variable disallowed"}
198 timeout {fail "(timeout) set environment without variable disallowed"}
201 # I'm not sure just what GDB has in mind in explicitly checking
202 # for this variant, but since GDB handles it, test it.
204 send_gdb "set environment =\n"
206 -re "Argument required .environment variable to set..*$gdb_prompt $"\
207 {pass "set environment equals without variable disallowed"}
209 {fail "set environment equals without variable disallowed"}
210 timeout {fail "(timeout) set environment equals without variable disallowed"}
213 # Setting an environment variable without a value sets it to a NULL
216 send_gdb "set environment EDITOR\n"
218 -re "Setting environment variable \"EDITOR\" to null value..*$gdb_prompt $"\
219 {pass "issue set environment without variable value"}
221 {fail "issue set environment without variable value"}
222 timeout {fail "(timeout) issue set environment without variable value"}
224 send_gdb "show environment EDITOR\n"
226 -re "EDITOR = \r\n$gdb_prompt $"\
227 {pass "set environment without variable value"}
229 {fail "set environment without variable value"}
230 timeout {fail "(timeout) set environment without variable value"}
233 # Verify that GDB responds gracefully to an attempt to show a
234 # non-existent environment variable. (We hope this variable is
237 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
239 -re "Environment variable \"FOOBARBAZGRUNGESPAZBALL\" not defined..*$gdb_prompt $"\
240 {pass "show non-existent environment variable disallowed"}
242 {fail "show non-existent environment variable disallowed"}
243 timeout {fail "(timeout) show non-existent environment variable disallowed"}
246 # Verify that GDB can set an environment variable hitherto undefined.
248 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t\n"
251 {pass "issue set environment for previously undefined variable"}
252 timeout {fail "(timeout) issue set environment for previously undefined variable"}
254 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
256 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
257 {pass "set environment for previously undefined variable"}
259 {fail "set environment for previously undefined variable"}
260 timeout {fail "(timeout) set environment for previously undefined variable"}
263 # Verify that GDB can also set an environment variable using the "="
266 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = t\n"
269 {pass "issue set environment with equals"}
270 timeout {fail "(timeout) issue set environment with equals"}
272 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
274 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
275 {pass "set environment with equals"}
277 {fail "set environment with equals"}
278 timeout {fail "(timeout) set environment with equals"}
281 # Verify that GDB can set an environment variable to a value that has
282 # an embedded (trailing, in this case) equals.
284 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t=\n"
287 {pass "issue set environment with trailing equals"}
288 timeout {fail "(timeout) issue set environment with trailing equals"}
290 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
292 -re "FOOBARBAZGRUNGESPAZBALL = t=\r\n$gdb_prompt $"\
293 {pass "set environment with trailing equals"}
295 {fail "set environment with trailing equals"}
296 timeout {fail "(timeout) set environment with trailing equals"}
299 # Verify that GDB can set an environment variable to a value preceded
300 # by whitespace, and that such whitespace is ignored (not included
303 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = foo\n"
306 {pass "issue set environment with preceding whitespace"}
307 timeout {fail "(timeout) issue set environment with preceding whitespace"}
309 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
311 -re "FOOBARBAZGRUNGESPAZBALL = foo\r\n$gdb_prompt $"\
312 {pass "set environment with preceding whitespace"}
314 {fail "set environment with preceding whitespace"}
315 timeout {fail "(timeout) set environment with preceding whitespace"}
318 # Verify that GDB can manipulate the distinguished PATH variable.
320 send_gdb "path /tmp/FOOBARBAZGRUNGESPAZBALL\n"
322 -re ".*Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
326 timeout {fail "(timeout) issue path"}
328 send_gdb "show paths\n"
330 -re "Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
334 timeout {fail "(timeout) show paths"}