From: John Gilmore Date: Sun, 29 Mar 1992 23:17:36 +0000 (+0000) Subject: Create and use macros for iterating on symtabs, psymtabs, msymbols. X-Git-Tag: gdb-4_18~22130 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=84ffdec2cbfe29d96552e3bb392bdad524b57eca;p=platform%2Fupstream%2Fbinutils.git Create and use macros for iterating on symtabs, psymtabs, msymbols. * minsyms.c (iterate_over_msymbols): Remove; clunky and slow. * symfile.h, symtab.h (iterate_over_msymbols): Remove prototype * coffread.c (coff_symfile_read): iterate_over_symtabs => ALL_SYMTABS. (patch_opaque_types): Avoid dummy args and result. * objfiles.c (have_partial_symbols, have_full_symbols, have_minimal_symbols): explicit iteration => ALL_OBJFILES; simplify. (iterate_over_objfiles, iterate_over_symtabs, iterate_over_psymtabs): Remove, clunky and slow. * objfiles.h: Replace iterate_over_* prototypes with ALL_SYMTABS, ALL_PSYMTABS, and ALL_MSYMBOLS macros. * symmisc.c (dump_symtab, dump_psymtab, dump_msymbols, dump_objfile): Remove dummy args and results. Move filename comparisons to callers. (printsyms_command, printpsyms_command, printmsyms_command, printobjfiles_command): iterate_over_* => ALL_*. Compare filenames. * symtab.c (lookup_symtab_1, lookup_symtab, lookup_partial_symtab, lookup_symbol, find_main_psymtab, find_pc_symtab, sources_info, list_symbols, make_symbol_completion_list): Replace explicit iteration with ALL_SYMTABS, ALL_PSYMTABS, or ALL_MSYMBOLS. Eliminate Dijkstra flag crap, break out of loops with gotos. (lookup_symtab_1): Protect '/' tests from short filenames. (cplus_mangled_symbol): Move inline into lookup_symbol. * xcoffexec.c (relocate_objfile_msymbols): Remove poor hack. (relocate_minimal_symbol): Move inline to vmap_symtab. (vmap_symtab): Replace iteration with ALL_OBJFILES, iterate_over_msymbols with ALL_MSYMBOLS. Misc cleanup prior to release. * dwarfread.c (dwarf_build_psymtabs): Remove mainline test. * mipsread.c (compare_symtabs, compare_psymtabs): Remove, unused. * mipsread.c: Add prototypes for all static functions. * symmisc.c (dump_symtab_lines, dump_symtabs, dump_last_symtab, dump_blockvector, dump_block, dump_addrchass, dump_namespace, dump_symbol, dump_type, dump_linetable, dump_strtbl): Remove, unused. * xcoffread.c (dump_symtab_lines, dump_symtabs, dump_last_symtab, dump_blockvector, dump_block, dump_addrchass, dump_namespace, dump_symbol, dump_type, dump_linetable, dump_strtbl): Remove 2nd unused copy! * buildsym.c (define_symbol): Handle global register variables (from Pierre Willard). Complain if register numbers are too large. --- diff --git a/gdb/buildsym.c b/gdb/buildsym.c index a104eb5..20ffa40 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -147,6 +147,9 @@ struct complaint invalid_member_complaint = struct complaint range_type_base_complaint = {"base type %d of range type is not defined", 0, 0}; + +struct complaint reg_value_complaint = + {"register number too large in symbol %s", 0, 0}; int hashname (name) @@ -340,7 +343,7 @@ really_free_pendings (foo) for (next = free_pendings; next; next = next1) { next1 = next->next; - free (next); + free ((PTR)next); } free_pendings = 0; @@ -348,7 +351,7 @@ really_free_pendings (foo) for (bnext = pending_blocks; bnext; bnext = bnext1) { bnext1 = bnext->next; - free (bnext); + free ((PTR)bnext); } #endif pending_blocks = 0; @@ -356,14 +359,14 @@ really_free_pendings (foo) for (next = file_symbols; next; next = next1) { next1 = next->next; - free (next); + free ((PTR)next); } file_symbols = 0; for (next = global_symbols; next; next = next1) { next1 = next->next; - free (next); + free ((PTR)next); } global_symbols = 0; } @@ -607,7 +610,7 @@ pop_subfile () name = link->name; subfile_stack = link->next; header_file_prev_index = link->prev_index; - free (link); + free ((PTR)link); return name; } @@ -820,7 +823,7 @@ end_symtab (end_addr, sort_pending, sort_linevec, objfile) if (global_stabs) { patch_block_stabs (global_symbols, global_stabs, objfile); - free (global_stabs); + free ((PTR)global_stabs); global_stabs = 0; } @@ -892,10 +895,10 @@ end_symtab (end_addr, sort_pending, sort_linevec, objfile) #endif } if (subfile->line_vector) - free (subfile->line_vector); + free ((PTR)subfile->line_vector); nextsub = subfile->next; - free (subfile); + free ((PTR)subfile); } #ifdef IBM6000_TARGET @@ -1393,17 +1396,32 @@ define_symbol (valu, string, desc, type, objfile) #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */ case 'P': + /* Parameter which is in a register. */ SYMBOL_CLASS (sym) = LOC_REGPARM; SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu); + if (SYMBOL_VALUE (sym) >= NUM_REGS) + { + complain (®_value_complaint, SYMBOL_NAME (sym)); + SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */ + } SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; add_symbol_to_list (sym, &local_symbols); break; case 'r': + /* Register variable (either global or local). */ SYMBOL_CLASS (sym) = LOC_REGISTER; SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu); + if (SYMBOL_VALUE (sym) >= NUM_REGS) + { + complain (®_value_complaint, SYMBOL_NAME (sym)); + SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */ + } SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; - add_symbol_to_list (sym, &local_symbols); + if (within_function) + add_symbol_to_list (sym, &local_symbols); + else + add_symbol_to_list (sym, &file_symbols); break; case 'S': @@ -2631,7 +2649,9 @@ read_struct_type (pp, type, objfile) for the derived classes, but for the fact that by then, we don't remember who needs what. */ +#if 0 int predicted_fieldno = -1; +#endif /* Now we must record the virtual function table pointer's field information. */ @@ -3164,14 +3184,14 @@ read_range_type (pp, typenums, objfile) /* a signed type */ /* FIXME -- the only way to distinguish `int' from `long' is to look at its name! */ - if ((n3 == (1 << (8 * sizeof (long) - 1)) - 1) && + if ((n3 ==(long)(((unsigned long)1 << (8 * sizeof (long) - 1)) - 1)) && long_kludge_name && long_kludge_name[0] == 'l' /* long */) return (lookup_fundamental_type (objfile, FT_LONG)); - if (n3 == (1 << (8 * sizeof (int) - 1)) - 1) + if (n3 == (long)(((unsigned long)1 << (8 * sizeof (int) - 1)) - 1)) return (lookup_fundamental_type (objfile, FT_INTEGER)); - if (n3 == (1 << (8 * sizeof (short) - 1)) - 1) + if (n3 == ( 1 << (8 * sizeof (short) - 1)) - 1) return (lookup_fundamental_type (objfile, FT_SHORT)); - if (n3 == (1 << (8 * sizeof (char) - 1)) - 1) + if (n3 == ( 1 << (8 * sizeof (char) - 1)) - 1) return (lookup_fundamental_type (objfile, FT_CHAR)); } diff --git a/gdb/dwarfread.c b/gdb/dwarfread.c index 269a691..7923fdb 100644 --- a/gdb/dwarfread.c +++ b/gdb/dwarfread.c @@ -57,12 +57,14 @@ other things to work on, if you get bored. :-) #include "defs.h" #include #include +#include #include "bfd.h" #include "symtab.h" #include "gdbtypes.h" #include "symfile.h" #include "objfiles.h" +#include "libbfd.h" /* FIXME Secret Internal BFD stuff (bfd_read) */ #include "elf/dwarf.h" #include "buildsym.h" @@ -310,7 +312,7 @@ read_structure_scope PARAMS ((struct dieinfo *, char *, char *, struct objfile *)); static struct type * -decode_array_element_type PARAMS ((char *, char *)); +decode_array_element_type PARAMS ((char *)); static struct type * decode_subscr_data PARAMS ((char *, char *)); @@ -436,17 +438,9 @@ dwarf_build_psymtabs (desc, filename, addr, mainline, dbfoff, dbsize, init_psymbol_list (objfile, 1024); } - /* From this point on, we don't need to pass mainline around, so zap - baseaddr to zero if we don't need relocation. */ + /* Save the relocation factor where everybody can see it. */ - if (mainline) - { - baseaddr = 0; - } - else - { - baseaddr = addr; - } + baseaddr = addr; /* Follow the compilation unit sibling chain, building a partial symbol table entry for each one. Save enough information about each compilation @@ -934,15 +928,15 @@ DESCRIPTION */ static struct type * -decode_array_element_type (scan, end) +decode_array_element_type (scan) char *scan; - char *end; { struct type *typep; short attribute; DIEREF dieref; unsigned short fundtype; + /* FIXME, does this confuse the host and target sizeof's? --gnu */ (void) memcpy (&attribute, scan, sizeof (short)); scan += sizeof (short); switch (attribute) @@ -1020,7 +1014,7 @@ decode_subscr_data (scan, end) switch (format) { case FMT_ET: - typep = decode_array_element_type (scan, end); + typep = decode_array_element_type (scan); break; case FMT_FT_C_C: (void) memcpy (&fundtype, scan, sizeof (short)); @@ -1865,7 +1859,7 @@ read_ofile_symtab (pst) if (LNFOFF (pst)) { if (bfd_seek (abfd, LNFOFF (pst), 0) || - (bfd_read (&lnsize, sizeof(long), 1, abfd) != sizeof(long))) + (bfd_read ((PTR)&lnsize, sizeof(long), 1, abfd) != sizeof(long))) { error ("can't read DWARF line number table size"); } @@ -2043,11 +2037,11 @@ init_psymbol_list (objfile, total_symbols) if (objfile -> global_psymbols.list) { - mfree (objfile -> md, objfile -> global_psymbols.list); + mfree (objfile -> md, (PTR)objfile -> global_psymbols.list); } if (objfile -> static_psymbols.list) { - mfree (objfile -> md, objfile -> static_psymbols.list); + mfree (objfile -> md, (PTR)objfile -> static_psymbols.list); } /* Current best guess is that there are approximately a twentieth diff --git a/gdb/minsyms.c b/gdb/minsyms.c index 760ea75..6810d9a 100644 --- a/gdb/minsyms.c +++ b/gdb/minsyms.c @@ -76,42 +76,6 @@ compare_minimal_symbols PARAMS ((const void *, const void *)); static int compact_minimal_symbols PARAMS ((struct minimal_symbol *, int)); -/* Call the function specified by FUNC for each currently available minimal - symbol, for as long as this function continues to return NULL. If the - function ever returns non-NULL, then the iteration over the minimal - symbols is terminated and the result is returned to the caller. - - The function called has full control over the form and content of the - information returned via the non-NULL result, which may be as simple as a - pointer to the minimal symbol that the iteration terminated on, or as - complex as a pointer to a private structure containing multiple results. */ - -PTR -iterate_over_msymbols (func, arg1, arg2, arg3) - PTR (*func) PARAMS ((struct objfile *, struct minimal_symbol *, - PTR, PTR, PTR)); - PTR arg1; - PTR arg2; - PTR arg3; -{ - register struct objfile *objfile; - register struct minimal_symbol *msymbol; - char *result = NULL; - - for (objfile = object_files; - objfile != NULL && result == NULL; - objfile = objfile -> next) - { - for (msymbol = objfile -> msymbols; - msymbol != NULL && msymbol -> name != NULL && result == NULL; - msymbol++) - { - result = (*func)(objfile, msymbol, arg1, arg2, arg3); - } - } - return (result); -} - /* Look through all the current minimal symbol tables and find the first minimal symbol that matches NAME. If OBJF is non-NULL, it specifies a particular objfile and the search is limited to that objfile. Returns @@ -345,7 +309,7 @@ discard_minimal_symbols (foo) while (msym_bunch != NULL) { next = msym_bunch -> next; - free (msym_bunch); + free ((PTR)msym_bunch); msym_bunch = next; } } diff --git a/gdb/mipsread.c b/gdb/mipsread.c index e07203f..f5fae21 100644 --- a/gdb/mipsread.c +++ b/gdb/mipsread.c @@ -71,7 +71,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #endif /* not CMUCS */ #include "coff/mips.h" -#include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */ +#include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */ #include "aout/aout64.h" #include "aout/stab_gnu.h" /* We always use GNU stabs, not native, now */ #include "coff/ecoff-ext.h" @@ -209,50 +209,88 @@ struct type *builtin_type_string; /* Forward declarations */ static void -fixup_symtab (); +fixup_symtab PARAMS ((HDRR *, char *, int, bfd *)); static void -read_mips_symtab (); +read_mips_symtab PARAMS ((struct objfile *, int)); + +static void +read_the_mips_symtab PARAMS ((bfd *, int, CORE_ADDR)); + +static int +upgrade_type PARAMS ((struct type **, int, union aux_ent *, int)); + +static void +parse_partial_symbols PARAMS ((int, struct objfile *)); static int -upgrade_type (); +cross_ref PARAMS ((union aux_ext *, struct type **, int, char **, int)); + +static void +fixup_sigtramp PARAMS ((void)); + +static struct symbol * +new_symbol PARAMS ((char *)); + +static struct type * +new_type PARAMS ((char *)); + +static struct block * +new_block PARAMS ((int)); + +static struct symtab * +new_symtab PARAMS ((char *, int, int, struct objfile *)); + +static struct linetable * +new_linetable PARAMS ((int)); + +static struct blockvector * +new_bvect PARAMS ((int)); + +static struct type * +parse_type PARAMS ((union aux_ext *, int *, int)); + +static struct symbol * +mylookup_symbol PARAMS ((char *, struct block *, enum namespace, + enum address_class)); + +static struct block * +shrink_block PARAMS ((struct block *, struct symtab *)); + +static PTR +xzalloc PARAMS ((unsigned int)); static void -parse_partial_symbols(); +sort_blocks PARAMS ((struct symtab *)); static int -cross_ref(); +compare_blocks PARAMS ((struct block **, struct block **)); + +static struct partial_symtab * +new_psymtab PARAMS ((char *, struct objfile *)); + +#if 0 +static struct partial_symtab * +parse_fdr PARAMS ((int, int, struct objfile *)); +#endif static void -fixup_sigtramp(); - -static struct symbol *new_symbol(); -static struct type *new_type(); -static struct block *new_block(); -static struct symtab *new_symtab(); -static struct linetable *new_linetable(); -static struct blockvector *new_bvect(); - -static struct type *parse_type(); -static struct symbol *mylookup_symbol(); -static struct block *shrink_block(); -static void sort_blocks(); - -static int compare_symtabs(); -static int compare_psymtabs(); -static int compare_blocks(); - -static struct partial_symtab *new_psymtab(); -static struct partial_symtab *parse_fdr(); -static int compare_psymbols(); - -static void psymtab_to_symtab_1(); -static void add_block(); -static void add_symbol(); -static int add_line(); -static struct linetable *shrink_linetable(); -static char* mips_next_symbol_text (); +psymtab_to_symtab_1 PARAMS ((struct partial_symtab *, char *)); +static void +add_block PARAMS ((struct block *, struct symtab *)); + +static void +add_symbol PARAMS ((struct symbol *, struct block *)); + +static int +add_line PARAMS ((struct linetable *, int, CORE_ADDR, int)); + +static struct linetable * +shrink_linetable PARAMS ((struct linetable *)); + +static char * +mips_next_symbol_text PARAMS ((void)); /* Things we export to other modules */ @@ -262,8 +300,8 @@ static char* mips_next_symbol_text (); CORE_ADDR sigtramp_address, sigtramp_end; void -mipscoff_new_init (objfile) - struct objfile *objfile; +mipscoff_new_init (ignore) + struct objfile *ignore; { } @@ -323,17 +361,18 @@ mipscoff_symfile_finish (objfile) if (cur_hdr) { - free ((char *)cur_hdr); + free ((PTR)cur_hdr); } cur_hdr = 0; } /* Allocate zeroed memory */ -static char * +static PTR xzalloc(size) + int size; { - char *p = xmalloc(size); + PTR p = xmalloc(size); memset(p, 0, size); return p; @@ -348,8 +387,6 @@ static void mipscoff_psymtab_to_symtab(pst) struct partial_symtab *pst; { - struct symtab *ret; - int i; if (!pst) return; @@ -376,9 +413,9 @@ mipscoff_psymtab_to_symtab(pst) /* Exported procedure: Is PC in the signal trampoline code */ int -in_sigtramp(pc, name) +in_sigtramp(pc, ignore) CORE_ADDR pc; - char *name; + char *ignore; /* function name */ { if (sigtramp_address == 0) fixup_sigtramp(); @@ -390,9 +427,9 @@ in_sigtramp(pc, name) /* Read the symtab information from file FSYM into memory. Also, return address just past end of our text segment in *END_OF_TEXT_SEGP. */ -static +static void read_the_mips_symtab(abfd, fsym, end_of_text_segp) - bfd *abfd; + bfd *abfd; int fsym; CORE_ADDR *end_of_text_segp; { @@ -416,7 +453,7 @@ read_the_mips_symtab(abfd, fsym, end_of_text_segp) st_hdrsize = bfd_h_get_32 (abfd, filhdr.f.f_nsyms); st_filptr = bfd_h_get_32 (abfd, filhdr.f.f_symptr); if (st_filptr == 0) - return 0; + return; lseek(fsym, st_filptr, L_SET); if (st_hdrsize != sizeof (hdr_ext)) { /* Profanity check */ @@ -434,7 +471,7 @@ read_the_mips_symtab(abfd, fsym, end_of_text_segp) /* Allocate space for the symbol table. Read it in. */ cur_hdr = (HDRR *) xmalloc(stsize + st_hdrsize); - memcpy(cur_hdr, &hdr_ext, st_hdrsize); + memcpy((PTR)cur_hdr, (PTR)&hdr_ext, st_hdrsize); if (read(fsym, (char *) cur_hdr + st_hdrsize, stsize) != stsize) goto readerr; @@ -769,22 +806,6 @@ struct mips_pending *is_pending_symbol(fh, sh) return p; } -/* Check whether we already saw type T in file FH as undefined */ - -static -struct mips_pending *is_pending_type(fh, t) - FDR *fh; - struct type *t; -{ - int f_idx = fh - (FDR *) cur_hdr->cbFdOffset; - register struct mips_pending *p; - - for (p = pending_list[f_idx]; p; p = p->next) - if (p->t == t) - break; - return p; -} - /* Add a new undef symbol SH of type T */ static @@ -808,6 +829,7 @@ add_pending(fh, sh, t) } /* Throw away undef entries when done with file index F_IDX */ +/* FIXME -- storage leak. This is never called!!! --gnu */ static free_pending(f_idx) @@ -816,7 +838,7 @@ free_pending(f_idx) for (p = pending_list[f_idx]; p; p = q) { q = p->next; - free(p); + free((PTR)p); } pending_list[f_idx] = 0; } @@ -857,6 +879,7 @@ lookup_numargs(adr) } /* Release storage when done with this file */ +/* FIXME -- storage leak. This is never called! --gnu */ static void free_numargs() @@ -865,7 +888,7 @@ free_numargs() while (n) { m = n->next; - free(n); + free((PTR)n); n = m; } numargs_list = 0; @@ -1172,7 +1195,8 @@ data: /* Common code for symbols describing data */ if (pend) t = is_pending_symbol(cur_fdr, sh)->t; else - t = new_type(prepend_tag_kind(sh->iss, type_code)); + t = new_type(prepend_tag_kind((char *)sh->iss, + type_code)); TYPE_CODE(t) = type_code; TYPE_LENGTH(t) = sh->value; @@ -1193,7 +1217,7 @@ data: /* Common code for symbols describing data */ enum_sym = (struct symbol *) obstack_alloc (¤t_objfile->symbol_obstack, sizeof (struct symbol)); - memset (enum_sym, 0, sizeof (struct symbol)); + memset ((PTR)enum_sym, 0, sizeof (struct symbol)); SYMBOL_NAME (enum_sym) = f->name; SYMBOL_CLASS (enum_sym) = LOC_CONST; SYMBOL_TYPE (enum_sym) = t; @@ -1303,7 +1327,8 @@ data: /* Common code for symbols describing data */ We must byte-swap the AX entries before we use them; BIGEND says whether they are big-endian or little-endian (from fh->fBigendian). */ -static struct type *parse_type(ax, bs, bigend) +static struct type * +parse_type(ax, bs, bigend) union aux_ext *ax; int *bs; int bigend; @@ -1343,7 +1368,6 @@ static struct type *parse_type(ax, bs, bigend) TIR t[1]; struct type *tp = 0; char *fmt; - int i; union aux_ext *tax; int type_code; @@ -1443,8 +1467,6 @@ static struct type *parse_type(ax, bs, bigend) /* Deal with range types */ if (t->bt == btRange) { - struct field *f; - TYPE_NFIELDS (tp) = 2; TYPE_FIELDS (tp) = (struct field *) obstack_alloc (¤t_objfile -> type_obstack, @@ -1491,6 +1513,7 @@ again: PARSE_TQ(tq0); static int upgrade_type(tpp, tq, ax, bigend) struct type **tpp; + int tq; union aux_ext *ax; int bigend; { @@ -1535,16 +1558,16 @@ upgrade_type(tpp, tq, ax, bigend) /* FIXME - Memory leak! */ if (TYPE_NFIELDS(t)) TYPE_FIELDS(t) = (struct field*) - xrealloc((char *) TYPE_FIELDS(t), + xrealloc((PTR) TYPE_FIELDS(t), (TYPE_NFIELDS(t)+1) * sizeof(struct field)); else TYPE_FIELDS(t) = (struct field*) xzalloc(sizeof(struct field)); f = &(TYPE_FIELD(t,TYPE_NFIELDS(t))); TYPE_NFIELDS(t)++; - memset(f, 0, sizeof(struct field)); + memset((PTR)f, 0, sizeof(struct field)); -/* XXX */ f->type = parse_type(fh->iauxBase + id * sizeof(union aux_ext), +/* XXX */ f->type = parse_type(id + (union aux_ext *)fh->iauxBase, &f->bitsize, bigend); ax++; @@ -1689,7 +1712,7 @@ parse_external(es, skip_procedures, bigend) n_undef_symbols++; if (info_verbose) printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what, - es->asym.iss, fdr_name(cur_fdr->rss)); + es->asym.iss, fdr_name((char *)cur_fdr->rss)); return; } @@ -1727,7 +1750,7 @@ parse_lines(fh, lt) struct linetable *lt; { unsigned char *base = (unsigned char*)fh->cbLineOffset; - int i, j, k; + int j, k; int delta, count, lineno = 0; PDR *pr; @@ -1735,7 +1758,7 @@ parse_lines(fh, lt) return; /* Scan by procedure descriptors */ - i = 0; j = 0, k = 0; + j = 0, k = 0; for (pr = (PDR*)IPDFIRST(cur_hdr,fh); j < fh->cpd; j++, pr++) { int l, halt; @@ -1799,7 +1822,6 @@ parse_partial_symbols(end_of_text_seg, objfile) HDRR *hdr = cur_hdr; /* Running pointers */ FDR *fh; - RFDT *rh; register EXTR *esh; register SYMR *sh; struct partial_symtab *pst; @@ -1896,7 +1918,7 @@ parse_partial_symbols(end_of_text_seg, objfile) complain (&unknown_ext_complaint, (char *)(esh->asym.iss)); } - prim_record_minimal_symbol ((char *)(esh->asym.iss), + prim_record_minimal_symbol ((char *)esh->asym.iss, esh->asym.value, ms_type); } @@ -2234,7 +2256,7 @@ psymtab_to_symtab_1(pst, filename) char *filename; { int have_stabs; - int i, f_max; + int i, f_max; struct symtab *st; FDR *fh; int maxlines; @@ -2327,12 +2349,9 @@ psymtab_to_symtab_1(pst, filename) if (fh) { SYMR *sh; PDR *pr; - int f_idx = cur_fd; - char *fh_name = (char*)fh->rss; /* Parse local symbols first */ - if (have_stabs) { if (fh->csym <= 2) { @@ -2360,7 +2379,8 @@ psymtab_to_symtab_1(pst, filename) : fh[1].adr; for (cur_sdx = 0; cur_sdx < fh->csym; ) { sh = (SYMR *) (fh->isymBase) + cur_sdx; - cur_sdx += parse_symbol(sh, fh->iauxBase, fh->fBigendian); + cur_sdx += parse_symbol(sh, (union aux_ent *)fh->iauxBase, + fh->fBigendian); } /* Procedures next, note we need to look-ahead to @@ -2521,7 +2541,8 @@ mylookup_symbol (name, block, namespace, class) return sym; bot++; } - if (block = BLOCK_SUPERBLOCK (block)) + block = BLOCK_SUPERBLOCK (block); + if (block) return mylookup_symbol (name, block, namespace, class); return 0; } @@ -2571,7 +2592,7 @@ add_block(b,s) { struct blockvector *bv = BLOCKVECTOR(s); - bv = (struct blockvector *)xrealloc((char *) bv, + bv = (struct blockvector *)xrealloc((PTR) bv, sizeof(struct blockvector) + BLOCKVECTOR_NBLOCKS(bv) * sizeof(bv->block)); @@ -2602,49 +2623,13 @@ add_line(lt, lineno, adr, last) lt->item[lt->nitems++].pc = adr << 2; return lineno; } - - -/* Comparison functions, used when sorting things */ - -/* Symtabs must be ordered viz the code segments they cover */ - -static int -compare_symtabs( s1, s2) - struct symtab **s1, **s2; -{ - /* "most specific" first */ - - register struct block *b1, *b2; - b1 = BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1),GLOBAL_BLOCK); - b2 = BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2),GLOBAL_BLOCK); - if (BLOCK_END(b1) == BLOCK_END(b2)) - return BLOCK_START(b1) - BLOCK_START(b2); - return BLOCK_END(b1) - BLOCK_END(b2); -} - - -/* Partial Symtabs, same */ - -static int -compare_psymtabs( s1, s2) - struct partial_symtab **s1, **s2; -{ - /* Perf twist: put the ones with no code at the end */ - - register int a = (*s1)->textlow; - register int b = (*s2)->textlow; - if (a == 0) - return b; - if (b == 0) - return -a; - return a - b; -} - +/* Sorting and reordering procedures */ /* Blocks with a smaller low bound should come first */ -static int compare_blocks(b1,b2) +static int +compare_blocks(b1, b2) struct block **b1, **b2; { register int addr_diff; @@ -2655,9 +2640,6 @@ static int compare_blocks(b1,b2) return addr_diff; } - -/* Sorting and reordering procedures */ - /* Sort the blocks of a symtab S. Reorder the blocks in the blockvector by code-address, as required by some MI search routines */ @@ -2762,31 +2744,36 @@ new_psymtab(name, objfile) } -/* Allocate a linetable array of the given SIZE */ +/* Allocate a linetable array of the given SIZE. Since the struct + already includes one item, we subtract one when calculating the + proper size to allocate. */ static struct linetable * new_linetable(size) + int size; { struct linetable *l; - size = size * sizeof(l->item) + sizeof(struct linetable); + size = (size-1) * sizeof(l->item) + sizeof(struct linetable); l = (struct linetable *)xmalloc(size); l->nitems = 0; return l; } /* Oops, too big. Shrink it. This was important with the 2.4 linetables, - I am not so sure about the 3.4 ones */ + I am not so sure about the 3.4 ones. + + Since the struct linetable already includes one item, we subtract one when + calculating the proper size to allocate. */ static struct linetable * shrink_linetable(lt) struct linetable * lt; { - struct linetable *l = new_linetable(lt->nitems); - memcpy(l, lt, lt->nitems * sizeof(l->item) + sizeof(struct linetable)); - free (lt); - return l; + return (struct linetable *) xrealloc ((PTR)lt, + sizeof(struct linetable) + + (lt->nitems - 1) * sizeof(lt->item)); } /* Allocate and zero a new blockvector of NBLOCKS blocks. */ @@ -2794,6 +2781,7 @@ shrink_linetable(lt) static struct blockvector * new_bvect(nblocks) + int nblocks; { struct blockvector *bv; int size; @@ -2811,11 +2799,11 @@ new_bvect(nblocks) static struct block * new_block(maxsyms) + int maxsyms; { int size = sizeof(struct block) + (maxsyms-1) * sizeof(struct symbol *); - struct block *b = (struct block *)xzalloc(size); - return b; + return (struct block *)xzalloc (size); } /* Ooops, too big. Shrink block B in symtab S to its minimal size. @@ -2832,8 +2820,8 @@ shrink_block(b, s) /* Just reallocate it and fix references to the old one */ - new = (struct block *) xrealloc ((char *)b, sizeof(struct block) + - (BLOCK_NSYMS(b)-1) * sizeof(struct symbol *)); + new = (struct block *) xrealloc ((PTR)b, sizeof(struct block) + + (BLOCK_NSYMS(b)-1) * sizeof(struct symbol *)); /* Should chase pointers to old one. Fortunately, that`s just the block`s function and inferior blocks */ @@ -2857,7 +2845,7 @@ new_symbol(name) struct symbol *s = (struct symbol *) obstack_alloc (¤t_objfile->symbol_obstack, sizeof (struct symbol)); - memset (s, 0, sizeof (*s)); + memset ((PTR)s, 0, sizeof (*s)); SYMBOL_NAME(s) = name; return s; } @@ -2961,11 +2949,13 @@ fixup_sigtramp() e->fregoffset = -(37 * sizeof(int)); e->isym = (long)s; + current_objfile = st->objfile; /* Keep new_symbol happy */ s = new_symbol(".gdbinfo."); SYMBOL_VALUE(s) = (int) e; SYMBOL_NAMESPACE(s) = LABEL_NAMESPACE; SYMBOL_CLASS(s) = LOC_CONST; SYMBOL_TYPE(s) = builtin_type_void; + current_objfile = NULL; } BLOCK_SYM(b,BLOCK_NSYMS(b)++) = s; diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 66bfd56..faf9e96 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -272,17 +272,15 @@ int have_partial_symbols () { struct objfile *ofp; - int havethem = 0; - for (ofp = object_files; ofp; ofp = ofp -> next) + ALL_OBJFILES (ofp) { if (ofp -> psymtabs != NULL) { - havethem++; - break; + return 1; } } - return (havethem); + return 0; } /* Many places in gdb want to test just to see if we have any full @@ -293,17 +291,15 @@ int have_full_symbols () { struct objfile *ofp; - int havethem = 0; - for (ofp = object_files; ofp; ofp = ofp -> next) + ALL_OBJFILES (ofp) { if (ofp -> symtabs != NULL) { - havethem++; - break; + return 1; } } - return (havethem); + return 0; } /* Many places in gdb want to test just to see if we have any minimal @@ -314,119 +310,17 @@ int have_minimal_symbols () { struct objfile *ofp; - int havethem = 0; - for (ofp = object_files; ofp; ofp = ofp -> next) + ALL_OBJFILES (ofp) { if (ofp -> msymbols != NULL) { - havethem++; - break; + return 1; } } - return (havethem); + return 0; } -/* Call the function specified by FUNC for each currently available objfile, - for as long as this function continues to return NULL. If the function - ever returns non-NULL, then the iteration over the objfiles is terminated, - and the result is returned to the caller. The function called has full - control over the form and content of the information returned via the - non-NULL result, which may be as simple as a pointer to the objfile that - the iteration terminated on, or as complex as a pointer to a private - structure containing multiple results. */ - -PTR -iterate_over_objfiles (func, arg1, arg2, arg3) - PTR (*func) PARAMS ((struct objfile *, PTR, PTR, PTR)); - PTR arg1; - PTR arg2; - PTR arg3; -{ - register struct objfile *objfile; - PTR result = NULL; - - for (objfile = object_files; - objfile != NULL && result == NULL; - objfile = objfile -> next) - { - result = (*func)(objfile, arg1, arg2, arg3); - } - return (result); -} - -/* Call the function specified by FUNC for each currently available symbol - table, for as long as this function continues to return NULL. If the - function ever returns non-NULL, then the iteration over the symbol tables - is terminated, and the result is returned to the caller. The function - called has full control over the form and content of the information - returned via the non-NULL result, which may be as simple as a pointer - to the symtab that the iteration terminated on, or as complex as a - pointer to a private structure containing multiple results. */ - -PTR -iterate_over_symtabs (func, arg1, arg2, arg3) - PTR (*func) PARAMS ((struct objfile *, struct symtab *, PTR, PTR, PTR)); - PTR arg1; - PTR arg2; - PTR arg3; -{ - register struct objfile *objfile; - register struct symtab *symtab; - PTR result = NULL; - - for (objfile = object_files; - objfile != NULL && result == NULL; - objfile = objfile -> next) - { - for (symtab = objfile -> symtabs; - symtab != NULL && result == NULL; - symtab = symtab -> next) - { - result = (*func)(objfile, symtab, arg1, arg2, arg3); - } - } - return (result); -} - -/* Call the function specified by FUNC for each currently available partial - symbol table, for as long as this function continues to return NULL. If - the function ever returns non-NULL, then the iteration over the partial - symbol tables is terminated, and the result is returned to the caller. - - The function called has full control over the form and content of the - information returned via the non-NULL result, which may be as simple as a - pointer to the partial symbol table that the iteration terminated on, or - as complex as a pointer to a private structure containing multiple - results. */ - -PTR -iterate_over_psymtabs (func, arg1, arg2, arg3) - PTR (*func) PARAMS ((struct objfile *, struct partial_symtab *, - PTR, PTR, PTR)); - PTR arg1; - PTR arg2; - PTR arg3; -{ - register struct objfile *objfile; - register struct partial_symtab *psymtab; - PTR result = NULL; - - for (objfile = object_files; - objfile != NULL && result == NULL; - objfile = objfile -> next) - { - for (psymtab = objfile -> psymtabs; - psymtab != NULL && result == NULL; - psymtab = psymtab -> next) - { - result = (*func)(objfile, psymtab, arg1, arg2, arg3); - } - } - return (result); -} - - /* Look for a mapped symbol file that corresponds to FILENAME and is more recent than MTIME. If MAPPED is nonzero, the user has asked that gdb use a mapped symbol file for this file, so create a new one if one does diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 3551c05..554c9b8 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -293,30 +293,34 @@ have_full_symbols PARAMS ((void)); extern int have_minimal_symbols PARAMS ((void)); -extern PTR -iterate_over_objfiles PARAMS ((PTR (*func) (struct objfile *, - PTR arg1, PTR arg2, PTR arg3), - PTR arg1, PTR arg2, PTR arg3)); - -extern PTR -iterate_over_symtabs PARAMS ((PTR (*func) (struct objfile *, struct symtab *, - PTR arg1, PTR arg2, PTR arg3), - PTR arg1, PTR arg2, PTR arg3)); - -extern PTR -iterate_over_psymtabs PARAMS ((PTR (*func) (struct objfile *, - struct partial_symtab *, - PTR arg1, PTR arg2, PTR arg3), - PTR arg1, PTR arg2, PTR arg3)); - /* Traverse all object files. ALL_OBJFILES_SAFE works even if you delete the objfile during the traversal. */ #define ALL_OBJFILES(obj) \ - for ((obj)=object_files; (obj)!=NULL; (obj)=(obj)->next) + for ((obj) = object_files; (obj) != NULL; (obj) = (obj)->next) #define ALL_OBJFILES_SAFE(obj,nxt) \ - for ((obj)=object_files; (obj)!=NULL?((nxt)=(obj)->next,1):0; (obj)=(nxt)) + for ((obj) = object_files; \ + (obj) != NULL? ((nxt)=(obj)->next,1) :0; \ + (obj) = (nxt)) + +/* Traverse all symtabs in all objfiles. */ + +#define ALL_SYMTABS(objfile, s) \ + ALL_OBJFILES (objfile) \ + for ((s) = (objfile) -> symtabs; (s) != NULL; (s) = (s) -> next) + +/* Traverse all psymtabs in all objfiles. */ + +#define ALL_PSYMTABS(objfile, p) \ + ALL_OBJFILES (objfile) \ + for ((p) = (objfile) -> psymtabs; (p) != NULL; (p) = (p) -> next) + +/* Traverse all minimal symbols in all objfiles. */ + +#define ALL_MSYMBOLS(objfile, m) \ + ALL_OBJFILES (objfile) \ + for ((m) = (objfile) -> msymbols; (m)->name != NULL; (m)++) #endif /* !defined (OBJFILES_H) */ diff --git a/gdb/xcoffexec.c b/gdb/xcoffexec.c index d64dec4..544aa47 100644 --- a/gdb/xcoffexec.c +++ b/gdb/xcoffexec.c @@ -355,48 +355,6 @@ map_vmap (bfd *bf, bfd *arch) } -#define FASTER_MSYMBOL_RELOCATION 1 - -#ifdef FASTER_MSYMBOL_RELOCATION - -/* Used to relocate an object file's minimal symbols. */ - -static void -reloc_objfile_msymbols (objf, addr) -struct objfile *objf; -CORE_ADDR addr; -{ - register struct minimal_symbol *msymbol; - int ii; - - for (msymbol = objf->msymbols, ii=0; - msymbol && ii < objf->minimal_symbol_count; ++msymbol, ++ii) - - if (msymbol->address < TEXT_SEGMENT_BASE) - msymbol->address += addr; -} - -#else /* !FASTER_MSYMBOL_RELOCATION */ - -/* Called via iterate_over_msymbols to relocate minimal symbols */ - -static int -relocate_minimal_symbol (objfile, msymbol, arg1, arg2, arg3) - struct objfile *objfile; - struct minimal_symbol *msymbol; - PTR arg1; - PTR arg2; - PTR arg3; -{ - if (msymbol->address < TEXT_SEGMENT_BASE) - msymbol -> address += (int) arg1; - - /* return 0, otherwise `iterate_over_msymbols()' will stop at the - first iteration. */ - return 0; -} -#endif /* FASTER_MSYMBOL_RELOCATION */ - /* true, if symbol table and minimal symbol table are relocated. */ int symtab_relocated = 0; @@ -411,11 +369,12 @@ struct stat *vip; { register struct symtab *s; register struct objfile *objfile; + register struct minimal_symbol *msymbol; /* * for each symbol table generated from the vp->bfd */ - for (objfile = object_files; objfile != NULL; objfile = objfile -> next) + ALL_OBJFILES (objfile) { for (s = objfile -> symtabs; s != NULL; s = s -> next) { @@ -463,25 +422,15 @@ struct stat *vip; for (; s; s = s->next) if (!s->nonreloc || LINETABLE(s)) vmap_symtab_1(s, vp, old_start); - -#ifdef FASTER_MSYMBOL_RELOCATION - /* we can rely on the fact that at least one symtab in this objfile - will get relocated. Thus, we can be sure that minimal symbol - vector is guaranteed for relocation. */ - - reloc_objfile_msymbols (objfile, vp->tstart - old_start); -#endif break; } } } if (vp->tstart != old_start) { -#ifndef FASTER_MSYMBOL_RELOCATION - (void) iterate_over_msymbols (relocate_minimal_symbol, - (PTR) (vp->tstart - old_start), - (PTR) NULL, (PTR) NULL); -#endif + ALL_MSYMBOLS (objfile, msymbol) + if (msymbol->address < TEXT_SEGMENT_BASE) + msymbol -> address += vp->tstart - old_start; /* breakpoints need to be relocated as well. */ fixup_breakpoints (0, TEXT_SEGMENT_BASE, vp->tstart - old_start); diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index a677f7b..1312f9b 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -313,7 +313,7 @@ struct pending_stabs *stabs; struct symbol *sym = find_symbol_in_list (symbols, name, pp-name); if (!sym) { ; - /* printf ("ERROR! stab symbol not found!\n"); /* FIXME */ + /* printf ("ERROR! stab symbol not found!\n"); */ /* FIXME */ /* The above is a false alarm. There are cases the we can have a stab, without its symbol. xlc generates this for the extern definitions in inner blocks. */ @@ -2387,182 +2387,9 @@ smash_to_pointer_type (type, to_type) #else /* IBM6000_HOST */ struct type * -builtin_type (pp) -char **pp; +builtin_type (ignore) +char **ignore; { - fatal ("internals eror: builtin_type called!"); + fatal ("GDB internal eror: builtin_type called on non-RS/6000!"); } #endif /* IBM6000_HOST */ - - -#define DEBUG 1 - -#if defined (DEBUG) && defined (IBM6000_HOST) /* Needs both defined */ -void -dump_strtbl () -{ - int ii; - printf ("===STRING TABLE DUMP...\n\n"); - for ( ii=0; ii < strtbl_len; ++ii ) - printf ("%c", isprint (*(strtbl+ii)) ? *(strtbl+ii) : ' '); - printf ("\n"); -} - -void -dump_linetable (ltb) - struct linetable *ltb; -{ - int ii; - for (ii=0; ii < ltb->nitems; ++ii) - printf ("line: %d, addr: 0x%x\n", ltb->item[ii].line, ltb->item[ii].pc); -} - -void -dump_type (typeP) - struct type *typeP; -{ - printf ("0x%x: name: %s\n", typeP, typeP->name ? typeP->name : "(nil)"); -} - -char *dump_namespace (); -char *dump_addrclass (); - -void -dump_symbol (pp) - struct symbol *pp; -{ - printf (" sym: %s\t%s,\t%s\ttype: 0x%x, val: 0x%x end: 0x%x\n", - pp->name, dump_namespace (pp->namespace), - dump_addrclass (pp->class), pp->type, - SYMBOL_CLASS(pp) == LOC_BLOCK ? BLOCK_START(SYMBOL_BLOCK_VALUE(pp)) - : pp->value.value, - SYMBOL_CLASS(pp) == LOC_BLOCK ? BLOCK_END(SYMBOL_BLOCK_VALUE(pp)) : 0); -} - - -char * -dump_namespace (ns) -int ns; -{ - static char *ns_name [] = { - "UNDEF_NS", "VAR_NS", "STRUCT_NS", "LABEL_NS"}; - - switch (ns) { - case UNDEF_NAMESPACE: - case VAR_NAMESPACE: - case STRUCT_NAMESPACE: - case LABEL_NAMESPACE: - return ns_name[ns]; - } - - return "***ERROR***"; -} - - -char * -dump_addrclass (ac) -int ac; /* address class */ -{ - static char *ac_name [] = { - "LOC_UNDEF", - "LOC_CONST", - "LOC_STATIC", - "LOC_REGISTER", - "LOC_ARG", - "LOC_REF_ARG", - "LOC_REGPARM", - "LOC_LOCAL", - "LOC_TYPEDEF", - "LOC_LABEL", - "LOC_BLOCK", - "LOC_CONST_BYTES", - "LOC_LOCAL_ARG", - }; - switch (ac) { - case LOC_UNDEF: - case LOC_CONST: - case LOC_STATIC: - case LOC_REGISTER: - case LOC_ARG: - case LOC_REF_ARG: - case LOC_REGPARM: - case LOC_LOCAL: - case LOC_TYPEDEF: - case LOC_LABEL: - case LOC_BLOCK: - case LOC_CONST_BYTES: - case LOC_LOCAL_ARG: - return ac_name [ac]; - } - return "***ERROR***"; -} - -void -dump_block (pp) - struct block *pp; -{ - int ii; - printf ("BLOCK..: start: 0x%x, end: 0x%x\n", pp->startaddr, pp->endaddr); - for (ii=0; ii < pp->nsyms; ++ii) - dump_symbol (pp->sym[ii]); -} - -void -dump_blockvector (pp) - struct blockvector *pp; -{ - int ii; - for (ii=0; ii < pp->nblocks; ++ii) - dump_block (pp->block [ii]); -} - - -void -dump_last_symtab (pp) - struct symtab *pp; -{ - for ( ; pp; pp = pp->next) { - if ( pp->next == 0 ) { - printf ("SYMTAB NAME: %s\n", pp->filename); - dump_blockvector (pp->blockvector); - } - } -} - -void -dump_symtabs (pp) - struct symtab *pp; -{ - for ( ; pp; pp = pp->next) { - printf ("SYMTAB NAME: %s\n", pp->filename ? pp->filename : "(nil)"); -/* if (pp->linetable) - dump_linetable (pp->linetable); */ - dump_blockvector (pp->blockvector); - } -} - -void -dump_symtab_lines (pp) - struct symtab *pp; -{ - for ( ; pp; pp = pp->next) { - printf ("SYMTAB NAME: %s\n", pp->filename ? pp->filename : "(nil)"); - if (pp->linetable) - dump_linetable (pp->linetable); - /* dump_blockvector (pp->blockvector); */ - } -} - -void -dump_msymbols (of) -struct objfile *of; -{ - int ii; - for (ii=0; ii < of->minimal_symbol_count; ++ii) - printf ("name: %s, addr: 0x%x, info: 0x%x\n", - of->msymbols[ii].name, - of->msymbols[ii].address, - of->msymbols[ii].info ); -} - -#endif /* DEBUG */