]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/dwarf: change cutu_reader::read_die_and_siblings to cutu_reader::read_all_dies
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 14 Mar 2025 04:32:48 +0000 (00:32 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Fri, 14 Mar 2025 16:23:40 +0000 (12:23 -0400)
After construction of a cutu_reader, only the top-level DIE has been
read in memory.  If the caller wants to access the full DIE tree, it
does:

    reader.top_level_die ()->child
      = reader.read_die_and_siblings (reader.top_level_die ());

I don't really like this poking into cutu_reader's data structures from
the outside, I would prefer if that work was done by cutu_reader.
Rename the read_die_and_siblings method to read_all_dies, and do that
work inside cutu_reader.

I also moved these operations inside the read_all_dies method:

    gdb_assert (cu->die_hash.empty ());
    cu->die_hash.reserve (cu->header.get_length_without_initial () / 12);

    ...

    cu->dies = reader.top_level_die ();

The rationale for this is that read_all_dies (and the functions it
calls) is responsible for filling the die_hash set.  So I think it makes
sense for it to do the reserve.

It is also cutu_reader's job, currently, to create and fill the fields
of dwarf2_cu.  So I think it makes sense for it to set cu->dies, after
having read the DIEs in memory.

Change-Id: I088c2e0b367db7d1f67e8c9e2d5b0d61165292fc
Approved-By: Tom Tromey <tom@tromey.com>
gdb/dwarf2/read.c
gdb/dwarf2/read.h

index cfd5efe27457e3621ac93db644dab4f3d4c0cb29..d656fbd3fd32af8d984c9232581d9c9cf556bbcf 100644 (file)
@@ -4400,18 +4400,7 @@ load_full_comp_unit (dwarf2_per_cu *this_cu,
   if (reader.is_dummy ())
     return;
 
-  struct dwarf2_cu *cu = reader.cu ();
-
-  gdb_assert (cu->die_hash.empty ());
-  cu->die_hash.reserve (cu->header.get_length_without_initial () / 12);
-
-  if (reader.top_level_die ()->has_children)
-    reader.top_level_die ()->child
-      = reader.read_die_and_siblings (reader.top_level_die ());
-
-  cu->dies = reader.top_level_die ();
-  /* comp_unit_die is not stored in die_hash, no need.  */
-
+  reader.read_all_dies ();
   reader.keep ();
 }
 
@@ -14577,16 +14566,21 @@ cutu_reader::read_die_and_siblings_1 (die_info *parent)
     }
 }
 
-/* Read a die, all of its descendents, and all of its siblings; set
-   all of the fields of all of the dies correctly.  Arguments are as
-   in read_die_and_children.
-   This the main entry point for reading a DIE and all its children.  */
+/* See read.h.  */
 
-die_info *
-cutu_reader::read_die_and_siblings (die_info *parent)
+void
+cutu_reader::read_all_dies ()
 {
   const gdb_byte *begin_info_ptr = m_info_ptr;
-  struct die_info *die = this->read_die_and_siblings_1 (parent);
+
+  if (m_top_level_die->has_children)
+    {
+      gdb_assert (m_cu->die_hash.empty ());
+      m_cu->die_hash.reserve (m_cu->header.get_length_without_initial () / 12);
+      m_top_level_die->child = this->read_die_and_siblings_1 (m_top_level_die);
+    }
+
+  m_cu->dies = m_top_level_die;
 
   if (dwarf_die_debug)
     {
@@ -14594,10 +14588,8 @@ cutu_reader::read_die_and_siblings (die_info *parent)
                  m_die_section->get_name (),
                  begin_info_ptr - m_die_section->buffer,
                  bfd_get_filename (m_abfd));
-      die->dump (dwarf_die_debug);
+      m_top_level_die->child->dump (dwarf_die_debug);
     }
-
-  return die;
 }
 
 /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS
@@ -19109,18 +19101,7 @@ read_signatured_type (signatured_type *sig_type,
 
   if (!reader.is_dummy ())
     {
-      struct dwarf2_cu *cu = reader.cu ();
-
-      gdb_assert (cu->die_hash.empty ());
-      cu->die_hash.reserve (cu->header.get_length_without_initial () / 12);
-
-      if (reader.top_level_die ()->has_children)
-       reader.top_level_die ()->child
-         = reader.read_die_and_siblings (reader.top_level_die ());
-
-      cu->dies = reader.top_level_die ();
-      /* comp_unit_die is not stored in die_hash, no need.  */
-
+      reader.read_all_dies ();
       reader.keep ();
     }
 
index 3f99b3931dc01bcb7dbf9f575ee8800b62fd226a..29dcf18269151ab8b9bc120d0c8ad2146b97d7de 100644 (file)
@@ -952,7 +952,8 @@ public:
     return std::move (m_abbrev_table_holder);
   }
 
-  die_info *read_die_and_siblings (die_info *parent);
+  /* Read all DIES of the debug info section in memory.  */
+  void read_all_dies ();
 
   const gdb_byte *read_attribute (attribute *attr, const attr_abbrev *abbrev,
                                  const gdb_byte *info_ptr,