]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/commands.exp
import gdb-19990422 snapshot
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / commands.exp
CommitLineData
c906108c
SS
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
20if $tracelevel then {
21 strace $tracelevel
22}
23
24#
25# test special commands (if, while, etc)
26#
27set prms_id 0
28set bug_id 0
29
30set testfile "run"
31set srcfile ${testfile}.c
32set binfile ${objdir}/${subdir}/commands
33if { [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
37gdb_exit
38gdb_start
39delete_breakpoints
40gdb_reinitialize_dir $srcdir/$subdir
41gdb_load ${binfile}
42
43proc 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
53proc 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
61proc 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
69proc 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
88proc 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
105proc 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
122proc 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.
152proc 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\\);.*
184factorial \\(value=4\\) at.*\[0-9\]*\[ \]*if \\(value > 1\\) \{.*
185\[0-9\]*\[ \]*value \\*= factorial \\(value - 1\\);.*
186factorial \\(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
197proc 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)
218proc 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
7a292a7a
SS
239
240
241proc test_command_prompt_position {} {
242 global gdb_prompt
243
244 if [target_info exists noargs] {
245 verbose "Skipping test_command_prompt_position because of noargs."
246 return
247 }
248
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.
252 delete_breakpoints
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"
257
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.
260
261 send_gdb "commands\n"
262 gdb_expect {
263 -re "Type commands.*End with.*\[\r\n\]>$" \
264 { send_gdb "printf \"Now the value is %d\\n\", value\n"
265 gdb_expect {
266 -re "^printf.*value\r\n>$" \
267 { send_gdb "end\n"
268 gdb_expect {
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" }
272 }
273 }
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 " }
277 }
278 }
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" }
282 }
283
284 gdb_stop_suppressing_tests;
285}
286
287
c906108c
SS
288gdbvar_simple_if_test
289gdbvar_simple_while_test
290gdbvar_complex_if_while_test
291progvar_simple_if_test
292progvar_simple_while_test
293progvar_complex_if_while_test
294if_while_breakpoint_command_test
295infrun_breakpoint_command_test
296breakpoint_command_test
297user_defined_command_test
7a292a7a
SS
298test_command_prompt_position
299
300
301
302