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