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