2001-08-02 Michael Snyder <msnyder@redhat.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / completion.exp
1 # Copyright 1998, 1999 Free Software Foundation, Inc.
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
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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 # This file is part of the gdb testsuite.
23
24 #
25 # tests for command completion
26 #
27 # Here are some useful test cases for completion.
28 # They should be tested with both M-? and TAB.
29 #
30 # "show output-" "radix"
31 # "show output" "-radix"
32 # "p" ambiguous (commands starting with p--path, print, printf, etc.)
33 # "p " ambiguous (all symbols)
34 # "info t foo" no completions
35 # "info t " no completions
36 # "info t" ambiguous ("info target", "info terminal", etc.)
37 # "info ajksdlfk" no completions
38 # "info ajksdlfk " no completions
39 # "info" " "
40 # "info " ambiguous (all info commands)
41 # "p \"a" no completions (string constant)
42 # "p 'a" ambiguous (all symbols starting with a)
43 # "p b-a" ambiguous (all symbols starting with a)
44 # "p b-" ambiguous (all symbols)
45 # "file Make" "file" (word break hard to screw up here)
46 # "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
47 #
48
49
50 if $tracelevel then {
51 strace $tracelevel
52 }
53
54
55 global usestubs
56
57 #
58 # test running programs
59 #
60 set prms_id 0
61 set bug_id 0
62
63 set testfile "break"
64 set srcfile ${testfile}.c
65 set binfile ${objdir}/${subdir}/${testfile}
66 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-w}] != "" } {
67 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
68 }
69
70 if [get_compiler_info ${binfile}] {
71 return -1;
72 }
73
74 gdb_exit
75
76 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
77 # the test results. Even if /dev/null doesn't exist on the particular
78 # platform, the readline library will use the default setting just by
79 # failing to open the file. OTOH, opening /dev/null successfully will
80 # also result in the default settings being used since nothing will be
81 # read from this file.
82 global env
83 if [info exists env(INPUTRC)] {
84 set old_inputrc $env(INPUTRC)
85 }
86 set env(INPUTRC) "/dev/null"
87
88 gdb_start
89 gdb_reinitialize_dir $srcdir/$subdir
90 gdb_load ${binfile}
91
92 if ![runto_main] then {
93 perror "tests suppressed"
94 }
95
96 set oldtimeout1 $timeout
97 set timeout 30
98
99
100 send_gdb "hfgfh\t"
101 sleep 1
102 gdb_expect {
103 -re "^hfgfh\\\x07$"\
104 { send_gdb "\n"
105 gdb_expect {
106 -re "Undefined command: \"hfgfh\"\\. Try \"help\"\\..*$gdb_prompt $"\
107 { pass "complete 'hfgfh'"}
108 -re ".*$gdb_prompt $" { fail "complete 'hfgfh'"}
109 timeout {fail "(timeout) complete 'hfgfh'"}
110 }
111 }
112 -re ".*$gdb_prompt $" { fail "complete 'hfgfh'" }
113 timeout { fail "(timeout) complete 'hfgfh'" }
114 }
115
116 #exp_internal 0
117
118 send_gdb "show output\t"
119 sleep 1
120 gdb_expect {
121 -re "^show output-radix $"\
122 { send_gdb "\n"
123 gdb_expect {
124 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
125 { pass "complete 'show output'"}
126 -re ".*$gdb_prompt $" { fail "complete 'show output'"}
127 timeout {fail "(timeout) complete 'show output'"}
128 }
129 }
130 -re "^show output$"\
131 { send_gdb "\n"
132 gdb_expect {
133 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
134 { fail "complete 'show output'"}
135 -re ".*$gdb_prompt $" { fail "complete 'show output'"}
136 timeout { fail "(timeout) complete 'show output'"}
137 }
138
139 }
140
141 -re ".*$gdb_prompt $" { fail "complete 'show output'" }
142 timeout { fail "(timeout) complete 'show output'" }
143 }
144
145
146 send_gdb "show output-\t"
147 sleep 1
148 gdb_expect {
149 -re "^show output-radix $"\
150 { send_gdb "\n"
151 gdb_expect {
152 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
153 { pass "complete 'show output-'"}
154 -re ".*$gdb_prompt $" { fail "complete 'show output-'"}
155 timeout {fail "(timeout) complete 'show output-'"}
156 }
157 }
158 -re "^show output-$"\
159 { send_gdb "\n"
160 gdb_expect {
161 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
162 { fail "complete 'show output-'"}
163 -re ".*$gdb_prompt $" { fail "complete 'show output-'"}
164 timeout { fail "(timeout) complete 'show output-'"}
165 }
166
167 }
168
169 -re ".*$gdb_prompt $" { fail "complete 'show output-'" }
170 timeout { fail "(timeout) complete 'show output-'" }
171 }
172
173 send_gdb "p\t"
174 sleep 1
175 gdb_expect {
176 -re "^p\\\x07$"\
177 { send_gdb "\n"
178 sleep 1
179 gdb_expect {
180 -re "The history is empty\\..*$gdb_prompt $"\
181 { pass "complete 'p'"}
182 -re ".*$gdb_prompt $" { fail "complete 'p'"}
183 timeout {fail "(timeout) complete 'p' 2"}
184 }
185 }
186 -re ".*$gdb_prompt $" { fail "complete 'p'" }
187 timeout { fail "(timeout) complete 'p' 1" }
188 }
189
190 send_gdb "p \t"
191 sleep 3
192 gdb_expect {
193 -re "^p \\\x07$"\
194 { send_gdb "\n"
195 sleep 1
196 gdb_expect {
197 -re "The history is empty\\..*$gdb_prompt $"\
198 { pass "complete 'p '"}
199 -re ".*$gdb_prompt $" { fail "complete 'p '"}
200 timeout {fail "(timeout) complete 'p ' 1"}
201 }
202 }
203 -re ".*$gdb_prompt $" { fail "complete 'p '" }
204 timeout { fail "(timeout) complete 'p ' 2" }
205 }
206
207
208 send_gdb "info t foo\t"
209 sleep 1
210 gdb_expect {
211 -re "^info t foo\\\x07$"\
212 { send_gdb "\n"
213 gdb_expect {
214 -re "Ambiguous info command \"t foo\": target, terminal, threads, tp, tracepoints, types\\..*$gdb_prompt $"\
215 { pass "complete 'info t foo'"}
216 -re ".*$gdb_prompt $" { fail "complete 'info t foo'"}
217 timeout {fail "(timeout) complete 'info t foo'"}
218 }
219 }
220 -re ".*$gdb_prompt $" { fail "complete 'info t foo'" }
221 timeout { fail "(timeout) complete 'info t foo'" }
222 }
223
224 send_gdb "info t\t"
225 sleep 1
226 gdb_expect {
227 -re "^info t\\\x07$"\
228 { send_gdb "\n"
229 gdb_expect {
230 -re "Ambiguous info command \"t\": target, terminal, threads, tp, tracepoints, types\\..
231 *$gdb_prompt $"\
232 { pass "complete 'info t'"}
233 -re ".*$gdb_prompt $" { fail "complete 'info t'"}
234 timeout {fail "(timeout) complete 'info t'"}
235 }
236 }
237 -re ".*$gdb_prompt $" { fail "complete 'info t'" }
238 timeout { fail "(timeout) complete 'info t'" }
239 }
240
241
242 send_gdb "info t \t"
243 sleep 1
244 gdb_expect {
245 -re "^info t \\\x07$"\
246 { send_gdb "\n"
247 gdb_expect {
248 -re "Ambiguous info command \"t \": target, terminal, threads, tp, tracepoints, types\\..
249 *$gdb_prompt $"\
250 { pass "complete 'info t '"}
251 -re ".*$gdb_prompt $" { fail "complete 'info t '"}
252 timeout {fail "(timeout) complete 'info t '"}
253 }
254 }
255 -re ".*$gdb_prompt $" { fail "complete 'info t '" }
256 timeout { fail "(timeout) complete 'info t '" }
257 }
258
259
260 send_gdb "info asdfgh\t"
261 sleep 1
262 gdb_expect {
263 -re "^info asdfgh\\\x07$"\
264 { send_gdb "\n"
265 gdb_expect {
266 -re "Undefined info command: \"asdfgh\". Try \"help info\"\\..
267 *$gdb_prompt $"\
268 { pass "complete 'info asdfgh'"}
269 -re ".*$gdb_prompt $" { fail "complete 'info asdfgh'"}
270 timeout {fail "(timeout) complete 'info asdfgh'"}
271 }
272 }
273 -re ".*$gdb_prompt $" { fail "complete 'info asdfgh'" }
274 timeout { fail "(timeout) complete 'info asdfgh'" }
275 }
276
277
278 send_gdb "info asdfgh \t"
279 sleep 1
280 gdb_expect {
281 -re "^info asdfgh \\\x07$"\
282 { send_gdb "\n"
283 gdb_expect {
284 -re "Undefined info command: \"asdfgh \". Try \"help info\"\\..
285 *$gdb_prompt $"\
286 { pass "complete 'info asdfgh '"}
287 -re ".*$gdb_prompt $" { fail "complete 'info asdfgh '"}
288 timeout {fail "(timeout) complete 'info asdfgh '"}
289 }
290 }
291 -re ".*$gdb_prompt $" { fail "complete 'info asdfgh '" }
292 timeout { fail "(timeout) complete 'info asdfgh '" }
293 }
294
295 send_gdb "info\t"
296 sleep 1
297 gdb_expect {
298 -re "^info $"\
299 { send_gdb "\n"
300 gdb_expect {
301 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands:\r\n\r\n.*info address.*info watchpoints.*\r\n\r\nType \"help info\" followed by info subcommand name for full documentation.\r\nCommand name abbreviations are allowed if unambiguous\\..*$gdb_prompt $"\
302 { pass "complete 'info'"}
303 -re ".*$gdb_prompt $" { fail "complete 'info'"}
304 timeout {fail "(timeout) complete 'info'"}
305 }
306 }
307 -re ".*$gdb_prompt $" { fail "complete 'info'" }
308 timeout { fail "(timeout) complete 'info'" }
309 }
310
311 send_gdb "info \t"
312 sleep 1
313 gdb_expect {
314 -re "^info \\\x07$"\
315 { send_gdb "\n"
316 gdb_expect {
317 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands:\r\n\r\n.*info address.*Type \"help info\" followed by info subcommand name for full documentation.\r\nCommand name abbreviations are allowed if unambiguous\\..*$gdb_prompt $"\
318 { pass "complete 'info '"}
319 -re ".*$gdb_prompt $" { fail "complete 'info '"}
320 timeout {fail "(timeout) complete 'info '"}
321 }
322 }
323 -re ".*$gdb_prompt $" { fail "complete 'info '" }
324 timeout { fail "(timeout) complete 'info '" }
325 }
326
327
328 send_gdb "info \t"
329 sleep 1
330 gdb_expect {
331 -re "^info \\\x07$"\
332 { send_gdb "\t"
333 gdb_expect {
334 -re "address.*types.*$gdb_prompt info $"\
335 { send_gdb "\n"
336 gdb_expect {
337 -re "\"info\".*unambiguous\\..*$gdb_prompt $"\
338 { pass "complete (2) 'info '"}
339 -re ".*$gdb_prompt $" { fail "complete (2) 'info '"}
340 timeout {fail "(timeout) complete (2) 'info '"}
341 }
342 }
343 -re ".*$gdb_prompt $" { fail "complete (2) 'info '"}
344 timeout {fail "(timeout) complete (2) 'info '"}
345 }
346 }
347 -re ".*$gdb_prompt $" { fail "complete (2) 'info '" }
348 timeout { fail "(timeout) complete (2) 'info '" }
349 }
350
351
352 send_gdb "p \"a\t"
353 sleep 1
354 gdb_expect {
355 -re "^p \"a\\\x07$"\
356 { send_gdb "\n"
357 gdb_expect {
358 -re "Unterminated string in expression\\..*$gdb_prompt $"\
359 { pass "complete 'p a'"}
360 -re ".*$gdb_prompt $" { fail "complete 'p a'"}
361 timeout {fail "(timeout) complete 'p a'"}
362 }
363 }
364 -re ".*$gdb_prompt $" { fail "complete 'p \"a'" }
365 timeout { fail "(timeout) complete 'p \"a'" }
366 }
367
368 send_gdb "p 'a\t"
369 sleep 1
370 gdb_expect {
371 -re "^p 'a\\\x07$"\
372 { send_gdb "\n"
373 gdb_expect {
374 -re "Invalid character constant\\..*$gdb_prompt $"\
375 { pass "complete 'p \'a'"}
376 -re ".*$gdb_prompt $" { fail "complete 'p \'a'"}
377 timeout {fail "(timeout) complete 'p \'a'"}
378 }
379 }
380 -re ".*$gdb_prompt $" { fail "complete 'p \'a'" }
381 timeout { fail "(timeout) complete 'p \'a'" }
382 }
383
384 send_gdb "p 'a\t"
385 sleep 1
386 gdb_expect {
387 -re "^p 'a\\\x07$" {
388 send_gdb "\t"
389 gdb_expect {
390 -re ".*argv.*$gdb_prompt p .a$" {
391 send_gdb "\n"
392 gdb_expect {
393 -re "Invalid character constant\\..*$gdb_prompt $" {
394 pass "complete (2) 'p \'a'"
395 }
396 -re ".*$gdb_prompt $" { fail "complete (2) 'p \'a'" }
397 timeout { fail "(timeout) complete (2) 'p \'a'" }
398 }
399 }
400 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
401 send_gdb "n"
402 gdb_expect {
403 -re "\\(gdb\\) p 'a$" {
404 send_gdb "\n"
405 gdb_expect {
406 -re "Invalid character constant\\..*$gdb_prompt $" {
407 pass "complete (2) 'p \'a'"
408 }
409 -re ".*$gdb_prompt $" {
410 fail "complete (2) 'p \'a'"
411 }
412 timeout { fail "(timeout) complete (2) 'p \'a'" }
413 }
414 }
415 -re ".*$gdb_prompt $" { fail "complete (2) 'p \'a'" }
416 timeout { fail "(timeout) complete (2) 'p \'a'" }
417 }
418 }
419 -re ".*$gdb_prompt $" { fail "complete (2) 'p \'a'" }
420 timeout { fail "(timeout) complete (2) 'p \'a'" }
421 }
422 }
423 -re ".*$gdb_prompt $" { fail "complete (2) 'p \'a'" }
424 timeout { fail "(timeout) complete (2) 'p \'a'" }
425 }
426
427
428 send_gdb "p b-a\t"
429 sleep 1
430 gdb_expect {
431 -re "^p b-a\\\x07$"\
432 { send_gdb "\n"
433 gdb_expect {
434 -re "No symbol \"b\" in current context\\..*$gdb_prompt $"\
435 { pass "complete 'p b-a'"}
436 -re ".*$gdb_prompt $" { fail "complete 'p b-a'"}
437 timeout {fail "(timeout) complete 'p b-a'"}
438 }
439 }
440 -re ".*$gdb_prompt $" { fail "complete 'p b-a'" }
441 timeout { fail "(timeout) complete 'p b-a'" }
442 }
443
444 send_gdb "p b-a\t"
445 sleep 1
446 gdb_expect {
447 -re "^p b-a\\\x07$" {
448 send_gdb "\t"
449 gdb_expect {
450 -re ".*argv.*$gdb_prompt p b-a$" {
451 send_gdb "\n"
452 gdb_expect {
453 -re "No symbol \"b\" in current context\\..*$gdb_prompt $" {
454 pass "complete (2) 'p b-a'"
455 }
456 -re ".*$gdb_prompt $" { fail "complete (2) 'p b-a'" }
457 timeout { fail "(timeout) complete (2) 'p b-a'" }
458 }
459 }
460 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
461 send_gdb "n"
462 gdb_expect {
463 -re "\\(gdb\\) p b-a$" {
464 send_gdb "\n"
465 gdb_expect {
466 -re "No symbol \"b\" in current context\\..*$gdb_prompt $" {
467 pass "complete (2) 'p b-a'"
468 }
469 -re ".*$gdb_prompt $" {
470 fail "complete (2) 'p b-a'"
471 }
472 timeout { fail "(timeout) complete (2) 'p b-a'" }
473 }
474 }
475 -re ".*$gdb_prompt $" { fail "complete (2) 'p b-a'" }
476 timeout { fail "(timeout) complete (2) 'p b-a'" }
477 }
478 }
479 -re ".*$gdb_prompt $" { fail "complete (2) 'p b-a'" }
480 timeout { fail "(timeout) complete (2) 'p b-a'" }
481 }
482 }
483 -re ".*$gdb_prompt $" { fail "complete (2) 'p b-a'" }
484 timeout { fail "(timeout) complete (2) 'p b-a'" }
485 }
486
487 send_gdb "p b-\t"
488 sleep 1
489 gdb_expect {
490 -re "^p b-\\\x07$" {
491 send_gdb "\t"
492 gdb_expect {
493 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
494 send_gdb "n"
495 gdb_expect {
496 -re "\\(gdb\\) p b-$" {
497 send_gdb "\n"
498 gdb_expect {
499 -re "No symbol \"b\" in current context\\..*$gdb_prompt $" {
500 pass "complete (2) 'p b-'"
501 }
502 -re ".*$gdb_prompt $" {
503 fail "complete (2) 'p b-'"
504 }
505 timeout { fail "(timeout) complete (2) 'p b-'" }
506 }
507 }
508 -re ".*$gdb_prompt $" { fail "complete (2) 'p b-'" }
509 timeout { fail "(timeout) complete (2) 'p b-'" }
510 }
511 }
512 -re ".*$gdb_prompt $" { fail "complete (2) 'p b-'" }
513 timeout { fail "(timeout) complete (2) 'p b-'" }
514 }
515 }
516 -re ".*$gdb_prompt $" { fail "complete (2) 'p b-'" }
517 timeout { fail "(timeout) complete (2) 'p b-'" }
518 }
519
520 send_gdb "file ${objdir}/Make\t"
521 sleep 1
522 gdb_expect {
523 -re "file ${objdir}/Makefile.*$"\
524 { send_gdb "\n"
525 gdb_expect {
526 -re "\r\nA program is being debugged already\\. Kill it\\? \\(y or n\\) $"\
527 { send_gdb "n\n"
528 gdb_expect {
529 -re "\r\nProgram not killed\\.\r\n$gdb_prompt $"\
530 { pass "complete 'file Make'"}
531 -re ".*$gdb_prompt $" { fail "complete 'file Make'"}
532 timeout {fail "(timeout) complete 'file Make'"}
533 }
534 }
535 -re ".*$gdb_prompt $" { fail "complete 'file Make'"}
536 timeout {fail "(timeout) complete 'file Make'"}
537 }
538 }
539 -re ".*$gdb_prompt $" { fail "complete 'file Make'" }
540 timeout { fail "(timeout) complete 'file Make'" }
541 }
542
543
544 send_gdb "file ${srcdir}/gdb.base/compl\t"
545 sleep 1
546 gdb_expect {
547 -re "^file ${srcdir}/gdb.base/completion\\.exp $"\
548 { send_gdb "\n"
549 gdb_expect {
550 -re "\r\nA program is being debugged already\\. Kill it\\? \\(y or n\\) $"
551 \
552 { send_gdb "n\n"
553 gdb_expect {
554 -re "\r\nProgram not killed\\.\r\n$gdb_prompt $"\
555 { pass "complete 'file gdb.base/compl'"}
556 -re ".*$gdb_prompt $" { fail "complete 'file gdb.base/compl'"}
557 timeout {fail "(timeout) complete 'file gdb.base/compl'"}
558 }
559 }
560 -re ".*$gdb_prompt $" { fail "complete 'file gdb.base/compl'"}
561 timeout {fail "(timeout) complete 'file gdb.base/compl'"}
562 }
563 }
564 -re ".*$gdb_prompt $" { fail "complete 'file gdb.base/compl'" }
565 timeout { fail "(timeout) complete 'file gdb.base/compl'" }
566 }
567
568 send_gdb "info func mark\t"
569 sleep 1
570 gdb_expect {
571 -re "^info func mark.*er$"\
572 {
573 send_gdb "\t\t"
574 sleep 3
575 gdb_expect {
576 -re "marker1.*$gdb_prompt info func marker$"\
577 { send_gdb "\n"
578 gdb_expect {
579 -re "All functions matching regular expression \"marker\":.*File.*break.c:\r\nint marker1\\(\\);\r\nint marker2\\(int\\).*marker3\\(char.*char.*\\).*marker4\\(long int\\);.*$gdb_prompt $"\
580 { pass "complete 'info func mar'"}
581 -re ".*$gdb_prompt $" { fail "complete 'info func mar'"}
582 timeout {fail "(timeout) complete 'info func mar'"}
583 }
584 }
585 -re ".*$gdb_prompt $" { fail "complete 'info func mar'"}
586 timeout {fail "(timeout) complete 'info func mar'"}
587 }
588 }
589 -re ".*$gdb_prompt $" { fail "complete 'info func mar'" }
590 timeout { fail "(timeout) complete 'info func mar'" }
591 }
592
593
594 send_gdb "set follow-fork-mode \t\t"
595 sleep 1
596 gdb_expect {
597 -re "ask.*child.*parent.*$gdb_prompt set follow-fork-mode $"\
598 { send_gdb "\n"
599 gdb_expect {
600 -re "Requires an argument.*ask.*child.*parent.*$gdb_prompt $"\
601 { pass "complete 'set follow-fork-mode'"}
602 -re "Ambiguous item \"\"\\..*$gdb_prompt $"\
603 { pass "complete 'set follow-fork-mode'"}
604 -re ".*$gdb_prompt $" { fail "complete 'set follow-fork-mode'"}
605 timeout {fail "(timeout) complete 'set follow-fork-mode'"}
606 }
607 }
608 -re ".*$gdb_prompt $" { fail "complete 'set follow-fork-mode'" }
609 timeout { fail "(timeout) complete 'set follow-fork-mode'" }
610 }
611
612 # Restore globals modified in this test...
613 if [info exists old_inputrc] {
614 set env(INPUTRC) $old_inputrc
615 } else {
616 unset env(INPUTRC)
617 }
618 set timeout $oldtimeout1
619
620 return 0
This page took 0.043076 seconds and 5 git commands to generate.