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
;
134 /* Things we import explicitly from other modules */
136 extern int info_verbose
;
138 /* Various complaints about symbol reading that don't abort the process */
140 struct complaint bad_file_number_complaint
=
141 {"bad file number %d", 0, 0};
143 struct complaint index_complaint
=
144 {"bad aux index at symbol %s", 0, 0};
146 struct complaint aux_index_complaint
=
147 {"bad proc end in aux found from symbol %s", 0, 0};
149 struct complaint block_index_complaint
=
150 {"bad aux index at block symbol %s", 0, 0};
152 struct complaint unknown_ext_complaint
=
153 {"unknown external symbol %s", 0, 0};
155 struct complaint unknown_sym_complaint
=
156 {"unknown local symbol %s", 0, 0};
158 struct complaint unknown_st_complaint
=
159 {"with type %d", 0, 0};
161 struct complaint block_overflow_complaint
=
162 {"block containing %s overfilled", 0, 0};
164 struct complaint basic_type_complaint
=
165 {"cannot map MIPS basic type 0x%x", 0, 0};
167 struct complaint unknown_type_qual_complaint
=
168 {"unknown type qualifier 0x%x", 0, 0};
170 struct complaint array_bitsize_complaint
=
171 {"size of array target type not known, assuming %d bits", 0, 0};
173 struct complaint bad_tag_guess_complaint
=
174 {"guessed tag type of %s incorrectly", 0, 0};
176 struct complaint block_member_complaint
=
177 {"declaration block contains unhandled symbol type %d", 0, 0};
179 struct complaint stEnd_complaint
=
180 {"stEnd with storage class %d not handled", 0, 0};
182 struct complaint unknown_mips_symtype_complaint
=
183 {"unknown symbol type 0x%x", 0, 0};
185 struct complaint stab_unknown_complaint
=
186 {"unknown stabs symbol %s", 0, 0};
188 struct complaint pdr_for_nonsymbol_complaint
=
189 {"PDR for %s, but no symbol", 0, 0};
191 struct complaint pdr_static_symbol_complaint
=
192 {"can't handle PDR for static proc at 0x%x", 0, 0};
194 struct complaint bad_setjmp_pdr_complaint
=
195 {"fixing bad setjmp PDR from libc", 0, 0};
197 struct complaint bad_fbitfield_complaint
=
198 {"can't handle TIR fBitfield", 0, 0};
200 struct complaint bad_rfd_entry_complaint
=
201 {"bad rfd entry for file %d, index %d", 0, 0};
203 struct complaint unexpected_type_code_complaint
=
204 {"unexpected type code for %s", 0, 0};
206 /* Macros and extra defs */
208 /* Already-parsed symbols are marked specially */
210 #define stParsed stType
212 /* Puns: hard to find whether -g was used and how */
214 #define MIN_GLEVEL GLEVEL_0
215 #define compare_glevel(a,b) \
216 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
217 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
219 /* Things that really are local to this module */
221 /* Remember what we deduced to be the source language of this psymtab. */
223 static enum language psymtab_language
= language_unknown
;
229 /* Pointer to current file decriptor record, and its index */
234 /* Index of current symbol */
238 /* Note how much "debuggable" this image is. We would like
239 to see at least one FDR with full symbols */
244 /* When examining .o files, report on undefined symbols */
246 static int n_undef_symbols
, n_undef_labels
, n_undef_vars
, n_undef_procs
;
248 /* Pseudo symbol to use when putting stabs into the symbol table. */
250 static char stabs_symbol
[] = STABS_SYMBOL
;
252 /* Extra builtin types */
254 struct type
*builtin_type_complex
;
255 struct type
*builtin_type_double_complex
;
256 struct type
*builtin_type_fixed_dec
;
257 struct type
*builtin_type_float_dec
;
258 struct type
*builtin_type_string
;
260 /* Forward declarations */
263 read_mips_symtab
PARAMS ((struct objfile
*, struct section_offsets
*));
266 read_the_mips_symtab
PARAMS ((bfd
*));
269 upgrade_type
PARAMS ((struct type
**, int, union aux_ext
*, int));
272 parse_partial_symbols
PARAMS ((struct objfile
*,
273 struct section_offsets
*));
276 cross_ref
PARAMS ((union aux_ext
*, struct type
**, enum type_code
, char **,
280 fixup_sigtramp
PARAMS ((void));
282 static struct symbol
*
283 new_symbol
PARAMS ((char *));
286 new_type
PARAMS ((char *));
288 static struct block
*
289 new_block
PARAMS ((int));
291 static struct symtab
*
292 new_symtab
PARAMS ((char *, int, int, struct objfile
*));
294 static struct linetable
*
295 new_linetable
PARAMS ((int));
297 static struct blockvector
*
298 new_bvect
PARAMS ((int));
301 parse_type
PARAMS ((union aux_ext
*, int *, int));
303 static struct symbol
*
304 mylookup_symbol
PARAMS ((char *, struct block
*, enum namespace,
305 enum address_class
));
307 static struct block
*
308 shrink_block
PARAMS ((struct block
*, struct symtab
*));
311 xzalloc
PARAMS ((unsigned int));
314 sort_blocks
PARAMS ((struct symtab
*));
317 compare_blocks
PARAMS ((const void *, const void *));
319 static struct partial_symtab
*
320 new_psymtab
PARAMS ((char *, struct objfile
*));
323 static struct partial_symtab
*
324 parse_fdr
PARAMS ((int, int, struct objfile
*));
328 psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*, char *));
331 add_block
PARAMS ((struct block
*, struct symtab
*));
334 add_symbol
PARAMS ((struct symbol
*, struct block
*));
337 add_line
PARAMS ((struct linetable
*, int, CORE_ADDR
, int));
339 static struct linetable
*
340 shrink_linetable
PARAMS ((struct linetable
*));
343 mips_next_symbol_text
PARAMS ((void));
345 /* Things we export to other modules */
347 /* Address bounds for the signal trampoline in inferior, if any */
348 /* FIXME: Nothing really seems to use this. Why is it here? */
350 CORE_ADDR sigtramp_address
, sigtramp_end
;
353 mipscoff_new_init (ignore
)
354 struct objfile
*ignore
;
356 sigtramp_address
= 0;
357 stabsread_new_init ();
358 buildsym_new_init ();
362 mipscoff_symfile_init (objfile
)
363 struct objfile
*objfile
;
365 if (objfile
->sym_private
!= NULL
)
367 mfree (objfile
->md
, objfile
->sym_private
);
369 objfile
->sym_private
= NULL
;
373 mipscoff_symfile_read (objfile
, section_offsets
, mainline
)
374 struct objfile
*objfile
;
375 struct section_offsets
*section_offsets
;
378 struct cleanup
* back_to
;
380 init_minimal_symbol_collection ();
381 back_to
= make_cleanup (discard_minimal_symbols
, 0);
383 /* Now that the executable file is positioned at symbol table,
384 process it and define symbols accordingly. */
386 read_mips_symtab (objfile
, section_offsets
);
388 /* Install any minimal symbols that have been collected as the current
389 minimal symbols for this objfile. */
391 install_minimal_symbols (objfile
);
393 do_cleanups (back_to
);
396 /* Perform any local cleanups required when we are done with a particular
397 objfile. I.E, we are in the process of discarding all symbol information
398 for an objfile, freeing up all memory held for it, and unlinking the
399 objfile struct from the global list of known objfiles. */
402 mipscoff_symfile_finish (objfile
)
403 struct objfile
*objfile
;
405 if (objfile
->sym_private
!= NULL
)
407 mfree (objfile
->md
, objfile
->sym_private
);
413 /* Allocate zeroed memory */
419 PTR p
= xmalloc (size
);
425 /* Exported procedure: Builds a symtab from the PST partial one.
426 Restores the environment in effect when PST was created, delegates
427 most of the work to an ancillary procedure, and sorts
428 and reorders the symtab list at the end */
431 mipscoff_psymtab_to_symtab (pst
)
432 struct partial_symtab
*pst
;
440 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
444 next_symbol_text_func
= mips_next_symbol_text
;
446 psymtab_to_symtab_1 (pst
, pst
->filename
);
448 /* Match with global symbols. This only needs to be done once,
449 after all of the symtabs and dependencies have been read in. */
450 scan_file_globals (pst
->objfile
);
453 printf_filtered ("done.\n");
456 /* Exported procedure: Is PC in the signal trampoline code */
459 in_sigtramp (pc
, ignore
)
461 char *ignore
; /* function name */
463 if (sigtramp_address
== 0)
465 return (pc
>= sigtramp_address
&& pc
< sigtramp_end
);
468 /* File-level interface functions */
470 /* Read the symtab information from file ABFD into memory. */
473 read_the_mips_symtab (abfd
)
476 if (ecoff_slurp_symbolic_info (abfd
) == false)
477 error ("Error reading symbol table: %s", bfd_errmsg (bfd_error
));
480 /* Find a file descriptor given its index RF relative to a file CF */
490 fdrs
= ecoff_data (cur_bfd
)->fdr
;
492 /* Object files do not have the RFD table, all refs are absolute */
495 (*ecoff_backend (cur_bfd
)->swap_rfd_in
)
497 ((char *) ecoff_data (cur_bfd
)->external_rfd
498 + (f
->rfdBase
+ rf
) * ecoff_backend (cur_bfd
)->external_rfd_size
),
503 /* Return a safer print NAME for a file descriptor */
510 return "<stripped file>";
513 return ecoff_data (cur_bfd
)->ss
+ f
->issBase
+ f
->rss
;
517 /* Read in and parse the symtab of the file OBJFILE. Symbols from
518 different sections are relocated via the SECTION_OFFSETS. */
521 read_mips_symtab (objfile
, section_offsets
)
522 struct objfile
*objfile
;
523 struct section_offsets
*section_offsets
;
525 cur_bfd
= objfile
->obfd
;
527 read_the_mips_symtab (objfile
->obfd
);
529 parse_partial_symbols (objfile
, section_offsets
);
532 /* Check to make sure file was compiled with -g. If not, warn the
533 user of this limitation. */
534 if (compare_glevel (max_glevel
, GLEVEL_2
) < 0)
536 if (max_gdbinfo
== 0)
537 printf ("\n%s not compiled with -g, debugging support is limited.\n",
539 printf ("You should compile with -g2 or -g3 for best debugging support.\n");
545 /* Local utilities */
547 /* Map of FDR indexes to partial symtabs */
551 struct partial_symtab
*pst
; /* the psymtab proper */
552 int n_globals
; /* exported globals (external symbols) */
553 int globals_offset
; /* cumulative */
557 /* Utility stack, used to nest procedures and blocks properly.
558 It is a doubly linked list, to avoid too many alloc/free.
559 Since we might need it quite a few times it is NOT deallocated
562 static struct parse_stack
564 struct parse_stack
*next
, *prev
;
565 struct symtab
*cur_st
; /* Current symtab. */
566 struct block
*cur_block
; /* Block in it. */
567 int blocktype
; /* What are we parsing. */
568 int maxsyms
; /* Max symbols in this block. */
569 struct type
*cur_type
; /* Type we parse fields for. */
570 int cur_field
; /* Field number in cur_type. */
571 int procadr
; /* Start addres of this procedure */
572 int numargs
; /* Its argument count */
575 *top_stack
; /* Top stack ptr */
578 /* Enter a new lexical context */
583 struct parse_stack
*new;
585 /* Reuse frames if possible */
586 if (top_stack
&& top_stack
->prev
)
587 new = top_stack
->prev
;
589 new = (struct parse_stack
*) xzalloc (sizeof (struct parse_stack
));
590 /* Initialize new frame with previous content */
593 register struct parse_stack
*prev
= new->prev
;
596 top_stack
->prev
= new;
598 new->next
= top_stack
;
603 /* Exit a lexical context */
611 top_stack
= top_stack
->next
;
615 /* Cross-references might be to things we haven't looked at
616 yet, e.g. type references. To avoid too many type
617 duplications we keep a quick fixup table, an array
618 of lists of references indexed by file descriptor */
620 static struct mips_pending
622 struct mips_pending
*next
; /* link */
623 char *s
; /* the unswapped symbol */
624 struct type
*t
; /* its partial type descriptor */
628 /* Check whether we already saw symbol SH in file FH as undefined */
630 static struct mips_pending
*
631 is_pending_symbol (fh
, sh
)
635 int f_idx
= fh
- ecoff_data (cur_bfd
)->fdr
;
636 register struct mips_pending
*p
;
638 /* Linear search is ok, list is typically no more than 10 deep */
639 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
645 /* Add a new undef symbol SH of type T */
648 add_pending (fh
, sh
, t
)
653 int f_idx
= fh
- ecoff_data (cur_bfd
)->fdr
;
654 struct mips_pending
*p
= is_pending_symbol (fh
, sh
);
656 /* Make sure we do not make duplicates */
659 p
= (struct mips_pending
*) xmalloc (sizeof (*p
));
662 p
->next
= pending_list
[f_idx
];
663 pending_list
[f_idx
] = p
;
667 /* Throw away undef entries when done with file index F_IDX */
668 /* FIXME -- storage leak. This is never called!!! --gnu */
676 register struct mips_pending
*p
, *q
;
678 for (p
= pending_list
[f_idx
]; p
; p
= q
)
683 pending_list
[f_idx
] = 0;
690 /* Parsing Routines proper. */
692 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
693 For blocks, procedures and types we open a new lexical context.
694 This is basically just a big switch on the symbol's type. Argument
695 AX is the base pointer of aux symbols for this file (fh->iauxBase).
696 EXT_SH points to the unswapped symbol, which is needed for struct,
697 union, etc., types; it is NULL for an EXTR. BIGEND says whether
698 aux symbols are big-endian or little-endian. Return count of
699 SYMR's handled (normally one).
701 FIXME: This modifies the symbol, but the only way we have to save
702 the modified information is to stuff it back into the BFD data. */
705 parse_symbol (sh
, ax
, ext_sh
, bigend
)
711 const bfd_size_type external_sym_size
712 = ecoff_backend (cur_bfd
)->external_sym_size
;
713 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*)) =
714 ecoff_backend (cur_bfd
)->swap_sym_in
;
718 struct mips_pending
*pend
;
722 enum address_class
class;
725 if (ext_sh
== (char *) NULL
)
726 name
= ecoff_data (cur_bfd
)->ssext
+ sh
->iss
;
728 name
= ecoff_data (cur_bfd
)->ss
+ cur_fdr
->issBase
+ sh
->iss
;
735 case stGlobal
: /* external symbol, goes into global block */
737 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack
->cur_st
),
739 s
= new_symbol (name
);
740 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
743 case stStatic
: /* static data, goes into current block. */
745 b
= top_stack
->cur_block
;
746 s
= new_symbol (name
);
747 if (sh
->sc
== scCommon
)
749 /* It is a FORTRAN common block. At least for SGI Fortran the
750 address is not in the symbol; we need to fix it later in
751 scan_file_globals. */
752 int bucket
= hashname (SYMBOL_NAME (s
));
753 SYMBOL_VALUE_CHAIN (s
) = global_sym_chain
[bucket
];
754 global_sym_chain
[bucket
] = s
;
757 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
760 case stLocal
: /* local variable, goes into current block */
761 if (sh
->sc
== scRegister
)
763 class = LOC_REGISTER
;
765 sh
->value
+= FP0_REGNUM
- 32;
769 b
= top_stack
->cur_block
;
770 s
= new_symbol (name
);
771 SYMBOL_VALUE (s
) = sh
->value
;
773 data
: /* Common code for symbols describing data */
774 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
775 SYMBOL_CLASS (s
) = class;
778 /* Type could be missing in a number of cases */
779 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
780 sh
->index
== 0xfffff)
781 SYMBOL_TYPE (s
) = builtin_type_int
; /* undefined? */
783 SYMBOL_TYPE (s
) = parse_type (ax
+ sh
->index
, 0, bigend
);
784 /* Value of a data symbol is its memory address */
787 case stParam
: /* arg to procedure, goes into current block */
789 top_stack
->numargs
++;
791 /* Special GNU C++ name. */
792 if (name
[0] == CPLUS_MARKER
&& name
[1] == 't' && name
[2] == 0)
793 name
= "this"; /* FIXME, not alloc'd in obstack */
794 s
= new_symbol (name
);
796 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
800 /* Pass by value in register. */
801 SYMBOL_CLASS(s
) = LOC_REGPARM
;
803 sh
->value
+= FP0_REGNUM
-32;
806 /* Pass by reference on stack. */
807 SYMBOL_CLASS(s
) = LOC_REF_ARG
;
810 /* Pass by reference in register. */
811 SYMBOL_CLASS(s
) = LOC_REGPARM_ADDR
;
814 /* Pass by value on stack. */
815 SYMBOL_CLASS(s
) = LOC_ARG
;
818 SYMBOL_VALUE (s
) = sh
->value
;
819 SYMBOL_TYPE (s
) = parse_type (ax
+ sh
->index
, 0, bigend
);
820 add_symbol (s
, top_stack
->cur_block
);
822 /* FIXME: This has not been tested. See dbxread.c */
823 /* Add the type of this parameter to the function/procedure
824 type of this block. */
825 add_param_to_type (&top_stack
->cur_block
->function
->type
, s
);
829 case stLabel
: /* label, goes into current block */
830 s
= new_symbol (name
);
831 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
; /* so that it can be used */
832 SYMBOL_CLASS (s
) = LOC_LABEL
; /* but not misused */
833 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
834 SYMBOL_TYPE (s
) = builtin_type_int
;
835 add_symbol (s
, top_stack
->cur_block
);
838 case stProc
: /* Procedure, usually goes into global block */
839 case stStaticProc
: /* Static procedure, goes into current block */
840 s
= new_symbol (name
);
841 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
842 SYMBOL_CLASS (s
) = LOC_BLOCK
;
843 /* Type of the return value */
844 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
845 t
= builtin_type_int
;
847 t
= parse_type (ax
+ sh
->index
+ 1, 0, bigend
);
848 b
= top_stack
->cur_block
;
849 if (sh
->st
== stProc
)
851 struct blockvector
*bv
= BLOCKVECTOR (top_stack
->cur_st
);
852 /* The next test should normally be true,
853 but provides a hook for nested functions
854 (which we don't want to make global). */
855 if (b
== BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
))
856 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
860 /* Make a type for the procedure itself */
862 /* FIXME: This has not been tested yet! See dbxread.c */
863 /* Generate a template for the type of this function. The
864 types of the arguments will be added as we read the symbol
866 bcopy (SYMBOL_TYPE (s
), lookup_function_type (t
), sizeof (struct type
));
868 SYMBOL_TYPE (s
) = lookup_function_type (t
);
871 /* Create and enter a new lexical context */
872 b
= new_block (top_stack
->maxsyms
);
873 SYMBOL_BLOCK_VALUE (s
) = b
;
874 BLOCK_FUNCTION (b
) = s
;
875 BLOCK_START (b
) = BLOCK_END (b
) = sh
->value
;
876 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
877 add_block (b
, top_stack
->cur_st
);
879 /* Not if we only have partial info */
880 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
884 top_stack
->cur_block
= b
;
885 top_stack
->blocktype
= sh
->st
;
886 top_stack
->cur_type
= SYMBOL_TYPE (s
);
887 top_stack
->cur_field
= -1;
888 top_stack
->procadr
= sh
->value
;
889 top_stack
->numargs
= 0;
891 sh
->value
= (long) SYMBOL_TYPE (s
);
895 /* Beginning of code for structure, union, and enum definitions.
896 They all share a common set of local variables, defined here. */
898 enum type_code type_code
;
904 case stStruct
: /* Start a block defining a struct type */
905 type_code
= TYPE_CODE_STRUCT
;
906 goto structured_common
;
908 case stUnion
: /* Start a block defining a union type */
909 type_code
= TYPE_CODE_UNION
;
910 goto structured_common
;
912 case stEnum
: /* Start a block defining an enum type */
913 type_code
= TYPE_CODE_ENUM
;
914 goto structured_common
;
916 case stBlock
: /* Either a lexical block, or some type */
917 if (sh
->sc
!= scInfo
&& sh
->sc
!= scCommon
)
918 goto case_stBlock_code
; /* Lexical block */
920 type_code
= TYPE_CODE_UNDEF
; /* We have a type. */
922 /* Common code for handling struct, union, enum, and/or as-yet-
923 unknown-type blocks of info about structured data. `type_code'
924 has been set to the proper TYPE_CODE, if we know it. */
927 top_stack
->blocktype
= stBlock
;
929 s
= new_symbol (name
);
930 SYMBOL_NAMESPACE (s
) = STRUCT_NAMESPACE
;
931 SYMBOL_CLASS (s
) = LOC_TYPEDEF
;
932 SYMBOL_VALUE (s
) = 0;
933 add_symbol (s
, top_stack
->cur_block
);
935 /* First count the number of fields and the highest value. */
938 for (ext_tsym
= ext_sh
+ external_sym_size
;
940 ext_tsym
+= external_sym_size
)
944 (*swap_sym_in
) (cur_bfd
, ext_tsym
, &tsym
);
952 if (nfields
== 0 && type_code
== TYPE_CODE_UNDEF
)
953 /* If the type of the member is Nil (or Void),
954 without qualifiers, assume the tag is an
956 if (tsym
.index
== indexNil
)
957 type_code
= TYPE_CODE_ENUM
;
960 ecoff_swap_tir_in (bigend
,
961 &ax
[tsym
.index
].a_ti
,
963 if ((tir
.bt
== btNil
|| tir
.bt
== btVoid
)
965 type_code
= TYPE_CODE_ENUM
;
968 if (tsym
.value
> max_value
)
969 max_value
= tsym
.value
;
979 /* This is a no-op; is it trying to tell us something
980 we should be checking? */
981 if (tsym
.sc
== scVariant
); /*UNIMPLEMENTED*/
985 /* This is something like a struct within a
986 struct. Skip over the fields of the inner
987 struct. The -1 is because the for loop will
988 increment ext_tsym. */
989 ext_tsym
= ((char *) ecoff_data (cur_bfd
)->external_sym
990 + ((cur_fdr
->isymBase
+ tsym
.index
- 1)
991 * external_sym_size
));
997 /* mips cc puts out a typedef for struct x if it is not yet
998 defined when it encounters
999 struct y { struct x *xp; };
1004 complain (&block_member_complaint
, tsym
.st
);
1009 /* In an stBlock, there is no way to distinguish structs,
1010 unions, and enums at this point. This is a bug in the
1011 original design (that has been fixed with the recent
1012 addition of the stStruct, stUnion, and stEnum symbol
1013 types.) The way you can tell is if/when you see a variable
1014 or field of that type. In that case the variable's type
1015 (in the AUX table) says if the type is struct, union, or
1016 enum, and points back to the stBlock here. So you can
1017 patch the tag kind up later - but only if there actually is
1018 a variable or field of that type.
1020 So until we know for sure, we will guess at this point.
1022 If the first member has index==indexNil or a void type,
1023 assume we have an enumeration.
1024 Otherwise, if there is more than one member, and all
1025 the members have offset 0, assume we have a union.
1026 Otherwise, assume we have a struct.
1028 The heuristic could guess wrong in the case of of an
1029 enumeration with no members or a union with one (or zero)
1030 members, or when all except the last field of a struct have
1031 width zero. These are uncommon and/or illegal situations,
1032 and in any case guessing wrong probably doesn't matter
1035 But if we later do find out we were wrong, we fixup the tag
1036 kind. Members of an enumeration must be handled
1037 differently from struct/union fields, and that is harder to
1038 patch up, but luckily we shouldn't need to. (If there are
1039 any enumeration members, we can tell for sure it's an enum
1042 if (type_code
== TYPE_CODE_UNDEF
)
1043 if (nfields
> 1 && max_value
== 0)
1044 type_code
= TYPE_CODE_UNION
;
1046 type_code
= TYPE_CODE_STRUCT
;
1048 /* If this type was expected, use its partial definition */
1049 pend
= is_pending_symbol (cur_fdr
, ext_sh
);
1050 if (pend
!= (struct mips_pending
*) NULL
)
1053 t
= new_type (NULL
);
1055 TYPE_TAG_NAME (t
) = obconcat (¤t_objfile
->symbol_obstack
,
1057 TYPE_CODE (t
) = type_code
;
1058 TYPE_LENGTH (t
) = sh
->value
;
1059 TYPE_NFIELDS (t
) = nfields
;
1060 TYPE_FIELDS (t
) = f
= ((struct field
*)
1062 nfields
* sizeof (struct field
)));
1063 /* Handle opaque struct definitions. */
1064 if (TYPE_NFIELDS (t
) == 0)
1066 TYPE_FLAGS (t
) |= TYPE_FLAG_STUB
;
1067 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
1070 if (type_code
== TYPE_CODE_ENUM
)
1072 /* This is a non-empty enum. */
1073 for (ext_tsym
= ext_sh
+ external_sym_size
;
1075 ext_tsym
+= external_sym_size
)
1078 struct symbol
*enum_sym
;
1080 (*swap_sym_in
) (cur_bfd
, ext_tsym
, &tsym
);
1082 if (tsym
.st
!= stMember
)
1085 f
->bitpos
= tsym
.value
;
1087 f
->name
= (ecoff_data (cur_bfd
)->ss
1092 enum_sym
= ((struct symbol
*)
1093 obstack_alloc (¤t_objfile
->symbol_obstack
,
1094 sizeof (struct symbol
)));
1095 memset ((PTR
) enum_sym
, 0, sizeof (struct symbol
));
1096 SYMBOL_NAME (enum_sym
) = f
->name
;
1097 SYMBOL_CLASS (enum_sym
) = LOC_CONST
;
1098 SYMBOL_TYPE (enum_sym
) = t
;
1099 SYMBOL_NAMESPACE (enum_sym
) = VAR_NAMESPACE
;
1100 SYMBOL_VALUE (enum_sym
) = tsym
.value
;
1101 add_symbol (enum_sym
, top_stack
->cur_block
);
1103 /* Skip the stMembers that we've handled. */
1108 SYMBOL_TYPE (s
) = t
;
1109 /* make this the current type */
1110 top_stack
->cur_type
= t
;
1111 top_stack
->cur_field
= 0;
1112 /* Mark that symbol has a type, and say which one */
1113 sh
->value
= (long) t
;
1117 /* End of local variables shared by struct, union, enum, and
1118 block (as yet unknown struct/union/enum) processing. */
1122 /* beginnning of (code) block. Value of symbol
1123 is the displacement from procedure start */
1124 push_parse_stack ();
1125 top_stack
->blocktype
= stBlock
;
1126 b
= new_block (top_stack
->maxsyms
);
1127 BLOCK_START (b
) = sh
->value
+ top_stack
->procadr
;
1128 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
1129 top_stack
->cur_block
= b
;
1130 add_block (b
, top_stack
->cur_st
);
1133 case stEnd
: /* end (of anything) */
1134 if (sh
->sc
== scInfo
|| sh
->sc
== scCommon
)
1136 /* Finished with type */
1137 top_stack
->cur_type
= 0;
1139 else if (sh
->sc
== scText
&&
1140 (top_stack
->blocktype
== stProc
||
1141 top_stack
->blocktype
== stStaticProc
))
1143 /* Finished with procedure */
1144 struct blockvector
*bv
= BLOCKVECTOR (top_stack
->cur_st
);
1145 struct mips_extra_func_info
*e
;
1149 BLOCK_END (top_stack
->cur_block
) += sh
->value
; /* size */
1151 /* Make up special symbol to contain procedure specific info */
1152 s
= new_symbol (MIPS_EFI_SYMBOL_NAME
);
1153 SYMBOL_NAMESPACE (s
) = LABEL_NAMESPACE
;
1154 SYMBOL_CLASS (s
) = LOC_CONST
;
1155 SYMBOL_TYPE (s
) = builtin_type_void
;
1156 e
= ((struct mips_extra_func_info
*)
1157 obstack_alloc (¤t_objfile
->symbol_obstack
,
1158 sizeof (struct mips_extra_func_info
)));
1159 SYMBOL_VALUE (s
) = (int) e
;
1160 e
->numargs
= top_stack
->numargs
;
1161 add_symbol (s
, top_stack
->cur_block
);
1163 /* Reallocate symbols, saving memory */
1164 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
1166 /* f77 emits proc-level with address bounds==[0,0],
1167 So look for such child blocks, and patch them. */
1168 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS (bv
); i
++)
1170 struct block
*b_bad
= BLOCKVECTOR_BLOCK (bv
, i
);
1171 if (BLOCK_SUPERBLOCK (b_bad
) == b
1172 && BLOCK_START (b_bad
) == top_stack
->procadr
1173 && BLOCK_END (b_bad
) == top_stack
->procadr
)
1175 BLOCK_START (b_bad
) = BLOCK_START (b
);
1176 BLOCK_END (b_bad
) = BLOCK_END (b
);
1180 else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
)
1182 /* End of (code) block. The value of the symbol is the
1183 displacement from the procedure`s start address of the
1184 end of this block. */
1185 BLOCK_END (top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1186 shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
1188 else if (sh
->sc
== scText
&& top_stack
->blocktype
== stFile
)
1190 /* End of file. Pop parse stack and ignore. Higher
1191 level code deals with this. */
1195 complain (&stEnd_complaint
, sh
->sc
);
1197 pop_parse_stack (); /* restore previous lexical context */
1200 case stMember
: /* member of struct or union */
1201 f
= &TYPE_FIELDS (top_stack
->cur_type
)[top_stack
->cur_field
++];
1203 f
->bitpos
= sh
->value
;
1205 f
->type
= parse_type (ax
+ sh
->index
, &f
->bitsize
, bigend
);
1208 case stTypedef
: /* type definition */
1209 s
= new_symbol (name
);
1210 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
1211 SYMBOL_CLASS (s
) = LOC_TYPEDEF
;
1212 SYMBOL_BLOCK_VALUE (s
) = top_stack
->cur_block
;
1213 add_symbol (s
, top_stack
->cur_block
);
1214 SYMBOL_TYPE (s
) = parse_type (ax
+ sh
->index
, 0, bigend
);
1215 sh
->value
= (long) SYMBOL_TYPE (s
);
1217 if (TYPE_TAG_NAME (SYMBOL_TYPE (s
)) != NULL
1218 && STREQ (TYPE_TAG_NAME (SYMBOL_TYPE (s
)), "<undefined>"))
1220 /* mips cc puts out a stTypedef for opaque struct definitions. */
1221 TYPE_FLAGS (SYMBOL_TYPE (s
)) |= TYPE_FLAG_STUB
;
1223 /* Incomplete definitions of structs should not get a name. */
1224 if (TYPE_NAME (SYMBOL_TYPE (s
)) == NULL
1225 && (TYPE_NFIELDS (SYMBOL_TYPE (s
)) != 0
1226 || (TYPE_CODE (SYMBOL_TYPE (s
)) != TYPE_CODE_STRUCT
1227 && TYPE_CODE (SYMBOL_TYPE (s
)) != TYPE_CODE_UNION
)))
1229 if (TYPE_CODE (SYMBOL_TYPE (s
)) == TYPE_CODE_PTR
1230 || TYPE_CODE (SYMBOL_TYPE (s
)) == TYPE_CODE_FUNC
)
1232 /* If we are giving a name to a type such as "pointer to
1233 foo" or "function returning foo", we better not set
1234 the TYPE_NAME. If the program contains "typedef char
1235 *caddr_t;", we don't want all variables of type char
1236 * to print as caddr_t. This is not just a
1237 consequence of GDB's type management; CC and GCC (at
1238 least through version 2.4) both output variables of
1239 either type char * or caddr_t with the type
1240 refering to the stTypedef symbol for caddr_t. If a future
1241 compiler cleans this up it GDB is not ready for it
1242 yet, but if it becomes ready we somehow need to
1243 disable this check (without breaking the PCC/GCC2.4
1248 Fortunately, this check seems not to be necessary
1249 for anything except pointers or functions. */
1252 TYPE_NAME (SYMBOL_TYPE (s
)) = SYMBOL_NAME (s
);
1256 case stFile
: /* file name */
1257 push_parse_stack ();
1258 top_stack
->blocktype
= sh
->st
;
1261 /* I`ve never seen these for C */
1263 break; /* register relocation */
1265 break; /* forwarding address */
1267 break; /* constant */
1269 complain (&unknown_mips_symtype_complaint
, sh
->st
);
1276 /* Parse the type information provided in the raw AX entries for
1277 the symbol SH. Return the bitfield size in BS, in case.
1278 We must byte-swap the AX entries before we use them; BIGEND says whether
1279 they are big-endian or little-endian (from fh->fBigendian). */
1281 static struct type
*
1282 parse_type (ax
, bs
, bigend
)
1287 /* Null entries in this map are treated specially */
1288 static struct type
**map_bt
[] =
1290 &builtin_type_void
, /* btNil */
1292 &builtin_type_char
, /* btChar */
1293 &builtin_type_unsigned_char
,/* btUChar */
1294 &builtin_type_short
, /* btShort */
1295 &builtin_type_unsigned_short
, /* btUShort */
1296 &builtin_type_int
, /* btInt */
1297 &builtin_type_unsigned_int
, /* btUInt */
1298 &builtin_type_long
, /* btLong */
1299 &builtin_type_unsigned_long
,/* btULong */
1300 &builtin_type_float
, /* btFloat */
1301 &builtin_type_double
, /* btDouble */
1308 &builtin_type_complex
, /* btComplex */
1309 &builtin_type_double_complex
, /* btDComplex */
1311 &builtin_type_fixed_dec
, /* btFixedDec */
1312 &builtin_type_float_dec
, /* btFloatDec */
1313 &builtin_type_string
, /* btString */
1316 &builtin_type_void
, /* btVoid */
1317 &builtin_type_long_long
, /* btLongLong */
1318 &builtin_type_unsigned_long_long
, /* btULongLong */
1322 struct type
*tp
= 0;
1324 enum type_code type_code
= TYPE_CODE_UNDEF
;
1326 /* Use aux as a type information record, map its basic type. */
1328 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1329 if (t
->bt
> (sizeof (map_bt
) / sizeof (*map_bt
)))
1331 complain (&basic_type_complaint
, t
->bt
);
1332 return builtin_type_int
;
1336 tp
= *map_bt
[t
->bt
];
1341 /* Cannot use builtin types -- build our own */
1345 tp
= lookup_pointer_type (builtin_type_void
);
1348 type_code
= TYPE_CODE_STRUCT
;
1351 type_code
= TYPE_CODE_UNION
;
1354 type_code
= TYPE_CODE_ENUM
;
1357 type_code
= TYPE_CODE_RANGE
;
1360 type_code
= TYPE_CODE_SET
;
1364 complain (&basic_type_complaint
, t
->bt
);
1365 return builtin_type_int
;
1369 /* Skip over any further type qualifiers (FIXME). */
1372 /* This is the way it would work if the compiler worked */
1377 ecoff_swap_tir_in (bigend
, &ax
->a_ti
, t1
);
1379 while (t1
->continued
);
1382 /* Move on to next aux */
1387 /* Inhibit core dumps with some cfront generated objects that
1389 if (bs
== (int *)NULL
)
1391 complain (&bad_fbitfield_complaint
, t
->bt
);
1392 return builtin_type_int
;
1394 *bs
= AUX_GET_WIDTH (bigend
, ax
);
1398 /* All these types really point to some (common) MIPS type
1399 definition, and only the type-qualifiers fully identify
1400 them. We'll make the same effort at sharing. */
1401 if (t
->bt
== btStruct
||
1405 /* btSet (I think) implies that the name is a tag name, not a typedef
1406 name. This apparently is a MIPS extension for C sets. */
1411 /* Try to cross reference this type */
1412 ax
+= cross_ref (ax
, &tp
, type_code
, &name
, bigend
);
1413 /* reading .o file ? */
1414 if (tp
== (struct type
*) NULL
)
1415 tp
= init_type (type_code
, 0, 0, (char *) NULL
,
1416 (struct objfile
*) NULL
);
1418 /* Make sure that TYPE_CODE(tp) has an expected type code.
1419 Any type may be returned from cross_ref if file indirect entries
1421 if (TYPE_CODE (tp
) != TYPE_CODE_STRUCT
1422 && TYPE_CODE (tp
) != TYPE_CODE_UNION
1423 && TYPE_CODE (tp
) != TYPE_CODE_ENUM
)
1425 complain (&unexpected_type_code_complaint
, name
);
1430 /* Usually, TYPE_CODE(tp) is already type_code. The main
1431 exception is if we guessed wrong re struct/union/enum. */
1432 if (TYPE_CODE (tp
) != type_code
)
1434 complain (&bad_tag_guess_complaint
, name
);
1435 TYPE_CODE (tp
) = type_code
;
1437 /* Do not set the tag name if it is a compiler generated tag name
1438 (.Fxx or .xxfake or empty) for unnamed struct/union/enums. */
1439 if (name
[0] == '.' || name
[0] == '\0')
1440 TYPE_TAG_NAME (tp
) = NULL
;
1441 else if (TYPE_TAG_NAME (tp
) == NULL
1442 || !STREQ (TYPE_TAG_NAME (tp
), name
))
1443 TYPE_TAG_NAME (tp
) = obsavestring (name
, strlen (name
),
1444 ¤t_objfile
->type_obstack
);
1448 /* All these types really point to some (common) MIPS type
1449 definition, and only the type-qualifiers fully identify
1450 them. We'll make the same effort at sharing.
1451 FIXME: btIndirect cannot happen here as it is handled by the
1452 switch t->bt above. And we are not doing any guessing on range types. */
1453 if (t
->bt
== btIndirect
||
1458 /* Try to cross reference this type */
1459 ax
+= cross_ref (ax
, &tp
, type_code
, &name
, bigend
);
1460 /* reading .o file ? */
1461 if (tp
== (struct type
*) NULL
)
1462 tp
= init_type (type_code
, 0, 0, (char *) NULL
,
1463 (struct objfile
*) NULL
);
1465 /* Make sure that TYPE_CODE(tp) has an expected type code.
1466 Any type may be returned from cross_ref if file indirect entries
1468 if (TYPE_CODE (tp
) != TYPE_CODE_RANGE
)
1470 complain (&unexpected_type_code_complaint
, name
);
1474 /* Usually, TYPE_CODE(tp) is already type_code. The main
1475 exception is if we guessed wrong re struct/union/enum. */
1476 if (TYPE_CODE (tp
) != type_code
)
1478 complain (&bad_tag_guess_complaint
, name
);
1479 TYPE_CODE (tp
) = type_code
;
1481 if (TYPE_NAME (tp
) == NULL
|| !STREQ (TYPE_NAME (tp
), name
))
1482 TYPE_NAME (tp
) = obsavestring (name
, strlen (name
),
1483 ¤t_objfile
->type_obstack
);
1487 /* Deal with range types */
1488 if (t
->bt
== btRange
)
1490 TYPE_NFIELDS (tp
) = 2;
1491 TYPE_FIELDS (tp
) = ((struct field
*)
1492 TYPE_ALLOC (tp
, 2 * sizeof (struct field
)));
1493 TYPE_FIELD_NAME (tp
, 0) = obsavestring ("Low", strlen ("Low"),
1494 ¤t_objfile
->type_obstack
);
1495 TYPE_FIELD_BITPOS (tp
, 0) = AUX_GET_DNLOW (bigend
, ax
);
1497 TYPE_FIELD_NAME (tp
, 1) = obsavestring ("High", strlen ("High"),
1498 ¤t_objfile
->type_obstack
);
1499 TYPE_FIELD_BITPOS (tp
, 1) = AUX_GET_DNHIGH (bigend
, ax
);
1503 /* Parse all the type qualifiers now. If there are more
1504 than 6 the game will continue in the next aux */
1506 #define PARSE_TQ(tq) \
1507 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, bigend);
1509 again
:PARSE_TQ (tq0
);
1520 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1526 /* Make up a complex type from a basic one. Type is passed by
1527 reference in TPP and side-effected as necessary. The type
1528 qualifier TQ says how to handle the aux symbols at AX for
1529 the symbol SX we are currently analyzing. BIGEND says whether
1530 aux symbols are big-endian or little-endian.
1531 Returns the number of aux symbols we parsed. */
1534 upgrade_type (tpp
, tq
, ax
, bigend
)
1543 /* Used in array processing */
1554 t
= lookup_pointer_type (*tpp
);
1559 t
= lookup_function_type (*tpp
);
1566 /* Determine and record the domain type (type of index) */
1567 ecoff_swap_rndx_in (bigend
, &ax
->a_rndx
, &rndx
);
1573 rf
= AUX_GET_ISYM (bigend
, ax
);
1576 fh
= get_rfd (cur_fd
, rf
);
1578 indx
= parse_type ((ecoff_data (cur_bfd
)->external_aux
1581 (int *) NULL
, bigend
);
1583 /* Get the bounds, and create the array type. */
1585 lower
= AUX_GET_DNLOW (bigend
, ax
);
1587 upper
= AUX_GET_DNHIGH (bigend
, ax
);
1589 rf
= AUX_GET_WIDTH (bigend
, ax
); /* bit size of array element */
1591 range
= create_range_type ((struct type
*) NULL
, indx
,
1594 t
= create_array_type ((struct type
*) NULL
, *tpp
, range
);
1596 /* Check whether supplied array element bit size matches
1597 the known size of the element type. If this complaint
1598 ends up not happening, we can remove this code. It's
1599 here because we aren't sure we understand this *&%&$
1601 id
= TYPE_LENGTH (TYPE_TARGET_TYPE (t
)) << 3; /* bitsize */
1604 /* Most likely an undefined type */
1606 TYPE_LENGTH (TYPE_TARGET_TYPE (t
)) = id
>> 3;
1609 complain (&array_bitsize_complaint
, rf
);
1615 /* Volatile -- currently ignored */
1619 /* Const -- currently ignored */
1623 complain (&unknown_type_qual_complaint
, tq
);
1629 /* Parse a procedure descriptor record PR. Note that the procedure is
1630 parsed _after_ the local symbols, now we just insert the extra
1631 information we need into a MIPS_EFI_SYMBOL_NAME symbol that has
1632 already been placed in the procedure's main block. Note also that
1633 images that have been partially stripped (ld -x) have been deprived
1634 of local symbols, and we have to cope with them here. FIRST_OFF is
1635 the offset of the first procedure for this FDR; we adjust the
1636 address by this amount, but I don't know why. SEARCH_SYMTAB is the symtab
1637 to look for the function which contains the MIPS_EFI_SYMBOL_NAME symbol
1638 in question, or NULL to use top_stack->cur_block. */
1640 static void parse_procedure
PARAMS ((PDR
*, struct symtab
*, unsigned long));
1643 parse_procedure (pr
, search_symtab
, first_off
)
1645 struct symtab
*search_symtab
;
1646 unsigned long first_off
;
1648 struct symbol
*s
, *i
;
1650 struct mips_extra_func_info
*e
;
1653 /* Simple rule to find files linked "-x" */
1654 if (cur_fdr
->rss
== -1)
1658 /* Static procedure at address pr->adr. Sigh. */
1659 complain (&pdr_static_symbol_complaint
, pr
->adr
);
1667 (*ecoff_backend (cur_bfd
)->swap_ext_in
)
1669 ((char *) ecoff_data (cur_bfd
)->external_ext
1670 + pr
->isym
* ecoff_backend (cur_bfd
)->external_ext_size
),
1672 sh_name
= ecoff_data (cur_bfd
)->ssext
+ she
.asym
.iss
;
1680 (*ecoff_backend (cur_bfd
)->swap_sym_in
)
1682 ((char *) ecoff_data (cur_bfd
)->external_sym
1683 + ((cur_fdr
->isymBase
+ pr
->isym
)
1684 * ecoff_backend (cur_bfd
)->external_sym_size
)),
1686 sh_name
= ecoff_data (cur_bfd
)->ss
+ cur_fdr
->issBase
+ sh
.iss
;
1689 if (search_symtab
!= NULL
)
1692 /* This loses both in the case mentioned (want a static, find a global),
1693 but also if we are looking up a non-mangled name which happens to
1694 match the name of a mangled function. */
1695 /* We have to save the cur_fdr across the call to lookup_symbol.
1696 If the pdr is for a static function and if a global function with
1697 the same name exists, lookup_symbol will eventually read in the symtab
1698 for the global function and clobber cur_fdr. */
1699 FDR
*save_cur_fdr
= cur_fdr
;
1700 s
= lookup_symbol (sh_name
, NULL
, VAR_NAMESPACE
, 0, NULL
);
1701 cur_fdr
= save_cur_fdr
;
1705 BLOCKVECTOR_BLOCK (BLOCKVECTOR (search_symtab
), STATIC_BLOCK
),
1711 s
= mylookup_symbol (sh_name
, top_stack
->cur_block
,
1712 VAR_NAMESPACE
, LOC_BLOCK
);
1716 b
= SYMBOL_BLOCK_VALUE (s
);
1720 complain (&pdr_for_nonsymbol_complaint
, sh_name
);
1724 /* FIXME -- delete. We can't do symbol allocation now; it's all done. */
1725 s
= new_symbol (sh_name
);
1726 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
1727 SYMBOL_CLASS (s
) = LOC_BLOCK
;
1728 /* Donno its type, hope int is ok */
1729 SYMBOL_TYPE (s
) = lookup_function_type (builtin_type_int
);
1730 add_symbol (s
, top_stack
->cur_block
);
1731 /* Wont have symbols for this one */
1733 SYMBOL_BLOCK_VALUE (s
) = b
;
1734 BLOCK_FUNCTION (b
) = s
;
1735 BLOCK_START (b
) = pr
->adr
;
1736 /* BOUND used to be the end of procedure's text, but the
1737 argument is no longer passed in. */
1738 BLOCK_END (b
) = bound
;
1739 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
1740 add_block (b
, top_stack
->cur_st
);
1744 i
= mylookup_symbol (MIPS_EFI_SYMBOL_NAME
, b
, LABEL_NAMESPACE
, LOC_CONST
);
1748 e
= (struct mips_extra_func_info
*) SYMBOL_VALUE (i
);
1750 e
->pdr
.isym
= (long) s
;
1751 e
->pdr
.adr
+= cur_fdr
->adr
- first_off
;
1753 /* Correct incorrect setjmp procedure descriptor from the library
1754 to make backtrace through setjmp work. */
1755 if (e
->pdr
.pcreg
== 0 && strcmp (sh_name
, "setjmp") == 0)
1757 complain (&bad_setjmp_pdr_complaint
, 0);
1758 e
->pdr
.pcreg
= RA_REGNUM
;
1759 e
->pdr
.regmask
= 0x80000000;
1760 e
->pdr
.regoffset
= -4;
1765 /* Parse the external symbol ES. Just call parse_symbol() after
1766 making sure we know where the aux are for it. For procedures,
1767 parsing of the PDRs has already provided all the needed
1768 information, we only parse them if SKIP_PROCEDURES is false,
1769 and only if this causes no symbol duplication.
1770 BIGEND says whether aux entries are big-endian or little-endian.
1772 This routine clobbers top_stack->cur_block and ->cur_st. */
1775 parse_external (es
, skip_procedures
, bigend
)
1777 int skip_procedures
;
1782 if (es
->ifd
!= ifdNil
)
1785 cur_fdr
= ecoff_data (cur_bfd
)->fdr
+ cur_fd
;
1786 ax
= ecoff_data (cur_bfd
)->external_aux
+ cur_fdr
->iauxBase
;
1790 cur_fdr
= ecoff_data (cur_bfd
)->fdr
;
1794 /* Reading .o files */
1795 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
)
1798 switch (es
->asym
.st
)
1818 /* FIXME: Turn this into a complaint? */
1820 printf_filtered ("Warning: %s `%s' is undefined (in %s)\n",
1822 ecoff_data (cur_bfd
)->ssext
+ es
->asym
.iss
,
1823 fdr_name (cur_fdr
));
1827 switch (es
->asym
.st
)
1830 /* If we have full symbols we do not need more */
1831 if (skip_procedures
)
1833 if (mylookup_symbol (ecoff_data (cur_bfd
)->ssext
+ es
->asym
.iss
,
1834 top_stack
->cur_block
,
1835 VAR_NAMESPACE
, LOC_BLOCK
))
1840 /* Note that the case of a symbol with indexNil must be handled
1841 anyways by parse_symbol(). */
1842 parse_symbol (&es
->asym
, ax
, (char *) NULL
, bigend
);
1843 /* Note that parse_symbol changed es->asym. */
1850 /* Parse the line number info for file descriptor FH into
1851 GDB's linetable LT. MIPS' encoding requires a little bit
1852 of magic to get things out. Note also that MIPS' line
1853 numbers can go back and forth, apparently we can live
1854 with that and do not need to reorder our linetables */
1857 parse_lines (fh
, pr
, lt
)
1860 struct linetable
*lt
;
1862 unsigned char *base
;
1864 int delta
, count
, lineno
= 0;
1865 unsigned long first_off
= pr
->adr
;
1867 if (fh
->cbLineOffset
== 0)
1870 base
= ecoff_data (cur_bfd
)->line
+ fh
->cbLineOffset
;
1872 /* Scan by procedure descriptors */
1874 for (j
= 0; j
< fh
->cpd
; j
++, pr
++)
1879 /* No code for this one */
1880 if (pr
->iline
== ilineNil
||
1881 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1884 /* Aurgh! To know where to stop expanding we must look-ahead. */
1885 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1886 if (pr
[l
].iline
!= -1)
1888 if (l
== (fh
->cpd
- j
))
1893 /* When procedures are moved around the linenumbers are
1894 attributed to the next procedure up. */
1895 if (pr
->iline
>= halt
)
1898 base
= ecoff_data (cur_bfd
)->line
+ fh
->cbLineOffset
+ pr
->cbLineOffset
;
1899 adr
= fh
->adr
+ pr
->adr
- first_off
;
1900 l
= adr
>> 2; /* in words */
1901 halt
+= (adr
>> 2) - pr
->iline
;
1902 for (lineno
= pr
->lnLow
; l
< halt
;)
1904 count
= *base
& 0x0f;
1905 delta
= *base
++ >> 4;
1910 delta
= (base
[0] << 8) | base
[1];
1911 if (delta
>= 0x8000)
1915 lineno
+= delta
; /* first delta is 0 */
1916 k
= add_line (lt
, lineno
, l
, k
);
1922 /* Master parsing procedure for first-pass reading of file symbols
1923 into a partial_symtab. */
1926 parse_partial_symbols (objfile
, section_offsets
)
1927 struct objfile
*objfile
;
1928 struct section_offsets
*section_offsets
;
1930 const struct ecoff_backend_data
* const backend
= ecoff_backend (cur_bfd
);
1931 const bfd_size_type external_sym_size
= backend
->external_sym_size
;
1932 const bfd_size_type external_rfd_size
= backend
->external_rfd_size
;
1933 const bfd_size_type external_ext_size
= backend
->external_ext_size
;
1934 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
1935 = backend
->swap_ext_in
;
1936 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
1937 = backend
->swap_sym_in
;
1938 void (* const swap_rfd_in
) PARAMS ((bfd
*, PTR
, RFDT
*))
1939 = backend
->swap_rfd_in
;
1941 HDRR
*hdr
= &ecoff_data (cur_bfd
)->symbolic_header
;
1942 /* Running pointers */
1947 register EXTR
*ext_in
;
1950 struct partial_symtab
*pst
;
1952 int past_first_source_file
= 0;
1954 /* List of current psymtab's include files */
1955 char **psymtab_include_list
;
1956 int includes_allocated
;
1959 struct pst_map
*fdr_to_pst
;
1960 /* Index within current psymtab dependency list */
1961 struct partial_symtab
**dependency_list
;
1962 int dependencies_used
, dependencies_allocated
;
1963 struct cleanup
*old_chain
;
1966 extern_tab
= (EXTR
*) obstack_alloc (&objfile
->psymbol_obstack
,
1967 sizeof (EXTR
) * hdr
->iextMax
);
1969 includes_allocated
= 30;
1971 psymtab_include_list
= (char **) alloca (includes_allocated
*
1973 next_symbol_text_func
= mips_next_symbol_text
;
1975 dependencies_allocated
= 30;
1976 dependencies_used
= 0;
1978 (struct partial_symtab
**) alloca (dependencies_allocated
*
1979 sizeof (struct partial_symtab
*));
1981 last_source_file
= NULL
;
1986 * Only parse the Local and External symbols, and the Relative FDR.
1987 * Fixup enough of the loader symtab to be able to use it.
1988 * Allocate space only for the file's portions we need to
1993 max_glevel
= MIN_GLEVEL
;
1995 /* Allocate the map FDR -> PST.
1996 Minor hack: -O3 images might claim some global data belongs
1997 to FDR -1. We`ll go along with that */
1998 fdr_to_pst
= (struct pst_map
*) xzalloc ((hdr
->ifdMax
+ 1) * sizeof *fdr_to_pst
);
1999 old_chain
= make_cleanup (free
, fdr_to_pst
);
2002 struct partial_symtab
*pst
= new_psymtab ("", objfile
);
2003 fdr_to_pst
[-1].pst
= pst
;
2007 /* Pass 0 over external syms: swap them in. */
2008 ext_block
= (EXTR
*) xmalloc (hdr
->iextMax
* sizeof (EXTR
));
2009 make_cleanup (free
, ext_block
);
2011 ext_out
= (char *) ecoff_data (cur_bfd
)->external_ext
;
2012 ext_out_end
= ext_out
+ hdr
->iextMax
* external_ext_size
;
2014 for (; ext_out
< ext_out_end
; ext_out
+= external_ext_size
, ext_in
++)
2015 (*swap_ext_in
) (cur_bfd
, ext_out
, ext_in
);
2017 /* Pass 1 over external syms: Presize and partition the list */
2019 ext_in_end
= ext_in
+ hdr
->iextMax
;
2020 for (; ext_in
< ext_in_end
; ext_in
++)
2021 fdr_to_pst
[ext_in
->ifd
].n_globals
++;
2023 /* Pass 1.5 over files: partition out global symbol space */
2025 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++)
2027 fdr_to_pst
[f_idx
].globals_offset
= s_idx
;
2028 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
2029 fdr_to_pst
[f_idx
].n_globals
= 0;
2032 /* Pass 2 over external syms: fill in external symbols */
2034 ext_in_end
= ext_in
+ hdr
->iextMax
;
2035 for (; ext_in
< ext_in_end
; ext_in
++)
2037 enum minimal_symbol_type ms_type
= mst_text
;
2039 extern_tab
[fdr_to_pst
[ext_in
->ifd
].globals_offset
2040 + fdr_to_pst
[ext_in
->ifd
].n_globals
++] = *ext_in
;
2042 if (ext_in
->asym
.sc
== scUndefined
|| ext_in
->asym
.sc
== scNil
)
2045 name
= ecoff_data (cur_bfd
)->ssext
+ ext_in
->asym
.iss
;
2046 switch (ext_in
->asym
.st
)
2051 if (ext_in
->asym
.sc
== scData
2052 || ext_in
->asym
.sc
== scSData
2053 || ext_in
->asym
.sc
== scRData
)
2059 if (ext_in
->asym
.sc
== scAbs
)
2061 else if (ext_in
->asym
.sc
== scText
)
2063 else if (ext_in
->asym
.sc
== scData
2064 || ext_in
->asym
.sc
== scSData
2065 || ext_in
->asym
.sc
== scRData
)
2071 ms_type
= mst_unknown
;
2072 complain (&unknown_ext_complaint
, name
);
2074 prim_record_minimal_symbol (name
, ext_in
->asym
.value
, ms_type
);
2077 /* Pass 3 over files, over local syms: fill in static symbols */
2078 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++)
2080 struct partial_symtab
*save_pst
;
2083 cur_fdr
= fh
= ecoff_data (cur_bfd
)->fdr
+ f_idx
;
2087 fdr_to_pst
[f_idx
].pst
= NULL
;
2090 pst
= start_psymtab_common (objfile
, section_offsets
,
2092 fh
->cpd
? fh
->adr
: 0,
2093 objfile
->global_psymbols
.next
,
2094 objfile
->static_psymbols
.next
);
2095 pst
->read_symtab_private
= ((char *)
2096 obstack_alloc (&objfile
->psymbol_obstack
,
2097 sizeof (struct symloc
)));
2098 memset ((PTR
) pst
->read_symtab_private
, 0, sizeof (struct symloc
));
2101 /* Make everything point to everything. */
2102 FDR_IDX (pst
) = f_idx
;
2103 fdr_to_pst
[f_idx
].pst
= pst
;
2105 /* FIXME: This tampers with data from BFD. */
2106 fh
->ioptBase
= (int) pst
;
2108 CUR_BFD (pst
) = cur_bfd
;
2110 /* The way to turn this into a symtab is to call... */
2111 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
2113 pst
->texthigh
= pst
->textlow
;
2115 /* For stabs-in-ecoff files, the second symbol must be @stab.
2116 This symbol is emitted by mips-tfile to signal that the
2117 current object file uses encapsulated stabs instead of mips
2118 ecoff for local symbols. (It is the second symbol because
2119 the first symbol is the stFile used to signal the start of a
2121 processing_gcc_compilation
= 0;
2124 (*swap_sym_in
) (cur_bfd
,
2125 ((char *) ecoff_data (cur_bfd
)->external_sym
2126 + (fh
->isymBase
+ 1) * external_sym_size
),
2128 if (STREQ (ecoff_data (cur_bfd
)->ss
+ fh
->issBase
+ sh
.iss
,
2130 processing_gcc_compilation
= 2;
2133 if (processing_gcc_compilation
!= 0)
2135 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++)
2140 (*swap_sym_in
) (cur_bfd
,
2141 ((char *) ecoff_data (cur_bfd
)->external_sym
2142 + (fh
->isymBase
+ cur_sdx
) * external_sym_size
),
2144 type_code
= ECOFF_UNMARK_STAB (sh
.index
);
2145 if (!ECOFF_IS_STAB (&sh
))
2147 if (sh
.st
== stProc
|| sh
.st
== stStaticProc
)
2149 long procaddr
= sh
.value
;
2153 isym
= AUX_GET_ISYM (fh
->fBigendian
,
2154 (ecoff_data (cur_bfd
)->external_aux
2157 (*swap_sym_in
) (cur_bfd
,
2159 ecoff_data (cur_bfd
)->external_sym
)
2160 + ((fh
->isymBase
+ isym
- 1)
2161 * external_sym_size
)),
2165 long high
= procaddr
+ sh
.value
;
2166 if (high
> pst
->texthigh
)
2167 pst
->texthigh
= high
;
2172 #define SET_NAMESTRING() \
2173 namestring = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss
2174 #define CUR_SYMBOL_TYPE type_code
2175 #define CUR_SYMBOL_VALUE sh.value
2176 #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms)\
2178 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
2179 #define HANDLE_RBRAC(val) \
2180 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
2181 #include "partial-stab.h"
2186 for (cur_sdx
= 0; cur_sdx
< fh
->csym
;)
2189 enum address_class
class;
2191 (*swap_sym_in
) (cur_bfd
,
2192 ((char *) ecoff_data (cur_bfd
)->external_sym
2193 + ((fh
->isymBase
+ cur_sdx
)
2194 * external_sym_size
)),
2197 if (ECOFF_IS_STAB (&sh
))
2203 /* Non absolute static symbols go into the minimal table. */
2204 if (sh
.sc
== scUndefined
|| sh
.sc
== scNil
2205 || (sh
.index
== indexNil
2206 && (sh
.st
!= stStatic
|| sh
.sc
== scAbs
)))
2208 /* FIXME, premature? */
2213 name
= ecoff_data (cur_bfd
)->ss
+ fh
->issBase
+ sh
.iss
;
2221 case stStaticProc
: /* Function */
2222 /* I believe this is used only for file-local functions.
2223 The comment in symconst.h ("load time only static procs")
2224 isn't particularly clear on this point. */
2225 prim_record_minimal_symbol (name
, sh
.value
, mst_file_text
);
2228 case stProc
: /* Asm labels apparently */
2229 ADD_PSYMBOL_TO_LIST (name
, strlen (name
),
2230 VAR_NAMESPACE
, LOC_BLOCK
,
2231 objfile
->static_psymbols
, sh
.value
,
2232 psymtab_language
, objfile
);
2233 /* Skip over procedure to next one. */
2234 if (sh
.index
>= hdr
->iauxMax
)
2236 /* Should not happen, but does when cross-compiling
2237 with the MIPS compiler. FIXME -- pull later. */
2238 complain (&index_complaint
, name
);
2239 new_sdx
= cur_sdx
+ 1; /* Don't skip at all */
2242 new_sdx
= AUX_GET_ISYM (fh
->fBigendian
,
2243 (ecoff_data (cur_bfd
)->external_aux
2246 procaddr
= sh
.value
;
2248 if (new_sdx
<= cur_sdx
)
2250 /* This should not happen either... FIXME. */
2251 complain (&aux_index_complaint
, name
);
2252 new_sdx
= cur_sdx
+ 1; /* Don't skip backward */
2256 (*swap_sym_in
) (cur_bfd
,
2257 ((char *) ecoff_data (cur_bfd
)->external_sym
2258 + ((fh
->isymBase
+ cur_sdx
- 1)
2259 * external_sym_size
)),
2263 high
= procaddr
+ sh
.value
;
2264 if (high
> pst
->texthigh
)
2265 pst
->texthigh
= high
;
2268 case stStatic
: /* Variable */
2269 if (sh
.sc
== scData
|| sh
.sc
== scSData
|| sh
.sc
== scRData
)
2270 prim_record_minimal_symbol (name
, sh
.value
, mst_file_data
);
2272 prim_record_minimal_symbol (name
, sh
.value
, mst_file_bss
);
2276 case stTypedef
:/* Typedef */
2277 class = LOC_TYPEDEF
;
2280 case stConstant
: /* Constant decl */
2287 case stBlock
: /* { }, str, un, enum*/
2288 if (sh
.sc
== scInfo
|| sh
.sc
== scCommon
)
2290 ADD_PSYMBOL_TO_LIST (name
, strlen (name
),
2291 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2292 objfile
->static_psymbols
,
2294 psymtab_language
, objfile
);
2296 /* Skip over the block */
2298 if (new_sdx
<= cur_sdx
)
2300 /* This happens with the Ultrix kernel. */
2301 complain (&block_index_complaint
, name
);
2302 new_sdx
= cur_sdx
+ 1; /* Don't skip backward */
2307 case stFile
: /* File headers */
2308 case stLabel
: /* Labels */
2309 case stEnd
: /* Ends of files */
2312 case stLocal
: /* Local variables */
2313 /* Normally these are skipped because we skip over
2314 all blocks we see. However, these can occur
2315 as visible symbols in a .h file that contains code. */
2319 /* Both complaints are valid: one gives symbol name,
2320 the other the offending symbol type. */
2321 complain (&unknown_sym_complaint
, name
);
2322 complain (&unknown_st_complaint
, sh
.st
);
2326 /* Use this gdb symbol */
2327 ADD_PSYMBOL_TO_LIST (name
, strlen (name
),
2328 VAR_NAMESPACE
, class,
2329 objfile
->static_psymbols
, sh
.value
,
2330 psymtab_language
, objfile
);
2332 cur_sdx
++; /* Go to next file symbol */
2335 /* Now do enter the external symbols. */
2336 ext_ptr
= &extern_tab
[fdr_to_pst
[f_idx
].globals_offset
];
2337 cur_sdx
= fdr_to_pst
[f_idx
].n_globals
;
2338 PST_PRIVATE (save_pst
)->extern_count
= cur_sdx
;
2339 PST_PRIVATE (save_pst
)->extern_tab
= ext_ptr
;
2340 for (; --cur_sdx
>= 0; ext_ptr
++)
2342 enum address_class
class;
2346 if (ext_ptr
->ifd
!= f_idx
)
2348 psh
= &ext_ptr
->asym
;
2358 complain (&unknown_ext_complaint
,
2359 ecoff_data (cur_bfd
)->ssext
+ psh
->iss
);
2360 /* Fall through, pretend it's global. */
2365 name
= ecoff_data (cur_bfd
)->ssext
+ psh
->iss
;
2366 ADD_PSYMBOL_ADDR_TO_LIST (name
, strlen (name
),
2367 VAR_NAMESPACE
, class,
2368 objfile
->global_psymbols
, (CORE_ADDR
) psh
->value
,
2369 psymtab_language
, objfile
);
2373 end_psymtab (save_pst
, psymtab_include_list
, includes_used
,
2374 -1, save_pst
->texthigh
,
2375 dependency_list
, dependencies_used
);
2376 if (objfile
->ei
.entry_point
>= save_pst
->textlow
&&
2377 objfile
->ei
.entry_point
< save_pst
->texthigh
)
2379 objfile
->ei
.entry_file_lowpc
= save_pst
->textlow
;
2380 objfile
->ei
.entry_file_highpc
= save_pst
->texthigh
;
2384 /* Now scan the FDRs for dependencies */
2385 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++)
2388 fh
= f_idx
+ ecoff_data (cur_bfd
)->fdr
;
2389 pst
= fdr_to_pst
[f_idx
].pst
;
2391 /* This should catch stabs-in-ecoff. */
2396 { /* If there are no functions defined here ... */
2397 /* ...then presumably a .h file: drop reverse depends .h->.c */
2398 for (; s_id0
< fh
->crfd
; s_id0
++)
2402 (*swap_rfd_in
) (cur_bfd
,
2403 ((char *) ecoff_data (cur_bfd
)->external_rfd
2404 + (fh
->rfdBase
+ s_id0
) * external_rfd_size
),
2408 s_id0
++; /* Skip self-dependency */
2413 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2415 ((struct partial_symtab
**)
2416 obstack_alloc (&objfile
->psymbol_obstack
,
2417 (pst
->number_of_dependencies
2418 * sizeof (struct partial_symtab
*))));
2419 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++)
2423 (*swap_rfd_in
) (cur_bfd
,
2424 ((char *) ecoff_data (cur_bfd
)->external_rfd
2425 + (fh
->rfdBase
+ s_idx
) * external_rfd_size
),
2427 if (rh
< 0 || rh
>= hdr
->ifdMax
)
2428 complain (&bad_file_number_complaint
, rh
);
2430 pst
->dependencies
[s_idx
- s_id0
] = fdr_to_pst
[rh
].pst
;
2433 do_cleanups (old_chain
);
2438 /* Do the initial analisys of the F_IDX-th file descriptor.
2439 Allocates a partial symtab for it, and builds the list
2440 of dependent files by recursion. LEV says at which level
2441 of recursion we are called (to pretty up debug traces) */
2443 static struct partial_symtab
*
2444 parse_fdr (f_idx
, lev
, objfile
)
2447 struct objfile
*objfile
;
2449 const bfd_size_type external_rfd_size
2450 = ecoff_backend (cur_bfd
)->external_rfd_size
;
2451 void (* const swap_rfd_in
) PARAMS ((bfd
*, PTR
, RFDT
*))
2452 = ecoff_backend (cur_bfd
)->swap_rfd_in
;
2454 register struct partial_symtab
*pst
;
2457 fh
= ecoff_data (cur_bfd
)->fdr
+ f_idx
;
2459 /* Use this to indicate into which symtab this file was parsed */
2461 return (struct partial_symtab
*) fh
->ioptBase
;
2463 /* Debuggability level */
2464 if (compare_glevel (max_glevel
, fh
->glevel
) < 0)
2465 max_glevel
= fh
->glevel
;
2467 /* Make a new partial_symtab */
2468 pst
= new_psymtab (fdr_name (fh
), objfile
);
2476 pst
->textlow
= fh
->adr
;
2477 pst
->texthigh
= fh
->cpd
; /* To be fixed later */
2480 /* Make everything point to everything. */
2481 FDR_IDX (pst
) = f_idx
;
2482 fdr_to_pst
[f_idx
].pst
= pst
;
2483 fh
->ioptBase
= (int) pst
;
2485 /* Analyze its dependencies */
2491 { /* If there are no functions defined here ... */
2492 /* ...then presumably a .h file: drop reverse depends .h->.c */
2493 for (; s_id0
< fh
->crfd
; s_id0
++)
2497 (*swap_rfd_in
) (cur_bfd
,
2498 ((char *) ecoff_data (cur_bfd
)->external_rfd
2499 + (fh
->rfdBase
+ s_id0
) * external_rfd_size
),
2503 s_id0
++; /* Skip self-dependency */
2508 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2509 pst
->dependencies
= ((struct partial_symtab
**)
2510 obstack_alloc (&objfile
->psymbol_obstack
,
2511 (pst
->number_of_dependencies
2512 * sizeof (struct partial_symtab
*))));
2513 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++)
2517 (*swap_rfd_in
) (cur_bfd
,
2518 ((char *) ecoff_data (cur_bfd
)->external_rfd
2519 + (fh
->rfdBase
+ s_idx
) * external_rfd_size
),
2521 pst
->dependencies
[s_idx
- s_id0
] = parse_fdr (rh
, lev
+ 1, objfile
);
2530 mips_next_symbol_text ()
2535 (*ecoff_backend (cur_bfd
)->swap_sym_in
)
2537 ((char *) ecoff_data (cur_bfd
)->external_sym
2538 + ((cur_fdr
->isymBase
+ cur_sdx
)
2539 * ecoff_backend (cur_bfd
)->external_sym_size
)),
2541 return ecoff_data (cur_bfd
)->ss
+ cur_fdr
->issBase
+ sh
.iss
;
2544 /* Ancillary function to psymtab_to_symtab(). Does all the work
2545 for turning the partial symtab PST into a symtab, recurring
2546 first on all dependent psymtabs. The argument FILENAME is
2547 only passed so we can see in debug stack traces what file
2550 This function has a split personality, based on whether the
2551 symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
2552 The flow of control and even the memory allocation differs. FIXME. */
2555 psymtab_to_symtab_1 (pst
, filename
)
2556 struct partial_symtab
*pst
;
2559 const bfd_size_type external_sym_size
2560 = ecoff_backend (cur_bfd
)->external_sym_size
;
2561 const bfd_size_type external_pdr_size
2562 = ecoff_backend (cur_bfd
)->external_pdr_size
;
2563 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
2564 = ecoff_backend (cur_bfd
)->swap_sym_in
;
2565 void (* const swap_sym_out
) PARAMS ((bfd
*, const SYMR
*, PTR
))
2566 = ecoff_backend (cur_bfd
)->swap_sym_out
;
2567 void (* const swap_pdr_in
) PARAMS ((bfd
*, PTR
, PDR
*))
2568 = ecoff_backend (cur_bfd
)->swap_pdr_in
;
2572 struct linetable
*lines
;
2578 /* Read in all partial symbtabs on which this one is dependent.
2579 NOTE that we do have circular dependencies, sigh. We solved
2580 that by setting pst->readin before this point. */
2582 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2583 if (!pst
->dependencies
[i
]->readin
)
2585 /* Inform about additional files to be read in. */
2588 fputs_filtered (" ", stdout
);
2590 fputs_filtered ("and ", stdout
);
2592 printf_filtered ("%s...",
2593 pst
->dependencies
[i
]->filename
);
2594 wrap_here (""); /* Flush output */
2597 /* We only pass the filename for debug purposes */
2598 psymtab_to_symtab_1 (pst
->dependencies
[i
],
2599 pst
->dependencies
[i
]->filename
);
2602 /* Do nothing if this is a dummy psymtab. */
2604 if (pst
->n_global_syms
== 0 && pst
->n_static_syms
== 0
2605 && pst
->textlow
== 0 && pst
->texthigh
== 0)
2608 /* Now read the symbols for this symtab */
2610 cur_bfd
= CUR_BFD (pst
);
2611 current_objfile
= pst
->objfile
;
2612 cur_fd
= FDR_IDX (pst
);
2613 fh
= (cur_fd
== -1) ? (FDR
*) NULL
: ecoff_data (cur_bfd
)->fdr
+ cur_fd
;
2616 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2617 processing_gcc_compilation
= 0;
2618 if (fh
!= (FDR
*) NULL
&& fh
->csym
>= 2)
2622 (*swap_sym_in
) (cur_bfd
,
2623 ((char *) ecoff_data (cur_bfd
)->external_sym
2624 + (fh
->isymBase
+ 1) * external_sym_size
),
2626 if (STREQ (ecoff_data (cur_bfd
)->ss
+ fh
->issBase
+ sh
.iss
,
2629 /* We indicate that this is a GCC compilation so that certain
2630 features will be enabled in stabsread/dbxread. */
2631 processing_gcc_compilation
= 2;
2635 if (processing_gcc_compilation
!= 0)
2640 unsigned long first_off
;
2642 /* This symbol table contains stabs-in-ecoff entries. */
2644 /* Parse local symbols first */
2646 if (fh
->csym
<= 2) /* FIXME, this blows psymtab->symtab ptr */
2648 current_objfile
= NULL
;
2651 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++)
2657 (*swap_sym_in
) (cur_bfd
,
2658 ((char *) ecoff_data (cur_bfd
)->external_sym
2659 + (fh
->isymBase
+ cur_sdx
) * external_sym_size
),
2661 name
= ecoff_data (cur_bfd
)->ss
+ fh
->issBase
+ sh
.iss
;
2663 if (ECOFF_IS_STAB (&sh
))
2665 int type_code
= ECOFF_UNMARK_STAB (sh
.index
);
2666 process_one_symbol (type_code
, 0, valu
, name
,
2667 pst
->section_offsets
, pst
->objfile
);
2668 if (type_code
== N_FUN
)
2670 /* Make up special symbol to contain
2671 procedure specific info */
2672 struct mips_extra_func_info
*e
=
2673 ((struct mips_extra_func_info
*)
2674 obstack_alloc (¤t_objfile
->symbol_obstack
,
2675 sizeof (struct mips_extra_func_info
)));
2676 struct symbol
*s
= new_symbol (MIPS_EFI_SYMBOL_NAME
);
2677 SYMBOL_NAMESPACE (s
) = LABEL_NAMESPACE
;
2678 SYMBOL_CLASS (s
) = LOC_CONST
;
2679 SYMBOL_TYPE (s
) = builtin_type_void
;
2680 SYMBOL_VALUE (s
) = (int) e
;
2681 add_symbol_to_list (s
, &local_symbols
);
2684 else if (sh
.st
== stLabel
&& sh
.index
!= indexNil
)
2686 /* Handle encoded stab line number. */
2687 record_line (current_subfile
, sh
.index
, valu
);
2689 else if (sh
.st
== stProc
|| sh
.st
== stStaticProc
|| sh
.st
== stEnd
)
2690 /* These are generated by gcc-2.x, do not complain */
2693 complain (&stab_unknown_complaint
, name
);
2695 st
= end_symtab (pst
->texthigh
, 0, 0, pst
->objfile
, SECT_OFF_TEXT
);
2698 /* Sort the symbol table now, we are done adding symbols to it.
2699 We must do this before parse_procedure calls lookup_symbol. */
2700 sort_symtab_syms (st
);
2702 /* This may not be necessary for stabs symtabs. FIXME. */
2705 /* Fill in procedure info next. */
2707 pdr_ptr
= ((char *) ecoff_data (cur_bfd
)->external_pdr
2708 + fh
->ipdFirst
* external_pdr_size
);
2709 pdr_end
= pdr_ptr
+ fh
->cpd
* external_pdr_size
;
2710 for (; pdr_ptr
< pdr_end
; pdr_ptr
+= external_pdr_size
)
2714 (*swap_pdr_in
) (cur_bfd
, pdr_ptr
, &pr
);
2720 parse_procedure (&pr
, st
, first_off
);
2725 /* This symbol table contains ordinary ecoff entries. */
2727 /* FIXME: doesn't use pst->section_offsets. */
2733 /* How many symbols will we need */
2734 /* FIXME, this does not count enum values. */
2735 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
2739 st
= new_symtab ("unknown", f_max
, 0, pst
->objfile
);
2743 f_max
+= fh
->csym
+ fh
->cpd
;
2744 maxlines
= 2 * fh
->cline
;
2745 st
= new_symtab (pst
->filename
, 2 * f_max
, maxlines
, pst
->objfile
);
2748 lines
= LINETABLE (st
);
2749 pending_list
= PST_PRIVATE (pst
)->pending_list
;
2750 if (pending_list
== 0)
2752 pending_list
= ((struct mips_pending
**)
2753 xzalloc (ecoff_data (cur_bfd
)->symbolic_header
.ifdMax
2754 * sizeof (struct mips_pending
*)));
2755 PST_PRIVATE (pst
)->pending_list
= pending_list
;
2758 /* Get a new lexical context */
2760 push_parse_stack ();
2761 top_stack
->cur_st
= st
;
2762 top_stack
->cur_block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (st
),
2764 BLOCK_START (top_stack
->cur_block
) = fh
? fh
->adr
: 0;
2765 BLOCK_END (top_stack
->cur_block
) = 0;
2766 top_stack
->blocktype
= stFile
;
2767 top_stack
->maxsyms
= 2 * f_max
;
2768 top_stack
->cur_type
= 0;
2769 top_stack
->procadr
= 0;
2770 top_stack
->numargs
= 0;
2777 /* Parse local symbols first */
2778 sym_ptr
= ((char *) ecoff_data (cur_bfd
)->external_sym
2779 + fh
->isymBase
* external_sym_size
);
2780 sym_end
= sym_ptr
+ fh
->csym
* external_sym_size
;
2781 while (sym_ptr
< sym_end
)
2786 (*swap_sym_in
) (cur_bfd
, sym_ptr
, &sh
);
2787 c
= parse_symbol (&sh
,
2788 (ecoff_data (cur_bfd
)->external_aux
2790 sym_ptr
, fh
->fBigendian
);
2791 /* FIXME: We must swap the modified symbol back out,
2792 although we would rather not. See parse_symbol. */
2793 (*swap_sym_out
) (cur_bfd
, &sh
, sym_ptr
);
2794 sym_ptr
+= c
* external_sym_size
;
2797 /* Linenumbers. At the end, check if we can save memory.
2798 parse_lines has to look ahead an arbitrary number of PDR
2799 structures, so we swap them all first. */
2803 struct cleanup
*old_chain
;
2809 pr_block
= (PDR
*) xmalloc (fh
->cpd
* sizeof (PDR
));
2811 old_chain
= make_cleanup (free
, pr_block
);
2813 pdr_ptr
= ((char *) ecoff_data (cur_bfd
)->external_pdr
2814 + fh
->ipdFirst
* external_pdr_size
);
2815 pdr_end
= pdr_ptr
+ fh
->cpd
* external_pdr_size
;
2819 pdr_ptr
+= external_pdr_size
, pdr_in
++)
2820 (*swap_pdr_in
) (cur_bfd
, pdr_ptr
, pdr_in
);
2822 parse_lines (fh
, pr_block
, lines
);
2823 if (lines
->nitems
< fh
->cline
)
2824 lines
= shrink_linetable (lines
);
2826 /* Fill in procedure info next. */
2828 pdr_in_end
= pdr_in
+ fh
->cpd
;
2829 for (; pdr_in
< pdr_in_end
; pdr_in
++)
2830 parse_procedure (pdr_in
, 0, pr_block
->adr
);
2832 do_cleanups (old_chain
);
2836 LINETABLE (st
) = lines
;
2838 /* .. and our share of externals.
2839 XXX use the global list to speed up things here. how?
2840 FIXME, Maybe quit once we have found the right number of ext's? */
2841 top_stack
->cur_st
= st
;
2842 top_stack
->cur_block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack
->cur_st
),
2844 top_stack
->blocktype
= stFile
;
2845 top_stack
->maxsyms
= (ecoff_data (cur_bfd
)->symbolic_header
.isymMax
2846 + ecoff_data (cur_bfd
)->symbolic_header
.ipdMax
2847 + ecoff_data (cur_bfd
)->symbolic_header
.iextMax
);
2849 ext_ptr
= PST_PRIVATE (pst
)->extern_tab
;
2850 for (i
= PST_PRIVATE (pst
)->extern_count
; --i
>= 0; ext_ptr
++)
2851 parse_external (ext_ptr
, 1, fh
->fBigendian
);
2853 /* If there are undefined, tell the user */
2854 if (n_undef_symbols
)
2856 printf_filtered ("File %s contains %d unresolved references:",
2857 st
->filename
, n_undef_symbols
);
2858 printf_filtered ("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2859 n_undef_vars
, n_undef_procs
, n_undef_labels
);
2860 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
2865 /* Sort the symbol table now, we are done adding symbols to it.*/
2866 sort_symtab_syms (st
);
2871 /* Now link the psymtab and the symtab. */
2874 current_objfile
= NULL
;
2877 /* Ancillary parsing procedures. */
2879 /* Lookup the type at relative index RN. Return it in TPP
2880 if found and in any event come up with its name PNAME.
2881 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
2882 Return value says how many aux symbols we ate. */
2885 cross_ref (ax
, tpp
, type_code
, pname
, bigend
)
2888 enum type_code type_code
; /* Use to alloc new type if none is found. */
2896 ecoff_swap_rndx_in (bigend
, &ax
->a_rndx
, rn
);
2898 /* Escape index means 'the next one' */
2899 if (rn
->rfd
== 0xfff)
2902 rf
= AUX_GET_ISYM (bigend
, ax
+ 1);
2912 *pname
= "<undefined>";
2917 * Find the relative file descriptor and the symbol in it
2919 FDR
*fh
= get_rfd (cur_fd
, rf
);
2924 if (rn
->index
>= fh
->csym
)
2926 /* File indirect entry is corrupt. */
2927 *tpp
= (struct type
*)NULL
;
2928 *pname
= "<illegal>";
2929 complain (&bad_rfd_entry_complaint
,
2930 fh
- ecoff_data (cur_bfd
)->fdr
, rn
->index
);
2934 /* If we have processed this symbol then we left a forwarding
2935 pointer to the corresponding GDB symbol. If not, we`ll put
2936 it in a list of pending symbols, to be processed later when
2937 the file will be. In any event, we collect the name for the
2938 type here. Which is why we made a first pass at strings. */
2940 esh
= ((char *) ecoff_data (cur_bfd
)->external_sym
2941 + ((fh
->isymBase
+ rn
->index
)
2942 * ecoff_backend (cur_bfd
)->external_sym_size
));
2943 (*ecoff_backend (cur_bfd
)->swap_sym_in
) (cur_bfd
, esh
, &sh
);
2945 /* Careful, we might be looking at .o files */
2947 *pname
= "<undefined>";
2948 else if (rn
->rfd
== 0xfff && rn
->index
== 0)
2949 /* For structs, unions and enums, rn->rfd is 0xfff and the index
2950 is a relative symbol number for the type, but an index of 0
2951 seems to mean that we don't know. This is said to fix a problem
2952 with "info func opendir" on an SGI showing
2953 "struct BSDopendir.c *BSDopendir();". */
2955 *tpp
= (struct type
*)NULL
;
2956 *pname
= "<unknown>";
2959 else if ((sh
.st
!= stBlock
&& sh
.st
!= stTypedef
&& sh
.st
!= stParsed
)
2962 /* File indirect entry is corrupt. */
2963 *tpp
= (struct type
*)NULL
;
2964 *pname
= "<illegal>";
2965 complain (&bad_rfd_entry_complaint
,
2966 fh
- ecoff_data (cur_bfd
)->fdr
, rn
->index
);
2970 *pname
= ecoff_data (cur_bfd
)->ss
+ fh
->issBase
+ sh
.iss
;
2972 /* Have we parsed it ? */
2973 if (sh
.value
!= 0 && sh
.st
== stParsed
)
2975 t
= (struct type
*) sh
.value
;
2980 /* Avoid duplicates */
2981 struct mips_pending
*p
= is_pending_symbol (fh
, esh
);
2986 *tpp
= init_type (type_code
, 0, 0, (char *) NULL
,
2987 (struct objfile
*) NULL
);
2988 add_pending (fh
, esh
, *tpp
);
2993 /* We used one auxent normally, two if we got a "next one" rf. */
2998 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2999 keeping the symtab sorted */
3001 static struct symbol
*
3002 mylookup_symbol (name
, block
, namespace, class)
3004 register struct block
*block
;
3005 enum namespace namespace;
3006 enum address_class
class;
3008 register int bot
, top
, inc
;
3009 register struct symbol
*sym
;
3012 top
= BLOCK_NSYMS (block
);
3016 sym
= BLOCK_SYM (block
, bot
);
3017 if (SYMBOL_NAME (sym
)[0] == inc
3018 && SYMBOL_NAMESPACE (sym
) == namespace
3019 && SYMBOL_CLASS (sym
) == class
3020 && strcmp (SYMBOL_NAME (sym
), name
) == 0)
3024 block
= BLOCK_SUPERBLOCK (block
);
3026 return mylookup_symbol (name
, block
, namespace, class);
3031 /* Add a new symbol S to a block B.
3032 Infrequently, we will need to reallocate the block to make it bigger.
3033 We only detect this case when adding to top_stack->cur_block, since
3034 that's the only time we know how big the block is. FIXME. */
3041 int nsyms
= BLOCK_NSYMS (b
)++;
3042 struct block
*origb
;
3043 struct parse_stack
*stackp
;
3045 if (b
== top_stack
->cur_block
&&
3046 nsyms
>= top_stack
->maxsyms
)
3048 complain (&block_overflow_complaint
, SYMBOL_NAME (s
));
3049 /* In this case shrink_block is actually grow_block, since
3050 BLOCK_NSYMS(b) is larger than its current size. */
3052 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
3054 /* Now run through the stack replacing pointers to the
3055 original block. shrink_block has already done this
3056 for the blockvector and BLOCK_FUNCTION. */
3057 for (stackp
= top_stack
; stackp
; stackp
= stackp
->next
)
3059 if (stackp
->cur_block
== origb
)
3061 stackp
->cur_block
= b
;
3062 stackp
->maxsyms
= BLOCK_NSYMS (b
);
3066 BLOCK_SYM (b
, nsyms
) = s
;
3069 /* Add a new block B to a symtab S */
3076 struct blockvector
*bv
= BLOCKVECTOR (s
);
3078 bv
= (struct blockvector
*) xrealloc ((PTR
) bv
,
3079 (sizeof (struct blockvector
)
3080 + BLOCKVECTOR_NBLOCKS (bv
)
3081 * sizeof (bv
->block
)));
3082 if (bv
!= BLOCKVECTOR (s
))
3083 BLOCKVECTOR (s
) = bv
;
3085 BLOCKVECTOR_BLOCK (bv
, BLOCKVECTOR_NBLOCKS (bv
)++) = b
;
3088 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
3089 MIPS' linenumber encoding might need more than one byte
3090 to describe it, LAST is used to detect these continuation lines.
3092 Combining lines with the same line number seems like a bad idea.
3093 E.g: There could be a line number entry with the same line number after the
3094 prologue and GDB should not ignore it (this is a better way to find
3095 a prologue than mips_skip_prologue).
3096 But due to the compressed line table format there are line number entries
3097 for the same line which are needed to bridge the gap to the next
3098 line number entry. These entries have a bogus address info with them
3099 and we are unable to tell them from intended duplicate line number
3101 This is another reason why -ggdb debugging format is preferable. */
3104 add_line (lt
, lineno
, adr
, last
)
3105 struct linetable
*lt
;
3111 last
= -2; /* make sure we record first line */
3113 if (last
== lineno
) /* skip continuation lines */
3116 lt
->item
[lt
->nitems
].line
= lineno
;
3117 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
3121 /* Sorting and reordering procedures */
3123 /* Blocks with a smaller low bound should come first */
3126 compare_blocks (arg1
, arg2
)
3127 const void *arg1
, *arg2
;
3129 register int addr_diff
;
3130 struct block
**b1
= (struct block
**) arg1
;
3131 struct block
**b2
= (struct block
**) arg2
;
3133 addr_diff
= (BLOCK_START ((*b1
))) - (BLOCK_START ((*b2
)));
3135 return (BLOCK_END ((*b2
))) - (BLOCK_END ((*b1
)));
3139 /* Sort the blocks of a symtab S.
3140 Reorder the blocks in the blockvector by code-address,
3141 as required by some MI search routines */
3147 struct blockvector
*bv
= BLOCKVECTOR (s
);
3149 if (BLOCKVECTOR_NBLOCKS (bv
) <= 2)
3152 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) == 0)
3153 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) = 0;
3154 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) == 0)
3155 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) = 0;
3159 * This is very unfortunate: normally all functions are compiled in
3160 * the order they are found, but if the file is compiled -O3 things
3161 * are very different. It would be nice to find a reliable test
3162 * to detect -O3 images in advance.
3164 if (BLOCKVECTOR_NBLOCKS (bv
) > 3)
3165 qsort (&BLOCKVECTOR_BLOCK (bv
, FIRST_LOCAL_BLOCK
),
3166 BLOCKVECTOR_NBLOCKS (bv
) - FIRST_LOCAL_BLOCK
,
3167 sizeof (struct block
*),
3171 register CORE_ADDR high
= 0;
3172 register int i
, j
= BLOCKVECTOR_NBLOCKS (bv
);
3174 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
3175 if (high
< BLOCK_END (BLOCKVECTOR_BLOCK (bv
, i
)))
3176 high
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, i
));
3177 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) = high
;
3180 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) =
3181 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, FIRST_LOCAL_BLOCK
));
3183 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) =
3184 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
3185 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) =
3186 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
3190 /* Constructor/restructor/destructor procedures */
3192 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
3193 MAXSYMS and linenumbers MAXLINES we'll put in it */
3195 static struct symtab
*
3196 new_symtab (name
, maxsyms
, maxlines
, objfile
)
3200 struct objfile
*objfile
;
3202 struct symtab
*s
= allocate_symtab (name
, objfile
);
3204 LINETABLE (s
) = new_linetable (maxlines
);
3206 /* All symtabs must have at least two blocks */
3207 BLOCKVECTOR (s
) = new_bvect (2);
3208 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
) = new_block (maxsyms
);
3209 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
) = new_block (maxsyms
);
3210 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)) =
3211 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3213 s
->free_code
= free_linetable
;
3218 /* Allocate a new partial_symtab NAME */
3220 static struct partial_symtab
*
3221 new_psymtab (name
, objfile
)
3223 struct objfile
*objfile
;
3225 struct partial_symtab
*psymtab
;
3227 psymtab
= allocate_psymtab (name
, objfile
);
3229 /* Keep a backpointer to the file's symbols */
3231 psymtab
->read_symtab_private
= ((char *)
3232 obstack_alloc (&objfile
->psymbol_obstack
,
3233 sizeof (struct symloc
)));
3234 memset ((PTR
) psymtab
->read_symtab_private
, 0, sizeof (struct symloc
));
3235 CUR_BFD (psymtab
) = cur_bfd
;
3237 /* The way to turn this into a symtab is to call... */
3238 psymtab
->read_symtab
= mipscoff_psymtab_to_symtab
;
3243 /* Allocate a linetable array of the given SIZE. Since the struct
3244 already includes one item, we subtract one when calculating the
3245 proper size to allocate. */
3247 static struct linetable
*
3248 new_linetable (size
)
3251 struct linetable
*l
;
3253 size
= (size
- 1) * sizeof (l
->item
) + sizeof (struct linetable
);
3254 l
= (struct linetable
*) xmalloc (size
);
3259 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
3260 I am not so sure about the 3.4 ones.
3262 Since the struct linetable already includes one item, we subtract one when
3263 calculating the proper size to allocate. */
3265 static struct linetable
*
3266 shrink_linetable (lt
)
3267 struct linetable
*lt
;
3270 return (struct linetable
*) xrealloc ((PTR
) lt
,
3271 (sizeof (struct linetable
)
3273 * sizeof (lt
->item
))));
3276 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
3278 static struct blockvector
*
3282 struct blockvector
*bv
;
3285 size
= sizeof (struct blockvector
) + nblocks
* sizeof (struct block
*);
3286 bv
= (struct blockvector
*) xzalloc (size
);
3288 BLOCKVECTOR_NBLOCKS (bv
) = nblocks
;
3293 /* Allocate and zero a new block of MAXSYMS symbols */
3295 static struct block
*
3299 int size
= sizeof (struct block
) + (maxsyms
- 1) * sizeof (struct symbol
*);
3301 return (struct block
*) xzalloc (size
);
3304 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
3305 Shrink_block can also be used by add_symbol to grow a block. */
3307 static struct block
*
3313 struct blockvector
*bv
= BLOCKVECTOR (s
);
3316 /* Just reallocate it and fix references to the old one */
3318 new = (struct block
*) xrealloc ((PTR
) b
,
3319 (sizeof (struct block
)
3320 + ((BLOCK_NSYMS (b
) - 1)
3321 * sizeof (struct symbol
*))));
3323 /* Should chase pointers to old one. Fortunately, that`s just
3324 the block`s function and inferior blocks */
3325 if (BLOCK_FUNCTION (new) && SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) == b
)
3326 SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) = new;
3327 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS (bv
); i
++)
3328 if (BLOCKVECTOR_BLOCK (bv
, i
) == b
)
3329 BLOCKVECTOR_BLOCK (bv
, i
) = new;
3330 else if (BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv
, i
)) == b
)
3331 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv
, i
)) = new;
3335 /* Create a new symbol with printname NAME */
3337 static struct symbol
*
3341 struct symbol
*s
= ((struct symbol
*)
3342 obstack_alloc (¤t_objfile
->symbol_obstack
,
3343 sizeof (struct symbol
)));
3345 memset ((PTR
) s
, 0, sizeof (*s
));
3346 SYMBOL_NAME (s
) = name
;
3350 /* Create a new type with printname NAME */
3352 static struct type
*
3358 t
= alloc_type (current_objfile
);
3359 TYPE_NAME (t
) = name
;
3360 TYPE_CPLUS_SPECIFIC (t
) = (struct cplus_struct_type
*) &cplus_struct_default
;
3365 /* Things used for calling functions in the inferior.
3366 These functions are exported to our companion
3367 mips-tdep.c file and are here because they play
3368 with the symbol-table explicitly. */
3370 /* Sigtramp: make sure we have all the necessary information
3371 about the signal trampoline code. Since the official code
3372 from MIPS does not do so, we make up that information ourselves.
3373 If they fix the library (unlikely) this code will neutralize itself. */
3380 struct block
*b
, *b0
;
3382 sigtramp_address
= -1;
3384 /* We have to handle the following cases here:
3385 a) The Mips library has a sigtramp label within sigvec.
3386 b) Irix has a _sigtramp which we want to use, but it also has sigvec. */
3387 s
= lookup_symbol ("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
3390 b0
= SYMBOL_BLOCK_VALUE (s
);
3391 s
= lookup_symbol ("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
3395 /* No sigvec or no sigtramp inside sigvec, try _sigtramp. */
3396 s
= lookup_symbol ("_sigtramp", 0, VAR_NAMESPACE
, 0, NULL
);
3399 /* But maybe this program uses its own version of sigvec */
3403 /* Did we or MIPSco fix the library ? */
3404 if (SYMBOL_CLASS (s
) == LOC_BLOCK
)
3406 sigtramp_address
= BLOCK_START (SYMBOL_BLOCK_VALUE (s
));
3407 sigtramp_end
= BLOCK_END (SYMBOL_BLOCK_VALUE (s
));
3411 sigtramp_address
= SYMBOL_VALUE (s
);
3412 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
3414 /* But what symtab does it live in ? */
3415 st
= find_pc_symtab (SYMBOL_VALUE (s
));
3418 * Ok, there goes the fix: turn it into a procedure, with all the
3419 * needed info. Note we make it a nested procedure of sigvec,
3420 * which is the way the (assembly) code is actually written.
3422 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
3423 SYMBOL_CLASS (s
) = LOC_BLOCK
;
3424 SYMBOL_TYPE (s
) = init_type (TYPE_CODE_FUNC
, 4, 0, (char *) NULL
,
3425 (struct objfile
*) NULL
);
3426 TYPE_TARGET_TYPE (SYMBOL_TYPE (s
)) = builtin_type_void
;
3428 /* Need a block to allocate MIPS_EFI_SYMBOL_NAME in */
3430 SYMBOL_BLOCK_VALUE (s
) = b
;
3431 BLOCK_START (b
) = sigtramp_address
;
3432 BLOCK_END (b
) = sigtramp_end
;
3433 BLOCK_FUNCTION (b
) = s
;
3434 BLOCK_SUPERBLOCK (b
) = BLOCK_SUPERBLOCK (b0
);
3438 /* Make a MIPS_EFI_SYMBOL_NAME entry for it */
3440 struct mips_extra_func_info
*e
=
3441 ((struct mips_extra_func_info
*)
3442 xzalloc (sizeof (struct mips_extra_func_info
)));
3444 e
->numargs
= 0; /* the kernel thinks otherwise */
3445 /* align_longword(sigcontext + SIGFRAME) */
3446 e
->pdr
.frameoffset
= 0x150;
3447 e
->pdr
.framereg
= SP_REGNUM
;
3448 /* read_next_frame_reg provides the true pc at the time of signal */
3449 e
->pdr
.pcreg
= PC_REGNUM
;
3450 e
->pdr
.regmask
= -2;
3451 e
->pdr
.regoffset
= -(41 * sizeof (int));
3452 e
->pdr
.fregmask
= -1;
3453 e
->pdr
.fregoffset
= -(7 * sizeof (int));
3454 e
->pdr
.isym
= (long) s
;
3455 e
->pdr
.adr
= sigtramp_address
;
3457 current_objfile
= st
->objfile
; /* Keep new_symbol happy */
3458 s
= new_symbol (MIPS_EFI_SYMBOL_NAME
);
3459 SYMBOL_VALUE (s
) = (int) e
;
3460 SYMBOL_NAMESPACE (s
) = LABEL_NAMESPACE
;
3461 SYMBOL_CLASS (s
) = LOC_CONST
;
3462 SYMBOL_TYPE (s
) = builtin_type_void
;
3463 current_objfile
= NULL
;
3466 BLOCK_SYM (b
, BLOCK_NSYMS (b
)++) = s
;
3470 /* Fake up identical offsets for all sections. */
3472 struct section_offsets
*
3473 mipscoff_symfile_offsets (objfile
, addr
)
3474 struct objfile
*objfile
;
3477 struct section_offsets
*section_offsets
;
3480 section_offsets
= ((struct section_offsets
*)
3481 obstack_alloc (&objfile
->psymbol_obstack
,
3482 (sizeof (struct section_offsets
)
3483 + (sizeof (section_offsets
->offsets
)
3484 * (SECT_OFF_MAX
- 1)))));
3486 for (i
= 0; i
< SECT_OFF_MAX
; i
++)
3487 ANOFFSET (section_offsets
, i
) = addr
;
3489 return section_offsets
;
3492 /* Initialization */
3494 static struct sym_fns ecoff_sym_fns
=
3496 "ecoff", /* sym_name: name or name prefix of BFD target type */
3497 5, /* sym_namelen: number of significant sym_name chars */
3498 mipscoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
3499 mipscoff_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
3500 mipscoff_symfile_read
, /* sym_read: read a symbol file into symtab */
3501 mipscoff_symfile_finish
, /* sym_finish: finished with file, cleanup */
3502 mipscoff_symfile_offsets
, /* sym_offsets: dummy FIXME til implem sym reloc */
3503 NULL
/* next: pointer to next struct sym_fns */
3508 _initialize_mipsread ()
3510 add_symtab_fns (&ecoff_sym_fns
);
3512 /* Missing basic types */
3514 builtin_type_string
=
3515 init_type (TYPE_CODE_STRING
,
3516 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3518 (struct objfile
*) NULL
);
3519 builtin_type_complex
=
3520 init_type (TYPE_CODE_FLT
,
3521 TARGET_COMPLEX_BIT
/ TARGET_CHAR_BIT
,
3523 (struct objfile
*) NULL
);
3524 builtin_type_double_complex
=
3525 init_type (TYPE_CODE_FLT
,
3526 TARGET_DOUBLE_COMPLEX_BIT
/ TARGET_CHAR_BIT
,
3527 0, "double complex",
3528 (struct objfile
*) NULL
);
3529 builtin_type_fixed_dec
=
3530 init_type (TYPE_CODE_INT
,
3531 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3533 (struct objfile
*) NULL
);
3534 builtin_type_float_dec
=
3535 init_type (TYPE_CODE_FLT
,
3536 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3537 0, "floating decimal",
3538 (struct objfile
*) NULL
);