-parse_symbol(sh, ax)
- SYMR *sh;
- AUXU *ax;
-{
- struct symbol *s;
- struct block *b;
- struct type *t;
- struct field *f;
- /* When a symbol is cross-referenced from other files/symbols
- we mark it explicitly */
- int pend = (sh->reserved == 1);
- enum address_class class;
-
- switch (sh->st) {
-
- case stNil:
- break;
-
- case stGlobal: /* external symbol, goes into global block */
- class = LOC_STATIC;
- b = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st),
- GLOBAL_BLOCK);
- s = new_symbol(sh->iss);
- SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
- goto data;
-
- case stStatic: /* static data, goes into current block. */
- class = LOC_STATIC;
- b = top_stack->cur_block;
- s = new_symbol(sh->iss);
- SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
- goto data;
-
- case stLocal: /* local variable, goes into current block */
- if (sh->sc == scRegister) {
- class = LOC_REGISTER;
- if (sh->value > 31)
- sh->value += 6;
- } else
- class = LOC_LOCAL;
- b = top_stack->cur_block;
- s = new_symbol(sh->iss);
- SYMBOL_VALUE(s) = sh->value;
-
-data: /* Common code for symbols describing data */
- SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
- SYMBOL_CLASS(s) = class;
- add_symbol(s, b);
-
- /* Type could be missing in a number of cases */
- if (sh->sc == scUndefined || sh->sc == scNil ||
- sh->index == 0xfffff)
- SYMBOL_TYPE(s) = builtin_type_int; /* undefined? */
- else
- SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0);
- /* Value of a data symbol is its memory address */
- break;
-
- case stParam: /* arg to procedure, goes into current block */
- max_gdbinfo++;
- top_stack->numargs++;
- s = new_symbol(sh->iss);
- SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
- if (sh->sc == scRegister) {
- SYMBOL_CLASS(s) = LOC_REGPARM;
- if (sh->value > 31)
- sh->value += 6;
- } else
- SYMBOL_CLASS(s) = LOC_ARG;
- 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 */
- s = new_symbol(sh->iss);
- SYMBOL_NAMESPACE(s) = VAR_NAMESPACE; /* so that it can be used */
- SYMBOL_CLASS(s) = LOC_LABEL; /* but not misused */
- SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
- SYMBOL_TYPE(s) = builtin_type_int;
- add_symbol(s, top_stack->cur_block);
- break;
-
- 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;
- SYMBOL_CLASS(s) = LOC_BLOCK;
- /* Type of the return value */
- if (sh->sc == scUndefined || sh->sc == scNil)
- t = builtin_type_int;
- else
- t = parse_type(ax + sh->index, sh, 0);
- 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);
- SYMBOL_BLOCK_VALUE(s) = b;
- BLOCK_FUNCTION(b) = s;
- BLOCK_START(b) = BLOCK_END(b) = sh->value;
- BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
- add_block(b, top_stack->cur_st);
-
- /* Not if we only have partial info */
- if (sh->sc == scUndefined || sh->sc == scNil)
- break;
-
- push_parse_stack();
- top_stack->cur_block = b;
- top_stack->blocktype = sh->st;
- top_stack->cur_type = SYMBOL_TYPE(s);
- top_stack->procadr = sh->value;
- top_stack->numargs = 0;
-
- sh->value = (long) SYMBOL_TYPE(s);
- break;
-
- case stBlock: /* Either a lexical block, or some type */
- push_parse_stack();
- top_stack->blocktype = stBlock;
- if (sh->sc == scInfo) { /* structure/union/enum def */
- s = new_symbol(sh->iss);
- SYMBOL_NAMESPACE(s) = STRUCT_NAMESPACE;
- SYMBOL_CLASS(s) = LOC_TYPEDEF;
- SYMBOL_VALUE(s) = 0;
- add_symbol(s, top_stack->cur_block);
- /* If this type was expected, use its partial definition */
- if (pend) {
- t = is_pending_symbol(cur_fdr, sh)->t;
- } else {
- /* Uhmm, can`t decide yet. Smash later */
- t = new_type(sh->iss);
- TYPE_CODE(t) = TYPE_CODE_UNDEF;
- add_pending(cur_fdr, sh, t);
- }
- SYMBOL_TYPE(s) = t;
- /* make this the current type */
- top_stack->cur_type = t;
- TYPE_LENGTH(t) = sh->value;
- /* Mark that symbol has a type, and say which one */
- sh->value = (long) t;
- } else {
- /* beginnning of (code) block. Value of symbol
- is the displacement from procedure start */
- b = new_block(top_stack->maxsyms);
- BLOCK_START(b) = sh->value + top_stack->procadr;
- BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
- top_stack->cur_block = b;
- add_block(b, top_stack->cur_st);
- }
- break;
-
- case stEnd: /* end (of anything) */
- if (sh->sc == scInfo) {
- /* Finished with type */
- top_stack->cur_type = 0;
- } else if (sh->sc == scText &&
- (top_stack->blocktype == stProc ||
- top_stack->blocktype == stStaticProc)) {
- /* Finished with procedure */
- struct blockvector *bv = BLOCKVECTOR(top_stack->cur_st);
- struct block *b;
- int i;
-
- BLOCK_END(top_stack->cur_block) += sh->value; /* size */
- got_numargs(top_stack->procadr, top_stack->numargs);
- /* Reallocate symbols, saving memory */
- b = shrink_block(top_stack->cur_block, top_stack->cur_st);
-
- /* f77 emits proc-level with address bounds==[0,0],
- So look for such child blocks, and patch them. */
- for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++) {
- struct block *b_bad = BLOCKVECTOR_BLOCK(bv,i);
- if (BLOCK_SUPERBLOCK(b_bad) == b
- && BLOCK_START(b_bad) == top_stack->procadr
- && BLOCK_END(b_bad) == top_stack->procadr) {
- BLOCK_START(b_bad) = BLOCK_START(b);
- BLOCK_END(b_bad) = BLOCK_END(b);
- }
- }
- if (entry_point < BLOCK_END(b)
- && entry_point >= BLOCK_START(b)) {
- startup_file_start = BLOCK_START(b);
- startup_file_end = BLOCK_END(b);
- }
- } else if (sh->sc == scText && top_stack->blocktype == stBlock) {
- /* End of (code) block. The value of the symbol
- is the displacement from the procedure`s start
- address of the end of this block. */
- BLOCK_END(top_stack->cur_block) = sh->value + top_stack->procadr;
- (void) shrink_block(top_stack->cur_block, top_stack->cur_st);
- }
- pop_parse_stack(); /* restore previous lexical context */
- break;
-
- case stMember: /* member of struct/union/enum.. */
- f = new_field(top_stack->cur_type, sh->iss);
- f->bitpos = sh->value;
- f->type = parse_type(ax + sh->index, sh, &f->bitsize);
- break;
-
- case stTypedef: /* type definition */
- s = new_symbol(sh->iss);
- SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
- SYMBOL_CLASS(s) = LOC_TYPEDEF;
- SYMBOL_BLOCK_VALUE(s) = top_stack->cur_block;
- add_symbol(s, top_stack->cur_block);
- SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0);
- sh->value = (long) SYMBOL_TYPE(s);
- break;
-
- case stFile: /* file name */
- push_parse_stack();
- top_stack->blocktype = sh->st;
- break;
-
- /* I`ve never seen these for C */
- case stRegReloc:
- break; /* register relocation */
- case stForward:
- break; /* forwarding address */
- case stConstant:
- break; /* constant */
- default:
- error("Unknown symbol type %x.", sh->st);
- }
- sh->st = stParsed;
-}
-
-/* Parse the type information provided in the AX entries for
- the symbol SH. Return the bitfield size in BS, in case. */
-
-static struct type *parse_type(ax, sh, bs)
- AUXU *ax;
- SYMR *sh;
- int *bs;
-{
- /* Null entries in this map are treated specially */
- static struct type **map_bt[] =
- {
- &builtin_type_void, /* btNil */
- 0, /* btAdr */
- &builtin_type_char, /* btChar */
- &builtin_type_unsigned_char, /* btUChar */
- &builtin_type_short, /* btShort */
- &builtin_type_unsigned_short, /* btUShort */
- &builtin_type_int, /* btInt */
- &builtin_type_unsigned_int, /* btUInt */
- &builtin_type_long, /* btLong */
- &builtin_type_unsigned_long, /* btULong */
- &builtin_type_float, /* btFloat */
- &builtin_type_double, /* btDouble */
- 0, /* btStruct */
- 0, /* btUnion */
- 0, /* btEnum */
- 0, /* btTypedef */
- 0, /* btRange */
- 0, /* btSet */
- &builtin_type_complex, /* btComplex */
- &builtin_type_double_complex, /* btDComplex */
- 0, /* btIndirect */
- &builtin_type_fixed_dec, /* btFixedDec */
- &builtin_type_float_dec, /* btFloatDec */
- &builtin_type_string, /* btString */
- 0, /* btBit */
- 0, /* btPicture */
- &builtin_type_void, /* btVoid */
- };
-
- TIR *t;
- struct type *tp = 0, *tp1;
- char *fmt = "%s";
-
- /* Procedures start off by one */
- if (sh->st == stProc || sh->st == stStaticProc)
- ax++;
-
- /* Undefined ? Should not happen */
- if (ax->rndx.rfd == 0xfff) {
- return builtin_type_void;
- }
-
- /* Use aux as a type information record, map its basic type */
- t = &ax->ti;
- if (t->bt > 26 || t->bt == btPicture) {
- complain (&basic_type_complaint, t->bt);
- return builtin_type_int;
- }
- if (map_bt[t->bt])
- tp = *map_bt[t->bt];
- else {
- /* Cannot use builtin types, use templates */
- tp = make_type(TYPE_CODE_VOID, 0, 0, 0);
- switch (t->bt) {
- case btAdr:
- *tp = *builtin_type_ptr;
- break;
- case btStruct:
- *tp = *builtin_type_struct;
- fmt = "struct %s";
- break;
- case btUnion:
- *tp = *builtin_type_union;
- fmt = "union %s";
- break;
- case btEnum:
- *tp = *builtin_type_enum;
- fmt = "enum %s";
- break;
- case btRange:
- *tp = *builtin_type_range;
- break;
- case btSet:
- *tp = *builtin_type_set;
- fmt = "set %s";
- break;
- }
- }
-
- /* Move on to next aux */
- ax++;
- if (t->continued) {
- /* This is the way it would work if the compiler worked */
- register TIR *t1 = t;
- while (t1->continued)
- ax++;
- }
-
- /* For bitfields all we need is the width */
- if (t->fBitfield) {
- *bs = ax->width;
- return tp;
- }
-
- /* All these types really point to some (common) MIPS type
- definition, and only the type-qualifiers fully identify
- them. We`ll make the same effort at sharing */
- if (t->bt == btIndirect ||
- t->bt == btStruct ||
- t->bt == btUnion ||
- t->bt == btEnum ||
- t->bt == btTypedef ||
- t->bt == btRange ||
- t->bt == btSet) {
- char name[256], *pn;
-
- /* Try to cross reference this type */
- tp1 = tp;
- ax += cross_ref(ax, &tp1, &pn);
- /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
- sprintf(name, fmt, pn);
-
- /* reading .o file ? */
- if (UNSAFE_DATA_ADDR(tp1))
- tp1 = tp;
- if (TYPE_CODE(tp1) == TYPE_CODE_UNDEF) {
- /*
- * Type was incompletely defined, now we know.
- */
- TYPE_CODE(tp1) = TYPE_CODE(tp);
- TYPE_NAME(tp1) = obsavestring(name, strlen(name));
- if (TYPE_CODE(tp1) == TYPE_CODE_ENUM) {
- int i;
-
- for (i = 0; i < TYPE_NFIELDS(tp1); i++)
- make_enum_constant(&TYPE_FIELD(tp1,i), tp1);
- }
- }
- if (tp1 != tp) {
- /* found as cross ref, rid of our template */
- if ((TYPE_FLAGS(tp) & TYPE_FLAG_PERM) == 0)
- free(tp);
- tp = tp1;
- /* stupid idea of prepending "struct" to type names */
- if (t->bt == btStruct && !index(TYPE_NAME(tp), ' ')) {
- sprintf(name, fmt, TYPE_NAME(tp));
- TYPE_NAME(tp) = obsavestring(name, strlen(name));
- }
- } else
- TYPE_NAME(tp) = savestring(name, strlen(name));
- }
-
- /* Deal with range types */
- if (t->bt == btRange) {
- struct field *f;
-
- f = new_field(tp, "Low");
- f->bitpos = ax->dnLow;
- ax++;
- f = new_field(tp, "High");
- f->bitpos = ax->dnHigh;
- ax++;
- }
-
- /* Parse all the type qualifiers now. If there are more
- than 6 the game will continue in the next aux */
-
-#define PARSE_TQ(tq) \
- if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, sh);
-
-again: PARSE_TQ(tq0);
- PARSE_TQ(tq1);
- PARSE_TQ(tq2);
- PARSE_TQ(tq3);
- PARSE_TQ(tq4);
- PARSE_TQ(tq5);
-#undef PARSE_TQ
-
- if (t->continued) {
- t++;
- goto again;
- }
- return tp;
-}
-
-/* Make up a complex type from a basic one. Type is passed by
- reference in TPP and side-effected as necessary. The type
- qualifier TQ says how to handle the aux symbols at AX for
- the symbol SX we are currently analyzing.
- Returns the number of aux symbols we parsed. */
-
-static int
-upgrade_type(tpp, tq, ax, sh)
- struct type **tpp;
- AUXU *ax;
- SYMR *sh;
-{
- int off;
- struct type *t;
-
- /* Used in array processing */
- int rf, id;
- FDR *fh;
- struct field *f;
- SYMR ss;
- int lower, upper;
-
- switch (tq) {
- case tqPtr:
- t = lookup_pointer_type (*tpp);
- *tpp = t;
- return 0;
-
- case tqProc:
- t = lookup_function_type (*tpp);
- *tpp = t;
- return 0;
-
- case tqArray:
- off = 0;
- t = make_type(TYPE_CODE_ARRAY, 0, 0, 0);
- TYPE_TARGET_TYPE(t) = *tpp;
-
- /* Determine and record the domain type (type of index) */
- id = ax->rndx.index;
- rf = ax->rndx.rfd;
- if (rf == 0xfff) {
- rf = (++ax)->isym;
- off++;
- }
- fh = get_rfd(cur_fd, rf);
- f = new_field(t, (char *)0);
- bzero(&ss, sizeof ss);
-/* XXX */ f->type = parse_type(fh->iauxBase + id * sizeof(AUXU),
- &ss, &f->bitsize);
-
- if (off == 0) {
- /*
- * This seems to be a pointer to the end of the Block defining
- * the type. Why it is here is magic for me, and I have no
- * good use for it anyways.
- */
- /* This used to occur because cross_ref returned
- the wrong result (ax pointed wrong). FIXME,
- delete this code in a while. -- gnu@cygnus jul91 */
- complain (&array_parse_complaint, 0);
- off++;
- id = (++ax)->rndx.index;
- if ((rf = ax->rndx.rfd) == 0xfff)
- rf = (++ax)->isym, off++;
- }
- lower = (++ax)->dnLow;
- upper = (++ax)->dnHigh;
- rf = (++ax)->width; /* bit size of array element */
-
- /* Check whether supplied array element bit size matches
- the known size of the element type. If this complaint
- ends up not happening, we can remove this code. It's
- here because we aren't sure we understand this *&%&$
- symbol format. */
- id = TYPE_LENGTH(TYPE_TARGET_TYPE(t)) << 3; /* bitsize */
- if (id == 0) {
- /* Most likely an undefined type */
- id = rf;
- TYPE_LENGTH(TYPE_TARGET_TYPE(t)) = id >> 3;
- }
- if (id != rf)
- complain (&array_bitsize_complaint, rf);
-
- TYPE_LENGTH(t) = (upper < 0) ? 0 :
- (upper - lower + 1) * (rf >> 3);
- *tpp = t;
- return 4 + off;
-
- case tqVol:
- /* Volatile -- currently ignored */
- return 0;
-
- default:
- complain (&unknown_type_qual_complaint, tq);
- return 0;
- }
-}
-
-
-/* Parse a procedure descriptor record PR. Note that the procedure
- is parsed _after_ the local symbols, now we just make up the
- extra information we need into a special symbol that we insert
- in the procedure's main block. Note also that images that
- have been partially stripped (ld -x) have been deprived
- of local symbols, and we have to cope with them here.
- The procedure's code ends at BOUND */
-
-static
-parse_procedure(pr, bound)
- PDR *pr;
-{
- struct symbol *s, *i;
- SYMR *sh = (SYMR*)pr->isym;
- struct block *b;
- struct mips_extra_func_info *e;
- char name[100];
- char *sh_name;
-
- /* Reuse the MIPS record */
- e = (struct mips_extra_func_info *) pr;
- e->numargs = lookup_numargs(pr->adr);
-
- /* Make up our special symbol */
- i = new_symbol(".gdbinfo.");
- SYMBOL_VALUE(i) = (int)e;
- SYMBOL_NAMESPACE(i) = LABEL_NAMESPACE;
- SYMBOL_CLASS(i) = LOC_CONST;
- SYMBOL_TYPE(i) = builtin_type_void;
-
- /* Make up a name for static procedures. Sigh. */
- if (sh == (SYMR*)-1) {
- sprintf(name,".static_procedure@%x",pr->adr);
- sh_name = savestring(name, strlen(name));
- s = NULL;
- }
- else {
- sh_name = (char*)sh->iss;
- s = mylookup_symbol(sh_name, top_stack->cur_block,
- VAR_NAMESPACE, LOC_BLOCK);
- }
- if (s != 0) {
- b = SYMBOL_BLOCK_VALUE(s);
- } else {
- s = new_symbol(sh_name);
- SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
- SYMBOL_CLASS(s) = LOC_BLOCK;
- /* Donno its type, hope int is ok */
- SYMBOL_TYPE(s) = lookup_function_type (builtin_type_int);
- add_symbol(s, top_stack->cur_block);
- /* Wont have symbols for this one */
- b = new_block(2);
- SYMBOL_BLOCK_VALUE(s) = b;
- BLOCK_FUNCTION(b) = s;
- BLOCK_START(b) = pr->adr;
- BLOCK_END(b) = bound;
- BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
- add_block(b, top_stack->cur_st);
- }
- e->isym = (long)s;
- add_symbol(i,b);
-}
-
-/* Parse the external symbol ES. Just call parse_symbol() after
- making sure we know where the aux are for it. For procedures,
- parsing of the PDRs has already provided all the needed
- information, we only parse them if SKIP_PROCEDURES is false,
- and only if this causes no symbol duplication.
-
- This routine clobbers top_stack->cur_block and ->cur_st. */
-
-static
-parse_external(es, skip_procedures)
- EXTR *es;
-{
- AUXU *ax;
-
- if (es->ifd != ifdNil) {
- cur_fd = es->ifd;
- cur_fdr = (FDR*)(cur_hdr->cbFdOffset) + cur_fd;
- ax = (AUXU*)cur_fdr->iauxBase;
- } else {
- cur_fdr = (FDR*)(cur_hdr->cbFdOffset);
- ax = 0;
- }
- top_stack->cur_st = cur_stab;
- top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st),
- GLOBAL_BLOCK);
-
- /* Reading .o files */
- if (es->asym.sc == scUndefined || es->asym.sc == scNil) {
- char *what;
- switch (es->asym.st) {
- case stStaticProc:
- case stProc: what = "procedure"; n_undef_procs++; break;
- case stGlobal: what = "variable"; n_undef_vars++; break;
- case stLabel: what = "label"; n_undef_labels++; break;
- default : what = "symbol"; break;
- }
- 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));
- return;
- }
-
- switch (es->asym.st) {
- case stProc:
- /* If we have full symbols we do not need more */
- if (skip_procedures)
- return;
- if (mylookup_symbol (es->asym.iss, top_stack->cur_block,
- VAR_NAMESPACE, LOC_BLOCK))
- break;
- /* fall through */
- case stGlobal:
- case stLabel:
- /*
- * Note that the case of a symbol with indexNil
- * must be handled anyways by parse_symbol().
- */
- parse_symbol(&es->asym, ax);
- break;
- default:
- break;
- }
-}
-
-/* Parse the line number info for file descriptor FH into
- GDB's linetable LT. MIPS' encoding requires a little bit
- of magic to get things out. Note also that MIPS' line
- numbers can go back and forth, apparently we can live
- with that and do not need to reorder our linetables */
-
-static
-parse_lines(fh, lt)
- FDR *fh;
- struct linetable *lt;
-{
- unsigned char *base = (unsigned char*)fh->cbLineOffset;
- int i, j, k;
- int delta, count, lineno = 0;
- PDR *pr;
-
- if (base == 0)
- return;
-
- /* Scan by procedure descriptors */
- i = 0; j = 0, k = 0;
- for (pr = (PDR*)IPDFIRST(cur_hdr,fh); j < fh->cpd; j++, pr++) {
- int l, halt;
-
- /* No code for this one */
- if (pr->iline == ilineNil ||
- pr->lnLow == -1 || pr->lnHigh == -1)
- continue;
- /*
- * Aurgh! To know where to stop expanding we
- * must look-ahead.
- */
- for (l = 1; l < (fh->cpd - j); l++)
- if (pr[l].iline != -1)
- break;
- if (l == (fh->cpd - j))
- halt = fh->cline;
- else
- halt = pr[l].iline;
- /*
- * When procedures are moved around the linenumbers
- * are attributed to the next procedure up
- */
- if (pr->iline >= halt) continue;
-
- base = (unsigned char*)pr->cbLineOffset;
- l = pr->adr >> 2; /* in words */
- halt += (pr->adr >> 2) - pr->iline;
- for (lineno = pr->lnLow; l < halt;) {
- count = *base & 0x0f;
- delta = *base++ >> 4;
- if (delta >= 8)
- delta -= 16;
- if (delta == -8) {
- delta = (base[0] << 8) | base[1];
- if (delta >= 0x8000)
- delta -= 0x10000;
- base += 2;
- }
- lineno += delta;/* first delta is 0 */
- k = add_line(lt, lineno, l, k);
- l += count + 1;
- }
- }
-}
-
-
-/* Parse the symbols of the file described by FH, whose index is F_IDX.
- BOUND is the highest core address of this file's procedures */
-
-static
-parse_one_file(fh, f_idx, bound)
- FDR *fh;
-{
- register int s_idx;
- SYMR *sh;
- PDR *pr;
-
- /* Parse local symbols first */
-
- for (s_idx = 0; s_idx < fh->csym; s_idx++) {
- sh = (SYMR *) (fh->isymBase) + s_idx;
- cur_sdx = s_idx;
- parse_symbol(sh, fh->iauxBase);
- }
-
- /* Procedures next, note we need to look-ahead to
- find out where the procedure's code ends */
-
- for (s_idx = 0; s_idx < fh->cpd-1; s_idx++) {
- pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + s_idx;
- parse_procedure(pr, pr[1].adr); /* next proc up */
- }
- if (fh->cpd) {
- pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + s_idx;
- parse_procedure(pr, bound); /* next file up */
- }
-
- /* Linenumbers. At the end, check if we can save memory */
- parse_lines(fh, LINETABLE(cur_stab));
- if (LINETABLE(cur_stab)->nitems < fh->cline)
- shrink_linetable(cur_stab);
-}
-\f
-/* Master parsing procedure for first-pass reading of file symbols
- into a partial_symtab.
-
- Parses the symtab described by the global symbolic header CUR_HDR.
- END_OF_TEXT_SEG gives the address just after the text segment for
- the symtab we are reading. */
-
-static
-parse_partial_symbols(end_of_text_seg)
- int end_of_text_seg;
-{
- int f_idx, s_idx, h_max, stat_idx;
- HDRR *hdr;
- /* Running pointers */
- FDR *fh;
- RFDT *rh;
- register EXTR *esh;
- register SYMR *sh;
- struct partial_symtab *pst;
-
- /*
- * Big plan:
- *
- * 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
- * look at. (XXX)
- */
-
- hdr = cur_hdr;
- max_gdbinfo = 0;
- max_glevel = MIN_GLEVEL;
-
- /* Allocate the map FDR -> PST.
- Minor hack: -O3 images might claim some global data belongs
- to FDR -1. We`ll go along with that */
- fdr_to_pst = (struct pst_map *)xzalloc((hdr->ifdMax+1) * sizeof *fdr_to_pst);
- fdr_to_pst++;
- {
- struct partial_symtab * pst = new_psymtab("");
- fdr_to_pst[-1].pst = pst;
- FDR_IDX(pst) = -1;
- }
-
- /* Now scan the FDRs, mostly for dependencies */
- for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
- (void) parse_fdr(f_idx, 1);
-
- /* Take a good guess at how many symbols we might ever need */
- h_max = hdr->iextMax;
-
- /* Parse externals: two passes because they can be ordered
- in any way, but gdb likes to have them segregated by their
- source file. */
-
- /* Pass 1 over external syms: Presize and partition the list */
- for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
- esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
- fdr_to_pst[esh->ifd].n_globals++;
- }
-
- if (global_psymbols.list) {
- int origsize = global_psymbols.next - global_psymbols.list;
-
- global_psymbols.list = (struct partial_symbol *)
- xrealloc (global_psymbols.list,
- (h_max + origsize) * sizeof(struct partial_symbol));
- global_psymbols.next = global_psymbols.list + origsize;
- global_psymbols.size = h_max + origsize;
- } else {
- global_psymbols.list = (struct partial_symbol *)
- xmalloc (h_max * sizeof(struct partial_symbol));
- global_psymbols.next = global_psymbols.list;
- global_psymbols.size = h_max;
- }
-
- /* Pass 1.5 over files: partition out global symbol space */
- s_idx = global_psymbols.next - global_psymbols.list;
- for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++) {
- fdr_to_pst[f_idx].pst->globals_offset = s_idx;
- s_idx += fdr_to_pst[f_idx].n_globals;
- }
-
- /* Pass 1.6 over files: partition out static symbol space.
- Note that this loop starts at 0, not at -1. */
- stat_idx = static_psymbols.next - static_psymbols.list;
- for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
- fdr_to_pst[f_idx].pst->statics_offset = stat_idx;
- fh = f_idx + (FDR *)(hdr->cbFdOffset);
- stat_idx += fh->csym;
- }
-
- /* Now that we know its max size, allocate static symbol list */
- if (static_psymbols.list) {
- int origsize = static_psymbols.next - static_psymbols.list;
-
- static_psymbols.list = (struct partial_symbol *)
- xrealloc (static_psymbols.list,
- stat_idx * sizeof(struct partial_symbol));
- static_psymbols.next = static_psymbols.list + origsize;
- static_psymbols.size = stat_idx;
- } else {
- static_psymbols.list = (struct partial_symbol *)
- xmalloc (stat_idx * sizeof(struct partial_symbol));
- static_psymbols.next = static_psymbols.list;
- static_psymbols.size = stat_idx;
- }
-
- /* Pass 2 over external syms: fill in external symbols */
- for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
- register struct partial_symbol *p;
- enum misc_function_type misc_type = mf_text;
- esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
-
- if (esh->asym.sc == scUndefined || esh->asym.sc == scNil)
- continue;
-
- /* Locate the psymtab and the preallocated psymbol. */
- pst = fdr_to_pst[esh->ifd].pst;
- p = global_psymbols.list + pst->globals_offset +
- pst->n_global_syms++;
- SYMBOL_NAME(p) = (char *)(esh->asym.iss);
- SYMBOL_NAMESPACE(p) = VAR_NAMESPACE;
-
- switch (esh->asym.st) {
- case stProc:
- SYMBOL_CLASS(p) = LOC_BLOCK;
- SYMBOL_VALUE(p) = esh->asym.value;
- break;
- case stGlobal:
- SYMBOL_CLASS(p) = LOC_STATIC;
- SYMBOL_VALUE_ADDRESS(p) = (CORE_ADDR)esh->asym.value;
- misc_type = mf_data;
- break;
- case stLabel:
- SYMBOL_CLASS(p) = LOC_LABEL;
- SYMBOL_VALUE_ADDRESS(p) = (CORE_ADDR)esh->asym.value;
- break;
- default:
- misc_type = mf_unknown;
- complain (&unknown_ext_complaint, SYMBOL_NAME(p));
- }
- prim_record_misc_function (SYMBOL_NAME(p),
- SYMBOL_VALUE(p),
- misc_type);
- }
-
- /* Pass 3 over files, over local syms: fill in static symbols */
- for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
- fh = f_idx + (FDR *)(cur_hdr->cbFdOffset);
- pst = fdr_to_pst[f_idx].pst;
- pst->texthigh = pst->textlow;
-
- for (s_idx = 0; s_idx < fh->csym; ) {
- register struct partial_symbol *p;
-
- sh = s_idx + (SYMR *) fh->isymBase;
-
- if (sh->sc == scUndefined || sh->sc == scNil) {
- /* FIXME, premature? */
- s_idx++;
- continue;
- }
-
- /* Locate the preallocated psymbol. */
- p = static_psymbols.list + pst->statics_offset +
- pst->n_static_syms;
- SYMBOL_NAME(p) = (char *)(sh->iss);
- SYMBOL_VALUE(p) = sh->value;
- SYMBOL_NAMESPACE(p) = VAR_NAMESPACE;
-
- switch (sh->st) {
- case stProc: /* Asm labels apparently */
- case stStaticProc: /* Function */
- SYMBOL_CLASS(p) = LOC_BLOCK;
- pst->n_static_syms++; /* Use gdb symbol */
- /* Skip over procedure to next one. */
- s_idx = (sh->index + (AUXU *)fh->iauxBase)
- ->isym;
- {
- long high;
- long procaddr = sh->value;
-
- sh = s_idx + (SYMR *) fh->isymBase - 1;
- if (sh->st != stEnd)
- continue;
- high = procaddr + sh->value;
- if (high > pst->texthigh)
- pst->texthigh = high;
- }
- continue;
- case stStatic: /* Variable */
- SYMBOL_CLASS(p) = LOC_STATIC;
- SYMBOL_VALUE_ADDRESS(p) = (CORE_ADDR)sh->value;
- break;
- case stTypedef: /* Typedef */
- SYMBOL_CLASS(p) = LOC_TYPEDEF;
- break;
- case stConstant: /* Constant decl */
- SYMBOL_CLASS(p) = LOC_CONST;
- break;
- case stBlock: /* { }, str, un, enum*/
- if (sh->sc == scInfo) {
- SYMBOL_NAMESPACE(p) = STRUCT_NAMESPACE;
- SYMBOL_CLASS(p) = LOC_TYPEDEF;
- pst->n_static_syms++;
- }
- /* Skip over the block */
- s_idx = sh->index;
- continue;
- case stFile: /* File headers */
- case stLabel: /* Labels */
- case stEnd: /* Ends of files */
- goto skip;
- default:
- complain (&unknown_sym_complaint, SYMBOL_NAME(p));
- complain (&unknown_st_complaint, sh->st);
- s_idx++;
- continue;
- }
- pst->n_static_syms++; /* Use this gdb symbol */
- skip:
- s_idx++; /* Go to next file symbol */
-#if 0
-/* We don't usually record static syms, but some we seem to. chk dbxread. */
-/*FIXME*/ prim_record_misc_function (SYMBOL_NAME(p),
- SYMBOL_VALUE(p),
- misc_type);
-#endif
- }
- }
-
- /* The array (of lists) of globals must be sorted. */
- reorder_psymtabs();
-
- /* Now sort the global psymbols. */
- for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
- struct partial_symtab *pst = fdr_to_pst[f_idx].pst;
- if (pst->n_global_syms > 1)
- qsort (global_psymbols.list + pst->globals_offset,
- pst->n_global_syms, sizeof (struct partial_symbol),
- compare_psymbols);
- }
-
- /* Mark the last code address, and remember it for later */
- hdr->cbDnOffset = end_of_text_seg;
-
- free(&fdr_to_pst[-1]);
- fdr_to_pst = 0;
-}
-
-
-/* Do the initial analisys of the F_IDX-th file descriptor.
- Allocates a partial symtab for it, and builds the list
- of dependent files by recursion. LEV says at which level
- of recursion we are called (to pretty up debug traces) */
-
-static struct partial_symtab *
-parse_fdr(f_idx, lev)
- int f_idx;
-{
- register FDR *fh;
- register struct partial_symtab *pst;
- int s_idx, s_id0;
-
- fh = (FDR *) (cur_hdr->cbFdOffset) + f_idx;
-
- /* Use this to indicate into which symtab this file was parsed */
- if (fh->ioptBase)
- return (struct partial_symtab *) fh->ioptBase;
-
- /* Debuggability level */
- if (compare_glevel(max_glevel, fh->glevel) < 0)
- max_glevel = fh->glevel;
-
- /* Make a new partial_symtab */
- pst = new_psymtab(fh->rss);
- if (fh->cpd == 0){
- pst->textlow = 0;
- pst->texthigh = 0;
- } else {
- pst->textlow = fh->adr;
- pst->texthigh = fh->cpd; /* To be fixed later */
- }
-
- /* Make everything point to everything. */
- FDR_IDX(pst) = f_idx;
- fdr_to_pst[f_idx].pst = pst;
- fh->ioptBase = (int)pst;
-
- /* Analyze its dependencies */
- if (fh->crfd <= 1)
- return pst;
-
- s_id0 = 0;
- if (fh->cpd == 0) { /* If there are no functions defined here ... */
- /* ...then presumably a .h file: drop reverse depends .h->.c */
- for (; s_id0 < fh->crfd; s_id0++) {
- RFDT *rh = (RFDT *) (fh->rfdBase) + s_id0;
- if (*rh == f_idx) {
- s_id0++; /* Skip self-dependency */
- break;
- }
- }
- }
- pst->number_of_dependencies = fh->crfd - s_id0;
- pst->dependencies = (struct partial_symtab **)
- obstack_alloc (psymbol_obstack,
- pst->number_of_dependencies *
- sizeof (struct partial_symtab *));
- for (s_idx = s_id0; s_idx < fh->crfd; s_idx++) {
- RFDT *rh = (RFDT *) (fh->rfdBase) + s_idx;
-
- pst->dependencies[s_idx-s_id0] = parse_fdr(*rh, lev+1);
- }
-
- return pst;
-}
-
-
-/* Ancillary function to psymtab_to_symtab(). Does all the work
- for turning the partial symtab PST into a symtab, recurring
- first on all dependent psymtabs. The argument FILENAME is
- only passed so we can see in debug stack traces what file
- is being read. */