1 /* Read a symbol table in MIPS' format (Third-Eye).
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993 Free Software
4 Contributed by Alessandro Forin (af@cs.cmu.edu) at CMU. Major work
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
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
;
336 mipscoff_symfile_init (objfile
)
337 struct objfile
*objfile
;
339 if (objfile
->sym_private
!= NULL
)
341 mfree (objfile
->md
, objfile
->sym_private
);
343 objfile
->sym_private
= NULL
;
347 mipscoff_symfile_read (objfile
, section_offsets
, mainline
)
348 struct objfile
*objfile
;
349 struct section_offsets
*section_offsets
;
352 init_minimal_symbol_collection ();
353 make_cleanup (discard_minimal_symbols
, 0);
355 /* Now that the executable file is positioned at symbol table,
356 process it and define symbols accordingly. */
358 read_mips_symtab (objfile
, section_offsets
);
360 /* Install any minimal symbols that have been collected as the current
361 minimal symbols for this objfile. */
363 install_minimal_symbols (objfile
);
366 /* Perform any local cleanups required when we are done with a particular
367 objfile. I.E, we are in the process of discarding all symbol information
368 for an objfile, freeing up all memory held for it, and unlinking the
369 objfile struct from the global list of known objfiles. */
372 mipscoff_symfile_finish (objfile
)
373 struct objfile
*objfile
;
375 if (objfile
->sym_private
!= NULL
)
377 mfree (objfile
->md
, objfile
->sym_private
);
383 /* Allocate zeroed memory */
389 PTR p
= xmalloc (size
);
395 /* Exported procedure: Builds a symtab from the PST partial one.
396 Restores the environment in effect when PST was created, delegates
397 most of the work to an ancillary procedure, and sorts
398 and reorders the symtab list at the end */
401 mipscoff_psymtab_to_symtab (pst
)
402 struct partial_symtab
*pst
;
410 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
413 /* Get the BFD and list of pending typedefs */
414 cur_bfd
= CUR_BFD (pst
);
416 next_symbol_text_func
= mips_next_symbol_text
;
418 psymtab_to_symtab_1 (pst
, pst
->filename
);
420 /* Match with global symbols. This only needs to be done once,
421 after all of the symtabs and dependencies have been read in. */
422 scan_file_globals (pst
->objfile
);
425 printf_filtered ("done.\n");
428 /* Exported procedure: Is PC in the signal trampoline code */
431 in_sigtramp (pc
, ignore
)
433 char *ignore
; /* function name */
435 if (sigtramp_address
== 0)
437 return (pc
>= sigtramp_address
&& pc
< sigtramp_end
);
440 /* File-level interface functions */
442 /* Read the symtab information from file ABFD into memory. */
445 read_the_mips_symtab (abfd
)
448 if (ecoff_slurp_symbolic_info (abfd
) == false)
449 error ("Error reading symbol table: %s", bfd_errmsg (bfd_error
));
452 /* Find a file descriptor given its index RF relative to a file CF */
462 fdrs
= ecoff_data (cur_bfd
)->fdr
;
464 /* Object files do not have the RFD table, all refs are absolute */
467 ecoff_swap_rfd_in (cur_bfd
,
468 ecoff_data (cur_bfd
)->external_rfd
+ f
->rfdBase
+ rf
,
473 /* Return a safer print NAME for a file descriptor */
480 return "<stripped file>";
483 return ecoff_data (cur_bfd
)->ss
+ f
->issBase
+ f
->rss
;
487 /* Read in and parse the symtab of the file OBJFILE. Symbols from
488 different sections are relocated via the SECTION_OFFSETS. */
491 read_mips_symtab (objfile
, section_offsets
)
492 struct objfile
*objfile
;
493 struct section_offsets
*section_offsets
;
495 cur_bfd
= objfile
->obfd
;
497 read_the_mips_symtab (objfile
->obfd
);
499 parse_partial_symbols (objfile
, section_offsets
);
502 /* Check to make sure file was compiled with -g. If not, warn the
503 user of this limitation. */
504 if (compare_glevel (max_glevel
, GLEVEL_2
) < 0)
506 if (max_gdbinfo
== 0)
507 printf ("\n%s not compiled with -g, debugging support is limited.\n",
509 printf ("You should compile with -g2 or -g3 for best debugging support.\n");
515 /* Local utilities */
517 /* Map of FDR indexes to partial symtabs */
521 struct partial_symtab
*pst
; /* the psymtab proper */
522 int n_globals
; /* exported globals (external symbols) */
523 int globals_offset
; /* cumulative */
527 /* Utility stack, used to nest procedures and blocks properly.
528 It is a doubly linked list, to avoid too many alloc/free.
529 Since we might need it quite a few times it is NOT deallocated
532 static struct parse_stack
534 struct parse_stack
*next
, *prev
;
535 struct symtab
*cur_st
; /* Current symtab. */
536 struct block
*cur_block
; /* Block in it. */
537 int blocktype
; /* What are we parsing. */
538 int maxsyms
; /* Max symbols in this block. */
539 struct type
*cur_type
; /* Type we parse fields for. */
540 int cur_field
; /* Field number in cur_type. */
541 int procadr
; /* Start addres of this procedure */
542 int numargs
; /* Its argument count */
545 *top_stack
; /* Top stack ptr */
548 /* Enter a new lexical context */
553 struct parse_stack
*new;
555 /* Reuse frames if possible */
556 if (top_stack
&& top_stack
->prev
)
557 new = top_stack
->prev
;
559 new = (struct parse_stack
*) xzalloc (sizeof (struct parse_stack
));
560 /* Initialize new frame with previous content */
563 register struct parse_stack
*prev
= new->prev
;
566 top_stack
->prev
= new;
568 new->next
= top_stack
;
573 /* Exit a lexical context */
581 top_stack
= top_stack
->next
;
585 /* Cross-references might be to things we haven't looked at
586 yet, e.g. type references. To avoid too many type
587 duplications we keep a quick fixup table, an array
588 of lists of references indexed by file descriptor */
590 static struct mips_pending
592 struct mips_pending
*next
; /* link */
593 struct sym_ext
*s
; /* the symbol */
594 struct type
*t
; /* its partial type descriptor */
598 /* Check whether we already saw symbol SH in file FH as undefined */
600 static struct mips_pending
*
601 is_pending_symbol (fh
, sh
)
605 int f_idx
= fh
- ecoff_data (cur_bfd
)->fdr
;
606 register struct mips_pending
*p
;
608 /* Linear search is ok, list is typically no more than 10 deep */
609 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
615 /* Add a new undef symbol SH of type T */
618 add_pending (fh
, sh
, t
)
623 int f_idx
= fh
- ecoff_data (cur_bfd
)->fdr
;
624 struct mips_pending
*p
= is_pending_symbol (fh
, sh
);
626 /* Make sure we do not make duplicates */
629 p
= (struct mips_pending
*) xmalloc (sizeof (*p
));
632 p
->next
= pending_list
[f_idx
];
633 pending_list
[f_idx
] = p
;
637 /* Throw away undef entries when done with file index F_IDX */
638 /* FIXME -- storage leak. This is never called!!! --gnu */
646 register struct mips_pending
*p
, *q
;
648 for (p
= pending_list
[f_idx
]; p
; p
= q
)
653 pending_list
[f_idx
] = 0;
659 prepend_tag_kind (tag_name
, type_code
)
661 enum type_code type_code
;
670 case TYPE_CODE_STRUCT
:
673 case TYPE_CODE_UNION
:
680 result
= (char *) obstack_alloc (¤t_objfile
->symbol_obstack
,
681 strlen (prefix
) + strlen (tag_name
) + 1);
682 sprintf (result
, "%s%s", prefix
, tag_name
);
687 /* Parsing Routines proper. */
689 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
690 For blocks, procedures and types we open a new lexical context.
691 This is basically just a big switch on the symbol's type. Argument
692 AX is the base pointer of aux symbols for this file (fh->iauxBase).
693 EXT_SH points to the unswapped symbol, which is needed for struct,
694 union, etc., types; it is NULL for an EXTR. BIGEND says whether
695 aux symbols are big-endian or little-endian. Return count of
696 SYMR's handled (normally one).
698 FIXME: This modifies the symbol, but the only way we have to save
699 the modified information is to stuff it back into the BFD data. */
702 parse_symbol (sh
, ax
, ext_sh
, bigend
)
705 struct sym_ext
*ext_sh
;
711 struct mips_pending
*pend
;
715 enum address_class
class;
718 if (ext_sh
== (struct sym_ext
*) NULL
)
719 name
= ecoff_data (cur_bfd
)->ssext
+ sh
->iss
;
721 name
= ecoff_data (cur_bfd
)->ss
+ cur_fdr
->issBase
+ sh
->iss
;
728 case stGlobal
: /* external symbol, goes into global block */
730 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack
->cur_st
),
732 s
= new_symbol (name
);
733 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
736 case stStatic
: /* static data, goes into current block. */
738 b
= top_stack
->cur_block
;
739 s
= new_symbol (name
);
740 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
743 case stLocal
: /* local variable, goes into current block */
744 if (sh
->sc
== scRegister
)
746 class = LOC_REGISTER
;
748 sh
->value
+= FP0_REGNUM
- 32;
752 b
= top_stack
->cur_block
;
753 s
= new_symbol (name
);
754 SYMBOL_VALUE (s
) = sh
->value
;
756 data
: /* Common code for symbols describing data */
757 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
758 SYMBOL_CLASS (s
) = class;
761 /* Type could be missing in a number of cases */
762 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
763 sh
->index
== 0xfffff)
764 SYMBOL_TYPE (s
) = builtin_type_int
; /* undefined? */
766 SYMBOL_TYPE (s
) = parse_type (ax
+ sh
->index
, 0, bigend
);
767 /* Value of a data symbol is its memory address */
770 case stParam
: /* arg to procedure, goes into current block */
772 top_stack
->numargs
++;
774 /* Special GNU C++ name. */
775 if (name
[0] == CPLUS_MARKER
&& name
[1] == 't' && name
[2] == 0)
776 name
= "this"; /* FIXME, not alloc'd in obstack */
777 s
= new_symbol (name
);
779 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
780 if (sh
->sc
== scRegister
)
782 SYMBOL_CLASS (s
) = LOC_REGPARM
;
784 sh
->value
+= FP0_REGNUM
- 32;
787 SYMBOL_CLASS (s
) = LOC_ARG
;
788 SYMBOL_VALUE (s
) = sh
->value
;
789 SYMBOL_TYPE (s
) = parse_type (ax
+ sh
->index
, 0, bigend
);
790 add_symbol (s
, top_stack
->cur_block
);
792 /* FIXME: This has not been tested. See dbxread.c */
793 /* Add the type of this parameter to the function/procedure
794 type of this block. */
795 add_param_to_type (&top_stack
->cur_block
->function
->type
, s
);
799 case stLabel
: /* label, goes into current block */
800 s
= new_symbol (name
);
801 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
; /* so that it can be used */
802 SYMBOL_CLASS (s
) = LOC_LABEL
; /* but not misused */
803 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
804 SYMBOL_TYPE (s
) = builtin_type_int
;
805 add_symbol (s
, top_stack
->cur_block
);
808 case stProc
: /* Procedure, usually goes into global block */
809 case stStaticProc
: /* Static procedure, goes into current block */
810 s
= new_symbol (name
);
811 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
812 SYMBOL_CLASS (s
) = LOC_BLOCK
;
813 /* Type of the return value */
814 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
815 t
= builtin_type_int
;
817 t
= parse_type (ax
+ sh
->index
+ 1, 0, bigend
);
818 b
= top_stack
->cur_block
;
819 if (sh
->st
== stProc
)
821 struct blockvector
*bv
= BLOCKVECTOR (top_stack
->cur_st
);
822 /* The next test should normally be true,
823 but provides a hook for nested functions
824 (which we don't want to make global). */
825 if (b
== BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
))
826 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
830 /* Make a type for the procedure itself */
832 /* FIXME: This has not been tested yet! See dbxread.c */
833 /* Generate a template for the type of this function. The
834 types of the arguments will be added as we read the symbol
836 bcopy (SYMBOL_TYPE (s
), lookup_function_type (t
), sizeof (struct type
));
838 SYMBOL_TYPE (s
) = lookup_function_type (t
);
841 /* Create and enter a new lexical context */
842 b
= new_block (top_stack
->maxsyms
);
843 SYMBOL_BLOCK_VALUE (s
) = b
;
844 BLOCK_FUNCTION (b
) = s
;
845 BLOCK_START (b
) = BLOCK_END (b
) = sh
->value
;
846 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
847 add_block (b
, top_stack
->cur_st
);
849 /* Not if we only have partial info */
850 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
854 top_stack
->cur_block
= b
;
855 top_stack
->blocktype
= sh
->st
;
856 top_stack
->cur_type
= SYMBOL_TYPE (s
);
857 top_stack
->cur_field
= -1;
858 top_stack
->procadr
= sh
->value
;
859 top_stack
->numargs
= 0;
861 sh
->value
= (long) SYMBOL_TYPE (s
);
864 /* Beginning of code for structure, union, and enum definitions.
865 They all share a common set of local variables, defined here. */
867 enum type_code type_code
;
868 struct sym_ext
*ext_tsym
;
873 case stStruct
: /* Start a block defining a struct type */
874 type_code
= TYPE_CODE_STRUCT
;
875 goto structured_common
;
877 case stUnion
: /* Start a block defining a union type */
878 type_code
= TYPE_CODE_UNION
;
879 goto structured_common
;
881 case stEnum
: /* Start a block defining an enum type */
882 type_code
= TYPE_CODE_ENUM
;
883 goto structured_common
;
885 case stBlock
: /* Either a lexical block, or some type */
886 if (sh
->sc
!= scInfo
)
887 goto case_stBlock_code
; /* Lexical block */
889 type_code
= TYPE_CODE_UNDEF
; /* We have a type. */
891 /* Common code for handling struct, union, enum, and/or as-yet-
892 unknown-type blocks of info about structured data. `type_code'
893 has been set to the proper TYPE_CODE, if we know it. */
896 top_stack
->blocktype
= stBlock
;
898 s
= new_symbol (name
);
899 SYMBOL_NAMESPACE (s
) = STRUCT_NAMESPACE
;
900 SYMBOL_CLASS (s
) = LOC_TYPEDEF
;
901 SYMBOL_VALUE (s
) = 0;
902 add_symbol (s
, top_stack
->cur_block
);
904 /* First count the number of fields and the highest value. */
907 for (ext_tsym
= ext_sh
+ 1; ; ext_tsym
++)
911 ecoff_swap_sym_in (cur_bfd
, ext_tsym
, &tsym
);
913 if (tsym
.st
== stEnd
)
916 if (tsym
.st
== stMember
)
918 if (nfields
== 0 && type_code
== TYPE_CODE_UNDEF
)
919 /* If the type of the member is Nil (or Void),
920 without qualifiers, assume the tag is an
922 if (tsym
.index
== indexNil
)
923 type_code
= TYPE_CODE_ENUM
;
926 ecoff_swap_tir_in (bigend
,
927 &ax
[tsym
.index
].a_ti
,
929 if ((tir
.bt
== btNil
|| tir
.bt
== btVoid
)
931 type_code
= TYPE_CODE_ENUM
;
934 if (tsym
.value
> max_value
)
935 max_value
= tsym
.value
;
937 else if (tsym
.st
== stBlock
938 || tsym
.st
== stUnion
940 || tsym
.st
== stStruct
941 || tsym
.st
== stParsed
)
943 if (tsym
.sc
== scVariant
); /*UNIMPLEMENTED*/
946 /* This is something like a struct within a
947 struct. Skip over the fields of the inner
948 struct. The -1 is because the for loop will
949 increment ext_tsym. */
950 ext_tsym
= (ecoff_data (cur_bfd
)->external_sym
957 complain (&block_member_complaint
, tsym
.st
);
960 /* In an stBlock, there is no way to distinguish structs,
961 unions, and enums at this point. This is a bug in the
962 original design (that has been fixed with the recent
963 addition of the stStruct, stUnion, and stEnum symbol
964 types.) The way you can tell is if/when you see a variable
965 or field of that type. In that case the variable's type
966 (in the AUX table) says if the type is struct, union, or
967 enum, and points back to the stBlock here. So you can
968 patch the tag kind up later - but only if there actually is
969 a variable or field of that type.
971 So until we know for sure, we will guess at this point.
973 If the first member has index==indexNil or a void type,
974 assume we have an enumeration.
975 Otherwise, if there is more than one member, and all
976 the members have offset 0, assume we have a union.
977 Otherwise, assume we have a struct.
979 The heuristic could guess wrong in the case of of an
980 enumeration with no members or a union with one (or zero)
981 members, or when all except the last field of a struct have
982 width zero. These are uncommon and/or illegal situations,
983 and in any case guessing wrong probably doesn't matter
986 But if we later do find out we were wrong, we fixup the tag
987 kind. Members of an enumeration must be handled
988 differently from struct/union fields, and that is harder to
989 patch up, but luckily we shouldn't need to. (If there are
990 any enumeration members, we can tell for sure it's an enum
993 if (type_code
== TYPE_CODE_UNDEF
)
994 if (nfields
> 1 && max_value
== 0)
995 type_code
= TYPE_CODE_UNION
;
997 type_code
= TYPE_CODE_STRUCT
;
999 /* If this type was expected, use its partial definition */
1000 pend
= is_pending_symbol (cur_fdr
, ext_sh
);
1001 if (pend
!= (struct mips_pending
*) NULL
)
1004 t
= new_type (prepend_tag_kind (name
, type_code
));
1006 TYPE_CODE (t
) = type_code
;
1007 TYPE_LENGTH (t
) = sh
->value
;
1008 TYPE_NFIELDS (t
) = nfields
;
1009 TYPE_FIELDS (t
) = f
= ((struct field
*)
1011 nfields
* sizeof (struct field
)));
1013 if (type_code
== TYPE_CODE_ENUM
)
1015 /* This is a non-empty enum. */
1016 for (ext_tsym
= ext_sh
+ 1; ; ext_tsym
++)
1019 struct symbol
*enum_sym
;
1021 ecoff_swap_sym_in (cur_bfd
, ext_tsym
, &tsym
);
1023 if (tsym
.st
!= stMember
)
1026 f
->bitpos
= tsym
.value
;
1028 f
->name
= (ecoff_data (cur_bfd
)->ss
1033 enum_sym
= ((struct symbol
*)
1034 obstack_alloc (¤t_objfile
->symbol_obstack
,
1035 sizeof (struct symbol
)));
1036 memset ((PTR
) enum_sym
, 0, sizeof (struct symbol
));
1037 SYMBOL_NAME (enum_sym
) = f
->name
;
1038 SYMBOL_CLASS (enum_sym
) = LOC_CONST
;
1039 SYMBOL_TYPE (enum_sym
) = t
;
1040 SYMBOL_NAMESPACE (enum_sym
) = VAR_NAMESPACE
;
1041 SYMBOL_VALUE (enum_sym
) = tsym
.value
;
1042 add_symbol (enum_sym
, top_stack
->cur_block
);
1044 /* Skip the stMembers that we've handled. */
1049 SYMBOL_TYPE (s
) = t
;
1050 /* make this the current type */
1051 top_stack
->cur_type
= t
;
1052 top_stack
->cur_field
= 0;
1053 /* Mark that symbol has a type, and say which one */
1054 sh
->value
= (long) t
;
1057 /* End of local variables shared by struct, union, enum, and
1058 block (as yet unknown struct/union/enum) processing. */
1062 /* beginnning of (code) block. Value of symbol
1063 is the displacement from procedure start */
1064 push_parse_stack ();
1065 top_stack
->blocktype
= stBlock
;
1066 b
= new_block (top_stack
->maxsyms
);
1067 BLOCK_START (b
) = sh
->value
+ top_stack
->procadr
;
1068 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
1069 top_stack
->cur_block
= b
;
1070 add_block (b
, top_stack
->cur_st
);
1073 case stEnd
: /* end (of anything) */
1074 if (sh
->sc
== scInfo
)
1076 /* Finished with type */
1077 top_stack
->cur_type
= 0;
1079 else if (sh
->sc
== scText
&&
1080 (top_stack
->blocktype
== stProc
||
1081 top_stack
->blocktype
== stStaticProc
))
1083 /* Finished with procedure */
1084 struct blockvector
*bv
= BLOCKVECTOR (top_stack
->cur_st
);
1085 struct mips_extra_func_info
*e
;
1089 BLOCK_END (top_stack
->cur_block
) += sh
->value
; /* size */
1091 /* Make up special symbol to contain procedure specific info */
1092 s
= new_symbol (MIPS_EFI_SYMBOL_NAME
);
1093 SYMBOL_NAMESPACE (s
) = LABEL_NAMESPACE
;
1094 SYMBOL_CLASS (s
) = LOC_CONST
;
1095 SYMBOL_TYPE (s
) = builtin_type_void
;
1096 e
= ((struct mips_extra_func_info
*)
1097 obstack_alloc (¤t_objfile
->symbol_obstack
,
1098 sizeof (struct mips_extra_func_info
)));
1099 SYMBOL_VALUE (s
) = (int) e
;
1100 e
->numargs
= top_stack
->numargs
;
1101 add_symbol (s
, top_stack
->cur_block
);
1103 /* Reallocate symbols, saving memory */
1104 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
1106 /* f77 emits proc-level with address bounds==[0,0],
1107 So look for such child blocks, and patch them. */
1108 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS (bv
); i
++)
1110 struct block
*b_bad
= BLOCKVECTOR_BLOCK (bv
, i
);
1111 if (BLOCK_SUPERBLOCK (b_bad
) == b
1112 && BLOCK_START (b_bad
) == top_stack
->procadr
1113 && BLOCK_END (b_bad
) == top_stack
->procadr
)
1115 BLOCK_START (b_bad
) = BLOCK_START (b
);
1116 BLOCK_END (b_bad
) = BLOCK_END (b
);
1120 else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
)
1122 /* End of (code) block. The value of the symbol is the
1123 displacement from the procedure`s start address of the
1124 end of this block. */
1125 BLOCK_END (top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1126 shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
1128 else if (sh
->sc
== scText
&& top_stack
->blocktype
== stFile
)
1130 /* End of file. Pop parse stack and ignore. Higher
1131 level code deals with this. */
1135 complain (&stEnd_complaint
, sh
->sc
);
1137 pop_parse_stack (); /* restore previous lexical context */
1140 case stMember
: /* member of struct or union */
1141 f
= &TYPE_FIELDS (top_stack
->cur_type
)[top_stack
->cur_field
++];
1143 f
->bitpos
= sh
->value
;
1145 f
->type
= parse_type (ax
+ sh
->index
, &f
->bitsize
, bigend
);
1148 case stTypedef
: /* type definition */
1149 s
= new_symbol (name
);
1150 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
1151 SYMBOL_CLASS (s
) = LOC_TYPEDEF
;
1152 SYMBOL_BLOCK_VALUE (s
) = top_stack
->cur_block
;
1153 add_symbol (s
, top_stack
->cur_block
);
1154 SYMBOL_TYPE (s
) = parse_type (ax
+ sh
->index
, 0, bigend
);
1155 sh
->value
= (long) SYMBOL_TYPE (s
);
1158 case stFile
: /* file name */
1159 push_parse_stack ();
1160 top_stack
->blocktype
= sh
->st
;
1163 /* I`ve never seen these for C */
1165 break; /* register relocation */
1167 break; /* forwarding address */
1169 break; /* constant */
1171 complain (&unknown_mips_symtype_complaint
, sh
->st
);
1180 /* Parse the type information provided in the raw AX entries for
1181 the symbol SH. Return the bitfield size in BS, in case.
1182 We must byte-swap the AX entries before we use them; BIGEND says whether
1183 they are big-endian or little-endian (from fh->fBigendian). */
1185 static struct type
*
1186 parse_type (ax
, bs
, bigend
)
1191 /* Null entries in this map are treated specially */
1192 static struct type
**map_bt
[] =
1194 &builtin_type_void
, /* btNil */
1196 &builtin_type_char
, /* btChar */
1197 &builtin_type_unsigned_char
,/* btUChar */
1198 &builtin_type_short
, /* btShort */
1199 &builtin_type_unsigned_short
, /* btUShort */
1200 &builtin_type_int
, /* btInt */
1201 &builtin_type_unsigned_int
, /* btUInt */
1202 &builtin_type_long
, /* btLong */
1203 &builtin_type_unsigned_long
,/* btULong */
1204 &builtin_type_float
, /* btFloat */
1205 &builtin_type_double
, /* btDouble */
1212 &builtin_type_complex
, /* btComplex */
1213 &builtin_type_double_complex
, /* btDComplex */
1215 &builtin_type_fixed_dec
, /* btFixedDec */
1216 &builtin_type_float_dec
, /* btFloatDec */
1217 &builtin_type_string
, /* btString */
1220 &builtin_type_void
, /* btVoid */
1221 &builtin_type_long_long
, /* btLongLong */
1222 &builtin_type_unsigned_long_long
, /* btULongLong */
1226 struct type
*tp
= 0;
1229 enum type_code type_code
= TYPE_CODE_UNDEF
;
1231 /* Use aux as a type information record, map its basic type. */
1233 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1234 if (t
->bt
> (sizeof (map_bt
) / sizeof (*map_bt
)))
1236 complain (&basic_type_complaint
, t
->bt
);
1237 return builtin_type_int
;
1241 tp
= *map_bt
[t
->bt
];
1247 /* Cannot use builtin types -- build our own */
1251 tp
= lookup_pointer_type (builtin_type_void
);
1255 type_code
= TYPE_CODE_STRUCT
;
1259 type_code
= TYPE_CODE_UNION
;
1263 type_code
= TYPE_CODE_ENUM
;
1267 type_code
= TYPE_CODE_RANGE
;
1271 type_code
= TYPE_CODE_SET
;
1276 complain (&basic_type_complaint
, t
->bt
);
1277 return builtin_type_int
;
1281 /* Skip over any further type qualifiers (FIXME). */
1284 /* This is the way it would work if the compiler worked */
1289 ecoff_swap_tir_in (bigend
, &ax
->a_ti
, t1
);
1291 while (t1
->continued
);
1294 /* Move on to next aux */
1299 *bs
= AUX_GET_WIDTH (bigend
, ax
);
1303 /* All these types really point to some (common) MIPS type
1304 definition, and only the type-qualifiers fully identify
1305 them. We'll make the same effort at sharing. */
1306 if (t
->bt
== btIndirect
||
1307 t
->bt
== btStruct
||
1310 t
->bt
== btTypedef
||
1314 char name
[256], *pn
;
1316 /* Try to cross reference this type */
1317 ax
+= cross_ref (ax
, &tp
, type_code
, &pn
, bigend
);
1318 /* reading .o file ? */
1319 if (tp
== (struct type
*) NULL
)
1320 tp
= init_type (type_code
, 0, 0, (char *) NULL
,
1321 (struct objfile
*) NULL
);
1322 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1323 sprintf (name
, fmt
, pn
);
1325 /* Usually, TYPE_CODE(tp) is already type_code. The main
1326 exception is if we guessed wrong re struct/union/enum. */
1327 if (TYPE_CODE (tp
) != type_code
)
1329 complain (&bad_tag_guess_complaint
, name
);
1330 TYPE_CODE (tp
) = type_code
;
1332 if (TYPE_NAME (tp
) == NULL
|| !STREQ (TYPE_NAME (tp
), name
))
1333 TYPE_NAME (tp
) = obsavestring (name
, strlen (name
),
1334 ¤t_objfile
->type_obstack
);
1337 /* Deal with range types */
1338 if (t
->bt
== btRange
)
1340 TYPE_NFIELDS (tp
) = 2;
1341 TYPE_FIELDS (tp
) = ((struct field
*)
1342 TYPE_ALLOC (tp
, 2 * sizeof (struct field
)));
1343 TYPE_FIELD_NAME (tp
, 0) = obsavestring ("Low", strlen ("Low"),
1344 ¤t_objfile
->type_obstack
);
1345 TYPE_FIELD_BITPOS (tp
, 0) = AUX_GET_DNLOW (bigend
, ax
);
1347 TYPE_FIELD_NAME (tp
, 1) = obsavestring ("High", strlen ("High"),
1348 ¤t_objfile
->type_obstack
);
1349 TYPE_FIELD_BITPOS (tp
, 1) = AUX_GET_DNHIGH (bigend
, ax
);
1353 /* Parse all the type qualifiers now. If there are more
1354 than 6 the game will continue in the next aux */
1356 #define PARSE_TQ(tq) \
1357 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, bigend);
1359 again
:PARSE_TQ (tq0
);
1370 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1376 /* Make up a complex type from a basic one. Type is passed by
1377 reference in TPP and side-effected as necessary. The type
1378 qualifier TQ says how to handle the aux symbols at AX for
1379 the symbol SX we are currently analyzing. BIGEND says whether
1380 aux symbols are big-endian or little-endian.
1381 Returns the number of aux symbols we parsed. */
1384 upgrade_type (tpp
, tq
, ax
, bigend
)
1393 /* Used in array processing */
1404 t
= lookup_pointer_type (*tpp
);
1409 t
= lookup_function_type (*tpp
);
1416 /* Determine and record the domain type (type of index) */
1417 ecoff_swap_rndx_in (bigend
, &ax
->a_rndx
, &rndx
);
1423 rf
= AUX_GET_ISYM (bigend
, ax
);
1426 fh
= get_rfd (cur_fd
, rf
);
1428 indx
= parse_type ((ecoff_data (cur_bfd
)->external_aux
1431 (int *) NULL
, bigend
);
1433 /* Get the bounds, and create the array type. */
1435 lower
= AUX_GET_DNLOW (bigend
, ax
);
1437 upper
= AUX_GET_DNHIGH (bigend
, ax
);
1439 rf
= AUX_GET_WIDTH (bigend
, ax
); /* bit size of array element */
1441 range
= create_range_type ((struct type
*) NULL
, indx
,
1444 t
= create_array_type ((struct type
*) NULL
, *tpp
, range
);
1446 /* Check whether supplied array element bit size matches
1447 the known size of the element type. If this complaint
1448 ends up not happening, we can remove this code. It's
1449 here because we aren't sure we understand this *&%&$
1451 id
= TYPE_LENGTH (TYPE_TARGET_TYPE (t
)) << 3; /* bitsize */
1454 /* Most likely an undefined type */
1456 TYPE_LENGTH (TYPE_TARGET_TYPE (t
)) = id
>> 3;
1459 complain (&array_bitsize_complaint
, rf
);
1465 /* Volatile -- currently ignored */
1469 /* Const -- currently ignored */
1473 complain (&unknown_type_qual_complaint
, tq
);
1479 /* Parse a procedure descriptor record PR. Note that the procedure is
1480 parsed _after_ the local symbols, now we just insert the extra
1481 information we need into a MIPS_EFI_SYMBOL_NAME symbol that has
1482 already been placed in the procedure's main block. Note also that
1483 images that have been partially stripped (ld -x) have been deprived
1484 of local symbols, and we have to cope with them here. FIRST_OFF is
1485 the offset of the first procedure for this FDR; we adjust the
1486 address by this amount, but I don't know why. */
1489 parse_procedure (pr
, have_stabs
, first_off
)
1492 unsigned long first_off
;
1494 struct symbol
*s
, *i
;
1496 struct mips_extra_func_info
*e
;
1499 /* Simple rule to find files linked "-x" */
1500 if (cur_fdr
->rss
== -1)
1504 /* Static procedure at address pr->adr. Sigh. */
1505 complain (&pdr_static_symbol_complaint
, pr
->adr
);
1513 ecoff_swap_ext_in (cur_bfd
,
1514 ecoff_data (cur_bfd
)->external_ext
+ pr
->isym
,
1516 sh_name
= ecoff_data (cur_bfd
)->ssext
+ she
.asym
.iss
;
1524 ecoff_swap_sym_in (cur_bfd
,
1525 (ecoff_data (cur_bfd
)->external_sym
1529 sh_name
= ecoff_data (cur_bfd
)->ss
+ cur_fdr
->issBase
+ sh
.iss
;
1534 /* We have to save the cur_fdr across the call to lookup_symbol.
1535 If the pdr is for a static function and if a global function with
1536 the same name exists, lookup_symbol will eventually read in the symtab
1537 for the global function and clobber cur_fdr. */
1538 FDR
*save_cur_fdr
= cur_fdr
;
1539 s
= lookup_symbol (sh_name
, NULL
, VAR_NAMESPACE
, 0, NULL
);
1540 cur_fdr
= save_cur_fdr
;
1543 s
= mylookup_symbol (sh_name
, top_stack
->cur_block
,
1544 VAR_NAMESPACE
, LOC_BLOCK
);
1548 b
= SYMBOL_BLOCK_VALUE (s
);
1552 complain (&pdr_for_nonsymbol_complaint
, sh_name
);
1556 /* FIXME -- delete. We can't do symbol allocation now; it's all done. */
1557 s
= new_symbol (sh_name
);
1558 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
1559 SYMBOL_CLASS (s
) = LOC_BLOCK
;
1560 /* Donno its type, hope int is ok */
1561 SYMBOL_TYPE (s
) = lookup_function_type (builtin_type_int
);
1562 add_symbol (s
, top_stack
->cur_block
);
1563 /* Wont have symbols for this one */
1565 SYMBOL_BLOCK_VALUE (s
) = b
;
1566 BLOCK_FUNCTION (b
) = s
;
1567 BLOCK_START (b
) = pr
->adr
;
1568 /* BOUND used to be the end of procedure's text, but the
1569 argument is no longer passed in. */
1570 BLOCK_END (b
) = bound
;
1571 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
1572 add_block (b
, top_stack
->cur_st
);
1576 i
= mylookup_symbol (MIPS_EFI_SYMBOL_NAME
, b
, LABEL_NAMESPACE
, LOC_CONST
);
1580 e
= (struct mips_extra_func_info
*) SYMBOL_VALUE (i
);
1582 e
->pdr
.isym
= (long) s
;
1583 e
->pdr
.adr
+= cur_fdr
->adr
- first_off
;
1587 /* Parse the external symbol ES. Just call parse_symbol() after
1588 making sure we know where the aux are for it. For procedures,
1589 parsing of the PDRs has already provided all the needed
1590 information, we only parse them if SKIP_PROCEDURES is false,
1591 and only if this causes no symbol duplication.
1592 BIGEND says whether aux entries are big-endian or little-endian.
1594 This routine clobbers top_stack->cur_block and ->cur_st. */
1597 parse_external (es
, skip_procedures
, bigend
)
1599 int skip_procedures
;
1604 if (es
->ifd
!= ifdNil
)
1607 cur_fdr
= ecoff_data (cur_bfd
)->fdr
+ cur_fd
;
1608 ax
= ecoff_data (cur_bfd
)->external_aux
+ cur_fdr
->iauxBase
;
1612 cur_fdr
= ecoff_data (cur_bfd
)->fdr
;
1616 /* Reading .o files */
1617 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
)
1620 switch (es
->asym
.st
)
1640 /* FIXME: Turn this into a complaint? */
1642 printf_filtered ("Warning: %s `%s' is undefined (in %s)\n",
1644 ecoff_data (cur_bfd
)->ssext
+ es
->asym
.iss
,
1645 fdr_name (cur_fdr
));
1649 switch (es
->asym
.st
)
1652 /* If we have full symbols we do not need more */
1653 if (skip_procedures
)
1655 if (mylookup_symbol (ecoff_data (cur_bfd
)->ssext
+ es
->asym
.iss
,
1656 top_stack
->cur_block
,
1657 VAR_NAMESPACE
, LOC_BLOCK
))
1662 /* Note that the case of a symbol with indexNil must be handled
1663 anyways by parse_symbol(). */
1664 parse_symbol (&es
->asym
, ax
, (struct sym_ext
*) NULL
, bigend
);
1665 /* Note that parse_symbol changed es->asym. */
1672 /* Parse the line number info for file descriptor FH into
1673 GDB's linetable LT. MIPS' encoding requires a little bit
1674 of magic to get things out. Note also that MIPS' line
1675 numbers can go back and forth, apparently we can live
1676 with that and do not need to reorder our linetables */
1679 parse_lines (fh
, pr
, lt
)
1682 struct linetable
*lt
;
1684 unsigned char *base
;
1686 int delta
, count
, lineno
= 0;
1687 unsigned long first_off
= pr
->adr
;
1689 if (fh
->cbLineOffset
== 0)
1692 base
= ecoff_data (cur_bfd
)->line
+ fh
->cbLineOffset
;
1694 /* Scan by procedure descriptors */
1696 for (j
= 0; j
< fh
->cpd
; j
++, pr
++)
1701 /* No code for this one */
1702 if (pr
->iline
== ilineNil
||
1703 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1706 /* Aurgh! To know where to stop expanding we must look-ahead. */
1707 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1708 if (pr
[l
].iline
!= -1)
1710 if (l
== (fh
->cpd
- j
))
1715 /* When procedures are moved around the linenumbers are
1716 attributed to the next procedure up. */
1717 if (pr
->iline
>= halt
)
1720 base
= ecoff_data (cur_bfd
)->line
+ fh
->cbLineOffset
+ pr
->cbLineOffset
;
1721 adr
= fh
->adr
+ pr
->adr
- first_off
;
1722 l
= adr
>> 2; /* in words */
1723 halt
+= (adr
>> 2) - pr
->iline
;
1724 for (lineno
= pr
->lnLow
; l
< halt
;)
1726 count
= *base
& 0x0f;
1727 delta
= *base
++ >> 4;
1732 delta
= (base
[0] << 8) | base
[1];
1733 if (delta
>= 0x8000)
1737 lineno
+= delta
; /* first delta is 0 */
1738 k
= add_line (lt
, lineno
, l
, k
);
1744 /* Master parsing procedure for first-pass reading of file symbols
1745 into a partial_symtab. */
1748 parse_partial_symbols (objfile
, section_offsets
)
1749 struct objfile
*objfile
;
1750 struct section_offsets
*section_offsets
;
1753 HDRR
*hdr
= &ecoff_data (cur_bfd
)->symbolic_header
;
1754 /* Running pointers */
1756 struct ext_ext
*ext_out
;
1757 struct ext_ext
*ext_out_end
;
1759 register EXTR
*ext_in
;
1762 struct partial_symtab
*pst
;
1764 int past_first_source_file
= 0;
1766 /* List of current psymtab's include files */
1767 char **psymtab_include_list
;
1768 int includes_allocated
;
1771 struct pst_map
*fdr_to_pst
;
1772 /* Index within current psymtab dependency list */
1773 struct partial_symtab
**dependency_list
;
1774 int dependencies_used
, dependencies_allocated
;
1775 struct cleanup
*old_chain
;
1778 extern_tab
= (EXTR
*) obstack_alloc (&objfile
->psymbol_obstack
,
1779 sizeof (EXTR
) * hdr
->iextMax
);
1781 includes_allocated
= 30;
1783 psymtab_include_list
= (char **) alloca (includes_allocated
*
1785 next_symbol_text_func
= mips_next_symbol_text
;
1787 dependencies_allocated
= 30;
1788 dependencies_used
= 0;
1790 (struct partial_symtab
**) alloca (dependencies_allocated
*
1791 sizeof (struct partial_symtab
*));
1793 last_source_file
= NULL
;
1798 * Only parse the Local and External symbols, and the Relative FDR.
1799 * Fixup enough of the loader symtab to be able to use it.
1800 * Allocate space only for the file's portions we need to
1805 max_glevel
= MIN_GLEVEL
;
1807 /* Allocate the map FDR -> PST.
1808 Minor hack: -O3 images might claim some global data belongs
1809 to FDR -1. We`ll go along with that */
1810 fdr_to_pst
= (struct pst_map
*) xzalloc ((hdr
->ifdMax
+ 1) * sizeof *fdr_to_pst
);
1811 old_chain
= make_cleanup (free
, fdr_to_pst
);
1814 struct partial_symtab
*pst
= new_psymtab ("", objfile
);
1815 fdr_to_pst
[-1].pst
= pst
;
1819 /* Pass 0 over external syms: swap them in. */
1820 ext_block
= (EXTR
*) xmalloc (hdr
->iextMax
* sizeof (EXTR
));
1821 make_cleanup (free
, ext_block
);
1823 ext_out
= ecoff_data (cur_bfd
)->external_ext
;
1824 ext_out_end
= ext_out
+ hdr
->iextMax
;
1826 for (; ext_out
< ext_out_end
; ext_out
++, ext_in
++)
1827 ecoff_swap_ext_in (cur_bfd
, ext_out
, ext_in
);
1829 /* Pass 1 over external syms: Presize and partition the list */
1831 ext_in_end
= ext_in
+ hdr
->iextMax
;
1832 for (; ext_in
< ext_in_end
; ext_in
++)
1833 fdr_to_pst
[ext_in
->ifd
].n_globals
++;
1835 /* Pass 1.5 over files: partition out global symbol space */
1837 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++)
1839 fdr_to_pst
[f_idx
].globals_offset
= s_idx
;
1840 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
1841 fdr_to_pst
[f_idx
].n_globals
= 0;
1844 /* Pass 2 over external syms: fill in external symbols */
1846 ext_in_end
= ext_in
+ hdr
->iextMax
;
1847 for (; ext_in
< ext_in_end
; ext_in
++)
1849 enum minimal_symbol_type ms_type
= mst_text
;
1851 extern_tab
[fdr_to_pst
[ext_in
->ifd
].globals_offset
1852 + fdr_to_pst
[ext_in
->ifd
].n_globals
++] = *ext_in
;
1854 if (ext_in
->asym
.sc
== scUndefined
|| ext_in
->asym
.sc
== scNil
)
1857 name
= ecoff_data (cur_bfd
)->ssext
+ ext_in
->asym
.iss
;
1858 switch (ext_in
->asym
.st
)
1868 ms_type
= mst_unknown
;
1869 complain (&unknown_ext_complaint
, name
);
1871 prim_record_minimal_symbol (name
, ext_in
->asym
.value
, ms_type
);
1874 /* Pass 3 over files, over local syms: fill in static symbols */
1875 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++)
1877 struct partial_symtab
*save_pst
;
1880 cur_fdr
= fh
= ecoff_data (cur_bfd
)->fdr
+ f_idx
;
1884 fdr_to_pst
[f_idx
].pst
= NULL
;
1887 pst
= start_psymtab_common (objfile
, section_offsets
,
1889 fh
->cpd
? fh
->adr
: 0,
1890 objfile
->global_psymbols
.next
,
1891 objfile
->static_psymbols
.next
);
1892 pst
->read_symtab_private
= ((char *)
1893 obstack_alloc (&objfile
->psymbol_obstack
,
1894 sizeof (struct symloc
)));
1895 memset ((PTR
) pst
->read_symtab_private
, 0, sizeof (struct symloc
));
1898 /* Make everything point to everything. */
1899 FDR_IDX (pst
) = f_idx
;
1900 fdr_to_pst
[f_idx
].pst
= pst
;
1902 /* FIXME: This tampers with data from BFD. */
1903 fh
->ioptBase
= (int) pst
;
1905 CUR_BFD (pst
) = cur_bfd
;
1907 /* The way to turn this into a symtab is to call... */
1908 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
1910 pst
->texthigh
= pst
->textlow
;
1912 /* For stabs-in-ecoff files, the second symbol must be @stab.
1913 This symbol is emitted by mips-tfile to signal that the
1914 current object file uses encapsulated stabs instead of mips
1915 ecoff for local symbols. (It is the second symbol because
1916 the first symbol is the stFile used to signal the start of a
1918 processing_gcc_compilation
= 0;
1921 ecoff_swap_sym_in (cur_bfd
,
1922 (ecoff_data (cur_bfd
)->external_sym
1926 if (STREQ (ecoff_data (cur_bfd
)->ss
+ fh
->issBase
+ sh
.iss
,
1928 processing_gcc_compilation
= 2;
1931 if (processing_gcc_compilation
!= 0)
1933 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++)
1938 ecoff_swap_sym_in (cur_bfd
,
1939 (ecoff_data (cur_bfd
)->external_sym
1943 type_code
= MIPS_UNMARK_STAB (sh
.index
);
1944 if (!MIPS_IS_STAB (&sh
))
1946 if (sh
.st
== stProc
|| sh
.st
== stStaticProc
)
1948 long procaddr
= sh
.value
;
1952 isym
= AUX_GET_ISYM (fh
->fBigendian
,
1953 (ecoff_data (cur_bfd
)->external_aux
1956 ecoff_swap_sym_in (cur_bfd
,
1957 (ecoff_data (cur_bfd
)->external_sym
1964 long high
= procaddr
+ sh
.value
;
1965 if (high
> pst
->texthigh
)
1966 pst
->texthigh
= high
;
1971 #define SET_NAMESTRING() \
1972 namestring = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss
1973 #define CUR_SYMBOL_TYPE type_code
1974 #define CUR_SYMBOL_VALUE sh.value
1975 #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms)\
1977 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
1978 #define HANDLE_RBRAC(val) \
1979 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
1980 #include "partial-stab.h"
1985 for (cur_sdx
= 0; cur_sdx
< fh
->csym
;)
1988 enum address_class
class;
1990 ecoff_swap_sym_in (cur_bfd
,
1991 (ecoff_data (cur_bfd
)->external_sym
1996 if (MIPS_IS_STAB (&sh
))
2002 if (sh
.sc
== scUndefined
|| sh
.sc
== scNil
||
2003 sh
.index
== 0xfffff)
2005 /* FIXME, premature? */
2010 name
= ecoff_data (cur_bfd
)->ss
+ fh
->issBase
+ sh
.iss
;
2018 case stProc
: /* Asm labels apparently */
2019 case stStaticProc
: /* Function */
2020 ADD_PSYMBOL_TO_LIST (name
, strlen (name
),
2021 VAR_NAMESPACE
, LOC_BLOCK
,
2022 objfile
->static_psymbols
, sh
.value
,
2023 psymtab_language
, objfile
);
2024 /* Skip over procedure to next one. */
2025 if (sh
.index
>= hdr
->iauxMax
)
2027 /* Should not happen, but does when cross-compiling
2028 with the MIPS compiler. FIXME -- pull later. */
2029 complain (&index_complaint
, name
);
2030 new_sdx
= cur_sdx
+ 1; /* Don't skip at all */
2033 new_sdx
= AUX_GET_ISYM (fh
->fBigendian
,
2034 (ecoff_data (cur_bfd
)->external_aux
2037 procaddr
= sh
.value
;
2039 if (new_sdx
<= cur_sdx
)
2041 /* This should not happen either... FIXME. */
2042 complain (&aux_index_complaint
, name
);
2043 new_sdx
= cur_sdx
+ 1; /* Don't skip backward */
2047 ecoff_swap_sym_in (cur_bfd
,
2048 (ecoff_data (cur_bfd
)->external_sym
2055 high
= procaddr
+ sh
.value
;
2056 if (high
> pst
->texthigh
)
2057 pst
->texthigh
= high
;
2060 case stStatic
: /* Variable */
2064 case stTypedef
:/* Typedef */
2065 class = LOC_TYPEDEF
;
2068 case stConstant
: /* Constant decl */
2075 case stBlock
: /* { }, str, un, enum*/
2076 if (sh
.sc
== scInfo
)
2078 ADD_PSYMBOL_TO_LIST (name
, strlen (name
),
2079 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2080 objfile
->static_psymbols
,
2082 psymtab_language
, objfile
);
2084 /* Skip over the block */
2086 if (new_sdx
<= cur_sdx
)
2088 /* This happens with the Ultrix kernel. */
2089 complain (&block_index_complaint
, name
);
2090 new_sdx
= cur_sdx
+ 1; /* Don't skip backward */
2095 case stFile
: /* File headers */
2096 case stLabel
: /* Labels */
2097 case stEnd
: /* Ends of files */
2100 case stLocal
: /* Local variables */
2101 /* Normally these are skipped because we skip over
2102 all blocks we see. However, these can occur
2103 as visible symbols in a .h file that contains code. */
2107 /* Both complaints are valid: one gives symbol name,
2108 the other the offending symbol type. */
2109 complain (&unknown_sym_complaint
, name
);
2110 complain (&unknown_st_complaint
, sh
.st
);
2114 /* Use this gdb symbol */
2115 ADD_PSYMBOL_TO_LIST (name
, strlen (name
),
2116 VAR_NAMESPACE
, class,
2117 objfile
->static_psymbols
, sh
.value
,
2118 psymtab_language
, objfile
);
2120 cur_sdx
++; /* Go to next file symbol */
2123 /* Now do enter the external symbols. */
2124 ext_ptr
= &extern_tab
[fdr_to_pst
[f_idx
].globals_offset
];
2125 cur_sdx
= fdr_to_pst
[f_idx
].n_globals
;
2126 PST_PRIVATE (save_pst
)->extern_count
= cur_sdx
;
2127 PST_PRIVATE (save_pst
)->extern_tab
= ext_ptr
;
2128 for (; --cur_sdx
>= 0; ext_ptr
++)
2130 register struct partial_symbol
*psym
;
2131 enum address_class
class;
2135 if (ext_ptr
->ifd
!= f_idx
)
2137 psh
= &ext_ptr
->asym
;
2147 complain (&unknown_ext_complaint
,
2148 ecoff_data (cur_bfd
)->ssext
+ psh
->iss
);
2149 /* Fall through, pretend it's global. */
2154 name
= ecoff_data (cur_bfd
)->ssext
+ psh
->iss
;
2155 ADD_PSYMBOL_ADDR_TO_LIST (name
, strlen (name
),
2156 VAR_NAMESPACE
, class,
2157 objfile
->global_psymbols
, (CORE_ADDR
) psh
->value
,
2158 psymtab_language
, objfile
);
2162 end_psymtab (save_pst
, psymtab_include_list
, includes_used
,
2163 -1, save_pst
->texthigh
,
2164 dependency_list
, dependencies_used
);
2165 if (objfile
->ei
.entry_point
>= save_pst
->textlow
&&
2166 objfile
->ei
.entry_point
< save_pst
->texthigh
)
2168 objfile
->ei
.entry_file_lowpc
= save_pst
->textlow
;
2169 objfile
->ei
.entry_file_highpc
= save_pst
->texthigh
;
2173 /* Now scan the FDRs for dependencies */
2174 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++)
2177 fh
= f_idx
+ ecoff_data (cur_bfd
)->fdr
;
2178 pst
= fdr_to_pst
[f_idx
].pst
;
2180 /* This should catch stabs-in-ecoff. */
2185 { /* If there are no functions defined here ... */
2186 /* ...then presumably a .h file: drop reverse depends .h->.c */
2187 for (; s_id0
< fh
->crfd
; s_id0
++)
2191 ecoff_swap_rfd_in (cur_bfd
,
2192 (ecoff_data (cur_bfd
)->external_rfd
2198 s_id0
++; /* Skip self-dependency */
2203 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2205 ((struct partial_symtab
**)
2206 obstack_alloc (&objfile
->psymbol_obstack
,
2207 (pst
->number_of_dependencies
2208 * sizeof (struct partial_symtab
*))));
2209 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++)
2213 ecoff_swap_rfd_in (cur_bfd
,
2214 (ecoff_data (cur_bfd
)->external_rfd
2218 if (rh
< 0 || rh
>= hdr
->ifdMax
)
2219 complain (&bad_file_number_complaint
, rh
);
2221 pst
->dependencies
[s_idx
- s_id0
] = fdr_to_pst
[rh
].pst
;
2224 do_cleanups (old_chain
);
2229 /* Do the initial analisys of the F_IDX-th file descriptor.
2230 Allocates a partial symtab for it, and builds the list
2231 of dependent files by recursion. LEV says at which level
2232 of recursion we are called (to pretty up debug traces) */
2234 static struct partial_symtab
*
2235 parse_fdr (f_idx
, lev
, objfile
)
2238 struct objfile
*objfile
;
2241 register struct partial_symtab
*pst
;
2244 fh
= ecoff_data (cur_bfd
)->fdr
+ f_idx
;
2246 /* Use this to indicate into which symtab this file was parsed */
2248 return (struct partial_symtab
*) fh
->ioptBase
;
2250 /* Debuggability level */
2251 if (compare_glevel (max_glevel
, fh
->glevel
) < 0)
2252 max_glevel
= fh
->glevel
;
2254 /* Make a new partial_symtab */
2255 pst
= new_psymtab (fdr_name (fh
), objfile
);
2263 pst
->textlow
= fh
->adr
;
2264 pst
->texthigh
= fh
->cpd
; /* To be fixed later */
2267 /* Make everything point to everything. */
2268 FDR_IDX (pst
) = f_idx
;
2269 fdr_to_pst
[f_idx
].pst
= pst
;
2270 fh
->ioptBase
= (int) pst
;
2272 /* Analyze its dependencies */
2278 { /* If there are no functions defined here ... */
2279 /* ...then presumably a .h file: drop reverse depends .h->.c */
2280 for (; s_id0
< fh
->crfd
; s_id0
++)
2284 ecoff_swap_rfd_in (cur_bfd
,
2285 (ecoff_data (cur_bfd
)->external_rfd
2291 s_id0
++; /* Skip self-dependency */
2296 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2297 pst
->dependencies
= ((struct partial_symtab
**)
2298 obstack_alloc (&objfile
->psymbol_obstack
,
2299 (pst
->number_of_dependencies
2300 * sizeof (struct partial_symtab
*))));
2301 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++)
2305 ecoff_swap_rfd_in (cur_bfd
,
2306 (ecoff_data (cur_bfd
)->external_rfd
2310 pst
->dependencies
[s_idx
- s_id0
] = parse_fdr (rh
, lev
+ 1, objfile
);
2319 mips_next_symbol_text ()
2324 ecoff_swap_sym_in (cur_bfd
,
2325 (ecoff_data (cur_bfd
)->external_sym
2329 return ecoff_data (cur_bfd
)->ss
+ cur_fdr
->issBase
+ sh
.iss
;
2332 /* Ancillary function to psymtab_to_symtab(). Does all the work
2333 for turning the partial symtab PST into a symtab, recurring
2334 first on all dependent psymtabs. The argument FILENAME is
2335 only passed so we can see in debug stack traces what file
2338 This function has a split personality, based on whether the
2339 symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
2340 The flow of control and even the memory allocation differs. FIXME. */
2343 psymtab_to_symtab_1 (pst
, filename
)
2344 struct partial_symtab
*pst
;
2350 struct linetable
*lines
;
2356 /* Read in all partial symbtabs on which this one is dependent.
2357 NOTE that we do have circular dependencies, sigh. We solved
2358 that by setting pst->readin before this point. */
2360 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2361 if (!pst
->dependencies
[i
]->readin
)
2363 /* Inform about additional files to be read in. */
2366 fputs_filtered (" ", stdout
);
2368 fputs_filtered ("and ", stdout
);
2370 printf_filtered ("%s...",
2371 pst
->dependencies
[i
]->filename
);
2372 wrap_here (""); /* Flush output */
2375 /* We only pass the filename for debug purposes */
2376 psymtab_to_symtab_1 (pst
->dependencies
[i
],
2377 pst
->dependencies
[i
]->filename
);
2380 /* Now read the symbols for this symtab */
2382 current_objfile
= pst
->objfile
;
2383 cur_fd
= FDR_IDX (pst
);
2384 fh
= (cur_fd
== -1) ? (FDR
*) NULL
: ecoff_data (cur_bfd
)->fdr
+ cur_fd
;
2387 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2388 processing_gcc_compilation
= 0;
2389 if (fh
!= (FDR
*) NULL
&& fh
->csym
>= 2)
2393 ecoff_swap_sym_in (cur_bfd
,
2394 (ecoff_data (cur_bfd
)->external_sym
2398 if (STREQ (ecoff_data (cur_bfd
)->ss
+ fh
->issBase
+ sh
.iss
,
2401 /* We indicate that this is a GCC compilation so that certain
2402 features will be enabled in stabsread/dbxread. */
2403 processing_gcc_compilation
= 2;
2407 if (processing_gcc_compilation
!= 0)
2409 struct pdr_ext
*pdr_ptr
;
2410 struct pdr_ext
*pdr_end
;
2412 unsigned long first_off
;
2414 /* This symbol table contains stabs-in-ecoff entries. */
2416 /* Parse local symbols first */
2418 if (fh
->csym
<= 2) /* FIXME, this blows psymtab->symtab ptr */
2420 current_objfile
= NULL
;
2423 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++)
2429 ecoff_swap_sym_in (cur_bfd
,
2430 (ecoff_data (cur_bfd
)->external_sym
2434 name
= ecoff_data (cur_bfd
)->ss
+ fh
->issBase
+ sh
.iss
;
2436 if (MIPS_IS_STAB (&sh
))
2438 int type_code
= MIPS_UNMARK_STAB (sh
.index
);
2439 process_one_symbol (type_code
, 0, valu
, name
,
2440 pst
->section_offsets
, pst
->objfile
);
2441 if (type_code
== N_FUN
)
2443 /* Make up special symbol to contain
2444 procedure specific info */
2445 struct mips_extra_func_info
*e
=
2446 ((struct mips_extra_func_info
*)
2447 obstack_alloc (¤t_objfile
->symbol_obstack
,
2448 sizeof (struct mips_extra_func_info
)));
2449 struct symbol
*s
= new_symbol (MIPS_EFI_SYMBOL_NAME
);
2450 SYMBOL_NAMESPACE (s
) = LABEL_NAMESPACE
;
2451 SYMBOL_CLASS (s
) = LOC_CONST
;
2452 SYMBOL_TYPE (s
) = builtin_type_void
;
2453 SYMBOL_VALUE (s
) = (int) e
;
2454 add_symbol_to_list (s
, &local_symbols
);
2457 else if (sh
.st
== stLabel
&& sh
.index
!= indexNil
)
2459 /* Handle encoded stab line number. */
2460 record_line (current_subfile
, sh
.index
, valu
);
2463 complain (&stab_unknown_complaint
, name
);
2465 st
= end_symtab (pst
->texthigh
, 0, 0, pst
->objfile
);
2468 /* Sort the symbol table now, we are done adding symbols to it.
2469 We must do this before parse_procedure calls lookup_symbol. */
2470 sort_symtab_syms (st
);
2472 /* This may not be necessary for stabs symtabs. FIXME. */
2475 /* Fill in procedure info next. */
2477 pdr_ptr
= ecoff_data (cur_bfd
)->external_pdr
+ fh
->ipdFirst
;
2478 pdr_end
= pdr_ptr
+ fh
->cpd
;
2479 for (; pdr_ptr
< pdr_end
; pdr_ptr
++)
2483 ecoff_swap_pdr_in (cur_bfd
, pdr_ptr
, &pr
);
2489 parse_procedure (&pr
, 1, first_off
);
2494 /* This symbol table contains ordinary ecoff entries. */
2496 /* FIXME: doesn't use pst->section_offsets. */
2502 /* How many symbols will we need */
2503 /* FIXME, this does not count enum values. */
2504 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
2508 st
= new_symtab ("unknown", f_max
, 0, pst
->objfile
);
2512 f_max
+= fh
->csym
+ fh
->cpd
;
2513 maxlines
= 2 * fh
->cline
;
2514 st
= new_symtab (pst
->filename
, 2 * f_max
, maxlines
, pst
->objfile
);
2517 lines
= LINETABLE (st
);
2518 pending_list
= PST_PRIVATE (pst
)->pending_list
;
2519 if (pending_list
== 0)
2521 pending_list
= ((struct mips_pending
**)
2522 xzalloc (ecoff_data (cur_bfd
)->symbolic_header
.ifdMax
2523 * sizeof (struct mips_pending
*)));
2524 PST_PRIVATE (pst
)->pending_list
= pending_list
;
2527 /* Get a new lexical context */
2529 push_parse_stack ();
2530 top_stack
->cur_st
= st
;
2531 top_stack
->cur_block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (st
),
2533 BLOCK_START (top_stack
->cur_block
) = fh
? fh
->adr
: 0;
2534 BLOCK_END (top_stack
->cur_block
) = 0;
2535 top_stack
->blocktype
= stFile
;
2536 top_stack
->maxsyms
= 2 * f_max
;
2537 top_stack
->cur_type
= 0;
2538 top_stack
->procadr
= 0;
2539 top_stack
->numargs
= 0;
2543 struct sym_ext
*sym_ptr
;
2544 struct sym_ext
*sym_end
;
2546 /* Parse local symbols first */
2547 sym_ptr
= ecoff_data (cur_bfd
)->external_sym
+ fh
->isymBase
;
2548 sym_end
= sym_ptr
+ fh
->csym
;
2549 while (sym_ptr
< sym_end
)
2554 ecoff_swap_sym_in (cur_bfd
, sym_ptr
, &sh
);
2555 c
= parse_symbol (&sh
,
2556 (ecoff_data (cur_bfd
)->external_aux
2558 sym_ptr
, fh
->fBigendian
);
2559 /* FIXME: We must swap the modified symbol back out,
2560 although we would rather not. See parse_symbol. */
2561 ecoff_swap_sym_out (cur_bfd
, &sh
, sym_ptr
);
2565 /* Linenumbers. At the end, check if we can save memory.
2566 parse_lines has to look ahead an arbitrary number of PDR
2567 structures, so we swap them all first. */
2571 struct cleanup
*old_chain
;
2572 struct pdr_ext
*pdr_ptr
;
2573 struct pdr_ext
*pdr_end
;
2577 pr_block
= (PDR
*) xmalloc (fh
->cpd
* sizeof (PDR
));
2579 old_chain
= make_cleanup (free
, pr_block
);
2581 pdr_ptr
= ecoff_data (cur_bfd
)->external_pdr
+ fh
->ipdFirst
;
2582 pdr_end
= pdr_ptr
+ fh
->cpd
;
2584 for (; pdr_ptr
< pdr_end
; pdr_ptr
++, pdr_in
++)
2585 ecoff_swap_pdr_in (cur_bfd
, pdr_ptr
, pdr_in
);
2587 parse_lines (fh
, pr_block
, lines
);
2588 if (lines
->nitems
< fh
->cline
)
2589 lines
= shrink_linetable (lines
);
2591 /* Fill in procedure info next. */
2593 pdr_in_end
= pdr_in
+ fh
->cpd
;
2594 for (; pdr_in
< pdr_in_end
; pdr_in
++)
2595 parse_procedure (pdr_in
, 0, pr_block
->adr
);
2597 do_cleanups (old_chain
);
2601 LINETABLE (st
) = lines
;
2603 /* .. and our share of externals.
2604 XXX use the global list to speed up things here. how?
2605 FIXME, Maybe quit once we have found the right number of ext's? */
2606 top_stack
->cur_st
= st
;
2607 top_stack
->cur_block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack
->cur_st
),
2609 top_stack
->blocktype
= stFile
;
2610 top_stack
->maxsyms
= (ecoff_data (cur_bfd
)->symbolic_header
.isymMax
2611 + ecoff_data (cur_bfd
)->symbolic_header
.ipdMax
2612 + ecoff_data (cur_bfd
)->symbolic_header
.iextMax
);
2614 ext_ptr
= PST_PRIVATE (pst
)->extern_tab
;
2615 for (i
= PST_PRIVATE (pst
)->extern_count
; --i
>= 0; ext_ptr
++)
2616 parse_external (ext_ptr
, 1, fh
->fBigendian
);
2618 /* If there are undefined, tell the user */
2619 if (n_undef_symbols
)
2621 printf_filtered ("File %s contains %d unresolved references:",
2622 st
->filename
, n_undef_symbols
);
2623 printf_filtered ("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2624 n_undef_vars
, n_undef_procs
, n_undef_labels
);
2625 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
2630 /* Sort the symbol table now, we are done adding symbols to it.*/
2631 sort_symtab_syms (st
);
2636 /* Now link the psymtab and the symtab. */
2639 current_objfile
= NULL
;
2642 /* Ancillary parsing procedures. */
2644 /* Lookup the type at relative index RN. Return it in TPP
2645 if found and in any event come up with its name PNAME.
2646 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
2647 Return value says how many aux symbols we ate. */
2650 cross_ref (ax
, tpp
, type_code
, pname
, bigend
)
2653 enum type_code type_code
; /* Use to alloc new type if none is found. */
2661 ecoff_swap_rndx_in (bigend
, &ax
->a_rndx
, rn
);
2663 /* Escape index means 'the next one' */
2664 if (rn
->rfd
== 0xfff)
2667 rf
= AUX_GET_ISYM (bigend
, ax
+ 1);
2677 *pname
= "<undefined>";
2682 * Find the relative file descriptor and the symbol in it
2684 FDR
*fh
= get_rfd (cur_fd
, rf
);
2685 struct sym_ext
*esh
;
2689 /* If we have processed this symbol then we left a forwarding
2690 pointer to the corresponding GDB symbol. If not, we`ll put
2691 it in a list of pending symbols, to be processed later when
2692 the file will be. In any event, we collect the name for the
2693 type here. Which is why we made a first pass at strings. */
2695 esh
= ecoff_data (cur_bfd
)->external_sym
+ fh
->isymBase
+ rn
->index
;
2696 ecoff_swap_sym_in (cur_bfd
, esh
, &sh
);
2698 /* Careful, we might be looking at .o files */
2700 *pname
= "<undefined>";
2702 *pname
= ecoff_data (cur_bfd
)->ss
+ fh
->issBase
+ sh
.iss
;
2704 /* Have we parsed it ? */
2705 if (sh
.value
!= 0 && sh
.st
== stParsed
)
2707 t
= (struct type
*) sh
.value
;
2712 /* Avoid duplicates */
2713 struct mips_pending
*p
= is_pending_symbol (fh
, esh
);
2718 *tpp
= init_type (type_code
, 0, 0, (char *) NULL
,
2719 (struct objfile
*) NULL
);
2720 add_pending (fh
, esh
, *tpp
);
2725 /* We used one auxent normally, two if we got a "next one" rf. */
2730 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2731 keeping the symtab sorted */
2733 static struct symbol
*
2734 mylookup_symbol (name
, block
, namespace, class)
2736 register struct block
*block
;
2737 enum namespace namespace;
2738 enum address_class
class;
2740 register int bot
, top
, inc
;
2741 register struct symbol
*sym
;
2744 top
= BLOCK_NSYMS (block
);
2748 sym
= BLOCK_SYM (block
, bot
);
2749 if (SYMBOL_NAME (sym
)[0] == inc
2750 && SYMBOL_NAMESPACE (sym
) == namespace
2751 && SYMBOL_CLASS (sym
) == class
2752 && STREQ (SYMBOL_NAME (sym
), name
))
2756 block
= BLOCK_SUPERBLOCK (block
);
2758 return mylookup_symbol (name
, block
, namespace, class);
2763 /* Add a new symbol S to a block B.
2764 Infrequently, we will need to reallocate the block to make it bigger.
2765 We only detect this case when adding to top_stack->cur_block, since
2766 that's the only time we know how big the block is. FIXME. */
2773 int nsyms
= BLOCK_NSYMS (b
)++;
2774 struct block
*origb
;
2775 struct parse_stack
*stackp
;
2777 if (b
== top_stack
->cur_block
&&
2778 nsyms
>= top_stack
->maxsyms
)
2780 complain (&block_overflow_complaint
, SYMBOL_NAME (s
));
2781 /* In this case shrink_block is actually grow_block, since
2782 BLOCK_NSYMS(b) is larger than its current size. */
2784 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
2786 /* Now run through the stack replacing pointers to the
2787 original block. shrink_block has already done this
2788 for the blockvector and BLOCK_FUNCTION. */
2789 for (stackp
= top_stack
; stackp
; stackp
= stackp
->next
)
2791 if (stackp
->cur_block
== origb
)
2793 stackp
->cur_block
= b
;
2794 stackp
->maxsyms
= BLOCK_NSYMS (b
);
2798 BLOCK_SYM (b
, nsyms
) = s
;
2801 /* Add a new block B to a symtab S */
2808 struct blockvector
*bv
= BLOCKVECTOR (s
);
2810 bv
= (struct blockvector
*) xrealloc ((PTR
) bv
,
2811 (sizeof (struct blockvector
)
2812 + BLOCKVECTOR_NBLOCKS (bv
)
2813 * sizeof (bv
->block
)));
2814 if (bv
!= BLOCKVECTOR (s
))
2815 BLOCKVECTOR (s
) = bv
;
2817 BLOCKVECTOR_BLOCK (bv
, BLOCKVECTOR_NBLOCKS (bv
)++) = b
;
2820 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2821 MIPS' linenumber encoding might need more than one byte
2822 to describe it, LAST is used to detect these continuation lines */
2825 add_line (lt
, lineno
, adr
, last
)
2826 struct linetable
*lt
;
2832 last
= -2; /* make sure we record first line */
2834 if (last
== lineno
) /* skip continuation lines */
2837 lt
->item
[lt
->nitems
].line
= lineno
;
2838 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
2842 /* Sorting and reordering procedures */
2844 /* Blocks with a smaller low bound should come first */
2847 compare_blocks (arg1
, arg2
)
2848 const void *arg1
, *arg2
;
2850 register int addr_diff
;
2851 struct block
**b1
= (struct block
**) arg1
;
2852 struct block
**b2
= (struct block
**) arg2
;
2854 addr_diff
= (BLOCK_START ((*b1
))) - (BLOCK_START ((*b2
)));
2856 return (BLOCK_END ((*b2
))) - (BLOCK_END ((*b1
)));
2860 /* Sort the blocks of a symtab S.
2861 Reorder the blocks in the blockvector by code-address,
2862 as required by some MI search routines */
2868 struct blockvector
*bv
= BLOCKVECTOR (s
);
2870 if (BLOCKVECTOR_NBLOCKS (bv
) <= 2)
2873 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) == 0)
2874 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) = 0;
2875 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) == 0)
2876 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) = 0;
2880 * This is very unfortunate: normally all functions are compiled in
2881 * the order they are found, but if the file is compiled -O3 things
2882 * are very different. It would be nice to find a reliable test
2883 * to detect -O3 images in advance.
2885 if (BLOCKVECTOR_NBLOCKS (bv
) > 3)
2886 qsort (&BLOCKVECTOR_BLOCK (bv
, FIRST_LOCAL_BLOCK
),
2887 BLOCKVECTOR_NBLOCKS (bv
) - FIRST_LOCAL_BLOCK
,
2888 sizeof (struct block
*),
2892 register CORE_ADDR high
= 0;
2893 register int i
, j
= BLOCKVECTOR_NBLOCKS (bv
);
2895 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
2896 if (high
< BLOCK_END (BLOCKVECTOR_BLOCK (bv
, i
)))
2897 high
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, i
));
2898 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) = high
;
2901 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) =
2902 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, FIRST_LOCAL_BLOCK
));
2904 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) =
2905 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
2906 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) =
2907 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
2911 /* Constructor/restructor/destructor procedures */
2913 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2914 MAXSYMS and linenumbers MAXLINES we'll put in it */
2916 static struct symtab
*
2917 new_symtab (name
, maxsyms
, maxlines
, objfile
)
2921 struct objfile
*objfile
;
2923 struct symtab
*s
= allocate_symtab (name
, objfile
);
2925 LINETABLE (s
) = new_linetable (maxlines
);
2927 /* All symtabs must have at least two blocks */
2928 BLOCKVECTOR (s
) = new_bvect (2);
2929 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
) = new_block (maxsyms
);
2930 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
) = new_block (maxsyms
);
2931 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)) =
2932 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
2934 s
->free_code
= free_linetable
;
2939 /* Allocate a new partial_symtab NAME */
2941 static struct partial_symtab
*
2942 new_psymtab (name
, objfile
)
2944 struct objfile
*objfile
;
2946 struct partial_symtab
*psymtab
;
2948 psymtab
= allocate_psymtab (name
, objfile
);
2950 /* Keep a backpointer to the file's symbols */
2952 psymtab
->read_symtab_private
= ((char *)
2953 obstack_alloc (&objfile
->psymbol_obstack
,
2954 sizeof (struct symloc
)));
2955 memset ((PTR
) psymtab
->read_symtab_private
, 0, sizeof (struct symloc
));
2956 CUR_BFD (psymtab
) = cur_bfd
;
2958 /* The way to turn this into a symtab is to call... */
2959 psymtab
->read_symtab
= mipscoff_psymtab_to_symtab
;
2964 /* Allocate a linetable array of the given SIZE. Since the struct
2965 already includes one item, we subtract one when calculating the
2966 proper size to allocate. */
2968 static struct linetable
*
2969 new_linetable (size
)
2972 struct linetable
*l
;
2974 size
= (size
- 1) * sizeof (l
->item
) + sizeof (struct linetable
);
2975 l
= (struct linetable
*) xmalloc (size
);
2980 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2981 I am not so sure about the 3.4 ones.
2983 Since the struct linetable already includes one item, we subtract one when
2984 calculating the proper size to allocate. */
2986 static struct linetable
*
2987 shrink_linetable (lt
)
2988 struct linetable
*lt
;
2991 return (struct linetable
*) xrealloc ((PTR
) lt
,
2992 (sizeof (struct linetable
)
2994 * sizeof (lt
->item
))));
2997 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2999 static struct blockvector
*
3003 struct blockvector
*bv
;
3006 size
= sizeof (struct blockvector
) + nblocks
* sizeof (struct block
*);
3007 bv
= (struct blockvector
*) xzalloc (size
);
3009 BLOCKVECTOR_NBLOCKS (bv
) = nblocks
;
3014 /* Allocate and zero a new block of MAXSYMS symbols */
3016 static struct block
*
3020 int size
= sizeof (struct block
) + (maxsyms
- 1) * sizeof (struct symbol
*);
3022 return (struct block
*) xzalloc (size
);
3025 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
3026 Shrink_block can also be used by add_symbol to grow a block. */
3028 static struct block
*
3034 struct blockvector
*bv
= BLOCKVECTOR (s
);
3037 /* Just reallocate it and fix references to the old one */
3039 new = (struct block
*) xrealloc ((PTR
) b
,
3040 (sizeof (struct block
)
3041 + ((BLOCK_NSYMS (b
) - 1)
3042 * sizeof (struct symbol
*))));
3044 /* Should chase pointers to old one. Fortunately, that`s just
3045 the block`s function and inferior blocks */
3046 if (BLOCK_FUNCTION (new) && SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) == b
)
3047 SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) = new;
3048 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS (bv
); i
++)
3049 if (BLOCKVECTOR_BLOCK (bv
, i
) == b
)
3050 BLOCKVECTOR_BLOCK (bv
, i
) = new;
3051 else if (BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv
, i
)) == b
)
3052 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv
, i
)) = new;
3056 /* Create a new symbol with printname NAME */
3058 static struct symbol
*
3062 struct symbol
*s
= ((struct symbol
*)
3063 obstack_alloc (¤t_objfile
->symbol_obstack
,
3064 sizeof (struct symbol
)));
3066 memset ((PTR
) s
, 0, sizeof (*s
));
3067 SYMBOL_NAME (s
) = name
;
3071 /* Create a new type with printname NAME */
3073 static struct type
*
3079 t
= alloc_type (current_objfile
);
3080 TYPE_NAME (t
) = name
;
3081 TYPE_CPLUS_SPECIFIC (t
) = (struct cplus_struct_type
*) &cplus_struct_default
;
3086 /* Things used for calling functions in the inferior.
3087 These functions are exported to our companion
3088 mips-tdep.c file and are here because they play
3089 with the symbol-table explicitly. */
3091 /* Sigtramp: make sure we have all the necessary information
3092 about the signal trampoline code. Since the official code
3093 from MIPS does not do so, we make up that information ourselves.
3094 If they fix the library (unlikely) this code will neutralize itself. */
3101 struct block
*b
, *b0
;
3103 sigtramp_address
= -1;
3105 /* We know it is sold as sigvec */
3106 s
= lookup_symbol ("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
3108 /* Most programs do not play with signals */
3110 s
= lookup_symbol ("_sigtramp", 0, VAR_NAMESPACE
, 0, NULL
);
3113 b0
= SYMBOL_BLOCK_VALUE (s
);
3115 /* A label of sigvec, to be more precise */
3116 s
= lookup_symbol ("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
3119 /* But maybe this program uses its own version of sigvec */
3123 /* Did we or MIPSco fix the library ? */
3124 if (SYMBOL_CLASS (s
) == LOC_BLOCK
)
3126 sigtramp_address
= BLOCK_START (SYMBOL_BLOCK_VALUE (s
));
3127 sigtramp_end
= BLOCK_END (SYMBOL_BLOCK_VALUE (s
));
3131 sigtramp_address
= SYMBOL_VALUE (s
);
3132 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
3134 /* But what symtab does it live in ? */
3135 st
= find_pc_symtab (SYMBOL_VALUE (s
));
3138 * Ok, there goes the fix: turn it into a procedure, with all the
3139 * needed info. Note we make it a nested procedure of sigvec,
3140 * which is the way the (assembly) code is actually written.
3142 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
3143 SYMBOL_CLASS (s
) = LOC_BLOCK
;
3144 SYMBOL_TYPE (s
) = init_type (TYPE_CODE_FUNC
, 4, 0, (char *) NULL
,
3145 (struct objfile
*) NULL
);
3146 TYPE_TARGET_TYPE (SYMBOL_TYPE (s
)) = builtin_type_void
;
3148 /* Need a block to allocate MIPS_EFI_SYMBOL_NAME in */
3150 SYMBOL_BLOCK_VALUE (s
) = b
;
3151 BLOCK_START (b
) = sigtramp_address
;
3152 BLOCK_END (b
) = sigtramp_end
;
3153 BLOCK_FUNCTION (b
) = s
;
3154 BLOCK_SUPERBLOCK (b
) = BLOCK_SUPERBLOCK (b0
);
3158 /* Make a MIPS_EFI_SYMBOL_NAME entry for it */
3160 struct mips_extra_func_info
*e
=
3161 ((struct mips_extra_func_info
*)
3162 xzalloc (sizeof (struct mips_extra_func_info
)));
3164 e
->numargs
= 0; /* the kernel thinks otherwise */
3165 /* align_longword(sigcontext + SIGFRAME) */
3166 e
->pdr
.frameoffset
= 0x150;
3167 e
->pdr
.framereg
= SP_REGNUM
;
3169 e
->pdr
.regmask
= -2;
3170 e
->pdr
.regoffset
= -(41 * sizeof (int));
3171 e
->pdr
.fregmask
= -1;
3172 e
->pdr
.fregoffset
= -(37 * sizeof (int));
3173 e
->pdr
.isym
= (long) s
;
3175 current_objfile
= st
->objfile
; /* Keep new_symbol happy */
3176 s
= new_symbol (MIPS_EFI_SYMBOL_NAME
);
3177 SYMBOL_VALUE (s
) = (int) e
;
3178 SYMBOL_NAMESPACE (s
) = LABEL_NAMESPACE
;
3179 SYMBOL_CLASS (s
) = LOC_CONST
;
3180 SYMBOL_TYPE (s
) = builtin_type_void
;
3181 current_objfile
= NULL
;
3184 BLOCK_SYM (b
, BLOCK_NSYMS (b
)++) = s
;
3188 /* Fake up identical offsets for all sections. */
3190 struct section_offsets
*
3191 mipscoff_symfile_offsets (objfile
, addr
)
3192 struct objfile
*objfile
;
3195 struct section_offsets
*section_offsets
;
3198 section_offsets
= ((struct section_offsets
*)
3199 obstack_alloc (&objfile
->psymbol_obstack
,
3200 (sizeof (struct section_offsets
)
3201 + (sizeof (section_offsets
->offsets
)
3202 * (SECT_OFF_MAX
- 1)))));
3204 for (i
= 0; i
< SECT_OFF_MAX
; i
++)
3205 ANOFFSET (section_offsets
, i
) = addr
;
3207 return section_offsets
;
3210 /* Initialization */
3212 static struct sym_fns ecoff_sym_fns
=
3214 "ecoff", /* sym_name: name or name prefix of BFD target type */
3215 5, /* sym_namelen: number of significant sym_name chars */
3216 mipscoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
3217 mipscoff_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
3218 mipscoff_symfile_read
, /* sym_read: read a symbol file into symtab */
3219 mipscoff_symfile_finish
, /* sym_finish: finished with file, cleanup */
3220 mipscoff_symfile_offsets
, /* sym_offsets: dummy FIXME til implem sym reloc */
3221 NULL
/* next: pointer to next struct sym_fns */
3226 _initialize_mipsread ()
3228 add_symtab_fns (&ecoff_sym_fns
);
3230 /* Missing basic types */
3232 builtin_type_string
=
3233 init_type (TYPE_CODE_STRING
,
3234 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3236 (struct objfile
*) NULL
);
3237 builtin_type_complex
=
3238 init_type (TYPE_CODE_FLT
,
3239 TARGET_COMPLEX_BIT
/ TARGET_CHAR_BIT
,
3241 (struct objfile
*) NULL
);
3242 builtin_type_double_complex
=
3243 init_type (TYPE_CODE_FLT
,
3244 TARGET_DOUBLE_COMPLEX_BIT
/ TARGET_CHAR_BIT
,
3245 0, "double complex",
3246 (struct objfile
*) NULL
);
3247 builtin_type_fixed_dec
=
3248 init_type (TYPE_CODE_INT
,
3249 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3251 (struct objfile
*) NULL
);
3252 builtin_type_float_dec
=
3253 init_type (TYPE_CODE_FLT
,
3254 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3255 0, "floating decimal",
3256 (struct objfile
*) NULL
);