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