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