]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Convert type copying to new hash table
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 4 Nov 2024 18:27:45 +0000 (13:27 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Tue, 26 Nov 2024 03:07:04 +0000 (22:07 -0500)
This converts the type copying code to use the new hash map.

Change-Id: I35f0a4946dcc5c5eb84820126cf716b600f3302f
Co-Authored-By: Tom Tromey <tom@tromey.com>
Approved-By: Tom Tromey <tom@tromey.com>
14 files changed:
gdb/compile/compile-object-run.c
gdb/extension-priv.h
gdb/extension.c
gdb/extension.h
gdb/gdbtypes.c
gdb/gdbtypes.h
gdb/guile/guile-internal.h
gdb/guile/scm-type.c
gdb/guile/scm-value.c
gdb/python/py-type.c
gdb/python/py-value.c
gdb/python/python-internal.h
gdb/value.c
gdb/value.h

index 5a810d5a16d4e28ab42d9d28b79d3488eec6e8a3..83163774662c8854147fcf45d5571bdd1c1cbf92 100644 (file)
@@ -105,9 +105,9 @@ do_module_cleanup (void *arg, int registers_valid)
 static type *
 create_copied_type_recursive (objfile *objfile, type *func_type)
 {
-  htab_up copied_types = create_copied_types_hash ();
-  func_type = copy_type_recursive (func_type, copied_types.get ());
-  return func_type;
+  copied_types_hash_t copied_types;
+
+  return copy_type_recursive (func_type, copied_types);
 }
 
 /* Perform inferior call of MODULE.  This function may throw an error.
index a31283f831cfd29559bf51a3675972998ee78a74..1c7f1469b2f0becd19a98d554ffe688774d8b341 100644 (file)
@@ -201,7 +201,8 @@ struct extension_language_ops
      COPIED_TYPES is used to prevent cycles / duplicates and is passed to
      preserve_one_value.  */
   void (*preserve_values) (const struct extension_language_defn *,
-                          struct objfile *objfile, htab_t copied_types);
+                          struct objfile *objfile,
+                          copied_types_hash_t &copied_types);
 
   /* Return non-zero if there is a stop condition for the breakpoint.
      This is used to implement the restriction that a breakpoint may have
index f13d391ecba91002d0c50c587874eca22fddb19f..b78ea4f27160745587bbf8233f1df86e2dfd1376 100644 (file)
@@ -563,7 +563,8 @@ apply_ext_lang_ptwrite_filter (btrace_thread_info *btinfo)
    preserve_one_value.  */
 
 void
-preserve_ext_lang_values (struct objfile *objfile, htab_t copied_types)
+preserve_ext_lang_values (struct objfile *objfile,
+                         copied_types_hash_t &copied_types)
 {
   for (const struct extension_language_defn *extlang : extension_languages)
     {
index 793a66fc1376d90d7d84cf67e50c6a4ff72fb148..fc6020a759cb6e32509439cdb18c74ff044ccc25 100644 (file)
@@ -22,8 +22,8 @@
 
 #include "mi/mi-cmds.h"
 #include "gdbsupport/array-view.h"
-#include "hashtab.h"
 #include <optional>
+#include "gdbtypes.h"
 
 struct breakpoint;
 struct command_line;
@@ -307,7 +307,8 @@ extern enum ext_lang_bt_status apply_ext_lang_frame_filter
 extern void apply_ext_lang_ptwrite_filter
   (struct btrace_thread_info *btinfo);
 
-extern void preserve_ext_lang_values (struct objfile *, htab_t copied_types);
+extern void preserve_ext_lang_values (struct objfile *,
+                                     copied_types_hash_t &copied_types);
 
 extern const struct extension_language_defn *get_breakpoint_cond_ext_lang
   (struct breakpoint *b, enum extension_language skip_lang);
index 1a04488d272a747bea4bbe2054b034b02c02b5d4..0928e24446708fd654194298b0dafa80730e213c 100644 (file)
@@ -5407,46 +5407,6 @@ recursive_dump_type (struct type *type, int spaces)
     obstack_free (&dont_print_type_obstack, NULL);
 }
 \f
-/* Trivial helpers for the libiberty hash table, for mapping one
-   type to another.  */
-
-struct type_pair
-{
-  type_pair (struct type *old_, struct type *newobj_)
-    : old (old_), newobj (newobj_)
-  {}
-
-  struct type * const old, * const newobj;
-};
-
-static hashval_t
-type_pair_hash (const void *item)
-{
-  const struct type_pair *pair = (const struct type_pair *) item;
-
-  return htab_hash_pointer (pair->old);
-}
-
-static int
-type_pair_eq (const void *item_lhs, const void *item_rhs)
-{
-  const struct type_pair *lhs = (const struct type_pair *) item_lhs;
-  const struct type_pair *rhs = (const struct type_pair *) item_rhs;
-
-  return lhs->old == rhs->old;
-}
-
-/* Allocate the hash table used by copy_type_recursive to walk
-   types without duplicates.  */
-
-htab_up
-create_copied_types_hash ()
-{
-  return htab_up (htab_create_alloc (1, type_pair_hash, type_pair_eq,
-                                    htab_delete_entry<type_pair>,
-                                    xcalloc, xfree));
-}
-
 /* Recursively copy (deep copy) a dynamic attribute list of a type.  */
 
 static struct dynamic_prop_list *
@@ -5478,27 +5438,20 @@ copy_dynamic_prop_list (struct obstack *storage,
    it is not associated with OBJFILE.  */
 
 struct type *
-copy_type_recursive (struct type *type, htab_t copied_types)
+copy_type_recursive (struct type *type, copied_types_hash_t &copied_types)
 {
-  void **slot;
-  struct type *new_type;
-
   if (!type->is_objfile_owned ())
     return type;
 
-  struct type_pair pair (type, nullptr);
+  if (auto iter = copied_types.find (type);
+      iter != copied_types.end ())
+    return iter->second;
 
-  slot = htab_find_slot (copied_types, &pair, INSERT);
-  if (*slot != NULL)
-    return ((struct type_pair *) *slot)->newobj;
-
-  new_type = type_allocator (type->arch ()).new_type ();
+  struct type *new_type = type_allocator (type->arch ()).new_type ();
 
   /* We must add the new type to the hash table immediately, in case
      we encounter this type again during a recursive call below.  */
-  struct type_pair *stored = new type_pair (type, new_type);
-
-  *slot = stored;
+  copied_types.emplace (type, new_type);
 
   /* Copy the common fields of types.  For the main type, we simply
      copy the entire thing and then update specific fields as needed.  */
index 7fdb377c263ae3921ee8a89ec7d2d4be21560b67..4cdc48b9a2f9782003d7151f66d19977eaec1923 100644 (file)
    written such that they can be used as both rvalues and lvalues.
  */
 
-#include "hashtab.h"
 #include "gdbsupport/array-view.h"
-#include "gdbsupport/gdb-hashtab.h"
 #include <optional>
 #include "gdbsupport/enum-flags.h"
 #include "dwarf2.h"
 #include "gdbsupport/gdb_obstack.h"
 #include "gmp-utils.h"
+#include "gdbsupport/unordered_map.h"
 
 /* Forward declarations for prototypes.  */
 struct field;
@@ -2785,10 +2784,10 @@ extern int class_or_union_p (const struct type *);
 
 extern void maintenance_print_type (const char *, int);
 
-extern htab_up create_copied_types_hash ();
+using copied_types_hash_t = gdb::unordered_map<type *, type *>;
 
 extern struct type *copy_type_recursive (struct type *type,
-                                        htab_t copied_types);
+                                        copied_types_hash_t &copied_types);
 
 extern struct type *copy_type (const struct type *type);
 
index 9b9bb21951dd28a908123ad5f580e2faf3683b7a..fbf689848a25ecd6a22d26e698b5688843685f04 100644 (file)
@@ -603,7 +603,7 @@ extern bool gdbscm_auto_load_enabled (const struct extension_language_defn *);
 
 extern void gdbscm_preserve_values
   (const struct extension_language_defn *,
-   struct objfile *, htab_t copied_types);
+   struct objfile *, copied_types_hash_t &copied_types);
 
 extern enum ext_lang_rc gdbscm_apply_val_pretty_printer
   (const struct extension_language_defn *,
index 19324a69810c49bb9ee8bb74930c7d244b6e6e21..f22876265074fe89b915f2aef9a856c759a2b71f 100644 (file)
@@ -94,8 +94,8 @@ struct tyscm_deleter
       return;
 
     gdb_assert (htab != nullptr);
-    htab_up copied_types = create_copied_types_hash ();
-    htab_traverse_noresize (htab, tyscm_copy_type_recursive, copied_types.get ());
+    copied_types_hash_t copied_types;
+    htab_traverse_noresize (htab, tyscm_copy_type_recursive, &copied_types);
     htab_delete (htab);
   }
 };
@@ -375,12 +375,11 @@ static int
 tyscm_copy_type_recursive (void **slot, void *info)
 {
   type_smob *t_smob = (type_smob *) *slot;
-  htab_t copied_types = (htab_t) info;
+  copied_types_hash_t &copied_types = *static_cast<copied_types_hash_t *> (info);
   htab_t htab;
   eqable_gdb_smob **new_slot;
   type_smob t_smob_for_lookup;
 
-  htab_empty (copied_types);
   t_smob->type = copy_type_recursive (t_smob->type, copied_types);
 
   /* The eq?-hashtab that the type lived in is going away.
index a7b21707eba1fa821a45d85858b39f4e13c15b22..0f4a6a46da0e82471971a6721580f600512abb46 100644 (file)
@@ -86,7 +86,8 @@ static SCM substitute_symbol;
 
 void
 gdbscm_preserve_values (const struct extension_language_defn *extlang,
-                       struct objfile *objfile, htab_t copied_types)
+                       struct objfile *objfile,
+                       copied_types_hash_t &copied_types)
 {
   value_smob *iter;
 
index 284960a3a879b3b91f25fe9e25542fbdb037986f..11a96d52c2e0c29d82da012185c79fc024b7d5a3 100644 (file)
@@ -1174,15 +1174,14 @@ struct typy_deleter
        operating on.  */
     gdbpy_enter enter_py;
 
-    htab_up copied_types = create_copied_types_hash ();
+    copied_types_hash_t copied_types;
 
     while (obj)
       {
        type_object *next = obj->next;
 
-       htab_empty (copied_types.get ());
-
-       obj->type = copy_type_recursive (obj->type, copied_types.get ());
+       copied_types.clear ();
+       obj->type = copy_type_recursive (obj->type, copied_types);
 
        obj->next = NULL;
        obj->prev = NULL;
index eef3841924fabf31d5b203c7227e020c3e27a0a1..1e8e58adcba06cffe2e2696ab9277cf38e95702b 100644 (file)
@@ -233,7 +233,8 @@ valpy_init (PyObject *self, PyObject *args, PyObject *kwds)
    each.  */
 void
 gdbpy_preserve_values (const struct extension_language_defn *extlang,
-                      struct objfile *objfile, htab_t copied_types)
+                      struct objfile *objfile,
+                      copied_types_hash_t &copied_types)
 {
   value_object *iter;
 
index d723c4d577b1d4ccade84ad15b07a340c234b5bc..a3a7294c303bb4cbd228283b196e20ddeb56e68d 100644 (file)
@@ -474,7 +474,7 @@ extern enum ext_lang_bt_status gdbpy_apply_frame_filter
    struct ui_out *out, int frame_low, int frame_high);
 extern void gdbpy_preserve_values (const struct extension_language_defn *,
                                   struct objfile *objfile,
-                                  htab_t copied_types);
+                                  copied_types_hash_t &copied_types);
 extern enum ext_lang_bp_stop gdbpy_breakpoint_cond_says_stop
   (const struct extension_language_defn *, struct breakpoint *);
 extern int gdbpy_breakpoint_has_cond (const struct extension_language_defn *,
index d9b3c6ece04c6d0961ef18ab9de24365d10fa22b..a18491602a8a501475208f8f3774478361a0027a 100644 (file)
@@ -2468,7 +2468,7 @@ add_internal_function (gdb::unique_xmalloc_ptr<char> &&name,
 }
 
 void
-value::preserve (struct objfile *objfile, htab_t copied_types)
+value::preserve (struct objfile *objfile, copied_types_hash_t &copied_types)
 {
   if (m_type->objfile_owner () == objfile)
     m_type = copy_type_recursive (m_type, copied_types);
@@ -2481,7 +2481,7 @@ value::preserve (struct objfile *objfile, htab_t copied_types)
 
 static void
 preserve_one_internalvar (struct internalvar *var, struct objfile *objfile,
-                         htab_t copied_types)
+                         copied_types_hash_t &copied_types)
 {
   switch (var->kind)
     {
@@ -2504,7 +2504,7 @@ preserve_one_internalvar (struct internalvar *var, struct objfile *objfile,
 
 static void
 preserve_one_varobj (struct varobj *varobj, struct objfile *objfile,
-                    htab_t copied_types)
+                    copied_types_hash_t &copied_types)
 {
   if (varobj->type->is_objfile_owned ()
       && varobj->type->objfile_owner () == objfile)
@@ -2528,22 +2528,21 @@ preserve_values (struct objfile *objfile)
 {
   /* Create the hash table.  We allocate on the objfile's obstack, since
      it is soon to be deleted.  */
-  htab_up copied_types = create_copied_types_hash ();
+  copied_types_hash_t copied_types;
 
   for (const value_ref_ptr &item : value_history)
-    item->preserve (objfile, copied_types.get ());
+    item->preserve (objfile, copied_types);
 
   for (auto &pair : internalvars)
-    preserve_one_internalvar (&pair.second, objfile, copied_types.get ());
+    preserve_one_internalvar (&pair.second, objfile, copied_types);
 
   /* For the remaining varobj, check that none has type owned by OBJFILE.  */
   all_root_varobjs ([&copied_types, objfile] (struct varobj *varobj)
     {
-      preserve_one_varobj (varobj, objfile,
-                          copied_types.get ());
+      preserve_one_varobj (varobj, objfile, copied_types);
     });
 
-  preserve_ext_lang_values (objfile, copied_types.get ());
+  preserve_ext_lang_values (objfile, copied_types);
 }
 
 static void
index 13cfb007aa2c0b5f9eaeace824ee7e4e34eacfc5..c8166a77332e8b5fcabbe5b06bc516427088b79d 100644 (file)
 #include "extension.h"
 #include "gdbsupport/gdb_ref_ptr.h"
 #include "gmp-utils.h"
+#include "gdbtypes.h"
 
 struct block;
 struct expression;
 struct regcache;
 struct symbol;
-struct type;
 struct ui_file;
 struct language_defn;
 struct value_print_options;
@@ -593,7 +593,7 @@ public:
 
   /* Update this value before discarding OBJFILE.  COPIED_TYPES is
      used to prevent cycles / duplicates.  */
-  void preserve (struct objfile *objfile, htab_t copied_types);
+  void preserve (struct objfile *objfile, copied_types_hash_t &copied_types);
 
   /* Unpack a bitfield of BITSIZE bits found at BITPOS in the object
      at VALADDR + EMBEDDEDOFFSET that has the type of DEST_VAL and