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