1 # Copyright 1992-2014 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 3 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, see <http://www.gnu.org/licenses/>.
16 # This file was written by Fred Fish. (fnf@cygnus.com)
19 standard_testfile scope0.c scope1.c
21 if {[prepare_for_testing ${testfile}.exp ${testfile} \
22 [list $srcfile $srcfile2] {debug}]} {
26 # Create and source the file that provides information about the compiler
27 # used to compile the test case.
28 if [get_compiler_info] {
32 # Test locating various things when stopped just inside main, after
33 # running init0(). To prevent cascading of errors, we report the
34 # first one and quit. If all pass, then we print the pass results.
36 proc test_at_main {} {
45 # This used to do an extra "next" if the first one didn't get us
46 # over the call to init0, to handle calls to __main in the
47 # prologue, etc. But if a breakpoint at main doesn't leave us on
48 # the first line of real code in the function, that's a GDB bug.
49 gdb_test "next" "$decimal.*foo \\(\\);" "next over init0() in main"
51 # Print scope0.c::filelocal, which is 1
53 if [gdb_test "print filelocal" "\\\$$decimal = 1" "print filelocal" ] {
58 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"] {
63 # Print scope0.c::filelocal_bss, which is 101
65 if [gdb_test "print filelocal_bss" "\\\$$decimal = 101" "print filelocal_bss" ] {
70 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"] {
75 # Print scope0.c::filelocal_ro, which is 201
77 # No clue why the rs6000 fails this test.
78 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
79 if [gdb_test "print filelocal_ro" "\\\$$decimal = 201" "print filelocal_ro in test_at_main" ] {
84 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
85 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"] {
90 # Print scope1.c::filelocal, which is 2
92 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
93 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"] {
98 # Print scope1.c::filelocal_bss, which is 102
100 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
101 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"] {
106 # Print scope1.c::filelocal_ro, which is 202
108 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
109 if {$hp_cc_compiler} then { setup_xfail "hppa2.0w-*-*" 11747CLLbs}
110 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"] {
115 # Print scope1.c::foo::funclocal, which is 3
117 if [gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal" ] {
122 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
123 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"] {
128 # Print scope1.c::foo::funclocal_ro, which is 203
130 if [gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" "print foo::funclocal_ro" ] {
135 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
136 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"] {
141 # Print scope1.c::bar::funclocal, which is 4
143 if [gdb_test "print bar::funclocal" "\\\$$decimal = 4" "print bar::funclocal" ] {
148 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
149 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"] {
152 gdb_stop_suppressing_tests
156 proc test_at_foo {} {
163 if [gdb_test "next" ".*bar \\(\\);" "" ] {
168 # Print scope0.c::filelocal, which is 1
170 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"] {
175 # Print scope0.c::filelocal_bss, which is 101
177 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"] {
182 # Print scope0.c::filelocal_ro, which is 201
184 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
185 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"] {
190 gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at foo"
192 # Print scope1.c::filelocal, which is 2
194 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
195 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"] {
200 gdb_test "print filelocal_bss" "\\\$$decimal = 102" \
201 "print filelocal_bss at foo"
203 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
204 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"
207 gdb_test "print filelocal_ro" "\\\$$decimal = 202" \
208 "print filelocal_ro at foo"
210 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
211 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"
214 # Print scope1.c::foo::funclocal, which is 3
216 gdb_test "print funclocal" "\\\$$decimal = 3" "print funclocal at foo"
218 gdb_test "print foo::funclocal" "\\\$$decimal = 3" \
219 "print foo::funclocal at foo"
221 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
222 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"
225 # Print scope1.c::foo::funclocal_bss, which is 103
227 gdb_test "print funclocal_bss" "\\\$$decimal = 103" \
228 "print funclocal_bss at foo"
230 gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" \
231 "print foo::funclocal_bss at foo"
233 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
234 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"
237 # Print scope1.c::foo::funclocal_ro, which is 203
239 gdb_test "print funclocal_ro" "\\\$$decimal = 203" \
240 "print funclocal_ro at foo"
242 gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" \
243 "print foo::funclocal_ro at foo"
245 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
246 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"
249 # Print scope1.c::bar::funclocal, which is 4
251 gdb_test "print bar::funclocal" "\\\$$decimal = 4" \
252 "print bar::funclocal at foo"
254 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
255 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"
256 gdb_stop_suppressing_tests
260 proc test_at_bar {} {
267 if [gdb_test "next" ".*" "" ] {
272 # Print scope0.c::filelocal, which is 1
274 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"] {
279 # Print scope0.c::filelocal_bss, which is 101
281 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"] {
286 # Print scope0.c::filelocal_ro, which is 201
288 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
289 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"] {
294 # Print scope1.c::filelocal, which is 2
296 if [gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at bar" ] {
301 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
302 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"] {
307 # Print scope1.c::filelocal_bss, which is 102
309 if [gdb_test "print filelocal_bss" "\\\$$decimal = 102" "print filelocal_bss at bar" ] {
314 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
315 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"] {
320 # Print scope1.c::filelocal_ro, which is 202
322 if [gdb_test "print filelocal_ro" "\\\$$decimal = 202" "print filelocal_ro in test_at_bar" ] {
327 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
328 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"] {
333 # Print scope1.c::foo::funclocal, which is 3
335 if [gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal at bar" ] {
340 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
341 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"] {
346 # Print scope1.c::foo::funclocal_bss, which is 103
348 if [gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" "print foo::funclocal_bss at bar" ] {
353 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
354 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"] {
359 # Print scope1.c::foo::funclocal_ro, which is 203
361 if [gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" "print foo::funclocal_ro at bar" ] {
366 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
367 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"] {
372 # Print scope1.c::bar::funclocal, which is 4
374 if [gdb_test "print funclocal" "\\\$$decimal = 4" "print funclocal at bar" ] {
379 if [gdb_test "print bar::funclocal" "\\\$$decimal = 4" "print bar::funclocal at bar" ] {
384 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
385 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"] {
390 # Print scope1.c::bar::funclocal_bss, which is 104
392 if [gdb_test "print funclocal_bss" "\\\$$decimal = 104" "print funclocal_bss at bar" ] {
397 if [gdb_test "print bar::funclocal_bss" "\\\$$decimal = 104" "print bar::funclocal_bss at bar" ] {
402 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
403 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"] {
406 gdb_stop_suppressing_tests
410 # This test has little to do with local scopes, but it is in scope.exp anyway.
413 proc test_at_autovars {} {
419 # Test symbol table lookup with 100 local (auto) variables.
421 gdb_breakpoint marker1
423 if [gdb_test "cont" "Break.* marker1 \\(\\) at .*:$decimal.*" "continue to marker1"] {
427 if [gdb_test "up" ".*autovars.*" "up from marker1 in scope.exp" ] {
432 while {$count < 100} {
433 if [gdb_test "print i$count" ".* = $count" "" ] {
437 set count [expr $count+1]
440 pass "$count auto variables correctly initialized"
442 # Test that block variable sorting is not screwing us.
443 gdb_test "frame" "#.*autovars \\(bcd=5, abc=6\\).*" "args in correct order"
446 proc test_at_localscopes {} {
452 gdb_breakpoint marker2
453 gdb_breakpoint marker3
454 gdb_breakpoint marker4
456 if [gdb_test "cont" "Break.* marker2 \\(\\) at .*:$decimal.*" "continue to marker2"] {
459 if [gdb_test "up" ".*localscopes.*" "up from marker2 in scopes.exp" ] {
463 # Should be at first (outermost) scope. Check values.
465 gdb_test "print localval" " = 10" "print localval, outer scope"
466 gdb_test "print localval1" " = 11" "print localval1, outer scope"
467 gdb_test "print localval2" "No symbol \"localval2\" in current context." \
468 "print localval2, outer scope"
469 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
470 "print localval3, outer scope"
472 if [gdb_test "cont" "Break.* marker3 \\(\\) at .*:$decimal.*" \
473 "continue to marker3 in scope.exp"] then { gdb_suppress_tests }
474 if [gdb_test "up" ".*localscopes.*" "up from marker3 in scope.exp"] {
478 # Should be at next (first nested) scope. Check values.
480 gdb_test "print localval" " = 20" \
481 "print localval, first nested scope"
482 gdb_test "print localval1" " = 11" "print localval1, first nested scope"
483 gdb_test "print localval2" " = 12" "print localval2, first nested scope"
484 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
485 "print localval3, first nested scope"
487 # This test will only fail if the file was compiled by gcc, but
488 # there's no way to check that.
489 if [gdb_test "cont" "Break.* marker4.*at .*:$decimal.*" \
490 "continue to marker4 in scope.exp"] then { gdb_suppress_tests }
491 if [gdb_test "up" ".*localscopes.*" "up from marker4 in scope.exp"] {
495 gdb_test "print localval" " = 30" "print localval, innermost scope"
496 gdb_test "print localval1" " = 11" "print localval1, innermost scope"
497 gdb_test "print localval2" " = 12" "print localval2, innermost scope"
498 gdb_test "print localval3" " = 13" "print localval3, innermost scope"
499 gdb_stop_suppressing_tests
502 # Test that variables in various segments print out correctly before
503 # the program is run.
505 # AIX--sections get mapped to the same address so we can't get the right one.
506 setup_xfail "rs6000-*-*"
508 gdb_test "print 'scope0.c'::filelocal_ro" "= 201"
510 # gdb currently cannot access bss memory on some targets if the inferior
513 # For PA boards using monitor/remote-pa.c, the bss test is going to
514 # randomly fail. We've already put remote-pa on the target stack,
515 # so we actually read memory from the board. Problem is crt0.o
516 # is responsible for clearing bss and that hasnt' happened yet.
518 # This is a problem for all non-native targets. -- manson
519 if [is_remote target] {
520 unsupported "print 'scope0.c'::filelocal_bss before run"
522 gdb_test "print 'scope0.c'::filelocal_bss" "= 0" \
523 "print 'scope0.c'::filelocal_bss before run"
526 gdb_test "print 'scope0.c'::filelocal" "= 1" \
527 "print 'scope0.c'::filelocal before run"
529 if [runto_main] then { test_at_main }
530 if [runto foo] then { test_at_foo }
531 if [runto bar] then { test_at_bar }
532 if [runto localscopes] then { test_at_localscopes }
533 if [runto autovars] then { test_at_autovars }