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 set test "complete 'hfgfh'"
74 gdb_test_multiple "" "$test" {
77 gdb_test_multiple "" $test {
78 -re "Undefined command: \"hfgfh\"\\. Try \"help\"\\..*$gdb_prompt $" {
87 set test "complete 'show output'"
88 send_gdb "show output\t"
89 gdb_test_multiple "" "$test" {
90 -re "^show output-radix $" {
92 gdb_test_multiple "" "$test" {
93 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
100 set test "complete 'show output-'"
101 send_gdb "show output-\t"
102 gdb_test_multiple "" "$test" {
103 -re "^show output-radix $" {
105 gdb_test_multiple "" "$test" {
106 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
113 set test "complete 'p'"
115 gdb_test_multiple "" "$test" {
118 gdb_test_multiple "" "$test" {
119 -re "The history is empty\\..*$gdb_prompt $" {
126 set test "complete 'p '"
128 gdb_test_multiple "" "$test" {
131 gdb_test_multiple "" "$test" {
132 -re "The history is empty\\..*$gdb_prompt $" {
139 set test "complete 'info t foo'"
140 send_gdb "info t foo\t"
141 gdb_test_multiple "" "$test" {
142 -re "^info t foo\\\x07$" {
144 gdb_test_multiple "" "$test" {
145 -re "Ambiguous info command \"t foo\": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
152 set test "complete 'info t'"
154 gdb_test_multiple "" "$test" {
155 -re "^info t\\\x07$" {
157 gdb_test_multiple "" "$test" {
158 -re "Ambiguous info command \"t\": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
165 set test "complete 'info t '"
167 gdb_test_multiple "" "$test" {
168 -re "^info t \\\x07$" {
170 gdb_test_multiple "" "$test" {
171 -re "Ambiguous info command \"t \": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
178 set test "complete 'info asdfgh'"
179 send_gdb "info asdfgh\t"
180 gdb_test_multiple "" "$test" {
181 -re "^info asdfgh\\\x07$" {
183 gdb_test_multiple "" "$test" {
184 -re "Undefined info command: \"asdfgh\". Try \"help info\"\\..*$gdb_prompt $" {
191 set test "complete 'info asdfgh '"
192 send_gdb "info asdfgh \t"
193 gdb_test_multiple "" "$test" {
194 -re "^info asdfgh \\\x07$" {
196 gdb_test_multiple "" "$test" {
197 -re "Undefined info command: \"asdfgh \". Try \"help info\"\\..*$gdb_prompt $" {
204 set test "complete 'info'"
206 gdb_test_multiple "" "$test" {
209 gdb_test_multiple "" "$test" {
210 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands.*$gdb_prompt $" {
217 set test "complete 'info '"
219 gdb_test_multiple "" "$test" {
220 -re "^info \\\x07$" {
222 gdb_test_multiple "" "$test" {
223 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands:\r\n\r\n.*$gdb_prompt $" {
230 set test "complete (2) 'info '"
232 gdb_test_multiple "" "$test" {
233 -re "^info \\\x07$" {
235 gdb_test_multiple "" "$test" {
236 -re "address.*types.*$gdb_prompt " {
238 gdb_test_multiple "" "$test" {
239 -re "\"info\".*unambiguous\\..*$gdb_prompt $" {
248 set test "complete 'help info wat'"
249 send_gdb "help info wat\t"
250 gdb_test_multiple "" "$test" {
251 -re "^help info watchpoints $" {
253 gdb_test_multiple "" "$test" {
254 -re "Status of specified watchpoints.*\r\n.*$gdb_prompt $" {
259 -re "^help info wat\\\x07$" {
264 set test "complete 'p \"break1'"
265 send_gdb "p \"break1\t"
266 gdb_test_multiple "" "$test" {
267 -re "^p \"break1\\\x07$" {
269 gdb_test_multiple "" "$test" {}
271 -re "^p \"break1\\.c\"$" {
273 gdb_test_multiple "" "$test" {
274 -re "$gdb_prompt $" {
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 $" {
297 -re "^p \"break1\\..*$" {
299 gdb_test_multiple "" "$test" {}
303 set test "complete 'p 'arg'"
305 gdb_test_multiple "" "$test" {
306 -re "^p 'arg\\\x07$" {
308 gdb_test_multiple "" "$test" {
309 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
316 set test "complete (2) 'p 'arg'"
318 gdb_test_multiple "" "$test" {
319 -re "^p 'arg\\\x07$" {
321 gdb_test_multiple "" "$test" {
322 -re "argv.*$gdb_prompt " {
324 gdb_test_multiple "" "$test" {
325 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
330 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
332 gdb_test_multiple "" "$test" {
333 -re "\\(gdb\\) p 'arg$" {
335 gdb_test_multiple "" "$test" {
336 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
347 set test "complete 'handle signal'"
348 send_gdb "handle sigq\t"
349 gdb_test_multiple "" "$test" {
350 -re "^handle sigq
\b\b\b\bSIGQUIT $" {
352 gdb_test_multiple "" "$test" {
353 -re "SIGQUIT.*Quit.*$gdb_prompt $" {
360 set test "complete 'handle keyword'"
361 send_gdb "handle nos\t"
362 gdb_test_multiple "" "$test" {
363 -re "^handle nostop $" {
365 gdb_test_multiple "" "$test" {
366 -re "$gdb_prompt $" {
373 set test "complete help aliases"
374 send_gdb "help user-define\t"
375 gdb_test_multiple "" "$test" {
376 -re "^help user-defined $" {
378 gdb_test_multiple "" "$test" {
379 -re "$gdb_prompt $" {
387 # These tests used to try completing the shorter "p b-a".
388 # Unfortunately, on some systems, there are .o files in system
389 # libraries which declare static variables named `b'. Of course,
390 # those variables aren't really in scope, as far as the compiler is
391 # concerned. But GDB deliberately tries to be more liberal: if you
392 # enter an identifier that doesn't have any binding in scope, GDB will
393 # search all the program's compilation units for a static variable of
396 # This behavior can help avoid a lot of pedantry, so it's usually a
397 # good thing. But in this test case, it causes GDB to print the value
398 # of some random variable, instead of giving us the "No symbol..."
399 # error we were expecting.
401 # For example, on S/390 linux, the file s_atan.c in libm.a declares a
402 # `b', which is a structure containing an int and a float, so GDB says
403 # ``Argument to arithmetic operation not a number or boolean'' instead
404 # of ``No symbol ...''.
406 # So, I'm hoping that there is no system with a static library variable named
407 # `no_var_by_this_name'.
409 set test "complete 'p no_var_named_this-arg'"
410 send_gdb "p no_var_named_this-arg\t"
411 gdb_test_multiple "" "$test" {
412 -re "^p no_var_named_this-arg\\\x07$" {
414 gdb_test_multiple "" "$test" {
415 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
422 set test "complete (2) 'p no_var_named_this-arg'"
423 send_gdb "p no_var_named_this-arg\t"
424 gdb_test_multiple "" "$test" {
425 -re "^p no_var_named_this-arg\\\x07$" {
427 gdb_test_multiple "" "$test" {
428 -re "argv.*$gdb_prompt " {
430 gdb_test_multiple "" "$test" {
431 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
436 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
442 pass "$test (eat prompt)"
445 fail "(timeout) $test (eat prompt)"
449 gdb_test_multiple "" "$test" {
450 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
459 set test "complete (2) 'p no_var_named_this-'"
460 send_gdb "p no_var_named_this-\t"
461 gdb_test_multiple "" "$test" {
462 -re "^p no_var_named_this-\\\x07$" {
464 gdb_test_multiple "" "$test" {
465 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
471 pass "$test (eat prompt)"
474 fail "(timeout) $test (eat prompt)"
478 gdb_test_multiple "" "$test" {
479 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
484 -re "argv.*$gdb_prompt $" {
486 gdb_test_multiple "" "$test" {
487 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
496 set test "complete 'p values\[0\].a'"
497 send_gdb "p values\[0\].a\t"
498 gdb_test_multiple "" "$test" {
499 -re "^p values.0..a_field $" {
501 gdb_test_multiple "" "$test" {
502 -re " = 0.*$gdb_prompt $" {
509 set test "complete 'p values\[0\] . a'"
510 send_gdb "p values\[0\] . a\t"
511 gdb_test_multiple "" "$test" {
512 -re "^p values.0. . a_field $" {
514 gdb_test_multiple "" "$test" {
515 -re " = 0.*$gdb_prompt $" {
522 set test "complete 'p &values\[0\] -> a'"
523 send_gdb "p &values\[0\] -> a\t"
524 gdb_test_multiple "" "$test" {
525 -re "^p &values.0. -> a_field $" {
527 gdb_test_multiple "" "$test" {
528 -re " = .*0x\[0-9a-fA-F\]*.*$gdb_prompt $" {
535 gdb_test "complete p &values\[0\]->z" \
536 "p &values.0.->z_field" \
537 "completion of field in anonymous union"
539 gdb_test "complete ptype &values\[0\]->z" \
540 "ptype &values.0.->z_field" \
541 "ptype completion of field in anonymous union"
543 gdb_test "complete whatis &values\[0\]->z" \
544 "whatis &values.0.->z_field" \
545 "whatis completion of field in anonymous union"
547 # The following tests used to simply try to complete `${objdir}/file',
548 # and so on. The problem is that ${objdir} can be very long; the
549 # completed filename may be more than eighty characters wide. When
550 # this happens, readline tries to manage things, producing output that
551 # may make sense on the screen, but is rather hard for our script to
554 # In the case that motivated this change, the (gdb) prompt occupied
555 # the leftmost six columns, and `${objdir}/' was seventy-four
556 # characters long --- eighty in all. After printing the slash,
557 # readline emitted a space, a carriage return, and then `Makefile'
558 # (the tab character being received as input after `Make'.
560 # Basically, you have to let readline do whatever it's going to do to
561 # make the screen look right. If it happens to use a different
562 # strategy on Tuesdays to get the cursor in the right place, that's
563 # not something the testsuite should care about.
565 # So, we avoid long lines. We `cd' to ${objdir} first, and then do
566 # the completion relative to the current directory.
568 # ${srcdir} may be a relative path. We want to make sure we end up
569 # in the right directory - so make sure we know where it is.
575 # If the directory name contains a '+' we must escape it, adding a backslash.
576 # If not, the test below will fail because it will interpret the '+' as a
577 # regexp operator. We use string_to_regexp for this purpose.
579 gdb_test "cd ${fullsrcdir}" \
580 "Working directory [string_to_regexp ${fullsrcdir}].*" \
584 # GDB used to fail adding / on directories, on the first try only.
585 set uniquedir ../testsuite/gdb.base/comp-dir
586 set escapeduniquedir [string_to_regexp ${uniquedir}]
588 set uniquesub ${uniquesu}r
589 set escapeuniquesub [string_to_regexp ${uniquesub}]
590 send_gdb "dir ${uniquedir}\t"
592 -re "${escapeduniquedir}/" {
593 pass "directory completion"
594 send_gdb "${uniquesu}\t"
596 -re "${escapeduniquedir} $" {
597 fail "directory completion (old gdb bug)"
598 send_gdb "\b/${uniquesu}\t"
601 fail "directory completion (timeout)"
602 send_gdb "\ndir ${uniquedir}/${uniquesu}\t"
607 -re "${escapeuniquesub}/$" {
608 pass "directory completion 2"
611 fail "directory completion 2"
615 # Empty COMMAND sends no newline while " " sends the newline we need.
616 gdb_test " " "Source directories searched: .*" "Glob remaining of directory test"
618 gdb_test "complete file ./gdb.base/compl" \
619 "file ./gdb.base/completion\\.exp.*" \
620 "complete-command 'file ./gdb.base/compl'"
622 set test "complete 'file ./gdb.base/complet'"
623 send_gdb "file ./gdb.base/complet\t"
624 gdb_test_multiple "" "$test" {
625 -re "^file ./gdb.base/completion\\.exp $" {
627 # Ignore the exact error message.
628 gdb_test_multiple "" "complete 'file ./gdb.base/complet'" {
629 -re "\r\nA program is being debugged already\\.\[\r\n\]+Are you sure you want to change the file\\? \\(y or n\\) $" {
633 -re "$gdb_prompt $" {
640 set test "complete 'info func marke'"
641 send_gdb "info func marke\t"
642 gdb_test_multiple "" "$test" {
643 -re "^info func marke.*r$" {
645 gdb_test_multiple "" "$test" {
646 -re "marker1.*$gdb_prompt " {
648 gdb_test_multiple "" "$test" {
649 -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 $" {
659 set test "complete 'set follow-fork-mode'"
660 send_gdb "set follow-fork-mode \t\t"
661 gdb_test_multiple "" "$test" {
662 -re "child.*parent.*$gdb_prompt " {
664 gdb_test_multiple "" "$test" {
665 -re "Requires an argument.*child.*parent.*$gdb_prompt $" {
668 -re "Ambiguous item \"\"\\..*$gdb_prompt $" {
675 gdb_test_no_output "complete print values\[0\].x." \
676 "field completion with invalid field"
678 # If there is a non-deprecated completion, it should be returned.
679 gdb_test "complete sav" "save" "test non-deprecated completion"
680 # If there is only a deprecated completion, then it should be returned.
681 gdb_test "complete save-t" "save-tracepoints" "test deprecated completion"
685 # Tag name completion.
688 gdb_test "complete ptype struct some_" "ptype struct some_struct"
689 gdb_test "complete ptype enum some_" "ptype enum some_enum"
690 gdb_test "complete ptype union some_" "ptype union some_union"
693 gdb_test "complete set gnutarget aut" "set gnutarget auto"
696 gdb_test "complete set cp-abi aut" "set cp-abi auto"
698 # Test that completion of commands 'target FOO' works well.
699 set targets [list "core" "tfile" "exec"]
701 # Test that completion of command 'target ctf' if GDB supports ctf
703 gdb_test_multiple "target ctf" "" {
704 -re "Undefined target command: \"ctf\"\. Try \"help target\"\.\r\n$gdb_prompt $" {
706 -re "No CTF directory specified.*\r\n$gdb_prompt $" {
707 lappend targets "ctf"
711 foreach target_name ${targets} {
712 gdb_test "complete target ${target_name} ./gdb.base/completion" \
713 "target ${target_name} ./gdb.base/completion\\.exp.*"
717 # "set foo unlimited" completion.
720 # A var_uinteger command.
721 gdb_test "complete set height " "set height unlimited"
722 gdb_test "complete set height u" "set height unlimited"
724 # A var_integer command.
725 gdb_test "complete set listsize " "set listsize unlimited"
726 gdb_test "complete set listsize unl" "set listsize unlimited"
728 # A var_zuinteger_unlimited command.
729 gdb_test "complete set trace-buffer-size " "set trace-buffer-size unlimited"
730 gdb_test "complete set trace-buffer-size unl" "set trace-buffer-size unlimited"
732 # Restore globals modified in this test...
733 set timeout $oldtimeout1