From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id Yc4hHkQTuGliEiwAWB0awg (envelope-from ) for ; Mon, 16 Mar 2026 10:27:16 -0400 Received: by simark.ca (Postfix, from userid 112) id 7825A1E0A2; Mon, 16 Mar 2026 10:27:16 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id BC7A91E0A2 for ; Mon, 16 Mar 2026 10:27:14 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 4491D4BA23E1 for ; Mon, 16 Mar 2026 14:27:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4491D4BA23E1 Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 8DA5F4BA23E1 for ; Mon, 16 Mar 2026 14:26:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8DA5F4BA23E1 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8DA5F4BA23E1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773671209; cv=none; b=tNMPhdg2Zm/Eq1U221YCEQWui+7nS7v2qGz7x09D3kt0ADwt34PaGDr6RN7ociMxdGOqfvVQbb0r2Jq+IhLPdnmcxT/Gn7VCTOnQrl+vMChzCOMZR8CHzepQxPlh6ad1kVAcPaHCvAzzwecioYum8ACV2lcJcZIKO64C6HkkRhY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773671209; c=relaxed/simple; bh=ekqnv/UmnAJGHNn53hMp0NZRFDlW/9J/GsM+DmM3ioQ=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=OBf3nYcuymcFHl3CTRvNNV+0DLCThtGEhND/FwvV4GHFsbKwK67M5YB6kHwauH4E6qbSpBaSg4xpgQqtKdjCgdwafmlZJi+3KLXSfpApsbRifuNAw6G1rHdbdKvHgB7e95OPxJv9923qqGcihGuKXu1PHdKTImPf+OTJHLB210Q= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8DA5F4BA23E1 Received: by simark.ca (Postfix) id 285C91E0BC; Mon, 16 Mar 2026 10:26:47 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 2/6] gdb: remove TYPE_MAIN_TYPE Date: Mon, 16 Mar 2026 10:25:19 -0400 Message-ID: <20260316142645.26877-3-simon.marchi@efficios.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260316142645.26877-1-simon.marchi@efficios.com> References: <20260316142645.26877-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Simon Marchi IMO, there is no point in keeping this macro. Remove it and access the field directly. If we ever want some kind of abstraction in front of the field, then we'll add a method. Change-Id: I1076b0e07644afdc0c1f3a4916148d3344a9d395 --- gdb/ada-lang.c | 3 +-- gdb/dwarf2/loc.c | 3 +-- gdb/dwarf2/read.c | 4 ++-- gdb/eval.c | 2 +- gdb/gdbtypes.c | 48 +++++++++++++++++++++++------------------------ gdb/gdbtypes.h | 21 ++++++++++----------- 6 files changed, 39 insertions(+), 42 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 7784f8841318..4ffe69645767 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -8570,8 +8570,7 @@ ada_to_fixed_type (struct type *type, const gdb_byte *valaddr, because we call check_typedef/ada_check_typedef pretty much everywhere. */ if (type->code () == TYPE_CODE_TYPEDEF - && (TYPE_MAIN_TYPE (ada_typedef_target_type (type)) - == TYPE_MAIN_TYPE (fixed_type))) + && (ada_typedef_target_type (type)->main_type == fixed_type->main_type)) return type; return fixed_type; diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c index 273d3d942b5a..a493a46dcfc9 100644 --- a/gdb/dwarf2/loc.c +++ b/gdb/dwarf2/loc.c @@ -1739,8 +1739,7 @@ dwarf2_evaluate_property (const dynamic_prop *prop, for (pinfo = addr_stack; pinfo != NULL; pinfo = pinfo->next) { /* This approach lets us avoid checking the qualifiers. */ - if (TYPE_MAIN_TYPE (pinfo->type) - == TYPE_MAIN_TYPE (baton->property_type)) + if (pinfo->type->main_type == baton->property_type->main_type) break; } if (pinfo == NULL) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index e41f06890d74..87f6f33ca071 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -13349,8 +13349,8 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu) /* Only use the attributes if they make sense together. */ if (*bit_size + offset <= 8 * type->length ()) { - TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_size = *bit_size; - TYPE_MAIN_TYPE (type)->type_specific.int_stuff.bit_offset = offset; + type->main_type->type_specific.int_stuff.bit_size = *bit_size; + type->main_type->type_specific.int_stuff.bit_offset = offset; } } diff --git a/gdb/eval.c b/gdb/eval.c index c13f3cb170d3..6cd6f1e677bc 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -455,7 +455,7 @@ fake_method::fake_method (type_instance_flags flags, { struct type *type = &m_type; - TYPE_MAIN_TYPE (type) = &m_main_type; + type->main_type = &m_main_type; type->set_length (1); type->set_code (TYPE_CODE_METHOD); TYPE_CHAIN (type) = type; diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 5e07e290f67e..bbefa3ff6b4b 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -216,8 +216,8 @@ type_allocator::new_type () /* Alloc the structure and start off with all fields zeroed. */ struct type *type = OBSTACK_ZALLOC (obstack, struct type); - TYPE_MAIN_TYPE (type) = OBSTACK_ZALLOC (obstack, struct main_type); - TYPE_MAIN_TYPE (type)->m_lang = m_lang; + type->main_type = OBSTACK_ZALLOC (obstack, struct main_type); + type->main_type->m_lang = m_lang; if (m_is_objfile) { @@ -329,7 +329,7 @@ alloc_type_instance (struct type *oldtype) type = OBSTACK_ZALLOC (&oldtype->objfile_owner ()->objfile_obstack, struct type); - TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype); + type->main_type = oldtype->main_type; TYPE_CHAIN (type) = type; /* Chain back to itself for now. */ @@ -346,7 +346,7 @@ smash_type (struct type *type) objfile *objfile = type->objfile_owner (); gdbarch *arch = type->arch_owner (); - memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type)); + memset (type->main_type, 0, sizeof (struct main_type)); /* Restore owner information. */ if (objfile_owned) @@ -608,7 +608,7 @@ make_qualified_type (struct type *type, type_instance_flags new_flags, gdb_assert (type->objfile_owner () == storage->objfile_owner ()); ntype = storage; - TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type); + ntype->main_type = type->main_type; TYPE_CHAIN (ntype) = ntype; } @@ -726,7 +726,7 @@ replace_type (struct type *ntype, struct type *type) lists; etc.) allocated on an objfile other than its own. */ gdb_assert (ntype->objfile_owner () == type->objfile_owner ()); - *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type); + *ntype->main_type = *type->main_type; /* The type length is not a part of the main type. Update it for each type on the variant chain. */ @@ -1407,12 +1407,12 @@ internal_type_self_type (struct type *type) if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_NONE) return NULL; gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_SELF_TYPE); - return TYPE_MAIN_TYPE (type)->type_specific.self_type; + return type->main_type->type_specific.self_type; case TYPE_CODE_METHOD: if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_NONE) return NULL; gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_FUNC); - return TYPE_MAIN_TYPE (type)->type_specific.func_stuff->self_type; + return type->main_type->type_specific.func_stuff->self_type; default: gdb_assert_not_reached ("bad type"); } @@ -1433,13 +1433,13 @@ set_type_self_type (struct type *type, struct type *self_type) if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_NONE) TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_SELF_TYPE; gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_SELF_TYPE); - TYPE_MAIN_TYPE (type)->type_specific.self_type = self_type; + type->main_type->type_specific.self_type = self_type; break; case TYPE_CODE_METHOD: if (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_NONE) INIT_FUNC_SPECIFIC (type); gdb_assert (TYPE_SPECIFIC_FIELD (type) == TYPE_SPECIFIC_FUNC); - TYPE_MAIN_TYPE (type)->type_specific.func_stuff->self_type = self_type; + type->main_type->type_specific.func_stuff->self_type = self_type; break; default: gdb_assert_not_reached ("bad type"); @@ -2301,12 +2301,12 @@ resolve_dynamic_array_or_string (struct type *type, struct type *dynamic_array_type = type; type = copy_type (dynamic_array_type->target_type ()); struct dynamic_prop_list *prop_list - = TYPE_MAIN_TYPE (dynamic_array_type)->dyn_prop_list; + = dynamic_array_type->main_type->dyn_prop_list; if (prop_list != nullptr) { struct obstack *obstack = &type->objfile_owner ()->objfile_obstack; - TYPE_MAIN_TYPE (type)->dyn_prop_list + type->main_type->dyn_prop_list = copy_dynamic_prop_list (obstack, prop_list); } return type; @@ -3220,8 +3220,8 @@ init_integer_type (type_allocator &alloc, t->set_is_unsigned (true); TYPE_SPECIFIC_FIELD (t) = TYPE_SPECIFIC_INT; - TYPE_MAIN_TYPE (t)->type_specific.int_stuff.bit_size = bit; - TYPE_MAIN_TYPE (t)->type_specific.int_stuff.bit_offset = 0; + t->main_type->type_specific.int_stuff.bit_size = bit; + t->main_type->type_specific.int_stuff.bit_offset = 0; return t; } @@ -3254,8 +3254,8 @@ init_boolean_type (type_allocator &alloc, t->set_is_unsigned (true); TYPE_SPECIFIC_FIELD (t) = TYPE_SPECIFIC_INT; - TYPE_MAIN_TYPE (t)->type_specific.int_stuff.bit_size = bit; - TYPE_MAIN_TYPE (t)->type_specific.int_stuff.bit_offset = 0; + t->main_type->type_specific.int_stuff.bit_size = bit; + t->main_type->type_specific.int_stuff.bit_offset = 0; return t; } @@ -3310,7 +3310,7 @@ init_complex_type (const char *name, struct type *target_type) gdb_assert (can_create_complex_type (target_type)); - if (TYPE_MAIN_TYPE (target_type)->flds_bnds.complex_type == nullptr) + if (target_type->main_type->flds_bnds.complex_type == nullptr) { if (name == nullptr && target_type->name () != nullptr) { @@ -3331,10 +3331,10 @@ init_complex_type (const char *name, struct type *target_type) t->set_name (name); t->set_target_type (target_type); - TYPE_MAIN_TYPE (target_type)->flds_bnds.complex_type = t; + target_type->main_type->flds_bnds.complex_type = t; } - return TYPE_MAIN_TYPE (target_type)->flds_bnds.complex_type; + return target_type->main_type->flds_bnds.complex_type; } /* See gdbtypes.h. */ @@ -3615,7 +3615,7 @@ class_or_union_p (const struct type *t) int class_types_same_p (const struct type *a, const struct type *b) { - return (TYPE_MAIN_TYPE (a) == TYPE_MAIN_TYPE (b) + return (a->main_type == b->main_type || (a->name () && b->name () && !strcmp (a->name (), b->name ()))); } @@ -5234,7 +5234,7 @@ copy_type_recursive (struct type *type, copied_types_hash_t &copied_types) /* Copy the common fields of types. For the main type, we simply copy the entire thing and then update specific fields as needed. */ - *TYPE_MAIN_TYPE (new_type) = *TYPE_MAIN_TYPE (type); + *new_type->main_type = *type->main_type; new_type->set_owner (type->arch ()); @@ -5353,8 +5353,8 @@ copy_type_recursive (struct type *type, copied_types_hash_t &copied_types) break; case TYPE_SPECIFIC_INT: TYPE_SPECIFIC_FIELD (new_type) = TYPE_SPECIFIC_INT; - TYPE_MAIN_TYPE (new_type)->type_specific.int_stuff - = TYPE_MAIN_TYPE (type)->type_specific.int_stuff; + new_type->main_type->type_specific.int_stuff + = type->main_type->type_specific.int_stuff; break; default: @@ -5372,7 +5372,7 @@ type_allocator::copy_type (const struct type *type) struct type *new_type = this->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), + memcpy (new_type->main_type, type->main_type, sizeof (struct main_type)); /* This might have been overwritten by the memcpy. */ diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 3917b40e3660..2058f2c8bb94 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -1886,9 +1886,9 @@ extern void allocate_gnat_aux_type (struct type *); #define INIT_FUNC_SPECIFIC(type) \ (TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_FUNC, \ - TYPE_MAIN_TYPE (type)->type_specific.func_stuff = (struct func_type *) \ + (type)->main_type->type_specific.func_stuff = (struct func_type *) \ TYPE_ZALLOC (type, \ - sizeof (*TYPE_MAIN_TYPE (type)->type_specific.func_stuff))) + sizeof (*(type)->main_type->type_specific.func_stuff))) /* "struct fixed_point_type_info" has a field that has a destructor. See allocate_fixed_point_type_info to understand how this is @@ -1897,7 +1897,6 @@ extern void allocate_gnat_aux_type (struct type *); (TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_FIXED_POINT, \ allocate_fixed_point_type_info (type)) -#define TYPE_MAIN_TYPE(thistype) (thistype)->main_type #define TYPE_POINTER_TYPE(thistype) (thistype)->pointer_type #define TYPE_REFERENCE_TYPE(thistype) (thistype)->reference_type #define TYPE_RVALUE_REFERENCE_TYPE(thistype) (thistype)->rvalue_reference_type @@ -1938,7 +1937,7 @@ extern void set_type_vptr_basetype (struct type *, struct type *); #define TYPE_NFN_FIELDS(thistype) TYPE_CPLUS_SPECIFIC(thistype)->nfn_fields #define TYPE_SPECIFIC_FIELD(thistype) \ - TYPE_MAIN_TYPE(thistype)->type_specific_field + (thistype)->main_type->type_specific_field /* We need this tap-dance with the TYPE_RAW_SPECIFIC because of the case where we're trying to print an Ada array using the C language. In that case, there is no "cplus_stuff", but the C language assumes @@ -1948,15 +1947,15 @@ extern void set_type_vptr_basetype (struct type *, struct type *); (!HAVE_CPLUS_STRUCT(thistype) \ ? (struct cplus_struct_type*)&cplus_struct_default \ : TYPE_RAW_CPLUS_SPECIFIC(thistype)) -#define TYPE_RAW_CPLUS_SPECIFIC(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.cplus_stuff +#define TYPE_RAW_CPLUS_SPECIFIC(thistype) (thistype)->main_type->type_specific.cplus_stuff #define TYPE_CPLUS_CALLING_CONVENTION(thistype) \ - TYPE_MAIN_TYPE(thistype)->type_specific.cplus_stuff->calling_convention -#define TYPE_FLOATFORMAT(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.floatformat -#define TYPE_GNAT_SPECIFIC(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.gnat_stuff + (thistype)->main_type->type_specific.cplus_stuff->calling_convention +#define TYPE_FLOATFORMAT(thistype) (thistype)->main_type->type_specific.floatformat +#define TYPE_GNAT_SPECIFIC(thistype) (thistype)->main_type->type_specific.gnat_stuff #define TYPE_DESCRIPTIVE_TYPE(thistype) TYPE_GNAT_SPECIFIC(thistype)->descriptive_type -#define TYPE_CALLING_CONVENTION(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.func_stuff->calling_convention -#define TYPE_NO_RETURN(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.func_stuff->is_noreturn -#define TYPE_TAIL_CALL_LIST(thistype) TYPE_MAIN_TYPE(thistype)->type_specific.func_stuff->tail_call_list +#define TYPE_CALLING_CONVENTION(thistype) (thistype)->main_type->type_specific.func_stuff->calling_convention +#define TYPE_NO_RETURN(thistype) (thistype)->main_type->type_specific.func_stuff->is_noreturn +#define TYPE_TAIL_CALL_LIST(thistype) (thistype)->main_type->type_specific.func_stuff->tail_call_list #define TYPE_BASECLASS(thistype,index) ((thistype)->field (index).type ()) #define TYPE_N_BASECLASSES(thistype) TYPE_CPLUS_SPECIFIC(thistype)->n_baseclasses #define TYPE_BASECLASS_NAME(thistype,index) (thistype->field (index).name ()) -- 2.53.0