Updated copyright notices for most files.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / environ.exp
CommitLineData
9b254dd1 1# Copyright 1997, 1998, 1999, 2003, 2007, 2008 Free Software Foundation, Inc.
c906108c
SS
2
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
c906108c 6# (at your option) any later version.
e22f8b7c 7#
c906108c
SS
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.
e22f8b7c 12#
c906108c 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>. */
c906108c
SS
15
16# Please email any bugs, comments, and/or additions to this file to:
17# bug-gdb@prep.ai.mit.edu
18
19if $tracelevel then {
20 strace $tracelevel
21 }
22
23global usestubs
24
25#
26# test running programs
27#
28set prms_id 0
29set bug_id 0
30
31# This test exists solely to exercise the "environment" commands for
32# code-coverage on HP-UX.
33#
34if ![istarget "hppa*-*-hpux*"] then {
35 return
36}
37
38set testfile "break"
39set srcfile ${testfile}.c
eb4bbda8 40set srcfile1 ${testfile}1.c
c906108c
SS
41set binfile ${objdir}/${subdir}/${testfile}
42
fc91c6c2 43if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
b60f0898
JB
44 untested environ.exp
45 return -1
eb4bbda8
MC
46}
47
fc91c6c2 48if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
b60f0898
JB
49 untested environ.exp
50 return -1
eb4bbda8 51}
c906108c 52
fc91c6c2 53if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
b60f0898
JB
54 untested environ.exp
55 return -1
c906108c
SS
56}
57
58gdb_exit
59gdb_start
60gdb_reinitialize_dir $srcdir/$subdir
61gdb_load ${binfile}
62
63if ![runto_main] then { fail "environment command tests suppressed" }
64
65# (No, this is not really related to the environment commands. But it's
66# a convenient place to verify that this command works.)
67#
68send_gdb "info program\n"
69gdb_expect {
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 $"\
71 {pass "info program"}
72 -re "$gdb_prompt $"\
73 {fail "info program"}
74 timeout {fail "(timeout) info program"}
75}
76
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...
79#
80send_gdb "next\n"
81gdb_expect {
82 -re ".*$gdb_prompt $"\
83 {pass "step before info program"}
84 timeout {fail "(timeout) step before info program"}
85}
86send_gdb "info program\n"
87gdb_expect {
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"}
90 -re "$gdb_prompt $"\
91 {fail "info program after step"}
92 timeout {fail "(timeout) info program after step"}
93}
94
95if ![runto_main] then { fail "environment command tests suppressed" }
96
97send_gdb "delete\n"
98gdb_expect {
99 -re ".*y or n. $"\
100 {send_gdb "y\n"
101 gdb_expect {
102 -re ".*$gdb_prompt $"\
103 {pass "delete breakpoint before info program"}
104 timeout {fail "(timeout) delete breakpoint before info program"}
105 }
106 }
107 -re "$gdb_prompt $"\
108 {fail "delete breakpoint before info program"}
109 timeout {fail "(timeout) delete breakpoint before info program"}
110}
111send_gdb "info program\n"
112gdb_expect {
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"}
115 -re "$gdb_prompt $"\
116 {fail "info program after deleted breakpoint"}
117 timeout {fail "(timeout) info program after deleted breakpoint"}
118}
119
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.)
123#
124# need to increase timeout because of very long output
125set oldtimeout $timeout
126set timeout [expr "$timeout + 300"]
127
128send_gdb "show environment\n"
129gdb_expect {
130 -re ".*SHELL=(\[a-zA-Z0-9\]*).*$gdb_prompt $"\
131 {pass "show environment"}
132 -re "$gdb_prompt $"\
133 {fail "show environment"}
134 timeout {fail "(timeout) show environment"}
135}
136set timeout $oldtimeout
137
138# Verify that we can unset a specific environment variable.
139#
140send_gdb "unset environment EDITOR\n"
141gdb_expect {
142 -re "$gdb_prompt $"\
143 {pass "issue unset environment"}
144 timeout {fail "(timeout) issue unset environment"}
145}
146send_gdb "show environment EDITOR\n"
147gdb_expect {
148 -re "Environment variable \"EDITOR\" not defined.\r\n$gdb_prompt $"\
149 {pass "unset environment"}
150 -re "$gdb_prompt $"\
151 {fail "unset environment"}
152 timeout {fail "(timeout) unset environment"}
153}
154
155# Verify that we can unset all environment variables.
156#
157send_gdb "unset environment\n"
158gdb_expect {
159 -re "Delete all environment variables.*y or n. $"\
160 {send_gdb "y\n"
161 gdb_expect {
162 -re "$gdb_prompt $"\
163 {pass "unset entire environment"}
164 timeout {fail "(timeout) unset entire environment"}
165 }
166 }
167 -re "$gdb_prompt $"\
168 {fail "unset entire environment"}
169 timeout {fail "(timeout) unset entire environment"}
170}
171
172# Verify that we can set a specific environment variable.
173#
174send_gdb "set environment EDITOR emacs\n"
175gdb_expect {
176 -re "$gdb_prompt $"\
177 {pass "issue set environment"}
178 timeout {fail "(timeout) issue set environment"}
179}
180send_gdb "show environment EDITOR\n"
181gdb_expect {
182 -re "EDITOR = emacs\r\n$gdb_prompt $"\
183 {pass "set environment"}
184 -re "$gdb_prompt $"\
185 {fail "set environment"}
186 timeout {fail "(timeout) set environment"}
187}
188
189# Verify that GDB responds gracefully to a request to set environment,
190# with no variable name.
191#
192send_gdb "set environment\n"
193gdb_expect {
194 -re "Argument required .environment variable and value..*$gdb_prompt $"\
195 {pass "set environment without variable disallowed"}
196 -re "$gdb_prompt $"\
197 {fail "set environment without variable disallowed"}
198 timeout {fail "(timeout) set environment without variable disallowed"}
199}
200
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.
203#
204send_gdb "set environment =\n"
205gdb_expect {
206 -re "Argument required .environment variable to set..*$gdb_prompt $"\
207 {pass "set environment equals without variable disallowed"}
208 -re "$gdb_prompt $"\
209 {fail "set environment equals without variable disallowed"}
210 timeout {fail "(timeout) set environment equals without variable disallowed"}
211}
212
213# Setting an environment variable without a value sets it to a NULL
214# value.
215#
216send_gdb "set environment EDITOR\n"
217gdb_expect {
218 -re "Setting environment variable \"EDITOR\" to null value..*$gdb_prompt $"\
219 {pass "issue set environment without variable value"}
220 -re "$gdb_prompt $"\
221 {fail "issue set environment without variable value"}
222 timeout {fail "(timeout) issue set environment without variable value"}
223}
224send_gdb "show environment EDITOR\n"
225gdb_expect {
226 -re "EDITOR = \r\n$gdb_prompt $"\
227 {pass "set environment without variable value"}
228 -re "$gdb_prompt $"\
229 {fail "set environment without variable value"}
230 timeout {fail "(timeout) set environment without variable value"}
231}
232
233# Verify that GDB responds gracefully to an attempt to show a
234# non-existent environment variable. (We hope this variable is
235# undefined!)
236#
237send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
238gdb_expect {
239 -re "Environment variable \"FOOBARBAZGRUNGESPAZBALL\" not defined..*$gdb_prompt $"\
240 {pass "show non-existent environment variable disallowed"}
241 -re "$gdb_prompt $"\
242 {fail "show non-existent environment variable disallowed"}
243 timeout {fail "(timeout) show non-existent environment variable disallowed"}
244}
245
246# Verify that GDB can set an environment variable hitherto undefined.
247#
248send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t\n"
249gdb_expect {
250 -re "$gdb_prompt $"\
251 {pass "issue set environment for previously undefined variable"}
252 timeout {fail "(timeout) issue set environment for previously undefined variable"}
253}
254send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
255gdb_expect {
256 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
257 {pass "set environment for previously undefined variable"}
258 -re "$gdb_prompt $"\
259 {fail "set environment for previously undefined variable"}
260 timeout {fail "(timeout) set environment for previously undefined variable"}
261}
262
263# Verify that GDB can also set an environment variable using the "="
264# syntax.
265#
266send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = t\n"
267gdb_expect {
268 -re "$gdb_prompt $"\
269 {pass "issue set environment with equals"}
270 timeout {fail "(timeout) issue set environment with equals"}
271}
272send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
273gdb_expect {
274 -re "FOOBARBAZGRUNGESPAZBALL = t\r\n$gdb_prompt $"\
275 {pass "set environment with equals"}
276 -re "$gdb_prompt $"\
277 {fail "set environment with equals"}
278 timeout {fail "(timeout) set environment with equals"}
279}
280
281# Verify that GDB can set an environment variable to a value that has
282# an embedded (trailing, in this case) equals.
283#
284send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t=\n"
285gdb_expect {
286 -re "$gdb_prompt $"\
287 {pass "issue set environment with trailing equals"}
288 timeout {fail "(timeout) issue set environment with trailing equals"}
289}
290send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
291gdb_expect {
292 -re "FOOBARBAZGRUNGESPAZBALL = t=\r\n$gdb_prompt $"\
293 {pass "set environment with trailing equals"}
294 -re "$gdb_prompt $"\
295 {fail "set environment with trailing equals"}
296 timeout {fail "(timeout) set environment with trailing equals"}
297}
298
299# Verify that GDB can set an environment variable to a value preceded
300# by whitespace, and that such whitespace is ignored (not included
301# in the set value).
302#
303send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = foo\n"
304gdb_expect {
305 -re "$gdb_prompt $"\
306 {pass "issue set environment with preceding whitespace"}
307 timeout {fail "(timeout) issue set environment with preceding whitespace"}
308}
309send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
310gdb_expect {
311 -re "FOOBARBAZGRUNGESPAZBALL = foo\r\n$gdb_prompt $"\
312 {pass "set environment with preceding whitespace"}
313 -re "$gdb_prompt $"\
314 {fail "set environment with preceding whitespace"}
315 timeout {fail "(timeout) set environment with preceding whitespace"}
316}
317
318# Verify that GDB can manipulate the distinguished PATH variable.
319#
320send_gdb "path /tmp/FOOBARBAZGRUNGESPAZBALL\n"
321gdb_expect {
322 -re ".*Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
323 {pass "issue path"}
324 -re "$gdb_prompt $"\
325 {fail "issue path"}
326 timeout {fail "(timeout) issue path"}
327}
328send_gdb "show paths\n"
329gdb_expect {
330 -re "Executable and object file path: /tmp/FOOBARBAZGRUNGESPAZBALL.*$gdb_prompt $"\
331 {pass "show paths"}
332 -re "$gdb_prompt $"\
333 {fail "show paths"}
334 timeout {fail "(timeout) show paths"}
335}
336
337gdb_exit
338return 0
This page took 0.891759 seconds and 4 git commands to generate.