]>
Commit | Line | Data |
---|---|---|
213516ef | 1 | # Copyright 1992-2023 Free Software Foundation, Inc. |
c906108c SS |
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 | |
e22f8b7c | 5 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
c906108c SS |
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. | |
e22f8b7c | 12 | # |
c906108c | 13 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c | 15 | |
c906108c SS |
16 | # This file was written by Fred Fish. (fnf@cygnus.com) |
17 | ||
c906108c | 18 | |
0ab77f5f | 19 | standard_testfile scope0.c scope1.c |
c906108c | 20 | |
f5ca0032 | 21 | if {[build_executable "failed to build" ${testfile} \ |
0ab77f5f TT |
22 | [list $srcfile $srcfile2] {debug}]} { |
23 | return -1 | |
c906108c SS |
24 | } |
25 | ||
c906108c SS |
26 | # Test locating various things when stopped just inside main, after |
27 | # running init0(). To prevent cascading of errors, we report the | |
28 | # first one and quit. If all pass, then we print the pass results. | |
29 | ||
e0bd9202 | 30 | proc_with_prefix test_at_main {} { |
c906108c SS |
31 | global gdb_prompt |
32 | global decimal | |
33 | global det_file | |
34 | global srcdir | |
35 | global subdir | |
c906108c | 36 | |
34e41e63 JB |
37 | # skip past init0. |
38 | # This used to do an extra "next" if the first one didn't get us | |
39 | # over the call to init0, to handle calls to __main in the | |
40 | # prologue, etc. But if a breakpoint at main doesn't leave us on | |
41 | # the first line of real code in the function, that's a GDB bug. | |
42 | gdb_test "next" "$decimal.*foo \\(\\);" "next over init0() in main" | |
c906108c SS |
43 | |
44 | # Print scope0.c::filelocal, which is 1 | |
0ac85db5 | 45 | gdb_test "print filelocal" "\\\$$decimal = 1" |
35b72e4e | 46 | gdb_test "print 'scope0.c'::filelocal" "\\\$$decimal = 1" "print 'scope0.c'::filelocal at main" |
c906108c SS |
47 | |
48 | # Print scope0.c::filelocal_bss, which is 101 | |
0ac85db5 | 49 | gdb_test "print filelocal_bss" "\\\$$decimal = 101" |
35b72e4e | 50 | gdb_test "print 'scope0.c'::filelocal_bss" "\\\$$decimal = 101" "print 'scope0.c'::filelocal_bss in test_at_main" |
c906108c SS |
51 | |
52 | # Print scope0.c::filelocal_ro, which is 201 | |
53 | ||
15656118 | 54 | # No clue why the rs6000 fails this test. |
65a33d75 | 55 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
0ac85db5 | 56 | gdb_test "print filelocal_ro" "\\\$$decimal = 201" "print filelocal_ro in test_at_main" |
c906108c | 57 | |
65a33d75 | 58 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 59 | gdb_test "print 'scope0.c'::filelocal_ro" "\\\$$decimal = 201" "print 'scope0.c'::filelocal_ro" |
c906108c SS |
60 | |
61 | # Print scope1.c::filelocal, which is 2 | |
65a33d75 | 62 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 63 | gdb_test "print 'scope1.c'::filelocal" "\\\$$decimal = 2" "print 'scope1.c'::filelocal" |
c906108c SS |
64 | |
65 | # Print scope1.c::filelocal_bss, which is 102 | |
65a33d75 | 66 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 67 | gdb_test "print 'scope1.c'::filelocal_bss" "\\\$$decimal = 102" "print 'scope1.c'::filelocal_bss" |
c906108c SS |
68 | |
69 | # Print scope1.c::filelocal_ro, which is 202 | |
65a33d75 | 70 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 71 | gdb_test "print 'scope1.c'::filelocal_ro" "\\\$$decimal = 202" "print 'scope1.c'::filelocal_ro" |
c906108c SS |
72 | |
73 | # Print scope1.c::foo::funclocal, which is 3 | |
0ac85db5 | 74 | gdb_test "print foo::funclocal" "\\\$$decimal = 3" |
c906108c | 75 | |
65a33d75 | 76 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 77 | gdb_test "print 'scope1.c'::foo::funclocal" "\\\$$decimal = 3" "print 'scope1.c'::foo::funclocal" |
c906108c SS |
78 | |
79 | # Print scope1.c::foo::funclocal_ro, which is 203 | |
0ac85db5 | 80 | gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" |
c906108c | 81 | |
65a33d75 | 82 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 83 | gdb_test "print 'scope1.c'::foo::funclocal_ro" "\\\$$decimal = 203" "print 'scope1.c'::foo::funclocal_ro" |
c906108c SS |
84 | |
85 | # Print scope1.c::bar::funclocal, which is 4 | |
0ac85db5 | 86 | gdb_test "print bar::funclocal" "\\\$$decimal = 4" |
c906108c | 87 | |
65a33d75 | 88 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 89 | gdb_test "print 'scope1.c'::bar::funclocal" "\\\$$decimal = 4" "print 'scope1.c'::bar::funclocal" |
c906108c SS |
90 | } |
91 | ||
e0bd9202 | 92 | proc_with_prefix test_at_foo {} { |
c906108c SS |
93 | global gdb_prompt |
94 | global decimal | |
95 | global det_file | |
96 | global srcdir | |
97 | global subdir | |
c906108c | 98 | |
0ac85db5 | 99 | gdb_test "next" ".*bar \\(\\);" |
c906108c SS |
100 | |
101 | # Print scope0.c::filelocal, which is 1 | |
35b72e4e | 102 | gdb_test "print 'scope0.c'::filelocal" "\\\$$decimal = 1" "print 'scope0.c'::filelocal at foo" |
c906108c SS |
103 | |
104 | # Print scope0.c::filelocal_bss, which is 101 | |
35b72e4e | 105 | gdb_test "print 'scope0.c'::filelocal_bss" "\\\$$decimal = 101" "print 'scope0.c'::filelocal_bss in test_at_foo" |
c906108c SS |
106 | |
107 | # Print scope0.c::filelocal_ro, which is 201 | |
65a33d75 | 108 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 109 | gdb_test "print 'scope0.c'::filelocal_ro" "\\\$$decimal = 201" "print 'scope0.c'::filelocal_ro" |
c906108c SS |
110 | |
111 | ||
c906108c | 112 | # Print scope1.c::filelocal, which is 2 |
0ac85db5 | 113 | gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at foo" |
c906108c | 114 | |
65a33d75 | 115 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 116 | gdb_test "print 'scope1.c'::filelocal" "\\\$$decimal = 2" "print 'scope1.c'::filelocal at foo" |
c906108c SS |
117 | |
118 | gdb_test "print filelocal_bss" "\\\$$decimal = 102" \ | |
119 | "print filelocal_bss at foo" | |
120 | ||
65a33d75 | 121 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 122 | gdb_test "print 'scope1.c'::filelocal_bss" "\\\$$decimal = 102" "print 'scope1.c'::filelocal_bss at foo" |
c906108c SS |
123 | |
124 | ||
125 | gdb_test "print filelocal_ro" "\\\$$decimal = 202" \ | |
126 | "print filelocal_ro at foo" | |
127 | ||
65a33d75 | 128 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 129 | gdb_test "print 'scope1.c'::filelocal_ro" "\\\$$decimal = 202" "print 'scope1.c'::filelocal_ro at foo" |
c906108c SS |
130 | |
131 | ||
132 | # Print scope1.c::foo::funclocal, which is 3 | |
133 | ||
134 | gdb_test "print funclocal" "\\\$$decimal = 3" "print funclocal at foo" | |
135 | ||
c906108c SS |
136 | gdb_test "print foo::funclocal" "\\\$$decimal = 3" \ |
137 | "print foo::funclocal at foo" | |
138 | ||
65a33d75 | 139 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 140 | gdb_test "print 'scope1.c'::foo::funclocal" "\\\$$decimal = 3" "print 'scope1.c'::foo::funclocal at foo" |
c906108c SS |
141 | |
142 | ||
143 | # Print scope1.c::foo::funclocal_bss, which is 103 | |
144 | ||
145 | gdb_test "print funclocal_bss" "\\\$$decimal = 103" \ | |
146 | "print funclocal_bss at foo" | |
147 | ||
c906108c SS |
148 | gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" \ |
149 | "print foo::funclocal_bss at foo" | |
150 | ||
65a33d75 | 151 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 152 | gdb_test "print 'scope1.c'::foo::funclocal_bss" "\\\$$decimal = 103" "print 'scope1.c'::foo::funclocal_bss at foo" |
c906108c SS |
153 | |
154 | ||
155 | # Print scope1.c::foo::funclocal_ro, which is 203 | |
156 | ||
157 | gdb_test "print funclocal_ro" "\\\$$decimal = 203" \ | |
158 | "print funclocal_ro at foo" | |
159 | ||
c906108c SS |
160 | gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" \ |
161 | "print foo::funclocal_ro at foo" | |
162 | ||
65a33d75 | 163 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 164 | gdb_test "print 'scope1.c'::foo::funclocal_ro" "\\\$$decimal = 203" "print 'scope1.c'::foo::funclocal_ro at foo" |
c906108c SS |
165 | |
166 | ||
167 | # Print scope1.c::bar::funclocal, which is 4 | |
168 | ||
c906108c SS |
169 | gdb_test "print bar::funclocal" "\\\$$decimal = 4" \ |
170 | "print bar::funclocal at foo" | |
171 | ||
65a33d75 | 172 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 173 | gdb_test "print 'scope1.c'::bar::funclocal" "\\\$$decimal = 4" "print 'scope1.c'::bar::funclocal at foo" |
c906108c SS |
174 | |
175 | } | |
176 | ||
e0bd9202 | 177 | proc_with_prefix test_at_bar {} { |
c906108c SS |
178 | global gdb_prompt |
179 | global decimal | |
180 | global det_file | |
181 | global srcdir | |
182 | global subdir | |
c906108c | 183 | |
0ac85db5 | 184 | gdb_test "next" |
c906108c SS |
185 | |
186 | # Print scope0.c::filelocal, which is 1 | |
35b72e4e | 187 | gdb_test "print 'scope0.c'::filelocal" "\\\$$decimal = 1" "print 'scope0.c'::filelocal at bar" |
c906108c | 188 | |
0ac85db5 | 189 | # Print scope0.c::filelocal_bss, which is 101 |
35b72e4e | 190 | gdb_test "print 'scope0.c'::filelocal_bss" "\\\$$decimal = 101" "print 'scope0.c'::filelocal_bss in test_at_bar" |
c906108c | 191 | |
0ac85db5 | 192 | # Print scope0.c::filelocal_ro, which is 201 |
65a33d75 | 193 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 194 | gdb_test "print 'scope0.c'::filelocal_ro" "\\\$$decimal = 201" "print 'scope0.c'::filelocal_ro at bar" |
c906108c SS |
195 | |
196 | # Print scope1.c::filelocal, which is 2 | |
0ac85db5 | 197 | gdb_test "print filelocal" "\\\$$decimal = 2" "print filelocal at bar" |
c906108c | 198 | |
65a33d75 | 199 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 200 | gdb_test "print 'scope1.c'::filelocal" "\\\$$decimal = 2" "print 'scope1.c'::filelocal at bar" |
c906108c SS |
201 | |
202 | # Print scope1.c::filelocal_bss, which is 102 | |
0ac85db5 | 203 | gdb_test "print filelocal_bss" "\\\$$decimal = 102" "print filelocal_bss at bar" |
c906108c | 204 | |
65a33d75 | 205 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 206 | gdb_test "print 'scope1.c'::filelocal_bss" "\\\$$decimal = 102" "print 'scope1.c'::filelocal_bss at bar" |
c906108c SS |
207 | |
208 | # Print scope1.c::filelocal_ro, which is 202 | |
0ac85db5 | 209 | gdb_test "print filelocal_ro" "\\\$$decimal = 202" "print filelocal_ro in test_at_bar" |
c906108c | 210 | |
65a33d75 | 211 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 212 | gdb_test "print 'scope1.c'::filelocal_ro" "\\\$$decimal = 202" "print 'scope1.c'::filelocal_ro at bar" |
c906108c SS |
213 | |
214 | # Print scope1.c::foo::funclocal, which is 3 | |
0ac85db5 | 215 | gdb_test "print foo::funclocal" "\\\$$decimal = 3" "print foo::funclocal at bar" |
c906108c | 216 | |
65a33d75 | 217 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 218 | gdb_test "print 'scope1.c'::foo::funclocal" "\\\$$decimal = 3" "print 'scope1.c'::foo::funclocal at bar" |
c906108c SS |
219 | |
220 | # Print scope1.c::foo::funclocal_bss, which is 103 | |
0ac85db5 | 221 | gdb_test "print foo::funclocal_bss" "\\\$$decimal = 103" "print foo::funclocal_bss at bar" |
c906108c | 222 | |
65a33d75 | 223 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 224 | gdb_test "print 'scope1.c'::foo::funclocal_bss" "\\\$$decimal = 103" "print 'scope1.c'::foo::funclocal_bss at bar" |
c906108c SS |
225 | |
226 | # Print scope1.c::foo::funclocal_ro, which is 203 | |
0ac85db5 | 227 | gdb_test "print foo::funclocal_ro" "\\\$$decimal = 203" "print foo::funclocal_ro at bar" |
c906108c | 228 | |
65a33d75 | 229 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 230 | gdb_test "print 'scope1.c'::foo::funclocal_ro" "\\\$$decimal = 203" "print 'scope1.c'::foo::funclocal_ro at bar" |
c906108c SS |
231 | |
232 | # Print scope1.c::bar::funclocal, which is 4 | |
0ac85db5 SM |
233 | gdb_test "print funclocal" "\\\$$decimal = 4" "print funclocal at bar" |
234 | gdb_test "print bar::funclocal" "\\\$$decimal = 4" "print bar::funclocal at bar" | |
c906108c | 235 | |
65a33d75 | 236 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 237 | gdb_test "print 'scope1.c'::bar::funclocal" "\\\$$decimal = 4" "print 'scope1.c'::bar::funclocal at bar" |
c906108c SS |
238 | |
239 | # Print scope1.c::bar::funclocal_bss, which is 104 | |
0ac85db5 SM |
240 | gdb_test "print funclocal_bss" "\\\$$decimal = 104" "print funclocal_bss at bar" |
241 | gdb_test "print bar::funclocal_bss" "\\\$$decimal = 104" "print bar::funclocal_bss at bar" | |
c906108c | 242 | |
65a33d75 | 243 | if {[test_compiler_info gcc-*-*]} { setup_xfail "rs6000-*-*" } |
35b72e4e | 244 | gdb_test "print 'scope1.c'::bar::funclocal_bss" "\\\$$decimal = 104" "print 'scope1.c'::bar::funclocal_bss at bar" |
c906108c SS |
245 | } |
246 | ||
247 | # This test has little to do with local scopes, but it is in scope.exp anyway. | |
248 | # That's life. | |
249 | ||
e0bd9202 | 250 | proc_with_prefix test_at_autovars {} { |
c906108c SS |
251 | global gdb_prompt |
252 | global decimal | |
253 | global hex | |
254 | global srcfile | |
255 | ||
256 | # Test symbol table lookup with 100 local (auto) variables. | |
257 | ||
258 | gdb_breakpoint marker1 | |
259 | ||
0ac85db5 | 260 | gdb_test "cont" "Break.* marker1 \\(\\) at .*:$decimal.*" "continue to marker1" |
2939f92a | 261 | gdb_test "up" ".*autovars.*" "up from marker1" |
c906108c SS |
262 | |
263 | set count 0 | |
264 | while {$count < 100} { | |
0ac85db5 | 265 | gdb_test "print i$count" ".* = $count" "" |
c906108c SS |
266 | set count [expr $count+1] |
267 | } | |
268 | clear_xfail "*-*-*" | |
269 | pass "$count auto variables correctly initialized" | |
270 | ||
271 | # Test that block variable sorting is not screwing us. | |
272 | gdb_test "frame" "#.*autovars \\(bcd=5, abc=6\\).*" "args in correct order" | |
273 | } | |
274 | ||
e0bd9202 | 275 | proc_with_prefix test_at_localscopes {} { |
c906108c SS |
276 | global gdb_prompt |
277 | global decimal | |
278 | global hex | |
279 | global srcfile | |
280 | ||
281 | gdb_breakpoint marker2 | |
282 | gdb_breakpoint marker3 | |
283 | gdb_breakpoint marker4 | |
284 | ||
0ac85db5 | 285 | gdb_test "cont" "Break.* marker2 \\(\\) at .*:$decimal.*" "continue to marker2" |
2939f92a | 286 | gdb_test "up" ".*localscopes.*" "up from marker2" |
c906108c SS |
287 | |
288 | # Should be at first (outermost) scope. Check values. | |
289 | ||
290 | gdb_test "print localval" " = 10" "print localval, outer scope" | |
291 | gdb_test "print localval1" " = 11" "print localval1, outer scope" | |
292 | gdb_test "print localval2" "No symbol \"localval2\" in current context." \ | |
293 | "print localval2, outer scope" | |
294 | gdb_test "print localval3" "No symbol \"localval3\" in current context." \ | |
295 | "print localval3, outer scope" | |
296 | ||
0ac85db5 | 297 | gdb_test "cont" "Break.* marker3 \\(\\) at .*:$decimal.*" \ |
2939f92a TV |
298 | "continue to marker3" |
299 | gdb_test "up" ".*localscopes.*" "up from marker3" | |
c906108c SS |
300 | |
301 | # Should be at next (first nested) scope. Check values. | |
302 | ||
303 | gdb_test "print localval" " = 20" \ | |
304 | "print localval, first nested scope" | |
305 | gdb_test "print localval1" " = 11" "print localval1, first nested scope" | |
306 | gdb_test "print localval2" " = 12" "print localval2, first nested scope" | |
307 | gdb_test "print localval3" "No symbol \"localval3\" in current context." \ | |
308 | "print localval3, first nested scope" | |
309 | ||
310 | # This test will only fail if the file was compiled by gcc, but | |
311 | # there's no way to check that. | |
0ac85db5 | 312 | gdb_test "cont" "Break.* marker4.*at .*:$decimal.*" \ |
2939f92a TV |
313 | "continue to marker4" |
314 | gdb_test "up" ".*localscopes.*" "up from marker4" | |
c906108c SS |
315 | |
316 | gdb_test "print localval" " = 30" "print localval, innermost scope" | |
317 | gdb_test "print localval1" " = 11" "print localval1, innermost scope" | |
318 | gdb_test "print localval2" " = 12" "print localval2, innermost scope" | |
319 | gdb_test "print localval3" " = 13" "print localval3, innermost scope" | |
c906108c SS |
320 | } |
321 | ||
f5ca0032 PA |
322 | # Note, we don't pass a binfile to clean_restart because we need to |
323 | # avoid gdb_load here. With remote targets, gdb_load connects to the | |
324 | # remote target, and we specificaly want the following tests to run | |
325 | # before the program is started. | |
326 | clean_restart | |
327 | gdb_file_cmd $binfile | |
328 | ||
c906108c SS |
329 | # Test that variables in various segments print out correctly before |
330 | # the program is run. | |
331 | ||
332 | # AIX--sections get mapped to the same address so we can't get the right one. | |
333 | setup_xfail "rs6000-*-*" | |
c906108c SS |
334 | |
335 | gdb_test "print 'scope0.c'::filelocal_ro" "= 201" | |
336 | ||
f5ca0032 | 337 | # Check that gdb can access bss memory if the inferior is not running. |
c906108c | 338 | # |
f5ca0032 PA |
339 | # Note the care above about avoiding gdb_load. Otherwise, for |
340 | # embedded stub-like boards, this test would randomly fail. If we'd | |
341 | # already put target remote on the target stack, we'd read memory from | |
342 | # the board instead of the program's binary, and we would have | |
343 | # connected before crt0.o had had a chance to clear bss. | |
344 | gdb_test "print 'scope0.c'::filelocal_bss" "= 0" \ | |
345 | "print 'scope0.c'::filelocal_bss before run" | |
c906108c SS |
346 | |
347 | gdb_test "print 'scope0.c'::filelocal" "= 1" \ | |
348 | "print 'scope0.c'::filelocal before run" | |
349 | ||
65a33d75 AB |
350 | if {[runto_main]} { test_at_main } |
351 | if {[runto foo]} { test_at_foo } | |
352 | if {[runto bar]} { test_at_bar } | |
353 | if {[runto localscopes]} { test_at_localscopes } | |
354 | if {[runto autovars]} { test_at_autovars } |