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.*" \
118 "complete target ${target_name}"
125 # "set foo unlimited" completion.
128 # A var_uinteger command.
129 gdb_test "complete set height " "set height unlimited"
130 gdb_test "complete set height u" "set height unlimited"
132 # A var_integer command.
133 gdb_test "complete set listsize " "set listsize unlimited"
134 gdb_test "complete set listsize unl" "set listsize unlimited"
136 # A var_zuinteger_unlimited command.
137 gdb_test "complete set trace-buffer-size " "set trace-buffer-size unlimited"
138 gdb_test "complete set trace-buffer-size unl" "set trace-buffer-size unlimited"
140 # Test "info registers" completion: First determine this
141 # architecture's registers and reggroups...
143 set regs_output [capture_command_output "mt print registers" \
144 ".*Name.*Nr.*Rel.*Offset.*Size.*Type.\[^\n\]*\n"]
145 append regs_output "\n"
146 append regs_output [capture_command_output "mt print reggroups" \
147 ".*Group.*Type\[^\n]*\n"]
149 foreach {- reg} [regexp -all -inline -line {^\s+(\w+)} $regs_output] {
150 lappend all_regs $reg
153 set regs_output [capture_command_output "mt print user-registers" \
154 ".*Nr.*Name\[^\n]*\n"]
155 foreach {- reg} [regexp -all -inline -line {^\s+\d+\s+(\w+)} $regs_output] {
156 lappend all_regs $reg
159 set all_regs [join [lsort -unique $all_regs]]
161 # ... and then compare them to the completion of "info registers".
163 set regs_output [capture_command_output "complete info registers " ""]
164 set completed_regs {}
165 foreach {-> reg} [regexp -all -inline -line {^info registers (\w+\S*)} $regs_output] {
166 lappend completed_regs $reg
168 set completed_regs [join [lsort $completed_regs]]
169 gdb_assert {{$all_regs eq $completed_regs}} "complete 'info registers '"
171 # Tests below are about tab-completion, which doesn't work if readline
172 # library isn't used. Check it first.
174 if { ![readline_is_used] } {
178 set test "complete 'hfgfh'"
180 gdb_test_multiple "" "$test" {
181 -re "^hfgfh\\\x07$" {
183 gdb_test_multiple "" $test {
184 -re "Undefined command: \"hfgfh\"\\. Try \"help\"\\..*$gdb_prompt $" {
193 set test "complete 'show output'"
194 send_gdb "show output\t"
195 gdb_test_multiple "" "$test" {
196 -re "^show output-radix $" {
198 gdb_test_multiple "" "$test" {
199 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
206 set test "complete 'show output-'"
207 send_gdb "show output-\t"
208 gdb_test_multiple "" "$test" {
209 -re "^show output-radix $" {
211 gdb_test_multiple "" "$test" {
212 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
219 set test "complete 'p'"
221 gdb_test_multiple "" "$test" {
224 gdb_test_multiple "" "$test" {
225 -re "The history is empty\\..*$gdb_prompt $" {
232 set test "complete 'p '"
234 gdb_test_multiple "" "$test" {
237 gdb_test_multiple "" "$test" {
238 -re "The history is empty\\..*$gdb_prompt $" {
245 set test "complete 'info t foo'"
246 send_gdb "info t foo\t"
247 gdb_test_multiple "" "$test" {
248 -re "^info t foo\\\x07$" {
250 gdb_test_multiple "" "$test" {
251 -re "Ambiguous info command \"t foo\": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
258 set test "complete 'info t'"
260 gdb_test_multiple "" "$test" {
261 -re "^info t\\\x07$" {
263 gdb_test_multiple "" "$test" {
264 -re "Ambiguous info command \"t\": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
271 set test "complete 'info t '"
273 gdb_test_multiple "" "$test" {
274 -re "^info t \\\x07$" {
276 gdb_test_multiple "" "$test" {
277 -re "Ambiguous info command \"t \": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
284 set test "complete 'info asdfgh'"
285 send_gdb "info asdfgh\t"
286 gdb_test_multiple "" "$test" {
287 -re "^info asdfgh\\\x07$" {
289 gdb_test_multiple "" "$test" {
290 -re "Undefined info command: \"asdfgh\". Try \"help info\"\\..*$gdb_prompt $" {
297 set test "complete 'info asdfgh '"
298 send_gdb "info asdfgh \t"
299 gdb_test_multiple "" "$test" {
300 -re "^info asdfgh \\\x07$" {
302 gdb_test_multiple "" "$test" {
303 -re "Undefined info command: \"asdfgh \". Try \"help info\"\\..*$gdb_prompt $" {
310 set test "complete 'info'"
312 gdb_test_multiple "" "$test" {
315 gdb_test_multiple "" "$test" {
316 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands.*$gdb_prompt $" {
323 set test "complete 'info '"
325 gdb_test_multiple "" "$test" {
326 -re "^info \\\x07$" {
328 gdb_test_multiple "" "$test" {
329 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands:\r\n\r\n.*$gdb_prompt $" {
336 set test "complete (2) 'info '"
338 gdb_test_multiple "" "$test" {
339 -re "^info \\\x07$" {
341 gdb_test_multiple "" "$test" {
342 -re "address.*types.*$gdb_prompt " {
344 gdb_test_multiple "" "$test" {
345 -re "\"info\".*unambiguous\\..*$gdb_prompt $" {
354 set test "complete 'help info wat'"
355 send_gdb "help info wat\t"
356 gdb_test_multiple "" "$test" {
357 -re "^help info watchpoints $" {
359 gdb_test_multiple "" "$test" {
360 -re "Status of specified watchpoints.*\r\n.*$gdb_prompt $" {
365 -re "^help info wat\\\x07$" {
370 set test "complete 'p \"break1'"
371 send_gdb "p \"break1\t"
372 gdb_test_multiple "" "$test" {
373 -re "^p \"break1\\\x07$" {
375 gdb_test_multiple "" "$test" {}
377 -re "^p \"break1\\.c\"$" {
379 gdb_test_multiple "" "$test" {
380 -re "$gdb_prompt $" {
388 set test "complete 'p \"break1.'"
389 send_gdb "p \"break1.\t"
390 gdb_test_multiple "" "$test" {
391 -re "^p \"break1\\.\\\x07$" {
393 gdb_test_multiple "" "$test" {}
395 -re "^p \"break1\\.c\"$" {
397 gdb_test_multiple "" "$test" {
398 -re "$gdb_prompt $" {
403 -re "^p \"break1\\..*$" {
405 gdb_test_multiple "" "$test" {}
409 set test "complete 'p 'arg'"
411 gdb_test_multiple "" "$test" {
412 -re "^p 'arg\\\x07$" {
414 gdb_test_multiple "" "$test" {
415 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
422 set test "complete (2) 'p 'arg'"
424 gdb_test_multiple "" "$test" {
425 -re "^p 'arg\\\x07$" {
427 gdb_test_multiple "" "$test" {
428 -re "argv.*$gdb_prompt " {
430 gdb_test_multiple "" "$test" {
431 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
436 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
438 gdb_test_multiple "" "$test" {
439 -re "\\(gdb\\) p 'arg$" {
441 gdb_test_multiple "" "$test" {
442 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
453 set test "complete 'handle signal'"
454 send_gdb "handle sigq\t"
455 gdb_test_multiple "" "$test" {
456 -re "^handle sigq
\b\b\b\bSIGQUIT $" {
458 gdb_test_multiple "" "$test" {
459 -re "SIGQUIT.*Quit.*$gdb_prompt $" {
466 set test "complete 'handle keyword'"
467 send_gdb "handle nos\t"
468 gdb_test_multiple "" "$test" {
469 -re "^handle nostop $" {
471 gdb_test_multiple "" "$test" {
472 -re "$gdb_prompt $" {
479 set test "complete help aliases"
480 send_gdb "help user-define\t"
481 gdb_test_multiple "" "$test" {
482 -re "^help user-defined $" {
484 gdb_test_multiple "" "$test" {
485 -re "$gdb_prompt $" {
493 # These tests used to try completing the shorter "p b-a".
494 # Unfortunately, on some systems, there are .o files in system
495 # libraries which declare static variables named `b'. Of course,
496 # those variables aren't really in scope, as far as the compiler is
497 # concerned. But GDB deliberately tries to be more liberal: if you
498 # enter an identifier that doesn't have any binding in scope, GDB will
499 # search all the program's compilation units for a static variable of
502 # This behavior can help avoid a lot of pedantry, so it's usually a
503 # good thing. But in this test case, it causes GDB to print the value
504 # of some random variable, instead of giving us the "No symbol..."
505 # error we were expecting.
507 # For example, on S/390 linux, the file s_atan.c in libm.a declares a
508 # `b', which is a structure containing an int and a float, so GDB says
509 # ``Argument to arithmetic operation not a number or boolean'' instead
510 # of ``No symbol ...''.
512 # So, I'm hoping that there is no system with a static library variable named
513 # `no_var_by_this_name'.
515 set test "complete 'p no_var_named_this-arg'"
516 send_gdb "p no_var_named_this-arg\t"
517 gdb_test_multiple "" "$test" {
518 -re "^p no_var_named_this-arg\\\x07$" {
520 gdb_test_multiple "" "$test" {
521 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
528 set test "complete (2) 'p no_var_named_this-arg'"
529 send_gdb "p no_var_named_this-arg\t"
530 gdb_test_multiple "" "$test" {
531 -re "^p no_var_named_this-arg\\\x07$" {
533 gdb_test_multiple "" "$test" {
534 -re "argv.*$gdb_prompt " {
536 gdb_test_multiple "" "$test" {
537 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
542 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
548 pass "$test (eat prompt)"
551 fail "(timeout) $test (eat prompt)"
555 gdb_test_multiple "" "$test" {
556 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
565 set test "complete (2) 'p no_var_named_this-'"
566 send_gdb "p no_var_named_this-\t"
567 gdb_test_multiple "" "$test" {
568 -re "^p no_var_named_this-\\\x07$" {
570 gdb_test_multiple "" "$test" {
571 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
577 pass "$test (eat prompt)"
580 fail "(timeout) $test (eat prompt)"
584 gdb_test_multiple "" "$test" {
585 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
590 -re "argv.*$gdb_prompt $" {
592 gdb_test_multiple "" "$test" {
593 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
602 set test "complete 'p values\[0\].a'"
603 send_gdb "p values\[0\].a\t"
604 gdb_test_multiple "" "$test" {
605 -re "^p values.0..a_field $" {
607 gdb_test_multiple "" "$test" {
608 -re " = 0.*$gdb_prompt $" {
615 set test "complete 'p values\[0\] . a'"
616 send_gdb "p values\[0\] . a\t"
617 gdb_test_multiple "" "$test" {
618 -re "^p values.0. . a_field $" {
620 gdb_test_multiple "" "$test" {
621 -re " = 0.*$gdb_prompt $" {
628 set test "complete 'p &values\[0\] -> a'"
629 send_gdb "p &values\[0\] -> a\t"
630 gdb_test_multiple "" "$test" {
631 -re "^p &values.0. -> a_field $" {
633 gdb_test_multiple "" "$test" {
634 -re " = .*0x\[0-9a-fA-F\]*.*$gdb_prompt $" {
641 gdb_test "complete p &values\[0\]->z" \
642 "p &values.0.->z_field" \
643 "completion of field in anonymous union"
645 gdb_test "complete ptype &values\[0\]->z" \
646 "ptype &values.0.->z_field" \
647 "ptype completion of field in anonymous union"
649 gdb_test "complete whatis &values\[0\]->z" \
650 "whatis &values.0.->z_field" \
651 "whatis completion of field in anonymous union"
653 # The following tests used to simply try to complete `${objdir}/file',
654 # and so on. The problem is that ${objdir} can be very long; the
655 # completed filename may be more than eighty characters wide. When
656 # this happens, readline tries to manage things, producing output that
657 # may make sense on the screen, but is rather hard for our script to
660 # In the case that motivated this change, the (gdb) prompt occupied
661 # the leftmost six columns, and `${objdir}/' was seventy-four
662 # characters long --- eighty in all. After printing the slash,
663 # readline emitted a space, a carriage return, and then `Makefile'
664 # (the tab character being received as input after `Make'.
666 # Basically, you have to let readline do whatever it's going to do to
667 # make the screen look right. If it happens to use a different
668 # strategy on Tuesdays to get the cursor in the right place, that's
669 # not something the testsuite should care about.
671 # So, we avoid long lines. We `cd' to ${objdir} first, and then do
672 # the completion relative to the current directory.
674 # ${srcdir} may be a relative path. We want to make sure we end up
675 # in the right directory - so make sure we know where it is.
681 # If the directory name contains a '+' we must escape it, adding a backslash.
682 # If not, the test below will fail because it will interpret the '+' as a
683 # regexp operator. We use string_to_regexp for this purpose.
685 gdb_test "cd ${fullsrcdir}" \
686 "Working directory [string_to_regexp ${fullsrcdir}].*" \
690 # GDB used to fail adding / on directories, on the first try only.
691 set uniquedir ../testsuite/gdb.base/comp-dir
692 set escapeduniquedir [string_to_regexp ${uniquedir}]
694 set uniquesub ${uniquesu}r
695 set escapeuniquesub [string_to_regexp ${uniquesub}]
696 send_gdb "dir ${uniquedir}\t"
698 -re "${escapeduniquedir}/" {
699 pass "directory completion"
700 send_gdb "${uniquesu}\t"
702 -re "${escapeduniquedir} $" {
703 fail "directory completion (old gdb bug)"
704 send_gdb "\b/${uniquesu}\t"
707 fail "directory completion (timeout)"
708 send_gdb "\ndir ${uniquedir}/${uniquesu}\t"
713 -re "${escapeuniquesub}/$" {
714 pass "directory completion 2"
717 fail "directory completion 2"
721 # Empty COMMAND sends no newline while " " sends the newline we need.
722 gdb_test " " "Source directories searched: .*" "Glob remaining of directory test"
724 gdb_test "complete file ./gdb.base/compl" \
725 "file ./gdb.base/completion\\.exp.*" \
726 "complete-command 'file ./gdb.base/compl'"
728 set test "complete 'file ./gdb.base/complet'"
729 send_gdb "file ./gdb.base/complet\t"
730 gdb_test_multiple "" "$test" {
731 -re "^file ./gdb.base/completion\\.exp $" {
733 # Ignore the exact error message.
734 gdb_test_multiple "" "complete 'file ./gdb.base/complet'" {
735 -re "\r\nA program is being debugged already\\.\[\r\n\]+Are you sure you want to change the file\\? \\(y or n\\) $" {
739 -re "$gdb_prompt $" {
746 set test "complete 'info func marke'"
747 send_gdb "info func marke\t"
748 gdb_test_multiple "" "$test" {
749 -re "^info func marke.*r$" {
751 gdb_test_multiple "" "$test" {
752 -re "marker1.*$gdb_prompt " {
754 gdb_test_multiple "" "$test" {
755 -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 $" {
765 set test "complete 'set follow-fork-mode'"
766 send_gdb "set follow-fork-mode \t\t"
767 gdb_test_multiple "" "$test" {
768 -re "child.*parent.*$gdb_prompt " {
770 gdb_test_multiple "" "$test" {
771 -re "Requires an argument.*child.*parent.*$gdb_prompt $" {
774 -re "Ambiguous item \"\"\\..*$gdb_prompt $" {