aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2024-11-04 13:27:54 -0500
committerSimon Marchi <simon.marchi@polymtl.ca>2024-11-25 22:07:04 -0500
commita5a6ba04802332630b73148efc92df6ddd69e4b7 (patch)
treefacf404d5d2866bb51488803a3cc67dd6d12ee1b /gdb
parent9c0818db31b7380779ec7904514a699cd22d8dbb (diff)
downloadgdb-a5a6ba04802332630b73148efc92df6ddd69e4b7.zip
gdb-a5a6ba04802332630b73148efc92df6ddd69e4b7.tar.gz
gdb-a5a6ba04802332630b73148efc92df6ddd69e4b7.tar.bz2
Convert dwarf_cu::die_hash to new hash table
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>
Diffstat (limited to 'gdb')
-rw-r--r--gdb/dwarf2/cu.h5
-rw-r--r--gdb/dwarf2/die.c21
-rw-r--r--gdb/dwarf2/die.h37
-rw-r--r--gdb/dwarf2/read.c39
4 files changed, 44 insertions, 58 deletions
diff --git a/gdb/dwarf2/cu.h b/gdb/dwarf2/cu.h
index ea8e147..23b06dc 100644
--- a/gdb/dwarf2/cu.h
+++ b/gdb/dwarf2/cu.h
@@ -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;
diff --git a/gdb/dwarf2/die.c b/gdb/dwarf2/die.c
index bfa54e5..500d7bf 100644
--- a/gdb/dwarf2/die.c
+++ b/gdb/dwarf2/die.c
@@ -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)
{
diff --git a/gdb/dwarf2/die.h b/gdb/dwarf2/die.h
index d4eab08..770964e 100644
--- a/gdb/dwarf2/die.h
+++ b/gdb/dwarf2/die.h
@@ -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 */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 8d5dedd..b20d3cd 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -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