]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/commands.exp
c49ec6c547d8749cfc73ae3b77694fc6398d326b
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / commands.exp
1 # Copyright (C) 1988, 1990, 1991, 1992 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
20 if $tracelevel then {
21 strace $tracelevel
22 }
23
24 #
25 # test special commands (if, while, etc)
26 #
27 set prms_id 0
28 set bug_id 0
29
30 set testfile "run"
31 set srcfile ${srcdir}/$subdir/${testfile}.c
32 set binfile ${objdir}/${subdir}/${testfile}
33 if { [compile "${srcfile} -g -o ${binfile}"] != "" } {
34 perror "Couldn't compile ${srcfile}"
35 return -1
36 }
37
38 gdb_exit
39 gdb_start
40 delete_breakpoints
41 gdb_reinitialize_dir $srcdir/$subdir
42 gdb_load ${binfile}
43
44 proc gdbvar_simple_if_test {} {
45 global prompt
46
47 gdb_test "set \$foo = 0" "" "set foo in gdbvar_simple_if_test"
48 # All this test should do is print 0xdeadbeef once.
49 gdb_test "if \$foo == 1\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" "\\\$\[0-9\]* = 0xdeadbeef" "gdbvar_simple_if_test #1"
50 # All this test should do is print 0xfeedface once.
51 gdb_test "if \$foo == 0\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" "\\\$\[0-9\]* = 0xfeedface" "gdbvar_simple_if_test #2"
52 }
53
54 proc gdbvar_simple_while_test {} {
55 global prompt
56
57 gdb_test "set \$foo = 5" "" "set foo in gdbvar_simple_while_test"
58 # This test should print 0xfeedface five times.
59 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"
60 }
61
62 proc gdbvar_complex_if_while_test {} {
63 global prompt
64
65 gdb_test "set \$foo = 4" "" "set foo in gdbvar complex_if_while_test"
66 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
67 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"
68 }
69
70 proc progvar_simple_if_test {} {
71 global prompt
72 global noargs
73
74 if $noargs {
75 verbose "Skipping progvar_simple_if_test because of noargs."
76 return
77 }
78
79 gdb_test "set args 5" "" "set args in progvar_simple_if_test"
80 if { ![runto factorial] } then { return }
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 }
86
87 proc progvar_simple_while_test {} {
88 global prompt
89 global noargs
90
91 if $noargs {
92 verbose "Skipping progvar_simple_while_test because of noargs."
93 return
94 }
95
96 gdb_test "set args 5" "" "set args in progvar_simple_while_test"
97 if { ![runto factorial] } then { return }
98 # This test should print 0xfeedface five times.
99 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"
100 }
101
102 proc progvar_complex_if_while_test {} {
103 global prompt
104 global noargs
105
106 if $noargs {
107 verbose "Skipping progvar_simple_if_while_test because of noargs."
108 return
109 }
110
111 gdb_test "set args 4" "" "set args in progvar_complex_if_while_test"
112 if { ![runto factorial] } then { return }
113 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
114 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"
115 }
116
117 proc if_while_breakpoint_command_test {} {
118 global noargs
119
120 if $noargs {
121 verbose "Skipping if_while_breakpoint_command_test because of noargs."
122 return
123 }
124
125 gdb_test "set args 5" "" "set args in if_while_breakpoint_command_test"
126 if { ![runto factorial] } then { return }
127 delete_breakpoints
128 gdb_test "break factorial" "Breakpoint.*at.*"
129
130 send "commands\n"
131 expect {
132 -re "End with" {
133 pass "commands in if_while_breakpoint_command_test"
134 }
135 default {
136 fail "(timeout or eof) commands in if_while_breakpoint_command_test"
137 }
138 }
139 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
140 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"
141 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"
142 gdb_test "info break" "while.*set.*if.*p/x.*else.*p/x.*end.*" "info break in if_while_breakpoint_command_test"
143 }
144
145 # Test that we can run the inferior from breakpoint commands.
146 proc infrun_breakpoint_command_test {} {
147 global noargs
148
149 if $noargs {
150 verbose "Skipping infrun_breakpoint_command_test because of noargs."
151 return
152 }
153
154 gdb_test "set args 6" "" "set args in progvar_simple_while_test"
155 if { ![runto factorial] } then { return }
156 delete_breakpoints
157 gdb_test "break factorial if value == 5" "Breakpoint.*at.*"
158 gdb_test "commands\nstep\nstep\nstep\nstep\nbt\nend" \
159 "End with.*" "commands in infrun_breakpoint_command_test"
160 gdb_test "continue" "Breakpoint \[0-9\]*, factorial \\(value=5\\).*at.*
161 \[0-9\]*\[ \]*if \\(value > 1\\) \{.*
162 \[0-9\]*\[ \]*value \\*= factorial \\(value - 1\\);.*
163 factorial \\(value=4\\) at.*\[0-9\]*\[ \]*if \\(value > 1\\) \{.*
164 \[0-9\]*\[ \]*value \\*= factorial \\(value - 1\\);.*
165 factorial \\(value=3\\) at .*
166 \[0-9\]*\[ \]*if \\(value > 1\\) \{.*
167 #0 factorial \\(value=3\\).*
168 #1 \[0-9a-fx\]* in factorial \\(value=4\\).*
169 #2 \[0-9a-fx\]* in factorial \\(value=5\\).*
170 #3 \[0-9a-fx\]* in factorial \\(value=6\\).*
171 #4 \[0-9a-fx\]* in main \\(.*\\).*" \
172 "continue in infrun_breakpoint_command_test"
173 }
174
175 proc breakpoint_command_test {} {
176 global noargs
177
178 if $noargs {
179 verbose "Skipping breakpoint_command_test because of noargs."
180 return
181 }
182
183 gdb_test "set args 6" "" "set args in progvar_simple_while_test"
184 if { ![runto factorial] } then { return }
185 delete_breakpoints
186 gdb_test "break factorial" "Breakpoint.*at.*"
187 gdb_test "commands\nprintf \"Now the value is %d\\n\", value\nend" \
188 "End with.*" "commands in breakpoint_command_test"
189 gdb_test "continue" "Breakpoint \[0-9\]*, factorial.*Now the value is 5" \
190 "continue in breakpoint_command_test"
191 gdb_test "print value" " = 5" "print value in breakpoint_command_test"
192 }
193
194 # Test a simple user defined command (with arguments)
195 proc user_defined_command_test {} {
196 global prompt
197
198 gdb_test "set \$foo = 4" "" "set foo in user_defined_command_test"
199
200 send "define mycommand\n"
201 expect {
202 -re "End with" {
203 pass "define mycommand in user_defined_command_test"
204 }
205 default {
206 fail "(timeout or eof) define mycommand in user_defined_command_test"
207 }
208 }
209 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
210 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"
211
212 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"
213 gdb_test "show user mycommand" "while.*set.*if.*p/x.*else.*p/x.*end.*" "display user command in user_defined_command_test"
214 }
215
216 gdbvar_simple_if_test
217 gdbvar_simple_while_test
218 gdbvar_complex_if_while_test
219 progvar_simple_if_test
220 progvar_simple_while_test
221 progvar_complex_if_while_test
222 if_while_breakpoint_command_test
223 infrun_breakpoint_command_test
224 breakpoint_command_test
225 user_defined_command_test