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