1 # Copyright 1998-2013 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
54 set srcfile ${testfile}.c
55 set srcfile1 ${testfile}1.c
56 set binfile ${objdir}/${subdir}/${testfile}
58 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
59 untested completion.exp
63 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
64 untested completion.exp
68 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
69 untested completion.exp
73 if [get_compiler_info] {
80 gdb_reinitialize_dir $srcdir/$subdir
83 if ![runto_main] then {
84 perror "tests suppressed"
87 set oldtimeout1 $timeout
90 set test "complete 'hfgfh'"
92 gdb_test_multiple "" "$test" {
95 gdb_test_multiple "" $test {
96 -re "Undefined command: \"hfgfh\"\\. Try \"help\"\\..*$gdb_prompt $" {
105 set test "complete 'show output'"
106 send_gdb "show output\t"
107 gdb_test_multiple "" "$test" {
108 -re "^show output-radix $" {
110 gdb_test_multiple "" "$test" {
111 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
118 set test "complete 'show output-'"
119 send_gdb "show output-\t"
120 gdb_test_multiple "" "$test" {
121 -re "^show output-radix $" {
123 gdb_test_multiple "" "$test" {
124 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
131 set test "complete 'p'"
133 gdb_test_multiple "" "$test" {
136 gdb_test_multiple "" "$test" {
137 -re "The history is empty\\..*$gdb_prompt $" {
144 set test "complete 'p '"
146 gdb_test_multiple "" "$test" {
149 gdb_test_multiple "" "$test" {
150 -re "The history is empty\\..*$gdb_prompt $" {
157 set test "complete 'info t foo'"
158 send_gdb "info t foo\t"
159 gdb_test_multiple "" "$test" {
160 -re "^info t foo\\\x07$" {
162 gdb_test_multiple "" "$test" {
163 -re "Ambiguous info command \"t foo\": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
170 set test "complete 'info t'"
172 gdb_test_multiple "" "$test" {
173 -re "^info t\\\x07$" {
175 gdb_test_multiple "" "$test" {
176 -re "Ambiguous info command \"t\": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
183 set test "complete 'info t '"
185 gdb_test_multiple "" "$test" {
186 -re "^info t \\\x07$" {
188 gdb_test_multiple "" "$test" {
189 -re "Ambiguous info command \"t \": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
196 set test "complete 'info asdfgh'"
197 send_gdb "info asdfgh\t"
198 gdb_test_multiple "" "$test" {
199 -re "^info asdfgh\\\x07$" {
201 gdb_test_multiple "" "$test" {
202 -re "Undefined info command: \"asdfgh\". Try \"help info\"\\..*$gdb_prompt $" {
209 set test "complete 'info asdfgh '"
210 send_gdb "info asdfgh \t"
211 gdb_test_multiple "" "$test" {
212 -re "^info asdfgh \\\x07$" {
214 gdb_test_multiple "" "$test" {
215 -re "Undefined info command: \"asdfgh \". Try \"help info\"\\..*$gdb_prompt $" {
222 set test "complete 'info'"
224 gdb_test_multiple "" "$test" {
227 gdb_test_multiple "" "$test" {
228 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands.*$gdb_prompt $" {
235 set test "complete 'info '"
237 gdb_test_multiple "" "$test" {
238 -re "^info \\\x07$" {
240 gdb_test_multiple "" "$test" {
241 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands:\r\n\r\n.*$gdb_prompt $" {
248 set test "complete (2) 'info '"
250 gdb_test_multiple "" "$test" {
251 -re "^info \\\x07$" {
253 gdb_test_multiple "" "$test" {
254 -re "address.*types.*$gdb_prompt " {
256 gdb_test_multiple "" "$test" {
257 -re "\"info\".*unambiguous\\..*$gdb_prompt $" {
266 set test "complete 'help info wat'"
267 send_gdb "help info wat\t"
268 gdb_test_multiple "" "$test" {
269 -re "^help info watchpoints $" {
271 gdb_test_multiple "" "$test" {
272 -re "Status of specified watchpoints.*\r\n.*$gdb_prompt $" {
277 -re "^help info wat\\\x07$" {
282 set test "complete 'p \"break1'"
283 send_gdb "p \"break1\t"
284 gdb_test_multiple "" "$test" {
285 -re "^p \"break1\\\x07$" {
287 gdb_test_multiple "" "$test" {}
289 -re "^p \"break1\\.c\"$" {
291 gdb_test_multiple "" "$test" {
292 -re "$gdb_prompt $" {
300 set test "complete 'p \"break1.'"
301 send_gdb "p \"break1.\t"
302 gdb_test_multiple "" "$test" {
303 -re "^p \"break1\\.\\\x07$" {
305 gdb_test_multiple "" "$test" {}
307 -re "^p \"break1\\.c\"$" {
309 gdb_test_multiple "" "$test" {
310 -re "$gdb_prompt $" {
315 -re "^p \"break1\\..*$" {
317 gdb_test_multiple "" "$test" {}
321 set test "complete 'p 'arg'"
323 gdb_test_multiple "" "$test" {
324 -re "^p 'arg\\\x07$" {
326 gdb_test_multiple "" "$test" {
327 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
334 set test "complete (2) 'p 'arg'"
336 gdb_test_multiple "" "$test" {
337 -re "^p 'arg\\\x07$" {
339 gdb_test_multiple "" "$test" {
340 -re "argv.*$gdb_prompt " {
342 gdb_test_multiple "" "$test" {
343 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
348 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
350 gdb_test_multiple "" "$test" {
351 -re "\\(gdb\\) p 'arg$" {
353 gdb_test_multiple "" "$test" {
354 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
365 set test "complete 'handle signal'"
366 send_gdb "handle sigq\t"
367 gdb_test_multiple "" "$test" {
368 -re "^handle sigq
\b\b\b\bSIGQUIT $" {
370 gdb_test_multiple "" "$test" {
371 -re "SIGQUIT.*Quit.*$gdb_prompt $" {
378 set test "complete 'handle keyword'"
379 send_gdb "handle nos\t"
380 gdb_test_multiple "" "$test" {
381 -re "^handle nostop $" {
383 gdb_test_multiple "" "$test" {
384 -re "$gdb_prompt $" {
391 set test "complete help aliases"
392 send_gdb "help user-define\t"
393 gdb_test_multiple "" "$test" {
394 -re "^help user-defined $" {
396 gdb_test_multiple "" "$test" {
397 -re "$gdb_prompt $" {
405 # These tests used to try completing the shorter "p b-a".
406 # Unfortunately, on some systems, there are .o files in system
407 # libraries which declare static variables named `b'. Of course,
408 # those variables aren't really in scope, as far as the compiler is
409 # concerned. But GDB deliberately tries to be more liberal: if you
410 # enter an identifier that doesn't have any binding in scope, GDB will
411 # search all the program's compilation units for a static variable of
414 # This behavior can help avoid a lot of pedantry, so it's usually a
415 # good thing. But in this test case, it causes GDB to print the value
416 # of some random variable, instead of giving us the "No symbol..."
417 # error we were expecting.
419 # For example, on S/390 linux, the file s_atan.c in libm.a declares a
420 # `b', which is a structure containing an int and a float, so GDB says
421 # ``Argument to arithmetic operation not a number or boolean'' instead
422 # of ``No symbol ...''.
424 # So, I'm hoping that there is no system with a static library variable named
425 # `no_var_by_this_name'.
427 set test "complete 'p no_var_named_this-arg'"
428 send_gdb "p no_var_named_this-arg\t"
429 gdb_test_multiple "" "$test" {
430 -re "^p no_var_named_this-arg\\\x07$" {
432 gdb_test_multiple "" "$test" {
433 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
440 set test "complete (2) 'p no_var_named_this-arg'"
441 send_gdb "p no_var_named_this-arg\t"
442 gdb_test_multiple "" "$test" {
443 -re "^p no_var_named_this-arg\\\x07$" {
445 gdb_test_multiple "" "$test" {
446 -re "argv.*$gdb_prompt " {
448 gdb_test_multiple "" "$test" {
449 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
454 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
460 pass "$test (eat prompt)"
463 fail "(timeout) $test (eat prompt)"
467 gdb_test_multiple "" "$test" {
468 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
477 set test "complete (2) 'p no_var_named_this-'"
478 send_gdb "p no_var_named_this-\t"
479 gdb_test_multiple "" "$test" {
480 -re "^p no_var_named_this-\\\x07$" {
482 gdb_test_multiple "" "$test" {
483 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
489 pass "$test (eat prompt)"
492 fail "(timeout) $test (eat prompt)"
496 gdb_test_multiple "" "$test" {
497 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
502 -re "argv.*$gdb_prompt $" {
504 gdb_test_multiple "" "$test" {
505 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
514 set test "complete 'p values\[0\].a'"
515 send_gdb "p values\[0\].a\t"
516 gdb_test_multiple "" "$test" {
517 -re "^p values.0..a_field $" {
519 gdb_test_multiple "" "$test" {
520 -re " = 0.*$gdb_prompt $" {
527 set test "complete 'p values\[0\] . a'"
528 send_gdb "p values\[0\] . a\t"
529 gdb_test_multiple "" "$test" {
530 -re "^p values.0. . a_field $" {
532 gdb_test_multiple "" "$test" {
533 -re " = 0.*$gdb_prompt $" {
540 set test "complete 'p &values\[0\] -> a'"
541 send_gdb "p &values\[0\] -> a\t"
542 gdb_test_multiple "" "$test" {
543 -re "^p &values.0. -> a_field $" {
545 gdb_test_multiple "" "$test" {
546 -re " = .*0x\[0-9a-fA-F\]*.*$gdb_prompt $" {
553 gdb_test "complete p &values\[0\]->z" \
554 "p &values.0.->z_field" \
555 "completion of field in anonymous union"
557 gdb_test "complete ptype &values\[0\]->z" \
558 "ptype &values.0.->z_field" \
559 "ptype completion of field in anonymous union"
561 gdb_test "complete whatis &values\[0\]->z" \
562 "whatis &values.0.->z_field" \
563 "whatis completion of field in anonymous union"
565 # The following tests used to simply try to complete `${objdir}/file',
566 # and so on. The problem is that ${objdir} can be very long; the
567 # completed filename may be more than eighty characters wide. When
568 # this happens, readline tries to manage things, producing output that
569 # may make sense on the screen, but is rather hard for our script to
572 # In the case that motivated this change, the (gdb) prompt occupied
573 # the leftmost six columns, and `${objdir}/' was seventy-four
574 # characters long --- eighty in all. After printing the slash,
575 # readline emitted a space, a carriage return, and then `Makefile'
576 # (the tab character being received as input after `Make'.
578 # Basically, you have to let readline do whatever it's going to do to
579 # make the screen look right. If it happens to use a different
580 # strategy on Tuesdays to get the cursor in the right place, that's
581 # not something the testsuite should care about.
583 # So, we avoid long lines. We `cd' to ${objdir} first, and then do
584 # the completion relative to the current directory.
586 # ${srcdir} may be a relative path. We want to make sure we end up
587 # in the right directory - so make sure we know where it is.
593 # If the directory name contains a '+' we must escape it, adding a backslash.
594 # If not, the test below will fail because it will interpret the '+' as a
595 # regexp operator. We use string_to_regexp for this purpose.
597 gdb_test "cd ${fullsrcdir}" \
598 "Working directory [string_to_regexp ${fullsrcdir}].*" \
602 # GDB used to fail adding / on directories, on the first try only.
603 set uniquedir ../testsuite/gdb.base/comp-dir
604 set escapeduniquedir [string_to_regexp ${uniquedir}]
606 set uniquesub ${uniquesu}r
607 set escapeuniquesub [string_to_regexp ${uniquesub}]
608 send_gdb "dir ${uniquedir}\t"
610 -re "${escapeduniquedir}/" {
611 pass "directory completion"
612 send_gdb "${uniquesu}\t"
614 -re "${escapeduniquedir} $" {
615 fail "directory completion (old gdb bug)"
616 send_gdb "\b/${uniquesu}\t"
619 fail "directory completion (timeout)"
620 send_gdb "\ndir ${uniquedir}/${uniquesu}\t"
625 -re "${escapeuniquesub}/$" {
626 pass "directory completion 2"
629 fail "directory completion 2"
633 # Empty COMMAND sends no newline while " " sends the newline we need.
634 gdb_test " " "Source directories searched: .*" "Glob remaining of directory test"
636 gdb_test "complete file ./gdb.base/compl" \
637 "file ./gdb.base/completion\\.exp.*" \
638 "complete-command 'file ./gdb.base/compl'"
640 set test "complete 'file ./gdb.base/complet'"
641 send_gdb "file ./gdb.base/complet\t"
642 gdb_test_multiple "" "$test" {
643 -re "^file ./gdb.base/completion\\.exp $" {
645 # Ignore the exact error message.
646 gdb_test_multiple "" "complete 'file ./gdb.base/complet'" {
647 -re "\r\nA program is being debugged already\\.\[\r\n\]+Are you sure you want to change the file\\? \\(y or n\\) $" {
651 -re "$gdb_prompt $" {
658 set test "complete 'info func marke'"
659 send_gdb "info func marke\t"
660 gdb_test_multiple "" "$test" {
661 -re "^info func marke.*r$" {
663 gdb_test_multiple "" "$test" {
664 -re "marker1.*$gdb_prompt " {
666 gdb_test_multiple "" "$test" {
667 -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 $" {
677 set test "complete 'set follow-fork-mode'"
678 send_gdb "set follow-fork-mode \t\t"
679 gdb_test_multiple "" "$test" {
680 -re "child.*parent.*$gdb_prompt " {
682 gdb_test_multiple "" "$test" {
683 -re "Requires an argument.*child.*parent.*$gdb_prompt $" {
686 -re "Ambiguous item \"\"\\..*$gdb_prompt $" {
693 gdb_test_no_output "complete print values\[0\].x." \
694 "field completion with invalid field"
696 # If there is a non-deprecated completion, it should be returned.
697 gdb_test "complete sav" "save" "test non-deprecated completion"
698 # If there is only a deprecated completion, then it should be returned.
699 gdb_test "complete save-t" "save-tracepoints" "test deprecated completion"
703 # Tag name completion.
706 gdb_test "complete ptype struct some_" "ptype struct some_struct"
707 gdb_test "complete ptype enum some_" "ptype enum some_enum"
708 gdb_test "complete ptype union some_" "ptype union some_union"
711 gdb_test "complete set gnutarget aut" "set gnutarget auto"
714 gdb_test "complete set cp-abi aut" "set cp-abi auto"
716 # Test that completion of commands 'target FOO' works well.
717 set targets [list "core" "tfile" "exec"]
719 # Test that completion of command 'target ctf' if GDB supports ctf
721 gdb_test_multiple "target ctf" "" {
722 -re "Undefined target command: \"ctf\"\. Try \"help target\"\.\r\n$gdb_prompt $" {
724 -re "No CTF directory specified.*\r\n$gdb_prompt $" {
725 lappend targets "ctf"
729 foreach target_name ${targets} {
730 gdb_test "complete target ${target_name} ./gdb.base/completion" \
731 "target ${target_name} ./gdb.base/completion\\.exp.*"
735 # "set foo unlimited" completion.
738 # A var_uinteger command.
739 gdb_test "complete set height " "set height unlimited"
740 gdb_test "complete set height u" "set height unlimited"
742 # A var_integer command.
743 gdb_test "complete set listsize " "set listsize unlimited"
744 gdb_test "complete set listsize unl" "set listsize unlimited"
746 # A var_zuinteger_unlimited command.
747 gdb_test "complete set trace-buffer-size " "set trace-buffer-size unlimited"
748 gdb_test "complete set trace-buffer-size unl" "set trace-buffer-size unlimited"
750 # Restore globals modified in this test...
751 set timeout $oldtimeout1