Remove all i386 debug register low level macros in config nm files.
[binutils-gdb.git] / gdb / gdbtypes.c
index dfa06aeced8d2b2a46f5f9c78ad46c91619ab740..f415773dfcc42fee175c0a6e7c4877597eb9382b 100644 (file)
@@ -162,20 +162,16 @@ alloc_type (struct objfile *objfile)
 
   if (objfile == NULL)
     {
-      type = xmalloc (sizeof (struct type));
-      memset (type, 0, sizeof (struct type));
-      TYPE_MAIN_TYPE (type) = xmalloc (sizeof (struct main_type));
+      type = XZALLOC (struct type);
+      TYPE_MAIN_TYPE (type) = XZALLOC (struct main_type);
     }
   else
     {
-      type = obstack_alloc (&objfile->objfile_obstack,
-                           sizeof (struct type));
-      memset (type, 0, sizeof (struct type));
-      TYPE_MAIN_TYPE (type) = obstack_alloc (&objfile->objfile_obstack,
-                                            sizeof (struct main_type));
+      type = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct type);
+      TYPE_MAIN_TYPE (type) = OBSTACK_ZALLOC (&objfile->objfile_obstack,
+                                             struct main_type);
       OBJSTAT (objfile, n_types++);
     }
-  memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
 
   /* Initialize the fields that might not be zero.  */
 
@@ -184,7 +180,7 @@ alloc_type (struct objfile *objfile)
   TYPE_VPTR_FIELDNO (type) = -1;
   TYPE_CHAIN (type) = type;    /* Chain back to itself.  */
 
-  return (type);
+  return type;
 }
 
 /* Alloc a new type instance structure, fill it with some defaults,
@@ -199,21 +195,16 @@ alloc_type_instance (struct type *oldtype)
   /* Allocate the structure.  */
 
   if (TYPE_OBJFILE (oldtype) == NULL)
-    {
-      type = xmalloc (sizeof (struct type));
-      memset (type, 0, sizeof (struct type));
-    }
+    type = XZALLOC (struct type);
   else
-    {
-      type = obstack_alloc (&TYPE_OBJFILE (oldtype)->objfile_obstack,
-                           sizeof (struct type));
-      memset (type, 0, sizeof (struct type));
-    }
+    type = OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype)->objfile_obstack,
+                          struct type);
+
   TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
 
   TYPE_CHAIN (type) = type;    /* Chain back to itself for now.  */
 
-  return (type);
+  return type;
 }
 
 /* Clear all remnants of the previous type at TYPE, in preparation for
@@ -387,24 +378,24 @@ lookup_reference_type (struct type *type)
 /* Lookup a function type that returns type TYPE.  TYPEPTR, if
    nonzero, points to a pointer to memory where the function type
    should be stored.  If *TYPEPTR is zero, update it to point to the
-   function type we return.  We allocate new memory if needed.  */
+   function type we return.  We allocate new memory from OBJFILE if needed; use
+   NULL for permanent types.  */
 
 struct type *
-make_function_type (struct type *type, struct type **typeptr)
+make_function_type (struct type *type, struct type **typeptr,
+                   struct objfile *objfile)
 {
   struct type *ntype;  /* New type */
-  struct objfile *objfile;
 
   if (typeptr == 0 || *typeptr == 0)   /* We'll need to allocate one.  */
     {
-      ntype = alloc_type (TYPE_OBJFILE (type));
+      ntype = alloc_type (objfile);
       if (typeptr)
        *typeptr = ntype;
     }
   else                 /* We have storage, but need to reset it.  */
     {
       ntype = *typeptr;
-      objfile = TYPE_OBJFILE (ntype);
       smash_type (ntype);
       TYPE_OBJFILE (ntype) = objfile;
     }
@@ -424,7 +415,7 @@ make_function_type (struct type *type, struct type **typeptr)
 struct type *
 lookup_function_type (struct type *type)
 {
-  return make_function_type (type, (struct type **) 0);
+  return make_function_type (type, (struct type **) 0, TYPE_OBJFILE (type));
 }
 
 /* Identify address space identifier by name --
@@ -654,7 +645,7 @@ lookup_memberptr_type (struct type *type, struct type *domain)
 
   mtype = alloc_type (TYPE_OBJFILE (type));
   smash_to_memberptr_type (mtype, domain, type);
-  return (mtype);
+  return mtype;
 }
 
 /* Return a pointer-to-method type, for a method of type TO_TYPE.  */
@@ -687,7 +678,7 @@ allocate_stub_method (struct type *type)
                     TYPE_OBJFILE (type));
   TYPE_TARGET_TYPE (mtype) = type;
   /*  _DOMAIN_TYPE (mtype) = unknown yet */
-  return (mtype);
+  return mtype;
 }
 
 /* Create a range type using either a blank type supplied in
@@ -705,9 +696,7 @@ create_range_type (struct type *result_type, struct type *index_type,
                   int low_bound, int high_bound)
 {
   if (result_type == NULL)
-    {
-      result_type = alloc_type (TYPE_OBJFILE (index_type));
-    }
+    result_type = alloc_type (TYPE_OBJFILE (index_type));
   TYPE_CODE (result_type) = TYPE_CODE_RANGE;
   TYPE_TARGET_TYPE (result_type) = index_type;
   if (TYPE_STUB (index_type))
@@ -715,11 +704,9 @@ create_range_type (struct type *result_type, struct type *index_type,
   else
     TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
   TYPE_NFIELDS (result_type) = 2;
-  TYPE_FIELDS (result_type) = TYPE_ALLOC (result_type,
-                                         TYPE_NFIELDS (result_type)
-                                         * sizeof (struct field));
-  memset (TYPE_FIELDS (result_type), 0,
-         TYPE_NFIELDS (result_type) * sizeof (struct field));
+  TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type,
+                                          TYPE_NFIELDS (result_type)
+                                          * sizeof (struct field));
   TYPE_LOW_BOUND (result_type) = low_bound;
   TYPE_HIGH_BOUND (result_type) = high_bound;
 
@@ -835,8 +822,7 @@ create_array_type (struct type *result_type,
       TYPE_LENGTH (element_type) * (high_bound - low_bound + 1);
   TYPE_NFIELDS (result_type) = 1;
   TYPE_FIELDS (result_type) =
-    (struct field *) TYPE_ALLOC (result_type, sizeof (struct field));
-  memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
+    (struct field *) TYPE_ZALLOC (result_type, sizeof (struct field));
   TYPE_INDEX_TYPE (result_type) = range_type;
   TYPE_VPTR_FIELDNO (result_type) = -1;
 
@@ -844,7 +830,7 @@ create_array_type (struct type *result_type,
   if (TYPE_LENGTH (result_type) == 0)
     TYPE_TARGET_STUB (result_type) = 1;
 
-  return (result_type);
+  return result_type;
 }
 
 /* Create a string type using either a blank type supplied in
@@ -871,7 +857,7 @@ create_string_type (struct type *result_type,
                                   string_char_type,
                                   range_type);
   TYPE_CODE (result_type) = TYPE_CODE_STRING;
-  return (result_type);
+  return result_type;
 }
 
 struct type *
@@ -883,9 +869,7 @@ create_set_type (struct type *result_type, struct type *domain_type)
     }
   TYPE_CODE (result_type) = TYPE_CODE_SET;
   TYPE_NFIELDS (result_type) = 1;
-  TYPE_FIELDS (result_type) = (struct field *)
-    TYPE_ALLOC (result_type, 1 * sizeof (struct field));
-  memset (TYPE_FIELDS (result_type), 0, sizeof (struct field));
+  TYPE_FIELDS (result_type) = TYPE_ZALLOC (result_type, sizeof (struct field));
 
   if (!TYPE_STUB (domain_type))
     {
@@ -900,7 +884,7 @@ create_set_type (struct type *result_type, struct type *domain_type)
     }
   TYPE_FIELD_TYPE (result_type, 0) = domain_type;
 
-  return (result_type);
+  return result_type;
 }
 
 void
@@ -931,9 +915,7 @@ init_flags_type (char *name, int length)
   type = init_type (TYPE_CODE_FLAGS, length, 
                    TYPE_FLAG_UNSIGNED, name, NULL);
   TYPE_NFIELDS (type) = nfields;
-  TYPE_FIELDS (type) = TYPE_ALLOC (type, 
-                                  nfields * sizeof (struct field));
-  memset (TYPE_FIELDS (type), 0, nfields * sizeof (struct field));
+  TYPE_FIELDS (type) = TYPE_ZALLOC (type, nfields * sizeof (struct field));
 
   return type;
 }
@@ -1067,11 +1049,11 @@ lookup_typename (char *name, struct block *block, int noerr)
                                                    name);
       if (tmp)
        {
-         return (tmp);
+         return tmp;
        }
       else if (!tmp && noerr)
        {
-         return (NULL);
+         return NULL;
        }
       else
        {
@@ -1145,14 +1127,14 @@ lookup_union (char *name, struct block *block)
   t = SYMBOL_TYPE (sym);
 
   if (TYPE_CODE (t) == TYPE_CODE_UNION)
-    return (t);
+    return t;
 
   /* C++ unions may come out with TYPE_CODE_CLASS, but we look at
    * a further "declared_type" field to discover it is really a union.
    */
   if (HAVE_CPLUS_STRUCT (t))
     if (TYPE_DECLARED_TYPE (t) == DECLARED_TYPE_UNION)
-      return (t);
+      return t;
 
   /* If we get here, it's not a union.  */
   error (_("This context has class, struct or enum %s, not a union."), 
@@ -1821,7 +1803,7 @@ init_type (enum type_code code, int length, int flags,
     {
       INIT_CPLUS_SPECIFIC (type);
     }
-  return (type);
+  return type;
 }
 
 /* Helper function.  Create an empty composite type.  */
@@ -1840,8 +1822,8 @@ init_composite_type (char *name, enum type_code code)
 /* Helper function.  Append a field to a composite type.  */
 
 void
-append_composite_type_field (struct type *t, char *name, 
-                            struct type *field)
+append_composite_type_field_aligned (struct type *t, char *name,
+                                    struct type *field, int alignment)
 {
   struct field *f;
   TYPE_NFIELDS (t) = TYPE_NFIELDS (t) + 1;
@@ -1860,12 +1842,31 @@ append_composite_type_field (struct type *t, char *name,
     {
       TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
       if (TYPE_NFIELDS (t) > 1)
-       FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
-                              + (TYPE_LENGTH (FIELD_TYPE (f[-1]))
-                                 * TARGET_CHAR_BIT));
+       {
+         FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
+                                + (TYPE_LENGTH (FIELD_TYPE (f[-1]))
+                                   * TARGET_CHAR_BIT));
+
+         if (alignment)
+           {
+             int left = FIELD_BITPOS (f[0]) % (alignment * TARGET_CHAR_BIT);
+             if (left)
+               {
+                 FIELD_BITPOS (f[0]) += left;
+                 TYPE_LENGTH (t) += left / TARGET_CHAR_BIT;
+               }
+           }
+       }
     }
 }
 
+void
+append_composite_type_field (struct type *t, char *name,
+                            struct type *field)
+{
+  append_composite_type_field_aligned (t, name, field, 0);
+}
+
 int
 can_dereference (struct type *t)
 {
@@ -2981,8 +2982,7 @@ copy_type_recursive (struct objfile *objfile,
       int i, nfields;
 
       nfields = TYPE_NFIELDS (type);
-      TYPE_FIELDS (new_type) = xmalloc (sizeof (struct field) * nfields);
-      memset (TYPE_FIELDS (new_type), 0, sizeof (struct field) * nfields);
+      TYPE_FIELDS (new_type) = XCALLOC (nfields, struct field);
       for (i = 0; i < nfields; i++)
        {
          TYPE_FIELD_ARTIFICIAL (new_type, i) =