This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Enhance objdump's --disassemble switch so that it can now take an optional parameter, specifying the


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d3def5d73eb9d8295ca7b11d130b17a815151951

commit d3def5d73eb9d8295ca7b11d130b17a815151951
Author: Masatake Yamato <yamato@redhat.com>
Date:   Wed Nov 7 18:07:36 2018 +0000

    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.

Diff:
---
 binutils/ChangeLog                               | 24 +++++++
 binutils/NEWS                                    |  4 ++
 binutils/doc/binutils.texi                       | 12 ++--
 binutils/objdump.c                               | 37 +++++++++--
 binutils/testsuite/binutils-all/bintest.s        |  8 +++
 binutils/testsuite/binutils-all/objcopy.exp      |  1 +
 binutils/testsuite/binutils-all/objdump.exp      | 82 +++++++++++++++++++++++-
 binutils/testsuite/binutils-all/readelf.s        |  5 +-
 binutils/testsuite/binutils-all/readelf.ss       | 12 ++--
 binutils/testsuite/binutils-all/readelf.ss-64    |  1 +
 binutils/testsuite/binutils-all/readelf.ss-mips  |  4 +-
 binutils/testsuite/binutils-all/readelf.ss-tmips |  4 +-
 12 files changed, 173 insertions(+), 21 deletions(-)

diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index e93f028..2b76d8c 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -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>
 
 	* po/pt.po: Updated Portuguese translation.
diff --git a/binutils/NEWS b/binutils/NEWS
index de70c3a..a3ee86e 100644
--- a/binutils/NEWS
+++ b/binutils/NEWS
@@ -1,5 +1,9 @@
 -*- 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 MIPS64r2 ISA, the Loongson-mmi ASE, Loongson-cam ASE, Loongson-ext ASE,
   Loongson-ext2 ASE and MSA ASE instructions. Add -march=gs264e option for
diff --git a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi
index 6cfda45..9954adf 100644
--- a/binutils/doc/binutils.texi
+++ b/binutils/doc/binutils.texi
@@ -2063,7 +2063,7 @@ ld(1), objdump(1), and the Info entries for @file{binutils}.
 objdump [@option{-a}|@option{--archive-headers}]
         [@option{-b} @var{bfdname}|@option{--target=@var{bfdname}}]
         [@option{-C}|@option{--demangle}[=@var{style}] ]
-        [@option{-d}|@option{--disassemble}]
+        [@option{-d}|@option{--disassemble}[=@var{symbol}]]
         [@option{-D}|@option{--disassemble-all}]
         [@option{-z}|@option{--disassemble-zeroes}]
         [@option{-EB}|@option{-EL}|@option{--endian=}@{big | little @}]
@@ -2189,11 +2189,15 @@ with ctags tool.
 
 @item -d
 @itemx --disassemble
+@itemx --disassemble=@var{symbol}
 @cindex disassembling object code
 @cindex machine instructions
-Display the assembler mnemonics for the machine instructions from
-@var{objfile}.  This option only disassembles those sections which are
-expected to contain instructions.
+Display the assembler mnemonics for the machine instructions from the
+input file.  This option only disassembles those sections which are 
+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
 @itemx --disassemble-all
diff --git a/binutils/objdump.c b/binutils/objdump.c
index 9c3bce8..e3b8d7f 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -118,6 +118,7 @@ static const char *prefix;		/* --prefix */
 static int prefix_strip;		/* --prefix-strip */
 static size_t prefix_length;
 static bfd_boolean unwind_inlines;	/* --inlines.  */
+static const char * disasm_sym;		/* Disassembly start symbol.  */
 
 /* A structure to record the sections mentioned in -j switches.  */
 struct only
@@ -145,6 +146,7 @@ struct objdump_disasm_info
   long               dynrelcount;
   disassembler_ftype disassemble_fn;
   arelent *          reloc;
+  const char *       symbol;
 };
 
 /* 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\
   -d, --disassemble        Display assembler contents of executable 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, --full-contents      Display the full contents of all sections requested\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-tags", no_argument, NULL, 'e'},
   {"demangle", optional_argument, NULL, 'C'},
-  {"disassemble", no_argument, NULL, 'd'},
+  {"disassemble", optional_argument, NULL, 'd'},
   {"disassemble-all", no_argument, NULL, 'D'},
   {"disassembler-options", required_argument, NULL, 'M'},
   {"disassemble-zeroes", no_argument, NULL, 'z'},
@@ -2253,6 +2256,7 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
       asymbol *nextsym;
       bfd_vma nextstop_offset;
       bfd_boolean insns;
+      bfd_boolean do_print = TRUE;
 
       addr = section->vma + addr_offset;
       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;
 	}
 
-      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");
 	  objdump_print_addr_with_sym (abfd, section, sym, addr,
@@ -2339,9 +2359,14 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
       else
 	insns = FALSE;
 
-      disassemble_bytes (pinfo, paux->disassemble_fn, insns, data,
-			 addr_offset, nextstop_offset,
-			 rel_offset, &rel_pp, rel_ppend);
+      if (do_print)
+	{
+	  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;
       sym = nextsym;
@@ -2394,6 +2419,7 @@ disassemble_data (bfd *abfd)
   aux.dynrelbuf = NULL;
   aux.dynrelcount = 0;
   aux.reloc = NULL;
+  aux.symbol = disasm_sym;
 
   disasm_info.print_address_func = objdump_print_address;
   disasm_info.symbol_at_address_func = objdump_symbol_at_address;
@@ -3995,6 +4021,7 @@ main (int argc, char **argv)
 	case 'd':
 	  disassemble = TRUE;
 	  seenflag = TRUE;
+	  disasm_sym = optarg;
 	  break;
 	case 'z':
 	  disassemble_zeroes = TRUE;
diff --git a/binutils/testsuite/binutils-all/bintest.s b/binutils/testsuite/binutils-all/bintest.s
index 9e00650..dcf742f 100644
--- a/binutils/testsuite/binutils-all/bintest.s
+++ b/binutils/testsuite/binutils-all/bintest.s
@@ -10,3 +10,11 @@ data_symbol:
 static_data_symbol:
 	.long	2
 	.comm common_symbol,4
+	.text
+	.global text_symbol2
+text_symbol2:
+	.long	2
+	.global text_symbol3
+text_symbol3:
+	.long 3
+	
diff --git a/binutils/testsuite/binutils-all/objcopy.exp b/binutils/testsuite/binutils-all/objcopy.exp
index 3676f76..762bd0a 100644
--- a/binutils/testsuite/binutils-all/objcopy.exp
+++ b/binutils/testsuite/binutils-all/objcopy.exp
@@ -80,6 +80,7 @@ proc objcopy_test {testname srcfile} {
 	setup_xfail "hppa*-*-*"
 	setup_xfail "m8*-*"
 	setup_xfail "sh-*-coff*"
+	setup_xfail "tic54x-*-*"
 	setup_xfail "tic80-*-*"
 
 	clear_xfail "hppa*64*-*-hpux*" "hppa*-*-linux*" "hppa*-*-lites*"
diff --git a/binutils/testsuite/binutils-all/objdump.exp b/binutils/testsuite/binutils-all/objdump.exp
index effc3dd..b1dea8d 100644
--- a/binutils/testsuite/binutils-all/objdump.exp
+++ b/binutils/testsuite/binutils-all/objdump.exp
@@ -206,6 +206,85 @@ if { [ remote_file host exists $testarchive ] } then {
     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
 
 proc test_objdump_s { testfile dumpfile } {
@@ -505,8 +584,7 @@ if {[is_elf_format]} then {
     test_follow_debuglink
 }
 
-
-# Options which are not tested: -a -d -D -R -T -x -l --stabs
+# Options which are not tested: -a -D -R -T -x -l --stabs
 # 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
 # if specific problems are found.
diff --git a/binutils/testsuite/binutils-all/readelf.s b/binutils/testsuite/binutils-all/readelf.s
index 5aae0ce..6ae4dc7 100644
--- a/binutils/testsuite/binutils-all/readelf.s
+++ b/binutils/testsuite/binutils-all/readelf.s
@@ -9,8 +9,9 @@ Section Headers:
  +\[ 2\] .rel.* +REL. +0+ 0+.* 0000.. 0. +I +.+ +1 +4
 # MIPS targets put .rela.text here.
 #...
- +\[ .\] .* +PROGBITS +00000000 0000(3c|40|48|50) 0000(04|10) 00 +WA +0 +0 +(.|..)
- +\[ .\] .* +NOBITS +00000000 0000(40|44|4c|60) 000000 00 +WA +0 +0 +(.|..)
+ +\[ .\] .* +PROGBITS +00000000 0000(3c|40|44|48|50) 0000(04|10) 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.
 # v850 targets put .call_table_data and .call_table_text here.
 #...
diff --git a/binutils/testsuite/binutils-all/readelf.ss b/binutils/testsuite/binutils-all/readelf.ss
index e9ab3ef..acc6d93 100644
--- a/binutils/testsuite/binutils-all/readelf.ss
+++ b/binutils/testsuite/binutils-all/readelf.ss
@@ -6,15 +6,15 @@ Symbol table '.symtab' contains .* entries:
  +2: 00000000 +0 +SECTION +LOCAL +DEFAULT +[34] 
  +3: 00000000 +0 +SECTION +LOCAL +DEFAULT +[45] 
  +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
 # v850 targets include extra SECTION symbols here for the .call_table_data
 # and .call_table_text sections.
 #...
- +.: 00000000 +0 +NOTYPE +GLOBAL +DEFAULT +1 text_symbol
- +..: 00000000 +0 +NOTYPE +GLOBAL +DEFAULT +UND external_symbol
- +..: 00000000 +0 +NOTYPE +GLOBAL +DEFAULT +[34] data_symbol
- +..: 00000004 +4 +(COMMON|OBJECT) +GLOBAL +DEFAULT +(COM|ANSI_COM) common_symbol
-# The MSP430 adds special crt0 symbols here.
+ +[0-9]+: 00000000 +0 +NOTYPE +GLOBAL +DEFAULT +1 text_symbol
+ +[0-9]+: 00000000 +0 +NOTYPE +GLOBAL +DEFAULT +UND external_symbol
+ +[0-9]+: 00000000 +0 +NOTYPE +GLOBAL +DEFAULT +[34] data_symbol
+ +[0-9]+: 00000004 +4 +(COMMON|OBJECT) +GLOBAL +DEFAULT +(COM|ANSI_COM) common_symbol
 #...
diff --git a/binutils/testsuite/binutils-all/readelf.ss-64 b/binutils/testsuite/binutils-all/readelf.ss-64
index b67bfda..bd10cab 100644
--- a/binutils/testsuite/binutils-all/readelf.ss-64
+++ b/binutils/testsuite/binutils-all/readelf.ss-64
@@ -15,3 +15,4 @@ Symbol table '.symtab' contains .* entries:
  +.: 0000000000000000 +0 +NOTYPE +GLOBAL +DEFAULT +UND external_symbol
  +.: 0000000000000000 +0 +NOTYPE +GLOBAL +DEFAULT +3 data_symbol
  +[0-9]+: 0000000000000004 +4 +(COMMON|OBJECT) +GLOBAL +DEFAULT +COM common_symbol
+#pass
diff --git a/binutils/testsuite/binutils-all/readelf.ss-mips b/binutils/testsuite/binutils-all/readelf.ss-mips
index 01d3df1..9f4cfa5 100644
--- a/binutils/testsuite/binutils-all/readelf.ss-mips
+++ b/binutils/testsuite/binutils-all/readelf.ss-mips
@@ -1,5 +1,5 @@
 
-Symbol table '.symtab' contains 14 entries:
+Symbol table '.symtab' contains 16 entries:
  +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
  +0: 00000000 +0 +NOTYPE +LOCAL +DEFAULT +UND 
  +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
  +12: 00000000 +0 +NOTYPE +LOCAL +DEFAULT +. static_data_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
diff --git a/binutils/testsuite/binutils-all/readelf.ss-tmips b/binutils/testsuite/binutils-all/readelf.ss-tmips
index c59f753..d22fc08 100644
--- a/binutils/testsuite/binutils-all/readelf.ss-tmips
+++ b/binutils/testsuite/binutils-all/readelf.ss-tmips
@@ -1,5 +1,5 @@
 
-Symbol table '.symtab' contains 14 entries:
+Symbol table '.symtab' contains 16 entries:
  +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
  +0: 00000000 +0 +NOTYPE +LOCAL +DEFAULT +UND 
  +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
  +12: 00000000 +0 +OBJECT +GLOBAL +DEFAULT +3 data_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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]