1 # Copyright (C) 1992, 1994 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17 # Please email any bugs, comments, and/or additions to this file to:
30 set binfile ${objdir}/${subdir}/${testfile}
31 if { [gdb_compile "${srcdir}/${subdir}/scope0.c ${srcdir}/${subdir}/scope1.c" "${binfile}" executable {debug}] != "" } {
32 perror "Couldn't compile scope0.c to object"
36 # Create and source the file that provides information about the compiler
37 # used to compile the test case.
38 if [get_compiler_info ${binfile}] {
42 # Test locating various things when stopped just inside main, after
43 # running init(). To prevent cascading of errors, we report the
44 # first one and quit. If all pass, then we print the pass results.
46 proc test_at_main {} {
54 # skip past init. There may be a call to __main at the start of
55 # main, so the first next may only get us to the init call.
56 if [gdb_test "next" "$decimal.*foo \\(\\);" "next over init() in main" "$decimal.*init \\(\\);" "next"] {
61 # Print scope0.c::filelocal, which is 1
63 if [gdb_test "print filelocal" "\\\$$decimal = 1" "print filelocal" ] {
68 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"] {
73 # Print scope0.c::filelocal_bss, which is 101
75 if [gdb_test "print filelocal_bss" "\\\$$decimal = 101" "print filelocal_bss" ] {
80 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"] {
85 # Print scope0.c::filelocal_ro, which is 201
87 # No clue why the powerpc fails this test.
88 setup_xfail "powerpc-*-*"
89 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
90 if [gdb_test "print filelocal_ro" "\\\$$decimal = 201" "print filelocal_ro in test_at_main" ] {
95 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
96 setup_xfail "powerpc-*-*"
97 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"] {
102 # Print scope1.c::filelocal, which is 2
104 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
105 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"] {
110 # Print scope1.c::filelocal_bss, which is 102
112 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
113 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"] {
118 # Print scope1.c::filelocal_ro, which is 202
120 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
121 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"] {
126 # Print scope1.c::foo::funclocal, which is 3
128 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
129 if [gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal" ] {
134 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
135 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"] {
140 # Print scope1.c::foo::funclocal_ro, which is 203
142 if [gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" "print foo::funclocal_ro" ] {
147 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
148 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"] {
153 # Print scope1.c::bar::funclocal, which is 4
155 if [gdb_test "print bar::funclocal" "\\\$$decimal = 4" "print bar::funclocal" ] {
160 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
161 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"] {
167 proc test_at_foo {} {
175 if [gdb_test "next" ".*bar \\(\\);" "" ] {
180 # Print scope0.c::filelocal, which is 1
182 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"] {
187 # Print scope0.c::filelocal_bss, which is 101
189 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"] {
194 # Print scope0.c::filelocal_ro, which is 201
196 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
197 setup_xfail "powerpc-*-*"
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 {$gcc_compiled} 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 {$gcc_compiled} 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 {$gcc_compiled} 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 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
232 gdb_test "print foo::funclocal" "\\\$$decimal = 3" \
233 "print foo::funclocal at foo"
235 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
236 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
237 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"
240 # Print scope1.c::foo::funclocal_bss, which is 103
242 gdb_test "print funclocal_bss" "\\\$$decimal = 103" \
243 "print funclocal_bss at foo"
245 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
246 gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" \
247 "print foo::funclocal_bss at foo"
249 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
250 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
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 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
260 gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" \
261 "print foo::funclocal_ro at foo"
263 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
264 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
265 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"
268 # Print scope1.c::bar::funclocal, which is 4
270 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
271 gdb_test "print bar::funclocal" "\\\$$decimal = 4" \
272 "print bar::funclocal at foo"
274 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
275 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
276 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"
280 proc test_at_bar {} {
288 if [gdb_test "next" ".*" "" ] {
293 # Print scope0.c::filelocal, which is 1
295 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"] {
300 # Print scope0.c::filelocal_bss, which is 101
302 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"] {
307 # Print scope0.c::filelocal_ro, which is 201
309 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
310 setup_xfail "powerpc-*-*"
311 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"] {
316 # Print scope1.c::filelocal, which is 2
318 if [gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at bar" ] {
323 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
324 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"] {
329 # Print scope1.c::filelocal_bss, which is 102
331 if [gdb_test "print filelocal_bss" "\\\$$decimal = 102" "print filelocal_bss at bar" ] {
336 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
337 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"] {
342 # Print scope1.c::filelocal_ro, which is 202
344 if [gdb_test "print filelocal_ro" "\\\$$decimal = 202" "print filelocal_ro in test_at_bar" ] {
349 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
350 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"] {
355 # Print scope1.c::foo::funclocal, which is 3
357 if {!$gcc_compiled} then { setup_xfail "hppa*-*-hpux*" }
358 if [gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal at bar" ] {
363 if {$gcc_compiled} 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 {$gcc_compiled} 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 {$gcc_compiled} 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 {$gcc_compiled} 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 {$gcc_compiled} 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"] {
432 # This test has little to do with local scopes, but it is in scope.exp anyway.
435 proc test_at_autovars {} {
441 # Test symbol table lookup with 100 local (auto) variables.
443 gdb_breakpoint marker1
445 if [gdb_test "cont" "Break.* marker1 \\(\\) at .*:$decimal.*" "continue to marker1"] {
449 if [gdb_test "up" ".*" "" ] {
454 while {$count < 100} {
455 if [gdb_test "print i$count" ".* = $count" "" ] {
459 set count [expr $count+1]
462 pass "$count auto variables correctly initialized"
464 # Test that block variable sorting is not screwing us.
465 gdb_test "frame" "#.*autovars \\(bcd=5, abc=6\\).*" "args in correct order"
468 proc test_at_localscopes {} {
474 gdb_breakpoint marker2
475 gdb_breakpoint marker3
476 gdb_breakpoint marker4
478 if [gdb_test "cont" "Break.* marker2 \\(\\) at .*:$decimal.*" "continue to marker2"] {
481 if [gdb_test "up" ".*" "" ] {
485 # Should be at first (outermost) scope. Check values.
487 gdb_test "print localval" " = 10" "print localval, outer scope"
488 gdb_test "print localval1" " = 11" "print localval1, outer scope"
489 gdb_test "print localval2" "No symbol \"localval2\" in current context." \
490 "print localval2, outer scope"
491 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
492 "print localval3, outer scope"
494 if [gdb_test "cont" "Break.* marker3 \\(\\) at .*:$decimal.*" \
495 "continue to marker3 in scope.exp"] then { return }
496 if [gdb_test "up" "" "up from marker3 in scope.exp"] then { return }
498 # Should be at next (first nested) scope. Check values.
500 gdb_test "print localval" " = 20" \
501 "print localval, first nested scope"
502 gdb_test "print localval1" " = 11" "print localval1, first nested scope"
503 gdb_test "print localval2" " = 12" "print localval2, first nested scope"
504 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
505 "print localval3, first nested scope"
507 # This test will only fail if the file was compiled by gcc, but
508 # there's no way to check that.
509 setup_xfail "a29k-*-udi" 2423
510 if [gdb_test "cont" "Break.* marker4.*at .*:$decimal.*" \
511 "continue to marker4 in scope.exp"] then { return }
512 if [gdb_test "up" "" "up from marker4 in scope.exp"] then { return }
514 gdb_test "print localval" " = 30" "print localval, innermost scope"
515 gdb_test "print localval1" " = 11" "print localval1, innermost scope"
516 gdb_test "print localval2" " = 12" "print localval2, innermost scope"
517 gdb_test "print localval3" " = 13" "print localval3, innermost scope"
520 # Start with a fresh gdb.
524 gdb_reinitialize_dir $srcdir/$subdir
527 if [istarget "*-*-vxworks*"] {
529 verbose "Timeout is now $timeout seconds" 2
532 # Test that variables in various segments print out correctly before
533 # the program is run.
535 # AIX--sections get mapped to the same address so we can't get the right one.
536 setup_xfail "rs6000-*-*"
537 setup_xfail "powerpc-*-*"
539 gdb_test "print 'scope0.c'::filelocal_ro" "= 201"
541 # gdb currently cannot access bss memory on some targets if the inferior
544 # For PA boards using monitor/remote-pa.c, the bss test is going to
545 # randomly fail. We've already put remote-pa on the target stack,
546 # so we actually read memory from the board. Problem is crt0.o
547 # is responsible for clearing bss and that hasnt' happened yet.
548 setup_xfail "hppa*-*-*pro*"
549 send_gdb "print 'scope0.c'::filelocal_bss\n"
551 -re " = 0\r\n$gdb_prompt $" {
552 pass "print 'scope0.c'::filelocal_bss before run"
554 -re "Cannot access memory.*$gdb_prompt $" {
556 fail "print 'scope0.c'::filelocal_bss before run"
558 -re ".*$gdb_prompt $" {
559 fail "print 'scope0.c'::filelocal_bss before run"
562 fail "print 'scope0.c'::filelocal_bss before run"
566 gdb_test "print 'scope0.c'::filelocal" "= 1" \
567 "print 'scope0.c'::filelocal before run"
569 if [runto_main] then { test_at_main }
570 if [istarget "mips-idt-*"] then {
571 # Restart because IDT/SIM runs out of file descriptors.
574 gdb_reinitialize_dir $srcdir/$subdir
577 if [runto foo] then { test_at_foo }
578 if [istarget "mips-idt-*"] then {
579 # Restart because IDT/SIM runs out of file descriptors.
582 gdb_reinitialize_dir $srcdir/$subdir
585 if [runto bar] then { test_at_bar }
586 if [istarget "mips-idt-*"] then {
587 # Restart because IDT/SIM runs out of file descriptors.
590 gdb_reinitialize_dir $srcdir/$subdir
593 if [runto localscopes] then { test_at_localscopes }
594 if [istarget "mips-idt-*"] then {
595 # Restart because IDT/SIM runs out of file descriptors.
598 gdb_reinitialize_dir $srcdir/$subdir
601 if [runto autovars] then { test_at_autovars }
603 if [istarget "*-*-vxworks*"] {
605 verbose "Timeout is now $timeout seconds" 2