* gdb.arch/altivec-abi.exp: Replace gdb_suppress_entire_file with
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / overlays.exp
1 # Copyright 1997, 1998, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
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
22 if $tracelevel then {
23 strace $tracelevel
24 }
25
26 #
27 # test running programs
28 #
29
30 set prms_id 0
31 set bug_id 0
32
33 if [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
42 if [istarget "*-*-linux*"] then {
43 verbose "Skipping overlay test -- Linux doesn't support overlayed programs."
44 return
45 }
46
47 set testfile "overlays"
48 set binfile ${objdir}/${subdir}/${testfile}
49 set srcfile ${testfile}.c
50
51 if {[gdb_compile "${srcdir}/${subdir}/${srcfile}" "${testfile}.o" object {debug}] != ""} then {
52 untested overlays.exp
53 return -1
54 }
55 if {[gdb_compile "${srcdir}/${subdir}/ovlymgr.c" ovlymgr.o object {debug}] != ""} then {
56 untested overlays.exp
57 return -1
58 }
59 if {[gdb_compile "${srcdir}/${subdir}/foo.c" foo.o object {debug} ] != ""} then {
60 untested overlays.exp
61 return -1
62 }
63
64 if {[gdb_compile "${srcdir}/${subdir}/bar.c" bar.o object {debug}] != ""} then {
65 untested overlays.exp
66 return -1
67 }
68 if {[gdb_compile "${srcdir}/${subdir}/baz.c" baz.o object {debug}] != ""} then {
69 untested overlays.exp
70 return -1
71 }
72 if {[gdb_compile "${srcdir}/${subdir}/grbx.c" grbx.o object {debug}] != ""} then {
73 untested overlays.exp
74 return -1
75 }
76 if {[gdb_compile "${testfile}.o ovlymgr.o foo.o bar.o baz.o grbx.o" ${binfile} executable "ldscript=-Wl,-T$linker_script"] != "" } {
77 untested overlays.exp
78 return -1
79 }
80
81 remote_exec build "mv ${testfile}.o foo.o bar.o baz.o grbx.o ovlymgr.o ${objdir}/${subdir}"
82
83
84 gdb_start
85 gdb_reinitialize_dir $srcdir/$subdir
86 gdb_load ${binfile}
87
88 #
89 # set it up at a breakpoint so we can play with the variable values
90 #
91
92 if ![runto_main] then {
93 gdb_suppress_tests;
94 }
95
96 # couple of convenience variables
97 set fptrcast [string_to_regexp "{int (int)}"]
98 set iptrcast [string_to_regexp "(int *)"]
99 set hexx "0x\[0-9abcdefABCDEF\]+"
100
101 gdb_test "overlay manual" ""
102 gdb_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
106 proc 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
128 set foo_lma [get_func_address "foo" "\\*foo\\*" "foo load address"]
129 set bar_lma [get_func_address "bar" "\\*bar\\*" "bar load address"]
130 set baz_lma [get_func_address "baz" "\\*baz\\*" "baz load address"]
131 set grbx_lma [get_func_address "grbx" "\\*grbx\\*" "grbx load address"]
132
133 gdb_test "print \$foox_lma = &foox" \
134 ".* $iptrcast 0x.*" "foox load addr"
135 gdb_test "print \$barx_lma = &barx" \
136 ".* $iptrcast 0x.*" "barx load addr"
137 gdb_test "print \$bazx_lma = &bazx" \
138 ".* $iptrcast 0x.*" "bazx load addr"
139 gdb_test "print \$grbxx_lma = &grbxx" \
140 ".* $iptrcast 0x.*" "grbxx load addr"
141
142 # map each overlay successively, and
143 # capture the VMA addresses of [foo bar baz grbx foox barx bazx grbxx]
144
145 gdb_test "overlay map .ovly0" ""
146 gdb_test "overlay list" "Section .ovly0, loaded at.*, mapped at.*" "List ovly0"
147 set foo_vma [get_func_address "foo" "foo" "foo runtime address"]
148
149 gdb_test "overlay map .ovly1" ""
150 gdb_test "overlay list" "Section .ovly1, loaded at.*, mapped at.*" "List ovly1"
151 set bar_vma [get_func_address "bar" "bar" "bar runtime address"]
152
153 gdb_test "overlay map .ovly2" ""
154 gdb_test "overlay list" "Section .ovly2, loaded at.*, mapped at.*" "List ovly2"
155 set baz_vma [get_func_address "baz" "baz" "baz runtime address"]
156
157 gdb_test "overlay map .ovly3" ""
158 gdb_test "overlay list" "Section .ovly3, loaded at.*, mapped at.*" "List ovly3"
159 set grbx_vma [get_func_address "grbx" "grbx" "grbx runtime address"]
160
161 gdb_test "overlay map .data00" ""
162 gdb_test "overlay list" "Section .data00, loaded .*, mapped .*" "List data00"
163 gdb_test "print \$foox_vma = &foox" \
164 ".* $iptrcast 0x.*" "foox runtime addr"
165
166 gdb_test "overlay map .data01" ""
167 gdb_test "overlay list" "Section .data01, loaded .*, mapped .*" "List data01"
168 gdb_test "print \$barx_vma = &barx" \
169 ".* $iptrcast 0x.*" "barx runtime addr"
170
171 gdb_test "overlay map .data02" ""
172 gdb_test "overlay list" "Section .data02, loaded .*, mapped .*" "List data02"
173 gdb_test "print \$bazx_vma = &bazx" \
174 ".* $iptrcast 0x.*" "bazx runtime addr"
175
176 gdb_test "overlay map .data03" ""
177 gdb_test "overlay list" "Section .data03, loaded .*, mapped .*" "List data03"
178 gdb_test "print \$grbxx_vma = &grbxx" \
179 ".* $iptrcast 0x.*" "grbxx runtime addr"
180
181 # Verify that LMA != VMA
182
183 gdb_test "print $foo_lma != $foo_vma" ".* = 1" "foo's LMA != VMA"
184 gdb_test "print $bar_lma != $bar_vma" ".* = 1" "bar's LMA != VMA"
185 gdb_test "print $baz_lma != $baz_vma" ".* = 1" "baz's LMA != VMA"
186 gdb_test "print $grbx_lma != $grbx_vma" ".* = 1" "grbx's LMA != VMA"
187 gdb_test "print \$foox_lma != \$foox_vma" ".* = 1" "foox's LMA != VMA"
188 gdb_test "print \$barx_lma != \$barx_vma" ".* = 1" "barx's LMA != VMA"
189 gdb_test "print \$bazx_lma != \$bazx_vma" ".* = 1" "bazx's LMA != VMA"
190 gdb_test "print \$grbxx_lma != \$grbxx_vma" ".* = 1" "grbxx's LMA != VMA"
191
192 # Verify that early-mapped overlays have been bumped out
193 # by later-mapped overlays layed over in the same VMA range.
194
195 send_gdb "overlay list\n"
196 gdb_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
205 # Verify that both sec1 and sec2 can be loaded simultaneously.
206 proc 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
231 simultaneous_pair .ovly0 .ovly2
232 simultaneous_pair .ovly0 .ovly3
233 simultaneous_pair .ovly1 .ovly2
234 simultaneous_pair .ovly1 .ovly3
235
236 simultaneous_pair .data00 .data02
237 simultaneous_pair .data00 .data03
238 simultaneous_pair .data01 .data02
239 simultaneous_pair .data01 .data03
240
241 # test automatic mode
242
243 gdb_test "overlay auto" ""
244 gdb_test "overlay list" "No sections are mapped." "List none mapped (auto)"
245 gdb_test "break foo" "Breakpoint .*at .*file .*foo.c.*" "break foo"
246 gdb_test "break bar" "Breakpoint .*at .*file .*bar.c.*" "break bar"
247 gdb_test "break baz" "Breakpoint .*at .*file .*baz.c.*" "break baz"
248 gdb_test "break grbx" "Breakpoint .*at .*file .*grbx.c.*" "break grbx"
249
250 send_gdb "continue\n"
251 gdb_expect {
252 -re "Breakpoint .* foo .x=1. at .*$gdb_prompt $" { pass "hit foo" }
253 -re ".*$gdb_prompt $" { fail "hit foo" }
254 timeout { fail "(timeout) hit foo" }
255 }
256
257 send_gdb "backtrace\n"
258 gdb_expect {
259 -re "#0 .*foo .*#1 .*main .*$gdb_prompt $" { pass "BT foo" }
260 -re ".*$gdb_prompt $" { fail "BT foo" }
261 timeout { fail "(timeout) BT foo" }
262 }
263
264
265 send_gdb "continue\n"
266 gdb_expect {
267 -re "Breakpoint .* bar .x=1. at .*$gdb_prompt $" { pass "hit bar" }
268 -re ".*$gdb_prompt $" { fail "hit bar" }
269 timeout { fail "(timeout) hit bar" }
270 }
271
272 send_gdb "backtrace\n"
273 gdb_expect {
274 -re "#0 .*bar .*#1 .*main .*$gdb_prompt $" { pass "BT bar" }
275 -re ".*$gdb_prompt $" { fail "BT bar" }
276 timeout { fail "(timeout) BT bar" }
277 }
278
279 send_gdb "continue\n"
280 gdb_expect {
281 -re "Breakpoint .* baz .x=1. at .*$gdb_prompt $" { pass "hit baz" }
282 -re ".*$gdb_prompt $" { fail "hit baz" }
283 timeout { fail "(timeout) hit baz" }
284 }
285
286 send_gdb "backtrace\n"
287 gdb_expect {
288 -re "#0 .*baz .*#1 .*main .*$gdb_prompt $" { pass "BT baz" }
289 -re ".*$gdb_prompt $" { fail "BT baz" }
290 timeout { fail "(timeout) BT baz" }
291 }
292
293 send_gdb "continue\n"
294 gdb_expect {
295 -re "Breakpoint .* grbx .x=1. at .*$gdb_prompt $" { pass "hit grbx" }
296 -re ".*$gdb_prompt $" { fail "hit grbx" }
297 timeout { fail "(timeout) hit grbx" }
298 }
299
300 send_gdb "backtrace\n"
301 gdb_expect {
302 -re "#0 .*grbx .*#1 .*main .*$gdb_prompt $" { pass "BT grbx" }
303 -re ".*$gdb_prompt $" { fail "BT grbx" }
304 timeout { fail "(timeout) BT grbx" }
305 }
306
This page took 0.036396 seconds and 5 git commands to generate.