[gdb/testsuite] Fix gdb.base/coredump-filter-build-id.exp with older eu-unstrip
[deliverable/binutils-gdb.git] / gdb / gdbtypes.c
index a4ae0d7a1a61911fb311beb633d742659b88d0dc..1b54a2310213fed797561841fda1c205adb40b39 100644 (file)
@@ -227,29 +227,28 @@ struct type *
 alloc_type_copy (const struct type *type)
 {
   if (type->is_objfile_owned ())
-    return alloc_type (type->objfile ());
+    return alloc_type (type->objfile_owner ());
   else
-    return alloc_type_arch (type->arch ());
+    return alloc_type_arch (type->arch_owner ());
 }
 
-/* If TYPE is gdbarch-associated, return that architecture.
-   If TYPE is objfile-associated, return that objfile's architecture.  */
+/* See gdbtypes.h.  */
 
-struct gdbarch *
-get_type_arch (const struct type *type)
+gdbarch *
+type::arch () const
 {
   struct gdbarch *arch;
 
-  if (type->is_objfile_owned ())
-    arch = type->objfile ()->arch ();
+  if (this->is_objfile_owned ())
+    arch = this->objfile_owner ()->arch ();
   else
-    arch = type->arch ();
+    arch = this->arch_owner ();
 
   /* The ARCH can be NULL if TYPE is associated with neither an objfile nor
      a gdbarch, however, this is very rare, and even then, in most cases
-     that get_type_arch is called, we assume that a non-NULL value is
+     that type::arch is called, we assume that a non-NULL value is
      returned.  */
-  gdb_assert (arch != NULL);
+  gdb_assert (arch != nullptr);
   return arch;
 }
 
@@ -273,8 +272,7 @@ get_target_type (struct type *type)
 unsigned int
 type_length_units (struct type *type)
 {
-  struct gdbarch *arch = get_type_arch (type);
-  int unit_size = gdbarch_addressable_memory_unit_size (arch);
+  int unit_size = gdbarch_addressable_memory_unit_size (type->arch ());
 
   return TYPE_LENGTH (type) / unit_size;
 }
@@ -291,9 +289,9 @@ alloc_type_instance (struct type *oldtype)
   /* Allocate the structure.  */
 
   if (!oldtype->is_objfile_owned ())
-    type = GDBARCH_OBSTACK_ZALLOC (get_type_arch (oldtype), struct type);
+    type = GDBARCH_OBSTACK_ZALLOC (oldtype->arch_owner (), struct type);
   else
-    type = OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype)->objfile_obstack,
+    type = OBSTACK_ZALLOC (&oldtype->objfile_owner ()->objfile_obstack,
                           struct type);
 
   TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
@@ -310,8 +308,8 @@ static void
 smash_type (struct type *type)
 {
   bool objfile_owned = type->is_objfile_owned ();
-  objfile *objfile = type->objfile ();
-  gdbarch *arch = type->arch ();
+  objfile *objfile = type->objfile_owner ();
+  gdbarch *arch = type->arch_owner ();
 
   memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
 
@@ -371,8 +369,7 @@ make_pointer_type (struct type *type, struct type **typeptr)
 
   /* FIXME!  Assumes the machine has only one representation for pointers!  */
 
-  TYPE_LENGTH (ntype)
-    = gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
+  TYPE_LENGTH (ntype) = gdbarch_ptr_bit (type->arch ()) / TARGET_CHAR_BIT;
   ntype->set_code (TYPE_CODE_PTR);
 
   /* Mark pointers as unsigned.  The target converts between pointers
@@ -455,8 +452,7 @@ make_reference_type (struct type *type, struct type **typeptr,
      references, and that it matches the (only) representation for
      pointers!  */
 
-  TYPE_LENGTH (ntype) =
-    gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
+  TYPE_LENGTH (ntype) = gdbarch_ptr_bit (type->arch ()) / TARGET_CHAR_BIT;
   ntype->set_code (refcode);
 
   *reftype = ntype;
@@ -648,7 +644,7 @@ make_qualified_type (struct type *type, type_instance_flags new_flags,
         as TYPE.  Otherwise, we can't link it into TYPE's cv chain:
         if one objfile is freed and the other kept, we'd have
         dangling pointers.  */
-      gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (storage));
+      gdb_assert (type->objfile_owner () == storage->objfile_owner ());
 
       ntype = storage;
       TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
@@ -738,7 +734,7 @@ make_cv_type (int cnst, int voltl,
         can't have inter-objfile pointers.  The only thing to do is
         to leave stub types as stub types, and look them up afresh by
         name each time you encounter them.  */
-      gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type));
+      gdb_assert ((*typeptr)->objfile_owner () == type->objfile_owner ());
     }
   
   ntype = make_qualified_type (type, new_flags, 
@@ -804,7 +800,7 @@ replace_type (struct type *ntype, struct type *type)
      the assignment of one type's main type structure to the other
      will produce a type with references to objects (names; field
      lists; etc.) allocated on an objfile other than its own.  */
-  gdb_assert (TYPE_OBJFILE (ntype) == TYPE_OBJFILE (type));
+  gdb_assert (ntype->objfile_owner () == type->objfile_owner ());
 
   *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
 
@@ -1430,9 +1426,9 @@ lookup_array_range_type (struct type *element_type,
   struct type *range_type;
 
   if (element_type->is_objfile_owned ())
-    index_type = objfile_type (element_type->objfile ())->builtin_int;
+    index_type = objfile_type (element_type->objfile_owner ())->builtin_int;
   else
-    index_type = builtin_type (element_type->arch ())->builtin_int;
+    index_type = builtin_type (element_type->arch_owner ())->builtin_int;
 
   range_type = create_static_range_type (NULL, index_type,
                                         low_bound, high_bound);
@@ -1617,8 +1613,7 @@ smash_to_memberptr_type (struct type *type, struct type *self_type,
   set_type_self_type (type, self_type);
   /* Assume that a data member pointer is the same size as a normal
      pointer.  */
-  TYPE_LENGTH (type)
-    = gdbarch_ptr_bit (get_type_arch (to_type)) / TARGET_CHAR_BIT;
+  TYPE_LENGTH (type) = gdbarch_ptr_bit (to_type->arch ()) / TARGET_CHAR_BIT;
 }
 
 /* Smash TYPE to be a type of pointer to methods type TO_TYPE.
@@ -1681,7 +1676,7 @@ type_name_or_error (struct type *type)
     return name;
 
   name = saved_type->name ();
-  objfile = TYPE_OBJFILE (saved_type);
+  objfile = saved_type->objfile_owner ();
   error (_("Invalid anonymous type %s [in module %s], GCC PR debug/47510 bug?"),
         name ? name : "<anonymous>",
         objfile ? objfile_name (objfile) : "<arch>");
@@ -2027,7 +2022,7 @@ get_vptr_fieldno (struct type *type, struct type **basetypep)
            {
              /* If the type comes from a different objfile we can't cache
                 it, it may have a different lifetime.  PR 2384 */
-             if (TYPE_OBJFILE (type) == TYPE_OBJFILE (basetype))
+             if (type->objfile_owner () == basetype->objfile_owner ())
                {
                  set_type_vptr_fieldno (type, fieldno);
                  set_type_vptr_basetype (type, basetype);
@@ -2228,7 +2223,7 @@ resolve_dynamic_range (struct type *dyn_range_type,
         I really don't think this is going to work with current GDB, the
         array indexing code in GDB seems to be pretty heavily tied to byte
         offsets right now.  Assuming 8 bits in a byte.  */
-      struct gdbarch *gdbarch = get_type_arch (dyn_range_type);
+      struct gdbarch *gdbarch = dyn_range_type->arch ();
       int unit_size = gdbarch_addressable_memory_unit_size (gdbarch);
       if (!byte_stride_p && (value % (unit_size * 8)) != 0)
        error (_("bit strides that are not a multiple of the byte size "
@@ -2550,7 +2545,6 @@ resolve_dynamic_struct (struct type *type,
   unsigned resolved_type_bit_length = 0;
 
   gdb_assert (type->code () == TYPE_CODE_STRUCT);
-  gdb_assert (type->num_fields () > 0);
 
   resolved_type = copy_type (type);
 
@@ -2569,9 +2563,10 @@ resolve_dynamic_struct (struct type *type,
        ((struct field *)
         TYPE_ALLOC (resolved_type,
                     resolved_type->num_fields () * sizeof (struct field)));
-      memcpy (resolved_type->fields (),
-             type->fields (),
-             resolved_type->num_fields () * sizeof (struct field));
+      if (type->num_fields () > 0)
+       memcpy (resolved_type->fields (),
+               type->fields (),
+               resolved_type->num_fields () * sizeof (struct field));
     }
 
   for (i = 0; i < resolved_type->num_fields (); ++i)
@@ -2800,7 +2795,7 @@ type::add_dyn_prop (dynamic_prop_node_kind prop_kind, dynamic_prop prop)
 
   gdb_assert (this->is_objfile_owned ());
 
-  temp = XOBNEW (&TYPE_OBJFILE (this)->objfile_obstack,
+  temp = XOBNEW (&this->objfile_owner ()->objfile_obstack,
                 struct dynamic_prop_list);
   temp->prop_kind = prop_kind;
   temp->prop = prop;
@@ -2903,7 +2898,7 @@ check_typedef (struct type *type)
          if (sym)
            TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
          else                                  /* TYPE_CODE_UNDEF */
-           TYPE_TARGET_TYPE (type) = alloc_type_arch (get_type_arch (type));
+           TYPE_TARGET_TYPE (type) = alloc_type_arch (type->arch ());
        }
       type = TYPE_TARGET_TYPE (type);
 
@@ -2969,7 +2964,7 @@ check_typedef (struct type *type)
             TYPE's objfile is pointless, too, since you'll have to
             move over any other types NEWTYPE refers to, which could
             be an unbounded amount of stuff.  */
-         if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type))
+         if (newtype->objfile_owner () == type->objfile_owner ())
            type = make_qualified_type (newtype, type->instance_flags (), type);
          else
            type = newtype;
@@ -2995,7 +2990,7 @@ check_typedef (struct type *type)
          /* Same as above for opaque types, we can replace the stub
             with the complete type only if they are in the same
             objfile.  */
-         if (TYPE_OBJFILE (SYMBOL_TYPE (sym)) == TYPE_OBJFILE (type))
+         if (SYMBOL_TYPE (sym)->objfile_owner () == type->objfile_owner ())
            type = make_qualified_type (SYMBOL_TYPE (sym),
                                        type->instance_flags (), type);
          else
@@ -3071,7 +3066,7 @@ safe_parse_type (struct gdbarch *gdbarch, const char *p, int length)
 static void
 check_stub_method (struct type *type, int method_id, int signature_id)
 {
-  struct gdbarch *gdbarch = get_type_arch (type);
+  struct gdbarch *gdbarch = type->arch ();
   struct fn_field *f;
   char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
   char *demangled_name = gdb_demangle (mangled_name,
@@ -3418,6 +3413,15 @@ init_decfloat_type (struct objfile *objfile, int bit, const char *name)
   return t;
 }
 
+/* Return true if init_complex_type can be called with TARGET_TYPE.  */
+
+bool
+can_create_complex_type (struct type *target_type)
+{
+  return (target_type->code () == TYPE_CODE_INT
+         || target_type->code () == TYPE_CODE_FLT);
+}
+
 /* Allocate a TYPE_CODE_COMPLEX type structure.  NAME is the type
    name.  TARGET_TYPE is the component type.  */
 
@@ -3426,8 +3430,7 @@ init_complex_type (const char *name, struct type *target_type)
 {
   struct type *t;
 
-  gdb_assert (target_type->code () == TYPE_CODE_INT
-             || target_type->code () == TYPE_CODE_FLT);
+  gdb_assert (can_create_complex_type (target_type));
 
   if (TYPE_MAIN_TYPE (target_type)->flds_bnds.complex_type == nullptr)
     {
@@ -3510,8 +3513,7 @@ type_align (struct type *type)
     return raw_align;
 
   /* Allow the architecture to provide an alignment.  */
-  struct gdbarch *arch = get_type_arch (type);
-  ULONGEST align = gdbarch_type_align (arch, type);
+  ULONGEST align = gdbarch_type_align (type->arch (), type);
   if (align != 0)
     return align;
 
@@ -3878,7 +3880,7 @@ is_unique_ancestor (struct type *base, struct value *val)
 enum bfd_endian
 type_byte_order (const struct type *type)
 {
-  bfd_endian byteorder = gdbarch_byte_order (get_type_arch (type));
+  bfd_endian byteorder = gdbarch_byte_order (type->arch ());
   if (type->endianity_is_not_default ())
     {
       if (byteorder == BFD_ENDIAN_BIG)
@@ -4073,6 +4075,10 @@ types_equal (struct type *a, struct type *b)
   if (b->code () == TYPE_CODE_TYPEDEF)
     b = check_typedef (b);
 
+  /* Check if identical after resolving typedefs.  */
+  if (a == b)
+    return true;
+
   /* If after resolving typedefs a and b are not of the same type
      code then they are not equal.  */
   if (a->code () != b->code ())
@@ -4095,10 +4101,6 @@ types_equal (struct type *a, struct type *b)
       && strcmp (a->name (), b->name ()) == 0)
     return true;
 
-  /* Check if identical after resolving typedefs.  */
-  if (a == b)
-    return true;
-
   /* Two function types are equal if their argument and return types
      are equal.  */
   if (a->code () == TYPE_CODE_FUNC)
@@ -4505,7 +4507,7 @@ rank_one_type_parm_int (struct type *parm, struct type *arg, struct value *value
     case TYPE_CODE_CHAR:
     case TYPE_CODE_RANGE:
     case TYPE_CODE_BOOL:
-      if (TYPE_DECLARED_CLASS (arg))
+      if (arg->is_declared_class ())
        return INCOMPATIBLE_TYPE_BADNESS;
       return INTEGER_PROMOTION_BADNESS;
     case TYPE_CODE_FLT:
@@ -4529,7 +4531,7 @@ rank_one_type_parm_enum (struct type *parm, struct type *arg, struct value *valu
     case TYPE_CODE_RANGE:
     case TYPE_CODE_BOOL:
     case TYPE_CODE_ENUM:
-      if (TYPE_DECLARED_CLASS (parm) || TYPE_DECLARED_CLASS (arg))
+      if (parm->is_declared_class () || arg->is_declared_class ())
        return INCOMPATIBLE_TYPE_BADNESS;
       return INTEGER_CONVERSION_BADNESS;
     case TYPE_CODE_FLT:
@@ -4549,7 +4551,7 @@ rank_one_type_parm_char (struct type *parm, struct type *arg, struct value *valu
     case TYPE_CODE_RANGE:
     case TYPE_CODE_BOOL:
     case TYPE_CODE_ENUM:
-      if (TYPE_DECLARED_CLASS (arg))
+      if (arg->is_declared_class ())
        return INCOMPATIBLE_TYPE_BADNESS;
       return INTEGER_CONVERSION_BADNESS;
     case TYPE_CODE_FLT:
@@ -4790,11 +4792,13 @@ rank_one_type (struct type *parm, struct type *arg, struct value *value)
     return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL),
                       REFERENCE_SEE_THROUGH_BADNESS));
   if (overload_debug)
-  /* Debugging only.  */
-    fprintf_filtered (gdb_stderr,
-                     "------ Arg is %s [%d], parm is %s [%d]\n",
-                     arg->name (), arg->code (),
-                     parm->name (), parm->code ());
+    {
+      /* Debugging only.  */
+      fprintf_filtered (gdb_stderr,
+                       "------ Arg is %s [%d], parm is %s [%d]\n",
+                       arg->name (), arg->code (),
+                       parm->name (), parm->code ());
+    }
 
   /* x -> y means arg of type x being supplied for parameter of type y.  */
 
@@ -5192,12 +5196,12 @@ recursive_dump_type (struct type *type, int spaces)
   if (type->is_objfile_owned ())
     {
       printf_filtered ("%*sobjfile ", spaces, "");
-      gdb_print_host_address (type->objfile (), gdb_stdout);
+      gdb_print_host_address (type->objfile_owner (), gdb_stdout);
     }
   else
     {
       printf_filtered ("%*sgdbarch ", spaces, "");
-      gdb_print_host_address (type->arch (), gdb_stdout);
+      gdb_print_host_address (type->arch_owner (), gdb_stdout);
     }
   printf_filtered ("\n");
   printf_filtered ("%*starget_type ", spaces, "");
@@ -5497,7 +5501,7 @@ copy_type_recursive (struct objfile *objfile,
 
   /* This type shouldn't be pointing to any types in other objfiles;
      if it did, the type might disappear unexpectedly.  */
-  gdb_assert (TYPE_OBJFILE (type) == objfile);
+  gdb_assert (type->objfile_owner () == objfile);
 
   struct type_pair pair (type, nullptr);
 
@@ -5505,7 +5509,7 @@ copy_type_recursive (struct objfile *objfile,
   if (*slot != NULL)
     return ((struct type_pair *) *slot)->newobj;
 
-  new_type = alloc_type_arch (get_type_arch (type));
+  new_type = alloc_type_arch (type->arch ());
 
   /* We must add the new type to the hash table immediately, in case
      we encounter this type again during a recursive call below.  */
@@ -5667,7 +5671,7 @@ copy_type (const struct type *type)
          sizeof (struct main_type));
   if (type->main_type->dyn_prop_list != NULL)
     new_type->main_type->dyn_prop_list
-      = copy_dynamic_prop_list (&TYPE_OBJFILE (type) -> objfile_obstack,
+      = copy_dynamic_prop_list (&type->objfile_owner ()->objfile_obstack,
                                type->main_type->dyn_prop_list);
 
   return new_type;
@@ -5844,10 +5848,8 @@ append_flags_type_field (struct type *type, int start_bitpos, int nr_bits,
 void
 append_flags_type_flag (struct type *type, int bitpos, const char *name)
 {
-  struct gdbarch *gdbarch = get_type_arch (type);
-
   append_flags_type_field (type, bitpos, 1,
-                          builtin_type (gdbarch)->builtin_bool,
+                          builtin_type (type->arch ())->builtin_bool,
                           name);
 }
 
@@ -5963,9 +5965,9 @@ allocate_fixed_point_type_info (struct type *type)
   if (type->is_objfile_owned ())
     {
       fixed_point_type_storage *storage
-       = fixed_point_objfile_key.get (TYPE_OBJFILE (type));
+       = fixed_point_objfile_key.get (type->objfile_owner ());
       if (storage == nullptr)
-       storage = fixed_point_objfile_key.emplace (TYPE_OBJFILE (type));
+       storage = fixed_point_objfile_key.emplace (type->objfile_owner ());
       info = up.get ();
       storage->push_back (std::move (up));
     }
@@ -6091,7 +6093,7 @@ gdbtypes_post_init (struct gdbarch *gdbarch)
   builtin_type->builtin_string
     = arch_type (gdbarch, TYPE_CODE_STRING, TARGET_CHAR_BIT, "string");
   builtin_type->builtin_bool
-    = arch_type (gdbarch, TYPE_CODE_BOOL, TARGET_CHAR_BIT, "bool");
+    = arch_boolean_type (gdbarch, TARGET_CHAR_BIT, 1, "bool");
 
   /* The following three are about decimal floating point types, which
      are 32-bits, 64-bits and 128-bits respectively.  */
This page took 0.03082 seconds and 4 git commands to generate.