Commit | Line | Data |
---|---|---|
82704155 | 1 | # Copyright (C) 1993-2019 Free Software Foundation, Inc. |
252b5132 RH |
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 | |
32866df7 | 5 | # the Free Software Foundation; either version 3 of the License, or |
252b5132 | 6 | # (at your option) any later version. |
65951855 | 7 | # |
252b5132 RH |
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. | |
65951855 | 12 | # |
252b5132 RH |
13 | # You should have received a copy of the GNU General Public License |
14 | # along with this program; if not, write to the Free Software | |
b43b5d5f | 15 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. |
252b5132 RH |
16 | |
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # bug-dejagnu@prep.ai.mit.edu | |
19 | ||
20 | # This file was written by Rob Savoye <rob@cygnus.com> | |
21 | # and rewritten by Ian Lance Taylor <ian@cygnus.com> | |
22 | ||
23 | if ![is_remote host] { | |
24 | if {[which $OBJDUMP] == 0} then { | |
25 | perror "$OBJDUMP does not exist" | |
26 | return | |
27 | } | |
28 | } | |
29 | ||
30 | send_user "Version [binutil_version $OBJDUMP]" | |
31 | ||
32 | # Simple test of objdump -i | |
33 | ||
34 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -i"] | |
35 | ||
41f5a528 | 36 | set cpus_expected [list] |
75800d2c | 37 | lappend cpus_expected aarch64 alpha am33-2 arc ARC700 ARCv2 arm cris |
a8eb42a8 | 38 | lappend cpus_expected d10v d30v fr30 fr500 fr550 h8 hppa i386 iamcu ip2022 |
c2bf1eec | 39 | lappend cpus_expected m16c m32c m32r m68hc11 m68hc12 m68k MCore mep c5 h1 MicroBlaze |
73589c9d | 40 | lappend cpus_expected mips mn10200 mn10300 ms1 msp MSP430 nds32 n1h_v3 ns32k |
e23eba97 | 41 | lappend cpus_expected or1k or1knd pj powerpc pyramid riscv romp rs6000 s390 sh sparc |
fceadf09 | 42 | lappend cpus_expected tic54x tic80 tilegx tms320c30 tms320c4x tms320c54x |
04cb01fd | 43 | lappend cpus_expected v850 vax x86-64 xscale xtensa z8k z8001 z8002 |
252b5132 RH |
44 | |
45 | # Make sure the target CPU shows up in the list. | |
41f5a528 FCE |
46 | lappend cpus_expected ${target_cpu} |
47 | ||
48 | # Create regexp | |
49 | set cpus_regex "([join $cpus_expected | ])" | |
50 | ||
51 | verbose -log "CPU regex: $cpus_regex" | |
252b5132 | 52 | |
41f5a528 | 53 | set want "BFD header file version.*srec\[^\n\]*\n\[^\n\]*header \[^\n\]*endian\[^\n\]*, data \[^\n\]*endian.*$cpus_regex" |
252b5132 RH |
54 | |
55 | if [regexp $want $got] then { | |
56 | pass "objdump -i" | |
57 | } else { | |
58 | fail "objdump -i" | |
59 | } | |
60 | ||
61 | # The remaining tests require a test file. | |
62 | ||
63 | ||
64 | if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then { | |
baae986a | 65 | fail "objdump (assembling bintest.s)" |
252b5132 RH |
66 | return |
67 | } | |
8e2f54bc | 68 | if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest2.o]} then { |
f795c494 | 69 | fail "objdump (assembling)" |
8e2f54bc L |
70 | return |
71 | } | |
252b5132 RH |
72 | if [is_remote host] { |
73 | set testfile [remote_download host tmpdir/bintest.o] | |
8e2f54bc | 74 | set testfile2 [remote_download host tmpdir/bintest2.o] |
252b5132 RH |
75 | } else { |
76 | set testfile tmpdir/bintest.o | |
8e2f54bc L |
77 | set testfile2 tmpdir/bintest2.o |
78 | } | |
79 | ||
a502b0bb L |
80 | # $testarchive exists only if it is supported. |
81 | set testarchive tmpdir/bintest.a | |
82 | remote_file host file delete $testarchive | |
8e2f54bc | 83 | if { ![istarget "alpha-*-*"] || [is_elf_format] } then { |
8e2f54bc L |
84 | set got [binutils_run $AR "rc tmpdir/bintest.a $testfile2"] |
85 | if ![string match "" $got] then { | |
86 | fail "bintest.a" | |
87 | remote_file host delete tmpdir/bintest.a | |
a502b0bb L |
88 | } elseif [is_remote host] { |
89 | set testarchive [remote_download host tmpdir/bintest.a] | |
8e2f54bc L |
90 | } |
91 | remote_file host delete tmpdir/bintest2.o | |
252b5132 RH |
92 | } |
93 | ||
94 | # Test objdump -f | |
95 | ||
8e2f54bc L |
96 | proc test_objdump_f { testfile dumpfile } { |
97 | global OBJDUMP | |
98 | global OBJDUMPFLAGS | |
99 | global cpus_regex | |
252b5132 | 100 | |
8e2f54bc | 101 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f $testfile"] |
252b5132 | 102 | |
8e2f54bc L |
103 | set want "$dumpfile:\[ \]*file format.*architecture:\[ \]*${cpus_regex}.*HAS_RELOC.*HAS_SYMS" |
104 | ||
105 | if ![regexp $want $got] then { | |
106 | fail "objdump -f ($testfile, $dumpfile)" | |
107 | } else { | |
108 | pass "objdump -f ($testfile, $dumpfile)" | |
109 | } | |
110 | } | |
111 | ||
112 | test_objdump_f $testfile $testfile | |
113 | if { [ remote_file host exists $testarchive ] } then { | |
114 | test_objdump_f $testarchive bintest2.o | |
252b5132 RH |
115 | } |
116 | ||
117 | # Test objdump -h | |
118 | ||
8e2f54bc L |
119 | proc test_objdump_h { testfile dumpfile } { |
120 | global OBJDUMP | |
121 | global OBJDUMPFLAGS | |
252b5132 | 122 | |
8e2f54bc | 123 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h $testfile"] |
252b5132 | 124 | |
8e2f54bc L |
125 | set want "$dumpfile:\[ \]*file format.*Sections.*\[0-9\]+\[ \]+\[^ \]*(text|TEXT|P|\\\$CODE\\\$)\[^ \]*\[ \]*(\[0-9a-fA-F\]+).*\[0-9\]+\[ \]+\[^ \]*(\\.data|DATA|D_1)\[^ \]*\[ \]*(\[0-9a-fA-F\]+)" |
126 | ||
127 | if ![regexp $want $got all text_name text_size data_name data_size] then { | |
128 | fail "objdump -h ($testfile, $dumpfile)" | |
252b5132 | 129 | } else { |
8e2f54bc L |
130 | verbose "text name is $text_name size is $text_size" |
131 | verbose "data name is $data_name size is $data_size" | |
132 | set ets 8 | |
133 | set eds 4 | |
134 | # The [ti]c4x target has the property sizeof(char)=sizeof(long)=1 | |
135 | if [istarget *c4x*-*-*] then { | |
136 | set ets 2 | |
137 | set eds 1 | |
138 | } | |
139 | # c54x section sizes are in bytes, not octets; adjust accordingly | |
140 | if [istarget *c54x*-*-*] then { | |
141 | set ets 4 | |
142 | set eds 2 | |
143 | } | |
144 | if {[expr "0x$text_size"] < $ets || [expr "0x$data_size"] < $eds} then { | |
145 | send_log "sizes too small\n" | |
146 | fail "objdump -h ($testfile, $dumpfile)" | |
147 | } else { | |
148 | pass "objdump -h ($testfile, $dumpfile)" | |
149 | } | |
252b5132 RH |
150 | } |
151 | } | |
152 | ||
8e2f54bc L |
153 | test_objdump_h $testfile $testfile |
154 | if { [ remote_file host exists $testarchive ] } then { | |
155 | test_objdump_h $testarchive bintest2.o | |
156 | } | |
157 | ||
252b5132 RH |
158 | # Test objdump -t |
159 | ||
8e2f54bc L |
160 | proc test_objdump_t { testfile} { |
161 | global OBJDUMP | |
162 | global OBJDUMPFLAGS | |
163 | ||
164 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -t $testfile"] | |
252b5132 | 165 | |
8e2f54bc L |
166 | if [info exists vars] then { unset vars } |
167 | while {[regexp "(\[a-z\]*_symbol)(.*)" $got all symbol rest]} { | |
168 | set vars($symbol) 1 | |
169 | set got $rest | |
170 | } | |
171 | ||
172 | if {![info exists vars(text_symbol)] \ | |
173 | || ![info exists vars(data_symbol)] \ | |
174 | || ![info exists vars(common_symbol)] \ | |
175 | || ![info exists vars(external_symbol)]} then { | |
176 | fail "objdump -t ($testfile)" | |
177 | } else { | |
178 | pass "objdump -t ($testfile)" | |
179 | } | |
252b5132 RH |
180 | } |
181 | ||
8e2f54bc L |
182 | test_objdump_t $testfile |
183 | if { [ remote_file host exists $testarchive ] } then { | |
184 | test_objdump_t $testarchive | |
252b5132 RH |
185 | } |
186 | ||
187 | # Test objdump -r | |
188 | ||
8e2f54bc L |
189 | proc test_objdump_r { testfile dumpfile } { |
190 | global OBJDUMP | |
191 | global OBJDUMPFLAGS | |
252b5132 | 192 | |
8e2f54bc | 193 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -r $testfile"] |
252b5132 | 194 | |
8e2f54bc L |
195 | set want "$dumpfile:\[ \]*file format.*RELOCATION RECORDS FOR \\\[\[^\]\]*(text|TEXT|P|\\\$CODE\\\$)\[^\]\]*\\\].*external_symbol" |
196 | ||
197 | if [regexp $want $got] then { | |
198 | pass "objdump -r ($testfile, $dumpfile)" | |
199 | } else { | |
200 | fail "objdump -r ($testfile, $dumpfile)" | |
201 | } | |
202 | } | |
203 | ||
204 | test_objdump_r $testfile $testfile | |
205 | if { [ remote_file host exists $testarchive ] } then { | |
206 | test_objdump_r $testarchive bintest2.o | |
252b5132 RH |
207 | } |
208 | ||
d3def5d7 MY |
209 | # Test objdump -d |
210 | proc test_objdump_d { testfile dumpfile } { | |
211 | global OBJDUMP | |
212 | global OBJDUMPFLAGS | |
213 | ||
214 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -d $testfile"] | |
215 | ||
216 | set want "$dumpfile:.*Disassembly of section" | |
217 | if ![regexp $want $got] then { | |
218 | fail "objdump -d $testfile: No disassembly title" | |
219 | return | |
220 | } | |
221 | ||
222 | set want "$dumpfile:.*00+0 <text_symbol>" | |
223 | if ![regexp $want $got] then { | |
224 | fail "objdump -d $testfile: Missing symbol name and address" | |
225 | return | |
226 | } | |
227 | ||
228 | set want "$dumpfile:.*00+. <text_symbol2>" | |
229 | if ![regexp $want $got] then { | |
230 | fail "objdump -d $testfile: Missing second symbol" | |
231 | return | |
232 | } | |
233 | ||
234 | set want "$dumpfile:.*00+. <text_symbol3>" | |
235 | if ![regexp $want $got] then { | |
236 | fail "objdump -d $testfile: Missing third symbol" | |
237 | return | |
238 | } | |
239 | ||
240 | pass "objdump -d $testfile" | |
241 | } | |
242 | ||
243 | test_objdump_d $testfile $testfile | |
244 | if { [ remote_file host exists $testarchive ] } then { | |
245 | test_objdump_d $testarchive bintest2.o | |
246 | } | |
247 | ||
248 | # Test objdump --disassemble=<symbol> | |
249 | proc test_objdump_d_sym { testfile dumpfile } { | |
250 | global OBJDUMP | |
251 | global OBJDUMPFLAGS | |
252 | ||
253 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS --disassemble=text_symbol2 $testfile"] | |
254 | ||
255 | set want "$dumpfile:.*Disassembly of section" | |
256 | if ![regexp $want $got] then { | |
257 | fail "objdump --disassemble=text_symbol2 $testfile: No disassembly title" | |
258 | return | |
259 | } | |
260 | ||
261 | set want "$dumpfile:.*00+0 <text_symbol>" | |
262 | if [regexp $want $got] then { | |
263 | fail "objdump --disassemble=text_symbol2 $testfile: First symbol displayed, when it should be absent" | |
264 | return | |
265 | } | |
266 | ||
267 | set want "$dumpfile:.*00+. <text_symbol2>" | |
268 | if ![regexp $want $got] then { | |
269 | fail "objdump --disassemble=text_symbol2 $testfile: Missing second symbol" | |
270 | return | |
271 | } | |
272 | ||
273 | set want "$dumpfile:.*00+. <text_symbol3>" | |
274 | if [regexp $want $got] then { | |
275 | fail "objdump --disassemble=text_symbol2 $testfile: Third symbol displayed when it should be absent" | |
276 | return | |
277 | } | |
278 | ||
279 | pass "objdump --disassemble=text_symbol2 $testfile" | |
280 | } | |
281 | ||
282 | test_objdump_d_sym $testfile $testfile | |
baae986a NC |
283 | |
284 | proc test_objdump_d_func_sym { testfile dumpfile } { | |
285 | global OBJDUMP | |
286 | global OBJDUMPFLAGS | |
287 | ||
288 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS --disassemble=func --disassemble-zeroes $testfile"] | |
289 | ||
290 | set want "$dumpfile:.*Disassembly of section" | |
291 | if ![regexp $want $got] then { | |
292 | fail "objdump --disassemble=func $testfile: No disassembly title" | |
293 | return | |
294 | } | |
295 | ||
296 | set want "$dumpfile:.*00+0 <start_of_text>" | |
297 | if [regexp $want $got] then { | |
298 | fail "objdump --disassemble=func $testfile: First symbol displayed, when it should be absent" | |
299 | return | |
300 | } | |
301 | ||
302 | set want "$dumpfile:.*00+. <func>" | |
303 | if ![regexp $want $got] then { | |
304 | fail "objdump --disassemble=func $testfile: Disassembly does not start at function symbol" | |
305 | return | |
306 | } | |
307 | ||
308 | set want "$dumpfile:.*00+. <global_non_func_sym>" | |
309 | if ![regexp $want $got] then { | |
310 | fail "objdump --disassemble=func $testfile: Non function symbol not displayed" | |
311 | return | |
312 | } | |
313 | ||
314 | set want "$dumpfile:.*00+. <next_func>" | |
315 | if [regexp $want $got] then { | |
316 | fail "objdump --disassemble=func $testfile: Disassembly did not stop at the next function" | |
317 | return | |
318 | } | |
319 | ||
320 | pass "objdump --disassemble=func $testfile" | |
321 | } | |
322 | ||
323 | proc test_objdump_d_non_func_sym { testfile dumpfile } { | |
324 | global OBJDUMP | |
325 | global OBJDUMPFLAGS | |
326 | ||
327 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS --disassemble=global_non_func_sym $testfile"] | |
328 | ||
329 | set want "$dumpfile:.*Disassembly of section" | |
330 | if ![regexp $want $got] then { | |
331 | fail "objdump --disassemble=non_func $testfile: No disassembly title" | |
332 | return | |
333 | } | |
334 | ||
335 | set want "$dumpfile:.*00+0 <start_of_text>" | |
336 | if [regexp $want $got] then { | |
337 | fail "objdump --disassemble=non_func $testfile: First symbol displayed, when it should be absent" | |
338 | return | |
339 | } | |
340 | ||
341 | set want "$dumpfile:.*00+. <global_non_func_sym>" | |
342 | if ![regexp $want $got] then { | |
343 | fail "objdump --disassemble=non_func $testfile: Non function symbol not displayed" | |
344 | return | |
345 | } | |
346 | ||
347 | set want "$dumpfile:.*00+. <local_non_func_sym>" | |
348 | if [regexp $want $got] then { | |
349 | fail "objdump --disassemble=non_func $testfile: Disassembly did not stop at the next symbol" | |
350 | return | |
351 | } | |
352 | ||
353 | pass "objdump --disassemble=non_func $testfile" | |
354 | } | |
355 | ||
356 | # Extra test for ELF format - check that --disassemble=func disassembles | |
357 | # all of func, and does not stop at the next symbol. | |
358 | if { [is_elf_format] } then { | |
359 | ||
360 | if {![binutils_assemble $srcdir/$subdir/disasm.s tmpdir/disasm.o]} then { | |
361 | fail "objdump --disassemble=func (assembling disasm.s)" | |
362 | } else { | |
363 | if [is_remote host] { | |
364 | set elftestfile [remote_download host tmpdir/disasm.o] | |
365 | } else { | |
366 | set elftestfile tmpdir/disasm.o | |
367 | } | |
368 | ||
369 | test_objdump_d_func_sym $elftestfile $elftestfile | |
370 | test_objdump_d_non_func_sym $elftestfile $elftestfile | |
371 | } | |
d3def5d7 MY |
372 | } |
373 | ||
374 | ||
252b5132 RH |
375 | # Test objdump -s |
376 | ||
8e2f54bc L |
377 | proc test_objdump_s { testfile dumpfile } { |
378 | global OBJDUMP | |
379 | global OBJDUMPFLAGS | |
252b5132 | 380 | |
8e2f54bc | 381 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -s $testfile"] |
252b5132 | 382 | |
8e2f54bc L |
383 | set want "$dumpfile:\[ \]*file format.*Contents.*(text|TEXT|P|\\\$CODE\\\$)\[^0-9\]*\[ \]*\[0-9a-fA-F\]*\[ \]*(00000001|01000000|00000100).*Contents.*(data|DATA|D_1)\[^0-9\]*\[ \]*\[0-9a-fA-F\]*\[ \]*(00000002|02000000|00000200)" |
384 | ||
385 | if [regexp $want $got] then { | |
386 | pass "objdump -s ($testfile, $dumpfile)" | |
387 | } else { | |
388 | fail "objdump -s ($testfile, $dumpfile)" | |
389 | } | |
390 | } | |
391 | ||
392 | test_objdump_s $testfile $testfile | |
393 | if { [ remote_file host exists $testarchive ] } then { | |
394 | test_objdump_s $testarchive bintest2.o | |
252b5132 RH |
395 | } |
396 | ||
1b315056 CS |
397 | # Test objdump -s on a file that contains a compressed .debug section |
398 | ||
dae148f3 | 399 | if { ![is_elf_format] } then { |
22bce68e AM |
400 | unsupported "objdump compressed debug" |
401 | } elseif { ![binutils_assemble $srcdir/$subdir/dw2-compressed.S tmpdir/dw2-compressed.o] } then { | |
402 | fail "objdump compressed debug" | |
1b315056 | 403 | } else { |
22bce68e AM |
404 | if [is_remote host] { |
405 | set compressed_testfile [remote_download host tmpdir/dw2-compressed.o] | |
406 | } else { | |
407 | set compressed_testfile tmpdir/dw2-compressed.o | |
408 | } | |
1b315056 | 409 | |
22bce68e | 410 | set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS -s -j .zdebug_abbrev $compressed_testfile" "" "/dev/null" "objdump.out"] |
1b315056 | 411 | |
22bce68e AM |
412 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
413 | fail "objdump -s -j .zdebug_abbrev (reason: unexpected output)" | |
414 | send_log $got | |
415 | send_log "\n" | |
416 | } | |
1b315056 | 417 | |
22bce68e AM |
418 | if { [regexp_diff objdump.out $srcdir/$subdir/objdump.s] } then { |
419 | fail "objdump -s -j .zdebug_abbrev" | |
420 | } else { | |
421 | pass "objdump -s -j .zdebug_abbrev" | |
422 | } | |
1b315056 | 423 | |
22bce68e | 424 | # Test objdump -W on a file that contains some compressed .debug sections |
1b315056 | 425 | |
22bce68e | 426 | set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS -W $compressed_testfile" "" "/dev/null" "objdump.out"] |
1b315056 | 427 | |
22bce68e AM |
428 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
429 | fail "objdump -W (reason: unexpected output)" | |
430 | send_log $got | |
431 | send_log "\n" | |
432 | } | |
1b315056 | 433 | |
22bce68e AM |
434 | if { [regexp_diff objdump.out $srcdir/$subdir/objdump.W] } then { |
435 | fail "objdump -W" | |
436 | } else { | |
437 | pass "objdump -W" | |
438 | } | |
1b315056 CS |
439 | } |
440 | ||
4eee63bc | 441 | # Test objdump -WL on a file that contains line information for multiple files and search directories. |
73589c9d | 442 | # Not supported on mcore and moxie targets because they do not (yet) support the generation |
e3cb57c3 NC |
443 | # of DWARF2 line debug information. |
444 | ||
445 | if { ![is_elf_format] | |
71ac97b2 | 446 | || [istarget "hppa64*-*-hpux*"] |
e3cb57c3 NC |
447 | || [istarget "ia64*-*-*"] |
448 | || [istarget "mcore-*-*"] | |
449 | || [istarget "moxie-*-*"] | |
e3cb57c3 | 450 | } then { |
d4cb0ea0 | 451 | unsupported "objump decode line" |
4eee63bc | 452 | } else { |
73589c9d CS |
453 | if { [istarget "or1k*-*-*"] } then { |
454 | set decodedline_testsrc $srcdir/$subdir/dw2-decodedline-1.S | |
455 | } else { | |
456 | set decodedline_testsrc $srcdir/$subdir/dw2-decodedline.S | |
457 | } | |
458 | if { ![binutils_assemble $decodedline_testsrc tmpdir/dw2-decodedline.o] } then { | |
d4cb0ea0 NC |
459 | fail "objdump decoded line" |
460 | } | |
461 | ||
462 | if [is_remote host] { | |
463 | set decodedline_testfile [remote_download host tmpdir/dw2-decodedline.o] | |
464 | } else { | |
465 | set decodedline_testfile tmpdir/dw2-decodedline.o | |
466 | } | |
4eee63bc | 467 | |
d4cb0ea0 | 468 | set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS -WL $decodedline_testfile" "" "/dev/null" "objdump.out"] |
4eee63bc | 469 | |
d4cb0ea0 NC |
470 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
471 | fail "objdump -WL (reason: unexpected output)" | |
472 | send_log $got | |
473 | send_log "\n" | |
474 | } | |
4eee63bc | 475 | |
d4cb0ea0 NC |
476 | if { [regexp_diff objdump.out $srcdir/$subdir/objdump.WL] } then { |
477 | fail "objdump -WL" | |
478 | } else { | |
479 | pass "objdump -WL" | |
480 | } | |
4eee63bc | 481 | } |
1b315056 | 482 | |
42bcef4a AB |
483 | # Test objdump -W on a file containing debug_ranges information. |
484 | ||
485 | if { ![is_elf_format] } then { | |
486 | unsupported "objdump debug_ranges test" | |
487 | } elseif { ![binutils_assemble $srcdir/$subdir/dw2-ranges.S tmpdir/dw2-ranges.o] } then { | |
488 | fail "objdump debug_ranges test" | |
489 | } else { | |
490 | if [is_remote host] { | |
491 | set ranges_testfile [remote_download host tmpdir/dw2-ranges.o] | |
492 | } else { | |
493 | set ranges_testfile tmpdir/dw2-ranges.o | |
494 | } | |
495 | ||
496 | set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS --dwarf=Ranges $ranges_testfile" "" "/dev/null" "objdump.out"] | |
497 | ||
498 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { | |
499 | fail "objdump -W for debug_ranges (reason: unexpected output)" | |
500 | send_log $got | |
501 | send_log "\n" | |
502 | } | |
503 | ||
f617a0f6 | 504 | setup_xfail "msp430-*-*" "nds32*-*-*" |
42bcef4a AB |
505 | if { [regexp_diff objdump.out $srcdir/$subdir/dw2-ranges.W] } then { |
506 | fail "objdump -W for debug_ranges" | |
507 | } else { | |
508 | pass "objdump -W for debug_ranges" | |
509 | } | |
510 | } | |
511 | ||
2425a30e NC |
512 | proc test_build_id_debuglink {} { |
513 | global srcdir | |
514 | global subdir | |
515 | global env | |
2425a30e NC |
516 | global STRIP |
517 | global OBJCOPY | |
518 | global OBJDUMP | |
519 | global CFLAGS_FOR_TARGET | |
520 | ||
521 | set test "build-id-debuglink" | |
2425a30e NC |
522 | |
523 | # Use a fixed build-id. | |
bb3b5316 AM |
524 | if { [info exists CFLAGS_FOR_TARGET] } { |
525 | set save_CFLAGS_FOR_TARGET $CFLAGS_FOR_TARGET | |
526 | } | |
2425a30e NC |
527 | set CFLAGS_FOR_TARGET "-g -Wl,--build-id=0x12345678abcdef01" |
528 | ||
2ecde2b6 | 529 | if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog executable debug] != "" } { |
bb3b5316 | 530 | unsupported "$test (build)" |
2425a30e NC |
531 | return |
532 | } | |
533 | ||
bb3b5316 AM |
534 | if { [info exists save_CFLAGS_FOR_TARGET] } { |
535 | set CFLAGS_FOR_TARGET $save_CFLAGS_FOR_TARGET | |
536 | } else { | |
537 | unset CFLAGS_FOR_TARGET | |
538 | } | |
2425a30e NC |
539 | |
540 | if { [binutils_run $STRIP "--strip-debug --remove-section=.comment tmpdir/testprog -o tmpdir/testprog.strip"] != "" } { | |
541 | fail "$test (strip debug info)" | |
542 | return | |
543 | } | |
544 | ||
545 | if { [binutils_run $OBJCOPY "--only-keep-debug tmpdir/testprog tmpdir/testprog.debug"] != "" } { | |
546 | fail "$test (create separate debug info file)" | |
547 | return | |
548 | } | |
549 | ||
550 | set got [remote_exec host "mkdir -p .build-id/12" ] | |
551 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { | |
552 | fail "$test (make debug directory)" | |
553 | return | |
554 | } | |
555 | ||
556 | set got [remote_exec host "cp tmpdir/testprog.debug .build-id/12/345678abcdef01.debug"] | |
557 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { | |
558 | fail "$test (copy debug info into debug directory)" | |
559 | return | |
560 | } | |
561 | ||
562 | set got [remote_exec host "$OBJDUMP -Sl tmpdir/testprog.strip" "" "/dev/null" "tmpdir/testprog.strip.dump"] | |
563 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { | |
564 | fail "$test (post strip dump)" | |
565 | return | |
566 | } | |
567 | ||
568 | set src2 tmpdir/testprog.strip.dump | |
569 | verbose " grep -e testprog.c ${src2}" | |
570 | set status [remote_exec build grep "-e testprog.c ${src2}"] | |
571 | set exec_output [lindex $status 1] | |
572 | set exec_output [prune_warnings $exec_output] | |
573 | if [string match "" $exec_output] then { | |
574 | send_log "$exec_output\n" | |
575 | verbose "$exec_output" 1 | |
576 | fail "$test (grepping for source file name in disassembly output)" | |
577 | } else { | |
578 | pass "$test" | |
579 | # Cleanup... | |
580 | set got [remote_exec host "rm .build-id/12/345678abcdef01.debug"] | |
581 | set got [remote_exec host "rmdir -p .build-id/12" ] | |
582 | set got [remote_exec host "rm tmpdir/testprog.strip.dump"] | |
583 | set got [remote_exec host "rm tmpdir/testprog.debug"] | |
584 | set got [remote_exec host "rm tmpdir/testprog.strip"] | |
585 | } | |
586 | } | |
587 | ||
0034eed0 | 588 | if {[is_elf_format]} then { |
2425a30e NC |
589 | test_build_id_debuglink |
590 | } | |
42bcef4a | 591 | |
dda8d76d NC |
592 | # Test objdump -Wk on a file containing debug links. |
593 | ||
594 | if { [is_elf_format] } then { | |
595 | set testsrc $srcdir/$subdir/debuglink.s | |
596 | ||
597 | if { ![binutils_assemble $testsrc tmpdir/debuglink.o] } then { | |
598 | fail "objdump -Wk (reason: could not assemble source)" | |
599 | } | |
600 | ||
601 | if [is_remote host] { | |
602 | set testfile [remote_download host tmpdir/debuglink.o] | |
603 | } else { | |
604 | set testfile tmpdir/debuglink.o | |
605 | } | |
606 | ||
607 | set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS -Wk $testfile" "" "/dev/null" "objdump.out"] | |
608 | ||
609 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { | |
610 | fail "objdump -Wk (reason: unexpected output)" | |
611 | send_log $got | |
612 | send_log "\n" | |
613 | } | |
614 | ||
615 | if { [regexp_diff objdump.out $srcdir/$subdir/objdump.Wk] } then { | |
616 | fail "objdump -Wk" | |
617 | } else { | |
618 | pass "objdump -Wk" | |
619 | } | |
620 | } | |
621 | ||
622 | ||
623 | # Very similar to proc test_build_id_debuglink except this time we | |
624 | # display some of the contents of the separate debug info file. | |
625 | ||
39f0547e | 626 | proc test_follow_debuglink { options dumpfile } { |
dda8d76d NC |
627 | global srcdir |
628 | global subdir | |
629 | global OBJDUMP | |
630 | ||
39f0547e | 631 | set test "follow-debuglink ($options)" |
dda8d76d NC |
632 | |
633 | if {![binutils_assemble $srcdir/$subdir/debuglink.s tmpdir/debuglink.o]} then { | |
634 | fail "$test (reason: assemble first source file)" | |
635 | return | |
636 | } | |
637 | ||
638 | if {![binutils_assemble $srcdir/$subdir/linkdebug.s tmpdir/linkdebug.debug]} then { | |
639 | fail "$test (reason: assemble second source file)" | |
640 | return | |
641 | } | |
642 | ||
643 | if ![is_remote host] { | |
644 | set tempfile tmpdir/debuglink.o | |
645 | } else { | |
646 | set tempfile [remote_download host tmpdir/linkdebug.debug] | |
647 | set tempfile [remote_download host tmpdir/debuglink.o] | |
648 | } | |
649 | ||
39f0547e | 650 | set got [remote_exec host "$OBJDUMP $options $tempfile" "" "/dev/null" "tmpdir/objdump.out"] |
dda8d76d NC |
651 | if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
652 | fail "$test (reason: unexpected error output from objdump)" | |
653 | return | |
654 | } | |
655 | ||
39f0547e | 656 | if { [regexp_diff tmpdir/objdump.out $srcdir/$subdir/$dumpfile] } then { |
dda8d76d NC |
657 | fail $test |
658 | verbose "output is \n[file_contents objdump.out]" 2 | |
659 | return | |
660 | } | |
661 | ||
662 | pass $test | |
663 | ||
664 | # Tidy up | |
665 | set got [remote_exec host "rm tmpdir/objdump.out"] | |
666 | set got [remote_exec host "rm $tempfile"] | |
667 | set got [remote_exec host "rm tmpdir/linkdebug.debug"] | |
668 | } | |
669 | ||
0034eed0 | 670 | if {[is_elf_format]} then { |
39f0547e NC |
671 | test_follow_debuglink "--dwarf=follow-links --dwarf=info --dwarf=str" objdump.WK2 |
672 | test_follow_debuglink "--dwarf=follow-links --headers --wide" objdump.WK3 | |
dda8d76d NC |
673 | } |
674 | ||
2379f9c4 FS |
675 | # Test objdump output with start and stop address limits for the specified |
676 | # dump option | |
677 | ||
678 | proc test_objdump_limited { testfile dopt want start stop } { | |
679 | global OBJDUMP | |
680 | global OBJDUMPFLAGS | |
681 | ||
682 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS $dopt --start-address 0x$start --stop-address 0x$stop $testfile"] | |
683 | ||
684 | if [regexp $want $got] then { | |
685 | pass "objdump $dopt --start-address 0x$start --stop-address 0x$stop ($testfile)" | |
686 | } else { | |
687 | fail "objdump $dopt --start-address 0x$start --stop-address 0x$stop ($testfile)" | |
688 | } | |
689 | } | |
690 | ||
691 | # Test objdump -d --start-address M --stop-address N | |
692 | ||
391bf891 AM |
693 | proc test_objdump_disas_limited { testfile text start stop } { |
694 | set want "$testfile:\[ \]*file format.*Disassembly of section $text:\n.*\[ \]*$start:.*" | |
2379f9c4 FS |
695 | test_objdump_limited $testfile -d $want $start $stop |
696 | } | |
697 | ||
698 | # Test objdump -s --start-address M --stop-address N | |
699 | ||
391bf891 AM |
700 | proc test_objdump_content_limited { testfile text start stop } { |
701 | set want "$testfile:\[ \]*file format.*Contents of section $text:\n\[ \]*$start .*" | |
2379f9c4 FS |
702 | test_objdump_limited $testfile -s $want $start $stop |
703 | } | |
704 | ||
705 | # Test objdump with --start-address and --stop-address options for higher | |
706 | # address ranges which may be sign-extended on targets that treat addresses | |
707 | # as signed. We only check that objdump produces some dump output at the | |
708 | # specified start address as a proxy for correct enforcement of the | |
709 | # start/stop limits. | |
710 | ||
711 | if {[is_elf_format]} then { | |
391bf891 AM |
712 | set sect_names [get_standard_section_names] |
713 | if { $sect_names != "" } { | |
714 | set text [lindex $sect_names 0] | |
715 | } else { | |
716 | set text ".text" | |
717 | } | |
2379f9c4 | 718 | # generate a copy of the test object with .text repositioned |
391bf891 AM |
719 | if { [binutils_run $OBJCOPY "--change-section-address $text=0x80000000 tmpdir/bintest.o tmpdir/bintest_signed.o"] != "" } { |
720 | fail "Failed to reposition $text to 0x80000000 (tmpdir/bintest.o -> tmpdir/bintest_signed.o)" | |
2379f9c4 FS |
721 | return |
722 | } | |
723 | ||
724 | if [is_remote host] { | |
725 | set testfile3 [remote_download host tmpdir/bintest_signed.o] | |
726 | } else { | |
727 | set testfile3 tmpdir/bintest_signed.o | |
728 | } | |
729 | ||
391bf891 AM |
730 | test_objdump_content_limited $testfile3 $text "80000004" "80000008" |
731 | test_objdump_disas_limited $testfile3 $text "80000004" "80000008" | |
2379f9c4 FS |
732 | remote_file host delete $testfile3 |
733 | } | |
734 | ||
1dd1bc4d OM |
735 | # Test objdump on .NET assemblies (PE files) |
736 | ||
737 | proc test_objdump_dotnet_assemblies {} { | |
738 | global OBJDUMP | |
739 | global base_dir | |
740 | ||
741 | set test "dotnet-assemblies" | |
742 | ||
7cd00957 OM |
743 | set got [binutils_run "$base_dir/testsuite/gentestdlls" "tmpdir pei-i386 pei-x86-64"] |
744 | set want "wrote linux-pei-x86-64.dll" | |
745 | # The test program is hardcoded to generate valid dlls on any target | |
1dd1bc4d | 746 | if ![regexp $want $got] then { |
7cd00957 | 747 | fail "$test" |
1dd1bc4d OM |
748 | } |
749 | ||
7cd00957 OM |
750 | # First test an ordinary x86 PE format DLL. |
751 | set test "dotnet-assemblies (ordinary x86 DLL)" | |
1dd1bc4d | 752 | set want "file format pei-i386" |
7cd00957 | 753 | set got [binutils_run $OBJDUMP "-x tmpdir/simple-pei-i386.dll"] |
1dd1bc4d OM |
754 | if ![regexp $want $got] then { |
755 | if [regexp "file format not recognized" $got] then { | |
7cd00957 OM |
756 | # If the target does not recognize vanilla x86 PE format files |
757 | # then it cannot be expected to recognize .NET assemblies. But | |
758 | # this means that these tests are unsupported, rather than failures. | |
1dd1bc4d OM |
759 | unsupported $test |
760 | } else { | |
761 | fail "$test" | |
762 | } | |
7cd00957 OM |
763 | # In either case, if cannot pass this test, then |
764 | # there is no point in running any further tests. | |
765 | return | |
766 | } | |
767 | pass $test | |
768 | ||
769 | # Next check a 32-bit .NET DLL. | |
770 | set test "dotnet-assemblies (32-bit .NET)" | |
771 | set got [binutils_run $OBJDUMP "-x tmpdir/linux-pei-i386.dll"] | |
772 | if ![regexp $want $got] then { | |
773 | fail "$test" | |
1dd1bc4d OM |
774 | } else { |
775 | pass $test | |
776 | } | |
777 | ||
7cd00957 OM |
778 | # Next check an ordrinary x86_64 PE format DLL. |
779 | set test "dotnet-assemblies (ordinary x86_64 DLL)" | |
1dd1bc4d | 780 | set want "file format pei-x86-64" |
7cd00957 | 781 | set got [binutils_run $OBJDUMP "-x tmpdir/simple-pei-x86-64.dll"] |
1dd1bc4d OM |
782 | if ![regexp $want $got] then { |
783 | if [regexp "file format not recognized" $got] then { | |
7cd00957 OM |
784 | # If the target does not support 64-bit PE format |
785 | # files, then the following tests are unsupported. | |
1dd1bc4d OM |
786 | unsupported $test |
787 | } else { | |
788 | fail "$test" | |
789 | } | |
7cd00957 OM |
790 | return |
791 | } | |
792 | pass $test | |
793 | ||
794 | # Finally check a 64-bit .NET DLL. | |
795 | set test "dotnet-assemblies (64-bit)" | |
796 | set got [binutils_run $OBJDUMP "-x tmpdir/linux-pei-x86-64.dll"] | |
797 | if ![regexp $want $got] then { | |
798 | fail "$test" | |
1dd1bc4d OM |
799 | } else { |
800 | pass $test | |
801 | } | |
802 | } | |
803 | ||
804 | test_objdump_dotnet_assemblies | |
805 | ||
a1c110a3 NC |
806 | # Test objdump -S |
807 | ||
808 | proc test_objdump_S { } { | |
809 | global srcdir | |
810 | global subdir | |
811 | global OBJDUMP | |
812 | global OBJDUMPFLAGS | |
813 | ||
814 | set test "objdump -S" | |
815 | ||
816 | if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog executable debug] != "" } { | |
817 | unsupported "$test (build)" | |
818 | return | |
819 | } | |
820 | ||
821 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -S tmpdir/testprog"] | |
822 | ||
823 | set want "static int local = 2" | |
824 | ||
825 | if [regexp $want $got] then { | |
826 | pass $test | |
827 | } else { | |
828 | fail $test | |
829 | } | |
830 | ||
831 | set test "objdump --source-comment" | |
832 | ||
833 | set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS --source-comment=// tmpdir/testprog"] | |
834 | ||
835 | set want "//static int local = 2" | |
836 | ||
837 | if [regexp $want $got] then { | |
838 | pass $test | |
839 | } else { | |
840 | fail $test | |
841 | } | |
842 | } | |
843 | ||
844 | test_objdump_S | |
845 | ||
d3def5d7 | 846 | # Options which are not tested: -a -D -R -T -x -l --stabs |
252b5132 RH |
847 | # I don't see any generic way to test any of these other than -a. |
848 | # Tests could be written for specific targets, and that should be done | |
849 | # if specific problems are found. |