From patchwork Fri Jun 20 15:38:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 1596 Received: (qmail 25824 invoked by alias); 20 Jun 2014 15:39:15 -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 25797 invoked by uid 89); 20 Jun 2014 15:39:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL, BAYES_00, KAM_STOCKGEN, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 20 Jun 2014 15:39:03 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5KFd02l030421 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 20 Jun 2014 11:39:01 -0400 Received: from barimba.redhat.com (ovpn-113-103.phx2.redhat.com [10.3.113.103]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s5KFcxMA004765; Fri, 20 Jun 2014 11:39:00 -0400 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/2] lazily allocate demangled hash Date: Fri, 20 Jun 2014 09:38:57 -0600 Message-Id: <1403278737-29257-3-git-send-email-tromey@redhat.com> In-Reply-To: <1403278737-29257-1-git-send-email-tromey@redhat.com> References: <1403278737-29257-1-git-send-email-tromey@redhat.com> Currently, the minsym demangled hash table is always allocated in the per-BFD, even when the objfile holds no symbols with mangled names. This patch changes gdb to lazily allocate the demangled hash table. This saves a little memory for each such objfile. Built and regtested on x86-64 Fedora 20. 2014-06-20 Tom Tromey * minsyms.c (lookup_minimal_symbol, iterate_over_minimal_symbols): Handle case where demangled hash table is not allocated. (build_minimal_symbol_hash_tables): Lazily create demangled hash table. * objfiles.h (struct objfile_per_bfd_storage) : Change type. --- gdb/ChangeLog | 9 +++++++++ gdb/minsyms.c | 39 ++++++++++++++++++++++++++------------- gdb/objfiles.h | 5 +++-- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/gdb/minsyms.c b/gdb/minsyms.c index e59b534..c7e7dfa 100644 --- a/gdb/minsyms.c +++ b/gdb/minsyms.c @@ -208,6 +208,8 @@ lookup_minimal_symbol (const char *name, const char *sfile, /* Select hash list according to pass. */ if (pass == 1) msymbol = objfile->per_bfd->msymbol_hash[hash]; + else if (objfile->per_bfd->msymbol_demangled_hash == NULL) + msymbol = NULL; else msymbol = objfile->per_bfd->msymbol_demangled_hash[dem_hash]; @@ -324,13 +326,16 @@ iterate_over_minimal_symbols (struct objfile *objf, const char *name, } /* The second pass is over the demangled table. */ - hash = msymbol_hash_iw (name) % MINIMAL_SYMBOL_HASH_SIZE; - iter = objf->per_bfd->msymbol_demangled_hash[hash]; - while (iter) + if (objf->per_bfd->msymbol_demangled_hash != NULL) { - if (MSYMBOL_MATCHES_SEARCH_NAME (iter, name)) - (*callback) (iter, user_data); - iter = iter->demangled_hash_next; + hash = msymbol_hash_iw (name) % MINIMAL_SYMBOL_HASH_SIZE; + iter = objf->per_bfd->msymbol_demangled_hash[hash]; + while (iter) + { + if (MSYMBOL_MATCHES_SEARCH_NAME (iter, name)) + (*callback) (iter, user_data); + iter = iter->demangled_hash_next; + } } } @@ -1147,11 +1152,11 @@ build_minimal_symbol_hash_tables (struct objfile *objfile) struct minimal_symbol *msym; /* Clear the hash tables. */ - for (i = 0; i < MINIMAL_SYMBOL_HASH_SIZE; i++) - { - objfile->per_bfd->msymbol_hash[i] = 0; - objfile->per_bfd->msymbol_demangled_hash[i] = 0; - } + memset (objfile->per_bfd->msymbol_hash, 0, + MINIMAL_SYMBOL_HASH_SIZE * sizeof (struct minimal_symbol *)); + if (objfile->per_bfd->msymbol_demangled_hash != NULL) + memset (objfile->per_bfd->msymbol_demangled_hash, 0, + MINIMAL_SYMBOL_HASH_SIZE * sizeof (struct minimal_symbol *)); /* Now, (re)insert the actual entries. */ for ((i = objfile->per_bfd->minimal_symbol_count, @@ -1164,8 +1169,16 @@ build_minimal_symbol_hash_tables (struct objfile *objfile) msym->demangled_hash_next = 0; if (MSYMBOL_SEARCH_NAME (msym) != MSYMBOL_LINKAGE_NAME (msym)) - add_minsym_to_demangled_hash_table (msym, - objfile->per_bfd->msymbol_demangled_hash); + { + if (objfile->per_bfd->msymbol_demangled_hash == NULL) + objfile->per_bfd->msymbol_demangled_hash + = OBSTACK_CALLOC (&objfile->per_bfd->storage_obstack, + MINIMAL_SYMBOL_HASH_SIZE, + struct minimal_symbol *); + + add_minsym_to_demangled_hash_table (msym, + objfile->per_bfd->msymbol_demangled_hash); + } } } diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 57a94e1..c37d0c5 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -244,9 +244,10 @@ struct objfile_per_bfd_storage struct minimal_symbol *msymbol_hash[MINIMAL_SYMBOL_HASH_SIZE]; /* This hash table is used to index the minimal symbols by their - demangled names. */ + demangled names. This may be NULL if no minimal symbol has a + mangled name. */ - struct minimal_symbol *msymbol_demangled_hash[MINIMAL_SYMBOL_HASH_SIZE]; + struct minimal_symbol **msymbol_demangled_hash; }; /* Master structure for keeping track of each file from which