* gdb.base/commands.exp: Call if_commands_test.
[deliverable/binutils-gdb.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 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 2 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, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
20
21 if $tracelevel then {
22 strace $tracelevel
23 }
24
25 #
26 # test special commands (if, while, etc)
27 #
28 set prms_id 0
29 set bug_id 0
30
31 set testfile "run"
32 set srcfile ${testfile}.c
33 set binfile ${objdir}/${subdir}/commands
34 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-DFAKEARGV}] != "" } {
35 untested commands.exp
36 return -1
37 }
38
39 gdb_exit
40 gdb_start
41 delete_breakpoints
42 gdb_reinitialize_dir $srcdir/$subdir
43 gdb_load ${binfile}
44
45 proc 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.
50 gdb_test "if \$foo == 1\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" \
51 "\\\$\[0-9\]* = 0xdeadbeef" "gdbvar_simple_if_test #1"
52 # All this test should do is print 0xfeedface once.
53 gdb_test "if \$foo == 0\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" \
54 "\\\$\[0-9\]* = 0xfeedface" "gdbvar_simple_if_test #2"
55 }
56
57 proc 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.
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"
65 }
66
67 proc 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.
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"
75 }
76
77 proc progvar_simple_if_test {} {
78 global gdb_prompt
79
80 if [target_info exists noargs] {
81 verbose "Skipping progvar_simple_if_test because of noargs."
82 return
83 }
84
85 if { ![runto factorial] } then { gdb_suppress_tests; }
86 # Don't depend upon argument passing, since most simulators don't
87 # currently support it. Bash value variable to be what we want.
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.
90 gdb_test "if value == 1\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" \
91 "\\\$\[0-9\]* = 0xdeadbeef" \
92 "progvar_simple_if_test #1"
93 # All this test should do is print 0xfeedface once.
94 gdb_test "if value == 5\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" \
95 "\\\$\[0-9\]* = 0xfeedface" \
96 "progvar_simple_if_test #2"
97 gdb_stop_suppressing_tests;
98 }
99
100 proc progvar_simple_while_test {} {
101 global gdb_prompt
102
103 if [target_info exists noargs] {
104 verbose "Skipping progvar_simple_while_test because of noargs."
105 return
106 }
107
108 gdb_test "set args 5" "" "set args in progvar_simple_while_test"
109 if { ![runto factorial] } then { gdb_suppress_tests }
110 # Don't depend upon argument passing, since most simulators don't
111 # currently support it. Bash value variable to be what we want.
112 gdb_test "p value=5" "" "set value to 5 in progvar_simple_if_test #2"
113 # This test should print 0xfeedface five times.
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"
117 gdb_stop_suppressing_tests;
118 }
119
120 proc progvar_complex_if_while_test {} {
121 global gdb_prompt
122
123 if [target_info exists noargs] {
124 verbose "Skipping progvar_simple_if_while_test because of noargs."
125 return
126 }
127
128 gdb_test "set args 4" "" "set args in progvar_complex_if_while_test"
129 if { ![runto factorial] } then { gdb_suppress_tests }
130 # Don't depend upon argument passing, since most simulators don't
131 # currently support it. Bash value variable to be what we want.
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.
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"
137 gdb_stop_suppressing_tests;
138 }
139
140 proc if_while_breakpoint_command_test {} {
141 if [target_info exists noargs] {
142 verbose "Skipping if_while_breakpoint_command_test because of noargs."
143 return
144 }
145
146 gdb_test "set args 5" "" "set args in if_while_breakpoint_command_test"
147 if { ![runto factorial] } then { gdb_suppress_tests }
148 # Don't depend upon argument passing, since most simulators don't
149 # currently support it. Bash value variable to be what we want.
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.
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"
173 gdb_stop_suppressing_tests;
174 }
175
176 # Test that we can run the inferior from breakpoint commands.
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
182 proc infrun_breakpoint_command_test {} {
183 if [target_info exists noargs] {
184 verbose "Skipping infrun_breakpoint_command_test because of noargs."
185 return
186 }
187
188 gdb_test "set args 6" "" "set args in infrun_breakpoint_command_test"
189 if { ![runto factorial] } then { gdb_suppress_tests }
190 # Don't depend upon argument passing, since most simulators don't
191 # currently support it. Bash value variable to be what we want.
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
196 # infrun_breakpoint_command_test - This test was broken into two parts
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 }
209 gdb_test "step\nstep\nstep\nstep\nend" "" \
210 "commands in infrun_breakpoint_command_test #2"
211
212 gdb_test "continue" \
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"
215
216 gdb_stop_suppressing_tests;
217 }
218
219 proc breakpoint_command_test {} {
220 if [target_info exists noargs] {
221 verbose "Skipping breakpoint_command_test because of noargs."
222 return
223 }
224
225 gdb_test "set args 6" "" "set args in breakpoint_command_test"
226 if { ![runto factorial] } then { gdb_suppress_tests; }
227 # Don't depend upon argument passing, since most simulators don't
228 # currently support it. Bash value variable to be what we want.
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" \
233 "End with.*" "commands in breakpoint_command_test"
234 gdb_test "continue" \
235 "Breakpoint \[0-9\]*, factorial.*Now the value is 5" \
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)
242 proc 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.
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" \
265 " while \\\$arg0.*set.* if \\\(\\\$arg0.*p/x.* else\[^\n\].*p/x.* end\[^\n\].* end\[^\n\].*" \
266 "display user command in user_defined_command_test"
267 }
268
269 proc watchpoint_command_test {} {
270 global noargs
271 global gdb_prompt
272
273 if [target_info exists noargs] {
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 }
305
306 if {$wp_id == -1} {return}
307
308 send_gdb "commands $wp_id\n"
309 gdb_expect {
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"}
315 }
316 send_gdb "print value\n"
317 gdb_expect {
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"}
321 }
322 send_gdb "continue\n"
323 gdb_expect {
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"}
327 }
328 send_gdb "end\n"
329 gdb_expect {
330 -re "$gdb_prompt $" {pass "end commands on watch"}
331 timeout {fail "(timeout) end commands on watch"}
332 }
333 send_gdb "continue\n"
334 gdb_expect {
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 $" {
336 pass "continue with watch"
337 }
338 -re "$gdb_prompt $" {fail "continue with watch"}
339 timeout {fail "(timeout) continue with watch"}
340 }
341 }
342
343 proc test_command_prompt_position {} {
344 global gdb_prompt
345
346 if [target_info exists noargs] {
347 verbose "Skipping test_command_prompt_position because of noargs."
348 return
349 }
350
351 if { ![runto factorial] } then { gdb_suppress_tests; }
352 # Don't depend upon argument passing, since most simulators don't
353 # currently support it. Bash value variable to be what we want.
354 delete_breakpoints
355 gdb_test "break factorial" "Breakpoint.*at.*" "break factorial #3"
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.
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.
365
366 send_gdb "commands\n"
367 gdb_expect {
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"
399 }
400 timeout { fail "(timeout) 3 commands in test_command_prompt_position" }
401 }
402
403 gdb_stop_suppressing_tests;
404 }
405
406
407
408 proc deprecated_command_test {} {
409 gdb_test "maintenance deprecate blah" "Can't find command.*" \
410 "tried to deprecate non-existing command"
411
412 gdb_test "maintenance deprecate p \"new_p\"" "" "maintenance deprecate p \"new_p\" /1/"
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"
416 gdb_test "p 5" ".\[0-9\]* = 5.*" "Deprecated warning goes away /1/"
417
418 gdb_test "maintenance deprecate p \"new_p\"" "" "maintenance deprecate p \"new_p\" /2/"
419 gdb_test "maintenance deprecate print \"new_print\"" ""
420 gdb_test "p 5" \
421 "Warning: command 'print' \\(p\\) is deprecated.*Use 'new_print'.*" \
422 "both alias and command are deprecated"
423 gdb_test "p 5" ".\[0-9\]* = 5.*" "Deprecated warning goes away /2/"
424
425 gdb_test "maintenance deprecate set remote memory-read-packet-size \"srm\" " \
426 "" \
427 "deprecate long command /1/"
428 gdb_test "set remote memory-read-packet-size" \
429 "Warning: command 'set remote memory-read-packet-size' is deprecated.*Use 'srm'.*" \
430 "long command deprecated /1/"
431
432 gdb_test "maintenance deprecate set remote memory-read-packet-size" \
433 "" \
434 "deprecate long command /2/"
435 gdb_test "set remote memory-read-packet-size" \
436 "Warning: command 'set remote memory-read-packet-size' is deprecated.*No alternative known.*" \
437 "long command deprecated with no alternative /2/"
438
439 gdb_test "maintenance deprecate" \
440 "\"maintenance deprecate\".*" \
441 "deprecate with no arguments"
442 }
443
444 proc bp_deleted_in_command_test {} {
445 global gdb_prompt
446
447 if [target_info exists noargs] {
448 verbose "Skipping bp_deleted_in_command_test because of noargs."
449 return
450 }
451
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 }
496
497 gdb_run_cmd
498 gdb_expect {
499 -re ".*factorial command-list executed.*1.*$gdb_prompt $" {
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
510 proc temporary_breakpoint_commands {} {
511 global gdb_prompt
512
513 if [target_info exists noargs] {
514 verbose "Skipping temporary_breakpoint_commands because of noargs."
515 return
516 }
517
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 {
561 -re ".*factorial tbreak commands executed.*1.*$gdb_prompt $" {
562 pass "run factorial until temporary breakpoint"
563 }
564 timeout { fail "(timeout) run factorial until temporary breakpoint" }
565 }
566 }
567
568 # Test that GDB can handle $arg0 outside of user functions without
569 # crashing.
570 proc 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 }
587
588 # Test that GDB can handle arguments when sourcing files recursively.
589 # If the arguments are overwritten with ####### then the test has failed.
590 proc recursive_source_test {} {
591 set fd [open "file1" w]
592 puts $fd \
593 {source file2
594 abcdef 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
603 end}
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
621 proc gdb_test_no_prompt { command result msg } {
622 global gdb_prompt
623
624 set msg "$command - $msg"
625 set result "^[string_to_regexp $command]\r\n$result$"
626 gdb_test_multiple $command $msg {
627 -re "$result" {
628 pass $msg
629 return 1
630 }
631 -re "\r\n *>$" {
632 fail $msg
633 return 0
634 }
635 }
636 return 0
637 }
638
639 proc if_commands_test {} {
640 global gdb_prompt
641
642 gdb_test "set \$tem = 1" "" "set \$tem in if_commands_test"
643
644 set test "if_commands_test 1"
645 gdb_test_no_prompt "if \$tem == 2" { >} $test
646 gdb_test_no_prompt "break main" { >} $test
647 gdb_test_no_prompt "else" { >} $test
648 gdb_test_no_prompt "break factorial" { >} $test
649 gdb_test_no_prompt "commands" { >} $test
650 gdb_test_no_prompt "silent" { >} $test
651 gdb_test_no_prompt "set \$tem = 3" { >} $test
652 gdb_test_no_prompt "continue" { >} $test
653 gdb_test_multiple "end" "first end - $test" {
654 -re " >\$" {
655 pass "first end - $test"
656 }
657 -re "\r\n>\$" {
658 fail "first end - $test"
659 }
660 }
661 gdb_test_multiple "end" "second end - $test" {
662 -re "Breakpoint \[0-9\]+ at .*: file .*/run.c, line \[0-9\]+\.\r\n$gdb_prompt $" {
663 pass "second end - $test"
664 }
665 -re "Undefined command: \"silent\".*$gdb_prompt $" {
666 fail "second end - $test"
667 }
668 }
669
670 set test "if_commands_test 2"
671 gdb_test_no_prompt "if \$tem == 1" { >} $test
672 gdb_test_no_prompt "break main" { >} $test
673 gdb_test_no_prompt "else" { >} $test
674 gdb_test_no_prompt "break factorial" { >} $test
675 gdb_test_no_prompt "commands" { >} $test
676 gdb_test_no_prompt "silent" { >} $test
677 gdb_test_no_prompt "set \$tem = 3" { >} $test
678 gdb_test_no_prompt "continue" { >} $test
679 gdb_test_multiple "end" "first end - $test" {
680 -re " >\$" {
681 pass "first end - $test"
682 }
683 -re "\r\n>\$" {
684 fail "first end - $test"
685 }
686 }
687 gdb_test_multiple "end" "second end - $test" {
688 -re "Breakpoint \[0-9\]+ at .*: file .*/run.c, line \[0-9\]+\.\r\n$gdb_prompt $" {
689 pass "second end - $test"
690 }
691 }
692 }
693
694 gdbvar_simple_if_test
695 gdbvar_simple_while_test
696 gdbvar_complex_if_while_test
697 progvar_simple_if_test
698 progvar_simple_while_test
699 progvar_complex_if_while_test
700 if_while_breakpoint_command_test
701 infrun_breakpoint_command_test
702 breakpoint_command_test
703 user_defined_command_test
704 watchpoint_command_test
705 test_command_prompt_position
706 deprecated_command_test
707 bp_deleted_in_command_test
708 temporary_breakpoint_commands
709 stray_arg0_test
710 recursive_source_test
711 if_commands_test
This page took 0.04514 seconds and 5 git commands to generate.