Updated copyright notices for most files.
[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 # Please email any bugs, comments, and/or additions to this file to:
17 # bug-gdb@prep.ai.mit.edu
18
19 if $tracelevel then {
20 strace $tracelevel
21 }
22
23 global usestubs
24
25 #
26 # test running programs
27 #
28 set prms_id 0
29 set bug_id 0
30
31 # This test exists solely to exercise the "environment" commands for
32 # code-coverage on HP-UX.
33 #
34 if ![istarget "hppa*-*-hpux*"] then {
35 return
36 }
37
38 set testfile "break"
39 set srcfile ${testfile}.c
40 set srcfile1 ${testfile}1.c
41 set binfile ${objdir}/${subdir}/${testfile}
42
43 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
44 untested environ.exp
45 return -1
46 }
47
48 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
49 untested environ.exp
50 return -1
51 }
52
53 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
54 untested environ.exp
55 return -1
56 }
57
58 gdb_exit
59 gdb_start
60 gdb_reinitialize_dir $srcdir/$subdir
61 gdb_load ${binfile}
62
63 if ![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 #
68 send_gdb "info program\n"
69 gdb_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 #
80 send_gdb "next\n"
81 gdb_expect {
82 -re ".*$gdb_prompt $"\
83 {pass "step before info program"}
84 timeout {fail "(timeout) step before info program"}
85 }
86 send_gdb "info program\n"
87 gdb_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
95 if ![runto_main] then { fail "environment command tests suppressed" }
96
97 send_gdb "delete\n"
98 gdb_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 }
111 send_gdb "info program\n"
112 gdb_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
125 set oldtimeout $timeout
126 set timeout [expr "$timeout + 300"]
127
128 send_gdb "show environment\n"
129 gdb_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 }
136 set timeout $oldtimeout
137
138 # Verify that we can unset a specific environment variable.
139 #
140 send_gdb "unset environment EDITOR\n"
141 gdb_expect {
142 -re "$gdb_prompt $"\
143 {pass "issue unset environment"}
144 timeout {fail "(timeout) issue unset environment"}
145 }
146 send_gdb "show environment EDITOR\n"
147 gdb_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 #
157 send_gdb "unset environment\n"
158 gdb_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 #
174 send_gdb "set environment EDITOR emacs\n"
175 gdb_expect {
176 -re "$gdb_prompt $"\
177 {pass "issue set environment"}
178 timeout {fail "(timeout) issue set environment"}
179 }
180 send_gdb "show environment EDITOR\n"
181 gdb_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 #
192 send_gdb "set environment\n"
193 gdb_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 #
204 send_gdb "set environment =\n"
205 gdb_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 #
216 send_gdb "set environment EDITOR\n"
217 gdb_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 }
224 send_gdb "show environment EDITOR\n"
225 gdb_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 #
237 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
238 gdb_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 #
248 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t\n"
249 gdb_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 }
254 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
255 gdb_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 #
266 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = t\n"
267 gdb_expect {
268 -re "$gdb_prompt $"\
269 {pass "issue set environment with equals"}
270 timeout {fail "(timeout) issue set environment with equals"}
271 }
272 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
273 gdb_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 #
284 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t=\n"
285 gdb_expect {
286 -re "$gdb_prompt $"\
287 {pass "issue set environment with trailing equals"}
288 timeout {fail "(timeout) issue set environment with trailing equals"}
289 }
290 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
291 gdb_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 #
303 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = foo\n"
304 gdb_expect {
305 -re "$gdb_prompt $"\
306 {pass "issue set environment with preceding whitespace"}
307 timeout {fail "(timeout) issue set environment with preceding whitespace"}
308 }
309 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
310 gdb_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 #
320 send_gdb "path /tmp/FOOBARBAZGRUNGESPAZBALL\n"
321 gdb_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 }
328 send_gdb "show paths\n"
329 gdb_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
337 gdb_exit
338 return 0
This page took 0.038001 seconds and 5 git commands to generate.