1 # Copyright 1998, 1999, 2001, 2003, 2004, 2007, 2008, 2009
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 # This file was written by Elena Zannoni. (ezannoni@cygnus.com)
27 # test running programs
33 set srcfile ${testfile}.c
34 set srcfile1 ${testfile}1.c
35 set binfile ${objdir}/${subdir}/${testfile}
37 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
42 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
47 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
54 gdb_reinitialize_dir $srcdir/$subdir
57 set bp_location1 [gdb_get_line_number "set breakpoint 1 here"]
58 set bp_location11 [gdb_get_line_number "set breakpoint 11 here"]
60 if ![runto_main] then { fail "define tests suppressed" }
62 # Verify that GDB allows a user to define their very own commands.
64 send_gdb "define nextwhere\n"
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"
70 {pass "define user command: nextwhere"}
71 timeout {fail "(timeout) define user command: nextwhere"}
75 {fail "define user command: nextwhere"}
76 timeout {fail "(timeout) define user command: nextwhere"}
79 # Verify that those commands work as gdb_expected.
81 send_gdb "nextwhere\n"
83 -re ".*$bp_location1\[ \t\]*printf.*#0\[ \t\]*main.*:$bp_location1.*$gdb_prompt $"\
84 {pass "use user command: nextwhere"}
86 {fail "use user command: nextwhere"}
87 timeout {fail "(timeout) use user command: nextwhere"}
90 # Verify that a user can define a command whose spelling is a
91 # proper substring of another user-defined command.
93 send_gdb "define nextwh\n"
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"
99 {pass "define user command: nextwh"}
100 timeout {fail "(timeout) define user command: nextwh"}
104 {fail "define user command: nextwh"}
105 timeout {fail "(timeout) define user command: nextwh"}
108 # Verify that a user can redefine their commands. (Test both the
109 # confirmed and unconfirmed cases.)
111 send_gdb "define nextwhere\n"
113 -re "Redefine command \"nextwhere\".*y or n. $"\
116 -re "Command \"nextwhere\" not redefined.*$gdb_prompt $"\
117 {pass "redefine user command aborted: nextwhere"}
119 {fail "redefine user command aborted: nextwhere"}
120 timeout {fail "(timeout) redefine user command aborted: nextwhere"}
124 {fail "redefine user command aborted: nextwhere"}
125 timeout {fail "(timeout) redefine user command aborted: nextwhere"}
128 send_gdb "define nextwhere\n"
130 -re "Redefine command \"nextwhere\".*y or n. $"\
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"
137 {pass "redefine user command: nextwhere"}
138 timeout {fail "(timeout) redefine user command: nextwhere"}
141 timeout {fail "(timeout) redefine user command: nextwhere"}
145 {fail "redefine user command: nextwhere"}
146 timeout {fail "(timeout) redefine user command: nextwhere"}
149 # Verify that GDB gracefully handles an attempt to redefine the
150 # help text for a builtin command.
152 send_gdb "document step\n"
154 -re "Command \"step\" is built-in..*$gdb_prompt $"\
155 {pass "redocumenting builtin command disallowed"}
157 {fail "redocumenting builtin command disallowed"}
158 timeout {fail "(timeout) redocumenting builtin command disallowed"}
161 # Verify that a user can document their own commands. (And redocument
164 send_gdb "document nextwhere\n"
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"
170 {pass "document user command: nextwhere"}
171 timeout {fail "(timeout) document user command: nextwhere"}
175 {fail "document user command: nextwhere"}
176 timeout {fail "(timeout) document user command: nextwhere"}
179 send_gdb "document nextwhere\n"
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"
185 {pass "re-document user command: nextwhere"}
186 timeout {fail "(timeout) re-document user command: nextwhere"}
190 {fail "re-document user command: nextwhere"}
191 timeout {fail "(timeout) re-document user command: nextwhere"}
194 send_gdb "help nextwhere\n"
196 -re "A next command that first shows you where you're stepping from.\r\n$gdb_prompt $"\
197 {pass "help user command: nextwhere"}
199 {fail "help user command: nextwhere"}
200 timeout {fail "(timeout) help user command: nextwhere"}
203 # Verify that the document command preserves whitespace in the beginning of the line.
205 send_gdb "document nextwhere\n"
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"
210 -re "$gdb_prompt $" {}
211 timeout {fail "(timeout) preserve whitespace in help string"}
215 {fail "preserve whitespace in help string"}
216 timeout {fail "(timeout) preserve whitespace in help string"}
219 send_gdb "help nextwhere\n"
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"}
224 {fail "preserve whitespace in help string"}
225 timeout {fail "(timeout) preserve whitespace in help string"}
228 # Verify that the command parser doesn't require a space after an 'if'
229 # command in a user defined function.
231 gdb_test_multiple "define ifnospace" "define user command: ifnospace" \
233 -re "Type commands for definition of \"ifnospace\".\r\nEnd with a line saying just \"end\".\r\n>$" \
235 gdb_test_multiple "if(3<4)\nprint \"hi there\\n\"\nend\nend" "send body of ifnospace" \
238 {pass "define user command: ifnospace"}
243 gdb_test "ifnospace" ".*hi there.*" "test ifnospace is parsed correctly"
245 # Verify that the command parser doesn't require a space after an 'while'
246 # command in a user defined function.
248 gdb_test_multiple "define whilenospace" "define user command: whilenospace" \
250 -re "Type commands for definition of \"whilenospace\".\r\nEnd with a line saying just \"end\".\r\n>$" \
252 gdb_test_multiple "set \$i=1\nwhile(\$i<2)\nset \$i=2\nprint \"hi there\\n\"\nend\nend" "send body of whilenospace" \
254 -re "$gdb_prompt $" \
255 {pass "define user command: whilenospace"}
260 gdb_test "whilenospace" ".*hi there.*" "test whilenospace is parsed correctly"
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-
266 send_gdb "define user-bt\n"
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"
272 {pass "define user command: user-bt"}
273 timeout {fail "(timeout) define user command: user-bt"}
277 {fail "define user command: user-bt"}
278 timeout {fail "(timeout) define user command: user-bt"}
281 send_gdb "define hook-stop\n"
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"
287 {pass "define hook-stop command"}
288 timeout {fail "(timeout) define hook-stop command"}
292 {fail "define hook-stop command"}
293 timeout {fail "(timeout) define hook-stop command"}
298 -re "#0\[ \t\]*main.*:$bp_location11.*$gdb_prompt $"\
299 {pass "use hook-stop command"}
301 {fail "use hook-stop command"}
302 timeout {fail "(timeout) use hook-stop command"}
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
309 send_gdb "define hook-bar\n"
311 -re "warning: Your new `hook-bar' command does not hook any existing command.\r\nProceed.*y or n. $"\
314 -re "Not confirmed.*$gdb_prompt $"\
315 {pass "define hook undefined command aborted: bar"}
317 {fail "define hook undefined command aborted: bar"}
318 timeout {fail "(timeout) define hook undefined command aborted: bar"}
322 {fail "define hook undefined command aborted: bar"}
323 timeout {fail "(timeout) define hook undefined command aborted: bar"}
326 send_gdb "define hook-bar\n"
328 -re "warning: Your new `hook-bar' command does not hook any existing command.\r\nProceed.*y or n. $"\
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"
335 {pass "define hook undefined command: bar"}
336 timeout {fail "(timeout) define hook undefined command: bar"}
340 {fail "define hook undefined command: bar"}
341 timeout {fail "(timeout) define hook undefined command: bar"}
345 {fail "define hook undefined command: bar"}
346 timeout {fail "(timeout) define hook undefined command: bar"}
349 # Test creation of an additional target subcommand.
350 gdb_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"
355 gdb_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"
361 gdb_test "help target" ".*A test target.*"
362 gdb_test "target testsuite" "hello"
363 gdb_test "show user target testsuite" "User command \"target testsuite\":\r\n printf \"hello\\\\n\"\r\n"
365 # We should even be able to hook subcommands.
366 gdb_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"
372 gdb_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"
378 gdb_test "target testsuite" "one\r\nhello\r\ntwo" "target testsuite with hooks"
380 # This is a quasi-define command: Verify that the user can redefine
383 send_gdb "set prompt \\(blah\\) \n"
386 {pass "set gdb_prompt"}
388 {fail "set gdb_prompt"}
389 timeout {fail "(timeout) set gdb_prompt"}
392 send_gdb "set prompt \\(gdb\\) \n"
395 {pass "reset gdb_prompt"}
396 timeout {fail "(timeout) reset gdb_prompt"}