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/>. */
23 # test running programs
28 # This test exists solely to exercise the "environment" commands for
29 # code-coverage on HP-UX.
31 if ![istarget "hppa*-*-hpux*"] then {
36 set srcfile ${testfile}.c
37 set srcfile1 ${testfile}1.c
38 set binfile ${objdir}/${subdir}/${testfile}
40 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
45 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
50 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
57 gdb_reinitialize_dir $srcdir/$subdir
60 if ![runto_main] then { fail "environment command tests suppressed" }
62 # (No, this is not really related to the environment commands. But it's
63 # a convenient place to verify that this command works.)
65 send_gdb "info program\n"
67 -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 $"\
71 timeout {fail "(timeout) info program"}
74 # We don't really care where this step lands, so long as it gets
75 # the inferior pushed off the breakpoint it's currently on...
79 -re ".*$gdb_prompt $"\
80 {pass "step before info program"}
81 timeout {fail "(timeout) step before info program"}
83 send_gdb "info program\n"
85 -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 $"\
86 {pass "info program after step"}
88 {fail "info program after step"}
89 timeout {fail "(timeout) info program after step"}
92 if ![runto_main] then { fail "environment command tests suppressed" }
99 -re ".*$gdb_prompt $"\
100 {pass "delete breakpoint before info program"}
101 timeout {fail "(timeout) delete breakpoint before info program"}
105 {fail "delete breakpoint before info program"}
106 timeout {fail "(timeout) delete breakpoint before info program"}
108 send_gdb "info program\n"
110 -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 $"\
111 {pass "info program after deleted breakpoint"}
113 {fail "info program after deleted breakpoint"}
114 timeout {fail "(timeout) info program after deleted breakpoint"}
117 # Verify that we can show all currently-set environment variables.
118 # (It's a bit hacky, but nonetheless probably safe to check for at
119 # least the SHELL variable.)
121 # need to increase timeout because of very long output
122 set oldtimeout $timeout
123 set timeout [expr "$timeout + 300"]
125 send_gdb "show environment\n"
127 -re ".*SHELL=(\[a-zA-Z0-9\]*).*$gdb_prompt $"\
128 {pass "show environment"}
130 {fail "show environment"}
131 timeout {fail "(timeout) show environment"}
133 set timeout $oldtimeout
135 # Verify that we can unset a specific environment variable.
137 send_gdb "unset environment EDITOR\n"
140 {pass "issue unset environment"}
141 timeout {fail "(timeout) issue unset environment"}
143 send_gdb "show environment EDITOR\n"
145 -re "Environment variable \"EDITOR\" not defined.\r\n$gdb_prompt $"\
146 {pass "unset environment"}
148 {fail "unset environment"}
149 timeout {fail "(timeout) unset environment"}
152 # Verify that we can unset all environment variables.
154 send_gdb "unset environment\n"
156 -re "Delete all environment variables.*y or n. $"\
160 {pass "unset entire environment"}
161 timeout {fail "(timeout) unset entire environment"}
165 {fail "unset entire environment"}
166 timeout {fail "(timeout) unset entire environment"}
169 # Verify that we can set a specific environment variable.
171 send_gdb "set environment EDITOR emacs\n"
174 {pass "issue set environment"}
175 timeout {fail "(timeout) issue set environment"}
177 send_gdb "show environment EDITOR\n"
179 -re "EDITOR = emacs\r\n$gdb_prompt $"\
180 {pass "set environment"}
182 {fail "set environment"}
183 timeout {fail "(timeout) set environment"}
186 # Verify that GDB responds gracefully to a request to set environment,
187 # with no variable name.
189 send_gdb "set environment\n"
191 -re "Argument required .environment variable and value..*$gdb_prompt $"\
192 {pass "set environment without variable disallowed"}
194 {fail "set environment without variable disallowed"}
195 timeout {fail "(timeout) set environment without variable disallowed"}
198 # I'm not sure just what GDB has in mind in explicitly checking
199 # for this variant, but since GDB handles it, test it.
201 send_gdb "set environment =\n"
203 -re "Argument required .environment variable to set..*$gdb_prompt $"\
204 {pass "set environment equals without variable disallowed"}
206 {fail "set environment equals without variable disallowed"}
207 timeout {fail "(timeout) set environment equals without variable disallowed"}
210 # Setting an environment variable without a value sets it to a NULL
213 send_gdb "set environment EDITOR\n"
215 -re "Setting environment variable \"EDITOR\" to null value..*$gdb_prompt $"\
216 {pass "issue set environment without variable value"}
218 {fail "issue set environment without variable value"}
219 timeout {fail "(timeout) issue set environment without variable value"}
221 send_gdb "show environment EDITOR\n"
223 -re "EDITOR = \r\n$gdb_prompt $"\
224 {pass "set environment without variable value"}
226 {fail "set environment without variable value"}
227 timeout {fail "(timeout) set environment without variable value"}
230 # Verify that GDB responds gracefully to an attempt to show a
231 # non-existent environment variable. (We hope this variable is
234 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
236 -re "Environment variable \"FOOBARBAZGRUNGESPAZBALL\" not defined..*$gdb_prompt $"\
237 {pass "show non-existent environment variable disallowed"}
239 {fail "show non-existent environment variable disallowed"}
240 timeout {fail "(timeout) show non-existent environment variable disallowed"}
243 # Verify that GDB can set an environment variable hitherto undefined.
245 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t\n"
248 {pass "issue set environment for previously undefined variable"}
249 timeout {fail "(timeout) issue set environment for previously undefined variable"}
251 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
253 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
254 {pass "set environment for previously undefined variable"}
256 {fail "set environment for previously undefined variable"}
257 timeout {fail "(timeout) set environment for previously undefined variable"}
260 # Verify that GDB can also set an environment variable using the "="
263 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = t\n"
266 {pass "issue set environment with equals"}
267 timeout {fail "(timeout) issue set environment with equals"}
269 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
271 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
272 {pass "set environment with equals"}
274 {fail "set environment with equals"}
275 timeout {fail "(timeout) set environment with equals"}
278 # Verify that GDB can set an environment variable to a value that has
279 # an embedded (trailing, in this case) equals.
281 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t=\n"
284 {pass "issue set environment with trailing equals"}
285 timeout {fail "(timeout) issue set environment with trailing equals"}
287 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
289 -re "FOOBARBAZGRUNGESPAZBALL = t=\r\n$gdb_prompt $"\
290 {pass "set environment with trailing equals"}
292 {fail "set environment with trailing equals"}
293 timeout {fail "(timeout) set environment with trailing equals"}
296 # Verify that GDB can set an environment variable to a value preceded
297 # by whitespace, and that such whitespace is ignored (not included
300 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = foo\n"
303 {pass "issue set environment with preceding whitespace"}
304 timeout {fail "(timeout) issue set environment with preceding whitespace"}
306 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
308 -re "FOOBARBAZGRUNGESPAZBALL = foo\r\n$gdb_prompt $"\
309 {pass "set environment with preceding whitespace"}
311 {fail "set environment with preceding whitespace"}
312 timeout {fail "(timeout) set environment with preceding whitespace"}
315 # Verify that GDB can manipulate the distinguished PATH variable.
317 send_gdb "path /tmp/FOOBARBAZGRUNGESPAZBALL\n"
319 -re ".*Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
323 timeout {fail "(timeout) issue path"}
325 send_gdb "show paths\n"
327 -re "Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
331 timeout {fail "(timeout) show paths"}