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