public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFA 0/2] Replace one use of VEC in dwarf2read.c
@ 2018-05-19 20:37 Tom Tromey
  2018-05-19 22:09 ` [RFA 2/2] Use std::vector for dwarf2_per_cu_data Tom Tromey
  2018-05-20 23:34 ` [RFA 1/2] Allocate dwarf2_per_cu_data and signatured_type with new Tom Tromey
  0 siblings, 2 replies; 4+ messages in thread
From: Tom Tromey @ 2018-05-19 20:37 UTC (permalink / raw)
  To: gdb-patches

This series replaces one use of VEC in dwarf2read.c with std::vector.
I think a good medium-term goal would be to remove all uses of VEC
from gdb.

Tested by the buildbot.

Tom

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

* [RFA 2/2] Use std::vector for dwarf2_per_cu_data
  2018-05-19 20:37 [RFA 0/2] Replace one use of VEC in dwarf2read.c Tom Tromey
@ 2018-05-19 22:09 ` Tom Tromey
  2018-05-20 23:34 ` [RFA 1/2] Allocate dwarf2_per_cu_data and signatured_type with new Tom Tromey
  1 sibling, 0 replies; 4+ messages in thread
From: Tom Tromey @ 2018-05-19 22:09 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This removes one use of VEC from dwarf2read, in favor of std::vector.

gdb/ChangeLog
2018-05-18  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (dwarf2_per_cu_data): Update.
	(process_psymtab_comp_unit_reader, scan_partial_symbols)
	(recursively_compute_inclusions)
	(compute_compunit_symtab_includes, process_cu_includes)
	(process_full_comp_unit, process_imported_unit_die)
	(queue_and_load_dwo_tu, follow_die_sig_1): Update.
	* dwarf2read.h (dwarf2_per_cu_ptr): Remove typedef.  Don't declare
	VEC.
	(struct dwarf2_per_objfile) <just_read_cus>: Now a std::vector.
	(struct dwarf2_per_cu_data) <imported_symtabs>: Now a
	std::vector.
---
 gdb/ChangeLog    | 14 ++++++++++++
 gdb/dwarf2read.c | 69 ++++++++++++++++----------------------------------------
 gdb/dwarf2read.h |  7 ++----
 3 files changed, 36 insertions(+), 54 deletions(-)

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index e53c015932..11d66bc0ee 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -2130,7 +2130,6 @@ dwarf2_per_cu_data::dwarf2_per_cu_data ()
 
 dwarf2_per_cu_data::~dwarf2_per_cu_data ()
 {
-  VEC_free (dwarf2_per_cu_ptr, imported_symtabs);
 }
 
 /* See declaration.  */
@@ -8010,24 +8009,20 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
 
   end_psymtab_common (objfile, pst);
 
-  if (!VEC_empty (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs))
+  if (!cu->per_cu->imported_symtabs.empty ())
     {
       int i;
-      int len = VEC_length (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs);
-      struct dwarf2_per_cu_data *iter;
+      int len = cu->per_cu->imported_symtabs.size ();
 
       /* Fill in 'dependencies' here; we fill in 'users' in a
 	 post-pass.  */
       pst->number_of_dependencies = len;
       pst->dependencies =
 	XOBNEWVEC (&objfile->objfile_obstack, struct partial_symtab *, len);
-      for (i = 0;
-	   VEC_iterate (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs,
-			i, iter);
-	   ++i)
-	pst->dependencies[i] = iter->v.psymtab;
+      for (i = 0; i < len; ++i)
+	pst->dependencies[i] = cu->per_cu->imported_symtabs[i]->v.psymtab;
 
-      VEC_free (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs);
+      cu->per_cu->imported_symtabs.clear ();
     }
 
   /* Get the list of files included in the current compilation unit,
@@ -8656,8 +8651,7 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
 		if (per_cu->v.psymtab == NULL)
 		  process_psymtab_comp_unit (per_cu, 1, cu->language);
 
-		VEC_safe_push (dwarf2_per_cu_ptr,
-			       cu->per_cu->imported_symtabs, per_cu);
+		cu->per_cu->imported_symtabs.push_back (per_cu);
 	      }
 	      break;
 	    case DW_TAG_imported_declaration:
@@ -10150,9 +10144,7 @@ recursively_compute_inclusions (VEC (compunit_symtab_ptr) **result,
 				struct compunit_symtab *immediate_parent)
 {
   void **slot;
-  int ix;
   struct compunit_symtab *cust;
-  struct dwarf2_per_cu_data *iter;
 
   slot = htab_find_slot (all_children, per_cu, INSERT);
   if (*slot != NULL)
@@ -10187,13 +10179,9 @@ recursively_compute_inclusions (VEC (compunit_symtab_ptr) **result,
 	}
     }
 
-  for (ix = 0;
-       VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs, ix, iter);
-       ++ix)
-    {
-      recursively_compute_inclusions (result, all_children,
-				      all_type_symtabs, iter, cust);
-    }
+  for (struct dwarf2_per_cu_data *iter : per_cu->imported_symtabs)
+    recursively_compute_inclusions (result, all_children,
+				    all_type_symtabs, iter, cust);
 }
 
 /* Compute the compunit_symtab 'includes' fields for the compunit_symtab of
@@ -10204,10 +10192,9 @@ compute_compunit_symtab_includes (struct dwarf2_per_cu_data *per_cu)
 {
   gdb_assert (! per_cu->is_debug_types);
 
-  if (!VEC_empty (dwarf2_per_cu_ptr, per_cu->imported_symtabs))
+  if (!per_cu->imported_symtabs.empty ())
     {
       int ix, len;
-      struct dwarf2_per_cu_data *per_cu_iter;
       struct compunit_symtab *compunit_symtab_iter;
       VEC (compunit_symtab_ptr) *result_symtabs = NULL;
       htab_t all_children, all_type_symtabs;
@@ -10222,15 +10209,10 @@ compute_compunit_symtab_includes (struct dwarf2_per_cu_data *per_cu)
       all_type_symtabs = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer,
 					    NULL, xcalloc, xfree);
 
-      for (ix = 0;
-	   VEC_iterate (dwarf2_per_cu_ptr, per_cu->imported_symtabs,
-			ix, per_cu_iter);
-	   ++ix)
-	{
-	  recursively_compute_inclusions (&result_symtabs, all_children,
-					  all_type_symtabs, per_cu_iter,
-					  cust);
-	}
+      for (struct dwarf2_per_cu_data *per_cu_iter : per_cu->imported_symtabs)
+	recursively_compute_inclusions (&result_symtabs, all_children,
+					all_type_symtabs, per_cu_iter,
+					cust);
 
       /* Now we have a transitive closure of all the included symtabs.  */
       len = VEC_length (compunit_symtab_ptr, result_symtabs);
@@ -10256,19 +10238,13 @@ compute_compunit_symtab_includes (struct dwarf2_per_cu_data *per_cu)
 static void
 process_cu_includes (struct dwarf2_per_objfile *dwarf2_per_objfile)
 {
-  int ix;
-  struct dwarf2_per_cu_data *iter;
-
-  for (ix = 0;
-       VEC_iterate (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus,
-		    ix, iter);
-       ++ix)
+  for (struct dwarf2_per_cu_data *iter : dwarf2_per_objfile->just_read_cus)
     {
       if (! iter->is_debug_types)
 	compute_compunit_symtab_includes (iter);
     }
 
-  VEC_free (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus);
+  dwarf2_per_objfile->just_read_cus.clear ();
 }
 
 /* Generate full symbol information for PER_CU, whose DIEs have
@@ -10376,7 +10352,7 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
     }
 
   /* Push it for inclusion processing later.  */
-  VEC_safe_push (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus, per_cu);
+  dwarf2_per_objfile->just_read_cus.push_back (per_cu);
 }
 
 /* Generate full symbol information for type unit PER_CU, whose DIEs have
@@ -10485,8 +10461,7 @@ process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu)
       if (maybe_queue_comp_unit (cu, per_cu, cu->language))
 	load_full_comp_unit (per_cu, false, cu->language);
 
-      VEC_safe_push (dwarf2_per_cu_ptr, cu->per_cu->imported_symtabs,
-		     per_cu);
+      cu->per_cu->imported_symtabs.push_back (per_cu);
     }
 }
 
@@ -13408,7 +13383,7 @@ queue_and_load_dwo_tu (void **slot, void *info)
 	 while processing PER_CU.  */
       if (maybe_queue_comp_unit (NULL, sig_cu, per_cu->cu->language))
 	load_full_type_unit (sig_cu);
-      VEC_safe_push (dwarf2_per_cu_ptr, per_cu->imported_symtabs, sig_cu);
+      per_cu->imported_symtabs.push_back (sig_cu);
     }
 
   return 1;
@@ -23260,11 +23235,7 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type,
 	 http://sourceware.org/bugzilla/show_bug.cgi?id=15021.  */
       if (dwarf2_per_objfile->index_table != NULL
 	  && dwarf2_per_objfile->index_table->version <= 7)
-	{
-	  VEC_safe_push (dwarf2_per_cu_ptr,
-			 (*ref_cu)->per_cu->imported_symtabs,
-			 sig_cu->per_cu);
-	}
+	(*ref_cu)->per_cu->imported_symtabs.push_back (sig_cu->per_cu);
 
       *ref_cu = sig_cu;
       return die;
diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
index 369461f965..405a7edf4f 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2read.h
@@ -23,9 +23,6 @@
 #include "filename-seen-cache.h"
 #include "gdb_obstack.h"
 
-typedef struct dwarf2_per_cu_data *dwarf2_per_cu_ptr;
-DEF_VEC_P (dwarf2_per_cu_ptr);
-
 /* A descriptor for dwarf sections.
 
    S.ASECTION, SIZE are typically initialized when the objfile is first
@@ -233,7 +230,7 @@ public:
   htab_t die_type_hash {};
 
   /* The CUs we recently read.  */
-  VEC (dwarf2_per_cu_ptr) *just_read_cus = NULL;
+  std::vector<struct dwarf2_per_cu_data *> just_read_cus;
 
   /* Table containing line_header indexed by offset and offset_in_dwz.  */
   htab_t line_header_hash {};
@@ -350,7 +347,7 @@ struct dwarf2_per_cu_data
      to.  Concurrently with this change gdb was modified to emit version 8
      indices so we only pay a price for gold generated indices.
      http://sourceware.org/bugzilla/show_bug.cgi?id=15021.  */
-  VEC (dwarf2_per_cu_ptr) *imported_symtabs = nullptr;
+  std::vector<struct dwarf2_per_cu_data *> imported_symtabs;
 };
 
 /* Entry in the signatured_types hash table.  */
-- 
2.13.6

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

* [RFA 1/2] Allocate dwarf2_per_cu_data and signatured_type with new
  2018-05-19 20:37 [RFA 0/2] Replace one use of VEC in dwarf2read.c Tom Tromey
  2018-05-19 22:09 ` [RFA 2/2] Use std::vector for dwarf2_per_cu_data Tom Tromey
@ 2018-05-20 23:34 ` Tom Tromey
  2018-05-21  9:54   ` Simon Marchi
  1 sibling, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2018-05-20 23:34 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This changes dwarf2_per_cu_data and signatured_type to be allocated
with new, rather than on the obstack.  The main idea here is to move
destructors into the objects that actually own the data, to make
dwarf2read a bit simpler to understand, and to enable the next patch.

This particular change required one little hack to make "delete" work
properly.  I did not think it would be good to add a virtual
destructor to dwarf2_per_cu_data just for this.

gdb/ChangeLog
2018-05-18  Tom Tromey  <tom@tromey.com>

	* dwarf2read.c (dwarf2_per_cu_data::dwarf2_per_cu_data)
	(dwarf2_per_cu_data::~dwarf2_per_cu_data): Define.
	(~dwarf2_per_objfile): Update.
	(create_cu_from_index_list): Use new.
	(create_signatured_type_table_from_index)
	(create_signatured_type_table_from_debug_names, add_type_unit)
	(read_comp_units_from_section): Use new.
	(create_cus_hash_table): Update.
	* dwarf2read.h (struct dwarf2_per_cu_data): Add constructor,
	destructor, initializers.
	(struct signatured_type): Likewise.
	(struct dwarf2_per_cu_data) <is_sig_type>: New member.
---
 gdb/ChangeLog    | 15 +++++++++++++++
 gdb/dwarf2read.c | 53 +++++++++++++++++++++++++++++++++--------------------
 gdb/dwarf2read.h | 47 +++++++++++++++++++++++++++++++++--------------
 3 files changed, 81 insertions(+), 34 deletions(-)

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 0690785c5e..e53c015932 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -2117,6 +2117,22 @@ attr_value_as_address (struct attribute *attr)
   return addr;
 }
 
+dwarf2_per_cu_data::dwarf2_per_cu_data ()
+  : queued (0),
+    load_all_dies (0),
+    is_debug_types (0),
+    is_dwz (0),
+    reading_dwo_directly (0),
+    tu_read (0),
+    is_sig_type (0)
+{
+}
+
+dwarf2_per_cu_data::~dwarf2_per_cu_data ()
+{
+  VEC_free (dwarf2_per_cu_ptr, imported_symtabs);
+}
+
 /* See declaration.  */
 
 dwarf2_per_objfile::dwarf2_per_objfile (struct objfile *objfile_,
@@ -2146,10 +2162,15 @@ dwarf2_per_objfile::~dwarf2_per_objfile ()
     htab_delete (line_header_hash);
 
   for (dwarf2_per_cu_data *per_cu : all_comp_units)
-    VEC_free (dwarf2_per_cu_ptr, per_cu->imported_symtabs);
+    {
+      if (per_cu->is_sig_type)
+	delete (struct signatured_type *) per_cu;
+      else
+	delete per_cu;
+    }
 
   for (signatured_type *sig_type : all_type_units)
-    VEC_free (dwarf2_per_cu_ptr, sig_type->per_cu.imported_symtabs);
+    delete sig_type;
 
   VEC_free (dwarf2_section_info_def, types);
 
@@ -2959,9 +2980,7 @@ create_cu_from_index_list (struct dwarf2_per_objfile *dwarf2_per_objfile,
                           sect_offset sect_off, ULONGEST length)
 {
   struct objfile *objfile = dwarf2_per_objfile->objfile;
-  dwarf2_per_cu_data *the_cu
-    = OBSTACK_ZALLOC (&objfile->objfile_obstack,
-                     struct dwarf2_per_cu_data);
+  dwarf2_per_cu_data *the_cu = new struct dwarf2_per_cu_data;
   the_cu->sect_off = sect_off;
   the_cu->length = length;
   the_cu->dwarf2_per_objfile = dwarf2_per_objfile;
@@ -3052,10 +3071,10 @@ create_signatured_type_table_from_index
       signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE);
       bytes += 3 * 8;
 
-      sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack,
-				 struct signatured_type);
+      sig_type = new struct signatured_type;
       sig_type->signature = signature;
       sig_type->type_offset_in_tu = type_offset_in_tu;
+      sig_type->per_cu.is_sig_type = 1;
       sig_type->per_cu.is_debug_types = 1;
       sig_type->per_cu.section = section;
       sig_type->per_cu.sect_off = sect_off;
@@ -3109,10 +3128,10 @@ create_signatured_type_table_from_debug_names
 				     section->buffer + to_underlying (sect_off),
 				     rcuh_kind::TYPE);
 
-      sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack,
-				 struct signatured_type);
+      sig_type = new struct signatured_type;
       sig_type->signature = cu_header.signature;
       sig_type->type_offset_in_tu = cu_header.type_cu_offset_in_tu;
+      sig_type->per_cu.is_sig_type = 1;
       sig_type->per_cu.is_debug_types = 1;
       sig_type->per_cu.section = section;
       sig_type->per_cu.sect_off = sect_off;
@@ -6831,11 +6850,11 @@ add_type_unit (struct dwarf2_per_objfile *dwarf2_per_objfile, ULONGEST sig,
       == dwarf2_per_objfile->all_type_units.capacity ())
     ++dwarf2_per_objfile->tu_stats.nr_all_type_units_reallocs;
 
-  signatured_type *sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack,
-					      struct signatured_type);
+  signatured_type *sig_type = new struct signatured_type;
 
   dwarf2_per_objfile->all_type_units.push_back (sig_type);
   sig_type->signature = sig;
+  sig_type->per_cu.is_sig_type = 1;
   sig_type->per_cu.is_debug_types = 1;
   if (dwarf2_per_objfile->using_index)
     {
@@ -8504,18 +8523,13 @@ read_comp_units_from_section (struct dwarf2_per_objfile *dwarf2_per_objfile,
 
       /* Save the compilation unit for later lookup.  */
       if (cu_header.unit_type != DW_UT_type)
-	{
-	  this_cu = XOBNEW (&objfile->objfile_obstack,
-			    struct dwarf2_per_cu_data);
-	  memset (this_cu, 0, sizeof (*this_cu));
-	}
+	this_cu = new struct dwarf2_per_cu_data;
       else
 	{
-	  auto sig_type = XOBNEW (&objfile->objfile_obstack,
-				  struct signatured_type);
-	  memset (sig_type, 0, sizeof (*sig_type));
+	  auto sig_type = new struct signatured_type;
 	  sig_type->signature = cu_header.signature;
 	  sig_type->type_offset_in_tu = cu_header.type_cu_offset_in_tu;
+	  sig_type->per_cu.is_sig_type = 1;
 	  this_cu = &sig_type->per_cu;
 	}
       this_cu->is_debug_types = (cu_header.unit_type == DW_UT_type);
@@ -11865,7 +11879,6 @@ create_cus_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
 
       memset (&create_dwo_cu_data.dwo_unit, 0,
 	      sizeof (create_dwo_cu_data.dwo_unit));
-      memset (&per_cu, 0, sizeof (per_cu));
       per_cu.dwarf2_per_objfile = dwarf2_per_objfile;
       per_cu.is_debug_types = 0;
       per_cu.sect_off = sect_offset (info_ptr - section.buffer);
diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h
index fbac7171de..369461f965 100644
--- a/gdb/dwarf2read.h
+++ b/gdb/dwarf2read.h
@@ -253,16 +253,21 @@ dwarf2_per_objfile *get_dwarf2_per_objfile (struct objfile *objfile);
 
 struct dwarf2_per_cu_data
 {
+  dwarf2_per_cu_data ();
+  ~dwarf2_per_cu_data ();
+
+  DISABLE_COPY_AND_ASSIGN (dwarf2_per_cu_data);
+
   /* The start offset and length of this compilation unit.
      NOTE: Unlike comp_unit_head.length, this length includes
      initial_length_size.
      If the DIE refers to a DWO file, this is always of the original die,
      not the DWO file.  */
-  sect_offset sect_off;
-  unsigned int length;
+  sect_offset sect_off {};
+  unsigned int length = 0;
 
   /* DWARF standard version this data has been read from (such as 4 or 5).  */
-  short dwarf_version;
+  short dwarf_version = 0;
 
   /* Flag indicating this compilation unit will be read in before
      any of the current compilation units are processed.  */
@@ -298,18 +303,22 @@ struct dwarf2_per_cu_data
      This flag is only valid if is_debug_types is true.  */
   unsigned int tu_read : 1;
 
+  /* Non-zero if this is actually a signatured_type, below.  This
+     allows for safe downcasting.  */
+  unsigned int is_sig_type : 1;
+
   /* The section this CU/TU lives in.
      If the DIE refers to a DWO file, this is always the original die,
      not the DWO file.  */
-  struct dwarf2_section_info *section;
+  struct dwarf2_section_info *section = nullptr;
 
   /* Set to non-NULL iff this CU is currently loaded.  When it gets freed out
      of the CU cache it gets reset to NULL again.  This is left as NULL for
      dummy CUs (a CU header, but nothing else).  */
-  struct dwarf2_cu *cu;
+  struct dwarf2_cu *cu = nullptr;
 
   /* The corresponding dwarf2_per_objfile.  */
-  struct dwarf2_per_objfile *dwarf2_per_objfile;
+  struct dwarf2_per_objfile *dwarf2_per_objfile = nullptr;
 
   /* When dwarf2_per_objfile->using_index is true, the 'quick' field
      is active.  Otherwise, the 'psymtab' field is active.  */
@@ -321,7 +330,7 @@ struct dwarf2_per_cu_data
 
     /* Data needed by the "quick" functions.  */
     struct dwarf2_per_cu_quick_data *quick;
-  } v;
+  } v {};
 
   /* The CUs we import using DW_TAG_imported_unit.  This is filled in
      while reading psymtabs, used to compute the psymtab dependencies,
@@ -341,13 +350,23 @@ struct dwarf2_per_cu_data
      to.  Concurrently with this change gdb was modified to emit version 8
      indices so we only pay a price for gold generated indices.
      http://sourceware.org/bugzilla/show_bug.cgi?id=15021.  */
-  VEC (dwarf2_per_cu_ptr) *imported_symtabs;
+  VEC (dwarf2_per_cu_ptr) *imported_symtabs = nullptr;
 };
 
 /* Entry in the signatured_types hash table.  */
 
 struct signatured_type
 {
+  signatured_type ()
+  {
+  }
+
+  ~signatured_type ()
+  {
+  }
+
+  DISABLE_COPY_AND_ASSIGN (signatured_type);
+
   /* The "per_cu" object of this type.
      This struct is used iff per_cu.is_debug_types.
      N.B.: This is the first member so that it's easy to convert pointers
@@ -355,32 +374,32 @@ struct signatured_type
   struct dwarf2_per_cu_data per_cu;
 
   /* The type's signature.  */
-  ULONGEST signature;
+  ULONGEST signature = 0;
 
   /* Offset in the TU of the type's DIE, as read from the TU header.
      If this TU is a DWO stub and the definition lives in a DWO file
      (specified by DW_AT_GNU_dwo_name), this value is unusable.  */
-  cu_offset type_offset_in_tu;
+  cu_offset type_offset_in_tu {};
 
   /* Offset in the section of the type's DIE.
      If the definition lives in a DWO file, this is the offset in the
      .debug_types.dwo section.
      The value is zero until the actual value is known.
      Zero is otherwise not a valid section offset.  */
-  sect_offset type_offset_in_section;
+  sect_offset type_offset_in_section {};
 
   /* Type units are grouped by their DW_AT_stmt_list entry so that they
      can share them.  This points to the containing symtab.  */
-  struct type_unit_group *type_unit_group;
+  struct type_unit_group *type_unit_group = nullptr;
 
   /* The type.
      The first time we encounter this type we fully read it in and install it
      in the symbol tables.  Subsequent times we only need the type.  */
-  struct type *type;
+  struct type *type = nullptr;
 
   /* Containing DWO unit.
      This field is valid iff per_cu.reading_dwo_directly.  */
-  struct dwo_unit *dwo_unit;
+  struct dwo_unit *dwo_unit = nullptr;
 };
 
 typedef struct signatured_type *sig_type_ptr;
-- 
2.13.6

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

* Re: [RFA 1/2] Allocate dwarf2_per_cu_data and signatured_type with new
  2018-05-20 23:34 ` [RFA 1/2] Allocate dwarf2_per_cu_data and signatured_type with new Tom Tromey
@ 2018-05-21  9:54   ` Simon Marchi
  0 siblings, 0 replies; 4+ messages in thread
From: Simon Marchi @ 2018-05-21  9:54 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 2018-05-19 04:37 PM, Tom Tromey wrote:
> This changes dwarf2_per_cu_data and signatured_type to be allocated
> with new, rather than on the obstack.  The main idea here is to move
> destructors into the objects that actually own the data, to make
> dwarf2read a bit simpler to understand, and to enable the next patch.
> 
> This particular change required one little hack to make "delete" work
> properly.  I did not think it would be good to add a virtual
> destructor to dwarf2_per_cu_data just for this.

Hi Tom,

It would only be useful to make the destructor of dwarf2_per_cu_data virtual
if other classes (such as signatured_type) inherited from it instead of
including it as their first data member.  But I think it would be preferrable
to do that (inheritance + virtual destructor) instead of hacking our way around
like this.

I have a patch in a branch that does that:
https://github.com/simark/binutils-gdb/commit/bbbd2c0b10b6e78965cdd70a157e7f475522009f

Though I would get rid of the allocation on the obstack like you did.  Do you think it
would be a good way to go?  Or does the extra space used by the vtable for each CU
worries you?

In any case, I pushed my obstack_new stuff, because I presumed there would be
some problem here.  This allocation in create_type_unit_group is problematic:

  tu_group = OBSTACK_ZALLOC (&objfile->objfile_obstack,
			     struct type_unit_group);

because type_unit_group includes a dwarf2_per_cu_data, which now needs to be
constructed.  That class would also need to be new'ed.

Thanks,

Simon

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

end of thread, other threads:[~2018-05-21  3:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-19 20:37 [RFA 0/2] Replace one use of VEC in dwarf2read.c Tom Tromey
2018-05-19 22:09 ` [RFA 2/2] Use std::vector for dwarf2_per_cu_data Tom Tromey
2018-05-20 23:34 ` [RFA 1/2] Allocate dwarf2_per_cu_data and signatured_type with new Tom Tromey
2018-05-21  9:54   ` 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).