1 /* Read a symbol table in ECOFF format (Third-Eye).
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993 Free Software
4 Original version contributed by Alessandro Forin (af@cs.cmu.edu) at
5 CMU. Major work by Per Bothner, John Gilmore and Ian Lance Taylor
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 /* This module provides the function mdebug_build_psymtabs. It reads
25 ECOFF debugging information into partial symbol tables. The
26 debugging information is read from two structures. A struct
27 ecoff_debug_swap includes the sizes of each ECOFF structure and
28 swapping routines; these are fixed for a particular target. A
29 struct ecoff_debug_info points to the debugging information for a
30 particular object file.
32 ECOFF symbol tables are mostly written in the byte order of the
33 target machine. However, one section of the table (the auxiliary
34 symbol information) is written in the host byte order. There is a
35 bit in the other symbol info which describes which host byte order
36 was used. ECOFF thereby takes the trophy from Intel `b.out' for
37 the most brain-dead adaptation of a file format to byte order.
39 This module can read all four of the known byte-order combinations,
40 on any type of host. */
50 #include "stabsread.h"
51 #include "complaints.h"
53 #if !defined (SEEK_SET)
58 /* These are needed if the tm.h file does not contain the necessary
59 mips specific definitions. */
61 #ifndef MIPS_EFI_SYMBOL_NAME
62 #define MIPS_EFI_SYMBOL_NAME "__GDB_EFI_INFO__"
64 #include "coff/symconst.h"
65 typedef struct mips_extra_func_info
{
68 } *mips_extra_func_info_t
;
75 #include <sys/types.h>
78 #include <sys/param.h>
83 #include "gdb-stabs.h"
87 #include "coff/ecoff.h" /* COFF-like aspects of ecoff files */
89 #include "libaout.h" /* Private BFD a.out information. */
90 #include "aout/aout64.h"
91 #include "aout/stab_gnu.h" /* STABS information */
93 #include "expression.h"
94 #include "language.h" /* Needed inside partial-stab.h */
96 /* Provide a default mapping from a ecoff register number to a gdb REGNUM. */
97 #ifndef ECOFF_REG_TO_REGNUM
98 #define ECOFF_REG_TO_REGNUM(num) (num)
101 /* Each partial symbol table entry contains a pointer to private data
102 for the read_symtab() function to use when expanding a partial
103 symbol table entry to a full symbol table entry.
105 For mdebugread this structure contains the index of the FDR that this
106 psymtab represents and a pointer to the BFD that the psymtab was
109 #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
110 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
111 #define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd)
112 #define DEBUG_SWAP(p) (PST_PRIVATE(p)->debug_swap)
113 #define DEBUG_INFO(p) (PST_PRIVATE(p)->debug_info)
114 #define PENDING_LIST(p) (PST_PRIVATE(p)->pending_list)
120 const struct ecoff_debug_swap
*debug_swap
;
121 struct ecoff_debug_info
*debug_info
;
122 struct mdebug_pending
**pending_list
;
123 EXTR
*extern_tab
; /* Pointer to external symbols for this file. */
124 int extern_count
; /* Size of extern_tab. */
125 enum language pst_language
;
128 /* Things we import explicitly from other modules */
130 extern int info_verbose
;
132 /* Various complaints about symbol reading that don't abort the process */
134 static struct complaint bad_file_number_complaint
=
135 {"bad file number %d", 0, 0};
137 static struct complaint index_complaint
=
138 {"bad aux index at symbol %s", 0, 0};
140 static struct complaint aux_index_complaint
=
141 {"bad proc end in aux found from symbol %s", 0, 0};
143 static struct complaint block_index_complaint
=
144 {"bad aux index at block symbol %s", 0, 0};
146 static struct complaint unknown_ext_complaint
=
147 {"unknown external symbol %s", 0, 0};
149 static struct complaint unknown_sym_complaint
=
150 {"unknown local symbol %s", 0, 0};
152 static struct complaint unknown_st_complaint
=
153 {"with type %d", 0, 0};
155 static struct complaint block_overflow_complaint
=
156 {"block containing %s overfilled", 0, 0};
158 static struct complaint basic_type_complaint
=
159 {"cannot map ECOFF basic type 0x%x for %s", 0, 0};
161 static struct complaint unknown_type_qual_complaint
=
162 {"unknown type qualifier 0x%x", 0, 0};
164 static struct complaint array_index_type_complaint
=
165 {"illegal array index type for %s, assuming int", 0, 0};
167 static struct complaint bad_tag_guess_complaint
=
168 {"guessed tag type of %s incorrectly", 0, 0};
170 static struct complaint block_member_complaint
=
171 {"declaration block contains unhandled symbol type %d", 0, 0};
173 static struct complaint stEnd_complaint
=
174 {"stEnd with storage class %d not handled", 0, 0};
176 static struct complaint unknown_mdebug_symtype_complaint
=
177 {"unknown symbol type 0x%x", 0, 0};
179 static struct complaint stab_unknown_complaint
=
180 {"unknown stabs symbol %s", 0, 0};
182 static struct complaint pdr_for_nonsymbol_complaint
=
183 {"PDR for %s, but no symbol", 0, 0};
185 static struct complaint pdr_static_symbol_complaint
=
186 {"can't handle PDR for static proc at 0x%lx", 0, 0};
188 static struct complaint bad_setjmp_pdr_complaint
=
189 {"fixing bad setjmp PDR from libc", 0, 0};
191 static struct complaint bad_fbitfield_complaint
=
192 {"can't handle TIR fBitfield for %s", 0, 0};
194 static struct complaint bad_continued_complaint
=
195 {"illegal TIR continued for %s", 0, 0};
197 static struct complaint bad_rfd_entry_complaint
=
198 {"bad rfd entry for %s: file %d, index %d", 0, 0};
200 static struct complaint unexpected_type_code_complaint
=
201 {"unexpected type code for %s", 0, 0};
203 static struct complaint unable_to_cross_ref_complaint
=
204 {"unable to cross ref btTypedef for %s", 0, 0};
206 static struct complaint illegal_forward_tq0_complaint
=
207 {"illegal tq0 in forward typedef for %s", 0, 0};
209 static struct complaint illegal_forward_bt_complaint
=
210 {"illegal bt %d in forward typedef for %s", 0, 0};
212 static struct complaint bad_linetable_guess_complaint
=
213 {"guessed size of linetable for %s incorrectly", 0, 0};
215 static struct complaint bad_ext_ifd_complaint
=
216 {"bad ifd for external symbol: %d (max %d)", 0, 0};
218 static struct complaint bad_ext_iss_complaint
=
219 {"bad iss for external symbol: %ld (max %ld)", 0, 0};
221 /* Macros and extra defs */
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 /* How to parse debugging information for CUR_BFD. */
242 static const struct ecoff_debug_swap
*debug_swap
;
244 /* Pointers to debugging information for CUR_BFD. */
246 static struct ecoff_debug_info
*debug_info
;
248 /* Pointer to current file decriptor record, and its index */
253 /* Index of current symbol */
257 /* Note how much "debuggable" this image is. We would like
258 to see at least one FDR with full symbols */
263 /* When examining .o files, report on undefined symbols */
265 static int n_undef_symbols
, n_undef_labels
, n_undef_vars
, n_undef_procs
;
267 /* Pseudo symbol to use when putting stabs into the symbol table. */
269 static char stabs_symbol
[] = STABS_SYMBOL
;
271 /* Extra builtin types */
273 struct type
*builtin_type_complex
;
274 struct type
*builtin_type_double_complex
;
275 struct type
*builtin_type_fixed_dec
;
276 struct type
*builtin_type_float_dec
;
277 struct type
*builtin_type_string
;
279 /* Forward declarations */
282 upgrade_type
PARAMS ((int, struct type
**, int, union aux_ext
*, int, char *));
285 parse_partial_symbols
PARAMS ((struct objfile
*,
286 struct section_offsets
*));
289 *get_rfd
PARAMS ((int, int));
292 cross_ref
PARAMS ((int, union aux_ext
*, struct type
**, enum type_code
,
293 char **, int, char *));
295 static struct symbol
*
296 new_symbol
PARAMS ((char *));
299 new_type
PARAMS ((char *));
301 static struct block
*
302 new_block
PARAMS ((int));
304 static struct symtab
*
305 new_symtab
PARAMS ((char *, int, int, struct objfile
*));
307 static struct linetable
*
308 new_linetable
PARAMS ((int));
310 static struct blockvector
*
311 new_bvect
PARAMS ((int));
314 parse_symbol
PARAMS ((SYMR
*, union aux_ext
*, char *, int));
317 parse_type
PARAMS ((int, union aux_ext
*, unsigned int, int *, int, char *));
319 static struct symbol
*
320 mylookup_symbol
PARAMS ((char *, struct block
*, enum namespace,
321 enum address_class
));
323 static struct block
*
324 shrink_block
PARAMS ((struct block
*, struct symtab
*));
327 xzalloc
PARAMS ((unsigned int));
330 sort_blocks
PARAMS ((struct symtab
*));
333 compare_blocks
PARAMS ((const void *, const void *));
335 static struct partial_symtab
*
336 new_psymtab
PARAMS ((char *, struct objfile
*));
339 psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*, char *));
342 add_block
PARAMS ((struct block
*, struct symtab
*));
345 add_symbol
PARAMS ((struct symbol
*, struct block
*));
348 add_line
PARAMS ((struct linetable
*, int, CORE_ADDR
, int));
350 static struct linetable
*
351 shrink_linetable
PARAMS ((struct linetable
*));
354 mdebug_next_symbol_text
PARAMS ((void));
356 /* Address bounds for the signal trampoline in inferior, if any */
358 CORE_ADDR sigtramp_address
, sigtramp_end
;
360 /* Allocate zeroed memory */
366 PTR p
= xmalloc (size
);
372 /* Exported procedure: Builds a symtab from the PST partial one.
373 Restores the environment in effect when PST was created, delegates
374 most of the work to an ancillary procedure, and sorts
375 and reorders the symtab list at the end */
378 mdebug_psymtab_to_symtab (pst
)
379 struct partial_symtab
*pst
;
387 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
388 gdb_flush (gdb_stdout
);
391 next_symbol_text_func
= mdebug_next_symbol_text
;
393 psymtab_to_symtab_1 (pst
, pst
->filename
);
395 /* Match with global symbols. This only needs to be done once,
396 after all of the symtabs and dependencies have been read in. */
397 scan_file_globals (pst
->objfile
);
400 printf_filtered ("done.\n");
403 /* File-level interface functions */
405 /* Find a file descriptor given its index RF relative to a file CF */
415 fdrs
= debug_info
->fdr
;
417 /* Object files do not have the RFD table, all refs are absolute */
420 (*debug_swap
->swap_rfd_in
) (cur_bfd
,
421 ((char *) debug_info
->external_rfd
423 * debug_swap
->external_rfd_size
)),
428 /* Return a safer print NAME for a file descriptor */
435 return "<stripped file>";
438 return debug_info
->ss
+ f
->issBase
+ f
->rss
;
442 /* Read in and parse the symtab of the file OBJFILE. Symbols from
443 different sections are relocated via the SECTION_OFFSETS. */
446 mdebug_build_psymtabs (objfile
, swap
, info
, section_offsets
)
447 struct objfile
*objfile
;
448 const struct ecoff_debug_swap
*swap
;
449 struct ecoff_debug_info
*info
;
450 struct section_offsets
*section_offsets
;
452 cur_bfd
= objfile
->obfd
;
456 /* Make sure all the FDR information is swapped in. */
457 if (info
->fdr
== (FDR
*) NULL
)
463 info
->fdr
= (FDR
*) obstack_alloc (&objfile
->psymbol_obstack
,
464 (info
->symbolic_header
.ifdMax
466 fdr_src
= info
->external_fdr
;
468 + info
->symbolic_header
.ifdMax
* swap
->external_fdr_size
);
470 for (; fdr_src
< fdr_end
; fdr_src
+= swap
->external_fdr_size
, fdr_ptr
++)
471 (*swap
->swap_fdr_in
) (objfile
->obfd
, fdr_src
, fdr_ptr
);
474 parse_partial_symbols (objfile
, section_offsets
);
477 /* Check to make sure file was compiled with -g. If not, warn the
478 user of this limitation. */
479 if (compare_glevel (max_glevel
, GLEVEL_2
) < 0)
481 if (max_gdbinfo
== 0)
482 printf_unfiltered ("\n%s not compiled with -g, debugging support is limited.\n",
484 printf_unfiltered ("You should compile with -g2 or -g3 for best debugging support.\n");
485 gdb_flush (gdb_stdout
);
490 /* Local utilities */
492 /* Map of FDR indexes to partial symtabs */
496 struct partial_symtab
*pst
; /* the psymtab proper */
497 long n_globals
; /* exported globals (external symbols) */
498 long globals_offset
; /* cumulative */
502 /* Utility stack, used to nest procedures and blocks properly.
503 It is a doubly linked list, to avoid too many alloc/free.
504 Since we might need it quite a few times it is NOT deallocated
507 static struct parse_stack
509 struct parse_stack
*next
, *prev
;
510 struct symtab
*cur_st
; /* Current symtab. */
511 struct block
*cur_block
; /* Block in it. */
513 /* What are we parsing. stFile, or stBlock are for files and
514 blocks. stProc or stStaticProc means we have seen the start of a
515 procedure, but not the start of the block within in. When we see
516 the start of that block, we change it to stNil, without pushing a
517 new block, i.e. stNil means both a procedure and a block. */
521 int maxsyms
; /* Max symbols in this block. */
522 struct type
*cur_type
; /* Type we parse fields for. */
523 int cur_field
; /* Field number in cur_type. */
524 CORE_ADDR procadr
; /* Start addres of this procedure */
525 int numargs
; /* Its argument count */
528 *top_stack
; /* Top stack ptr */
531 /* Enter a new lexical context */
536 struct parse_stack
*new;
538 /* Reuse frames if possible */
539 if (top_stack
&& top_stack
->prev
)
540 new = top_stack
->prev
;
542 new = (struct parse_stack
*) xzalloc (sizeof (struct parse_stack
));
543 /* Initialize new frame with previous content */
546 register struct parse_stack
*prev
= new->prev
;
549 top_stack
->prev
= new;
551 new->next
= top_stack
;
556 /* Exit a lexical context */
564 top_stack
= top_stack
->next
;
568 /* Cross-references might be to things we haven't looked at
569 yet, e.g. type references. To avoid too many type
570 duplications we keep a quick fixup table, an array
571 of lists of references indexed by file descriptor */
573 struct mdebug_pending
575 struct mdebug_pending
*next
; /* link */
576 char *s
; /* the unswapped symbol */
577 struct type
*t
; /* its partial type descriptor */
581 /* The pending information is kept for an entire object file, and used
582 to be in the sym_private field. I took it out when I split
583 mdebugread from mipsread, because this might not be the only type
584 of symbols read from an object file. Instead, we allocate the
585 pending information table when we create the partial symbols, and
586 we store a pointer to the single table in each psymtab. */
588 static struct mdebug_pending
**pending_list
;
590 /* Check whether we already saw symbol SH in file FH */
592 static struct mdebug_pending
*
593 is_pending_symbol (fh
, sh
)
597 int f_idx
= fh
- debug_info
->fdr
;
598 register struct mdebug_pending
*p
;
600 /* Linear search is ok, list is typically no more than 10 deep */
601 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
607 /* Add a new symbol SH of type T */
610 add_pending (fh
, sh
, t
)
615 int f_idx
= fh
- debug_info
->fdr
;
616 struct mdebug_pending
*p
= is_pending_symbol (fh
, sh
);
618 /* Make sure we do not make duplicates */
621 p
= ((struct mdebug_pending
*)
622 obstack_alloc (¤t_objfile
->psymbol_obstack
,
623 sizeof (struct mdebug_pending
)));
626 p
->next
= pending_list
[f_idx
];
627 pending_list
[f_idx
] = p
;
632 /* Parsing Routines proper. */
634 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
635 For blocks, procedures and types we open a new lexical context.
636 This is basically just a big switch on the symbol's type. Argument
637 AX is the base pointer of aux symbols for this file (fh->iauxBase).
638 EXT_SH points to the unswapped symbol, which is needed for struct,
639 union, etc., types; it is NULL for an EXTR. BIGEND says whether
640 aux symbols are big-endian or little-endian. Return count of
641 SYMR's handled (normally one). */
644 parse_symbol (sh
, ax
, ext_sh
, bigend
)
650 const bfd_size_type external_sym_size
= debug_swap
->external_sym_size
;
651 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*)) =
652 debug_swap
->swap_sym_in
;
656 struct mdebug_pending
*pend
;
660 enum address_class
class;
662 long svalue
= sh
->value
;
665 if (ext_sh
== (char *) NULL
)
666 name
= debug_info
->ssext
+ sh
->iss
;
668 name
= debug_info
->ss
+ cur_fdr
->issBase
+ sh
->iss
;
675 case stGlobal
: /* external symbol, goes into global block */
677 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack
->cur_st
),
679 s
= new_symbol (name
);
680 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
683 case stStatic
: /* static data, goes into current block. */
685 b
= top_stack
->cur_block
;
686 s
= new_symbol (name
);
687 if (sh
->sc
== scCommon
)
689 /* It is a FORTRAN common block. At least for SGI Fortran the
690 address is not in the symbol; we need to fix it later in
691 scan_file_globals. */
692 int bucket
= hashname (SYMBOL_NAME (s
));
693 SYMBOL_VALUE_CHAIN (s
) = global_sym_chain
[bucket
];
694 global_sym_chain
[bucket
] = s
;
697 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
700 case stLocal
: /* local variable, goes into current block */
701 if (sh
->sc
== scRegister
)
703 class = LOC_REGISTER
;
704 svalue
= ECOFF_REG_TO_REGNUM (svalue
);
708 b
= top_stack
->cur_block
;
709 s
= new_symbol (name
);
710 SYMBOL_VALUE (s
) = svalue
;
712 data
: /* Common code for symbols describing data */
713 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
714 SYMBOL_CLASS (s
) = class;
717 /* Type could be missing in a number of cases */
718 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
719 sh
->index
== 0xfffff)
720 SYMBOL_TYPE (s
) = builtin_type_int
; /* undefined? */
722 SYMBOL_TYPE (s
) = parse_type (cur_fd
, ax
, sh
->index
, 0, bigend
, name
);
723 /* Value of a data symbol is its memory address */
726 case stParam
: /* arg to procedure, goes into current block */
728 top_stack
->numargs
++;
730 /* Special GNU C++ name. */
731 if (name
[0] == CPLUS_MARKER
&& name
[1] == 't' && name
[2] == 0)
732 name
= "this"; /* FIXME, not alloc'd in obstack */
733 s
= new_symbol (name
);
735 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
739 /* Pass by value in register. */
740 SYMBOL_CLASS(s
) = LOC_REGPARM
;
741 svalue
= ECOFF_REG_TO_REGNUM (svalue
);
744 /* Pass by reference on stack. */
745 SYMBOL_CLASS(s
) = LOC_REF_ARG
;
748 /* Pass by reference in register. */
749 SYMBOL_CLASS(s
) = LOC_REGPARM_ADDR
;
750 svalue
= ECOFF_REG_TO_REGNUM (svalue
);
753 /* Pass by value on stack. */
754 SYMBOL_CLASS(s
) = LOC_ARG
;
757 SYMBOL_VALUE (s
) = svalue
;
758 SYMBOL_TYPE (s
) = parse_type (cur_fd
, ax
, sh
->index
, 0, bigend
, name
);
759 add_symbol (s
, top_stack
->cur_block
);
761 /* FIXME: This has not been tested. See dbxread.c */
762 /* Add the type of this parameter to the function/procedure
763 type of this block. */
764 add_param_to_type (&top_stack
->cur_block
->function
->type
, s
);
768 case stLabel
: /* label, goes into current block */
769 s
= new_symbol (name
);
770 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
; /* so that it can be used */
771 SYMBOL_CLASS (s
) = LOC_LABEL
; /* but not misused */
772 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
773 SYMBOL_TYPE (s
) = builtin_type_int
;
774 add_symbol (s
, top_stack
->cur_block
);
777 case stProc
: /* Procedure, usually goes into global block */
778 case stStaticProc
: /* Static procedure, goes into current block */
779 s
= new_symbol (name
);
780 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
781 SYMBOL_CLASS (s
) = LOC_BLOCK
;
782 /* Type of the return value */
783 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
784 t
= builtin_type_int
;
786 t
= parse_type (cur_fd
, ax
, sh
->index
+ 1, 0, bigend
, name
);
787 b
= top_stack
->cur_block
;
788 if (sh
->st
== stProc
)
790 struct blockvector
*bv
= BLOCKVECTOR (top_stack
->cur_st
);
791 /* The next test should normally be true, but provides a
792 hook for nested functions (which we don't want to make
794 if (b
== BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
))
795 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
796 /* Irix 5 sometimes has duplicate names for the same
797 function. We want to add such names up at the global
798 level, not as a nested function. */
799 else if (sh
->value
== top_stack
->procadr
)
800 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
804 /* Make a type for the procedure itself */
806 /* FIXME: This has not been tested yet! See dbxread.c */
807 /* Generate a template for the type of this function. The
808 types of the arguments will be added as we read the symbol
810 memcpy (lookup_function_type (t
), SYMBOL_TYPE (s
), sizeof (struct type
));
812 SYMBOL_TYPE (s
) = lookup_function_type (t
);
815 /* Create and enter a new lexical context */
816 b
= new_block (top_stack
->maxsyms
);
817 SYMBOL_BLOCK_VALUE (s
) = b
;
818 BLOCK_FUNCTION (b
) = s
;
819 BLOCK_START (b
) = BLOCK_END (b
) = sh
->value
;
820 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
821 add_block (b
, top_stack
->cur_st
);
823 /* Not if we only have partial info */
824 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
828 top_stack
->cur_block
= b
;
829 top_stack
->blocktype
= sh
->st
;
830 top_stack
->cur_type
= SYMBOL_TYPE (s
);
831 top_stack
->cur_field
= -1;
832 top_stack
->procadr
= sh
->value
;
833 top_stack
->numargs
= 0;
836 /* Beginning of code for structure, union, and enum definitions.
837 They all share a common set of local variables, defined here. */
839 enum type_code type_code
;
845 case stStruct
: /* Start a block defining a struct type */
846 type_code
= TYPE_CODE_STRUCT
;
847 goto structured_common
;
849 case stUnion
: /* Start a block defining a union type */
850 type_code
= TYPE_CODE_UNION
;
851 goto structured_common
;
853 case stEnum
: /* Start a block defining an enum type */
854 type_code
= TYPE_CODE_ENUM
;
855 goto structured_common
;
857 case stBlock
: /* Either a lexical block, or some type */
858 if (sh
->sc
!= scInfo
&& sh
->sc
!= scCommon
)
859 goto case_stBlock_code
; /* Lexical block */
861 type_code
= TYPE_CODE_UNDEF
; /* We have a type. */
863 /* Common code for handling struct, union, enum, and/or as-yet-
864 unknown-type blocks of info about structured data. `type_code'
865 has been set to the proper TYPE_CODE, if we know it. */
868 top_stack
->blocktype
= stBlock
;
870 /* First count the number of fields and the highest value. */
873 for (ext_tsym
= ext_sh
+ external_sym_size
;
875 ext_tsym
+= external_sym_size
)
879 (*swap_sym_in
) (cur_bfd
, ext_tsym
, &tsym
);
887 if (nfields
== 0 && type_code
== TYPE_CODE_UNDEF
)
888 /* If the type of the member is Nil (or Void),
889 without qualifiers, assume the tag is an
891 if (tsym
.index
== indexNil
)
892 type_code
= TYPE_CODE_ENUM
;
895 ecoff_swap_tir_in (bigend
,
896 &ax
[tsym
.index
].a_ti
,
898 if ((tir
.bt
== btNil
|| tir
.bt
== btVoid
)
900 type_code
= TYPE_CODE_ENUM
;
903 if (tsym
.value
> max_value
)
904 max_value
= tsym
.value
;
913 /* This is a no-op; is it trying to tell us something
914 we should be checking? */
915 if (tsym
.sc
== scVariant
); /*UNIMPLEMENTED*/
919 /* This is something like a struct within a
920 struct. Skip over the fields of the inner
921 struct. The -1 is because the for loop will
922 increment ext_tsym. */
923 ext_tsym
= ((char *) debug_info
->external_sym
924 + ((cur_fdr
->isymBase
+ tsym
.index
- 1)
925 * external_sym_size
));
931 /* mips cc puts out a typedef for struct x if it is not yet
932 defined when it encounters
933 struct y { struct x *xp; };
938 complain (&block_member_complaint
, tsym
.st
);
943 /* In an stBlock, there is no way to distinguish structs,
944 unions, and enums at this point. This is a bug in the
945 original design (that has been fixed with the recent
946 addition of the stStruct, stUnion, and stEnum symbol
947 types.) The way you can tell is if/when you see a variable
948 or field of that type. In that case the variable's type
949 (in the AUX table) says if the type is struct, union, or
950 enum, and points back to the stBlock here. So you can
951 patch the tag kind up later - but only if there actually is
952 a variable or field of that type.
954 So until we know for sure, we will guess at this point.
956 If the first member has index==indexNil or a void type,
957 assume we have an enumeration.
958 Otherwise, if there is more than one member, and all
959 the members have offset 0, assume we have a union.
960 Otherwise, assume we have a struct.
962 The heuristic could guess wrong in the case of of an
963 enumeration with no members or a union with one (or zero)
964 members, or when all except the last field of a struct have
965 width zero. These are uncommon and/or illegal situations,
966 and in any case guessing wrong probably doesn't matter
969 But if we later do find out we were wrong, we fixup the tag
970 kind. Members of an enumeration must be handled
971 differently from struct/union fields, and that is harder to
972 patch up, but luckily we shouldn't need to. (If there are
973 any enumeration members, we can tell for sure it's an enum
976 if (type_code
== TYPE_CODE_UNDEF
)
977 if (nfields
> 1 && max_value
== 0)
978 type_code
= TYPE_CODE_UNION
;
980 type_code
= TYPE_CODE_STRUCT
;
982 /* Create a new type or use the pending type. */
983 pend
= is_pending_symbol (cur_fdr
, ext_sh
);
984 if (pend
== (struct mdebug_pending
*) NULL
)
987 add_pending (cur_fdr
, ext_sh
, t
);
992 /* Alpha cc unnamed structs do not get a tag name. */
994 TYPE_TAG_NAME (t
) = NULL
;
996 TYPE_TAG_NAME (t
) = obconcat (¤t_objfile
->symbol_obstack
,
999 TYPE_CODE (t
) = type_code
;
1000 TYPE_LENGTH (t
) = sh
->value
;
1001 TYPE_NFIELDS (t
) = nfields
;
1002 TYPE_FIELDS (t
) = f
= ((struct field
*)
1004 nfields
* sizeof (struct field
)));
1006 if (type_code
== TYPE_CODE_ENUM
)
1008 /* This is a non-empty enum. */
1009 for (ext_tsym
= ext_sh
+ external_sym_size
;
1011 ext_tsym
+= external_sym_size
)
1014 struct symbol
*enum_sym
;
1016 (*swap_sym_in
) (cur_bfd
, ext_tsym
, &tsym
);
1018 if (tsym
.st
!= stMember
)
1021 f
->bitpos
= tsym
.value
;
1023 f
->name
= debug_info
->ss
+ cur_fdr
->issBase
+ tsym
.iss
;
1026 enum_sym
= ((struct symbol
*)
1027 obstack_alloc (¤t_objfile
->symbol_obstack
,
1028 sizeof (struct symbol
)));
1029 memset ((PTR
) enum_sym
, 0, sizeof (struct symbol
));
1030 SYMBOL_NAME (enum_sym
) = f
->name
;
1031 SYMBOL_CLASS (enum_sym
) = LOC_CONST
;
1032 SYMBOL_TYPE (enum_sym
) = t
;
1033 SYMBOL_NAMESPACE (enum_sym
) = VAR_NAMESPACE
;
1034 SYMBOL_VALUE (enum_sym
) = tsym
.value
;
1035 add_symbol (enum_sym
, top_stack
->cur_block
);
1037 /* Skip the stMembers that we've handled. */
1042 /* make this the current type */
1043 top_stack
->cur_type
= t
;
1044 top_stack
->cur_field
= 0;
1046 /* Do not create a symbol for alpha cc unnamed structs. */
1050 /* gcc puts out an empty struct for an opaque struct definitions,
1051 do not create a symbol for it either. */
1052 if (TYPE_NFIELDS (t
) == 0)
1054 TYPE_FLAGS (t
) |= TYPE_FLAG_STUB
;
1058 s
= new_symbol (name
);
1059 SYMBOL_NAMESPACE (s
) = STRUCT_NAMESPACE
;
1060 SYMBOL_CLASS (s
) = LOC_TYPEDEF
;
1061 SYMBOL_VALUE (s
) = 0;
1062 SYMBOL_TYPE (s
) = t
;
1063 add_symbol (s
, top_stack
->cur_block
);
1066 /* End of local variables shared by struct, union, enum, and
1067 block (as yet unknown struct/union/enum) processing. */
1071 /* beginnning of (code) block. Value of symbol
1072 is the displacement from procedure start */
1073 push_parse_stack ();
1075 /* Do not start a new block if this is the outermost block of a
1076 procedure. This allows the LOC_BLOCK symbol to point to the
1077 block with the local variables, so funcname::var works. */
1078 if (top_stack
->blocktype
== stProc
1079 || top_stack
->blocktype
== stStaticProc
)
1081 top_stack
->blocktype
= stNil
;
1085 top_stack
->blocktype
= stBlock
;
1086 b
= new_block (top_stack
->maxsyms
);
1087 BLOCK_START (b
) = sh
->value
+ top_stack
->procadr
;
1088 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
1089 top_stack
->cur_block
= b
;
1090 add_block (b
, top_stack
->cur_st
);
1093 case stEnd
: /* end (of anything) */
1094 if (sh
->sc
== scInfo
|| sh
->sc
== scCommon
)
1096 /* Finished with type */
1097 top_stack
->cur_type
= 0;
1099 else if (sh
->sc
== scText
&&
1100 (top_stack
->blocktype
== stProc
||
1101 top_stack
->blocktype
== stStaticProc
))
1103 /* Finished with procedure */
1104 struct blockvector
*bv
= BLOCKVECTOR (top_stack
->cur_st
);
1105 struct mips_extra_func_info
*e
;
1109 BLOCK_END (top_stack
->cur_block
) += sh
->value
; /* size */
1111 /* Make up special symbol to contain procedure specific info */
1112 s
= new_symbol (MIPS_EFI_SYMBOL_NAME
);
1113 SYMBOL_NAMESPACE (s
) = LABEL_NAMESPACE
;
1114 SYMBOL_CLASS (s
) = LOC_CONST
;
1115 SYMBOL_TYPE (s
) = builtin_type_void
;
1116 e
= ((struct mips_extra_func_info
*)
1117 obstack_alloc (¤t_objfile
->symbol_obstack
,
1118 sizeof (struct mips_extra_func_info
)));
1119 SYMBOL_VALUE (s
) = (long) e
;
1120 e
->numargs
= top_stack
->numargs
;
1121 add_symbol (s
, top_stack
->cur_block
);
1123 /* Reallocate symbols, saving memory */
1124 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
1126 /* f77 emits proc-level with address bounds==[0,0],
1127 So look for such child blocks, and patch them. */
1128 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS (bv
); i
++)
1130 struct block
*b_bad
= BLOCKVECTOR_BLOCK (bv
, i
);
1131 if (BLOCK_SUPERBLOCK (b_bad
) == b
1132 && BLOCK_START (b_bad
) == top_stack
->procadr
1133 && BLOCK_END (b_bad
) == top_stack
->procadr
)
1135 BLOCK_START (b_bad
) = BLOCK_START (b
);
1136 BLOCK_END (b_bad
) = BLOCK_END (b
);
1140 else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
)
1142 /* End of (code) block. The value of the symbol is the
1143 displacement from the procedure`s start address of the
1144 end of this block. */
1145 BLOCK_END (top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1146 shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
1148 else if (sh
->sc
== scText
&& top_stack
->blocktype
== stNil
)
1150 /* End of outermost block. Pop parse stack and ignore. The
1151 following stEnd of stProc will take care of the block. */
1154 else if (sh
->sc
== scText
&& top_stack
->blocktype
== stFile
)
1156 /* End of file. Pop parse stack and ignore. Higher
1157 level code deals with this. */
1161 complain (&stEnd_complaint
, sh
->sc
);
1163 pop_parse_stack (); /* restore previous lexical context */
1166 case stMember
: /* member of struct or union */
1167 f
= &TYPE_FIELDS (top_stack
->cur_type
)[top_stack
->cur_field
++];
1169 f
->bitpos
= sh
->value
;
1171 f
->type
= parse_type (cur_fd
, ax
, sh
->index
, &bitsize
, bigend
, name
);
1172 f
->bitsize
= bitsize
;
1175 case stTypedef
: /* type definition */
1176 /* Typedefs for forward declarations and opaque structs from alpha cc
1177 are handled by cross_ref, skip them. */
1181 /* Parse the type or use the pending type. */
1182 pend
= is_pending_symbol (cur_fdr
, ext_sh
);
1183 if (pend
== (struct mdebug_pending
*) NULL
)
1185 t
= parse_type (cur_fd
, ax
, sh
->index
, (int *)NULL
, bigend
, name
);
1186 add_pending (cur_fdr
, ext_sh
, t
);
1191 /* mips cc puts out a typedef with the name of the struct for forward
1192 declarations. These should not go into the symbol table and
1193 TYPE_NAME should not be set for them.
1194 They can't be distinguished from an intentional typedef to
1195 the same name however:
1197 struct x { int ix; int jx; };
1201 struct xx {int ixx; int jxx; };
1202 generates a cross referencing stTypedef for x and xx.
1203 The user visible effect of this is that the type of a pointer
1204 to struct foo sometimes is given as `foo *' instead of `struct foo *'.
1205 The problem is fixed with alpha cc. */
1207 s
= new_symbol (name
);
1208 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
1209 SYMBOL_CLASS (s
) = LOC_TYPEDEF
;
1210 SYMBOL_BLOCK_VALUE (s
) = top_stack
->cur_block
;
1211 SYMBOL_TYPE (s
) = t
;
1212 add_symbol (s
, top_stack
->cur_block
);
1214 /* Incomplete definitions of structs should not get a name. */
1215 if (TYPE_NAME (SYMBOL_TYPE (s
)) == NULL
1216 && (TYPE_NFIELDS (SYMBOL_TYPE (s
)) != 0
1217 || (TYPE_CODE (SYMBOL_TYPE (s
)) != TYPE_CODE_STRUCT
1218 && TYPE_CODE (SYMBOL_TYPE (s
)) != TYPE_CODE_UNION
)))
1220 if (TYPE_CODE (SYMBOL_TYPE (s
)) == TYPE_CODE_PTR
1221 || TYPE_CODE (SYMBOL_TYPE (s
)) == TYPE_CODE_FUNC
)
1223 /* If we are giving a name to a type such as "pointer to
1224 foo" or "function returning foo", we better not set
1225 the TYPE_NAME. If the program contains "typedef char
1226 *caddr_t;", we don't want all variables of type char
1227 * to print as caddr_t. This is not just a
1228 consequence of GDB's type management; CC and GCC (at
1229 least through version 2.4) both output variables of
1230 either type char * or caddr_t with the type
1231 refering to the stTypedef symbol for caddr_t. If a future
1232 compiler cleans this up it GDB is not ready for it
1233 yet, but if it becomes ready we somehow need to
1234 disable this check (without breaking the PCC/GCC2.4
1239 Fortunately, this check seems not to be necessary
1240 for anything except pointers or functions. */
1243 TYPE_NAME (SYMBOL_TYPE (s
)) = SYMBOL_NAME (s
);
1247 case stFile
: /* file name */
1248 push_parse_stack ();
1249 top_stack
->blocktype
= sh
->st
;
1252 /* I`ve never seen these for C */
1254 break; /* register relocation */
1256 break; /* forwarding address */
1258 break; /* constant */
1260 complain (&unknown_mdebug_symtype_complaint
, sh
->st
);
1267 /* Parse the type information provided in the raw AX entries for
1268 the symbol SH. Return the bitfield size in BS, in case.
1269 We must byte-swap the AX entries before we use them; BIGEND says whether
1270 they are big-endian or little-endian (from fh->fBigendian). */
1272 static struct type
*
1273 parse_type (fd
, ax
, aux_index
, bs
, bigend
, sym_name
)
1276 unsigned int aux_index
;
1281 /* Null entries in this map are treated specially */
1282 static struct type
**map_bt
[] =
1284 &builtin_type_void
, /* btNil */
1286 &builtin_type_char
, /* btChar */
1287 &builtin_type_unsigned_char
,/* btUChar */
1288 &builtin_type_short
, /* btShort */
1289 &builtin_type_unsigned_short
, /* btUShort */
1290 &builtin_type_int
, /* btInt */
1291 &builtin_type_unsigned_int
, /* btUInt */
1292 &builtin_type_long
, /* btLong */
1293 &builtin_type_unsigned_long
,/* btULong */
1294 &builtin_type_float
, /* btFloat */
1295 &builtin_type_double
, /* btDouble */
1302 &builtin_type_complex
, /* btComplex */
1303 &builtin_type_double_complex
, /* btDComplex */
1305 &builtin_type_fixed_dec
, /* btFixedDec */
1306 &builtin_type_float_dec
, /* btFloatDec */
1307 &builtin_type_string
, /* btString */
1310 &builtin_type_void
, /* btVoid */
1311 0, /* DEC C++: Pointer to member */
1312 0, /* DEC C++: Virtual function table */
1313 0, /* DEC C++: Class (Record) */
1314 &builtin_type_long
, /* btLong64 */
1315 &builtin_type_unsigned_long
, /* btULong64 */
1316 &builtin_type_long_long
, /* btLongLong64 */
1317 &builtin_type_unsigned_long_long
, /* btULongLong64 */
1318 &builtin_type_unsigned_long
, /* btAdr64 */
1319 &builtin_type_long
, /* btInt64 */
1320 &builtin_type_unsigned_long
, /* btUInt64 */
1324 struct type
*tp
= 0;
1325 enum type_code type_code
= TYPE_CODE_UNDEF
;
1327 /* Handle corrupt aux indices. */
1328 if (aux_index
>= (debug_info
->fdr
+ fd
)->caux
)
1330 complain (&index_complaint
, sym_name
);
1331 return builtin_type_int
;
1335 /* Use aux as a type information record, map its basic type. */
1336 ecoff_swap_tir_in (bigend
, &ax
->a_ti
, t
);
1337 if (t
->bt
>= (sizeof (map_bt
) / sizeof (*map_bt
)))
1339 complain (&basic_type_complaint
, t
->bt
, sym_name
);
1340 return builtin_type_int
;
1344 tp
= *map_bt
[t
->bt
];
1349 /* Cannot use builtin types -- build our own */
1353 tp
= lookup_pointer_type (builtin_type_void
);
1356 type_code
= TYPE_CODE_STRUCT
;
1359 type_code
= TYPE_CODE_UNION
;
1362 type_code
= TYPE_CODE_ENUM
;
1365 type_code
= TYPE_CODE_RANGE
;
1368 type_code
= TYPE_CODE_SET
;
1371 /* alpha cc uses this for typedefs. The true type will be
1372 obtained by crossreferencing below. */
1373 type_code
= TYPE_CODE_ERROR
;
1376 complain (&basic_type_complaint
, t
->bt
, sym_name
);
1377 return builtin_type_int
;
1381 /* Move on to next aux */
1386 /* Inhibit core dumps with some cfront generated objects that
1388 if (bs
== (int *)NULL
)
1390 complain (&bad_fbitfield_complaint
, sym_name
);
1391 return builtin_type_int
;
1393 *bs
= AUX_GET_WIDTH (bigend
, ax
);
1397 /* All these types really point to some (common) MIPS type
1398 definition, and only the type-qualifiers fully identify
1399 them. We'll make the same effort at sharing. */
1400 if (t
->bt
== btStruct
||
1404 /* btSet (I think) implies that the name is a tag name, not a typedef
1405 name. This apparently is a MIPS extension for C sets. */
1410 /* Try to cross reference this type, build new type on failure. */
1411 ax
+= cross_ref (fd
, ax
, &tp
, type_code
, &name
, bigend
, sym_name
);
1412 if (tp
== (struct type
*) NULL
)
1413 tp
= init_type (type_code
, 0, 0, (char *) NULL
, current_objfile
);
1415 /* Make sure that TYPE_CODE(tp) has an expected type code.
1416 Any type may be returned from cross_ref if file indirect entries
1418 if (TYPE_CODE (tp
) != TYPE_CODE_STRUCT
1419 && TYPE_CODE (tp
) != TYPE_CODE_UNION
1420 && TYPE_CODE (tp
) != TYPE_CODE_ENUM
)
1422 complain (&unexpected_type_code_complaint
, sym_name
);
1427 /* Usually, TYPE_CODE(tp) is already type_code. The main
1428 exception is if we guessed wrong re struct/union/enum.
1429 But for struct vs. union a wrong guess is harmless, so
1430 don't complain(). */
1431 if ((TYPE_CODE (tp
) == TYPE_CODE_ENUM
1432 && type_code
!= TYPE_CODE_ENUM
)
1433 || (TYPE_CODE (tp
) != TYPE_CODE_ENUM
1434 && type_code
== TYPE_CODE_ENUM
))
1436 complain (&bad_tag_guess_complaint
, sym_name
);
1439 if (TYPE_CODE (tp
) != type_code
)
1441 TYPE_CODE (tp
) = type_code
;
1444 /* Do not set the tag name if it is a compiler generated tag name
1445 (.Fxx or .xxfake or empty) for unnamed struct/union/enums. */
1446 if (name
[0] == '.' || name
[0] == '\0')
1447 TYPE_TAG_NAME (tp
) = NULL
;
1448 else if (TYPE_TAG_NAME (tp
) == NULL
1449 || !STREQ (TYPE_TAG_NAME (tp
), name
))
1450 TYPE_TAG_NAME (tp
) = obsavestring (name
, strlen (name
),
1451 ¤t_objfile
->type_obstack
);
1455 /* All these types really point to some (common) MIPS type
1456 definition, and only the type-qualifiers fully identify
1457 them. We'll make the same effort at sharing.
1458 FIXME: btIndirect cannot happen here as it is handled by the
1459 switch t->bt above. And we are not doing any guessing on range types. */
1460 if (t
->bt
== btIndirect
||
1465 /* Try to cross reference this type, build new type on failure. */
1466 ax
+= cross_ref (fd
, ax
, &tp
, type_code
, &name
, bigend
, sym_name
);
1467 if (tp
== (struct type
*) NULL
)
1468 tp
= init_type (type_code
, 0, 0, (char *) NULL
, current_objfile
);
1470 /* Make sure that TYPE_CODE(tp) has an expected type code.
1471 Any type may be returned from cross_ref if file indirect entries
1473 if (TYPE_CODE (tp
) != TYPE_CODE_RANGE
)
1475 complain (&unexpected_type_code_complaint
, sym_name
);
1479 /* Usually, TYPE_CODE(tp) is already type_code. The main
1480 exception is if we guessed wrong re struct/union/enum. */
1481 if (TYPE_CODE (tp
) != type_code
)
1483 complain (&bad_tag_guess_complaint
, sym_name
);
1484 TYPE_CODE (tp
) = type_code
;
1486 if (TYPE_NAME (tp
) == NULL
|| !STREQ (TYPE_NAME (tp
), name
))
1487 TYPE_NAME (tp
) = obsavestring (name
, strlen (name
),
1488 ¤t_objfile
->type_obstack
);
1491 if (t
->bt
== btTypedef
)
1495 /* Try to cross reference this type, it should succeed. */
1496 ax
+= cross_ref (fd
, ax
, &tp
, type_code
, &name
, bigend
, sym_name
);
1497 if (tp
== (struct type
*) NULL
)
1499 complain (&unable_to_cross_ref_complaint
, sym_name
);
1500 tp
= builtin_type_int
;
1504 /* Deal with range types */
1505 if (t
->bt
== btRange
)
1507 TYPE_NFIELDS (tp
) = 2;
1508 TYPE_FIELDS (tp
) = ((struct field
*)
1509 TYPE_ALLOC (tp
, 2 * sizeof (struct field
)));
1510 TYPE_FIELD_NAME (tp
, 0) = obsavestring ("Low", strlen ("Low"),
1511 ¤t_objfile
->type_obstack
);
1512 TYPE_FIELD_BITPOS (tp
, 0) = AUX_GET_DNLOW (bigend
, ax
);
1514 TYPE_FIELD_NAME (tp
, 1) = obsavestring ("High", strlen ("High"),
1515 ¤t_objfile
->type_obstack
);
1516 TYPE_FIELD_BITPOS (tp
, 1) = AUX_GET_DNHIGH (bigend
, ax
);
1520 /* Parse all the type qualifiers now. If there are more
1521 than 6 the game will continue in the next aux */
1525 #define PARSE_TQ(tq) \
1526 if (t->tq != tqNil) \
1527 ax += upgrade_type(fd, &tp, t->tq, ax, bigend, sym_name); \
1539 /* mips cc 2.x and gcc never put out continued aux entries. */
1543 ecoff_swap_tir_in (bigend
, &ax
->a_ti
, t
);
1547 /* Complain for illegal continuations due to corrupt aux entries. */
1549 complain (&bad_continued_complaint
, sym_name
);
1554 /* Make up a complex type from a basic one. Type is passed by
1555 reference in TPP and side-effected as necessary. The type
1556 qualifier TQ says how to handle the aux symbols at AX for
1557 the symbol SX we are currently analyzing. BIGEND says whether
1558 aux symbols are big-endian or little-endian.
1559 Returns the number of aux symbols we parsed. */
1562 upgrade_type (fd
, tpp
, tq
, ax
, bigend
, sym_name
)
1573 /* Used in array processing */
1584 t
= lookup_pointer_type (*tpp
);
1589 t
= lookup_function_type (*tpp
);
1596 /* Determine and record the domain type (type of index) */
1597 ecoff_swap_rndx_in (bigend
, &ax
->a_rndx
, &rndx
);
1603 rf
= AUX_GET_ISYM (bigend
, ax
);
1606 fh
= get_rfd (fd
, rf
);
1608 indx
= parse_type (fd
, debug_info
->external_aux
+ fh
->iauxBase
,
1609 id
, (int *) NULL
, bigend
, sym_name
);
1611 /* The bounds type should be an integer type, but might be anything
1612 else due to corrupt aux entries. */
1613 if (TYPE_CODE (indx
) != TYPE_CODE_INT
)
1615 complain (&array_index_type_complaint
, sym_name
);
1616 indx
= builtin_type_int
;
1619 /* Get the bounds, and create the array type. */
1621 lower
= AUX_GET_DNLOW (bigend
, ax
);
1623 upper
= AUX_GET_DNHIGH (bigend
, ax
);
1625 rf
= AUX_GET_WIDTH (bigend
, ax
); /* bit size of array element */
1627 range
= create_range_type ((struct type
*) NULL
, indx
,
1630 t
= create_array_type ((struct type
*) NULL
, *tpp
, range
);
1632 /* We used to fill in the supplied array element bitsize
1633 here if the TYPE_LENGTH of the target type was zero.
1634 This happens for a `pointer to an array of anonymous structs',
1635 but in this case the array element bitsize is also zero,
1636 so nothing is gained.
1637 And we used to check the TYPE_LENGTH of the target type against
1638 the supplied array element bitsize.
1639 gcc causes a mismatch for `pointer to array of object',
1640 since the sdb directives it uses do not have a way of
1641 specifying the bitsize, but it does no harm (the
1642 TYPE_LENGTH should be correct) and we should be able to
1643 ignore the erroneous bitsize from the auxiliary entry safely.
1644 dbx seems to ignore it too. */
1650 /* Volatile -- currently ignored */
1654 /* Const -- currently ignored */
1658 complain (&unknown_type_qual_complaint
, tq
);
1664 /* Parse a procedure descriptor record PR. Note that the procedure is
1665 parsed _after_ the local symbols, now we just insert the extra
1666 information we need into a MIPS_EFI_SYMBOL_NAME symbol that has
1667 already been placed in the procedure's main block. Note also that
1668 images that have been partially stripped (ld -x) have been deprived
1669 of local symbols, and we have to cope with them here. FIRST_OFF is
1670 the offset of the first procedure for this FDR; we adjust the
1671 address by this amount, but I don't know why. SEARCH_SYMTAB is the symtab
1672 to look for the function which contains the MIPS_EFI_SYMBOL_NAME symbol
1673 in question, or NULL to use top_stack->cur_block. */
1675 static void parse_procedure
PARAMS ((PDR
*, struct symtab
*, unsigned long));
1678 parse_procedure (pr
, search_symtab
, first_off
)
1680 struct symtab
*search_symtab
;
1681 unsigned long first_off
;
1683 struct symbol
*s
, *i
;
1685 struct mips_extra_func_info
*e
;
1688 /* Simple rule to find files linked "-x" */
1689 if (cur_fdr
->rss
== -1)
1693 /* Static procedure at address pr->adr. Sigh. */
1694 complain (&pdr_static_symbol_complaint
, (unsigned long) pr
->adr
);
1702 (*debug_swap
->swap_ext_in
) (cur_bfd
,
1703 ((char *) debug_info
->external_ext
1705 * debug_swap
->external_ext_size
)),
1707 sh_name
= debug_info
->ssext
+ she
.asym
.iss
;
1715 (*debug_swap
->swap_sym_in
) (cur_bfd
,
1716 ((char *) debug_info
->external_sym
1717 + ((cur_fdr
->isymBase
+ pr
->isym
)
1718 * debug_swap
->external_sym_size
)),
1720 sh_name
= debug_info
->ss
+ cur_fdr
->issBase
+ sh
.iss
;
1723 if (search_symtab
!= NULL
)
1726 /* This loses both in the case mentioned (want a static, find a global),
1727 but also if we are looking up a non-mangled name which happens to
1728 match the name of a mangled function. */
1729 /* We have to save the cur_fdr across the call to lookup_symbol.
1730 If the pdr is for a static function and if a global function with
1731 the same name exists, lookup_symbol will eventually read in the symtab
1732 for the global function and clobber cur_fdr. */
1733 FDR
*save_cur_fdr
= cur_fdr
;
1734 s
= lookup_symbol (sh_name
, NULL
, VAR_NAMESPACE
, 0, NULL
);
1735 cur_fdr
= save_cur_fdr
;
1739 BLOCKVECTOR_BLOCK (BLOCKVECTOR (search_symtab
), STATIC_BLOCK
),
1745 s
= mylookup_symbol (sh_name
, top_stack
->cur_block
,
1746 VAR_NAMESPACE
, LOC_BLOCK
);
1750 b
= SYMBOL_BLOCK_VALUE (s
);
1754 complain (&pdr_for_nonsymbol_complaint
, sh_name
);
1758 /* FIXME -- delete. We can't do symbol allocation now; it's all done. */
1759 s
= new_symbol (sh_name
);
1760 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
1761 SYMBOL_CLASS (s
) = LOC_BLOCK
;
1762 /* Donno its type, hope int is ok */
1763 SYMBOL_TYPE (s
) = lookup_function_type (builtin_type_int
);
1764 add_symbol (s
, top_stack
->cur_block
);
1765 /* Wont have symbols for this one */
1767 SYMBOL_BLOCK_VALUE (s
) = b
;
1768 BLOCK_FUNCTION (b
) = s
;
1769 BLOCK_START (b
) = pr
->adr
;
1770 /* BOUND used to be the end of procedure's text, but the
1771 argument is no longer passed in. */
1772 BLOCK_END (b
) = bound
;
1773 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
1774 add_block (b
, top_stack
->cur_st
);
1778 i
= mylookup_symbol (MIPS_EFI_SYMBOL_NAME
, b
, LABEL_NAMESPACE
, LOC_CONST
);
1782 e
= (struct mips_extra_func_info
*) SYMBOL_VALUE (i
);
1784 e
->pdr
.isym
= (long) s
;
1785 e
->pdr
.adr
+= cur_fdr
->adr
- first_off
;
1787 /* Correct incorrect setjmp procedure descriptor from the library
1788 to make backtrace through setjmp work. */
1789 if (e
->pdr
.pcreg
== 0 && STREQ (sh_name
, "setjmp"))
1791 complain (&bad_setjmp_pdr_complaint
, 0);
1792 e
->pdr
.pcreg
= RA_REGNUM
;
1793 e
->pdr
.regmask
= 0x80000000;
1794 e
->pdr
.regoffset
= -4;
1797 /* Fake PC_REGNUM for alpha __sigtramp so that read_next_frame_reg
1798 will use the saved user pc from the sigcontext. */
1799 if (STREQ (sh_name
, "__sigtramp"))
1800 e
->pdr
.pcreg
= PC_REGNUM
;
1801 /* Make the same patch for Irix. */
1802 if (STREQ (sh_name
, "_sigtramp"))
1803 e
->pdr
.pcreg
= PC_REGNUM
;
1807 /* Parse the external symbol ES. Just call parse_symbol() after
1808 making sure we know where the aux are for it. For procedures,
1809 parsing of the PDRs has already provided all the needed
1810 information, we only parse them if SKIP_PROCEDURES is false,
1811 and only if this causes no symbol duplication.
1812 BIGEND says whether aux entries are big-endian or little-endian.
1814 This routine clobbers top_stack->cur_block and ->cur_st. */
1817 parse_external (es
, skip_procedures
, bigend
)
1819 int skip_procedures
;
1824 if (es
->ifd
!= ifdNil
)
1827 cur_fdr
= debug_info
->fdr
+ cur_fd
;
1828 ax
= debug_info
->external_aux
+ cur_fdr
->iauxBase
;
1832 cur_fdr
= debug_info
->fdr
;
1836 /* Reading .o files */
1837 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
)
1840 switch (es
->asym
.st
)
1843 /* These are generated for static symbols in .o files,
1864 /* FIXME: Turn this into a complaint? */
1866 printf_filtered ("Warning: %s `%s' is undefined (in %s)\n",
1867 what
, debug_info
->ssext
+ es
->asym
.iss
,
1868 fdr_name (cur_fdr
));
1872 switch (es
->asym
.st
)
1875 /* If we have full symbols we do not need more */
1876 if (skip_procedures
)
1878 if (mylookup_symbol (debug_info
->ssext
+ es
->asym
.iss
,
1879 top_stack
->cur_block
,
1880 VAR_NAMESPACE
, LOC_BLOCK
))
1885 /* Note that the case of a symbol with indexNil must be handled
1886 anyways by parse_symbol(). */
1887 parse_symbol (&es
->asym
, ax
, (char *) NULL
, bigend
);
1894 /* Parse the line number info for file descriptor FH into
1895 GDB's linetable LT. MIPS' encoding requires a little bit
1896 of magic to get things out. Note also that MIPS' line
1897 numbers can go back and forth, apparently we can live
1898 with that and do not need to reorder our linetables */
1901 parse_lines (fh
, pr
, lt
, maxlines
)
1904 struct linetable
*lt
;
1907 unsigned char *base
;
1909 int delta
, count
, lineno
= 0;
1910 unsigned long first_off
= pr
->adr
;
1912 if (fh
->cbLine
== 0)
1915 base
= debug_info
->line
+ fh
->cbLineOffset
;
1917 /* Scan by procedure descriptors */
1919 for (j
= 0; j
< fh
->cpd
; j
++, pr
++)
1923 unsigned char *halt
;
1925 /* No code for this one */
1926 if (pr
->iline
== ilineNil
||
1927 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1930 /* Determine start and end address of compressed line bytes for
1932 base
= debug_info
->line
+ fh
->cbLineOffset
;
1933 if (j
!= (fh
->cpd
- 1))
1934 halt
= base
+ pr
[1].cbLineOffset
;
1936 halt
= base
+ fh
->cbLine
;
1937 base
+= pr
->cbLineOffset
;
1939 adr
= fh
->adr
+ pr
->adr
- first_off
;
1940 l
= adr
>> 2; /* in words */
1941 for (lineno
= pr
->lnLow
; base
< halt
; )
1943 count
= *base
& 0x0f;
1944 delta
= *base
++ >> 4;
1949 delta
= (base
[0] << 8) | base
[1];
1950 if (delta
>= 0x8000)
1954 lineno
+= delta
; /* first delta is 0 */
1956 /* Complain if the line table overflows. Could happen
1957 with corrupt binaries. */
1958 if (lt
->nitems
>= maxlines
)
1960 complain (&bad_linetable_guess_complaint
, fdr_name (fh
));
1963 k
= add_line (lt
, lineno
, l
, k
);
1969 /* Master parsing procedure for first-pass reading of file symbols
1970 into a partial_symtab. */
1973 parse_partial_symbols (objfile
, section_offsets
)
1974 struct objfile
*objfile
;
1975 struct section_offsets
*section_offsets
;
1977 const bfd_size_type external_sym_size
= debug_swap
->external_sym_size
;
1978 const bfd_size_type external_rfd_size
= debug_swap
->external_rfd_size
;
1979 const bfd_size_type external_ext_size
= debug_swap
->external_ext_size
;
1980 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
1981 = debug_swap
->swap_ext_in
;
1982 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
1983 = debug_swap
->swap_sym_in
;
1984 void (* const swap_rfd_in
) PARAMS ((bfd
*, PTR
, RFDT
*))
1985 = debug_swap
->swap_rfd_in
;
1987 HDRR
*hdr
= &debug_info
->symbolic_header
;
1988 /* Running pointers */
1993 register EXTR
*ext_in
;
1996 struct partial_symtab
*pst
;
1998 int past_first_source_file
= 0;
2000 /* List of current psymtab's include files */
2001 char **psymtab_include_list
;
2002 int includes_allocated
;
2005 struct pst_map
*fdr_to_pst
;
2006 /* Index within current psymtab dependency list */
2007 struct partial_symtab
**dependency_list
;
2008 int dependencies_used
, dependencies_allocated
;
2009 struct cleanup
*old_chain
;
2011 enum language prev_language
;
2013 extern_tab
= (EXTR
*) obstack_alloc (&objfile
->psymbol_obstack
,
2014 sizeof (EXTR
) * hdr
->iextMax
);
2016 includes_allocated
= 30;
2018 psymtab_include_list
= (char **) alloca (includes_allocated
*
2020 next_symbol_text_func
= mdebug_next_symbol_text
;
2022 dependencies_allocated
= 30;
2023 dependencies_used
= 0;
2025 (struct partial_symtab
**) alloca (dependencies_allocated
*
2026 sizeof (struct partial_symtab
*));
2028 last_source_file
= NULL
;
2033 * Only parse the Local and External symbols, and the Relative FDR.
2034 * Fixup enough of the loader symtab to be able to use it.
2035 * Allocate space only for the file's portions we need to
2040 max_glevel
= MIN_GLEVEL
;
2042 /* Allocate the map FDR -> PST.
2043 Minor hack: -O3 images might claim some global data belongs
2044 to FDR -1. We`ll go along with that */
2045 fdr_to_pst
= (struct pst_map
*) xzalloc ((hdr
->ifdMax
+ 1) * sizeof *fdr_to_pst
);
2046 old_chain
= make_cleanup (free
, fdr_to_pst
);
2049 struct partial_symtab
*pst
= new_psymtab ("", objfile
);
2050 fdr_to_pst
[-1].pst
= pst
;
2054 /* Allocate the global pending list. */
2056 ((struct mdebug_pending
**)
2057 obstack_alloc (&objfile
->psymbol_obstack
,
2058 hdr
->ifdMax
* sizeof (struct mdebug_pending
*)));
2059 memset ((PTR
) pending_list
, 0,
2060 hdr
->ifdMax
* sizeof (struct mdebug_pending
*));
2062 /* Pass 0 over external syms: swap them in. */
2063 ext_block
= (EXTR
*) xmalloc (hdr
->iextMax
* sizeof (EXTR
));
2064 make_cleanup (free
, ext_block
);
2066 ext_out
= (char *) debug_info
->external_ext
;
2067 ext_out_end
= ext_out
+ hdr
->iextMax
* external_ext_size
;
2069 for (; ext_out
< ext_out_end
; ext_out
+= external_ext_size
, ext_in
++)
2070 (*swap_ext_in
) (cur_bfd
, ext_out
, ext_in
);
2072 /* Pass 1 over external syms: Presize and partition the list */
2074 ext_in_end
= ext_in
+ hdr
->iextMax
;
2075 for (; ext_in
< ext_in_end
; ext_in
++)
2077 /* See calls to complain below. */
2078 if (ext_in
->ifd
>= -1
2079 && ext_in
->ifd
< hdr
->ifdMax
2080 && ext_in
->asym
.iss
>= 0
2081 && ext_in
->asym
.iss
< hdr
->issExtMax
)
2082 fdr_to_pst
[ext_in
->ifd
].n_globals
++;
2085 /* Pass 1.5 over files: partition out global symbol space */
2087 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++)
2089 fdr_to_pst
[f_idx
].globals_offset
= s_idx
;
2090 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
2091 fdr_to_pst
[f_idx
].n_globals
= 0;
2094 /* Pass 2 over external syms: fill in external symbols */
2096 ext_in_end
= ext_in
+ hdr
->iextMax
;
2097 for (; ext_in
< ext_in_end
; ext_in
++)
2099 enum minimal_symbol_type ms_type
= mst_text
;
2101 /* The Irix 5 native tools seem to sometimes generate bogus
2102 external symbols. */
2103 if (ext_in
->ifd
< -1 || ext_in
->ifd
>= hdr
->ifdMax
)
2105 complain (&bad_ext_ifd_complaint
, ext_in
->ifd
, hdr
->ifdMax
);
2108 if (ext_in
->asym
.iss
< 0 || ext_in
->asym
.iss
>= hdr
->issExtMax
)
2110 complain (&bad_ext_iss_complaint
, ext_in
->asym
.iss
,
2115 extern_tab
[fdr_to_pst
[ext_in
->ifd
].globals_offset
2116 + fdr_to_pst
[ext_in
->ifd
].n_globals
++] = *ext_in
;
2118 if (ext_in
->asym
.sc
== scUndefined
|| ext_in
->asym
.sc
== scNil
)
2121 name
= debug_info
->ssext
+ ext_in
->asym
.iss
;
2122 switch (ext_in
->asym
.st
)
2127 ms_type
= mst_file_text
;
2130 if (ext_in
->asym
.sc
== scData
2131 || ext_in
->asym
.sc
== scSData
2132 || ext_in
->asym
.sc
== scRData
)
2138 if (ext_in
->asym
.sc
== scAbs
)
2140 else if (ext_in
->asym
.sc
== scText
)
2142 else if (ext_in
->asym
.sc
== scData
2143 || ext_in
->asym
.sc
== scSData
2144 || ext_in
->asym
.sc
== scRData
)
2150 /* The alpha has the section start addresses in stLocal symbols
2151 whose name starts with a `.'. Skip those but complain for all
2152 other stLocal symbols. */
2157 ms_type
= mst_unknown
;
2158 complain (&unknown_ext_complaint
, name
);
2160 prim_record_minimal_symbol (name
, ext_in
->asym
.value
, ms_type
);
2163 /* Pass 3 over files, over local syms: fill in static symbols */
2164 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++)
2166 struct partial_symtab
*save_pst
;
2169 cur_fdr
= fh
= debug_info
->fdr
+ f_idx
;
2173 fdr_to_pst
[f_idx
].pst
= NULL
;
2176 pst
= start_psymtab_common (objfile
, section_offsets
,
2178 fh
->cpd
? fh
->adr
: 0,
2179 objfile
->global_psymbols
.next
,
2180 objfile
->static_psymbols
.next
);
2181 pst
->read_symtab_private
= ((char *)
2182 obstack_alloc (&objfile
->psymbol_obstack
,
2183 sizeof (struct symloc
)));
2184 memset ((PTR
) pst
->read_symtab_private
, 0, sizeof (struct symloc
));
2187 FDR_IDX (pst
) = f_idx
;
2188 CUR_BFD (pst
) = cur_bfd
;
2189 DEBUG_SWAP (pst
) = debug_swap
;
2190 DEBUG_INFO (pst
) = debug_info
;
2191 PENDING_LIST (pst
) = pending_list
;
2193 /* The way to turn this into a symtab is to call... */
2194 pst
->read_symtab
= mdebug_psymtab_to_symtab
;
2196 /* Set up language for the pst.
2197 The language from the FDR is used if it is unambigious (e.g. cfront
2198 with native cc and g++ will set the language to C).
2199 Otherwise we have to deduce the language from the filename.
2200 Native ecoff has every header file in a separate FDR, so
2201 deduce_language_from_filename will return language_unknown for
2202 a header file, which is not what we want.
2203 But the FDRs for the header files are after the FDR for the source
2204 file, so we can assign the language of the source file to the
2205 following header files. Then we save the language in the private
2206 pst data so that we can reuse it when building symtabs. */
2207 prev_language
= psymtab_language
;
2211 case langCplusplusV2
:
2212 psymtab_language
= language_cplus
;
2215 psymtab_language
= deduce_language_from_filename (fdr_name (fh
));
2218 if (psymtab_language
== language_unknown
)
2219 psymtab_language
= prev_language
;
2220 PST_PRIVATE (pst
)->pst_language
= psymtab_language
;
2222 pst
->texthigh
= pst
->textlow
;
2224 /* For stabs-in-ecoff files, the second symbol must be @stab.
2225 This symbol is emitted by mips-tfile to signal that the
2226 current object file uses encapsulated stabs instead of mips
2227 ecoff for local symbols. (It is the second symbol because
2228 the first symbol is the stFile used to signal the start of a
2230 processing_gcc_compilation
= 0;
2233 (*swap_sym_in
) (cur_bfd
,
2234 ((char *) debug_info
->external_sym
2235 + (fh
->isymBase
+ 1) * external_sym_size
),
2237 if (STREQ (debug_info
->ss
+ fh
->issBase
+ sh
.iss
, stabs_symbol
))
2238 processing_gcc_compilation
= 2;
2241 if (processing_gcc_compilation
!= 0)
2243 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++)
2248 (*swap_sym_in
) (cur_bfd
,
2249 (((char *) debug_info
->external_sym
)
2250 + (fh
->isymBase
+ cur_sdx
) * external_sym_size
),
2252 type_code
= ECOFF_UNMARK_STAB (sh
.index
);
2253 if (!ECOFF_IS_STAB (&sh
))
2255 if (sh
.st
== stProc
|| sh
.st
== stStaticProc
)
2257 long procaddr
= sh
.value
;
2261 isym
= AUX_GET_ISYM (fh
->fBigendian
,
2262 (debug_info
->external_aux
2265 (*swap_sym_in
) (cur_bfd
,
2266 ((char *) debug_info
->external_sym
2267 + ((fh
->isymBase
+ isym
- 1)
2268 * external_sym_size
)),
2272 long high
= procaddr
+ sh
.value
;
2273 if (high
> pst
->texthigh
)
2274 pst
->texthigh
= high
;
2279 #define SET_NAMESTRING() \
2280 namestring = debug_info->ss + fh->issBase + sh.iss
2281 #define CUR_SYMBOL_TYPE type_code
2282 #define CUR_SYMBOL_VALUE sh.value
2283 #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms)\
2285 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
2286 #define HANDLE_RBRAC(val) \
2287 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
2288 #include "partial-stab.h"
2293 for (cur_sdx
= 0; cur_sdx
< fh
->csym
;)
2296 enum address_class
class;
2298 (*swap_sym_in
) (cur_bfd
,
2299 ((char *) debug_info
->external_sym
2300 + ((fh
->isymBase
+ cur_sdx
)
2301 * external_sym_size
)),
2304 if (ECOFF_IS_STAB (&sh
))
2310 /* Non absolute static symbols go into the minimal table. */
2311 if (sh
.sc
== scUndefined
|| sh
.sc
== scNil
2312 || (sh
.index
== indexNil
2313 && (sh
.st
!= stStatic
|| sh
.sc
== scAbs
)))
2315 /* FIXME, premature? */
2320 name
= debug_info
->ss
+ fh
->issBase
+ sh
.iss
;
2328 case stStaticProc
: /* Function */
2329 /* I believe this is used only for file-local functions.
2330 The comment in symconst.h ("load time only static procs")
2331 isn't particularly clear on this point. */
2332 prim_record_minimal_symbol (name
, sh
.value
, mst_file_text
);
2335 case stProc
: /* Asm labels apparently */
2336 ADD_PSYMBOL_TO_LIST (name
, strlen (name
),
2337 VAR_NAMESPACE
, LOC_BLOCK
,
2338 objfile
->static_psymbols
, sh
.value
,
2339 psymtab_language
, objfile
);
2340 /* Skip over procedure to next one. */
2341 if (sh
.index
>= hdr
->iauxMax
)
2343 /* Should not happen, but does when cross-compiling
2344 with the MIPS compiler. FIXME -- pull later. */
2345 complain (&index_complaint
, name
);
2346 new_sdx
= cur_sdx
+ 1; /* Don't skip at all */
2349 new_sdx
= AUX_GET_ISYM (fh
->fBigendian
,
2350 (debug_info
->external_aux
2353 procaddr
= sh
.value
;
2355 if (new_sdx
<= cur_sdx
)
2357 /* This should not happen either... FIXME. */
2358 complain (&aux_index_complaint
, name
);
2359 new_sdx
= cur_sdx
+ 1; /* Don't skip backward */
2363 (*swap_sym_in
) (cur_bfd
,
2364 ((char *) debug_info
->external_sym
2365 + ((fh
->isymBase
+ cur_sdx
- 1)
2366 * external_sym_size
)),
2370 high
= procaddr
+ sh
.value
;
2371 if (high
> pst
->texthigh
)
2372 pst
->texthigh
= high
;
2375 case stStatic
: /* Variable */
2376 if (sh
.sc
== scData
|| sh
.sc
== scSData
|| sh
.sc
== scRData
)
2377 prim_record_minimal_symbol (name
, sh
.value
, mst_file_data
);
2379 prim_record_minimal_symbol (name
, sh
.value
, mst_file_bss
);
2383 case stTypedef
:/* Typedef */
2384 /* Skip typedefs for forward declarations and opaque
2385 structs from alpha cc. */
2388 class = LOC_TYPEDEF
;
2391 case stConstant
: /* Constant decl */
2398 case stBlock
: /* { }, str, un, enum*/
2399 /* Do not create a partial symbol for cc unnamed aggregates
2400 and gcc empty aggregates. */
2401 if ((sh
.sc
== scInfo
|| sh
.sc
== scCommon
)
2403 && sh
.index
!= cur_sdx
+ 2)
2405 ADD_PSYMBOL_TO_LIST (name
, strlen (name
),
2406 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2407 objfile
->static_psymbols
,
2409 psymtab_language
, objfile
);
2411 /* Skip over the block */
2413 if (new_sdx
<= cur_sdx
)
2415 /* This happens with the Ultrix kernel. */
2416 complain (&block_index_complaint
, name
);
2417 new_sdx
= cur_sdx
+ 1; /* Don't skip backward */
2422 case stFile
: /* File headers */
2423 case stLabel
: /* Labels */
2424 case stEnd
: /* Ends of files */
2427 case stLocal
: /* Local variables */
2428 /* Normally these are skipped because we skip over
2429 all blocks we see. However, these can occur
2430 as visible symbols in a .h file that contains code. */
2434 /* Both complaints are valid: one gives symbol name,
2435 the other the offending symbol type. */
2436 complain (&unknown_sym_complaint
, name
);
2437 complain (&unknown_st_complaint
, sh
.st
);
2441 /* Use this gdb symbol */
2442 ADD_PSYMBOL_TO_LIST (name
, strlen (name
),
2443 VAR_NAMESPACE
, class,
2444 objfile
->static_psymbols
, sh
.value
,
2445 psymtab_language
, objfile
);
2447 cur_sdx
++; /* Go to next file symbol */
2450 /* Now do enter the external symbols. */
2451 ext_ptr
= &extern_tab
[fdr_to_pst
[f_idx
].globals_offset
];
2452 cur_sdx
= fdr_to_pst
[f_idx
].n_globals
;
2453 PST_PRIVATE (save_pst
)->extern_count
= cur_sdx
;
2454 PST_PRIVATE (save_pst
)->extern_tab
= ext_ptr
;
2455 for (; --cur_sdx
>= 0; ext_ptr
++)
2457 enum address_class
class;
2461 if (ext_ptr
->ifd
!= f_idx
)
2463 psh
= &ext_ptr
->asym
;
2465 /* Do not add undefined symbols to the partial symbol table. */
2466 if (psh
->sc
== scUndefined
|| psh
->sc
== scNil
)
2472 /* These are generated for static symbols in .o files,
2483 complain (&unknown_ext_complaint
,
2484 debug_info
->ssext
+ psh
->iss
);
2485 /* Fall through, pretend it's global. */
2490 name
= debug_info
->ssext
+ psh
->iss
;
2491 ADD_PSYMBOL_ADDR_TO_LIST (name
, strlen (name
),
2492 VAR_NAMESPACE
, class,
2493 objfile
->global_psymbols
,
2494 (CORE_ADDR
) psh
->value
,
2495 psymtab_language
, objfile
);
2499 /* Link pst to FDR. end_psymtab returns NULL if the psymtab was
2500 empty and put on the free list. */
2501 fdr_to_pst
[f_idx
].pst
= end_psymtab (save_pst
,
2502 psymtab_include_list
, includes_used
,
2503 -1, save_pst
->texthigh
,
2504 dependency_list
, dependencies_used
);
2505 if (objfile
->ei
.entry_point
>= save_pst
->textlow
&&
2506 objfile
->ei
.entry_point
< save_pst
->texthigh
)
2508 objfile
->ei
.entry_file_lowpc
= save_pst
->textlow
;
2509 objfile
->ei
.entry_file_highpc
= save_pst
->texthigh
;
2513 /* Now scan the FDRs for dependencies */
2514 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++)
2516 fh
= f_idx
+ debug_info
->fdr
;
2517 pst
= fdr_to_pst
[f_idx
].pst
;
2519 if (pst
== (struct partial_symtab
*)NULL
)
2522 /* This should catch stabs-in-ecoff. */
2526 /* Skip the first file indirect entry as it is a self dependency
2527 for source files or a reverse .h -> .c dependency for header files. */
2528 pst
->number_of_dependencies
= 0;
2530 ((struct partial_symtab
**)
2531 obstack_alloc (&objfile
->psymbol_obstack
,
2533 * sizeof (struct partial_symtab
*))));
2534 for (s_idx
= 1; s_idx
< fh
->crfd
; s_idx
++)
2538 (*swap_rfd_in
) (cur_bfd
,
2539 ((char *) debug_info
->external_rfd
2540 + (fh
->rfdBase
+ s_idx
) * external_rfd_size
),
2542 if (rh
< 0 || rh
>= hdr
->ifdMax
)
2544 complain (&bad_file_number_complaint
, rh
);
2548 /* Skip self dependencies of header files. */
2552 /* Do not add to dependeny list if psymtab was empty. */
2553 if (fdr_to_pst
[rh
].pst
== (struct partial_symtab
*)NULL
)
2555 pst
->dependencies
[pst
->number_of_dependencies
++] = fdr_to_pst
[rh
].pst
;
2558 do_cleanups (old_chain
);
2563 mdebug_next_symbol_text ()
2568 (*debug_swap
->swap_sym_in
) (cur_bfd
,
2569 ((char *) debug_info
->external_sym
2570 + ((cur_fdr
->isymBase
+ cur_sdx
)
2571 * debug_swap
->external_sym_size
)),
2573 return debug_info
->ss
+ cur_fdr
->issBase
+ sh
.iss
;
2576 /* Ancillary function to psymtab_to_symtab(). Does all the work
2577 for turning the partial symtab PST into a symtab, recurring
2578 first on all dependent psymtabs. The argument FILENAME is
2579 only passed so we can see in debug stack traces what file
2582 This function has a split personality, based on whether the
2583 symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
2584 The flow of control and even the memory allocation differs. FIXME. */
2587 psymtab_to_symtab_1 (pst
, filename
)
2588 struct partial_symtab
*pst
;
2591 bfd_size_type external_sym_size
;
2592 bfd_size_type external_pdr_size
;
2593 void (*swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*));
2594 void (*swap_pdr_in
) PARAMS ((bfd
*, PTR
, PDR
*));
2598 struct linetable
*lines
;
2604 /* Read in all partial symbtabs on which this one is dependent.
2605 NOTE that we do have circular dependencies, sigh. We solved
2606 that by setting pst->readin before this point. */
2608 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2609 if (!pst
->dependencies
[i
]->readin
)
2611 /* Inform about additional files to be read in. */
2614 fputs_filtered (" ", gdb_stdout
);
2616 fputs_filtered ("and ", gdb_stdout
);
2618 printf_filtered ("%s...",
2619 pst
->dependencies
[i
]->filename
);
2620 wrap_here (""); /* Flush output */
2621 gdb_flush (gdb_stdout
);
2623 /* We only pass the filename for debug purposes */
2624 psymtab_to_symtab_1 (pst
->dependencies
[i
],
2625 pst
->dependencies
[i
]->filename
);
2628 /* Do nothing if this is a dummy psymtab. */
2630 if (pst
->n_global_syms
== 0 && pst
->n_static_syms
== 0
2631 && pst
->textlow
== 0 && pst
->texthigh
== 0)
2634 /* Now read the symbols for this symtab */
2636 cur_bfd
= CUR_BFD (pst
);
2637 debug_swap
= DEBUG_SWAP (pst
);
2638 debug_info
= DEBUG_INFO (pst
);
2639 pending_list
= PENDING_LIST (pst
);
2640 external_sym_size
= debug_swap
->external_sym_size
;
2641 external_pdr_size
= debug_swap
->external_pdr_size
;
2642 swap_sym_in
= debug_swap
->swap_sym_in
;
2643 swap_pdr_in
= debug_swap
->swap_pdr_in
;
2644 current_objfile
= pst
->objfile
;
2645 cur_fd
= FDR_IDX (pst
);
2646 fh
= ((cur_fd
== -1)
2648 : debug_info
->fdr
+ cur_fd
);
2651 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2652 processing_gcc_compilation
= 0;
2653 if (fh
!= (FDR
*) NULL
&& fh
->csym
>= 2)
2657 (*swap_sym_in
) (cur_bfd
,
2658 ((char *) debug_info
->external_sym
2659 + (fh
->isymBase
+ 1) * external_sym_size
),
2661 if (STREQ (debug_info
->ss
+ fh
->issBase
+ sh
.iss
,
2664 /* We indicate that this is a GCC compilation so that certain
2665 features will be enabled in stabsread/dbxread. */
2666 processing_gcc_compilation
= 2;
2670 if (processing_gcc_compilation
!= 0)
2675 unsigned long first_off
= 0;
2677 /* This symbol table contains stabs-in-ecoff entries. */
2679 /* Parse local symbols first */
2681 if (fh
->csym
<= 2) /* FIXME, this blows psymtab->symtab ptr */
2683 current_objfile
= NULL
;
2686 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++)
2692 (*swap_sym_in
) (cur_bfd
,
2693 (((char *) debug_info
->external_sym
)
2694 + (fh
->isymBase
+ cur_sdx
) * external_sym_size
),
2696 name
= debug_info
->ss
+ fh
->issBase
+ sh
.iss
;
2698 if (ECOFF_IS_STAB (&sh
))
2700 int type_code
= ECOFF_UNMARK_STAB (sh
.index
);
2701 process_one_symbol (type_code
, 0, valu
, name
,
2702 pst
->section_offsets
, pst
->objfile
);
2703 if (type_code
== N_FUN
)
2705 /* Make up special symbol to contain
2706 procedure specific info */
2707 struct mips_extra_func_info
*e
=
2708 ((struct mips_extra_func_info
*)
2709 obstack_alloc (¤t_objfile
->symbol_obstack
,
2710 sizeof (struct mips_extra_func_info
)));
2711 struct symbol
*s
= new_symbol (MIPS_EFI_SYMBOL_NAME
);
2712 SYMBOL_NAMESPACE (s
) = LABEL_NAMESPACE
;
2713 SYMBOL_CLASS (s
) = LOC_CONST
;
2714 SYMBOL_TYPE (s
) = builtin_type_void
;
2715 SYMBOL_VALUE (s
) = (long) e
;
2716 add_symbol_to_list (s
, &local_symbols
);
2719 else if (sh
.st
== stLabel
&& sh
.index
!= indexNil
)
2721 /* Handle encoded stab line number. */
2722 record_line (current_subfile
, sh
.index
, valu
);
2724 else if (sh
.st
== stProc
|| sh
.st
== stStaticProc
|| sh
.st
== stEnd
)
2725 /* These are generated by gcc-2.x, do not complain */
2728 complain (&stab_unknown_complaint
, name
);
2730 st
= end_symtab (pst
->texthigh
, 0, 0, pst
->objfile
, SECT_OFF_TEXT
);
2733 /* Sort the symbol table now, we are done adding symbols to it.
2734 We must do this before parse_procedure calls lookup_symbol. */
2735 sort_symtab_syms (st
);
2737 /* This may not be necessary for stabs symtabs. FIXME. */
2740 /* Fill in procedure info next. */
2742 pdr_ptr
= ((char *) debug_info
->external_pdr
2743 + fh
->ipdFirst
* external_pdr_size
);
2744 pdr_end
= pdr_ptr
+ fh
->cpd
* external_pdr_size
;
2745 for (; pdr_ptr
< pdr_end
; pdr_ptr
+= external_pdr_size
)
2749 (*swap_pdr_in
) (cur_bfd
, pdr_ptr
, &pr
);
2755 parse_procedure (&pr
, st
, first_off
);
2760 /* This symbol table contains ordinary ecoff entries. */
2762 /* FIXME: doesn't use pst->section_offsets. */
2768 /* How many symbols will we need */
2769 /* FIXME, this does not count enum values. */
2770 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
2774 st
= new_symtab ("unknown", f_max
, 0, pst
->objfile
);
2778 f_max
+= fh
->csym
+ fh
->cpd
;
2779 maxlines
= 2 * fh
->cline
;
2780 st
= new_symtab (pst
->filename
, 2 * f_max
, maxlines
, pst
->objfile
);
2782 /* The proper language was already determined when building
2783 the psymtab, use it. */
2784 st
->language
= PST_PRIVATE (pst
)->pst_language
;
2787 psymtab_language
= st
->language
;
2789 lines
= LINETABLE (st
);
2791 /* Get a new lexical context */
2793 push_parse_stack ();
2794 top_stack
->cur_st
= st
;
2795 top_stack
->cur_block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (st
),
2797 BLOCK_START (top_stack
->cur_block
) = fh
? fh
->adr
: 0;
2798 BLOCK_END (top_stack
->cur_block
) = 0;
2799 top_stack
->blocktype
= stFile
;
2800 top_stack
->maxsyms
= 2 * f_max
;
2801 top_stack
->cur_type
= 0;
2802 top_stack
->procadr
= 0;
2803 top_stack
->numargs
= 0;
2810 /* Parse local symbols first */
2811 sym_ptr
= ((char *) debug_info
->external_sym
2812 + fh
->isymBase
* external_sym_size
);
2813 sym_end
= sym_ptr
+ fh
->csym
* external_sym_size
;
2814 while (sym_ptr
< sym_end
)
2819 (*swap_sym_in
) (cur_bfd
, sym_ptr
, &sh
);
2820 c
= parse_symbol (&sh
,
2821 debug_info
->external_aux
+ fh
->iauxBase
,
2822 sym_ptr
, fh
->fBigendian
);
2823 sym_ptr
+= c
* external_sym_size
;
2826 /* Linenumbers. At the end, check if we can save memory.
2827 parse_lines has to look ahead an arbitrary number of PDR
2828 structures, so we swap them all first. */
2832 struct cleanup
*old_chain
;
2838 pr_block
= (PDR
*) xmalloc (fh
->cpd
* sizeof (PDR
));
2840 old_chain
= make_cleanup (free
, pr_block
);
2842 pdr_ptr
= ((char *) debug_info
->external_pdr
2843 + fh
->ipdFirst
* external_pdr_size
);
2844 pdr_end
= pdr_ptr
+ fh
->cpd
* external_pdr_size
;
2848 pdr_ptr
+= external_pdr_size
, pdr_in
++)
2849 (*swap_pdr_in
) (cur_bfd
, pdr_ptr
, pdr_in
);
2851 parse_lines (fh
, pr_block
, lines
, maxlines
);
2852 if (lines
->nitems
< fh
->cline
)
2853 lines
= shrink_linetable (lines
);
2855 /* Fill in procedure info next. */
2857 pdr_in_end
= pdr_in
+ fh
->cpd
;
2858 for (; pdr_in
< pdr_in_end
; pdr_in
++)
2859 parse_procedure (pdr_in
, 0, pr_block
->adr
);
2861 do_cleanups (old_chain
);
2865 LINETABLE (st
) = lines
;
2867 /* .. and our share of externals.
2868 XXX use the global list to speed up things here. how?
2869 FIXME, Maybe quit once we have found the right number of ext's? */
2870 top_stack
->cur_st
= st
;
2871 top_stack
->cur_block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack
->cur_st
),
2873 top_stack
->blocktype
= stFile
;
2875 = (debug_info
->symbolic_header
.isymMax
2876 + debug_info
->symbolic_header
.ipdMax
2877 + debug_info
->symbolic_header
.iextMax
);
2879 ext_ptr
= PST_PRIVATE (pst
)->extern_tab
;
2880 for (i
= PST_PRIVATE (pst
)->extern_count
; --i
>= 0; ext_ptr
++)
2881 parse_external (ext_ptr
, 1, fh
->fBigendian
);
2883 /* If there are undefined symbols, tell the user.
2884 The alpha has an undefined symbol for every symbol that is
2885 from a shared library, so tell the user only if verbose is on. */
2886 if (info_verbose
&& n_undef_symbols
)
2888 printf_filtered ("File %s contains %d unresolved references:",
2889 st
->filename
, n_undef_symbols
);
2890 printf_filtered ("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2891 n_undef_vars
, n_undef_procs
, n_undef_labels
);
2892 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
2897 /* Sort the symbol table now, we are done adding symbols to it.*/
2898 sort_symtab_syms (st
);
2903 /* Now link the psymtab and the symtab. */
2906 current_objfile
= NULL
;
2909 /* Ancillary parsing procedures. */
2911 /* Lookup the type at relative index RN. Return it in TPP
2912 if found and in any event come up with its name PNAME.
2913 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
2914 Return value says how many aux symbols we ate. */
2917 cross_ref (fd
, ax
, tpp
, type_code
, pname
, bigend
, sym_name
)
2921 enum type_code type_code
; /* Use to alloc new type if none is found. */
2933 struct mdebug_pending
*pend
;
2935 *tpp
= (struct type
*)NULL
;
2937 ecoff_swap_rndx_in (bigend
, &ax
->a_rndx
, rn
);
2939 /* Escape index means 'the next one' */
2940 if (rn
->rfd
== 0xfff)
2943 rf
= AUX_GET_ISYM (bigend
, ax
+ 1);
2950 /* mips cc uses a rf of -1 for opaque struct definitions.
2951 Set TYPE_FLAG_STUB for these types so that check_stub_type will
2952 resolve them if the struct gets defined in another compilation unit. */
2955 *pname
= "<undefined>";
2956 *tpp
= init_type (type_code
, 0, 0, (char *) NULL
, current_objfile
);
2957 TYPE_FLAGS (*tpp
) |= TYPE_FLAG_STUB
;
2961 /* mips cc uses an escaped rn->index of 0 for struct return types
2962 of procedures that were compiled without -g. These will always remain
2964 if (rn
->rfd
== 0xfff && rn
->index
== 0)
2966 *pname
= "<undefined>";
2970 /* Find the relative file descriptor and the symbol in it. */
2971 fh
= get_rfd (fd
, rf
);
2972 xref_fd
= fh
- debug_info
->fdr
;
2974 if (rn
->index
>= fh
->csym
)
2976 /* File indirect entry is corrupt. */
2977 *pname
= "<illegal>";
2978 complain (&bad_rfd_entry_complaint
,
2979 sym_name
, xref_fd
, rn
->index
);
2983 /* If we have processed this symbol then we left a forwarding
2984 pointer to the type in the pending list. If not, we`ll put
2985 it in a list of pending types, to be processed later when
2986 the file will be. In any event, we collect the name for the
2989 esh
= ((char *) debug_info
->external_sym
2990 + ((fh
->isymBase
+ rn
->index
)
2991 * debug_swap
->external_sym_size
));
2992 (*debug_swap
->swap_sym_in
) (cur_bfd
, esh
, &sh
);
2994 /* Make sure that this type of cross reference can be handled. */
2996 || (sh
.st
!= stBlock
&& sh
.st
!= stTypedef
2997 && sh
.st
!= stStruct
&& sh
.st
!= stUnion
2998 && sh
.st
!= stEnum
))
3000 /* File indirect entry is corrupt. */
3001 *pname
= "<illegal>";
3002 complain (&bad_rfd_entry_complaint
,
3003 sym_name
, xref_fd
, rn
->index
);
3007 *pname
= debug_info
->ss
+ fh
->issBase
+ sh
.iss
;
3009 pend
= is_pending_symbol (fh
, esh
);
3014 /* We have not yet seen this type. */
3016 if (sh
.iss
== 0 && sh
.st
== stTypedef
)
3020 /* alpha cc puts out a stTypedef with a sh.iss of zero for
3022 a) forward declarations of structs/unions/enums which are not
3023 defined in this compilation unit.
3024 For these the type will be void. This is a bad design decision
3025 as cross referencing across compilation units is impossible
3026 due to the missing name.
3027 b) forward declarations of structs/unions/enums which are defined
3028 later in this file or in another file in the same compilation
3029 unit. Simply cross reference those again to get the
3031 The forward references are not entered in the pending list and
3032 in the symbol table. */
3034 ecoff_swap_tir_in (bigend
,
3035 &(debug_info
->external_aux
3036 + fh
->iauxBase
+ sh
.index
)->a_ti
,
3038 if (tir
.tq0
!= tqNil
)
3039 complain (&illegal_forward_tq0_complaint
, sym_name
);
3043 *tpp
= init_type (type_code
, 0, 0, (char *) NULL
,
3045 *pname
= "<undefined>";
3052 (debug_info
->external_aux
3053 + fh
->iauxBase
+ sh
.index
+ 1),
3054 tpp
, type_code
, pname
,
3055 fh
->fBigendian
, sym_name
);
3059 complain (&illegal_forward_bt_complaint
, tir
.bt
, sym_name
);
3060 *tpp
= init_type (type_code
, 0, 0, (char *) NULL
,
3066 else if (sh
.st
== stTypedef
)
3068 /* Parse the type for a normal typedef. This might recursively call
3069 cross_ref till we get a non typedef'ed type.
3070 FIXME: This is not correct behaviour, but gdb currently
3071 cannot handle typedefs without type copying. But type copying is
3072 impossible as we might have mutual forward references between
3073 two files and the copied type would not get filled in when
3074 we later parse its definition. */
3075 *tpp
= parse_type (xref_fd
,
3076 debug_info
->external_aux
+ fh
->iauxBase
,
3080 debug_info
->ss
+ fh
->issBase
+ sh
.iss
);
3084 /* Cross reference to a struct/union/enum which is defined
3085 in another file in the same compilation unit but that file
3086 has not been parsed yet.
3087 Initialize the type only, it will be filled in when
3088 it's definition is parsed. */
3089 *tpp
= init_type (type_code
, 0, 0, (char *) NULL
, current_objfile
);
3091 add_pending (fh
, esh
, *tpp
);
3094 /* We used one auxent normally, two if we got a "next one" rf. */
3099 /* Quick&dirty lookup procedure, to avoid the MI ones that require
3100 keeping the symtab sorted */
3102 static struct symbol
*
3103 mylookup_symbol (name
, block
, namespace, class)
3105 register struct block
*block
;
3106 enum namespace namespace;
3107 enum address_class
class;
3109 register int bot
, top
, inc
;
3110 register struct symbol
*sym
;
3113 top
= BLOCK_NSYMS (block
);
3117 sym
= BLOCK_SYM (block
, bot
);
3118 if (SYMBOL_NAME (sym
)[0] == inc
3119 && SYMBOL_NAMESPACE (sym
) == namespace
3120 && SYMBOL_CLASS (sym
) == class
3121 && strcmp (SYMBOL_NAME (sym
), name
) == 0)
3125 block
= BLOCK_SUPERBLOCK (block
);
3127 return mylookup_symbol (name
, block
, namespace, class);
3132 /* Add a new symbol S to a block B.
3133 Infrequently, we will need to reallocate the block to make it bigger.
3134 We only detect this case when adding to top_stack->cur_block, since
3135 that's the only time we know how big the block is. FIXME. */
3142 int nsyms
= BLOCK_NSYMS (b
)++;
3143 struct block
*origb
;
3144 struct parse_stack
*stackp
;
3146 if (b
== top_stack
->cur_block
&&
3147 nsyms
>= top_stack
->maxsyms
)
3149 complain (&block_overflow_complaint
, SYMBOL_NAME (s
));
3150 /* In this case shrink_block is actually grow_block, since
3151 BLOCK_NSYMS(b) is larger than its current size. */
3153 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
3155 /* Now run through the stack replacing pointers to the
3156 original block. shrink_block has already done this
3157 for the blockvector and BLOCK_FUNCTION. */
3158 for (stackp
= top_stack
; stackp
; stackp
= stackp
->next
)
3160 if (stackp
->cur_block
== origb
)
3162 stackp
->cur_block
= b
;
3163 stackp
->maxsyms
= BLOCK_NSYMS (b
);
3167 BLOCK_SYM (b
, nsyms
) = s
;
3170 /* Add a new block B to a symtab S */
3177 struct blockvector
*bv
= BLOCKVECTOR (s
);
3179 bv
= (struct blockvector
*) xrealloc ((PTR
) bv
,
3180 (sizeof (struct blockvector
)
3181 + BLOCKVECTOR_NBLOCKS (bv
)
3182 * sizeof (bv
->block
)));
3183 if (bv
!= BLOCKVECTOR (s
))
3184 BLOCKVECTOR (s
) = bv
;
3186 BLOCKVECTOR_BLOCK (bv
, BLOCKVECTOR_NBLOCKS (bv
)++) = b
;
3189 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
3190 MIPS' linenumber encoding might need more than one byte
3191 to describe it, LAST is used to detect these continuation lines.
3193 Combining lines with the same line number seems like a bad idea.
3194 E.g: There could be a line number entry with the same line number after the
3195 prologue and GDB should not ignore it (this is a better way to find
3196 a prologue than mips_skip_prologue).
3197 But due to the compressed line table format there are line number entries
3198 for the same line which are needed to bridge the gap to the next
3199 line number entry. These entries have a bogus address info with them
3200 and we are unable to tell them from intended duplicate line number
3202 This is another reason why -ggdb debugging format is preferable. */
3205 add_line (lt
, lineno
, adr
, last
)
3206 struct linetable
*lt
;
3212 last
= -2; /* make sure we record first line */
3214 if (last
== lineno
) /* skip continuation lines */
3217 lt
->item
[lt
->nitems
].line
= lineno
;
3218 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
3222 /* Sorting and reordering procedures */
3224 /* Blocks with a smaller low bound should come first */
3227 compare_blocks (arg1
, arg2
)
3231 register int addr_diff
;
3232 struct block
**b1
= (struct block
**) arg1
;
3233 struct block
**b2
= (struct block
**) arg2
;
3235 addr_diff
= (BLOCK_START ((*b1
))) - (BLOCK_START ((*b2
)));
3237 return (BLOCK_END ((*b2
))) - (BLOCK_END ((*b1
)));
3241 /* Sort the blocks of a symtab S.
3242 Reorder the blocks in the blockvector by code-address,
3243 as required by some MI search routines */
3249 struct blockvector
*bv
= BLOCKVECTOR (s
);
3251 if (BLOCKVECTOR_NBLOCKS (bv
) <= 2)
3254 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) == 0)
3255 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) = 0;
3256 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) == 0)
3257 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) = 0;
3261 * This is very unfortunate: normally all functions are compiled in
3262 * the order they are found, but if the file is compiled -O3 things
3263 * are very different. It would be nice to find a reliable test
3264 * to detect -O3 images in advance.
3266 if (BLOCKVECTOR_NBLOCKS (bv
) > 3)
3267 qsort (&BLOCKVECTOR_BLOCK (bv
, FIRST_LOCAL_BLOCK
),
3268 BLOCKVECTOR_NBLOCKS (bv
) - FIRST_LOCAL_BLOCK
,
3269 sizeof (struct block
*),
3273 register CORE_ADDR high
= 0;
3274 register int i
, j
= BLOCKVECTOR_NBLOCKS (bv
);
3276 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
3277 if (high
< BLOCK_END (BLOCKVECTOR_BLOCK (bv
, i
)))
3278 high
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, i
));
3279 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) = high
;
3282 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) =
3283 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, FIRST_LOCAL_BLOCK
));
3285 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) =
3286 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
3287 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) =
3288 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
3292 /* Constructor/restructor/destructor procedures */
3294 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
3295 MAXSYMS and linenumbers MAXLINES we'll put in it */
3297 static struct symtab
*
3298 new_symtab (name
, maxsyms
, maxlines
, objfile
)
3302 struct objfile
*objfile
;
3304 struct symtab
*s
= allocate_symtab (name
, objfile
);
3306 LINETABLE (s
) = new_linetable (maxlines
);
3308 /* All symtabs must have at least two blocks */
3309 BLOCKVECTOR (s
) = new_bvect (2);
3310 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
) = new_block (maxsyms
);
3311 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
) = new_block (maxsyms
);
3312 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)) =
3313 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3315 s
->free_code
= free_linetable
;
3320 /* Allocate a new partial_symtab NAME */
3322 static struct partial_symtab
*
3323 new_psymtab (name
, objfile
)
3325 struct objfile
*objfile
;
3327 struct partial_symtab
*psymtab
;
3329 psymtab
= allocate_psymtab (name
, objfile
);
3331 /* Keep a backpointer to the file's symbols */
3333 psymtab
->read_symtab_private
= ((char *)
3334 obstack_alloc (&objfile
->psymbol_obstack
,
3335 sizeof (struct symloc
)));
3336 memset ((PTR
) psymtab
->read_symtab_private
, 0, sizeof (struct symloc
));
3337 CUR_BFD (psymtab
) = cur_bfd
;
3338 DEBUG_SWAP (psymtab
) = debug_swap
;
3339 DEBUG_INFO (psymtab
) = debug_info
;
3340 PENDING_LIST (psymtab
) = pending_list
;
3342 /* The way to turn this into a symtab is to call... */
3343 psymtab
->read_symtab
= mdebug_psymtab_to_symtab
;
3348 /* Allocate a linetable array of the given SIZE. Since the struct
3349 already includes one item, we subtract one when calculating the
3350 proper size to allocate. */
3352 static struct linetable
*
3353 new_linetable (size
)
3356 struct linetable
*l
;
3358 size
= (size
- 1) * sizeof (l
->item
) + sizeof (struct linetable
);
3359 l
= (struct linetable
*) xmalloc (size
);
3364 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
3365 I am not so sure about the 3.4 ones.
3367 Since the struct linetable already includes one item, we subtract one when
3368 calculating the proper size to allocate. */
3370 static struct linetable
*
3371 shrink_linetable (lt
)
3372 struct linetable
*lt
;
3375 return (struct linetable
*) xrealloc ((PTR
) lt
,
3376 (sizeof (struct linetable
)
3378 * sizeof (lt
->item
))));
3381 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
3383 static struct blockvector
*
3387 struct blockvector
*bv
;
3390 size
= sizeof (struct blockvector
) + nblocks
* sizeof (struct block
*);
3391 bv
= (struct blockvector
*) xzalloc (size
);
3393 BLOCKVECTOR_NBLOCKS (bv
) = nblocks
;
3398 /* Allocate and zero a new block of MAXSYMS symbols */
3400 static struct block
*
3404 int size
= sizeof (struct block
) + (maxsyms
- 1) * sizeof (struct symbol
*);
3406 return (struct block
*) xzalloc (size
);
3409 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
3410 Shrink_block can also be used by add_symbol to grow a block. */
3412 static struct block
*
3418 struct blockvector
*bv
= BLOCKVECTOR (s
);
3421 /* Just reallocate it and fix references to the old one */
3423 new = (struct block
*) xrealloc ((PTR
) b
,
3424 (sizeof (struct block
)
3425 + ((BLOCK_NSYMS (b
) - 1)
3426 * sizeof (struct symbol
*))));
3428 /* Should chase pointers to old one. Fortunately, that`s just
3429 the block`s function and inferior blocks */
3430 if (BLOCK_FUNCTION (new) && SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) == b
)
3431 SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) = new;
3432 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS (bv
); i
++)
3433 if (BLOCKVECTOR_BLOCK (bv
, i
) == b
)
3434 BLOCKVECTOR_BLOCK (bv
, i
) = new;
3435 else if (BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv
, i
)) == b
)
3436 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv
, i
)) = new;
3440 /* Create a new symbol with printname NAME */
3442 static struct symbol
*
3446 struct symbol
*s
= ((struct symbol
*)
3447 obstack_alloc (¤t_objfile
->symbol_obstack
,
3448 sizeof (struct symbol
)));
3450 memset ((PTR
) s
, 0, sizeof (*s
));
3451 SYMBOL_NAME (s
) = name
;
3452 SYMBOL_LANGUAGE (s
) = psymtab_language
;
3453 SYMBOL_INIT_DEMANGLED_NAME (s
, ¤t_objfile
->symbol_obstack
);
3457 /* Create a new type with printname NAME */
3459 static struct type
*
3465 t
= alloc_type (current_objfile
);
3466 TYPE_NAME (t
) = name
;
3467 TYPE_CPLUS_SPECIFIC (t
) = (struct cplus_struct_type
*) &cplus_struct_default
;
3471 /* Read ECOFF debugging information from a BFD section. This is
3472 called from elfread.c. It parses the section into a
3473 ecoff_debug_info struct, and then lets the rest of the file handle
3477 elfmdebug_build_psymtabs (objfile
, swap
, sec
, section_offsets
)
3478 struct objfile
*objfile
;
3479 const struct ecoff_debug_swap
*swap
;
3481 struct section_offsets
*section_offsets
;
3483 bfd
*abfd
= objfile
->obfd
;
3485 struct ecoff_debug_info
*info
;
3487 buf
= alloca (swap
->external_hdr_size
);
3488 if (bfd_get_section_contents (abfd
, sec
, buf
, (file_ptr
) 0,
3489 swap
->external_hdr_size
) == false)
3490 perror_with_name (bfd_get_filename (abfd
));
3492 info
= ((struct ecoff_debug_info
*)
3493 obstack_alloc (&objfile
->psymbol_obstack
,
3494 sizeof (struct ecoff_debug_info
)));
3496 (*swap
->swap_hdr_in
) (abfd
, buf
, &info
->symbolic_header
);
3498 /* The offsets in symbolic_header are file offsets, not section
3499 offsets. Strangely, on Irix 5 the information is not entirely
3500 within the .mdebug section. There are parts of an executable
3501 file which are not within any ELF section at all. This means
3502 that we must read the information using bfd_read. */
3504 #define READ(ptr, count, off, size, type) \
3507 if (info->symbolic_header.count == 0) \
3508 info->ptr = (type) NULL; \
3511 info->ptr = ((type) \
3512 obstack_alloc (&objfile->psymbol_obstack, \
3513 (info->symbolic_header.count \
3515 if (bfd_seek (abfd, info->symbolic_header.off, SEEK_SET) < 0 \
3516 || (bfd_read ((PTR) info->ptr, size, \
3517 info->symbolic_header.count, abfd) \
3518 != info->symbolic_header.count * size)) \
3519 perror_with_name (bfd_get_filename (abfd)); \
3524 READ (line
, cbLine
, cbLineOffset
, sizeof (unsigned char), unsigned char *);
3525 READ (external_dnr
, idnMax
, cbDnOffset
, swap
->external_dnr_size
, PTR
);
3526 READ (external_pdr
, ipdMax
, cbPdOffset
, swap
->external_pdr_size
, PTR
);
3527 READ (external_sym
, isymMax
, cbSymOffset
, swap
->external_sym_size
, PTR
);
3528 READ (external_opt
, ioptMax
, cbOptOffset
, swap
->external_opt_size
, PTR
);
3529 READ (external_aux
, iauxMax
, cbAuxOffset
, sizeof (union aux_ext
),
3531 READ (ss
, issMax
, cbSsOffset
, sizeof (char), char *);
3532 READ (ssext
, issExtMax
, cbSsExtOffset
, sizeof (char), char *);
3533 READ (external_fdr
, ifdMax
, cbFdOffset
, swap
->external_fdr_size
, PTR
);
3534 READ (external_rfd
, crfd
, cbRfdOffset
, swap
->external_rfd_size
, PTR
);
3535 READ (external_ext
, iextMax
, cbExtOffset
, swap
->external_ext_size
, PTR
);
3541 mdebug_build_psymtabs (objfile
, swap
, info
, section_offsets
);
3545 /* Things used for calling functions in the inferior.
3546 These functions are exported to our companion
3547 mips-tdep.c file and are here because they play
3548 with the symbol-table explicitly. */
3550 /* Sigtramp: make sure we have all the necessary information
3551 about the signal trampoline code. Since the official code
3552 from MIPS does not do so, we make up that information ourselves.
3553 If they fix the library (unlikely) this code will neutralize itself. */
3555 /* FIXME: This function is called only by mips-tdep.c. It needs to be
3556 here because it calls functions defined in this file, but perhaps
3557 this could be handled in a better way. */
3564 struct block
*b
, *b0
= NULL
;
3566 sigtramp_address
= -1;
3568 /* We have to handle the following cases here:
3569 a) The Mips library has a sigtramp label within sigvec.
3570 b) Irix has a _sigtramp which we want to use, but it also has sigvec. */
3571 s
= lookup_symbol ("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
3574 b0
= SYMBOL_BLOCK_VALUE (s
);
3575 s
= lookup_symbol ("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
3579 /* No sigvec or no sigtramp inside sigvec, try _sigtramp. */
3580 s
= lookup_symbol ("_sigtramp", 0, VAR_NAMESPACE
, 0, NULL
);
3583 /* But maybe this program uses its own version of sigvec */
3587 /* Did we or MIPSco fix the library ? */
3588 if (SYMBOL_CLASS (s
) == LOC_BLOCK
)
3590 sigtramp_address
= BLOCK_START (SYMBOL_BLOCK_VALUE (s
));
3591 sigtramp_end
= BLOCK_END (SYMBOL_BLOCK_VALUE (s
));
3595 sigtramp_address
= SYMBOL_VALUE (s
);
3596 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
3598 /* But what symtab does it live in ? */
3599 st
= find_pc_symtab (SYMBOL_VALUE (s
));
3602 * Ok, there goes the fix: turn it into a procedure, with all the
3603 * needed info. Note we make it a nested procedure of sigvec,
3604 * which is the way the (assembly) code is actually written.
3606 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
3607 SYMBOL_CLASS (s
) = LOC_BLOCK
;
3608 SYMBOL_TYPE (s
) = init_type (TYPE_CODE_FUNC
, 4, 0, (char *) NULL
,
3610 TYPE_TARGET_TYPE (SYMBOL_TYPE (s
)) = builtin_type_void
;
3612 /* Need a block to allocate MIPS_EFI_SYMBOL_NAME in */
3614 SYMBOL_BLOCK_VALUE (s
) = b
;
3615 BLOCK_START (b
) = sigtramp_address
;
3616 BLOCK_END (b
) = sigtramp_end
;
3617 BLOCK_FUNCTION (b
) = s
;
3618 BLOCK_SUPERBLOCK (b
) = BLOCK_SUPERBLOCK (b0
);
3622 /* Make a MIPS_EFI_SYMBOL_NAME entry for it */
3624 struct mips_extra_func_info
*e
=
3625 ((struct mips_extra_func_info
*)
3626 xzalloc (sizeof (struct mips_extra_func_info
)));
3628 e
->numargs
= 0; /* the kernel thinks otherwise */
3629 /* align_longword(sigcontext + SIGFRAME) */
3630 e
->pdr
.frameoffset
= 0x150;
3631 e
->pdr
.framereg
= SP_REGNUM
;
3632 /* read_next_frame_reg provides the true pc at the time of signal */
3633 e
->pdr
.pcreg
= PC_REGNUM
;
3634 e
->pdr
.regmask
= -2;
3635 e
->pdr
.regoffset
= -(41 * sizeof (int));
3636 e
->pdr
.fregmask
= -1;
3637 e
->pdr
.fregoffset
= -(7 * sizeof (int));
3638 e
->pdr
.isym
= (long) s
;
3639 e
->pdr
.adr
= sigtramp_address
;
3641 current_objfile
= st
->objfile
; /* Keep new_symbol happy */
3642 s
= new_symbol (MIPS_EFI_SYMBOL_NAME
);
3643 SYMBOL_VALUE (s
) = (long) e
;
3644 SYMBOL_NAMESPACE (s
) = LABEL_NAMESPACE
;
3645 SYMBOL_CLASS (s
) = LOC_CONST
;
3646 SYMBOL_TYPE (s
) = builtin_type_void
;
3647 current_objfile
= NULL
;
3650 BLOCK_SYM (b
, BLOCK_NSYMS (b
)++) = s
;
3654 _initialize_mdebugread ()
3656 /* Missing basic types */
3658 builtin_type_string
=
3659 init_type (TYPE_CODE_STRING
,
3660 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3662 (struct objfile
*) NULL
);
3663 builtin_type_complex
=
3664 init_type (TYPE_CODE_FLT
,
3665 TARGET_COMPLEX_BIT
/ TARGET_CHAR_BIT
,
3667 (struct objfile
*) NULL
);
3668 builtin_type_double_complex
=
3669 init_type (TYPE_CODE_FLT
,
3670 TARGET_DOUBLE_COMPLEX_BIT
/ TARGET_CHAR_BIT
,
3671 0, "double complex",
3672 (struct objfile
*) NULL
);
3673 builtin_type_fixed_dec
=
3674 init_type (TYPE_CODE_INT
,
3675 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3677 (struct objfile
*) NULL
);
3678 builtin_type_float_dec
=
3679 init_type (TYPE_CODE_FLT
,
3680 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3681 0, "floating decimal",
3682 (struct objfile
*) NULL
);