From ea1549b346e7014425e5ce74943ca3e2f81097e2 Mon Sep 17 00:00:00 2001 From: John Gilmore Date: Fri, 1 May 1992 09:14:43 +0000 Subject: [PATCH] * 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. --- gdb/ChangeLog | 33 ++++++++ gdb/buildsym.c | 124 +++++++++++---------------- gdb/buildsym.h | 8 -- gdb/gdbtypes.c | 217 ++++++++++++++++++++++++++++++++++++------------ gdb/gdbtypes.h | 9 ++ gdb/xcoffread.c | 46 ---------- 6 files changed, 254 insertions(+), 183 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index cff4c1a9304..1bcb2a71cb0 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,36 @@ +Fri May 1 01:53:26 1992 John Gilmore (gnu at cygnus.com) + + * 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. + Wed Apr 29 15:26:51 1992 Per Bothner (bothner@rtl.cygnus.com) * cplus-dem.c: Allow nested class names (as in diff --git a/gdb/buildsym.c b/gdb/buildsym.c index fd86a280b9c..3a82e9a482b 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -189,6 +189,9 @@ dbx_lookup_type (typenums) register int filenum = typenums[0], index = typenums[1]; unsigned old_len; + if (filenum == -1) /* -1,-1 is for temporary types. */ + return 0; + if (filenum < 0 || filenum >= n_this_object_header_files) error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.", filenum, index, symnum); @@ -252,30 +255,19 @@ dbx_alloc_type (typenums, objfile) struct objfile *objfile; { register struct type **type_addr; - register struct type *type; - if (typenums[0] != -1) - { - type_addr = dbx_lookup_type (typenums); - type = *type_addr; - } - else - { - type_addr = 0; - type = 0; - } + if (typenums[0] == -1) + return alloc_type (objfile); + + type_addr = dbx_lookup_type (typenums); /* If we are referring to a type not known at all yet, allocate an empty type for it. We will fill it in later if we find out how. */ - if (type == 0) - { - type = alloc_type (objfile); - if (type_addr) - *type_addr = type; - } - - return type; + if (*type_addr == 0) + *type_addr = alloc_type (objfile); + + return *type_addr; } /* maintain the lists of symbols and blocks */ @@ -595,7 +587,6 @@ push_subfile () if (current_subfile == 0 || current_subfile->name == 0) abort (); tem->name = current_subfile->name; - tem->prev_index = header_file_prev_index; } char * @@ -609,7 +600,6 @@ pop_subfile () name = link->name; subfile_stack = link->next; - header_file_prev_index = link->prev_index; free ((PTR)link); return name; @@ -692,7 +682,6 @@ start_symtab (name, dirname, start_addr) /* Leave FILENUM of 0 free for builtin types and this file's types. */ n_this_object_header_files = 1; - header_file_prev_index = -1; type_vector_length = 0; type_vector = (struct type **) 0; @@ -1277,6 +1266,7 @@ define_symbol (valu, string, desc, type, objfile) save away the name so that far away from here in read_range_type, we can examine it to decide between "int" and "long". FIXME. */ long_kludge_name = SYMBOL_NAME (sym); + type_read = read_type (&p, objfile); if ((deftype == 'F' || deftype == 'f') @@ -1475,16 +1465,12 @@ define_symbol (valu, string, desc, type, objfile) SYMBOL_CLASS (sym) = LOC_TYPEDEF; SYMBOL_VALUE (sym) = valu; SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; - if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL) - TYPE_NAME (SYMBOL_TYPE (sym)) = - obsavestring (SYMBOL_NAME (sym), - strlen (SYMBOL_NAME (sym)), - &objfile -> symbol_obstack); - /* C++ vagaries: we may have a type which is derived from - a base type which did not have its name defined when the - derived class was output. We fill in the derived class's - base part member's name here in that case. */ - else if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT + /* C++ vagaries: we may have a type which is derived from + a base type which did not have its name defined when the + derived class was output. We fill in the derived class's + base part member's name here in that case. */ + if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL) + if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION) && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym))) { @@ -1917,23 +1903,30 @@ read_type (pp, objfile) *dbx_lookup_type (typenums) = type; break; + /* In the following types, we must be sure to overwrite any existing + type that the typenums refer to, rather than allocating a new one + and making the typenums point to the new one. This is because there + may already be pointers to the existing type (if it had been + forward-referenced), and we must change it to a pointer, function, + reference, or whatever, *in-place*. */ + case '*': type1 = read_type (pp, objfile); -/* FIXME -- we should be doing smash_to_XXX types here. */ -#ifdef IBM6000_TARGET - /* postponed type decoration should be allowed. */ - if (typenums[1] > 0 && typenums[1] < type_vector_length && - (type = type_vector[typenums[1]])) { - smash_to_pointer_type (type, type1); + type = make_pointer_type (type1, dbx_lookup_type (typenums)); break; - } -#endif - type = lookup_pointer_type (type1); - if (typenums[0] != -1) - *dbx_lookup_type (typenums) = type; + + case '&': /* Reference to another type */ + type1 = read_type (pp, objfile); + type = make_reference_type (type1, dbx_lookup_type (typenums)); + break; + + case 'f': /* Function returning another type */ + type1 = read_type (pp, objfile); + type = make_function_type (type1, dbx_lookup_type (typenums)); break; - case '@': +/* FIXME -- we should be doing smash_to_XXX types here. */ + case '@': /* Member (class & variable) type */ { struct type *domain = read_type (pp, objfile); struct type *memtype; @@ -1949,7 +1942,7 @@ read_type (pp, objfile) } break; - case '#': + case '#': /* Method (class & fn) type */ if ((*pp)[0] == '#') { /* We'll get the parameter types from the name. */ @@ -1980,33 +1973,19 @@ read_type (pp, objfile) } break; - case '&': - type1 = read_type (pp, objfile); - type = lookup_reference_type (type1); - if (typenums[0] != -1) - *dbx_lookup_type (typenums) = type; - break; - - case 'f': - type1 = read_type (pp, objfile); - type = lookup_function_type (type1); - if (typenums[0] != -1) - *dbx_lookup_type (typenums) = type; - break; - - case 'r': + case 'r': /* Range type */ type = read_range_type (pp, typenums, objfile); if (typenums[0] != -1) *dbx_lookup_type (typenums) = type; break; - case 'e': + case 'e': /* Enumeration type */ type = dbx_alloc_type (typenums, objfile); type = read_enum_type (pp, type, objfile); *dbx_lookup_type (typenums) = type; break; - case 's': + case 's': /* Struct type */ type = dbx_alloc_type (typenums, objfile); if (!TYPE_NAME (type)) TYPE_NAME (type) = type_synonym_name; @@ -2014,7 +1993,7 @@ read_type (pp, objfile) type = read_struct_type (pp, type, objfile); break; - case 'u': + case 'u': /* Union type */ type = dbx_alloc_type (typenums, objfile); if (!TYPE_NAME (type)) TYPE_NAME (type) = type_synonym_name; @@ -2023,7 +2002,7 @@ read_type (pp, objfile) TYPE_CODE (type) = TYPE_CODE_UNION; break; - case 'a': + case 'a': /* Array type */ if (**pp != 'r') return error_type (pp); ++*pp; @@ -2041,18 +2020,6 @@ read_type (pp, objfile) if (type == 0) abort (); -#if 0 - /* If this is an overriding temporary alteration for a header file's - contents, and this type number is unknown in the global definition, - put this type into the global definition at this type number. */ - if (header_file_prev_index >= 0) - { - register struct type **tp - = explicit_lookup_type (header_file_prev_index, typenums[1]); - if (*tp == 0) - *tp = type; - } -#endif return type; } @@ -2874,9 +2841,14 @@ read_enum_type (pp, type, objfile) struct pending *osyms, *syms; int o_nsyms; +#if 0 + /* FIXME! The stabs produced by Sun CC merrily define things that ought + to be file-scope, between N_FN entries, using N_LSYM. What's a mother + to do? For now, force all enum values to file scope. */ if (within_function) symlist = &local_symbols; else +#endif symlist = &file_symbols; osyms = *symlist; o_nsyms = osyms ? osyms->nsyms : 0; diff --git a/gdb/buildsym.h b/gdb/buildsym.h index 721238417e6..8183cfc1c31 100644 --- a/gdb/buildsym.h +++ b/gdb/buildsym.h @@ -256,18 +256,10 @@ EXTERN int n_this_object_header_files; EXTERN int n_allocated_this_object_header_files; -/* When a header file is getting special overriding definitions - for one source file, record here the header_files index - of its normal definition vector. - At other times, this is -1. */ - -EXTERN int header_file_prev_index; - struct subfile_stack { struct subfile_stack *next; char *name; - int prev_index; }; EXTERN struct subfile_stack *subfile_stack; diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index fcc673aada9..2523c7697fa 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++. diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 51099bf9741..7578b446c2d 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -485,6 +485,9 @@ init_type PARAMS ((enum type_code, int, int, char *, struct objfile *)); extern struct type * lookup_reference_type PARAMS ((struct type *)); +extern struct type * +make_reference_type PARAMS ((struct type *, struct type **)); + extern struct type * lookup_member_type PARAMS ((struct type *, struct type *)); @@ -504,9 +507,15 @@ type_name_no_tag PARAMS ((const struct type *)); extern struct type * lookup_struct_elt_type PARAMS ((struct type *, char *, int)); +extern struct type * +make_pointer_type PARAMS ((struct type *, struct type **)); + extern struct type * lookup_pointer_type PARAMS ((struct type *)); +extern struct type * +make_function_type PARAMS ((struct type *, struct type **)); + extern struct type * lookup_function_type PARAMS ((struct type *)); diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index 34132551feb..addb5cf303c 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -2333,52 +2333,6 @@ _initialize_xcoffread () add_symtab_fns(&aixcoff_sym_fns); } - -/* In order to handle forward type references, we needed to have this old - routine. Try printing the type of member `p' in the following structure - in a dbx environment. - - struct s { - ... - struct s *p; - }; -*/ - - -/* Smash TYPE to be a type of pointers to TO_TYPE. - If TO_TYPE is not permanent and has no pointer-type yet, - record TYPE as its pointer-type. */ - -void -smash_to_pointer_type (type, to_type) - struct type *type, *to_type; -{ -/* int type_permanent = (TYPE_FLAGS (type) & TYPE_FLAG_PERM); */ - - bzero (type, sizeof (struct type)); - TYPE_TARGET_TYPE (type) = to_type; - /* We assume the machine has only one representation for pointers! */ - TYPE_LENGTH (type) = sizeof (char *); - TYPE_CODE (type) = TYPE_CODE_PTR; - -/* ??? TYPE_TARGET_TYPE and TYPE_MAIN_VARIANT are the same. You can't do - this. It will break the target type!!! - TYPE_MAIN_VARIANT (type) = type; - - if (type_permanent) - TYPE_FLAGS (type) |= TYPE_FLAG_PERM; -*/ - - if (TYPE_POINTER_TYPE (to_type) == 0) -#if 0 - && (!(TYPE_FLAGS (to_type) & TYPE_FLAG_PERM) - || type_permanent)) -#endif /* 0 */ - { - TYPE_POINTER_TYPE (to_type) = type; - } -} - #else /* IBM6000_HOST */ struct type * builtin_type (ignore) -- 2.30.2