[4/4] Simplify debug_names index writing

Message ID 20210529135443.1446279-5-tom@tromey.com
State New
Headers show
Series
  • Some small debug index writer cleanups
Related show

Commit Message

Tom Tromey May 29, 2021, 1:54 p.m.
Like the previous patch, this changes the .debug_names writer to find
the TU indices in the main loop over all CUs and TUs.

2021-05-29  Tom Tromey  <tom@tromey.com>

	* dwarf2/index-write.c (struct signatured_type_index_data):
	Remove.
	(debug_names::write_one_signatured_type_data)
	(debug_names::write_one_signatured_type): Remove.
	(write_debug_names): Write type CUs in loop.
---
 gdb/ChangeLog            |  8 ++++
 gdb/dwarf2/index-write.c | 93 +++++-----------------------------------
 2 files changed, 18 insertions(+), 83 deletions(-)

-- 
2.26.3

Patch

diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index 06c8e1026f0..6e593310d28 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -585,21 +585,6 @@  write_psymbols (struct mapped_symtab *symtab,
     }
 }
 
-/* A helper struct used when iterating over debug_types.  */
-struct signatured_type_index_data
-{
-  signatured_type_index_data (data_buf &types_list_,
-			      std::unordered_set<partial_symbol *> &psyms_seen_)
-    : types_list (types_list_), psyms_seen (psyms_seen_)
-  {}
-
-  struct objfile *objfile;
-  struct mapped_symtab *symtab;
-  data_buf &types_list;
-  std::unordered_set<partial_symbol *> &psyms_seen;
-  int cu_index;
-};
-
 /* Recurse into all "included" dependencies and count their symbols as
    if they appeared in this psymtab.  */
 
@@ -902,32 +887,6 @@  class debug_names
     m_debugstrlookup.file_write (file_str);
   }
 
-  /* A helper user data for write_one_signatured_type.  */
-  class write_one_signatured_type_data
-  {
-  public:
-    write_one_signatured_type_data (debug_names &nametable_,
-				    signatured_type_index_data &&info_)
-    : nametable (nametable_), info (std::move (info_))
-    {}
-    debug_names &nametable;
-    struct signatured_type_index_data info;
-  };
-
-  /* A helper function to pass write_one_signatured_type to
-     htab_traverse_noresize.  */
-  static int
-  write_one_signatured_type (void **slot, void *d)
-  {
-    write_one_signatured_type_data *data = (write_one_signatured_type_data *) d;
-    struct signatured_type_index_data *info = &data->info;
-    struct signatured_type *entry = (struct signatured_type *) *slot;
-
-    data->nametable.write_one_signatured_type (entry, info);
-
-    return 1;
-  }
-
 private:
 
   /* Storage for symbol names mapping them to their .debug_str section
@@ -1210,25 +1169,6 @@  class debug_names
       }
   }
 
-  /* A helper function that writes a single signatured_type
-     to a debug_names.  */
-  void
-  write_one_signatured_type (struct signatured_type *entry,
-			     struct signatured_type_index_data *info)
-  {
-    partial_symtab *psymtab = entry->v.psymtab;
-
-    write_psymbols (info->psyms_seen, psymtab->global_psymbols,
-		    info->cu_index, false, unit_kind::tu);
-    write_psymbols (info->psyms_seen, psymtab->static_psymbols,
-		    info->cu_index, true, unit_kind::tu);
-
-    info->types_list.append_uint (dwarf5_offset_size (), m_dwarf5_byte_order,
-				  to_underlying (entry->sect_off));
-
-    ++info->cu_index;
-  }
-
   /* Store value of each symbol.  */
   std::unordered_map<c_str_view, std::set<symbol_value>, c_str_view_hasher>
     m_name_to_value_set;
@@ -1475,17 +1415,16 @@  write_debug_names (dwarf2_per_objfile *per_objfile,
      work here.  Also, the debug_types entries do not appear in
      all_comp_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);
   std::unordered_set<partial_symbol *>
     psyms_seen (psyms_seen_size (per_objfile));
   int counter = 0;
+  int types_counter = 0;
   for (int i = 0; i < per_objfile->per_bfd->all_comp_units.size (); ++i)
     {
       const dwarf2_per_cu_data *per_cu
 	= per_objfile->per_bfd->all_comp_units[i].get ();
-      if (per_cu->is_debug_types)
-	continue;
-
       partial_symtab *psymtab = per_cu->v.psymtab;
 
       /* CU of a shared file from 'dwz -m' may be unused by this main
@@ -1494,29 +1433,17 @@  write_debug_names (dwarf2_per_objfile *per_objfile,
       if (psymtab == NULL)
 	continue;
 
+      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;
+
       if (psymtab->user == NULL)
 	nametable.recursively_write_psymbols (objfile, psymtab, psyms_seen,
-					      counter);
-
-      cu_list.append_uint (nametable.dwarf5_offset_size (), dwarf5_byte_order,
-			   to_underlying (per_cu->sect_off));
-      ++counter;
-    }
+					      this_counter);
 
-  /* Write out the .debug_type entries, if any.  */
-  data_buf types_cu_list;
-  if (per_objfile->per_bfd->signatured_types)
-    {
-      debug_names::write_one_signatured_type_data sig_data (nametable,
-			signatured_type_index_data (types_cu_list, psyms_seen));
-
-      sig_data.info.objfile = objfile;
-      /* It is used only for gdb_index.  */
-      sig_data.info.symtab = nullptr;
-      sig_data.info.cu_index = 0;
-      htab_traverse_noresize (per_objfile->per_bfd->signatured_types.get (),
-			      debug_names::write_one_signatured_type,
-			      &sig_data);
+      this_list.append_uint (nametable.dwarf5_offset_size (),
+			     dwarf5_byte_order,
+			     to_underlying (per_cu->sect_off));
+      ++this_counter;
     }
 
   nametable.build ();