1# Copyright (C) 1992, 1994 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 "scope" 30set binfile ${objdir}/${subdir}/${testfile} 31if { [compile "-g -c ${srcdir}/${subdir}/scope0.c"] != "" } { 32 perror "Couldn't compile scope0.c to object" 33 return -1 34} 35execute_anywhere "mv scope0.o ${binfile}0.o" 36if { [compile "-g -c ${srcdir}/${subdir}/scope1.c"] != "" } { 37 perror "Couldn't compile scope1.c to object" 38 return -1 39} 40execute_anywhere "mv scope1.o ${binfile}1.o" 41if { [compile "${objdir}/${subdir}/scope0.o ${objdir}/${subdir}/scope1.o -o ${binfile}"] != "" } { 42 perror "Couldn't link scope." 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# Test locating various things when stopped just inside main, after 56# running init(). To prevent cascading of errors, we report the 57# first one and quit. If all pass, then we print the pass results. 58 59proc test_at_main {} { 60 global prompt 61 global decimal 62 global det_file 63 global srcdir 64 global subdir 65 global gcc_compiled 66 67 # skip past init. There may be a call to __main at the start of 68 # main, so the first next may only get us to the init call. 69 send "next\n" 70 expect { 71 -re "$decimal.*foo \\(\\);\r\n$prompt $" { 72 pass "next over init() in main" 73 } 74 -re "$decimal.*init \\(\\);\r\n$prompt $"\ 75 { send "next\n" ; exp_continue } 76 -re "$prompt $" { fail "next over init() in main" ; return } 77 timeout { fail "(timeout) next over init() in main" ; return } 78 } 79 80 # Print scope0.c::filelocal, which is 1 81 82 send "print filelocal\n" 83 expect { 84 -re "\\\$$decimal = 1\r\n$prompt $" { pass "print filelocal" } 85 -re "$prompt $" { fail "print filelocal" ; return } 86 timeout { 87 fail "(timeout) print filelocal" ; return 88 } 89 } 90 91 send "print 'scope0.c'::filelocal\n" 92 expect { 93 -re "\\\$$decimal = 1\r\n$prompt $" { 94 pass "print 'scope0.c'::filelocal at main" 95 } 96 -re "No symbol \"scope0.c\" in current context.*$prompt $" { 97 send "print '$srcdir/$subdir/scope0.c'::filelocal\n" 98 exp_continue 99 } 100 -re "$prompt $" { fail "print 'scope0.c'::filelocal at main" ; return } 101 timeout { 102 fail "(timeout) print 'scope0.c'::filelocal at main" ; return 103 } 104 } 105 106 # Print scope0.c::filelocal_bss, which is 101 107 108 send "print filelocal_bss\n" 109 expect { 110 -re "\\\$$decimal = 101\r\n$prompt $" { 111 pass "print filelocal_bss" 112 } 113 -re "$prompt $" { fail "print filelocal_bss" ; return } 114 timeout { 115 fail "(timeout) print filelocal_bss" ; return 116 } 117 } 118 119 send "print 'scope0.c'::filelocal_bss\n" 120 expect { 121 -re "\\\$$decimal = 101\r\n$prompt $" { 122 pass "print 'scope0.c'::filelocal_bss in test_at_main" 123 } 124 -re "No symbol \"scope0.c\" in current context.*$prompt $" { 125 send "print '$srcdir/$subdir/scope0.c'::filelocal_bss\n" 126 exp_continue 127 } 128 -re "$prompt $" { 129 fail "print 'scope0.c'::filelocal_bss in test_at_main" ; return 130 } 131 timeout { 132 fail "(timeout) print 'scope0.c'::filelocal_bss in test_at_main" 133 return 134 } 135 } 136 137 # Print scope0.c::filelocal_ro, which is 201 138 139 # No clue why the powerpc fails this test. 140 setup_xfail "powerpc-*-*" 141 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 142 send "print filelocal_ro\n" 143 expect { 144 -re "\\\$$decimal = 201\r\n$prompt $" { 145 pass "print filelocal_ro in test_at_main" 146 } 147 -re "$prompt $" { 148 fail "print filelocal_ro in test_at_main" 149 return 150 } 151 timeout { 152 fail "(timeout) print filelocal_ro in test_at_main" 153 return 154 } 155 } 156 157 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 158 setup_xfail "powerpc-*-*" 159 send "print 'scope0.c'::filelocal_ro\n" 160 expect { 161 -re "\\\$$decimal = 201\r\n$prompt $" { 162 pass "print 'scope0.c'::filelocal_ro" 163 } 164 -re "No symbol \"scope0.c\" in current context.*$prompt $" { 165 send "print '$srcdir/$subdir/scope0.c'::filelocal_ro\n" 166 exp_continue 167 } 168 -re "$prompt $" { fail "print 'scope0.c'::filelocal_ro" ; return } 169 timeout { 170 fail "(timeout) print 'scope0.c'::filelocal_ro" ; return 171 } 172 } 173 174 # Print scope1.c::filelocal, which is 2 175 176 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 177 send "print 'scope1.c'::filelocal\n" 178 expect { 179 -re "\\\$$decimal = 2\r\n$prompt $" { 180 pass "print 'scope1.c'::filelocal" 181 } 182 -re "No symbol \"scope1.c\" in current context.*$prompt $" { 183 send "print '$srcdir/$subdir/scope1.c'::filelocal\n" 184 exp_continue 185 } 186 -re "$prompt $" { fail "print 'scope1.c'::filelocal" ; return } 187 timeout { 188 fail "(timeout) print 'scope1.c'::filelocal" ; return 189 } 190 } 191 192 # Print scope1.c::filelocal_bss, which is 102 193 194 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 195 send "print 'scope1.c'::filelocal_bss\n" 196 expect { 197 -re "\\\$$decimal = 102\r\n$prompt $" { 198 pass "print 'scope1.c'::filelocal_bss" 199 } 200 -re "No symbol \"scope1.c\" in current context.*$prompt $" { 201 send "print '$srcdir/$subdir/scope1.c'::filelocal_bss\n" 202 exp_continue 203 } 204 -re "$prompt $" { fail "print 'scope1.c'::filelocal_bss" ; return } 205 timeout { 206 fail "(timeout) print 'scope1.c'::filelocal_bss" ; return 207 } 208 } 209 210 # Print scope1.c::filelocal_ro, which is 202 211 212 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 213 send "print 'scope1.c'::filelocal_ro\n" 214 expect { 215 -re "\\\$$decimal = 202\r\n$prompt $" { 216 pass "print 'scope1.c'::filelocal_ro" 217 } 218 -re "No symbol \"scope1.c\" in current context.*$prompt $" { 219 send "print '$srcdir/$subdir/scope1.c'::filelocal_ro\n" 220 exp_continue 221 } 222 -re "$prompt " {fail "print 'scope1.c'::filelocal_ro" ; return } 223 timeout { 224 fail "(timeout) print 'scope1.c'::filelocal_ro" ; return 225 } 226 } 227 228 # Print scope1.c::foo::funclocal, which is 3 229 230 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" } 231 send "print foo::funclocal\n" 232 expect { 233 -re "\\\$$decimal = 3\r\n$prompt $" { pass "print foo::funclocal" } 234 -re "$prompt $" { fail "print foo::funclocal" ; return } 235 timeout { 236 fail "(timeout) print foo::funclocal" ; return 237 } 238 } 239 240 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 241 send "print 'scope1.c'::foo::funclocal\n" 242 expect { 243 -re "\\\$$decimal = 3\r\n$prompt $" { 244 pass "print 'scope1.c'::foo::funclocal" 245 } 246 -re "No symbol \"scope1.c\" in current context.*$prompt $" { 247 send "print '$srcdir/$subdir/scope1.c'::foo::funclocal\n" 248 exp_continue 249 } 250 -re "$prompt $" { fail "print 'scope1.c'::foo::funclocal" ; return } 251 timeout { 252 fail "(timeout) print 'scope1.c'::foo::funclocal" ; return 253 } 254 } 255 256 # Print scope1.c::foo::funclocal_ro, which is 203 257 258 send "print foo::funclocal_ro\n" 259 expect { 260 -re "\\\$$decimal = 203\r\n$prompt $" { 261 pass "print foo::funclocal_ro" 262 } 263 -re "$prompt $" { fail "print foo::funclocal_ro" ; return } 264 timeout { 265 fail "(timeout) print foo::funclocal_ro" ; return 266 } 267 } 268 269 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 270 send "print 'scope1.c'::foo::funclocal_ro\n" 271 expect { 272 -re "\\\$$decimal = 203\r\n$prompt $" { 273 pass "print 'scope1.c'::foo::funclocal_ro" } 274 -re "No symbol \"scope1.c\" in current context.*$prompt $" { 275 send "print '$srcdir/$subdir/scope1.c'::foo::funclocal_ro\n" 276 exp_continue 277 } 278 -re "$prompt $" { fail "print 'scope1.c'::foo::funclocal_ro" ; return } 279 timeout { 280 fail "(timeout) print 'scope1.c'::foo::funclocal_ro" ; return 281 } 282 } 283 284 # Print scope1.c::bar::funclocal, which is 4 285 286 send "print bar::funclocal\n" 287 expect { 288 -re "\\\$$decimal = 4\r\n$prompt $" { pass "print bar::funclocal" } 289 -re "$prompt $" { fail "print bar::funclocal" ; return } 290 timeout { 291 fail "(timeout) print bar::funclocal" ; return 292 } 293 } 294 295 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 296 send "print 'scope1.c'::bar::funclocal\n" 297 expect { 298 -re "\\\$$decimal = 4\r\n$prompt $" { 299 pass "print 'scope1.c'::bar::funclocal" 300 } 301 -re "No symbol \"scope1.c\" in current context.*$prompt $" { 302 send "print '$srcdir/$subdir/scope1.c'::bar::funclocal\n" 303 exp_continue 304 } 305 -re "$prompt $" { fail "print 'scope1.c'::bar::funclocal" ; return } 306 timeout { 307 fail "(timeout) print 'scope1.c'::bar::funclocal" ; return 308 } 309 } 310} 311 312proc test_at_foo {} { 313 global prompt 314 global decimal 315 global det_file 316 global srcdir 317 global subdir 318 global gcc_compiled 319 320 send "next\n" 321 expect { 322 -re ".*bar \\(\\);\r\n$prompt $" {} 323 -re "$prompt $" { fail "continue to foo()" ; return } 324 timeout { fail "(timeout) continue to foo()" ; return } 325 } 326 327 # Print scope0.c::filelocal, which is 1 328 329 send "print 'scope0.c'::filelocal\n" 330 expect { 331 -re "\\\$$decimal = 1\r\n$prompt $" { 332 pass "print 'scope0.c'::filelocal at foo" 333 } 334 -re "No symbol \"scope0.c\" in current context.*$prompt $" { 335 send "print '$srcdir/$subdir/scope0.c'::filelocal\n" 336 exp_continue 337 } 338 -re "$prompt $" { fail "print 'scope0.c'::filelocal at foo" ; return } 339 timeout { 340 fail "(timeout) print 'scope0.c'::filelocal at foo" ; return 341 } 342 } 343 344 # Print scope0.c::filelocal_bss, which is 101 345 346 send "print 'scope0.c'::filelocal_bss\n" 347 expect { 348 -re "\\\$$decimal = 101\r\n$prompt $" { 349 pass "print 'scope0.c'::filelocal_bss in test_at_foo" 350 } 351 -re "No symbol \"scope0.c\" in current context.*$prompt $" { 352 send "print '$srcdir/$subdir/scope0.c'::filelocal_bss\n" 353 exp_continue 354 } 355 -re "$prompt $" { 356 fail "print 'scope0.c'::filelocal_bss in test_at_foo" 357 return 358 } 359 timeout { 360 fail "(timeout) print 'scope0.c'::filelocal_bss in test_at_foo" 361 return 362 } 363 } 364 365 # Print scope0.c::filelocal_ro, which is 201 366 367 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 368 setup_xfail "powerpc-*-*" 369 send "print 'scope0.c'::filelocal_ro\n" 370 expect { 371 -re "\\\$$decimal = 201\r\n$prompt $" { pass "print 'scope0.c'::filelocal_ro" } 372 -re "No symbol \"scope0.c\" in current context.*$prompt $" { 373 send "print '$srcdir/$subdir/scope0.c'::filelocal_ro\n" 374 exp_continue 375 } 376 -re "$prompt $" { fail "print 'scope0.c'::filelocal_ro" ; return } 377 timeout { 378 fail "(timeout) print 'scope0.c'::filelocal_ro" ; return 379 } 380 } 381 382 gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at foo" 383 384 # Print scope1.c::filelocal, which is 2 385 386 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 387 send "print 'scope1.c'::filelocal\n" 388 expect { 389 -re "\\\$$decimal = 2\r\n$prompt $" { 390 pass "print 'scope1.c'::filelocal at foo" 391 } 392 -re "No symbol \"scope1.c\" in current context.*$prompt $" { 393 send "print '$srcdir/$subdir/scope1.c'::filelocal\n" 394 exp_continue 395 } 396 -re "$prompt $" { fail "print 'scope1.c'::filelocal at foo" ; return } 397 timeout { 398 fail "(timeout) print 'scope1.c'::filelocal at foo" ; return 399 } 400 } 401 402 gdb_test "print filelocal_bss" "\\\$$decimal = 102" \ 403 "print filelocal_bss at foo" 404 405 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 406 send "print 'scope1.c'::filelocal_bss\n" 407 expect { 408 -re "\\\$$decimal = 102\r\n$prompt $" { 409 pass "print 'scope1.c'::filelocal_bss at foo" 410 } 411 -re "No symbol \"scope1.c\" in current context.*$prompt $" { 412 send "print '$srcdir/$subdir/scope1.c'::filelocal_bss\n" 413 exp_continue 414 } 415 -re "$prompt $" { fail "print 'scope1.c'::filelocal_bss at foo" } 416 timeout { 417 fail "(timeout) print 'scope1.c'::filelocal_bss at foo" 418 } 419 } 420 421 gdb_test "print filelocal_ro" "\\\$$decimal = 202" \ 422 "print filelocal_ro at foo" 423 424 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 425 send "print 'scope1.c'::filelocal_ro\n" 426 expect { 427 -re "\\\$$decimal = 202\r\n$prompt $" { pass "print 'scope1.c'::filelocal_ro at foo" } 428 -re "No symbol \"scope1.c\" in current context.*$prompt $" { 429 send "print '$srcdir/$subdir/scope1.c'::filelocal_ro\n" 430 exp_continue 431 } 432 -re "$prompt $" { fail "print 'scope1.c'::filelocal_ro at foo" } 433 timeout { 434 fail "(timeout) print 'scope1.c'::filelocal_ro at foo" 435 } 436 } 437 438 # Print scope1.c::foo::funclocal, which is 3 439 440 gdb_test "print funclocal" "\\\$$decimal = 3" "print funclocal at foo" 441 442 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" } 443 gdb_test "print foo::funclocal" "\\\$$decimal = 3" \ 444 "print foo::funclocal at foo" 445 446 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 447 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" } 448 send "print 'scope1.c'::foo::funclocal\n" 449 expect { 450 -re "\\\$$decimal = 3\r\n$prompt $" { 451 pass "print 'scope1.c'::foo::funclocal at foo" 452 } 453 -re "No symbol \"scope1.c\" in current context.*$prompt $" { 454 send "print '$srcdir/$subdir/scope1.c'::foo::funclocal\n" 455 exp_continue 456 } 457 -re "$prompt $" { fail "print 'scope1.c'::foo::funclocal at foo" } 458 timeout { 459 fail "(timeout) print 'scope1.c'::foo::funclocal at foo" 460 } 461 } 462 463 # Print scope1.c::foo::funclocal_bss, which is 103 464 465 gdb_test "print funclocal_bss" "\\\$$decimal = 103" \ 466 "print funclocal_bss at foo" 467 468 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" } 469 gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" \ 470 "print foo::funclocal_bss at foo" 471 472 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 473 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" } 474 send "print 'scope1.c'::foo::funclocal_bss\n" 475 expect { 476 -re "\\\$$decimal = 103\r\n$prompt $" { 477 pass "print 'scope1.c'::foo::funclocal_bss at foo" 478 } 479 -re "No symbol \"scope1.c\" in current context.*$prompt $" { 480 send "print '$srcdir/$subdir/scope1.c'::foo::funclocal_bss\n" 481 exp_continue 482 } 483 -re "$prompt $" { 484 fail "print 'scope1.c'::foo::funclocal_bss at foo" 485 } 486 timeout { 487 fail "(timeout) print 'scope1.c'::foo::funclocal_bss at foo" 488 } 489 } 490 491 # Print scope1.c::foo::funclocal_ro, which is 203 492 493 gdb_test "print funclocal_ro" "\\\$$decimal = 203" \ 494 "print funclocal_ro at foo" 495 496 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" } 497 gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" \ 498 "print foo::funclocal_ro at foo" 499 500 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 501 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" } 502 send "print 'scope1.c'::foo::funclocal_ro\n" 503 expect { 504 -re "\\\$$decimal = 203\r\n$prompt $" { 505 pass "print 'scope1.c'::foo::funclocal_ro at foo" 506 } 507 -re "No symbol \"scope1.c\" in current context.*$prompt $" { 508 send "print '$srcdir/$subdir/scope1.c'::foo::funclocal_ro\n" 509 exp_continue 510 } 511 -re "$prompt $" { fail "print 'scope1.c'::foo::funclocal_ro at foo" } 512 timeout { 513 fail "(timeout) print 'scope1.c'::foo::funclocal_ro at foo" 514 } 515 } 516 517 # Print scope1.c::bar::funclocal, which is 4 518 519 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" } 520 gdb_test "print bar::funclocal" "\\\$$decimal = 4" \ 521 "print bar::funclocal at foo" 522 523 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 524 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" } 525 send "print 'scope1.c'::bar::funclocal\n" 526 expect { 527 -re "\\\$$decimal = 4\r\n$prompt $" { 528 pass "print 'scope1.c'::bar::funclocal at foo" 529 } 530 -re "No symbol \"scope1.c\" in current context.*$prompt $" { 531 send "print '$srcdir/$subdir/scope1.c'::bar::funclocal\n" 532 exp_continue 533 } 534 -re "$prompt $" { fail "print 'scope1.c'::bar::funclocal at foo" } 535 timeout { 536 fail "(timeout) print 'scope1.c'::bar::funclocal at foo" 537 } 538 } 539} 540 541proc test_at_bar {} { 542 global prompt 543 global decimal 544 global det_file 545 global srcdir 546 global subdir 547 global gcc_compiled 548 549 send "next\n" 550 expect { 551 -re ".*$prompt $" {} 552 timeout { fail "(timeout) next in bar()" ; return } 553 } 554 555 # Print scope0.c::filelocal, which is 1 556 557 send "print 'scope0.c'::filelocal\n" 558 expect { 559 -re "\\\$$decimal = 1\r\n$prompt $" { 560 pass "print 'scope0.c'::filelocal at bar" 561 } 562 -re "No symbol \"scope0.c\" in current context.*$prompt $" { 563 send "print '$srcdir/$subdir/scope0.c'::filelocal\n" 564 exp_continue 565 } 566 -re "$prompt $" { 567 fail "print 'scope0.c'::filelocal at bar" ; return 568 } 569 timeout { 570 fail "(timeout) print 'scope0.c'::filelocal at bar" ; return 571 } 572 } 573 574 # Print scope0.c::filelocal_bss, which is 101 575 576 send "print 'scope0.c'::filelocal_bss\n" 577 expect { 578 -re "\\\$$decimal = 101\r\n$prompt $" { 579 pass "print 'scope0.c'::filelocal_bss in test_at_bar" 580 } 581 -re "No symbol \"scope0.c\" in current context.*$prompt $" { 582 send "print '$srcdir/$subdir/scope0.c'::filelocal_bss\n" 583 exp_continue 584 } 585 -re "$prompt $" { 586 fail "print 'scope0.c'::filelocal_bss in test_at_bar" 587 return 588 } 589 timeout { 590 fail "(timeout) print 'scope0.c'::filelocal_bss in test_at_bar" 591 return 592 } 593 } 594 595 # Print scope0.c::filelocal_ro, which is 201 596 597 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 598 setup_xfail "powerpc-*-*" 599 send "print 'scope0.c'::filelocal_ro\n" 600 expect { 601 -re "\\\$$decimal = 201\r\n$prompt $" { 602 pass "print 'scope0.c'::filelocal_ro at bar" 603 } 604 -re "No symbol \"scope0.c\" in current context.*$prompt $" { 605 send "print '$srcdir/$subdir/scope0.c'::filelocal_ro\n" 606 exp_continue 607 } 608 -re "$prompt $" { 609 fail "print 'scope0.c'::filelocal_ro at bar" ; return 610 } 611 timeout { 612 fail "(timeout) print 'scope0.c'::filelocal_ro at bar" ; return 613 } 614 } 615 616 # Print scope1.c::filelocal, which is 2 617 618 send "print filelocal\n" 619 expect { 620 -re "\\\$$decimal = 2\r\n$prompt $" { 621 pass "print filelocal at bar" 622 } 623 -re "$prompt $" { 624 fail "print filelocal at bar" ; return 625 } 626 timeout { 627 fail "(timeout) print filelocal at bar" ; return 628 } 629 } 630 631 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 632 send "print 'scope1.c'::filelocal\n" 633 expect { 634 -re "\\\$$decimal = 2\r\n$prompt $" { 635 pass "print 'scope1.c'::filelocal at bar" 636 } 637 -re "No symbol \"scope1.c\" in current context.*$prompt $" { 638 send "print '$srcdir/$subdir/scope1.c'::filelocal\n" 639 exp_continue 640 } 641 -re "$prompt $" { 642 fail "print 'scope1.c'::filelocal at bar" ; return 643 } 644 timeout { 645 fail "(timeout) print 'scope1.c'::filelocal at bar" ; return 646 } 647 } 648 649 # Print scope1.c::filelocal_bss, which is 102 650 651 send "print filelocal_bss\n" 652 expect { 653 -re "\\\$$decimal = 102\r\n$prompt $" { 654 pass "print filelocal_bss at bar" 655 } 656 -re "$prompt $" { 657 fail "print filelocal_bss at bar" ; return 658 } 659 timeout { 660 fail "(timeout) print filelocal_bss at bar" ; return 661 } 662 } 663 664 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 665 send "print 'scope1.c'::filelocal_bss\n" 666 expect { 667 -re "\\\$$decimal = 102\r\n$prompt $" { 668 pass "print 'scope1.c'::filelocal_bss at bar" 669 } 670 -re "No symbol \"scope1.c\" in current context.*$prompt $" { 671 send "print '$srcdir/$subdir/scope1.c'::filelocal_bss\n" 672 exp_continue 673 } 674 -re "$prompt $" { 675 fail "print 'scope1.c'::filelocal_bss at bar" ; return 676 } 677 timeout { 678 fail "(timeout) print 'scope1.c'::filelocal_bss at bar" ; return 679 } 680 } 681 682 # Print scope1.c::filelocal_ro, which is 202 683 684 send "print filelocal_ro\n" 685 expect { 686 -re "\\\$$decimal = 202\r\n$prompt $" { 687 pass "print filelocal_ro in test_at_bar" 688 } 689 -re "$prompt $" { 690 fail "print filelocal_ro in test_at_bar" 691 return 692 } 693 timeout { 694 fail "(timeout) print filelocal_ro in test_at_bar" 695 return 696 } 697 } 698 699 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 700 send "print 'scope1.c'::filelocal_ro\n" 701 expect { 702 -re "\\\$$decimal = 202\r\n$prompt $" { 703 pass "print 'scope1.c'::filelocal_ro at bar" 704 } 705 -re "No symbol \"scope1.c\" in current context.*$prompt $" { 706 send "print '$srcdir/$subdir/scope1.c'::filelocal_ro\n" 707 exp_continue 708 } 709 -re "$prompt $" { 710 fail "print 'scope1.c'::filelocal_ro at bar" ; return 711 } 712 timeout { 713 fail "(timeout) print 'scope1.c'::filelocal_ro at bar" ; return 714 } 715 } 716 717 # Print scope1.c::foo::funclocal, which is 3 718 719 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" } 720 send "print foo::funclocal\n" 721 expect { 722 -re "\\\$$decimal = 3\r\n$prompt $" { 723 pass "print foo::funclocal at bar" 724 } 725 -re "$prompt $" { 726 fail "print foo::funclocal at bar" ; return 727 } 728 timeout { 729 fail "(timeout) print foo::funclocal at bar" ; return 730 } 731 } 732 733 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 734 send "print 'scope1.c'::foo::funclocal\n" 735 expect { 736 -re "\\\$$decimal = 3\r\n$prompt $" { 737 pass "print 'scope1.c'::foo::funclocal at bar" 738 } 739 -re "No symbol \"scope1.c\" in current context.*$prompt $" { 740 send "print '$srcdir/$subdir/scope1.c'::foo::funclocal\n" 741 exp_continue 742 } 743 -re "$prompt $" { 744 fail "print 'scope1.c'::foo::funclocal at bar" ; return 745 } 746 timeout { 747 fail "(timeout) print 'scope1.c'::foo::funclocal at bar" ; return 748 } 749 } 750 751 # Print scope1.c::foo::funclocal_bss, which is 103 752 753 send "print foo::funclocal_bss\n" 754 expect { 755 -re "\\\$$decimal = 103\r\n$prompt $" { 756 pass "print foo::funclocal_bss at bar" 757 } 758 -re "$prompt $" { 759 fail "print foo::funclocal_bss at bar" ; return 760 } 761 timeout { 762 fail "(timeout) print foo::funclocal_bss at bar" ; return 763 } 764 } 765 766 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 767 send "print 'scope1.c'::foo::funclocal_bss\n" 768 expect { 769 -re "\\\$$decimal = 103\r\n$prompt $" { 770 pass "print 'scope1.c'::foo::funclocal_bss at bar" 771 } 772 -re "No symbol \"scope1.c\" in current context.*$prompt $" { 773 send "print '$srcdir/$subdir/scope1.c'::foo::funclocal_bss\n" 774 exp_continue 775 } 776 -re "$prompt $" { 777 fail "print 'scope1.c'::foo::funclocal_bss at bar" ; return 778 } 779 timeout { 780 fail "(timeout) print 'scope1.c'::foo::funclocal_bss at bar" ; return 781 } 782 } 783 784 # Print scope1.c::foo::funclocal_ro, which is 203 785 786 send "print foo::funclocal_ro\n" 787 expect { 788 -re "\\\$$decimal = 203\r\n$prompt $" { 789 pass "print foo::funclocal_ro at bar" 790 } 791 -re "$prompt $" { 792 fail "print foo::funclocal_ro at bar" ; return 793 } 794 timeout { 795 fail "(timeout) print foo::funclocal_ro at bar" ; return 796 } 797 } 798 799 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 800 send "print 'scope1.c'::foo::funclocal_ro\n" 801 expect { 802 -re "\\\$$decimal = 203\r\n$prompt $" { 803 pass "print 'scope1.c'::foo::funclocal_ro at bar" 804 } 805 -re "No symbol \"scope1.c\" in current context.*$prompt $" { 806 send "print '$srcdir/$subdir/scope1.c'::foo::funclocal_ro\n" 807 exp_continue 808 } 809 -re "$prompt $" { 810 fail "print 'scope1.c'::foo::funclocal_ro at bar" ; return 811 } 812 timeout { 813 fail "(timeout) print 'scope1.c'::foo::funclocal_ro at bar" ; return 814 } 815 } 816 817 # Print scope1.c::bar::funclocal, which is 4 818 819 send "print funclocal\n" 820 expect { 821 -re "\\\$$decimal = 4\r\n$prompt $" { 822 pass "print funclocal at bar" 823 } 824 -re "$prompt $" { 825 fail "print funclocal at bar" ; return 826 } 827 timeout { 828 fail "(timeout) print funclocal at bar" ; return 829 } 830 } 831 832 send "print bar::funclocal\n" 833 expect { 834 -re "\\\$$decimal = 4\r\n$prompt $" { 835 pass "print bar::funclocal at bar" 836 } 837 -re "$prompt $" { 838 fail "print bar::funclocal at bar" ; return 839 } 840 timeout { 841 fail "(timeout) print bar::funclocal at bar" ; return 842 } 843 } 844 845 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 846 send "print 'scope1.c'::bar::funclocal\n" 847 expect { 848 -re "\\\$$decimal = 4\r\n$prompt $" { 849 pass "print 'scope1.c'::bar::funclocal at bar" 850 } 851 -re "No symbol \"scope1.c\" in current context.*$prompt $" { 852 send "print '$srcdir/$subdir/scope1.c'::bar::funclocal\n" 853 exp_continue 854 } 855 -re "$prompt $" { 856 fail "print 'scope1.c'::bar::funclocal at bar" ; return 857 } 858 timeout { 859 fail "(timeout) print 'scope1.c'::bar::funclocal at bar" ; return 860 } 861 } 862 863 # Print scope1.c::bar::funclocal_bss, which is 104 864 865 send "print funclocal_bss\n" 866 expect { 867 -re "\\\$$decimal = 104\r\n$prompt $" { 868 pass "print funclocal_bss at bar" 869 } 870 -re "$prompt $" { 871 fail "print funclocal_bss at bar" ; return 872 } 873 timeout { 874 fail "(timeout) print funclocal_bss at bar" ; return 875 } 876 } 877 878 send "print bar::funclocal_bss\n" 879 expect { 880 -re "\\\$$decimal = 104\r\n$prompt $" { 881 pass "print bar::funclocal_bss at bar" 882 } 883 -re "$prompt $" { 884 fail "print bar::funclocal_bss at bar" ; return 885 } 886 timeout { 887 fail "(timeout) print bar::funclocal_bss at bar" ; return 888 } 889 } 890 891 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" } 892 send "print 'scope1.c'::bar::funclocal_bss\n" 893 expect { 894 -re "\\\$$decimal = 104\r\n$prompt $" { 895 pass "print 'scope1.c'::bar::funclocal_bss at bar" 896 } 897 -re "No symbol \"scope1.c\" in current context.*$prompt $" { 898 send "print '$srcdir/$subdir/scope1.c'::bar::funclocal_bss\n" 899 exp_continue 900 } 901 -re "$prompt $" { 902 fail "print 'scope1.c'::bar::funclocal_bss at bar" ; return 903 } 904 timeout { 905 fail "(timeout) print 'scope1.c'::bar::funclocal_bss at bar" ; return 906 } 907 } 908} 909 910# This test has little to do with local scopes, but it is in scope.exp anyway. 911# That's life. 912 913proc test_at_autovars {} { 914 global prompt 915 global decimal 916 global hex 917 global srcfile 918 919 # Test symbol table lookup with 100 local (auto) variables. 920 921 send "break marker1\n" ; expect -re ".*$prompt $" 922 923 send "cont\n" 924 expect { 925 -re "Break.* marker1 \\(\\) at .*:$decimal.*$prompt $" { 926 send "up\n" 927 expect { 928 -re ".*$prompt $" {} 929 timeout { fail "(timeout) up from marker1" ; return } 930 } 931 } 932 -re "$prompt $" { fail "continue to marker1" ; return } 933 timeout { fail "(timeout) continue to marker1" ; return } 934 } 935 936 set count 0 937 while {$count < 100} { 938 send "print i$count\n" 939 expect { 940 -re ".* = $count\r\n$prompt $" {} 941 -re "$prompt $" { 942 fail "bad value for auto variable i$count"; return 943 } 944 timeout { 945 fail "(timeout) bad value for auto variable i$count"; return 946 } 947 } 948 set count [expr $count+1] 949 } 950 clear_xfail "*-*-*" 951 pass "$count auto variables correctly initialized" 952 953 # Test that block variable sorting is not screwing us. 954 gdb_test "frame" "#.*autovars \\(bcd=5, abc=6\\).*" "args in correct order" 955} 956 957proc test_at_localscopes {} { 958 global prompt 959 global decimal 960 global hex 961 global srcfile 962 963 send "break marker2\n" ; expect -re ".*$prompt $" 964 send "break marker3\n" ; expect -re ".*$prompt $" 965 send "break marker4\n" ; expect -re ".*$prompt $" 966 967 send "cont\n" 968 expect { 969 -re "Break.* marker2 \\(\\) at .*:$decimal.*$prompt $" { 970 send "up\n" 971 expect { 972 -re ".*$prompt $" {} 973 timeout { fail "(timeout) up from marker2" ; return } 974 } 975 } 976 -re "$prompt $" { fail "continue to marker2" ; return } 977 timeout { fail "(timeout) continue to marker2" ; return } 978 } 979 980 # Should be at first (outermost) scope. Check values. 981 982 gdb_test "print localval" " = 10" "print localval, outer scope" 983 gdb_test "print localval1" " = 11" "print localval1, outer scope" 984 gdb_test "print localval2" "No symbol \"localval2\" in current context." \ 985 "print localval2, outer scope" 986 gdb_test "print localval3" "No symbol \"localval3\" in current context." \ 987 "print localval3, outer scope" 988 989 if [gdb_test "cont" "Break.* marker3 \\(\\) at .*:$decimal.*" \ 990 "continue to marker3 in scope.exp"] then { return } 991 if [gdb_test "up" "" "up from marker3 in scope.exp"] then { return } 992 993 # Should be at next (first nested) scope. Check values. 994 995 gdb_test "print localval" " = 20" \ 996 "print localval, first nested scope" 997 gdb_test "print localval1" " = 11" "print localval1, first nested scope" 998 gdb_test "print localval2" " = 12" "print localval2, first nested scope" 999 gdb_test "print localval3" "No symbol \"localval3\" in current context." \ 1000 "print localval3, first nested scope" 1001 1002 # This test will only fail if the file was compiled by gcc, but 1003 # there's no way to check that. 1004 setup_xfail "a29k-*-udi" 2423 1005 if [gdb_test "cont" "Break.* marker4.*at .*:$decimal.*" \ 1006 "continue to marker4 in scope.exp"] then { return } 1007 if [gdb_test "up" "" "up from marker4 in scope.exp"] then { return } 1008 1009 gdb_test "print localval" " = 30" "print localval, innermost scope" 1010 gdb_test "print localval1" " = 11" "print localval1, innermost scope" 1011 gdb_test "print localval2" " = 12" "print localval2, innermost scope" 1012 gdb_test "print localval3" " = 13" "print localval3, innermost scope" 1013} 1014 1015# Start with a fresh gdb. 1016 1017gdb_exit 1018gdb_start 1019gdb_reinitialize_dir $srcdir/$subdir 1020gdb_load ${binfile} 1021 1022if [istarget "*-*-vxworks*"] { 1023 set timeout 120 1024 verbose "Timeout is now $timeout seconds" 2 1025} 1026 1027# Test that variables in various segments print out correctly before 1028# the program is run. 1029 1030# AIX--sections get mapped to the same address so we can't get the right one. 1031setup_xfail "rs6000-*-*" 1032setup_xfail "powerpc-*-*" 1033 1034gdb_test "print 'scope0.c'::filelocal_ro" "= 201" 1035 1036# gdb currently cannot access bss memory on some targets if the inferior 1037# is not running. 1038# 1039# For PA boards using monitor/remote-pa.c, the bss test is going to 1040# randomly fail. We've already put remote-pa on the target stack, 1041# so we actually read memory from the board. Problem is crt0.o 1042# is responsible for clearing bss and that hasnt' happened yet. 1043setup_xfail "hppa*-*-*pro*" 1044send "print 'scope0.c'::filelocal_bss\n" 1045expect { 1046 -re " = 0\r\n$prompt $" { 1047 pass "print 'scope0.c'::filelocal_bss before run" 1048 } 1049 -re "Cannot access memory.*$prompt $" { 1050 setup_xfail "*-*-*" 1051 fail "print 'scope0.c'::filelocal_bss before run" 1052 } 1053 -re ".*$prompt $" { 1054 fail "print 'scope0.c'::filelocal_bss before run" 1055 } 1056 default { 1057 fail "print 'scope0.c'::filelocal_bss before run" 1058 } 1059} 1060 1061gdb_test "print 'scope0.c'::filelocal" "= 1" \ 1062 "print 'scope0.c'::filelocal before run" 1063 1064if [runto_main] then { test_at_main } 1065if [istarget "mips-idt-*"] then { 1066 # Restart because IDT/SIM runs out of file descriptors. 1067 gdb_exit 1068 gdb_start 1069 gdb_reinitialize_dir $srcdir/$subdir 1070 gdb_load ${binfile} 1071} 1072if [runto foo] then { test_at_foo } 1073if [istarget "mips-idt-*"] then { 1074 # Restart because IDT/SIM runs out of file descriptors. 1075 gdb_exit 1076 gdb_start 1077 gdb_reinitialize_dir $srcdir/$subdir 1078 gdb_load ${binfile} 1079} 1080if [runto bar] then { test_at_bar } 1081if [istarget "mips-idt-*"] then { 1082 # Restart because IDT/SIM runs out of file descriptors. 1083 gdb_exit 1084 gdb_start 1085 gdb_reinitialize_dir $srcdir/$subdir 1086 gdb_load ${binfile} 1087} 1088if [runto localscopes] then { test_at_localscopes } 1089if [istarget "mips-idt-*"] then { 1090 # Restart because IDT/SIM runs out of file descriptors. 1091 gdb_exit 1092 gdb_start 1093 gdb_reinitialize_dir $srcdir/$subdir 1094 gdb_load ${binfile} 1095} 1096if [runto autovars] then { test_at_autovars } 1097 1098if [istarget "*-*-vxworks*"] { 1099 set timeout 120 1100 verbose "Timeout is now $timeout seconds" 2 1101} 1102