From b0b6a9878a472438a6fe2e93be819546efc5033a Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 8 Feb 2020 13:40:54 -0700 Subject: [PATCH] Change dwarf2_per_objfile::signatured_types to be htab_up 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-02-08 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/ChangeLog b/gdb/ChangeLog index cae5468ba76..50aecc7bb07 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,24 @@ +2020-02-08 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. + 2020-02-08 Tom Tromey * dwarf2/read.h (struct dwarf2_queue_item): Move from diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index 3c9ccbba46d..2cbf2ebd202 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -1461,7 +1461,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); } @@ -1534,7 +1534,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 527ed2e4221..d47a90bac23 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. */ @@ -1868,9 +1868,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, @@ -2739,7 +2739,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) { @@ -2769,13 +2769,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. */ @@ -2795,7 +2795,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) { @@ -2826,13 +2826,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 @@ -6400,16 +6400,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. */ @@ -6433,7 +6430,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; @@ -6532,7 +6529,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); @@ -6584,7 +6581,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, @@ -6599,7 +6596,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, @@ -6612,12 +6609,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; @@ -6652,7 +6651,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); @@ -6733,7 +6732,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; @@ -6757,7 +6756,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; @@ -6798,7 +6798,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; @@ -6849,7 +6849,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; } } @@ -8075,8 +8076,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) @@ -8105,10 +8106,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; } @@ -11483,18 +11482,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. */ @@ -11537,7 +11533,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; @@ -11585,7 +11581,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) { @@ -12986,7 +12982,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) { @@ -12994,7 +12991,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); } @@ -13109,7 +13106,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 13b5878ca23..ac87258c664 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -157,7 +157,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. */ -- 2.30.2