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