From: Alan Modra <amodra@gmail.com>
To: "Mikołaj Piróg" <mikolajpirog@gmail.com>
Cc: binutils@sourceware.org
Subject: Re: [PATCH] objdump: Implement short name search
Date: Thu, 29 Feb 2024 12:33:29 +1030 [thread overview]
Message-ID: <Zd/l8TIa17xD1c/l@squeak.grove.modra.org> (raw)
In-Reply-To: <CAOscM-s9V4+7xqy2JLOAh-ABrWnMLKpQ=txZgimP5LFc-xQaFA@mail.gmail.com>
On Wed, Feb 28, 2024 at 06:46:18PM +0100, Mikołaj Piróg wrote:
> 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.
I like the idea. It sounds useful. Hmm, I wonder could you provide
this functionality without a new option. ie. When demamgling
automatically detect that the user has specified a function name
without args.
If you do need a new option then the patch needs changes to
doc/binutils.texi, describing what the new objdump option does.
> 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)
I think this should be moved a little lower, so that loop_until is
function_sym, but I haven't checked fully that this won't exit the
loop prematurely. Obviously you want to disassemble the entire
function, but also continue looking for another occurrence of the same
function name (with a different signature).
> @@ -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;
> }
--
Alan Modra
Australia Development Lab, IBM
next prev parent reply other threads:[~2024-02-29 2:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-28 17:46 Mikołaj Piróg
2024-02-29 2:03 ` Alan Modra [this message]
2024-02-29 21:29 ` Mikołaj Piróg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zd/l8TIa17xD1c/l@squeak.grove.modra.org \
--to=amodra@gmail.com \
--cc=binutils@sourceware.org \
--cc=mikolajpirog@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).