1 /* Read a symbol table in MIPS' format (Third-Eye).
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993 Free Software
5 by Per Bothner, John Gilmore and Ian Lance Taylor at Cygnus Support.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 /* This module provides three functions: mipscoff_symfile_init,
24 which initializes to read a symbol file; mipscoff_new_init, which
25 discards existing cached information when all symbols are being
26 discarded; and mipscoff_symfile_read, which reads a symbol table
29 mipscoff_symfile_read only does the minimum work necessary for letting the
30 user "name" things symbolically; it does not read the entire symtab.
31 Instead, it reads the external and static symbols and puts them in partial
32 symbol tables. When more extensive information is requested of a
33 file, the corresponding partial symbol table is mutated into a full
34 fledged symbol table by going back and reading the symbols
35 for real. mipscoff_psymtab_to_symtab() is called indirectly through
36 a pointer in the psymtab to do this.
38 ECOFF symbol tables are mostly written in the byte order of the
39 target machine. However, one section of the table (the auxiliary
40 symbol information) is written in the host byte order. There is a
41 bit in the other symbol info which describes which host byte order
42 was used. ECOFF thereby takes the trophy from Intel `b.out' for
43 the most brain-dead adaptation of a file format to byte order.
45 This module can read all four of the known byte-order combinations,
46 on any type of host. */
56 #include "stabsread.h"
57 #include "complaints.h"
59 /* These are needed if the tm.h file does not contain the necessary
60 mips specific definitions. */
62 #ifndef MIPS_EFI_SYMBOL_NAME
63 #define MIPS_EFI_SYMBOL_NAME "__GDB_EFI_INFO__"
65 #include "coff/symconst.h"
66 typedef struct mips_extra_func_info {
69 } *mips_extra_func_info_t;
79 #include <sys/types.h>
84 #include <sys/param.h>
89 #include "gdb-stabs.h"
93 #include "coff/internal.h"
94 #include "coff/mips.h" /* COFF-like aspects of ecoff files */
95 #include "coff/ecoff-ext.h" /* External forms of ecoff sym structures */
97 /* FIXME: coff/internal.h and aout/aout64.h both define N_ABS. We
98 want the definition from aout/aout64.h. */
100 /* FIXME: coff/mips.h and aout/aout64.h both define ZMAGIC. We don't
104 #include "libaout.h" /* Private BFD a.out information. */
105 #include "aout/aout64.h"
106 #include "aout/stab_gnu.h" /* STABS information */
108 /* FIXME: libcoff.h and libaout.h both define a couple of macros. We
111 #undef obj_sym_filepos
113 #include "libcoff.h" /* Private BFD COFF information. */
114 #include "libecoff.h" /* Private BFD ECOFF information. */
116 #include "expression.h"
117 #include "language.h" /* Needed inside partial-stab.h */
119 /* Each partial symbol table entry contains a pointer to private data
120 for the read_symtab() function to use when expanding a partial
121 symbol table entry to a full symbol table entry.
123 For mipsread this structure contains the index of the FDR that this
124 psymtab represents and a pointer to the BFD that the psymtab was
127 #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
128 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
129 #define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd)
135 EXTR *extern_tab; /* Pointer to external symbols for this file. */
136 int extern_count; /* Size of extern_tab. */
137 struct mips_pending **pending_list;
140 /* Things we import explicitly from other modules */
142 extern int info_verbose;
144 /* Various complaints about symbol reading that don't abort the process */
146 struct complaint bad_file_number_complaint =
147 {"bad file number %d", 0, 0};
149 struct complaint index_complaint =
150 {"bad aux index at symbol %s", 0, 0};
152 struct complaint aux_index_complaint =
153 {"bad proc end in aux found from symbol %s", 0, 0};
155 struct complaint block_index_complaint =
156 {"bad aux index at block symbol %s", 0, 0};
158 struct complaint unknown_ext_complaint =
159 {"unknown external symbol %s", 0, 0};
161 struct complaint unknown_sym_complaint =
162 {"unknown local symbol %s", 0, 0};
164 struct complaint unknown_st_complaint =
165 {"with type %d", 0, 0};
167 struct complaint block_overflow_complaint =
168 {"block containing %s overfilled", 0, 0};
170 struct complaint basic_type_complaint =
171 {"cannot map MIPS basic type 0x%x", 0, 0};
173 struct complaint unknown_type_qual_complaint =
174 {"unknown type qualifier 0x%x", 0, 0};
176 struct complaint array_bitsize_complaint =
177 {"size of array target type not known, assuming %d bits", 0, 0};
179 struct complaint bad_tag_guess_complaint =
180 {"guessed tag type of %s incorrectly", 0, 0};
182 struct complaint block_member_complaint =
183 {"declaration block contains unhandled symbol type %d", 0, 0};
185 struct complaint stEnd_complaint =
186 {"stEnd with storage class %d not handled", 0, 0};
188 struct complaint unknown_mips_symtype_complaint =
189 {"unknown symbol type 0x%x", 0, 0};
191 struct complaint stab_unknown_complaint =
192 {"unknown stabs symbol %s", 0, 0};
194 struct complaint pdr_for_nonsymbol_complaint =
195 {"PDR for %s, but no symbol", 0, 0};
197 struct complaint pdr_static_symbol_complaint =
198 {"can't handle PDR for static proc at 0x%x", 0, 0};
200 struct complaint bad_setjmp_pdr_complaint =
201 {"fixing bad setjmp PDR from libc", 0, 0};
203 /* Macros and extra defs */
205 /* Already-parsed symbols are marked specially */
207 #define stParsed stType
209 /* Puns: hard to find whether -g was used and how */
211 #define MIN_GLEVEL GLEVEL_0
212 #define compare_glevel(a,b) \
213 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
214 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
216 /* Things that really are local to this module */
218 /* Remember what we deduced to be the source language of this psymtab. */
220 static enum language psymtab_language = language_unknown;
226 /* Pointer to current file decriptor record, and its index */
231 /* Index of current symbol */
235 /* Note how much "debuggable" this image is. We would like
236 to see at least one FDR with full symbols */
241 /* When examining .o files, report on undefined symbols */
243 static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;
245 /* Pseudo symbol to use when putting stabs into the symbol table. */
247 static char stabs_symbol[] = STABS_SYMBOL;
249 /* Extra builtin types */
251 struct type *builtin_type_complex;
252 struct type *builtin_type_double_complex;
253 struct type *builtin_type_fixed_dec;
254 struct type *builtin_type_float_dec;
255 struct type *builtin_type_string;
257 /* Forward declarations */
260 read_mips_symtab PARAMS ((struct objfile *, struct section_offsets *));
263 read_the_mips_symtab PARAMS ((bfd *));
266 upgrade_type PARAMS ((struct type **, int, union aux_ext *, int));
269 parse_partial_symbols PARAMS ((struct objfile *,
270 struct section_offsets *));
273 cross_ref PARAMS ((union aux_ext *, struct type **, enum type_code, char **,
277 fixup_sigtramp PARAMS ((void));
279 static struct symbol *
280 new_symbol PARAMS ((char *));
283 new_type PARAMS ((char *));
285 static struct block *
286 new_block PARAMS ((int));
288 static struct symtab *
289 new_symtab PARAMS ((char *, int, int, struct objfile *));
291 static struct linetable *
292 new_linetable PARAMS ((int));
294 static struct blockvector *
295 new_bvect PARAMS ((int));
298 parse_type PARAMS ((union aux_ext *, int *, int));
300 static struct symbol *
301 mylookup_symbol PARAMS ((char *, struct block *, enum namespace,
302 enum address_class));
304 static struct block *
305 shrink_block PARAMS ((struct block *, struct symtab *));
308 xzalloc PARAMS ((unsigned int));
311 sort_blocks PARAMS ((struct symtab *));
314 compare_blocks PARAMS ((const void *, const void *));
316 static struct partial_symtab *
317 new_psymtab PARAMS ((char *, struct objfile *));
320 static struct partial_symtab *
321 parse_fdr PARAMS ((int, int, struct objfile *));
325 psymtab_to_symtab_1 PARAMS ((struct partial_symtab *, char *));
328 add_block PARAMS ((struct block *, struct symtab *));
331 add_symbol PARAMS ((struct symbol *, struct block *));
334 add_line PARAMS ((struct linetable *, int, CORE_ADDR, int));
336 static struct linetable *
337 shrink_linetable PARAMS ((struct linetable *));
340 mips_next_symbol_text PARAMS ((void));
342 /* Things we export to other modules */
344 /* Address bounds for the signal trampoline in inferior, if any */
345 /* FIXME: Nothing really seems to use this. Why is it here? */
347 CORE_ADDR sigtramp_address, sigtramp_end;
350 mipscoff_new_init (ignore)
351 struct objfile *ignore;
353 stabsread_new_init ();
354 buildsym_new_init ();
358 mipscoff_symfile_init (objfile)
359 struct objfile *objfile;
361 if (objfile->sym_private != NULL)
363 mfree (objfile->md, objfile->sym_private);
365 objfile->sym_private = NULL;
369 mipscoff_symfile_read (objfile, section_offsets, mainline)
370 struct objfile *objfile;
371 struct section_offsets *section_offsets;
374 init_minimal_symbol_collection ();
375 make_cleanup (discard_minimal_symbols, 0);
377 /* Now that the executable file is positioned at symbol table,
378 process it and define symbols accordingly. */
380 read_mips_symtab (objfile, section_offsets);
382 /* Install any minimal symbols that have been collected as the current
383 minimal symbols for this objfile. */
385 install_minimal_symbols (objfile);
388 /* Perform any local cleanups required when we are done with a particular
389 objfile. I.E, we are in the process of discarding all symbol information
390 for an objfile, freeing up all memory held for it, and unlinking the
391 objfile struct from the global list of known objfiles. */
394 mipscoff_symfile_finish (objfile)
395 struct objfile *objfile;
397 if (objfile->sym_private != NULL)
399 mfree (objfile->md, objfile->sym_private);
405 /* Allocate zeroed memory */
411 PTR p = xmalloc (size);
417 /* Exported procedure: Builds a symtab from the PST partial one.
418 Restores the environment in effect when PST was created, delegates
419 most of the work to an ancillary procedure, and sorts
420 and reorders the symtab list at the end */
423 mipscoff_psymtab_to_symtab (pst)
424 struct partial_symtab *pst;
432 printf_filtered ("Reading in symbols for %s...", pst->filename);
436 next_symbol_text_func = mips_next_symbol_text;
438 psymtab_to_symtab_1 (pst, pst->filename);
440 /* Match with global symbols. This only needs to be done once,
441 after all of the symtabs and dependencies have been read in. */
442 scan_file_globals (pst->objfile);
445 printf_filtered ("done.\n");
448 /* Exported procedure: Is PC in the signal trampoline code */
451 in_sigtramp (pc, ignore)
453 char *ignore; /* function name */
455 if (sigtramp_address == 0)
457 return (pc >= sigtramp_address && pc < sigtramp_end);
460 /* File-level interface functions */
462 /* Read the symtab information from file ABFD into memory. */
465 read_the_mips_symtab (abfd)
468 if (ecoff_slurp_symbolic_info (abfd) == false)
469 error ("Error reading symbol table: %s", bfd_errmsg (bfd_error));
472 /* Find a file descriptor given its index RF relative to a file CF */
482 fdrs = ecoff_data (cur_bfd)->fdr;
484 /* Object files do not have the RFD table, all refs are absolute */
487 ecoff_swap_rfd_in (cur_bfd,
488 ecoff_data (cur_bfd)->external_rfd + f->rfdBase + rf,
493 /* Return a safer print NAME for a file descriptor */
500 return "<stripped file>";
503 return ecoff_data (cur_bfd)->ss + f->issBase + f->rss;
507 /* Read in and parse the symtab of the file OBJFILE. Symbols from
508 different sections are relocated via the SECTION_OFFSETS. */
511 read_mips_symtab (objfile, section_offsets)
512 struct objfile *objfile;
513 struct section_offsets *section_offsets;
515 cur_bfd = objfile->obfd;
517 read_the_mips_symtab (objfile->obfd);
519 parse_partial_symbols (objfile, section_offsets);
522 /* Check to make sure file was compiled with -g. If not, warn the
523 user of this limitation. */
524 if (compare_glevel (max_glevel, GLEVEL_2) < 0)
526 if (max_gdbinfo == 0)
527 printf ("\n%s not compiled with -g, debugging support is limited.\n",
529 printf ("You should compile with -g2 or -g3 for best debugging support.\n");
535 /* Local utilities */
537 /* Map of FDR indexes to partial symtabs */
541 struct partial_symtab *pst; /* the psymtab proper */
542 int n_globals; /* exported globals (external symbols) */
543 int globals_offset; /* cumulative */
547 /* Utility stack, used to nest procedures and blocks properly.
548 It is a doubly linked list, to avoid too many alloc/free.
549 Since we might need it quite a few times it is NOT deallocated
552 static struct parse_stack
554 struct parse_stack *next, *prev;
555 struct symtab *cur_st; /* Current symtab. */
556 struct block *cur_block; /* Block in it. */
557 int blocktype; /* What are we parsing. */
558 int maxsyms; /* Max symbols in this block. */
559 struct type *cur_type; /* Type we parse fields for. */
560 int cur_field; /* Field number in cur_type. */
561 int procadr; /* Start addres of this procedure */
562 int numargs; /* Its argument count */
565 *top_stack; /* Top stack ptr */
568 /* Enter a new lexical context */
573 struct parse_stack *new;
575 /* Reuse frames if possible */
576 if (top_stack && top_stack->prev)
577 new = top_stack->prev;
579 new = (struct parse_stack *) xzalloc (sizeof (struct parse_stack));
580 /* Initialize new frame with previous content */
583 register struct parse_stack *prev = new->prev;
586 top_stack->prev = new;
588 new->next = top_stack;
593 /* Exit a lexical context */
601 top_stack = top_stack->next;
605 /* Cross-references might be to things we haven't looked at
606 yet, e.g. type references. To avoid too many type
607 duplications we keep a quick fixup table, an array
608 of lists of references indexed by file descriptor */
610 static struct mips_pending
612 struct mips_pending *next; /* link */
613 struct sym_ext *s; /* the symbol */
614 struct type *t; /* its partial type descriptor */
618 /* Check whether we already saw symbol SH in file FH as undefined */
620 static struct mips_pending *
621 is_pending_symbol (fh, sh)
625 int f_idx = fh - ecoff_data (cur_bfd)->fdr;
626 register struct mips_pending *p;
628 /* Linear search is ok, list is typically no more than 10 deep */
629 for (p = pending_list[f_idx]; p; p = p->next)
635 /* Add a new undef symbol SH of type T */
638 add_pending (fh, sh, t)
643 int f_idx = fh - ecoff_data (cur_bfd)->fdr;
644 struct mips_pending *p = is_pending_symbol (fh, sh);
646 /* Make sure we do not make duplicates */
649 p = (struct mips_pending *) xmalloc (sizeof (*p));
652 p->next = pending_list[f_idx];
653 pending_list[f_idx] = p;
657 /* Throw away undef entries when done with file index F_IDX */
658 /* FIXME -- storage leak. This is never called!!! --gnu */
666 register struct mips_pending *p, *q;
668 for (p = pending_list[f_idx]; p; p = q)
673 pending_list[f_idx] = 0;
679 prepend_tag_kind (tag_name, type_code)
681 enum type_code type_code;
690 case TYPE_CODE_STRUCT:
693 case TYPE_CODE_UNION:
700 result = (char *) obstack_alloc (¤t_objfile->symbol_obstack,
701 strlen (prefix) + strlen (tag_name) + 1);
702 sprintf (result, "%s%s", prefix, tag_name);
707 /* Parsing Routines proper. */
709 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
710 For blocks, procedures and types we open a new lexical context.
711 This is basically just a big switch on the symbol's type. Argument
712 AX is the base pointer of aux symbols for this file (fh->iauxBase).
713 EXT_SH points to the unswapped symbol, which is needed for struct,
714 union, etc., types; it is NULL for an EXTR. BIGEND says whether
715 aux symbols are big-endian or little-endian. Return count of
716 SYMR's handled (normally one).
718 FIXME: This modifies the symbol, but the only way we have to save
719 the modified information is to stuff it back into the BFD data. */
722 parse_symbol (sh, ax, ext_sh, bigend)
725 struct sym_ext *ext_sh;
731 struct mips_pending *pend;
735 enum address_class class;
738 if (ext_sh == (struct sym_ext *) NULL)
739 name = ecoff_data (cur_bfd)->ssext + sh->iss;
741 name = ecoff_data (cur_bfd)->ss + cur_fdr->issBase + sh->iss;
748 case stGlobal: /* external symbol, goes into global block */
750 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
752 s = new_symbol (name);
753 SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
756 case stStatic: /* static data, goes into current block. */
758 b = top_stack->cur_block;
759 s = new_symbol (name);
760 SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
763 case stLocal: /* local variable, goes into current block */
764 if (sh->sc == scRegister)
766 class = LOC_REGISTER;
768 sh->value += FP0_REGNUM - 32;
772 b = top_stack->cur_block;
773 s = new_symbol (name);
774 SYMBOL_VALUE (s) = sh->value;
776 data: /* Common code for symbols describing data */
777 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
778 SYMBOL_CLASS (s) = class;
781 /* Type could be missing in a number of cases */
782 if (sh->sc == scUndefined || sh->sc == scNil ||
783 sh->index == 0xfffff)
784 SYMBOL_TYPE (s) = builtin_type_int; /* undefined? */
786 SYMBOL_TYPE (s) = parse_type (ax + sh->index, 0, bigend);
787 /* Value of a data symbol is its memory address */
790 case stParam: /* arg to procedure, goes into current block */
792 top_stack->numargs++;
794 /* Special GNU C++ name. */
795 if (name[0] == CPLUS_MARKER && name[1] == 't' && name[2] == 0)
796 name = "this"; /* FIXME, not alloc'd in obstack */
797 s = new_symbol (name);
799 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
800 if (sh->sc == scRegister)
802 SYMBOL_CLASS (s) = LOC_REGPARM;
804 sh->value += FP0_REGNUM - 32;
807 SYMBOL_CLASS (s) = LOC_ARG;
808 SYMBOL_VALUE (s) = sh->value;
809 SYMBOL_TYPE (s) = parse_type (ax + sh->index, 0, bigend);
810 add_symbol (s, top_stack->cur_block);
812 /* FIXME: This has not been tested. See dbxread.c */
813 /* Add the type of this parameter to the function/procedure
814 type of this block. */
815 add_param_to_type (&top_stack->cur_block->function->type, s);
819 case stLabel: /* label, goes into current block */
820 s = new_symbol (name);
821 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE; /* so that it can be used */
822 SYMBOL_CLASS (s) = LOC_LABEL; /* but not misused */
823 SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
824 SYMBOL_TYPE (s) = builtin_type_int;
825 add_symbol (s, top_stack->cur_block);
828 case stProc: /* Procedure, usually goes into global block */
829 case stStaticProc: /* Static procedure, goes into current block */
830 s = new_symbol (name);
831 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
832 SYMBOL_CLASS (s) = LOC_BLOCK;
833 /* Type of the return value */
834 if (sh->sc == scUndefined || sh->sc == scNil)
835 t = builtin_type_int;
837 t = parse_type (ax + sh->index + 1, 0, bigend);
838 b = top_stack->cur_block;
839 if (sh->st == stProc)
841 struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
842 /* The next test should normally be true,
843 but provides a hook for nested functions
844 (which we don't want to make global). */
845 if (b == BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK))
846 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
850 /* Make a type for the procedure itself */
852 /* FIXME: This has not been tested yet! See dbxread.c */
853 /* Generate a template for the type of this function. The
854 types of the arguments will be added as we read the symbol
856 bcopy (SYMBOL_TYPE (s), lookup_function_type (t), sizeof (struct type));
858 SYMBOL_TYPE (s) = lookup_function_type (t);
861 /* Create and enter a new lexical context */
862 b = new_block (top_stack->maxsyms);
863 SYMBOL_BLOCK_VALUE (s) = b;
864 BLOCK_FUNCTION (b) = s;
865 BLOCK_START (b) = BLOCK_END (b) = sh->value;
866 BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
867 add_block (b, top_stack->cur_st);
869 /* Not if we only have partial info */
870 if (sh->sc == scUndefined || sh->sc == scNil)
874 top_stack->cur_block = b;
875 top_stack->blocktype = sh->st;
876 top_stack->cur_type = SYMBOL_TYPE (s);
877 top_stack->cur_field = -1;
878 top_stack->procadr = sh->value;
879 top_stack->numargs = 0;
881 sh->value = (long) SYMBOL_TYPE (s);
884 /* Beginning of code for structure, union, and enum definitions.
885 They all share a common set of local variables, defined here. */
887 enum type_code type_code;
888 struct sym_ext *ext_tsym;
893 case stStruct: /* Start a block defining a struct type */
894 type_code = TYPE_CODE_STRUCT;
895 goto structured_common;
897 case stUnion: /* Start a block defining a union type */
898 type_code = TYPE_CODE_UNION;
899 goto structured_common;
901 case stEnum: /* Start a block defining an enum type */
902 type_code = TYPE_CODE_ENUM;
903 goto structured_common;
905 case stBlock: /* Either a lexical block, or some type */
906 if (sh->sc != scInfo)
907 goto case_stBlock_code; /* Lexical block */
909 type_code = TYPE_CODE_UNDEF; /* We have a type. */
911 /* Common code for handling struct, union, enum, and/or as-yet-
912 unknown-type blocks of info about structured data. `type_code'
913 has been set to the proper TYPE_CODE, if we know it. */
916 top_stack->blocktype = stBlock;
918 s = new_symbol (name);
919 SYMBOL_NAMESPACE (s) = STRUCT_NAMESPACE;
920 SYMBOL_CLASS (s) = LOC_TYPEDEF;
921 SYMBOL_VALUE (s) = 0;
922 add_symbol (s, top_stack->cur_block);
924 /* First count the number of fields and the highest value. */
927 for (ext_tsym = ext_sh + 1; ; ext_tsym++)
931 ecoff_swap_sym_in (cur_bfd, ext_tsym, &tsym);
933 if (tsym.st == stEnd)
936 if (tsym.st == stMember)
938 if (nfields == 0 && type_code == TYPE_CODE_UNDEF)
939 /* If the type of the member is Nil (or Void),
940 without qualifiers, assume the tag is an
942 if (tsym.index == indexNil)
943 type_code = TYPE_CODE_ENUM;
946 ecoff_swap_tir_in (bigend,
947 &ax[tsym.index].a_ti,
949 if ((tir.bt == btNil || tir.bt == btVoid)
951 type_code = TYPE_CODE_ENUM;
954 if (tsym.value > max_value)
955 max_value = tsym.value;
957 else if (tsym.st == stBlock
958 || tsym.st == stUnion
960 || tsym.st == stStruct
961 || tsym.st == stParsed)
963 if (tsym.sc == scVariant); /*UNIMPLEMENTED*/
966 /* This is something like a struct within a
967 struct. Skip over the fields of the inner
968 struct. The -1 is because the for loop will
969 increment ext_tsym. */
970 ext_tsym = (ecoff_data (cur_bfd)->external_sym
977 complain (&block_member_complaint, tsym.st);
980 /* In an stBlock, there is no way to distinguish structs,
981 unions, and enums at this point. This is a bug in the
982 original design (that has been fixed with the recent
983 addition of the stStruct, stUnion, and stEnum symbol
984 types.) The way you can tell is if/when you see a variable
985 or field of that type. In that case the variable's type
986 (in the AUX table) says if the type is struct, union, or
987 enum, and points back to the stBlock here. So you can
988 patch the tag kind up later - but only if there actually is
989 a variable or field of that type.
991 So until we know for sure, we will guess at this point.
993 If the first member has index==indexNil or a void type,
994 assume we have an enumeration.
995 Otherwise, if there is more than one member, and all
996 the members have offset 0, assume we have a union.
997 Otherwise, assume we have a struct.
999 The heuristic could guess wrong in the case of of an
1000 enumeration with no members or a union with one (or zero)
1001 members, or when all except the last field of a struct have
1002 width zero. These are uncommon and/or illegal situations,
1003 and in any case guessing wrong probably doesn't matter
1006 But if we later do find out we were wrong, we fixup the tag
1007 kind. Members of an enumeration must be handled
1008 differently from struct/union fields, and that is harder to
1009 patch up, but luckily we shouldn't need to. (If there are
1010 any enumeration members, we can tell for sure it's an enum
1013 if (type_code == TYPE_CODE_UNDEF)
1014 if (nfields > 1 && max_value == 0)
1015 type_code = TYPE_CODE_UNION;
1017 type_code = TYPE_CODE_STRUCT;
1019 /* If this type was expected, use its partial definition */
1020 pend = is_pending_symbol (cur_fdr, ext_sh);
1021 if (pend != (struct mips_pending *) NULL)
1024 t = new_type (prepend_tag_kind (name, type_code));
1026 TYPE_CODE (t) = type_code;
1027 TYPE_LENGTH (t) = sh->value;
1028 TYPE_NFIELDS (t) = nfields;
1029 TYPE_FIELDS (t) = f = ((struct field *)
1031 nfields * sizeof (struct field)));
1033 if (type_code == TYPE_CODE_ENUM)
1035 /* This is a non-empty enum. */
1036 for (ext_tsym = ext_sh + 1; ; ext_tsym++)
1039 struct symbol *enum_sym;
1041 ecoff_swap_sym_in (cur_bfd, ext_tsym, &tsym);
1043 if (tsym.st != stMember)
1046 f->bitpos = tsym.value;
1048 f->name = (ecoff_data (cur_bfd)->ss
1053 enum_sym = ((struct symbol *)
1054 obstack_alloc (¤t_objfile->symbol_obstack,
1055 sizeof (struct symbol)));
1056 memset ((PTR) enum_sym, 0, sizeof (struct symbol));
1057 SYMBOL_NAME (enum_sym) = f->name;
1058 SYMBOL_CLASS (enum_sym) = LOC_CONST;
1059 SYMBOL_TYPE (enum_sym) = t;
1060 SYMBOL_NAMESPACE (enum_sym) = VAR_NAMESPACE;
1061 SYMBOL_VALUE (enum_sym) = tsym.value;
1062 add_symbol (enum_sym, top_stack->cur_block);
1064 /* Skip the stMembers that we've handled. */
1069 SYMBOL_TYPE (s) = t;
1070 /* make this the current type */
1071 top_stack->cur_type = t;
1072 top_stack->cur_field = 0;
1073 /* Mark that symbol has a type, and say which one */
1074 sh->value = (long) t;
1077 /* End of local variables shared by struct, union, enum, and
1078 block (as yet unknown struct/union/enum) processing. */
1082 /* beginnning of (code) block. Value of symbol
1083 is the displacement from procedure start */
1084 push_parse_stack ();
1085 top_stack->blocktype = stBlock;
1086 b = new_block (top_stack->maxsyms);
1087 BLOCK_START (b) = sh->value + top_stack->procadr;
1088 BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
1089 top_stack->cur_block = b;
1090 add_block (b, top_stack->cur_st);
1093 case stEnd: /* end (of anything) */
1094 if (sh->sc == scInfo)
1096 /* Finished with type */
1097 top_stack->cur_type = 0;
1099 else if (sh->sc == scText &&
1100 (top_stack->blocktype == stProc ||
1101 top_stack->blocktype == stStaticProc))
1103 /* Finished with procedure */
1104 struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
1105 struct mips_extra_func_info *e;
1109 BLOCK_END (top_stack->cur_block) += sh->value; /* size */
1111 /* Make up special symbol to contain procedure specific info */
1112 s = new_symbol (MIPS_EFI_SYMBOL_NAME);
1113 SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
1114 SYMBOL_CLASS (s) = LOC_CONST;
1115 SYMBOL_TYPE (s) = builtin_type_void;
1116 e = ((struct mips_extra_func_info *)
1117 obstack_alloc (¤t_objfile->symbol_obstack,
1118 sizeof (struct mips_extra_func_info)));
1119 SYMBOL_VALUE (s) = (int) e;
1120 e->numargs = top_stack->numargs;
1121 add_symbol (s, top_stack->cur_block);
1123 /* Reallocate symbols, saving memory */
1124 b = shrink_block (top_stack->cur_block, top_stack->cur_st);
1126 /* f77 emits proc-level with address bounds==[0,0],
1127 So look for such child blocks, and patch them. */
1128 for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
1130 struct block *b_bad = BLOCKVECTOR_BLOCK (bv, i);
1131 if (BLOCK_SUPERBLOCK (b_bad) == b
1132 && BLOCK_START (b_bad) == top_stack->procadr
1133 && BLOCK_END (b_bad) == top_stack->procadr)
1135 BLOCK_START (b_bad) = BLOCK_START (b);
1136 BLOCK_END (b_bad) = BLOCK_END (b);
1140 else if (sh->sc == scText && top_stack->blocktype == stBlock)
1142 /* End of (code) block. The value of the symbol is the
1143 displacement from the procedure`s start address of the
1144 end of this block. */
1145 BLOCK_END (top_stack->cur_block) = sh->value + top_stack->procadr;
1146 shrink_block (top_stack->cur_block, top_stack->cur_st);
1148 else if (sh->sc == scText && top_stack->blocktype == stFile)
1150 /* End of file. Pop parse stack and ignore. Higher
1151 level code deals with this. */
1155 complain (&stEnd_complaint, sh->sc);
1157 pop_parse_stack (); /* restore previous lexical context */
1160 case stMember: /* member of struct or union */
1161 f = &TYPE_FIELDS (top_stack->cur_type)[top_stack->cur_field++];
1163 f->bitpos = sh->value;
1165 f->type = parse_type (ax + sh->index, &f->bitsize, bigend);
1168 case stTypedef: /* type definition */
1169 s = new_symbol (name);
1170 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
1171 SYMBOL_CLASS (s) = LOC_TYPEDEF;
1172 SYMBOL_BLOCK_VALUE (s) = top_stack->cur_block;
1173 add_symbol (s, top_stack->cur_block);
1174 SYMBOL_TYPE (s) = parse_type (ax + sh->index, 0, bigend);
1175 sh->value = (long) SYMBOL_TYPE (s);
1178 case stFile: /* file name */
1179 push_parse_stack ();
1180 top_stack->blocktype = sh->st;
1183 /* I`ve never seen these for C */
1185 break; /* register relocation */
1187 break; /* forwarding address */
1189 break; /* constant */
1191 complain (&unknown_mips_symtype_complaint, sh->st);
1200 /* Parse the type information provided in the raw AX entries for
1201 the symbol SH. Return the bitfield size in BS, in case.
1202 We must byte-swap the AX entries before we use them; BIGEND says whether
1203 they are big-endian or little-endian (from fh->fBigendian). */
1205 static struct type *
1206 parse_type (ax, bs, bigend)
1211 /* Null entries in this map are treated specially */
1212 static struct type **map_bt[] =
1214 &builtin_type_void, /* btNil */
1216 &builtin_type_char, /* btChar */
1217 &builtin_type_unsigned_char,/* btUChar */
1218 &builtin_type_short, /* btShort */
1219 &builtin_type_unsigned_short, /* btUShort */
1220 &builtin_type_int, /* btInt */
1221 &builtin_type_unsigned_int, /* btUInt */
1222 &builtin_type_long, /* btLong */
1223 &builtin_type_unsigned_long,/* btULong */
1224 &builtin_type_float, /* btFloat */
1225 &builtin_type_double, /* btDouble */
1232 &builtin_type_complex, /* btComplex */
1233 &builtin_type_double_complex, /* btDComplex */
1235 &builtin_type_fixed_dec, /* btFixedDec */
1236 &builtin_type_float_dec, /* btFloatDec */
1237 &builtin_type_string, /* btString */
1240 &builtin_type_void, /* btVoid */
1241 &builtin_type_long_long, /* btLongLong */
1242 &builtin_type_unsigned_long_long, /* btULongLong */
1246 struct type *tp = 0;
1249 enum type_code type_code = TYPE_CODE_UNDEF;
1251 /* Use aux as a type information record, map its basic type. */
1253 ecoff_swap_tir_in (bigend, &tax->a_ti, t);
1254 if (t->bt > (sizeof (map_bt) / sizeof (*map_bt)))
1256 complain (&basic_type_complaint, t->bt);
1257 return builtin_type_int;
1261 tp = *map_bt[t->bt];
1267 /* Cannot use builtin types -- build our own */
1271 tp = lookup_pointer_type (builtin_type_void);
1275 type_code = TYPE_CODE_STRUCT;
1279 type_code = TYPE_CODE_UNION;
1283 type_code = TYPE_CODE_ENUM;
1287 type_code = TYPE_CODE_RANGE;
1291 type_code = TYPE_CODE_SET;
1296 complain (&basic_type_complaint, t->bt);
1297 return builtin_type_int;
1301 /* Skip over any further type qualifiers (FIXME). */
1304 /* This is the way it would work if the compiler worked */
1309 ecoff_swap_tir_in (bigend, &ax->a_ti, t1);
1311 while (t1->continued);
1314 /* Move on to next aux */
1319 *bs = AUX_GET_WIDTH (bigend, ax);
1323 /* All these types really point to some (common) MIPS type
1324 definition, and only the type-qualifiers fully identify
1325 them. We'll make the same effort at sharing. */
1326 if (t->bt == btIndirect ||
1327 t->bt == btStruct ||
1330 t->bt == btTypedef ||
1334 char name[256], *pn;
1336 /* Try to cross reference this type */
1337 ax += cross_ref (ax, &tp, type_code, &pn, bigend);
1338 /* reading .o file ? */
1339 if (tp == (struct type *) NULL)
1340 tp = init_type (type_code, 0, 0, (char *) NULL,
1341 (struct objfile *) NULL);
1342 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1343 sprintf (name, fmt, pn);
1345 /* Usually, TYPE_CODE(tp) is already type_code. The main
1346 exception is if we guessed wrong re struct/union/enum. */
1347 if (TYPE_CODE (tp) != type_code)
1349 complain (&bad_tag_guess_complaint, name);
1350 TYPE_CODE (tp) = type_code;
1352 if (TYPE_NAME (tp) == NULL || !STREQ (TYPE_NAME (tp), name))
1353 TYPE_NAME (tp) = obsavestring (name, strlen (name),
1354 ¤t_objfile->type_obstack);
1357 /* Deal with range types */
1358 if (t->bt == btRange)
1360 TYPE_NFIELDS (tp) = 2;
1361 TYPE_FIELDS (tp) = ((struct field *)
1362 TYPE_ALLOC (tp, 2 * sizeof (struct field)));
1363 TYPE_FIELD_NAME (tp, 0) = obsavestring ("Low", strlen ("Low"),
1364 ¤t_objfile->type_obstack);
1365 TYPE_FIELD_BITPOS (tp, 0) = AUX_GET_DNLOW (bigend, ax);
1367 TYPE_FIELD_NAME (tp, 1) = obsavestring ("High", strlen ("High"),
1368 ¤t_objfile->type_obstack);
1369 TYPE_FIELD_BITPOS (tp, 1) = AUX_GET_DNHIGH (bigend, ax);
1373 /* Parse all the type qualifiers now. If there are more
1374 than 6 the game will continue in the next aux */
1376 #define PARSE_TQ(tq) \
1377 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, bigend);
1379 again:PARSE_TQ (tq0);
1390 ecoff_swap_tir_in (bigend, &tax->a_ti, t);
1396 /* Make up a complex type from a basic one. Type is passed by
1397 reference in TPP and side-effected as necessary. The type
1398 qualifier TQ says how to handle the aux symbols at AX for
1399 the symbol SX we are currently analyzing. BIGEND says whether
1400 aux symbols are big-endian or little-endian.
1401 Returns the number of aux symbols we parsed. */
1404 upgrade_type (tpp, tq, ax, bigend)
1413 /* Used in array processing */
1424 t = lookup_pointer_type (*tpp);
1429 t = lookup_function_type (*tpp);
1436 /* Determine and record the domain type (type of index) */
1437 ecoff_swap_rndx_in (bigend, &ax->a_rndx, &rndx);
1443 rf = AUX_GET_ISYM (bigend, ax);
1446 fh = get_rfd (cur_fd, rf);
1448 indx = parse_type ((ecoff_data (cur_bfd)->external_aux
1451 (int *) NULL, bigend);
1453 /* Get the bounds, and create the array type. */
1455 lower = AUX_GET_DNLOW (bigend, ax);
1457 upper = AUX_GET_DNHIGH (bigend, ax);
1459 rf = AUX_GET_WIDTH (bigend, ax); /* bit size of array element */
1461 range = create_range_type ((struct type *) NULL, indx,
1464 t = create_array_type ((struct type *) NULL, *tpp, range);
1466 /* Check whether supplied array element bit size matches
1467 the known size of the element type. If this complaint
1468 ends up not happening, we can remove this code. It's
1469 here because we aren't sure we understand this *&%&$
1471 id = TYPE_LENGTH (TYPE_TARGET_TYPE (t)) << 3; /* bitsize */
1474 /* Most likely an undefined type */
1476 TYPE_LENGTH (TYPE_TARGET_TYPE (t)) = id >> 3;
1479 complain (&array_bitsize_complaint, rf);
1485 /* Volatile -- currently ignored */
1489 /* Const -- currently ignored */
1493 complain (&unknown_type_qual_complaint, tq);
1499 /* Parse a procedure descriptor record PR. Note that the procedure is
1500 parsed _after_ the local symbols, now we just insert the extra
1501 information we need into a MIPS_EFI_SYMBOL_NAME symbol that has
1502 already been placed in the procedure's main block. Note also that
1503 images that have been partially stripped (ld -x) have been deprived
1504 of local symbols, and we have to cope with them here. FIRST_OFF is
1505 the offset of the first procedure for this FDR; we adjust the
1506 address by this amount, but I don't know why. */
1509 parse_procedure (pr, have_stabs, first_off)
1512 unsigned long first_off;
1514 struct symbol *s, *i;
1516 struct mips_extra_func_info *e;
1519 /* Simple rule to find files linked "-x" */
1520 if (cur_fdr->rss == -1)
1524 /* Static procedure at address pr->adr. Sigh. */
1525 complain (&pdr_static_symbol_complaint, pr->adr);
1533 ecoff_swap_ext_in (cur_bfd,
1534 ecoff_data (cur_bfd)->external_ext + pr->isym,
1536 sh_name = ecoff_data (cur_bfd)->ssext + she.asym.iss;
1544 ecoff_swap_sym_in (cur_bfd,
1545 (ecoff_data (cur_bfd)->external_sym
1549 sh_name = ecoff_data (cur_bfd)->ss + cur_fdr->issBase + sh.iss;
1554 /* We have to save the cur_fdr across the call to lookup_symbol.
1555 If the pdr is for a static function and if a global function with
1556 the same name exists, lookup_symbol will eventually read in the symtab
1557 for the global function and clobber cur_fdr. */
1558 FDR *save_cur_fdr = cur_fdr;
1559 s = lookup_symbol (sh_name, NULL, VAR_NAMESPACE, 0, NULL);
1560 cur_fdr = save_cur_fdr;
1563 s = mylookup_symbol (sh_name, top_stack->cur_block,
1564 VAR_NAMESPACE, LOC_BLOCK);
1568 b = SYMBOL_BLOCK_VALUE (s);
1572 complain (&pdr_for_nonsymbol_complaint, sh_name);
1576 /* FIXME -- delete. We can't do symbol allocation now; it's all done. */
1577 s = new_symbol (sh_name);
1578 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
1579 SYMBOL_CLASS (s) = LOC_BLOCK;
1580 /* Donno its type, hope int is ok */
1581 SYMBOL_TYPE (s) = lookup_function_type (builtin_type_int);
1582 add_symbol (s, top_stack->cur_block);
1583 /* Wont have symbols for this one */
1585 SYMBOL_BLOCK_VALUE (s) = b;
1586 BLOCK_FUNCTION (b) = s;
1587 BLOCK_START (b) = pr->adr;
1588 /* BOUND used to be the end of procedure's text, but the
1589 argument is no longer passed in. */
1590 BLOCK_END (b) = bound;
1591 BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
1592 add_block (b, top_stack->cur_st);
1596 i = mylookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, LOC_CONST);
1600 e = (struct mips_extra_func_info *) SYMBOL_VALUE (i);
1602 e->pdr.isym = (long) s;
1603 e->pdr.adr += cur_fdr->adr - first_off;
1605 /* Correct incorrect setjmp procedure descriptor from the library
1606 to make backtrace through setjmp work. */
1607 if (e->pdr.pcreg == 0 && strcmp (sh_name, "setjmp") == 0)
1609 complain (&bad_setjmp_pdr_complaint, 0);
1610 e->pdr.pcreg = RA_REGNUM;
1611 e->pdr.regmask = 0x80000000;
1612 e->pdr.regoffset = -4;
1617 /* Parse the external symbol ES. Just call parse_symbol() after
1618 making sure we know where the aux are for it. For procedures,
1619 parsing of the PDRs has already provided all the needed
1620 information, we only parse them if SKIP_PROCEDURES is false,
1621 and only if this causes no symbol duplication.
1622 BIGEND says whether aux entries are big-endian or little-endian.
1624 This routine clobbers top_stack->cur_block and ->cur_st. */
1627 parse_external (es, skip_procedures, bigend)
1629 int skip_procedures;
1634 if (es->ifd != ifdNil)
1637 cur_fdr = ecoff_data (cur_bfd)->fdr + cur_fd;
1638 ax = ecoff_data (cur_bfd)->external_aux + cur_fdr->iauxBase;
1642 cur_fdr = ecoff_data (cur_bfd)->fdr;
1646 /* Reading .o files */
1647 if (es->asym.sc == scUndefined || es->asym.sc == scNil)
1650 switch (es->asym.st)
1670 /* FIXME: Turn this into a complaint? */
1672 printf_filtered ("Warning: %s `%s' is undefined (in %s)\n",
1674 ecoff_data (cur_bfd)->ssext + es->asym.iss,
1675 fdr_name (cur_fdr));
1679 switch (es->asym.st)
1682 /* If we have full symbols we do not need more */
1683 if (skip_procedures)
1685 if (mylookup_symbol (ecoff_data (cur_bfd)->ssext + es->asym.iss,
1686 top_stack->cur_block,
1687 VAR_NAMESPACE, LOC_BLOCK))
1692 /* Note that the case of a symbol with indexNil must be handled
1693 anyways by parse_symbol(). */
1694 parse_symbol (&es->asym, ax, (struct sym_ext *) NULL, bigend);
1695 /* Note that parse_symbol changed es->asym. */
1702 /* Parse the line number info for file descriptor FH into
1703 GDB's linetable LT. MIPS' encoding requires a little bit
1704 of magic to get things out. Note also that MIPS' line
1705 numbers can go back and forth, apparently we can live
1706 with that and do not need to reorder our linetables */
1709 parse_lines (fh, pr, lt)
1712 struct linetable *lt;
1714 unsigned char *base;
1716 int delta, count, lineno = 0;
1717 unsigned long first_off = pr->adr;
1719 if (fh->cbLineOffset == 0)
1722 base = ecoff_data (cur_bfd)->line + fh->cbLineOffset;
1724 /* Scan by procedure descriptors */
1726 for (j = 0; j < fh->cpd; j++, pr++)
1731 /* No code for this one */
1732 if (pr->iline == ilineNil ||
1733 pr->lnLow == -1 || pr->lnHigh == -1)
1736 /* Aurgh! To know where to stop expanding we must look-ahead. */
1737 for (l = 1; l < (fh->cpd - j); l++)
1738 if (pr[l].iline != -1)
1740 if (l == (fh->cpd - j))
1745 /* When procedures are moved around the linenumbers are
1746 attributed to the next procedure up. */
1747 if (pr->iline >= halt)
1750 base = ecoff_data (cur_bfd)->line + fh->cbLineOffset + pr->cbLineOffset;
1751 adr = fh->adr + pr->adr - first_off;
1752 l = adr >> 2; /* in words */
1753 halt += (adr >> 2) - pr->iline;
1754 for (lineno = pr->lnLow; l < halt;)
1756 count = *base & 0x0f;
1757 delta = *base++ >> 4;
1762 delta = (base[0] << 8) | base[1];
1763 if (delta >= 0x8000)
1767 lineno += delta; /* first delta is 0 */
1768 k = add_line (lt, lineno, l, k);
1774 /* Master parsing procedure for first-pass reading of file symbols
1775 into a partial_symtab. */
1778 parse_partial_symbols (objfile, section_offsets)
1779 struct objfile *objfile;
1780 struct section_offsets *section_offsets;
1783 HDRR *hdr = &ecoff_data (cur_bfd)->symbolic_header;
1784 /* Running pointers */
1786 struct ext_ext *ext_out;
1787 struct ext_ext *ext_out_end;
1789 register EXTR *ext_in;
1792 struct partial_symtab *pst;
1794 int past_first_source_file = 0;
1796 /* List of current psymtab's include files */
1797 char **psymtab_include_list;
1798 int includes_allocated;
1801 struct pst_map *fdr_to_pst;
1802 /* Index within current psymtab dependency list */
1803 struct partial_symtab **dependency_list;
1804 int dependencies_used, dependencies_allocated;
1805 struct cleanup *old_chain;
1808 extern_tab = (EXTR *) obstack_alloc (&objfile->psymbol_obstack,
1809 sizeof (EXTR) * hdr->iextMax);
1811 includes_allocated = 30;
1813 psymtab_include_list = (char **) alloca (includes_allocated *
1815 next_symbol_text_func = mips_next_symbol_text;
1817 dependencies_allocated = 30;
1818 dependencies_used = 0;
1820 (struct partial_symtab **) alloca (dependencies_allocated *
1821 sizeof (struct partial_symtab *));
1823 last_source_file = NULL;
1828 * Only parse the Local and External symbols, and the Relative FDR.
1829 * Fixup enough of the loader symtab to be able to use it.
1830 * Allocate space only for the file's portions we need to
1835 max_glevel = MIN_GLEVEL;
1837 /* Allocate the map FDR -> PST.
1838 Minor hack: -O3 images might claim some global data belongs
1839 to FDR -1. We`ll go along with that */
1840 fdr_to_pst = (struct pst_map *) xzalloc ((hdr->ifdMax + 1) * sizeof *fdr_to_pst);
1841 old_chain = make_cleanup (free, fdr_to_pst);
1844 struct partial_symtab *pst = new_psymtab ("", objfile);
1845 fdr_to_pst[-1].pst = pst;
1849 /* Pass 0 over external syms: swap them in. */
1850 ext_block = (EXTR *) xmalloc (hdr->iextMax * sizeof (EXTR));
1851 make_cleanup (free, ext_block);
1853 ext_out = ecoff_data (cur_bfd)->external_ext;
1854 ext_out_end = ext_out + hdr->iextMax;
1856 for (; ext_out < ext_out_end; ext_out++, ext_in++)
1857 ecoff_swap_ext_in (cur_bfd, ext_out, ext_in);
1859 /* Pass 1 over external syms: Presize and partition the list */
1861 ext_in_end = ext_in + hdr->iextMax;
1862 for (; ext_in < ext_in_end; ext_in++)
1863 fdr_to_pst[ext_in->ifd].n_globals++;
1865 /* Pass 1.5 over files: partition out global symbol space */
1867 for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++)
1869 fdr_to_pst[f_idx].globals_offset = s_idx;
1870 s_idx += fdr_to_pst[f_idx].n_globals;
1871 fdr_to_pst[f_idx].n_globals = 0;
1874 /* Pass 2 over external syms: fill in external symbols */
1876 ext_in_end = ext_in + hdr->iextMax;
1877 for (; ext_in < ext_in_end; ext_in++)
1879 enum minimal_symbol_type ms_type = mst_text;
1881 extern_tab[fdr_to_pst[ext_in->ifd].globals_offset
1882 + fdr_to_pst[ext_in->ifd].n_globals++] = *ext_in;
1884 if (ext_in->asym.sc == scUndefined || ext_in->asym.sc == scNil)
1887 name = ecoff_data (cur_bfd)->ssext + ext_in->asym.iss;
1888 switch (ext_in->asym.st)
1898 ms_type = mst_unknown;
1899 complain (&unknown_ext_complaint, name);
1901 prim_record_minimal_symbol (name, ext_in->asym.value, ms_type);
1904 /* Pass 3 over files, over local syms: fill in static symbols */
1905 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
1907 struct partial_symtab *save_pst;
1910 cur_fdr = fh = ecoff_data (cur_bfd)->fdr + f_idx;
1914 fdr_to_pst[f_idx].pst = NULL;
1917 pst = start_psymtab_common (objfile, section_offsets,
1919 fh->cpd ? fh->adr : 0,
1920 objfile->global_psymbols.next,
1921 objfile->static_psymbols.next);
1922 pst->read_symtab_private = ((char *)
1923 obstack_alloc (&objfile->psymbol_obstack,
1924 sizeof (struct symloc)));
1925 memset ((PTR) pst->read_symtab_private, 0, sizeof (struct symloc));
1928 /* Make everything point to everything. */
1929 FDR_IDX (pst) = f_idx;
1930 fdr_to_pst[f_idx].pst = pst;
1932 /* FIXME: This tampers with data from BFD. */
1933 fh->ioptBase = (int) pst;
1935 CUR_BFD (pst) = cur_bfd;
1937 /* The way to turn this into a symtab is to call... */
1938 pst->read_symtab = mipscoff_psymtab_to_symtab;
1940 pst->texthigh = pst->textlow;
1942 /* For stabs-in-ecoff files, the second symbol must be @stab.
1943 This symbol is emitted by mips-tfile to signal that the
1944 current object file uses encapsulated stabs instead of mips
1945 ecoff for local symbols. (It is the second symbol because
1946 the first symbol is the stFile used to signal the start of a
1948 processing_gcc_compilation = 0;
1951 ecoff_swap_sym_in (cur_bfd,
1952 (ecoff_data (cur_bfd)->external_sym
1956 if (STREQ (ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss,
1958 processing_gcc_compilation = 2;
1961 if (processing_gcc_compilation != 0)
1963 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
1968 ecoff_swap_sym_in (cur_bfd,
1969 (ecoff_data (cur_bfd)->external_sym
1973 type_code = MIPS_UNMARK_STAB (sh.index);
1974 if (!MIPS_IS_STAB (&sh))
1976 if (sh.st == stProc || sh.st == stStaticProc)
1978 long procaddr = sh.value;
1982 isym = AUX_GET_ISYM (fh->fBigendian,
1983 (ecoff_data (cur_bfd)->external_aux
1986 ecoff_swap_sym_in (cur_bfd,
1987 (ecoff_data (cur_bfd)->external_sym
1994 long high = procaddr + sh.value;
1995 if (high > pst->texthigh)
1996 pst->texthigh = high;
2001 #define SET_NAMESTRING() \
2002 namestring = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss
2003 #define CUR_SYMBOL_TYPE type_code
2004 #define CUR_SYMBOL_VALUE sh.value
2005 #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms)\
2007 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
2008 #define HANDLE_RBRAC(val) \
2009 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
2010 #include "partial-stab.h"
2015 for (cur_sdx = 0; cur_sdx < fh->csym;)
2018 enum address_class class;
2020 ecoff_swap_sym_in (cur_bfd,
2021 (ecoff_data (cur_bfd)->external_sym
2026 if (MIPS_IS_STAB (&sh))
2032 if (sh.sc == scUndefined || sh.sc == scNil ||
2033 sh.index == 0xfffff)
2035 /* FIXME, premature? */
2040 name = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss;
2048 case stProc: /* Asm labels apparently */
2049 case stStaticProc: /* Function */
2050 ADD_PSYMBOL_TO_LIST (name, strlen (name),
2051 VAR_NAMESPACE, LOC_BLOCK,
2052 objfile->static_psymbols, sh.value,
2053 psymtab_language, objfile);
2054 /* Skip over procedure to next one. */
2055 if (sh.index >= hdr->iauxMax)
2057 /* Should not happen, but does when cross-compiling
2058 with the MIPS compiler. FIXME -- pull later. */
2059 complain (&index_complaint, name);
2060 new_sdx = cur_sdx + 1; /* Don't skip at all */
2063 new_sdx = AUX_GET_ISYM (fh->fBigendian,
2064 (ecoff_data (cur_bfd)->external_aux
2067 procaddr = sh.value;
2069 if (new_sdx <= cur_sdx)
2071 /* This should not happen either... FIXME. */
2072 complain (&aux_index_complaint, name);
2073 new_sdx = cur_sdx + 1; /* Don't skip backward */
2077 ecoff_swap_sym_in (cur_bfd,
2078 (ecoff_data (cur_bfd)->external_sym
2085 high = procaddr + sh.value;
2086 if (high > pst->texthigh)
2087 pst->texthigh = high;
2090 case stStatic: /* Variable */
2094 case stTypedef:/* Typedef */
2095 class = LOC_TYPEDEF;
2098 case stConstant: /* Constant decl */
2105 case stBlock: /* { }, str, un, enum*/
2106 if (sh.sc == scInfo)
2108 ADD_PSYMBOL_TO_LIST (name, strlen (name),
2109 STRUCT_NAMESPACE, LOC_TYPEDEF,
2110 objfile->static_psymbols,
2112 psymtab_language, objfile);
2114 /* Skip over the block */
2116 if (new_sdx <= cur_sdx)
2118 /* This happens with the Ultrix kernel. */
2119 complain (&block_index_complaint, name);
2120 new_sdx = cur_sdx + 1; /* Don't skip backward */
2125 case stFile: /* File headers */
2126 case stLabel: /* Labels */
2127 case stEnd: /* Ends of files */
2130 case stLocal: /* Local variables */
2131 /* Normally these are skipped because we skip over
2132 all blocks we see. However, these can occur
2133 as visible symbols in a .h file that contains code. */
2137 /* Both complaints are valid: one gives symbol name,
2138 the other the offending symbol type. */
2139 complain (&unknown_sym_complaint, name);
2140 complain (&unknown_st_complaint, sh.st);
2144 /* Use this gdb symbol */
2145 ADD_PSYMBOL_TO_LIST (name, strlen (name),
2146 VAR_NAMESPACE, class,
2147 objfile->static_psymbols, sh.value,
2148 psymtab_language, objfile);
2150 cur_sdx++; /* Go to next file symbol */
2153 /* Now do enter the external symbols. */
2154 ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset];
2155 cur_sdx = fdr_to_pst[f_idx].n_globals;
2156 PST_PRIVATE (save_pst)->extern_count = cur_sdx;
2157 PST_PRIVATE (save_pst)->extern_tab = ext_ptr;
2158 for (; --cur_sdx >= 0; ext_ptr++)
2160 register struct partial_symbol *psym;
2161 enum address_class class;
2165 if (ext_ptr->ifd != f_idx)
2167 psh = &ext_ptr->asym;
2177 complain (&unknown_ext_complaint,
2178 ecoff_data (cur_bfd)->ssext + psh->iss);
2179 /* Fall through, pretend it's global. */
2184 name = ecoff_data (cur_bfd)->ssext + psh->iss;
2185 ADD_PSYMBOL_ADDR_TO_LIST (name, strlen (name),
2186 VAR_NAMESPACE, class,
2187 objfile->global_psymbols, (CORE_ADDR) psh->value,
2188 psymtab_language, objfile);
2192 end_psymtab (save_pst, psymtab_include_list, includes_used,
2193 -1, save_pst->texthigh,
2194 dependency_list, dependencies_used);
2195 if (objfile->ei.entry_point >= save_pst->textlow &&
2196 objfile->ei.entry_point < save_pst->texthigh)
2198 objfile->ei.entry_file_lowpc = save_pst->textlow;
2199 objfile->ei.entry_file_highpc = save_pst->texthigh;
2203 /* Now scan the FDRs for dependencies */
2204 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
2207 fh = f_idx + ecoff_data (cur_bfd)->fdr;
2208 pst = fdr_to_pst[f_idx].pst;
2210 /* This should catch stabs-in-ecoff. */
2215 { /* If there are no functions defined here ... */
2216 /* ...then presumably a .h file: drop reverse depends .h->.c */
2217 for (; s_id0 < fh->crfd; s_id0++)
2221 ecoff_swap_rfd_in (cur_bfd,
2222 (ecoff_data (cur_bfd)->external_rfd
2228 s_id0++; /* Skip self-dependency */
2233 pst->number_of_dependencies = fh->crfd - s_id0;
2235 ((struct partial_symtab **)
2236 obstack_alloc (&objfile->psymbol_obstack,
2237 (pst->number_of_dependencies
2238 * sizeof (struct partial_symtab *))));
2239 for (s_idx = s_id0; s_idx < fh->crfd; s_idx++)
2243 ecoff_swap_rfd_in (cur_bfd,
2244 (ecoff_data (cur_bfd)->external_rfd
2248 if (rh < 0 || rh >= hdr->ifdMax)
2249 complain (&bad_file_number_complaint, rh);
2251 pst->dependencies[s_idx - s_id0] = fdr_to_pst[rh].pst;
2254 do_cleanups (old_chain);
2259 /* Do the initial analisys of the F_IDX-th file descriptor.
2260 Allocates a partial symtab for it, and builds the list
2261 of dependent files by recursion. LEV says at which level
2262 of recursion we are called (to pretty up debug traces) */
2264 static struct partial_symtab *
2265 parse_fdr (f_idx, lev, objfile)
2268 struct objfile *objfile;
2271 register struct partial_symtab *pst;
2274 fh = ecoff_data (cur_bfd)->fdr + f_idx;
2276 /* Use this to indicate into which symtab this file was parsed */
2278 return (struct partial_symtab *) fh->ioptBase;
2280 /* Debuggability level */
2281 if (compare_glevel (max_glevel, fh->glevel) < 0)
2282 max_glevel = fh->glevel;
2284 /* Make a new partial_symtab */
2285 pst = new_psymtab (fdr_name (fh), objfile);
2293 pst->textlow = fh->adr;
2294 pst->texthigh = fh->cpd; /* To be fixed later */
2297 /* Make everything point to everything. */
2298 FDR_IDX (pst) = f_idx;
2299 fdr_to_pst[f_idx].pst = pst;
2300 fh->ioptBase = (int) pst;
2302 /* Analyze its dependencies */
2308 { /* If there are no functions defined here ... */
2309 /* ...then presumably a .h file: drop reverse depends .h->.c */
2310 for (; s_id0 < fh->crfd; s_id0++)
2314 ecoff_swap_rfd_in (cur_bfd,
2315 (ecoff_data (cur_bfd)->external_rfd
2321 s_id0++; /* Skip self-dependency */
2326 pst->number_of_dependencies = fh->crfd - s_id0;
2327 pst->dependencies = ((struct partial_symtab **)
2328 obstack_alloc (&objfile->psymbol_obstack,
2329 (pst->number_of_dependencies
2330 * sizeof (struct partial_symtab *))));
2331 for (s_idx = s_id0; s_idx < fh->crfd; s_idx++)
2335 ecoff_swap_rfd_in (cur_bfd,
2336 (ecoff_data (cur_bfd)->external_rfd
2340 pst->dependencies[s_idx - s_id0] = parse_fdr (rh, lev + 1, objfile);
2349 mips_next_symbol_text ()
2354 ecoff_swap_sym_in (cur_bfd,
2355 (ecoff_data (cur_bfd)->external_sym
2359 return ecoff_data (cur_bfd)->ss + cur_fdr->issBase + sh.iss;
2362 /* Ancillary function to psymtab_to_symtab(). Does all the work
2363 for turning the partial symtab PST into a symtab, recurring
2364 first on all dependent psymtabs. The argument FILENAME is
2365 only passed so we can see in debug stack traces what file
2368 This function has a split personality, based on whether the
2369 symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
2370 The flow of control and even the memory allocation differs. FIXME. */
2373 psymtab_to_symtab_1 (pst, filename)
2374 struct partial_symtab *pst;
2380 struct linetable *lines;
2386 /* Read in all partial symbtabs on which this one is dependent.
2387 NOTE that we do have circular dependencies, sigh. We solved
2388 that by setting pst->readin before this point. */
2390 for (i = 0; i < pst->number_of_dependencies; i++)
2391 if (!pst->dependencies[i]->readin)
2393 /* Inform about additional files to be read in. */
2396 fputs_filtered (" ", stdout);
2398 fputs_filtered ("and ", stdout);
2400 printf_filtered ("%s...",
2401 pst->dependencies[i]->filename);
2402 wrap_here (""); /* Flush output */
2405 /* We only pass the filename for debug purposes */
2406 psymtab_to_symtab_1 (pst->dependencies[i],
2407 pst->dependencies[i]->filename);
2410 /* Do nothing if this is a dummy psymtab. */
2412 if (pst->n_global_syms == 0 && pst->n_static_syms == 0
2413 && pst->textlow == 0 && pst->texthigh == 0)
2416 /* Now read the symbols for this symtab */
2418 cur_bfd = CUR_BFD (pst);
2419 current_objfile = pst->objfile;
2420 cur_fd = FDR_IDX (pst);
2421 fh = (cur_fd == -1) ? (FDR *) NULL : ecoff_data (cur_bfd)->fdr + cur_fd;
2424 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2425 processing_gcc_compilation = 0;
2426 if (fh != (FDR *) NULL && fh->csym >= 2)
2430 ecoff_swap_sym_in (cur_bfd,
2431 (ecoff_data (cur_bfd)->external_sym
2435 if (STREQ (ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss,
2438 /* We indicate that this is a GCC compilation so that certain
2439 features will be enabled in stabsread/dbxread. */
2440 processing_gcc_compilation = 2;
2444 if (processing_gcc_compilation != 0)
2446 struct pdr_ext *pdr_ptr;
2447 struct pdr_ext *pdr_end;
2449 unsigned long first_off;
2451 /* This symbol table contains stabs-in-ecoff entries. */
2453 /* Parse local symbols first */
2455 if (fh->csym <= 2) /* FIXME, this blows psymtab->symtab ptr */
2457 current_objfile = NULL;
2460 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
2466 ecoff_swap_sym_in (cur_bfd,
2467 (ecoff_data (cur_bfd)->external_sym
2471 name = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss;
2473 if (MIPS_IS_STAB (&sh))
2475 int type_code = MIPS_UNMARK_STAB (sh.index);
2476 process_one_symbol (type_code, 0, valu, name,
2477 pst->section_offsets, pst->objfile);
2478 if (type_code == N_FUN)
2480 /* Make up special symbol to contain
2481 procedure specific info */
2482 struct mips_extra_func_info *e =
2483 ((struct mips_extra_func_info *)
2484 obstack_alloc (¤t_objfile->symbol_obstack,
2485 sizeof (struct mips_extra_func_info)));
2486 struct symbol *s = new_symbol (MIPS_EFI_SYMBOL_NAME);
2487 SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
2488 SYMBOL_CLASS (s) = LOC_CONST;
2489 SYMBOL_TYPE (s) = builtin_type_void;
2490 SYMBOL_VALUE (s) = (int) e;
2491 add_symbol_to_list (s, &local_symbols);
2494 else if (sh.st == stLabel && sh.index != indexNil)
2496 /* Handle encoded stab line number. */
2497 record_line (current_subfile, sh.index, valu);
2499 else if (sh.st == stProc || sh.st == stStaticProc || sh.st == stEnd)
2500 /* These are generated by gcc-2.x, do not complain */
2503 complain (&stab_unknown_complaint, name);
2505 st = end_symtab (pst->texthigh, 0, 0, pst->objfile, SECT_OFF_TEXT);
2508 /* Sort the symbol table now, we are done adding symbols to it.
2509 We must do this before parse_procedure calls lookup_symbol. */
2510 sort_symtab_syms (st);
2512 /* This may not be necessary for stabs symtabs. FIXME. */
2515 /* Fill in procedure info next. */
2517 pdr_ptr = ecoff_data (cur_bfd)->external_pdr + fh->ipdFirst;
2518 pdr_end = pdr_ptr + fh->cpd;
2519 for (; pdr_ptr < pdr_end; pdr_ptr++)
2523 ecoff_swap_pdr_in (cur_bfd, pdr_ptr, &pr);
2529 parse_procedure (&pr, 1, first_off);
2534 /* This symbol table contains ordinary ecoff entries. */
2536 /* FIXME: doesn't use pst->section_offsets. */
2542 /* How many symbols will we need */
2543 /* FIXME, this does not count enum values. */
2544 f_max = pst->n_global_syms + pst->n_static_syms;
2548 st = new_symtab ("unknown", f_max, 0, pst->objfile);
2552 f_max += fh->csym + fh->cpd;
2553 maxlines = 2 * fh->cline;
2554 st = new_symtab (pst->filename, 2 * f_max, maxlines, pst->objfile);
2557 lines = LINETABLE (st);
2558 pending_list = PST_PRIVATE (pst)->pending_list;
2559 if (pending_list == 0)
2561 pending_list = ((struct mips_pending **)
2562 xzalloc (ecoff_data (cur_bfd)->symbolic_header.ifdMax
2563 * sizeof (struct mips_pending *)));
2564 PST_PRIVATE (pst)->pending_list = pending_list;
2567 /* Get a new lexical context */
2569 push_parse_stack ();
2570 top_stack->cur_st = st;
2571 top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (st),
2573 BLOCK_START (top_stack->cur_block) = fh ? fh->adr : 0;
2574 BLOCK_END (top_stack->cur_block) = 0;
2575 top_stack->blocktype = stFile;
2576 top_stack->maxsyms = 2 * f_max;
2577 top_stack->cur_type = 0;
2578 top_stack->procadr = 0;
2579 top_stack->numargs = 0;
2583 struct sym_ext *sym_ptr;
2584 struct sym_ext *sym_end;
2586 /* Parse local symbols first */
2587 sym_ptr = ecoff_data (cur_bfd)->external_sym + fh->isymBase;
2588 sym_end = sym_ptr + fh->csym;
2589 while (sym_ptr < sym_end)
2594 ecoff_swap_sym_in (cur_bfd, sym_ptr, &sh);
2595 c = parse_symbol (&sh,
2596 (ecoff_data (cur_bfd)->external_aux
2598 sym_ptr, fh->fBigendian);
2599 /* FIXME: We must swap the modified symbol back out,
2600 although we would rather not. See parse_symbol. */
2601 ecoff_swap_sym_out (cur_bfd, &sh, sym_ptr);
2605 /* Linenumbers. At the end, check if we can save memory.
2606 parse_lines has to look ahead an arbitrary number of PDR
2607 structures, so we swap them all first. */
2611 struct cleanup *old_chain;
2612 struct pdr_ext *pdr_ptr;
2613 struct pdr_ext *pdr_end;
2617 pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR));
2619 old_chain = make_cleanup (free, pr_block);
2621 pdr_ptr = ecoff_data (cur_bfd)->external_pdr + fh->ipdFirst;
2622 pdr_end = pdr_ptr + fh->cpd;
2624 for (; pdr_ptr < pdr_end; pdr_ptr++, pdr_in++)
2625 ecoff_swap_pdr_in (cur_bfd, pdr_ptr, pdr_in);
2627 parse_lines (fh, pr_block, lines);
2628 if (lines->nitems < fh->cline)
2629 lines = shrink_linetable (lines);
2631 /* Fill in procedure info next. */
2633 pdr_in_end = pdr_in + fh->cpd;
2634 for (; pdr_in < pdr_in_end; pdr_in++)
2635 parse_procedure (pdr_in, 0, pr_block->adr);
2637 do_cleanups (old_chain);
2641 LINETABLE (st) = lines;
2643 /* .. and our share of externals.
2644 XXX use the global list to speed up things here. how?
2645 FIXME, Maybe quit once we have found the right number of ext's? */
2646 top_stack->cur_st = st;
2647 top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
2649 top_stack->blocktype = stFile;
2650 top_stack->maxsyms = (ecoff_data (cur_bfd)->symbolic_header.isymMax
2651 + ecoff_data (cur_bfd)->symbolic_header.ipdMax
2652 + ecoff_data (cur_bfd)->symbolic_header.iextMax);
2654 ext_ptr = PST_PRIVATE (pst)->extern_tab;
2655 for (i = PST_PRIVATE (pst)->extern_count; --i >= 0; ext_ptr++)
2656 parse_external (ext_ptr, 1, fh->fBigendian);
2658 /* If there are undefined, tell the user */
2659 if (n_undef_symbols)
2661 printf_filtered ("File %s contains %d unresolved references:",
2662 st->filename, n_undef_symbols);
2663 printf_filtered ("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2664 n_undef_vars, n_undef_procs, n_undef_labels);
2665 n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
2670 /* Sort the symbol table now, we are done adding symbols to it.*/
2671 sort_symtab_syms (st);
2676 /* Now link the psymtab and the symtab. */
2679 current_objfile = NULL;
2682 /* Ancillary parsing procedures. */
2684 /* Lookup the type at relative index RN. Return it in TPP
2685 if found and in any event come up with its name PNAME.
2686 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
2687 Return value says how many aux symbols we ate. */
2690 cross_ref (ax, tpp, type_code, pname, bigend)
2693 enum type_code type_code; /* Use to alloc new type if none is found. */
2701 ecoff_swap_rndx_in (bigend, &ax->a_rndx, rn);
2703 /* Escape index means 'the next one' */
2704 if (rn->rfd == 0xfff)
2707 rf = AUX_GET_ISYM (bigend, ax + 1);
2717 *pname = "<undefined>";
2722 * Find the relative file descriptor and the symbol in it
2724 FDR *fh = get_rfd (cur_fd, rf);
2725 struct sym_ext *esh;
2729 /* If we have processed this symbol then we left a forwarding
2730 pointer to the corresponding GDB symbol. If not, we`ll put
2731 it in a list of pending symbols, to be processed later when
2732 the file will be. In any event, we collect the name for the
2733 type here. Which is why we made a first pass at strings. */
2735 esh = ecoff_data (cur_bfd)->external_sym + fh->isymBase + rn->index;
2736 ecoff_swap_sym_in (cur_bfd, esh, &sh);
2738 /* Careful, we might be looking at .o files */
2740 *pname = "<undefined>";
2742 *pname = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss;
2744 /* Have we parsed it ? */
2745 if (sh.value != 0 && sh.st == stParsed)
2747 t = (struct type *) sh.value;
2752 /* Avoid duplicates */
2753 struct mips_pending *p = is_pending_symbol (fh, esh);
2758 *tpp = init_type (type_code, 0, 0, (char *) NULL,
2759 (struct objfile *) NULL);
2760 add_pending (fh, esh, *tpp);
2765 /* We used one auxent normally, two if we got a "next one" rf. */
2770 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2771 keeping the symtab sorted */
2773 static struct symbol *
2774 mylookup_symbol (name, block, namespace, class)
2776 register struct block *block;
2777 enum namespace namespace;
2778 enum address_class class;
2780 register int bot, top, inc;
2781 register struct symbol *sym;
2784 top = BLOCK_NSYMS (block);
2788 sym = BLOCK_SYM (block, bot);
2789 if (SYMBOL_NAME (sym)[0] == inc
2790 && SYMBOL_NAMESPACE (sym) == namespace
2791 && SYMBOL_CLASS (sym) == class
2792 && STREQ (SYMBOL_NAME (sym), name))
2796 block = BLOCK_SUPERBLOCK (block);
2798 return mylookup_symbol (name, block, namespace, class);
2803 /* Add a new symbol S to a block B.
2804 Infrequently, we will need to reallocate the block to make it bigger.
2805 We only detect this case when adding to top_stack->cur_block, since
2806 that's the only time we know how big the block is. FIXME. */
2813 int nsyms = BLOCK_NSYMS (b)++;
2814 struct block *origb;
2815 struct parse_stack *stackp;
2817 if (b == top_stack->cur_block &&
2818 nsyms >= top_stack->maxsyms)
2820 complain (&block_overflow_complaint, SYMBOL_NAME (s));
2821 /* In this case shrink_block is actually grow_block, since
2822 BLOCK_NSYMS(b) is larger than its current size. */
2824 b = shrink_block (top_stack->cur_block, top_stack->cur_st);
2826 /* Now run through the stack replacing pointers to the
2827 original block. shrink_block has already done this
2828 for the blockvector and BLOCK_FUNCTION. */
2829 for (stackp = top_stack; stackp; stackp = stackp->next)
2831 if (stackp->cur_block == origb)
2833 stackp->cur_block = b;
2834 stackp->maxsyms = BLOCK_NSYMS (b);
2838 BLOCK_SYM (b, nsyms) = s;
2841 /* Add a new block B to a symtab S */
2848 struct blockvector *bv = BLOCKVECTOR (s);
2850 bv = (struct blockvector *) xrealloc ((PTR) bv,
2851 (sizeof (struct blockvector)
2852 + BLOCKVECTOR_NBLOCKS (bv)
2853 * sizeof (bv->block)));
2854 if (bv != BLOCKVECTOR (s))
2855 BLOCKVECTOR (s) = bv;
2857 BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)++) = b;
2860 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2861 MIPS' linenumber encoding might need more than one byte
2862 to describe it, LAST is used to detect these continuation lines.
2864 Combining lines with the same line number seems like a bad idea.
2865 E.g: There could be a line number entry with the same line number after the
2866 prologue and GDB should not ignore it (this is a better way to find
2867 a prologue than mips_skip_prologue).
2868 But due to the compressed line table format there are line number entries
2869 for the same line which are needed to bridge the gap to the next
2870 line number entry. These entries have a bogus address info with them
2871 and we are unable to tell them from intended duplicate line number
2873 This is another reason why -ggdb debugging format is preferable. */
2876 add_line (lt, lineno, adr, last)
2877 struct linetable *lt;
2883 last = -2; /* make sure we record first line */
2885 if (last == lineno) /* skip continuation lines */
2888 lt->item[lt->nitems].line = lineno;
2889 lt->item[lt->nitems++].pc = adr << 2;
2893 /* Sorting and reordering procedures */
2895 /* Blocks with a smaller low bound should come first */
2898 compare_blocks (arg1, arg2)
2899 const void *arg1, *arg2;
2901 register int addr_diff;
2902 struct block **b1 = (struct block **) arg1;
2903 struct block **b2 = (struct block **) arg2;
2905 addr_diff = (BLOCK_START ((*b1))) - (BLOCK_START ((*b2)));
2907 return (BLOCK_END ((*b2))) - (BLOCK_END ((*b1)));
2911 /* Sort the blocks of a symtab S.
2912 Reorder the blocks in the blockvector by code-address,
2913 as required by some MI search routines */
2919 struct blockvector *bv = BLOCKVECTOR (s);
2921 if (BLOCKVECTOR_NBLOCKS (bv) <= 2)
2924 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) == 0)
2925 BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = 0;
2926 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) == 0)
2927 BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = 0;
2931 * This is very unfortunate: normally all functions are compiled in
2932 * the order they are found, but if the file is compiled -O3 things
2933 * are very different. It would be nice to find a reliable test
2934 * to detect -O3 images in advance.
2936 if (BLOCKVECTOR_NBLOCKS (bv) > 3)
2937 qsort (&BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK),
2938 BLOCKVECTOR_NBLOCKS (bv) - FIRST_LOCAL_BLOCK,
2939 sizeof (struct block *),
2943 register CORE_ADDR high = 0;
2944 register int i, j = BLOCKVECTOR_NBLOCKS (bv);
2946 for (i = FIRST_LOCAL_BLOCK; i < j; i++)
2947 if (high < BLOCK_END (BLOCKVECTOR_BLOCK (bv, i)))
2948 high = BLOCK_END (BLOCKVECTOR_BLOCK (bv, i));
2949 BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = high;
2952 BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) =
2953 BLOCK_START (BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK));
2955 BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
2956 BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
2957 BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
2958 BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
2962 /* Constructor/restructor/destructor procedures */
2964 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2965 MAXSYMS and linenumbers MAXLINES we'll put in it */
2967 static struct symtab *
2968 new_symtab (name, maxsyms, maxlines, objfile)
2972 struct objfile *objfile;
2974 struct symtab *s = allocate_symtab (name, objfile);
2976 LINETABLE (s) = new_linetable (maxlines);
2978 /* All symtabs must have at least two blocks */
2979 BLOCKVECTOR (s) = new_bvect (2);
2980 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK) = new_block (maxsyms);
2981 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK) = new_block (maxsyms);
2982 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)) =
2983 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
2985 s->free_code = free_linetable;
2990 /* Allocate a new partial_symtab NAME */
2992 static struct partial_symtab *
2993 new_psymtab (name, objfile)
2995 struct objfile *objfile;
2997 struct partial_symtab *psymtab;
2999 psymtab = allocate_psymtab (name, objfile);
3001 /* Keep a backpointer to the file's symbols */
3003 psymtab->read_symtab_private = ((char *)
3004 obstack_alloc (&objfile->psymbol_obstack,
3005 sizeof (struct symloc)));
3006 memset ((PTR) psymtab->read_symtab_private, 0, sizeof (struct symloc));
3007 CUR_BFD (psymtab) = cur_bfd;
3009 /* The way to turn this into a symtab is to call... */
3010 psymtab->read_symtab = mipscoff_psymtab_to_symtab;
3015 /* Allocate a linetable array of the given SIZE. Since the struct
3016 already includes one item, we subtract one when calculating the
3017 proper size to allocate. */
3019 static struct linetable *
3020 new_linetable (size)
3023 struct linetable *l;
3025 size = (size - 1) * sizeof (l->item) + sizeof (struct linetable);
3026 l = (struct linetable *) xmalloc (size);
3031 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
3032 I am not so sure about the 3.4 ones.
3034 Since the struct linetable already includes one item, we subtract one when
3035 calculating the proper size to allocate. */
3037 static struct linetable *
3038 shrink_linetable (lt)
3039 struct linetable *lt;
3042 return (struct linetable *) xrealloc ((PTR) lt,
3043 (sizeof (struct linetable)
3045 * sizeof (lt->item))));
3048 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
3050 static struct blockvector *
3054 struct blockvector *bv;
3057 size = sizeof (struct blockvector) + nblocks * sizeof (struct block *);
3058 bv = (struct blockvector *) xzalloc (size);
3060 BLOCKVECTOR_NBLOCKS (bv) = nblocks;
3065 /* Allocate and zero a new block of MAXSYMS symbols */
3067 static struct block *
3071 int size = sizeof (struct block) + (maxsyms - 1) * sizeof (struct symbol *);
3073 return (struct block *) xzalloc (size);
3076 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
3077 Shrink_block can also be used by add_symbol to grow a block. */
3079 static struct block *
3085 struct blockvector *bv = BLOCKVECTOR (s);
3088 /* Just reallocate it and fix references to the old one */
3090 new = (struct block *) xrealloc ((PTR) b,
3091 (sizeof (struct block)
3092 + ((BLOCK_NSYMS (b) - 1)
3093 * sizeof (struct symbol *))));
3095 /* Should chase pointers to old one. Fortunately, that`s just
3096 the block`s function and inferior blocks */
3097 if (BLOCK_FUNCTION (new) && SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) == b)
3098 SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) = new;
3099 for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
3100 if (BLOCKVECTOR_BLOCK (bv, i) == b)
3101 BLOCKVECTOR_BLOCK (bv, i) = new;
3102 else if (BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) == b)
3103 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) = new;
3107 /* Create a new symbol with printname NAME */
3109 static struct symbol *
3113 struct symbol *s = ((struct symbol *)
3114 obstack_alloc (¤t_objfile->symbol_obstack,
3115 sizeof (struct symbol)));
3117 memset ((PTR) s, 0, sizeof (*s));
3118 SYMBOL_NAME (s) = name;
3122 /* Create a new type with printname NAME */
3124 static struct type *
3130 t = alloc_type (current_objfile);
3131 TYPE_NAME (t) = name;
3132 TYPE_CPLUS_SPECIFIC (t) = (struct cplus_struct_type *) &cplus_struct_default;
3137 /* Things used for calling functions in the inferior.
3138 These functions are exported to our companion
3139 mips-tdep.c file and are here because they play
3140 with the symbol-table explicitly. */
3142 /* Sigtramp: make sure we have all the necessary information
3143 about the signal trampoline code. Since the official code
3144 from MIPS does not do so, we make up that information ourselves.
3145 If they fix the library (unlikely) this code will neutralize itself. */
3152 struct block *b, *b0;
3154 sigtramp_address = -1;
3156 /* We have to handle the following cases here:
3157 a) The Mips library has a sigtramp label within sigvec.
3158 b) Irix has a _sigtramp which we want to use, but it also has sigvec. */
3159 s = lookup_symbol ("sigvec", 0, VAR_NAMESPACE, 0, NULL);
3162 b0 = SYMBOL_BLOCK_VALUE (s);
3163 s = lookup_symbol ("sigtramp", b0, VAR_NAMESPACE, 0, NULL);
3167 /* No sigvec or no sigtramp inside sigvec, try _sigtramp. */
3168 s = lookup_symbol ("_sigtramp", 0, VAR_NAMESPACE, 0, NULL);
3171 /* But maybe this program uses its own version of sigvec */
3175 /* Did we or MIPSco fix the library ? */
3176 if (SYMBOL_CLASS (s) == LOC_BLOCK)
3178 sigtramp_address = BLOCK_START (SYMBOL_BLOCK_VALUE (s));
3179 sigtramp_end = BLOCK_END (SYMBOL_BLOCK_VALUE (s));
3183 sigtramp_address = SYMBOL_VALUE (s);
3184 sigtramp_end = sigtramp_address + 0x88; /* black magic */
3186 /* But what symtab does it live in ? */
3187 st = find_pc_symtab (SYMBOL_VALUE (s));
3190 * Ok, there goes the fix: turn it into a procedure, with all the
3191 * needed info. Note we make it a nested procedure of sigvec,
3192 * which is the way the (assembly) code is actually written.
3194 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
3195 SYMBOL_CLASS (s) = LOC_BLOCK;
3196 SYMBOL_TYPE (s) = init_type (TYPE_CODE_FUNC, 4, 0, (char *) NULL,
3197 (struct objfile *) NULL);
3198 TYPE_TARGET_TYPE (SYMBOL_TYPE (s)) = builtin_type_void;
3200 /* Need a block to allocate MIPS_EFI_SYMBOL_NAME in */
3202 SYMBOL_BLOCK_VALUE (s) = b;
3203 BLOCK_START (b) = sigtramp_address;
3204 BLOCK_END (b) = sigtramp_end;
3205 BLOCK_FUNCTION (b) = s;
3206 BLOCK_SUPERBLOCK (b) = BLOCK_SUPERBLOCK (b0);
3210 /* Make a MIPS_EFI_SYMBOL_NAME entry for it */
3212 struct mips_extra_func_info *e =
3213 ((struct mips_extra_func_info *)
3214 xzalloc (sizeof (struct mips_extra_func_info)));
3216 e->numargs = 0; /* the kernel thinks otherwise */
3217 /* align_longword(sigcontext + SIGFRAME) */
3218 e->pdr.frameoffset = 0x150;
3219 e->pdr.framereg = SP_REGNUM;
3220 /* read_next_frame_reg provides the true pc at the time of signal */
3221 e->pdr.pcreg = PC_REGNUM;
3222 e->pdr.regmask = -2;
3223 e->pdr.regoffset = -(41 * sizeof (int));
3224 e->pdr.fregmask = -1;
3225 e->pdr.fregoffset = -(7 * sizeof (int));
3226 e->pdr.isym = (long) s;
3228 current_objfile = st->objfile; /* Keep new_symbol happy */
3229 s = new_symbol (MIPS_EFI_SYMBOL_NAME);
3230 SYMBOL_VALUE (s) = (int) e;
3231 SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
3232 SYMBOL_CLASS (s) = LOC_CONST;
3233 SYMBOL_TYPE (s) = builtin_type_void;
3234 current_objfile = NULL;
3237 BLOCK_SYM (b, BLOCK_NSYMS (b)++) = s;
3241 /* Fake up identical offsets for all sections. */
3243 struct section_offsets *
3244 mipscoff_symfile_offsets (objfile, addr)
3245 struct objfile *objfile;
3248 struct section_offsets *section_offsets;
3251 section_offsets = ((struct section_offsets *)
3252 obstack_alloc (&objfile->psymbol_obstack,
3253 (sizeof (struct section_offsets)
3254 + (sizeof (section_offsets->offsets)
3255 * (SECT_OFF_MAX - 1)))));
3257 for (i = 0; i < SECT_OFF_MAX; i++)
3258 ANOFFSET (section_offsets, i) = addr;
3260 return section_offsets;
3263 /* Initialization */
3265 static struct sym_fns ecoff_sym_fns =
3267 "ecoff", /* sym_name: name or name prefix of BFD target type */
3268 5, /* sym_namelen: number of significant sym_name chars */
3269 mipscoff_new_init, /* sym_new_init: init anything gbl to entire symtab */
3270 mipscoff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
3271 mipscoff_symfile_read, /* sym_read: read a symbol file into symtab */
3272 mipscoff_symfile_finish, /* sym_finish: finished with file, cleanup */
3273 mipscoff_symfile_offsets, /* sym_offsets: dummy FIXME til implem sym reloc */
3274 NULL /* next: pointer to next struct sym_fns */
3279 _initialize_mipsread ()
3281 add_symtab_fns (&ecoff_sym_fns);
3283 /* Missing basic types */
3285 builtin_type_string =
3286 init_type (TYPE_CODE_STRING,
3287 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3289 (struct objfile *) NULL);
3290 builtin_type_complex =
3291 init_type (TYPE_CODE_FLT,
3292 TARGET_COMPLEX_BIT / TARGET_CHAR_BIT,
3294 (struct objfile *) NULL);
3295 builtin_type_double_complex =
3296 init_type (TYPE_CODE_FLT,
3297 TARGET_DOUBLE_COMPLEX_BIT / TARGET_CHAR_BIT,
3298 0, "double complex",
3299 (struct objfile *) NULL);
3300 builtin_type_fixed_dec =
3301 init_type (TYPE_CODE_INT,
3302 TARGET_INT_BIT / TARGET_CHAR_BIT,
3304 (struct objfile *) NULL);
3305 builtin_type_float_dec =
3306 init_type (TYPE_CODE_FLT,
3307 TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3308 0, "floating decimal",
3309 (struct objfile *) NULL);