1 # Copyright 1992, 1994-2000, 2002-2004, 2007-2012 Free Software
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)
21 set binfile ${objdir}/${subdir}/${testfile}
24 if { [gdb_compile "${srcdir}/${subdir}/scope0.c" "${binfile}0.o" object {debug}] != "" } {
29 if { [gdb_compile "${srcdir}/${subdir}/scope1.c" "${binfile}1.o" object {debug}] != "" } {
34 if { [gdb_compile "${binfile}0.o ${binfile}1.o" ${binfile} executable {debug}] != "" } {
39 # Create and source the file that provides information about the compiler
40 # used to compile the test case.
41 if [get_compiler_info ${binfile}] {
45 # Test locating various things when stopped just inside main, after
46 # running init0(). To prevent cascading of errors, we report the
47 # first one and quit. If all pass, then we print the pass results.
49 proc test_at_main {} {
58 # This used to do an extra "next" if the first one didn't get us
59 # over the call to init0, to handle calls to __main in the
60 # prologue, etc. But if a breakpoint at main doesn't leave us on
61 # the first line of real code in the function, that's a GDB bug.
62 gdb_test "next" "$decimal.*foo \\(\\);" "next over init0() in main"
64 # Print scope0.c::filelocal, which is 1
66 if [gdb_test "print filelocal" "\\\$$decimal = 1" "print filelocal" ] {
71 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"] {
76 # Print scope0.c::filelocal_bss, which is 101
78 if [gdb_test "print filelocal_bss" "\\\$$decimal = 101" "print filelocal_bss" ] {
83 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"] {
88 # Print scope0.c::filelocal_ro, which is 201
90 # No clue why the rs6000 fails this test.
91 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
92 if [gdb_test "print filelocal_ro" "\\\$$decimal = 201" "print filelocal_ro in test_at_main" ] {
97 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
98 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"] {
103 # Print scope1.c::filelocal, which is 2
105 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
106 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"] {
111 # Print scope1.c::filelocal_bss, which is 102
113 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
114 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"] {
119 # Print scope1.c::filelocal_ro, which is 202
121 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
122 if {$hp_cc_compiler} then { setup_xfail "hppa2.0w-*-*" 11747CLLbs}
123 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"] {
128 # Print scope1.c::foo::funclocal, which is 3
130 if [gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal" ] {
135 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
136 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"] {
141 # Print scope1.c::foo::funclocal_ro, which is 203
143 if [gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" "print foo::funclocal_ro" ] {
148 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
149 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"] {
154 # Print scope1.c::bar::funclocal, which is 4
156 if [gdb_test "print bar::funclocal" "\\\$$decimal = 4" "print bar::funclocal" ] {
161 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
162 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"] {
165 gdb_stop_suppressing_tests;
169 proc test_at_foo {} {
176 if [gdb_test "next" ".*bar \\(\\);" "" ] {
181 # Print scope0.c::filelocal, which is 1
183 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"] {
188 # Print scope0.c::filelocal_bss, which is 101
190 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"] {
195 # Print scope0.c::filelocal_ro, which is 201
197 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
198 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"] {
203 gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at foo"
205 # Print scope1.c::filelocal, which is 2
207 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
208 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"] {
213 gdb_test "print filelocal_bss" "\\\$$decimal = 102" \
214 "print filelocal_bss at foo"
216 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
217 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"
220 gdb_test "print filelocal_ro" "\\\$$decimal = 202" \
221 "print filelocal_ro at foo"
223 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
224 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"
227 # Print scope1.c::foo::funclocal, which is 3
229 gdb_test "print funclocal" "\\\$$decimal = 3" "print funclocal at foo"
231 gdb_test "print foo::funclocal" "\\\$$decimal = 3" \
232 "print foo::funclocal at foo"
234 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
235 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"
238 # Print scope1.c::foo::funclocal_bss, which is 103
240 gdb_test "print funclocal_bss" "\\\$$decimal = 103" \
241 "print funclocal_bss at foo"
243 gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" \
244 "print foo::funclocal_bss at foo"
246 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
247 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"
250 # Print scope1.c::foo::funclocal_ro, which is 203
252 gdb_test "print funclocal_ro" "\\\$$decimal = 203" \
253 "print funclocal_ro at foo"
255 gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" \
256 "print foo::funclocal_ro at foo"
258 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
259 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"
262 # Print scope1.c::bar::funclocal, which is 4
264 gdb_test "print bar::funclocal" "\\\$$decimal = 4" \
265 "print bar::funclocal at foo"
267 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
268 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"
269 gdb_stop_suppressing_tests;
273 proc test_at_bar {} {
280 if [gdb_test "next" ".*" "" ] {
285 # Print scope0.c::filelocal, which is 1
287 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"] {
292 # Print scope0.c::filelocal_bss, which is 101
294 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"] {
299 # Print scope0.c::filelocal_ro, which is 201
301 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
302 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"] {
307 # Print scope1.c::filelocal, which is 2
309 if [gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at bar" ] {
314 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
315 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"] {
320 # Print scope1.c::filelocal_bss, which is 102
322 if [gdb_test "print filelocal_bss" "\\\$$decimal = 102" "print filelocal_bss at bar" ] {
327 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
328 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"] {
333 # Print scope1.c::filelocal_ro, which is 202
335 if [gdb_test "print filelocal_ro" "\\\$$decimal = 202" "print filelocal_ro in test_at_bar" ] {
340 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
341 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"] {
346 # Print scope1.c::foo::funclocal, which is 3
348 if [gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal at bar" ] {
353 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
354 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"] {
359 # Print scope1.c::foo::funclocal_bss, which is 103
361 if [gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" "print foo::funclocal_bss at bar" ] {
366 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
367 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"] {
372 # Print scope1.c::foo::funclocal_ro, which is 203
374 if [gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" "print foo::funclocal_ro at bar" ] {
379 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
380 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"] {
385 # Print scope1.c::bar::funclocal, which is 4
387 if [gdb_test "print funclocal" "\\\$$decimal = 4" "print funclocal at bar" ] {
392 if [gdb_test "print bar::funclocal" "\\\$$decimal = 4" "print bar::funclocal at bar" ] {
397 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
398 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"] {
403 # Print scope1.c::bar::funclocal_bss, which is 104
405 if [gdb_test "print funclocal_bss" "\\\$$decimal = 104" "print funclocal_bss at bar" ] {
410 if [gdb_test "print bar::funclocal_bss" "\\\$$decimal = 104" "print bar::funclocal_bss at bar" ] {
415 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
416 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"] {
419 gdb_stop_suppressing_tests;
423 # This test has little to do with local scopes, but it is in scope.exp anyway.
426 proc test_at_autovars {} {
432 # Test symbol table lookup with 100 local (auto) variables.
434 gdb_breakpoint marker1
436 if [gdb_test "cont" "Break.* marker1 \\(\\) at .*:$decimal.*" "continue to marker1"] {
440 if [gdb_test "up" ".*autovars.*" "up from marker1 in scope.exp" ] {
445 while {$count < 100} {
446 if [gdb_test "print i$count" ".* = $count" "" ] {
450 set count [expr $count+1]
453 pass "$count auto variables correctly initialized"
455 # Test that block variable sorting is not screwing us.
456 gdb_test "frame" "#.*autovars \\(bcd=5, abc=6\\).*" "args in correct order"
459 proc test_at_localscopes {} {
465 gdb_breakpoint marker2
466 gdb_breakpoint marker3
467 gdb_breakpoint marker4
469 if [gdb_test "cont" "Break.* marker2 \\(\\) at .*:$decimal.*" "continue to marker2"] {
472 if [gdb_test "up" ".*localscopes.*" "up from marker2 in scopes.exp" ] {
476 # Should be at first (outermost) scope. Check values.
478 gdb_test "print localval" " = 10" "print localval, outer scope"
479 gdb_test "print localval1" " = 11" "print localval1, outer scope"
480 gdb_test "print localval2" "No symbol \"localval2\" in current context." \
481 "print localval2, outer scope"
482 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
483 "print localval3, outer scope"
485 if [gdb_test "cont" "Break.* marker3 \\(\\) at .*:$decimal.*" \
486 "continue to marker3 in scope.exp"] then { gdb_suppress_tests }
487 if [gdb_test "up" ".*localscopes.*" "up from marker3 in scope.exp"] {
491 # Should be at next (first nested) scope. Check values.
493 gdb_test "print localval" " = 20" \
494 "print localval, first nested scope"
495 gdb_test "print localval1" " = 11" "print localval1, first nested scope"
496 gdb_test "print localval2" " = 12" "print localval2, first nested scope"
497 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
498 "print localval3, first nested scope"
500 # This test will only fail if the file was compiled by gcc, but
501 # there's no way to check that.
502 if [gdb_test "cont" "Break.* marker4.*at .*:$decimal.*" \
503 "continue to marker4 in scope.exp"] then { gdb_suppress_tests }
504 if [gdb_test "up" ".*localscopes.*" "up from marker4 in scope.exp"] {
508 gdb_test "print localval" " = 30" "print localval, innermost scope"
509 gdb_test "print localval1" " = 11" "print localval1, innermost scope"
510 gdb_test "print localval2" " = 12" "print localval2, innermost scope"
511 gdb_test "print localval3" " = 13" "print localval3, innermost scope"
512 gdb_stop_suppressing_tests;
515 # Start with a fresh gdb.
519 gdb_reinitialize_dir $srcdir/$subdir
522 if [istarget "*-*-vxworks*"] {
524 verbose "Timeout is now $timeout seconds" 2
527 # Test that variables in various segments print out correctly before
528 # the program is run.
530 # AIX--sections get mapped to the same address so we can't get the right one.
531 setup_xfail "rs6000-*-*"
533 gdb_test "print 'scope0.c'::filelocal_ro" "= 201"
535 # gdb currently cannot access bss memory on some targets if the inferior
538 # For PA boards using monitor/remote-pa.c, the bss test is going to
539 # randomly fail. We've already put remote-pa on the target stack,
540 # so we actually read memory from the board. Problem is crt0.o
541 # is responsible for clearing bss and that hasnt' happened yet.
543 # This is a problem for all non-native targets. -- manson
544 if [is_remote target] {
545 unsupported "print 'scope0.c'::filelocal_bss before run"
547 gdb_test "print 'scope0.c'::filelocal_bss" "= 0" \
548 "print 'scope0.c'::filelocal_bss before run"
551 gdb_test "print 'scope0.c'::filelocal" "= 1" \
552 "print 'scope0.c'::filelocal before run"
554 if [runto_main] then { test_at_main }
555 if [runto foo] then { test_at_foo }
556 if [runto bar] then { test_at_bar }
557 if [runto localscopes] then { test_at_localscopes }
558 if [runto autovars] then { test_at_autovars }
560 if [istarget "*-*-vxworks*"] {
562 verbose "Timeout is now $timeout seconds" 2