Commit | Line | Data |
---|---|---|
9b254dd1 | 1 | # Copyright 1997, 1998, 2001, 2002, 2003, 2004, 2007, 2008 |
6aba47ca | 2 | # Free Software Foundation, Inc. |
c906108c SS |
3 | # |
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by | |
e22f8b7c | 6 | # the Free Software Foundation; either version 3 of the License, or |
c906108c | 7 | # (at your option) any later version. |
e22f8b7c | 8 | # |
c906108c SS |
9 | # This program is distributed in the hope that it will be useful, |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
e22f8b7c | 13 | # |
c906108c | 14 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c906108c SS |
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 Michael Snyder (msnyder@cygnus.com) | |
21 | ||
22 | if $tracelevel then { | |
23 | strace $tracelevel | |
24 | } | |
25 | ||
26 | # | |
27 | # test running programs | |
28 | # | |
29 | ||
30 | set prms_id 0 | |
31 | set bug_id 0 | |
32 | ||
83547f02 UW |
33 | set data_overlays 1 |
34 | ||
c906108c SS |
35 | if [istarget "d10v-*-*"] then { |
36 | set linker_script "${srcdir}/${subdir}/d10v.ld"; | |
37 | } elseif [istarget "m32r-*-*"] then { | |
38 | set linker_script "${srcdir}/${subdir}/m32r.ld"; | |
83547f02 UW |
39 | } elseif [istarget "spu-*-*"] then { |
40 | set linker_script "${srcdir}/${subdir}/spu.ld"; | |
41 | set data_overlays 0 | |
c906108c SS |
42 | } else { |
43 | verbose "Skipping overlay test -- not implemented for this target." | |
44 | return | |
45 | } | |
46 | ||
6be3092d KI |
47 | if [istarget "*-*-linux*"] then { |
48 | verbose "Skipping overlay test -- Linux doesn't support overlayed programs." | |
49 | return | |
50 | } | |
51 | ||
c906108c SS |
52 | set testfile "overlays" |
53 | set binfile ${objdir}/${subdir}/${testfile} | |
f2dd3617 | 54 | set srcfile ${testfile}.c |
c906108c | 55 | |
f2dd3617 | 56 | if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${testfile}.o" object {debug}] != ""} then { |
b60f0898 JB |
57 | untested overlays.exp |
58 | return -1 | |
c906108c SS |
59 | } |
60 | if {[gdb_compile "${srcdir}/${subdir}/ovlymgr.c" ovlymgr.o object {debug}] != ""} then { | |
b60f0898 JB |
61 | untested overlays.exp |
62 | return -1 | |
c906108c | 63 | } |
f2dd3617 | 64 | if {[gdb_compile "${srcdir}/${subdir}/foo.c" foo.o object {debug} ] != ""} then { |
b60f0898 JB |
65 | untested overlays.exp |
66 | return -1 | |
c906108c SS |
67 | } |
68 | ||
f2dd3617 | 69 | if {[gdb_compile "${srcdir}/${subdir}/bar.c" bar.o object {debug}] != ""} then { |
b60f0898 JB |
70 | untested overlays.exp |
71 | return -1 | |
c906108c | 72 | } |
f2dd3617 | 73 | if {[gdb_compile "${srcdir}/${subdir}/baz.c" baz.o object {debug}] != ""} then { |
b60f0898 JB |
74 | untested overlays.exp |
75 | return -1 | |
c906108c | 76 | } |
f2dd3617 | 77 | if {[gdb_compile "${srcdir}/${subdir}/grbx.c" grbx.o object {debug}] != ""} then { |
b60f0898 JB |
78 | untested overlays.exp |
79 | return -1 | |
c906108c SS |
80 | } |
81 | if {[gdb_compile "${testfile}.o ovlymgr.o foo.o bar.o baz.o grbx.o" ${binfile} executable "ldscript=-Wl,-T$linker_script"] != "" } { | |
b60f0898 JB |
82 | untested overlays.exp |
83 | return -1 | |
c906108c SS |
84 | } |
85 | ||
86 | remote_exec build "mv ${testfile}.o foo.o bar.o baz.o grbx.o ovlymgr.o ${objdir}/${subdir}" | |
87 | ||
88 | ||
89 | gdb_start | |
90 | gdb_reinitialize_dir $srcdir/$subdir | |
91 | gdb_load ${binfile} | |
92 | ||
93 | # | |
94 | # set it up at a breakpoint so we can play with the variable values | |
95 | # | |
96 | ||
97 | if ![runto_main] then { | |
98 | gdb_suppress_tests; | |
99 | } | |
100 | ||
101 | # couple of convenience variables | |
c5984d70 | 102 | set fptrcast [string_to_regexp "{int (int)}"] |
c906108c | 103 | set iptrcast [string_to_regexp "(int *)"] |
c5984d70 | 104 | set hexx "0x\[0-9abcdefABCDEF\]+" |
c906108c SS |
105 | |
106 | gdb_test "overlay manual" "" | |
107 | gdb_test "overlay list" "No sections are mapped." "List with none mapped" | |
108 | ||
109 | # capture the LMA addresses of [foo bar baz grbx foox barx bazx grbxx] | |
110 | ||
c5984d70 MS |
111 | proc get_func_address { func func_sym msg } { |
112 | global gdb_prompt | |
113 | global fptrcast | |
114 | global hexx | |
115 | ||
116 | set func_addr 0 | |
117 | send_gdb "print $func\n" | |
118 | gdb_expect { | |
119 | -re "\\$\[0-9\]+ = $fptrcast (${hexx}) <$func_sym>.*$gdb_prompt $" { | |
120 | set func_addr $expect_out(1,string) | |
121 | pass "get $msg" | |
122 | } | |
123 | -re ".*$gdb_prompt $" { | |
124 | fail "get $msg" | |
125 | } | |
126 | default { | |
127 | fail "get $msg (timeout)" | |
128 | } | |
129 | } | |
130 | return $func_addr | |
131 | } | |
132 | ||
133 | set foo_lma [get_func_address "foo" "\\*foo\\*" "foo load address"] | |
134 | set bar_lma [get_func_address "bar" "\\*bar\\*" "bar load address"] | |
135 | set baz_lma [get_func_address "baz" "\\*baz\\*" "baz load address"] | |
136 | set grbx_lma [get_func_address "grbx" "\\*grbx\\*" "grbx load address"] | |
137 | ||
83547f02 UW |
138 | if $data_overlays then { |
139 | gdb_test "print \$foox_lma = &foox" \ | |
c906108c | 140 | ".* $iptrcast 0x.*" "foox load addr" |
83547f02 | 141 | gdb_test "print \$barx_lma = &barx" \ |
c906108c | 142 | ".* $iptrcast 0x.*" "barx load addr" |
83547f02 | 143 | gdb_test "print \$bazx_lma = &bazx" \ |
c906108c | 144 | ".* $iptrcast 0x.*" "bazx load addr" |
83547f02 | 145 | gdb_test "print \$grbxx_lma = &grbxx" \ |
c906108c | 146 | ".* $iptrcast 0x.*" "grbxx load addr" |
83547f02 | 147 | } |
c906108c SS |
148 | |
149 | # map each overlay successively, and | |
150 | # capture the VMA addresses of [foo bar baz grbx foox barx bazx grbxx] | |
151 | ||
152 | gdb_test "overlay map .ovly0" "" | |
153 | gdb_test "overlay list" "Section .ovly0, loaded at.*, mapped at.*" "List ovly0" | |
c5984d70 | 154 | set foo_vma [get_func_address "foo" "foo" "foo runtime address"] |
c906108c SS |
155 | |
156 | gdb_test "overlay map .ovly1" "" | |
157 | gdb_test "overlay list" "Section .ovly1, loaded at.*, mapped at.*" "List ovly1" | |
c5984d70 | 158 | set bar_vma [get_func_address "bar" "bar" "bar runtime address"] |
c906108c SS |
159 | |
160 | gdb_test "overlay map .ovly2" "" | |
161 | gdb_test "overlay list" "Section .ovly2, loaded at.*, mapped at.*" "List ovly2" | |
c5984d70 | 162 | set baz_vma [get_func_address "baz" "baz" "baz runtime address"] |
c906108c SS |
163 | |
164 | gdb_test "overlay map .ovly3" "" | |
165 | gdb_test "overlay list" "Section .ovly3, loaded at.*, mapped at.*" "List ovly3" | |
c5984d70 | 166 | set grbx_vma [get_func_address "grbx" "grbx" "grbx runtime address"] |
c906108c | 167 | |
83547f02 UW |
168 | if $data_overlays then { |
169 | gdb_test "overlay map .data00" "" | |
170 | gdb_test "overlay list" "Section .data00, loaded .*, mapped .*" "List data00" | |
171 | gdb_test "print \$foox_vma = &foox" \ | |
c906108c SS |
172 | ".* $iptrcast 0x.*" "foox runtime addr" |
173 | ||
83547f02 UW |
174 | gdb_test "overlay map .data01" "" |
175 | gdb_test "overlay list" "Section .data01, loaded .*, mapped .*" "List data01" | |
176 | gdb_test "print \$barx_vma = &barx" \ | |
c906108c SS |
177 | ".* $iptrcast 0x.*" "barx runtime addr" |
178 | ||
83547f02 UW |
179 | gdb_test "overlay map .data02" "" |
180 | gdb_test "overlay list" "Section .data02, loaded .*, mapped .*" "List data02" | |
181 | gdb_test "print \$bazx_vma = &bazx" \ | |
c906108c SS |
182 | ".* $iptrcast 0x.*" "bazx runtime addr" |
183 | ||
83547f02 UW |
184 | gdb_test "overlay map .data03" "" |
185 | gdb_test "overlay list" "Section .data03, loaded .*, mapped .*" "List data03" | |
186 | gdb_test "print \$grbxx_vma = &grbxx" \ | |
c906108c | 187 | ".* $iptrcast 0x.*" "grbxx runtime addr" |
83547f02 | 188 | } |
c906108c SS |
189 | # Verify that LMA != VMA |
190 | ||
c5984d70 MS |
191 | gdb_test "print $foo_lma != $foo_vma" ".* = 1" "foo's LMA != VMA" |
192 | gdb_test "print $bar_lma != $bar_vma" ".* = 1" "bar's LMA != VMA" | |
193 | gdb_test "print $baz_lma != $baz_vma" ".* = 1" "baz's LMA != VMA" | |
194 | gdb_test "print $grbx_lma != $grbx_vma" ".* = 1" "grbx's LMA != VMA" | |
83547f02 UW |
195 | if $data_overlays then { |
196 | gdb_test "print \$foox_lma != \$foox_vma" ".* = 1" "foox's LMA != VMA" | |
197 | gdb_test "print \$barx_lma != \$barx_vma" ".* = 1" "barx's LMA != VMA" | |
198 | gdb_test "print \$bazx_lma != \$bazx_vma" ".* = 1" "bazx's LMA != VMA" | |
199 | gdb_test "print \$grbxx_lma != \$grbxx_vma" ".* = 1" "grbxx's LMA != VMA" | |
200 | } | |
c906108c SS |
201 | |
202 | # Verify that early-mapped overlays have been bumped out | |
203 | # by later-mapped overlays layed over in the same VMA range. | |
204 | ||
205 | send_gdb "overlay list\n" | |
206 | gdb_expect { | |
207 | -re ".*ovly0, " { fail ".ovly0 not unmapped by .ovly1" } | |
208 | -re ".*ovly2, " { fail ".ovly2 not unmapped by .ovly3" } | |
209 | -re ".*data00," { fail ".data00 not unmapped by .data01" } | |
210 | -re ".*data02," { fail ".data02 not unmapped by .data03" } | |
211 | -re ".*$gdb_prompt $" { pass "Automatic unmapping" } | |
212 | timeout { fail "(timeout) Automatic unmapping" } | |
213 | } | |
214 | ||
ffd61a58 MS |
215 | # Verify that both sec1 and sec2 can be loaded simultaneously. |
216 | proc simultaneous_pair { sec1 sec2 } { | |
217 | global gdb_prompt | |
218 | ||
219 | set pairname "$sec1 and $sec2 mapped simultaneously" | |
220 | gdb_test "overlay map $sec1" "" "$pairname: map $sec1" | |
221 | gdb_test "overlay map $sec2" "" "$pairname: map $sec2" | |
222 | ||
223 | set seen_sec1 0 | |
224 | set seen_sec2 0 | |
225 | ||
226 | send_gdb "overlay list\n" | |
227 | gdb_expect { | |
228 | -re ".*[string_to_regexp $sec1], " { set seen_sec1 1; exp_continue } | |
229 | -re ".*[string_to_regexp $sec2], " { set seen_sec2 1; exp_continue } | |
230 | -re ".*$gdb_prompt $" { | |
231 | if {$seen_sec1 && $seen_sec2} { | |
232 | pass "$pairname" | |
233 | } else { | |
234 | fail "$pairname" | |
235 | } | |
236 | } | |
237 | timeout { fail "(timeout) $pairname" } | |
238 | } | |
239 | } | |
240 | ||
241 | simultaneous_pair .ovly0 .ovly2 | |
242 | simultaneous_pair .ovly0 .ovly3 | |
243 | simultaneous_pair .ovly1 .ovly2 | |
244 | simultaneous_pair .ovly1 .ovly3 | |
245 | ||
83547f02 UW |
246 | if $data_overlays then { |
247 | simultaneous_pair .data00 .data02 | |
248 | simultaneous_pair .data00 .data03 | |
249 | simultaneous_pair .data01 .data02 | |
250 | simultaneous_pair .data01 .data03 | |
251 | } | |
ffd61a58 | 252 | |
c906108c SS |
253 | # test automatic mode |
254 | ||
255 | gdb_test "overlay auto" "" | |
256 | gdb_test "overlay list" "No sections are mapped." "List none mapped (auto)" | |
257 | gdb_test "break foo" "Breakpoint .*at .*file .*foo.c.*" "break foo" | |
258 | gdb_test "break bar" "Breakpoint .*at .*file .*bar.c.*" "break bar" | |
259 | gdb_test "break baz" "Breakpoint .*at .*file .*baz.c.*" "break baz" | |
260 | gdb_test "break grbx" "Breakpoint .*at .*file .*grbx.c.*" "break grbx" | |
261 | ||
262 | send_gdb "continue\n" | |
263 | gdb_expect { | |
264 | -re "Breakpoint .* foo .x=1. at .*$gdb_prompt $" { pass "hit foo" } | |
265 | -re ".*$gdb_prompt $" { fail "hit foo" } | |
266 | timeout { fail "(timeout) hit foo" } | |
267 | } | |
268 | ||
269 | send_gdb "backtrace\n" | |
270 | gdb_expect { | |
271 | -re "#0 .*foo .*#1 .*main .*$gdb_prompt $" { pass "BT foo" } | |
272 | -re ".*$gdb_prompt $" { fail "BT foo" } | |
273 | timeout { fail "(timeout) BT foo" } | |
274 | } | |
275 | ||
276 | ||
277 | send_gdb "continue\n" | |
278 | gdb_expect { | |
279 | -re "Breakpoint .* bar .x=1. at .*$gdb_prompt $" { pass "hit bar" } | |
280 | -re ".*$gdb_prompt $" { fail "hit bar" } | |
281 | timeout { fail "(timeout) hit bar" } | |
282 | } | |
283 | ||
284 | send_gdb "backtrace\n" | |
285 | gdb_expect { | |
286 | -re "#0 .*bar .*#1 .*main .*$gdb_prompt $" { pass "BT bar" } | |
287 | -re ".*$gdb_prompt $" { fail "BT bar" } | |
288 | timeout { fail "(timeout) BT bar" } | |
289 | } | |
290 | ||
291 | send_gdb "continue\n" | |
292 | gdb_expect { | |
293 | -re "Breakpoint .* baz .x=1. at .*$gdb_prompt $" { pass "hit baz" } | |
294 | -re ".*$gdb_prompt $" { fail "hit baz" } | |
295 | timeout { fail "(timeout) hit baz" } | |
296 | } | |
297 | ||
298 | send_gdb "backtrace\n" | |
299 | gdb_expect { | |
300 | -re "#0 .*baz .*#1 .*main .*$gdb_prompt $" { pass "BT baz" } | |
301 | -re ".*$gdb_prompt $" { fail "BT baz" } | |
302 | timeout { fail "(timeout) BT baz" } | |
303 | } | |
304 | ||
305 | send_gdb "continue\n" | |
306 | gdb_expect { | |
307 | -re "Breakpoint .* grbx .x=1. at .*$gdb_prompt $" { pass "hit grbx" } | |
308 | -re ".*$gdb_prompt $" { fail "hit grbx" } | |
309 | timeout { fail "(timeout) hit grbx" } | |
310 | } | |
311 | ||
312 | send_gdb "backtrace\n" | |
313 | gdb_expect { | |
314 | -re "#0 .*grbx .*#1 .*main .*$gdb_prompt $" { pass "BT grbx" } | |
315 | -re ".*$gdb_prompt $" { fail "BT grbx" } | |
316 | timeout { fail "(timeout) BT grbx" } | |
317 | } | |
318 |