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