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 /* Types corresponding to btComplex, btDComplex, etc. These are here
272 rather than in gdbtypes.c or some such, because the meaning of codes
273 like btComplex is specific to the mdebug debug format. FIXME: We should
274 be using our own types thoughout this file, instead of sometimes using
277 static struct type
*mdebug_type_complex
;
278 static struct type
*mdebug_type_double_complex
;
279 static struct type
*mdebug_type_fixed_dec
;
280 static struct type
*mdebug_type_float_dec
;
281 static struct type
*mdebug_type_string
;
283 /* Forward declarations */
286 upgrade_type
PARAMS ((int, struct type
**, int, union aux_ext
*, int, char *));
289 parse_partial_symbols
PARAMS ((struct objfile
*,
290 struct section_offsets
*));
293 *get_rfd
PARAMS ((int, int));
296 cross_ref
PARAMS ((int, union aux_ext
*, struct type
**, enum type_code
,
297 char **, int, char *));
299 static struct symbol
*
300 new_symbol
PARAMS ((char *));
303 new_type
PARAMS ((char *));
305 static struct block
*
306 new_block
PARAMS ((int));
308 static struct symtab
*
309 new_symtab
PARAMS ((char *, int, int, struct objfile
*));
311 static struct linetable
*
312 new_linetable
PARAMS ((int));
314 static struct blockvector
*
315 new_bvect
PARAMS ((int));
318 parse_symbol
PARAMS ((SYMR
*, union aux_ext
*, char *, int));
321 parse_type
PARAMS ((int, union aux_ext
*, unsigned int, int *, int, char *));
323 static struct symbol
*
324 mylookup_symbol
PARAMS ((char *, struct block
*, enum namespace,
325 enum address_class
));
327 static struct block
*
328 shrink_block
PARAMS ((struct block
*, struct symtab
*));
331 xzalloc
PARAMS ((unsigned int));
334 sort_blocks
PARAMS ((struct symtab
*));
337 compare_blocks
PARAMS ((const void *, const void *));
339 static struct partial_symtab
*
340 new_psymtab
PARAMS ((char *, struct objfile
*));
343 psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*, char *));
346 add_block
PARAMS ((struct block
*, struct symtab
*));
349 add_symbol
PARAMS ((struct symbol
*, struct block
*));
352 add_line
PARAMS ((struct linetable
*, int, CORE_ADDR
, int));
354 static struct linetable
*
355 shrink_linetable
PARAMS ((struct linetable
*));
358 mdebug_next_symbol_text
PARAMS ((void));
360 /* Address bounds for the signal trampoline in inferior, if any */
362 CORE_ADDR sigtramp_address
, sigtramp_end
;
364 /* Allocate zeroed memory */
370 PTR p
= xmalloc (size
);
376 /* Exported procedure: Builds a symtab from the PST partial one.
377 Restores the environment in effect when PST was created, delegates
378 most of the work to an ancillary procedure, and sorts
379 and reorders the symtab list at the end */
382 mdebug_psymtab_to_symtab (pst
)
383 struct partial_symtab
*pst
;
391 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
392 gdb_flush (gdb_stdout
);
395 next_symbol_text_func
= mdebug_next_symbol_text
;
397 psymtab_to_symtab_1 (pst
, pst
->filename
);
399 /* Match with global symbols. This only needs to be done once,
400 after all of the symtabs and dependencies have been read in. */
401 scan_file_globals (pst
->objfile
);
404 printf_filtered ("done.\n");
407 /* File-level interface functions */
409 /* Find a file descriptor given its index RF relative to a file CF */
419 fdrs
= debug_info
->fdr
;
421 /* Object files do not have the RFD table, all refs are absolute */
424 (*debug_swap
->swap_rfd_in
) (cur_bfd
,
425 ((char *) debug_info
->external_rfd
427 * debug_swap
->external_rfd_size
)),
432 /* Return a safer print NAME for a file descriptor */
439 return "<stripped file>";
442 return debug_info
->ss
+ f
->issBase
+ f
->rss
;
446 /* Read in and parse the symtab of the file OBJFILE. Symbols from
447 different sections are relocated via the SECTION_OFFSETS. */
450 mdebug_build_psymtabs (objfile
, swap
, info
, section_offsets
)
451 struct objfile
*objfile
;
452 const struct ecoff_debug_swap
*swap
;
453 struct ecoff_debug_info
*info
;
454 struct section_offsets
*section_offsets
;
456 cur_bfd
= objfile
->obfd
;
460 /* Make sure all the FDR information is swapped in. */
461 if (info
->fdr
== (FDR
*) NULL
)
467 info
->fdr
= (FDR
*) obstack_alloc (&objfile
->psymbol_obstack
,
468 (info
->symbolic_header
.ifdMax
470 fdr_src
= info
->external_fdr
;
472 + info
->symbolic_header
.ifdMax
* swap
->external_fdr_size
);
474 for (; fdr_src
< fdr_end
; fdr_src
+= swap
->external_fdr_size
, fdr_ptr
++)
475 (*swap
->swap_fdr_in
) (objfile
->obfd
, fdr_src
, fdr_ptr
);
478 parse_partial_symbols (objfile
, section_offsets
);
481 /* Check to make sure file was compiled with -g. If not, warn the
482 user of this limitation. */
483 if (compare_glevel (max_glevel
, GLEVEL_2
) < 0)
485 if (max_gdbinfo
== 0)
486 printf_unfiltered ("\n%s not compiled with -g, debugging support is limited.\n",
488 printf_unfiltered ("You should compile with -g2 or -g3 for best debugging support.\n");
489 gdb_flush (gdb_stdout
);
494 /* Local utilities */
496 /* Map of FDR indexes to partial symtabs */
500 struct partial_symtab
*pst
; /* the psymtab proper */
501 long n_globals
; /* exported globals (external symbols) */
502 long globals_offset
; /* cumulative */
506 /* Utility stack, used to nest procedures and blocks properly.
507 It is a doubly linked list, to avoid too many alloc/free.
508 Since we might need it quite a few times it is NOT deallocated
511 static struct parse_stack
513 struct parse_stack
*next
, *prev
;
514 struct symtab
*cur_st
; /* Current symtab. */
515 struct block
*cur_block
; /* Block in it. */
517 /* What are we parsing. stFile, or stBlock are for files and
518 blocks. stProc or stStaticProc means we have seen the start of a
519 procedure, but not the start of the block within in. When we see
520 the start of that block, we change it to stNil, without pushing a
521 new block, i.e. stNil means both a procedure and a block. */
525 int maxsyms
; /* Max symbols in this block. */
526 struct type
*cur_type
; /* Type we parse fields for. */
527 int cur_field
; /* Field number in cur_type. */
528 CORE_ADDR procadr
; /* Start addres of this procedure */
529 int numargs
; /* Its argument count */
532 *top_stack
; /* Top stack ptr */
535 /* Enter a new lexical context */
540 struct parse_stack
*new;
542 /* Reuse frames if possible */
543 if (top_stack
&& top_stack
->prev
)
544 new = top_stack
->prev
;
546 new = (struct parse_stack
*) xzalloc (sizeof (struct parse_stack
));
547 /* Initialize new frame with previous content */
550 register struct parse_stack
*prev
= new->prev
;
553 top_stack
->prev
= new;
555 new->next
= top_stack
;
560 /* Exit a lexical context */
568 top_stack
= top_stack
->next
;
572 /* Cross-references might be to things we haven't looked at
573 yet, e.g. type references. To avoid too many type
574 duplications we keep a quick fixup table, an array
575 of lists of references indexed by file descriptor */
577 struct mdebug_pending
579 struct mdebug_pending
*next
; /* link */
580 char *s
; /* the unswapped symbol */
581 struct type
*t
; /* its partial type descriptor */
585 /* The pending information is kept for an entire object file, and used
586 to be in the sym_private field. I took it out when I split
587 mdebugread from mipsread, because this might not be the only type
588 of symbols read from an object file. Instead, we allocate the
589 pending information table when we create the partial symbols, and
590 we store a pointer to the single table in each psymtab. */
592 static struct mdebug_pending
**pending_list
;
594 /* Check whether we already saw symbol SH in file FH */
596 static struct mdebug_pending
*
597 is_pending_symbol (fh
, sh
)
601 int f_idx
= fh
- debug_info
->fdr
;
602 register struct mdebug_pending
*p
;
604 /* Linear search is ok, list is typically no more than 10 deep */
605 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
611 /* Add a new symbol SH of type T */
614 add_pending (fh
, sh
, t
)
619 int f_idx
= fh
- debug_info
->fdr
;
620 struct mdebug_pending
*p
= is_pending_symbol (fh
, sh
);
622 /* Make sure we do not make duplicates */
625 p
= ((struct mdebug_pending
*)
626 obstack_alloc (¤t_objfile
->psymbol_obstack
,
627 sizeof (struct mdebug_pending
)));
630 p
->next
= pending_list
[f_idx
];
631 pending_list
[f_idx
] = p
;
636 /* Parsing Routines proper. */
638 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
639 For blocks, procedures and types we open a new lexical context.
640 This is basically just a big switch on the symbol's type. Argument
641 AX is the base pointer of aux symbols for this file (fh->iauxBase).
642 EXT_SH points to the unswapped symbol, which is needed for struct,
643 union, etc., types; it is NULL for an EXTR. BIGEND says whether
644 aux symbols are big-endian or little-endian. Return count of
645 SYMR's handled (normally one). */
648 parse_symbol (sh
, ax
, ext_sh
, bigend
)
654 const bfd_size_type external_sym_size
= debug_swap
->external_sym_size
;
655 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*)) =
656 debug_swap
->swap_sym_in
;
660 struct mdebug_pending
*pend
;
664 enum address_class
class;
666 long svalue
= sh
->value
;
669 if (ext_sh
== (char *) NULL
)
670 name
= debug_info
->ssext
+ sh
->iss
;
672 name
= debug_info
->ss
+ cur_fdr
->issBase
+ sh
->iss
;
679 case stGlobal
: /* external symbol, goes into global block */
681 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack
->cur_st
),
683 s
= new_symbol (name
);
684 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
687 case stStatic
: /* static data, goes into current block. */
689 b
= top_stack
->cur_block
;
690 s
= new_symbol (name
);
691 if (sh
->sc
== scCommon
)
693 /* It is a FORTRAN common block. At least for SGI Fortran the
694 address is not in the symbol; we need to fix it later in
695 scan_file_globals. */
696 int bucket
= hashname (SYMBOL_NAME (s
));
697 SYMBOL_VALUE_CHAIN (s
) = global_sym_chain
[bucket
];
698 global_sym_chain
[bucket
] = s
;
701 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
704 case stLocal
: /* local variable, goes into current block */
705 if (sh
->sc
== scRegister
)
707 class = LOC_REGISTER
;
708 svalue
= ECOFF_REG_TO_REGNUM (svalue
);
712 b
= top_stack
->cur_block
;
713 s
= new_symbol (name
);
714 SYMBOL_VALUE (s
) = svalue
;
716 data
: /* Common code for symbols describing data */
717 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
718 SYMBOL_CLASS (s
) = class;
721 /* Type could be missing in a number of cases */
722 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
723 sh
->index
== 0xfffff)
724 SYMBOL_TYPE (s
) = builtin_type_int
; /* undefined? */
726 SYMBOL_TYPE (s
) = parse_type (cur_fd
, ax
, sh
->index
, 0, bigend
, name
);
727 /* Value of a data symbol is its memory address */
730 case stParam
: /* arg to procedure, goes into current block */
732 top_stack
->numargs
++;
734 /* Special GNU C++ name. */
735 if (name
[0] == CPLUS_MARKER
&& name
[1] == 't' && name
[2] == 0)
736 name
= "this"; /* FIXME, not alloc'd in obstack */
737 s
= new_symbol (name
);
739 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
743 /* Pass by value in register. */
744 SYMBOL_CLASS(s
) = LOC_REGPARM
;
745 svalue
= ECOFF_REG_TO_REGNUM (svalue
);
748 /* Pass by reference on stack. */
749 SYMBOL_CLASS(s
) = LOC_REF_ARG
;
752 /* Pass by reference in register. */
753 SYMBOL_CLASS(s
) = LOC_REGPARM_ADDR
;
754 svalue
= ECOFF_REG_TO_REGNUM (svalue
);
757 /* Pass by value on stack. */
758 SYMBOL_CLASS(s
) = LOC_ARG
;
761 SYMBOL_VALUE (s
) = svalue
;
762 SYMBOL_TYPE (s
) = parse_type (cur_fd
, ax
, sh
->index
, 0, bigend
, name
);
763 add_symbol (s
, top_stack
->cur_block
);
765 /* FIXME: This has not been tested. See dbxread.c */
766 /* Add the type of this parameter to the function/procedure
767 type of this block. */
768 add_param_to_type (&top_stack
->cur_block
->function
->type
, s
);
772 case stLabel
: /* label, goes into current block */
773 s
= new_symbol (name
);
774 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
; /* so that it can be used */
775 SYMBOL_CLASS (s
) = LOC_LABEL
; /* but not misused */
776 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
777 SYMBOL_TYPE (s
) = builtin_type_int
;
778 add_symbol (s
, top_stack
->cur_block
);
781 case stProc
: /* Procedure, usually goes into global block */
782 case stStaticProc
: /* Static procedure, goes into current block */
783 s
= new_symbol (name
);
784 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
785 SYMBOL_CLASS (s
) = LOC_BLOCK
;
786 /* Type of the return value */
787 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
788 t
= builtin_type_int
;
790 t
= parse_type (cur_fd
, ax
, sh
->index
+ 1, 0, bigend
, name
);
791 b
= top_stack
->cur_block
;
792 if (sh
->st
== stProc
)
794 struct blockvector
*bv
= BLOCKVECTOR (top_stack
->cur_st
);
795 /* The next test should normally be true, but provides a
796 hook for nested functions (which we don't want to make
798 if (b
== BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
))
799 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
800 /* Irix 5 sometimes has duplicate names for the same
801 function. We want to add such names up at the global
802 level, not as a nested function. */
803 else if (sh
->value
== top_stack
->procadr
)
804 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
808 /* Make a type for the procedure itself */
810 /* FIXME: This has not been tested yet! See dbxread.c */
811 /* Generate a template for the type of this function. The
812 types of the arguments will be added as we read the symbol
814 memcpy (lookup_function_type (t
), SYMBOL_TYPE (s
), sizeof (struct type
));
816 SYMBOL_TYPE (s
) = lookup_function_type (t
);
819 /* Create and enter a new lexical context */
820 b
= new_block (top_stack
->maxsyms
);
821 SYMBOL_BLOCK_VALUE (s
) = b
;
822 BLOCK_FUNCTION (b
) = s
;
823 BLOCK_START (b
) = BLOCK_END (b
) = sh
->value
;
824 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
825 add_block (b
, top_stack
->cur_st
);
827 /* Not if we only have partial info */
828 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
832 top_stack
->cur_block
= b
;
833 top_stack
->blocktype
= sh
->st
;
834 top_stack
->cur_type
= SYMBOL_TYPE (s
);
835 top_stack
->cur_field
= -1;
836 top_stack
->procadr
= sh
->value
;
837 top_stack
->numargs
= 0;
840 /* Beginning of code for structure, union, and enum definitions.
841 They all share a common set of local variables, defined here. */
843 enum type_code type_code
;
849 case stStruct
: /* Start a block defining a struct type */
850 type_code
= TYPE_CODE_STRUCT
;
851 goto structured_common
;
853 case stUnion
: /* Start a block defining a union type */
854 type_code
= TYPE_CODE_UNION
;
855 goto structured_common
;
857 case stEnum
: /* Start a block defining an enum type */
858 type_code
= TYPE_CODE_ENUM
;
859 goto structured_common
;
861 case stBlock
: /* Either a lexical block, or some type */
862 if (sh
->sc
!= scInfo
&& sh
->sc
!= scCommon
)
863 goto case_stBlock_code
; /* Lexical block */
865 type_code
= TYPE_CODE_UNDEF
; /* We have a type. */
867 /* Common code for handling struct, union, enum, and/or as-yet-
868 unknown-type blocks of info about structured data. `type_code'
869 has been set to the proper TYPE_CODE, if we know it. */
872 top_stack
->blocktype
= stBlock
;
874 /* First count the number of fields and the highest value. */
877 for (ext_tsym
= ext_sh
+ external_sym_size
;
879 ext_tsym
+= external_sym_size
)
883 (*swap_sym_in
) (cur_bfd
, ext_tsym
, &tsym
);
891 if (nfields
== 0 && type_code
== TYPE_CODE_UNDEF
)
892 /* If the type of the member is Nil (or Void),
893 without qualifiers, assume the tag is an
895 if (tsym
.index
== indexNil
)
896 type_code
= TYPE_CODE_ENUM
;
899 ecoff_swap_tir_in (bigend
,
900 &ax
[tsym
.index
].a_ti
,
902 if ((tir
.bt
== btNil
|| tir
.bt
== btVoid
)
904 type_code
= TYPE_CODE_ENUM
;
907 if (tsym
.value
> max_value
)
908 max_value
= tsym
.value
;
917 /* This is a no-op; is it trying to tell us something
918 we should be checking? */
919 if (tsym
.sc
== scVariant
); /*UNIMPLEMENTED*/
923 /* This is something like a struct within a
924 struct. Skip over the fields of the inner
925 struct. The -1 is because the for loop will
926 increment ext_tsym. */
927 ext_tsym
= ((char *) debug_info
->external_sym
928 + ((cur_fdr
->isymBase
+ tsym
.index
- 1)
929 * external_sym_size
));
935 /* mips cc puts out a typedef for struct x if it is not yet
936 defined when it encounters
937 struct y { struct x *xp; };
942 complain (&block_member_complaint
, tsym
.st
);
947 /* In an stBlock, there is no way to distinguish structs,
948 unions, and enums at this point. This is a bug in the
949 original design (that has been fixed with the recent
950 addition of the stStruct, stUnion, and stEnum symbol
951 types.) The way you can tell is if/when you see a variable
952 or field of that type. In that case the variable's type
953 (in the AUX table) says if the type is struct, union, or
954 enum, and points back to the stBlock here. So you can
955 patch the tag kind up later - but only if there actually is
956 a variable or field of that type.
958 So until we know for sure, we will guess at this point.
960 If the first member has index==indexNil or a void type,
961 assume we have an enumeration.
962 Otherwise, if there is more than one member, and all
963 the members have offset 0, assume we have a union.
964 Otherwise, assume we have a struct.
966 The heuristic could guess wrong in the case of of an
967 enumeration with no members or a union with one (or zero)
968 members, or when all except the last field of a struct have
969 width zero. These are uncommon and/or illegal situations,
970 and in any case guessing wrong probably doesn't matter
973 But if we later do find out we were wrong, we fixup the tag
974 kind. Members of an enumeration must be handled
975 differently from struct/union fields, and that is harder to
976 patch up, but luckily we shouldn't need to. (If there are
977 any enumeration members, we can tell for sure it's an enum
980 if (type_code
== TYPE_CODE_UNDEF
)
981 if (nfields
> 1 && max_value
== 0)
982 type_code
= TYPE_CODE_UNION
;
984 type_code
= TYPE_CODE_STRUCT
;
986 /* Create a new type or use the pending type. */
987 pend
= is_pending_symbol (cur_fdr
, ext_sh
);
988 if (pend
== (struct mdebug_pending
*) NULL
)
991 add_pending (cur_fdr
, ext_sh
, t
);
996 /* Alpha cc unnamed structs do not get a tag name. */
998 TYPE_TAG_NAME (t
) = NULL
;
1000 TYPE_TAG_NAME (t
) = obconcat (¤t_objfile
->symbol_obstack
,
1003 TYPE_CODE (t
) = type_code
;
1004 TYPE_LENGTH (t
) = sh
->value
;
1005 TYPE_NFIELDS (t
) = nfields
;
1006 TYPE_FIELDS (t
) = f
= ((struct field
*)
1008 nfields
* sizeof (struct field
)));
1010 if (type_code
== TYPE_CODE_ENUM
)
1012 /* This is a non-empty enum. */
1014 /* c89 has the number of enumerators in the sh.value field,
1015 not the type length, so we have to compensate for that
1016 incompatibility quirk.
1017 This might do the wrong thing for an enum with one or two
1018 enumerators and gcc -gcoff -fshort-enums, but these cases
1019 are hopefully rare enough. */
1020 if (TYPE_LENGTH (t
) == TYPE_NFIELDS (t
))
1021 TYPE_LENGTH (t
) = TARGET_INT_BIT
/ HOST_CHAR_BIT
;
1022 for (ext_tsym
= ext_sh
+ external_sym_size
;
1024 ext_tsym
+= external_sym_size
)
1027 struct symbol
*enum_sym
;
1029 (*swap_sym_in
) (cur_bfd
, ext_tsym
, &tsym
);
1031 if (tsym
.st
!= stMember
)
1034 f
->bitpos
= tsym
.value
;
1036 f
->name
= debug_info
->ss
+ cur_fdr
->issBase
+ tsym
.iss
;
1039 enum_sym
= ((struct symbol
*)
1040 obstack_alloc (¤t_objfile
->symbol_obstack
,
1041 sizeof (struct symbol
)));
1042 memset ((PTR
) enum_sym
, 0, sizeof (struct symbol
));
1043 SYMBOL_NAME (enum_sym
) = f
->name
;
1044 SYMBOL_CLASS (enum_sym
) = LOC_CONST
;
1045 SYMBOL_TYPE (enum_sym
) = t
;
1046 SYMBOL_NAMESPACE (enum_sym
) = VAR_NAMESPACE
;
1047 SYMBOL_VALUE (enum_sym
) = tsym
.value
;
1048 add_symbol (enum_sym
, top_stack
->cur_block
);
1050 /* Skip the stMembers that we've handled. */
1055 /* make this the current type */
1056 top_stack
->cur_type
= t
;
1057 top_stack
->cur_field
= 0;
1059 /* Do not create a symbol for alpha cc unnamed structs. */
1063 /* gcc puts out an empty struct for an opaque struct definitions,
1064 do not create a symbol for it either. */
1065 if (TYPE_NFIELDS (t
) == 0)
1067 TYPE_FLAGS (t
) |= TYPE_FLAG_STUB
;
1071 s
= new_symbol (name
);
1072 SYMBOL_NAMESPACE (s
) = STRUCT_NAMESPACE
;
1073 SYMBOL_CLASS (s
) = LOC_TYPEDEF
;
1074 SYMBOL_VALUE (s
) = 0;
1075 SYMBOL_TYPE (s
) = t
;
1076 add_symbol (s
, top_stack
->cur_block
);
1079 /* End of local variables shared by struct, union, enum, and
1080 block (as yet unknown struct/union/enum) processing. */
1084 /* beginnning of (code) block. Value of symbol
1085 is the displacement from procedure start */
1086 push_parse_stack ();
1088 /* Do not start a new block if this is the outermost block of a
1089 procedure. This allows the LOC_BLOCK symbol to point to the
1090 block with the local variables, so funcname::var works. */
1091 if (top_stack
->blocktype
== stProc
1092 || top_stack
->blocktype
== stStaticProc
)
1094 top_stack
->blocktype
= stNil
;
1098 top_stack
->blocktype
= stBlock
;
1099 b
= new_block (top_stack
->maxsyms
);
1100 BLOCK_START (b
) = sh
->value
+ top_stack
->procadr
;
1101 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
1102 top_stack
->cur_block
= b
;
1103 add_block (b
, top_stack
->cur_st
);
1106 case stEnd
: /* end (of anything) */
1107 if (sh
->sc
== scInfo
|| sh
->sc
== scCommon
)
1109 /* Finished with type */
1110 top_stack
->cur_type
= 0;
1112 else if (sh
->sc
== scText
&&
1113 (top_stack
->blocktype
== stProc
||
1114 top_stack
->blocktype
== stStaticProc
))
1116 /* Finished with procedure */
1117 struct blockvector
*bv
= BLOCKVECTOR (top_stack
->cur_st
);
1118 struct mips_extra_func_info
*e
;
1122 BLOCK_END (top_stack
->cur_block
) += sh
->value
; /* size */
1124 /* Make up special symbol to contain procedure specific info */
1125 s
= new_symbol (MIPS_EFI_SYMBOL_NAME
);
1126 SYMBOL_NAMESPACE (s
) = LABEL_NAMESPACE
;
1127 SYMBOL_CLASS (s
) = LOC_CONST
;
1128 SYMBOL_TYPE (s
) = builtin_type_void
;
1129 e
= ((struct mips_extra_func_info
*)
1130 obstack_alloc (¤t_objfile
->symbol_obstack
,
1131 sizeof (struct mips_extra_func_info
)));
1132 SYMBOL_VALUE (s
) = (long) e
;
1133 e
->numargs
= top_stack
->numargs
;
1134 add_symbol (s
, top_stack
->cur_block
);
1136 /* Reallocate symbols, saving memory */
1137 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
1139 /* f77 emits proc-level with address bounds==[0,0],
1140 So look for such child blocks, and patch them. */
1141 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS (bv
); i
++)
1143 struct block
*b_bad
= BLOCKVECTOR_BLOCK (bv
, i
);
1144 if (BLOCK_SUPERBLOCK (b_bad
) == b
1145 && BLOCK_START (b_bad
) == top_stack
->procadr
1146 && BLOCK_END (b_bad
) == top_stack
->procadr
)
1148 BLOCK_START (b_bad
) = BLOCK_START (b
);
1149 BLOCK_END (b_bad
) = BLOCK_END (b
);
1153 else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
)
1155 /* End of (code) block. The value of the symbol is the
1156 displacement from the procedure`s start address of the
1157 end of this block. */
1158 BLOCK_END (top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1159 shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
1161 else if (sh
->sc
== scText
&& top_stack
->blocktype
== stNil
)
1163 /* End of outermost block. Pop parse stack and ignore. The
1164 following stEnd of stProc will take care of the block. */
1167 else if (sh
->sc
== scText
&& top_stack
->blocktype
== stFile
)
1169 /* End of file. Pop parse stack and ignore. Higher
1170 level code deals with this. */
1174 complain (&stEnd_complaint
, sh
->sc
);
1176 pop_parse_stack (); /* restore previous lexical context */
1179 case stMember
: /* member of struct or union */
1180 f
= &TYPE_FIELDS (top_stack
->cur_type
)[top_stack
->cur_field
++];
1182 f
->bitpos
= sh
->value
;
1184 f
->type
= parse_type (cur_fd
, ax
, sh
->index
, &bitsize
, bigend
, name
);
1185 f
->bitsize
= bitsize
;
1188 case stTypedef
: /* type definition */
1189 /* Typedefs for forward declarations and opaque structs from alpha cc
1190 are handled by cross_ref, skip them. */
1194 /* Parse the type or use the pending type. */
1195 pend
= is_pending_symbol (cur_fdr
, ext_sh
);
1196 if (pend
== (struct mdebug_pending
*) NULL
)
1198 t
= parse_type (cur_fd
, ax
, sh
->index
, (int *)NULL
, bigend
, name
);
1199 add_pending (cur_fdr
, ext_sh
, t
);
1204 /* mips cc puts out a typedef with the name of the struct for forward
1205 declarations. These should not go into the symbol table and
1206 TYPE_NAME should not be set for them.
1207 They can't be distinguished from an intentional typedef to
1208 the same name however:
1210 struct x { int ix; int jx; };
1214 struct xx {int ixx; int jxx; };
1215 generates a cross referencing stTypedef for x and xx.
1216 The user visible effect of this is that the type of a pointer
1217 to struct foo sometimes is given as `foo *' instead of `struct foo *'.
1218 The problem is fixed with alpha cc. */
1220 s
= new_symbol (name
);
1221 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
1222 SYMBOL_CLASS (s
) = LOC_TYPEDEF
;
1223 SYMBOL_BLOCK_VALUE (s
) = top_stack
->cur_block
;
1224 SYMBOL_TYPE (s
) = t
;
1225 add_symbol (s
, top_stack
->cur_block
);
1227 /* Incomplete definitions of structs should not get a name. */
1228 if (TYPE_NAME (SYMBOL_TYPE (s
)) == NULL
1229 && (TYPE_NFIELDS (SYMBOL_TYPE (s
)) != 0
1230 || (TYPE_CODE (SYMBOL_TYPE (s
)) != TYPE_CODE_STRUCT
1231 && TYPE_CODE (SYMBOL_TYPE (s
)) != TYPE_CODE_UNION
)))
1233 if (TYPE_CODE (SYMBOL_TYPE (s
)) == TYPE_CODE_PTR
1234 || TYPE_CODE (SYMBOL_TYPE (s
)) == TYPE_CODE_FUNC
)
1236 /* If we are giving a name to a type such as "pointer to
1237 foo" or "function returning foo", we better not set
1238 the TYPE_NAME. If the program contains "typedef char
1239 *caddr_t;", we don't want all variables of type char
1240 * to print as caddr_t. This is not just a
1241 consequence of GDB's type management; CC and GCC (at
1242 least through version 2.4) both output variables of
1243 either type char * or caddr_t with the type
1244 refering to the stTypedef symbol for caddr_t. If a future
1245 compiler cleans this up it GDB is not ready for it
1246 yet, but if it becomes ready we somehow need to
1247 disable this check (without breaking the PCC/GCC2.4
1252 Fortunately, this check seems not to be necessary
1253 for anything except pointers or functions. */
1256 TYPE_NAME (SYMBOL_TYPE (s
)) = SYMBOL_NAME (s
);
1260 case stFile
: /* file name */
1261 push_parse_stack ();
1262 top_stack
->blocktype
= sh
->st
;
1265 /* I`ve never seen these for C */
1267 break; /* register relocation */
1269 break; /* forwarding address */
1271 break; /* constant */
1273 complain (&unknown_mdebug_symtype_complaint
, sh
->st
);
1280 /* Parse the type information provided in the raw AX entries for
1281 the symbol SH. Return the bitfield size in BS, in case.
1282 We must byte-swap the AX entries before we use them; BIGEND says whether
1283 they are big-endian or little-endian (from fh->fBigendian). */
1285 static struct type
*
1286 parse_type (fd
, ax
, aux_index
, bs
, bigend
, sym_name
)
1289 unsigned int aux_index
;
1294 /* Null entries in this map are treated specially */
1295 static struct type
**map_bt
[] =
1297 &builtin_type_void
, /* btNil */
1299 &builtin_type_char
, /* btChar */
1300 &builtin_type_unsigned_char
,/* btUChar */
1301 &builtin_type_short
, /* btShort */
1302 &builtin_type_unsigned_short
, /* btUShort */
1303 &builtin_type_int
, /* btInt */
1304 &builtin_type_unsigned_int
, /* btUInt */
1305 &builtin_type_long
, /* btLong */
1306 &builtin_type_unsigned_long
,/* btULong */
1307 &builtin_type_float
, /* btFloat */
1308 &builtin_type_double
, /* btDouble */
1315 &mdebug_type_complex
, /* btComplex */
1316 &mdebug_type_double_complex
, /* btDComplex */
1318 &mdebug_type_fixed_dec
, /* btFixedDec */
1319 &mdebug_type_float_dec
, /* btFloatDec */
1320 &mdebug_type_string
, /* btString */
1323 &builtin_type_void
, /* btVoid */
1324 0, /* DEC C++: Pointer to member */
1325 0, /* DEC C++: Virtual function table */
1326 0, /* DEC C++: Class (Record) */
1327 &builtin_type_long
, /* btLong64 */
1328 &builtin_type_unsigned_long
, /* btULong64 */
1329 &builtin_type_long_long
, /* btLongLong64 */
1330 &builtin_type_unsigned_long_long
, /* btULongLong64 */
1331 &builtin_type_unsigned_long
, /* btAdr64 */
1332 &builtin_type_long
, /* btInt64 */
1333 &builtin_type_unsigned_long
, /* btUInt64 */
1337 struct type
*tp
= 0;
1338 enum type_code type_code
= TYPE_CODE_UNDEF
;
1340 /* Handle corrupt aux indices. */
1341 if (aux_index
>= (debug_info
->fdr
+ fd
)->caux
)
1343 complain (&index_complaint
, sym_name
);
1344 return builtin_type_int
;
1348 /* Use aux as a type information record, map its basic type. */
1349 ecoff_swap_tir_in (bigend
, &ax
->a_ti
, t
);
1350 if (t
->bt
>= (sizeof (map_bt
) / sizeof (*map_bt
)))
1352 complain (&basic_type_complaint
, t
->bt
, sym_name
);
1353 return builtin_type_int
;
1357 tp
= *map_bt
[t
->bt
];
1362 /* Cannot use builtin types -- build our own */
1366 tp
= lookup_pointer_type (builtin_type_void
);
1369 type_code
= TYPE_CODE_STRUCT
;
1372 type_code
= TYPE_CODE_UNION
;
1375 type_code
= TYPE_CODE_ENUM
;
1378 type_code
= TYPE_CODE_RANGE
;
1381 type_code
= TYPE_CODE_SET
;
1384 /* alpha cc uses this for typedefs. The true type will be
1385 obtained by crossreferencing below. */
1386 type_code
= TYPE_CODE_ERROR
;
1389 complain (&basic_type_complaint
, t
->bt
, sym_name
);
1390 return builtin_type_int
;
1394 /* Move on to next aux */
1399 /* Inhibit core dumps with some cfront generated objects that
1401 if (bs
== (int *)NULL
)
1403 complain (&bad_fbitfield_complaint
, sym_name
);
1404 return builtin_type_int
;
1406 *bs
= AUX_GET_WIDTH (bigend
, ax
);
1410 /* All these types really point to some (common) MIPS type
1411 definition, and only the type-qualifiers fully identify
1412 them. We'll make the same effort at sharing. */
1413 if (t
->bt
== btStruct
||
1417 /* btSet (I think) implies that the name is a tag name, not a typedef
1418 name. This apparently is a MIPS extension for C sets. */
1423 /* Try to cross reference this type, build new type on failure. */
1424 ax
+= cross_ref (fd
, ax
, &tp
, type_code
, &name
, bigend
, sym_name
);
1425 if (tp
== (struct type
*) NULL
)
1426 tp
= init_type (type_code
, 0, 0, (char *) NULL
, current_objfile
);
1428 /* Make sure that TYPE_CODE(tp) has an expected type code.
1429 Any type may be returned from cross_ref if file indirect entries
1431 if (TYPE_CODE (tp
) != TYPE_CODE_STRUCT
1432 && TYPE_CODE (tp
) != TYPE_CODE_UNION
1433 && TYPE_CODE (tp
) != TYPE_CODE_ENUM
)
1435 complain (&unexpected_type_code_complaint
, sym_name
);
1440 /* Usually, TYPE_CODE(tp) is already type_code. The main
1441 exception is if we guessed wrong re struct/union/enum.
1442 But for struct vs. union a wrong guess is harmless, so
1443 don't complain(). */
1444 if ((TYPE_CODE (tp
) == TYPE_CODE_ENUM
1445 && type_code
!= TYPE_CODE_ENUM
)
1446 || (TYPE_CODE (tp
) != TYPE_CODE_ENUM
1447 && type_code
== TYPE_CODE_ENUM
))
1449 complain (&bad_tag_guess_complaint
, sym_name
);
1452 if (TYPE_CODE (tp
) != type_code
)
1454 TYPE_CODE (tp
) = type_code
;
1457 /* Do not set the tag name if it is a compiler generated tag name
1458 (.Fxx or .xxfake or empty) for unnamed struct/union/enums. */
1459 if (name
[0] == '.' || name
[0] == '\0')
1460 TYPE_TAG_NAME (tp
) = NULL
;
1461 else if (TYPE_TAG_NAME (tp
) == NULL
1462 || !STREQ (TYPE_TAG_NAME (tp
), name
))
1463 TYPE_TAG_NAME (tp
) = obsavestring (name
, strlen (name
),
1464 ¤t_objfile
->type_obstack
);
1468 /* All these types really point to some (common) MIPS type
1469 definition, and only the type-qualifiers fully identify
1470 them. We'll make the same effort at sharing.
1471 FIXME: btIndirect cannot happen here as it is handled by the
1472 switch t->bt above. And we are not doing any guessing on range types. */
1473 if (t
->bt
== btIndirect
||
1478 /* Try to cross reference this type, build new type on failure. */
1479 ax
+= cross_ref (fd
, ax
, &tp
, type_code
, &name
, bigend
, sym_name
);
1480 if (tp
== (struct type
*) NULL
)
1481 tp
= init_type (type_code
, 0, 0, (char *) NULL
, current_objfile
);
1483 /* Make sure that TYPE_CODE(tp) has an expected type code.
1484 Any type may be returned from cross_ref if file indirect entries
1486 if (TYPE_CODE (tp
) != TYPE_CODE_RANGE
)
1488 complain (&unexpected_type_code_complaint
, sym_name
);
1492 /* Usually, TYPE_CODE(tp) is already type_code. The main
1493 exception is if we guessed wrong re struct/union/enum. */
1494 if (TYPE_CODE (tp
) != type_code
)
1496 complain (&bad_tag_guess_complaint
, sym_name
);
1497 TYPE_CODE (tp
) = type_code
;
1499 if (TYPE_NAME (tp
) == NULL
|| !STREQ (TYPE_NAME (tp
), name
))
1500 TYPE_NAME (tp
) = obsavestring (name
, strlen (name
),
1501 ¤t_objfile
->type_obstack
);
1504 if (t
->bt
== btTypedef
)
1508 /* Try to cross reference this type, it should succeed. */
1509 ax
+= cross_ref (fd
, ax
, &tp
, type_code
, &name
, bigend
, sym_name
);
1510 if (tp
== (struct type
*) NULL
)
1512 complain (&unable_to_cross_ref_complaint
, sym_name
);
1513 tp
= builtin_type_int
;
1517 /* Deal with range types */
1518 if (t
->bt
== btRange
)
1520 TYPE_NFIELDS (tp
) = 2;
1521 TYPE_FIELDS (tp
) = ((struct field
*)
1522 TYPE_ALLOC (tp
, 2 * sizeof (struct field
)));
1523 TYPE_FIELD_NAME (tp
, 0) = obsavestring ("Low", strlen ("Low"),
1524 ¤t_objfile
->type_obstack
);
1525 TYPE_FIELD_BITPOS (tp
, 0) = AUX_GET_DNLOW (bigend
, ax
);
1527 TYPE_FIELD_NAME (tp
, 1) = obsavestring ("High", strlen ("High"),
1528 ¤t_objfile
->type_obstack
);
1529 TYPE_FIELD_BITPOS (tp
, 1) = AUX_GET_DNHIGH (bigend
, ax
);
1533 /* Parse all the type qualifiers now. If there are more
1534 than 6 the game will continue in the next aux */
1538 #define PARSE_TQ(tq) \
1539 if (t->tq != tqNil) \
1540 ax += upgrade_type(fd, &tp, t->tq, ax, bigend, sym_name); \
1552 /* mips cc 2.x and gcc never put out continued aux entries. */
1556 ecoff_swap_tir_in (bigend
, &ax
->a_ti
, t
);
1560 /* Complain for illegal continuations due to corrupt aux entries. */
1562 complain (&bad_continued_complaint
, sym_name
);
1567 /* Make up a complex type from a basic one. Type is passed by
1568 reference in TPP and side-effected as necessary. The type
1569 qualifier TQ says how to handle the aux symbols at AX for
1570 the symbol SX we are currently analyzing. BIGEND says whether
1571 aux symbols are big-endian or little-endian.
1572 Returns the number of aux symbols we parsed. */
1575 upgrade_type (fd
, tpp
, tq
, ax
, bigend
, sym_name
)
1586 /* Used in array processing */
1597 t
= lookup_pointer_type (*tpp
);
1602 t
= lookup_function_type (*tpp
);
1609 /* Determine and record the domain type (type of index) */
1610 ecoff_swap_rndx_in (bigend
, &ax
->a_rndx
, &rndx
);
1616 rf
= AUX_GET_ISYM (bigend
, ax
);
1619 fh
= get_rfd (fd
, rf
);
1621 indx
= parse_type (fd
, debug_info
->external_aux
+ fh
->iauxBase
,
1622 id
, (int *) NULL
, bigend
, sym_name
);
1624 /* The bounds type should be an integer type, but might be anything
1625 else due to corrupt aux entries. */
1626 if (TYPE_CODE (indx
) != TYPE_CODE_INT
)
1628 complain (&array_index_type_complaint
, sym_name
);
1629 indx
= builtin_type_int
;
1632 /* Get the bounds, and create the array type. */
1634 lower
= AUX_GET_DNLOW (bigend
, ax
);
1636 upper
= AUX_GET_DNHIGH (bigend
, ax
);
1638 rf
= AUX_GET_WIDTH (bigend
, ax
); /* bit size of array element */
1640 range
= create_range_type ((struct type
*) NULL
, indx
,
1643 t
= create_array_type ((struct type
*) NULL
, *tpp
, range
);
1645 /* We used to fill in the supplied array element bitsize
1646 here if the TYPE_LENGTH of the target type was zero.
1647 This happens for a `pointer to an array of anonymous structs',
1648 but in this case the array element bitsize is also zero,
1649 so nothing is gained.
1650 And we used to check the TYPE_LENGTH of the target type against
1651 the supplied array element bitsize.
1652 gcc causes a mismatch for `pointer to array of object',
1653 since the sdb directives it uses do not have a way of
1654 specifying the bitsize, but it does no harm (the
1655 TYPE_LENGTH should be correct) and we should be able to
1656 ignore the erroneous bitsize from the auxiliary entry safely.
1657 dbx seems to ignore it too. */
1663 /* Volatile -- currently ignored */
1667 /* Const -- currently ignored */
1671 complain (&unknown_type_qual_complaint
, tq
);
1677 /* Parse a procedure descriptor record PR. Note that the procedure is
1678 parsed _after_ the local symbols, now we just insert the extra
1679 information we need into a MIPS_EFI_SYMBOL_NAME symbol that has
1680 already been placed in the procedure's main block. Note also that
1681 images that have been partially stripped (ld -x) have been deprived
1682 of local symbols, and we have to cope with them here. FIRST_OFF is
1683 the offset of the first procedure for this FDR; we adjust the
1684 address by this amount, but I don't know why. SEARCH_SYMTAB is the symtab
1685 to look for the function which contains the MIPS_EFI_SYMBOL_NAME symbol
1686 in question, or NULL to use top_stack->cur_block. */
1688 static void parse_procedure
PARAMS ((PDR
*, struct symtab
*, unsigned long));
1691 parse_procedure (pr
, search_symtab
, first_off
)
1693 struct symtab
*search_symtab
;
1694 unsigned long first_off
;
1696 struct symbol
*s
, *i
;
1698 struct mips_extra_func_info
*e
;
1701 /* Simple rule to find files linked "-x" */
1702 if (cur_fdr
->rss
== -1)
1706 /* Static procedure at address pr->adr. Sigh. */
1707 complain (&pdr_static_symbol_complaint
, (unsigned long) pr
->adr
);
1715 (*debug_swap
->swap_ext_in
) (cur_bfd
,
1716 ((char *) debug_info
->external_ext
1718 * debug_swap
->external_ext_size
)),
1720 sh_name
= debug_info
->ssext
+ she
.asym
.iss
;
1728 (*debug_swap
->swap_sym_in
) (cur_bfd
,
1729 ((char *) debug_info
->external_sym
1730 + ((cur_fdr
->isymBase
+ pr
->isym
)
1731 * debug_swap
->external_sym_size
)),
1733 sh_name
= debug_info
->ss
+ cur_fdr
->issBase
+ sh
.iss
;
1736 if (search_symtab
!= NULL
)
1739 /* This loses both in the case mentioned (want a static, find a global),
1740 but also if we are looking up a non-mangled name which happens to
1741 match the name of a mangled function. */
1742 /* We have to save the cur_fdr across the call to lookup_symbol.
1743 If the pdr is for a static function and if a global function with
1744 the same name exists, lookup_symbol will eventually read in the symtab
1745 for the global function and clobber cur_fdr. */
1746 FDR
*save_cur_fdr
= cur_fdr
;
1747 s
= lookup_symbol (sh_name
, NULL
, VAR_NAMESPACE
, 0, NULL
);
1748 cur_fdr
= save_cur_fdr
;
1752 BLOCKVECTOR_BLOCK (BLOCKVECTOR (search_symtab
), STATIC_BLOCK
),
1758 s
= mylookup_symbol (sh_name
, top_stack
->cur_block
,
1759 VAR_NAMESPACE
, LOC_BLOCK
);
1763 b
= SYMBOL_BLOCK_VALUE (s
);
1767 complain (&pdr_for_nonsymbol_complaint
, sh_name
);
1771 /* FIXME -- delete. We can't do symbol allocation now; it's all done. */
1772 s
= new_symbol (sh_name
);
1773 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
1774 SYMBOL_CLASS (s
) = LOC_BLOCK
;
1775 /* Donno its type, hope int is ok */
1776 SYMBOL_TYPE (s
) = lookup_function_type (builtin_type_int
);
1777 add_symbol (s
, top_stack
->cur_block
);
1778 /* Wont have symbols for this one */
1780 SYMBOL_BLOCK_VALUE (s
) = b
;
1781 BLOCK_FUNCTION (b
) = s
;
1782 BLOCK_START (b
) = pr
->adr
;
1783 /* BOUND used to be the end of procedure's text, but the
1784 argument is no longer passed in. */
1785 BLOCK_END (b
) = bound
;
1786 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
1787 add_block (b
, top_stack
->cur_st
);
1791 i
= mylookup_symbol (MIPS_EFI_SYMBOL_NAME
, b
, LABEL_NAMESPACE
, LOC_CONST
);
1795 e
= (struct mips_extra_func_info
*) SYMBOL_VALUE (i
);
1797 e
->pdr
.isym
= (long) s
;
1798 e
->pdr
.adr
+= cur_fdr
->adr
- first_off
;
1800 /* Correct incorrect setjmp procedure descriptor from the library
1801 to make backtrace through setjmp work. */
1802 if (e
->pdr
.pcreg
== 0 && STREQ (sh_name
, "setjmp"))
1804 complain (&bad_setjmp_pdr_complaint
, 0);
1805 e
->pdr
.pcreg
= RA_REGNUM
;
1806 e
->pdr
.regmask
= 0x80000000;
1807 e
->pdr
.regoffset
= -4;
1810 /* Fake PC_REGNUM for alpha __sigtramp so that read_next_frame_reg
1811 will use the saved user pc from the sigcontext. */
1812 if (STREQ (sh_name
, "__sigtramp"))
1813 e
->pdr
.pcreg
= PC_REGNUM
;
1814 /* Make the same patch for Irix. */
1815 if (STREQ (sh_name
, "_sigtramp"))
1816 e
->pdr
.pcreg
= PC_REGNUM
;
1820 /* Parse the external symbol ES. Just call parse_symbol() after
1821 making sure we know where the aux are for it. For procedures,
1822 parsing of the PDRs has already provided all the needed
1823 information, we only parse them if SKIP_PROCEDURES is false,
1824 and only if this causes no symbol duplication.
1825 BIGEND says whether aux entries are big-endian or little-endian.
1827 This routine clobbers top_stack->cur_block and ->cur_st. */
1830 parse_external (es
, skip_procedures
, bigend
)
1832 int skip_procedures
;
1837 if (es
->ifd
!= ifdNil
)
1840 cur_fdr
= debug_info
->fdr
+ cur_fd
;
1841 ax
= debug_info
->external_aux
+ cur_fdr
->iauxBase
;
1845 cur_fdr
= debug_info
->fdr
;
1849 /* Reading .o files */
1850 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
)
1853 switch (es
->asym
.st
)
1856 /* These are generated for static symbols in .o files,
1877 /* FIXME: Turn this into a complaint? */
1879 printf_filtered ("Warning: %s `%s' is undefined (in %s)\n",
1880 what
, debug_info
->ssext
+ es
->asym
.iss
,
1881 fdr_name (cur_fdr
));
1885 switch (es
->asym
.st
)
1888 /* If we have full symbols we do not need more */
1889 if (skip_procedures
)
1891 if (mylookup_symbol (debug_info
->ssext
+ es
->asym
.iss
,
1892 top_stack
->cur_block
,
1893 VAR_NAMESPACE
, LOC_BLOCK
))
1898 /* Note that the case of a symbol with indexNil must be handled
1899 anyways by parse_symbol(). */
1900 parse_symbol (&es
->asym
, ax
, (char *) NULL
, bigend
);
1907 /* Parse the line number info for file descriptor FH into
1908 GDB's linetable LT. MIPS' encoding requires a little bit
1909 of magic to get things out. Note also that MIPS' line
1910 numbers can go back and forth, apparently we can live
1911 with that and do not need to reorder our linetables */
1914 parse_lines (fh
, pr
, lt
, maxlines
)
1917 struct linetable
*lt
;
1920 unsigned char *base
;
1922 int delta
, count
, lineno
= 0;
1923 unsigned long first_off
= pr
->adr
;
1925 if (fh
->cbLine
== 0)
1928 base
= debug_info
->line
+ fh
->cbLineOffset
;
1930 /* Scan by procedure descriptors */
1932 for (j
= 0; j
< fh
->cpd
; j
++, pr
++)
1936 unsigned char *halt
;
1938 /* No code for this one */
1939 if (pr
->iline
== ilineNil
||
1940 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1943 /* Determine start and end address of compressed line bytes for
1945 base
= debug_info
->line
+ fh
->cbLineOffset
;
1946 if (j
!= (fh
->cpd
- 1))
1947 halt
= base
+ pr
[1].cbLineOffset
;
1949 halt
= base
+ fh
->cbLine
;
1950 base
+= pr
->cbLineOffset
;
1952 adr
= fh
->adr
+ pr
->adr
- first_off
;
1953 l
= adr
>> 2; /* in words */
1954 for (lineno
= pr
->lnLow
; base
< halt
; )
1956 count
= *base
& 0x0f;
1957 delta
= *base
++ >> 4;
1962 delta
= (base
[0] << 8) | base
[1];
1963 if (delta
>= 0x8000)
1967 lineno
+= delta
; /* first delta is 0 */
1969 /* Complain if the line table overflows. Could happen
1970 with corrupt binaries. */
1971 if (lt
->nitems
>= maxlines
)
1973 complain (&bad_linetable_guess_complaint
, fdr_name (fh
));
1976 k
= add_line (lt
, lineno
, l
, k
);
1982 /* Master parsing procedure for first-pass reading of file symbols
1983 into a partial_symtab. */
1986 parse_partial_symbols (objfile
, section_offsets
)
1987 struct objfile
*objfile
;
1988 struct section_offsets
*section_offsets
;
1990 const bfd_size_type external_sym_size
= debug_swap
->external_sym_size
;
1991 const bfd_size_type external_rfd_size
= debug_swap
->external_rfd_size
;
1992 const bfd_size_type external_ext_size
= debug_swap
->external_ext_size
;
1993 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
1994 = debug_swap
->swap_ext_in
;
1995 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
1996 = debug_swap
->swap_sym_in
;
1997 void (* const swap_rfd_in
) PARAMS ((bfd
*, PTR
, RFDT
*))
1998 = debug_swap
->swap_rfd_in
;
2000 HDRR
*hdr
= &debug_info
->symbolic_header
;
2001 /* Running pointers */
2006 register EXTR
*ext_in
;
2009 struct partial_symtab
*pst
;
2011 int past_first_source_file
= 0;
2013 /* List of current psymtab's include files */
2014 char **psymtab_include_list
;
2015 int includes_allocated
;
2018 struct pst_map
*fdr_to_pst
;
2019 /* Index within current psymtab dependency list */
2020 struct partial_symtab
**dependency_list
;
2021 int dependencies_used
, dependencies_allocated
;
2022 struct cleanup
*old_chain
;
2024 enum language prev_language
;
2026 extern_tab
= (EXTR
*) obstack_alloc (&objfile
->psymbol_obstack
,
2027 sizeof (EXTR
) * hdr
->iextMax
);
2029 includes_allocated
= 30;
2031 psymtab_include_list
= (char **) alloca (includes_allocated
*
2033 next_symbol_text_func
= mdebug_next_symbol_text
;
2035 dependencies_allocated
= 30;
2036 dependencies_used
= 0;
2038 (struct partial_symtab
**) alloca (dependencies_allocated
*
2039 sizeof (struct partial_symtab
*));
2041 last_source_file
= NULL
;
2046 * Only parse the Local and External symbols, and the Relative FDR.
2047 * Fixup enough of the loader symtab to be able to use it.
2048 * Allocate space only for the file's portions we need to
2053 max_glevel
= MIN_GLEVEL
;
2055 /* Allocate the map FDR -> PST.
2056 Minor hack: -O3 images might claim some global data belongs
2057 to FDR -1. We`ll go along with that */
2058 fdr_to_pst
= (struct pst_map
*) xzalloc ((hdr
->ifdMax
+ 1) * sizeof *fdr_to_pst
);
2059 old_chain
= make_cleanup (free
, fdr_to_pst
);
2062 struct partial_symtab
*pst
= new_psymtab ("", objfile
);
2063 fdr_to_pst
[-1].pst
= pst
;
2067 /* Allocate the global pending list. */
2069 ((struct mdebug_pending
**)
2070 obstack_alloc (&objfile
->psymbol_obstack
,
2071 hdr
->ifdMax
* sizeof (struct mdebug_pending
*)));
2072 memset ((PTR
) pending_list
, 0,
2073 hdr
->ifdMax
* sizeof (struct mdebug_pending
*));
2075 /* Pass 0 over external syms: swap them in. */
2076 ext_block
= (EXTR
*) xmalloc (hdr
->iextMax
* sizeof (EXTR
));
2077 make_cleanup (free
, ext_block
);
2079 ext_out
= (char *) debug_info
->external_ext
;
2080 ext_out_end
= ext_out
+ hdr
->iextMax
* external_ext_size
;
2082 for (; ext_out
< ext_out_end
; ext_out
+= external_ext_size
, ext_in
++)
2083 (*swap_ext_in
) (cur_bfd
, ext_out
, ext_in
);
2085 /* Pass 1 over external syms: Presize and partition the list */
2087 ext_in_end
= ext_in
+ hdr
->iextMax
;
2088 for (; ext_in
< ext_in_end
; ext_in
++)
2090 /* See calls to complain below. */
2091 if (ext_in
->ifd
>= -1
2092 && ext_in
->ifd
< hdr
->ifdMax
2093 && ext_in
->asym
.iss
>= 0
2094 && ext_in
->asym
.iss
< hdr
->issExtMax
)
2095 fdr_to_pst
[ext_in
->ifd
].n_globals
++;
2098 /* Pass 1.5 over files: partition out global symbol space */
2100 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++)
2102 fdr_to_pst
[f_idx
].globals_offset
= s_idx
;
2103 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
2104 fdr_to_pst
[f_idx
].n_globals
= 0;
2107 /* Pass 2 over external syms: fill in external symbols */
2109 ext_in_end
= ext_in
+ hdr
->iextMax
;
2110 for (; ext_in
< ext_in_end
; ext_in
++)
2112 enum minimal_symbol_type ms_type
= mst_text
;
2114 /* The Irix 5 native tools seem to sometimes generate bogus
2115 external symbols. */
2116 if (ext_in
->ifd
< -1 || ext_in
->ifd
>= hdr
->ifdMax
)
2118 complain (&bad_ext_ifd_complaint
, ext_in
->ifd
, hdr
->ifdMax
);
2121 if (ext_in
->asym
.iss
< 0 || ext_in
->asym
.iss
>= hdr
->issExtMax
)
2123 complain (&bad_ext_iss_complaint
, ext_in
->asym
.iss
,
2128 extern_tab
[fdr_to_pst
[ext_in
->ifd
].globals_offset
2129 + fdr_to_pst
[ext_in
->ifd
].n_globals
++] = *ext_in
;
2131 if (ext_in
->asym
.sc
== scUndefined
|| ext_in
->asym
.sc
== scNil
)
2134 name
= debug_info
->ssext
+ ext_in
->asym
.iss
;
2135 switch (ext_in
->asym
.st
)
2140 ms_type
= mst_file_text
;
2143 if (ext_in
->asym
.sc
== scData
2144 || ext_in
->asym
.sc
== scSData
2145 || ext_in
->asym
.sc
== scRData
)
2151 if (ext_in
->asym
.sc
== scAbs
)
2153 else if (ext_in
->asym
.sc
== scText
)
2155 else if (ext_in
->asym
.sc
== scData
2156 || ext_in
->asym
.sc
== scSData
2157 || ext_in
->asym
.sc
== scRData
)
2163 /* The alpha has the section start addresses in stLocal symbols
2164 whose name starts with a `.'. Skip those but complain for all
2165 other stLocal symbols. */
2170 ms_type
= mst_unknown
;
2171 complain (&unknown_ext_complaint
, name
);
2173 prim_record_minimal_symbol (name
, ext_in
->asym
.value
, ms_type
, objfile
);
2176 /* Pass 3 over files, over local syms: fill in static symbols */
2177 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++)
2179 struct partial_symtab
*save_pst
;
2182 cur_fdr
= fh
= debug_info
->fdr
+ f_idx
;
2186 fdr_to_pst
[f_idx
].pst
= NULL
;
2189 pst
= start_psymtab_common (objfile
, section_offsets
,
2191 fh
->cpd
? fh
->adr
: 0,
2192 objfile
->global_psymbols
.next
,
2193 objfile
->static_psymbols
.next
);
2194 pst
->read_symtab_private
= ((char *)
2195 obstack_alloc (&objfile
->psymbol_obstack
,
2196 sizeof (struct symloc
)));
2197 memset ((PTR
) pst
->read_symtab_private
, 0, sizeof (struct symloc
));
2200 FDR_IDX (pst
) = f_idx
;
2201 CUR_BFD (pst
) = cur_bfd
;
2202 DEBUG_SWAP (pst
) = debug_swap
;
2203 DEBUG_INFO (pst
) = debug_info
;
2204 PENDING_LIST (pst
) = pending_list
;
2206 /* The way to turn this into a symtab is to call... */
2207 pst
->read_symtab
= mdebug_psymtab_to_symtab
;
2209 /* Set up language for the pst.
2210 The language from the FDR is used if it is unambigious (e.g. cfront
2211 with native cc and g++ will set the language to C).
2212 Otherwise we have to deduce the language from the filename.
2213 Native ecoff has every header file in a separate FDR, so
2214 deduce_language_from_filename will return language_unknown for
2215 a header file, which is not what we want.
2216 But the FDRs for the header files are after the FDR for the source
2217 file, so we can assign the language of the source file to the
2218 following header files. Then we save the language in the private
2219 pst data so that we can reuse it when building symtabs. */
2220 prev_language
= psymtab_language
;
2224 case langCplusplusV2
:
2225 psymtab_language
= language_cplus
;
2228 psymtab_language
= deduce_language_from_filename (fdr_name (fh
));
2231 if (psymtab_language
== language_unknown
)
2232 psymtab_language
= prev_language
;
2233 PST_PRIVATE (pst
)->pst_language
= psymtab_language
;
2235 pst
->texthigh
= pst
->textlow
;
2237 /* For stabs-in-ecoff files, the second symbol must be @stab.
2238 This symbol is emitted by mips-tfile to signal that the
2239 current object file uses encapsulated stabs instead of mips
2240 ecoff for local symbols. (It is the second symbol because
2241 the first symbol is the stFile used to signal the start of a
2243 processing_gcc_compilation
= 0;
2246 (*swap_sym_in
) (cur_bfd
,
2247 ((char *) debug_info
->external_sym
2248 + (fh
->isymBase
+ 1) * external_sym_size
),
2250 if (STREQ (debug_info
->ss
+ fh
->issBase
+ sh
.iss
, stabs_symbol
))
2251 processing_gcc_compilation
= 2;
2254 if (processing_gcc_compilation
!= 0)
2256 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++)
2261 (*swap_sym_in
) (cur_bfd
,
2262 (((char *) debug_info
->external_sym
)
2263 + (fh
->isymBase
+ cur_sdx
) * external_sym_size
),
2265 type_code
= ECOFF_UNMARK_STAB (sh
.index
);
2266 if (!ECOFF_IS_STAB (&sh
))
2268 if (sh
.st
== stProc
|| sh
.st
== stStaticProc
)
2270 long procaddr
= sh
.value
;
2274 isym
= AUX_GET_ISYM (fh
->fBigendian
,
2275 (debug_info
->external_aux
2278 (*swap_sym_in
) (cur_bfd
,
2279 ((char *) debug_info
->external_sym
2280 + ((fh
->isymBase
+ isym
- 1)
2281 * external_sym_size
)),
2285 long high
= procaddr
+ sh
.value
;
2286 if (high
> pst
->texthigh
)
2287 pst
->texthigh
= high
;
2292 #define SET_NAMESTRING() \
2293 namestring = debug_info->ss + fh->issBase + sh.iss
2294 #define CUR_SYMBOL_TYPE type_code
2295 #define CUR_SYMBOL_VALUE sh.value
2296 #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms)\
2298 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
2299 #define HANDLE_RBRAC(val) \
2300 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
2301 #include "partial-stab.h"
2306 for (cur_sdx
= 0; cur_sdx
< fh
->csym
;)
2309 enum address_class
class;
2311 (*swap_sym_in
) (cur_bfd
,
2312 ((char *) debug_info
->external_sym
2313 + ((fh
->isymBase
+ cur_sdx
)
2314 * external_sym_size
)),
2317 if (ECOFF_IS_STAB (&sh
))
2323 /* Non absolute static symbols go into the minimal table. */
2324 if (sh
.sc
== scUndefined
|| sh
.sc
== scNil
2325 || (sh
.index
== indexNil
2326 && (sh
.st
!= stStatic
|| sh
.sc
== scAbs
)))
2328 /* FIXME, premature? */
2333 name
= debug_info
->ss
+ fh
->issBase
+ sh
.iss
;
2341 case stStaticProc
: /* Function */
2342 /* I believe this is used only for file-local functions.
2343 The comment in symconst.h ("load time only static procs")
2344 isn't particularly clear on this point. */
2345 prim_record_minimal_symbol (name
, sh
.value
, mst_file_text
,
2349 case stProc
: /* Asm labels apparently */
2350 ADD_PSYMBOL_TO_LIST (name
, strlen (name
),
2351 VAR_NAMESPACE
, LOC_BLOCK
,
2352 objfile
->static_psymbols
, sh
.value
,
2353 psymtab_language
, objfile
);
2354 /* Skip over procedure to next one. */
2355 if (sh
.index
>= hdr
->iauxMax
)
2357 /* Should not happen, but does when cross-compiling
2358 with the MIPS compiler. FIXME -- pull later. */
2359 complain (&index_complaint
, name
);
2360 new_sdx
= cur_sdx
+ 1; /* Don't skip at all */
2363 new_sdx
= AUX_GET_ISYM (fh
->fBigendian
,
2364 (debug_info
->external_aux
2367 procaddr
= sh
.value
;
2369 if (new_sdx
<= cur_sdx
)
2371 /* This should not happen either... FIXME. */
2372 complain (&aux_index_complaint
, name
);
2373 new_sdx
= cur_sdx
+ 1; /* Don't skip backward */
2377 (*swap_sym_in
) (cur_bfd
,
2378 ((char *) debug_info
->external_sym
2379 + ((fh
->isymBase
+ cur_sdx
- 1)
2380 * external_sym_size
)),
2384 high
= procaddr
+ sh
.value
;
2385 if (high
> pst
->texthigh
)
2386 pst
->texthigh
= high
;
2389 case stStatic
: /* Variable */
2390 if (sh
.sc
== scData
|| sh
.sc
== scSData
|| sh
.sc
== scRData
)
2391 prim_record_minimal_symbol (name
, sh
.value
, mst_file_data
,
2394 prim_record_minimal_symbol (name
, sh
.value
, mst_file_bss
,
2399 case stTypedef
:/* Typedef */
2400 /* Skip typedefs for forward declarations and opaque
2401 structs from alpha cc. */
2404 class = LOC_TYPEDEF
;
2407 case stConstant
: /* Constant decl */
2414 case stBlock
: /* { }, str, un, enum*/
2415 /* Do not create a partial symbol for cc unnamed aggregates
2416 and gcc empty aggregates. */
2417 if ((sh
.sc
== scInfo
|| sh
.sc
== scCommon
)
2419 && sh
.index
!= cur_sdx
+ 2)
2421 ADD_PSYMBOL_TO_LIST (name
, strlen (name
),
2422 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2423 objfile
->static_psymbols
,
2425 psymtab_language
, objfile
);
2427 /* Skip over the block */
2429 if (new_sdx
<= cur_sdx
)
2431 /* This happens with the Ultrix kernel. */
2432 complain (&block_index_complaint
, name
);
2433 new_sdx
= cur_sdx
+ 1; /* Don't skip backward */
2438 case stFile
: /* File headers */
2439 case stLabel
: /* Labels */
2440 case stEnd
: /* Ends of files */
2443 case stLocal
: /* Local variables */
2444 /* Normally these are skipped because we skip over
2445 all blocks we see. However, these can occur
2446 as visible symbols in a .h file that contains code. */
2450 /* Both complaints are valid: one gives symbol name,
2451 the other the offending symbol type. */
2452 complain (&unknown_sym_complaint
, name
);
2453 complain (&unknown_st_complaint
, sh
.st
);
2457 /* Use this gdb symbol */
2458 ADD_PSYMBOL_TO_LIST (name
, strlen (name
),
2459 VAR_NAMESPACE
, class,
2460 objfile
->static_psymbols
, sh
.value
,
2461 psymtab_language
, objfile
);
2463 cur_sdx
++; /* Go to next file symbol */
2466 /* Now do enter the external symbols. */
2467 ext_ptr
= &extern_tab
[fdr_to_pst
[f_idx
].globals_offset
];
2468 cur_sdx
= fdr_to_pst
[f_idx
].n_globals
;
2469 PST_PRIVATE (save_pst
)->extern_count
= cur_sdx
;
2470 PST_PRIVATE (save_pst
)->extern_tab
= ext_ptr
;
2471 for (; --cur_sdx
>= 0; ext_ptr
++)
2473 enum address_class
class;
2477 if (ext_ptr
->ifd
!= f_idx
)
2479 psh
= &ext_ptr
->asym
;
2481 /* Do not add undefined symbols to the partial symbol table. */
2482 if (psh
->sc
== scUndefined
|| psh
->sc
== scNil
)
2488 /* These are generated for static symbols in .o files,
2499 complain (&unknown_ext_complaint
,
2500 debug_info
->ssext
+ psh
->iss
);
2501 /* Fall through, pretend it's global. */
2506 name
= debug_info
->ssext
+ psh
->iss
;
2507 ADD_PSYMBOL_ADDR_TO_LIST (name
, strlen (name
),
2508 VAR_NAMESPACE
, class,
2509 objfile
->global_psymbols
,
2510 (CORE_ADDR
) psh
->value
,
2511 psymtab_language
, objfile
);
2515 /* Link pst to FDR. end_psymtab returns NULL if the psymtab was
2516 empty and put on the free list. */
2517 fdr_to_pst
[f_idx
].pst
= end_psymtab (save_pst
,
2518 psymtab_include_list
, includes_used
,
2519 -1, save_pst
->texthigh
,
2520 dependency_list
, dependencies_used
);
2521 if (objfile
->ei
.entry_point
>= save_pst
->textlow
&&
2522 objfile
->ei
.entry_point
< save_pst
->texthigh
)
2524 objfile
->ei
.entry_file_lowpc
= save_pst
->textlow
;
2525 objfile
->ei
.entry_file_highpc
= save_pst
->texthigh
;
2529 /* Now scan the FDRs for dependencies */
2530 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++)
2532 fh
= f_idx
+ debug_info
->fdr
;
2533 pst
= fdr_to_pst
[f_idx
].pst
;
2535 if (pst
== (struct partial_symtab
*)NULL
)
2538 /* This should catch stabs-in-ecoff. */
2542 /* Skip the first file indirect entry as it is a self dependency
2543 for source files or a reverse .h -> .c dependency for header files. */
2544 pst
->number_of_dependencies
= 0;
2546 ((struct partial_symtab
**)
2547 obstack_alloc (&objfile
->psymbol_obstack
,
2549 * sizeof (struct partial_symtab
*))));
2550 for (s_idx
= 1; s_idx
< fh
->crfd
; s_idx
++)
2554 (*swap_rfd_in
) (cur_bfd
,
2555 ((char *) debug_info
->external_rfd
2556 + (fh
->rfdBase
+ s_idx
) * external_rfd_size
),
2558 if (rh
< 0 || rh
>= hdr
->ifdMax
)
2560 complain (&bad_file_number_complaint
, rh
);
2564 /* Skip self dependencies of header files. */
2568 /* Do not add to dependeny list if psymtab was empty. */
2569 if (fdr_to_pst
[rh
].pst
== (struct partial_symtab
*)NULL
)
2571 pst
->dependencies
[pst
->number_of_dependencies
++] = fdr_to_pst
[rh
].pst
;
2574 do_cleanups (old_chain
);
2579 mdebug_next_symbol_text ()
2584 (*debug_swap
->swap_sym_in
) (cur_bfd
,
2585 ((char *) debug_info
->external_sym
2586 + ((cur_fdr
->isymBase
+ cur_sdx
)
2587 * debug_swap
->external_sym_size
)),
2589 return debug_info
->ss
+ cur_fdr
->issBase
+ sh
.iss
;
2592 /* Ancillary function to psymtab_to_symtab(). Does all the work
2593 for turning the partial symtab PST into a symtab, recurring
2594 first on all dependent psymtabs. The argument FILENAME is
2595 only passed so we can see in debug stack traces what file
2598 This function has a split personality, based on whether the
2599 symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
2600 The flow of control and even the memory allocation differs. FIXME. */
2603 psymtab_to_symtab_1 (pst
, filename
)
2604 struct partial_symtab
*pst
;
2607 bfd_size_type external_sym_size
;
2608 bfd_size_type external_pdr_size
;
2609 void (*swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*));
2610 void (*swap_pdr_in
) PARAMS ((bfd
*, PTR
, PDR
*));
2614 struct linetable
*lines
;
2620 /* Read in all partial symbtabs on which this one is dependent.
2621 NOTE that we do have circular dependencies, sigh. We solved
2622 that by setting pst->readin before this point. */
2624 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2625 if (!pst
->dependencies
[i
]->readin
)
2627 /* Inform about additional files to be read in. */
2630 fputs_filtered (" ", gdb_stdout
);
2632 fputs_filtered ("and ", gdb_stdout
);
2634 printf_filtered ("%s...",
2635 pst
->dependencies
[i
]->filename
);
2636 wrap_here (""); /* Flush output */
2637 gdb_flush (gdb_stdout
);
2639 /* We only pass the filename for debug purposes */
2640 psymtab_to_symtab_1 (pst
->dependencies
[i
],
2641 pst
->dependencies
[i
]->filename
);
2644 /* Do nothing if this is a dummy psymtab. */
2646 if (pst
->n_global_syms
== 0 && pst
->n_static_syms
== 0
2647 && pst
->textlow
== 0 && pst
->texthigh
== 0)
2650 /* Now read the symbols for this symtab */
2652 cur_bfd
= CUR_BFD (pst
);
2653 debug_swap
= DEBUG_SWAP (pst
);
2654 debug_info
= DEBUG_INFO (pst
);
2655 pending_list
= PENDING_LIST (pst
);
2656 external_sym_size
= debug_swap
->external_sym_size
;
2657 external_pdr_size
= debug_swap
->external_pdr_size
;
2658 swap_sym_in
= debug_swap
->swap_sym_in
;
2659 swap_pdr_in
= debug_swap
->swap_pdr_in
;
2660 current_objfile
= pst
->objfile
;
2661 cur_fd
= FDR_IDX (pst
);
2662 fh
= ((cur_fd
== -1)
2664 : debug_info
->fdr
+ cur_fd
);
2667 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2668 processing_gcc_compilation
= 0;
2669 if (fh
!= (FDR
*) NULL
&& fh
->csym
>= 2)
2673 (*swap_sym_in
) (cur_bfd
,
2674 ((char *) debug_info
->external_sym
2675 + (fh
->isymBase
+ 1) * external_sym_size
),
2677 if (STREQ (debug_info
->ss
+ fh
->issBase
+ sh
.iss
,
2680 /* We indicate that this is a GCC compilation so that certain
2681 features will be enabled in stabsread/dbxread. */
2682 processing_gcc_compilation
= 2;
2686 if (processing_gcc_compilation
!= 0)
2691 unsigned long first_off
= 0;
2693 /* This symbol table contains stabs-in-ecoff entries. */
2695 /* Parse local symbols first */
2697 if (fh
->csym
<= 2) /* FIXME, this blows psymtab->symtab ptr */
2699 current_objfile
= NULL
;
2702 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++)
2708 (*swap_sym_in
) (cur_bfd
,
2709 (((char *) debug_info
->external_sym
)
2710 + (fh
->isymBase
+ cur_sdx
) * external_sym_size
),
2712 name
= debug_info
->ss
+ fh
->issBase
+ sh
.iss
;
2714 if (ECOFF_IS_STAB (&sh
))
2716 int type_code
= ECOFF_UNMARK_STAB (sh
.index
);
2718 /* We should never get non N_STAB symbols here, but they
2719 should be harmless, so keep process_one_symbol from
2720 complaining about them. */
2721 if (type_code
& N_STAB
)
2723 process_one_symbol (type_code
, 0, valu
, name
,
2724 pst
->section_offsets
, pst
->objfile
);
2726 if (type_code
== N_FUN
)
2728 /* Make up special symbol to contain
2729 procedure specific info */
2730 struct mips_extra_func_info
*e
=
2731 ((struct mips_extra_func_info
*)
2732 obstack_alloc (¤t_objfile
->symbol_obstack
,
2733 sizeof (struct mips_extra_func_info
)));
2734 struct symbol
*s
= new_symbol (MIPS_EFI_SYMBOL_NAME
);
2735 SYMBOL_NAMESPACE (s
) = LABEL_NAMESPACE
;
2736 SYMBOL_CLASS (s
) = LOC_CONST
;
2737 SYMBOL_TYPE (s
) = builtin_type_void
;
2738 SYMBOL_VALUE (s
) = (long) e
;
2739 add_symbol_to_list (s
, &local_symbols
);
2742 else if (sh
.st
== stLabel
&& sh
.index
!= indexNil
)
2744 /* Handle encoded stab line number. */
2745 record_line (current_subfile
, sh
.index
, valu
);
2747 else if (sh
.st
== stProc
|| sh
.st
== stStaticProc
|| sh
.st
== stEnd
)
2748 /* These are generated by gcc-2.x, do not complain */
2751 complain (&stab_unknown_complaint
, name
);
2753 st
= end_symtab (pst
->texthigh
, 0, 0, pst
->objfile
, SECT_OFF_TEXT
);
2756 /* Sort the symbol table now, we are done adding symbols to it.
2757 We must do this before parse_procedure calls lookup_symbol. */
2758 sort_symtab_syms (st
);
2760 /* This may not be necessary for stabs symtabs. FIXME. */
2763 /* Fill in procedure info next. */
2765 pdr_ptr
= ((char *) debug_info
->external_pdr
2766 + fh
->ipdFirst
* external_pdr_size
);
2767 pdr_end
= pdr_ptr
+ fh
->cpd
* external_pdr_size
;
2768 for (; pdr_ptr
< pdr_end
; pdr_ptr
+= external_pdr_size
)
2772 (*swap_pdr_in
) (cur_bfd
, pdr_ptr
, &pr
);
2778 parse_procedure (&pr
, st
, first_off
);
2783 /* This symbol table contains ordinary ecoff entries. */
2785 /* FIXME: doesn't use pst->section_offsets. */
2791 /* How many symbols will we need */
2792 /* FIXME, this does not count enum values. */
2793 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
2797 st
= new_symtab ("unknown", f_max
, 0, pst
->objfile
);
2801 f_max
+= fh
->csym
+ fh
->cpd
;
2802 maxlines
= 2 * fh
->cline
;
2803 st
= new_symtab (pst
->filename
, 2 * f_max
, maxlines
, pst
->objfile
);
2805 /* The proper language was already determined when building
2806 the psymtab, use it. */
2807 st
->language
= PST_PRIVATE (pst
)->pst_language
;
2810 psymtab_language
= st
->language
;
2812 lines
= LINETABLE (st
);
2814 /* Get a new lexical context */
2816 push_parse_stack ();
2817 top_stack
->cur_st
= st
;
2818 top_stack
->cur_block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (st
),
2820 BLOCK_START (top_stack
->cur_block
) = fh
? fh
->adr
: 0;
2821 BLOCK_END (top_stack
->cur_block
) = 0;
2822 top_stack
->blocktype
= stFile
;
2823 top_stack
->maxsyms
= 2 * f_max
;
2824 top_stack
->cur_type
= 0;
2825 top_stack
->procadr
= 0;
2826 top_stack
->numargs
= 0;
2833 /* Parse local symbols first */
2834 sym_ptr
= ((char *) debug_info
->external_sym
2835 + fh
->isymBase
* external_sym_size
);
2836 sym_end
= sym_ptr
+ fh
->csym
* external_sym_size
;
2837 while (sym_ptr
< sym_end
)
2842 (*swap_sym_in
) (cur_bfd
, sym_ptr
, &sh
);
2843 c
= parse_symbol (&sh
,
2844 debug_info
->external_aux
+ fh
->iauxBase
,
2845 sym_ptr
, fh
->fBigendian
);
2846 sym_ptr
+= c
* external_sym_size
;
2849 /* Linenumbers. At the end, check if we can save memory.
2850 parse_lines has to look ahead an arbitrary number of PDR
2851 structures, so we swap them all first. */
2855 struct cleanup
*old_chain
;
2861 pr_block
= (PDR
*) xmalloc (fh
->cpd
* sizeof (PDR
));
2863 old_chain
= make_cleanup (free
, pr_block
);
2865 pdr_ptr
= ((char *) debug_info
->external_pdr
2866 + fh
->ipdFirst
* external_pdr_size
);
2867 pdr_end
= pdr_ptr
+ fh
->cpd
* external_pdr_size
;
2871 pdr_ptr
+= external_pdr_size
, pdr_in
++)
2872 (*swap_pdr_in
) (cur_bfd
, pdr_ptr
, pdr_in
);
2874 parse_lines (fh
, pr_block
, lines
, maxlines
);
2875 if (lines
->nitems
< fh
->cline
)
2876 lines
= shrink_linetable (lines
);
2878 /* Fill in procedure info next. */
2880 pdr_in_end
= pdr_in
+ fh
->cpd
;
2881 for (; pdr_in
< pdr_in_end
; pdr_in
++)
2882 parse_procedure (pdr_in
, 0, pr_block
->adr
);
2884 do_cleanups (old_chain
);
2888 LINETABLE (st
) = lines
;
2890 /* .. and our share of externals.
2891 XXX use the global list to speed up things here. how?
2892 FIXME, Maybe quit once we have found the right number of ext's? */
2893 top_stack
->cur_st
= st
;
2894 top_stack
->cur_block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack
->cur_st
),
2896 top_stack
->blocktype
= stFile
;
2898 = (debug_info
->symbolic_header
.isymMax
2899 + debug_info
->symbolic_header
.ipdMax
2900 + debug_info
->symbolic_header
.iextMax
);
2902 ext_ptr
= PST_PRIVATE (pst
)->extern_tab
;
2903 for (i
= PST_PRIVATE (pst
)->extern_count
; --i
>= 0; ext_ptr
++)
2904 parse_external (ext_ptr
, 1, fh
->fBigendian
);
2906 /* If there are undefined symbols, tell the user.
2907 The alpha has an undefined symbol for every symbol that is
2908 from a shared library, so tell the user only if verbose is on. */
2909 if (info_verbose
&& n_undef_symbols
)
2911 printf_filtered ("File %s contains %d unresolved references:",
2912 st
->filename
, n_undef_symbols
);
2913 printf_filtered ("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2914 n_undef_vars
, n_undef_procs
, n_undef_labels
);
2915 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
2920 /* Sort the symbol table now, we are done adding symbols to it.*/
2921 sort_symtab_syms (st
);
2926 /* Now link the psymtab and the symtab. */
2929 current_objfile
= NULL
;
2932 /* Ancillary parsing procedures. */
2934 /* Lookup the type at relative index RN. Return it in TPP
2935 if found and in any event come up with its name PNAME.
2936 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
2937 Return value says how many aux symbols we ate. */
2940 cross_ref (fd
, ax
, tpp
, type_code
, pname
, bigend
, sym_name
)
2944 enum type_code type_code
; /* Use to alloc new type if none is found. */
2956 struct mdebug_pending
*pend
;
2958 *tpp
= (struct type
*)NULL
;
2960 ecoff_swap_rndx_in (bigend
, &ax
->a_rndx
, rn
);
2962 /* Escape index means 'the next one' */
2963 if (rn
->rfd
== 0xfff)
2966 rf
= AUX_GET_ISYM (bigend
, ax
+ 1);
2973 /* mips cc uses a rf of -1 for opaque struct definitions.
2974 Set TYPE_FLAG_STUB for these types so that check_stub_type will
2975 resolve them if the struct gets defined in another compilation unit. */
2978 *pname
= "<undefined>";
2979 *tpp
= init_type (type_code
, 0, 0, (char *) NULL
, current_objfile
);
2980 TYPE_FLAGS (*tpp
) |= TYPE_FLAG_STUB
;
2984 /* mips cc uses an escaped rn->index of 0 for struct return types
2985 of procedures that were compiled without -g. These will always remain
2987 if (rn
->rfd
== 0xfff && rn
->index
== 0)
2989 *pname
= "<undefined>";
2993 /* Find the relative file descriptor and the symbol in it. */
2994 fh
= get_rfd (fd
, rf
);
2995 xref_fd
= fh
- debug_info
->fdr
;
2997 if (rn
->index
>= fh
->csym
)
2999 /* File indirect entry is corrupt. */
3000 *pname
= "<illegal>";
3001 complain (&bad_rfd_entry_complaint
,
3002 sym_name
, xref_fd
, rn
->index
);
3006 /* If we have processed this symbol then we left a forwarding
3007 pointer to the type in the pending list. If not, we`ll put
3008 it in a list of pending types, to be processed later when
3009 the file will be. In any event, we collect the name for the
3012 esh
= ((char *) debug_info
->external_sym
3013 + ((fh
->isymBase
+ rn
->index
)
3014 * debug_swap
->external_sym_size
));
3015 (*debug_swap
->swap_sym_in
) (cur_bfd
, esh
, &sh
);
3017 /* Make sure that this type of cross reference can be handled. */
3019 || (sh
.st
!= stBlock
&& sh
.st
!= stTypedef
3020 && sh
.st
!= stStruct
&& sh
.st
!= stUnion
3021 && sh
.st
!= stEnum
))
3023 /* File indirect entry is corrupt. */
3024 *pname
= "<illegal>";
3025 complain (&bad_rfd_entry_complaint
,
3026 sym_name
, xref_fd
, rn
->index
);
3030 *pname
= debug_info
->ss
+ fh
->issBase
+ sh
.iss
;
3032 pend
= is_pending_symbol (fh
, esh
);
3037 /* We have not yet seen this type. */
3039 if (sh
.iss
== 0 && sh
.st
== stTypedef
)
3043 /* alpha cc puts out a stTypedef with a sh.iss of zero for
3045 a) forward declarations of structs/unions/enums which are not
3046 defined in this compilation unit.
3047 For these the type will be void. This is a bad design decision
3048 as cross referencing across compilation units is impossible
3049 due to the missing name.
3050 b) forward declarations of structs/unions/enums which are defined
3051 later in this file or in another file in the same compilation
3052 unit. Simply cross reference those again to get the
3054 The forward references are not entered in the pending list and
3055 in the symbol table. */
3057 ecoff_swap_tir_in (bigend
,
3058 &(debug_info
->external_aux
3059 + fh
->iauxBase
+ sh
.index
)->a_ti
,
3061 if (tir
.tq0
!= tqNil
)
3062 complain (&illegal_forward_tq0_complaint
, sym_name
);
3066 *tpp
= init_type (type_code
, 0, 0, (char *) NULL
,
3068 *pname
= "<undefined>";
3075 (debug_info
->external_aux
3076 + fh
->iauxBase
+ sh
.index
+ 1),
3077 tpp
, type_code
, pname
,
3078 fh
->fBigendian
, sym_name
);
3082 complain (&illegal_forward_bt_complaint
, tir
.bt
, sym_name
);
3083 *tpp
= init_type (type_code
, 0, 0, (char *) NULL
,
3089 else if (sh
.st
== stTypedef
)
3091 /* Parse the type for a normal typedef. This might recursively call
3092 cross_ref till we get a non typedef'ed type.
3093 FIXME: This is not correct behaviour, but gdb currently
3094 cannot handle typedefs without type copying. But type copying is
3095 impossible as we might have mutual forward references between
3096 two files and the copied type would not get filled in when
3097 we later parse its definition. */
3098 *tpp
= parse_type (xref_fd
,
3099 debug_info
->external_aux
+ fh
->iauxBase
,
3103 debug_info
->ss
+ fh
->issBase
+ sh
.iss
);
3107 /* Cross reference to a struct/union/enum which is defined
3108 in another file in the same compilation unit but that file
3109 has not been parsed yet.
3110 Initialize the type only, it will be filled in when
3111 it's definition is parsed. */
3112 *tpp
= init_type (type_code
, 0, 0, (char *) NULL
, current_objfile
);
3114 add_pending (fh
, esh
, *tpp
);
3117 /* We used one auxent normally, two if we got a "next one" rf. */
3122 /* Quick&dirty lookup procedure, to avoid the MI ones that require
3123 keeping the symtab sorted */
3125 static struct symbol
*
3126 mylookup_symbol (name
, block
, namespace, class)
3128 register struct block
*block
;
3129 enum namespace namespace;
3130 enum address_class
class;
3132 register int bot
, top
, inc
;
3133 register struct symbol
*sym
;
3136 top
= BLOCK_NSYMS (block
);
3140 sym
= BLOCK_SYM (block
, bot
);
3141 if (SYMBOL_NAME (sym
)[0] == inc
3142 && SYMBOL_NAMESPACE (sym
) == namespace
3143 && SYMBOL_CLASS (sym
) == class
3144 && strcmp (SYMBOL_NAME (sym
), name
) == 0)
3148 block
= BLOCK_SUPERBLOCK (block
);
3150 return mylookup_symbol (name
, block
, namespace, class);
3155 /* Add a new symbol S to a block B.
3156 Infrequently, we will need to reallocate the block to make it bigger.
3157 We only detect this case when adding to top_stack->cur_block, since
3158 that's the only time we know how big the block is. FIXME. */
3165 int nsyms
= BLOCK_NSYMS (b
)++;
3166 struct block
*origb
;
3167 struct parse_stack
*stackp
;
3169 if (b
== top_stack
->cur_block
&&
3170 nsyms
>= top_stack
->maxsyms
)
3172 complain (&block_overflow_complaint
, SYMBOL_NAME (s
));
3173 /* In this case shrink_block is actually grow_block, since
3174 BLOCK_NSYMS(b) is larger than its current size. */
3176 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
3178 /* Now run through the stack replacing pointers to the
3179 original block. shrink_block has already done this
3180 for the blockvector and BLOCK_FUNCTION. */
3181 for (stackp
= top_stack
; stackp
; stackp
= stackp
->next
)
3183 if (stackp
->cur_block
== origb
)
3185 stackp
->cur_block
= b
;
3186 stackp
->maxsyms
= BLOCK_NSYMS (b
);
3190 BLOCK_SYM (b
, nsyms
) = s
;
3193 /* Add a new block B to a symtab S */
3200 struct blockvector
*bv
= BLOCKVECTOR (s
);
3202 bv
= (struct blockvector
*) xrealloc ((PTR
) bv
,
3203 (sizeof (struct blockvector
)
3204 + BLOCKVECTOR_NBLOCKS (bv
)
3205 * sizeof (bv
->block
)));
3206 if (bv
!= BLOCKVECTOR (s
))
3207 BLOCKVECTOR (s
) = bv
;
3209 BLOCKVECTOR_BLOCK (bv
, BLOCKVECTOR_NBLOCKS (bv
)++) = b
;
3212 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
3213 MIPS' linenumber encoding might need more than one byte
3214 to describe it, LAST is used to detect these continuation lines.
3216 Combining lines with the same line number seems like a bad idea.
3217 E.g: There could be a line number entry with the same line number after the
3218 prologue and GDB should not ignore it (this is a better way to find
3219 a prologue than mips_skip_prologue).
3220 But due to the compressed line table format there are line number entries
3221 for the same line which are needed to bridge the gap to the next
3222 line number entry. These entries have a bogus address info with them
3223 and we are unable to tell them from intended duplicate line number
3225 This is another reason why -ggdb debugging format is preferable. */
3228 add_line (lt
, lineno
, adr
, last
)
3229 struct linetable
*lt
;
3234 /* DEC c89 sometimes produces zero linenos which confuse gdb.
3235 Change them to something sensible. */
3239 last
= -2; /* make sure we record first line */
3241 if (last
== lineno
) /* skip continuation lines */
3244 lt
->item
[lt
->nitems
].line
= lineno
;
3245 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
3249 /* Sorting and reordering procedures */
3251 /* Blocks with a smaller low bound should come first */
3254 compare_blocks (arg1
, arg2
)
3258 register int addr_diff
;
3259 struct block
**b1
= (struct block
**) arg1
;
3260 struct block
**b2
= (struct block
**) arg2
;
3262 addr_diff
= (BLOCK_START ((*b1
))) - (BLOCK_START ((*b2
)));
3264 return (BLOCK_END ((*b2
))) - (BLOCK_END ((*b1
)));
3268 /* Sort the blocks of a symtab S.
3269 Reorder the blocks in the blockvector by code-address,
3270 as required by some MI search routines */
3276 struct blockvector
*bv
= BLOCKVECTOR (s
);
3278 if (BLOCKVECTOR_NBLOCKS (bv
) <= 2)
3281 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) == 0)
3282 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) = 0;
3283 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) == 0)
3284 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) = 0;
3288 * This is very unfortunate: normally all functions are compiled in
3289 * the order they are found, but if the file is compiled -O3 things
3290 * are very different. It would be nice to find a reliable test
3291 * to detect -O3 images in advance.
3293 if (BLOCKVECTOR_NBLOCKS (bv
) > 3)
3294 qsort (&BLOCKVECTOR_BLOCK (bv
, FIRST_LOCAL_BLOCK
),
3295 BLOCKVECTOR_NBLOCKS (bv
) - FIRST_LOCAL_BLOCK
,
3296 sizeof (struct block
*),
3300 register CORE_ADDR high
= 0;
3301 register int i
, j
= BLOCKVECTOR_NBLOCKS (bv
);
3303 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
3304 if (high
< BLOCK_END (BLOCKVECTOR_BLOCK (bv
, i
)))
3305 high
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, i
));
3306 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) = high
;
3309 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) =
3310 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, FIRST_LOCAL_BLOCK
));
3312 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) =
3313 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
3314 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) =
3315 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
3319 /* Constructor/restructor/destructor procedures */
3321 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
3322 MAXSYMS and linenumbers MAXLINES we'll put in it */
3324 static struct symtab
*
3325 new_symtab (name
, maxsyms
, maxlines
, objfile
)
3329 struct objfile
*objfile
;
3331 struct symtab
*s
= allocate_symtab (name
, objfile
);
3333 LINETABLE (s
) = new_linetable (maxlines
);
3335 /* All symtabs must have at least two blocks */
3336 BLOCKVECTOR (s
) = new_bvect (2);
3337 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
) = new_block (maxsyms
);
3338 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
) = new_block (maxsyms
);
3339 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)) =
3340 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3342 s
->free_code
= free_linetable
;
3347 /* Allocate a new partial_symtab NAME */
3349 static struct partial_symtab
*
3350 new_psymtab (name
, objfile
)
3352 struct objfile
*objfile
;
3354 struct partial_symtab
*psymtab
;
3356 psymtab
= allocate_psymtab (name
, objfile
);
3358 /* Keep a backpointer to the file's symbols */
3360 psymtab
->read_symtab_private
= ((char *)
3361 obstack_alloc (&objfile
->psymbol_obstack
,
3362 sizeof (struct symloc
)));
3363 memset ((PTR
) psymtab
->read_symtab_private
, 0, sizeof (struct symloc
));
3364 CUR_BFD (psymtab
) = cur_bfd
;
3365 DEBUG_SWAP (psymtab
) = debug_swap
;
3366 DEBUG_INFO (psymtab
) = debug_info
;
3367 PENDING_LIST (psymtab
) = pending_list
;
3369 /* The way to turn this into a symtab is to call... */
3370 psymtab
->read_symtab
= mdebug_psymtab_to_symtab
;
3375 /* Allocate a linetable array of the given SIZE. Since the struct
3376 already includes one item, we subtract one when calculating the
3377 proper size to allocate. */
3379 static struct linetable
*
3380 new_linetable (size
)
3383 struct linetable
*l
;
3385 size
= (size
- 1) * sizeof (l
->item
) + sizeof (struct linetable
);
3386 l
= (struct linetable
*) xmalloc (size
);
3391 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
3392 I am not so sure about the 3.4 ones.
3394 Since the struct linetable already includes one item, we subtract one when
3395 calculating the proper size to allocate. */
3397 static struct linetable
*
3398 shrink_linetable (lt
)
3399 struct linetable
*lt
;
3402 return (struct linetable
*) xrealloc ((PTR
) lt
,
3403 (sizeof (struct linetable
)
3405 * sizeof (lt
->item
))));
3408 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
3410 static struct blockvector
*
3414 struct blockvector
*bv
;
3417 size
= sizeof (struct blockvector
) + nblocks
* sizeof (struct block
*);
3418 bv
= (struct blockvector
*) xzalloc (size
);
3420 BLOCKVECTOR_NBLOCKS (bv
) = nblocks
;
3425 /* Allocate and zero a new block of MAXSYMS symbols */
3427 static struct block
*
3431 int size
= sizeof (struct block
) + (maxsyms
- 1) * sizeof (struct symbol
*);
3433 return (struct block
*) xzalloc (size
);
3436 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
3437 Shrink_block can also be used by add_symbol to grow a block. */
3439 static struct block
*
3445 struct blockvector
*bv
= BLOCKVECTOR (s
);
3448 /* Just reallocate it and fix references to the old one */
3450 new = (struct block
*) xrealloc ((PTR
) b
,
3451 (sizeof (struct block
)
3452 + ((BLOCK_NSYMS (b
) - 1)
3453 * sizeof (struct symbol
*))));
3455 /* Should chase pointers to old one. Fortunately, that`s just
3456 the block`s function and inferior blocks */
3457 if (BLOCK_FUNCTION (new) && SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) == b
)
3458 SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) = new;
3459 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS (bv
); i
++)
3460 if (BLOCKVECTOR_BLOCK (bv
, i
) == b
)
3461 BLOCKVECTOR_BLOCK (bv
, i
) = new;
3462 else if (BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv
, i
)) == b
)
3463 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv
, i
)) = new;
3467 /* Create a new symbol with printname NAME */
3469 static struct symbol
*
3473 struct symbol
*s
= ((struct symbol
*)
3474 obstack_alloc (¤t_objfile
->symbol_obstack
,
3475 sizeof (struct symbol
)));
3477 memset ((PTR
) s
, 0, sizeof (*s
));
3478 SYMBOL_NAME (s
) = name
;
3479 SYMBOL_LANGUAGE (s
) = psymtab_language
;
3480 SYMBOL_INIT_DEMANGLED_NAME (s
, ¤t_objfile
->symbol_obstack
);
3484 /* Create a new type with printname NAME */
3486 static struct type
*
3492 t
= alloc_type (current_objfile
);
3493 TYPE_NAME (t
) = name
;
3494 TYPE_CPLUS_SPECIFIC (t
) = (struct cplus_struct_type
*) &cplus_struct_default
;
3498 /* Read ECOFF debugging information from a BFD section. This is
3499 called from elfread.c. It parses the section into a
3500 ecoff_debug_info struct, and then lets the rest of the file handle
3504 elfmdebug_build_psymtabs (objfile
, swap
, sec
, section_offsets
)
3505 struct objfile
*objfile
;
3506 const struct ecoff_debug_swap
*swap
;
3508 struct section_offsets
*section_offsets
;
3510 bfd
*abfd
= objfile
->obfd
;
3512 struct ecoff_debug_info
*info
;
3514 buf
= alloca (swap
->external_hdr_size
);
3515 if (bfd_get_section_contents (abfd
, sec
, buf
, (file_ptr
) 0,
3516 swap
->external_hdr_size
) == false)
3517 perror_with_name (bfd_get_filename (abfd
));
3519 info
= ((struct ecoff_debug_info
*)
3520 obstack_alloc (&objfile
->psymbol_obstack
,
3521 sizeof (struct ecoff_debug_info
)));
3523 (*swap
->swap_hdr_in
) (abfd
, buf
, &info
->symbolic_header
);
3525 /* The offsets in symbolic_header are file offsets, not section
3526 offsets. Strangely, on Irix 5 the information is not entirely
3527 within the .mdebug section. There are parts of an executable
3528 file which are not within any ELF section at all. This means
3529 that we must read the information using bfd_read. */
3531 #define READ(ptr, count, off, size, type) \
3534 if (info->symbolic_header.count == 0) \
3535 info->ptr = (type) NULL; \
3538 info->ptr = ((type) \
3539 obstack_alloc (&objfile->psymbol_obstack, \
3540 (info->symbolic_header.count \
3542 if (bfd_seek (abfd, info->symbolic_header.off, SEEK_SET) < 0 \
3543 || (bfd_read ((PTR) info->ptr, size, \
3544 info->symbolic_header.count, abfd) \
3545 != info->symbolic_header.count * size)) \
3546 perror_with_name (bfd_get_filename (abfd)); \
3551 READ (line
, cbLine
, cbLineOffset
, sizeof (unsigned char), unsigned char *);
3552 READ (external_dnr
, idnMax
, cbDnOffset
, swap
->external_dnr_size
, PTR
);
3553 READ (external_pdr
, ipdMax
, cbPdOffset
, swap
->external_pdr_size
, PTR
);
3554 READ (external_sym
, isymMax
, cbSymOffset
, swap
->external_sym_size
, PTR
);
3555 READ (external_opt
, ioptMax
, cbOptOffset
, swap
->external_opt_size
, PTR
);
3556 READ (external_aux
, iauxMax
, cbAuxOffset
, sizeof (union aux_ext
),
3558 READ (ss
, issMax
, cbSsOffset
, sizeof (char), char *);
3559 READ (ssext
, issExtMax
, cbSsExtOffset
, sizeof (char), char *);
3560 READ (external_fdr
, ifdMax
, cbFdOffset
, swap
->external_fdr_size
, PTR
);
3561 READ (external_rfd
, crfd
, cbRfdOffset
, swap
->external_rfd_size
, PTR
);
3562 READ (external_ext
, iextMax
, cbExtOffset
, swap
->external_ext_size
, PTR
);
3568 mdebug_build_psymtabs (objfile
, swap
, info
, section_offsets
);
3572 /* Things used for calling functions in the inferior.
3573 These functions are exported to our companion
3574 mips-tdep.c file and are here because they play
3575 with the symbol-table explicitly. */
3577 /* Sigtramp: make sure we have all the necessary information
3578 about the signal trampoline code. Since the official code
3579 from MIPS does not do so, we make up that information ourselves.
3580 If they fix the library (unlikely) this code will neutralize itself. */
3582 /* FIXME: This function is called only by mips-tdep.c. It needs to be
3583 here because it calls functions defined in this file, but perhaps
3584 this could be handled in a better way. */
3591 struct block
*b
, *b0
= NULL
;
3593 sigtramp_address
= -1;
3595 /* We have to handle the following cases here:
3596 a) The Mips library has a sigtramp label within sigvec.
3597 b) Irix has a _sigtramp which we want to use, but it also has sigvec. */
3598 s
= lookup_symbol ("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
3601 b0
= SYMBOL_BLOCK_VALUE (s
);
3602 s
= lookup_symbol ("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
3606 /* No sigvec or no sigtramp inside sigvec, try _sigtramp. */
3607 s
= lookup_symbol ("_sigtramp", 0, VAR_NAMESPACE
, 0, NULL
);
3610 /* But maybe this program uses its own version of sigvec */
3614 /* Did we or MIPSco fix the library ? */
3615 if (SYMBOL_CLASS (s
) == LOC_BLOCK
)
3617 sigtramp_address
= BLOCK_START (SYMBOL_BLOCK_VALUE (s
));
3618 sigtramp_end
= BLOCK_END (SYMBOL_BLOCK_VALUE (s
));
3622 sigtramp_address
= SYMBOL_VALUE (s
);
3623 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
3625 /* But what symtab does it live in ? */
3626 st
= find_pc_symtab (SYMBOL_VALUE (s
));
3629 * Ok, there goes the fix: turn it into a procedure, with all the
3630 * needed info. Note we make it a nested procedure of sigvec,
3631 * which is the way the (assembly) code is actually written.
3633 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
3634 SYMBOL_CLASS (s
) = LOC_BLOCK
;
3635 SYMBOL_TYPE (s
) = init_type (TYPE_CODE_FUNC
, 4, 0, (char *) NULL
,
3637 TYPE_TARGET_TYPE (SYMBOL_TYPE (s
)) = builtin_type_void
;
3639 /* Need a block to allocate MIPS_EFI_SYMBOL_NAME in */
3641 SYMBOL_BLOCK_VALUE (s
) = b
;
3642 BLOCK_START (b
) = sigtramp_address
;
3643 BLOCK_END (b
) = sigtramp_end
;
3644 BLOCK_FUNCTION (b
) = s
;
3645 BLOCK_SUPERBLOCK (b
) = BLOCK_SUPERBLOCK (b0
);
3649 /* Make a MIPS_EFI_SYMBOL_NAME entry for it */
3651 struct mips_extra_func_info
*e
=
3652 ((struct mips_extra_func_info
*)
3653 xzalloc (sizeof (struct mips_extra_func_info
)));
3655 e
->numargs
= 0; /* the kernel thinks otherwise */
3656 /* align_longword(sigcontext + SIGFRAME) */
3657 e
->pdr
.frameoffset
= 0x150;
3658 e
->pdr
.framereg
= SP_REGNUM
;
3659 /* read_next_frame_reg provides the true pc at the time of signal */
3660 e
->pdr
.pcreg
= PC_REGNUM
;
3661 e
->pdr
.regmask
= -2;
3662 e
->pdr
.regoffset
= -(41 * sizeof (int));
3663 e
->pdr
.fregmask
= -1;
3664 e
->pdr
.fregoffset
= -(7 * sizeof (int));
3665 e
->pdr
.isym
= (long) s
;
3666 e
->pdr
.adr
= sigtramp_address
;
3668 current_objfile
= st
->objfile
; /* Keep new_symbol happy */
3669 s
= new_symbol (MIPS_EFI_SYMBOL_NAME
);
3670 SYMBOL_VALUE (s
) = (long) e
;
3671 SYMBOL_NAMESPACE (s
) = LABEL_NAMESPACE
;
3672 SYMBOL_CLASS (s
) = LOC_CONST
;
3673 SYMBOL_TYPE (s
) = builtin_type_void
;
3674 current_objfile
= NULL
;
3677 BLOCK_SYM (b
, BLOCK_NSYMS (b
)++) = s
;
3681 _initialize_mdebugread ()
3683 /* Missing basic types */
3685 /* Is a "string" the way btString means it the same as TYPE_CODE_STRING?
3687 mdebug_type_string
=
3688 init_type (TYPE_CODE_STRING
,
3689 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
3691 (struct objfile
*) NULL
);
3693 mdebug_type_complex
=
3694 init_type (TYPE_CODE_ERROR
,
3695 TARGET_COMPLEX_BIT
/ TARGET_CHAR_BIT
,
3697 (struct objfile
*) NULL
);
3698 mdebug_type_double_complex
=
3699 init_type (TYPE_CODE_ERROR
,
3700 TARGET_DOUBLE_COMPLEX_BIT
/ TARGET_CHAR_BIT
,
3701 0, "double complex",
3702 (struct objfile
*) NULL
);
3704 /* We use TYPE_CODE_INT to print these as integers. Does this do any
3705 good? Would we be better off with TYPE_CODE_ERROR? Should
3706 TYPE_CODE_ERROR print things in hex if it knows the size? */
3707 mdebug_type_fixed_dec
=
3708 init_type (TYPE_CODE_INT
,
3709 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3711 (struct objfile
*) NULL
);
3713 mdebug_type_float_dec
=
3714 init_type (TYPE_CODE_ERROR
,
3715 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
3716 0, "floating decimal",
3717 (struct objfile
*) NULL
);