]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Move dwarf2_per_bfd::index_addrmap to mapped_gdb_index
authorTom Tromey <tromey@adacore.com>
Thu, 30 May 2024 16:39:17 +0000 (10:39 -0600)
committerTom Tromey <tromey@adacore.com>
Fri, 31 May 2024 14:26:05 +0000 (08:26 -0600)
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>
gdb/dwarf2/cooked-index.h
gdb/dwarf2/mapped-index.h
gdb/dwarf2/read-gdb-index.c
gdb/dwarf2/read.c
gdb/dwarf2/read.h

index d245570e34def01f2d13cce1bad181668df07656..efd03e61b65d53970476fae66c4d9d4f9ecdb0d7 100644 (file)
@@ -671,7 +671,7 @@ public:
   /* 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;
 
index 86a3c59e7e49d614f8d868725331dd016b8e3b09..b4f6483ea92cffd78732b27e4c8de41228631ec2 100644 (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
index 94109244b3ee5d55da31579989fe56d10602a66e..8cd665cee3726319c82cd7656a53cfdc98630809 100644 (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);
 }
 
index 4818da58acba9272e448f3426520fd7d4bb2018c..6a19064409c291f23dc2d86d01d10b2e9678111a 100644 (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)
index 7ab61528ab7f381385e8949708db7cfed03f8b26..e55d053232c9bf954028f7a418ab52a45a73ccc0 100644 (file)
@@ -534,9 +534,6 @@ public:
   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)