[PATCH] Move dwarf2_per_bfd::index_addrmap to mapped_gdb_index
Tom Tromey
tromey@adacore.com
Thu May 30 16:41:14 GMT 2024
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
---
gdb/dwarf2/cooked-index.h | 5 +----
gdb/dwarf2/mapped-index.h | 5 +++++
gdb/dwarf2/read-gdb-index.c | 17 ++++++++++++++---
gdb/dwarf2/read.c | 27 +++++----------------------
gdb/dwarf2/read.h | 8 --------
5 files changed, 25 insertions(+), 37 deletions(-)
diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h
index d245570e34d..efd03e61b65 100644
--- a/gdb/dwarf2/cooked-index.h
+++ b/gdb/dwarf2/cooked-index.h
@@ -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;
diff --git a/gdb/dwarf2/mapped-index.h b/gdb/dwarf2/mapped-index.h
index 86a3c59e7e4..b4f6483ea92 100644
--- a/gdb/dwarf2/mapped-index.h
+++ b/gdb/dwarf2/mapped-index.h
@@ -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
diff --git a/gdb/dwarf2/read-gdb-index.c b/gdb/dwarf2/read-gdb-index.c
index 94109244b3e..1fc31fb1444 100644
--- a/gdb/dwarf2/read-gdb-index.c
+++ b/gdb/dwarf2/read-gdb-index.c
@@ -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 ((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);
}
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 4818da58acb..6a19064409c 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -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)
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 7ab61528ab7..e55d053232c 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -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)
--
2.44.0
More information about the Gdb-patches
mailing list