1 /* Read a symbol table in MIPS' format (Third-Eye).
2 Copyright (C) 1986, 1987, 1989-1991 Free Software Foundation, Inc.
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;
166 static struct type *builtin_type_ptr;
167 static struct type *builtin_type_struct;
168 static struct type *builtin_type_union;
169 static struct type *builtin_type_enum;
170 static struct type *builtin_type_range;
171 static struct type *builtin_type_set;
173 /* Forward declarations */
175 static struct symbol *new_symbol();
176 static struct type *new_type();
177 static struct field *new_field();
178 static struct block *new_block();
179 static struct symtab *new_symtab();
180 static struct linetable *new_linetable();
181 static struct blockvector *new_bvect();
183 static struct type *parse_type();
184 static struct type *make_type();
185 static struct symbol *mylookup_symbol();
186 static struct block *shrink_block();
188 static int compare_symtabs();
189 static int compare_psymtabs();
190 static int compare_blocks();
192 static struct partial_symtab *new_psymtab();
193 static struct partial_symtab *parse_fdr();
194 static int compare_psymbols();
196 static void psymtab_to_symtab_1();
197 static void add_block();
198 static void add_symbol();
199 static int add_line();
200 static void reorder_symtabs();
201 static void reorder_psymtabs();
202 static void shrink_linetable();
204 /* Things we export to other modules */
206 /* Address bounds for the signal trampoline in inferior, if any */
207 /* FIXME: Nothing really seems to use this. Why is it here? */
209 CORE_ADDR sigtramp_address, sigtramp_end;
211 /* The entry point (starting address) of the file, if it is an executable. */
213 extern CORE_ADDR startup_file_start; /* From blockframe.c */
214 extern CORE_ADDR startup_file_end; /* From blockframe.c */
219 /* If we have a file symbol header lying around, blow it away. */
221 free ((char *)cur_hdr);
226 mipscoff_symfile_init (sf)
229 sf->sym_private = NULL;
233 mipscoff_symfile_read(sf, addr, mainline)
238 struct coff_symfile_info *info = (struct coff_symfile_info *)sf->sym_private;
239 bfd *abfd = sf->objfile->obfd;
240 char *name = bfd_get_filename (abfd);
244 int stringtab_offset;
246 /* Initialize a variable that we couldn't do at _initialize_ time. */
247 builtin_type_ptr = lookup_pointer_type (builtin_type_void);
249 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
250 desc = fileno ((FILE *)(abfd->iostream)); /* Raw file descriptor */
253 /* Position to read the symbol table. */
254 val = lseek (desc, (long)symtab_offset, 0);
256 perror_with_name (name);
258 init_misc_bunches ();
259 make_cleanup (discard_misc_bunches, 0);
261 /* Now that the executable file is positioned at symbol table,
262 process it and define symbols accordingly. */
264 read_mips_symtab(sf->objfile, desc);
266 /* Go over the misc symbol bunches and install them in vector. */
268 condense_misc_bunches (!mainline);
271 /* Exported procedure: Allocate zeroed memory */
276 char *p = xmalloc(size);
282 /* Exported procedure: Builds a symtab from the PST partial one.
283 Restores the environment in effect when PST was created, delegates
284 most of the work to an ancillary procedure, and sorts
285 and reorders the symtab list at the end */
288 mipscoff_psymtab_to_symtab(pst)
289 struct partial_symtab *pst;
298 printf_filtered("Reading in symbols for %s...", pst->filename);
301 /* Restore the header and list of pending typedefs */
302 cur_hdr = CUR_HDR(pst);
304 psymtab_to_symtab_1(pst, pst->filename);
309 printf_filtered("done.\n");
312 /* Exported procedure: Is PC in the signal trampoline code */
315 in_sigtramp(pc, name)
319 if (sigtramp_address == 0)
321 return (pc >= sigtramp_address && pc < sigtramp_end);
324 /* File-level interface functions */
326 /* Read the symtab information from file FSYM into memory. Also,
327 return address just past end of our text segment in *END_OF_TEXT_SEGP. */
330 read_the_mips_symtab(abfd, fsym, end_of_text_segp)
333 CORE_ADDR *end_of_text_segp;
335 int stsize, st_hdrsize;
338 /* Header for executable/object file we read symbols from */
339 struct coff_exec filhdr;
341 /* We get here with DESC pointing to the symtab header. But we need
342 * other info from the initial headers */
344 myread(fsym, &filhdr, sizeof filhdr);
346 if (end_of_text_segp)
348 bfd_h_get_32 (abfd, filhdr.a.text_start) +
349 bfd_h_get_32 (abfd, filhdr.a.tsize);
351 /* Find and read the symbol table header */
352 st_hdrsize = bfd_h_get_32 (abfd, filhdr.f.f_nsyms);
353 st_filptr = bfd_h_get_32 (abfd, filhdr.f.f_symptr);
357 lseek(fsym, st_filptr, L_SET);
358 if (st_hdrsize > sizeof (st_hdr)) /* Profanity check */
360 if (read(fsym, &st_hdr, st_hdrsize) != st_hdrsize)
363 /* Find out how large the symbol table is */
364 stsize = (st_hdr.cbExtOffset - (st_filptr + st_hdrsize))
365 + st_hdr.iextMax * cbEXTR;
367 /* Allocate space for the symbol table. Read it in. */
368 cur_hdr = (HDRR *) xmalloc(stsize + st_hdrsize);
370 bcopy(&st_hdr, cur_hdr, st_hdrsize);
371 if (read(fsym, (char *) cur_hdr + st_hdrsize, stsize) != stsize)
374 /* Fixup file_pointers in it */
375 fixup_symtab(cur_hdr, (char *) cur_hdr + st_hdrsize,
376 st_filptr + st_hdrsize);
380 error("Short read on %s", bfd_get_filename (abfd));
384 /* Turn all file-relative pointers in the symtab described by HDR
385 into memory pointers, given that the symtab itself is located
386 at DATA in memory and F_PTR in the file. */
389 fixup_symtab( hdr, data, f_ptr)
401 * These fields are useless (and empty) by now:
402 * hdr->cbDnOffset, hdr->cbOptOffset
403 * We use them for other internal purposes.
406 hdr->cbOptOffset = 0;
409 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
425 * Fix all string pointers inside the symtab, and
426 * the FDR records. Also fix other miscellany.
428 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
429 register unsigned code_offset;
431 /* Header itself, and strings */
432 fh = (FDR *) (hdr->cbFdOffset) + f_idx;
433 fh->issBase += hdr->cbSsOffset;
435 fh->rss = (long)fh->rss + fh->issBase;
436 for (s_idx = 0; s_idx < fh->csym; s_idx++) {
437 sh = (SYMR*)(hdr->cbSymOffset) + fh->isymBase + s_idx;
438 sh->iss = (long) sh->iss + fh->issBase;
445 fh->isymBase = (int)((SYMR*)(hdr->cbSymOffset)+fh->isymBase);
447 /* cannot fix fh->ipdFirst because it is a short */
448 #define IPDFIRST(h,fh) \
449 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
451 /* Optional symbols (actually used for partial_symtabs) */
457 fh->iauxBase = hdr->cbAuxOffset + fh->iauxBase * sizeof(AUXU);
458 /* Relative file descriptor table */
459 fh->rfdBase = hdr->cbRfdOffset + fh->rfdBase * sizeof(RFDT);
463 fh->cbLineOffset += hdr->cbLineOffset;
465 /* Procedure symbols. (XXX This should be done later) */
466 code_offset = fh->adr;
467 for (s_idx = 0; s_idx < fh->cpd; s_idx++) {
468 unsigned name, only_ext;
470 pr = (PDR*)(IPDFIRST(hdr,fh)) + s_idx;
472 /* Simple rule to find files linked "-x" */
473 only_ext = fh->rss == -1;
475 if (pr->isym == -1) {
476 /* static function */
480 name = hdr->cbExtOffset + pr->isym * sizeof(EXTR);
481 sh = &((EXTR*)name)->asym;
485 sh = (SYMR*)fh->isymBase + pr->isym;
486 /* Included code ? */
487 if (s_idx == 0 && pr->adr != 0)
488 code_offset -= pr->adr;
491 /* Turn index into a pointer */
494 /* Fix line numbers */
495 pr->cbLineOffset += fh->cbLineOffset;
497 /* Relocate address */
499 pr->adr += code_offset;
503 /* External symbols: fix string */
504 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
505 esh = (EXTR*)(hdr->cbExtOffset) + s_idx;
506 esh->asym.iss = esh->asym.iss + hdr->cbSsExtOffset;
511 /* Find a file descriptor given its index RF relative to a file CF */
519 f = (FDR *) (cur_hdr->cbFdOffset) + cf;
520 /* Object files do not have the RFD table, all refs are absolute */
522 return (FDR *) (cur_hdr->cbFdOffset) + rf;
523 cf = *((pRFDT) f->rfdBase + rf);
524 return (FDR *) (cur_hdr->cbFdOffset) + cf;
527 /* Return a safer print NAME for a file descriptor */
533 if (name == (char *) -1)
534 return "<stripped file>";
535 if (UNSAFE_DATA_ADDR(name))
541 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
542 whether we are adding to the general symtab or not.
543 FIXME: INCREMENTAL is currently always zero, though it should not be. */
546 read_mips_symtab (objfile, desc)
547 struct objfile *objfile;
550 CORE_ADDR end_of_text_seg;
552 read_the_mips_symtab(objfile->obfd, desc, &end_of_text_seg);
554 parse_partial_symbols(end_of_text_seg, objfile);
557 * Check to make sure file was compiled with -g.
558 * If not, warn the user of this limitation.
560 if (compare_glevel(max_glevel, GLEVEL_2) < 0) {
561 if (max_gdbinfo == 0)
563 "\n%s not compiled with -g, debugging support is limited.\n",
566 "You should compile with -g2 or -g3 for best debugging support.\n");
571 /* Local utilities */
573 /* Map of FDR indexes to partial symtabs */
575 static struct pst_map {
576 struct partial_symtab *pst; /* the psymtab proper */
577 int n_globals; /* globals it exports */
578 int n_statics; /* statics (locals) it contains */
582 /* Utility stack, used to nest procedures and blocks properly.
583 It is a doubly linked list, to avoid too many alloc/free.
584 Since we might need it quite a few times it is NOT deallocated
587 static struct parse_stack {
588 struct parse_stack *next, *prev;
589 struct symtab *cur_st; /* Current symtab */
590 struct block *cur_block; /* Block in it */
591 int blocktype; /* What are we parsing */
592 int maxsyms; /* Max symbols in this block */
593 struct type *cur_type; /* Type we parse fields for */
594 int procadr; /* Start addres of this procedure */
595 int numargs; /* Its argument count */
596 } *top_stack; /* Top stack ptr */
599 /* Enter a new lexical context */
601 static push_parse_stack()
603 struct parse_stack *new;
605 /* Reuse frames if possible */
606 if (top_stack && top_stack->prev)
607 new = top_stack->prev;
609 new = (struct parse_stack *) xzalloc(sizeof(struct parse_stack));
610 /* Initialize new frame with previous content */
612 register struct parse_stack *prev = new->prev;
615 top_stack->prev = new;
617 new->next = top_stack;
622 /* Exit a lexical context */
624 static pop_parse_stack()
629 top_stack = top_stack->next;
633 /* Cross-references might be to things we haven't looked at
634 yet, e.g. type references. To avoid too many type
635 duplications we keep a quick fixup table, an array
636 of lists of references indexed by file descriptor */
638 static struct pending {
639 struct pending *next; /* link */
640 SYMR *s; /* the symbol */
641 struct type *t; /* its partial type descriptor */
645 /* Check whether we already saw symbol SH in file FH as undefined */
648 struct pending *is_pending_symbol(fh, sh)
652 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
653 register struct pending *p;
655 /* Linear search is ok, list is typically no more than 10 deep */
656 for (p = pending_list[f_idx]; p; p = p->next)
662 /* Check whether we already saw type T in file FH as undefined */
665 struct pending *is_pending_type(fh, t)
669 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
670 register struct pending *p;
672 for (p = pending_list[f_idx]; p; p = p->next)
678 /* Add a new undef symbol SH of type T */
681 add_pending(fh, sh, t)
686 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
687 struct pending *p = is_pending_symbol(fh, sh);
689 /* Make sure we do not make duplicates */
691 p = (struct pending *) xmalloc(sizeof(*p));
694 p->next = pending_list[f_idx];
695 pending_list[f_idx] = p;
697 sh->reserved = 1; /* for quick check */
700 /* Throw away undef entries when done with file index F_IDX */
705 register struct pending *p, *q;
707 for (p = pending_list[f_idx]; p; p = q) {
711 pending_list[f_idx] = 0;
714 /* The number of args to a procedure is not explicit in the symtab,
715 this is the list of all those we know of.
716 This makes parsing more reasonable and avoids extra passes */
718 static struct numarg {
719 struct numarg *next; /* link */
720 unsigned adr; /* procedure's start address */
721 unsigned num; /* arg count */
724 /* Record that the procedure at ADR takes NUM arguments. */
729 struct numarg *n = (struct numarg *) xmalloc(sizeof(struct numarg));
733 n->next = numargs_list;
737 /* See if we know how many arguments the procedure at ADR takes */
742 struct numarg *n = numargs_list;
744 while (n && n->adr != adr)
746 return (n) ? n->num : -1;
749 /* Release storage when done with this file */
754 struct numarg *n = numargs_list, *m;
765 /* Parsing Routines proper. */
767 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
768 For blocks, procedures and types we open a new lexical context.
769 This is basically just a big switch on the symbol's type */
780 /* When a symbol is cross-referenced from other files/symbols
781 we mark it explicitly */
782 int pend = (sh->reserved == 1);
783 enum address_class class;
790 case stGlobal: /* external symbol, goes into global block */
792 b = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st),
794 s = new_symbol(sh->iss);
795 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
798 case stStatic: /* static data, goes into current block. */
800 b = top_stack->cur_block;
801 s = new_symbol(sh->iss);
802 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
805 case stLocal: /* local variable, goes into current block */
806 if (sh->sc == scRegister) {
807 class = LOC_REGISTER;
812 b = top_stack->cur_block;
813 s = new_symbol(sh->iss);
814 SYMBOL_VALUE(s) = sh->value;
816 data: /* Common code for symbols describing data */
817 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
818 SYMBOL_CLASS(s) = class;
821 /* Type could be missing in a number of cases */
822 if (sh->sc == scUndefined || sh->sc == scNil ||
823 sh->index == 0xfffff)
824 SYMBOL_TYPE(s) = builtin_type_int; /* undefined? */
826 SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0);
827 /* Value of a data symbol is its memory address */
830 case stParam: /* arg to procedure, goes into current block */
832 top_stack->numargs++;
833 s = new_symbol(sh->iss);
834 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
835 if (sh->sc == scRegister) {
836 SYMBOL_CLASS(s) = LOC_REGPARM;
840 SYMBOL_CLASS(s) = LOC_ARG;
841 SYMBOL_VALUE(s) = sh->value;
842 SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0);
843 add_symbol(s, top_stack->cur_block);
845 /* FIXME: This has not been tested. See dbxread.c */
846 /* Add the type of this parameter to the function/procedure
847 type of this block. */
848 add_param_to_type(&top_stack->cur_block->function->type,s);
852 case stLabel: /* label, goes into current block */
853 s = new_symbol(sh->iss);
854 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE; /* so that it can be used */
855 SYMBOL_CLASS(s) = LOC_LABEL; /* but not misused */
856 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
857 SYMBOL_TYPE(s) = builtin_type_int;
858 add_symbol(s, top_stack->cur_block);
861 case stProc: /* Procedure, usually goes into global block */
862 case stStaticProc: /* Static procedure, goes into current block */
863 s = new_symbol(sh->iss);
864 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
865 SYMBOL_CLASS(s) = LOC_BLOCK;
866 /* Type of the return value */
867 if (sh->sc == scUndefined || sh->sc == scNil)
868 t = builtin_type_int;
870 t = parse_type(ax + sh->index, sh, 0);
871 b = top_stack->cur_block;
872 if (sh->st == stProc) {
873 struct blockvector *bv = BLOCKVECTOR(top_stack->cur_st);
874 /* The next test should normally be true,
875 but provides a hook for nested functions
876 (which we don't want to make global). */
877 if (b == BLOCKVECTOR_BLOCK(bv, STATIC_BLOCK))
878 b = BLOCKVECTOR_BLOCK(bv, GLOBAL_BLOCK);
882 /* Make a type for the procedure itself */
884 /* FIXME: This has not been tested yet! See dbxread.c */
885 /* Generate a template for the type of this function. The
886 types of the arguments will be added as we read the symbol
888 bcopy(SYMBOL_TYPE(s),lookup_function_type(t),sizeof(struct type));
890 SYMBOL_TYPE(s) = lookup_function_type (t);
893 /* Create and enter a new lexical context */
894 b = new_block(top_stack->maxsyms);
895 SYMBOL_BLOCK_VALUE(s) = b;
896 BLOCK_FUNCTION(b) = s;
897 BLOCK_START(b) = BLOCK_END(b) = sh->value;
898 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
899 add_block(b, top_stack->cur_st);
901 /* Not if we only have partial info */
902 if (sh->sc == scUndefined || sh->sc == scNil)
906 top_stack->cur_block = b;
907 top_stack->blocktype = sh->st;
908 top_stack->cur_type = SYMBOL_TYPE(s);
909 top_stack->procadr = sh->value;
910 top_stack->numargs = 0;
912 sh->value = (long) SYMBOL_TYPE(s);
915 case stBlock: /* Either a lexical block, or some type */
917 top_stack->blocktype = stBlock;
918 if (sh->sc == scInfo) { /* structure/union/enum def */
919 s = new_symbol(sh->iss);
920 SYMBOL_NAMESPACE(s) = STRUCT_NAMESPACE;
921 SYMBOL_CLASS(s) = LOC_TYPEDEF;
923 add_symbol(s, top_stack->cur_block);
924 /* If this type was expected, use its partial definition */
926 t = is_pending_symbol(cur_fdr, sh)->t;
928 /* Uhmm, can`t decide yet. Smash later */
929 t = new_type(sh->iss);
930 TYPE_CODE(t) = TYPE_CODE_UNDEF;
931 add_pending(cur_fdr, sh, t);
934 /* make this the current type */
935 top_stack->cur_type = t;
936 TYPE_LENGTH(t) = sh->value;
937 /* Mark that symbol has a type, and say which one */
938 sh->value = (long) t;
940 /* beginnning of (code) block. Value of symbol
941 is the displacement from procedure start */
942 b = new_block(top_stack->maxsyms);
943 BLOCK_START(b) = sh->value + top_stack->procadr;
944 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
945 top_stack->cur_block = b;
946 add_block(b, top_stack->cur_st);
950 case stEnd: /* end (of anything) */
951 if (sh->sc == scInfo) {
952 /* Finished with type */
953 top_stack->cur_type = 0;
954 } else if (sh->sc == scText &&
955 (top_stack->blocktype == stProc ||
956 top_stack->blocktype == stStaticProc)) {
957 /* Finished with procedure */
958 struct blockvector *bv = BLOCKVECTOR(top_stack->cur_st);
962 BLOCK_END(top_stack->cur_block) += sh->value; /* size */
963 got_numargs(top_stack->procadr, top_stack->numargs);
964 /* Reallocate symbols, saving memory */
965 b = shrink_block(top_stack->cur_block, top_stack->cur_st);
967 /* f77 emits proc-level with address bounds==[0,0],
968 So look for such child blocks, and patch them. */
969 for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++) {
970 struct block *b_bad = BLOCKVECTOR_BLOCK(bv,i);
971 if (BLOCK_SUPERBLOCK(b_bad) == b
972 && BLOCK_START(b_bad) == top_stack->procadr
973 && BLOCK_END(b_bad) == top_stack->procadr) {
974 BLOCK_START(b_bad) = BLOCK_START(b);
975 BLOCK_END(b_bad) = BLOCK_END(b);
978 if (entry_point < BLOCK_END(b)
979 && entry_point >= BLOCK_START(b)) {
980 startup_file_start = BLOCK_START(b);
981 startup_file_end = BLOCK_END(b);
983 } else if (sh->sc == scText && top_stack->blocktype == stBlock) {
984 /* End of (code) block. The value of the symbol
985 is the displacement from the procedure`s start
986 address of the end of this block. */
987 BLOCK_END(top_stack->cur_block) = sh->value + top_stack->procadr;
988 (void) shrink_block(top_stack->cur_block, top_stack->cur_st);
990 pop_parse_stack(); /* restore previous lexical context */
993 case stMember: /* member of struct/union/enum.. */
994 f = new_field(top_stack->cur_type, sh->iss);
995 f->bitpos = sh->value;
996 f->type = parse_type(ax + sh->index, sh, &f->bitsize);
999 case stTypedef: /* type definition */
1000 s = new_symbol(sh->iss);
1001 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
1002 SYMBOL_CLASS(s) = LOC_TYPEDEF;
1003 SYMBOL_BLOCK_VALUE(s) = top_stack->cur_block;
1004 add_symbol(s, top_stack->cur_block);
1005 SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0);
1006 sh->value = (long) SYMBOL_TYPE(s);
1009 case stFile: /* file name */
1011 top_stack->blocktype = sh->st;
1014 /* I`ve never seen these for C */
1016 break; /* register relocation */
1018 break; /* forwarding address */
1020 break; /* constant */
1022 error("Unknown symbol type %x.", sh->st);
1027 /* Parse the type information provided in the AX entries for
1028 the symbol SH. Return the bitfield size in BS, in case. */
1030 static struct type *parse_type(ax, sh, bs)
1035 /* Null entries in this map are treated specially */
1036 static struct type **map_bt[] =
1038 &builtin_type_void, /* btNil */
1040 &builtin_type_char, /* btChar */
1041 &builtin_type_unsigned_char, /* btUChar */
1042 &builtin_type_short, /* btShort */
1043 &builtin_type_unsigned_short, /* btUShort */
1044 &builtin_type_int, /* btInt */
1045 &builtin_type_unsigned_int, /* btUInt */
1046 &builtin_type_long, /* btLong */
1047 &builtin_type_unsigned_long, /* btULong */
1048 &builtin_type_float, /* btFloat */
1049 &builtin_type_double, /* btDouble */
1056 &builtin_type_complex, /* btComplex */
1057 &builtin_type_double_complex, /* btDComplex */
1059 &builtin_type_fixed_dec, /* btFixedDec */
1060 &builtin_type_float_dec, /* btFloatDec */
1061 &builtin_type_string, /* btString */
1064 &builtin_type_void, /* btVoid */
1068 struct type *tp = 0, *tp1;
1071 /* Procedures start off by one */
1072 if (sh->st == stProc || sh->st == stStaticProc)
1075 /* Undefined ? Should not happen */
1076 if (ax->rndx.rfd == 0xfff) {
1077 return builtin_type_void;
1080 /* Use aux as a type information record, map its basic type */
1082 if (t->bt > 26 || t->bt == btPicture) {
1083 complain (&basic_type_complaint, t->bt);
1084 return builtin_type_int;
1087 tp = *map_bt[t->bt];
1089 /* Cannot use builtin types, use templates */
1090 tp = make_type(TYPE_CODE_VOID, 0, 0, 0);
1093 *tp = *builtin_type_ptr;
1096 *tp = *builtin_type_struct;
1100 *tp = *builtin_type_union;
1104 *tp = *builtin_type_enum;
1108 *tp = *builtin_type_range;
1111 *tp = *builtin_type_set;
1117 /* Move on to next aux */
1120 /* This is the way it would work if the compiler worked */
1121 register TIR *t1 = t;
1122 while (t1->continued)
1126 /* For bitfields all we need is the width */
1132 /* All these types really point to some (common) MIPS type
1133 definition, and only the type-qualifiers fully identify
1134 them. We`ll make the same effort at sharing */
1135 if (t->bt == btIndirect ||
1136 t->bt == btStruct ||
1139 t->bt == btTypedef ||
1142 char name[256], *pn;
1144 /* Try to cross reference this type */
1146 ax += cross_ref(ax, &tp1, &pn);
1147 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1148 sprintf(name, fmt, pn);
1150 /* reading .o file ? */
1151 if (UNSAFE_DATA_ADDR(tp1))
1153 if (TYPE_CODE(tp1) == TYPE_CODE_UNDEF) {
1155 * Type was incompletely defined, now we know.
1157 TYPE_CODE(tp1) = TYPE_CODE(tp);
1158 TYPE_NAME(tp1) = obsavestring(name, strlen(name));
1159 if (TYPE_CODE(tp1) == TYPE_CODE_ENUM) {
1162 for (i = 0; i < TYPE_NFIELDS(tp1); i++)
1163 make_enum_constant(&TYPE_FIELD(tp1,i), tp1);
1167 /* found as cross ref, rid of our template */
1168 if ((TYPE_FLAGS(tp) & TYPE_FLAG_PERM) == 0)
1171 /* stupid idea of prepending "struct" to type names */
1172 if (t->bt == btStruct && !index(TYPE_NAME(tp), ' ')) {
1173 sprintf(name, fmt, TYPE_NAME(tp));
1174 TYPE_NAME(tp) = obsavestring(name, strlen(name));
1177 TYPE_NAME(tp) = savestring(name, strlen(name));
1180 /* Deal with range types */
1181 if (t->bt == btRange) {
1184 f = new_field(tp, "Low");
1185 f->bitpos = ax->dnLow;
1187 f = new_field(tp, "High");
1188 f->bitpos = ax->dnHigh;
1192 /* Parse all the type qualifiers now. If there are more
1193 than 6 the game will continue in the next aux */
1195 #define PARSE_TQ(tq) \
1196 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, sh);
1198 again: PARSE_TQ(tq0);
1213 /* Make up a complex type from a basic one. Type is passed by
1214 reference in TPP and side-effected as necessary. The type
1215 qualifier TQ says how to handle the aux symbols at AX for
1216 the symbol SX we are currently analyzing.
1217 Returns the number of aux symbols we parsed. */
1220 upgrade_type(tpp, tq, ax, sh)
1228 /* Used in array processing */
1237 t = lookup_pointer_type (*tpp);
1242 t = lookup_function_type (*tpp);
1248 t = make_type(TYPE_CODE_ARRAY, 0, 0, 0);
1249 TYPE_TARGET_TYPE(t) = *tpp;
1251 /* Determine and record the domain type (type of index) */
1252 id = ax->rndx.index;
1258 fh = get_rfd(cur_fd, rf);
1259 f = new_field(t, (char *)0);
1260 bzero(&ss, sizeof ss);
1261 /* XXX */ f->type = parse_type(fh->iauxBase + id * sizeof(AUXU),
1266 * This seems to be a pointer to the end of the Block defining
1267 * the type. Why it is here is magic for me, and I have no
1268 * good use for it anyways.
1270 /* This used to occur because cross_ref returned
1271 the wrong result (ax pointed wrong). FIXME,
1272 delete this code in a while. -- gnu@cygnus jul91 */
1273 complain (&array_parse_complaint, 0);
1275 id = (++ax)->rndx.index;
1276 if ((rf = ax->rndx.rfd) == 0xfff)
1277 rf = (++ax)->isym, off++;
1279 lower = (++ax)->dnLow;
1280 upper = (++ax)->dnHigh;
1281 rf = (++ax)->width; /* bit size of array element */
1283 /* Check whether supplied array element bit size matches
1284 the known size of the element type. If this complaint
1285 ends up not happening, we can remove this code. It's
1286 here because we aren't sure we understand this *&%&$
1288 id = TYPE_LENGTH(TYPE_TARGET_TYPE(t)) << 3; /* bitsize */
1290 /* Most likely an undefined type */
1292 TYPE_LENGTH(TYPE_TARGET_TYPE(t)) = id >> 3;
1295 complain (&array_bitsize_complaint, rf);
1297 TYPE_LENGTH(t) = (upper < 0) ? 0 :
1298 (upper - lower + 1) * (rf >> 3);
1303 /* Volatile -- currently ignored */
1307 complain (&unknown_type_qual_complaint, tq);
1313 /* Parse a procedure descriptor record PR. Note that the procedure
1314 is parsed _after_ the local symbols, now we just make up the
1315 extra information we need into a special symbol that we insert
1316 in the procedure's main block. Note also that images that
1317 have been partially stripped (ld -x) have been deprived
1318 of local symbols, and we have to cope with them here.
1319 The procedure's code ends at BOUND */
1322 parse_procedure(pr, bound)
1325 struct symbol *s, *i;
1326 SYMR *sh = (SYMR*)pr->isym;
1328 struct mips_extra_func_info *e;
1332 /* Reuse the MIPS record */
1333 e = (struct mips_extra_func_info *) pr;
1334 e->numargs = lookup_numargs(pr->adr);
1336 /* Make up our special symbol */
1337 i = new_symbol(".gdbinfo.");
1338 SYMBOL_VALUE(i) = (int)e;
1339 SYMBOL_NAMESPACE(i) = LABEL_NAMESPACE;
1340 SYMBOL_CLASS(i) = LOC_CONST;
1341 SYMBOL_TYPE(i) = builtin_type_void;
1343 /* Make up a name for static procedures. Sigh. */
1344 if (sh == (SYMR*)-1) {
1345 sprintf(name,".static_procedure@%x",pr->adr);
1346 sh_name = savestring(name, strlen(name));
1350 sh_name = (char*)sh->iss;
1351 s = mylookup_symbol(sh_name, top_stack->cur_block,
1352 VAR_NAMESPACE, LOC_BLOCK);
1355 b = SYMBOL_BLOCK_VALUE(s);
1357 s = new_symbol(sh_name);
1358 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
1359 SYMBOL_CLASS(s) = LOC_BLOCK;
1360 /* Donno its type, hope int is ok */
1361 SYMBOL_TYPE(s) = lookup_function_type (builtin_type_int);
1362 add_symbol(s, top_stack->cur_block);
1363 /* Wont have symbols for this one */
1365 SYMBOL_BLOCK_VALUE(s) = b;
1366 BLOCK_FUNCTION(b) = s;
1367 BLOCK_START(b) = pr->adr;
1368 BLOCK_END(b) = bound;
1369 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
1370 add_block(b, top_stack->cur_st);
1376 /* Parse the external symbol ES. Just call parse_symbol() after
1377 making sure we know where the aux are for it. For procedures,
1378 parsing of the PDRs has already provided all the needed
1379 information, we only parse them if SKIP_PROCEDURES is false,
1380 and only if this causes no symbol duplication.
1382 This routine clobbers top_stack->cur_block and ->cur_st. */
1385 parse_external(es, skip_procedures)
1390 if (es->ifd != ifdNil) {
1392 cur_fdr = (FDR*)(cur_hdr->cbFdOffset) + cur_fd;
1393 ax = (AUXU*)cur_fdr->iauxBase;
1395 cur_fdr = (FDR*)(cur_hdr->cbFdOffset);
1398 top_stack->cur_st = cur_stab;
1399 top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st),
1402 /* Reading .o files */
1403 if (es->asym.sc == scUndefined || es->asym.sc == scNil) {
1405 switch (es->asym.st) {
1407 case stProc: what = "procedure"; n_undef_procs++; break;
1408 case stGlobal: what = "variable"; n_undef_vars++; break;
1409 case stLabel: what = "label"; n_undef_labels++; break;
1410 default : what = "symbol"; break;
1414 printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what,
1415 es->asym.iss, fdr_name(cur_fdr->rss));
1419 switch (es->asym.st) {
1421 /* If we have full symbols we do not need more */
1422 if (skip_procedures)
1424 if (mylookup_symbol (es->asym.iss, top_stack->cur_block,
1425 VAR_NAMESPACE, LOC_BLOCK))
1431 * Note that the case of a symbol with indexNil
1432 * must be handled anyways by parse_symbol().
1434 parse_symbol(&es->asym, ax);
1441 /* Parse the line number info for file descriptor FH into
1442 GDB's linetable LT. MIPS' encoding requires a little bit
1443 of magic to get things out. Note also that MIPS' line
1444 numbers can go back and forth, apparently we can live
1445 with that and do not need to reorder our linetables */
1450 struct linetable *lt;
1452 unsigned char *base = (unsigned char*)fh->cbLineOffset;
1454 int delta, count, lineno = 0;
1460 /* Scan by procedure descriptors */
1461 i = 0; j = 0, k = 0;
1462 for (pr = (PDR*)IPDFIRST(cur_hdr,fh); j < fh->cpd; j++, pr++) {
1465 /* No code for this one */
1466 if (pr->iline == ilineNil ||
1467 pr->lnLow == -1 || pr->lnHigh == -1)
1470 * Aurgh! To know where to stop expanding we
1473 for (l = 1; l < (fh->cpd - j); l++)
1474 if (pr[l].iline != -1)
1476 if (l == (fh->cpd - j))
1481 * When procedures are moved around the linenumbers
1482 * are attributed to the next procedure up
1484 if (pr->iline >= halt) continue;
1486 base = (unsigned char*)pr->cbLineOffset;
1487 l = pr->adr >> 2; /* in words */
1488 halt += (pr->adr >> 2) - pr->iline;
1489 for (lineno = pr->lnLow; l < halt;) {
1490 count = *base & 0x0f;
1491 delta = *base++ >> 4;
1495 delta = (base[0] << 8) | base[1];
1496 if (delta >= 0x8000)
1500 lineno += delta;/* first delta is 0 */
1501 k = add_line(lt, lineno, l, k);
1508 /* Parse the symbols of the file described by FH, whose index is F_IDX.
1509 BOUND is the highest core address of this file's procedures */
1512 parse_one_file(fh, f_idx, bound)
1519 /* Parse local symbols first */
1521 for (s_idx = 0; s_idx < fh->csym; s_idx++) {
1522 sh = (SYMR *) (fh->isymBase) + s_idx;
1524 parse_symbol(sh, fh->iauxBase);
1527 /* Procedures next, note we need to look-ahead to
1528 find out where the procedure's code ends */
1530 for (s_idx = 0; s_idx < fh->cpd-1; s_idx++) {
1531 pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + s_idx;
1532 parse_procedure(pr, pr[1].adr); /* next proc up */
1535 pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + s_idx;
1536 parse_procedure(pr, bound); /* next file up */
1539 /* Linenumbers. At the end, check if we can save memory */
1540 parse_lines(fh, LINETABLE(cur_stab));
1541 if (LINETABLE(cur_stab)->nitems < fh->cline)
1542 shrink_linetable(cur_stab);
1545 /* Master parsing procedure for first-pass reading of file symbols
1546 into a partial_symtab.
1548 Parses the symtab described by the global symbolic header CUR_HDR.
1549 END_OF_TEXT_SEG gives the address just after the text segment for
1550 the symtab we are reading. */
1553 parse_partial_symbols(end_of_text_seg, objfile)
1554 int end_of_text_seg;
1555 struct objfile *objfile;
1557 int f_idx, s_idx, h_max, stat_idx;
1559 /* Running pointers */
1564 struct partial_symtab *pst;
1569 * Only parse the Local and External symbols, and the Relative FDR.
1570 * Fixup enough of the loader symtab to be able to use it.
1571 * Allocate space only for the file's portions we need to
1577 max_glevel = MIN_GLEVEL;
1579 /* Allocate the map FDR -> PST.
1580 Minor hack: -O3 images might claim some global data belongs
1581 to FDR -1. We`ll go along with that */
1582 fdr_to_pst = (struct pst_map *)xzalloc((hdr->ifdMax+1) * sizeof *fdr_to_pst);
1585 struct partial_symtab * pst = new_psymtab("", objfile);
1586 fdr_to_pst[-1].pst = pst;
1590 /* Now scan the FDRs, mostly for dependencies */
1591 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
1592 (void) parse_fdr(f_idx, 1, objfile);
1594 /* Take a good guess at how many symbols we might ever need */
1595 h_max = hdr->iextMax;
1597 /* Parse externals: two passes because they can be ordered
1598 in any way, but gdb likes to have them segregated by their
1601 /* Pass 1 over external syms: Presize and partition the list */
1602 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
1603 esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
1604 fdr_to_pst[esh->ifd].n_globals++;
1607 if (global_psymbols.list) {
1608 int origsize = global_psymbols.next - global_psymbols.list;
1610 global_psymbols.list = (struct partial_symbol *)
1611 xrealloc (global_psymbols.list,
1612 (h_max + origsize) * sizeof(struct partial_symbol));
1613 global_psymbols.next = global_psymbols.list + origsize;
1614 global_psymbols.size = h_max + origsize;
1616 global_psymbols.list = (struct partial_symbol *)
1617 xmalloc (h_max * sizeof(struct partial_symbol));
1618 global_psymbols.next = global_psymbols.list;
1619 global_psymbols.size = h_max;
1622 /* Pass 1.5 over files: partition out global symbol space */
1623 s_idx = global_psymbols.next - global_psymbols.list;
1624 for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++) {
1625 fdr_to_pst[f_idx].pst->globals_offset = s_idx;
1626 s_idx += fdr_to_pst[f_idx].n_globals;
1629 /* Pass 1.6 over files: partition out static symbol space.
1630 Note that this loop starts at 0, not at -1. */
1631 stat_idx = static_psymbols.next - static_psymbols.list;
1632 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
1633 fdr_to_pst[f_idx].pst->statics_offset = stat_idx;
1634 fh = f_idx + (FDR *)(hdr->cbFdOffset);
1635 stat_idx += fh->csym;
1638 /* Now that we know its max size, allocate static symbol list */
1639 if (static_psymbols.list) {
1640 int origsize = static_psymbols.next - static_psymbols.list;
1642 static_psymbols.list = (struct partial_symbol *)
1643 xrealloc (static_psymbols.list,
1644 stat_idx * sizeof(struct partial_symbol));
1645 static_psymbols.next = static_psymbols.list + origsize;
1646 static_psymbols.size = stat_idx;
1648 static_psymbols.list = (struct partial_symbol *)
1649 xmalloc (stat_idx * sizeof(struct partial_symbol));
1650 static_psymbols.next = static_psymbols.list;
1651 static_psymbols.size = stat_idx;
1654 /* Pass 2 over external syms: fill in external symbols */
1655 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
1656 register struct partial_symbol *p;
1657 enum misc_function_type misc_type = mf_text;
1658 esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
1660 if (esh->asym.sc == scUndefined || esh->asym.sc == scNil)
1663 /* Locate the psymtab and the preallocated psymbol. */
1664 pst = fdr_to_pst[esh->ifd].pst;
1665 p = global_psymbols.list + pst->globals_offset +
1666 pst->n_global_syms++;
1667 SYMBOL_NAME(p) = (char *)(esh->asym.iss);
1668 SYMBOL_NAMESPACE(p) = VAR_NAMESPACE;
1670 switch (esh->asym.st) {
1672 SYMBOL_CLASS(p) = LOC_BLOCK;
1673 SYMBOL_VALUE(p) = esh->asym.value;
1676 SYMBOL_CLASS(p) = LOC_STATIC;
1677 SYMBOL_VALUE_ADDRESS(p) = (CORE_ADDR)esh->asym.value;
1678 misc_type = mf_data;
1681 SYMBOL_CLASS(p) = LOC_LABEL;
1682 SYMBOL_VALUE_ADDRESS(p) = (CORE_ADDR)esh->asym.value;
1685 misc_type = mf_unknown;
1686 complain (&unknown_ext_complaint, SYMBOL_NAME(p));
1688 prim_record_misc_function (SYMBOL_NAME(p),
1693 /* Pass 3 over files, over local syms: fill in static symbols */
1694 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
1695 fh = f_idx + (FDR *)(cur_hdr->cbFdOffset);
1696 pst = fdr_to_pst[f_idx].pst;
1697 pst->texthigh = pst->textlow;
1699 for (s_idx = 0; s_idx < fh->csym; ) {
1700 register struct partial_symbol *p;
1702 sh = s_idx + (SYMR *) fh->isymBase;
1704 if (sh->sc == scUndefined || sh->sc == scNil ||
1705 sh->index == 0xfffff) {
1706 /* FIXME, premature? */
1711 /* Locate the preallocated psymbol. */
1712 p = static_psymbols.list + pst->statics_offset +
1714 SYMBOL_NAME(p) = (char *)(sh->iss);
1715 SYMBOL_VALUE(p) = sh->value;
1716 SYMBOL_NAMESPACE(p) = VAR_NAMESPACE;
1719 case stProc: /* Asm labels apparently */
1720 case stStaticProc: /* Function */
1721 SYMBOL_CLASS(p) = LOC_BLOCK;
1722 pst->n_static_syms++; /* Use gdb symbol */
1723 /* Skip over procedure to next one. */
1724 s_idx = (sh->index + (AUXU *)fh->iauxBase)
1728 long procaddr = sh->value;
1730 sh = s_idx + (SYMR *) fh->isymBase - 1;
1731 if (sh->st != stEnd)
1733 high = procaddr + sh->value;
1734 if (high > pst->texthigh)
1735 pst->texthigh = high;
1738 case stStatic: /* Variable */
1739 SYMBOL_CLASS(p) = LOC_STATIC;
1740 SYMBOL_VALUE_ADDRESS(p) = (CORE_ADDR)sh->value;
1742 case stTypedef: /* Typedef */
1743 SYMBOL_CLASS(p) = LOC_TYPEDEF;
1745 case stConstant: /* Constant decl */
1746 SYMBOL_CLASS(p) = LOC_CONST;
1748 case stBlock: /* { }, str, un, enum*/
1749 if (sh->sc == scInfo) {
1750 SYMBOL_NAMESPACE(p) = STRUCT_NAMESPACE;
1751 SYMBOL_CLASS(p) = LOC_TYPEDEF;
1752 pst->n_static_syms++;
1754 /* Skip over the block */
1757 case stFile: /* File headers */
1758 case stLabel: /* Labels */
1759 case stEnd: /* Ends of files */
1762 complain (&unknown_sym_complaint, SYMBOL_NAME(p));
1763 complain (&unknown_st_complaint, sh->st);
1767 pst->n_static_syms++; /* Use this gdb symbol */
1769 s_idx++; /* Go to next file symbol */
1771 /* We don't usually record static syms, but some we seem to. chk dbxread. */
1772 /*FIXME*/ prim_record_misc_function (SYMBOL_NAME(p),
1779 /* The array (of lists) of globals must be sorted. */
1782 /* Now sort the global psymbols. */
1783 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
1784 struct partial_symtab *pst = fdr_to_pst[f_idx].pst;
1785 if (pst->n_global_syms > 1)
1786 qsort (global_psymbols.list + pst->globals_offset,
1787 pst->n_global_syms, sizeof (struct partial_symbol),
1791 /* Mark the last code address, and remember it for later */
1792 hdr->cbDnOffset = end_of_text_seg;
1794 free(&fdr_to_pst[-1]);
1799 /* Do the initial analisys of the F_IDX-th file descriptor.
1800 Allocates a partial symtab for it, and builds the list
1801 of dependent files by recursion. LEV says at which level
1802 of recursion we are called (to pretty up debug traces) */
1804 static struct partial_symtab *
1805 parse_fdr(f_idx, lev, objfile)
1808 struct objfile *objfile;
1811 register struct partial_symtab *pst;
1814 fh = (FDR *) (cur_hdr->cbFdOffset) + f_idx;
1816 /* Use this to indicate into which symtab this file was parsed */
1818 return (struct partial_symtab *) fh->ioptBase;
1820 /* Debuggability level */
1821 if (compare_glevel(max_glevel, fh->glevel) < 0)
1822 max_glevel = fh->glevel;
1824 /* Make a new partial_symtab */
1825 pst = new_psymtab(fh->rss, objfile);
1830 pst->textlow = fh->adr;
1831 pst->texthigh = fh->cpd; /* To be fixed later */
1834 /* Make everything point to everything. */
1835 FDR_IDX(pst) = f_idx;
1836 fdr_to_pst[f_idx].pst = pst;
1837 fh->ioptBase = (int)pst;
1839 /* Analyze its dependencies */
1844 if (fh->cpd == 0) { /* If there are no functions defined here ... */
1845 /* ...then presumably a .h file: drop reverse depends .h->.c */
1846 for (; s_id0 < fh->crfd; s_id0++) {
1847 RFDT *rh = (RFDT *) (fh->rfdBase) + s_id0;
1849 s_id0++; /* Skip self-dependency */
1854 pst->number_of_dependencies = fh->crfd - s_id0;
1855 pst->dependencies = (struct partial_symtab **)
1856 obstack_alloc (psymbol_obstack,
1857 pst->number_of_dependencies *
1858 sizeof (struct partial_symtab *));
1859 for (s_idx = s_id0; s_idx < fh->crfd; s_idx++) {
1860 RFDT *rh = (RFDT *) (fh->rfdBase) + s_idx;
1862 pst->dependencies[s_idx-s_id0] = parse_fdr(*rh, lev+1, objfile);
1869 /* Ancillary function to psymtab_to_symtab(). Does all the work
1870 for turning the partial symtab PST into a symtab, recurring
1871 first on all dependent psymtabs. The argument FILENAME is
1872 only passed so we can see in debug stack traces what file
1876 psymtab_to_symtab_1(pst, filename)
1877 struct partial_symtab *pst;
1888 pending_list = (struct pending **) cur_hdr->cbOptOffset;
1889 if (pending_list == 0) {
1890 pending_list = (struct pending **)
1891 xzalloc(cur_hdr->ifdMax * sizeof(struct pending *));
1892 cur_hdr->cbOptOffset = (int)pending_list;
1895 /* How many symbols will we need */
1896 /* FIXME, this does not count enum values. */
1897 f_max = pst->n_global_syms + pst->n_static_syms;
1898 if (FDR_IDX(pst) == -1) {
1900 st = new_symtab ("unknown", f_max, 0, pst->objfile);
1902 fh = (FDR *) (cur_hdr->cbFdOffset) + FDR_IDX(pst);
1903 f_max += fh->csym + fh->cpd;
1904 st = new_symtab (pst->filename, 2 * f_max, 2 * fh->cline,
1908 /* Read in all partial symbtabs on which this one is dependent.
1909 NOTE that we do have circular dependencies, sigh. We solved
1910 that by setting pst->readin before this point. */
1912 for (i = 0; i < pst->number_of_dependencies; i++)
1913 if (!pst->dependencies[i]->readin) {
1914 /* Inform about additional files to be read in. */
1917 fputs_filtered (" ", stdout);
1919 fputs_filtered ("and ", stdout);
1921 printf_filtered ("%s...",
1922 pst->dependencies[i]->filename);
1923 wrap_here (""); /* Flush output */
1926 /* We only pass the filename for debug purposes */
1927 psymtab_to_symtab_1(pst->dependencies[i],
1928 pst->dependencies[i]->filename);
1931 /* Now read the symbols for this symtab */
1933 cur_fd = FDR_IDX(pst);
1937 /* Get a new lexical context */
1940 top_stack->cur_st = cur_stab;
1941 top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab),
1943 BLOCK_START(top_stack->cur_block) = fh ? fh->adr : 0;
1944 BLOCK_END(top_stack->cur_block) = 0;
1945 top_stack->blocktype = stFile;
1946 top_stack->maxsyms = 2*f_max;
1947 top_stack->cur_type = 0;
1948 top_stack->procadr = 0;
1949 top_stack->numargs = 0;
1951 /* Parse locals and procedures */
1953 parse_one_file(fh, cur_fd, (cur_fd == (cur_hdr->ifdMax - 1)) ?
1954 cur_hdr->cbDnOffset : fh[1].adr);
1956 /* .. and our share of externals.
1957 XXX use the global list to speed up things here. how ?
1958 FIXME, Maybe quit once we have found the right number of ext's? */
1959 /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
1960 top_stack->blocktype = stFile;
1961 top_stack->maxsyms = cur_hdr->isymMax + cur_hdr->ipdMax + cur_hdr->iextMax;
1962 for (i = 0; i < cur_hdr->iextMax; i++) {
1963 register EXTR *esh = (EXTR *) (cur_hdr->cbExtOffset) + i;
1964 if (esh->ifd == cur_fd)
1965 parse_external(esh, 1);
1968 /* If there are undefined, tell the user */
1969 if (n_undef_symbols) {
1970 printf_filtered("File %s contains %d unresolved references:",
1971 st->filename, n_undef_symbols);
1972 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
1973 n_undef_vars, n_undef_procs, n_undef_labels);
1974 n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
1980 * Sort the symbol table now, we are done adding symbols to it.
1982 sort_symtab_syms(st);
1984 /* Now link the psymtab and the symtab. */
1988 /* Ancillary parsing procedures. */
1990 /* Lookup the type at relative index RN. Return it in TPP
1991 if found and in any event come up with its name PNAME.
1992 Return value says how many aux symbols we ate */
1995 cross_ref(rn, tpp, pname)
2002 /* Escape index means 'the next one' */
2003 if (rn->rfd == 0xfff)
2004 rf = *(unsigned *) (rn + 1);
2010 *pname = "<undefined>";
2013 * Find the relative file descriptor and the symbol in it
2015 FDR *fh = get_rfd(cur_fd, rf);
2020 * If we have processed this symbol then we left a forwarding
2021 * pointer to the corresponding GDB symbol. If not, we`ll put
2022 * it in a list of pending symbols, to be processed later when
2023 * the file f will be. In any event, we collect the name for
2024 * the type here. Which is why we made a first pass at
2027 sh = (SYMR *) (fh->isymBase) + rn->index;
2029 /* Careful, we might be looking at .o files */
2030 *pname = (UNSAFE_DATA_ADDR(sh->iss)) ? "<undefined>" :
2033 /* Have we parsed it ? */
2034 if ((!UNSAFE_DATA_ADDR(sh->value)) && (sh->st == stParsed)) {
2035 t = (struct type *) sh->value;
2040 /* Avoid duplicates */
2041 p = is_pending_symbol(fh, sh);
2046 add_pending(fh, sh, *tpp);
2050 /* We used one auxent normally, two if we got a "next one" rf. */
2051 return (rn->rfd == 0xfff? 2: 1);
2055 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2056 keeping the symtab sorted */
2058 static struct symbol *
2059 mylookup_symbol (name, block, namespace, class)
2061 register struct block *block;
2062 enum namespace namespace;
2063 enum address_class class;
2065 register int bot, top, inc;
2066 register struct symbol *sym;
2069 top = BLOCK_NSYMS(block);
2072 sym = BLOCK_SYM(block, bot);
2073 if (SYMBOL_NAME(sym)[0] == inc
2074 && SYMBOL_NAMESPACE(sym) == namespace
2075 && SYMBOL_CLASS(sym) == class
2076 && !strcmp(SYMBOL_NAME(sym), name))
2080 if (block = BLOCK_SUPERBLOCK (block))
2081 return mylookup_symbol (name, block, namespace, class);
2086 /* Add a new symbol S to a block B.
2087 Infrequently, we will need to reallocate the block to make it bigger.
2088 We only detect this case when adding to top_stack->cur_block, since
2089 that's the only time we know how big the block is. FIXME. */
2096 int nsyms = BLOCK_NSYMS(b)++;
2097 struct block *origb;
2098 struct parse_stack *stackp;
2100 if (b == top_stack->cur_block &&
2101 nsyms >= top_stack->maxsyms) {
2102 complain (&block_overflow_complaint, s->name);
2103 /* In this case shrink_block is actually grow_block, since
2104 BLOCK_NSYMS(b) is larger than its current size. */
2106 b = shrink_block (top_stack->cur_block, top_stack->cur_st);
2108 /* Now run through the stack replacing pointers to the
2109 original block. shrink_block has already done this
2110 for the blockvector and BLOCK_FUNCTION. */
2111 for (stackp = top_stack; stackp; stackp = stackp->next) {
2112 if (stackp->cur_block == origb) {
2113 stackp->cur_block = b;
2114 stackp->maxsyms = BLOCK_NSYMS (b);
2118 BLOCK_SYM(b,nsyms) = s;
2121 /* Add a new block B to a symtab S */
2128 struct blockvector *bv = BLOCKVECTOR(s);
2130 bv = (struct blockvector *)xrealloc(bv, sizeof(struct blockvector) +
2131 BLOCKVECTOR_NBLOCKS(bv) * sizeof(bv->block));
2132 if (bv != BLOCKVECTOR(s))
2133 BLOCKVECTOR(s) = bv;
2135 BLOCKVECTOR_BLOCK(bv, BLOCKVECTOR_NBLOCKS(bv)++) = b;
2138 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2139 MIPS' linenumber encoding might need more than one byte
2140 to describe it, LAST is used to detect these continuation lines */
2143 add_line(lt, lineno, adr, last)
2144 struct linetable *lt;
2150 last = -2; /* make sure we record first line */
2152 if (last == lineno) /* skip continuation lines */
2155 lt->item[lt->nitems].line = lineno;
2156 lt->item[lt->nitems++].pc = adr << 2;
2162 /* Comparison functions, used when sorting things */
2164 /* Symtabs must be ordered viz the code segments they cover */
2167 compare_symtabs( s1, s2)
2168 struct symtab **s1, **s2;
2170 /* "most specific" first */
2172 register struct block *b1, *b2;
2173 b1 = BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1),GLOBAL_BLOCK);
2174 b2 = BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2),GLOBAL_BLOCK);
2175 if (BLOCK_END(b1) == BLOCK_END(b2))
2176 return BLOCK_START(b1) - BLOCK_START(b2);
2177 return BLOCK_END(b1) - BLOCK_END(b2);
2181 /* Partial Symtabs, same */
2184 compare_psymtabs( s1, s2)
2185 struct partial_symtab **s1, **s2;
2187 /* Perf twist: put the ones with no code at the end */
2189 register int a = (*s1)->textlow;
2190 register int b = (*s2)->textlow;
2199 /* Partial symbols are compared lexicog by their print names */
2202 compare_psymbols (s1, s2)
2203 register struct partial_symbol *s1, *s2;
2206 *st1 = SYMBOL_NAME(s1),
2207 *st2 = SYMBOL_NAME(s2);
2209 return (st1[0] - st2[0] ? st1[0] - st2[0] :
2210 strcmp(st1 + 1, st2 + 1));
2213 /* Blocks with a smaller low bound should come first */
2215 static int compare_blocks(b1,b2)
2216 struct block **b1, **b2;
2218 register int addr_diff;
2220 addr_diff = (BLOCK_START((*b1))) - (BLOCK_START((*b2)));
2222 return (BLOCK_END((*b1))) - (BLOCK_END((*b2)));
2227 /* Sorting and reordering procedures */
2229 /* Sort the blocks of a symtab S.
2230 Reorder the blocks in the blockvector by code-address,
2231 as required by some MI search routines */
2237 struct blockvector *bv = BLOCKVECTOR(s);
2239 if (BLOCKVECTOR_NBLOCKS(bv) <= 2) {
2241 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) == 0)
2242 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = 0;
2243 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) == 0)
2244 BLOCK_START(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) = 0;
2248 * This is very unfortunate: normally all functions are compiled in
2249 * the order they are found, but if the file is compiled -O3 things
2250 * are very different. It would be nice to find a reliable test
2251 * to detect -O3 images in advance.
2253 if (BLOCKVECTOR_NBLOCKS(bv) > 3)
2254 qsort(&BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK),
2255 BLOCKVECTOR_NBLOCKS(bv) - FIRST_LOCAL_BLOCK,
2256 sizeof(struct block *),
2260 register CORE_ADDR high = 0;
2261 register int i, j = BLOCKVECTOR_NBLOCKS(bv);
2263 for (i = FIRST_LOCAL_BLOCK; i < j; i++)
2264 if (high < BLOCK_END(BLOCKVECTOR_BLOCK(bv,i)))
2265 high = BLOCK_END(BLOCKVECTOR_BLOCK(bv,i));
2266 BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = high;
2269 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) =
2270 BLOCK_START(BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK));
2272 BLOCK_START(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) =
2273 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK));
2274 BLOCK_END (BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) =
2275 BLOCK_END (BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK));
2278 /* Sort the symtab list, as required by some search procedures.
2279 We want files ordered to make them look right to users, and for
2280 searching (see block_for_pc). */
2286 struct symtab *stab;
2287 register struct symtab **all_symtabs;
2288 register int symtab_count;
2293 /* Create an array of pointers to all the symtabs. */
2294 for (symtab_count = 0, stab = symtab_list;
2296 symtab_count++, stab = stab->next) {
2297 obstack_grow (psymbol_obstack, &stab, sizeof (stab));
2298 /* FIXME: Only sort blocks for new symtabs ??? */
2302 all_symtabs = (struct symtab **)
2303 obstack_base (psymbol_obstack);
2304 qsort((char *)all_symtabs, symtab_count,
2305 sizeof(struct symtab *), compare_symtabs);
2307 /* Re-construct the symtab list, but now it is sorted. */
2308 for (i = 0; i < symtab_count-1; i++)
2309 all_symtabs[i]->next = all_symtabs[i+1];
2310 all_symtabs[i]->next = 0;
2311 symtab_list = all_symtabs[0];
2313 obstack_free (psymbol_obstack, all_symtabs);
2316 /* Sort the partial symtab list, as required by some search procedures.
2317 PC lookups stop at the first psymtab such that textlow <= PC < texthigh */
2323 register int all_psymtabs_count;
2324 struct partial_symtab *pstab;
2325 struct partial_symtab **all_psymtabs;
2327 if (!partial_symtab_list)
2330 /* Create an array of pointers to all the partial_symtabs. */
2332 for (all_psymtabs_count = 0, pstab = partial_symtab_list;
2334 all_psymtabs_count++, pstab = pstab->next)
2335 obstack_grow (psymbol_obstack, &pstab, sizeof (pstab));
2337 all_psymtabs = (struct partial_symtab **)
2338 obstack_base (psymbol_obstack);
2340 qsort((char *)all_psymtabs, all_psymtabs_count,
2341 sizeof(struct partial_symtab *), compare_psymtabs);
2343 /* Re-construct the partial_symtab_list, but now it is sorted. */
2345 for (i = 0; i < all_psymtabs_count-1; i++)
2346 all_psymtabs[i]->next = all_psymtabs[i+1];
2347 all_psymtabs[i]->next = 0;
2348 partial_symtab_list = all_psymtabs[0];
2350 obstack_free (psymbol_obstack, all_psymtabs);
2353 /* Constructor/restructor/destructor procedures */
2355 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2356 MAXSYMS and linenumbers MAXLINES we'll put in it */
2360 new_symtab(name, maxsyms, maxlines, objfile)
2363 struct symtab *s = allocate_symtab (name, objfile);
2365 LINETABLE(s) = new_linetable(maxlines);
2367 /* All symtabs must have at least two blocks */
2368 BLOCKVECTOR(s) = new_bvect(2);
2369 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK) = new_block(maxsyms);
2370 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), STATIC_BLOCK) = new_block(maxsyms);
2371 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s),STATIC_BLOCK)) =
2372 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK);
2374 s->free_code = free_linetable;
2376 /* Link the new symtab into the list of such. */
2377 s->next = symtab_list;
2383 /* Allocate a new partial_symtab NAME */
2385 static struct partial_symtab *
2386 new_psymtab(name, objfile)
2388 struct objfile *objfile;
2390 struct partial_symtab *pst;
2392 pst = (struct partial_symtab *)
2393 obstack_alloc (psymbol_obstack, sizeof (*pst));
2394 bzero (pst, sizeof (*pst));
2396 if (name == (char*)-1) /* FIXME -- why not null here? */
2397 pst->filename = "<no name>";
2399 pst->filename = name;
2401 /* Chain it to its object file */
2402 pst->objfile = objfile;
2403 pst->objfile_chain = objfile->psymtabs;
2404 objfile->psymtabs = pst;
2406 pst->next = partial_symtab_list;
2407 partial_symtab_list = pst;
2409 /* Keep a backpointer to the file's symbols */
2410 pst->read_symtab_private = (char *) obstack_alloc (psymbol_obstack,
2411 sizeof (struct symloc));
2412 CUR_HDR(pst) = cur_hdr;
2414 /* The way to turn this into a symtab is to call... */
2415 pst->read_symtab = mipscoff_psymtab_to_symtab;
2421 /* Allocate a linetable array of the given SIZE */
2424 struct linetable *new_linetable(size)
2426 struct linetable *l;
2428 size = size * sizeof(l->item) + sizeof(struct linetable);
2429 l = (struct linetable *)xmalloc(size);
2434 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2435 I am not so sure about the 3.4 ones */
2441 struct linetable *l = new_linetable(LINETABLE(s)->nitems);
2443 bcopy(LINETABLE(s), l,
2444 LINETABLE(s)->nitems * sizeof(l->item) + sizeof(struct linetable));
2445 free (LINETABLE(s));
2449 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2452 struct blockvector *
2455 struct blockvector *bv;
2458 size = sizeof(struct blockvector) + nblocks * sizeof(struct block*);
2459 bv = (struct blockvector *) xzalloc(size);
2461 BLOCKVECTOR_NBLOCKS(bv) = nblocks;
2466 /* Allocate and zero a new block of MAXSYMS symbols */
2472 int size = sizeof(struct block) + (maxsyms-1) * sizeof(struct symbol *);
2473 struct block *b = (struct block *)xzalloc(size);
2478 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2479 Shrink_block can also be used by add_symbol to grow a block. */
2481 static struct block *
2487 struct blockvector *bv = BLOCKVECTOR(s);
2490 /* Just reallocate it and fix references to the old one */
2492 new = (struct block *) xrealloc ((char *)b, sizeof(struct block) +
2493 (BLOCK_NSYMS(b)-1) * sizeof(struct symbol *));
2495 /* Should chase pointers to old one. Fortunately, that`s just
2496 the block`s function and inferior blocks */
2497 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b)
2498 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2499 for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++)
2500 if (BLOCKVECTOR_BLOCK(bv,i) == b)
2501 BLOCKVECTOR_BLOCK(bv,i) = new;
2502 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) == b)
2503 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) = new;
2507 /* Create a new symbol with printname NAME */
2514 struct symbol *s = (struct symbol *)
2515 obstack_alloc (symbol_obstack, sizeof (struct symbol));
2517 bzero (s, sizeof (*s));
2518 SYMBOL_NAME(s) = name;
2522 /* Create a new type with printname NAME */
2529 struct type *t = (struct type *)
2530 obstack_alloc (symbol_obstack, sizeof (struct type));
2532 bzero (t, sizeof (*t));
2533 TYPE_VPTR_FIELDNO (t) = -1;
2534 TYPE_NAME(t) = name;
2538 /* Create and initialize a new type with printname NAME.
2539 CODE and LENGTH are the initial info we put in,
2540 UNS says whether the type is unsigned or not. */
2544 make_type(code, length, uns, name)
2545 enum type_code code;
2549 register struct type *type;
2551 type = (struct type *) xzalloc(sizeof(struct type));
2552 TYPE_CODE(type) = code;
2553 TYPE_LENGTH(type) = length;
2554 TYPE_FLAGS(type) = uns ? TYPE_FLAG_UNSIGNED : 0;
2555 TYPE_NAME(type) = name;
2556 TYPE_VPTR_FIELDNO (type) = -1;
2561 /* Allocate a new field named NAME to the type TYPE */
2565 new_field(type,name)
2571 /* Fields are kept in an array */
2572 if (TYPE_NFIELDS(type))
2573 TYPE_FIELDS(type) = (struct field*)xrealloc(TYPE_FIELDS(type),
2574 (TYPE_NFIELDS(type)+1) * sizeof(struct field));
2576 TYPE_FIELDS(type) = (struct field*)xzalloc(sizeof(struct field));
2577 f = &(TYPE_FIELD(type,TYPE_NFIELDS(type)));
2578 TYPE_NFIELDS(type)++;
2579 bzero(f, sizeof(struct field));
2580 f->name = name; /* Whether or not NAME is zero, this works. */
2584 /* Make an enum constant for a member F of an enumerated type T */
2587 make_enum_constant(f,t)
2593 * This is awful, but that`s the way it is supposed to be
2594 * (BTW, no need to free the real 'type', it's a builtin)
2596 f->type = (struct type *) f->bitpos;
2598 s = new_symbol(f->name);
2599 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
2600 SYMBOL_CLASS(s) = LOC_CONST;
2602 SYMBOL_VALUE(s) = f->bitpos;
2603 add_symbol(s, top_stack->cur_block);
2608 /* Things used for calling functions in the inferior.
2609 These functions are exported to our companion
2610 mips-dep.c file and are here because they play
2611 with the symbol-table explicitly. */
2614 /* Need to make a new symbol on the fly for the dummy
2615 frame we put on the stack. Which goes in the.. */
2617 static struct symtab *dummy_symtab;
2619 /* Make up a dummy symbol for the code we put at END_PC,
2620 of size SIZE, invoking a function with NARGS arguments
2621 and using a frame of FRAMESIZE bytes */
2623 mips_create_dummy_symbol(end_pc, size, nargs, framesize)
2627 struct mips_extra_func_info *gdbinfo;
2629 /* Allocate symtab if not done already */
2630 if (dummy_symtab == 0)
2631 dummy_symtab = new_symtab(".dummy_symtab.", 100, 0);
2633 /* Make a new block. Only needs one symbol */
2635 BLOCK_START(bl) = end_pc - size;
2636 BLOCK_END(bl) = end_pc;
2638 BLOCK_SUPERBLOCK(bl) =
2639 BLOCKVECTOR_BLOCK(BLOCKVECTOR(dummy_symtab),GLOBAL_BLOCK);
2640 add_block(bl, dummy_symtab);
2641 sort_blocks(dummy_symtab);
2643 BLOCK_FUNCTION(bl) = new_symbol("??");
2644 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(bl)) = bl;
2645 g = new_symbol(".gdbinfo.");
2646 BLOCK_SYM(bl,BLOCK_NSYMS(bl)++) = g;
2648 SYMBOL_NAMESPACE(g) = LABEL_NAMESPACE;
2649 SYMBOL_CLASS(g) = LOC_CONST;
2650 SYMBOL_TYPE(g) = builtin_type_void;
2651 gdbinfo = (struct mips_extra_func_info *)
2652 xzalloc(sizeof(struct mips_extra_func_info));
2654 SYMBOL_VALUE(g) = (long) gdbinfo;
2656 gdbinfo->numargs = nargs;
2657 gdbinfo->framesize = framesize;
2658 gdbinfo->framereg = 29;
2659 gdbinfo->pcreg = 31;
2660 gdbinfo->regmask = -2;
2661 gdbinfo->regoffset = -4;
2662 gdbinfo->fregmask = 0; /* XXX */
2663 gdbinfo->fregoffset = 0; /* XXX */
2666 /* We just returned from the dummy code at END_PC, drop its symbol */
2668 mips_destroy_dummy_symbol(end_pc)
2671 struct blockvector *bv = BLOCKVECTOR(dummy_symtab);
2674 bl = block_for_pc(end_pc);
2675 free(BLOCK_FUNCTION(bl));
2676 free(SYMBOL_VALUE(BLOCK_SYM(bl,0)));
2677 free(BLOCK_SYM(bl,0));
2679 for (i = FIRST_LOCAL_BLOCK; i < BLOCKVECTOR_NBLOCKS(bv); i++)
2680 if (BLOCKVECTOR_BLOCK(bv,i) == bl)
2682 for (; i < BLOCKVECTOR_NBLOCKS(bv) - 1; i++)
2683 BLOCKVECTOR_BLOCK(bv,i) = BLOCKVECTOR_BLOCK(bv,i+1);
2684 BLOCKVECTOR_NBLOCKS(bv)--;
2685 sort_blocks(dummy_symtab);
2690 /* Sigtramp: make sure we have all the necessary information
2691 about the signal trampoline code. Since the official code
2692 from MIPS does not do so, we make up that information ourselves.
2693 If they fix the library (unlikely) this code will neutralize itself. */
2700 struct block *b, *b0;
2702 sigtramp_address = -1;
2704 /* We know it is sold as sigvec */
2705 s = lookup_symbol("sigvec", 0, VAR_NAMESPACE, 0, NULL);
2707 /* Most programs do not play with signals */
2711 b0 = SYMBOL_BLOCK_VALUE(s);
2713 /* A label of sigvec, to be more precise */
2714 s = lookup_symbol("sigtramp", b0, VAR_NAMESPACE, 0, NULL);
2716 /* But maybe this program uses its own version of sigvec */
2720 sigtramp_address = SYMBOL_VALUE(s);
2721 sigtramp_end = sigtramp_address + 0x88; /* black magic */
2723 /* Did we or MIPSco fix the library ? */
2724 if (SYMBOL_CLASS(s) == LOC_BLOCK)
2727 /* But what symtab does it live in ? */
2728 st = find_pc_symtab(SYMBOL_VALUE(s));
2731 * Ok, there goes the fix: turn it into a procedure, with all the
2732 * needed info. Note we make it a nested procedure of sigvec,
2733 * which is the way the (assembly) code is actually written.
2735 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
2736 SYMBOL_CLASS(s) = LOC_BLOCK;
2737 SYMBOL_TYPE(s) = make_type(TYPE_CODE_FUNC, 4, 0, 0);
2738 TYPE_TARGET_TYPE(SYMBOL_TYPE(s)) = builtin_type_void;
2740 /* Need a block to allocate .gdbinfo. in */
2742 SYMBOL_BLOCK_VALUE(s) = b;
2743 BLOCK_START(b) = sigtramp_address;
2744 BLOCK_END(b) = sigtramp_end;
2745 BLOCK_FUNCTION(b) = s;
2746 BLOCK_SUPERBLOCK(b) = BLOCK_SUPERBLOCK(b0);
2750 /* Make a .gdbinfo. for it */
2752 struct mips_extra_func_info *e =
2753 (struct mips_extra_func_info *)
2754 xzalloc(sizeof(struct mips_extra_func_info));
2756 e->numargs = 0; /* the kernel thinks otherwise */
2757 /* align_longword(sigcontext + SIGFRAME) */
2758 e->framesize = 0x150;
2759 e->framereg = SP_REGNUM;
2762 e->regoffset = -(41 * sizeof(int));
2764 e->fregoffset = -(37 * sizeof(int));
2767 s = new_symbol(".gdbinfo.");
2768 SYMBOL_VALUE(s) = (int) e;
2769 SYMBOL_NAMESPACE(s) = LABEL_NAMESPACE;
2770 SYMBOL_CLASS(s) = LOC_CONST;
2771 SYMBOL_TYPE(s) = builtin_type_void;
2774 BLOCK_SYM(b,BLOCK_NSYMS(b)++) = s;
2777 /* Initialization */
2779 static struct sym_fns ecoff_sym_fns = {"ecoff", 5,
2780 mipscoff_new_init, mipscoff_symfile_init,
2781 mipscoff_symfile_read};
2783 _initialize_mipsread ()
2785 add_symtab_fns (&ecoff_sym_fns);
2787 /* Missing basic types */
2788 builtin_type_string = make_type(TYPE_CODE_PASCAL_ARRAY,
2790 builtin_type_complex = make_type(TYPE_CODE_FLT,
2791 2 * sizeof(float), 0, "complex");
2792 builtin_type_double_complex = make_type(TYPE_CODE_FLT,
2793 2 * sizeof(double), 0, "double_complex");
2794 builtin_type_fixed_dec = make_type(TYPE_CODE_INT, sizeof(int),
2795 0, "fixed_decimal");
2796 builtin_type_float_dec = make_type(TYPE_CODE_FLT, sizeof(double),
2797 0, "floating_decimal");
2799 /* Templates types */
2800 builtin_type_struct = make_type(TYPE_CODE_STRUCT, 0, 0, 0);
2801 builtin_type_union = make_type(TYPE_CODE_UNION, 0, 0, 0);
2802 builtin_type_enum = make_type(TYPE_CODE_ENUM, 0, 0, 0);
2803 builtin_type_range = make_type(TYPE_CODE_RANGE, 0, 0, 0);
2804 builtin_type_set = make_type(TYPE_CODE_SET, 0, 0, 0);
2806 /* We can't do this now because builtin_type_void may not
2807 be set yet. Do it at symbol reading time. */
2808 /* builtin_type_ptr = lookup_pointer_type (builtin_type_void); */