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