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. */
42 #include <sys/param.h>
46 #include <mips/syms.h>
50 #endif /* not CMUCS */
52 #include "coff-mips.h"
55 struct external_filehdr f;
56 struct external_aouthdr a;
59 /* Each partial symbol table entry contains a pointer to private data for the
60 read_symtab() function to use when expanding a partial symbol table entry
61 to a full symbol table entry.
63 For mipsread this structure contains the index of the FDR that this psymtab
64 represents and a pointer to the symbol table header HDRR from the symbol
65 file that the psymtab was created from. */
67 #define FDR_IDX(p) (((struct symloc *)((p)->read_symtab_private))->fdr_idx)
68 #define CUR_HDR(p) (((struct symloc *)((p)->read_symtab_private))->cur_hdr)
75 /* Things we import explicitly from other modules */
77 extern int info_verbose;
78 extern struct block *block_for_pc();
79 extern void sort_symtab_syms();
81 /* Various complaints about symbol reading that don't abort the process */
83 struct complaint unknown_ext_complaint =
84 {"unknown external symbol %s", 0, 0};
86 struct complaint unknown_sym_complaint =
87 {"unknown local symbol %s", 0, 0};
89 struct complaint unknown_st_complaint =
90 {"with type %d", 0, 0};
92 struct complaint block_overflow_complaint =
93 {"block containing %s overfilled", 0, 0};
95 struct complaint basic_type_complaint =
96 {"cannot map MIPS basic type 0x%x", 0, 0};
98 struct complaint unknown_type_qual_complaint =
99 {"unknown type qualifier 0x%x", 0, 0};
101 struct complaint array_bitsize_complaint =
102 {"size of array target type not known, assuming %d bits", 0, 0};
104 struct complaint array_parse_complaint =
105 {"array type with strange relative symbol", 0, 0};
107 /* Macros and extra defs */
109 /* Already-parsed symbols are marked specially */
111 #define stParsed stType
113 /* Puns: hard to find whether -g was used and how */
115 #define MIN_GLEVEL GLEVEL_0
116 #define compare_glevel(a,b) \
117 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
118 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
120 /* When looking at .o files, avoid tripping over bad addresses */
122 #define SAFE_TEXT_ADDR 0x400000
123 #define SAFE_DATA_ADDR 0x10000000
125 #define UNSAFE_DATA_ADDR(p) ((unsigned)p < SAFE_DATA_ADDR || (unsigned)p > 2*SAFE_DATA_ADDR)
127 /* Things that really are local to this module */
129 /* GDB symtable for the current compilation unit */
131 static struct symtab *cur_stab;
133 /* MIPS symtab header for the current file */
135 static HDRR *cur_hdr;
137 /* Pointer to current file decriptor record, and its index */
142 /* Index of current symbol */
146 /* Note how much "debuggable" this image is. We would like
147 to see at least one FDR with full symbols */
152 /* When examining .o files, report on undefined symbols */
154 static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;
156 /* Extra builtin types */
158 struct type *builtin_type_complex;
159 struct type *builtin_type_double_complex;
160 struct type *builtin_type_fixed_dec;
161 struct type *builtin_type_float_dec;
162 struct type *builtin_type_string;
164 /* Forward declarations */
166 static struct symbol *new_symbol();
167 static struct type *new_type();
168 static struct field *new_field();
169 static struct block *new_block();
170 static struct symtab *new_symtab();
171 static struct linetable *new_linetable();
172 static struct blockvector *new_bvect();
174 static struct type *parse_type();
175 static struct type *make_type();
176 static struct symbol *mylookup_symbol();
177 static struct block *shrink_block();
179 static int compare_symtabs();
180 static int compare_psymtabs();
181 static int compare_blocks();
183 static struct partial_symtab *new_psymtab();
184 static struct partial_symtab *parse_fdr();
185 static int compare_psymbols();
187 static void psymtab_to_symtab_1();
188 static void add_block();
189 static void add_symbol();
190 static int add_line();
191 static void reorder_symtabs();
192 static void reorder_psymtabs();
193 static void shrink_linetable();
195 /* Things we export to other modules */
197 /* Address bounds for the signal trampoline in inferior, if any */
198 /* FIXME: Nothing really seems to use this. Why is it here? */
200 CORE_ADDR sigtramp_address, sigtramp_end;
202 /* The entry point (starting address) of the file, if it is an executable. */
204 extern CORE_ADDR startup_file_start; /* From blockframe.c */
205 extern CORE_ADDR startup_file_end; /* From blockframe.c */
210 /* If we have a file symbol header lying around, blow it away. */
212 free ((char *)cur_hdr);
217 mipscoff_symfile_init (sf)
220 sf->sym_private = NULL;
224 mipscoff_symfile_read(sf, addr, mainline)
229 struct coff_symfile_info *info = (struct coff_symfile_info *)sf->sym_private;
230 bfd *abfd = sf->objfile->obfd;
231 char *name = bfd_get_filename (abfd);
235 int stringtab_offset;
237 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
238 desc = fileno ((FILE *)(abfd->iostream)); /* Raw file descriptor */
241 /* Position to read the symbol table. */
242 val = lseek (desc, (long)symtab_offset, 0);
244 perror_with_name (name);
246 init_misc_bunches ();
247 make_cleanup (discard_misc_bunches, 0);
249 /* Now that the executable file is positioned at symbol table,
250 process it and define symbols accordingly. */
252 read_mips_symtab(sf->objfile, desc);
254 /* Go over the misc symbol bunches and install them in vector. */
256 condense_misc_bunches (!mainline);
259 /* Exported procedure: Allocate zeroed memory */
264 char *p = xmalloc(size);
270 /* Exported procedure: Builds a symtab from the PST partial one.
271 Restores the environment in effect when PST was created, delegates
272 most of the work to an ancillary procedure, and sorts
273 and reorders the symtab list at the end */
276 mipscoff_psymtab_to_symtab(pst)
277 struct partial_symtab *pst;
286 printf_filtered("Reading in symbols for %s...", pst->filename);
289 /* Restore the header and list of pending typedefs */
290 cur_hdr = CUR_HDR(pst);
292 psymtab_to_symtab_1(pst, pst->filename);
297 printf_filtered("done.\n");
300 /* Exported procedure: Is PC in the signal trampoline code */
303 in_sigtramp(pc, name)
307 if (sigtramp_address == 0)
309 return (pc >= sigtramp_address && pc < sigtramp_end);
312 /* File-level interface functions */
314 /* Read the symtab information from file FSYM into memory. Also,
315 return address just past end of our text segment in *END_OF_TEXT_SEGP. */
318 read_the_mips_symtab(abfd, fsym, end_of_text_segp)
321 CORE_ADDR *end_of_text_segp;
323 int stsize, st_hdrsize;
326 /* Header for executable/object file we read symbols from */
327 struct coff_exec filhdr;
329 /* We get here with DESC pointing to the symtab header. But we need
330 * other info from the initial headers */
332 myread(fsym, &filhdr, sizeof filhdr);
334 if (end_of_text_segp)
336 bfd_h_get_32 (abfd, filhdr.a.text_start) +
337 bfd_h_get_32 (abfd, filhdr.a.tsize);
339 /* Find and read the symbol table header */
340 st_hdrsize = bfd_h_get_32 (abfd, filhdr.f.f_nsyms);
341 st_filptr = bfd_h_get_32 (abfd, filhdr.f.f_symptr);
345 lseek(fsym, st_filptr, L_SET);
346 if (st_hdrsize > sizeof (st_hdr)) /* Profanity check */
348 if (read(fsym, &st_hdr, st_hdrsize) != st_hdrsize)
351 /* Find out how large the symbol table is */
352 stsize = (st_hdr.cbExtOffset - (st_filptr + st_hdrsize))
353 + st_hdr.iextMax * cbEXTR;
355 /* Allocate space for the symbol table. Read it in. */
356 cur_hdr = (HDRR *) xmalloc(stsize + st_hdrsize);
358 bcopy(&st_hdr, cur_hdr, st_hdrsize);
359 if (read(fsym, (char *) cur_hdr + st_hdrsize, stsize) != stsize)
362 /* Fixup file_pointers in it */
363 fixup_symtab(cur_hdr, (char *) cur_hdr + st_hdrsize,
364 st_filptr + st_hdrsize);
368 error("Short read on %s", bfd_get_filename (abfd));
372 /* Turn all file-relative pointers in the symtab described by HDR
373 into memory pointers, given that the symtab itself is located
374 at DATA in memory and F_PTR in the file. */
377 fixup_symtab( hdr, data, f_ptr)
389 * These fields are useless (and empty) by now:
390 * hdr->cbDnOffset, hdr->cbOptOffset
391 * We use them for other internal purposes.
394 hdr->cbOptOffset = 0;
397 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
413 * Fix all string pointers inside the symtab, and
414 * the FDR records. Also fix other miscellany.
416 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
417 register unsigned code_offset;
419 /* Header itself, and strings */
420 fh = (FDR *) (hdr->cbFdOffset) + f_idx;
421 fh->issBase += hdr->cbSsOffset;
423 fh->rss = (long)fh->rss + fh->issBase;
424 for (s_idx = 0; s_idx < fh->csym; s_idx++) {
425 sh = (SYMR*)(hdr->cbSymOffset) + fh->isymBase + s_idx;
426 sh->iss = (long) sh->iss + fh->issBase;
433 fh->isymBase = (int)((SYMR*)(hdr->cbSymOffset)+fh->isymBase);
435 /* cannot fix fh->ipdFirst because it is a short */
436 #define IPDFIRST(h,fh) \
437 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
439 /* Optional symbols (actually used for partial_symtabs) */
445 fh->iauxBase = hdr->cbAuxOffset + fh->iauxBase * sizeof(AUXU);
446 /* Relative file descriptor table */
447 fh->rfdBase = hdr->cbRfdOffset + fh->rfdBase * sizeof(RFDT);
451 fh->cbLineOffset += hdr->cbLineOffset;
453 /* Procedure symbols. (XXX This should be done later) */
454 code_offset = fh->adr;
455 for (s_idx = 0; s_idx < fh->cpd; s_idx++) {
456 unsigned name, only_ext;
458 pr = (PDR*)(IPDFIRST(hdr,fh)) + s_idx;
460 /* Simple rule to find files linked "-x" */
461 only_ext = fh->rss == -1;
463 if (pr->isym == -1) {
464 /* static function */
468 name = hdr->cbExtOffset + pr->isym * sizeof(EXTR);
469 sh = &((EXTR*)name)->asym;
473 sh = (SYMR*)fh->isymBase + pr->isym;
474 /* Included code ? */
475 if (s_idx == 0 && pr->adr != 0)
476 code_offset -= pr->adr;
479 /* Turn index into a pointer */
482 /* Fix line numbers */
483 pr->cbLineOffset += fh->cbLineOffset;
485 /* Relocate address */
487 pr->adr += code_offset;
491 /* External symbols: fix string */
492 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
493 esh = (EXTR*)(hdr->cbExtOffset) + s_idx;
494 esh->asym.iss = esh->asym.iss + hdr->cbSsExtOffset;
499 /* Find a file descriptor given its index RF relative to a file CF */
507 f = (FDR *) (cur_hdr->cbFdOffset) + cf;
508 /* Object files do not have the RFD table, all refs are absolute */
510 return (FDR *) (cur_hdr->cbFdOffset) + rf;
511 cf = *((pRFDT) f->rfdBase + rf);
512 return (FDR *) (cur_hdr->cbFdOffset) + cf;
515 /* Return a safer print NAME for a file descriptor */
521 if (name == (char *) -1)
522 return "<stripped file>";
523 if (UNSAFE_DATA_ADDR(name))
529 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
530 whether we are adding to the general symtab or not.
531 FIXME: INCREMENTAL is currently always zero, though it should not be. */
534 read_mips_symtab (objfile, desc)
535 struct objfile *objfile;
538 CORE_ADDR end_of_text_seg;
540 read_the_mips_symtab(objfile->obfd, desc, &end_of_text_seg);
542 parse_partial_symbols(end_of_text_seg, objfile);
545 * Check to make sure file was compiled with -g.
546 * If not, warn the user of this limitation.
548 if (compare_glevel(max_glevel, GLEVEL_2) < 0) {
549 if (max_gdbinfo == 0)
551 "\n%s not compiled with -g, debugging support is limited.\n",
554 "You should compile with -g2 or -g3 for best debugging support.\n");
559 /* Local utilities */
561 /* Map of FDR indexes to partial symtabs */
563 static struct pst_map {
564 struct partial_symtab *pst; /* the psymtab proper */
565 int n_globals; /* globals it exports */
566 int n_statics; /* statics (locals) it contains */
570 /* Utility stack, used to nest procedures and blocks properly.
571 It is a doubly linked list, to avoid too many alloc/free.
572 Since we might need it quite a few times it is NOT deallocated
575 static struct parse_stack {
576 struct parse_stack *next, *prev;
577 struct symtab *cur_st; /* Current symtab */
578 struct block *cur_block; /* Block in it */
579 int blocktype; /* What are we parsing */
580 int maxsyms; /* Max symbols in this block */
581 struct type *cur_type; /* Type we parse fields for */
582 int procadr; /* Start addres of this procedure */
583 int numargs; /* Its argument count */
584 } *top_stack; /* Top stack ptr */
587 /* Enter a new lexical context */
589 static push_parse_stack()
591 struct parse_stack *new;
593 /* Reuse frames if possible */
594 if (top_stack && top_stack->prev)
595 new = top_stack->prev;
597 new = (struct parse_stack *) xzalloc(sizeof(struct parse_stack));
598 /* Initialize new frame with previous content */
600 register struct parse_stack *prev = new->prev;
603 top_stack->prev = new;
605 new->next = top_stack;
610 /* Exit a lexical context */
612 static pop_parse_stack()
617 top_stack = top_stack->next;
621 /* Cross-references might be to things we haven't looked at
622 yet, e.g. type references. To avoid too many type
623 duplications we keep a quick fixup table, an array
624 of lists of references indexed by file descriptor */
626 static struct pending {
627 struct pending *next; /* link */
628 SYMR *s; /* the symbol */
629 struct type *t; /* its partial type descriptor */
633 /* Check whether we already saw symbol SH in file FH as undefined */
636 struct pending *is_pending_symbol(fh, sh)
640 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
641 register struct pending *p;
643 /* Linear search is ok, list is typically no more than 10 deep */
644 for (p = pending_list[f_idx]; p; p = p->next)
650 /* Check whether we already saw type T in file FH as undefined */
653 struct pending *is_pending_type(fh, t)
657 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
658 register struct pending *p;
660 for (p = pending_list[f_idx]; p; p = p->next)
666 /* Add a new undef symbol SH of type T */
669 add_pending(fh, sh, t)
674 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
675 struct pending *p = is_pending_symbol(fh, sh);
677 /* Make sure we do not make duplicates */
679 p = (struct pending *) xmalloc(sizeof(*p));
682 p->next = pending_list[f_idx];
683 pending_list[f_idx] = p;
685 sh->reserved = 1; /* for quick check */
688 /* Throw away undef entries when done with file index F_IDX */
693 register struct pending *p, *q;
695 for (p = pending_list[f_idx]; p; p = q) {
699 pending_list[f_idx] = 0;
702 /* The number of args to a procedure is not explicit in the symtab,
703 this is the list of all those we know of.
704 This makes parsing more reasonable and avoids extra passes */
706 static struct numarg {
707 struct numarg *next; /* link */
708 unsigned adr; /* procedure's start address */
709 unsigned num; /* arg count */
712 /* Record that the procedure at ADR takes NUM arguments. */
717 struct numarg *n = (struct numarg *) xmalloc(sizeof(struct numarg));
721 n->next = numargs_list;
725 /* See if we know how many arguments the procedure at ADR takes */
730 struct numarg *n = numargs_list;
732 while (n && n->adr != adr)
734 return (n) ? n->num : -1;
737 /* Release storage when done with this file */
742 struct numarg *n = numargs_list, *m;
753 /* Parsing Routines proper. */
755 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
756 For blocks, procedures and types we open a new lexical context.
757 This is basically just a big switch on the symbol's type */
768 /* When a symbol is cross-referenced from other files/symbols
769 we mark it explicitly */
770 int pend = (sh->reserved == 1);
771 enum address_class class;
778 case stGlobal: /* external symbol, goes into global block */
780 b = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st),
782 s = new_symbol(sh->iss);
783 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
786 case stStatic: /* static data, goes into current block. */
788 b = top_stack->cur_block;
789 s = new_symbol(sh->iss);
790 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
793 case stLocal: /* local variable, goes into current block */
794 if (sh->sc == scRegister) {
795 class = LOC_REGISTER;
800 b = top_stack->cur_block;
801 s = new_symbol(sh->iss);
802 SYMBOL_VALUE(s) = sh->value;
804 data: /* Common code for symbols describing data */
805 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
806 SYMBOL_CLASS(s) = class;
809 /* Type could be missing in a number of cases */
810 if (sh->sc == scUndefined || sh->sc == scNil ||
811 sh->index == 0xfffff)
812 SYMBOL_TYPE(s) = builtin_type_int; /* undefined? */
814 SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0);
815 /* Value of a data symbol is its memory address */
818 case stParam: /* arg to procedure, goes into current block */
820 top_stack->numargs++;
821 s = new_symbol(sh->iss);
822 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
823 if (sh->sc == scRegister) {
824 SYMBOL_CLASS(s) = LOC_REGPARM;
828 SYMBOL_CLASS(s) = LOC_ARG;
829 SYMBOL_VALUE(s) = sh->value;
830 SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0);
831 add_symbol(s, top_stack->cur_block);
833 /* FIXME: This has not been tested. See dbxread.c */
834 /* Add the type of this parameter to the function/procedure
835 type of this block. */
836 add_param_to_type(&top_stack->cur_block->function->type,s);
840 case stLabel: /* label, goes into current block */
841 s = new_symbol(sh->iss);
842 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE; /* so that it can be used */
843 SYMBOL_CLASS(s) = LOC_LABEL; /* but not misused */
844 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
845 SYMBOL_TYPE(s) = builtin_type_int;
846 add_symbol(s, top_stack->cur_block);
849 case stProc: /* Procedure, usually goes into global block */
850 case stStaticProc: /* Static procedure, goes into current block */
851 s = new_symbol(sh->iss);
852 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
853 SYMBOL_CLASS(s) = LOC_BLOCK;
854 /* Type of the return value */
855 if (sh->sc == scUndefined || sh->sc == scNil)
856 t = builtin_type_int;
858 t = parse_type(ax + sh->index, sh, 0);
859 b = top_stack->cur_block;
860 if (sh->st == stProc) {
861 struct blockvector *bv = BLOCKVECTOR(top_stack->cur_st);
862 /* The next test should normally be true,
863 but provides a hook for nested functions
864 (which we don't want to make global). */
865 if (b == BLOCKVECTOR_BLOCK(bv, STATIC_BLOCK))
866 b = BLOCKVECTOR_BLOCK(bv, GLOBAL_BLOCK);
870 /* Make a type for the procedure itself */
872 /* FIXME: This has not been tested yet! See dbxread.c */
873 /* Generate a template for the type of this function. The
874 types of the arguments will be added as we read the symbol
876 bcopy(SYMBOL_TYPE(s),lookup_function_type(t),sizeof(struct type));
878 SYMBOL_TYPE(s) = lookup_function_type (t);
881 /* Create and enter a new lexical context */
882 b = new_block(top_stack->maxsyms);
883 SYMBOL_BLOCK_VALUE(s) = b;
884 BLOCK_FUNCTION(b) = s;
885 BLOCK_START(b) = BLOCK_END(b) = sh->value;
886 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
887 add_block(b, top_stack->cur_st);
889 /* Not if we only have partial info */
890 if (sh->sc == scUndefined || sh->sc == scNil)
894 top_stack->cur_block = b;
895 top_stack->blocktype = sh->st;
896 top_stack->cur_type = SYMBOL_TYPE(s);
897 top_stack->procadr = sh->value;
898 top_stack->numargs = 0;
900 sh->value = (long) SYMBOL_TYPE(s);
903 case stBlock: /* Either a lexical block, or some type */
905 top_stack->blocktype = stBlock;
906 if (sh->sc == scInfo) { /* structure/union/enum def */
907 s = new_symbol(sh->iss);
908 SYMBOL_NAMESPACE(s) = STRUCT_NAMESPACE;
909 SYMBOL_CLASS(s) = LOC_TYPEDEF;
911 add_symbol(s, top_stack->cur_block);
912 /* If this type was expected, use its partial definition */
914 t = is_pending_symbol(cur_fdr, sh)->t;
916 /* Uhmm, can`t decide yet. Smash later */
917 t = new_type(sh->iss);
918 TYPE_CODE(t) = TYPE_CODE_UNDEF;
919 add_pending(cur_fdr, sh, t);
922 /* make this the current type */
923 top_stack->cur_type = t;
924 TYPE_LENGTH(t) = sh->value;
925 /* Mark that symbol has a type, and say which one */
926 sh->value = (long) t;
928 /* beginnning of (code) block. Value of symbol
929 is the displacement from procedure start */
930 b = new_block(top_stack->maxsyms);
931 BLOCK_START(b) = sh->value + top_stack->procadr;
932 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
933 top_stack->cur_block = b;
934 add_block(b, top_stack->cur_st);
938 case stEnd: /* end (of anything) */
939 if (sh->sc == scInfo) {
940 /* Finished with type */
941 top_stack->cur_type = 0;
942 } else if (sh->sc == scText &&
943 (top_stack->blocktype == stProc ||
944 top_stack->blocktype == stStaticProc)) {
945 /* Finished with procedure */
946 struct blockvector *bv = BLOCKVECTOR(top_stack->cur_st);
950 BLOCK_END(top_stack->cur_block) += sh->value; /* size */
951 got_numargs(top_stack->procadr, top_stack->numargs);
952 /* Reallocate symbols, saving memory */
953 b = shrink_block(top_stack->cur_block, top_stack->cur_st);
955 /* f77 emits proc-level with address bounds==[0,0],
956 So look for such child blocks, and patch them. */
957 for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++) {
958 struct block *b_bad = BLOCKVECTOR_BLOCK(bv,i);
959 if (BLOCK_SUPERBLOCK(b_bad) == b
960 && BLOCK_START(b_bad) == top_stack->procadr
961 && BLOCK_END(b_bad) == top_stack->procadr) {
962 BLOCK_START(b_bad) = BLOCK_START(b);
963 BLOCK_END(b_bad) = BLOCK_END(b);
966 if (entry_point < BLOCK_END(b)
967 && entry_point >= BLOCK_START(b)) {
968 startup_file_start = BLOCK_START(b);
969 startup_file_end = BLOCK_END(b);
971 } else if (sh->sc == scText && top_stack->blocktype == stBlock) {
972 /* End of (code) block. The value of the symbol
973 is the displacement from the procedure`s start
974 address of the end of this block. */
975 BLOCK_END(top_stack->cur_block) = sh->value + top_stack->procadr;
976 (void) shrink_block(top_stack->cur_block, top_stack->cur_st);
978 pop_parse_stack(); /* restore previous lexical context */
981 case stMember: /* member of struct/union/enum.. */
982 f = new_field(top_stack->cur_type, sh->iss);
983 f->bitpos = sh->value;
984 f->type = parse_type(ax + sh->index, sh, &f->bitsize);
987 case stTypedef: /* type definition */
988 s = new_symbol(sh->iss);
989 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
990 SYMBOL_CLASS(s) = LOC_TYPEDEF;
991 SYMBOL_BLOCK_VALUE(s) = top_stack->cur_block;
992 add_symbol(s, top_stack->cur_block);
993 SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0);
994 sh->value = (long) SYMBOL_TYPE(s);
997 case stFile: /* file name */
999 top_stack->blocktype = sh->st;
1002 /* I`ve never seen these for C */
1004 break; /* register relocation */
1006 break; /* forwarding address */
1008 break; /* constant */
1010 error("Unknown symbol type %x.", sh->st);
1015 /* Parse the type information provided in the AX entries for
1016 the symbol SH. Return the bitfield size in BS, in case. */
1018 static struct type *parse_type(ax, sh, bs)
1023 /* Null entries in this map are treated specially */
1024 static struct type **map_bt[] =
1026 &builtin_type_void, /* btNil */
1028 &builtin_type_char, /* btChar */
1029 &builtin_type_unsigned_char, /* btUChar */
1030 &builtin_type_short, /* btShort */
1031 &builtin_type_unsigned_short, /* btUShort */
1032 &builtin_type_int, /* btInt */
1033 &builtin_type_unsigned_int, /* btUInt */
1034 &builtin_type_long, /* btLong */
1035 &builtin_type_unsigned_long, /* btULong */
1036 &builtin_type_float, /* btFloat */
1037 &builtin_type_double, /* btDouble */
1044 &builtin_type_complex, /* btComplex */
1045 &builtin_type_double_complex, /* btDComplex */
1047 &builtin_type_fixed_dec, /* btFixedDec */
1048 &builtin_type_float_dec, /* btFloatDec */
1049 &builtin_type_string, /* btString */
1052 &builtin_type_void, /* btVoid */
1056 struct type *tp = 0, *tp1;
1059 /* Procedures start off by one */
1060 if (sh->st == stProc || sh->st == stStaticProc)
1063 /* Undefined ? Should not happen */
1064 if (ax->rndx.rfd == 0xfff) {
1065 return builtin_type_void;
1068 /* Use aux as a type information record, map its basic type */
1070 if (t->bt > (sizeof (map_bt)/sizeof (*map_bt))) {
1071 complain (&basic_type_complaint, t->bt);
1072 return builtin_type_int;
1075 tp = *map_bt[t->bt];
1078 /* Cannot use builtin types -- build our own */
1081 tp = lookup_pointer_type (builtin_type_void);
1085 tp = make_struct_type(TYPE_CODE_STRUCT, 0, 0, 0);
1089 tp = make_struct_type(TYPE_CODE_UNION, 0, 0, 0);
1093 tp = make_type(TYPE_CODE_ENUM, 0, 0, 0);
1097 tp = make_type(TYPE_CODE_RANGE, 0, 0, 0);
1101 tp = make_type(TYPE_CODE_SET, 0, 0, 0);
1105 complain (&basic_type_complaint, t->bt);
1106 return builtin_type_int;
1110 /* Move on to next aux */
1113 /* This is the way it would work if the compiler worked */
1114 register TIR *t1 = t;
1115 while (t1->continued)
1119 /* For bitfields all we need is the width */
1125 /* All these types really point to some (common) MIPS type
1126 definition, and only the type-qualifiers fully identify
1127 them. We`ll make the same effort at sharing */
1128 if (t->bt == btIndirect ||
1129 t->bt == btStruct ||
1132 t->bt == btTypedef ||
1135 char name[256], *pn;
1137 /* Try to cross reference this type */
1139 ax += cross_ref(ax, &tp1, &pn);
1140 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1141 sprintf(name, fmt, pn);
1143 /* reading .o file ? */
1144 if (UNSAFE_DATA_ADDR(tp1))
1146 if (TYPE_CODE(tp1) == TYPE_CODE_UNDEF) {
1148 * Type was incompletely defined, now we know.
1150 TYPE_CODE(tp1) = TYPE_CODE(tp);
1151 TYPE_NAME(tp1) = obsavestring(name, strlen(name));
1152 if (TYPE_CODE(tp1) == TYPE_CODE_ENUM) {
1155 for (i = 0; i < TYPE_NFIELDS(tp1); i++)
1156 make_enum_constant(&TYPE_FIELD(tp1,i), tp1);
1160 /* found as cross ref, rid of our template */
1161 if ((TYPE_FLAGS(tp) & TYPE_FLAG_PERM) == 0)
1164 /* stupid idea of prepending "struct" to type names */
1165 if (t->bt == btStruct && !index(TYPE_NAME(tp), ' ')) {
1166 sprintf(name, fmt, TYPE_NAME(tp));
1167 TYPE_NAME(tp) = obsavestring(name, strlen(name));
1170 TYPE_NAME(tp) = savestring(name, strlen(name));
1173 /* Deal with range types */
1174 if (t->bt == btRange) {
1177 f = new_field(tp, "Low");
1178 f->bitpos = ax->dnLow;
1180 f = new_field(tp, "High");
1181 f->bitpos = ax->dnHigh;
1185 /* Parse all the type qualifiers now. If there are more
1186 than 6 the game will continue in the next aux */
1188 #define PARSE_TQ(tq) \
1189 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, sh);
1191 again: PARSE_TQ(tq0);
1206 /* Make up a complex type from a basic one. Type is passed by
1207 reference in TPP and side-effected as necessary. The type
1208 qualifier TQ says how to handle the aux symbols at AX for
1209 the symbol SX we are currently analyzing.
1210 Returns the number of aux symbols we parsed. */
1213 upgrade_type(tpp, tq, ax, sh)
1221 /* Used in array processing */
1230 t = lookup_pointer_type (*tpp);
1235 t = lookup_function_type (*tpp);
1241 t = make_type(TYPE_CODE_ARRAY, 0, 0, 0);
1242 TYPE_TARGET_TYPE(t) = *tpp;
1244 /* Determine and record the domain type (type of index) */
1245 id = ax->rndx.index;
1251 fh = get_rfd(cur_fd, rf);
1252 f = new_field(t, (char *)0);
1253 bzero(&ss, sizeof ss);
1254 /* XXX */ f->type = parse_type(fh->iauxBase + id * sizeof(AUXU),
1259 * This seems to be a pointer to the end of the Block defining
1260 * the type. Why it is here is magic for me, and I have no
1261 * good use for it anyways.
1263 /* This used to occur because cross_ref returned
1264 the wrong result (ax pointed wrong). FIXME,
1265 delete this code in a while. -- gnu@cygnus jul91 */
1266 complain (&array_parse_complaint, 0);
1268 id = (++ax)->rndx.index;
1269 if ((rf = ax->rndx.rfd) == 0xfff)
1270 rf = (++ax)->isym, off++;
1272 lower = (++ax)->dnLow;
1273 upper = (++ax)->dnHigh;
1274 rf = (++ax)->width; /* bit size of array element */
1276 /* Check whether supplied array element bit size matches
1277 the known size of the element type. If this complaint
1278 ends up not happening, we can remove this code. It's
1279 here because we aren't sure we understand this *&%&$
1281 id = TYPE_LENGTH(TYPE_TARGET_TYPE(t)) << 3; /* bitsize */
1283 /* Most likely an undefined type */
1285 TYPE_LENGTH(TYPE_TARGET_TYPE(t)) = id >> 3;
1288 complain (&array_bitsize_complaint, rf);
1290 TYPE_LENGTH(t) = (upper < 0) ? 0 :
1291 (upper - lower + 1) * (rf >> 3);
1296 /* Volatile -- currently ignored */
1300 complain (&unknown_type_qual_complaint, tq);
1306 /* Parse a procedure descriptor record PR. Note that the procedure
1307 is parsed _after_ the local symbols, now we just make up the
1308 extra information we need into a special symbol that we insert
1309 in the procedure's main block. Note also that images that
1310 have been partially stripped (ld -x) have been deprived
1311 of local symbols, and we have to cope with them here.
1312 The procedure's code ends at BOUND */
1315 parse_procedure(pr, bound)
1318 struct symbol *s, *i;
1319 SYMR *sh = (SYMR*)pr->isym;
1321 struct mips_extra_func_info *e;
1325 /* Reuse the MIPS record */
1326 e = (struct mips_extra_func_info *) pr;
1327 e->numargs = lookup_numargs(pr->adr);
1329 /* Make up our special symbol */
1330 i = new_symbol(".gdbinfo.");
1331 SYMBOL_VALUE(i) = (int)e;
1332 SYMBOL_NAMESPACE(i) = LABEL_NAMESPACE;
1333 SYMBOL_CLASS(i) = LOC_CONST;
1334 SYMBOL_TYPE(i) = builtin_type_void;
1336 /* Make up a name for static procedures. Sigh. */
1337 if (sh == (SYMR*)-1) {
1338 sprintf(name,".static_procedure@%x",pr->adr);
1339 sh_name = savestring(name, strlen(name));
1343 sh_name = (char*)sh->iss;
1344 s = mylookup_symbol(sh_name, top_stack->cur_block,
1345 VAR_NAMESPACE, LOC_BLOCK);
1348 b = SYMBOL_BLOCK_VALUE(s);
1350 s = new_symbol(sh_name);
1351 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
1352 SYMBOL_CLASS(s) = LOC_BLOCK;
1353 /* Donno its type, hope int is ok */
1354 SYMBOL_TYPE(s) = lookup_function_type (builtin_type_int);
1355 add_symbol(s, top_stack->cur_block);
1356 /* Wont have symbols for this one */
1358 SYMBOL_BLOCK_VALUE(s) = b;
1359 BLOCK_FUNCTION(b) = s;
1360 BLOCK_START(b) = pr->adr;
1361 BLOCK_END(b) = bound;
1362 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
1363 add_block(b, top_stack->cur_st);
1369 /* Parse the external symbol ES. Just call parse_symbol() after
1370 making sure we know where the aux are for it. For procedures,
1371 parsing of the PDRs has already provided all the needed
1372 information, we only parse them if SKIP_PROCEDURES is false,
1373 and only if this causes no symbol duplication.
1375 This routine clobbers top_stack->cur_block and ->cur_st. */
1378 parse_external(es, skip_procedures)
1383 if (es->ifd != ifdNil) {
1385 cur_fdr = (FDR*)(cur_hdr->cbFdOffset) + cur_fd;
1386 ax = (AUXU*)cur_fdr->iauxBase;
1388 cur_fdr = (FDR*)(cur_hdr->cbFdOffset);
1391 top_stack->cur_st = cur_stab;
1392 top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st),
1395 /* Reading .o files */
1396 if (es->asym.sc == scUndefined || es->asym.sc == scNil) {
1398 switch (es->asym.st) {
1400 case stProc: what = "procedure"; n_undef_procs++; break;
1401 case stGlobal: what = "variable"; n_undef_vars++; break;
1402 case stLabel: what = "label"; n_undef_labels++; break;
1403 default : what = "symbol"; break;
1407 printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what,
1408 es->asym.iss, fdr_name(cur_fdr->rss));
1412 switch (es->asym.st) {
1414 /* If we have full symbols we do not need more */
1415 if (skip_procedures)
1417 if (mylookup_symbol (es->asym.iss, top_stack->cur_block,
1418 VAR_NAMESPACE, LOC_BLOCK))
1424 * Note that the case of a symbol with indexNil
1425 * must be handled anyways by parse_symbol().
1427 parse_symbol(&es->asym, ax);
1434 /* Parse the line number info for file descriptor FH into
1435 GDB's linetable LT. MIPS' encoding requires a little bit
1436 of magic to get things out. Note also that MIPS' line
1437 numbers can go back and forth, apparently we can live
1438 with that and do not need to reorder our linetables */
1443 struct linetable *lt;
1445 unsigned char *base = (unsigned char*)fh->cbLineOffset;
1447 int delta, count, lineno = 0;
1453 /* Scan by procedure descriptors */
1454 i = 0; j = 0, k = 0;
1455 for (pr = (PDR*)IPDFIRST(cur_hdr,fh); j < fh->cpd; j++, pr++) {
1458 /* No code for this one */
1459 if (pr->iline == ilineNil ||
1460 pr->lnLow == -1 || pr->lnHigh == -1)
1463 * Aurgh! To know where to stop expanding we
1466 for (l = 1; l < (fh->cpd - j); l++)
1467 if (pr[l].iline != -1)
1469 if (l == (fh->cpd - j))
1474 * When procedures are moved around the linenumbers
1475 * are attributed to the next procedure up
1477 if (pr->iline >= halt) continue;
1479 base = (unsigned char*)pr->cbLineOffset;
1480 l = pr->adr >> 2; /* in words */
1481 halt += (pr->adr >> 2) - pr->iline;
1482 for (lineno = pr->lnLow; l < halt;) {
1483 count = *base & 0x0f;
1484 delta = *base++ >> 4;
1488 delta = (base[0] << 8) | base[1];
1489 if (delta >= 0x8000)
1493 lineno += delta;/* first delta is 0 */
1494 k = add_line(lt, lineno, l, k);
1501 /* Parse the symbols of the file described by FH, whose index is F_IDX.
1502 BOUND is the highest core address of this file's procedures */
1505 parse_one_file(fh, f_idx, bound)
1512 /* Parse local symbols first */
1514 for (s_idx = 0; s_idx < fh->csym; s_idx++) {
1515 sh = (SYMR *) (fh->isymBase) + s_idx;
1517 parse_symbol(sh, fh->iauxBase);
1520 /* Procedures next, note we need to look-ahead to
1521 find out where the procedure's code ends */
1523 for (s_idx = 0; s_idx < fh->cpd-1; s_idx++) {
1524 pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + s_idx;
1525 parse_procedure(pr, pr[1].adr); /* next proc up */
1528 pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + s_idx;
1529 parse_procedure(pr, bound); /* next file up */
1532 /* Linenumbers. At the end, check if we can save memory */
1533 parse_lines(fh, LINETABLE(cur_stab));
1534 if (LINETABLE(cur_stab)->nitems < fh->cline)
1535 shrink_linetable(cur_stab);
1538 /* Master parsing procedure for first-pass reading of file symbols
1539 into a partial_symtab.
1541 Parses the symtab described by the global symbolic header CUR_HDR.
1542 END_OF_TEXT_SEG gives the address just after the text segment for
1543 the symtab we are reading. */
1546 parse_partial_symbols(end_of_text_seg, objfile)
1547 int end_of_text_seg;
1548 struct objfile *objfile;
1550 int f_idx, s_idx, h_max, stat_idx;
1552 /* Running pointers */
1557 struct partial_symtab *pst;
1562 * Only parse the Local and External symbols, and the Relative FDR.
1563 * Fixup enough of the loader symtab to be able to use it.
1564 * Allocate space only for the file's portions we need to
1570 max_glevel = MIN_GLEVEL;
1572 /* Allocate the map FDR -> PST.
1573 Minor hack: -O3 images might claim some global data belongs
1574 to FDR -1. We`ll go along with that */
1575 fdr_to_pst = (struct pst_map *)xzalloc((hdr->ifdMax+1) * sizeof *fdr_to_pst);
1578 struct partial_symtab * pst = new_psymtab("", objfile);
1579 fdr_to_pst[-1].pst = pst;
1583 /* Now scan the FDRs, mostly for dependencies */
1584 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
1585 (void) parse_fdr(f_idx, 1, objfile);
1587 /* Take a good guess at how many symbols we might ever need */
1588 h_max = hdr->iextMax;
1590 /* Parse externals: two passes because they can be ordered
1591 in any way, but gdb likes to have them segregated by their
1594 /* Pass 1 over external syms: Presize and partition the list */
1595 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
1596 esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
1597 fdr_to_pst[esh->ifd].n_globals++;
1600 if (global_psymbols.list) {
1601 int origsize = global_psymbols.next - global_psymbols.list;
1603 global_psymbols.list = (struct partial_symbol *)
1604 xrealloc (global_psymbols.list,
1605 (h_max + origsize) * sizeof(struct partial_symbol));
1606 global_psymbols.next = global_psymbols.list + origsize;
1607 global_psymbols.size = h_max + origsize;
1609 global_psymbols.list = (struct partial_symbol *)
1610 xmalloc (h_max * sizeof(struct partial_symbol));
1611 global_psymbols.next = global_psymbols.list;
1612 global_psymbols.size = h_max;
1615 /* Pass 1.5 over files: partition out global symbol space */
1616 s_idx = global_psymbols.next - global_psymbols.list;
1617 for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++) {
1618 fdr_to_pst[f_idx].pst->globals_offset = s_idx;
1619 s_idx += fdr_to_pst[f_idx].n_globals;
1622 /* Pass 1.6 over files: partition out static symbol space.
1623 Note that this loop starts at 0, not at -1. */
1624 stat_idx = static_psymbols.next - static_psymbols.list;
1625 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
1626 fdr_to_pst[f_idx].pst->statics_offset = stat_idx;
1627 fh = f_idx + (FDR *)(hdr->cbFdOffset);
1628 stat_idx += fh->csym;
1631 /* Now that we know its max size, allocate static symbol list */
1632 if (static_psymbols.list) {
1633 int origsize = static_psymbols.next - static_psymbols.list;
1635 static_psymbols.list = (struct partial_symbol *)
1636 xrealloc (static_psymbols.list,
1637 stat_idx * sizeof(struct partial_symbol));
1638 static_psymbols.next = static_psymbols.list + origsize;
1639 static_psymbols.size = stat_idx;
1641 static_psymbols.list = (struct partial_symbol *)
1642 xmalloc (stat_idx * sizeof(struct partial_symbol));
1643 static_psymbols.next = static_psymbols.list;
1644 static_psymbols.size = stat_idx;
1647 /* Pass 2 over external syms: fill in external symbols */
1648 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
1649 register struct partial_symbol *p;
1650 enum misc_function_type misc_type = mf_text;
1651 esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
1653 if (esh->asym.sc == scUndefined || esh->asym.sc == scNil)
1656 /* Locate the psymtab and the preallocated psymbol. */
1657 pst = fdr_to_pst[esh->ifd].pst;
1658 p = global_psymbols.list + pst->globals_offset +
1659 pst->n_global_syms++;
1660 SYMBOL_NAME(p) = (char *)(esh->asym.iss);
1661 SYMBOL_NAMESPACE(p) = VAR_NAMESPACE;
1663 switch (esh->asym.st) {
1665 SYMBOL_CLASS(p) = LOC_BLOCK;
1666 SYMBOL_VALUE(p) = esh->asym.value;
1669 SYMBOL_CLASS(p) = LOC_STATIC;
1670 SYMBOL_VALUE_ADDRESS(p) = (CORE_ADDR)esh->asym.value;
1671 misc_type = mf_data;
1674 SYMBOL_CLASS(p) = LOC_LABEL;
1675 SYMBOL_VALUE_ADDRESS(p) = (CORE_ADDR)esh->asym.value;
1678 misc_type = mf_unknown;
1679 complain (&unknown_ext_complaint, SYMBOL_NAME(p));
1681 prim_record_misc_function (SYMBOL_NAME(p),
1686 /* Pass 3 over files, over local syms: fill in static symbols */
1687 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
1688 fh = f_idx + (FDR *)(cur_hdr->cbFdOffset);
1689 pst = fdr_to_pst[f_idx].pst;
1690 pst->texthigh = pst->textlow;
1692 for (s_idx = 0; s_idx < fh->csym; ) {
1693 register struct partial_symbol *p;
1695 sh = s_idx + (SYMR *) fh->isymBase;
1697 if (sh->sc == scUndefined || sh->sc == scNil ||
1698 sh->index == 0xfffff) {
1699 /* FIXME, premature? */
1704 /* Locate the preallocated psymbol. */
1705 p = static_psymbols.list + pst->statics_offset +
1707 SYMBOL_NAME(p) = (char *)(sh->iss);
1708 SYMBOL_VALUE(p) = sh->value;
1709 SYMBOL_NAMESPACE(p) = VAR_NAMESPACE;
1712 case stProc: /* Asm labels apparently */
1713 case stStaticProc: /* Function */
1714 SYMBOL_CLASS(p) = LOC_BLOCK;
1715 pst->n_static_syms++; /* Use gdb symbol */
1716 /* Skip over procedure to next one. */
1717 s_idx = (sh->index + (AUXU *)fh->iauxBase)
1721 long procaddr = sh->value;
1723 sh = s_idx + (SYMR *) fh->isymBase - 1;
1724 if (sh->st != stEnd)
1726 high = procaddr + sh->value;
1727 if (high > pst->texthigh)
1728 pst->texthigh = high;
1731 case stStatic: /* Variable */
1732 SYMBOL_CLASS(p) = LOC_STATIC;
1733 SYMBOL_VALUE_ADDRESS(p) = (CORE_ADDR)sh->value;
1735 case stTypedef: /* Typedef */
1736 SYMBOL_CLASS(p) = LOC_TYPEDEF;
1738 case stConstant: /* Constant decl */
1739 SYMBOL_CLASS(p) = LOC_CONST;
1741 case stBlock: /* { }, str, un, enum*/
1742 if (sh->sc == scInfo) {
1743 SYMBOL_NAMESPACE(p) = STRUCT_NAMESPACE;
1744 SYMBOL_CLASS(p) = LOC_TYPEDEF;
1745 pst->n_static_syms++;
1747 /* Skip over the block */
1750 case stFile: /* File headers */
1751 case stLabel: /* Labels */
1752 case stEnd: /* Ends of files */
1755 complain (&unknown_sym_complaint, SYMBOL_NAME(p));
1756 complain (&unknown_st_complaint, sh->st);
1760 pst->n_static_syms++; /* Use this gdb symbol */
1762 s_idx++; /* Go to next file symbol */
1764 /* We don't usually record static syms, but some we seem to. chk dbxread. */
1765 /*FIXME*/ prim_record_misc_function (SYMBOL_NAME(p),
1772 /* The array (of lists) of globals must be sorted. */
1775 /* Now sort the global psymbols. */
1776 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
1777 struct partial_symtab *pst = fdr_to_pst[f_idx].pst;
1778 if (pst->n_global_syms > 1)
1779 qsort (global_psymbols.list + pst->globals_offset,
1780 pst->n_global_syms, sizeof (struct partial_symbol),
1784 /* Mark the last code address, and remember it for later */
1785 hdr->cbDnOffset = end_of_text_seg;
1787 free(&fdr_to_pst[-1]);
1792 /* Do the initial analisys of the F_IDX-th file descriptor.
1793 Allocates a partial symtab for it, and builds the list
1794 of dependent files by recursion. LEV says at which level
1795 of recursion we are called (to pretty up debug traces) */
1797 static struct partial_symtab *
1798 parse_fdr(f_idx, lev, objfile)
1801 struct objfile *objfile;
1804 register struct partial_symtab *pst;
1807 fh = (FDR *) (cur_hdr->cbFdOffset) + f_idx;
1809 /* Use this to indicate into which symtab this file was parsed */
1811 return (struct partial_symtab *) fh->ioptBase;
1813 /* Debuggability level */
1814 if (compare_glevel(max_glevel, fh->glevel) < 0)
1815 max_glevel = fh->glevel;
1817 /* Make a new partial_symtab */
1818 pst = new_psymtab(fh->rss, objfile);
1823 pst->textlow = fh->adr;
1824 pst->texthigh = fh->cpd; /* To be fixed later */
1827 /* Make everything point to everything. */
1828 FDR_IDX(pst) = f_idx;
1829 fdr_to_pst[f_idx].pst = pst;
1830 fh->ioptBase = (int)pst;
1832 /* Analyze its dependencies */
1837 if (fh->cpd == 0) { /* If there are no functions defined here ... */
1838 /* ...then presumably a .h file: drop reverse depends .h->.c */
1839 for (; s_id0 < fh->crfd; s_id0++) {
1840 RFDT *rh = (RFDT *) (fh->rfdBase) + s_id0;
1842 s_id0++; /* Skip self-dependency */
1847 pst->number_of_dependencies = fh->crfd - s_id0;
1848 pst->dependencies = (struct partial_symtab **)
1849 obstack_alloc (psymbol_obstack,
1850 pst->number_of_dependencies *
1851 sizeof (struct partial_symtab *));
1852 for (s_idx = s_id0; s_idx < fh->crfd; s_idx++) {
1853 RFDT *rh = (RFDT *) (fh->rfdBase) + s_idx;
1855 pst->dependencies[s_idx-s_id0] = parse_fdr(*rh, lev+1, objfile);
1862 /* Ancillary function to psymtab_to_symtab(). Does all the work
1863 for turning the partial symtab PST into a symtab, recurring
1864 first on all dependent psymtabs. The argument FILENAME is
1865 only passed so we can see in debug stack traces what file
1869 psymtab_to_symtab_1(pst, filename)
1870 struct partial_symtab *pst;
1881 pending_list = (struct pending **) cur_hdr->cbOptOffset;
1882 if (pending_list == 0) {
1883 pending_list = (struct pending **)
1884 xzalloc(cur_hdr->ifdMax * sizeof(struct pending *));
1885 cur_hdr->cbOptOffset = (int)pending_list;
1888 /* How many symbols will we need */
1889 /* FIXME, this does not count enum values. */
1890 f_max = pst->n_global_syms + pst->n_static_syms;
1891 if (FDR_IDX(pst) == -1) {
1893 st = new_symtab ("unknown", f_max, 0, pst->objfile);
1895 fh = (FDR *) (cur_hdr->cbFdOffset) + FDR_IDX(pst);
1896 f_max += fh->csym + fh->cpd;
1897 st = new_symtab (pst->filename, 2 * f_max, 2 * fh->cline,
1901 /* Read in all partial symbtabs on which this one is dependent.
1902 NOTE that we do have circular dependencies, sigh. We solved
1903 that by setting pst->readin before this point. */
1905 for (i = 0; i < pst->number_of_dependencies; i++)
1906 if (!pst->dependencies[i]->readin) {
1907 /* Inform about additional files to be read in. */
1910 fputs_filtered (" ", stdout);
1912 fputs_filtered ("and ", stdout);
1914 printf_filtered ("%s...",
1915 pst->dependencies[i]->filename);
1916 wrap_here (""); /* Flush output */
1919 /* We only pass the filename for debug purposes */
1920 psymtab_to_symtab_1(pst->dependencies[i],
1921 pst->dependencies[i]->filename);
1924 /* Now read the symbols for this symtab */
1926 cur_fd = FDR_IDX(pst);
1930 /* Get a new lexical context */
1933 top_stack->cur_st = cur_stab;
1934 top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab),
1936 BLOCK_START(top_stack->cur_block) = fh ? fh->adr : 0;
1937 BLOCK_END(top_stack->cur_block) = 0;
1938 top_stack->blocktype = stFile;
1939 top_stack->maxsyms = 2*f_max;
1940 top_stack->cur_type = 0;
1941 top_stack->procadr = 0;
1942 top_stack->numargs = 0;
1944 /* Parse locals and procedures */
1946 parse_one_file(fh, cur_fd, (cur_fd == (cur_hdr->ifdMax - 1)) ?
1947 cur_hdr->cbDnOffset : fh[1].adr);
1949 /* .. and our share of externals.
1950 XXX use the global list to speed up things here. how ?
1951 FIXME, Maybe quit once we have found the right number of ext's? */
1952 /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
1953 top_stack->blocktype = stFile;
1954 top_stack->maxsyms = cur_hdr->isymMax + cur_hdr->ipdMax + cur_hdr->iextMax;
1955 for (i = 0; i < cur_hdr->iextMax; i++) {
1956 register EXTR *esh = (EXTR *) (cur_hdr->cbExtOffset) + i;
1957 if (esh->ifd == cur_fd)
1958 parse_external(esh, 1);
1961 /* If there are undefined, tell the user */
1962 if (n_undef_symbols) {
1963 printf_filtered("File %s contains %d unresolved references:",
1964 st->filename, n_undef_symbols);
1965 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
1966 n_undef_vars, n_undef_procs, n_undef_labels);
1967 n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
1973 * Sort the symbol table now, we are done adding symbols to it.
1975 sort_symtab_syms(st);
1977 /* Now link the psymtab and the symtab. */
1981 /* Ancillary parsing procedures. */
1983 /* Lookup the type at relative index RN. Return it in TPP
1984 if found and in any event come up with its name PNAME.
1985 Return value says how many aux symbols we ate */
1988 cross_ref(rn, tpp, pname)
1995 /* Escape index means 'the next one' */
1996 if (rn->rfd == 0xfff)
1997 rf = *(unsigned *) (rn + 1);
2003 *pname = "<undefined>";
2006 * Find the relative file descriptor and the symbol in it
2008 FDR *fh = get_rfd(cur_fd, rf);
2013 * If we have processed this symbol then we left a forwarding
2014 * pointer to the corresponding GDB symbol. If not, we`ll put
2015 * it in a list of pending symbols, to be processed later when
2016 * the file f will be. In any event, we collect the name for
2017 * the type here. Which is why we made a first pass at
2020 sh = (SYMR *) (fh->isymBase) + rn->index;
2022 /* Careful, we might be looking at .o files */
2023 *pname = (UNSAFE_DATA_ADDR(sh->iss)) ? "<undefined>" :
2026 /* Have we parsed it ? */
2027 if ((!UNSAFE_DATA_ADDR(sh->value)) && (sh->st == stParsed)) {
2028 t = (struct type *) sh->value;
2033 /* Avoid duplicates */
2034 p = is_pending_symbol(fh, sh);
2039 add_pending(fh, sh, *tpp);
2043 /* We used one auxent normally, two if we got a "next one" rf. */
2044 return (rn->rfd == 0xfff? 2: 1);
2048 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2049 keeping the symtab sorted */
2051 static struct symbol *
2052 mylookup_symbol (name, block, namespace, class)
2054 register struct block *block;
2055 enum namespace namespace;
2056 enum address_class class;
2058 register int bot, top, inc;
2059 register struct symbol *sym;
2062 top = BLOCK_NSYMS(block);
2065 sym = BLOCK_SYM(block, bot);
2066 if (SYMBOL_NAME(sym)[0] == inc
2067 && SYMBOL_NAMESPACE(sym) == namespace
2068 && SYMBOL_CLASS(sym) == class
2069 && !strcmp(SYMBOL_NAME(sym), name))
2073 if (block = BLOCK_SUPERBLOCK (block))
2074 return mylookup_symbol (name, block, namespace, class);
2079 /* Add a new symbol S to a block B.
2080 Infrequently, we will need to reallocate the block to make it bigger.
2081 We only detect this case when adding to top_stack->cur_block, since
2082 that's the only time we know how big the block is. FIXME. */
2089 int nsyms = BLOCK_NSYMS(b)++;
2090 struct block *origb;
2091 struct parse_stack *stackp;
2093 if (b == top_stack->cur_block &&
2094 nsyms >= top_stack->maxsyms) {
2095 complain (&block_overflow_complaint, s->name);
2096 /* In this case shrink_block is actually grow_block, since
2097 BLOCK_NSYMS(b) is larger than its current size. */
2099 b = shrink_block (top_stack->cur_block, top_stack->cur_st);
2101 /* Now run through the stack replacing pointers to the
2102 original block. shrink_block has already done this
2103 for the blockvector and BLOCK_FUNCTION. */
2104 for (stackp = top_stack; stackp; stackp = stackp->next) {
2105 if (stackp->cur_block == origb) {
2106 stackp->cur_block = b;
2107 stackp->maxsyms = BLOCK_NSYMS (b);
2111 BLOCK_SYM(b,nsyms) = s;
2114 /* Add a new block B to a symtab S */
2121 struct blockvector *bv = BLOCKVECTOR(s);
2123 bv = (struct blockvector *)xrealloc(bv, sizeof(struct blockvector) +
2124 BLOCKVECTOR_NBLOCKS(bv) * sizeof(bv->block));
2125 if (bv != BLOCKVECTOR(s))
2126 BLOCKVECTOR(s) = bv;
2128 BLOCKVECTOR_BLOCK(bv, BLOCKVECTOR_NBLOCKS(bv)++) = b;
2131 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2132 MIPS' linenumber encoding might need more than one byte
2133 to describe it, LAST is used to detect these continuation lines */
2136 add_line(lt, lineno, adr, last)
2137 struct linetable *lt;
2143 last = -2; /* make sure we record first line */
2145 if (last == lineno) /* skip continuation lines */
2148 lt->item[lt->nitems].line = lineno;
2149 lt->item[lt->nitems++].pc = adr << 2;
2155 /* Comparison functions, used when sorting things */
2157 /* Symtabs must be ordered viz the code segments they cover */
2160 compare_symtabs( s1, s2)
2161 struct symtab **s1, **s2;
2163 /* "most specific" first */
2165 register struct block *b1, *b2;
2166 b1 = BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1),GLOBAL_BLOCK);
2167 b2 = BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2),GLOBAL_BLOCK);
2168 if (BLOCK_END(b1) == BLOCK_END(b2))
2169 return BLOCK_START(b1) - BLOCK_START(b2);
2170 return BLOCK_END(b1) - BLOCK_END(b2);
2174 /* Partial Symtabs, same */
2177 compare_psymtabs( s1, s2)
2178 struct partial_symtab **s1, **s2;
2180 /* Perf twist: put the ones with no code at the end */
2182 register int a = (*s1)->textlow;
2183 register int b = (*s2)->textlow;
2192 /* Partial symbols are compared lexicog by their print names */
2195 compare_psymbols (s1, s2)
2196 register struct partial_symbol *s1, *s2;
2199 *st1 = SYMBOL_NAME(s1),
2200 *st2 = SYMBOL_NAME(s2);
2202 return (st1[0] - st2[0] ? st1[0] - st2[0] :
2203 strcmp(st1 + 1, st2 + 1));
2206 /* Blocks with a smaller low bound should come first */
2208 static int compare_blocks(b1,b2)
2209 struct block **b1, **b2;
2211 register int addr_diff;
2213 addr_diff = (BLOCK_START((*b1))) - (BLOCK_START((*b2)));
2215 return (BLOCK_END((*b1))) - (BLOCK_END((*b2)));
2220 /* Sorting and reordering procedures */
2222 /* Sort the blocks of a symtab S.
2223 Reorder the blocks in the blockvector by code-address,
2224 as required by some MI search routines */
2230 struct blockvector *bv = BLOCKVECTOR(s);
2232 if (BLOCKVECTOR_NBLOCKS(bv) <= 2) {
2234 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) == 0)
2235 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = 0;
2236 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) == 0)
2237 BLOCK_START(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) = 0;
2241 * This is very unfortunate: normally all functions are compiled in
2242 * the order they are found, but if the file is compiled -O3 things
2243 * are very different. It would be nice to find a reliable test
2244 * to detect -O3 images in advance.
2246 if (BLOCKVECTOR_NBLOCKS(bv) > 3)
2247 qsort(&BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK),
2248 BLOCKVECTOR_NBLOCKS(bv) - FIRST_LOCAL_BLOCK,
2249 sizeof(struct block *),
2253 register CORE_ADDR high = 0;
2254 register int i, j = BLOCKVECTOR_NBLOCKS(bv);
2256 for (i = FIRST_LOCAL_BLOCK; i < j; i++)
2257 if (high < BLOCK_END(BLOCKVECTOR_BLOCK(bv,i)))
2258 high = BLOCK_END(BLOCKVECTOR_BLOCK(bv,i));
2259 BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = high;
2262 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) =
2263 BLOCK_START(BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK));
2265 BLOCK_START(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) =
2266 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK));
2267 BLOCK_END (BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) =
2268 BLOCK_END (BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK));
2271 /* Sort the symtab list, as required by some search procedures.
2272 We want files ordered to make them look right to users, and for
2273 searching (see block_for_pc). */
2279 struct symtab *stab;
2280 register struct symtab **all_symtabs;
2281 register int symtab_count;
2286 /* Create an array of pointers to all the symtabs. */
2287 for (symtab_count = 0, stab = symtab_list;
2289 symtab_count++, stab = stab->next) {
2290 obstack_grow (psymbol_obstack, &stab, sizeof (stab));
2291 /* FIXME: Only sort blocks for new symtabs ??? */
2295 all_symtabs = (struct symtab **)
2296 obstack_base (psymbol_obstack);
2297 qsort((char *)all_symtabs, symtab_count,
2298 sizeof(struct symtab *), compare_symtabs);
2300 /* Re-construct the symtab list, but now it is sorted. */
2301 for (i = 0; i < symtab_count-1; i++)
2302 all_symtabs[i]->next = all_symtabs[i+1];
2303 all_symtabs[i]->next = 0;
2304 symtab_list = all_symtabs[0];
2306 obstack_free (psymbol_obstack, all_symtabs);
2309 /* Sort the partial symtab list, as required by some search procedures.
2310 PC lookups stop at the first psymtab such that textlow <= PC < texthigh */
2316 register int all_psymtabs_count;
2317 struct partial_symtab *pstab;
2318 struct partial_symtab **all_psymtabs;
2320 if (!partial_symtab_list)
2323 /* Create an array of pointers to all the partial_symtabs. */
2325 for (all_psymtabs_count = 0, pstab = partial_symtab_list;
2327 all_psymtabs_count++, pstab = pstab->next)
2328 obstack_grow (psymbol_obstack, &pstab, sizeof (pstab));
2330 all_psymtabs = (struct partial_symtab **)
2331 obstack_base (psymbol_obstack);
2333 qsort((char *)all_psymtabs, all_psymtabs_count,
2334 sizeof(struct partial_symtab *), compare_psymtabs);
2336 /* Re-construct the partial_symtab_list, but now it is sorted. */
2338 for (i = 0; i < all_psymtabs_count-1; i++)
2339 all_psymtabs[i]->next = all_psymtabs[i+1];
2340 all_psymtabs[i]->next = 0;
2341 partial_symtab_list = all_psymtabs[0];
2343 obstack_free (psymbol_obstack, all_psymtabs);
2346 /* Constructor/restructor/destructor procedures */
2348 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2349 MAXSYMS and linenumbers MAXLINES we'll put in it */
2353 new_symtab(name, maxsyms, maxlines, objfile)
2356 struct symtab *s = allocate_symtab (name, objfile);
2358 LINETABLE(s) = new_linetable(maxlines);
2360 /* All symtabs must have at least two blocks */
2361 BLOCKVECTOR(s) = new_bvect(2);
2362 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK) = new_block(maxsyms);
2363 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), STATIC_BLOCK) = new_block(maxsyms);
2364 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s),STATIC_BLOCK)) =
2365 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK);
2367 s->free_code = free_linetable;
2369 /* Link the new symtab into the list of such. */
2370 s->next = symtab_list;
2376 /* Allocate a new partial_symtab NAME */
2378 static struct partial_symtab *
2379 new_psymtab(name, objfile)
2381 struct objfile *objfile;
2383 struct partial_symtab *pst;
2385 pst = (struct partial_symtab *)
2386 obstack_alloc (psymbol_obstack, sizeof (*pst));
2387 bzero (pst, sizeof (*pst));
2389 if (name == (char*)-1) /* FIXME -- why not null here? */
2390 pst->filename = "<no name>";
2392 pst->filename = name;
2394 /* Chain it to its object file */
2395 pst->objfile = objfile;
2396 pst->objfile_chain = objfile->psymtabs;
2397 objfile->psymtabs = pst;
2399 pst->next = partial_symtab_list;
2400 partial_symtab_list = pst;
2402 /* Keep a backpointer to the file's symbols */
2403 pst->read_symtab_private = (char *) obstack_alloc (psymbol_obstack,
2404 sizeof (struct symloc));
2405 CUR_HDR(pst) = cur_hdr;
2407 /* The way to turn this into a symtab is to call... */
2408 pst->read_symtab = mipscoff_psymtab_to_symtab;
2414 /* Allocate a linetable array of the given SIZE */
2417 struct linetable *new_linetable(size)
2419 struct linetable *l;
2421 size = size * sizeof(l->item) + sizeof(struct linetable);
2422 l = (struct linetable *)xmalloc(size);
2427 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2428 I am not so sure about the 3.4 ones */
2434 struct linetable *l = new_linetable(LINETABLE(s)->nitems);
2436 bcopy(LINETABLE(s), l,
2437 LINETABLE(s)->nitems * sizeof(l->item) + sizeof(struct linetable));
2438 free (LINETABLE(s));
2442 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2445 struct blockvector *
2448 struct blockvector *bv;
2451 size = sizeof(struct blockvector) + nblocks * sizeof(struct block*);
2452 bv = (struct blockvector *) xzalloc(size);
2454 BLOCKVECTOR_NBLOCKS(bv) = nblocks;
2459 /* Allocate and zero a new block of MAXSYMS symbols */
2465 int size = sizeof(struct block) + (maxsyms-1) * sizeof(struct symbol *);
2466 struct block *b = (struct block *)xzalloc(size);
2471 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2472 Shrink_block can also be used by add_symbol to grow a block. */
2474 static struct block *
2480 struct blockvector *bv = BLOCKVECTOR(s);
2483 /* Just reallocate it and fix references to the old one */
2485 new = (struct block *) xrealloc ((char *)b, sizeof(struct block) +
2486 (BLOCK_NSYMS(b)-1) * sizeof(struct symbol *));
2488 /* Should chase pointers to old one. Fortunately, that`s just
2489 the block`s function and inferior blocks */
2490 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b)
2491 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2492 for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++)
2493 if (BLOCKVECTOR_BLOCK(bv,i) == b)
2494 BLOCKVECTOR_BLOCK(bv,i) = new;
2495 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) == b)
2496 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) = new;
2500 /* Create a new symbol with printname NAME */
2507 struct symbol *s = (struct symbol *)
2508 obstack_alloc (symbol_obstack, sizeof (struct symbol));
2510 bzero (s, sizeof (*s));
2511 SYMBOL_NAME(s) = name;
2515 /* Create a new type with printname NAME */
2522 struct type *t = (struct type *)
2523 obstack_alloc (symbol_obstack, sizeof (struct type));
2525 bzero (t, sizeof (*t));
2526 TYPE_VPTR_FIELDNO (t) = -1;
2527 TYPE_NAME(t) = name;
2531 /* Create and initialize a new type with printname NAME.
2532 CODE and LENGTH are the initial info we put in,
2533 UNS says whether the type is unsigned or not. */
2537 make_type(code, length, uns, name)
2538 enum type_code code;
2542 register struct type *type;
2544 /* FIXME, I don't think this ever gets freed. */
2545 type = (struct type *) xzalloc(sizeof(struct type));
2546 TYPE_CODE(type) = code;
2547 TYPE_LENGTH(type) = length;
2548 TYPE_FLAGS(type) = uns ? TYPE_FLAG_UNSIGNED : 0;
2549 TYPE_NAME(type) = name;
2550 TYPE_VPTR_FIELDNO (type) = -1;
2555 /* Create and initialize a new struct or union type, a la make_type. */
2559 make_struct_type(code, length, uns, name)
2560 enum type_code code;
2564 register struct type *type;
2566 type = make_type (code, length, uns, name);
2568 /* FIXME, I don't think this ever gets freed. */
2569 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
2570 xzalloc (sizeof (struct cplus_struct_type));
2574 /* Allocate a new field named NAME to the type TYPE */
2578 new_field(type,name)
2584 /* Fields are kept in an array */
2585 if (TYPE_NFIELDS(type))
2586 TYPE_FIELDS(type) = (struct field*)xrealloc(TYPE_FIELDS(type),
2587 (TYPE_NFIELDS(type)+1) * sizeof(struct field));
2589 TYPE_FIELDS(type) = (struct field*)xzalloc(sizeof(struct field));
2590 f = &(TYPE_FIELD(type,TYPE_NFIELDS(type)));
2591 TYPE_NFIELDS(type)++;
2592 bzero(f, sizeof(struct field));
2593 f->name = name; /* Whether or not NAME is zero, this works. */
2597 /* Make an enum constant for a member F of an enumerated type T */
2600 make_enum_constant(f,t)
2606 * This is awful, but that`s the way it is supposed to be
2607 * (BTW, no need to free the real 'type', it's a builtin)
2609 f->type = (struct type *) f->bitpos;
2611 s = new_symbol(f->name);
2612 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
2613 SYMBOL_CLASS(s) = LOC_CONST;
2615 SYMBOL_VALUE(s) = f->bitpos;
2616 add_symbol(s, top_stack->cur_block);
2621 /* Things used for calling functions in the inferior.
2622 These functions are exported to our companion
2623 mips-dep.c file and are here because they play
2624 with the symbol-table explicitly. */
2627 /* Need to make a new symbol on the fly for the dummy
2628 frame we put on the stack. Which goes in the.. */
2630 static struct symtab *dummy_symtab;
2632 /* Make up a dummy symbol for the code we put at END_PC,
2633 of size SIZE, invoking a function with NARGS arguments
2634 and using a frame of FRAMESIZE bytes */
2636 mips_create_dummy_symbol(end_pc, size, nargs, framesize)
2640 struct mips_extra_func_info *gdbinfo;
2642 /* Allocate symtab if not done already */
2643 if (dummy_symtab == 0)
2644 dummy_symtab = new_symtab(".dummy_symtab.", 100, 0);
2646 /* Make a new block. Only needs one symbol */
2648 BLOCK_START(bl) = end_pc - size;
2649 BLOCK_END(bl) = end_pc;
2651 BLOCK_SUPERBLOCK(bl) =
2652 BLOCKVECTOR_BLOCK(BLOCKVECTOR(dummy_symtab),GLOBAL_BLOCK);
2653 add_block(bl, dummy_symtab);
2654 sort_blocks(dummy_symtab);
2656 BLOCK_FUNCTION(bl) = new_symbol("??");
2657 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(bl)) = bl;
2658 g = new_symbol(".gdbinfo.");
2659 BLOCK_SYM(bl,BLOCK_NSYMS(bl)++) = g;
2661 SYMBOL_NAMESPACE(g) = LABEL_NAMESPACE;
2662 SYMBOL_CLASS(g) = LOC_CONST;
2663 SYMBOL_TYPE(g) = builtin_type_void;
2664 gdbinfo = (struct mips_extra_func_info *)
2665 xzalloc(sizeof(struct mips_extra_func_info));
2667 SYMBOL_VALUE(g) = (long) gdbinfo;
2669 gdbinfo->numargs = nargs;
2670 gdbinfo->framesize = framesize;
2671 gdbinfo->framereg = 29;
2672 gdbinfo->pcreg = 31;
2673 gdbinfo->regmask = -2;
2674 gdbinfo->regoffset = -4;
2675 gdbinfo->fregmask = 0; /* XXX */
2676 gdbinfo->fregoffset = 0; /* XXX */
2679 /* We just returned from the dummy code at END_PC, drop its symbol */
2681 mips_destroy_dummy_symbol(end_pc)
2684 struct blockvector *bv = BLOCKVECTOR(dummy_symtab);
2687 bl = block_for_pc(end_pc);
2688 free(BLOCK_FUNCTION(bl));
2689 free(SYMBOL_VALUE(BLOCK_SYM(bl,0)));
2690 free(BLOCK_SYM(bl,0));
2692 for (i = FIRST_LOCAL_BLOCK; i < BLOCKVECTOR_NBLOCKS(bv); i++)
2693 if (BLOCKVECTOR_BLOCK(bv,i) == bl)
2695 for (; i < BLOCKVECTOR_NBLOCKS(bv) - 1; i++)
2696 BLOCKVECTOR_BLOCK(bv,i) = BLOCKVECTOR_BLOCK(bv,i+1);
2697 BLOCKVECTOR_NBLOCKS(bv)--;
2698 sort_blocks(dummy_symtab);
2703 /* Sigtramp: make sure we have all the necessary information
2704 about the signal trampoline code. Since the official code
2705 from MIPS does not do so, we make up that information ourselves.
2706 If they fix the library (unlikely) this code will neutralize itself. */
2713 struct block *b, *b0;
2715 sigtramp_address = -1;
2717 /* We know it is sold as sigvec */
2718 s = lookup_symbol("sigvec", 0, VAR_NAMESPACE, 0, NULL);
2720 /* Most programs do not play with signals */
2724 b0 = SYMBOL_BLOCK_VALUE(s);
2726 /* A label of sigvec, to be more precise */
2727 s = lookup_symbol("sigtramp", b0, VAR_NAMESPACE, 0, NULL);
2729 /* But maybe this program uses its own version of sigvec */
2733 sigtramp_address = SYMBOL_VALUE(s);
2734 sigtramp_end = sigtramp_address + 0x88; /* black magic */
2736 /* Did we or MIPSco fix the library ? */
2737 if (SYMBOL_CLASS(s) == LOC_BLOCK)
2740 /* But what symtab does it live in ? */
2741 st = find_pc_symtab(SYMBOL_VALUE(s));
2744 * Ok, there goes the fix: turn it into a procedure, with all the
2745 * needed info. Note we make it a nested procedure of sigvec,
2746 * which is the way the (assembly) code is actually written.
2748 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
2749 SYMBOL_CLASS(s) = LOC_BLOCK;
2750 SYMBOL_TYPE(s) = make_type(TYPE_CODE_FUNC, 4, 0, 0);
2751 TYPE_TARGET_TYPE(SYMBOL_TYPE(s)) = builtin_type_void;
2753 /* Need a block to allocate .gdbinfo. in */
2755 SYMBOL_BLOCK_VALUE(s) = b;
2756 BLOCK_START(b) = sigtramp_address;
2757 BLOCK_END(b) = sigtramp_end;
2758 BLOCK_FUNCTION(b) = s;
2759 BLOCK_SUPERBLOCK(b) = BLOCK_SUPERBLOCK(b0);
2763 /* Make a .gdbinfo. for it */
2765 struct mips_extra_func_info *e =
2766 (struct mips_extra_func_info *)
2767 xzalloc(sizeof(struct mips_extra_func_info));
2769 e->numargs = 0; /* the kernel thinks otherwise */
2770 /* align_longword(sigcontext + SIGFRAME) */
2771 e->framesize = 0x150;
2772 e->framereg = SP_REGNUM;
2775 e->regoffset = -(41 * sizeof(int));
2777 e->fregoffset = -(37 * sizeof(int));
2780 s = new_symbol(".gdbinfo.");
2781 SYMBOL_VALUE(s) = (int) e;
2782 SYMBOL_NAMESPACE(s) = LABEL_NAMESPACE;
2783 SYMBOL_CLASS(s) = LOC_CONST;
2784 SYMBOL_TYPE(s) = builtin_type_void;
2787 BLOCK_SYM(b,BLOCK_NSYMS(b)++) = s;
2790 /* Initialization */
2792 static struct sym_fns ecoff_sym_fns = {"ecoff", 5,
2793 mipscoff_new_init, mipscoff_symfile_init,
2794 mipscoff_symfile_read};
2796 _initialize_mipsread ()
2798 add_symtab_fns (&ecoff_sym_fns);
2800 /* Missing basic types */
2801 builtin_type_string = make_type(TYPE_CODE_PASCAL_ARRAY,
2803 builtin_type_complex = make_type(TYPE_CODE_FLT,
2804 2 * sizeof(float), 0, "complex");
2805 builtin_type_double_complex = make_type(TYPE_CODE_FLT,
2806 2 * sizeof(double), 0, "double_complex");
2807 builtin_type_fixed_dec = make_type(TYPE_CODE_INT, sizeof(int),
2808 0, "fixed_decimal");
2809 builtin_type_float_dec = make_type(TYPE_CODE_FLT, sizeof(double),
2810 0, "floating_decimal");