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