Various spelling fixes.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / completion.exp
1 # Copyright 1998, 1999, 2002, 2003, 2004, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, 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 if $tracelevel then {
50 strace $tracelevel
51 }
52
53
54 global usestubs
55
56 #
57 # test running programs
58 #
59
60 set testfile "break"
61 set srcfile ${testfile}.c
62 set srcfile1 ${testfile}1.c
63 set binfile ${objdir}/${subdir}/${testfile}
64
65 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
66 untested completion.exp
67 return -1
68 }
69
70 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
71 untested completion.exp
72 return -1
73 }
74
75 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
76 untested completion.exp
77 return -1
78 }
79
80 if [get_compiler_info ${binfile}] {
81 return -1;
82 }
83
84 gdb_exit
85
86 gdb_start
87 gdb_reinitialize_dir $srcdir/$subdir
88 gdb_load ${binfile}
89
90 if ![runto_main] then {
91 perror "tests suppressed"
92 }
93
94 set oldtimeout1 $timeout
95 set timeout 30
96
97 set test "complete 'hfgfh'"
98 send_gdb "hfgfh\t"
99 gdb_test_multiple "" "$test" {
100 -re "^hfgfh\\\x07$" {
101 send_gdb "\n"
102 gdb_test_multiple "" $test {
103 -re "Undefined command: \"hfgfh\"\\. Try \"help\"\\..*$gdb_prompt $" {
104 pass "$test"
105 }
106 }
107 }
108 }
109
110 #exp_internal 0
111
112 set test "complete 'show output'"
113 send_gdb "show output\t"
114 gdb_test_multiple "" "$test" {
115 -re "^show output-radix $" {
116 send_gdb "\n"
117 gdb_test_multiple "" "$test" {
118 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
119 pass "$test"
120 }
121 }
122 }
123 }
124
125 set test "complete 'show output-'"
126 send_gdb "show output-\t"
127 gdb_test_multiple "" "$test" {
128 -re "^show output-radix $" {
129 send_gdb "\n"
130 gdb_test_multiple "" "$test" {
131 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $" {
132 pass "$test"
133 }
134 }
135 }
136 }
137
138 set test "complete 'p'"
139 send_gdb "p\t"
140 gdb_test_multiple "" "$test" {
141 -re "^p\\\x07$" {
142 send_gdb "\n"
143 gdb_test_multiple "" "$test" {
144 -re "The history is empty\\..*$gdb_prompt $" {
145 pass "$test"
146 }
147 }
148 }
149 }
150
151 set test "complete 'p '"
152 send_gdb "p \t"
153 gdb_test_multiple "" "$test" {
154 -re "^p \\\x07$" {
155 send_gdb "\n"
156 gdb_test_multiple "" "$test" {
157 -re "The history is empty\\..*$gdb_prompt $" {
158 pass "$test"
159 }
160 }
161 }
162 }
163
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$" {
168 send_gdb "\n"
169 gdb_test_multiple "" "$test" {
170 -re "Ambiguous info command \"t foo\": target, tasks, terminal, threads, tp, tracepoints, tvariables, types\\..*$gdb_prompt $" {
171 pass "$test"
172 }
173 }
174 }
175 }
176
177 set test "complete 'info t'"
178 send_gdb "info t\t"
179 gdb_test_multiple "" "$test" {
180 -re "^info t\\\x07$" {
181 send_gdb "\n"
182 gdb_test_multiple "" "$test" {
183 -re "Ambiguous info command \"t\": target, tasks, terminal, threads, tp, tracepoints, tvariables, types\\..*$gdb_prompt $" {
184 pass "$test"
185 }
186 }
187 }
188 }
189
190 set test "complete 'info t '"
191 send_gdb "info t \t"
192 gdb_test_multiple "" "$test" {
193 -re "^info t \\\x07$" {
194 send_gdb "\n"
195 gdb_test_multiple "" "$test" {
196 -re "Ambiguous info command \"t \": target, tasks, terminal, threads, tp, tracepoints, tvariables, types\\..*$gdb_prompt $" {
197 pass "$test"
198 }
199 }
200 }
201 }
202
203 set test "complete 'info asdfgh'"
204 send_gdb "info asdfgh\t"
205 gdb_test_multiple "" "$test" {
206 -re "^info asdfgh\\\x07$" {
207 send_gdb "\n"
208 gdb_test_multiple "" "$test" {
209 -re "Undefined info command: \"asdfgh\". Try \"help info\"\\..*$gdb_prompt $" {
210 pass "$test"
211 }
212 }
213 }
214 }
215
216 set test "complete 'info asdfgh '"
217 send_gdb "info asdfgh \t"
218 gdb_test_multiple "" "$test" {
219 -re "^info asdfgh \\\x07$" {
220 send_gdb "\n"
221 gdb_test_multiple "" "$test" {
222 -re "Undefined info command: \"asdfgh \". Try \"help info\"\\..*$gdb_prompt $" {
223 pass "$test"
224 }
225 }
226 }
227 }
228
229 set test "complete 'info'"
230 send_gdb "info\t"
231 gdb_test_multiple "" "$test" {
232 -re "^info $" {
233 send_gdb "\n"
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 $" {
236 pass "$test"
237 }
238 }
239 }
240 }
241
242 set test "complete 'info '"
243 send_gdb "info \t"
244 gdb_test_multiple "" "$test" {
245 -re "^info \\\x07$" {
246 send_gdb "\n"
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 $" {
249 pass "$test"
250 }
251 }
252 }
253 }
254
255 set test "complete (2) 'info '"
256 send_gdb "info \t"
257 gdb_test_multiple "" "$test" {
258 -re "^info \\\x07$" {
259 send_gdb "\t"
260 gdb_test_multiple "" "$test" {
261 -re "address.*types.*$gdb_prompt " {
262 send_gdb "\n"
263 gdb_test_multiple "" "$test" {
264 -re "\"info\".*unambiguous\\..*$gdb_prompt $" {
265 pass "$test"
266 }
267 }
268 }
269 }
270 }
271 }
272
273 set test "complete 'help info wat'"
274 send_gdb "help info wat\t"
275 gdb_test_multiple "" "$test" {
276 -re "^help info watchpoints $" {
277 send_gdb "\n"
278 gdb_test_multiple "" "$test" {
279 -re "Status of specified watchpoints.*\r\n.*$gdb_prompt $" {
280 pass "$test"
281 }
282 }
283 }
284 -re "^help info wat\\\x07$" {
285 fail "$test"
286 }
287 }
288
289 set test "complete 'p \"break1'"
290 send_gdb "p \"break1\t"
291 gdb_test_multiple "" "$test" {
292 -re "^p \"break1\\\x07$" {
293 send_gdb "\n"
294 gdb_test_multiple "" "$test" {}
295 }
296 -re "^p \"break1\\.c\"$" {
297 send_gdb "\n"
298 gdb_test_multiple "" "$test" {
299 -re "$gdb_prompt $" {
300 pass "$test"
301 }
302 }
303 }
304 }
305
306 setup_xfail "*-*-*"
307 set test "complete 'p \"break1.'"
308 send_gdb "p \"break1.\t"
309 gdb_test_multiple "" "$test" {
310 -re "^p \"break1\\.\\\x07$" {
311 send_gdb "\n"
312 gdb_test_multiple "" "$test" {}
313 }
314 -re "^p \"break1\\.c\"$" {
315 send_gdb "\n"
316 gdb_test_multiple "" "$test" {
317 -re "$gdb_prompt $" {
318 pass "$test"
319 }
320 }
321 }
322 -re "^p \"break1\\..*$" {
323 send_gdb "\n"
324 gdb_test_multiple "" "$test" {}
325 }
326 }
327
328 set test "complete 'p 'arg'"
329 send_gdb "p 'arg\t"
330 gdb_test_multiple "" "$test" {
331 -re "^p 'arg\\\x07$" {
332 send_gdb "\n"
333 gdb_test_multiple "" "$test" {
334 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
335 pass "$test"
336 }
337 }
338 }
339 }
340
341 set test "complete (2) 'p 'arg'"
342 send_gdb "p 'arg\t"
343 gdb_test_multiple "" "$test" {
344 -re "^p 'arg\\\x07$" {
345 send_gdb "\t"
346 gdb_test_multiple "" "$test" {
347 -re "argv.*$gdb_prompt " {
348 send_gdb "\n"
349 gdb_test_multiple "" "$test" {
350 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
351 pass "$test"
352 }
353 }
354 }
355 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
356 send_gdb "n"
357 gdb_test_multiple "" "$test" {
358 -re "\\(gdb\\) p 'arg$" {
359 send_gdb "\n"
360 gdb_test_multiple "" "$test" {
361 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
362 pass "$test"
363 }
364 }
365 }
366 }
367 }
368 }
369 }
370 }
371
372
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
380 # the given name.
381 #
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.
386 #
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 ...''.
391 #
392 # So, I'm hoping that there is no system with a static library variable named
393 # `no_var_by_this_name'.
394
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$" {
399 send_gdb "\n"
400 gdb_test_multiple "" "$test" {
401 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
402 pass "$test"
403 }
404 }
405 }
406 }
407
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$" {
412 send_gdb "\t"
413 gdb_test_multiple "" "$test" {
414 -re "argv.*$gdb_prompt " {
415 send_gdb "\n"
416 gdb_test_multiple "" "$test" {
417 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
418 pass "$test"
419 }
420 }
421 }
422 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
423 send_gdb "n\n"
424
425 # Eat the prompt
426 gdb_expect {
427 -re "$gdb_prompt " {
428 pass "$test (eat prompt)"
429 }
430 timeout {
431 fail "(timeout) $test (eat prompt)"
432 }
433 }
434
435 gdb_test_multiple "" "$test" {
436 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
437 pass "$test"
438 }
439 }
440 }
441 }
442 }
443 }
444
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$" {
449 send_gdb "\t"
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\\)$" {
452 send_gdb "n\n"
453
454 # Eat the prompt
455 gdb_expect {
456 -re "$gdb_prompt " {
457 pass "$test (eat prompt)"
458 }
459 timeout {
460 fail "(timeout) $test (eat prompt)"
461 }
462 }
463
464 gdb_test_multiple "" "$test" {
465 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
466 pass "$test"
467 }
468 }
469 }
470 -re "argv.*$gdb_prompt $" {
471 send_gdb "\n"
472 gdb_test_multiple "" "$test" {
473 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
474 pass "$test"
475 }
476 }
477 }
478 }
479 }
480 }
481
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 $" {
486 send_gdb "\n"
487 gdb_test_multiple "" "$test" {
488 -re " = 0.*$gdb_prompt $" {
489 pass "$test"
490 }
491 }
492 }
493 }
494
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 $" {
499 send_gdb "\n"
500 gdb_test_multiple "" "$test" {
501 -re " = 0.*$gdb_prompt $" {
502 pass "$test"
503 }
504 }
505 }
506 }
507
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 $" {
512 send_gdb "\n"
513 gdb_test_multiple "" "$test" {
514 -re " = .*0x\[0-9a-fA-F\]*.*$gdb_prompt $" {
515 pass "$test"
516 }
517 }
518 }
519 }
520
521 gdb_test "complete p &values\[0\]->z" \
522 "p &values.0.->z_field" \
523 "completion of field in anonymous union"
524
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
530 # recognize.
531 #
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'.
537 #
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.
542 #
543 # So, we avoid long lines. We `cd' to ${objdir} first, and then do
544 # the completion relative to the current directory.
545
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.
548 set mydir [pwd]
549 cd ${srcdir}
550 set fullsrcdir [pwd]
551 cd ${mydir}
552
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.
556
557 gdb_test "cd ${fullsrcdir}" \
558 "Working directory [string_to_regexp ${fullsrcdir}].*" \
559 "cd to \${srcdir}"
560
561
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}]
565 set uniquesu subdi
566 set uniquesub ${uniquesu}r
567 set escapeuniquesub [string_to_regexp ${uniquesub}]
568 send_gdb "dir ${uniquedir}\t"
569 gdb_expect {
570 -re "${escapeduniquedir}/" {
571 pass "directory completion"
572 send_gdb "${uniquesu}\t"
573 }
574 -re "${escapeduniquedir} $" {
575 fail "directory completion (old gdb bug)"
576 send_gdb "\b/${uniquesu}\t"
577 }
578 default {
579 fail "directory completion (timeout)"
580 send_gdb "\ndir ${uniquedir}/${uniquesu}\t"
581 }
582 }
583
584 gdb_expect {
585 -re "${escapeuniquesub}/$" {
586 pass "directory completion 2"
587 }
588 timeout {
589 fail "directory completion 2"
590 }
591 }
592
593 # Empty COMMAND sends no newline while " " sends the newline we need.
594 gdb_test " " "Source directories searched: .*" "Glob remaining of directory test"
595
596 gdb_test "complete file ./gdb.base/compl" \
597 "file ./gdb.base/completion\\.exp.*" \
598 "complete-command 'file ./gdb.base/compl'"
599
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 $" {
604 send_gdb "\n"
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\\) $" {
608 send_gdb "n\n"
609 exp_continue
610 }
611 -re "$gdb_prompt $" {
612 pass "$test"
613 }
614 }
615 }
616 }
617
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$" {
622 send_gdb "\t\t"
623 gdb_test_multiple "" "$test" {
624 -re "marker1.*$gdb_prompt " {
625 send_gdb "\n"
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 $" {
628 pass "$test"
629 }
630 }
631 }
632 }
633 }
634 }
635
636
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 " {
641 send_gdb "\n"
642 gdb_test_multiple "" "$test" {
643 -re "Requires an argument.*child.*parent.*$gdb_prompt $" {
644 pass "$test"
645 }
646 -re "Ambiguous item \"\"\\..*$gdb_prompt $" {
647 pass "$test"
648 }
649 }
650 }
651 }
652
653 gdb_test_no_output "complete print values\[0\].x." \
654 "field completion with invalid field"
655
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"
660
661
662 # Restore globals modified in this test...
663 set timeout $oldtimeout1
664
665 return 0
This page took 0.044361 seconds and 4 git commands to generate.