OSDN Git Service

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