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