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