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