[gdb/syscalls] Sync with strace v6.13
[binutils-gdb.git] / gdb / testsuite / gdb.base / overlays.exp
blobc8730ece8a088f4d116d63ccf184c06b538b0b60
1 # Copyright 1997-2024 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 require {istarget "m32r-*-*"} {!istarget "*-*-linux*"}
27 standard_testfile overlays.c ovlymgr.c foo.c bar.c baz.c grbx.c
29 if {[build_executable $testfile.exp $testfile \
30          [list $srcfile $srcfile2 $srcfile3 $srcfile4 $srcfile5 $srcfile6] \
31          "debug ldscript=-Wl,-T$linker_script"] == -1} {
32      untested "failed to compile"
33      return -1
36 remote_exec build "mv ${testfile}.o foo.o bar.o baz.o grbx.o ovlymgr.o ${objdir}/${subdir}"
39 gdb_start
40 gdb_reinitialize_dir $srcdir/$subdir
41 gdb_load ${binfile}
44 # set it up at a breakpoint so we can play with the variable values
47 if {![runto_main]} {
48     return 0
51 # couple of convenience variables
52 set fptrcast [string_to_regexp "{int (int)}"]
53 set iptrcast [string_to_regexp "(int *)"]
54 set hexx "0x\[0-9abcdefABCDEF\]+"
56 gdb_test_no_output "overlay manual"
57 gdb_test "overlay list" "No sections are mapped." "list with none mapped"
59 # capture the LMA addresses of [foo bar baz grbx foox barx bazx grbxx]
61 proc get_func_address { func func_sym msg } {
62     global gdb_prompt
63     global fptrcast
64     global hexx
66     set func_addr 0
67     send_gdb "print $func\n" 
68     gdb_expect {
69         -re "\\$\[0-9\]+ = $fptrcast (${hexx}) <$func_sym>.*$gdb_prompt $" {
70             set func_addr $expect_out(1,string)
71             pass "get $msg"
72         }
73         -re ".*$gdb_prompt $" {
74             fail "get $msg"
75         }
76         default {
77             fail "get $msg (timeout)"
78         }
79     }
80     return $func_addr
83 set foo_lma  [get_func_address "foo"  "\\*foo\\*"  "foo  load address"]
84 set bar_lma  [get_func_address "bar"  "\\*bar\\*"  "bar  load address"]
85 set baz_lma  [get_func_address "baz"  "\\*baz\\*"  "baz  load address"]
86 set grbx_lma [get_func_address "grbx" "\\*grbx\\*" "grbx load address"]
88 if {$data_overlays} {
89     gdb_test "print \$foox_lma = &foox" \
90         ".* $iptrcast 0x.*"  "foox load addr"
91     gdb_test "print \$barx_lma = &barx" \
92         ".* $iptrcast 0x.*"  "barx load addr"
93     gdb_test "print \$bazx_lma = &bazx" \
94         ".* $iptrcast 0x.*"  "bazx load addr"
95     gdb_test "print \$grbxx_lma = &grbxx" \
96         ".* $iptrcast 0x.*" "grbxx load addr"
99 # map each overlay successively, and
100 # capture the VMA addresses of [foo bar baz grbx foox barx bazx grbxx]
102 gdb_test "overlay map .ovly0" "" 
103 gdb_test "overlay list" "Section .ovly0, loaded at.*, mapped at.*" "list ovly0"
104 set foo_vma [get_func_address "foo"  "foo"  "foo  runtime address"]
106 gdb_test "overlay map .ovly1" "" 
107 gdb_test "overlay list" "Section .ovly1, loaded at.*, mapped at.*" "list ovly1"
108 set bar_vma [get_func_address "bar"  "bar"  "bar  runtime address"]
110 gdb_test "overlay map .ovly2" "" 
111 gdb_test "overlay list" "Section .ovly2, loaded at.*, mapped at.*" "list ovly2"
112 set baz_vma [get_func_address "baz"  "baz"  "baz  runtime address"]
114 gdb_test "overlay map .ovly3" "" 
115 gdb_test "overlay list" "Section .ovly3, loaded at.*, mapped at.*" "list ovly3"
116 set grbx_vma [get_func_address "grbx" "grbx" "grbx runtime address"]
118 if {$data_overlays} {
119     gdb_test "overlay map .data00" "" 
120     gdb_test "overlay list" "Section .data00, loaded .*, mapped .*" "list data00"
121     gdb_test "print \$foox_vma = &foox" \
122         ".* $iptrcast 0x.*"  "foox runtime addr"
124     gdb_test "overlay map .data01" "" 
125     gdb_test "overlay list" "Section .data01, loaded .*, mapped .*" "list data01"
126     gdb_test "print \$barx_vma = &barx" \
127         ".* $iptrcast 0x.*"  "barx runtime addr"
129     gdb_test "overlay map .data02" "" 
130     gdb_test "overlay list" "Section .data02, loaded .*, mapped .*" "list data02"
131     gdb_test "print \$bazx_vma = &bazx" \
132         ".* $iptrcast 0x.*"  "bazx runtime addr"
134     gdb_test "overlay map .data03" "" 
135     gdb_test "overlay list" "Section .data03, loaded .*, mapped .*" "list data03"
136     gdb_test "print \$grbxx_vma = &grbxx" \
137         ".* $iptrcast 0x.*"  "grbxx runtime addr"
139 # Verify that LMA != VMA
141 gdb_test "print $foo_lma   != $foo_vma" ".* = 1"   "foo's LMA   != VMA"
142 gdb_test "print $bar_lma   != $bar_vma" ".* = 1"   "bar's LMA   != VMA"
143 gdb_test "print $baz_lma   != $baz_vma" ".* = 1"   "baz's LMA   != VMA"
144 gdb_test "print $grbx_lma  != $grbx_vma" ".* = 1"  "grbx's LMA  != VMA"
145 if {$data_overlays} {
146     gdb_test "print \$foox_lma  != \$foox_vma" ".* = 1"  "foox's LMA  != VMA"
147     gdb_test "print \$barx_lma  != \$barx_vma" ".* = 1"  "barx's LMA  != VMA"
148     gdb_test "print \$bazx_lma  != \$bazx_vma" ".* = 1"  "bazx's LMA  != VMA"
149     gdb_test "print \$grbxx_lma != \$grbxx_vma" ".* = 1" "grbxx's LMA != VMA"
152 # Verify that early-mapped overlays have been bumped out 
153 # by later-mapped overlays laid over in the same VMA range.
155 send_gdb "overlay list\n"
156 gdb_expect {
157     -re ".*ovly0, "             { fail ".ovly0  not unmapped by .ovly1"  }
158     -re ".*ovly2, "             { fail ".ovly2  not unmapped by .ovly3"  }
159     -re ".*data00,"             { fail ".data00 not unmapped by .data01" }
160     -re ".*data02,"             { fail ".data02 not unmapped by .data03" }
161     -re ".*$gdb_prompt $"       { pass "automatic unmapping"             }
162     timeout                     { fail "(timeout) Automatic unmapping"   }
165 # Verify that both sec1 and sec2 can be loaded simultaneously.
166 proc simultaneous_pair { sec1 sec2 } {
167     global gdb_prompt
169     set pairname "$sec1 and $sec2 mapped simultaneously"
170     gdb_test "overlay map $sec1" "" "$pairname: map $sec1"
171     gdb_test "overlay map $sec2" "" "$pairname: map $sec2"
173     set seen_sec1 0
174     set seen_sec2 0
176     send_gdb "overlay list\n"
177     gdb_expect {
178         -re ".*[string_to_regexp $sec1], " { set seen_sec1 1; exp_continue }
179         -re ".*[string_to_regexp $sec2], " { set seen_sec2 1; exp_continue }
180         -re ".*$gdb_prompt $" {
181             if {$seen_sec1 && $seen_sec2} {
182                 pass "$pairname"
183             } else {
184                 fail "$pairname"
185             }
186         }
187         timeout { fail "(timeout) $pairname" }
188     }
191 simultaneous_pair .ovly0 .ovly2
192 simultaneous_pair .ovly0 .ovly3
193 simultaneous_pair .ovly1 .ovly2
194 simultaneous_pair .ovly1 .ovly3
196 if {$data_overlays} {
197     simultaneous_pair .data00 .data02
198     simultaneous_pair .data00 .data03
199     simultaneous_pair .data01 .data02
200     simultaneous_pair .data01 .data03
203 # test automatic mode
205 gdb_test_no_output "overlay auto"
206 gdb_test "overlay list" "No sections are mapped." "list none mapped (auto)"
207 gdb_test "break foo"  "Breakpoint .*at .*file .*foo.c.*"  "break foo"
208 gdb_test "break bar"  "Breakpoint .*at .*file .*bar.c.*"  "break bar"
209 gdb_test "break baz"  "Breakpoint .*at .*file .*baz.c.*"  "break baz"
210 gdb_test "break grbx" "Breakpoint .*at .*file .*grbx.c.*" "break grbx"
212 send_gdb "continue\n"
213 gdb_expect {
214     -re "Breakpoint .* foo .x=1. at .*$gdb_prompt $" { pass   "hit foo" }
215     -re ".*$gdb_prompt $"                            { fail   "hit foo" }
216     timeout                                  { fail "(timeout) hit foo" }
219 send_gdb "backtrace\n"
220 gdb_expect {
221     -re "#0 .*foo .*#1 .*main .*$gdb_prompt $"       { pass   "BT foo" }
222     -re ".*$gdb_prompt $"                            { fail   "BT foo" }
223     timeout                                  { fail "(timeout) BT foo" }
227 send_gdb "continue\n"
228 gdb_expect {
229     -re "Breakpoint .* bar .x=1. at .*$gdb_prompt $" { pass   "hit bar" }
230     -re ".*$gdb_prompt $"                            { fail   "hit bar" }
231     timeout                                  { fail "(timeout) hit bar" }
234 send_gdb "backtrace\n"
235 gdb_expect {
236     -re "#0 .*bar .*#1 .*main .*$gdb_prompt $"       { pass   "BT bar" }
237     -re ".*$gdb_prompt $"                            { fail   "BT bar" }
238     timeout                                  { fail "(timeout) BT bar" }
241 send_gdb "continue\n"
242 gdb_expect {
243     -re "Breakpoint .* baz .x=1. at .*$gdb_prompt $" { pass   "hit baz" }
244     -re ".*$gdb_prompt $"                            { fail   "hit baz" }
245     timeout                                  { fail "(timeout) hit baz" }
248 send_gdb "backtrace\n"
249 gdb_expect {
250     -re "#0 .*baz .*#1 .*main .*$gdb_prompt $"       { pass   "BT baz" }
251     -re ".*$gdb_prompt $"                            { fail   "BT baz" }
252     timeout                                  { fail "(timeout) BT baz" }
255 send_gdb "continue\n"
256 gdb_expect {
257     -re "Breakpoint .* grbx .x=1. at .*$gdb_prompt $" { pass   "hit grbx" }
258     -re ".*$gdb_prompt $"                             { fail   "hit grbx" }
259     timeout                                   { fail "(timeout) hit grbx" }
262 send_gdb "backtrace\n"
263 gdb_expect {
264     -re "#0 .*grbx .*#1 .*main .*$gdb_prompt $"      { pass   "BT grbx" }
265     -re ".*$gdb_prompt $"                            { fail   "BT grbx" }
266     timeout                                  { fail "(timeout) BT grbx" }