#include "complaints.h"
#include "dwarf2/attribute.h"
-#include "hashtab.h"
/* This data structure holds a complete die structure. */
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. */
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 */
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
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);
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;
}
*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.
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;
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. */
(*ref_cu)->per_cu->imported_symtabs.push_back (sig_cu->per_cu);
*ref_cu = sig_cu;
- return die;
+ return *die_it;
}
return NULL;
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