[gdb/testsuite] Fix dwo path in fission-*.S
[deliverable/binutils-gdb.git] / gdb / gdbtypes.h
index cdd136ef52524c48efae2fa63bcbfa6151d7532f..0cc00e74a207ee6db56a6752e7f41fc2cc139d0c 100644 (file)
@@ -1,7 +1,7 @@
 
 /* Internal type definitions for GDB.
 
-   Copyright (C) 1992-2020 Free Software Foundation, Inc.
+   Copyright (C) 1992-2021 Free Software Foundation, Inc.
 
    Contributed by Cygnus Support, using pieces from other GDB modules.
 
 
 #include "hashtab.h"
 #include "gdbsupport/array-view.h"
+#include "gdbsupport/gdb_optional.h"
 #include "gdbsupport/offset-type.h"
 #include "gdbsupport/enum-flags.h"
 #include "gdbsupport/underlying.h"
 #include "gdbsupport/print-utils.h"
 #include "dwarf2.h"
 #include "gdb_obstack.h"
+#include "gmp-utils.h"
 
 /* Forward declarations for prototypes.  */
 struct field;
@@ -189,7 +191,10 @@ enum type_code
     TYPE_CODE_INTERNAL_FUNCTION,
 
     /* * Methods implemented in extension languages.  */
-    TYPE_CODE_XMETHOD
+    TYPE_CODE_XMETHOD,
+
+    /* * Fixed Point type.  */
+    TYPE_CODE_FIXED_POINT,
   };
 
 /* * Some bits for the type's instance_flags word.  See the macros
@@ -213,52 +218,30 @@ DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
 /* * Not textual.  By default, GDB treats all single byte integers as
    characters (or elements of strings) unless this flag is set.  */
 
-#define TYPE_NOTTEXT(t)        (TYPE_INSTANCE_FLAGS (t) & TYPE_INSTANCE_FLAG_NOTTEXT)
-
-/* * Type owner.  If TYPE_OBJFILE_OWNED is true, the type is owned by
-   the objfile retrieved as TYPE_OBJFILE.  Otherwise, the type is
-   owned by an architecture; TYPE_OBJFILE is NULL in this case.  */
-
-#define TYPE_OBJFILE_OWNED(t) (TYPE_MAIN_TYPE (t)->flag_objfile_owned)
-#define TYPE_OWNER(t) TYPE_MAIN_TYPE(t)->owner
-#define TYPE_OBJFILE(t) (TYPE_OBJFILE_OWNED(t)? TYPE_OWNER(t).objfile : NULL)
-
-/* * True if this type was declared using the "class" keyword.  This is
-   only valid for C++ structure and enum types.  If false, a structure
-   was declared as a "struct"; if true it was declared "class".  For
-   enum types, this is true when "enum class" or "enum struct" was
-   used to declare the type..  */
-
-#define TYPE_DECLARED_CLASS(t) (TYPE_MAIN_TYPE (t)->flag_declared_class)
-
-/* * True if this type is a "flag" enum.  A flag enum is one where all
-   the values are pairwise disjoint when "and"ed together.  This
-   affects how enum values are printed.  */
-
-#define TYPE_FLAG_ENUM(t) (TYPE_MAIN_TYPE (t)->flag_flag_enum)
+#define TYPE_NOTTEXT(t)        (((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_NOTTEXT)
 
 /* * Constant type.  If this is set, the corresponding type has a
    const modifier.  */
 
-#define TYPE_CONST(t) ((TYPE_INSTANCE_FLAGS (t) & TYPE_INSTANCE_FLAG_CONST) != 0)
+#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.  */
 
 #define TYPE_VOLATILE(t) \
-  ((TYPE_INSTANCE_FLAGS (t) & TYPE_INSTANCE_FLAG_VOLATILE) != 0)
+  ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_VOLATILE) != 0)
 
 /* * Restrict type.  If this is set, the corresponding type has a
    restrict modifier.  */
 
 #define TYPE_RESTRICT(t) \
-  ((TYPE_INSTANCE_FLAGS (t) & TYPE_INSTANCE_FLAG_RESTRICT) != 0)
+  ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_RESTRICT) != 0)
 
 /* * Atomic type.  If this is set, the corresponding type has an
    _Atomic modifier.  */
 
 #define TYPE_ATOMIC(t) \
-  ((TYPE_INSTANCE_FLAGS (t) & TYPE_INSTANCE_FLAG_ATOMIC) != 0)
+  ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_ATOMIC) != 0)
 
 /* * True if this type represents either an lvalue or lvalue reference type.  */
 
@@ -297,10 +280,10 @@ DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
    is instruction space, and for data objects is data memory.  */
 
 #define TYPE_CODE_SPACE(t) \
-  ((TYPE_INSTANCE_FLAGS (t) & TYPE_INSTANCE_FLAG_CODE_SPACE) != 0)
+  ((((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_CODE_SPACE) != 0)
 
 #define TYPE_DATA_SPACE(t) \
-  ((TYPE_INSTANCE_FLAGS (t) & TYPE_INSTANCE_FLAG_DATA_SPACE) != 0)
+  ((((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
@@ -309,13 +292,13 @@ DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
    target specific ways to represent these different types of address
    classes.  */
 
-#define TYPE_ADDRESS_CLASS_1(t) (TYPE_INSTANCE_FLAGS(t) \
-                                 & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1)
-#define TYPE_ADDRESS_CLASS_2(t) (TYPE_INSTANCE_FLAGS(t) \
+#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) (TYPE_INSTANCE_FLAGS(t) \
+#define TYPE_ADDRESS_CLASS_ALL(t) (((t)->instance_flags ()) \
                                   & TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL)
 
 /* * Information about a single discriminant.  */
@@ -405,6 +388,7 @@ enum dynamic_prop_kind
   PROP_LOCLIST,    /* Location list.  */
   PROP_VARIANT_PARTS, /* Variant parts.  */
   PROP_TYPE,      /* Type.  */
+  PROP_VARIABLE_NAME, /* Variable name.  */
 };
 
 union dynamic_prop_data
@@ -431,6 +415,11 @@ union dynamic_prop_data
      rewrite the property's kind and set this field.  */
 
   struct type *original_type;
+
+  /* Name of a variable to look up; the variable holds the value of
+     this property.  */
+
+  const char *variable_name;
 };
 
 /* * Used to store a dynamic property.  */
@@ -513,6 +502,22 @@ struct dynamic_prop
     m_data.original_type = original_type;
   }
 
+  /* Return the name of the variable that holds this property's value.
+     Only valid for PROP_VARIABLE_NAME.  */
+  const char *variable_name () const
+  {
+    gdb_assert (m_kind == PROP_VARIABLE_NAME);
+    return m_data.variable_name;
+  }
+
+  /* Set the name of the variable that holds this property's value,
+     and set this property to be of kind PROP_VARIABLE_NAME.  */
+  void set_variable_name (const char *name)
+  {
+    m_kind = PROP_VARIABLE_NAME;
+    m_data.variable_name = name;
+  }
+
   /* Determine which field of the union dynamic_prop.data is used.  */
   enum dynamic_prop_kind m_kind;
 
@@ -599,7 +604,9 @@ enum type_specific_kind
   TYPE_SPECIFIC_FLOATFORMAT,
   /* Note: This is used by TYPE_CODE_FUNC and TYPE_CODE_METHOD.  */
   TYPE_SPECIFIC_FUNC,
-  TYPE_SPECIFIC_SELF_TYPE
+  TYPE_SPECIFIC_SELF_TYPE,
+  TYPE_SPECIFIC_INT,
+  TYPE_SPECIFIC_FIXED_POINT,
 };
 
 union type_owner
@@ -764,6 +771,25 @@ union type_specific
      is a member of.  */
 
   struct type *self_type;
+
+  /* * For TYPE_CODE_FIXED_POINT types, the info necessary to decode
+     values of that type.  */
+  struct fixed_point_type_info *fixed_point_info;
+
+  /* * An integer-like scalar type may be stored in just part of its
+     enclosing storage bytes.  This structure describes this
+     situation.  */
+  struct
+  {
+    /* * The bit size of the integer.  This can be 0.  For integers
+       that fill their storage (the ordinary case), this field holds
+       the byte size times 8.  */
+    unsigned short bit_size;
+    /* * The bit offset of the integer.  This is ordinarily 0, and can
+       only be non-zero if the bit size is less than the storage
+       size.  */
+    unsigned short bit_offset;
+  } int_stuff;
 };
 
 /* * Main structure representing a type in GDB.
@@ -791,18 +817,18 @@ struct main_type
   unsigned int m_flag_stub_supported : 1;
   unsigned int m_flag_gnu_ifunc : 1;
   unsigned int m_flag_fixed_instance : 1;
-  unsigned int flag_objfile_owned : 1;
+  unsigned int m_flag_objfile_owned : 1;
   unsigned int m_flag_endianity_not_default : 1;
 
   /* * True if this type was declared with "class" rather than
      "struct".  */
 
-  unsigned int flag_declared_class : 1;
+  unsigned int m_flag_declared_class : 1;
 
   /* * True if this is an enum type with disjoint values.  This
      affects how the enum is printed.  */
 
-  unsigned int flag_flag_enum : 1;
+  unsigned int m_flag_flag_enum : 1;
 
   /* * A discriminant telling us which field of the type_specific
      union is being used for this type, if any.  */
@@ -834,7 +860,7 @@ struct main_type
      this is somewhat ugly, but without major overhaul of the internal
      type system, it can't be avoided for now.  */
 
-  union type_owner owner;
+  union type_owner m_owner;
 
   /* * For a pointer type, describes the type of object pointed to.
      - For an array type, describes the type of the elements.
@@ -1169,6 +1195,72 @@ struct type
     this->main_type->m_flag_endianity_not_default = endianity_is_not_default;
   }
 
+
+  /* True if this type was declared using the "class" keyword.  This is
+     only valid for C++ structure and enum types.  If false, a structure
+     was declared as a "struct"; if true it was declared "class".  For
+     enum types, this is true when "enum class" or "enum struct" was
+     used to declare the type.  */
+
+  bool is_declared_class () const
+  {
+    return this->main_type->m_flag_declared_class;
+  }
+
+  void set_is_declared_class (bool is_declared_class) const
+  {
+    this->main_type->m_flag_declared_class = is_declared_class;
+  }
+
+  /* True if this type is a "flag" enum.  A flag enum is one where all
+     the values are pairwise disjoint when "and"ed together.  This
+     affects how enum values are printed.  */
+
+  bool is_flag_enum () const
+  {
+    return this->main_type->m_flag_flag_enum;
+  }
+
+  void set_is_flag_enum (bool is_flag_enum)
+  {
+    this->main_type->m_flag_flag_enum = is_flag_enum;
+  }
+
+  /* * Assuming that THIS is a TYPE_CODE_FIXED_POINT, return a reference
+     to this type's fixed_point_info.  */
+
+  struct fixed_point_type_info &fixed_point_info () const
+  {
+    gdb_assert (this->code () == TYPE_CODE_FIXED_POINT);
+    gdb_assert (this->main_type->type_specific.fixed_point_info != nullptr);
+
+    return *this->main_type->type_specific.fixed_point_info;
+  }
+
+  /* * Assuming that THIS is a TYPE_CODE_FIXED_POINT, set this type's
+     fixed_point_info to INFO.  */
+
+  void set_fixed_point_info (struct fixed_point_type_info *info) const
+  {
+    gdb_assert (this->code () == TYPE_CODE_FIXED_POINT);
+
+    this->main_type->type_specific.fixed_point_info = info;
+  }
+
+  /* * Assuming that THIS is a TYPE_CODE_FIXED_POINT, return its base type.
+
+     In other words, this returns the type after having peeled all
+     intermediate type layers (such as TYPE_CODE_RANGE, for instance).
+     The TYPE_CODE of the type returned is guaranteed to be
+     a TYPE_CODE_FIXED_POINT.  */
+
+  struct type *fixed_point_type_base_type ();
+
+  /* * Assuming that THIS is a TYPE_CODE_FIXED_POINT, return its scaling
+     factor.  */
+
+  const gdb_mpq &fixed_point_scaling_factor ();
+
   /* * Return the dynamic property of the requested KIND from this type's
      list of dynamic properties.  */
   dynamic_prop *dyn_prop (dynamic_prop_node_kind kind) const;
@@ -1182,6 +1274,85 @@ struct type
   /* * Remove dynamic property of kind KIND from this type, if it exists.  */
   void remove_dyn_prop (dynamic_prop_node_kind kind);
 
+  /* Return true if this type is owned by an objfile.  Return false if it is
+     owned by an architecture.  */
+  bool is_objfile_owned () const
+  {
+    return this->main_type->m_flag_objfile_owned;
+  }
+
+  /* Set the owner of the type to be OBJFILE.  */
+  void set_owner (objfile *objfile)
+  {
+    gdb_assert (objfile != nullptr);
+
+    this->main_type->m_owner.objfile = objfile;
+    this->main_type->m_flag_objfile_owned = true;
+  }
+
+  /* Set the owner of the type to be ARCH.  */
+  void set_owner (gdbarch *arch)
+  {
+    gdb_assert (arch != nullptr);
+
+    this->main_type->m_owner.gdbarch = arch;
+    this->main_type->m_flag_objfile_owned = false;
+  }
+
+  /* Return the objfile owner of this type.
+
+     Return nullptr if this type is not objfile-owned.  */
+  struct objfile *objfile_owner () const
+  {
+    if (!this->is_objfile_owned ())
+      return nullptr;
+
+    return this->main_type->m_owner.objfile;
+  }
+
+  /* Return the gdbarch owner of this type.
+
+     Return nullptr if this type is not gdbarch-owned.  */
+  gdbarch *arch_owner () const
+  {
+    if (this->is_objfile_owned ())
+      return nullptr;
+
+    return this->main_type->m_owner.gdbarch;
+  }
+
+  /* Return the type's architecture.  For types owned by an
+     architecture, that architecture is returned.  For types owned by an
+     objfile, that objfile's architecture is returned.
+
+     The return value is always non-nullptr.  */
+  gdbarch *arch () const;
+
+  /* * Return true if this is an integer type whose logical (bit) size
+     differs from its storage size; false otherwise.  Always return
+     false for non-integer (i.e., non-TYPE_SPECIFIC_INT) types.  */
+  bool bit_size_differs_p () const
+  {
+    return (main_type->type_specific_field == TYPE_SPECIFIC_INT
+           && main_type->type_specific.int_stuff.bit_size != 8 * length);
+  }
+
+  /* * Return the logical (bit) size for this integer type.  Only
+     valid for integer (TYPE_SPECIFIC_INT) types.  */
+  unsigned short bit_size () const
+  {
+    gdb_assert (main_type->type_specific_field == TYPE_SPECIFIC_INT);
+    return main_type->type_specific.int_stuff.bit_size;
+  }
+
+  /* * Return the bit offset for this integer type.  Only valid for
+     integer (TYPE_SPECIFIC_INT) types.  */
+  unsigned short bit_offset () const
+  {
+    gdb_assert (main_type->type_specific_field == TYPE_SPECIFIC_INT);
+    return main_type->type_specific.int_stuff.bit_offset;
+  }
+
   /* * Type that is a pointer to this type.
      NULL if no such pointer-to type is known yet.
      The debugger may add the address of such a type
@@ -1637,6 +1808,14 @@ struct call_site
     struct call_site_parameter parameter[1];
   };
 
+/* The type-specific info for TYPE_CODE_FIXED_POINT types.  */
+
+struct fixed_point_type_info
+{
+  /* The fixed point type's scaling factor.  */
+  gdb_mpq scaling_factor;
+};
+
 /* * The default value of TYPE_CPLUS_SPECIFIC(T) points to this shared
    static structure.  */
 
@@ -1684,7 +1863,13 @@ extern void allocate_gnat_aux_type (struct type *);
      TYPE_ZALLOC (type,                                                               \
                  sizeof (*TYPE_MAIN_TYPE (type)->type_specific.func_stuff)))
 
-#define TYPE_INSTANCE_FLAGS(thistype) ((thistype)->instance_flags ())
+/* "struct fixed_point_type_info" has a field that has a destructor.
+   See allocate_fixed_point_type_info to understand how this is
+   handled.  */
+#define INIT_FIXED_POINT_SPECIFIC(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_TARGET_TYPE(thistype) TYPE_MAIN_TYPE(thistype)->target_type
 #define TYPE_POINTER_TYPE(thistype) (thistype)->pointer_type
@@ -2100,10 +2285,10 @@ extern const struct floatformat *floatformats_bfloat16[BFD_ENDIAN_UNKNOWN];
    when it is no longer needed.  */
 
 #define TYPE_ALLOC(t,size)                                              \
-  (obstack_alloc ((TYPE_OBJFILE_OWNED (t)                               \
-                   ? &TYPE_OBJFILE (t)->objfile_obstack                 \
-                   : gdbarch_obstack (TYPE_OWNER (t).gdbarch)),         \
-                  size))
+  (obstack_alloc (((t)->is_objfile_owned ()                             \
+                  ? &((t)->objfile_owner ()->objfile_obstack)          \
+                  : gdbarch_obstack ((t)->arch_owner ())),             \
+                 size))
 
 
 /* See comment on TYPE_ALLOC.  */
@@ -2119,12 +2304,6 @@ extern struct type *alloc_type (struct objfile *);
 extern struct type *alloc_type_arch (struct gdbarch *);
 extern struct type *alloc_type_copy (const struct type *);
 
-/* * Return the type's architecture.  For types owned by an
-   architecture, that architecture is returned.  For types owned by an
-   objfile, that objfile's architecture is returned.  */
-
-extern struct gdbarch *get_type_arch (const struct type *);
-
 /* * This returns the target type (or NULL) of TYPE, also skipping
    past typedefs.  */
 
@@ -2149,9 +2328,12 @@ extern struct type *init_float_type (struct objfile *, int, const char *,
                                     const struct floatformat **,
                                     enum bfd_endian = BFD_ENDIAN_UNKNOWN);
 extern struct type *init_decfloat_type (struct objfile *, int, const char *);
+extern bool can_create_complex_type (struct type *);
 extern struct type *init_complex_type (const char *, struct type *);
 extern struct type *init_pointer_type (struct objfile *, int, const char *,
                                       struct type *);
+extern struct type *init_fixed_point_type (struct objfile *, int, int,
+                                          const char *);
 
 /* Helper functions to construct architecture-owned types.  */
 extern struct type *arch_type (struct gdbarch *, enum type_code, int,
@@ -2205,7 +2387,7 @@ extern struct type *lookup_rvalue_reference_type (struct type *);
 
 
 extern struct type *make_reference_type (struct type *, struct type **,
-                                         enum type_code);
+                                        enum type_code);
 
 extern struct type *make_cv_type (int, int, struct type *, struct type **);
 
@@ -2217,11 +2399,11 @@ extern struct type *make_atomic_type (struct type *);
 
 extern void replace_type (struct type *, struct type *);
 
-extern type_instance_flags address_space_name_to_int (struct gdbarch *,
-                                                     const char *);
+extern type_instance_flags address_space_name_to_type_instance_flags
+  (struct gdbarch *, const char *);
 
-extern const char *address_space_int_to_name (struct gdbarch *,
-                                             type_instance_flags);
+extern const char *address_space_type_instance_flags_to_name
+  (struct gdbarch *, type_instance_flags);
 
 extern struct type *make_type_with_address_space
   (struct type *type, type_instance_flags space_identifier);
@@ -2364,12 +2546,34 @@ extern struct type *lookup_template_type (const char *, struct type *,
 
 extern int get_vptr_fieldno (struct type *, struct type **);
 
-extern int get_discrete_bounds (struct type *, LONGEST *, LONGEST *);
+/* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
+   TYPE.
+
+   Return true if the two bounds are available, false otherwise.  */
+
+extern bool get_discrete_bounds (struct type *type, LONGEST *lowp,
+                                LONGEST *highp);
+
+/* If TYPE's low bound is a known constant, return it, else return nullopt.  */
+
+extern gdb::optional<LONGEST> get_discrete_low_bound (struct type *type);
+
+/* If TYPE's high bound is a known constant, return it, else return nullopt.  */
 
-extern int get_array_bounds (struct type *type, LONGEST *low_bound,
-                            LONGEST *high_bound);
+extern gdb::optional<LONGEST> get_discrete_high_bound (struct type *type);
 
-extern int discrete_position (struct type *type, LONGEST val, LONGEST *pos);
+/* Assuming TYPE is a simple, non-empty array type, compute its upper
+   and lower bound.  Save the low bound into LOW_BOUND if not NULL.
+   Save the high bound into HIGH_BOUND if not NULL.
+
+   Return true if the operation was successful.  Return false otherwise,
+   in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.  */
+
+extern bool get_array_bounds (struct type *type, LONGEST *low_bound,
+                             LONGEST *high_bound);
+
+extern gdb::optional<LONGEST> discrete_position (struct type *type,
+                                                LONGEST val);
 
 extern int class_types_same_p (const struct type *, const struct type *);
 
@@ -2473,7 +2677,7 @@ extern int class_or_union_p (const struct type *);
 
 extern void maintenance_print_type (const char *, int);
 
-extern htab_t create_copied_types_hash (struct objfile *objfile);
+extern htab_up create_copied_types_hash (struct objfile *objfile);
 
 extern struct type *copy_type_recursive (struct objfile *objfile,
                                         struct type *type,
@@ -2489,10 +2693,18 @@ extern int type_not_allocated (const struct type *type);
 
 extern int type_not_associated (const struct type *type);
 
+/* Return True if TYPE is a TYPE_CODE_FIXED_POINT or if TYPE is
+   a range type whose base type is a TYPE_CODE_FIXED_POINT.  */
+extern bool is_fixed_point_type (struct type *type);
+
+/* Allocate a fixed-point type info for TYPE.  This should only be
+   called by INIT_FIXED_POINT_SPECIFIC.  */
+extern void allocate_fixed_point_type_info (struct type *type);
+
 /* * When the type includes explicit byte ordering, return that.
-   Otherwise, the byte ordering from gdbarch_byte_order for 
-   get_type_arch is returned.  */
-   
+   Otherwise, the byte ordering from gdbarch_byte_order for
+   the type's arch is returned.  */
+
 extern enum bfd_endian type_byte_order (const struct type *type);
 
 /* A flag to enable printing of debugging information of C++
This page took 0.0316959999999999 seconds and 4 git commands to generate.