1 /* Read a symbol table in MIPS' format (Third-Eye).
2 Copyright 1986, 1987, 1989, 1990, 1991 Free Software Foundation, Inc.
3 Contributed by Alessandro Forin (af@cs.cmu.edu) at CMU.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This module provides three functions: mipscoff_symfile_init,
22 which initializes to read a symbol file; mipscoff_new_init, which
23 discards existing cached information when all symbols are being
24 discarded; and mipscoff_symfile_read, which reads a symbol table
27 mipscoff_symfile_read only does the minimum work necessary for letting the
28 user "name" things symbolically; it does not read the entire symtab.
29 Instead, it reads the external and static symbols and puts them in partial
30 symbol tables. When more extensive information is requested of a
31 file, the corresponding partial symbol table is mutated into a full
32 fledged symbol table by going back and reading the symbols
33 for real. mipscoff_psymtab_to_symtab() is called indirectly through
34 a pointer in the psymtab to do this. */
43 #include <sys/param.h>
47 #include <mips/syms.h>
51 #endif /* not CMUCS */
53 #include "coff/mips.h"
54 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
55 #include "aout/aout64.h"
56 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native, now */
59 struct external_filehdr f;
60 struct external_aouthdr a;
63 /* These must match the corresponding definition in gcc/config/xm-mips.h.
64 At some point, these should probably go into a shared include file,
65 but currently gcc and gdb do not share any directories. */
67 #define CODE_MASK 0x8F300
68 #define MIPS_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK)
69 #define MIPS_MARK_STAB(code) ((code)+CODE_MASK)
70 #define MIPS_UNMARK_STAB(code) ((code)-CODE_MASK)
71 #define STABS_SYMBOL "@stabs"
73 /* Each partial symbol table entry contains a pointer to private data for the
74 read_symtab() function to use when expanding a partial symbol table entry
75 to a full symbol table entry.
77 For mipsread this structure contains the index of the FDR that this psymtab
78 represents and a pointer to the symbol table header HDRR from the symbol
79 file that the psymtab was created from. */
81 #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
82 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
83 #define CUR_HDR(p) (PST_PRIVATE(p)->cur_hdr)
88 EXTR **extern_tab; /* Pointer to external symbols for this file. */
89 int extern_count; /* Size of extern_tab. */
92 /* Things we import explicitly from other modules */
94 extern int info_verbose;
95 extern struct block *block_for_pc();
96 extern void sort_symtab_syms();
98 /* Various complaints about symbol reading that don't abort the process */
100 struct complaint unknown_ext_complaint =
101 {"unknown external symbol %s", 0, 0};
103 struct complaint unknown_sym_complaint =
104 {"unknown local symbol %s", 0, 0};
106 struct complaint unknown_st_complaint =
107 {"with type %d", 0, 0};
109 struct complaint block_overflow_complaint =
110 {"block containing %s overfilled", 0, 0};
112 struct complaint basic_type_complaint =
113 {"cannot map MIPS basic type 0x%x", 0, 0};
115 struct complaint unknown_type_qual_complaint =
116 {"unknown type qualifier 0x%x", 0, 0};
118 struct complaint array_bitsize_complaint =
119 {"size of array target type not known, assuming %d bits", 0, 0};
121 struct complaint array_parse_complaint =
122 {"array type with strange relative symbol", 0, 0};
124 struct complaint bad_tag_guess_complaint =
125 {"guessed tag type incorrectly", 0, 0};
127 /* Macros and extra defs */
129 /* Already-parsed symbols are marked specially */
131 #define stParsed stType
133 /* Puns: hard to find whether -g was used and how */
135 #define MIN_GLEVEL GLEVEL_0
136 #define compare_glevel(a,b) \
137 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
138 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
140 /* When looking at .o files, avoid tripping over bad addresses */
142 #define SAFE_TEXT_ADDR 0x400000
143 #define SAFE_DATA_ADDR 0x10000000
145 #define UNSAFE_DATA_ADDR(p) ((unsigned)p < SAFE_DATA_ADDR || (unsigned)p > 2*SAFE_DATA_ADDR)
147 /* Things that really are local to this module */
149 /* GDB symtable for the current compilation unit */
151 static struct symtab *cur_stab;
153 /* MIPS symtab header for the current file */
155 static HDRR *cur_hdr;
157 /* Pointer to current file decriptor record, and its index */
162 /* Index of current symbol */
166 /* Note how much "debuggable" this image is. We would like
167 to see at least one FDR with full symbols */
172 /* When examining .o files, report on undefined symbols */
174 static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;
176 /* Pseudo symbol to use when putting stabs into the symbol table. */
178 static char stabs_symbol[] = STABS_SYMBOL;
180 /* Extra builtin types */
182 struct type *builtin_type_complex;
183 struct type *builtin_type_double_complex;
184 struct type *builtin_type_fixed_dec;
185 struct type *builtin_type_float_dec;
186 struct type *builtin_type_string;
188 /* Forward declarations */
190 static struct symbol *new_symbol();
191 static struct type *new_type();
192 static struct block *new_block();
193 static struct symtab *new_symtab();
194 static struct linetable *new_linetable();
195 static struct blockvector *new_bvect();
197 static struct type *parse_type();
198 static struct type *make_type();
199 static struct symbol *mylookup_symbol();
200 static struct block *shrink_block();
201 static void sort_blocks();
203 static int compare_symtabs();
204 static int compare_psymtabs();
205 static int compare_blocks();
207 static struct partial_symtab *new_psymtab();
208 static struct partial_symtab *parse_fdr();
209 static int compare_psymbols();
211 static void psymtab_to_symtab_1();
212 static void add_block();
213 static void add_symbol();
214 static int add_line();
215 static struct linetable *shrink_linetable();
216 static char* mips_next_symbol_text ();
219 /* Things we export to other modules */
221 /* Address bounds for the signal trampoline in inferior, if any */
222 /* FIXME: Nothing really seems to use this. Why is it here? */
224 CORE_ADDR sigtramp_address, sigtramp_end;
226 /* The entry point (starting address) of the file, if it is an executable. */
228 extern CORE_ADDR startup_file_start; /* From blockframe.c */
229 extern CORE_ADDR startup_file_end; /* From blockframe.c */
234 /* If we have a file symbol header lying around, blow it away. */
236 free ((char *)cur_hdr);
241 mipscoff_symfile_init (sf)
244 sf->sym_private = NULL;
248 mipscoff_symfile_read(sf, addr, mainline)
253 struct coff_symfile_info *info = (struct coff_symfile_info *)sf->sym_private;
254 bfd *abfd = sf->objfile->obfd;
255 char *name = bfd_get_filename (abfd);
259 int stringtab_offset;
261 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
262 desc = fileno ((FILE *)(abfd->iostream)); /* Raw file descriptor */
265 /* Position to read the symbol table. */
266 val = lseek (desc, (long)symtab_offset, 0);
268 perror_with_name (name);
270 init_misc_bunches ();
271 make_cleanup (discard_misc_bunches, 0);
273 /* Now that the executable file is positioned at symbol table,
274 process it and define symbols accordingly. */
276 read_mips_symtab(sf->objfile, desc);
278 /* Go over the misc symbol bunches and install them in vector. */
280 condense_misc_bunches (!mainline);
283 /* Exported procedure: Allocate zeroed memory */
288 char *p = xmalloc(size);
294 /* Exported procedure: Builds a symtab from the PST partial one.
295 Restores the environment in effect when PST was created, delegates
296 most of the work to an ancillary procedure, and sorts
297 and reorders the symtab list at the end */
300 mipscoff_psymtab_to_symtab(pst)
301 struct partial_symtab *pst;
310 printf_filtered("Reading in symbols for %s...", pst->filename);
313 /* Restore the header and list of pending typedefs */
314 cur_hdr = CUR_HDR(pst);
316 next_symbol_text_func = mips_next_symbol_text;
318 psymtab_to_symtab_1(pst, pst->filename);
320 /* Match with global symbols. This only needs to be done once,
321 after all of the symtabs and dependencies have been read in. */
322 scan_file_globals ();
325 printf_filtered("done.\n");
328 /* Exported procedure: Is PC in the signal trampoline code */
331 in_sigtramp(pc, name)
335 if (sigtramp_address == 0)
337 return (pc >= sigtramp_address && pc < sigtramp_end);
340 /* File-level interface functions */
342 /* Read the symtab information from file FSYM into memory. Also,
343 return address just past end of our text segment in *END_OF_TEXT_SEGP. */
346 read_the_mips_symtab(abfd, fsym, end_of_text_segp)
349 CORE_ADDR *end_of_text_segp;
351 int stsize, st_hdrsize;
354 /* Header for executable/object file we read symbols from */
355 struct coff_exec filhdr;
357 /* We get here with DESC pointing to the symtab header. But we need
358 * other info from the initial headers */
360 myread(fsym, &filhdr, sizeof filhdr);
362 if (end_of_text_segp)
364 bfd_h_get_32 (abfd, filhdr.a.text_start) +
365 bfd_h_get_32 (abfd, filhdr.a.tsize);
367 /* Find and read the symbol table header */
368 st_hdrsize = bfd_h_get_32 (abfd, filhdr.f.f_nsyms);
369 st_filptr = bfd_h_get_32 (abfd, filhdr.f.f_symptr);
373 lseek(fsym, st_filptr, L_SET);
374 if (st_hdrsize > sizeof (st_hdr)) /* Profanity check */
376 if (read(fsym, &st_hdr, st_hdrsize) != st_hdrsize)
379 /* Find out how large the symbol table is */
380 stsize = (st_hdr.cbExtOffset - (st_filptr + st_hdrsize))
381 + st_hdr.iextMax * cbEXTR;
383 /* Allocate space for the symbol table. Read it in. */
384 cur_hdr = (HDRR *) xmalloc(stsize + st_hdrsize);
386 memcpy(cur_hdr, &st_hdr, st_hdrsize);
387 if (read(fsym, (char *) cur_hdr + st_hdrsize, stsize) != stsize)
390 /* Fixup file_pointers in it */
391 fixup_symtab(cur_hdr, (char *) cur_hdr + st_hdrsize,
392 st_filptr + st_hdrsize);
396 error("Short read on %s", bfd_get_filename (abfd));
400 /* Turn all file-relative pointers in the symtab described by HDR
401 into memory pointers, given that the symtab itself is located
402 at DATA in memory and F_PTR in the file. */
405 fixup_symtab( hdr, data, f_ptr)
417 * These fields are useless (and empty) by now:
418 * hdr->cbDnOffset, hdr->cbOptOffset
419 * We use them for other internal purposes.
422 hdr->cbOptOffset = 0;
425 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
441 * Fix all string pointers inside the symtab, and
442 * the FDR records. Also fix other miscellany.
444 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
445 register unsigned code_offset;
447 /* Header itself, and strings */
448 fh = (FDR *) (hdr->cbFdOffset) + f_idx;
449 fh->issBase += hdr->cbSsOffset;
451 fh->rss = (long)fh->rss + fh->issBase;
454 fh->isymBase = (int)((SYMR*)(hdr->cbSymOffset)+fh->isymBase);
456 /* FIXME! Probably don't want to do this here! */
457 for (s_idx = 0; s_idx < fh->csym; s_idx++) {
458 sh = (SYMR*)fh->isymBase + s_idx;
459 sh->iss = (long) sh->iss + fh->issBase;
465 /* cannot fix fh->ipdFirst because it is a short */
466 #define IPDFIRST(h,fh) \
467 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
469 /* Optional symbols (actually used for partial_symtabs) */
475 fh->iauxBase = hdr->cbAuxOffset + fh->iauxBase * sizeof(AUXU);
476 /* Relative file descriptor table */
477 fh->rfdBase = hdr->cbRfdOffset + fh->rfdBase * sizeof(RFDT);
481 fh->cbLineOffset += hdr->cbLineOffset;
483 /* Procedure symbols. (XXX This should be done later) */
484 code_offset = fh->adr;
485 for (s_idx = 0; s_idx < fh->cpd; s_idx++) {
486 unsigned name, only_ext;
488 pr = (PDR*)(IPDFIRST(hdr,fh)) + s_idx;
490 /* Simple rule to find files linked "-x" */
491 only_ext = fh->rss == -1;
493 if (pr->isym == -1) {
494 /* static function */
498 name = hdr->cbExtOffset + pr->isym * sizeof(EXTR);
499 sh = &((EXTR*)name)->asym;
503 sh = (SYMR*)fh->isymBase + pr->isym;
504 /* Included code ? */
505 if (s_idx == 0 && pr->adr != 0)
506 code_offset -= pr->adr;
509 /* Turn index into a pointer */
512 /* Fix line numbers */
513 pr->cbLineOffset += fh->cbLineOffset;
515 /* Relocate address */
517 pr->adr += code_offset;
521 /* External symbols: fix string */
522 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
523 esh = (EXTR*)(hdr->cbExtOffset) + s_idx;
524 esh->asym.iss = esh->asym.iss + hdr->cbSsExtOffset;
529 /* Find a file descriptor given its index RF relative to a file CF */
537 f = (FDR *) (cur_hdr->cbFdOffset) + cf;
538 /* Object files do not have the RFD table, all refs are absolute */
540 return (FDR *) (cur_hdr->cbFdOffset) + rf;
541 cf = *((pRFDT) f->rfdBase + rf);
542 return (FDR *) (cur_hdr->cbFdOffset) + cf;
545 /* Return a safer print NAME for a file descriptor */
551 if (name == (char *) -1)
552 return "<stripped file>";
553 if (UNSAFE_DATA_ADDR(name))
559 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
560 whether we are adding to the general symtab or not.
561 FIXME: INCREMENTAL is currently always zero, though it should not be. */
564 read_mips_symtab (objfile, desc)
565 struct objfile *objfile;
568 CORE_ADDR end_of_text_seg;
570 read_the_mips_symtab(objfile->obfd, desc, &end_of_text_seg);
572 parse_partial_symbols(end_of_text_seg, objfile);
576 * Check to make sure file was compiled with -g.
577 * If not, warn the user of this limitation.
579 if (compare_glevel(max_glevel, GLEVEL_2) < 0) {
580 if (max_gdbinfo == 0)
582 "\n%s not compiled with -g, debugging support is limited.\n",
585 "You should compile with -g2 or -g3 for best debugging support.\n");
591 /* Local utilities */
593 /* Map of FDR indexes to partial symtabs */
596 struct partial_symtab *pst; /* the psymtab proper */
597 int n_globals; /* exported globals (external symbols) */
598 int globals_offset; /* cumulative */
602 /* Utility stack, used to nest procedures and blocks properly.
603 It is a doubly linked list, to avoid too many alloc/free.
604 Since we might need it quite a few times it is NOT deallocated
607 static struct parse_stack {
608 struct parse_stack *next, *prev;
609 struct symtab *cur_st; /* Current symtab. */
610 struct block *cur_block; /* Block in it. */
611 int blocktype; /* What are we parsing. */
612 int maxsyms; /* Max symbols in this block. */
613 struct type *cur_type; /* Type we parse fields for. */
614 int cur_field; /* Field number in cur_type. */
615 int procadr; /* Start addres of this procedure */
616 int numargs; /* Its argument count */
617 } *top_stack; /* Top stack ptr */
620 /* Enter a new lexical context */
622 static push_parse_stack()
624 struct parse_stack *new;
626 /* Reuse frames if possible */
627 if (top_stack && top_stack->prev)
628 new = top_stack->prev;
630 new = (struct parse_stack *) xzalloc(sizeof(struct parse_stack));
631 /* Initialize new frame with previous content */
633 register struct parse_stack *prev = new->prev;
636 top_stack->prev = new;
638 new->next = top_stack;
643 /* Exit a lexical context */
645 static pop_parse_stack()
650 top_stack = top_stack->next;
654 /* Cross-references might be to things we haven't looked at
655 yet, e.g. type references. To avoid too many type
656 duplications we keep a quick fixup table, an array
657 of lists of references indexed by file descriptor */
659 static struct mips_pending {
660 struct mips_pending *next; /* link */
661 SYMR *s; /* the symbol */
662 struct type *t; /* its partial type descriptor */
666 /* Check whether we already saw symbol SH in file FH as undefined */
669 struct mips_pending *is_pending_symbol(fh, sh)
673 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
674 register struct mips_pending *p;
676 /* Linear search is ok, list is typically no more than 10 deep */
677 for (p = pending_list[f_idx]; p; p = p->next)
683 /* Check whether we already saw type T in file FH as undefined */
686 struct mips_pending *is_pending_type(fh, t)
690 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
691 register struct mips_pending *p;
693 for (p = pending_list[f_idx]; p; p = p->next)
699 /* Add a new undef symbol SH of type T */
702 add_pending(fh, sh, t)
707 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
708 struct mips_pending *p = is_pending_symbol(fh, sh);
710 /* Make sure we do not make duplicates */
712 p = (struct mips_pending *) xmalloc(sizeof(*p));
715 p->next = pending_list[f_idx];
716 pending_list[f_idx] = p;
718 sh->reserved = 1; /* for quick check */
721 /* Throw away undef entries when done with file index F_IDX */
726 register struct mips_pending *p, *q;
728 for (p = pending_list[f_idx]; p; p = q) {
732 pending_list[f_idx] = 0;
735 /* The number of args to a procedure is not explicit in the symtab,
736 this is the list of all those we know of.
737 This makes parsing more reasonable and avoids extra passes */
739 static struct numarg {
740 struct numarg *next; /* link */
741 unsigned adr; /* procedure's start address */
742 unsigned num; /* arg count */
745 /* Record that the procedure at ADR takes NUM arguments. */
750 struct numarg *n = (struct numarg *) xmalloc(sizeof(struct numarg));
754 n->next = numargs_list;
758 /* See if we know how many arguments the procedure at ADR takes */
763 struct numarg *n = numargs_list;
765 while (n && n->adr != adr)
767 return (n) ? n->num : -1;
770 /* Release storage when done with this file */
775 struct numarg *n = numargs_list, *m;
786 prepend_tag_kind(tag_name, type_code)
796 case TYPE_CODE_STRUCT:
799 case TYPE_CODE_UNION:
806 result = (char*)obstack_alloc (symbol_obstack,
807 strlen(prefix) + strlen(tag_name) + 1);
808 sprintf(result, "%s%s", prefix, tag_name);
813 /* Parsing Routines proper. */
815 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
816 For blocks, procedures and types we open a new lexical context.
817 This is basically just a big switch on the symbol's type.
818 Return count of SYMR's handled (normally one). */
831 /* When a symbol is cross-referenced from other files/symbols
832 we mark it explicitly */
833 int pend = (sh->reserved == 1);
834 enum address_class class;
841 case stGlobal: /* external symbol, goes into global block */
843 b = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st),
845 s = new_symbol(sh->iss);
846 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
849 case stStatic: /* static data, goes into current block. */
851 b = top_stack->cur_block;
852 s = new_symbol(sh->iss);
853 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
856 case stLocal: /* local variable, goes into current block */
857 if (sh->sc == scRegister) {
858 class = LOC_REGISTER;
860 sh->value += FP0_REGNUM-32;
863 b = top_stack->cur_block;
864 s = new_symbol(sh->iss);
865 SYMBOL_VALUE(s) = sh->value;
867 data: /* Common code for symbols describing data */
868 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
869 SYMBOL_CLASS(s) = class;
872 /* Type could be missing in a number of cases */
873 if (sh->sc == scUndefined || sh->sc == scNil ||
874 sh->index == 0xfffff)
875 SYMBOL_TYPE(s) = builtin_type_int; /* undefined? */
877 SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0);
878 /* Value of a data symbol is its memory address */
881 case stParam: /* arg to procedure, goes into current block */
883 top_stack->numargs++;
885 name = (char*)sh->iss;
886 /* Special GNU C++ name. */
887 if (name[0] == CPLUS_MARKER && name[1] == 't' && name[2] == 0)
889 s = new_symbol(name);
891 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
892 if (sh->sc == scRegister) {
893 SYMBOL_CLASS(s) = LOC_REGPARM;
895 sh->value += FP0_REGNUM-32;
897 SYMBOL_CLASS(s) = LOC_ARG;
898 SYMBOL_VALUE(s) = sh->value;
899 SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0);
900 add_symbol(s, top_stack->cur_block);
902 /* FIXME: This has not been tested. See dbxread.c */
903 /* Add the type of this parameter to the function/procedure
904 type of this block. */
905 add_param_to_type(&top_stack->cur_block->function->type,s);
909 case stLabel: /* label, goes into current block */
910 s = new_symbol(sh->iss);
911 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE; /* so that it can be used */
912 SYMBOL_CLASS(s) = LOC_LABEL; /* but not misused */
913 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
914 SYMBOL_TYPE(s) = builtin_type_int;
915 add_symbol(s, top_stack->cur_block);
918 case stProc: /* Procedure, usually goes into global block */
919 case stStaticProc: /* Static procedure, goes into current block */
920 s = new_symbol(sh->iss);
921 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
922 SYMBOL_CLASS(s) = LOC_BLOCK;
923 /* Type of the return value */
924 if (sh->sc == scUndefined || sh->sc == scNil)
925 t = builtin_type_int;
927 t = parse_type(ax + sh->index, sh, 0);
928 b = top_stack->cur_block;
929 if (sh->st == stProc) {
930 struct blockvector *bv = BLOCKVECTOR(top_stack->cur_st);
931 /* The next test should normally be true,
932 but provides a hook for nested functions
933 (which we don't want to make global). */
934 if (b == BLOCKVECTOR_BLOCK(bv, STATIC_BLOCK))
935 b = BLOCKVECTOR_BLOCK(bv, GLOBAL_BLOCK);
939 /* Make a type for the procedure itself */
941 /* FIXME: This has not been tested yet! See dbxread.c */
942 /* Generate a template for the type of this function. The
943 types of the arguments will be added as we read the symbol
945 bcopy(SYMBOL_TYPE(s),lookup_function_type(t),sizeof(struct type));
947 SYMBOL_TYPE(s) = lookup_function_type (t);
950 /* Create and enter a new lexical context */
951 b = new_block(top_stack->maxsyms);
952 SYMBOL_BLOCK_VALUE(s) = b;
953 BLOCK_FUNCTION(b) = s;
954 BLOCK_START(b) = BLOCK_END(b) = sh->value;
955 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
956 add_block(b, top_stack->cur_st);
958 /* Not if we only have partial info */
959 if (sh->sc == scUndefined || sh->sc == scNil)
963 top_stack->cur_block = b;
964 top_stack->blocktype = sh->st;
965 top_stack->cur_type = SYMBOL_TYPE(s);
966 top_stack->cur_field = -1;
967 top_stack->procadr = sh->value;
968 top_stack->numargs = 0;
970 sh->value = (long) SYMBOL_TYPE(s);
974 #ifndef btVoid /* btVoid was added late. */
977 /* These new symbol types have been recently added to SGI machines. */
991 case stBlock: /* Either a lexical block, or some type */
993 top_stack->blocktype = stBlock;
994 if (sh->sc == scInfo) { /* structure/union/enum def */
996 sh->st == stStruct ? TYPE_CODE_STRUCT
997 : sh->st == stUnion ? TYPE_CODE_UNION
998 : sh->st == stEnum ? TYPE_CODE_ENUM
1005 s = new_symbol(sh->iss);
1006 SYMBOL_NAMESPACE(s) = STRUCT_NAMESPACE;
1007 SYMBOL_CLASS(s) = LOC_TYPEDEF;
1008 SYMBOL_VALUE(s) = 0;
1009 add_symbol(s, top_stack->cur_block);
1011 /* First count the number of fields. */
1012 for (tsym = sh+1; tsym->st != stEnd; tsym++)
1013 if (tsym->st == stMember) {
1014 if (nfields == 0 && type_code == TYPE_CODE_UNDEF)
1015 /* If the type of the member is Nil (or Void)
1016 assume the tag is an enumeration. */
1017 if (tsym->index == indexNil
1018 || ax[tsym->index].ti.bt == btNil
1019 || ax[tsym->index].ti.bt == btVoid)
1020 type_code = TYPE_CODE_ENUM;
1022 if (tsym->value > max_value)
1023 max_value = tsym->value;
1025 else if (tsym->st == stBlock
1026 || tsym->st == stParsed) {
1027 if (tsym->sc == scVariant) ; /*UNIMPLEMENTED*/
1028 if (tsym->index != 0)
1029 tsym = ((SYMR*)cur_fdr->isymBase)
1034 /* There is no guaranteed way to distinguish struct,
1035 unions, and enums at this point. This is a bug in the
1036 original design (that has been fixed with the
1037 recent addition of the stStruct, stUnion, and stEnum
1038 symbol types.) The way you can tell is if/when you
1039 see a variable or field of that type: In that case
1040 the variable's type (in the AUX table) says if the
1041 type is struct, union, or enum,
1042 and points back to the stBlock here.
1043 So you can patch the tag kind up later - but only
1044 if there actually is a variable or field of that type.
1046 So until we know for sure, we will guess at this point.
1048 If the first member has index==indexNil or a void type,
1049 assume we have an enumeration.
1050 Otherwise, if all the members have offset 0,
1051 assume we have a union.
1052 Otherwise, assume we have a struct.
1054 The heuristic could guess wrong in the case of
1055 of an enumeration with no members or a union
1056 with one (or zero) members, or when all except the
1057 last field of a struct have width zero.
1058 These are uncommon and/or illegal situations, and
1059 in any case guessing wrong probably doesn't matter much.
1061 But if we later do find out we were wrong,
1062 we fixup the tag kind. Members of an enumeration
1063 must be handled differently from struct/union fields,
1064 and that is harder to patch up, but luckily we
1065 shouldn't need to. (If there are any enumeration
1066 members, we can tell for sure it's an enum here.) */
1068 if (type_code == TYPE_CODE_UNDEF)
1069 if (max_value == 0) type_code = TYPE_CODE_UNION;
1070 else type_code = TYPE_CODE_STRUCT;
1072 /* If this type was expected, use its partial definition */
1074 t = is_pending_symbol(cur_fdr, sh)->t;
1076 t = new_type(prepend_tag_kind(sh->iss, type_code));
1078 TYPE_CODE(t) = type_code;
1079 TYPE_NFIELDS(t) = nfields;
1080 TYPE_FIELDS(t) = f = (struct field*)
1081 obstack_alloc (symbol_obstack,
1082 nfields * sizeof (struct field));
1084 if (type_code == TYPE_CODE_ENUM) {
1085 /* This is a non-empty enum. */
1086 while (sh[1].st == stMember) {
1087 struct symbol *enum_sym;
1089 f->bitpos = sh->value;
1091 f->name = (char*)sh->iss;
1094 enum_sym = (struct symbol *)
1095 obstack_alloc (symbol_obstack,
1096 sizeof (struct symbol));
1097 memset (enum_sym, 0, sizeof (struct symbol));
1098 SYMBOL_NAME (enum_sym) = f->name;
1099 SYMBOL_CLASS (enum_sym) = LOC_CONST;
1100 SYMBOL_TYPE (enum_sym) = t;
1101 SYMBOL_NAMESPACE (enum_sym) = VAR_NAMESPACE;
1102 SYMBOL_VALUE (enum_sym) = sh->value;
1103 add_symbol(enum_sym, top_stack->cur_block);
1105 /* Skip the stMembers that we've handled. */
1111 /* make this the current type */
1112 top_stack->cur_type = t;
1113 top_stack->cur_field = 0;
1114 TYPE_LENGTH(t) = sh->value;
1115 /* Mark that symbol has a type, and say which one */
1116 sh->value = (long) t;
1118 /* beginnning of (code) block. Value of symbol
1119 is the displacement from procedure start */
1120 b = new_block(top_stack->maxsyms);
1121 BLOCK_START(b) = sh->value + top_stack->procadr;
1122 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
1123 top_stack->cur_block = b;
1124 add_block(b, top_stack->cur_st);
1128 case stEnd: /* end (of anything) */
1129 if (sh->sc == scInfo) {
1130 /* Finished with type */
1131 top_stack->cur_type = 0;
1132 } else if (sh->sc == scText &&
1133 (top_stack->blocktype == stProc ||
1134 top_stack->blocktype == stStaticProc)) {
1135 /* Finished with procedure */
1136 struct blockvector *bv = BLOCKVECTOR(top_stack->cur_st);
1140 BLOCK_END(top_stack->cur_block) += sh->value; /* size */
1141 got_numargs(top_stack->procadr, top_stack->numargs);
1142 /* Reallocate symbols, saving memory */
1143 b = shrink_block(top_stack->cur_block, top_stack->cur_st);
1145 /* f77 emits proc-level with address bounds==[0,0],
1146 So look for such child blocks, and patch them. */
1147 for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++) {
1148 struct block *b_bad = BLOCKVECTOR_BLOCK(bv,i);
1149 if (BLOCK_SUPERBLOCK(b_bad) == b
1150 && BLOCK_START(b_bad) == top_stack->procadr
1151 && BLOCK_END(b_bad) == top_stack->procadr) {
1152 BLOCK_START(b_bad) = BLOCK_START(b);
1153 BLOCK_END(b_bad) = BLOCK_END(b);
1156 } else if (sh->sc == scText && top_stack->blocktype == stBlock) {
1157 /* End of (code) block. The value of the symbol
1158 is the displacement from the procedure`s start
1159 address of the end of this block. */
1160 BLOCK_END(top_stack->cur_block) = sh->value + top_stack->procadr;
1161 (void) shrink_block(top_stack->cur_block, top_stack->cur_st);
1163 pop_parse_stack(); /* restore previous lexical context */
1166 case stMember: /* member of struct or union */
1167 f = &TYPE_FIELDS(top_stack->cur_type)[top_stack->cur_field++];
1168 f->name = (char*)sh->iss;
1169 f->bitpos = sh->value;
1171 f->type = parse_type(ax + sh->index, sh, &f->bitsize);
1174 case stTypedef: /* type definition */
1175 s = new_symbol(sh->iss);
1176 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
1177 SYMBOL_CLASS(s) = LOC_TYPEDEF;
1178 SYMBOL_BLOCK_VALUE(s) = top_stack->cur_block;
1179 add_symbol(s, top_stack->cur_block);
1180 SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0);
1181 sh->value = (long) SYMBOL_TYPE(s);
1184 case stFile: /* file name */
1186 top_stack->blocktype = sh->st;
1189 /* I`ve never seen these for C */
1191 break; /* register relocation */
1193 break; /* forwarding address */
1195 break; /* constant */
1197 error("Unknown symbol type %x.", sh->st);
1203 /* Parse the type information provided in the AX entries for
1204 the symbol SH. Return the bitfield size in BS, in case. */
1206 static struct type *parse_type(ax, sh, bs)
1211 /* Null entries in this map are treated specially */
1212 static struct type **map_bt[] =
1214 &builtin_type_void, /* btNil */
1216 &builtin_type_char, /* btChar */
1217 &builtin_type_unsigned_char, /* btUChar */
1218 &builtin_type_short, /* btShort */
1219 &builtin_type_unsigned_short, /* btUShort */
1220 &builtin_type_int, /* btInt */
1221 &builtin_type_unsigned_int, /* btUInt */
1222 &builtin_type_long, /* btLong */
1223 &builtin_type_unsigned_long, /* btULong */
1224 &builtin_type_float, /* btFloat */
1225 &builtin_type_double, /* btDouble */
1232 &builtin_type_complex, /* btComplex */
1233 &builtin_type_double_complex, /* btDComplex */
1235 &builtin_type_fixed_dec, /* btFixedDec */
1236 &builtin_type_float_dec, /* btFloatDec */
1237 &builtin_type_string, /* btString */
1240 &builtin_type_void, /* btVoid */
1244 struct type *tp = 0;
1249 /* Procedures start off by one */
1250 if (sh->st == stProc || sh->st == stStaticProc)
1253 /* Undefined ? Should not happen */
1254 if (ax->rndx.rfd == 0xfff) {
1255 return builtin_type_void;
1258 /* Use aux as a type information record, map its basic type */
1260 if (t->bt > (sizeof (map_bt)/sizeof (*map_bt))) {
1261 complain (&basic_type_complaint, t->bt);
1262 return builtin_type_int;
1264 if (map_bt[t->bt]) {
1265 tp = *map_bt[t->bt];
1269 /* Cannot use builtin types -- build our own */
1272 tp = lookup_pointer_type (builtin_type_void);
1276 type_code = TYPE_CODE_STRUCT;
1280 type_code = TYPE_CODE_UNION;
1284 type_code = TYPE_CODE_ENUM;
1288 type_code = TYPE_CODE_RANGE;
1292 type_code = TYPE_CODE_SET;
1297 complain (&basic_type_complaint, t->bt);
1298 return builtin_type_int;
1302 /* Move on to next aux */
1305 /* This is the way it would work if the compiler worked */
1306 register TIR *t1 = t;
1307 while (t1->continued)
1316 /* All these types really point to some (common) MIPS type
1317 definition, and only the type-qualifiers fully identify
1318 them. We'll make the same effort at sharing. */
1319 if (t->bt == btIndirect ||
1320 t->bt == btStruct ||
1323 t->bt == btTypedef ||
1326 char name[256], *pn;
1328 /* Try to cross reference this type */
1329 ax += cross_ref(ax, &tp, type_code, &pn);
1330 /* reading .o file ? */
1331 if (UNSAFE_DATA_ADDR(tp))
1332 tp = make_type(type_code, 0, 0, 0);
1333 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1334 sprintf(name, fmt, pn);
1336 /* Usually, TYPE_CODE(tp) is already type_code. The main
1337 exception is if we guessed wrong re struct/union/enum. */
1338 if (TYPE_CODE(tp) != type_code) {
1339 complain (&bad_tag_guess_complaint, 0);
1340 TYPE_CODE(tp) = type_code;
1342 if (TYPE_NAME(tp) == NULL || strcmp(TYPE_NAME(tp), name) != 0)
1343 TYPE_NAME(tp) = obsavestring(name, strlen(name));
1346 /* Deal with range types */
1347 if (t->bt == btRange) {
1350 TYPE_NFIELDS (tp) = 2;
1352 (struct field *) obstack_alloc (symbol_obstack,
1353 2 * sizeof (struct field));
1354 TYPE_FIELD_NAME (tp, 0) = "Low";
1355 TYPE_FIELD_BITPOS (tp, 0) = ax->dnLow;
1357 TYPE_FIELD_NAME (tp, 1) = "High";
1358 TYPE_FIELD_BITPOS (tp, 1) = ax->dnHigh;
1362 /* Parse all the type qualifiers now. If there are more
1363 than 6 the game will continue in the next aux */
1365 #define PARSE_TQ(tq) \
1366 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, sh);
1368 again: PARSE_TQ(tq0);
1383 /* Make up a complex type from a basic one. Type is passed by
1384 reference in TPP and side-effected as necessary. The type
1385 qualifier TQ says how to handle the aux symbols at AX for
1386 the symbol SX we are currently analyzing.
1387 Returns the number of aux symbols we parsed. */
1390 upgrade_type(tpp, tq, ax, sh)
1398 /* Used in array processing */
1407 t = lookup_pointer_type (*tpp);
1412 t = lookup_function_type (*tpp);
1418 t = make_type(TYPE_CODE_ARRAY, 0, 0, 0);
1419 TYPE_TARGET_TYPE(t) = *tpp;
1421 /* Determine and record the domain type (type of index) */
1422 id = ax->rndx.index;
1428 fh = get_rfd(cur_fd, rf);
1430 /* Fields are kept in an array */
1431 /* FIXME - Memory leak! */
1432 if (TYPE_NFIELDS(t))
1433 TYPE_FIELDS(t) = (struct field*)
1434 xrealloc(TYPE_FIELDS(t),
1435 (TYPE_NFIELDS(t)+1) * sizeof(struct field));
1437 TYPE_FIELDS(t) = (struct field*)
1438 xzalloc(sizeof(struct field));
1439 f = &(TYPE_FIELD(t,TYPE_NFIELDS(t)));
1441 memset(f, 0, sizeof(struct field));
1443 memset(&ss, 0, sizeof ss);
1444 /* XXX */ f->type = parse_type(fh->iauxBase + id * sizeof(AUXU),
1449 * This seems to be a pointer to the end of the Block defining
1450 * the type. Why it is here is magic for me, and I have no
1451 * good use for it anyways.
1453 /* This used to occur because cross_ref returned
1454 the wrong result (ax pointed wrong). FIXME,
1455 delete this code in a while. -- gnu@cygnus jul91 */
1456 complain (&array_parse_complaint, 0);
1458 id = (++ax)->rndx.index;
1459 if ((rf = ax->rndx.rfd) == 0xfff)
1460 rf = (++ax)->isym, off++;
1462 lower = (++ax)->dnLow;
1463 upper = (++ax)->dnHigh;
1464 rf = (++ax)->width; /* bit size of array element */
1466 /* Check whether supplied array element bit size matches
1467 the known size of the element type. If this complaint
1468 ends up not happening, we can remove this code. It's
1469 here because we aren't sure we understand this *&%&$
1471 id = TYPE_LENGTH(TYPE_TARGET_TYPE(t)) << 3; /* bitsize */
1473 /* Most likely an undefined type */
1475 TYPE_LENGTH(TYPE_TARGET_TYPE(t)) = id >> 3;
1478 complain (&array_bitsize_complaint, rf);
1480 TYPE_LENGTH(t) = (upper < 0) ? 0 :
1481 (upper - lower + 1) * (rf >> 3);
1486 /* Volatile -- currently ignored */
1490 complain (&unknown_type_qual_complaint, tq);
1496 /* Parse a procedure descriptor record PR. Note that the procedure
1497 is parsed _after_ the local symbols, now we just make up the
1498 extra information we need into a special symbol that we insert
1499 in the procedure's main block. Note also that images that
1500 have been partially stripped (ld -x) have been deprived
1501 of local symbols, and we have to cope with them here.
1502 The procedure's code ends at BOUND */
1505 parse_procedure(pr, bound)
1508 struct symbol *s, *i;
1509 SYMR *sh = (SYMR*)pr->isym;
1511 struct mips_extra_func_info *e;
1515 /* Reuse the MIPS record */
1516 e = (struct mips_extra_func_info *) pr;
1517 e->numargs = lookup_numargs(pr->adr);
1519 /* Make up our special symbol */
1520 i = new_symbol(".gdbinfo.");
1521 SYMBOL_VALUE(i) = (int)e;
1522 SYMBOL_NAMESPACE(i) = LABEL_NAMESPACE;
1523 SYMBOL_CLASS(i) = LOC_CONST;
1524 SYMBOL_TYPE(i) = builtin_type_void;
1526 /* Make up a name for static procedures. Sigh. */
1527 if (sh == (SYMR*)-1) {
1528 sprintf(name,".static_procedure@%x",pr->adr);
1529 sh_name = savestring(name, strlen(name));
1533 sh_name = (char*)sh->iss;
1534 s = mylookup_symbol(sh_name, top_stack->cur_block,
1535 VAR_NAMESPACE, LOC_BLOCK);
1538 b = SYMBOL_BLOCK_VALUE(s);
1540 s = new_symbol(sh_name);
1541 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
1542 SYMBOL_CLASS(s) = LOC_BLOCK;
1543 /* Donno its type, hope int is ok */
1544 SYMBOL_TYPE(s) = lookup_function_type (builtin_type_int);
1545 add_symbol(s, top_stack->cur_block);
1546 /* Wont have symbols for this one */
1548 SYMBOL_BLOCK_VALUE(s) = b;
1549 BLOCK_FUNCTION(b) = s;
1550 BLOCK_START(b) = pr->adr;
1551 BLOCK_END(b) = bound;
1552 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
1553 add_block(b, top_stack->cur_st);
1559 /* Parse the external symbol ES. Just call parse_symbol() after
1560 making sure we know where the aux are for it. For procedures,
1561 parsing of the PDRs has already provided all the needed
1562 information, we only parse them if SKIP_PROCEDURES is false,
1563 and only if this causes no symbol duplication.
1565 This routine clobbers top_stack->cur_block and ->cur_st. */
1568 parse_external(es, skip_procedures)
1573 if (es->ifd != ifdNil) {
1575 cur_fdr = (FDR*)(cur_hdr->cbFdOffset) + cur_fd;
1576 ax = (AUXU*)cur_fdr->iauxBase;
1578 cur_fdr = (FDR*)(cur_hdr->cbFdOffset);
1581 top_stack->cur_st = cur_stab;
1582 top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st),
1585 /* Reading .o files */
1586 if (es->asym.sc == scUndefined || es->asym.sc == scNil) {
1588 switch (es->asym.st) {
1590 case stProc: what = "procedure"; n_undef_procs++; break;
1591 case stGlobal: what = "variable"; n_undef_vars++; break;
1592 case stLabel: what = "label"; n_undef_labels++; break;
1593 default : what = "symbol"; break;
1597 printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what,
1598 es->asym.iss, fdr_name(cur_fdr->rss));
1602 switch (es->asym.st) {
1604 /* If we have full symbols we do not need more */
1605 if (skip_procedures)
1607 if (mylookup_symbol (es->asym.iss, top_stack->cur_block,
1608 VAR_NAMESPACE, LOC_BLOCK))
1614 * Note that the case of a symbol with indexNil
1615 * must be handled anyways by parse_symbol().
1617 parse_symbol(&es->asym, ax);
1624 /* Parse the line number info for file descriptor FH into
1625 GDB's linetable LT. MIPS' encoding requires a little bit
1626 of magic to get things out. Note also that MIPS' line
1627 numbers can go back and forth, apparently we can live
1628 with that and do not need to reorder our linetables */
1633 struct linetable *lt;
1635 unsigned char *base = (unsigned char*)fh->cbLineOffset;
1637 int delta, count, lineno = 0;
1643 /* Scan by procedure descriptors */
1644 i = 0; j = 0, k = 0;
1645 for (pr = (PDR*)IPDFIRST(cur_hdr,fh); j < fh->cpd; j++, pr++) {
1648 /* No code for this one */
1649 if (pr->iline == ilineNil ||
1650 pr->lnLow == -1 || pr->lnHigh == -1)
1653 * Aurgh! To know where to stop expanding we
1656 for (l = 1; l < (fh->cpd - j); l++)
1657 if (pr[l].iline != -1)
1659 if (l == (fh->cpd - j))
1664 * When procedures are moved around the linenumbers
1665 * are attributed to the next procedure up
1667 if (pr->iline >= halt) continue;
1669 base = (unsigned char*)pr->cbLineOffset;
1670 l = pr->adr >> 2; /* in words */
1671 halt += (pr->adr >> 2) - pr->iline;
1672 for (lineno = pr->lnLow; l < halt;) {
1673 count = *base & 0x0f;
1674 delta = *base++ >> 4;
1678 delta = (base[0] << 8) | base[1];
1679 if (delta >= 0x8000)
1683 lineno += delta;/* first delta is 0 */
1684 k = add_line(lt, lineno, l, k);
1691 /* Master parsing procedure for first-pass reading of file symbols
1692 into a partial_symtab.
1694 Parses the symtab described by the global symbolic header CUR_HDR.
1695 END_OF_TEXT_SEG gives the address just after the text segment for
1696 the symtab we are reading. */
1699 parse_partial_symbols(end_of_text_seg, objfile)
1700 int end_of_text_seg;
1701 struct objfile *objfile;
1704 /* int stat_idx, h_max;*/
1705 HDRR *hdr = cur_hdr;
1706 /* Running pointers */
1711 struct partial_symtab *pst;
1713 int past_first_source_file = 0;
1715 /* List of current psymtab's include files */
1716 char **psymtab_include_list;
1717 int includes_allocated;
1720 struct pst_map * fdr_to_pst;
1721 /* Index within current psymtab dependency list */
1722 struct partial_symtab **dependency_list;
1723 int dependencies_used, dependencies_allocated;
1724 struct cleanup *old_chain;
1726 extern_tab = (EXTR**)obstack_alloc (psymbol_obstack,
1727 sizeof(EXTR *) * hdr->iextMax);
1729 includes_allocated = 30;
1731 psymtab_include_list = (char **) alloca (includes_allocated *
1733 next_symbol_text_func = mips_next_symbol_text;
1735 dependencies_allocated = 30;
1736 dependencies_used = 0;
1738 (struct partial_symtab **) alloca (dependencies_allocated *
1739 sizeof (struct partial_symtab *));
1741 last_source_file = 0;
1746 * Only parse the Local and External symbols, and the Relative FDR.
1747 * Fixup enough of the loader symtab to be able to use it.
1748 * Allocate space only for the file's portions we need to
1753 max_glevel = MIN_GLEVEL;
1755 /* Allocate the map FDR -> PST.
1756 Minor hack: -O3 images might claim some global data belongs
1757 to FDR -1. We`ll go along with that */
1758 fdr_to_pst = (struct pst_map *)xzalloc((hdr->ifdMax+1) * sizeof *fdr_to_pst);
1759 old_chain = make_cleanup (free, fdr_to_pst);
1762 struct partial_symtab * pst = new_psymtab("", objfile);
1763 fdr_to_pst[-1].pst = pst;
1767 /* Pass 1 over external syms: Presize and partition the list */
1768 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
1769 esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
1770 fdr_to_pst[esh->ifd].n_globals++;
1773 /* Pass 1.5 over files: partition out global symbol space */
1775 for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++) {
1776 fdr_to_pst[f_idx].globals_offset = s_idx;
1777 s_idx += fdr_to_pst[f_idx].n_globals;
1778 fdr_to_pst[f_idx].n_globals = 0;
1781 /* Pass 2 over external syms: fill in external symbols */
1782 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
1783 enum misc_function_type misc_type = mf_text;
1784 esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
1786 extern_tab[fdr_to_pst[esh->ifd].globals_offset
1787 + fdr_to_pst[esh->ifd].n_globals++] = esh;
1789 if (esh->asym.sc == scUndefined || esh->asym.sc == scNil)
1792 switch (esh->asym.st) {
1796 misc_type = mf_data;
1801 misc_type = mf_unknown;
1802 complain (&unknown_ext_complaint,
1803 (char *)(esh->asym.iss));
1805 prim_record_misc_function ((char *)(esh->asym.iss),
1810 /* Pass 3 over files, over local syms: fill in static symbols */
1811 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
1812 struct partial_symtab *save_pst;
1814 cur_fdr = fh = f_idx + (FDR *)(cur_hdr->cbFdOffset);
1816 if (fh->csym == 0) {
1817 fdr_to_pst[f_idx].pst = NULL;
1820 pst = start_psymtab_common (objfile, 0, (char*)fh->rss,
1821 fh->cpd ? fh->adr : 0,
1822 global_psymbols.next,
1823 static_psymbols.next);
1824 pst->read_symtab_private = (char *)
1825 obstack_alloc (psymbol_obstack, sizeof (struct symloc));
1828 /* Make everything point to everything. */
1829 FDR_IDX(pst) = f_idx;
1830 fdr_to_pst[f_idx].pst = pst;
1831 fh->ioptBase = (int)pst;
1833 CUR_HDR(pst) = cur_hdr;
1835 /* The way to turn this into a symtab is to call... */
1836 pst->read_symtab = mipscoff_psymtab_to_symtab;
1838 pst->texthigh = pst->textlow;
1840 pst->globals_offset = global_psymbols.next - global_psymbols.list;
1841 pst->statics_offset = static_psymbols.next - static_psymbols.list;
1843 pst->n_global_syms = 0;
1844 pst->n_static_syms = 0;
1846 /* The second symbol must be @stab.
1847 This symbol is emitted by mips-tfile to signal
1848 that the current object file uses encapsulated stabs
1849 instead of mips ecoff for local symbols.
1850 (It is the second symbol because the first symbol is
1851 the stFile used to signal the start of a file). */
1853 && strcmp(((SYMR *)fh->isymBase)[1].iss, stabs_symbol) == 0) {
1854 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++) {
1857 sh = cur_sdx + (SYMR *) fh->isymBase;
1858 type_code = MIPS_UNMARK_STAB(sh->index);
1859 if (!MIPS_IS_STAB(sh)) {
1860 if (sh->st == stProc || sh->st == stStaticProc) {
1861 long procaddr = sh->value;
1862 sh = (sh->index + (AUXU *)fh->iauxBase)->isym
1863 + (SYMR *) fh->isymBase - 1;
1864 if (sh->st == stEnd) {
1865 long high = procaddr + sh->value;
1866 if (high > pst->texthigh)
1867 pst->texthigh = high;
1872 #define SET_NAMESTRING() namestring = (char*)sh->iss
1873 #define CUR_SYMBOL_TYPE type_code
1874 #define CUR_SYMBOL_VALUE sh->value
1875 #define START_PSYMTAB(ofile,addr,fname,low,symoff,global_syms,static_syms)\
1877 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
1878 #define addr 0 /* FIXME, should be offset of addresses */
1879 #define HANDLE_RBRAC(val) \
1880 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
1881 #include "partial-stab.h"
1886 register struct partial_symbol *psym;
1887 for (cur_sdx = 0; cur_sdx < fh->csym; ) {
1888 register struct partial_symbol *p;
1891 sh = cur_sdx + (SYMR *) fh->isymBase;
1893 if (MIPS_IS_STAB(sh)) {
1898 if (sh->sc == scUndefined || sh->sc == scNil ||
1899 sh->index == 0xfffff) {
1900 /* FIXME, premature? */
1905 name = (char *)(sh->iss);
1910 case stProc: /* Asm labels apparently */
1911 case stStaticProc: /* Function */
1912 ADD_PSYMBOL_TO_LIST(name, strlen(name),
1913 VAR_NAMESPACE, LOC_BLOCK,
1914 static_psymbols, sh->value);
1915 /* Skip over procedure to next one. */
1916 cur_sdx = (sh->index + (AUXU *)fh->iauxBase)->isym;
1917 procaddr = sh->value;
1919 sh = cur_sdx + (SYMR *) fh->isymBase - 1;
1920 if (sh->st != stEnd)
1922 high = procaddr + sh->value;
1923 if (high > pst->texthigh)
1924 pst->texthigh = high;
1926 case stStatic: /* Variable */
1929 case stTypedef: /* Typedef */
1930 class = LOC_TYPEDEF;
1932 case stConstant: /* Constant decl */
1935 case stBlock: /* { }, str, un, enum*/
1936 if (sh->sc == scInfo) {
1937 ADD_PSYMBOL_TO_LIST(name, strlen(name),
1938 STRUCT_NAMESPACE, LOC_TYPEDEF,
1939 static_psymbols, sh->value);
1941 /* Skip over the block */
1942 cur_sdx = sh->index;
1944 case stFile: /* File headers */
1945 case stLabel: /* Labels */
1946 case stEnd: /* Ends of files */
1949 complain (&unknown_sym_complaint, SYMBOL_NAME(p));
1950 complain (&unknown_st_complaint, sh->st);
1954 /* Use this gdb symbol */
1955 ADD_PSYMBOL_TO_LIST(name, strlen(name),
1956 VAR_NAMESPACE, class,
1957 static_psymbols, sh->value);
1959 cur_sdx++; /* Go to next file symbol */
1962 /* Now do enter the external symbols. */
1963 ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset];
1964 cur_sdx = fdr_to_pst[f_idx].n_globals;
1965 PST_PRIVATE(save_pst)->extern_count = cur_sdx;
1966 PST_PRIVATE(save_pst)->extern_tab = ext_ptr;
1967 for (; --cur_sdx >= 0; ext_ptr++) {
1968 enum address_class class;
1969 if ((*ext_ptr)->ifd != f_idx)
1971 sh = &(*ext_ptr)->asym;
1980 complain (&unknown_ext_complaint, sh->iss);
1985 if (global_psymbols.next >=
1986 global_psymbols.list + global_psymbols.size)
1987 extend_psymbol_list (&global_psymbols);
1988 psym = global_psymbols.next++;
1989 SYMBOL_NAME (psym) = (char*)sh->iss;
1990 SYMBOL_NAMESPACE (psym) = VAR_NAMESPACE;
1991 SYMBOL_CLASS (psym) = class;
1992 SYMBOL_VALUE_ADDRESS (psym) = (CORE_ADDR)sh->value;
1996 end_psymtab (save_pst, psymtab_include_list, includes_used,
1997 -1, save_pst->texthigh,
1998 dependency_list, dependencies_used,
1999 global_psymbols.next, static_psymbols.next);
2000 if (entry_point < save_pst->texthigh
2001 && entry_point >= save_pst->textlow) {
2002 startup_file_start = save_pst->textlow;
2003 startup_file_end = save_pst->texthigh;
2007 /* Mark the last code address, and remember it for later */
2008 hdr->cbDnOffset = end_of_text_seg;
2010 do_cleanups (old_chain);
2015 /* Do the initial analisys of the F_IDX-th file descriptor.
2016 Allocates a partial symtab for it, and builds the list
2017 of dependent files by recursion. LEV says at which level
2018 of recursion we are called (to pretty up debug traces) */
2020 static struct partial_symtab *
2021 parse_fdr(f_idx, lev, objfile)
2024 struct objfile *objfile;
2027 register struct partial_symtab *pst;
2030 fh = (FDR *) (cur_hdr->cbFdOffset) + f_idx;
2032 /* Use this to indicate into which symtab this file was parsed */
2034 return (struct partial_symtab *) fh->ioptBase;
2036 /* Debuggability level */
2037 if (compare_glevel(max_glevel, fh->glevel) < 0)
2038 max_glevel = fh->glevel;
2040 /* Make a new partial_symtab */
2041 pst = new_psymtab(fh->rss, objfile);
2046 pst->textlow = fh->adr;
2047 pst->texthigh = fh->cpd; /* To be fixed later */
2050 /* Make everything point to everything. */
2051 FDR_IDX(pst) = f_idx;
2052 fdr_to_pst[f_idx].pst = pst;
2053 fh->ioptBase = (int)pst;
2055 /* Analyze its dependencies */
2060 if (fh->cpd == 0) { /* If there are no functions defined here ... */
2061 /* ...then presumably a .h file: drop reverse depends .h->.c */
2062 for (; s_id0 < fh->crfd; s_id0++) {
2063 RFDT *rh = (RFDT *) (fh->rfdBase) + s_id0;
2065 s_id0++; /* Skip self-dependency */
2070 pst->number_of_dependencies = fh->crfd - s_id0;
2071 pst->dependencies = (struct partial_symtab **)
2072 obstack_alloc (psymbol_obstack,
2073 pst->number_of_dependencies *
2074 sizeof (struct partial_symtab *));
2075 for (s_idx = s_id0; s_idx < fh->crfd; s_idx++) {
2076 RFDT *rh = (RFDT *) (fh->rfdBase) + s_idx;
2078 pst->dependencies[s_idx-s_id0] = parse_fdr(*rh, lev+1, objfile);
2086 mips_next_symbol_text ()
2089 return (char*)((SYMR *)cur_fdr->isymBase)[cur_sdx].iss;
2092 /* Ancillary function to psymtab_to_symtab(). Does all the work
2093 for turning the partial symtab PST into a symtab, recurring
2094 first on all dependent psymtabs. The argument FILENAME is
2095 only passed so we can see in debug stack traces what file
2099 psymtab_to_symtab_1(pst, filename)
2100 struct partial_symtab *pst;
2108 struct linetable *lines;
2114 /* How many symbols will we need */
2115 /* FIXME, this does not count enum values. */
2116 f_max = pst->n_global_syms + pst->n_static_syms;
2117 if (FDR_IDX(pst) == -1) {
2121 fh = (FDR *) (cur_hdr->cbFdOffset) + FDR_IDX(pst);
2122 f_max += fh->csym + fh->cpd;
2123 maxlines = 2 * fh->cline;
2126 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2129 && strcmp(((SYMR *)fh->isymBase)[1].iss, stabs_symbol) == 0;
2133 st = new_symtab (pst->filename, 2 * f_max, maxlines,
2136 st = new_symtab ("unknown", f_max, 0, pst->objfile);
2137 lines = LINETABLE(st);
2138 pending_list = (struct mips_pending **) cur_hdr->cbOptOffset;
2139 if (pending_list == 0) {
2140 pending_list = (struct mips_pending **)
2141 xzalloc(cur_hdr->ifdMax * sizeof(struct mips_pending *));
2142 cur_hdr->cbOptOffset = (int)pending_list;
2146 /* Read in all partial symbtabs on which this one is dependent.
2147 NOTE that we do have circular dependencies, sigh. We solved
2148 that by setting pst->readin before this point. */
2150 for (i = 0; i < pst->number_of_dependencies; i++)
2151 if (!pst->dependencies[i]->readin) {
2152 /* Inform about additional files to be read in. */
2155 fputs_filtered (" ", stdout);
2157 fputs_filtered ("and ", stdout);
2159 printf_filtered ("%s...",
2160 pst->dependencies[i]->filename);
2161 wrap_here (""); /* Flush output */
2164 /* We only pass the filename for debug purposes */
2165 psymtab_to_symtab_1(pst->dependencies[i],
2166 pst->dependencies[i]->filename);
2170 /* Now read the symbols for this symtab */
2173 cur_fd = FDR_IDX(pst);
2176 /* Get a new lexical context */
2179 top_stack->cur_st = cur_stab;
2180 top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab),
2182 BLOCK_START(top_stack->cur_block) = fh ? fh->adr : 0;
2183 BLOCK_END(top_stack->cur_block) = 0;
2184 top_stack->blocktype = stFile;
2185 top_stack->maxsyms = 2*f_max;
2186 top_stack->cur_type = 0;
2187 top_stack->procadr = 0;
2188 top_stack->numargs = 0;
2191 /* Parse locals and procedures */
2196 char *fh_name = (char*)fh->rss;
2198 /* Parse local symbols first */
2204 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++) {
2205 register SYMR *sh = cur_sdx + (SYMR *) fh->isymBase;
2206 char *name = (char*)sh->iss;
2207 CORE_ADDR valu = sh->value;
2208 if (MIPS_IS_STAB(sh)) {
2209 int type_code = MIPS_UNMARK_STAB(sh->index);
2210 process_one_symbol (type_code, 0, valu, name, /*FIXME*/ 0);
2212 else if (sh->st == stLabel && sh->index != indexNil) {
2213 /* Handle encoded stab line number. */
2214 record_line (current_subfile, sh->index, valu);
2217 st = end_symtab (pst->texthigh, 0, 0, pst->objfile);
2220 /* BOUND is the highest core address of this file's procedures */
2221 int bound = cur_fd == cur_hdr->ifdMax - 1 ? cur_hdr->cbDnOffset
2223 for (cur_sdx = 0; cur_sdx < fh->csym; ) {
2224 sh = (SYMR *) (fh->isymBase) + cur_sdx;
2225 cur_sdx += parse_symbol(sh, fh->iauxBase);
2228 /* Procedures next, note we need to look-ahead to
2229 find out where the procedure's code ends */
2231 for (i = 0; i < fh->cpd-1; i++) {
2232 pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + i;
2233 parse_procedure(pr, pr[1].adr); /* next proc up */
2236 pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + i;
2237 parse_procedure(pr, bound); /* next file up */
2239 /* Linenumbers. At the end, check if we can save memory */
2240 parse_lines(fh, lines);
2241 if (lines->nitems < fh->cline)
2242 lines = shrink_linetable(lines);
2248 LINETABLE(st) = lines;
2250 /* .. and our share of externals.
2251 XXX use the global list to speed up things here. how ?
2252 FIXME, Maybe quit once we have found the right number of ext's? */
2253 /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
2254 top_stack->blocktype = stFile;
2255 top_stack->maxsyms =
2256 cur_hdr->isymMax + cur_hdr->ipdMax + cur_hdr->iextMax;
2258 ext_ptr = PST_PRIVATE(pst)->extern_tab;
2259 for (i = PST_PRIVATE(pst)->extern_count; --i >= 0; ext_ptr++)
2260 parse_external(*ext_ptr, 1);
2262 /* If there are undefined, tell the user */
2263 if (n_undef_symbols) {
2264 printf_filtered("File %s contains %d unresolved references:",
2265 st->filename, n_undef_symbols);
2266 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2267 n_undef_vars, n_undef_procs, n_undef_labels);
2268 n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
2274 /* Sort the symbol table now, we are done adding symbols to it.*/
2275 sort_symtab_syms(st);
2279 /* Now link the psymtab and the symtab. */
2283 /* Ancillary parsing procedures. */
2285 /* Lookup the type at relative index RN. Return it in TPP
2286 if found and in any event come up with its name PNAME.
2287 Return value says how many aux symbols we ate */
2290 cross_ref(rn, tpp, type_code, pname)
2293 int type_code; /* Use to alloc new type if none is found. */
2298 /* Escape index means 'the next one' */
2299 if (rn->rfd == 0xfff)
2300 rf = *(unsigned *) (rn + 1);
2306 *pname = "<undefined>";
2309 * Find the relative file descriptor and the symbol in it
2311 FDR *fh = get_rfd(cur_fd, rf);
2316 * If we have processed this symbol then we left a forwarding
2317 * pointer to the corresponding GDB symbol. If not, we`ll put
2318 * it in a list of pending symbols, to be processed later when
2319 * the file f will be. In any event, we collect the name for
2320 * the type here. Which is why we made a first pass at
2323 sh = (SYMR *) (fh->isymBase) + rn->index;
2325 /* Careful, we might be looking at .o files */
2326 *pname = (UNSAFE_DATA_ADDR(sh->iss)) ? "<undefined>" :
2329 /* Have we parsed it ? */
2330 if ((!UNSAFE_DATA_ADDR(sh->value)) && (sh->st == stParsed)) {
2331 t = (struct type *) sh->value;
2334 /* Avoid duplicates */
2335 struct mips_pending *p = is_pending_symbol(fh, sh);
2339 *tpp = make_type(type_code, 0, 0, 0);
2340 add_pending(fh, sh, *tpp);
2345 /* We used one auxent normally, two if we got a "next one" rf. */
2346 return (rn->rfd == 0xfff? 2: 1);
2350 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2351 keeping the symtab sorted */
2353 static struct symbol *
2354 mylookup_symbol (name, block, namespace, class)
2356 register struct block *block;
2357 enum namespace namespace;
2358 enum address_class class;
2360 register int bot, top, inc;
2361 register struct symbol *sym;
2364 top = BLOCK_NSYMS(block);
2367 sym = BLOCK_SYM(block, bot);
2368 if (SYMBOL_NAME(sym)[0] == inc
2369 && SYMBOL_NAMESPACE(sym) == namespace
2370 && SYMBOL_CLASS(sym) == class
2371 && !strcmp(SYMBOL_NAME(sym), name))
2375 if (block = BLOCK_SUPERBLOCK (block))
2376 return mylookup_symbol (name, block, namespace, class);
2381 /* Add a new symbol S to a block B.
2382 Infrequently, we will need to reallocate the block to make it bigger.
2383 We only detect this case when adding to top_stack->cur_block, since
2384 that's the only time we know how big the block is. FIXME. */
2391 int nsyms = BLOCK_NSYMS(b)++;
2392 struct block *origb;
2393 struct parse_stack *stackp;
2395 if (b == top_stack->cur_block &&
2396 nsyms >= top_stack->maxsyms) {
2397 complain (&block_overflow_complaint, s->name);
2398 /* In this case shrink_block is actually grow_block, since
2399 BLOCK_NSYMS(b) is larger than its current size. */
2401 b = shrink_block (top_stack->cur_block, top_stack->cur_st);
2403 /* Now run through the stack replacing pointers to the
2404 original block. shrink_block has already done this
2405 for the blockvector and BLOCK_FUNCTION. */
2406 for (stackp = top_stack; stackp; stackp = stackp->next) {
2407 if (stackp->cur_block == origb) {
2408 stackp->cur_block = b;
2409 stackp->maxsyms = BLOCK_NSYMS (b);
2413 BLOCK_SYM(b,nsyms) = s;
2416 /* Add a new block B to a symtab S */
2423 struct blockvector *bv = BLOCKVECTOR(s);
2425 bv = (struct blockvector *)xrealloc(bv, sizeof(struct blockvector) +
2426 BLOCKVECTOR_NBLOCKS(bv) * sizeof(bv->block));
2427 if (bv != BLOCKVECTOR(s))
2428 BLOCKVECTOR(s) = bv;
2430 BLOCKVECTOR_BLOCK(bv, BLOCKVECTOR_NBLOCKS(bv)++) = b;
2433 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2434 MIPS' linenumber encoding might need more than one byte
2435 to describe it, LAST is used to detect these continuation lines */
2438 add_line(lt, lineno, adr, last)
2439 struct linetable *lt;
2445 last = -2; /* make sure we record first line */
2447 if (last == lineno) /* skip continuation lines */
2450 lt->item[lt->nitems].line = lineno;
2451 lt->item[lt->nitems++].pc = adr << 2;
2457 /* Comparison functions, used when sorting things */
2459 /* Symtabs must be ordered viz the code segments they cover */
2462 compare_symtabs( s1, s2)
2463 struct symtab **s1, **s2;
2465 /* "most specific" first */
2467 register struct block *b1, *b2;
2468 b1 = BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1),GLOBAL_BLOCK);
2469 b2 = BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2),GLOBAL_BLOCK);
2470 if (BLOCK_END(b1) == BLOCK_END(b2))
2471 return BLOCK_START(b1) - BLOCK_START(b2);
2472 return BLOCK_END(b1) - BLOCK_END(b2);
2476 /* Partial Symtabs, same */
2479 compare_psymtabs( s1, s2)
2480 struct partial_symtab **s1, **s2;
2482 /* Perf twist: put the ones with no code at the end */
2484 register int a = (*s1)->textlow;
2485 register int b = (*s2)->textlow;
2494 /* Blocks with a smaller low bound should come first */
2496 static int compare_blocks(b1,b2)
2497 struct block **b1, **b2;
2499 register int addr_diff;
2501 addr_diff = (BLOCK_START((*b1))) - (BLOCK_START((*b2)));
2503 return (BLOCK_END((*b1))) - (BLOCK_END((*b2)));
2508 /* Sorting and reordering procedures */
2510 /* Sort the blocks of a symtab S.
2511 Reorder the blocks in the blockvector by code-address,
2512 as required by some MI search routines */
2518 struct blockvector *bv = BLOCKVECTOR(s);
2520 if (BLOCKVECTOR_NBLOCKS(bv) <= 2) {
2522 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) == 0)
2523 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = 0;
2524 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) == 0)
2525 BLOCK_START(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) = 0;
2529 * This is very unfortunate: normally all functions are compiled in
2530 * the order they are found, but if the file is compiled -O3 things
2531 * are very different. It would be nice to find a reliable test
2532 * to detect -O3 images in advance.
2534 if (BLOCKVECTOR_NBLOCKS(bv) > 3)
2535 qsort(&BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK),
2536 BLOCKVECTOR_NBLOCKS(bv) - FIRST_LOCAL_BLOCK,
2537 sizeof(struct block *),
2541 register CORE_ADDR high = 0;
2542 register int i, j = BLOCKVECTOR_NBLOCKS(bv);
2544 for (i = FIRST_LOCAL_BLOCK; i < j; i++)
2545 if (high < BLOCK_END(BLOCKVECTOR_BLOCK(bv,i)))
2546 high = BLOCK_END(BLOCKVECTOR_BLOCK(bv,i));
2547 BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = high;
2550 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) =
2551 BLOCK_START(BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK));
2553 BLOCK_START(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) =
2554 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK));
2555 BLOCK_END (BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) =
2556 BLOCK_END (BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK));
2560 /* Constructor/restructor/destructor procedures */
2562 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2563 MAXSYMS and linenumbers MAXLINES we'll put in it */
2567 new_symtab(name, maxsyms, maxlines, objfile)
2570 struct symtab *s = allocate_symtab (name, objfile);
2572 LINETABLE(s) = new_linetable(maxlines);
2574 /* All symtabs must have at least two blocks */
2575 BLOCKVECTOR(s) = new_bvect(2);
2576 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK) = new_block(maxsyms);
2577 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), STATIC_BLOCK) = new_block(maxsyms);
2578 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s),STATIC_BLOCK)) =
2579 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK);
2581 s->free_code = free_linetable;
2583 /* Link the new symtab into the list of such. */
2584 s->next = symtab_list;
2590 /* Allocate a new partial_symtab NAME */
2592 static struct partial_symtab *
2593 new_psymtab(name, objfile)
2595 struct objfile *objfile;
2597 struct partial_symtab *pst;
2599 pst = (struct partial_symtab *)
2600 obstack_alloc (psymbol_obstack, sizeof (*pst));
2601 memset (pst, 0, sizeof (*pst));
2603 if (name == (char*)-1) /* FIXME -- why not null here? */
2604 pst->filename = "<no name>";
2606 pst->filename = name;
2608 /* Chain it to its object file */
2609 pst->objfile = objfile;
2610 pst->objfile_chain = objfile->psymtabs;
2611 objfile->psymtabs = pst;
2613 pst->next = partial_symtab_list;
2614 partial_symtab_list = pst;
2616 /* Keep a backpointer to the file's symbols */
2617 pst->read_symtab_private = (char *) obstack_alloc (psymbol_obstack,
2618 sizeof (struct symloc));
2619 CUR_HDR(pst) = cur_hdr;
2621 /* The way to turn this into a symtab is to call... */
2622 pst->read_symtab = mipscoff_psymtab_to_symtab;
2628 /* Allocate a linetable array of the given SIZE */
2630 static struct linetable *
2633 struct linetable *l;
2635 size = size * sizeof(l->item) + sizeof(struct linetable);
2636 l = (struct linetable *)xmalloc(size);
2641 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2642 I am not so sure about the 3.4 ones */
2644 static struct linetable *
2645 shrink_linetable(lt)
2646 struct linetable * lt;
2648 struct linetable *l = new_linetable(lt->nitems);
2650 memcpy(l, lt, lt->nitems * sizeof(l->item) + sizeof(struct linetable));
2655 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2658 struct blockvector *
2661 struct blockvector *bv;
2664 size = sizeof(struct blockvector) + nblocks * sizeof(struct block*);
2665 bv = (struct blockvector *) xzalloc(size);
2667 BLOCKVECTOR_NBLOCKS(bv) = nblocks;
2672 /* Allocate and zero a new block of MAXSYMS symbols */
2678 int size = sizeof(struct block) + (maxsyms-1) * sizeof(struct symbol *);
2679 struct block *b = (struct block *)xzalloc(size);
2684 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2685 Shrink_block can also be used by add_symbol to grow a block. */
2687 static struct block *
2693 struct blockvector *bv = BLOCKVECTOR(s);
2696 /* Just reallocate it and fix references to the old one */
2698 new = (struct block *) xrealloc ((char *)b, sizeof(struct block) +
2699 (BLOCK_NSYMS(b)-1) * sizeof(struct symbol *));
2701 /* Should chase pointers to old one. Fortunately, that`s just
2702 the block`s function and inferior blocks */
2703 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b)
2704 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2705 for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++)
2706 if (BLOCKVECTOR_BLOCK(bv,i) == b)
2707 BLOCKVECTOR_BLOCK(bv,i) = new;
2708 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) == b)
2709 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) = new;
2713 /* Create a new symbol with printname NAME */
2720 struct symbol *s = (struct symbol *)
2721 obstack_alloc (symbol_obstack, sizeof (struct symbol));
2723 memset (s, 0, sizeof (*s));
2724 SYMBOL_NAME(s) = name;
2728 /* Create a new type with printname NAME */
2735 struct type *t = (struct type *)
2736 obstack_alloc (symbol_obstack, sizeof (struct type));
2738 memset (t, 0, sizeof (*t));
2739 TYPE_VPTR_FIELDNO (t) = -1;
2740 TYPE_NAME(t) = name;
2741 TYPE_CPLUS_SPECIFIC(t) = &cplus_struct_default;
2745 /* Create and initialize a new type with printname NAME.
2746 CODE and LENGTH are the initial info we put in,
2747 UNS says whether the type is unsigned or not. */
2751 make_type(code, length, uns, name)
2752 enum type_code code;
2756 register struct type *type;
2758 /* FIXME, I don't think this ever gets freed. */
2759 type = (struct type *) xzalloc(sizeof(struct type));
2760 TYPE_CODE(type) = code;
2761 TYPE_LENGTH(type) = length;
2762 TYPE_FLAGS(type) = uns ? TYPE_FLAG_UNSIGNED : 0;
2763 TYPE_NAME(type) = name;
2764 TYPE_VPTR_FIELDNO (type) = -1;
2766 if (code != TYPE_CODE_METHOD && code != TYPE_CODE_FUNC)
2767 TYPE_CPLUS_SPECIFIC(type) = &cplus_struct_default;
2771 /* Things used for calling functions in the inferior.
2772 These functions are exported to our companion
2773 mips-tdep.c file and are here because they play
2774 with the symbol-table explicitly. */
2776 /* Sigtramp: make sure we have all the necessary information
2777 about the signal trampoline code. Since the official code
2778 from MIPS does not do so, we make up that information ourselves.
2779 If they fix the library (unlikely) this code will neutralize itself. */
2786 struct block *b, *b0;
2788 sigtramp_address = -1;
2790 /* We know it is sold as sigvec */
2791 s = lookup_symbol("sigvec", 0, VAR_NAMESPACE, 0, NULL);
2793 /* Most programs do not play with signals */
2797 b0 = SYMBOL_BLOCK_VALUE(s);
2799 /* A label of sigvec, to be more precise */
2800 s = lookup_symbol("sigtramp", b0, VAR_NAMESPACE, 0, NULL);
2802 /* But maybe this program uses its own version of sigvec */
2806 sigtramp_address = SYMBOL_VALUE(s);
2807 sigtramp_end = sigtramp_address + 0x88; /* black magic */
2809 /* Did we or MIPSco fix the library ? */
2810 if (SYMBOL_CLASS(s) == LOC_BLOCK)
2813 /* But what symtab does it live in ? */
2814 st = find_pc_symtab(SYMBOL_VALUE(s));
2817 * Ok, there goes the fix: turn it into a procedure, with all the
2818 * needed info. Note we make it a nested procedure of sigvec,
2819 * which is the way the (assembly) code is actually written.
2821 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
2822 SYMBOL_CLASS(s) = LOC_BLOCK;
2823 SYMBOL_TYPE(s) = make_type(TYPE_CODE_FUNC, 4, 0, 0);
2824 TYPE_TARGET_TYPE(SYMBOL_TYPE(s)) = builtin_type_void;
2826 /* Need a block to allocate .gdbinfo. in */
2828 SYMBOL_BLOCK_VALUE(s) = b;
2829 BLOCK_START(b) = sigtramp_address;
2830 BLOCK_END(b) = sigtramp_end;
2831 BLOCK_FUNCTION(b) = s;
2832 BLOCK_SUPERBLOCK(b) = BLOCK_SUPERBLOCK(b0);
2836 /* Make a .gdbinfo. for it */
2838 struct mips_extra_func_info *e =
2839 (struct mips_extra_func_info *)
2840 xzalloc(sizeof(struct mips_extra_func_info));
2842 e->numargs = 0; /* the kernel thinks otherwise */
2843 /* align_longword(sigcontext + SIGFRAME) */
2844 e->framesize = 0x150;
2845 e->framereg = SP_REGNUM;
2848 e->regoffset = -(41 * sizeof(int));
2850 e->fregoffset = -(37 * sizeof(int));
2853 s = new_symbol(".gdbinfo.");
2854 SYMBOL_VALUE(s) = (int) e;
2855 SYMBOL_NAMESPACE(s) = LABEL_NAMESPACE;
2856 SYMBOL_CLASS(s) = LOC_CONST;
2857 SYMBOL_TYPE(s) = builtin_type_void;
2860 BLOCK_SYM(b,BLOCK_NSYMS(b)++) = s;
2863 /* Initialization */
2865 static struct sym_fns ecoff_sym_fns = {"ecoff", 5,
2866 mipscoff_new_init, mipscoff_symfile_init,
2867 mipscoff_symfile_read};
2869 _initialize_mipsread ()
2871 add_symtab_fns (&ecoff_sym_fns);
2873 /* Missing basic types */
2874 builtin_type_string = make_type(TYPE_CODE_PASCAL_ARRAY,
2876 builtin_type_complex = make_type(TYPE_CODE_FLT,
2877 2 * sizeof(float), 0, "complex");
2878 builtin_type_double_complex = make_type(TYPE_CODE_FLT,
2879 2 * sizeof(double), 0, "double_complex");
2880 builtin_type_fixed_dec = make_type(TYPE_CODE_INT, sizeof(int),
2881 0, "fixed_decimal");
2882 builtin_type_float_dec = make_type(TYPE_CODE_FLT, sizeof(double),
2883 0, "floating_decimal");