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