2004-06-28 Michael Chastain <mec.gnu@mindspring.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / define.exp
1 # Copyright 1998, 1999, 2001, 2003 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 # This file was written by Elena Zannoni. (ezannoni@cygnus.com)
21
22 if $tracelevel then {
23 strace $tracelevel
24 }
25
26 global usestubs
27
28
29 #
30 # test running programs
31 #
32 set prms_id 0
33 set bug_id 0
34
35 set testfile "break"
36 set srcfile ${testfile}.c
37 set srcfile1 ${testfile}1.c
38 set binfile ${objdir}/${subdir}/${testfile}
39
40 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug additional_flags=-w}] != "" } {
41 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
42 }
43
44 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug additional_flags=-w}] != "" } {
45 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
46 }
47
48 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug additional_flags=-w}] != "" } {
49 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
50 }
51
52 gdb_exit
53 gdb_start
54 gdb_reinitialize_dir $srcdir/$subdir
55 gdb_load ${binfile}
56
57 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
58 set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
59
60 if ![runto_main] then { fail "define tests suppressed" }
61
62 # Verify that GDB allows a user to define their very own commands.
63 #
64 send_gdb "define nextwhere\n"
65 gdb_expect {
66 -re "Type commands for definition of \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$"\
67 {send_gdb "next\nbt\nend\n"
68 gdb_expect {
69 -re "$gdb_prompt $"\
70 {pass "define user command: nextwhere"}
71 timeout {fail "(timeout) define user command: nextwhere"}
72 }
73 }
74 -re "$gdb_prompt $"\
75 {fail "define user command: nextwhere"}
76 timeout {fail "(timeout) define user command: nextwhere"}
77 }
78
79 # Verify that those commands work as gdb_expected.
80 #
81 send_gdb "nextwhere\n"
82 gdb_expect {
83 -re ".*$bp_location1\[ \t\]*printf.*#0\[ \t\]*main.*:$bp_location1.*$gdb_prompt $"\
84 {pass "use user command: nextwhere"}
85 -re "$gdb_prompt $"\
86 {fail "use user command: nextwhere"}
87 timeout {fail "(timeout) use user command: nextwhere"}
88 }
89
90 # Verify that a user can define a command whose spelling is a
91 # proper substring of another user-defined command.
92 #
93 send_gdb "define nextwh\n"
94 gdb_expect {
95 -re "Type commands for definition of \"nextwh\".\r\nEnd with a line saying just \"end\".\r\n>$"\
96 {send_gdb "next 2\nbt\nend\n"
97 gdb_expect {
98 -re "$gdb_prompt $"\
99 {pass "define user command: nextwh"}
100 timeout {fail "(timeout) define user command: nextwh"}
101 }
102 }
103 -re "$gdb_prompt $"\
104 {fail "define user command: nextwh"}
105 timeout {fail "(timeout) define user command: nextwh"}
106 }
107
108 # Verify that a user can redefine their commands. (Test both the
109 # confirmed and unconfirmed cases.)
110 #
111 send_gdb "define nextwhere\n"
112 gdb_expect {
113 -re "Redefine command \"nextwhere\".*y or n. $"\
114 {send_gdb "n\n"
115 gdb_expect {
116 -re "Command \"nextwhere\" not redefined.*$gdb_prompt $"\
117 {pass "redefine user command aborted: nextwhere"}
118 -re "$gdb_prompt $"\
119 {fail "redefine user command aborted: nextwhere"}
120 timeout {fail "(timeout) redefine user command aborted: nextwhere"}
121 }
122 }
123 -re "$gdb_prompt $"\
124 {fail "redefine user command aborted: nextwhere"}
125 timeout {fail "(timeout) redefine user command aborted: nextwhere"}
126 }
127
128 send_gdb "define nextwhere\n"
129 gdb_expect {
130 -re "Redefine command \"nextwhere\".*y or n. $"\
131 {send_gdb "y\n"
132 gdb_expect {
133 -re "Type commands for definition of \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$"\
134 {send_gdb "bt\nnext\nend\n"
135 gdb_expect {
136 -re "$gdb_prompt $"\
137 {pass "redefine user command: nextwhere"}
138 timeout {fail "(timeout) redefine user command: nextwhere"}
139 }
140 }
141 timeout {fail "(timeout) redefine user command: nextwhere"}
142 }
143 }
144 -re "$gdb_prompt $"\
145 {fail "redefine user command: nextwhere"}
146 timeout {fail "(timeout) redefine user command: nextwhere"}
147 }
148
149 # Verify that GDB gracefully handles an attempt to redefine the
150 # help text for a builtin command.
151 #
152 send_gdb "document step\n"
153 gdb_expect {
154 -re "Command \"step\" is built-in..*$gdb_prompt $"\
155 {pass "redocumenting builtin command disallowed"}
156 -re "$gdb_prompt $"\
157 {fail "redocumenting builtin command disallowed"}
158 timeout {fail "(timeout) redocumenting builtin command disallowed"}
159 }
160
161 # Verify that a user can document their own commands. (And redocument
162 # them.)
163 #
164 send_gdb "document nextwhere\n"
165 gdb_expect {
166 -re "Type documentation for \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$"\
167 {send_gdb "A next command that frist shows you where you're stepping from.\nend\n"
168 gdb_expect {
169 -re "$gdb_prompt $"\
170 {pass "document user command: nextwhere"}
171 timeout {fail "(timeout) document user command: nextwhere"}
172 }
173 }
174 -re "$gdb_prompt $"\
175 {fail "document user command: nextwhere"}
176 timeout {fail "(timeout) document user command: nextwhere"}
177 }
178
179 send_gdb "document nextwhere\n"
180 gdb_expect {
181 -re "Type documentation for \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$"\
182 {send_gdb "A next command that first shows you where you're stepping from.\nend\n"
183 gdb_expect {
184 -re "$gdb_prompt $"\
185 {pass "re-document user command: nextwhere"}
186 timeout {fail "(timeout) re-document user command: nextwhere"}
187 }
188 }
189 -re "$gdb_prompt $"\
190 {fail "re-document user command: nextwhere"}
191 timeout {fail "(timeout) re-document user command: nextwhere"}
192 }
193
194 send_gdb "help nextwhere\n"
195 gdb_expect {
196 -re "A next command that first shows you where you're stepping from.\r\n$gdb_prompt $"\
197 {pass "help user command: nextwhere"}
198 -re "$gdb_prompt $"\
199 {fail "help user command: nextwhere"}
200 timeout {fail "(timeout) help user command: nextwhere"}
201 }
202
203 # Verify that the user can "hook" a builtin command. We choose to
204 # hook the "stop" pseudo command, and we'll define it to use a user-
205 # define command.
206 #
207 send_gdb "define user-bt\n"
208 gdb_expect {
209 -re "Type commands for definition of \"user-bt\".\r\nEnd with a line saying just \"end\".\r\n>$"\
210 {send_gdb "bt\nend\n"
211 gdb_expect {
212 -re "$gdb_prompt $"\
213 {pass "define user command: user-bt"}
214 timeout {fail "(timeout) define user command: user-bt"}
215 }
216 }
217 -re "$gdb_prompt $"\
218 {fail "define user command: user-bt"}
219 timeout {fail "(timeout) define user command: user-bt"}
220 }
221
222 send_gdb "define hook-stop\n"
223 gdb_expect {
224 -re "Type commands for definition of \"hook-stop\".\r\nEnd with a line saying just \"end\".\r\n>$"\
225 {send_gdb "user-b\nend\n"
226 gdb_expect {
227 -re "$gdb_prompt $"\
228 {pass "define hook-stop command"}
229 timeout {fail "(timeout) define hook-stop command"}
230 }
231 }
232 -re "$gdb_prompt $"\
233 {fail "define hook-stop command"}
234 timeout {fail "(timeout) define hook-stop command"}
235 }
236
237 send_gdb "next\n"
238 gdb_expect {
239 -re "#0\[ \t\]*main.*:$bp_location11.*$gdb_prompt $"\
240 {pass "use hook-stop command"}
241 -re "$gdb_prompt $"\
242 {fail "use hook-stop command"}
243 timeout {fail "(timeout) use hook-stop command"}
244 }
245
246 # Verify that GDB responds gracefully to an attempt to define a "hook
247 # command" which doesn't exist. (Test both the confirmed and unconfirmed
248 # cases.)
249 #
250 send_gdb "define hook-bar\n"
251 gdb_expect {
252 -re "warning: Your new `hook-bar' command does not hook any existing command.\r\nProceed.*y or n. $"\
253 {send_gdb "n\n"
254 gdb_expect {
255 -re "Not confirmed.*$gdb_prompt $"\
256 {pass "define hook undefined command aborted: bar"}
257 -re "$gdb_prompt $"\
258 {fail "define hook undefined command aborted: bar"}
259 timeout {fail "(timeout) define hook undefined command aborted: bar"}
260 }
261 }
262 -re "$gdb_prompt $"\
263 {fail "define hook undefined command aborted: bar"}
264 timeout {fail "(timeout) define hook undefined command aborted: bar"}
265 }
266
267 send_gdb "define hook-bar\n"
268 gdb_expect {
269 -re "warning: Your new `hook-bar' command does not hook any existing command.\r\nProceed.*y or n. $"\
270 {send_gdb "y\n"
271 gdb_expect {
272 -re "Type commands for definition of \"hook-bar\".\r\nEnd with a line saying just \"end\".\r\n>$"\
273 {send_gdb "nextwhere\nend\n"
274 gdb_expect {
275 -re "$gdb_prompt $"\
276 {pass "define hook undefined command: bar"}
277 timeout {fail "(timeout) define hook undefined command: bar"}
278 }
279 }
280 -re "$gdb_prompt $"\
281 {fail "define hook undefined command: bar"}
282 timeout {fail "(timeout) define hook undefined command: bar"}
283 }
284 }
285 -re "$gdb_prompt $"\
286 {fail "define hook undefined command: bar"}
287 timeout {fail "(timeout) define hook undefined command: bar"}
288 }
289
290 # This is a quasi-define command: Verify that the user can redefine
291 # GDB's gdb_prompt.
292 #
293 send_gdb "set prompt \\(blah\\) \n"
294 gdb_expect {
295 -re "\\(blah\\) $"\
296 {pass "set gdb_prompt"}
297 -re "$gdb_prompt $"\
298 {fail "set gdb_prompt"}
299 timeout {fail "(timeout) set gdb_prompt"}
300 }
301
302 send_gdb "set prompt \\(gdb\\) \n"
303 gdb_expect {
304 -re "$gdb_prompt $"\
305 {pass "reset gdb_prompt"}
306 timeout {fail "(timeout) reset gdb_prompt"}
307 }
308
309 gdb_exit
310 return 0
311
312
313
314
315
316
This page took 0.037137 seconds and 4 git commands to generate.