1 # Copyright 1998, 1999, 2002, 2003, 2004, 2007, 2008
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
22 # This file is part of the gdb testsuite.
25 # tests for command completion
27 # Here are some useful test cases for completion.
28 # They should be tested with both M-? and TAB.
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
40 # "info " ambiguous (all info commands)
41 # "p \"break1" unambiguous (completes to filename "break1.c")
42 # "p \"break1." unambiguous (should complete to "break1.c" but does not,
43 # due to readline limitations)
44 # "p 'arg" ambiguous (all symbols starting with arg)
45 # "p b-arg" ambiguous (all symbols starting with arg)
46 # "p b-" ambiguous (all symbols)
47 # "file Make" "file" (word break hard to screw up here)
48 # "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
60 # test running programs
66 set srcfile ${testfile}.c
67 set srcfile1 ${testfile}1.c
68 set binfile ${objdir}/${subdir}/${testfile}
70 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
71 untested completion.exp
75 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
76 untested completion.exp
80 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
81 untested completion.exp
85 if [get_compiler_info ${binfile}] {
91 # Don't let a .inputrc file or an existing setting of INPUTRC mess up
92 # the test results. Even if /dev/null doesn't exist on the particular
93 # platform, the readline library will use the default setting just by
94 # failing to open the file. OTOH, opening /dev/null successfully will
95 # also result in the default settings being used since nothing will be
96 # read from this file.
98 if [info exists env(INPUTRC)] {
99 set old_inputrc $env(INPUTRC)
101 set env(INPUTRC) "/dev/null"
104 gdb_reinitialize_dir $srcdir/$subdir
107 if ![runto_main] then {
108 perror "tests suppressed"
111 set oldtimeout1 $timeout
121 -re "Undefined command: \"hfgfh\"\\. Try \"help\"\\..*$gdb_prompt $"\
122 { pass "complete 'hfgfh'"}
123 -re ".*$gdb_prompt $" { fail "complete 'hfgfh'"}
124 timeout {fail "(timeout) complete 'hfgfh'"}
127 -re ".*$gdb_prompt $" { fail "complete 'hfgfh'" }
128 timeout { fail "(timeout) complete 'hfgfh'" }
133 send_gdb "show output\t"
136 -re "^show output-radix $"\
139 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
140 { pass "complete 'show output'"}
141 -re ".*$gdb_prompt $" { fail "complete 'show output'"}
142 timeout {fail "(timeout) complete 'show output'"}
148 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
149 { fail "complete 'show output'"}
150 -re ".*$gdb_prompt $" { fail "complete 'show output'"}
151 timeout { fail "(timeout) complete 'show output'"}
156 -re ".*$gdb_prompt $" { fail "complete 'show output'" }
157 timeout { fail "(timeout) complete 'show output'" }
161 send_gdb "show output-\t"
164 -re "^show output-radix $"\
167 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
168 { pass "complete 'show output-'"}
169 -re ".*$gdb_prompt $" { fail "complete 'show output-'"}
170 timeout {fail "(timeout) complete 'show output-'"}
173 -re "^show output-$"\
176 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
177 { fail "complete 'show output-'"}
178 -re ".*$gdb_prompt $" { fail "complete 'show output-'"}
179 timeout { fail "(timeout) complete 'show output-'"}
184 -re ".*$gdb_prompt $" { fail "complete 'show output-'" }
185 timeout { fail "(timeout) complete 'show output-'" }
195 -re "The history is empty\\..*$gdb_prompt $"\
196 { pass "complete 'p'"}
197 -re ".*$gdb_prompt $" { fail "complete 'p'"}
198 timeout {fail "(timeout) complete 'p' 2"}
201 -re ".*$gdb_prompt $" { fail "complete 'p'" }
202 timeout { fail "(timeout) complete 'p' 1" }
212 -re "The history is empty\\..*$gdb_prompt $"\
213 { pass "complete 'p '"}
214 -re ".*$gdb_prompt $" { fail "complete 'p '"}
215 timeout {fail "(timeout) complete 'p ' 1"}
218 -re ".*$gdb_prompt $" { fail "complete 'p '" }
219 timeout { fail "(timeout) complete 'p ' 2" }
223 send_gdb "info t foo\t"
226 -re "^info t foo\\\x07$"\
229 -re "Ambiguous info command \"t foo\": target, terminal, threads, tp, tracepoints, types\\..*$gdb_prompt $"\
230 { pass "complete 'info t foo'"}
231 -re ".*$gdb_prompt $" { fail "complete 'info t foo'"}
232 timeout {fail "(timeout) complete 'info t foo'"}
235 -re ".*$gdb_prompt $" { fail "complete 'info t foo'" }
236 timeout { fail "(timeout) complete 'info t foo'" }
242 -re "^info t\\\x07$"\
245 -re "Ambiguous info command \"t\": target, terminal, threads, tp, tracepoints, types\\..
247 { pass "complete 'info t'"}
248 -re ".*$gdb_prompt $" { fail "complete 'info t'"}
249 timeout {fail "(timeout) complete 'info t'"}
252 -re ".*$gdb_prompt $" { fail "complete 'info t'" }
253 timeout { fail "(timeout) complete 'info t'" }
260 -re "^info t \\\x07$"\
263 -re "Ambiguous info command \"t \": target, terminal, threads, tp, tracepoints, types\\..
265 { pass "complete 'info t '"}
266 -re ".*$gdb_prompt $" { fail "complete 'info t '"}
267 timeout {fail "(timeout) complete 'info t '"}
270 -re ".*$gdb_prompt $" { fail "complete 'info t '" }
271 timeout { fail "(timeout) complete 'info t '" }
275 send_gdb "info asdfgh\t"
278 -re "^info asdfgh\\\x07$"\
281 -re "Undefined info command: \"asdfgh\". Try \"help info\"\\..
283 { pass "complete 'info asdfgh'"}
284 -re ".*$gdb_prompt $" { fail "complete 'info asdfgh'"}
285 timeout {fail "(timeout) complete 'info asdfgh'"}
288 -re ".*$gdb_prompt $" { fail "complete 'info asdfgh'" }
289 timeout { fail "(timeout) complete 'info asdfgh'" }
293 send_gdb "info asdfgh \t"
296 -re "^info asdfgh \\\x07$"\
299 -re "Undefined info command: \"asdfgh \". Try \"help info\"\\..
301 { pass "complete 'info asdfgh '"}
302 -re ".*$gdb_prompt $" { fail "complete 'info asdfgh '"}
303 timeout {fail "(timeout) complete 'info asdfgh '"}
306 -re ".*$gdb_prompt $" { fail "complete 'info asdfgh '" }
307 timeout { fail "(timeout) complete 'info asdfgh '" }
316 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands.*$gdb_prompt $"\
317 { pass "complete 'info'"}
318 -re ".*$gdb_prompt $" { fail "complete 'info'"}
319 timeout {fail "(timeout) complete 'info'"}
322 -re ".*$gdb_prompt $" { fail "complete 'info'" }
323 timeout { fail "(timeout) complete 'info'" }
332 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands:\r\n\r\n.*$gdb_prompt $"\
333 { pass "complete 'info '"}
334 -re ".*$gdb_prompt $" { fail "complete 'info '"}
335 timeout {fail "(timeout) complete 'info '"}
338 -re ".*$gdb_prompt $" { fail "complete 'info '" }
339 timeout { fail "(timeout) complete 'info '" }
349 -re "address.*types.*$gdb_prompt info $"\
352 -re "\"info\".*unambiguous\\..*$gdb_prompt $"\
353 { pass "complete (2) 'info '"}
354 -re ".*$gdb_prompt $" { fail "complete (2) 'info '"}
355 timeout {fail "(timeout) complete (2) 'info '"}
358 -re ".*$gdb_prompt $" { fail "complete (2) 'info '"}
359 timeout {fail "(timeout) complete (2) 'info '"}
362 -re ".*$gdb_prompt $" { fail "complete (2) 'info '" }
363 timeout { fail "(timeout) complete (2) 'info '" }
367 send_gdb "help info wat\t"
369 -re "^help info watchpoints $"\
372 -re "Synonym for .*\r\n.*$gdb_prompt $"\
373 { pass "complete help info wat" }
374 -re ".*$gdb_prompt $" { fail "complete help info wat"}
375 timeout {fail "(timeout) complete help info wat"}
378 -re "^help info wat\\\x07$" { fail "complete (2) help info wat" }
379 -re ".*$gdb_prompt $" { fail "complete (3) help info wat" }
380 timeout { fail "(timeout) complete (3) help info wat" }
384 send_gdb "p \"break1\t"
387 -re "^p \"break1\\\x07$"\
390 -re ".*$gdb_prompt $" { fail "complete 'p \"break1'"}
391 timeout {fail "(timeout) complete 'p \"break1'"}
394 -re "^p \"break1\\.c\"$"\
397 -re ".*$gdb_prompt $" { pass "complete 'p \"break1'"}
398 timeout {fail "(timeout) complete 'p \"break1'"}
404 -re ".*$gdb_prompt $" { fail "complete 'p \"break1'"}
405 timeout {fail "(timeout) complete 'p \"break1'"}
408 -re ".*$gdb_prompt $" { fail "complete 'p \"break1'" }
409 timeout { fail "(timeout) complete 'p \"break1'" }
413 send_gdb "p \"break1.\t"
416 -re "^p \"break1\\.\\\x07$"\
419 -re ".*$gdb_prompt $" { fail "complete 'p \"break1.'"}
420 timeout {fail "(timeout) complete 'p \"break1.'"}
423 -re "^p \"break1\\.c\"$"\
426 -re ".*$gdb_prompt $" { pass "complete 'p \"break1.'"}
427 timeout {fail "(timeout) complete 'p \"break1.'"}
430 -re "^p \"break1\\..*$"
433 -re ".*$gdb_prompt $" { fail "complete 'p \"break1.'"}
434 timeout {fail "(timeout) complete 'p \"break1.'"}
437 -re ".*$gdb_prompt $" { fail "complete 'p \"break1.'" }
438 timeout { fail "(timeout) complete 'p \"break1.'" }
444 -re "^p 'arg\\\x07$"\
447 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $"\
448 { pass "complete 'p \'arg'"}
449 -re ".*$gdb_prompt $" { fail "complete 'p \'arg'"}
450 timeout {fail "(timeout) complete 'p \'arg'"}
453 -re ".*$gdb_prompt $" { fail "complete 'p \'arg'" }
454 timeout { fail "(timeout) complete 'p \'arg'" }
460 -re "^p 'arg\\\x07$" {
463 -re ".*argv.*$gdb_prompt p 'arg$" {
466 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
467 pass "complete (2) 'p \'arg'"
469 -re ".*$gdb_prompt $" { fail "complete (2) 'p \'arg'" }
470 timeout { fail "(timeout) complete (2) 'p \'arg'" }
473 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
476 -re "\\(gdb\\) p 'arg$" {
479 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
480 pass "complete (2) 'p \'arg'"
482 -re ".*$gdb_prompt $" {
483 fail "complete (2) 'p \'arg'"
485 timeout { fail "(timeout) complete (2) 'p \'arg'" }
488 -re ".*$gdb_prompt $" { fail "complete (2) 'p \'arg'" }
489 timeout { fail "(timeout) complete (2) 'p \'arg'" }
492 -re ".*$gdb_prompt $" { fail "complete (2) 'p \'arg'" }
493 timeout { fail "(timeout) complete (2) 'p \'arg'" }
496 -re ".*$gdb_prompt $" { fail "complete (2) 'p \'arg'" }
497 timeout { fail "(timeout) complete (2) 'p \'arg'" }
501 # These tests used to try completing the shorter "p b-a".
502 # Unfortunately, on some systems, there are .o files in system
503 # libraries which declare static variables named `b'. Of course,
504 # those variables aren't really in scope, as far as the compiler is
505 # concerned. But GDB deliberately tries to be more liberal: if you
506 # enter an identifier that doesn't have any binding in scope, GDB will
507 # search all the program's compilation units for a static variable of
510 # This behavior can help avoid a lot of pedantry, so it's usually a
511 # good thing. But in this test case, it causes GDB to print the value
512 # of some random variable, instead of giving us the "No symbol..."
513 # error we were expecting.
515 # For example, on S/390 linux, the file s_atan.c in libm.a declares a
516 # `b', which is a structure containing an int and a float, so GDB says
517 # ``Argument to arithmetic operation not a number or boolean'' instead
518 # of ``No symbol ...''.
520 # So, I'm hoping that there is no system with a static library variable named
521 # `no_var_by_this_name'.
522 send_gdb "p no_var_named_this-arg\t"
525 -re "^p no_var_named_this-arg\\\x07$" {
528 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
529 pass "complete 'p no_var_named_this-arg'"
531 -re ".*$gdb_prompt $" {
532 fail "complete 'p no_var_named_this-arg'"
535 fail "(timeout) complete 'p no_var_named_this-arg'"
539 -re ".*$gdb_prompt $" {
540 fail "complete 'p no_var_named_this-arg'"
543 fail "(timeout) complete 'p no_var_named_this-arg'"
547 send_gdb "p no_var_named_this-arg\t"
550 -re "^p no_var_named_this-arg\\\x07$" {
553 -re ".*argv.*$gdb_prompt p no_var_named_this-arg$" {
556 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
557 pass "complete (2) 'p no_var_named_this-arg'"
559 -re ".*$gdb_prompt $" {
560 fail "complete (2) 'p no_var_named_this-arg'"
563 fail "(timeout) complete (2) 'p no_var_named_this-arg'"
567 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
570 -re "\\(gdb\\) p no_var_named_this-arg$" {
573 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
574 pass "complete (2) 'p no_var_named_this-arg'"
576 -re ".*$gdb_prompt $" {
577 fail "complete (2) 'p no_var_named_this-arg'"
580 fail "(timeout) complete (2) 'p no_var_named_this-arg'"
584 -re ".*$gdb_prompt $" {
585 fail "complete (2) 'p no_var_named_this-arg'"
588 fail "(timeout) complete (2) 'p no_var_named_this-arg'"
592 -re ".*$gdb_prompt $" {
593 fail "complete (2) 'p no_var_named_this-arg'"
595 timeout { fail "(timeout) complete (2) 'p no_var_named_this-arg'" }
598 -re ".*$gdb_prompt $" { fail "complete (2) 'p no_var_named_this-arg'" }
599 timeout { fail "(timeout) complete (2) 'p no_var_named_this-arg'" }
602 send_gdb "p no_var_named_this-\t"
605 -re "^p no_var_named_this-\\\x07$" {
608 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
611 -re "\\(gdb\\) p no_var_named_this-$" {
614 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
615 pass "complete (2) 'p no_var_named_this-'"
617 -re ".*$gdb_prompt $" {
618 fail "complete (2) 'p no_var_named_this-'"
621 fail "(timeout) complete (2) 'p no_var_named_this-'"
625 -re ".*$gdb_prompt $" {
626 fail "complete (2) 'p no_var_named_this-'"
629 fail "(timeout) complete (2) 'p no_var_named_this-'"
633 -re ".*argv.*$gdb_prompt p no_var_named_this-$" {
636 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
637 pass "complete (2) 'p no_var_named_this-'"
639 -re ".*$gdb_prompt $" {
640 fail "complete (2) 'p no_var_named_this-'"
643 fail "(timeout) complete (2) 'p no_var_named_this-'"
647 -re ".*$gdb_prompt $" {
648 fail "complete (2) 'p no_var_named_this-'"
650 timeout { fail "(timeout) complete (2) 'p no_var_named_this-'" }
653 -re ".*$gdb_prompt $" { fail "complete (2) 'p no_var_named_this-'" }
654 timeout { fail "(timeout) complete (2) 'p no_var_named_this-'" }
657 send_gdb "p values\[0\].a\t"
660 -re "^p values.0..a_field $"\
664 -re "^.* = 0.*$gdb_prompt $"\
665 { pass "complete 'p values\[0\].a'"}
666 -re ".*$gdb_prompt $" { fail "complete 'p values\[0\].a'"}
667 timeout {fail "(timeout) complete 'p values\[0\].a'"}
670 -re ".*$gdb_prompt $" { fail "complete 'p values\[0\].a'" }
671 timeout { fail "(timeout) complete 'p values\[0\].a' 2" }
674 send_gdb "p values\[0\] . a\t"
676 -re "^p values.0. . a_field $"\
679 -re "^.* = 0.*$gdb_prompt $"\
680 { pass "complete 'p values\[0\] . a'"}
681 -re ".*$gdb_prompt $" { fail "complete 'p values\[0\] . a'"}
682 timeout {fail "(timeout) complete 'p values\[0\] . a'"}
685 -re ".*$gdb_prompt $" { fail "complete 'p values\[0\] . a'" }
686 timeout { fail "(timeout) complete 'p values\[0\] . a' 2" }
689 send_gdb "p &values\[0\] -> a\t"
691 -re "^p &values.0. -> a_field $"\
694 -re "^.* = .*0x\[0-9a-fA-F\]*.*$gdb_prompt $"\
695 { pass "complete 'p &values\[0\] -> a'"}
696 -re ".*$gdb_prompt $" { fail "complete 'p &values\[0\] -> a'"}
697 timeout {fail "(timeout) complete 'p &values\[0\] -> a'"}
700 -re ".*$gdb_prompt $" { fail "complete 'p &values\[0\] -> a'" }
701 timeout { fail "(timeout) complete 'p &values\[0\] -> a' 2" }
704 # The following tests used to simply try to complete `${objdir}/file',
705 # and so on. The problem is that ${objdir} can be very long; the
706 # completed filename may be more than eighty characters wide. When
707 # this happens, readline tries to manage things, producing output that
708 # may make sense on the screen, but is rather hard for our script to
711 # In the case that motivated this change, the (gdb) prompt occupied
712 # the leftmost six columns, and `${objdir}/' was seventy-four
713 # characters long --- eighty in all. After printing the slash,
714 # readline emitted a space, a carriage return, and then `Makefile'
715 # (the tab character being received as input after `Make'.
717 # Basically, you have to let readline do whatever it's going to do to
718 # make the screen look right. If it happens to use a different
719 # strategy on Tuesdays to get the cursor in the right place, that's
720 # not something the testsuite should care about.
722 # So, we avoid long lines. We `cd' to ${objdir} first, and then do
723 # the completion relative to the current directory.
725 # ${srcdir} may be a relative path. We want to make sure we end up
726 # in the right directory - so make sure we know where it is.
732 # If the directory name contains a '+' we must escape it, adding a backslash.
733 # If not, the test below will fail because it will interpret the '+' as a
734 # regexp operator. We use string_to_regexp for this purpose.
736 gdb_test "cd ${fullsrcdir}" \
737 "Working directory [string_to_regexp ${fullsrcdir}].*" \
740 send_gdb "complete file ./gdb.base/compl\n"
743 -re "file ./gdb.base/completion\\.exp.*$gdb_prompt $"
744 { pass "complete-command 'file ./gdb.base/compl'"}
745 -re ".*$gdb_prompt $" { fail "complete-command 'file ./gdb.base/compl'" }
746 timeout { fail "(timeout) complete-command 'file ./gdb.base/compl'" }
749 send_gdb "file ./gdb.base/complet\t"
752 -re "^file ./gdb.base/completion\\.exp $"\
754 # Ignore the exact error message.
755 gdb_test_multiple "" "complete 'file ./gdb.base/complet'" {
756 -re "\r\nA program is being debugged already\\.\[\r\n\]+Are you sure you want to change the file\\? \\(y or n\\) $" {
760 -re ".*$gdb_prompt $" { pass "complete 'file ./gdb.base/complet'" }
763 -re ".*$gdb_prompt $" { fail "complete 'file ./gdb.base/complet'" }
764 timeout { fail "(timeout) complete 'file ./gdb.base/complet'" }
767 send_gdb "info func marke\t"
770 -re "^info func marke.*r$"\
775 -re "marker1.*$gdb_prompt info func marker$"\
778 -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 $"\
779 { pass "complete 'info func marke'"}
780 -re ".*$gdb_prompt $" { fail "complete 'info func marke'"}
781 timeout {fail "(timeout) complete 'info func marke'"}
784 -re ".*$gdb_prompt $" { fail "complete 'info func marke'"}
785 timeout {fail "(timeout) complete 'info func marke'"}
788 -re ".*$gdb_prompt $" { fail "complete 'info func marke'" }
789 timeout { fail "(timeout) complete 'info func marke'" }
793 send_gdb "set follow-fork-mode \t\t"
796 -re "child.*parent.*$gdb_prompt set follow-fork-mode $"\
799 -re "Requires an argument.*child.*parent.*$gdb_prompt $"\
800 { pass "complete 'set follow-fork-mode'"}
801 -re "Ambiguous item \"\"\\..*$gdb_prompt $"\
802 { pass "complete 'set follow-fork-mode'"}
803 -re ".*$gdb_prompt $" { fail "complete 'set follow-fork-mode'"}
804 timeout {fail "(timeout) complete 'set follow-fork-mode'"}
807 -re ".*$gdb_prompt $" { fail "complete 'set follow-fork-mode'" }
808 timeout { fail "(timeout) complete 'set follow-fork-mode'" }
811 # Restore globals modified in this test...
812 if [info exists old_inputrc] {
813 set env(INPUTRC) $old_inputrc
817 set timeout $oldtimeout1