[PATCH 7/57][Arm][GAS] Add support for MVE instructions: vstr/vldr
[binutils-gdb.git] / gdb / testsuite / gdb.base / relocate.exp
bloba20a45edabd0c05966f0dc9564476f06f987a257
1 # Copyright 2002-2019 Free Software Foundation, Inc.
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 # relocate.exp -- Expect script to test loading symbols from unrelocated
17 # object files.
19 standard_testfile .c
20 append binfile .o
22 remote_exec build "rm -f ${binfile}"
23 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } {
24 untested "failed to compile"
25 return -1
28 gdb_exit
29 gdb_start
30 gdb_reinitialize_dir $srcdir/$subdir
32 #Check that invalid options are rejected.
33 foreach x {"-raednow" "readnow" "foo" "-readnow s"} {
34 set word [lindex $x [expr [llength $x]-1]]
35 gdb_test "add-symbol-file ${binfile} 0 $x" \
36 "Unrecognized argument \"$word\"" \
37 "add-symbol-file: unknown option $word"
40 # Check that we can pass parameters using any position in the command
41 # line.
42 set test "add-symbol-file positionless -readnow"
43 gdb_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
48 # When we use -s as the first argument, the section will be printed
49 # first as well.
50 set test "add-symbol-file positionless -s"
51 gdb_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
56 set test "add-symbol-file positionless -s, no -readnow"
57 gdb_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
62 # Check that passing "-s .text", no matter the position, always has
63 # the same result.
64 set test "add-symbol-file different -s .text, after file"
65 gdb_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
70 set test "add-symbol-file different -s .text, before file"
71 gdb_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
76 # Check that passing a single "-s .text" is equivalent to passing
77 # the text address in a positional argument.
78 set test "add-symbol-file -s .text, no address"
79 gdb_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
84 # Check section addresses can be omitted.
85 set test "add-symbol-file no address"
86 gdb_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
91 # Test that passing "--" disables option processing.
92 gdb_test "add-symbol-file -- $binfile 0x100 -s .bss 0x3" \
93 "Unrecognized argument \"-s\"" \
94 "add-symbol-file with -- disables option processing"
95 set test "add-symbol-file with -- disables option processing, non-existent filename"
96 gdb_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
101 # Test that passing the wrong number of arguments to '-s' leads to an
102 # error.
103 gdb_test "add-symbol-file $binfile -s" \
104 "Missing section name after \"-s\"" \
105 "add-symbol-file with -s without section name"
106 gdb_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 '-'
110 set test "add-symbol-file with -s using section name starting with dash"
111 gdb_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
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.
118 gdb_test "symbol-file -readnow $binfile" \
119 "Reading symbols from ${binfile}\.\.\.\r\nExpanding full symbols from ${binfile}\.\.\." \
120 "symbol-file with -readnow first"
121 clean_restart
122 gdb_test "symbol-file $binfile -readnow" \
123 "Reading symbols from ${binfile}\.\.\.\r\nExpanding full symbols from ${binfile}\.\.\." \
124 "symbol-file with -readnow second"
125 gdb_test "symbol-file -readnow" \
126 "no symbol file name was specified" \
127 "symbol-file without filename"
128 gdb_test "symbol-file -- -non-existent-file" \
129 "-non-existent-file: No such file or directory\." \
130 "symbol-file with -- disables option processing"
131 clean_restart
132 gdb_test "symbol-file -readnow -- $binfile" \
133 "Reading symbols from ${binfile}\.\.\.\r\nExpanding full symbols from ${binfile}\.\.\." \
134 "symbol-file with -- and -readnow"
135 gdb_test "symbol-file -- $binfile -readnow" \
136 "Unrecognized argument \"-readnow\"" \
137 "symbol-file with -- and -readnow, invalid option"
139 clean_restart
141 gdb_test "add-symbol-file ${binfile} 0 -s" \
142 "Missing section name after .-s." \
143 "add-symbol-file bare -s"
144 gdb_test "add-symbol-file ${binfile} 0 -s .whatever" \
145 "Missing section address after .-s." \
146 "add-symbol-file missing address"
148 # Load the object file.
149 gdb_test "add-symbol-file ${binfile} 0" \
150 "Reading symbols from .*${testfile}\\.o\\.\\.\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
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\\) " \
155 # Print the addresses of static variables.
156 set static_foo_addr [get_var_address static_foo]
157 set static_bar_addr [get_var_address static_bar]
159 # Make sure they have different addresses.
160 if { "${static_foo_addr}" == "${static_bar_addr}" } {
161 fail "static variables have different addresses"
162 } else {
163 pass "static variables have different addresses"
166 # Print the addresses of global variables.
167 set global_foo_addr [get_var_address global_foo]
168 set global_bar_addr [get_var_address global_bar]
170 # Make sure they have different addresses.
171 if { "${global_foo_addr}" == "${global_bar_addr}" } {
172 fail "global variables have different addresses"
173 } else {
174 pass "global variables have different addresses"
177 # Print the addresses of functions.
178 set function_foo_addr [get_var_address function_foo]
179 set function_bar_addr [get_var_address function_bar]
181 # Make sure they have different addresses.
182 if { "${function_foo_addr}" == "${function_bar_addr}" } {
183 fail "functions have different addresses"
184 } else {
185 pass "functions have different addresses"
188 # Now use a variable as an offset to add-symbol-file, and check that
189 # the functions' addresses change.
191 gdb_exit
192 gdb_start
193 gdb_reinitialize_dir $srcdir/$subdir
195 gdb_test_no_output "set \$offset = 0x10000"
197 # Load the object file.
198 gdb_test "add-symbol-file ${binfile} \$offset" \
199 "Reading symbols from .*${testfile}\\.o\\.\\.\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
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\\) " \
204 # Print the addresses of functions.
205 set new_function_foo_addr [get_var_address function_foo]
207 # Make sure they have different addresses.
208 if { "${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"
214 # Load the object using symbol-file with an offset and check that
215 # all addresses are moved by that offset.
217 set offset 0x10000
218 clean_restart
219 gdb_test "symbol-file -o $offset $binfile" \
220 "Reading symbols from ${binfile}\.\.\." \
221 "symbol-file with offset"
223 # Make sure the address of a static variable is moved by offset.
224 set new_static_foo_addr [get_var_address static_foo]
225 gdb_assert {${new_static_foo_addr} == ${static_foo_addr} + $offset} \
226 "static variable foo is moved by offset"
228 # Make sure the address of a global variable is moved by offset.
229 set new_global_foo_addr [get_var_address global_foo]
230 gdb_assert {${new_global_foo_addr} == ${global_foo_addr} + $offset} \
231 "global variable foo is moved by offset"
233 # Make sure the address of a function is moved by offset.
234 set new_function_foo_addr [get_var_address function_foo]
235 gdb_assert {${new_function_foo_addr} == ${function_foo_addr} + $offset} \
236 "function foo is moved by offset"
238 # Load the object using add-symbol-file with an offset and check that
239 # all addresses are moved by that offset.
241 set offset 0x10000
242 clean_restart
243 gdb_test "add-symbol-file -o $offset $binfile" \
244 "Reading symbols from ${binfile}\.\.\." \
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\\) " \
249 # Make sure the address of a static variable is moved by offset.
250 set new_static_foo_addr [get_var_address static_foo]
251 gdb_assert { ${new_static_foo_addr} == ${static_foo_addr} + $offset } \
252 "static variable foo is moved by offset"
254 # Make sure the address of a global variable is moved by offset.
255 set new_global_foo_addr [get_var_address global_foo]
256 gdb_assert { ${new_global_foo_addr} == ${global_foo_addr} + $offset } \
257 "global variable foo is moved by offset"
259 # Make sure the address of a function is moved by offset.
260 set new_function_foo_addr [get_var_address function_foo]
261 gdb_assert { ${new_function_foo_addr} == ${function_foo_addr} + $offset } \
262 "function foo is moved by offset"
264 # Re-load the object giving an explicit address for .text
266 set text [ format "0x%x" [expr ${function_foo_addr} + 0x20000] ]
267 clean_restart
268 gdb_test "add-symbol-file $binfile -o $offset $text" \
269 "Reading symbols from ${binfile}\.\.\." \
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\\) " \
274 # Make sure function has a different addresses now.
275 set function_foo_addr [get_var_address function_foo]
276 gdb_assert { ${function_foo_addr} != ${new_function_foo_addr} } \
277 "function foo has a different address"
279 # Re-load the object giving an explicit address for .data
281 set data [ format "0x%x" [expr ${global_foo_addr} + 0x20000] ]
282 clean_restart
283 gdb_test "add-symbol-file $binfile -o $offset -s .data $data" \
284 "Reading symbols from ${binfile}\.\.\." \
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\\) " \
289 # Make sure variable has a different addresses now.
290 set global_foo_addr [get_var_address global_foo]
291 gdb_assert { ${global_foo_addr} != ${new_global_foo_addr} } \
292 "global variable foo has a different address"
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.
297 gdb_exit
298 gdb_start
299 gdb_reinitialize_dir $srcdir/$subdir
300 gdb_file_cmd ${binfile}
302 # Check the values of the variables.
303 gdb_test "print static_foo" "\\\$$decimal = 1"
304 gdb_test "print static_bar" "\\\$$decimal = 2"
305 gdb_test "print global_foo" "\\\$$decimal = 3"
306 gdb_test "print global_bar" "\\\$$decimal = 4"