public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] [gdb/symtab] Rename all_comp_units to all_units
@ 2022-09-18  8:10 Tom de Vries
  2022-09-18  8:10 ` [PATCH 2/2] [gdb/symtab] Add all_comp_units/all_type_units views on all_units Tom de Vries
  2022-09-18 21:49 ` [PATCH 1/2] [gdb/symtab] Rename all_comp_units to all_units Simon Marchi
  0 siblings, 2 replies; 3+ messages in thread
From: Tom de Vries @ 2022-09-18  8:10 UTC (permalink / raw)
  To: gdb-patches

Mechanically rename all_comp_units to all_units:
...
$ sed -i 's/all_comp_units/all_units/' gdb/dwarf2/*
...

Tested on x86_64-linux.
---
 gdb/dwarf2/index-write.c |  20 +++---
 gdb/dwarf2/read.c        | 150 +++++++++++++++++++--------------------
 gdb/dwarf2/read.h        |   4 +-
 3 files changed, 87 insertions(+), 87 deletions(-)

diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index b6d8dddafd3..09f14953bf8 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -1025,7 +1025,7 @@ class debug_names
 static bool
 check_dwarf64_offsets (dwarf2_per_objfile *per_objfile)
 {
-  for (const auto &per_cu : per_objfile->per_bfd->all_comp_units)
+  for (const auto &per_cu : per_objfile->per_bfd->all_units)
     {
       if (to_underlying (per_cu->sect_off)
 	  >= (static_cast<uint64_t> (1) << 32))
@@ -1176,28 +1176,28 @@ write_gdbindex (dwarf2_per_objfile *per_objfile,
      in the index file).  This will later be needed to write the address
      table.  */
   cu_index_map cu_index_htab;
-  cu_index_htab.reserve (per_objfile->per_bfd->all_comp_units.size ());
+  cu_index_htab.reserve (per_objfile->per_bfd->all_units.size ());
 
   /* Store out the .debug_type CUs, if any.  */
   data_buf types_cu_list;
 
   /* The CU list is already sorted, so we don't need to do additional
      work here.  Also, the debug_types entries do not appear in
-     all_comp_units, but only in their own hash table.  */
+     all_units, but only in their own hash table.  */
 
   int counter = 0;
   int types_counter = 0;
-  for (int i = 0; i < per_objfile->per_bfd->all_comp_units.size (); ++i)
+  for (int i = 0; i < per_objfile->per_bfd->all_units.size (); ++i)
     {
       dwarf2_per_cu_data *per_cu
-	= per_objfile->per_bfd->all_comp_units[i].get ();
+	= per_objfile->per_bfd->all_units[i].get ();
 
       int &this_counter = per_cu->is_debug_types ? types_counter : counter;
 
       const auto insertpair = cu_index_htab.emplace (per_cu, this_counter);
       gdb_assert (insertpair.second);
 
-      /* The all_comp_units list contains CUs read from the objfile as well as
+      /* The all_units list contains CUs read from the objfile as well as
 	 from the eventual dwz file.  We need to place the entry in the
 	 corresponding index.  */
       data_buf &cu_list = (per_cu->is_debug_types
@@ -1264,16 +1264,16 @@ write_debug_names (dwarf2_per_objfile *per_objfile,
 
   /* The CU list is already sorted, so we don't need to do additional
      work here.  Also, the debug_types entries do not appear in
-     all_comp_units, but only in their own hash table.  */
+     all_units, but only in their own hash table.  */
   data_buf cu_list;
   data_buf types_cu_list;
   debug_names nametable (per_objfile, dwarf5_is_dwarf64, dwarf5_byte_order);
   int counter = 0;
   int types_counter = 0;
-  for (int i = 0; i < per_objfile->per_bfd->all_comp_units.size (); ++i)
+  for (int i = 0; i < per_objfile->per_bfd->all_units.size (); ++i)
     {
       dwarf2_per_cu_data *per_cu
-	= per_objfile->per_bfd->all_comp_units[i].get ();
+	= per_objfile->per_bfd->all_units[i].get ();
 
       int &this_counter = per_cu->is_debug_types ? types_counter : counter;
       data_buf &this_list = per_cu->is_debug_types ? types_cu_list : cu_list;
@@ -1286,7 +1286,7 @@ write_debug_names (dwarf2_per_objfile *per_objfile,
     }
 
    /* Verify that all units are represented.  */
-  gdb_assert (counter == (per_objfile->per_bfd->all_comp_units.size ()
+  gdb_assert (counter == (per_objfile->per_bfd->all_units.size ()
 			  - per_objfile->per_bfd->tu_stats.nr_tus));
   gdb_assert (types_counter == per_objfile->per_bfd->tu_stats.nr_tus);
 
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index ceb14511f8b..024d901b520 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1201,7 +1201,7 @@ static void prepare_one_comp_unit (struct dwarf2_cu *cu,
 static struct type *set_die_type (struct die_info *, struct type *,
 				  struct dwarf2_cu *, bool = false);
 
-static void create_all_comp_units (dwarf2_per_objfile *per_objfile);
+static void create_all_units (dwarf2_per_objfile *per_objfile);
 
 static void load_full_comp_unit (dwarf2_per_cu_data *per_cu,
 				 dwarf2_per_objfile *per_objfile,
@@ -1384,21 +1384,21 @@ line_header_eq_voidp (const void *item_lhs, const void *item_rhs)
 
 \f
 
-/* An iterator for all_comp_units that is based on index.  This
-   approach makes it possible to iterate over all_comp_units safely,
+/* An iterator for all_units that is based on index.  This
+   approach makes it possible to iterate over all_units safely,
    when some caller in the loop may add new units.  */
 
-class all_comp_units_iterator
+class all_units_iterator
 {
 public:
 
-  all_comp_units_iterator (dwarf2_per_bfd *per_bfd, bool start)
+  all_units_iterator (dwarf2_per_bfd *per_bfd, bool start)
     : m_per_bfd (per_bfd),
-      m_index (start ? 0 : per_bfd->all_comp_units.size ())
+      m_index (start ? 0 : per_bfd->all_units.size ())
   {
   }
 
-  all_comp_units_iterator &operator++ ()
+  all_units_iterator &operator++ ()
   {
     ++m_index;
     return *this;
@@ -1409,13 +1409,13 @@ class all_comp_units_iterator
     return m_per_bfd->get_cu (m_index);
   }
 
-  bool operator== (const all_comp_units_iterator &other) const
+  bool operator== (const all_units_iterator &other) const
   {
     return m_index == other.m_index;
   }
 
 
-  bool operator!= (const all_comp_units_iterator &other) const
+  bool operator!= (const all_units_iterator &other) const
   {
     return m_index != other.m_index;
   }
@@ -1426,24 +1426,24 @@ class all_comp_units_iterator
   size_t m_index;
 };
 
-/* A range adapter for the all_comp_units_iterator.  */
-class all_comp_units_range
+/* A range adapter for the all_units_iterator.  */
+class all_units_range
 {
 public:
 
-  all_comp_units_range (dwarf2_per_bfd *per_bfd)
+  all_units_range (dwarf2_per_bfd *per_bfd)
     : m_per_bfd (per_bfd)
   {
   }
 
-  all_comp_units_iterator begin ()
+  all_units_iterator begin ()
   {
-    return all_comp_units_iterator (m_per_bfd, true);
+    return all_units_iterator (m_per_bfd, true);
   }
 
-  all_comp_units_iterator end ()
+  all_units_iterator end ()
   {
-    return all_comp_units_iterator (m_per_bfd, false);
+    return all_units_iterator (m_per_bfd, false);
   }
 
 private:
@@ -1467,7 +1467,7 @@ dwarf2_per_bfd::dwarf2_per_bfd (bfd *obfd, const dwarf2_debug_sections *names,
 
 dwarf2_per_bfd::~dwarf2_per_bfd ()
 {
-  for (auto &per_cu : all_comp_units)
+  for (auto &per_cu : all_units)
     {
       per_cu->imported_symtabs_free ();
       per_cu->free_cached_file_names ();
@@ -2096,7 +2096,7 @@ dwarf2_per_bfd::allocate_per_cu ()
 {
   dwarf2_per_cu_data_up result (new dwarf2_per_cu_data);
   result->per_bfd = this;
-  result->index = all_comp_units.size ();
+  result->index = all_units.size ();
   return result;
 }
 
@@ -2107,7 +2107,7 @@ dwarf2_per_bfd::allocate_signatured_type (ULONGEST signature)
 {
   signatured_type_up result (new signatured_type (signature));
   result->per_bfd = this;
-  result->index = all_comp_units.size ();
+  result->index = all_units.size ();
   result->is_debug_types = true;
   tu_stats.nr_tus++;
   return result;
@@ -2151,7 +2151,7 @@ create_cus_from_index_list (dwarf2_per_bfd *per_bfd,
       dwarf2_per_cu_data_up per_cu
 	= create_cu_from_index_list (per_bfd, section, is_dwz, sect_off,
 				     length);
-      per_bfd->all_comp_units.push_back (std::move (per_cu));
+      per_bfd->all_units.push_back (std::move (per_cu));
     }
 }
 
@@ -2163,8 +2163,8 @@ create_cus_from_index (dwarf2_per_bfd *per_bfd,
 		       const gdb_byte *cu_list, offset_type cu_list_elements,
 		       const gdb_byte *dwz_list, offset_type dwz_elements)
 {
-  gdb_assert (per_bfd->all_comp_units.empty ());
-  per_bfd->all_comp_units.reserve ((cu_list_elements + dwz_elements) / 2);
+  gdb_assert (per_bfd->all_units.empty ());
+  per_bfd->all_units.reserve ((cu_list_elements + dwz_elements) / 2);
 
   create_cus_from_index_list (per_bfd, cu_list, cu_list_elements,
 			      &per_bfd->info, 0);
@@ -2210,7 +2210,7 @@ create_signatured_type_table_from_index
       slot = htab_find_slot (sig_types_hash.get (), sig_type.get (), INSERT);
       *slot = sig_type.get ();
 
-      per_bfd->all_comp_units.emplace_back (sig_type.release ());
+      per_bfd->all_units.emplace_back (sig_type.release ());
     }
 
   per_bfd->signatured_types = std::move (sig_types_hash);
@@ -2258,7 +2258,7 @@ create_signatured_type_table_from_debug_names
       slot = htab_find_slot (sig_types_hash.get (), sig_type.get (), INSERT);
       *slot = sig_type.get ();
 
-      per_objfile->per_bfd->all_comp_units.emplace_back (sig_type.release ());
+      per_objfile->per_bfd->all_units.emplace_back (sig_type.release ());
     }
 
   per_objfile->per_bfd->signatured_types = std::move (sig_types_hash);
@@ -2301,7 +2301,7 @@ create_addrmap_from_index (dwarf2_per_objfile *per_objfile,
 	  continue;
 	}
 
-      if (cu_index >= per_bfd->all_comp_units.size ())
+      if (cu_index >= per_bfd->all_units.size ())
 	{
 	  complaint (_(".gdb_index address table has invalid CU number %u"),
 		     (unsigned) cu_index);
@@ -2336,7 +2336,7 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
 		     dwarf2_per_cu_data *,
 		     gdb::hash_enum<sect_offset>>
     debug_info_offset_to_per_cu;
-  for (const auto &per_cu : per_bfd->all_comp_units)
+  for (const auto &per_cu : per_bfd->all_units)
     {
       /* A TU will not need aranges, and skipping them here is an easy
 	 way of ignoring .debug_types -- and possibly seeing a
@@ -2349,7 +2349,7 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile,
 	= debug_info_offset_to_per_cu.emplace (per_cu->sect_off,
 					       per_cu.get ());
 
-      /* Assume no duplicate offsets in all_comp_units.  */
+      /* Assume no duplicate offsets in all_units.  */
       gdb_assert (insertpair.second);
     }
 
@@ -2709,7 +2709,7 @@ dwarf2_read_gdb_index
 	 index.  */
       if (per_bfd->types.size () > 1)
 	{
-	  per_bfd->all_comp_units.clear ();
+	  per_bfd->all_units.clear ();
 	  return 0;
 	}
 
@@ -2726,7 +2726,7 @@ dwarf2_read_gdb_index
 
   per_bfd->index_table = std::move (map);
   per_bfd->quick_file_names_table =
-    create_quick_file_names_table (per_bfd->all_comp_units.size ());
+    create_quick_file_names_table (per_bfd->all_units.size ());
 
   return 1;
 }
@@ -2881,7 +2881,7 @@ dwarf2_base_index_functions::find_last_source_symtab (struct objfile *objfile)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
   dwarf2_per_cu_data *dwarf_cu
-    = per_objfile->per_bfd->all_comp_units.back ().get ();
+    = per_objfile->per_bfd->all_units.back ().get ();
   compunit_symtab *cust = dw2_instantiate_symtab (dwarf_cu, per_objfile, false);
 
   if (cust == NULL)
@@ -2918,7 +2918,7 @@ dwarf2_base_index_functions::forget_cached_source_info
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
-  for (auto &per_cu : per_objfile->per_bfd->all_comp_units)
+  for (auto &per_cu : per_objfile->per_bfd->all_units)
     per_cu->free_cached_file_names ();
 }
 
@@ -2993,7 +2993,7 @@ dw2_symtab_iter_next (struct dw2_symtab_iterator *iter,
 			 && symbol_kind != GDB_INDEX_SYMBOL_KIND_NONE);
 
       /* Don't crash on bad data.  */
-      if (cu_index >= per_objfile->per_bfd->all_comp_units.size ())
+      if (cu_index >= per_objfile->per_bfd->all_units.size ())
 	{
 	  complaint (_(".gdb_index entry has bad CU index"
 		       " [in module %s]"), objfile_name (per_objfile->objfile));
@@ -3074,7 +3074,7 @@ dwarf2_base_index_functions::print_stats (struct objfile *objfile,
     return;
 
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
-  int total = per_objfile->per_bfd->all_comp_units.size ();
+  int total = per_objfile->per_bfd->all_units.size ();
   int count = 0;
 
   for (int i = 0; i < total; ++i)
@@ -3108,7 +3108,7 @@ void
 dwarf2_base_index_functions::expand_all_symtabs (struct objfile *objfile)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
-  int total_units = per_objfile->per_bfd->all_comp_units.size ();
+  int total_units = per_objfile->per_bfd->all_units.size ();
 
   for (int i = 0; i < total_units; ++i)
     {
@@ -4071,7 +4071,7 @@ dw2_expand_marked_cus
 	}
 
       /* Don't crash on bad data.  */
-      if (cu_index >= per_objfile->per_bfd->all_comp_units.size ())
+      if (cu_index >= per_objfile->per_bfd->all_units.size ())
 	{
 	  complaint (_(".gdb_index entry has bad CU index"
 		       " [in module %s]"), objfile_name (per_objfile->objfile));
@@ -4109,7 +4109,7 @@ dw_expand_symtabs_matching_file_matcher
   /* The rule is CUs specify all the files, including those used by
      any TU, so there's no need to scan TUs here.  */
 
-  for (const auto &per_cu : per_objfile->per_bfd->all_comp_units)
+  for (const auto &per_cu : per_objfile->per_bfd->all_units)
     {
       QUIT;
 
@@ -4208,7 +4208,7 @@ dwarf2_gdb_index::expand_symtabs_matching
   if (lookup_name == nullptr)
     {
       for (dwarf2_per_cu_data *per_cu
-	     : all_comp_units_range (per_objfile->per_bfd))
+	     : all_units_range (per_objfile->per_bfd))
 	{
 	  QUIT;
 
@@ -4326,7 +4326,7 @@ dwarf2_base_index_functions::map_symbol_filenames
      reuse the file names data from a currently unexpanded CU, in this
      case we don't want to report the files from the unexpanded CU.  */
 
-  for (const auto &per_cu : per_objfile->per_bfd->all_comp_units)
+  for (const auto &per_cu : per_objfile->per_bfd->all_units)
     {
       if (!per_cu->is_debug_types
 	  && per_objfile->symtab_set_p (per_cu.get ()))
@@ -4337,7 +4337,7 @@ dwarf2_base_index_functions::map_symbol_filenames
     }
 
   for (dwarf2_per_cu_data *per_cu
-	 : all_comp_units_range (per_objfile->per_bfd))
+	 : all_units_range (per_objfile->per_bfd))
     {
       /* We only need to look at symtabs not already expanded.  */
       if (per_cu->is_debug_types || per_objfile->symtab_set_p (per_cu))
@@ -4397,7 +4397,7 @@ dwarf2_base_index_functions::has_unexpanded_symtabs (struct objfile *objfile)
 {
   dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile);
 
-  for (const auto &per_cu : per_objfile->per_bfd->all_comp_units)
+  for (const auto &per_cu : per_objfile->per_bfd->all_units)
     {
       /* Is this already expanded?  */
       if (per_objfile->symtab_set_p (per_cu.get ()))
@@ -4625,7 +4625,7 @@ create_cus_from_debug_names_list (dwarf2_per_bfd *per_bfd,
 	  dwarf2_per_cu_data_up per_cu
 	    = create_cu_from_index_list (per_bfd, &section, is_dwz,
 					 sect_off, 0);
-	  per_bfd->all_comp_units.push_back (std::move (per_cu));
+	  per_bfd->all_units.push_back (std::move (per_cu));
 	}
       return true;
     }
@@ -4664,7 +4664,7 @@ create_cus_from_debug_names_list (dwarf2_per_bfd *per_bfd,
 	  dwarf2_per_cu_data_up per_cu
 	    = create_cu_from_index_list (per_bfd, &section, is_dwz,
 					 sect_off_prev, length);
-	  per_bfd->all_comp_units.push_back (std::move (per_cu));
+	  per_bfd->all_units.push_back (std::move (per_cu));
 	}
       sect_off_prev = sect_off_next;
     }
@@ -4680,8 +4680,8 @@ create_cus_from_debug_names (dwarf2_per_bfd *per_bfd,
 			     const mapped_debug_names &map,
 			     const mapped_debug_names &dwz_map)
 {
-  gdb_assert (per_bfd->all_comp_units.empty ());
-  per_bfd->all_comp_units.reserve (map.cu_count + dwz_map.cu_count);
+  gdb_assert (per_bfd->all_units.empty ());
+  per_bfd->all_units.reserve (map.cu_count + dwz_map.cu_count);
 
   if (!create_cus_from_debug_names_list (per_bfd, map, per_bfd->info,
 					 false /* is_dwz */))
@@ -4731,7 +4731,7 @@ dwarf2_read_debug_names (dwarf2_per_objfile *per_objfile)
 
   if (!create_cus_from_debug_names (per_bfd, *map, dwz_map))
     {
-      per_bfd->all_comp_units.clear ();
+      per_bfd->all_units.clear ();
       return false;
     }
 
@@ -4741,7 +4741,7 @@ dwarf2_read_debug_names (dwarf2_per_objfile *per_objfile)
 	 index.  */
       if (per_bfd->types.size () > 1)
 	{
-	  per_bfd->all_comp_units.clear ();
+	  per_bfd->all_units.clear ();
 	  return false;
 	}
 
@@ -4758,7 +4758,7 @@ dwarf2_read_debug_names (dwarf2_per_objfile *per_objfile)
 
   per_bfd->index_table = std::move (map);
   per_bfd->quick_file_names_table =
-    create_quick_file_names_table (per_bfd->all_comp_units.size ());
+    create_quick_file_names_table (per_bfd->all_units.size ());
 
   return true;
 }
@@ -5017,7 +5017,7 @@ dw2_debug_names_iterator::next ()
 	case DW_IDX_compile_unit:
 	  {
 	    /* Don't crash on bad data.  */
-	    int nr_cus = (per_bfd->all_comp_units.size ()
+	    int nr_cus = (per_bfd->all_units.size ()
 			  - per_bfd->tu_stats.nr_tus);
 	    if (ull >= nr_cus)
 	      {
@@ -5041,7 +5041,7 @@ dw2_debug_names_iterator::next ()
 	      continue;
 	    }
 	  {
-	    int nr_cus = (per_bfd->all_comp_units.size ()
+	    int nr_cus = (per_bfd->all_units.size ()
 			  - per_bfd->tu_stats.nr_tus);
 	    per_cu = per_bfd->get_cu (nr_cus + ull);
 	  }
@@ -5254,7 +5254,7 @@ dwarf2_debug_names_index::expand_symtabs_matching
   if (lookup_name == nullptr)
     {
       for (dwarf2_per_cu_data *per_cu
-	     : all_comp_units_range (per_objfile->per_bfd))
+	     : all_units_range (per_objfile->per_bfd))
 	{
 	  QUIT;
 
@@ -5365,9 +5365,9 @@ dwarf2_initialize_objfile (struct objfile *objfile)
     {
       dwarf_read_debug_printf ("readnow requested");
 
-      create_all_comp_units (per_objfile);
+      create_all_units (per_objfile);
       per_bfd->quick_file_names_table
-	= create_quick_file_names_table (per_bfd->all_comp_units.size ());
+	= create_quick_file_names_table (per_bfd->all_units.size ());
 
       objfile->qf.emplace_front (new readnow_functions);
       return;
@@ -5662,15 +5662,15 @@ create_debug_types_hash_table (dwarf2_per_objfile *per_objfile,
 static struct signatured_type *
 add_type_unit (dwarf2_per_objfile *per_objfile, ULONGEST sig, void **slot)
 {
-  if (per_objfile->per_bfd->all_comp_units.size ()
-      == per_objfile->per_bfd->all_comp_units.capacity ())
+  if (per_objfile->per_bfd->all_units.size ()
+      == per_objfile->per_bfd->all_units.capacity ())
     ++per_objfile->per_bfd->tu_stats.nr_all_type_units_reallocs;
 
   signatured_type_up sig_type_holder
     = per_objfile->per_bfd->allocate_signatured_type (sig);
   signatured_type *sig_type = sig_type_holder.get ();
 
-  per_objfile->per_bfd->all_comp_units.emplace_back
+  per_objfile->per_bfd->all_units.emplace_back
     (sig_type_holder.release ());
 
   if (slot == NULL)
@@ -6942,12 +6942,12 @@ build_type_psymtabs (dwarf2_per_objfile *per_objfile,
 
   dwarf_read_debug_printf ("Building type unit groups ...");
 
-  /* Sort in a separate table to maintain the order of all_comp_units
+  /* Sort in a separate table to maintain the order of all_units
      for .gdb_index: TU indices directly index all_type_units.  */
   std::vector<tu_abbrev_offset> sorted_by_abbrev;
   sorted_by_abbrev.reserve (per_objfile->per_bfd->tu_stats.nr_tus);
 
-  for (const auto &cu : per_objfile->per_bfd->all_comp_units)
+  for (const auto &cu : per_objfile->per_bfd->all_units)
     {
       if (cu->is_debug_types)
 	{
@@ -7032,7 +7032,7 @@ process_skeletonless_type_unit (void **slot, void *info)
   if (*slot != NULL)
     return 1;
 
-  /* This does the job that create_all_comp_units would have done for
+  /* This does the job that create_all_units would have done for
      this TU.  */
   signatured_type *entry
     = add_type_unit (data->per_objfile, dwo_unit->signature, slot);
@@ -7096,12 +7096,12 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile)
   per_bfd->map_info_sections (objfile);
 
   cooked_index_storage index_storage;
-  create_all_comp_units (per_objfile);
+  create_all_units (per_objfile);
   build_type_psymtabs (per_objfile, &index_storage);
   std::vector<std::unique_ptr<cooked_index>> indexes;
 
   per_bfd->quick_file_names_table
-    = create_quick_file_names_table (per_bfd->all_comp_units.size ());
+    = create_quick_file_names_table (per_bfd->all_units.size ());
   if (!per_bfd->debug_aranges.empty ())
     read_addrmap_from_aranges (per_objfile, &per_bfd->debug_aranges,
 			       index_storage.get_addrmap ());
@@ -7110,7 +7110,7 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile)
     /* Ensure that complaints are handled correctly.  */
     complaint_interceptor complaint_handler;
 
-    using iter_type = decltype (per_bfd->all_comp_units.begin ());
+    using iter_type = decltype (per_bfd->all_units.begin ());
 
     auto task_size_ = [] (iter_type iter)
       {
@@ -7127,8 +7127,8 @@ dwarf2_build_psymtabs_hard (dwarf2_per_objfile *per_objfile)
     using result_type = std::pair<std::unique_ptr<cooked_index>,
 				  std::vector<gdb_exception>>;
     std::vector<result_type> results
-      = gdb::parallel_for_each (1, per_bfd->all_comp_units.begin (),
-				per_bfd->all_comp_units.end (),
+      = gdb::parallel_for_each (1, per_bfd->all_units.begin (),
+				per_bfd->all_units.end (),
 				[=] (iter_type iter, iter_type end)
       {
 	std::vector<gdb_exception> errors;
@@ -7255,7 +7255,7 @@ read_comp_units_from_section (dwarf2_per_objfile *per_objfile,
       this_cu->set_version (cu_header.version);
 
       info_ptr = info_ptr + this_cu->length ();
-      per_objfile->per_bfd->all_comp_units.push_back (std::move (this_cu));
+      per_objfile->per_bfd->all_units.push_back (std::move (this_cu));
     }
 }
 
@@ -7263,10 +7263,10 @@ read_comp_units_from_section (dwarf2_per_objfile *per_objfile,
    This is only done for -readnow and building partial symtabs.  */
 
 static void
-create_all_comp_units (dwarf2_per_objfile *per_objfile)
+create_all_units (dwarf2_per_objfile *per_objfile)
 {
   htab_up types_htab;
-  gdb_assert (per_objfile->per_bfd->all_comp_units.empty ());
+  gdb_assert (per_objfile->per_bfd->all_units.empty ());
 
   read_comp_units_from_section (per_objfile, &per_objfile->per_bfd->info,
 				&per_objfile->per_bfd->abbrev, 0,
@@ -18649,7 +18649,7 @@ cooked_index_functions::expand_symtabs_matching
   if (lookup_name == nullptr)
     {
       for (dwarf2_per_cu_data *per_cu
-	     : all_comp_units_range (per_objfile->per_bfd))
+	     : all_units_range (per_objfile->per_bfd))
 	{
 	  QUIT;
 
@@ -23542,18 +23542,18 @@ static int
 dwarf2_find_containing_comp_unit
   (sect_offset sect_off,
    unsigned int offset_in_dwz,
-   const std::vector<dwarf2_per_cu_data_up> &all_comp_units)
+   const std::vector<dwarf2_per_cu_data_up> &all_units)
 {
   int low, high;
 
   low = 0;
-  high = all_comp_units.size () - 1;
+  high = all_units.size () - 1;
   while (high > low)
     {
       struct dwarf2_per_cu_data *mid_cu;
       int mid = low + (high - low) / 2;
 
-      mid_cu = all_comp_units[mid].get ();
+      mid_cu = all_units[mid].get ();
       if (mid_cu->is_dwz > offset_in_dwz
 	  || (mid_cu->is_dwz == offset_in_dwz
 	      && mid_cu->sect_off + mid_cu->length () > sect_off))
@@ -23574,8 +23574,8 @@ dwarf2_find_containing_comp_unit (sect_offset sect_off,
 				  dwarf2_per_bfd *per_bfd)
 {
   int low = dwarf2_find_containing_comp_unit
-    (sect_off, offset_in_dwz, per_bfd->all_comp_units);
-  dwarf2_per_cu_data *this_cu = per_bfd->all_comp_units[low].get ();
+    (sect_off, offset_in_dwz, per_bfd->all_units);
+  dwarf2_per_cu_data *this_cu = per_bfd->all_units[low].get ();
 
   if (this_cu->is_dwz != offset_in_dwz || this_cu->sect_off > sect_off)
     {
@@ -23585,13 +23585,13 @@ dwarf2_find_containing_comp_unit (sect_offset sect_off,
 	       sect_offset_str (sect_off),
 	       bfd_get_filename (per_bfd->obfd));
 
-      gdb_assert (per_bfd->all_comp_units[low-1]->sect_off
+      gdb_assert (per_bfd->all_units[low-1]->sect_off
 		  <= sect_off);
-      return per_bfd->all_comp_units[low - 1].get ();
+      return per_bfd->all_units[low - 1].get ();
     }
   else
     {
-      if (low == per_bfd->all_comp_units.size () - 1
+      if (low == per_bfd->all_units.size () - 1
 	  && sect_off >= this_cu->sect_off + this_cu->length ())
 	error (_("invalid dwarf2 offset %s"), sect_offset_str (sect_off));
       gdb_assert (sect_off < this_cu->sect_off + this_cu->length ());
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index c2f86a9d367..ce4fe52f4a2 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -433,7 +433,7 @@ struct dwarf2_per_bfd
   /* Return the CU given its index.  */
   dwarf2_per_cu_data *get_cu (int index) const
   {
-    return this->all_comp_units[index].get ();
+    return this->all_units[index].get ();
   }
 
   /* A convenience function to allocate a dwarf2_per_cu_data.  The
@@ -489,7 +489,7 @@ struct dwarf2_per_bfd
 
   /* Table of all the compilation units.  This is used to locate
      the target compilation unit of a particular reference.  */
-  std::vector<dwarf2_per_cu_data_up> all_comp_units;
+  std::vector<dwarf2_per_cu_data_up> all_units;
 
   /* Table of struct type_unit_group objects.
      The hash key is the DW_AT_stmt_list value.  */

base-commit: 4e38ed582cb9a2e09141126c2e0a527816e702e6
-- 
2.35.3


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

* [PATCH 2/2] [gdb/symtab] Add all_comp_units/all_type_units views on all_units
  2022-09-18  8:10 [PATCH 1/2] [gdb/symtab] Rename all_comp_units to all_units Tom de Vries
@ 2022-09-18  8:10 ` Tom de Vries
  2022-09-18 21:49 ` [PATCH 1/2] [gdb/symtab] Rename all_comp_units to all_units Simon Marchi
  1 sibling, 0 replies; 3+ messages in thread
From: Tom de Vries @ 2022-09-18  8:10 UTC (permalink / raw)
  To: gdb-patches

Add all_comp_units/all_type_units views on all_units.

Having the views allows us to:
- easily get the number of CUs or TUs in all_units, and
- easily access the nth CU or TU.

This minimizes the use of tu_stats.nr_tus.

Tested on x86_64-linux.
---
 gdb/dwarf2/index-write.c |  5 ++---
 gdb/dwarf2/read.c        | 33 +++++++++++++++++++++++++--------
 gdb/dwarf2/read.h        |  5 +++++
 3 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index 09f14953bf8..4cc0ee53070 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -1286,9 +1286,8 @@ write_debug_names (dwarf2_per_objfile *per_objfile,
     }
 
    /* Verify that all units are represented.  */
-  gdb_assert (counter == (per_objfile->per_bfd->all_units.size ()
-			  - per_objfile->per_bfd->tu_stats.nr_tus));
-  gdb_assert (types_counter == per_objfile->per_bfd->tu_stats.nr_tus);
+  gdb_assert (counter == per_objfile->per_bfd->all_comp_units.size ());
+  gdb_assert (types_counter == per_objfile->per_bfd->all_type_units.size ());
 
   for (const cooked_index_entry *entry : table->all_entries ())
     nametable.insert (entry);
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 024d901b520..a3693050d46 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2631,6 +2631,8 @@ to use the section anyway."),
   return 1;
 }
 
+static void finalize_all_units (dwarf2_per_bfd *per_bfd);
+
 /* Callback types for dwarf2_read_gdb_index.  */
 
 typedef gdb::function_view
@@ -2722,6 +2724,8 @@ dwarf2_read_gdb_index
 					       types_list_elements);
     }
 
+  finalize_all_units (per_bfd);
+
   create_addrmap_from_index (per_objfile, map.get ());
 
   per_bfd->index_table = std::move (map);
@@ -4754,6 +4758,8 @@ dwarf2_read_debug_names (dwarf2_per_objfile *per_objfile)
 	(per_objfile, *map, section, &per_bfd->abbrev);
     }
 
+  finalize_all_units (per_bfd);
+
   create_addrmap_from_aranges (per_objfile, &per_bfd->debug_aranges);
 
   per_bfd->index_table = std::move (map);
@@ -5017,9 +5023,7 @@ dw2_debug_names_iterator::next ()
 	case DW_IDX_compile_unit:
 	  {
 	    /* Don't crash on bad data.  */
-	    int nr_cus = (per_bfd->all_units.size ()
-			  - per_bfd->tu_stats.nr_tus);
-	    if (ull >= nr_cus)
+	    if (ull >= per_bfd->all_comp_units.size ())
 	      {
 		complaint (_(".debug_names entry has bad CU index %s"
 			     " [in module %s]"),
@@ -5032,7 +5036,7 @@ dw2_debug_names_iterator::next ()
 	  break;
 	case DW_IDX_type_unit:
 	  /* Don't crash on bad data.  */
-	  if (ull >= per_bfd->tu_stats.nr_tus)
+	  if (ull >= per_bfd->all_type_units.size ())
 	    {
 	      complaint (_(".debug_names entry has bad TU index %s"
 			   " [in module %s]"),
@@ -5041,8 +5045,7 @@ dw2_debug_names_iterator::next ()
 	      continue;
 	    }
 	  {
-	    int nr_cus = (per_bfd->all_units.size ()
-			  - per_bfd->tu_stats.nr_tus);
+	    int nr_cus = per_bfd->all_comp_units.size ();
 	    per_cu = per_bfd->get_cu (nr_cus + ull);
 	  }
 	  break;
@@ -6918,7 +6921,7 @@ build_type_psymtabs (dwarf2_per_objfile *per_objfile,
   /* It's up to the caller to not call us multiple times.  */
   gdb_assert (per_objfile->per_bfd->type_unit_groups == NULL);
 
-  if (per_objfile->per_bfd->tu_stats.nr_tus == 0)
+  if (per_objfile->per_bfd->all_type_units.size () == 0)
     return;
 
   /* TUs typically share abbrev tables, and there can be way more TUs than
@@ -6945,7 +6948,7 @@ build_type_psymtabs (dwarf2_per_objfile *per_objfile,
   /* Sort in a separate table to maintain the order of all_units
      for .gdb_index: TU indices directly index all_type_units.  */
   std::vector<tu_abbrev_offset> sorted_by_abbrev;
-  sorted_by_abbrev.reserve (per_objfile->per_bfd->tu_stats.nr_tus);
+  sorted_by_abbrev.reserve (per_objfile->per_bfd->all_type_units.size ());
 
   for (const auto &cu : per_objfile->per_bfd->all_units)
     {
@@ -7259,6 +7262,18 @@ read_comp_units_from_section (dwarf2_per_objfile *per_objfile,
     }
 }
 
+/* Initialize the views on all_units.  */
+
+static void
+finalize_all_units (dwarf2_per_bfd *per_bfd)
+{
+  size_t nr_tus = per_bfd->tu_stats.nr_tus;
+  size_t nr_cus = per_bfd->all_units.size () - nr_tus;
+  gdb::array_view<dwarf2_per_cu_data_up> tmp = per_bfd->all_units;
+  per_bfd->all_comp_units = tmp.slice (0, nr_cus);
+  per_bfd->all_type_units = tmp.slice (nr_cus, nr_tus);
+}
+
 /* Create a list of all compilation units in OBJFILE.
    This is only done for -readnow and building partial symtabs.  */
 
@@ -7290,6 +7305,8 @@ create_all_units (dwarf2_per_objfile *per_objfile)
     }
 
   per_objfile->per_bfd->signatured_types = std::move (types_htab);
+
+  finalize_all_units (per_objfile->per_bfd);
 }
 
 /* Return the initial uleb128 in the die at INFO_PTR.  */
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index ce4fe52f4a2..5f01fbc1025 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -491,6 +491,11 @@ struct dwarf2_per_bfd
      the target compilation unit of a particular reference.  */
   std::vector<dwarf2_per_cu_data_up> all_units;
 
+  /* The all_units vector contains both CUs and TUs.  Provide views on the
+     vector that are limited to either the CU part or the TU part.  */
+  gdb::array_view<dwarf2_per_cu_data_up> all_comp_units;
+  gdb::array_view<dwarf2_per_cu_data_up> all_type_units;
+
   /* Table of struct type_unit_group objects.
      The hash key is the DW_AT_stmt_list value.  */
   htab_up type_unit_groups;
-- 
2.35.3


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

* Re: [PATCH 1/2] [gdb/symtab] Rename all_comp_units to all_units
  2022-09-18  8:10 [PATCH 1/2] [gdb/symtab] Rename all_comp_units to all_units Tom de Vries
  2022-09-18  8:10 ` [PATCH 2/2] [gdb/symtab] Add all_comp_units/all_type_units views on all_units Tom de Vries
@ 2022-09-18 21:49 ` Simon Marchi
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2022-09-18 21:49 UTC (permalink / raw)
  To: Tom de Vries, gdb-patches

> @@ -1201,7 +1201,7 @@ static void prepare_one_comp_unit (struct dwarf2_cu *cu,
>  static struct type *set_die_type (struct die_info *, struct type *,
>  				  struct dwarf2_cu *, bool = false);
>  
> -static void create_all_comp_units (dwarf2_per_objfile *per_objfile);
> +static void create_all_units (dwarf2_per_objfile *per_objfile);

I don't know if you intended to rename this, or it just caught up in the
sed.  It's not necessarily wrong to rename it, given that under it we
create comp units and type units.  More functions could be renamed the
same way (from comp_unit to unit), and dwarf2_per_cu_data also, while at
it, since it represents more than just CUs.  But that's really some
feature creep over what you intended to do in the beginning, so I would
suggest just sticking to renaming the all_comp_units vector for now.

> diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
> index c2f86a9d367..ce4fe52f4a2 100644
> --- a/gdb/dwarf2/read.h
> +++ b/gdb/dwarf2/read.h
> @@ -433,7 +433,7 @@ struct dwarf2_per_bfd
>    /* Return the CU given its index.  */
>    dwarf2_per_cu_data *get_cu (int index) const
>    {
> -    return this->all_comp_units[index].get ();
> +    return this->all_units[index].get ();

This makes me realize that this method (dwarf2_per_bfd::get_cu) should
probably be renamed get_unit, since it allows to fetch comp units as
well as type units (not in this patch though).

Simon


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

end of thread, other threads:[~2022-09-18 21:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-18  8:10 [PATCH 1/2] [gdb/symtab] Rename all_comp_units to all_units Tom de Vries
2022-09-18  8:10 ` [PATCH 2/2] [gdb/symtab] Add all_comp_units/all_type_units views on all_units Tom de Vries
2022-09-18 21:49 ` [PATCH 1/2] [gdb/symtab] Rename all_comp_units to all_units 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).