[PATCH v3 28/33] Genericize addrmap handling in the DWARF index writer
Tom Tromey
tom@tromey.com
Sat Dec 4 20:38:39 GMT 2021
This updates the DWARF index writing code to make the addrmap-writing
a bit more generic. Now, it can handle multiple maps, and it can work
using the maps generated by the new indexer.
Note that the new addrmap_index_data::using_index field will be
deleted in a future patch, when the rest of the DWARF psymtab code is
removed.
---
gdb/dwarf2/index-write.c | 37 ++++++++++++++++++++++++++++---------
1 file changed, 28 insertions(+), 9 deletions(-)
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index 8bf7e8fdd1c..13b929fea54 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -412,8 +412,11 @@ typedef std::unordered_map<dwarf2_per_cu_data *, unsigned int> cu_index_map;
/* Helper struct for building the address table. */
struct addrmap_index_data
{
- addrmap_index_data (data_buf &addr_vec_, cu_index_map &cu_index_htab_)
- : addr_vec (addr_vec_), cu_index_htab (cu_index_htab_)
+ addrmap_index_data (data_buf &addr_vec_, cu_index_map &cu_index_htab_,
+ bool using_index_)
+ : addr_vec (addr_vec_),
+ cu_index_htab (cu_index_htab_),
+ using_index (using_index_)
{}
data_buf &addr_vec;
@@ -421,6 +424,8 @@ struct addrmap_index_data
int operator() (CORE_ADDR start_addr, void *obj);
+ /* True if the DWARF reader uses the new DWARF indexer. */
+ bool using_index;
/* True if the previous_* fields are valid.
We can't write an entry until we see the next entry (since it is only then
that we know the end of the entry). */
@@ -447,7 +452,11 @@ add_address_entry (data_buf &addr_vec,
int
addrmap_index_data::operator() (CORE_ADDR start_addr, void *obj)
{
- dwarf2_psymtab *pst = (dwarf2_psymtab *) obj;
+ dwarf2_per_cu_data *per_cu;
+ if (using_index)
+ per_cu = (dwarf2_per_cu_data *) obj;
+ else
+ per_cu = obj == nullptr ? nullptr : ((dwarf2_psymtab *) obj)->per_cu_data;
if (previous_valid)
add_address_entry (addr_vec,
@@ -455,9 +464,9 @@ addrmap_index_data::operator() (CORE_ADDR start_addr, void *obj)
previous_cu_index);
previous_cu_start = start_addr;
- if (pst != NULL)
+ if (per_cu != NULL)
{
- const auto it = cu_index_htab.find (pst->per_cu_data);
+ const auto it = cu_index_htab.find (per_cu);
gdb_assert (it != cu_index_htab.cend ());
previous_cu_index = it->second;
previous_valid = true;
@@ -474,9 +483,10 @@ addrmap_index_data::operator() (CORE_ADDR start_addr, void *obj)
static void
write_address_map (struct addrmap *addrmap, data_buf &addr_vec,
- cu_index_map &cu_index_htab)
+ cu_index_map &cu_index_htab, bool using_index)
{
- struct addrmap_index_data addrmap_index_data (addr_vec, cu_index_htab);
+ struct addrmap_index_data addrmap_index_data (addr_vec, cu_index_htab,
+ using_index);
addrmap_foreach (addrmap, addrmap_index_data);
@@ -1377,8 +1387,17 @@ write_gdbindex (dwarf2_per_objfile *per_objfile, FILE *out_file,
/* Dump the address map. */
data_buf addr_vec;
- write_address_map (per_objfile->per_bfd->partial_symtabs->psymtabs_addrmap,
- addr_vec, cu_index_htab);
+ if (per_objfile->per_bfd->using_index)
+ {
+ std::vector<addrmap *> addrmaps
+ = per_objfile->per_bfd->cooked_index_table->get_addrmaps ();
+ for (auto map : addrmaps)
+ write_address_map (map, addr_vec, cu_index_htab, true);
+ }
+ else
+ write_address_map (per_objfile->per_bfd->partial_symtabs->psymtabs_addrmap,
+ addr_vec, cu_index_htab,
+ per_objfile->per_bfd->using_index);
/* Now that we've processed all symbols we can shrink their cu_indices
lists. */
--
2.31.1
More information about the Gdb-patches
mailing list