]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/scope.exp
5d3cf8f70b24ded77fd0a988d4978ad406428082
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / scope.exp
1 # Copyright (C) 1992, 1994 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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. */
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 # This file was written by Fred Fish. (fnf@cygnus.com)
21
22 if $tracelevel then {
23 strace $tracelevel
24 }
25
26 set prms_id 0
27 set bug_id 0
28
29 set binfile "scope"
30 set srcfile $binfile.c
31
32 if ![file exists $objdir/$subdir/$binfile] then {
33 perror "$objdir/$subdir/$binfile does not exist."
34 return 0
35 }
36
37 source gdb.base/scope0.ci
38
39 # Test locating various things when stopped just inside main, after
40 # running init(). To prevent cascading of errors, we report the
41 # first one and quit. If all pass, then we print the pass results.
42
43 proc test_at_main {} {
44 global prompt
45 global decimal
46 global det_file
47 global srcdir
48 global subdir
49 global gcc_compiled
50
51 # skip past init. There may be a call to __main at the start of
52 # main, so the first next may only get us to the init call.
53 send "next\n"
54 expect {
55 -re "$decimal.*foo \\(\\);\r\n$prompt $" {
56 pass "next over init() in main"
57 }
58 -re "$decimal.*init \\(\\);\r\n$prompt $"\
59 { send "next\n" ; exp_continue }
60 -re "$prompt $" { fail "next over init() in main" ; return }
61 timeout { fail "(timeout) next over init() in main" ; return }
62 }
63
64 # Print scope0.c::filelocal, which is 1
65
66 send "print filelocal\n"
67 expect {
68 -re "\\\$$decimal = 1\r\n$prompt $" { pass "print filelocal" }
69 -re "$prompt $" { fail "print filelocal" ; return }
70 timeout {
71 fail "(timeout) print filelocal" ; return
72 }
73 }
74
75 send "print 'scope0.c'::filelocal\n"
76 expect {
77 -re "\\\$$decimal = 1\r\n$prompt $" {
78 pass "print 'scope0.c'::filelocal at main"
79 }
80 -re "No symbol \"scope0.c\" in current context.*$prompt $" {
81 send "print '$srcdir/$subdir/scope0.c'::filelocal\n"
82 exp_continue
83 }
84 -re "$prompt $" { fail "print 'scope0.c'::filelocal at main" ; return }
85 timeout {
86 fail "(timeout) print 'scope0.c'::filelocal at main" ; return
87 }
88 }
89
90 # Print scope0.c::filelocal_bss, which is 101
91
92 send "print filelocal_bss\n"
93 expect {
94 -re "\\\$$decimal = 101\r\n$prompt $" {
95 pass "print filelocal_bss"
96 }
97 -re "$prompt $" { fail "print filelocal_bss" ; return }
98 timeout {
99 fail "(timeout) print filelocal_bss" ; return
100 }
101 }
102
103 send "print 'scope0.c'::filelocal_bss\n"
104 expect {
105 -re "\\\$$decimal = 101\r\n$prompt $" {
106 pass "print 'scope0.c'::filelocal_bss in test_at_main"
107 }
108 -re "No symbol \"scope0.c\" in current context.*$prompt $" {
109 send "print '$srcdir/$subdir/scope0.c'::filelocal_bss\n"
110 exp_continue
111 }
112 -re "$prompt $" {
113 fail "print 'scope0.c'::filelocal_bss in test_at_main" ; return
114 }
115 timeout {
116 fail "(timeout) print 'scope0.c'::filelocal_bss in test_at_main"
117 return
118 }
119 }
120
121 # Print scope0.c::filelocal_ro, which is 201
122
123 # No clue why the powerpc fails this test.
124 setup_xfail "powerpc-*-*"
125 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
126 send "print filelocal_ro\n"
127 expect {
128 -re "\\\$$decimal = 201\r\n$prompt $" {
129 pass "print filelocal_ro in test_at_main"
130 }
131 -re "$prompt $" {
132 fail "print filelocal_ro in test_at_main"
133 return
134 }
135 timeout {
136 fail "(timeout) print filelocal_ro in test_at_main"
137 return
138 }
139 }
140
141 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
142 setup_xfail "powerpc-*-*"
143 send "print 'scope0.c'::filelocal_ro\n"
144 expect {
145 -re "\\\$$decimal = 201\r\n$prompt $" {
146 pass "print 'scope0.c'::filelocal_ro"
147 }
148 -re "No symbol \"scope0.c\" in current context.*$prompt $" {
149 send "print '$srcdir/$subdir/scope0.c'::filelocal_ro\n"
150 exp_continue
151 }
152 -re "$prompt $" { fail "print 'scope0.c'::filelocal_ro" ; return }
153 timeout {
154 fail "(timeout) print 'scope0.c'::filelocal_ro" ; return
155 }
156 }
157
158 # Print scope1.c::filelocal, which is 2
159
160 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
161 send "print 'scope1.c'::filelocal\n"
162 expect {
163 -re "\\\$$decimal = 2\r\n$prompt $" {
164 pass "print 'scope1.c'::filelocal"
165 }
166 -re "No symbol \"scope1.c\" in current context.*$prompt $" {
167 send "print '$srcdir/$subdir/scope1.c'::filelocal\n"
168 exp_continue
169 }
170 -re "$prompt $" { fail "print 'scope1.c'::filelocal" ; return }
171 timeout {
172 fail "(timeout) print 'scope1.c'::filelocal" ; return
173 }
174 }
175
176 # Print scope1.c::filelocal_bss, which is 102
177
178 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
179 send "print 'scope1.c'::filelocal_bss\n"
180 expect {
181 -re "\\\$$decimal = 102\r\n$prompt $" {
182 pass "print 'scope1.c'::filelocal_bss"
183 }
184 -re "No symbol \"scope1.c\" in current context.*$prompt $" {
185 send "print '$srcdir/$subdir/scope1.c'::filelocal_bss\n"
186 exp_continue
187 }
188 -re "$prompt $" { fail "print 'scope1.c'::filelocal_bss" ; return }
189 timeout {
190 fail "(timeout) print 'scope1.c'::filelocal_bss" ; return
191 }
192 }
193
194 # Print scope1.c::filelocal_ro, which is 202
195
196 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
197 send "print 'scope1.c'::filelocal_ro\n"
198 expect {
199 -re "\\\$$decimal = 202\r\n$prompt $" {
200 pass "print 'scope1.c'::filelocal_ro"
201 }
202 -re "No symbol \"scope1.c\" in current context.*$prompt $" {
203 send "print '$srcdir/$subdir/scope1.c'::filelocal_ro\n"
204 exp_continue
205 }
206 -re "$prompt " {fail "print 'scope1.c'::filelocal_ro" ; return }
207 timeout {
208 fail "(timeout) print 'scope1.c'::filelocal_ro" ; return
209 }
210 }
211
212 # Print scope1.c::foo::funclocal, which is 3
213
214 send "print foo::funclocal\n"
215 expect {
216 -re "\\\$$decimal = 3\r\n$prompt $" { pass "print foo::funclocal" }
217 -re "$prompt $" { fail "print foo::funclocal" ; return }
218 timeout {
219 fail "(timeout) print foo::funclocal" ; return
220 }
221 }
222
223 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
224 send "print 'scope1.c'::foo::funclocal\n"
225 expect {
226 -re "\\\$$decimal = 3\r\n$prompt $" {
227 pass "print 'scope1.c'::foo::funclocal"
228 }
229 -re "No symbol \"scope1.c\" in current context.*$prompt $" {
230 send "print '$srcdir/$subdir/scope1.c'::foo::funclocal\n"
231 exp_continue
232 }
233 -re "$prompt $" { fail "print 'scope1.c'::foo::funclocal" ; return }
234 timeout {
235 fail "(timeout) print 'scope1.c'::foo::funclocal" ; return
236 }
237 }
238
239 # Print scope1.c::foo::funclocal_ro, which is 203
240
241 send "print foo::funclocal_ro\n"
242 expect {
243 -re "\\\$$decimal = 203\r\n$prompt $" {
244 pass "print foo::funclocal_ro"
245 }
246 -re "$prompt $" { fail "print foo::funclocal_ro" ; return }
247 timeout {
248 fail "(timeout) print foo::funclocal_ro" ; return
249 }
250 }
251
252 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
253 send "print 'scope1.c'::foo::funclocal_ro\n"
254 expect {
255 -re "\\\$$decimal = 203\r\n$prompt $" {
256 pass "print 'scope1.c'::foo::funclocal_ro" }
257 -re "No symbol \"scope1.c\" in current context.*$prompt $" {
258 send "print '$srcdir/$subdir/scope1.c'::foo::funclocal_ro\n"
259 exp_continue
260 }
261 -re "$prompt $" { fail "print 'scope1.c'::foo::funclocal_ro" ; return }
262 timeout {
263 fail "(timeout) print 'scope1.c'::foo::funclocal_ro" ; return
264 }
265 }
266
267 # Print scope1.c::bar::funclocal, which is 4
268
269 send "print bar::funclocal\n"
270 expect {
271 -re "\\\$$decimal = 4\r\n$prompt $" { pass "print bar::funclocal" }
272 -re "$prompt $" { fail "print bar::funclocal" ; return }
273 timeout {
274 fail "(timeout) print bar::funclocal" ; return
275 }
276 }
277
278 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
279 send "print 'scope1.c'::bar::funclocal\n"
280 expect {
281 -re "\\\$$decimal = 4\r\n$prompt $" {
282 pass "print 'scope1.c'::bar::funclocal"
283 }
284 -re "No symbol \"scope1.c\" in current context.*$prompt $" {
285 send "print '$srcdir/$subdir/scope1.c'::bar::funclocal\n"
286 exp_continue
287 }
288 -re "$prompt $" { fail "print 'scope1.c'::bar::funclocal" ; return }
289 timeout {
290 fail "print 'scope1.c'::bar::funclocal" ; return
291 }
292 }
293 }
294
295 proc test_at_foo {} {
296 global prompt
297 global decimal
298 global det_file
299 global srcdir
300 global subdir
301 global gcc_compiled
302
303 send "next\n"
304 expect {
305 -re ".*bar \\(\\);\r\n$prompt $" {}
306 -re "$prompt $" { fail "continue to foo()" ; return }
307 timeout { fail "(timeout) continue to foo()" ; return }
308 }
309
310 # Print scope0.c::filelocal, which is 1
311
312 send "print 'scope0.c'::filelocal\n"
313 expect {
314 -re "\\\$$decimal = 1\r\n$prompt $" {
315 pass "print 'scope0.c'::filelocal at foo"
316 }
317 -re "No symbol \"scope0.c\" in current context.*$prompt $" {
318 send "print '$srcdir/$subdir/scope0.c'::filelocal\n"
319 exp_continue
320 }
321 -re "$prompt $" { fail "print 'scope0.c'::filelocal at foo" ; return }
322 timeout {
323 fail "(timeout) print 'scope0.c'::filelocal at foo" ; return
324 }
325 }
326
327 # Print scope0.c::filelocal_bss, which is 101
328
329 send "print 'scope0.c'::filelocal_bss\n"
330 expect {
331 -re "\\\$$decimal = 101\r\n$prompt $" {
332 pass "print 'scope0.c'::filelocal_bss in test_at_foo"
333 }
334 -re "No symbol \"scope0.c\" in current context.*$prompt $" {
335 send "print '$srcdir/$subdir/scope0.c'::filelocal_bss\n"
336 exp_continue
337 }
338 -re "$prompt $" {
339 fail "print 'scope0.c'::filelocal_bss in test_at_foo"
340 return
341 }
342 timeout {
343 fail "(timeout) print 'scope0.c'::filelocal_bss in test_at_foo"
344 return
345 }
346 }
347
348 # Print scope0.c::filelocal_ro, which is 201
349
350 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
351 setup_xfail "powerpc-*-*"
352 send "print 'scope0.c'::filelocal_ro\n"
353 expect {
354 -re "\\\$$decimal = 201\r\n$prompt $" { pass "print 'scope0.c'::filelocal_ro" }
355 -re "No symbol \"scope0.c\" in current context.*$prompt $" {
356 send "print '$srcdir/$subdir/scope0.c'::filelocal_ro\n"
357 exp_continue
358 }
359 -re "$prompt $" { fail "print 'scope0.c'::filelocal_ro" ; return }
360 timeout {
361 fail "(timeout) print 'scope0.c'::filelocal_ro" ; return
362 }
363 }
364
365 gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at foo"
366
367 # Print scope1.c::filelocal, which is 2
368
369 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
370 send "print 'scope1.c'::filelocal\n"
371 expect {
372 -re "\\\$$decimal = 2\r\n$prompt $" {
373 pass "print 'scope1.c'::filelocal at foo"
374 }
375 -re "No symbol \"scope1.c\" in current context.*$prompt $" {
376 send "print '$srcdir/$subdir/scope1.c'::filelocal\n"
377 exp_continue
378 }
379 -re "$prompt $" { fail "print 'scope1.c'::filelocal at foo" ; return }
380 timeout {
381 fail "(timeout) print 'scope1.c'::filelocal at foo" ; return
382 }
383 }
384
385 gdb_test "print filelocal_bss" "\\\$$decimal = 102" \
386 "print filelocal_bss at foo"
387
388 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
389 send "print 'scope1.c'::filelocal_bss\n"
390 expect {
391 -re "\\\$$decimal = 102\r\n$prompt $" {
392 pass "print 'scope1.c'::filelocal_bss at foo"
393 }
394 -re "No symbol \"scope1.c\" in current context.*$prompt $" {
395 send "print '$srcdir/$subdir/scope1.c'::filelocal_bss\n"
396 exp_continue
397 }
398 -re "$prompt $" { fail "print 'scope1.c'::filelocal_bss at foo" }
399 timeout {
400 fail "(timeout) print 'scope1.c'::filelocal_bss at foo"
401 }
402 }
403
404 gdb_test "print filelocal_ro" "\\\$$decimal = 202" \
405 "print filelocal_ro at foo"
406
407 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
408 send "print 'scope1.c'::filelocal_ro\n"
409 expect {
410 -re "\\\$$decimal = 202\r\n$prompt $" { pass "print 'scope1.c'::filelocal_ro at foo" }
411 -re "No symbol \"scope1.c\" in current context.*$prompt $" {
412 send "print '$srcdir/$subdir/scope1.c'::filelocal_ro\n"
413 exp_continue
414 }
415 -re "$prompt $" { fail "print 'scope1.c'::filelocal_ro at foo" }
416 timeout {
417 fail "(timeout) print 'scope1.c'::filelocal_ro at foo"
418 }
419 }
420
421 # Print scope1.c::foo::funclocal, which is 3
422
423 gdb_test "print funclocal" "\\\$$decimal = 3" "print funclocal at foo"
424
425 gdb_test "print foo::funclocal" "\\\$$decimal = 3" \
426 "print foo::funclocal at foo"
427
428 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
429 send "print 'scope1.c'::foo::funclocal\n"
430 expect {
431 -re "\\\$$decimal = 3\r\n$prompt $" {
432 pass "print 'scope1.c'::foo::funclocal at foo"
433 }
434 -re "No symbol \"scope1.c\" in current context.*$prompt $" {
435 send "print '$srcdir/$subdir/scope1.c'::foo::funclocal\n"
436 exp_continue
437 }
438 -re "$prompt $" { fail "print 'scope1.c'::foo::funclocal at foo" }
439 timeout {
440 fail "(timeout) print 'scope1.c'::foo::funclocal at foo"
441 }
442 }
443
444 # Print scope1.c::foo::funclocal_bss, which is 103
445
446 gdb_test "print funclocal_bss" "\\\$$decimal = 103" \
447 "print funclocal_bss at foo"
448
449 gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" \
450 "print foo::funclocal_bss at foo"
451
452 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
453 send "print 'scope1.c'::foo::funclocal_bss\n"
454 expect {
455 -re "\\\$$decimal = 103\r\n$prompt $" {
456 pass "print 'scope1.c'::foo::funclocal_bss at foo"
457 }
458 -re "No symbol \"scope1.c\" in current context.*$prompt $" {
459 send "print '$srcdir/$subdir/scope1.c'::foo::funclocal_bss\n"
460 exp_continue
461 }
462 -re "$prompt $" {
463 fail "print 'scope1.c'::foo::funclocal_bss at foo"
464 }
465 timeout {
466 fail "(timeout) print 'scope1.c'::foo::funclocal_bss at foo"
467 }
468 }
469
470 # Print scope1.c::foo::funclocal_ro, which is 203
471
472 gdb_test "print funclocal_ro" "\\\$$decimal = 203" \
473 "print funclocal_ro at foo"
474
475 gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" \
476 "print foo::funclocal_ro at foo"
477
478 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
479 send "print 'scope1.c'::foo::funclocal_ro\n"
480 expect {
481 -re "\\\$$decimal = 203\r\n$prompt $" {
482 pass "print 'scope1.c'::foo::funclocal_ro at foo"
483 }
484 -re "No symbol \"scope1.c\" in current context.*$prompt $" {
485 send "print '$srcdir/$subdir/scope1.c'::foo::funclocal_ro\n"
486 exp_continue
487 }
488 -re "$prompt $" { fail "print 'scope1.c'::foo::funclocal_ro at foo" }
489 timeout {
490 fail "(timeout) print 'scope1.c'::foo::funclocal_ro at foo"
491 }
492 }
493
494 # Print scope1.c::bar::funclocal, which is 4
495
496 gdb_test "print bar::funclocal" "\\\$$decimal = 4" \
497 "print bar::funclocal at foo"
498
499 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
500 send "print 'scope1.c'::bar::funclocal\n"
501 expect {
502 -re "\\\$$decimal = 4\r\n$prompt $" {
503 pass "print 'scope1.c'::bar::funclocal at foo"
504 }
505 -re "No symbol \"scope1.c\" in current context.*$prompt $" {
506 send "print '$srcdir/$subdir/scope1.c'::bar::funclocal\n"
507 exp_continue
508 }
509 -re "$prompt $" { fail "print 'scope1.c'::bar::funclocal at foo" }
510 timeout {
511 fail "(timeout) print 'scope1.c'::bar::funclocal at foo"
512 }
513 }
514 }
515
516 proc test_at_bar {} {
517 global prompt
518 global decimal
519 global det_file
520 global srcdir
521 global subdir
522 global gcc_compiled
523
524 send "next\n"
525 expect {
526 -re ".*$prompt $" {}
527 timeout { fail "next in bar()" ; return }
528 }
529
530 # Print scope0.c::filelocal, which is 1
531
532 send "print 'scope0.c'::filelocal\n"
533 expect {
534 -re "\\\$$decimal = 1\r\n$prompt $" {
535 pass "print 'scope0.c'::filelocal at bar"
536 }
537 -re "No symbol \"scope0.c\" in current context.*$prompt $" {
538 send "print '$srcdir/$subdir/scope0.c'::filelocal\n"
539 exp_continue
540 }
541 -re "$prompt $" { fail "print 'scope0.c'::filelocal at bar" ; return }
542 timeout {
543 fail "(timeout) print 'scope0.c'::filelocal at bar" ; return
544 }
545 }
546
547 # Print scope0.c::filelocal_bss, which is 101
548
549 send "print 'scope0.c'::filelocal_bss\n"
550 expect {
551 -re "\\\$$decimal = 101\r\n$prompt $" {
552 pass "print 'scope0.c'::filelocal_bss in test_at_bar"
553 }
554 -re "No symbol \"scope0.c\" in current context.*$prompt $" {
555 send "print '$srcdir/$subdir/scope0.c'::filelocal_bss\n"
556 exp_continue
557 }
558 -re "$prompt $" {
559 fail "print 'scope0.c'::filelocal_bss in test_at_bar"
560 return
561 }
562 timeout {
563 fail "(timeout) print 'scope0.c'::filelocal_bss in test_at_bar"
564 return
565 }
566 }
567
568 # Print scope0.c::filelocal_ro, which is 201
569
570 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
571 setup_xfail "powerpc-*-*"
572 send "print 'scope0.c'::filelocal_ro\n"
573 expect {
574 -re "\\\$$decimal = 201\r\n$prompt $" { pass "print 'scope0.c'::filelocal_ro" }
575 -re "No symbol \"scope0.c\" in current context.*$prompt $" {
576 send "print '$srcdir/$subdir/scope0.c'::filelocal_ro\n"
577 exp_continue
578 }
579 -re "$prompt $" { fail "print 'scope0.c'::filelocal_ro" ; return }
580 timeout {
581 fail "(timeout) print 'scope0.c'::filelocal_ro" ; return
582 }
583 }
584
585 # Print scope1.c::filelocal, which is 2
586
587 send "print filelocal\n"
588 expect {
589 -re "\\\$$decimal = 2\r\n$prompt $" { pass "print filelocal" }
590 -re "$prompt $" { fail "print filelocal" ; return }
591 timeout {
592 fail "(timeout) print filelocal" ; return
593 }
594 }
595
596 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
597 send "print 'scope1.c'::filelocal\n"
598 expect {
599 -re "\\\$$decimal = 2\r\n$prompt $" { pass "print 'scope1.c'::filelocal" }
600 -re "No symbol \"scope1.c\" in current context.*$prompt $" {
601 send "print '$srcdir/$subdir/scope1.c'::filelocal\n"
602 exp_continue
603 }
604 -re "$prompt $" { fail "print 'scope1.c'::filelocal" ; return }
605 timeout {
606 fail "(timeout) print 'scope1.c'::filelocal" ; return
607 }
608 }
609
610 # Print scope1.c::filelocal_bss, which is 102
611
612 send "print filelocal_bss\n"
613 expect {
614 -re "\\\$$decimal = 102\r\n$prompt $" { pass "print filelocal_bss" }
615 -re "$prompt $" { fail "print filelocal_bss" ; return }
616 timeout {
617 fail "(timeout) print filelocal_bss" ; return
618 }
619 }
620
621 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
622 send "print 'scope1.c'::filelocal_bss\n"
623 expect {
624 -re "\\\$$decimal = 102\r\n$prompt $" { pass "print 'scope1.c'::filelocal_bss" }
625 -re "No symbol \"scope1.c\" in current context.*$prompt $" {
626 send "print '$srcdir/$subdir/scope1.c'::filelocal_bss\n"
627 exp_continue
628 }
629 -re "$prompt $" { fail "print 'scope1.c'::filelocal_bss" ; return }
630 timeout {
631 fail "(timeout) print 'scope1.c'::filelocal_bss" ; return
632 }
633 }
634
635 # Print scope1.c::filelocal_ro, which is 202
636
637 send "print filelocal_ro\n"
638 expect {
639 -re "\\\$$decimal = 202\r\n$prompt $" {
640 pass "print filelocal_ro in test_at_bar"
641 }
642 -re "$prompt $" {
643 fail "print filelocal_ro in test_at_bar"
644 return
645 }
646 timeout {
647 fail "(timeout) print filelocal_ro in test_at_bar"
648 return
649 }
650 }
651
652 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
653 send "print 'scope1.c'::filelocal_ro\n"
654 expect {
655 -re "\\\$$decimal = 202\r\n$prompt $" { pass "print 'scope1.c'::filelocal_ro" }
656 -re "No symbol \"scope1.c\" in current context.*$prompt $" {
657 send "print '$srcdir/$subdir/scope1.c'::filelocal_ro\n"
658 exp_continue
659 }
660 -re "$prompt $" { fail "print 'scope1.c'::filelocal_ro" ; return }
661 timeout {
662 fail "(timeout) print 'scope1.c'::filelocal_ro" ; return
663 }
664 }
665
666 # Print scope1.c::foo::funclocal, which is 3
667
668 send "print foo::funclocal\n"
669 expect {
670 -re "\\\$$decimal = 3\r\n$prompt $" { pass "print foo::funclocal" }
671 -re "$prompt $" { fail "print foo::funclocal" ; return }
672 timeout {
673 fail "(timeout) print foo::funclocal" ; return
674 }
675 }
676
677 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
678 send "print 'scope1.c'::foo::funclocal\n"
679 expect {
680 -re "\\\$$decimal = 3\r\n$prompt $" { pass "print 'scope1.c'::foo::funclocal" }
681 -re "No symbol \"scope1.c\" in current context.*$prompt $" {
682 send "print '$srcdir/$subdir/scope1.c'::foo::funclocal\n"
683 exp_continue
684 }
685 -re "$prompt $" { fail "print 'scope1.c'::foo::funclocal" ; return }
686 timeout {
687 fail "(timeout) print 'scope1.c'::foo::funclocal" ; return
688 }
689 }
690
691 # Print scope1.c::foo::funclocal_bss, which is 103
692
693 send "print foo::funclocal_bss\n"
694 expect {
695 -re "\\\$$decimal = 103\r\n$prompt $" { pass "print foo::funclocal_bss" }
696 -re "$prompt $" { fail "print foo::funclocal_bss" ; return }
697 timeout {
698 fail "(timeout) print foo::funclocal_bss" ; return
699 }
700 }
701
702 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
703 send "print 'scope1.c'::foo::funclocal_bss\n"
704 expect {
705 -re "\\\$$decimal = 103\r\n$prompt $" { pass "print 'scope1.c'::foo::funclocal_bss" }
706 -re "No symbol \"scope1.c\" in current context.*$prompt $" {
707 send "print '$srcdir/$subdir/scope1.c'::foo::funclocal_bss\n"
708 exp_continue
709 }
710 -re "$prompt $" { fail "print 'scope1.c'::foo::funclocal_bss" ; return }
711 timeout {
712 fail "(timeout) print 'scope1.c'::foo::funclocal_bss" ; return
713 }
714 }
715
716 # Print scope1.c::foo::funclocal_ro, which is 203
717
718 send "print foo::funclocal_ro\n"
719 expect {
720 -re "\\\$$decimal = 203\r\n$prompt $" { pass "print foo::funclocal_ro" }
721 -re "$prompt $" { fail "print foo::funclocal_ro" ; return }
722 timeout {
723 fail "(timeout) print foo::funclocal_ro" ; return
724 }
725 }
726
727 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
728 send "print 'scope1.c'::foo::funclocal_ro\n"
729 expect {
730 -re "\\\$$decimal = 203\r\n$prompt $" { pass "print 'scope1.c'::foo::funclocal_ro" }
731 -re "No symbol \"scope1.c\" in current context.*$prompt $" {
732 send "print '$srcdir/$subdir/scope1.c'::foo::funclocal_ro\n"
733 exp_continue
734 }
735 -re "$prompt $" { fail "print 'scope1.c'::foo::funclocal_ro" ; return }
736 timeout {
737 fail "(timeout) print 'scope1.c'::foo::funclocal_ro" ; return
738 }
739 }
740
741 # Print scope1.c::bar::funclocal, which is 4
742
743 send "print funclocal\n"
744 expect {
745 -re "\\\$$decimal = 4\r\n$prompt $" { pass "print funclocal" }
746 -re "$prompt $" { fail "print funclocal" ; return }
747 timeout {
748 fail "(timeout) print funclocal" ; return
749 }
750 }
751
752 send "print bar::funclocal\n"
753 expect {
754 -re "\\\$$decimal = 4\r\n$prompt $" { pass "print bar::funclocal" }
755 -re "$prompt $" { fail "print bar::funclocal" ; return }
756 timeout {
757 fail "(timeout) print bar::funclocal" ; return
758 }
759 }
760
761 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
762 send "print 'scope1.c'::bar::funclocal\n"
763 expect {
764 -re "\\\$$decimal = 4\r\n$prompt $" { pass "print 'scope1.c'::bar::funclocal" }
765 -re "No symbol \"scope1.c\" in current context.*$prompt $" {
766 send "print '$srcdir/$subdir/scope1.c'::bar::funclocal\n"
767 exp_continue
768 }
769 -re "$prompt $" { fail "print 'scope1.c'::bar::funclocal" ; return }
770 timeout {
771 fail "(timeout) print 'scope1.c'::bar::funclocal" ; return
772 }
773 }
774
775 # Print scope1.c::bar::funclocal_bss, which is 104
776
777 send "print funclocal_bss\n"
778 expect {
779 -re "\\\$$decimal = 104\r\n$prompt $" { pass "print funclocal_bss" }
780 -re "$prompt $" { fail "print funclocal_bss" ; return }
781 timeout {
782 fail "(timeout) print funclocal_bss" ; return
783 }
784 }
785
786 send "print bar::funclocal_bss\n"
787 expect {
788 -re "\\\$$decimal = 104\r\n$prompt $" { pass "print bar::funclocal_bss" }
789 -re "$prompt $" { fail "print bar::funclocal_bss" ; return }
790 timeout {
791 fail "(timeout) print bar::funclocal_bss" ; return
792 }
793 }
794
795 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
796 send "print 'scope1.c'::bar::funclocal_bss\n"
797 expect {
798 -re "\\\$$decimal = 104\r\n$prompt $" { pass "print 'scope1.c'::bar::funclocal_bss" }
799 -re "No symbol \"scope1.c\" in current context.*$prompt $" {
800 send "print '$srcdir/$subdir/scope1.c'::bar::funclocal_bss\n"
801 exp_continue
802 }
803 -re "$prompt $" { fail "print 'scope1.c'::bar::funclocal_bss" ; return }
804 timeout {
805 fail "(timeout) print 'scope1.c'::bar::funclocal_bss" ; return
806 }
807 }
808 }
809
810 # This test has little to do with local scopes, but it is in scope.exp anyway.
811 # That's life.
812
813 proc test_at_autovars {} {
814 global prompt
815 global decimal
816 global hex
817 global srcfile
818
819 # Test symbol table lookup with 100 local (auto) variables.
820
821 send "break marker1\n" ; expect -re ".*$prompt $"
822
823 send "cont\n"
824 expect {
825 -re "Break.* marker1 \\(\\) at .*:$decimal.*$prompt $" {
826 send "up\n"
827 expect {
828 -re ".*$prompt $" {}
829 timeout { fail "up from marker1" ; return }
830 }
831 }
832 -re "$prompt $" { fail "continue to marker1" ; return }
833 timeout { fail "(timeout) continue to marker1" ; return }
834 }
835
836 set count 0
837 while {$count < 100} {
838 send "print i$count\n"
839 expect {
840 -re ".* = $count\r\n$prompt $" {}
841 -re "$prompt $" {
842 fail "bad value for auto variable i$count"; return
843 }
844 timeout {
845 fail "(timeout) bad value for auto variable i$count"; return
846 }
847 }
848 set count [expr $count+1]
849 }
850 clear_xfail "*-*-*"
851 pass "$count auto variables correctly initialized"
852
853 # Test that block variable sorting is not screwing us.
854 gdb_test "frame" "#.*autovars \\(bcd=5, abc=6\\).*" "args in correct order"
855 }
856
857 proc test_at_localscopes {} {
858 global prompt
859 global decimal
860 global hex
861 global srcfile
862
863 send "break marker2\n" ; expect -re ".*$prompt $"
864 send "break marker3\n" ; expect -re ".*$prompt $"
865 send "break marker4\n" ; expect -re ".*$prompt $"
866
867 send "cont\n"
868 expect {
869 -re "Break.* marker2 \\(\\) at .*:$decimal.*$prompt $" {
870 send "up\n"
871 expect {
872 -re ".*$prompt $" {}
873 timeout { fail "up from marker2" ; return }
874 }
875 }
876 -re "$prompt $" { fail "continue to marker2" ; return }
877 timeout { fail "(timeout) continue to marker2" ; return }
878 }
879
880 # Should be at first (outermost) scope. Check values.
881
882 gdb_test "print localval" " = 10" "print localval, outer scope"
883 gdb_test "print localval1" " = 11" "print localval1, outer scope"
884 gdb_test "print localval2" "No symbol \"localval2\" in current context." \
885 "print localval2, outer scope"
886 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
887 "print localval3, outer scope"
888
889 if [gdb_test "cont" "Break.* marker3 \\(\\) at .*:$decimal.*" \
890 "continue to marker3 in scope.exp"] then { return }
891 if [gdb_test "up" "" "up from marker3 in scope.exp"] then { return }
892
893 # Should be at next (first nested) scope. Check values.
894
895 gdb_test "print localval" " = 20" \
896 "print localval, first nested scope"
897 gdb_test "print localval1" " = 11" "print localval1, first nested scope"
898 gdb_test "print localval2" " = 12" "print localval2, first nested scope"
899 gdb_test "print localval3" "No symbol \"localval3\" in current context." \
900 "print localval3, first nested scope"
901
902 # This test will only fail if the file was compiled by gcc, but
903 # there's no way to check that.
904 setup_xfail "a29k-*-udi" 2423
905 if [gdb_test "cont" "Break.* marker4.*at .*:$decimal.*" \
906 "continue to marker4 in scope.exp"] then { return }
907 if [gdb_test "up" "" "up from marker4 in scope.exp"] then { return }
908
909 gdb_test "print localval" " = 30" "print localval, innermost scope"
910 gdb_test "print localval1" " = 11" "print localval1, innermost scope"
911 gdb_test "print localval2" " = 12" "print localval2, innermost scope"
912 gdb_test "print localval3" " = 13" "print localval3, innermost scope"
913 }
914
915 # Start with a fresh gdb.
916
917 gdb_exit
918 gdb_start
919 gdb_reinitialize_dir $srcdir/$subdir
920 gdb_load $objdir/$subdir/$binfile
921
922 if [istarget "*-*-vxworks*"] {
923 set timeout 120
924 }
925
926 # Test that variables in various segments print out correctly before
927 # the program is run.
928
929 # AIX--sections get mapped to the same address so we can't get the right one.
930 setup_xfail "rs6000-*-*"
931 setup_xfail "powerpc-*-*"
932
933 gdb_test "print 'scope0.c'::filelocal_ro" "= 201"
934
935 # gdb currently cannot access bss memory on some targets if the inferior
936 # is not running.
937 #
938 # For PA boards using monitor/remote-pa.c, the bss test is going to
939 # randomly fail. We've already put remote-pa on the target stack,
940 # so we actually read memory from the board. Problem is crt0.o
941 # is responsible for clearing bss and that hasnt' happened yet.
942 setup_xfail "hppa*-*-*pro*"
943 if {$gcc_compiled} then { setup_xfail "rs6000-*-*" }
944 send "print 'scope0.c'::filelocal_bss\n"
945 expect {
946 -re " = 0\r\n$prompt $" {
947 pass "print 'scope0.c'::filelocal_bss before run"
948 }
949 -re "Cannot access memory.*$prompt $" {
950 setup_xfail "*-*-*"
951 fail "print 'scope0.c'::filelocal_bss before run"
952 }
953 -re ".*$prompt $" {
954 fail "print 'scope0.c'::filelocal_bss before run"
955 }
956 default {
957 fail "print 'scope0.c'::filelocal_bss before run"
958 }
959 }
960
961 # AIX--sections get mapped to the same address so we can't get the right one.
962 setup_xfail "rs6000-*-*"
963
964 gdb_test "print 'scope0.c'::filelocal" "= 1" \
965 "print 'scope0.c'::filelocal before run"
966
967 if [runto_main] then { test_at_main }
968 if [istarget "mips-idt-*"] then {
969 # Restart because IDT/SIM runs out of file descriptors.
970 gdb_exit
971 gdb_start
972 gdb_reinitialize_dir $srcdir/$subdir
973 gdb_load $objdir/$subdir/$binfile
974 }
975 if [runto foo] then { test_at_foo }
976 if [istarget "mips-idt-*"] then {
977 # Restart because IDT/SIM runs out of file descriptors.
978 gdb_exit
979 gdb_start
980 gdb_reinitialize_dir $srcdir/$subdir
981 gdb_load $objdir/$subdir/$binfile
982 }
983 if [runto bar] then { test_at_bar }
984 if [istarget "mips-idt-*"] then {
985 # Restart because IDT/SIM runs out of file descriptors.
986 gdb_exit
987 gdb_start
988 gdb_reinitialize_dir $srcdir/$subdir
989 gdb_load $objdir/$subdir/$binfile
990 }
991 if [runto localscopes] then { test_at_localscopes }
992 if [istarget "mips-idt-*"] then {
993 # Restart because IDT/SIM runs out of file descriptors.
994 gdb_exit
995 gdb_start
996 gdb_reinitialize_dir $srcdir/$subdir
997 gdb_load $objdir/$subdir/$binfile
998 }
999 if [runto autovars] then { test_at_autovars }
1000
1001 if [istarget "*-*-vxworks*"] {
1002 set timeout 120
1003 }