From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway31.websitewelcome.com (gateway31.websitewelcome.com [192.185.143.40]) by sourceware.org (Postfix) with ESMTPS id E4B35385843E for ; Thu, 26 Aug 2021 02:19:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E4B35385843E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tromey.com Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 950E52910F for ; Wed, 25 Aug 2021 21:19:43 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id J4zXmyQdVrJtZJ4zXmYbLn; Wed, 25 Aug 2021 21:19:43 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: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=NiHhNjRnjQsqyMcebIb2gLgsEfRYn54r+eZgHklOVt8=; b=qjQRrHT5EC2PVjgaQPrIUnINJ5 7Q9cUvg3xp1psyoOwFhlDAFgyDsKmFzrqzzR872cIdhVRVfxGJfzdvaSi95w8ow//gE0j2Zi2OIvE 9TmpvlkwH/WwvGx0ezq9EJYKj; Received: from 97-122-86-84.hlrn.qwest.net ([97.122.86.84]:46876 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mJ4zX-003LSg-Bj; Wed, 25 Aug 2021 20:19:43 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 18/30] Wire in the new DWARF indexer Date: Wed, 25 Aug 2021 20:19:25 -0600 Message-Id: <20210826021937.1490292-19-tom@tromey.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210826021937.1490292-1-tom@tromey.com> References: <20210826021937.1490292-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.86.84 X-Source-L: No X-Exim-ID: 1mJ4zX-003LSg-Bj X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-86-84.hlrn.qwest.net (localhost.localdomain) [97.122.86.84]:46876 X-Source-Auth: tom+tromey.com X-Email-Count: 19 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3030.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NEUTRAL, TXREP, URIBL_CSS_A autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Aug 2021 02:20:04 -0000 This wires the new DWARF indexer into the existing reader code. That is, this patch makes the modification necessary to enable the new indexer. It is not actually enabled by this patch -- that will be done later. I did a bit of performance testing for this patch and a few others. I copied my built gdb to /tmp, so that each test would be done on the same executable. Then, each time, I did: $ ./gdb -nx (gdb) maint time 1 (gdb) file /tmp/gdb This patch is the baseline and on one machine came in at 1.598869 wall time. --- gdb/dwarf2/read.c | 199 +++++++++++++++++++++++++++++++++------------- 1 file changed, 142 insertions(+), 57 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 1bed6a32cdd..0e88d402890 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -794,7 +794,8 @@ class cutu_reader : public die_reader_specs dwarf2_per_objfile *per_objfile, struct abbrev_table *abbrev_table, dwarf2_cu *existing_cu, - bool skip_partial); + bool skip_partial, + abbrev_cache *cache = nullptr); explicit cutu_reader (struct dwarf2_per_cu_data *this_cu, dwarf2_per_objfile *per_objfile, @@ -1102,7 +1103,9 @@ static dwarf2_psymtab *create_partial_symtab (dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile, const char *name); -static void build_type_psymtabs_reader (cutu_reader *reader); +class cooked_index_storage; +static void build_type_psymtabs_reader (cutu_reader *reader, + cooked_index_storage *storage); static void dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile); @@ -5594,6 +5597,13 @@ dwarf2_initialize_objfile (struct objfile *objfile) return; } + if (per_bfd->cooked_index_table != nullptr) + { + dwarf_read_debug_printf ("re-using cooked index table"); + objfile->qf.push_front (make_cooked_index_funcs ()); + return; + } + /* There might already be partial symtabs built for this BFD. This happens when loading the same binary twice with the index-cache enabled. If so, don't try to read an index. The objfile / per_objfile initialization will @@ -5606,13 +5616,6 @@ dwarf2_initialize_objfile (struct objfile *objfile) return; } - if (per_bfd->cooked_index_table != nullptr) - { - dwarf_read_debug_printf ("re-using cooked index table"); - objfile->qf.push_front (make_cooked_index_funcs ()); - return; - } - if (dwarf2_read_debug_names (per_objfile)) { dwarf_read_debug_printf ("found debug names"); @@ -6074,7 +6077,9 @@ fill_in_sig_entry_from_dwo_entry (dwarf2_per_objfile *per_objfile, else gdb_assert (sig_entry->v.psymtab == NULL); gdb_assert (sig_entry->signature == dwo_entry->signature); - gdb_assert (to_underlying (sig_entry->type_offset_in_section) == 0); + gdb_assert (to_underlying (sig_entry->type_offset_in_section) == 0 + || (to_underlying (sig_entry->type_offset_in_section) + == to_underlying (dwo_entry->type_offset_in_tu))); gdb_assert (sig_entry->type_unit_group == NULL); gdb_assert (sig_entry->dwo_unit == NULL); @@ -6558,7 +6563,8 @@ cutu_reader::cutu_reader (dwarf2_per_cu_data *this_cu, dwarf2_per_objfile *per_objfile, struct abbrev_table *abbrev_table, dwarf2_cu *existing_cu, - bool skip_partial) + bool skip_partial, + abbrev_cache *cache) : die_reader_specs {}, m_this_cu (this_cu) { @@ -6682,10 +6688,16 @@ cutu_reader::cutu_reader (dwarf2_per_cu_data *this_cu, gdb_assert (cu->header.abbrev_sect_off == abbrev_table->sect_off); else { - abbrev_section->read (objfile); - m_abbrev_table_holder - = abbrev_table::read (abbrev_section, cu->header.abbrev_sect_off); - abbrev_table = m_abbrev_table_holder.get (); + if (cache != nullptr) + abbrev_table = cache->find (abbrev_section, + cu->header.abbrev_sect_off); + if (abbrev_table == nullptr) + { + abbrev_section->read (objfile); + m_abbrev_table_holder + = abbrev_table::read (abbrev_section, cu->header.abbrev_sect_off); + abbrev_table = m_abbrev_table_holder.get (); + } } /* Read the top level CU/TU die. */ @@ -7374,16 +7386,21 @@ static void process_psymtab_comp_unit (dwarf2_per_cu_data *this_cu, dwarf2_per_objfile *per_objfile, bool want_partial_unit, - enum language pretend_language) + enum language pretend_language, + cooked_index_storage *storage) { /* If this compilation unit was already read in, free the cached copy in order to read it in again. This is necessary because we skipped some symbols when we first read in the compilation unit (see load_partial_dies). This problem could be avoided, but the benefit is unclear. */ - per_objfile->remove_cu (this_cu); + if (!per_objfile->per_bfd->using_index) + per_objfile->remove_cu (this_cu); - cutu_reader reader (this_cu, per_objfile, nullptr, nullptr, false); + cutu_reader reader (this_cu, per_objfile, nullptr, nullptr, false, + (storage == nullptr + ? nullptr + : storage->get_abbrev_cache ())); if (reader.comp_unit_die == nullptr) return; @@ -7411,12 +7428,28 @@ process_psymtab_comp_unit (dwarf2_per_cu_data *this_cu, /* Nothing. */ } else if (this_cu->is_debug_types) - build_type_psymtabs_reader (&reader); + build_type_psymtabs_reader (&reader, storage); else if (want_partial_unit || reader.comp_unit_die->tag != DW_TAG_partial_unit) - process_psymtab_comp_unit_reader (&reader, reader.info_ptr, - reader.comp_unit_die, - pretend_language); + { + if (per_objfile->per_bfd->using_index) + { + if (!this_cu->scanned && reader.comp_unit_die->has_children) + { + this_cu->scanned = true; + prepare_one_comp_unit (reader.cu, reader.comp_unit_die, + pretend_language); + gdb_assert (storage != nullptr); + cooked_indexer indexer (storage, this_cu, + reader.cu->per_cu->lang); + indexer.make_index (&reader); + } + } + else + process_psymtab_comp_unit_reader (&reader, reader.info_ptr, + reader.comp_unit_die, + pretend_language); + } /* Age out any secondary CUs. */ per_objfile->age_comp_units (); @@ -7425,7 +7458,8 @@ process_psymtab_comp_unit (dwarf2_per_cu_data *this_cu, /* Reader function for build_type_psymtabs. */ static void -build_type_psymtabs_reader (cutu_reader *reader) +build_type_psymtabs_reader (cutu_reader *reader, + cooked_index_storage *storage) { dwarf2_per_objfile *per_objfile = reader->cu->per_objfile; struct dwarf2_cu *cu = reader->cu; @@ -7453,16 +7487,26 @@ build_type_psymtabs_reader (cutu_reader *reader) tu_group->tus->push_back (sig_type); prepare_one_comp_unit (cu, type_unit_die, language_minimal); - pst = create_partial_symtab (per_cu, per_objfile, ""); - pst->anonymous = true; - first_die = load_partial_dies (reader, info_ptr, 1); + if (per_objfile->per_bfd->using_index) + { + gdb_assert (storage != nullptr); + cooked_indexer indexer (storage, per_cu, cu->per_cu->lang); + indexer.make_index (reader); + } + else + { + pst = create_partial_symtab (per_cu, per_objfile, ""); + pst->anonymous = true; - lowpc = (CORE_ADDR) -1; - highpc = (CORE_ADDR) 0; - scan_partial_symbols (first_die, &lowpc, &highpc, 0, cu); + first_die = load_partial_dies (reader, info_ptr, 1); - pst->end (); + lowpc = (CORE_ADDR) -1; + highpc = (CORE_ADDR) 0; + scan_partial_symbols (first_die, &lowpc, &highpc, 0, cu); + + pst->end (); + } } /* Struct used to sort TUs by their abbreviation table offset. */ @@ -7501,7 +7545,8 @@ struct tu_abbrev_offset dwarf2_per_objfile->per_bfd->type_unit_groups. */ static void -build_type_psymtabs (dwarf2_per_objfile *per_objfile) +build_type_psymtabs (dwarf2_per_objfile *per_objfile, + cooked_index_storage *storage) { struct tu_stats *tu_stats = &per_objfile->per_bfd->tu_stats; abbrev_table_up abbrev_table; @@ -7570,7 +7615,7 @@ build_type_psymtabs (dwarf2_per_objfile *per_objfile) cutu_reader reader (tu.sig_type, per_objfile, abbrev_table.get (), nullptr, false); if (!reader.dummy_p) - build_type_psymtabs_reader (&reader); + build_type_psymtabs_reader (&reader, storage); } } @@ -7626,6 +7671,12 @@ build_type_psymtab_dependencies (void **slot, void *info) return 1; } +struct skeleton_data +{ + dwarf2_per_objfile *per_objfile; + cooked_index_storage *storage; +}; + /* Traversal function for process_skeletonless_type_unit. Read a TU in a DWO file and build partial symbols for it. */ @@ -7633,15 +7684,16 @@ static int process_skeletonless_type_unit (void **slot, void *info) { struct dwo_unit *dwo_unit = (struct dwo_unit *) *slot; - dwarf2_per_objfile *per_objfile = (dwarf2_per_objfile *) info; + skeleton_data *data = (skeleton_data *) info; /* If this TU doesn't exist in the global table, add it and read it in. */ - if (per_objfile->per_bfd->signatured_types == NULL) - per_objfile->per_bfd->signatured_types = allocate_signatured_type_table (); + if (data->per_objfile->per_bfd->signatured_types == NULL) + data->per_objfile->per_bfd->signatured_types + = allocate_signatured_type_table (); signatured_type find_entry (dwo_unit->signature); - slot = htab_find_slot (per_objfile->per_bfd->signatured_types.get (), + slot = htab_find_slot (data->per_objfile->per_bfd->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. */ @@ -7651,14 +7703,14 @@ process_skeletonless_type_unit (void **slot, void *info) /* This does the job that create_all_comp_units would have done for this TU. */ signatured_type *entry - = add_type_unit (per_objfile, dwo_unit->signature, slot); - fill_in_sig_entry_from_dwo_entry (per_objfile, entry, dwo_unit); + = add_type_unit (data->per_objfile, dwo_unit->signature, slot); + fill_in_sig_entry_from_dwo_entry (data->per_objfile, entry, dwo_unit); *slot = entry; /* This does the job that build_type_psymtabs would have done. */ - cutu_reader reader (entry, per_objfile, nullptr, nullptr, false); + cutu_reader reader (entry, data->per_objfile, nullptr, nullptr, false); if (!reader.dummy_p) - build_type_psymtabs_reader (&reader); + build_type_psymtabs_reader (&reader, data->storage); return 1; } @@ -7682,15 +7734,18 @@ process_dwo_file_for_skeletonless_type_units (void **slot, void *info) Note: This can't be done until we know what all the DWO files are. */ static void -process_skeletonless_type_units (dwarf2_per_objfile *per_objfile) +process_skeletonless_type_units (dwarf2_per_objfile *per_objfile, + cooked_index_storage *storage) { + skeleton_data data { per_objfile, storage }; + /* Skeletonless TUs in DWP files without .gdb_index is not supported yet. */ if (get_dwp_file (per_objfile) == NULL && per_objfile->per_bfd->dwo_files != NULL) { htab_traverse_noresize (per_objfile->per_bfd->dwo_files.get (), process_dwo_file_for_skeletonless_type_units, - per_objfile); + &data); } } @@ -7736,9 +7791,6 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile) read_in_chain. Make sure to free them when we're done. */ free_cached_comp_units freer (per_objfile); - create_all_comp_units (per_objfile); - build_type_psymtabs (per_objfile); - /* Create a temporary address map on a temporary obstack. We later copy this to the final obstack. */ auto_obstack temp_obstack; @@ -7747,20 +7799,35 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile) = make_scoped_restore (&per_bfd->partial_symtabs->psymtabs_addrmap, addrmap_create_mutable (&temp_obstack)); + cooked_index_storage index_storage; + cooked_index_storage *index_storage_ptr + = per_bfd->using_index ? &index_storage : nullptr; + create_all_comp_units (per_objfile); + build_type_psymtabs (per_objfile, index_storage_ptr); + if (per_bfd->using_index) + { + per_bfd->quick_file_names_table + = create_quick_file_names_table (per_bfd->all_comp_units.size ()); + + if (!per_bfd->debug_aranges.empty ()) + read_addrmap_from_aranges (per_objfile, &per_bfd->debug_aranges, + index_storage.get_addrmap ()); + } + for (const auto &per_cu : per_bfd->all_comp_units) { - if (per_cu->v.psymtab != NULL) + if (!per_bfd->using_index && per_cu->v.psymtab != NULL) /* In case a forward DW_TAG_imported_unit has read the CU already. */ continue; process_psymtab_comp_unit (per_cu.get (), per_objfile, false, - language_minimal); + language_minimal, index_storage_ptr); } /* This has to wait until we read the CUs, we need the list of DWOs. */ - process_skeletonless_type_units (per_objfile); + process_skeletonless_type_units (per_objfile, &index_storage); /* Now that all TUs have been processed we can fill in the dependencies. */ - if (per_bfd->type_unit_groups != NULL) + if (!per_bfd->using_index && per_bfd->type_unit_groups != NULL) { htab_traverse_noresize (per_bfd->type_unit_groups.get (), build_type_psymtab_dependencies, per_objfile); @@ -7769,14 +7836,27 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile) if (dwarf_read_debug > 0) print_tu_stats (per_objfile); - set_partial_user (per_objfile); + if (per_bfd->using_index) + { + per_bfd->cooked_index_table = index_storage.release (); + per_bfd->cooked_index_table->finalize (); - per_bfd->partial_symtabs->psymtabs_addrmap - = addrmap_create_fixed (per_bfd->partial_symtabs->psymtabs_addrmap, - per_bfd->partial_symtabs->obstack ()); - /* At this point we want to keep the address map. */ - save_psymtabs_addrmap.release (); + const cooked_index_entry *main_entry + = per_bfd->cooked_index_table->get_main (); + if (main_entry != nullptr) + set_objfile_main_name (objfile, main_entry->name, + main_entry->per_cu->lang); + } + else + { + set_partial_user (per_objfile); + per_bfd->partial_symtabs->psymtabs_addrmap + = addrmap_create_fixed (per_bfd->partial_symtabs->psymtabs_addrmap, + per_bfd->partial_symtabs->obstack ()); + /* At this point we want to keep the address map. */ + save_psymtabs_addrmap.release (); + } dwarf_read_debug_printf ("Done building psymtabs of %s", objfile_name (objfile)); } @@ -7865,6 +7945,10 @@ read_comp_units_from_section (dwarf2_per_objfile *per_objfile, this_cu->is_dwz = is_dwz; this_cu->section = section; + if (per_objfile->per_bfd->using_index) + this_cu->v.quick = OBSTACK_ZALLOC (&per_objfile->per_bfd->obstack, + struct dwarf2_per_cu_quick_data); + info_ptr = info_ptr + this_cu->length; per_objfile->per_bfd->all_comp_units.push_back (std::move (this_cu)); } @@ -7993,7 +8077,7 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, /* Go read the partial unit, if needed. */ if (per_cu->v.psymtab == NULL) process_psymtab_comp_unit (per_cu, cu->per_objfile, true, - cu->per_cu->lang); + cu->per_cu->lang, nullptr); if (pdi->die_parent == nullptr && per_cu->unit_type == DW_UT_compile @@ -19277,7 +19361,8 @@ cooked_indexer::ensure_cu_exists (cutu_reader *reader, cutu_reader *result = m_index_storage->get_reader (per_cu); if (result == nullptr) { - cutu_reader new_reader (per_cu, per_objfile, nullptr, nullptr, false); + cutu_reader new_reader (per_cu, per_objfile, nullptr, nullptr, false, + m_index_storage->get_abbrev_cache ()); prepare_one_comp_unit (new_reader.cu, new_reader.comp_unit_die, language_minimal); -- 2.31.1