Do not set prms_id/bug_id anymore.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / shreloc.exp
CommitLineData
4c38e0a4
JB
1# Copyright (C) 2003, 2005, 2007, 2008, 2009, 2010
2# Free Software Foundation, Inc.
53df362e
RG
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
53df362e
RG
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
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
53df362e
RG
16#
17
53df362e
RG
18# Tests for shared object file relocation. If two shared objects have
19# the same load address (actually, overlapping load spaces), one of
20# them gets relocated at load-time. Check that gdb gets the right
21# values for the debugging and minimal symbols.
22
93f02886 23if {[skip_shlib_tests]} {
d9407aaa
NC
24 return 0
25}
26
53df362e
RG
27if $tracelevel then {
28 strace $tracelevel
29}
30
31#
32# This file uses shreloc.c, shreloc1.c and shreloc2.c
33#
34
53df362e
RG
35
36set workdir ${objdir}/${subdir}
96b0c7ac
DJ
37set testfile "shreloc"
38set libfile1 "shreloc1"
39set libfile2 "shreloc2"
40set srcfile $srcdir/$subdir/$testfile.c
41set lib1src $srcdir/$subdir/$libfile1.c
42set lib2src $srcdir/$subdir/$libfile2.c
43set binfile $objdir/$subdir/$testfile
44set lib1_sl $objdir/$subdir/$libfile1.sl
45set lib2_sl $objdir/$subdir/$libfile2.sl
46
47if [get_compiler_info ${binfile}] {
48 return -1
53df362e
RG
49}
50
96b0c7ac
DJ
51set lib_opts "debug"
52set exec_opts [list debug shlib=$lib1_sl shlib=$lib2_sl]
53df362e
RG
53
54if {([istarget "*pc-cygwin"] || [istarget "*pc-mingw32"]) } {
05cfdb42 55 lappend lib_opts "ldflags=-Wl,--image-base,0x04000000"
53df362e
RG
56}
57
96b0c7ac
DJ
58if [test_compiler_info "xlc-*"] {
59
60 # IBM's xlc compiler does not add static variables to the ELF symbol
61 # table by default. We need this option to make the variables show
62 # up in "maint print msymbols".
63
64 lappend lib_opts "additional_flags=-qstatsym"
65
53df362e
RG
66}
67
96b0c7ac
DJ
68if { [gdb_compile_shlib $lib1src $lib1_sl $lib_opts] != ""} {
69 untested "Could not build $lib1_sl."
70 return -1
71} elseif { [gdb_compile_shlib $lib2src $lib2_sl $lib_opts] != ""} {
72 untested "Could not build $lib1_s2."
73 return -1
74} elseif { [gdb_compile $srcfile $binfile executable $exec_opts] != ""} {
75 untested "Could not build $binfile."
53df362e
RG
76 return -1
77}
78
96b0c7ac
DJ
79# Start with a fresh gdb.
80
53df362e
RG
81gdb_exit
82gdb_start
83gdb_reinitialize_dir $srcdir/$subdir
84gdb_load ${workdir}/shreloc
93f02886 85gdb_load_shlibs $lib1_sl $lib2_sl
53df362e
RG
86
87# Load up the shared objects
88if ![runto_main] then {
89 fail "Can't run to main"
90 return 0
91}
92
93proc get_var_address { var } {
94 global gdb_prompt hex
95
96 send_gdb "print &${var}\n"
97 # Match output like:
98 # $1 = (int *) 0x0
99 # $5 = (int (*)()) 0
100 # $6 = (int (*)()) 0x24 <function_bar>
101 gdb_expect {
102 -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $"
103 {
104 pass "get address of ${var}"
105 if { $expect_out(1,string) == "0" } {
106 return "0x0"
107 } else {
108 return $expect_out(1,string)
109 }
110 }
111 -re "${gdb_prompt} $"
112 { fail "get address of ${var} (unknown output)" }
113 timeout
114 { fail "get address of ${var} (timeout)" }
115 }
116 return ""
117}
118
119#
120# Check debugging symbol relocations
121#
122
123# Check extern function for relocation
124set fn_1_addr [get_var_address fn_1]
125set fn_2_addr [get_var_address fn_2]
126
127if { "${fn_1_addr}" == "${fn_2_addr}" } {
128 fail "relocated extern functions have different addresses"
129} else {
130 pass "relocated extern functions have different addresses"
131}
132
133# Check extern var for relocation
134set extern_var_1_addr [get_var_address extern_var_1]
135set extern_var_2_addr [get_var_address extern_var_2]
136
137if { "${extern_var_1_addr}" == "${extern_var_2_addr}" } {
138 fail "relocated extern variables have different addresses"
139} else {
140 pass "relocated extern variables have different addresses"
141}
142
143# Check static var for relocation
144set static_var_1_addr [get_var_address static_var_1]
145set static_var_2_addr [get_var_address static_var_2]
146
147if { "${static_var_1_addr}" == "${static_var_2_addr}" } {
148 fail "relocated static variables have different addresses"
149} else {
150 pass "relocated static variables have different addresses"
151}
152
153#
154# Check minimal symbol relocations
155#
156
157proc send_gdb_discard { command } {
158 # Send a command to gdb and discard output up to the next prompt
159
160 global gdb_prompt
161
162 send_gdb "${command}\n"
163
164 # Discard output
165 gdb_expect {
166 -re ".*\[\r\n]+${gdb_prompt} $" {
167 return 1
168 }
169 timeout {
170 fail "{$command} (timeout)"
171 return 0
172 }
173 }
174}
175
176proc get_msym_addrs { var msymfile } {
177 # Extract the list of values for symbols matching var in the
178 # minimal symbol output file
179
180 global gdb_prompt hex
181 set result ""
182
183 send_gdb "shell grep -E \" ${var}(\[ \t\]+.*)?\$\" ${msymfile}\n"
184
185 while 1 {
186 gdb_expect {
187 -re "\[\[\]\[ 0-9\]+\] . (${hex}) ${var}(\[ \t\]+\[^\r\n\]*)?\[\r\n\]+" {
188 set result [concat $result $expect_out(1,string)]
189 }
190
191 -re "$gdb_prompt $" {
a8b7528f 192 pass "get_msym_addrs ${var}"
53df362e
RG
193 return "${result}"
194 }
195
196 -re "\[^\r\n\]*\[\r\n\]+" {
197 # Skip
198 }
199
200 timeout {
201 fail "get_msym_addrs ${var} (timeout)"
202 return -1
203 }
204 }
205 }
206}
207
208proc check_same {var msymfile} {
209 # Check that the minimal symbol values matching var are the same
210
211 set len [llength [lsort -unique [get_msym_addrs "${var}" "${msymfile}"]]]
212
213 if { $len == 1 } {
214 return 1
215 } else {
216 return 0
217 }
218}
219
220proc check_different {var msymfile} {
221 # Check that the minimal symbol values matching var are different
222
223 set addr_list [lsort [get_msym_addrs "${var}" "${msymfile}"]]
224 set prev ""
225
226 if { [llength ${addr_list}] < 2 } {
227 return 0
228 }
229
230 foreach addr ${addr_list} {
231 if { ${prev} == ${addr} } {
232 return 0
233 }
234 set prev ${addr}
235 }
236
237 return 1
238}
239
240set msymfile "${workdir}/shreloc.txt"
241
242if [send_gdb_discard "maint print msymbols ${msymfile}"] {
243 if {[check_different "static_var_\[12\]" "${msymfile}"]} {
244 pass "(msymbol) relocated static vars have different addresses"
245 } else {
246 fail "(msymbol) relocated static vars have different addresses"
247 }
248
249 if {[check_different "extern_var_\[12\]" "${msymfile}"]} {
250 pass "(msymbol) relocated extern vars have different addresses"
251 } else {
252 fail "(msymbol) relocated extern vars have different addresses"
253 }
254
255 if {[check_different "fn_\[12\]" "${msymfile}"]} {
256 pass "(msymbol) relocated functions have different addresses"
257 } else {
258 fail "(msymbol) relocated functions have different addresses"
259 }
260}
261
262if {([istarget "*pc-cygwin"] || [istarget "*pc-mingw32"]) } {
263 #
264 # We know the names of some absolute symbols included in the
265 # portable-executable (DLL) format. Check that they didn't get
266 # relocated.
267 #
268 # A better approach would be include absolute symbols via the assembler.
269 #
270 if {[check_same "_minor_os_version__" "${msymfile}"]} {
271 pass "Absolute symbols not relocated"
272 } else {
273 fail "Absolute symbols not relocated"
274 }
275}
This page took 0.660716 seconds and 4 git commands to generate.