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