1 # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004,
2 # 2007, 2008, 2009 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 3 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, see <http://www.gnu.org/licenses/>.
17 # This file was written by Fred Fish. (fnf@cygnus.com)
27 set binfile ${objdir}/${subdir}/${testfile}
30 if { [gdb_compile "${srcdir}/${subdir}/scope0.c" "${binfile}0.o" object {debug}] != "" } {
35 if { [gdb_compile "${srcdir}/${subdir}/scope1.c" "${binfile}1.o" object {debug}] != "" } {
40 if { [gdb_compile "${binfile}0.o ${binfile}1.o" ${binfile} executable {debug}] != "" } {
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 # This used to do an extra "next" if the first one didn't get us
65 # over the call to init0, to handle calls to __main in the
66 # prologue, etc. But if a breakpoint at main doesn't leave us on
67 # the first line of real code in the function, that's a GDB bug.
68 gdb_test "next" "$decimal.*foo \\(\\);" "next over init0() in main"
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 rs6000 fails this test.
97 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
98 if [gdb_test "print filelocal_ro" "\\\$$decimal = 201" "print filelocal_ro in test_at_main" ] {
103 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
104 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"] {
109 # Print scope1.c::filelocal, which is 2
111 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
112 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"] {
117 # Print scope1.c::filelocal_bss, which is 102
119 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
120 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"] {
125 # Print scope1.c::filelocal_ro, which is 202
127 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
128 if {$hp_cc_compiler} then { setup_xfail "hppa2.0w-*-*" 11747CLLbs}
129 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"] {
134 # Print scope1.c::foo::funclocal, which is 3
136 if [gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal" ] {
141 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
142 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"] {
147 # Print scope1.c::foo::funclocal_ro, which is 203
149 if [gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" "print foo::funclocal_ro" ] {
154 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
155 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"] {
160 # Print scope1.c::bar::funclocal, which is 4
162 if [gdb_test "print bar::funclocal" "\\\$$decimal = 4" "print bar::funclocal" ] {
167 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
168 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"] {
171 gdb_stop_suppressing_tests;
175 proc test_at_foo {} {
182 if [gdb_test "next" ".*bar \\(\\);" "" ] {
187 # Print scope0.c::filelocal, which is 1
189 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"] {
194 # Print scope0.c::filelocal_bss, which is 101
196 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"] {
201 # Print scope0.c::filelocal_ro, which is 201
203 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
204 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"] {
209 gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at foo"
211 # Print scope1.c::filelocal, which is 2
213 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
214 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"] {
219 gdb_test "print filelocal_bss" "\\\$$decimal = 102" \
220 "print filelocal_bss at foo"
222 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
223 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"
226 gdb_test "print filelocal_ro" "\\\$$decimal = 202" \
227 "print filelocal_ro at foo"
229 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
230 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"
233 # Print scope1.c::foo::funclocal, which is 3
235 gdb_test "print funclocal" "\\\$$decimal = 3" "print funclocal at foo"
237 gdb_test "print foo::funclocal" "\\\$$decimal = 3" \
238 "print foo::funclocal at foo"
240 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
241 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"
244 # Print scope1.c::foo::funclocal_bss, which is 103
246 gdb_test "print funclocal_bss" "\\\$$decimal = 103" \
247 "print funclocal_bss at foo"
249 gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" \
250 "print foo::funclocal_bss at foo"
252 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
253 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"
256 # Print scope1.c::foo::funclocal_ro, which is 203
258 gdb_test "print funclocal_ro" "\\\$$decimal = 203" \
259 "print funclocal_ro at foo"
261 gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" \
262 "print foo::funclocal_ro at foo"
264 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
265 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"
268 # Print scope1.c::bar::funclocal, which is 4
270 gdb_test "print bar::funclocal" "\\\$$decimal = 4" \
271 "print bar::funclocal at foo"
273 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
274 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"
275 gdb_stop_suppressing_tests;
279 proc test_at_bar {} {
286 if [gdb_test "next" ".*" "" ] {
291 # Print scope0.c::filelocal, which is 1
293 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"] {
298 # Print scope0.c::filelocal_bss, which is 101
300 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"] {
305 # Print scope0.c::filelocal_ro, which is 201
307 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
308 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"] {
313 # Print scope1.c::filelocal, which is 2
315 if [gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at bar" ] {
320 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
321 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"] {
326 # Print scope1.c::filelocal_bss, which is 102
328 if [gdb_test "print filelocal_bss" "\\\$$decimal = 102" "print filelocal_bss at bar" ] {
333 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
334 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"] {
339 # Print scope1.c::filelocal_ro, which is 202
341 if [gdb_test "print filelocal_ro" "\\\$$decimal = 202" "print filelocal_ro in test_at_bar" ] {
346 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
347 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"] {
352 # Print scope1.c::foo::funclocal, which is 3
354 if [gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal at bar" ] {
359 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
360 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"] {
365 # Print scope1.c::foo::funclocal_bss, which is 103
367 if [gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" "print foo::funclocal_bss at bar" ] {
372 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
373 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"] {
378 # Print scope1.c::foo::funclocal_ro, which is 203
380 if [gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" "print foo::funclocal_ro at bar" ] {
385 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
386 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"] {
391 # Print scope1.c::bar::funclocal, which is 4
393 if [gdb_test "print funclocal" "\\\$$decimal = 4" "print funclocal at bar" ] {
398 if [gdb_test "print bar::funclocal" "\\\$$decimal = 4" "print bar::funclocal at bar" ] {
403 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
404 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"] {
409 # Print scope1.c::bar::funclocal_bss, which is 104
411 if [gdb_test "print funclocal_bss" "\\\$$decimal = 104" "print funclocal_bss at bar" ] {
416 if [gdb_test "print bar::funclocal_bss" "\\\$$decimal = 104" "print bar::funclocal_bss at bar" ] {
421 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
422 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"] {
425 gdb_stop_suppressing_tests;
429 # This test has little to do with local scopes, but it is in scope.exp anyway.
432 proc test_at_autovars {} {
438 # Test symbol table lookup with 100 local (auto) variables.
440 gdb_breakpoint marker1
442 if [gdb_test "cont" "Break.* marker1 \\(\\) at .*:$decimal.*" "continue to marker1"] {
446 if [gdb_test "up" ".*autovars.*" "up from marker1 in scope.exp" ] {
451 while {$count < 100} {
452 if [gdb_test "print i$count" ".* = $count" "" ] {
456 set count [expr $count+1]
459 pass "$count auto variables correctly initialized"
461 # Test that block variable sorting is not screwing us.
462 gdb_test "frame" "#.*autovars \\(bcd=5, abc=6\\).*" "args in correct order"
465 proc test_at_localscopes {} {
471 gdb_breakpoint marker2
472 gdb_breakpoint marker3
473 gdb_breakpoint marker4
475 if [gdb_test "cont" "Break.* marker2 \\(\\) at .*:$decimal.*" "continue to marker2"] {
478 if [gdb_test "up" ".*localscopes.*" "up from marker2 in scopes.exp" ] {
482 # Should be at first (outermost) scope. Check values.
484 gdb_test "print localval" " = 10" "print localval, outer scope"
485 gdb_test "print localval1" " = 11" "print localval1, outer scope"
486 gdb_test "print localval2" "No symbol \"localval2\" in current context." \
487 "print localval2, outer scope"
488 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
489 "print localval3, outer scope"
491 if [gdb_test "cont" "Break.* marker3 \\(\\) at .*:$decimal.*" \
492 "continue to marker3 in scope.exp"] then { gdb_suppress_tests }
493 if [gdb_test "up" ".*localscopes.*" "up from marker3 in scope.exp"] {
497 # Should be at next (first nested) scope. Check values.
499 gdb_test "print localval" " = 20" \
500 "print localval, first nested scope"
501 gdb_test "print localval1" " = 11" "print localval1, first nested scope"
502 gdb_test "print localval2" " = 12" "print localval2, first nested scope"
503 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
504 "print localval3, first nested scope"
506 # This test will only fail if the file was compiled by gcc, but
507 # there's no way to check that.
508 if [gdb_test "cont" "Break.* marker4.*at .*:$decimal.*" \
509 "continue to marker4 in scope.exp"] then { gdb_suppress_tests }
510 if [gdb_test "up" ".*localscopes.*" "up from marker4 in scope.exp"] {
514 gdb_test "print localval" " = 30" "print localval, innermost scope"
515 gdb_test "print localval1" " = 11" "print localval1, innermost scope"
516 gdb_test "print localval2" " = 12" "print localval2, innermost scope"
517 gdb_test "print localval3" " = 13" "print localval3, innermost scope"
518 gdb_stop_suppressing_tests;
521 # Start with a fresh gdb.
525 gdb_reinitialize_dir $srcdir/$subdir
528 if [istarget "*-*-vxworks*"] {
530 verbose "Timeout is now $timeout seconds" 2
533 # Test that variables in various segments print out correctly before
534 # the program is run.
536 # AIX--sections get mapped to the same address so we can't get the right one.
537 setup_xfail "rs6000-*-*"
539 gdb_test "print 'scope0.c'::filelocal_ro" "= 201"
541 # gdb currently cannot access bss memory on some targets if the inferior
544 # For PA boards using monitor/remote-pa.c, the bss test is going to
545 # randomly fail. We've already put remote-pa on the target stack,
546 # so we actually read memory from the board. Problem is crt0.o
547 # is responsible for clearing bss and that hasnt' happened yet.
549 # This is a problem for all non-native targets. -- manson
550 if [is_remote target] {
551 unsupported "print 'scope0.c'::filelocal_bss before run"
553 gdb_test "print 'scope0.c'::filelocal_bss" "= 0" \
554 "print 'scope0.c'::filelocal_bss before run"
557 gdb_test "print 'scope0.c'::filelocal" "= 1" \
558 "print 'scope0.c'::filelocal before run"
560 if [runto_main] then { test_at_main }
561 if [istarget "mips-idt-*"] then {
562 # Restart because IDT/SIM runs out of file descriptors.
565 gdb_reinitialize_dir $srcdir/$subdir
568 if [runto foo] then { test_at_foo }
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 bar] then { test_at_bar }
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 localscopes] then { test_at_localscopes }
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 autovars] then { test_at_autovars }
594 if [istarget "*-*-vxworks*"] {
596 verbose "Timeout is now $timeout seconds" 2