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 {} {
63 # skip past init. There may be a call to __main at the start of
64 # main, so the first next may only get us to the init0 call.
65 if [gdb_test "next" "$decimal.*foo \\(\\);" "next over init0() in main" "$decimal.*init0 \\(\\);" "next"] {
70 # Print scope0.c::filelocal, which is 1
72 if [gdb_test "print filelocal" "\\\$$decimal = 1" "print filelocal" ] {
77 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"] {
82 # Print scope0.c::filelocal_bss, which is 101
84 if [gdb_test "print filelocal_bss" "\\\$$decimal = 101" "print filelocal_bss" ] {
89 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"] {
94 # Print scope0.c::filelocal_ro, which is 201
96 # No clue why the powerpc fails this test.
97 setup_xfail "powerpc-*-*"
98 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
99 if [gdb_test "print filelocal_ro" "\\\$$decimal = 201" "print filelocal_ro in test_at_main" ] {
104 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
105 setup_xfail "powerpc-*-*"
106 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"] {
111 # Print scope1.c::filelocal, which is 2
113 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
114 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"] {
119 # Print scope1.c::filelocal_bss, which is 102
121 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
122 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"] {
127 # Print scope1.c::filelocal_ro, which is 202
129 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
130 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"] {
135 # Print scope1.c::foo::funclocal, which is 3
137 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
138 if [gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal" ] {
143 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
144 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"] {
149 # Print scope1.c::foo::funclocal_ro, which is 203
151 if [gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" "print foo::funclocal_ro" ] {
156 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
157 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"] {
162 # Print scope1.c::bar::funclocal, which is 4
164 if [gdb_test "print bar::funclocal" "\\\$$decimal = 4" "print bar::funclocal" ] {
169 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
170 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"] {
173 gdb_stop_suppressing_tests;
177 proc test_at_foo {} {
185 if [gdb_test "next" ".*bar \\(\\);" "" ] {
190 # Print scope0.c::filelocal, which is 1
192 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"] {
197 # Print scope0.c::filelocal_bss, which is 101
199 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"] {
204 # Print scope0.c::filelocal_ro, which is 201
206 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
207 setup_xfail "powerpc-*-*"
208 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"] {
213 gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at foo"
215 # Print scope1.c::filelocal, which is 2
217 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
218 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"] {
223 gdb_test "print filelocal_bss" "\\\$$decimal = 102" \
224 "print filelocal_bss at foo"
226 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
227 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"
230 gdb_test "print filelocal_ro" "\\\$$decimal = 202" \
231 "print filelocal_ro at foo"
233 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
234 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"
237 # Print scope1.c::foo::funclocal, which is 3
239 gdb_test "print funclocal" "\\\$$decimal = 3" "print funclocal at foo"
241 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
242 gdb_test "print foo::funclocal" "\\\$$decimal = 3" \
243 "print foo::funclocal at foo"
245 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
246 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
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 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
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 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
261 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"
264 # Print scope1.c::foo::funclocal_ro, which is 203
266 gdb_test "print funclocal_ro" "\\\$$decimal = 203" \
267 "print funclocal_ro at foo"
269 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
270 gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" \
271 "print foo::funclocal_ro at foo"
273 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
274 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
275 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"
278 # Print scope1.c::bar::funclocal, which is 4
280 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
281 gdb_test "print bar::funclocal" "\\\$$decimal = 4" \
282 "print bar::funclocal at foo"
284 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
285 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
286 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"
287 gdb_stop_suppressing_tests;
291 proc test_at_bar {} {
299 if [gdb_test "next" ".*" "" ] {
304 # Print scope0.c::filelocal, which is 1
306 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"] {
311 # Print scope0.c::filelocal_bss, which is 101
313 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"] {
318 # Print scope0.c::filelocal_ro, which is 201
320 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
321 setup_xfail "powerpc-*-*"
322 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"] {
327 # Print scope1.c::filelocal, which is 2
329 if [gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at bar" ] {
334 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
335 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"] {
340 # Print scope1.c::filelocal_bss, which is 102
342 if [gdb_test "print filelocal_bss" "\\\$$decimal = 102" "print filelocal_bss at bar" ] {
347 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
348 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"] {
353 # Print scope1.c::filelocal_ro, which is 202
355 if [gdb_test "print filelocal_ro" "\\\$$decimal = 202" "print filelocal_ro in test_at_bar" ] {
360 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
361 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"] {
366 # Print scope1.c::foo::funclocal, which is 3
368 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
369 if [gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal at bar" ] {
374 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
375 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"] {
380 # Print scope1.c::foo::funclocal_bss, which is 103
382 if [gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" "print foo::funclocal_bss at bar" ] {
387 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
388 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"] {
393 # Print scope1.c::foo::funclocal_ro, which is 203
395 if [gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" "print foo::funclocal_ro at bar" ] {
400 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
401 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"] {
406 # Print scope1.c::bar::funclocal, which is 4
408 if [gdb_test "print funclocal" "\\\$$decimal = 4" "print funclocal at bar" ] {
413 if [gdb_test "print bar::funclocal" "\\\$$decimal = 4" "print bar::funclocal at bar" ] {
418 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
419 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"] {
424 # Print scope1.c::bar::funclocal_bss, which is 104
426 if [gdb_test "print funclocal_bss" "\\\$$decimal = 104" "print funclocal_bss at bar" ] {
431 if [gdb_test "print bar::funclocal_bss" "\\\$$decimal = 104" "print bar::funclocal_bss at bar" ] {
436 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
437 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"] {
440 gdb_stop_suppressing_tests;
444 # This test has little to do with local scopes, but it is in scope.exp anyway.
447 proc test_at_autovars {} {
453 # Test symbol table lookup with 100 local (auto) variables.
455 gdb_breakpoint marker1
457 if [gdb_test "cont" "Break.* marker1 \\(\\) at .*:$decimal.*" "continue to marker1"] {
461 if [gdb_test "up" ".*" "" ] {
466 while {$count < 100} {
467 if [gdb_test "print i$count" ".* = $count" "" ] {
471 set count [expr $count+1]
474 pass "$count auto variables correctly initialized"
476 # Test that block variable sorting is not screwing us.
477 gdb_test "frame" "#.*autovars \\(bcd=5, abc=6\\).*" "args in correct order"
480 proc test_at_localscopes {} {
486 gdb_breakpoint marker2
487 gdb_breakpoint marker3
488 gdb_breakpoint marker4
490 if [gdb_test "cont" "Break.* marker2 \\(\\) at .*:$decimal.*" "continue to marker2"] {
493 if [gdb_test "up" ".*" "" ] {
497 # Should be at first (outermost) scope. Check values.
499 gdb_test "print localval" " = 10" "print localval, outer scope"
500 gdb_test "print localval1" " = 11" "print localval1, outer scope"
501 gdb_test "print localval2" "No symbol \"localval2\" in current context." \
502 "print localval2, outer scope"
503 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
504 "print localval3, outer scope"
506 if [gdb_test "cont" "Break.* marker3 \\(\\) at .*:$decimal.*" \
507 "continue to marker3 in scope.exp"] then { gdb_suppress_tests }
508 if [gdb_test "up" "" "up from marker3 in scope.exp"] then { gdb_suppress_tests }
510 # Should be at next (first nested) scope. Check values.
512 gdb_test "print localval" " = 20" \
513 "print localval, first nested scope"
514 gdb_test "print localval1" " = 11" "print localval1, first nested scope"
515 gdb_test "print localval2" " = 12" "print localval2, first nested scope"
516 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
517 "print localval3, first nested scope"
519 # This test will only fail if the file was compiled by gcc, but
520 # there's no way to check that.
521 setup_xfail "a29k-*-udi" 2423
522 if [gdb_test "cont" "Break.* marker4.*at .*:$decimal.*" \
523 "continue to marker4 in scope.exp"] then { gdb_suppress_tests }
524 if [gdb_test "up" "" "up from marker4 in scope.exp"] then { gdb_suppress_tests }
526 gdb_test "print localval" " = 30" "print localval, innermost scope"
527 gdb_test "print localval1" " = 11" "print localval1, innermost scope"
528 gdb_test "print localval2" " = 12" "print localval2, innermost scope"
529 gdb_test "print localval3" " = 13" "print localval3, innermost scope"
530 gdb_stop_suppressing_tests;
533 # Start with a fresh gdb.
537 gdb_reinitialize_dir $srcdir/$subdir
540 if [istarget "*-*-vxworks*"] {
542 verbose "Timeout is now $timeout seconds" 2
545 # Test that variables in various segments print out correctly before
546 # the program is run.
548 # AIX--sections get mapped to the same address so we can't get the right one.
549 setup_xfail "rs6000-*-*"
550 setup_xfail "powerpc-*-*"
552 gdb_test "print 'scope0.c'::filelocal_ro" "= 201"
554 # gdb currently cannot access bss memory on some targets if the inferior
557 # For PA boards using monitor/remote-pa.c, the bss test is going to
558 # randomly fail. We've already put remote-pa on the target stack,
559 # so we actually read memory from the board. Problem is crt0.o
560 # is responsible for clearing bss and that hasnt' happened yet.
562 # This is a problem for all non-native targets. -- manson
564 unsupported "print 'scope0.c'::filelocal_bss before run"
566 gdb_test "print 'scope0.c'::filelocal_bss" "= 0" \
567 "print 'scope0.c'::filelocal_bss before run"
570 gdb_test "print 'scope0.c'::filelocal" "= 1" \
571 "print 'scope0.c'::filelocal before run"
573 if [runto_main] then { test_at_main }
574 if [istarget "mips-idt-*"] then {
575 # Restart because IDT/SIM runs out of file descriptors.
578 gdb_reinitialize_dir $srcdir/$subdir
581 if [runto foo] then { test_at_foo }
582 if [istarget "mips-idt-*"] then {
583 # Restart because IDT/SIM runs out of file descriptors.
586 gdb_reinitialize_dir $srcdir/$subdir
589 if [runto bar] then { test_at_bar }
590 if [istarget "mips-idt-*"] then {
591 # Restart because IDT/SIM runs out of file descriptors.
594 gdb_reinitialize_dir $srcdir/$subdir
597 if [runto localscopes] then { test_at_localscopes }
598 if [istarget "mips-idt-*"] then {
599 # Restart because IDT/SIM runs out of file descriptors.
602 gdb_reinitialize_dir $srcdir/$subdir
605 if [runto autovars] then { test_at_autovars }
607 if [istarget "*-*-vxworks*"] {
609 verbose "Timeout is now $timeout seconds" 2