From patchwork Fri Mar 8 18:13:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TWlrb8WCYWogUGlyw7Nn?= X-Patchwork-Id: 86992 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 83458385E007 for ; Fri, 8 Mar 2024 18:14:24 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) by sourceware.org (Postfix) with ESMTPS id 80DE43858D33 for ; Fri, 8 Mar 2024 18:13:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 80DE43858D33 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 80DE43858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f30 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709921635; cv=none; b=DrCQZEIm7ZQGoM5RQyRRDNxIv9YLUFMwU7EqG6fdrEhV7pkT9VKf/JGRr9zlaYn0DlZGRxhj95lxhr9VsXXgNUIJ/Nr+hWLILM+FNuzA/FZuJkU4ivBeQ0FMCFXQchoAb3donEbm3h5fNhwai/cZv2HSyVatpqQ45b6mbuq208k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709921635; c=relaxed/simple; bh=A3b6GJJHkqqfn6UDHnf32T4g9Yr8nkpsp+3MHxVpGlE=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=RRTAg5Ld+PVfRL8R4IJJ2jczwQmAXE+U7Mn929vS3QgivLt8SgdV64N+hlUTMFehVExES//6oIu8f4oQLcRxa61kNHpqX2UWDwJ6lY+J3loM7gd3spjDs/CBxQqBmdWV84Z5ioXCUp/7+TeV3DZ8016nQOIVB+nJUG/Qg99/S2E= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf30.google.com with SMTP id 6a1803df08f44-68f571be9ddso16906466d6.0 for ; Fri, 08 Mar 2024 10:13:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709921632; x=1710526432; darn=sourceware.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=w9fuLgiGuk4ftIo46D9basZSdDG1QV2qhYcJN7Mt63g=; b=DAPIIggWPsNayyw5ggjTEM0Y+le+m377B0f+Lu29Y7+zP3BqrJCS6QKqhHu/3aINW6 zKNHkns071p52J7KQk2Wh8fzs8xIX3LQYgJghLExUlgz1lhShy1TlqnzYETLSqevPMhk YO1QVtiDI0N3eWC14eQIT8VzmeioRc2fugng0hV8lEZukQLWb40aHQbFGvuNgC5RQxV9 tjJxO1kFCsp2J3YOQi6gRg1zRLJ0icPskAGQt+HRPHt9I+h7GHvh8Y1VZQpTUYZ+fFsW 8eJJLwiZJO309zLWjC6Zj0sHqC+RxFsGRZvulFtxiC6JJQDGZ9hU3Df7GI/UggLbC/wC Pm9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709921632; x=1710526432; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=w9fuLgiGuk4ftIo46D9basZSdDG1QV2qhYcJN7Mt63g=; b=Jed78C5fJfLera5BEeIhCIaGk4liP0YgLK8KjnWH7GSOWxfGlLOFs6yx4WUt9adn5P KLAhR9JkhtOcm5plJ7tUyS/el9syKY5YhOcbwvcsBEBiibj1VdGrlVc8fpY9UQsjnVCL t4wT9w1ijs+wzx3c5MGs2pTJdi8OZkLisfzUiUrgEeMETIQC4adWybKuwvYNLvcKXSlU nXIHa5ESCyTBsMD5ZEBeOt+nXx8PHKT6GEW6koimuFdWbCYPACzd6AIeUgKEuajv2s3l t9kl3JF4hsLAKVHHptCb3Auz7qzVtrbFZo0RulTsvEba9bGBURfCykLnwcDX2ky3KW3P S91w== X-Gm-Message-State: AOJu0YxpECtX3CIDLSm525v21WBWB8J1KZnQGDDufxGxZ8SaHEq8RI8V PIMcV1waX8qpJB7bJ44ja8Z18HeY1HJHl+TsRYtBya8xFXzPfNlYKTlChRw0V7R0Gq5RJTB7KL7 ACcfx3ldsqYU5ervl26wxabtXTTBaT43DpPnE4A== X-Google-Smtp-Source: AGHT+IG8r9DbSEKCbAgGLSEVqjwIIjTFH+iYS9IDH2Hhi25JbVO3l/aW6p4wqExMiMxe7nW+F+iz3D6rNm+ycSEtNyg= X-Received: by 2002:a05:6214:a94:b0:690:b225:3df4 with SMTP id ev20-20020a0562140a9400b00690b2253df4mr3433649qvb.14.1709921631818; Fri, 08 Mar 2024 10:13:51 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: =?utf-8?b?TWlrb8WCYWogUGlyw7Nn?= Date: Fri, 8 Mar 2024 19:13:41 +0100 Message-ID: Subject: [RFC][PATCH v2 2/2] objdump: Implement short name search To: binutils@sourceware.org X-Spam-Status: No, score=-8.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, HTML_MESSAGE, 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+patchwork=sourceware.org@sourceware.org Implement short name search. When objdump is used like so: objdump --disassemble=sym -C file It will attempt to decide if "sym" is a short name or a regular name. If it is a short name, it will search for symbols matching given name. { @@ -3905,7 +3908,10 @@ 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_TMPL_DROP); + else + alloc = bfd_demangle (abfd, name, demangle_flags); if (alloc != NULL) name = alloc; } @@ -3923,7 +3929,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) @@ -5879,7 +5885,18 @@ display_file (char *filename, char *target, bool last_file) else bfd_close_all_done (file); } - + +/* Attempts to determine if a given name represents a short name of a symbol. + Short name of a symbol is name without a signature and template qualification. */ +static bool is_short_name(const char *name) { + char *begin = strchr(name, '('); + char *end = strchr(name, ')'); + if (end - begin <= 1) + return true; + + return false; +} + int main (int argc, char **argv) { @@ -6255,6 +6272,9 @@ main (int argc, char **argv) } } + if (disasm_sym != NULL && do_demangle) + short_name_search = is_short_name(disasm_sym); + if (disassembler_color == on_if_terminal_output) disassembler_color = isatty (1) ? on : off; pt., 8 mar 2024 o 19:04 Mikołaj Piróg napisał(a): > This patch refines my previous attempt of implementing short name search ( > https://sourceware.org/pipermail/binutils/2024-February/132713.html). The > idea is to enable such usage: > > objdump --disassemble=ns::foo -C file > > The objdump will then output all symbols matching the name "ns::foo". > I introduced new demangling option to remove template qualification, so for > example, "--dissassemble=std::vector::push_back" will match all instances > of push_back in the file. > > The motivation behind this usage is to ease a process of a quick > disassembly of a binary in search for a particular function. Providing a > function signature isn't comfortable. > > > > > > > diff --git a/binutils/objdump.c b/binutils/objdump.c index 7beb221cb2f..21c4b86bf3d 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -138,6 +138,9 @@ 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; /* True when demangling is used, disasm_sym + is given and appears to be + a short name */ static enum color_selection