From af758d117e1454daebc6135cb70529b9843c3437 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 27 May 2020 11:15:47 -0400 Subject: [PATCH] Remove symtab links from dwarf2_psymtab and dwarf2_per_cu_quick_data The dwarf2_psymtab and dwarf2_per_cu_quick_data types contain a pointer to a compunit_symtab, which is a pointer to the corresponding full symtab. The dwarf2_psymtab and dwarf2_per_cu_quick_data objects are going to become objfile-independent, and possibly shared by multiple objfiles, whereas compunit_symtab will stay objfile-dependent. This backlink to the compunit_symtab must therefore be removed. This patch replaces them with a vector in the dwarf2_per_objfile type, that serves as a mapping from dwarf2_per_cu_data objects to compunit_symtab objects, for this particular objfile. The vector is indexed using the index assigned to the dwarf2_per_cu_data at its creation. I removed the get_compunit_symtab, as it appears to bring not much value over calling dwarf2_per_objfile::get_symtab directly. gdb/ChangeLog: YYYY-MM-DD Tom Tromey YYYY-MM-DD Simon Marchi * dwarf2/read.h (struct dwarf2_per_bfd) : New method. (struct dwarf2_per_objfile) : New methods. : New field. (struct dwarf2_psymtab): Derive from partial_symtab. : Declare methods. * dwarf2/read.c (dwarf2_per_objfile::symtab_set_p, dwarf2_per_objfile::get_symtab, dwarf2_per_objfile::set_symtab): New methods. (struct dwarf2_per_cu_quick_data) : Remove. (dw2_do_instantiate_symtab, dw2_instantiate_symtab) (dw2_map_expand_apply, dw2_map_symtabs_matching_filename) (dw2_symtab_iter_next, dw2_print_stats) (dw2_expand_symtabs_with_fullname) (dw2_expand_symtabs_matching_one) (dw_expand_symtabs_matching_file_matcher) (dw2_find_pc_sect_compunit_symtab, dw2_map_symbol_filenames) (dw2_debug_names_iterator::next) (dw2_debug_names_map_matching_symbols) (fill_in_sig_entry_from_dwo_entry, dwarf2_psymtab::read_symtab) (process_queue, dwarf2_psymtab::expand_psymtab): Update. (dwarf2_psymtab::readin_p, dwarf2_psymtab::get_compunit_symtab): New methods. (get_compunit_symtab, process_full_comp_unit) (process_full_type_unit): Update. (dwarf2_build_psymtabs, dwarf2_initialize_objfile, add_type_unit): Call Change-Id: Iec53d96e0b70a57d8b68408febdac3c6c3d4854b --- gdb/ChangeLog | 31 +++++++++ gdb/dwarf2/read.c | 162 +++++++++++++++++++++++++++------------------- gdb/dwarf2/read.h | 37 ++++++++++- 3 files changed, 160 insertions(+), 70 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index bb51c6d2f93..55ee15a98cd 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,34 @@ +2020-05-27 Tom Tromey + Simon Marchi + + * dwarf2/read.h (struct dwarf2_per_bfd) : New + method. + (struct dwarf2_per_objfile) : New methods. + : New field. + (struct dwarf2_psymtab): Derive from partial_symtab. + : Declare methods. + * dwarf2/read.c (dwarf2_per_objfile::symtab_set_p, + dwarf2_per_objfile::get_symtab, dwarf2_per_objfile::set_symtab): + New methods. + (struct dwarf2_per_cu_quick_data) : Remove. + (dw2_do_instantiate_symtab, dw2_instantiate_symtab) + (dw2_map_expand_apply, dw2_map_symtabs_matching_filename) + (dw2_symtab_iter_next, dw2_print_stats) + (dw2_expand_symtabs_with_fullname) + (dw2_expand_symtabs_matching_one) + (dw_expand_symtabs_matching_file_matcher) + (dw2_find_pc_sect_compunit_symtab, dw2_map_symbol_filenames) + (dw2_debug_names_iterator::next) + (dw2_debug_names_map_matching_symbols) + (fill_in_sig_entry_from_dwo_entry, dwarf2_psymtab::read_symtab) + (process_queue, dwarf2_psymtab::expand_psymtab): Update. + (dwarf2_psymtab::readin_p, dwarf2_psymtab::get_compunit_symtab): + New methods. + (get_compunit_symtab, process_full_comp_unit) + (process_full_type_unit): Update. + (dwarf2_build_psymtabs, dwarf2_initialize_objfile, add_type_unit): Call + 2020-05-27 Simon Marchi * dwarf2/read.h (dwarf2_per_objfile): Rename to dwarf2_per_bfd, diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index b2734dbee93..a7409b5a1ef 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -1811,6 +1811,38 @@ private: dwarf2_per_objfile *m_per_objfile; }; +/* See read.h. */ + +bool +dwarf2_per_objfile::symtab_set_p (const dwarf2_per_cu_data *per_cu) const +{ + gdb_assert (per_cu->index < this->m_symtabs.size ()); + + return this->m_symtabs[per_cu->index] != nullptr; +} + +/* See read.h. */ + +compunit_symtab * +dwarf2_per_objfile::get_symtab (const dwarf2_per_cu_data *per_cu) const +{ + gdb_assert (per_cu->index < this->m_symtabs.size ()); + + return this->m_symtabs[per_cu->index]; +} + +/* See read.h. */ + +void +dwarf2_per_objfile::set_symtab (const dwarf2_per_cu_data *per_cu, + compunit_symtab *symtab) +{ + gdb_assert (per_cu->index < this->m_symtabs.size ()); + gdb_assert (this->m_symtabs[per_cu->index] == nullptr); + + this->m_symtabs[per_cu->index] = symtab; +} + /* Try to locate the sections we need for DWARF 2 debugging information and return true if we have enough to do something. NAMES points to the dwarf2 section names, or is NULL if the standard @@ -2198,10 +2230,6 @@ struct dwarf2_per_cu_quick_data NOTE: This points into dwarf2_per_objfile->per_bfd->quick_file_names_table. */ struct quick_file_names *file_names; - /* The corresponding symbol table. This is NULL if symbols for this - CU have not yet been read. */ - struct compunit_symtab *compunit_symtab; - /* A temporary mark bit used when iterating over all CUs in expand_symtabs_matching. */ unsigned int mark : 1; @@ -2325,9 +2353,7 @@ dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu, bool skip_partial) with the dwarf queue empty. */ dwarf2_queue_guard q_guard (dwarf2_per_objfile); - if (dwarf2_per_objfile->per_bfd->using_index - ? per_cu->v.quick->compunit_symtab == NULL - : (per_cu->v.psymtab == NULL || !per_cu->v.psymtab->readin)) + if (!dwarf2_per_objfile->symtab_set_p (per_cu)) { queue_comp_unit (per_cu, language_minimal); load_cu (per_cu, skip_partial); @@ -2362,7 +2388,8 @@ dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu, bool skip_partial) struct dwarf2_per_objfile *dwarf2_per_objfile = per_cu->dwarf2_per_objfile; gdb_assert (dwarf2_per_objfile->per_bfd->using_index); - if (!per_cu->v.quick->compunit_symtab) + + if (!dwarf2_per_objfile->symtab_set_p (per_cu)) { free_cached_comp_units freer (dwarf2_per_objfile); scoped_restore decrementer = increment_reading_symtab (); @@ -2370,7 +2397,7 @@ dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu, bool skip_partial) process_cu_includes (dwarf2_per_objfile); } - return per_cu->v.quick->compunit_symtab; + return dwarf2_per_objfile->get_symtab (per_cu); } /* See declaration. */ @@ -3274,7 +3301,8 @@ dw2_map_expand_apply (struct objfile *objfile, struct compunit_symtab *last_made = objfile->compunit_symtabs; /* Don't visit already-expanded CUs. */ - if (per_cu->v.quick->compunit_symtab) + dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); + if (per_objfile->symtab_set_p (per_cu)) return 0; /* This may expand more than one symtab, and we want to iterate over @@ -3302,7 +3330,7 @@ dw2_map_symtabs_matching_filename for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->per_bfd->all_comp_units) { /* We only need to look at symtabs not already expanded. */ - if (per_cu->v.quick->compunit_symtab) + if (dwarf2_per_objfile->symtab_set_p (per_cu)) continue; quick_file_names *file_data = dw2_get_file_names (per_cu); @@ -3444,7 +3472,7 @@ dw2_symtab_iter_next (struct dw2_symtab_iterator *iter) dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->per_bfd->get_cutu (cu_index); /* Skip if already read in. */ - if (per_cu->v.quick->compunit_symtab) + if (dwarf2_per_objfile->symtab_set_p (per_cu)) continue; /* Check static vs global. */ @@ -3559,7 +3587,7 @@ dw2_print_stats (struct objfile *objfile) { dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->per_bfd->get_cutu (i); - if (!per_cu->v.quick->compunit_symtab) + if (!dwarf2_per_objfile->symtab_set_p (per_cu)) ++count; } printf_filtered (_(" Number of read CUs: %d\n"), total - count); @@ -3642,7 +3670,7 @@ dw2_expand_symtabs_with_fullname (struct objfile *objfile, for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->per_bfd->all_comp_units) { /* We only need to look at symtabs not already expanded. */ - if (per_cu->v.quick->compunit_symtab) + if (dwarf2_per_objfile->symtab_set_p (per_cu)) continue; quick_file_names *file_data = dw2_get_file_names (per_cu); @@ -4503,15 +4531,14 @@ dw2_expand_symtabs_matching_one { if (file_matcher == NULL || per_cu->v.quick->mark) { - bool symtab_was_null - = (per_cu->v.quick->compunit_symtab == NULL); + dwarf2_per_objfile *per_objfile = per_cu->dwarf2_per_objfile; + bool symtab_was_null = !per_objfile->symtab_set_p (per_cu); - dw2_instantiate_symtab (per_cu, false); + compunit_symtab *symtab = dw2_instantiate_symtab (per_cu, false); + gdb_assert (symtab != nullptr); - if (expansion_notify != NULL - && symtab_was_null - && per_cu->v.quick->compunit_symtab != NULL) - expansion_notify (per_cu->v.quick->compunit_symtab); + if (expansion_notify != NULL && symtab_was_null) + expansion_notify (symtab); } } @@ -4629,7 +4656,7 @@ dw_expand_symtabs_matching_file_matcher per_cu->v.quick->mark = 0; /* We only need to look at symtabs not already expanded. */ - if (per_cu->v.quick->compunit_symtab) + if (dwarf2_per_objfile->symtab_set_p (per_cu)) continue; quick_file_names *file_data = dw2_get_file_names (per_cu); @@ -4767,7 +4794,8 @@ dw2_find_pc_sect_compunit_symtab (struct objfile *objfile, if (!data) return NULL; - if (warn_if_readin && data->v.quick->compunit_symtab) + dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); + if (warn_if_readin && per_objfile->symtab_set_p (data)) warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"), paddress (objfile->arch (), pc)); @@ -4800,7 +4828,7 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun, for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->per_bfd->all_comp_units) { - if (per_cu->v.quick->compunit_symtab) + if (dwarf2_per_objfile->symtab_set_p (per_cu)) { void **slot = htab_find_slot (visited.get (), per_cu->v.quick->file_names, @@ -4813,7 +4841,7 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun, for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->per_bfd->all_comp_units) { /* We only need to look at symtabs not already expanded. */ - if (per_cu->v.quick->compunit_symtab) + if (dwarf2_per_objfile->symtab_set_p (per_cu)) continue; quick_file_names *file_data = dw2_get_file_names (per_cu); @@ -5484,7 +5512,7 @@ dw2_debug_names_iterator::next () } /* Skip if already read in. */ - if (per_cu->v.quick->compunit_symtab) + if (dwarf2_per_objfile->symtab_set_p (per_cu)) goto again; /* Check static vs global. */ @@ -5725,11 +5753,11 @@ dw2_debug_names_map_matching_symbols the psymtab code does. */ for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->per_bfd->all_comp_units) { - struct compunit_symtab *cust = per_cu->v.quick->compunit_symtab; - if (cust != nullptr) + compunit_symtab *symtab = dwarf2_per_objfile->get_symtab (per_cu); + if (symtab != nullptr) { const struct block *block - = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), block_kind); + = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (symtab), block_kind); if (!iterate_over_symbols_terminated (block, name, domain, callback)) break; @@ -5879,6 +5907,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) dwarf2_per_objfile->per_bfd->quick_file_names_table = create_quick_file_names_table (dwarf2_per_objfile->per_bfd->all_comp_units.size ()); + dwarf2_per_objfile->resize_symtabs (); for (int i = 0; i < (dwarf2_per_objfile->per_bfd->all_comp_units.size () + dwarf2_per_objfile->per_bfd->all_type_units.size ()); ++i) @@ -5899,6 +5928,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) if (dwarf2_read_debug_names (dwarf2_per_objfile)) { *index_kind = dw_index_kind::DEBUG_NAMES; + dwarf2_per_objfile->resize_symtabs (); return true; } @@ -5907,6 +5937,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) get_gdb_index_contents_from_section)) { *index_kind = dw_index_kind::GDB_INDEX; + dwarf2_per_objfile->resize_symtabs (); return true; } @@ -5917,6 +5948,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind) { global_index_cache.hit (); *index_kind = dw_index_kind::GDB_INDEX; + dwarf2_per_objfile->resize_symtabs (); return true; } @@ -5945,6 +5977,8 @@ dwarf2_build_psymtabs (struct objfile *objfile) dwarf2_build_psymtabs_hard (dwarf2_per_objfile); psymtabs.keep (); + dwarf2_per_objfile->resize_symtabs (); + /* (maybe) store an index in the cache. */ global_index_cache.store (dwarf2_per_objfile); } @@ -6375,6 +6409,8 @@ add_type_unit (struct dwarf2_per_objfile *dwarf2_per_objfile, ULONGEST sig, signatured_type *sig_type = dwarf2_per_objfile->per_bfd->allocate_signatured_type (); + dwarf2_per_objfile->resize_symtabs (); + dwarf2_per_objfile->per_bfd->all_type_units.push_back (sig_type); sig_type->signature = sig; sig_type->per_cu.is_debug_types = 1; @@ -6410,7 +6446,7 @@ fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile *dwarf2_per_objfile, if (dwarf2_per_objfile->per_bfd->using_index) { gdb_assert (sig_entry->per_cu.v.quick != NULL); - gdb_assert (sig_entry->per_cu.v.quick->compunit_symtab == NULL); + gdb_assert (!dwarf2_per_objfile->symtab_set_p (&sig_entry->per_cu)); } else gdb_assert (sig_entry->per_cu.v.psymtab == NULL); @@ -8837,7 +8873,8 @@ dwarf2_psymtab::read_symtab (struct objfile *objfile) struct dwarf2_per_objfile *dwarf2_per_objfile = get_dwarf2_per_objfile (objfile); - gdb_assert (!readin); + gdb_assert (!dwarf2_per_objfile->symtab_set_p (per_cu_data)); + /* If this psymtab is constructed from a debug-only objfile, the has_section_at_zero flag will not necessarily be correct. We can get the correct value for this flag by looking at the data @@ -8933,9 +8970,7 @@ process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile) { dwarf2_queue_item &item = dwarf2_per_objfile->per_bfd->queue.front (); - if ((dwarf2_per_objfile->per_bfd->using_index - ? !item.per_cu->v.quick->compunit_symtab - : (item.per_cu->v.psymtab && !item.per_cu->v.psymtab->readin)) + if (!dwarf2_per_objfile->symtab_set_p (item.per_cu) /* Skip dummy CUs. */ && item.per_cu->cu != NULL) { @@ -8990,7 +9025,7 @@ process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile) void dwarf2_psymtab::expand_psymtab (struct objfile *objfile) { - gdb_assert (!readin); + gdb_assert (!readin_p (objfile)); expand_dependencies (objfile); @@ -8998,6 +9033,24 @@ dwarf2_psymtab::expand_psymtab (struct objfile *objfile) gdb_assert (get_compunit_symtab (objfile) != nullptr); } +/* See psympriv.h. */ + +bool +dwarf2_psymtab::readin_p (struct objfile *objfile) const +{ + dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); + return per_objfile->symtab_set_p (per_cu_data); +} + +/* See psympriv.h. */ + +compunit_symtab * +dwarf2_psymtab::get_compunit_symtab (struct objfile *objfile) const +{ + dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); + return per_objfile->get_symtab (per_cu_data); +} + /* Trivial hash function for die_info: the hash value of a DIE is its offset in .debug_info for this objfile. */ @@ -9535,17 +9588,6 @@ rust_union_quirks (struct dwarf2_cu *cu) cu->rust_unions.clear (); } -/* Return the symtab for PER_CU. This works properly regardless of - whether we're using the index or psymtabs. */ - -static struct compunit_symtab * -get_compunit_symtab (struct dwarf2_per_cu_data *per_cu) -{ - return (per_cu->dwarf2_per_objfile->per_bfd->using_index - ? per_cu->v.quick->compunit_symtab - : per_cu->v.psymtab->compunit_symtab); -} - /* A helper function for computing the list of all symbol tables included by PER_CU. */ @@ -9555,10 +9597,7 @@ recursively_compute_inclusions (std::vector *result, struct dwarf2_per_cu_data *per_cu, struct compunit_symtab *immediate_parent) { - void **slot; - struct compunit_symtab *cust; - - slot = htab_find_slot (all_children, per_cu, INSERT); + void **slot = htab_find_slot (all_children, per_cu, INSERT); if (*slot != NULL) { /* This inclusion and its children have been processed. */ @@ -9566,8 +9605,9 @@ recursively_compute_inclusions (std::vector *result, } *slot = per_cu; + /* Only add a CU if it has a symbol table. */ - cust = get_compunit_symtab (per_cu); + compunit_symtab *cust = per_cu->dwarf2_per_objfile->get_symtab (per_cu); if (cust != NULL) { /* If this is a type unit only add its symbol table if we haven't @@ -9612,7 +9652,7 @@ compute_compunit_symtab_includes (struct dwarf2_per_cu_data *per_cu) int len; std::vector result_symtabs; htab_t all_children, all_type_symtabs; - struct compunit_symtab *cust = get_compunit_symtab (per_cu); + compunit_symtab *cust = per_cu->dwarf2_per_objfile->get_symtab (per_cu); /* If we don't have a symtab, we can just skip this case. */ if (cust == NULL) @@ -9749,14 +9789,7 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu, cust->call_site_htab = cu->call_site_htab; } - if (dwarf2_per_objfile->per_bfd->using_index) - per_cu->v.quick->compunit_symtab = cust; - else - { - dwarf2_psymtab *pst = per_cu->v.psymtab; - pst->compunit_symtab = cust; - pst->readin = true; - } + dwarf2_per_objfile->set_symtab (per_cu, cust); /* Push it for inclusion processing later. */ dwarf2_per_objfile->per_bfd->just_read_cus.push_back (per_cu); @@ -9829,14 +9862,7 @@ process_full_type_unit (struct dwarf2_per_cu_data *per_cu, cust = sig_type->type_unit_group->compunit_symtab; } - if (dwarf2_per_objfile->per_bfd->using_index) - per_cu->v.quick->compunit_symtab = cust; - else - { - dwarf2_psymtab *pst = per_cu->v.psymtab; - pst->compunit_symtab = cust; - pst->readin = true; - } + dwarf2_per_objfile->set_symtab (per_cu, cust); /* Not needed any more. */ cu->reset_builder (); diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index 4dc9496046f..7631938edb0 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -123,6 +123,11 @@ struct dwarf2_per_bfd is allocated on the dwarf2_per_bfd obstack. */ signatured_type *allocate_signatured_type (); + /* Return the number of partial symtabs allocated with allocate_per_cu + and allocate_signatured_type so far. */ + int num_psymtabs () const + { return m_num_psymtabs; } + private: /* This function is mapped across the sections and remembers the offset and size of each of the debugging sections we are @@ -278,12 +283,38 @@ struct dwarf2_per_objfile const struct comp_unit_head *cu_header, unsigned int *bytes_read_ptr); + /* Resize the M_SYMTABS vector to the needed size (the number of partial + symtabs allocated by the per-bfd). */ + void resize_symtabs () + { + /* The symtabs vector should only grow, not shrink. */ + gdb_assert (per_bfd->num_psymtabs () >= m_symtabs.size ()); + + m_symtabs.resize (per_bfd->num_psymtabs ()); + } + + /* Return true if the symtab corresponding to PER_CU has been set, + false otherwise. */ + bool symtab_set_p (const dwarf2_per_cu_data *per_cu) const; + + /* Return the compunit_symtab associated to PER_CU, if it has been created. */ + compunit_symtab *get_symtab (const dwarf2_per_cu_data *per_cu) const; + + /* Set the compunit_symtab associated to PER_CU. */ + void set_symtab (const dwarf2_per_cu_data *per_cu, compunit_symtab *symtab); + /* Back link. */ struct objfile *objfile; /* Pointer to the data that is (possibly) shared between this objfile and other objfiles backed by the same BFD. */ struct dwarf2_per_bfd *per_bfd; + +private: + /* Hold the corresponding compunit_symtab for each CU or TU. This + is indexed by dwarf2_per_cu_data::index. A NULL value means + that the CU/TU has not been expanded yet. */ + std::vector m_symtabs; }; /* Get the dwarf2_per_objfile associated to OBJFILE. */ @@ -291,17 +322,19 @@ struct dwarf2_per_objfile dwarf2_per_objfile *get_dwarf2_per_objfile (struct objfile *objfile); /* A partial symtab specialized for DWARF. */ -struct dwarf2_psymtab : public standard_psymtab +struct dwarf2_psymtab : public partial_symtab { dwarf2_psymtab (const char *filename, struct objfile *objfile, dwarf2_per_cu_data *per_cu) - : standard_psymtab (filename, objfile, 0), + : partial_symtab (filename, objfile, 0), per_cu_data (per_cu) { } void read_symtab (struct objfile *) override; void expand_psymtab (struct objfile *) override; + bool readin_p (struct objfile *) const override; + compunit_symtab *get_compunit_symtab (struct objfile *) const override; struct dwarf2_per_cu_data *per_cu_data; }; -- 2.30.2