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