]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/dwarf: change signatured_type_up to include deleter type
authorSimon Marchi <simon.marchi@polymtl.ca>
Wed, 20 May 2026 18:19:28 +0000 (14:19 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 21 May 2026 17:45:15 +0000 (13:45 -0400)
We currently have:

  using dwarf2_per_cu_up = std::unique_ptr<dwarf2_per_cu, dwarf2_per_cu_deleter>;
  using signatured_type_up = std::unique_ptr<signatured_type>;

Meaning that it's not possible to pass a signatured_type_up as a
dwarf2_per_cu_up, even though the target types are related (it is
possible to pass a `signatured_type *` as a `dwarf2_per_cu *`).

If we give signatured_type_up the same deleter as dwarf2_per_cu_up, then
it becomes possible to pass a signatured_type_up as a dwarf2_per_cu_up.
This lets us avoid releasing a signatured_type_up only to create a
dwarf2dwarf2_per_cu_up immediately after in some spots.  The only
downside is that we can't use make_unique anymore, but it's already the
case for dwarf2_per_cu_up.

Swap the order of things in add_type_unit so that we don't need a
special holder variable.

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

index 30ad0b21f2da37ba16c5f4595f8342def396be7f..dfa54f7914a286c18e0fd34b946482322639d998 100644 (file)
@@ -1036,7 +1036,7 @@ create_foreign_type_units_from_debug_names (dwarf2_per_bfd *per_bfd,
 
       map.foreign_type_units.emplace_back (sig_type.get ());
       per_bfd->signatured_types.emplace (sig_type.get ());
-      per_bfd->all_units.emplace_back (sig_type.release ());
+      per_bfd->all_units.emplace_back (std::move (sig_type));
     }
 }
 
index 48d1200270be698e645cffe6911b2f08878faa71..e0f527b7503ecc663771c5a5936cf1322bbd5908 100644 (file)
@@ -584,7 +584,7 @@ create_signatured_type_table_from_gdb_index
 
       sig_types_hash.emplace (sig_type.get ());
       units.emplace_back (sig_type.get ());
-      per_bfd->all_units.emplace_back (sig_type.release ());
+      per_bfd->all_units.emplace_back (std::move (sig_type));
     }
 
   per_bfd->signatured_types = std::move (sig_types_hash);
index f8ade564b0ba8dd18995262e41857bae8ce1f75d..883b068ad8aec1372f8b201614701d869326c8e4 100644 (file)
@@ -1440,9 +1440,8 @@ dwarf2_per_bfd::allocate_signatured_type (dwarf2_section_info *section,
                                          ULONGEST signature)
 {
   gdb_assert (section != nullptr);
-  auto result
-    = std::make_unique<signatured_type> (this, section, sect_off, length,
-                                        is_dwz, signature);
+  signatured_type_up result (new signatured_type (this, section, sect_off,
+                                                 length, is_dwz, signature));
   result->index = all_units.size ();
   this->num_type_units++;
   return result;
@@ -1453,10 +1452,9 @@ dwarf2_per_bfd::allocate_signatured_type (dwarf2_section_info *section,
 signatured_type_up
 dwarf2_per_bfd::allocate_signatured_type (ULONGEST signature)
 {
-  auto result
-    = std::make_unique<signatured_type> (this, nullptr,
-                                        invalid_sect_offset,
-                                        0, false, signature);
+  signatured_type_up result (new signatured_type (this, nullptr,
+                                                 invalid_sect_offset, 0,
+                                                 false, signature));
   result->index = all_units.size ();
   this->num_type_units++;
   return result;
@@ -2244,13 +2242,12 @@ add_type_unit (dwarf2_per_bfd *per_bfd, dwarf2_section_info *section,
   if (per_bfd->all_units.size () == per_bfd->all_units.capacity ())
     ++per_bfd->tu_stats.nr_all_type_units_reallocs;
 
-  signatured_type_up sig_type_holder
+  signatured_type_up sig_type
     = per_bfd->allocate_signatured_type (section, sect_off, length,
                                         false /* is_dwz */, sig);
-  signatured_type *sig_type = sig_type_holder.get ();
 
-  per_bfd->all_units.emplace_back (sig_type_holder.release ());
-  auto emplace_ret = per_bfd->signatured_types.emplace (sig_type);
+  auto emplace_ret = per_bfd->signatured_types.emplace (sig_type.get ());
+  per_bfd->all_units.emplace_back (std::move (sig_type));
 
   /* Assert that an insertion took place - that there wasn't a type unit with
      that signature already.  */
index 12dc6224d8c0867683a27b10036e93d08b73c5e3..fd6ee1b8b800014a56099278980f3319e469be4a 100644 (file)
@@ -504,7 +504,8 @@ struct signatured_type : public dwarf2_per_cu
   dwarf2_per_cu *hint_per_cu = nullptr;
 };
 
-using signatured_type_up = std::unique_ptr<signatured_type>;
+using signatured_type_up
+  = std::unique_ptr<signatured_type, dwarf2_per_cu_deleter>;
 
 /* See dwarf2_per_cu declaration.  */