]>
Commit | Line | Data |
---|---|---|
1d506c26 | 1 | # Copyright 2002-2024 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 | ||
c95d486d | 28 | clean_restart |
a7d17088 | 29 | |
41dc8db8 MB |
30 | #Check that invalid options are rejected. |
31 | foreach x {"-raednow" "readnow" "foo" "-readnow s"} { | |
02ca603a | 32 | set word [lindex $x [expr [llength $x]-1]] |
41dc8db8 | 33 | gdb_test "add-symbol-file ${binfile} 0 $x" \ |
02ca603a TT |
34 | "Unrecognized argument \"$word\"" \ |
35 | "add-symbol-file: unknown option $word" | |
41dc8db8 MB |
36 | } |
37 | ||
40fc416f SDJ |
38 | # Check that we can pass parameters using any position in the command |
39 | # line. | |
40 | set test "add-symbol-file positionless -readnow" | |
41 | gdb_test_multiple "add-symbol-file -readnow $binfile 0x100 -s .bss 0x3" $test { | |
42 | -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\\) " { | |
43 | gdb_test "n" "Not confirmed\." $test | |
44 | } | |
45 | } | |
46 | # When we use -s as the first argument, the section will be printed | |
47 | # first as well. | |
48 | set test "add-symbol-file positionless -s" | |
49 | gdb_test_multiple "add-symbol-file -s .bss 0x3 -readnow $binfile 0x100" $test { | |
50 | -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\\) " { | |
51 | gdb_test "n" "Not confirmed\." $test | |
52 | } | |
53 | } | |
54 | set test "add-symbol-file positionless -s, no -readnow" | |
55 | gdb_test_multiple "add-symbol-file $binfile 0x100 -s .bss 0x3" $test { | |
56 | -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\\) " { | |
57 | gdb_test "n" "Not confirmed\." $test | |
58 | } | |
59 | } | |
60 | # Check that passing "-s .text", no matter the position, always has | |
61 | # the same result. | |
62 | set test "add-symbol-file different -s .text, after file" | |
63 | gdb_test_multiple "add-symbol-file $binfile 0x100 -s .text 0x200" $test { | |
64 | -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\\) " { | |
65 | gdb_test "n" "Not confirmed\." $test | |
66 | } | |
67 | } | |
68 | set test "add-symbol-file different -s .text, before file" | |
69 | gdb_test_multiple "add-symbol-file -s .text 0x200 $binfile 0x100" $test { | |
70 | -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\\) " { | |
71 | gdb_test "n" "Not confirmed\." $test | |
72 | } | |
73 | } | |
ed6dfe51 PT |
74 | # Check that passing a single "-s .text" is equivalent to passing |
75 | # the text address in a positional argument. | |
76 | set test "add-symbol-file -s .text, no address" | |
77 | gdb_test_multiple "add-symbol-file $binfile -s .text 0x100" $test { | |
78 | -re "add symbol table from file \"${binfile}\" at\r\n\t\.text_addr = 0x100\r\n\\(y or n\\) " { | |
79 | gdb_test "n" "Not confirmed\." $test | |
80 | } | |
81 | } | |
82 | # Check section addresses can be omitted. | |
83 | set test "add-symbol-file no address" | |
84 | gdb_test_multiple "add-symbol-file $binfile" $test { | |
85 | -re "add symbol table from file \"${binfile}\"\r\n\\(y or n\\) " { | |
86 | gdb_test "n" "Not confirmed\." $test | |
87 | } | |
88 | } | |
40fc416f SDJ |
89 | # Test that passing "--" disables option processing. |
90 | gdb_test "add-symbol-file -- $binfile 0x100 -s .bss 0x3" \ | |
91 | "Unrecognized argument \"-s\"" \ | |
92 | "add-symbol-file with -- disables option processing" | |
93 | set test "add-symbol-file with -- disables option processing, non-existent filename" | |
94 | gdb_test_multiple "add-symbol-file -- -non-existent-file 0x100" $test { | |
95 | -re "add symbol table from file \"-non-existent-file\" at\r\n\t\.text_addr = 0x100\r\n\\(y or n\\) " { | |
96 | gdb_test "y" "-non-existent-file: No such file or directory\." $test | |
97 | } | |
98 | } | |
99 | # Test that passing the wrong number of arguments to '-s' leads to an | |
100 | # error. | |
101 | gdb_test "add-symbol-file $binfile -s" \ | |
102 | "Missing section name after \"-s\"" \ | |
103 | "add-symbol-file with -s without section name" | |
104 | gdb_test "add-symbol-file $binfile -s .bss" \ | |
105 | "Missing section address after \"-s\"" \ | |
106 | "add-symbol-file with -s without section address" | |
107 | # Test that '-s' accepts section names with '-' | |
108 | set test "add-symbol-file with -s using section name starting with dash" | |
109 | gdb_test_multiple "add-symbol-file -s -section-name 0x200 $binfile 0x100" $test { | |
110 | -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\\) " { | |
111 | gdb_test "n" "Not confirmed\." $test | |
112 | } | |
113 | } | |
114 | # Since we're here, might as well test the 'symbol-file' command and | |
115 | # if its arguments can also be passed at any position. | |
116 | gdb_test "symbol-file -readnow $binfile" \ | |
3453e7e4 | 117 | "Reading symbols from ${binfile}\.\.\.\r\nExpanding full symbols from ${binfile}\.\.\." \ |
40fc416f SDJ |
118 | "symbol-file with -readnow first" |
119 | clean_restart | |
120 | gdb_test "symbol-file $binfile -readnow" \ | |
3453e7e4 | 121 | "Reading symbols from ${binfile}\.\.\.\r\nExpanding full symbols from ${binfile}\.\.\." \ |
40fc416f SDJ |
122 | "symbol-file with -readnow second" |
123 | gdb_test "symbol-file -readnow" \ | |
124 | "no symbol file name was specified" \ | |
125 | "symbol-file without filename" | |
126 | gdb_test "symbol-file -- -non-existent-file" \ | |
127 | "-non-existent-file: No such file or directory\." \ | |
128 | "symbol-file with -- disables option processing" | |
129 | clean_restart | |
130 | gdb_test "symbol-file -readnow -- $binfile" \ | |
3453e7e4 | 131 | "Reading symbols from ${binfile}\.\.\.\r\nExpanding full symbols from ${binfile}\.\.\." \ |
40fc416f SDJ |
132 | "symbol-file with -- and -readnow" |
133 | gdb_test "symbol-file -- $binfile -readnow" \ | |
134 | "Unrecognized argument \"-readnow\"" \ | |
135 | "symbol-file with -- and -readnow, invalid option" | |
136 | ||
137 | clean_restart | |
138 | ||
02ca603a TT |
139 | gdb_test "add-symbol-file ${binfile} 0 -s" \ |
140 | "Missing section name after .-s." \ | |
141 | "add-symbol-file bare -s" | |
142 | gdb_test "add-symbol-file ${binfile} 0 -s .whatever" \ | |
143 | "Missing section address after .-s." \ | |
144 | "add-symbol-file missing address" | |
145 | ||
a7d17088 DJ |
146 | # Load the object file. |
147 | gdb_test "add-symbol-file ${binfile} 0" \ | |
3453e7e4 | 148 | "Reading symbols from .*${testfile}\\.o\\.\\.\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \ |
a7d17088 DJ |
149 | "add-symbol-file ${testfile}.o 0" \ |
150 | "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0\[\r\n\]+\\(y or n\\) " \ | |
151 | "y" | |
152 | ||
c2b75043 LM |
153 | with_test_prefix "print addresses, static vars" { |
154 | # Print the addresses of static variables. | |
155 | set static_foo_addr [get_var_address static_foo] | |
156 | set static_bar_addr [get_var_address static_bar] | |
157 | } | |
a7d17088 DJ |
158 | |
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" | |
164 | } | |
165 | ||
c2b75043 LM |
166 | with_test_prefix "print addresses, global vars" { |
167 | # Print the addresses of global variables. | |
168 | set global_foo_addr [get_var_address global_foo] | |
169 | set global_bar_addr [get_var_address global_bar] | |
170 | } | |
a7d17088 DJ |
171 | |
172 | # Make sure they have different addresses. | |
173 | if { "${global_foo_addr}" == "${global_bar_addr}" } { | |
174 | fail "global variables have different addresses" | |
175 | } else { | |
176 | pass "global variables have different addresses" | |
177 | } | |
178 | ||
c2b75043 LM |
179 | with_test_prefix "print addresses, functions" { |
180 | # Print the addresses of functions. | |
181 | set function_foo_addr [get_var_address function_foo] | |
182 | set function_bar_addr [get_var_address function_bar] | |
183 | } | |
a7d17088 DJ |
184 | |
185 | # Make sure they have different addresses. | |
186 | if { "${function_foo_addr}" == "${function_bar_addr}" } { | |
187 | fail "functions have different addresses" | |
188 | } else { | |
189 | pass "functions have different addresses" | |
190 | } | |
191 | ||
2f816dda DJ |
192 | # Now use a variable as an offset to add-symbol-file, and check that |
193 | # the functions' addresses change. | |
194 | ||
c95d486d | 195 | clean_restart |
2f816dda | 196 | |
27d3a1a2 | 197 | gdb_test_no_output "set \$offset = 0x10000" |
2f816dda DJ |
198 | |
199 | # Load the object file. | |
200 | gdb_test "add-symbol-file ${binfile} \$offset" \ | |
3453e7e4 | 201 | "Reading symbols from .*${testfile}\\.o\\.\\.\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \ |
2f816dda DJ |
202 | "add-symbol-file ${testfile}.o \$offset" \ |
203 | "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x10000\[\r\n\]+\\(y or n\\) " \ | |
204 | "y" | |
205 | ||
206 | # Print the addresses of functions. | |
207 | set new_function_foo_addr [get_var_address function_foo] | |
208 | ||
209 | # Make sure they have different addresses. | |
210 | if { "${function_foo_addr}" == "${new_function_foo_addr}" } { | |
211 | fail "function foo has a different address" | |
212 | } else { | |
213 | pass "function foo has a different address" | |
214 | } | |
215 | ||
d4d429d5 PT |
216 | # Load the object using symbol-file with an offset and check that |
217 | # all addresses are moved by that offset. | |
218 | ||
219 | set offset 0x10000 | |
220 | clean_restart | |
32a5f98a | 221 | set readnow_re "Expanding full symbols from ${binfile}\.\.\." |
d4d429d5 | 222 | gdb_test "symbol-file -o $offset $binfile" \ |
32a5f98a | 223 | "Reading symbols from ${binfile}\.\.\.(\r\n$readnow_re)?" \ |
d4d429d5 PT |
224 | "symbol-file with offset" |
225 | ||
c2b75043 LM |
226 | with_test_prefix "static vars" { |
227 | # Make sure the address of a static variable is moved by offset. | |
228 | set new_static_foo_addr [get_var_address static_foo] | |
229 | gdb_assert {${new_static_foo_addr} == ${static_foo_addr} + $offset} \ | |
230 | "static variable foo is moved by offset" | |
231 | } | |
d4d429d5 | 232 | |
c2b75043 LM |
233 | with_test_prefix "global vars" { |
234 | # Make sure the address of a global variable is moved by offset. | |
235 | set new_global_foo_addr [get_var_address global_foo] | |
236 | gdb_assert {${new_global_foo_addr} == ${global_foo_addr} + $offset} \ | |
237 | "global variable foo is moved by offset" | |
238 | } | |
d4d429d5 | 239 | |
c2b75043 LM |
240 | with_test_prefix "functions" { |
241 | # Make sure the address of a function is moved by offset. | |
242 | set new_function_foo_addr [get_var_address function_foo] | |
243 | gdb_assert {${new_function_foo_addr} == ${function_foo_addr} + $offset} \ | |
244 | "function foo is moved by offset" | |
245 | } | |
d4d429d5 | 246 | |
291f9a96 PT |
247 | # Load the object using add-symbol-file with an offset and check that |
248 | # all addresses are moved by that offset. | |
249 | ||
250 | set offset 0x10000 | |
251 | clean_restart | |
252 | gdb_test "add-symbol-file -o $offset $binfile" \ | |
32a5f98a | 253 | "Reading symbols from ${binfile}\.\.\.(\r\n$readnow_re)?" \ |
291f9a96 PT |
254 | "add-symbol-file with offset" \ |
255 | "add symbol table from file \".*${testfile}\\.o\" with all sections offset by $offset\[\r\n\]+\\(y or n\\) " \ | |
256 | "y" | |
257 | ||
c2b75043 LM |
258 | with_test_prefix "static scope, 2nd" { |
259 | # Make sure the address of a static variable is moved by offset. | |
260 | set new_static_foo_addr [get_var_address static_foo] | |
261 | gdb_assert { ${new_static_foo_addr} == ${static_foo_addr} + $offset } \ | |
262 | "static variable foo is moved by offset" | |
263 | } | |
291f9a96 | 264 | |
c2b75043 LM |
265 | with_test_prefix "global vars, 2nd" { |
266 | # Make sure the address of a global variable is moved by offset. | |
267 | set new_global_foo_addr [get_var_address global_foo] | |
268 | gdb_assert { ${new_global_foo_addr} == ${global_foo_addr} + $offset } \ | |
269 | "global variable foo is moved by offset" | |
270 | } | |
291f9a96 | 271 | |
c2b75043 LM |
272 | with_test_prefix "functions, 2nd" { |
273 | # Make sure the address of a function is moved by offset. | |
274 | set new_function_foo_addr [get_var_address function_foo] | |
275 | gdb_assert { ${new_function_foo_addr} == ${function_foo_addr} + $offset } \ | |
276 | "function foo is moved by offset" | |
277 | } | |
291f9a96 PT |
278 | |
279 | # Re-load the object giving an explicit address for .text | |
280 | ||
281 | set text [ format "0x%x" [expr ${function_foo_addr} + 0x20000] ] | |
282 | clean_restart | |
283 | gdb_test "add-symbol-file $binfile -o $offset $text" \ | |
32a5f98a | 284 | "Reading symbols from ${binfile}\.\.\.(\r\n$readnow_re)?" \ |
291f9a96 PT |
285 | "add-symbol-file with offset, text address given" \ |
286 | "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\\) " \ | |
287 | "y" | |
288 | ||
c2b75043 LM |
289 | with_test_prefix "functions, 3rd" { |
290 | # Make sure function has a different addresses now. | |
291 | set function_foo_addr [get_var_address function_foo] | |
292 | gdb_assert { ${function_foo_addr} != ${new_function_foo_addr} } \ | |
293 | "function foo has a different address" | |
294 | } | |
291f9a96 PT |
295 | |
296 | # Re-load the object giving an explicit address for .data | |
297 | ||
298 | set data [ format "0x%x" [expr ${global_foo_addr} + 0x20000] ] | |
299 | clean_restart | |
300 | gdb_test "add-symbol-file $binfile -o $offset -s .data $data" \ | |
32a5f98a | 301 | "Reading symbols from ${binfile}\.\.\.(\r\n$readnow_re)?" \ |
291f9a96 PT |
302 | "add-symbol-file with offset, data address given" \ |
303 | "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\\) " \ | |
304 | "y" | |
305 | ||
c2b75043 LM |
306 | with_test_prefix "global vars, 3rd" { |
307 | # Make sure variable has a different addresses now. | |
308 | set global_foo_addr [get_var_address global_foo] | |
309 | gdb_assert { ${global_foo_addr} != ${new_global_foo_addr} } \ | |
310 | "global variable foo has a different address" | |
311 | } | |
291f9a96 | 312 | |
c1bd25fd DJ |
313 | # Now try loading the object as an exec-file; we should be able to print |
314 | # the values of variables after we do this. | |
315 | ||
c95d486d | 316 | clean_restart |
582e64c2 | 317 | gdb_file_cmd ${binfile} |
c1bd25fd DJ |
318 | |
319 | # Check the values of the variables. | |
320 | gdb_test "print static_foo" "\\\$$decimal = 1" | |
321 | gdb_test "print static_bar" "\\\$$decimal = 2" | |
322 | gdb_test "print global_foo" "\\\$$decimal = 3" | |
323 | gdb_test "print global_bar" "\\\$$decimal = 4" |