1 # Copyright 1998, 1999, 2001, 2003, 2004, 2007 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Please email any bugs, comments, and/or additions to this file to:
17 # bug-gdb@prep.ai.mit.edu
19 # This file was written by Elena Zannoni. (ezannoni@cygnus.com)
29 # test running programs
35 set srcfile ${testfile}.c
36 set srcfile1 ${testfile}1.c
37 set binfile ${objdir}/${subdir}/${testfile}
39 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
44 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
49 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
56 gdb_reinitialize_dir $srcdir/$subdir
59 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
60 set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
62 if ![runto_main] then { fail "define tests suppressed" }
64 # Verify that GDB allows a user to define their very own commands.
66 send_gdb "define nextwhere\n"
68 -re "Type commands for definition of \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$"\
69 {send_gdb "next\nbt\nend\n"
72 {pass "define user command: nextwhere"}
73 timeout {fail "(timeout) define user command: nextwhere"}
77 {fail "define user command: nextwhere"}
78 timeout {fail "(timeout) define user command: nextwhere"}
81 # Verify that those commands work as gdb_expected.
83 send_gdb "nextwhere\n"
85 -re ".*$bp_location1\[ \t\]*printf.*#0\[ \t\]*main.*:$bp_location1.*$gdb_prompt $"\
86 {pass "use user command: nextwhere"}
88 {fail "use user command: nextwhere"}
89 timeout {fail "(timeout) use user command: nextwhere"}
92 # Verify that a user can define a command whose spelling is a
93 # proper substring of another user-defined command.
95 send_gdb "define nextwh\n"
97 -re "Type commands for definition of \"nextwh\".\r\nEnd with a line saying just \"end\".\r\n>$"\
98 {send_gdb "next 2\nbt\nend\n"
101 {pass "define user command: nextwh"}
102 timeout {fail "(timeout) define user command: nextwh"}
106 {fail "define user command: nextwh"}
107 timeout {fail "(timeout) define user command: nextwh"}
110 # Verify that a user can redefine their commands. (Test both the
111 # confirmed and unconfirmed cases.)
113 send_gdb "define nextwhere\n"
115 -re "Redefine command \"nextwhere\".*y or n. $"\
118 -re "Command \"nextwhere\" not redefined.*$gdb_prompt $"\
119 {pass "redefine user command aborted: nextwhere"}
121 {fail "redefine user command aborted: nextwhere"}
122 timeout {fail "(timeout) redefine user command aborted: nextwhere"}
126 {fail "redefine user command aborted: nextwhere"}
127 timeout {fail "(timeout) redefine user command aborted: nextwhere"}
130 send_gdb "define nextwhere\n"
132 -re "Redefine command \"nextwhere\".*y or n. $"\
135 -re "Type commands for definition of \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$"\
136 {send_gdb "bt\nnext\nend\n"
139 {pass "redefine user command: nextwhere"}
140 timeout {fail "(timeout) redefine user command: nextwhere"}
143 timeout {fail "(timeout) redefine user command: nextwhere"}
147 {fail "redefine user command: nextwhere"}
148 timeout {fail "(timeout) redefine user command: nextwhere"}
151 # Verify that GDB gracefully handles an attempt to redefine the
152 # help text for a builtin command.
154 send_gdb "document step\n"
156 -re "Command \"step\" is built-in..*$gdb_prompt $"\
157 {pass "redocumenting builtin command disallowed"}
159 {fail "redocumenting builtin command disallowed"}
160 timeout {fail "(timeout) redocumenting builtin command disallowed"}
163 # Verify that a user can document their own commands. (And redocument
166 send_gdb "document nextwhere\n"
168 -re "Type documentation for \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$"\
169 {send_gdb "A next command that frist shows you where you're stepping from.\nend\n"
172 {pass "document user command: nextwhere"}
173 timeout {fail "(timeout) document user command: nextwhere"}
177 {fail "document user command: nextwhere"}
178 timeout {fail "(timeout) document user command: nextwhere"}
181 send_gdb "document nextwhere\n"
183 -re "Type documentation for \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$"\
184 {send_gdb "A next command that first shows you where you're stepping from.\nend\n"
187 {pass "re-document user command: nextwhere"}
188 timeout {fail "(timeout) re-document user command: nextwhere"}
192 {fail "re-document user command: nextwhere"}
193 timeout {fail "(timeout) re-document user command: nextwhere"}
196 send_gdb "help nextwhere\n"
198 -re "A next command that first shows you where you're stepping from.\r\n$gdb_prompt $"\
199 {pass "help user command: nextwhere"}
201 {fail "help user command: nextwhere"}
202 timeout {fail "(timeout) help user command: nextwhere"}
205 # Verify that the command parser doesn't require a space after an 'if'
206 # command in a user defined function.
208 gdb_test_multiple "define ifnospace" "define user command: ifnospace" \
210 -re "Type commands for definition of \"ifnospace\".\r\nEnd with a line saying just \"end\".\r\n>$" \
212 gdb_test_multiple "if(3<4)\nprint \"hi there\\n\"\nend\nend" "send body of ifnospace" \
215 {pass "define user command: ifnospace"}
220 gdb_test "ifnospace" ".*hi there.*" "test ifnospace is parsed correctly"
222 # Verify that the command parser doesn't require a space after an 'while'
223 # command in a user defined function.
225 gdb_test_multiple "define whilenospace" "define user command: whilenospace" \
227 -re "Type commands for definition of \"whilenospace\".\r\nEnd with a line saying just \"end\".\r\n>$" \
229 gdb_test_multiple "set \$i=1\nwhile(\$i<2)\nset \$i=2\nprint \"hi there\\n\"\nend\nend" "send body of whilenospace" \
231 -re "$gdb_prompt $" \
232 {pass "define user command: whilenospace"}
237 gdb_test "whilenospace" ".*hi there.*" "test whilenospace is parsed correctly"
239 # Verify that the user can "hook" a builtin command. We choose to
240 # hook the "stop" pseudo command, and we'll define it to use a user-
243 send_gdb "define user-bt\n"
245 -re "Type commands for definition of \"user-bt\".\r\nEnd with a line saying just \"end\".\r\n>$"\
246 {send_gdb "bt\nend\n"
249 {pass "define user command: user-bt"}
250 timeout {fail "(timeout) define user command: user-bt"}
254 {fail "define user command: user-bt"}
255 timeout {fail "(timeout) define user command: user-bt"}
258 send_gdb "define hook-stop\n"
260 -re "Type commands for definition of \"hook-stop\".\r\nEnd with a line saying just \"end\".\r\n>$"\
261 {send_gdb "user-b\nend\n"
264 {pass "define hook-stop command"}
265 timeout {fail "(timeout) define hook-stop command"}
269 {fail "define hook-stop command"}
270 timeout {fail "(timeout) define hook-stop command"}
275 -re "#0\[ \t\]*main.*:$bp_location11.*$gdb_prompt $"\
276 {pass "use hook-stop command"}
278 {fail "use hook-stop command"}
279 timeout {fail "(timeout) use hook-stop command"}
282 # Verify that GDB responds gracefully to an attempt to define a "hook
283 # command" which doesn't exist. (Test both the confirmed and unconfirmed
286 send_gdb "define hook-bar\n"
288 -re "warning: Your new `hook-bar' command does not hook any existing command.\r\nProceed.*y or n. $"\
291 -re "Not confirmed.*$gdb_prompt $"\
292 {pass "define hook undefined command aborted: bar"}
294 {fail "define hook undefined command aborted: bar"}
295 timeout {fail "(timeout) define hook undefined command aborted: bar"}
299 {fail "define hook undefined command aborted: bar"}
300 timeout {fail "(timeout) define hook undefined command aborted: bar"}
303 send_gdb "define hook-bar\n"
305 -re "warning: Your new `hook-bar' command does not hook any existing command.\r\nProceed.*y or n. $"\
308 -re "Type commands for definition of \"hook-bar\".\r\nEnd with a line saying just \"end\".\r\n>$"\
309 {send_gdb "nextwhere\nend\n"
312 {pass "define hook undefined command: bar"}
313 timeout {fail "(timeout) define hook undefined command: bar"}
317 {fail "define hook undefined command: bar"}
318 timeout {fail "(timeout) define hook undefined command: bar"}
322 {fail "define hook undefined command: bar"}
323 timeout {fail "(timeout) define hook undefined command: bar"}
326 # This is a quasi-define command: Verify that the user can redefine
329 send_gdb "set prompt \\(blah\\) \n"
332 {pass "set gdb_prompt"}
334 {fail "set gdb_prompt"}
335 timeout {fail "(timeout) set gdb_prompt"}
338 send_gdb "set prompt \\(gdb\\) \n"
341 {pass "reset gdb_prompt"}
342 timeout {fail "(timeout) reset gdb_prompt"}