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