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