1 # Copyright 1998, 1999, 2001, 2003, 2004, 2007, 2008
2 # Free Software Foundation, Inc.
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.
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.
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/>.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Elena Zannoni. (ezannoni@cygnus.com)
30 # test running programs
36 set srcfile ${testfile}.c
37 set srcfile1 ${testfile}1.c
38 set binfile ${objdir}/${subdir}/${testfile}
40 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
45 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
50 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
57 gdb_reinitialize_dir $srcdir/$subdir
60 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
61 set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
63 if ![runto_main] then { fail "define tests suppressed" }
65 # Verify that GDB allows a user to define their very own commands.
67 send_gdb "define nextwhere\n"
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"
73 {pass "define user command: nextwhere"}
74 timeout {fail "(timeout) define user command: nextwhere"}
78 {fail "define user command: nextwhere"}
79 timeout {fail "(timeout) define user command: nextwhere"}
82 # Verify that those commands work as gdb_expected.
84 send_gdb "nextwhere\n"
86 -re ".*$bp_location1\[ \t\]*printf.*#0\[ \t\]*main.*:$bp_location1.*$gdb_prompt $"\
87 {pass "use user command: nextwhere"}
89 {fail "use user command: nextwhere"}
90 timeout {fail "(timeout) use user command: nextwhere"}
93 # Verify that a user can define a command whose spelling is a
94 # proper substring of another user-defined command.
96 send_gdb "define nextwh\n"
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"
102 {pass "define user command: nextwh"}
103 timeout {fail "(timeout) define user command: nextwh"}
107 {fail "define user command: nextwh"}
108 timeout {fail "(timeout) define user command: nextwh"}
111 # Verify that a user can redefine their commands. (Test both the
112 # confirmed and unconfirmed cases.)
114 send_gdb "define nextwhere\n"
116 -re "Redefine command \"nextwhere\".*y or n. $"\
119 -re "Command \"nextwhere\" not redefined.*$gdb_prompt $"\
120 {pass "redefine user command aborted: nextwhere"}
122 {fail "redefine user command aborted: nextwhere"}
123 timeout {fail "(timeout) redefine user command aborted: nextwhere"}
127 {fail "redefine user command aborted: nextwhere"}
128 timeout {fail "(timeout) redefine user command aborted: nextwhere"}
131 send_gdb "define nextwhere\n"
133 -re "Redefine command \"nextwhere\".*y or n. $"\
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"
140 {pass "redefine user command: nextwhere"}
141 timeout {fail "(timeout) redefine user command: nextwhere"}
144 timeout {fail "(timeout) redefine user command: nextwhere"}
148 {fail "redefine user command: nextwhere"}
149 timeout {fail "(timeout) redefine user command: nextwhere"}
152 # Verify that GDB gracefully handles an attempt to redefine the
153 # help text for a builtin command.
155 send_gdb "document step\n"
157 -re "Command \"step\" is built-in..*$gdb_prompt $"\
158 {pass "redocumenting builtin command disallowed"}
160 {fail "redocumenting builtin command disallowed"}
161 timeout {fail "(timeout) redocumenting builtin command disallowed"}
164 # Verify that a user can document their own commands. (And redocument
167 send_gdb "document nextwhere\n"
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"
173 {pass "document user command: nextwhere"}
174 timeout {fail "(timeout) document user command: nextwhere"}
178 {fail "document user command: nextwhere"}
179 timeout {fail "(timeout) document user command: nextwhere"}
182 send_gdb "document nextwhere\n"
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"
188 {pass "re-document user command: nextwhere"}
189 timeout {fail "(timeout) re-document user command: nextwhere"}
193 {fail "re-document user command: nextwhere"}
194 timeout {fail "(timeout) re-document user command: nextwhere"}
197 send_gdb "help nextwhere\n"
199 -re "A next command that first shows you where you're stepping from.\r\n$gdb_prompt $"\
200 {pass "help user command: nextwhere"}
202 {fail "help user command: nextwhere"}
203 timeout {fail "(timeout) help user command: nextwhere"}
206 # Verify that the command parser doesn't require a space after an 'if'
207 # command in a user defined function.
209 gdb_test_multiple "define ifnospace" "define user command: ifnospace" \
211 -re "Type commands for definition of \"ifnospace\".\r\nEnd with a line saying just \"end\".\r\n>$" \
213 gdb_test_multiple "if(3<4)\nprint \"hi there\\n\"\nend\nend" "send body of ifnospace" \
216 {pass "define user command: ifnospace"}
221 gdb_test "ifnospace" ".*hi there.*" "test ifnospace is parsed correctly"
223 # Verify that the command parser doesn't require a space after an 'while'
224 # command in a user defined function.
226 gdb_test_multiple "define whilenospace" "define user command: whilenospace" \
228 -re "Type commands for definition of \"whilenospace\".\r\nEnd with a line saying just \"end\".\r\n>$" \
230 gdb_test_multiple "set \$i=1\nwhile(\$i<2)\nset \$i=2\nprint \"hi there\\n\"\nend\nend" "send body of whilenospace" \
232 -re "$gdb_prompt $" \
233 {pass "define user command: whilenospace"}
238 gdb_test "whilenospace" ".*hi there.*" "test whilenospace is parsed correctly"
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-
244 send_gdb "define user-bt\n"
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"
250 {pass "define user command: user-bt"}
251 timeout {fail "(timeout) define user command: user-bt"}
255 {fail "define user command: user-bt"}
256 timeout {fail "(timeout) define user command: user-bt"}
259 send_gdb "define hook-stop\n"
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"
265 {pass "define hook-stop command"}
266 timeout {fail "(timeout) define hook-stop command"}
270 {fail "define hook-stop command"}
271 timeout {fail "(timeout) define hook-stop command"}
276 -re "#0\[ \t\]*main.*:$bp_location11.*$gdb_prompt $"\
277 {pass "use hook-stop command"}
279 {fail "use hook-stop command"}
280 timeout {fail "(timeout) use hook-stop command"}
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
287 send_gdb "define hook-bar\n"
289 -re "warning: Your new `hook-bar' command does not hook any existing command.\r\nProceed.*y or n. $"\
292 -re "Not confirmed.*$gdb_prompt $"\
293 {pass "define hook undefined command aborted: bar"}
295 {fail "define hook undefined command aborted: bar"}
296 timeout {fail "(timeout) define hook undefined command aborted: bar"}
300 {fail "define hook undefined command aborted: bar"}
301 timeout {fail "(timeout) define hook undefined command aborted: bar"}
304 send_gdb "define hook-bar\n"
306 -re "warning: Your new `hook-bar' command does not hook any existing command.\r\nProceed.*y or n. $"\
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"
313 {pass "define hook undefined command: bar"}
314 timeout {fail "(timeout) define hook undefined command: bar"}
318 {fail "define hook undefined command: bar"}
319 timeout {fail "(timeout) define hook undefined command: bar"}
323 {fail "define hook undefined command: bar"}
324 timeout {fail "(timeout) define hook undefined command: bar"}
327 # This is a quasi-define command: Verify that the user can redefine
330 send_gdb "set prompt \\(blah\\) \n"
333 {pass "set gdb_prompt"}
335 {fail "set gdb_prompt"}
336 timeout {fail "(timeout) set gdb_prompt"}
339 send_gdb "set prompt \\(gdb\\) \n"
342 {pass "reset gdb_prompt"}
343 timeout {fail "(timeout) reset gdb_prompt"}