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