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