1 # Copyright 1998, 1999, 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
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 3 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Please email any bugs, comments, and/or additions to this file to:
17 # bug-gdb@prep.ai.mit.edu
19 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
21 # This file is part of the gdb testsuite.
24 # tests for command completion
26 # Here are some useful test cases for completion.
27 # They should be tested with both M-? and TAB.
29 # "show output-" "radix"
30 # "show output" "-radix"
31 # "p" ambiguous (commands starting with p--path, print, printf, etc.)
32 # "p " ambiguous (all symbols)
33 # "info t foo" no completions
34 # "info t " no completions
35 # "info t" ambiguous ("info target", "info terminal", etc.)
36 # "info ajksdlfk" no completions
37 # "info ajksdlfk " no completions
39 # "info " ambiguous (all info commands)
40 # "p \"break1" unambiguous (completes to filename "break1.c")
41 # "p \"break1." unambiguous (should complete to "break1.c" but does not,
42 # due to readline limitations)
43 # "p 'a" ambiguous (all symbols starting with a)
44 # "p b-a" ambiguous (all symbols starting with a)
45 # "p b-" ambiguous (all symbols)
46 # "file Make" "file" (word break hard to screw up here)
47 # "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
59 # test running programs
65 set srcfile ${testfile}.c
66 set srcfile1 ${testfile}1.c
67 set binfile ${objdir}/${subdir}/${testfile}
69 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
70 untested completion.exp
74 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
75 untested completion.exp
79 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
80 untested completion.exp
84 if [get_compiler_info ${binfile}] {
90 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
91 # the test results. Even if /dev/null doesn't exist on the particular
92 # platform, the readline library will use the default setting just by
93 # failing to open the file. OTOH, opening /dev/null successfully will
94 # also result in the default settings being used since nothing will be
95 # read from this file.
97 if [info exists env(INPUTRC)] {
98 set old_inputrc $env(INPUTRC)
100 set env(INPUTRC) "/dev/null"
103 gdb_reinitialize_dir $srcdir/$subdir
106 if ![runto_main] then {
107 perror "tests suppressed"
110 set oldtimeout1 $timeout
120 -re "Undefined command: \"hfgfh\"\\. Try \"help\"\\..*$gdb_prompt $"\
121 { pass "complete 'hfgfh'"}
122 -re ".*$gdb_prompt $" { fail "complete 'hfgfh'"}
123 timeout {fail "(timeout) complete 'hfgfh'"}
126 -re ".*$gdb_prompt $" { fail "complete 'hfgfh'" }
127 timeout { fail "(timeout) complete 'hfgfh'" }
132 send_gdb "show output\t"
135 -re "^show output-radix $"\
138 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
139 { pass "complete 'show output'"}
140 -re ".*$gdb_prompt $" { fail "complete 'show output'"}
141 timeout {fail "(timeout) complete 'show output'"}
147 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
148 { fail "complete 'show output'"}
149 -re ".*$gdb_prompt $" { fail "complete 'show output'"}
150 timeout { fail "(timeout) complete 'show output'"}
155 -re ".*$gdb_prompt $" { fail "complete 'show output'" }
156 timeout { fail "(timeout) complete 'show output'" }
160 send_gdb "show output-\t"
163 -re "^show output-radix $"\
166 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
167 { pass "complete 'show output-'"}
168 -re ".*$gdb_prompt $" { fail "complete 'show output-'"}
169 timeout {fail "(timeout) complete 'show output-'"}
172 -re "^show output-$"\
175 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
176 { fail "complete 'show output-'"}
177 -re ".*$gdb_prompt $" { fail "complete 'show output-'"}
178 timeout { fail "(timeout) complete 'show output-'"}
183 -re ".*$gdb_prompt $" { fail "complete 'show output-'" }
184 timeout { fail "(timeout) complete 'show output-'" }
194 -re "The history is empty\\..*$gdb_prompt $"\
195 { pass "complete 'p'"}
196 -re ".*$gdb_prompt $" { fail "complete 'p'"}
197 timeout {fail "(timeout) complete 'p' 2"}
200 -re ".*$gdb_prompt $" { fail "complete 'p'" }
201 timeout { fail "(timeout) complete 'p' 1" }
211 -re "The history is empty\\..*$gdb_prompt $"\
212 { pass "complete 'p '"}
213 -re ".*$gdb_prompt $" { fail "complete 'p '"}
214 timeout {fail "(timeout) complete 'p ' 1"}
217 -re ".*$gdb_prompt $" { fail "complete 'p '" }
218 timeout { fail "(timeout) complete 'p ' 2" }
222 send_gdb "info t foo\t"
225 -re "^info t foo\\\x07$"\
228 -re "Ambiguous info command \"t foo\": target, terminal, threads, tp, tracepoints, types\\..*$gdb_prompt $"\
229 { pass "complete 'info t foo'"}
230 -re ".*$gdb_prompt $" { fail "complete 'info t foo'"}
231 timeout {fail "(timeout) complete 'info t foo'"}
234 -re ".*$gdb_prompt $" { fail "complete 'info t foo'" }
235 timeout { fail "(timeout) complete 'info t foo'" }
241 -re "^info t\\\x07$"\
244 -re "Ambiguous info command \"t\": target, terminal, threads, tp, tracepoints, types\\..
246 { pass "complete 'info t'"}
247 -re ".*$gdb_prompt $" { fail "complete 'info t'"}
248 timeout {fail "(timeout) complete 'info t'"}
251 -re ".*$gdb_prompt $" { fail "complete 'info t'" }
252 timeout { fail "(timeout) complete 'info t'" }
259 -re "^info t \\\x07$"\
262 -re "Ambiguous info command \"t \": target, terminal, threads, tp, tracepoints, types\\..
264 { pass "complete 'info t '"}
265 -re ".*$gdb_prompt $" { fail "complete 'info t '"}
266 timeout {fail "(timeout) complete 'info t '"}
269 -re ".*$gdb_prompt $" { fail "complete 'info t '" }
270 timeout { fail "(timeout) complete 'info t '" }
274 send_gdb "info asdfgh\t"
277 -re "^info asdfgh\\\x07$"\
280 -re "Undefined info command: \"asdfgh\". Try \"help info\"\\..
282 { pass "complete 'info asdfgh'"}
283 -re ".*$gdb_prompt $" { fail "complete 'info asdfgh'"}
284 timeout {fail "(timeout) complete 'info asdfgh'"}
287 -re ".*$gdb_prompt $" { fail "complete 'info asdfgh'" }
288 timeout { fail "(timeout) complete 'info asdfgh'" }
292 send_gdb "info asdfgh \t"
295 -re "^info asdfgh \\\x07$"\
298 -re "Undefined info command: \"asdfgh \". Try \"help info\"\\..
300 { pass "complete 'info asdfgh '"}
301 -re ".*$gdb_prompt $" { fail "complete 'info asdfgh '"}
302 timeout {fail "(timeout) complete 'info asdfgh '"}
305 -re ".*$gdb_prompt $" { fail "complete 'info asdfgh '" }
306 timeout { fail "(timeout) complete 'info asdfgh '" }
315 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands.*$gdb_prompt $"\
316 { pass "complete 'info'"}
317 -re ".*$gdb_prompt $" { fail "complete 'info'"}
318 timeout {fail "(timeout) complete 'info'"}
321 -re ".*$gdb_prompt $" { fail "complete 'info'" }
322 timeout { fail "(timeout) complete 'info'" }
331 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands:\r\n\r\n.*$gdb_prompt $"\
332 { pass "complete 'info '"}
333 -re ".*$gdb_prompt $" { fail "complete 'info '"}
334 timeout {fail "(timeout) complete 'info '"}
337 -re ".*$gdb_prompt $" { fail "complete 'info '" }
338 timeout { fail "(timeout) complete 'info '" }
348 -re "address.*types.*$gdb_prompt info $"\
351 -re "\"info\".*unambiguous\\..*$gdb_prompt $"\
352 { pass "complete (2) 'info '"}
353 -re ".*$gdb_prompt $" { fail "complete (2) 'info '"}
354 timeout {fail "(timeout) complete (2) 'info '"}
357 -re ".*$gdb_prompt $" { fail "complete (2) 'info '"}
358 timeout {fail "(timeout) complete (2) 'info '"}
361 -re ".*$gdb_prompt $" { fail "complete (2) 'info '" }
362 timeout { fail "(timeout) complete (2) 'info '" }
366 send_gdb "p \"break1\t"
369 -re "^p \"break1\\\x07$"\
372 -re ".*$gdb_prompt $" { fail "complete 'p \"break1'"}
373 timeout {fail "(timeout) complete 'p \"break1'"}
376 -re "^p \"break1\\.c\"$"\
379 -re ".*$gdb_prompt $" { pass "complete 'p \"break1'"}
380 timeout {fail "(timeout) complete 'p \"break1'"}
386 -re ".*$gdb_prompt $" { fail "complete 'p \"break1'"}
387 timeout {fail "(timeout) complete 'p \"break1'"}
390 -re ".*$gdb_prompt $" { fail "complete 'p \"break1'" }
391 timeout { fail "(timeout) complete 'p \"break1'" }
395 send_gdb "p \"break1.\t"
398 -re "^p \"break1\\.\\\x07$"\
401 -re ".*$gdb_prompt $" { fail "complete 'p \"break1.'"}
402 timeout {fail "(timeout) complete 'p \"break1.'"}
405 -re "^p \"break1\\.c\"$"\
408 -re ".*$gdb_prompt $" { pass "complete 'p \"break1.'"}
409 timeout {fail "(timeout) complete 'p \"break1.'"}
412 -re "^p \"break1\\..*$"
415 -re ".*$gdb_prompt $" { fail "complete 'p \"break1.'"}
416 timeout {fail "(timeout) complete 'p \"break1.'"}
419 -re ".*$gdb_prompt $" { fail "complete 'p \"break1.'" }
420 timeout { fail "(timeout) complete 'p \"break1.'" }
429 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $"\
430 { pass "complete 'p \'a'"}
431 -re ".*$gdb_prompt $" { fail "complete 'p \'a'"}
432 timeout {fail "(timeout) complete 'p \'a'"}
435 -re ".*$gdb_prompt $" { fail "complete 'p \'a'" }
436 timeout { fail "(timeout) complete 'p \'a'" }
445 -re ".*argv.*$gdb_prompt p .a$" {
448 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
449 pass "complete (2) 'p \'a'"
451 -re ".*$gdb_prompt $" { fail "complete (2) 'p \'a'" }
452 timeout { fail "(timeout) complete (2) 'p \'a'" }
455 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
458 -re "\\(gdb\\) p 'a$" {
461 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
462 pass "complete (2) 'p \'a'"
464 -re ".*$gdb_prompt $" {
465 fail "complete (2) 'p \'a'"
467 timeout { fail "(timeout) complete (2) 'p \'a'" }
470 -re ".*$gdb_prompt $" { fail "complete (2) 'p \'a'" }
471 timeout { fail "(timeout) complete (2) 'p \'a'" }
474 -re ".*$gdb_prompt $" { fail "complete (2) 'p \'a'" }
475 timeout { fail "(timeout) complete (2) 'p \'a'" }
478 -re ".*$gdb_prompt $" { fail "complete (2) 'p \'a'" }
479 timeout { fail "(timeout) complete (2) 'p \'a'" }
483 # These tests used to try completing the shorter "p b-a".
484 # Unfortunately, on some systems, there are .o files in system
485 # libraries which declare static variables named `b'. Of course,
486 # those variables aren't really in scope, as far as the compiler is
487 # concerned. But GDB deliberately tries to be more liberal: if you
488 # enter an identifier that doesn't have any binding in scope, GDB will
489 # search all the program's compilation units for a static variable of
492 # This behavior can help avoid a lot of pedantry, so it's usually a
493 # good thing. But in this test case, it causes GDB to print the value
494 # of some random variable, instead of giving us the "No symbol..."
495 # error we were expecting.
497 # For example, on S/390 linux, the file s_atan.c in libm.a declares a
498 # `b', which is a structure containing an int and a float, so GDB says
499 # ``Argument to arithmetic operation not a number or boolean'' instead
500 # of ``No symbol ...''.
502 # So, I'm hoping that there is no system with a static library variable named
503 # `no_var_by_this_name'.
504 send_gdb "p no_var_named_this-a\t"
507 -re "^p no_var_named_this-a\\\x07$" {
510 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
511 pass "complete 'p no_var_named_this-a'"
513 -re ".*$gdb_prompt $" {
514 fail "complete 'p no_var_named_this-a'"
517 fail "(timeout) complete 'p no_var_named_this-a'"
521 -re ".*$gdb_prompt $" {
522 fail "complete 'p no_var_named_this-a'"
525 fail "(timeout) complete 'p no_var_named_this-a'"
529 send_gdb "p no_var_named_this-a\t"
532 -re "^p no_var_named_this-a\\\x07$" {
535 -re ".*argv.*$gdb_prompt p no_var_named_this-a$" {
538 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
539 pass "complete (2) 'p no_var_named_this-a'"
541 -re ".*$gdb_prompt $" {
542 fail "complete (2) 'p no_var_named_this-a'"
545 fail "(timeout) complete (2) 'p no_var_named_this-a'"
549 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
552 -re "\\(gdb\\) p no_var_named_this-a$" {
555 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
556 pass "complete (2) 'p no_var_named_this-a'"
558 -re ".*$gdb_prompt $" {
559 fail "complete (2) 'p no_var_named_this-a'"
562 fail "(timeout) complete (2) 'p no_var_named_this-a'"
566 -re ".*$gdb_prompt $" {
567 fail "complete (2) 'p no_var_named_this-a'"
570 fail "(timeout) complete (2) 'p no_var_named_this-a'"
574 -re ".*$gdb_prompt $" {
575 fail "complete (2) 'p no_var_named_this-a'"
577 timeout { fail "(timeout) complete (2) 'p no_var_named_this-a'" }
580 -re ".*$gdb_prompt $" { fail "complete (2) 'p no_var_named_this-a'" }
581 timeout { fail "(timeout) complete (2) 'p no_var_named_this-a'" }
584 send_gdb "p no_var_named_this-\t"
587 -re "^p no_var_named_this-\\\x07$" {
590 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
593 -re "\\(gdb\\) p no_var_named_this-$" {
596 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
597 pass "complete (2) 'p no_var_named_this-'"
599 -re ".*$gdb_prompt $" {
600 fail "complete (2) 'p no_var_named_this-'"
603 fail "(timeout) complete (2) 'p no_var_named_this-'"
607 -re ".*$gdb_prompt $" {
608 fail "complete (2) 'p no_var_named_this-'"
611 fail "(timeout) complete (2) 'p no_var_named_this-'"
615 -re ".*$gdb_prompt $" {
616 fail "complete (2) 'p no_var_named_this-'"
618 timeout { fail "(timeout) complete (2) 'p no_var_named_this-'" }
621 -re ".*$gdb_prompt $" { fail "complete (2) 'p no_var_named_this-'" }
622 timeout { fail "(timeout) complete (2) 'p no_var_named_this-'" }
626 # The following tests used to simply try to complete `${objdir}/file',
627 # and so on. The problem is that ${objdir} can be very long; the
628 # completed filename may be more than eighty characters wide. When
629 # this happens, readline tries to manage things, producing output that
630 # may make sense on the screen, but is rather hard for our script to
633 # In the case that motivated this change, the (gdb) prompt occupied
634 # the leftmost six columns, and `${objdir}/' was seventy-four
635 # characters long --- eighty in all. After printing the slash,
636 # readline emitted a space, a carriage return, and then `Makefile'
637 # (the tab character being received as input after `Make'.
639 # Basically, you have to let readline do whatever it's going to do to
640 # make the screen look right. If it happens to use a different
641 # strategy on Tuesdays to get the cursor in the right place, that's
642 # not something the testsuite should care about.
644 # So, we avoid long lines. We `cd' to ${objdir} first, and then do
645 # the completion relative to the current directory.
647 # ${srcdir} may be a relative path. We want to make sure we end up
648 # in the right directory - so make sure we know where it is.
654 # If the directory name contains a '+' we must escape it, adding a backslash.
655 # If not, the test below will fail because it will interpret the '+' as a
656 # regexp operator. We use string_to_regexp for this purpose.
658 gdb_test "cd ${fullsrcdir}" \
659 "Working directory [string_to_regexp ${fullsrcdir}].*" \
662 send_gdb "complete file ./gdb.base/compl\n"
665 -re "file ./gdb.base/completion\\.exp.*$gdb_prompt $"
666 { pass "complete-command 'file ./gdb.base/compl'"}
667 -re ".*$gdb_prompt $" { fail "complete-command 'file ./gdb.base/compl'" }
668 timeout { fail "(timeout) complete-command 'file ./gdb.base/compl'" }
671 send_gdb "file ./gdb.base/complet\t"
674 -re "^file ./gdb.base/completion\\.exp $"\
676 # Ignore the exact error message.
677 gdb_test_multiple "" "complete 'file ./gdb.base/complet'" {
678 -re "\r\nA program is being debugged already\\.\[\r\n\]+Are you sure you want to change the file\\? \\(y or n\\) $" {
682 -re ".*$gdb_prompt $" { pass "complete 'file ./gdb.base/complet'" }
685 -re ".*$gdb_prompt $" { fail "complete 'file ./gdb.base/complet'" }
686 timeout { fail "(timeout) complete 'file ./gdb.base/complet'" }
689 send_gdb "info func marke\t"
692 -re "^info func marke.*r$"\
697 -re "marker1.*$gdb_prompt info func marker$"\
700 -re "All functions matching regular expression \"marker\":.*File.*break1.c:\r\nint marker1\\((void|)\\);\r\nint marker2\\(int\\).*marker3\\(char.*char.*\\).*marker4\\(long int\\);.*$gdb_prompt $"\
701 { pass "complete 'info func marke'"}
702 -re ".*$gdb_prompt $" { fail "complete 'info func marke'"}
703 timeout {fail "(timeout) complete 'info func marke'"}
706 -re ".*$gdb_prompt $" { fail "complete 'info func marke'"}
707 timeout {fail "(timeout) complete 'info func marke'"}
710 -re ".*$gdb_prompt $" { fail "complete 'info func marke'" }
711 timeout { fail "(timeout) complete 'info func marke'" }
715 send_gdb "set follow-fork-mode \t\t"
718 -re "child.*parent.*$gdb_prompt set follow-fork-mode $"\
721 -re "Requires an argument.*child.*parent.*$gdb_prompt $"\
722 { pass "complete 'set follow-fork-mode'"}
723 -re "Ambiguous item \"\"\\..*$gdb_prompt $"\
724 { pass "complete 'set follow-fork-mode'"}
725 -re ".*$gdb_prompt $" { fail "complete 'set follow-fork-mode'"}
726 timeout {fail "(timeout) complete 'set follow-fork-mode'"}
729 -re ".*$gdb_prompt $" { fail "complete 'set follow-fork-mode'" }
730 timeout { fail "(timeout) complete 'set follow-fork-mode'" }
733 # Restore globals modified in this test...
734 if [info exists old_inputrc] {
735 set env(INPUTRC) $old_inputrc
739 set timeout $oldtimeout1