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. */
24 #include <sys/param.h>
32 #include <mips/syms.h>
36 #endif /* not CMUCS */
38 /* Since these things are defined differently on various systems I'll
39 (re)define here what I really need in this module. I only assume the
40 three standard COFF structure definitions: filehdr, aouthdr, scnhdr */
41 #define MIPS /* Kludge to get MIPS version of coff */
42 #undef _ETEXT /* Avoid duplicated define from <syms.h> */
46 struct external_filehdr f;
47 struct external_aouthdr a;
55 #define a_magic a.magic /* magic number */
56 #define a_text a.tsize /* size of text segment */
57 #define a_data a.dsize /* size of initialized data */
58 #define a_bss a.bsize /* size of uninitialized data */
59 #define a_syms f.f_nsyms /* size of symbol table */
60 #define a_entry a.entry /* entry point */
64 (((x).a_magic)!=OMAGIC && ((x).a_magic)!=NMAGIC && ((x).a_magic)!=ZMAGIC)
66 /* Things we import explicitly from other modules */
68 extern int info_verbose;
69 extern struct block *block_for_pc();
70 extern void sort_symtab_syms();
72 /* Forward declarations */
74 static void psymtab_to_symtab_1();
76 /* Macros and extra defs */
78 struct complaint unknown_ext_complaint =
79 {"unknown external symbol %s", 0, 0};
81 struct complaint unknown_sym_complaint =
82 {"unknown local symbol %s", 0, 0};
84 struct complaint unknown_st_complaint =
85 {"with type %d", 0, 0};
87 /* Already parsed symbols are marked specially */
89 #define stParsed stType
91 /* Puns: hard to find whether -g was used and how */
93 #define MIN_GLEVEL GLEVEL_0
94 #define compare_glevel(a,b) \
95 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
96 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
98 /* When looking at .o files avoid tripping over bad addresses */
100 #define SAFE_TEXT_ADDR 0x400000
101 #define SAFE_DATA_ADDR 0x10000000
103 #define UNSAFE_DATA_ADDR(p) ((unsigned)p < SAFE_DATA_ADDR || (unsigned)p > 2*SAFE_DATA_ADDR)
105 /* Things that really are local to this module */
107 /* GDB symtable for the current compilation unit */
109 static struct symtab *cur_stab;
111 /* Pointer to current file decriptor record, and its index */
116 /* Index of current symbol */
120 /* Note how much "debuggable" this image is. We would like
121 to see at least one FDR with full symbols */
126 /* When examining .o files, report on undefined symbols */
128 static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;
130 /* Extra builtin types */
132 struct type *builtin_type_complex;
133 struct type *builtin_type_double_complex;
134 struct type *builtin_type_fixed_dec;
135 struct type *builtin_type_float_dec;
136 struct type *builtin_type_string;
140 static struct type *builtin_type_ptr;
141 static struct type *builtin_type_struct;
142 static struct type *builtin_type_union;
143 static struct type *builtin_type_enum;
144 static struct type *builtin_type_range;
145 static struct type *builtin_type_set;
150 static struct symbol *new_symbol();
151 static struct type *new_type();
152 static struct field *new_field();
153 static struct block *new_block();
154 static struct symtab *new_symtab();
155 static struct linetable *new_linetable();
156 static struct blockvector *new_bvect();
158 static struct type *parse_type();
159 static struct type *make_type();
160 static struct symbol *mylookup_symbol();
161 static struct block *shrink_block();
163 static int compare_symtabs();
164 static int compare_psymtabs();
165 static int compare_blocks();
167 static struct partial_symtab *new_psymtab();
168 static struct partial_symtab *parse_fdr();
169 static int compare_psymbols();
171 static void reorder_symtabs();
172 static void reorder_psymtabs();
174 /* Things we export to other modules */
176 /* Address bounds for the signal trampoline in inferior, if any */
177 /* FIXME: Nothing really seems to use this. Why is it here? */
179 CORE_ADDR sigtramp_address, sigtramp_end;
182 /* Functions that we really export */
184 /* THIS DESCRIPTION IS OBSOLETE POST-BFD; FIXME! */
185 /* Basically, this module must provide two functions: symbol_file_command()
186 which loads the symbol table from a file, and add_file_command() which
187 adds more symbols to the symbol table (incrementally).
189 These two functions only do the minimum work necessary for letting the
190 user "name" things symbolically, they do not read the entire symtab.
191 Instead, they read in the external and static symbols and put them in partial
192 symbol tables. When more extensive information is requested of a
193 file the corresponding partial symbol table is mutated into a full
194 fledged symbol table by going back and reading the relative symbols
195 for real. mipscoff_psymtab_to_symtab() is the function that does this */
197 /* The entry point (starting address) of the file, if it is an executable. */
199 static CORE_ADDR entry_point;
201 extern CORE_ADDR startup_file_start; /* From blockframe.c */
202 extern CORE_ADDR startup_file_end; /* From blockframe.c */
210 mipscoff_symfile_init (sf)
213 bfd *abfd = sf->sym_bfd;
214 sf->sym_private = NULL;
215 /* Save startup file's range of PC addresses to help blockframe.c
216 decide where the bottom of the stack is. */
217 if (bfd_get_file_flags (abfd) & EXEC_P)
219 /* Executable file -- record its entry point so we'll recognize
220 the startup file because it contains the entry point. */
221 entry_point = bfd_get_start_address (abfd);
225 /* Examination of non-executable.o files. Short-circuit this stuff. */
226 /* ~0 will not be in any file, we hope. */
228 /* set the startup file to be an empty range. */
229 startup_file_start = 0;
230 startup_file_end = 0;
235 mipscoff_symfile_read(sf, addr, mainline)
240 struct coff_symfile_info *info = (struct coff_symfile_info *)sf->sym_private;
241 bfd *abfd = sf->sym_bfd;
242 char *name = bfd_get_filename (abfd);
247 int stringtab_offset;
249 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
250 desc = fileno ((FILE *)(abfd->iostream)); /* Raw file descriptor */
251 num_symbols = bfd_get_symcount (abfd); /* How many syms */
252 /* symtab_offset = obj_sym_filepos (abfd); * Symbol table file offset */
253 /* stringtab_offset = symtab_offset + num_symbols * SYMESZ; * String tab */
257 debug_info = text_hdr.s_relptr;
260 dc_terminate (tdesc_handle);
266 /* Read the line number table, all at once. */
267 info->min_lineno_offset = 0;
268 info->max_lineno_offset = 0;
269 bfd_map_over_sections (abfd, find_linenos, info);
271 val = init_lineno (desc, info->min_lineno_offset,
272 info->max_lineno_offset - info->min_lineno_offset);
274 error ("\"%s\": error reading line numbers\n", name);
276 /* Now read the string table, all at once. */
278 val = init_stringtab (desc, stringtab_offset);
281 free_all_symtabs (); /* FIXME blows whole symtab */
282 printf ("\"%s\": can't get string table", name);
286 make_cleanup (free_stringtab, 0);
289 /* Position to read the symbol table. Do not read it all at once. */
290 val = lseek (desc, (long)symtab_offset, 0);
292 perror_with_name (name);
294 init_misc_bunches ();
295 make_cleanup (discard_misc_bunches, 0);
297 /* Now that the executable file is positioned at symbol table,
298 process it and define symbols accordingly. */
300 read_mips_symtab(abfd, desc);
302 /* patch_opaque_types ();*/
304 /* Sort symbols alphabetically within each block. */
306 sort_all_symtab_syms ();
308 /* Go over the misc symbol bunches and install them in vector. */
310 condense_misc_bunches (0);
314 mipscoff_symfile_discard()
318 /* Exported procedure: Allocate zeroed memory */
322 char *p = xmalloc(size);
328 /* Exported procedure: Builds a symtab from the PST partial one.
329 Restores the environment in effect when PST was created, delegates
330 most of the work to an ancillary procedure, and sorts
331 and reorders the symtab list at the end */
334 static HDRR *cur_hdr; /* MIPS symtab header for the current file */
337 mipscoff_psymtab_to_symtab(pst)
338 struct partial_symtab *pst;
347 printf_filtered("Reading in symbols for %s...", pst->filename);
350 /* Restore the header and list of pending typedefs */
351 /* FIXME, we should use private data that is a proper pointer. */
352 cur_hdr = (HDRR *) pst->ldsymlen;
354 psymtab_to_symtab_1(pst);
358 /* Finish up the debug error message. */
360 printf_filtered("done.\n");
363 /* Exported procedure: Is PC in the signal trampoline code */
366 in_sigtramp(pc, name)
370 if (sigtramp_address == 0)
372 return (pc >= sigtramp_address && pc < sigtramp_end);
375 /* File-level interface functions */
377 /* Read the symtab information from file FSYM into memory. Also,
378 return address just past end of our text segment in *END_OF_TEXT_SEGP. */
381 read_the_mips_symtab(abfd, fsym, end_of_text_segp)
384 CORE_ADDR *end_of_text_segp;
386 int stsize, st_hdrsize;
389 /* Header for executable/object file we read symbols from */
390 struct coff_exec filhdr;
392 /* We get here with DESC pointing to the symtab header. But we need
393 * other info from the initial headers */
395 myread(fsym, &filhdr, sizeof filhdr);
397 if (end_of_text_segp)
399 bfd_h_get_32 (abfd, filhdr.a.text_start) +
400 bfd_h_get_32 (abfd, filhdr.a.tsize);
402 /* Find and read the symbol table header */
403 st_hdrsize = bfd_h_get_32 (abfd, filhdr.f.f_nsyms);
404 st_filptr = bfd_h_get_32 (abfd, filhdr.f.f_symptr);
408 lseek(fsym, st_filptr, L_SET);
409 if (st_hdrsize > sizeof (st_hdr)) /* Profanity check */
411 if (read(fsym, &st_hdr, st_hdrsize) != st_hdrsize)
414 /* Find out how large the symbol table is */
415 stsize = (st_hdr.cbExtOffset - (st_filptr + st_hdrsize))
416 + st_hdr.iextMax * cbEXTR;
418 /* Allocate space for the symbol table. Read it in. */
419 cur_hdr = (HDRR *) xmalloc(stsize + st_hdrsize);
421 bcopy(&st_hdr, cur_hdr, st_hdrsize);
422 if (read(fsym, (char *) cur_hdr + st_hdrsize, stsize) != stsize)
425 /* Fixup file_pointers in it */
426 fixup_symtab(cur_hdr, (char *) cur_hdr + st_hdrsize,
427 st_filptr + st_hdrsize);
431 error("Short read on %s", symfile);
435 /* Turn all file-relative pointers in the symtab described by HDR
436 into memory pointers, given that the symtab itself is located
437 at DATA in memory and F_PTR in the file. */
440 fixup_symtab( hdr, data, f_ptr)
452 * These fields are useless (and empty) by now:
453 * hdr->cbDnOffset, hdr->cbOptOffset
454 * We use them for other internal purposes.
457 hdr->cbOptOffset = 0;
460 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
476 * Fix all string pointers inside the symtab, and
477 * the FDR records. Also fix other miscellany.
479 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
480 register unsigned code_offset;
482 /* Header itself, and strings */
483 fh = (FDR *) (hdr->cbFdOffset) + f_idx;
484 fh->issBase += hdr->cbSsOffset;
486 fh->rss = (long)fh->rss + fh->issBase;
487 for (s_idx = 0; s_idx < fh->csym; s_idx++) {
488 sh = (SYMR*)(hdr->cbSymOffset) + fh->isymBase + s_idx;
489 sh->iss = (long) sh->iss + fh->issBase;
496 fh->isymBase = (int)((SYMR*)(hdr->cbSymOffset)+fh->isymBase);
498 /* cannot fix fh->ipdFirst because it is a short */
499 #define IPDFIRST(h,fh) \
500 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
502 /* Optional symbols (actually used for partial_symtabs) */
508 fh->iauxBase = hdr->cbAuxOffset + fh->iauxBase * sizeof(AUXU);
509 /* Relative file descriptor table */
510 fh->rfdBase = hdr->cbRfdOffset + fh->rfdBase * sizeof(RFDT);
514 fh->cbLineOffset += hdr->cbLineOffset;
516 /* Procedure symbols. (XXX This should be done later) */
517 code_offset = fh->adr;
518 for (s_idx = 0; s_idx < fh->cpd; s_idx++) {
519 unsigned name, only_ext;
521 pr = (PDR*)(IPDFIRST(hdr,fh)) + s_idx;
523 /* Simple rule to find files linked "-x" */
524 only_ext = fh->rss == -1;
526 if (pr->isym == -1) {
527 /* static function */
531 name = hdr->cbExtOffset + pr->isym * sizeof(EXTR);
532 sh = &((EXTR*)name)->asym;
536 sh = (SYMR*)fh->isymBase + pr->isym;
537 /* Included code ? */
538 if (s_idx == 0 && pr->adr != 0)
539 code_offset -= pr->adr;
542 /* Turn index into a pointer */
545 /* Fix line numbers */
546 pr->cbLineOffset += fh->cbLineOffset;
548 /* Relocate address */
550 pr->adr += code_offset;
554 /* External symbols: fix string */
555 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
556 esh = (EXTR*)(hdr->cbExtOffset) + s_idx;
557 esh->asym.iss = esh->asym.iss + hdr->cbSsExtOffset;
562 /* Find a file descriptor given its index RF relative to a file CF */
565 FDR *get_rfd( cf, rf)
569 f = (FDR *) (cur_hdr->cbFdOffset) + cf;
570 /* Object files do not have the RFD table, all refs are absolute */
572 return (FDR *) (cur_hdr->cbFdOffset) + rf;
573 cf = *((pRFDT) f->rfdBase + rf);
574 return (FDR *) (cur_hdr->cbFdOffset) + cf;
577 /* Return a safer print NAME for a file descriptor */
583 if (name == (char *) -1)
584 return "<stripped file>";
585 if (UNSAFE_DATA_ADDR(name))
591 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
592 whether we are adding to the general symtab or not.
593 FIXME: INCREMENTAL is currently always zero, though it should not be. */
596 read_mips_symtab (abfd, desc)
600 CORE_ADDR end_of_text_seg;
602 read_the_mips_symtab(abfd, desc, &end_of_text_seg);
604 parse_partial_symbols(cur_hdr, end_of_text_seg);
608 * Check to make sure file was compiled with -g.
609 * If not, warn the user of this limitation.
611 if (compare_glevel(max_glevel, GLEVEL_2) < 0) {
612 if (max_gdbinfo == 0)
613 printf("\n%s not compiled with -g, debugging support is limited.", symfile);
614 printf("\nYou should compile with -g2 or -g3 for best debugging support.\n");
619 * Dont allow char * to have a typename (else would get
622 TYPE_NAME(lookup_pointer_type(builtin_type_char)) = 0;
626 /* Local utilities */
629 /* Map of FDR indexes to partial symtabs */
631 static struct pst_map {
632 struct partial_symtab *pst; /* the psymtab proper */
633 int n_globals; /* globals it exports */
634 int n_statics; /* statics (locals) it contains */
638 /* Utility stack, used to nest procedures and blocks properly.
639 It is a doubly linked list, to avoid too many alloc/free.
640 Since we might need it quite a few times it is NOT deallocated
643 static struct parse_stack {
644 struct parse_stack *next, *prev;
645 struct symtab *cur_st; /* Current symtab */
646 struct block *cur_block; /* Block in it */
647 int blocktype; /* What are we parsing */
648 int maxsyms; /* Max symbols in this block */
649 struct type *cur_type; /* Type we parse fields for */
650 int procadr; /* Start addres of this procedure */
651 int numargs; /* Its argument count */
652 } *top_stack; /* Top stack ptr */
655 /* Enter a new lexical context */
657 static push_parse_stack()
659 struct parse_stack *new;
661 /* Reuse frames if possible */
662 if (top_stack && top_stack->prev)
663 new = top_stack->prev;
665 new = (struct parse_stack *) xzalloc(sizeof(struct parse_stack));
666 /* Initialize new frame with previous content */
668 register struct parse_stack *prev = new->prev;
671 top_stack->prev = new;
673 new->next = top_stack;
678 /* Exit a lexical context */
680 static pop_parse_stack()
685 top_stack = top_stack->next;
689 /* Cross-references might be to things we haven't looked at
690 yet, e.g. type references. To avoid too many type
691 duplications we keep a quick fixup table, an array
692 of lists of references indexed by file descriptor */
694 static struct pending {
695 struct pending *next; /* link */
696 SYMR *s; /* the symbol */
697 struct type *t; /* its partial type descriptor */
701 /* Check whether we already saw symbol SH in file FH as undefined */
704 struct pending *is_pending_symbol(fh, sh)
708 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
709 register struct pending *p;
711 /* Linear search is ok, list is typically no more than 10 deep */
712 for (p = pending_list[f_idx]; p; p = p->next)
718 /* Check whether we already saw type T in file FH as undefined */
721 struct pending *is_pending_type(fh, t)
725 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
726 register struct pending *p;
728 for (p = pending_list[f_idx]; p; p = p->next)
734 /* Add a new undef symbol SH of type T */
737 add_pending(fh, sh, t)
742 int f_idx = fh - (FDR *) cur_hdr->cbFdOffset;
743 struct pending *p = is_pending_symbol(fh, sh);
745 /* Make sure we do not make duplicates */
747 p = (struct pending *) xmalloc(sizeof(*p));
750 p->next = pending_list[f_idx];
751 pending_list[f_idx] = p;
753 sh->reserved = 1; /* for quick check */
756 /* Throw away undef entries when done with file index F_IDX */
761 register struct pending *p, *q;
763 for (p = pending_list[f_idx]; p; p = q) {
767 pending_list[f_idx] = 0;
770 /* The number of args to a procedure is not explicit in the symtab,
771 this is the list of all those we know of.
772 This makes parsing more reasonable and avoids extra passes */
774 static struct numarg {
775 struct numarg *next; /* link */
776 unsigned adr; /* procedure's start address */
777 unsigned num; /* arg count */
780 /* Record that the procedure at ADR takes NUM arguments. */
785 struct numarg *n = (struct numarg *) xmalloc(sizeof(struct numarg));
789 n->next = numargs_list;
793 /* See if we know how many arguments the procedure at ADR takes */
798 struct numarg *n = numargs_list;
800 while (n && n->adr != adr)
802 return (n) ? n->num : -1;
805 /* Release storage when done with this file */
810 struct numarg *n = numargs_list, *m;
821 /* Parsing Routines proper. */
823 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
824 For blocks, procedures and types we open a new lexical context.
825 This is basically just a big switch on the symbol's type */
836 /* When a symbol is cross-referenced from other files/symbols
837 we mark it explicitly */
838 int pend = (sh->reserved == 1);
839 enum address_class class;
846 case stGlobal: /* external symbol, goes into the primary block */
848 b = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st),
850 s = new_symbol(sh->iss);
851 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
854 case stStatic: /* static data, goes into the current block. */
856 b = top_stack->cur_block;
857 s = new_symbol(sh->iss);
858 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
861 case stLocal: /* local variable, goes into the current block */
862 if (sh->sc == scRegister) {
863 class = LOC_REGISTER;
868 b = top_stack->cur_block;
869 s = new_symbol(sh->iss);
870 SYMBOL_VALUE(s) = sh->value;
872 data: /* Common code for symbols describing data */
873 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
874 SYMBOL_CLASS(s) = class;
877 /* Type could be missing in a number of cases */
878 if (sh->sc == scUndefined || sh->sc == scNil ||
879 sh->index == 0xfffff)
880 SYMBOL_TYPE(s) = builtin_type_int; /* undefined? */
882 SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0);
883 /* Value of a data symbol is its memory address */
886 case stParam: /* argument to procedure, goes into current block */
888 top_stack->numargs++;
889 s = new_symbol(sh->iss);
890 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
891 if (sh->sc == scRegister) {
892 SYMBOL_CLASS(s) = LOC_REGPARM;
896 SYMBOL_CLASS(s) = LOC_ARG;
897 SYMBOL_VALUE(s) = sh->value;
898 SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0);
899 add_symbol(s, top_stack->cur_block);
902 case stLabel: /* label, we do make a symbol for it */
903 s = new_symbol(sh->iss);
904 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE; /* so that it can be used */
905 SYMBOL_CLASS(s) = LOC_LABEL; /* but not misused */
906 SYMBOL_VALUE_ADDRESS(s) = (CORE_ADDR)sh->value;
907 SYMBOL_TYPE(s) = builtin_type_int;
908 add_symbol(s, top_stack->cur_block);
911 case stProc: /* Procedure */
912 case stStaticProc: /* Static procedure */
913 s = new_symbol(sh->iss);
914 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
915 SYMBOL_CLASS(s) = LOC_BLOCK;
916 /* Type of the return value */
917 if (sh->sc == scUndefined || sh->sc == scNil)
918 t = builtin_type_int;
920 t = parse_type(ax + sh->index, sh, 0);
921 add_symbol(s, top_stack->cur_block);
923 /* Make a type for the procedure itself */
924 SYMBOL_TYPE(s) = lookup_function_type (t);
926 /* Create and enter a new lexical context */
927 b = new_block(top_stack->maxsyms);
928 SYMBOL_BLOCK_VALUE(s) = b;
929 BLOCK_FUNCTION(b) = s;
930 BLOCK_START(b) = BLOCK_END(b) = sh->value;
931 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
932 add_block(b, top_stack->cur_st);
934 /* Not if we only have partial info */
935 if (sh->sc == scUndefined || sh->sc == scNil)
939 top_stack->cur_block = b;
940 top_stack->blocktype = sh->st;
941 top_stack->cur_type = SYMBOL_TYPE(s);
942 top_stack->procadr = sh->value;
943 top_stack->numargs = 0;
945 sh->value = (long) SYMBOL_TYPE(s);
948 case stBlock: /* Either a lexical block, or some type */
950 top_stack->blocktype = stBlock;
951 if (sh->sc == scInfo) { /* structure/union/enum def */
952 s = new_symbol(sh->iss);
953 SYMBOL_NAMESPACE(s) = STRUCT_NAMESPACE;
954 SYMBOL_CLASS(s) = LOC_TYPEDEF;
956 add_symbol(s, top_stack->cur_block);
957 /* If this type was expected, use its partial definition */
959 t = is_pending_symbol(cur_fdr, sh)->t;
961 /* Uhmm, can`t decide yet. Smash later */
962 t = new_type(sh->iss);
963 TYPE_CODE(t) = TYPE_CODE_UNDEF;
964 add_pending(cur_fdr, sh, t);
967 /* make this the current type */
968 top_stack->cur_type = t;
969 TYPE_LENGTH(t) = sh->value;
970 /* Mark that symbol has a type, and say which one */
971 sh->value = (long) t;
973 /* beginnning of (code) block. Value of symbol
974 is the displacement from procedure start */
975 b = new_block(top_stack->maxsyms);
976 BLOCK_START(b) = sh->value + top_stack->procadr;
977 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
978 top_stack->cur_block = b;
979 add_block(b, top_stack->cur_st);
983 case stEnd: /* end (of anything) */
984 if (sh->sc == scInfo) {
985 /* Finished with type */
986 top_stack->cur_type = 0;
987 } else if (sh->sc == scText &&
988 (top_stack->blocktype == stProc ||
989 top_stack->blocktype == stStaticProc)) {
990 /* Finished with procedure */
991 struct blockvector *bv = BLOCKVECTOR(top_stack->cur_st);
995 BLOCK_END(top_stack->cur_block) += sh->value; /* size */
996 got_numargs(top_stack->procadr, top_stack->numargs);
997 /* Reallocate symbols, saving memory */
998 b = shrink_block(top_stack->cur_block, top_stack->cur_st);
1000 /* f77 emits proc-level with address bounds==[0,0],
1001 So look for such child blocks, and patch them. */
1002 for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++) {
1003 struct block *b_bad = BLOCKVECTOR_BLOCK(bv,i);
1004 if (BLOCK_SUPERBLOCK(b_bad) == b
1005 && BLOCK_START(b_bad) == top_stack->procadr
1006 && BLOCK_END(b_bad) == top_stack->procadr) {
1007 BLOCK_START(b_bad) = BLOCK_START(b);
1008 BLOCK_END(b_bad) = BLOCK_END(b);
1011 if (entry_point < BLOCK_END(b)
1012 && entry_point >= BLOCK_START(b)) {
1013 startup_file_start = BLOCK_START(b);
1014 startup_file_end = BLOCK_END(b);
1016 } else if (sh->sc == scText && top_stack->blocktype == stBlock) {
1017 /* End of (code) block. The value of the symbol
1018 is the displacement from the procedure`s start
1019 address of the end of this block. */
1020 BLOCK_END(top_stack->cur_block) = sh->value + top_stack->procadr;
1021 (void) shrink_block(top_stack->cur_block, top_stack->cur_st);
1023 pop_parse_stack(); /* restore previous lexical context */
1026 case stMember: /* member of struct/union/enum.. */
1027 f = new_field(top_stack->cur_type, sh->iss);
1028 f->bitpos = sh->value;
1029 f->type = parse_type(ax + sh->index, sh, &f->bitsize);
1032 case stTypedef: /* type definition */
1033 s = new_symbol(sh->iss);
1034 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
1035 SYMBOL_CLASS(s) = LOC_TYPEDEF;
1036 SYMBOL_BLOCK_VALUE(s) = top_stack->cur_block;
1037 add_symbol(s, top_stack->cur_block);
1038 SYMBOL_TYPE(s) = parse_type(ax + sh->index, sh, 0);
1039 sh->value = (long) SYMBOL_TYPE(s);
1042 case stFile: /* file name */
1044 top_stack->blocktype = sh->st;
1047 /* I`ve never seen these for C */
1049 break; /* register relocation */
1051 break; /* forwarding address */
1053 break; /* constant */
1055 error("Unknown symbol type %x.", sh->st);
1060 /* Parse the type information provided in the AX entries for
1061 the symbol SH. Return the bitfield size in BS, in case. */
1063 static struct type *parse_type(ax, sh, bs)
1068 /* Null entries in this map are treated specially */
1069 static struct type **map_bt[] =
1071 &builtin_type_void, /* btNil */
1073 &builtin_type_char, /* btChar */
1074 &builtin_type_unsigned_char, /* btUChar */
1075 &builtin_type_short, /* btShort */
1076 &builtin_type_unsigned_short, /* btUShort */
1077 &builtin_type_int, /* btInt */
1078 &builtin_type_unsigned_int, /* btUInt */
1079 &builtin_type_long, /* btLong */
1080 &builtin_type_unsigned_long, /* btULong */
1081 &builtin_type_float, /* btFloat */
1082 &builtin_type_double, /* btDouble */
1089 &builtin_type_complex, /* btComplex */
1090 &builtin_type_double_complex, /* btDComplex */
1092 &builtin_type_fixed_dec, /* btFixedDec */
1093 &builtin_type_float_dec, /* btFloatDec */
1094 &builtin_type_string, /* btString */
1097 &builtin_type_void, /* btVoid */
1101 struct type *tp = 0, *tp1;
1104 /* Procedures start off by one */
1105 if (sh->st == stProc || sh->st == stStaticProc)
1108 /* Undefined ? Should not happen */
1109 if (ax->rndx.rfd == 0xfff) {
1110 return builtin_type_void;
1113 /* Use aux as a type information record, map its basic type */
1115 if (t->bt > 26 || t->bt == btPicture) {
1116 printf_filtered("Internal: cannot map MIPS basic type x%x\n", t->bt);
1117 return builtin_type_int;
1120 tp = *map_bt[t->bt];
1122 /* Cannot use builtin types, use templates */
1123 tp = make_type(TYPE_CODE_VOID, 0, 0, 0);
1126 *tp = *builtin_type_ptr;
1129 *tp = *builtin_type_struct;
1133 *tp = *builtin_type_union;
1137 *tp = *builtin_type_enum;
1141 *tp = *builtin_type_range;
1144 *tp = *builtin_type_set;
1150 /* Move on to next aux */
1153 /* This is the way it would work if the compiler worked */
1154 register TIR *t1 = t;
1155 while (t1->continued)
1159 /* For bitfields all we need is the width */
1165 /* All these types really point to some (common) MIPS type
1166 definition, and only the type-qualifiers fully identify
1167 them. We`ll make the same effort at sharing */
1168 if (t->bt == btIndirect ||
1169 t->bt == btStruct ||
1172 t->bt == btTypedef ||
1175 char name[256], *pn;
1177 /* Try to cross reference this type */
1179 ax += cross_ref(ax, &tp1, &pn);
1180 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1181 sprintf(name, fmt, pn);
1183 /* reading .o file ? */
1184 if (UNSAFE_DATA_ADDR(tp1))
1186 if (TYPE_CODE(tp1) == TYPE_CODE_UNDEF) {
1188 * Type was incompletely defined, now we know.
1190 TYPE_CODE(tp1) = TYPE_CODE(tp);
1191 TYPE_NAME(tp1) = obsavestring(name, strlen(name));
1192 if (TYPE_CODE(tp1) == TYPE_CODE_ENUM) {
1195 for (i = 0; i < TYPE_NFIELDS(tp1); i++)
1196 make_enum_constant(&TYPE_FIELD(tp1,i), tp1);
1200 /* found as cross ref, rid of our template */
1201 if ((TYPE_FLAGS(tp) & TYPE_FLAG_PERM) == 0)
1204 /* stupid idea of prepending "struct" to type names */
1205 if (t->bt == btStruct && !index(TYPE_NAME(tp), ' ')) {
1206 sprintf(name, fmt, TYPE_NAME(tp));
1207 TYPE_NAME(tp) = obsavestring(name, strlen(name));
1210 TYPE_NAME(tp) = savestring(name, strlen(name));
1213 /* Deal with range types */
1214 if (t->bt == btRange) {
1217 f = new_field(tp, "Low");
1218 f->bitpos = ax->dnLow;
1220 f = new_field(tp, "High");
1221 f->bitpos = ax->dnHigh;
1225 /* Parse all the type qualifiers now. If there are more
1226 than 6 the game will continue in the next aux */
1228 #define PARSE_TQ(tq) \
1229 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, sh);
1231 again: PARSE_TQ(tq0);
1246 /* Make up a complex type from a basic one. Type is passed by
1247 reference in TPP and side-effected as necessary. The type
1248 qualifier TQ says how to handle the aux symbols at AX for
1249 the symbol SX we are currently analyzing.
1250 Returns the number of aux symbols we parsed. */
1253 upgrade_type(tpp, tq, ax, sh)
1263 t = lookup_pointer_type (*tpp);
1264 } else if (tq == tqProc) {
1265 t = lookup_function_type (*tpp);
1266 } else if (tq == tqArray) {
1272 t = make_type(TYPE_CODE_ARRAY, 0, 0, 0);
1273 TYPE_TARGET_TYPE(t) = *tpp;
1275 /* Pointer to domain type (type of index) */
1276 id = ax->rndx.index;
1277 if ((rf = ax->rndx.rfd) == 0xfff)
1278 rf = (++ax)->isym, off++;
1280 fh = get_rfd(cur_fd, rf);
1281 f = new_field(t, 0);
1282 bzero(&ss, sizeof ss);
1283 /* XXX */ f->type = parse_type(fh->iauxBase + id * sizeof(AUXU),
1287 * This seems to be a pointer to the end of the Block defining
1288 * the type. Why it is here is magic for me, and I have no
1289 * good use for it anyways.
1293 id = (++ax)->rndx.index;
1294 if ((rf = ax->rndx.rfd) == 0xfff)
1295 rf = (++ax)->isym, off++;
1297 f->bitpos = (++ax)->dnLow; /* ?? */
1298 f->bitsize = (++ax)->dnHigh; /* ?? */
1299 rf = (++ax)->width - 1; /* bit alignment */
1300 id = TYPE_LENGTH(TYPE_TARGET_TYPE(t)) << 3; /* bitsize */
1303 /* Most likely an undefined type */
1305 TYPE_LENGTH(TYPE_TARGET_TYPE(t)) = id >> 3;
1307 TYPE_LENGTH(t) = (f->bitsize < 0) ? 0 :
1308 (f->bitsize - f->bitpos + 1) * (id >> 3);
1312 printf_filtered("Internal: unknown type qualifier %x\n", tq);
1321 /* Parse a procedure descriptor record PR. Note that the procedure
1322 is parsed _after_ the local symbols, now we just make up the
1323 extra information we need into a special symbol that we insert
1324 in the procedure's main block. Note also that images that
1325 have been partially stripped (ld -x) have been deprived
1326 of local symbols, and we have to cope with them here.
1327 The procedure's code ends at BOUND */
1330 parse_procedure(pr, bound)
1333 struct symbol *s, *i;
1334 SYMR *sh = (SYMR*)pr->isym;
1336 struct mips_extra_func_info *e;
1340 /* Reuse the MIPS record */
1341 e = (struct mips_extra_func_info *) pr;
1342 e->numargs = lookup_numargs(pr->adr);
1344 /* Make up our special symbol */
1345 i = new_symbol(".gdbinfo.");
1346 SYMBOL_VALUE(i) = (int)e;
1347 SYMBOL_NAMESPACE(i) = LABEL_NAMESPACE;
1348 SYMBOL_CLASS(i) = LOC_CONST;
1349 SYMBOL_TYPE(i) = builtin_type_void;
1351 /* Make up a name for static procedures. Sigh. */
1352 if (sh == (SYMR*)-1) {
1353 sprintf(name,".static_procedure@%x",pr->adr);
1354 sh_name = savestring(name, strlen(name));
1358 sh_name = (char*)sh->iss;
1359 s = mylookup_symbol(sh_name, top_stack->cur_block,
1360 VAR_NAMESPACE, LOC_BLOCK);
1363 b = SYMBOL_BLOCK_VALUE(s);
1365 s = new_symbol(sh_name);
1366 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
1367 SYMBOL_CLASS(s) = LOC_BLOCK;
1368 /* Donno its type, hope int is ok */
1369 SYMBOL_TYPE(s) = lookup_function_type (builtin_type_int);
1370 add_symbol(s, top_stack->cur_block);
1371 /* Wont have symbols for this one */
1373 SYMBOL_BLOCK_VALUE(s) = b;
1374 BLOCK_FUNCTION(b) = s;
1375 BLOCK_START(b) = pr->adr;
1376 BLOCK_END(b) = bound;
1377 BLOCK_SUPERBLOCK(b) = top_stack->cur_block;
1378 add_block(b, top_stack->cur_st);
1384 /* Parse the external symbol ES. Just call parse_symbol() after
1385 making sure we know where the aux are for it. For procedures,
1386 parsing of the PDRs has already provided all the needed
1387 information, we only parse them if SKIP_PROCEDURES is false,
1388 and only if this causes no symbol duplication.
1390 This routine clobbers top_stack->cur_block and ->cur_st. */
1393 parse_external(es, skip_procedures)
1398 if (es->ifd != ifdNil) {
1400 cur_fdr = (FDR*)(cur_hdr->cbFdOffset) + cur_fd;
1401 ax = (AUXU*)cur_fdr->iauxBase;
1403 cur_fdr = (FDR*)(cur_hdr->cbFdOffset);
1406 top_stack->cur_st = cur_stab;
1407 top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack->cur_st),
1410 /* Reading .o files */
1411 if (es->asym.sc == scUndefined || es->asym.sc == scNil) {
1413 switch (es->asym.st) {
1415 case stProc: what = "Procedure"; n_undef_procs++; break;
1416 case stGlobal: what = "Variable"; n_undef_vars++; break;
1417 case stLabel: what = "Label"; n_undef_labels++; break;
1418 default : what = "Symbol"; break;
1422 printf_filtered("Warning: %s %s is undefined (in %s)\n", what,
1423 es->asym.iss, fdr_name(cur_fdr->rss));
1427 switch (es->asym.st) {
1429 /* If we have full symbols we do not need more */
1430 if (skip_procedures)
1432 if (mylookup_symbol (es->asym.iss, top_stack->cur_block,
1433 VAR_NAMESPACE, LOC_BLOCK))
1439 * Note that the case of a symbol with indexNil
1440 * must be handled anyways by parse_symbol().
1442 parse_symbol(&es->asym, ax);
1449 /* Parse the line number info for file descriptor FH into
1450 GDB's linetable LT. MIPS' encoding requires a little bit
1451 of magic to get things out. Note also that MIPS' line
1452 numbers can go back and forth, apparently we can live
1453 with that and do not need to reorder our linetables */
1458 struct linetable *lt;
1460 char *base = (char*)fh->cbLineOffset;
1462 int delta, count, lineno = 0;
1468 /* Scan by procedure descriptors */
1469 i = 0; j = 0, k = 0;
1470 for (pr = (PDR*)IPDFIRST(cur_hdr,fh); j < fh->cpd; j++, pr++) {
1473 /* No code for this one */
1474 if (pr->iline == ilineNil ||
1475 pr->lnLow == -1 || pr->lnHigh == -1)
1478 * Aurgh! To know where to stop expanding we
1481 for (l = 1; l < (fh->cpd - j); l++)
1482 if (pr[l].iline != -1)
1484 if (l == (fh->cpd - j))
1489 * When procedures are moved around the linenumbers
1490 * are attributed to the next procedure up
1492 if (pr->iline >= halt) continue;
1494 base = (char*)pr->cbLineOffset;
1495 l = pr->adr >> 2; /* in words */
1496 halt += (pr->adr >> 2) - pr->iline;
1497 for (lineno = pr->lnLow; l < halt;) {
1498 count = *base & 0x0f;
1499 delta = *base++ >> 4;
1501 delta = (base[0] << 8) | (base[1] & 0xff);
1504 lineno += delta;/* first delta is 0 */
1505 k = add_line(lt, lineno, l, k);
1512 /* Parse the symbols of the file described by FH, whose index is F_IDX.
1513 BOUND is the highest core address of this file's procedures */
1516 parse_one_file(fh, f_idx, bound)
1523 /* Parse local symbols first */
1525 for (s_idx = 0; s_idx < fh->csym; s_idx++) {
1526 sh = (SYMR *) (fh->isymBase) + s_idx;
1528 parse_symbol(sh, fh->iauxBase);
1531 /* Procedures next, note we need to look-ahead to
1532 find out where the procedure's code ends */
1534 for (s_idx = 0; s_idx < fh->cpd-1; s_idx++) {
1535 pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + s_idx;
1536 parse_procedure(pr, pr[1].adr); /* next proc up */
1539 pr = (PDR *) (IPDFIRST(cur_hdr, fh)) + s_idx;
1540 parse_procedure(pr, bound); /* next file up */
1543 /* Linenumbers. At the end, check if we can save memory */
1544 parse_lines(fh, LINETABLE(cur_stab));
1545 if (LINETABLE(cur_stab)->nitems < fh->cline)
1546 shrink_linetable(cur_stab);
1549 /* Master parsing procedure for first-pass reading of file symbols
1550 into a partial_symtab.
1552 Parses the symtab described by the symbolic header HDR.
1553 END_OF_TEXT_SEG gives the address just after the text segment for
1554 the symtab we are reading. */
1557 parse_partial_symbols(hdr, end_of_text_seg)
1560 int f_idx, s_idx, h_max, stat_idx;
1561 CORE_ADDR dummy, *prevhigh;
1562 /* Running pointers */
1567 struct partial_symtab *pst;
1572 * Only parse the Local and External symbols, and the Relative FDR.
1573 * Fixup enough of the loader symtab to be able to use it.
1574 * Allocate space only for the file`s portions we need to
1580 max_glevel = MIN_GLEVEL;
1582 /* Allocate the map FDR -> PST.
1583 Minor hack: -O3 images might claim some global data belongs
1584 to FDR -1. We`ll go along with that */
1585 fdr_to_pst = (struct pst_map *)xzalloc((hdr->ifdMax+1) * sizeof *fdr_to_pst);
1588 struct partial_symtab * pst = new_psymtab("");
1589 fdr_to_pst[-1].pst = pst;
1593 /* Now scan the FDRs, mostly for dependencies */
1594 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
1595 (void) parse_fdr(f_idx, 1);
1597 /* Take a good guess at how many symbols we might ever need */
1598 h_max = hdr->iextMax;
1600 /* Parse externals: two passes because they can be ordered
1601 in any way, but gdb likes to have them segregated by their
1604 /* Pass 1 over external syms: Presize and partition the list */
1605 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
1606 esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
1607 fdr_to_pst[esh->ifd].n_globals++;
1610 if (global_psymbols.list) {
1611 int origsize = global_psymbols.next - global_psymbols.list;
1613 global_psymbols.list = (struct partial_symbol *)
1614 xrealloc (global_psymbols.list,
1615 (h_max + origsize) * sizeof(struct partial_symbol));
1616 global_psymbols.next = global_psymbols.list + origsize;
1617 global_psymbols.size = h_max + origsize;
1619 global_psymbols.list = (struct partial_symbol *)
1620 xmalloc (h_max * sizeof(struct partial_symbol));
1621 global_psymbols.next = global_psymbols.list;
1622 global_psymbols.size = h_max;
1625 /* Pass 1.5 over files: partition out global symbol space */
1626 s_idx = global_psymbols.next - global_psymbols.list;
1627 for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++) {
1628 fdr_to_pst[f_idx].pst->globals_offset = s_idx;
1629 s_idx += fdr_to_pst[f_idx].n_globals;
1632 /* Pass 1.6 over files: partition out static symbol space.
1633 Note that this loop starts at 0, not at -1. */
1634 stat_idx = static_psymbols.next - static_psymbols.list;
1635 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
1636 fdr_to_pst[f_idx].pst->statics_offset = stat_idx;
1637 fh = f_idx + (FDR *)(hdr->cbFdOffset);
1638 stat_idx += fh->csym;
1641 /* Now that we know its max size, allocate static symbol list */
1642 if (static_psymbols.list) {
1643 int origsize = static_psymbols.next - static_psymbols.list;
1645 static_psymbols.list = (struct partial_symbol *)
1646 xrealloc (static_psymbols.list,
1647 stat_idx * sizeof(struct partial_symbol));
1648 static_psymbols.next = static_psymbols.list + origsize;
1649 static_psymbols.size = stat_idx;
1651 static_psymbols.list = (struct partial_symbol *)
1652 xmalloc (stat_idx * sizeof(struct partial_symbol));
1653 static_psymbols.next = static_psymbols.list;
1654 static_psymbols.size = stat_idx;
1657 /* Pass 2 over external syms: fill in external symbols */
1658 for (s_idx = 0; s_idx < hdr->iextMax; s_idx++) {
1659 register struct partial_symbol *p;
1660 enum misc_function_type misc_type = mf_text;
1661 esh = (EXTR *) (hdr->cbExtOffset) + s_idx;
1663 if (esh->asym.sc == scUndefined || esh->asym.sc == scNil)
1666 /* Locate the psymtab and the preallocated psymbol. */
1667 pst = fdr_to_pst[esh->ifd].pst;
1668 p = global_psymbols.list + pst->globals_offset +
1669 pst->n_global_syms++;
1670 SYMBOL_NAME(p) = (char *)(esh->asym.iss);
1671 SYMBOL_NAMESPACE(p) = VAR_NAMESPACE;
1673 switch (esh->asym.st) {
1675 SYMBOL_CLASS(p) = LOC_BLOCK;
1676 SYMBOL_VALUE(p) = esh->asym.value;
1679 SYMBOL_CLASS(p) = LOC_STATIC;
1680 SYMBOL_VALUE_ADDRESS(p) = (CORE_ADDR)esh->asym.value;
1681 misc_type = mf_data;
1684 SYMBOL_CLASS(p) = LOC_LABEL;
1685 SYMBOL_VALUE_ADDRESS(p) = (CORE_ADDR)esh->asym.value;
1688 misc_type = mf_unknown;
1689 complain (&unknown_ext_complaint, SYMBOL_NAME(p));
1691 prim_record_misc_function (SYMBOL_NAME(p),
1696 /* Pass 3 over files, over local syms: fill in static symbols */
1697 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
1698 fh = f_idx + (FDR *)(cur_hdr->cbFdOffset);
1699 pst = fdr_to_pst[f_idx].pst;
1701 for (s_idx = 0; s_idx < fh->csym; ) {
1702 register struct partial_symbol *p;
1704 sh = s_idx + (SYMR *) fh->isymBase;
1706 if (sh->sc == scUndefined || sh->sc == scNil) {
1707 /* FIXME, premature? */
1712 /* Locate the preallocated psymbol. */
1713 p = static_psymbols.list + pst->statics_offset +
1715 SYMBOL_NAME(p) = (char *)(sh->iss);
1716 SYMBOL_VALUE(p) = sh->value;
1717 SYMBOL_NAMESPACE(p) = VAR_NAMESPACE;
1720 case stProc: /* Asm labels apparently */
1721 case stStaticProc: /* Function */
1722 SYMBOL_CLASS(p) = LOC_BLOCK;
1723 pst->n_static_syms++; /* Use gdb symbol */
1724 /* Skip over procedure to next one. */
1725 s_idx = (sh->index + (AUXU *)fh->iauxBase)
1728 case stStatic: /* Variable */
1729 SYMBOL_CLASS(p) = LOC_STATIC;
1730 SYMBOL_VALUE_ADDRESS(p) = (CORE_ADDR)sh->value;
1732 case stTypedef: /* Typedef */
1733 SYMBOL_CLASS(p) = LOC_TYPEDEF;
1735 case stConstant: /* Constant decl */
1736 SYMBOL_CLASS(p) = LOC_CONST;
1738 case stBlock: /* { }, str, un, enum */
1739 /* Eventually we want struct names and enum
1740 values out of here. FIXME */
1741 /* Skip over the block */
1744 case stFile: /* File headers */
1745 case stLabel: /* Labels */
1746 case stEnd: /* Ends of files */
1749 complain (&unknown_sym_complaint, SYMBOL_NAME(p));
1750 complain (&unknown_st_complaint, sh->st);
1754 pst->n_static_syms++; /* Use this gdb symbol */
1756 s_idx++; /* Go to next file symbol */
1758 /* We don't usually record static syms, but some we seem to. chk dbxread. */
1759 /*FIXME*/ prim_record_misc_function (SYMBOL_NAME(p),
1766 /* The array (of lists) of globals must be sorted.
1767 Take care, since we are at it, of pst->texthigh.
1769 NOTE: The way we handle textlow/high is incorrect, but good
1770 enough for a first approximation. The case we fail is on a
1771 file "foo.c" that looks like
1773 #include "bar.c" -- this contains proc2()
1775 where proc3() is attributed to bar.c. But since this is a
1776 dependent file it will cause loading of foo.c as well, so
1777 everything will be fine at the end. */
1780 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++) {
1781 struct partial_symtab *pst = fdr_to_pst[f_idx].pst;
1782 if (pst->n_global_syms > 1)
1783 qsort (global_psymbols.list + pst->globals_offset,
1784 pst->n_global_syms, sizeof (struct partial_symbol),
1787 *prevhigh = pst->textlow;
1788 prevhigh = &pst->texthigh;
1792 /* Mark the last code address, and remember it for later */
1793 *prevhigh = end_of_text_seg;
1794 hdr->cbDnOffset = end_of_text_seg;
1797 free(&fdr_to_pst[-1]);
1802 /* Do the initial analisys of the F_IDX-th file descriptor.
1803 Allocates a partial symtab for it, and builds the list
1804 of dependent files by recursion. LEV says at which level
1805 of recursion we are called (to pretty up debug traces) */
1807 static struct partial_symtab *
1808 parse_fdr(f_idx, lev)
1812 register struct partial_symtab *pst;
1815 fh = (FDR *) (cur_hdr->cbFdOffset) + f_idx;
1817 /* Use this to indicate into which symtab this file was parsed */
1819 return (struct partial_symtab *) fh->ioptBase;
1821 /* Debuggability level */
1822 if (compare_glevel(max_glevel, fh->glevel) < 0)
1823 max_glevel = fh->glevel;
1825 /* Make a new partial_symtab */
1826 pst = new_psymtab(fh->rss);
1831 pst->textlow = fh->adr;
1832 pst->texthigh = fh->cpd; /* To be fixed later */
1835 /* Make everything point to everything. */
1836 pst->ldsymoff = f_idx;
1837 fdr_to_pst[f_idx].pst = pst;
1838 fh->ioptBase = (int)pst;
1840 /* Analyze its dependencies */
1845 if (fh->cpd == 0) { /* If there are no functions defined here ... */
1846 /* ...then presumably a .h file: drop reverse depends .h->.c */
1847 for (; s_id0 < fh->crfd; s_id0++) {
1848 RFDT *rh = (RFDT *) (fh->rfdBase) + s_id0;
1850 s_id0++; /* Skip self-dependency */
1855 pst->number_of_dependencies = fh->crfd - s_id0;
1856 pst->dependencies = (struct partial_symtab **)
1857 obstack_alloc (psymbol_obstack,
1858 pst->number_of_dependencies * sizeof(char*));
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);
1870 /* Ancillary function to psymtab_to_symtab(). Does all the work
1871 for turning the partial symtab PST into a symtab, recurring
1872 first on all dependent psymtabs */
1875 psymtab_to_symtab_1(pst)
1876 struct partial_symtab *pst;
1886 pending_list = (struct pending **) cur_hdr->cbOptOffset;
1887 if (pending_list == 0) {
1888 pending_list = (struct pending **)
1889 xzalloc(cur_hdr->ifdMax * sizeof(struct pending *));
1890 cur_hdr->cbOptOffset = (int)pending_list;
1893 /* How many symbols will we need */
1894 f_max = pst->n_global_syms + pst->n_static_syms;
1895 if (pst->ldsymoff == -1) {
1897 st = new_symtab( "unknown", f_max, 0);
1899 fh = (FDR *) (cur_hdr->cbFdOffset) + pst->ldsymoff;
1900 f_max += fh->csym + fh->cpd;
1901 st = new_symtab(pst->filename, 2 * f_max, 2 * fh->cline);
1905 * Read in all partial symbtabs on which this one is dependent.
1906 * NOTE that we do have circular dependencies, sigh.
1908 for (i = 0; i < pst->number_of_dependencies; i++)
1909 if (!pst->dependencies[i]->readin) {
1911 * DO NOT inform about additional files that need to
1912 * be read in, it would only annoy the user.
1914 psymtab_to_symtab_1(pst->dependencies[i]);
1917 /* Now read the symbols for this symtab */
1919 cur_fd = pst->ldsymoff;
1923 /* Get a new lexical context */
1926 top_stack->cur_st = cur_stab;
1927 top_stack->cur_block = BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab),
1929 BLOCK_START(top_stack->cur_block) = fh ? fh->adr : 0;
1930 BLOCK_END(top_stack->cur_block) = 0;
1931 top_stack->blocktype = stFile;
1932 top_stack->maxsyms = f_max;
1933 top_stack->cur_type = 0;
1934 top_stack->procadr = 0;
1935 top_stack->numargs = 0;
1937 /* Parse locals and procedures */
1939 parse_one_file(fh, cur_fd, (cur_fd == (cur_hdr->ifdMax - 1)) ?
1940 cur_hdr->cbDnOffset : fh[1].adr);
1942 /* .. and our share of externals.
1943 XXX use the global list to speed up things here. how ?
1944 FIXME, Maybe quit once we have found the right number of ext's? */
1945 /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
1946 top_stack->blocktype = stFile;
1947 top_stack->maxsyms = cur_hdr->isymMax + cur_hdr->ipdMax + cur_hdr->iextMax;
1948 for (i = 0; i < cur_hdr->iextMax; i++) {
1949 register EXTR *esh = (EXTR *) (cur_hdr->cbExtOffset) + i;
1950 if (esh->ifd == cur_fd)
1951 parse_external(esh, 1);
1954 /* If there are undefined, tell the user */
1955 if (n_undef_symbols) {
1956 printf_filtered("File %s contains %d unresolved references:",
1957 st->filename, n_undef_symbols);
1958 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
1959 n_undef_vars, n_undef_procs, n_undef_labels);
1960 n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
1966 * Sort the symbol table now, we are done adding symbols to it.
1968 sort_symtab_syms(st);
1970 /* Now link the psymtab and the symtab. */
1974 /* Ancillary parsing procedures. */
1976 /* Lookup the type at relative index RN. Return it in TPP
1977 if found and in any event come up with its name PNAME.
1978 Return value says how many aux symbols we ate */
1981 cross_ref(rn, tpp, pname)
1988 /* Escape index means 'the next one' */
1989 if (rn->rfd == 0xfff)
1990 rf = *(unsigned *) (rn + 1);
1996 *pname = "<undefined>";
1999 * Find the relative file descriptor and the symbol in it
2001 FDR *fh = get_rfd(cur_fd, rf);
2006 * If we have processed this symbol then we left a forwarding
2007 * pointer to the corresponding GDB symbol. If not, we`ll put
2008 * it in a list of pending symbols, to be processed later when
2009 * the file f will be. In any event, we collect the name for
2010 * the type here. Which is why we made a first pass at
2013 sh = (SYMR *) (fh->isymBase) + rn->index;
2015 /* Careful, we might be looking at .o files */
2016 *pname = (UNSAFE_DATA_ADDR(sh->iss)) ? "<undefined>" :
2019 /* Have we parsed it ? */
2020 if ((!UNSAFE_DATA_ADDR(sh->value)) && (sh->st == stParsed)) {
2021 t = (struct type *) sh->value;
2026 /* Avoid duplicates */
2027 p = is_pending_symbol(fh, sh);
2032 add_pending(fh, sh, *tpp);
2035 return (rn->rfd == 0xfff);
2039 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2040 keeping the symtab sorted */
2042 static struct symbol *
2043 mylookup_symbol (name, block, namespace, class)
2045 register struct block *block;
2046 enum namespace namespace;
2047 enum address_class class;
2049 register int bot, top, inc;
2050 register struct symbol *sym;
2053 top = BLOCK_NSYMS(block);
2056 sym = BLOCK_SYM(block, bot);
2057 if (SYMBOL_NAME(sym)[0] == inc
2058 && SYMBOL_NAMESPACE(sym) == namespace
2059 && SYMBOL_CLASS(sym) == class
2060 && !strcmp(SYMBOL_NAME(sym), name))
2064 if (block = BLOCK_SUPERBLOCK (block))
2065 return mylookup_symbol (name, block, namespace, class);
2070 /* Add a new symbol S to a block B */
2077 BLOCK_SYM(b,BLOCK_NSYMS(b)++) = s;
2078 if (b == top_stack->cur_block &&
2079 BLOCK_NSYMS(b) > top_stack->maxsyms)
2080 printf_filtered("Internal: block at @%x overfilled (by %d)\n",
2081 b, BLOCK_NSYMS(b) - top_stack->maxsyms);
2084 /* Add a new block B to a symtab S */
2091 struct blockvector *bv = BLOCKVECTOR(s);
2093 bv = (struct blockvector *)xrealloc(bv, sizeof(struct blockvector) +
2094 BLOCKVECTOR_NBLOCKS(bv) * sizeof(bv->block));
2095 if (bv != BLOCKVECTOR(s))
2096 BLOCKVECTOR(s) = bv;
2098 BLOCKVECTOR_BLOCK(bv, BLOCKVECTOR_NBLOCKS(bv)++) = b;
2101 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2102 MIPS' linenumber encoding might need more than one byte
2103 to describe it, LAST is used to detect these continuation lines */
2106 add_line(lt, lineno, adr, last)
2107 struct linetable *lt;
2111 last = -2; /* make sure we record first line */
2113 if (last == lineno) /* skip continuation lines */
2116 lt->item[lt->nitems].line = lineno;
2117 lt->item[lt->nitems++].pc = adr << 2;
2123 /* Comparison functions, used when sorting things */
2125 /* Symtabs must be ordered viz the code segments they cover */
2128 compare_symtabs( s1, s2)
2129 struct symtab **s1, **s2;
2131 /* "most specific" first */
2133 register struct block *b1, *b2;
2134 b1 = BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1),GLOBAL_BLOCK);
2135 b2 = BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2),GLOBAL_BLOCK);
2136 if (BLOCK_END(b1) == BLOCK_END(b2))
2137 return BLOCK_START(b1) - BLOCK_START(b2);
2138 return BLOCK_END(b1) - BLOCK_END(b2);
2142 /* Partial Symtabs, same */
2145 compare_psymtabs( s1, s2)
2146 struct partial_symtab **s1, **s2;
2148 /* Perf twist: put the ones with no code at the end */
2150 register int a = (*s1)->textlow;
2151 register int b = (*s2)->textlow;
2160 /* Partial symbols are compared lexicog by their print names */
2163 compare_psymbols (s1, s2)
2164 register struct partial_symbol *s1, *s2;
2167 *st1 = SYMBOL_NAME(s1),
2168 *st2 = SYMBOL_NAME(s2);
2170 return (st1[0] - st2[0] ? st1[0] - st2[0] :
2171 strcmp(st1 + 1, st2 + 1));
2174 /* Blocks with a smaller low bound should come first */
2176 static int compare_blocks(b1,b2)
2177 struct block **b1, **b2;
2179 register int addr_diff;
2181 addr_diff = (BLOCK_START((*b1))) - (BLOCK_START((*b2)));
2183 return (BLOCK_END((*b1))) - (BLOCK_END((*b2)));
2188 /* Sorting and reordering procedures */
2190 /* Sort the blocks of a symtab S.
2191 Reorder the blocks in the blockvector by code-address,
2192 as required by some MI search routines */
2198 struct blockvector *bv = BLOCKVECTOR(s);
2200 if (BLOCKVECTOR_NBLOCKS(bv) <= 2) {
2202 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) == 0)
2203 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = 0;
2204 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) == 0)
2205 BLOCK_START(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) = 0;
2209 * This is very unfortunate: normally all functions are compiled in
2210 * the order they are found, but if the file is compiled -O3 things
2211 * are very different. It would be nice to find a reliable test
2212 * to detect -O3 images in advance.
2214 if (BLOCKVECTOR_NBLOCKS(bv) > 3)
2215 qsort(&BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK),
2216 BLOCKVECTOR_NBLOCKS(bv) - FIRST_LOCAL_BLOCK,
2217 sizeof(struct block *),
2221 register CORE_ADDR high = 0;
2222 register int i, j = BLOCKVECTOR_NBLOCKS(bv);
2224 for (i = FIRST_LOCAL_BLOCK; i < j; i++)
2225 if (high < BLOCK_END(BLOCKVECTOR_BLOCK(bv,i)))
2226 high = BLOCK_END(BLOCKVECTOR_BLOCK(bv,i));
2227 BLOCK_END(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) = high;
2230 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK)) =
2231 BLOCK_START(BLOCKVECTOR_BLOCK(bv,FIRST_LOCAL_BLOCK));
2233 BLOCK_START(BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) =
2234 BLOCK_START(BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK));
2235 BLOCK_END (BLOCKVECTOR_BLOCK(bv,STATIC_BLOCK)) =
2236 BLOCK_END (BLOCKVECTOR_BLOCK(bv,GLOBAL_BLOCK));
2239 /* Sort the symtab list, as required by some search procedures.
2240 We want files ordered to make them look right to users, and for
2241 searching (see block_for_pc). */
2247 struct symtab *stab;
2248 register struct symtab **all_symtabs;
2249 register int symtab_count;
2254 /* Create an array of pointers to all the symtabs. */
2255 for (symtab_count = 0, stab = symtab_list;
2257 symtab_count++, stab = stab->next) {
2258 obstack_grow (psymbol_obstack, &stab, sizeof (stab));
2259 /* FIXME: Only sort blocks for new symtabs ??? */
2263 all_symtabs = (struct symtab **)
2264 obstack_base (psymbol_obstack);
2265 qsort((char *)all_symtabs, symtab_count,
2266 sizeof(struct symtab *), compare_symtabs);
2268 /* Re-construct the symtab list, but now it is sorted. */
2269 for (i = 0; i < symtab_count-1; i++)
2270 all_symtabs[i]->next = all_symtabs[i+1];
2271 all_symtabs[i]->next = 0;
2272 symtab_list = all_symtabs[0];
2274 obstack_free (psymbol_obstack, all_symtabs);
2277 /* Sort the partial symtab list, as required by some search procedures.
2278 PC lookups stop at the first psymtab such that textlow <= PC < texthigh */
2284 register int all_psymtabs_count;
2285 struct partial_symtab *pstab;
2286 struct partial_symtab **all_psymtabs;
2288 if (!partial_symtab_list)
2291 /* Create an array of pointers to all the partial_symtabs. */
2293 for (all_psymtabs_count = 0, pstab = partial_symtab_list;
2295 all_psymtabs_count++, pstab = pstab->next)
2296 obstack_grow (psymbol_obstack, &pstab, sizeof (pstab));
2298 all_psymtabs = (struct partial_symtab **)
2299 obstack_base (psymbol_obstack);
2301 qsort((char *)all_psymtabs, all_psymtabs_count,
2302 sizeof(struct partial_symtab *), compare_psymtabs);
2304 /* Re-construct the partial_symtab_list, but now it is sorted. */
2306 for (i = 0; i < all_psymtabs_count-1; i++)
2307 all_psymtabs[i]->next = all_psymtabs[i+1];
2308 all_psymtabs[i]->next = 0;
2309 partial_symtab_list = all_psymtabs[0];
2311 obstack_free (psymbol_obstack, all_psymtabs);
2314 /* Constructor/restructor/destructor procedures */
2316 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2317 MAXSYMS and linenumbers MAXLINES we'll put in it */
2321 new_symtab(name, maxsyms, maxlines)
2324 struct symtab *s = (struct symtab *) xzalloc(sizeof(struct symtab));
2327 LINETABLE(s) = new_linetable(maxlines);
2331 /* All symtabs must have at least two blocks */
2332 BLOCKVECTOR(s) = new_bvect(2);
2333 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK) = new_block(maxsyms);
2334 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), STATIC_BLOCK) = new_block(maxsyms);
2335 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s),STATIC_BLOCK)) =
2336 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s), GLOBAL_BLOCK);
2338 s->free_code = free_linetable;
2340 /* Link the new symtab into the list of such. */
2341 s->next = symtab_list;
2347 /* Allocate a new partial_symtab NAME */
2349 static struct partial_symtab *
2353 struct partial_symtab *pst;
2355 pst = (struct partial_symtab *)
2356 obstack_alloc (psymbol_obstack, sizeof (*pst));
2357 bzero (pst, sizeof (*pst));
2359 if (name == (char*)-1) /* FIXME -- why not null here? */
2360 pst->filename = "<no name>";
2362 pst->filename = name;
2364 pst->next = partial_symtab_list;
2365 partial_symtab_list = pst;
2367 /* Keep a backpointer to the file`s symbols */
2368 /* FIXME, we should use private data that is a proper pointer. */
2369 pst->ldsymlen = (int)cur_hdr;
2371 /* The way to turn this into a symtab is to call... */
2372 pst->read_symtab = mipscoff_psymtab_to_symtab;
2378 /* Allocate a linetable array of the given SIZE */
2381 struct linetable *new_linetable(size)
2383 struct linetable *l;
2385 size = size * sizeof(l->item) + sizeof(struct linetable);
2386 l = (struct linetable *)xmalloc(size);
2391 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2392 I am not so sure about the 3.4 ones */
2394 static shrink_linetable(s)
2397 struct linetable *l = new_linetable(LINETABLE(s)->nitems);
2399 bcopy(LINETABLE(s), l,
2400 LINETABLE(s)->nitems * sizeof(l->item) + sizeof(struct linetable));
2401 free (LINETABLE(s));
2405 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2408 struct blockvector *new_bvect(nblocks)
2410 struct blockvector *bv;
2413 size = sizeof(struct blockvector) + nblocks * sizeof(struct block*);
2414 bv = (struct blockvector *) xzalloc(size);
2416 BLOCKVECTOR_NBLOCKS(bv) = nblocks;
2421 /* Allocate and zero a new block of MAXSYMS symbols */
2424 struct block *new_block(maxsyms)
2426 int size = sizeof(struct block) + (maxsyms-1) * sizeof(struct symbol *);
2427 struct block *b = (struct block *)xzalloc(size);
2432 /* Ooops, too big. Shrink block B in symtab S to its minimal size */
2434 static struct block *
2440 struct blockvector *bv = BLOCKVECTOR(s);
2443 /* Just get a new one, copy, and fix references to the old one */
2445 new = (struct block *)xmalloc(sizeof(struct block) +
2446 (BLOCK_NSYMS(b)-1) * sizeof(struct symbol *));
2448 bcopy(b, new, sizeof(*new) + (BLOCK_NSYMS(b) - 1) * sizeof(struct symbol*));
2450 /* Should chase pointers to old one. Fortunately, that`s just
2451 the block`s function and inferior blocks */
2452 if (BLOCK_FUNCTION(b) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(b)) == b)
2453 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(b)) = new;
2454 for (i = 0; i < BLOCKVECTOR_NBLOCKS(bv); i++)
2455 if (BLOCKVECTOR_BLOCK(bv,i) == b)
2456 BLOCKVECTOR_BLOCK(bv,i) = new;
2457 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) == b)
2458 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv,i)) = new;
2463 /* Create a new symbol with printname NAME */
2470 struct symbol *s = (struct symbol *)
2471 obstack_alloc (symbol_obstack, sizeof (struct symbol));
2473 bzero (s, sizeof (*s));
2474 SYMBOL_NAME(s) = name;
2478 /* Create a new type with printname NAME */
2485 struct type *t = (struct type *)
2486 obstack_alloc (symbol_obstack, sizeof (struct type));
2488 bzero (t, sizeof (*t));
2489 TYPE_NAME(t) = name;
2493 /* Create and initialize a new type with printname NAME.
2494 CODE and LENGTH are the initial info we put in,
2495 UNS says whether the type is unsigned or not. */
2499 make_type(code, length, uns, name)
2500 enum type_code code;
2504 register struct type *type;
2506 type = (struct type *) xzalloc(sizeof(struct type));
2507 TYPE_CODE(type) = code;
2508 TYPE_LENGTH(type) = length;
2509 TYPE_FLAGS(type) = uns ? TYPE_FLAG_UNSIGNED : 0;
2510 TYPE_NAME(type) = name;
2515 /* Allocate a new field named NAME to the type TYPE */
2518 struct field *new_field(type,name)
2524 /* Fields are kept in an array */
2525 if (TYPE_NFIELDS(type))
2526 TYPE_FIELDS(type) = (struct field*)xrealloc(TYPE_FIELDS(type),
2527 (TYPE_NFIELDS(type)+1) * sizeof(struct field));
2529 TYPE_FIELDS(type) = (struct field*)xzalloc(2*sizeof(struct field));
2530 f = &(TYPE_FIELD(type,TYPE_NFIELDS(type)++));
2531 bzero(f, sizeof(struct field));
2537 /* Make an enum constant for a member F of an enumerated type T */
2540 make_enum_constant(f,t)
2546 * This is awful, but that`s the way it is supposed to be
2547 * (BTW, no need to free the real 'type', it's a builtin)
2549 f->type = (struct type *) f->bitpos;
2551 s = new_symbol(f->name);
2552 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
2553 SYMBOL_CLASS(s) = LOC_CONST;
2555 SYMBOL_VALUE(s) = f->bitpos;
2556 add_symbol(s, top_stack->cur_block);
2561 /* Things used for calling functions in the inferior.
2562 These functions are exported to our companion
2563 mips-dep.c file and are here because they play
2564 with the symbol-table explicitly. */
2567 /* Need to make a new symbol on the fly for the dummy
2568 frame we put on the stack. Which goes in the.. */
2570 static struct symtab *dummy_symtab;
2572 /* Make up a dummy symbol for the code we put at END_PC,
2573 of size SIZE, invoking a function with NARGS arguments
2574 and using a frame of FRAMESIZE bytes */
2576 mips_create_dummy_symbol(end_pc, size, nargs, framesize)
2580 struct mips_extra_func_info *gdbinfo;
2582 /* Allocate symtab if not done already */
2583 if (dummy_symtab == 0)
2584 dummy_symtab = new_symtab(".dummy_symtab.", 100, 0);
2586 /* Make a new block. Only needs one symbol */
2588 BLOCK_START(bl) = end_pc - size;
2589 BLOCK_END(bl) = end_pc;
2591 BLOCK_SUPERBLOCK(bl) =
2592 BLOCKVECTOR_BLOCK(BLOCKVECTOR(dummy_symtab),GLOBAL_BLOCK);
2593 add_block(bl, dummy_symtab);
2594 sort_blocks(dummy_symtab);
2596 BLOCK_FUNCTION(bl) = new_symbol("??");
2597 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(bl)) = bl;
2598 g = new_symbol(".gdbinfo.");
2599 BLOCK_SYM(bl,BLOCK_NSYMS(bl)++) = g;
2601 SYMBOL_NAMESPACE(g) = LABEL_NAMESPACE;
2602 SYMBOL_CLASS(g) = LOC_CONST;
2603 SYMBOL_TYPE(g) = builtin_type_void;
2604 gdbinfo = (struct mips_extra_func_info *)
2605 xzalloc(sizeof(struct mips_extra_func_info));
2607 SYMBOL_VALUE(g) = (long) gdbinfo;
2609 gdbinfo->numargs = nargs;
2610 gdbinfo->framesize = framesize;
2611 gdbinfo->framereg = 29;
2612 gdbinfo->pcreg = 31;
2613 gdbinfo->regmask = -2;
2614 gdbinfo->regoffset = -4;
2615 gdbinfo->fregmask = 0; /* XXX */
2616 gdbinfo->fregoffset = 0; /* XXX */
2619 /* We just returned from the dummy code at END_PC, drop its symbol */
2621 mips_destroy_dummy_symbol(end_pc)
2624 struct blockvector *bv = BLOCKVECTOR(dummy_symtab);
2627 bl = block_for_pc(end_pc);
2628 free(BLOCK_FUNCTION(bl));
2629 free(SYMBOL_VALUE(BLOCK_SYM(bl,0)));
2630 free(BLOCK_SYM(bl,0));
2632 for (i = FIRST_LOCAL_BLOCK; i < BLOCKVECTOR_NBLOCKS(bv); i++)
2633 if (BLOCKVECTOR_BLOCK(bv,i) == bl)
2635 for (; i < BLOCKVECTOR_NBLOCKS(bv) - 1; i++)
2636 BLOCKVECTOR_BLOCK(bv,i) = BLOCKVECTOR_BLOCK(bv,i+1);
2637 BLOCKVECTOR_NBLOCKS(bv)--;
2638 sort_blocks(dummy_symtab);
2643 /* Sigtramp: make sure we have all the necessary information
2644 about the signal trampoline code. Since the official code
2645 from MIPS does not do so, we make up that information ourselves.
2646 If they fix the library (unlikely) this code will neutralize itself. */
2653 struct block *b, *b0;
2655 sigtramp_address = -1;
2657 /* We know it is sold as sigvec */
2658 s = lookup_symbol("sigvec", 0, VAR_NAMESPACE, 0, NULL);
2660 /* Most programs do not play with signals */
2664 b0 = SYMBOL_BLOCK_VALUE(s);
2666 /* A label of sigvec, to be more precise */
2667 s = lookup_symbol("sigtramp", b0, VAR_NAMESPACE, 0, NULL);
2669 /* But maybe this program uses its own version of sigvec */
2673 sigtramp_address = SYMBOL_VALUE(s);
2674 sigtramp_end = sigtramp_address + 0x88; /* black magic */
2676 /* Did we or MIPSco fix the library ? */
2677 if (SYMBOL_CLASS(s) == LOC_BLOCK)
2680 /* But what symtab does it live in ? */
2681 st = find_pc_symtab(SYMBOL_VALUE(s));
2684 * Ok, there goes the fix: turn it into a procedure, with all the
2685 * needed info. Note we make it a nested procedure of sigvec,
2686 * which is the way the (assembly) code is actually written.
2688 SYMBOL_NAMESPACE(s) = VAR_NAMESPACE;
2689 SYMBOL_CLASS(s) = LOC_BLOCK;
2690 SYMBOL_TYPE(s) = make_type(TYPE_CODE_FUNC, 4, 0, 0);
2691 TYPE_TARGET_TYPE(SYMBOL_TYPE(s)) = builtin_type_void;
2693 /* Need a block to allocate .gdbinfo. in */
2695 SYMBOL_BLOCK_VALUE(s) = b;
2696 BLOCK_START(b) = sigtramp_address;
2697 BLOCK_END(b) = sigtramp_end;
2698 BLOCK_FUNCTION(b) = s;
2699 BLOCK_SUPERBLOCK(b) = BLOCK_SUPERBLOCK(b0);
2703 /* Make a .gdbinfo. for it */
2705 struct mips_extra_func_info *e =
2706 (struct mips_extra_func_info *)
2707 xzalloc(sizeof(struct mips_extra_func_info));
2709 e->numargs = 0; /* the kernel thinks otherwise */
2710 /* align_longword(sigcontext + SIGFRAME) */
2711 e->framesize = 0x150;
2712 e->framereg = SP_REGNUM;
2715 e->regoffset = -(41 * sizeof(int));
2717 e->fregoffset = -(37 * sizeof(int));
2720 s = new_symbol(".gdbinfo.");
2721 SYMBOL_VALUE(s) = (int) e;
2722 SYMBOL_NAMESPACE(s) = LABEL_NAMESPACE;
2723 SYMBOL_CLASS(s) = LOC_CONST;
2724 SYMBOL_TYPE(s) = builtin_type_void;
2727 BLOCK_SYM(b,BLOCK_NSYMS(b)++) = s;
2731 /* Initialization */
2733 static struct sym_fns ecoff_sym_fns = {"ecoff", 5,
2734 mipscoff_new_init, mipscoff_symfile_init,
2735 mipscoff_symfile_read, mipscoff_symfile_discard};
2737 _initialize_mipsread ()
2739 add_symtab_fns (&ecoff_sym_fns);
2741 bzero (&global_psymbols, sizeof (global_psymbols));
2742 bzero (&static_psymbols, sizeof (static_psymbols));
2744 /* Missing basic types */
2745 builtin_type_string = make_type(TYPE_CODE_PASCAL_ARRAY,
2747 builtin_type_complex = make_type(TYPE_CODE_FLT,
2748 2 * sizeof(float), 0, "complex");
2749 builtin_type_double_complex = make_type(TYPE_CODE_FLT,
2750 2 * sizeof(double), 0, "double_complex");
2751 builtin_type_fixed_dec = make_type(TYPE_CODE_INT, sizeof(int),
2752 0, "fixed_decimal");
2753 builtin_type_float_dec = make_type(TYPE_CODE_FLT, sizeof(double),
2754 0, "floating_decimal");
2756 /* Templates types */
2757 builtin_type_ptr = lookup_pointer_type (builtin_type_void);
2758 builtin_type_struct = make_type(TYPE_CODE_STRUCT, 0, 0, 0);
2759 builtin_type_union = make_type(TYPE_CODE_UNION, 0, 0, 0);
2760 builtin_type_enum = make_type(TYPE_CODE_ENUM, 0, 0, 0);
2761 builtin_type_range = make_type(TYPE_CODE_RANGE, 0, 0, 0);
2762 builtin_type_set = make_type(TYPE_CODE_SET, 0, 0, 0);