]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/commands.exp
Initial creation of sourceware repository
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / commands.exp
1 # Copyright (C) 1988, 1990, 1991, 1992, 1997 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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.
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 if $tracelevel then {
21 strace $tracelevel
22 }
23
24 #
25 # test special commands (if, while, etc)
26 #
27 set prms_id 0
28 set bug_id 0
29
30 set testfile "run"
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."
35 }
36
37 gdb_exit
38 gdb_start
39 delete_breakpoints
40 gdb_reinitialize_dir $srcdir/$subdir
41 gdb_load ${binfile}
42
43 proc gdbvar_simple_if_test {} {
44 global gdb_prompt
45
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"
51 }
52
53 proc gdbvar_simple_while_test {} {
54 global gdb_prompt
55
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"
59 }
60
61 proc gdbvar_complex_if_while_test {} {
62 global gdb_prompt
63
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"
67 }
68
69 proc progvar_simple_if_test {} {
70 global gdb_prompt
71
72 if [target_info exists noargs] {
73 verbose "Skipping progvar_simple_if_test because of noargs."
74 return
75 }
76
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;
86 }
87
88 proc progvar_simple_while_test {} {
89 global gdb_prompt
90
91 if [target_info exists noargs] {
92 verbose "Skipping progvar_simple_while_test because of noargs."
93 return
94 }
95
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;
103 }
104
105 proc progvar_complex_if_while_test {} {
106 global gdb_prompt
107
108 if [target_info exists noargs] {
109 verbose "Skipping progvar_simple_if_while_test because of noargs."
110 return
111 }
112
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;
120 }
121
122 proc if_while_breakpoint_command_test {} {
123 if [target_info exists noargs] {
124 verbose "Skipping if_while_breakpoint_command_test because of noargs."
125 return
126 }
127
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"
132 delete_breakpoints
133 gdb_test "break factorial" "Breakpoint.*at.*" "break factorial #1"
134
135 send_gdb "commands\n"
136 gdb_expect {
137 -re "End with" {
138 pass "commands in if_while_breakpoint_command_test"
139 }
140 default {
141 fail "(timeout or eof) commands in if_while_breakpoint_command_test"
142 }
143 }
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;
149 }
150
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."
155 return
156 }
157
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"
162 delete_breakpoints
163 gdb_test "break factorial if value == 5" "Breakpoint.*at.*"
164
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"
170 gdb_expect {
171 -re "End with" {
172 pass "commands in infrun_breakpoint_command_test #1"
173 }
174 default {
175 fail "(timeout or eof) commands in infrun_breakpoint_command_test"
176 }
177 }
178 gdb_test "step\nstep\nstep\nstep\nbt\nend" "" \
179 "commands in infrun_breakpoint_command_test #2"
180
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;
195 }
196
197 proc breakpoint_command_test {} {
198 if [target_info exists noargs] {
199 verbose "Skipping breakpoint_command_test because of noargs."
200 return
201 }
202
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"
207 delete_breakpoints
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;
215 }
216
217 # Test a simple user defined command (with arguments)
218 proc user_defined_command_test {} {
219 global gdb_prompt
220
221 gdb_test "set \$foo = 4" "" "set foo in user_defined_command_test"
222
223 send_gdb "define mycommand\n"
224 gdb_expect {
225 -re "End with" {
226 pass "define mycommand in user_defined_command_test"
227 }
228 default {
229 fail "(timeout or eof) define mycommand in user_defined_command_test"
230 }
231 }
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"
234
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"
237 }
238
239 gdbvar_simple_if_test
240 gdbvar_simple_while_test
241 gdbvar_complex_if_while_test
242 progvar_simple_if_test
243 progvar_simple_while_test
244 progvar_complex_if_while_test
245 if_while_breakpoint_command_test
246 infrun_breakpoint_command_test
247 breakpoint_command_test
248 user_defined_command_test