]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/commands.exp
Updated copyright notices for most files.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / commands.exp
CommitLineData
b6ba6518 1# Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1997, 1998, 1999, 2000,
0fb0cc75
JB
2# 2001, 2002, 2003, 2005, 2006, 2007, 2008, 2009
3# Free Software Foundation, Inc.
c906108c
SS
4
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
e22f8b7c 7# the Free Software Foundation; either version 3 of the License, or
c906108c 8# (at your option) any later version.
e22f8b7c 9#
c906108c
SS
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
e22f8b7c 14#
c906108c 15# You should have received a copy of the GNU General Public License
e22f8b7c 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 17
c906108c
SS
18if $tracelevel then {
19 strace $tracelevel
20}
21
22#
23# test special commands (if, while, etc)
24#
25set prms_id 0
26set bug_id 0
27
28set testfile "run"
29set srcfile ${testfile}.c
30set binfile ${objdir}/${subdir}/commands
31if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
b60f0898
JB
32 untested commands.exp
33 return -1
c906108c
SS
34}
35
36gdb_exit
37gdb_start
38delete_breakpoints
39gdb_reinitialize_dir $srcdir/$subdir
40gdb_load ${binfile}
41
42proc gdbvar_simple_if_test {} {
43 global gdb_prompt
44
45 gdb_test "set \$foo = 0" "" "set foo in gdbvar_simple_if_test"
46 # All this test should do is print 0xdeadbeef once.
42f5c13f
MS
47 gdb_test "if \$foo == 1\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" \
48 "\\\$\[0-9\]* = 0xdeadbeef" "gdbvar_simple_if_test #1"
c906108c 49 # All this test should do is print 0xfeedface once.
42f5c13f
MS
50 gdb_test "if \$foo == 0\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" \
51 "\\\$\[0-9\]* = 0xfeedface" "gdbvar_simple_if_test #2"
c906108c
SS
52}
53
54proc gdbvar_simple_while_test {} {
55 global gdb_prompt
56
57 gdb_test "set \$foo = 5" "" "set foo in gdbvar_simple_while_test"
58 # This test should print 0xfeedface five times.
42f5c13f
MS
59 gdb_test "while \$foo > 0\np/x 0xfeedface\nset \$foo -= 1\nend" \
60 "\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" \
61 "gdbvar_simple_while_test #1"
c906108c
SS
62}
63
64proc gdbvar_complex_if_while_test {} {
65 global gdb_prompt
66
67 gdb_test "set \$foo = 4" "" "set foo in gdbvar complex_if_while_test"
68 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
42f5c13f
MS
69 gdb_test "while \$foo > 0\nset \$foo -= 1\nif \(\$foo % 2\) == 1\np/x 0xdeadbeef\nelse\np/x 0xfeedface\nend\nend" \
70 "\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" \
71 "gdbvar_complex_if_while_test #1"
c906108c
SS
72}
73
74proc progvar_simple_if_test {} {
75 global gdb_prompt
76
beb998c6 77 if [target_info exists noargs] {
c906108c
SS
78 verbose "Skipping progvar_simple_if_test because of noargs."
79 return
80 }
81
82 if { ![runto factorial] } then { gdb_suppress_tests; }
42f5c13f
MS
83 # Don't depend upon argument passing, since most simulators don't
84 # currently support it. Bash value variable to be what we want.
c906108c
SS
85 gdb_test "p value=5" "" "set value to 5 in progvar_simple_if_test #1"
86 # All this test should do is print 0xdeadbeef once.
42f5c13f
MS
87 gdb_test "if value == 1\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" \
88 "\\\$\[0-9\]* = 0xdeadbeef" \
89 "progvar_simple_if_test #1"
c906108c 90 # All this test should do is print 0xfeedface once.
42f5c13f
MS
91 gdb_test "if value == 5\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" \
92 "\\\$\[0-9\]* = 0xfeedface" \
93 "progvar_simple_if_test #2"
c906108c
SS
94 gdb_stop_suppressing_tests;
95}
96
97proc progvar_simple_while_test {} {
98 global gdb_prompt
99
beb998c6 100 if [target_info exists noargs] {
c906108c
SS
101 verbose "Skipping progvar_simple_while_test because of noargs."
102 return
103 }
104
085dd6e6 105 gdb_test "set args 5" "" "set args in progvar_simple_while_test"
c906108c 106 if { ![runto factorial] } then { gdb_suppress_tests }
42f5c13f
MS
107 # Don't depend upon argument passing, since most simulators don't
108 # currently support it. Bash value variable to be what we want.
c906108c
SS
109 gdb_test "p value=5" "" "set value to 5 in progvar_simple_if_test #2"
110 # This test should print 0xfeedface five times.
42f5c13f
MS
111 gdb_test "while value > 0\np/x 0xfeedface\nset value -= 1\nend" \
112 "\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" \
113 "progvar_simple_while_test #1"
c906108c
SS
114 gdb_stop_suppressing_tests;
115}
116
117proc progvar_complex_if_while_test {} {
118 global gdb_prompt
119
beb998c6 120 if [target_info exists noargs] {
c906108c
SS
121 verbose "Skipping progvar_simple_if_while_test because of noargs."
122 return
123 }
124
085dd6e6 125 gdb_test "set args 4" "" "set args in progvar_complex_if_while_test"
c906108c 126 if { ![runto factorial] } then { gdb_suppress_tests }
42f5c13f
MS
127 # Don't depend upon argument passing, since most simulators don't
128 # currently support it. Bash value variable to be what we want.
c906108c
SS
129 gdb_test "p value=4" "" "set value to 4 in progvar_simple_if_test"
130 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
42f5c13f
MS
131 gdb_test "while value > 0\nset value -= 1\nif \(value % 2\) == 1\np/x 0xdeadbeef\nelse\np/x 0xfeedface\nend\nend" \
132 "\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" \
133 "progvar_complex_if_while_test #1"
c906108c
SS
134 gdb_stop_suppressing_tests;
135}
136
137proc if_while_breakpoint_command_test {} {
beb998c6 138 if [target_info exists noargs] {
c906108c
SS
139 verbose "Skipping if_while_breakpoint_command_test because of noargs."
140 return
141 }
142
085dd6e6 143 gdb_test "set args 5" "" "set args in if_while_breakpoint_command_test"
c906108c 144 if { ![runto factorial] } then { gdb_suppress_tests }
42f5c13f
MS
145 # Don't depend upon argument passing, since most simulators don't
146 # currently support it. Bash value variable to be what we want.
c906108c
SS
147 gdb_test "p value=5" "" "set value to 5 in progvar_simple_if_test"
148 delete_breakpoints
149 gdb_test "break factorial" "Breakpoint.*at.*" "break factorial #1"
150
151 send_gdb "commands\n"
152 gdb_expect {
153 -re "End with" {
154 pass "commands in if_while_breakpoint_command_test"
155 }
156 default {
157 fail "(timeout or eof) commands in if_while_breakpoint_command_test"
158 }
159 }
160 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
42f5c13f
MS
161 gdb_test "while value > 0\nset value -= 1\nif \(value % 2\) == 1\np/x 0xdeadbeef\nelse\np/x 0xfeedface\nend\nend\nend" \
162 "" \
163 "commands part 2 in if_while_breakpoint_command_test"
164 gdb_test "continue" \
165 "\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" \
166 "if_while_breakpoint_command_test #1"
167 gdb_test "info break" \
168 "while.*set.*if.*p/x.*else.*p/x.*end.*" \
169 "info break in if_while_breakpoint_command_test"
c906108c
SS
170 gdb_stop_suppressing_tests;
171}
172
173# Test that we can run the inferior from breakpoint commands.
02aa71d5
MC
174#
175# The expected behavior is that all commands after the first "step"
176# shall be ignored. See the gdb manual, "Break Commands",
177# subsection "Breakpoint command lists".
178
c906108c 179proc infrun_breakpoint_command_test {} {
beb998c6 180 if [target_info exists noargs] {
c906108c
SS
181 verbose "Skipping infrun_breakpoint_command_test because of noargs."
182 return
183 }
184
7dbd117d 185 gdb_test "set args 6" "" "set args in infrun_breakpoint_command_test"
c906108c 186 if { ![runto factorial] } then { gdb_suppress_tests }
42f5c13f
MS
187 # Don't depend upon argument passing, since most simulators don't
188 # currently support it. Bash value variable to be what we want.
c906108c
SS
189 gdb_test "p value=6" "" "set value to 6 in progvar_simple_if_test #1"
190 delete_breakpoints
191 gdb_test "break factorial if value == 5" "Breakpoint.*at.*"
192
beb998c6 193# infrun_breakpoint_command_test - This test was broken into two parts
c906108c
SS
194# to get around a synchronization problem in expect.
195# part1: issue the gdb command "commands"
196# part2: send the list of commands
197 send_gdb "commands\n"
198 gdb_expect {
199 -re "End with" {
200 pass "commands in infrun_breakpoint_command_test #1"
201 }
202 default {
203 fail "(timeout or eof) commands in infrun_breakpoint_command_test"
204 }
205 }
02aa71d5 206 gdb_test "step\nstep\nstep\nstep\nend" "" \
c906108c 207 "commands in infrun_breakpoint_command_test #2"
085dd6e6 208
085dd6e6 209 gdb_test "continue" \
42f5c13f
MS
210 "Continuing.*.*.*Breakpoint \[0-9\]*, factorial \\(value=5\\).*at.*\[0-9\]*\[ \]*if \\(value > 1\\) \{.*\[0-9\]*\[ \]*value \\*= factorial \\(value - 1\\);.*" \
211 "continue in infrun_breakpoint_command_test"
085dd6e6 212
c906108c
SS
213 gdb_stop_suppressing_tests;
214}
215
216proc breakpoint_command_test {} {
beb998c6 217 if [target_info exists noargs] {
c906108c
SS
218 verbose "Skipping breakpoint_command_test because of noargs."
219 return
220 }
221
085dd6e6 222 gdb_test "set args 6" "" "set args in breakpoint_command_test"
c906108c 223 if { ![runto factorial] } then { gdb_suppress_tests; }
42f5c13f
MS
224 # Don't depend upon argument passing, since most simulators don't
225 # currently support it. Bash value variable to be what we want.
c906108c
SS
226 gdb_test "p value=6" "" "set value to 6 in progvar_simple_if_test #2"
227 delete_breakpoints
228 gdb_test "break factorial" "Breakpoint.*at.*" "break factorial #2"
229 gdb_test "commands\nprintf \"Now the value is %d\\n\", value\nend" \
085dd6e6 230 "End with.*" "commands in breakpoint_command_test"
42f5c13f
MS
231 gdb_test "continue" \
232 "Breakpoint \[0-9\]*, factorial.*Now the value is 5" \
c906108c
SS
233 "continue in breakpoint_command_test"
234 gdb_test "print value" " = 5" "print value in breakpoint_command_test"
235 gdb_stop_suppressing_tests;
236}
237
238# Test a simple user defined command (with arguments)
239proc user_defined_command_test {} {
240 global gdb_prompt
241
242 gdb_test "set \$foo = 4" "" "set foo in user_defined_command_test"
243
244 send_gdb "define mycommand\n"
245 gdb_expect {
246 -re "End with" {
247 pass "define mycommand in user_defined_command_test"
248 }
249 default {
250 fail "(timeout or eof) define mycommand in user_defined_command_test"
251 }
252 }
253 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
42f5c13f
MS
254 gdb_test "while \$arg0 > 0\nset \$arg0 -= 1\nif \(\$arg0 % 2\) == 1\np/x 0xdeadbeef\nelse\np/x 0xfeedface\nend\nend\nend" \
255 "" \
256 "enter commands in user_defined_command_test"
257
258 gdb_test "mycommand \$foo" \
259 "\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface\[^\n\]*\n\\\$\[0-9\]* = 0xdeadbeef\[^\n\]*\n\\\$\[0-9\]* = 0xfeedface" \
260 "execute user defined command in user_defined_command_test"
261 gdb_test "show user mycommand" \
e6ccd35f 262 " while \\\$arg0.*set.* if \\\(\\\$arg0.*p/x.* else\[^\n\].*p/x.* end\[^\n\].* end\[^\n\].*" \
42f5c13f 263 "display user command in user_defined_command_test"
c906108c
SS
264}
265
085dd6e6
JM
266proc watchpoint_command_test {} {
267 global noargs
268 global gdb_prompt
269
beb998c6 270 if [target_info exists noargs] {
085dd6e6
JM
271 verbose "Skipping watchpoint_command_test because of noargs."
272 return
273 }
274
bd5ddfe8
DJ
275 # Disable hardware watchpoints if necessary.
276 if [target_info exists gdb,no_hardware_watchpoints] {
277 gdb_test "set can-use-hw-watchpoints 0" "" ""
278 }
279
085dd6e6
JM
280 gdb_test "set args 6" "" "set args in watchpoint_command_test"
281 if { ![runto factorial] } then { return }
282 delete_breakpoints
283
284 # Verify that we can create a watchpoint, and give it a commands
285 # list that continues the inferior. We set the watchpoint on a
286 # local variable, too, so that it self-deletes when the watched
287 # data goes out of scope.
288 #
289 # What should happen is: Each time the watchpoint triggers, it
290 # continues the inferior. Eventually, the watchpoint will self-
291 # delete, when the watched variable is out of scope. But by that
292 # time, the inferior should have exited. GDB shouldn't crash or
293 # anything untoward as a result of this.
294 #
295 set wp_id -1
296
297 send_gdb "watch local_var\n"
298 gdb_expect {
299 -re ".*\[Ww\]atchpoint (\[0-9\]*): local_var.*$gdb_prompt $" {
300 set wp_id $expect_out(1,string)
301 pass "watch local_var"
302 }
303 -re "$gdb_prompt $"\
304 {fail "watch local_var"}
305 timeout {fail "(timeout) watch local_var"}
306 }
7a292a7a 307
085dd6e6
JM
308 if {$wp_id == -1} {return}
309
310 send_gdb "commands $wp_id\n"
311 gdb_expect {
42f5c13f
MS
312 -re "Type commands for when breakpoint $wp_id is hit, one per line.*>" {
313 pass "begin commands on watch"
314 }
315 -re "$gdb_prompt $" {fail "begin commands on watch"}
316 timeout {fail "(timeout) begin commands on watch"}
085dd6e6
JM
317 }
318 send_gdb "print value\n"
319 gdb_expect {
42f5c13f
MS
320 -re ">" {pass "add print command to watch"}
321 -re "$gdb_prompt $" {fail "add print command to watch"}
322 timeout {fail "(timeout) add print command to watch"}
085dd6e6
JM
323 }
324 send_gdb "continue\n"
325 gdb_expect {
42f5c13f
MS
326 -re ">" {pass "add continue command to watch"}
327 -re "$gdb_prompt $" {fail "add continue command to watch"}
328 timeout {fail "(timeout) add continue command to watch"}
085dd6e6
JM
329 }
330 send_gdb "end\n"
331 gdb_expect {
7dbd117d
MC
332 -re "$gdb_prompt $" {pass "end commands on watch"}
333 timeout {fail "(timeout) end commands on watch"}
085dd6e6
JM
334 }
335 send_gdb "continue\n"
336 gdb_expect {
384e1a61 337 -re "Continuing.*\[Ww\]atchpoint $wp_id deleted because the program has left the block in.*which its expression is valid.*run.c:(57|82).*$gdb_prompt $" {
42f5c13f
MS
338 pass "continue with watch"
339 }
340 -re "$gdb_prompt $" {fail "continue with watch"}
341 timeout {fail "(timeout) continue with watch"}
085dd6e6
JM
342 }
343}
7a292a7a
SS
344
345proc test_command_prompt_position {} {
346 global gdb_prompt
347
beb998c6 348 if [target_info exists noargs] {
7a292a7a
SS
349 verbose "Skipping test_command_prompt_position because of noargs."
350 return
351 }
352
353 if { ![runto factorial] } then { gdb_suppress_tests; }
42f5c13f
MS
354 # Don't depend upon argument passing, since most simulators don't
355 # currently support it. Bash value variable to be what we want.
7a292a7a 356 delete_breakpoints
7dbd117d 357 gdb_test "break factorial" "Breakpoint.*at.*" "break factorial #3"
7a292a7a
SS
358 gdb_test "p value=5" "" "set value to 5 in test_command_prompt_position"
359 # All this test should do is print 0xdeadbeef once.
42f5c13f
MS
360 gdb_test "if value == 1\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" \
361 "\\\$\[0-9\]* = 0xdeadbeef" \
362 "if test in test_command_prompt_position"
363
364 # Now let's test for the correct position of the '>' in gdb's
365 # prompt for commands. It should be at the beginning of the line,
366 # and not after one space.
7a292a7a
SS
367
368 send_gdb "commands\n"
369 gdb_expect {
42f5c13f
MS
370 -re "Type commands.*End with.*\[\r\n\]>$" {
371 send_gdb "printf \"Now the value is %d\\n\", value\n"
372 gdb_expect {
373 -re "^printf.*value\r\n>$" {
374 send_gdb "end\n"
375 gdb_expect {
376 -re "^end\r\n$gdb_prompt $" {
377 pass "> OK in test_command_prompt_position"
378 }
379 -re ".*$gdb_prompt $" {
380 fail "some other message in test_command_prompt_position"
381 }
382 timeout {
383 fail "(timeout) 1 in test_command_prompt_position"
384 }
385 }
386 }
387 -re "^ >$" { fail "> not OK in test_command_prompt_position" }
388 -re ".*$gdb_prompt $" {
389 fail "wrong message in test_command_prompt_position"
390 }
391 timeout {
392 fail "(timeout) 2 in test_command_prompt_position "
393 }
394 }
395 }
396 -re "Type commands.*End with.*\[\r\n\] >$" {
397 fail "prompt not OK in test_command_prompt_position"
398 }
399 -re ".*$gdb_prompt $" {
400 fail "commands in test_command_prompt_position"
7a292a7a 401 }
42f5c13f
MS
402 timeout { fail "(timeout) 3 commands in test_command_prompt_position" }
403 }
7a292a7a
SS
404
405 gdb_stop_suppressing_tests;
406}
407
408
003ba290
FN
409
410proc deprecated_command_test {} {
003ba290 411 gdb_test "maintenance deprecate blah" "Can't find command.*" \
7dbd117d 412 "tried to deprecate non-existing command"
003ba290 413
7dbd117d 414 gdb_test "maintenance deprecate p \"new_p\"" "" "maintenance deprecate p \"new_p\" /1/"
42f5c13f
MS
415 gdb_test "p 5" \
416 "Warning: 'p', an alias for the command 'print' is deprecated.*Use 'new_p'.*" \
417 "p deprecated warning, with replacement"
7dbd117d 418 gdb_test "p 5" ".\[0-9\]* = 5.*" "Deprecated warning goes away /1/"
003ba290 419
7dbd117d 420 gdb_test "maintenance deprecate p \"new_p\"" "" "maintenance deprecate p \"new_p\" /2/"
003ba290 421 gdb_test "maintenance deprecate print \"new_print\"" ""
42f5c13f
MS
422 gdb_test "p 5" \
423 "Warning: command 'print' \\(p\\) is deprecated.*Use 'new_print'.*" \
424 "both alias and command are deprecated"
7dbd117d 425 gdb_test "p 5" ".\[0-9\]* = 5.*" "Deprecated warning goes away /2/"
003ba290 426
42f5c13f
MS
427 gdb_test "maintenance deprecate set remote memory-read-packet-size \"srm\" " \
428 "" \
7dbd117d 429 "deprecate long command /1/"
42f5c13f
MS
430 gdb_test "set remote memory-read-packet-size" \
431 "Warning: command 'set remote memory-read-packet-size' is deprecated.*Use 'srm'.*" \
7dbd117d 432 "long command deprecated /1/"
42f5c13f
MS
433
434 gdb_test "maintenance deprecate set remote memory-read-packet-size" \
435 "" \
7dbd117d 436 "deprecate long command /2/"
42f5c13f
MS
437 gdb_test "set remote memory-read-packet-size" \
438 "Warning: command 'set remote memory-read-packet-size' is deprecated.*No alternative known.*" \
7dbd117d 439 "long command deprecated with no alternative /2/"
42f5c13f
MS
440
441 gdb_test "maintenance deprecate" \
442 "\"maintenance deprecate\".*" \
443 "deprecate with no arguments"
003ba290
FN
444}
445
c2b8ed2c
MS
446proc bp_deleted_in_command_test {} {
447 global gdb_prompt
448
c9d37158
DJ
449 if [target_info exists noargs] {
450 verbose "Skipping bp_deleted_in_command_test because of noargs."
451 return
452 }
453
c2b8ed2c
MS
454 gdb_test "set args 1" "" "set args in bp_deleted_in_command_test"
455 delete_breakpoints
456
457 # Create a breakpoint, and associate a command-list to it, with
458 # one command that deletes this breakpoint.
459 gdb_test "break factorial" \
460 "Breakpoint \[0-9\]+ at .*: file .*/run.c, line \[0-9\]+\." \
461 "breakpoint in bp_deleted_in_command_test"
462
463 send_gdb "commands\n"
464 gdb_expect {
465 -re "Type commands for when breakpoint .* is hit, one per line.*>" {
466 pass "begin commands in bp_deleted_in_command_test"
467 }
468 -re "$gdb_prompt $" {fail "begin commands in bp_deleted_in_command_test"}
469 timeout {fail "(timeout) begin commands bp_deleted_in_command_test"}
470 }
471 send_gdb "silent\n"
472 gdb_expect {
473 -re ">" {pass "add silent command"}
474 -re "$gdb_prompt $" {fail "add silent command"}
475 timeout {fail "(timeout) add silent command"}
476 }
477 send_gdb "clear factorial\n"
478 gdb_expect {
479 -re ">" {pass "add clear command"}
480 -re "$gdb_prompt $" {fail "add clear command"}
481 timeout {fail "(timeout) add clear command"} }
482 send_gdb "printf \"factorial command-list executed\\n\"\n"
483 gdb_expect {
484 -re ">" {pass "add printf command"}
485 -re "$gdb_prompt $" {fail "add printf command"}
486 timeout {fail "(timeout) add printf command"}
487 }
488 send_gdb "cont\n"
489 gdb_expect {
490 -re ">" {pass "add cont command"}
491 -re "$gdb_prompt $" {fail "add cont command"}
492 timeout {fail "(timeout) add cont command"} }
493 send_gdb "end\n"
494 gdb_expect {
495 -re "$gdb_prompt $" {pass "end commands"}
496 timeout {fail "(timeout) end commands"}
497 }
003ba290 498
c2b8ed2c
MS
499 gdb_run_cmd
500 gdb_expect {
b2b4a1b5 501 -re ".*factorial command-list executed.*1.*$gdb_prompt $" {
c2b8ed2c
MS
502 pass "run factorial until breakpoint"
503 }
504 -re ".*$gdb_prompt $" {
505 fail "run factorial until breakpoint"
506 }
507 default { fail "(timeout) run factorial until breakpoint" }
508 timeout { fail "(timeout) run factorial until breakpoint" }
509 }
510}
511
512proc temporary_breakpoint_commands {} {
513 global gdb_prompt
514
c9d37158
DJ
515 if [target_info exists noargs] {
516 verbose "Skipping temporary_breakpoint_commands because of noargs."
517 return
518 }
519
c2b8ed2c
MS
520 gdb_test "set args 1" "" "set args in temporary_breakpoint_commands"
521 delete_breakpoints
522
523 # Create a temporary breakpoint, and associate a commands list to it.
524 # This test will verify that this commands list is executed when the
525 # breakpoint is hit.
526 gdb_test "tbreak factorial" \
18ac113b 527 "Temporary breakpoint \[0-9\]+ at .*: file .*/run.c, line \[0-9\]+\." \
c2b8ed2c
MS
528 "breakpoint in temporary_breakpoint_commands"
529
530 send_gdb "commands\n"
531 gdb_expect {
532 -re "Type commands for when breakpoint .* is hit, one per line.*>" {
533 pass "begin commands in bp_deleted_in_command_test"
534 }
535 -re "$gdb_prompt $" {fail "begin commands in bp_deleted_in_command_test"}
536 timeout {fail "(timeout) begin commands bp_deleted_in_command_test"}
537 }
538 send_gdb "silent\n"
539 gdb_expect {
540 -re ">" {pass "add silent tbreak command"}
541 -re "$gdb_prompt $" {fail "add silent tbreak command"}
542 timeout {fail "(timeout) add silent tbreak command"}
543 }
544 send_gdb "printf \"factorial tbreak commands executed\\n\"\n"
545 gdb_expect {
546 -re ">" {pass "add printf tbreak command"}
547 -re "$gdb_prompt $" {fail "add printf tbreak command"}
548 timeout {fail "(timeout) add printf tbreak command"}
549 }
550 send_gdb "cont\n"
551 gdb_expect {
552 -re ">" {pass "add cont tbreak command"}
553 -re "$gdb_prompt $" {fail "add cont tbreak command"}
554 timeout {fail "(timeout) add cont tbreak command"} }
555 send_gdb "end\n"
556 gdb_expect {
557 -re "$gdb_prompt $" {pass "end tbreak commands"}
558 timeout {fail "(timeout) end tbreak commands"}
559 }
560
561 gdb_run_cmd
562 gdb_expect {
b2b4a1b5 563 -re ".*factorial tbreak commands executed.*1.*$gdb_prompt $" {
c2b8ed2c
MS
564 pass "run factorial until temporary breakpoint"
565 }
566 timeout { fail "(timeout) run factorial until temporary breakpoint" }
567 }
568}
61d9b92f
DJ
569
570# Test that GDB can handle $arg0 outside of user functions without
571# crashing.
572proc stray_arg0_test { } {
573 gdb_test "print \$arg0" \
574 "\\\$\[0-9\]* = void" \
575 "stray_arg0_test #1"
576
577 gdb_test "if 1 == 1\nprint \$arg0\nend" \
578 "\\\$\[0-9\]* = void" \
579 "stray_arg0_test #2"
580
581 gdb_test "print \$arg0 = 1" \
582 "\\\$\[0-9\]* = 1" \
583 "stray_arg0_test #3"
584
585 gdb_test "print \$arg0" \
586 "\\\$\[0-9\]* = 1" \
587 "stray_arg0_test #4"
588}
e28493f2
AS
589
590# Test that GDB can handle arguments when sourcing files recursively.
591# If the arguments are overwritten with ####### then the test has failed.
592proc recursive_source_test {} {
593 set fd [open "file1" w]
594 puts $fd \
595{source file2
596abcdef qwerty}
597 close $fd
598
599 set fd [open "file2" w]
600 puts $fd \
601{define abcdef
602 echo 1: <<<$arg0>>>\n
603 source file3
604 echo 2: <<<$arg0>>>\n
605end}
606 close $fd
607
608 set fd [open "file3" w]
609 puts $fd \
610"echo in file3\\n
611#################################################################"
612 close $fd
613
614 gdb_test "source file1" \
615 "1: <<<qwerty>>>\[\r\n]+in file3\[\r\n]+2: <<<qwerty>>>" \
616 "recursive source test"
617
618 file delete file1
619 file delete file2
620 file delete file3
621}
622
704a4f78
DJ
623proc gdb_test_no_prompt { command result msg } {
624 global gdb_prompt
625
626 set msg "$command - $msg"
627 set result "^[string_to_regexp $command]\r\n$result$"
628 gdb_test_multiple $command $msg {
629 -re "$result" {
630 pass $msg
631 return 1
632 }
633 -re "\r\n *>$" {
634 fail $msg
635 return 0
636 }
637 }
638 return 0
639}
640
641proc if_commands_test {} {
642 global gdb_prompt
643
644 gdb_test "set \$tem = 1" "" "set \$tem in if_commands_test"
645
646 set test "if_commands_test 1"
647 gdb_test_no_prompt "if \$tem == 2" { >} $test
648 gdb_test_no_prompt "break main" { >} $test
649 gdb_test_no_prompt "else" { >} $test
650 gdb_test_no_prompt "break factorial" { >} $test
651 gdb_test_no_prompt "commands" { >} $test
652 gdb_test_no_prompt "silent" { >} $test
653 gdb_test_no_prompt "set \$tem = 3" { >} $test
654 gdb_test_no_prompt "continue" { >} $test
655 gdb_test_multiple "end" "first end - $test" {
656 -re " >\$" {
657 pass "first end - $test"
658 }
659 -re "\r\n>\$" {
660 fail "first end - $test"
661 }
662 }
663 gdb_test_multiple "end" "second end - $test" {
664 -re "Breakpoint \[0-9\]+ at .*: file .*/run.c, line \[0-9\]+\.\r\n$gdb_prompt $" {
665 pass "second end - $test"
666 }
667 -re "Undefined command: \"silent\".*$gdb_prompt $" {
668 fail "second end - $test"
669 }
670 }
671
672 set test "if_commands_test 2"
673 gdb_test_no_prompt "if \$tem == 1" { >} $test
674 gdb_test_no_prompt "break main" { >} $test
675 gdb_test_no_prompt "else" { >} $test
676 gdb_test_no_prompt "break factorial" { >} $test
677 gdb_test_no_prompt "commands" { >} $test
678 gdb_test_no_prompt "silent" { >} $test
679 gdb_test_no_prompt "set \$tem = 3" { >} $test
680 gdb_test_no_prompt "continue" { >} $test
681 gdb_test_multiple "end" "first end - $test" {
682 -re " >\$" {
683 pass "first end - $test"
684 }
685 -re "\r\n>\$" {
686 fail "first end - $test"
687 }
688 }
689 gdb_test_multiple "end" "second end - $test" {
690 -re "Breakpoint \[0-9\]+ at .*: file .*/run.c, line \[0-9\]+\.\r\n$gdb_prompt $" {
691 pass "second end - $test"
692 }
693 }
694}
695
fad6eecd
TT
696proc redefine_hook_test {} {
697 global gdb_prompt
698
699 gdb_test "define one\nend" \
700 "" \
701 "define one"
702
703 gdb_test "define hook-one\necho hibob\\n\nend" \
704 "" \
705 "define hook-one"
706
707 gdb_test_multiple "define one" "redefine one" {
708 -re "Redefine command .one.. .y or n. $" {
709 send_gdb "y\n"
710 exp_continue
711 }
712
713 -re "End with" {
714 pass "define one in redefine_hook_test"
715 }
716 default {
717 fail "(timeout or eof) define one in redefine_hook_test"
718 }
719 }
720
721 gdb_test "end" \
722 "" \
723 "enter commands for one redefinition in redefine_hook_test"
724
725 gdb_test "one" \
726 "hibob" \
727 "execute one command in redefine_hook_test"
728}
729
b05dcbb7
TT
730proc redefine_backtrace_test {} {
731 global gdb_prompt
732
733 gdb_test_multiple "define backtrace" "define backtrace" {
734 -re "Really redefine built-in.*$" {
735 send_gdb "y\n"
736 exp_continue
737 }
738
739 -re "End with" {
740 pass "define backtrace in redefine_backtrace_test"
741 }
742 default {
743 fail "(timeout or eof) define backtrace in redefine_backtrace_test"
744 }
745 }
746 gdb_test "echo hibob\\n\nend" \
747 "" \
748 "enter commands in redefine_backtrace_test"
749
750 gdb_test "backtrace" \
751 "hibob" \
752 "execute backtrace command in redefine_backtrace_test"
753 gdb_test "bt" \
754 "hibob" \
755 "execute bt command in redefine_backtrace_test"
756}
757
c906108c
SS
758gdbvar_simple_if_test
759gdbvar_simple_while_test
760gdbvar_complex_if_while_test
761progvar_simple_if_test
762progvar_simple_while_test
763progvar_complex_if_while_test
764if_while_breakpoint_command_test
765infrun_breakpoint_command_test
766breakpoint_command_test
767user_defined_command_test
085dd6e6 768watchpoint_command_test
7a292a7a 769test_command_prompt_position
003ba290 770deprecated_command_test
c2b8ed2c
MS
771bp_deleted_in_command_test
772temporary_breakpoint_commands
61d9b92f 773stray_arg0_test
e28493f2 774recursive_source_test
704a4f78 775if_commands_test
fad6eecd 776redefine_hook_test
b05dcbb7
TT
777# This one should come last, as it redefines "backtrace".
778redefine_backtrace_test