Add support for locating separate debug info files via the build-id method.
[deliverable/binutils-gdb.git] / binutils / testsuite / binutils-all / objdump.exp
CommitLineData
2571583a 1# Copyright (C) 1993-2017 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]
24740d83 37lappend cpus_expected aarch64 alpha arc ARC700 ARCv2 arm cris
bf64a951 38lappend cpus_expected d10v d30v fr30 fr500 fr550 h8 hppa i386 i860 i960 iamcu ip2022
153a2776 39lappend cpus_expected m16c m32c m32r m68hc11 m68hc12 m68k m88k 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
fb6cedde
WL
42lappend cpus_expected tahoe tic54x tic80 tilegx tms320c30 tms320c4x tms320c54x
43lappend cpus_expected v850 vax we32k 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
61# The remaining tests require a test file.
62
63
64if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then {
65 return
66}
67if [is_remote host] {
68 set testfile [remote_download host tmpdir/bintest.o]
69} else {
70 set testfile tmpdir/bintest.o
71}
72
73# Test objdump -f
74
75set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f $testfile"]
76
41f5a528 77set want "$testfile:\[ \]*file format.*architecture:\[ \]*${cpus_regex}.*HAS_RELOC.*HAS_SYMS"
252b5132
RH
78
79if ![regexp $want $got] then {
80 fail "objdump -f"
81} else {
82 pass "objdump -f"
83}
84
85# Test objdump -h
86
87set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h $testfile"]
88
96037eb0 89set want "$testfile:\[ \]*file format.*Sections.*\[0-9\]+\[ \]+\[^ \]*(text|TEXT|P|\\\$CODE\\\$)\[^ \]*\[ \]*(\[0-9a-fA-F\]+).*\[0-9\]+\[ \]+\[^ \]*(\\.data|DATA|D_1)\[^ \]*\[ \]*(\[0-9a-fA-F\]+)"
252b5132
RH
90
91if ![regexp $want $got all text_name text_size data_name data_size] then {
92 fail "objdump -h"
93} else {
94 verbose "text name is $text_name size is $text_size"
95 verbose "data name is $data_name size is $data_size"
60bcf0fa
NC
96 set ets 8
97 set eds 4
48c5eb8a
SS
98 # The [ti]c4x target has the property sizeof(char)=sizeof(long)=1
99 if [istarget *c4x*-*-*] then {
100 set ets 2
101 set eds 1
102 }
60bcf0fa
NC
103 # c54x section sizes are in bytes, not octets; adjust accordingly
104 if [istarget *c54x*-*-*] then {
105 set ets 4
106 set eds 2
107 }
108 if {[expr "0x$text_size"] < $ets || [expr "0x$data_size"] < $eds} then {
252b5132
RH
109 send_log "sizes too small\n"
110 fail "objdump -h"
111 } else {
112 pass "objdump -h"
113 }
114}
115
116# Test objdump -t
117
118set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -t $testfile"]
119
120if [info exists vars] then { unset vars }
121while {[regexp "(\[a-z\]*_symbol)(.*)" $got all symbol rest]} {
122 set vars($symbol) 1
123 set got $rest
124}
125
126if {![info exists vars(text_symbol)] \
127 || ![info exists vars(data_symbol)] \
128 || ![info exists vars(common_symbol)] \
129 || ![info exists vars(external_symbol)]} then {
130 fail "objdump -t"
131} else {
132 pass "objdump -t"
133}
134
135# Test objdump -r
136
137set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -r $testfile"]
138
96037eb0 139set want "$testfile:\[ \]*file format.*RELOCATION RECORDS FOR \\\[\[^\]\]*(text|TEXT|P|\\\$CODE\\\$)\[^\]\]*\\\].*external_symbol"
252b5132
RH
140
141if [regexp $want $got] then {
142 pass "objdump -r"
143} else {
144 fail "objdump -r"
145}
146
147# Test objdump -s
148
149set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -s $testfile"]
150
96037eb0 151set want "$testfile:\[ \]*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)"
252b5132
RH
152
153if [regexp $want $got] then {
154 pass "objdump -s"
155} else {
156 fail "objdump -s"
157}
158
1b315056
CS
159# Test objdump -s on a file that contains a compressed .debug section
160
dae148f3 161if { ![is_elf_format] } then {
22bce68e
AM
162 unsupported "objdump compressed debug"
163} elseif { ![binutils_assemble $srcdir/$subdir/dw2-compressed.S tmpdir/dw2-compressed.o] } then {
164 fail "objdump compressed debug"
1b315056 165} else {
22bce68e
AM
166 if [is_remote host] {
167 set compressed_testfile [remote_download host tmpdir/dw2-compressed.o]
168 } else {
169 set compressed_testfile tmpdir/dw2-compressed.o
170 }
1b315056 171
22bce68e 172 set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS -s -j .zdebug_abbrev $compressed_testfile" "" "/dev/null" "objdump.out"]
1b315056 173
22bce68e
AM
174 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
175 fail "objdump -s -j .zdebug_abbrev (reason: unexpected output)"
176 send_log $got
177 send_log "\n"
178 }
1b315056 179
22bce68e
AM
180 if { [regexp_diff objdump.out $srcdir/$subdir/objdump.s] } then {
181 fail "objdump -s -j .zdebug_abbrev"
182 } else {
183 pass "objdump -s -j .zdebug_abbrev"
184 }
1b315056 185
22bce68e 186 # Test objdump -W on a file that contains some compressed .debug sections
1b315056 187
22bce68e 188 set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS -W $compressed_testfile" "" "/dev/null" "objdump.out"]
1b315056 189
22bce68e
AM
190 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
191 fail "objdump -W (reason: unexpected output)"
192 send_log $got
193 send_log "\n"
194 }
1b315056 195
22bce68e
AM
196 if { [regexp_diff objdump.out $srcdir/$subdir/objdump.W] } then {
197 fail "objdump -W"
198 } else {
199 pass "objdump -W"
200 }
1b315056
CS
201}
202
4eee63bc 203# Test objdump -WL on a file that contains line information for multiple files and search directories.
73589c9d 204# Not supported on mcore and moxie targets because they do not (yet) support the generation
e3cb57c3
NC
205# of DWARF2 line debug information.
206
207if { ![is_elf_format]
71ac97b2
AM
208 || [istarget "hppa64*-*-hpux*"]
209 || [istarget "i370-*-*"]
210 || [istarget "i960-*-*"]
e3cb57c3
NC
211 || [istarget "ia64*-*-*"]
212 || [istarget "mcore-*-*"]
213 || [istarget "moxie-*-*"]
e3cb57c3 214} then {
d4cb0ea0 215 unsupported "objump decode line"
4eee63bc 216} else {
73589c9d
CS
217 if { [istarget "or1k*-*-*"] } then {
218 set decodedline_testsrc $srcdir/$subdir/dw2-decodedline-1.S
219 } else {
220 set decodedline_testsrc $srcdir/$subdir/dw2-decodedline.S
221 }
222 if { ![binutils_assemble $decodedline_testsrc tmpdir/dw2-decodedline.o] } then {
d4cb0ea0
NC
223 fail "objdump decoded line"
224 }
225
226 if [is_remote host] {
227 set decodedline_testfile [remote_download host tmpdir/dw2-decodedline.o]
228 } else {
229 set decodedline_testfile tmpdir/dw2-decodedline.o
230 }
4eee63bc 231
d4cb0ea0 232 set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS -WL $decodedline_testfile" "" "/dev/null" "objdump.out"]
4eee63bc 233
d4cb0ea0
NC
234 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
235 fail "objdump -WL (reason: unexpected output)"
236 send_log $got
237 send_log "\n"
238 }
4eee63bc 239
d4cb0ea0
NC
240 if { [regexp_diff objdump.out $srcdir/$subdir/objdump.WL] } then {
241 fail "objdump -WL"
242 } else {
243 pass "objdump -WL"
244 }
4eee63bc 245}
1b315056 246
42bcef4a
AB
247# Test objdump -W on a file containing debug_ranges information.
248
249if { ![is_elf_format] } then {
250 unsupported "objdump debug_ranges test"
251} elseif { ![binutils_assemble $srcdir/$subdir/dw2-ranges.S tmpdir/dw2-ranges.o] } then {
252 fail "objdump debug_ranges test"
253} else {
254 if [is_remote host] {
255 set ranges_testfile [remote_download host tmpdir/dw2-ranges.o]
256 } else {
257 set ranges_testfile tmpdir/dw2-ranges.o
258 }
259
260 set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS --dwarf=Ranges $ranges_testfile" "" "/dev/null" "objdump.out"]
261
262 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
263 fail "objdump -W for debug_ranges (reason: unexpected output)"
264 send_log $got
265 send_log "\n"
266 }
267
e23eba97 268 setup_xfail "msp430-*-*" "nds32*-*-*" "riscv*-*-*"
42bcef4a
AB
269 if { [regexp_diff objdump.out $srcdir/$subdir/dw2-ranges.W] } then {
270 fail "objdump -W for debug_ranges"
271 } else {
272 pass "objdump -W for debug_ranges"
273 }
274}
275
2425a30e
NC
276proc test_build_id_debuglink {} {
277 global srcdir
278 global subdir
279 global env
280 global CC_FOR_TARGET
281 global STRIP
282 global OBJCOPY
283 global OBJDUMP
284 global CFLAGS_FOR_TARGET
285
286 set test "build-id-debuglink"
287 if {![info exists CC_FOR_TARGET]} {
288 set CC_FOR_TARGET $env(CC)
289 }
290 if { $CC_FOR_TARGET == "" } {
291 unsupported $test
292 return
293 }
294
295 # Use a fixed build-id.
296 set CFLAGS_FOR_TARGET "-g -Wl,--build-id=0x12345678abcdef01"
297
298 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog exectuable debug] != "" } {
299 fail "$test (build)"
300 return
301 }
302
303 # FIXME: Do we need to restore CFLAGS_FOR_TARGET to its old value ?
304
305 if { [binutils_run $STRIP "--strip-debug --remove-section=.comment tmpdir/testprog -o tmpdir/testprog.strip"] != "" } {
306 fail "$test (strip debug info)"
307 return
308 }
309
310 if { [binutils_run $OBJCOPY "--only-keep-debug tmpdir/testprog tmpdir/testprog.debug"] != "" } {
311 fail "$test (create separate debug info file)"
312 return
313 }
314
315 set got [remote_exec host "mkdir -p .build-id/12" ]
316 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
317 fail "$test (make debug directory)"
318 return
319 }
320
321 set got [remote_exec host "cp tmpdir/testprog.debug .build-id/12/345678abcdef01.debug"]
322 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
323 fail "$test (copy debug info into debug directory)"
324 return
325 }
326
327 set got [remote_exec host "$OBJDUMP -Sl tmpdir/testprog.strip" "" "/dev/null" "tmpdir/testprog.strip.dump"]
328 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
329 fail "$test (post strip dump)"
330 return
331 }
332
333 set src2 tmpdir/testprog.strip.dump
334 verbose " grep -e testprog.c ${src2}"
335 set status [remote_exec build grep "-e testprog.c ${src2}"]
336 set exec_output [lindex $status 1]
337 set exec_output [prune_warnings $exec_output]
338 if [string match "" $exec_output] then {
339 send_log "$exec_output\n"
340 verbose "$exec_output" 1
341 fail "$test (grepping for source file name in disassembly output)"
342 } else {
343 pass "$test"
344 # Cleanup...
345 set got [remote_exec host "rm .build-id/12/345678abcdef01.debug"]
346 set got [remote_exec host "rmdir -p .build-id/12" ]
347 set got [remote_exec host "rm tmpdir/testprog.strip.dump"]
348 set got [remote_exec host "rm tmpdir/testprog.debug"]
349 set got [remote_exec host "rm tmpdir/testprog.strip"]
350 }
351}
352
353if {[isnative] && [is_elf_format]} then {
354 test_build_id_debuglink
355}
42bcef4a 356
252b5132
RH
357# Options which are not tested: -a -d -D -R -T -x -l --stabs
358# I don't see any generic way to test any of these other than -a.
359# Tests could be written for specific targets, and that should be done
360# if specific problems are found.
This page took 0.761231 seconds and 4 git commands to generate.