public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] objdump: Implement short name search
@ 2024-02-28 17:46 Mikołaj Piróg
  2024-02-29  2:03 ` Alan Modra
  0 siblings, 1 reply; 3+ messages in thread
From: Mikołaj Piróg @ 2024-02-28 17:46 UTC (permalink / raw)
  To: binutils


[-- Attachment #1.1: Type: text/plain, Size: 883 bytes --]

This patch introduces the "--short-name-search" option to objdump. When
this option is used like so: objdump --disassemble=ns::foo
--short-name-search -C file The objdump will then output disassembled
output for functions that match the name "ns::foo". The current behaviour
of objdump in this context is to match the whole function signature, not
only the name (like so: "ns::foo(int, char const*)"). Option
"--short-name-search" works only in conjunction with demangling ("-C"). The
motivation behind this change is to ease a process of a quick disassembly
of a given function in a binary, since providing the whole function
signature isn't comfortable. I am not particularly happy with the name for
this option, but I couldn't come up with anything better. If the
functionality provided by this patch is desired in objdump, I am happy to
listen for suggestions for a better name.

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2984 bytes --]

diff --git a/binutils/objdump.c b/binutils/objdump.c
index 7beb221cb2f..a013eee3c12 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -138,6 +138,7 @@ static bool extended_color_output = false; /* --visualize-jumps=extended-color.
 static int process_links = false;       /* --process-links.  */
 static int show_all_symbols;            /* --show-all-symbols.  */
 static bool decompressed_dumps = false; /* -Z, --decompress.  */
+static bool short_name_search = false; /* --short-name-search */
 
 static enum color_selection
   {
@@ -272,6 +273,8 @@ usage (FILE *stream, int status)
   -D, --disassemble-all    Display assembler contents of all sections\n"));
   fprintf (stream, _("\
       --disassemble=<sym>  Display assembler contents from <sym>\n"));
+  fprintf (stream, _("\
+      --short-name-search  When searching for <sym>, compare functions names, not signatures\n"));
   fprintf (stream, _("\
   -S, --source             Intermix source code with disassembly\n"));
   fprintf (stream, _("\
@@ -488,7 +491,8 @@ enum option_values
 #endif
     OPTION_SFRAME,
     OPTION_VISUALIZE_JUMPS,
-    OPTION_DISASSEMBLER_COLOR
+    OPTION_DISASSEMBLER_COLOR,
+    OPTION_SYMBOL_SHORT_NAME_SEARCH
   };
 
 static struct option long_options[]=
@@ -543,6 +547,7 @@ static struct option long_options[]=
   {"section", required_argument, NULL, 'j'},
   {"section-headers", no_argument, NULL, 'h'},
   {"sframe", optional_argument, NULL, OPTION_SFRAME},
+  {"short-name-search", no_argument, NULL, OPTION_SYMBOL_SHORT_NAME_SEARCH},
   {"show-all-symbols", no_argument, &show_all_symbols, 1},
   {"show-raw-insn", no_argument, &show_raw_insn, 1},
   {"source", no_argument, NULL, 'S'},
@@ -3905,7 +3910,11 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
 	      if (do_demangle && name[0] != '\0')
 		{
 		  /* Demangle the name.  */
-		  alloc = bfd_demangle (abfd, name, demangle_flags);
+		  if (short_name_search)
+		    alloc = bfd_demangle (abfd, name, DMGL_NO_OPTS);
+		  else
+		    alloc = bfd_demangle (abfd, name, demangle_flags);
+
 		  if (alloc != NULL)
 		    name = alloc;
 		}
@@ -3923,7 +3932,7 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
 		   (*rel_pp)->address - rel_offset < sym_offset)
 			  ++rel_pp;
 
-		  if (sym->flags & BSF_FUNCTION)
+		  if (sym->flags & BSF_FUNCTION && !(short_name_search && do_demangle))
 		    {
 		      if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
 			  && ((elf_symbol_type *) sym)->internal_elf_sym.st_size > 0)
@@ -6200,6 +6209,9 @@ main (int argc, char **argv)
 	    dump_sframe_section_name = xstrdup (optarg);
 	  seenflag = true;
 	  break;
+	case OPTION_SYMBOL_SHORT_NAME_SEARCH:
+	  short_name_search = true;
+	  break;
 	case 'G':
 	  dump_stab_section_info = true;
 	  seenflag = true;
@@ -6287,6 +6299,5 @@ main (int argc, char **argv)
   free (dump_ctf_section_name);
   free (dump_ctf_parent_name);
   free ((void *) source_comment);
-
   return exit_status;
 }

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-29 21:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-28 17:46 [PATCH] objdump: Implement short name search Mikołaj Piróg
2024-02-29  2:03 ` Alan Modra
2024-02-29 21:29   ` Mikołaj Piróg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).