From patchwork Fri Mar 8 18:08:44 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: 86991 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 9DE06385E00B for ; Fri, 8 Mar 2024 18:09:31 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by sourceware.org (Postfix) with ESMTPS id 5B14B3858D33 for ; Fri, 8 Mar 2024 18:08:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5B14B3858D33 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 5B14B3858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f31 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709921339; cv=none; b=PD4M9Tf+tERwM6DjvnH0MFojxeRBvNqgwJmS4iKpgVyvAM2Zj1zYfPgD6FxMPJ5Dh0btj8koNoGWksFi//aN9cGa1ipP7x9O2cwx+18AETr0f0M4nCT3IkdaUuyV4bY3cgaiZyc+vZZr3Z9YCEDyK+M9VDfLD4LuUnvjDB8lZUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709921339; c=relaxed/simple; bh=8AF1d4u6xapP2Ci7+VXFVvTYGwqSHdPy2D2tKZSr600=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=FxkxZNZrXV84gLqPqxywfwcWcdPFymFYOjEJskww5NGwAWXr8+pvbdOaeaRiIeEVPN9yOSPKmuzmvhJdrMEYNnjk4ryDsJgIXwrdix2xKy2rO5Uw0fjYdp2MrMLpIsN2/Wd4yWGLSWPWFBeYZLTCrgJsz8v/XlVtIRFHoXEw7uw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf31.google.com with SMTP id 6a1803df08f44-690ae5ce241so8076846d6.2 for ; Fri, 08 Mar 2024 10:08:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709921335; x=1710526135; 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=ruyaz+/V8edEwHZteuL6DlZ9z7O4wBic0joIMBbfsPs=; b=RvFqDmmkrqopSVYh2xZQbU60YoQHz6eujmQB9+vjUKwDCSXyTuI4vG5S6uSIqvriz/ bqXCL2ucV+37GiEQWplz5Vxy3RRO8JqrAYWCEm+oZ1ueNrUCFegCOmEUzR68IhXC1yP6 zSJLYpObzhYdee4jTwRfotnQrTKr03N3uT4nEFwDllvR6UWdvpwswhESzm2synrjjDZN eT2u22+5Z2oOIDFRK4dYGM/sI0zNYpB/rxtZyDeDbnAKZkdy9pG7YpfIXuy2yrHUMtWq M/l1Ck0TnxtO4a7nWwB1Y6wi88UjyhIQX2gFVVfiTEeSNgsiMyl4X0FGBRuiTbr0W6lH Bsqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709921335; x=1710526135; 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=ruyaz+/V8edEwHZteuL6DlZ9z7O4wBic0joIMBbfsPs=; b=UwWIWpP++gIzOld22xesB9gkH3Jcy0/oRg37dBDsPERle0jAq9H6U48uCrP2curmYX BFmS2bAPBDupgNbHGpItoOxJSV/anpKmHJ0Fa4zXEo5xKl5agMbhaJeydFdWTm38uxrg Bpy0a1PqEiiIgqAvCmFauM1azgIvGZy3Fdta4bNxK6KVSTO6Lxil+7BHA3BdhzTRYMF0 or2bct0UTkyAgIZrDwQNZVDYhzJ2aSEsfP5K9NQDC+baU/z+7utlvjO98hrKA/XVw/xR Cgas8tlAjhbPd8uJRIEnshi55Qrj/svHlD76fqDd/AXyXtFpOXIwKkG2ehsN3n/kUQPY 8GcQ== X-Gm-Message-State: AOJu0YzyjRVmjBq3HrCZ4i7b0mGUUGB/yIUJ+8mgQQtMoSrboq7fHJA0 lBY03ao6+Ec+kOUN7Htke46uL+2VHxB8Asxe7ckhAAOsGA57sVbpniS+0hkv1YBwgtHUZF8hNOP H0w5U++c+iQYc8qpsydV9CRgxDFqjwoZsKF0RmQ== X-Google-Smtp-Source: AGHT+IEMyDanpenhhs3VjQ8C5CCKQD9a0YGUePFPLyLTLwJ7ZYYOKQ6RMZ09LOqRMnjdK0qfm98S3eM6z4K2OtyFSVg= X-Received: by 2002:a0c:ca8f:0:b0:690:ab51:beca with SMTP id a15-20020a0cca8f000000b00690ab51becamr5176520qvk.49.1709921335545; Fri, 08 Mar 2024 10:08:55 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: =?utf-8?b?TWlrb8WCYWogUGlyw7Nn?= Date: Fri, 8 Mar 2024 19:08:44 +0100 Message-ID: Subject: [RFC][PATCH v2 1/2] libiberty: implement option to drop templates during demangling To: binutils@sourceware.org X-Spam-Status: No, score=-8.5 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 This patch introduces option that when given to cplus_demangle, drops template from a symbol during demangling (in printing stage) d_append_char (dpi, '<'); @@ -5333,6 +5336,9 @@ d_print_comp_inner (struct d_print_info *dpi, int options, } case DEMANGLE_COMPONENT_TEMPLATE_PARAM: + if ((options & DMGL_TMPL_DROP) != 0) + break; + if (dpi->lambda_tpl_parms > dc->u.s_number.number + 1) { const struct demangle_component *a @@ -5492,6 +5498,23 @@ d_print_comp_inner (struct d_print_info *dpi, int options, return; case DEMANGLE_COMPONENT_SUB_STD: + /* Special-case substitions are stored wholly as a string. They need + to be stripped of templates manually */ + if ((options & DMGL_TMPL_DROP) != 0) + { + char *template_begin = strchr(dc->u.s_string.string, '<'); + if (template_begin != NULL) + { + d_append_buffer(dpi, dc->u.s_string.string, (template_begin - dc->u.s_string.string)); + + char *template_end= strrchr(dc->u.s_string.string, '>'); + if (template_end == NULL) + return; + + d_append_buffer(dpi, template_end, dc->u.s_string.len - (template_end - dc->u.s_string.string) - 1); + return; + } + } d_append_buffer (dpi, dc->u.s_string.string, dc->u.s_string.len); return; 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/include/demangle.h b/include/demangle.h index 49b84d4de88..89a3b64e436 100644 --- a/include/demangle.h +++ b/include/demangle.h @@ -51,6 +51,8 @@ extern "C" { types, even if present. It applies only to the toplevel function type. */ +#define DMGL_TMPL_DROP (1 << 7) /* Supress printing of templates, even + if present. */ #define DMGL_AUTO (1 << 8) #define DMGL_GNU_V3 (1 << 14) diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c index fc2cf64e6e0..ad873ed6177 100644 --- a/libiberty/cp-demangle.c +++ b/libiberty/cp-demangle.c @@ -5315,6 +5315,9 @@ d_print_comp_inner (struct d_print_info *dpi, int options, else { d_print_comp (dpi, options, dcl); + if ((options & DMGL_TMPL_DROP) != 0) + return; + if (d_last_char (dpi) == '<') d_append_char (dpi, ' '); 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