1 # Copyright 1997-1999, 2003, 2007-2012 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/>. */
17 # test running programs
20 # This test exists solely to exercise the "environment" commands for
21 # code-coverage on HP-UX.
23 if ![istarget "hppa*-*-hpux*"] then {
28 set srcfile ${testfile}.c
29 set srcfile1 ${testfile}1.c
30 set binfile ${objdir}/${subdir}/${testfile}
32 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
37 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
42 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
49 gdb_reinitialize_dir $srcdir/$subdir
52 if ![runto_main] then { fail "environment command tests suppressed" }
54 # (No, this is not really related to the environment commands. But it's
55 # a convenient place to verify that this command works.)
57 send_gdb "info program\n"
59 -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 $"\
63 timeout {fail "(timeout) info program"}
66 # We don't really care where this step lands, so long as it gets
67 # the inferior pushed off the breakpoint it's currently on...
71 -re ".*$gdb_prompt $"\
72 {pass "step before info program"}
73 timeout {fail "(timeout) step before info program"}
75 send_gdb "info program\n"
77 -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 $"\
78 {pass "info program after step"}
80 {fail "info program after step"}
81 timeout {fail "(timeout) info program after step"}
84 if ![runto_main] then { fail "environment command tests suppressed" }
91 -re ".*$gdb_prompt $"\
92 {pass "delete breakpoint before info program"}
93 timeout {fail "(timeout) delete breakpoint before info program"}
97 {fail "delete breakpoint before info program"}
98 timeout {fail "(timeout) delete breakpoint before info program"}
100 send_gdb "info program\n"
102 -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 $"\
103 {pass "info program after deleted breakpoint"}
105 {fail "info program after deleted breakpoint"}
106 timeout {fail "(timeout) info program after deleted breakpoint"}
109 # Verify that we can show all currently-set environment variables.
110 # (It's a bit hacky, but nonetheless probably safe to check for at
111 # least the SHELL variable.)
113 # need to increase timeout because of very long output
114 set oldtimeout $timeout
115 set timeout [expr "$timeout + 300"]
117 send_gdb "show environment\n"
119 -re ".*SHELL=(\[a-zA-Z0-9\]*).*$gdb_prompt $"\
120 {pass "show environment"}
122 {fail "show environment"}
123 timeout {fail "(timeout) show environment"}
125 set timeout $oldtimeout
127 # Verify that we can unset a specific environment variable.
129 send_gdb "unset environment EDITOR\n"
132 {pass "issue unset environment"}
133 timeout {fail "(timeout) issue unset environment"}
135 send_gdb "show environment EDITOR\n"
137 -re "Environment variable \"EDITOR\" not defined.\r\n$gdb_prompt $"\
138 {pass "unset environment"}
140 {fail "unset environment"}
141 timeout {fail "(timeout) unset environment"}
144 # Verify that we can unset all environment variables.
146 send_gdb "unset environment\n"
148 -re "Delete all environment variables.*y or n. $"\
152 {pass "unset entire environment"}
153 timeout {fail "(timeout) unset entire environment"}
157 {fail "unset entire environment"}
158 timeout {fail "(timeout) unset entire environment"}
161 # Verify that we can set a specific environment variable.
163 send_gdb "set environment EDITOR emacs\n"
166 {pass "issue set environment"}
167 timeout {fail "(timeout) issue set environment"}
169 send_gdb "show environment EDITOR\n"
171 -re "EDITOR = emacs\r\n$gdb_prompt $"\
172 {pass "set environment"}
174 {fail "set environment"}
175 timeout {fail "(timeout) set environment"}
178 # Verify that GDB responds gracefully to a request to set environment,
179 # with no variable name.
181 send_gdb "set environment\n"
183 -re "Argument required .environment variable and value..*$gdb_prompt $"\
184 {pass "set environment without variable disallowed"}
186 {fail "set environment without variable disallowed"}
187 timeout {fail "(timeout) set environment without variable disallowed"}
190 # I'm not sure just what GDB has in mind in explicitly checking
191 # for this variant, but since GDB handles it, test it.
193 send_gdb "set environment =\n"
195 -re "Argument required .environment variable to set..*$gdb_prompt $"\
196 {pass "set environment equals without variable disallowed"}
198 {fail "set environment equals without variable disallowed"}
199 timeout {fail "(timeout) set environment equals without variable disallowed"}
202 # Setting an environment variable without a value sets it to a NULL
205 send_gdb "set environment EDITOR\n"
207 -re "Setting environment variable \"EDITOR\" to null value..*$gdb_prompt $"\
208 {pass "issue set environment without variable value"}
210 {fail "issue set environment without variable value"}
211 timeout {fail "(timeout) issue set environment without variable value"}
213 send_gdb "show environment EDITOR\n"
215 -re "EDITOR = \r\n$gdb_prompt $"\
216 {pass "set environment without variable value"}
218 {fail "set environment without variable value"}
219 timeout {fail "(timeout) set environment without variable value"}
222 # Verify that GDB responds gracefully to an attempt to show a
223 # non-existent environment variable. (We hope this variable is
226 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
228 -re "Environment variable \"FOOBARBAZGRUNGESPAZBALL\" not defined..*$gdb_prompt $"\
229 {pass "show non-existent environment variable disallowed"}
231 {fail "show non-existent environment variable disallowed"}
232 timeout {fail "(timeout) show non-existent environment variable disallowed"}
235 # Verify that GDB can set an environment variable hitherto undefined.
237 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t\n"
240 {pass "issue set environment for previously undefined variable"}
241 timeout {fail "(timeout) issue set environment for previously undefined variable"}
243 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
245 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
246 {pass "set environment for previously undefined variable"}
248 {fail "set environment for previously undefined variable"}
249 timeout {fail "(timeout) set environment for previously undefined variable"}
252 # Verify that GDB can also set an environment variable using the "="
255 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = t\n"
258 {pass "issue set environment with equals"}
259 timeout {fail "(timeout) issue set environment with equals"}
261 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
263 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
264 {pass "set environment with equals"}
266 {fail "set environment with equals"}
267 timeout {fail "(timeout) set environment with equals"}
270 # Verify that GDB can set an environment variable to a value that has
271 # an embedded (trailing, in this case) equals.
273 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t=\n"
276 {pass "issue set environment with trailing equals"}
277 timeout {fail "(timeout) issue set environment with trailing equals"}
279 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
281 -re "FOOBARBAZGRUNGESPAZBALL = t=\r\n$gdb_prompt $"\
282 {pass "set environment with trailing equals"}
284 {fail "set environment with trailing equals"}
285 timeout {fail "(timeout) set environment with trailing equals"}
288 # Verify that GDB can set an environment variable to a value preceded
289 # by whitespace, and that such whitespace is ignored (not included
292 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = foo\n"
295 {pass "issue set environment with preceding whitespace"}
296 timeout {fail "(timeout) issue set environment with preceding whitespace"}
298 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
300 -re "FOOBARBAZGRUNGESPAZBALL = foo\r\n$gdb_prompt $"\
301 {pass "set environment with preceding whitespace"}
303 {fail "set environment with preceding whitespace"}
304 timeout {fail "(timeout) set environment with preceding whitespace"}
307 # Verify that GDB can manipulate the distinguished PATH variable.
309 send_gdb "path /tmp/FOOBARBAZGRUNGESPAZBALL\n"
311 -re ".*Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
315 timeout {fail "(timeout) issue path"}
317 send_gdb "show paths\n"
319 -re "Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
323 timeout {fail "(timeout) show paths"}