gdb/testsuite/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / commands.exp
CommitLineData
b6ba6518 1# Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1997, 1998, 1999, 2000,
4c38e0a4 2# 2001, 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010
0fb0cc75 3# Free Software Foundation, Inc.
c906108c
SS
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
e22f8b7c 7# the Free Software Foundation; either version 3 of the License, or
c906108c 8# (at your option) any later version.
e22f8b7c 9#
c906108c
SS
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.
e22f8b7c 14#
c906108c 15# You should have received a copy of the GNU General Public License
e22f8b7c 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 17
c906108c
SS
18if $tracelevel then {
19 strace $tracelevel
20}
21
22#
23# test special commands (if, while, etc)
24#
c906108c 25
aa81e255
JK
26if { [prepare_for_testing commands.exp commands run.c {debug additional_flags=-DFAKEARGV}] } {
27 return -1
c906108c
SS
28}
29
c906108c
SS
30proc 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.
42f5c13f
MS
35 gdb_test "if \$foo == 1\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" \
36 "\\\$\[0-9\]* = 0xdeadbeef" "gdbvar_simple_if_test #1"
c906108c 37 # All this test should do is print 0xfeedface once.
42f5c13f
MS
38 gdb_test "if \$foo == 0\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" \
39 "\\\$\[0-9\]* = 0xfeedface" "gdbvar_simple_if_test #2"
c906108c
SS
40}
41
42proc 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.
42f5c13f
MS
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"
c906108c
SS
50}
51
52proc 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.
42f5c13f
MS
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"
c906108c
SS
60}
61
62proc progvar_simple_if_test {} {
63 global gdb_prompt
64
beb998c6 65 if [target_info exists noargs] {
c906108c
SS
66 verbose "Skipping progvar_simple_if_test because of noargs."
67 return
68 }
69
70 if { ![runto factorial] } then { gdb_suppress_tests; }
42f5c13f
MS
71 # Don't depend upon argument passing, since most simulators don't
72 # currently support it. Bash value variable to be what we want.
c906108c
SS
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.
42f5c13f
MS
75 gdb_test "if value == 1\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" \
76 "\\\$\[0-9\]* = 0xdeadbeef" \
77 "progvar_simple_if_test #1"
c906108c 78 # All this test should do is print 0xfeedface once.
42f5c13f
MS
79 gdb_test "if value == 5\np/x 0xfeedface\nelse\np/x 0xdeadbeef\nend" \
80 "\\\$\[0-9\]* = 0xfeedface" \
81 "progvar_simple_if_test #2"
c906108c
SS
82 gdb_stop_suppressing_tests;
83}
84
85proc progvar_simple_while_test {} {
86 global gdb_prompt
87
beb998c6 88 if [target_info exists noargs] {
c906108c
SS
89 verbose "Skipping progvar_simple_while_test because of noargs."
90 return
91 }
92
085dd6e6 93 gdb_test "set args 5" "" "set args in progvar_simple_while_test"
c906108c 94 if { ![runto factorial] } then { gdb_suppress_tests }
42f5c13f
MS
95 # Don't depend upon argument passing, since most simulators don't
96 # currently support it. Bash value variable to be what we want.
c906108c
SS
97 gdb_test "p value=5" "" "set value to 5 in progvar_simple_if_test #2"
98 # This test should print 0xfeedface five times.
42f5c13f
MS
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"
c906108c
SS
102 gdb_stop_suppressing_tests;
103}
104
105proc progvar_complex_if_while_test {} {
106 global gdb_prompt
107
beb998c6 108 if [target_info exists noargs] {
c906108c
SS
109 verbose "Skipping progvar_simple_if_while_test because of noargs."
110 return
111 }
112
085dd6e6 113 gdb_test "set args 4" "" "set args in progvar_complex_if_while_test"
c906108c 114 if { ![runto factorial] } then { gdb_suppress_tests }
42f5c13f
MS
115 # Don't depend upon argument passing, since most simulators don't
116 # currently support it. Bash value variable to be what we want.
c906108c
SS
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.
42f5c13f
MS
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"
c906108c
SS
122 gdb_stop_suppressing_tests;
123}
124
125proc if_while_breakpoint_command_test {} {
beb998c6 126 if [target_info exists noargs] {
c906108c
SS
127 verbose "Skipping if_while_breakpoint_command_test because of noargs."
128 return
129 }
130
085dd6e6 131 gdb_test "set args 5" "" "set args in if_while_breakpoint_command_test"
c906108c 132 if { ![runto factorial] } then { gdb_suppress_tests }
42f5c13f
MS
133 # Don't depend upon argument passing, since most simulators don't
134 # currently support it. Bash value variable to be what we want.
c906108c
SS
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
ad3986f0
MS
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 }
c906108c 144 }
ad3986f0 145
c906108c 146 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
42f5c13f
MS
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"
c906108c
SS
156 gdb_stop_suppressing_tests;
157}
158
159# Test that we can run the inferior from breakpoint commands.
02aa71d5
MC
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
c906108c 165proc infrun_breakpoint_command_test {} {
beb998c6 166 if [target_info exists noargs] {
c906108c
SS
167 verbose "Skipping infrun_breakpoint_command_test because of noargs."
168 return
169 }
170
7dbd117d 171 gdb_test "set args 6" "" "set args in infrun_breakpoint_command_test"
c906108c 172 if { ![runto factorial] } then { gdb_suppress_tests }
42f5c13f
MS
173 # Don't depend upon argument passing, since most simulators don't
174 # currently support it. Bash value variable to be what we want.
c906108c
SS
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
beb998c6 179# infrun_breakpoint_command_test - This test was broken into two parts
c906108c
SS
180# to get around a synchronization problem in expect.
181# part1: issue the gdb command "commands"
182# part2: send the list of commands
ad3986f0
MS
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 }
c906108c 188 }
02aa71d5 189 gdb_test "step\nstep\nstep\nstep\nend" "" \
c906108c 190 "commands in infrun_breakpoint_command_test #2"
085dd6e6 191
ad3986f0
MS
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"
085dd6e6 195
c906108c
SS
196 gdb_stop_suppressing_tests;
197}
198
199proc breakpoint_command_test {} {
beb998c6 200 if [target_info exists noargs] {
c906108c
SS
201 verbose "Skipping breakpoint_command_test because of noargs."
202 return
203 }
204
085dd6e6 205 gdb_test "set args 6" "" "set args in breakpoint_command_test"
c906108c 206 if { ![runto factorial] } then { gdb_suppress_tests; }
42f5c13f
MS
207 # Don't depend upon argument passing, since most simulators don't
208 # currently support it. Bash value variable to be what we want.
c906108c
SS
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" \
085dd6e6 213 "End with.*" "commands in breakpoint_command_test"
42f5c13f
MS
214 gdb_test "continue" \
215 "Breakpoint \[0-9\]*, factorial.*Now the value is 5" \
c906108c
SS
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)
222proc user_defined_command_test {} {
223 global gdb_prompt
224
225 gdb_test "set \$foo = 4" "" "set foo in user_defined_command_test"
226
ad3986f0
MS
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 }
c906108c 232 }
ad3986f0 233
c906108c 234 # This test should alternate between 0xdeadbeef and 0xfeedface two times.
42f5c13f
MS
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" \
e6ccd35f 243 " while \\\$arg0.*set.* if \\\(\\\$arg0.*p/x.* else\[^\n\].*p/x.* end\[^\n\].* end\[^\n\].*" \
42f5c13f 244 "display user command in user_defined_command_test"
c906108c
SS
245}
246
085dd6e6
JM
247proc watchpoint_command_test {} {
248 global noargs
249 global gdb_prompt
250
beb998c6 251 if [target_info exists noargs] {
085dd6e6
JM
252 verbose "Skipping watchpoint_command_test because of noargs."
253 return
254 }
255
bd5ddfe8
DJ
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
085dd6e6
JM
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
ad3986f0
MS
278 gdb_test_multiple "watch local_var" "watch local_var" {
279 -re "\[Ww\]atchpoint (\[0-9\]*): local_var.*$gdb_prompt $" {
085dd6e6
JM
280 set wp_id $expect_out(1,string)
281 pass "watch local_var"
282 }
085dd6e6 283 }
7a292a7a 284
085dd6e6
JM
285 if {$wp_id == -1} {return}
286
3f9e0d32 287 gdb_test_multiple "commands $wp_id" "begin commands on watch" {
ad3986f0
MS
288 -re "Type commands for breakpoint.*, one per line.*>$" {
289 pass "begin commands on watch"
290 }
085dd6e6 291 }
ad3986f0
MS
292 gdb_test_multiple "print value" "add print command to watch" {
293 -re ">$" {
294 pass "add print command to watch"
295 }
085dd6e6 296 }
ad3986f0
MS
297 gdb_test_multiple "continue" "add continue command to watch" {
298 -re ">$" {
299 pass "add continue command to watch"
42f5c13f 300 }
085dd6e6 301 }
ad3986f0
MS
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"
085dd6e6 309}
7a292a7a
SS
310
311proc test_command_prompt_position {} {
312 global gdb_prompt
313
beb998c6 314 if [target_info exists noargs] {
7a292a7a
SS
315 verbose "Skipping test_command_prompt_position because of noargs."
316 return
317 }
318
319 if { ![runto factorial] } then { gdb_suppress_tests; }
42f5c13f
MS
320 # Don't depend upon argument passing, since most simulators don't
321 # currently support it. Bash value variable to be what we want.
7a292a7a 322 delete_breakpoints
7dbd117d 323 gdb_test "break factorial" "Breakpoint.*at.*" "break factorial #3"
7a292a7a
SS
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.
42f5c13f
MS
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.
7a292a7a
SS
333
334 send_gdb "commands\n"
335 gdb_expect {
42f5c13f
MS
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"
7a292a7a 367 }
42f5c13f
MS
368 timeout { fail "(timeout) 3 commands in test_command_prompt_position" }
369 }
7a292a7a
SS
370
371 gdb_stop_suppressing_tests;
372}
373
374
003ba290
FN
375
376proc deprecated_command_test {} {
003ba290 377 gdb_test "maintenance deprecate blah" "Can't find command.*" \
7dbd117d 378 "tried to deprecate non-existing command"
003ba290 379
7dbd117d 380 gdb_test "maintenance deprecate p \"new_p\"" "" "maintenance deprecate p \"new_p\" /1/"
42f5c13f
MS
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"
7dbd117d 384 gdb_test "p 5" ".\[0-9\]* = 5.*" "Deprecated warning goes away /1/"
003ba290 385
7dbd117d 386 gdb_test "maintenance deprecate p \"new_p\"" "" "maintenance deprecate p \"new_p\" /2/"
003ba290 387 gdb_test "maintenance deprecate print \"new_print\"" ""
42f5c13f
MS
388 gdb_test "p 5" \
389 "Warning: command 'print' \\(p\\) is deprecated.*Use 'new_print'.*" \
390 "both alias and command are deprecated"
7dbd117d 391 gdb_test "p 5" ".\[0-9\]* = 5.*" "Deprecated warning goes away /2/"
003ba290 392
42f5c13f
MS
393 gdb_test "maintenance deprecate set remote memory-read-packet-size \"srm\" " \
394 "" \
7dbd117d 395 "deprecate long command /1/"
42f5c13f
MS
396 gdb_test "set remote memory-read-packet-size" \
397 "Warning: command 'set remote memory-read-packet-size' is deprecated.*Use 'srm'.*" \
7dbd117d 398 "long command deprecated /1/"
42f5c13f
MS
399
400 gdb_test "maintenance deprecate set remote memory-read-packet-size" \
401 "" \
7dbd117d 402 "deprecate long command /2/"
42f5c13f
MS
403 gdb_test "set remote memory-read-packet-size" \
404 "Warning: command 'set remote memory-read-packet-size' is deprecated.*No alternative known.*" \
7dbd117d 405 "long command deprecated with no alternative /2/"
42f5c13f
MS
406
407 gdb_test "maintenance deprecate" \
408 "\"maintenance deprecate\".*" \
409 "deprecate with no arguments"
003ba290
FN
410}
411
c2b8ed2c
MS
412proc bp_deleted_in_command_test {} {
413 global gdb_prompt
414
c9d37158
DJ
415 if [target_info exists noargs] {
416 verbose "Skipping bp_deleted_in_command_test because of noargs."
417 return
418 }
419
c2b8ed2c
MS
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
ad3986f0
MS
429 gdb_test_multiple "commands" "begin commands in bp_deleted_in_command_test" {
430 -re "Type commands for breakpoint.*>$" {
c2b8ed2c
MS
431 pass "begin commands in bp_deleted_in_command_test"
432 }
c2b8ed2c 433 }
ad3986f0
MS
434 gdb_test_multiple "silent" "add silent command" {
435 -re ">$" {
436 pass "add silent command"
437 }
c2b8ed2c 438 }
ad3986f0
MS
439 gdb_test_multiple "clear factorial" "add clear command" {
440 -re ">$" {
441 pass "add clear command"
442 }
c2b8ed2c 443 }
ad3986f0
MS
444 gdb_test_multiple "printf \"factorial command-list executed\\n\"" \
445 "add printf command" {
446 -re ">$" {
447 pass "add printf command"
448 }
c2b8ed2c 449 }
ad3986f0
MS
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"
003ba290 458
c2b8ed2c
MS
459 gdb_run_cmd
460 gdb_expect {
759f0f0b 461 -re ".*factorial command-list executed.*$gdb_prompt $" {
c2b8ed2c
MS
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
472proc temporary_breakpoint_commands {} {
473 global gdb_prompt
474
c9d37158
DJ
475 if [target_info exists noargs] {
476 verbose "Skipping temporary_breakpoint_commands because of noargs."
477 return
478 }
479
c2b8ed2c
MS
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" \
18ac113b 487 "Temporary breakpoint \[0-9\]+ at .*: file .*/run.c, line \[0-9\]+\." \
c2b8ed2c
MS
488 "breakpoint in temporary_breakpoint_commands"
489
ad3986f0
MS
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"
c2b8ed2c 499 }
c2b8ed2c 500 }
ad3986f0
MS
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"
c2b8ed2c
MS
515
516 gdb_run_cmd
517 gdb_expect {
759f0f0b 518 -re ".*factorial tbreak commands executed.*$gdb_prompt $" {
c2b8ed2c
MS
519 pass "run factorial until temporary breakpoint"
520 }
521 timeout { fail "(timeout) run factorial until temporary breakpoint" }
522 }
523}
61d9b92f
DJ
524
525# Test that GDB can handle $arg0 outside of user functions without
526# crashing.
527proc 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}
e28493f2 544
02e7ef19
JB
545# Test that GDB is able to source a file with an indented comment.
546proc source_file_with_indented_comment {} {
547 set fd [open "file1" w]
548 puts $fd \
549{define my_fun
550 #indented comment
551end
552echo Done!\n}
553 close $fd
554
555 gdb_test "source file1" "Done!" "source file with indented comment"
556}
557
e28493f2
AS
558# Test that GDB can handle arguments when sourcing files recursively.
559# If the arguments are overwritten with ####### then the test has failed.
560proc recursive_source_test {} {
561 set fd [open "file1" w]
562 puts $fd \
563{source file2
564abcdef 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
573end}
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
704a4f78
DJ
591proc 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
609proc 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
fad6eecd
TT
664proc 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
b05dcbb7
TT
698proc 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
c906108c
SS
726gdbvar_simple_if_test
727gdbvar_simple_while_test
728gdbvar_complex_if_while_test
729progvar_simple_if_test
730progvar_simple_while_test
731progvar_complex_if_while_test
732if_while_breakpoint_command_test
733infrun_breakpoint_command_test
734breakpoint_command_test
735user_defined_command_test
085dd6e6 736watchpoint_command_test
7a292a7a 737test_command_prompt_position
003ba290 738deprecated_command_test
c2b8ed2c
MS
739bp_deleted_in_command_test
740temporary_breakpoint_commands
61d9b92f 741stray_arg0_test
02e7ef19 742source_file_with_indented_comment
e28493f2 743recursive_source_test
704a4f78 744if_commands_test
fad6eecd 745redefine_hook_test
b05dcbb7
TT
746# This one should come last, as it redefines "backtrace".
747redefine_backtrace_test
This page took 1.053515 seconds and 4 git commands to generate.