1 # Copyright 1998, 1999, 2002, 2003, 2004, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
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)
57 # test running programs
61 set srcfile ${testfile}.c
62 set srcfile1 ${testfile}1.c
63 set binfile ${objdir}/${subdir}/${testfile}
65 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
66 untested completion.exp
70 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
71 untested completion.exp
75 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
76 untested completion.exp
80 if [get_compiler_info ${binfile}] {
87 gdb_reinitialize_dir $srcdir/$subdir
90 if ![runto_main] then {
91 perror "tests suppressed"
94 set oldtimeout1 $timeout
97 set test "complete 'hfgfh'"
99 gdb_test_multiple "" "$test" {
100 -re "^hfgfh\\\x07$" {
102 gdb_test_multiple "" $test {
103 -re "Undefined command: \"hfgfh\"\\. Try \"help\"\\..*$gdb_prompt $" {
112 set test "complete 'show output'"
113 send_gdb "show output\t"
114 gdb_test_multiple "" "$test" {
115 -re "^show output-radix $" {
117 gdb_test_multiple "" "$test" {
118 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
125 set test "complete 'show output-'"
126 send_gdb "show output-\t"
127 gdb_test_multiple "" "$test" {
128 -re "^show output-radix $" {
130 gdb_test_multiple "" "$test" {
131 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
138 set test "complete 'p'"
140 gdb_test_multiple "" "$test" {
143 gdb_test_multiple "" "$test" {
144 -re "The history is empty\\..*$gdb_prompt $" {
151 set test "complete 'p '"
153 gdb_test_multiple "" "$test" {
156 gdb_test_multiple "" "$test" {
157 -re "The history is empty\\..*$gdb_prompt $" {
164 set test "complete 'info t foo'"
165 send_gdb "info t foo\t"
166 gdb_test_multiple "" "$test" {
167 -re "^info t foo\\\x07$" {
169 gdb_test_multiple "" "$test" {
170 -re "Ambiguous info command \"t foo\": target, tasks, terminal, threads, tp, tracepoints, tvariables, types\\..*$gdb_prompt $" {
177 set test "complete 'info t'"
179 gdb_test_multiple "" "$test" {
180 -re "^info t\\\x07$" {
182 gdb_test_multiple "" "$test" {
183 -re "Ambiguous info command \"t\": target, tasks, terminal, threads, tp, tracepoints, tvariables, types\\..*$gdb_prompt $" {
190 set test "complete 'info t '"
192 gdb_test_multiple "" "$test" {
193 -re "^info t \\\x07$" {
195 gdb_test_multiple "" "$test" {
196 -re "Ambiguous info command \"t \": target, tasks, terminal, threads, tp, tracepoints, tvariables, types\\..*$gdb_prompt $" {
203 set test "complete 'info asdfgh'"
204 send_gdb "info asdfgh\t"
205 gdb_test_multiple "" "$test" {
206 -re "^info asdfgh\\\x07$" {
208 gdb_test_multiple "" "$test" {
209 -re "Undefined info command: \"asdfgh\". Try \"help info\"\\..*$gdb_prompt $" {
216 set test "complete 'info asdfgh '"
217 send_gdb "info asdfgh \t"
218 gdb_test_multiple "" "$test" {
219 -re "^info asdfgh \\\x07$" {
221 gdb_test_multiple "" "$test" {
222 -re "Undefined info command: \"asdfgh \". Try \"help info\"\\..*$gdb_prompt $" {
229 set test "complete 'info'"
231 gdb_test_multiple "" "$test" {
234 gdb_test_multiple "" "$test" {
235 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands.*$gdb_prompt $" {
242 set test "complete 'info '"
244 gdb_test_multiple "" "$test" {
245 -re "^info \\\x07$" {
247 gdb_test_multiple "" "$test" {
248 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands:\r\n\r\n.*$gdb_prompt $" {
255 set test "complete (2) 'info '"
257 gdb_test_multiple "" "$test" {
258 -re "^info \\\x07$" {
260 gdb_test_multiple "" "$test" {
261 -re "address.*types.*$gdb_prompt " {
263 gdb_test_multiple "" "$test" {
264 -re "\"info\".*unambiguous\\..*$gdb_prompt $" {
273 set test "complete help info wat"
274 send_gdb "help info wat\t"
275 gdb_test_multiple "" "$test" {
276 -re "^help info watchpoints $" {
278 gdb_test_multiple "" "$test" {
279 -re "Status of specified watchpoints.*\r\n.*$gdb_prompt $" {
284 -re "^help info wat\\\x07$" {
289 set test "complete 'p \"break1'"
290 send_gdb "p \"break1\t"
291 gdb_test_multiple "" "$test" {
292 -re "^p \"break1\\\x07$" {
294 gdb_test_multiple "" "$test" {}
296 -re "^p \"break1\\.c\"$" {
298 gdb_test_multiple "" "$test" {
299 -re ".*$gdb_prompt $" {
307 set test "complete 'p \"break1.'"
308 send_gdb "p \"break1.\t"
309 gdb_test_multiple "" "$test" {
310 -re "^p \"break1\\.\\\x07$" {
312 gdb_test_multiple "" "$test" {}
314 -re "^p \"break1\\.c\"$" {
316 gdb_test_multiple "" "$test" {
317 -re ".*$gdb_prompt $" {
322 -re "^p \"break1\\..*$" {
324 gdb_test_multiple "" "$test" {}
328 set test "complete 'p \'arg'"
330 gdb_test_multiple "" "$test" {
331 -re "^p 'arg\\\x07$" {
333 gdb_test_multiple "" "$test" {
334 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
341 set test "complete (2) 'p \'arg'"
343 gdb_test_multiple "" "$test" {
344 -re "^p 'arg\\\x07$" {
346 gdb_test_multiple "" "$test" {
347 -re ".*argv.*$gdb_prompt " {
349 gdb_test_multiple "" "$test" {
350 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
355 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
357 gdb_test_multiple "" "$test" {
358 -re "\\(gdb\\) p 'arg$" {
360 gdb_test_multiple "" "$test" {
361 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
373 # These tests used to try completing the shorter "p b-a".
374 # Unfortunately, on some systems, there are .o files in system
375 # libraries which declare static variables named `b'. Of course,
376 # those variables aren't really in scope, as far as the compiler is
377 # concerned. But GDB deliberately tries to be more liberal: if you
378 # enter an identifier that doesn't have any binding in scope, GDB will
379 # search all the program's compilation units for a static variable of
382 # This behavior can help avoid a lot of pedantry, so it's usually a
383 # good thing. But in this test case, it causes GDB to print the value
384 # of some random variable, instead of giving us the "No symbol..."
385 # error we were expecting.
387 # For example, on S/390 linux, the file s_atan.c in libm.a declares a
388 # `b', which is a structure containing an int and a float, so GDB says
389 # ``Argument to arithmetic operation not a number or boolean'' instead
390 # of ``No symbol ...''.
392 # So, I'm hoping that there is no system with a static library variable named
393 # `no_var_by_this_name'.
395 set test "complete 'p no_var_named_this-arg'"
396 send_gdb "p no_var_named_this-arg\t"
397 gdb_test_multiple "" "$test" {
398 -re "^p no_var_named_this-arg\\\x07$" {
400 gdb_test_multiple "" "$test" {
401 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
408 set test "complete (2) 'p no_var_named_this-arg'"
409 send_gdb "p no_var_named_this-arg\t"
410 gdb_test_multiple "" "$test" {
411 -re "^p no_var_named_this-arg\\\x07$" {
413 gdb_test_multiple "" "$test" {
414 -re ".*argv.*$gdb_prompt " {
416 gdb_test_multiple "" "$test" {
417 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
422 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
428 pass "$test (eat prompt)"
431 fail "(timeout) $test (eat prompt)"
435 gdb_test_multiple "" "$test" {
436 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
445 set test "complete (2) 'p no_var_named_this-'"
446 send_gdb "p no_var_named_this-\t"
447 gdb_test_multiple "" "$test" {
448 -re "^p no_var_named_this-\\\x07$" {
450 gdb_test_multiple "" "$test" {
451 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
457 pass "$test (eat prompt)"
460 fail "(timeout) $test (eat prompt)"
464 gdb_test_multiple "" "$test" {
465 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
470 -re ".*argv.*$gdb_prompt $" {
472 gdb_test_multiple "" "$test" {
473 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
482 set test "complete 'p values\[0\].a'"
483 send_gdb "p values\[0\].a\t"
484 gdb_test_multiple "" "$test" {
485 -re "^p values.0..a_field $" {
487 gdb_test_multiple "" "$test" {
488 -re "^.* = 0.*$gdb_prompt $" {
495 set test "complete 'p values\[0\] . a'"
496 send_gdb "p values\[0\] . a\t"
497 gdb_test_multiple "" "$test" {
498 -re "^p values.0. . a_field $" {
500 gdb_test_multiple "" "$test" {
501 -re "^.* = 0.*$gdb_prompt $" {
508 set test "complete 'p &values\[0\] -> a'"
509 send_gdb "p &values\[0\] -> a\t"
510 gdb_test_multiple "" "$test" {
511 -re "^p &values.0. -> a_field $" {
513 gdb_test_multiple "" "$test" {
514 -re "^.* = .*0x\[0-9a-fA-F\]*.*$gdb_prompt $" {
521 gdb_test "complete p &values\[0\]->z" \
522 "p &values.0.->z_field" \
523 "completion of field in anonymous union"
525 # The following tests used to simply try to complete `${objdir}/file',
526 # and so on. The problem is that ${objdir} can be very long; the
527 # completed filename may be more than eighty characters wide. When
528 # this happens, readline tries to manage things, producing output that
529 # may make sense on the screen, but is rather hard for our script to
532 # In the case that motivated this change, the (gdb) prompt occupied
533 # the leftmost six columns, and `${objdir}/' was seventy-four
534 # characters long --- eighty in all. After printing the slash,
535 # readline emitted a space, a carriage return, and then `Makefile'
536 # (the tab character being received as input after `Make'.
538 # Basically, you have to let readline do whatever it's going to do to
539 # make the screen look right. If it happens to use a different
540 # strategy on Tuesdays to get the cursor in the right place, that's
541 # not something the testsuite should care about.
543 # So, we avoid long lines. We `cd' to ${objdir} first, and then do
544 # the completion relative to the current directory.
546 # ${srcdir} may be a relative path. We want to make sure we end up
547 # in the right directory - so make sure we know where it is.
553 # If the directory name contains a '+' we must escape it, adding a backslash.
554 # If not, the test below will fail because it will interpret the '+' as a
555 # regexp operator. We use string_to_regexp for this purpose.
557 gdb_test "cd ${fullsrcdir}" \
558 "Working directory [string_to_regexp ${fullsrcdir}].*" \
562 # GDB used to fail adding / on directories, on the first try only.
563 set uniquedir ../testsuite/gdb.base/comp-dir
564 set escapeduniquedir [string_to_regexp ${uniquedir}]
566 set uniquesub ${uniquesu}r
567 set escapeuniquesub [string_to_regexp ${uniquesub}]
568 send_gdb "dir ${uniquedir}\t"
570 -re "${escapeduniquedir}/" {
571 pass "directory completion"
572 send_gdb "${uniquesu}\t"
574 -re "${escapeduniquedir} $" {
575 fail "directory completion (old gdb bug)"
576 send_gdb "\b/${uniquesu}\t"
579 fail "directory completion (timeout)"
580 send_gdb "\ndir ${uniquedir}/${uniquesu}\t"
585 -re "${escapeuniquesub}/$" {
586 pass "directory completion 2"
589 fail "directory completion 2"
593 # Empty COMMAND sends no newline while " " sends the newline we need.
594 gdb_test " " "Source directories searched: .*" "Glob remaining of directory test"
596 gdb_test "complete file ./gdb.base/compl" \
597 "file ./gdb.base/completion\\.exp.*" \
598 "complete-command 'file ./gdb.base/compl'"
600 set test "complete 'file ./gdb.base/complet'"
601 send_gdb "file ./gdb.base/complet\t"
602 gdb_test_multiple "" "$test" {
603 -re "^file ./gdb.base/completion\\.exp $" {
605 # Ignore the exact error message.
606 gdb_test_multiple "" "complete 'file ./gdb.base/complet'" {
607 -re "\r\nA program is being debugged already\\.\[\r\n\]+Are you sure you want to change the file\\? \\(y or n\\) $" {
611 -re ".*$gdb_prompt $" {
618 set test "complete 'info func marke'"
619 send_gdb "info func marke\t"
620 gdb_test_multiple "" "$test" {
621 -re "^info func marke.*r$" {
623 gdb_test_multiple "" "$test" {
624 -re "marker1.*$gdb_prompt " {
626 gdb_test_multiple "" "$test" {
627 -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 $" {
637 set test "complete 'set follow-fork-mode'"
638 send_gdb "set follow-fork-mode \t\t"
639 gdb_test_multiple "" "$test" {
640 -re "child.*parent.*$gdb_prompt " {
642 gdb_test_multiple "" "$test" {
643 -re "Requires an argument.*child.*parent.*$gdb_prompt $" {
646 -re "Ambiguous item \"\"\\..*$gdb_prompt $" {
653 gdb_test_no_output "complete print values\[0\].x." \
654 "field completion with invalid field"
656 # If there is a non-deprecated completion, it should be returned.
657 gdb_test "complete sav" "save" "test non-deprecated completion"
658 # If there is only a deprecated completion, then it should be returned.
659 gdb_test "complete save-t" "save-tracepoints" "test deprecated completion"
662 # Restore globals modified in this test...
663 set timeout $oldtimeout1