From 0c4d2cc2b3a353604c3320b867ce5d471fee1ecb Mon Sep 17 00:00:00 2001 From: John Gilmore Date: Thu, 19 Sep 1991 02:32:35 +0000 Subject: [PATCH] * symfile.c (allocate_symtab): New fn, consolidates the work of allocating and initializing a new struct symtab. Set the language of the symtab based on its filename extension. * symfile.h: Declare it. * mipsread.c (new_symtab): Use it. Minor formatting changes. * dbxread.c (end_symtab): Use it. * mipsread.c (parse_symbol, case stParam and stProc): Add #if 0'd code for saving types of parameters with each function definition. * dbxread.c (define_symbol, function and parameter cases): Ditto. (read_dbx_symtab, case N_DEFD): Ignore. (read_enum_type): Recognize FALSE/TRUE enum as Modula-2 BOOLEAN type. (read_range_type): Rename MAX_OF_TYPE to MAX_OF_C_TYPE, etc. #if 0 out its uses, though, since they set a dead value. * coffread.c (end_symtab): Use allocate_symtab. (process_coff_symbol): #if 0'd for functions and params as above. (read_enum_type): Recognize Modula-2 BOOLEAN. --- gdb/dbxread.c | 139 ++++++++++++++++++++++++++++++++----------------- gdb/mipsread.c | 39 ++++++++++---- 2 files changed, 121 insertions(+), 57 deletions(-) diff --git a/gdb/dbxread.c b/gdb/dbxread.c index c40656c7bc6..6d138e0030c 100644 --- a/gdb/dbxread.c +++ b/gdb/dbxread.c @@ -326,6 +326,13 @@ int context_stack_size; int within_function; +#if 0 +/* The type of the function we are currently reading in. This is + used by define_symbol to record the type of arguments to a function. */ + +static struct type *in_function_type; +#endif + /* List of blocks already made (lexical contexts already closed). This is used at the end to make the blockvector. */ @@ -387,7 +394,7 @@ struct complaint string_table_offset_complaint = {"bad string table offset in symbol %d", 0, 0}; struct complaint unknown_symtype_complaint = - {"unknown symbol type 0x%x", 0, 0}; + {"unknown symbol type %s", 0, 0}; struct complaint lbrac_rbrac_complaint = {"block start larger than block end", 0, 0}; @@ -1137,7 +1144,7 @@ end_symtab (end_addr) for (subfile = subfiles; subfile; subfile = nextsub) { - symtab = (struct symtab *) xmalloc (sizeof (struct symtab)); + symtab = allocate_symtab (subfile->name); /* Fill in its components. */ symtab->blockvector = blockvector; @@ -1149,7 +1156,6 @@ end_symtab (end_addr) type_vector->length = type_vector_length; symtab->typevector = type_vector; - symtab->filename = subfile->name; symtab->dirname = subfile->dirname; symtab->free_code = free_linetable; @@ -1157,12 +1163,6 @@ end_symtab (end_addr) if (subfile->next == 0) symtab->free_ptr = (char *) type_vector; - symtab->nlines = 0; - symtab->line_charpos = 0; - - symtab->language = language_unknown; - symtab->fullname = NULL; - /* There should never already be a symtab for this name, since any prev dups have been removed when the psymtab was read in. FIXME, there ought to be a way to check this here. */ @@ -1236,14 +1236,18 @@ record_misc_function (name, address, type) CORE_ADDR address; int type; { - enum misc_function_type misc_type = - (type == (N_TEXT | N_EXT) ? mf_text : - (type == (N_DATA | N_EXT) - || type == (N_DATA) - || type == (N_SETV | N_EXT) - ) ? mf_data : - type == (N_BSS | N_EXT) ? mf_bss : - type == (N_ABS | N_EXT) ? mf_abs : mf_unknown); + enum misc_function_type misc_type; + + switch (type &~ N_EXT) { + case N_TEXT: misc_type = mf_text; break; + case N_DATA: misc_type = mf_data; break; + case N_BSS: misc_type = mf_bss; break; + case N_ABS: misc_type = mf_abs; break; +#ifdef N_SETV + case N_SETV: misc_type = mf_data; break; +#endif + default: misc_type = mf_unknown; break; + } prim_record_misc_function (obsavestring (name, strlen (name)), address, misc_type); @@ -1964,7 +1968,6 @@ read_dbx_symtab (symfile_name, addr, namestring, valu, first_symnum * sizeof (struct nlist), global_psymbols.next, static_psymbols.next); - continue; } @@ -2311,6 +2314,7 @@ read_dbx_symtab (symfile_name, addr, case N_LBRAC: case N_RBRAC: case N_NSYMS: /* Ultrix 4.0: symbol count */ + case N_DEFD: /* GNU Modula-2 */ /* These symbols aren't interesting; don't worry about them */ continue; @@ -2318,7 +2322,7 @@ read_dbx_symtab (symfile_name, addr, default: /* If we haven't found it yet, ignore it. It's probably some new type we don't know about yet. */ - complain (&unknown_symtype_complaint, bufp->n_type); + complain (&unknown_symtype_complaint, local_hex_string(bufp->n_type)); continue; } } @@ -2406,8 +2410,11 @@ compare_psymbols (s1, s2) *st1 = SYMBOL_NAME (s1), *st2 = SYMBOL_NAME (s2); - return (st1[0] - st2[0] ? st1[0] - st2[0] : - strcmp (st1 + 1, st2 + 1)); + if (st1[0] - st2[0]) + return st1[0] - st2[0]; + if (st1[1] - st2[1]) + return st1[1] - st2[1]; + return strcmp (st1 + 1, st2 + 1); } @@ -2757,6 +2764,7 @@ scan_file_globals () } /* Process a pair of symbols. Currently they must both be N_SO's. */ +/* ARGSUSED */ static void process_symbol_pair (type1, desc1, value1, name1, type2, desc2, value2, name2) @@ -2925,7 +2933,7 @@ read_ofile_symtab (desc, stringtab, stringtab_size, sym_offset, processing_gcc_compilation = 1; else if (type & N_EXT || type == (unsigned char)N_TEXT || type == (unsigned char)N_NBTEXT - ) + ) { /* Global symbol: see if we came across a dbx defintion for a corresponding symbol. If so, store the value. Remove syms from the chain when their values are stored, but @@ -2936,6 +2944,7 @@ read_ofile_symtab (desc, stringtab, stringtab_size, sym_offset, be satisfied in each file as it appears. So we skip this section. */ ; + } } return end_symtab (text_offset + text_size); @@ -3233,6 +3242,7 @@ process_one_symbol (type, desc, valu, name) case N_ECOML: case N_LENG: + case N_DEFD: /* GNU Modula-2 symbol */ break; default: @@ -3272,6 +3282,7 @@ read_type_number (pp, typenums) get this name). */ static char *type_synonym_name; +/* ARGSUSED */ static struct symbol * define_symbol (valu, string, desc, type) unsigned int valu; @@ -3440,7 +3451,22 @@ define_symbol (valu, string, desc, type) if ((deftype == 'F' || deftype == 'f') && TYPE_CODE (type_read) != TYPE_CODE_FUNC) + { +#if 0 +/* This code doesn't work -- it needs to realloc and can't. */ + struct type *new = (struct type *) + obstack_alloc (symbol_obstack, sizeof (struct type)); + + /* Generate a template for the type of this function. The + types of the arguments will be added as we read the symbol + table. */ + *new = *lookup_function_type (type_read); + SYMBOL_TYPE(sym) = new; + in_function_type = new; +#else SYMBOL_TYPE (sym) = lookup_function_type (type_read); +#endif + } else SYMBOL_TYPE (sym) = type_read; } @@ -3499,6 +3525,10 @@ define_symbol (valu, string, desc, type) SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type); SYMBOL_VALUE (sym) = valu; SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; +#if 0 + /* This doesn't work yet. */ + add_param_to_type (&in_function_type, sym); +#endif add_symbol_to_list (sym, &local_symbols); /* If it's gcc-compiled, if it says `short', believe it. */ @@ -3596,11 +3626,11 @@ define_symbol (valu, string, desc, type) || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION) && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym))) { - int i; - for (i = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; i >= 0; i--) - if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), i) == 0) - TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), i) = - type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), i)); + int j; + for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--) + if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0) + TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) = + type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j)); } add_symbol_to_list (sym, &file_symbols); @@ -4934,17 +4964,25 @@ read_enum_type (pp, type) j = o_nsyms; for (; j < syms->nsyms; j++,n++) { - struct symbol *sym = syms->symbol[j]; - SYMBOL_TYPE (sym) = type; - TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (sym); + struct symbol *xsym = syms->symbol[j]; + SYMBOL_TYPE (xsym) = type; + TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym); TYPE_FIELD_VALUE (type, n) = 0; - TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (sym); + TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym); TYPE_FIELD_BITSIZE (type, n) = 0; } if (syms == osyms) break; } + /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */ + if(TYPE_NFIELDS(type) == 2 && + ((!strcmp(TYPE_FIELD_NAME(type,0),"TRUE") && + !strcmp(TYPE_FIELD_NAME(type,1),"FALSE")) || + (!strcmp(TYPE_FIELD_NAME(type,1),"TRUE") && + !strcmp(TYPE_FIELD_NAME(type,0),"FALSE")))) + TYPE_CODE(type) = TYPE_CODE_BOOL; + return type; } @@ -5061,8 +5099,8 @@ read_huge_number (pp, end, valu, bits) } } -#define MAX_OF_TYPE(t) ((1 << (sizeof (t)*8 - 1)) - 1) -#define MIN_OF_TYPE(t) (-(1 << (sizeof (t)*8 - 1))) +#define MAX_OF_C_TYPE(t) ((1 << (sizeof (t)*8 - 1)) - 1) +#define MIN_OF_C_TYPE(t) (-(1 << (sizeof (t)*8 - 1))) static struct type * read_range_type (pp, typenums) @@ -5222,34 +5260,39 @@ read_range_type (pp, typenums) sizeof (struct type)); bzero (result_type, sizeof (struct type)); - TYPE_TARGET_TYPE (result_type) = (self_subrange ? - builtin_type_int : - *dbx_lookup_type(rangenums)); + TYPE_CODE (result_type) = TYPE_CODE_RANGE; + + TYPE_TARGET_TYPE (result_type) = *dbx_lookup_type(rangenums); + + TYPE_NFIELDS (result_type) = 2; + TYPE_FIELDS (result_type) = + (struct field *) obstack_alloc (symbol_obstack, + 2 * sizeof (struct field)); + bzero (TYPE_FIELDS (result_type), 2 * sizeof (struct field)); + TYPE_FIELD_BITPOS (result_type, 0) = n2; + TYPE_FIELD_BITPOS (result_type, 1) = n3; +#if 0 +/* Note that TYPE_LENGTH (result_type) is just overridden a few + statements down. What do we really need here? */ /* We have to figure out how many bytes it takes to hold this range type. I'm going to assume that anything that is pushing the bounds of a long was taken care of above. */ - if (n2 >= MIN_OF_TYPE(char) && n3 <= MAX_OF_TYPE(char)) + if (n2 >= MIN_OF_C_TYPE(char) && n3 <= MAX_OF_C_TYPE(char)) TYPE_LENGTH (result_type) = 1; - else if (n2 >= MIN_OF_TYPE(short) && n3 <= MAX_OF_TYPE(short)) + else if (n2 >= MIN_OF_C_TYPE(short) && n3 <= MAX_OF_C_TYPE(short)) TYPE_LENGTH (result_type) = sizeof (short); - else if (n2 >= MIN_OF_TYPE(int) && n3 <= MAX_OF_TYPE(int)) + else if (n2 >= MIN_OF_C_TYPE(int) && n3 <= MAX_OF_C_TYPE(int)) TYPE_LENGTH (result_type) = sizeof (int); - else if (n2 >= MIN_OF_TYPE(long) && n3 <= MAX_OF_TYPE(long)) + else if (n2 >= MIN_OF_C_TYPE(long) && n3 <= MAX_OF_C_TYPE(long)) TYPE_LENGTH (result_type) = sizeof (long); else /* Ranged type doesn't fit within known sizes. */ + /* FIXME -- use "long long" here. */ return error_type (pp); +#endif TYPE_LENGTH (result_type) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type)); - TYPE_CODE (result_type) = TYPE_CODE_RANGE; - TYPE_NFIELDS (result_type) = 2; - TYPE_FIELDS (result_type) = - (struct field *) obstack_alloc (symbol_obstack, - 2 * sizeof (struct field)); - bzero (TYPE_FIELDS (result_type), 2 * sizeof (struct field)); - TYPE_FIELD_BITPOS (result_type, 0) = n2; - TYPE_FIELD_BITPOS (result_type, 1) = n3; return result_type; } diff --git a/gdb/mipsread.c b/gdb/mipsread.c index c966d194829..371c92419da 100644 --- a/gdb/mipsread.c +++ b/gdb/mipsread.c @@ -273,7 +273,8 @@ mipscoff_symfile_read(sf, addr, mainline) /* Exported procedure: Allocate zeroed memory */ -char *xzalloc(size) +char * +xzalloc(size) { char *p = xmalloc(size); @@ -841,6 +842,12 @@ data: /* Common code for symbols describing data */ SYMBOL_VALUE(s) = sh->value; SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0); add_symbol(s, top_stack->cur_block); +#if 0 + /* FIXME: This has not been tested. See dbxread.c */ + /* Add the type of this parameter to the function/procedure + type of this block. */ + add_param_to_type(&top_stack->cur_block->function->type,s); +#endif break; case stLabel: /* label, goes into current block */ @@ -852,7 +859,7 @@ data: /* Common code for symbols describing data */ add_symbol(s, top_stack->cur_block); break; - case stProc: /* Procedure, goes into current block? FIXME */ + case stProc: /* Procedure, usually goes into global block */ case stStaticProc: /* Static procedure, goes into current block */ s = new_symbol(sh->iss); SYMBOL_NAMESPACE(s) = VAR_NAMESPACE; @@ -862,10 +869,27 @@ data: /* Common code for symbols describing data */ t = builtin_type_int; else t = parse_type(ax + sh->index, sh, 0); - add_symbol(s, top_stack->cur_block); + b = top_stack->cur_block; + if (sh->st == stProc) { + struct blockvector *bv = BLOCKVECTOR(top_stack->cur_st); + /* The next test should normally be true, + but provides a hook for nested functions + (which we don't want to make global). */ + if (b == BLOCKVECTOR_BLOCK(bv, STATIC_BLOCK)) + b = BLOCKVECTOR_BLOCK(bv, GLOBAL_BLOCK); + } + add_symbol(s, b); /* Make a type for the procedure itself */ +#if 0 + /* FIXME: This has not been tested yet! See dbxread.c */ + /* Generate a template for the type of this function. The + types of the arguments will be added as we read the symbol + table. */ + bcopy(SYMBOL_TYPE(s),lookup_function_type(t),sizeof(struct type)); +#else SYMBOL_TYPE(s) = lookup_function_type (t); +#endif /* Create and enter a new lexical context */ b = new_block(top_stack->maxsyms); @@ -1543,7 +1567,7 @@ parse_partial_symbols(end_of_text_seg) * * Only parse the Local and External symbols, and the Relative FDR. * Fixup enough of the loader symtab to be able to use it. - * Allocate space only for the file`s portions we need to + * Allocate space only for the file's portions we need to * look at. (XXX) */ @@ -2337,13 +2361,10 @@ struct symtab * new_symtab(name, maxsyms, maxlines) char *name; { - struct symtab *s = (struct symtab *) xzalloc(sizeof(struct symtab)); - int i; + struct symtab *s = allocate_symtab (name); LINETABLE(s) = new_linetable(maxlines); - s->filename = name; - /* All symtabs must have at least two blocks */ BLOCKVECTOR(s) = new_bvect(2); BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK) = new_block(maxsyms); @@ -2380,7 +2401,7 @@ new_psymtab(name) pst->next = partial_symtab_list; partial_symtab_list = pst; - /* Keep a backpointer to the file`s symbols */ + /* Keep a backpointer to the file's symbols */ /* FIXME, we should use private data that is a proper pointer. */ pst->ldsymlen = (int)cur_hdr; -- 2.30.2