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