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