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