Commit | Line | Data |
---|---|---|
c906108c SS |
1 | # Copyright (C) 1988, 1990, 1991, 1992, 1997 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 ${testfile}.c | |
32 | set binfile ${objdir}/${subdir}/commands | |
33 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } { | |
34 | gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." | |
35 | } | |
36 | ||
37 | gdb_exit | |
38 | gdb_start | |
39 | delete_breakpoints | |
40 | gdb_reinitialize_dir $srcdir/$subdir | |
41 | gdb_load ${binfile} | |
42 | ||
43 | proc gdbvar_simple_if_test {} { | |
44 | global gdb_prompt | |
45 | ||
46 | gdb_test "set \$foo = 0" "" "set foo in gdbvar_simple_if_test" | |
47 | # All this test should do is print 0xdeadbeef once. | |
48 | gdb_test "if \$foo == 1\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" "\\\$\[0-9\]* = 0xdeadbeef" "gdbvar_simple_if_test #1" | |
49 | # All this test should do is print 0xfeedface once. | |
50 | gdb_test "if \$foo == 0\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" "\\\$\[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" "\\\$\[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 | } | |
60 | ||
61 | proc gdbvar_complex_if_while_test {} { | |
62 | global gdb_prompt | |
63 | ||
64 | gdb_test "set \$foo = 4" "" "set foo in gdbvar complex_if_while_test" | |
65 | # This test should alternate between 0xdeadbeef and 0xfeedface two times. | |
66 | 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 | } | |
68 | ||
69 | proc progvar_simple_if_test {} { | |
70 | global gdb_prompt | |
71 | ||
72 | if [target_info exists noargs] { | |
73 | verbose "Skipping progvar_simple_if_test because of noargs." | |
74 | return | |
75 | } | |
76 | ||
77 | if { ![runto factorial] } then { gdb_suppress_tests; } | |
78 | # Don't depend upon argument passing, since most simulators don't currently | |
79 | # support it. Bash value variable to be what we want. | |
80 | gdb_test "p value=5" "" "set value to 5 in progvar_simple_if_test #1" | |
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 | gdb_stop_suppressing_tests; | |
86 | } | |
87 | ||
88 | proc progvar_simple_while_test {} { | |
89 | global gdb_prompt | |
90 | ||
91 | if [target_info exists noargs] { | |
92 | verbose "Skipping progvar_simple_while_test because of noargs." | |
93 | return | |
94 | } | |
95 | ||
085dd6e6 | 96 | gdb_test "set args 5" "" "set args in progvar_simple_while_test" |
c906108c SS |
97 | if { ![runto factorial] } then { gdb_suppress_tests } |
98 | # Don't depend upon argument passing, since most simulators don't currently | |
99 | # support it. Bash value variable to be what we want. | |
100 | gdb_test "p value=5" "" "set value to 5 in progvar_simple_if_test #2" | |
101 | # This test should print 0xfeedface five times. | |
102 | 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" | |
103 | gdb_stop_suppressing_tests; | |
104 | } | |
105 | ||
106 | proc progvar_complex_if_while_test {} { | |
107 | global gdb_prompt | |
108 | ||
109 | if [target_info exists noargs] { | |
110 | verbose "Skipping progvar_simple_if_while_test because of noargs." | |
111 | return | |
112 | } | |
113 | ||
085dd6e6 | 114 | gdb_test "set args 4" "" "set args in progvar_complex_if_while_test" |
c906108c SS |
115 | if { ![runto factorial] } then { gdb_suppress_tests } |
116 | # Don't depend upon argument passing, since most simulators don't currently | |
117 | # support it. Bash value variable to be what we want. | |
118 | gdb_test "p value=4" "" "set value to 4 in progvar_simple_if_test" | |
119 | # This test should alternate between 0xdeadbeef and 0xfeedface two times. | |
120 | 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" | |
121 | gdb_stop_suppressing_tests; | |
122 | } | |
123 | ||
124 | proc if_while_breakpoint_command_test {} { | |
125 | if [target_info exists noargs] { | |
126 | verbose "Skipping if_while_breakpoint_command_test because of noargs." | |
127 | return | |
128 | } | |
129 | ||
085dd6e6 | 130 | gdb_test "set args 5" "" "set args in if_while_breakpoint_command_test" |
c906108c SS |
131 | if { ![runto factorial] } then { gdb_suppress_tests } |
132 | # Don't depend upon argument passing, since most simulators don't currently | |
133 | # support it. Bash value variable to be what we want. | |
134 | gdb_test "p value=5" "" "set value to 5 in progvar_simple_if_test" | |
135 | delete_breakpoints | |
136 | gdb_test "break factorial" "Breakpoint.*at.*" "break factorial #1" | |
137 | ||
138 | send_gdb "commands\n" | |
139 | gdb_expect { | |
140 | -re "End with" { | |
141 | pass "commands in if_while_breakpoint_command_test" | |
142 | } | |
143 | default { | |
144 | fail "(timeout or eof) commands in if_while_breakpoint_command_test" | |
145 | } | |
146 | } | |
147 | # This test should alternate between 0xdeadbeef and 0xfeedface two times. | |
148 | 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" | |
149 | 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" | |
150 | gdb_test "info break" "while.*set.*if.*p/x.*else.*p/x.*end.*" "info break in if_while_breakpoint_command_test" | |
151 | gdb_stop_suppressing_tests; | |
152 | } | |
153 | ||
154 | # Test that we can run the inferior from breakpoint commands. | |
155 | proc infrun_breakpoint_command_test {} { | |
156 | if [target_info exists noargs] { | |
157 | verbose "Skipping infrun_breakpoint_command_test because of noargs." | |
158 | return | |
159 | } | |
160 | ||
085dd6e6 | 161 | gdb_test "set args 6" "" "set args in progvar_simple_while_test" |
c906108c SS |
162 | if { ![runto factorial] } then { gdb_suppress_tests } |
163 | # Don't depend upon argument passing, since most simulators don't currently | |
164 | # support it. Bash value variable to be what we want. | |
165 | gdb_test "p value=6" "" "set value to 6 in progvar_simple_if_test #1" | |
166 | delete_breakpoints | |
167 | gdb_test "break factorial if value == 5" "Breakpoint.*at.*" | |
168 | ||
169 | # infrun_breakpoint_command_test - This test was broken into two parts | |
170 | # to get around a synchronization problem in expect. | |
171 | # part1: issue the gdb command "commands" | |
172 | # part2: send the list of commands | |
173 | send_gdb "commands\n" | |
174 | gdb_expect { | |
175 | -re "End with" { | |
176 | pass "commands in infrun_breakpoint_command_test #1" | |
177 | } | |
178 | default { | |
179 | fail "(timeout or eof) commands in infrun_breakpoint_command_test" | |
180 | } | |
181 | } | |
182 | gdb_test "step\nstep\nstep\nstep\nbt\nend" "" \ | |
183 | "commands in infrun_breakpoint_command_test #2" | |
085dd6e6 JM |
184 | |
185 | if { [istarget "hppa*-hp-hpux*"] } { | |
186 | gdb_test "continue" \ | |
187 | "Continuing.*.*.*Breakpoint \[0-9\]*, factorial \\(value=5\\).*at.*\[0-9\]*\[ \]*if \\(value > 1\\) \{.*\[0-9\]*\[ \]*value \\*= factorial \\(value - 1\\);.*" \ | |
188 | "contiune in infrun_breakpoint_command_test" | |
189 | } else { | |
190 | gdb_test "continue" \ | |
191 | "Breakpoint \[0-9\]*, factorial \\(value=5\\).*at.* | |
c906108c SS |
192 | \[0-9\]*\[ \]*if \\(value > 1\\) \{.* |
193 | \[0-9\]*\[ \]*value \\*= factorial \\(value - 1\\);.* | |
194 | factorial \\(value=4\\) at.*\[0-9\]*\[ \]*if \\(value > 1\\) \{.* | |
195 | \[0-9\]*\[ \]*value \\*= factorial \\(value - 1\\);.* | |
196 | factorial \\(value=3\\) at .* | |
197 | \[0-9\]*\[ \]*if \\(value > 1\\) \{.* | |
198 | #0 factorial \\(value=3\\).* | |
199 | #1 \[0-9a-fx\]* in factorial \\(value=4\\).* | |
200 | #2 \[0-9a-fx\]* in factorial \\(value=5\\).* | |
201 | #3 \[0-9a-fx\]* in factorial \\(value=6\\).* | |
202 | #4 \[0-9a-fx\]* in main \\(.*\\).*" \ | |
085dd6e6 JM |
203 | "continue in infrun_breakpoint_command_test"; |
204 | } | |
205 | ||
c906108c SS |
206 | gdb_stop_suppressing_tests; |
207 | } | |
208 | ||
209 | proc breakpoint_command_test {} { | |
210 | if [target_info exists noargs] { | |
211 | verbose "Skipping breakpoint_command_test because of noargs." | |
212 | return | |
213 | } | |
214 | ||
085dd6e6 | 215 | gdb_test "set args 6" "" "set args in breakpoint_command_test" |
c906108c SS |
216 | if { ![runto factorial] } then { gdb_suppress_tests; } |
217 | # Don't depend upon argument passing, since most simulators don't currently | |
218 | # support it. Bash value variable to be what we want. | |
219 | gdb_test "p value=6" "" "set value to 6 in progvar_simple_if_test #2" | |
220 | delete_breakpoints | |
221 | gdb_test "break factorial" "Breakpoint.*at.*" "break factorial #2" | |
222 | gdb_test "commands\nprintf \"Now the value is %d\\n\", value\nend" \ | |
085dd6e6 | 223 | "End with.*" "commands in breakpoint_command_test" |
c906108c SS |
224 | gdb_test "continue" "Breakpoint \[0-9\]*, factorial.*Now the value is 5" \ |
225 | "continue in breakpoint_command_test" | |
226 | gdb_test "print value" " = 5" "print value in breakpoint_command_test" | |
227 | gdb_stop_suppressing_tests; | |
228 | } | |
229 | ||
230 | # Test a simple user defined command (with arguments) | |
231 | proc user_defined_command_test {} { | |
232 | global gdb_prompt | |
233 | ||
234 | gdb_test "set \$foo = 4" "" "set foo in user_defined_command_test" | |
235 | ||
236 | send_gdb "define mycommand\n" | |
237 | gdb_expect { | |
238 | -re "End with" { | |
239 | pass "define mycommand in user_defined_command_test" | |
240 | } | |
241 | default { | |
242 | fail "(timeout or eof) define mycommand in user_defined_command_test" | |
243 | } | |
244 | } | |
245 | # This test should alternate between 0xdeadbeef and 0xfeedface two times. | |
246 | 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" | |
247 | ||
248 | 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" | |
249 | gdb_test "show user mycommand" "while.*set.*if.*p/x.*else.*p/x.*end.*" "display user command in user_defined_command_test" | |
250 | } | |
251 | ||
085dd6e6 JM |
252 | proc watchpoint_command_test {} { |
253 | global noargs | |
254 | global gdb_prompt | |
255 | ||
256 | if [target_info exists noargs] { | |
257 | verbose "Skipping watchpoint_command_test because of noargs." | |
258 | return | |
259 | } | |
260 | ||
261 | gdb_test "set args 6" "" "set args in watchpoint_command_test" | |
262 | if { ![runto factorial] } then { return } | |
263 | delete_breakpoints | |
264 | ||
265 | # Verify that we can create a watchpoint, and give it a commands | |
266 | # list that continues the inferior. We set the watchpoint on a | |
267 | # local variable, too, so that it self-deletes when the watched | |
268 | # data goes out of scope. | |
269 | # | |
270 | # What should happen is: Each time the watchpoint triggers, it | |
271 | # continues the inferior. Eventually, the watchpoint will self- | |
272 | # delete, when the watched variable is out of scope. But by that | |
273 | # time, the inferior should have exited. GDB shouldn't crash or | |
274 | # anything untoward as a result of this. | |
275 | # | |
276 | set wp_id -1 | |
277 | ||
278 | send_gdb "watch local_var\n" | |
279 | gdb_expect { | |
280 | -re ".*\[Ww\]atchpoint (\[0-9\]*): local_var.*$gdb_prompt $" { | |
281 | set wp_id $expect_out(1,string) | |
282 | pass "watch local_var" | |
283 | } | |
284 | -re "$gdb_prompt $"\ | |
285 | {fail "watch local_var"} | |
286 | timeout {fail "(timeout) watch local_var"} | |
287 | } | |
7a292a7a | 288 | |
085dd6e6 JM |
289 | if {$wp_id == -1} {return} |
290 | ||
291 | send_gdb "commands $wp_id\n" | |
292 | gdb_expect { | |
293 | -re "Type commands for when breakpoint $wp_id is hit, one per line.*>"\ | |
294 | {pass "begin commands on watch"} | |
295 | -re "$gdb_prompt $"\ | |
296 | {fail "begin commands on watch"} | |
297 | timeout {fail "(timeout) begin commands on watch"} | |
298 | } | |
299 | send_gdb "print value\n" | |
300 | gdb_expect { | |
301 | -re ">"\ | |
302 | {pass "add print command to watch"} | |
303 | -re "$gdb_prompt $"\ | |
304 | {fail "add print command to watch"} | |
305 | timeout {fail "(timeout) add print command to watch"} | |
306 | } | |
307 | send_gdb "continue\n" | |
308 | gdb_expect { | |
309 | -re ">"\ | |
310 | {pass "add continue command to watch"} | |
311 | -re "$gdb_prompt $"\ | |
312 | {fail "add continue command to watch"} | |
313 | timeout {fail "(timeout) add continue command to watch"} | |
314 | } | |
315 | send_gdb "end\n" | |
316 | gdb_expect { | |
317 | -re "$gdb_prompt $"\ | |
318 | {pass "begin commands on watch"} | |
319 | timeout {fail "(timeout) begin commands on watch"} | |
320 | } | |
321 | send_gdb "continue\n" | |
322 | gdb_expect { | |
323 | -re "Continuing.*\[Ww\]atchpoint $wp_id deleted because the program has left the block in.*which its expression is valid.*run.c:57.*"\ | |
324 | {pass "continue with watch"} | |
325 | -re "$gdb_prompt $"\ | |
326 | {fail "continue with watch"} | |
327 | timeout {fail "(timeout) continue with watch"} | |
328 | } | |
329 | } | |
7a292a7a SS |
330 | |
331 | proc test_command_prompt_position {} { | |
332 | global gdb_prompt | |
333 | ||
334 | if [target_info exists noargs] { | |
335 | verbose "Skipping test_command_prompt_position because of noargs." | |
336 | return | |
337 | } | |
338 | ||
339 | if { ![runto factorial] } then { gdb_suppress_tests; } | |
340 | # Don't depend upon argument passing, since most simulators don't currently | |
341 | # support it. Bash value variable to be what we want. | |
342 | delete_breakpoints | |
343 | gdb_test "break factorial" "Breakpoint.*at.*" "break factorial #2" | |
344 | gdb_test "p value=5" "" "set value to 5 in test_command_prompt_position" | |
345 | # All this test should do is print 0xdeadbeef once. | |
346 | gdb_test "if value == 1\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" "\\\$\[0-9\]* = 0xdeadbeef" "if test in test_command_prompt_position" | |
347 | ||
348 | # Now let's test for the correct position of the '>' in gdb's prompt for commands. | |
349 | # It should be at the beginning of the line, and not after one space. | |
350 | ||
351 | send_gdb "commands\n" | |
352 | gdb_expect { | |
353 | -re "Type commands.*End with.*\[\r\n\]>$" \ | |
354 | { send_gdb "printf \"Now the value is %d\\n\", value\n" | |
355 | gdb_expect { | |
356 | -re "^printf.*value\r\n>$" \ | |
357 | { send_gdb "end\n" | |
358 | gdb_expect { | |
359 | -re "^end\r\n$gdb_prompt $" { pass "> OK in test_command_prompt_position" } | |
360 | -re ".*$gdb_prompt $" { fail "some other message in test_command_prompt_position" } | |
361 | timeout { fail "(timeout) 1 in test_command_prompt_position" } | |
362 | } | |
363 | } | |
364 | -re "^ >$" { fail "> not OK in test_command_prompt_position" } | |
365 | -re ".*$gdb_prompt $" { fail "wrong message in test_command_prompt_position" } | |
366 | timeout { fail "(timeout) 2 in test_command_prompt_position " } | |
367 | } | |
368 | } | |
369 | -re "Type commands.*End with.*\[\r\n\] >$" { fail "prompt not OK in test_command_prompt_position" } | |
370 | -re ".*$gdb_prompt $" { fail "commands in test_command_prompt_position" } | |
371 | timeout { fail "(timeout) 3 commands in test_command_prompt_position" } | |
372 | } | |
373 | ||
374 | gdb_stop_suppressing_tests; | |
375 | } | |
376 | ||
377 | ||
c906108c SS |
378 | gdbvar_simple_if_test |
379 | gdbvar_simple_while_test | |
380 | gdbvar_complex_if_while_test | |
381 | progvar_simple_if_test | |
382 | progvar_simple_while_test | |
383 | progvar_complex_if_while_test | |
384 | if_while_breakpoint_command_test | |
385 | infrun_breakpoint_command_test | |
386 | breakpoint_command_test | |
387 | user_defined_command_test | |
085dd6e6 | 388 | watchpoint_command_test |
7a292a7a SS |
389 | test_command_prompt_position |
390 | ||
391 | ||
392 | ||
393 |