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 /* Information is passed among various mipsread routines for accessing
114 symbol files. A pointer to this structure is kept in the sym_private
115 field of the objfile struct. */
117 struct ecoff_symfile_info
{
118 struct mips_pending
**pending_list
;
120 #define ECOFF_SYMFILE_INFO(o) ((struct ecoff_symfile_info *)((o)->sym_private))
121 #define ECOFF_PENDING_LIST(o) (ECOFF_SYMFILE_INFO(o)->pending_list)
124 /* Each partial symbol table entry contains a pointer to private data
125 for the read_symtab() function to use when expanding a partial
126 symbol table entry to a full symbol table entry.
128 For mipsread this structure contains the index of the FDR that this
129 psymtab represents and a pointer to the BFD that the psymtab was
132 #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
133 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
134 #define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd)
140 EXTR
*extern_tab
; /* Pointer to external symbols for this file. */
141 int extern_count
; /* Size of extern_tab. */
142 enum language pst_language
;
145 /* Things we import explicitly from other modules */
147 extern int info_verbose
;
149 /* Various complaints about symbol reading that don't abort the process */
151 struct complaint bad_file_number_complaint
=
152 {"bad file number %d", 0, 0};
154 struct complaint index_complaint
=
155 {"bad aux index at symbol %s", 0, 0};
157 struct complaint aux_index_complaint
=
158 {"bad proc end in aux found from symbol %s", 0, 0};
160 struct complaint block_index_complaint
=
161 {"bad aux index at block symbol %s", 0, 0};
163 struct complaint unknown_ext_complaint
=
164 {"unknown external symbol %s", 0, 0};
166 struct complaint unknown_sym_complaint
=
167 {"unknown local symbol %s", 0, 0};
169 struct complaint unknown_st_complaint
=
170 {"with type %d", 0, 0};
172 struct complaint block_overflow_complaint
=
173 {"block containing %s overfilled", 0, 0};
175 struct complaint basic_type_complaint
=
176 {"cannot map MIPS basic type 0x%x for %s", 0, 0};
178 struct complaint unknown_type_qual_complaint
=
179 {"unknown type qualifier 0x%x", 0, 0};
181 struct complaint array_bitsize_complaint
=
182 {"size of array target type not known, assuming %d bits", 0, 0};
184 struct complaint bad_tag_guess_complaint
=
185 {"guessed tag type of %s incorrectly", 0, 0};
187 struct complaint block_member_complaint
=
188 {"declaration block contains unhandled symbol type %d", 0, 0};
190 struct complaint stEnd_complaint
=
191 {"stEnd with storage class %d not handled", 0, 0};
193 struct complaint unknown_mips_symtype_complaint
=
194 {"unknown symbol type 0x%x", 0, 0};
196 struct complaint stab_unknown_complaint
=
197 {"unknown stabs symbol %s", 0, 0};
199 struct complaint pdr_for_nonsymbol_complaint
=
200 {"PDR for %s, but no symbol", 0, 0};
202 struct complaint pdr_static_symbol_complaint
=
203 {"can't handle PDR for static proc at 0x%x", 0, 0};
205 struct complaint bad_setjmp_pdr_complaint
=
206 {"fixing bad setjmp PDR from libc", 0, 0};
208 struct complaint bad_fbitfield_complaint
=
209 {"can't handle TIR fBitfield for %s", 0, 0};
211 struct complaint bad_rfd_entry_complaint
=
212 {"bad rfd entry for %s: file %d, index %d", 0, 0};
214 struct complaint unexpected_type_code_complaint
=
215 {"unexpected type code for %s", 0, 0};
217 /* Macros and extra defs */
219 /* Already-parsed symbols are marked specially */
221 #define stParsed stType
223 /* Puns: hard to find whether -g was used and how */
225 #define MIN_GLEVEL GLEVEL_0
226 #define compare_glevel(a,b) \
227 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
228 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
230 /* Things that really are local to this module */
232 /* Remember what we deduced to be the source language of this psymtab. */
234 static enum language psymtab_language
= language_unknown
;
240 /* Pointer to current file decriptor record, and its index */
245 /* Index of current symbol */
249 /* Note how much "debuggable" this image is. We would like
250 to see at least one FDR with full symbols */
255 /* When examining .o files, report on undefined symbols */
257 static int n_undef_symbols
, n_undef_labels
, n_undef_vars
, n_undef_procs
;
259 /* Pseudo symbol to use when putting stabs into the symbol table. */
261 static char stabs_symbol
[] = STABS_SYMBOL
;
263 /* Extra builtin types */
265 struct type
*builtin_type_complex
;
266 struct type
*builtin_type_double_complex
;
267 struct type
*builtin_type_fixed_dec
;
268 struct type
*builtin_type_float_dec
;
269 struct type
*builtin_type_string
;
271 /* Forward declarations */
274 read_mips_symtab
PARAMS ((struct objfile
*, struct section_offsets
*));
277 read_the_mips_symtab
PARAMS ((bfd
*));
280 upgrade_type
PARAMS ((struct type
**, int, union aux_ext
*, int));
283 parse_partial_symbols
PARAMS ((struct objfile
*,
284 struct section_offsets
*));
287 cross_ref
PARAMS ((union aux_ext
*, struct type
**, enum type_code
, char **,
291 fixup_sigtramp
PARAMS ((void));
293 static struct symbol
*
294 new_symbol
PARAMS ((char *));
297 new_type
PARAMS ((char *));
299 static struct block
*
300 new_block
PARAMS ((int));
302 static struct symtab
*
303 new_symtab
PARAMS ((char *, int, int, struct objfile
*));
305 static struct linetable
*
306 new_linetable
PARAMS ((int));
308 static struct blockvector
*
309 new_bvect
PARAMS ((int));
312 parse_type
PARAMS ((union aux_ext
*, int *, int, char *));
314 static struct symbol
*
315 mylookup_symbol
PARAMS ((char *, struct block
*, enum namespace,
316 enum address_class
));
318 static struct block
*
319 shrink_block
PARAMS ((struct block
*, struct symtab
*));
322 xzalloc
PARAMS ((unsigned int));
325 sort_blocks
PARAMS ((struct symtab
*));
328 compare_blocks
PARAMS ((const void *, const void *));
330 static struct partial_symtab
*
331 new_psymtab
PARAMS ((char *, struct objfile
*));
334 psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*, char *));
337 add_block
PARAMS ((struct block
*, struct symtab
*));
340 add_symbol
PARAMS ((struct symbol
*, struct block
*));
343 add_line
PARAMS ((struct linetable
*, int, CORE_ADDR
, int));
345 static struct linetable
*
346 shrink_linetable
PARAMS ((struct linetable
*));
349 mips_next_symbol_text
PARAMS ((void));
351 /* Things we export to other modules */
353 /* Address bounds for the signal trampoline in inferior, if any */
354 /* FIXME: Nothing really seems to use this. Why is it here? */
356 CORE_ADDR sigtramp_address
, sigtramp_end
;
359 mipscoff_new_init (ignore
)
360 struct objfile
*ignore
;
362 sigtramp_address
= 0;
363 stabsread_new_init ();
364 buildsym_new_init ();
368 mipscoff_symfile_init (objfile
)
369 struct objfile
*objfile
;
371 if (objfile
->sym_private
!= NULL
)
373 mfree (objfile
->md
, objfile
->sym_private
);
375 objfile
->sym_private
= (PTR
)
376 xmmalloc (objfile
->md
, sizeof (struct ecoff_symfile_info
));
380 mipscoff_symfile_read (objfile
, section_offsets
, mainline
)
381 struct objfile
*objfile
;
382 struct section_offsets
*section_offsets
;
385 struct cleanup
* back_to
;
387 init_minimal_symbol_collection ();
388 back_to
= make_cleanup (discard_minimal_symbols
, 0);
390 /* Now that the executable file is positioned at symbol table,
391 process it and define symbols accordingly. */
393 read_mips_symtab (objfile
, section_offsets
);
395 /* Install any minimal symbols that have been collected as the current
396 minimal symbols for this objfile. */
398 install_minimal_symbols (objfile
);
400 do_cleanups (back_to
);
403 /* Perform any local cleanups required when we are done with a particular
404 objfile. I.E, we are in the process of discarding all symbol information
405 for an objfile, freeing up all memory held for it, and unlinking the
406 objfile struct from the global list of known objfiles. */
409 mipscoff_symfile_finish (objfile
)
410 struct objfile
*objfile
;
412 if (objfile
->sym_private
!= NULL
)
414 mfree (objfile
->md
, objfile
->sym_private
);
420 /* Allocate zeroed memory */
426 PTR p
= xmalloc (size
);
432 /* Exported procedure: Builds a symtab from the PST partial one.
433 Restores the environment in effect when PST was created, delegates
434 most of the work to an ancillary procedure, and sorts
435 and reorders the symtab list at the end */
438 mipscoff_psymtab_to_symtab (pst
)
439 struct partial_symtab
*pst
;
447 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
451 next_symbol_text_func
= mips_next_symbol_text
;
453 psymtab_to_symtab_1 (pst
, pst
->filename
);
455 /* Match with global symbols. This only needs to be done once,
456 after all of the symtabs and dependencies have been read in. */
457 scan_file_globals (pst
->objfile
);
460 printf_filtered ("done.\n");
463 /* Exported procedure: Is PC in the signal trampoline code */
466 in_sigtramp (pc
, ignore
)
468 char *ignore
; /* function name */
470 if (sigtramp_address
== 0)
472 return (pc
>= sigtramp_address
&& pc
< sigtramp_end
);
475 /* File-level interface functions */
477 /* Read the symtab information from file ABFD into memory. */
480 read_the_mips_symtab (abfd
)
483 if (ecoff_slurp_symbolic_info (abfd
) == false)
484 error ("Error reading symbol table: %s", bfd_errmsg (bfd_error
));
487 /* Find a file descriptor given its index RF relative to a file CF */
497 fdrs
= ecoff_data (cur_bfd
)->fdr
;
499 /* Object files do not have the RFD table, all refs are absolute */
502 (*ecoff_backend (cur_bfd
)->swap_rfd_in
)
504 ((char *) ecoff_data (cur_bfd
)->external_rfd
505 + (f
->rfdBase
+ rf
) * ecoff_backend (cur_bfd
)->external_rfd_size
),
510 /* Return a safer print NAME for a file descriptor */
517 return "<stripped file>";
520 return ecoff_data (cur_bfd
)->ss
+ f
->issBase
+ f
->rss
;
524 /* Read in and parse the symtab of the file OBJFILE. Symbols from
525 different sections are relocated via the SECTION_OFFSETS. */
528 read_mips_symtab (objfile
, section_offsets
)
529 struct objfile
*objfile
;
530 struct section_offsets
*section_offsets
;
532 cur_bfd
= objfile
->obfd
;
534 read_the_mips_symtab (objfile
->obfd
);
536 parse_partial_symbols (objfile
, section_offsets
);
539 /* Check to make sure file was compiled with -g. If not, warn the
540 user of this limitation. */
541 if (compare_glevel (max_glevel
, GLEVEL_2
) < 0)
543 if (max_gdbinfo
== 0)
544 printf ("\n%s not compiled with -g, debugging support is limited.\n",
546 printf ("You should compile with -g2 or -g3 for best debugging support.\n");
552 /* Local utilities */
554 /* Map of FDR indexes to partial symtabs */
558 struct partial_symtab
*pst
; /* the psymtab proper */
559 int n_globals
; /* exported globals (external symbols) */
560 int globals_offset
; /* cumulative */
564 /* Utility stack, used to nest procedures and blocks properly.
565 It is a doubly linked list, to avoid too many alloc/free.
566 Since we might need it quite a few times it is NOT deallocated
569 static struct parse_stack
571 struct parse_stack
*next
, *prev
;
572 struct symtab
*cur_st
; /* Current symtab. */
573 struct block
*cur_block
; /* Block in it. */
574 int blocktype
; /* What are we parsing. */
575 int maxsyms
; /* Max symbols in this block. */
576 struct type
*cur_type
; /* Type we parse fields for. */
577 int cur_field
; /* Field number in cur_type. */
578 int procadr
; /* Start addres of this procedure */
579 int numargs
; /* Its argument count */
582 *top_stack
; /* Top stack ptr */
585 /* Enter a new lexical context */
590 struct parse_stack
*new;
592 /* Reuse frames if possible */
593 if (top_stack
&& top_stack
->prev
)
594 new = top_stack
->prev
;
596 new = (struct parse_stack
*) xzalloc (sizeof (struct parse_stack
));
597 /* Initialize new frame with previous content */
600 register struct parse_stack
*prev
= new->prev
;
603 top_stack
->prev
= new;
605 new->next
= top_stack
;
610 /* Exit a lexical context */
618 top_stack
= top_stack
->next
;
622 /* Cross-references might be to things we haven't looked at
623 yet, e.g. type references. To avoid too many type
624 duplications we keep a quick fixup table, an array
625 of lists of references indexed by file descriptor */
629 struct mips_pending
*next
; /* link */
630 char *s
; /* the unswapped symbol */
631 struct type
*t
; /* its partial type descriptor */
635 /* Check whether we already saw symbol SH in file FH as undefined */
637 static struct mips_pending
*
638 is_pending_symbol (fh
, sh
)
642 int f_idx
= fh
- ecoff_data (cur_bfd
)->fdr
;
643 register struct mips_pending
*p
;
644 struct mips_pending
**pending_list
= ECOFF_PENDING_LIST (current_objfile
);
646 /* Linear search is ok, list is typically no more than 10 deep */
647 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
653 /* Add a new undef symbol SH of type T */
656 add_pending (fh
, sh
, t
)
661 int f_idx
= fh
- ecoff_data (cur_bfd
)->fdr
;
662 struct mips_pending
*p
= is_pending_symbol (fh
, sh
);
664 /* Make sure we do not make duplicates */
667 struct mips_pending
**pending_list
= ECOFF_PENDING_LIST (current_objfile
);
669 p
= ((struct mips_pending
*)
670 obstack_alloc (¤t_objfile
->psymbol_obstack
,
671 sizeof (struct mips_pending
)));
674 p
->next
= pending_list
[f_idx
];
675 pending_list
[f_idx
] = p
;
680 /* Parsing Routines proper. */
682 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
683 For blocks, procedures and types we open a new lexical context.
684 This is basically just a big switch on the symbol's type. Argument
685 AX is the base pointer of aux symbols for this file (fh->iauxBase).
686 EXT_SH points to the unswapped symbol, which is needed for struct,
687 union, etc., types; it is NULL for an EXTR. BIGEND says whether
688 aux symbols are big-endian or little-endian. Return count of
689 SYMR's handled (normally one).
691 FIXME: This modifies the symbol, but the only way we have to save
692 the modified information is to stuff it back into the BFD data. */
695 parse_symbol (sh
, ax
, ext_sh
, bigend
)
701 const bfd_size_type external_sym_size
702 = ecoff_backend (cur_bfd
)->external_sym_size
;
703 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*)) =
704 ecoff_backend (cur_bfd
)->swap_sym_in
;
708 struct mips_pending
*pend
;
712 enum address_class
class;
715 if (ext_sh
== (char *) NULL
)
716 name
= ecoff_data (cur_bfd
)->ssext
+ sh
->iss
;
718 name
= ecoff_data (cur_bfd
)->ss
+ cur_fdr
->issBase
+ sh
->iss
;
725 case stGlobal
: /* external symbol, goes into global block */
727 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack
->cur_st
),
729 s
= new_symbol (name
);
730 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
733 case stStatic
: /* static data, goes into current block. */
735 b
= top_stack
->cur_block
;
736 s
= new_symbol (name
);
737 if (sh
->sc
== scCommon
)
739 /* It is a FORTRAN common block. At least for SGI Fortran the
740 address is not in the symbol; we need to fix it later in
741 scan_file_globals. */
742 int bucket
= hashname (SYMBOL_NAME (s
));
743 SYMBOL_VALUE_CHAIN (s
) = global_sym_chain
[bucket
];
744 global_sym_chain
[bucket
] = s
;
747 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
750 case stLocal
: /* local variable, goes into current block */
751 if (sh
->sc
== scRegister
)
753 class = LOC_REGISTER
;
755 sh
->value
+= FP0_REGNUM
- 32;
759 b
= top_stack
->cur_block
;
760 s
= new_symbol (name
);
761 SYMBOL_VALUE (s
) = sh
->value
;
763 data
: /* Common code for symbols describing data */
764 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
765 SYMBOL_CLASS (s
) = class;
768 /* Type could be missing in a number of cases */
769 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
770 sh
->index
== 0xfffff)
771 SYMBOL_TYPE (s
) = builtin_type_int
; /* undefined? */
773 SYMBOL_TYPE (s
) = parse_type (ax
+ sh
->index
, 0, bigend
, name
);
774 /* Value of a data symbol is its memory address */
777 case stParam
: /* arg to procedure, goes into current block */
779 top_stack
->numargs
++;
781 /* Special GNU C++ name. */
782 if (name
[0] == CPLUS_MARKER
&& name
[1] == 't' && name
[2] == 0)
783 name
= "this"; /* FIXME, not alloc'd in obstack */
784 s
= new_symbol (name
);
786 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
790 /* Pass by value in register. */
791 SYMBOL_CLASS(s
) = LOC_REGPARM
;
793 sh
->value
+= FP0_REGNUM
-32;
796 /* Pass by reference on stack. */
797 SYMBOL_CLASS(s
) = LOC_REF_ARG
;
800 /* Pass by reference in register. */
801 SYMBOL_CLASS(s
) = LOC_REGPARM_ADDR
;
804 /* Pass by value on stack. */
805 SYMBOL_CLASS(s
) = LOC_ARG
;
808 SYMBOL_VALUE (s
) = sh
->value
;
809 SYMBOL_TYPE (s
) = parse_type (ax
+ sh
->index
, 0, bigend
, name
);
810 add_symbol (s
, top_stack
->cur_block
);
812 /* FIXME: This has not been tested. See dbxread.c */
813 /* Add the type of this parameter to the function/procedure
814 type of this block. */
815 add_param_to_type (&top_stack
->cur_block
->function
->type
, s
);
819 case stLabel
: /* label, goes into current block */
820 s
= new_symbol (name
);
821 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
; /* so that it can be used */
822 SYMBOL_CLASS (s
) = LOC_LABEL
; /* but not misused */
823 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
824 SYMBOL_TYPE (s
) = builtin_type_int
;
825 add_symbol (s
, top_stack
->cur_block
);
828 case stProc
: /* Procedure, usually goes into global block */
829 case stStaticProc
: /* Static procedure, goes into current block */
830 s
= new_symbol (name
);
831 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
832 SYMBOL_CLASS (s
) = LOC_BLOCK
;
833 /* Type of the return value */
834 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
835 t
= builtin_type_int
;
837 t
= parse_type (ax
+ sh
->index
+ 1, 0, bigend
, name
);
838 b
= top_stack
->cur_block
;
839 if (sh
->st
== stProc
)
841 struct blockvector
*bv
= BLOCKVECTOR (top_stack
->cur_st
);
842 /* The next test should normally be true,
843 but provides a hook for nested functions
844 (which we don't want to make global). */
845 if (b
== BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
))
846 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
850 /* Make a type for the procedure itself */
852 /* FIXME: This has not been tested yet! See dbxread.c */
853 /* Generate a template for the type of this function. The
854 types of the arguments will be added as we read the symbol
856 memcpy (lookup_function_type (t
), SYMBOL_TYPE (s
), sizeof (struct type
));
858 SYMBOL_TYPE (s
) = lookup_function_type (t
);
861 /* Create and enter a new lexical context */
862 b
= new_block (top_stack
->maxsyms
);
863 SYMBOL_BLOCK_VALUE (s
) = b
;
864 BLOCK_FUNCTION (b
) = s
;
865 BLOCK_START (b
) = BLOCK_END (b
) = sh
->value
;
866 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
867 add_block (b
, top_stack
->cur_st
);
869 /* Not if we only have partial info */
870 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
874 top_stack
->cur_block
= b
;
875 top_stack
->blocktype
= sh
->st
;
876 top_stack
->cur_type
= SYMBOL_TYPE (s
);
877 top_stack
->cur_field
= -1;
878 top_stack
->procadr
= sh
->value
;
879 top_stack
->numargs
= 0;
881 sh
->value
= (long) SYMBOL_TYPE (s
);
885 /* Beginning of code for structure, union, and enum definitions.
886 They all share a common set of local variables, defined here. */
888 enum type_code type_code
;
894 case stStruct
: /* Start a block defining a struct type */
895 type_code
= TYPE_CODE_STRUCT
;
896 goto structured_common
;
898 case stUnion
: /* Start a block defining a union type */
899 type_code
= TYPE_CODE_UNION
;
900 goto structured_common
;
902 case stEnum
: /* Start a block defining an enum type */
903 type_code
= TYPE_CODE_ENUM
;
904 goto structured_common
;
906 case stBlock
: /* Either a lexical block, or some type */
907 if (sh
->sc
!= scInfo
&& sh
->sc
!= scCommon
)
908 goto case_stBlock_code
; /* Lexical block */
910 type_code
= TYPE_CODE_UNDEF
; /* We have a type. */
912 /* Common code for handling struct, union, enum, and/or as-yet-
913 unknown-type blocks of info about structured data. `type_code'
914 has been set to the proper TYPE_CODE, if we know it. */
917 top_stack
->blocktype
= stBlock
;
919 s
= new_symbol (name
);
920 SYMBOL_NAMESPACE (s
) = STRUCT_NAMESPACE
;
921 SYMBOL_CLASS (s
) = LOC_TYPEDEF
;
922 SYMBOL_VALUE (s
) = 0;
923 add_symbol (s
, top_stack
->cur_block
);
925 /* First count the number of fields and the highest value. */
928 for (ext_tsym
= ext_sh
+ external_sym_size
;
930 ext_tsym
+= external_sym_size
)
934 (*swap_sym_in
) (cur_bfd
, ext_tsym
, &tsym
);
942 if (nfields
== 0 && type_code
== TYPE_CODE_UNDEF
)
943 /* If the type of the member is Nil (or Void),
944 without qualifiers, assume the tag is an
946 if (tsym
.index
== indexNil
)
947 type_code
= TYPE_CODE_ENUM
;
950 ecoff_swap_tir_in (bigend
,
951 &ax
[tsym
.index
].a_ti
,
953 if ((tir
.bt
== btNil
|| tir
.bt
== btVoid
)
955 type_code
= TYPE_CODE_ENUM
;
958 if (tsym
.value
> max_value
)
959 max_value
= tsym
.value
;
969 /* This is a no-op; is it trying to tell us something
970 we should be checking? */
971 if (tsym
.sc
== scVariant
); /*UNIMPLEMENTED*/
975 /* This is something like a struct within a
976 struct. Skip over the fields of the inner
977 struct. The -1 is because the for loop will
978 increment ext_tsym. */
979 ext_tsym
= ((char *) ecoff_data (cur_bfd
)->external_sym
980 + ((cur_fdr
->isymBase
+ tsym
.index
- 1)
981 * external_sym_size
));
987 /* mips cc puts out a typedef for struct x if it is not yet
988 defined when it encounters
989 struct y { struct x *xp; };
994 complain (&block_member_complaint
, tsym
.st
);
999 /* In an stBlock, there is no way to distinguish structs,
1000 unions, and enums at this point. This is a bug in the
1001 original design (that has been fixed with the recent
1002 addition of the stStruct, stUnion, and stEnum symbol
1003 types.) The way you can tell is if/when you see a variable
1004 or field of that type. In that case the variable's type
1005 (in the AUX table) says if the type is struct, union, or
1006 enum, and points back to the stBlock here. So you can
1007 patch the tag kind up later - but only if there actually is
1008 a variable or field of that type.
1010 So until we know for sure, we will guess at this point.
1012 If the first member has index==indexNil or a void type,
1013 assume we have an enumeration.
1014 Otherwise, if there is more than one member, and all
1015 the members have offset 0, assume we have a union.
1016 Otherwise, assume we have a struct.
1018 The heuristic could guess wrong in the case of of an
1019 enumeration with no members or a union with one (or zero)
1020 members, or when all except the last field of a struct have
1021 width zero. These are uncommon and/or illegal situations,
1022 and in any case guessing wrong probably doesn't matter
1025 But if we later do find out we were wrong, we fixup the tag
1026 kind. Members of an enumeration must be handled
1027 differently from struct/union fields, and that is harder to
1028 patch up, but luckily we shouldn't need to. (If there are
1029 any enumeration members, we can tell for sure it's an enum
1032 if (type_code
== TYPE_CODE_UNDEF
)
1033 if (nfields
> 1 && max_value
== 0)
1034 type_code
= TYPE_CODE_UNION
;
1036 type_code
= TYPE_CODE_STRUCT
;
1038 /* If this type was expected, use its partial definition */
1039 pend
= is_pending_symbol (cur_fdr
, ext_sh
);
1040 if (pend
!= (struct mips_pending
*) NULL
)
1043 t
= new_type (NULL
);
1045 TYPE_TAG_NAME (t
) = obconcat (¤t_objfile
->symbol_obstack
,
1047 TYPE_CODE (t
) = type_code
;
1048 TYPE_LENGTH (t
) = sh
->value
;
1049 TYPE_NFIELDS (t
) = nfields
;
1050 TYPE_FIELDS (t
) = f
= ((struct field
*)
1052 nfields
* sizeof (struct field
)));
1053 /* Handle opaque struct definitions. */
1054 if (TYPE_NFIELDS (t
) == 0)
1056 TYPE_FLAGS (t
) |= TYPE_FLAG_STUB
;
1057 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
1060 if (type_code
== TYPE_CODE_ENUM
)
1062 /* This is a non-empty enum. */
1063 for (ext_tsym
= ext_sh
+ external_sym_size
;
1065 ext_tsym
+= external_sym_size
)
1068 struct symbol
*enum_sym
;
1070 (*swap_sym_in
) (cur_bfd
, ext_tsym
, &tsym
);
1072 if (tsym
.st
!= stMember
)
1075 f
->bitpos
= tsym
.value
;
1077 f
->name
= (ecoff_data (cur_bfd
)->ss
1082 enum_sym
= ((struct symbol
*)
1083 obstack_alloc (¤t_objfile
->symbol_obstack
,
1084 sizeof (struct symbol
)));
1085 memset ((PTR
) enum_sym
, 0, sizeof (struct symbol
));
1086 SYMBOL_NAME (enum_sym
) = f
->name
;
1087 SYMBOL_CLASS (enum_sym
) = LOC_CONST
;
1088 SYMBOL_TYPE (enum_sym
) = t
;
1089 SYMBOL_NAMESPACE (enum_sym
) = VAR_NAMESPACE
;
1090 SYMBOL_VALUE (enum_sym
) = tsym
.value
;
1091 add_symbol (enum_sym
, top_stack
->cur_block
);
1093 /* Skip the stMembers that we've handled. */
1098 SYMBOL_TYPE (s
) = t
;
1099 /* make this the current type */
1100 top_stack
->cur_type
= t
;
1101 top_stack
->cur_field
= 0;
1102 /* Mark that symbol has a type, and say which one */
1103 sh
->value
= (long) t
;
1107 /* End of local variables shared by struct, union, enum, and
1108 block (as yet unknown struct/union/enum) processing. */
1112 /* beginnning of (code) block. Value of symbol
1113 is the displacement from procedure start */
1114 push_parse_stack ();
1115 top_stack
->blocktype
= stBlock
;
1116 b
= new_block (top_stack
->maxsyms
);
1117 BLOCK_START (b
) = sh
->value
+ top_stack
->procadr
;
1118 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
1119 top_stack
->cur_block
= b
;
1120 add_block (b
, top_stack
->cur_st
);
1123 case stEnd
: /* end (of anything) */
1124 if (sh
->sc
== scInfo
|| sh
->sc
== scCommon
)
1126 /* Finished with type */
1127 top_stack
->cur_type
= 0;
1129 else if (sh
->sc
== scText
&&
1130 (top_stack
->blocktype
== stProc
||
1131 top_stack
->blocktype
== stStaticProc
))
1133 /* Finished with procedure */
1134 struct blockvector
*bv
= BLOCKVECTOR (top_stack
->cur_st
);
1135 struct mips_extra_func_info
*e
;
1139 BLOCK_END (top_stack
->cur_block
) += sh
->value
; /* size */
1141 /* Make up special symbol to contain procedure specific info */
1142 s
= new_symbol (MIPS_EFI_SYMBOL_NAME
);
1143 SYMBOL_NAMESPACE (s
) = LABEL_NAMESPACE
;
1144 SYMBOL_CLASS (s
) = LOC_CONST
;
1145 SYMBOL_TYPE (s
) = builtin_type_void
;
1146 e
= ((struct mips_extra_func_info
*)
1147 obstack_alloc (¤t_objfile
->symbol_obstack
,
1148 sizeof (struct mips_extra_func_info
)));
1149 SYMBOL_VALUE (s
) = (int) e
;
1150 e
->numargs
= top_stack
->numargs
;
1151 add_symbol (s
, top_stack
->cur_block
);
1153 /* Reallocate symbols, saving memory */
1154 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
1156 /* f77 emits proc-level with address bounds==[0,0],
1157 So look for such child blocks, and patch them. */
1158 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS (bv
); i
++)
1160 struct block
*b_bad
= BLOCKVECTOR_BLOCK (bv
, i
);
1161 if (BLOCK_SUPERBLOCK (b_bad
) == b
1162 && BLOCK_START (b_bad
) == top_stack
->procadr
1163 && BLOCK_END (b_bad
) == top_stack
->procadr
)
1165 BLOCK_START (b_bad
) = BLOCK_START (b
);
1166 BLOCK_END (b_bad
) = BLOCK_END (b
);
1170 else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
)
1172 /* End of (code) block. The value of the symbol is the
1173 displacement from the procedure`s start address of the
1174 end of this block. */
1175 BLOCK_END (top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1176 shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
1178 else if (sh
->sc
== scText
&& top_stack
->blocktype
== stFile
)
1180 /* End of file. Pop parse stack and ignore. Higher
1181 level code deals with this. */
1185 complain (&stEnd_complaint
, sh
->sc
);
1187 pop_parse_stack (); /* restore previous lexical context */
1190 case stMember
: /* member of struct or union */
1191 f
= &TYPE_FIELDS (top_stack
->cur_type
)[top_stack
->cur_field
++];
1193 f
->bitpos
= sh
->value
;
1195 f
->type
= parse_type (ax
+ sh
->index
, &f
->bitsize
, bigend
, name
);
1198 case stTypedef
: /* type definition */
1199 s
= new_symbol (name
);
1200 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
1201 SYMBOL_CLASS (s
) = LOC_TYPEDEF
;
1202 SYMBOL_BLOCK_VALUE (s
) = top_stack
->cur_block
;
1203 add_symbol (s
, top_stack
->cur_block
);
1204 SYMBOL_TYPE (s
) = parse_type (ax
+ sh
->index
, 0, bigend
, name
);
1205 sh
->value
= (long) SYMBOL_TYPE (s
);
1207 if (TYPE_TAG_NAME (SYMBOL_TYPE (s
)) != NULL
1208 && STREQ (TYPE_TAG_NAME (SYMBOL_TYPE (s
)), "<undefined>"))
1210 /* mips cc puts out a stTypedef for opaque struct definitions. */
1211 TYPE_FLAGS (SYMBOL_TYPE (s
)) |= TYPE_FLAG_STUB
;
1213 /* Incomplete definitions of structs should not get a name. */
1214 if (TYPE_NAME (SYMBOL_TYPE (s
)) == NULL
1215 && (TYPE_NFIELDS (SYMBOL_TYPE (s
)) != 0
1216 || (TYPE_CODE (SYMBOL_TYPE (s
)) != TYPE_CODE_STRUCT
1217 && TYPE_CODE (SYMBOL_TYPE (s
)) != TYPE_CODE_UNION
)))
1219 if (TYPE_CODE (SYMBOL_TYPE (s
)) == TYPE_CODE_PTR
1220 || TYPE_CODE (SYMBOL_TYPE (s
)) == TYPE_CODE_FUNC
)
1222 /* If we are giving a name to a type such as "pointer to
1223 foo" or "function returning foo", we better not set
1224 the TYPE_NAME. If the program contains "typedef char
1225 *caddr_t;", we don't want all variables of type char
1226 * to print as caddr_t. This is not just a
1227 consequence of GDB's type management; CC and GCC (at
1228 least through version 2.4) both output variables of
1229 either type char * or caddr_t with the type
1230 refering to the stTypedef symbol for caddr_t. If a future
1231 compiler cleans this up it GDB is not ready for it
1232 yet, but if it becomes ready we somehow need to
1233 disable this check (without breaking the PCC/GCC2.4
1238 Fortunately, this check seems not to be necessary
1239 for anything except pointers or functions. */
1242 TYPE_NAME (SYMBOL_TYPE (s
)) = SYMBOL_NAME (s
);
1246 case stFile
: /* file name */
1247 push_parse_stack ();
1248 top_stack
->blocktype
= sh
->st
;
1251 /* I`ve never seen these for C */
1253 break; /* register relocation */
1255 break; /* forwarding address */
1257 break; /* constant */
1259 complain (&unknown_mips_symtype_complaint
, sh
->st
);
1266 /* Parse the type information provided in the raw AX entries for
1267 the symbol SH. Return the bitfield size in BS, in case.
1268 We must byte-swap the AX entries before we use them; BIGEND says whether
1269 they are big-endian or little-endian (from fh->fBigendian). */
1271 static struct type
*
1272 parse_type (ax
, bs
, bigend
, sym_name
)
1278 /* Null entries in this map are treated specially */
1279 static struct type
**map_bt
[] =
1281 &builtin_type_void
, /* btNil */
1283 &builtin_type_char
, /* btChar */
1284 &builtin_type_unsigned_char
,/* btUChar */
1285 &builtin_type_short
, /* btShort */
1286 &builtin_type_unsigned_short
, /* btUShort */
1287 &builtin_type_int
, /* btInt */
1288 &builtin_type_unsigned_int
, /* btUInt */
1289 &builtin_type_long
, /* btLong */
1290 &builtin_type_unsigned_long
,/* btULong */
1291 &builtin_type_float
, /* btFloat */
1292 &builtin_type_double
, /* btDouble */
1299 &builtin_type_complex
, /* btComplex */
1300 &builtin_type_double_complex
, /* btDComplex */
1302 &builtin_type_fixed_dec
, /* btFixedDec */
1303 &builtin_type_float_dec
, /* btFloatDec */
1304 &builtin_type_string
, /* btString */
1307 &builtin_type_void
, /* btVoid */
1308 &builtin_type_long_long
, /* btLongLong */
1309 &builtin_type_unsigned_long_long
, /* btULongLong */
1313 struct type
*tp
= 0;
1315 enum type_code type_code
= TYPE_CODE_UNDEF
;
1317 /* Use aux as a type information record, map its basic type. */
1319 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1320 if (t
->bt
>= (sizeof (map_bt
) / sizeof (*map_bt
)))
1322 complain (&basic_type_complaint
, t
->bt
, sym_name
);
1323 return builtin_type_int
;
1327 tp
= *map_bt
[t
->bt
];
1332 /* Cannot use builtin types -- build our own */
1336 tp
= lookup_pointer_type (builtin_type_void
);
1339 type_code
= TYPE_CODE_STRUCT
;
1342 type_code
= TYPE_CODE_UNION
;
1345 type_code
= TYPE_CODE_ENUM
;
1348 type_code
= TYPE_CODE_RANGE
;
1351 type_code
= TYPE_CODE_SET
;
1355 complain (&basic_type_complaint
, t
->bt
, sym_name
);
1356 return builtin_type_int
;
1360 /* Skip over any further type qualifiers (FIXME). */
1363 /* This is the way it would work if the compiler worked */
1368 ecoff_swap_tir_in (bigend
, &ax
->a_ti
, t1
);
1370 while (t1
->continued
);
1373 /* Move on to next aux */
1378 /* Inhibit core dumps with some cfront generated objects that
1380 if (bs
== (int *)NULL
)
1382 complain (&bad_fbitfield_complaint
, sym_name
);
1383 return builtin_type_int
;
1385 *bs
= AUX_GET_WIDTH (bigend
, ax
);
1389 /* All these types really point to some (common) MIPS type
1390 definition, and only the type-qualifiers fully identify
1391 them. We'll make the same effort at sharing. */
1392 if (t
->bt
== btStruct
||
1396 /* btSet (I think) implies that the name is a tag name, not a typedef
1397 name. This apparently is a MIPS extension for C sets. */
1402 /* Try to cross reference this type */
1403 ax
+= cross_ref (ax
, &tp
, type_code
, &name
, bigend
, sym_name
);
1404 /* reading .o file ? */
1405 if (tp
== (struct type
*) NULL
)
1406 tp
= init_type (type_code
, 0, 0, (char *) NULL
,
1407 (struct objfile
*) NULL
);
1409 /* Make sure that TYPE_CODE(tp) has an expected type code.
1410 Any type may be returned from cross_ref if file indirect entries
1412 if (TYPE_CODE (tp
) != TYPE_CODE_STRUCT
1413 && TYPE_CODE (tp
) != TYPE_CODE_UNION
1414 && TYPE_CODE (tp
) != TYPE_CODE_ENUM
)
1416 complain (&unexpected_type_code_complaint
, sym_name
);
1421 /* Usually, TYPE_CODE(tp) is already type_code. The main
1422 exception is if we guessed wrong re struct/union/enum. */
1423 if (TYPE_CODE (tp
) != type_code
)
1425 complain (&bad_tag_guess_complaint
, sym_name
);
1426 TYPE_CODE (tp
) = type_code
;
1428 /* Do not set the tag name if it is a compiler generated tag name
1429 (.Fxx or .xxfake or empty) for unnamed struct/union/enums. */
1430 if (name
[0] == '.' || name
[0] == '\0')
1431 TYPE_TAG_NAME (tp
) = NULL
;
1432 else if (TYPE_TAG_NAME (tp
) == NULL
1433 || !STREQ (TYPE_TAG_NAME (tp
), name
))
1434 TYPE_TAG_NAME (tp
) = obsavestring (name
, strlen (name
),
1435 ¤t_objfile
->type_obstack
);
1439 /* All these types really point to some (common) MIPS type
1440 definition, and only the type-qualifiers fully identify
1441 them. We'll make the same effort at sharing.
1442 FIXME: btIndirect cannot happen here as it is handled by the
1443 switch t->bt above. And we are not doing any guessing on range types. */
1444 if (t
->bt
== btIndirect
||
1449 /* Try to cross reference this type */
1450 ax
+= cross_ref (ax
, &tp
, type_code
, &name
, bigend
, sym_name
);
1451 /* reading .o file ? */
1452 if (tp
== (struct type
*) NULL
)
1453 tp
= init_type (type_code
, 0, 0, (char *) NULL
,
1454 (struct objfile
*) NULL
);
1456 /* Make sure that TYPE_CODE(tp) has an expected type code.
1457 Any type may be returned from cross_ref if file indirect entries
1459 if (TYPE_CODE (tp
) != TYPE_CODE_RANGE
)
1461 complain (&unexpected_type_code_complaint
, sym_name
);
1465 /* Usually, TYPE_CODE(tp) is already type_code. The main
1466 exception is if we guessed wrong re struct/union/enum. */
1467 if (TYPE_CODE (tp
) != type_code
)
1469 complain (&bad_tag_guess_complaint
, sym_name
);
1470 TYPE_CODE (tp
) = type_code
;
1472 if (TYPE_NAME (tp
) == NULL
|| !STREQ (TYPE_NAME (tp
), name
))
1473 TYPE_NAME (tp
) = obsavestring (name
, strlen (name
),
1474 ¤t_objfile
->type_obstack
);
1478 /* Deal with range types */
1479 if (t
->bt
== btRange
)
1481 TYPE_NFIELDS (tp
) = 2;
1482 TYPE_FIELDS (tp
) = ((struct field
*)
1483 TYPE_ALLOC (tp
, 2 * sizeof (struct field
)));
1484 TYPE_FIELD_NAME (tp
, 0) = obsavestring ("Low", strlen ("Low"),
1485 ¤t_objfile
->type_obstack
);
1486 TYPE_FIELD_BITPOS (tp
, 0) = AUX_GET_DNLOW (bigend
, ax
);
1488 TYPE_FIELD_NAME (tp
, 1) = obsavestring ("High", strlen ("High"),
1489 ¤t_objfile
->type_obstack
);
1490 TYPE_FIELD_BITPOS (tp
, 1) = AUX_GET_DNHIGH (bigend
, ax
);
1494 /* Parse all the type qualifiers now. If there are more
1495 than 6 the game will continue in the next aux */
1497 #define PARSE_TQ(tq) \
1498 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, bigend);
1500 again
:PARSE_TQ (tq0
);
1511 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1517 /* Make up a complex type from a basic one. Type is passed by
1518 reference in TPP and side-effected as necessary. The type
1519 qualifier TQ says how to handle the aux symbols at AX for
1520 the symbol SX we are currently analyzing. BIGEND says whether
1521 aux symbols are big-endian or little-endian.
1522 Returns the number of aux symbols we parsed. */
1525 upgrade_type (tpp
, tq
, ax
, bigend
)
1534 /* Used in array processing */
1545 t
= lookup_pointer_type (*tpp
);
1550 t
= lookup_function_type (*tpp
);
1557 /* Determine and record the domain type (type of index) */
1558 ecoff_swap_rndx_in (bigend
, &ax
->a_rndx
, &rndx
);
1564 rf
= AUX_GET_ISYM (bigend
, ax
);
1567 fh
= get_rfd (cur_fd
, rf
);
1569 indx
= parse_type ((ecoff_data (cur_bfd
)->external_aux
1572 (int *) NULL
, bigend
, "<array index>");
1574 /* Get the bounds, and create the array type. */
1576 lower
= AUX_GET_DNLOW (bigend
, ax
);
1578 upper
= AUX_GET_DNHIGH (bigend
, ax
);
1580 rf
= AUX_GET_WIDTH (bigend
, ax
); /* bit size of array element */
1582 range
= create_range_type ((struct type
*) NULL
, indx
,
1585 t
= create_array_type ((struct type
*) NULL
, *tpp
, range
);
1587 /* Check whether supplied array element bit size matches
1588 the known size of the element type. If this complaint
1589 ends up not happening, we can remove this code. It's
1590 here because we aren't sure we understand this *&%&$
1592 id
= TYPE_LENGTH (TYPE_TARGET_TYPE (t
)) << 3; /* bitsize */
1595 /* Most likely an undefined type */
1597 TYPE_LENGTH (TYPE_TARGET_TYPE (t
)) = id
>> 3;
1600 complain (&array_bitsize_complaint
, rf
);
1606 /* Volatile -- currently ignored */
1610 /* Const -- currently ignored */
1614 complain (&unknown_type_qual_complaint
, tq
);
1620 /* Parse a procedure descriptor record PR. Note that the procedure is
1621 parsed _after_ the local symbols, now we just insert the extra
1622 information we need into a MIPS_EFI_SYMBOL_NAME symbol that has
1623 already been placed in the procedure's main block. Note also that
1624 images that have been partially stripped (ld -x) have been deprived
1625 of local symbols, and we have to cope with them here. FIRST_OFF is
1626 the offset of the first procedure for this FDR; we adjust the
1627 address by this amount, but I don't know why. SEARCH_SYMTAB is the symtab
1628 to look for the function which contains the MIPS_EFI_SYMBOL_NAME symbol
1629 in question, or NULL to use top_stack->cur_block. */
1631 static void parse_procedure
PARAMS ((PDR
*, struct symtab
*, unsigned long));
1634 parse_procedure (pr
, search_symtab
, first_off
)
1636 struct symtab
*search_symtab
;
1637 unsigned long first_off
;
1639 struct symbol
*s
, *i
;
1641 struct mips_extra_func_info
*e
;
1644 /* Simple rule to find files linked "-x" */
1645 if (cur_fdr
->rss
== -1)
1649 /* Static procedure at address pr->adr. Sigh. */
1650 complain (&pdr_static_symbol_complaint
, pr
->adr
);
1658 (*ecoff_backend (cur_bfd
)->swap_ext_in
)
1660 ((char *) ecoff_data (cur_bfd
)->external_ext
1661 + pr
->isym
* ecoff_backend (cur_bfd
)->external_ext_size
),
1663 sh_name
= ecoff_data (cur_bfd
)->ssext
+ she
.asym
.iss
;
1671 (*ecoff_backend (cur_bfd
)->swap_sym_in
)
1673 ((char *) ecoff_data (cur_bfd
)->external_sym
1674 + ((cur_fdr
->isymBase
+ pr
->isym
)
1675 * ecoff_backend (cur_bfd
)->external_sym_size
)),
1677 sh_name
= ecoff_data (cur_bfd
)->ss
+ cur_fdr
->issBase
+ sh
.iss
;
1680 if (search_symtab
!= NULL
)
1683 /* This loses both in the case mentioned (want a static, find a global),
1684 but also if we are looking up a non-mangled name which happens to
1685 match the name of a mangled function. */
1686 /* We have to save the cur_fdr across the call to lookup_symbol.
1687 If the pdr is for a static function and if a global function with
1688 the same name exists, lookup_symbol will eventually read in the symtab
1689 for the global function and clobber cur_fdr. */
1690 FDR
*save_cur_fdr
= cur_fdr
;
1691 s
= lookup_symbol (sh_name
, NULL
, VAR_NAMESPACE
, 0, NULL
);
1692 cur_fdr
= save_cur_fdr
;
1696 BLOCKVECTOR_BLOCK (BLOCKVECTOR (search_symtab
), STATIC_BLOCK
),
1702 s
= mylookup_symbol (sh_name
, top_stack
->cur_block
,
1703 VAR_NAMESPACE
, LOC_BLOCK
);
1707 b
= SYMBOL_BLOCK_VALUE (s
);
1711 complain (&pdr_for_nonsymbol_complaint
, sh_name
);
1715 /* FIXME -- delete. We can't do symbol allocation now; it's all done. */
1716 s
= new_symbol (sh_name
);
1717 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
1718 SYMBOL_CLASS (s
) = LOC_BLOCK
;
1719 /* Donno its type, hope int is ok */
1720 SYMBOL_TYPE (s
) = lookup_function_type (builtin_type_int
);
1721 add_symbol (s
, top_stack
->cur_block
);
1722 /* Wont have symbols for this one */
1724 SYMBOL_BLOCK_VALUE (s
) = b
;
1725 BLOCK_FUNCTION (b
) = s
;
1726 BLOCK_START (b
) = pr
->adr
;
1727 /* BOUND used to be the end of procedure's text, but the
1728 argument is no longer passed in. */
1729 BLOCK_END (b
) = bound
;
1730 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
1731 add_block (b
, top_stack
->cur_st
);
1735 i
= mylookup_symbol (MIPS_EFI_SYMBOL_NAME
, b
, LABEL_NAMESPACE
, LOC_CONST
);
1739 e
= (struct mips_extra_func_info
*) SYMBOL_VALUE (i
);
1741 e
->pdr
.isym
= (long) s
;
1742 e
->pdr
.adr
+= cur_fdr
->adr
- first_off
;
1744 /* Correct incorrect setjmp procedure descriptor from the library
1745 to make backtrace through setjmp work. */
1746 if (e
->pdr
.pcreg
== 0 && strcmp (sh_name
, "setjmp") == 0)
1748 complain (&bad_setjmp_pdr_complaint
, 0);
1749 e
->pdr
.pcreg
= RA_REGNUM
;
1750 e
->pdr
.regmask
= 0x80000000;
1751 e
->pdr
.regoffset
= -4;
1756 /* Parse the external symbol ES. Just call parse_symbol() after
1757 making sure we know where the aux are for it. For procedures,
1758 parsing of the PDRs has already provided all the needed
1759 information, we only parse them if SKIP_PROCEDURES is false,
1760 and only if this causes no symbol duplication.
1761 BIGEND says whether aux entries are big-endian or little-endian.
1763 This routine clobbers top_stack->cur_block and ->cur_st. */
1766 parse_external (es
, skip_procedures
, bigend
)
1768 int skip_procedures
;
1773 if (es
->ifd
!= ifdNil
)
1776 cur_fdr
= ecoff_data (cur_bfd
)->fdr
+ cur_fd
;
1777 ax
= ecoff_data (cur_bfd
)->external_aux
+ cur_fdr
->iauxBase
;
1781 cur_fdr
= ecoff_data (cur_bfd
)->fdr
;
1785 /* Reading .o files */
1786 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
)
1789 switch (es
->asym
.st
)
1809 /* FIXME: Turn this into a complaint? */
1811 printf_filtered ("Warning: %s `%s' is undefined (in %s)\n",
1813 ecoff_data (cur_bfd
)->ssext
+ es
->asym
.iss
,
1814 fdr_name (cur_fdr
));
1818 switch (es
->asym
.st
)
1821 /* If we have full symbols we do not need more */
1822 if (skip_procedures
)
1824 if (mylookup_symbol (ecoff_data (cur_bfd
)->ssext
+ es
->asym
.iss
,
1825 top_stack
->cur_block
,
1826 VAR_NAMESPACE
, LOC_BLOCK
))
1831 /* Note that the case of a symbol with indexNil must be handled
1832 anyways by parse_symbol(). */
1833 parse_symbol (&es
->asym
, ax
, (char *) NULL
, bigend
);
1834 /* Note that parse_symbol changed es->asym. */
1841 /* Parse the line number info for file descriptor FH into
1842 GDB's linetable LT. MIPS' encoding requires a little bit
1843 of magic to get things out. Note also that MIPS' line
1844 numbers can go back and forth, apparently we can live
1845 with that and do not need to reorder our linetables */
1848 parse_lines (fh
, pr
, lt
)
1851 struct linetable
*lt
;
1853 unsigned char *base
;
1855 int delta
, count
, lineno
= 0;
1856 unsigned long first_off
= pr
->adr
;
1858 if (fh
->cbLine
== 0)
1861 base
= ecoff_data (cur_bfd
)->line
+ fh
->cbLineOffset
;
1863 /* Scan by procedure descriptors */
1865 for (j
= 0; j
< fh
->cpd
; j
++, pr
++)
1870 /* No code for this one */
1871 if (pr
->iline
== ilineNil
||
1872 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1875 /* Aurgh! To know where to stop expanding we must look-ahead. */
1876 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1877 if (pr
[l
].iline
!= -1)
1879 if (l
== (fh
->cpd
- j
))
1884 /* When procedures are moved around the linenumbers are
1885 attributed to the next procedure up. */
1886 if (pr
->iline
>= halt
)
1889 base
= ecoff_data (cur_bfd
)->line
+ fh
->cbLineOffset
+ pr
->cbLineOffset
;
1890 adr
= fh
->adr
+ pr
->adr
- first_off
;
1891 l
= adr
>> 2; /* in words */
1892 halt
+= (adr
>> 2) - pr
->iline
;
1893 for (lineno
= pr
->lnLow
; l
< halt
;)
1895 count
= *base
& 0x0f;
1896 delta
= *base
++ >> 4;
1901 delta
= (base
[0] << 8) | base
[1];
1902 if (delta
>= 0x8000)
1906 lineno
+= delta
; /* first delta is 0 */
1907 k
= add_line (lt
, lineno
, l
, k
);
1913 /* Master parsing procedure for first-pass reading of file symbols
1914 into a partial_symtab. */
1917 parse_partial_symbols (objfile
, section_offsets
)
1918 struct objfile
*objfile
;
1919 struct section_offsets
*section_offsets
;
1921 const struct ecoff_backend_data
* const backend
= ecoff_backend (cur_bfd
);
1922 const bfd_size_type external_sym_size
= backend
->external_sym_size
;
1923 const bfd_size_type external_rfd_size
= backend
->external_rfd_size
;
1924 const bfd_size_type external_ext_size
= backend
->external_ext_size
;
1925 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
1926 = backend
->swap_ext_in
;
1927 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
1928 = backend
->swap_sym_in
;
1929 void (* const swap_rfd_in
) PARAMS ((bfd
*, PTR
, RFDT
*))
1930 = backend
->swap_rfd_in
;
1932 HDRR
*hdr
= &ecoff_data (cur_bfd
)->symbolic_header
;
1933 /* Running pointers */
1938 register EXTR
*ext_in
;
1941 struct partial_symtab
*pst
;
1943 int past_first_source_file
= 0;
1945 /* List of current psymtab's include files */
1946 char **psymtab_include_list
;
1947 int includes_allocated
;
1950 struct pst_map
*fdr_to_pst
;
1951 /* Index within current psymtab dependency list */
1952 struct partial_symtab
**dependency_list
;
1953 int dependencies_used
, dependencies_allocated
;
1954 struct cleanup
*old_chain
;
1956 enum language prev_language
;
1958 extern_tab
= (EXTR
*) obstack_alloc (&objfile
->psymbol_obstack
,
1959 sizeof (EXTR
) * hdr
->iextMax
);
1961 includes_allocated
= 30;
1963 psymtab_include_list
= (char **) alloca (includes_allocated
*
1965 next_symbol_text_func
= mips_next_symbol_text
;
1967 dependencies_allocated
= 30;
1968 dependencies_used
= 0;
1970 (struct partial_symtab
**) alloca (dependencies_allocated
*
1971 sizeof (struct partial_symtab
*));
1973 last_source_file
= NULL
;
1978 * Only parse the Local and External symbols, and the Relative FDR.
1979 * Fixup enough of the loader symtab to be able to use it.
1980 * Allocate space only for the file's portions we need to
1985 max_glevel
= MIN_GLEVEL
;
1987 /* Allocate the map FDR -> PST.
1988 Minor hack: -O3 images might claim some global data belongs
1989 to FDR -1. We`ll go along with that */
1990 fdr_to_pst
= (struct pst_map
*) xzalloc ((hdr
->ifdMax
+ 1) * sizeof *fdr_to_pst
);
1991 old_chain
= make_cleanup (free
, fdr_to_pst
);
1994 struct partial_symtab
*pst
= new_psymtab ("", objfile
);
1995 fdr_to_pst
[-1].pst
= pst
;
1999 /* Allocate the global pending list. */
2000 ECOFF_PENDING_LIST (objfile
) =
2001 ((struct mips_pending
**)
2002 obstack_alloc (&objfile
->psymbol_obstack
,
2003 hdr
->ifdMax
* sizeof (struct mips_pending
*)));
2004 memset ((PTR
) ECOFF_PENDING_LIST (objfile
), 0,
2005 hdr
->ifdMax
* sizeof (struct mips_pending
*));
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 FDR_IDX (pst
) = f_idx
;
2102 CUR_BFD (pst
) = cur_bfd
;
2104 /* The way to turn this into a symtab is to call... */
2105 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
2107 /* Set up language for the pst.
2108 The language from the FDR is used if it is unambigious (e.g. cfront
2109 with native cc and g++ will set the language to C).
2110 Otherwise we have to deduce the language from the filename.
2111 Native ecoff has every header file in a separate FDR, so
2112 deduce_language_from_filename will return language_unknown for
2113 a header file, which is not what we want.
2114 But the FDRs for the header files are after the FDR for the source
2115 file, so we can assign the language of the source file to the
2116 following header files. Then we save the language in the private
2117 pst data so that we can reuse it when building symtabs. */
2118 prev_language
= psymtab_language
;
2122 case langCplusplusV2
:
2123 psymtab_language
= language_cplus
;
2126 psymtab_language
= deduce_language_from_filename (fdr_name (fh
));
2129 if (psymtab_language
== language_unknown
)
2130 psymtab_language
= prev_language
;
2131 PST_PRIVATE (pst
)->pst_language
= psymtab_language
;
2133 pst
->texthigh
= pst
->textlow
;
2135 /* For stabs-in-ecoff files, the second symbol must be @stab.
2136 This symbol is emitted by mips-tfile to signal that the
2137 current object file uses encapsulated stabs instead of mips
2138 ecoff for local symbols. (It is the second symbol because
2139 the first symbol is the stFile used to signal the start of a
2141 processing_gcc_compilation
= 0;
2144 (*swap_sym_in
) (cur_bfd
,
2145 ((char *) ecoff_data (cur_bfd
)->external_sym
2146 + (fh
->isymBase
+ 1) * external_sym_size
),
2148 if (STREQ (ecoff_data (cur_bfd
)->ss
+ fh
->issBase
+ sh
.iss
,
2150 processing_gcc_compilation
= 2;
2153 if (processing_gcc_compilation
!= 0)
2155 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++)
2160 (*swap_sym_in
) (cur_bfd
,
2161 ((char *) ecoff_data (cur_bfd
)->external_sym
2162 + (fh
->isymBase
+ cur_sdx
) * external_sym_size
),
2164 type_code
= ECOFF_UNMARK_STAB (sh
.index
);
2165 if (!ECOFF_IS_STAB (&sh
))
2167 if (sh
.st
== stProc
|| sh
.st
== stStaticProc
)
2169 long procaddr
= sh
.value
;
2173 isym
= AUX_GET_ISYM (fh
->fBigendian
,
2174 (ecoff_data (cur_bfd
)->external_aux
2177 (*swap_sym_in
) (cur_bfd
,
2179 ecoff_data (cur_bfd
)->external_sym
)
2180 + ((fh
->isymBase
+ isym
- 1)
2181 * external_sym_size
)),
2185 long high
= procaddr
+ sh
.value
;
2186 if (high
> pst
->texthigh
)
2187 pst
->texthigh
= high
;
2192 #define SET_NAMESTRING() \
2193 namestring = ecoff_data (cur_bfd)->ss + fh->issBase + sh.iss
2194 #define CUR_SYMBOL_TYPE type_code
2195 #define CUR_SYMBOL_VALUE sh.value
2196 #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms)\
2198 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
2199 #define HANDLE_RBRAC(val) \
2200 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
2201 #include "partial-stab.h"
2206 for (cur_sdx
= 0; cur_sdx
< fh
->csym
;)
2209 enum address_class
class;
2211 (*swap_sym_in
) (cur_bfd
,
2212 ((char *) ecoff_data (cur_bfd
)->external_sym
2213 + ((fh
->isymBase
+ cur_sdx
)
2214 * external_sym_size
)),
2217 if (ECOFF_IS_STAB (&sh
))
2223 /* Non absolute static symbols go into the minimal table. */
2224 if (sh
.sc
== scUndefined
|| sh
.sc
== scNil
2225 || (sh
.index
== indexNil
2226 && (sh
.st
!= stStatic
|| sh
.sc
== scAbs
)))
2228 /* FIXME, premature? */
2233 name
= ecoff_data (cur_bfd
)->ss
+ fh
->issBase
+ sh
.iss
;
2241 case stStaticProc
: /* Function */
2242 /* I believe this is used only for file-local functions.
2243 The comment in symconst.h ("load time only static procs")
2244 isn't particularly clear on this point. */
2245 prim_record_minimal_symbol (name
, sh
.value
, mst_file_text
);
2248 case stProc
: /* Asm labels apparently */
2249 ADD_PSYMBOL_TO_LIST (name
, strlen (name
),
2250 VAR_NAMESPACE
, LOC_BLOCK
,
2251 objfile
->static_psymbols
, sh
.value
,
2252 psymtab_language
, objfile
);
2253 /* Skip over procedure to next one. */
2254 if (sh
.index
>= hdr
->iauxMax
)
2256 /* Should not happen, but does when cross-compiling
2257 with the MIPS compiler. FIXME -- pull later. */
2258 complain (&index_complaint
, name
);
2259 new_sdx
= cur_sdx
+ 1; /* Don't skip at all */
2262 new_sdx
= AUX_GET_ISYM (fh
->fBigendian
,
2263 (ecoff_data (cur_bfd
)->external_aux
2266 procaddr
= sh
.value
;
2268 if (new_sdx
<= cur_sdx
)
2270 /* This should not happen either... FIXME. */
2271 complain (&aux_index_complaint
, name
);
2272 new_sdx
= cur_sdx
+ 1; /* Don't skip backward */
2276 (*swap_sym_in
) (cur_bfd
,
2277 ((char *) ecoff_data (cur_bfd
)->external_sym
2278 + ((fh
->isymBase
+ cur_sdx
- 1)
2279 * external_sym_size
)),
2283 high
= procaddr
+ sh
.value
;
2284 if (high
> pst
->texthigh
)
2285 pst
->texthigh
= high
;
2288 case stStatic
: /* Variable */
2289 if (sh
.sc
== scData
|| sh
.sc
== scSData
|| sh
.sc
== scRData
)
2290 prim_record_minimal_symbol (name
, sh
.value
, mst_file_data
);
2292 prim_record_minimal_symbol (name
, sh
.value
, mst_file_bss
);
2296 case stTypedef
:/* Typedef */
2297 class = LOC_TYPEDEF
;
2300 case stConstant
: /* Constant decl */
2307 case stBlock
: /* { }, str, un, enum*/
2308 if (sh
.sc
== scInfo
|| sh
.sc
== scCommon
)
2310 ADD_PSYMBOL_TO_LIST (name
, strlen (name
),
2311 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2312 objfile
->static_psymbols
,
2314 psymtab_language
, objfile
);
2316 /* Skip over the block */
2318 if (new_sdx
<= cur_sdx
)
2320 /* This happens with the Ultrix kernel. */
2321 complain (&block_index_complaint
, name
);
2322 new_sdx
= cur_sdx
+ 1; /* Don't skip backward */
2327 case stFile
: /* File headers */
2328 case stLabel
: /* Labels */
2329 case stEnd
: /* Ends of files */
2332 case stLocal
: /* Local variables */
2333 /* Normally these are skipped because we skip over
2334 all blocks we see. However, these can occur
2335 as visible symbols in a .h file that contains code. */
2339 /* Both complaints are valid: one gives symbol name,
2340 the other the offending symbol type. */
2341 complain (&unknown_sym_complaint
, name
);
2342 complain (&unknown_st_complaint
, sh
.st
);
2346 /* Use this gdb symbol */
2347 ADD_PSYMBOL_TO_LIST (name
, strlen (name
),
2348 VAR_NAMESPACE
, class,
2349 objfile
->static_psymbols
, sh
.value
,
2350 psymtab_language
, objfile
);
2352 cur_sdx
++; /* Go to next file symbol */
2355 /* Now do enter the external symbols. */
2356 ext_ptr
= &extern_tab
[fdr_to_pst
[f_idx
].globals_offset
];
2357 cur_sdx
= fdr_to_pst
[f_idx
].n_globals
;
2358 PST_PRIVATE (save_pst
)->extern_count
= cur_sdx
;
2359 PST_PRIVATE (save_pst
)->extern_tab
= ext_ptr
;
2360 for (; --cur_sdx
>= 0; ext_ptr
++)
2362 enum address_class
class;
2366 if (ext_ptr
->ifd
!= f_idx
)
2368 psh
= &ext_ptr
->asym
;
2378 complain (&unknown_ext_complaint
,
2379 ecoff_data (cur_bfd
)->ssext
+ psh
->iss
);
2380 /* Fall through, pretend it's global. */
2385 name
= ecoff_data (cur_bfd
)->ssext
+ psh
->iss
;
2386 ADD_PSYMBOL_ADDR_TO_LIST (name
, strlen (name
),
2387 VAR_NAMESPACE
, class,
2388 objfile
->global_psymbols
, (CORE_ADDR
) psh
->value
,
2389 psymtab_language
, objfile
);
2393 /* Link pst to FDR. end_psymtab returns NULL if the psymtab was
2394 empty and put on the free list. */
2395 fdr_to_pst
[f_idx
].pst
= end_psymtab (save_pst
,
2396 psymtab_include_list
, includes_used
,
2397 -1, save_pst
->texthigh
,
2398 dependency_list
, dependencies_used
);
2399 if (objfile
->ei
.entry_point
>= save_pst
->textlow
&&
2400 objfile
->ei
.entry_point
< save_pst
->texthigh
)
2402 objfile
->ei
.entry_file_lowpc
= save_pst
->textlow
;
2403 objfile
->ei
.entry_file_highpc
= save_pst
->texthigh
;
2407 /* Now scan the FDRs for dependencies */
2408 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++)
2410 fh
= f_idx
+ ecoff_data (cur_bfd
)->fdr
;
2411 pst
= fdr_to_pst
[f_idx
].pst
;
2413 if (pst
== (struct partial_symtab
*)NULL
)
2416 /* This should catch stabs-in-ecoff. */
2420 /* Skip the first file indirect entry as it is a self dependency
2421 for source files or a reverse .h -> .c dependency for header files. */
2422 pst
->number_of_dependencies
= 0;
2424 ((struct partial_symtab
**)
2425 obstack_alloc (&objfile
->psymbol_obstack
,
2427 * sizeof (struct partial_symtab
*))));
2428 for (s_idx
= 1; s_idx
< fh
->crfd
; s_idx
++)
2432 (*swap_rfd_in
) (cur_bfd
,
2433 ((char *) ecoff_data (cur_bfd
)->external_rfd
2434 + (fh
->rfdBase
+ s_idx
) * external_rfd_size
),
2436 if (rh
< 0 || rh
>= hdr
->ifdMax
)
2438 complain (&bad_file_number_complaint
, rh
);
2442 /* Skip self dependencies of header files. */
2446 /* Do not add to dependeny list if psymtab was empty. */
2447 if (fdr_to_pst
[rh
].pst
== (struct partial_symtab
*)NULL
)
2449 pst
->dependencies
[pst
->number_of_dependencies
++] = fdr_to_pst
[rh
].pst
;
2452 do_cleanups (old_chain
);
2457 mips_next_symbol_text ()
2462 (*ecoff_backend (cur_bfd
)->swap_sym_in
)
2464 ((char *) ecoff_data (cur_bfd
)->external_sym
2465 + ((cur_fdr
->isymBase
+ cur_sdx
)
2466 * ecoff_backend (cur_bfd
)->external_sym_size
)),
2468 return ecoff_data (cur_bfd
)->ss
+ cur_fdr
->issBase
+ sh
.iss
;
2471 /* Ancillary function to psymtab_to_symtab(). Does all the work
2472 for turning the partial symtab PST into a symtab, recurring
2473 first on all dependent psymtabs. The argument FILENAME is
2474 only passed so we can see in debug stack traces what file
2477 This function has a split personality, based on whether the
2478 symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
2479 The flow of control and even the memory allocation differs. FIXME. */
2482 psymtab_to_symtab_1 (pst
, filename
)
2483 struct partial_symtab
*pst
;
2486 const bfd_size_type external_sym_size
2487 = ecoff_backend (cur_bfd
)->external_sym_size
;
2488 const bfd_size_type external_pdr_size
2489 = ecoff_backend (cur_bfd
)->external_pdr_size
;
2490 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
2491 = ecoff_backend (cur_bfd
)->swap_sym_in
;
2492 void (* const swap_sym_out
) PARAMS ((bfd
*, const SYMR
*, PTR
))
2493 = ecoff_backend (cur_bfd
)->swap_sym_out
;
2494 void (* const swap_pdr_in
) PARAMS ((bfd
*, PTR
, PDR
*))
2495 = ecoff_backend (cur_bfd
)->swap_pdr_in
;
2499 struct linetable
*lines
;
2505 /* Read in all partial symbtabs on which this one is dependent.
2506 NOTE that we do have circular dependencies, sigh. We solved
2507 that by setting pst->readin before this point. */
2509 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2510 if (!pst
->dependencies
[i
]->readin
)
2512 /* Inform about additional files to be read in. */
2515 fputs_filtered (" ", stdout
);
2517 fputs_filtered ("and ", stdout
);
2519 printf_filtered ("%s...",
2520 pst
->dependencies
[i
]->filename
);
2521 wrap_here (""); /* Flush output */
2524 /* We only pass the filename for debug purposes */
2525 psymtab_to_symtab_1 (pst
->dependencies
[i
],
2526 pst
->dependencies
[i
]->filename
);
2529 /* Do nothing if this is a dummy psymtab. */
2531 if (pst
->n_global_syms
== 0 && pst
->n_static_syms
== 0
2532 && pst
->textlow
== 0 && pst
->texthigh
== 0)
2535 /* Now read the symbols for this symtab */
2537 cur_bfd
= CUR_BFD (pst
);
2538 current_objfile
= pst
->objfile
;
2539 cur_fd
= FDR_IDX (pst
);
2540 fh
= (cur_fd
== -1) ? (FDR
*) NULL
: ecoff_data (cur_bfd
)->fdr
+ cur_fd
;
2543 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2544 processing_gcc_compilation
= 0;
2545 if (fh
!= (FDR
*) NULL
&& fh
->csym
>= 2)
2549 (*swap_sym_in
) (cur_bfd
,
2550 ((char *) ecoff_data (cur_bfd
)->external_sym
2551 + (fh
->isymBase
+ 1) * external_sym_size
),
2553 if (STREQ (ecoff_data (cur_bfd
)->ss
+ fh
->issBase
+ sh
.iss
,
2556 /* We indicate that this is a GCC compilation so that certain
2557 features will be enabled in stabsread/dbxread. */
2558 processing_gcc_compilation
= 2;
2562 if (processing_gcc_compilation
!= 0)
2567 unsigned long first_off
= 0;
2569 /* This symbol table contains stabs-in-ecoff entries. */
2571 /* Parse local symbols first */
2573 if (fh
->csym
<= 2) /* FIXME, this blows psymtab->symtab ptr */
2575 current_objfile
= NULL
;
2578 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++)
2584 (*swap_sym_in
) (cur_bfd
,
2585 ((char *) ecoff_data (cur_bfd
)->external_sym
2586 + (fh
->isymBase
+ cur_sdx
) * external_sym_size
),
2588 name
= ecoff_data (cur_bfd
)->ss
+ fh
->issBase
+ sh
.iss
;
2590 if (ECOFF_IS_STAB (&sh
))
2592 int type_code
= ECOFF_UNMARK_STAB (sh
.index
);
2593 process_one_symbol (type_code
, 0, valu
, name
,
2594 pst
->section_offsets
, pst
->objfile
);
2595 if (type_code
== N_FUN
)
2597 /* Make up special symbol to contain
2598 procedure specific info */
2599 struct mips_extra_func_info
*e
=
2600 ((struct mips_extra_func_info
*)
2601 obstack_alloc (¤t_objfile
->symbol_obstack
,
2602 sizeof (struct mips_extra_func_info
)));
2603 struct symbol
*s
= new_symbol (MIPS_EFI_SYMBOL_NAME
);
2604 SYMBOL_NAMESPACE (s
) = LABEL_NAMESPACE
;
2605 SYMBOL_CLASS (s
) = LOC_CONST
;
2606 SYMBOL_TYPE (s
) = builtin_type_void
;
2607 SYMBOL_VALUE (s
) = (int) e
;
2608 add_symbol_to_list (s
, &local_symbols
);
2611 else if (sh
.st
== stLabel
&& sh
.index
!= indexNil
)
2613 /* Handle encoded stab line number. */
2614 record_line (current_subfile
, sh
.index
, valu
);
2616 else if (sh
.st
== stProc
|| sh
.st
== stStaticProc
|| sh
.st
== stEnd
)
2617 /* These are generated by gcc-2.x, do not complain */
2620 complain (&stab_unknown_complaint
, name
);
2622 st
= end_symtab (pst
->texthigh
, 0, 0, pst
->objfile
, SECT_OFF_TEXT
);
2625 /* Sort the symbol table now, we are done adding symbols to it.
2626 We must do this before parse_procedure calls lookup_symbol. */
2627 sort_symtab_syms (st
);
2629 /* This may not be necessary for stabs symtabs. FIXME. */
2632 /* Fill in procedure info next. */
2634 pdr_ptr
= ((char *) ecoff_data (cur_bfd
)->external_pdr
2635 + fh
->ipdFirst
* external_pdr_size
);
2636 pdr_end
= pdr_ptr
+ fh
->cpd
* external_pdr_size
;
2637 for (; pdr_ptr
< pdr_end
; pdr_ptr
+= external_pdr_size
)
2641 (*swap_pdr_in
) (cur_bfd
, pdr_ptr
, &pr
);
2647 parse_procedure (&pr
, st
, first_off
);
2652 /* This symbol table contains ordinary ecoff entries. */
2654 /* FIXME: doesn't use pst->section_offsets. */
2660 /* How many symbols will we need */
2661 /* FIXME, this does not count enum values. */
2662 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
2666 st
= new_symtab ("unknown", f_max
, 0, pst
->objfile
);
2670 f_max
+= fh
->csym
+ fh
->cpd
;
2671 maxlines
= 2 * fh
->cline
;
2672 st
= new_symtab (pst
->filename
, 2 * f_max
, maxlines
, pst
->objfile
);
2674 /* The proper language was already determined when building
2675 the psymtab, use it. */
2676 st
->language
= PST_PRIVATE (pst
)->pst_language
;
2679 psymtab_language
= st
->language
;
2681 lines
= LINETABLE (st
);
2683 /* Get a new lexical context */
2685 push_parse_stack ();
2686 top_stack
->cur_st
= st
;
2687 top_stack
->cur_block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (st
),
2689 BLOCK_START (top_stack
->cur_block
) = fh
? fh
->adr
: 0;
2690 BLOCK_END (top_stack
->cur_block
) = 0;
2691 top_stack
->blocktype
= stFile
;
2692 top_stack
->maxsyms
= 2 * f_max
;
2693 top_stack
->cur_type
= 0;
2694 top_stack
->procadr
= 0;
2695 top_stack
->numargs
= 0;
2702 /* Parse local symbols first */
2703 sym_ptr
= ((char *) ecoff_data (cur_bfd
)->external_sym
2704 + fh
->isymBase
* external_sym_size
);
2705 sym_end
= sym_ptr
+ fh
->csym
* external_sym_size
;
2706 while (sym_ptr
< sym_end
)
2711 (*swap_sym_in
) (cur_bfd
, sym_ptr
, &sh
);
2712 c
= parse_symbol (&sh
,
2713 (ecoff_data (cur_bfd
)->external_aux
2715 sym_ptr
, fh
->fBigendian
);
2716 /* FIXME: We must swap the modified symbol back out,
2717 although we would rather not. See parse_symbol. */
2718 (*swap_sym_out
) (cur_bfd
, &sh
, sym_ptr
);
2719 sym_ptr
+= c
* external_sym_size
;
2722 /* Linenumbers. At the end, check if we can save memory.
2723 parse_lines has to look ahead an arbitrary number of PDR
2724 structures, so we swap them all first. */
2728 struct cleanup
*old_chain
;
2734 pr_block
= (PDR
*) xmalloc (fh
->cpd
* sizeof (PDR
));
2736 old_chain
= make_cleanup (free
, pr_block
);
2738 pdr_ptr
= ((char *) ecoff_data (cur_bfd
)->external_pdr
2739 + fh
->ipdFirst
* external_pdr_size
);
2740 pdr_end
= pdr_ptr
+ fh
->cpd
* external_pdr_size
;
2744 pdr_ptr
+= external_pdr_size
, pdr_in
++)
2745 (*swap_pdr_in
) (cur_bfd
, pdr_ptr
, pdr_in
);
2747 parse_lines (fh
, pr_block
, lines
);
2748 if (lines
->nitems
< fh
->cline
)
2749 lines
= shrink_linetable (lines
);
2751 /* Fill in procedure info next. */
2753 pdr_in_end
= pdr_in
+ fh
->cpd
;
2754 for (; pdr_in
< pdr_in_end
; pdr_in
++)
2755 parse_procedure (pdr_in
, 0, pr_block
->adr
);
2757 do_cleanups (old_chain
);
2761 LINETABLE (st
) = lines
;
2763 /* .. and our share of externals.
2764 XXX use the global list to speed up things here. how?
2765 FIXME, Maybe quit once we have found the right number of ext's? */
2766 top_stack
->cur_st
= st
;
2767 top_stack
->cur_block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack
->cur_st
),
2769 top_stack
->blocktype
= stFile
;
2770 top_stack
->maxsyms
= (ecoff_data (cur_bfd
)->symbolic_header
.isymMax
2771 + ecoff_data (cur_bfd
)->symbolic_header
.ipdMax
2772 + ecoff_data (cur_bfd
)->symbolic_header
.iextMax
);
2774 ext_ptr
= PST_PRIVATE (pst
)->extern_tab
;
2775 for (i
= PST_PRIVATE (pst
)->extern_count
; --i
>= 0; ext_ptr
++)
2776 parse_external (ext_ptr
, 1, fh
->fBigendian
);
2778 /* If there are undefined, tell the user */
2779 if (n_undef_symbols
)
2781 printf_filtered ("File %s contains %d unresolved references:",
2782 st
->filename
, n_undef_symbols
);
2783 printf_filtered ("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2784 n_undef_vars
, n_undef_procs
, n_undef_labels
);
2785 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
2790 /* Sort the symbol table now, we are done adding symbols to it.*/
2791 sort_symtab_syms (st
);
2796 /* Now link the psymtab and the symtab. */
2799 current_objfile
= NULL
;
2802 /* Ancillary parsing procedures. */
2804 /* Lookup the type at relative index RN. Return it in TPP
2805 if found and in any event come up with its name PNAME.
2806 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
2807 Return value says how many aux symbols we ate. */
2810 cross_ref (ax
, tpp
, type_code
, pname
, bigend
, sym_name
)
2813 enum type_code type_code
; /* Use to alloc new type if none is found. */
2822 ecoff_swap_rndx_in (bigend
, &ax
->a_rndx
, rn
);
2824 /* Escape index means 'the next one' */
2825 if (rn
->rfd
== 0xfff)
2828 rf
= AUX_GET_ISYM (bigend
, ax
+ 1);
2838 *pname
= "<undefined>";
2843 * Find the relative file descriptor and the symbol in it
2845 FDR
*fh
= get_rfd (cur_fd
, rf
);
2850 if (rn
->index
>= fh
->csym
)
2852 /* File indirect entry is corrupt. */
2853 *tpp
= (struct type
*)NULL
;
2854 *pname
= "<illegal>";
2855 complain (&bad_rfd_entry_complaint
,
2856 sym_name
, fh
- ecoff_data (cur_bfd
)->fdr
, rn
->index
);
2860 /* If we have processed this symbol then we left a forwarding
2861 pointer to the corresponding GDB symbol. If not, we`ll put
2862 it in a list of pending symbols, to be processed later when
2863 the file will be. In any event, we collect the name for the
2864 type here. Which is why we made a first pass at strings. */
2866 esh
= ((char *) ecoff_data (cur_bfd
)->external_sym
2867 + ((fh
->isymBase
+ rn
->index
)
2868 * ecoff_backend (cur_bfd
)->external_sym_size
));
2869 (*ecoff_backend (cur_bfd
)->swap_sym_in
) (cur_bfd
, esh
, &sh
);
2871 /* Careful, we might be looking at .o files */
2873 *pname
= "<undefined>";
2874 else if (rn
->rfd
== 0xfff && rn
->index
== 0)
2875 /* For structs, unions and enums, rn->rfd is 0xfff and the index
2876 is a relative symbol number for the type, but an index of 0
2877 seems to mean that we don't know. This is said to fix a problem
2878 with "info func opendir" on an SGI showing
2879 "struct BSDopendir.c *BSDopendir();". */
2881 *tpp
= (struct type
*)NULL
;
2882 *pname
= "<unknown>";
2885 else if ((sh
.st
!= stBlock
&& sh
.st
!= stTypedef
&& sh
.st
!= stParsed
)
2888 /* File indirect entry is corrupt. */
2889 *tpp
= (struct type
*)NULL
;
2890 *pname
= "<illegal>";
2891 complain (&bad_rfd_entry_complaint
,
2892 sym_name
, fh
- ecoff_data (cur_bfd
)->fdr
, rn
->index
);
2896 *pname
= ecoff_data (cur_bfd
)->ss
+ fh
->issBase
+ sh
.iss
;
2898 /* Have we parsed it ? */
2899 if (sh
.value
!= 0 && sh
.st
== stParsed
)
2901 t
= (struct type
*) sh
.value
;
2906 /* Avoid duplicates */
2907 struct mips_pending
*p
= is_pending_symbol (fh
, esh
);
2912 *tpp
= init_type (type_code
, 0, 0, (char *) NULL
,
2913 (struct objfile
*) NULL
);
2914 add_pending (fh
, esh
, *tpp
);
2919 /* We used one auxent normally, two if we got a "next one" rf. */
2924 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2925 keeping the symtab sorted */
2927 static struct symbol
*
2928 mylookup_symbol (name
, block
, namespace, class)
2930 register struct block
*block
;
2931 enum namespace namespace;
2932 enum address_class
class;
2934 register int bot
, top
, inc
;
2935 register struct symbol
*sym
;
2938 top
= BLOCK_NSYMS (block
);
2942 sym
= BLOCK_SYM (block
, bot
);
2943 if (SYMBOL_NAME (sym
)[0] == inc
2944 && SYMBOL_NAMESPACE (sym
) == namespace
2945 && SYMBOL_CLASS (sym
) == class
2946 && strcmp (SYMBOL_NAME (sym
), name
) == 0)
2950 block
= BLOCK_SUPERBLOCK (block
);
2952 return mylookup_symbol (name
, block
, namespace, class);
2957 /* Add a new symbol S to a block B.
2958 Infrequently, we will need to reallocate the block to make it bigger.
2959 We only detect this case when adding to top_stack->cur_block, since
2960 that's the only time we know how big the block is. FIXME. */
2967 int nsyms
= BLOCK_NSYMS (b
)++;
2968 struct block
*origb
;
2969 struct parse_stack
*stackp
;
2971 if (b
== top_stack
->cur_block
&&
2972 nsyms
>= top_stack
->maxsyms
)
2974 complain (&block_overflow_complaint
, SYMBOL_NAME (s
));
2975 /* In this case shrink_block is actually grow_block, since
2976 BLOCK_NSYMS(b) is larger than its current size. */
2978 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
2980 /* Now run through the stack replacing pointers to the
2981 original block. shrink_block has already done this
2982 for the blockvector and BLOCK_FUNCTION. */
2983 for (stackp
= top_stack
; stackp
; stackp
= stackp
->next
)
2985 if (stackp
->cur_block
== origb
)
2987 stackp
->cur_block
= b
;
2988 stackp
->maxsyms
= BLOCK_NSYMS (b
);
2992 BLOCK_SYM (b
, nsyms
) = s
;
2995 /* Add a new block B to a symtab S */
3002 struct blockvector
*bv
= BLOCKVECTOR (s
);
3004 bv
= (struct blockvector
*) xrealloc ((PTR
) bv
,
3005 (sizeof (struct blockvector
)
3006 + BLOCKVECTOR_NBLOCKS (bv
)
3007 * sizeof (bv
->block
)));
3008 if (bv
!= BLOCKVECTOR (s
))
3009 BLOCKVECTOR (s
) = bv
;
3011 BLOCKVECTOR_BLOCK (bv
, BLOCKVECTOR_NBLOCKS (bv
)++) = b
;
3014 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
3015 MIPS' linenumber encoding might need more than one byte
3016 to describe it, LAST is used to detect these continuation lines.
3018 Combining lines with the same line number seems like a bad idea.
3019 E.g: There could be a line number entry with the same line number after the
3020 prologue and GDB should not ignore it (this is a better way to find
3021 a prologue than mips_skip_prologue).
3022 But due to the compressed line table format there are line number entries
3023 for the same line which are needed to bridge the gap to the next
3024 line number entry. These entries have a bogus address info with them
3025 and we are unable to tell them from intended duplicate line number
3027 This is another reason why -ggdb debugging format is preferable. */
3030 add_line (lt
, lineno
, adr
, last
)
3031 struct linetable
*lt
;
3037 last
= -2; /* make sure we record first line */
3039 if (last
== lineno
) /* skip continuation lines */
3042 lt
->item
[lt
->nitems
].line
= lineno
;
3043 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
3047 /* Sorting and reordering procedures */
3049 /* Blocks with a smaller low bound should come first */
3052 compare_blocks (arg1
, arg2
)
3053 const void *arg1
, *arg2
;
3055 register int addr_diff
;
3056 struct block
**b1
= (struct block
**) arg1
;
3057 struct block
**b2
= (struct block
**) arg2
;
3059 addr_diff
= (BLOCK_START ((*b1
))) - (BLOCK_START ((*b2
)));
3061 return (BLOCK_END ((*b2
))) - (BLOCK_END ((*b1
)));
3065 /* Sort the blocks of a symtab S.
3066 Reorder the blocks in the blockvector by code-address,
3067 as required by some MI search routines */
3073 struct blockvector
*bv
= BLOCKVECTOR (s
);
3075 if (BLOCKVECTOR_NBLOCKS (bv
) <= 2)
3078 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) == 0)
3079 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) = 0;
3080 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) == 0)
3081 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) = 0;
3085 * This is very unfortunate: normally all functions are compiled in
3086 * the order they are found, but if the file is compiled -O3 things
3087 * are very different. It would be nice to find a reliable test
3088 * to detect -O3 images in advance.
3090 if (BLOCKVECTOR_NBLOCKS (bv
) > 3)
3091 qsort (&BLOCKVECTOR_BLOCK (bv
, FIRST_LOCAL_BLOCK
),
3092 BLOCKVECTOR_NBLOCKS (bv
) - FIRST_LOCAL_BLOCK
,
3093 sizeof (struct block
*),
3097 register CORE_ADDR high
= 0;
3098 register int i
, j
= BLOCKVECTOR_NBLOCKS (bv
);
3100 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
3101 if (high
< BLOCK_END (BLOCKVECTOR_BLOCK (bv
, i
)))
3102 high
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, i
));
3103 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) = high
;
3106 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) =
3107 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, FIRST_LOCAL_BLOCK
));
3109 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) =
3110 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
3111 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) =
3112 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
3116 /* Constructor/restructor/destructor procedures */
3118 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
3119 MAXSYMS and linenumbers MAXLINES we'll put in it */
3121 static struct symtab
*
3122 new_symtab (name
, maxsyms
, maxlines
, objfile
)
3126 struct objfile
*objfile
;
3128 struct symtab
*s
= allocate_symtab (name
, objfile
);
3130 LINETABLE (s
) = new_linetable (maxlines
);
3132 /* All symtabs must have at least two blocks */
3133 BLOCKVECTOR (s
) = new_bvect (2);
3134 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
) = new_block (maxsyms
);
3135 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
) = new_block (maxsyms
);
3136 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)) =
3137 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3139 s
->free_code
= free_linetable
;
3144 /* Allocate a new partial_symtab NAME */
3146 static struct partial_symtab
*
3147 new_psymtab (name
, objfile
)
3149 struct objfile
*objfile
;
3151 struct partial_symtab
*psymtab
;
3153 psymtab
= allocate_psymtab (name
, objfile
);
3155 /* Keep a backpointer to the file's symbols */
3157 psymtab
->read_symtab_private
= ((char *)
3158 obstack_alloc (&objfile
->psymbol_obstack
,
3159 sizeof (struct symloc
)));
3160 memset ((PTR
) psymtab
->read_symtab_private
, 0, sizeof (struct symloc
));
3161 CUR_BFD (psymtab
) = cur_bfd
;
3163 /* The way to turn this into a symtab is to call... */
3164 psymtab
->read_symtab
= mipscoff_psymtab_to_symtab
;
3169 /* Allocate a linetable array of the given SIZE. Since the struct
3170 already includes one item, we subtract one when calculating the
3171 proper size to allocate. */
3173 static struct linetable
*
3174 new_linetable (size
)
3177 struct linetable
*l
;
3179 size
= (size
- 1) * sizeof (l
->item
) + sizeof (struct linetable
);
3180 l
= (struct linetable
*) xmalloc (size
);
3185 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
3186 I am not so sure about the 3.4 ones.
3188 Since the struct linetable already includes one item, we subtract one when
3189 calculating the proper size to allocate. */
3191 static struct linetable
*
3192 shrink_linetable (lt
)
3193 struct linetable
*lt
;
3196 return (struct linetable
*) xrealloc ((PTR
) lt
,
3197 (sizeof (struct linetable
)
3199 * sizeof (lt
->item
))));
3202 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
3204 static struct blockvector
*
3208 struct blockvector
*bv
;
3211 size
= sizeof (struct blockvector
) + nblocks
* sizeof (struct block
*);
3212 bv
= (struct blockvector
*) xzalloc (size
);
3214 BLOCKVECTOR_NBLOCKS (bv
) = nblocks
;
3219 /* Allocate and zero a new block of MAXSYMS symbols */
3221 static struct block
*
3225 int size
= sizeof (struct block
) + (maxsyms
- 1) * sizeof (struct symbol
*);
3227 return (struct block
*) xzalloc (size
);
3230 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
3231 Shrink_block can also be used by add_symbol to grow a block. */
3233 static struct block
*
3239 struct blockvector
*bv
= BLOCKVECTOR (s
);
3242 /* Just reallocate it and fix references to the old one */
3244 new = (struct block
*) xrealloc ((PTR
) b
,
3245 (sizeof (struct block
)
3246 + ((BLOCK_NSYMS (b
) - 1)
3247 * sizeof (struct symbol
*))));
3249 /* Should chase pointers to old one. Fortunately, that`s just
3250 the block`s function and inferior blocks */
3251 if (BLOCK_FUNCTION (new) && SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) == b
)
3252 SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) = new;
3253 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS (bv
); i
++)
3254 if (BLOCKVECTOR_BLOCK (bv
, i
) == b
)
3255 BLOCKVECTOR_BLOCK (bv
, i
) = new;
3256 else if (BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv
, i
)) == b
)
3257 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv
, i
)) = new;
3261 /* Create a new symbol with printname NAME */
3263 static struct symbol
*
3267 struct symbol
*s
= ((struct symbol
*)
3268 obstack_alloc (¤t_objfile
->symbol_obstack
,
3269 sizeof (struct symbol
)));
3271 memset ((PTR
) s
, 0, sizeof (*s
));
3272 SYMBOL_NAME (s
) = name
;
3273 SYMBOL_LANGUAGE (s
) = psymtab_language
;
3274 SYMBOL_INIT_DEMANGLED_NAME (s
, ¤t_objfile
->symbol_obstack
);
3278 /* Create a new type with printname NAME */
3280 static struct type
*
3286 t
= alloc_type (current_objfile
);
3287 TYPE_NAME (t
) = name
;
3288 TYPE_CPLUS_SPECIFIC (t
) = (struct cplus_struct_type
*) &cplus_struct_default
;
3293 /* Things used for calling functions in the inferior.
3294 These functions are exported to our companion
3295 mips-tdep.c file and are here because they play
3296 with the symbol-table explicitly. */
3298 /* Sigtramp: make sure we have all the necessary information
3299 about the signal trampoline code. Since the official code
3300 from MIPS does not do so, we make up that information ourselves.
3301 If they fix the library (unlikely) this code will neutralize itself. */
3308 struct block
*b
, *b0
= NULL
;
3310 sigtramp_address
= -1;
3312 /* We have to handle the following cases here:
3313 a) The Mips library has a sigtramp label within sigvec.
3314 b) Irix has a _sigtramp which we want to use, but it also has sigvec. */
3315 s
= lookup_symbol ("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
3318 b0
= SYMBOL_BLOCK_VALUE (s
);
3319 s
= lookup_symbol ("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
3323 /* No sigvec or no sigtramp inside sigvec, try _sigtramp. */
3324 s
= lookup_symbol ("_sigtramp", 0, VAR_NAMESPACE
, 0, NULL
);
3327 /* But maybe this program uses its own version of sigvec */
3331 /* Did we or MIPSco fix the library ? */
3332 if (SYMBOL_CLASS (s
) == LOC_BLOCK
)
3334 sigtramp_address
= BLOCK_START (SYMBOL_BLOCK_VALUE (s
));
3335 sigtramp_end
= BLOCK_END (SYMBOL_BLOCK_VALUE (s
));
3339 sigtramp_address
= SYMBOL_VALUE (s
);
3340 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
3342 /* But what symtab does it live in ? */
3343 st
= find_pc_symtab (SYMBOL_VALUE (s
));
3346 * Ok, there goes the fix: turn it into a procedure, with all the
3347 * needed info. Note we make it a nested procedure of sigvec,
3348 * which is the way the (assembly) code is actually written.
3350 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
3351 SYMBOL_CLASS (s
) = LOC_BLOCK
;
3352 SYMBOL_TYPE (s
) = init_type (TYPE_CODE_FUNC
, 4, 0, (char *) NULL
,
3353 (struct objfile
*) NULL
);
3354 TYPE_TARGET_TYPE (SYMBOL_TYPE (s
)) = builtin_type_void
;
3356 /* Need a block to allocate MIPS_EFI_SYMBOL_NAME in */
3358 SYMBOL_BLOCK_VALUE (s
) = b
;
3359 BLOCK_START (b
) = sigtramp_address
;
3360 BLOCK_END (b
) = sigtramp_end
;
3361 BLOCK_FUNCTION (b
) = s
;
3362 BLOCK_SUPERBLOCK (b
) = BLOCK_SUPERBLOCK (b0
);
3366 /* Make a MIPS_EFI_SYMBOL_NAME entry for it */
3368 struct mips_extra_func_info
*e
=
3369 ((struct mips_extra_func_info
*)
3370 xzalloc (sizeof (struct mips_extra_func_info
)));
3372 e
->numargs
= 0; /* the kernel thinks otherwise */
3373 /* align_longword(sigcontext + SIGFRAME) */
3374 e
->pdr
.frameoffset
= 0x150;
3375 e
->pdr
.framereg
= SP_REGNUM
;
3376 /* read_next_frame_reg provides the true pc at the time of signal */
3377 e
->pdr
.pcreg
= PC_REGNUM
;
3378 e
->pdr
.regmask
= -2;
3379 e
->pdr
.regoffset
= -(41 * sizeof (int));
3380 e
->pdr
.fregmask
= -1;
3381 e
->pdr
.fregoffset
= -(7 * sizeof (int));
3382 e
->pdr
.isym
= (long) s
;
3383 e
->pdr
.adr
= sigtramp_address
;
3385 current_objfile
= st
->objfile
; /* Keep new_symbol happy */
3386 s
= new_symbol (MIPS_EFI_SYMBOL_NAME
);
3387 SYMBOL_VALUE (s
) = (int) e
;
3388 SYMBOL_NAMESPACE (s
) = LABEL_NAMESPACE
;
3389 SYMBOL_CLASS (s
) = LOC_CONST
;
3390 SYMBOL_TYPE (s
) = builtin_type_void
;
3391 current_objfile
= NULL
;
3394 BLOCK_SYM (b
, BLOCK_NSYMS (b
)++) = s
;
3398 /* Fake up identical offsets for all sections. */
3400 struct section_offsets
*
3401 mipscoff_symfile_offsets (objfile
, addr
)
3402 struct objfile
*objfile
;
3405 struct section_offsets
*section_offsets
;
3408 section_offsets
= ((struct section_offsets
*)
3409 obstack_alloc (&objfile
->psymbol_obstack
,
3410 (sizeof (struct section_offsets
)
3411 + (sizeof (section_offsets
->offsets
)
3412 * (SECT_OFF_MAX
- 1)))));
3414 for (i
= 0; i
< SECT_OFF_MAX
; i
++)
3415 ANOFFSET (section_offsets
, i
) = addr
;
3417 return section_offsets
;
3420 /* Initialization */
3422 static struct sym_fns ecoff_sym_fns
=
3424 "ecoff", /* sym_name: name or name prefix of BFD target type */
3425 5, /* sym_namelen: number of significant sym_name chars */
3426 mipscoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
3427 mipscoff_symfile_init
, /* sym_init: read initial info, setup for sym_read() */
3428 mipscoff_symfile_read
, /* sym_read: read a symbol file into symtab */
3429 mipscoff_symfile_finish
, /* sym_finish: finished with file, cleanup */
3430 mipscoff_symfile_offsets
, /* sym_offsets: dummy FIXME til implem sym reloc */
3431 NULL
/* next: pointer to next struct sym_fns */
3436 _initialize_mipsread ()
3438 add_symtab_fns (&ecoff_sym_fns
);
3440 /* Missing basic types */
3442 builtin_type_string
=
3443 init_type (TYPE_CODE_STRING
,
3444 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3446 (struct objfile
*) NULL
);
3447 builtin_type_complex
=
3448 init_type (TYPE_CODE_FLT
,
3449 TARGET_COMPLEX_BIT
/ TARGET_CHAR_BIT
,
3451 (struct objfile
*) NULL
);
3452 builtin_type_double_complex
=
3453 init_type (TYPE_CODE_FLT
,
3454 TARGET_DOUBLE_COMPLEX_BIT
/ TARGET_CHAR_BIT
,
3455 0, "double complex",
3456 (struct objfile
*) NULL
);
3457 builtin_type_fixed_dec
=
3458 init_type (TYPE_CODE_INT
,
3459 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3461 (struct objfile
*) NULL
);
3462 builtin_type_float_dec
=
3463 init_type (TYPE_CODE_FLT
,
3464 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3465 0, "floating decimal",
3466 (struct objfile
*) NULL
);