]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add dwarf2_per_bfd::start_reading
authorTom Tromey <tom@tromey.com>
Thu, 6 Feb 2025 21:07:59 +0000 (14:07 -0700)
committerTom Tromey <tom@tromey.com>
Sun, 9 Feb 2025 23:14:01 +0000 (16:14 -0700)
The cooked index "start_reading" method can only be called after the
dwarf2_per_bfd "index_table" member is set.  This patch refactors this
code a little to centralize this constraint, adding a new
dwarf2_per_bfd::start_reading method and another (virtual) method to
dwarf_scanner_base.

This removes some casts, but also is also useful to support another
series I'm working on where the .gdb_index is rewritten.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/dwarf2/cooked-index.h
gdb/dwarf2/mapped-index.h
gdb/dwarf2/read-debug-names.c
gdb/dwarf2/read.c
gdb/dwarf2/read.h

index d1d81f8e2a54e34d6b5a7c671ccf0316a1fdee58..fc29bfdec620d27bc1288641badd3feffc1517d4 100644 (file)
@@ -633,7 +633,7 @@ public:
   DISABLE_COPY_AND_ASSIGN (cooked_index);
 
   /* Start reading the DWARF.  */
-  void start_reading ();
+  void start_reading () override;
 
   /* Called by cooked_index_worker to set the contents of this index
      and transition to the MAIN_AVAILABLE state.  WARN is used to
index 8bc81b4c1ace7d628c5a9152b90d6b7b4f43e8ec..b32fe6ad32d4371ffa78688e0069c47f01159e5c 100644 (file)
@@ -32,6 +32,11 @@ struct dwarf_scanner_base
   virtual ~dwarf_scanner_base () = default;
   DISABLE_COPY_AND_ASSIGN (dwarf_scanner_base);
 
+  /* Start the reading.  This is only really relevant to the cooked
+     index; see cooked-index.h.  */
+  virtual void start_reading ()
+  { }
+
   /* Return a quick_symbol_functions instance that refers back to this
      dwarf_scanner_base.  */
   virtual quick_symbol_functions_up make_quick_functions () const = 0;
index ffc4f3ad5eb028662c694e124c85de105067ff55..3d73bcde9a506648275a8642b65344e61177ebaf 100644 (file)
@@ -769,13 +769,11 @@ do_dwarf2_read_debug_names (dwarf2_per_objfile *per_objfile)
   map.shard = std::make_unique<cooked_index_shard> ();
   map.shard->install_addrmap (&addrmap);
 
-  cooked_index *idx
-    = new debug_names_index (per_objfile,
-                            (std::make_unique<cooked_index_debug_names>
-                             (per_objfile, std::move (map))));
-  per_bfd->index_table.reset (idx);
-
-  idx->start_reading ();
+  auto cidn = (std::make_unique<cooked_index_debug_names>
+              (per_objfile, std::move (map)));
+  auto idx = std::make_unique<debug_names_index> (per_objfile,
+                                                 std::move (cidn));
+  per_bfd->start_reading (std::move (idx));
 
   return true;
 }
index 70e90226d09066d56c04114ce9daaca14c3695f4..be33beac0f113a585af75cfb2f2a9b821fe72771 100644 (file)
@@ -1608,6 +1608,16 @@ dwarf2_per_bfd::map_info_sections (struct objfile *objfile)
     section.read (objfile);
 }
 
+/* See dwarf2/read.h.  */
+
+void
+dwarf2_per_bfd::start_reading (std::unique_ptr<dwarf_scanner_base> new_table)
+{
+  gdb_assert (index_table == nullptr);
+  index_table = std::move (new_table);
+  index_table->start_reading ();
+}
+
 \f
 /* DWARF quick_symbol_functions support.  */
 
@@ -16340,12 +16350,9 @@ start_debug_info_reader (dwarf2_per_objfile *per_objfile)
      scanning; and then start the scanning.  */
   dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
   std::unique_ptr<cooked_index_worker> worker
-    (new cooked_index_debug_info (per_objfile));
-  cooked_index *idx = new cooked_index (per_objfile, std::move (worker));
-  per_bfd->index_table.reset (idx);
-  /* Don't start reading until after 'index_table' is set.  This
-     avoids races.  */
-  idx->start_reading ();
+    = std::make_unique<cooked_index_debug_info> (per_objfile);
+  per_bfd->start_reading (std::make_unique<cooked_index> (per_objfile,
+                                                         std::move (worker)));
 }
 
 \f
index 12d5f066e87e1c657da569ae8ef99f333146beae..ebea8b7b57f4d93ab23b640d269b4e7a0d4495c5 100644 (file)
@@ -451,6 +451,10 @@ struct dwarf2_per_bfd
      .debug_info.  */
   void map_info_sections (struct objfile *objfile);
 
+  /* Set the 'index_table' member and then call start_reading on
+     it.  */
+  void start_reading (std::unique_ptr<dwarf_scanner_base> new_table);
+
 private:
   /* This function is mapped across the sections and remembers the
      offset and size of each of the debugging sections we are