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 foreach target_name ${targets} {
109 gdb_test "complete target ${target_name} ./gdb.base/completion" \
110 "target ${target_name} \\./gdb.base/completion.*\\./gdb.base/completion0\\.o.*\\./gdb.base/completion1\\.o.*"
114 # "set foo unlimited" completion.
117 # A var_uinteger command.
118 gdb_test "complete set height " "set height unlimited"
119 gdb_test "complete set height u" "set height unlimited"
121 # A var_integer command.
122 gdb_test "complete set listsize " "set listsize unlimited"
123 gdb_test "complete set listsize unl" "set listsize unlimited"
125 # A var_zuinteger_unlimited command.
126 gdb_test "complete set trace-buffer-size " "set trace-buffer-size unlimited"
127 gdb_test "complete set trace-buffer-size unl" "set trace-buffer-size unlimited"
129 # Tests below are about tab-completion, which doesn't work if readline
130 # library isn't used. Check it first.
132 if { ![readline_is_used] } {
136 set test "complete 'hfgfh'"
138 gdb_test_multiple "" "$test" {
139 -re "^hfgfh\\\x07$" {
141 gdb_test_multiple "" $test {
142 -re "Undefined command: \"hfgfh\"\\. Try \"help\"\\..*$gdb_prompt $" {
151 set test "complete 'show output'"
152 send_gdb "show output\t"
153 gdb_test_multiple "" "$test" {
154 -re "^show output-radix $" {
156 gdb_test_multiple "" "$test" {
157 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
164 set test "complete 'show output-'"
165 send_gdb "show output-\t"
166 gdb_test_multiple "" "$test" {
167 -re "^show output-radix $" {
169 gdb_test_multiple "" "$test" {
170 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
177 set test "complete 'p'"
179 gdb_test_multiple "" "$test" {
182 gdb_test_multiple "" "$test" {
183 -re "The history is empty\\..*$gdb_prompt $" {
190 set test "complete 'p '"
192 gdb_test_multiple "" "$test" {
195 gdb_test_multiple "" "$test" {
196 -re "The history is empty\\..*$gdb_prompt $" {
203 set test "complete 'info t foo'"
204 send_gdb "info t foo\t"
205 gdb_test_multiple "" "$test" {
206 -re "^info t foo\\\x07$" {
208 gdb_test_multiple "" "$test" {
209 -re "Ambiguous info command \"t foo\": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
216 set test "complete 'info t'"
218 gdb_test_multiple "" "$test" {
219 -re "^info t\\\x07$" {
221 gdb_test_multiple "" "$test" {
222 -re "Ambiguous info command \"t\": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
229 set test "complete 'info t '"
231 gdb_test_multiple "" "$test" {
232 -re "^info t \\\x07$" {
234 gdb_test_multiple "" "$test" {
235 -re "Ambiguous info command \"t \": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
242 set test "complete 'info asdfgh'"
243 send_gdb "info asdfgh\t"
244 gdb_test_multiple "" "$test" {
245 -re "^info asdfgh\\\x07$" {
247 gdb_test_multiple "" "$test" {
248 -re "Undefined info command: \"asdfgh\". Try \"help info\"\\..*$gdb_prompt $" {
255 set test "complete 'info asdfgh '"
256 send_gdb "info asdfgh \t"
257 gdb_test_multiple "" "$test" {
258 -re "^info asdfgh \\\x07$" {
260 gdb_test_multiple "" "$test" {
261 -re "Undefined info command: \"asdfgh \". Try \"help info\"\\..*$gdb_prompt $" {
268 set test "complete 'info'"
270 gdb_test_multiple "" "$test" {
273 gdb_test_multiple "" "$test" {
274 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands.*$gdb_prompt $" {
281 set test "complete 'info '"
283 gdb_test_multiple "" "$test" {
284 -re "^info \\\x07$" {
286 gdb_test_multiple "" "$test" {
287 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands:\r\n\r\n.*$gdb_prompt $" {
294 set test "complete (2) 'info '"
296 gdb_test_multiple "" "$test" {
297 -re "^info \\\x07$" {
299 gdb_test_multiple "" "$test" {
300 -re "address.*types.*$gdb_prompt " {
302 gdb_test_multiple "" "$test" {
303 -re "\"info\".*unambiguous\\..*$gdb_prompt $" {
312 set test "complete 'help info wat'"
313 send_gdb "help info wat\t"
314 gdb_test_multiple "" "$test" {
315 -re "^help info watchpoints $" {
317 gdb_test_multiple "" "$test" {
318 -re "Status of specified watchpoints.*\r\n.*$gdb_prompt $" {
323 -re "^help info wat\\\x07$" {
328 set test "complete 'p \"break1'"
329 send_gdb "p \"break1\t"
330 gdb_test_multiple "" "$test" {
331 -re "^p \"break1\\\x07$" {
333 gdb_test_multiple "" "$test" {}
335 -re "^p \"break1\\.c\"$" {
337 gdb_test_multiple "" "$test" {
338 -re "$gdb_prompt $" {
346 set test "complete 'p \"break1.'"
347 send_gdb "p \"break1.\t"
348 gdb_test_multiple "" "$test" {
349 -re "^p \"break1\\.\\\x07$" {
351 gdb_test_multiple "" "$test" {}
353 -re "^p \"break1\\.c\"$" {
355 gdb_test_multiple "" "$test" {
356 -re "$gdb_prompt $" {
361 -re "^p \"break1\\..*$" {
363 gdb_test_multiple "" "$test" {}
367 set test "complete 'p 'arg'"
369 gdb_test_multiple "" "$test" {
370 -re "^p 'arg\\\x07$" {
372 gdb_test_multiple "" "$test" {
373 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
380 set test "complete (2) 'p 'arg'"
382 gdb_test_multiple "" "$test" {
383 -re "^p 'arg\\\x07$" {
385 gdb_test_multiple "" "$test" {
386 -re "argv.*$gdb_prompt " {
388 gdb_test_multiple "" "$test" {
389 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
394 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
396 gdb_test_multiple "" "$test" {
397 -re "\\(gdb\\) p 'arg$" {
399 gdb_test_multiple "" "$test" {
400 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
411 set test "complete 'handle signal'"
412 send_gdb "handle sigq\t"
413 gdb_test_multiple "" "$test" {
414 -re "^handle sigq
\b\b\b\bSIGQUIT $" {
416 gdb_test_multiple "" "$test" {
417 -re "SIGQUIT.*Quit.*$gdb_prompt $" {
424 set test "complete 'handle keyword'"
425 send_gdb "handle nos\t"
426 gdb_test_multiple "" "$test" {
427 -re "^handle nostop $" {
429 gdb_test_multiple "" "$test" {
430 -re "$gdb_prompt $" {
437 set test "complete help aliases"
438 send_gdb "help user-define\t"
439 gdb_test_multiple "" "$test" {
440 -re "^help user-defined $" {
442 gdb_test_multiple "" "$test" {
443 -re "$gdb_prompt $" {
451 # These tests used to try completing the shorter "p b-a".
452 # Unfortunately, on some systems, there are .o files in system
453 # libraries which declare static variables named `b'. Of course,
454 # those variables aren't really in scope, as far as the compiler is
455 # concerned. But GDB deliberately tries to be more liberal: if you
456 # enter an identifier that doesn't have any binding in scope, GDB will
457 # search all the program's compilation units for a static variable of
460 # This behavior can help avoid a lot of pedantry, so it's usually a
461 # good thing. But in this test case, it causes GDB to print the value
462 # of some random variable, instead of giving us the "No symbol..."
463 # error we were expecting.
465 # For example, on S/390 linux, the file s_atan.c in libm.a declares a
466 # `b', which is a structure containing an int and a float, so GDB says
467 # ``Argument to arithmetic operation not a number or boolean'' instead
468 # of ``No symbol ...''.
470 # So, I'm hoping that there is no system with a static library variable named
471 # `no_var_by_this_name'.
473 set test "complete 'p no_var_named_this-arg'"
474 send_gdb "p no_var_named_this-arg\t"
475 gdb_test_multiple "" "$test" {
476 -re "^p no_var_named_this-arg\\\x07$" {
478 gdb_test_multiple "" "$test" {
479 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
486 set test "complete (2) 'p no_var_named_this-arg'"
487 send_gdb "p no_var_named_this-arg\t"
488 gdb_test_multiple "" "$test" {
489 -re "^p no_var_named_this-arg\\\x07$" {
491 gdb_test_multiple "" "$test" {
492 -re "argv.*$gdb_prompt " {
494 gdb_test_multiple "" "$test" {
495 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
500 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
506 pass "$test (eat prompt)"
509 fail "(timeout) $test (eat prompt)"
513 gdb_test_multiple "" "$test" {
514 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
523 set test "complete (2) 'p no_var_named_this-'"
524 send_gdb "p no_var_named_this-\t"
525 gdb_test_multiple "" "$test" {
526 -re "^p no_var_named_this-\\\x07$" {
528 gdb_test_multiple "" "$test" {
529 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
535 pass "$test (eat prompt)"
538 fail "(timeout) $test (eat prompt)"
542 gdb_test_multiple "" "$test" {
543 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
548 -re "argv.*$gdb_prompt $" {
550 gdb_test_multiple "" "$test" {
551 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
560 set test "complete 'p values\[0\].a'"
561 send_gdb "p values\[0\].a\t"
562 gdb_test_multiple "" "$test" {
563 -re "^p values.0..a_field $" {
565 gdb_test_multiple "" "$test" {
566 -re " = 0.*$gdb_prompt $" {
573 set test "complete 'p values\[0\] . a'"
574 send_gdb "p values\[0\] . a\t"
575 gdb_test_multiple "" "$test" {
576 -re "^p values.0. . a_field $" {
578 gdb_test_multiple "" "$test" {
579 -re " = 0.*$gdb_prompt $" {
586 set test "complete 'p &values\[0\] -> a'"
587 send_gdb "p &values\[0\] -> a\t"
588 gdb_test_multiple "" "$test" {
589 -re "^p &values.0. -> a_field $" {
591 gdb_test_multiple "" "$test" {
592 -re " = .*0x\[0-9a-fA-F\]*.*$gdb_prompt $" {
599 gdb_test "complete p &values\[0\]->z" \
600 "p &values.0.->z_field" \
601 "completion of field in anonymous union"
603 gdb_test "complete ptype &values\[0\]->z" \
604 "ptype &values.0.->z_field" \
605 "ptype completion of field in anonymous union"
607 gdb_test "complete whatis &values\[0\]->z" \
608 "whatis &values.0.->z_field" \
609 "whatis completion of field in anonymous union"
611 # The following tests used to simply try to complete `${objdir}/file',
612 # and so on. The problem is that ${objdir} can be very long; the
613 # completed filename may be more than eighty characters wide. When
614 # this happens, readline tries to manage things, producing output that
615 # may make sense on the screen, but is rather hard for our script to
618 # In the case that motivated this change, the (gdb) prompt occupied
619 # the leftmost six columns, and `${objdir}/' was seventy-four
620 # characters long --- eighty in all. After printing the slash,
621 # readline emitted a space, a carriage return, and then `Makefile'
622 # (the tab character being received as input after `Make'.
624 # Basically, you have to let readline do whatever it's going to do to
625 # make the screen look right. If it happens to use a different
626 # strategy on Tuesdays to get the cursor in the right place, that's
627 # not something the testsuite should care about.
629 # So, we avoid long lines. We `cd' to ${objdir} first, and then do
630 # the completion relative to the current directory.
632 # ${srcdir} may be a relative path. We want to make sure we end up
633 # in the right directory - so make sure we know where it is.
639 # If the directory name contains a '+' we must escape it, adding a backslash.
640 # If not, the test below will fail because it will interpret the '+' as a
641 # regexp operator. We use string_to_regexp for this purpose.
643 gdb_test "cd ${fullsrcdir}" \
644 "Working directory [string_to_regexp ${fullsrcdir}].*" \
648 # GDB used to fail adding / on directories, on the first try only.
649 set uniquedir ../testsuite/gdb.base/comp-dir
650 set escapeduniquedir [string_to_regexp ${uniquedir}]
652 set uniquesub ${uniquesu}r
653 set escapeuniquesub [string_to_regexp ${uniquesub}]
654 send_gdb "dir ${uniquedir}\t"
656 -re "${escapeduniquedir}/" {
657 pass "directory completion"
658 send_gdb "${uniquesu}\t"
660 -re "${escapeduniquedir} $" {
661 fail "directory completion (old gdb bug)"
662 send_gdb "\b/${uniquesu}\t"
665 fail "directory completion (timeout)"
666 send_gdb "\ndir ${uniquedir}/${uniquesu}\t"
671 -re "${escapeuniquesub}/$" {
672 pass "directory completion 2"
675 fail "directory completion 2"
679 # Empty COMMAND sends no newline while " " sends the newline we need.
680 gdb_test " " "Source directories searched: .*" "Glob remaining of directory test"
682 gdb_test "complete file ./gdb.base/compl" \
683 "file ./gdb.base/completion\\.exp.*" \
684 "complete-command 'file ./gdb.base/compl'"
686 set test "complete 'file ./gdb.base/complet'"
687 send_gdb "file ./gdb.base/complet\t"
688 gdb_test_multiple "" "$test" {
689 -re "^file ./gdb.base/completion\\.exp $" {
691 # Ignore the exact error message.
692 gdb_test_multiple "" "complete 'file ./gdb.base/complet'" {
693 -re "\r\nA program is being debugged already\\.\[\r\n\]+Are you sure you want to change the file\\? \\(y or n\\) $" {
697 -re "$gdb_prompt $" {
704 set test "complete 'info func marke'"
705 send_gdb "info func marke\t"
706 gdb_test_multiple "" "$test" {
707 -re "^info func marke.*r$" {
709 gdb_test_multiple "" "$test" {
710 -re "marker1.*$gdb_prompt " {
712 gdb_test_multiple "" "$test" {
713 -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 $" {
723 set test "complete 'set follow-fork-mode'"
724 send_gdb "set follow-fork-mode \t\t"
725 gdb_test_multiple "" "$test" {
726 -re "child.*parent.*$gdb_prompt " {
728 gdb_test_multiple "" "$test" {
729 -re "Requires an argument.*child.*parent.*$gdb_prompt $" {
732 -re "Ambiguous item \"\"\\..*$gdb_prompt $" {
739 # Restore globals modified in this test...
740 set timeout $oldtimeout1