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