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. */
48 #define TM_FILE_OVERRIDE
50 #include "mips/tm-mips.h"
58 #include "stabsread.h"
59 #include "complaints.h"
62 #include <sys/types.h>
67 #include <sys/param.h>
72 #include "gdb-stabs.h"
76 #include "coff/internal.h"
77 #include "coff/mips.h" /* COFF-like aspects of ecoff files */
78 #include "coff/ecoff-ext.h" /* External forms of ecoff sym structures */
80 /* FIXME: coff/internal.h and aout/aout64.h both define N_ABS. We
81 want the definition from aout/aout64.h. */
83 /* FIXME: coff/mips.h and aout/aout64.h both define ZMAGIC. We don't
87 #include "libaout.h" /* Private BFD a.out information. */
88 #include "aout/aout64.h"
89 #include "aout/stab_gnu.h" /* STABS information */
91 /* FIXME: libcoff.h and libaout.h both define a couple of macros. We
94 #undef obj_sym_filepos
96 #include "libcoff.h" /* Private BFD COFF information. */
97 #include "libecoff.h" /* Private BFD ECOFF information. */
99 #include "expression.h"
100 #include "language.h" /* Needed inside partial-stab.h */
102 /* Each partial symbol table entry contains a pointer to private data
103 for the read_symtab() function to use when expanding a partial
104 symbol table entry to a full symbol table entry.
106 For mipsread this structure contains the index of the FDR that this
107 psymtab represents and a pointer to the BFD that the psymtab was
110 #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
111 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
112 #define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd)
118 EXTR *extern_tab; /* Pointer to external symbols for this file. */
119 int extern_count; /* Size of extern_tab. */
120 struct mips_pending **pending_list;
123 /* Things we import explicitly from other modules */
125 extern int info_verbose;
127 /* Various complaints about symbol reading that don't abort the process */
129 struct complaint bad_file_number_complaint =
130 {"bad file number %d", 0, 0};
132 struct complaint index_complaint =
133 {"bad aux index at symbol %s", 0, 0};
135 struct complaint aux_index_complaint =
136 {"bad proc end in aux found from symbol %s", 0, 0};
138 struct complaint block_index_complaint =
139 {"bad aux index at block symbol %s", 0, 0};
141 struct complaint unknown_ext_complaint =
142 {"unknown external symbol %s", 0, 0};
144 struct complaint unknown_sym_complaint =
145 {"unknown local symbol %s", 0, 0};
147 struct complaint unknown_st_complaint =
148 {"with type %d", 0, 0};
150 struct complaint block_overflow_complaint =
151 {"block containing %s overfilled", 0, 0};
153 struct complaint basic_type_complaint =
154 {"cannot map MIPS basic type 0x%x", 0, 0};
156 struct complaint unknown_type_qual_complaint =
157 {"unknown type qualifier 0x%x", 0, 0};
159 struct complaint array_bitsize_complaint =
160 {"size of array target type not known, assuming %d bits", 0, 0};
162 struct complaint bad_tag_guess_complaint =
163 {"guessed tag type of %s incorrectly", 0, 0};
165 struct complaint block_member_complaint =
166 {"declaration block contains unhandled symbol type %d", 0, 0};
168 struct complaint stEnd_complaint =
169 {"stEnd with storage class %d not handled", 0, 0};
171 struct complaint unknown_mips_symtype_complaint =
172 {"unknown symbol type 0x%x", 0, 0};
174 struct complaint stab_unknown_complaint =
175 {"unknown stabs symbol %s", 0, 0};
177 struct complaint pdr_for_nonsymbol_complaint =
178 {"PDR for %s, but no symbol", 0, 0};
180 struct complaint pdr_static_symbol_complaint =
181 {"can't handle PDR for static proc at 0x%x", 0, 0};
183 /* Macros and extra defs */
185 /* Already-parsed symbols are marked specially */
187 #define stParsed stType
189 /* Puns: hard to find whether -g was used and how */
191 #define MIN_GLEVEL GLEVEL_0
192 #define compare_glevel(a,b) \
193 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
194 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
196 /* Things that really are local to this module */
198 /* Remember what we deduced to be the source language of this psymtab. */
200 static enum language psymtab_language = language_unknown;
206 /* Pointer to current file decriptor record, and its index */
211 /* Index of current symbol */
215 /* Note how much "debuggable" this image is. We would like
216 to see at least one FDR with full symbols */
221 /* When examining .o files, report on undefined symbols */
223 static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;
225 /* Pseudo symbol to use when putting stabs into the symbol table. */
227 static char stabs_symbol[] = STABS_SYMBOL;
229 /* Extra builtin types */
231 struct type *builtin_type_complex;
232 struct type *builtin_type_double_complex;
233 struct type *builtin_type_fixed_dec;
234 struct type *builtin_type_float_dec;
235 struct type *builtin_type_string;
237 /* Forward declarations */
240 read_mips_symtab PARAMS ((struct objfile *, struct section_offsets *));
243 read_the_mips_symtab PARAMS ((bfd *));
246 upgrade_type PARAMS ((struct type **, int, union aux_ext *, int));
249 parse_partial_symbols PARAMS ((struct objfile *,
250 struct section_offsets *));
253 cross_ref PARAMS ((union aux_ext *, struct type **, enum type_code, char **,
257 fixup_sigtramp PARAMS ((void));
259 static struct symbol *
260 new_symbol PARAMS ((char *));
263 new_type PARAMS ((char *));
265 static struct block *
266 new_block PARAMS ((int));
268 static struct symtab *
269 new_symtab PARAMS ((char *, int, int, struct objfile *));
271 static struct linetable *
272 new_linetable PARAMS ((int));
274 static struct blockvector *
275 new_bvect PARAMS ((int));
278 parse_type PARAMS ((union aux_ext *, int *, int));
280 static struct symbol *
281 mylookup_symbol PARAMS ((char *, struct block *, enum namespace,
282 enum address_class));
284 static struct block *
285 shrink_block PARAMS ((struct block *, struct symtab *));
288 xzalloc PARAMS ((unsigned int));
291 sort_blocks PARAMS ((struct symtab *));
294 compare_blocks PARAMS ((const void *, const void *));
296 static struct partial_symtab *
297 new_psymtab PARAMS ((char *, struct objfile *));
300 static struct partial_symtab *
301 parse_fdr PARAMS ((int, int, struct objfile *));
305 psymtab_to_symtab_1 PARAMS ((struct partial_symtab *, char *));
308 add_block PARAMS ((struct block *, struct symtab *));
311 add_symbol PARAMS ((struct symbol *, struct block *));
314 add_line PARAMS ((struct linetable *, int, CORE_ADDR, int));
316 static struct linetable *
317 shrink_linetable PARAMS ((struct linetable *));
320 mips_next_symbol_text PARAMS ((void));
322 /* Things we export to other modules */
324 /* Address bounds for the signal trampoline in inferior, if any */
325 /* FIXME: Nothing really seems to use this. Why is it here? */
327 CORE_ADDR sigtramp_address, sigtramp_end;
330 mipscoff_new_init (ignore)
331 struct objfile *ignore;
333 stabsread_new_init ();
334 buildsym_new_init ();
338 mipscoff_symfile_init (objfile)
339 struct objfile *objfile;
341 if (objfile->sym_private != NULL)
343 mfree (objfile->md, objfile->sym_private);
345 objfile->sym_private = NULL;
349 mipscoff_symfile_read (objfile, section_offsets, mainline)
350 struct objfile *objfile;
351 struct section_offsets *section_offsets;
354 init_minimal_symbol_collection ();
355 make_cleanup (discard_minimal_symbols, 0);
357 /* Now that the executable file is positioned at symbol table,
358 process it and define symbols accordingly. */
360 read_mips_symtab (objfile, section_offsets);
362 /* Install any minimal symbols that have been collected as the current
363 minimal symbols for this objfile. */
365 install_minimal_symbols (objfile);
368 /* Perform any local cleanups required when we are done with a particular
369 objfile. I.E, we are in the process of discarding all symbol information
370 for an objfile, freeing up all memory held for it, and unlinking the
371 objfile struct from the global list of known objfiles. */
374 mipscoff_symfile_finish (objfile)
375 struct objfile *objfile;
377 if (objfile->sym_private != NULL)
379 mfree (objfile->md, objfile->sym_private);
385 /* Allocate zeroed memory */
391 PTR p = xmalloc (size);
397 /* Exported procedure: Builds a symtab from the PST partial one.
398 Restores the environment in effect when PST was created, delegates
399 most of the work to an ancillary procedure, and sorts
400 and reorders the symtab list at the end */
403 mipscoff_psymtab_to_symtab (pst)
404 struct partial_symtab *pst;
412 printf_filtered ("Reading in symbols for %s...", pst->filename);
415 /* Get the BFD and list of pending typedefs */
416 cur_bfd = CUR_BFD (pst);
418 next_symbol_text_func = mips_next_symbol_text;
420 psymtab_to_symtab_1 (pst, pst->filename);
422 /* Match with global symbols. This only needs to be done once,
423 after all of the symtabs and dependencies have been read in. */
424 scan_file_globals (pst->objfile);
427 printf_filtered ("done.\n");
430 /* Exported procedure: Is PC in the signal trampoline code */
433 in_sigtramp (pc, ignore)
435 char *ignore; /* function name */
437 if (sigtramp_address == 0)
439 return (pc >= sigtramp_address && pc < sigtramp_end);
442 /* File-level interface functions */
444 /* Read the symtab information from file ABFD into memory. */
447 read_the_mips_symtab (abfd)
450 if (ecoff_slurp_symbolic_info (abfd) == false)
451 error ("Error reading symbol table: %s", bfd_errmsg (bfd_error));
454 /* Find a file descriptor given its index RF relative to a file CF */
464 fdrs = ecoff_data (cur_bfd)->fdr;
466 /* Object files do not have the RFD table, all refs are absolute */
469 ecoff_swap_rfd_in (cur_bfd,
470 ecoff_data (cur_bfd)->external_rfd + f->rfdBase + rf,
475 /* Return a safer print NAME for a file descriptor */
482 return "<stripped file>";
485 return ecoff_data (cur_bfd)->ss + f->issBase + f->rss;
489 /* Read in and parse the symtab of the file OBJFILE. Symbols from
490 different sections are relocated via the SECTION_OFFSETS. */
493 read_mips_symtab (objfile, section_offsets)
494 struct objfile *objfile;
495 struct section_offsets *section_offsets;
497 cur_bfd = objfile->obfd;
499 read_the_mips_symtab (objfile->obfd);
501 parse_partial_symbols (objfile, section_offsets);
504 /* Check to make sure file was compiled with -g. If not, warn the
505 user of this limitation. */
506 if (compare_glevel (max_glevel, GLEVEL_2) < 0)
508 if (max_gdbinfo == 0)
509 printf ("\n%s not compiled with -g, debugging support is limited.\n",
511 printf ("You should compile with -g2 or -g3 for best debugging support.\n");
517 /* Local utilities */
519 /* Map of FDR indexes to partial symtabs */
523 struct partial_symtab *pst; /* the psymtab proper */
524 int n_globals; /* exported globals (external symbols) */
525 int globals_offset; /* cumulative */
529 /* Utility stack, used to nest procedures and blocks properly.
530 It is a doubly linked list, to avoid too many alloc/free.
531 Since we might need it quite a few times it is NOT deallocated
534 static struct parse_stack
536 struct parse_stack *next, *prev;
537 struct symtab *cur_st; /* Current symtab. */
538 struct block *cur_block; /* Block in it. */
539 int blocktype; /* What are we parsing. */
540 int maxsyms; /* Max symbols in this block. */
541 struct type *cur_type; /* Type we parse fields for. */
542 int cur_field; /* Field number in cur_type. */
543 int procadr; /* Start addres of this procedure */
544 int numargs; /* Its argument count */
547 *top_stack; /* Top stack ptr */
550 /* Enter a new lexical context */
555 struct parse_stack *new;
557 /* Reuse frames if possible */
558 if (top_stack && top_stack->prev)
559 new = top_stack->prev;
561 new = (struct parse_stack *) xzalloc (sizeof (struct parse_stack));
562 /* Initialize new frame with previous content */
565 register struct parse_stack *prev = new->prev;
568 top_stack->prev = new;
570 new->next = top_stack;
575 /* Exit a lexical context */
583 top_stack = top_stack->next;
587 /* Cross-references might be to things we haven't looked at
588 yet, e.g. type references. To avoid too many type
589 duplications we keep a quick fixup table, an array
590 of lists of references indexed by file descriptor */
592 static struct mips_pending
594 struct mips_pending *next; /* link */
595 struct sym_ext *s; /* the symbol */
596 struct type *t; /* its partial type descriptor */
600 /* Check whether we already saw symbol SH in file FH as undefined */
602 static struct mips_pending *
603 is_pending_symbol (fh, sh)
607 int f_idx = fh - ecoff_data (cur_bfd)->fdr;
608 register struct mips_pending *p;
610 /* Linear search is ok, list is typically no more than 10 deep */
611 for (p = pending_list[f_idx]; p; p = p->next)
617 /* Add a new undef symbol SH of type T */
620 add_pending (fh, sh, t)
625 int f_idx = fh - ecoff_data (cur_bfd)->fdr;
626 struct mips_pending *p = is_pending_symbol (fh, sh);
628 /* Make sure we do not make duplicates */
631 p = (struct mips_pending *) xmalloc (sizeof (*p));
634 p->next = pending_list[f_idx];
635 pending_list[f_idx] = p;
639 /* Throw away undef entries when done with file index F_IDX */
640 /* FIXME -- storage leak. This is never called!!! --gnu */
648 register struct mips_pending *p, *q;
650 for (p = pending_list[f_idx]; p; p = q)
655 pending_list[f_idx] = 0;
661 prepend_tag_kind (tag_name, type_code)
663 enum type_code type_code;
672 case TYPE_CODE_STRUCT:
675 case TYPE_CODE_UNION:
682 result = (char *) obstack_alloc (¤t_objfile->symbol_obstack,
683 strlen (prefix) + strlen (tag_name) + 1);
684 sprintf (result, "%s%s", prefix, tag_name);
689 /* Parsing Routines proper. */
691 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
692 For blocks, procedures and types we open a new lexical context.
693 This is basically just a big switch on the symbol's type. Argument
694 AX is the base pointer of aux symbols for this file (fh->iauxBase).
695 EXT_SH points to the unswapped symbol, which is needed for struct,
696 union, etc., types; it is NULL for an EXTR. BIGEND says whether
697 aux symbols are big-endian or little-endian. Return count of
698 SYMR's handled (normally one).
700 FIXME: This modifies the symbol, but the only way we have to save
701 the modified information is to stuff it back into the BFD data. */
704 parse_symbol (sh, ax, ext_sh, bigend)
707 struct sym_ext *ext_sh;
713 struct mips_pending *pend;
717 enum address_class class;
720 if (ext_sh == (struct sym_ext *) NULL)
721 name = ecoff_data (cur_bfd)->ssext + sh->iss;
723 name = ecoff_data (cur_bfd)->ss + cur_fdr->issBase + sh->iss;
730 case stGlobal: /* external symbol, goes into global block */
732 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
734 s = new_symbol (name);
735 SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
738 case stStatic: /* static data, goes into current block. */
740 b = top_stack->cur_block;
741 s = new_symbol (name);
742 SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
745 case stLocal: /* local variable, goes into current block */
746 if (sh->sc == scRegister)
748 class = LOC_REGISTER;
750 sh->value += FP0_REGNUM - 32;
754 b = top_stack->cur_block;
755 s = new_symbol (name);
756 SYMBOL_VALUE (s) = sh->value;
758 data: /* Common code for symbols describing data */
759 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
760 SYMBOL_CLASS (s) = class;
763 /* Type could be missing in a number of cases */
764 if (sh->sc == scUndefined || sh->sc == scNil ||
765 sh->index == 0xfffff)
766 SYMBOL_TYPE (s) = builtin_type_int; /* undefined? */
768 SYMBOL_TYPE (s) = parse_type (ax + sh->index, 0, bigend);
769 /* Value of a data symbol is its memory address */
772 case stParam: /* arg to procedure, goes into current block */
774 top_stack->numargs++;
776 /* Special GNU C++ name. */
777 if (name[0] == CPLUS_MARKER && name[1] == 't' && name[2] == 0)
778 name = "this"; /* FIXME, not alloc'd in obstack */
779 s = new_symbol (name);
781 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
782 if (sh->sc == scRegister)
784 SYMBOL_CLASS (s) = LOC_REGPARM;
786 sh->value += FP0_REGNUM - 32;
789 SYMBOL_CLASS (s) = LOC_ARG;
790 SYMBOL_VALUE (s) = sh->value;
791 SYMBOL_TYPE (s) = parse_type (ax + sh->index, 0, bigend);
792 add_symbol (s, top_stack->cur_block);
794 /* FIXME: This has not been tested. See dbxread.c */
795 /* Add the type of this parameter to the function/procedure
796 type of this block. */
797 add_param_to_type (&top_stack->cur_block->function->type, s);
801 case stLabel: /* label, goes into current block */
802 s = new_symbol (name);
803 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE; /* so that it can be used */
804 SYMBOL_CLASS (s) = LOC_LABEL; /* but not misused */
805 SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
806 SYMBOL_TYPE (s) = builtin_type_int;
807 add_symbol (s, top_stack->cur_block);
810 case stProc: /* Procedure, usually goes into global block */
811 case stStaticProc: /* Static procedure, goes into current block */
812 s = new_symbol (name);
813 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
814 SYMBOL_CLASS (s) = LOC_BLOCK;
815 /* Type of the return value */
816 if (sh->sc == scUndefined || sh->sc == scNil)
817 t = builtin_type_int;
819 t = parse_type (ax + sh->index + 1, 0, bigend);
820 b = top_stack->cur_block;
821 if (sh->st == stProc)
823 struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
824 /* The next test should normally be true,
825 but provides a hook for nested functions
826 (which we don't want to make global). */
827 if (b == BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK))
828 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
832 /* Make a type for the procedure itself */
834 /* FIXME: This has not been tested yet! See dbxread.c */
835 /* Generate a template for the type of this function. The
836 types of the arguments will be added as we read the symbol
838 bcopy (SYMBOL_TYPE (s), lookup_function_type (t), sizeof (struct type));
840 SYMBOL_TYPE (s) = lookup_function_type (t);
843 /* Create and enter a new lexical context */
844 b = new_block (top_stack->maxsyms);
845 SYMBOL_BLOCK_VALUE (s) = b;
846 BLOCK_FUNCTION (b) = s;
847 BLOCK_START (b) = BLOCK_END (b) = sh->value;
848 BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
849 add_block (b, top_stack->cur_st);
851 /* Not if we only have partial info */
852 if (sh->sc == scUndefined || sh->sc == scNil)
856 top_stack->cur_block = b;
857 top_stack->blocktype = sh->st;
858 top_stack->cur_type = SYMBOL_TYPE (s);
859 top_stack->cur_field = -1;
860 top_stack->procadr = sh->value;
861 top_stack->numargs = 0;
863 sh->value = (long) SYMBOL_TYPE (s);
866 /* Beginning of code for structure, union, and enum definitions.
867 They all share a common set of local variables, defined here. */
869 enum type_code type_code;
870 struct sym_ext *ext_tsym;
875 case stStruct: /* Start a block defining a struct type */
876 type_code = TYPE_CODE_STRUCT;
877 goto structured_common;
879 case stUnion: /* Start a block defining a union type */
880 type_code = TYPE_CODE_UNION;
881 goto structured_common;
883 case stEnum: /* Start a block defining an enum type */
884 type_code = TYPE_CODE_ENUM;
885 goto structured_common;
887 case stBlock: /* Either a lexical block, or some type */
888 if (sh->sc != scInfo)
889 goto case_stBlock_code; /* Lexical block */
891 type_code = TYPE_CODE_UNDEF; /* We have a type. */
893 /* Common code for handling struct, union, enum, and/or as-yet-
894 unknown-type blocks of info about structured data. `type_code'
895 has been set to the proper TYPE_CODE, if we know it. */
898 top_stack->blocktype = stBlock;
900 s = new_symbol (name);
901 SYMBOL_NAMESPACE (s) = STRUCT_NAMESPACE;
902 SYMBOL_CLASS (s) = LOC_TYPEDEF;
903 SYMBOL_VALUE (s) = 0;
904 add_symbol (s, top_stack->cur_block);
906 /* First count the number of fields and the highest value. */
909 for (ext_tsym = ext_sh + 1; ; ext_tsym++)
913 ecoff_swap_sym_in (cur_bfd, ext_tsym, &tsym);
915 if (tsym.st == stEnd)
918 if (tsym.st == stMember)
920 if (nfields == 0 && type_code == TYPE_CODE_UNDEF)
921 /* If the type of the member is Nil (or Void),
922 without qualifiers, assume the tag is an
924 if (tsym.index == indexNil)
925 type_code = TYPE_CODE_ENUM;
928 ecoff_swap_tir_in (bigend,
929 &ax[tsym.index].a_ti,
931 if ((tir.bt == btNil || tir.bt == btVoid)
933 type_code = TYPE_CODE_ENUM;
936 if (tsym.value > max_value)
937 max_value = tsym.value;
939 else if (tsym.st == stBlock
940 || tsym.st == stUnion
942 || tsym.st == stStruct
943 || tsym.st == stParsed)
945 if (tsym.sc == scVariant); /*UNIMPLEMENTED*/
948 /* This is something like a struct within a
949 struct. Skip over the fields of the inner
950 struct. The -1 is because the for loop will
951 increment ext_tsym. */
952 ext_tsym = (ecoff_data (cur_bfd)->external_sym
959 complain (&block_member_complaint, tsym.st);
962 /* In an stBlock, there is no way to distinguish structs,
963 unions, and enums at this point. This is a bug in the
964 original design (that has been fixed with the recent
965 addition of the stStruct, stUnion, and stEnum symbol
966 types.) The way you can tell is if/when you see a variable
967 or field of that type. In that case the variable's type
968 (in the AUX table) says if the type is struct, union, or
969 enum, and points back to the stBlock here. So you can
970 patch the tag kind up later - but only if there actually is
971 a variable or field of that type.
973 So until we know for sure, we will guess at this point.
975 If the first member has index==indexNil or a void type,
976 assume we have an enumeration.
977 Otherwise, if there is more than one member, and all
978 the members have offset 0, assume we have a union.
979 Otherwise, assume we have a struct.
981 The heuristic could guess wrong in the case of of an
982 enumeration with no members or a union with one (or zero)
983 members, or when all except the last field of a struct have
984 width zero. These are uncommon and/or illegal situations,
985 and in any case guessing wrong probably doesn't matter
988 But if we later do find out we were wrong, we fixup the tag
989 kind. Members of an enumeration must be handled
990 differently from struct/union fields, and that is harder to
991 patch up, but luckily we shouldn't need to. (If there are
992 any enumeration members, we can tell for sure it's an enum
995 if (type_code == TYPE_CODE_UNDEF)
996 if (nfields > 1 && max_value == 0)
997 type_code = TYPE_CODE_UNION;
999 type_code = TYPE_CODE_STRUCT;
1001 /* If this type was expected, use its partial definition */
1002 pend = is_pending_symbol (cur_fdr, ext_sh);
1003 if (pend != (struct mips_pending *) NULL)
1006 t = new_type (prepend_tag_kind (name, type_code));
1008 TYPE_CODE (t) = type_code;
1009 TYPE_LENGTH (t) = sh->value;
1010 TYPE_NFIELDS (t) = nfields;
1011 TYPE_FIELDS (t) = f = ((struct field *)
1013 nfields * sizeof (struct field)));
1015 if (type_code == TYPE_CODE_ENUM)
1017 /* This is a non-empty enum. */
1018 for (ext_tsym = ext_sh + 1; ; ext_tsym++)
1021 struct symbol *enum_sym;
1023 ecoff_swap_sym_in (cur_bfd, ext_tsym, &tsym);
1025 if (tsym.st != stMember)
1028 f->bitpos = tsym.value;
1030 f->name = (ecoff_data (cur_bfd)->ss
1035 enum_sym = ((struct symbol *)
1036 obstack_alloc (¤t_objfile->symbol_obstack,
1037 sizeof (struct symbol)));
1038 memset ((PTR) enum_sym, 0, sizeof (struct symbol));
1039 SYMBOL_NAME (enum_sym) = f->name;
1040 SYMBOL_CLASS (enum_sym) = LOC_CONST;
1041 SYMBOL_TYPE (enum_sym) = t;
1042 SYMBOL_NAMESPACE (enum_sym) = VAR_NAMESPACE;
1043 SYMBOL_VALUE (enum_sym) = tsym.value;
1044 add_symbol (enum_sym, top_stack->cur_block);
1046 /* Skip the stMembers that we've handled. */
1051 SYMBOL_TYPE (s) = t;
1052 /* make this the current type */
1053 top_stack->cur_type = t;
1054 top_stack->cur_field = 0;
1055 /* Mark that symbol has a type, and say which one */
1056 sh->value = (long) t;
1059 /* End of local variables shared by struct, union, enum, and
1060 block (as yet unknown struct/union/enum) processing. */
1064 /* beginnning of (code) block. Value of symbol
1065 is the displacement from procedure start */
1066 push_parse_stack ();
1067 top_stack->blocktype = stBlock;
1068 b = new_block (top_stack->maxsyms);
1069 BLOCK_START (b) = sh->value + top_stack->procadr;
1070 BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
1071 top_stack->cur_block = b;
1072 add_block (b, top_stack->cur_st);
1075 case stEnd: /* end (of anything) */
1076 if (sh->sc == scInfo)
1078 /* Finished with type */
1079 top_stack->cur_type = 0;
1081 else if (sh->sc == scText &&
1082 (top_stack->blocktype == stProc ||
1083 top_stack->blocktype == stStaticProc))
1085 /* Finished with procedure */
1086 struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
1087 struct mips_extra_func_info *e;
1091 BLOCK_END (top_stack->cur_block) += sh->value; /* size */
1093 /* Make up special symbol to contain procedure specific info */
1094 s = new_symbol (MIPS_EFI_SYMBOL_NAME);
1095 SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
1096 SYMBOL_CLASS (s) = LOC_CONST;
1097 SYMBOL_TYPE (s) = builtin_type_void;
1098 e = ((struct mips_extra_func_info *)
1099 obstack_alloc (¤t_objfile->symbol_obstack,
1100 sizeof (struct mips_extra_func_info)));
1101 SYMBOL_VALUE (s) = (int) e;
1102 e->numargs = top_stack->numargs;
1103 add_symbol (s, top_stack->cur_block);
1105 /* Reallocate symbols, saving memory */
1106 b = shrink_block (top_stack->cur_block, top_stack->cur_st);
1108 /* f77 emits proc-level with address bounds==[0,0],
1109 So look for such child blocks, and patch them. */
1110 for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
1112 struct block *b_bad = BLOCKVECTOR_BLOCK (bv, i);
1113 if (BLOCK_SUPERBLOCK (b_bad) == b
1114 && BLOCK_START (b_bad) == top_stack->procadr
1115 && BLOCK_END (b_bad) == top_stack->procadr)
1117 BLOCK_START (b_bad) = BLOCK_START (b);
1118 BLOCK_END (b_bad) = BLOCK_END (b);
1122 else if (sh->sc == scText && top_stack->blocktype == stBlock)
1124 /* End of (code) block. The value of the symbol is the
1125 displacement from the procedure`s start address of the
1126 end of this block. */
1127 BLOCK_END (top_stack->cur_block) = sh->value + top_stack->procadr;
1128 shrink_block (top_stack->cur_block, top_stack->cur_st);
1130 else if (sh->sc == scText && top_stack->blocktype == stFile)
1132 /* End of file. Pop parse stack and ignore. Higher
1133 level code deals with this. */
1137 complain (&stEnd_complaint, sh->sc);
1139 pop_parse_stack (); /* restore previous lexical context */
1142 case stMember: /* member of struct or union */
1143 f = &TYPE_FIELDS (top_stack->cur_type)[top_stack->cur_field++];
1145 f->bitpos = sh->value;
1147 f->type = parse_type (ax + sh->index, &f->bitsize, bigend);
1150 case stTypedef: /* type definition */
1151 s = new_symbol (name);
1152 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
1153 SYMBOL_CLASS (s) = LOC_TYPEDEF;
1154 SYMBOL_BLOCK_VALUE (s) = top_stack->cur_block;
1155 add_symbol (s, top_stack->cur_block);
1156 SYMBOL_TYPE (s) = parse_type (ax + sh->index, 0, bigend);
1157 sh->value = (long) SYMBOL_TYPE (s);
1160 case stFile: /* file name */
1161 push_parse_stack ();
1162 top_stack->blocktype = sh->st;
1165 /* I`ve never seen these for C */
1167 break; /* register relocation */
1169 break; /* forwarding address */
1171 break; /* constant */
1173 complain (&unknown_mips_symtype_complaint, sh->st);
1182 /* Parse the type information provided in the raw AX entries for
1183 the symbol SH. Return the bitfield size in BS, in case.
1184 We must byte-swap the AX entries before we use them; BIGEND says whether
1185 they are big-endian or little-endian (from fh->fBigendian). */
1187 static struct type *
1188 parse_type (ax, bs, bigend)
1193 /* Null entries in this map are treated specially */
1194 static struct type **map_bt[] =
1196 &builtin_type_void, /* btNil */
1198 &builtin_type_char, /* btChar */
1199 &builtin_type_unsigned_char,/* btUChar */
1200 &builtin_type_short, /* btShort */
1201 &builtin_type_unsigned_short, /* btUShort */
1202 &builtin_type_int, /* btInt */
1203 &builtin_type_unsigned_int, /* btUInt */
1204 &builtin_type_long, /* btLong */
1205 &builtin_type_unsigned_long,/* btULong */
1206 &builtin_type_float, /* btFloat */
1207 &builtin_type_double, /* btDouble */
1214 &builtin_type_complex, /* btComplex */
1215 &builtin_type_double_complex, /* btDComplex */
1217 &builtin_type_fixed_dec, /* btFixedDec */
1218 &builtin_type_float_dec, /* btFloatDec */
1219 &builtin_type_string, /* btString */
1222 &builtin_type_void, /* btVoid */
1223 &builtin_type_long_long, /* btLongLong */
1224 &builtin_type_unsigned_long_long, /* btULongLong */
1228 struct type *tp = 0;
1231 enum type_code type_code = TYPE_CODE_UNDEF;
1233 /* Use aux as a type information record, map its basic type. */
1235 ecoff_swap_tir_in (bigend, &tax->a_ti, t);
1236 if (t->bt > (sizeof (map_bt) / sizeof (*map_bt)))
1238 complain (&basic_type_complaint, t->bt);
1239 return builtin_type_int;
1243 tp = *map_bt[t->bt];
1249 /* Cannot use builtin types -- build our own */
1253 tp = lookup_pointer_type (builtin_type_void);
1257 type_code = TYPE_CODE_STRUCT;
1261 type_code = TYPE_CODE_UNION;
1265 type_code = TYPE_CODE_ENUM;
1269 type_code = TYPE_CODE_RANGE;
1273 type_code = TYPE_CODE_SET;
1278 complain (&basic_type_complaint, t->bt);
1279 return builtin_type_int;
1283 /* Skip over any further type qualifiers (FIXME). */
1286 /* This is the way it would work if the compiler worked */
1291 ecoff_swap_tir_in (bigend, &ax->a_ti, t1);
1293 while (t1->continued);
1296 /* Move on to next aux */
1301 *bs = AUX_GET_WIDTH (bigend, ax);
1305 /* All these types really point to some (common) MIPS type
1306 definition, and only the type-qualifiers fully identify
1307 them. We'll make the same effort at sharing. */
1308 if (t->bt == btIndirect ||
1309 t->bt == btStruct ||
1312 t->bt == btTypedef ||
1316 char name[256], *pn;
1318 /* Try to cross reference this type */
1319 ax += cross_ref (ax, &tp, type_code, &pn, bigend);
1320 /* reading .o file ? */
1321 if (tp == (struct type *) NULL)
1322 tp = init_type (type_code, 0, 0, (char *) NULL,
1323 (struct objfile *) NULL);
1324 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1325 sprintf (name, fmt, pn);
1327 /* Usually, TYPE_CODE(tp) is already type_code. The main
1328 exception is if we guessed wrong re struct/union/enum. */
1329 if (TYPE_CODE (tp) != type_code)
1331 complain (&bad_tag_guess_complaint, name);
1332 TYPE_CODE (tp) = type_code;
1334 if (TYPE_NAME (tp) == NULL || !STREQ (TYPE_NAME (tp), name))
1335 TYPE_NAME (tp) = obsavestring (name, strlen (name),
1336 ¤t_objfile->type_obstack);
1339 /* Deal with range types */
1340 if (t->bt == btRange)
1342 TYPE_NFIELDS (tp) = 2;
1343 TYPE_FIELDS (tp) = ((struct field *)
1344 TYPE_ALLOC (tp, 2 * sizeof (struct field)));
1345 TYPE_FIELD_NAME (tp, 0) = obsavestring ("Low", strlen ("Low"),
1346 ¤t_objfile->type_obstack);
1347 TYPE_FIELD_BITPOS (tp, 0) = AUX_GET_DNLOW (bigend, ax);
1349 TYPE_FIELD_NAME (tp, 1) = obsavestring ("High", strlen ("High"),
1350 ¤t_objfile->type_obstack);
1351 TYPE_FIELD_BITPOS (tp, 1) = AUX_GET_DNHIGH (bigend, ax);
1355 /* Parse all the type qualifiers now. If there are more
1356 than 6 the game will continue in the next aux */
1358 #define PARSE_TQ(tq) \
1359 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, bigend);
1361 again:PARSE_TQ (tq0);
1372 ecoff_swap_tir_in (bigend, &tax->a_ti, t);
1378 /* Make up a complex type from a basic one. Type is passed by
1379 reference in TPP and side-effected as necessary. The type
1380 qualifier TQ says how to handle the aux symbols at AX for
1381 the symbol SX we are currently analyzing. BIGEND says whether
1382 aux symbols are big-endian or little-endian.
1383 Returns the number of aux symbols we parsed. */
1386 upgrade_type (tpp, tq, ax, bigend)
1395 /* Used in array processing */
1406 t = lookup_pointer_type (*tpp);
1411 t = lookup_function_type (*tpp);
1418 /* Determine and record the domain type (type of index) */
1419 ecoff_swap_rndx_in (bigend, &ax->a_rndx, &rndx);
1425 rf = AUX_GET_ISYM (bigend, ax);
1428 fh = get_rfd (cur_fd, rf);
1430 indx = parse_type ((ecoff_data (cur_bfd)->external_aux
1433 (int *) NULL, bigend);
1435 /* Get the bounds, and create the array type. */
1437 lower = AUX_GET_DNLOW (bigend, ax);
1439 upper = AUX_GET_DNHIGH (bigend, ax);
1441 rf = AUX_GET_WIDTH (bigend, ax); /* bit size of array element */
1443 range = create_range_type ((struct type *) NULL, indx,
1446 t = create_array_type ((struct type *) NULL, *tpp, range);
1448 /* Check whether supplied array element bit size matches
1449 the known size of the element type. If this complaint
1450 ends up not happening, we can remove this code. It's
1451 here because we aren't sure we understand this *&%&$
1453 id = TYPE_LENGTH (TYPE_TARGET_TYPE (t)) << 3; /* bitsize */
1456 /* Most likely an undefined type */
1458 TYPE_LENGTH (TYPE_TARGET_TYPE (t)) = id >> 3;
1461 complain (&array_bitsize_complaint, rf);
1467 /* Volatile -- currently ignored */
1471 /* Const -- currently ignored */
1475 complain (&unknown_type_qual_complaint, tq);
1481 /* Parse a procedure descriptor record PR. Note that the procedure is
1482 parsed _after_ the local symbols, now we just insert the extra
1483 information we need into a MIPS_EFI_SYMBOL_NAME symbol that has
1484 already been placed in the procedure's main block. Note also that
1485 images that have been partially stripped (ld -x) have been deprived
1486 of local symbols, and we have to cope with them here. FIRST_OFF is
1487 the offset of the first procedure for this FDR; we adjust the
1488 address by this amount, but I don't know why. */
1491 parse_procedure (pr, have_stabs, first_off)
1494 unsigned long first_off;
1496 struct symbol *s, *i;
1498 struct mips_extra_func_info *e;
1501 /* Simple rule to find files linked "-x" */
1502 if (cur_fdr->rss == -1)
1506 /* Static procedure at address pr->adr. Sigh. */
1507 complain (&pdr_static_symbol_complaint, pr->adr);
1515 ecoff_swap_ext_in (cur_bfd,
1516 ecoff_data (cur_bfd)->external_ext + pr->isym,
1518 sh_name = ecoff_data (cur_bfd)->ssext + she.asym.iss;
1526 ecoff_swap_sym_in (cur_bfd,
1527 (ecoff_data (cur_bfd)->external_sym
1531 sh_name = ecoff_data (cur_bfd)->ss + cur_fdr->issBase + sh.iss;
1536 /* We have to save the cur_fdr across the call to lookup_symbol.
1537 If the pdr is for a static function and if a global function with
1538 the same name exists, lookup_symbol will eventually read in the symtab
1539 for the global function and clobber cur_fdr. */
1540 FDR *save_cur_fdr = cur_fdr;
1541 s = lookup_symbol (sh_name, NULL, VAR_NAMESPACE, 0, NULL);
1542 cur_fdr = save_cur_fdr;
1545 s = mylookup_symbol (sh_name, top_stack->cur_block,
1546 VAR_NAMESPACE, LOC_BLOCK);
1550 b = SYMBOL_BLOCK_VALUE (s);
1554 complain (&pdr_for_nonsymbol_complaint, sh_name);
1558 /* FIXME -- delete. We can't do symbol allocation now; it's all done. */
1559 s = new_symbol (sh_name);
1560 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
1561 SYMBOL_CLASS (s) = LOC_BLOCK;
1562 /* Donno its type, hope int is ok */
1563 SYMBOL_TYPE (s) = lookup_function_type (builtin_type_int);
1564 add_symbol (s, top_stack->cur_block);
1565 /* Wont have symbols for this one */
1567 SYMBOL_BLOCK_VALUE (s) = b;
1568 BLOCK_FUNCTION (b) = s;
1569 BLOCK_START (b) = pr->adr;
1570 /* BOUND used to be the end of procedure's text, but the
1571 argument is no longer passed in. */
1572 BLOCK_END (b) = bound;
1573 BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
1574 add_block (b, top_stack->cur_st);
1578 i = mylookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, LOC_CONST);
1582 e = (struct mips_extra_func_info *) SYMBOL_VALUE (i);
1584 e->pdr.isym = (long) s;
1585 e->pdr.adr += cur_fdr->adr - first_off;
1589 /* Parse the external symbol ES. Just call parse_symbol() after
1590 making sure we know where the aux are for it. For procedures,
1591 parsing of the PDRs has already provided all the needed
1592 information, we only parse them if SKIP_PROCEDURES is false,
1593 and only if this causes no symbol duplication.
1594 BIGEND says whether aux entries are big-endian or little-endian.
1596 This routine clobbers top_stack->cur_block and ->cur_st. */
1599 parse_external (es, skip_procedures, bigend)
1601 int skip_procedures;
1606 if (es->ifd != ifdNil)
1609 cur_fdr = ecoff_data (cur_bfd)->fdr + cur_fd;
1610 ax = ecoff_data (cur_bfd)->external_aux + cur_fdr->iauxBase;
1614 cur_fdr = ecoff_data (cur_bfd)->fdr;
1618 /* Reading .o files */
1619 if (es->asym.sc == scUndefined || es->asym.sc == scNil)
1622 switch (es->asym.st)
1642 /* FIXME: Turn this into a complaint? */
1644 printf_filtered ("Warning: %s `%s' is undefined (in %s)\n",
1646 ecoff_data (cur_bfd)->ssext + es->asym.iss,
1647 fdr_name (cur_fdr));
1651 switch (es->asym.st)
1654 /* If we have full symbols we do not need more */
1655 if (skip_procedures)
1657 if (mylookup_symbol (ecoff_data (cur_bfd)->ssext + es->asym.iss,
1658 top_stack->cur_block,
1659 VAR_NAMESPACE, LOC_BLOCK))
1664 /* Note that the case of a symbol with indexNil must be handled
1665 anyways by parse_symbol(). */
1666 parse_symbol (&es->asym, ax, (struct sym_ext *) NULL, bigend);
1667 /* Note that parse_symbol changed es->asym. */
1674 /* Parse the line number info for file descriptor FH into
1675 GDB's linetable LT. MIPS' encoding requires a little bit
1676 of magic to get things out. Note also that MIPS' line
1677 numbers can go back and forth, apparently we can live
1678 with that and do not need to reorder our linetables */
1681 parse_lines (fh, pr, lt)
1684 struct linetable *lt;
1686 unsigned char *base;
1688 int delta, count, lineno = 0;
1689 unsigned long first_off = pr->adr;
1691 if (fh->cbLineOffset == 0)
1694 base = ecoff_data (cur_bfd)->line + fh->cbLineOffset;
1696 /* Scan by procedure descriptors */
1698 for (j = 0; j < fh->cpd; j++, pr++)
1703 /* No code for this one */
1704 if (pr->iline == ilineNil ||
1705 pr->lnLow == -1 || pr->lnHigh == -1)
1708 /* Aurgh! To know where to stop expanding we must look-ahead. */
1709 for (l = 1; l < (fh->cpd - j); l++)
1710 if (pr[l].iline != -1)
1712 if (l == (fh->cpd - j))
1717 /* When procedures are moved around the linenumbers are
1718 attributed to the next procedure up. */
1719 if (pr->iline >= halt)
1722 base = ecoff_data (cur_bfd)->line + fh->cbLineOffset + pr->cbLineOffset;
1723 adr = fh->adr + pr->adr - first_off;
1724 l = adr >> 2; /* in words */
1725 halt += (adr >> 2) - pr->iline;
1726 for (lineno = pr->lnLow; l < halt;)
1728 count = *base & 0x0f;
1729 delta = *base++ >> 4;
1734 delta = (base[0] << 8) | base[1];
1735 if (delta >= 0x8000)
1739 lineno += delta; /* first delta is 0 */
1740 k = add_line (lt, lineno, l, k);
1746 /* Master parsing procedure for first-pass reading of file symbols
1747 into a partial_symtab. */
1750 parse_partial_symbols (objfile, section_offsets)
1751 struct objfile *objfile;
1752 struct section_offsets *section_offsets;
1755 HDRR *hdr = &ecoff_data (cur_bfd)->symbolic_header;
1756 /* Running pointers */
1758 struct ext_ext *ext_out;
1759 struct ext_ext *ext_out_end;
1761 register EXTR *ext_in;
1764 struct partial_symtab *pst;
1766 int past_first_source_file = 0;
1768 /* List of current psymtab's include files */
1769 char **psymtab_include_list;
1770 int includes_allocated;
1773 struct pst_map *fdr_to_pst;
1774 /* Index within current psymtab dependency list */
1775 struct partial_symtab **dependency_list;
1776 int dependencies_used, dependencies_allocated;
1777 struct cleanup *old_chain;
1780 extern_tab = (EXTR *) obstack_alloc (&objfile->psymbol_obstack,
1781 sizeof (EXTR) * hdr->iextMax);
1783 includes_allocated = 30;
1785 psymtab_include_list = (char **) alloca (includes_allocated *
1787 next_symbol_text_func = mips_next_symbol_text;
1789 dependencies_allocated = 30;
1790 dependencies_used = 0;
1792 (struct partial_symtab **) alloca (dependencies_allocated *
1793 sizeof (struct partial_symtab *));
1795 last_source_file = NULL;
1800 * Only parse the Local and External symbols, and the Relative FDR.
1801 * Fixup enough of the loader symtab to be able to use it.
1802 * Allocate space only for the file's portions we need to
1807 max_glevel = MIN_GLEVEL;
1809 /* Allocate the map FDR -> PST.
1810 Minor hack: -O3 images might claim some global data belongs
1811 to FDR -1. We`ll go along with that */
1812 fdr_to_pst = (struct pst_map *) xzalloc ((hdr->ifdMax + 1) * sizeof *fdr_to_pst);
1813 old_chain = make_cleanup (free, fdr_to_pst);
1816 struct partial_symtab *pst = new_psymtab ("", objfile);
1817 fdr_to_pst[-1].pst = pst;
1821 /* Pass 0 over external syms: swap them in. */
1822 ext_block = (EXTR *) xmalloc (hdr->iextMax * sizeof (EXTR));
1823 make_cleanup (free, ext_block);
1825 ext_out = ecoff_data (cur_bfd)->external_ext;
1826 ext_out_end = ext_out + hdr->iextMax;
1828 for (; ext_out < ext_out_end; ext_out++, ext_in++)
1829 ecoff_swap_ext_in (cur_bfd, ext_out, ext_in);
1831 /* Pass 1 over external syms: Presize and partition the list */
1833 ext_in_end = ext_in + hdr->iextMax;
1834 for (; ext_in < ext_in_end; ext_in++)
1835 fdr_to_pst[ext_in->ifd].n_globals++;
1837 /* Pass 1.5 over files: partition out global symbol space */
1839 for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++)
1841 fdr_to_pst[f_idx].globals_offset = s_idx;
1842 s_idx += fdr_to_pst[f_idx].n_globals;
1843 fdr_to_pst[f_idx].n_globals = 0;
1846 /* Pass 2 over external syms: fill in external symbols */
1848 ext_in_end = ext_in + hdr->iextMax;
1849 for (; ext_in < ext_in_end; ext_in++)
1851 enum minimal_symbol_type ms_type = mst_text;
1853 extern_tab[fdr_to_pst[ext_in->ifd].globals_offset
1854 + fdr_to_pst[ext_in->ifd].n_globals++] = *ext_in;
1856 if (ext_in->asym.sc == scUndefined || ext_in->asym.sc == scNil)
1859 name = ecoff_data (cur_bfd)->ssext + ext_in->asym.iss;
1860 switch (ext_in->asym.st)
1870 ms_type = mst_unknown;
1871 complain (&unknown_ext_complaint, name);
1873 prim_record_minimal_symbol (name, ext_in->asym.value, ms_type);
1876 /* Pass 3 over files, over local syms: fill in static symbols */
1877 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
1879 struct partial_symtab *save_pst;
1882 cur_fdr = fh = ecoff_data (cur_bfd)->fdr + f_idx;
1886 fdr_to_pst[f_idx].pst = NULL;
1889 pst = start_psymtab_common (objfile, section_offsets,
1891 fh->cpd ? fh->adr : 0,
1892 objfile->global_psymbols.next,
1893 objfile->static_psymbols.next);
1894 pst->read_symtab_private = ((char *)
1895 obstack_alloc (&objfile->psymbol_obstack,
1896 sizeof (struct symloc)));
1897 memset ((PTR) pst->read_symtab_private, 0, sizeof (struct symloc));
1900 /* Make everything point to everything. */
1901 FDR_IDX (pst) = f_idx;
1902 fdr_to_pst[f_idx].pst = pst;
1904 /* FIXME: This tampers with data from BFD. */
1905 fh->ioptBase = (int) pst;
1907 CUR_BFD (pst) = cur_bfd;
1909 /* The way to turn this into a symtab is to call... */
1910 pst->read_symtab = mipscoff_psymtab_to_symtab;
1912 pst->texthigh = pst->textlow;
1914 /* For stabs-in-ecoff files, the second symbol must be @stab.
1915 This symbol is emitted by mips-tfile to signal that the
1916 current object file uses encapsulated stabs instead of mips
1917 ecoff for local symbols. (It is the second symbol because
1918 the first symbol is the stFile used to signal the start of a
1920 processing_gcc_compilation = 0;
1923 ecoff_swap_sym_in (cur_bfd,
1924 (ecoff_data (cur_bfd)->external_sym
1928 if (STREQ (ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss,
1930 processing_gcc_compilation = 2;
1933 if (processing_gcc_compilation != 0)
1935 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
1940 ecoff_swap_sym_in (cur_bfd,
1941 (ecoff_data (cur_bfd)->external_sym
1945 type_code = MIPS_UNMARK_STAB (sh.index);
1946 if (!MIPS_IS_STAB (&sh))
1948 if (sh.st == stProc || sh.st == stStaticProc)
1950 long procaddr = sh.value;
1954 isym = AUX_GET_ISYM (fh->fBigendian,
1955 (ecoff_data (cur_bfd)->external_aux
1958 ecoff_swap_sym_in (cur_bfd,
1959 (ecoff_data (cur_bfd)->external_sym
1966 long high = procaddr + sh.value;
1967 if (high > pst->texthigh)
1968 pst->texthigh = high;
1973 #define SET_NAMESTRING() \
1974 namestring = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss
1975 #define CUR_SYMBOL_TYPE type_code
1976 #define CUR_SYMBOL_VALUE sh.value
1977 #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms)\
1979 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
1980 #define HANDLE_RBRAC(val) \
1981 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
1982 #include "partial-stab.h"
1987 for (cur_sdx = 0; cur_sdx < fh->csym;)
1990 enum address_class class;
1992 ecoff_swap_sym_in (cur_bfd,
1993 (ecoff_data (cur_bfd)->external_sym
1998 if (MIPS_IS_STAB (&sh))
2004 if (sh.sc == scUndefined || sh.sc == scNil ||
2005 sh.index == 0xfffff)
2007 /* FIXME, premature? */
2012 name = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss;
2020 case stProc: /* Asm labels apparently */
2021 case stStaticProc: /* Function */
2022 ADD_PSYMBOL_TO_LIST (name, strlen (name),
2023 VAR_NAMESPACE, LOC_BLOCK,
2024 objfile->static_psymbols, sh.value,
2025 psymtab_language, objfile);
2026 /* Skip over procedure to next one. */
2027 if (sh.index >= hdr->iauxMax)
2029 /* Should not happen, but does when cross-compiling
2030 with the MIPS compiler. FIXME -- pull later. */
2031 complain (&index_complaint, name);
2032 new_sdx = cur_sdx + 1; /* Don't skip at all */
2035 new_sdx = AUX_GET_ISYM (fh->fBigendian,
2036 (ecoff_data (cur_bfd)->external_aux
2039 procaddr = sh.value;
2041 if (new_sdx <= cur_sdx)
2043 /* This should not happen either... FIXME. */
2044 complain (&aux_index_complaint, name);
2045 new_sdx = cur_sdx + 1; /* Don't skip backward */
2049 ecoff_swap_sym_in (cur_bfd,
2050 (ecoff_data (cur_bfd)->external_sym
2057 high = procaddr + sh.value;
2058 if (high > pst->texthigh)
2059 pst->texthigh = high;
2062 case stStatic: /* Variable */
2066 case stTypedef:/* Typedef */
2067 class = LOC_TYPEDEF;
2070 case stConstant: /* Constant decl */
2077 case stBlock: /* { }, str, un, enum*/
2078 if (sh.sc == scInfo)
2080 ADD_PSYMBOL_TO_LIST (name, strlen (name),
2081 STRUCT_NAMESPACE, LOC_TYPEDEF,
2082 objfile->static_psymbols,
2084 psymtab_language, objfile);
2086 /* Skip over the block */
2088 if (new_sdx <= cur_sdx)
2090 /* This happens with the Ultrix kernel. */
2091 complain (&block_index_complaint, name);
2092 new_sdx = cur_sdx + 1; /* Don't skip backward */
2097 case stFile: /* File headers */
2098 case stLabel: /* Labels */
2099 case stEnd: /* Ends of files */
2102 case stLocal: /* Local variables */
2103 /* Normally these are skipped because we skip over
2104 all blocks we see. However, these can occur
2105 as visible symbols in a .h file that contains code. */
2109 /* Both complaints are valid: one gives symbol name,
2110 the other the offending symbol type. */
2111 complain (&unknown_sym_complaint, name);
2112 complain (&unknown_st_complaint, sh.st);
2116 /* Use this gdb symbol */
2117 ADD_PSYMBOL_TO_LIST (name, strlen (name),
2118 VAR_NAMESPACE, class,
2119 objfile->static_psymbols, sh.value,
2120 psymtab_language, objfile);
2122 cur_sdx++; /* Go to next file symbol */
2125 /* Now do enter the external symbols. */
2126 ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset];
2127 cur_sdx = fdr_to_pst[f_idx].n_globals;
2128 PST_PRIVATE (save_pst)->extern_count = cur_sdx;
2129 PST_PRIVATE (save_pst)->extern_tab = ext_ptr;
2130 for (; --cur_sdx >= 0; ext_ptr++)
2132 register struct partial_symbol *psym;
2133 enum address_class class;
2137 if (ext_ptr->ifd != f_idx)
2139 psh = &ext_ptr->asym;
2149 complain (&unknown_ext_complaint,
2150 ecoff_data (cur_bfd)->ssext + psh->iss);
2151 /* Fall through, pretend it's global. */
2156 name = ecoff_data (cur_bfd)->ssext + psh->iss;
2157 ADD_PSYMBOL_ADDR_TO_LIST (name, strlen (name),
2158 VAR_NAMESPACE, class,
2159 objfile->global_psymbols, (CORE_ADDR) psh->value,
2160 psymtab_language, objfile);
2164 end_psymtab (save_pst, psymtab_include_list, includes_used,
2165 -1, save_pst->texthigh,
2166 dependency_list, dependencies_used);
2167 if (objfile->ei.entry_point >= save_pst->textlow &&
2168 objfile->ei.entry_point < save_pst->texthigh)
2170 objfile->ei.entry_file_lowpc = save_pst->textlow;
2171 objfile->ei.entry_file_highpc = save_pst->texthigh;
2175 /* Now scan the FDRs for dependencies */
2176 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
2179 fh = f_idx + ecoff_data (cur_bfd)->fdr;
2180 pst = fdr_to_pst[f_idx].pst;
2182 /* This should catch stabs-in-ecoff. */
2187 { /* If there are no functions defined here ... */
2188 /* ...then presumably a .h file: drop reverse depends .h->.c */
2189 for (; s_id0 < fh->crfd; s_id0++)
2193 ecoff_swap_rfd_in (cur_bfd,
2194 (ecoff_data (cur_bfd)->external_rfd
2200 s_id0++; /* Skip self-dependency */
2205 pst->number_of_dependencies = fh->crfd - s_id0;
2207 ((struct partial_symtab **)
2208 obstack_alloc (&objfile->psymbol_obstack,
2209 (pst->number_of_dependencies
2210 * sizeof (struct partial_symtab *))));
2211 for (s_idx = s_id0; s_idx < fh->crfd; s_idx++)
2215 ecoff_swap_rfd_in (cur_bfd,
2216 (ecoff_data (cur_bfd)->external_rfd
2220 if (rh < 0 || rh >= hdr->ifdMax)
2221 complain (&bad_file_number_complaint, rh);
2223 pst->dependencies[s_idx - s_id0] = fdr_to_pst[rh].pst;
2226 do_cleanups (old_chain);
2231 /* Do the initial analisys of the F_IDX-th file descriptor.
2232 Allocates a partial symtab for it, and builds the list
2233 of dependent files by recursion. LEV says at which level
2234 of recursion we are called (to pretty up debug traces) */
2236 static struct partial_symtab *
2237 parse_fdr (f_idx, lev, objfile)
2240 struct objfile *objfile;
2243 register struct partial_symtab *pst;
2246 fh = ecoff_data (cur_bfd)->fdr + f_idx;
2248 /* Use this to indicate into which symtab this file was parsed */
2250 return (struct partial_symtab *) fh->ioptBase;
2252 /* Debuggability level */
2253 if (compare_glevel (max_glevel, fh->glevel) < 0)
2254 max_glevel = fh->glevel;
2256 /* Make a new partial_symtab */
2257 pst = new_psymtab (fdr_name (fh), objfile);
2265 pst->textlow = fh->adr;
2266 pst->texthigh = fh->cpd; /* To be fixed later */
2269 /* Make everything point to everything. */
2270 FDR_IDX (pst) = f_idx;
2271 fdr_to_pst[f_idx].pst = pst;
2272 fh->ioptBase = (int) pst;
2274 /* Analyze its dependencies */
2280 { /* If there are no functions defined here ... */
2281 /* ...then presumably a .h file: drop reverse depends .h->.c */
2282 for (; s_id0 < fh->crfd; s_id0++)
2286 ecoff_swap_rfd_in (cur_bfd,
2287 (ecoff_data (cur_bfd)->external_rfd
2293 s_id0++; /* Skip self-dependency */
2298 pst->number_of_dependencies = fh->crfd - s_id0;
2299 pst->dependencies = ((struct partial_symtab **)
2300 obstack_alloc (&objfile->psymbol_obstack,
2301 (pst->number_of_dependencies
2302 * sizeof (struct partial_symtab *))));
2303 for (s_idx = s_id0; s_idx < fh->crfd; s_idx++)
2307 ecoff_swap_rfd_in (cur_bfd,
2308 (ecoff_data (cur_bfd)->external_rfd
2312 pst->dependencies[s_idx - s_id0] = parse_fdr (rh, lev + 1, objfile);
2321 mips_next_symbol_text ()
2326 ecoff_swap_sym_in (cur_bfd,
2327 (ecoff_data (cur_bfd)->external_sym
2331 return ecoff_data (cur_bfd)->ss + cur_fdr->issBase + sh.iss;
2334 /* Ancillary function to psymtab_to_symtab(). Does all the work
2335 for turning the partial symtab PST into a symtab, recurring
2336 first on all dependent psymtabs. The argument FILENAME is
2337 only passed so we can see in debug stack traces what file
2340 This function has a split personality, based on whether the
2341 symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
2342 The flow of control and even the memory allocation differs. FIXME. */
2345 psymtab_to_symtab_1 (pst, filename)
2346 struct partial_symtab *pst;
2352 struct linetable *lines;
2358 /* Read in all partial symbtabs on which this one is dependent.
2359 NOTE that we do have circular dependencies, sigh. We solved
2360 that by setting pst->readin before this point. */
2362 for (i = 0; i < pst->number_of_dependencies; i++)
2363 if (!pst->dependencies[i]->readin)
2365 /* Inform about additional files to be read in. */
2368 fputs_filtered (" ", stdout);
2370 fputs_filtered ("and ", stdout);
2372 printf_filtered ("%s...",
2373 pst->dependencies[i]->filename);
2374 wrap_here (""); /* Flush output */
2377 /* We only pass the filename for debug purposes */
2378 psymtab_to_symtab_1 (pst->dependencies[i],
2379 pst->dependencies[i]->filename);
2382 /* Now read the symbols for this symtab */
2384 current_objfile = pst->objfile;
2385 cur_fd = FDR_IDX (pst);
2386 fh = (cur_fd == -1) ? (FDR *) NULL : ecoff_data (cur_bfd)->fdr + cur_fd;
2389 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2390 processing_gcc_compilation = 0;
2391 if (fh != (FDR *) NULL && fh->csym >= 2)
2395 ecoff_swap_sym_in (cur_bfd,
2396 (ecoff_data (cur_bfd)->external_sym
2400 if (STREQ (ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss,
2403 /* We indicate that this is a GCC compilation so that certain
2404 features will be enabled in stabsread/dbxread. */
2405 processing_gcc_compilation = 2;
2409 if (processing_gcc_compilation != 0)
2411 struct pdr_ext *pdr_ptr;
2412 struct pdr_ext *pdr_end;
2414 unsigned long first_off;
2416 /* This symbol table contains stabs-in-ecoff entries. */
2418 /* Parse local symbols first */
2420 if (fh->csym <= 2) /* FIXME, this blows psymtab->symtab ptr */
2422 current_objfile = NULL;
2425 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
2431 ecoff_swap_sym_in (cur_bfd,
2432 (ecoff_data (cur_bfd)->external_sym
2436 name = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss;
2438 if (MIPS_IS_STAB (&sh))
2440 int type_code = MIPS_UNMARK_STAB (sh.index);
2441 process_one_symbol (type_code, 0, valu, name,
2442 pst->section_offsets, pst->objfile);
2443 if (type_code == N_FUN)
2445 /* Make up special symbol to contain
2446 procedure specific info */
2447 struct mips_extra_func_info *e =
2448 ((struct mips_extra_func_info *)
2449 obstack_alloc (¤t_objfile->symbol_obstack,
2450 sizeof (struct mips_extra_func_info)));
2451 struct symbol *s = new_symbol (MIPS_EFI_SYMBOL_NAME);
2452 SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
2453 SYMBOL_CLASS (s) = LOC_CONST;
2454 SYMBOL_TYPE (s) = builtin_type_void;
2455 SYMBOL_VALUE (s) = (int) e;
2456 add_symbol_to_list (s, &local_symbols);
2459 else if (sh.st == stLabel && sh.index != indexNil)
2461 /* Handle encoded stab line number. */
2462 record_line (current_subfile, sh.index, valu);
2464 else if (sh.st == stProc || sh.st == stStaticProc || sh.st == stEnd)
2465 /* These are generated by gcc-2.x, do not complain */
2468 complain (&stab_unknown_complaint, name);
2470 st = end_symtab (pst->texthigh, 0, 0, pst->objfile, SECT_OFF_TEXT);
2473 /* Sort the symbol table now, we are done adding symbols to it.
2474 We must do this before parse_procedure calls lookup_symbol. */
2475 sort_symtab_syms (st);
2477 /* This may not be necessary for stabs symtabs. FIXME. */
2480 /* Fill in procedure info next. */
2482 pdr_ptr = ecoff_data (cur_bfd)->external_pdr + fh->ipdFirst;
2483 pdr_end = pdr_ptr + fh->cpd;
2484 for (; pdr_ptr < pdr_end; pdr_ptr++)
2488 ecoff_swap_pdr_in (cur_bfd, pdr_ptr, &pr);
2494 parse_procedure (&pr, 1, first_off);
2499 /* This symbol table contains ordinary ecoff entries. */
2501 /* FIXME: doesn't use pst->section_offsets. */
2507 /* How many symbols will we need */
2508 /* FIXME, this does not count enum values. */
2509 f_max = pst->n_global_syms + pst->n_static_syms;
2513 st = new_symtab ("unknown", f_max, 0, pst->objfile);
2517 f_max += fh->csym + fh->cpd;
2518 maxlines = 2 * fh->cline;
2519 st = new_symtab (pst->filename, 2 * f_max, maxlines, pst->objfile);
2522 lines = LINETABLE (st);
2523 pending_list = PST_PRIVATE (pst)->pending_list;
2524 if (pending_list == 0)
2526 pending_list = ((struct mips_pending **)
2527 xzalloc (ecoff_data (cur_bfd)->symbolic_header.ifdMax
2528 * sizeof (struct mips_pending *)));
2529 PST_PRIVATE (pst)->pending_list = pending_list;
2532 /* Get a new lexical context */
2534 push_parse_stack ();
2535 top_stack->cur_st = st;
2536 top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (st),
2538 BLOCK_START (top_stack->cur_block) = fh ? fh->adr : 0;
2539 BLOCK_END (top_stack->cur_block) = 0;
2540 top_stack->blocktype = stFile;
2541 top_stack->maxsyms = 2 * f_max;
2542 top_stack->cur_type = 0;
2543 top_stack->procadr = 0;
2544 top_stack->numargs = 0;
2548 struct sym_ext *sym_ptr;
2549 struct sym_ext *sym_end;
2551 /* Parse local symbols first */
2552 sym_ptr = ecoff_data (cur_bfd)->external_sym + fh->isymBase;
2553 sym_end = sym_ptr + fh->csym;
2554 while (sym_ptr < sym_end)
2559 ecoff_swap_sym_in (cur_bfd, sym_ptr, &sh);
2560 c = parse_symbol (&sh,
2561 (ecoff_data (cur_bfd)->external_aux
2563 sym_ptr, fh->fBigendian);
2564 /* FIXME: We must swap the modified symbol back out,
2565 although we would rather not. See parse_symbol. */
2566 ecoff_swap_sym_out (cur_bfd, &sh, sym_ptr);
2570 /* Linenumbers. At the end, check if we can save memory.
2571 parse_lines has to look ahead an arbitrary number of PDR
2572 structures, so we swap them all first. */
2576 struct cleanup *old_chain;
2577 struct pdr_ext *pdr_ptr;
2578 struct pdr_ext *pdr_end;
2582 pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR));
2584 old_chain = make_cleanup (free, pr_block);
2586 pdr_ptr = ecoff_data (cur_bfd)->external_pdr + fh->ipdFirst;
2587 pdr_end = pdr_ptr + fh->cpd;
2589 for (; pdr_ptr < pdr_end; pdr_ptr++, pdr_in++)
2590 ecoff_swap_pdr_in (cur_bfd, pdr_ptr, pdr_in);
2592 parse_lines (fh, pr_block, lines);
2593 if (lines->nitems < fh->cline)
2594 lines = shrink_linetable (lines);
2596 /* Fill in procedure info next. */
2598 pdr_in_end = pdr_in + fh->cpd;
2599 for (; pdr_in < pdr_in_end; pdr_in++)
2600 parse_procedure (pdr_in, 0, pr_block->adr);
2602 do_cleanups (old_chain);
2606 LINETABLE (st) = lines;
2608 /* .. and our share of externals.
2609 XXX use the global list to speed up things here. how?
2610 FIXME, Maybe quit once we have found the right number of ext's? */
2611 top_stack->cur_st = st;
2612 top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
2614 top_stack->blocktype = stFile;
2615 top_stack->maxsyms = (ecoff_data (cur_bfd)->symbolic_header.isymMax
2616 + ecoff_data (cur_bfd)->symbolic_header.ipdMax
2617 + ecoff_data (cur_bfd)->symbolic_header.iextMax);
2619 ext_ptr = PST_PRIVATE (pst)->extern_tab;
2620 for (i = PST_PRIVATE (pst)->extern_count; --i >= 0; ext_ptr++)
2621 parse_external (ext_ptr, 1, fh->fBigendian);
2623 /* If there are undefined, tell the user */
2624 if (n_undef_symbols)
2626 printf_filtered ("File %s contains %d unresolved references:",
2627 st->filename, n_undef_symbols);
2628 printf_filtered ("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2629 n_undef_vars, n_undef_procs, n_undef_labels);
2630 n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
2635 /* Sort the symbol table now, we are done adding symbols to it.*/
2636 sort_symtab_syms (st);
2641 /* Now link the psymtab and the symtab. */
2644 current_objfile = NULL;
2647 /* Ancillary parsing procedures. */
2649 /* Lookup the type at relative index RN. Return it in TPP
2650 if found and in any event come up with its name PNAME.
2651 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
2652 Return value says how many aux symbols we ate. */
2655 cross_ref (ax, tpp, type_code, pname, bigend)
2658 enum type_code type_code; /* Use to alloc new type if none is found. */
2666 ecoff_swap_rndx_in (bigend, &ax->a_rndx, rn);
2668 /* Escape index means 'the next one' */
2669 if (rn->rfd == 0xfff)
2672 rf = AUX_GET_ISYM (bigend, ax + 1);
2682 *pname = "<undefined>";
2687 * Find the relative file descriptor and the symbol in it
2689 FDR *fh = get_rfd (cur_fd, rf);
2690 struct sym_ext *esh;
2694 /* If we have processed this symbol then we left a forwarding
2695 pointer to the corresponding GDB symbol. If not, we`ll put
2696 it in a list of pending symbols, to be processed later when
2697 the file will be. In any event, we collect the name for the
2698 type here. Which is why we made a first pass at strings. */
2700 esh = ecoff_data (cur_bfd)->external_sym + fh->isymBase + rn->index;
2701 ecoff_swap_sym_in (cur_bfd, esh, &sh);
2703 /* Careful, we might be looking at .o files */
2705 *pname = "<undefined>";
2707 *pname = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss;
2709 /* Have we parsed it ? */
2710 if (sh.value != 0 && sh.st == stParsed)
2712 t = (struct type *) sh.value;
2717 /* Avoid duplicates */
2718 struct mips_pending *p = is_pending_symbol (fh, esh);
2723 *tpp = init_type (type_code, 0, 0, (char *) NULL,
2724 (struct objfile *) NULL);
2725 add_pending (fh, esh, *tpp);
2730 /* We used one auxent normally, two if we got a "next one" rf. */
2735 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2736 keeping the symtab sorted */
2738 static struct symbol *
2739 mylookup_symbol (name, block, namespace, class)
2741 register struct block *block;
2742 enum namespace namespace;
2743 enum address_class class;
2745 register int bot, top, inc;
2746 register struct symbol *sym;
2749 top = BLOCK_NSYMS (block);
2753 sym = BLOCK_SYM (block, bot);
2754 if (SYMBOL_NAME (sym)[0] == inc
2755 && SYMBOL_NAMESPACE (sym) == namespace
2756 && SYMBOL_CLASS (sym) == class
2757 && STREQ (SYMBOL_NAME (sym), name))
2761 block = BLOCK_SUPERBLOCK (block);
2763 return mylookup_symbol (name, block, namespace, class);
2768 /* Add a new symbol S to a block B.
2769 Infrequently, we will need to reallocate the block to make it bigger.
2770 We only detect this case when adding to top_stack->cur_block, since
2771 that's the only time we know how big the block is. FIXME. */
2778 int nsyms = BLOCK_NSYMS (b)++;
2779 struct block *origb;
2780 struct parse_stack *stackp;
2782 if (b == top_stack->cur_block &&
2783 nsyms >= top_stack->maxsyms)
2785 complain (&block_overflow_complaint, SYMBOL_NAME (s));
2786 /* In this case shrink_block is actually grow_block, since
2787 BLOCK_NSYMS(b) is larger than its current size. */
2789 b = shrink_block (top_stack->cur_block, top_stack->cur_st);
2791 /* Now run through the stack replacing pointers to the
2792 original block. shrink_block has already done this
2793 for the blockvector and BLOCK_FUNCTION. */
2794 for (stackp = top_stack; stackp; stackp = stackp->next)
2796 if (stackp->cur_block == origb)
2798 stackp->cur_block = b;
2799 stackp->maxsyms = BLOCK_NSYMS (b);
2803 BLOCK_SYM (b, nsyms) = s;
2806 /* Add a new block B to a symtab S */
2813 struct blockvector *bv = BLOCKVECTOR (s);
2815 bv = (struct blockvector *) xrealloc ((PTR) bv,
2816 (sizeof (struct blockvector)
2817 + BLOCKVECTOR_NBLOCKS (bv)
2818 * sizeof (bv->block)));
2819 if (bv != BLOCKVECTOR (s))
2820 BLOCKVECTOR (s) = bv;
2822 BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)++) = b;
2825 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2826 MIPS' linenumber encoding might need more than one byte
2827 to describe it, LAST is used to detect these continuation lines */
2830 add_line (lt, lineno, adr, last)
2831 struct linetable *lt;
2837 last = -2; /* make sure we record first line */
2839 if (last == lineno) /* skip continuation lines */
2842 lt->item[lt->nitems].line = lineno;
2843 lt->item[lt->nitems++].pc = adr << 2;
2847 /* Sorting and reordering procedures */
2849 /* Blocks with a smaller low bound should come first */
2852 compare_blocks (arg1, arg2)
2853 const void *arg1, *arg2;
2855 register int addr_diff;
2856 struct block **b1 = (struct block **) arg1;
2857 struct block **b2 = (struct block **) arg2;
2859 addr_diff = (BLOCK_START ((*b1))) - (BLOCK_START ((*b2)));
2861 return (BLOCK_END ((*b2))) - (BLOCK_END ((*b1)));
2865 /* Sort the blocks of a symtab S.
2866 Reorder the blocks in the blockvector by code-address,
2867 as required by some MI search routines */
2873 struct blockvector *bv = BLOCKVECTOR (s);
2875 if (BLOCKVECTOR_NBLOCKS (bv) <= 2)
2878 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) == 0)
2879 BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = 0;
2880 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) == 0)
2881 BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = 0;
2885 * This is very unfortunate: normally all functions are compiled in
2886 * the order they are found, but if the file is compiled -O3 things
2887 * are very different. It would be nice to find a reliable test
2888 * to detect -O3 images in advance.
2890 if (BLOCKVECTOR_NBLOCKS (bv) > 3)
2891 qsort (&BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK),
2892 BLOCKVECTOR_NBLOCKS (bv) - FIRST_LOCAL_BLOCK,
2893 sizeof (struct block *),
2897 register CORE_ADDR high = 0;
2898 register int i, j = BLOCKVECTOR_NBLOCKS (bv);
2900 for (i = FIRST_LOCAL_BLOCK; i < j; i++)
2901 if (high < BLOCK_END (BLOCKVECTOR_BLOCK (bv, i)))
2902 high = BLOCK_END (BLOCKVECTOR_BLOCK (bv, i));
2903 BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = high;
2906 BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) =
2907 BLOCK_START (BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK));
2909 BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
2910 BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
2911 BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
2912 BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
2916 /* Constructor/restructor/destructor procedures */
2918 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2919 MAXSYMS and linenumbers MAXLINES we'll put in it */
2921 static struct symtab *
2922 new_symtab (name, maxsyms, maxlines, objfile)
2926 struct objfile *objfile;
2928 struct symtab *s = allocate_symtab (name, objfile);
2930 LINETABLE (s) = new_linetable (maxlines);
2932 /* All symtabs must have at least two blocks */
2933 BLOCKVECTOR (s) = new_bvect (2);
2934 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK) = new_block (maxsyms);
2935 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK) = new_block (maxsyms);
2936 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)) =
2937 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
2939 s->free_code = free_linetable;
2944 /* Allocate a new partial_symtab NAME */
2946 static struct partial_symtab *
2947 new_psymtab (name, objfile)
2949 struct objfile *objfile;
2951 struct partial_symtab *psymtab;
2953 psymtab = allocate_psymtab (name, objfile);
2955 /* Keep a backpointer to the file's symbols */
2957 psymtab->read_symtab_private = ((char *)
2958 obstack_alloc (&objfile->psymbol_obstack,
2959 sizeof (struct symloc)));
2960 memset ((PTR) psymtab->read_symtab_private, 0, sizeof (struct symloc));
2961 CUR_BFD (psymtab) = cur_bfd;
2963 /* The way to turn this into a symtab is to call... */
2964 psymtab->read_symtab = mipscoff_psymtab_to_symtab;
2969 /* Allocate a linetable array of the given SIZE. Since the struct
2970 already includes one item, we subtract one when calculating the
2971 proper size to allocate. */
2973 static struct linetable *
2974 new_linetable (size)
2977 struct linetable *l;
2979 size = (size - 1) * sizeof (l->item) + sizeof (struct linetable);
2980 l = (struct linetable *) xmalloc (size);
2985 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2986 I am not so sure about the 3.4 ones.
2988 Since the struct linetable already includes one item, we subtract one when
2989 calculating the proper size to allocate. */
2991 static struct linetable *
2992 shrink_linetable (lt)
2993 struct linetable *lt;
2996 return (struct linetable *) xrealloc ((PTR) lt,
2997 (sizeof (struct linetable)
2999 * sizeof (lt->item))));
3002 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
3004 static struct blockvector *
3008 struct blockvector *bv;
3011 size = sizeof (struct blockvector) + nblocks * sizeof (struct block *);
3012 bv = (struct blockvector *) xzalloc (size);
3014 BLOCKVECTOR_NBLOCKS (bv) = nblocks;
3019 /* Allocate and zero a new block of MAXSYMS symbols */
3021 static struct block *
3025 int size = sizeof (struct block) + (maxsyms - 1) * sizeof (struct symbol *);
3027 return (struct block *) xzalloc (size);
3030 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
3031 Shrink_block can also be used by add_symbol to grow a block. */
3033 static struct block *
3039 struct blockvector *bv = BLOCKVECTOR (s);
3042 /* Just reallocate it and fix references to the old one */
3044 new = (struct block *) xrealloc ((PTR) b,
3045 (sizeof (struct block)
3046 + ((BLOCK_NSYMS (b) - 1)
3047 * sizeof (struct symbol *))));
3049 /* Should chase pointers to old one. Fortunately, that`s just
3050 the block`s function and inferior blocks */
3051 if (BLOCK_FUNCTION (new) && SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) == b)
3052 SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) = new;
3053 for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
3054 if (BLOCKVECTOR_BLOCK (bv, i) == b)
3055 BLOCKVECTOR_BLOCK (bv, i) = new;
3056 else if (BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) == b)
3057 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) = new;
3061 /* Create a new symbol with printname NAME */
3063 static struct symbol *
3067 struct symbol *s = ((struct symbol *)
3068 obstack_alloc (¤t_objfile->symbol_obstack,
3069 sizeof (struct symbol)));
3071 memset ((PTR) s, 0, sizeof (*s));
3072 SYMBOL_NAME (s) = name;
3076 /* Create a new type with printname NAME */
3078 static struct type *
3084 t = alloc_type (current_objfile);
3085 TYPE_NAME (t) = name;
3086 TYPE_CPLUS_SPECIFIC (t) = (struct cplus_struct_type *) &cplus_struct_default;
3091 /* Things used for calling functions in the inferior.
3092 These functions are exported to our companion
3093 mips-tdep.c file and are here because they play
3094 with the symbol-table explicitly. */
3096 /* Sigtramp: make sure we have all the necessary information
3097 about the signal trampoline code. Since the official code
3098 from MIPS does not do so, we make up that information ourselves.
3099 If they fix the library (unlikely) this code will neutralize itself. */
3106 struct block *b, *b0;
3108 sigtramp_address = -1;
3110 /* We know it is sold as sigvec */
3111 s = lookup_symbol ("sigvec", 0, VAR_NAMESPACE, 0, NULL);
3113 /* Most programs do not play with signals */
3115 s = lookup_symbol ("_sigtramp", 0, VAR_NAMESPACE, 0, NULL);
3118 b0 = SYMBOL_BLOCK_VALUE (s);
3120 /* A label of sigvec, to be more precise */
3121 s = lookup_symbol ("sigtramp", b0, VAR_NAMESPACE, 0, NULL);
3124 /* But maybe this program uses its own version of sigvec */
3128 /* Did we or MIPSco fix the library ? */
3129 if (SYMBOL_CLASS (s) == LOC_BLOCK)
3131 sigtramp_address = BLOCK_START (SYMBOL_BLOCK_VALUE (s));
3132 sigtramp_end = BLOCK_END (SYMBOL_BLOCK_VALUE (s));
3136 sigtramp_address = SYMBOL_VALUE (s);
3137 sigtramp_end = sigtramp_address + 0x88; /* black magic */
3139 /* But what symtab does it live in ? */
3140 st = find_pc_symtab (SYMBOL_VALUE (s));
3143 * Ok, there goes the fix: turn it into a procedure, with all the
3144 * needed info. Note we make it a nested procedure of sigvec,
3145 * which is the way the (assembly) code is actually written.
3147 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
3148 SYMBOL_CLASS (s) = LOC_BLOCK;
3149 SYMBOL_TYPE (s) = init_type (TYPE_CODE_FUNC, 4, 0, (char *) NULL,
3150 (struct objfile *) NULL);
3151 TYPE_TARGET_TYPE (SYMBOL_TYPE (s)) = builtin_type_void;
3153 /* Need a block to allocate MIPS_EFI_SYMBOL_NAME in */
3155 SYMBOL_BLOCK_VALUE (s) = b;
3156 BLOCK_START (b) = sigtramp_address;
3157 BLOCK_END (b) = sigtramp_end;
3158 BLOCK_FUNCTION (b) = s;
3159 BLOCK_SUPERBLOCK (b) = BLOCK_SUPERBLOCK (b0);
3163 /* Make a MIPS_EFI_SYMBOL_NAME entry for it */
3165 struct mips_extra_func_info *e =
3166 ((struct mips_extra_func_info *)
3167 xzalloc (sizeof (struct mips_extra_func_info)));
3169 e->numargs = 0; /* the kernel thinks otherwise */
3170 /* align_longword(sigcontext + SIGFRAME) */
3171 e->pdr.frameoffset = 0x150;
3172 e->pdr.framereg = SP_REGNUM;
3174 e->pdr.regmask = -2;
3175 e->pdr.regoffset = -(41 * sizeof (int));
3176 e->pdr.fregmask = -1;
3177 e->pdr.fregoffset = -(37 * sizeof (int));
3178 e->pdr.isym = (long) s;
3180 current_objfile = st->objfile; /* Keep new_symbol happy */
3181 s = new_symbol (MIPS_EFI_SYMBOL_NAME);
3182 SYMBOL_VALUE (s) = (int) e;
3183 SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
3184 SYMBOL_CLASS (s) = LOC_CONST;
3185 SYMBOL_TYPE (s) = builtin_type_void;
3186 current_objfile = NULL;
3189 BLOCK_SYM (b, BLOCK_NSYMS (b)++) = s;
3193 /* Fake up identical offsets for all sections. */
3195 struct section_offsets *
3196 mipscoff_symfile_offsets (objfile, addr)
3197 struct objfile *objfile;
3200 struct section_offsets *section_offsets;
3203 section_offsets = ((struct section_offsets *)
3204 obstack_alloc (&objfile->psymbol_obstack,
3205 (sizeof (struct section_offsets)
3206 + (sizeof (section_offsets->offsets)
3207 * (SECT_OFF_MAX - 1)))));
3209 for (i = 0; i < SECT_OFF_MAX; i++)
3210 ANOFFSET (section_offsets, i) = addr;
3212 return section_offsets;
3215 /* Initialization */
3217 static struct sym_fns ecoff_sym_fns =
3219 "ecoff", /* sym_name: name or name prefix of BFD target type */
3220 5, /* sym_namelen: number of significant sym_name chars */
3221 mipscoff_new_init, /* sym_new_init: init anything gbl to entire symtab */
3222 mipscoff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
3223 mipscoff_symfile_read, /* sym_read: read a symbol file into symtab */
3224 mipscoff_symfile_finish, /* sym_finish: finished with file, cleanup */
3225 mipscoff_symfile_offsets, /* sym_offsets: dummy FIXME til implem sym reloc */
3226 NULL /* next: pointer to next struct sym_fns */
3231 _initialize_mipsread ()
3233 add_symtab_fns (&ecoff_sym_fns);
3235 /* Missing basic types */
3237 builtin_type_string =
3238 init_type (TYPE_CODE_STRING,
3239 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
3241 (struct objfile *) NULL);
3242 builtin_type_complex =
3243 init_type (TYPE_CODE_FLT,
3244 TARGET_COMPLEX_BIT / TARGET_CHAR_BIT,
3246 (struct objfile *) NULL);
3247 builtin_type_double_complex =
3248 init_type (TYPE_CODE_FLT,
3249 TARGET_DOUBLE_COMPLEX_BIT / TARGET_CHAR_BIT,
3250 0, "double complex",
3251 (struct objfile *) NULL);
3252 builtin_type_fixed_dec =
3253 init_type (TYPE_CODE_INT,
3254 TARGET_INT_BIT / TARGET_CHAR_BIT,
3256 (struct objfile *) NULL);
3257 builtin_type_float_dec =
3258 init_type (TYPE_CODE_FLT,
3259 TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
3260 0, "floating decimal",
3261 (struct objfile *) NULL);