1# Copyright (C) 1992, 1994, 1995 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 Fred Fish. (fnf@cygnus.com) 21 22if $tracelevel then { 23 strace $tracelevel 24} 25 26set prms_id 0 27set bug_id 0 28 29set testfile "list" 30set binfile ${objdir}/${subdir}/${testfile} 31if { [compile "-g -c ${srcdir}/${subdir}/list0.c"] != "" } { 32 perror "Couldn't compile ${testfile}0.c to object" 33 return -1 34} 35execute_anywhere "mv list0.o ${binfile}0.o" 36if { [compile "-g -c ${srcdir}/${subdir}/list1.c"] != "" } { 37 perror "Couldn't compile ${testfile}1.c to object" 38 return -1 39} 40execute_anywhere "mv list1.o ${binfile}1.o" 41if { [compile "${binfile}0.o ${binfile}1.o -o ${binfile}"] != "" } { 42 perror "Couldn't link ${testfile}." 43 return -1 44} 45 46# Create and source the file that provides information about the compiler 47# used to compile the test case. 48execute_anywhere "rm -f ${binfile}.ci" 49if { [compile "-E ${srcdir}/${subdir}/compiler.c > ${binfile}.ci"] != "" } { 50 perror "Couldn't make ${binfile}.ci file" 51 return -1 52} 53source ${binfile}.ci 54 55# 56# Local utility proc just to set and verify listsize 57# Return 1 if success, 0 if fail. 58# 59 60proc set_listsize { arg } { 61 global prompt 62 63 send "set listsize $arg\n" 64 expect { 65 -re "set listsize $arg\[\r\n\]+$prompt $" {} 66 -re ".*$prompt $" { fail "setting listsize to $arg" ; return 0 } 67 timeout { fail "set listsize to $arg (timeout)" ; return 0 } 68 } 69 70 send "show listsize\n" 71 expect { 72 -re "Number of source lines .* is $arg.\r\n.*$prompt $" {} 73 -re ".*$prompt $" { fail "listsize not set to $arg" ; return 0 } 74 timeout { fail "show listsize (timeout)" ; return 0 } 75 } 76 return 1 77} 78 79# 80# Test display of listsize lines around a given line number. 81# 82 83proc test_listsize {} { 84 global prompt 85 86 # Show default size 87 88 send "show listsize\n" 89 expect { 90 -re "Number of source lines gdb will list by default is 10.*$prompt $" { 91 pass "show default list size" 92 } 93 -re ".*$prompt $" { 94 fail "show default listsize (10)" 95 } 96 timeout { 97 fail "show listsize (timeout)" 98 } 99 } 100 101 # Show the default lines 102 # The second case is for optimized code, it is still correct. 103 104 # This doesn't work for COFF targets. 105 setup_xfail "a29k-*-udi" 106 send "list\n" 107 expect { 108 -re "1\[ \t\]+#include \"list0.h\".*10\[ \t\]+x = 0;\r\n$prompt $" { 109 pass "list default lines around main" 110 } 111 -re "2.*11\[ \t\]+foo .x\[+)\]+;\r\n$prompt $" { 112 pass "list default lines around main" 113 } 114 -re ".*$prompt $" { 115 fail "list default lines around main" 116 } 117 timeout { 118 fail "list default lines around main (timeout)" 119 } 120 } 121 122 # Ensure we can limit printouts to one line 123 124 if [ set_listsize 1 ] then { 125 setup_xfail "*-*-*" 126 send "list 1\n" 127 expect { 128 -re "1\[ \t\]+#include \"list0.h\"\r\n$prompt $" { 129 pass "list line 1 with listsize 1" 130 } 131 -re "list 1\r\n$prompt $" { 132 fail "list line 1 with listsize 1" 133 } 134 -re ".*$prompt $" { 135 fail "list line 1 with listsize 1" 136 } 137 timeout { 138 fail "list line 1 with listsize 1 (timeout)" 139 } 140 } 141 142 setup_xfail "*-*-*" 143 send "list 2\n" 144 expect { 145 -re "2\[ \t\]+\r\n$prompt $" { 146 pass "list line 2 with listsize 1" 147 } 148 -re "list 2\r\n$prompt $" { 149 fail "list line 2 with listsize 1" 150 } 151 -re ".*$prompt $" { 152 fail "list line 2 with listsize 1" 153 } 154 timeout { 155 fail "list line 2 with listsize 1 (timeout)" 156 } 157 } 158 } 159 160 # Try just two lines 161 162 if [ set_listsize 2 ] then { 163 send "list 1\n" 164 expect { 165 -re "1\[ \t\]+#include \"list0.h\"\r\n$prompt $" { 166 pass "list line 1 with listsize 2" 167 } 168 -re ".*$prompt $" { 169 fail "list line 1 with listsize 2" 170 } 171 timeout { 172 fail "list line 1 with listsize 2 (timeout)" 173 } 174 } 175 176 send "list 2\n" 177 expect { 178 -re "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+\r\n$prompt $" { 179 pass "list line 2 with listsize 2" 180 } 181 -re ".*$prompt $" { 182 fail "list line 2 with listsize 2" 183 } 184 timeout { 185 fail "list line 2 with listsize 2 (timeout)" 186 } 187 } 188 189 send "list 3\n" 190 expect { 191 -re "2\[ \t\]+\r\n3\[ \t\]+main \[)(\]+\r\n$prompt $" { 192 pass "list line 3 with listsize 2" 193 } 194 -re ".*$prompt $" { 195 fail "list line 3 with listsize 2" 196 } 197 timeout { 198 fail "list line 3 with listsize 2 (timeout)" 199 } 200 } 201 } 202 203 # Try small listsize > 1 that is an odd number 204 205 if [ set_listsize 3 ] then { 206 setup_xfail "*-*-*" 207 send "list 1\n" 208 expect { 209 -re "1\[ \t\]+#include \"list0.h\"2\[ \t\]+\r\n$prompt $" { 210 pass "list line 1 with listsize 3" 211 } 212 -re "1\[ \t\]+#include \"list0.h\"\r\n$prompt $" { 213 fail "list line 1 with listsize 3" 214 } 215 -re ".*$prompt $" { 216 fail "list line 1 with listsize 3" 217 } 218 timeout { 219 fail "list line 1 with listsize 3 (timeout)" 220 } 221 } 222 223 setup_xfail "*-*-*" 224 send "list 2\n" 225 expect { 226 -re "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+main \[)(\]+\r\n$prompt $" { 227 pass "list line 2 with listsize 3" 228 } 229 -re "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+\r\n$prompt $" { 230 fail "list line 2 with listsize 3" 231 } 232 -re ".*$prompt $" { 233 fail "list line 2 with listsize 3" 234 } 235 timeout { 236 fail "list line 2 with listsize 3 (timeout)" 237 } 238 } 239 240 setup_xfail "*-*-*" 241 send "list 3\n" 242 expect { 243 -re "2\[ \t\]+\r\n3\[ \t\]+main \[(\]+\[)\]+\r\n4\[ \t\]+\{\r\n$prompt $" { 244 pass "list line 3 with listsize 3" 245 } 246 -re "2\[ \t\]+\r\n3\[ \t\]+main \[)(\]+\r\n$prompt $" { 247 fail "list line 3 with listsize 3" 248 } 249 -re ".*$prompt $" { 250 fail "list line 3 with listsize 3" 251 } 252 timeout { 253 fail "list line 3 with listsize 3 (timeout)" 254 } 255 } 256 } 257 258 # Try small listsize > 2 that is an even number. 259 260 if [ set_listsize 4 ] then { 261 send "list 1\n" 262 expect { 263 -re "1\[ \t\]+#include \"list0.h\"\r\n2\[ \t\]+\r\n$prompt $" { 264 pass "list line 1 with listsize 4" 265 } 266 -re ".*$prompt $" { 267 fail "list line 1 with listsize 4" 268 } 269 timeout { 270 fail "list line 1 with listsize 4 (timeout)" 271 } 272 } 273 274 send "list 2\n" 275 expect { 276 -re "1\[ \t\]+#include \"list0.h\".*3\[ \t\]+main \[)(\]+\r\n$prompt $" { 277 pass "list line 2 with listsize 4" 278 } 279 -re ".*$prompt $" { 280 fail "list line 2 with listsize 4" 281 } 282 timeout { 283 fail "list line 2 with listsize 4 (timeout)" 284 } 285 } 286 287 send "list 3\n" 288 expect { 289 -re "1\[ \t\]+#include \"list0.h\".*4\[ \t\]+\{\r\n$prompt $" { 290 pass "list line 3 with listsize 4" 291 } 292 -re ".*$prompt $" { 293 fail "list line 3 with listsize 4" 294 } 295 timeout { 296 fail "list line 3 with listsize 4 (timeout)" 297 } 298 } 299 300 send "list 4\n" 301 expect { 302 -re "2\[ \t\]+\r\n.*5\[ \t\]+int x;\r\n$prompt $" { 303 pass "list line 4 with listsize 4" 304 } 305 -re ".*$prompt $" { 306 fail "list line 4 with listsize 4" 307 } 308 timeout { 309 fail "list line 4 with listsize 4 (timeout)" 310 } 311 } 312 } 313 314 # Try a size larger than the entire file. 315 316 if [ set_listsize 100 ] then { 317 send "list 1\n" 318 expect { 319 -re "1\[ \t\]+#include \"list0.h\".*\r\n42\[ \t\]+\}\r\n$prompt $" { 320 pass "list line 1 with listsize 100" 321 } 322 -re ".*$prompt $" { 323 fail "list line 1 with listsize 100" 324 } 325 timeout { 326 fail "list line 1 with listsize 100 (timeout)" 327 } 328 } 329 330 send "list 10\n" 331 expect { 332 -re "1\[ \t\]+#include \"list0.h\".*\r\n42\[ \t\]+\}\r\n$prompt $" { 333 pass "list line 10 with listsize 100" 334 } 335 -re ".*$prompt $" { 336 fail "list line 10 with listsize 100" 337 } 338 timeout { 339 fail "list line 10 with listsize 100 (timeout)" 340 } 341 } 342 } 343 344 # Try listsize of 0 which suppresses printing. 345 346 send "set listsize 0\n" 347 expect { 348 -re "set listsize 0\[\r\n\]+$prompt $" { 349 setup_xfail "*-*-*" 350 send "show listsize\n" 351 expect { 352 -re "Number of source lines .* is 0.\r\n.*$prompt $" { 353 pass "listsize of 0 displays as 0" 354 } 355 -re "Number of source lines .* is unlimited.\r\n.*$prompt $" { 356 fail "listsize of 0 displays as unlimited" 357 } 358 -re ".*$prompt $" { 359 fail "listsize not set to unlimited (0)" 360 } 361 timeout { 362 fail "show listsize (timeout)" 363 } 364 } 365 send "list 1\n" 366 expect { 367 -re "list 1\[\r\n\]+$prompt $" { 368 pass "listsize of 0 suppresses output" 369 } 370 -re ".*$prompt $" { 371 fail "listsize of 0 should suppress output" 372 } 373 timeout { 374 fail "listsize of 0 suppresses output (timeout)" 375 } 376 } 377 } 378 -re ".*$prompt $" { 379 fail "setting listsize to 0" 380 } 381 timeout { 382 fail "set listsize to 0 (timeout)" 383 } 384 } 385 386 # Try listsize of -1 which is special, and means unlimited. 387 388 send "set listsize -1\n" 389 expect { 390 -re "set listsize -1\[\r\n\]+$prompt $" { 391 send "show listsize\n" 392 expect { 393 -re "Number of source lines .* is unlimited.\r\n.*$prompt $" { 394 pass "listsize of -1 displays as unlimited" 395 } 396 -re ".*$prompt $" { 397 fail "listsize not set to unlimited (-1)" 398 } 399 timeout { 400 fail "show listsize (timeout)" 401 } 402 } 403 setup_xfail "*-*-*" 404 send "list 1\n" 405 expect { 406 -re "1\[ \t\]+#include .*\r\n39\[ \t\]+\}\r\n$prompt $" { 407 pass "list line 1 with unlimited listsize" 408 } 409 -re "list 1\[\r\n\]+$prompt $" { 410 fail "listsize of -1 (unlimited) suppresses output" 411 } 412 timeout { 413 fail "list line 1 with unlimited listsize (timeout)" 414 } 415 } 416 } 417 -re ".*$prompt $" { 418 fail "setting listsize to -1" 419 } 420 timeout { 421 fail "set listsize to -1 (timeout)" 422 } 423 } 424} 425 426# 427# Test "list filename:number" for C include file 428# 429 430proc test_list_include_file {} { 431 global prompt 432 433 # FIXME Fails for COFF as well, I think. 434 setup_xfail "a29k-*-udi" 435 send "list list0.h:1\n" 436 expect { 437 -re "1\[ \t\]+/\[*\]+ An include file .*5\[ \t\]+foo \[(\]+x\[)\]+\r\n$prompt $" { 438 pass "list line 1 in include file" 439 } 440 -re "No source file named list0.h.\r\n$prompt $" { 441 fail "list line 1 in include file" 442 } 443 -re ".*$prompt $" { 444 fail "list line 1 in include file" 445 } 446 timeout { 447 fail "list line 1 in include file (timeout)" 448 } 449 } 450 451 # FIXME Fails for COFF as well, I think. 452 setup_xfail "a29k-*-udi" 453 send "list list0.h:100\n" 454 expect { 455 -re "Line number 95 out of range; .*list0.h has 36 lines.\r\n$prompt $" { 456 pass "list message for lines past EOF" 457 } 458 -re "No source file named list0.h.\r\n$prompt $" { 459 fail "list message for lines past EOF" 460 } 461 -re ".*$prompt $" { 462 fail "list message for lines past EOF" 463 } 464 timeout { 465 fail "list message for lines past EOF (timeout)" 466 } 467 } 468} 469 470# 471# Test "list filename:number" for C source file 472# 473 474proc test_list_filename_and_number {} { 475 global prompt 476 477 set testcnt 0 478 479 send "list list0.c:1\n" 480 expect { 481 -re "1\[ \t\]+#include \"list0.h\".*5\[ \t\]+int x;\r\n$prompt $" { 482 incr testcnt 483 } 484 -re ".*$prompt $" { fail "list list0.c:1" ; return } 485 timeout { fail "list list0.c:1 (timeout)" ; return } 486 } 487 send "list list0.c:10\n" 488 expect { 489 -re "5\[ \t\]+int x;.*14\[ \t\]+foo .x\[+)\]+;\r\n$prompt $" { 490 incr testcnt 491 } 492 -re ".*$prompt $" { fail "list list.c:10" ; return } 493 timeout { fail "list list.c:10 (timeout)" ; return } 494 } 495 send "list list1.c:1\n" 496 expect { 497 -re "1\[ \t\]+void.*5\[ \t\]+printf \[(\]+.*\[)\]+;\r\n$prompt $" { 498 incr testcnt 499 } 500 -re ".*$prompt $" { fail "list list1.c:1" ; return } 501 timeout { fail "list list1.c:1 (timeout)" ; return } 502 } 503 send "list list1.c:12\n" 504 expect { 505 -re "7\[ \t\]+long_line \[(\]+.*\[)\]+;.*14\[ \t\]+\}\r\n.*$prompt $" { 506 incr testcnt 507 } 508 -re ".*$prompt $" { fail "list list1.c:12" ; return } 509 timeout { fail "list list1.c:12 (timeout)" ; return } 510 } 511 pass "list filename:number ($testcnt tests)" 512} 513 514# 515# Test "list function" for C source file 516# 517 518proc test_list_function {} { 519 global prompt 520 global gcc_compiled 521 522 # gcc appears to generate incorrect debugging information for code 523 # in include files, which breaks this test. 524 # SunPRO cc is the second case below, it's also correct. 525 setup_xfail "a29k-*-udi" 526 send "list main\n" 527 expect { 528 -re "1\[ \t\]+#include .*8\[ \t\]+breakpoint\[(\]\[)\]+;\r\n$prompt $" { 529 pass "list function in source file 1" 530 } 531 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$prompt $" { 532 pass "list function in source file 1" 533 } 534 -re ".*$prompt $" { fail "list main" ; return } 535 timeout { fail "list main (timeout)" ; return } 536 } 537 538 # Ultrix gdb takes the second case below; it's also correct. 539 # SunPRO cc is the third case. 540 send "list bar\n" 541 expect { 542 -re "1\[ \t\]+void.*8\[ \t\]+\}\r\n$prompt $" { 543 pass "list function in source file 2" 544 } 545 -re "1\[ \t\]+void.*7\[ \t\]*long_line ..;\r\n$prompt $" { 546 pass "list function in source file 2" 547 } 548 -re "1\[ \t\]+void.*7\[ \t\]*long_line ..;.*9\[ \t\]*\r\n$prompt $" { 549 pass "list function in source file 2" 550 } 551 -re ".*$prompt $" { fail "list bar" ; return } 552 timeout { fail "list bar (timeout)" ; return } 553 } 554 555 # Test "list function" for C include file 556 # Ultrix gdb is the second case, still correct. 557 # SunPRO cc is the third case. 558 setup_xfail "powerpc-*-*" 559 send "list foo\n" 560 expect { 561 -re "2\[ \t\]+including file.*11\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$prompt $" { 562 pass "list function in include file" 563 } 564 -re "1\[ \t\]+/. An include file.*10\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$prompt $" { 565 pass "list function in include file" 566 } 567 -re "3\[ \t\]+.*12\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$prompt $" { 568 pass "list function in include file" 569 } 570 -re ".*main \[)(\]+.*$prompt $" { 571 fail "list function in include file" 572 } 573 -re ".*$prompt $" { fail "list foo (in include file)" ; return } 574 timeout { fail "list foo (timeout)" ; return } 575 } 576} 577 578proc test_list_forward {} { 579 global prompt 580 581 set testcnt 0 582 583 send "list list0.c:10\n" 584 expect { 585 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$prompt $" { incr testcnt } 586 -re ".*$prompt $" { fail "list list0.c:10" ; return } 587 timeout { fail "list list0.c:10 (timeout)" ; return } 588 } 589 590 send "list\n" 591 expect { 592 -re "15\[ \t\]+foo \[(\]+.*\[)\]+;.*24\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$prompt $" { incr testcnt } 593 -re ".*$prompt $" { fail "list 15-24" ; return } 594 timeout { fail "list 15-24 (timeout)" ; return } 595 } 596 597 send "list\n" 598 expect { 599 -re "25\[ \t\]+foo \[(\]+.*\[)\]+;.*34\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$prompt $" { incr testcnt } 600 -re ".*$prompt $" { fail "list 25-34" ; return } 601 timeout { fail "list 25-34 (timeout)" ; return } 602 } 603 604 send "list\n" 605 expect { 606 -re "35\[ \t\]+foo \[(\]+.*\[)\]+;.*42\[ \t\]+\}\r\n$prompt $" { incr testcnt } 607 -re ".*$prompt $" { fail "list 35-42" ; return } 608 timeout { fail "list 35-42 (timeout)" ; return } 609 } 610 611 pass "successive list commands to page forward ($testcnt tests)" 612} 613 614proc test_list_backwards {} { 615 global prompt 616 617 set testcnt 0 618 619 send "list list0.c:33\n" 620 expect { 621 -re "28\[ \t\]+foo \[(\]+.*\[)\]+;.*37\[ \t\]+\r\n$prompt $" { incr testcnt } 622 -re ".*$prompt $" { fail "list list0.c:33" ; return } 623 timeout { fail "list list0.c:33 (timeout)" ; return } 624 } 625 626 send "list -\n" 627 expect { 628 -re "18\[ \t\]+foo \[(\]+.*\[)\]+;.*27\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$prompt $" { incr testcnt } 629 -re ".*$prompt $" { fail "list 18-27" ; return } 630 timeout { fail "list 18-27 (timeout)" ; return } 631 } 632 633 send "list -\n" 634 expect { 635 -re "8\[ \t\]+breakpoint\[(\]\[)\];.*17\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$prompt $" { incr testcnt } 636 -re ".*$prompt $" { fail "list 8-17" ; return } 637 timeout { fail "list 8-17 (timeout)" ; return } 638 } 639 640 send "list -\n" 641 expect { 642 -re "1\[ \t\]+#include .*7\[ \t\]+set_debug_traps\[(\]\[)\]+;\r\n$prompt $" { incr testcnt } 643 -re ".*$prompt $" { fail "list 1-7" ; return } 644 timeout { fail "list 1-7 (timeout)" ; return } 645 } 646 647 pass "$testcnt successive \"list -\" commands to page backwards" 648} 649 650# 651# Test "list first,last" 652# 653 654proc test_list_range {} { 655 global prompt 656 657 send "list list0.c:2,list0.c:5\n" 658 expect { 659 -re "2\[ \t\]+\r\n3\[ \t\]+main \[)(\]+.*5\[ \t\]+int x;\r\n$prompt $" { 660 pass "list range; filename:line1,filename:line2" 661 } 662 -re ".*$prompt $" { fail "list list0.c:2,list0.c:5" } 663 timeout { fail "list list0.c:2,list0.c:5 (timeout)" } 664 } 665 666 send "list 2,5\n" 667 expect { 668 -re "2\[ \t\]+\r\n3\[ \t\]+main \[)(\]+.*5\[ \t\]+int x;\r\n$prompt $" { 669 pass "list range; line1,line2" 670 } 671 -re ".*$prompt $" { fail "list 2,5" } 672 timeout { fail "list 2,5 (timeout)" } 673 } 674 675 #send "list -1,6\n" 676 #expect { 677 #-re "Line number 0 out of range; .*list0.c has 39 lines.\r\n$prompt $" { 678 #pass "list range; lower bound negative" 679 #} 680 #-re ".*$prompt $" { fail "list -1,6" } 681 #timeout { fail "list -1,6 (timeout)" } 682 #} 683 684 #send "list -100,-40\n" 685 #expect { 686 #-re "Line number -60 out of range; .*list0.c has 39 lines.\r\n$prompt $" { 687 #pass "list range; both bounds negative" 688 #} 689 #-re ".*$prompt $" { fail "-100,-40" } 690 #timeout { fail "-100,-40 (timeout)" } 691 #} 692 693 send "list 30,43\n" 694 expect { 695 -re "30\[ \t\]+foo \[(\]+.*\[)\]+;.*42\[ \t\]+\}\r\n$prompt $" { 696 pass "list range; upper bound past EOF" 697 } 698 -re ".*$prompt $" { fail "list 30,43" } 699 timeout { fail "list 30,43 (timeout)" } 700 } 701 702 send "list 43,100\n" 703 expect { 704 -re "Line number 43 out of range; .*list0.c has 42 lines.\r\n$prompt $" { 705 pass "list range; both bounds past EOF" 706 } 707 -re ".*$prompt $" { fail "43,100" } 708 timeout { fail "43,100 (timeout)" } 709 } 710 711 send "list list0.c:2,list1.c:17\n" 712 expect { 713 -re "Specified start and end are in different files.\r\n$prompt $" { 714 pass "list range, must be same files" 715 } 716 -re ".*$prompt $" { fail "list0.c:2,list1.c:17" } 717 timeout { fail "list0.c:2,list1.c:17 (timeout)" } 718 } 719} 720 721# 722# Test "list filename:function" 723# 724 725proc test_list_filename_and_function {} { 726 global prompt 727 728 set testcnt 0 729 730 # gcc appears to generate incorrect debugging information for code 731 # in include files, which breaks this test. 732 # SunPRO cc is the second case below, it's also correct. 733 setup_xfail "a29k-*-udi" 734 send "list list0.c:main\n" 735 expect { 736 -re "1\[ \t\]+#include .*8\[ \t\]+breakpoint\[(\]\[)\]+;\r\n$prompt $" { 737 incr testcnt 738 } 739 -re "5\[ \t\]+int x;.*14\[ \t\]+foo \[(\]+.*\[)\]+;\r\n$prompt $" { 740 pass "list function in source file 1" 741 } 742 -re ".*$prompt $" { fail "list list0.c:main" } 743 timeout { fail "list list0.c:main (timeout)" } 744 } 745 746 # The i960 and a29k-amd-udi are the second case 747 748 # Not sure what the point of having this function be unused is. 749 # AIX is legitimately removing it. 750 setup_xfail "rs6000-*-aix*" 751 send "list list0.c:unused\n" 752 expect { 753 -re "36\[ \t\]+\}.*42\[ \t\]+\}\r\n$prompt $" { 754 incr testcnt 755 } 756 -re "37.*42\[ \t\]+\}\r\n$prompt $" { 757 incr testcnt 758 } 759 -re ".*$prompt $" { fail "list list0.c:unused" } 760 timeout { fail "list list0.c:unused (timeout)" } 761 } 762 clear_xfail "rs6000-*-aix*" 763 764 # gcc appears to generate incorrect debugging information for code 765 # in include files, which breaks this test. 766 # Ultrix gdb is the second case, one line different but still correct. 767 # SunPRO cc is the third case. 768 setup_xfail "rs6000-*-*" 1804 769 setup_xfail "powerpc-*-*" 1804 770 # FIXME Fails for COFF as well, I think. 771 setup_xfail "a29k-*-udi" 772 send "list list0.h:foo\n" 773 expect { 774 -re "2\[ \t\]+including file. This.*11\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$prompt $" { 775 incr testcnt 776 } 777 -re "1\[ \t\]+/. An include file.*10\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$prompt $" { 778 incr testcnt 779 } 780 -re "3\[ \t\]+.*12\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$prompt $" { 781 incr testcnt 782 } 783 -re "No source file named list0.h.\r\n$prompt $" { 784 fail "list list0.h:foo" 785 } 786 -re ".*$prompt $" { fail "list list0.h:foo" } 787 timeout { fail "list list0.h:foo (timeout)" } 788 } 789 790 # Ultrix gdb is the second case. 791 # a29k-amd-udi is the third case. 792 send "list list1.c:bar\n" 793 expect { 794 -re "1\[ \t\]+void.*8\[ \t\]+\}\r\n$prompt $" { 795 incr testcnt 796 } 797 -re "1\[ \t\]+void.*7\[ \t\]*long_line ..;\r\n$prompt $" { 798 incr testcnt 799 } 800 -re "1\[ \t\]+void.*9\[ \t\]*\r\n$prompt $" { 801 incr testcnt 802 } 803 -re ".*$prompt $" { fail "list list1.c:bar" } 804 timeout { fail "list list1.c:bar (timeout)" } 805 } 806 807 # The i960 and a29k-amd-udi are the second case 808 809 # Not sure what the point of having this function be unused is. 810 # AIX is legitimately removing it. 811 setup_xfail "rs6000-*-aix*" 812 send "list list1.c:unused\n" 813 expect { 814 -re "7\[ \t\]+long_line \[(\]\[)\];.*14\[ \t\]+\}\r\n.*$prompt $" { 815 incr testcnt 816 } 817 -re "9.*14\[ \t\]+\}\r\n.*$prompt $" { 818 incr testcnt 819 } 820 -re ".*$prompt $" { fail "list list1.c:unused" } 821 timeout { fail "list list1.c:unused (timeout)" } 822 } 823 clear_xfail "rs6000-*-aix*" 824 825 pass "list filename:function ($testcnt tests)" 826 827 # Test some invalid specs 828 # The following test takes the FIXME result on most systems using 829 # DWARF. It fails to notice that main() is not in the file requested. 830 831 setup_xfail "*-*-*" 832 833# Does this actually work ANYWHERE? I believe not, as this is an `aspect' of 834# lookup_symbol(), where, when it is given a specific symtab which does not 835# contain the requested symbol, it will subsequently search all of the symtabs 836# for the requested symbol. 837 838 send "list list0.c:foo\n" 839 expect { 840 -re "Function \"foo\" not defined in .*list0.c\r\n$prompt $" { 841 pass "list filename:function; wrong filename rejected" 842 } 843 -re "2\[ \t\]+including file.*11\[ \t\]+bar \[(\]+.*\[)\]+;\r\n$prompt $" { 844 fail "list filename:function; wrong filename not rejected" 845 } 846 -re ".*main \[)(\]+.*$prompt $" { 847 fail "list filename:function; wrong filename not rejected" 848 } 849 -re ".*$prompt $" { 850 fail "list filename:function; wrong filename not rejected" 851 } 852 timeout { 853 fail "list filename:function; wrong filename (timeout)" 854 } 855 } 856 857 send "list foobar.c:main\n" 858 expect { 859 -re "No source file named foobar.c.\r\n$prompt $" { 860 pass "list filename:function; nonexistant file" 861 } 862 -re ".*$prompt $" { 863 fail "list filename:function; nonexistant file" 864 } 865 timeout { 866 fail "list filename:function; nonexistant file (timeout)" 867 } 868 } 869 870 send "list list0.h:foobar\n" 871 expect { 872 -re "Function \"foobar\" not defined.\r\n$prompt $" { 873 pass "list filename:function; nonexistant function" 874 } 875 -re "No source file named list0.h.\r\n$prompt $" { 876 fail "list filename:function; nonexistant function" 877 } 878 -re ".*$prompt $" { 879 fail "list filename:function; nonexistant function" 880 } 881 timeout { 882 fail "list filename:function; nonexistant function (timeout)" 883 } 884 } 885 886} 887 888proc test_forward_search {} { 889 global timeout 890 891 gdb_test "set listsize 4" "" 892 # On SunOS4, this gives us lines 19-22. On AIX, it gives us 893 # lines 20-23. This depends on whether the line number of a function 894 # is considered to be the openbrace or the first statement--either one 895 # is acceptable. 896 gdb_test "list long_line" "20\[ \t\]+long_line .*" 897 898 gdb_test "search 4321" " not found" 899 900 gdb_test "search 6789" "24\[ \t\]+oof .6789.;" 901 902 # Test that GDB won't crash if the line being searched is extremely long. 903 904 set oldtimeout $timeout 905 set timeout [expr "$timeout + 300"] 906 verbose "Timeout is now $timeout seconds" 2 907 match_max 10000 908 gdb_test "search 1234" ".*1234.*" "search extremely long line (> 5000 chars)" 909 set timeout $oldtimeout 910 verbose "Timeout is now $timeout seconds" 2 911} 912 913# Start with a fresh gdb. 914 915gdb_exit 916gdb_start 917gdb_reinitialize_dir $srcdir/$subdir 918gdb_load ${binfile} 919 920if $usestubs { 921 send "step\n" 922 # if use stubs step out of the breakpoint() function. 923 expect { 924 -re "main.* at .*$prompt $" {} 925 timeout { fail "single step at breakpoint() (timeout)" ; return 0 } 926 } 927} 928 929send "set width 0\n" 930expect -re "$prompt $" 931 932test_listsize 933if [ set_listsize 10 ] then { 934 test_list_include_file 935 test_list_filename_and_number 936 test_list_function 937 test_list_forward 938 test_list_backwards 939 test_list_range 940 test_list_filename_and_function 941 test_forward_search 942} 943