Commit | Line | Data |
---|---|---|
6aba47ca | 1 | # Copyright 1998, 1999, 2001, 2003, 2004, 2007 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 SS |
15 | |
16 | # Please email any bugs, comments, and/or additions to this file to: | |
17 | # bug-gdb@prep.ai.mit.edu | |
18 | ||
19 | # This file was written by Elena Zannoni. (ezannoni@cygnus.com) | |
20 | ||
21 | if $tracelevel then { | |
22 | strace $tracelevel | |
23 | } | |
24 | ||
25 | global usestubs | |
26 | ||
27 | ||
28 | # | |
29 | # test running programs | |
30 | # | |
31 | set prms_id 0 | |
32 | set bug_id 0 | |
33 | ||
34 | set testfile "break" | |
35 | set srcfile ${testfile}.c | |
a1dea79a | 36 | set srcfile1 ${testfile}1.c |
c906108c SS |
37 | set binfile ${objdir}/${subdir}/${testfile} |
38 | ||
fc91c6c2 | 39 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } { |
b60f0898 JB |
40 | untested define.exp |
41 | return -1 | |
a1dea79a FF |
42 | } |
43 | ||
fc91c6c2 | 44 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } { |
b60f0898 JB |
45 | untested define.exp |
46 | return -1 | |
a1dea79a FF |
47 | } |
48 | ||
fc91c6c2 | 49 | if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } { |
b60f0898 JB |
50 | untested define.exp |
51 | return -1 | |
c906108c SS |
52 | } |
53 | ||
54 | gdb_exit | |
55 | gdb_start | |
56 | gdb_reinitialize_dir $srcdir/$subdir | |
57 | gdb_load ${binfile} | |
58 | ||
a1dea79a FF |
59 | set bp_location1 [gdb_get_line_number "set breakpoint 1 here"] |
60 | set bp_location11 [gdb_get_line_number "set breakpoint 11 here"] | |
61 | ||
c906108c SS |
62 | if ![runto_main] then { fail "define tests suppressed" } |
63 | ||
64 | # Verify that GDB allows a user to define their very own commands. | |
65 | # | |
66 | send_gdb "define nextwhere\n" | |
67 | gdb_expect { | |
68 | -re "Type commands for definition of \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$"\ | |
69 | {send_gdb "next\nbt\nend\n" | |
70 | gdb_expect { | |
71 | -re "$gdb_prompt $"\ | |
72 | {pass "define user command: nextwhere"} | |
73 | timeout {fail "(timeout) define user command: nextwhere"} | |
74 | } | |
75 | } | |
76 | -re "$gdb_prompt $"\ | |
77 | {fail "define user command: nextwhere"} | |
78 | timeout {fail "(timeout) define user command: nextwhere"} | |
79 | } | |
80 | ||
81 | # Verify that those commands work as gdb_expected. | |
82 | # | |
83 | send_gdb "nextwhere\n" | |
84 | gdb_expect { | |
a1dea79a | 85 | -re ".*$bp_location1\[ \t\]*printf.*#0\[ \t\]*main.*:$bp_location1.*$gdb_prompt $"\ |
c906108c SS |
86 | {pass "use user command: nextwhere"} |
87 | -re "$gdb_prompt $"\ | |
88 | {fail "use user command: nextwhere"} | |
89 | timeout {fail "(timeout) use user command: nextwhere"} | |
90 | } | |
91 | ||
92 | # Verify that a user can define a command whose spelling is a | |
93 | # proper substring of another user-defined command. | |
94 | # | |
95 | send_gdb "define nextwh\n" | |
96 | gdb_expect { | |
97 | -re "Type commands for definition of \"nextwh\".\r\nEnd with a line saying just \"end\".\r\n>$"\ | |
98 | {send_gdb "next 2\nbt\nend\n" | |
99 | gdb_expect { | |
100 | -re "$gdb_prompt $"\ | |
101 | {pass "define user command: nextwh"} | |
102 | timeout {fail "(timeout) define user command: nextwh"} | |
103 | } | |
104 | } | |
105 | -re "$gdb_prompt $"\ | |
106 | {fail "define user command: nextwh"} | |
107 | timeout {fail "(timeout) define user command: nextwh"} | |
108 | } | |
109 | ||
110 | # Verify that a user can redefine their commands. (Test both the | |
111 | # confirmed and unconfirmed cases.) | |
112 | # | |
113 | send_gdb "define nextwhere\n" | |
114 | gdb_expect { | |
115 | -re "Redefine command \"nextwhere\".*y or n. $"\ | |
116 | {send_gdb "n\n" | |
117 | gdb_expect { | |
118 | -re "Command \"nextwhere\" not redefined.*$gdb_prompt $"\ | |
119 | {pass "redefine user command aborted: nextwhere"} | |
120 | -re "$gdb_prompt $"\ | |
121 | {fail "redefine user command aborted: nextwhere"} | |
122 | timeout {fail "(timeout) redefine user command aborted: nextwhere"} | |
123 | } | |
124 | } | |
125 | -re "$gdb_prompt $"\ | |
126 | {fail "redefine user command aborted: nextwhere"} | |
127 | timeout {fail "(timeout) redefine user command aborted: nextwhere"} | |
128 | } | |
129 | ||
130 | send_gdb "define nextwhere\n" | |
131 | gdb_expect { | |
132 | -re "Redefine command \"nextwhere\".*y or n. $"\ | |
133 | {send_gdb "y\n" | |
134 | gdb_expect { | |
135 | -re "Type commands for definition of \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$"\ | |
136 | {send_gdb "bt\nnext\nend\n" | |
137 | gdb_expect { | |
138 | -re "$gdb_prompt $"\ | |
139 | {pass "redefine user command: nextwhere"} | |
140 | timeout {fail "(timeout) redefine user command: nextwhere"} | |
141 | } | |
142 | } | |
143 | timeout {fail "(timeout) redefine user command: nextwhere"} | |
144 | } | |
145 | } | |
146 | -re "$gdb_prompt $"\ | |
147 | {fail "redefine user command: nextwhere"} | |
148 | timeout {fail "(timeout) redefine user command: nextwhere"} | |
149 | } | |
150 | ||
151 | # Verify that GDB gracefully handles an attempt to redefine the | |
152 | # help text for a builtin command. | |
153 | # | |
154 | send_gdb "document step\n" | |
155 | gdb_expect { | |
156 | -re "Command \"step\" is built-in..*$gdb_prompt $"\ | |
157 | {pass "redocumenting builtin command disallowed"} | |
158 | -re "$gdb_prompt $"\ | |
159 | {fail "redocumenting builtin command disallowed"} | |
160 | timeout {fail "(timeout) redocumenting builtin command disallowed"} | |
161 | } | |
162 | ||
163 | # Verify that a user can document their own commands. (And redocument | |
164 | # them.) | |
165 | # | |
166 | send_gdb "document nextwhere\n" | |
167 | gdb_expect { | |
168 | -re "Type documentation for \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$"\ | |
169 | {send_gdb "A next command that frist shows you where you're stepping from.\nend\n" | |
170 | gdb_expect { | |
171 | -re "$gdb_prompt $"\ | |
172 | {pass "document user command: nextwhere"} | |
173 | timeout {fail "(timeout) document user command: nextwhere"} | |
174 | } | |
175 | } | |
176 | -re "$gdb_prompt $"\ | |
7dbd117d MC |
177 | {fail "document user command: nextwhere"} |
178 | timeout {fail "(timeout) document user command: nextwhere"} | |
c906108c SS |
179 | } |
180 | ||
181 | send_gdb "document nextwhere\n" | |
182 | gdb_expect { | |
183 | -re "Type documentation for \"nextwhere\".\r\nEnd with a line saying just \"end\".\r\n>$"\ | |
184 | {send_gdb "A next command that first shows you where you're stepping from.\nend\n" | |
185 | gdb_expect { | |
186 | -re "$gdb_prompt $"\ | |
7dbd117d MC |
187 | {pass "re-document user command: nextwhere"} |
188 | timeout {fail "(timeout) re-document user command: nextwhere"} | |
c906108c SS |
189 | } |
190 | } | |
191 | -re "$gdb_prompt $"\ | |
7dbd117d MC |
192 | {fail "re-document user command: nextwhere"} |
193 | timeout {fail "(timeout) re-document user command: nextwhere"} | |
c906108c SS |
194 | } |
195 | ||
196 | send_gdb "help nextwhere\n" | |
197 | gdb_expect { | |
198 | -re "A next command that first shows you where you're stepping from.\r\n$gdb_prompt $"\ | |
199 | {pass "help user command: nextwhere"} | |
200 | -re "$gdb_prompt $"\ | |
201 | {fail "help user command: nextwhere"} | |
202 | timeout {fail "(timeout) help user command: nextwhere"} | |
203 | } | |
204 | ||
33f2d567 JM |
205 | # Verify that the command parser doesn't require a space after an 'if' |
206 | # command in a user defined function. | |
207 | # | |
208 | gdb_test_multiple "define ifnospace" "define user command: ifnospace" \ | |
209 | { | |
210 | -re "Type commands for definition of \"ifnospace\".\r\nEnd with a line saying just \"end\".\r\n>$" \ | |
211 | { | |
212 | gdb_test_multiple "if(3<4)\nprint \"hi there\\n\"\nend\nend" "send body of ifnospace" \ | |
213 | { | |
214 | -re "$gdb_prompt $"\ | |
215 | {pass "define user command: ifnospace"} | |
216 | } | |
217 | } | |
218 | } | |
219 | ||
220 | gdb_test "ifnospace" ".*hi there.*" "test ifnospace is parsed correctly" | |
221 | ||
222 | # Verify that the command parser doesn't require a space after an 'while' | |
223 | # command in a user defined function. | |
224 | # | |
225 | gdb_test_multiple "define whilenospace" "define user command: whilenospace" \ | |
226 | { | |
227 | -re "Type commands for definition of \"whilenospace\".\r\nEnd with a line saying just \"end\".\r\n>$" \ | |
228 | { | |
229 | gdb_test_multiple "set \$i=1\nwhile(\$i<2)\nset \$i=2\nprint \"hi there\\n\"\nend\nend" "send body of whilenospace" \ | |
230 | { | |
231 | -re "$gdb_prompt $" \ | |
232 | {pass "define user command: whilenospace"} | |
233 | } | |
234 | } | |
235 | } | |
236 | ||
237 | gdb_test "whilenospace" ".*hi there.*" "test whilenospace is parsed correctly" | |
238 | ||
c906108c SS |
239 | # Verify that the user can "hook" a builtin command. We choose to |
240 | # hook the "stop" pseudo command, and we'll define it to use a user- | |
241 | # define command. | |
242 | # | |
243 | send_gdb "define user-bt\n" | |
244 | gdb_expect { | |
245 | -re "Type commands for definition of \"user-bt\".\r\nEnd with a line saying just \"end\".\r\n>$"\ | |
246 | {send_gdb "bt\nend\n" | |
247 | gdb_expect { | |
248 | -re "$gdb_prompt $"\ | |
249 | {pass "define user command: user-bt"} | |
250 | timeout {fail "(timeout) define user command: user-bt"} | |
251 | } | |
252 | } | |
253 | -re "$gdb_prompt $"\ | |
254 | {fail "define user command: user-bt"} | |
255 | timeout {fail "(timeout) define user command: user-bt"} | |
256 | } | |
257 | ||
258 | send_gdb "define hook-stop\n" | |
259 | gdb_expect { | |
260 | -re "Type commands for definition of \"hook-stop\".\r\nEnd with a line saying just \"end\".\r\n>$"\ | |
261 | {send_gdb "user-b\nend\n" | |
262 | gdb_expect { | |
263 | -re "$gdb_prompt $"\ | |
264 | {pass "define hook-stop command"} | |
265 | timeout {fail "(timeout) define hook-stop command"} | |
266 | } | |
267 | } | |
268 | -re "$gdb_prompt $"\ | |
269 | {fail "define hook-stop command"} | |
270 | timeout {fail "(timeout) define hook-stop command"} | |
271 | } | |
272 | ||
273 | send_gdb "next\n" | |
274 | gdb_expect { | |
a1dea79a | 275 | -re "#0\[ \t\]*main.*:$bp_location11.*$gdb_prompt $"\ |
c906108c SS |
276 | {pass "use hook-stop command"} |
277 | -re "$gdb_prompt $"\ | |
278 | {fail "use hook-stop command"} | |
279 | timeout {fail "(timeout) use hook-stop command"} | |
280 | } | |
281 | ||
282 | # Verify that GDB responds gracefully to an attempt to define a "hook | |
283 | # command" which doesn't exist. (Test both the confirmed and unconfirmed | |
284 | # cases.) | |
285 | # | |
286 | send_gdb "define hook-bar\n" | |
287 | gdb_expect { | |
288 | -re "warning: Your new `hook-bar' command does not hook any existing command.\r\nProceed.*y or n. $"\ | |
289 | {send_gdb "n\n" | |
290 | gdb_expect { | |
291 | -re "Not confirmed.*$gdb_prompt $"\ | |
292 | {pass "define hook undefined command aborted: bar"} | |
293 | -re "$gdb_prompt $"\ | |
294 | {fail "define hook undefined command aborted: bar"} | |
295 | timeout {fail "(timeout) define hook undefined command aborted: bar"} | |
296 | } | |
297 | } | |
298 | -re "$gdb_prompt $"\ | |
299 | {fail "define hook undefined command aborted: bar"} | |
300 | timeout {fail "(timeout) define hook undefined command aborted: bar"} | |
301 | } | |
302 | ||
303 | send_gdb "define hook-bar\n" | |
304 | gdb_expect { | |
305 | -re "warning: Your new `hook-bar' command does not hook any existing command.\r\nProceed.*y or n. $"\ | |
306 | {send_gdb "y\n" | |
307 | gdb_expect { | |
308 | -re "Type commands for definition of \"hook-bar\".\r\nEnd with a line saying just \"end\".\r\n>$"\ | |
309 | {send_gdb "nextwhere\nend\n" | |
310 | gdb_expect { | |
311 | -re "$gdb_prompt $"\ | |
312 | {pass "define hook undefined command: bar"} | |
313 | timeout {fail "(timeout) define hook undefined command: bar"} | |
314 | } | |
315 | } | |
316 | -re "$gdb_prompt $"\ | |
317 | {fail "define hook undefined command: bar"} | |
318 | timeout {fail "(timeout) define hook undefined command: bar"} | |
319 | } | |
320 | } | |
321 | -re "$gdb_prompt $"\ | |
322 | {fail "define hook undefined command: bar"} | |
323 | timeout {fail "(timeout) define hook undefined command: bar"} | |
324 | } | |
325 | ||
326 | # This is a quasi-define command: Verify that the user can redefine | |
327 | # GDB's gdb_prompt. | |
328 | # | |
329 | send_gdb "set prompt \\(blah\\) \n" | |
330 | gdb_expect { | |
331 | -re "\\(blah\\) $"\ | |
332 | {pass "set gdb_prompt"} | |
333 | -re "$gdb_prompt $"\ | |
334 | {fail "set gdb_prompt"} | |
335 | timeout {fail "(timeout) set gdb_prompt"} | |
336 | } | |
337 | ||
338 | send_gdb "set prompt \\(gdb\\) \n" | |
339 | gdb_expect { | |
340 | -re "$gdb_prompt $"\ | |
341 | {pass "reset gdb_prompt"} | |
342 | timeout {fail "(timeout) reset gdb_prompt"} | |
343 | } | |
344 | ||
345 | gdb_exit | |
346 | return 0 | |
347 | ||
348 | ||
349 | ||
350 | ||
351 | ||
352 |