From: Simon Marchi Date: Wed, 12 Feb 2025 15:52:53 +0000 (-0500) Subject: gdb/dwarf: unique_ptr cleanup X-Git-Tag: binutils-2_45~1585 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f24d402bf8dd67af99c37384fdf900eea1698689;p=thirdparty%2Fbinutils-gdb.git gdb/dwarf: unique_ptr cleanup 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 --- diff --git a/gdb/buildsym.h b/gdb/buildsym.h index 974645c1c47..1d30f551ace 100644 --- a/gdb/buildsym.h +++ b/gdb/buildsym.h @@ -448,7 +448,7 @@ private: struct pending *m_local_symbols = nullptr; }; - +using buildsym_compunit_up = std::unique_ptr; extern void add_symbol_to_list (struct symbol *symbol, struct pending **listhead); diff --git a/gdb/dwarf2/abbrev.h b/gdb/dwarf2/abbrev.h index 93e3b90c70e..29914f9c86d 100644 --- a/gdb/dwarf2/abbrev.h +++ b/gdb/dwarf2/abbrev.h @@ -61,7 +61,7 @@ struct abbrev_info }; struct abbrev_table; -typedef std::unique_ptr abbrev_table_up; +using abbrev_table_up = std::unique_ptr; /* Top level data structure to contain an abbreviation table. diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index 896f5879fd0..d7b5a6837ad 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -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 &&worker) + cooked_index_worker_up &&worker) : m_state (std::move (worker)), m_per_bfd (per_objfile->per_bfd) { diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 4ab1adbe05e..925f73b5f6c 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -371,6 +371,8 @@ using cooked_index_shard_up = std::unique_ptr; class cutu_reader; +using cutu_reader_up = std::unique_ptr; + /* 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 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 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 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, + using result_type = std::tuple, parent_map>; @@ -570,6 +572,8 @@ protected: index_cache_store_context m_cache_store; }; +using cooked_index_worker_up = std::unique_ptr; + /* 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 &&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 m_state; + cooked_index_worker_up m_state; dwarf2_per_bfd *m_per_bfd; }; diff --git a/gdb/dwarf2/cu.h b/gdb/dwarf2/cu.h index 737d3ba9acc..a24040f4d41 100644 --- a/gdb/dwarf2/cu.h +++ b/gdb/dwarf2/cu.h @@ -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 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; + #endif /* GDB_DWARF2_CU_H */ diff --git a/gdb/dwarf2/dwz.c b/gdb/dwarf2/dwz.c index fb11ac6550b..1fda21029f1 100644 --- a/gdb/dwarf2/dwz.c +++ b/gdb/dwarf2/dwz.c @@ -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 result - (new struct dwz_file (std::move (dwz_bfd))); + auto result = std::make_unique (std::move (dwz_bfd)); for (asection *sec : gdb_bfd_sections (result->dwz_bfd)) locate_dwz_sections (per_objfile->objfile, result->dwz_bfd.get (), diff --git a/gdb/dwarf2/dwz.h b/gdb/dwarf2/dwz.h index 3ec3af1a819..13b7692070f 100644 --- a/gdb/dwarf2/dwz.h +++ b/gdb/dwarf2/dwz.h @@ -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_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; + /* 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, diff --git a/gdb/dwarf2/file-and-dir.h b/gdb/dwarf2/file-and-dir.h index a5b1d8a3a21..6d8cfc938be 100644 --- a/gdb/dwarf2/file-and-dir.h +++ b/gdb/dwarf2/file-and-dir.h @@ -126,4 +126,6 @@ private: gdb::unique_xmalloc_ptr m_fullname; }; +using file_and_directory_up = std::unique_ptr; + #endif /* GDB_DWARF2_FILE_AND_DIR_H */ diff --git a/gdb/dwarf2/index-cache.c b/gdb/dwarf2/index-cache.c index 4e1aaa0d731..9e3396ebd88 100644 --- a/gdb/dwarf2/index-cache.c +++ b/gdb/dwarf2/index-cache.c @@ -203,7 +203,7 @@ struct index_cache_resource_mmap final : public index_cache_resource gdb::array_view index_cache::lookup_gdb_index (const bfd_build_id *build_id, - std::unique_ptr *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 index_cache::lookup_gdb_index (const bfd_build_id *build_id, - std::unique_ptr *resource) + index_cache_resource_up *resource) { return {}; } diff --git a/gdb/dwarf2/index-cache.h b/gdb/dwarf2/index-cache.h index 94c4413ff6e..4d9bfd798aa 100644 --- a/gdb/dwarf2/index-cache.h +++ b/gdb/dwarf2/index-cache.h @@ -33,6 +33,8 @@ struct index_cache_resource virtual ~index_cache_resource () = 0; }; +using index_cache_resource_up = std::unique_ptr; + /* 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 lookup_gdb_index (const bfd_build_id *build_id, - std::unique_ptr *resource); + index_cache_resource_up *resource); /* Return the number of cache hits. */ unsigned int n_hits () const diff --git a/gdb/dwarf2/line-header.h b/gdb/dwarf2/line-header.h index 30809f69acc..d08ab552463 100644 --- a/gdb/dwarf2/line-header.h +++ b/gdb/dwarf2/line-header.h @@ -200,7 +200,7 @@ struct line_header const char *m_comp_dir = nullptr; }; -typedef std::unique_ptr line_header_up; +using line_header_up = std::unique_ptr; inline const char * file_entry::include_dir (const line_header *lh) const diff --git a/gdb/dwarf2/mapped-index.h b/gdb/dwarf2/mapped-index.h index b32fe6ad32d..3117df260bc 100644 --- a/gdb/dwarf2/mapped-index.h +++ b/gdb/dwarf2/mapped-index.h @@ -69,4 +69,6 @@ struct dwarf_scanner_base { return nullptr; } }; +using dwarf_scanner_base_up = std::unique_ptr; + #endif /* GDB_DWARF2_MAPPED_INDEX_H */ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 738dd5af52b..198b9ff4102 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -285,6 +285,8 @@ struct type_unit_group struct stmt_list_hash hash {}; }; +using type_unit_group_up = std::unique_ptr; + /* 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; + /* 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 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 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 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 +static type_unit_group_up create_type_unit_group (struct dwarf2_cu *cu, sect_offset line_offset_struct) { auto tu_group = std::make_unique (); @@ -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 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 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 copy - (new cutu_reader (std::move (new_reader))); + auto copy = std::make_unique (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> shards; + std::vector 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 +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 (); + return dwp_file_up (); } const char *name = bfd_get_filename (dbfd.get ()); - std::unique_ptr dwp_file - (new struct dwp_file (name, std::move (dbfd))); + auto dwp_file = std::make_unique (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 copy - (new cutu_reader (std::move (new_reader))); + auto copy = std::make_unique (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 worker - = std::make_unique (per_objfile); + auto worker = std::make_unique (per_objfile); per_bfd->start_reading (std::make_unique (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 cu) + dwarf2_cu_up cu) { gdb_assert (this->get_cu (per_cu) == nullptr); diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index ebea8b7b57f..640a8e2e391 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -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_up; +using dwarf2_per_cu_data_up + = std::unique_ptr; /* 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 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; +struct dwp_file; + +using dwp_file_up = std::unique_ptr; + /* 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 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 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> dwz_file; + std::optional 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 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_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; + 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 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 m_symtabs; - /* Map from a type unit group to the corresponding unshared - structure. */ - typedef std::unique_ptr - type_unit_group_unshareable_up; - + /* Map from a type unit group to the corresponding unshared + structure. */ std::unordered_map 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> m_dwarf2_cus; + std::unordered_map m_dwarf2_cus; }; /* Converts DWARF language names to GDB language names. */