]>
Commit | Line | Data |
---|---|---|
1 | # Copyright 2002-2022 Free Software Foundation, Inc. | |
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 | |
5 | # the Free Software Foundation; either version 3 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
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. | |
12 | # | |
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/>. */ | |
15 | ||
16 | # relocate.exp -- Expect script to test loading symbols from unrelocated | |
17 | # object files. | |
18 | ||
19 | standard_testfile .c | |
20 | append binfile .o | |
21 | ||
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 | |
26 | } | |
27 | ||
28 | gdb_exit | |
29 | gdb_start | |
30 | gdb_reinitialize_dir $srcdir/$subdir | |
31 | ||
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" | |
38 | } | |
39 | ||
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 | } | |
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 | } | |
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" \ | |
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" | |
138 | ||
139 | clean_restart | |
140 | ||
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 | ||
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\\) " \ | |
153 | "y" | |
154 | ||
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 | } | |
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 | ||
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 | } | |
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 | ||
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 | } | |
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 | ||
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 | ||
201 | gdb_test_no_output "set \$offset = 0x10000" | |
202 | ||
203 | # Load the object file. | |
204 | gdb_test "add-symbol-file ${binfile} \$offset" \ | |
205 | "Reading symbols from .*${testfile}\\.o\\.\\.\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \ | |
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 | ||
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 | set readnow_re "Expanding full symbols from ${binfile}\.\.\." | |
226 | gdb_test "symbol-file -o $offset $binfile" \ | |
227 | "Reading symbols from ${binfile}\.\.\.(\r\n$readnow_re)?" \ | |
228 | "symbol-file with offset" | |
229 | ||
230 | with_test_prefix "static vars" { | |
231 | # Make sure the address of a static variable is moved by offset. | |
232 | set new_static_foo_addr [get_var_address static_foo] | |
233 | gdb_assert {${new_static_foo_addr} == ${static_foo_addr} + $offset} \ | |
234 | "static variable foo is moved by offset" | |
235 | } | |
236 | ||
237 | with_test_prefix "global vars" { | |
238 | # Make sure the address of a global variable is moved by offset. | |
239 | set new_global_foo_addr [get_var_address global_foo] | |
240 | gdb_assert {${new_global_foo_addr} == ${global_foo_addr} + $offset} \ | |
241 | "global variable foo is moved by offset" | |
242 | } | |
243 | ||
244 | with_test_prefix "functions" { | |
245 | # Make sure the address of a function is moved by offset. | |
246 | set new_function_foo_addr [get_var_address function_foo] | |
247 | gdb_assert {${new_function_foo_addr} == ${function_foo_addr} + $offset} \ | |
248 | "function foo is moved by offset" | |
249 | } | |
250 | ||
251 | # Load the object using add-symbol-file with an offset and check that | |
252 | # all addresses are moved by that offset. | |
253 | ||
254 | set offset 0x10000 | |
255 | clean_restart | |
256 | gdb_test "add-symbol-file -o $offset $binfile" \ | |
257 | "Reading symbols from ${binfile}\.\.\.(\r\n$readnow_re)?" \ | |
258 | "add-symbol-file with offset" \ | |
259 | "add symbol table from file \".*${testfile}\\.o\" with all sections offset by $offset\[\r\n\]+\\(y or n\\) " \ | |
260 | "y" | |
261 | ||
262 | with_test_prefix "static scope, 2nd" { | |
263 | # Make sure the address of a static variable is moved by offset. | |
264 | set new_static_foo_addr [get_var_address static_foo] | |
265 | gdb_assert { ${new_static_foo_addr} == ${static_foo_addr} + $offset } \ | |
266 | "static variable foo is moved by offset" | |
267 | } | |
268 | ||
269 | with_test_prefix "global vars, 2nd" { | |
270 | # Make sure the address of a global variable is moved by offset. | |
271 | set new_global_foo_addr [get_var_address global_foo] | |
272 | gdb_assert { ${new_global_foo_addr} == ${global_foo_addr} + $offset } \ | |
273 | "global variable foo is moved by offset" | |
274 | } | |
275 | ||
276 | with_test_prefix "functions, 2nd" { | |
277 | # Make sure the address of a function is moved by offset. | |
278 | set new_function_foo_addr [get_var_address function_foo] | |
279 | gdb_assert { ${new_function_foo_addr} == ${function_foo_addr} + $offset } \ | |
280 | "function foo is moved by offset" | |
281 | } | |
282 | ||
283 | # Re-load the object giving an explicit address for .text | |
284 | ||
285 | set text [ format "0x%x" [expr ${function_foo_addr} + 0x20000] ] | |
286 | clean_restart | |
287 | gdb_test "add-symbol-file $binfile -o $offset $text" \ | |
288 | "Reading symbols from ${binfile}\.\.\.(\r\n$readnow_re)?" \ | |
289 | "add-symbol-file with offset, text address given" \ | |
290 | "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\\) " \ | |
291 | "y" | |
292 | ||
293 | with_test_prefix "functions, 3rd" { | |
294 | # Make sure function has a different addresses now. | |
295 | set function_foo_addr [get_var_address function_foo] | |
296 | gdb_assert { ${function_foo_addr} != ${new_function_foo_addr} } \ | |
297 | "function foo has a different address" | |
298 | } | |
299 | ||
300 | # Re-load the object giving an explicit address for .data | |
301 | ||
302 | set data [ format "0x%x" [expr ${global_foo_addr} + 0x20000] ] | |
303 | clean_restart | |
304 | gdb_test "add-symbol-file $binfile -o $offset -s .data $data" \ | |
305 | "Reading symbols from ${binfile}\.\.\.(\r\n$readnow_re)?" \ | |
306 | "add-symbol-file with offset, data address given" \ | |
307 | "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\\) " \ | |
308 | "y" | |
309 | ||
310 | with_test_prefix "global vars, 3rd" { | |
311 | # Make sure variable has a different addresses now. | |
312 | set global_foo_addr [get_var_address global_foo] | |
313 | gdb_assert { ${global_foo_addr} != ${new_global_foo_addr} } \ | |
314 | "global variable foo has a different address" | |
315 | } | |
316 | ||
317 | # Now try loading the object as an exec-file; we should be able to print | |
318 | # the values of variables after we do this. | |
319 | ||
320 | gdb_exit | |
321 | gdb_start | |
322 | gdb_reinitialize_dir $srcdir/$subdir | |
323 | gdb_file_cmd ${binfile} | |
324 | ||
325 | # Check the values of the variables. | |
326 | gdb_test "print static_foo" "\\\$$decimal = 1" | |
327 | gdb_test "print static_bar" "\\\$$decimal = 2" | |
328 | gdb_test "print global_foo" "\\\$$decimal = 3" | |
329 | gdb_test "print global_bar" "\\\$$decimal = 4" |