1 # Copyright (C) 1988, 1990, 1991, 1992 Free Software Foundation, Inc.
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.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
25 # test special commands (if, while, etc)
32 if ![file exists $objdir/$subdir/$binfile] then {
33 perror "$objdir/$subdir/$binfile does not exist."
38 gdb_reinitialize_dir $srcdir/$subdir
39 gdb_load $objdir/$subdir/$binfile
41 proc gdbvar_simple_if_test {} {
44 gdb_test "set \\\$foo = 0"
45 # All this test should do is print 0xdeadbeef once.
46 gdb_test "if \\\$foo == 1\\np/x 0xfeedface\\nelse\\np/x 0xdeadbeef\\nend" "\\\$\[0-9\]* = 0xdeadbeef" "gdbvar_simple_if_test #1"
47 # All this test should do is print 0xfeedface once.
48 gdb_test "if \\\$foo == 0\\np/x 0xfeedface\\nelse\\np/x 0xdeadbeef\\nend" "\\\$\[0-9\]* = 0xfeedface" "gdbvar_simple_if_test #2"
51 proc gdbvar_simple_while_test {} {
54 gdb_test "set \\\$foo = 5"
55 # This test should print 0xfeedface five times.
56 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 proc gdbvar_complex_if_while_test {} {
62 gdb_test "set \\\$foo = 4"
63 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
64 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 proc progvar_simple_if_test {} {
71 if { ![runto factorial] } then { return }
72 # All this test should do is print 0xdeadbeef once.
73 gdb_test "if value == 1\\np/x 0xfeedface\\nelse\\np/x 0xdeadbeef\\nend" "\\\$\[0-9\]* = 0xdeadbeef" "progvar_simple_if_test #1"
74 # All this test should do is print 0xfeedface once.
75 gdb_test "if value == 5\\np/x 0xfeedface\\nelse\\np/x 0xdeadbeef\\nend" "\\\$\[0-9\]* = 0xfeedface" "progvar_simple_if_test #2"
78 proc progvar_simple_while_test {} {
82 if { ![runto factorial] } then { return }
83 # This test should print 0xfeedface five times.
84 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"
87 proc progvar_complex_if_while_test {} {
91 if { ![runto factorial] } then { return }
92 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
93 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"
96 proc if_while_breakpoint_command_test {} {
100 if { ![runto factorial] } then { return }
102 gdb_test "break factorial" "Breakpoint.*at"
103 # For some stupid reason doing this with a gdb_test timed out. Weird.
107 default { fail "(timeout or eof) commands" }
109 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
110 gdb_test "while value > 0\\nset value -= 1\\nif \(value % 2\) == 1\\np/x 0xdeadbeef\\nelse\\np/x 0xfeedface\\nend\\nend\\nend\\n" ".*$prompt.*" "commands"
111 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"
112 gdb_test "info break" "while.*set.*if.*p/x.*else.*p/x.*end.*" "info break"
115 # Test a simple user defined command (with arguments)
116 proc user_defined_command_test {} {
119 gdb_test "set \\\$foo = 4"
120 # For some stupid reason doing this with a gdb_test timed out. Weird.
121 send "define mycommand\n"
124 default { fail "(timeout or eof) enter user defined command" }
126 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
127 gdb_test "while \\\$arg0 > 0\\nset \\\$arg0 -= 1\\nif \(\\\$arg0 % 2\) == 1\\np/x 0xdeadbeef\\nelse\\np/x 0xfeedface\\nend\\nend\\nend\\n" ".*$prompt.*" "enter user defined command"
129 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"
130 gdb_test "show user mycommand" "while.*set.*if.*p/x.*else.*p/x.*end.*" "display user command"
133 gdbvar_simple_if_test
134 gdbvar_simple_while_test
135 gdbvar_complex_if_while_test
136 progvar_simple_if_test
137 progvar_simple_while_test
138 progvar_complex_if_while_test
139 if_while_breakpoint_command_test
140 user_defined_command_test