1 # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003
2 # Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
21 # This file was written by Fred Fish. (fnf@cygnus.com)
31 set binfile ${objdir}/${subdir}/${testfile}
34 if { [gdb_compile "${srcdir}/${subdir}/scope0.c" "${binfile}0.o" object {debug}] != "" } {
35 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
38 if { [gdb_compile "${srcdir}/${subdir}/scope1.c" "${binfile}1.o" object {debug}] != "" } {
39 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
42 if { [gdb_compile "${binfile}0.o ${binfile}1.o" ${binfile} executable {debug}] != "" } {
43 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
46 # Create and source the file that provides information about the compiler
47 # used to compile the test case.
48 if [get_compiler_info ${binfile}] {
52 # Test locating various things when stopped just inside main, after
53 # running init0(). To prevent cascading of errors, we report the
54 # first one and quit. If all pass, then we print the pass results.
56 proc test_at_main {} {
64 # skip past init. There may be a call to __main at the start of
65 # main, so the first next may only get us to the init0 call.
66 if [gdb_test "next" "$decimal.*foo \\(\\);" "next over init0() in main" "$decimal.*init0 \\(\\);" "next"] {
71 # Print scope0.c::filelocal, which is 1
73 if [gdb_test "print filelocal" "\\\$$decimal = 1" "print filelocal" ] {
78 if [gdb_test "print 'scope0.c'::filelocal" "\\\$$decimal = 1" "print 'scope0.c'::filelocal at main" "No symbol \"scope0.c\" in current context.*" "print '$srcdir/$subdir/scope0.c'::filelocal"] {
83 # Print scope0.c::filelocal_bss, which is 101
85 if [gdb_test "print filelocal_bss" "\\\$$decimal = 101" "print filelocal_bss" ] {
90 if [gdb_test "print 'scope0.c'::filelocal_bss" "\\\$$decimal = 101" "print 'scope0.c'::filelocal_bss in test_at_main" "No symbol \"scope0.c\" in current context.*" "print '$srcdir/$subdir/scope0.c'::filelocal_bss"] {
95 # Print scope0.c::filelocal_ro, which is 201
97 # No clue why the powerpc fails this test.
98 setup_xfail "powerpc-*-*"
99 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
100 if [gdb_test "print filelocal_ro" "\\\$$decimal = 201" "print filelocal_ro in test_at_main" ] {
105 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
106 setup_xfail "powerpc-*-*"
107 if [gdb_test "print 'scope0.c'::filelocal_ro" "\\\$$decimal = 201" "print 'scope0.c'::filelocal_ro" "No symbol \"scope0.c\" in current context.*" "print '$srcdir/$subdir/scope0.c'::filelocal_ro"] {
112 # Print scope1.c::filelocal, which is 2
114 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
115 if {$hp_cc_compiler} then { setup_xfail "hppa2.0w-*-*" 11747CLLbs}
116 if [gdb_test "print 'scope1.c'::filelocal" "\\\$$decimal = 2" "print 'scope1.c'::filelocal" "No symbol \"scope1.c\" in current context.*" "print '$srcdir/$subdir/scope1.c'::filelocal"] {
121 # Print scope1.c::filelocal_bss, which is 102
123 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
124 if {$hp_cc_compiler} then { setup_xfail "hppa2.0w-*-*" 11747CLLbs}
125 if [gdb_test "print 'scope1.c'::filelocal_bss" "\\\$$decimal = 102" "print 'scope1.c'::filelocal_bss" "No symbol \"scope1.c\" in current context.*" "print '$srcdir/$subdir/scope1.c'::filelocal_bss"] {
130 # Print scope1.c::filelocal_ro, which is 202
132 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
133 if {$hp_cc_compiler} then { setup_xfail "hppa2.0w-*-*" 11747CLLbs}
134 if [gdb_test "print 'scope1.c'::filelocal_ro" "\\\$$decimal = 202" "print 'scope1.c'::filelocal_ro" "No symbol \"scope1.c\" in current context.*" "print '$srcdir/$subdir/scope1.c'::filelocal_ro"] {
139 # Print scope1.c::foo::funclocal, which is 3
141 if [gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal" ] {
146 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
147 if [gdb_test "print 'scope1.c'::foo::funclocal" "\\\$$decimal = 3" "print 'scope1.c'::foo::funclocal" "No symbol \"scope1.c\" in current context.*" "print '$srcdir/$subdir/scope1.c'::foo::funclocal"] {
152 # Print scope1.c::foo::funclocal_ro, which is 203
154 if [gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" "print foo::funclocal_ro" ] {
159 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
160 if [gdb_test "print 'scope1.c'::foo::funclocal_ro" "\\\$$decimal = 203" "print 'scope1.c'::foo::funclocal_ro" "No symbol \"scope1.c\" in current context.*" "print '$srcdir/$subdir/scope1.c'::foo::funclocal_ro"] {
165 # Print scope1.c::bar::funclocal, which is 4
167 if [gdb_test "print bar::funclocal" "\\\$$decimal = 4" "print bar::funclocal" ] {
172 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
173 if [gdb_test "print 'scope1.c'::bar::funclocal" "\\\$$decimal = 4" "print 'scope1.c'::bar::funclocal" "No symbol \"scope1.c\" in current context.*" "print '$srcdir/$subdir/scope1.c'::bar::funclocal"] {
176 gdb_stop_suppressing_tests;
180 proc test_at_foo {} {
187 if [gdb_test "next" ".*bar \\(\\);" "" ] {
192 # Print scope0.c::filelocal, which is 1
194 if [gdb_test "print 'scope0.c'::filelocal" "\\\$$decimal = 1" "print 'scope0.c'::filelocal at foo" "No symbol \"scope0.c\" in current context.*" "print '$srcdir/$subdir/scope0.c'::filelocal"] {
199 # Print scope0.c::filelocal_bss, which is 101
201 if [gdb_test "print 'scope0.c'::filelocal_bss" "\\\$$decimal = 101" "print 'scope0.c'::filelocal_bss in test_at_foo" "No symbol \"scope0.c\" in current context.*" "print '$srcdir/$subdir/scope0.c'::filelocal_bss"] {
206 # Print scope0.c::filelocal_ro, which is 201
208 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
209 setup_xfail "powerpc-*-*"
210 if [gdb_test "print 'scope0.c'::filelocal_ro" "\\\$$decimal = 201" "print 'scope0.c'::filelocal_ro" "No symbol \"scope0.c\" in current context.*" "print '$srcdir/$subdir/scope0.c'::filelocal_ro"] {
215 gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at foo"
217 # Print scope1.c::filelocal, which is 2
219 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
220 if [gdb_test "print 'scope1.c'::filelocal" "\\\$$decimal = 2" "print 'scope1.c'::filelocal at foo" "No symbol \"scope1.c\" in current context.*" "print '$srcdir/$subdir/scope1.c'::filelocal"] {
225 gdb_test "print filelocal_bss" "\\\$$decimal = 102" \
226 "print filelocal_bss at foo"
228 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
229 gdb_test "print 'scope1.c'::filelocal_bss" "\\\$$decimal = 102" "print 'scope1.c'::filelocal_bss at foo" "No symbol \"scope1.c\" in current context.*" "print '$srcdir/$subdir/scope1.c'::filelocal_bss"
232 gdb_test "print filelocal_ro" "\\\$$decimal = 202" \
233 "print filelocal_ro at foo"
235 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
236 gdb_test "print 'scope1.c'::filelocal_ro" "\\\$$decimal = 202" "print 'scope1.c'::filelocal_ro at foo" "No symbol \"scope1.c\" in current context.*" "print '$srcdir/$subdir/scope1.c'::filelocal_ro"
239 # Print scope1.c::foo::funclocal, which is 3
241 gdb_test "print funclocal" "\\\$$decimal = 3" "print funclocal at foo"
243 gdb_test "print foo::funclocal" "\\\$$decimal = 3" \
244 "print foo::funclocal at foo"
246 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
247 gdb_test "print 'scope1.c'::foo::funclocal" "\\\$$decimal = 3" "print 'scope1.c'::foo::funclocal at foo" "No symbol \"scope1.c\" in current context.*" "print '$srcdir/$subdir/scope1.c'::foo::funclocal"
250 # Print scope1.c::foo::funclocal_bss, which is 103
252 gdb_test "print funclocal_bss" "\\\$$decimal = 103" \
253 "print funclocal_bss at foo"
255 gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" \
256 "print foo::funclocal_bss at foo"
258 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
259 gdb_test "print 'scope1.c'::foo::funclocal_bss" "\\\$$decimal = 103" "print 'scope1.c'::foo::funclocal_bss at foo" "No symbol \"scope1.c\" in current context.*" "print '$srcdir/$subdir/scope1.c'::foo::funclocal_bss"
262 # Print scope1.c::foo::funclocal_ro, which is 203
264 gdb_test "print funclocal_ro" "\\\$$decimal = 203" \
265 "print funclocal_ro at foo"
267 gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" \
268 "print foo::funclocal_ro at foo"
270 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
271 gdb_test "print 'scope1.c'::foo::funclocal_ro" "\\\$$decimal = 203" "print 'scope1.c'::foo::funclocal_ro at foo" "No symbol \"scope1.c\" in current context.*" "print '$srcdir/$subdir/scope1.c'::foo::funclocal_ro"
274 # Print scope1.c::bar::funclocal, which is 4
276 gdb_test "print bar::funclocal" "\\\$$decimal = 4" \
277 "print bar::funclocal at foo"
279 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
280 gdb_test "print 'scope1.c'::bar::funclocal" "\\\$$decimal = 4" "print 'scope1.c'::bar::funclocal at foo" "No symbol \"scope1.c\" in current context.*" "print '$srcdir/$subdir/scope1.c'::bar::funclocal"
281 gdb_stop_suppressing_tests;
285 proc test_at_bar {} {
292 if [gdb_test "next" ".*" "" ] {
297 # Print scope0.c::filelocal, which is 1
299 if [gdb_test "print 'scope0.c'::filelocal" "\\\$$decimal = 1" "print 'scope0.c'::filelocal at bar" "No symbol \"scope0.c\" in current context.*" "print '$srcdir/$subdir/scope0.c'::filelocal"] {
304 # Print scope0.c::filelocal_bss, which is 101
306 if [gdb_test "print 'scope0.c'::filelocal_bss" "\\\$$decimal = 101" "print 'scope0.c'::filelocal_bss in test_at_bar" "No symbol \"scope0.c\" in current context.*" "print '$srcdir/$subdir/scope0.c'::filelocal_bss"] {
311 # Print scope0.c::filelocal_ro, which is 201
313 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
314 setup_xfail "powerpc-*-*"
315 if [gdb_test "print 'scope0.c'::filelocal_ro" "\\\$$decimal = 201" "print 'scope0.c'::filelocal_ro at bar" "No symbol \"scope0.c\" in current context.*" "print '$srcdir/$subdir/scope0.c'::filelocal_ro"] {
320 # Print scope1.c::filelocal, which is 2
322 if [gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at bar" ] {
327 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
328 if [gdb_test "print 'scope1.c'::filelocal" "\\\$$decimal = 2" "print 'scope1.c'::filelocal at bar" "No symbol \"scope1.c\" in current context.*" "print '$srcdir/$subdir/scope1.c'::filelocal"] {
333 # Print scope1.c::filelocal_bss, which is 102
335 if [gdb_test "print filelocal_bss" "\\\$$decimal = 102" "print filelocal_bss at bar" ] {
340 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
341 if [gdb_test "print 'scope1.c'::filelocal_bss" "\\\$$decimal = 102" "print 'scope1.c'::filelocal_bss at bar" "No symbol \"scope1.c\" in current context.*" "print '$srcdir/$subdir/scope1.c'::filelocal_bss"] {
346 # Print scope1.c::filelocal_ro, which is 202
348 if [gdb_test "print filelocal_ro" "\\\$$decimal = 202" "print filelocal_ro in test_at_bar" ] {
353 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
354 if [gdb_test "print 'scope1.c'::filelocal_ro" "\\\$$decimal = 202" "print 'scope1.c'::filelocal_ro at bar" "No symbol \"scope1.c\" in current context.*" "print '$srcdir/$subdir/scope1.c'::filelocal_ro"] {
359 # Print scope1.c::foo::funclocal, which is 3
361 if [gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal at bar" ] {
366 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
367 if [gdb_test "print 'scope1.c'::foo::funclocal" "\\\$$decimal = 3" "print 'scope1.c'::foo::funclocal at bar" "No symbol \"scope1.c\" in current context.*" "print '$srcdir/$subdir/scope1.c'::foo::funclocal"] {
372 # Print scope1.c::foo::funclocal_bss, which is 103
374 if [gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" "print foo::funclocal_bss at bar" ] {
379 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
380 if [gdb_test "print 'scope1.c'::foo::funclocal_bss" "\\\$$decimal = 103" "print 'scope1.c'::foo::funclocal_bss at bar" "No symbol \"scope1.c\" in current context.*" "print '$srcdir/$subdir/scope1.c'::foo::funclocal_bss"] {
385 # Print scope1.c::foo::funclocal_ro, which is 203
387 if [gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" "print foo::funclocal_ro at bar" ] {
392 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
393 if [gdb_test "print 'scope1.c'::foo::funclocal_ro" "\\\$$decimal = 203" "print 'scope1.c'::foo::funclocal_ro at bar" "No symbol \"scope1.c\" in current context.*" "print '$srcdir/$subdir/scope1.c'::foo::funclocal_ro"] {
398 # Print scope1.c::bar::funclocal, which is 4
400 if [gdb_test "print funclocal" "\\\$$decimal = 4" "print funclocal at bar" ] {
405 if [gdb_test "print bar::funclocal" "\\\$$decimal = 4" "print bar::funclocal at bar" ] {
410 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
411 if [gdb_test "print 'scope1.c'::bar::funclocal" "\\\$$decimal = 4" "print 'scope1.c'::bar::funclocal at bar" "No symbol \"scope1.c\" in current context.*" "print '$srcdir/$subdir/scope1.c'::bar::funclocal"] {
416 # Print scope1.c::bar::funclocal_bss, which is 104
418 if [gdb_test "print funclocal_bss" "\\\$$decimal = 104" "print funclocal_bss at bar" ] {
423 if [gdb_test "print bar::funclocal_bss" "\\\$$decimal = 104" "print bar::funclocal_bss at bar" ] {
428 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
429 if [gdb_test "print 'scope1.c'::bar::funclocal_bss" "\\\$$decimal = 104" "print 'scope1.c'::bar::funclocal_bss at bar" "No symbol \"scope1.c\" in current context.*" "print '$srcdir/$subdir/scope1.c'::bar::funclocal_bss"] {
432 gdb_stop_suppressing_tests;
436 # This test has little to do with local scopes, but it is in scope.exp anyway.
439 proc test_at_autovars {} {
445 # Test symbol table lookup with 100 local (auto) variables.
447 gdb_breakpoint marker1
449 if [gdb_test "cont" "Break.* marker1 \\(\\) at .*:$decimal.*" "continue to marker1"] {
453 if [gdb_test "up" ".*autovars.*" "up from marker1 in scope.exp" ] {
458 while {$count < 100} {
459 if [gdb_test "print i$count" ".* = $count" "" ] {
463 set count [expr $count+1]
466 pass "$count auto variables correctly initialized"
468 # Test that block variable sorting is not screwing us.
469 gdb_test "frame" "#.*autovars \\(bcd=5, abc=6\\).*" "args in correct order"
472 proc test_at_localscopes {} {
478 gdb_breakpoint marker2
479 gdb_breakpoint marker3
480 gdb_breakpoint marker4
482 if [gdb_test "cont" "Break.* marker2 \\(\\) at .*:$decimal.*" "continue to marker2"] {
485 if [gdb_test "up" ".*localscopes.*" "up from marker2 in scopes.exp" ] {
489 # Should be at first (outermost) scope. Check values.
491 gdb_test "print localval" " = 10" "print localval, outer scope"
492 gdb_test "print localval1" " = 11" "print localval1, outer scope"
493 gdb_test "print localval2" "No symbol \"localval2\" in current context." \
494 "print localval2, outer scope"
495 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
496 "print localval3, outer scope"
498 if [gdb_test "cont" "Break.* marker3 \\(\\) at .*:$decimal.*" \
499 "continue to marker3 in scope.exp"] then { gdb_suppress_tests }
500 if [gdb_test "up" ".*localscopes.*" "up from marker3 in scope.exp"] {
504 # Should be at next (first nested) scope. Check values.
506 gdb_test "print localval" " = 20" \
507 "print localval, first nested scope"
508 gdb_test "print localval1" " = 11" "print localval1, first nested scope"
509 gdb_test "print localval2" " = 12" "print localval2, first nested scope"
510 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
511 "print localval3, first nested scope"
513 # This test will only fail if the file was compiled by gcc, but
514 # there's no way to check that.
515 if [gdb_test "cont" "Break.* marker4.*at .*:$decimal.*" \
516 "continue to marker4 in scope.exp"] then { gdb_suppress_tests }
517 if [gdb_test "up" ".*localscopes.*" "up from marker4 in scope.exp"] {
521 gdb_test "print localval" " = 30" "print localval, innermost scope"
522 gdb_test "print localval1" " = 11" "print localval1, innermost scope"
523 gdb_test "print localval2" " = 12" "print localval2, innermost scope"
524 gdb_test "print localval3" " = 13" "print localval3, innermost scope"
525 gdb_stop_suppressing_tests;
528 # Start with a fresh gdb.
532 gdb_reinitialize_dir $srcdir/$subdir
535 if [istarget "*-*-vxworks*"] {
537 verbose "Timeout is now $timeout seconds" 2
540 # Test that variables in various segments print out correctly before
541 # the program is run.
543 # AIX--sections get mapped to the same address so we can't get the right one.
544 setup_xfail "rs6000-*-*"
545 setup_xfail "powerpc-*-*"
547 gdb_test "print 'scope0.c'::filelocal_ro" "= 201"
549 # gdb currently cannot access bss memory on some targets if the inferior
552 # For PA boards using monitor/remote-pa.c, the bss test is going to
553 # randomly fail. We've already put remote-pa on the target stack,
554 # so we actually read memory from the board. Problem is crt0.o
555 # is responsible for clearing bss and that hasnt' happened yet.
557 # This is a problem for all non-native targets. -- manson
558 if [is_remote target] {
559 unsupported "print 'scope0.c'::filelocal_bss before run"
561 gdb_test "print 'scope0.c'::filelocal_bss" "= 0" \
562 "print 'scope0.c'::filelocal_bss before run"
565 gdb_test "print 'scope0.c'::filelocal" "= 1" \
566 "print 'scope0.c'::filelocal before run"
568 if [runto_main] then { test_at_main }
569 if [istarget "mips-idt-*"] then {
570 # Restart because IDT/SIM runs out of file descriptors.
573 gdb_reinitialize_dir $srcdir/$subdir
576 if [runto foo] then { test_at_foo }
577 if [istarget "mips-idt-*"] then {
578 # Restart because IDT/SIM runs out of file descriptors.
581 gdb_reinitialize_dir $srcdir/$subdir
584 if [runto bar] then { test_at_bar }
585 if [istarget "mips-idt-*"] then {
586 # Restart because IDT/SIM runs out of file descriptors.
589 gdb_reinitialize_dir $srcdir/$subdir
592 if [runto localscopes] then { test_at_localscopes }
593 if [istarget "mips-idt-*"] then {
594 # Restart because IDT/SIM runs out of file descriptors.
597 gdb_reinitialize_dir $srcdir/$subdir
600 if [runto autovars] then { test_at_autovars }
602 if [istarget "*-*-vxworks*"] {
604 verbose "Timeout is now $timeout seconds" 2