From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id AC77638582BD; Thu, 28 Jul 2022 20:44:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AC77638582BD Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Change allocation of type-copying hash table X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: b382c16682acc33d2e81e5604c9dbd408be376d2 X-Git-Newrev: bde539c2f9e19271d6d6c740f875b4129e03eba3 Message-Id: <20220728204406.AC77638582BD@sourceware.org> Date: Thu, 28 Jul 2022 20:44:06 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Jul 2022 20:44:06 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dbde539c2f9e1= 9271d6d6c740f875b4129e03eba3 commit bde539c2f9e19271d6d6c740f875b4129e03eba3 Author: Tom Tromey Date: Tue May 24 15:17:19 2022 -0600 Change allocation of type-copying hash table =20 When an objfile is destroyed, types that are still in use and allocated on that objfile are copied. A temporary hash map is created during this process, and it is allocated on the destroyed objfile's obstack -- which normally is fine, as that is going to be destroyed shortly anyway. =20 However, this approach requires that the objfile be passed to registry destruction, and this won't be possible in the rewritten registry. This patch changes the copied type hash table to simply use the heap instead. It also removes the 'objfile' parameter from copy_type_recursive, to make this all more clear. =20 This patch also fixes an apparent bug in copy_type_recursive. Previously it was copying the dynamic property list to the dying objfile's obstack: =20 - =3D copy_dynamic_prop_list (&objfile->objfile_obstack, =20 However I think this is incorrect -- that obstack is about to be destroyed. Diff: --- gdb/compile/compile-object-run.c | 4 ++-- gdb/gdbtypes.c | 40 ++++++++++++++----------------------= ---- gdb/gdbtypes.h | 5 ++--- gdb/guile/scm-type.c | 4 ++-- gdb/python/py-type.c | 5 ++--- gdb/value.c | 11 +++++------ 6 files changed, 27 insertions(+), 42 deletions(-) diff --git a/gdb/compile/compile-object-run.c b/gdb/compile/compile-object-= run.c index 331ae35c5e9..6fcd10b29a4 100644 --- a/gdb/compile/compile-object-run.c +++ b/gdb/compile/compile-object-run.c @@ -109,8 +109,8 @@ do_module_cleanup (void *arg, int registers_valid) static type * create_copied_type_recursive (objfile *objfile, type *func_type) { - htab_up copied_types =3D create_copied_types_hash (objfile); - func_type =3D copy_type_recursive (objfile, func_type, copied_types.get = ()); + htab_up copied_types =3D create_copied_types_hash (); + func_type =3D copy_type_recursive (func_type, copied_types.get ()); return func_type; } =20 diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index c8f98554859..34da6d80e92 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -5562,7 +5562,7 @@ recursive_dump_type (struct type *type, int spaces) /* Trivial helpers for the libiberty hash table, for mapping one type to another. */ =20 -struct type_pair : public allocate_on_obstack +struct type_pair { type_pair (struct type *old_, struct type *newobj_) : old (old_), newobj (newobj_) @@ -5589,22 +5589,20 @@ type_pair_eq (const void *item_lhs, const void *ite= m_rhs) } =20 /* Allocate the hash table used by copy_type_recursive to walk - types without duplicates. We use OBJFILE's obstack, because - OBJFILE is about to be deleted. */ + types without duplicates. */ =20 htab_up -create_copied_types_hash (struct objfile *objfile) +create_copied_types_hash () { - return htab_up (htab_create_alloc_ex (1, type_pair_hash, type_pair_eq, - NULL, &objfile->objfile_obstack, - hashtab_obstack_allocate, - dummy_obstack_deallocate)); + return htab_up (htab_create_alloc (1, type_pair_hash, type_pair_eq, + htab_delete_entry, + xcalloc, xfree)); } =20 /* Recursively copy (deep copy) a dynamic attribute list of a type. */ =20 static struct dynamic_prop_list * -copy_dynamic_prop_list (struct obstack *objfile_obstack, +copy_dynamic_prop_list (struct obstack *storage, struct dynamic_prop_list *list) { struct dynamic_prop_list *copy =3D list; @@ -5615,7 +5613,7 @@ copy_dynamic_prop_list (struct obstack *objfile_obsta= ck, struct dynamic_prop_list *node_copy; =20 node_copy =3D ((struct dynamic_prop_list *) - obstack_copy (objfile_obstack, *node_ptr, + obstack_copy (storage, *node_ptr, sizeof (struct dynamic_prop_list))); node_copy->prop =3D (*node_ptr)->prop; *node_ptr =3D node_copy; @@ -5632,9 +5630,7 @@ copy_dynamic_prop_list (struct obstack *objfile_obsta= ck, it is not associated with OBJFILE. */ =20 struct type * -copy_type_recursive (struct objfile *objfile,=20 - struct type *type, - htab_t copied_types) +copy_type_recursive (struct type *type, htab_t copied_types) { void **slot; struct type *new_type; @@ -5642,10 +5638,6 @@ copy_type_recursive (struct objfile *objfile, if (!type->is_objfile_owned ()) return type; =20 - /* This type shouldn't be pointing to any types in other objfiles; - if it did, the type might disappear unexpectedly. */ - gdb_assert (type->objfile_owner () =3D=3D objfile); - struct type_pair pair (type, nullptr); =20 slot =3D htab_find_slot (copied_types, &pair, INSERT); @@ -5656,8 +5648,7 @@ copy_type_recursive (struct objfile *objfile, =20 /* 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 - =3D new (&objfile->objfile_obstack) struct type_pair (type, new_type); + struct type_pair *stored =3D new type_pair (type, new_type); =20 *slot =3D stored; =20 @@ -5690,8 +5681,7 @@ copy_type_recursive (struct objfile *objfile, TYPE_FIELD_BITSIZE (new_type, i) =3D TYPE_FIELD_BITSIZE (type, i); if (type->field (i).type ()) new_type->field (i).set_type - (copy_type_recursive (objfile, type->field (i).type (), - copied_types)); + (copy_type_recursive (type->field (i).type (), copied_types)); if (type->field (i).name ()) new_type->field (i).set_name (xstrdup (type->field (i).name ())); =20 @@ -5736,16 +5726,14 @@ copy_type_recursive (struct objfile *objfile, =20 if (type->main_type->dyn_prop_list !=3D NULL) new_type->main_type->dyn_prop_list - =3D copy_dynamic_prop_list (&objfile->objfile_obstack, + =3D copy_dynamic_prop_list (gdbarch_obstack (new_type->arch_owner ()= ), type->main_type->dyn_prop_list); =20 =20 /* Copy pointers to other types. */ if (TYPE_TARGET_TYPE (type)) TYPE_TARGET_TYPE (new_type) =3D=20 - copy_type_recursive (objfile,=20 - TYPE_TARGET_TYPE (type), - copied_types); + copy_type_recursive (TYPE_TARGET_TYPE (type), copied_types); =20 /* Maybe copy the type_specific bits. =20 @@ -5774,7 +5762,7 @@ copy_type_recursive (struct objfile *objfile, break; case TYPE_SPECIFIC_SELF_TYPE: set_type_self_type (new_type, - copy_type_recursive (objfile, TYPE_SELF_TYPE (type), + copy_type_recursive (TYPE_SELF_TYPE (type), copied_types)); break; case TYPE_SPECIFIC_FIXED_POINT: diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 7437e1db8ab..cb989228222 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -2875,10 +2875,9 @@ extern int class_or_union_p (const struct type *); =20 extern void maintenance_print_type (const char *, int); =20 -extern htab_up create_copied_types_hash (struct objfile *objfile); +extern htab_up create_copied_types_hash (); =20 -extern struct type *copy_type_recursive (struct objfile *objfile, - struct type *type, +extern struct type *copy_type_recursive (struct type *type, htab_t copied_types); =20 extern struct type *copy_type (const struct type *type); diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c index 27d00f12a95..dd7eace8d40 100644 --- a/gdb/guile/scm-type.c +++ b/gdb/guile/scm-type.c @@ -360,7 +360,7 @@ tyscm_copy_type_recursive (void **slot, void *info) gdb_assert (objfile !=3D NULL); =20 htab_empty (copied_types); - t_smob->type =3D copy_type_recursive (objfile, t_smob->type, copied_type= s); + t_smob->type =3D copy_type_recursive (t_smob->type, copied_types); =20 /* The eq?-hashtab that the type lived in is going away. Add the type to its new eq?-hashtab: Otherwise if/when the type is la= ter @@ -391,7 +391,7 @@ save_objfile_types (struct objfile *objfile, void *datu= m) if (!gdb_scheme_initialized) return; =20 - htab_up copied_types =3D create_copied_types_hash (objfile); + htab_up copied_types =3D create_copied_types_hash (); =20 if (htab !=3D NULL) { diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index 0e772ad44b4..7cfc8d16233 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -1123,7 +1123,7 @@ save_objfile_types (struct objfile *objfile, void *da= tum) operating on. */ gdbpy_enter enter_py (objfile->arch ()); =20 - htab_up copied_types =3D create_copied_types_hash (objfile); + htab_up copied_types =3D create_copied_types_hash (); =20 while (obj) { @@ -1131,8 +1131,7 @@ save_objfile_types (struct objfile *objfile, void *da= tum) =20 htab_empty (copied_types.get ()); =20 - obj->type =3D copy_type_recursive (objfile, obj->type, - copied_types.get ()); + obj->type =3D copy_type_recursive (obj->type, copied_types.get ()); =20 obj->next =3D NULL; obj->prev =3D NULL; diff --git a/gdb/value.c b/gdb/value.c index d027eef07e5..557e22154eb 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -2571,11 +2571,10 @@ preserve_one_value (struct value *value, struct obj= file *objfile, htab_t copied_types) { if (value->type->objfile_owner () =3D=3D objfile) - value->type =3D copy_type_recursive (objfile, value->type, copied_type= s); + value->type =3D copy_type_recursive (value->type, copied_types); =20 if (value->enclosing_type->objfile_owner () =3D=3D objfile) - value->enclosing_type =3D copy_type_recursive (objfile, - value->enclosing_type, + value->enclosing_type =3D copy_type_recursive (value->enclosing_type, copied_types); } =20 @@ -2591,7 +2590,7 @@ preserve_one_internalvar (struct internalvar *var, st= ruct objfile *objfile, if (var->u.integer.type && var->u.integer.type->objfile_owner () =3D=3D objfile) var->u.integer.type - =3D copy_type_recursive (objfile, var->u.integer.type, copied_types); + =3D copy_type_recursive (var->u.integer.type, copied_types); break; =20 case INTERNALVAR_VALUE: @@ -2612,7 +2611,7 @@ preserve_one_varobj (struct varobj *varobj, struct ob= jfile *objfile, && varobj->type->objfile_owner () =3D=3D objfile) { varobj->type - =3D copy_type_recursive (objfile, varobj->type, copied_types); + =3D copy_type_recursive (varobj->type, copied_types); } =20 if (varobj->value !=3D nullptr) @@ -2632,7 +2631,7 @@ preserve_values (struct objfile *objfile) =20 /* Create the hash table. We allocate on the objfile's obstack, since it is soon to be deleted. */ - htab_up copied_types =3D create_copied_types_hash (objfile); + htab_up copied_types =3D create_copied_types_hash (); =20 for (const value_ref_ptr &item : value_history) preserve_one_value (item.get (), objfile, copied_types.get ());