]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: convert type instance flags to bitfields
authorTankut Baris Aktemur <tankutbaris.aktemur@amd.com>
Thu, 23 Jul 2026 10:04:42 +0000 (05:04 -0500)
committerTankut Baris Aktemur <tankutbaris.aktemur@amd.com>
Thu, 23 Jul 2026 10:10:06 +0000 (05:10 -0500)
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.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/d-lang.c
gdb/expop.h
gdb/expprint.c
gdb/ft32-tdep.c
gdb/gdb-gdb.py.in
gdb/gdbtypes.c
gdb/gdbtypes.h
gdb/printcmd.c
gdb/testsuite/gdb.base/maint.exp
gdb/testsuite/gdb.gdb/python-helper.exp
gdb/type-stack.c

index 0a779a7b7c01d3de3332aec1cee7fe75836b17b5..c2a1137583040399dec79394ae24db1f5818a663 100644 (file)
@@ -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
index 6d6f4acdc2498177d1a6787b9fd473bdbc026d7f..ce175afbc3d957884b3d097454c485aaf7a5009d 100644 (file)
@@ -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)
index e99430d2325d1f1f042750a910e9e280723ebd51..bc1929b1a1b5f18b0969d73567179600f367cca8 100644 (file)
@@ -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");
 }
index 476e79355c7ca4b48998c4f7a2bf83e79c36bae2..f951a6f25e351a38e8712261771df4550fdf852b 100644 (file)
@@ -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);
index 417b6492db5a7fe256231c2ebe0af5f48bd3ad0f..7e39d27366eae6612c6035408ca4f887a59dbae9 100644 (file)
@@ -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"])
index aa80dfb51c0b0e4c260b394642a62abc3eeba425..a866f36d1ea5c77b5e669ccc106808bbe6deb0ba 100644 (file)
@@ -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, nullptr);
 }
@@ -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, nullptr);
 }
@@ -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
index 1749c3ba741f1c1710427f7f1e122f23648d22a1..11a08428bafcc8c8449cb3908f562e52883bc6be 100644 (file)
@@ -99,51 +99,80 @@ 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);
+  }
 
-DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
+  bool operator!= (const type_instance_flags &other) const
+  {
+    return !(*this == other);
+  }
 
-/* Not textual.  By default, GDB treats all single byte integers as
-   characters (or elements of strings) unless this flag is set.  */
+  type_instance_flags &operator|= (const type_instance_flags &other)
+  {
+    is_const = is_const || other.is_const;
+    is_volatile = is_volatile || other.is_volatile;
+
+    gdb_assert (harvard_aspace == 0);
+    harvard_aspace = other.harvard_aspace;
 
-#define TYPE_NOTTEXT(t)        (((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_NOTTEXT)
+    gdb_assert (address_class == 0);
+    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.  */
+  /* Constant type.  If this is set, the corresponding type has a
+     const modifier.  */
+  bool is_const : 1;
 
-#define TYPE_CONST(t) ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_CONST) != 0)
+  /* Volatile type.  If this is set, the corresponding type has a
+     volatile modifier.  */
+  bool is_volatile : 1;
 
-/* Volatile type.  If this is set, the corresponding type has a
-   volatile modifier.  */
+  /* See enum harvard_address_space above.  */
+  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.  */
 
@@ -163,33 +192,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))
 
-/* See enum harvard_address_space above.  */
-
 #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.  */
 
@@ -1167,10 +1177,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.  */
@@ -1179,6 +1189,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
   {
@@ -1597,7 +1619,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
index b79dbe24c17074f87809da80712d0e22edbbd871..c9e6e4886e34eccd2781606a764baf2aeb528b55 100644 (file)
@@ -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 ();
 
index 0099eb672dcbd4c2152018743df54d7fcc3a75cc..f0c183c8c417340cff547115fbc08f1ba2a3811d 100644 (file)
@@ -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
     }
 }
index e700deda16d9ecad787b811fcbc27a2ae3154405..d1cca48cbb8ca021d2a31abfdf8e0d519b17248a 100644 (file)
@@ -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.
index c5ff1d718c4dae2878812097756ce89b7d800908..476848fcad14793ddbdb11a06f7691350097957d 100644 (file)
@@ -82,7 +82,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 ())
@@ -90,16 +90,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");