From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id MJB0IFMGlWL3SQkAWB0awg (envelope-from ) for ; Mon, 30 May 2022 14:00:51 -0400 Received: by simark.ca (Postfix, from userid 112) id 80EF51E221; Mon, 30 May 2022 14:00:51 -0400 (EDT) Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=Phx7377J; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 9F9721E143 for ; Mon, 30 May 2022 14:00:50 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4FF0C3848581 for ; Mon, 30 May 2022 18:00:50 +0000 (GMT) Received: from qproxy1-pub.mail.unifiedlayer.com (qproxy1-pub.mail.unifiedlayer.com [173.254.64.10]) by sourceware.org (Postfix) with ESMTPS id 828B8384B0CC for ; Mon, 30 May 2022 18:00:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 828B8384B0CC Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from gproxy2-pub.mail.unifiedlayer.com (unknown [69.89.18.3]) by qproxy1.mail.unifiedlayer.com (Postfix) with ESMTP id EA69D802F156 for ; Mon, 30 May 2022 18:00:07 +0000 (UTC) Received: from cmgw15.mail.unifiedlayer.com (unknown [10.0.90.130]) by progateway4.mail.pro1.eigbox.com (Postfix) with ESMTP id BA71A10047E35 for ; Mon, 30 May 2022 17:59:37 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id vjg1nKsu0kku4vjg1nYOMj; Mon, 30 May 2022 17:59:37 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=I6Wg+Psg c=1 sm=1 tr=0 ts=62950609 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=oZkIemNP1mAA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=vnOt7WNp1m9eZoHNivYA:9 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=iPdLTe2U8mLQQoFYJJFnvd/DD0voxvKjoDtDJTlXPY0=; b=Phx7377JnjY0aNP/GpaXhX8ry0 BBPQGkFf/35TW68XL3s1LvUlN7QWKNoqVASQrasoTU05m4E8dZPgD/eenm1kqBw3BwwKuIZ6olib9 jZrCybFRyKddnpcoVJU1EfhFj; Received: from 71-211-158-194.hlrn.qwest.net ([71.211.158.194]:45630 helo=prentzel.Home) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nvjg0-002OyG-Rj; Mon, 30 May 2022 11:59:36 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Subject: [PATCH 2/6] Change allocation of type-copying hash table Date: Mon, 30 May 2022 11:59:30 -0600 Message-Id: <20220530175934.3872892-3-tom@tromey.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220530175934.3872892-1-tom@tromey.com> References: <20220530175934.3872892-1-tom@tromey.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.211.158.194 X-Source-L: No X-Exim-ID: 1nvjg0-002OyG-Rj X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-158-194.hlrn.qwest.net (prentzel.Home) [71.211.158.194]:45630 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Tromey Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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. 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. 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: - = copy_dynamic_prop_list (&objfile->objfile_obstack, However I think this is incorrect -- that obstack is about to be destroyed. --- 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 | 9 ++++--- 6 files changed, 26 insertions(+), 41 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 = create_copied_types_hash (objfile); - func_type = copy_type_recursive (objfile, func_type, copied_types.get ()); + htab_up copied_types = create_copied_types_hash (); + func_type = copy_type_recursive (func_type, copied_types.get ()); return func_type; } diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 2a51372a037..9f49c15862f 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. */ -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 *item_rhs) } /* 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. */ 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)); } /* Recursively copy (deep copy) a dynamic attribute list of a type. */ 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 = list; @@ -5615,7 +5613,7 @@ copy_dynamic_prop_list (struct obstack *objfile_obstack, struct dynamic_prop_list *node_copy; node_copy = ((struct dynamic_prop_list *) - obstack_copy (objfile_obstack, *node_ptr, + obstack_copy (storage, *node_ptr, sizeof (struct dynamic_prop_list))); node_copy->prop = (*node_ptr)->prop; *node_ptr = node_copy; @@ -5632,9 +5630,7 @@ copy_dynamic_prop_list (struct obstack *objfile_obstack, it is not associated with OBJFILE. */ struct type * -copy_type_recursive (struct objfile *objfile, - 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; - /* 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 () == objfile); - struct type_pair pair (type, nullptr); slot = htab_find_slot (copied_types, &pair, INSERT); @@ -5656,8 +5648,7 @@ copy_type_recursive (struct objfile *objfile, /* 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 (&objfile->objfile_obstack) struct type_pair (type, new_type); + struct type_pair *stored = new type_pair (type, new_type); *slot = stored; @@ -5690,8 +5681,7 @@ copy_type_recursive (struct objfile *objfile, TYPE_FIELD_BITSIZE (new_type, i) = 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 ())); @@ -5736,16 +5726,14 @@ copy_type_recursive (struct objfile *objfile, if (type->main_type->dyn_prop_list != NULL) new_type->main_type->dyn_prop_list - = copy_dynamic_prop_list (&objfile->objfile_obstack, + = copy_dynamic_prop_list (gdbarch_obstack (new_type->arch_owner ()), type->main_type->dyn_prop_list); /* Copy pointers to other types. */ if (TYPE_TARGET_TYPE (type)) TYPE_TARGET_TYPE (new_type) = - copy_type_recursive (objfile, - TYPE_TARGET_TYPE (type), - copied_types); + copy_type_recursive (TYPE_TARGET_TYPE (type), copied_types); /* Maybe copy the type_specific bits. @@ -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 *); extern void maintenance_print_type (const char *, int); -extern htab_up create_copied_types_hash (struct objfile *objfile); +extern htab_up create_copied_types_hash (); -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); 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 != NULL); htab_empty (copied_types); - t_smob->type = copy_type_recursive (objfile, t_smob->type, copied_types); + t_smob->type = copy_type_recursive (t_smob->type, copied_types); /* 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 later @@ -391,7 +391,7 @@ save_objfile_types (struct objfile *objfile, void *datum) if (!gdb_scheme_initialized) return; - htab_up copied_types = create_copied_types_hash (objfile); + htab_up copied_types = create_copied_types_hash (); if (htab != NULL) { diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index 5352ead84bd..6cbf5f2eb6a 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -1125,7 +1125,7 @@ save_objfile_types (struct objfile *objfile, void *datum) operating on. */ gdbpy_enter enter_py (objfile->arch ()); - htab_up copied_types = create_copied_types_hash (objfile); + htab_up copied_types = create_copied_types_hash (); while (obj) { @@ -1133,8 +1133,7 @@ save_objfile_types (struct objfile *objfile, void *datum) htab_empty (copied_types.get ()); - obj->type = copy_type_recursive (objfile, obj->type, - copied_types.get ()); + obj->type = copy_type_recursive (obj->type, copied_types.get ()); obj->next = NULL; obj->prev = NULL; diff --git a/gdb/value.c b/gdb/value.c index 022fca91a42..6fb84aee582 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -2567,11 +2567,10 @@ preserve_one_value (struct value *value, struct objfile *objfile, htab_t copied_types) { if (value->type->objfile_owner () == objfile) - value->type = copy_type_recursive (objfile, value->type, copied_types); + value->type = copy_type_recursive (value->type, copied_types); if (value->enclosing_type->objfile_owner () == objfile) - value->enclosing_type = copy_type_recursive (objfile, - value->enclosing_type, + value->enclosing_type = copy_type_recursive (value->enclosing_type, copied_types); } @@ -2587,7 +2586,7 @@ preserve_one_internalvar (struct internalvar *var, struct objfile *objfile, if (var->u.integer.type && var->u.integer.type->objfile_owner () == objfile) var->u.integer.type - = copy_type_recursive (objfile, var->u.integer.type, copied_types); + = copy_type_recursive (var->u.integer.type, copied_types); break; case INTERNALVAR_VALUE: @@ -2609,7 +2608,7 @@ 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 (objfile); + htab_up copied_types = create_copied_types_hash (); for (const value_ref_ptr &item : value_history) preserve_one_value (item.get (), objfile, copied_types.get ()); -- 2.34.1