diff options
author | John Gilmore <gnu@cygnus> | 1992-05-01 09:14:43 +0000 |
---|---|---|
committer | John Gilmore <gnu@cygnus> | 1992-05-01 09:14:43 +0000 |
commit | ea1549b346e7014425e5ce74943ca3e2f81097e2 (patch) | |
tree | b03d8035ff9c150cd363107d52060705d592da33 /gdb/gdbtypes.c | |
parent | 5bdf762bb8861ca302b47a491660479513e9edde (diff) | |
download | ppe42-binutils-ea1549b346e7014425e5ce74943ca3e2f81097e2.tar.gz ppe42-binutils-ea1549b346e7014425e5ce74943ca3e2f81097e2.zip |
* gdbtypes.c (make_{reference,pointer,function}_type): New
functions which handle overwriting of forward-referenced types
for stabs file reading.
(lookup_{reference,pointer,function}_type): These just call
the make_*_type functions with a null storage alloc parameter.
* gdbtypes.h (make_{reference,pointer,function}_type): Declare.
* xcoffread.c (smash_to_pointer_type): Remove, no longer used.
* buildsym.c (dbx_lookup_type): Zero result for (-1,-1) arg.
(dbx_alloc_type): Make it easier to understand. No funct change.
(define_symbol: 't'): Don't put the typedef name into the name of
the struct, union, or enum. Bugfix.
(read_type: '*', '&', 'f'): Add comments. Use make_XXX_type
routines to properly handle overwriting preallocated types so that
forward references will work.
(read_enum_type): Force enum values to file scope, due to bug in
Sun compiler output. FIXME, fix later.
Remove unused header_file_prev_index mechanism. It was already
obsolete in gdb-3.5. These comments appeared in 3.5:
/* This code was used before I knew about the instance codes.
My first hypothesis is that it is not necessary now
that instance codes are handled. */
* dbxread.c (add_new_header_file): Remove header_file_prev_index.
* buildsym.h: Remove it and prev_index that saves it.
* buildsym.c (push_subfile, pop_subfile, start_symtab): Remove it.
* solib.c (special_symbol_handling): When called from core files,
must set up debug_addr. Don't print error messages, just return.
* symmisc.c (print_symbol): Less ascii diarrhea for enums, please.
Diffstat (limited to 'gdb/gdbtypes.c')
-rw-r--r-- | gdb/gdbtypes.c | 217 |
1 files changed, 164 insertions, 53 deletions
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index fcc673aada..2523c7697f 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -62,6 +62,61 @@ alloc_type (objfile) return (type); } +/* Lookup a pointer to a type TYPE. TYPEPTR, if nonzero, points + to a pointer to memory where the pointer type should be stored. + If *TYPEPTR is zero, update it to point to the pointer type we return. + We allocate new memory if needed. */ + +struct type * +make_pointer_type (type, typeptr) + struct type *type; + struct type **typeptr; +{ + register struct type *ntype; /* New type */ + struct objfile *objfile; + + ntype = TYPE_POINTER_TYPE (type); + + if (ntype) + if (typeptr == 0) + return ntype; /* Don't care about alloc, and have new type. */ + else if (*typeptr == 0) + { + *typeptr = ntype; /* Tracking alloc, and we have new type. */ + return ntype; + } + + if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ + { + ntype = alloc_type (TYPE_OBJFILE (type)); + if (typeptr) + *typeptr = ntype; + } + else /* We have storage, but need to reset it. */ + { + ntype = *typeptr; + objfile = TYPE_OBJFILE (ntype); + memset ((char *)ntype, 0, sizeof (struct type)); + TYPE_OBJFILE (ntype) = objfile; + } + + TYPE_TARGET_TYPE (ntype) = type; + TYPE_POINTER_TYPE (type) = ntype; + + /* FIXME! Assume the machine has only one representation for pointers! */ + + TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT; + TYPE_CODE (ntype) = TYPE_CODE_PTR; + + /* pointers are unsigned */ + TYPE_FLAGS (ntype) |= TYPE_FLAG_UNSIGNED; + + if (!TYPE_POINTER_TYPE (type)) /* Remember it, if don't have one. */ + TYPE_POINTER_TYPE (type) = ntype; + + return ntype; +} + /* Given a type TYPE, return a type of pointers to that type. May need to construct such a type if this is the first use. */ @@ -69,74 +124,130 @@ struct type * lookup_pointer_type (type) struct type *type; { - register struct type *ptype; - - if ((ptype = TYPE_POINTER_TYPE (type)) == NULL) - { - /* This is the first time anyone wanted a pointer to a TYPE. */ - - ptype = alloc_type (TYPE_OBJFILE (type)); - TYPE_TARGET_TYPE (ptype) = type; - TYPE_POINTER_TYPE (type) = ptype; - - /* FIXME, assume machine has only one representation for pointers! */ - - TYPE_LENGTH (ptype) = TARGET_PTR_BIT / TARGET_CHAR_BIT; - TYPE_CODE (ptype) = TYPE_CODE_PTR; - - /* pointers are unsigned */ - TYPE_FLAGS(ptype) |= TYPE_FLAG_UNSIGNED; - - } - return (ptype); + return make_pointer_type (type, (struct type **)0); +} + +/* Lookup a C++ `reference' to a type TYPE. TYPEPTR, if nonzero, points + to a pointer to memory where the reference type should be stored. + If *TYPEPTR is zero, update it to point to the reference type we return. + We allocate new memory if needed. */ + +struct type * +make_reference_type (type, typeptr) + struct type *type; + struct type **typeptr; +{ + register struct type *ntype; /* New type */ + struct objfile *objfile; + + ntype = TYPE_REFERENCE_TYPE (type); + + if (ntype) + if (typeptr == 0) + return ntype; /* Don't care about alloc, and have new type. */ + else if (*typeptr == 0) + { + *typeptr = ntype; /* Tracking alloc, and we have new type. */ + return ntype; + } + + if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ + { + ntype = alloc_type (TYPE_OBJFILE (type)); + if (typeptr) + *typeptr = ntype; + } + else /* We have storage, but need to reset it. */ + { + ntype = *typeptr; + objfile = TYPE_OBJFILE (ntype); + memset ((char *)ntype, 0, sizeof (struct type)); + TYPE_OBJFILE (ntype) = objfile; + } + + TYPE_TARGET_TYPE (ntype) = type; + TYPE_REFERENCE_TYPE (type) = ntype; + + /* FIXME! Assume the machine has only one representation for references, + and that it matches the (only) representation for pointers! */ + + TYPE_LENGTH (ntype) = TARGET_PTR_BIT / TARGET_CHAR_BIT; + TYPE_CODE (ntype) = TYPE_CODE_REF; + + if (!TYPE_REFERENCE_TYPE (type)) /* Remember it, if don't have one. */ + TYPE_REFERENCE_TYPE (type) = ntype; + + return ntype; } +/* Same as above, but caller doesn't care about memory allocation details. */ + struct type * lookup_reference_type (type) struct type *type; { - register struct type *rtype; - - if ((rtype = TYPE_REFERENCE_TYPE (type)) == NULL) - { - /* This is the first time anyone wanted a pointer to a TYPE. */ - - rtype = alloc_type (TYPE_OBJFILE (type)); - TYPE_TARGET_TYPE (rtype) = type; - TYPE_REFERENCE_TYPE (type) = rtype; - - /* We assume the machine has only one representation for pointers! */ - /* FIXME: This confuses host<->target data representations, and is a - poor assumption besides. */ - - TYPE_LENGTH (rtype) = sizeof (char *); - TYPE_CODE (rtype) = TYPE_CODE_REF; - - } - return (rtype); + return make_reference_type (type, (struct type **)0); } -/* Given a type TYPE, return a type of functions that return that type. - May need to construct such a type if this is the first use. */ +/* 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. */ struct type * -lookup_function_type (type) +make_function_type (type, typeptr) struct type *type; + struct type **typeptr; { - register struct type *ptype; + register struct type *ntype; /* New type */ + struct objfile *objfile; + + ntype = TYPE_FUNCTION_TYPE (type); - if ((ptype = TYPE_FUNCTION_TYPE (type)) == NULL) + if (ntype) + if (typeptr == 0) + return ntype; /* Don't care about alloc, and have new type. */ + else if (*typeptr == 0) + { + *typeptr = ntype; /* Tracking alloc, and we have new type. */ + return ntype; + } + + if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */ { - /* This is the first time anyone wanted a function returning a TYPE. */ - - ptype = alloc_type (TYPE_OBJFILE (type)); - TYPE_TARGET_TYPE (ptype) = type; - TYPE_FUNCTION_TYPE (type) = ptype; - - TYPE_LENGTH (ptype) = 1; - TYPE_CODE (ptype) = TYPE_CODE_FUNC; + ntype = alloc_type (TYPE_OBJFILE (type)); + if (typeptr) + *typeptr = ntype; } - return (ptype); + else /* We have storage, but need to reset it. */ + { + ntype = *typeptr; + objfile = TYPE_OBJFILE (ntype); + memset ((char *)ntype, 0, sizeof (struct type)); + TYPE_OBJFILE (ntype) = objfile; + } + + TYPE_TARGET_TYPE (ntype) = type; + TYPE_FUNCTION_TYPE (type) = ntype; + + TYPE_LENGTH (ntype) = 1; + TYPE_CODE (ntype) = TYPE_CODE_FUNC; + + if (!TYPE_FUNCTION_TYPE (type)) /* Remember it, if don't have one. */ + TYPE_FUNCTION_TYPE (type) = ntype; + + return ntype; +} + + +/* Given a type TYPE, return a type of functions that return that type. + May need to construct such a type if this is the first use. */ + +struct type * +lookup_function_type (type) + struct type *type; +{ + return make_function_type (type, (struct type **)0); } /* Implement direct support for MEMBER_TYPE in GNU C++. |