From patchwork Thu Oct 17 22:47:13 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: 35103 Received: (qmail 101829 invoked by alias); 17 Oct 2019 22:47:17 -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 101820 invoked by uid 89); 17 Oct 2019 22:47:17 -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=2019-10-02, 20191002 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; Thu, 17 Oct 2019 22:47:16 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id AE1B620806; Thu, 17 Oct 2019 18:47:14 -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 8B7BA206CA; Thu, 17 Oct 2019 18:47:13 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 520E120AF6; Thu, 17 Oct 2019 18:47:13 -0400 (EDT) X-Gerrit-PatchSet: 1 Date: Thu, 17 Oct 2019 18:47:13 -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] Don't make an extra copy + allocation of the demangled name X-Gerrit-Change-Id: Ie6ad50e1e1e73509f55d756f0a437897bb93e3b0 X-Gerrit-Change-Number: 132 X-Gerrit-ChangeURL: X-Gerrit-Commit: 8dec8d2449194e5cc3980a652b0bb43a6bd69e0d 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 Christian Biesinger has uploaded a new change for review. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/132 ...................................................................... Don't make an extra copy + allocation of the demangled name We can just keep around the malloc()-ed name we got from bfd and free it later. gdb/ChangeLog: 2019-10-02 Christian Biesinger * symtab.c (struct demangled_name_entry): Change demangled name to a char*, now that we don't allocate it as part of the struct anymore. (free_demangled_name_entry): New function. (create_demangled_names_hash): Pass free function to htab_create_alloc. (symbol_set_names): No longer obstack allocate + copy the demangled name, just store the allocated name from bfd. Change-Id: Ie6ad50e1e1e73509f55d756f0a437897bb93e3b0 --- M gdb/symtab.c 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index 8a551f1..a185f92 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -715,7 +715,7 @@ { const char *mangled; ENUM_BITFIELD(language) language : LANGUAGE_BITS; - char demangled[1]; + char* demangled; }; /* Hash function for the demangled name hash. */ @@ -742,6 +742,15 @@ return strcmp (da->mangled, db->mangled) == 0; } +static void +free_demangled_name_entry (void *data) +{ + struct demangled_name_entry *e + = (struct demangled_name_entry *) data; + + xfree (e->demangled); +} + /* Create the hash table used for demangled names. Each hash entry is a pair of strings; one for the mangled name and one for the demangled name. The entry is hashed via just the mangled name. */ @@ -756,7 +765,7 @@ per_bfd->demangled_names_hash.reset (htab_create_alloc (256, hash_demangled_name_entry, eq_demangled_name_entry, - NULL, xcalloc, xfree)); + free_demangled_name_entry, xcalloc, xfree)); } /* Try to determine the demangled name for a symbol, based on the @@ -869,8 +878,6 @@ { char *demangled_name_ptr = symbol_find_demangled_name (gsymbol, linkage_name_copy); - gdb::unique_xmalloc_ptr demangled_name (demangled_name_ptr); - int demangled_len = demangled_name ? strlen (demangled_name.get ()) : 0; /* Suppose we have demangled_name==NULL, copy_name==0, and linkage_name_copy==linkage_name. In this case, we already have the @@ -886,39 +893,31 @@ *slot = ((struct demangled_name_entry *) obstack_alloc (&per_bfd->storage_obstack, - offsetof (struct demangled_name_entry, demangled) - + demangled_len + 1)); + sizeof (demangled_name_entry))); (*slot)->mangled = linkage_name; } else { - char *mangled_ptr; - /* If we must copy the mangled name, put it directly after - the demangled name so we can have a single + the struct so we can have a single allocation. */ *slot = ((struct demangled_name_entry *) obstack_alloc (&per_bfd->storage_obstack, - offsetof (struct demangled_name_entry, demangled) - + len + demangled_len + 2)); - mangled_ptr = &((*slot)->demangled[demangled_len + 1]); + sizeof (demangled_name_entry) + len + 1)); + char *mangled_ptr = reinterpret_cast (*slot + 1); strcpy (mangled_ptr, linkage_name_copy); (*slot)->mangled = mangled_ptr; } + (*slot)->demangled = demangled_name_ptr; (*slot)->language = gsymbol->language; - - if (demangled_name != NULL) - strcpy ((*slot)->demangled, demangled_name.get ()); - else - (*slot)->demangled[0] = '\0'; } else if (gsymbol->language == language_unknown || gsymbol->language == language_auto) gsymbol->language = (*slot)->language; gsymbol->name = (*slot)->mangled; - if ((*slot)->demangled[0] != '\0') + if ((*slot)->demangled != nullptr) symbol_set_demangled_name (gsymbol, (*slot)->demangled, &per_bfd->storage_obstack); else