1 # Copyright 1992-2019 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 {[build_executable "failed to build" ${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 {} {
44 # This used to do an extra "next" if the first one didn't get us
45 # over the call to init0, to handle calls to __main in the
46 # prologue, etc. But if a breakpoint at main doesn't leave us on
47 # the first line of real code in the function, that's a GDB bug.
48 gdb_test "next" "$decimal.*foo \\(\\);" "next over init0() in main"
50 # Print scope0.c::filelocal, which is 1
52 if [gdb_test "print filelocal" "\\\$$decimal = 1" "print filelocal" ] {
57 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"] {
62 # Print scope0.c::filelocal_bss, which is 101
64 if [gdb_test "print filelocal_bss" "\\\$$decimal = 101" "print filelocal_bss" ] {
69 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"] {
74 # Print scope0.c::filelocal_ro, which is 201
76 # No clue why the rs6000 fails this test.
77 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
78 if [gdb_test "print filelocal_ro" "\\\$$decimal = 201" "print filelocal_ro in test_at_main" ] {
83 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
84 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"] {
89 # Print scope1.c::filelocal, which is 2
91 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
92 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"] {
97 # Print scope1.c::filelocal_bss, which is 102
99 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
100 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"] {
105 # Print scope1.c::filelocal_ro, which is 202
107 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
108 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"] {
113 # Print scope1.c::foo::funclocal, which is 3
115 if [gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal" ] {
120 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
121 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"] {
126 # Print scope1.c::foo::funclocal_ro, which is 203
128 if [gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" "print foo::funclocal_ro" ] {
133 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
134 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"] {
139 # Print scope1.c::bar::funclocal, which is 4
141 if [gdb_test "print bar::funclocal" "\\\$$decimal = 4" "print bar::funclocal" ] {
146 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
147 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"] {
150 gdb_stop_suppressing_tests
154 proc test_at_foo {} {
161 if [gdb_test "next" ".*bar \\(\\);" "" ] {
166 # Print scope0.c::filelocal, which is 1
168 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"] {
173 # Print scope0.c::filelocal_bss, which is 101
175 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"] {
180 # Print scope0.c::filelocal_ro, which is 201
182 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
183 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"] {
188 gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at foo"
190 # Print scope1.c::filelocal, which is 2
192 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
193 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"] {
198 gdb_test "print filelocal_bss" "\\\$$decimal = 102" \
199 "print filelocal_bss at foo"
201 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
202 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"
205 gdb_test "print filelocal_ro" "\\\$$decimal = 202" \
206 "print filelocal_ro at foo"
208 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
209 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"
212 # Print scope1.c::foo::funclocal, which is 3
214 gdb_test "print funclocal" "\\\$$decimal = 3" "print funclocal at foo"
216 gdb_test "print foo::funclocal" "\\\$$decimal = 3" \
217 "print foo::funclocal at foo"
219 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
220 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"
223 # Print scope1.c::foo::funclocal_bss, which is 103
225 gdb_test "print funclocal_bss" "\\\$$decimal = 103" \
226 "print funclocal_bss at foo"
228 gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" \
229 "print foo::funclocal_bss at foo"
231 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
232 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"
235 # Print scope1.c::foo::funclocal_ro, which is 203
237 gdb_test "print funclocal_ro" "\\\$$decimal = 203" \
238 "print funclocal_ro at foo"
240 gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" \
241 "print foo::funclocal_ro at foo"
243 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
244 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"
247 # Print scope1.c::bar::funclocal, which is 4
249 gdb_test "print bar::funclocal" "\\\$$decimal = 4" \
250 "print bar::funclocal at foo"
252 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
253 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"
254 gdb_stop_suppressing_tests
258 proc test_at_bar {} {
265 if [gdb_test "next" ".*" "" ] {
270 # Print scope0.c::filelocal, which is 1
272 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"] {
277 # Print scope0.c::filelocal_bss, which is 101
279 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"] {
284 # Print scope0.c::filelocal_ro, which is 201
286 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
287 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"] {
292 # Print scope1.c::filelocal, which is 2
294 if [gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at bar" ] {
299 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
300 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"] {
305 # Print scope1.c::filelocal_bss, which is 102
307 if [gdb_test "print filelocal_bss" "\\\$$decimal = 102" "print filelocal_bss at bar" ] {
312 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
313 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"] {
318 # Print scope1.c::filelocal_ro, which is 202
320 if [gdb_test "print filelocal_ro" "\\\$$decimal = 202" "print filelocal_ro in test_at_bar" ] {
325 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
326 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"] {
331 # Print scope1.c::foo::funclocal, which is 3
333 if [gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal at bar" ] {
338 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
339 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"] {
344 # Print scope1.c::foo::funclocal_bss, which is 103
346 if [gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" "print foo::funclocal_bss at bar" ] {
351 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
352 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"] {
357 # Print scope1.c::foo::funclocal_ro, which is 203
359 if [gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" "print foo::funclocal_ro at bar" ] {
364 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
365 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"] {
370 # Print scope1.c::bar::funclocal, which is 4
372 if [gdb_test "print funclocal" "\\\$$decimal = 4" "print funclocal at bar" ] {
377 if [gdb_test "print bar::funclocal" "\\\$$decimal = 4" "print bar::funclocal at bar" ] {
382 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
383 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"] {
388 # Print scope1.c::bar::funclocal_bss, which is 104
390 if [gdb_test "print funclocal_bss" "\\\$$decimal = 104" "print funclocal_bss at bar" ] {
395 if [gdb_test "print bar::funclocal_bss" "\\\$$decimal = 104" "print bar::funclocal_bss at bar" ] {
400 if { [test_compiler_info gcc-*-*] } then { setup_xfail "rs6000-*-*" }
401 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"] {
404 gdb_stop_suppressing_tests
408 # This test has little to do with local scopes, but it is in scope.exp anyway.
411 proc test_at_autovars {} {
417 # Test symbol table lookup with 100 local (auto) variables.
419 gdb_breakpoint marker1
421 if [gdb_test "cont" "Break.* marker1 \\(\\) at .*:$decimal.*" "continue to marker1"] {
425 if [gdb_test "up" ".*autovars.*" "up from marker1 in scope.exp" ] {
430 while {$count < 100} {
431 if [gdb_test "print i$count" ".* = $count" "" ] {
435 set count [expr $count+1]
438 pass "$count auto variables correctly initialized"
440 # Test that block variable sorting is not screwing us.
441 gdb_test "frame" "#.*autovars \\(bcd=5, abc=6\\).*" "args in correct order"
444 proc test_at_localscopes {} {
450 gdb_breakpoint marker2
451 gdb_breakpoint marker3
452 gdb_breakpoint marker4
454 if [gdb_test "cont" "Break.* marker2 \\(\\) at .*:$decimal.*" "continue to marker2"] {
457 if [gdb_test "up" ".*localscopes.*" "up from marker2 in scopes.exp" ] {
461 # Should be at first (outermost) scope. Check values.
463 gdb_test "print localval" " = 10" "print localval, outer scope"
464 gdb_test "print localval1" " = 11" "print localval1, outer scope"
465 gdb_test "print localval2" "No symbol \"localval2\" in current context." \
466 "print localval2, outer scope"
467 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
468 "print localval3, outer scope"
470 if [gdb_test "cont" "Break.* marker3 \\(\\) at .*:$decimal.*" \
471 "continue to marker3 in scope.exp"] then { gdb_suppress_tests }
472 if [gdb_test "up" ".*localscopes.*" "up from marker3 in scope.exp"] {
476 # Should be at next (first nested) scope. Check values.
478 gdb_test "print localval" " = 20" \
479 "print localval, first nested scope"
480 gdb_test "print localval1" " = 11" "print localval1, first nested scope"
481 gdb_test "print localval2" " = 12" "print localval2, first nested scope"
482 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
483 "print localval3, first nested scope"
485 # This test will only fail if the file was compiled by gcc, but
486 # there's no way to check that.
487 if [gdb_test "cont" "Break.* marker4.*at .*:$decimal.*" \
488 "continue to marker4 in scope.exp"] then { gdb_suppress_tests }
489 if [gdb_test "up" ".*localscopes.*" "up from marker4 in scope.exp"] {
493 gdb_test "print localval" " = 30" "print localval, innermost scope"
494 gdb_test "print localval1" " = 11" "print localval1, innermost scope"
495 gdb_test "print localval2" " = 12" "print localval2, innermost scope"
496 gdb_test "print localval3" " = 13" "print localval3, innermost scope"
497 gdb_stop_suppressing_tests
500 # Note, we don't pass a binfile to clean_restart because we need to
501 # avoid gdb_load here. With remote targets, gdb_load connects to the
502 # remote target, and we specificaly want the following tests to run
503 # before the program is started.
505 gdb_file_cmd $binfile
507 # Test that variables in various segments print out correctly before
508 # the program is run.
510 # AIX--sections get mapped to the same address so we can't get the right one.
511 setup_xfail "rs6000-*-*"
513 gdb_test "print 'scope0.c'::filelocal_ro" "= 201"
515 # Check that gdb can access bss memory if the inferior is not running.
517 # Note the care above about avoiding gdb_load. Otherwise, for
518 # embedded stub-like boards, this test would randomly fail. If we'd
519 # already put target remote on the target stack, we'd read memory from
520 # the board instead of the program's binary, and we would have
521 # connected before crt0.o had had a chance to clear bss.
522 gdb_test "print 'scope0.c'::filelocal_bss" "= 0" \
523 "print 'scope0.c'::filelocal_bss before run"
525 gdb_test "print 'scope0.c'::filelocal" "= 1" \
526 "print 'scope0.c'::filelocal before run"
528 if [runto_main] then { test_at_main }
529 if [runto foo] then { test_at_foo }
530 if [runto bar] then { test_at_bar }
531 if [runto localscopes] then { test_at_localscopes }
532 if [runto autovars] then { test_at_autovars }