]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Enhance objdump's --disassemble switch so that it can now take an optional parameter...
authorMasatake Yamato <yamato@redhat.com>
Wed, 7 Nov 2018 18:07:36 +0000 (18:07 +0000)
committerNick Clifton <nickc@redhat.com>
Wed, 7 Nov 2018 18:07:36 +0000 (18:07 +0000)
* 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.

12 files changed:
binutils/ChangeLog
binutils/NEWS
binutils/doc/binutils.texi
binutils/objdump.c
binutils/testsuite/binutils-all/bintest.s
binutils/testsuite/binutils-all/objcopy.exp
binutils/testsuite/binutils-all/objdump.exp
binutils/testsuite/binutils-all/readelf.s
binutils/testsuite/binutils-all/readelf.ss
binutils/testsuite/binutils-all/readelf.ss-64
binutils/testsuite/binutils-all/readelf.ss-mips
binutils/testsuite/binutils-all/readelf.ss-tmips

index e93f028edf85e64fe9591f0e392d92bc06df11bd..2b76d8cc0f4f1f87b20528254e12a955791f4f9c 100644 (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>
 
        * po/pt.po: Updated Portuguese translation.
index de70c3a23cbf7123a6cdd6aa254545c3563b8b6e..a3ee86ef7f513a6be433ad57a2b4b5b4ae4cce58 100644 (file)
@@ -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
index 6cfda45b2736eb5e806c03ff90db2fb7aabb95bb..9954adf484da3096d68ccafc0962667d03c5d3dc 100644 (file)
@@ -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
index 9c3bce8b75381c6620e0f5fc98a4227c44192495..e3b8d7fd024ba06ccc94ee4aecfac77666830d3d 100644 (file)
@@ -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;
index 9e006502219df8a8fd691a08cf18d94f5ed8b1c1..dcf742f7dcf77d86cad281bcc1f1fbb6e6f5307f 100644 (file)
@@ -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
+       
index 3676f762131345299253536b26608ee0ca42c41c..762bd0a9e75e75b50f87f28cd3512bff5c1edaff 100644 (file)
@@ -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*"
index effc3dd6a1ca9a6fd127bdff86e62230fa08291a..b1dea8dd74955576d574c6d332f047fbdf38644c 100644 (file)
@@ -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.
index 5aae0cec9cf3effd6f0e404b26043bc3bcce6a17..6ae4dc756b974698b472665bf062d0dd46724e31 100644 (file)
@@ -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.
 #...
index e9ab3ef38a067e583642e9e183badb920361d455..acc6d9390c58302693a92181e3acd9352e850943 100644 (file)
@@ -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
 #...
index b67bfdaf0e376d5c43da35b7596e2e50b5504822..bd10cabef35859fa881df896b176815116828f66 100644 (file)
@@ -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
index 01d3df19c39e2976ac7d8b89ba7dba21e0c3bf13..9f4cfa52de11809696773c0bdc06e4714c0f75a9 100644 (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
  +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
index c59f753191a5356a18b0132aa054e7e72a975003..d22fc083d85496e2118bf38962455fb0cbb04a81 100644 (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
  +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