Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masatake/cf2201b4b07a0d3f2d9cee6e1315cff3 to your computer and use it in GitHub Desktop.
Save masatake/cf2201b4b07a0d3f2d9cee6e1315cff3 to your computer and use it in GitHub Desktop.
diff --git a/binutils/objdump.c b/binutils/objdump.c
index 9c3bce8b75..ce6bf7b920 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 *label;
/* 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 * label;
};
/* Architecture to disassemble for, or default if NULL. */
@@ -313,8 +315,8 @@ 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-all", no_argument, NULL, 'D'},
+ {"disassemble", optional_argument, NULL, 'd'},
+ {"disassemble-all", optional_argument, NULL, 'D'},
{"disassembler-options", required_argument, NULL, 'M'},
{"disassemble-zeroes", no_argument, NULL, 'z'},
{"dynamic-reloc", no_argument, NULL, 'R'},
@@ -2253,6 +2255,7 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
asymbol *nextsym;
bfd_vma nextstop_offset;
bfd_boolean insns;
+ bfd_boolean do_print = FALSE;
addr = section->vma + addr_offset;
addr = ((addr & ((sign_adjust << 1) - 1)) ^ sign_adjust) - sign_adjust;
@@ -2278,7 +2281,12 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
pinfo->symtab_pos = -1;
}
- if (! prefix_addresses)
+ {
+ const char *l = (sym && paux->label)? bfd_asymbol_name (sym): NULL;
+ do_print = (paux->label == NULL || (l && streq(l, paux->label)));
+ }
+
+ if (! prefix_addresses && do_print)
{
pinfo->fprintf_func (pinfo->stream, "\n");
objdump_print_addr_with_sym (abfd, section, sym, addr,
@@ -2339,9 +2347,10 @@ 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);
addr_offset = nextstop_offset;
sym = nextsym;
@@ -2394,6 +2403,7 @@ disassemble_data (bfd *abfd)
aux.dynrelbuf = NULL;
aux.dynrelcount = 0;
aux.reloc = NULL;
+ aux.label = label;
disasm_info.print_address_func = objdump_print_address;
disasm_info.symbol_at_address_func = objdump_symbol_at_address;
@@ -3995,6 +4005,7 @@ main (int argc, char **argv)
case 'd':
disassemble = TRUE;
seenflag = TRUE;
+ label = optarg;
break;
case 'z':
disassemble_zeroes = TRUE;
@@ -4003,6 +4014,7 @@ main (int argc, char **argv)
disassemble = TRUE;
disassemble_all = TRUE;
seenflag = TRUE;
+ label = optarg;
break;
case 'S':
disassemble = TRUE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment