[PATCH 08/14] Remove symtab links from dwarf2_psymtab and dwarf2_per_cu_quick_data

Tom Tromey
2020-02-15T16:55:00Z

This removes the links from dwarf2_psymtab and
dwarf2_per_cu_quick_data to the compunit_symtab. Now, the DWARF code
uses the index in these objects to find the corresponding symtab in
the "unshared" object.

2020-02-15 Tom Tromey <tom@tromey.com>

* dwarf2/read.h (struct dwarf2_unshareable) <symtabs>: New
member.
(struct dwarf2_psymtab): Derive from partial_symtab.
<readin_p, get_compunit_symtab>: Declare methods.
* dwarf2/read.c (struct dwarf2_per_cu_quick_data)
<compunit_symtab>: 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, does)
(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): Resize the symtabs vector.
(dwarf2_resize_unshareable): New function.
(dwarf2_initialize_objfile): Call dwarf2_resize_unshareable.
---
gdb/ChangeLog | 26 +++++++
gdb/dwarf2/read.c | 194 +++++++++++++++++++++++++++++++---------------
gdb/dwarf2/read.h | 14 +++-
3 files changed, 170 insertions(+), 64 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 281d39ad271..44fdb070e49 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2205,10 +2205,6 @@ struct dwarf2_per_cu_quick_data
NOTE: This points into dwarf2_per_objfile->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;
@@ -2332,9 +2328,9 @@ 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->using_index
- ? per_cu->v.quick->compunit_symtab == NULL
- : (per_cu->v.psymtab == NULL || !per_cu->v.psymtab->readin))
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[per_cu->index];
+ if (!symtab.has_value ())
{
queue_comp_unit (per_cu, language_minimal);
load_cu (per_cu, skip_partial);
@@ -2369,7 +2365,10 @@ 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->using_index);
- if (!per_cu->v.quick->compunit_symtab)
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[per_cu->index];
+
+ if (!symtab.has_value ())
{
free_cached_comp_units freer (dwarf2_per_objfile);
scoped_restore decrementer = increment_reading_symtab ();
@@ -2377,7 +2376,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 *symtab;
}

/* See declaration. */
@@ -3289,7 +3288,11 @@ 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)
+ struct dwarf2_per_objfile *dwarf2_per_objfile
+ = get_dwarf2_per_objfile (objfile);
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[per_cu->index];
+ if (symtab.has_value ())
return 0;

/* This may expand more than one symtab, and we want to iterate over
@@ -3317,7 +3320,9 @@ dw2_map_symtabs_matching_filename
for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
{
/* We only need to look at symtabs not already expanded. */
- if (per_cu->v.quick->compunit_symtab)
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[per_cu->index];
+ if (symtab.has_value ())
continue;

quick_file_names *file_data = dw2_get_file_names (per_cu);
@@ -3458,7 +3463,9 @@ dw2_symtab_iter_next (struct dw2_symtab_iterator *iter)
dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cutu (cu_index);

/* Skip if already read in. */
- if (per_cu->v.quick->compunit_symtab)
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[per_cu->index];
+ if (symtab.has_value ())
continue;

/* Check static vs global. */
@@ -3573,7 +3580,9 @@ dw2_print_stats (struct objfile *objfile)
{
dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->get_cutu (i);

- if (!per_cu->v.quick->compunit_symtab)
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[per_cu->index];
+ if (!symtab.has_value ())
++count;
}
printf_filtered (_(" Number of read CUs: %d\n"), total - count);
@@ -3656,7 +3665,9 @@ dw2_expand_symtabs_with_fullname (struct objfile *objfile,
for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
{
/* We only need to look at symtabs not already expanded. */
- if (per_cu->v.quick->compunit_symtab)
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[per_cu->index];
+ if (symtab.has_value ())
continue;

quick_file_names *file_data = dw2_get_file_names (per_cu);
@@ -4455,15 +4466,19 @@ 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);
+ struct dwarf2_per_objfile *dwarf2_per_objfile
+ = per_cu->dwarf2_per_objfile;
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[per_cu->index];
+ bool symtab_was_null = !symtab.has_value () || *symtab == nullptr;

dw2_instantiate_symtab (per_cu, false);

if (expansion_notify != NULL
&& symtab_was_null
- && per_cu->v.quick->compunit_symtab != NULL)
- expansion_notify (per_cu->v.quick->compunit_symtab);
+ && symtab.has_value ()
+ && *symtab != nullptr)
+ expansion_notify (*symtab);
}
}

@@ -4583,7 +4598,9 @@ 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)
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[per_cu->index];
+ if (symtab.has_value ())
continue;

quick_file_names *file_data = dw2_get_file_names (per_cu);
@@ -4708,7 +4725,11 @@ dw2_find_pc_sect_compunit_symtab (struct objfile *objfile,
if (!data)
return NULL;

- if (warn_if_readin && data->v.quick->compunit_symtab)
+ struct dwarf2_per_objfile *dwarf2_per_objfile
+ = get_dwarf2_per_objfile (objfile);
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[data->index];
+ if (warn_if_readin && symtab.has_value ())
warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
paddress (get_objfile_arch (objfile), pc));

@@ -4741,7 +4762,9 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,

for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
{
- if (per_cu->v.quick->compunit_symtab)
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[per_cu->index];
+ if (symtab.has_value ())
{
void **slot = htab_find_slot (visited.get (),
per_cu->v.quick->file_names,
@@ -4754,7 +4777,9 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
{
/* We only need to look at symtabs not already expanded. */
- if (per_cu->v.quick->compunit_symtab)
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[per_cu->index];
+ if (symtab.has_value ())
continue;

quick_file_names *file_data = dw2_get_file_names (per_cu);
@@ -5386,7 +5411,9 @@ dw2_debug_names_iterator::next ()
}

/* Skip if already read in. */
- if (per_cu->v.quick->compunit_symtab)
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[per_cu->index];
+ if (symtab.has_value ())
goto again;

/* Check static vs global. */
@@ -5627,11 +5654,12 @@ dw2_debug_names_map_matching_symbols
the psymtab code does. */
for (dwarf2_per_cu_data *per_cu : dwarf2_per_objfile->all_comp_units)
{
- struct compunit_symtab *cust = per_cu->v.quick->compunit_symtab;
- if (cust != nullptr)
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[per_cu->index];
+ if (symtab.has_value () && *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;
@@ -5748,6 +5776,15 @@ get_gdb_index_contents_from_cache_dwz (objfile *obj, dwz_file *dwz)
return global_index_cache.lookup_gdb_index (build_id, &dwz->index_cache_res);
}

+/* Make sure we have space for the compunit_symtabs we may need. */
+
+static void
+dwarf2_resize_unshareable (dwarf2_per_objfile *dwarf2_per_objfile)
+{
+ dwarf2_per_objfile->unshareable->symtabs.resize
+ (dwarf2_per_objfile->num_psymtabs);
+}
+
/* See symfile.h. */

bool
@@ -5768,6 +5805,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
dwarf2_per_objfile->quick_file_names_table
= create_quick_file_names_table
(dwarf2_per_objfile->all_comp_units.size ());
+ dwarf2_resize_unshareable (dwarf2_per_objfile);

for (int i = 0; i < (dwarf2_per_objfile->all_comp_units.size ()
+ dwarf2_per_objfile->all_type_units.size ()); ++i)
@@ -5788,6 +5826,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_resize_unshareable (dwarf2_per_objfile);
return true;
}

@@ -5796,6 +5835,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
get_gdb_index_contents_from_section<dwz_file>))
{
*index_kind = dw_index_kind::GDB_INDEX;
+ dwarf2_resize_unshareable (dwarf2_per_objfile);
return true;
}

@@ -5806,6 +5846,7 @@ dwarf2_initialize_objfile (struct objfile *objfile, dw_index_kind *index_kind)
{
global_index_cache.hit ();
*index_kind = dw_index_kind::GDB_INDEX;
+ dwarf2_resize_unshareable (dwarf2_per_objfile);
return true;
}

@@ -5834,6 +5875,8 @@ dwarf2_build_psymtabs (struct objfile *objfile)
dwarf2_build_psymtabs_hard (dwarf2_per_objfile);
psymtabs.keep ();

+ dwarf2_resize_unshareable (dwarf2_per_objfile);
+
/* (maybe) store an index in the cache. */
global_index_cache.store (dwarf2_per_objfile);
}
@@ -6259,7 +6302,7 @@ fill_in_sig_entry_from_dwo_entry (struct dwarf2_per_objfile *dwarf2_per_objfile,
if (dwarf2_per_objfile->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->unshareable->symtabs[sig_entry->per_cu.index].has_value ());
}
else
gdb_assert (sig_entry->per_cu.v.psymtab == NULL);
@@ -8700,7 +8743,10 @@ dwarf2_psymtab::read_symtab (struct objfile *objfile)
struct dwarf2_per_objfile *dwarf2_per_objfile
= get_dwarf2_per_objfile (objfile);

- gdb_assert (!readin);
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[per_cu_data->index];
+ gdb_assert (!symtab.has_value ());
+
/* 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
@@ -8796,9 +8842,9 @@ process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile)
{
dwarf2_queue_item &item = dwarf2_per_objfile->queue.front ();

- if ((dwarf2_per_objfile->using_index
- ? !item.per_cu->v.quick->compunit_symtab
- : (item.per_cu->v.psymtab && !item.per_cu->v.psymtab->readin))
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[item.per_cu->index];
+ if (!symtab.has_value ()
/* Skip dummy CUs. */
&& item.per_cu->cu != NULL)
{
@@ -8853,24 +8899,57 @@ process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile)
void
dwarf2_psymtab::expand_psymtab (struct objfile *objfile)
{
- struct dwarf2_per_cu_data *per_cu;
-
- if (readin)
- return;
-
- read_dependencies (objfile);
-
- per_cu = per_cu_data;
+ struct dwarf2_per_objfile *dwarf2_per_objfile
+ = get_dwarf2_per_objfile (objfile);

- if (per_cu == NULL)
+ if (per_cu_data == NULL)
{
/* It's an include file, no symbols to read for it.
Everything is in the parent symtab. */
- readin = true;
return;
}

- dw2_do_instantiate_symtab (per_cu, false);
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[per_cu_data->index];
+
+ if (symtab.has_value ())
+ return;
+
+ read_dependencies (objfile);
+
+ dw2_do_instantiate_symtab (per_cu_data, false);
+}
+
+/* See psympriv.h. */
+
+bool
+dwarf2_psymtab::readin_p (struct objfile *objfile) const
+{
+ if (per_cu_data == nullptr)
+ return true;
+
+ dwarf2_per_objfile *dwarf2_per_objfile
+ = get_dwarf2_per_objfile (objfile);
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[per_cu_data->index];
+ return symtab.has_value ();
+}
+
+/* See psympriv.h. */
+
+compunit_symtab *
+dwarf2_psymtab::get_compunit_symtab (struct objfile *objfile) const
+{
+ if (per_cu_data == nullptr)
+ return nullptr;
+
+ dwarf2_per_objfile *dwarf2_per_objfile
+ = get_dwarf2_per_objfile (objfile);
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[per_cu_data->index];
+ if (!symtab.has_value ())
+ return nullptr;
+ return *symtab;
}

/* Trivial hash function for die_info: the hash value of a DIE
@@ -9413,9 +9492,12 @@ rust_union_quirks (struct dwarf2_cu *cu)
static struct compunit_symtab *
get_compunit_symtab (struct dwarf2_per_cu_data *per_cu)
{
- return (per_cu->dwarf2_per_objfile->using_index
- ? per_cu->v.quick->compunit_symtab
- : per_cu->v.psymtab->compunit_symtab);
+ struct dwarf2_per_objfile *dwarf2_per_objfile
+ = per_cu->dwarf2_per_objfile;
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[per_cu->index];
+ gdb_assert (symtab.has_value ());
+ return *symtab;
}

/* A helper function for computing the list of all symbol tables
@@ -9621,14 +9703,9 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
cust->call_site_htab = cu->call_site_htab;
}

- if (dwarf2_per_objfile->using_index)
- per_cu->v.quick->compunit_symtab = cust;
- else
- {
- dwarf2_psymtab *pst = per_cu->v.psymtab;
- pst->compunit_symtab = cust;
- pst->readin = true;
- }
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[per_cu->index];
+ symtab = cust;

/* Push it for inclusion processing later. */
dwarf2_per_objfile->just_read_cus.push_back (per_cu);
@@ -9701,14 +9778,9 @@ process_full_type_unit (struct dwarf2_per_cu_data *per_cu,
cust = sig_type->type_unit_group->compunit_symtab;
}

- if (dwarf2_per_objfile->using_index)
- per_cu->v.quick->compunit_symtab = cust;
- else
- {
- dwarf2_psymtab *pst = per_cu->v.psymtab;
- pst->compunit_symtab = cust;
- pst->readin = true;
- }
+ gdb::optional<compunit_symtab *> &symtab
+ = dwarf2_per_objfile->unshareable->symtabs[per_cu->index];
+ symtab = cust;

/* Not needed any more. */
cu->reset_builder ();
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 5fc7f7f72e5..98d58fb6880 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -82,6 +82,10 @@ struct dwarf2_unshareable
This is NULL if not allocated yet.
The mapping is done via (CU/TU + DIE offset) -> type. */
htab_up die_type_hash;
+
+ /* Hold the corresponding compunit_symtab for each CU or TU. This
+ is indexed by dwarf2_per_cu_data::index. */
+ std::vector<gdb::optional<compunit_symtab *>> symtabs;
};

/* Collection of data recorded per objfile.
@@ -281,22 +285,26 @@ public:
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)
- : standard_psymtab (filename, objfile)
+ : partial_symtab (filename, objfile)
{
}

dwarf2_psymtab (const char *filename, struct objfile *objfile,
CORE_ADDR addr)
- : standard_psymtab (filename, objfile, addr)
+ : partial_symtab (filename, objfile, addr)
{
}

void read_symtab (struct objfile *) override;
void expand_psymtab (struct objfile *) override;

+ bool readin_p (struct objfile *) const override;
+ struct compunit_symtab *get_compunit_symtab (struct objfile *) const
+ override;
+
struct dwarf2_per_cu_data *per_cu_data;
};

--
2.17.2