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