From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 2/6] gdb: remove TYPE_MAIN_TYPE
Date: Mon, 16 Mar 2026 10:25:19 -0400 [thread overview]
Message-ID: <20260316142645.26877-3-simon.marchi@efficios.com> (raw)
In-Reply-To: <20260316142645.26877-1-simon.marchi@efficios.com>
From: Simon Marchi <simon.marchi@polymtl.ca>
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
next prev parent reply other threads:[~2026-03-16 14:27 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-16 14:25 [PATCH 0/6] Remove some trivial TYPE_* macros Simon Marchi
2026-03-16 14:25 ` [PATCH 1/6] gdb: remove INIT_NONE_SPECIFIC Simon Marchi
2026-03-16 14:25 ` Simon Marchi [this message]
2026-03-16 14:25 ` [PATCH 3/6] gdb: remove TYPE_POINTER_TYPE Simon Marchi
2026-03-16 14:25 ` [PATCH 4/6] gdb: remove TYPE_REFERENCE_TYPE Simon Marchi
2026-03-16 14:25 ` [PATCH 5/6] gdb: remove TYPE_RVALUE_REFERENCE_TYPE Simon Marchi
2026-03-16 14:25 ` [PATCH 6/6] gdb: remove TYPE_CHAIN Simon Marchi
2026-03-16 17:16 ` [PATCH 0/6] Remove some trivial TYPE_* macros Andrew Burgess
2026-03-16 17:28 ` Simon Marchi
2026-03-19 14:34 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260316142645.26877-3-simon.marchi@efficios.com \
--to=simon.marchi@efficios.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@polymtl.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox