1 # Copyright (C) 1992, 1994, 1997, 1998 Free Software Foundation, Inc.
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.
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.
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.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Fred Fish. (fnf@cygnus.com)
30 set binfile ${objdir}/${subdir}/${testfile}
33 if { [gdb_compile "${srcdir}/${subdir}/scope0.c" "${binfile}0.o" object {debug}] != "" } {
34 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
37 if { [gdb_compile "${srcdir}/${subdir}/scope1.c" "${binfile}1.o" object {debug}] != "" } {
38 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
41 if { [gdb_compile "${binfile}0.o ${binfile}1.o" ${binfile} executable {debug}] != "" } {
42 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
45 # Create and source the file that provides information about the compiler
46 # used to compile the test case.
47 if [get_compiler_info ${binfile}] {
51 # Test locating various things when stopped just inside main, after
52 # running init0(). To prevent cascading of errors, we report the
53 # first one and quit. If all pass, then we print the pass results.
55 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 {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
100 if [gdb_test "print filelocal_ro" "\\\$$decimal = 201" "print filelocal_ro in test_at_main" ] {
105 if {$gcc_compiled} 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 {$gcc_compiled} 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 {$gcc_compiled} 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 {$gcc_compiled} 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 {$gcc_compiled} 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 {$gcc_compiled} 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 {$gcc_compiled} 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 {} {
188 if [gdb_test "next" ".*bar \\(\\);" "" ] {
193 # Print scope0.c::filelocal, which is 1
195 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"] {
200 # Print scope0.c::filelocal_bss, which is 101
202 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"] {
207 # Print scope0.c::filelocal_ro, which is 201
209 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
210 setup_xfail "powerpc-*-*"
211 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"] {
216 gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at foo"
218 # Print scope1.c::filelocal, which is 2
220 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
221 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"] {
226 gdb_test "print filelocal_bss" "\\\$$decimal = 102" \
227 "print filelocal_bss at foo"
229 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
230 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"
233 gdb_test "print filelocal_ro" "\\\$$decimal = 202" \
234 "print filelocal_ro at foo"
236 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
237 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"
240 # Print scope1.c::foo::funclocal, which is 3
242 gdb_test "print funclocal" "\\\$$decimal = 3" "print funclocal at foo"
244 gdb_test "print foo::funclocal" "\\\$$decimal = 3" \
245 "print foo::funclocal at foo"
247 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
248 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"
251 # Print scope1.c::foo::funclocal_bss, which is 103
253 gdb_test "print funclocal_bss" "\\\$$decimal = 103" \
254 "print funclocal_bss at foo"
256 gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" \
257 "print foo::funclocal_bss at foo"
259 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
260 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"
263 # Print scope1.c::foo::funclocal_ro, which is 203
265 gdb_test "print funclocal_ro" "\\\$$decimal = 203" \
266 "print funclocal_ro at foo"
268 gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" \
269 "print foo::funclocal_ro at foo"
271 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
272 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"
275 # Print scope1.c::bar::funclocal, which is 4
277 gdb_test "print bar::funclocal" "\\\$$decimal = 4" \
278 "print bar::funclocal at foo"
280 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
281 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"
282 gdb_stop_suppressing_tests;
286 proc test_at_bar {} {
294 if [gdb_test "next" ".*" "" ] {
299 # Print scope0.c::filelocal, which is 1
301 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"] {
306 # Print scope0.c::filelocal_bss, which is 101
308 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"] {
313 # Print scope0.c::filelocal_ro, which is 201
315 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
316 setup_xfail "powerpc-*-*"
317 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"] {
322 # Print scope1.c::filelocal, which is 2
324 if [gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at bar" ] {
329 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
330 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"] {
335 # Print scope1.c::filelocal_bss, which is 102
337 if [gdb_test "print filelocal_bss" "\\\$$decimal = 102" "print filelocal_bss at bar" ] {
342 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
343 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"] {
348 # Print scope1.c::filelocal_ro, which is 202
350 if [gdb_test "print filelocal_ro" "\\\$$decimal = 202" "print filelocal_ro in test_at_bar" ] {
355 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
356 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"] {
361 # Print scope1.c::foo::funclocal, which is 3
363 if [gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal at bar" ] {
368 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
369 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"] {
374 # Print scope1.c::foo::funclocal_bss, which is 103
376 if [gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" "print foo::funclocal_bss at bar" ] {
381 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
382 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"] {
387 # Print scope1.c::foo::funclocal_ro, which is 203
389 if [gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" "print foo::funclocal_ro at bar" ] {
394 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
395 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"] {
400 # Print scope1.c::bar::funclocal, which is 4
402 if [gdb_test "print funclocal" "\\\$$decimal = 4" "print funclocal at bar" ] {
407 if [gdb_test "print bar::funclocal" "\\\$$decimal = 4" "print bar::funclocal at bar" ] {
412 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
413 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"] {
418 # Print scope1.c::bar::funclocal_bss, which is 104
420 if [gdb_test "print funclocal_bss" "\\\$$decimal = 104" "print funclocal_bss at bar" ] {
425 if [gdb_test "print bar::funclocal_bss" "\\\$$decimal = 104" "print bar::funclocal_bss at bar" ] {
430 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
431 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"] {
434 gdb_stop_suppressing_tests;
438 # This test has little to do with local scopes, but it is in scope.exp anyway.
441 proc test_at_autovars {} {
447 # Test symbol table lookup with 100 local (auto) variables.
449 gdb_breakpoint marker1
451 if [gdb_test "cont" "Break.* marker1 \\(\\) at .*:$decimal.*" "continue to marker1"] {
455 if [gdb_test "up" ".*" "" ] {
460 while {$count < 100} {
461 if [gdb_test "print i$count" ".* = $count" "" ] {
465 set count [expr $count+1]
468 pass "$count auto variables correctly initialized"
470 # Test that block variable sorting is not screwing us.
471 gdb_test "frame" "#.*autovars \\(bcd=5, abc=6\\).*" "args in correct order"
474 proc test_at_localscopes {} {
480 gdb_breakpoint marker2
481 gdb_breakpoint marker3
482 gdb_breakpoint marker4
484 if [gdb_test "cont" "Break.* marker2 \\(\\) at .*:$decimal.*" "continue to marker2"] {
487 if [gdb_test "up" ".*" "" ] {
491 # Should be at first (outermost) scope. Check values.
493 gdb_test "print localval" " = 10" "print localval, outer scope"
494 gdb_test "print localval1" " = 11" "print localval1, outer scope"
495 gdb_test "print localval2" "No symbol \"localval2\" in current context." \
496 "print localval2, outer scope"
497 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
498 "print localval3, outer scope"
500 if [gdb_test "cont" "Break.* marker3 \\(\\) at .*:$decimal.*" \
501 "continue to marker3 in scope.exp"] then { gdb_suppress_tests }
502 if [gdb_test "up" "" "up from marker3 in scope.exp"] then { gdb_suppress_tests }
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 setup_xfail "a29k-*-udi" 2423
516 if [gdb_test "cont" "Break.* marker4.*at .*:$decimal.*" \
517 "continue to marker4 in scope.exp"] then { gdb_suppress_tests }
518 if [gdb_test "up" "" "up from marker4 in scope.exp"] then { gdb_suppress_tests }
520 gdb_test "print localval" " = 30" "print localval, innermost scope"
521 gdb_test "print localval1" " = 11" "print localval1, innermost scope"
522 gdb_test "print localval2" " = 12" "print localval2, innermost scope"
523 gdb_test "print localval3" " = 13" "print localval3, innermost scope"
524 gdb_stop_suppressing_tests;
527 # Start with a fresh gdb.
531 gdb_reinitialize_dir $srcdir/$subdir
534 if [istarget "*-*-vxworks*"] {
536 verbose "Timeout is now $timeout seconds" 2
539 # Test that variables in various segments print out correctly before
540 # the program is run.
542 # AIX--sections get mapped to the same address so we can't get the right one.
543 setup_xfail "rs6000-*-*"
544 setup_xfail "powerpc-*-*"
546 gdb_test "print 'scope0.c'::filelocal_ro" "= 201"
548 # gdb currently cannot access bss memory on some targets if the inferior
551 # For PA boards using monitor/remote-pa.c, the bss test is going to
552 # randomly fail. We've already put remote-pa on the target stack,
553 # so we actually read memory from the board. Problem is crt0.o
554 # is responsible for clearing bss and that hasnt' happened yet.
556 # This is a problem for all non-native targets. -- manson
558 unsupported "print 'scope0.c'::filelocal_bss before run"
560 gdb_test "print 'scope0.c'::filelocal_bss" "= 0" \
561 "print 'scope0.c'::filelocal_bss before run"
564 gdb_test "print 'scope0.c'::filelocal" "= 1" \
565 "print 'scope0.c'::filelocal before run"
567 if [runto_main] then { test_at_main }
568 if [istarget "mips-idt-*"] then {
569 # Restart because IDT/SIM runs out of file descriptors.
572 gdb_reinitialize_dir $srcdir/$subdir
575 if [runto foo] then { test_at_foo }
576 if [istarget "mips-idt-*"] then {
577 # Restart because IDT/SIM runs out of file descriptors.
580 gdb_reinitialize_dir $srcdir/$subdir
583 if [runto bar] then { test_at_bar }
584 if [istarget "mips-idt-*"] then {
585 # Restart because IDT/SIM runs out of file descriptors.
588 gdb_reinitialize_dir $srcdir/$subdir
591 if [runto localscopes] then { test_at_localscopes }
592 if [istarget "mips-idt-*"] then {
593 # Restart because IDT/SIM runs out of file descriptors.
596 gdb_reinitialize_dir $srcdir/$subdir
599 if [runto autovars] then { test_at_autovars }
601 if [istarget "*-*-vxworks*"] {
603 verbose "Timeout is now $timeout seconds" 2