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. */
56 #include "stabsread.h"
57 #include "complaints.h"
59 /* These are needed if the tm.h file does not contain the necessary
60 mips specific definitions. */
62 #ifndef MIPS_EFI_SYMBOL_NAME
63 #define MIPS_EFI_SYMBOL_NAME "__GDB_EFI_INFO__"
65 #include "coff/symconst.h"
66 typedef struct mips_extra_func_info
{
69 } *mips_extra_func_info_t
;
79 #include <sys/types.h>
82 #include <sys/param.h>
87 #include "gdb-stabs.h"
91 #include "coff/internal.h"
92 #include "coff/ecoff.h" /* COFF-like aspects of ecoff files */
94 /* FIXME: coff/internal.h and aout/aout64.h both define N_ABS. We
95 want the definition from aout/aout64.h. */
98 #include "libaout.h" /* Private BFD a.out information. */
99 #include "aout/aout64.h"
100 #include "aout/stab_gnu.h" /* STABS information */
102 /* FIXME: libcoff.h and libaout.h both define a couple of macros. We
105 #undef obj_sym_filepos
107 #include "libcoff.h" /* Private BFD COFF information. */
108 #include "libecoff.h" /* Private BFD ECOFF information. */
110 #include "expression.h"
111 #include "language.h" /* Needed inside partial-stab.h */
113 /* Each partial symbol table entry contains a pointer to private data
114 for the read_symtab() function to use when expanding a partial
115 symbol table entry to a full symbol table entry.
117 For mipsread this structure contains the index of the FDR that this
118 psymtab represents and a pointer to the BFD that the psymtab was
121 #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
122 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
123 #define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd)
129 EXTR
*extern_tab
; /* Pointer to external symbols for this file. */
130 int extern_count
; /* Size of extern_tab. */
131 struct mips_pending
**pending_list
;
132 enum language pst_language
;
135 /* Things we import explicitly from other modules */
137 extern int info_verbose
;
139 /* Various complaints about symbol reading that don't abort the process */
141 struct complaint bad_file_number_complaint
=
142 {"bad file number %d", 0, 0};
144 struct complaint index_complaint
=
145 {"bad aux index at symbol %s", 0, 0};
147 struct complaint aux_index_complaint
=
148 {"bad proc end in aux found from symbol %s", 0, 0};
150 struct complaint block_index_complaint
=
151 {"bad aux index at block symbol %s", 0, 0};
153 struct complaint unknown_ext_complaint
=
154 {"unknown external symbol %s", 0, 0};
156 struct complaint unknown_sym_complaint
=
157 {"unknown local symbol %s", 0, 0};
159 struct complaint unknown_st_complaint
=
160 {"with type %d", 0, 0};
162 struct complaint block_overflow_complaint
=
163 {"block containing %s overfilled", 0, 0};
165 struct complaint basic_type_complaint
=
166 {"cannot map MIPS basic type 0x%x for %s", 0, 0};
168 struct complaint unknown_type_qual_complaint
=
169 {"unknown type qualifier 0x%x", 0, 0};
171 struct complaint array_bitsize_complaint
=
172 {"size of array target type not known, assuming %d bits", 0, 0};
174 struct complaint bad_tag_guess_complaint
=
175 {"guessed tag type of %s incorrectly", 0, 0};
177 struct complaint block_member_complaint
=
178 {"declaration block contains unhandled symbol type %d", 0, 0};
180 struct complaint stEnd_complaint
=
181 {"stEnd with storage class %d not handled", 0, 0};
183 struct complaint unknown_mips_symtype_complaint
=
184 {"unknown symbol type 0x%x", 0, 0};
186 struct complaint stab_unknown_complaint
=
187 {"unknown stabs symbol %s", 0, 0};
189 struct complaint pdr_for_nonsymbol_complaint
=
190 {"PDR for %s, but no symbol", 0, 0};
192 struct complaint pdr_static_symbol_complaint
=
193 {"can't handle PDR for static proc at 0x%x", 0, 0};
195 struct complaint bad_setjmp_pdr_complaint
=
196 {"fixing bad setjmp PDR from libc", 0, 0};
198 struct complaint bad_fbitfield_complaint
=
199 {"can't handle TIR fBitfield for %s", 0, 0};
201 struct complaint bad_rfd_entry_complaint
=
202 {"bad rfd entry for %s: file %d, index %d", 0, 0};
204 struct complaint unexpected_type_code_complaint
=
205 {"unexpected type code for %s", 0, 0};
207 /* Macros and extra defs */
209 /* Already-parsed symbols are marked specially */
211 #define stParsed stType
213 /* Puns: hard to find whether -g was used and how */
215 #define MIN_GLEVEL GLEVEL_0
216 #define compare_glevel(a,b) \
217 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
218 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
220 /* Things that really are local to this module */
222 /* Remember what we deduced to be the source language of this psymtab. */
224 static enum language psymtab_language
= language_unknown
;
230 /* Pointer to current file decriptor record, and its index */
235 /* Index of current symbol */
239 /* Note how much "debuggable" this image is. We would like
240 to see at least one FDR with full symbols */
245 /* When examining .o files, report on undefined symbols */
247 static int n_undef_symbols
, n_undef_labels
, n_undef_vars
, n_undef_procs
;
249 /* Pseudo symbol to use when putting stabs into the symbol table. */
251 static char stabs_symbol
[] = STABS_SYMBOL
;
253 /* Extra builtin types */
255 struct type
*builtin_type_complex
;
256 struct type
*builtin_type_double_complex
;
257 struct type
*builtin_type_fixed_dec
;
258 struct type
*builtin_type_float_dec
;
259 struct type
*builtin_type_string
;
261 /* Forward declarations */
264 read_mips_symtab
PARAMS ((struct objfile
*, struct section_offsets
*));
267 read_the_mips_symtab
PARAMS ((bfd
*));
270 upgrade_type
PARAMS ((struct type
**, int, union aux_ext
*, int));
273 parse_partial_symbols
PARAMS ((struct objfile
*,
274 struct section_offsets
*));
277 cross_ref
PARAMS ((union aux_ext
*, struct type
**, enum type_code
, char **,
281 fixup_sigtramp
PARAMS ((void));
283 static struct symbol
*
284 new_symbol
PARAMS ((char *));
287 new_type
PARAMS ((char *));
289 static struct block
*
290 new_block
PARAMS ((int));
292 static struct symtab
*
293 new_symtab
PARAMS ((char *, int, int, struct objfile
*));
295 static struct linetable
*
296 new_linetable
PARAMS ((int));
298 static struct blockvector
*
299 new_bvect
PARAMS ((int));
302 parse_type
PARAMS ((union aux_ext
*, int *, int, char *));
304 static struct symbol
*
305 mylookup_symbol
PARAMS ((char *, struct block
*, enum namespace,
306 enum address_class
));
308 static struct block
*
309 shrink_block
PARAMS ((struct block
*, struct symtab
*));
312 xzalloc
PARAMS ((unsigned int));
315 sort_blocks
PARAMS ((struct symtab
*));
318 compare_blocks
PARAMS ((const void *, const void *));
320 static struct partial_symtab
*
321 new_psymtab
PARAMS ((char *, struct objfile
*));
324 psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*, char *));
327 add_block
PARAMS ((struct block
*, struct symtab
*));
330 add_symbol
PARAMS ((struct symbol
*, struct block
*));
333 add_line
PARAMS ((struct linetable
*, int, CORE_ADDR
, int));
335 static struct linetable
*
336 shrink_linetable
PARAMS ((struct linetable
*));
339 mips_next_symbol_text
PARAMS ((void));
341 /* Things we export to other modules */
343 /* Address bounds for the signal trampoline in inferior, if any */
344 /* FIXME: Nothing really seems to use this. Why is it here? */
346 CORE_ADDR sigtramp_address
, sigtramp_end
;
349 mipscoff_new_init (ignore
)
350 struct objfile
*ignore
;
352 sigtramp_address
= 0;
353 stabsread_new_init ();
354 buildsym_new_init ();
358 mipscoff_symfile_init (objfile
)
359 struct objfile
*objfile
;
361 if (objfile
->sym_private
!= NULL
)
363 mfree (objfile
->md
, objfile
->sym_private
);
365 objfile
->sym_private
= NULL
;
369 mipscoff_symfile_read (objfile
, section_offsets
, mainline
)
370 struct objfile
*objfile
;
371 struct section_offsets
*section_offsets
;
374 struct cleanup
* back_to
;
376 init_minimal_symbol_collection ();
377 back_to
= make_cleanup (discard_minimal_symbols
, 0);
379 /* Now that the executable file is positioned at symbol table,
380 process it and define symbols accordingly. */
382 read_mips_symtab (objfile
, section_offsets
);
384 /* Install any minimal symbols that have been collected as the current
385 minimal symbols for this objfile. */
387 install_minimal_symbols (objfile
);
389 do_cleanups (back_to
);
392 /* Perform any local cleanups required when we are done with a particular
393 objfile. I.E, we are in the process of discarding all symbol information
394 for an objfile, freeing up all memory held for it, and unlinking the
395 objfile struct from the global list of known objfiles. */
398 mipscoff_symfile_finish (objfile
)
399 struct objfile
*objfile
;
401 if (objfile
->sym_private
!= NULL
)
403 mfree (objfile
->md
, objfile
->sym_private
);
409 /* Allocate zeroed memory */
415 PTR p
= xmalloc (size
);
421 /* Exported procedure: Builds a symtab from the PST partial one.
422 Restores the environment in effect when PST was created, delegates
423 most of the work to an ancillary procedure, and sorts
424 and reorders the symtab list at the end */
427 mipscoff_psymtab_to_symtab (pst
)
428 struct partial_symtab
*pst
;
436 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
440 next_symbol_text_func
= mips_next_symbol_text
;
442 psymtab_to_symtab_1 (pst
, pst
->filename
);
444 /* Match with global symbols. This only needs to be done once,
445 after all of the symtabs and dependencies have been read in. */
446 scan_file_globals (pst
->objfile
);
449 printf_filtered ("done.\n");
452 /* Exported procedure: Is PC in the signal trampoline code */
455 in_sigtramp (pc
, ignore
)
457 char *ignore
; /* function name */
459 if (sigtramp_address
== 0)
461 return (pc
>= sigtramp_address
&& pc
< sigtramp_end
);
464 /* File-level interface functions */
466 /* Read the symtab information from file ABFD into memory. */
469 read_the_mips_symtab (abfd
)
472 if (ecoff_slurp_symbolic_info (abfd
) == false)
473 error ("Error reading symbol table: %s", bfd_errmsg (bfd_error
));
476 /* Find a file descriptor given its index RF relative to a file CF */
486 fdrs
= ecoff_data (cur_bfd
)->fdr
;
488 /* Object files do not have the RFD table, all refs are absolute */
491 (*ecoff_backend (cur_bfd
)->swap_rfd_in
)
493 ((char *) ecoff_data (cur_bfd
)->external_rfd
494 + (f
->rfdBase
+ rf
) * ecoff_backend (cur_bfd
)->external_rfd_size
),
499 /* Return a safer print NAME for a file descriptor */
506 return "<stripped file>";
509 return ecoff_data (cur_bfd
)->ss
+ f
->issBase
+ f
->rss
;
513 /* Read in and parse the symtab of the file OBJFILE. Symbols from
514 different sections are relocated via the SECTION_OFFSETS. */
517 read_mips_symtab (objfile
, section_offsets
)
518 struct objfile
*objfile
;
519 struct section_offsets
*section_offsets
;
521 cur_bfd
= objfile
->obfd
;
523 read_the_mips_symtab (objfile
->obfd
);
525 parse_partial_symbols (objfile
, section_offsets
);
528 /* Check to make sure file was compiled with -g. If not, warn the
529 user of this limitation. */
530 if (compare_glevel (max_glevel
, GLEVEL_2
) < 0)
532 if (max_gdbinfo
== 0)
533 printf ("\n%s not compiled with -g, debugging support is limited.\n",
535 printf ("You should compile with -g2 or -g3 for best debugging support.\n");
541 /* Local utilities */
543 /* Map of FDR indexes to partial symtabs */
547 struct partial_symtab
*pst
; /* the psymtab proper */
548 int n_globals
; /* exported globals (external symbols) */
549 int globals_offset
; /* cumulative */
553 /* Utility stack, used to nest procedures and blocks properly.
554 It is a doubly linked list, to avoid too many alloc/free.
555 Since we might need it quite a few times it is NOT deallocated
558 static struct parse_stack
560 struct parse_stack
*next
, *prev
;
561 struct symtab
*cur_st
; /* Current symtab. */
562 struct block
*cur_block
; /* Block in it. */
563 int blocktype
; /* What are we parsing. */
564 int maxsyms
; /* Max symbols in this block. */
565 struct type
*cur_type
; /* Type we parse fields for. */
566 int cur_field
; /* Field number in cur_type. */
567 int procadr
; /* Start addres of this procedure */
568 int numargs
; /* Its argument count */
571 *top_stack
; /* Top stack ptr */
574 /* Enter a new lexical context */
579 struct parse_stack
*new;
581 /* Reuse frames if possible */
582 if (top_stack
&& top_stack
->prev
)
583 new = top_stack
->prev
;
585 new = (struct parse_stack
*) xzalloc (sizeof (struct parse_stack
));
586 /* Initialize new frame with previous content */
589 register struct parse_stack
*prev
= new->prev
;
592 top_stack
->prev
= new;
594 new->next
= top_stack
;
599 /* Exit a lexical context */
607 top_stack
= top_stack
->next
;
611 /* Cross-references might be to things we haven't looked at
612 yet, e.g. type references. To avoid too many type
613 duplications we keep a quick fixup table, an array
614 of lists of references indexed by file descriptor */
616 static struct mips_pending
618 struct mips_pending
*next
; /* link */
619 char *s
; /* the unswapped symbol */
620 struct type
*t
; /* its partial type descriptor */
624 /* Check whether we already saw symbol SH in file FH as undefined */
626 static struct mips_pending
*
627 is_pending_symbol (fh
, sh
)
631 int f_idx
= fh
- ecoff_data (cur_bfd
)->fdr
;
632 register struct mips_pending
*p
;
634 /* Linear search is ok, list is typically no more than 10 deep */
635 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
641 /* Add a new undef symbol SH of type T */
644 add_pending (fh
, sh
, t
)
649 int f_idx
= fh
- ecoff_data (cur_bfd
)->fdr
;
650 struct mips_pending
*p
= is_pending_symbol (fh
, sh
);
652 /* Make sure we do not make duplicates */
655 p
= (struct mips_pending
*) xmalloc (sizeof (*p
));
658 p
->next
= pending_list
[f_idx
];
659 pending_list
[f_idx
] = p
;
663 /* Throw away undef entries when done with file index F_IDX */
664 /* FIXME -- storage leak. This is never called!!! --gnu */
672 register struct mips_pending
*p
, *q
;
674 for (p
= pending_list
[f_idx
]; p
; p
= q
)
679 pending_list
[f_idx
] = 0;
686 /* Parsing Routines proper. */
688 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
689 For blocks, procedures and types we open a new lexical context.
690 This is basically just a big switch on the symbol's type. Argument
691 AX is the base pointer of aux symbols for this file (fh->iauxBase).
692 EXT_SH points to the unswapped symbol, which is needed for struct,
693 union, etc., types; it is NULL for an EXTR. BIGEND says whether
694 aux symbols are big-endian or little-endian. Return count of
695 SYMR's handled (normally one).
697 FIXME: This modifies the symbol, but the only way we have to save
698 the modified information is to stuff it back into the BFD data. */
701 parse_symbol (sh
, ax
, ext_sh
, bigend
)
707 const bfd_size_type external_sym_size
708 = ecoff_backend (cur_bfd
)->external_sym_size
;
709 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*)) =
710 ecoff_backend (cur_bfd
)->swap_sym_in
;
714 struct mips_pending
*pend
;
718 enum address_class
class;
721 if (ext_sh
== (char *) NULL
)
722 name
= ecoff_data (cur_bfd
)->ssext
+ sh
->iss
;
724 name
= ecoff_data (cur_bfd
)->ss
+ cur_fdr
->issBase
+ sh
->iss
;
731 case stGlobal
: /* external symbol, goes into global block */
733 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack
->cur_st
),
735 s
= new_symbol (name
);
736 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
739 case stStatic
: /* static data, goes into current block. */
741 b
= top_stack
->cur_block
;
742 s
= new_symbol (name
);
743 if (sh
->sc
== scCommon
)
745 /* It is a FORTRAN common block. At least for SGI Fortran the
746 address is not in the symbol; we need to fix it later in
747 scan_file_globals. */
748 int bucket
= hashname (SYMBOL_NAME (s
));
749 SYMBOL_VALUE_CHAIN (s
) = global_sym_chain
[bucket
];
750 global_sym_chain
[bucket
] = s
;
753 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
756 case stLocal
: /* local variable, goes into current block */
757 if (sh
->sc
== scRegister
)
759 class = LOC_REGISTER
;
761 sh
->value
+= FP0_REGNUM
- 32;
765 b
= top_stack
->cur_block
;
766 s
= new_symbol (name
);
767 SYMBOL_VALUE (s
) = sh
->value
;
769 data
: /* Common code for symbols describing data */
770 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
771 SYMBOL_CLASS (s
) = class;
774 /* Type could be missing in a number of cases */
775 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
776 sh
->index
== 0xfffff)
777 SYMBOL_TYPE (s
) = builtin_type_int
; /* undefined? */
779 SYMBOL_TYPE (s
) = parse_type (ax
+ sh
->index
, 0, bigend
, name
);
780 /* Value of a data symbol is its memory address */
783 case stParam
: /* arg to procedure, goes into current block */
785 top_stack
->numargs
++;
787 /* Special GNU C++ name. */
788 if (name
[0] == CPLUS_MARKER
&& name
[1] == 't' && name
[2] == 0)
789 name
= "this"; /* FIXME, not alloc'd in obstack */
790 s
= new_symbol (name
);
792 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
796 /* Pass by value in register. */
797 SYMBOL_CLASS(s
) = LOC_REGPARM
;
799 sh
->value
+= FP0_REGNUM
-32;
802 /* Pass by reference on stack. */
803 SYMBOL_CLASS(s
) = LOC_REF_ARG
;
806 /* Pass by reference in register. */
807 SYMBOL_CLASS(s
) = LOC_REGPARM_ADDR
;
810 /* Pass by value on stack. */
811 SYMBOL_CLASS(s
) = LOC_ARG
;
814 SYMBOL_VALUE (s
) = sh
->value
;
815 SYMBOL_TYPE (s
) = parse_type (ax
+ sh
->index
, 0, bigend
, name
);
816 add_symbol (s
, top_stack
->cur_block
);
818 /* FIXME: This has not been tested. See dbxread.c */
819 /* Add the type of this parameter to the function/procedure
820 type of this block. */
821 add_param_to_type (&top_stack
->cur_block
->function
->type
, s
);
825 case stLabel
: /* label, goes into current block */
826 s
= new_symbol (name
);
827 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
; /* so that it can be used */
828 SYMBOL_CLASS (s
) = LOC_LABEL
; /* but not misused */
829 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
830 SYMBOL_TYPE (s
) = builtin_type_int
;
831 add_symbol (s
, top_stack
->cur_block
);
834 case stProc
: /* Procedure, usually goes into global block */
835 case stStaticProc
: /* Static procedure, goes into current block */
836 s
= new_symbol (name
);
837 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
838 SYMBOL_CLASS (s
) = LOC_BLOCK
;
839 /* Type of the return value */
840 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
841 t
= builtin_type_int
;
843 t
= parse_type (ax
+ sh
->index
+ 1, 0, bigend
, name
);
844 b
= top_stack
->cur_block
;
845 if (sh
->st
== stProc
)
847 struct blockvector
*bv
= BLOCKVECTOR (top_stack
->cur_st
);
848 /* The next test should normally be true,
849 but provides a hook for nested functions
850 (which we don't want to make global). */
851 if (b
== BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
))
852 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
856 /* Make a type for the procedure itself */
858 /* FIXME: This has not been tested yet! See dbxread.c */
859 /* Generate a template for the type of this function. The
860 types of the arguments will be added as we read the symbol
862 bcopy (SYMBOL_TYPE (s
), lookup_function_type (t
), sizeof (struct type
));
864 SYMBOL_TYPE (s
) = lookup_function_type (t
);
867 /* Create and enter a new lexical context */
868 b
= new_block (top_stack
->maxsyms
);
869 SYMBOL_BLOCK_VALUE (s
) = b
;
870 BLOCK_FUNCTION (b
) = s
;
871 BLOCK_START (b
) = BLOCK_END (b
) = sh
->value
;
872 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
873 add_block (b
, top_stack
->cur_st
);
875 /* Not if we only have partial info */
876 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
880 top_stack
->cur_block
= b
;
881 top_stack
->blocktype
= sh
->st
;
882 top_stack
->cur_type
= SYMBOL_TYPE (s
);
883 top_stack
->cur_field
= -1;
884 top_stack
->procadr
= sh
->value
;
885 top_stack
->numargs
= 0;
887 sh
->value
= (long) SYMBOL_TYPE (s
);
891 /* Beginning of code for structure, union, and enum definitions.
892 They all share a common set of local variables, defined here. */
894 enum type_code type_code
;
900 case stStruct
: /* Start a block defining a struct type */
901 type_code
= TYPE_CODE_STRUCT
;
902 goto structured_common
;
904 case stUnion
: /* Start a block defining a union type */
905 type_code
= TYPE_CODE_UNION
;
906 goto structured_common
;
908 case stEnum
: /* Start a block defining an enum type */
909 type_code
= TYPE_CODE_ENUM
;
910 goto structured_common
;
912 case stBlock
: /* Either a lexical block, or some type */
913 if (sh
->sc
!= scInfo
&& sh
->sc
!= scCommon
)
914 goto case_stBlock_code
; /* Lexical block */
916 type_code
= TYPE_CODE_UNDEF
; /* We have a type. */
918 /* Common code for handling struct, union, enum, and/or as-yet-
919 unknown-type blocks of info about structured data. `type_code'
920 has been set to the proper TYPE_CODE, if we know it. */
923 top_stack
->blocktype
= stBlock
;
925 s
= new_symbol (name
);
926 SYMBOL_NAMESPACE (s
) = STRUCT_NAMESPACE
;
927 SYMBOL_CLASS (s
) = LOC_TYPEDEF
;
928 SYMBOL_VALUE (s
) = 0;
929 add_symbol (s
, top_stack
->cur_block
);
931 /* First count the number of fields and the highest value. */
934 for (ext_tsym
= ext_sh
+ external_sym_size
;
936 ext_tsym
+= external_sym_size
)
940 (*swap_sym_in
) (cur_bfd
, ext_tsym
, &tsym
);
948 if (nfields
== 0 && type_code
== TYPE_CODE_UNDEF
)
949 /* If the type of the member is Nil (or Void),
950 without qualifiers, assume the tag is an
952 if (tsym
.index
== indexNil
)
953 type_code
= TYPE_CODE_ENUM
;
956 ecoff_swap_tir_in (bigend
,
957 &ax
[tsym
.index
].a_ti
,
959 if ((tir
.bt
== btNil
|| tir
.bt
== btVoid
)
961 type_code
= TYPE_CODE_ENUM
;
964 if (tsym
.value
> max_value
)
965 max_value
= tsym
.value
;
975 /* This is a no-op; is it trying to tell us something
976 we should be checking? */
977 if (tsym
.sc
== scVariant
); /*UNIMPLEMENTED*/
981 /* This is something like a struct within a
982 struct. Skip over the fields of the inner
983 struct. The -1 is because the for loop will
984 increment ext_tsym. */
985 ext_tsym
= ((char *) ecoff_data (cur_bfd
)->external_sym
986 + ((cur_fdr
->isymBase
+ tsym
.index
- 1)
987 * external_sym_size
));
993 /* mips cc puts out a typedef for struct x if it is not yet
994 defined when it encounters
995 struct y { struct x *xp; };
1000 complain (&block_member_complaint
, tsym
.st
);
1005 /* In an stBlock, there is no way to distinguish structs,
1006 unions, and enums at this point. This is a bug in the
1007 original design (that has been fixed with the recent
1008 addition of the stStruct, stUnion, and stEnum symbol
1009 types.) The way you can tell is if/when you see a variable
1010 or field of that type. In that case the variable's type
1011 (in the AUX table) says if the type is struct, union, or
1012 enum, and points back to the stBlock here. So you can
1013 patch the tag kind up later - but only if there actually is
1014 a variable or field of that type.
1016 So until we know for sure, we will guess at this point.
1018 If the first member has index==indexNil or a void type,
1019 assume we have an enumeration.
1020 Otherwise, if there is more than one member, and all
1021 the members have offset 0, assume we have a union.
1022 Otherwise, assume we have a struct.
1024 The heuristic could guess wrong in the case of of an
1025 enumeration with no members or a union with one (or zero)
1026 members, or when all except the last field of a struct have
1027 width zero. These are uncommon and/or illegal situations,
1028 and in any case guessing wrong probably doesn't matter
1031 But if we later do find out we were wrong, we fixup the tag
1032 kind. Members of an enumeration must be handled
1033 differently from struct/union fields, and that is harder to
1034 patch up, but luckily we shouldn't need to. (If there are
1035 any enumeration members, we can tell for sure it's an enum
1038 if (type_code
== TYPE_CODE_UNDEF
)
1039 if (nfields
> 1 && max_value
== 0)
1040 type_code
= TYPE_CODE_UNION
;
1042 type_code
= TYPE_CODE_STRUCT
;
1044 /* If this type was expected, use its partial definition */
1045 pend
= is_pending_symbol (cur_fdr
, ext_sh
);
1046 if (pend
!= (struct mips_pending
*) NULL
)
1049 t
= new_type (NULL
);
1051 TYPE_TAG_NAME (t
) = obconcat (¤t_objfile
->symbol_obstack
,
1053 TYPE_CODE (t
) = type_code
;
1054 TYPE_LENGTH (t
) = sh
->value
;
1055 TYPE_NFIELDS (t
) = nfields
;
1056 TYPE_FIELDS (t
) = f
= ((struct field
*)
1058 nfields
* sizeof (struct field
)));
1059 /* Handle opaque struct definitions. */
1060 if (TYPE_NFIELDS (t
) == 0)
1062 TYPE_FLAGS (t
) |= TYPE_FLAG_STUB
;
1063 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
1066 if (type_code
== TYPE_CODE_ENUM
)
1068 /* This is a non-empty enum. */
1069 for (ext_tsym
= ext_sh
+ external_sym_size
;
1071 ext_tsym
+= external_sym_size
)
1074 struct symbol
*enum_sym
;
1076 (*swap_sym_in
) (cur_bfd
, ext_tsym
, &tsym
);
1078 if (tsym
.st
!= stMember
)
1081 f
->bitpos
= tsym
.value
;
1083 f
->name
= (ecoff_data (cur_bfd
)->ss
1088 enum_sym
= ((struct symbol
*)
1089 obstack_alloc (¤t_objfile
->symbol_obstack
,
1090 sizeof (struct symbol
)));
1091 memset ((PTR
) enum_sym
, 0, sizeof (struct symbol
));
1092 SYMBOL_NAME (enum_sym
) = f
->name
;
1093 SYMBOL_CLASS (enum_sym
) = LOC_CONST
;
1094 SYMBOL_TYPE (enum_sym
) = t
;
1095 SYMBOL_NAMESPACE (enum_sym
) = VAR_NAMESPACE
;
1096 SYMBOL_VALUE (enum_sym
) = tsym
.value
;
1097 add_symbol (enum_sym
, top_stack
->cur_block
);
1099 /* Skip the stMembers that we've handled. */
1104 SYMBOL_TYPE (s
) = t
;
1105 /* make this the current type */
1106 top_stack
->cur_type
= t
;
1107 top_stack
->cur_field
= 0;
1108 /* Mark that symbol has a type, and say which one */
1109 sh
->value
= (long) t
;
1113 /* End of local variables shared by struct, union, enum, and
1114 block (as yet unknown struct/union/enum) processing. */
1118 /* beginnning of (code) block. Value of symbol
1119 is the displacement from procedure start */
1120 push_parse_stack ();
1121 top_stack
->blocktype
= stBlock
;
1122 b
= new_block (top_stack
->maxsyms
);
1123 BLOCK_START (b
) = sh
->value
+ top_stack
->procadr
;
1124 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
1125 top_stack
->cur_block
= b
;
1126 add_block (b
, top_stack
->cur_st
);
1129 case stEnd
: /* end (of anything) */
1130 if (sh
->sc
== scInfo
|| sh
->sc
== scCommon
)
1132 /* Finished with type */
1133 top_stack
->cur_type
= 0;
1135 else if (sh
->sc
== scText
&&
1136 (top_stack
->blocktype
== stProc
||
1137 top_stack
->blocktype
== stStaticProc
))
1139 /* Finished with procedure */
1140 struct blockvector
*bv
= BLOCKVECTOR (top_stack
->cur_st
);
1141 struct mips_extra_func_info
*e
;
1145 BLOCK_END (top_stack
->cur_block
) += sh
->value
; /* size */
1147 /* Make up special symbol to contain procedure specific info */
1148 s
= new_symbol (MIPS_EFI_SYMBOL_NAME
);
1149 SYMBOL_NAMESPACE (s
) = LABEL_NAMESPACE
;
1150 SYMBOL_CLASS (s
) = LOC_CONST
;
1151 SYMBOL_TYPE (s
) = builtin_type_void
;
1152 e
= ((struct mips_extra_func_info
*)
1153 obstack_alloc (¤t_objfile
->symbol_obstack
,
1154 sizeof (struct mips_extra_func_info
)));
1155 SYMBOL_VALUE (s
) = (int) e
;
1156 e
->numargs
= top_stack
->numargs
;
1157 add_symbol (s
, top_stack
->cur_block
);
1159 /* Reallocate symbols, saving memory */
1160 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
1162 /* f77 emits proc-level with address bounds==[0,0],
1163 So look for such child blocks, and patch them. */
1164 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS (bv
); i
++)
1166 struct block
*b_bad
= BLOCKVECTOR_BLOCK (bv
, i
);
1167 if (BLOCK_SUPERBLOCK (b_bad
) == b
1168 && BLOCK_START (b_bad
) == top_stack
->procadr
1169 && BLOCK_END (b_bad
) == top_stack
->procadr
)
1171 BLOCK_START (b_bad
) = BLOCK_START (b
);
1172 BLOCK_END (b_bad
) = BLOCK_END (b
);
1176 else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
)
1178 /* End of (code) block. The value of the symbol is the
1179 displacement from the procedure`s start address of the
1180 end of this block. */
1181 BLOCK_END (top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1182 shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
1184 else if (sh
->sc
== scText
&& top_stack
->blocktype
== stFile
)
1186 /* End of file. Pop parse stack and ignore. Higher
1187 level code deals with this. */
1191 complain (&stEnd_complaint
, sh
->sc
);
1193 pop_parse_stack (); /* restore previous lexical context */
1196 case stMember
: /* member of struct or union */
1197 f
= &TYPE_FIELDS (top_stack
->cur_type
)[top_stack
->cur_field
++];
1199 f
->bitpos
= sh
->value
;
1201 f
->type
= parse_type (ax
+ sh
->index
, &f
->bitsize
, bigend
, name
);
1204 case stTypedef
: /* type definition */
1205 s
= new_symbol (name
);
1206 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
1207 SYMBOL_CLASS (s
) = LOC_TYPEDEF
;
1208 SYMBOL_BLOCK_VALUE (s
) = top_stack
->cur_block
;
1209 add_symbol (s
, top_stack
->cur_block
);
1210 SYMBOL_TYPE (s
) = parse_type (ax
+ sh
->index
, 0, bigend
, name
);
1211 sh
->value
= (long) SYMBOL_TYPE (s
);
1213 if (TYPE_TAG_NAME (SYMBOL_TYPE (s
)) != NULL
1214 && STREQ (TYPE_TAG_NAME (SYMBOL_TYPE (s
)), "<undefined>"))
1216 /* mips cc puts out a stTypedef for opaque struct definitions. */
1217 TYPE_FLAGS (SYMBOL_TYPE (s
)) |= TYPE_FLAG_STUB
;
1219 /* Incomplete definitions of structs should not get a name. */
1220 if (TYPE_NAME (SYMBOL_TYPE (s
)) == NULL
1221 && (TYPE_NFIELDS (SYMBOL_TYPE (s
)) != 0
1222 || (TYPE_CODE (SYMBOL_TYPE (s
)) != TYPE_CODE_STRUCT
1223 && TYPE_CODE (SYMBOL_TYPE (s
)) != TYPE_CODE_UNION
)))
1225 if (TYPE_CODE (SYMBOL_TYPE (s
)) == TYPE_CODE_PTR
1226 || TYPE_CODE (SYMBOL_TYPE (s
)) == TYPE_CODE_FUNC
)
1228 /* If we are giving a name to a type such as "pointer to
1229 foo" or "function returning foo", we better not set
1230 the TYPE_NAME. If the program contains "typedef char
1231 *caddr_t;", we don't want all variables of type char
1232 * to print as caddr_t. This is not just a
1233 consequence of GDB's type management; CC and GCC (at
1234 least through version 2.4) both output variables of
1235 either type char * or caddr_t with the type
1236 refering to the stTypedef symbol for caddr_t. If a future
1237 compiler cleans this up it GDB is not ready for it
1238 yet, but if it becomes ready we somehow need to
1239 disable this check (without breaking the PCC/GCC2.4
1244 Fortunately, this check seems not to be necessary
1245 for anything except pointers or functions. */
1248 TYPE_NAME (SYMBOL_TYPE (s
)) = SYMBOL_NAME (s
);
1252 case stFile
: /* file name */
1253 push_parse_stack ();
1254 top_stack
->blocktype
= sh
->st
;
1257 /* I`ve never seen these for C */
1259 break; /* register relocation */
1261 break; /* forwarding address */
1263 break; /* constant */
1265 complain (&unknown_mips_symtype_complaint
, sh
->st
);
1272 /* Parse the type information provided in the raw AX entries for
1273 the symbol SH. Return the bitfield size in BS, in case.
1274 We must byte-swap the AX entries before we use them; BIGEND says whether
1275 they are big-endian or little-endian (from fh->fBigendian). */
1277 static struct type
*
1278 parse_type (ax
, bs
, bigend
, sym_name
)
1284 /* Null entries in this map are treated specially */
1285 static struct type
**map_bt
[] =
1287 &builtin_type_void
, /* btNil */
1289 &builtin_type_char
, /* btChar */
1290 &builtin_type_unsigned_char
,/* btUChar */
1291 &builtin_type_short
, /* btShort */
1292 &builtin_type_unsigned_short
, /* btUShort */
1293 &builtin_type_int
, /* btInt */
1294 &builtin_type_unsigned_int
, /* btUInt */
1295 &builtin_type_long
, /* btLong */
1296 &builtin_type_unsigned_long
,/* btULong */
1297 &builtin_type_float
, /* btFloat */
1298 &builtin_type_double
, /* btDouble */
1305 &builtin_type_complex
, /* btComplex */
1306 &builtin_type_double_complex
, /* btDComplex */
1308 &builtin_type_fixed_dec
, /* btFixedDec */
1309 &builtin_type_float_dec
, /* btFloatDec */
1310 &builtin_type_string
, /* btString */
1313 &builtin_type_void
, /* btVoid */
1314 &builtin_type_long_long
, /* btLongLong */
1315 &builtin_type_unsigned_long_long
, /* btULongLong */
1319 struct type
*tp
= 0;
1321 enum type_code type_code
= TYPE_CODE_UNDEF
;
1323 /* Use aux as a type information record, map its basic type. */
1325 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1326 if (t
->bt
>= (sizeof (map_bt
) / sizeof (*map_bt
)))
1328 complain (&basic_type_complaint
, t
->bt
, sym_name
);
1329 return builtin_type_int
;
1333 tp
= *map_bt
[t
->bt
];
1338 /* Cannot use builtin types -- build our own */
1342 tp
= lookup_pointer_type (builtin_type_void
);
1345 type_code
= TYPE_CODE_STRUCT
;
1348 type_code
= TYPE_CODE_UNION
;
1351 type_code
= TYPE_CODE_ENUM
;
1354 type_code
= TYPE_CODE_RANGE
;
1357 type_code
= TYPE_CODE_SET
;
1361 complain (&basic_type_complaint
, t
->bt
, sym_name
);
1362 return builtin_type_int
;
1366 /* Skip over any further type qualifiers (FIXME). */
1369 /* This is the way it would work if the compiler worked */
1374 ecoff_swap_tir_in (bigend
, &ax
->a_ti
, t1
);
1376 while (t1
->continued
);
1379 /* Move on to next aux */
1384 /* Inhibit core dumps with some cfront generated objects that
1386 if (bs
== (int *)NULL
)
1388 complain (&bad_fbitfield_complaint
, sym_name
);
1389 return builtin_type_int
;
1391 *bs
= AUX_GET_WIDTH (bigend
, ax
);
1395 /* All these types really point to some (common) MIPS type
1396 definition, and only the type-qualifiers fully identify
1397 them. We'll make the same effort at sharing. */
1398 if (t
->bt
== btStruct
||
1402 /* btSet (I think) implies that the name is a tag name, not a typedef
1403 name. This apparently is a MIPS extension for C sets. */
1408 /* Try to cross reference this type */
1409 ax
+= cross_ref (ax
, &tp
, type_code
, &name
, bigend
, sym_name
);
1410 /* reading .o file ? */
1411 if (tp
== (struct type
*) NULL
)
1412 tp
= init_type (type_code
, 0, 0, (char *) NULL
,
1413 (struct objfile
*) NULL
);
1415 /* Make sure that TYPE_CODE(tp) has an expected type code.
1416 Any type may be returned from cross_ref if file indirect entries
1418 if (TYPE_CODE (tp
) != TYPE_CODE_STRUCT
1419 && TYPE_CODE (tp
) != TYPE_CODE_UNION
1420 && TYPE_CODE (tp
) != TYPE_CODE_ENUM
)
1422 complain (&unexpected_type_code_complaint
, sym_name
);
1427 /* Usually, TYPE_CODE(tp) is already type_code. The main
1428 exception is if we guessed wrong re struct/union/enum. */
1429 if (TYPE_CODE (tp
) != type_code
)
1431 complain (&bad_tag_guess_complaint
, sym_name
);
1432 TYPE_CODE (tp
) = type_code
;
1434 /* Do not set the tag name if it is a compiler generated tag name
1435 (.Fxx or .xxfake or empty) for unnamed struct/union/enums. */
1436 if (name
[0] == '.' || name
[0] == '\0')
1437 TYPE_TAG_NAME (tp
) = NULL
;
1438 else if (TYPE_TAG_NAME (tp
) == NULL
1439 || !STREQ (TYPE_TAG_NAME (tp
), name
))
1440 TYPE_TAG_NAME (tp
) = obsavestring (name
, strlen (name
),
1441 ¤t_objfile
->type_obstack
);
1445 /* All these types really point to some (common) MIPS type
1446 definition, and only the type-qualifiers fully identify
1447 them. We'll make the same effort at sharing.
1448 FIXME: btIndirect cannot happen here as it is handled by the
1449 switch t->bt above. And we are not doing any guessing on range types. */
1450 if (t
->bt
== btIndirect
||
1455 /* Try to cross reference this type */
1456 ax
+= cross_ref (ax
, &tp
, type_code
, &name
, bigend
, sym_name
);
1457 /* reading .o file ? */
1458 if (tp
== (struct type
*) NULL
)
1459 tp
= init_type (type_code
, 0, 0, (char *) NULL
,
1460 (struct objfile
*) NULL
);
1462 /* Make sure that TYPE_CODE(tp) has an expected type code.
1463 Any type may be returned from cross_ref if file indirect entries
1465 if (TYPE_CODE (tp
) != TYPE_CODE_RANGE
)
1467 complain (&unexpected_type_code_complaint
, sym_name
);
1471 /* Usually, TYPE_CODE(tp) is already type_code. The main
1472 exception is if we guessed wrong re struct/union/enum. */
1473 if (TYPE_CODE (tp
) != type_code
)
1475 complain (&bad_tag_guess_complaint
, sym_name
);
1476 TYPE_CODE (tp
) = type_code
;
1478 if (TYPE_NAME (tp
) == NULL
|| !STREQ (TYPE_NAME (tp
), name
))
1479 TYPE_NAME (tp
) = obsavestring (name
, strlen (name
),
1480 ¤t_objfile
->type_obstack
);
1484 /* Deal with range types */
1485 if (t
->bt
== btRange
)
1487 TYPE_NFIELDS (tp
) = 2;
1488 TYPE_FIELDS (tp
) = ((struct field
*)
1489 TYPE_ALLOC (tp
, 2 * sizeof (struct field
)));
1490 TYPE_FIELD_NAME (tp
, 0) = obsavestring ("Low", strlen ("Low"),
1491 ¤t_objfile
->type_obstack
);
1492 TYPE_FIELD_BITPOS (tp
, 0) = AUX_GET_DNLOW (bigend
, ax
);
1494 TYPE_FIELD_NAME (tp
, 1) = obsavestring ("High", strlen ("High"),
1495 ¤t_objfile
->type_obstack
);
1496 TYPE_FIELD_BITPOS (tp
, 1) = AUX_GET_DNHIGH (bigend
, ax
);
1500 /* Parse all the type qualifiers now. If there are more
1501 than 6 the game will continue in the next aux */
1503 #define PARSE_TQ(tq) \
1504 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, bigend);
1506 again
:PARSE_TQ (tq0
);
1517 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1523 /* Make up a complex type from a basic one. Type is passed by
1524 reference in TPP and side-effected as necessary. The type
1525 qualifier TQ says how to handle the aux symbols at AX for
1526 the symbol SX we are currently analyzing. BIGEND says whether
1527 aux symbols are big-endian or little-endian.
1528 Returns the number of aux symbols we parsed. */
1531 upgrade_type (tpp
, tq
, ax
, bigend
)
1540 /* Used in array processing */
1551 t
= lookup_pointer_type (*tpp
);
1556 t
= lookup_function_type (*tpp
);
1563 /* Determine and record the domain type (type of index) */
1564 ecoff_swap_rndx_in (bigend
, &ax
->a_rndx
, &rndx
);
1570 rf
= AUX_GET_ISYM (bigend
, ax
);
1573 fh
= get_rfd (cur_fd
, rf
);
1575 indx
= parse_type ((ecoff_data (cur_bfd
)->external_aux
1578 (int *) NULL
, bigend
, "<array index>");
1580 /* Get the bounds, and create the array type. */
1582 lower
= AUX_GET_DNLOW (bigend
, ax
);
1584 upper
= AUX_GET_DNHIGH (bigend
, ax
);
1586 rf
= AUX_GET_WIDTH (bigend
, ax
); /* bit size of array element */
1588 range
= create_range_type ((struct type
*) NULL
, indx
,
1591 t
= create_array_type ((struct type
*) NULL
, *tpp
, range
);
1593 /* Check whether supplied array element bit size matches
1594 the known size of the element type. If this complaint
1595 ends up not happening, we can remove this code. It's
1596 here because we aren't sure we understand this *&%&$
1598 id
= TYPE_LENGTH (TYPE_TARGET_TYPE (t
)) << 3; /* bitsize */
1601 /* Most likely an undefined type */
1603 TYPE_LENGTH (TYPE_TARGET_TYPE (t
)) = id
>> 3;
1606 complain (&array_bitsize_complaint
, rf
);
1612 /* Volatile -- currently ignored */
1616 /* Const -- currently ignored */
1620 complain (&unknown_type_qual_complaint
, tq
);
1626 /* Parse a procedure descriptor record PR. Note that the procedure is
1627 parsed _after_ the local symbols, now we just insert the extra
1628 information we need into a MIPS_EFI_SYMBOL_NAME symbol that has
1629 already been placed in the procedure's main block. Note also that
1630 images that have been partially stripped (ld -x) have been deprived
1631 of local symbols, and we have to cope with them here. FIRST_OFF is
1632 the offset of the first procedure for this FDR; we adjust the
1633 address by this amount, but I don't know why. SEARCH_SYMTAB is the symtab
1634 to look for the function which contains the MIPS_EFI_SYMBOL_NAME symbol
1635 in question, or NULL to use top_stack->cur_block. */
1637 static void parse_procedure
PARAMS ((PDR
*, struct symtab
*, unsigned long));
1640 parse_procedure (pr
, search_symtab
, first_off
)
1642 struct symtab
*search_symtab
;
1643 unsigned long first_off
;
1645 struct symbol
*s
, *i
;
1647 struct mips_extra_func_info
*e
;
1650 /* Simple rule to find files linked "-x" */
1651 if (cur_fdr
->rss
== -1)
1655 /* Static procedure at address pr->adr. Sigh. */
1656 complain (&pdr_static_symbol_complaint
, pr
->adr
);
1664 (*ecoff_backend (cur_bfd
)->swap_ext_in
)
1666 ((char *) ecoff_data (cur_bfd
)->external_ext
1667 + pr
->isym
* ecoff_backend (cur_bfd
)->external_ext_size
),
1669 sh_name
= ecoff_data (cur_bfd
)->ssext
+ she
.asym
.iss
;
1677 (*ecoff_backend (cur_bfd
)->swap_sym_in
)
1679 ((char *) ecoff_data (cur_bfd
)->external_sym
1680 + ((cur_fdr
->isymBase
+ pr
->isym
)
1681 * ecoff_backend (cur_bfd
)->external_sym_size
)),
1683 sh_name
= ecoff_data (cur_bfd
)->ss
+ cur_fdr
->issBase
+ sh
.iss
;
1686 if (search_symtab
!= NULL
)
1689 /* This loses both in the case mentioned (want a static, find a global),
1690 but also if we are looking up a non-mangled name which happens to
1691 match the name of a mangled function. */
1692 /* We have to save the cur_fdr across the call to lookup_symbol.
1693 If the pdr is for a static function and if a global function with
1694 the same name exists, lookup_symbol will eventually read in the symtab
1695 for the global function and clobber cur_fdr. */
1696 FDR
*save_cur_fdr
= cur_fdr
;
1697 s
= lookup_symbol (sh_name
, NULL
, VAR_NAMESPACE
, 0, NULL
);
1698 cur_fdr
= save_cur_fdr
;
1702 BLOCKVECTOR_BLOCK (BLOCKVECTOR (search_symtab
), STATIC_BLOCK
),
1708 s
= mylookup_symbol (sh_name
, top_stack
->cur_block
,
1709 VAR_NAMESPACE
, LOC_BLOCK
);
1713 b
= SYMBOL_BLOCK_VALUE (s
);
1717 complain (&pdr_for_nonsymbol_complaint
, sh_name
);
1721 /* FIXME -- delete. We can't do symbol allocation now; it's all done. */
1722 s
= new_symbol (sh_name
);
1723 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
1724 SYMBOL_CLASS (s
) = LOC_BLOCK
;
1725 /* Donno its type, hope int is ok */
1726 SYMBOL_TYPE (s
) = lookup_function_type (builtin_type_int
);
1727 add_symbol (s
, top_stack
->cur_block
);
1728 /* Wont have symbols for this one */
1730 SYMBOL_BLOCK_VALUE (s
) = b
;
1731 BLOCK_FUNCTION (b
) = s
;
1732 BLOCK_START (b
) = pr
->adr
;
1733 /* BOUND used to be the end of procedure's text, but the
1734 argument is no longer passed in. */
1735 BLOCK_END (b
) = bound
;
1736 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
1737 add_block (b
, top_stack
->cur_st
);
1741 i
= mylookup_symbol (MIPS_EFI_SYMBOL_NAME
, b
, LABEL_NAMESPACE
, LOC_CONST
);
1745 e
= (struct mips_extra_func_info
*) SYMBOL_VALUE (i
);
1747 e
->pdr
.isym
= (long) s
;
1748 e
->pdr
.adr
+= cur_fdr
->adr
- first_off
;
1750 /* Correct incorrect setjmp procedure descriptor from the library
1751 to make backtrace through setjmp work. */
1752 if (e
->pdr
.pcreg
== 0 && strcmp (sh_name
, "setjmp") == 0)
1754 complain (&bad_setjmp_pdr_complaint
, 0);
1755 e
->pdr
.pcreg
= RA_REGNUM
;
1756 e
->pdr
.regmask
= 0x80000000;
1757 e
->pdr
.regoffset
= -4;
1762 /* Parse the external symbol ES. Just call parse_symbol() after
1763 making sure we know where the aux are for it. For procedures,
1764 parsing of the PDRs has already provided all the needed
1765 information, we only parse them if SKIP_PROCEDURES is false,
1766 and only if this causes no symbol duplication.
1767 BIGEND says whether aux entries are big-endian or little-endian.
1769 This routine clobbers top_stack->cur_block and ->cur_st. */
1772 parse_external (es
, skip_procedures
, bigend
)
1774 int skip_procedures
;
1779 if (es
->ifd
!= ifdNil
)
1782 cur_fdr
= ecoff_data (cur_bfd
)->fdr
+ cur_fd
;
1783 ax
= ecoff_data (cur_bfd
)->external_aux
+ cur_fdr
->iauxBase
;
1787 cur_fdr
= ecoff_data (cur_bfd
)->fdr
;
1791 /* Reading .o files */
1792 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
)
1795 switch (es
->asym
.st
)
1815 /* FIXME: Turn this into a complaint? */
1817 printf_filtered ("Warning: %s `%s' is undefined (in %s)\n",
1819 ecoff_data (cur_bfd
)->ssext
+ es
->asym
.iss
,
1820 fdr_name (cur_fdr
));
1824 switch (es
->asym
.st
)
1827 /* If we have full symbols we do not need more */
1828 if (skip_procedures
)
1830 if (mylookup_symbol (ecoff_data (cur_bfd
)->ssext
+ es
->asym
.iss
,
1831 top_stack
->cur_block
,
1832 VAR_NAMESPACE
, LOC_BLOCK
))
1837 /* Note that the case of a symbol with indexNil must be handled
1838 anyways by parse_symbol(). */
1839 parse_symbol (&es
->asym
, ax
, (char *) NULL
, bigend
);
1840 /* Note that parse_symbol changed es->asym. */
1847 /* Parse the line number info for file descriptor FH into
1848 GDB's linetable LT. MIPS' encoding requires a little bit
1849 of magic to get things out. Note also that MIPS' line
1850 numbers can go back and forth, apparently we can live
1851 with that and do not need to reorder our linetables */
1854 parse_lines (fh
, pr
, lt
)
1857 struct linetable
*lt
;
1859 unsigned char *base
;
1861 int delta
, count
, lineno
= 0;
1862 unsigned long first_off
= pr
->adr
;
1864 if (fh
->cbLine
== 0)
1867 base
= ecoff_data (cur_bfd
)->line
+ fh
->cbLineOffset
;
1869 /* Scan by procedure descriptors */
1871 for (j
= 0; j
< fh
->cpd
; j
++, pr
++)
1876 /* No code for this one */
1877 if (pr
->iline
== ilineNil
||
1878 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1881 /* Aurgh! To know where to stop expanding we must look-ahead. */
1882 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1883 if (pr
[l
].iline
!= -1)
1885 if (l
== (fh
->cpd
- j
))
1890 /* When procedures are moved around the linenumbers are
1891 attributed to the next procedure up. */
1892 if (pr
->iline
>= halt
)
1895 base
= ecoff_data (cur_bfd
)->line
+ fh
->cbLineOffset
+ pr
->cbLineOffset
;
1896 adr
= fh
->adr
+ pr
->adr
- first_off
;
1897 l
= adr
>> 2; /* in words */
1898 halt
+= (adr
>> 2) - pr
->iline
;
1899 for (lineno
= pr
->lnLow
; l
< halt
;)
1901 count
= *base
& 0x0f;
1902 delta
= *base
++ >> 4;
1907 delta
= (base
[0] << 8) | base
[1];
1908 if (delta
>= 0x8000)
1912 lineno
+= delta
; /* first delta is 0 */
1913 k
= add_line (lt
, lineno
, l
, k
);
1919 /* Master parsing procedure for first-pass reading of file symbols
1920 into a partial_symtab. */
1923 parse_partial_symbols (objfile
, section_offsets
)
1924 struct objfile
*objfile
;
1925 struct section_offsets
*section_offsets
;
1927 const struct ecoff_backend_data
* const backend
= ecoff_backend (cur_bfd
);
1928 const bfd_size_type external_sym_size
= backend
->external_sym_size
;
1929 const bfd_size_type external_rfd_size
= backend
->external_rfd_size
;
1930 const bfd_size_type external_ext_size
= backend
->external_ext_size
;
1931 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
1932 = backend
->swap_ext_in
;
1933 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
1934 = backend
->swap_sym_in
;
1935 void (* const swap_rfd_in
) PARAMS ((bfd
*, PTR
, RFDT
*))
1936 = backend
->swap_rfd_in
;
1938 HDRR
*hdr
= &ecoff_data (cur_bfd
)->symbolic_header
;
1939 /* Running pointers */
1944 register EXTR
*ext_in
;
1947 struct partial_symtab
*pst
;
1949 int past_first_source_file
= 0;
1951 /* List of current psymtab's include files */
1952 char **psymtab_include_list
;
1953 int includes_allocated
;
1956 struct pst_map
*fdr_to_pst
;
1957 /* Index within current psymtab dependency list */
1958 struct partial_symtab
**dependency_list
;
1959 int dependencies_used
, dependencies_allocated
;
1960 struct cleanup
*old_chain
;
1962 enum language prev_language
;
1964 extern_tab
= (EXTR
*) obstack_alloc (&objfile
->psymbol_obstack
,
1965 sizeof (EXTR
) * hdr
->iextMax
);
1967 includes_allocated
= 30;
1969 psymtab_include_list
= (char **) alloca (includes_allocated
*
1971 next_symbol_text_func
= mips_next_symbol_text
;
1973 dependencies_allocated
= 30;
1974 dependencies_used
= 0;
1976 (struct partial_symtab
**) alloca (dependencies_allocated
*
1977 sizeof (struct partial_symtab
*));
1979 last_source_file
= NULL
;
1984 * Only parse the Local and External symbols, and the Relative FDR.
1985 * Fixup enough of the loader symtab to be able to use it.
1986 * Allocate space only for the file's portions we need to
1991 max_glevel
= MIN_GLEVEL
;
1993 /* Allocate the map FDR -> PST.
1994 Minor hack: -O3 images might claim some global data belongs
1995 to FDR -1. We`ll go along with that */
1996 fdr_to_pst
= (struct pst_map
*) xzalloc ((hdr
->ifdMax
+ 1) * sizeof *fdr_to_pst
);
1997 old_chain
= make_cleanup (free
, fdr_to_pst
);
2000 struct partial_symtab
*pst
= new_psymtab ("", objfile
);
2001 fdr_to_pst
[-1].pst
= pst
;
2005 /* Pass 0 over external syms: swap them in. */
2006 ext_block
= (EXTR
*) xmalloc (hdr
->iextMax
* sizeof (EXTR
));
2007 make_cleanup (free
, ext_block
);
2009 ext_out
= (char *) ecoff_data (cur_bfd
)->external_ext
;
2010 ext_out_end
= ext_out
+ hdr
->iextMax
* external_ext_size
;
2012 for (; ext_out
< ext_out_end
; ext_out
+= external_ext_size
, ext_in
++)
2013 (*swap_ext_in
) (cur_bfd
, ext_out
, ext_in
);
2015 /* Pass 1 over external syms: Presize and partition the list */
2017 ext_in_end
= ext_in
+ hdr
->iextMax
;
2018 for (; ext_in
< ext_in_end
; ext_in
++)
2019 fdr_to_pst
[ext_in
->ifd
].n_globals
++;
2021 /* Pass 1.5 over files: partition out global symbol space */
2023 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++)
2025 fdr_to_pst
[f_idx
].globals_offset
= s_idx
;
2026 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
2027 fdr_to_pst
[f_idx
].n_globals
= 0;
2030 /* Pass 2 over external syms: fill in external symbols */
2032 ext_in_end
= ext_in
+ hdr
->iextMax
;
2033 for (; ext_in
< ext_in_end
; ext_in
++)
2035 enum minimal_symbol_type ms_type
= mst_text
;
2037 extern_tab
[fdr_to_pst
[ext_in
->ifd
].globals_offset
2038 + fdr_to_pst
[ext_in
->ifd
].n_globals
++] = *ext_in
;
2040 if (ext_in
->asym
.sc
== scUndefined
|| ext_in
->asym
.sc
== scNil
)
2043 name
= ecoff_data (cur_bfd
)->ssext
+ ext_in
->asym
.iss
;
2044 switch (ext_in
->asym
.st
)
2049 if (ext_in
->asym
.sc
== scData
2050 || ext_in
->asym
.sc
== scSData
2051 || ext_in
->asym
.sc
== scRData
)
2057 if (ext_in
->asym
.sc
== scAbs
)
2059 else if (ext_in
->asym
.sc
== scText
)
2061 else if (ext_in
->asym
.sc
== scData
2062 || ext_in
->asym
.sc
== scSData
2063 || ext_in
->asym
.sc
== scRData
)
2069 ms_type
= mst_unknown
;
2070 complain (&unknown_ext_complaint
, name
);
2072 prim_record_minimal_symbol (name
, ext_in
->asym
.value
, ms_type
);
2075 /* Pass 3 over files, over local syms: fill in static symbols */
2076 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++)
2078 struct partial_symtab
*save_pst
;
2081 cur_fdr
= fh
= ecoff_data (cur_bfd
)->fdr
+ f_idx
;
2085 fdr_to_pst
[f_idx
].pst
= NULL
;
2088 pst
= start_psymtab_common (objfile
, section_offsets
,
2090 fh
->cpd
? fh
->adr
: 0,
2091 objfile
->global_psymbols
.next
,
2092 objfile
->static_psymbols
.next
);
2093 pst
->read_symtab_private
= ((char *)
2094 obstack_alloc (&objfile
->psymbol_obstack
,
2095 sizeof (struct symloc
)));
2096 memset ((PTR
) pst
->read_symtab_private
, 0, sizeof (struct symloc
));
2099 FDR_IDX (pst
) = f_idx
;
2100 CUR_BFD (pst
) = cur_bfd
;
2102 /* The way to turn this into a symtab is to call... */
2103 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
2105 /* Set up language for the pst. Native ecoff has every header file in
2106 a separate FDR. deduce_language_from_filename will return
2107 language_unknown for a header file, which is not what we want.
2108 But the FDRs for the header files are after the FDR for the source
2109 file, so we can assign the language of the source file to the
2110 following header files. Then we save the language in the private
2111 pst data so that we can reuse it when building symtabs. */
2112 prev_language
= psymtab_language
;
2113 psymtab_language
= deduce_language_from_filename (fdr_name (fh
));
2114 if (psymtab_language
== language_unknown
)
2115 psymtab_language
= prev_language
;
2116 PST_PRIVATE (pst
)->pst_language
= psymtab_language
;
2118 pst
->texthigh
= pst
->textlow
;
2120 /* For stabs-in-ecoff files, the second symbol must be @stab.
2121 This symbol is emitted by mips-tfile to signal that the
2122 current object file uses encapsulated stabs instead of mips
2123 ecoff for local symbols. (It is the second symbol because
2124 the first symbol is the stFile used to signal the start of a
2126 processing_gcc_compilation
= 0;
2129 (*swap_sym_in
) (cur_bfd
,
2130 ((char *) ecoff_data (cur_bfd
)->external_sym
2131 + (fh
->isymBase
+ 1) * external_sym_size
),
2133 if (STREQ (ecoff_data (cur_bfd
)->ss
+ fh
->issBase
+ sh
.iss
,
2135 processing_gcc_compilation
= 2;
2138 if (processing_gcc_compilation
!= 0)
2140 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++)
2145 (*swap_sym_in
) (cur_bfd
,
2146 ((char *) ecoff_data (cur_bfd
)->external_sym
2147 + (fh
->isymBase
+ cur_sdx
) * external_sym_size
),
2149 type_code
= ECOFF_UNMARK_STAB (sh
.index
);
2150 if (!ECOFF_IS_STAB (&sh
))
2152 if (sh
.st
== stProc
|| sh
.st
== stStaticProc
)
2154 long procaddr
= sh
.value
;
2158 isym
= AUX_GET_ISYM (fh
->fBigendian
,
2159 (ecoff_data (cur_bfd
)->external_aux
2162 (*swap_sym_in
) (cur_bfd
,
2164 ecoff_data (cur_bfd
)->external_sym
)
2165 + ((fh
->isymBase
+ isym
- 1)
2166 * external_sym_size
)),
2170 long high
= procaddr
+ sh
.value
;
2171 if (high
> pst
->texthigh
)
2172 pst
->texthigh
= high
;
2177 #define SET_NAMESTRING() \
2178 namestring = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss
2179 #define CUR_SYMBOL_TYPE type_code
2180 #define CUR_SYMBOL_VALUE sh.value
2181 #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms)\
2183 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
2184 #define HANDLE_RBRAC(val) \
2185 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
2186 #include "partial-stab.h"
2191 for (cur_sdx
= 0; cur_sdx
< fh
->csym
;)
2194 enum address_class
class;
2196 (*swap_sym_in
) (cur_bfd
,
2197 ((char *) ecoff_data (cur_bfd
)->external_sym
2198 + ((fh
->isymBase
+ cur_sdx
)
2199 * external_sym_size
)),
2202 if (ECOFF_IS_STAB (&sh
))
2208 /* Non absolute static symbols go into the minimal table. */
2209 if (sh
.sc
== scUndefined
|| sh
.sc
== scNil
2210 || (sh
.index
== indexNil
2211 && (sh
.st
!= stStatic
|| sh
.sc
== scAbs
)))
2213 /* FIXME, premature? */
2218 name
= ecoff_data (cur_bfd
)->ss
+ fh
->issBase
+ sh
.iss
;
2226 case stStaticProc
: /* Function */
2227 /* I believe this is used only for file-local functions.
2228 The comment in symconst.h ("load time only static procs")
2229 isn't particularly clear on this point. */
2230 prim_record_minimal_symbol (name
, sh
.value
, mst_file_text
);
2233 case stProc
: /* Asm labels apparently */
2234 ADD_PSYMBOL_TO_LIST (name
, strlen (name
),
2235 VAR_NAMESPACE
, LOC_BLOCK
,
2236 objfile
->static_psymbols
, sh
.value
,
2237 psymtab_language
, objfile
);
2238 /* Skip over procedure to next one. */
2239 if (sh
.index
>= hdr
->iauxMax
)
2241 /* Should not happen, but does when cross-compiling
2242 with the MIPS compiler. FIXME -- pull later. */
2243 complain (&index_complaint
, name
);
2244 new_sdx
= cur_sdx
+ 1; /* Don't skip at all */
2247 new_sdx
= AUX_GET_ISYM (fh
->fBigendian
,
2248 (ecoff_data (cur_bfd
)->external_aux
2251 procaddr
= sh
.value
;
2253 if (new_sdx
<= cur_sdx
)
2255 /* This should not happen either... FIXME. */
2256 complain (&aux_index_complaint
, name
);
2257 new_sdx
= cur_sdx
+ 1; /* Don't skip backward */
2261 (*swap_sym_in
) (cur_bfd
,
2262 ((char *) ecoff_data (cur_bfd
)->external_sym
2263 + ((fh
->isymBase
+ cur_sdx
- 1)
2264 * external_sym_size
)),
2268 high
= procaddr
+ sh
.value
;
2269 if (high
> pst
->texthigh
)
2270 pst
->texthigh
= high
;
2273 case stStatic
: /* Variable */
2274 if (sh
.sc
== scData
|| sh
.sc
== scSData
|| sh
.sc
== scRData
)
2275 prim_record_minimal_symbol (name
, sh
.value
, mst_file_data
);
2277 prim_record_minimal_symbol (name
, sh
.value
, mst_file_bss
);
2281 case stTypedef
:/* Typedef */
2282 class = LOC_TYPEDEF
;
2285 case stConstant
: /* Constant decl */
2292 case stBlock
: /* { }, str, un, enum*/
2293 if (sh
.sc
== scInfo
|| sh
.sc
== scCommon
)
2295 ADD_PSYMBOL_TO_LIST (name
, strlen (name
),
2296 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2297 objfile
->static_psymbols
,
2299 psymtab_language
, objfile
);
2301 /* Skip over the block */
2303 if (new_sdx
<= cur_sdx
)
2305 /* This happens with the Ultrix kernel. */
2306 complain (&block_index_complaint
, name
);
2307 new_sdx
= cur_sdx
+ 1; /* Don't skip backward */
2312 case stFile
: /* File headers */
2313 case stLabel
: /* Labels */
2314 case stEnd
: /* Ends of files */
2317 case stLocal
: /* Local variables */
2318 /* Normally these are skipped because we skip over
2319 all blocks we see. However, these can occur
2320 as visible symbols in a .h file that contains code. */
2324 /* Both complaints are valid: one gives symbol name,
2325 the other the offending symbol type. */
2326 complain (&unknown_sym_complaint
, name
);
2327 complain (&unknown_st_complaint
, sh
.st
);
2331 /* Use this gdb symbol */
2332 ADD_PSYMBOL_TO_LIST (name
, strlen (name
),
2333 VAR_NAMESPACE
, class,
2334 objfile
->static_psymbols
, sh
.value
,
2335 psymtab_language
, objfile
);
2337 cur_sdx
++; /* Go to next file symbol */
2340 /* Now do enter the external symbols. */
2341 ext_ptr
= &extern_tab
[fdr_to_pst
[f_idx
].globals_offset
];
2342 cur_sdx
= fdr_to_pst
[f_idx
].n_globals
;
2343 PST_PRIVATE (save_pst
)->extern_count
= cur_sdx
;
2344 PST_PRIVATE (save_pst
)->extern_tab
= ext_ptr
;
2345 for (; --cur_sdx
>= 0; ext_ptr
++)
2347 enum address_class
class;
2351 if (ext_ptr
->ifd
!= f_idx
)
2353 psh
= &ext_ptr
->asym
;
2363 complain (&unknown_ext_complaint
,
2364 ecoff_data (cur_bfd
)->ssext
+ psh
->iss
);
2365 /* Fall through, pretend it's global. */
2370 name
= ecoff_data (cur_bfd
)->ssext
+ psh
->iss
;
2371 ADD_PSYMBOL_ADDR_TO_LIST (name
, strlen (name
),
2372 VAR_NAMESPACE
, class,
2373 objfile
->global_psymbols
, (CORE_ADDR
) psh
->value
,
2374 psymtab_language
, objfile
);
2378 /* Link pst to FDR. end_psymtab returns NULL if the psymtab was
2379 empty and put on the free list. */
2380 fdr_to_pst
[f_idx
].pst
= end_psymtab (save_pst
,
2381 psymtab_include_list
, includes_used
,
2382 -1, save_pst
->texthigh
,
2383 dependency_list
, dependencies_used
);
2384 if (objfile
->ei
.entry_point
>= save_pst
->textlow
&&
2385 objfile
->ei
.entry_point
< save_pst
->texthigh
)
2387 objfile
->ei
.entry_file_lowpc
= save_pst
->textlow
;
2388 objfile
->ei
.entry_file_highpc
= save_pst
->texthigh
;
2392 /* Now scan the FDRs for dependencies */
2393 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++)
2396 fh
= f_idx
+ ecoff_data (cur_bfd
)->fdr
;
2397 pst
= fdr_to_pst
[f_idx
].pst
;
2399 if (pst
== (struct partial_symtab
*)NULL
)
2402 /* This should catch stabs-in-ecoff. */
2407 { /* If there are no functions defined here ... */
2408 /* ...then presumably a .h file: drop reverse depends .h->.c */
2409 for (; s_id0
< fh
->crfd
; s_id0
++)
2413 (*swap_rfd_in
) (cur_bfd
,
2414 ((char *) ecoff_data (cur_bfd
)->external_rfd
2415 + (fh
->rfdBase
+ s_id0
) * external_rfd_size
),
2419 s_id0
++; /* Skip self-dependency */
2424 pst
->number_of_dependencies
= 0;
2426 ((struct partial_symtab
**)
2427 obstack_alloc (&objfile
->psymbol_obstack
,
2429 * sizeof (struct partial_symtab
*))));
2430 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++)
2434 (*swap_rfd_in
) (cur_bfd
,
2435 ((char *) ecoff_data (cur_bfd
)->external_rfd
2436 + (fh
->rfdBase
+ s_idx
) * external_rfd_size
),
2438 if (rh
< 0 || rh
>= hdr
->ifdMax
)
2440 complain (&bad_file_number_complaint
, rh
);
2444 /* Skip self-dependency. */
2448 /* Do not add to dependeny list if psymtab was empty. */
2449 if (fdr_to_pst
[rh
].pst
== (struct partial_symtab
*)NULL
)
2451 pst
->dependencies
[pst
->number_of_dependencies
++] = fdr_to_pst
[rh
].pst
;
2454 do_cleanups (old_chain
);
2459 mips_next_symbol_text ()
2464 (*ecoff_backend (cur_bfd
)->swap_sym_in
)
2466 ((char *) ecoff_data (cur_bfd
)->external_sym
2467 + ((cur_fdr
->isymBase
+ cur_sdx
)
2468 * ecoff_backend (cur_bfd
)->external_sym_size
)),
2470 return ecoff_data (cur_bfd
)->ss
+ cur_fdr
->issBase
+ sh
.iss
;
2473 /* Ancillary function to psymtab_to_symtab(). Does all the work
2474 for turning the partial symtab PST into a symtab, recurring
2475 first on all dependent psymtabs. The argument FILENAME is
2476 only passed so we can see in debug stack traces what file
2479 This function has a split personality, based on whether the
2480 symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
2481 The flow of control and even the memory allocation differs. FIXME. */
2484 psymtab_to_symtab_1 (pst
, filename
)
2485 struct partial_symtab
*pst
;
2488 const bfd_size_type external_sym_size
2489 = ecoff_backend (cur_bfd
)->external_sym_size
;
2490 const bfd_size_type external_pdr_size
2491 = ecoff_backend (cur_bfd
)->external_pdr_size
;
2492 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
2493 = ecoff_backend (cur_bfd
)->swap_sym_in
;
2494 void (* const swap_sym_out
) PARAMS ((bfd
*, const SYMR
*, PTR
))
2495 = ecoff_backend (cur_bfd
)->swap_sym_out
;
2496 void (* const swap_pdr_in
) PARAMS ((bfd
*, PTR
, PDR
*))
2497 = ecoff_backend (cur_bfd
)->swap_pdr_in
;
2501 struct linetable
*lines
;
2507 /* Read in all partial symbtabs on which this one is dependent.
2508 NOTE that we do have circular dependencies, sigh. We solved
2509 that by setting pst->readin before this point. */
2511 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2512 if (!pst
->dependencies
[i
]->readin
)
2514 /* Inform about additional files to be read in. */
2517 fputs_filtered (" ", stdout
);
2519 fputs_filtered ("and ", stdout
);
2521 printf_filtered ("%s...",
2522 pst
->dependencies
[i
]->filename
);
2523 wrap_here (""); /* Flush output */
2526 /* We only pass the filename for debug purposes */
2527 psymtab_to_symtab_1 (pst
->dependencies
[i
],
2528 pst
->dependencies
[i
]->filename
);
2531 /* Do nothing if this is a dummy psymtab. */
2533 if (pst
->n_global_syms
== 0 && pst
->n_static_syms
== 0
2534 && pst
->textlow
== 0 && pst
->texthigh
== 0)
2537 /* Now read the symbols for this symtab */
2539 cur_bfd
= CUR_BFD (pst
);
2540 current_objfile
= pst
->objfile
;
2541 cur_fd
= FDR_IDX (pst
);
2542 fh
= (cur_fd
== -1) ? (FDR
*) NULL
: ecoff_data (cur_bfd
)->fdr
+ cur_fd
;
2545 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2546 processing_gcc_compilation
= 0;
2547 if (fh
!= (FDR
*) NULL
&& fh
->csym
>= 2)
2551 (*swap_sym_in
) (cur_bfd
,
2552 ((char *) ecoff_data (cur_bfd
)->external_sym
2553 + (fh
->isymBase
+ 1) * external_sym_size
),
2555 if (STREQ (ecoff_data (cur_bfd
)->ss
+ fh
->issBase
+ sh
.iss
,
2558 /* We indicate that this is a GCC compilation so that certain
2559 features will be enabled in stabsread/dbxread. */
2560 processing_gcc_compilation
= 2;
2564 if (processing_gcc_compilation
!= 0)
2569 unsigned long first_off
;
2571 /* This symbol table contains stabs-in-ecoff entries. */
2573 /* Parse local symbols first */
2575 if (fh
->csym
<= 2) /* FIXME, this blows psymtab->symtab ptr */
2577 current_objfile
= NULL
;
2580 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++)
2586 (*swap_sym_in
) (cur_bfd
,
2587 ((char *) ecoff_data (cur_bfd
)->external_sym
2588 + (fh
->isymBase
+ cur_sdx
) * external_sym_size
),
2590 name
= ecoff_data (cur_bfd
)->ss
+ fh
->issBase
+ sh
.iss
;
2592 if (ECOFF_IS_STAB (&sh
))
2594 int type_code
= ECOFF_UNMARK_STAB (sh
.index
);
2595 process_one_symbol (type_code
, 0, valu
, name
,
2596 pst
->section_offsets
, pst
->objfile
);
2597 if (type_code
== N_FUN
)
2599 /* Make up special symbol to contain
2600 procedure specific info */
2601 struct mips_extra_func_info
*e
=
2602 ((struct mips_extra_func_info
*)
2603 obstack_alloc (¤t_objfile
->symbol_obstack
,
2604 sizeof (struct mips_extra_func_info
)));
2605 struct symbol
*s
= new_symbol (MIPS_EFI_SYMBOL_NAME
);
2606 SYMBOL_NAMESPACE (s
) = LABEL_NAMESPACE
;
2607 SYMBOL_CLASS (s
) = LOC_CONST
;
2608 SYMBOL_TYPE (s
) = builtin_type_void
;
2609 SYMBOL_VALUE (s
) = (int) e
;
2610 add_symbol_to_list (s
, &local_symbols
);
2613 else if (sh
.st
== stLabel
&& sh
.index
!= indexNil
)
2615 /* Handle encoded stab line number. */
2616 record_line (current_subfile
, sh
.index
, valu
);
2618 else if (sh
.st
== stProc
|| sh
.st
== stStaticProc
|| sh
.st
== stEnd
)
2619 /* These are generated by gcc-2.x, do not complain */
2622 complain (&stab_unknown_complaint
, name
);
2624 st
= end_symtab (pst
->texthigh
, 0, 0, pst
->objfile
, SECT_OFF_TEXT
);
2627 /* Sort the symbol table now, we are done adding symbols to it.
2628 We must do this before parse_procedure calls lookup_symbol. */
2629 sort_symtab_syms (st
);
2631 /* This may not be necessary for stabs symtabs. FIXME. */
2634 /* Fill in procedure info next. */
2636 pdr_ptr
= ((char *) ecoff_data (cur_bfd
)->external_pdr
2637 + fh
->ipdFirst
* external_pdr_size
);
2638 pdr_end
= pdr_ptr
+ fh
->cpd
* external_pdr_size
;
2639 for (; pdr_ptr
< pdr_end
; pdr_ptr
+= external_pdr_size
)
2643 (*swap_pdr_in
) (cur_bfd
, pdr_ptr
, &pr
);
2649 parse_procedure (&pr
, st
, first_off
);
2654 /* This symbol table contains ordinary ecoff entries. */
2656 /* FIXME: doesn't use pst->section_offsets. */
2662 /* How many symbols will we need */
2663 /* FIXME, this does not count enum values. */
2664 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
2668 st
= new_symtab ("unknown", f_max
, 0, pst
->objfile
);
2672 f_max
+= fh
->csym
+ fh
->cpd
;
2673 maxlines
= 2 * fh
->cline
;
2674 st
= new_symtab (pst
->filename
, 2 * f_max
, maxlines
, pst
->objfile
);
2676 /* The proper language was already determined when building
2677 the psymtab, use it. */
2678 st
->language
= PST_PRIVATE (pst
)->pst_language
;
2681 psymtab_language
= st
->language
;
2683 lines
= LINETABLE (st
);
2684 pending_list
= PST_PRIVATE (pst
)->pending_list
;
2685 if (pending_list
== 0)
2687 pending_list
= ((struct mips_pending
**)
2688 xzalloc (ecoff_data (cur_bfd
)->symbolic_header
.ifdMax
2689 * sizeof (struct mips_pending
*)));
2690 PST_PRIVATE (pst
)->pending_list
= pending_list
;
2693 /* Get a new lexical context */
2695 push_parse_stack ();
2696 top_stack
->cur_st
= st
;
2697 top_stack
->cur_block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (st
),
2699 BLOCK_START (top_stack
->cur_block
) = fh
? fh
->adr
: 0;
2700 BLOCK_END (top_stack
->cur_block
) = 0;
2701 top_stack
->blocktype
= stFile
;
2702 top_stack
->maxsyms
= 2 * f_max
;
2703 top_stack
->cur_type
= 0;
2704 top_stack
->procadr
= 0;
2705 top_stack
->numargs
= 0;
2712 /* Parse local symbols first */
2713 sym_ptr
= ((char *) ecoff_data (cur_bfd
)->external_sym
2714 + fh
->isymBase
* external_sym_size
);
2715 sym_end
= sym_ptr
+ fh
->csym
* external_sym_size
;
2716 while (sym_ptr
< sym_end
)
2721 (*swap_sym_in
) (cur_bfd
, sym_ptr
, &sh
);
2722 c
= parse_symbol (&sh
,
2723 (ecoff_data (cur_bfd
)->external_aux
2725 sym_ptr
, fh
->fBigendian
);
2726 /* FIXME: We must swap the modified symbol back out,
2727 although we would rather not. See parse_symbol. */
2728 (*swap_sym_out
) (cur_bfd
, &sh
, sym_ptr
);
2729 sym_ptr
+= c
* external_sym_size
;
2732 /* Linenumbers. At the end, check if we can save memory.
2733 parse_lines has to look ahead an arbitrary number of PDR
2734 structures, so we swap them all first. */
2738 struct cleanup
*old_chain
;
2744 pr_block
= (PDR
*) xmalloc (fh
->cpd
* sizeof (PDR
));
2746 old_chain
= make_cleanup (free
, pr_block
);
2748 pdr_ptr
= ((char *) ecoff_data (cur_bfd
)->external_pdr
2749 + fh
->ipdFirst
* external_pdr_size
);
2750 pdr_end
= pdr_ptr
+ fh
->cpd
* external_pdr_size
;
2754 pdr_ptr
+= external_pdr_size
, pdr_in
++)
2755 (*swap_pdr_in
) (cur_bfd
, pdr_ptr
, pdr_in
);
2757 parse_lines (fh
, pr_block
, lines
);
2758 if (lines
->nitems
< fh
->cline
)
2759 lines
= shrink_linetable (lines
);
2761 /* Fill in procedure info next. */
2763 pdr_in_end
= pdr_in
+ fh
->cpd
;
2764 for (; pdr_in
< pdr_in_end
; pdr_in
++)
2765 parse_procedure (pdr_in
, 0, pr_block
->adr
);
2767 do_cleanups (old_chain
);
2771 LINETABLE (st
) = lines
;
2773 /* .. and our share of externals.
2774 XXX use the global list to speed up things here. how?
2775 FIXME, Maybe quit once we have found the right number of ext's? */
2776 top_stack
->cur_st
= st
;
2777 top_stack
->cur_block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack
->cur_st
),
2779 top_stack
->blocktype
= stFile
;
2780 top_stack
->maxsyms
= (ecoff_data (cur_bfd
)->symbolic_header
.isymMax
2781 + ecoff_data (cur_bfd
)->symbolic_header
.ipdMax
2782 + ecoff_data (cur_bfd
)->symbolic_header
.iextMax
);
2784 ext_ptr
= PST_PRIVATE (pst
)->extern_tab
;
2785 for (i
= PST_PRIVATE (pst
)->extern_count
; --i
>= 0; ext_ptr
++)
2786 parse_external (ext_ptr
, 1, fh
->fBigendian
);
2788 /* If there are undefined, tell the user */
2789 if (n_undef_symbols
)
2791 printf_filtered ("File %s contains %d unresolved references:",
2792 st
->filename
, n_undef_symbols
);
2793 printf_filtered ("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2794 n_undef_vars
, n_undef_procs
, n_undef_labels
);
2795 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
2800 /* Sort the symbol table now, we are done adding symbols to it.*/
2801 sort_symtab_syms (st
);
2806 /* Now link the psymtab and the symtab. */
2809 current_objfile
= NULL
;
2812 /* Ancillary parsing procedures. */
2814 /* Lookup the type at relative index RN. Return it in TPP
2815 if found and in any event come up with its name PNAME.
2816 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
2817 Return value says how many aux symbols we ate. */
2820 cross_ref (ax
, tpp
, type_code
, pname
, bigend
, sym_name
)
2823 enum type_code type_code
; /* Use to alloc new type if none is found. */
2832 ecoff_swap_rndx_in (bigend
, &ax
->a_rndx
, rn
);
2834 /* Escape index means 'the next one' */
2835 if (rn
->rfd
== 0xfff)
2838 rf
= AUX_GET_ISYM (bigend
, ax
+ 1);
2848 *pname
= "<undefined>";
2853 * Find the relative file descriptor and the symbol in it
2855 FDR
*fh
= get_rfd (cur_fd
, rf
);
2860 if (rn
->index
>= fh
->csym
)
2862 /* File indirect entry is corrupt. */
2863 *tpp
= (struct type
*)NULL
;
2864 *pname
= "<illegal>";
2865 complain (&bad_rfd_entry_complaint
,
2866 sym_name
, fh
- ecoff_data (cur_bfd
)->fdr
, rn
->index
);
2870 /* If we have processed this symbol then we left a forwarding
2871 pointer to the corresponding GDB symbol. If not, we`ll put
2872 it in a list of pending symbols, to be processed later when
2873 the file will be. In any event, we collect the name for the
2874 type here. Which is why we made a first pass at strings. */
2876 esh
= ((char *) ecoff_data (cur_bfd
)->external_sym
2877 + ((fh
->isymBase
+ rn
->index
)
2878 * ecoff_backend (cur_bfd
)->external_sym_size
));
2879 (*ecoff_backend (cur_bfd
)->swap_sym_in
) (cur_bfd
, esh
, &sh
);
2881 /* Careful, we might be looking at .o files */
2883 *pname
= "<undefined>";
2884 else if (rn
->rfd
== 0xfff && rn
->index
== 0)
2885 /* For structs, unions and enums, rn->rfd is 0xfff and the index
2886 is a relative symbol number for the type, but an index of 0
2887 seems to mean that we don't know. This is said to fix a problem
2888 with "info func opendir" on an SGI showing
2889 "struct BSDopendir.c *BSDopendir();". */
2891 *tpp
= (struct type
*)NULL
;
2892 *pname
= "<unknown>";
2895 else if ((sh
.st
!= stBlock
&& sh
.st
!= stTypedef
&& sh
.st
!= stParsed
)
2898 /* File indirect entry is corrupt. */
2899 *tpp
= (struct type
*)NULL
;
2900 *pname
= "<illegal>";
2901 complain (&bad_rfd_entry_complaint
,
2902 sym_name
, fh
- ecoff_data (cur_bfd
)->fdr
, rn
->index
);
2906 *pname
= ecoff_data (cur_bfd
)->ss
+ fh
->issBase
+ sh
.iss
;
2908 /* Have we parsed it ? */
2909 if (sh
.value
!= 0 && sh
.st
== stParsed
)
2911 t
= (struct type
*) sh
.value
;
2916 /* Avoid duplicates */
2917 struct mips_pending
*p
= is_pending_symbol (fh
, esh
);
2922 *tpp
= init_type (type_code
, 0, 0, (char *) NULL
,
2923 (struct objfile
*) NULL
);
2924 add_pending (fh
, esh
, *tpp
);
2929 /* We used one auxent normally, two if we got a "next one" rf. */
2934 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2935 keeping the symtab sorted */
2937 static struct symbol
*
2938 mylookup_symbol (name
, block
, namespace, class)
2940 register struct block
*block
;
2941 enum namespace namespace;
2942 enum address_class
class;
2944 register int bot
, top
, inc
;
2945 register struct symbol
*sym
;
2948 top
= BLOCK_NSYMS (block
);
2952 sym
= BLOCK_SYM (block
, bot
);
2953 if (SYMBOL_NAME (sym
)[0] == inc
2954 && SYMBOL_NAMESPACE (sym
) == namespace
2955 && SYMBOL_CLASS (sym
) == class
2956 && strcmp (SYMBOL_NAME (sym
), name
) == 0)
2960 block
= BLOCK_SUPERBLOCK (block
);
2962 return mylookup_symbol (name
, block
, namespace, class);
2967 /* Add a new symbol S to a block B.
2968 Infrequently, we will need to reallocate the block to make it bigger.
2969 We only detect this case when adding to top_stack->cur_block, since
2970 that's the only time we know how big the block is. FIXME. */
2977 int nsyms
= BLOCK_NSYMS (b
)++;
2978 struct block
*origb
;
2979 struct parse_stack
*stackp
;
2981 if (b
== top_stack
->cur_block
&&
2982 nsyms
>= top_stack
->maxsyms
)
2984 complain (&block_overflow_complaint
, SYMBOL_NAME (s
));
2985 /* In this case shrink_block is actually grow_block, since
2986 BLOCK_NSYMS(b) is larger than its current size. */
2988 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
2990 /* Now run through the stack replacing pointers to the
2991 original block. shrink_block has already done this
2992 for the blockvector and BLOCK_FUNCTION. */
2993 for (stackp
= top_stack
; stackp
; stackp
= stackp
->next
)
2995 if (stackp
->cur_block
== origb
)
2997 stackp
->cur_block
= b
;
2998 stackp
->maxsyms
= BLOCK_NSYMS (b
);
3002 BLOCK_SYM (b
, nsyms
) = s
;
3005 /* Add a new block B to a symtab S */
3012 struct blockvector
*bv
= BLOCKVECTOR (s
);
3014 bv
= (struct blockvector
*) xrealloc ((PTR
) bv
,
3015 (sizeof (struct blockvector
)
3016 + BLOCKVECTOR_NBLOCKS (bv
)
3017 * sizeof (bv
->block
)));
3018 if (bv
!= BLOCKVECTOR (s
))
3019 BLOCKVECTOR (s
) = bv
;
3021 BLOCKVECTOR_BLOCK (bv
, BLOCKVECTOR_NBLOCKS (bv
)++) = b
;
3024 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
3025 MIPS' linenumber encoding might need more than one byte
3026 to describe it, LAST is used to detect these continuation lines.
3028 Combining lines with the same line number seems like a bad idea.
3029 E.g: There could be a line number entry with the same line number after the
3030 prologue and GDB should not ignore it (this is a better way to find
3031 a prologue than mips_skip_prologue).
3032 But due to the compressed line table format there are line number entries
3033 for the same line which are needed to bridge the gap to the next
3034 line number entry. These entries have a bogus address info with them
3035 and we are unable to tell them from intended duplicate line number
3037 This is another reason why -ggdb debugging format is preferable. */
3040 add_line (lt
, lineno
, adr
, last
)
3041 struct linetable
*lt
;
3047 last
= -2; /* make sure we record first line */
3049 if (last
== lineno
) /* skip continuation lines */
3052 lt
->item
[lt
->nitems
].line
= lineno
;
3053 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
3057 /* Sorting and reordering procedures */
3059 /* Blocks with a smaller low bound should come first */
3062 compare_blocks (arg1
, arg2
)
3063 const void *arg1
, *arg2
;
3065 register int addr_diff
;
3066 struct block
**b1
= (struct block
**) arg1
;
3067 struct block
**b2
= (struct block
**) arg2
;
3069 addr_diff
= (BLOCK_START ((*b1
))) - (BLOCK_START ((*b2
)));
3071 return (BLOCK_END ((*b2
))) - (BLOCK_END ((*b1
)));
3075 /* Sort the blocks of a symtab S.
3076 Reorder the blocks in the blockvector by code-address,
3077 as required by some MI search routines */
3083 struct blockvector
*bv
= BLOCKVECTOR (s
);
3085 if (BLOCKVECTOR_NBLOCKS (bv
) <= 2)
3088 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) == 0)
3089 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) = 0;
3090 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) == 0)
3091 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) = 0;
3095 * This is very unfortunate: normally all functions are compiled in
3096 * the order they are found, but if the file is compiled -O3 things
3097 * are very different. It would be nice to find a reliable test
3098 * to detect -O3 images in advance.
3100 if (BLOCKVECTOR_NBLOCKS (bv
) > 3)
3101 qsort (&BLOCKVECTOR_BLOCK (bv
, FIRST_LOCAL_BLOCK
),
3102 BLOCKVECTOR_NBLOCKS (bv
) - FIRST_LOCAL_BLOCK
,
3103 sizeof (struct block
*),
3107 register CORE_ADDR high
= 0;
3108 register int i
, j
= BLOCKVECTOR_NBLOCKS (bv
);
3110 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
3111 if (high
< BLOCK_END (BLOCKVECTOR_BLOCK (bv
, i
)))
3112 high
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, i
));
3113 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) = high
;
3116 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) =
3117 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, FIRST_LOCAL_BLOCK
));
3119 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) =
3120 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
3121 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) =
3122 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
3126 /* Constructor/restructor/destructor procedures */
3128 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
3129 MAXSYMS and linenumbers MAXLINES we'll put in it */
3131 static struct symtab
*
3132 new_symtab (name
, maxsyms
, maxlines
, objfile
)
3136 struct objfile
*objfile
;
3138 struct symtab
*s
= allocate_symtab (name
, objfile
);
3140 LINETABLE (s
) = new_linetable (maxlines
);
3142 /* All symtabs must have at least two blocks */
3143 BLOCKVECTOR (s
) = new_bvect (2);
3144 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
) = new_block (maxsyms
);
3145 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
) = new_block (maxsyms
);
3146 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)) =
3147 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3149 s
->free_code
= free_linetable
;
3154 /* Allocate a new partial_symtab NAME */
3156 static struct partial_symtab
*
3157 new_psymtab (name
, objfile
)
3159 struct objfile
*objfile
;
3161 struct partial_symtab
*psymtab
;
3163 psymtab
= allocate_psymtab (name
, objfile
);
3165 /* Keep a backpointer to the file's symbols */
3167 psymtab
->read_symtab_private
= ((char *)
3168 obstack_alloc (&objfile
->psymbol_obstack
,
3169 sizeof (struct symloc
)));
3170 memset ((PTR
) psymtab
->read_symtab_private
, 0, sizeof (struct symloc
));
3171 CUR_BFD (psymtab
) = cur_bfd
;
3173 /* The way to turn this into a symtab is to call... */
3174 psymtab
->read_symtab
= mipscoff_psymtab_to_symtab
;
3179 /* Allocate a linetable array of the given SIZE. Since the struct
3180 already includes one item, we subtract one when calculating the
3181 proper size to allocate. */
3183 static struct linetable
*
3184 new_linetable (size
)
3187 struct linetable
*l
;
3189 size
= (size
- 1) * sizeof (l
->item
) + sizeof (struct linetable
);
3190 l
= (struct linetable
*) xmalloc (size
);
3195 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
3196 I am not so sure about the 3.4 ones.
3198 Since the struct linetable already includes one item, we subtract one when
3199 calculating the proper size to allocate. */
3201 static struct linetable
*
3202 shrink_linetable (lt
)
3203 struct linetable
*lt
;
3206 return (struct linetable
*) xrealloc ((PTR
) lt
,
3207 (sizeof (struct linetable
)
3209 * sizeof (lt
->item
))));
3212 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
3214 static struct blockvector
*
3218 struct blockvector
*bv
;
3221 size
= sizeof (struct blockvector
) + nblocks
* sizeof (struct block
*);
3222 bv
= (struct blockvector
*) xzalloc (size
);
3224 BLOCKVECTOR_NBLOCKS (bv
) = nblocks
;
3229 /* Allocate and zero a new block of MAXSYMS symbols */
3231 static struct block
*
3235 int size
= sizeof (struct block
) + (maxsyms
- 1) * sizeof (struct symbol
*);
3237 return (struct block
*) xzalloc (size
);
3240 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
3241 Shrink_block can also be used by add_symbol to grow a block. */
3243 static struct block
*
3249 struct blockvector
*bv
= BLOCKVECTOR (s
);
3252 /* Just reallocate it and fix references to the old one */
3254 new = (struct block
*) xrealloc ((PTR
) b
,
3255 (sizeof (struct block
)
3256 + ((BLOCK_NSYMS (b
) - 1)
3257 * sizeof (struct symbol
*))));
3259 /* Should chase pointers to old one. Fortunately, that`s just
3260 the block`s function and inferior blocks */
3261 if (BLOCK_FUNCTION (new) && SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) == b
)
3262 SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) = new;
3263 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS (bv
); i
++)
3264 if (BLOCKVECTOR_BLOCK (bv
, i
) == b
)
3265 BLOCKVECTOR_BLOCK (bv
, i
) = new;
3266 else if (BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv
, i
)) == b
)
3267 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv
, i
)) = new;
3271 /* Create a new symbol with printname NAME */
3273 static struct symbol
*
3277 struct symbol
*s
= ((struct symbol
*)
3278 obstack_alloc (¤t_objfile
->symbol_obstack
,
3279 sizeof (struct symbol
)));
3281 memset ((PTR
) s
, 0, sizeof (*s
));
3282 SYMBOL_NAME (s
) = name
;
3283 SYMBOL_LANGUAGE (s
) = psymtab_language
;
3284 SYMBOL_INIT_DEMANGLED_NAME (s
, ¤t_objfile
->symbol_obstack
);
3288 /* Create a new type with printname NAME */
3290 static struct type
*
3296 t
= alloc_type (current_objfile
);
3297 TYPE_NAME (t
) = name
;
3298 TYPE_CPLUS_SPECIFIC (t
) = (struct cplus_struct_type
*) &cplus_struct_default
;
3303 /* Things used for calling functions in the inferior.
3304 These functions are exported to our companion
3305 mips-tdep.c file and are here because they play
3306 with the symbol-table explicitly. */
3308 /* Sigtramp: make sure we have all the necessary information
3309 about the signal trampoline code. Since the official code
3310 from MIPS does not do so, we make up that information ourselves.
3311 If they fix the library (unlikely) this code will neutralize itself. */
3318 struct block
*b
, *b0
;
3320 sigtramp_address
= -1;
3322 /* We have to handle the following cases here:
3323 a) The Mips library has a sigtramp label within sigvec.
3324 b) Irix has a _sigtramp which we want to use, but it also has sigvec. */
3325 s
= lookup_symbol ("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
3328 b0
= SYMBOL_BLOCK_VALUE (s
);
3329 s
= lookup_symbol ("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
3333 /* No sigvec or no sigtramp inside sigvec, try _sigtramp. */
3334 s
= lookup_symbol ("_sigtramp", 0, VAR_NAMESPACE
, 0, NULL
);
3337 /* But maybe this program uses its own version of sigvec */
3341 /* Did we or MIPSco fix the library ? */
3342 if (SYMBOL_CLASS (s
) == LOC_BLOCK
)
3344 sigtramp_address
= BLOCK_START (SYMBOL_BLOCK_VALUE (s
));
3345 sigtramp_end
= BLOCK_END (SYMBOL_BLOCK_VALUE (s
));
3349 sigtramp_address
= SYMBOL_VALUE (s
);
3350 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
3352 /* But what symtab does it live in ? */
3353 st
= find_pc_symtab (SYMBOL_VALUE (s
));
3356 * Ok, there goes the fix: turn it into a procedure, with all the
3357 * needed info. Note we make it a nested procedure of sigvec,
3358 * which is the way the (assembly) code is actually written.
3360 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
3361 SYMBOL_CLASS (s
) = LOC_BLOCK
;
3362 SYMBOL_TYPE (s
) = init_type (TYPE_CODE_FUNC
, 4, 0, (char *) NULL
,
3363 (struct objfile
*) NULL
);
3364 TYPE_TARGET_TYPE (SYMBOL_TYPE (s
)) = builtin_type_void
;
3366 /* Need a block to allocate MIPS_EFI_SYMBOL_NAME in */
3368 SYMBOL_BLOCK_VALUE (s
) = b
;
3369 BLOCK_START (b
) = sigtramp_address
;
3370 BLOCK_END (b
) = sigtramp_end
;
3371 BLOCK_FUNCTION (b
) = s
;
3372 BLOCK_SUPERBLOCK (b
) = BLOCK_SUPERBLOCK (b0
);
3376 /* Make a MIPS_EFI_SYMBOL_NAME entry for it */
3378 struct mips_extra_func_info
*e
=
3379 ((struct mips_extra_func_info
*)
3380 xzalloc (sizeof (struct mips_extra_func_info
)));
3382 e
->numargs
= 0; /* the kernel thinks otherwise */
3383 /* align_longword(sigcontext + SIGFRAME) */
3384 e
->pdr
.frameoffset
= 0x150;
3385 e
->pdr
.framereg
= SP_REGNUM
;
3386 /* read_next_frame_reg provides the true pc at the time of signal */
3387 e
->pdr
.pcreg
= PC_REGNUM
;
3388 e
->pdr
.regmask
= -2;
3389 e
->pdr
.regoffset
= -(41 * sizeof (int));
3390 e
->pdr
.fregmask
= -1;
3391 e
->pdr
.fregoffset
= -(7 * sizeof (int));
3392 e
->pdr
.isym
= (long) s
;
3393 e
->pdr
.adr
= sigtramp_address
;
3395 current_objfile
= st
->objfile
; /* Keep new_symbol happy */
3396 s
= new_symbol (MIPS_EFI_SYMBOL_NAME
);
3397 SYMBOL_VALUE (s
) = (int) e
;
3398 SYMBOL_NAMESPACE (s
) = LABEL_NAMESPACE
;
3399 SYMBOL_CLASS (s
) = LOC_CONST
;
3400 SYMBOL_TYPE (s
) = builtin_type_void
;
3401 current_objfile
= NULL
;
3404 BLOCK_SYM (b
, BLOCK_NSYMS (b
)++) = s
;
3408 /* Fake up identical offsets for all sections. */
3410 struct section_offsets
*
3411 mipscoff_symfile_offsets (objfile
, addr
)
3412 struct objfile
*objfile
;
3415 struct section_offsets
*section_offsets
;
3418 section_offsets
= ((struct section_offsets
*)
3419 obstack_alloc (&objfile
->psymbol_obstack
,
3420 (sizeof (struct section_offsets
)
3421 + (sizeof (section_offsets
->offsets
)
3422 * (SECT_OFF_MAX
- 1)))));
3424 for (i
= 0; i
< SECT_OFF_MAX
; i
++)
3425 ANOFFSET (section_offsets
, i
) = addr
;
3427 return section_offsets
;
3430 /* Initialization */
3432 static struct sym_fns ecoff_sym_fns
=
3434 "ecoff", /* sym_name: name or name prefix of BFD target type */
3435 5, /* sym_namelen: number of significant sym_name chars */
3436 mipscoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
3437 mipscoff_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
3438 mipscoff_symfile_read
, /* sym_read: read a symbol file into symtab */
3439 mipscoff_symfile_finish
, /* sym_finish: finished with file, cleanup */
3440 mipscoff_symfile_offsets
, /* sym_offsets: dummy FIXME til implem sym reloc */
3441 NULL
/* next: pointer to next struct sym_fns */
3446 _initialize_mipsread ()
3448 add_symtab_fns (&ecoff_sym_fns
);
3450 /* Missing basic types */
3452 builtin_type_string
=
3453 init_type (TYPE_CODE_STRING
,
3454 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3456 (struct objfile
*) NULL
);
3457 builtin_type_complex
=
3458 init_type (TYPE_CODE_FLT
,
3459 TARGET_COMPLEX_BIT
/ TARGET_CHAR_BIT
,
3461 (struct objfile
*) NULL
);
3462 builtin_type_double_complex
=
3463 init_type (TYPE_CODE_FLT
,
3464 TARGET_DOUBLE_COMPLEX_BIT
/ TARGET_CHAR_BIT
,
3465 0, "double complex",
3466 (struct objfile
*) NULL
);
3467 builtin_type_fixed_dec
=
3468 init_type (TYPE_CODE_INT
,
3469 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3471 (struct objfile
*) NULL
);
3472 builtin_type_float_dec
=
3473 init_type (TYPE_CODE_FLT
,
3474 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3475 0, "floating decimal",
3476 (struct objfile
*) NULL
);