1 # Copyright 1998-1999, 2002-2004, 2007-2012 Free Software Foundation,
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
19 # This file is part of the gdb testsuite.
22 # tests for command completion
24 # Here are some useful test cases for completion.
25 # They should be tested with both M-? and TAB.
27 # "show output-" "radix"
28 # "show output" "-radix"
29 # "p" ambiguous (commands starting with p--path, print, printf, etc.)
30 # "p " ambiguous (all symbols)
31 # "info t foo" no completions
32 # "info t " no completions
33 # "info t" ambiguous ("info target", "info terminal", etc.)
34 # "info ajksdlfk" no completions
35 # "info ajksdlfk " no completions
37 # "info " ambiguous (all info commands)
38 # "p \"break1" unambiguous (completes to filename "break1.c")
39 # "p \"break1." unambiguous (should complete to "break1.c" but does not,
40 # due to readline limitations)
41 # "p 'arg" ambiguous (all symbols starting with arg)
42 # "p b-arg" ambiguous (all symbols starting with arg)
43 # "p b-" ambiguous (all symbols)
44 # "file Make" "file" (word break hard to screw up here)
45 # "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
55 # test running programs
59 set srcfile ${testfile}.c
60 set srcfile1 ${testfile}1.c
61 set binfile ${objdir}/${subdir}/${testfile}
63 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
64 untested completion.exp
68 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
69 untested completion.exp
73 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
74 untested completion.exp
78 if [get_compiler_info ${binfile}] {
85 gdb_reinitialize_dir $srcdir/$subdir
88 if ![runto_main] then {
89 perror "tests suppressed"
92 set oldtimeout1 $timeout
95 set test "complete 'hfgfh'"
97 gdb_test_multiple "" "$test" {
100 gdb_test_multiple "" $test {
101 -re "Undefined command: \"hfgfh\"\\. Try \"help\"\\..*$gdb_prompt $" {
110 set test "complete 'show output'"
111 send_gdb "show output\t"
112 gdb_test_multiple "" "$test" {
113 -re "^show output-radix $" {
115 gdb_test_multiple "" "$test" {
116 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
123 set test "complete 'show output-'"
124 send_gdb "show output-\t"
125 gdb_test_multiple "" "$test" {
126 -re "^show output-radix $" {
128 gdb_test_multiple "" "$test" {
129 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
136 set test "complete 'p'"
138 gdb_test_multiple "" "$test" {
141 gdb_test_multiple "" "$test" {
142 -re "The history is empty\\..*$gdb_prompt $" {
149 set test "complete 'p '"
151 gdb_test_multiple "" "$test" {
154 gdb_test_multiple "" "$test" {
155 -re "The history is empty\\..*$gdb_prompt $" {
162 set test "complete 'info t foo'"
163 send_gdb "info t foo\t"
164 gdb_test_multiple "" "$test" {
165 -re "^info t foo\\\x07$" {
167 gdb_test_multiple "" "$test" {
168 -re "Ambiguous info command \"t foo\": target, tasks, terminal, threads, tp, tracepoints, tvariables, types\\..*$gdb_prompt $" {
175 set test "complete 'info t'"
177 gdb_test_multiple "" "$test" {
178 -re "^info t\\\x07$" {
180 gdb_test_multiple "" "$test" {
181 -re "Ambiguous info command \"t\": target, tasks, terminal, threads, tp, tracepoints, tvariables, types\\..*$gdb_prompt $" {
188 set test "complete 'info t '"
190 gdb_test_multiple "" "$test" {
191 -re "^info t \\\x07$" {
193 gdb_test_multiple "" "$test" {
194 -re "Ambiguous info command \"t \": target, tasks, terminal, threads, tp, tracepoints, tvariables, types\\..*$gdb_prompt $" {
201 set test "complete 'info asdfgh'"
202 send_gdb "info asdfgh\t"
203 gdb_test_multiple "" "$test" {
204 -re "^info asdfgh\\\x07$" {
206 gdb_test_multiple "" "$test" {
207 -re "Undefined info command: \"asdfgh\". Try \"help info\"\\..*$gdb_prompt $" {
214 set test "complete 'info asdfgh '"
215 send_gdb "info asdfgh \t"
216 gdb_test_multiple "" "$test" {
217 -re "^info asdfgh \\\x07$" {
219 gdb_test_multiple "" "$test" {
220 -re "Undefined info command: \"asdfgh \". Try \"help info\"\\..*$gdb_prompt $" {
227 set test "complete 'info'"
229 gdb_test_multiple "" "$test" {
232 gdb_test_multiple "" "$test" {
233 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands.*$gdb_prompt $" {
240 set test "complete 'info '"
242 gdb_test_multiple "" "$test" {
243 -re "^info \\\x07$" {
245 gdb_test_multiple "" "$test" {
246 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands:\r\n\r\n.*$gdb_prompt $" {
253 set test "complete (2) 'info '"
255 gdb_test_multiple "" "$test" {
256 -re "^info \\\x07$" {
258 gdb_test_multiple "" "$test" {
259 -re "address.*types.*$gdb_prompt " {
261 gdb_test_multiple "" "$test" {
262 -re "\"info\".*unambiguous\\..*$gdb_prompt $" {
271 set test "complete 'help info wat'"
272 send_gdb "help info wat\t"
273 gdb_test_multiple "" "$test" {
274 -re "^help info watchpoints $" {
276 gdb_test_multiple "" "$test" {
277 -re "Status of specified watchpoints.*\r\n.*$gdb_prompt $" {
282 -re "^help info wat\\\x07$" {
287 set test "complete 'p \"break1'"
288 send_gdb "p \"break1\t"
289 gdb_test_multiple "" "$test" {
290 -re "^p \"break1\\\x07$" {
292 gdb_test_multiple "" "$test" {}
294 -re "^p \"break1\\.c\"$" {
296 gdb_test_multiple "" "$test" {
297 -re "$gdb_prompt $" {
305 set test "complete 'p \"break1.'"
306 send_gdb "p \"break1.\t"
307 gdb_test_multiple "" "$test" {
308 -re "^p \"break1\\.\\\x07$" {
310 gdb_test_multiple "" "$test" {}
312 -re "^p \"break1\\.c\"$" {
314 gdb_test_multiple "" "$test" {
315 -re "$gdb_prompt $" {
320 -re "^p \"break1\\..*$" {
322 gdb_test_multiple "" "$test" {}
326 set test "complete 'p 'arg'"
328 gdb_test_multiple "" "$test" {
329 -re "^p 'arg\\\x07$" {
331 gdb_test_multiple "" "$test" {
332 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
339 set test "complete (2) 'p 'arg'"
341 gdb_test_multiple "" "$test" {
342 -re "^p 'arg\\\x07$" {
344 gdb_test_multiple "" "$test" {
345 -re "argv.*$gdb_prompt " {
347 gdb_test_multiple "" "$test" {
348 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
353 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
355 gdb_test_multiple "" "$test" {
356 -re "\\(gdb\\) p 'arg$" {
358 gdb_test_multiple "" "$test" {
359 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
371 # These tests used to try completing the shorter "p b-a".
372 # Unfortunately, on some systems, there are .o files in system
373 # libraries which declare static variables named `b'. Of course,
374 # those variables aren't really in scope, as far as the compiler is
375 # concerned. But GDB deliberately tries to be more liberal: if you
376 # enter an identifier that doesn't have any binding in scope, GDB will
377 # search all the program's compilation units for a static variable of
380 # This behavior can help avoid a lot of pedantry, so it's usually a
381 # good thing. But in this test case, it causes GDB to print the value
382 # of some random variable, instead of giving us the "No symbol..."
383 # error we were expecting.
385 # For example, on S/390 linux, the file s_atan.c in libm.a declares a
386 # `b', which is a structure containing an int and a float, so GDB says
387 # ``Argument to arithmetic operation not a number or boolean'' instead
388 # of ``No symbol ...''.
390 # So, I'm hoping that there is no system with a static library variable named
391 # `no_var_by_this_name'.
393 set test "complete 'p no_var_named_this-arg'"
394 send_gdb "p no_var_named_this-arg\t"
395 gdb_test_multiple "" "$test" {
396 -re "^p no_var_named_this-arg\\\x07$" {
398 gdb_test_multiple "" "$test" {
399 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
406 set test "complete (2) 'p no_var_named_this-arg'"
407 send_gdb "p no_var_named_this-arg\t"
408 gdb_test_multiple "" "$test" {
409 -re "^p no_var_named_this-arg\\\x07$" {
411 gdb_test_multiple "" "$test" {
412 -re "argv.*$gdb_prompt " {
414 gdb_test_multiple "" "$test" {
415 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
420 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
426 pass "$test (eat prompt)"
429 fail "(timeout) $test (eat prompt)"
433 gdb_test_multiple "" "$test" {
434 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
443 set test "complete (2) 'p no_var_named_this-'"
444 send_gdb "p no_var_named_this-\t"
445 gdb_test_multiple "" "$test" {
446 -re "^p no_var_named_this-\\\x07$" {
448 gdb_test_multiple "" "$test" {
449 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
455 pass "$test (eat prompt)"
458 fail "(timeout) $test (eat prompt)"
462 gdb_test_multiple "" "$test" {
463 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
468 -re "argv.*$gdb_prompt $" {
470 gdb_test_multiple "" "$test" {
471 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
480 set test "complete 'p values\[0\].a'"
481 send_gdb "p values\[0\].a\t"
482 gdb_test_multiple "" "$test" {
483 -re "^p values.0..a_field $" {
485 gdb_test_multiple "" "$test" {
486 -re " = 0.*$gdb_prompt $" {
493 set test "complete 'p values\[0\] . a'"
494 send_gdb "p values\[0\] . a\t"
495 gdb_test_multiple "" "$test" {
496 -re "^p values.0. . a_field $" {
498 gdb_test_multiple "" "$test" {
499 -re " = 0.*$gdb_prompt $" {
506 set test "complete 'p &values\[0\] -> a'"
507 send_gdb "p &values\[0\] -> a\t"
508 gdb_test_multiple "" "$test" {
509 -re "^p &values.0. -> a_field $" {
511 gdb_test_multiple "" "$test" {
512 -re " = .*0x\[0-9a-fA-F\]*.*$gdb_prompt $" {
519 gdb_test "complete p &values\[0\]->z" \
520 "p &values.0.->z_field" \
521 "completion of field in anonymous union"
523 # The following tests used to simply try to complete `${objdir}/file',
524 # and so on. The problem is that ${objdir} can be very long; the
525 # completed filename may be more than eighty characters wide. When
526 # this happens, readline tries to manage things, producing output that
527 # may make sense on the screen, but is rather hard for our script to
530 # In the case that motivated this change, the (gdb) prompt occupied
531 # the leftmost six columns, and `${objdir}/' was seventy-four
532 # characters long --- eighty in all. After printing the slash,
533 # readline emitted a space, a carriage return, and then `Makefile'
534 # (the tab character being received as input after `Make'.
536 # Basically, you have to let readline do whatever it's going to do to
537 # make the screen look right. If it happens to use a different
538 # strategy on Tuesdays to get the cursor in the right place, that's
539 # not something the testsuite should care about.
541 # So, we avoid long lines. We `cd' to ${objdir} first, and then do
542 # the completion relative to the current directory.
544 # ${srcdir} may be a relative path. We want to make sure we end up
545 # in the right directory - so make sure we know where it is.
551 # If the directory name contains a '+' we must escape it, adding a backslash.
552 # If not, the test below will fail because it will interpret the '+' as a
553 # regexp operator. We use string_to_regexp for this purpose.
555 gdb_test "cd ${fullsrcdir}" \
556 "Working directory [string_to_regexp ${fullsrcdir}].*" \
560 # GDB used to fail adding / on directories, on the first try only.
561 set uniquedir ../testsuite/gdb.base/comp-dir
562 set escapeduniquedir [string_to_regexp ${uniquedir}]
564 set uniquesub ${uniquesu}r
565 set escapeuniquesub [string_to_regexp ${uniquesub}]
566 send_gdb "dir ${uniquedir}\t"
568 -re "${escapeduniquedir}/" {
569 pass "directory completion"
570 send_gdb "${uniquesu}\t"
572 -re "${escapeduniquedir} $" {
573 fail "directory completion (old gdb bug)"
574 send_gdb "\b/${uniquesu}\t"
577 fail "directory completion (timeout)"
578 send_gdb "\ndir ${uniquedir}/${uniquesu}\t"
583 -re "${escapeuniquesub}/$" {
584 pass "directory completion 2"
587 fail "directory completion 2"
591 # Empty COMMAND sends no newline while " " sends the newline we need.
592 gdb_test " " "Source directories searched: .*" "Glob remaining of directory test"
594 gdb_test "complete file ./gdb.base/compl" \
595 "file ./gdb.base/completion\\.exp.*" \
596 "complete-command 'file ./gdb.base/compl'"
598 set test "complete 'file ./gdb.base/complet'"
599 send_gdb "file ./gdb.base/complet\t"
600 gdb_test_multiple "" "$test" {
601 -re "^file ./gdb.base/completion\\.exp $" {
603 # Ignore the exact error message.
604 gdb_test_multiple "" "complete 'file ./gdb.base/complet'" {
605 -re "\r\nA program is being debugged already\\.\[\r\n\]+Are you sure you want to change the file\\? \\(y or n\\) $" {
609 -re "$gdb_prompt $" {
616 set test "complete 'info func marke'"
617 send_gdb "info func marke\t"
618 gdb_test_multiple "" "$test" {
619 -re "^info func marke.*r$" {
621 gdb_test_multiple "" "$test" {
622 -re "marker1.*$gdb_prompt " {
624 gdb_test_multiple "" "$test" {
625 -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 $" {
635 set test "complete 'set follow-fork-mode'"
636 send_gdb "set follow-fork-mode \t\t"
637 gdb_test_multiple "" "$test" {
638 -re "child.*parent.*$gdb_prompt " {
640 gdb_test_multiple "" "$test" {
641 -re "Requires an argument.*child.*parent.*$gdb_prompt $" {
644 -re "Ambiguous item \"\"\\..*$gdb_prompt $" {
651 gdb_test_no_output "complete print values\[0\].x." \
652 "field completion with invalid field"
654 # If there is a non-deprecated completion, it should be returned.
655 gdb_test "complete sav" "save" "test non-deprecated completion"
656 # If there is only a deprecated completion, then it should be returned.
657 gdb_test "complete save-t" "save-tracepoints" "test deprecated completion"
660 # Restore globals modified in this test...
661 set timeout $oldtimeout1