]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/environ.exp
run copyright.sh for 2011.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / environ.exp
1 # Copyright 1997, 1998, 1999, 2003, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
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
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
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.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17 if $tracelevel then {
18 strace $tracelevel
19 }
20
21 global usestubs
22
23 #
24 # test running programs
25 #
26
27 # This test exists solely to exercise the "environment" commands for
28 # code-coverage on HP-UX.
29 #
30 if ![istarget "hppa*-*-hpux*"] then {
31 return
32 }
33
34 set testfile "break"
35 set srcfile ${testfile}.c
36 set srcfile1 ${testfile}1.c
37 set binfile ${objdir}/${subdir}/${testfile}
38
39 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
40 untested environ.exp
41 return -1
42 }
43
44 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
45 untested environ.exp
46 return -1
47 }
48
49 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
50 untested environ.exp
51 return -1
52 }
53
54 gdb_exit
55 gdb_start
56 gdb_reinitialize_dir $srcdir/$subdir
57 gdb_load ${binfile}
58
59 if ![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 #
64 send_gdb "info program\n"
65 gdb_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 #
76 send_gdb "next\n"
77 gdb_expect {
78 -re ".*$gdb_prompt $"\
79 {pass "step before info program"}
80 timeout {fail "(timeout) step before info program"}
81 }
82 send_gdb "info program\n"
83 gdb_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
91 if ![runto_main] then { fail "environment command tests suppressed" }
92
93 send_gdb "delete\n"
94 gdb_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 }
107 send_gdb "info program\n"
108 gdb_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
121 set oldtimeout $timeout
122 set timeout [expr "$timeout + 300"]
123
124 send_gdb "show environment\n"
125 gdb_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 }
132 set timeout $oldtimeout
133
134 # Verify that we can unset a specific environment variable.
135 #
136 send_gdb "unset environment EDITOR\n"
137 gdb_expect {
138 -re "$gdb_prompt $"\
139 {pass "issue unset environment"}
140 timeout {fail "(timeout) issue unset environment"}
141 }
142 send_gdb "show environment EDITOR\n"
143 gdb_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 #
153 send_gdb "unset environment\n"
154 gdb_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 #
170 send_gdb "set environment EDITOR emacs\n"
171 gdb_expect {
172 -re "$gdb_prompt $"\
173 {pass "issue set environment"}
174 timeout {fail "(timeout) issue set environment"}
175 }
176 send_gdb "show environment EDITOR\n"
177 gdb_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 #
188 send_gdb "set environment\n"
189 gdb_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 #
200 send_gdb "set environment =\n"
201 gdb_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 #
212 send_gdb "set environment EDITOR\n"
213 gdb_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 }
220 send_gdb "show environment EDITOR\n"
221 gdb_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 #
233 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
234 gdb_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 #
244 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t\n"
245 gdb_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 }
250 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
251 gdb_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 #
262 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = t\n"
263 gdb_expect {
264 -re "$gdb_prompt $"\
265 {pass "issue set environment with equals"}
266 timeout {fail "(timeout) issue set environment with equals"}
267 }
268 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
269 gdb_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 #
280 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL t=\n"
281 gdb_expect {
282 -re "$gdb_prompt $"\
283 {pass "issue set environment with trailing equals"}
284 timeout {fail "(timeout) issue set environment with trailing equals"}
285 }
286 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
287 gdb_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 #
299 send_gdb "set environment FOOBARBAZGRUNGESPAZBALL = foo\n"
300 gdb_expect {
301 -re "$gdb_prompt $"\
302 {pass "issue set environment with preceding whitespace"}
303 timeout {fail "(timeout) issue set environment with preceding whitespace"}
304 }
305 send_gdb "show environment FOOBARBAZGRUNGESPAZBALL\n"
306 gdb_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 #
316 send_gdb "path /tmp/FOOBARBAZGRUNGESPAZBALL\n"
317 gdb_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 }
324 send_gdb "show paths\n"
325 gdb_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
333 gdb_exit
334 return 0