aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-11-22 17:05:55 -0700
committerTom Tromey <tom@tromey.com>2022-04-20 09:10:03 -0600
commita827b8ec32f9e0ed10b2bf647ce983db813a3d3c (patch)
tree9226cd00839bc1cfce10251a42651834f0ceaa78 /gdb
parentf75a1d3a732d96ed4adadddaaeafe17732453256 (diff)
downloadgdb-a827b8ec32f9e0ed10b2bf647ce983db813a3d3c.zip
gdb-a827b8ec32f9e0ed10b2bf647ce983db813a3d3c.tar.gz
gdb-a827b8ec32f9e0ed10b2bf647ce983db813a3d3c.tar.bz2
Unify the DWARF index holders
The dwarf2_per_bfd object has a separate field for each possible kind of index. Until an earlier patch in this series, two of these were even derived from a common base class, but still had separate slots. This patch unifies all the index fields using the common base class that was introduced earlier in this series. This makes it more obvious that only a single index can be active at a time, and also removes some code from dwarf2_initialize_objfile.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/dwarf2/index-write.c28
-rw-r--r--gdb/dwarf2/read.c107
-rw-r--r--gdb/dwarf2/read.h10
3 files changed, 72 insertions, 73 deletions
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index 58b0f0b..b7a2e21 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -1087,12 +1087,11 @@ write_gdbindex_1 (FILE *out_file,
/* Write the contents of the internal "cooked" index. */
static void
-write_cooked_index (dwarf2_per_objfile *per_objfile,
+write_cooked_index (cooked_index_vector *table,
const cu_index_map &cu_index_htab,
struct mapped_symtab *symtab)
{
- for (const cooked_index_entry *entry
- : per_objfile->per_bfd->cooked_index_table->all_entries ())
+ for (const cooked_index_entry *entry : table->all_entries ())
{
const auto it = cu_index_htab.find (entry->per_cu);
gdb_assert (it != cu_index_htab.cend ());
@@ -1178,13 +1177,14 @@ write_gdbindex (dwarf2_per_objfile *per_objfile, FILE *out_file,
++this_counter;
}
- write_cooked_index (per_objfile, cu_index_htab, &symtab);
+ cooked_index_vector *table
+ = (static_cast<cooked_index_vector *>
+ (per_objfile->per_bfd->index_table.get ()));
+ write_cooked_index (table, cu_index_htab, &symtab);
/* Dump the address map. */
data_buf addr_vec;
- std::vector<addrmap *> addrmaps
- = per_objfile->per_bfd->cooked_index_table->get_addrmaps ();
- for (auto map : addrmaps)
+ for (auto map : table->get_addrmaps ())
write_address_map (map, addr_vec, cu_index_htab);
/* Now that we've processed all symbols we can shrink their cu_indices
@@ -1250,8 +1250,10 @@ write_debug_names (dwarf2_per_objfile *per_objfile,
- per_objfile->per_bfd->tu_stats.nr_tus));
gdb_assert (types_counter == per_objfile->per_bfd->tu_stats.nr_tus);
- for (const cooked_index_entry *entry
- : per_objfile->per_bfd->cooked_index_table->all_entries ())
+ cooked_index_vector *table
+ = (static_cast<cooked_index_vector *>
+ (per_objfile->per_bfd->index_table.get ()));
+ for (const cooked_index_entry *entry : table->all_entries ())
nametable.insert (entry);
nametable.build ();
@@ -1388,10 +1390,12 @@ write_dwarf_index (dwarf2_per_objfile *per_objfile, const char *dir,
{
struct objfile *objfile = per_objfile->objfile;
- if (per_objfile->per_bfd->cooked_index_table == nullptr)
+ cooked_index_vector *table
+ = (static_cast<cooked_index_vector *>
+ (per_objfile->per_bfd->index_table.get ()));
+ if (table == nullptr)
{
- if (per_objfile->per_bfd->index_table != nullptr
- || per_objfile->per_bfd->debug_names_table != nullptr)
+ if (per_objfile->per_bfd->index_table != nullptr)
error (_("Cannot use an index to create the index"));
error (_("No debugging symbols"));
}
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index aa3bf6e..bb5b636 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2932,7 +2932,8 @@ static void
dw2_symtab_iter_init (struct dw2_symtab_iterator *iter,
dwarf2_per_objfile *per_objfile,
gdb::optional<block_enum> block_index,
- domain_enum domain, offset_type namei)
+ domain_enum domain, offset_type namei,
+ mapped_index &index)
{
iter->per_objfile = per_objfile;
iter->block_index = block_index;
@@ -2942,12 +2943,10 @@ dw2_symtab_iter_init (struct dw2_symtab_iterator *iter,
iter->vec = {};
iter->length = 0;
- mapped_index *index = per_objfile->per_bfd->index_table.get ();
-
- gdb_assert (!index->symbol_name_slot_invalid (namei));
- offset_type vec_idx = index->symbol_vec_index (namei);
+ gdb_assert (!index.symbol_name_slot_invalid (namei));
+ offset_type vec_idx = index.symbol_vec_index (namei);
- iter->vec = offset_view (index->constant_pool.slice (vec_idx));
+ iter->vec = offset_view (index.constant_pool.slice (vec_idx));
iter->length = iter->vec[0];
}
@@ -3078,8 +3077,9 @@ dwarf2_gdb_index::dump (struct objfile *objfile)
{
dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
- gdb_printf (".gdb_index: version %d\n",
- per_objfile->per_bfd->index_table->version);
+ mapped_index *index = (static_cast<mapped_index *>
+ (per_objfile->per_bfd->index_table.get ()));
+ gdb_printf (".gdb_index: version %d\n", index->version);
gdb_printf ("\n");
}
@@ -3129,7 +3129,9 @@ dwarf2_gdb_index::expand_matching_symbols
const block_enum block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
- mapped_index &index = *per_objfile->per_bfd->index_table;
+ mapped_index &index
+ = (static_cast<mapped_index &>
+ (*per_objfile->per_bfd->index_table.get ()));
const char *match_name = name.ada ().lookup_name ().c_str ();
auto matcher = [&] (const char *symname)
@@ -3145,7 +3147,8 @@ dwarf2_gdb_index::expand_matching_symbols
struct dw2_symtab_iterator iter;
struct dwarf2_per_cu_data *per_cu;
- dw2_symtab_iter_init (&iter, per_objfile, block_kind, domain, namei);
+ dw2_symtab_iter_init (&iter, per_objfile, block_kind, domain, namei,
+ index);
while ((per_cu = dw2_symtab_iter_next (&iter, index)) != NULL)
dw2_expand_symtabs_matching_one (per_cu, per_objfile, nullptr,
nullptr);
@@ -3967,7 +3970,9 @@ dw2_expand_marked_cus
{
offset_type vec_len, vec_idx;
bool global_seen = false;
- mapped_index &index = *per_objfile->per_bfd->index_table;
+ mapped_index &index
+ = (static_cast<mapped_index &>
+ (*per_objfile->per_bfd->index_table.get ()));
offset_view vec (index.constant_pool.slice (index.symbol_vec_index (idx)));
vec_len = vec[0];
@@ -4185,7 +4190,9 @@ dwarf2_gdb_index::expand_symtabs_matching
return true;
}
- mapped_index &index = *per_objfile->per_bfd->index_table;
+ mapped_index &index
+ = (static_cast<mapped_index &>
+ (*per_objfile->per_bfd->index_table.get ()));
bool result
= dw2_expand_symtabs_matching_symbol (index, *lookup_name,
@@ -4683,7 +4690,7 @@ dwarf2_read_debug_names (dwarf2_per_objfile *per_objfile)
create_addrmap_from_aranges (per_objfile, &per_bfd->debug_aranges);
- per_bfd->debug_names_table = std::move (map);
+ per_bfd->index_table = std::move (map);
per_bfd->quick_file_names_table =
create_quick_file_names_table (per_bfd->all_comp_units.size ());
@@ -5119,7 +5126,9 @@ dwarf2_debug_names_index::expand_matching_symbols
{
dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
- mapped_debug_names &map = *per_objfile->per_bfd->debug_names_table;
+ mapped_debug_names &map
+ = (static_cast<mapped_debug_names &>
+ (*per_objfile->per_bfd->index_table.get ()));
const block_search_flags block_flags
= global ? SEARCH_GLOBAL_BLOCK : SEARCH_STATIC_BLOCK;
@@ -5179,7 +5188,9 @@ dwarf2_debug_names_index::expand_symtabs_matching
return true;
}
- mapped_debug_names &map = *per_objfile->per_bfd->debug_names_table;
+ mapped_debug_names &map
+ = (static_cast<mapped_debug_names &>
+ (*per_objfile->per_bfd->index_table.get ()));
bool result
= dw2_expand_symtabs_matching_symbol (map, *lookup_name,
@@ -5284,38 +5295,20 @@ dwarf2_initialize_objfile (struct objfile *objfile)
return;
}
- /* Was a debug names index already read when we processed an objfile sharing
- PER_BFD? */
- if (per_bfd->debug_names_table != nullptr)
- {
- dwarf_read_debug_printf ("re-using shared debug names table");
- objfile->qf.push_front
- (per_bfd->debug_names_table->make_quick_functions ());
- return;
- }
-
/* Was a GDB index already read when we processed an objfile sharing
PER_BFD? */
if (per_bfd->index_table != nullptr)
{
- dwarf_read_debug_printf ("re-using shared index table");
+ dwarf_read_debug_printf ("re-using symbols");
objfile->qf.push_front (per_bfd->index_table->make_quick_functions ());
return;
}
- if (per_bfd->cooked_index_table != nullptr)
- {
- dwarf_read_debug_printf ("re-using cooked index table");
- objfile->qf.push_front
- (per_bfd->cooked_index_table->make_quick_functions ());
- return;
- }
-
if (dwarf2_read_debug_names (per_objfile))
{
dwarf_read_debug_printf ("found debug names");
objfile->qf.push_front
- (per_bfd->debug_names_table->make_quick_functions ());
+ (per_bfd->index_table->make_quick_functions ());
return;
}
@@ -5354,7 +5347,7 @@ dwarf2_build_psymtabs (struct objfile *objfile, bool already_attached)
if (already_attached)
{
- if (per_objfile->per_bfd->cooked_index_table != nullptr)
+ if (per_objfile->per_bfd->index_table != nullptr)
return;
}
else
@@ -7134,11 +7127,11 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile)
}),
indexes.end ());
indexes.shrink_to_fit ();
- per_bfd->cooked_index_table.reset
- (new cooked_index_vector (std::move (indexes)));
- const cooked_index_entry *main_entry
- = per_bfd->cooked_index_table->get_main ();
+ cooked_index_vector *vec = new cooked_index_vector (std::move (indexes));
+ per_bfd->index_table.reset (vec);
+
+ const cooked_index_entry *main_entry = vec->get_main ();
if (main_entry != nullptr)
set_objfile_main_name (objfile, main_entry->name,
main_entry->per_cu->lang);
@@ -18478,12 +18471,14 @@ cooked_index_functions::find_pc_sect_compunit_symtab
int warn_if_readin)
{
dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
- if (per_objfile->per_bfd->cooked_index_table == nullptr)
+ if (per_objfile->per_bfd->index_table == nullptr)
return nullptr;
CORE_ADDR baseaddr = objfile->text_section_offset ();
- dwarf2_per_cu_data *per_cu
- = per_objfile->per_bfd->cooked_index_table->lookup (pc - baseaddr);
+ cooked_index_vector *table
+ = (static_cast<cooked_index_vector *>
+ (per_objfile->per_bfd->index_table.get ()));
+ dwarf2_per_cu_data *per_cu = table->lookup (pc - baseaddr);
if (per_cu == nullptr)
return nullptr;
@@ -18507,12 +18502,14 @@ cooked_index_functions::find_compunit_symtab_by_address
return nullptr;
dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
- if (per_objfile->per_bfd->cooked_index_table == nullptr)
+ if (per_objfile->per_bfd->index_table == nullptr)
return nullptr;
CORE_ADDR baseaddr = objfile->data_section_offset ();
- dwarf2_per_cu_data *per_cu
- = per_objfile->per_bfd->cooked_index_table->lookup (address - baseaddr);
+ cooked_index_vector *table
+ = (static_cast<cooked_index_vector *>
+ (per_objfile->per_bfd->index_table.get ()));
+ dwarf2_per_cu_data *per_cu = table->lookup (address - baseaddr);
if (per_cu == nullptr)
return nullptr;
@@ -18528,7 +18525,7 @@ cooked_index_functions::expand_matching_symbols
symbol_compare_ftype *ordered_compare)
{
dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
- if (per_objfile->per_bfd->cooked_index_table == nullptr)
+ if (per_objfile->per_bfd->index_table == nullptr)
return;
const block_search_flags search_flags = (global
? SEARCH_GLOBAL_BLOCK
@@ -18537,8 +18534,10 @@ cooked_index_functions::expand_matching_symbols
symbol_name_matcher_ftype *name_match
= lang->get_symbol_name_matcher (lookup_name);
- for (const cooked_index_entry *entry
- : per_objfile->per_bfd->cooked_index_table->all_entries ())
+ cooked_index_vector *table
+ = (static_cast<cooked_index_vector *>
+ (per_objfile->per_bfd->index_table.get ()));
+ for (const cooked_index_entry *entry : table->all_entries ())
{
if (entry->parent_entry != nullptr)
continue;
@@ -18564,7 +18563,7 @@ cooked_index_functions::expand_symtabs_matching
enum search_domain kind)
{
dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
- if (per_objfile->per_bfd->cooked_index_table == nullptr)
+ if (per_objfile->per_bfd->index_table == nullptr)
return true;
dw_expand_symtabs_matching_file_matcher (per_objfile, file_matcher);
@@ -18602,14 +18601,16 @@ cooked_index_functions::expand_symtabs_matching
language_ada
};
+ cooked_index_vector *table
+ = (static_cast<cooked_index_vector *>
+ (per_objfile->per_bfd->index_table.get ()));
for (enum language lang : unique_styles)
{
std::vector<gdb::string_view> name_vec
= lookup_name_without_params.split_name (lang);
- for (const cooked_index_entry *entry
- : per_objfile->per_bfd->cooked_index_table->find (name_vec.back (),
- completing))
+ for (const cooked_index_entry *entry : table->find (name_vec.back (),
+ completing))
{
/* No need to consider symbols from expanded CUs. */
if (per_objfile->symtab_set_p (entry->per_cu))
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index f3b09c6..b58c574 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -441,14 +441,8 @@ public:
VMA of 0. */
bool has_section_at_zero = false;
- /* The mapped index, or NULL if .gdb_index is missing or not being used. */
- std::unique_ptr<mapped_index> index_table;
-
- /* The mapped index, or NULL if .debug_names is missing or not being used. */
- std::unique_ptr<mapped_debug_names> debug_names_table;
-
- /* The cooked index, or NULL if not using one. */
- std::unique_ptr<cooked_index_vector> cooked_index_table;
+ /* The mapped index, or NULL in the readnow case. */
+ std::unique_ptr<dwarf_scanner_base> index_table;
/* When using index_table, this keeps track of all quick_file_names entries.
TUs typically share line table entries with a CU, so we maintain a