]>
Commit | Line | Data |
---|---|---|
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 |
19 | standard_testfile .c |
20 | append binfile .o | |
a7d17088 DJ |
21 | |
22 | remote_exec build "rm -f ${binfile}" | |
f2dd3617 | 23 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } { |
84c93cd5 | 24 | untested "failed to compile" |
b60f0898 | 25 | return -1 |
a7d17088 DJ |
26 | } |
27 | ||
a7d17088 DJ |
28 | gdb_exit |
29 | gdb_start | |
30 | gdb_reinitialize_dir $srcdir/$subdir | |
31 | ||
41dc8db8 MB |
32 | #Check that invalid options are rejected. |
33 | foreach 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. | |
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 | |
46 | } | |
47 | } | |
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 | |
54 | } | |
55 | } | |
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 | |
60 | } | |
61 | } | |
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 | |
68 | } | |
69 | } | |
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 | |
74 | } | |
75 | } | |
ed6dfe51 PT |
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 | |
82 | } | |
83 | } | |
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 | |
89 | } | |
90 | } | |
40fc416f SDJ |
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 | |
99 | } | |
100 | } | |
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 | |
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. | |
118 | gdb_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" |
121 | clean_restart | |
122 | gdb_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" |
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" \ | |
3453e7e4 | 133 | "Reading symbols from ${binfile}\.\.\.\r\nExpanding full symbols from ${binfile}\.\.\." \ |
40fc416f SDJ |
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" | |
138 | ||
139 | clean_restart | |
140 | ||
02ca603a TT |
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" | |
147 | ||
a7d17088 DJ |
148 | # Load the object file. |
149 | gdb_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 | ||
c2b75043 LM |
155 | with_test_prefix "print addresses, static vars" { |
156 | # Print the addresses of static variables. | |
157 | set static_foo_addr [get_var_address static_foo] | |
158 | set static_bar_addr [get_var_address static_bar] | |
159 | } | |
a7d17088 DJ |
160 | |
161 | # Make sure they have different addresses. | |
162 | if { "${static_foo_addr}" == "${static_bar_addr}" } { | |
163 | fail "static variables have different addresses" | |
164 | } else { | |
165 | pass "static variables have different addresses" | |
166 | } | |
167 | ||
c2b75043 LM |
168 | with_test_prefix "print addresses, global vars" { |
169 | # Print the addresses of global variables. | |
170 | set global_foo_addr [get_var_address global_foo] | |
171 | set global_bar_addr [get_var_address global_bar] | |
172 | } | |
a7d17088 DJ |
173 | |
174 | # Make sure they have different addresses. | |
175 | if { "${global_foo_addr}" == "${global_bar_addr}" } { | |
176 | fail "global variables have different addresses" | |
177 | } else { | |
178 | pass "global variables have different addresses" | |
179 | } | |
180 | ||
c2b75043 LM |
181 | with_test_prefix "print addresses, functions" { |
182 | # Print the addresses of functions. | |
183 | set function_foo_addr [get_var_address function_foo] | |
184 | set function_bar_addr [get_var_address function_bar] | |
185 | } | |
a7d17088 DJ |
186 | |
187 | # Make sure they have different addresses. | |
188 | if { "${function_foo_addr}" == "${function_bar_addr}" } { | |
189 | fail "functions have different addresses" | |
190 | } else { | |
191 | pass "functions have different addresses" | |
192 | } | |
193 | ||
2f816dda DJ |
194 | # Now use a variable as an offset to add-symbol-file, and check that |
195 | # the functions' addresses change. | |
196 | ||
197 | gdb_exit | |
198 | gdb_start | |
199 | gdb_reinitialize_dir $srcdir/$subdir | |
200 | ||
27d3a1a2 | 201 | gdb_test_no_output "set \$offset = 0x10000" |
2f816dda DJ |
202 | |
203 | # Load the object file. | |
204 | gdb_test "add-symbol-file ${binfile} \$offset" \ | |
3453e7e4 | 205 | "Reading symbols from .*${testfile}\\.o\\.\\.\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \ |
2f816dda DJ |
206 | "add-symbol-file ${testfile}.o \$offset" \ |
207 | "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x10000\[\r\n\]+\\(y or n\\) " \ | |
208 | "y" | |
209 | ||
210 | # Print the addresses of functions. | |
211 | set new_function_foo_addr [get_var_address function_foo] | |
212 | ||
213 | # Make sure they have different addresses. | |
214 | if { "${function_foo_addr}" == "${new_function_foo_addr}" } { | |
215 | fail "function foo has a different address" | |
216 | } else { | |
217 | pass "function foo has a different address" | |
218 | } | |
219 | ||
d4d429d5 PT |
220 | # Load the object using symbol-file with an offset and check that |
221 | # all addresses are moved by that offset. | |
222 | ||
223 | set offset 0x10000 | |
224 | clean_restart | |
225 | gdb_test "symbol-file -o $offset $binfile" \ | |
3453e7e4 | 226 | "Reading symbols from ${binfile}\.\.\." \ |
d4d429d5 PT |
227 | "symbol-file with offset" |
228 | ||
c2b75043 LM |
229 | with_test_prefix "static vars" { |
230 | # Make sure the address of a static variable is moved by offset. | |
231 | set new_static_foo_addr [get_var_address static_foo] | |
232 | gdb_assert {${new_static_foo_addr} == ${static_foo_addr} + $offset} \ | |
233 | "static variable foo is moved by offset" | |
234 | } | |
d4d429d5 | 235 | |
c2b75043 LM |
236 | with_test_prefix "global vars" { |
237 | # Make sure the address of a global variable is moved by offset. | |
238 | set new_global_foo_addr [get_var_address global_foo] | |
239 | gdb_assert {${new_global_foo_addr} == ${global_foo_addr} + $offset} \ | |
240 | "global variable foo is moved by offset" | |
241 | } | |
d4d429d5 | 242 | |
c2b75043 LM |
243 | with_test_prefix "functions" { |
244 | # Make sure the address of a function is moved by offset. | |
245 | set new_function_foo_addr [get_var_address function_foo] | |
246 | gdb_assert {${new_function_foo_addr} == ${function_foo_addr} + $offset} \ | |
247 | "function foo is moved by offset" | |
248 | } | |
d4d429d5 | 249 | |
291f9a96 PT |
250 | # Load the object using add-symbol-file with an offset and check that |
251 | # all addresses are moved by that offset. | |
252 | ||
253 | set offset 0x10000 | |
254 | clean_restart | |
255 | gdb_test "add-symbol-file -o $offset $binfile" \ | |
3453e7e4 | 256 | "Reading symbols from ${binfile}\.\.\." \ |
291f9a96 PT |
257 | "add-symbol-file with offset" \ |
258 | "add symbol table from file \".*${testfile}\\.o\" with all sections offset by $offset\[\r\n\]+\\(y or n\\) " \ | |
259 | "y" | |
260 | ||
c2b75043 LM |
261 | with_test_prefix "static scope, 2nd" { |
262 | # Make sure the address of a static variable is moved by offset. | |
263 | set new_static_foo_addr [get_var_address static_foo] | |
264 | gdb_assert { ${new_static_foo_addr} == ${static_foo_addr} + $offset } \ | |
265 | "static variable foo is moved by offset" | |
266 | } | |
291f9a96 | 267 | |
c2b75043 LM |
268 | with_test_prefix "global vars, 2nd" { |
269 | # Make sure the address of a global variable is moved by offset. | |
270 | set new_global_foo_addr [get_var_address global_foo] | |
271 | gdb_assert { ${new_global_foo_addr} == ${global_foo_addr} + $offset } \ | |
272 | "global variable foo is moved by offset" | |
273 | } | |
291f9a96 | 274 | |
c2b75043 LM |
275 | with_test_prefix "functions, 2nd" { |
276 | # Make sure the address of a function is moved by offset. | |
277 | set new_function_foo_addr [get_var_address function_foo] | |
278 | gdb_assert { ${new_function_foo_addr} == ${function_foo_addr} + $offset } \ | |
279 | "function foo is moved by offset" | |
280 | } | |
291f9a96 PT |
281 | |
282 | # Re-load the object giving an explicit address for .text | |
283 | ||
284 | set text [ format "0x%x" [expr ${function_foo_addr} + 0x20000] ] | |
285 | clean_restart | |
286 | gdb_test "add-symbol-file $binfile -o $offset $text" \ | |
3453e7e4 | 287 | "Reading symbols from ${binfile}\.\.\." \ |
291f9a96 PT |
288 | "add-symbol-file with offset, text address given" \ |
289 | "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\\) " \ | |
290 | "y" | |
291 | ||
c2b75043 LM |
292 | with_test_prefix "functions, 3rd" { |
293 | # Make sure function has a different addresses now. | |
294 | set function_foo_addr [get_var_address function_foo] | |
295 | gdb_assert { ${function_foo_addr} != ${new_function_foo_addr} } \ | |
296 | "function foo has a different address" | |
297 | } | |
291f9a96 PT |
298 | |
299 | # Re-load the object giving an explicit address for .data | |
300 | ||
301 | set data [ format "0x%x" [expr ${global_foo_addr} + 0x20000] ] | |
302 | clean_restart | |
303 | gdb_test "add-symbol-file $binfile -o $offset -s .data $data" \ | |
3453e7e4 | 304 | "Reading symbols from ${binfile}\.\.\." \ |
291f9a96 PT |
305 | "add-symbol-file with offset, data address given" \ |
306 | "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\\) " \ | |
307 | "y" | |
308 | ||
c2b75043 LM |
309 | with_test_prefix "global vars, 3rd" { |
310 | # Make sure variable has a different addresses now. | |
311 | set global_foo_addr [get_var_address global_foo] | |
312 | gdb_assert { ${global_foo_addr} != ${new_global_foo_addr} } \ | |
313 | "global variable foo has a different address" | |
314 | } | |
291f9a96 | 315 | |
c1bd25fd DJ |
316 | # Now try loading the object as an exec-file; we should be able to print |
317 | # the values of variables after we do this. | |
318 | ||
319 | gdb_exit | |
320 | gdb_start | |
321 | gdb_reinitialize_dir $srcdir/$subdir | |
582e64c2 | 322 | gdb_file_cmd ${binfile} |
c1bd25fd DJ |
323 | |
324 | # Check the values of the variables. | |
325 | gdb_test "print static_foo" "\\\$$decimal = 1" | |
326 | gdb_test "print static_bar" "\\\$$decimal = 2" | |
327 | gdb_test "print global_foo" "\\\$$decimal = 3" | |
328 | gdb_test "print global_bar" "\\\$$decimal = 4" |