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. */
39 #include <sys/param.h>
47 #include <mips/syms.h>
51 #endif /* not CMUCS */
56 struct external_filehdr f;
57 struct external_aouthdr a;
60 /* Things we import explicitly from other modules */
62 extern int info_verbose;
63 extern struct block *block_for_pc();
64 extern void sort_symtab_syms();
66 /* Various complaints about symbol reading that don't abort the process */
68 struct complaint unknown_ext_complaint =
69 {"unknown external symbol %s", 0, 0};
71 struct complaint unknown_sym_complaint =
72 {"unknown local symbol %s", 0, 0};
74 struct complaint unknown_st_complaint =
75 {"with type %d", 0, 0};
77 struct complaint block_overflow_complaint =
78 {"block containing %s overfilled", 0, 0};
80 struct complaint basic_type_complaint =
81 {"cannot map MIPS basic type 0x%x", 0, 0};
83 struct complaint unknown_type_qual_complaint =
84 {"unknown type qualifier 0x%x", 0, 0};
86 struct complaint array_bitsize_complaint =
87 {"size of array target type not known, assuming %d bits", 0, 0};
89 struct complaint array_parse_complaint =
90 {"array type with strange relative symbol", 0, 0};
92 /* Macros and extra defs */
94 /* Already-parsed symbols are marked specially */
96 #define stParsed stType
98 /* Puns: hard to find whether -g was used and how */
100 #define MIN_GLEVEL GLEVEL_0
101 #define compare_glevel(a,b) \
102 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
103 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
105 /* When looking at .o files, avoid tripping over bad addresses */
107 #define SAFE_TEXT_ADDR 0x400000
108 #define SAFE_DATA_ADDR 0x10000000
110 #define UNSAFE_DATA_ADDR(p) ((unsigned)p < SAFE_DATA_ADDR || (unsigned)p > 2*SAFE_DATA_ADDR)
112 /* Things that really are local to this module */
114 /* GDB symtable for the current compilation unit */
116 static struct symtab *cur_stab;
118 /* MIPS symtab header for the current file */
120 static HDRR *cur_hdr;
122 /* Pointer to current file decriptor record, and its index */
127 /* Index of current symbol */
131 /* Note how much "debuggable" this image is. We would like
132 to see at least one FDR with full symbols */
137 /* When examining .o files, report on undefined symbols */
139 static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;
141 /* Extra builtin types */
143 struct type *builtin_type_complex;
144 struct type *builtin_type_double_complex;
145 struct type *builtin_type_fixed_dec;
146 struct type *builtin_type_float_dec;
147 struct type *builtin_type_string;
151 static struct type *builtin_type_ptr;
152 static struct type *builtin_type_struct;
153 static struct type *builtin_type_union;
154 static struct type *builtin_type_enum;
155 static struct type *builtin_type_range;
156 static struct type *builtin_type_set;
158 /* Forward declarations */
160 static struct symbol *new_symbol();
161 static struct type *new_type();
162 static struct field *new_field();
163 static struct block *new_block();
164 static struct symtab *new_symtab();
165 static struct linetable *new_linetable();
166 static struct blockvector *new_bvect();
168 static struct type *parse_type();
169 static struct type *make_type();
170 static struct symbol *mylookup_symbol();
171 static struct block *shrink_block();
173 static int compare_symtabs();
174 static int compare_psymtabs();
175 static int compare_blocks();
177 static struct partial_symtab *new_psymtab();
178 static struct partial_symtab *parse_fdr();
179 static int compare_psymbols();
181 static void psymtab_to_symtab_1();
182 static void add_block();
183 static void add_symbol();
184 static int add_line();
185 static void reorder_symtabs();
186 static void reorder_psymtabs();
187 static void shrink_linetable();
189 /* Things we export to other modules */
191 /* Address bounds for the signal trampoline in inferior, if any */
192 /* FIXME: Nothing really seems to use this. Why is it here? */
194 CORE_ADDR sigtramp_address, sigtramp_end;
196 /* The entry point (starting address) of the file, if it is an executable. */
198 static CORE_ADDR entry_point;
200 extern CORE_ADDR startup_file_start; /* From blockframe.c */
201 extern CORE_ADDR startup_file_end; /* From blockframe.c */
206 /* If we have a file symbol header lying around, blow it away. */
208 free ((char *)cur_hdr);
213 mipscoff_symfile_init (sf)
216 bfd *abfd = sf->sym_bfd;
217 sf->sym_private = NULL;
219 /* Save startup file's range of PC addresses to help blockframe.c
220 decide where the bottom of the stack is. */
221 if (bfd_get_file_flags (abfd) & EXEC_P)
223 /* Executable file -- record its entry point so we'll recognize
224 the startup file because it contains the entry point. */
225 entry_point = bfd_get_start_address (abfd);
229 /* Examination of non-executable.o files. Short-circuit this stuff. */
230 /* ~0 will not be in any file, we hope. */
232 /* set the startup file to be an empty range. */
233 startup_file_start = 0;
234 startup_file_end = 0;
239 mipscoff_symfile_read(sf, addr, mainline)
244 struct coff_symfile_info *info = (struct coff_symfile_info *)sf->sym_private;
245 bfd *abfd = sf->sym_bfd;
246 char *name = bfd_get_filename (abfd);
250 int stringtab_offset;
252 /* Initialize a variable that we couldn't do at _initialize_ time. */
253 builtin_type_ptr = lookup_pointer_type (builtin_type_void);
255 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
256 desc = fileno ((FILE *)(abfd->iostream)); /* Raw file descriptor */
259 /* Position to read the symbol table. */
260 val = lseek (desc, (long)symtab_offset, 0);
262 perror_with_name (name);
264 init_misc_bunches ();
265 make_cleanup (discard_misc_bunches, 0);
267 /* Now that the executable file is positioned at symbol table,
268 process it and define symbols accordingly. */
270 read_mips_symtab(abfd, desc);
272 /* Go over the misc symbol bunches and install them in vector. */
274 condense_misc_bunches (!mainline);
277 /* Exported procedure: Allocate zeroed memory */
282 char *p = xmalloc(size);
288 /* Exported procedure: Builds a symtab from the PST partial one.
289 Restores the environment in effect when PST was created, delegates
290 most of the work to an ancillary procedure, and sorts
291 and reorders the symtab list at the end */
294 mipscoff_psymtab_to_symtab(pst)
295 struct partial_symtab *pst;
304 printf_filtered("Reading in symbols for %s...", pst->filename);
307 /* Restore the header and list of pending typedefs */
308 /* FIXME, we should use private data that is a proper pointer. */
309 cur_hdr = (HDRR *) pst->ldsymlen;
311 psymtab_to_symtab_1(pst, pst->filename);
316 printf_filtered("done.\n");
319 /* Exported procedure: Is PC in the signal trampoline code */
322 in_sigtramp(pc, name)
326 if (sigtramp_address == 0)
328 return (pc >= sigtramp_address && pc < sigtramp_end);
331 /* File-level interface functions */
333 /* Read the symtab information from file FSYM into memory. Also,
334 return address just past end of our text segment in *END_OF_TEXT_SEGP. */
337 read_the_mips_symtab(abfd, fsym, end_of_text_segp)
340 CORE_ADDR *end_of_text_segp;
342 int stsize, st_hdrsize;
345 /* Header for executable/object file we read symbols from */
346 struct coff_exec filhdr;
348 /* We get here with DESC pointing to the symtab header. But we need
349 * other info from the initial headers */
351 myread(fsym, &filhdr, sizeof filhdr);
353 if (end_of_text_segp)
355 bfd_h_get_32 (abfd, filhdr.a.text_start) +
356 bfd_h_get_32 (abfd, filhdr.a.tsize);
358 /* Find and read the symbol table header */
359 st_hdrsize = bfd_h_get_32 (abfd, filhdr.f.f_nsyms);
360 st_filptr = bfd_h_get_32 (abfd, filhdr.f.f_symptr);
364 lseek(fsym, st_filptr, L_SET);
365 if (st_hdrsize > sizeof (st_hdr)) /* Profanity check */
367 if (read(fsym, &st_hdr, st_hdrsize) != st_hdrsize)
370 /* Find out how large the symbol table is */
371 stsize = (st_hdr.cbExtOffset - (st_filptr + st_hdrsize))
372 + st_hdr.iextMax * cbEXTR;
374 /* Allocate space for the symbol table. Read it in. */
375 cur_hdr = (HDRR *) xmalloc(stsize + st_hdrsize);
377 bcopy(&st_hdr, cur_hdr, st_hdrsize);
378 if (read(fsym, (char *) cur_hdr + st_hdrsize, stsize) != stsize)
381 /* Fixup file_pointers in it */
382 fixup_symtab(cur_hdr, (char *) cur_hdr + st_hdrsize,
383 st_filptr + st_hdrsize);
387 error("Short read on %s", symfile);
391 /* Turn all file-relative pointers in the symtab described by HDR
392 into memory pointers, given that the symtab itself is located
393 at DATA in memory and F_PTR in the file. */
396 fixup_symtab( hdr, data, f_ptr)
408 * These fields are useless (and empty) by now:
409 * hdr->cbDnOffset, hdr->cbOptOffset
410 * We use them for other internal purposes.
413 hdr->cbOptOffset = 0;
416 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
432 * Fix all string pointers inside the symtab, and
433 * the FDR records. Also fix other miscellany.
435 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
436 register unsigned code_offset;
438 /* Header itself, and strings */
439 fh = (FDR *) (hdr->cbFdOffset) + f_idx;
440 fh->issBase += hdr->cbSsOffset;
442 fh->rss = (long)fh->rss + fh->issBase;
443 for (s_idx = 0; s_idx < fh->csym; s_idx++) {
444 sh = (SYMR*)(hdr->cbSymOffset) + fh->isymBase + s_idx;
445 sh->iss = (long) sh->iss + fh->issBase;
452 fh->isymBase = (int)((SYMR*)(hdr->cbSymOffset)+fh->isymBase);
454 /* cannot fix fh->ipdFirst because it is a short */
455 #define IPDFIRST(h,fh) \
456 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
458 /* Optional symbols (actually used for partial_symtabs) */
464 fh->iauxBase = hdr->cbAuxOffset + fh->iauxBase * sizeof(AUXU);
465 /* Relative file descriptor table */
466 fh->rfdBase = hdr->cbRfdOffset + fh->rfdBase * sizeof(RFDT);
470 fh->cbLineOffset += hdr->cbLineOffset;
472 /* Procedure symbols. (XXX This should be done later) */
473 code_offset = fh->adr;
474 for (s_idx = 0; s_idx < fh->cpd; s_idx++) {
475 unsigned name, only_ext;
477 pr = (PDR*)(IPDFIRST(hdr,fh)) + s_idx;
479 /* Simple rule to find files linked "-x" */
480 only_ext = fh->rss == -1;
482 if (pr->isym == -1) {
483 /* static function */
487 name = hdr->cbExtOffset + pr->isym * sizeof(EXTR);
488 sh = &((EXTR*)name)->asym;
492 sh = (SYMR*)fh->isymBase + pr->isym;
493 /* Included code ? */
494 if (s_idx == 0 && pr->adr != 0)
495 code_offset -= pr->adr;
498 /* Turn index into a pointer */
501 /* Fix line numbers */
502 pr->cbLineOffset += fh->cbLineOffset;
504 /* Relocate address */
506 pr->adr += code_offset;
510 /* External symbols: fix string */
511 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
512 esh = (EXTR*)(hdr->cbExtOffset) + s_idx;
513 esh->asym.iss = esh->asym.iss + hdr->cbSsExtOffset;
518 /* Find a file descriptor given its index RF relative to a file CF */
526 f = (FDR *) (cur_hdr->cbFdOffset) + cf;
527 /* Object files do not have the RFD table, all refs are absolute */
529 return (FDR *) (cur_hdr->cbFdOffset) + rf;
530 cf = *((pRFDT) f->rfdBase + rf);
531 return (FDR *) (cur_hdr->cbFdOffset) + cf;
534 /* Return a safer print NAME for a file descriptor */
540 if (name == (char *) -1)
541 return "<stripped file>";
542 if (UNSAFE_DATA_ADDR(name))
548 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
549 whether we are adding to the general symtab or not.
550 FIXME: INCREMENTAL is currently always zero, though it should not be. */
553 read_mips_symtab (abfd, desc)
557 CORE_ADDR end_of_text_seg;
559 read_the_mips_symtab(abfd, desc, &end_of_text_seg);
561 parse_partial_symbols(end_of_text_seg);
564 * Check to make sure file was compiled with -g.
565 * If not, warn the user of this limitation.
567 if (compare_glevel(max_glevel, GLEVEL_2) < 0) {
568 if (max_gdbinfo == 0)
569 printf("\n%s not compiled with -g, debugging support is limited.", symfile);
570 printf("\nYou should compile with -g2 or -g3 for best debugging support.\n");
575 /* Local utilities */
577 /* Map of FDR indexes to partial symtabs */
579 static struct pst_map {
580 struct partial_symtab *pst; /* the psymtab proper */
581 int n_globals; /* globals it exports */
582 int n_statics; /* statics (locals) it contains */
586 /* Utility stack, used to nest procedures and blocks properly.
587 It is a doubly linked list, to avoid too many alloc/free.
588 Since we might need it quite a few times it is NOT deallocated
591 static struct parse_stack {
592 struct parse_stack *next, *prev;
593 struct symtab *cur_st; /* Current symtab */
594 struct block *cur_block; /* Block in it */
595 int blocktype; /* What are we parsing */
596 int maxsyms; /* Max symbols in this block */
597 struct type *cur_type; /* Type we parse fields for */
598 int procadr; /* Start addres of this procedure */
599 int numargs; /* Its argument count */
600 } *top_stack; /* Top stack ptr */
603 /* Enter a new lexical context */
605 static push_parse_stack()
607 struct parse_stack *new;
609 /* Reuse frames if possible */
610 if (top_stack && top_stack->prev)
611 new = top_stack->prev;
613 new = (struct parse_stack *) xzalloc(sizeof(struct parse_stack));
614 /* Initialize new frame with previous content */
616 register struct parse_stack *prev = new->prev;
619 top_stack->prev = new;
621 new->next = top_stack;
626 /* Exit a lexical context */
628 static pop_parse_stack()
633 top_stack = top_stack->next;
637 /* Cross-references might be to things we haven't looked at
638 yet, e.g. type references. To avoid too many type
639 duplications we keep a quick fixup table, an array
640 of lists of references indexed by file descriptor */
642 static struct pending {
643 struct pending *next; /* link */
644 SYMR *s; /* the symbol */
645 struct type *t; /* its partial type descriptor */
649 /* Check whether we already saw symbol SH in file FH as undefined */
652 struct pending *is_pending_symbol(fh, sh)
656 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
657 register struct pending *p;
659 /* Linear search is ok, list is typically no more than 10 deep */
660 for (p = pending_list[f_idx]; p; p = p->next)
666 /* Check whether we already saw type T in file FH as undefined */
669 struct pending *is_pending_type(fh, t)
673 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
674 register struct pending *p;
676 for (p = pending_list[f_idx]; p; p = p->next)
682 /* Add a new undef symbol SH of type T */
685 add_pending(fh, sh, t)
690 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
691 struct pending *p = is_pending_symbol(fh, sh);
693 /* Make sure we do not make duplicates */
695 p = (struct pending *) xmalloc(sizeof(*p));
698 p->next = pending_list[f_idx];
699 pending_list[f_idx] = p;
701 sh->reserved = 1; /* for quick check */
704 /* Throw away undef entries when done with file index F_IDX */
709 register struct pending *p, *q;
711 for (p = pending_list[f_idx]; p; p = q) {
715 pending_list[f_idx] = 0;
718 /* The number of args to a procedure is not explicit in the symtab,
719 this is the list of all those we know of.
720 This makes parsing more reasonable and avoids extra passes */
722 static struct numarg {
723 struct numarg *next; /* link */
724 unsigned adr; /* procedure's start address */
725 unsigned num; /* arg count */
728 /* Record that the procedure at ADR takes NUM arguments. */
733 struct numarg *n = (struct numarg *) xmalloc(sizeof(struct numarg));
737 n->next = numargs_list;
741 /* See if we know how many arguments the procedure at ADR takes */
746 struct numarg *n = numargs_list;
748 while (n && n->adr != adr)
750 return (n) ? n->num : -1;
753 /* Release storage when done with this file */
758 struct numarg *n = numargs_list, *m;
769 /* Parsing Routines proper. */
771 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
772 For blocks, procedures and types we open a new lexical context.
773 This is basically just a big switch on the symbol's type */
784 /* When a symbol is cross-referenced from other files/symbols
785 we mark it explicitly */
786 int pend = (sh->reserved == 1);
787 enum address_class class;
794 case stGlobal: /* external symbol, goes into global block */
796 b = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st),
798 s = new_symbol(sh->iss);
799 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
802 case stStatic: /* static data, goes into current block. */
804 b = top_stack->cur_block;
805 s = new_symbol(sh->iss);
806 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
809 case stLocal: /* local variable, goes into current block */
810 if (sh->sc == scRegister) {
811 class = LOC_REGISTER;
816 b = top_stack->cur_block;
817 s = new_symbol(sh->iss);
818 SYMBOL_VALUE(s) = sh->value;
820 data: /* Common code for symbols describing data */
821 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
822 SYMBOL_CLASS(s) = class;
825 /* Type could be missing in a number of cases */
826 if (sh->sc == scUndefined || sh->sc == scNil ||
827 sh->index == 0xfffff)
828 SYMBOL_TYPE(s) = builtin_type_int; /* undefined? */
830 SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0);
831 /* Value of a data symbol is its memory address */
834 case stParam: /* arg to procedure, goes into current block */
836 top_stack->numargs++;
837 s = new_symbol(sh->iss);
838 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
839 if (sh->sc == scRegister) {
840 SYMBOL_CLASS(s) = LOC_REGPARM;
844 SYMBOL_CLASS(s) = LOC_ARG;
845 SYMBOL_VALUE(s) = sh->value;
846 SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0);
847 add_symbol(s, top_stack->cur_block);
849 /* FIXME: This has not been tested. See dbxread.c */
850 /* Add the type of this parameter to the function/procedure
851 type of this block. */
852 add_param_to_type(&top_stack->cur_block->function->type,s);
856 case stLabel: /* label, goes into current block */
857 s = new_symbol(sh->iss);
858 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE; /* so that it can be used */
859 SYMBOL_CLASS(s) = LOC_LABEL; /* but not misused */
860 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
861 SYMBOL_TYPE(s) = builtin_type_int;
862 add_symbol(s, top_stack->cur_block);
865 case stProc: /* Procedure, usually goes into global block */
866 case stStaticProc: /* Static procedure, goes into current block */
867 s = new_symbol(sh->iss);
868 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
869 SYMBOL_CLASS(s) = LOC_BLOCK;
870 /* Type of the return value */
871 if (sh->sc == scUndefined || sh->sc == scNil)
872 t = builtin_type_int;
874 t = parse_type(ax + sh->index, sh, 0);
875 b = top_stack->cur_block;
876 if (sh->st == stProc) {
877 struct blockvector *bv = BLOCKVECTOR(top_stack->cur_st);
878 /* The next test should normally be true,
879 but provides a hook for nested functions
880 (which we don't want to make global). */
881 if (b == BLOCKVECTOR_BLOCK(bv, STATIC_BLOCK))
882 b = BLOCKVECTOR_BLOCK(bv, GLOBAL_BLOCK);
886 /* Make a type for the procedure itself */
888 /* FIXME: This has not been tested yet! See dbxread.c */
889 /* Generate a template for the type of this function. The
890 types of the arguments will be added as we read the symbol
892 bcopy(SYMBOL_TYPE(s),lookup_function_type(t),sizeof(struct type));
894 SYMBOL_TYPE(s) = lookup_function_type (t);
897 /* Create and enter a new lexical context */
898 b = new_block(top_stack->maxsyms);
899 SYMBOL_BLOCK_VALUE(s) = b;
900 BLOCK_FUNCTION(b) = s;
901 BLOCK_START(b) = BLOCK_END(b) = sh->value;
902 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
903 add_block(b, top_stack->cur_st);
905 /* Not if we only have partial info */
906 if (sh->sc == scUndefined || sh->sc == scNil)
910 top_stack->cur_block = b;
911 top_stack->blocktype = sh->st;
912 top_stack->cur_type = SYMBOL_TYPE(s);
913 top_stack->procadr = sh->value;
914 top_stack->numargs = 0;
916 sh->value = (long) SYMBOL_TYPE(s);
919 case stBlock: /* Either a lexical block, or some type */
921 top_stack->blocktype = stBlock;
922 if (sh->sc == scInfo) { /* structure/union/enum def */
923 s = new_symbol(sh->iss);
924 SYMBOL_NAMESPACE(s) = STRUCT_NAMESPACE;
925 SYMBOL_CLASS(s) = LOC_TYPEDEF;
927 add_symbol(s, top_stack->cur_block);
928 /* If this type was expected, use its partial definition */
930 t = is_pending_symbol(cur_fdr, sh)->t;
932 /* Uhmm, can`t decide yet. Smash later */
933 t = new_type(sh->iss);
934 TYPE_CODE(t) = TYPE_CODE_UNDEF;
935 add_pending(cur_fdr, sh, t);
938 /* make this the current type */
939 top_stack->cur_type = t;
940 TYPE_LENGTH(t) = sh->value;
941 /* Mark that symbol has a type, and say which one */
942 sh->value = (long) t;
944 /* beginnning of (code) block. Value of symbol
945 is the displacement from procedure start */
946 b = new_block(top_stack->maxsyms);
947 BLOCK_START(b) = sh->value + top_stack->procadr;
948 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
949 top_stack->cur_block = b;
950 add_block(b, top_stack->cur_st);
954 case stEnd: /* end (of anything) */
955 if (sh->sc == scInfo) {
956 /* Finished with type */
957 top_stack->cur_type = 0;
958 } else if (sh->sc == scText &&
959 (top_stack->blocktype == stProc ||
960 top_stack->blocktype == stStaticProc)) {
961 /* Finished with procedure */
962 struct blockvector *bv = BLOCKVECTOR(top_stack->cur_st);
966 BLOCK_END(top_stack->cur_block) += sh->value; /* size */
967 got_numargs(top_stack->procadr, top_stack->numargs);
968 /* Reallocate symbols, saving memory */
969 b = shrink_block(top_stack->cur_block, top_stack->cur_st);
971 /* f77 emits proc-level with address bounds==[0,0],
972 So look for such child blocks, and patch them. */
973 for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++) {
974 struct block *b_bad = BLOCKVECTOR_BLOCK(bv,i);
975 if (BLOCK_SUPERBLOCK(b_bad) == b
976 && BLOCK_START(b_bad) == top_stack->procadr
977 && BLOCK_END(b_bad) == top_stack->procadr) {
978 BLOCK_START(b_bad) = BLOCK_START(b);
979 BLOCK_END(b_bad) = BLOCK_END(b);
982 if (entry_point < BLOCK_END(b)
983 && entry_point >= BLOCK_START(b)) {
984 startup_file_start = BLOCK_START(b);
985 startup_file_end = BLOCK_END(b);
987 } else if (sh->sc == scText && top_stack->blocktype == stBlock) {
988 /* End of (code) block. The value of the symbol
989 is the displacement from the procedure`s start
990 address of the end of this block. */
991 BLOCK_END(top_stack->cur_block) = sh->value + top_stack->procadr;
992 (void) shrink_block(top_stack->cur_block, top_stack->cur_st);
994 pop_parse_stack(); /* restore previous lexical context */
997 case stMember: /* member of struct/union/enum.. */
998 f = new_field(top_stack->cur_type, sh->iss);
999 f->bitpos = sh->value;
1000 f->type = parse_type(ax + sh->index, sh, &f->bitsize);
1003 case stTypedef: /* type definition */
1004 s = new_symbol(sh->iss);
1005 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
1006 SYMBOL_CLASS(s) = LOC_TYPEDEF;
1007 SYMBOL_BLOCK_VALUE(s) = top_stack->cur_block;
1008 add_symbol(s, top_stack->cur_block);
1009 SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0);
1010 sh->value = (long) SYMBOL_TYPE(s);
1013 case stFile: /* file name */
1015 top_stack->blocktype = sh->st;
1018 /* I`ve never seen these for C */
1020 break; /* register relocation */
1022 break; /* forwarding address */
1024 break; /* constant */
1026 error("Unknown symbol type %x.", sh->st);
1031 /* Parse the type information provided in the AX entries for
1032 the symbol SH. Return the bitfield size in BS, in case. */
1034 static struct type *parse_type(ax, sh, bs)
1039 /* Null entries in this map are treated specially */
1040 static struct type **map_bt[] =
1042 &builtin_type_void, /* btNil */
1044 &builtin_type_char, /* btChar */
1045 &builtin_type_unsigned_char, /* btUChar */
1046 &builtin_type_short, /* btShort */
1047 &builtin_type_unsigned_short, /* btUShort */
1048 &builtin_type_int, /* btInt */
1049 &builtin_type_unsigned_int, /* btUInt */
1050 &builtin_type_long, /* btLong */
1051 &builtin_type_unsigned_long, /* btULong */
1052 &builtin_type_float, /* btFloat */
1053 &builtin_type_double, /* btDouble */
1060 &builtin_type_complex, /* btComplex */
1061 &builtin_type_double_complex, /* btDComplex */
1063 &builtin_type_fixed_dec, /* btFixedDec */
1064 &builtin_type_float_dec, /* btFloatDec */
1065 &builtin_type_string, /* btString */
1068 &builtin_type_void, /* btVoid */
1072 struct type *tp = 0, *tp1;
1075 /* Procedures start off by one */
1076 if (sh->st == stProc || sh->st == stStaticProc)
1079 /* Undefined ? Should not happen */
1080 if (ax->rndx.rfd == 0xfff) {
1081 return builtin_type_void;
1084 /* Use aux as a type information record, map its basic type */
1086 if (t->bt > 26 || t->bt == btPicture) {
1087 complain (&basic_type_complaint, t->bt);
1088 return builtin_type_int;
1091 tp = *map_bt[t->bt];
1093 /* Cannot use builtin types, use templates */
1094 tp = make_type(TYPE_CODE_VOID, 0, 0, 0);
1097 *tp = *builtin_type_ptr;
1100 *tp = *builtin_type_struct;
1104 *tp = *builtin_type_union;
1108 *tp = *builtin_type_enum;
1112 *tp = *builtin_type_range;
1115 *tp = *builtin_type_set;
1121 /* Move on to next aux */
1124 /* This is the way it would work if the compiler worked */
1125 register TIR *t1 = t;
1126 while (t1->continued)
1130 /* For bitfields all we need is the width */
1136 /* All these types really point to some (common) MIPS type
1137 definition, and only the type-qualifiers fully identify
1138 them. We`ll make the same effort at sharing */
1139 if (t->bt == btIndirect ||
1140 t->bt == btStruct ||
1143 t->bt == btTypedef ||
1146 char name[256], *pn;
1148 /* Try to cross reference this type */
1150 ax += cross_ref(ax, &tp1, &pn);
1151 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1152 sprintf(name, fmt, pn);
1154 /* reading .o file ? */
1155 if (UNSAFE_DATA_ADDR(tp1))
1157 if (TYPE_CODE(tp1) == TYPE_CODE_UNDEF) {
1159 * Type was incompletely defined, now we know.
1161 TYPE_CODE(tp1) = TYPE_CODE(tp);
1162 TYPE_NAME(tp1) = obsavestring(name, strlen(name));
1163 if (TYPE_CODE(tp1) == TYPE_CODE_ENUM) {
1166 for (i = 0; i < TYPE_NFIELDS(tp1); i++)
1167 make_enum_constant(&TYPE_FIELD(tp1,i), tp1);
1171 /* found as cross ref, rid of our template */
1172 if ((TYPE_FLAGS(tp) & TYPE_FLAG_PERM) == 0)
1175 /* stupid idea of prepending "struct" to type names */
1176 if (t->bt == btStruct && !index(TYPE_NAME(tp), ' ')) {
1177 sprintf(name, fmt, TYPE_NAME(tp));
1178 TYPE_NAME(tp) = obsavestring(name, strlen(name));
1181 TYPE_NAME(tp) = savestring(name, strlen(name));
1184 /* Deal with range types */
1185 if (t->bt == btRange) {
1188 f = new_field(tp, "Low");
1189 f->bitpos = ax->dnLow;
1191 f = new_field(tp, "High");
1192 f->bitpos = ax->dnHigh;
1196 /* Parse all the type qualifiers now. If there are more
1197 than 6 the game will continue in the next aux */
1199 #define PARSE_TQ(tq) \
1200 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, sh);
1202 again: PARSE_TQ(tq0);
1217 /* Make up a complex type from a basic one. Type is passed by
1218 reference in TPP and side-effected as necessary. The type
1219 qualifier TQ says how to handle the aux symbols at AX for
1220 the symbol SX we are currently analyzing.
1221 Returns the number of aux symbols we parsed. */
1224 upgrade_type(tpp, tq, ax, sh)
1232 /* Used in array processing */
1241 t = lookup_pointer_type (*tpp);
1246 t = lookup_function_type (*tpp);
1252 t = make_type(TYPE_CODE_ARRAY, 0, 0, 0);
1253 TYPE_TARGET_TYPE(t) = *tpp;
1255 /* Determine and record the domain type (type of index) */
1256 id = ax->rndx.index;
1262 fh = get_rfd(cur_fd, rf);
1263 f = new_field(t, (char *)0);
1264 bzero(&ss, sizeof ss);
1265 /* XXX */ f->type = parse_type(fh->iauxBase + id * sizeof(AUXU),
1270 * This seems to be a pointer to the end of the Block defining
1271 * the type. Why it is here is magic for me, and I have no
1272 * good use for it anyways.
1274 /* This used to occur because cross_ref returned
1275 the wrong result (ax pointed wrong). FIXME,
1276 delete this code in a while. -- gnu@cygnus jul91 */
1277 complain (&array_parse_complaint, 0);
1279 id = (++ax)->rndx.index;
1280 if ((rf = ax->rndx.rfd) == 0xfff)
1281 rf = (++ax)->isym, off++;
1283 lower = (++ax)->dnLow;
1284 upper = (++ax)->dnHigh;
1285 rf = (++ax)->width; /* bit size of array element */
1287 /* Check whether supplied array element bit size matches
1288 the known size of the element type. If this complaint
1289 ends up not happening, we can remove this code. It's
1290 here because we aren't sure we understand this *&%&$
1292 id = TYPE_LENGTH(TYPE_TARGET_TYPE(t)) << 3; /* bitsize */
1294 /* Most likely an undefined type */
1296 TYPE_LENGTH(TYPE_TARGET_TYPE(t)) = id >> 3;
1299 complain (&array_bitsize_complaint, rf);
1301 TYPE_LENGTH(t) = (upper < 0) ? 0 :
1302 (upper - lower + 1) * (rf >> 3);
1307 /* Volatile -- currently ignored */
1311 complain (&unknown_type_qual_complaint, tq);
1317 /* Parse a procedure descriptor record PR. Note that the procedure
1318 is parsed _after_ the local symbols, now we just make up the
1319 extra information we need into a special symbol that we insert
1320 in the procedure's main block. Note also that images that
1321 have been partially stripped (ld -x) have been deprived
1322 of local symbols, and we have to cope with them here.
1323 The procedure's code ends at BOUND */
1326 parse_procedure(pr, bound)
1329 struct symbol *s, *i;
1330 SYMR *sh = (SYMR*)pr->isym;
1332 struct mips_extra_func_info *e;
1336 /* Reuse the MIPS record */
1337 e = (struct mips_extra_func_info *) pr;
1338 e->numargs = lookup_numargs(pr->adr);
1340 /* Make up our special symbol */
1341 i = new_symbol(".gdbinfo.");
1342 SYMBOL_VALUE(i) = (int)e;
1343 SYMBOL_NAMESPACE(i) = LABEL_NAMESPACE;
1344 SYMBOL_CLASS(i) = LOC_CONST;
1345 SYMBOL_TYPE(i) = builtin_type_void;
1347 /* Make up a name for static procedures. Sigh. */
1348 if (sh == (SYMR*)-1) {
1349 sprintf(name,".static_procedure@%x",pr->adr);
1350 sh_name = savestring(name, strlen(name));
1354 sh_name = (char*)sh->iss;
1355 s = mylookup_symbol(sh_name, top_stack->cur_block,
1356 VAR_NAMESPACE, LOC_BLOCK);
1359 b = SYMBOL_BLOCK_VALUE(s);
1361 s = new_symbol(sh_name);
1362 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
1363 SYMBOL_CLASS(s) = LOC_BLOCK;
1364 /* Donno its type, hope int is ok */
1365 SYMBOL_TYPE(s) = lookup_function_type (builtin_type_int);
1366 add_symbol(s, top_stack->cur_block);
1367 /* Wont have symbols for this one */
1369 SYMBOL_BLOCK_VALUE(s) = b;
1370 BLOCK_FUNCTION(b) = s;
1371 BLOCK_START(b) = pr->adr;
1372 BLOCK_END(b) = bound;
1373 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
1374 add_block(b, top_stack->cur_st);
1380 /* Parse the external symbol ES. Just call parse_symbol() after
1381 making sure we know where the aux are for it. For procedures,
1382 parsing of the PDRs has already provided all the needed
1383 information, we only parse them if SKIP_PROCEDURES is false,
1384 and only if this causes no symbol duplication.
1386 This routine clobbers top_stack->cur_block and ->cur_st. */
1389 parse_external(es, skip_procedures)
1394 if (es->ifd != ifdNil) {
1396 cur_fdr = (FDR*)(cur_hdr->cbFdOffset) + cur_fd;
1397 ax = (AUXU*)cur_fdr->iauxBase;
1399 cur_fdr = (FDR*)(cur_hdr->cbFdOffset);
1402 top_stack->cur_st = cur_stab;
1403 top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st),
1406 /* Reading .o files */
1407 if (es->asym.sc == scUndefined || es->asym.sc == scNil) {
1409 switch (es->asym.st) {
1411 case stProc: what = "procedure"; n_undef_procs++; break;
1412 case stGlobal: what = "variable"; n_undef_vars++; break;
1413 case stLabel: what = "label"; n_undef_labels++; break;
1414 default : what = "symbol"; break;
1418 printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what,
1419 es->asym.iss, fdr_name(cur_fdr->rss));
1423 switch (es->asym.st) {
1425 /* If we have full symbols we do not need more */
1426 if (skip_procedures)
1428 if (mylookup_symbol (es->asym.iss, top_stack->cur_block,
1429 VAR_NAMESPACE, LOC_BLOCK))
1435 * Note that the case of a symbol with indexNil
1436 * must be handled anyways by parse_symbol().
1438 parse_symbol(&es->asym, ax);
1445 /* Parse the line number info for file descriptor FH into
1446 GDB's linetable LT. MIPS' encoding requires a little bit
1447 of magic to get things out. Note also that MIPS' line
1448 numbers can go back and forth, apparently we can live
1449 with that and do not need to reorder our linetables */
1454 struct linetable *lt;
1456 unsigned char *base = (unsigned char*)fh->cbLineOffset;
1458 int delta, count, lineno = 0;
1464 /* Scan by procedure descriptors */
1465 i = 0; j = 0, k = 0;
1466 for (pr = (PDR*)IPDFIRST(cur_hdr,fh); j < fh->cpd; j++, pr++) {
1469 /* No code for this one */
1470 if (pr->iline == ilineNil ||
1471 pr->lnLow == -1 || pr->lnHigh == -1)
1474 * Aurgh! To know where to stop expanding we
1477 for (l = 1; l < (fh->cpd - j); l++)
1478 if (pr[l].iline != -1)
1480 if (l == (fh->cpd - j))
1485 * When procedures are moved around the linenumbers
1486 * are attributed to the next procedure up
1488 if (pr->iline >= halt) continue;
1490 base = (unsigned char*)pr->cbLineOffset;
1491 l = pr->adr >> 2; /* in words */
1492 halt += (pr->adr >> 2) - pr->iline;
1493 for (lineno = pr->lnLow; l < halt;) {
1494 count = *base & 0x0f;
1495 delta = *base++ >> 4;
1499 delta = (base[0] << 8) | base[1];
1502 lineno += delta;/* first delta is 0 */
1503 k = add_line(lt, lineno, l, k);
1510 /* Parse the symbols of the file described by FH, whose index is F_IDX.
1511 BOUND is the highest core address of this file's procedures */
1514 parse_one_file(fh, f_idx, bound)
1521 /* Parse local symbols first */
1523 for (s_idx = 0; s_idx < fh->csym; s_idx++) {
1524 sh = (SYMR *) (fh->isymBase) + s_idx;
1526 parse_symbol(sh, fh->iauxBase);
1529 /* Procedures next, note we need to look-ahead to
1530 find out where the procedure's code ends */
1532 for (s_idx = 0; s_idx < fh->cpd-1; s_idx++) {
1533 pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + s_idx;
1534 parse_procedure(pr, pr[1].adr); /* next proc up */
1537 pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + s_idx;
1538 parse_procedure(pr, bound); /* next file up */
1541 /* Linenumbers. At the end, check if we can save memory */
1542 parse_lines(fh, LINETABLE(cur_stab));
1543 if (LINETABLE(cur_stab)->nitems < fh->cline)
1544 shrink_linetable(cur_stab);
1547 /* Master parsing procedure for first-pass reading of file symbols
1548 into a partial_symtab.
1550 Parses the symtab described by the global symbolic header CUR_HDR.
1551 END_OF_TEXT_SEG gives the address just after the text segment for
1552 the symtab we are reading. */
1555 parse_partial_symbols(end_of_text_seg)
1556 int end_of_text_seg;
1558 int f_idx, s_idx, h_max, stat_idx;
1559 CORE_ADDR dummy, *prevhigh;
1561 /* Running pointers */
1566 struct partial_symtab *pst;
1571 * Only parse the Local and External symbols, and the Relative FDR.
1572 * Fixup enough of the loader symtab to be able to use it.
1573 * Allocate space only for the file's portions we need to
1579 max_glevel = MIN_GLEVEL;
1581 /* Allocate the map FDR -> PST.
1582 Minor hack: -O3 images might claim some global data belongs
1583 to FDR -1. We`ll go along with that */
1584 fdr_to_pst = (struct pst_map *)xzalloc((hdr->ifdMax+1) * sizeof *fdr_to_pst);
1587 struct partial_symtab * pst = new_psymtab("");
1588 fdr_to_pst[-1].pst = pst;
1592 /* Now scan the FDRs, mostly for dependencies */
1593 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
1594 (void) parse_fdr(f_idx, 1);
1596 /* Take a good guess at how many symbols we might ever need */
1597 h_max = hdr->iextMax;
1599 /* Parse externals: two passes because they can be ordered
1600 in any way, but gdb likes to have them segregated by their
1603 /* Pass 1 over external syms: Presize and partition the list */
1604 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
1605 esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
1606 fdr_to_pst[esh->ifd].n_globals++;
1609 if (global_psymbols.list) {
1610 int origsize = global_psymbols.next - global_psymbols.list;
1612 global_psymbols.list = (struct partial_symbol *)
1613 xrealloc (global_psymbols.list,
1614 (h_max + origsize) * sizeof(struct partial_symbol));
1615 global_psymbols.next = global_psymbols.list + origsize;
1616 global_psymbols.size = h_max + origsize;
1618 global_psymbols.list = (struct partial_symbol *)
1619 xmalloc (h_max * sizeof(struct partial_symbol));
1620 global_psymbols.next = global_psymbols.list;
1621 global_psymbols.size = h_max;
1624 /* Pass 1.5 over files: partition out global symbol space */
1625 s_idx = global_psymbols.next - global_psymbols.list;
1626 for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++) {
1627 fdr_to_pst[f_idx].pst->globals_offset = s_idx;
1628 s_idx += fdr_to_pst[f_idx].n_globals;
1631 /* Pass 1.6 over files: partition out static symbol space.
1632 Note that this loop starts at 0, not at -1. */
1633 stat_idx = static_psymbols.next - static_psymbols.list;
1634 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
1635 fdr_to_pst[f_idx].pst->statics_offset = stat_idx;
1636 fh = f_idx + (FDR *)(hdr->cbFdOffset);
1637 stat_idx += fh->csym;
1640 /* Now that we know its max size, allocate static symbol list */
1641 if (static_psymbols.list) {
1642 int origsize = static_psymbols.next - static_psymbols.list;
1644 static_psymbols.list = (struct partial_symbol *)
1645 xrealloc (static_psymbols.list,
1646 stat_idx * sizeof(struct partial_symbol));
1647 static_psymbols.next = static_psymbols.list + origsize;
1648 static_psymbols.size = stat_idx;
1650 static_psymbols.list = (struct partial_symbol *)
1651 xmalloc (stat_idx * sizeof(struct partial_symbol));
1652 static_psymbols.next = static_psymbols.list;
1653 static_psymbols.size = stat_idx;
1656 /* Pass 2 over external syms: fill in external symbols */
1657 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
1658 register struct partial_symbol *p;
1659 enum misc_function_type misc_type = mf_text;
1660 esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
1662 if (esh->asym.sc == scUndefined || esh->asym.sc == scNil)
1665 /* Locate the psymtab and the preallocated psymbol. */
1666 pst = fdr_to_pst[esh->ifd].pst;
1667 p = global_psymbols.list + pst->globals_offset +
1668 pst->n_global_syms++;
1669 SYMBOL_NAME(p) = (char *)(esh->asym.iss);
1670 SYMBOL_NAMESPACE(p) = VAR_NAMESPACE;
1672 switch (esh->asym.st) {
1674 SYMBOL_CLASS(p) = LOC_BLOCK;
1675 SYMBOL_VALUE(p) = esh->asym.value;
1678 SYMBOL_CLASS(p) = LOC_STATIC;
1679 SYMBOL_VALUE_ADDRESS(p) = (CORE_ADDR)esh->asym.value;
1680 misc_type = mf_data;
1683 SYMBOL_CLASS(p) = LOC_LABEL;
1684 SYMBOL_VALUE_ADDRESS(p) = (CORE_ADDR)esh->asym.value;
1687 misc_type = mf_unknown;
1688 complain (&unknown_ext_complaint, SYMBOL_NAME(p));
1690 prim_record_misc_function (SYMBOL_NAME(p),
1695 /* Pass 3 over files, over local syms: fill in static symbols */
1696 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
1697 fh = f_idx + (FDR *)(cur_hdr->cbFdOffset);
1698 pst = fdr_to_pst[f_idx].pst;
1700 for (s_idx = 0; s_idx < fh->csym; ) {
1701 register struct partial_symbol *p;
1703 sh = s_idx + (SYMR *) fh->isymBase;
1705 if (sh->sc == scUndefined || sh->sc == scNil) {
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)
1727 case stStatic: /* Variable */
1728 SYMBOL_CLASS(p) = LOC_STATIC;
1729 SYMBOL_VALUE_ADDRESS(p) = (CORE_ADDR)sh->value;
1731 case stTypedef: /* Typedef */
1732 SYMBOL_CLASS(p) = LOC_TYPEDEF;
1734 case stConstant: /* Constant decl */
1735 SYMBOL_CLASS(p) = LOC_CONST;
1737 case stBlock: /* { }, str, un, enum */
1738 /* Eventually we want struct names and enum
1739 values out of here. FIXME */
1740 /* Skip over the block */
1743 case stFile: /* File headers */
1744 case stLabel: /* Labels */
1745 case stEnd: /* Ends of files */
1748 complain (&unknown_sym_complaint, SYMBOL_NAME(p));
1749 complain (&unknown_st_complaint, sh->st);
1753 pst->n_static_syms++; /* Use this gdb symbol */
1755 s_idx++; /* Go to next file symbol */
1757 /* We don't usually record static syms, but some we seem to. chk dbxread. */
1758 /*FIXME*/ prim_record_misc_function (SYMBOL_NAME(p),
1765 /* The array (of lists) of globals must be sorted.
1766 Take care, since we are at it, of pst->texthigh.
1768 NOTE: The way we handle textlow/high is incorrect, but good
1769 enough for a first approximation. The case we fail is on a
1770 file "foo.c" that looks like
1772 #include "bar.c" -- this contains proc2()
1774 where proc3() is attributed to bar.c. But since this is a
1775 dependent file it will cause loading of foo.c as well, so
1776 everything will be fine at the end. */
1778 /* First, sort the psymtabs by their textlow addresses. */
1781 /* Now, rip through and fill in "texthigh" from the textlow
1782 of the following psymtab. Slimy but it might work.
1783 Sort the global psymbols while we're at it. */
1785 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
1786 struct partial_symtab *pst = fdr_to_pst[f_idx].pst;
1787 if (pst->n_global_syms > 1)
1788 qsort (global_psymbols.list + pst->globals_offset,
1789 pst->n_global_syms, sizeof (struct partial_symbol),
1792 *prevhigh = pst->textlow;
1793 prevhigh = &pst->texthigh;
1797 /* Mark the last code address, and remember it for later */
1798 *prevhigh = end_of_text_seg;
1799 hdr->cbDnOffset = end_of_text_seg;
1801 free(&fdr_to_pst[-1]);
1806 /* Do the initial analisys of the F_IDX-th file descriptor.
1807 Allocates a partial symtab for it, and builds the list
1808 of dependent files by recursion. LEV says at which level
1809 of recursion we are called (to pretty up debug traces) */
1811 static struct partial_symtab *
1812 parse_fdr(f_idx, lev)
1816 register struct partial_symtab *pst;
1819 fh = (FDR *) (cur_hdr->cbFdOffset) + f_idx;
1821 /* Use this to indicate into which symtab this file was parsed */
1823 return (struct partial_symtab *) fh->ioptBase;
1825 /* Debuggability level */
1826 if (compare_glevel(max_glevel, fh->glevel) < 0)
1827 max_glevel = fh->glevel;
1829 /* Make a new partial_symtab */
1830 pst = new_psymtab(fh->rss);
1835 pst->textlow = fh->adr;
1836 pst->texthigh = fh->cpd; /* To be fixed later */
1839 /* Make everything point to everything. */
1840 pst->ldsymoff = f_idx;
1841 fdr_to_pst[f_idx].pst = pst;
1842 fh->ioptBase = (int)pst;
1844 /* Analyze its dependencies */
1849 if (fh->cpd == 0) { /* If there are no functions defined here ... */
1850 /* ...then presumably a .h file: drop reverse depends .h->.c */
1851 for (; s_id0 < fh->crfd; s_id0++) {
1852 RFDT *rh = (RFDT *) (fh->rfdBase) + s_id0;
1854 s_id0++; /* Skip self-dependency */
1859 pst->number_of_dependencies = fh->crfd - s_id0;
1860 pst->dependencies = (struct partial_symtab **)
1861 obstack_alloc (psymbol_obstack,
1862 pst->number_of_dependencies *
1863 sizeof (struct partial_symtab *));
1864 for (s_idx = s_id0; s_idx < fh->crfd; s_idx++) {
1865 RFDT *rh = (RFDT *) (fh->rfdBase) + s_idx;
1867 pst->dependencies[s_idx-s_id0] = parse_fdr(*rh, lev+1);
1874 /* Ancillary function to psymtab_to_symtab(). Does all the work
1875 for turning the partial symtab PST into a symtab, recurring
1876 first on all dependent psymtabs. The argument FILENAME is
1877 only passed so we can see in debug stack traces what file
1881 psymtab_to_symtab_1(pst, filename)
1882 struct partial_symtab *pst;
1893 pending_list = (struct pending **) cur_hdr->cbOptOffset;
1894 if (pending_list == 0) {
1895 pending_list = (struct pending **)
1896 xzalloc(cur_hdr->ifdMax * sizeof(struct pending *));
1897 cur_hdr->cbOptOffset = (int)pending_list;
1900 /* How many symbols will we need */
1901 /* FIXME, this does not count enum values. */
1902 f_max = pst->n_global_syms + pst->n_static_syms;
1903 if (pst->ldsymoff == -1) {
1905 st = new_symtab( "unknown", f_max, 0);
1907 fh = (FDR *) (cur_hdr->cbFdOffset) + pst->ldsymoff;
1908 f_max += fh->csym + fh->cpd;
1909 st = new_symtab(pst->filename, 2 * f_max, 2 * fh->cline);
1912 /* Read in all partial symbtabs on which this one is dependent.
1913 NOTE that we do have circular dependencies, sigh. We solved
1914 that by setting pst->readin before this point. */
1916 for (i = 0; i < pst->number_of_dependencies; i++)
1917 if (!pst->dependencies[i]->readin) {
1918 /* Inform about additional files to be read in. */
1921 fputs_filtered (" ", stdout);
1923 fputs_filtered ("and ", stdout);
1925 printf_filtered ("%s...",
1926 pst->dependencies[i]->filename);
1927 wrap_here (""); /* Flush output */
1930 /* We only pass the filename for debug purposes */
1931 psymtab_to_symtab_1(pst->dependencies[i],
1932 pst->dependencies[i]->filename);
1935 /* Now read the symbols for this symtab */
1937 cur_fd = pst->ldsymoff;
1941 /* Get a new lexical context */
1944 top_stack->cur_st = cur_stab;
1945 top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab),
1947 BLOCK_START(top_stack->cur_block) = fh ? fh->adr : 0;
1948 BLOCK_END(top_stack->cur_block) = 0;
1949 top_stack->blocktype = stFile;
1950 top_stack->maxsyms = 2*f_max;
1951 top_stack->cur_type = 0;
1952 top_stack->procadr = 0;
1953 top_stack->numargs = 0;
1955 /* Parse locals and procedures */
1957 parse_one_file(fh, cur_fd, (cur_fd == (cur_hdr->ifdMax - 1)) ?
1958 cur_hdr->cbDnOffset : fh[1].adr);
1960 /* .. and our share of externals.
1961 XXX use the global list to speed up things here. how ?
1962 FIXME, Maybe quit once we have found the right number of ext's? */
1963 /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
1964 top_stack->blocktype = stFile;
1965 top_stack->maxsyms = cur_hdr->isymMax + cur_hdr->ipdMax + cur_hdr->iextMax;
1966 for (i = 0; i < cur_hdr->iextMax; i++) {
1967 register EXTR *esh = (EXTR *) (cur_hdr->cbExtOffset) + i;
1968 if (esh->ifd == cur_fd)
1969 parse_external(esh, 1);
1972 /* If there are undefined, tell the user */
1973 if (n_undef_symbols) {
1974 printf_filtered("File %s contains %d unresolved references:",
1975 st->filename, n_undef_symbols);
1976 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
1977 n_undef_vars, n_undef_procs, n_undef_labels);
1978 n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
1984 * Sort the symbol table now, we are done adding symbols to it.
1986 sort_symtab_syms(st);
1988 /* Now link the psymtab and the symtab. */
1992 /* Ancillary parsing procedures. */
1994 /* Lookup the type at relative index RN. Return it in TPP
1995 if found and in any event come up with its name PNAME.
1996 Return value says how many aux symbols we ate */
1999 cross_ref(rn, tpp, pname)
2006 /* Escape index means 'the next one' */
2007 if (rn->rfd == 0xfff)
2008 rf = *(unsigned *) (rn + 1);
2014 *pname = "<undefined>";
2017 * Find the relative file descriptor and the symbol in it
2019 FDR *fh = get_rfd(cur_fd, rf);
2024 * If we have processed this symbol then we left a forwarding
2025 * pointer to the corresponding GDB symbol. If not, we`ll put
2026 * it in a list of pending symbols, to be processed later when
2027 * the file f will be. In any event, we collect the name for
2028 * the type here. Which is why we made a first pass at
2031 sh = (SYMR *) (fh->isymBase) + rn->index;
2033 /* Careful, we might be looking at .o files */
2034 *pname = (UNSAFE_DATA_ADDR(sh->iss)) ? "<undefined>" :
2037 /* Have we parsed it ? */
2038 if ((!UNSAFE_DATA_ADDR(sh->value)) && (sh->st == stParsed)) {
2039 t = (struct type *) sh->value;
2044 /* Avoid duplicates */
2045 p = is_pending_symbol(fh, sh);
2050 add_pending(fh, sh, *tpp);
2054 /* We used one auxent normally, two if we got a "next one" rf. */
2055 return (rn->rfd == 0xfff? 2: 1);
2059 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2060 keeping the symtab sorted */
2062 static struct symbol *
2063 mylookup_symbol (name, block, namespace, class)
2065 register struct block *block;
2066 enum namespace namespace;
2067 enum address_class class;
2069 register int bot, top, inc;
2070 register struct symbol *sym;
2073 top = BLOCK_NSYMS(block);
2076 sym = BLOCK_SYM(block, bot);
2077 if (SYMBOL_NAME(sym)[0] == inc
2078 && SYMBOL_NAMESPACE(sym) == namespace
2079 && SYMBOL_CLASS(sym) == class
2080 && !strcmp(SYMBOL_NAME(sym), name))
2084 if (block = BLOCK_SUPERBLOCK (block))
2085 return mylookup_symbol (name, block, namespace, class);
2090 /* Add a new symbol S to a block B.
2091 Infrequently, we will need to reallocate the block to make it bigger.
2092 We only detect this case when adding to top_stack->cur_block, since
2093 that's the only time we know how big the block is. FIXME. */
2100 int nsyms = BLOCK_NSYMS(b)++;
2101 struct block *origb;
2102 struct parse_stack *stackp;
2104 if (b == top_stack->cur_block &&
2105 nsyms >= top_stack->maxsyms) {
2106 complain (&block_overflow_complaint, s->name);
2107 /* In this case shrink_block is actually grow_block, since
2108 BLOCK_NSYMS(b) is larger than its current size. */
2110 b = shrink_block (top_stack->cur_block, top_stack->cur_st);
2112 /* Now run through the stack replacing pointers to the
2113 original block. shrink_block has already done this
2114 for the blockvector and BLOCK_FUNCTION. */
2115 for (stackp = top_stack; stackp; stackp = stackp->next) {
2116 if (stackp->cur_block == origb) {
2117 stackp->cur_block = b;
2118 stackp->maxsyms = BLOCK_NSYMS (b);
2122 BLOCK_SYM(b,nsyms) = s;
2125 /* Add a new block B to a symtab S */
2132 struct blockvector *bv = BLOCKVECTOR(s);
2134 bv = (struct blockvector *)xrealloc(bv, sizeof(struct blockvector) +
2135 BLOCKVECTOR_NBLOCKS(bv) * sizeof(bv->block));
2136 if (bv != BLOCKVECTOR(s))
2137 BLOCKVECTOR(s) = bv;
2139 BLOCKVECTOR_BLOCK(bv, BLOCKVECTOR_NBLOCKS(bv)++) = b;
2142 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2143 MIPS' linenumber encoding might need more than one byte
2144 to describe it, LAST is used to detect these continuation lines */
2147 add_line(lt, lineno, adr, last)
2148 struct linetable *lt;
2154 last = -2; /* make sure we record first line */
2156 if (last == lineno) /* skip continuation lines */
2159 lt->item[lt->nitems].line = lineno;
2160 lt->item[lt->nitems++].pc = adr << 2;
2166 /* Comparison functions, used when sorting things */
2168 /* Symtabs must be ordered viz the code segments they cover */
2171 compare_symtabs( s1, s2)
2172 struct symtab **s1, **s2;
2174 /* "most specific" first */
2176 register struct block *b1, *b2;
2177 b1 = BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1),GLOBAL_BLOCK);
2178 b2 = BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2),GLOBAL_BLOCK);
2179 if (BLOCK_END(b1) == BLOCK_END(b2))
2180 return BLOCK_START(b1) - BLOCK_START(b2);
2181 return BLOCK_END(b1) - BLOCK_END(b2);
2185 /* Partial Symtabs, same */
2188 compare_psymtabs( s1, s2)
2189 struct partial_symtab **s1, **s2;
2191 /* Perf twist: put the ones with no code at the end */
2193 register int a = (*s1)->textlow;
2194 register int b = (*s2)->textlow;
2203 /* Partial symbols are compared lexicog by their print names */
2206 compare_psymbols (s1, s2)
2207 register struct partial_symbol *s1, *s2;
2210 *st1 = SYMBOL_NAME(s1),
2211 *st2 = SYMBOL_NAME(s2);
2213 return (st1[0] - st2[0] ? st1[0] - st2[0] :
2214 strcmp(st1 + 1, st2 + 1));
2217 /* Blocks with a smaller low bound should come first */
2219 static int compare_blocks(b1,b2)
2220 struct block **b1, **b2;
2222 register int addr_diff;
2224 addr_diff = (BLOCK_START((*b1))) - (BLOCK_START((*b2)));
2226 return (BLOCK_END((*b1))) - (BLOCK_END((*b2)));
2231 /* Sorting and reordering procedures */
2233 /* Sort the blocks of a symtab S.
2234 Reorder the blocks in the blockvector by code-address,
2235 as required by some MI search routines */
2241 struct blockvector *bv = BLOCKVECTOR(s);
2243 if (BLOCKVECTOR_NBLOCKS(bv) <= 2) {
2245 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) == 0)
2246 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = 0;
2247 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) == 0)
2248 BLOCK_START(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) = 0;
2252 * This is very unfortunate: normally all functions are compiled in
2253 * the order they are found, but if the file is compiled -O3 things
2254 * are very different. It would be nice to find a reliable test
2255 * to detect -O3 images in advance.
2257 if (BLOCKVECTOR_NBLOCKS(bv) > 3)
2258 qsort(&BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK),
2259 BLOCKVECTOR_NBLOCKS(bv) - FIRST_LOCAL_BLOCK,
2260 sizeof(struct block *),
2264 register CORE_ADDR high = 0;
2265 register int i, j = BLOCKVECTOR_NBLOCKS(bv);
2267 for (i = FIRST_LOCAL_BLOCK; i < j; i++)
2268 if (high < BLOCK_END(BLOCKVECTOR_BLOCK(bv,i)))
2269 high = BLOCK_END(BLOCKVECTOR_BLOCK(bv,i));
2270 BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = high;
2273 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) =
2274 BLOCK_START(BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK));
2276 BLOCK_START(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) =
2277 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK));
2278 BLOCK_END (BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) =
2279 BLOCK_END (BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK));
2282 /* Sort the symtab list, as required by some search procedures.
2283 We want files ordered to make them look right to users, and for
2284 searching (see block_for_pc). */
2290 struct symtab *stab;
2291 register struct symtab **all_symtabs;
2292 register int symtab_count;
2297 /* Create an array of pointers to all the symtabs. */
2298 for (symtab_count = 0, stab = symtab_list;
2300 symtab_count++, stab = stab->next) {
2301 obstack_grow (psymbol_obstack, &stab, sizeof (stab));
2302 /* FIXME: Only sort blocks for new symtabs ??? */
2306 all_symtabs = (struct symtab **)
2307 obstack_base (psymbol_obstack);
2308 qsort((char *)all_symtabs, symtab_count,
2309 sizeof(struct symtab *), compare_symtabs);
2311 /* Re-construct the symtab list, but now it is sorted. */
2312 for (i = 0; i < symtab_count-1; i++)
2313 all_symtabs[i]->next = all_symtabs[i+1];
2314 all_symtabs[i]->next = 0;
2315 symtab_list = all_symtabs[0];
2317 obstack_free (psymbol_obstack, all_symtabs);
2320 /* Sort the partial symtab list, as required by some search procedures.
2321 PC lookups stop at the first psymtab such that textlow <= PC < texthigh */
2327 register int all_psymtabs_count;
2328 struct partial_symtab *pstab;
2329 struct partial_symtab **all_psymtabs;
2331 if (!partial_symtab_list)
2334 /* Create an array of pointers to all the partial_symtabs. */
2336 for (all_psymtabs_count = 0, pstab = partial_symtab_list;
2338 all_psymtabs_count++, pstab = pstab->next)
2339 obstack_grow (psymbol_obstack, &pstab, sizeof (pstab));
2341 all_psymtabs = (struct partial_symtab **)
2342 obstack_base (psymbol_obstack);
2344 qsort((char *)all_psymtabs, all_psymtabs_count,
2345 sizeof(struct partial_symtab *), compare_psymtabs);
2347 /* Re-construct the partial_symtab_list, but now it is sorted. */
2349 for (i = 0; i < all_psymtabs_count-1; i++)
2350 all_psymtabs[i]->next = all_psymtabs[i+1];
2351 all_psymtabs[i]->next = 0;
2352 partial_symtab_list = all_psymtabs[0];
2354 obstack_free (psymbol_obstack, all_psymtabs);
2357 /* Constructor/restructor/destructor procedures */
2359 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2360 MAXSYMS and linenumbers MAXLINES we'll put in it */
2364 new_symtab(name, maxsyms, maxlines)
2367 struct symtab *s = allocate_symtab (name);
2369 LINETABLE(s) = new_linetable(maxlines);
2371 /* All symtabs must have at least two blocks */
2372 BLOCKVECTOR(s) = new_bvect(2);
2373 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK) = new_block(maxsyms);
2374 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), STATIC_BLOCK) = new_block(maxsyms);
2375 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s),STATIC_BLOCK)) =
2376 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK);
2378 s->free_code = free_linetable;
2380 /* Link the new symtab into the list of such. */
2381 s->next = symtab_list;
2387 /* Allocate a new partial_symtab NAME */
2389 static struct partial_symtab *
2393 struct partial_symtab *pst;
2395 pst = (struct partial_symtab *)
2396 obstack_alloc (psymbol_obstack, sizeof (*pst));
2397 bzero (pst, sizeof (*pst));
2399 if (name == (char*)-1) /* FIXME -- why not null here? */
2400 pst->filename = "<no name>";
2402 pst->filename = name;
2404 pst->next = partial_symtab_list;
2405 partial_symtab_list = pst;
2407 /* Keep a backpointer to the file's symbols */
2408 /* FIXME, we should use private data that is a proper pointer. */
2409 pst->ldsymlen = (int)cur_hdr;
2411 /* The way to turn this into a symtab is to call... */
2412 pst->read_symtab = mipscoff_psymtab_to_symtab;
2418 /* Allocate a linetable array of the given SIZE */
2421 struct linetable *new_linetable(size)
2423 struct linetable *l;
2425 size = size * sizeof(l->item) + sizeof(struct linetable);
2426 l = (struct linetable *)xmalloc(size);
2431 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2432 I am not so sure about the 3.4 ones */
2438 struct linetable *l = new_linetable(LINETABLE(s)->nitems);
2440 bcopy(LINETABLE(s), l,
2441 LINETABLE(s)->nitems * sizeof(l->item) + sizeof(struct linetable));
2442 free (LINETABLE(s));
2446 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2449 struct blockvector *
2452 struct blockvector *bv;
2455 size = sizeof(struct blockvector) + nblocks * sizeof(struct block*);
2456 bv = (struct blockvector *) xzalloc(size);
2458 BLOCKVECTOR_NBLOCKS(bv) = nblocks;
2463 /* Allocate and zero a new block of MAXSYMS symbols */
2469 int size = sizeof(struct block) + (maxsyms-1) * sizeof(struct symbol *);
2470 struct block *b = (struct block *)xzalloc(size);
2475 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2476 Shrink_block can also be used by add_symbol to grow a block. */
2478 static struct block *
2484 struct blockvector *bv = BLOCKVECTOR(s);
2487 /* Just reallocate it and fix references to the old one */
2489 new = (struct block *) xrealloc ((char *)b, sizeof(struct block) +
2490 (BLOCK_NSYMS(b)-1) * sizeof(struct symbol *));
2492 /* Should chase pointers to old one. Fortunately, that`s just
2493 the block`s function and inferior blocks */
2494 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b)
2495 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2496 for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++)
2497 if (BLOCKVECTOR_BLOCK(bv,i) == b)
2498 BLOCKVECTOR_BLOCK(bv,i) = new;
2499 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) == b)
2500 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) = new;
2504 /* Create a new symbol with printname NAME */
2511 struct symbol *s = (struct symbol *)
2512 obstack_alloc (symbol_obstack, sizeof (struct symbol));
2514 bzero (s, sizeof (*s));
2515 SYMBOL_NAME(s) = name;
2519 /* Create a new type with printname NAME */
2526 struct type *t = (struct type *)
2527 obstack_alloc (symbol_obstack, sizeof (struct type));
2529 bzero (t, sizeof (*t));
2530 TYPE_NAME(t) = name;
2534 /* Create and initialize a new type with printname NAME.
2535 CODE and LENGTH are the initial info we put in,
2536 UNS says whether the type is unsigned or not. */
2540 make_type(code, length, uns, name)
2541 enum type_code code;
2545 register struct type *type;
2547 type = (struct type *) xzalloc(sizeof(struct type));
2548 TYPE_CODE(type) = code;
2549 TYPE_LENGTH(type) = length;
2550 TYPE_FLAGS(type) = uns ? TYPE_FLAG_UNSIGNED : 0;
2551 TYPE_NAME(type) = name;
2556 /* Allocate a new field named NAME to the type TYPE */
2560 new_field(type,name)
2566 /* Fields are kept in an array */
2567 if (TYPE_NFIELDS(type))
2568 TYPE_FIELDS(type) = (struct field*)xrealloc(TYPE_FIELDS(type),
2569 (TYPE_NFIELDS(type)+1) * sizeof(struct field));
2571 TYPE_FIELDS(type) = (struct field*)xzalloc(sizeof(struct field));
2572 f = &(TYPE_FIELD(type,TYPE_NFIELDS(type)));
2573 TYPE_NFIELDS(type)++;
2574 bzero(f, sizeof(struct field));
2575 f->name = name; /* Whether or not NAME is zero, this works. */
2579 /* Make an enum constant for a member F of an enumerated type T */
2582 make_enum_constant(f,t)
2588 * This is awful, but that`s the way it is supposed to be
2589 * (BTW, no need to free the real 'type', it's a builtin)
2591 f->type = (struct type *) f->bitpos;
2593 s = new_symbol(f->name);
2594 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
2595 SYMBOL_CLASS(s) = LOC_CONST;
2597 SYMBOL_VALUE(s) = f->bitpos;
2598 add_symbol(s, top_stack->cur_block);
2603 /* Things used for calling functions in the inferior.
2604 These functions are exported to our companion
2605 mips-dep.c file and are here because they play
2606 with the symbol-table explicitly. */
2609 /* Need to make a new symbol on the fly for the dummy
2610 frame we put on the stack. Which goes in the.. */
2612 static struct symtab *dummy_symtab;
2614 /* Make up a dummy symbol for the code we put at END_PC,
2615 of size SIZE, invoking a function with NARGS arguments
2616 and using a frame of FRAMESIZE bytes */
2618 mips_create_dummy_symbol(end_pc, size, nargs, framesize)
2622 struct mips_extra_func_info *gdbinfo;
2624 /* Allocate symtab if not done already */
2625 if (dummy_symtab == 0)
2626 dummy_symtab = new_symtab(".dummy_symtab.", 100, 0);
2628 /* Make a new block. Only needs one symbol */
2630 BLOCK_START(bl) = end_pc - size;
2631 BLOCK_END(bl) = end_pc;
2633 BLOCK_SUPERBLOCK(bl) =
2634 BLOCKVECTOR_BLOCK(BLOCKVECTOR(dummy_symtab),GLOBAL_BLOCK);
2635 add_block(bl, dummy_symtab);
2636 sort_blocks(dummy_symtab);
2638 BLOCK_FUNCTION(bl) = new_symbol("??");
2639 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(bl)) = bl;
2640 g = new_symbol(".gdbinfo.");
2641 BLOCK_SYM(bl,BLOCK_NSYMS(bl)++) = g;
2643 SYMBOL_NAMESPACE(g) = LABEL_NAMESPACE;
2644 SYMBOL_CLASS(g) = LOC_CONST;
2645 SYMBOL_TYPE(g) = builtin_type_void;
2646 gdbinfo = (struct mips_extra_func_info *)
2647 xzalloc(sizeof(struct mips_extra_func_info));
2649 SYMBOL_VALUE(g) = (long) gdbinfo;
2651 gdbinfo->numargs = nargs;
2652 gdbinfo->framesize = framesize;
2653 gdbinfo->framereg = 29;
2654 gdbinfo->pcreg = 31;
2655 gdbinfo->regmask = -2;
2656 gdbinfo->regoffset = -4;
2657 gdbinfo->fregmask = 0; /* XXX */
2658 gdbinfo->fregoffset = 0; /* XXX */
2661 /* We just returned from the dummy code at END_PC, drop its symbol */
2663 mips_destroy_dummy_symbol(end_pc)
2666 struct blockvector *bv = BLOCKVECTOR(dummy_symtab);
2669 bl = block_for_pc(end_pc);
2670 free(BLOCK_FUNCTION(bl));
2671 free(SYMBOL_VALUE(BLOCK_SYM(bl,0)));
2672 free(BLOCK_SYM(bl,0));
2674 for (i = FIRST_LOCAL_BLOCK; i < BLOCKVECTOR_NBLOCKS(bv); i++)
2675 if (BLOCKVECTOR_BLOCK(bv,i) == bl)
2677 for (; i < BLOCKVECTOR_NBLOCKS(bv) - 1; i++)
2678 BLOCKVECTOR_BLOCK(bv,i) = BLOCKVECTOR_BLOCK(bv,i+1);
2679 BLOCKVECTOR_NBLOCKS(bv)--;
2680 sort_blocks(dummy_symtab);
2685 /* Sigtramp: make sure we have all the necessary information
2686 about the signal trampoline code. Since the official code
2687 from MIPS does not do so, we make up that information ourselves.
2688 If they fix the library (unlikely) this code will neutralize itself. */
2695 struct block *b, *b0;
2697 sigtramp_address = -1;
2699 /* We know it is sold as sigvec */
2700 s = lookup_symbol("sigvec", 0, VAR_NAMESPACE, 0, NULL);
2702 /* Most programs do not play with signals */
2706 b0 = SYMBOL_BLOCK_VALUE(s);
2708 /* A label of sigvec, to be more precise */
2709 s = lookup_symbol("sigtramp", b0, VAR_NAMESPACE, 0, NULL);
2711 /* But maybe this program uses its own version of sigvec */
2715 sigtramp_address = SYMBOL_VALUE(s);
2716 sigtramp_end = sigtramp_address + 0x88; /* black magic */
2718 /* Did we or MIPSco fix the library ? */
2719 if (SYMBOL_CLASS(s) == LOC_BLOCK)
2722 /* But what symtab does it live in ? */
2723 st = find_pc_symtab(SYMBOL_VALUE(s));
2726 * Ok, there goes the fix: turn it into a procedure, with all the
2727 * needed info. Note we make it a nested procedure of sigvec,
2728 * which is the way the (assembly) code is actually written.
2730 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
2731 SYMBOL_CLASS(s) = LOC_BLOCK;
2732 SYMBOL_TYPE(s) = make_type(TYPE_CODE_FUNC, 4, 0, 0);
2733 TYPE_TARGET_TYPE(SYMBOL_TYPE(s)) = builtin_type_void;
2735 /* Need a block to allocate .gdbinfo. in */
2737 SYMBOL_BLOCK_VALUE(s) = b;
2738 BLOCK_START(b) = sigtramp_address;
2739 BLOCK_END(b) = sigtramp_end;
2740 BLOCK_FUNCTION(b) = s;
2741 BLOCK_SUPERBLOCK(b) = BLOCK_SUPERBLOCK(b0);
2745 /* Make a .gdbinfo. for it */
2747 struct mips_extra_func_info *e =
2748 (struct mips_extra_func_info *)
2749 xzalloc(sizeof(struct mips_extra_func_info));
2751 e->numargs = 0; /* the kernel thinks otherwise */
2752 /* align_longword(sigcontext + SIGFRAME) */
2753 e->framesize = 0x150;
2754 e->framereg = SP_REGNUM;
2757 e->regoffset = -(41 * sizeof(int));
2759 e->fregoffset = -(37 * sizeof(int));
2762 s = new_symbol(".gdbinfo.");
2763 SYMBOL_VALUE(s) = (int) e;
2764 SYMBOL_NAMESPACE(s) = LABEL_NAMESPACE;
2765 SYMBOL_CLASS(s) = LOC_CONST;
2766 SYMBOL_TYPE(s) = builtin_type_void;
2769 BLOCK_SYM(b,BLOCK_NSYMS(b)++) = s;
2772 /* Initialization */
2774 static struct sym_fns ecoff_sym_fns = {"ecoff", 5,
2775 mipscoff_new_init, mipscoff_symfile_init,
2776 mipscoff_symfile_read};
2778 _initialize_mipsread ()
2780 add_symtab_fns (&ecoff_sym_fns);
2782 /* Missing basic types */
2783 builtin_type_string = make_type(TYPE_CODE_PASCAL_ARRAY,
2785 builtin_type_complex = make_type(TYPE_CODE_FLT,
2786 2 * sizeof(float), 0, "complex");
2787 builtin_type_double_complex = make_type(TYPE_CODE_FLT,
2788 2 * sizeof(double), 0, "double_complex");
2789 builtin_type_fixed_dec = make_type(TYPE_CODE_INT, sizeof(int),
2790 0, "fixed_decimal");
2791 builtin_type_float_dec = make_type(TYPE_CODE_FLT, sizeof(double),
2792 0, "floating_decimal");
2794 /* Templates types */
2795 builtin_type_struct = make_type(TYPE_CODE_STRUCT, 0, 0, 0);
2796 builtin_type_union = make_type(TYPE_CODE_UNION, 0, 0, 0);
2797 builtin_type_enum = make_type(TYPE_CODE_ENUM, 0, 0, 0);
2798 builtin_type_range = make_type(TYPE_CODE_RANGE, 0, 0, 0);
2799 builtin_type_set = make_type(TYPE_CODE_SET, 0, 0, 0);
2801 /* We can't do this now because builtin_type_void may not
2802 be set yet. Do it at symbol reading time. */
2803 /* builtin_type_ptr = lookup_pointer_type (builtin_type_void); */