Move dwarf2_per_bfd::index_addrmap to mapped_gdb_index

dwarf2_per_bfd::index_addrmap is only used by the .gdb_index reader,
so this field can be moved to mapped_gdb_index instead.  Then,
cooked_index_functions::find_per_cu can be removed in favor of a
method on the index object.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31821
Approved-By: Simon Marchi <simon.marchi@efficios.com>
This commit is contained in:
Tom Tromey 2024-05-30 10:39:17 -06:00
parent 5df6499c83
commit 2e3b7a3893
5 changed files with 25 additions and 37 deletions

View File

@ -671,7 +671,7 @@ class cooked_index : public dwarf_scanner_base
/* Look up ADDR in the address map, and return either the
corresponding CU, or nullptr if the address could not be
found. */
dwarf2_per_cu_data *lookup (unrelocated_addr addr);
dwarf2_per_cu_data *lookup (unrelocated_addr addr) override;
/* Return a new vector of all the addrmaps used by all the indexes
held by this object. */
@ -737,9 +737,6 @@ struct cooked_index_functions : public dwarf2_base_index_functions
return table;
}
dwarf2_per_cu_data *find_per_cu (dwarf2_per_bfd *per_bfd,
unrelocated_addr adjusted_pc) override;
struct compunit_symtab *find_compunit_symtab_by_address
(struct objfile *objfile, CORE_ADDR address) override;

View File

@ -82,6 +82,11 @@ struct dwarf_scanner_base
virtual void wait_completely ()
{
}
/* Look up ADDR, and return either the corresponding CU, or nullptr
if the address could not be found. */
virtual dwarf2_per_cu_data *lookup (unrelocated_addr addr)
{ return nullptr; }
};
/* Base class containing bits shared by both .gdb_index and

View File

@ -91,6 +91,9 @@ struct mapped_gdb_index final : public mapped_index_base
/* The shortcut table data. */
gdb::array_view<const gdb_byte> shortcut_table;
/* An address map that maps from PC to dwarf2_per_cu_data. */
addrmap_fixed *index_addrmap = nullptr;
/* Return the index into the constant pool of the name of the IDXth
symbol in the symbol table. */
offset_type symbol_name_index (offset_type idx) const
@ -129,6 +132,15 @@ struct mapped_gdb_index final : public mapped_index_base
{
return version >= 8;
}
dwarf2_per_cu_data *lookup (unrelocated_addr addr) override
{
if (index_addrmap == nullptr)
return nullptr;
void *obj = index_addrmap->find (static_cast<CORE_ADDR> (addr));
return static_cast<dwarf2_per_cu_data *> (obj);
}
};
struct dwarf2_gdb_index : public dwarf2_base_index_functions
@ -528,8 +540,7 @@ create_signatured_type_table_from_gdb_index
per_bfd->signatured_types = std::move (sig_types_hash);
}
/* Read the address map data from the mapped GDB index, and use it to
populate the index_addrmap. */
/* Read the address map data from the mapped GDB index. */
static void
create_addrmap_from_gdb_index (dwarf2_per_objfile *per_objfile,
@ -570,7 +581,7 @@ create_addrmap_from_gdb_index (dwarf2_per_objfile *per_objfile,
mutable_map.set_empty (lo, hi - 1, per_bfd->get_cu (cu_index));
}
per_bfd->index_addrmap
index->index_addrmap
= new (&per_bfd->obstack) addrmap_fixed (&per_bfd->obstack, &mutable_map);
}

View File

@ -2997,17 +2997,6 @@ recursively_find_pc_sect_compunit_symtab (struct compunit_symtab *cust,
return NULL;
}
dwarf2_per_cu_data *
dwarf2_base_index_functions::find_per_cu (dwarf2_per_bfd *per_bfd,
unrelocated_addr adjusted_pc)
{
if (per_bfd->index_addrmap == nullptr)
return nullptr;
void *obj = per_bfd->index_addrmap->find ((CORE_ADDR) adjusted_pc);
return static_cast<dwarf2_per_cu_data *> (obj);
}
struct compunit_symtab *
dwarf2_base_index_functions::find_pc_sect_compunit_symtab
(struct objfile *objfile,
@ -3019,10 +3008,14 @@ dwarf2_base_index_functions::find_pc_sect_compunit_symtab
struct compunit_symtab *result;
dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
if (per_bfd->index_table == nullptr)
return nullptr;
CORE_ADDR baseaddr = objfile->text_section_offset ();
struct dwarf2_per_cu_data *data
= find_per_cu (per_objfile->per_bfd, (unrelocated_addr) (pc - baseaddr));
= per_bfd->index_table->lookup ((unrelocated_addr) (pc - baseaddr));
if (data == nullptr)
return nullptr;
@ -16559,16 +16552,6 @@ cooked_indexer::make_index (cutu_reader *reader)
index_dies (reader, reader->info_ptr, nullptr, false);
}
dwarf2_per_cu_data *
cooked_index_functions::find_per_cu (dwarf2_per_bfd *per_bfd,
unrelocated_addr adjusted_pc)
{
cooked_index *table
= (gdb::checked_static_cast<cooked_index *>
(per_bfd->index_table.get ()));
return table->lookup (adjusted_pc);
}
struct compunit_symtab *
cooked_index_functions::find_compunit_symtab_by_address
(struct objfile *objfile, CORE_ADDR address)

View File

@ -534,9 +534,6 @@ struct dwarf2_per_bfd
std::unordered_map<sect_offset, std::vector<sect_offset>,
gdb::hash_enum<sect_offset>>
abstract_to_concrete;
/* The address map that is used by the DWARF index code. */
addrmap_fixed *index_addrmap = nullptr;
};
/* An iterator for all_units that is based on index. This
@ -846,11 +843,6 @@ struct dwarf2_base_index_functions : public quick_symbol_functions
void expand_all_symtabs (struct objfile *objfile) override;
/* A helper function that finds the per-cu object from an "adjusted"
PC -- a PC with the base text offset removed. */
virtual dwarf2_per_cu_data *find_per_cu (dwarf2_per_bfd *per_bfd,
unrelocated_addr adjusted_pc);
struct compunit_symtab *find_pc_sect_compunit_symtab
(struct objfile *objfile, struct bound_minimal_symbol msymbol,
CORE_ADDR pc, struct obj_section *section, int warn_if_readin)