* gdb.base/call-signal-resume.exp, gdb.base/unwindonsignal.exp: Skip
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / define.exp
CommitLineData
4c38e0a4 1# Copyright 1998, 1999, 2001, 2003, 2004, 2007, 2008, 2009, 2010
9b254dd1 2# Free Software Foundation, Inc.
c906108c
SS
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
c906108c 7# (at your option) any later version.
e22f8b7c 8#
c906108c
SS
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.
e22f8b7c 13#
c906108c 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 16
c906108c
SS
17# This file was written by Elena Zannoni. (ezannoni@cygnus.com)
18
19if $tracelevel then {
20 strace $tracelevel
21 }
22
23global usestubs
24
25
26#
27# test running programs
28#
29set prms_id 0
30set bug_id 0
31
32set testfile "break"
33set srcfile ${testfile}.c
a1dea79a 34set srcfile1 ${testfile}1.c
c906108c
SS
35set binfile ${objdir}/${subdir}/${testfile}
36
fc91c6c2 37if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
b60f0898
JB
38 untested define.exp
39 return -1
a1dea79a
FF
40}
41
fc91c6c2 42if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
b60f0898
JB
43 untested define.exp
44 return -1
a1dea79a
FF
45}
46
fc91c6c2 47if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
b60f0898
JB
48 untested define.exp
49 return -1
c906108c
SS
50}
51
52gdb_exit
53gdb_start
54gdb_reinitialize_dir $srcdir/$subdir
55gdb_load ${binfile}
56
a1dea79a
FF
57set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
58set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
59
c906108c
SS
60if ![runto_main] then { fail "define tests suppressed" }
61
62# Verify that GDB allows a user to define their very own commands.
63#
64send_gdb "define nextwhere\n"
65gdb_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#
81send_gdb "nextwhere\n"
82gdb_expect {
a1dea79a 83 -re ".*$bp_location1\[ \t\]*printf.*#0\[ \t\]*main.*:$bp_location1.*$gdb_prompt $"\
c906108c
SS
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#
93send_gdb "define nextwh\n"
94gdb_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#
111send_gdb "define nextwhere\n"
112gdb_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
128send_gdb "define nextwhere\n"
129gdb_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#
152send_gdb "document step\n"
153gdb_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#
164send_gdb "document nextwhere\n"
165gdb_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 $"\
7dbd117d
MC
175 {fail "document user command: nextwhere"}
176 timeout {fail "(timeout) document user command: nextwhere"}
c906108c
SS
177}
178
179send_gdb "document nextwhere\n"
180gdb_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 $"\
7dbd117d
MC
185 {pass "re-document user command: nextwhere"}
186 timeout {fail "(timeout) re-document user command: nextwhere"}
c906108c
SS
187 }
188 }
189 -re "$gdb_prompt $"\
7dbd117d
MC
190 {fail "re-document user command: nextwhere"}
191 timeout {fail "(timeout) re-document user command: nextwhere"}
c906108c
SS
192}
193
194send_gdb "help nextwhere\n"
195gdb_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
311a4e6b
TJB
203# Verify that the document command preserves whitespace in the beginning of the line.
204#
205send_gdb "document nextwhere\n"
206gdb_expect {
207 -re "Type documentation for \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$"\
208 {send_gdb " A next command that first shows you where you're stepping from.\nend\n"
209 gdb_expect {
210 -re "$gdb_prompt $" {}
211 timeout {fail "(timeout) preserve whitespace in help string"}
212 }
213 }
214 -re "$gdb_prompt $"\
215 {fail "preserve whitespace in help string"}
216 timeout {fail "(timeout) preserve whitespace in help string"}
217}
218
219send_gdb "help nextwhere\n"
220gdb_expect {
221 -re " A next command that first shows you where you're stepping from.\r\n$gdb_prompt $"\
222 {pass "preserve whitespace in help string"}
223 -re "$gdb_prompt $"\
224 {fail "preserve whitespace in help string"}
225 timeout {fail "(timeout) preserve whitespace in help string"}
226}
227
33f2d567
JM
228# Verify that the command parser doesn't require a space after an 'if'
229# command in a user defined function.
230#
231gdb_test_multiple "define ifnospace" "define user command: ifnospace" \
232{
233 -re "Type commands for definition of \"ifnospace\".\r\nEnd with a line saying just \"end\".\r\n>$" \
234 {
235 gdb_test_multiple "if(3<4)\nprint \"hi there\\n\"\nend\nend" "send body of ifnospace" \
236 {
237 -re "$gdb_prompt $"\
238 {pass "define user command: ifnospace"}
239 }
240 }
241}
242
243gdb_test "ifnospace" ".*hi there.*" "test ifnospace is parsed correctly"
244
245# Verify that the command parser doesn't require a space after an 'while'
246# command in a user defined function.
247#
248gdb_test_multiple "define whilenospace" "define user command: whilenospace" \
249{
250 -re "Type commands for definition of \"whilenospace\".\r\nEnd with a line saying just \"end\".\r\n>$" \
251 {
252 gdb_test_multiple "set \$i=1\nwhile(\$i<2)\nset \$i=2\nprint \"hi there\\n\"\nend\nend" "send body of whilenospace" \
253 {
254 -re "$gdb_prompt $" \
255 {pass "define user command: whilenospace"}
256 }
257 }
258}
259
260gdb_test "whilenospace" ".*hi there.*" "test whilenospace is parsed correctly"
261
c906108c
SS
262# Verify that the user can "hook" a builtin command. We choose to
263# hook the "stop" pseudo command, and we'll define it to use a user-
264# define command.
265#
266send_gdb "define user-bt\n"
267gdb_expect {
268 -re "Type commands for definition of \"user-bt\".\r\nEnd with a line saying just \"end\".\r\n>$"\
269 {send_gdb "bt\nend\n"
270 gdb_expect {
271 -re "$gdb_prompt $"\
272 {pass "define user command: user-bt"}
273 timeout {fail "(timeout) define user command: user-bt"}
274 }
275 }
276 -re "$gdb_prompt $"\
277 {fail "define user command: user-bt"}
278 timeout {fail "(timeout) define user command: user-bt"}
279}
280
281send_gdb "define hook-stop\n"
282gdb_expect {
283 -re "Type commands for definition of \"hook-stop\".\r\nEnd with a line saying just \"end\".\r\n>$"\
284 {send_gdb "user-b\nend\n"
285 gdb_expect {
286 -re "$gdb_prompt $"\
287 {pass "define hook-stop command"}
288 timeout {fail "(timeout) define hook-stop command"}
289 }
290 }
291 -re "$gdb_prompt $"\
292 {fail "define hook-stop command"}
293 timeout {fail "(timeout) define hook-stop command"}
294}
295
296send_gdb "next\n"
297gdb_expect {
a1dea79a 298 -re "#0\[ \t\]*main.*:$bp_location11.*$gdb_prompt $"\
c906108c
SS
299 {pass "use hook-stop command"}
300 -re "$gdb_prompt $"\
301 {fail "use hook-stop command"}
302 timeout {fail "(timeout) use hook-stop command"}
303}
304
305# Verify that GDB responds gracefully to an attempt to define a "hook
306# command" which doesn't exist. (Test both the confirmed and unconfirmed
307# cases.)
308#
309send_gdb "define hook-bar\n"
310gdb_expect {
311 -re "warning: Your new `hook-bar' command does not hook any existing command.\r\nProceed.*y or n. $"\
312 {send_gdb "n\n"
313 gdb_expect {
314 -re "Not confirmed.*$gdb_prompt $"\
315 {pass "define hook undefined command aborted: bar"}
316 -re "$gdb_prompt $"\
317 {fail "define hook undefined command aborted: bar"}
318 timeout {fail "(timeout) define hook undefined command aborted: bar"}
319 }
320 }
321 -re "$gdb_prompt $"\
322 {fail "define hook undefined command aborted: bar"}
323 timeout {fail "(timeout) define hook undefined command aborted: bar"}
324}
325
326send_gdb "define hook-bar\n"
327gdb_expect {
328 -re "warning: Your new `hook-bar' command does not hook any existing command.\r\nProceed.*y or n. $"\
329 {send_gdb "y\n"
330 gdb_expect {
331 -re "Type commands for definition of \"hook-bar\".\r\nEnd with a line saying just \"end\".\r\n>$"\
332 {send_gdb "nextwhere\nend\n"
333 gdb_expect {
334 -re "$gdb_prompt $"\
335 {pass "define hook undefined command: bar"}
336 timeout {fail "(timeout) define hook undefined command: bar"}
337 }
338 }
339 -re "$gdb_prompt $"\
340 {fail "define hook undefined command: bar"}
341 timeout {fail "(timeout) define hook undefined command: bar"}
342 }
343 }
344 -re "$gdb_prompt $"\
345 {fail "define hook undefined command: bar"}
346 timeout {fail "(timeout) define hook undefined command: bar"}
347}
348
adb483fe
DJ
349# Test creation of an additional target subcommand.
350gdb_test_multiple "define target testsuite" "" {
351 -re "Type commands for definition of \"target testsuite\".\r\nEnd with a line saying just \"end\".\r\n>$" {
352 gdb_test "printf \"hello\\n\"\nend" "" "define target testsuite"
353 }
354}
355gdb_test_multiple "document target testsuite" "" {
356 -re "Type documentation for \"target testsuite\".\r\nEnd with a line saying just \"end\".\r\n>$" {
357 gdb_test "A test target.\nend" "" "document target testsuite"
358 }
359}
360
361gdb_test "help target" ".*A test target.*"
362gdb_test "target testsuite" "hello"
363gdb_test "show user target testsuite" "User command \"target testsuite\":\r\n printf \"hello\\\\n\"\r\n"
364
365# We should even be able to hook subcommands.
366gdb_test_multiple "define target hook-testsuite" "" {
367 -re "Type commands for definition of \"target hook-testsuite\".\r\nEnd with a line saying just \"end\".\r\n>$" {
368 gdb_test "printf \"one\\n\"\nend" "" "define target hook-testsuite"
369 }
370}
371
372gdb_test_multiple "define target hookpost-testsuite" "" {
373 -re "Type commands for definition of \"target hookpost-testsuite\".\r\nEnd with a line saying just \"end\".\r\n>$" {
374 gdb_test "printf \"two\\n\"\nend" "" "define target hookpost-testsuite"
375 }
376}
377
378gdb_test "target testsuite" "one\r\nhello\r\ntwo" "target testsuite with hooks"
379
c906108c
SS
380# This is a quasi-define command: Verify that the user can redefine
381# GDB's gdb_prompt.
382#
383send_gdb "set prompt \\(blah\\) \n"
384gdb_expect {
385 -re "\\(blah\\) $"\
386 {pass "set gdb_prompt"}
387 -re "$gdb_prompt $"\
388 {fail "set gdb_prompt"}
389 timeout {fail "(timeout) set gdb_prompt"}
390}
391
392send_gdb "set prompt \\(gdb\\) \n"
393gdb_expect {
394 -re "$gdb_prompt $"\
395 {pass "reset gdb_prompt"}
396 timeout {fail "(timeout) reset gdb_prompt"}
397}
398
399gdb_exit
400return 0
This page took 1.180088 seconds and 4 git commands to generate.