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