1 # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004,
2 # 2007, 2008, 2009, 2010, 2011 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)
25 set binfile ${objdir}/${subdir}/${testfile}
28 if { [gdb_compile "${srcdir}/${subdir}/scope0.c" "${binfile}0.o" object {debug}] != "" } {
33 if { [gdb_compile "${srcdir}/${subdir}/scope1.c" "${binfile}1.o" object {debug}] != "" } {
38 if { [gdb_compile "${binfile}0.o ${binfile}1.o" ${binfile} executable {debug}] != "" } {
43 # Create and source the file that provides information about the compiler
44 # used to compile the test case.
45 if [get_compiler_info ${binfile}] {
49 # Test locating various things when stopped just inside main, after
50 # running init0(). To prevent cascading of errors, we report the
51 # first one and quit. If all pass, then we print the pass results.
53 proc test_at_main {} {
62 # This used to do an extra "next" if the first one didn't get us
63 # over the call to init0, to handle calls to __main in the
64 # prologue, etc. But if a breakpoint at main doesn't leave us on
65 # the first line of real code in the function, that's a GDB bug.
66 gdb_test "next" "$decimal.*foo \\(\\);" "next over init0() in main"
68 # Print scope0.c::filelocal, which is 1
70 if [gdb_test "print filelocal" "\\\$$decimal = 1" "print filelocal" ] {
75 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"] {
80 # Print scope0.c::filelocal_bss, which is 101
82 if [gdb_test "print filelocal_bss" "\\\$$decimal = 101" "print filelocal_bss" ] {
87 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"] {
92 # Print scope0.c::filelocal_ro, which is 201
94 # No clue why the rs6000 fails this test.
95 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
96 if [gdb_test "print filelocal_ro" "\\\$$decimal = 201" "print filelocal_ro in test_at_main" ] {
101 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
102 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"] {
107 # Print scope1.c::filelocal, which is 2
109 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
110 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"] {
115 # Print scope1.c::filelocal_bss, which is 102
117 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
118 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"] {
123 # Print scope1.c::filelocal_ro, which is 202
125 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
126 if {$hp_cc_compiler} then { setup_xfail "hppa2.0w-*-*" 11747CLLbs}
127 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"] {
132 # Print scope1.c::foo::funclocal, which is 3
134 if [gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal" ] {
139 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
140 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"] {
145 # Print scope1.c::foo::funclocal_ro, which is 203
147 if [gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" "print foo::funclocal_ro" ] {
152 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
153 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"] {
158 # Print scope1.c::bar::funclocal, which is 4
160 if [gdb_test "print bar::funclocal" "\\\$$decimal = 4" "print bar::funclocal" ] {
165 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
166 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"] {
169 gdb_stop_suppressing_tests;
173 proc test_at_foo {} {
180 if [gdb_test "next" ".*bar \\(\\);" "" ] {
185 # Print scope0.c::filelocal, which is 1
187 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"] {
192 # Print scope0.c::filelocal_bss, which is 101
194 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"] {
199 # Print scope0.c::filelocal_ro, which is 201
201 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
202 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"] {
207 gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at foo"
209 # Print scope1.c::filelocal, which is 2
211 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
212 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"] {
217 gdb_test "print filelocal_bss" "\\\$$decimal = 102" \
218 "print filelocal_bss at foo"
220 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
221 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"
224 gdb_test "print filelocal_ro" "\\\$$decimal = 202" \
225 "print filelocal_ro at foo"
227 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
228 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"
231 # Print scope1.c::foo::funclocal, which is 3
233 gdb_test "print funclocal" "\\\$$decimal = 3" "print funclocal at foo"
235 gdb_test "print foo::funclocal" "\\\$$decimal = 3" \
236 "print foo::funclocal at foo"
238 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
239 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"
242 # Print scope1.c::foo::funclocal_bss, which is 103
244 gdb_test "print funclocal_bss" "\\\$$decimal = 103" \
245 "print funclocal_bss at foo"
247 gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" \
248 "print foo::funclocal_bss at foo"
250 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
251 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"
254 # Print scope1.c::foo::funclocal_ro, which is 203
256 gdb_test "print funclocal_ro" "\\\$$decimal = 203" \
257 "print funclocal_ro at foo"
259 gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" \
260 "print foo::funclocal_ro at foo"
262 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
263 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"
266 # Print scope1.c::bar::funclocal, which is 4
268 gdb_test "print bar::funclocal" "\\\$$decimal = 4" \
269 "print bar::funclocal at foo"
271 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
272 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"
273 gdb_stop_suppressing_tests;
277 proc test_at_bar {} {
284 if [gdb_test "next" ".*" "" ] {
289 # Print scope0.c::filelocal, which is 1
291 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"] {
296 # Print scope0.c::filelocal_bss, which is 101
298 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"] {
303 # Print scope0.c::filelocal_ro, which is 201
305 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
306 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"] {
311 # Print scope1.c::filelocal, which is 2
313 if [gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at bar" ] {
318 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
319 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"] {
324 # Print scope1.c::filelocal_bss, which is 102
326 if [gdb_test "print filelocal_bss" "\\\$$decimal = 102" "print filelocal_bss at bar" ] {
331 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
332 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"] {
337 # Print scope1.c::filelocal_ro, which is 202
339 if [gdb_test "print filelocal_ro" "\\\$$decimal = 202" "print filelocal_ro in test_at_bar" ] {
344 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
345 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"] {
350 # Print scope1.c::foo::funclocal, which is 3
352 if [gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal at bar" ] {
357 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
358 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"] {
363 # Print scope1.c::foo::funclocal_bss, which is 103
365 if [gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" "print foo::funclocal_bss at bar" ] {
370 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
371 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"] {
376 # Print scope1.c::foo::funclocal_ro, which is 203
378 if [gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" "print foo::funclocal_ro at bar" ] {
383 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
384 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"] {
389 # Print scope1.c::bar::funclocal, which is 4
391 if [gdb_test "print funclocal" "\\\$$decimal = 4" "print funclocal at bar" ] {
396 if [gdb_test "print bar::funclocal" "\\\$$decimal = 4" "print bar::funclocal at bar" ] {
401 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
402 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"] {
407 # Print scope1.c::bar::funclocal_bss, which is 104
409 if [gdb_test "print funclocal_bss" "\\\$$decimal = 104" "print funclocal_bss at bar" ] {
414 if [gdb_test "print bar::funclocal_bss" "\\\$$decimal = 104" "print bar::funclocal_bss at bar" ] {
419 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
420 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"] {
423 gdb_stop_suppressing_tests;
427 # This test has little to do with local scopes, but it is in scope.exp anyway.
430 proc test_at_autovars {} {
436 # Test symbol table lookup with 100 local (auto) variables.
438 gdb_breakpoint marker1
440 if [gdb_test "cont" "Break.* marker1 \\(\\) at .*:$decimal.*" "continue to marker1"] {
444 if [gdb_test "up" ".*autovars.*" "up from marker1 in scope.exp" ] {
449 while {$count < 100} {
450 if [gdb_test "print i$count" ".* = $count" "" ] {
454 set count [expr $count+1]
457 pass "$count auto variables correctly initialized"
459 # Test that block variable sorting is not screwing us.
460 gdb_test "frame" "#.*autovars \\(bcd=5, abc=6\\).*" "args in correct order"
463 proc test_at_localscopes {} {
469 gdb_breakpoint marker2
470 gdb_breakpoint marker3
471 gdb_breakpoint marker4
473 if [gdb_test "cont" "Break.* marker2 \\(\\) at .*:$decimal.*" "continue to marker2"] {
476 if [gdb_test "up" ".*localscopes.*" "up from marker2 in scopes.exp" ] {
480 # Should be at first (outermost) scope. Check values.
482 gdb_test "print localval" " = 10" "print localval, outer scope"
483 gdb_test "print localval1" " = 11" "print localval1, outer scope"
484 gdb_test "print localval2" "No symbol \"localval2\" in current context." \
485 "print localval2, outer scope"
486 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
487 "print localval3, outer scope"
489 if [gdb_test "cont" "Break.* marker3 \\(\\) at .*:$decimal.*" \
490 "continue to marker3 in scope.exp"] then { gdb_suppress_tests }
491 if [gdb_test "up" ".*localscopes.*" "up from marker3 in scope.exp"] {
495 # Should be at next (first nested) scope. Check values.
497 gdb_test "print localval" " = 20" \
498 "print localval, first nested scope"
499 gdb_test "print localval1" " = 11" "print localval1, first nested scope"
500 gdb_test "print localval2" " = 12" "print localval2, first nested scope"
501 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
502 "print localval3, first nested scope"
504 # This test will only fail if the file was compiled by gcc, but
505 # there's no way to check that.
506 if [gdb_test "cont" "Break.* marker4.*at .*:$decimal.*" \
507 "continue to marker4 in scope.exp"] then { gdb_suppress_tests }
508 if [gdb_test "up" ".*localscopes.*" "up from marker4 in scope.exp"] {
512 gdb_test "print localval" " = 30" "print localval, innermost scope"
513 gdb_test "print localval1" " = 11" "print localval1, innermost scope"
514 gdb_test "print localval2" " = 12" "print localval2, innermost scope"
515 gdb_test "print localval3" " = 13" "print localval3, innermost scope"
516 gdb_stop_suppressing_tests;
519 # Start with a fresh gdb.
523 gdb_reinitialize_dir $srcdir/$subdir
526 if [istarget "*-*-vxworks*"] {
528 verbose "Timeout is now $timeout seconds" 2
531 # Test that variables in various segments print out correctly before
532 # the program is run.
534 # AIX--sections get mapped to the same address so we can't get the right one.
535 setup_xfail "rs6000-*-*"
537 gdb_test "print 'scope0.c'::filelocal_ro" "= 201"
539 # gdb currently cannot access bss memory on some targets if the inferior
542 # For PA boards using monitor/remote-pa.c, the bss test is going to
543 # randomly fail. We've already put remote-pa on the target stack,
544 # so we actually read memory from the board. Problem is crt0.o
545 # is responsible for clearing bss and that hasnt' happened yet.
547 # This is a problem for all non-native targets. -- manson
548 if [is_remote target] {
549 unsupported "print 'scope0.c'::filelocal_bss before run"
551 gdb_test "print 'scope0.c'::filelocal_bss" "= 0" \
552 "print 'scope0.c'::filelocal_bss before run"
555 gdb_test "print 'scope0.c'::filelocal" "= 1" \
556 "print 'scope0.c'::filelocal before run"
558 if [runto_main] then { test_at_main }
559 if [istarget "mips-idt-*"] then {
560 # Restart because IDT/SIM runs out of file descriptors.
563 gdb_reinitialize_dir $srcdir/$subdir
566 if [runto foo] then { test_at_foo }
567 if [istarget "mips-idt-*"] then {
568 # Restart because IDT/SIM runs out of file descriptors.
571 gdb_reinitialize_dir $srcdir/$subdir
574 if [runto bar] then { test_at_bar }
575 if [istarget "mips-idt-*"] then {
576 # Restart because IDT/SIM runs out of file descriptors.
579 gdb_reinitialize_dir $srcdir/$subdir
582 if [runto localscopes] then { test_at_localscopes }
583 if [istarget "mips-idt-*"] then {
584 # Restart because IDT/SIM runs out of file descriptors.
587 gdb_reinitialize_dir $srcdir/$subdir
590 if [runto autovars] then { test_at_autovars }
592 if [istarget "*-*-vxworks*"] {
594 verbose "Timeout is now $timeout seconds" 2