From: Simon Marchi Date: Mon, 16 Mar 2026 14:25:19 +0000 (-0400) Subject: gdb: remove TYPE_MAIN_TYPE X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=792a48cefc4fbc58bdde4630693ce259ed3b3dd4;p=thirdparty%2Fbinutils-gdb.git gdb: remove TYPE_MAIN_TYPE 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 Approved-By: Andrew Burgess --- diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 5611e61ee25..4ab2e4d19a8 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -8567,8 +8567,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 273d3d942b5..a493a46dcfc 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 29c601ef2c3..8b87d58dd9c 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -13348,8 +13348,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 c47ac2614c5..32b07f91883 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 0ad06f56c30..896b3afe66a 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 () != nullptr && b->name () != nullptr && streq (a->name (), b->name ()))); @@ -5236,7 +5236,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 ()); @@ -5355,8 +5355,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: @@ -5374,7 +5374,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 3917b40e366..2058f2c8bb9 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 ())