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"
69 set oldtimeout1 $timeout
72 gdb_test_no_output "complete print values\[0\].x." \
73 "field completion with invalid field"
75 # If there is a non-deprecated completion, it should be returned.
76 gdb_test "complete sav" "save" "test non-deprecated completion"
77 # If there is only a deprecated completion, then it should be returned.
78 gdb_test "complete save-t" "save-tracepoints" "test deprecated completion"
82 # Tag name completion.
85 gdb_test "complete ptype struct some_" "ptype struct some_struct"
86 gdb_test "complete ptype enum some_" "ptype enum some_enum"
87 gdb_test "complete ptype union some_" "ptype union some_union"
90 gdb_test "complete set gnutarget aut" "set gnutarget auto"
93 gdb_test "complete set cp-abi aut" "set cp-abi auto"
95 # Test that completion of commands 'target FOO' works well.
96 set targets [list "core" "tfile" "exec"]
98 # Test that completion of command 'target ctf' if GDB supports ctf
100 gdb_test_multiple "target ctf" "" {
101 -re "Undefined target command: \"ctf\"\. Try \"help target\"\.\r\n$gdb_prompt $" {
103 -re "No CTF directory specified.*\r\n$gdb_prompt $" {
104 lappend targets "ctf"
108 # Test artifacts are put in different locations depending on test
109 # is a parallel run or not. Firstly check file exists, and then
110 # do the test on file completion.
112 foreach dir1 [ list "./gdb.base" "./outputs/gdb.base/completion" ] {
113 if [remote_file host exists ${dir1}/completion] {
114 foreach target_name ${targets} {
115 gdb_test "complete target ${target_name} ${dir1}/completion" \
116 "target ${target_name} ${dir1}/completion.*${dir1}/completion0\\.o.*${dir1}/completion1\\.o.*"
123 # "set foo unlimited" completion.
126 # A var_uinteger command.
127 gdb_test "complete set height " "set height unlimited"
128 gdb_test "complete set height u" "set height unlimited"
130 # A var_integer command.
131 gdb_test "complete set listsize " "set listsize unlimited"
132 gdb_test "complete set listsize unl" "set listsize unlimited"
134 # A var_zuinteger_unlimited command.
135 gdb_test "complete set trace-buffer-size " "set trace-buffer-size unlimited"
136 gdb_test "complete set trace-buffer-size unl" "set trace-buffer-size unlimited"
138 # Tests below are about tab-completion, which doesn't work if readline
139 # library isn't used. Check it first.
141 if { ![readline_is_used] } {
145 set test "complete 'hfgfh'"
147 gdb_test_multiple "" "$test" {
148 -re "^hfgfh\\\x07$" {
150 gdb_test_multiple "" $test {
151 -re "Undefined command: \"hfgfh\"\\. Try \"help\"\\..*$gdb_prompt $" {
160 set test "complete 'show output'"
161 send_gdb "show output\t"
162 gdb_test_multiple "" "$test" {
163 -re "^show output-radix $" {
165 gdb_test_multiple "" "$test" {
166 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
173 set test "complete 'show output-'"
174 send_gdb "show output-\t"
175 gdb_test_multiple "" "$test" {
176 -re "^show output-radix $" {
178 gdb_test_multiple "" "$test" {
179 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
186 set test "complete 'p'"
188 gdb_test_multiple "" "$test" {
191 gdb_test_multiple "" "$test" {
192 -re "The history is empty\\..*$gdb_prompt $" {
199 set test "complete 'p '"
201 gdb_test_multiple "" "$test" {
204 gdb_test_multiple "" "$test" {
205 -re "The history is empty\\..*$gdb_prompt $" {
212 set test "complete 'info t foo'"
213 send_gdb "info t foo\t"
214 gdb_test_multiple "" "$test" {
215 -re "^info t foo\\\x07$" {
217 gdb_test_multiple "" "$test" {
218 -re "Ambiguous info command \"t foo\": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
225 set test "complete 'info t'"
227 gdb_test_multiple "" "$test" {
228 -re "^info t\\\x07$" {
230 gdb_test_multiple "" "$test" {
231 -re "Ambiguous info command \"t\": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
238 set test "complete 'info t '"
240 gdb_test_multiple "" "$test" {
241 -re "^info t \\\x07$" {
243 gdb_test_multiple "" "$test" {
244 -re "Ambiguous info command \"t \": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
251 set test "complete 'info asdfgh'"
252 send_gdb "info asdfgh\t"
253 gdb_test_multiple "" "$test" {
254 -re "^info asdfgh\\\x07$" {
256 gdb_test_multiple "" "$test" {
257 -re "Undefined info command: \"asdfgh\". Try \"help info\"\\..*$gdb_prompt $" {
264 set test "complete 'info asdfgh '"
265 send_gdb "info asdfgh \t"
266 gdb_test_multiple "" "$test" {
267 -re "^info asdfgh \\\x07$" {
269 gdb_test_multiple "" "$test" {
270 -re "Undefined info command: \"asdfgh \". Try \"help info\"\\..*$gdb_prompt $" {
277 set test "complete 'info'"
279 gdb_test_multiple "" "$test" {
282 gdb_test_multiple "" "$test" {
283 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands.*$gdb_prompt $" {
290 set test "complete 'info '"
292 gdb_test_multiple "" "$test" {
293 -re "^info \\\x07$" {
295 gdb_test_multiple "" "$test" {
296 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands:\r\n\r\n.*$gdb_prompt $" {
303 set test "complete (2) 'info '"
305 gdb_test_multiple "" "$test" {
306 -re "^info \\\x07$" {
308 gdb_test_multiple "" "$test" {
309 -re "address.*types.*$gdb_prompt " {
311 gdb_test_multiple "" "$test" {
312 -re "\"info\".*unambiguous\\..*$gdb_prompt $" {
321 set test "complete 'help info wat'"
322 send_gdb "help info wat\t"
323 gdb_test_multiple "" "$test" {
324 -re "^help info watchpoints $" {
326 gdb_test_multiple "" "$test" {
327 -re "Status of specified watchpoints.*\r\n.*$gdb_prompt $" {
332 -re "^help info wat\\\x07$" {
337 set test "complete 'p \"break1'"
338 send_gdb "p \"break1\t"
339 gdb_test_multiple "" "$test" {
340 -re "^p \"break1\\\x07$" {
342 gdb_test_multiple "" "$test" {}
344 -re "^p \"break1\\.c\"$" {
346 gdb_test_multiple "" "$test" {
347 -re "$gdb_prompt $" {
355 set test "complete 'p \"break1.'"
356 send_gdb "p \"break1.\t"
357 gdb_test_multiple "" "$test" {
358 -re "^p \"break1\\.\\\x07$" {
360 gdb_test_multiple "" "$test" {}
362 -re "^p \"break1\\.c\"$" {
364 gdb_test_multiple "" "$test" {
365 -re "$gdb_prompt $" {
370 -re "^p \"break1\\..*$" {
372 gdb_test_multiple "" "$test" {}
376 set test "complete 'p 'arg'"
378 gdb_test_multiple "" "$test" {
379 -re "^p 'arg\\\x07$" {
381 gdb_test_multiple "" "$test" {
382 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
389 set test "complete (2) 'p 'arg'"
391 gdb_test_multiple "" "$test" {
392 -re "^p 'arg\\\x07$" {
394 gdb_test_multiple "" "$test" {
395 -re "argv.*$gdb_prompt " {
397 gdb_test_multiple "" "$test" {
398 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
403 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
405 gdb_test_multiple "" "$test" {
406 -re "\\(gdb\\) p 'arg$" {
408 gdb_test_multiple "" "$test" {
409 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
420 set test "complete 'handle signal'"
421 send_gdb "handle sigq\t"
422 gdb_test_multiple "" "$test" {
423 -re "^handle sigq
\b\b\b\bSIGQUIT $" {
425 gdb_test_multiple "" "$test" {
426 -re "SIGQUIT.*Quit.*$gdb_prompt $" {
433 set test "complete 'handle keyword'"
434 send_gdb "handle nos\t"
435 gdb_test_multiple "" "$test" {
436 -re "^handle nostop $" {
438 gdb_test_multiple "" "$test" {
439 -re "$gdb_prompt $" {
446 set test "complete help aliases"
447 send_gdb "help user-define\t"
448 gdb_test_multiple "" "$test" {
449 -re "^help user-defined $" {
451 gdb_test_multiple "" "$test" {
452 -re "$gdb_prompt $" {
460 # These tests used to try completing the shorter "p b-a".
461 # Unfortunately, on some systems, there are .o files in system
462 # libraries which declare static variables named `b'. Of course,
463 # those variables aren't really in scope, as far as the compiler is
464 # concerned. But GDB deliberately tries to be more liberal: if you
465 # enter an identifier that doesn't have any binding in scope, GDB will
466 # search all the program's compilation units for a static variable of
469 # This behavior can help avoid a lot of pedantry, so it's usually a
470 # good thing. But in this test case, it causes GDB to print the value
471 # of some random variable, instead of giving us the "No symbol..."
472 # error we were expecting.
474 # For example, on S/390 linux, the file s_atan.c in libm.a declares a
475 # `b', which is a structure containing an int and a float, so GDB says
476 # ``Argument to arithmetic operation not a number or boolean'' instead
477 # of ``No symbol ...''.
479 # So, I'm hoping that there is no system with a static library variable named
480 # `no_var_by_this_name'.
482 set test "complete 'p no_var_named_this-arg'"
483 send_gdb "p no_var_named_this-arg\t"
484 gdb_test_multiple "" "$test" {
485 -re "^p no_var_named_this-arg\\\x07$" {
487 gdb_test_multiple "" "$test" {
488 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
495 set test "complete (2) 'p no_var_named_this-arg'"
496 send_gdb "p no_var_named_this-arg\t"
497 gdb_test_multiple "" "$test" {
498 -re "^p no_var_named_this-arg\\\x07$" {
500 gdb_test_multiple "" "$test" {
501 -re "argv.*$gdb_prompt " {
503 gdb_test_multiple "" "$test" {
504 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
509 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
515 pass "$test (eat prompt)"
518 fail "(timeout) $test (eat prompt)"
522 gdb_test_multiple "" "$test" {
523 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
532 set test "complete (2) 'p no_var_named_this-'"
533 send_gdb "p no_var_named_this-\t"
534 gdb_test_multiple "" "$test" {
535 -re "^p no_var_named_this-\\\x07$" {
537 gdb_test_multiple "" "$test" {
538 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
544 pass "$test (eat prompt)"
547 fail "(timeout) $test (eat prompt)"
551 gdb_test_multiple "" "$test" {
552 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
557 -re "argv.*$gdb_prompt $" {
559 gdb_test_multiple "" "$test" {
560 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
569 set test "complete 'p values\[0\].a'"
570 send_gdb "p values\[0\].a\t"
571 gdb_test_multiple "" "$test" {
572 -re "^p values.0..a_field $" {
574 gdb_test_multiple "" "$test" {
575 -re " = 0.*$gdb_prompt $" {
582 set test "complete 'p values\[0\] . a'"
583 send_gdb "p values\[0\] . a\t"
584 gdb_test_multiple "" "$test" {
585 -re "^p values.0. . a_field $" {
587 gdb_test_multiple "" "$test" {
588 -re " = 0.*$gdb_prompt $" {
595 set test "complete 'p &values\[0\] -> a'"
596 send_gdb "p &values\[0\] -> a\t"
597 gdb_test_multiple "" "$test" {
598 -re "^p &values.0. -> a_field $" {
600 gdb_test_multiple "" "$test" {
601 -re " = .*0x\[0-9a-fA-F\]*.*$gdb_prompt $" {
608 gdb_test "complete p &values\[0\]->z" \
609 "p &values.0.->z_field" \
610 "completion of field in anonymous union"
612 gdb_test "complete ptype &values\[0\]->z" \
613 "ptype &values.0.->z_field" \
614 "ptype completion of field in anonymous union"
616 gdb_test "complete whatis &values\[0\]->z" \
617 "whatis &values.0.->z_field" \
618 "whatis completion of field in anonymous union"
620 # The following tests used to simply try to complete `${objdir}/file',
621 # and so on. The problem is that ${objdir} can be very long; the
622 # completed filename may be more than eighty characters wide. When
623 # this happens, readline tries to manage things, producing output that
624 # may make sense on the screen, but is rather hard for our script to
627 # In the case that motivated this change, the (gdb) prompt occupied
628 # the leftmost six columns, and `${objdir}/' was seventy-four
629 # characters long --- eighty in all. After printing the slash,
630 # readline emitted a space, a carriage return, and then `Makefile'
631 # (the tab character being received as input after `Make'.
633 # Basically, you have to let readline do whatever it's going to do to
634 # make the screen look right. If it happens to use a different
635 # strategy on Tuesdays to get the cursor in the right place, that's
636 # not something the testsuite should care about.
638 # So, we avoid long lines. We `cd' to ${objdir} first, and then do
639 # the completion relative to the current directory.
641 # ${srcdir} may be a relative path. We want to make sure we end up
642 # in the right directory - so make sure we know where it is.
648 # If the directory name contains a '+' we must escape it, adding a backslash.
649 # If not, the test below will fail because it will interpret the '+' as a
650 # regexp operator. We use string_to_regexp for this purpose.
652 gdb_test "cd ${fullsrcdir}" \
653 "Working directory [string_to_regexp ${fullsrcdir}].*" \
657 # GDB used to fail adding / on directories, on the first try only.
658 set uniquedir ../testsuite/gdb.base/comp-dir
659 set escapeduniquedir [string_to_regexp ${uniquedir}]
661 set uniquesub ${uniquesu}r
662 set escapeuniquesub [string_to_regexp ${uniquesub}]
663 send_gdb "dir ${uniquedir}\t"
665 -re "${escapeduniquedir}/" {
666 pass "directory completion"
667 send_gdb "${uniquesu}\t"
669 -re "${escapeduniquedir} $" {
670 fail "directory completion (old gdb bug)"
671 send_gdb "\b/${uniquesu}\t"
674 fail "directory completion (timeout)"
675 send_gdb "\ndir ${uniquedir}/${uniquesu}\t"
680 -re "${escapeuniquesub}/$" {
681 pass "directory completion 2"
684 fail "directory completion 2"
688 # Empty COMMAND sends no newline while " " sends the newline we need.
689 gdb_test " " "Source directories searched: .*" "Glob remaining of directory test"
691 gdb_test "complete file ./gdb.base/compl" \
692 "file ./gdb.base/completion\\.exp.*" \
693 "complete-command 'file ./gdb.base/compl'"
695 set test "complete 'file ./gdb.base/complet'"
696 send_gdb "file ./gdb.base/complet\t"
697 gdb_test_multiple "" "$test" {
698 -re "^file ./gdb.base/completion\\.exp $" {
700 # Ignore the exact error message.
701 gdb_test_multiple "" "complete 'file ./gdb.base/complet'" {
702 -re "\r\nA program is being debugged already\\.\[\r\n\]+Are you sure you want to change the file\\? \\(y or n\\) $" {
706 -re "$gdb_prompt $" {
713 set test "complete 'info func marke'"
714 send_gdb "info func marke\t"
715 gdb_test_multiple "" "$test" {
716 -re "^info func marke.*r$" {
718 gdb_test_multiple "" "$test" {
719 -re "marker1.*$gdb_prompt " {
721 gdb_test_multiple "" "$test" {
722 -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 $" {
732 set test "complete 'set follow-fork-mode'"
733 send_gdb "set follow-fork-mode \t\t"
734 gdb_test_multiple "" "$test" {
735 -re "child.*parent.*$gdb_prompt " {
737 gdb_test_multiple "" "$test" {
738 -re "Requires an argument.*child.*parent.*$gdb_prompt $" {
741 -re "Ambiguous item \"\"\\..*$gdb_prompt $" {
748 # Restore globals modified in this test...
749 set timeout $oldtimeout1