]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/completion.exp
* NEWS: Update.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / completion.exp
1 # Copyright 1998-1999, 2002-2004, 2007-2012 Free Software Foundation,
2 # Inc.
3
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.
8 #
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.
13 #
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/>.
16
17 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
18
19 # This file is part of the gdb testsuite.
20
21 #
22 # tests for command completion
23 #
24 # Here are some useful test cases for completion.
25 # They should be tested with both M-? and TAB.
26 #
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
36 # "info" " "
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)
46 #
47
48
49
50 #
51 # test running programs
52 #
53
54 set testfile "break"
55 set srcfile ${testfile}.c
56 set srcfile1 ${testfile}1.c
57 set binfile ${objdir}/${subdir}/${testfile}
58
59 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
60 untested completion.exp
61 return -1
62 }
63
64 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
65 untested completion.exp
66 return -1
67 }
68
69 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
70 untested completion.exp
71 return -1
72 }
73
74 if [get_compiler_info] {
75 return -1;
76 }
77
78 gdb_exit
79
80 gdb_start
81 gdb_reinitialize_dir $srcdir/$subdir
82 gdb_load ${binfile}
83
84 if ![runto_main] then {
85 perror "tests suppressed"
86 }
87
88 set oldtimeout1 $timeout
89 set timeout 30
90
91 set test "complete 'hfgfh'"
92 send_gdb "hfgfh\t"
93 gdb_test_multiple "" "$test" {
94 -re "^hfgfh\\\x07$" {
95 send_gdb "\n"
96 gdb_test_multiple "" $test {
97 -re "Undefined command: \"hfgfh\"\\. Try \"help\"\\..*$gdb_prompt $" {
98 pass "$test"
99 }
100 }
101 }
102 }
103
104 #exp_internal 0
105
106 set test "complete 'show output'"
107 send_gdb "show output\t"
108 gdb_test_multiple "" "$test" {
109 -re "^show output-radix $" {
110 send_gdb "\n"
111 gdb_test_multiple "" "$test" {
112 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
113 pass "$test"
114 }
115 }
116 }
117 }
118
119 set test "complete 'show output-'"
120 send_gdb "show output-\t"
121 gdb_test_multiple "" "$test" {
122 -re "^show output-radix $" {
123 send_gdb "\n"
124 gdb_test_multiple "" "$test" {
125 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
126 pass "$test"
127 }
128 }
129 }
130 }
131
132 set test "complete 'p'"
133 send_gdb "p\t"
134 gdb_test_multiple "" "$test" {
135 -re "^p\\\x07$" {
136 send_gdb "\n"
137 gdb_test_multiple "" "$test" {
138 -re "The history is empty\\..*$gdb_prompt $" {
139 pass "$test"
140 }
141 }
142 }
143 }
144
145 set test "complete 'p '"
146 send_gdb "p \t"
147 gdb_test_multiple "" "$test" {
148 -re "^p \\\x07$" {
149 send_gdb "\n"
150 gdb_test_multiple "" "$test" {
151 -re "The history is empty\\..*$gdb_prompt $" {
152 pass "$test"
153 }
154 }
155 }
156 }
157
158 set test "complete 'info t foo'"
159 send_gdb "info t foo\t"
160 gdb_test_multiple "" "$test" {
161 -re "^info t foo\\\x07$" {
162 send_gdb "\n"
163 gdb_test_multiple "" "$test" {
164 -re "Ambiguous info command \"t foo\": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
165 pass "$test"
166 }
167 }
168 }
169 }
170
171 set test "complete 'info t'"
172 send_gdb "info t\t"
173 gdb_test_multiple "" "$test" {
174 -re "^info t\\\x07$" {
175 send_gdb "\n"
176 gdb_test_multiple "" "$test" {
177 -re "Ambiguous info command \"t\": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
178 pass "$test"
179 }
180 }
181 }
182 }
183
184 set test "complete 'info t '"
185 send_gdb "info t \t"
186 gdb_test_multiple "" "$test" {
187 -re "^info t \\\x07$" {
188 send_gdb "\n"
189 gdb_test_multiple "" "$test" {
190 -re "Ambiguous info command \"t \": target, tasks, terminal, threads, tp, tracepoints, tvariables, (type-printers, )?types\\..*$gdb_prompt $" {
191 pass "$test"
192 }
193 }
194 }
195 }
196
197 set test "complete 'info asdfgh'"
198 send_gdb "info asdfgh\t"
199 gdb_test_multiple "" "$test" {
200 -re "^info asdfgh\\\x07$" {
201 send_gdb "\n"
202 gdb_test_multiple "" "$test" {
203 -re "Undefined info command: \"asdfgh\". Try \"help info\"\\..*$gdb_prompt $" {
204 pass "$test"
205 }
206 }
207 }
208 }
209
210 set test "complete 'info asdfgh '"
211 send_gdb "info asdfgh \t"
212 gdb_test_multiple "" "$test" {
213 -re "^info asdfgh \\\x07$" {
214 send_gdb "\n"
215 gdb_test_multiple "" "$test" {
216 -re "Undefined info command: \"asdfgh \". Try \"help info\"\\..*$gdb_prompt $" {
217 pass "$test"
218 }
219 }
220 }
221 }
222
223 set test "complete 'info'"
224 send_gdb "info\t"
225 gdb_test_multiple "" "$test" {
226 -re "^info $" {
227 send_gdb "\n"
228 gdb_test_multiple "" "$test" {
229 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands.*$gdb_prompt $" {
230 pass "$test"
231 }
232 }
233 }
234 }
235
236 set test "complete 'info '"
237 send_gdb "info \t"
238 gdb_test_multiple "" "$test" {
239 -re "^info \\\x07$" {
240 send_gdb "\n"
241 gdb_test_multiple "" "$test" {
242 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands:\r\n\r\n.*$gdb_prompt $" {
243 pass "$test"
244 }
245 }
246 }
247 }
248
249 set test "complete (2) 'info '"
250 send_gdb "info \t"
251 gdb_test_multiple "" "$test" {
252 -re "^info \\\x07$" {
253 send_gdb "\t"
254 gdb_test_multiple "" "$test" {
255 -re "address.*types.*$gdb_prompt " {
256 send_gdb "\n"
257 gdb_test_multiple "" "$test" {
258 -re "\"info\".*unambiguous\\..*$gdb_prompt $" {
259 pass "$test"
260 }
261 }
262 }
263 }
264 }
265 }
266
267 set test "complete 'help info wat'"
268 send_gdb "help info wat\t"
269 gdb_test_multiple "" "$test" {
270 -re "^help info watchpoints $" {
271 send_gdb "\n"
272 gdb_test_multiple "" "$test" {
273 -re "Status of specified watchpoints.*\r\n.*$gdb_prompt $" {
274 pass "$test"
275 }
276 }
277 }
278 -re "^help info wat\\\x07$" {
279 fail "$test"
280 }
281 }
282
283 set test "complete 'p \"break1'"
284 send_gdb "p \"break1\t"
285 gdb_test_multiple "" "$test" {
286 -re "^p \"break1\\\x07$" {
287 send_gdb "\n"
288 gdb_test_multiple "" "$test" {}
289 }
290 -re "^p \"break1\\.c\"$" {
291 send_gdb "\n"
292 gdb_test_multiple "" "$test" {
293 -re "$gdb_prompt $" {
294 pass "$test"
295 }
296 }
297 }
298 }
299
300 setup_xfail "*-*-*"
301 set test "complete 'p \"break1.'"
302 send_gdb "p \"break1.\t"
303 gdb_test_multiple "" "$test" {
304 -re "^p \"break1\\.\\\x07$" {
305 send_gdb "\n"
306 gdb_test_multiple "" "$test" {}
307 }
308 -re "^p \"break1\\.c\"$" {
309 send_gdb "\n"
310 gdb_test_multiple "" "$test" {
311 -re "$gdb_prompt $" {
312 pass "$test"
313 }
314 }
315 }
316 -re "^p \"break1\\..*$" {
317 send_gdb "\n"
318 gdb_test_multiple "" "$test" {}
319 }
320 }
321
322 set test "complete 'p 'arg'"
323 send_gdb "p 'arg\t"
324 gdb_test_multiple "" "$test" {
325 -re "^p 'arg\\\x07$" {
326 send_gdb "\n"
327 gdb_test_multiple "" "$test" {
328 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
329 pass "$test"
330 }
331 }
332 }
333 }
334
335 set test "complete (2) 'p 'arg'"
336 send_gdb "p 'arg\t"
337 gdb_test_multiple "" "$test" {
338 -re "^p 'arg\\\x07$" {
339 send_gdb "\t"
340 gdb_test_multiple "" "$test" {
341 -re "argv.*$gdb_prompt " {
342 send_gdb "\n"
343 gdb_test_multiple "" "$test" {
344 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
345 pass "$test"
346 }
347 }
348 }
349 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
350 send_gdb "n"
351 gdb_test_multiple "" "$test" {
352 -re "\\(gdb\\) p 'arg$" {
353 send_gdb "\n"
354 gdb_test_multiple "" "$test" {
355 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
356 pass "$test"
357 }
358 }
359 }
360 }
361 }
362 }
363 }
364 }
365
366 set test "complete 'handle signal'"
367 send_gdb "handle sigq\t"
368 gdb_test_multiple "" "$test" {
369 -re "^handle sigq\b\b\b\bSIGQUIT $" {
370 send_gdb "\n"
371 gdb_test_multiple "" "$test" {
372 -re "SIGQUIT.*Quit.*$gdb_prompt $" {
373 pass "$test"
374 }
375 }
376 }
377 }
378
379 set test "complete 'handle keyword'"
380 send_gdb "handle nos\t"
381 gdb_test_multiple "" "$test" {
382 -re "^handle nostop $" {
383 send_gdb "\n"
384 gdb_test_multiple "" "$test" {
385 -re "$gdb_prompt $" {
386 pass "$test"
387 }
388 }
389 }
390 }
391
392
393 # These tests used to try completing the shorter "p b-a".
394 # Unfortunately, on some systems, there are .o files in system
395 # libraries which declare static variables named `b'. Of course,
396 # those variables aren't really in scope, as far as the compiler is
397 # concerned. But GDB deliberately tries to be more liberal: if you
398 # enter an identifier that doesn't have any binding in scope, GDB will
399 # search all the program's compilation units for a static variable of
400 # the given name.
401 #
402 # This behavior can help avoid a lot of pedantry, so it's usually a
403 # good thing. But in this test case, it causes GDB to print the value
404 # of some random variable, instead of giving us the "No symbol..."
405 # error we were expecting.
406 #
407 # For example, on S/390 linux, the file s_atan.c in libm.a declares a
408 # `b', which is a structure containing an int and a float, so GDB says
409 # ``Argument to arithmetic operation not a number or boolean'' instead
410 # of ``No symbol ...''.
411 #
412 # So, I'm hoping that there is no system with a static library variable named
413 # `no_var_by_this_name'.
414
415 set test "complete 'p no_var_named_this-arg'"
416 send_gdb "p no_var_named_this-arg\t"
417 gdb_test_multiple "" "$test" {
418 -re "^p no_var_named_this-arg\\\x07$" {
419 send_gdb "\n"
420 gdb_test_multiple "" "$test" {
421 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
422 pass "$test"
423 }
424 }
425 }
426 }
427
428 set test "complete (2) 'p no_var_named_this-arg'"
429 send_gdb "p no_var_named_this-arg\t"
430 gdb_test_multiple "" "$test" {
431 -re "^p no_var_named_this-arg\\\x07$" {
432 send_gdb "\t"
433 gdb_test_multiple "" "$test" {
434 -re "argv.*$gdb_prompt " {
435 send_gdb "\n"
436 gdb_test_multiple "" "$test" {
437 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
438 pass "$test"
439 }
440 }
441 }
442 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
443 send_gdb "n\n"
444
445 # Eat the prompt
446 gdb_expect {
447 -re "$gdb_prompt " {
448 pass "$test (eat prompt)"
449 }
450 timeout {
451 fail "(timeout) $test (eat prompt)"
452 }
453 }
454
455 gdb_test_multiple "" "$test" {
456 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
457 pass "$test"
458 }
459 }
460 }
461 }
462 }
463 }
464
465 set test "complete (2) 'p no_var_named_this-'"
466 send_gdb "p no_var_named_this-\t"
467 gdb_test_multiple "" "$test" {
468 -re "^p no_var_named_this-\\\x07$" {
469 send_gdb "\t"
470 gdb_test_multiple "" "$test" {
471 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
472 send_gdb "n\n"
473
474 # Eat the prompt
475 gdb_expect {
476 -re "$gdb_prompt " {
477 pass "$test (eat prompt)"
478 }
479 timeout {
480 fail "(timeout) $test (eat prompt)"
481 }
482 }
483
484 gdb_test_multiple "" "$test" {
485 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
486 pass "$test"
487 }
488 }
489 }
490 -re "argv.*$gdb_prompt $" {
491 send_gdb "\n"
492 gdb_test_multiple "" "$test" {
493 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
494 pass "$test"
495 }
496 }
497 }
498 }
499 }
500 }
501
502 set test "complete 'p values\[0\].a'"
503 send_gdb "p values\[0\].a\t"
504 gdb_test_multiple "" "$test" {
505 -re "^p values.0..a_field $" {
506 send_gdb "\n"
507 gdb_test_multiple "" "$test" {
508 -re " = 0.*$gdb_prompt $" {
509 pass "$test"
510 }
511 }
512 }
513 }
514
515 set test "complete 'p values\[0\] . a'"
516 send_gdb "p values\[0\] . a\t"
517 gdb_test_multiple "" "$test" {
518 -re "^p values.0. . a_field $" {
519 send_gdb "\n"
520 gdb_test_multiple "" "$test" {
521 -re " = 0.*$gdb_prompt $" {
522 pass "$test"
523 }
524 }
525 }
526 }
527
528 set test "complete 'p &values\[0\] -> a'"
529 send_gdb "p &values\[0\] -> a\t"
530 gdb_test_multiple "" "$test" {
531 -re "^p &values.0. -> a_field $" {
532 send_gdb "\n"
533 gdb_test_multiple "" "$test" {
534 -re " = .*0x\[0-9a-fA-F\]*.*$gdb_prompt $" {
535 pass "$test"
536 }
537 }
538 }
539 }
540
541 gdb_test "complete p &values\[0\]->z" \
542 "p &values.0.->z_field" \
543 "completion of field in anonymous union"
544
545 # The following tests used to simply try to complete `${objdir}/file',
546 # and so on. The problem is that ${objdir} can be very long; the
547 # completed filename may be more than eighty characters wide. When
548 # this happens, readline tries to manage things, producing output that
549 # may make sense on the screen, but is rather hard for our script to
550 # recognize.
551 #
552 # In the case that motivated this change, the (gdb) prompt occupied
553 # the leftmost six columns, and `${objdir}/' was seventy-four
554 # characters long --- eighty in all. After printing the slash,
555 # readline emitted a space, a carriage return, and then `Makefile'
556 # (the tab character being received as input after `Make'.
557 #
558 # Basically, you have to let readline do whatever it's going to do to
559 # make the screen look right. If it happens to use a different
560 # strategy on Tuesdays to get the cursor in the right place, that's
561 # not something the testsuite should care about.
562 #
563 # So, we avoid long lines. We `cd' to ${objdir} first, and then do
564 # the completion relative to the current directory.
565
566 # ${srcdir} may be a relative path. We want to make sure we end up
567 # in the right directory - so make sure we know where it is.
568 set mydir [pwd]
569 cd ${srcdir}
570 set fullsrcdir [pwd]
571 cd ${mydir}
572
573 # If the directory name contains a '+' we must escape it, adding a backslash.
574 # If not, the test below will fail because it will interpret the '+' as a
575 # regexp operator. We use string_to_regexp for this purpose.
576
577 gdb_test "cd ${fullsrcdir}" \
578 "Working directory [string_to_regexp ${fullsrcdir}].*" \
579 "cd to \${srcdir}"
580
581
582 # GDB used to fail adding / on directories, on the first try only.
583 set uniquedir ../testsuite/gdb.base/comp-dir
584 set escapeduniquedir [string_to_regexp ${uniquedir}]
585 set uniquesu subdi
586 set uniquesub ${uniquesu}r
587 set escapeuniquesub [string_to_regexp ${uniquesub}]
588 send_gdb "dir ${uniquedir}\t"
589 gdb_expect {
590 -re "${escapeduniquedir}/" {
591 pass "directory completion"
592 send_gdb "${uniquesu}\t"
593 }
594 -re "${escapeduniquedir} $" {
595 fail "directory completion (old gdb bug)"
596 send_gdb "\b/${uniquesu}\t"
597 }
598 default {
599 fail "directory completion (timeout)"
600 send_gdb "\ndir ${uniquedir}/${uniquesu}\t"
601 }
602 }
603
604 gdb_expect {
605 -re "${escapeuniquesub}/$" {
606 pass "directory completion 2"
607 }
608 timeout {
609 fail "directory completion 2"
610 }
611 }
612
613 # Empty COMMAND sends no newline while " " sends the newline we need.
614 gdb_test " " "Source directories searched: .*" "Glob remaining of directory test"
615
616 gdb_test "complete file ./gdb.base/compl" \
617 "file ./gdb.base/completion\\.exp.*" \
618 "complete-command 'file ./gdb.base/compl'"
619
620 set test "complete 'file ./gdb.base/complet'"
621 send_gdb "file ./gdb.base/complet\t"
622 gdb_test_multiple "" "$test" {
623 -re "^file ./gdb.base/completion\\.exp $" {
624 send_gdb "\n"
625 # Ignore the exact error message.
626 gdb_test_multiple "" "complete 'file ./gdb.base/complet'" {
627 -re "\r\nA program is being debugged already\\.\[\r\n\]+Are you sure you want to change the file\\? \\(y or n\\) $" {
628 send_gdb "n\n"
629 exp_continue
630 }
631 -re "$gdb_prompt $" {
632 pass "$test"
633 }
634 }
635 }
636 }
637
638 set test "complete 'info func marke'"
639 send_gdb "info func marke\t"
640 gdb_test_multiple "" "$test" {
641 -re "^info func marke.*r$" {
642 send_gdb "\t\t"
643 gdb_test_multiple "" "$test" {
644 -re "marker1.*$gdb_prompt " {
645 send_gdb "\n"
646 gdb_test_multiple "" "$test" {
647 -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 $" {
648 pass "$test"
649 }
650 }
651 }
652 }
653 }
654 }
655
656
657 set test "complete 'set follow-fork-mode'"
658 send_gdb "set follow-fork-mode \t\t"
659 gdb_test_multiple "" "$test" {
660 -re "child.*parent.*$gdb_prompt " {
661 send_gdb "\n"
662 gdb_test_multiple "" "$test" {
663 -re "Requires an argument.*child.*parent.*$gdb_prompt $" {
664 pass "$test"
665 }
666 -re "Ambiguous item \"\"\\..*$gdb_prompt $" {
667 pass "$test"
668 }
669 }
670 }
671 }
672
673 gdb_test_no_output "complete print values\[0\].x." \
674 "field completion with invalid field"
675
676 # If there is a non-deprecated completion, it should be returned.
677 gdb_test "complete sav" "save" "test non-deprecated completion"
678 # If there is only a deprecated completion, then it should be returned.
679 gdb_test "complete save-t" "save-tracepoints" "test deprecated completion"
680
681
682 # Restore globals modified in this test...
683 set timeout $oldtimeout1
684
685 return 0