gdb: handle endbr64 instruction in amd64_analyze_prologue
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / relocate.exp
CommitLineData
b811d2c2 1# Copyright 2002-2020 Free Software Foundation, Inc.
a7d17088
DJ
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
a7d17088 6# (at your option) any later version.
e22f8b7c 7#
a7d17088
DJ
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.
e22f8b7c 12#
a7d17088 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>. */
a7d17088 15
a7d17088
DJ
16# relocate.exp -- Expect script to test loading symbols from unrelocated
17# object files.
18
822bd149
TT
19standard_testfile .c
20append binfile .o
a7d17088
DJ
21
22remote_exec build "rm -f ${binfile}"
f2dd3617 23if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } {
84c93cd5 24 untested "failed to compile"
b60f0898 25 return -1
a7d17088
DJ
26}
27
a7d17088
DJ
28gdb_exit
29gdb_start
30gdb_reinitialize_dir $srcdir/$subdir
31
41dc8db8
MB
32#Check that invalid options are rejected.
33foreach x {"-raednow" "readnow" "foo" "-readnow s"} {
02ca603a 34 set word [lindex $x [expr [llength $x]-1]]
41dc8db8 35 gdb_test "add-symbol-file ${binfile} 0 $x" \
02ca603a
TT
36 "Unrecognized argument \"$word\"" \
37 "add-symbol-file: unknown option $word"
41dc8db8
MB
38}
39
40fc416f
SDJ
40# Check that we can pass parameters using any position in the command
41# line.
42set test "add-symbol-file positionless -readnow"
43gdb_test_multiple "add-symbol-file -readnow $binfile 0x100 -s .bss 0x3" $test {
44 -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\.bss_addr = 0x3\r\n\\(y or n\\) " {
45 gdb_test "n" "Not confirmed\." $test
46 }
47}
48# When we use -s as the first argument, the section will be printed
49# first as well.
50set test "add-symbol-file positionless -s"
51gdb_test_multiple "add-symbol-file -s .bss 0x3 -readnow $binfile 0x100" $test {
52 -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\.bss_addr = 0x3\r\n\\(y or n\\) " {
53 gdb_test "n" "Not confirmed\." $test
54 }
55}
56set test "add-symbol-file positionless -s, no -readnow"
57gdb_test_multiple "add-symbol-file $binfile 0x100 -s .bss 0x3" $test {
58 -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\.bss_addr = 0x3\r\n\\(y or n\\) " {
59 gdb_test "n" "Not confirmed\." $test
60 }
61}
62# Check that passing "-s .text", no matter the position, always has
63# the same result.
64set test "add-symbol-file different -s .text, after file"
65gdb_test_multiple "add-symbol-file $binfile 0x100 -s .text 0x200" $test {
66 -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\.text_addr = 0x200\r\n\\(y or n\\) " {
67 gdb_test "n" "Not confirmed\." $test
68 }
69}
70set test "add-symbol-file different -s .text, before file"
71gdb_test_multiple "add-symbol-file -s .text 0x200 $binfile 0x100" $test {
72 -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\.text_addr = 0x200\r\n\\(y or n\\) " {
73 gdb_test "n" "Not confirmed\." $test
74 }
75}
ed6dfe51
PT
76# Check that passing a single "-s .text" is equivalent to passing
77# the text address in a positional argument.
78set test "add-symbol-file -s .text, no address"
79gdb_test_multiple "add-symbol-file $binfile -s .text 0x100" $test {
80 -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\\(y or n\\) " {
81 gdb_test "n" "Not confirmed\." $test
82 }
83}
84# Check section addresses can be omitted.
85set test "add-symbol-file no address"
86gdb_test_multiple "add-symbol-file $binfile" $test {
87 -re "add symbol table from file \"${binfile}\"\r\n\\(y or n\\) " {
88 gdb_test "n" "Not confirmed\." $test
89 }
90}
40fc416f
SDJ
91# Test that passing "--" disables option processing.
92gdb_test "add-symbol-file -- $binfile 0x100 -s .bss 0x3" \
93 "Unrecognized argument \"-s\"" \
94 "add-symbol-file with -- disables option processing"
95set test "add-symbol-file with -- disables option processing, non-existent filename"
96gdb_test_multiple "add-symbol-file -- -non-existent-file 0x100" $test {
97 -re "add symbol table from file \"-non-existent-file\" at\r\n\t\.text_addr = 0x100\r\n\\(y or n\\) " {
98 gdb_test "y" "-non-existent-file: No such file or directory\." $test
99 }
100}
101# Test that passing the wrong number of arguments to '-s' leads to an
102# error.
103gdb_test "add-symbol-file $binfile -s" \
104 "Missing section name after \"-s\"" \
105 "add-symbol-file with -s without section name"
106gdb_test "add-symbol-file $binfile -s .bss" \
107 "Missing section address after \"-s\"" \
108 "add-symbol-file with -s without section address"
109# Test that '-s' accepts section names with '-'
110set test "add-symbol-file with -s using section name starting with dash"
111gdb_test_multiple "add-symbol-file -s -section-name 0x200 $binfile 0x100" $test {
112 -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\t\-section-name_addr = 0x200\r\n\\(y or n\\) " {
113 gdb_test "n" "Not confirmed\." $test
114 }
115}
116# Since we're here, might as well test the 'symbol-file' command and
117# if its arguments can also be passed at any position.
118gdb_test "symbol-file -readnow $binfile" \
3453e7e4 119 "Reading symbols from ${binfile}\.\.\.\r\nExpanding full symbols from ${binfile}\.\.\." \
40fc416f
SDJ
120 "symbol-file with -readnow first"
121clean_restart
122gdb_test "symbol-file $binfile -readnow" \
3453e7e4 123 "Reading symbols from ${binfile}\.\.\.\r\nExpanding full symbols from ${binfile}\.\.\." \
40fc416f
SDJ
124 "symbol-file with -readnow second"
125gdb_test "symbol-file -readnow" \
126 "no symbol file name was specified" \
127 "symbol-file without filename"
128gdb_test "symbol-file -- -non-existent-file" \
129 "-non-existent-file: No such file or directory\." \
130 "symbol-file with -- disables option processing"
131clean_restart
132gdb_test "symbol-file -readnow -- $binfile" \
3453e7e4 133 "Reading symbols from ${binfile}\.\.\.\r\nExpanding full symbols from ${binfile}\.\.\." \
40fc416f
SDJ
134 "symbol-file with -- and -readnow"
135gdb_test "symbol-file -- $binfile -readnow" \
136 "Unrecognized argument \"-readnow\"" \
137 "symbol-file with -- and -readnow, invalid option"
138
139clean_restart
140
02ca603a
TT
141gdb_test "add-symbol-file ${binfile} 0 -s" \
142 "Missing section name after .-s." \
143 "add-symbol-file bare -s"
144gdb_test "add-symbol-file ${binfile} 0 -s .whatever" \
145 "Missing section address after .-s." \
146 "add-symbol-file missing address"
147
a7d17088
DJ
148# Load the object file.
149gdb_test "add-symbol-file ${binfile} 0" \
3453e7e4 150 "Reading symbols from .*${testfile}\\.o\\.\\.\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
a7d17088
DJ
151 "add-symbol-file ${testfile}.o 0" \
152 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0\[\r\n\]+\\(y or n\\) " \
153 "y"
154
155# Print the addresses of static variables.
156set static_foo_addr [get_var_address static_foo]
157set static_bar_addr [get_var_address static_bar]
158
159# Make sure they have different addresses.
160if { "${static_foo_addr}" == "${static_bar_addr}" } {
161 fail "static variables have different addresses"
162} else {
163 pass "static variables have different addresses"
164}
165
166# Print the addresses of global variables.
167set global_foo_addr [get_var_address global_foo]
168set global_bar_addr [get_var_address global_bar]
169
170# Make sure they have different addresses.
171if { "${global_foo_addr}" == "${global_bar_addr}" } {
172 fail "global variables have different addresses"
173} else {
174 pass "global variables have different addresses"
175}
176
177# Print the addresses of functions.
178set function_foo_addr [get_var_address function_foo]
179set function_bar_addr [get_var_address function_bar]
180
181# Make sure they have different addresses.
182if { "${function_foo_addr}" == "${function_bar_addr}" } {
183 fail "functions have different addresses"
184} else {
185 pass "functions have different addresses"
186}
187
2f816dda
DJ
188# Now use a variable as an offset to add-symbol-file, and check that
189# the functions' addresses change.
190
191gdb_exit
192gdb_start
193gdb_reinitialize_dir $srcdir/$subdir
194
27d3a1a2 195gdb_test_no_output "set \$offset = 0x10000"
2f816dda
DJ
196
197# Load the object file.
198gdb_test "add-symbol-file ${binfile} \$offset" \
3453e7e4 199 "Reading symbols from .*${testfile}\\.o\\.\\.\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
2f816dda
DJ
200 "add-symbol-file ${testfile}.o \$offset" \
201 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x10000\[\r\n\]+\\(y or n\\) " \
202 "y"
203
204# Print the addresses of functions.
205set new_function_foo_addr [get_var_address function_foo]
206
207# Make sure they have different addresses.
208if { "${function_foo_addr}" == "${new_function_foo_addr}" } {
209 fail "function foo has a different address"
210} else {
211 pass "function foo has a different address"
212}
213
d4d429d5
PT
214# Load the object using symbol-file with an offset and check that
215# all addresses are moved by that offset.
216
217set offset 0x10000
218clean_restart
219gdb_test "symbol-file -o $offset $binfile" \
3453e7e4 220 "Reading symbols from ${binfile}\.\.\." \
d4d429d5
PT
221 "symbol-file with offset"
222
223# Make sure the address of a static variable is moved by offset.
224set new_static_foo_addr [get_var_address static_foo]
225gdb_assert {${new_static_foo_addr} == ${static_foo_addr} + $offset} \
226 "static variable foo is moved by offset"
227
228# Make sure the address of a global variable is moved by offset.
229set new_global_foo_addr [get_var_address global_foo]
230gdb_assert {${new_global_foo_addr} == ${global_foo_addr} + $offset} \
231 "global variable foo is moved by offset"
232
233# Make sure the address of a function is moved by offset.
234set new_function_foo_addr [get_var_address function_foo]
235gdb_assert {${new_function_foo_addr} == ${function_foo_addr} + $offset} \
236 "function foo is moved by offset"
237
291f9a96
PT
238# Load the object using add-symbol-file with an offset and check that
239# all addresses are moved by that offset.
240
241set offset 0x10000
242clean_restart
243gdb_test "add-symbol-file -o $offset $binfile" \
3453e7e4 244 "Reading symbols from ${binfile}\.\.\." \
291f9a96
PT
245 "add-symbol-file with offset" \
246 "add symbol table from file \".*${testfile}\\.o\" with all sections offset by $offset\[\r\n\]+\\(y or n\\) " \
247 "y"
248
249# Make sure the address of a static variable is moved by offset.
250set new_static_foo_addr [get_var_address static_foo]
251gdb_assert { ${new_static_foo_addr} == ${static_foo_addr} + $offset } \
252 "static variable foo is moved by offset"
253
254# Make sure the address of a global variable is moved by offset.
255set new_global_foo_addr [get_var_address global_foo]
256gdb_assert { ${new_global_foo_addr} == ${global_foo_addr} + $offset } \
257 "global variable foo is moved by offset"
258
259# Make sure the address of a function is moved by offset.
260set new_function_foo_addr [get_var_address function_foo]
261gdb_assert { ${new_function_foo_addr} == ${function_foo_addr} + $offset } \
262 "function foo is moved by offset"
263
264# Re-load the object giving an explicit address for .text
265
266set text [ format "0x%x" [expr ${function_foo_addr} + 0x20000] ]
267clean_restart
268gdb_test "add-symbol-file $binfile -o $offset $text" \
3453e7e4 269 "Reading symbols from ${binfile}\.\.\." \
291f9a96
PT
270 "add-symbol-file with offset, text address given" \
271 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = ${text}\[\r\n\]+with other sections offset by ${offset}\[\r\n\]+\\(y or n\\) " \
272 "y"
273
274# Make sure function has a different addresses now.
275set function_foo_addr [get_var_address function_foo]
276gdb_assert { ${function_foo_addr} != ${new_function_foo_addr} } \
277 "function foo has a different address"
278
279# Re-load the object giving an explicit address for .data
280
281set data [ format "0x%x" [expr ${global_foo_addr} + 0x20000] ]
282clean_restart
283gdb_test "add-symbol-file $binfile -o $offset -s .data $data" \
3453e7e4 284 "Reading symbols from ${binfile}\.\.\." \
291f9a96
PT
285 "add-symbol-file with offset, data address given" \
286 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.data_addr = ${data}\[\r\n\]+with other sections offset by ${offset}\[\r\n\]+\\(y or n\\) " \
287 "y"
288
289# Make sure variable has a different addresses now.
290set global_foo_addr [get_var_address global_foo]
291gdb_assert { ${global_foo_addr} != ${new_global_foo_addr} } \
292 "global variable foo has a different address"
293
c1bd25fd
DJ
294# Now try loading the object as an exec-file; we should be able to print
295# the values of variables after we do this.
296
297gdb_exit
298gdb_start
299gdb_reinitialize_dir $srcdir/$subdir
582e64c2 300gdb_file_cmd ${binfile}
c1bd25fd
DJ
301
302# Check the values of the variables.
303gdb_test "print static_foo" "\\\$$decimal = 1"
304gdb_test "print static_bar" "\\\$$decimal = 2"
305gdb_test "print global_foo" "\\\$$decimal = 3"
306gdb_test "print global_bar" "\\\$$decimal = 4"
This page took 2.186452 seconds and 4 git commands to generate.