This commit was generated by cvs2svn to track changes on a CVS vendor
[external/binutils.git] / gdb / testsuite / gdb.base / completion.exp
1 # Copyright (C) 1998 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 # This file was written by Elena Zannoni (ezannoni@cygnus.com)
21
22 # This file is part of the gdb testsuite.
23
24 #
25 # tests for command completion
26 #
27 # Here are some useful test cases for completion.  
28 # They should be tested with both M-? and TAB.
29 #
30 #   "show output-" "radix"
31 #   "show output" "-radix"
32 #   "p" ambiguous (commands starting with p--path, print, printf, etc.)
33 #   "p "  ambiguous (all symbols)
34 #   "info t foo" no completions
35 #   "info t " no completions
36 #   "info t" ambiguous ("info target", "info terminal", etc.)
37 #   "info ajksdlfk" no completions
38 #   "info ajksdlfk " no completions
39 #   "info" " "
40 #   "info " ambiguous (all info commands)
41 #   "p \"a" no completions (string constant)
42 #   "p 'a" ambiguous (all symbols starting with a)
43 #   "p b-a" ambiguous (all symbols starting with a)
44 #   "p b-" ambiguous (all symbols)
45 #   "file Make" "file" (word break hard to screw up here)
46 #   "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
47 #
48
49
50 if $tracelevel then {
51         strace $tracelevel
52         }
53
54
55 if { ![istarget "hppa*-hp-hpux*"] } {
56     #skip all these tests for now (FIXME)
57     continue
58 }
59
60 global usestubs
61
62 #
63 # test running programs
64 #
65 set prms_id 0
66 set bug_id 0
67
68 set testfile "break"
69 set srcfile ${testfile}.c
70 set binfile ${objdir}/${subdir}/${testfile}
71 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug additional_flags=-w}] != "" } {
72     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
73 }
74
75 if [get_compiler_info ${binfile}] {
76     return -1;
77 }
78
79 gdb_exit
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
92 send_gdb "hfgfh\t"
93 sleep 1
94 gdb_expect  {
95         -re "^hfgfh\\\x07$"\
96             { send_gdb "\n"
97               gdb_expect {
98                       -re "Undefined command: \"hfgfh\"\\.  Try \"help\"\\..*$gdb_prompt $"\
99                                         { pass "complete 'hfgfh'"}
100                       -re ".*$gdb_prompt $" { fail "complete 'hfgfh'"}
101                       timeout           {fail "(timeout) complete 'hfgfh'"}
102                      }
103             }
104         -re ".*$gdb_prompt $"       { fail "complete 'hfgfh'" }
105         timeout         { fail "(timeout) complete 'hfgfh'" }
106         }
107
108 #exp_internal 0
109
110 send_gdb "show output\t"
111 sleep 1
112 gdb_expect  {
113         -re "^show output-radix $"\
114             { send_gdb "\n"
115               gdb_expect {
116                       -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
117                                         { pass "complete 'show output'"}
118                       -re ".*$gdb_prompt $" { fail "complete 'show output'"}
119                       timeout           {fail "(timeout) complete 'show output'"}
120                      }
121             }
122         -re "^show output$"\
123             { send_gdb "\n"
124                gdb_expect {
125                       -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
126                                         { fail "complete 'show output'"}
127                       -re ".*$gdb_prompt $" { fail "complete 'show output'"}
128                       timeout           { fail "(timeout) complete 'show output'"}
129                      }
130
131              }
132
133         -re ".*$gdb_prompt $"       { fail "complete 'show output'" }
134         timeout         { fail "(timeout) complete 'show output'" }
135         }
136
137
138 send_gdb "show output-\t"
139 sleep 1
140 gdb_expect  {
141         -re "^show output-radix $"\
142             { send_gdb "\n"
143               gdb_expect {
144                       -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
145                                         { pass "complete 'show output-'"}
146                       -re ".*$gdb_prompt $" { fail "complete 'show output-'"}
147                       timeout           {fail "(timeout) complete 'show output-'"}
148                      }
149             }
150         -re "^show output-$"\
151             { send_gdb "\n"
152                gdb_expect {
153                       -re "Default output radix for printing of values is 10\\..*$gdb_prompt $"\
154                                         { fail "complete 'show output-'"}
155                       -re ".*$gdb_prompt $" { fail "complete 'show output-'"}
156                       timeout           { fail "(timeout) complete 'show output-'"}
157                      }
158
159              }
160
161         -re ".*$gdb_prompt $"       { fail "complete 'show output-'" }
162         timeout         { fail "(timeout) complete 'show output-'" }
163         }
164
165 send_gdb "p\t"
166 sleep 1
167 gdb_expect  {
168         -re "^p\\\x07$"\
169             { send_gdb "\n"
170               sleep 1
171               gdb_expect {
172                       -re "The history is empty\\..*$gdb_prompt $"\
173                                         { pass "complete 'p'"}
174                       -re ".*$gdb_prompt $" { fail "complete 'p'"}
175                       timeout           {fail "(timeout) complete 'p' 2"}
176                      }
177             }
178         -re ".*$gdb_prompt $"       { fail "complete 'p'" }
179         timeout         { fail "(timeout) complete 'p' 1" }
180         }
181
182 send_gdb "p \t"
183 sleep 3
184 gdb_expect  {
185         -re "^p \\\x07$"\
186             { send_gdb "\n"
187               sleep 1
188               gdb_expect {
189                       -re "The history is empty\\..*$gdb_prompt $"\
190                                         { pass "complete 'p '"}
191                       -re ".*$gdb_prompt $" { fail "complete 'p '"}
192                       timeout           {fail "(timeout) complete 'p ' 1"}
193                      }
194             }
195         -re ".*$gdb_prompt $"       { fail "complete 'p '" }
196         timeout         { fail "(timeout) complete 'p ' 2" }
197         }
198
199
200 send_gdb "info t foo\t"
201 sleep 1
202 gdb_expect  {
203         -re "^info t foo\\\x07$"\
204             { send_gdb "\n"
205               gdb_expect {
206                       -re "Ambiguous info command \"t foo\": target, terminal, threads, tp, tracepoints, types\\..*$gdb_prompt $"\
207                                         { pass "complete 'info t foo'"}
208                       -re ".*$gdb_prompt $" { fail "complete 'info t foo'"}
209                       timeout           {fail "(timeout) complete 'info t foo'"}
210                      }
211             }
212         -re ".*$gdb_prompt $"       { fail "complete 'info t foo'" }
213         timeout         { fail "(timeout) complete 'info t foo'" }
214         }
215
216 send_gdb "info t\t"
217 sleep 1
218 gdb_expect  {
219         -re "^info t\\\x07$"\
220             { send_gdb "\n"
221               gdb_expect {
222                       -re "Ambiguous info command \"t\": target, terminal, threads, tp, tracepoints, types\\..
223 *$gdb_prompt $"\
224                                         { pass "complete 'info t'"}
225                       -re ".*$gdb_prompt $" { fail "complete 'info t'"}
226                       timeout           {fail "(timeout) complete 'info t'"}
227                      }
228             }
229         -re ".*$gdb_prompt $"       { fail "complete 'info t'" }
230         timeout         { fail "(timeout) complete 'info t'" }
231         }
232
233
234 send_gdb "info t \t"
235 sleep 1
236 gdb_expect  {
237         -re "^info t \\\x07$"\
238             { send_gdb "\n"
239               gdb_expect {
240                       -re "Ambiguous info command \"t \": target, terminal, threads, tp, tracepoints, types\\..
241 *$gdb_prompt $"\
242                                         { pass "complete 'info t '"}
243                       -re ".*$gdb_prompt $" { fail "complete 'info t '"}
244                       timeout           {fail "(timeout) complete 'info t '"}
245                      }
246             }
247         -re ".*$gdb_prompt $"       { fail "complete 'info t '" }
248         timeout         { fail "(timeout) complete 'info t '" }
249         }
250
251
252 send_gdb "info asdfgh\t"
253 sleep 1
254 gdb_expect  {
255         -re "^info asdfgh\\\x07$"\
256             { send_gdb "\n"
257               gdb_expect {
258                       -re "Undefined info command: \"asdfgh\".  Try \"help info\"\\..
259 *$gdb_prompt $"\
260                                         { pass "complete 'info asdfgh'"}
261                       -re ".*$gdb_prompt $" { fail "complete 'info asdfgh'"}
262                       timeout           {fail "(timeout) complete 'info asdfgh'"}
263                      }
264             }
265         -re ".*$gdb_prompt $"       { fail "complete 'info asdfgh'" }
266         timeout         { fail "(timeout) complete 'info asdfgh'" }
267         }
268
269
270 send_gdb "info asdfgh \t"
271 sleep 1
272 gdb_expect  {
273         -re "^info asdfgh \\\x07$"\
274             { send_gdb "\n"
275               gdb_expect {
276                       -re "Undefined info command: \"asdfgh \".  Try \"help info\"\\..
277 *$gdb_prompt $"\
278                                         { pass "complete 'info asdfgh '"}
279                       -re ".*$gdb_prompt $" { fail "complete 'info asdfgh '"}
280                       timeout           {fail "(timeout) complete 'info asdfgh '"}
281                      }
282             }
283         -re ".*$gdb_prompt $"       { fail "complete 'info asdfgh '" }
284         timeout         { fail "(timeout) complete 'info asdfgh '" }
285         }
286
287 send_gdb "info\t"
288 sleep 1
289 gdb_expect  {
290         -re "^info $"\
291             { send_gdb "\n"
292               gdb_expect {
293                       -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands:\r\n\r\n.*info address.*info watchpoints.*\r\n\r\nType \"help info\" followed by info subcommand name for full documentation.\r\nCommand name abbreviations are allowed if unambiguous\\..*$gdb_prompt $"\
294                                         { pass "complete 'info'"}
295                       -re ".*$gdb_prompt $" { fail "complete 'info'"}
296                       timeout           {fail "(timeout) complete 'info'"}
297                      }
298             }
299         -re ".*$gdb_prompt $"       { fail "complete 'info'" }
300         timeout         { fail "(timeout) complete 'info'" }
301         }
302
303 send_gdb "info \t"
304 sleep 1
305 gdb_expect  {
306         -re "^info \\\x07$"\
307             { send_gdb "\n"
308               gdb_expect {
309                       -re "\"info\" must be followed by the name of an info command\\.\r\nList of info subcommands:\r\n\r\n.*info address.*Type \"help info\" followed by info subcommand name for full documentation.\r\nCommand name abbreviations are allowed if unambiguous\\..*$gdb_prompt $"\
310                                         { pass "complete 'info '"}
311                       -re ".*$gdb_prompt $" { fail "complete 'info '"}
312                       timeout           {fail "(timeout) complete 'info '"}
313                      }
314             }
315         -re ".*$gdb_prompt $"       { fail "complete 'info '" }
316         timeout         { fail "(timeout) complete 'info '" }
317         }
318
319
320 send_gdb "info \t"
321 sleep 1
322 gdb_expect  {
323         -re "^info \\\x07$"\
324             { send_gdb "\t"
325               gdb_expect {
326                       -re "address.*types.*$gdb_prompt info $"\
327                           { send_gdb "\n"
328                             gdb_expect {
329                                      -re "\"info\".*unambiguous\\..*$gdb_prompt $"\
330                                         { pass "complete (2) 'info '"}
331                                      -re ".*$gdb_prompt $" { fail "complete (2) 'info '"}
332                                      timeout           {fail "(timeout) complete (2) 'info '"}
333                                     }
334                            }
335                       -re ".*$gdb_prompt $" { fail "complete (2) 'info '"}
336                       timeout           {fail "(timeout) complete (2) 'info '"}
337                      }
338             }
339         -re ".*$gdb_prompt $"       { fail "complete (2) 'info '" }
340         timeout         { fail "(timeout) complete (2) 'info '" }
341         }
342
343
344 send_gdb "p \"a\t"
345 sleep 1
346 gdb_expect  {
347         -re "^p \"a\\\x07$"\
348             { send_gdb "\n"
349               gdb_expect {
350                       -re "Unterminated string in expression\\..*$gdb_prompt $"\
351                                         { pass "complete 'p a'"}
352                       -re ".*$gdb_prompt $" { fail "complete 'p a'"}
353                       timeout           {fail "(timeout) complete 'p a'"}
354                      }
355             }
356         -re ".*$gdb_prompt $"       { fail "complete 'p \"a'" }
357         timeout         { fail "(timeout) complete 'p \"a'" }
358         }
359
360 send_gdb "p 'a\t"
361 sleep 1
362 gdb_expect  {
363         -re "^p 'a\\\x07$"\
364             { send_gdb "\n"
365               gdb_expect {
366                       -re "Invalid character constant\\..*$gdb_prompt $"\
367                                         { pass "complete 'p \'a'"}
368                       -re ".*$gdb_prompt $" { fail "complete 'p \'a'"}
369                       timeout           {fail "(timeout) complete 'p \'a'"}
370                      }
371             }
372         -re ".*$gdb_prompt $"       { fail "complete 'p \'a'" }
373         timeout         { fail "(timeout) complete 'p \'a'" }
374         }
375
376 send_gdb "p 'a\t"
377 sleep 1
378 gdb_expect {
379     -re "^p 'a\\\x07$" {
380         send_gdb "\t"
381         gdb_expect {
382             -re "a64l.*atol.*$gdb_prompt p .a$" {
383                 send_gdb "\n"
384                 gdb_expect {
385                     -re "Invalid character constant\\..*$gdb_prompt $" {
386                         pass "complete (2) 'p \'a'"
387                     }
388                     -re ".*$gdb_prompt $" { fail "complete (2) 'p \'a'" }
389                     timeout { fail "(timeout) complete (2) 'p \'a'" }
390                 }
391             }
392             -re "(There are $decimal possibilities\\.  Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
393                 send_gdb "n"
394                 gdb_expect {
395                     -re "\\(gdb\\) p 'a$" {
396                         send_gdb "\n"
397                         gdb_expect {
398                             -re "Invalid character constant\\..*$gdb_prompt $" {
399                                 pass "complete (2) 'p \'a'"
400                             }
401                             -re ".*$gdb_prompt $" { 
402                                 fail "complete (2) 'p \'a'"
403                             }
404                             timeout { fail "(timeout) complete (2) 'p \'a'" }
405                         }
406                     }
407                     -re ".*$gdb_prompt $" { fail "complete (2) 'p \'a'" }
408                     timeout { fail "(timeout) complete (2) 'p \'a'" }
409                 }
410             }
411             -re ".*$gdb_prompt $" { fail "complete (2) 'p \'a'" }
412             timeout { fail "(timeout) complete (2) 'p \'a'" }
413         }
414     }
415     -re ".*$gdb_prompt $" { fail "complete (2) 'p \'a'" }
416     timeout { fail "(timeout) complete (2) 'p \'a'" }
417 }
418
419
420 send_gdb "p b-a\t"
421 sleep 1
422 gdb_expect  {
423         -re "^p b-a\\\x07$"\
424             { send_gdb "\n"
425               gdb_expect {
426                       -re "No symbol \"b\" in current context\\..*$gdb_prompt $"\
427                                         { pass "complete 'p b-a'"}
428                       -re ".*$gdb_prompt $" { fail "complete 'p b-a'"}
429                       timeout           {fail "(timeout) complete 'p b-a'"}
430                      }
431             }
432         -re ".*$gdb_prompt $"       { fail "complete 'p b-a'" }
433         timeout         { fail "(timeout) complete 'p b-a'" }
434         }
435
436 send_gdb "p b-a\t"
437 sleep 1
438 gdb_expect {
439     -re "^p b-a\\\x07$" {
440         send_gdb "\t"
441         gdb_expect {
442             -re "a64l.*atol.*$gdb_prompt p b-a$" {
443                 send_gdb "\n"
444                 gdb_expect {
445                     -re "No symbol \"b\" in current context\\..*$gdb_prompt $" {
446                         pass "complete (2) 'p b-a'"
447                     }
448                     -re ".*$gdb_prompt $" { fail "complete (2) 'p b-a'" }
449                     timeout { fail "(timeout) complete (2) 'p b-a'" }
450                 }
451             }
452             -re "(There are $decimal possibilities\\.  Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
453                 send_gdb "n"
454                 gdb_expect {
455                     -re "\\(gdb\\) p b-a$" {
456                         send_gdb "\n"
457                         gdb_expect {
458                             -re "No symbol \"b\" in current context\\..*$gdb_prompt $" {
459                                 pass "complete (2) 'p b-a'"
460                             }
461                             -re ".*$gdb_prompt $" {
462                                 fail "complete (2) 'p b-a'"
463                             }
464                             timeout { fail "(timeout) complete (2) 'p b-a'" }
465                         }
466                     }
467                     -re ".*$gdb_prompt $" { fail "complete (2) 'p b-a'" }
468                     timeout { fail "(timeout) complete (2) 'p b-a'" }
469                 }
470             }
471             -re ".*$gdb_prompt $" { fail "complete (2) 'p b-a'" }
472             timeout { fail "(timeout) complete (2) 'p b-a'" }
473         }
474     }
475     -re ".*$gdb_prompt $" { fail "complete (2) 'p b-a'" }
476     timeout { fail "(timeout) complete (2) 'p b-a'" }
477 }
478
479 send_gdb "p b-\t"
480 sleep 1
481 gdb_expect  {
482     -re "^p b-\\\x07$" {
483         send_gdb "\t"
484         gdb_expect {
485             -re "(There are $decimal possibilities\\.  Do you really\r\nwish to see them all.|Display all $decimal possibilities.) \\(y or n\\)$" {
486                 send_gdb "n"
487                 gdb_expect {
488                     -re "\\(gdb\\) p b-$" {
489                         send_gdb "\n"
490                         gdb_expect {
491                             -re "No symbol \"b\" in current context\\..*$gdb_prompt $" {
492                                 pass "complete (2) 'p b-'"
493                             }
494                             -re ".*$gdb_prompt $" {
495                                 fail "complete (2) 'p b-'"
496                             }
497                             timeout { fail "(timeout) complete (2) 'p b-'" }
498                         }
499                     }
500                     -re ".*$gdb_prompt $" { fail "complete (2) 'p b-'" }
501                     timeout { fail "(timeout) complete (2) 'p b-'" }
502                 }
503             }
504             -re ".*$gdb_prompt $" { fail "complete (2) 'p b-'" }
505             timeout { fail "(timeout) complete (2) 'p b-'" }
506         }
507     }
508     -re ".*$gdb_prompt $" { fail "complete (2) 'p b-'" }
509     timeout { fail "(timeout) complete (2) 'p b-'" }
510 }
511
512 send_gdb "file ${objdir}/Make\t"
513 sleep 1
514 gdb_expect  {
515         -re "file ${objdir}/Makefile.*$"\
516             { send_gdb "\n"
517               gdb_expect {
518                       -re "\r\nA program is being debugged already\\.  Kill it\\? \\(y or n\\) $"\
519                       { send_gdb "n\n"
520                         gdb_expect {
521                                 -re "\r\nProgram not killed\\.\r\n$gdb_prompt $"\
522                                         { pass "complete 'file Make'"}
523                                 -re ".*$gdb_prompt $" { fail "complete 'file Make'"}
524                                 timeout           {fail "(timeout) complete 'file Make'"}
525                                }
526                       }
527                       -re ".*$gdb_prompt $" { fail "complete 'file Make'"}
528                       timeout           {fail "(timeout) complete 'file Make'"}
529                      }
530             }
531         -re ".*$gdb_prompt $"       { fail "complete 'file Make'" }
532         timeout         { fail "(timeout) complete 'file Make'" }
533         }
534
535
536 send_gdb "file ${srcdir}/gdb.base/self\t"
537 sleep 1
538 gdb_expect  {
539         -re "^file ${srcdir}/gdb.base/.*'selftest\\.exp' $"\
540             { send_gdb "\n"
541               gdb_expect {
542                       -re "\r\nA program is being debugged already\\.  Kill it\\? \\(y or n\\) $"
543 \
544                       { send_gdb "n\n"
545                         gdb_expect {
546                                 -re "\r\nProgram not killed\\.\r\n$gdb_prompt $"\
547                                         { pass "complete 'file gdb.base/self'"}
548                                 -re ".*$gdb_prompt $" { fail "complete 'file gdb.base/self'"}
549                                 timeout           {fail "(timeout) complete 'file gdb.base/self'"}
550                                }
551                       }
552                       -re ".*$gdb_prompt $" { fail "complete 'file gdb.base/self'"}
553                       timeout           {fail "(timeout) complete 'file gdb.base/self'"}
554                      }
555             }
556         -re ".*$gdb_prompt $"       { fail "complete 'file gdb.base/self'" }
557         timeout         { fail "(timeout) complete 'file gdb.base/self'" }
558         }
559
560
561 send_gdb "info func mark\t"
562 sleep 1
563 gdb_expect  {
564         -re "^info func mark.*er$"\
565             {
566               send_gdb "\t\t"
567               sleep 3
568               gdb_expect {
569                       -re "marker1.*$gdb_prompt info func marker$"\
570                       { send_gdb "\n"
571                         gdb_expect {
572                                 -re "All functions matching regular expression \"marker\":\r\n\r\nFile.*break.c:\r\nint marker1\\(.*\\);\r\nint marker2\\(int\\).*marker3\\(char.*char.*\\).*marker4\\(long\\);\r\n$gdb_prompt $"\
573                                                   { pass "complete 'info func mar'"}
574                                 -re ".*$gdb_prompt $" { fail "complete 'info func mar'"}
575                                 timeout           {fail "(timeout) complete 'info func mar'"}
576                                }
577                       }
578                       -re ".*$gdb_prompt $" { fail "complete 'info func mar'"}
579                       timeout           {fail "(timeout) complete 'info func mar'"}
580                      }
581             }
582         -re ".*$gdb_prompt $"       { fail "complete 'info func mar'" }
583         timeout         { fail "(timeout) complete 'info func mar'" }
584         }
585
586
587 send_gdb "set follow-fork-mode \t\t"
588 sleep 1
589 gdb_expect  {
590         -re "ask.*child.*parent.*$gdb_prompt set follow-fork-mode $"\
591             { send_gdb "\n"
592               gdb_expect {
593                       -re "Requires an argument.*parent.*child.*ask.*$gdb_prompt $"\
594                                         { pass "complete 'set follow-fork-mode'"}
595                       -re "Ambiguous item \"\"\\..*$gdb_prompt $"\
596                                         { pass "complete 'set follow-fork-mode'"}
597                       -re ".*$gdb_prompt $" { fail "complete 'set follow-fork-mode'"}
598                       timeout           {fail "(timeout) complete 'set follow-fork-mode'"}
599                      }
600             }
601         -re ".*$gdb_prompt $"       { fail "complete 'set follow-fork-mode'" }
602         timeout         { fail "(timeout) complete 'set follow-fork-mode'" }
603         }
604
605 set timeout $oldtimeout1
606 return 0
607
608
609
610
611
612
613
614
615
616
617
618
619
620