From patchwork Mon Mar 13 22:08:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 66334 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3C23F3850232 for ; Mon, 13 Mar 2023 22:08:57 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from gproxy2-pub.mail.unifiedlayer.com (gproxy2-pub.mail.unifiedlayer.com [69.89.18.3]) by sourceware.org (Postfix) with ESMTPS id A74B43858C27 for ; Mon, 13 Mar 2023 22:08:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A74B43858C27 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 cmgw10.mail.unifiedlayer.com (unknown [10.0.90.125]) by progateway4.mail.pro1.eigbox.com (Postfix) with ESMTP id E3C481004A3F6 for ; Mon, 13 Mar 2023 22:08:06 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id bqKspfLG5HIU4bqKspFy9r; Mon, 13 Mar 2023 22:08:06 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=NfUja0P4 c=1 sm=1 tr=0 ts=640f9ec6 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10:nop_charset_1 a=k__wU0fu6RkA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=Dhl7312aG6fIw3zdZO4A:9 a=QEXdDO2ut3YA:10:nop_charset_2 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc: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=wDsFtfh8JrJh3SSgoeZKq/+gSlsh++hAcjreiDqoISs=; b=vjWcqlkSxuZaCIC2sdPGxfgwaB Y8FGQtFHrNwMyWE6yc1xXWj3gDVlPDSfTsNJgEIGWssI+RATwGVzlGCAkDeQZcx9HLjJAveV79FU5 XjqKXN/bsLjs2jZma6RWlKpBi; Received: from 71-211-185-113.hlrn.qwest.net ([71.211.185.113]:52788 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pbqKs-000u2m-L0 for gdb-patches@sourceware.org; Mon, 13 Mar 2023 16:08:06 -0600 From: Tom Tromey Date: Mon, 13 Mar 2023 16:08:03 -0600 Subject: [PATCH 03/20] Remove alloc_type_copy MIME-Version: 1.0 Message-Id: <20230313-split-objfile-type-allocator-2-v1-3-69ba773ac17b@tromey.com> References: <20230313-split-objfile-type-allocator-2-v1-0-69ba773ac17b@tromey.com> In-Reply-To: <20230313-split-objfile-type-allocator-2-v1-0-69ba773ac17b@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.1 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.185.113 X-Source-L: No X-Exim-ID: 1pbqKs-000u2m-L0 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-185-113.hlrn.qwest.net ([192.168.0.21]) [71.211.185.113]:52788 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3026.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This removes alloc_type_copy, replacing all uses with the new type allocator. --- gdb/ada-lang.c | 25 +++++++++++++------------ gdb/gdbtypes.c | 30 ++++++++++-------------------- gdb/gdbtypes.h | 6 +----- gdb/rust-lang.c | 2 +- gdb/stabsread.c | 2 +- 5 files changed, 26 insertions(+), 39 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 7b07c4f9473..624584e8ee5 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -2140,8 +2140,9 @@ ada_type_of_array (struct value *arr, int bounds) return NULL; while (arity > 0) { - struct type *range_type = alloc_type_copy (arr->type ()); - struct type *array_type = alloc_type_copy (arr->type ()); + type_allocator alloc (arr->type ()); + struct type *range_type = alloc.new_type (); + struct type *array_type = alloc.new_type (); struct value *low = desc_one_bound (descriptor, arity, 0); struct value *high = desc_one_bound (descriptor, arity, 1); @@ -2382,7 +2383,7 @@ constrained_packed_array_type (struct type *type, long *elt_bits) else index_type = type->index_type (); - new_type = alloc_type_copy (type); + new_type = type_allocator (type).new_type (); new_elt_type = constrained_packed_array_type (ada_check_typedef (type->target_type ()), elt_bits); @@ -7816,7 +7817,7 @@ variant_field_index (struct type *type) static struct type * empty_record (struct type *templ) { - struct type *type = alloc_type_copy (templ); + struct type *type = type_allocator (templ).new_type (); type->set_code (TYPE_CODE_STRUCT); INIT_NONE_SPECIFIC (type); @@ -7872,7 +7873,7 @@ ada_template_to_fixed_record_type_1 (struct type *type, nfields++; } - rtype = alloc_type_copy (type); + rtype = type_allocator (type).new_type (); rtype->set_code (TYPE_CODE_STRUCT); INIT_NONE_SPECIFIC (rtype); rtype->set_num_fields (nfields); @@ -8123,7 +8124,7 @@ template_to_static_fixed_type (struct type *type0) /* Clone TYPE0 only the first time we get a new field type. */ if (type == type0) { - type = alloc_type_copy (type0); + type = type_allocator (type0).new_type (); type0->set_target_type (type); type->set_code (type0->code ()); INIT_NONE_SPECIFIC (type); @@ -8177,7 +8178,7 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr, else dval = dval0; - rtype = alloc_type_copy (type); + rtype = type_allocator (type).new_type (); rtype->set_code (TYPE_CODE_STRUCT); INIT_NONE_SPECIFIC (rtype); rtype->set_num_fields (nfields); @@ -8470,7 +8471,7 @@ to_fixed_array_type (struct type *type0, struct value *dval, if (elt_type0 == elt_type && !constrained_packed_array_p) result = type0; else - result = create_array_type (alloc_type_copy (type0), + result = create_array_type (type_allocator (type0).new_type (), elt_type, type0->index_type ()); } else @@ -8502,7 +8503,7 @@ to_fixed_array_type (struct type *type0, struct value *dval, struct type *range_type = to_fixed_range_type (index_type_desc->field (i).type (), dval); - result = create_array_type (alloc_type_copy (elt_type0), + result = create_array_type (type_allocator (elt_type0).new_type (), result, range_type); elt_type0 = elt_type0->target_type (); } @@ -11514,8 +11515,8 @@ to_fixed_range_type (struct type *raw_type, struct value *dval) if (L < INT_MIN || U > INT_MAX) return raw_type; else - return create_static_range_type (alloc_type_copy (raw_type), raw_type, - L, U); + return create_static_range_type (type_allocator (raw_type).new_type (), + raw_type, L, U); } else { @@ -11566,7 +11567,7 @@ to_fixed_range_type (struct type *raw_type, struct value *dval) } } - type = create_static_range_type (alloc_type_copy (raw_type), + type = create_static_range_type (type_allocator (raw_type).new_type (), base_type, L, U); /* create_static_range_type alters the resulting type's length to match the size of the base_type, which is not what we want. diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 1e880edf681..6ad6aadb468 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -258,16 +258,6 @@ alloc_type (struct objfile *objfile) return type; } -/* If TYPE is objfile-associated, allocate a new type structure - associated with the same objfile. If TYPE is gdbarch-associated, - allocate a new type structure associated with the same gdbarch. */ - -struct type * -alloc_type_copy (const struct type *type) -{ - return type_allocator (type).new_type (); -} - /* See gdbtypes.h. */ type * @@ -421,7 +411,7 @@ make_pointer_type (struct type *type, struct type **typeptr) if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ { - ntype = alloc_type_copy (type); + ntype = type_allocator (type).new_type (); if (typeptr) *typeptr = ntype; } @@ -499,7 +489,7 @@ make_reference_type (struct type *type, struct type **typeptr, if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ { - ntype = alloc_type_copy (type); + ntype = type_allocator (type).new_type (); if (typeptr) *typeptr = ntype; } @@ -574,7 +564,7 @@ make_function_type (struct type *type, struct type **typeptr) if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ { - ntype = alloc_type_copy (type); + ntype = type_allocator (type).new_type (); if (typeptr) *typeptr = ntype; } @@ -906,7 +896,7 @@ lookup_memberptr_type (struct type *type, struct type *domain) { struct type *mtype; - mtype = alloc_type_copy (type); + mtype = type_allocator (type).new_type (); smash_to_memberptr_type (mtype, domain, type); return mtype; } @@ -918,7 +908,7 @@ lookup_methodptr_type (struct type *to_type) { struct type *mtype; - mtype = alloc_type_copy (to_type); + mtype = type_allocator (to_type).new_type (); smash_to_methodptr_type (mtype, to_type); return mtype; } @@ -981,7 +971,7 @@ create_range_type (struct type *result_type, struct type *index_type, gdb_assert (index_type->length () > 0); if (result_type == NULL) - result_type = alloc_type_copy (index_type); + result_type = type_allocator (index_type).new_type (); result_type->set_code (TYPE_CODE_RANGE); result_type->set_target_type (index_type); if (index_type->is_stub ()) @@ -1425,7 +1415,7 @@ create_array_type_with_stride (struct type *result_type, } if (result_type == NULL) - result_type = alloc_type_copy (range_type); + result_type = type_allocator (range_type).new_type (); result_type->set_code (TYPE_CODE_ARRAY); result_type->set_target_type (element_type); @@ -1527,7 +1517,7 @@ struct type * create_set_type (struct type *result_type, struct type *domain_type) { if (result_type == NULL) - result_type = alloc_type_copy (domain_type); + result_type = type_allocator (domain_type).new_type (); result_type->set_code (TYPE_CODE_SET); result_type->set_num_fields (1); @@ -3597,7 +3587,7 @@ init_complex_type (const char *name, struct type *target_type) name = new_name; } - t = alloc_type_copy (target_type); + t = type_allocator (target_type).new_type (); set_type_code (t, TYPE_CODE_COMPLEX); t->set_length (2 * target_type->length ()); t->set_name (name); @@ -5804,7 +5794,7 @@ copy_type_recursive (struct type *type, htab_t copied_types) struct type * copy_type (const struct type *type) { - struct type *new_type = alloc_type_copy (type); + struct type *new_type = type_allocator (type).new_type (); new_type->set_instance_flags (type->instance_flags ()); new_type->set_length (type->length ()); memcpy (TYPE_MAIN_TYPE (new_type), TYPE_MAIN_TYPE (type), diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 861d0021d30..03f94709006 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -2186,12 +2186,8 @@ extern const struct floatformat *floatformats_bfloat16[BFD_ENDIAN_UNKNOWN]; #define TYPE_ZALLOC(t,size) (memset (TYPE_ALLOC (t, size), 0, size)) -/* Use alloc_type to allocate a type owned by an objfile. Use - alloc_type_copy to allocate a type with the same owner as a - pre-existing template type, no matter whether objfile or - gdbarch. */ +/* Use alloc_type to allocate a type owned by an objfile. */ extern struct type *alloc_type (struct objfile *); -extern struct type *alloc_type_copy (const struct type *); /* * This returns the target type (or NULL) of TYPE, also skipping past typedefs. */ diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 6fc73b262f5..82004da53d4 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -939,7 +939,7 @@ rust_composite_type (struct type *original, const char *field1, struct type *type1, const char *field2, struct type *type2) { - struct type *result = alloc_type_copy (original); + struct type *result = type_allocator (original).new_type (); int i, nfields, bitpos; nfields = 0; diff --git a/gdb/stabsread.c b/gdb/stabsread.c index 73f05c44b23..cfe245325f5 100644 --- a/gdb/stabsread.c +++ b/gdb/stabsread.c @@ -1475,7 +1475,7 @@ allocate_stub_method (struct type *type) { struct type *mtype; - mtype = alloc_type_copy (type); + mtype = type_allocator (type).new_type (); mtype->set_code (TYPE_CODE_METHOD); mtype->set_length (1); mtype->set_is_stub (true);