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