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