From: Tankut Baris Aktemur <tankutbaris.aktemur@amd.com>
To: <gdb-patches@sourceware.org>
Subject: [PATCH 07/16] gdb: convert type instance flags to bitfields
Date: Mon, 13 Jul 2026 09:00:06 -0500 [thread overview]
Message-ID: <20260713-users-aktemur-type-instance-flags-v1-7-779cad0c85ec@amd.com> (raw)
In-Reply-To: <20260713-users-aktemur-type-instance-flags-v1-0-779cad0c85ec@amd.com>
Convert the instance flags of a type to a struct with bitfields. This
helps avoid bitwise operations and instead refer to the fields by
name. In particular, Harvard address space information (i.e. code
space and data space) and address class information become enum values
instead of being handled by seemingly independent bits.
---
gdb/d-lang.c | 9 +-
gdb/expop.h | 6 ++
gdb/expprint.c | 4 +-
gdb/ft32-tdep.c | 5 +-
gdb/gdb-gdb.py.in | 99 +++++-------------
gdb/gdbtypes.c | 105 +++++++------------
gdb/gdbtypes.h | 173 ++++++++++++++++++--------------
gdb/printcmd.c | 17 ++--
gdb/testsuite/gdb.base/maint.exp | 2 +-
gdb/testsuite/gdb.gdb/python-helper.exp | 8 +-
gdb/type-stack.c | 10 +-
11 files changed, 190 insertions(+), 248 deletions(-)
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 0a779a7b7c0..c2a11375830 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -233,13 +233,8 @@ build_d_types (struct gdbarch *gdbarch)
= init_float_type (alloc, gdbarch_long_double_bit (gdbarch),
"real", gdbarch_long_double_format (gdbarch));
- builtin_d_type->builtin_byte->set_instance_flags
- (builtin_d_type->builtin_byte->instance_flags ()
- | TYPE_INSTANCE_FLAG_NOTTEXT);
-
- builtin_d_type->builtin_ubyte->set_instance_flags
- (builtin_d_type->builtin_ubyte->instance_flags ()
- | TYPE_INSTANCE_FLAG_NOTTEXT);
+ builtin_d_type->builtin_byte->set_nottext (true);
+ builtin_d_type->builtin_ubyte->set_nottext (true);
/* Imaginary and complex types. */
builtin_d_type->builtin_ifloat
diff --git a/gdb/expop.h b/gdb/expop.h
index 6d6f4acdc24..ce175afbc3d 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -275,6 +275,12 @@ check_objfile (enum_flags<T> val, struct objfile *objfile)
return false;
}
+static inline bool
+check_objfile (type_instance_flags val, struct objfile *objfile)
+{
+ return false;
+}
+
template<typename T>
static inline bool
check_objfile (const std::vector<T> &collection, struct objfile *objfile)
diff --git a/gdb/expprint.c b/gdb/expprint.c
index e99430d2325..bc1929b1a1b 100644
--- a/gdb/expprint.c
+++ b/gdb/expprint.c
@@ -148,9 +148,9 @@ dump_for_expression (struct ui_file *stream, int depth,
type_instance_flags flags)
{
gdb_printf (stream, _("%*sType flags: "), depth, "");
- if (flags & TYPE_INSTANCE_FLAG_CONST)
+ if (flags.is_const)
gdb_puts ("const ", stream);
- if (flags & TYPE_INSTANCE_FLAG_VOLATILE)
+ if (flags.is_volatile)
gdb_puts ("volatile", stream);
gdb_printf (stream, "\n");
}
diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c
index 476e79355c7..f951a6f25e3 100644
--- a/gdb/ft32-tdep.c
+++ b/gdb/ft32-tdep.c
@@ -332,7 +332,7 @@ ft32_pointer_to_address (struct gdbarch *gdbarch,
CORE_ADDR addr
= extract_unsigned_integer (buf, type->length (), byte_order);
- if (TYPE_ADDRESS_CLASS_1 (type))
+ if (TYPE_ADDRESS_CLASS (type) == 1)
return addr;
else
return addr | RAM_BIAS;
@@ -579,8 +579,7 @@ ft32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
func_void_type = lookup_function_type (void_type);
tdep->pc_type = init_pointer_type (alloc, 4 * TARGET_CHAR_BIT, NULL,
func_void_type);
- tdep->pc_type->set_instance_flags (tdep->pc_type->instance_flags ()
- | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1);
+ tdep->pc_type->set_address_class (1);
set_gdbarch_num_regs (gdbarch, FT32_NUM_REGS);
set_gdbarch_sp_regnum (gdbarch, FT32_SP_REGNUM);
diff --git a/gdb/gdb-gdb.py.in b/gdb/gdb-gdb.py.in
index 417b6492db5..7e39d27366e 100644
--- a/gdb/gdb-gdb.py.in
+++ b/gdb/gdb-gdb.py.in
@@ -20,86 +20,32 @@ import os.path
import gdb
-class TypeFlag:
- """A class that allows us to store a flag name, its short name,
- and its value.
-
- In the GDB sources, struct type has a component called instance_flags
- in which the value is the addition of various flags. These flags are
- defined by the enumerates type_instance_flag_value. This class helps us
- recreate a list with all these flags that is easy to manipulate and sort.
- Because all flag names start with TYPE_INSTANCE_FLAG_, a short_name
- attribute is provided that strips this prefix.
-
- ATTRIBUTES
- name: The enumeration name (eg: "TYPE_INSTANCE_FLAG_CONST").
- value: The associated value.
- short_name: The enumeration name, with the suffix stripped.
- """
-
- def __init__(self, name, value):
- self.name = name
- self.value = value
- self.short_name = name.replace("TYPE_INSTANCE_FLAG_", "")
-
- def __lt__(self, other):
- """Sort by value order."""
- return self.value < other.value
-
-
-# A list of all existing TYPE_INSTANCE_FLAGS_* enumerations,
-# stored as TypeFlags objects. Lazy-initialized.
-TYPE_FLAGS = None
-
-
-class TypeFlagsPrinter:
- """A class that prints a decoded form of an instance_flags value.
-
- This class uses a global named TYPE_FLAGS, which is a list of
- all defined TypeFlag values. Using a global allows us to compute
- this list only once.
-
- This class relies on a couple of enumeration types being defined.
- If not, then printing of the instance_flag is going to be degraded,
- but it's not a fatal error.
- """
+class StructTypeInstanceFlagsPrettyPrinter:
+ """Pretty-print an object of type struct type_instance_flags"""
def __init__(self, val):
self.val = val
def __str__(self):
- global TYPE_FLAGS
- if TYPE_FLAGS is None:
- self.init_TYPE_FLAGS()
- if not self.val:
- return "0"
- if TYPE_FLAGS:
- flag_list = [
- flag.short_name for flag in TYPE_FLAGS if self.val & flag.value
- ]
- else:
- flag_list = ["???"]
- return "0x%x [%s]" % (self.val, "|".join(flag_list))
-
- def init_TYPE_FLAGS(self):
- """Initialize the TYPE_FLAGS global as a list of TypeFlag objects.
- This operation requires the search of a couple of enumeration types.
- If not found, a warning is printed on stdout, and TYPE_FLAGS is
- set to the empty list.
-
- The resulting list is sorted by increasing value, to facilitate
- printing of the list of flags used in an instance_flags value.
- """
- global TYPE_FLAGS
- TYPE_FLAGS = []
- try:
- iflags = gdb.lookup_type("enum type_instance_flag_value")
- except:
- print("Warning: Cannot find enum type_instance_flag_value type.")
- print(" `struct type' pretty-printer will be degraded")
- return
- TYPE_FLAGS = [TypeFlag(field.name, field.enumval) for field in iflags.fields()]
- TYPE_FLAGS.sort()
+ fields = []
+ if self.val["is_const"]:
+ fields.append("CONST")
+ if self.val["is_volatile"]:
+ fields.append("VOLATILE")
+ if self.val["harvard_aspace"] == 1: # HARVARD_ASPACE_CODE
+ fields.append("CODE_SPACE")
+ elif self.val["harvard_aspace"] == 2: # HARVARD_ASPACE_DATA
+ fields.append("DATA_SPACE")
+ if self.val["address_class"] != 0:
+ fields.append("ADDRESS_CLASS(%d)" % self.val["address_class"])
+ if self.val["is_nottext"]:
+ fields.append("NOTTEXT")
+ if self.val["is_restrict"]:
+ fields.append("RESTRICT")
+ if self.val["is_atomic"]:
+ fields.append("ATOMIC")
+
+ return "[" + "|".join(fields) + "]"
class StructTypePrettyPrinter:
@@ -114,7 +60,8 @@ class StructTypePrettyPrinter:
fields.append("reference_type = %s" % self.val["reference_type"])
fields.append("chain = %s" % self.val["reference_type"])
fields.append(
- "instance_flags = %s" % TypeFlagsPrinter(self.val["m_instance_flags"])
+ "instance_flags = %s"
+ % StructTypeInstanceFlagsPrettyPrinter(self.val["m_instance_flags"])
)
fields.append("length = %d" % self.val["m_length"])
fields.append("main_type = %s" % self.val["main_type"])
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 205a79dfbc1..958a2ff9f29 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -603,14 +603,11 @@ struct type *
make_type_with_harvard_address_space (struct type *type,
enum harvard_address_space aspace)
{
- type_instance_flags new_flags
- = (enum type_instance_flag_value) (aspace << 2);
-
- gdb_assert ((new_flags & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
- | TYPE_INSTANCE_FLAG_DATA_SPACE)) == 0);
- new_flags |= (type->instance_flags ()
- & ~(TYPE_INSTANCE_FLAG_CODE_SPACE
- | TYPE_INSTANCE_FLAG_DATA_SPACE));
+ gdb_assert (aspace == HARVARD_ASPACE_NONE
+ || aspace == HARVARD_ASPACE_CODE
+ || aspace == HARVARD_ASPACE_DATA);
+ type_instance_flags new_flags = type->instance_flags ();
+ new_flags.harvard_aspace = aspace;
return make_qualified_type (type, new_flags, NULL);
}
@@ -625,13 +622,9 @@ struct type *
make_type_with_address_class (struct type *type,
unsigned int address_class)
{
- type_instance_flags new_flags
- = (enum type_instance_flag_value) (address_class << 4);
-
- gdb_assert ((new_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) == 0);
-
- new_flags |= (type->instance_flags ()
- & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL);
+ gdb_assert (address_class < 4); /* We use two bits for this field. */
+ type_instance_flags new_flags = type->instance_flags ();
+ new_flags.address_class = address_class;
return make_qualified_type (type, new_flags, NULL);
}
@@ -641,15 +634,9 @@ make_type_with_address_class (struct type *type,
type *
make_cv_type (int cnst, int voltl, type *type)
{
- type_instance_flags new_flags = (type->instance_flags ()
- & ~(TYPE_INSTANCE_FLAG_CONST
- | TYPE_INSTANCE_FLAG_VOLATILE));
-
- if (cnst)
- new_flags |= TYPE_INSTANCE_FLAG_CONST;
-
- if (voltl)
- new_flags |= TYPE_INSTANCE_FLAG_VOLATILE;
+ type_instance_flags new_flags = type->instance_flags ();
+ new_flags.is_const = cnst;
+ new_flags.is_volatile = voltl;
return make_qualified_type (type, new_flags, nullptr);
}
@@ -659,10 +646,10 @@ make_cv_type (int cnst, int voltl, type *type)
struct type *
make_restrict_type (struct type *type)
{
- return make_qualified_type (type,
- (type->instance_flags ()
- | TYPE_INSTANCE_FLAG_RESTRICT),
- NULL);
+ type_instance_flags new_flags = type->instance_flags ();
+ new_flags.is_restrict = true;
+
+ return make_qualified_type (type, new_flags, nullptr);
}
/* Make a type without const, volatile, or restrict. */
@@ -670,12 +657,12 @@ make_restrict_type (struct type *type)
struct type *
make_unqualified_type (struct type *type)
{
- return make_qualified_type (type,
- (type->instance_flags ()
- & ~(TYPE_INSTANCE_FLAG_CONST
- | TYPE_INSTANCE_FLAG_VOLATILE
- | TYPE_INSTANCE_FLAG_RESTRICT)),
- NULL);
+ type_instance_flags new_flags = type->instance_flags ();
+ new_flags.is_const = false;
+ new_flags.is_volatile = false;
+ new_flags.is_restrict = false;
+
+ return make_qualified_type (type, new_flags, nullptr);
}
/* Make a '_Atomic'-qualified version of TYPE. */
@@ -683,10 +670,10 @@ make_unqualified_type (struct type *type)
struct type *
make_atomic_type (struct type *type)
{
- return make_qualified_type (type,
- (type->instance_flags ()
- | TYPE_INSTANCE_FLAG_ATOMIC),
- NULL);
+ type_instance_flags new_flags = type->instance_flags ();
+ new_flags.is_atomic = true;
+
+ return make_qualified_type (type, new_flags, nullptr);
}
/* Replace the contents of ntype with the type *type. This changes the
@@ -723,7 +710,7 @@ replace_type (struct type *ntype, struct type *type)
variants. This assertion shouldn't ever be triggered because
symbol readers which do construct address-class variants don't
call replace_type(). */
- gdb_assert (TYPE_ADDRESS_CLASS_ALL (chain) == 0);
+ gdb_assert (TYPE_ADDRESS_CLASS (chain) == 0);
chain->set_length (type->length ());
chain = chain->chain;
@@ -1362,8 +1349,8 @@ make_vector_type (struct type *array_type)
elt_type = inner_array->target_type ();
if (elt_type->code () == TYPE_CODE_INT)
{
- type_instance_flags flags
- = elt_type->instance_flags () | TYPE_INSTANCE_FLAG_NOTTEXT;
+ type_instance_flags flags = elt_type->instance_flags ();
+ flags.is_nottext = true;
elt_type = make_qualified_type (elt_type, flags, NULL);
inner_array->set_target_type (elt_type);
}
@@ -3074,19 +3061,13 @@ check_typedef (struct type *type)
outer cast in a chain of casting win), instead of assuming
"it can't happen". */
{
- const type_instance_flags ALL_SPACES
- = (TYPE_INSTANCE_FLAG_CODE_SPACE
- | TYPE_INSTANCE_FLAG_DATA_SPACE);
- const type_instance_flags ALL_CLASSES
- = TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL;
-
type_instance_flags new_instance_flags = type->instance_flags ();
/* Treat code vs data spaces and address classes separately. */
- if ((instance_flags & ALL_SPACES) != 0)
- new_instance_flags &= ~ALL_SPACES;
- if ((instance_flags & ALL_CLASSES) != 0)
- new_instance_flags &= ~ALL_CLASSES;
+ if (instance_flags.harvard_aspace != HARVARD_ASPACE_NONE)
+ new_instance_flags.harvard_aspace = HARVARD_ASPACE_NONE;
+ if (instance_flags.address_class != 0)
+ new_instance_flags.address_class = 0;
instance_flags |= new_instance_flags;
}
@@ -5039,8 +5020,7 @@ recursive_dump_type (struct type *type, int spaces)
host_address_to_string (type->reference_type));
gdb_printf ("%*stype_chain %s\n", spaces, "",
host_address_to_string (type->chain));
- gdb_printf ("%*sinstance_flags 0x%x", spaces, "",
- (unsigned) type->instance_flags ());
+ gdb_printf ("%*sinstance_flags [", spaces, "");
if (TYPE_CONST (type))
{
gdb_puts (" TYPE_CONST");
@@ -5057,13 +5037,9 @@ recursive_dump_type (struct type *type, int spaces)
{
gdb_puts (" TYPE_DATA_SPACE");
}
- if (TYPE_ADDRESS_CLASS_1 (type))
+ if (TYPE_ADDRESS_CLASS (type) != 0)
{
- gdb_puts (" TYPE_ADDRESS_CLASS_1");
- }
- if (TYPE_ADDRESS_CLASS_2 (type))
- {
- gdb_puts (" TYPE_ADDRESS_CLASS_2");
+ gdb_printf (" TYPE_ADDRESS_CLASS(%u)", TYPE_ADDRESS_CLASS (type));
}
if (TYPE_RESTRICT (type))
{
@@ -5073,7 +5049,7 @@ recursive_dump_type (struct type *type, int spaces)
{
gdb_puts (" TYPE_ATOMIC");
}
- gdb_puts ("\n");
+ gdb_puts ("]\n");
gdb_printf ("%*sflags", spaces, "");
if (type->is_unsigned ())
@@ -5875,13 +5851,8 @@ create_gdbtypes_data (struct gdbarch *gdbarch)
builtin_type->builtin_uint128
= init_integer_type (alloc, 128, 1, "uint128_t");
- builtin_type->builtin_int8->set_instance_flags
- (builtin_type->builtin_int8->instance_flags ()
- | TYPE_INSTANCE_FLAG_NOTTEXT);
-
- builtin_type->builtin_uint8->set_instance_flags
- (builtin_type->builtin_uint8->instance_flags ()
- | TYPE_INSTANCE_FLAG_NOTTEXT);
+ builtin_type->builtin_int8->set_nottext (true);
+ builtin_type->builtin_uint8->set_nottext (true);
/* Wide character types. */
builtin_type->builtin_char16
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 854679141ff..19b6e6640ec 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -71,6 +71,9 @@ enum type_code
};
+/* Enums for instruction-space delimited type. See the type instance
+ flags for more details. */
+
enum harvard_address_space
{
HARVARD_ASPACE_NONE = 0,
@@ -78,51 +81,95 @@ enum harvard_address_space
HARVARD_ASPACE_DATA = 2,
};
-/* Some bits for the type's instance_flags word. See the macros
- below for documentation on each bit. */
+/* A type's instance_flags. */
-enum type_instance_flag_value : unsigned
+struct type_instance_flags
{
- TYPE_INSTANCE_FLAG_CONST = (1 << 0),
- TYPE_INSTANCE_FLAG_VOLATILE = (1 << 1),
- TYPE_INSTANCE_FLAG_CODE_SPACE = (1 << 2),
- TYPE_INSTANCE_FLAG_DATA_SPACE = (1 << 3),
- TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1 = (1 << 4),
- TYPE_INSTANCE_FLAG_ADDRESS_CLASS_2 = (1 << 5),
- TYPE_INSTANCE_FLAG_NOTTEXT = (1 << 6),
- TYPE_INSTANCE_FLAG_RESTRICT = (1 << 7),
- TYPE_INSTANCE_FLAG_ATOMIC = (1 << 8)
-};
+ bool operator== (const type_instance_flags &other) const
+ {
+ return (is_const == other.is_const
+ && is_volatile == other.is_volatile
+ && harvard_aspace == other.harvard_aspace
+ && address_class == other.address_class
+ && is_nottext == other.is_nottext
+ && is_restrict == other.is_restrict
+ && is_atomic == other.is_atomic);
+ }
+
+ bool operator!= (const type_instance_flags &other) const
+ {
+ return !(*this == other);
+ }
+
+ type_instance_flags &operator|= (const type_instance_flags &other)
+ {
+ is_const = is_const || other.is_const;
+ is_volatile = is_volatile || other.is_volatile;
+ harvard_aspace
+ = static_cast<harvard_address_space> (harvard_aspace
+ | other.harvard_aspace);
+ address_class = address_class | other.address_class;
+ is_nottext = is_nottext || other.is_nottext;
+ is_restrict = is_restrict || other.is_restrict;
+ is_atomic = is_atomic || other.is_atomic;
+ return *this;
+ }
+
+ /* Constant type. If this is set, the corresponding type has a
+ const modifier. */
+ bool is_const : 1;
-DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
+ /* Volatile type. If this is set, the corresponding type has a
+ volatile modifier. */
+ bool is_volatile : 1;
-/* Not textual. By default, GDB treats all single byte integers as
- characters (or elements of strings) unless this flag is set. */
+ /* This is for Harvard architectures which have separate instruction
+ and data address spaces (and perhaps others).
-#define TYPE_NOTTEXT(t) (((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_NOTTEXT)
+ GDB usually defines a flat address space that is a superset of
+ the architecture's two (or more) address spaces, but this is an
+ extension of the architecture's model.
-/* Constant type. If this is set, the corresponding type has a
- const modifier. */
+ If the field is set to HARVARD_ASPACE_CODE, an object of the
+ corresponding type resides in instruction memory, even if its
+ address (in the extended flat address space) does not reflect
+ this.
-#define TYPE_CONST(t) ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_CONST) != 0)
+ Similarly, if set to HARVARD_ASPACE_DATA, then an object of the
+ corresponding type resides in the data memory space, even if this
+ is not indicated by its (flat address space) address.
-/* Volatile type. If this is set, the corresponding type has a
- volatile modifier. */
+ If set to HARVARD_ASPACE_NONE, the default space for functions /
+ methods is instruction space, and for data objects is data
+ memory. */
+ harvard_address_space harvard_aspace : 2;
-#define TYPE_VOLATILE(t) \
- ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_VOLATILE) != 0)
+ /* Address class field. Some environments provide for pointers
+ whose size is different from that of a normal pointer or address
+ types where the bits are interpreted differently than normal
+ addresses. The ADDRESS_CLASS field may be used in target
+ specific ways to represent these different types of address
+ classes. */
+ unsigned int address_class : 2;
-/* Restrict type. If this is set, the corresponding type has a
- restrict modifier. */
+ /* Not textual. By default, GDB treats all single byte integers as
+ characters (or elements of strings) unless this flag is set. */
+ bool is_nottext : 1;
-#define TYPE_RESTRICT(t) \
- ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_RESTRICT) != 0)
+ /* Restrict type. If this is set, the corresponding type has a
+ restrict modifier. */
+ bool is_restrict : 1;
-/* Atomic type. If this is set, the corresponding type has an
- _Atomic modifier. */
+ /* Atomic type. If this is set, the corresponding type has an
+ _Atomic modifier. */
+ bool is_atomic : 1;
+};
-#define TYPE_ATOMIC(t) \
- ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_ATOMIC) != 0)
+#define TYPE_NOTTEXT(t) (((t)->instance_flags ()).is_nottext)
+#define TYPE_CONST(t) (((t)->instance_flags ()).is_const)
+#define TYPE_VOLATILE(t) (((t)->instance_flags ()).is_volatile)
+#define TYPE_RESTRICT(t) (((t)->instance_flags ()).is_restrict)
+#define TYPE_ATOMIC(t) (((t)->instance_flags ()).is_atomic)
/* True if this type represents either an lvalue or lvalue reference type. */
@@ -142,50 +189,14 @@ DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
(((t)->dyn_prop (DYN_PROP_BYTE_SIZE) != nullptr) \
|| ((t)->dyn_prop (DYN_PROP_BIT_SIZE) != nullptr))
-/* Instruction-space delimited type. This is for Harvard architectures
- which have separate instruction and data address spaces (and perhaps
- others).
-
- GDB usually defines a flat address space that is a superset of the
- architecture's two (or more) address spaces, but this is an extension
- of the architecture's model.
-
- If TYPE_INSTANCE_FLAG_CODE_SPACE is set, an object of the corresponding type
- resides in instruction memory, even if its address (in the extended
- flat address space) does not reflect this.
-
- Similarly, if TYPE_INSTANCE_FLAG_DATA_SPACE is set, then an object of the
- corresponding type resides in the data memory space, even if
- this is not indicated by its (flat address space) address.
-
- If neither flag is set, the default space for functions / methods
- is instruction space, and for data objects is data memory. */
-
#define TYPE_CODE_SPACE(t) \
- ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_CODE_SPACE) != 0)
+ (((t)->instance_flags ()).harvard_aspace == HARVARD_ASPACE_CODE)
#define TYPE_DATA_SPACE(t) \
- ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_DATA_SPACE) != 0)
-
-/* Address class flags. Some environments provide for pointers
- whose size is different from that of a normal pointer or address
- types where the bits are interpreted differently than normal
- addresses. The TYPE_INSTANCE_FLAG_ADDRESS_CLASS_n flags may be used in
- target specific ways to represent these different types of address
- classes. */
-
-#define TYPE_ADDRESS_CLASS_1(t) (((t)->instance_flags ()) \
- & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1)
-#define TYPE_ADDRESS_CLASS_2(t) (((t)->instance_flags ()) \
- & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_2)
-#define TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL \
- (TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1 | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_2)
-#define TYPE_ADDRESS_CLASS_ALL(t) (((t)->instance_flags ()) \
- & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
-#define TYPE_ADDRESS_CLASS_FROM_INSTANCE_FLAGS(t) \
- ((unsigned int) ((t) & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) >> 4)
+ (((t)->instance_flags ()).harvard_aspace == HARVARD_ASPACE_DATA)
+
#define TYPE_ADDRESS_CLASS(t) \
- (TYPE_ADDRESS_CLASS_FROM_INSTANCE_FLAGS ((t)->instance_flags ()))
+ (((t)->instance_flags ()).address_class)
/* Information about a single discriminant. */
@@ -1163,10 +1174,10 @@ struct type
this->field (0).set_type (index_type);
}
- /* Return the instance flags converted to the correct type. */
+ /* Return the instance flags. */
const type_instance_flags instance_flags () const
{
- return (enum type_instance_flag_value) this->m_instance_flags;
+ return this->m_instance_flags;
}
/* Set the instance flags. */
@@ -1175,6 +1186,18 @@ struct type
this->m_instance_flags = flags;
}
+ /* Set the address class id. */
+ void set_address_class (unsigned int address_class)
+ {
+ this->m_instance_flags.address_class = address_class;
+ }
+
+ /* Set the is_nottext flag. */
+ void set_nottext (bool flag)
+ {
+ this->m_instance_flags.is_nottext = flag;
+ }
+
/* Get the bounds bounds of this type. The type must be a range type. */
range_bounds *bounds () const
{
@@ -1593,7 +1616,7 @@ struct type
instance flags are completely inherited from the target type. No
qualifiers can be cleared by the typedef. See also
check_typedef. */
- unsigned m_instance_flags : 9;
+ type_instance_flags m_instance_flags;
/* Length of storage for a value of this type. The value is the
expression in host bytes of what sizeof(type) would return. This
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 3f6cfa9dde3..2b86b89e6be 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1056,17 +1056,12 @@ format_to_type (format_data fmt, gdbarch *gdbarch, type_instance_flags flags)
gdb_assert (val_type != nullptr);
- if ((flags & TYPE_INSTANCE_FLAG_CODE_SPACE) != 0)
+ if (flags.harvard_aspace != HARVARD_ASPACE_NONE)
val_type = make_type_with_harvard_address_space (val_type,
- HARVARD_ASPACE_CODE);
- else if ((flags & TYPE_INSTANCE_FLAG_DATA_SPACE) != 0)
- val_type = make_type_with_harvard_address_space (val_type,
- HARVARD_ASPACE_DATA);
+ flags.harvard_aspace);
- unsigned int aclass
- = (unsigned int) (flags & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) >> 4;
- if (aclass != 0)
- val_type = make_type_with_address_class (val_type, aclass);
+ if (flags.address_class != 0)
+ val_type = make_type_with_address_class (val_type, flags.address_class);
return val_type;
}
@@ -1899,7 +1894,7 @@ x_command (const char *exp, int from_tty)
else
next_address = value_as_address (val);
- type_instance_flags flags = 0;
+ type_instance_flags flags {};
if (val->type ()->is_pointer_or_reference ())
flags = val->type ()->target_type ()->instance_flags ();
@@ -2186,7 +2181,7 @@ do_one_display (struct display *d)
if (d->format.format == 'i')
addr = gdbarch_addr_bits_remove (d->exp->gdbarch, addr);
- type_instance_flags flags = 0;
+ type_instance_flags flags {};
if (val->type ()->is_pointer_or_reference ())
flags = val->type ()->target_type ()->instance_flags ();
diff --git a/gdb/testsuite/gdb.base/maint.exp b/gdb/testsuite/gdb.base/maint.exp
index 0099eb672dc..f0c183c8c41 100644
--- a/gdb/testsuite/gdb.base/maint.exp
+++ b/gdb/testsuite/gdb.base/maint.exp
@@ -280,7 +280,7 @@ foreach { test_name command } $test_list {
set msg "maint print type"
gdb_test_multiple "maint print type argc" $msg {
- -re "type node $hex\r\nname .int. \\($hex\\)\r\ncode $hex \\(TYPE_CODE_INT\\)\r\nlength \[24\]\r\nobjfile $hex\r\ntarget_type $hex\r\npointer_type $hex\r\nreference_type $hex\r\ntype_chain $hex\r\ninstance_flags $hex\r\nflags\r\nnfields 0 $hex\r\n$gdb_prompt $" {
+ -re "type node $hex\r\nname .int. \\($hex\\)\r\ncode $hex \\(TYPE_CODE_INT\\)\r\nlength \[24\]\r\nobjfile $hex\r\ntarget_type $hex\r\npointer_type $hex\r\nreference_type $hex\r\ntype_chain $hex\r\ninstance_flags \\\[\\\]\r\nflags\r\nnfields 0 $hex\r\n$gdb_prompt $" {
pass $msg
}
}
diff --git a/gdb/testsuite/gdb.gdb/python-helper.exp b/gdb/testsuite/gdb.gdb/python-helper.exp
index e700deda16d..d1cca48cbb8 100644
--- a/gdb/testsuite/gdb.gdb/python-helper.exp
+++ b/gdb/testsuite/gdb.gdb/python-helper.exp
@@ -151,7 +151,7 @@ proc test_python_helper {} {
"\{pointer_type = 0x0," \
" reference_type = 0x0," \
" chain = 0x0," \
- " instance_flags = 0," \
+ " instance_flags = \\\[\\\]," \
" length = $decimal," \
" main_type = $hex\}"]
gdb_test -prompt $outer_prompt_re "print *val->m_type" $answer "pretty print type"
@@ -166,6 +166,12 @@ proc test_python_helper {} {
" int_stuff = \{ bit_size = $decimal, bit_offset = $decimal \}\}"]
gdb_test -prompt $outer_prompt_re "print *val->m_type->main_type" $answer "pretty print type->main_type"
+ # Test printing instance flags using an artificial type.
+ set answer [string_to_regexp {instance_flags = [VOLATILE|DATA_SPACE|ADDRESS_CLASS(3)]}]
+ gdb_test -prompt $outer_prompt_re \
+ "print *make_type_with_harvard_address_space (make_cv_type (0, 1, make_type_with_address_class (val->m_type, 3)), 2)" \
+ "${answer}.*" "pretty print type instance flags"
+
# Send the continue to the outer GDB, which resumes the inner GDB,
# we then detect the prompt from the inner GDB, hence the use of
# -i here.
diff --git a/gdb/type-stack.c b/gdb/type-stack.c
index f49e6d05e10..50912d110f6 100644
--- a/gdb/type-stack.c
+++ b/gdb/type-stack.c
@@ -101,7 +101,7 @@ type_stack::insert (struct gdbarch *gdbarch, const char *string)
type_instance_flags
type_stack::follow_type_instance_flags ()
{
- type_instance_flags flags = 0;
+ type_instance_flags flags {};
for (;;)
switch (pop ())
@@ -109,16 +109,16 @@ type_stack::follow_type_instance_flags ()
case tp_end:
return flags;
case tp_const:
- flags |= TYPE_INSTANCE_FLAG_CONST;
+ flags.is_const = true;
break;
case tp_volatile:
- flags |= TYPE_INSTANCE_FLAG_VOLATILE;
+ flags.is_volatile = true;
break;
case tp_atomic:
- flags |= TYPE_INSTANCE_FLAG_ATOMIC;
+ flags.is_atomic = true;
break;
case tp_restrict:
- flags |= TYPE_INSTANCE_FLAG_RESTRICT;
+ flags.is_restrict = true;
break;
default:
gdb_assert_not_reached ("unrecognized tp_ value in follow_types");
--
2.34.1
next prev parent reply other threads:[~2026-07-13 14:03 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-13 13:59 [PATCH 00/16] Rewrite type instance flags as a struct with bitfields Tankut Baris Aktemur
2026-07-13 14:00 ` [PATCH 01/16] gdb: use type instance macros to query const, volatile, restrict Tankut Baris Aktemur
2026-07-21 17:52 ` Tom Tromey
2026-07-13 14:00 ` [PATCH 02/16] gdb: convert address_class_type_flags_to_name to address_class_id_to_name Tankut Baris Aktemur
2026-07-21 18:03 ` Tom Tromey
2026-07-13 14:00 ` [PATCH 03/16] gdb: convert address_class_name_to_type_flags to address_class_name_to_id Tankut Baris Aktemur
2026-07-21 18:10 ` Tom Tromey
2026-07-13 14:00 ` [PATCH 04/16] gdb: convert address_class_type_flags to address_class_dwarf_to_id Tankut Baris Aktemur
2026-07-21 18:19 ` Tom Tromey
2026-07-13 14:00 ` [PATCH 05/16] gdb: inline address_space_{name, type_instance_flags}_to_{type_instance_flags, name} Tankut Baris Aktemur
2026-07-21 18:29 ` Tom Tromey
2026-07-22 10:29 ` Aktemur, Baris
2026-07-22 13:38 ` Tom Tromey
2026-07-13 14:00 ` [PATCH 06/16] gdb: split make_type_with_address_space Tankut Baris Aktemur
2026-07-21 18:49 ` Tom Tromey
2026-07-13 14:00 ` Tankut Baris Aktemur [this message]
2026-07-21 19:13 ` [PATCH 07/16] gdb: convert type instance flags to bitfields Tom Tromey
2026-07-22 10:29 ` Aktemur, Baris
2026-07-13 14:00 ` [PATCH 08/16] gdb: convert TYPE_NOTTEXT macro to type::is_nottext Tankut Baris Aktemur
2026-07-21 18:39 ` Tom Tromey
2026-07-13 14:00 ` [PATCH 09/16] gdb: convert TYPE_CONST macro to type::is_const Tankut Baris Aktemur
2026-07-21 18:40 ` Tom Tromey
2026-07-13 14:00 ` [PATCH 10/16] gdb: convert TYPE_VOLATILE macro to type::is_volatile Tankut Baris Aktemur
2026-07-13 14:00 ` [PATCH 11/16] gdb: convert TYPE_CODE_SPACE macro to type::is_code_space Tankut Baris Aktemur
2026-07-13 14:00 ` [PATCH 12/16] gdb: convert TYPE_DATA_SPACE macro to type::is_data_space Tankut Baris Aktemur
2026-07-13 14:00 ` [PATCH 13/16] gdb: convert TYPE_RESTRICT macro to type::is_restrict Tankut Baris Aktemur
2026-07-13 14:00 ` [PATCH 14/16] gdb: convert TYPE_ATOMIC macro to type::is_atomic Tankut Baris Aktemur
2026-07-13 14:00 ` [PATCH 15/16] gdb: convert TYPE_ADDRESS_CLASS macro to type::address_class Tankut Baris Aktemur
2026-07-13 14:00 ` [PATCH 16/16] gdb: remove unnecessary braces in recursive_dump_type Tankut Baris Aktemur
2026-07-21 18:45 ` 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=20260713-users-aktemur-type-instance-flags-v1-7-779cad0c85ec@amd.com \
--to=tankutbaris.aktemur@amd.com \
--cc=gdb-patches@sourceware.org \
/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