Simplify debug_names index writing
authorTom Tromey <tom@tromey.com>
Sat, 29 May 2021 13:25:57 +0000 (07:25 -0600)
committerTom Tromey <tom@tromey.com>
Mon, 5 Jul 2021 18:24:00 +0000 (12:24 -0600)
This changes the .debug_names writer to find the TU indices in the
main loop over all CUs and TUs.  (An earlier patch applied this same
treatment to the .gdb_index writer.)

gdb/dwarf2/index-write.c

index 0eb43c3f907b4f7d410dc5bc629ba64997a28aed..4e00c716d910a5e501aac78c86ce66b2bfa23f43 100644 (file)
@@ -586,21 +586,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.  */
 
@@ -903,32 +888,6 @@ public:
     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
@@ -1211,25 +1170,6 @@ private:
       }
   }
 
-  /* 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;
@@ -1476,17 +1416,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
@@ -1495,29 +1434,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 ();