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