]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/define.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / define.exp
CommitLineData
6aba47ca 1# Copyright 1998, 1999, 2001, 2003, 2004, 2007 Free Software Foundation, Inc.
c906108c
SS
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
a1dea79a 15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
c906108c
SS
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
22if $tracelevel then {
23 strace $tracelevel
24 }
25
26global usestubs
27
28
29#
30# test running programs
31#
32set prms_id 0
33set bug_id 0
34
35set testfile "break"
36set srcfile ${testfile}.c
a1dea79a 37set srcfile1 ${testfile}1.c
c906108c
SS
38set binfile ${objdir}/${subdir}/${testfile}
39
fc91c6c2 40if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
b60f0898
JB
41 untested define.exp
42 return -1
a1dea79a
FF
43}
44
fc91c6c2 45if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
b60f0898
JB
46 untested define.exp
47 return -1
a1dea79a
FF
48}
49
fc91c6c2 50if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
b60f0898
JB
51 untested define.exp
52 return -1
c906108c
SS
53}
54
55gdb_exit
56gdb_start
57gdb_reinitialize_dir $srcdir/$subdir
58gdb_load ${binfile}
59
a1dea79a
FF
60set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
61set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
62
c906108c
SS
63if ![runto_main] then { fail "define tests suppressed" }
64
65# Verify that GDB allows a user to define their very own commands.
66#
67send_gdb "define nextwhere\n"
68gdb_expect {
69 -re "Type commands for definition of \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$"\
70 {send_gdb "next\nbt\nend\n"
71 gdb_expect {
72 -re "$gdb_prompt $"\
73 {pass "define user command: nextwhere"}
74 timeout {fail "(timeout) define user command: nextwhere"}
75 }
76 }
77 -re "$gdb_prompt $"\
78 {fail "define user command: nextwhere"}
79 timeout {fail "(timeout) define user command: nextwhere"}
80}
81
82# Verify that those commands work as gdb_expected.
83#
84send_gdb "nextwhere\n"
85gdb_expect {
a1dea79a 86 -re ".*$bp_location1\[ \t\]*printf.*#0\[ \t\]*main.*:$bp_location1.*$gdb_prompt $"\
c906108c
SS
87 {pass "use user command: nextwhere"}
88 -re "$gdb_prompt $"\
89 {fail "use user command: nextwhere"}
90 timeout {fail "(timeout) use user command: nextwhere"}
91}
92
93# Verify that a user can define a command whose spelling is a
94# proper substring of another user-defined command.
95#
96send_gdb "define nextwh\n"
97gdb_expect {
98 -re "Type commands for definition of \"nextwh\".\r\nEnd with a line saying just \"end\".\r\n>$"\
99 {send_gdb "next 2\nbt\nend\n"
100 gdb_expect {
101 -re "$gdb_prompt $"\
102 {pass "define user command: nextwh"}
103 timeout {fail "(timeout) define user command: nextwh"}
104 }
105 }
106 -re "$gdb_prompt $"\
107 {fail "define user command: nextwh"}
108 timeout {fail "(timeout) define user command: nextwh"}
109}
110
111# Verify that a user can redefine their commands. (Test both the
112# confirmed and unconfirmed cases.)
113#
114send_gdb "define nextwhere\n"
115gdb_expect {
116 -re "Redefine command \"nextwhere\".*y or n. $"\
117 {send_gdb "n\n"
118 gdb_expect {
119 -re "Command \"nextwhere\" not redefined.*$gdb_prompt $"\
120 {pass "redefine user command aborted: nextwhere"}
121 -re "$gdb_prompt $"\
122 {fail "redefine user command aborted: nextwhere"}
123 timeout {fail "(timeout) redefine user command aborted: nextwhere"}
124 }
125 }
126 -re "$gdb_prompt $"\
127 {fail "redefine user command aborted: nextwhere"}
128 timeout {fail "(timeout) redefine user command aborted: nextwhere"}
129}
130
131send_gdb "define nextwhere\n"
132gdb_expect {
133 -re "Redefine command \"nextwhere\".*y or n. $"\
134 {send_gdb "y\n"
135 gdb_expect {
136 -re "Type commands for definition of \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$"\
137 {send_gdb "bt\nnext\nend\n"
138 gdb_expect {
139 -re "$gdb_prompt $"\
140 {pass "redefine user command: nextwhere"}
141 timeout {fail "(timeout) redefine user command: nextwhere"}
142 }
143 }
144 timeout {fail "(timeout) redefine user command: nextwhere"}
145 }
146 }
147 -re "$gdb_prompt $"\
148 {fail "redefine user command: nextwhere"}
149 timeout {fail "(timeout) redefine user command: nextwhere"}
150}
151
152# Verify that GDB gracefully handles an attempt to redefine the
153# help text for a builtin command.
154#
155send_gdb "document step\n"
156gdb_expect {
157 -re "Command \"step\" is built-in..*$gdb_prompt $"\
158 {pass "redocumenting builtin command disallowed"}
159 -re "$gdb_prompt $"\
160 {fail "redocumenting builtin command disallowed"}
161 timeout {fail "(timeout) redocumenting builtin command disallowed"}
162}
163
164# Verify that a user can document their own commands. (And redocument
165# them.)
166#
167send_gdb "document nextwhere\n"
168gdb_expect {
169 -re "Type documentation for \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$"\
170 {send_gdb "A next command that frist shows you where you're stepping from.\nend\n"
171 gdb_expect {
172 -re "$gdb_prompt $"\
173 {pass "document user command: nextwhere"}
174 timeout {fail "(timeout) document user command: nextwhere"}
175 }
176 }
177 -re "$gdb_prompt $"\
7dbd117d
MC
178 {fail "document user command: nextwhere"}
179 timeout {fail "(timeout) document user command: nextwhere"}
c906108c
SS
180}
181
182send_gdb "document nextwhere\n"
183gdb_expect {
184 -re "Type documentation for \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$"\
185 {send_gdb "A next command that first shows you where you're stepping from.\nend\n"
186 gdb_expect {
187 -re "$gdb_prompt $"\
7dbd117d
MC
188 {pass "re-document user command: nextwhere"}
189 timeout {fail "(timeout) re-document user command: nextwhere"}
c906108c
SS
190 }
191 }
192 -re "$gdb_prompt $"\
7dbd117d
MC
193 {fail "re-document user command: nextwhere"}
194 timeout {fail "(timeout) re-document user command: nextwhere"}
c906108c
SS
195}
196
197send_gdb "help nextwhere\n"
198gdb_expect {
199 -re "A next command that first shows you where you're stepping from.\r\n$gdb_prompt $"\
200 {pass "help user command: nextwhere"}
201 -re "$gdb_prompt $"\
202 {fail "help user command: nextwhere"}
203 timeout {fail "(timeout) help user command: nextwhere"}
204}
205
33f2d567
JM
206# Verify that the command parser doesn't require a space after an 'if'
207# command in a user defined function.
208#
209gdb_test_multiple "define ifnospace" "define user command: ifnospace" \
210{
211 -re "Type commands for definition of \"ifnospace\".\r\nEnd with a line saying just \"end\".\r\n>$" \
212 {
213 gdb_test_multiple "if(3<4)\nprint \"hi there\\n\"\nend\nend" "send body of ifnospace" \
214 {
215 -re "$gdb_prompt $"\
216 {pass "define user command: ifnospace"}
217 }
218 }
219}
220
221gdb_test "ifnospace" ".*hi there.*" "test ifnospace is parsed correctly"
222
223# Verify that the command parser doesn't require a space after an 'while'
224# command in a user defined function.
225#
226gdb_test_multiple "define whilenospace" "define user command: whilenospace" \
227{
228 -re "Type commands for definition of \"whilenospace\".\r\nEnd with a line saying just \"end\".\r\n>$" \
229 {
230 gdb_test_multiple "set \$i=1\nwhile(\$i<2)\nset \$i=2\nprint \"hi there\\n\"\nend\nend" "send body of whilenospace" \
231 {
232 -re "$gdb_prompt $" \
233 {pass "define user command: whilenospace"}
234 }
235 }
236}
237
238gdb_test "whilenospace" ".*hi there.*" "test whilenospace is parsed correctly"
239
c906108c
SS
240# Verify that the user can "hook" a builtin command. We choose to
241# hook the "stop" pseudo command, and we'll define it to use a user-
242# define command.
243#
244send_gdb "define user-bt\n"
245gdb_expect {
246 -re "Type commands for definition of \"user-bt\".\r\nEnd with a line saying just \"end\".\r\n>$"\
247 {send_gdb "bt\nend\n"
248 gdb_expect {
249 -re "$gdb_prompt $"\
250 {pass "define user command: user-bt"}
251 timeout {fail "(timeout) define user command: user-bt"}
252 }
253 }
254 -re "$gdb_prompt $"\
255 {fail "define user command: user-bt"}
256 timeout {fail "(timeout) define user command: user-bt"}
257}
258
259send_gdb "define hook-stop\n"
260gdb_expect {
261 -re "Type commands for definition of \"hook-stop\".\r\nEnd with a line saying just \"end\".\r\n>$"\
262 {send_gdb "user-b\nend\n"
263 gdb_expect {
264 -re "$gdb_prompt $"\
265 {pass "define hook-stop command"}
266 timeout {fail "(timeout) define hook-stop command"}
267 }
268 }
269 -re "$gdb_prompt $"\
270 {fail "define hook-stop command"}
271 timeout {fail "(timeout) define hook-stop command"}
272}
273
274send_gdb "next\n"
275gdb_expect {
a1dea79a 276 -re "#0\[ \t\]*main.*:$bp_location11.*$gdb_prompt $"\
c906108c
SS
277 {pass "use hook-stop command"}
278 -re "$gdb_prompt $"\
279 {fail "use hook-stop command"}
280 timeout {fail "(timeout) use hook-stop command"}
281}
282
283# Verify that GDB responds gracefully to an attempt to define a "hook
284# command" which doesn't exist. (Test both the confirmed and unconfirmed
285# cases.)
286#
287send_gdb "define hook-bar\n"
288gdb_expect {
289 -re "warning: Your new `hook-bar' command does not hook any existing command.\r\nProceed.*y or n. $"\
290 {send_gdb "n\n"
291 gdb_expect {
292 -re "Not confirmed.*$gdb_prompt $"\
293 {pass "define hook undefined command aborted: bar"}
294 -re "$gdb_prompt $"\
295 {fail "define hook undefined command aborted: bar"}
296 timeout {fail "(timeout) define hook undefined command aborted: bar"}
297 }
298 }
299 -re "$gdb_prompt $"\
300 {fail "define hook undefined command aborted: bar"}
301 timeout {fail "(timeout) define hook undefined command aborted: bar"}
302}
303
304send_gdb "define hook-bar\n"
305gdb_expect {
306 -re "warning: Your new `hook-bar' command does not hook any existing command.\r\nProceed.*y or n. $"\
307 {send_gdb "y\n"
308 gdb_expect {
309 -re "Type commands for definition of \"hook-bar\".\r\nEnd with a line saying just \"end\".\r\n>$"\
310 {send_gdb "nextwhere\nend\n"
311 gdb_expect {
312 -re "$gdb_prompt $"\
313 {pass "define hook undefined command: bar"}
314 timeout {fail "(timeout) define hook undefined command: bar"}
315 }
316 }
317 -re "$gdb_prompt $"\
318 {fail "define hook undefined command: bar"}
319 timeout {fail "(timeout) define hook undefined command: bar"}
320 }
321 }
322 -re "$gdb_prompt $"\
323 {fail "define hook undefined command: bar"}
324 timeout {fail "(timeout) define hook undefined command: bar"}
325}
326
327# This is a quasi-define command: Verify that the user can redefine
328# GDB's gdb_prompt.
329#
330send_gdb "set prompt \\(blah\\) \n"
331gdb_expect {
332 -re "\\(blah\\) $"\
333 {pass "set gdb_prompt"}
334 -re "$gdb_prompt $"\
335 {fail "set gdb_prompt"}
336 timeout {fail "(timeout) set gdb_prompt"}
337}
338
339send_gdb "set prompt \\(gdb\\) \n"
340gdb_expect {
341 -re "$gdb_prompt $"\
342 {pass "reset gdb_prompt"}
343 timeout {fail "(timeout) reset gdb_prompt"}
344}
345
346gdb_exit
347return 0
348
349
350
351
352
353