gdb/testsuite/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / completion.exp
1 # Copyright 1998, 1999, 2002, 2003, 2004, 2007, 2008, 2009, 2010
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 set prms_id 0
60 set bug_id 0
61
62 set testfile "break"
63 set srcfile ${testfile}.c
64 set srcfile1 ${testfile}1.c
65 set binfile ${objdir}/${subdir}/${testfile}
66
67 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}0.o" object {debug nowarnings}] != "" } {
68 untested completion.exp
69 return -1
70 }
71
72 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug nowarnings}] != "" } {
73 untested completion.exp
74 return -1
75 }
76
77 if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug nowarnings}] != "" } {
78 untested completion.exp
79 return -1
80 }
81
82 if [get_compiler_info ${binfile}] {
83 return -1;
84 }
85
86 gdb_exit
87
88 gdb_start
89 gdb_reinitialize_dir $srcdir/$subdir
90 gdb_load ${binfile}
91
92 if ![runto_main] then {
93 perror "tests suppressed"
94 }
95
96 set oldtimeout1 $timeout
97 set timeout 30
98
99
100 send_gdb "hfgfh\t"
101 sleep 1
102 gdb_expect {
103 -re "^hfgfh\\\x07$"\
104 { send_gdb "\n"
105 gdb_expect {
106 -re "Undefined command: \"hfgfh\"\\. Try \"help\"\\..*$gdb_prompt $"\
107 { pass "complete 'hfgfh'"}
108 -re ".*$gdb_prompt $" { fail "complete 'hfgfh'"}
109 timeout {fail "(timeout) complete 'hfgfh'"}
110 }
111 }
112 -re ".*$gdb_prompt $" { fail "complete 'hfgfh'" }
113 timeout { fail "(timeout) complete 'hfgfh'" }
114 }
115
116 #exp_internal 0
117
118 send_gdb "show output\t"
119 sleep 1
120 gdb_expect {
121 -re "^show output-radix $"\
122 { send_gdb "\n"
123 gdb_expect {
124 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
125 { pass "complete 'show output'"}
126 -re ".*$gdb_prompt $" { fail "complete 'show output'"}
127 timeout {fail "(timeout) complete 'show output'"}
128 }
129 }
130 -re "^show output$"\
131 { send_gdb "\n"
132 gdb_expect {
133 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
134 { fail "complete 'show output'"}
135 -re ".*$gdb_prompt $" { fail "complete 'show output'"}
136 timeout { fail "(timeout) complete 'show output'"}
137 }
138
139 }
140
141 -re ".*$gdb_prompt $" { fail "complete 'show output'" }
142 timeout { fail "(timeout) complete 'show output'" }
143 }
144
145
146 send_gdb "show output-\t"
147 sleep 1
148 gdb_expect {
149 -re "^show output-radix $"\
150 { send_gdb "\n"
151 gdb_expect {
152 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
153 { pass "complete 'show output-'"}
154 -re ".*$gdb_prompt $" { fail "complete 'show output-'"}
155 timeout {fail "(timeout) complete 'show output-'"}
156 }
157 }
158 -re "^show output-$"\
159 { send_gdb "\n"
160 gdb_expect {
161 -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
162 { fail "complete 'show output-'"}
163 -re ".*$gdb_prompt $" { fail "complete 'show output-'"}
164 timeout { fail "(timeout) complete 'show output-'"}
165 }
166
167 }
168
169 -re ".*$gdb_prompt $" { fail "complete 'show output-'" }
170 timeout { fail "(timeout) complete 'show output-'" }
171 }
172
173 send_gdb "p\t"
174 sleep 1
175 gdb_expect {
176 -re "^p\\\x07$"\
177 { send_gdb "\n"
178 sleep 1
179 gdb_expect {
180 -re "The history is empty\\..*$gdb_prompt $"\
181 { pass "complete 'p'"}
182 -re ".*$gdb_prompt $" { fail "complete 'p'"}
183 timeout {fail "(timeout) complete 'p' 2"}
184 }
185 }
186 -re ".*$gdb_prompt $" { fail "complete 'p'" }
187 timeout { fail "(timeout) complete 'p' 1" }
188 }
189
190 send_gdb "p \t"
191 sleep 3
192 gdb_expect {
193 -re "^p \\\x07$"\
194 { send_gdb "\n"
195 sleep 1
196 gdb_expect {
197 -re "The history is empty\\..*$gdb_prompt $"\
198 { pass "complete 'p '"}
199 -re ".*$gdb_prompt $" { fail "complete 'p '"}
200 timeout {fail "(timeout) complete 'p ' 1"}
201 }
202 }
203 -re ".*$gdb_prompt $" { fail "complete 'p '" }
204 timeout { fail "(timeout) complete 'p ' 2" }
205 }
206
207
208 send_gdb "info t foo\t"
209 sleep 1
210 gdb_expect {
211 -re "^info t foo\\\x07$"\
212 { send_gdb "\n"
213 gdb_expect {
214 -re "Ambiguous info command \"t foo\": target, tasks, terminal, threads, tp, tracepoints, tvariables, types\\..*$gdb_prompt $"\
215 { pass "complete 'info t foo'"}
216 -re ".*$gdb_prompt $" { fail "complete 'info t foo'"}
217 timeout {fail "(timeout) complete 'info t foo'"}
218 }
219 }
220 -re ".*$gdb_prompt $" { fail "complete 'info t foo'" }
221 timeout { fail "(timeout) complete 'info t foo'" }
222 }
223
224 send_gdb "info t\t"
225 sleep 1
226 gdb_expect {
227 -re "^info t\\\x07$"\
228 { send_gdb "\n"
229 gdb_expect {
230 -re "Ambiguous info command \"t\": target, tasks, terminal, threads, tp, tracepoints, tvariables, types\\..
231 *$gdb_prompt $"\
232 { pass "complete 'info t'"}
233 -re ".*$gdb_prompt $" { fail "complete 'info t'"}
234 timeout {fail "(timeout) complete 'info t'"}
235 }
236 }
237 -re ".*$gdb_prompt $" { fail "complete 'info t'" }
238 timeout { fail "(timeout) complete 'info t'" }
239 }
240
241
242 send_gdb "info t \t"
243 sleep 1
244 gdb_expect {
245 -re "^info t \\\x07$"\
246 { send_gdb "\n"
247 gdb_expect {
248 -re "Ambiguous info command \"t \": target, tasks, terminal, threads, tp, tracepoints, tvariables, types\\..
249 *$gdb_prompt $"\
250 { pass "complete 'info t '"}
251 -re ".*$gdb_prompt $" { fail "complete 'info t '"}
252 timeout {fail "(timeout) complete 'info t '"}
253 }
254 }
255 -re ".*$gdb_prompt $" { fail "complete 'info t '" }
256 timeout { fail "(timeout) complete 'info t '" }
257 }
258
259
260 send_gdb "info asdfgh\t"
261 sleep 1
262 gdb_expect {
263 -re "^info asdfgh\\\x07$"\
264 { send_gdb "\n"
265 gdb_expect {
266 -re "Undefined info command: \"asdfgh\". Try \"help info\"\\..
267 *$gdb_prompt $"\
268 { pass "complete 'info asdfgh'"}
269 -re ".*$gdb_prompt $" { fail "complete 'info asdfgh'"}
270 timeout {fail "(timeout) complete 'info asdfgh'"}
271 }
272 }
273 -re ".*$gdb_prompt $" { fail "complete 'info asdfgh'" }
274 timeout { fail "(timeout) complete 'info asdfgh'" }
275 }
276
277
278 send_gdb "info asdfgh \t"
279 sleep 1
280 gdb_expect {
281 -re "^info asdfgh \\\x07$"\
282 { send_gdb "\n"
283 gdb_expect {
284 -re "Undefined info command: \"asdfgh \". Try \"help info\"\\..
285 *$gdb_prompt $"\
286 { pass "complete 'info asdfgh '"}
287 -re ".*$gdb_prompt $" { fail "complete 'info asdfgh '"}
288 timeout {fail "(timeout) complete 'info asdfgh '"}
289 }
290 }
291 -re ".*$gdb_prompt $" { fail "complete 'info asdfgh '" }
292 timeout { fail "(timeout) complete 'info asdfgh '" }
293 }
294
295 send_gdb "info\t"
296 sleep 1
297 gdb_expect {
298 -re "^info $"\
299 { send_gdb "\n"
300 gdb_expect {
301 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands.*$gdb_prompt $"\
302 { pass "complete 'info'"}
303 -re ".*$gdb_prompt $" { fail "complete 'info'"}
304 timeout {fail "(timeout) complete 'info'"}
305 }
306 }
307 -re ".*$gdb_prompt $" { fail "complete 'info'" }
308 timeout { fail "(timeout) complete 'info'" }
309 }
310
311 send_gdb "info \t"
312 sleep 1
313 gdb_expect {
314 -re "^info \\\x07$"\
315 { send_gdb "\n"
316 gdb_expect {
317 -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands:\r\n\r\n.*$gdb_prompt $"\
318 { pass "complete 'info '"}
319 -re ".*$gdb_prompt $" { fail "complete 'info '"}
320 timeout {fail "(timeout) complete 'info '"}
321 }
322 }
323 -re ".*$gdb_prompt $" { fail "complete 'info '" }
324 timeout { fail "(timeout) complete 'info '" }
325 }
326
327
328 send_gdb "info \t"
329 sleep 1
330 gdb_expect {
331 -re "^info \\\x07$"\
332 { send_gdb "\t"
333 gdb_expect {
334 -re "address.*types.*$gdb_prompt info $"\
335 { send_gdb "\n"
336 gdb_expect {
337 -re "\"info\".*unambiguous\\..*$gdb_prompt $"\
338 { pass "complete (2) 'info '"}
339 -re ".*$gdb_prompt $" { fail "complete (2) 'info '"}
340 timeout {fail "(timeout) complete (2) 'info '"}
341 }
342 }
343 -re ".*$gdb_prompt $" { fail "complete (2) 'info '"}
344 timeout {fail "(timeout) complete (2) 'info '"}
345 }
346 }
347 -re ".*$gdb_prompt $" { fail "complete (2) 'info '" }
348 timeout { fail "(timeout) complete (2) 'info '" }
349 }
350
351
352 send_gdb "help info wat\t"
353 gdb_expect {
354 -re "^help info watchpoints $"\
355 { send_gdb "\n"
356 gdb_expect {
357 -re "Synonym for .*\r\n.*$gdb_prompt $"\
358 { pass "complete help info wat" }
359 -re ".*$gdb_prompt $" { fail "complete help info wat"}
360 timeout {fail "(timeout) complete help info wat"}
361 }
362 }
363 -re "^help info wat\\\x07$" { fail "complete (2) help info wat" }
364 -re ".*$gdb_prompt $" { fail "complete (3) help info wat" }
365 timeout { fail "(timeout) complete (3) help info wat" }
366 }
367
368
369 send_gdb "p \"break1\t"
370 sleep 1
371 gdb_expect {
372 -re "^p \"break1\\\x07$"\
373 { send_gdb "\n"
374 gdb_expect {
375 -re ".*$gdb_prompt $" { fail "complete 'p \"break1'"}
376 timeout {fail "(timeout) complete 'p \"break1'"}
377 }
378 }
379 -re "^p \"break1\\.c\"$"\
380 { send_gdb "\n"
381 gdb_expect {
382 -re ".*$gdb_prompt $" { pass "complete 'p \"break1'"}
383 timeout {fail "(timeout) complete 'p \"break1'"}
384 }
385 }
386 -re "^p \"break1.*$"
387 { send_gdb "\n"
388 gdb_expect {
389 -re ".*$gdb_prompt $" { fail "complete 'p \"break1'"}
390 timeout {fail "(timeout) complete 'p \"break1'"}
391 }
392 }
393 -re ".*$gdb_prompt $" { fail "complete 'p \"break1'" }
394 timeout { fail "(timeout) complete 'p \"break1'" }
395 }
396
397 setup_xfail "*-*-*"
398 send_gdb "p \"break1.\t"
399 sleep 1
400 gdb_expect {
401 -re "^p \"break1\\.\\\x07$"\
402 { send_gdb "\n"
403 gdb_expect {
404 -re ".*$gdb_prompt $" { fail "complete 'p \"break1.'"}
405 timeout {fail "(timeout) complete 'p \"break1.'"}
406 }
407 }
408 -re "^p \"break1\\.c\"$"\
409 { send_gdb "\n"
410 gdb_expect {
411 -re ".*$gdb_prompt $" { pass "complete 'p \"break1.'"}
412 timeout {fail "(timeout) complete 'p \"break1.'"}
413 }
414 }
415 -re "^p \"break1\\..*$"
416 { send_gdb "\n"
417 gdb_expect {
418 -re ".*$gdb_prompt $" { fail "complete 'p \"break1.'"}
419 timeout {fail "(timeout) complete 'p \"break1.'"}
420 }
421 }
422 -re ".*$gdb_prompt $" { fail "complete 'p \"break1.'" }
423 timeout { fail "(timeout) complete 'p \"break1.'" }
424 }
425
426 send_gdb "p 'arg\t"
427 sleep 1
428 gdb_expect {
429 -re "^p 'arg\\\x07$"\
430 { send_gdb "\n"
431 gdb_expect {
432 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $"\
433 { pass "complete 'p \'arg'"}
434 -re ".*$gdb_prompt $" { fail "complete 'p \'arg'"}
435 timeout {fail "(timeout) complete 'p \'arg'"}
436 }
437 }
438 -re ".*$gdb_prompt $" { fail "complete 'p \'arg'" }
439 timeout { fail "(timeout) complete 'p \'arg'" }
440 }
441
442 send_gdb "p 'arg\t"
443 sleep 1
444 gdb_expect {
445 -re "^p 'arg\\\x07$" {
446 send_gdb "\t"
447 gdb_expect {
448 -re ".*argv.*$gdb_prompt p 'arg$" {
449 send_gdb "\n"
450 gdb_expect {
451 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
452 pass "complete (2) 'p \'arg'"
453 }
454 -re ".*$gdb_prompt $" { fail "complete (2) 'p \'arg'" }
455 timeout { fail "(timeout) complete (2) 'p \'arg'" }
456 }
457 }
458 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
459 send_gdb "n"
460 gdb_expect {
461 -re "\\(gdb\\) p 'arg$" {
462 send_gdb "\n"
463 gdb_expect {
464 -re "(Invalid character constant\\.|Unmatched single quote\\.).*$gdb_prompt $" {
465 pass "complete (2) 'p \'arg'"
466 }
467 -re ".*$gdb_prompt $" {
468 fail "complete (2) 'p \'arg'"
469 }
470 timeout { fail "(timeout) complete (2) 'p \'arg'" }
471 }
472 }
473 -re ".*$gdb_prompt $" { fail "complete (2) 'p \'arg'" }
474 timeout { fail "(timeout) complete (2) 'p \'arg'" }
475 }
476 }
477 -re ".*$gdb_prompt $" { fail "complete (2) 'p \'arg'" }
478 timeout { fail "(timeout) complete (2) 'p \'arg'" }
479 }
480 }
481 -re ".*$gdb_prompt $" { fail "complete (2) 'p \'arg'" }
482 timeout { fail "(timeout) complete (2) 'p \'arg'" }
483 }
484
485
486 # These tests used to try completing the shorter "p b-a".
487 # Unfortunately, on some systems, there are .o files in system
488 # libraries which declare static variables named `b'. Of course,
489 # those variables aren't really in scope, as far as the compiler is
490 # concerned. But GDB deliberately tries to be more liberal: if you
491 # enter an identifier that doesn't have any binding in scope, GDB will
492 # search all the program's compilation units for a static variable of
493 # the given name.
494 #
495 # This behavior can help avoid a lot of pedantry, so it's usually a
496 # good thing. But in this test case, it causes GDB to print the value
497 # of some random variable, instead of giving us the "No symbol..."
498 # error we were expecting.
499 #
500 # For example, on S/390 linux, the file s_atan.c in libm.a declares a
501 # `b', which is a structure containing an int and a float, so GDB says
502 # ``Argument to arithmetic operation not a number or boolean'' instead
503 # of ``No symbol ...''.
504 #
505 # So, I'm hoping that there is no system with a static library variable named
506 # `no_var_by_this_name'.
507 send_gdb "p no_var_named_this-arg\t"
508 sleep 1
509 gdb_expect {
510 -re "^p no_var_named_this-arg\\\x07$" {
511 send_gdb "\n"
512 gdb_expect {
513 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
514 pass "complete 'p no_var_named_this-arg'"
515 }
516 -re ".*$gdb_prompt $" {
517 fail "complete 'p no_var_named_this-arg'"
518 }
519 timeout {
520 fail "(timeout) complete 'p no_var_named_this-arg'"
521 }
522 }
523 }
524 -re ".*$gdb_prompt $" {
525 fail "complete 'p no_var_named_this-arg'"
526 }
527 timeout {
528 fail "(timeout) complete 'p no_var_named_this-arg'"
529 }
530 }
531
532 send_gdb "p no_var_named_this-arg\t"
533 sleep 1
534 gdb_expect {
535 -re "^p no_var_named_this-arg\\\x07$" {
536 send_gdb "\t"
537 gdb_expect {
538 -re ".*argv.*$gdb_prompt p no_var_named_this-arg$" {
539 send_gdb "\n"
540 gdb_expect {
541 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
542 pass "complete (2) 'p no_var_named_this-arg'"
543 }
544 -re ".*$gdb_prompt $" {
545 fail "complete (2) 'p no_var_named_this-arg'"
546 }
547 timeout {
548 fail "(timeout) complete (2) 'p no_var_named_this-arg'"
549 }
550 }
551 }
552 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
553 send_gdb "n"
554 gdb_expect {
555 -re "\\(gdb\\) p no_var_named_this-arg$" {
556 send_gdb "\n"
557 gdb_expect {
558 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
559 pass "complete (2) 'p no_var_named_this-arg'"
560 }
561 -re ".*$gdb_prompt $" {
562 fail "complete (2) 'p no_var_named_this-arg'"
563 }
564 timeout {
565 fail "(timeout) complete (2) 'p no_var_named_this-arg'"
566 }
567 }
568 }
569 -re ".*$gdb_prompt $" {
570 fail "complete (2) 'p no_var_named_this-arg'"
571 }
572 timeout {
573 fail "(timeout) complete (2) 'p no_var_named_this-arg'"
574 }
575 }
576 }
577 -re ".*$gdb_prompt $" {
578 fail "complete (2) 'p no_var_named_this-arg'"
579 }
580 timeout { fail "(timeout) complete (2) 'p no_var_named_this-arg'" }
581 }
582 }
583 -re ".*$gdb_prompt $" { fail "complete (2) 'p no_var_named_this-arg'" }
584 timeout { fail "(timeout) complete (2) 'p no_var_named_this-arg'" }
585 }
586
587 send_gdb "p no_var_named_this-\t"
588 sleep 1
589 gdb_expect {
590 -re "^p no_var_named_this-\\\x07$" {
591 send_gdb "\t"
592 gdb_expect {
593 -re "(There are $decimal possibilities\\. Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
594 send_gdb "n"
595 gdb_expect {
596 -re "\\(gdb\\) p no_var_named_this-$" {
597 send_gdb "\n"
598 gdb_expect {
599 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
600 pass "complete (2) 'p no_var_named_this-'"
601 }
602 -re ".*$gdb_prompt $" {
603 fail "complete (2) 'p no_var_named_this-'"
604 }
605 timeout {
606 fail "(timeout) complete (2) 'p no_var_named_this-'"
607 }
608 }
609 }
610 -re ".*$gdb_prompt $" {
611 fail "complete (2) 'p no_var_named_this-'"
612 }
613 timeout {
614 fail "(timeout) complete (2) 'p no_var_named_this-'"
615 }
616 }
617 }
618 -re ".*argv.*$gdb_prompt p no_var_named_this-$" {
619 send_gdb "\n"
620 gdb_expect {
621 -re "No symbol \"no_var_named_this\" in current context\\..*$gdb_prompt $" {
622 pass "complete (2) 'p no_var_named_this-'"
623 }
624 -re ".*$gdb_prompt $" {
625 fail "complete (2) 'p no_var_named_this-'"
626 }
627 timeout {
628 fail "(timeout) complete (2) 'p no_var_named_this-'"
629 }
630 }
631 }
632 -re ".*$gdb_prompt $" {
633 fail "complete (2) 'p no_var_named_this-'"
634 }
635 timeout { fail "(timeout) complete (2) 'p no_var_named_this-'" }
636 }
637 }
638 -re ".*$gdb_prompt $" { fail "complete (2) 'p no_var_named_this-'" }
639 timeout { fail "(timeout) complete (2) 'p no_var_named_this-'" }
640 }
641
642 send_gdb "p values\[0\].a\t"
643 sleep 3
644 gdb_expect {
645 -re "^p values.0..a_field $"\
646 { send_gdb "\n"
647 sleep 1
648 gdb_expect {
649 -re "^.* = 0.*$gdb_prompt $"\
650 { pass "complete 'p values\[0\].a'"}
651 -re ".*$gdb_prompt $" { fail "complete 'p values\[0\].a'"}
652 timeout {fail "(timeout) complete 'p values\[0\].a'"}
653 }
654 }
655 -re ".*$gdb_prompt $" { fail "complete 'p values\[0\].a'" }
656 timeout { fail "(timeout) complete 'p values\[0\].a' 2" }
657 }
658
659 send_gdb "p values\[0\] . a\t"
660 gdb_expect {
661 -re "^p values.0. . a_field $"\
662 { send_gdb "\n"
663 gdb_expect {
664 -re "^.* = 0.*$gdb_prompt $"\
665 { pass "complete 'p values\[0\] . a'"}
666 -re ".*$gdb_prompt $" { fail "complete 'p values\[0\] . a'"}
667 timeout {fail "(timeout) complete 'p values\[0\] . a'"}
668 }
669 }
670 -re ".*$gdb_prompt $" { fail "complete 'p values\[0\] . a'" }
671 timeout { fail "(timeout) complete 'p values\[0\] . a' 2" }
672 }
673
674 send_gdb "p &values\[0\] -> a\t"
675 gdb_expect {
676 -re "^p &values.0. -> a_field $"\
677 { send_gdb "\n"
678 gdb_expect {
679 -re "^.* = .*0x\[0-9a-fA-F\]*.*$gdb_prompt $"\
680 { pass "complete 'p &values\[0\] -> a'"}
681 -re ".*$gdb_prompt $" { fail "complete 'p &values\[0\] -> a'"}
682 timeout {fail "(timeout) complete 'p &values\[0\] -> a'"}
683 }
684 }
685 -re ".*$gdb_prompt $" { fail "complete 'p &values\[0\] -> a'" }
686 timeout { fail "(timeout) complete 'p &values\[0\] -> a' 2" }
687 }
688
689 # The following tests used to simply try to complete `${objdir}/file',
690 # and so on. The problem is that ${objdir} can be very long; the
691 # completed filename may be more than eighty characters wide. When
692 # this happens, readline tries to manage things, producing output that
693 # may make sense on the screen, but is rather hard for our script to
694 # recognize.
695 #
696 # In the case that motivated this change, the (gdb) prompt occupied
697 # the leftmost six columns, and `${objdir}/' was seventy-four
698 # characters long --- eighty in all. After printing the slash,
699 # readline emitted a space, a carriage return, and then `Makefile'
700 # (the tab character being received as input after `Make'.
701 #
702 # Basically, you have to let readline do whatever it's going to do to
703 # make the screen look right. If it happens to use a different
704 # strategy on Tuesdays to get the cursor in the right place, that's
705 # not something the testsuite should care about.
706 #
707 # So, we avoid long lines. We `cd' to ${objdir} first, and then do
708 # the completion relative to the current directory.
709
710 # ${srcdir} may be a relative path. We want to make sure we end up
711 # in the right directory - so make sure we know where it is.
712 set mydir [pwd]
713 cd ${srcdir}
714 set fullsrcdir [pwd]
715 cd ${mydir}
716
717 # If the directory name contains a '+' we must escape it, adding a backslash.
718 # If not, the test below will fail because it will interpret the '+' as a
719 # regexp operator. We use string_to_regexp for this purpose.
720
721 gdb_test "cd ${fullsrcdir}" \
722 "Working directory [string_to_regexp ${fullsrcdir}].*" \
723 "cd to \${srcdir}"
724
725
726 # GDB used to fail adding / on directories, on the first try only.
727 set uniquedir ../testsuite/gdb.base/comp-dir
728 set escapeduniquedir [string_to_regexp ${uniquedir}]
729 set uniquesu subdi
730 set uniquesub ${uniquesu}r
731 set escapeuniquesub [string_to_regexp ${uniquesub}]
732 send_gdb "dir ${uniquedir}\t"
733 gdb_expect {
734 -re "${escapeduniquedir}/" {
735 pass "directory completion"
736 send_gdb "${uniquesu}\t"
737 }
738 -re "${escapeduniquedir} $" {
739 fail "directory completion (old gdb bug)"
740 send_gdb "\b/${uniquesu}\t"
741 }
742 default {
743 fail "directory completion (timeout)"
744 send_gdb "\ndir ${uniquedir}/${uniquesu}\t"
745 }
746 }
747
748 gdb_expect {
749 -re "${escapeuniquesub}/$" {
750 pass "directory completion 2"
751 }
752 timeout {
753 fail "directory completion 2"
754 }
755 }
756
757 # Empty COMMAND sends no newline while " " sends the newline we need.
758 gdb_test " " "Source directories searched: .*" "Glob remaining of directory test"
759
760
761 send_gdb "complete file ./gdb.base/compl\n"
762 sleep 1
763 gdb_expect {
764 -re "file ./gdb.base/completion\\.exp.*$gdb_prompt $"
765 { pass "complete-command 'file ./gdb.base/compl'"}
766 -re ".*$gdb_prompt $" { fail "complete-command 'file ./gdb.base/compl'" }
767 timeout { fail "(timeout) complete-command 'file ./gdb.base/compl'" }
768 }
769
770 send_gdb "file ./gdb.base/complet\t"
771 sleep 1
772 gdb_expect {
773 -re "^file ./gdb.base/completion\\.exp $"\
774 { send_gdb "\n"
775 # Ignore the exact error message.
776 gdb_test_multiple "" "complete 'file ./gdb.base/complet'" {
777 -re "\r\nA program is being debugged already\\.\[\r\n\]+Are you sure you want to change the file\\? \\(y or n\\) $" {
778 send_gdb "n\n"
779 exp_continue
780 }
781 -re ".*$gdb_prompt $" { pass "complete 'file ./gdb.base/complet'" }
782 }
783 }
784 -re ".*$gdb_prompt $" { fail "complete 'file ./gdb.base/complet'" }
785 timeout { fail "(timeout) complete 'file ./gdb.base/complet'" }
786 }
787
788 send_gdb "info func marke\t"
789 sleep 1
790 gdb_expect {
791 -re "^info func marke.*r$"\
792 {
793 send_gdb "\t\t"
794 sleep 3
795 gdb_expect {
796 -re "marker1.*$gdb_prompt info func marker$"\
797 { send_gdb "\n"
798 gdb_expect {
799 -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 $"\
800 { pass "complete 'info func marke'"}
801 -re ".*$gdb_prompt $" { fail "complete 'info func marke'"}
802 timeout {fail "(timeout) complete 'info func marke'"}
803 }
804 }
805 -re ".*$gdb_prompt $" { fail "complete 'info func marke'"}
806 timeout {fail "(timeout) complete 'info func marke'"}
807 }
808 }
809 -re ".*$gdb_prompt $" { fail "complete 'info func marke'" }
810 timeout { fail "(timeout) complete 'info func marke'" }
811 }
812
813
814 send_gdb "set follow-fork-mode \t\t"
815 sleep 1
816 gdb_expect {
817 -re "child.*parent.*$gdb_prompt set follow-fork-mode $"\
818 { send_gdb "\n"
819 gdb_expect {
820 -re "Requires an argument.*child.*parent.*$gdb_prompt $"\
821 { pass "complete 'set follow-fork-mode'"}
822 -re "Ambiguous item \"\"\\..*$gdb_prompt $"\
823 { pass "complete 'set follow-fork-mode'"}
824 -re ".*$gdb_prompt $" { fail "complete 'set follow-fork-mode'"}
825 timeout {fail "(timeout) complete 'set follow-fork-mode'"}
826 }
827 }
828 -re ".*$gdb_prompt $" { fail "complete 'set follow-fork-mode'" }
829 timeout { fail "(timeout) complete 'set follow-fork-mode'" }
830 }
831
832 send_gdb "p values\[0\].nonex.\t"
833 gdb_expect {
834 -re "Type struct some_struct has no component named nonex.\r\n$gdb_prompt $"\
835 { pass "Completing non-existing component" }
836 -re ".*$gdb_prompt $" { fail "Completing non-existing component" }
837 timeout { fail "(timeout) Completing non-existing component" }
838 eof { fail "(eof) Completing non-existing component #2" }
839 }
840 # Double memory freeing gets found only on the second run:
841 send_gdb "p values\[0\].nonex.\t"
842 gdb_expect {
843 -re "Type struct some_struct has no component named nonex.\r\n$gdb_prompt $"\
844 { pass "Completing non-existing component #2" }
845 -re ".*$gdb_prompt $" { fail "Completing non-existing component #2" }
846 timeout { fail "(timeout) Completing non-existing component #2" }
847 eof { fail "(eof) Completing non-existing component #2" }
848 }
849
850 # Restore globals modified in this test...
851 set timeout $oldtimeout1
852
853 return 0
This page took 0.048289 seconds and 5 git commands to generate.