Fix for PR gdb/1543.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / environ.exp
1 # Copyright 1997, 1998, 1999, 2003, 2007, 2008 Free Software Foundation, Inc.
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 3 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, see <http://www.gnu.org/licenses/>. */
15
16 if $tracelevel then {
17 strace $tracelevel
18 }
19
20 global usestubs
21
22 #
23 # test running programs
24 #
25 set prms_id 0
26 set bug_id 0
27
28 # This test exists solely to exercise the "environment" commands for
29 # code-coverage on HP-UX.
30 #
31 if ![istarget "hppa*-*-hpux*"] then {
32 return
33 }
34
35 set testfile "break"
36 set srcfile ${testfile}.c
37 set srcfile1 ${testfile}1.c
38 set binfile ${objdir}/${subdir}/${testfile}
39
40 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
41 untested environ.exp
42 return -1
43 }
44
45 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
46 untested environ.exp
47 return -1
48 }
49
50 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
51 untested environ.exp
52 return -1
53 }
54
55 gdb_exit
56 gdb_start
57 gdb_reinitialize_dir $srcdir/$subdir
58 gdb_load ${binfile}
59
60 if ![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 #
65 send_gdb "info program\n"
66 gdb_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 #
77 send_gdb "next\n"
78 gdb_expect {
79 -re ".*$gdb_prompt $"\
80 {pass "step before info program"}
81 timeout {fail "(timeout) step before info program"}
82 }
83 send_gdb "info program\n"
84 gdb_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
92 if ![runto_main] then { fail "environment command tests suppressed" }
93
94 send_gdb "delete\n"
95 gdb_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 }
108 send_gdb "info program\n"
109 gdb_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
122 set oldtimeout $timeout
123 set timeout [expr "$timeout + 300"]
124
125 send_gdb "show environment\n"
126 gdb_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 }
133 set timeout $oldtimeout
134
135 # Verify that we can unset a specific environment variable.
136 #
137 send_gdb "unset environment EDITOR\n"
138 gdb_expect {
139 -re "$gdb_prompt $"\
140 {pass "issue unset environment"}
141 timeout {fail "(timeout) issue unset environment"}
142 }
143 send_gdb "show environment EDITOR\n"
144 gdb_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 #
154 send_gdb "unset environment\n"
155 gdb_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 #
171 send_gdb "set environment EDITOR emacs\n"
172 gdb_expect {
173 -re "$gdb_prompt $"\
174 {pass "issue set environment"}
175 timeout {fail "(timeout) issue set environment"}
176 }
177 send_gdb "show environment EDITOR\n"
178 gdb_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 #
189 send_gdb "set environment\n"
190 gdb_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 #
201 send_gdb "set environment =\n"
202 gdb_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 #
213 send_gdb "set environment EDITOR\n"
214 gdb_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 }
221 send_gdb "show environment EDITOR\n"
222 gdb_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 #
234 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
235 gdb_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 #
245 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t\n"
246 gdb_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 }
251 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
252 gdb_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 #
263 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = t\n"
264 gdb_expect {
265 -re "$gdb_prompt $"\
266 {pass "issue set environment with equals"}
267 timeout {fail "(timeout) issue set environment with equals"}
268 }
269 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
270 gdb_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 #
281 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t=\n"
282 gdb_expect {
283 -re "$gdb_prompt $"\
284 {pass "issue set environment with trailing equals"}
285 timeout {fail "(timeout) issue set environment with trailing equals"}
286 }
287 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
288 gdb_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 #
300 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = foo\n"
301 gdb_expect {
302 -re "$gdb_prompt $"\
303 {pass "issue set environment with preceding whitespace"}
304 timeout {fail "(timeout) issue set environment with preceding whitespace"}
305 }
306 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
307 gdb_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 #
317 send_gdb "path /tmp/FOOBARBAZGRUNGESPAZBALL\n"
318 gdb_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 }
325 send_gdb "show paths\n"
326 gdb_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
334 gdb_exit
335 return 0
This page took 0.037861 seconds and 4 git commands to generate.