From patchwork Thu Jan 23 00:56:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 37490 Received: (qmail 81996 invoked by alias); 23 Jan 2020 00:57:47 -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 80319 invoked by uid 89); 23 Jan 2020 00:57:32 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: gateway24.websitewelcome.com Received: from gateway24.websitewelcome.com (HELO gateway24.websitewelcome.com) (192.185.50.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 23 Jan 2020 00:57:23 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 24D2919345 for ; Wed, 22 Jan 2020 18:57:22 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id uQoEiqj3KLLpRuQoEisvEx; Wed, 22 Jan 2020 18:57:22 -0600 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=d5qJP3501NC/WNmjSS3I0xqq2CRyWMhQnL6m1qFK0aM=; b=gBNRVFhdbxIedi2ntFjAjXpsIW cM4m3io6Cg+KDyp13KSqtux8d+25vh26lhFXs2tOp05p5/kVwA+bwrbD5CWRal2Yw58UBw2J/h1kt pVNOi8uio0klBIgpe/eMFjCf1; Received: from 75-166-123-50.hlrn.qwest.net ([75.166.123.50]:40826 helo=bapiya.Home) by box5379.bluehost.com with esmtpa (Exim 4.92) (envelope-from ) id 1iuQoD-004Kis-Tz; Wed, 22 Jan 2020 17:57:22 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 14/38] Change dwarf2_per_objfile::signatured_types to be htab_up Date: Wed, 22 Jan 2020 17:56:46 -0700 Message-Id: <20200123005710.7978-15-tom@tromey.com> In-Reply-To: <20200123005710.7978-1-tom@tromey.com> References: <20200123005710.7978-1-tom@tromey.com> This changes dwarf2_per_objfile::signatured_types to be an htab_up. This in turn lets us change it not to use the objfile obstack for allocation; obstack allocation for hash tables is a bad practice because it leads to excess memory use if the table is ever resized. gdb/ChangeLog 2020-01-22 Tom Tromey * dwarf2/read.h (struct dwarf2_per_objfile) : Change type to htab_up. * dwarf2/read.c (create_signatured_type_table_from_index) (create_signatured_type_table_from_debug_names) (create_all_type_units, add_type_unit) (lookup_dwo_signatured_type, lookup_signatured_type) (process_skeletonless_type_unit): Update. (create_debug_type_hash_table, create_debug_types_hash_table): Change type of types_htab. (allocate_signatured_type_table, allocate_dwo_unit_table): Return htab_up. Don't allocate on obstack. (create_cus_hash_table): Change type of cus_htab parameter. (struct dwo_file) : Now htab_up. (lookup_dwo_signatured_type, lookup_dwo_cutu) (process_dwo_file_for_skeletonless_type_units, lookup_dwo_cutu) (queue_and_load_all_dwo_tus): Update. * dwarf2/index-write.c (write_gdbindex): Update. (write_debug_names): Update. Change-Id: I290a209b96945fb5f415c82723b62830e9c4b467 --- gdb/ChangeLog | 21 +++++++++ gdb/dwarf2/index-write.c | 4 +- gdb/dwarf2/read.c | 96 ++++++++++++++++++++-------------------- gdb/dwarf2/read.h | 2 +- 4 files changed, 71 insertions(+), 52 deletions(-) diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index 6744e1a44db..3d71f967b5f 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -1460,7 +1460,7 @@ write_gdbindex (struct dwarf2_per_objfile *dwarf2_per_objfile, FILE *out_file, sig_data.objfile = objfile; sig_data.symtab = &symtab; sig_data.cu_index = dwarf2_per_objfile->all_comp_units.size (); - htab_traverse_noresize (dwarf2_per_objfile->signatured_types, + htab_traverse_noresize (dwarf2_per_objfile->signatured_types.get (), write_one_signatured_type, &sig_data); } @@ -1533,7 +1533,7 @@ write_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile, /* It is used only for gdb_index. */ sig_data.info.symtab = nullptr; sig_data.info.cu_index = 0; - htab_traverse_noresize (dwarf2_per_objfile->signatured_types, + htab_traverse_noresize (dwarf2_per_objfile->signatured_types.get (), debug_names::write_one_signatured_type, &sig_data); } diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 1e64870678e..10cbc7bd231 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -727,11 +727,11 @@ struct dwo_file Each element is a struct dwo_unit. Multiple CUs per DWO are supported as an extension to handle LLVM's Link Time Optimization output (where multiple source files may be compiled into a single object/dwo pair). */ - htab_t cus {}; + htab_up cus {}; /* Table of TUs in the file. Each element is a struct dwo_unit. */ - htab_t tus {}; + htab_up tus {}; }; /* These sections are what may appear in a DWP file. */ @@ -1873,9 +1873,9 @@ static const gdb_byte *read_and_check_comp_unit_head struct dwarf2_section_info *abbrev_section, const gdb_byte *info_ptr, rcuh_kind section_kind); -static htab_t allocate_signatured_type_table (struct objfile *objfile); +static htab_up allocate_signatured_type_table (struct objfile *objfile); -static htab_t allocate_dwo_unit_table (struct objfile *objfile); +static htab_up allocate_dwo_unit_table (struct objfile *objfile); static struct dwo_unit *lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile *dwarf2_per_objfile, @@ -2744,7 +2744,7 @@ create_signatured_type_table_from_index gdb_assert (dwarf2_per_objfile->all_type_units.empty ()); dwarf2_per_objfile->all_type_units.reserve (elements / 3); - htab_t sig_types_hash = allocate_signatured_type_table (objfile); + htab_up sig_types_hash = allocate_signatured_type_table (objfile); for (offset_type i = 0; i < elements; i += 3) { @@ -2774,13 +2774,13 @@ create_signatured_type_table_from_index = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwarf2_per_cu_quick_data); - slot = htab_find_slot (sig_types_hash, sig_type, INSERT); + slot = htab_find_slot (sig_types_hash.get (), sig_type, INSERT); *slot = sig_type; dwarf2_per_objfile->all_type_units.push_back (sig_type); } - dwarf2_per_objfile->signatured_types = sig_types_hash; + dwarf2_per_objfile->signatured_types = std::move (sig_types_hash); } /* Create the signatured type hash table from .debug_names. */ @@ -2800,7 +2800,7 @@ create_signatured_type_table_from_debug_names gdb_assert (dwarf2_per_objfile->all_type_units.empty ()); dwarf2_per_objfile->all_type_units.reserve (map.tu_count); - htab_t sig_types_hash = allocate_signatured_type_table (objfile); + htab_up sig_types_hash = allocate_signatured_type_table (objfile); for (uint32_t i = 0; i < map.tu_count; ++i) { @@ -2831,13 +2831,13 @@ create_signatured_type_table_from_debug_names = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwarf2_per_cu_quick_data); - slot = htab_find_slot (sig_types_hash, sig_type, INSERT); + slot = htab_find_slot (sig_types_hash.get (), sig_type, INSERT); *slot = sig_type; dwarf2_per_objfile->all_type_units.push_back (sig_type); } - dwarf2_per_objfile->signatured_types = sig_types_hash; + dwarf2_per_objfile->signatured_types = std::move (sig_types_hash); } /* Read the address map data from the mapped index, and use it to @@ -6407,16 +6407,13 @@ eq_signatured_type (const void *item_lhs, const void *item_rhs) /* Allocate a hash table for signatured types. */ -static htab_t +static htab_up allocate_signatured_type_table (struct objfile *objfile) { - return htab_create_alloc_ex (41, - hash_signatured_type, - eq_signatured_type, - NULL, - &objfile->objfile_obstack, - hashtab_obstack_allocate, - dummy_obstack_deallocate); + return htab_up (htab_create_alloc (41, + hash_signatured_type, + eq_signatured_type, + NULL, xcalloc, xfree)); } /* A helper function to add a signatured type CU to a table. */ @@ -6440,7 +6437,7 @@ add_signatured_type_cu_to_table (void **slot, void *datum) static void create_debug_type_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile, struct dwo_file *dwo_file, - dwarf2_section_info *section, htab_t &types_htab, + dwarf2_section_info *section, htab_up &types_htab, rcuh_kind section_kind) { struct objfile *objfile = dwarf2_per_objfile->objfile; @@ -6539,7 +6536,7 @@ create_debug_type_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile, sig_type->per_cu.length = length; } - slot = htab_find_slot (types_htab, + slot = htab_find_slot (types_htab.get (), dwo_file ? (void*) dwo_tu : (void *) sig_type, INSERT); gdb_assert (slot != NULL); @@ -6591,7 +6588,7 @@ static void create_debug_types_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile, struct dwo_file *dwo_file, gdb::array_view type_sections, - htab_t &types_htab) + htab_up &types_htab) { for (dwarf2_section_info §ion : type_sections) create_debug_type_hash_table (dwarf2_per_objfile, dwo_file, §ion, @@ -6606,7 +6603,7 @@ create_debug_types_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile, static int create_all_type_units (struct dwarf2_per_objfile *dwarf2_per_objfile) { - htab_t types_htab = NULL; + htab_up types_htab; create_debug_type_hash_table (dwarf2_per_objfile, NULL, &dwarf2_per_objfile->info, types_htab, @@ -6619,12 +6616,14 @@ create_all_type_units (struct dwarf2_per_objfile *dwarf2_per_objfile) return 0; } - dwarf2_per_objfile->signatured_types = types_htab; + dwarf2_per_objfile->signatured_types = std::move (types_htab); gdb_assert (dwarf2_per_objfile->all_type_units.empty ()); - dwarf2_per_objfile->all_type_units.reserve (htab_elements (types_htab)); + dwarf2_per_objfile->all_type_units.reserve + (htab_elements (dwarf2_per_objfile->signatured_types.get ())); - htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table, + htab_traverse_noresize (dwarf2_per_objfile->signatured_types.get (), + add_signatured_type_cu_to_table, &dwarf2_per_objfile->all_type_units); return 1; @@ -6659,7 +6658,7 @@ add_type_unit (struct dwarf2_per_objfile *dwarf2_per_objfile, ULONGEST sig, if (slot == NULL) { - slot = htab_find_slot (dwarf2_per_objfile->signatured_types, + slot = htab_find_slot (dwarf2_per_objfile->signatured_types.get (), sig_type, INSERT); } gdb_assert (*slot == NULL); @@ -6740,7 +6739,7 @@ lookup_dwo_signatured_type (struct dwarf2_cu *cu, ULONGEST sig) .gdb_index with this TU. */ find_sig_entry.signature = sig; - slot = htab_find_slot (dwarf2_per_objfile->signatured_types, + slot = htab_find_slot (dwarf2_per_objfile->signatured_types.get (), &find_sig_entry, INSERT); sig_entry = (struct signatured_type *) *slot; @@ -6764,7 +6763,8 @@ lookup_dwo_signatured_type (struct dwarf2_cu *cu, ULONGEST sig) if (dwo_file->tus == NULL) return NULL; find_dwo_entry.signature = sig; - dwo_entry = (struct dwo_unit *) htab_find (dwo_file->tus, &find_dwo_entry); + dwo_entry = (struct dwo_unit *) htab_find (dwo_file->tus.get (), + &find_dwo_entry); if (dwo_entry == NULL) return NULL; @@ -6805,7 +6805,7 @@ lookup_dwp_signatured_type (struct dwarf2_cu *cu, ULONGEST sig) } find_sig_entry.signature = sig; - slot = htab_find_slot (dwarf2_per_objfile->signatured_types, + slot = htab_find_slot (dwarf2_per_objfile->signatured_types.get (), &find_sig_entry, INSERT); sig_entry = (struct signatured_type *) *slot; @@ -6856,7 +6856,8 @@ lookup_signatured_type (struct dwarf2_cu *cu, ULONGEST sig) return NULL; find_entry.signature = sig; entry = ((struct signatured_type *) - htab_find (dwarf2_per_objfile->signatured_types, &find_entry)); + htab_find (dwarf2_per_objfile->signatured_types.get (), + &find_entry)); return entry; } } @@ -8083,8 +8084,8 @@ process_skeletonless_type_unit (void **slot, void *info) } find_entry.signature = dwo_unit->signature; - slot = htab_find_slot (dwarf2_per_objfile->signatured_types, &find_entry, - INSERT); + slot = htab_find_slot (dwarf2_per_objfile->signatured_types.get (), + &find_entry, INSERT); /* If we've already seen this type there's nothing to do. What's happening is we're doing our own version of comdat-folding here. */ if (*slot != NULL) @@ -8113,10 +8114,8 @@ process_dwo_file_for_skeletonless_type_units (void **slot, void *info) struct dwo_file *dwo_file = (struct dwo_file *) *slot; if (dwo_file->tus != NULL) - { - htab_traverse_noresize (dwo_file->tus, - process_skeletonless_type_unit, info); - } + htab_traverse_noresize (dwo_file->tus.get (), + process_skeletonless_type_unit, info); return 1; } @@ -11528,18 +11527,15 @@ eq_dwo_unit (const void *item_lhs, const void *item_rhs) /* Allocate a hash table for DWO CUs,TUs. There is one of these tables for each of CUs,TUs for each DWO file. */ -static htab_t +static htab_up allocate_dwo_unit_table (struct objfile *objfile) { /* Start out with a pretty small number. Generally DWO files contain only one CU and maybe some TUs. */ - return htab_create_alloc_ex (3, - hash_dwo_unit, - eq_dwo_unit, - NULL, - &objfile->objfile_obstack, - hashtab_obstack_allocate, - dummy_obstack_deallocate); + return htab_up (htab_create_alloc (3, + hash_dwo_unit, + eq_dwo_unit, + NULL, xcalloc, xfree)); } /* die_reader_func for create_dwo_cu. */ @@ -11582,7 +11578,7 @@ create_dwo_cu_reader (const struct die_reader_specs *reader, static void create_cus_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile, dwarf2_cu *cu, struct dwo_file &dwo_file, - dwarf2_section_info §ion, htab_t &cus_htab) + dwarf2_section_info §ion, htab_up &cus_htab) { struct objfile *objfile = dwarf2_per_objfile->objfile; const gdb_byte *info_ptr, *end_ptr; @@ -11630,7 +11626,7 @@ create_cus_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile, dwo_unit = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_unit); *dwo_unit = read_unit; - slot = htab_find_slot (cus_htab, dwo_unit, INSERT); + slot = htab_find_slot (cus_htab.get (), dwo_unit, INSERT); gdb_assert (slot != NULL); if (*slot != NULL) { @@ -13031,7 +13027,8 @@ lookup_dwo_cutu (struct dwarf2_per_cu_data *this_unit, memset (&find_dwo_cutu, 0, sizeof (find_dwo_cutu)); find_dwo_cutu.signature = signature; dwo_cutu - = (struct dwo_unit *) htab_find (dwo_file->tus, &find_dwo_cutu); + = (struct dwo_unit *) htab_find (dwo_file->tus.get (), + &find_dwo_cutu); } else if (!is_debug_types && dwo_file->cus) { @@ -13039,7 +13036,7 @@ lookup_dwo_cutu (struct dwarf2_per_cu_data *this_unit, memset (&find_dwo_cutu, 0, sizeof (find_dwo_cutu)); find_dwo_cutu.signature = signature; - dwo_cutu = (struct dwo_unit *)htab_find (dwo_file->cus, + dwo_cutu = (struct dwo_unit *)htab_find (dwo_file->cus.get (), &find_dwo_cutu); } @@ -13154,7 +13151,8 @@ queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data *per_cu) dwo_file = dwo_unit->dwo_file; if (dwo_file->tus != NULL) - htab_traverse_noresize (dwo_file->tus, queue_and_load_dwo_tu, per_cu); + htab_traverse_noresize (dwo_file->tus.get (), queue_and_load_dwo_tu, + per_cu); } /* Read in various DIEs. */ diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index 9c671806479..33ecb4a5911 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -156,7 +156,7 @@ public: /* A table mapping .debug_types signatures to its signatured_type entry. This is NULL if the .debug_types section hasn't been read in yet. */ - htab_t signatured_types {}; + htab_up signatured_types; /* Type unit statistics, to see how well the scaling improvements are doing. */