1#!/bin/sh
2#
3#   Copyright (c) International Business Machines  Corp., 2000
4#
5#   This program is free software;  you can redistribute it and/or modify
6#   it under the terms of the GNU General Public License as published by
7#   the Free Software Foundation; either version 2 of the License, or
8#   (at your option) any later version.
9#
10#   This program is distributed in the hope that it will be useful,
11#   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13#   the GNU General Public License for more details.
14#
15#   You should have received a copy of the GNU General Public License
16#   along with this program;  if not, write to the Free Software
17#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18#
19#
20#
21#  FILE   : objdump
22#
23#  PURPOSE: Tests the functionality of the `objdump` command.
24#
25#  HISTORY:
26#    06/01 Robbie Williamson (robbiew@us.ibm.com)
27#      -Ported
28#
29#
30#-----------------------------------------------------------------------
31#
32#----------------------------------------------------------------------
33#Uncomment line below for debug output.
34#trace_logic=${trace_logic:-"set -x"}
35$trace_logic
36
37TCsrc=${TCsrc:-${0%/*}}
38TCtmp=${TCtmp:-/tmp/objdump$$}
39
40do_setup()
41{
42	mkdir $TCtmp
43	ar -cr $TCtmp/lib.a $TCsrc/test_arch.obj
44
45	echo 1; objdump -f $TCsrc/test_arch_stripped > $TCtmp/er_dump_f
46	echo 2; objdump -h $TCsrc/test_arch_stripped > $TCtmp/er_dump_h
47	echo 3; objdump -R $TCsrc/test_arch_stripped > $TCtmp/er_dump_R
48	echo 4; objdump -r $TCsrc/test_arch_stripped > $TCtmp/er_dump_reloc
49	echo 5; objdump -t $TCsrc/test_arch_stripped > $TCtmp/er_dump_symbols
50	echo 6; objdump -f --show-raw-insn $TCsrc/test_arch_stripped > $TCtmp/er_dump_fshow
51	echo 7; objdump -h --show-raw-insn $TCsrc/test_arch_stripped > $TCtmp/er_dump_hshow
52	echo 7; objdump -s --show-raw-insn $TCsrc/test_arch_stripped > $TCtmp/er_dump_sshow
53	echo 8; objdump -t --show-raw-insn $TCsrc/test_arch_stripped > $TCtmp/er_dump_tshow
54	echo 9; objdump -R --show-raw-insn $TCsrc/test_arch_stripped > $TCtmp/er_dump_Rshow
55	echo 10; objdump -r --show-raw-insn $TCsrc/test_arch_stripped > $TCtmp/er_dump_rshow
56	echo 11; objdump -T $TCsrc/test_arch_stripped > $TCtmp/er_dump_dynamic_symbols
57	echo 12; objdump -a $TCtmp/lib.a > $TCtmp/er_dump_a
58	echo 13; objdump -a --show-raw-insn $TCtmp/lib.a > $TCtmp/er_dump_ashow
59	echo 14; objdump --debugging $TCsrc/test_arch_debug > $TCtmp/er_dump_debug
60}
61
62do_test()
63{
64	#ASSERTION POSIX NEXT_AVAILABLE C
65	#
66	#-f   Dump each file header.
67	#
68	#CODE
69
70	objdump -f $TCsrc/test_arch_stripped > $TCtmp/ar_dump_f
71
72	diff -bw  $TCtmp/ar_dump_f  $TCtmp/er_dump_f 2>&1 1>/dev/null
73
74	if [ $? -eq 0 ]
75	then
76		echo  "objdump -f"
77	else
78		echo "FAIL - objdump -f"
79		exit 1
80	fi
81
82	rm -f $TCtmp/[ae]r_dump_f
83
84	##ASSERTION POSIX NEXT_AVAILABLE C
85	#
86	#-h  Dump the section headers.
87	#
88	#CODE
89
90	objdump -h $TCsrc/test_arch_stripped > $TCtmp/ar_dump_h
91
92	diff -bw  $TCtmp/ar_dump_h $TCtmp/er_dump_h 2>&1 1>/dev/null
93
94	if [ $? -eq 0 ]; then
95		echo  "objdump -h"
96	else
97		echo "FAIL - objdump -h"
98		exit 1
99	fi
100
101	rm -f $TCtmp/[ae]r_dump_h
102
103	##ASSERTION POSIX NEXT_AVAILABLE C
104	#
105	#-R Dump dynamic linking information and static shared library information, if
106	#available.
107	#
108	#CODE
109
110	objdump -R $TCsrc/test_arch_stripped > $TCtmp/ar_dump_R
111
112	diff -bw  $TCtmp/ar_dump_R $TCtmp/er_dump_R 2>&1 1>/dev/null
113
114	if [ $? -eq 0 ]; then
115		echo  "objdump -R"
116	else
117		echo "FAIL - objdump -R"
118		exit 1
119	fi
120
121	rm -f $TCtmp/[ae]r_dump_R
122
123	##ASSERTION POSIX NEXT_AVAILABLE C
124	#
125	# -r  Dump relocation information.
126	#
127	#CODE
128
129	objdump -r $TCsrc/test_arch_stripped > $TCtmp/ar_dump_reloc
130
131	diff -bw  $TCtmp/ar_dump_reloc $TCtmp/er_dump_reloc 2>&1 1>/dev/null
132
133	if [ $? -eq 0 ]; then
134		echo  "objdump -r"
135	else
136		echo "FAIL - objdump -r"
137		exit 1
138	fi
139
140	rm -f $TCtmp/[ae]r_dump_reloc
141
142	##ASSERTION POSIX NEXT_AVAILABLE C
143	#
144	#-t  Dump symbol table entries.
145	#
146	#CODE
147
148	objdump -t $TCsrc/test_arch_stripped > $TCtmp/ar_dump_symbols
149
150	diff -bw  $TCtmp/ar_dump_symbols $TCtmp/er_dump_symbols 2>&1 1>/dev/null
151
152	if [ $? -eq 0 ]; then
153		echo  "objdump -t"
154	else
155		echo "FAIL - objdump -t"
156		exit 1
157	fi
158
159	rm -f $TCtmp/[ae]r_dump_symbols
160
161
162	##ASSERTION POSIX NEXT_AVAILABLE C
163	#
164	#-f --show-raw-insn
165	#
166	#--show-raw-insn
167	#
168	#When disassembling instructions, print the instruction  in  hex  as
169	#well  as  in symbolic form.  This is the default except when
170	#--prefix-addresses is used.
171	#
172	#CODE
173
174	objdump -f --show-raw-insn $TCsrc/test_arch_stripped > $TCtmp/ar_dump_fshow
175
176	diff -bw   $TCtmp/ar_dump_fshow  $TCtmp/er_dump_fshow 2>&1 1>/dev/null
177
178	if [ $? -eq 0 ]; then
179		echo  "objdump -f --show-raw-insn"
180	else
181		echo "FAIL - objdump -f --show-raw-insn"
182		exit 1
183	fi
184
185	rm -f $TCtmp/[ae]r_dump_fshow
186
187	##ASSERTION POSIX NEXT_AVAILABLE C
188	#
189	#-h --show-raw-insn
190	#
191	#When disassembling instructions, print the instruction  in  hex  as
192	#well  as  in symbolic form.  This is the default except when
193	#--prefix-addresses is used.
194	#
195	#CODE
196
197	objdump -h --show-raw-insn $TCsrc/test_arch_stripped > $TCtmp/ar_dump_hshow
198
199	diff -bw   $TCtmp/ar_dump_hshow  $TCtmp/er_dump_hshow 2>&1 1>/dev/null
200
201	if [ $? -eq 0 ]; then
202		echo  "objdump -h --show-raw-insn"
203	else
204		echo "FAIL - objdump -h --show-raw-insn"
205		exit 1
206	fi
207
208	rm -f $TCtmp/[ae]r_dump_hshow
209
210	##ASSERTION POSIX NEXT_AVAILABLE C
211	#
212	#-s --show-raw-insn
213	#
214	#--show-raw-insn
215	#
216	#When disassembling instructions, print the instruction  in  hex  as
217	#well  as  in symbolic form.  This is the default except when
218	#--prefix-addresses is used.
219	#
220	#
221	#CODE
222
223	objdump -s --show-raw-insn $TCsrc/test_arch_stripped > $TCtmp/ar_dump_sshow
224
225	diff -bw   $TCtmp/ar_dump_sshow  $TCtmp/er_dump_sshow 2>&1 1>/dev/null
226
227	if [ $? -eq 0 ]; then
228		echo  "objdump -s --show-raw-insn"
229	else
230		echo "FAIL - objdump -s --show-raw-insn"
231		exit 1
232	fi
233
234	rm -f $TCtmp/[ae]r_dump_sshow
235
236	##ASSERTION POSIX NEXT_AVAILABLE C
237	#
238	#-t--show-raw-insn
239	#
240	#--show-raw-insn
241	#
242	#When disassembling instructions, print the instruction  in  hex  as
243	#well  as  in symbolic form.  This is the default except when
244	#--prefix-addresses is used.
245	#
246	#
247	#CODE
248
249	objdump -t --show-raw-insn $TCsrc/test_arch_stripped > $TCtmp/ar_dump_tshow
250
251	diff -bw   $TCtmp/ar_dump_tshow  $TCtmp/er_dump_tshow 2>&1 1>/dev/null
252
253	if [ $? -eq 0 ]; then
254		echo  "objdump -t --show-raw-insn"
255	else
256		echo "FAIL - objdump -t --show-raw-insn"
257		exit 1
258	fi
259
260	rm -f $TCtmp/[ae]r_dump_tshow
261
262	##ASSERTION POSIX NEXT_AVAILABLE C
263	#
264	#-R --show-raw-insn
265	#
266	#--show-raw-insn
267	#
268	#When disassembling instructions, print the instruction  in  hex  as
269	#well  as  in symbolic form.  This is the default except when
270	#--prefix-addresses is used.
271	#
272	#
273	objdump -R --show-raw-insn $TCsrc/test_arch_stripped > $TCtmp/ar_dump_Rshow
274
275	diff -bw   $TCtmp/ar_dump_Rshow  $TCtmp/er_dump_Rshow 2>&1 1>/dev/null
276
277	if [ $? -eq 0 ]; then
278		echo  "objdump -R --show-raw-insn"
279	else
280		echo "FAIL - objdump -R --show-raw-insn"
281		exit 1
282	fi
283
284	rm -f $TCtmp/[ae]r_dump_Rshow
285
286	##ASSERTION POSIX NEXT_AVAILABLE C
287	#
288	#-r --show-raw-insn
289	#
290	#--show-raw-insn
291	#
292	#When disassembling instructions, print the instruction  in  hex  as
293	#well  as  in symbolic form.  This is the default except when
294	#--prefix-addresses is used.
295	#
296	#
297	#CODE
298
299	objdump -r --show-raw-insn $TCsrc/test_arch_stripped > $TCtmp/ar_dump_rshow
300
301	diff -bw   $TCtmp/ar_dump_rshow  $TCtmp/er_dump_rshow 2>&1 1>/dev/null
302
303	if [ $? -eq 0 ]; then
304		echo  "objdump -r --show-raw-insn"
305	else
306		echo "FAIL - objdump -r --show-raw-insn"
307		exit 1
308	fi
309
310	rm -f $TCtmp/[ae]r_dump_rshow
311
312	##ASSERTION POSIX NEXT_AVAILABLE C
313	#
314	#-T
315	#
316	#Dumps the dynamic symbol table entries - dumps all of .dynsym
317	#
318	#
319	#CODE
320
321	objdump -T $TCsrc/test_arch_stripped > $TCtmp/ar_dump_dynamic_symbols
322
323	diff -bw   $TCtmp/ar_dump_dynamic_symbols  $TCtmp/er_dump_dynamic_symbols 2>&1 1>/dev/null
324
325	if [ $? -eq 0 ]; then
326		echo  "objdump -T"
327	else
328		echo "FAIL - objdump -T"
329		exit 1
330	fi
331
332	rm -f $TCtmp/[ae]r_dump_dynamic_symbols
333
334	##ASSERTION POSIX NEXT_AVAILABLE C
335	#-a
336	#
337	#CODE
338
339	objdump -a $TCtmp/lib.a > $TCtmp/ar_dump_a
340
341	diff -bw $TCtmp/ar_dump_a $TCtmp/er_dump_a 2>&1 1>/dev/null
342
343	if [ $? -eq 0 ]; then
344		echo  "objdump -a"
345	else
346		echo "FAIL - objdump -a"
347		exit 1
348	fi
349
350	rm -f $TCtmp/[ae]r_dump_a
351
352	##ASSERTION POSIX NEXT_AVAILABLE C
353	#- --show-raw-insn
354	#
355	#CODE
356
357	objdump -a --show-raw-insn $TCtmp/lib.a > $TCtmp/ar_dump_ashow
358
359	diff -bw $TCtmp/ar_dump_ashow $TCtmp/er_dump_ashow 2>&1 1>/dev/null
360
361	if [ $? -eq 0 ]; then
362		echo  "objdump -a --show-raw-insn"
363	else
364		echo "FAIL - objdump -a --show-raw-insn"
365		exit 1
366	fi
367
368	rm -f $TCtmp/[ae]r_dump_ashow
369
370	##ASSERTION POSIX NEXT_AVAILABLE C
371	#--debugging
372	#
373	#CODE
374
375	if ! objdump --debugging $TCsrc/test_arch_debug > $TCtmp/ar_dump_debug; then
376		echo "FAIL - objdump --debugging"
377		exit 1
378	else
379		diff -bw $TCtmp/ar_dump_debug $TCtmp/er_dump_debug 2>&1 1>/dev/null
380		if [ $? -eq 0 ]; then
381			echo  "objdump --debugging"
382		else
383			echo "FAIL - objdump --debugging"
384			exit 1
385		fi
386
387	fi
388
389	rm -rf $TCtmp
390
391	echo PASS
392	exit 0
393}
394
395do_setup
396do_test
397