1 # Copyright (C) 1988, 1990, 1991, 1992, 1997 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
25 # test special commands (if, while, etc)
31 set srcfile ${testfile}.c
32 set binfile ${objdir}/${subdir}/commands
33 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
34 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
40 gdb_reinitialize_dir $srcdir/$subdir
43 proc gdbvar_simple_if_test {} {
46 gdb_test "set \$foo = 0" "" "set foo in gdbvar_simple_if_test"
47 # All this test should do is print 0xdeadbeef once.
48 gdb_test "if \$foo == 1\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" "\\\$\[0-9\]* = 0xdeadbeef" "gdbvar_simple_if_test #1"
49 # All this test should do is print 0xfeedface once.
50 gdb_test "if \$foo == 0\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" "\\\$\[0-9\]* = 0xfeedface" "gdbvar_simple_if_test #2"
53 proc gdbvar_simple_while_test {} {
56 gdb_test "set \$foo = 5" "" "set foo in gdbvar_simple_while_test"
57 # This test should print 0xfeedface five times.
58 gdb_test "while \$foo > 0\np/x 0xfeedface\nset \$foo -= 1\nend" "\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" "gdbvar_simple_while_test #1"
61 proc gdbvar_complex_if_while_test {} {
64 gdb_test "set \$foo = 4" "" "set foo in gdbvar complex_if_while_test"
65 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
66 gdb_test "while \$foo > 0\nset \$foo -= 1\nif \(\$foo % 2\) == 1\np/x 0xdeadbeef\nelse\np/x 0xfeedface\nend\nend" "\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" "gdbvar_complex_if_while_test #1"
69 proc progvar_simple_if_test {} {
72 if [target_info exists noargs] {
73 verbose "Skipping progvar_simple_if_test because of noargs."
77 if { ![runto factorial] } then { gdb_suppress_tests; }
78 # Don't depend upon argument passing, since most simulators don't currently
79 # support it. Bash value variable to be what we want.
80 gdb_test "p value=5" "" "set value to 5 in progvar_simple_if_test #1"
81 # All this test should do is print 0xdeadbeef once.
82 gdb_test "if value == 1\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" "\\\$\[0-9\]* = 0xdeadbeef" "progvar_simple_if_test #1"
83 # All this test should do is print 0xfeedface once.
84 gdb_test "if value == 5\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" "\\\$\[0-9\]* = 0xfeedface" "progvar_simple_if_test #2"
85 gdb_stop_suppressing_tests;
88 proc progvar_simple_while_test {} {
91 if [target_info exists noargs] {
92 verbose "Skipping progvar_simple_while_test because of noargs."
96 if { ![runto factorial] } then { gdb_suppress_tests }
97 # Don't depend upon argument passing, since most simulators don't currently
98 # support it. Bash value variable to be what we want.
99 gdb_test "p value=5" "" "set value to 5 in progvar_simple_if_test #2"
100 # This test should print 0xfeedface five times.
101 gdb_test "while value > 0\np/x 0xfeedface\nset value -= 1\nend" "\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" "progvar_simple_while_test #1"
102 gdb_stop_suppressing_tests;
105 proc progvar_complex_if_while_test {} {
108 if [target_info exists noargs] {
109 verbose "Skipping progvar_simple_if_while_test because of noargs."
113 if { ![runto factorial] } then { gdb_suppress_tests }
114 # Don't depend upon argument passing, since most simulators don't currently
115 # support it. Bash value variable to be what we want.
116 gdb_test "p value=4" "" "set value to 4 in progvar_simple_if_test"
117 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
118 gdb_test "while value > 0\nset value -= 1\nif \(value % 2\) == 1\np/x 0xdeadbeef\nelse\np/x 0xfeedface\nend\nend" "\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" "progvar_complex_if_while_test #1"
119 gdb_stop_suppressing_tests;
122 proc if_while_breakpoint_command_test {} {
123 if [target_info exists noargs] {
124 verbose "Skipping if_while_breakpoint_command_test because of noargs."
128 if { ![runto factorial] } then { gdb_suppress_tests }
129 # Don't depend upon argument passing, since most simulators don't currently
130 # support it. Bash value variable to be what we want.
131 gdb_test "p value=5" "" "set value to 5 in progvar_simple_if_test"
133 gdb_test "break factorial" "Breakpoint.*at.*" "break factorial #1"
135 send_gdb "commands\n"
138 pass "commands in if_while_breakpoint_command_test"
141 fail "(timeout or eof) commands in if_while_breakpoint_command_test"
144 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
145 gdb_test "while value > 0\nset value -= 1\nif \(value % 2\) == 1\np/x 0xdeadbeef\nelse\np/x 0xfeedface\nend\nend\nend" "" "commands part 2 in if_while_breakpoint_command_test"
146 gdb_test "continue" "\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" "if_while_breakpoint_command_test #1"
147 gdb_test "info break" "while.*set.*if.*p/x.*else.*p/x.*end.*" "info break in if_while_breakpoint_command_test"
148 gdb_stop_suppressing_tests;
151 # Test that we can run the inferior from breakpoint commands.
152 proc infrun_breakpoint_command_test {} {
153 if [target_info exists noargs] {
154 verbose "Skipping infrun_breakpoint_command_test because of noargs."
158 if { ![runto factorial] } then { gdb_suppress_tests }
159 # Don't depend upon argument passing, since most simulators don't currently
160 # support it. Bash value variable to be what we want.
161 gdb_test "p value=6" "" "set value to 6 in progvar_simple_if_test #1"
163 gdb_test "break factorial if value == 5" "Breakpoint.*at.*"
165 # infrun_breakpoint_command_test - This test was broken into two parts
166 # to get around a synchronization problem in expect.
167 # part1: issue the gdb command "commands"
168 # part2: send the list of commands
169 send_gdb "commands\n"
172 pass "commands in infrun_breakpoint_command_test #1"
175 fail "(timeout or eof) commands in infrun_breakpoint_command_test"
178 gdb_test "step\nstep\nstep\nstep\nbt\nend" "" \
179 "commands in infrun_breakpoint_command_test #2"
181 gdb_test "continue" "Breakpoint \[0-9\]*, factorial \\(value=5\\).*at.*
182 \[0-9\]*\[ \]*if \\(value > 1\\) \{.*
183 \[0-9\]*\[ \]*value \\*= factorial \\(value - 1\\);.*
184 factorial \\(value=4\\) at.*\[0-9\]*\[ \]*if \\(value > 1\\) \{.*
185 \[0-9\]*\[ \]*value \\*= factorial \\(value - 1\\);.*
186 factorial \\(value=3\\) at .*
187 \[0-9\]*\[ \]*if \\(value > 1\\) \{.*
188 #0 factorial \\(value=3\\).*
189 #1 \[0-9a-fx\]* in factorial \\(value=4\\).*
190 #2 \[0-9a-fx\]* in factorial \\(value=5\\).*
191 #3 \[0-9a-fx\]* in factorial \\(value=6\\).*
192 #4 \[0-9a-fx\]* in main \\(.*\\).*" \
193 "continue in infrun_breakpoint_command_test";
194 gdb_stop_suppressing_tests;
197 proc breakpoint_command_test {} {
198 if [target_info exists noargs] {
199 verbose "Skipping breakpoint_command_test because of noargs."
203 if { ![runto factorial] } then { gdb_suppress_tests; }
204 # Don't depend upon argument passing, since most simulators don't currently
205 # support it. Bash value variable to be what we want.
206 gdb_test "p value=6" "" "set value to 6 in progvar_simple_if_test #2"
208 gdb_test "break factorial" "Breakpoint.*at.*" "break factorial #2"
209 gdb_test "commands\nprintf \"Now the value is %d\\n\", value\nend" \
210 "Type commands.*\nEnd with.*" "commands in breakpoint_command_test"
211 gdb_test "continue" "Breakpoint \[0-9\]*, factorial.*Now the value is 5" \
212 "continue in breakpoint_command_test"
213 gdb_test "print value" " = 5" "print value in breakpoint_command_test"
214 gdb_stop_suppressing_tests;
217 # Test a simple user defined command (with arguments)
218 proc user_defined_command_test {} {
221 gdb_test "set \$foo = 4" "" "set foo in user_defined_command_test"
223 send_gdb "define mycommand\n"
226 pass "define mycommand in user_defined_command_test"
229 fail "(timeout or eof) define mycommand in user_defined_command_test"
232 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
233 gdb_test "while \$arg0 > 0\nset \$arg0 -= 1\nif \(\$arg0 % 2\) == 1\np/x 0xdeadbeef\nelse\np/x 0xfeedface\nend\nend\nend" "" "enter commands in user_defined_command_test"
235 gdb_test "mycommand \$foo" "\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" "execute user defined command in user_defined_command_test"
236 gdb_test "show user mycommand" "while.*set.*if.*p/x.*else.*p/x.*end.*" "display user command in user_defined_command_test"
241 proc test_command_prompt_position {} {
244 if [target_info exists noargs] {
245 verbose "Skipping test_command_prompt_position because of noargs."
249 if { ![runto factorial] } then { gdb_suppress_tests; }
250 # Don't depend upon argument passing, since most simulators don't currently
251 # support it. Bash value variable to be what we want.
253 gdb_test "break factorial" "Breakpoint.*at.*" "break factorial #2"
254 gdb_test "p value=5" "" "set value to 5 in test_command_prompt_position"
255 # All this test should do is print 0xdeadbeef once.
256 gdb_test "if value == 1\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" "\\\$\[0-9\]* = 0xdeadbeef" "if test in test_command_prompt_position"
258 # Now let's test for the correct position of the '>' in gdb's prompt for commands.
259 # It should be at the beginning of the line, and not after one space.
261 send_gdb "commands\n"
263 -re "Type commands.*End with.*\[\r\n\]>$" \
264 { send_gdb "printf \"Now the value is %d\\n\", value\n"
266 -re "^printf.*value\r\n>$" \
269 -re "^end\r\n$gdb_prompt $" { pass "> OK in test_command_prompt_position" }
270 -re ".*$gdb_prompt $" { fail "some other message in test_command_prompt_position" }
271 timeout { fail "(timeout) 1 in test_command_prompt_position" }
274 -re "^ >$" { fail "> not OK in test_command_prompt_position" }
275 -re ".*$gdb_prompt $" { fail "wrong message in test_command_prompt_position" }
276 timeout { fail "(timeout) 2 in test_command_prompt_position " }
279 -re "Type commands.*End with.*\[\r\n\] >$" { fail "prompt not OK in test_command_prompt_position" }
280 -re ".*$gdb_prompt $" { fail "commands in test_command_prompt_position" }
281 timeout { fail "(timeout) 3 commands in test_command_prompt_position" }
284 gdb_stop_suppressing_tests;
288 gdbvar_simple_if_test
289 gdbvar_simple_while_test
290 gdbvar_complex_if_while_test
291 progvar_simple_if_test
292 progvar_simple_while_test
293 progvar_complex_if_while_test
294 if_while_breakpoint_command_test
295 infrun_breakpoint_command_test
296 breakpoint_command_test
297 user_defined_command_test
298 test_command_prompt_position