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