Enhance objdump's --disassemble switch so that it can now take an optional parameter, specifying the starting symbol for disassembly. Disassembly will continue from this symbol up to the next symbol.

* objdump.c (long_options): Have the --disassemble option take an
	optional argument.
	(usage): Add description for the `symbol' argument to the
	--disassemble option.
	(disasm_sym): New file private variable.
	(struct objdump_disasm_info): New field `symbol'.
	(disassemble_section): Introduce `do_print' local variable
	to control whether objdump displays the result of disassembling
	for a symbol or not.
	(main): Set `symbol' file private variable if the option argument
	for the --disassemble option is given.
	* doc/binutils.texi (objdump): Add description for the option
	argument.
	* NEWS: Mention the new feature.
	* testsuite/binutils-all/objdump.exp: Add tests of the -d and
	--disassemble=<symbol> options.
	* testsuite/binutils-all/bintest.s: Add more symbols and code.
	* testsuite/binutils-all/readelf.s: Update expected output.
	* testsuite/binutils-all/readelf.ss-64: Likewise.
	* testsuite/binutils-all/readelf.ss-mips: Likewise.
	* testsuite/binutils-all/readelf.ss-tmips: Likewise.
This commit is contained in:
Masatake Yamato 2018-11-07 18:07:36 +00:00 committed by Nick Clifton
parent 0661ae2e53
commit d3def5d73e
12 changed files with 173 additions and 21 deletions

View File

@ -1,3 +1,27 @@
2018-11-07 Masatake Yamato <yamato@redhat.com>
* objdump.c (long_options): Have the --disassemble option take an
optional argument.
(usage): Add description for the `symbol' argument to the
--disassemble option.
(disasm_sym): New file private variable.
(struct objdump_disasm_info): New field `symbol'.
(disassemble_section): Introduce `do_print' local variable
to control whether objdump displays the result of disassembling
for a symbol or not.
(main): Set `symbol' file private variable if the option argument
for the --disassemble option is given.
* doc/binutils.texi (objdump): Add description for the option
argument.
* NEWS: Mention the new feature.
* testsuite/binutils-all/objdump.exp: Add tests of the -d and
--disassemble=<symbol> options.
* testsuite/binutils-all/bintest.s: Add more symbols and code.
* testsuite/binutils-all/readelf.s: Update expected output.
* testsuite/binutils-all/readelf.ss-64: Likewise.
* testsuite/binutils-all/readelf.ss-mips: Likewise.
* testsuite/binutils-all/readelf.ss-tmips: Likewise.
2018-11-07 Nick Clifton <nickc@redhat.com> 2018-11-07 Nick Clifton <nickc@redhat.com>
* po/pt.po: Updated Portuguese translation. * po/pt.po: Updated Portuguese translation.

View File

@ -1,5 +1,9 @@
-*- text -*- -*- text -*-
* Objdump's --disassemble option can now take a parameter, specifying the
starting symbol for disassembly. Disassembly will continue from this
symbol up to the next symbol.
* The MIPS port now supports the Loongson 2K1000 processor which implements * The MIPS port now supports the Loongson 2K1000 processor which implements
the MIPS64r2 ISA, the Loongson-mmi ASE, Loongson-cam ASE, Loongson-ext ASE, the MIPS64r2 ISA, the Loongson-mmi ASE, Loongson-cam ASE, Loongson-ext ASE,
Loongson-ext2 ASE and MSA ASE instructions. Add -march=gs264e option for Loongson-ext2 ASE and MSA ASE instructions. Add -march=gs264e option for

View File

@ -2063,7 +2063,7 @@ ld(1), objdump(1), and the Info entries for @file{binutils}.
objdump [@option{-a}|@option{--archive-headers}] objdump [@option{-a}|@option{--archive-headers}]
[@option{-b} @var{bfdname}|@option{--target=@var{bfdname}}] [@option{-b} @var{bfdname}|@option{--target=@var{bfdname}}]
[@option{-C}|@option{--demangle}[=@var{style}] ] [@option{-C}|@option{--demangle}[=@var{style}] ]
[@option{-d}|@option{--disassemble}] [@option{-d}|@option{--disassemble}[=@var{symbol}]]
[@option{-D}|@option{--disassemble-all}] [@option{-D}|@option{--disassemble-all}]
[@option{-z}|@option{--disassemble-zeroes}] [@option{-z}|@option{--disassemble-zeroes}]
[@option{-EB}|@option{-EL}|@option{--endian=}@{big | little @}] [@option{-EB}|@option{-EL}|@option{--endian=}@{big | little @}]
@ -2189,11 +2189,15 @@ with ctags tool.
@item -d @item -d
@itemx --disassemble @itemx --disassemble
@itemx --disassemble=@var{symbol}
@cindex disassembling object code @cindex disassembling object code
@cindex machine instructions @cindex machine instructions
Display the assembler mnemonics for the machine instructions from Display the assembler mnemonics for the machine instructions from the
@var{objfile}. This option only disassembles those sections which are input file. This option only disassembles those sections which are
expected to contain instructions. expected to contain instructions. If the optional @var{symbol}
argument is given, then display the assembler mnemonics only from
@var{symbol} up to next symbol. If there are no matches for
@var{symbol} then nothing will be displayed.
@item -D @item -D
@itemx --disassemble-all @itemx --disassemble-all

View File

@ -118,6 +118,7 @@ static const char *prefix; /* --prefix */
static int prefix_strip; /* --prefix-strip */ static int prefix_strip; /* --prefix-strip */
static size_t prefix_length; static size_t prefix_length;
static bfd_boolean unwind_inlines; /* --inlines. */ static bfd_boolean unwind_inlines; /* --inlines. */
static const char * disasm_sym; /* Disassembly start symbol. */
/* A structure to record the sections mentioned in -j switches. */ /* A structure to record the sections mentioned in -j switches. */
struct only struct only
@ -145,6 +146,7 @@ struct objdump_disasm_info
long dynrelcount; long dynrelcount;
disassembler_ftype disassemble_fn; disassembler_ftype disassemble_fn;
arelent * reloc; arelent * reloc;
const char * symbol;
}; };
/* Architecture to disassemble for, or default if NULL. */ /* Architecture to disassemble for, or default if NULL. */
@ -209,6 +211,7 @@ usage (FILE *stream, int status)
-x, --all-headers Display the contents of all headers\n\ -x, --all-headers Display the contents of all headers\n\
-d, --disassemble Display assembler contents of executable sections\n\ -d, --disassemble Display assembler contents of executable sections\n\
-D, --disassemble-all Display assembler contents of all sections\n\ -D, --disassemble-all Display assembler contents of all sections\n\
--disassemble=<sym> Display assembler contents from <sym>\n\
-S, --source Intermix source code with disassembly\n\ -S, --source Intermix source code with disassembly\n\
-s, --full-contents Display the full contents of all sections requested\n\ -s, --full-contents Display the full contents of all sections requested\n\
-g, --debugging Display debug information in object file\n\ -g, --debugging Display debug information in object file\n\
@ -313,7 +316,7 @@ static struct option long_options[]=
{"debugging", no_argument, NULL, 'g'}, {"debugging", no_argument, NULL, 'g'},
{"debugging-tags", no_argument, NULL, 'e'}, {"debugging-tags", no_argument, NULL, 'e'},
{"demangle", optional_argument, NULL, 'C'}, {"demangle", optional_argument, NULL, 'C'},
{"disassemble", no_argument, NULL, 'd'}, {"disassemble", optional_argument, NULL, 'd'},
{"disassemble-all", no_argument, NULL, 'D'}, {"disassemble-all", no_argument, NULL, 'D'},
{"disassembler-options", required_argument, NULL, 'M'}, {"disassembler-options", required_argument, NULL, 'M'},
{"disassemble-zeroes", no_argument, NULL, 'z'}, {"disassemble-zeroes", no_argument, NULL, 'z'},
@ -2253,6 +2256,7 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
asymbol *nextsym; asymbol *nextsym;
bfd_vma nextstop_offset; bfd_vma nextstop_offset;
bfd_boolean insns; bfd_boolean insns;
bfd_boolean do_print = TRUE;
addr = section->vma + addr_offset; addr = section->vma + addr_offset;
addr = ((addr & ((sign_adjust << 1) - 1)) ^ sign_adjust) - sign_adjust; addr = ((addr & ((sign_adjust << 1) - 1)) ^ sign_adjust) - sign_adjust;
@ -2278,7 +2282,23 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
pinfo->symtab_pos = -1; pinfo->symtab_pos = -1;
} }
if (! prefix_addresses) if (sym && paux->symbol)
{
const char *name = bfd_asymbol_name (sym);
char *alloc = NULL;
if (do_demangle && name[0] != '\0')
{
/* Demangle the name. */
alloc = bfd_demangle (abfd, name, DMGL_ANSI | DMGL_PARAMS);
if (alloc != NULL)
name = alloc;
}
do_print = streq (name, paux->symbol);
free (alloc);
}
if (! prefix_addresses && do_print)
{ {
pinfo->fprintf_func (pinfo->stream, "\n"); pinfo->fprintf_func (pinfo->stream, "\n");
objdump_print_addr_with_sym (abfd, section, sym, addr, objdump_print_addr_with_sym (abfd, section, sym, addr,
@ -2339,9 +2359,14 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
else else
insns = FALSE; insns = FALSE;
disassemble_bytes (pinfo, paux->disassemble_fn, insns, data, if (do_print)
addr_offset, nextstop_offset, {
rel_offset, &rel_pp, rel_ppend); disassemble_bytes (pinfo, paux->disassemble_fn, insns, data,
addr_offset, nextstop_offset,
rel_offset, &rel_pp, rel_ppend);
if (paux->symbol)
break;
}
addr_offset = nextstop_offset; addr_offset = nextstop_offset;
sym = nextsym; sym = nextsym;
@ -2394,6 +2419,7 @@ disassemble_data (bfd *abfd)
aux.dynrelbuf = NULL; aux.dynrelbuf = NULL;
aux.dynrelcount = 0; aux.dynrelcount = 0;
aux.reloc = NULL; aux.reloc = NULL;
aux.symbol = disasm_sym;
disasm_info.print_address_func = objdump_print_address; disasm_info.print_address_func = objdump_print_address;
disasm_info.symbol_at_address_func = objdump_symbol_at_address; disasm_info.symbol_at_address_func = objdump_symbol_at_address;
@ -3995,6 +4021,7 @@ main (int argc, char **argv)
case 'd': case 'd':
disassemble = TRUE; disassemble = TRUE;
seenflag = TRUE; seenflag = TRUE;
disasm_sym = optarg;
break; break;
case 'z': case 'z':
disassemble_zeroes = TRUE; disassemble_zeroes = TRUE;

View File

@ -10,3 +10,11 @@ data_symbol:
static_data_symbol: static_data_symbol:
.long 2 .long 2
.comm common_symbol,4 .comm common_symbol,4
.text
.global text_symbol2
text_symbol2:
.long 2
.global text_symbol3
text_symbol3:
.long 3

View File

@ -80,6 +80,7 @@ proc objcopy_test {testname srcfile} {
setup_xfail "hppa*-*-*" setup_xfail "hppa*-*-*"
setup_xfail "m8*-*" setup_xfail "m8*-*"
setup_xfail "sh-*-coff*" setup_xfail "sh-*-coff*"
setup_xfail "tic54x-*-*"
setup_xfail "tic80-*-*" setup_xfail "tic80-*-*"
clear_xfail "hppa*64*-*-hpux*" "hppa*-*-linux*" "hppa*-*-lites*" clear_xfail "hppa*64*-*-hpux*" "hppa*-*-linux*" "hppa*-*-lites*"

View File

@ -206,6 +206,85 @@ if { [ remote_file host exists $testarchive ] } then {
test_objdump_r $testarchive bintest2.o test_objdump_r $testarchive bintest2.o
} }
# Test objdump -d
proc test_objdump_d { testfile dumpfile } {
global OBJDUMP
global OBJDUMPFLAGS
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -d $testfile"]
set want "$dumpfile:.*Disassembly of section"
if ![regexp $want $got] then {
fail "objdump -d $testfile: No disassembly title"
return
}
set want "$dumpfile:.*00+0 <text_symbol>"
if ![regexp $want $got] then {
fail "objdump -d $testfile: Missing symbol name and address"
return
}
set want "$dumpfile:.*00+. <text_symbol2>"
if ![regexp $want $got] then {
fail "objdump -d $testfile: Missing second symbol"
return
}
set want "$dumpfile:.*00+. <text_symbol3>"
if ![regexp $want $got] then {
fail "objdump -d $testfile: Missing third symbol"
return
}
pass "objdump -d $testfile"
}
test_objdump_d $testfile $testfile
if { [ remote_file host exists $testarchive ] } then {
test_objdump_d $testarchive bintest2.o
}
# Test objdump --disassemble=<symbol>
proc test_objdump_d_sym { testfile dumpfile } {
global OBJDUMP
global OBJDUMPFLAGS
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS --disassemble=text_symbol2 $testfile"]
set want "$dumpfile:.*Disassembly of section"
if ![regexp $want $got] then {
fail "objdump --disassemble=text_symbol2 $testfile: No disassembly title"
return
}
set want "$dumpfile:.*00+0 <text_symbol>"
if [regexp $want $got] then {
fail "objdump --disassemble=text_symbol2 $testfile: First symbol displayed, when it should be absent"
return
}
set want "$dumpfile:.*00+. <text_symbol2>"
if ![regexp $want $got] then {
fail "objdump --disassemble=text_symbol2 $testfile: Missing second symbol"
return
}
set want "$dumpfile:.*00+. <text_symbol3>"
if [regexp $want $got] then {
fail "objdump --disassemble=text_symbol2 $testfile: Third symbol displayed when it should be absent"
return
}
pass "objdump --disassemble=text_symbol2 $testfile"
}
test_objdump_d_sym $testfile $testfile
if { [ remote_file host exists $testarchive ] } then {
test_objdump_d_sym $testarchive bintest2.o
}
# Test objdump -s # Test objdump -s
proc test_objdump_s { testfile dumpfile } { proc test_objdump_s { testfile dumpfile } {
@ -505,8 +584,7 @@ if {[is_elf_format]} then {
test_follow_debuglink test_follow_debuglink
} }
# Options which are not tested: -a -D -R -T -x -l --stabs
# Options which are not tested: -a -d -D -R -T -x -l --stabs
# I don't see any generic way to test any of these other than -a. # I don't see any generic way to test any of these other than -a.
# Tests could be written for specific targets, and that should be done # Tests could be written for specific targets, and that should be done
# if specific problems are found. # if specific problems are found.

View File

@ -9,8 +9,9 @@ Section Headers:
+\[ 2\] .rel.* +REL. +0+ 0+.* 0000.. 0. +I +.+ +1 +4 +\[ 2\] .rel.* +REL. +0+ 0+.* 0000.. 0. +I +.+ +1 +4
# MIPS targets put .rela.text here. # MIPS targets put .rela.text here.
#... #...
+\[ .\] .* +PROGBITS +00000000 0000(3c|40|48|50) 0000(04|10) 00 +WA +0 +0 +(.|..) +\[ .\] .* +PROGBITS +00000000 0000(3c|40|44|48|50) 0000(04|10) 00 +WA +0 +0 +(.|..)
+\[ .\] .* +NOBITS +00000000 0000(40|44|4c|60) 000000 00 +WA +0 +0 +(.|..) +\[ .\] .* +NOBITS +00000000 0000(40|44|48|4c|60) 000000 00 +WA +0 +0 +(.|..)
# ARM targets put .ARM.attributes here
# MIPS targets put .reginfo, .mdebug, .MIPS.abiflags and .gnu.attributes here. # MIPS targets put .reginfo, .mdebug, .MIPS.abiflags and .gnu.attributes here.
# v850 targets put .call_table_data and .call_table_text here. # v850 targets put .call_table_data and .call_table_text here.
#... #...

View File

@ -6,15 +6,15 @@ Symbol table '.symtab' contains .* entries:
+2: 00000000 +0 +SECTION +LOCAL +DEFAULT +[34] +2: 00000000 +0 +SECTION +LOCAL +DEFAULT +[34]
+3: 00000000 +0 +SECTION +LOCAL +DEFAULT +[45] +3: 00000000 +0 +SECTION +LOCAL +DEFAULT +[45]
+4: 00000000 +0 +NOTYPE +LOCAL +DEFAULT +1 static_text_symbol +4: 00000000 +0 +NOTYPE +LOCAL +DEFAULT +1 static_text_symbol
# arm-elf targets add the $d mapping symbol here... # ARM targets add the $d mapping symbol here...
# NDS32 targets add the $d2 mapping symbol here...
#... #...
+.: 00000000 +0 +NOTYPE +LOCAL +DEFAULT +[34] static_data_symbol +.: 00000000 +0 +NOTYPE +LOCAL +DEFAULT +[34] static_data_symbol
# v850 targets include extra SECTION symbols here for the .call_table_data # v850 targets include extra SECTION symbols here for the .call_table_data
# and .call_table_text sections. # and .call_table_text sections.
#... #...
+.: 00000000 +0 +NOTYPE +GLOBAL +DEFAULT +1 text_symbol +[0-9]+: 00000000 +0 +NOTYPE +GLOBAL +DEFAULT +1 text_symbol
+..: 00000000 +0 +NOTYPE +GLOBAL +DEFAULT +UND external_symbol +[0-9]+: 00000000 +0 +NOTYPE +GLOBAL +DEFAULT +UND external_symbol
+..: 00000000 +0 +NOTYPE +GLOBAL +DEFAULT +[34] data_symbol +[0-9]+: 00000000 +0 +NOTYPE +GLOBAL +DEFAULT +[34] data_symbol
+..: 00000004 +4 +(COMMON|OBJECT) +GLOBAL +DEFAULT +(COM|ANSI_COM) common_symbol +[0-9]+: 00000004 +4 +(COMMON|OBJECT) +GLOBAL +DEFAULT +(COM|ANSI_COM) common_symbol
# The MSP430 adds special crt0 symbols here.
#... #...

View File

@ -15,3 +15,4 @@ Symbol table '.symtab' contains .* entries:
+.: 0000000000000000 +0 +NOTYPE +GLOBAL +DEFAULT +UND external_symbol +.: 0000000000000000 +0 +NOTYPE +GLOBAL +DEFAULT +UND external_symbol
+.: 0000000000000000 +0 +NOTYPE +GLOBAL +DEFAULT +3 data_symbol +.: 0000000000000000 +0 +NOTYPE +GLOBAL +DEFAULT +3 data_symbol
+[0-9]+: 0000000000000004 +4 +(COMMON|OBJECT) +GLOBAL +DEFAULT +COM common_symbol +[0-9]+: 0000000000000004 +4 +(COMMON|OBJECT) +GLOBAL +DEFAULT +COM common_symbol
#pass

View File

@ -1,5 +1,5 @@
Symbol table '.symtab' contains 14 entries: Symbol table '.symtab' contains 16 entries:
+Num: +Value +Size +Type +Bind +Vis +Ndx +Name +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+0: 00000000 +0 +NOTYPE +LOCAL +DEFAULT +UND +0: 00000000 +0 +NOTYPE +LOCAL +DEFAULT +UND
+1: 00000000 +0 +SECTION +LOCAL +DEFAULT +. (|\.text) +1: 00000000 +0 +SECTION +LOCAL +DEFAULT +. (|\.text)
@ -15,3 +15,5 @@ Symbol table '.symtab' contains 14 entries:
+11: 00000000 +0 +OBJECT +GLOBAL +DEFAULT +. data_symbol +11: 00000000 +0 +OBJECT +GLOBAL +DEFAULT +. data_symbol
+12: 00000000 +0 +NOTYPE +LOCAL +DEFAULT +. static_data_symbol +12: 00000000 +0 +NOTYPE +LOCAL +DEFAULT +. static_data_symbol
+13: 00000004 +4 +(COMMON|OBJECT) +GLOBAL +DEFAULT +(PRC|COM) common_symbol +13: 00000004 +4 +(COMMON|OBJECT) +GLOBAL +DEFAULT +(PRC|COM) common_symbol
+14: 00000008 +0 +OBJECT +GLOBAL +DEFAULT +. text_symbol2
+15: 0000000c +0 +OBJECT +GLOBAL +DEFAULT +. text_symbol3

View File

@ -1,5 +1,5 @@
Symbol table '.symtab' contains 14 entries: Symbol table '.symtab' contains 16 entries:
+Num: +Value +Size +Type +Bind +Vis +Ndx +Name +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+0: 00000000 +0 +NOTYPE +LOCAL +DEFAULT +UND +0: 00000000 +0 +NOTYPE +LOCAL +DEFAULT +UND
+1: 00000000 +0 +SECTION +LOCAL +DEFAULT +1 +1: 00000000 +0 +SECTION +LOCAL +DEFAULT +1
@ -15,3 +15,5 @@ Symbol table '.symtab' contains 14 entries:
+11: 00000000 +0 +NOTYPE +GLOBAL +DEFAULT +UND external_symbol +11: 00000000 +0 +NOTYPE +GLOBAL +DEFAULT +UND external_symbol
+12: 00000000 +0 +OBJECT +GLOBAL +DEFAULT +3 data_symbol +12: 00000000 +0 +OBJECT +GLOBAL +DEFAULT +3 data_symbol
+13: 00000004 +4 +(COMMON|OBJECT) +GLOBAL +DEFAULT +(PRC|COM) common_symbol +13: 00000004 +4 +(COMMON|OBJECT) +GLOBAL +DEFAULT +(PRC|COM) common_symbol
+14: 00000008 +0 +OBJECT +GLOBAL +DEFAULT +. text_symbol2
+15: 0000000c +0 +OBJECT +GLOBAL +DEFAULT +. text_symbol3