1 # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004,
2 # 2007 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}] != "" } {
39 if { [gdb_compile "${srcdir}/${subdir}/scope1.c" "${binfile}1.o" object {debug}] != "" } {
44 if { [gdb_compile "${binfile}0.o ${binfile}1.o" ${binfile} executable {debug}] != "" } {
49 # Create and source the file that provides information about the compiler
50 # used to compile the test case.
51 if [get_compiler_info ${binfile}] {
55 # Test locating various things when stopped just inside main, after
56 # running init0(). To prevent cascading of errors, we report the
57 # first one and quit. If all pass, then we print the pass results.
59 proc test_at_main {} {
68 # This used to do an extra "next" if the first one didn't get us
69 # over the call to init0, to handle calls to __main in the
70 # prologue, etc. But if a breakpoint at main doesn't leave us on
71 # the first line of real code in the function, that's a GDB bug.
72 gdb_test "next" "$decimal.*foo \\(\\);" "next over init0() in main"
74 # Print scope0.c::filelocal, which is 1
76 if [gdb_test "print filelocal" "\\\$$decimal = 1" "print filelocal" ] {
81 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"] {
86 # Print scope0.c::filelocal_bss, which is 101
88 if [gdb_test "print filelocal_bss" "\\\$$decimal = 101" "print filelocal_bss" ] {
93 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"] {
98 # Print scope0.c::filelocal_ro, which is 201
100 # No clue why the rs6000 fails this test.
101 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
102 if [gdb_test "print filelocal_ro" "\\\$$decimal = 201" "print filelocal_ro in test_at_main" ] {
107 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
108 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"] {
113 # Print scope1.c::filelocal, which is 2
115 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
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 [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"] {
129 # Print scope1.c::filelocal_ro, which is 202
131 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
132 if {$hp_cc_compiler} then { setup_xfail "hppa2.0w-*-*" 11747CLLbs}
133 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"] {
138 # Print scope1.c::foo::funclocal, which is 3
140 if [gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal" ] {
145 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
146 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"] {
151 # Print scope1.c::foo::funclocal_ro, which is 203
153 if [gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" "print foo::funclocal_ro" ] {
158 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
159 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"] {
164 # Print scope1.c::bar::funclocal, which is 4
166 if [gdb_test "print bar::funclocal" "\\\$$decimal = 4" "print bar::funclocal" ] {
171 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
172 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"] {
175 gdb_stop_suppressing_tests;
179 proc test_at_foo {} {
186 if [gdb_test "next" ".*bar \\(\\);" "" ] {
191 # Print scope0.c::filelocal, which is 1
193 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"] {
198 # Print scope0.c::filelocal_bss, which is 101
200 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"] {
205 # Print scope0.c::filelocal_ro, which is 201
207 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
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 { [test_compiler_info gcc-*-*] } 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 { [test_compiler_info gcc-*-*] } 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 { [test_compiler_info gcc-*-*] } 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 gdb_test "print foo::funclocal" "\\\$$decimal = 3" \
242 "print foo::funclocal at foo"
244 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
245 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"
248 # Print scope1.c::foo::funclocal_bss, which is 103
250 gdb_test "print funclocal_bss" "\\\$$decimal = 103" \
251 "print funclocal_bss at foo"
253 gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" \
254 "print foo::funclocal_bss at foo"
256 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
257 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"
260 # Print scope1.c::foo::funclocal_ro, which is 203
262 gdb_test "print funclocal_ro" "\\\$$decimal = 203" \
263 "print funclocal_ro at foo"
265 gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" \
266 "print foo::funclocal_ro at foo"
268 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
269 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"
272 # Print scope1.c::bar::funclocal, which is 4
274 gdb_test "print bar::funclocal" "\\\$$decimal = 4" \
275 "print bar::funclocal at foo"
277 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
278 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"
279 gdb_stop_suppressing_tests;
283 proc test_at_bar {} {
290 if [gdb_test "next" ".*" "" ] {
295 # Print scope0.c::filelocal, which is 1
297 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"] {
302 # Print scope0.c::filelocal_bss, which is 101
304 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"] {
309 # Print scope0.c::filelocal_ro, which is 201
311 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
312 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"] {
317 # Print scope1.c::filelocal, which is 2
319 if [gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at bar" ] {
324 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
325 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"] {
330 # Print scope1.c::filelocal_bss, which is 102
332 if [gdb_test "print filelocal_bss" "\\\$$decimal = 102" "print filelocal_bss at bar" ] {
337 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
338 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"] {
343 # Print scope1.c::filelocal_ro, which is 202
345 if [gdb_test "print filelocal_ro" "\\\$$decimal = 202" "print filelocal_ro in test_at_bar" ] {
350 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
351 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"] {
356 # Print scope1.c::foo::funclocal, which is 3
358 if [gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal at bar" ] {
363 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
364 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"] {
369 # Print scope1.c::foo::funclocal_bss, which is 103
371 if [gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" "print foo::funclocal_bss at bar" ] {
376 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
377 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"] {
382 # Print scope1.c::foo::funclocal_ro, which is 203
384 if [gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" "print foo::funclocal_ro at bar" ] {
389 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
390 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"] {
395 # Print scope1.c::bar::funclocal, which is 4
397 if [gdb_test "print funclocal" "\\\$$decimal = 4" "print funclocal at bar" ] {
402 if [gdb_test "print bar::funclocal" "\\\$$decimal = 4" "print bar::funclocal at bar" ] {
407 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
408 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"] {
413 # Print scope1.c::bar::funclocal_bss, which is 104
415 if [gdb_test "print funclocal_bss" "\\\$$decimal = 104" "print funclocal_bss at bar" ] {
420 if [gdb_test "print bar::funclocal_bss" "\\\$$decimal = 104" "print bar::funclocal_bss at bar" ] {
425 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
426 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"] {
429 gdb_stop_suppressing_tests;
433 # This test has little to do with local scopes, but it is in scope.exp anyway.
436 proc test_at_autovars {} {
442 # Test symbol table lookup with 100 local (auto) variables.
444 gdb_breakpoint marker1
446 if [gdb_test "cont" "Break.* marker1 \\(\\) at .*:$decimal.*" "continue to marker1"] {
450 if [gdb_test "up" ".*autovars.*" "up from marker1 in scope.exp" ] {
455 while {$count < 100} {
456 if [gdb_test "print i$count" ".* = $count" "" ] {
460 set count [expr $count+1]
463 pass "$count auto variables correctly initialized"
465 # Test that block variable sorting is not screwing us.
466 gdb_test "frame" "#.*autovars \\(bcd=5, abc=6\\).*" "args in correct order"
469 proc test_at_localscopes {} {
475 gdb_breakpoint marker2
476 gdb_breakpoint marker3
477 gdb_breakpoint marker4
479 if [gdb_test "cont" "Break.* marker2 \\(\\) at .*:$decimal.*" "continue to marker2"] {
482 if [gdb_test "up" ".*localscopes.*" "up from marker2 in scopes.exp" ] {
486 # Should be at first (outermost) scope. Check values.
488 gdb_test "print localval" " = 10" "print localval, outer scope"
489 gdb_test "print localval1" " = 11" "print localval1, outer scope"
490 gdb_test "print localval2" "No symbol \"localval2\" in current context." \
491 "print localval2, outer scope"
492 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
493 "print localval3, outer scope"
495 if [gdb_test "cont" "Break.* marker3 \\(\\) at .*:$decimal.*" \
496 "continue to marker3 in scope.exp"] then { gdb_suppress_tests }
497 if [gdb_test "up" ".*localscopes.*" "up from marker3 in scope.exp"] {
501 # Should be at next (first nested) scope. Check values.
503 gdb_test "print localval" " = 20" \
504 "print localval, first nested scope"
505 gdb_test "print localval1" " = 11" "print localval1, first nested scope"
506 gdb_test "print localval2" " = 12" "print localval2, first nested scope"
507 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
508 "print localval3, first nested scope"
510 # This test will only fail if the file was compiled by gcc, but
511 # there's no way to check that.
512 if [gdb_test "cont" "Break.* marker4.*at .*:$decimal.*" \
513 "continue to marker4 in scope.exp"] then { gdb_suppress_tests }
514 if [gdb_test "up" ".*localscopes.*" "up from marker4 in scope.exp"] {
518 gdb_test "print localval" " = 30" "print localval, innermost scope"
519 gdb_test "print localval1" " = 11" "print localval1, innermost scope"
520 gdb_test "print localval2" " = 12" "print localval2, innermost scope"
521 gdb_test "print localval3" " = 13" "print localval3, innermost scope"
522 gdb_stop_suppressing_tests;
525 # Start with a fresh gdb.
529 gdb_reinitialize_dir $srcdir/$subdir
532 if [istarget "*-*-vxworks*"] {
534 verbose "Timeout is now $timeout seconds" 2
537 # Test that variables in various segments print out correctly before
538 # the program is run.
540 # AIX--sections get mapped to the same address so we can't get the right one.
541 setup_xfail "rs6000-*-*"
543 gdb_test "print 'scope0.c'::filelocal_ro" "= 201"
545 # gdb currently cannot access bss memory on some targets if the inferior
548 # For PA boards using monitor/remote-pa.c, the bss test is going to
549 # randomly fail. We've already put remote-pa on the target stack,
550 # so we actually read memory from the board. Problem is crt0.o
551 # is responsible for clearing bss and that hasnt' happened yet.
553 # This is a problem for all non-native targets. -- manson
554 if [is_remote target] {
555 unsupported "print 'scope0.c'::filelocal_bss before run"
557 gdb_test "print 'scope0.c'::filelocal_bss" "= 0" \
558 "print 'scope0.c'::filelocal_bss before run"
561 gdb_test "print 'scope0.c'::filelocal" "= 1" \
562 "print 'scope0.c'::filelocal before run"
564 if [runto_main] then { test_at_main }
565 if [istarget "mips-idt-*"] then {
566 # Restart because IDT/SIM runs out of file descriptors.
569 gdb_reinitialize_dir $srcdir/$subdir
572 if [runto foo] then { test_at_foo }
573 if [istarget "mips-idt-*"] then {
574 # Restart because IDT/SIM runs out of file descriptors.
577 gdb_reinitialize_dir $srcdir/$subdir
580 if [runto bar] then { test_at_bar }
581 if [istarget "mips-idt-*"] then {
582 # Restart because IDT/SIM runs out of file descriptors.
585 gdb_reinitialize_dir $srcdir/$subdir
588 if [runto localscopes] then { test_at_localscopes }
589 if [istarget "mips-idt-*"] then {
590 # Restart because IDT/SIM runs out of file descriptors.
593 gdb_reinitialize_dir $srcdir/$subdir
596 if [runto autovars] then { test_at_autovars }
598 if [istarget "*-*-vxworks*"] {
600 verbose "Timeout is now $timeout seconds" 2