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