1 # Copyright 1998-2014 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 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
18 # This file is part of the gdb testsuite.
21 # tests for command completion
23 # Here are some useful test cases for completion.
24 # They should be tested with both M-? and TAB.
26 # "show output-" "radix"
27 # "show output" "-radix"
28 # "p" ambiguous (commands starting with p--path, print, printf, etc.)
29 # "p " ambiguous (all symbols)
30 # "info t foo" no completions
31 # "info t " no completions
32 # "info t" ambiguous ("info target", "info terminal", etc.)
33 # "info ajksdlfk" no completions
34 # "info ajksdlfk " no completions
36 # "info " ambiguous (all info commands)
37 # "p \"break1" unambiguous (completes to filename "break1.c")
38 # "p \"break1." unambiguous (should complete to "break1.c" but does not,
39 # due to readline limitations)
40 # "p 'arg" ambiguous (all symbols starting with arg)
41 # "p b-arg" ambiguous (all symbols starting with arg)
42 # "p b-" ambiguous (all symbols)
43 # "file Make" "file" (word break hard to screw up here)
44 # "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
50 # test running programs
53 standard_testfile break.c break1.c
55 if [get_compiler_info] {
59 if {[prepare_for_testing $testfile.exp $testfile \
60 [list $srcfile $srcfile2] {debug nowarnings}]} {
61 untested $testfile.exp
65 if ![runto_main] then {
66 perror "tests suppressed"
71 gdb_test_no_output "complete print values\[0\].x." \
72 "field completion with invalid field"
74 # If there is a non-deprecated completion, it should be returned.
75 gdb_test "complete sav" "save" "test non-deprecated completion"
76 # If there is only a deprecated completion, then it should be returned.
77 gdb_test "complete save-t" "save-tracepoints" "test deprecated completion"
81 # Tag name completion.
84 gdb_test "complete ptype struct some_" "ptype struct some_struct"
85 gdb_test "complete ptype enum some_" "ptype enum some_enum"
86 gdb_test "complete ptype union some_" "ptype union some_union"
89 gdb_test "complete set gnutarget aut" "set gnutarget auto"
92 gdb_test "complete set cp-abi aut" "set cp-abi auto"
94 # Test that completion of commands 'target FOO' works well.
95 set targets [list "core" "tfile" "exec"]
97 # Test that completion of command 'target ctf' if GDB supports ctf
99 gdb_test_multiple "target ctf" "" {
100 -re "Undefined target command: \"ctf\"\. Try \"help target\"\.\r\n$gdb_prompt $" {
102 -re "No CTF directory specified.*\r\n$gdb_prompt $" {
103 lappend targets "ctf"
107 # Test artifacts are put in different locations depending on test
108 # is a parallel run or not. Firstly check file exists, and then
109 # do the test on file completion.
111 foreach dir1 [ list "./gdb.base" "./outputs/gdb.base/completion" ] {
112 if { [remote_file host exists ${dir1}/completion]
113 && [remote_file host exists ${dir1}/completion0.o]
114 && [remote_file host exists ${dir1}/completion1.o] } {
115 foreach target_name ${targets} {
116 gdb_test "complete target ${target_name} ${dir1}/completion" \
117 "target ${target_name} ${dir1}/completion.*${dir1}/completion0\\.o.*${dir1}/completion1\\.o.*"
124 # "set foo unlimited" completion.
127 # A var_uinteger command.
128 gdb_test "complete set height " "set height unlimited"
129 gdb_test "complete set height u" "set height unlimited"
131 # A var_integer command.
132 gdb_test "complete set listsize " "set listsize unlimited"
133 gdb_test "complete set listsize unl" "set listsize unlimited"
135 # A var_zuinteger_unlimited command.
136 gdb_test "complete set trace-buffer-size " "set trace-buffer-size unlimited"
137 gdb_test "complete set trace-buffer-size unl" "set trace-buffer-size unlimited"
139 # Tests below are about tab-completion, which doesn't work if readline
140 # library isn't used. Check it first.
142 if { ![readline_is_used] } {
146 set test "complete 'hfgfh'"
148 gdb_test_multiple "" "$test" {
149 -re "^hfgfh\\\x07$" {
151 gdb_test_multiple "" $test {
152 -re "Undefined command: \"hfgfh\"\\. Try \"help\"\\..*$gdb_prompt $" {
161 set test "complete 'show output'"
162 send_gdb "show output\t"
163 gdb_test_multiple "" "$test" {
164 -re "^show output-radix $" {
166 gdb_test_multiple "" "$test" {
167 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
174 set test "complete 'show output-'"
175 send_gdb "show output-\t"
176 gdb_test_multiple "" "$test" {
177 -re "^show output-radix $" {
179 gdb_test_multiple "" "$test" {
180 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
187 set test "complete 'p'"
189 gdb_test_multiple "" "$test" {
192 gdb_test_multiple "" "$test" {
193 -re "The history is empty\\..*$gdb_prompt $" {
200 set test "complete 'p '"
202 gdb_test_multiple "" "$test" {
205 gdb_test_multiple "" "$test" {
206 -re "The history is empty\\..*$gdb_prompt $" {
213 set test "complete 'info t foo'"
214 send_gdb "info t foo\t"
215 gdb_test_multiple "" "$test" {
216 -re "^info t foo\\\x07$" {
218 gdb_test_multiple "" "$test" {
219 -re "Ambiguous info command \"t foo\": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
226 set test "complete 'info t'"
228 gdb_test_multiple "" "$test" {
229 -re "^info t\\\x07$" {
231 gdb_test_multiple "" "$test" {
232 -re "Ambiguous info command \"t\": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
239 set test "complete 'info t '"
241 gdb_test_multiple "" "$test" {
242 -re "^info t \\\x07$" {
244 gdb_test_multiple "" "$test" {
245 -re "Ambiguous info command \"t \": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
252 set test "complete 'info asdfgh'"
253 send_gdb "info asdfgh\t"
254 gdb_test_multiple "" "$test" {
255 -re "^info asdfgh\\\x07$" {
257 gdb_test_multiple "" "$test" {
258 -re "Undefined info command: \"asdfgh\". Try \"help info\"\\..*$gdb_prompt $" {
265 set test "complete 'info asdfgh '"
266 send_gdb "info asdfgh \t"
267 gdb_test_multiple "" "$test" {
268 -re "^info asdfgh \\\x07$" {
270 gdb_test_multiple "" "$test" {
271 -re "Undefined info command: \"asdfgh \". Try \"help info\"\\..*$gdb_prompt $" {
278 set test "complete 'info'"
280 gdb_test_multiple "" "$test" {
283 gdb_test_multiple "" "$test" {
284 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands.*$gdb_prompt $" {
291 set test "complete 'info '"
293 gdb_test_multiple "" "$test" {
294 -re "^info \\\x07$" {
296 gdb_test_multiple "" "$test" {
297 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands:\r\n\r\n.*$gdb_prompt $" {
304 set test "complete (2) 'info '"
306 gdb_test_multiple "" "$test" {
307 -re "^info \\\x07$" {
309 gdb_test_multiple "" "$test" {
310 -re "address.*types.*$gdb_prompt " {
312 gdb_test_multiple "" "$test" {
313 -re "\"info\".*unambiguous\\..*$gdb_prompt $" {
322 set test "complete 'help info wat'"
323 send_gdb "help info wat\t"
324 gdb_test_multiple "" "$test" {
325 -re "^help info watchpoints $" {
327 gdb_test_multiple "" "$test" {
328 -re "Status of specified watchpoints.*\r\n.*$gdb_prompt $" {
333 -re "^help info wat\\\x07$" {
338 set test "complete 'p \"break1'"
339 send_gdb "p \"break1\t"
340 gdb_test_multiple "" "$test" {
341 -re "^p \"break1\\\x07$" {
343 gdb_test_multiple "" "$test" {}
345 -re "^p \"break1\\.c\"$" {
347 gdb_test_multiple "" "$test" {
348 -re "$gdb_prompt $" {
356 set test "complete 'p \"break1.'"
357 send_gdb "p \"break1.\t"
358 gdb_test_multiple "" "$test" {
359 -re "^p \"break1\\.\\\x07$" {
361 gdb_test_multiple "" "$test" {}
363 -re "^p \"break1\\.c\"$" {
365 gdb_test_multiple "" "$test" {
366 -re "$gdb_prompt $" {
371 -re "^p \"break1\\..*$" {
373 gdb_test_multiple "" "$test" {}
377 set test "complete 'p 'arg'"
379 gdb_test_multiple "" "$test" {
380 -re "^p 'arg\\\x07$" {
382 gdb_test_multiple "" "$test" {
383 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
390 set test "complete (2) 'p 'arg'"
392 gdb_test_multiple "" "$test" {
393 -re "^p 'arg\\\x07$" {
395 gdb_test_multiple "" "$test" {
396 -re "argv.*$gdb_prompt " {
398 gdb_test_multiple "" "$test" {
399 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
404 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
406 gdb_test_multiple "" "$test" {
407 -re "\\(gdb\\) p 'arg$" {
409 gdb_test_multiple "" "$test" {
410 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
421 set test "complete 'handle signal'"
422 send_gdb "handle sigq\t"
423 gdb_test_multiple "" "$test" {
424 -re "^handle sigq
\b\b\b\bSIGQUIT $" {
426 gdb_test_multiple "" "$test" {
427 -re "SIGQUIT.*Quit.*$gdb_prompt $" {
434 set test "complete 'handle keyword'"
435 send_gdb "handle nos\t"
436 gdb_test_multiple "" "$test" {
437 -re "^handle nostop $" {
439 gdb_test_multiple "" "$test" {
440 -re "$gdb_prompt $" {
447 set test "complete help aliases"
448 send_gdb "help user-define\t"
449 gdb_test_multiple "" "$test" {
450 -re "^help user-defined $" {
452 gdb_test_multiple "" "$test" {
453 -re "$gdb_prompt $" {
461 # These tests used to try completing the shorter "p b-a".
462 # Unfortunately, on some systems, there are .o files in system
463 # libraries which declare static variables named `b'. Of course,
464 # those variables aren't really in scope, as far as the compiler is
465 # concerned. But GDB deliberately tries to be more liberal: if you
466 # enter an identifier that doesn't have any binding in scope, GDB will
467 # search all the program's compilation units for a static variable of
470 # This behavior can help avoid a lot of pedantry, so it's usually a
471 # good thing. But in this test case, it causes GDB to print the value
472 # of some random variable, instead of giving us the "No symbol..."
473 # error we were expecting.
475 # For example, on S/390 linux, the file s_atan.c in libm.a declares a
476 # `b', which is a structure containing an int and a float, so GDB says
477 # ``Argument to arithmetic operation not a number or boolean'' instead
478 # of ``No symbol ...''.
480 # So, I'm hoping that there is no system with a static library variable named
481 # `no_var_by_this_name'.
483 set test "complete 'p no_var_named_this-arg'"
484 send_gdb "p no_var_named_this-arg\t"
485 gdb_test_multiple "" "$test" {
486 -re "^p no_var_named_this-arg\\\x07$" {
488 gdb_test_multiple "" "$test" {
489 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
496 set test "complete (2) 'p no_var_named_this-arg'"
497 send_gdb "p no_var_named_this-arg\t"
498 gdb_test_multiple "" "$test" {
499 -re "^p no_var_named_this-arg\\\x07$" {
501 gdb_test_multiple "" "$test" {
502 -re "argv.*$gdb_prompt " {
504 gdb_test_multiple "" "$test" {
505 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
510 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
516 pass "$test (eat prompt)"
519 fail "(timeout) $test (eat prompt)"
523 gdb_test_multiple "" "$test" {
524 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
533 set test "complete (2) 'p no_var_named_this-'"
534 send_gdb "p no_var_named_this-\t"
535 gdb_test_multiple "" "$test" {
536 -re "^p no_var_named_this-\\\x07$" {
538 gdb_test_multiple "" "$test" {
539 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
545 pass "$test (eat prompt)"
548 fail "(timeout) $test (eat prompt)"
552 gdb_test_multiple "" "$test" {
553 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
558 -re "argv.*$gdb_prompt $" {
560 gdb_test_multiple "" "$test" {
561 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
570 set test "complete 'p values\[0\].a'"
571 send_gdb "p values\[0\].a\t"
572 gdb_test_multiple "" "$test" {
573 -re "^p values.0..a_field $" {
575 gdb_test_multiple "" "$test" {
576 -re " = 0.*$gdb_prompt $" {
583 set test "complete 'p values\[0\] . a'"
584 send_gdb "p values\[0\] . a\t"
585 gdb_test_multiple "" "$test" {
586 -re "^p values.0. . a_field $" {
588 gdb_test_multiple "" "$test" {
589 -re " = 0.*$gdb_prompt $" {
596 set test "complete 'p &values\[0\] -> a'"
597 send_gdb "p &values\[0\] -> a\t"
598 gdb_test_multiple "" "$test" {
599 -re "^p &values.0. -> a_field $" {
601 gdb_test_multiple "" "$test" {
602 -re " = .*0x\[0-9a-fA-F\]*.*$gdb_prompt $" {
609 gdb_test "complete p &values\[0\]->z" \
610 "p &values.0.->z_field" \
611 "completion of field in anonymous union"
613 gdb_test "complete ptype &values\[0\]->z" \
614 "ptype &values.0.->z_field" \
615 "ptype completion of field in anonymous union"
617 gdb_test "complete whatis &values\[0\]->z" \
618 "whatis &values.0.->z_field" \
619 "whatis completion of field in anonymous union"
621 # The following tests used to simply try to complete `${objdir}/file',
622 # and so on. The problem is that ${objdir} can be very long; the
623 # completed filename may be more than eighty characters wide. When
624 # this happens, readline tries to manage things, producing output that
625 # may make sense on the screen, but is rather hard for our script to
628 # In the case that motivated this change, the (gdb) prompt occupied
629 # the leftmost six columns, and `${objdir}/' was seventy-four
630 # characters long --- eighty in all. After printing the slash,
631 # readline emitted a space, a carriage return, and then `Makefile'
632 # (the tab character being received as input after `Make'.
634 # Basically, you have to let readline do whatever it's going to do to
635 # make the screen look right. If it happens to use a different
636 # strategy on Tuesdays to get the cursor in the right place, that's
637 # not something the testsuite should care about.
639 # So, we avoid long lines. We `cd' to ${objdir} first, and then do
640 # the completion relative to the current directory.
642 # ${srcdir} may be a relative path. We want to make sure we end up
643 # in the right directory - so make sure we know where it is.
649 # If the directory name contains a '+' we must escape it, adding a backslash.
650 # If not, the test below will fail because it will interpret the '+' as a
651 # regexp operator. We use string_to_regexp for this purpose.
653 gdb_test "cd ${fullsrcdir}" \
654 "Working directory [string_to_regexp ${fullsrcdir}].*" \
658 # GDB used to fail adding / on directories, on the first try only.
659 set uniquedir ../testsuite/gdb.base/comp-dir
660 set escapeduniquedir [string_to_regexp ${uniquedir}]
662 set uniquesub ${uniquesu}r
663 set escapeuniquesub [string_to_regexp ${uniquesub}]
664 send_gdb "dir ${uniquedir}\t"
666 -re "${escapeduniquedir}/" {
667 pass "directory completion"
668 send_gdb "${uniquesu}\t"
670 -re "${escapeduniquedir} $" {
671 fail "directory completion (old gdb bug)"
672 send_gdb "\b/${uniquesu}\t"
675 fail "directory completion (timeout)"
676 send_gdb "\ndir ${uniquedir}/${uniquesu}\t"
681 -re "${escapeuniquesub}/$" {
682 pass "directory completion 2"
685 fail "directory completion 2"
689 # Empty COMMAND sends no newline while " " sends the newline we need.
690 gdb_test " " "Source directories searched: .*" "Glob remaining of directory test"
692 gdb_test "complete file ./gdb.base/compl" \
693 "file ./gdb.base/completion\\.exp.*" \
694 "complete-command 'file ./gdb.base/compl'"
696 set test "complete 'file ./gdb.base/complet'"
697 send_gdb "file ./gdb.base/complet\t"
698 gdb_test_multiple "" "$test" {
699 -re "^file ./gdb.base/completion\\.exp $" {
701 # Ignore the exact error message.
702 gdb_test_multiple "" "complete 'file ./gdb.base/complet'" {
703 -re "\r\nA program is being debugged already\\.\[\r\n\]+Are you sure you want to change the file\\? \\(y or n\\) $" {
707 -re "$gdb_prompt $" {
714 set test "complete 'info func marke'"
715 send_gdb "info func marke\t"
716 gdb_test_multiple "" "$test" {
717 -re "^info func marke.*r$" {
719 gdb_test_multiple "" "$test" {
720 -re "marker1.*$gdb_prompt " {
722 gdb_test_multiple "" "$test" {
723 -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 $" {
733 set test "complete 'set follow-fork-mode'"
734 send_gdb "set follow-fork-mode \t\t"
735 gdb_test_multiple "" "$test" {
736 -re "child.*parent.*$gdb_prompt " {
738 gdb_test_multiple "" "$test" {
739 -re "Requires an argument.*child.*parent.*$gdb_prompt $" {
742 -re "Ambiguous item \"\"\\..*$gdb_prompt $" {