]>
Commit | Line | Data |
---|---|---|
4a94e368 | 1 | # Copyright 1998-2022 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 | # This file was written by Elena Zannoni. (ezannoni@cygnus.com) |
17 | ||
c906108c SS |
18 | |
19 | # | |
20 | # test running programs | |
21 | # | |
c906108c | 22 | |
f76495c8 | 23 | standard_testfile break.c break1.c |
c906108c | 24 | |
5b362f04 | 25 | if {[prepare_for_testing "failed to prepare" ${testfile} \ |
f76495c8 TT |
26 | [list $srcfile $srcfile2] {debug nowarnings}]} { |
27 | return -1 | |
a1dea79a FF |
28 | } |
29 | ||
a1dea79a FF |
30 | set bp_location1 [gdb_get_line_number "set breakpoint 1 here"] |
31 | set bp_location11 [gdb_get_line_number "set breakpoint 11 here"] | |
32 | ||
4dfef5be SM |
33 | if ![runto_main] then { |
34 | return | |
35 | } | |
c906108c SS |
36 | |
37 | # Verify that GDB allows a user to define their very own commands. | |
38 | # | |
a76e022a MS |
39 | gdb_test_multiple "define nextwhere" "define user command: nextwhere" { |
40 | -re "Type commands for definition of \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$" { | |
41 | gdb_test "next\nbt\nend" "" \ | |
42 | "define user command: nextwhere" | |
43 | } | |
c906108c SS |
44 | } |
45 | ||
46 | # Verify that those commands work as gdb_expected. | |
47 | # | |
a76e022a MS |
48 | gdb_test "nextwhere" \ |
49 | "$bp_location1\[ \t\]*printf.*#0\[ \t\]*main.*:$bp_location1.*" \ | |
50 | "use user command: nextwhere" | |
c906108c SS |
51 | |
52 | # Verify that a user can define a command whose spelling is a | |
53 | # proper substring of another user-defined command. | |
54 | # | |
a76e022a MS |
55 | gdb_test_multiple "define nextwh" "define user command: nextwh" { |
56 | -re "Type commands for definition of \"nextwh\".\r\nEnd with a line saying just \"end\".\r\n>$" { | |
57 | gdb_test "next 2\nbt\nend" "" \ | |
58 | "define user command: nextwh" | |
59 | } | |
c906108c SS |
60 | } |
61 | ||
62 | # Verify that a user can redefine their commands. (Test both the | |
63 | # confirmed and unconfirmed cases.) | |
64 | # | |
a76e022a MS |
65 | gdb_test "define nextwhere" \ |
66 | "Command \"nextwhere\" not redefined.*" \ | |
67 | "redefine user command aborted: nextwhere" \ | |
68 | "Redefine command \"nextwhere\".*y or n. $" \ | |
69 | "n" | |
c906108c SS |
70 | |
71 | send_gdb "define nextwhere\n" | |
72 | gdb_expect { | |
73 | -re "Redefine command \"nextwhere\".*y or n. $"\ | |
74 | {send_gdb "y\n" | |
75 | gdb_expect { | |
76 | -re "Type commands for definition of \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$"\ | |
77 | {send_gdb "bt\nnext\nend\n" | |
78 | gdb_expect { | |
79 | -re "$gdb_prompt $"\ | |
80 | {pass "redefine user command: nextwhere"} | |
81 | timeout {fail "(timeout) redefine user command: nextwhere"} | |
82 | } | |
83 | } | |
84 | timeout {fail "(timeout) redefine user command: nextwhere"} | |
85 | } | |
86 | } | |
87 | -re "$gdb_prompt $"\ | |
88 | {fail "redefine user command: nextwhere"} | |
89 | timeout {fail "(timeout) redefine user command: nextwhere"} | |
90 | } | |
91 | ||
92 | # Verify that GDB gracefully handles an attempt to redefine the | |
93 | # help text for a builtin command. | |
94 | # | |
a76e022a MS |
95 | gdb_test "document step" "Command \"step\" is built-in.*" \ |
96 | "redocumenting builtin command disallowed" | |
c906108c SS |
97 | |
98 | # Verify that a user can document their own commands. (And redocument | |
99 | # them.) | |
100 | # | |
a76e022a MS |
101 | gdb_test_multiple "document nextwhere" "document user command: nextwhere" { |
102 | -re "Type documentation for \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$" { | |
103 | gdb_test "A next command that first shows you where you're stepping from.\nend" \ | |
104 | "" \ | |
105 | "document user command: nextwhere" | |
106 | } | |
c906108c SS |
107 | } |
108 | ||
a76e022a MS |
109 | gdb_test_multiple "document nextwhere" "re-document user command: nextwhere" { |
110 | -re "Type documentation for \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$" { | |
111 | gdb_test "A next command that first shows you where you're stepping from.\nend" \ | |
112 | "" \ | |
113 | "re-document user command: nextwhere" | |
114 | } | |
c906108c SS |
115 | } |
116 | ||
a76e022a MS |
117 | gdb_test "help nextwhere" \ |
118 | "A next command that first shows you where you're stepping from.*" \ | |
119 | "help user command: nextwhere" | |
c906108c | 120 | |
311a4e6b TJB |
121 | # Verify that the document command preserves whitespace in the beginning of the line. |
122 | # | |
a76e022a MS |
123 | gdb_test_multiple "document nextwhere" "set up whitespace in help string" { |
124 | -re "Type documentation for \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$" { | |
125 | gdb_test " A next command that first shows you where you're stepping from.\nend" \ | |
126 | "" \ | |
127 | "set up whitespace in help string" | |
128 | } | |
311a4e6b TJB |
129 | } |
130 | ||
a76e022a MS |
131 | gdb_test "help nextwhere" \ |
132 | " A next command that first shows you where you're stepping from.*" \ | |
133 | "preserve whitespace in help string" | |
311a4e6b | 134 | |
be09caf1 PW |
135 | # Verify that GDB allows a user to use . in a command name. |
136 | # | |
137 | gdb_test_multiple "define dot.command" "define user command: dot.command" { | |
138 | -re "Type commands for definition of \"dot.command\".\r\nEnd with a line saying just \"end\".\r\n>$" { | |
139 | gdb_test "echo dot command\\n\nend" "" \ | |
140 | "define user command: dot.command" | |
141 | } | |
142 | } | |
143 | ||
144 | # Verify that dot.command works. | |
145 | # | |
146 | gdb_test "dot.command" \ | |
147 | "dot command" \ | |
148 | "full name dot.command" | |
149 | gdb_test "dot" \ | |
150 | "dot command" \ | |
151 | "partial name dot" | |
152 | gdb_test "dot." \ | |
153 | "dot command" \ | |
154 | "partial name dot." | |
155 | gdb_test "dot.c" \ | |
156 | "dot command" \ | |
157 | "partial name dot.c" | |
158 | ||
159 | ||
33f2d567 JM |
160 | # Verify that the command parser doesn't require a space after an 'if' |
161 | # command in a user defined function. | |
162 | # | |
163 | gdb_test_multiple "define ifnospace" "define user command: ifnospace" \ | |
164 | { | |
165 | -re "Type commands for definition of \"ifnospace\".\r\nEnd with a line saying just \"end\".\r\n>$" \ | |
166 | { | |
167 | gdb_test_multiple "if(3<4)\nprint \"hi there\\n\"\nend\nend" "send body of ifnospace" \ | |
168 | { | |
169 | -re "$gdb_prompt $"\ | |
170 | {pass "define user command: ifnospace"} | |
171 | } | |
172 | } | |
173 | } | |
174 | ||
175 | gdb_test "ifnospace" ".*hi there.*" "test ifnospace is parsed correctly" | |
176 | ||
604c4576 JG |
177 | # Verify that the command parser properly handles command abbreviations. |
178 | with_test_prefix "command abbreviations in define" { | |
179 | set test "define user command: breakmain" | |
180 | gdb_test_multiple "define breakmain" "$test" { | |
181 | -re "Type commands for definition of \"breakmain\".\r\nEnd with a line saying just \"end\".\r\n>$" { | |
182 | pass "$test" | |
183 | set test "send body of breakmain" | |
e777225b | 184 | gdb_test_multiple "break -q main\ncommand\necho\nend\nend" "$test" { |
604c4576 JG |
185 | -re "$gdb_prompt $"\ |
186 | {pass "$test"} | |
187 | } | |
188 | } | |
189 | } | |
190 | ||
191 | gdb_test "breakmain" ".*Breakpoint .*" "run user command" | |
192 | ||
193 | # If GDB fails to interpret properly the abbrev "command", the last "end" | |
194 | # will be missing. Issue it to avoid a desync that would break the other | |
195 | # tests in this file. | |
196 | gdb_test "end" \ | |
197 | "This command cannot be used at the top level.*" \ | |
198 | "additional end command" | |
199 | ||
200 | gdb_test "info break \$bpnum" \ | |
201 | [multi_line \ | |
202 | "Num Type\[ \]+Disp Enb Address\[ \]+What.*" \ | |
203 | "\[0-9\]+\[\t \]+breakpoint keep y.* in main at .*" \ | |
204 | "\[\t \]+echo.*"] \ | |
205 | "info break shows echo command" | |
206 | } | |
207 | ||
208 | ||
33f2d567 JM |
209 | # Verify that the command parser doesn't require a space after an 'while' |
210 | # command in a user defined function. | |
211 | # | |
212 | gdb_test_multiple "define whilenospace" "define user command: whilenospace" \ | |
213 | { | |
214 | -re "Type commands for definition of \"whilenospace\".\r\nEnd with a line saying just \"end\".\r\n>$" \ | |
215 | { | |
216 | gdb_test_multiple "set \$i=1\nwhile(\$i<2)\nset \$i=2\nprint \"hi there\\n\"\nend\nend" "send body of whilenospace" \ | |
217 | { | |
218 | -re "$gdb_prompt $" \ | |
219 | {pass "define user command: whilenospace"} | |
220 | } | |
221 | } | |
222 | } | |
223 | ||
224 | gdb_test "whilenospace" ".*hi there.*" "test whilenospace is parsed correctly" | |
225 | ||
c906108c SS |
226 | # Verify that the user can "hook" a builtin command. We choose to |
227 | # hook the "stop" pseudo command, and we'll define it to use a user- | |
228 | # define command. | |
229 | # | |
a76e022a MS |
230 | gdb_test_multiple "define user-bt" "define user command: user-bt" { |
231 | -re "Type commands for definition of \"user-bt\".\r\nEnd with a line saying just \"end\".\r\n>$" { | |
232 | gdb_test "bt\nend" \ | |
233 | "" \ | |
234 | "define user command: user-bt" | |
235 | } | |
c906108c SS |
236 | } |
237 | ||
a76e022a MS |
238 | gdb_test_multiple "define hook-stop" "define hook-stop command" { |
239 | -re "Type commands for definition of \"hook-stop\".\r\nEnd with a line saying just \"end\".\r\n>$" { | |
240 | gdb_test "user-b\nend" \ | |
241 | "" \ | |
242 | "define hook-stop command" | |
243 | } | |
c906108c SS |
244 | } |
245 | ||
a76e022a MS |
246 | gdb_test "next" "#0\[ \t\]*main.*:$bp_location11.*" \ |
247 | "use hook-stop command" | |
c906108c SS |
248 | |
249 | # Verify that GDB responds gracefully to an attempt to define a "hook | |
250 | # command" which doesn't exist. (Test both the confirmed and unconfirmed | |
251 | # cases.) | |
252 | # | |
a76e022a MS |
253 | gdb_test "define hook-bar" \ |
254 | "Not confirmed.*" \ | |
255 | "define hook undefined command aborted: bar" \ | |
256 | "warning: Your new `hook-bar' command does not hook any existing command.\r\nProceed.*y or n. $" \ | |
257 | "n" | |
c906108c SS |
258 | |
259 | send_gdb "define hook-bar\n" | |
260 | gdb_expect { | |
261 | -re "warning: Your new `hook-bar' command does not hook any existing command.\r\nProceed.*y or n. $"\ | |
262 | {send_gdb "y\n" | |
263 | gdb_expect { | |
264 | -re "Type commands for definition of \"hook-bar\".\r\nEnd with a line saying just \"end\".\r\n>$"\ | |
265 | {send_gdb "nextwhere\nend\n" | |
266 | gdb_expect { | |
267 | -re "$gdb_prompt $"\ | |
268 | {pass "define hook undefined command: bar"} | |
269 | timeout {fail "(timeout) define hook undefined command: bar"} | |
270 | } | |
271 | } | |
272 | -re "$gdb_prompt $"\ | |
273 | {fail "define hook undefined command: bar"} | |
274 | timeout {fail "(timeout) define hook undefined command: bar"} | |
275 | } | |
276 | } | |
277 | -re "$gdb_prompt $"\ | |
278 | {fail "define hook undefined command: bar"} | |
279 | timeout {fail "(timeout) define hook undefined command: bar"} | |
280 | } | |
281 | ||
adb483fe DJ |
282 | # Test creation of an additional target subcommand. |
283 | gdb_test_multiple "define target testsuite" "" { | |
284 | -re "Type commands for definition of \"target testsuite\".\r\nEnd with a line saying just \"end\".\r\n>$" { | |
285 | gdb_test "printf \"hello\\n\"\nend" "" "define target testsuite" | |
286 | } | |
287 | } | |
288 | gdb_test_multiple "document target testsuite" "" { | |
289 | -re "Type documentation for \"target testsuite\".\r\nEnd with a line saying just \"end\".\r\n>$" { | |
290 | gdb_test "A test target.\nend" "" "document target testsuite" | |
291 | } | |
292 | } | |
293 | ||
294 | gdb_test "help target" ".*A test target.*" | |
295 | gdb_test "target testsuite" "hello" | |
296 | gdb_test "show user target testsuite" "User command \"target testsuite\":\r\n printf \"hello\\\\n\"\r\n" | |
297 | ||
298 | # We should even be able to hook subcommands. | |
299 | gdb_test_multiple "define target hook-testsuite" "" { | |
300 | -re "Type commands for definition of \"target hook-testsuite\".\r\nEnd with a line saying just \"end\".\r\n>$" { | |
301 | gdb_test "printf \"one\\n\"\nend" "" "define target hook-testsuite" | |
302 | } | |
303 | } | |
304 | ||
305 | gdb_test_multiple "define target hookpost-testsuite" "" { | |
306 | -re "Type commands for definition of \"target hookpost-testsuite\".\r\nEnd with a line saying just \"end\".\r\n>$" { | |
307 | gdb_test "printf \"two\\n\"\nend" "" "define target hookpost-testsuite" | |
308 | } | |
309 | } | |
310 | ||
311 | gdb_test "target testsuite" "one\r\nhello\r\ntwo" "target testsuite with hooks" | |
312 | ||
b863685d RB |
313 | # Save the GDB prompt so it can be restored to the original value later. |
314 | set prior_prompt "" | |
315 | gdb_test_multiple "show prompt" "save gdb_prompt" { | |
316 | -re "Gdb's prompt is \"($gdb_prompt) \"\.\[\r\n\]*$gdb_prompt $" { | |
317 | set prior_prompt $expect_out(1,string) | |
318 | pass "save gdb_prompt" | |
319 | } | |
320 | } | |
321 | ||
c906108c SS |
322 | # This is a quasi-define command: Verify that the user can redefine |
323 | # GDB's gdb_prompt. | |
324 | # | |
a76e022a MS |
325 | gdb_test_multiple "set prompt \\(blah\\) " "set gdb_prompt" { |
326 | -re "\\(blah\\) $" { | |
327 | pass "set gdb_prompt" | |
328 | } | |
c906108c SS |
329 | } |
330 | ||
b863685d | 331 | gdb_test_multiple "set prompt $prior_prompt " "reset gdb_prompt" { |
b528dae0 | 332 | -re "\r\n$gdb_prompt $" { |
a76e022a MS |
333 | pass "reset gdb_prompt" |
334 | } | |
c906108c SS |
335 | } |
336 | ||
7a2c85f2 TT |
337 | gdb_test_multiple "define do-define" "" { |
338 | -re "Type commands for definition of \"do-define\".\r\nEnd with a line saying just \"end\".\r\n>$" { | |
339 | gdb_test "define do-printit\necho here\\n\nend\nend" "" "define do-define" | |
340 | } | |
341 | } | |
342 | gdb_test_no_output "do-define" "invoke do-define" | |
343 | gdb_test "do-printit" "here" "invoke do-printit" | |
344 | ||
c906108c SS |
345 | gdb_exit |
346 | return 0 |