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