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 type *make_struct_type();
177 static struct symbol *mylookup_symbol();
178 static struct block *shrink_block();
180 static int compare_symtabs();
181 static int compare_psymtabs();
182 static int compare_blocks();
184 static struct partial_symtab *new_psymtab();
185 static struct partial_symtab *parse_fdr();
186 static int compare_psymbols();
188 static void psymtab_to_symtab_1();
189 static void add_block();
190 static void add_symbol();
191 static int add_line();
192 static void reorder_symtabs();
193 static void reorder_psymtabs();
194 static void shrink_linetable();
196 /* Things we export to other modules */
198 /* Address bounds for the signal trampoline in inferior, if any */
199 /* FIXME: Nothing really seems to use this. Why is it here? */
201 CORE_ADDR sigtramp_address, sigtramp_end;
203 /* The entry point (starting address) of the file, if it is an executable. */
205 extern CORE_ADDR startup_file_start; /* From blockframe.c */
206 extern CORE_ADDR startup_file_end; /* From blockframe.c */
211 /* If we have a file symbol header lying around, blow it away. */
213 free ((char *)cur_hdr);
218 mipscoff_symfile_init (sf)
221 sf->sym_private = NULL;
225 mipscoff_symfile_read(sf, addr, mainline)
230 struct coff_symfile_info *info = (struct coff_symfile_info *)sf->sym_private;
231 bfd *abfd = sf->objfile->obfd;
232 char *name = bfd_get_filename (abfd);
236 int stringtab_offset;
238 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
239 desc = fileno ((FILE *)(abfd->iostream)); /* Raw file descriptor */
242 /* Position to read the symbol table. */
243 val = lseek (desc, (long)symtab_offset, 0);
245 perror_with_name (name);
247 init_misc_bunches ();
248 make_cleanup (discard_misc_bunches, 0);
250 /* Now that the executable file is positioned at symbol table,
251 process it and define symbols accordingly. */
253 read_mips_symtab(sf->objfile, desc);
255 /* Go over the misc symbol bunches and install them in vector. */
257 condense_misc_bunches (!mainline);
260 /* Exported procedure: Allocate zeroed memory */
265 char *p = xmalloc(size);
271 /* Exported procedure: Builds a symtab from the PST partial one.
272 Restores the environment in effect when PST was created, delegates
273 most of the work to an ancillary procedure, and sorts
274 and reorders the symtab list at the end */
277 mipscoff_psymtab_to_symtab(pst)
278 struct partial_symtab *pst;
287 printf_filtered("Reading in symbols for %s...", pst->filename);
290 /* Restore the header and list of pending typedefs */
291 cur_hdr = CUR_HDR(pst);
293 psymtab_to_symtab_1(pst, pst->filename);
298 printf_filtered("done.\n");
301 /* Exported procedure: Is PC in the signal trampoline code */
304 in_sigtramp(pc, name)
308 if (sigtramp_address == 0)
310 return (pc >= sigtramp_address && pc < sigtramp_end);
313 /* File-level interface functions */
315 /* Read the symtab information from file FSYM into memory. Also,
316 return address just past end of our text segment in *END_OF_TEXT_SEGP. */
319 read_the_mips_symtab(abfd, fsym, end_of_text_segp)
322 CORE_ADDR *end_of_text_segp;
324 int stsize, st_hdrsize;
327 /* Header for executable/object file we read symbols from */
328 struct coff_exec filhdr;
330 /* We get here with DESC pointing to the symtab header. But we need
331 * other info from the initial headers */
333 myread(fsym, &filhdr, sizeof filhdr);
335 if (end_of_text_segp)
337 bfd_h_get_32 (abfd, filhdr.a.text_start) +
338 bfd_h_get_32 (abfd, filhdr.a.tsize);
340 /* Find and read the symbol table header */
341 st_hdrsize = bfd_h_get_32 (abfd, filhdr.f.f_nsyms);
342 st_filptr = bfd_h_get_32 (abfd, filhdr.f.f_symptr);
346 lseek(fsym, st_filptr, L_SET);
347 if (st_hdrsize > sizeof (st_hdr)) /* Profanity check */
349 if (read(fsym, &st_hdr, st_hdrsize) != st_hdrsize)
352 /* Find out how large the symbol table is */
353 stsize = (st_hdr.cbExtOffset - (st_filptr + st_hdrsize))
354 + st_hdr.iextMax * cbEXTR;
356 /* Allocate space for the symbol table. Read it in. */
357 cur_hdr = (HDRR *) xmalloc(stsize + st_hdrsize);
359 bcopy(&st_hdr, cur_hdr, st_hdrsize);
360 if (read(fsym, (char *) cur_hdr + st_hdrsize, stsize) != stsize)
363 /* Fixup file_pointers in it */
364 fixup_symtab(cur_hdr, (char *) cur_hdr + st_hdrsize,
365 st_filptr + st_hdrsize);
369 error("Short read on %s", bfd_get_filename (abfd));
373 /* Turn all file-relative pointers in the symtab described by HDR
374 into memory pointers, given that the symtab itself is located
375 at DATA in memory and F_PTR in the file. */
378 fixup_symtab( hdr, data, f_ptr)
390 * These fields are useless (and empty) by now:
391 * hdr->cbDnOffset, hdr->cbOptOffset
392 * We use them for other internal purposes.
395 hdr->cbOptOffset = 0;
398 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
414 * Fix all string pointers inside the symtab, and
415 * the FDR records. Also fix other miscellany.
417 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
418 register unsigned code_offset;
420 /* Header itself, and strings */
421 fh = (FDR *) (hdr->cbFdOffset) + f_idx;
422 fh->issBase += hdr->cbSsOffset;
424 fh->rss = (long)fh->rss + fh->issBase;
425 for (s_idx = 0; s_idx < fh->csym; s_idx++) {
426 sh = (SYMR*)(hdr->cbSymOffset) + fh->isymBase + s_idx;
427 sh->iss = (long) sh->iss + fh->issBase;
434 fh->isymBase = (int)((SYMR*)(hdr->cbSymOffset)+fh->isymBase);
436 /* cannot fix fh->ipdFirst because it is a short */
437 #define IPDFIRST(h,fh) \
438 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
440 /* Optional symbols (actually used for partial_symtabs) */
446 fh->iauxBase = hdr->cbAuxOffset + fh->iauxBase * sizeof(AUXU);
447 /* Relative file descriptor table */
448 fh->rfdBase = hdr->cbRfdOffset + fh->rfdBase * sizeof(RFDT);
452 fh->cbLineOffset += hdr->cbLineOffset;
454 /* Procedure symbols. (XXX This should be done later) */
455 code_offset = fh->adr;
456 for (s_idx = 0; s_idx < fh->cpd; s_idx++) {
457 unsigned name, only_ext;
459 pr = (PDR*)(IPDFIRST(hdr,fh)) + s_idx;
461 /* Simple rule to find files linked "-x" */
462 only_ext = fh->rss == -1;
464 if (pr->isym == -1) {
465 /* static function */
469 name = hdr->cbExtOffset + pr->isym * sizeof(EXTR);
470 sh = &((EXTR*)name)->asym;
474 sh = (SYMR*)fh->isymBase + pr->isym;
475 /* Included code ? */
476 if (s_idx == 0 && pr->adr != 0)
477 code_offset -= pr->adr;
480 /* Turn index into a pointer */
483 /* Fix line numbers */
484 pr->cbLineOffset += fh->cbLineOffset;
486 /* Relocate address */
488 pr->adr += code_offset;
492 /* External symbols: fix string */
493 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
494 esh = (EXTR*)(hdr->cbExtOffset) + s_idx;
495 esh->asym.iss = esh->asym.iss + hdr->cbSsExtOffset;
500 /* Find a file descriptor given its index RF relative to a file CF */
508 f = (FDR *) (cur_hdr->cbFdOffset) + cf;
509 /* Object files do not have the RFD table, all refs are absolute */
511 return (FDR *) (cur_hdr->cbFdOffset) + rf;
512 cf = *((pRFDT) f->rfdBase + rf);
513 return (FDR *) (cur_hdr->cbFdOffset) + cf;
516 /* Return a safer print NAME for a file descriptor */
522 if (name == (char *) -1)
523 return "<stripped file>";
524 if (UNSAFE_DATA_ADDR(name))
530 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
531 whether we are adding to the general symtab or not.
532 FIXME: INCREMENTAL is currently always zero, though it should not be. */
535 read_mips_symtab (objfile, desc)
536 struct objfile *objfile;
539 CORE_ADDR end_of_text_seg;
541 read_the_mips_symtab(objfile->obfd, desc, &end_of_text_seg);
543 parse_partial_symbols(end_of_text_seg, objfile);
546 * Check to make sure file was compiled with -g.
547 * If not, warn the user of this limitation.
549 if (compare_glevel(max_glevel, GLEVEL_2) < 0) {
550 if (max_gdbinfo == 0)
552 "\n%s not compiled with -g, debugging support is limited.\n",
555 "You should compile with -g2 or -g3 for best debugging support.\n");
560 /* Local utilities */
562 /* Map of FDR indexes to partial symtabs */
564 static struct pst_map {
565 struct partial_symtab *pst; /* the psymtab proper */
566 int n_globals; /* globals it exports */
567 int n_statics; /* statics (locals) it contains */
571 /* Utility stack, used to nest procedures and blocks properly.
572 It is a doubly linked list, to avoid too many alloc/free.
573 Since we might need it quite a few times it is NOT deallocated
576 static struct parse_stack {
577 struct parse_stack *next, *prev;
578 struct symtab *cur_st; /* Current symtab */
579 struct block *cur_block; /* Block in it */
580 int blocktype; /* What are we parsing */
581 int maxsyms; /* Max symbols in this block */
582 struct type *cur_type; /* Type we parse fields for */
583 int procadr; /* Start addres of this procedure */
584 int numargs; /* Its argument count */
585 } *top_stack; /* Top stack ptr */
588 /* Enter a new lexical context */
590 static push_parse_stack()
592 struct parse_stack *new;
594 /* Reuse frames if possible */
595 if (top_stack && top_stack->prev)
596 new = top_stack->prev;
598 new = (struct parse_stack *) xzalloc(sizeof(struct parse_stack));
599 /* Initialize new frame with previous content */
601 register struct parse_stack *prev = new->prev;
604 top_stack->prev = new;
606 new->next = top_stack;
611 /* Exit a lexical context */
613 static pop_parse_stack()
618 top_stack = top_stack->next;
622 /* Cross-references might be to things we haven't looked at
623 yet, e.g. type references. To avoid too many type
624 duplications we keep a quick fixup table, an array
625 of lists of references indexed by file descriptor */
627 static struct pending {
628 struct pending *next; /* link */
629 SYMR *s; /* the symbol */
630 struct type *t; /* its partial type descriptor */
634 /* Check whether we already saw symbol SH in file FH as undefined */
637 struct pending *is_pending_symbol(fh, sh)
641 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
642 register struct pending *p;
644 /* Linear search is ok, list is typically no more than 10 deep */
645 for (p = pending_list[f_idx]; p; p = p->next)
651 /* Check whether we already saw type T in file FH as undefined */
654 struct pending *is_pending_type(fh, t)
658 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
659 register struct pending *p;
661 for (p = pending_list[f_idx]; p; p = p->next)
667 /* Add a new undef symbol SH of type T */
670 add_pending(fh, sh, t)
675 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
676 struct pending *p = is_pending_symbol(fh, sh);
678 /* Make sure we do not make duplicates */
680 p = (struct pending *) xmalloc(sizeof(*p));
683 p->next = pending_list[f_idx];
684 pending_list[f_idx] = p;
686 sh->reserved = 1; /* for quick check */
689 /* Throw away undef entries when done with file index F_IDX */
694 register struct pending *p, *q;
696 for (p = pending_list[f_idx]; p; p = q) {
700 pending_list[f_idx] = 0;
703 /* The number of args to a procedure is not explicit in the symtab,
704 this is the list of all those we know of.
705 This makes parsing more reasonable and avoids extra passes */
707 static struct numarg {
708 struct numarg *next; /* link */
709 unsigned adr; /* procedure's start address */
710 unsigned num; /* arg count */
713 /* Record that the procedure at ADR takes NUM arguments. */
718 struct numarg *n = (struct numarg *) xmalloc(sizeof(struct numarg));
722 n->next = numargs_list;
726 /* See if we know how many arguments the procedure at ADR takes */
731 struct numarg *n = numargs_list;
733 while (n && n->adr != adr)
735 return (n) ? n->num : -1;
738 /* Release storage when done with this file */
743 struct numarg *n = numargs_list, *m;
754 /* Parsing Routines proper. */
756 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
757 For blocks, procedures and types we open a new lexical context.
758 This is basically just a big switch on the symbol's type */
769 /* When a symbol is cross-referenced from other files/symbols
770 we mark it explicitly */
771 int pend = (sh->reserved == 1);
772 enum address_class class;
779 case stGlobal: /* external symbol, goes into global block */
781 b = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st),
783 s = new_symbol(sh->iss);
784 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
787 case stStatic: /* static data, goes into current block. */
789 b = top_stack->cur_block;
790 s = new_symbol(sh->iss);
791 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
794 case stLocal: /* local variable, goes into current block */
795 if (sh->sc == scRegister) {
796 class = LOC_REGISTER;
801 b = top_stack->cur_block;
802 s = new_symbol(sh->iss);
803 SYMBOL_VALUE(s) = sh->value;
805 data: /* Common code for symbols describing data */
806 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
807 SYMBOL_CLASS(s) = class;
810 /* Type could be missing in a number of cases */
811 if (sh->sc == scUndefined || sh->sc == scNil ||
812 sh->index == 0xfffff)
813 SYMBOL_TYPE(s) = builtin_type_int; /* undefined? */
815 SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0);
816 /* Value of a data symbol is its memory address */
819 case stParam: /* arg to procedure, goes into current block */
821 top_stack->numargs++;
822 s = new_symbol(sh->iss);
823 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
824 if (sh->sc == scRegister) {
825 SYMBOL_CLASS(s) = LOC_REGPARM;
829 SYMBOL_CLASS(s) = LOC_ARG;
830 SYMBOL_VALUE(s) = sh->value;
831 SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0);
832 add_symbol(s, top_stack->cur_block);
834 /* FIXME: This has not been tested. See dbxread.c */
835 /* Add the type of this parameter to the function/procedure
836 type of this block. */
837 add_param_to_type(&top_stack->cur_block->function->type,s);
841 case stLabel: /* label, goes into current block */
842 s = new_symbol(sh->iss);
843 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE; /* so that it can be used */
844 SYMBOL_CLASS(s) = LOC_LABEL; /* but not misused */
845 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
846 SYMBOL_TYPE(s) = builtin_type_int;
847 add_symbol(s, top_stack->cur_block);
850 case stProc: /* Procedure, usually goes into global block */
851 case stStaticProc: /* Static procedure, goes into current block */
852 s = new_symbol(sh->iss);
853 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
854 SYMBOL_CLASS(s) = LOC_BLOCK;
855 /* Type of the return value */
856 if (sh->sc == scUndefined || sh->sc == scNil)
857 t = builtin_type_int;
859 t = parse_type(ax + sh->index, sh, 0);
860 b = top_stack->cur_block;
861 if (sh->st == stProc) {
862 struct blockvector *bv = BLOCKVECTOR(top_stack->cur_st);
863 /* The next test should normally be true,
864 but provides a hook for nested functions
865 (which we don't want to make global). */
866 if (b == BLOCKVECTOR_BLOCK(bv, STATIC_BLOCK))
867 b = BLOCKVECTOR_BLOCK(bv, GLOBAL_BLOCK);
871 /* Make a type for the procedure itself */
873 /* FIXME: This has not been tested yet! See dbxread.c */
874 /* Generate a template for the type of this function. The
875 types of the arguments will be added as we read the symbol
877 bcopy(SYMBOL_TYPE(s),lookup_function_type(t),sizeof(struct type));
879 SYMBOL_TYPE(s) = lookup_function_type (t);
882 /* Create and enter a new lexical context */
883 b = new_block(top_stack->maxsyms);
884 SYMBOL_BLOCK_VALUE(s) = b;
885 BLOCK_FUNCTION(b) = s;
886 BLOCK_START(b) = BLOCK_END(b) = sh->value;
887 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
888 add_block(b, top_stack->cur_st);
890 /* Not if we only have partial info */
891 if (sh->sc == scUndefined || sh->sc == scNil)
895 top_stack->cur_block = b;
896 top_stack->blocktype = sh->st;
897 top_stack->cur_type = SYMBOL_TYPE(s);
898 top_stack->procadr = sh->value;
899 top_stack->numargs = 0;
901 sh->value = (long) SYMBOL_TYPE(s);
904 case stBlock: /* Either a lexical block, or some type */
906 top_stack->blocktype = stBlock;
907 if (sh->sc == scInfo) { /* structure/union/enum def */
908 s = new_symbol(sh->iss);
909 SYMBOL_NAMESPACE(s) = STRUCT_NAMESPACE;
910 SYMBOL_CLASS(s) = LOC_TYPEDEF;
912 add_symbol(s, top_stack->cur_block);
913 /* If this type was expected, use its partial definition */
915 t = is_pending_symbol(cur_fdr, sh)->t;
917 /* Uhmm, can`t decide yet. Smash later */
918 t = new_type(sh->iss);
919 TYPE_CODE(t) = TYPE_CODE_UNDEF;
920 add_pending(cur_fdr, sh, t);
923 /* make this the current type */
924 top_stack->cur_type = t;
925 TYPE_LENGTH(t) = sh->value;
926 /* Mark that symbol has a type, and say which one */
927 sh->value = (long) t;
929 /* beginnning of (code) block. Value of symbol
930 is the displacement from procedure start */
931 b = new_block(top_stack->maxsyms);
932 BLOCK_START(b) = sh->value + top_stack->procadr;
933 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
934 top_stack->cur_block = b;
935 add_block(b, top_stack->cur_st);
939 case stEnd: /* end (of anything) */
940 if (sh->sc == scInfo) {
941 /* Finished with type */
942 top_stack->cur_type = 0;
943 } else if (sh->sc == scText &&
944 (top_stack->blocktype == stProc ||
945 top_stack->blocktype == stStaticProc)) {
946 /* Finished with procedure */
947 struct blockvector *bv = BLOCKVECTOR(top_stack->cur_st);
951 BLOCK_END(top_stack->cur_block) += sh->value; /* size */
952 got_numargs(top_stack->procadr, top_stack->numargs);
953 /* Reallocate symbols, saving memory */
954 b = shrink_block(top_stack->cur_block, top_stack->cur_st);
956 /* f77 emits proc-level with address bounds==[0,0],
957 So look for such child blocks, and patch them. */
958 for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++) {
959 struct block *b_bad = BLOCKVECTOR_BLOCK(bv,i);
960 if (BLOCK_SUPERBLOCK(b_bad) == b
961 && BLOCK_START(b_bad) == top_stack->procadr
962 && BLOCK_END(b_bad) == top_stack->procadr) {
963 BLOCK_START(b_bad) = BLOCK_START(b);
964 BLOCK_END(b_bad) = BLOCK_END(b);
967 if (entry_point < BLOCK_END(b)
968 && entry_point >= BLOCK_START(b)) {
969 startup_file_start = BLOCK_START(b);
970 startup_file_end = BLOCK_END(b);
972 } else if (sh->sc == scText && top_stack->blocktype == stBlock) {
973 /* End of (code) block. The value of the symbol
974 is the displacement from the procedure`s start
975 address of the end of this block. */
976 BLOCK_END(top_stack->cur_block) = sh->value + top_stack->procadr;
977 (void) shrink_block(top_stack->cur_block, top_stack->cur_st);
979 pop_parse_stack(); /* restore previous lexical context */
982 case stMember: /* member of struct/union/enum.. */
983 f = new_field(top_stack->cur_type, sh->iss);
984 f->bitpos = sh->value;
985 f->type = parse_type(ax + sh->index, sh, &f->bitsize);
988 case stTypedef: /* type definition */
989 s = new_symbol(sh->iss);
990 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
991 SYMBOL_CLASS(s) = LOC_TYPEDEF;
992 SYMBOL_BLOCK_VALUE(s) = top_stack->cur_block;
993 add_symbol(s, top_stack->cur_block);
994 SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0);
995 sh->value = (long) SYMBOL_TYPE(s);
998 case stFile: /* file name */
1000 top_stack->blocktype = sh->st;
1003 /* I`ve never seen these for C */
1005 break; /* register relocation */
1007 break; /* forwarding address */
1009 break; /* constant */
1011 error("Unknown symbol type %x.", sh->st);
1016 /* Parse the type information provided in the AX entries for
1017 the symbol SH. Return the bitfield size in BS, in case. */
1019 static struct type *parse_type(ax, sh, bs)
1024 /* Null entries in this map are treated specially */
1025 static struct type **map_bt[] =
1027 &builtin_type_void, /* btNil */
1029 &builtin_type_char, /* btChar */
1030 &builtin_type_unsigned_char, /* btUChar */
1031 &builtin_type_short, /* btShort */
1032 &builtin_type_unsigned_short, /* btUShort */
1033 &builtin_type_int, /* btInt */
1034 &builtin_type_unsigned_int, /* btUInt */
1035 &builtin_type_long, /* btLong */
1036 &builtin_type_unsigned_long, /* btULong */
1037 &builtin_type_float, /* btFloat */
1038 &builtin_type_double, /* btDouble */
1045 &builtin_type_complex, /* btComplex */
1046 &builtin_type_double_complex, /* btDComplex */
1048 &builtin_type_fixed_dec, /* btFixedDec */
1049 &builtin_type_float_dec, /* btFloatDec */
1050 &builtin_type_string, /* btString */
1053 &builtin_type_void, /* btVoid */
1057 struct type *tp = 0, *tp1;
1060 /* Procedures start off by one */
1061 if (sh->st == stProc || sh->st == stStaticProc)
1064 /* Undefined ? Should not happen */
1065 if (ax->rndx.rfd == 0xfff) {
1066 return builtin_type_void;
1069 /* Use aux as a type information record, map its basic type */
1071 if (t->bt > (sizeof (map_bt)/sizeof (*map_bt))) {
1072 complain (&basic_type_complaint, t->bt);
1073 return builtin_type_int;
1075 if (map_bt[t->bt]) {
1076 tp = *map_bt[t->bt];
1079 /* Cannot use builtin types -- build our own */
1082 tp = lookup_pointer_type (builtin_type_void);
1086 tp = make_struct_type(TYPE_CODE_STRUCT, 0, 0, 0);
1090 tp = make_struct_type(TYPE_CODE_UNION, 0, 0, 0);
1094 tp = make_type(TYPE_CODE_ENUM, 0, 0, 0);
1098 tp = make_type(TYPE_CODE_RANGE, 0, 0, 0);
1102 tp = make_type(TYPE_CODE_SET, 0, 0, 0);
1106 complain (&basic_type_complaint, t->bt);
1107 return builtin_type_int;
1111 /* Move on to next aux */
1114 /* This is the way it would work if the compiler worked */
1115 register TIR *t1 = t;
1116 while (t1->continued)
1120 /* For bitfields all we need is the width */
1126 /* All these types really point to some (common) MIPS type
1127 definition, and only the type-qualifiers fully identify
1128 them. We`ll make the same effort at sharing */
1129 if (t->bt == btIndirect ||
1130 t->bt == btStruct ||
1133 t->bt == btTypedef ||
1136 char name[256], *pn;
1138 /* Try to cross reference this type */
1140 ax += cross_ref(ax, &tp1, &pn);
1141 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1142 sprintf(name, fmt, pn);
1144 /* reading .o file ? */
1145 if (UNSAFE_DATA_ADDR(tp1))
1147 if (TYPE_CODE(tp1) == TYPE_CODE_UNDEF) {
1149 * Type was incompletely defined, now we know.
1151 TYPE_CODE(tp1) = TYPE_CODE(tp);
1152 TYPE_NAME(tp1) = obsavestring(name, strlen(name));
1153 if (TYPE_CODE(tp1) == TYPE_CODE_ENUM) {
1156 for (i = 0; i < TYPE_NFIELDS(tp1); i++)
1157 make_enum_constant(&TYPE_FIELD(tp1,i), tp1);
1161 /* found as cross ref, rid of our template */
1162 if ((TYPE_FLAGS(tp) & TYPE_FLAG_PERM) == 0)
1165 /* stupid idea of prepending "struct" to type names */
1166 if (t->bt == btStruct && !index(TYPE_NAME(tp), ' ')) {
1167 sprintf(name, fmt, TYPE_NAME(tp));
1168 TYPE_NAME(tp) = obsavestring(name, strlen(name));
1171 TYPE_NAME(tp) = savestring(name, strlen(name));
1174 /* Deal with range types */
1175 if (t->bt == btRange) {
1178 f = new_field(tp, "Low");
1179 f->bitpos = ax->dnLow;
1181 f = new_field(tp, "High");
1182 f->bitpos = ax->dnHigh;
1186 /* Parse all the type qualifiers now. If there are more
1187 than 6 the game will continue in the next aux */
1189 #define PARSE_TQ(tq) \
1190 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, sh);
1192 again: PARSE_TQ(tq0);
1207 /* Make up a complex type from a basic one. Type is passed by
1208 reference in TPP and side-effected as necessary. The type
1209 qualifier TQ says how to handle the aux symbols at AX for
1210 the symbol SX we are currently analyzing.
1211 Returns the number of aux symbols we parsed. */
1214 upgrade_type(tpp, tq, ax, sh)
1222 /* Used in array processing */
1231 t = lookup_pointer_type (*tpp);
1236 t = lookup_function_type (*tpp);
1242 t = make_type(TYPE_CODE_ARRAY, 0, 0, 0);
1243 TYPE_TARGET_TYPE(t) = *tpp;
1245 /* Determine and record the domain type (type of index) */
1246 id = ax->rndx.index;
1252 fh = get_rfd(cur_fd, rf);
1253 f = new_field(t, (char *)0);
1254 bzero(&ss, sizeof ss);
1255 /* XXX */ f->type = parse_type(fh->iauxBase + id * sizeof(AUXU),
1260 * This seems to be a pointer to the end of the Block defining
1261 * the type. Why it is here is magic for me, and I have no
1262 * good use for it anyways.
1264 /* This used to occur because cross_ref returned
1265 the wrong result (ax pointed wrong). FIXME,
1266 delete this code in a while. -- gnu@cygnus jul91 */
1267 complain (&array_parse_complaint, 0);
1269 id = (++ax)->rndx.index;
1270 if ((rf = ax->rndx.rfd) == 0xfff)
1271 rf = (++ax)->isym, off++;
1273 lower = (++ax)->dnLow;
1274 upper = (++ax)->dnHigh;
1275 rf = (++ax)->width; /* bit size of array element */
1277 /* Check whether supplied array element bit size matches
1278 the known size of the element type. If this complaint
1279 ends up not happening, we can remove this code. It's
1280 here because we aren't sure we understand this *&%&$
1282 id = TYPE_LENGTH(TYPE_TARGET_TYPE(t)) << 3; /* bitsize */
1284 /* Most likely an undefined type */
1286 TYPE_LENGTH(TYPE_TARGET_TYPE(t)) = id >> 3;
1289 complain (&array_bitsize_complaint, rf);
1291 TYPE_LENGTH(t) = (upper < 0) ? 0 :
1292 (upper - lower + 1) * (rf >> 3);
1297 /* Volatile -- currently ignored */
1301 complain (&unknown_type_qual_complaint, tq);
1307 /* Parse a procedure descriptor record PR. Note that the procedure
1308 is parsed _after_ the local symbols, now we just make up the
1309 extra information we need into a special symbol that we insert
1310 in the procedure's main block. Note also that images that
1311 have been partially stripped (ld -x) have been deprived
1312 of local symbols, and we have to cope with them here.
1313 The procedure's code ends at BOUND */
1316 parse_procedure(pr, bound)
1319 struct symbol *s, *i;
1320 SYMR *sh = (SYMR*)pr->isym;
1322 struct mips_extra_func_info *e;
1326 /* Reuse the MIPS record */
1327 e = (struct mips_extra_func_info *) pr;
1328 e->numargs = lookup_numargs(pr->adr);
1330 /* Make up our special symbol */
1331 i = new_symbol(".gdbinfo.");
1332 SYMBOL_VALUE(i) = (int)e;
1333 SYMBOL_NAMESPACE(i) = LABEL_NAMESPACE;
1334 SYMBOL_CLASS(i) = LOC_CONST;
1335 SYMBOL_TYPE(i) = builtin_type_void;
1337 /* Make up a name for static procedures. Sigh. */
1338 if (sh == (SYMR*)-1) {
1339 sprintf(name,".static_procedure@%x",pr->adr);
1340 sh_name = savestring(name, strlen(name));
1344 sh_name = (char*)sh->iss;
1345 s = mylookup_symbol(sh_name, top_stack->cur_block,
1346 VAR_NAMESPACE, LOC_BLOCK);
1349 b = SYMBOL_BLOCK_VALUE(s);
1351 s = new_symbol(sh_name);
1352 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
1353 SYMBOL_CLASS(s) = LOC_BLOCK;
1354 /* Donno its type, hope int is ok */
1355 SYMBOL_TYPE(s) = lookup_function_type (builtin_type_int);
1356 add_symbol(s, top_stack->cur_block);
1357 /* Wont have symbols for this one */
1359 SYMBOL_BLOCK_VALUE(s) = b;
1360 BLOCK_FUNCTION(b) = s;
1361 BLOCK_START(b) = pr->adr;
1362 BLOCK_END(b) = bound;
1363 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
1364 add_block(b, top_stack->cur_st);
1370 /* Parse the external symbol ES. Just call parse_symbol() after
1371 making sure we know where the aux are for it. For procedures,
1372 parsing of the PDRs has already provided all the needed
1373 information, we only parse them if SKIP_PROCEDURES is false,
1374 and only if this causes no symbol duplication.
1376 This routine clobbers top_stack->cur_block and ->cur_st. */
1379 parse_external(es, skip_procedures)
1384 if (es->ifd != ifdNil) {
1386 cur_fdr = (FDR*)(cur_hdr->cbFdOffset) + cur_fd;
1387 ax = (AUXU*)cur_fdr->iauxBase;
1389 cur_fdr = (FDR*)(cur_hdr->cbFdOffset);
1392 top_stack->cur_st = cur_stab;
1393 top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st),
1396 /* Reading .o files */
1397 if (es->asym.sc == scUndefined || es->asym.sc == scNil) {
1399 switch (es->asym.st) {
1401 case stProc: what = "procedure"; n_undef_procs++; break;
1402 case stGlobal: what = "variable"; n_undef_vars++; break;
1403 case stLabel: what = "label"; n_undef_labels++; break;
1404 default : what = "symbol"; break;
1408 printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what,
1409 es->asym.iss, fdr_name(cur_fdr->rss));
1413 switch (es->asym.st) {
1415 /* If we have full symbols we do not need more */
1416 if (skip_procedures)
1418 if (mylookup_symbol (es->asym.iss, top_stack->cur_block,
1419 VAR_NAMESPACE, LOC_BLOCK))
1425 * Note that the case of a symbol with indexNil
1426 * must be handled anyways by parse_symbol().
1428 parse_symbol(&es->asym, ax);
1435 /* Parse the line number info for file descriptor FH into
1436 GDB's linetable LT. MIPS' encoding requires a little bit
1437 of magic to get things out. Note also that MIPS' line
1438 numbers can go back and forth, apparently we can live
1439 with that and do not need to reorder our linetables */
1444 struct linetable *lt;
1446 unsigned char *base = (unsigned char*)fh->cbLineOffset;
1448 int delta, count, lineno = 0;
1454 /* Scan by procedure descriptors */
1455 i = 0; j = 0, k = 0;
1456 for (pr = (PDR*)IPDFIRST(cur_hdr,fh); j < fh->cpd; j++, pr++) {
1459 /* No code for this one */
1460 if (pr->iline == ilineNil ||
1461 pr->lnLow == -1 || pr->lnHigh == -1)
1464 * Aurgh! To know where to stop expanding we
1467 for (l = 1; l < (fh->cpd - j); l++)
1468 if (pr[l].iline != -1)
1470 if (l == (fh->cpd - j))
1475 * When procedures are moved around the linenumbers
1476 * are attributed to the next procedure up
1478 if (pr->iline >= halt) continue;
1480 base = (unsigned char*)pr->cbLineOffset;
1481 l = pr->adr >> 2; /* in words */
1482 halt += (pr->adr >> 2) - pr->iline;
1483 for (lineno = pr->lnLow; l < halt;) {
1484 count = *base & 0x0f;
1485 delta = *base++ >> 4;
1489 delta = (base[0] << 8) | base[1];
1490 if (delta >= 0x8000)
1494 lineno += delta;/* first delta is 0 */
1495 k = add_line(lt, lineno, l, k);
1502 /* Parse the symbols of the file described by FH, whose index is F_IDX.
1503 BOUND is the highest core address of this file's procedures */
1506 parse_one_file(fh, f_idx, bound)
1513 /* Parse local symbols first */
1515 for (s_idx = 0; s_idx < fh->csym; s_idx++) {
1516 sh = (SYMR *) (fh->isymBase) + s_idx;
1518 parse_symbol(sh, fh->iauxBase);
1521 /* Procedures next, note we need to look-ahead to
1522 find out where the procedure's code ends */
1524 for (s_idx = 0; s_idx < fh->cpd-1; s_idx++) {
1525 pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + s_idx;
1526 parse_procedure(pr, pr[1].adr); /* next proc up */
1529 pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + s_idx;
1530 parse_procedure(pr, bound); /* next file up */
1533 /* Linenumbers. At the end, check if we can save memory */
1534 parse_lines(fh, LINETABLE(cur_stab));
1535 if (LINETABLE(cur_stab)->nitems < fh->cline)
1536 shrink_linetable(cur_stab);
1539 /* Master parsing procedure for first-pass reading of file symbols
1540 into a partial_symtab.
1542 Parses the symtab described by the global symbolic header CUR_HDR.
1543 END_OF_TEXT_SEG gives the address just after the text segment for
1544 the symtab we are reading. */
1547 parse_partial_symbols(end_of_text_seg, objfile)
1548 int end_of_text_seg;
1549 struct objfile *objfile;
1551 int f_idx, s_idx, h_max, stat_idx;
1553 /* Running pointers */
1558 struct partial_symtab *pst;
1563 * Only parse the Local and External symbols, and the Relative FDR.
1564 * Fixup enough of the loader symtab to be able to use it.
1565 * Allocate space only for the file's portions we need to
1571 max_glevel = MIN_GLEVEL;
1573 /* Allocate the map FDR -> PST.
1574 Minor hack: -O3 images might claim some global data belongs
1575 to FDR -1. We`ll go along with that */
1576 fdr_to_pst = (struct pst_map *)xzalloc((hdr->ifdMax+1) * sizeof *fdr_to_pst);
1579 struct partial_symtab * pst = new_psymtab("", objfile);
1580 fdr_to_pst[-1].pst = pst;
1584 /* Now scan the FDRs, mostly for dependencies */
1585 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
1586 (void) parse_fdr(f_idx, 1, objfile);
1588 /* Take a good guess at how many symbols we might ever need */
1589 h_max = hdr->iextMax;
1591 /* Parse externals: two passes because they can be ordered
1592 in any way, but gdb likes to have them segregated by their
1595 /* Pass 1 over external syms: Presize and partition the list */
1596 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
1597 esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
1598 fdr_to_pst[esh->ifd].n_globals++;
1601 if (global_psymbols.list) {
1602 int origsize = global_psymbols.next - global_psymbols.list;
1604 global_psymbols.list = (struct partial_symbol *)
1605 xrealloc (global_psymbols.list,
1606 (h_max + origsize) * sizeof(struct partial_symbol));
1607 global_psymbols.next = global_psymbols.list + origsize;
1608 global_psymbols.size = h_max + origsize;
1610 global_psymbols.list = (struct partial_symbol *)
1611 xmalloc (h_max * sizeof(struct partial_symbol));
1612 global_psymbols.next = global_psymbols.list;
1613 global_psymbols.size = h_max;
1616 /* Pass 1.5 over files: partition out global symbol space */
1617 s_idx = global_psymbols.next - global_psymbols.list;
1618 for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++) {
1619 fdr_to_pst[f_idx].pst->globals_offset = s_idx;
1620 s_idx += fdr_to_pst[f_idx].n_globals;
1623 /* Pass 1.6 over files: partition out static symbol space.
1624 Note that this loop starts at 0, not at -1. */
1625 stat_idx = static_psymbols.next - static_psymbols.list;
1626 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
1627 fdr_to_pst[f_idx].pst->statics_offset = stat_idx;
1628 fh = f_idx + (FDR *)(hdr->cbFdOffset);
1629 stat_idx += fh->csym;
1632 /* Now that we know its max size, allocate static symbol list */
1633 if (static_psymbols.list) {
1634 int origsize = static_psymbols.next - static_psymbols.list;
1636 static_psymbols.list = (struct partial_symbol *)
1637 xrealloc (static_psymbols.list,
1638 stat_idx * sizeof(struct partial_symbol));
1639 static_psymbols.next = static_psymbols.list + origsize;
1640 static_psymbols.size = stat_idx;
1642 static_psymbols.list = (struct partial_symbol *)
1643 xmalloc (stat_idx * sizeof(struct partial_symbol));
1644 static_psymbols.next = static_psymbols.list;
1645 static_psymbols.size = stat_idx;
1648 /* Pass 2 over external syms: fill in external symbols */
1649 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
1650 register struct partial_symbol *p;
1651 enum misc_function_type misc_type = mf_text;
1652 esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
1654 if (esh->asym.sc == scUndefined || esh->asym.sc == scNil)
1657 /* Locate the psymtab and the preallocated psymbol. */
1658 pst = fdr_to_pst[esh->ifd].pst;
1659 p = global_psymbols.list + pst->globals_offset +
1660 pst->n_global_syms++;
1661 SYMBOL_NAME(p) = (char *)(esh->asym.iss);
1662 SYMBOL_NAMESPACE(p) = VAR_NAMESPACE;
1664 switch (esh->asym.st) {
1666 SYMBOL_CLASS(p) = LOC_BLOCK;
1667 SYMBOL_VALUE(p) = esh->asym.value;
1670 SYMBOL_CLASS(p) = LOC_STATIC;
1671 SYMBOL_VALUE_ADDRESS(p) = (CORE_ADDR)esh->asym.value;
1672 misc_type = mf_data;
1675 SYMBOL_CLASS(p) = LOC_LABEL;
1676 SYMBOL_VALUE_ADDRESS(p) = (CORE_ADDR)esh->asym.value;
1679 misc_type = mf_unknown;
1680 complain (&unknown_ext_complaint, SYMBOL_NAME(p));
1682 prim_record_misc_function (SYMBOL_NAME(p),
1687 /* Pass 3 over files, over local syms: fill in static symbols */
1688 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
1689 fh = f_idx + (FDR *)(cur_hdr->cbFdOffset);
1690 pst = fdr_to_pst[f_idx].pst;
1691 pst->texthigh = pst->textlow;
1693 for (s_idx = 0; s_idx < fh->csym; ) {
1694 register struct partial_symbol *p;
1696 sh = s_idx + (SYMR *) fh->isymBase;
1698 if (sh->sc == scUndefined || sh->sc == scNil ||
1699 sh->index == 0xfffff) {
1700 /* FIXME, premature? */
1705 /* Locate the preallocated psymbol. */
1706 p = static_psymbols.list + pst->statics_offset +
1708 SYMBOL_NAME(p) = (char *)(sh->iss);
1709 SYMBOL_VALUE(p) = sh->value;
1710 SYMBOL_NAMESPACE(p) = VAR_NAMESPACE;
1713 case stProc: /* Asm labels apparently */
1714 case stStaticProc: /* Function */
1715 SYMBOL_CLASS(p) = LOC_BLOCK;
1716 pst->n_static_syms++; /* Use gdb symbol */
1717 /* Skip over procedure to next one. */
1718 s_idx = (sh->index + (AUXU *)fh->iauxBase)
1722 long procaddr = sh->value;
1724 sh = s_idx + (SYMR *) fh->isymBase - 1;
1725 if (sh->st != stEnd)
1727 high = procaddr + sh->value;
1728 if (high > pst->texthigh)
1729 pst->texthigh = high;
1732 case stStatic: /* Variable */
1733 SYMBOL_CLASS(p) = LOC_STATIC;
1734 SYMBOL_VALUE_ADDRESS(p) = (CORE_ADDR)sh->value;
1736 case stTypedef: /* Typedef */
1737 SYMBOL_CLASS(p) = LOC_TYPEDEF;
1739 case stConstant: /* Constant decl */
1740 SYMBOL_CLASS(p) = LOC_CONST;
1742 case stBlock: /* { }, str, un, enum*/
1743 if (sh->sc == scInfo) {
1744 SYMBOL_NAMESPACE(p) = STRUCT_NAMESPACE;
1745 SYMBOL_CLASS(p) = LOC_TYPEDEF;
1746 pst->n_static_syms++;
1748 /* Skip over the block */
1751 case stFile: /* File headers */
1752 case stLabel: /* Labels */
1753 case stEnd: /* Ends of files */
1756 complain (&unknown_sym_complaint, SYMBOL_NAME(p));
1757 complain (&unknown_st_complaint, sh->st);
1761 pst->n_static_syms++; /* Use this gdb symbol */
1763 s_idx++; /* Go to next file symbol */
1765 /* We don't usually record static syms, but some we seem to. chk dbxread. */
1766 /*FIXME*/ prim_record_misc_function (SYMBOL_NAME(p),
1773 /* The array (of lists) of globals must be sorted. */
1776 /* Now sort the global psymbols. */
1777 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
1778 struct partial_symtab *pst = fdr_to_pst[f_idx].pst;
1779 if (pst->n_global_syms > 1)
1780 qsort (global_psymbols.list + pst->globals_offset,
1781 pst->n_global_syms, sizeof (struct partial_symbol),
1785 /* Mark the last code address, and remember it for later */
1786 hdr->cbDnOffset = end_of_text_seg;
1788 free(&fdr_to_pst[-1]);
1793 /* Do the initial analisys of the F_IDX-th file descriptor.
1794 Allocates a partial symtab for it, and builds the list
1795 of dependent files by recursion. LEV says at which level
1796 of recursion we are called (to pretty up debug traces) */
1798 static struct partial_symtab *
1799 parse_fdr(f_idx, lev, objfile)
1802 struct objfile *objfile;
1805 register struct partial_symtab *pst;
1808 fh = (FDR *) (cur_hdr->cbFdOffset) + f_idx;
1810 /* Use this to indicate into which symtab this file was parsed */
1812 return (struct partial_symtab *) fh->ioptBase;
1814 /* Debuggability level */
1815 if (compare_glevel(max_glevel, fh->glevel) < 0)
1816 max_glevel = fh->glevel;
1818 /* Make a new partial_symtab */
1819 pst = new_psymtab(fh->rss, objfile);
1824 pst->textlow = fh->adr;
1825 pst->texthigh = fh->cpd; /* To be fixed later */
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 /* Analyze its dependencies */
1838 if (fh->cpd == 0) { /* If there are no functions defined here ... */
1839 /* ...then presumably a .h file: drop reverse depends .h->.c */
1840 for (; s_id0 < fh->crfd; s_id0++) {
1841 RFDT *rh = (RFDT *) (fh->rfdBase) + s_id0;
1843 s_id0++; /* Skip self-dependency */
1848 pst->number_of_dependencies = fh->crfd - s_id0;
1849 pst->dependencies = (struct partial_symtab **)
1850 obstack_alloc (psymbol_obstack,
1851 pst->number_of_dependencies *
1852 sizeof (struct partial_symtab *));
1853 for (s_idx = s_id0; s_idx < fh->crfd; s_idx++) {
1854 RFDT *rh = (RFDT *) (fh->rfdBase) + s_idx;
1856 pst->dependencies[s_idx-s_id0] = parse_fdr(*rh, lev+1, objfile);
1863 /* Ancillary function to psymtab_to_symtab(). Does all the work
1864 for turning the partial symtab PST into a symtab, recurring
1865 first on all dependent psymtabs. The argument FILENAME is
1866 only passed so we can see in debug stack traces what file
1870 psymtab_to_symtab_1(pst, filename)
1871 struct partial_symtab *pst;
1882 pending_list = (struct pending **) cur_hdr->cbOptOffset;
1883 if (pending_list == 0) {
1884 pending_list = (struct pending **)
1885 xzalloc(cur_hdr->ifdMax * sizeof(struct pending *));
1886 cur_hdr->cbOptOffset = (int)pending_list;
1889 /* How many symbols will we need */
1890 /* FIXME, this does not count enum values. */
1891 f_max = pst->n_global_syms + pst->n_static_syms;
1892 if (FDR_IDX(pst) == -1) {
1894 st = new_symtab ("unknown", f_max, 0, pst->objfile);
1896 fh = (FDR *) (cur_hdr->cbFdOffset) + FDR_IDX(pst);
1897 f_max += fh->csym + fh->cpd;
1898 st = new_symtab (pst->filename, 2 * f_max, 2 * fh->cline,
1902 /* Read in all partial symbtabs on which this one is dependent.
1903 NOTE that we do have circular dependencies, sigh. We solved
1904 that by setting pst->readin before this point. */
1906 for (i = 0; i < pst->number_of_dependencies; i++)
1907 if (!pst->dependencies[i]->readin) {
1908 /* Inform about additional files to be read in. */
1911 fputs_filtered (" ", stdout);
1913 fputs_filtered ("and ", stdout);
1915 printf_filtered ("%s...",
1916 pst->dependencies[i]->filename);
1917 wrap_here (""); /* Flush output */
1920 /* We only pass the filename for debug purposes */
1921 psymtab_to_symtab_1(pst->dependencies[i],
1922 pst->dependencies[i]->filename);
1925 /* Now read the symbols for this symtab */
1927 cur_fd = FDR_IDX(pst);
1931 /* Get a new lexical context */
1934 top_stack->cur_st = cur_stab;
1935 top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab),
1937 BLOCK_START(top_stack->cur_block) = fh ? fh->adr : 0;
1938 BLOCK_END(top_stack->cur_block) = 0;
1939 top_stack->blocktype = stFile;
1940 top_stack->maxsyms = 2*f_max;
1941 top_stack->cur_type = 0;
1942 top_stack->procadr = 0;
1943 top_stack->numargs = 0;
1945 /* Parse locals and procedures */
1947 parse_one_file(fh, cur_fd, (cur_fd == (cur_hdr->ifdMax - 1)) ?
1948 cur_hdr->cbDnOffset : fh[1].adr);
1950 /* .. and our share of externals.
1951 XXX use the global list to speed up things here. how ?
1952 FIXME, Maybe quit once we have found the right number of ext's? */
1953 /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
1954 top_stack->blocktype = stFile;
1955 top_stack->maxsyms = cur_hdr->isymMax + cur_hdr->ipdMax + cur_hdr->iextMax;
1956 for (i = 0; i < cur_hdr->iextMax; i++) {
1957 register EXTR *esh = (EXTR *) (cur_hdr->cbExtOffset) + i;
1958 if (esh->ifd == cur_fd)
1959 parse_external(esh, 1);
1962 /* If there are undefined, tell the user */
1963 if (n_undef_symbols) {
1964 printf_filtered("File %s contains %d unresolved references:",
1965 st->filename, n_undef_symbols);
1966 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
1967 n_undef_vars, n_undef_procs, n_undef_labels);
1968 n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
1974 * Sort the symbol table now, we are done adding symbols to it.
1976 sort_symtab_syms(st);
1978 /* Now link the psymtab and the symtab. */
1982 /* Ancillary parsing procedures. */
1984 /* Lookup the type at relative index RN. Return it in TPP
1985 if found and in any event come up with its name PNAME.
1986 Return value says how many aux symbols we ate */
1989 cross_ref(rn, tpp, pname)
1996 /* Escape index means 'the next one' */
1997 if (rn->rfd == 0xfff)
1998 rf = *(unsigned *) (rn + 1);
2004 *pname = "<undefined>";
2007 * Find the relative file descriptor and the symbol in it
2009 FDR *fh = get_rfd(cur_fd, rf);
2014 * If we have processed this symbol then we left a forwarding
2015 * pointer to the corresponding GDB symbol. If not, we`ll put
2016 * it in a list of pending symbols, to be processed later when
2017 * the file f will be. In any event, we collect the name for
2018 * the type here. Which is why we made a first pass at
2021 sh = (SYMR *) (fh->isymBase) + rn->index;
2023 /* Careful, we might be looking at .o files */
2024 *pname = (UNSAFE_DATA_ADDR(sh->iss)) ? "<undefined>" :
2027 /* Have we parsed it ? */
2028 if ((!UNSAFE_DATA_ADDR(sh->value)) && (sh->st == stParsed)) {
2029 t = (struct type *) sh->value;
2034 /* Avoid duplicates */
2035 p = is_pending_symbol(fh, sh);
2040 add_pending(fh, sh, *tpp);
2044 /* We used one auxent normally, two if we got a "next one" rf. */
2045 return (rn->rfd == 0xfff? 2: 1);
2049 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2050 keeping the symtab sorted */
2052 static struct symbol *
2053 mylookup_symbol (name, block, namespace, class)
2055 register struct block *block;
2056 enum namespace namespace;
2057 enum address_class class;
2059 register int bot, top, inc;
2060 register struct symbol *sym;
2063 top = BLOCK_NSYMS(block);
2066 sym = BLOCK_SYM(block, bot);
2067 if (SYMBOL_NAME(sym)[0] == inc
2068 && SYMBOL_NAMESPACE(sym) == namespace
2069 && SYMBOL_CLASS(sym) == class
2070 && !strcmp(SYMBOL_NAME(sym), name))
2074 if (block = BLOCK_SUPERBLOCK (block))
2075 return mylookup_symbol (name, block, namespace, class);
2080 /* Add a new symbol S to a block B.
2081 Infrequently, we will need to reallocate the block to make it bigger.
2082 We only detect this case when adding to top_stack->cur_block, since
2083 that's the only time we know how big the block is. FIXME. */
2090 int nsyms = BLOCK_NSYMS(b)++;
2091 struct block *origb;
2092 struct parse_stack *stackp;
2094 if (b == top_stack->cur_block &&
2095 nsyms >= top_stack->maxsyms) {
2096 complain (&block_overflow_complaint, s->name);
2097 /* In this case shrink_block is actually grow_block, since
2098 BLOCK_NSYMS(b) is larger than its current size. */
2100 b = shrink_block (top_stack->cur_block, top_stack->cur_st);
2102 /* Now run through the stack replacing pointers to the
2103 original block. shrink_block has already done this
2104 for the blockvector and BLOCK_FUNCTION. */
2105 for (stackp = top_stack; stackp; stackp = stackp->next) {
2106 if (stackp->cur_block == origb) {
2107 stackp->cur_block = b;
2108 stackp->maxsyms = BLOCK_NSYMS (b);
2112 BLOCK_SYM(b,nsyms) = s;
2115 /* Add a new block B to a symtab S */
2122 struct blockvector *bv = BLOCKVECTOR(s);
2124 bv = (struct blockvector *)xrealloc(bv, sizeof(struct blockvector) +
2125 BLOCKVECTOR_NBLOCKS(bv) * sizeof(bv->block));
2126 if (bv != BLOCKVECTOR(s))
2127 BLOCKVECTOR(s) = bv;
2129 BLOCKVECTOR_BLOCK(bv, BLOCKVECTOR_NBLOCKS(bv)++) = b;
2132 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2133 MIPS' linenumber encoding might need more than one byte
2134 to describe it, LAST is used to detect these continuation lines */
2137 add_line(lt, lineno, adr, last)
2138 struct linetable *lt;
2144 last = -2; /* make sure we record first line */
2146 if (last == lineno) /* skip continuation lines */
2149 lt->item[lt->nitems].line = lineno;
2150 lt->item[lt->nitems++].pc = adr << 2;
2156 /* Comparison functions, used when sorting things */
2158 /* Symtabs must be ordered viz the code segments they cover */
2161 compare_symtabs( s1, s2)
2162 struct symtab **s1, **s2;
2164 /* "most specific" first */
2166 register struct block *b1, *b2;
2167 b1 = BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1),GLOBAL_BLOCK);
2168 b2 = BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2),GLOBAL_BLOCK);
2169 if (BLOCK_END(b1) == BLOCK_END(b2))
2170 return BLOCK_START(b1) - BLOCK_START(b2);
2171 return BLOCK_END(b1) - BLOCK_END(b2);
2175 /* Partial Symtabs, same */
2178 compare_psymtabs( s1, s2)
2179 struct partial_symtab **s1, **s2;
2181 /* Perf twist: put the ones with no code at the end */
2183 register int a = (*s1)->textlow;
2184 register int b = (*s2)->textlow;
2193 /* Partial symbols are compared lexicog by their print names */
2196 compare_psymbols (s1, s2)
2197 register struct partial_symbol *s1, *s2;
2200 *st1 = SYMBOL_NAME(s1),
2201 *st2 = SYMBOL_NAME(s2);
2203 return (st1[0] - st2[0] ? st1[0] - st2[0] :
2204 strcmp(st1 + 1, st2 + 1));
2207 /* Blocks with a smaller low bound should come first */
2209 static int compare_blocks(b1,b2)
2210 struct block **b1, **b2;
2212 register int addr_diff;
2214 addr_diff = (BLOCK_START((*b1))) - (BLOCK_START((*b2)));
2216 return (BLOCK_END((*b1))) - (BLOCK_END((*b2)));
2221 /* Sorting and reordering procedures */
2223 /* Sort the blocks of a symtab S.
2224 Reorder the blocks in the blockvector by code-address,
2225 as required by some MI search routines */
2231 struct blockvector *bv = BLOCKVECTOR(s);
2233 if (BLOCKVECTOR_NBLOCKS(bv) <= 2) {
2235 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) == 0)
2236 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = 0;
2237 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) == 0)
2238 BLOCK_START(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) = 0;
2242 * This is very unfortunate: normally all functions are compiled in
2243 * the order they are found, but if the file is compiled -O3 things
2244 * are very different. It would be nice to find a reliable test
2245 * to detect -O3 images in advance.
2247 if (BLOCKVECTOR_NBLOCKS(bv) > 3)
2248 qsort(&BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK),
2249 BLOCKVECTOR_NBLOCKS(bv) - FIRST_LOCAL_BLOCK,
2250 sizeof(struct block *),
2254 register CORE_ADDR high = 0;
2255 register int i, j = BLOCKVECTOR_NBLOCKS(bv);
2257 for (i = FIRST_LOCAL_BLOCK; i < j; i++)
2258 if (high < BLOCK_END(BLOCKVECTOR_BLOCK(bv,i)))
2259 high = BLOCK_END(BLOCKVECTOR_BLOCK(bv,i));
2260 BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = high;
2263 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) =
2264 BLOCK_START(BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK));
2266 BLOCK_START(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) =
2267 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK));
2268 BLOCK_END (BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) =
2269 BLOCK_END (BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK));
2272 /* Sort the symtab list, as required by some search procedures.
2273 We want files ordered to make them look right to users, and for
2274 searching (see block_for_pc). */
2280 struct symtab *stab;
2281 register struct symtab **all_symtabs;
2282 register int symtab_count;
2287 /* Create an array of pointers to all the symtabs. */
2288 for (symtab_count = 0, stab = symtab_list;
2290 symtab_count++, stab = stab->next) {
2291 obstack_grow (psymbol_obstack, &stab, sizeof (stab));
2292 /* FIXME: Only sort blocks for new symtabs ??? */
2296 all_symtabs = (struct symtab **)
2297 obstack_base (psymbol_obstack);
2298 qsort((char *)all_symtabs, symtab_count,
2299 sizeof(struct symtab *), compare_symtabs);
2301 /* Re-construct the symtab list, but now it is sorted. */
2302 for (i = 0; i < symtab_count-1; i++)
2303 all_symtabs[i]->next = all_symtabs[i+1];
2304 all_symtabs[i]->next = 0;
2305 symtab_list = all_symtabs[0];
2307 obstack_free (psymbol_obstack, all_symtabs);
2310 /* Sort the partial symtab list, as required by some search procedures.
2311 PC lookups stop at the first psymtab such that textlow <= PC < texthigh */
2317 register int all_psymtabs_count;
2318 struct partial_symtab *pstab;
2319 struct partial_symtab **all_psymtabs;
2321 if (!partial_symtab_list)
2324 /* Create an array of pointers to all the partial_symtabs. */
2326 for (all_psymtabs_count = 0, pstab = partial_symtab_list;
2328 all_psymtabs_count++, pstab = pstab->next)
2329 obstack_grow (psymbol_obstack, &pstab, sizeof (pstab));
2331 all_psymtabs = (struct partial_symtab **)
2332 obstack_base (psymbol_obstack);
2334 qsort((char *)all_psymtabs, all_psymtabs_count,
2335 sizeof(struct partial_symtab *), compare_psymtabs);
2337 /* Re-construct the partial_symtab_list, but now it is sorted. */
2339 for (i = 0; i < all_psymtabs_count-1; i++)
2340 all_psymtabs[i]->next = all_psymtabs[i+1];
2341 all_psymtabs[i]->next = 0;
2342 partial_symtab_list = all_psymtabs[0];
2344 obstack_free (psymbol_obstack, all_psymtabs);
2347 /* Constructor/restructor/destructor procedures */
2349 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2350 MAXSYMS and linenumbers MAXLINES we'll put in it */
2354 new_symtab(name, maxsyms, maxlines, objfile)
2357 struct symtab *s = allocate_symtab (name, objfile);
2359 LINETABLE(s) = new_linetable(maxlines);
2361 /* All symtabs must have at least two blocks */
2362 BLOCKVECTOR(s) = new_bvect(2);
2363 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK) = new_block(maxsyms);
2364 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), STATIC_BLOCK) = new_block(maxsyms);
2365 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s),STATIC_BLOCK)) =
2366 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK);
2368 s->free_code = free_linetable;
2370 /* Link the new symtab into the list of such. */
2371 s->next = symtab_list;
2377 /* Allocate a new partial_symtab NAME */
2379 static struct partial_symtab *
2380 new_psymtab(name, objfile)
2382 struct objfile *objfile;
2384 struct partial_symtab *pst;
2386 pst = (struct partial_symtab *)
2387 obstack_alloc (psymbol_obstack, sizeof (*pst));
2388 bzero (pst, sizeof (*pst));
2390 if (name == (char*)-1) /* FIXME -- why not null here? */
2391 pst->filename = "<no name>";
2393 pst->filename = name;
2395 /* Chain it to its object file */
2396 pst->objfile = objfile;
2397 pst->objfile_chain = objfile->psymtabs;
2398 objfile->psymtabs = pst;
2400 pst->next = partial_symtab_list;
2401 partial_symtab_list = pst;
2403 /* Keep a backpointer to the file's symbols */
2404 pst->read_symtab_private = (char *) obstack_alloc (psymbol_obstack,
2405 sizeof (struct symloc));
2406 CUR_HDR(pst) = cur_hdr;
2408 /* The way to turn this into a symtab is to call... */
2409 pst->read_symtab = mipscoff_psymtab_to_symtab;
2415 /* Allocate a linetable array of the given SIZE */
2418 struct linetable *new_linetable(size)
2420 struct linetable *l;
2422 size = size * sizeof(l->item) + sizeof(struct linetable);
2423 l = (struct linetable *)xmalloc(size);
2428 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2429 I am not so sure about the 3.4 ones */
2435 struct linetable *l = new_linetable(LINETABLE(s)->nitems);
2437 bcopy(LINETABLE(s), l,
2438 LINETABLE(s)->nitems * sizeof(l->item) + sizeof(struct linetable));
2439 free (LINETABLE(s));
2443 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2446 struct blockvector *
2449 struct blockvector *bv;
2452 size = sizeof(struct blockvector) + nblocks * sizeof(struct block*);
2453 bv = (struct blockvector *) xzalloc(size);
2455 BLOCKVECTOR_NBLOCKS(bv) = nblocks;
2460 /* Allocate and zero a new block of MAXSYMS symbols */
2466 int size = sizeof(struct block) + (maxsyms-1) * sizeof(struct symbol *);
2467 struct block *b = (struct block *)xzalloc(size);
2472 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2473 Shrink_block can also be used by add_symbol to grow a block. */
2475 static struct block *
2481 struct blockvector *bv = BLOCKVECTOR(s);
2484 /* Just reallocate it and fix references to the old one */
2486 new = (struct block *) xrealloc ((char *)b, sizeof(struct block) +
2487 (BLOCK_NSYMS(b)-1) * sizeof(struct symbol *));
2489 /* Should chase pointers to old one. Fortunately, that`s just
2490 the block`s function and inferior blocks */
2491 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b)
2492 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2493 for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++)
2494 if (BLOCKVECTOR_BLOCK(bv,i) == b)
2495 BLOCKVECTOR_BLOCK(bv,i) = new;
2496 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) == b)
2497 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) = new;
2501 /* Create a new symbol with printname NAME */
2508 struct symbol *s = (struct symbol *)
2509 obstack_alloc (symbol_obstack, sizeof (struct symbol));
2511 bzero (s, sizeof (*s));
2512 SYMBOL_NAME(s) = name;
2516 /* Create a new type with printname NAME */
2523 struct type *t = (struct type *)
2524 obstack_alloc (symbol_obstack, sizeof (struct type));
2526 bzero (t, sizeof (*t));
2527 TYPE_VPTR_FIELDNO (t) = -1;
2528 TYPE_NAME(t) = name;
2532 /* Create and initialize a new type with printname NAME.
2533 CODE and LENGTH are the initial info we put in,
2534 UNS says whether the type is unsigned or not. */
2538 make_type(code, length, uns, name)
2539 enum type_code code;
2543 register struct type *type;
2545 /* FIXME, I don't think this ever gets freed. */
2546 type = (struct type *) xzalloc(sizeof(struct type));
2547 TYPE_CODE(type) = code;
2548 TYPE_LENGTH(type) = length;
2549 TYPE_FLAGS(type) = uns ? TYPE_FLAG_UNSIGNED : 0;
2550 TYPE_NAME(type) = name;
2551 TYPE_VPTR_FIELDNO (type) = -1;
2556 /* Create and initialize a new struct or union type, a la make_type. */
2560 make_struct_type(code, length, uns, name)
2561 enum type_code code;
2565 register struct type *type;
2567 type = make_type (code, length, uns, name);
2569 /* FIXME, I don't think this ever gets freed. */
2570 TYPE_CPLUS_SPECIFIC (type) = (struct cplus_struct_type *)
2571 xzalloc (sizeof (struct cplus_struct_type));
2575 /* Allocate a new field named NAME to the type TYPE */
2579 new_field(type,name)
2585 /* Fields are kept in an array */
2586 if (TYPE_NFIELDS(type))
2587 TYPE_FIELDS(type) = (struct field*)xrealloc(TYPE_FIELDS(type),
2588 (TYPE_NFIELDS(type)+1) * sizeof(struct field));
2590 TYPE_FIELDS(type) = (struct field*)xzalloc(sizeof(struct field));
2591 f = &(TYPE_FIELD(type,TYPE_NFIELDS(type)));
2592 TYPE_NFIELDS(type)++;
2593 bzero(f, sizeof(struct field));
2594 f->name = name; /* Whether or not NAME is zero, this works. */
2598 /* Make an enum constant for a member F of an enumerated type T */
2601 make_enum_constant(f,t)
2607 * This is awful, but that`s the way it is supposed to be
2608 * (BTW, no need to free the real 'type', it's a builtin)
2610 f->type = (struct type *) f->bitpos;
2612 s = new_symbol(f->name);
2613 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
2614 SYMBOL_CLASS(s) = LOC_CONST;
2616 SYMBOL_VALUE(s) = f->bitpos;
2617 add_symbol(s, top_stack->cur_block);
2622 /* Things used for calling functions in the inferior.
2623 These functions are exported to our companion
2624 mips-dep.c file and are here because they play
2625 with the symbol-table explicitly. */
2628 /* Need to make a new symbol on the fly for the dummy
2629 frame we put on the stack. Which goes in the.. */
2631 static struct symtab *dummy_symtab;
2633 /* Make up a dummy symbol for the code we put at END_PC,
2634 of size SIZE, invoking a function with NARGS arguments
2635 and using a frame of FRAMESIZE bytes */
2637 mips_create_dummy_symbol(end_pc, size, nargs, framesize)
2641 struct mips_extra_func_info *gdbinfo;
2643 /* Allocate symtab if not done already */
2644 if (dummy_symtab == 0)
2645 dummy_symtab = new_symtab(".dummy_symtab.", 100, 0);
2647 /* Make a new block. Only needs one symbol */
2649 BLOCK_START(bl) = end_pc - size;
2650 BLOCK_END(bl) = end_pc;
2652 BLOCK_SUPERBLOCK(bl) =
2653 BLOCKVECTOR_BLOCK(BLOCKVECTOR(dummy_symtab),GLOBAL_BLOCK);
2654 add_block(bl, dummy_symtab);
2655 sort_blocks(dummy_symtab);
2657 BLOCK_FUNCTION(bl) = new_symbol("??");
2658 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(bl)) = bl;
2659 g = new_symbol(".gdbinfo.");
2660 BLOCK_SYM(bl,BLOCK_NSYMS(bl)++) = g;
2662 SYMBOL_NAMESPACE(g) = LABEL_NAMESPACE;
2663 SYMBOL_CLASS(g) = LOC_CONST;
2664 SYMBOL_TYPE(g) = builtin_type_void;
2665 gdbinfo = (struct mips_extra_func_info *)
2666 xzalloc(sizeof(struct mips_extra_func_info));
2668 SYMBOL_VALUE(g) = (long) gdbinfo;
2670 gdbinfo->numargs = nargs;
2671 gdbinfo->framesize = framesize;
2672 gdbinfo->framereg = 29;
2673 gdbinfo->pcreg = 31;
2674 gdbinfo->regmask = -2;
2675 gdbinfo->regoffset = -4;
2676 gdbinfo->fregmask = 0; /* XXX */
2677 gdbinfo->fregoffset = 0; /* XXX */
2680 /* We just returned from the dummy code at END_PC, drop its symbol */
2682 mips_destroy_dummy_symbol(end_pc)
2685 struct blockvector *bv = BLOCKVECTOR(dummy_symtab);
2688 bl = block_for_pc(end_pc);
2689 free(BLOCK_FUNCTION(bl));
2690 free(SYMBOL_VALUE(BLOCK_SYM(bl,0)));
2691 free(BLOCK_SYM(bl,0));
2693 for (i = FIRST_LOCAL_BLOCK; i < BLOCKVECTOR_NBLOCKS(bv); i++)
2694 if (BLOCKVECTOR_BLOCK(bv,i) == bl)
2696 for (; i < BLOCKVECTOR_NBLOCKS(bv) - 1; i++)
2697 BLOCKVECTOR_BLOCK(bv,i) = BLOCKVECTOR_BLOCK(bv,i+1);
2698 BLOCKVECTOR_NBLOCKS(bv)--;
2699 sort_blocks(dummy_symtab);
2704 /* Sigtramp: make sure we have all the necessary information
2705 about the signal trampoline code. Since the official code
2706 from MIPS does not do so, we make up that information ourselves.
2707 If they fix the library (unlikely) this code will neutralize itself. */
2714 struct block *b, *b0;
2716 sigtramp_address = -1;
2718 /* We know it is sold as sigvec */
2719 s = lookup_symbol("sigvec", 0, VAR_NAMESPACE, 0, NULL);
2721 /* Most programs do not play with signals */
2725 b0 = SYMBOL_BLOCK_VALUE(s);
2727 /* A label of sigvec, to be more precise */
2728 s = lookup_symbol("sigtramp", b0, VAR_NAMESPACE, 0, NULL);
2730 /* But maybe this program uses its own version of sigvec */
2734 sigtramp_address = SYMBOL_VALUE(s);
2735 sigtramp_end = sigtramp_address + 0x88; /* black magic */
2737 /* Did we or MIPSco fix the library ? */
2738 if (SYMBOL_CLASS(s) == LOC_BLOCK)
2741 /* But what symtab does it live in ? */
2742 st = find_pc_symtab(SYMBOL_VALUE(s));
2745 * Ok, there goes the fix: turn it into a procedure, with all the
2746 * needed info. Note we make it a nested procedure of sigvec,
2747 * which is the way the (assembly) code is actually written.
2749 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
2750 SYMBOL_CLASS(s) = LOC_BLOCK;
2751 SYMBOL_TYPE(s) = make_type(TYPE_CODE_FUNC, 4, 0, 0);
2752 TYPE_TARGET_TYPE(SYMBOL_TYPE(s)) = builtin_type_void;
2754 /* Need a block to allocate .gdbinfo. in */
2756 SYMBOL_BLOCK_VALUE(s) = b;
2757 BLOCK_START(b) = sigtramp_address;
2758 BLOCK_END(b) = sigtramp_end;
2759 BLOCK_FUNCTION(b) = s;
2760 BLOCK_SUPERBLOCK(b) = BLOCK_SUPERBLOCK(b0);
2764 /* Make a .gdbinfo. for it */
2766 struct mips_extra_func_info *e =
2767 (struct mips_extra_func_info *)
2768 xzalloc(sizeof(struct mips_extra_func_info));
2770 e->numargs = 0; /* the kernel thinks otherwise */
2771 /* align_longword(sigcontext + SIGFRAME) */
2772 e->framesize = 0x150;
2773 e->framereg = SP_REGNUM;
2776 e->regoffset = -(41 * sizeof(int));
2778 e->fregoffset = -(37 * sizeof(int));
2781 s = new_symbol(".gdbinfo.");
2782 SYMBOL_VALUE(s) = (int) e;
2783 SYMBOL_NAMESPACE(s) = LABEL_NAMESPACE;
2784 SYMBOL_CLASS(s) = LOC_CONST;
2785 SYMBOL_TYPE(s) = builtin_type_void;
2788 BLOCK_SYM(b,BLOCK_NSYMS(b)++) = s;
2791 /* Initialization */
2793 static struct sym_fns ecoff_sym_fns = {"ecoff", 5,
2794 mipscoff_new_init, mipscoff_symfile_init,
2795 mipscoff_symfile_read};
2797 _initialize_mipsread ()
2799 add_symtab_fns (&ecoff_sym_fns);
2801 /* Missing basic types */
2802 builtin_type_string = make_type(TYPE_CODE_PASCAL_ARRAY,
2804 builtin_type_complex = make_type(TYPE_CODE_FLT,
2805 2 * sizeof(float), 0, "complex");
2806 builtin_type_double_complex = make_type(TYPE_CODE_FLT,
2807 2 * sizeof(double), 0, "double_complex");
2808 builtin_type_fixed_dec = make_type(TYPE_CODE_INT, sizeof(int),
2809 0, "fixed_decimal");
2810 builtin_type_float_dec = make_type(TYPE_CODE_FLT, sizeof(double),
2811 0, "floating_decimal");