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-*-*" }
116 if {$hp_cc_compiler} then { setup_xfail "hppa2.0w-*-*"}
117 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"] {
122 # Print scope1.c::filelocal_bss, which is 102
124 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
126 if {$hp_cc_compiler} then { setup_xfail "hppa2.0w-*-*"}
127 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"] {
132 # Print scope1.c::filelocal_ro, which is 202
134 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
136 if {$hp_cc_compiler} then { setup_xfail "hppa2.0w-*-*"}
137 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"] {
142 # Print scope1.c::foo::funclocal, which is 3
144 if [gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal" ] {
149 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
150 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"] {
155 # Print scope1.c::foo::funclocal_ro, which is 203
157 if [gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" "print foo::funclocal_ro" ] {
162 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
163 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"] {
168 # Print scope1.c::bar::funclocal, which is 4
170 if [gdb_test "print bar::funclocal" "\\\$$decimal = 4" "print bar::funclocal" ] {
175 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
176 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"] {
179 gdb_stop_suppressing_tests;
183 proc test_at_foo {} {
191 if [gdb_test "next" ".*bar \\(\\);" "" ] {
196 # Print scope0.c::filelocal, which is 1
198 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"] {
203 # Print scope0.c::filelocal_bss, which is 101
205 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"] {
210 # Print scope0.c::filelocal_ro, which is 201
212 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
213 setup_xfail "powerpc-*-*"
214 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"] {
219 gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at foo"
221 # Print scope1.c::filelocal, which is 2
223 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
224 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"] {
229 gdb_test "print filelocal_bss" "\\\$$decimal = 102" \
230 "print filelocal_bss at foo"
232 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
233 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"
236 gdb_test "print filelocal_ro" "\\\$$decimal = 202" \
237 "print filelocal_ro at foo"
239 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
240 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"
243 # Print scope1.c::foo::funclocal, which is 3
245 gdb_test "print funclocal" "\\\$$decimal = 3" "print funclocal at foo"
247 gdb_test "print foo::funclocal" "\\\$$decimal = 3" \
248 "print foo::funclocal at foo"
250 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
251 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"
254 # Print scope1.c::foo::funclocal_bss, which is 103
256 gdb_test "print funclocal_bss" "\\\$$decimal = 103" \
257 "print funclocal_bss at foo"
259 gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" \
260 "print foo::funclocal_bss at foo"
262 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
263 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"
266 # Print scope1.c::foo::funclocal_ro, which is 203
268 gdb_test "print funclocal_ro" "\\\$$decimal = 203" \
269 "print funclocal_ro at foo"
271 gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" \
272 "print foo::funclocal_ro at foo"
274 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
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 gdb_test "print bar::funclocal" "\\\$$decimal = 4" \
281 "print bar::funclocal at foo"
283 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
284 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"
285 gdb_stop_suppressing_tests;
289 proc test_at_bar {} {
297 if [gdb_test "next" ".*" "" ] {
302 # Print scope0.c::filelocal, which is 1
304 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"] {
309 # Print scope0.c::filelocal_bss, which is 101
311 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"] {
316 # Print scope0.c::filelocal_ro, which is 201
318 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
319 setup_xfail "powerpc-*-*"
320 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"] {
325 # Print scope1.c::filelocal, which is 2
327 if [gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at bar" ] {
332 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
333 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"] {
338 # Print scope1.c::filelocal_bss, which is 102
340 if [gdb_test "print filelocal_bss" "\\\$$decimal = 102" "print filelocal_bss at bar" ] {
345 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
346 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"] {
351 # Print scope1.c::filelocal_ro, which is 202
353 if [gdb_test "print filelocal_ro" "\\\$$decimal = 202" "print filelocal_ro in test_at_bar" ] {
358 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
359 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"] {
364 # Print scope1.c::foo::funclocal, which is 3
366 if [gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal at bar" ] {
371 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
372 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"] {
377 # Print scope1.c::foo::funclocal_bss, which is 103
379 if [gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" "print foo::funclocal_bss at bar" ] {
384 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
385 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"] {
390 # Print scope1.c::foo::funclocal_ro, which is 203
392 if [gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" "print foo::funclocal_ro at bar" ] {
397 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
398 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"] {
403 # Print scope1.c::bar::funclocal, which is 4
405 if [gdb_test "print funclocal" "\\\$$decimal = 4" "print funclocal at bar" ] {
410 if [gdb_test "print bar::funclocal" "\\\$$decimal = 4" "print bar::funclocal at bar" ] {
415 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
416 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"] {
421 # Print scope1.c::bar::funclocal_bss, which is 104
423 if [gdb_test "print funclocal_bss" "\\\$$decimal = 104" "print funclocal_bss at bar" ] {
428 if [gdb_test "print bar::funclocal_bss" "\\\$$decimal = 104" "print bar::funclocal_bss at bar" ] {
433 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
434 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"] {
437 gdb_stop_suppressing_tests;
441 # This test has little to do with local scopes, but it is in scope.exp anyway.
444 proc test_at_autovars {} {
450 # Test symbol table lookup with 100 local (auto) variables.
452 gdb_breakpoint marker1
454 if [gdb_test "cont" "Break.* marker1 \\(\\) at .*:$decimal.*" "continue to marker1"] {
458 if [gdb_test "up" ".*" "" ] {
463 while {$count < 100} {
464 if [gdb_test "print i$count" ".* = $count" "" ] {
468 set count [expr $count+1]
471 pass "$count auto variables correctly initialized"
473 # Test that block variable sorting is not screwing us.
474 gdb_test "frame" "#.*autovars \\(bcd=5, abc=6\\).*" "args in correct order"
477 proc test_at_localscopes {} {
483 gdb_breakpoint marker2
484 gdb_breakpoint marker3
485 gdb_breakpoint marker4
487 if [gdb_test "cont" "Break.* marker2 \\(\\) at .*:$decimal.*" "continue to marker2"] {
490 if [gdb_test "up" ".*" "" ] {
494 # Should be at first (outermost) scope. Check values.
496 gdb_test "print localval" " = 10" "print localval, outer scope"
497 gdb_test "print localval1" " = 11" "print localval1, outer scope"
498 gdb_test "print localval2" "No symbol \"localval2\" in current context." \
499 "print localval2, outer scope"
500 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
501 "print localval3, outer scope"
503 if [gdb_test "cont" "Break.* marker3 \\(\\) at .*:$decimal.*" \
504 "continue to marker3 in scope.exp"] then { gdb_suppress_tests }
505 if [gdb_test "up" "" "up from marker3 in scope.exp"] then { gdb_suppress_tests }
507 # Should be at next (first nested) scope. Check values.
509 gdb_test "print localval" " = 20" \
510 "print localval, first nested scope"
511 gdb_test "print localval1" " = 11" "print localval1, first nested scope"
512 gdb_test "print localval2" " = 12" "print localval2, first nested scope"
513 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
514 "print localval3, first nested scope"
516 # This test will only fail if the file was compiled by gcc, but
517 # there's no way to check that.
518 setup_xfail "a29k-*-udi" 2423
519 if [gdb_test "cont" "Break.* marker4.*at .*:$decimal.*" \
520 "continue to marker4 in scope.exp"] then { gdb_suppress_tests }
521 if [gdb_test "up" "" "up from marker4 in scope.exp"] then { gdb_suppress_tests }
523 gdb_test "print localval" " = 30" "print localval, innermost scope"
524 gdb_test "print localval1" " = 11" "print localval1, innermost scope"
525 gdb_test "print localval2" " = 12" "print localval2, innermost scope"
526 gdb_test "print localval3" " = 13" "print localval3, innermost scope"
527 gdb_stop_suppressing_tests;
530 # Start with a fresh gdb.
534 gdb_reinitialize_dir $srcdir/$subdir
537 if [istarget "*-*-vxworks*"] {
539 verbose "Timeout is now $timeout seconds" 2
542 # Test that variables in various segments print out correctly before
543 # the program is run.
545 # AIX--sections get mapped to the same address so we can't get the right one.
546 setup_xfail "rs6000-*-*"
547 setup_xfail "powerpc-*-*"
549 gdb_test "print 'scope0.c'::filelocal_ro" "= 201"
551 # gdb currently cannot access bss memory on some targets if the inferior
554 # For PA boards using monitor/remote-pa.c, the bss test is going to
555 # randomly fail. We've already put remote-pa on the target stack,
556 # so we actually read memory from the board. Problem is crt0.o
557 # is responsible for clearing bss and that hasnt' happened yet.
559 # This is a problem for all non-native targets. -- manson
561 unsupported "print 'scope0.c'::filelocal_bss before run"
563 gdb_test "print 'scope0.c'::filelocal_bss" "= 0" \
564 "print 'scope0.c'::filelocal_bss before run"
567 gdb_test "print 'scope0.c'::filelocal" "= 1" \
568 "print 'scope0.c'::filelocal before run"
570 if [runto_main] then { test_at_main }
571 if [istarget "mips-idt-*"] then {
572 # Restart because IDT/SIM runs out of file descriptors.
575 gdb_reinitialize_dir $srcdir/$subdir
578 if [runto foo] then { test_at_foo }
579 if [istarget "mips-idt-*"] then {
580 # Restart because IDT/SIM runs out of file descriptors.
583 gdb_reinitialize_dir $srcdir/$subdir
586 if [runto bar] then { test_at_bar }
587 if [istarget "mips-idt-*"] then {
588 # Restart because IDT/SIM runs out of file descriptors.
591 gdb_reinitialize_dir $srcdir/$subdir
594 if [runto localscopes] then { test_at_localscopes }
595 if [istarget "mips-idt-*"] then {
596 # Restart because IDT/SIM runs out of file descriptors.
599 gdb_reinitialize_dir $srcdir/$subdir
602 if [runto autovars] then { test_at_autovars }
604 if [istarget "*-*-vxworks*"] {
606 verbose "Timeout is now $timeout seconds" 2