[binutils-gdb] Add dwarf2_per_bfd::start_reading

Tom Tromey tromey@sourceware.org
Sun Feb 9 23:23:55 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=433bc515df150f83020b72a45a9a7da47f755974

commit 433bc515df150f83020b72a45a9a7da47f755974
Author: Tom Tromey <tom@tromey.com>
Date:   Thu Feb 6 14:07:59 2025 -0700

    Add dwarf2_per_bfd::start_reading
    
    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>

Diff:
---
 gdb/dwarf2/cooked-index.h     |  2 +-
 gdb/dwarf2/mapped-index.h     |  5 +++++
 gdb/dwarf2/read-debug-names.c | 12 +++++-------
 gdb/dwarf2/read.c             | 19 +++++++++++++------
 gdb/dwarf2/read.h             |  4 ++++
 5 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h
index d1d81f8e2a5..fc29bfdec62 100644
--- a/gdb/dwarf2/cooked-index.h
+++ b/gdb/dwarf2/cooked-index.h
@@ -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
diff --git a/gdb/dwarf2/mapped-index.h b/gdb/dwarf2/mapped-index.h
index 8bc81b4c1ac..b32fe6ad32d 100644
--- a/gdb/dwarf2/mapped-index.h
+++ b/gdb/dwarf2/mapped-index.h
@@ -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;
diff --git a/gdb/dwarf2/read-debug-names.c b/gdb/dwarf2/read-debug-names.c
index ffc4f3ad5eb..3d73bcde9a5 100644
--- a/gdb/dwarf2/read-debug-names.c
+++ b/gdb/dwarf2/read-debug-names.c
@@ -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;
 }
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 70e90226d09..be33beac0f1 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -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 ();
+}
+
 

 /* 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)));
 }
 
 

diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 12d5f066e87..ebea8b7b57f 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -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


More information about the Gdb-cvs mailing list