]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/dwarf: unique_ptr cleanup
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 12 Feb 2025 15:52:53 +0000 (10:52 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Fri, 14 Feb 2025 18:17:35 +0000 (13:17 -0500)
Throughout gdb/dwarf2, use `*_up` typedefs.  Add a few missing typedefs,
and move some so they are, ideally, just after the corresponding class.

Change-Id: Iab5cd8fc2e9989d4bd8d4868586703c2312f254f
Approved-By: Tom Tromey <tom@tromey.com>
14 files changed:
gdb/buildsym.h
gdb/dwarf2/abbrev.h
gdb/dwarf2/cooked-index.c
gdb/dwarf2/cooked-index.h
gdb/dwarf2/cu.h
gdb/dwarf2/dwz.c
gdb/dwarf2/dwz.h
gdb/dwarf2/file-and-dir.h
gdb/dwarf2/index-cache.c
gdb/dwarf2/index-cache.h
gdb/dwarf2/line-header.h
gdb/dwarf2/mapped-index.h
gdb/dwarf2/read.c
gdb/dwarf2/read.h

index 974645c1c4753a7ab52d711bc5ab7bc2252dc969..1d30f551ace0182a56ebee14cf71f296502d2ba2 100644 (file)
@@ -448,7 +448,7 @@ private:
   struct pending *m_local_symbols = nullptr;
 };
 
-\f
+using buildsym_compunit_up = std::unique_ptr<buildsym_compunit>;
 
 extern void add_symbol_to_list (struct symbol *symbol,
                                struct pending **listhead);
index 93e3b90c70e69f4a7968c82b13b2f650395791aa..29914f9c86dfa46bbab90f5e87a7c248760d942d 100644 (file)
@@ -61,7 +61,7 @@ struct abbrev_info
 };
 
 struct abbrev_table;
-typedef std::unique_ptr<struct abbrev_table> abbrev_table_up;
+using abbrev_table_up = std::unique_ptr<abbrev_table>;
 
 /* Top level data structure to contain an abbreviation table.
 
index 896f5879fd0e62660e52a83c6a1f8228cfbbcd6b..d7b5a6837adf592502d779ef33ad54a2edb74342 100644 (file)
@@ -612,7 +612,7 @@ cooked_index_worker::write_to_cache (const cooked_index *idx,
 }
 
 cooked_index::cooked_index (dwarf2_per_objfile *per_objfile,
-                           std::unique_ptr<cooked_index_worker> &&worker)
+                           cooked_index_worker_up &&worker)
   : m_state (std::move (worker)),
     m_per_bfd (per_objfile->per_bfd)
 {
index 4ab1adbe05e1142f40349d4308a80f7c3ae4c3d7..925f73b5f6c15860787898b2cd244739cc66837e 100644 (file)
@@ -371,6 +371,8 @@ using cooked_index_shard_up = std::unique_ptr<cooked_index_shard>;
 
 class cutu_reader;
 
+using cutu_reader_up = std::unique_ptr<cutu_reader>;
+
 /* An instance of this is created when scanning DWARF to create a
    cooked index.  */
 
@@ -390,7 +392,7 @@ public:
   cutu_reader *get_reader (dwarf2_per_cu_data *per_cu);
 
   /* Preserve READER by storing it in the local hash table.  */
-  cutu_reader *preserve (std::unique_ptr<cutu_reader> reader);
+  cutu_reader *preserve (cutu_reader_up reader);
 
   /* Add an entry to the index.  The arguments describe the entry; see
      cooked-index.h.  The new entry is returned.  */
@@ -406,7 +408,7 @@ public:
 
   /* Install the current addrmap into the shard being constructed,
      then transfer ownership of the index to the caller.  */
-  std::unique_ptr<cooked_index_shard> release ()
+  cooked_index_shard_up release ()
   {
     m_shard->install_addrmap (&m_addrmap);
     return std::move (m_shard);
@@ -445,7 +447,7 @@ private:
   /* A hash table of cutu_reader objects.  */
   htab_up m_reader_hash;
   /* The index shard that is being constructed.  */
-  std::unique_ptr<cooked_index_shard> m_shard;
+  cooked_index_shard_up m_shard;
 
   /* Parent map for each CU that is read.  */
   parent_map m_parent_map;
@@ -531,7 +533,7 @@ protected:
      thread-safe.  run_on_main_thread could be used, but that would
      mean the messages are printed after the prompt, which looks
      weird.  */
-  using result_type = std::tuple<std::unique_ptr<cooked_index_shard>,
+  using result_type = std::tuple<cooked_index_shard_up,
                                 complaint_collection,
                                 std::vector<gdb_exception>,
                                 parent_map>;
@@ -570,6 +572,8 @@ protected:
   index_cache_store_context m_cache_store;
 };
 
+using cooked_index_worker_up = std::unique_ptr<cooked_index_worker>;
+
 /* The main index of DIEs.
 
    The index is created by multiple threads.  The overall process is
@@ -627,7 +631,7 @@ class cooked_index : public dwarf_scanner_base
 {
 public:
   cooked_index (dwarf2_per_objfile *per_objfile,
-               std::unique_ptr<cooked_index_worker> &&worker);
+               cooked_index_worker_up &&worker);
   ~cooked_index () override;
 
   DISABLE_COPY_AND_ASSIGN (cooked_index);
@@ -715,7 +719,7 @@ private:
   /* This tracks the current state.  When this is nullptr, it means
      that the state is CACHE_DONE -- it's important to note that only
      the main thread may change the value of this pointer.  */
-  std::unique_ptr<cooked_index_worker> m_state;
+  cooked_index_worker_up m_state;
 
   dwarf2_per_bfd *m_per_bfd;
 };
index 737d3ba9acc3eb2b1a7fb84c58a3de868c4f4666..a24040f4d41d135eeef63090969355b94fe322c0 100644 (file)
@@ -120,7 +120,7 @@ struct dwarf2_cu
 private:
   /* The symtab builder for this CU.  This is only non-NULL when full
      symbols are being read.  */
-  std::unique_ptr<buildsym_compunit> m_builder;
+  buildsym_compunit_up m_builder;
 
   /* A set of pointers to dwarf2_per_cu_data objects for compilation
      units referenced by this one.  Only used during full symbol processing;
@@ -280,4 +280,6 @@ public:
   buildsym_compunit *get_builder ();
 };
 
+using dwarf2_cu_up = std::unique_ptr<dwarf2_cu>;
+
 #endif /* GDB_DWARF2_CU_H */
index fb11ac6550bc6409c2fea262d5e4fb63e94893b8..1fda21029f1f5e7a53ce91af90ff6072e8a19e48 100644 (file)
@@ -265,8 +265,7 @@ dwarf2_read_dwz_file (dwarf2_per_objfile *per_objfile)
     error (_("could not find '.gnu_debugaltlink' file for %s"),
           bfd_get_filename (per_bfd->obfd));
 
-  std::unique_ptr<struct dwz_file> result
-    (new struct dwz_file (std::move (dwz_bfd)));
+  auto result = std::make_unique<dwz_file> (std::move (dwz_bfd));
 
   for (asection *sec : gdb_bfd_sections (result->dwz_bfd))
     locate_dwz_sections (per_objfile->objfile, result->dwz_bfd.get (),
index 3ec3af1a8196c5715096fbc27b373d5082b0287c..13b7692070f22cc325f53859d0eb5da20a3d29ee 100644 (file)
@@ -56,7 +56,7 @@ struct dwz_file
 
   /* If we loaded the index from an external file, this contains the
      resources associated to the open file, memory mapping, etc.  */
-  std::unique_ptr<index_cache_resource> index_cache_res;
+  index_cache_resource_up index_cache_res;
 
   /* Read a string at offset STR_OFFSET in the .debug_str section from
      this dwz file.  Throw an error if the offset is too large.  If
@@ -66,6 +66,8 @@ struct dwz_file
   const char *read_string (struct objfile *objfile, LONGEST str_offset);
 };
 
+using dwz_file_up = std::unique_ptr<dwz_file>;
+
 /* Return the separate '.dwz' debug file.  If there is no
    .gnu_debugaltlink section in the file, then the result depends on
    REQUIRE: if REQUIRE is true, then error; if REQUIRE is false,
index a5b1d8a3a2166c68a604b417444743b7d983d160..6d8cfc938be12091367c27b236a183b4ca30eded 100644 (file)
@@ -126,4 +126,6 @@ private:
   gdb::unique_xmalloc_ptr<char> m_fullname;
 };
 
+using file_and_directory_up = std::unique_ptr<file_and_directory>;
+
 #endif /* GDB_DWARF2_FILE_AND_DIR_H */
index 4e1aaa0d7319f7036756a3991a50983d6c335dba..9e3396ebd88c1029f551210d75d6e43e07fa0b78 100644 (file)
@@ -203,7 +203,7 @@ struct index_cache_resource_mmap final : public index_cache_resource
 
 gdb::array_view<const gdb_byte>
 index_cache::lookup_gdb_index (const bfd_build_id *build_id,
-                              std::unique_ptr<index_cache_resource> *resource)
+                              index_cache_resource_up *resource)
 {
   if (!enabled ())
     return {};
@@ -249,7 +249,7 @@ index_cache::lookup_gdb_index (const bfd_build_id *build_id,
 
 gdb::array_view<const gdb_byte>
 index_cache::lookup_gdb_index (const bfd_build_id *build_id,
-                              std::unique_ptr<index_cache_resource> *resource)
+                              index_cache_resource_up *resource)
 {
   return {};
 }
index 94c4413ff6ea743d4aafd52b6db464414b5d5573..4d9bfd798aa1d6f5b7dea507dc58be1a98ec0f38 100644 (file)
@@ -33,6 +33,8 @@ struct index_cache_resource
   virtual ~index_cache_resource () = 0;
 };
 
+using index_cache_resource_up = std::unique_ptr<index_cache_resource>;
+
 /* Information to be captured in the main thread, and to be used by worker
    threads during store ().  */
 
@@ -89,7 +91,7 @@ public:
      If no matching index file is found, return an empty array view.  */
   gdb::array_view<const gdb_byte>
   lookup_gdb_index (const bfd_build_id *build_id,
-                   std::unique_ptr<index_cache_resource> *resource);
+                   index_cache_resource_up *resource);
 
   /* Return the number of cache hits.  */
   unsigned int n_hits () const
index 30809f69acc72c8eda5bbb625060b9d406af4a3b..d08ab552463a8a6bcd15354286963fcdcf0a8966 100644 (file)
@@ -200,7 +200,7 @@ struct line_header
   const char *m_comp_dir = nullptr;
 };
 
-typedef std::unique_ptr<line_header> line_header_up;
+using line_header_up = std::unique_ptr<line_header>;
 
 inline const char *
 file_entry::include_dir (const line_header *lh) const
index b32fe6ad32d4371ffa78688e0069c47f01159e5c..3117df260bc6ec759070bcfee059271de909792f 100644 (file)
@@ -69,4 +69,6 @@ struct dwarf_scanner_base
   { return nullptr; }
 };
 
+using dwarf_scanner_base_up = std::unique_ptr<dwarf_scanner_base>;
+
 #endif /* GDB_DWARF2_MAPPED_INDEX_H */
index 738dd5af52b7ba714355f38d1ee3e18b8a1d31ac..198b9ff4102c214c2f6e0cac69d09febe2d3b500 100644 (file)
@@ -285,6 +285,8 @@ struct type_unit_group
   struct stmt_list_hash hash {};
 };
 
+using type_unit_group_up = std::unique_ptr<type_unit_group>;
+
 /* These sections are what may appear in a (real or virtual) DWO file.  */
 
 struct dwo_sections
@@ -380,6 +382,8 @@ struct dwo_file
   htab_up tus;
 };
 
+using dwo_file_up = std::unique_ptr<dwo_file>;
+
 /* These sections are what may appear in a DWP file.  */
 
 struct dwp_sections
@@ -621,7 +625,7 @@ private:
                                  dwarf2_cu *existing_cu);
 
   struct dwarf2_per_cu_data *m_this_cu;
-  std::unique_ptr<dwarf2_cu> m_new_cu;
+  dwarf2_cu_up m_new_cu;
 
   /* The ordinary abbreviation table.  */
   abbrev_table_up m_abbrev_table_holder;
@@ -1163,10 +1167,6 @@ static struct dwo_unit *lookup_dwo_type_unit
 
 static void queue_and_load_all_dwo_tus (dwarf2_cu *cu);
 
-/* A unique pointer to a dwo_file.  */
-
-typedef std::unique_ptr<struct dwo_file> dwo_file_up;
-
 static void process_cu_includes (dwarf2_per_objfile *per_objfile);
 
 static void check_producer (struct dwarf2_cu *cu);
@@ -1611,7 +1611,7 @@ dwarf2_per_bfd::map_info_sections (struct objfile *objfile)
 /* See dwarf2/read.h.  */
 
 void
-dwarf2_per_bfd::start_reading (std::unique_ptr<dwarf_scanner_base> new_table)
+dwarf2_per_bfd::start_reading (dwarf_scanner_base_up new_table)
 {
   gdb_assert (index_table == nullptr);
   index_table = std::move (new_table);
@@ -3569,7 +3569,7 @@ allocate_type_unit_groups_table ()
 /* Helper routine for get_type_unit_group.
    Create the type_unit_group object used to hold one or more TUs.  */
 
-static std::unique_ptr<type_unit_group>
+static type_unit_group_up
 create_type_unit_group (struct dwarf2_cu *cu, sect_offset line_offset_struct)
 {
   auto tu_group = std::make_unique<type_unit_group> ();
@@ -3623,8 +3623,7 @@ get_type_unit_group (struct dwarf2_cu *cu, const struct attribute *stmt_list)
   if (*slot == nullptr)
     {
       sect_offset line_offset_struct = (sect_offset) line_offset;
-      std::unique_ptr<type_unit_group> grp
-       = create_type_unit_group (cu, line_offset_struct);
+      auto grp = create_type_unit_group (cu, line_offset_struct);
       *slot = grp.release ();
       ++tu_stats->nr_symtabs;
     }
@@ -3653,7 +3652,7 @@ cooked_index_storage::get_reader (dwarf2_per_cu_data *per_cu)
 }
 
 cutu_reader *
-cooked_index_storage::preserve (std::unique_ptr<cutu_reader> reader)
+cooked_index_storage::preserve (cutu_reader_up reader)
 {
   m_abbrev_table_cache.add (reader->release_abbrev_table ());
 
@@ -3860,8 +3859,7 @@ process_psymtab_comp_unit (dwarf2_per_cu_data *this_cu,
       if (new_reader.comp_unit_die == nullptr || new_reader.dummy_p)
        return;
 
-      std::unique_ptr<cutu_reader> copy
-       (new cutu_reader (std::move (new_reader)));
+      auto copy = std::make_unique<cutu_reader> (std::move (new_reader));
       reader = storage->preserve (std::move (copy));
     }
 
@@ -4204,7 +4202,7 @@ cooked_index_worker_debug_info::done_reading ()
 {
   /* Only handle the scanning results here.  Complaints and exceptions
      can only be dealt with on the main thread.  */
-  std::vector<std::unique_ptr<cooked_index_shard>> shards;
+  std::vector<cooked_index_shard_up> shards;
 
   for (auto &one_result : m_results)
     {
@@ -8679,7 +8677,7 @@ open_dwp_file (dwarf2_per_objfile *per_objfile, const char *file_name)
    By convention the name of the DWP file is ${objfile}.dwp.
    The result is NULL if it can't be found.  */
 
-static std::unique_ptr<struct dwp_file>
+static dwp_file_up
 open_and_init_dwp_file (dwarf2_per_objfile *per_objfile)
 {
   struct objfile *objfile = per_objfile->objfile;
@@ -8716,12 +8714,11 @@ open_and_init_dwp_file (dwarf2_per_objfile *per_objfile)
     {
       dwarf_read_debug_printf ("DWP file not found: %s", dwp_name.c_str ());
 
-      return std::unique_ptr<dwp_file> ();
+      return dwp_file_up ();
     }
 
   const char *name = bfd_get_filename (dbfd.get ());
-  std::unique_ptr<struct dwp_file> dwp_file
-    (new struct dwp_file (name, std::move (dbfd)));
+  auto dwp_file = std::make_unique<struct dwp_file> (name, std::move (dbfd));
 
   dwp_file->num_sections = elf_numsections (dwp_file->dbfd);
   dwp_file->elf_sections =
@@ -15547,8 +15544,7 @@ cooked_indexer::ensure_cu_exists (cutu_reader *reader,
 
       prepare_one_comp_unit (new_reader.cu, new_reader.comp_unit_die,
                             language_minimal);
-      std::unique_ptr<cutu_reader> copy
-       (new cutu_reader (std::move (new_reader)));
+      auto copy = std::make_unique<cutu_reader> (std::move (new_reader));
       result = m_index_storage->preserve (std::move (copy));
     }
 
@@ -16350,8 +16346,7 @@ start_debug_info_reader (dwarf2_per_objfile *per_objfile)
   /* Set the index table early so that sharing works even while
      scanning; and then start the scanning.  */
   dwarf2_per_bfd *per_bfd = per_objfile->per_bfd;
-  std::unique_ptr<cooked_index_worker> worker
-    = std::make_unique<cooked_index_worker_debug_info> (per_objfile);
+  auto worker = std::make_unique<cooked_index_worker_debug_info> (per_objfile);
   per_bfd->start_reading (std::make_unique<cooked_index> (per_objfile,
                                                          std::move (worker)));
 }
@@ -21292,7 +21287,7 @@ dwarf2_per_objfile::get_cu (dwarf2_per_cu_data *per_cu)
 
 void
 dwarf2_per_objfile::set_cu (dwarf2_per_cu_data *per_cu,
-                           std::unique_ptr<dwarf2_cu> cu)
+                           dwarf2_cu_up cu)
 {
   gdb_assert (this->get_cu (per_cu) == nullptr);
 
index ebea8b7b57f4d93ab23b640d269b4e7a0d4495c5..640a8e2e3914964a13675047a7788a59ea519f77 100644 (file)
@@ -28,6 +28,7 @@
 #include "dwarf2/mapped-index.h"
 #include "dwarf2/section.h"
 #include "dwarf2/cu.h"
+#include "dwarf2/dwz.h"
 #include "gdbsupport/gdb_obstack.h"
 #include "gdbsupport/function-view.h"
 #include "gdbsupport/packed.h"
@@ -87,8 +88,8 @@ struct dwarf2_per_cu_data_deleter
 
 /* A specialization of unique_ptr for dwarf2_per_cu_data and
    subclasses.  */
-typedef std::unique_ptr<dwarf2_per_cu_data, dwarf2_per_cu_data_deleter>
-    dwarf2_per_cu_data_up;
+using dwarf2_per_cu_data_up
+  = std::unique_ptr<dwarf2_per_cu_data, dwarf2_per_cu_data_deleter>;
 
 /* Persistent data held for a compilation unit, even when not
    processing it.  We put a pointer to this structure in the
@@ -224,7 +225,7 @@ public:
      don't need to re-examine the DWO in some situations.  This may be
      nullptr, depending on the CU; for example a partial unit won't
      have one.  */
-  std::unique_ptr<file_and_directory> fnd;
+  file_and_directory_up fnd;
 
   /* The file table.  This can be NULL if there was no file table
      or it's currently not read in.
@@ -397,6 +398,10 @@ struct signatured_type : public dwarf2_per_cu_data
 
 using signatured_type_up = std::unique_ptr<signatured_type>;
 
+struct dwp_file;
+
+using dwp_file_up = std::unique_ptr<dwp_file>;
+
 /* Some DWARF data can be shared across objfiles who share the same BFD,
    this data is stored in this object.
 
@@ -453,7 +458,7 @@ struct dwarf2_per_bfd
 
   /* Set the 'index_table' member and then call start_reading on
      it.  */
-  void start_reading (std::unique_ptr<dwarf_scanner_base> new_table);
+  void start_reading (dwarf_scanner_base_up new_table);
 
 private:
   /* This function is mapped across the sections and remembers the
@@ -524,11 +529,11 @@ public:
   bool dwp_checked = false;
 
   /* The DWP file if there is one, or NULL.  */
-  std::unique_ptr<struct dwp_file> dwp_file;
+  dwp_file_up dwp_file;
 
   /* The shared '.dwz' file, if one exists.  This is used when the
      original data was compressed using 'dwz -m'.  */
-  std::optional<std::unique_ptr<struct dwz_file>> dwz_file;
+  std::optional<dwz_file_up> dwz_file;
 
   /* Whether copy relocations are supported by this object format.  */
   bool can_copy;
@@ -538,7 +543,7 @@ public:
   bool has_section_at_zero = false;
 
   /* The mapped index, or NULL in the readnow case.  */
-  std::unique_ptr<dwarf_scanner_base> index_table;
+  dwarf_scanner_base_up index_table;
 
   /* When using index_table, this keeps track of all quick_file_names entries.
      TUs typically share line table entries with a CU, so we maintain a
@@ -554,7 +559,7 @@ public:
 
   /* If we loaded the index from an external file, this contains the
      resources associated to the open file, memory mapping, etc.  */
-  std::unique_ptr<index_cache_resource> index_cache_res;
+  index_cache_resource_up index_cache_res;
 
   /* Mapping from abstract origin DIE to concrete DIEs that reference it as
      DW_AT_abstract_origin.  */
@@ -659,6 +664,9 @@ struct type_unit_group_unshareable
   struct symtab **symtabs = nullptr;
 };
 
+using type_unit_group_unshareable_up
+  = std::unique_ptr<type_unit_group_unshareable>;
+
 struct per_cu_and_offset
 {
   dwarf2_per_cu_data *per_cu;
@@ -729,7 +737,7 @@ struct dwarf2_per_objfile
   dwarf2_cu *get_cu (dwarf2_per_cu_data *per_cu);
 
   /* Set the dwarf2_cu matching PER_CU for this objfile.  */
-  void set_cu (dwarf2_per_cu_data *per_cu, std::unique_ptr<dwarf2_cu> cu);
+  void set_cu (dwarf2_per_cu_data *per_cu, dwarf2_cu_up cu);
 
   /* Remove/free the dwarf2_cu matching PER_CU for this objfile.  */
   void remove_cu (dwarf2_per_cu_data *per_cu);
@@ -785,11 +793,8 @@ private:
      that the CU/TU has not been expanded yet.  */
   std::vector<compunit_symtab *> m_symtabs;
 
-  /* Map from a type unit group to the corresponding unshared
-     structure.  */
-  typedef std::unique_ptr<type_unit_group_unshareable>
-    type_unit_group_unshareable_up;
-
+ /* Map from a type unit group to the corresponding unshared
+    structure.  */
   std::unordered_map<type_unit_group *, type_unit_group_unshareable_up>
     m_type_units;
 
@@ -798,8 +803,7 @@ private:
 
   /* Map from the objfile-independent dwarf2_per_cu_data instances to the
      corresponding objfile-dependent dwarf2_cu instances.  */
-  std::unordered_map<dwarf2_per_cu_data *,
-                    std::unique_ptr<dwarf2_cu>> m_dwarf2_cus;
+  std::unordered_map<dwarf2_per_cu_data *, dwarf2_cu_up> m_dwarf2_cus;
 };
 
 /* Converts DWARF language names to GDB language names.  */