+2018-09-10 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * eval.c (fake_method::fake_method): Call xzalloc directly for a
+ type that is neither object file owned, nor gdbarch owned.
+ * gdbtypes.c (get_type_gdbarch): Add an assert that returned
+ gdbarch is non-NULL.
+ (alloc_type_instance): Allocate non-objfile owned types on the
+ gdbarch obstack.
+ (copy_type_recursive): Allocate TYPE_FIELDS and TYPE_RANGE_DATA
+ using TYPE_ALLOC to ensure memory is allocated on the correct
+ obstack.
+ * gdbtypes.h (TYPE_ALLOC): Allocate space on either the objfile
+ obstack, or the gdbarch obstack.
+ (TYPE_ZALLOC): Rewrite using TYPE_ALLOC.
+
2018-09-14 Tom Tromey <tom@tromey.com>
* infcall.c (call_function_by_hand_dummy): Remove unnecessary
}
}
+ /* We don't use TYPE_ZALLOC here to allocate space as TYPE is owned by
+ neither an objfile nor a gdbarch. As a result we must manually
+ allocate memory for auxiliary fields, and free the memory ourselves
+ when we are done with it. */
TYPE_NFIELDS (type) = num_types;
TYPE_FIELDS (type) = (struct field *)
- TYPE_ZALLOC (type, sizeof (struct field) * num_types);
+ xzalloc (sizeof (struct field) * num_types);
while (num_types-- > 0)
TYPE_FIELD_TYPE (type, num_types) = param_types[num_types];
struct gdbarch *
get_type_arch (const struct type *type)
{
+ struct gdbarch *arch;
+
if (TYPE_OBJFILE_OWNED (type))
- return get_objfile_arch (TYPE_OWNER (type).objfile);
+ arch = get_objfile_arch (TYPE_OWNER (type).objfile);
else
- return TYPE_OWNER (type).gdbarch;
+ arch = TYPE_OWNER (type).gdbarch;
+
+ /* 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
+ returned. */
+ gdb_assert (arch != NULL);
+ return arch;
}
/* See gdbtypes.h. */
/* Allocate the structure. */
if (! TYPE_OBJFILE_OWNED (oldtype))
- type = XCNEW (struct type);
+ type = GDBARCH_OBSTACK_ZALLOC (get_type_arch (oldtype), struct type);
else
type = OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype)->objfile_obstack,
struct type);
int i, nfields;
nfields = TYPE_NFIELDS (type);
- TYPE_FIELDS (new_type) = XCNEWVEC (struct field, nfields);
+ TYPE_FIELDS (new_type) = (struct field *)
+ TYPE_ZALLOC (new_type, nfields * sizeof (struct field));
for (i = 0; i < nfields; i++)
{
TYPE_FIELD_ARTIFICIAL (new_type, i) =
/* For range types, copy the bounds information. */
if (TYPE_CODE (type) == TYPE_CODE_RANGE)
{
- TYPE_RANGE_DATA (new_type) = XNEW (struct range_bounds);
+ TYPE_RANGE_DATA (new_type) = (struct range_bounds *)
+ TYPE_ALLOC (new_type, sizeof (struct range_bounds));
*TYPE_RANGE_DATA (new_type) = *TYPE_RANGE_DATA (type);
}
#include "common/enum-flags.h"
#include "common/underlying.h"
#include "common/print-utils.h"
+#include "gdbarch.h"
/* Forward declarations for prototypes. */
struct field;
extern const struct floatformat *floatformats_ibm_long_double[BFD_ENDIAN_UNKNOWN];
-/* * Allocate space for storing data associated with a particular
+/* Allocate space for storing data associated with a particular
type. We ensure that the space is allocated using the same
mechanism that was used to allocate the space for the type
structure itself. I.e. if the type is on an objfile's
objfile_obstack, then the space for data associated with that type
- will also be allocated on the objfile_obstack. If the type is not
- associated with any particular objfile (such as builtin types),
- then the data space will be allocated with xmalloc, the same as for
- the type structure. */
-
-#define TYPE_ALLOC(t,size) \
- (TYPE_OBJFILE_OWNED (t) \
- ? obstack_alloc (&TYPE_OBJFILE (t) -> objfile_obstack, size) \
- : xmalloc (size))
-
-#define TYPE_ZALLOC(t,size) \
- (TYPE_OBJFILE_OWNED (t) \
- ? memset (obstack_alloc (&TYPE_OBJFILE (t)->objfile_obstack, size), \
- 0, size) \
- : xzalloc (size))
+ will also be allocated on the objfile_obstack. If the type is
+ associated with a gdbarch, then the space for data associated with that
+ type will also be allocated on the gdbarch_obstack.
+
+ If a type is not associated with neither an objfile or a gdbarch then
+ you should not use this macro to allocate space for data, instead you
+ should call xmalloc directly, and ensure the memory is correctly freed
+ 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))
+
+
+/* See comment on TYPE_ALLOC. */
+
+#define TYPE_ZALLOC(t,size) (memset (TYPE_ALLOC (t, size), 0, size))
/* Use alloc_type to allocate a type owned by an objfile. Use
alloc_type_arch to allocate a type owned by an architecture. Use