From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway24.websitewelcome.com (gateway24.websitewelcome.com [192.185.51.59]) by sourceware.org (Postfix) with ESMTPS id E48293858411 for ; Sat, 4 Dec 2021 20:38:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E48293858411 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 cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway24.websitewelcome.com (Postfix) with ESMTP id 0948774020 for ; Sat, 4 Dec 2021 14:38:53 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id tbo4m4Af7jXZUtbo5mOJyM; Sat, 04 Dec 2021 14:38:53 -0600 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=eKGiN5GtWwhdd/FshABacXc43KHESEIHNg6QMgFuz7A=; b=VHrgTvhUkm62tS3zX02UknAyUl fokCs/3D5eNhFIMxuLuEmMxp0EMoGZOXWzVukcKN175QyCqv9f+tonjABknp216zQlKgbGuvddldT d3Ui16u0cegzDGzmpzBSZvCZB; Received: from 97-122-84-67.hlrn.qwest.net ([97.122.84.67]:51992 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 1mtbo4-000f48-KB; Sat, 04 Dec 2021 13:38:52 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v3 20/33] Wire in the new DWARF indexer Date: Sat, 4 Dec 2021 13:38:31 -0700 Message-Id: <20211204203844.1188999-21-tom@tromey.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211204203844.1188999-1-tom@tromey.com> References: <20211204203844.1188999-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.84.67 X-Source-L: No X-Exim-ID: 1mtbo4-000f48-KB X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-84-67.hlrn.qwest.net (localhost.localdomain) [97.122.84.67]:51992 X-Source-Auth: tom+tromey.com X-Email-Count: 21 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3031.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_NEUTRAL, TXREP 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: Sat, 04 Dec 2021 20:38:56 -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 | 205 +++++++++++++++++++++++++++++++++------------- 1 file changed, 146 insertions(+), 59 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 1fd8a6f7543..3f6cc75f059 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, @@ -1116,7 +1117,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); @@ -5617,6 +5620,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 @@ -5629,13 +5639,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"); @@ -6100,9 +6103,12 @@ 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); + gdb_assert (sig_entry->dwo_unit == NULL + || sig_entry->dwo_unit == dwo_entry); sig_entry->section = dwo_entry->section; sig_entry->sect_off = dwo_entry->sect_off; @@ -6180,7 +6186,8 @@ lookup_dwo_signatured_type (struct dwarf2_cu *cu, ULONGEST sig) if (sig_entry == NULL) sig_entry = add_type_unit (per_objfile, sig, slot); - fill_in_sig_entry_from_dwo_entry (per_objfile, sig_entry, dwo_entry); + if (sig_entry->dwo_unit == nullptr) + fill_in_sig_entry_from_dwo_entry (per_objfile, sig_entry, dwo_entry); sig_entry->tu_read = 1; return sig_entry; } @@ -6584,7 +6591,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) { @@ -6708,10 +6716,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. */ @@ -7400,16 +7414,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; @@ -7437,12 +7456,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) + { + 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 (); @@ -7451,7 +7486,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; @@ -7479,16 +7515,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; + + first_die = load_partial_dies (reader, info_ptr, 1); - lowpc = (CORE_ADDR) -1; - highpc = (CORE_ADDR) 0; - scan_partial_symbols (first_die, &lowpc, &highpc, 0, cu); + lowpc = (CORE_ADDR) -1; + highpc = (CORE_ADDR) 0; + scan_partial_symbols (first_die, &lowpc, &highpc, 0, cu); - pst->end (); + pst->end (); + } } /* Struct used to sort TUs by their abbreviation table offset. */ @@ -7527,7 +7573,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; @@ -7596,7 +7643,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); } } @@ -7652,6 +7699,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. */ @@ -7659,15 +7712,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. */ @@ -7677,14 +7731,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; } @@ -7708,15 +7762,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); } } @@ -7762,9 +7819,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; @@ -7773,20 +7827,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); @@ -7795,14 +7864,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)); } @@ -7891,6 +7973,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)); } @@ -8020,7 +8106,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 @@ -19312,7 +19398,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