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