From patchwork Tue Oct 22 22:30:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 35239 Received: (qmail 103725 invoked by alias); 22 Oct 2019 22:30:39 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 103367 invoked by uid 89); 22 Oct 2019 22:30:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 22 Oct 2019 22:30:29 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id 8CEF52041F; Tue, 22 Oct 2019 18:30:27 -0400 (EDT) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [IPv6:2620:52:3:1:5054:ff:fe06:16ca]) by mx1.osci.io (Postfix) with ESMTP id 3F0C020183; Tue, 22 Oct 2019 18:30:25 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 239E62192E; Tue, 22 Oct 2019 18:30:25 -0400 (EDT) X-Gerrit-PatchSet: 1 Date: Tue, 22 Oct 2019 18:30:25 -0400 From: "Christian Biesinger (Code Review)" To: gdb-patches@sourceware.org Cc: Christian Biesinger Message-ID: Auto-Submitted: auto-generated X-Gerrit-MessageType: newchange Subject: [review] Only make a nullterminated string if we need to X-Gerrit-Change-Id: I183302e1f51483ff6dff0fd5c3b0f32f0f04a5d2 X-Gerrit-Change-Number: 222 X-Gerrit-ChangeURL: X-Gerrit-Commit: 28611e1270b632a276dae660ba23ab57b8aa7873 References: Reply-To: cbiesinger@google.com, cbiesinger@google.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3 Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/222 ...................................................................... Only make a nullterminated string if we need to As of 7bb43059820c5febb4509b15202a93efde442bc6, we no longer need a nullterminated linkage_name to look up the entry in the hash table. So this patch makes it so we only make the copy if the entry was not found. gdb/ChangeLog: 2019-10-22 Christian Biesinger * symtab.c (symbol_set_names): Only make a nullterminated copy of linkage_name if the entry was not found and we need to demangle. Change-Id: I183302e1f51483ff6dff0fd5c3b0f32f0f04a5d2 --- M gdb/symtab.c 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index 0a87fec..787c4b6 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -829,8 +829,6 @@ struct objfile_per_bfd_storage *per_bfd) { struct demangled_name_entry **slot; - /* A 0-terminated copy of the linkage name. */ - const char *linkage_name_copy; if (gsymbol->language == language_ada) { @@ -855,20 +853,7 @@ if (per_bfd->demangled_names_hash == NULL) create_demangled_names_hash (per_bfd); - if (linkage_name[len] != '\0') - { - char *alloc_name; - - alloc_name = (char *) alloca (len + 1); - memcpy (alloc_name, linkage_name, len); - alloc_name[len] = '\0'; - - linkage_name_copy = alloc_name; - } - else - linkage_name_copy = linkage_name; - - struct demangled_name_entry entry (gdb::string_view (linkage_name_copy, len)); + struct demangled_name_entry entry (gdb::string_view (linkage_name, len)); slot = ((struct demangled_name_entry **) htab_find_slot (per_bfd->demangled_names_hash.get (), &entry, INSERT)); @@ -880,6 +865,21 @@ || (gsymbol->language == language_go && (*slot)->demangled[0] == '\0')) { + /* A 0-terminated copy of the linkage name. */ + const char *linkage_name_copy; + if (linkage_name[len] != '\0') + { + char *alloc_name; + + alloc_name = (char *) alloca (len + 1); + memcpy (alloc_name, linkage_name, len); + alloc_name[len] = '\0'; + + linkage_name_copy = alloc_name; + } + else + linkage_name_copy = linkage_name; + char *demangled_name_ptr = symbol_find_demangled_name (gsymbol, linkage_name_copy); gdb::unique_xmalloc_ptr demangled_name (demangled_name_ptr);