]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/completion.exp
gdb/testsuite/
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / completion.exp
1 # Copyright 1998-2013 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
17
18 # This file is part of the gdb testsuite.
19
20 #
21 # tests for command completion
22 #
23 # Here are some useful test cases for completion.
24 # They should be tested with both M-? and TAB.
25 #
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
35 # "info" " "
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)
45 #
46
47
48
49 #
50 # test running programs
51 #
52
53 set testfile "break"
54 set srcfile ${testfile}.c
55 set srcfile1 ${testfile}1.c
56 set binfile ${objdir}/${subdir}/${testfile}
57
58 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
59 untested completion.exp
60 return -1
61 }
62
63 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
64 untested completion.exp
65 return -1
66 }
67
68 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
69 untested completion.exp
70 return -1
71 }
72
73 if [get_compiler_info] {
74 return -1
75 }
76
77 gdb_exit
78
79 gdb_start
80 gdb_reinitialize_dir $srcdir/$subdir
81 gdb_load ${binfile}
82
83 if ![runto_main] then {
84 perror "tests suppressed"
85 }
86
87 set oldtimeout1 $timeout
88 set timeout 30
89
90 set test "complete 'hfgfh'"
91 send_gdb "hfgfh\t"
92 gdb_test_multiple "" "$test" {
93 -re "^hfgfh\\\x07$" {
94 send_gdb "\n"
95 gdb_test_multiple "" $test {
96 -re "Undefined command: \"hfgfh\"\\. Try \"help\"\\..*$gdb_prompt $" {
97 pass "$test"
98 }
99 }
100 }
101 }
102
103 #exp_internal 0
104
105 set test "complete 'show output'"
106 send_gdb "show output\t"
107 gdb_test_multiple "" "$test" {
108 -re "^show output-radix $" {
109 send_gdb "\n"
110 gdb_test_multiple "" "$test" {
111 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
112 pass "$test"
113 }
114 }
115 }
116 }
117
118 set test "complete 'show output-'"
119 send_gdb "show output-\t"
120 gdb_test_multiple "" "$test" {
121 -re "^show output-radix $" {
122 send_gdb "\n"
123 gdb_test_multiple "" "$test" {
124 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
125 pass "$test"
126 }
127 }
128 }
129 }
130
131 set test "complete 'p'"
132 send_gdb "p\t"
133 gdb_test_multiple "" "$test" {
134 -re "^p\\\x07$" {
135 send_gdb "\n"
136 gdb_test_multiple "" "$test" {
137 -re "The history is empty\\..*$gdb_prompt $" {
138 pass "$test"
139 }
140 }
141 }
142 }
143
144 set test "complete 'p '"
145 send_gdb "p \t"
146 gdb_test_multiple "" "$test" {
147 -re "^p \\\x07$" {
148 send_gdb "\n"
149 gdb_test_multiple "" "$test" {
150 -re "The history is empty\\..*$gdb_prompt $" {
151 pass "$test"
152 }
153 }
154 }
155 }
156
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$" {
161 send_gdb "\n"
162 gdb_test_multiple "" "$test" {
163 -re "Ambiguous info command \"t foo\": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
164 pass "$test"
165 }
166 }
167 }
168 }
169
170 set test "complete 'info t'"
171 send_gdb "info t\t"
172 gdb_test_multiple "" "$test" {
173 -re "^info t\\\x07$" {
174 send_gdb "\n"
175 gdb_test_multiple "" "$test" {
176 -re "Ambiguous info command \"t\": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
177 pass "$test"
178 }
179 }
180 }
181 }
182
183 set test "complete 'info t '"
184 send_gdb "info t \t"
185 gdb_test_multiple "" "$test" {
186 -re "^info t \\\x07$" {
187 send_gdb "\n"
188 gdb_test_multiple "" "$test" {
189 -re "Ambiguous info command \"t \": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
190 pass "$test"
191 }
192 }
193 }
194 }
195
196 set test "complete 'info asdfgh'"
197 send_gdb "info asdfgh\t"
198 gdb_test_multiple "" "$test" {
199 -re "^info asdfgh\\\x07$" {
200 send_gdb "\n"
201 gdb_test_multiple "" "$test" {
202 -re "Undefined info command: \"asdfgh\". Try \"help info\"\\..*$gdb_prompt $" {
203 pass "$test"
204 }
205 }
206 }
207 }
208
209 set test "complete 'info asdfgh '"
210 send_gdb "info asdfgh \t"
211 gdb_test_multiple "" "$test" {
212 -re "^info asdfgh \\\x07$" {
213 send_gdb "\n"
214 gdb_test_multiple "" "$test" {
215 -re "Undefined info command: \"asdfgh \". Try \"help info\"\\..*$gdb_prompt $" {
216 pass "$test"
217 }
218 }
219 }
220 }
221
222 set test "complete 'info'"
223 send_gdb "info\t"
224 gdb_test_multiple "" "$test" {
225 -re "^info $" {
226 send_gdb "\n"
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 $" {
229 pass "$test"
230 }
231 }
232 }
233 }
234
235 set test "complete 'info '"
236 send_gdb "info \t"
237 gdb_test_multiple "" "$test" {
238 -re "^info \\\x07$" {
239 send_gdb "\n"
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 $" {
242 pass "$test"
243 }
244 }
245 }
246 }
247
248 set test "complete (2) 'info '"
249 send_gdb "info \t"
250 gdb_test_multiple "" "$test" {
251 -re "^info \\\x07$" {
252 send_gdb "\t"
253 gdb_test_multiple "" "$test" {
254 -re "address.*types.*$gdb_prompt " {
255 send_gdb "\n"
256 gdb_test_multiple "" "$test" {
257 -re "\"info\".*unambiguous\\..*$gdb_prompt $" {
258 pass "$test"
259 }
260 }
261 }
262 }
263 }
264 }
265
266 set test "complete 'help info wat'"
267 send_gdb "help info wat\t"
268 gdb_test_multiple "" "$test" {
269 -re "^help info watchpoints $" {
270 send_gdb "\n"
271 gdb_test_multiple "" "$test" {
272 -re "Status of specified watchpoints.*\r\n.*$gdb_prompt $" {
273 pass "$test"
274 }
275 }
276 }
277 -re "^help info wat\\\x07$" {
278 fail "$test"
279 }
280 }
281
282 set test "complete 'p \"break1'"
283 send_gdb "p \"break1\t"
284 gdb_test_multiple "" "$test" {
285 -re "^p \"break1\\\x07$" {
286 send_gdb "\n"
287 gdb_test_multiple "" "$test" {}
288 }
289 -re "^p \"break1\\.c\"$" {
290 send_gdb "\n"
291 gdb_test_multiple "" "$test" {
292 -re "$gdb_prompt $" {
293 pass "$test"
294 }
295 }
296 }
297 }
298
299 setup_xfail "*-*-*"
300 set test "complete 'p \"break1.'"
301 send_gdb "p \"break1.\t"
302 gdb_test_multiple "" "$test" {
303 -re "^p \"break1\\.\\\x07$" {
304 send_gdb "\n"
305 gdb_test_multiple "" "$test" {}
306 }
307 -re "^p \"break1\\.c\"$" {
308 send_gdb "\n"
309 gdb_test_multiple "" "$test" {
310 -re "$gdb_prompt $" {
311 pass "$test"
312 }
313 }
314 }
315 -re "^p \"break1\\..*$" {
316 send_gdb "\n"
317 gdb_test_multiple "" "$test" {}
318 }
319 }
320
321 set test "complete 'p 'arg'"
322 send_gdb "p 'arg\t"
323 gdb_test_multiple "" "$test" {
324 -re "^p 'arg\\\x07$" {
325 send_gdb "\n"
326 gdb_test_multiple "" "$test" {
327 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
328 pass "$test"
329 }
330 }
331 }
332 }
333
334 set test "complete (2) 'p 'arg'"
335 send_gdb "p 'arg\t"
336 gdb_test_multiple "" "$test" {
337 -re "^p 'arg\\\x07$" {
338 send_gdb "\t"
339 gdb_test_multiple "" "$test" {
340 -re "argv.*$gdb_prompt " {
341 send_gdb "\n"
342 gdb_test_multiple "" "$test" {
343 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
344 pass "$test"
345 }
346 }
347 }
348 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
349 send_gdb "n"
350 gdb_test_multiple "" "$test" {
351 -re "\\(gdb\\) p 'arg$" {
352 send_gdb "\n"
353 gdb_test_multiple "" "$test" {
354 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
355 pass "$test"
356 }
357 }
358 }
359 }
360 }
361 }
362 }
363 }
364
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 $" {
369 send_gdb "\n"
370 gdb_test_multiple "" "$test" {
371 -re "SIGQUIT.*Quit.*$gdb_prompt $" {
372 pass "$test"
373 }
374 }
375 }
376 }
377
378 set test "complete 'handle keyword'"
379 send_gdb "handle nos\t"
380 gdb_test_multiple "" "$test" {
381 -re "^handle nostop $" {
382 send_gdb "\n"
383 gdb_test_multiple "" "$test" {
384 -re "$gdb_prompt $" {
385 pass "$test"
386 }
387 }
388 }
389 }
390
391 set test "complete help aliases"
392 send_gdb "help user-define\t"
393 gdb_test_multiple "" "$test" {
394 -re "^help user-defined $" {
395 send_gdb "\n"
396 gdb_test_multiple "" "$test" {
397 -re "$gdb_prompt $" {
398 pass "$test"
399 }
400 }
401 }
402 }
403
404
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
412 # the given name.
413 #
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.
418 #
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 ...''.
423 #
424 # So, I'm hoping that there is no system with a static library variable named
425 # `no_var_by_this_name'.
426
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$" {
431 send_gdb "\n"
432 gdb_test_multiple "" "$test" {
433 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
434 pass "$test"
435 }
436 }
437 }
438 }
439
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$" {
444 send_gdb "\t"
445 gdb_test_multiple "" "$test" {
446 -re "argv.*$gdb_prompt " {
447 send_gdb "\n"
448 gdb_test_multiple "" "$test" {
449 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
450 pass "$test"
451 }
452 }
453 }
454 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
455 send_gdb "n\n"
456
457 # Eat the prompt
458 gdb_expect {
459 -re "$gdb_prompt " {
460 pass "$test (eat prompt)"
461 }
462 timeout {
463 fail "(timeout) $test (eat prompt)"
464 }
465 }
466
467 gdb_test_multiple "" "$test" {
468 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
469 pass "$test"
470 }
471 }
472 }
473 }
474 }
475 }
476
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$" {
481 send_gdb "\t"
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\\)$" {
484 send_gdb "n\n"
485
486 # Eat the prompt
487 gdb_expect {
488 -re "$gdb_prompt " {
489 pass "$test (eat prompt)"
490 }
491 timeout {
492 fail "(timeout) $test (eat prompt)"
493 }
494 }
495
496 gdb_test_multiple "" "$test" {
497 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
498 pass "$test"
499 }
500 }
501 }
502 -re "argv.*$gdb_prompt $" {
503 send_gdb "\n"
504 gdb_test_multiple "" "$test" {
505 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
506 pass "$test"
507 }
508 }
509 }
510 }
511 }
512 }
513
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 $" {
518 send_gdb "\n"
519 gdb_test_multiple "" "$test" {
520 -re " = 0.*$gdb_prompt $" {
521 pass "$test"
522 }
523 }
524 }
525 }
526
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 $" {
531 send_gdb "\n"
532 gdb_test_multiple "" "$test" {
533 -re " = 0.*$gdb_prompt $" {
534 pass "$test"
535 }
536 }
537 }
538 }
539
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 $" {
544 send_gdb "\n"
545 gdb_test_multiple "" "$test" {
546 -re " = .*0x\[0-9a-fA-F\]*.*$gdb_prompt $" {
547 pass "$test"
548 }
549 }
550 }
551 }
552
553 gdb_test "complete p &values\[0\]->z" \
554 "p &values.0.->z_field" \
555 "completion of field in anonymous union"
556
557 gdb_test "complete ptype &values\[0\]->z" \
558 "ptype &values.0.->z_field" \
559 "ptype completion of field in anonymous union"
560
561 gdb_test "complete whatis &values\[0\]->z" \
562 "whatis &values.0.->z_field" \
563 "whatis completion of field in anonymous union"
564
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
570 # recognize.
571 #
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'.
577 #
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.
582 #
583 # So, we avoid long lines. We `cd' to ${objdir} first, and then do
584 # the completion relative to the current directory.
585
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.
588 set mydir [pwd]
589 cd ${srcdir}
590 set fullsrcdir [pwd]
591 cd ${mydir}
592
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.
596
597 gdb_test "cd ${fullsrcdir}" \
598 "Working directory [string_to_regexp ${fullsrcdir}].*" \
599 "cd to \${srcdir}"
600
601
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}]
605 set uniquesu subdi
606 set uniquesub ${uniquesu}r
607 set escapeuniquesub [string_to_regexp ${uniquesub}]
608 send_gdb "dir ${uniquedir}\t"
609 gdb_expect {
610 -re "${escapeduniquedir}/" {
611 pass "directory completion"
612 send_gdb "${uniquesu}\t"
613 }
614 -re "${escapeduniquedir} $" {
615 fail "directory completion (old gdb bug)"
616 send_gdb "\b/${uniquesu}\t"
617 }
618 default {
619 fail "directory completion (timeout)"
620 send_gdb "\ndir ${uniquedir}/${uniquesu}\t"
621 }
622 }
623
624 gdb_expect {
625 -re "${escapeuniquesub}/$" {
626 pass "directory completion 2"
627 }
628 timeout {
629 fail "directory completion 2"
630 }
631 }
632
633 # Empty COMMAND sends no newline while " " sends the newline we need.
634 gdb_test " " "Source directories searched: .*" "Glob remaining of directory test"
635
636 gdb_test "complete file ./gdb.base/compl" \
637 "file ./gdb.base/completion\\.exp.*" \
638 "complete-command 'file ./gdb.base/compl'"
639
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 $" {
644 send_gdb "\n"
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\\) $" {
648 send_gdb "n\n"
649 exp_continue
650 }
651 -re "$gdb_prompt $" {
652 pass "$test"
653 }
654 }
655 }
656 }
657
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$" {
662 send_gdb "\t\t"
663 gdb_test_multiple "" "$test" {
664 -re "marker1.*$gdb_prompt " {
665 send_gdb "\n"
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 $" {
668 pass "$test"
669 }
670 }
671 }
672 }
673 }
674 }
675
676
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 " {
681 send_gdb "\n"
682 gdb_test_multiple "" "$test" {
683 -re "Requires an argument.*child.*parent.*$gdb_prompt $" {
684 pass "$test"
685 }
686 -re "Ambiguous item \"\"\\..*$gdb_prompt $" {
687 pass "$test"
688 }
689 }
690 }
691 }
692
693 gdb_test_no_output "complete print values\[0\].x." \
694 "field completion with invalid field"
695
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"
700
701
702 #
703 # Tag name completion.
704 #
705
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"
709
710
711 gdb_test "complete set gnutarget aut" "set gnutarget auto"
712
713
714 gdb_test "complete set cp-abi aut" "set cp-abi auto"
715
716 # Restore globals modified in this test...
717 set timeout $oldtimeout1
718
719 return 0