]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Convert dwarf_cu::die_hash to new hash table
authorSimon Marchi <simon.marchi@polymtl.ca>
Mon, 4 Nov 2024 18:27:54 +0000 (13:27 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Tue, 26 Nov 2024 03:07:04 +0000 (22:07 -0500)
Convert one use of htab_t, mapping offsets to die_info object, to
`gdb::unordered_set`.

Change-Id: Ic80df22bda551e2d4c2511d167e057f4d6cd2b3e
Approved-By: Tom Tromey <tom@tromey.com>
gdb/dwarf2/cu.h
gdb/dwarf2/die.c
gdb/dwarf2/die.h
gdb/dwarf2/read.c

index ea8e14770bd2cf11fa13197585dc0b7203ba08f2..23b06dc1fb68b4f1033413b939594691cf62e1ab 100644 (file)
@@ -25,6 +25,7 @@
 #include <optional>
 #include "language.h"
 #include "gdbsupport/unordered_set.h"
+#include "dwarf2/die.h"
 
 /* Type used for delaying computation of method physnames.
    See comments for compute_delayed_physnames.  */
@@ -153,7 +154,9 @@ public:
 
   /* A hash table of DIE cu_offset for following references with
      die_info->offset.sect_off as hash.  */
-  htab_up die_hash;
+  using die_hash_t = gdb::unordered_set<die_info *, die_info_hash_sect_off,
+                                       die_info_eq_sect_off>;
+  die_hash_t die_hash;
 
   /* Full DIEs if read in.  */
   struct die_info *dies = nullptr;
index bfa54e517abbadc02c27ad0baa35db59ca971164..500d7bfe08184fcd5623a18e914d3ca6392a3d04 100644 (file)
@@ -35,27 +35,6 @@ die_info::allocate (struct obstack *obstack, int num_attrs)
   return die;
 }
 
-/* See die.h.  */
-
-hashval_t
-die_info::hash (const void *item)
-{
-  const struct die_info *die = (const struct die_info *) item;
-
-  return to_underlying (die->sect_off);
-}
-
-/* See die.h.  */
-
-int
-die_info::eq (const void *item_lhs, const void *item_rhs)
-{
-  const struct die_info *die_lhs = (const struct die_info *) item_lhs;
-  const struct die_info *die_rhs = (const struct die_info *) item_rhs;
-
-  return die_lhs->sect_off == die_rhs->sect_off;
-}
-
 static void
 dump_die_shallow (struct ui_file *f, int indent, struct die_info *die)
 {
index d4eab0838bfe6aaf398f0157789c0e6604570041..770964eb9a83a33237cae6daa595c25380d697ca 100644 (file)
@@ -22,7 +22,6 @@
 
 #include "complaints.h"
 #include "dwarf2/attribute.h"
-#include "hashtab.h"
 
 /* This data structure holds a complete die structure.  */
 struct die_info
@@ -31,14 +30,6 @@ struct die_info
      attributes that are needed.  */
   static die_info *allocate (struct obstack *obstack, int num_attrs);
 
-  /* Trivial hash function for die_info: the hash value of a DIE is
-     its offset in .debug_info for this objfile.  */
-  static hashval_t hash (const void *item);
-
-  /* Trivial comparison function for die_info structures: two DIEs
-     are equal if they have the same offset.  */
-  static int eq (const void *item_lhs, const void *item_rhs);
-
   /* Dump this DIE and any children to MAX_LEVEL.  They are written to
      gdb_stdlog.  Note this is called from the pdie user command in
      gdb-gdb.gdb.  */
@@ -148,4 +139,32 @@ struct die_info
   struct attribute attrs[1];
 };
 
+/* Key hash type to store die_info objects in gdb::unordered_set, identified by
+   their section offsets.  */
+
+struct die_info_hash_sect_off final
+{
+  using is_transparent = void;
+
+  std::size_t operator() (const die_info *die) const noexcept
+  { return (*this) (die->sect_off); }
+
+  std::size_t operator() (sect_offset offset) const noexcept
+  { return std::hash<sect_offset> () (offset); }
+};
+
+/* Key equal type to store die_info objects in gdb::unordered_set, identified by
+   their section offsets.  */
+
+struct die_info_eq_sect_off final
+{
+  using is_transparent = void;
+
+  bool operator() (const die_info *a, const die_info *b) const noexcept
+  { return (*this) (a->sect_off, b); }
+
+  bool operator() (sect_offset offset, const die_info *die) const noexcept
+  { return offset == die->sect_off; }
+};
+
 #endif /* GDB_DWARF2_DIE_H */
index 8d5dedd2f6236beba65fc4ce1862ee5ddeb24843..b20d3cd5f304b0fd4048cc640418fa5e41b1a7ea 100644 (file)
@@ -5572,11 +5572,8 @@ load_full_comp_unit (dwarf2_per_cu_data *this_cu,
   struct dwarf2_cu *cu = reader.cu;
   const gdb_byte *info_ptr = reader.info_ptr;
 
-  gdb_assert (cu->die_hash == NULL);
-  cu->die_hash.reset (htab_create_alloc
-                     (cu->header.get_length_without_initial () / 12,
-                      die_info::hash, die_info::eq,
-                      nullptr, xcalloc, xfree));
+  gdb_assert (cu->die_hash.empty ());
+  cu->die_hash.reserve (cu->header.get_length_without_initial () / 12);
 
   if (reader.comp_unit_die->has_children)
     reader.comp_unit_die->child
@@ -15967,10 +15964,8 @@ read_die_and_children (const struct die_reader_specs *reader,
       return NULL;
     }
 
-  void **slot = htab_find_slot_with_hash (reader->cu->die_hash.get (), die,
-                                         to_underlying (die->sect_off),
-                                         INSERT);
-  *slot = die;
+  bool inserted = reader->cu->die_hash.emplace (die).second;
+  gdb_assert (inserted);
 
   if (die->has_children)
     die->child = read_die_and_siblings_1 (reader, cur_ptr, new_info_ptr, die);
@@ -20587,7 +20582,6 @@ static struct die_info *
 follow_die_offset (sect_offset sect_off, int offset_in_dwz,
                   struct dwarf2_cu **ref_cu)
 {
-  struct die_info temp_die;
   struct dwarf2_cu *target_cu, *cu = *ref_cu;
   dwarf2_per_objfile *per_objfile = cu->per_objfile;
 
@@ -20648,11 +20642,9 @@ follow_die_offset (sect_offset sect_off, int offset_in_dwz,
     }
 
   *ref_cu = target_cu;
-  temp_die.sect_off = sect_off;
 
-  return (struct die_info *) htab_find_with_hash (target_cu->die_hash.get (),
-                                                 &temp_die,
-                                                 to_underlying (sect_off));
+  auto it = target_cu->die_hash.find (sect_off);
+  return it != target_cu->die_hash.end () ? *it : nullptr;
 }
 
 /* Follow reference attribute ATTR of SRC_DIE.
@@ -21011,9 +21003,7 @@ static struct die_info *
 follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type,
                  struct dwarf2_cu **ref_cu)
 {
-  struct die_info temp_die;
   struct dwarf2_cu *sig_cu;
-  struct die_info *die;
   dwarf2_per_objfile *per_objfile = (*ref_cu)->per_objfile;
 
 
@@ -21034,11 +21024,9 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type,
   sig_cu = per_objfile->get_cu (sig_type);
   gdb_assert (sig_cu != NULL);
   gdb_assert (to_underlying (sig_type->type_offset_in_section) != 0);
-  temp_die.sect_off = sig_type->type_offset_in_section;
-  die = (struct die_info *) htab_find_with_hash (sig_cu->die_hash.get (),
-                                                &temp_die,
-                                                to_underlying (temp_die.sect_off));
-  if (die)
+
+  if (auto die_it = sig_cu->die_hash.find (sig_type->type_offset_in_section);
+      die_it != sig_cu->die_hash.end ())
     {
       /* For .gdb_index version 7 keep track of included TUs.
         http://sourceware.org/bugzilla/show_bug.cgi?id=15021.  */
@@ -21047,7 +21035,7 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type,
        (*ref_cu)->per_cu->imported_symtabs.push_back (sig_cu->per_cu);
 
       *ref_cu = sig_cu;
-      return die;
+      return *die_it;
     }
 
   return NULL;
@@ -21229,11 +21217,8 @@ read_signatured_type (signatured_type *sig_type,
       struct dwarf2_cu *cu = reader.cu;
       const gdb_byte *info_ptr = reader.info_ptr;
 
-      gdb_assert (cu->die_hash == NULL);
-      cu->die_hash.reset (htab_create_alloc
-                         (cu->header.get_length_without_initial () / 12,
-                          die_info::hash, die_info::eq,
-                          nullptr, xcalloc, xfree));
+      gdb_assert (cu->die_hash.empty ());
+      cu->die_hash.reserve (cu->header.get_length_without_initial () / 12);
 
       if (reader.comp_unit_die->has_children)
        reader.comp_unit_die->child