1 # Copyright 1997, 1998, 1999, 2003, 2007, 2008, 2009, 2010, 2011
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/>. */
22 # test running programs
25 # This test exists solely to exercise the "environment" commands for
26 # code-coverage on HP-UX.
28 if ![istarget "hppa*-*-hpux*"] then {
33 set srcfile ${testfile}.c
34 set srcfile1 ${testfile}1.c
35 set binfile ${objdir}/${subdir}/${testfile}
37 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
42 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
47 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
54 gdb_reinitialize_dir $srcdir/$subdir
57 if ![runto_main] then { fail "environment command tests suppressed" }
59 # (No, this is not really related to the environment commands. But it's
60 # a convenient place to verify that this command works.)
62 send_gdb "info program\n"
64 -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 $"\
68 timeout {fail "(timeout) info program"}
71 # We don't really care where this step lands, so long as it gets
72 # the inferior pushed off the breakpoint it's currently on...
76 -re ".*$gdb_prompt $"\
77 {pass "step before info program"}
78 timeout {fail "(timeout) step before info program"}
80 send_gdb "info program\n"
82 -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 $"\
83 {pass "info program after step"}
85 {fail "info program after step"}
86 timeout {fail "(timeout) info program after step"}
89 if ![runto_main] then { fail "environment command tests suppressed" }
96 -re ".*$gdb_prompt $"\
97 {pass "delete breakpoint before info program"}
98 timeout {fail "(timeout) delete breakpoint before info program"}
102 {fail "delete breakpoint before info program"}
103 timeout {fail "(timeout) delete breakpoint before info program"}
105 send_gdb "info program\n"
107 -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 $"\
108 {pass "info program after deleted breakpoint"}
110 {fail "info program after deleted breakpoint"}
111 timeout {fail "(timeout) info program after deleted breakpoint"}
114 # Verify that we can show all currently-set environment variables.
115 # (It's a bit hacky, but nonetheless probably safe to check for at
116 # least the SHELL variable.)
118 # need to increase timeout because of very long output
119 set oldtimeout $timeout
120 set timeout [expr "$timeout + 300"]
122 send_gdb "show environment\n"
124 -re ".*SHELL=(\[a-zA-Z0-9\]*).*$gdb_prompt $"\
125 {pass "show environment"}
127 {fail "show environment"}
128 timeout {fail "(timeout) show environment"}
130 set timeout $oldtimeout
132 # Verify that we can unset a specific environment variable.
134 send_gdb "unset environment EDITOR\n"
137 {pass "issue unset environment"}
138 timeout {fail "(timeout) issue unset environment"}
140 send_gdb "show environment EDITOR\n"
142 -re "Environment variable \"EDITOR\" not defined.\r\n$gdb_prompt $"\
143 {pass "unset environment"}
145 {fail "unset environment"}
146 timeout {fail "(timeout) unset environment"}
149 # Verify that we can unset all environment variables.
151 send_gdb "unset environment\n"
153 -re "Delete all environment variables.*y or n. $"\
157 {pass "unset entire environment"}
158 timeout {fail "(timeout) unset entire environment"}
162 {fail "unset entire environment"}
163 timeout {fail "(timeout) unset entire environment"}
166 # Verify that we can set a specific environment variable.
168 send_gdb "set environment EDITOR emacs\n"
171 {pass "issue set environment"}
172 timeout {fail "(timeout) issue set environment"}
174 send_gdb "show environment EDITOR\n"
176 -re "EDITOR = emacs\r\n$gdb_prompt $"\
177 {pass "set environment"}
179 {fail "set environment"}
180 timeout {fail "(timeout) set environment"}
183 # Verify that GDB responds gracefully to a request to set environment,
184 # with no variable name.
186 send_gdb "set environment\n"
188 -re "Argument required .environment variable and value..*$gdb_prompt $"\
189 {pass "set environment without variable disallowed"}
191 {fail "set environment without variable disallowed"}
192 timeout {fail "(timeout) set environment without variable disallowed"}
195 # I'm not sure just what GDB has in mind in explicitly checking
196 # for this variant, but since GDB handles it, test it.
198 send_gdb "set environment =\n"
200 -re "Argument required .environment variable to set..*$gdb_prompt $"\
201 {pass "set environment equals without variable disallowed"}
203 {fail "set environment equals without variable disallowed"}
204 timeout {fail "(timeout) set environment equals without variable disallowed"}
207 # Setting an environment variable without a value sets it to a NULL
210 send_gdb "set environment EDITOR\n"
212 -re "Setting environment variable \"EDITOR\" to null value..*$gdb_prompt $"\
213 {pass "issue set environment without variable value"}
215 {fail "issue set environment without variable value"}
216 timeout {fail "(timeout) issue set environment without variable value"}
218 send_gdb "show environment EDITOR\n"
220 -re "EDITOR = \r\n$gdb_prompt $"\
221 {pass "set environment without variable value"}
223 {fail "set environment without variable value"}
224 timeout {fail "(timeout) set environment without variable value"}
227 # Verify that GDB responds gracefully to an attempt to show a
228 # non-existent environment variable. (We hope this variable is
231 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
233 -re "Environment variable \"FOOBARBAZGRUNGESPAZBALL\" not defined..*$gdb_prompt $"\
234 {pass "show non-existent environment variable disallowed"}
236 {fail "show non-existent environment variable disallowed"}
237 timeout {fail "(timeout) show non-existent environment variable disallowed"}
240 # Verify that GDB can set an environment variable hitherto undefined.
242 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t\n"
245 {pass "issue set environment for previously undefined variable"}
246 timeout {fail "(timeout) issue set environment for previously undefined variable"}
248 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
250 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
251 {pass "set environment for previously undefined variable"}
253 {fail "set environment for previously undefined variable"}
254 timeout {fail "(timeout) set environment for previously undefined variable"}
257 # Verify that GDB can also set an environment variable using the "="
260 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = t\n"
263 {pass "issue set environment with equals"}
264 timeout {fail "(timeout) issue set environment with equals"}
266 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
268 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
269 {pass "set environment with equals"}
271 {fail "set environment with equals"}
272 timeout {fail "(timeout) set environment with equals"}
275 # Verify that GDB can set an environment variable to a value that has
276 # an embedded (trailing, in this case) equals.
278 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t=\n"
281 {pass "issue set environment with trailing equals"}
282 timeout {fail "(timeout) issue set environment with trailing equals"}
284 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
286 -re "FOOBARBAZGRUNGESPAZBALL = t=\r\n$gdb_prompt $"\
287 {pass "set environment with trailing equals"}
289 {fail "set environment with trailing equals"}
290 timeout {fail "(timeout) set environment with trailing equals"}
293 # Verify that GDB can set an environment variable to a value preceded
294 # by whitespace, and that such whitespace is ignored (not included
297 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = foo\n"
300 {pass "issue set environment with preceding whitespace"}
301 timeout {fail "(timeout) issue set environment with preceding whitespace"}
303 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
305 -re "FOOBARBAZGRUNGESPAZBALL = foo\r\n$gdb_prompt $"\
306 {pass "set environment with preceding whitespace"}
308 {fail "set environment with preceding whitespace"}
309 timeout {fail "(timeout) set environment with preceding whitespace"}
312 # Verify that GDB can manipulate the distinguished PATH variable.
314 send_gdb "path /tmp/FOOBARBAZGRUNGESPAZBALL\n"
316 -re ".*Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
320 timeout {fail "(timeout) issue path"}
322 send_gdb "show paths\n"
324 -re "Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
328 timeout {fail "(timeout) show paths"}