Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.base / overlays.exp
blob57ead7dde74be3131d64125a4d439d8175cbeee2
1 # Copyright 1997-2023 Free Software Foundation, Inc.
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 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
23 set data_overlays 1
25 if {[istarget "m32r-*-*"]} {
26     set linker_script "${srcdir}/${subdir}/m32r.ld"
27 } else {
28     verbose "Skipping overlay test -- not implemented for this target."
29     return 
32 if {[istarget "*-*-linux*"]} {
33     verbose "Skipping overlay test -- Linux doesn't support overlayed programs."
34     return 
37 standard_testfile overlays.c ovlymgr.c foo.c bar.c baz.c grbx.c
39 if {[build_executable $testfile.exp $testfile \
40          [list $srcfile $srcfile2 $srcfile3 $srcfile4 $srcfile5 $srcfile6] \
41          "debug ldscript=-Wl,-T$linker_script"] == -1} {
42      untested "failed to compile"
43      return -1
46 remote_exec build "mv ${testfile}.o foo.o bar.o baz.o grbx.o ovlymgr.o ${objdir}/${subdir}"
49 gdb_start
50 gdb_reinitialize_dir $srcdir/$subdir
51 gdb_load ${binfile}
54 # set it up at a breakpoint so we can play with the variable values
57 if {![runto_main]} {
58     return 0
61 # couple of convenience variables
62 set fptrcast [string_to_regexp "{int (int)}"]
63 set iptrcast [string_to_regexp "(int *)"]
64 set hexx "0x\[0-9abcdefABCDEF\]+"
66 gdb_test_no_output "overlay manual"
67 gdb_test "overlay list" "No sections are mapped." "list with none mapped"
69 # capture the LMA addresses of [foo bar baz grbx foox barx bazx grbxx]
71 proc get_func_address { func func_sym msg } {
72     global gdb_prompt
73     global fptrcast
74     global hexx
76     set func_addr 0
77     send_gdb "print $func\n" 
78     gdb_expect {
79         -re "\\$\[0-9\]+ = $fptrcast (${hexx}) <$func_sym>.*$gdb_prompt $" {
80             set func_addr $expect_out(1,string)
81             pass "get $msg"
82         }
83         -re ".*$gdb_prompt $" {
84             fail "get $msg"
85         }
86         default {
87             fail "get $msg (timeout)"
88         }
89     }
90     return $func_addr
93 set foo_lma  [get_func_address "foo"  "\\*foo\\*"  "foo  load address"]
94 set bar_lma  [get_func_address "bar"  "\\*bar\\*"  "bar  load address"]
95 set baz_lma  [get_func_address "baz"  "\\*baz\\*"  "baz  load address"]
96 set grbx_lma [get_func_address "grbx" "\\*grbx\\*" "grbx load address"]
98 if {$data_overlays} {
99     gdb_test "print \$foox_lma = &foox" \
100         ".* $iptrcast 0x.*"  "foox load addr"
101     gdb_test "print \$barx_lma = &barx" \
102         ".* $iptrcast 0x.*"  "barx load addr"
103     gdb_test "print \$bazx_lma = &bazx" \
104         ".* $iptrcast 0x.*"  "bazx load addr"
105     gdb_test "print \$grbxx_lma = &grbxx" \
106         ".* $iptrcast 0x.*" "grbxx load addr"
109 # map each overlay successively, and
110 # capture the VMA addresses of [foo bar baz grbx foox barx bazx grbxx]
112 gdb_test "overlay map .ovly0" "" 
113 gdb_test "overlay list" "Section .ovly0, loaded at.*, mapped at.*" "list ovly0"
114 set foo_vma [get_func_address "foo"  "foo"  "foo  runtime address"]
116 gdb_test "overlay map .ovly1" "" 
117 gdb_test "overlay list" "Section .ovly1, loaded at.*, mapped at.*" "list ovly1"
118 set bar_vma [get_func_address "bar"  "bar"  "bar  runtime address"]
120 gdb_test "overlay map .ovly2" "" 
121 gdb_test "overlay list" "Section .ovly2, loaded at.*, mapped at.*" "list ovly2"
122 set baz_vma [get_func_address "baz"  "baz"  "baz  runtime address"]
124 gdb_test "overlay map .ovly3" "" 
125 gdb_test "overlay list" "Section .ovly3, loaded at.*, mapped at.*" "list ovly3"
126 set grbx_vma [get_func_address "grbx" "grbx" "grbx runtime address"]
128 if {$data_overlays} {
129     gdb_test "overlay map .data00" "" 
130     gdb_test "overlay list" "Section .data00, loaded .*, mapped .*" "list data00"
131     gdb_test "print \$foox_vma = &foox" \
132         ".* $iptrcast 0x.*"  "foox runtime addr"
134     gdb_test "overlay map .data01" "" 
135     gdb_test "overlay list" "Section .data01, loaded .*, mapped .*" "list data01"
136     gdb_test "print \$barx_vma = &barx" \
137         ".* $iptrcast 0x.*"  "barx runtime addr"
139     gdb_test "overlay map .data02" "" 
140     gdb_test "overlay list" "Section .data02, loaded .*, mapped .*" "list data02"
141     gdb_test "print \$bazx_vma = &bazx" \
142         ".* $iptrcast 0x.*"  "bazx runtime addr"
144     gdb_test "overlay map .data03" "" 
145     gdb_test "overlay list" "Section .data03, loaded .*, mapped .*" "list data03"
146     gdb_test "print \$grbxx_vma = &grbxx" \
147         ".* $iptrcast 0x.*"  "grbxx runtime addr"
149 # Verify that LMA != VMA
151 gdb_test "print $foo_lma   != $foo_vma" ".* = 1"   "foo's LMA   != VMA"
152 gdb_test "print $bar_lma   != $bar_vma" ".* = 1"   "bar's LMA   != VMA"
153 gdb_test "print $baz_lma   != $baz_vma" ".* = 1"   "baz's LMA   != VMA"
154 gdb_test "print $grbx_lma  != $grbx_vma" ".* = 1"  "grbx's LMA  != VMA"
155 if {$data_overlays} {
156     gdb_test "print \$foox_lma  != \$foox_vma" ".* = 1"  "foox's LMA  != VMA"
157     gdb_test "print \$barx_lma  != \$barx_vma" ".* = 1"  "barx's LMA  != VMA"
158     gdb_test "print \$bazx_lma  != \$bazx_vma" ".* = 1"  "bazx's LMA  != VMA"
159     gdb_test "print \$grbxx_lma != \$grbxx_vma" ".* = 1" "grbxx's LMA != VMA"
162 # Verify that early-mapped overlays have been bumped out 
163 # by later-mapped overlays layed over in the same VMA range.
165 send_gdb "overlay list\n"
166 gdb_expect {
167     -re ".*ovly0, "             { fail ".ovly0  not unmapped by .ovly1"  }
168     -re ".*ovly2, "             { fail ".ovly2  not unmapped by .ovly3"  }
169     -re ".*data00,"             { fail ".data00 not unmapped by .data01" }
170     -re ".*data02,"             { fail ".data02 not unmapped by .data03" }
171     -re ".*$gdb_prompt $"       { pass "automatic unmapping"             }
172     timeout                     { fail "(timeout) Automatic unmapping"   }
175 # Verify that both sec1 and sec2 can be loaded simultaneously.
176 proc simultaneous_pair { sec1 sec2 } {
177     global gdb_prompt
179     set pairname "$sec1 and $sec2 mapped simultaneously"
180     gdb_test "overlay map $sec1" "" "$pairname: map $sec1"
181     gdb_test "overlay map $sec2" "" "$pairname: map $sec2"
183     set seen_sec1 0
184     set seen_sec2 0
186     send_gdb "overlay list\n"
187     gdb_expect {
188         -re ".*[string_to_regexp $sec1], " { set seen_sec1 1; exp_continue }
189         -re ".*[string_to_regexp $sec2], " { set seen_sec2 1; exp_continue }
190         -re ".*$gdb_prompt $" {
191             if {$seen_sec1 && $seen_sec2} {
192                 pass "$pairname"
193             } else {
194                 fail "$pairname"
195             }
196         }
197         timeout { fail "(timeout) $pairname" }
198     }
201 simultaneous_pair .ovly0 .ovly2
202 simultaneous_pair .ovly0 .ovly3
203 simultaneous_pair .ovly1 .ovly2
204 simultaneous_pair .ovly1 .ovly3
206 if {$data_overlays} {
207     simultaneous_pair .data00 .data02
208     simultaneous_pair .data00 .data03
209     simultaneous_pair .data01 .data02
210     simultaneous_pair .data01 .data03
213 # test automatic mode
215 gdb_test_no_output "overlay auto"
216 gdb_test "overlay list" "No sections are mapped." "list none mapped (auto)"
217 gdb_test "break foo"  "Breakpoint .*at .*file .*foo.c.*"  "break foo"
218 gdb_test "break bar"  "Breakpoint .*at .*file .*bar.c.*"  "break bar"
219 gdb_test "break baz"  "Breakpoint .*at .*file .*baz.c.*"  "break baz"
220 gdb_test "break grbx" "Breakpoint .*at .*file .*grbx.c.*" "break grbx"
222 send_gdb "continue\n"
223 gdb_expect {
224     -re "Breakpoint .* foo .x=1. at .*$gdb_prompt $" { pass   "hit foo" }
225     -re ".*$gdb_prompt $"                            { fail   "hit foo" }
226     timeout                                  { fail "(timeout) hit foo" }
229 send_gdb "backtrace\n"
230 gdb_expect {
231     -re "#0 .*foo .*#1 .*main .*$gdb_prompt $"       { pass   "BT foo" }
232     -re ".*$gdb_prompt $"                            { fail   "BT foo" }
233     timeout                                  { fail "(timeout) BT foo" }
237 send_gdb "continue\n"
238 gdb_expect {
239     -re "Breakpoint .* bar .x=1. at .*$gdb_prompt $" { pass   "hit bar" }
240     -re ".*$gdb_prompt $"                            { fail   "hit bar" }
241     timeout                                  { fail "(timeout) hit bar" }
244 send_gdb "backtrace\n"
245 gdb_expect {
246     -re "#0 .*bar .*#1 .*main .*$gdb_prompt $"       { pass   "BT bar" }
247     -re ".*$gdb_prompt $"                            { fail   "BT bar" }
248     timeout                                  { fail "(timeout) BT bar" }
251 send_gdb "continue\n"
252 gdb_expect {
253     -re "Breakpoint .* baz .x=1. at .*$gdb_prompt $" { pass   "hit baz" }
254     -re ".*$gdb_prompt $"                            { fail   "hit baz" }
255     timeout                                  { fail "(timeout) hit baz" }
258 send_gdb "backtrace\n"
259 gdb_expect {
260     -re "#0 .*baz .*#1 .*main .*$gdb_prompt $"       { pass   "BT baz" }
261     -re ".*$gdb_prompt $"                            { fail   "BT baz" }
262     timeout                                  { fail "(timeout) BT baz" }
265 send_gdb "continue\n"
266 gdb_expect {
267     -re "Breakpoint .* grbx .x=1. at .*$gdb_prompt $" { pass   "hit grbx" }
268     -re ".*$gdb_prompt $"                             { fail   "hit grbx" }
269     timeout                                   { fail "(timeout) hit grbx" }
272 send_gdb "backtrace\n"
273 gdb_expect {
274     -re "#0 .*grbx .*#1 .*main .*$gdb_prompt $"      { pass   "BT grbx" }
275     -re ".*$gdb_prompt $"                            { fail   "BT grbx" }
276     timeout                                  { fail "(timeout) BT grbx" }