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