1 # Copyright (C) 1988, 1990, 1991, 1992 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}/${testfile}
33 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
34 perror "Couldn't compile ${srcfile}"
41 gdb_reinitialize_dir $srcdir/$subdir
44 proc gdbvar_simple_if_test {} {
47 gdb_test "set \$foo = 0" "" "set foo in gdbvar_simple_if_test"
48 # All this test should do is print 0xdeadbeef once.
49 gdb_test "if \$foo == 1\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" "\\\$\[0-9\]* = 0xdeadbeef" "gdbvar_simple_if_test #1"
50 # All this test should do is print 0xfeedface once.
51 gdb_test "if \$foo == 0\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" "\\\$\[0-9\]* = 0xfeedface" "gdbvar_simple_if_test #2"
54 proc gdbvar_simple_while_test {} {
57 gdb_test "set \$foo = 5" "" "set foo in gdbvar_simple_while_test"
58 # This test should print 0xfeedface five times.
59 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"
62 proc gdbvar_complex_if_while_test {} {
65 gdb_test "set \$foo = 4" "" "set foo in gdbvar complex_if_while_test"
66 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
67 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"
70 proc progvar_simple_if_test {} {
73 if [target_info exists gdb,noargs] {
74 verbose "Skipping progvar_simple_if_test because of noargs."
78 gdb_test "set args 5" "" "set args in progvar_simple_if_test"
79 if { ![runto factorial] } then { return }
80 # All this test should do is print 0xdeadbeef once.
81 gdb_test "if value == 1\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" "\\\$\[0-9\]* = 0xdeadbeef" "progvar_simple_if_test #1"
82 # All this test should do is print 0xfeedface once.
83 gdb_test "if value == 5\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" "\\\$\[0-9\]* = 0xfeedface" "progvar_simple_if_test #2"
86 proc progvar_simple_while_test {} {
89 if [target_info exists gdb,noargs] {
90 verbose "Skipping progvar_simple_while_test because of noargs."
94 gdb_test "set args 5" "" "set args in progvar_simple_while_test"
95 if { ![runto factorial] } then { return }
96 # This test should print 0xfeedface five times.
97 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"
100 proc progvar_complex_if_while_test {} {
103 if [target_info exists gdb,noargs] {
104 verbose "Skipping progvar_simple_if_while_test because of noargs."
108 gdb_test "set args 4" "" "set args in progvar_complex_if_while_test"
109 if { ![runto factorial] } then { return }
110 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
111 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"
114 proc if_while_breakpoint_command_test {} {
115 if [target_info exists gdb,noargs] {
116 verbose "Skipping if_while_breakpoint_command_test because of noargs."
120 gdb_test "set args 5" "" "set args in if_while_breakpoint_command_test"
121 if { ![runto factorial] } then { return }
123 gdb_test "break factorial" "Breakpoint.*at.*"
125 send_gdb "commands\n"
128 pass "commands in if_while_breakpoint_command_test"
131 fail "(timeout or eof) commands in if_while_breakpoint_command_test"
134 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
135 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"
136 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"
137 gdb_test "info break" "while.*set.*if.*p/x.*else.*p/x.*end.*" "info break in if_while_breakpoint_command_test"
140 # Test that we can run the inferior from breakpoint commands.
141 proc infrun_breakpoint_command_test {} {
142 if [target_info exists gdb,noargs] {
143 verbose "Skipping infrun_breakpoint_command_test because of noargs."
147 gdb_test "set args 6" "" "set args in progvar_simple_while_test"
148 if { ![runto factorial] } then { return }
150 gdb_test "break factorial if value == 5" "Breakpoint.*at.*"
151 gdb_test "commands\nstep\nstep\nstep\nstep\nbt\nend" \
152 "End with.*" "commands in infrun_breakpoint_command_test"
153 gdb_test "continue" "Breakpoint \[0-9\]*, factorial \\(value=5\\).*at.*
154 \[0-9\]*\[ \]*if \\(value > 1\\) \{.*
155 \[0-9\]*\[ \]*value \\*= factorial \\(value - 1\\);.*
156 factorial \\(value=4\\) at.*\[0-9\]*\[ \]*if \\(value > 1\\) \{.*
157 \[0-9\]*\[ \]*value \\*= factorial \\(value - 1\\);.*
158 factorial \\(value=3\\) at .*
159 \[0-9\]*\[ \]*if \\(value > 1\\) \{.*
160 #0 factorial \\(value=3\\).*
161 #1 \[0-9a-fx\]* in factorial \\(value=4\\).*
162 #2 \[0-9a-fx\]* in factorial \\(value=5\\).*
163 #3 \[0-9a-fx\]* in factorial \\(value=6\\).*
164 #4 \[0-9a-fx\]* in main \\(.*\\).*" \
165 "continue in infrun_breakpoint_command_test"
168 proc breakpoint_command_test {} {
169 if [target_info exists gdb,noargs] {
170 verbose "Skipping breakpoint_command_test because of noargs."
174 gdb_test "set args 6" "" "set args in progvar_simple_while_test"
175 if { ![runto factorial] } then { return }
177 gdb_test "break factorial" "Breakpoint.*at.*"
178 gdb_test "commands\nprintf \"Now the value is %d\\n\", value\nend" \
179 "End with.*" "commands in breakpoint_command_test"
180 gdb_test "continue" "Breakpoint \[0-9\]*, factorial.*Now the value is 5" \
181 "continue in breakpoint_command_test"
182 gdb_test "print value" " = 5" "print value in breakpoint_command_test"
185 # Test a simple user defined command (with arguments)
186 proc user_defined_command_test {} {
189 gdb_test "set \$foo = 4" "" "set foo in user_defined_command_test"
191 send_gdb "define mycommand\n"
194 pass "define mycommand in user_defined_command_test"
197 fail "(timeout or eof) define mycommand in user_defined_command_test"
200 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
201 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"
203 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"
204 gdb_test "show user mycommand" "while.*set.*if.*p/x.*else.*p/x.*end.*" "display user command in user_defined_command_test"
207 gdbvar_simple_if_test
208 gdbvar_simple_while_test
209 gdbvar_complex_if_while_test
210 progvar_simple_if_test
211 progvar_simple_while_test
212 progvar_complex_if_while_test
213 if_while_breakpoint_command_test
214 infrun_breakpoint_command_test
215 breakpoint_command_test
216 user_defined_command_test