public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 4/4] dwarf2read: Get rid of VEC (dwarf2_section_info_def)
  2019-06-21 11:58 [PATCH 0/4] C++-fication of dwo_file and removal of a VEC Simon Marchi
  2019-06-21 11:58 ` [PATCH 1/4] dwarf2read: Use bool for dwarf2_section_info fields Simon Marchi
@ 2019-06-21 11:58 ` Simon Marchi
  2019-06-21 11:58 ` [PATCH 2/4] dwarf2read: C++ify dwo_file Simon Marchi
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2019-06-21 11:58 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

This patch removes uses of VEC (dwarf2_section_info_def) in favor of
std::vector<dwarf2_section_info>.  The conversion is relatively
straightforward, no function changes are intended.

gdb/ChangeLog:

	* dwarf2read.h (dwarf2_section_info_def): Remove.
	(DEF_VEC_O (dwarf2_section_info_def)): Remove.
	* dwarf2read.c (struct dwo_sections) <types>: Change type to
	std::vector<dwarf2_section_info>.
	(struct dwo_file) <~dwo_file>: Remove.
	(dwarf2_per_objfile::~dwarf2_per_objfile): Don't manually free
	types field.
	(dwarf2_per_objfile::locate_sections): Adjust to std::vector.
	(dwarf2_read_debug_names): Likewise.
	(create_debug_types_hash_table): Change parameter type to
	array_view, adjust code accordingly.
	(dwarf2_locate_dwo_sections): Adjust to std::vector.
	(partial_die_info::fixup): Likewise.
	(determine_prefix): Likewise.
	* dwarf-index-write.c (write_psymtabs_to_index): Adjust.
---
 gdb/dwarf-index-write.c |  2 +-
 gdb/dwarf2read.c        | 46 +++++++++++------------------------------
 gdb/dwarf2read.h        |  5 +----
 3 files changed, 14 insertions(+), 39 deletions(-)

diff --git a/gdb/dwarf-index-write.c b/gdb/dwarf-index-write.c
index 9979ae44402f..3f5862aeb4ca 100644
--- a/gdb/dwarf-index-write.c
+++ b/gdb/dwarf-index-write.c
@@ -1638,7 +1638,7 @@ write_psymtabs_to_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
   if (dwarf2_per_objfile->using_index)
     error (_("Cannot use an index to create the index"));
 
-  if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1)
+  if (dwarf2_per_objfile->types.size () > 1)
     error (_("Cannot make an index when the file has multiple .debug_types sections"));
 
   if (!objfile->partial_symtabs->psymtabs
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 05c872017066..fccbd05e2d69 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -655,7 +655,7 @@ struct dwo_sections
   struct dwarf2_section_info str_offsets;
   /* In the case of a virtual DWO file, these two are unused.  */
   struct dwarf2_section_info info;
-  VEC (dwarf2_section_info_def) *types;
+  std::vector<dwarf2_section_info> types;
 };
 
 /* CUs/TUs in DWP/DWO files.  */
@@ -706,11 +706,6 @@ struct dwo_file
   dwo_file () = default;
   DISABLE_COPY_AND_ASSIGN (dwo_file);
 
-  ~dwo_file ()
-  {
-    VEC_free (dwarf2_section_info_def, sections.types);
-  }
-
   /* The DW_AT_GNU_dwo_name attribute.
      For virtual DWO files the name is constructed from the section offsets
      of abbrev,line,loc,str_offsets so that we combine virtual DWO files
@@ -2160,8 +2155,6 @@ dwarf2_per_objfile::~dwarf2_per_objfile ()
   for (signatured_type *sig_type : all_type_units)
     VEC_free (dwarf2_per_cu_ptr, sig_type->per_cu.imported_symtabs);
 
-  VEC_free (dwarf2_section_info_def, types);
-
   /* Everything else should be on the objfile obstack.  */
 }
 
@@ -2418,8 +2411,7 @@ dwarf2_per_objfile::locate_sections (bfd *abfd, asection *sectp,
       type_section.s.section = sectp;
       type_section.size = bfd_get_section_size (sectp);
 
-      VEC_safe_push (dwarf2_section_info_def, this->types,
-		     &type_section);
+      this->types.push_back (type_section);
     }
   else if (section_is_p (sectp->name, &names.gdb_index))
     {
@@ -3592,15 +3584,12 @@ dwarf2_read_gdb_index
 
   if (types_list_elements)
     {
-      struct dwarf2_section_info *section;
-
       /* We can only handle a single .debug_types when we have an
 	 index.  */
-      if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1)
+      if (dwarf2_per_objfile->types.size () != 1)
 	return 0;
 
-      section = VEC_index (dwarf2_section_info_def,
-			   dwarf2_per_objfile->types, 0);
+      dwarf2_section_info *section = &dwarf2_per_objfile->types[0];
 
       create_signatured_type_table_from_index (dwarf2_per_objfile, section,
 					       types_list, types_list_elements);
@@ -5636,11 +5625,10 @@ dwarf2_read_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile)
     {
       /* We can only handle a single .debug_types when we have an
 	 index.  */
-      if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1)
+      if (dwarf2_per_objfile->types.size () != 1)
 	return false;
 
-      dwarf2_section_info *section = VEC_index (dwarf2_section_info_def,
-						dwarf2_per_objfile->types, 0);
+      dwarf2_section_info *section = &dwarf2_per_objfile->types[0];
 
       create_signatured_type_table_from_debug_names
 	(dwarf2_per_objfile, *map, section, &dwarf2_per_objfile->abbrev);
@@ -6817,19 +6805,11 @@ create_debug_type_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
 static void
 create_debug_types_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
 			       struct dwo_file *dwo_file,
-			       VEC (dwarf2_section_info_def) *types,
+			       gdb::array_view<dwarf2_section_info> type_sections,
 			       htab_t &types_htab)
 {
-  int ix;
-  struct dwarf2_section_info *section;
-
-  if (VEC_empty (dwarf2_section_info_def, types))
-    return;
-
-  for (ix = 0;
-       VEC_iterate (dwarf2_section_info_def, types, ix, section);
-       ++ix)
-    create_debug_type_hash_table (dwarf2_per_objfile, dwo_file, section,
+  for (dwarf2_section_info &section : type_sections)
+    create_debug_type_hash_table (dwarf2_per_objfile, dwo_file, &section,
 				  types_htab, rcuh_kind::TYPE);
 }
 
@@ -12943,8 +12923,7 @@ dwarf2_locate_dwo_sections (bfd *abfd, asection *sectp, void *dwo_sections_ptr)
       memset (&type_section, 0, sizeof (type_section));
       type_section.s.section = sectp;
       type_section.size = bfd_get_section_size (sectp);
-      VEC_safe_push (dwarf2_section_info_def, dwo_sections->types,
-		     &type_section);
+      dwo_sections->types.push_back (type_section);
     }
 }
 
@@ -19030,8 +19009,7 @@ partial_die_info::fixup (struct dwarf2_cu *cu)
      children, see if we can determine the namespace from their linkage
      name.  */
   if (cu->language == language_cplus
-      && !VEC_empty (dwarf2_section_info_def,
-		     cu->per_cu->dwarf2_per_objfile->types)
+      && !cu->per_cu->dwarf2_per_objfile->types.empty ()
       && die_parent == NULL
       && has_children
       && (tag == DW_TAG_class_type
@@ -22533,7 +22511,7 @@ determine_prefix (struct die_info *die, struct dwarf2_cu *cu)
       case DW_TAG_partial_unit:
 	/* gcc-4.5 -gdwarf-4 can drop the enclosing namespace.  Cope.  */
 	if (cu->language == language_cplus
-	    && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)
+	    && !dwarf2_per_objfile->types.empty ()
 	    && die->child != NULL
 	    && (die->tag == DW_TAG_class_type
 		|| die->tag == DW_TAG_structure_type
diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
index 4a1cd9cf00ed..9251bde12592 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2read.h
@@ -73,9 +73,6 @@ struct dwarf2_section_info
   bool is_virtual;
 };
 
-typedef struct dwarf2_section_info dwarf2_section_info_def;
-DEF_VEC_O (dwarf2_section_info_def);
-
 /* Read the contents of the section INFO.
    OBJFILE is the main object file, but not necessarily the file where
    the section comes from.  E.g., for DWO files the bfd of INFO is the bfd
@@ -167,7 +164,7 @@ public:
   dwarf2_section_info debug_names {};
   dwarf2_section_info debug_aranges {};
 
-  VEC (dwarf2_section_info_def) *types = NULL;
+  std::vector<dwarf2_section_info> types;
 
   /* Back link.  */
   struct objfile *objfile = NULL;
-- 
2.22.0

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/4] dwarf2read: Use bool for dwarf2_section_info fields
  2019-06-21 11:58 [PATCH 0/4] C++-fication of dwo_file and removal of a VEC Simon Marchi
@ 2019-06-21 11:58 ` Simon Marchi
  2019-06-21 11:58 ` [PATCH 4/4] dwarf2read: Get rid of VEC (dwarf2_section_info_def) Simon Marchi
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2019-06-21 11:58 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

Use bool instead of char where applicable in dwarf2_section_info.

No functional changes intended.

gdb/ChangeLog:

	* dwarf2read.h (struct dwarf2_section_info) <readin,
	is_virtual>: Change type to bool.
	* dwarf2read.c (dwarf2_read_section, create_dwp_v2_section): Use
	true instead of 1.
---
 gdb/dwarf2read.c | 4 ++--
 gdb/dwarf2read.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 9cf513b582a5..bfc362480f26 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -2474,7 +2474,7 @@ dwarf2_read_section (struct objfile *objfile, dwarf2_section_info *info)
   if (info->readin)
     return;
   info->buffer = NULL;
-  info->readin = 1;
+  info->readin = true;
 
   if (dwarf2_section_empty_p (info))
     return;
@@ -12513,7 +12513,7 @@ create_dwp_v2_section (struct dwarf2_per_objfile *dwarf2_per_objfile,
 
   memset (&result, 0, sizeof (result));
   result.s.containing_section = section;
-  result.is_virtual = 1;
+  result.is_virtual = true;
 
   if (size == 0)
     return result;
diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
index 7113cfd38482..c06093c99794 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2read.h
@@ -67,10 +67,10 @@ struct dwarf2_section_info
      Only valid if is_virtual.  */
   bfd_size_type virtual_offset;
   /* True if we have tried to read this section.  */
-  char readin;
+  bool readin;
   /* True if this is a virtual section, False otherwise.
      This specifies which of s.section and s.containing_section to use.  */
-  char is_virtual;
+  bool is_virtual;
 };
 
 typedef struct dwarf2_section_info dwarf2_section_info_def;
-- 
2.22.0

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 0/4] C++-fication of dwo_file and removal of a VEC
@ 2019-06-21 11:58 Simon Marchi
  2019-06-21 11:58 ` [PATCH 1/4] dwarf2read: Use bool for dwarf2_section_info fields Simon Marchi
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Simon Marchi @ 2019-06-21 11:58 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

I did this while navigating the dwo code to try to understand how it
works.  No functional changes intended, it is just meant to convert a
few things to their C++ equivalent.

Regtested on the buildbot.

Simon Marchi (4):
  dwarf2read: Use bool for dwarf2_section_info fields
  dwarf2read: C++ify dwo_file
  dwarf2read: Make dwo_file::dbfd a gdb_bfd_ref_ptr
  dwarf2read: Get rid of VEC (dwarf2_section_info_def)

 gdb/dwarf-index-write.c |   2 +-
 gdb/dwarf2read.c        | 156 +++++++++++++---------------------------
 gdb/dwarf2read.h        |  11 ++-
 3 files changed, 53 insertions(+), 116 deletions(-)

-- 
2.22.0

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/4] dwarf2read: C++ify dwo_file
  2019-06-21 11:58 [PATCH 0/4] C++-fication of dwo_file and removal of a VEC Simon Marchi
  2019-06-21 11:58 ` [PATCH 1/4] dwarf2read: Use bool for dwarf2_section_info fields Simon Marchi
  2019-06-21 11:58 ` [PATCH 4/4] dwarf2read: Get rid of VEC (dwarf2_section_info_def) Simon Marchi
@ 2019-06-21 11:58 ` Simon Marchi
  2019-06-21 12:05 ` [PATCH 3/4] dwarf2read: Make dwo_file::dbfd a gdb_bfd_ref_ptr Simon Marchi
  2019-06-21 16:33 ` [PATCH 0/4] C++-fication of dwo_file and removal of a VEC Tom Tromey
  4 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2019-06-21 11:58 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

This patch changes dwo_file to be allocated/deallocated with new/delete,
so that we can start using C++ features in it, and in struct
dwo_sections.

The free_dwo_file function becomes the destructor of struct dwo_file
(and will disappear in upcoming patches, which will use gdb_bfd_ref_ptr
for dbfd and an std::vector for sections.types).

gdb/ChangeLog:

	* dwarf2read.h (struct dwarf2_per_objfile) <dwo_files>: Change
	type to htab_up.
	* dwarf2read.c (struct dwo_file): Initialize fields.
	<~dwo_file>: New.
	(free_dwo_file): Remove, move content to ~dwo_file.
	(struct dwo_file_deleter): Remove.
	(dwo_file_up>: Remove custom deleter.
	(free_dwo_files): Remove.
	(dwarf2_per_objfile::~dwarf2_per_objfile): Don't explicitly free
	dwo_files.
	(process_skeletonless_type_units): Call unique_ptr::get.
	(allocate_dwo_file_hash_table): Add deleter to created hash
	table.  Change return type to htab_up.
	(lookup_dwo_file_slot): Don't memset dwo_file, call
	unique_ptr::get.
	(create_dwo_unit_in_dwp_v1): Allocate dwo_file with new.
	(create_dwo_unit_in_dwp_v2): Likewise.
	(open_and_init_dwo_file): Likewise.
	(free_dwo_file_from_slot): Remove.
---
 gdb/dwarf2read.c | 112 ++++++++++++++++-------------------------------
 gdb/dwarf2read.h |   2 +-
 2 files changed, 39 insertions(+), 75 deletions(-)

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index bfc362480f26..c73ab6367da9 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -703,33 +703,43 @@ enum dwp_v2_section_ids
 
 struct dwo_file
 {
+  dwo_file () = default;
+  DISABLE_COPY_AND_ASSIGN (dwo_file);
+
+  ~dwo_file ()
+  {
+    gdb_bfd_unref (dbfd);
+
+    VEC_free (dwarf2_section_info_def, sections.types);
+  }
+
   /* The DW_AT_GNU_dwo_name attribute.
      For virtual DWO files the name is constructed from the section offsets
      of abbrev,line,loc,str_offsets so that we combine virtual DWO files
      from related CU+TUs.  */
-  const char *dwo_name;
+  const char *dwo_name = nullptr;
 
   /* The DW_AT_comp_dir attribute.  */
-  const char *comp_dir;
+  const char *comp_dir = nullptr;
 
   /* The bfd, when the file is open.  Otherwise this is NULL.
      This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd.  */
-  bfd *dbfd;
+  bfd *dbfd = nullptr;
 
   /* The sections that make up this DWO file.
      Remember that for virtual DWO files in DWP V2, these are virtual
      sections (for lack of a better name).  */
-  struct dwo_sections sections;
+  struct dwo_sections sections {};
 
   /* The CUs in the file.
      Each element is a struct dwo_unit. Multiple CUs per DWO are supported as
      an extension to handle LLVM's Link Time Optimization output (where
      multiple source files may be compiled into a single object/dwo pair). */
-  htab_t cus;
+  htab_t cus {};
 
   /* Table of TUs in the file.
      Each element is a struct dwo_unit.  */
-  htab_t tus;
+  htab_t tus {};
 };
 
 /* These sections are what may appear in a DWP file.  */
@@ -1988,21 +1998,9 @@ static struct dwo_unit *lookup_dwo_type_unit
 
 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data *);
 
-static void free_dwo_file (struct dwo_file *);
-
-/* A unique_ptr helper to free a dwo_file.  */
-
-struct dwo_file_deleter
-{
-  void operator() (struct dwo_file *df) const
-  {
-    free_dwo_file (df);
-  }
-};
-
 /* A unique pointer to a dwo_file.  */
 
-typedef std::unique_ptr<struct dwo_file, dwo_file_deleter> dwo_file_up;
+typedef std::unique_ptr<struct dwo_file> dwo_file_up;
 
 static void process_cu_includes (struct dwarf2_per_objfile *dwarf2_per_objfile);
 
@@ -2147,8 +2145,6 @@ dwarf2_per_objfile::dwarf2_per_objfile (struct objfile *objfile_,
     locate_sections (obfd, sec, *names);
 }
 
-static void free_dwo_files (htab_t dwo_files, struct objfile *objfile);
-
 dwarf2_per_objfile::~dwarf2_per_objfile ()
 {
   /* Cached DIE trees use xmalloc and the comp_unit_obstack.  */
@@ -2168,9 +2164,6 @@ dwarf2_per_objfile::~dwarf2_per_objfile ()
 
   VEC_free (dwarf2_section_info_def, types);
 
-  if (dwo_files != NULL)
-    free_dwo_files (dwo_files, objfile);
-
   /* Everything else should be on the objfile obstack.  */
 }
 
@@ -8407,7 +8400,7 @@ process_skeletonless_type_units (struct dwarf2_per_objfile *dwarf2_per_objfile)
   if (get_dwp_file (dwarf2_per_objfile) == NULL
       && dwarf2_per_objfile->dwo_files != NULL)
     {
-      htab_traverse_noresize (dwarf2_per_objfile->dwo_files,
+      htab_traverse_noresize (dwarf2_per_objfile->dwo_files.get (),
 			      process_dwo_file_for_skeletonless_type_units,
 			      dwarf2_per_objfile);
     }
@@ -11775,16 +11768,23 @@ eq_dwo_file (const void *item_lhs, const void *item_rhs)
 
 /* Allocate a hash table for DWO files.  */
 
-static htab_t
+static htab_up
 allocate_dwo_file_hash_table (struct objfile *objfile)
 {
-  return htab_create_alloc_ex (41,
-			       hash_dwo_file,
-			       eq_dwo_file,
-			       NULL,
-			       &objfile->objfile_obstack,
-			       hashtab_obstack_allocate,
-			       dummy_obstack_deallocate);
+  auto delete_dwo_file = [] (void *item)
+    {
+      struct dwo_file *dwo_file = (struct dwo_file *) item;
+
+      delete dwo_file;
+    };
+
+  return htab_up (htab_create_alloc_ex (41,
+					hash_dwo_file,
+					eq_dwo_file,
+					delete_dwo_file,
+					&objfile->objfile_obstack,
+					hashtab_obstack_allocate,
+					dummy_obstack_deallocate));
 }
 
 /* Lookup DWO file DWO_NAME.  */
@@ -11801,10 +11801,10 @@ lookup_dwo_file_slot (struct dwarf2_per_objfile *dwarf2_per_objfile,
     dwarf2_per_objfile->dwo_files
       = allocate_dwo_file_hash_table (dwarf2_per_objfile->objfile);
 
-  memset (&find_entry, 0, sizeof (find_entry));
   find_entry.dwo_name = dwo_name;
   find_entry.comp_dir = comp_dir;
-  slot = htab_find_slot (dwarf2_per_objfile->dwo_files, &find_entry, INSERT);
+  slot = htab_find_slot (dwarf2_per_objfile->dwo_files.get (), &find_entry,
+			 INSERT);
 
   return slot;
 }
@@ -12451,7 +12451,7 @@ create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile *dwarf2_per_objfile,
 	  fprintf_unfiltered (gdb_stdlog, "Creating virtual DWO: %s\n",
 			      virtual_dwo_name.c_str ());
 	}
-      dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_file);
+      dwo_file = new struct dwo_file;
       dwo_file->dwo_name
 	= (const char *) obstack_copy0 (&objfile->objfile_obstack,
 					virtual_dwo_name.c_str (),
@@ -12649,7 +12649,7 @@ create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile *dwarf2_per_objfile,
 	  fprintf_unfiltered (gdb_stdlog, "Creating virtual DWO: %s\n",
 			      virtual_dwo_name.c_str ());
 	}
-      dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_file);
+      dwo_file = new struct dwo_file;
       dwo_file->dwo_name
 	= (const char *) obstack_copy0 (&objfile->objfile_obstack,
 					virtual_dwo_name.c_str (),
@@ -12959,7 +12959,6 @@ open_and_init_dwo_file (struct dwarf2_per_cu_data *per_cu,
 			const char *dwo_name, const char *comp_dir)
 {
   struct dwarf2_per_objfile *dwarf2_per_objfile = per_cu->dwarf2_per_objfile;
-  struct objfile *objfile = dwarf2_per_objfile->objfile;
 
   gdb_bfd_ref_ptr dbfd (open_dwo_file (dwarf2_per_objfile, dwo_name, comp_dir));
   if (dbfd == NULL)
@@ -12969,10 +12968,7 @@ open_and_init_dwo_file (struct dwarf2_per_cu_data *per_cu,
       return NULL;
     }
 
-  /* We use a unique pointer here, despite the obstack allocation,
-     because a dwo_file needs some cleanup if it is abandoned.  */
-  dwo_file_up dwo_file (OBSTACK_ZALLOC (&objfile->objfile_obstack,
-					struct dwo_file));
+  dwo_file_up dwo_file (new struct dwo_file);
   dwo_file->dwo_name = dwo_name;
   dwo_file->comp_dir = comp_dir;
   dwo_file->dbfd = dbfd.release ();
@@ -13486,38 +13482,6 @@ queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data *per_cu)
     htab_traverse_noresize (dwo_file->tus, queue_and_load_dwo_tu, per_cu);
 }
 
-/* Free all resources associated with DWO_FILE.
-   Close the DWO file and munmap the sections.  */
-
-static void
-free_dwo_file (struct dwo_file *dwo_file)
-{
-  /* Note: dbfd is NULL for virtual DWO files.  */
-  gdb_bfd_unref (dwo_file->dbfd);
-
-  VEC_free (dwarf2_section_info_def, dwo_file->sections.types);
-}
-
-/* Traversal function for free_dwo_files.  */
-
-static int
-free_dwo_file_from_slot (void **slot, void *info)
-{
-  struct dwo_file *dwo_file = (struct dwo_file *) *slot;
-
-  free_dwo_file (dwo_file);
-
-  return 1;
-}
-
-/* Free all resources associated with DWO_FILES.  */
-
-static void
-free_dwo_files (htab_t dwo_files, struct objfile *objfile)
-{
-  htab_traverse_noresize (dwo_files, free_dwo_file_from_slot, objfile);
-}
-\f
 /* Read in various DIEs.  */
 
 /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes).
diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
index c06093c99794..4a1cd9cf00ed 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2read.h
@@ -197,7 +197,7 @@ public:
 
   /* A table mapping DW_AT_dwo_name values to struct dwo_file objects.
      This is NULL if the table hasn't been allocated yet.  */
-  htab_t dwo_files {};
+  htab_up dwo_files;
 
   /* True if we've checked for whether there is a DWP file.  */
   bool dwp_checked = false;
-- 
2.22.0

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/4] dwarf2read: Make dwo_file::dbfd a gdb_bfd_ref_ptr
  2019-06-21 11:58 [PATCH 0/4] C++-fication of dwo_file and removal of a VEC Simon Marchi
                   ` (2 preceding siblings ...)
  2019-06-21 11:58 ` [PATCH 2/4] dwarf2read: C++ify dwo_file Simon Marchi
@ 2019-06-21 12:05 ` Simon Marchi
  2019-06-21 16:33 ` [PATCH 0/4] C++-fication of dwo_file and removal of a VEC Tom Tromey
  4 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2019-06-21 12:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

This removes the manual call to gdb_bfd_ref in favor of gdb_bfd_ref_ptr.

gdb/ChangeLog:

  * dwarf2read.c (struct dwo_file) <dbfd>: Change type to
  gdb_bfd_ref_ptr.
  <~dwo_file>: Remove call to gdb_bfd_unref.
  (open_and_init_dwo_file): Move gdb_bfd_ref_ptr into dbfd field. Call
  gdb_bfd_ref_ptr::get.
---
 gdb/dwarf2read.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index c73ab6367da9..05c872017066 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -708,8 +708,6 @@ struct dwo_file
 
   ~dwo_file ()
   {
-    gdb_bfd_unref (dbfd);
-
     VEC_free (dwarf2_section_info_def, sections.types);
   }
 
@@ -724,7 +722,7 @@ struct dwo_file
 
   /* The bfd, when the file is open.  Otherwise this is NULL.
      This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd.  */
-  bfd *dbfd = nullptr;
+  gdb_bfd_ref_ptr dbfd;
 
   /* The sections that make up this DWO file.
      Remember that for virtual DWO files in DWP V2, these are virtual
@@ -12960,7 +12958,7 @@ open_and_init_dwo_file (struct dwarf2_per_cu_data *per_cu,
 {
   struct dwarf2_per_objfile *dwarf2_per_objfile = per_cu->dwarf2_per_objfile;
 
-  gdb_bfd_ref_ptr dbfd (open_dwo_file (dwarf2_per_objfile, dwo_name, comp_dir));
+  gdb_bfd_ref_ptr dbfd = open_dwo_file (dwarf2_per_objfile, dwo_name, comp_dir);
   if (dbfd == NULL)
     {
       if (dwarf_read_debug)
@@ -12971,9 +12969,9 @@ open_and_init_dwo_file (struct dwarf2_per_cu_data *per_cu,
   dwo_file_up dwo_file (new struct dwo_file);
   dwo_file->dwo_name = dwo_name;
   dwo_file->comp_dir = comp_dir;
-  dwo_file->dbfd = dbfd.release ();
+  dwo_file->dbfd = std::move (dbfd);
 
-  bfd_map_over_sections (dwo_file->dbfd, dwarf2_locate_dwo_sections,
+  bfd_map_over_sections (dwo_file->dbfd.get (), dwarf2_locate_dwo_sections,
 			 &dwo_file->sections);
 
   create_cus_hash_table (dwarf2_per_objfile, *dwo_file, dwo_file->sections.info,
-- 
2.22.0

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/4] C++-fication of dwo_file and removal of a VEC
  2019-06-21 11:58 [PATCH 0/4] C++-fication of dwo_file and removal of a VEC Simon Marchi
                   ` (3 preceding siblings ...)
  2019-06-21 12:05 ` [PATCH 3/4] dwarf2read: Make dwo_file::dbfd a gdb_bfd_ref_ptr Simon Marchi
@ 2019-06-21 16:33 ` Tom Tromey
  2019-06-21 18:16   ` Simon Marchi
  4 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2019-06-21 16:33 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:

Simon> I did this while navigating the dwo code to try to understand how it
Simon> works.  No functional changes intended, it is just meant to convert a
Simon> few things to their C++ equivalent.

I read through this and everything looked good to me.
Thank you for doing this.

Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/4] C++-fication of dwo_file and removal of a VEC
  2019-06-21 16:33 ` [PATCH 0/4] C++-fication of dwo_file and removal of a VEC Tom Tromey
@ 2019-06-21 18:16   ` Simon Marchi
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Marchi @ 2019-06-21 18:16 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On 2019-06-21 12:33 p.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@efficios.com> writes:
> 
> Simon> I did this while navigating the dwo code to try to understand how it
> Simon> works.  No functional changes intended, it is just meant to convert a
> Simon> few things to their C++ equivalent.
> 
> I read through this and everything looked good to me.
> Thank you for doing this.
> 
> Tom

Thanks, I have pushed it.

Simon

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-06-21 18:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-21 11:58 [PATCH 0/4] C++-fication of dwo_file and removal of a VEC Simon Marchi
2019-06-21 11:58 ` [PATCH 1/4] dwarf2read: Use bool for dwarf2_section_info fields Simon Marchi
2019-06-21 11:58 ` [PATCH 4/4] dwarf2read: Get rid of VEC (dwarf2_section_info_def) Simon Marchi
2019-06-21 11:58 ` [PATCH 2/4] dwarf2read: C++ify dwo_file Simon Marchi
2019-06-21 12:05 ` [PATCH 3/4] dwarf2read: Make dwo_file::dbfd a gdb_bfd_ref_ptr Simon Marchi
2019-06-21 16:33 ` [PATCH 0/4] C++-fication of dwo_file and removal of a VEC Tom Tromey
2019-06-21 18:16   ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).