From: Fred Fish Date: Mon, 24 Aug 1992 00:13:11 +0000 (+0000) Subject: * coffread.c (decode_type): Call alloc_type to alloc new X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=dac9734e5892a69910e8bc28f0983b05d99b6e3f;p=binutils-gdb.git * coffread.c (decode_type): Call alloc_type to alloc new types. * stabsread.c (read_array_type, read_range_type, define_symbol): Call alloc_type to alloc new types. * stabsread.c (define_symbol): Move dbl_valu symbol field data from type_obstack to symbol_obstack. * stabsread.c (define_symbol): Move typedef_sym from type_obstack to symbol_obstack. * gdbtypes.h (TYPE_ALLOC): New macro to allocate space for data associated with a type, using the same mechanism as was used to allocate space for the type structure itself. * coffread.c (patch_type, coff_read_struct_type, coff_read_enum_type): Use TYPE_ALLOC. * dwarfread.c (struct_type): Use TYPE_ALLOC. * gdbtypes.c (create_array_type, check_stub_method, allocate_cplus_struct_type): Use TYPE_ALLOC. * mipsread.c (parse_symbol, parse_type): Use TYPE_ALLOC. * stabsread.c (read_struct_type, read_array_type, read_enum_type, read_range_type): Use TYPE_ALLOC. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e53bc2178d8..263259d9e64 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,25 @@ +Sun Aug 23 17:10:07 1992 Fred Fish (fnf@cygnus.com) + + * coffread.c (decode_type): Call alloc_type to alloc new + types. + * stabsread.c (read_array_type, read_range_type, define_symbol): + Call alloc_type to alloc new types. + * stabsread.c (define_symbol): Move dbl_valu symbol field data + from type_obstack to symbol_obstack. + * stabsread.c (define_symbol): Move typedef_sym from type_obstack + to symbol_obstack. + * gdbtypes.h (TYPE_ALLOC): New macro to allocate space for data + associated with a type, using the same mechanism as was used to + allocate space for the type structure itself. + * coffread.c (patch_type, coff_read_struct_type, + coff_read_enum_type): Use TYPE_ALLOC. + * dwarfread.c (struct_type): Use TYPE_ALLOC. + * gdbtypes.c (create_array_type, check_stub_method, + allocate_cplus_struct_type): Use TYPE_ALLOC. + * mipsread.c (parse_symbol, parse_type): Use TYPE_ALLOC. + * stabsread.c (read_struct_type, read_array_type, read_enum_type, + read_range_type): Use TYPE_ALLOC. + Sun Aug 23 11:04:08 1992 Fred Fish (fnf@cygnus.com) * breakpoint.c (breakpoint_re_set): Select a default source diff --git a/gdb/dwarfread.c b/gdb/dwarfread.c index 6844813fb04..4c340ef7041 100644 --- a/gdb/dwarfread.c +++ b/gdb/dwarfread.c @@ -935,8 +935,7 @@ struct_type (dip, thisdie, enddie, objfile) { TYPE_NFIELDS (type) = nfields; TYPE_FIELDS (type) = (struct field *) - obstack_alloc (&objfile -> type_obstack, - sizeof (struct field) * nfields); + TYPE_ALLOC (type, sizeof (struct field) * nfields); /* Copy the saved-up fields into the field vector. */ for (n = nfields; list; list = list -> next) { diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index 764421b9458..2090edaf964 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -52,7 +52,7 @@ alloc_type (objfile) type = (struct type *) obstack_alloc (&objfile -> type_obstack, sizeof (struct type)); } - memset ((char *)type, 0, sizeof (struct type)); + memset ((char *) type, 0, sizeof (struct type)); /* Initialize the fields that might not be zero. */ @@ -97,7 +97,7 @@ make_pointer_type (type, typeptr) { ntype = *typeptr; objfile = TYPE_OBJFILE (ntype); - memset ((char *)ntype, 0, sizeof (struct type)); + memset ((char *) ntype, 0, sizeof (struct type)); TYPE_OBJFILE (ntype) = objfile; } @@ -162,7 +162,7 @@ make_reference_type (type, typeptr) { ntype = *typeptr; objfile = TYPE_OBJFILE (ntype); - memset ((char *)ntype, 0, sizeof (struct type)); + memset ((char *) ntype, 0, sizeof (struct type)); TYPE_OBJFILE (ntype) = objfile; } @@ -224,7 +224,7 @@ make_function_type (type, typeptr) { ntype = *typeptr; objfile = TYPE_OBJFILE (ntype); - memset ((char *)ntype, 0, sizeof (struct type)); + memset ((char *) ntype, 0, sizeof (struct type)); TYPE_OBJFILE (ntype) = objfile; } @@ -314,8 +314,7 @@ create_array_type (element_type, number) TYPE_LENGTH (result_type) = number * TYPE_LENGTH (element_type); TYPE_NFIELDS (result_type) = 1; TYPE_FIELDS (result_type) = (struct field *) - obstack_alloc (&TYPE_OBJFILE (result_type) -> type_obstack, - sizeof (struct field)); + TYPE_ALLOC (result_type, sizeof (struct field)); { /* Create range type. */ @@ -328,8 +327,7 @@ create_array_type (element_type, number) TYPE_NFIELDS (range_type) = 2; TYPE_FIELDS (range_type) = (struct field *) - obstack_alloc (&TYPE_OBJFILE (range_type) -> type_obstack, - 2 * sizeof (struct field)); + TYPE_ALLOC (range_type, 2 * sizeof (struct field)); TYPE_FIELD_BITPOS (range_type, 0) = 0; /* FIXME */ TYPE_FIELD_BITPOS (range_type, 1) = number-1; /* FIXME */ TYPE_FIELD_TYPE (range_type, 0) = builtin_type_int; /* FIXME */ @@ -362,7 +360,7 @@ smash_to_member_type (type, domain, to_type) objfile = TYPE_OBJFILE (type); - memset ((char *)type, 0, sizeof (struct type)); + memset ((char *) type, 0, sizeof (struct type)); TYPE_OBJFILE (type) = objfile; TYPE_TARGET_TYPE (type) = to_type; TYPE_DOMAIN_TYPE (type) = domain; @@ -388,7 +386,7 @@ smash_to_method_type (type, domain, to_type, args) objfile = TYPE_OBJFILE (type); - memset ((char *)type, 0, sizeof (struct type)); + memset ((char *) type, 0, sizeof (struct type)); TYPE_OBJFILE (type) = objfile; TYPE_TARGET_TYPE (type) = to_type; TYPE_DOMAIN_TYPE (type) = domain; @@ -797,8 +795,7 @@ check_stub_method (type, i, j) NULL [...] or void [end of arglist]. */ argtypes = (struct type **) - obstack_alloc (&TYPE_OBJFILE (type) -> type_obstack, - (argcount+2) * sizeof (struct type *)); + TYPE_ALLOC (type, (argcount + 2) * sizeof (struct type *)); p = argtypetext; argtypes[0] = lookup_pointer_type (type); argcount = 1; @@ -860,8 +857,7 @@ allocate_cplus_struct_type (type) if (!HAVE_CPLUS_STRUCT (type)) { TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *) - obstack_alloc (¤t_objfile -> type_obstack, - sizeof (struct cplus_struct_type)); + TYPE_ALLOC (type, sizeof (struct cplus_struct_type)); *(TYPE_CPLUS_SPECIFIC(type)) = cplus_struct_default; } } @@ -951,7 +947,7 @@ lookup_fundamental_type (objfile, typeid) nbytes = FT_NUM_MEMBERS * sizeof (struct type *); objfile -> fundamental_types = (struct type **) obstack_alloc (&objfile -> type_obstack, nbytes); - memset ((char *)objfile -> fundamental_types, 0, nbytes); + memset ((char *) objfile -> fundamental_types, 0, nbytes); } typep = objfile -> fundamental_types + typeid; if ((type = *typep) == NULL) diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 60a8225bb6a..5aaf73ba69d 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -507,6 +507,20 @@ extern struct type *builtin_type_m2_bool; TYPE_UNSIGNED(t) ? UMIN_OF_SIZE(TYPE_LENGTH(t)) \ : MIN_OF_SIZE(TYPE_LENGTH(t)) +/* 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 type_obstack, then the space for data + associated with that type will also be allocated on the type_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 (t) != NULL \ + ? obstack_alloc (&TYPE_OBJFILE (t) -> type_obstack, size) \ + : xmalloc (size) + extern struct type * alloc_type PARAMS ((struct objfile *)); diff --git a/gdb/stabsread.c b/gdb/stabsread.c index 79a4d088e68..f74e435a96b 100644 --- a/gdb/stabsread.c +++ b/gdb/stabsread.c @@ -491,7 +491,7 @@ define_symbol (valu, string, desc, type, objfile) SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile, FT_DBL_PREC_FLOAT); dbl_valu = (char *) - obstack_alloc (&objfile -> type_obstack, sizeof (double)); + obstack_alloc (&objfile -> symbol_obstack, sizeof (double)); memcpy (dbl_valu, &d, sizeof (double)); SWAP_TARGET_AND_HOST (dbl_valu, sizeof (double)); SYMBOL_VALUE_BYTES (sym) = dbl_valu; @@ -602,8 +602,7 @@ define_symbol (valu, string, desc, type, objfile) #if 0 /* This code doesn't work -- it needs to realloc and can't. */ /* Attempt to set up to record a function prototype... */ - struct type *new = (struct type *) - obstack_alloc (&objfile -> type_obstack, sizeof (struct type)); + struct type *new = alloc_type (objfile); /* Generate a template for the type of this function. The types of the arguments will be added as we read the symbol @@ -830,7 +829,7 @@ define_symbol (valu, string, desc, type, objfile) if (synonym) { register struct symbol *typedef_sym = (struct symbol *) - obstack_alloc (&objfile -> type_obstack, sizeof (struct symbol)); + obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol)); memset (typedef_sym, 0, sizeof (struct symbol)); SYMBOL_NAME (typedef_sym) = SYMBOL_NAME (sym); SYMBOL_TYPE (typedef_sym) = SYMBOL_TYPE (sym); @@ -1351,7 +1350,7 @@ read_struct_type (pp, type, objfile) n_baseclasses = read_number (pp, ','); TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) - obstack_alloc (&objfile -> type_obstack, B_BYTES (n_baseclasses)); + TYPE_ALLOC (type, B_BYTES (n_baseclasses)); B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), n_baseclasses); for (i = 0; i < n_baseclasses; i++) @@ -1619,7 +1618,7 @@ read_struct_type (pp, type, objfile) TYPE_NFIELDS (type) = nfields; TYPE_FIELDS (type) = (struct field *) - obstack_alloc (&objfile -> type_obstack, sizeof (struct field) * nfields); + TYPE_ALLOC (type, sizeof (struct field) * nfields); memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); if (non_public_fields) @@ -1627,11 +1626,11 @@ read_struct_type (pp, type, objfile) ALLOCATE_CPLUS_STRUCT_TYPE (type); TYPE_FIELD_PRIVATE_BITS (type) = (B_TYPE *) - obstack_alloc (&objfile -> type_obstack, B_BYTES (nfields)); + TYPE_ALLOC (type, B_BYTES (nfields)); B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); TYPE_FIELD_PROTECTED_BITS (type) = (B_TYPE *) - obstack_alloc (&objfile -> type_obstack, B_BYTES (nfields)); + TYPE_ALLOC (type, B_BYTES (nfields)); B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); } @@ -1879,8 +1878,7 @@ read_struct_type (pp, type, objfile) if (nfn_fields) { TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) - obstack_alloc (&objfile -> type_obstack, - sizeof (struct fn_fieldlist) * nfn_fields); + TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields); memset (TYPE_FN_FIELDLISTS (type), 0, sizeof (struct fn_fieldlist) * nfn_fields); TYPE_NFN_FIELDS (type) = nfn_fields; @@ -2059,10 +2057,7 @@ read_array_type (pp, type, objfile) { /* Create range type. */ - range_type = (struct type *) - obstack_alloc (&objfile -> type_obstack, sizeof (struct type)); - memset (range_type, 0, sizeof (struct type)); - TYPE_OBJFILE (range_type) = objfile; + range_type = alloc_type (objfile); TYPE_CODE (range_type) = TYPE_CODE_RANGE; TYPE_TARGET_TYPE (range_type) = index_type; @@ -2071,7 +2066,7 @@ read_array_type (pp, type, objfile) TYPE_NFIELDS (range_type) = 2; TYPE_FIELDS (range_type) = (struct field *) - obstack_alloc (&objfile -> type_obstack, 2 * sizeof (struct field)); + TYPE_ALLOC (range_type, 2 * sizeof (struct field)); memset (TYPE_FIELDS (range_type), 0, 2 * sizeof (struct field)); TYPE_FIELD_BITPOS (range_type, 0) = lower; TYPE_FIELD_BITPOS (range_type, 1) = upper; @@ -2082,7 +2077,7 @@ read_array_type (pp, type, objfile) TYPE_LENGTH (type) = (upper - lower + 1) * TYPE_LENGTH (element_type); TYPE_NFIELDS (type) = 1; TYPE_FIELDS (type) = (struct field *) - obstack_alloc (&objfile -> type_obstack, sizeof (struct field)); + TYPE_ALLOC (type, sizeof (struct field)); memset (TYPE_FIELDS (type), 0, sizeof (struct field)); TYPE_FIELD_TYPE (type, 0) = range_type; @@ -2161,7 +2156,7 @@ read_enum_type (pp, type, objfile) TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB; TYPE_NFIELDS (type) = nsyms; TYPE_FIELDS (type) = (struct field *) - obstack_alloc (&objfile -> type_obstack, sizeof (struct field) * nsyms); + TYPE_ALLOC (type, sizeof (struct field) * nsyms); memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms); /* Find the symbols for the values and put them into the type. @@ -2505,10 +2500,7 @@ read_range_type (pp, typenums, objfile) if (got_signed || got_unsigned) { - result_type = (struct type *) - obstack_alloc (&objfile -> type_obstack, sizeof (struct type)); - memset (result_type, 0, sizeof (struct type)); - TYPE_OBJFILE (result_type) = objfile; + result_type = alloc_type (objfile); TYPE_LENGTH (result_type) = nbits / TARGET_CHAR_BIT; TYPE_CODE (result_type) = TYPE_CODE_INT; if (got_unsigned) @@ -2617,10 +2609,7 @@ read_range_type (pp, typenums, objfile) if (self_subrange) return error_type (pp); - result_type = (struct type *) - obstack_alloc (&objfile -> type_obstack, sizeof (struct type)); - memset (result_type, 0, sizeof (struct type)); - TYPE_OBJFILE (result_type) = objfile; + result_type = alloc_type (objfile); TYPE_CODE (result_type) = TYPE_CODE_RANGE; @@ -2632,7 +2621,7 @@ read_range_type (pp, typenums, objfile) TYPE_NFIELDS (result_type) = 2; TYPE_FIELDS (result_type) = (struct field *) - obstack_alloc (&objfile -> type_obstack, 2 * sizeof (struct field)); + TYPE_ALLOC (result_type, 2 * sizeof (struct field)); memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field)); TYPE_FIELD_BITPOS (result_type, 0) = n2; TYPE_FIELD_BITPOS (result_type, 1) = n3;