From patchwork Wed Feb 28 17:46:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?TWlrb8WCYWogUGlyw7Nn?= X-Patchwork-Id: 207935 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp3505087dyb; Wed, 28 Feb 2024 09:46:45 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVvfzPRoJ0u79v++vMb7EWjl3ZQ0wUduei7w1F/apUvqsDuxAPlVGAYxPKKJpQVs2wBo7BdK/h0EIwFEvYAcCIJ3OXG9g== X-Google-Smtp-Source: AGHT+IEZPsEDxxzVitxHT1fUhDLaER4MAvXb+BcLGfXcduu5hp6oZUVyY5EmpJcfms64E4gNKQ0R X-Received: by 2002:a05:620a:3727:b0:787:b5e6:ff4f with SMTP id de39-20020a05620a372700b00787b5e6ff4fmr4903172qkb.36.1709142405128; Wed, 28 Feb 2024 09:46:45 -0800 (PST) Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id q23-20020ac84517000000b0042e7b41a92asi8429004qtn.622.2024.02.28.09.46.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 09:46:45 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=POfSCsGo; arc=fail (body hash mismatch); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C577B3858C39 for ; Wed, 28 Feb 2024 17:46:44 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-qv1-xf35.google.com (mail-qv1-xf35.google.com [IPv6:2607:f8b0:4864:20::f35]) by sourceware.org (Postfix) with ESMTPS id C4C6E3858D39 for ; Wed, 28 Feb 2024 17:46:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C4C6E3858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C4C6E3858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709142397; cv=none; b=VXuVYryjdslEjS7NXSxDr8vWtTAc/XbZXqLG+Z1r6jJwTUVjMLEVQfOEivcftiTNJE/VFrlbjxw+AfDqFbKtH9hYL3XUruZrlYWbe6IISI2KLfxZqGzYKXVg+GIOhI10gblLQEz1yKuvuI2s5+9y75Mr/1wOLY2c46bHfXMqrFM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709142397; c=relaxed/simple; bh=T3J8UetqEKAgBpK6vPPbWaCA4xMjkaPpScISZtR8hj4=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=pfUMgxReFIr3UmYEe0dlK10U18NW0+Dj98Ke1nBs+eYYaDo4jafLTVaQCRAA7bRn6oiZsiuRbct4ATVkS0J2v7o57eWh/+hHKs+ZOFTIOAhUOWmtuJtjLzblTpsNRlaoTyra33rGb4r8fxs0GpPnEc8VI5rAmc/YL0YgbR0lQ8Y= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf35.google.com with SMTP id 6a1803df08f44-68ee2c0a237so8219586d6.1 for ; Wed, 28 Feb 2024 09:46:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709142395; x=1709747195; darn=sourceware.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=7IIHsW85CQLZ8dMjFkLSQPna9436MkkGZFssUUUUOBA=; b=POfSCsGoDbom5PXtXjd7KtAGXwUKlQmIqAmyt4Vm3edQKGhIEJfHmprZvVRG/oL+Mg ruBSHH8RW2VZhwhUkaJy9VWctY7WO6Gle2rysy4eFpc3yM3bPjLCneCkwLzqsIlbY8do ScAaGveND1j74jgGJ0yRxixIuYovghobamqILRzDmswHNIK3YT+E/E4ElVXIhPlkYhz1 cAWP6H9W7YXB0Y8XGHAmCeqs9C+Maqam8x9OAvl0NgQzY0b2t+35+kHiE/brqrwk1YsW /GuJpGxWV+5DrC/mTjixKY2WfkENEgbEJbprGt1NmpOg5M/j48PemihfOj5dkhUdqI5R dcpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709142395; x=1709747195; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=7IIHsW85CQLZ8dMjFkLSQPna9436MkkGZFssUUUUOBA=; b=hiyYMw/dbDY8+pzeHeFXXmBF+Bl/MQOJFVjaxjjsmoX0kHJbH2+2MqkLRKshPvLRwg Qg274Yn1t427o6QgDkEyw9FOqfGmjd9xgsRz0Vl24JoFciINOU16q9DgvL9BifSoITY6 ZPxyQbLah17gs9e9dngaLqJxr0OghnBi/veriYF9SB5fOZ0J8i3nsoR8aBGx1TtFxGjz oMrv2ghgVNCL0RIBjGMUkblo5y3j0F4KxR5p1diyO2x9qPq3HDG4QhOQ34/dwDoyOqLt fkmNeZ2LV4ac7aSCXwRROZqdekeXzjWbUCv1lMwJklQsGjFuAMtyx6ookRLQBKNbLcYG 6Vag== X-Gm-Message-State: AOJu0Yz0D4782FgWMq1ltP7T2KGdjfo08eiHff742hXm5j02YBfXyk0G qydrHzIacTF4fOtXaWg4SQLIIAc3iVNqkyqWAW0nZ5OOZhofNhuYfA/3PsrtGSQvtbGg4/U0pi/ zIgRVgGZKvotNLpT0iLrlY54bygZLPB8Qfja5wg== X-Received: by 2002:a05:6214:438a:b0:690:2069:d413 with SMTP id oh10-20020a056214438a00b006902069d413mr4624140qvb.6.1709142390015; Wed, 28 Feb 2024 09:46:30 -0800 (PST) MIME-Version: 1.0 From: =?utf-8?b?TWlrb8WCYWogUGlyw7Nn?= Date: Wed, 28 Feb 2024 18:46:18 +0100 Message-ID: Subject: [PATCH] objdump: Implement short name search To: binutils@sourceware.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, HTML_MESSAGE, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792165706491779386 X-GMAIL-MSGID: 1792165706491779386 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. 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= Display assembler contents from \n")); + fprintf (stream, _("\ + --short-name-search When searching for , 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; }