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