]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/dwarf: remove cutu_reader::keep, add cutu_reader::release_cu
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 14 Mar 2025 04:32:49 +0000 (00:32 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Fri, 14 Mar 2025 16:23:40 +0000 (12:23 -0400)
This is a bit subjective, but I often struggle to understand what
cutu_reader::keep is meant to do (keep what, where).  Perhaps it's just
a question of bad naming, but I think it's a bit confusing for
cutu_reader to transfer the ownership of the dwarf2_cu to the
per_objfile directly.

Add the cutu::release_cu method and make the caller of cutu_reader
transfer the ownership to the per_objfile object.

Right now, it is theoretically possible for release_cu to return
nullptr, so I made callers check the return value.  A patch later in
this series will change release_cu to ensure it always return
non-nullptr, so those callers will get simplified.

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

index d656fbd3fd32af8d984c9232581d9c9cf556bbcf..46114f06aee859ec77e7d280b399c94092a357d5 100644 (file)
@@ -3246,18 +3246,14 @@ cutu_reader::cutu_reader (dwarf2_per_cu *this_cu,
   prepare_one_comp_unit (cu, pretend_language);
 }
 
-void
-cutu_reader::keep ()
+/* See read.h.  */
+
+dwarf2_cu_up
+cutu_reader::release_cu ()
 {
-  /* Done, clean up.  */
   gdb_assert (!m_dummy_p);
-  if (m_new_cu != NULL)
-    {
-      /* Save this dwarf2_cu in the per_objfile.  The per_objfile owns it
-        now.  */
-      dwarf2_per_objfile *per_objfile = m_new_cu->per_objfile;
-      per_objfile->set_cu (m_this_cu, std::move (m_new_cu));
-    }
+
+  return std::move (m_new_cu);
 }
 
 /* Read CU/TU THIS_CU but do not follow DW_AT_GNU_dwo_name (DW_AT_dwo_name)
@@ -4401,7 +4397,14 @@ load_full_comp_unit (dwarf2_per_cu *this_cu,
     return;
 
   reader.read_all_dies ();
-  reader.keep ();
+
+  if (auto new_cu = reader.release_cu ();
+      new_cu != nullptr)
+    {
+      /* Save this dwarf2_cu in the per_objfile.  The per_objfile owns it
+        now.  */
+      per_objfile->set_cu (this_cu, std::move (new_cu));
+    }
 }
 
 /* Add a DIE to the delayed physname list.  */
@@ -19102,7 +19105,12 @@ read_signatured_type (signatured_type *sig_type,
   if (!reader.is_dummy ())
     {
       reader.read_all_dies ();
-      reader.keep ();
+
+      /* Save this dwarf2_cu in the per_objfile.  The per_objfile owns it
+        now.  */
+      dwarf2_cu_up new_cu = reader.release_cu ();
+      gdb_assert (new_cu != nullptr);
+      per_objfile->set_cu (sig_type, std::move (new_cu));
     }
 
   sig_type->tu_read = 1;
index 29dcf18269151ab8b9bc120d0c8ad2146b97d7de..2c88c0c97887dda6d82b2825c96aec48500f84b2 100644 (file)
@@ -941,9 +941,8 @@ public:
 
   const dwarf2_section_info *section () const { return m_die_section; }
 
-  /* Release the new CU, putting it on the chain.  This cannot be done
-     for dummy CUs.  */
-  void keep ();
+  /* Release the CU created by this cutu_reader.  */
+  dwarf2_cu_up release_cu ();
 
   /* Release the abbrev table, transferring ownership to the
      caller.  */