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