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