Further cleanup/modernization of gdb.base/commands.exp
[binutils-gdb.git] / gdb / testsuite / gdb.base / commands.exp
1 # Copyright 1988-2016 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 3 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, see <http://www.gnu.org/licenses/>.
15
16 #
17 # test special commands (if, while, etc)
18 #
19
20 standard_testfile
21
22 if { [prepare_for_testing commands.exp commands run.c {debug additional_flags=-DFAKEARGV}] } {
23 return -1
24 }
25
26 # Run to FUNCTION. If that fails, issue a FAIL and make the caller
27 # return.
28
29 proc runto_or_return {function} {
30 if { ![runto factorial] } {
31 fail "cannot run to $function"
32 return -code return
33 }
34 }
35
36 proc_with_prefix gdbvar_simple_if_test {} {
37 global gdb_prompt
38 global valnum_re
39
40 gdb_test_no_output "set \$foo = 0" "set foo"
41 # All this test should do is print 0xdeadbeef once.
42 gdb_test \
43 [multi_line_input \
44 {if $foo == 1} \
45 { p/x 0xfeedface} \
46 {else} \
47 { p/x 0xdeadbeef} \
48 {end}] \
49 "$valnum_re = 0xdeadbeef" \
50 "#1"
51
52 # All this test should do is print 0xfeedface once.
53 gdb_test \
54 [multi_line_input \
55 {if $foo == 0} \
56 { p/x 0xfeedface} \
57 {else} \
58 { p/x 0xdeadbeef} \
59 {end}] \
60 "$valnum_re = 0xfeedface" \
61 "#2"
62 }
63
64 proc_with_prefix gdbvar_simple_while_test {} {
65 global gdb_prompt
66 global valnum_re
67
68 gdb_test_no_output "set \$foo = 5" "set foo"
69 # This test should print 0xfeedface five times.
70 gdb_test \
71 [multi_line_input \
72 {while $foo > 0} \
73 { p/x 0xfeedface} \
74 { set $foo -= 1} \
75 {end}] \
76 [multi_line \
77 "$valnum_re = 0xfeedface" \
78 "$valnum_re = 0xfeedface" \
79 "$valnum_re = 0xfeedface" \
80 "$valnum_re = 0xfeedface" \
81 "$valnum_re = 0xfeedface"] \
82 "#1"
83 }
84
85 proc_with_prefix gdbvar_complex_if_while_test {} {
86 global gdb_prompt
87 global valnum_re
88
89 gdb_test_no_output "set \$foo = 4" "set foo"
90 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
91 gdb_test \
92 [multi_line_input \
93 {while $foo > 0} \
94 { set $foo -= 1} \
95 { if ($foo % 2) == 1} \
96 { p/x 0xdeadbeef} \
97 { else} \
98 { p/x 0xfeedface} \
99 { end} \
100 {end}] \
101 [multi_line \
102 "$valnum_re = 0xdeadbeef" \
103 "$valnum_re = 0xfeedface" \
104 "$valnum_re = 0xdeadbeef" \
105 "$valnum_re = 0xfeedface"] \
106 "#1"
107 }
108
109 proc_with_prefix progvar_simple_if_test {} {
110 global gdb_prompt
111 global valnum_re
112
113 runto_or_return factorial
114
115 # Don't depend upon argument passing, since most simulators don't
116 # currently support it. Bash value variable to be what we want.
117 gdb_test "p value=5" " = 5" "set value to 5"
118 # All this test should do is print 0xdeadbeef once.
119 gdb_test \
120 [multi_line_input \
121 {if value == 1} \
122 { p/x 0xfeedface} \
123 {else} \
124 { p/x 0xdeadbeef} \
125 {end}] \
126 "$valnum_re = 0xdeadbeef" \
127 "#1"
128
129 # All this test should do is print 0xfeedface once.
130 gdb_test \
131 [multi_line_input \
132 {if value == 5} \
133 { p/x 0xfeedface} \
134 {else} \
135 { p/x 0xdeadbeef} \
136 {end}] \
137 "$valnum_re = 0xfeedface" \
138 "#2"
139 }
140
141 proc_with_prefix progvar_simple_while_test {} {
142 global gdb_prompt
143 global valnum_re
144
145 runto_or_return factorial
146
147 # Don't depend upon argument passing, since most simulators don't
148 # currently support it. Bash value variable to be what we want.
149 gdb_test "p value=5" " = 5" "set value to 5"
150 # This test should print 0xfeedface five times.
151 gdb_test \
152 [multi_line_input \
153 {while value > 0} \
154 { p/x 0xfeedface} \
155 { set value -= 1} \
156 {end}] \
157 [multi_line \
158 "$valnum_re = 0xfeedface" \
159 "$valnum_re = 0xfeedface" \
160 "$valnum_re = 0xfeedface" \
161 "$valnum_re = 0xfeedface" \
162 "$valnum_re = 0xfeedface"] \
163 "#1"
164 }
165
166 proc_with_prefix progvar_complex_if_while_test {} {
167 global gdb_prompt
168 global valnum_re
169
170 runto_or_return factorial
171
172 # Don't depend upon argument passing, since most simulators don't
173 # currently support it. Bash value variable to be what we want.
174 gdb_test "p value=4" " = 4" "set value to 4"
175 # This test should alternate between 0xdeadbeef and 0xfeedface two
176 # times.
177 gdb_test \
178 [multi_line_input \
179 {while value > 0} \
180 { set value -= 1} \
181 { if (value % 2) == 1} \
182 { p/x 0xdeadbeef} \
183 { else} \
184 { p/x 0xfeedface} \
185 { end} \
186 {end}] \
187 [multi_line \
188 "$valnum_re = 0xdeadbeef" \
189 "$valnum_re = 0xfeedface" \
190 "$valnum_re = 0xdeadbeef" \
191 "$valnum_re = 0xfeedface"] \
192 "#1"
193 }
194
195 proc_with_prefix if_while_breakpoint_command_test {} {
196 global valnum_re
197
198 runto_or_return factorial
199
200 # Don't depend upon argument passing, since most simulators don't
201 # currently support it. Bash value variable to be what we want.
202 gdb_test "p value=5" " = 5" "set value to 5"
203 delete_breakpoints
204 gdb_test "break factorial" "Breakpoint.*at.*" "break factorial"
205
206 gdb_test_multiple "commands" "commands" {
207 -re "End with" {
208 pass "commands"
209 }
210 }
211
212 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
213 gdb_test \
214 [multi_line_input \
215 {while value > 0} \
216 { set value -= 1} \
217 { if (value % 2) == 1} \
218 { p/x 0xdeadbeef} \
219 { else} \
220 { p/x 0xfeedface} \
221 { end} \
222 {end} \
223 {end}] \
224 "" \
225 "commands part 2"
226 gdb_test \
227 "continue" \
228 [multi_line \
229 "$valnum_re = 0xdeadbeef" \
230 "$valnum_re = 0xfeedface" \
231 "$valnum_re = 0xdeadbeef" \
232 "$valnum_re = 0xfeedface"] \
233 "#1"
234 gdb_test "info break" "while.*set.*if.*p/x.*else.*p/x.*end.*"
235 }
236
237 # Test that we can run the inferior from breakpoint commands.
238 #
239 # The expected behavior is that all commands after the first "step"
240 # shall be ignored. See the gdb manual, "Break Commands",
241 # subsection "Breakpoint command lists".
242
243 proc_with_prefix infrun_breakpoint_command_test {} {
244 runto_or_return factorial
245
246 # Don't depend upon argument passing, since most simulators don't
247 # currently support it. Bash value variable to be what we want.
248 gdb_test "p value=6" " = 6" "set value to 6"
249 delete_breakpoints
250 gdb_test "break factorial if value == 5" "Breakpoint.*at.*"
251
252 # infrun_breakpoint_command_test - This test was broken into two parts
253 # to get around a synchronization problem in expect.
254 # part1: issue the gdb command "commands"
255 # part2: send the list of commands
256
257 set test "commands #1"
258 gdb_test_multiple "commands" $test {
259 -re "End with" {
260 pass $test
261 }
262 }
263 gdb_test "step\nstep\nstep\nstep\nend" "" \
264 "commands #2"
265
266 gdb_test "continue" \
267 "Continuing.*.*.*Breakpoint \[0-9\]*, factorial \\(value=5\\).*at.*\[0-9\]*\[ \]*if \\(value > 1\\) \{.*\[0-9\]*\[ \]*value \\*= factorial \\(value - 1\\);.*"
268 }
269
270 proc_with_prefix breakpoint_command_test {} {
271 runto_or_return factorial
272
273 # Don't depend upon argument passing, since most simulators don't
274 # currently support it. Bash value variable to be what we want.
275 gdb_test "p value=6" " = 6" "set value to 6"
276 delete_breakpoints
277 gdb_test "break factorial" "Breakpoint.*at.*"
278 gdb_test \
279 [multi_line_input \
280 {commands} \
281 { printf "Now the value is %d\n", value} \
282 {end}] \
283 "End with.*" \
284 "commands"
285 gdb_test "continue" \
286 "Breakpoint \[0-9\]*, factorial.*Now the value is 5"
287 gdb_test "print value" " = 5"
288 }
289
290 # Test a simple user defined command (with arguments)
291 proc_with_prefix user_defined_command_test {} {
292 global gdb_prompt
293 global valnum_re
294
295 gdb_test_no_output "set \$foo = 4" "set foo"
296
297 gdb_test_multiple "define mycommand" "define mycommand" {
298 -re "End with" {
299 pass "define mycommand"
300 }
301 }
302
303 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
304 gdb_test \
305 [multi_line_input \
306 {while $arg0 > 0} \
307 { set $arg0 -= 1} \
308 { if ($arg0 % 2) == 1} \
309 { p/x 0xdeadbeef} \
310 { else} \
311 { p/x 0xfeedface} \
312 { end} \
313 {end} \
314 {end}] \
315 "" \
316 "enter commands"
317
318 global decimal
319 set valnum_re "\\\$$decimal"
320
321 gdb_test \
322 {mycommand $foo} \
323 [multi_line \
324 "$valnum_re = 0xdeadbeef" \
325 "$valnum_re = 0xfeedface" \
326 "$valnum_re = 0xdeadbeef" \
327 "$valnum_re = 0xfeedface"] \
328 "execute user-defined command"
329 gdb_test "show user mycommand" \
330 " while \\\$arg0.*set.* if \\\(\\\$arg0.*p/x.* else\[^\n\].*p/x.* end\[^\n\].* end\[^\n\].*" \
331 "display user command"
332
333 # Create and test a user-defined command with an empty body.
334 gdb_test_multiple "define myemptycommand" "define myemptycommand" {
335 -re "End with" {
336 pass "define myemptycommand"
337 }
338 }
339 gdb_test "end" \
340 "" \
341 "end definition of user-defined command with empty body"
342
343 gdb_test_no_output "myemptycommand" \
344 "execute user-defined empty command"
345
346 gdb_test "show user" \
347 "User command \"myemptycommand.*" \
348 "display empty command in command list"
349
350 gdb_test "show user myemptycommand" \
351 "User command \"myemptycommand.*" \
352 "display user-defined empty command"
353 }
354
355 proc_with_prefix watchpoint_command_test {} {
356 global gdb_prompt
357
358 # Disable hardware watchpoints if necessary.
359 if [target_info exists gdb,no_hardware_watchpoints] {
360 gdb_test_no_output "set can-use-hw-watchpoints 0" ""
361 }
362
363 runto_or_return factorial
364
365 delete_breakpoints
366
367 # Verify that we can create a watchpoint, and give it a commands
368 # list that continues the inferior. We set the watchpoint on a
369 # local variable, too, so that it self-deletes when the watched
370 # data goes out of scope.
371 #
372 # What should happen is: Each time the watchpoint triggers, it
373 # continues the inferior. Eventually, the watchpoint will self-
374 # delete, when the watched variable is out of scope. But by that
375 # time, the inferior should have exited. GDB shouldn't crash or
376 # anything untoward as a result of this.
377 #
378 set wp_id -1
379
380 gdb_test_multiple "watch local_var" "watch local_var" {
381 -re "\[Ww\]atchpoint (\[0-9\]*): local_var.*$gdb_prompt $" {
382 set wp_id $expect_out(1,string)
383 pass "watch local_var"
384 }
385 }
386
387 if {$wp_id == -1} {return}
388
389 gdb_test_multiple "commands $wp_id" "begin commands on watch" {
390 -re "Type commands for breakpoint.*, one per line.*>$" {
391 pass "begin commands on watch"
392 }
393 }
394 # See the 'No symbol "value...' fail below. This command will
395 # fail if it's executed in the wrong frame. If adjusting the
396 # test, make sure this property holds.
397 gdb_test_multiple "print value" "add print command to watch" {
398 -re ">$" {
399 pass "add print command to watch"
400 }
401 }
402 gdb_test_multiple "continue" "add continue command to watch" {
403 -re ">$" {
404 pass "add continue command to watch"
405 }
406 }
407 gdb_test "end" \
408 "" \
409 "end commands on watch"
410
411 set test "continue with watch"
412 set lno_1 [gdb_get_line_number "commands.exp: hw local_var out of scope" "run.c"]
413 set lno_2 [gdb_get_line_number "commands.exp: local_var out of scope" "run.c"]
414 gdb_test_multiple "continue" "$test" {
415 -re "No symbol \"value\" in current context.\r\n$gdb_prompt $" {
416 # Happens if GDB actually runs the watchpoints commands,
417 # even though the watchpoint was deleted for not being in
418 # scope.
419 fail $test
420 }
421 -re "Continuing.*\[Ww\]atchpoint $wp_id deleted because the program has left the block in.*which its expression is valid.*run.c:($lno_1|$lno_2).*$gdb_prompt $" {
422 pass $test
423 }
424 }
425 }
426
427 proc_with_prefix test_command_prompt_position {} {
428 global gdb_prompt
429 global valnum_re
430
431 runto_or_return factorial
432
433 # Don't depend upon argument passing, since most simulators don't
434 # currently support it. Bash value variable to be what we want.
435 delete_breakpoints
436 gdb_test "break factorial" "Breakpoint.*at.*"
437 gdb_test "p value=5" ".*" "set value to 5"
438 # All this test should do is print 0xdeadbeef once.
439 gdb_test \
440 [multi_line_input \
441 {if value == 1} \
442 { p/x 0xfeedface} \
443 {else} \
444 { p/x 0xdeadbeef} \
445 {end}] \
446 "$valnum_re = 0xdeadbeef" \
447 "if test"
448
449 # Now let's test for the correct position of the '>' in gdb's
450 # prompt for commands. It should be at the beginning of the line,
451 # and not after one space.
452
453 set test "> OK"
454 gdb_test_multiple "commands" $test {
455 -re "Type commands.*End with.*\[\r\n\]>$" {
456 gdb_test_multiple "printf \"Now the value is %d\\n\", value" $test {
457 -re "^printf.*value\r\n>$" {
458 gdb_test_multiple "end" $test {
459 -re "^end\r\n$gdb_prompt $" {
460 pass $test
461 }
462 }
463 }
464 }
465 }
466 }
467 }
468
469
470
471 proc_with_prefix deprecated_command_test {} {
472 gdb_test "maintenance deprecate blah" "Can't find command.*" \
473 "tried to deprecate non-existing command"
474
475 gdb_test_no_output "maintenance deprecate p \"new_p\"" "maintenance deprecate p \"new_p\" /1/"
476 gdb_test "p 5" \
477 "Warning: 'p', an alias for the command 'print' is deprecated.*Use 'new_p'.*" \
478 "p deprecated warning, with replacement"
479 gdb_test "p 5" ".\[0-9\]* = 5.*" "Deprecated warning goes away /1/"
480
481 gdb_test_no_output "maintenance deprecate p \"new_p\"" "maintenance deprecate p \"new_p\" /2/"
482 gdb_test_no_output "maintenance deprecate print \"new_print\""
483 gdb_test "p 5" \
484 "Warning: command 'print' \\(p\\) is deprecated.*Use 'new_print'.*" \
485 "both alias and command are deprecated"
486 gdb_test "p 5" ".\[0-9\]* = 5.*" "Deprecated warning goes away /2/"
487
488 gdb_test_no_output "maintenance deprecate set remote memory-read-packet-size \"srm\" " \
489 "deprecate long command /1/"
490 gdb_test "set remote memory-read-packet-size" \
491 "Warning: command 'set remote memory-read-packet-size' is deprecated.*Use 'srm'.*" \
492 "long command deprecated /1/"
493
494 gdb_test_no_output "maintenance deprecate set remote memory-read-packet-size" \
495 "deprecate long command /2/"
496 gdb_test "set remote memory-read-packet-size" \
497 "Warning: command 'set remote memory-read-packet-size' is deprecated.*No alternative known.*" \
498 "long command deprecated with no alternative /2/"
499
500 gdb_test "maintenance deprecate" \
501 "\"maintenance deprecate\".*" \
502 "deprecate with no arguments"
503 }
504
505 proc_with_prefix bp_deleted_in_command_test {} {
506 global gdb_prompt
507
508 delete_breakpoints
509
510 # Create a breakpoint, and associate a command-list to it, with
511 # one command that deletes this breakpoint.
512 gdb_test "break factorial" \
513 "Breakpoint \[0-9\]+ at .*: file .*run.c, line \[0-9\]+\."
514
515 gdb_test_multiple "commands" "begin commands" {
516 -re "Type commands for breakpoint.*>$" {
517 pass "begin commands"
518 }
519 }
520 gdb_test_multiple "silent" "add silent command" {
521 -re ">$" {
522 pass "add silent command"
523 }
524 }
525 gdb_test_multiple "clear factorial" "add clear command" {
526 -re ">$" {
527 pass "add clear command"
528 }
529 }
530 gdb_test_multiple "printf \"factorial command-list executed\\n\"" \
531 "add printf command" {
532 -re ">$" {
533 pass "add printf command"
534 }
535 }
536 gdb_test_multiple "cont" "add cont command" {
537 -re ">$" {
538 pass "add cont command"
539 }
540 }
541 gdb_test "end" \
542 "" \
543 "end commands"
544
545 gdb_run_cmd
546 gdb_test "" "factorial command-list executed.*" "run factorial until breakpoint"
547 }
548
549 proc_with_prefix temporary_breakpoint_commands {} {
550 global gdb_prompt
551
552 delete_breakpoints
553
554 # Create a temporary breakpoint, and associate a commands list to it.
555 # This test will verify that this commands list is executed when the
556 # breakpoint is hit.
557 gdb_test "tbreak factorial" \
558 "Temporary breakpoint \[0-9\]+ at .*: file .*run.c, line \[0-9\]+\." \
559 "breakpoint"
560
561 gdb_test_multiple "commands" \
562 "begin commands in bp_deleted_in_command_test" {
563 -re "Type commands for breakpoint.*>$" {
564 pass "begin commands"
565 }
566 }
567 gdb_test_multiple "silent" "add silent tbreak command" {
568 -re ">$" {
569 pass "add silent tbreak command"
570 }
571 }
572 gdb_test_multiple "printf \"factorial tbreak commands executed\\n\"" \
573 "add printf tbreak command" {
574 -re ">$" {
575 pass "add printf tbreak command"
576 }
577 }
578 gdb_test_multiple "cont" "add cont tbreak command" {
579 -re ">$" {
580 pass "add cont tbreak command"
581 }
582 }
583 gdb_test "end" \
584 "" \
585 "end tbreak commands"
586
587 gdb_run_cmd
588 gdb_test "" "factorial tbreak commands executed.*" \
589 "run factorial until temporary breakpoint"
590 }
591
592 # Test that GDB can handle $arg0 outside of user functions without
593 # crashing.
594 proc_with_prefix stray_arg0_test { } {
595 global valnum_re
596
597 gdb_test "print \$arg0" \
598 "$valnum_re = void" \
599 "#1"
600
601 gdb_test "if 1 == 1\nprint \$arg0\nend" \
602 "$valnum_re = void" \
603 "#2"
604
605 gdb_test "print \$arg0 = 1" \
606 "$valnum_re = 1" \
607 "#3"
608
609 gdb_test "print \$arg0" \
610 "$valnum_re = 1" \
611 "#4"
612 }
613
614 # Test that GDB is able to source a file with an indented comment.
615 proc_with_prefix source_file_with_indented_comment {} {
616 set file1 [standard_output_file file1]
617
618 set fd [open "$file1" w]
619 puts $fd \
620 {define my_fun
621 #indented comment
622 end
623 echo Done!\n}
624 close $fd
625
626 gdb_test "source $file1" "Done!" "source file"
627 }
628
629 # Test that GDB can handle arguments when sourcing files recursively.
630 # If the arguments are overwritten with ####### then the test has failed.
631 proc_with_prefix recursive_source_test {} {
632 set file1 [standard_output_file file1]
633 set file2 [standard_output_file file2]
634 set file3 [standard_output_file file3]
635
636 set fd [open "$file1" w]
637 puts $fd \
638 "source $file2
639 abcdef qwerty"
640 close $fd
641
642 set fd [open "$file2" w]
643 puts $fd \
644 "define abcdef
645 echo 1: <<<\$arg0>>>\\n
646 source $file3
647 echo 2: <<<\$arg0>>>\\n
648 end"
649 close $fd
650
651 set fd [open "$file3" w]
652 puts $fd \
653 "echo in file3\\n
654 #################################################################"
655 close $fd
656
657 gdb_test "source $file1" \
658 "1: <<<qwerty>>>\[\r\n]+in file3\[\r\n]+2: <<<qwerty>>>" \
659 "source file"
660
661 file delete $file1
662 file delete $file2
663 file delete $file3
664 }
665
666 proc gdb_test_no_prompt { command result msg } {
667 global gdb_prompt
668
669 set msg "$command - $msg"
670 set result "^[string_to_regexp $command]\r\n$result$"
671 gdb_test_multiple $command $msg {
672 -re "$result" {
673 pass $msg
674 return 1
675 }
676 -re "\r\n *>$" {
677 fail $msg
678 return 0
679 }
680 }
681 return 0
682 }
683
684 proc_with_prefix if_commands_test {} {
685 global gdb_prompt
686
687 gdb_test_no_output "set \$tem = 1" "set \$tem"
688
689 set test "if_commands_test 1"
690 gdb_test_no_prompt "if \$tem == 2" { >} $test
691 gdb_test_no_prompt "break main" { >} $test
692 gdb_test_no_prompt "else" { >} $test
693 gdb_test_no_prompt "break factorial" { >} $test
694 gdb_test_no_prompt "commands" { >} $test
695 gdb_test_no_prompt "silent" { >} $test
696 gdb_test_no_prompt "set \$tem = 3" { >} $test
697 gdb_test_no_prompt "continue" { >} $test
698 gdb_test_multiple "end" "first end - $test" {
699 -re " >\$" {
700 pass "first end - $test"
701 }
702 -re "\r\n>\$" {
703 fail "first end - $test"
704 }
705 }
706 gdb_test_multiple "end" "second end - $test" {
707 -re "Breakpoint \[0-9\]+ at .*: file .*run.c, line \[0-9\]+\.\r\n$gdb_prompt $" {
708 pass "second end - $test"
709 }
710 -re "Undefined command: \"silent\".*$gdb_prompt $" {
711 fail "second end - $test"
712 }
713 }
714
715 set test "if_commands_test 2"
716 gdb_test_no_prompt "if \$tem == 1" { >} $test
717 gdb_test_no_prompt "break main" { >} $test
718 gdb_test_no_prompt "else" { >} $test
719 gdb_test_no_prompt "break factorial" { >} $test
720 gdb_test_no_prompt "commands" { >} $test
721 gdb_test_no_prompt "silent" { >} $test
722 gdb_test_no_prompt "set \$tem = 3" { >} $test
723 gdb_test_no_prompt "continue" { >} $test
724 gdb_test_multiple "end" "first end - $test" {
725 -re " >\$" {
726 pass "first end - $test"
727 }
728 -re "\r\n>\$" {
729 fail "first end - $test"
730 }
731 }
732 gdb_test_multiple "end" "second end - $test" {
733 -re "Breakpoint \[0-9\]+ at .*: file .*run.c, line \[0-9\]+\.\r\n$gdb_prompt $" {
734 pass "second end - $test"
735 }
736 }
737 }
738
739 # Verify an error during "commands" commands execution will prevent any other
740 # "commands" from other breakpoints at the same location to be executed.
741
742 proc_with_prefix error_clears_commands_left {} {
743 set test "hook-stop 1"
744 gdb_test_multiple {define hook-stop} $test {
745 -re "End with a line saying just \"end\"\\.\r\n>$" {
746 pass $test
747 }
748 }
749 set test "hook-stop 1a"
750 gdb_test_multiple {echo hook-stop1\n} $test {
751 -re "\r\n>$" {
752 pass $test
753 }
754 }
755 gdb_test_no_output "end" "hook-stop 1b"
756
757 delete_breakpoints
758 gdb_breakpoint "main"
759
760 set test "main commands 1"
761 gdb_test_multiple {commands $bpnum} $test {
762 -re "End with a line saying just \"end\"\\.\r\n>$" {
763 pass $test
764 }
765 }
766 set test "main commands 1a"
767 gdb_test_multiple {echo cmd1\n} $test {
768 -re "\r\n>$" {
769 pass $test
770 }
771 }
772 set test "main commands 1b"
773 gdb_test_multiple {errorcommandxy\n} $test {
774 -re "\r\n>$" {
775 pass $test
776 }
777 }
778 gdb_test_no_output "end" "main commands 1c"
779
780 gdb_breakpoint "main"
781 set test "main commands 2"
782 gdb_test_multiple {commands $bpnum} $test {
783 -re "End with a line saying just \"end\"\\.\r\n>$" {
784 pass $test
785 }
786 }
787 set test "main commands 2a"
788 gdb_test_multiple {echo cmd2\n} $test {
789 -re "\r\n>$" {
790 pass $test
791 }
792 }
793 set test "main commands 2b"
794 gdb_test_multiple {errorcommandyz\n} $test {
795 -re "\r\n>$" {
796 pass $test
797 }
798 }
799 gdb_test_no_output "end" "main commands 2c"
800
801 gdb_run_cmd
802 gdb_test \
803 "" \
804 [multi_line \
805 "hook-stop1" \
806 ".*" \
807 "cmd1" \
808 "Undefined command: \"errorcommandxy\"\\. Try \"help\"\\."] \
809 "cmd1 error"
810
811 gdb_test {echo idle\n} "\r\nidle" "no cmd2"
812 }
813
814 proc_with_prefix redefine_hook_test {} {
815 global gdb_prompt
816
817 gdb_test \
818 [multi_line_input \
819 "define one"\
820 "end"] \
821 "" \
822 "define one"
823
824 gdb_test \
825 [multi_line_input \
826 "define hook-one" \
827 "echo hibob\\n" \
828 "end"] \
829 "" \
830 "define hook-one"
831
832 set test "redefine one"
833 gdb_test_multiple "define one" $test {
834 -re "Redefine command .one.. .y or n. $" {
835 send_gdb "y\n"
836 exp_continue
837 }
838
839 -re "End with" {
840 pass $test
841 }
842 }
843
844 gdb_test "end" "" "enter commands for one redefinition"
845
846 gdb_test "one" "hibob" "execute one command"
847 }
848
849 proc_with_prefix redefine_backtrace_test {} {
850 global gdb_prompt
851
852 gdb_test_multiple "define backtrace" "define backtrace" {
853 -re "Really redefine built-in command \"backtrace\"\\? \\(y or n\\) $" {
854 pass "define backtrace"
855 }
856 }
857
858 gdb_test_multiple "y" "expect response to define backtrace" {
859 -re "End with a line saying just \"end\"\\.\r\n>$" {
860 pass "expect response to define backtrace"
861 }
862 }
863
864 gdb_test \
865 [multi_line_input \
866 "echo hibob\\n" \
867 "end"] \
868 "" \
869 "enter commands"
870
871 gdb_test "backtrace" "hibob" "execute backtrace command"
872 gdb_test "bt" "hibob" "execute bt command"
873 }
874
875 gdbvar_simple_if_test
876 gdbvar_simple_while_test
877 gdbvar_complex_if_while_test
878 progvar_simple_if_test
879 progvar_simple_while_test
880 progvar_complex_if_while_test
881 if_while_breakpoint_command_test
882 infrun_breakpoint_command_test
883 breakpoint_command_test
884 user_defined_command_test
885 watchpoint_command_test
886 test_command_prompt_position
887 deprecated_command_test
888 bp_deleted_in_command_test
889 temporary_breakpoint_commands
890 stray_arg0_test
891 source_file_with_indented_comment
892 recursive_source_test
893 if_commands_test
894 error_clears_commands_left
895 redefine_hook_test
896 # This one should come last, as it redefines "backtrace".
897 redefine_backtrace_test