1 # Copyright 1997-2016 Free Software Foundation, Inc.
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 3 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # This file was written by Michael Snyder (msnyder@cygnus.com)
19 # test running programs
25 if [istarget "m32r-*-*"] then {
26 set linker_script "${srcdir}/${subdir}/m32r.ld"
27 } elseif [istarget "spu-*-*"] then {
28 set linker_script "${srcdir}/${subdir}/spu.ld"
31 verbose "Skipping overlay test -- not implemented for this target."
35 if [istarget "*-*-linux*"] then {
36 verbose "Skipping overlay test -- Linux doesn't support overlayed programs."
40 standard_testfile overlays.c ovlymgr.c foo.c bar.c baz.c grbx.c
42 if {[build_executable $testfile.exp $testfile \
43 [list $srcfile $srcfile2 $srcfile3 $srcfile4 $srcfile5 $srcfile6] \
44 {debug ldscript=-Wl,-T$linker_script}] == -1} {
49 remote_exec build "mv ${testfile}.o foo.o bar.o baz.o grbx.o ovlymgr.o ${objdir}/${subdir}"
53 gdb_reinitialize_dir $srcdir/$subdir
57 # set it up at a breakpoint so we can play with the variable values
60 if ![runto_main] then {
64 # couple of convenience variables
65 set fptrcast [string_to_regexp "{int (int)}"]
66 set iptrcast [string_to_regexp "(int *)"]
67 set hexx "0x\[0-9abcdefABCDEF\]+"
69 gdb_test_no_output "overlay manual"
70 gdb_test "overlay list" "No sections are mapped." "List with none mapped"
72 # capture the LMA addresses of [foo bar baz grbx foox barx bazx grbxx]
74 proc get_func_address { func func_sym msg } {
80 send_gdb "print $func\n"
82 -re "\\$\[0-9\]+ = $fptrcast (${hexx}) <$func_sym>.*$gdb_prompt $" {
83 set func_addr $expect_out(1,string)
86 -re ".*$gdb_prompt $" {
90 fail "get $msg (timeout)"
96 set foo_lma [get_func_address "foo" "\\*foo\\*" "foo load address"]
97 set bar_lma [get_func_address "bar" "\\*bar\\*" "bar load address"]
98 set baz_lma [get_func_address "baz" "\\*baz\\*" "baz load address"]
99 set grbx_lma [get_func_address "grbx" "\\*grbx\\*" "grbx load address"]
101 if $data_overlays then {
102 gdb_test "print \$foox_lma = &foox" \
103 ".* $iptrcast 0x.*" "foox load addr"
104 gdb_test "print \$barx_lma = &barx" \
105 ".* $iptrcast 0x.*" "barx load addr"
106 gdb_test "print \$bazx_lma = &bazx" \
107 ".* $iptrcast 0x.*" "bazx load addr"
108 gdb_test "print \$grbxx_lma = &grbxx" \
109 ".* $iptrcast 0x.*" "grbxx load addr"
112 # map each overlay successively, and
113 # capture the VMA addresses of [foo bar baz grbx foox barx bazx grbxx]
115 gdb_test "overlay map .ovly0" ""
116 gdb_test "overlay list" "Section .ovly0, loaded at.*, mapped at.*" "List ovly0"
117 set foo_vma [get_func_address "foo" "foo" "foo runtime address"]
119 gdb_test "overlay map .ovly1" ""
120 gdb_test "overlay list" "Section .ovly1, loaded at.*, mapped at.*" "List ovly1"
121 set bar_vma [get_func_address "bar" "bar" "bar runtime address"]
123 gdb_test "overlay map .ovly2" ""
124 gdb_test "overlay list" "Section .ovly2, loaded at.*, mapped at.*" "List ovly2"
125 set baz_vma [get_func_address "baz" "baz" "baz runtime address"]
127 gdb_test "overlay map .ovly3" ""
128 gdb_test "overlay list" "Section .ovly3, loaded at.*, mapped at.*" "List ovly3"
129 set grbx_vma [get_func_address "grbx" "grbx" "grbx runtime address"]
131 if $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" \
135 ".* $iptrcast 0x.*" "foox runtime addr"
137 gdb_test "overlay map .data01" ""
138 gdb_test "overlay list" "Section .data01, loaded .*, mapped .*" "List data01"
139 gdb_test "print \$barx_vma = &barx" \
140 ".* $iptrcast 0x.*" "barx runtime addr"
142 gdb_test "overlay map .data02" ""
143 gdb_test "overlay list" "Section .data02, loaded .*, mapped .*" "List data02"
144 gdb_test "print \$bazx_vma = &bazx" \
145 ".* $iptrcast 0x.*" "bazx runtime addr"
147 gdb_test "overlay map .data03" ""
148 gdb_test "overlay list" "Section .data03, loaded .*, mapped .*" "List data03"
149 gdb_test "print \$grbxx_vma = &grbxx" \
150 ".* $iptrcast 0x.*" "grbxx runtime addr"
152 # Verify that LMA != VMA
154 gdb_test "print $foo_lma != $foo_vma" ".* = 1" "foo's LMA != VMA"
155 gdb_test "print $bar_lma != $bar_vma" ".* = 1" "bar's LMA != VMA"
156 gdb_test "print $baz_lma != $baz_vma" ".* = 1" "baz's LMA != VMA"
157 gdb_test "print $grbx_lma != $grbx_vma" ".* = 1" "grbx's LMA != VMA"
158 if $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"
165 # Verify that early-mapped overlays have been bumped out
166 # by later-mapped overlays layed over in the same VMA range.
168 send_gdb "overlay list\n"
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" }
178 # Verify that both sec1 and sec2 can be loaded simultaneously.
179 proc simultaneous_pair { sec1 sec2 } {
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"
189 send_gdb "overlay list\n"
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} {
200 timeout { fail "(timeout) $pairname" }
204 simultaneous_pair .ovly0 .ovly2
205 simultaneous_pair .ovly0 .ovly3
206 simultaneous_pair .ovly1 .ovly2
207 simultaneous_pair .ovly1 .ovly3
209 if $data_overlays then {
210 simultaneous_pair .data00 .data02
211 simultaneous_pair .data00 .data03
212 simultaneous_pair .data01 .data02
213 simultaneous_pair .data01 .data03
216 # test automatic mode
218 gdb_test_no_output "overlay auto"
219 gdb_test "overlay list" "No sections are mapped." "List none mapped (auto)"
220 gdb_test "break foo" "Breakpoint .*at .*file .*foo.c.*" "break foo"
221 gdb_test "break bar" "Breakpoint .*at .*file .*bar.c.*" "break bar"
222 gdb_test "break baz" "Breakpoint .*at .*file .*baz.c.*" "break baz"
223 gdb_test "break grbx" "Breakpoint .*at .*file .*grbx.c.*" "break grbx"
225 send_gdb "continue\n"
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" }
232 send_gdb "backtrace\n"
234 -re "#0 .*foo .*#1 .*main .*$gdb_prompt $" { pass "BT foo" }
235 -re ".*$gdb_prompt $" { fail "BT foo" }
236 timeout { fail "(timeout) BT foo" }
240 send_gdb "continue\n"
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" }
247 send_gdb "backtrace\n"
249 -re "#0 .*bar .*#1 .*main .*$gdb_prompt $" { pass "BT bar" }
250 -re ".*$gdb_prompt $" { fail "BT bar" }
251 timeout { fail "(timeout) BT bar" }
254 send_gdb "continue\n"
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" }
261 send_gdb "backtrace\n"
263 -re "#0 .*baz .*#1 .*main .*$gdb_prompt $" { pass "BT baz" }
264 -re ".*$gdb_prompt $" { fail "BT baz" }
265 timeout { fail "(timeout) BT baz" }
268 send_gdb "continue\n"
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" }
275 send_gdb "backtrace\n"
277 -re "#0 .*grbx .*#1 .*main .*$gdb_prompt $" { pass "BT grbx" }
278 -re ".*$gdb_prompt $" { fail "BT grbx" }
279 timeout { fail "(timeout) BT grbx" }