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