1 /* Read a symbol table in ECOFF format (Third-Eye).
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
3 Free Software Foundation, Inc.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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"
54 /* These are needed if the tm.h file does not contain the necessary
55 mips specific definitions. */
57 #ifndef MIPS_EFI_SYMBOL_NAME
58 #define MIPS_EFI_SYMBOL_NAME "__GDB_EFI_INFO__"
60 #include "coff/symconst.h"
61 typedef struct mips_extra_func_info
{
64 } *mips_extra_func_info_t
;
71 #include <sys/types.h>
74 #include <sys/param.h>
77 #include "gdb_string.h"
79 #include "gdb-stabs.h"
83 #include "coff/ecoff.h" /* COFF-like aspects of ecoff files */
85 #include "libaout.h" /* Private BFD a.out information. */
86 #include "aout/aout64.h"
87 #include "aout/stab_gnu.h" /* STABS information */
89 #include "expression.h"
90 #include "language.h" /* Needed inside partial-stab.h */
92 /* Provide a default mapping from a ecoff register number to a gdb REGNUM. */
93 #ifndef ECOFF_REG_TO_REGNUM
94 #define ECOFF_REG_TO_REGNUM(num) (num)
97 /* We put a pointer to this structure in the read_symtab_private field
102 /* Index of the FDR that this psymtab represents. */
104 /* The BFD that the psymtab was created from. */
106 const struct ecoff_debug_swap
*debug_swap
;
107 struct ecoff_debug_info
*debug_info
;
108 struct mdebug_pending
**pending_list
;
109 /* Pointer to external symbols for this file. */
111 /* Size of extern_tab. */
113 enum language pst_language
;
116 #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
117 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
118 #define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd)
119 #define DEBUG_SWAP(p) (PST_PRIVATE(p)->debug_swap)
120 #define DEBUG_INFO(p) (PST_PRIVATE(p)->debug_info)
121 #define PENDING_LIST(p) (PST_PRIVATE(p)->pending_list)
123 /* Things we import explicitly from other modules */
125 extern int info_verbose
;
127 /* Various complaints about symbol reading that don't abort the process */
129 static struct complaint bad_file_number_complaint
=
130 {"bad file number %d", 0, 0};
132 static struct complaint index_complaint
=
133 {"bad aux index at symbol %s", 0, 0};
135 static struct complaint aux_index_complaint
=
136 {"bad proc end in aux found from symbol %s", 0, 0};
138 static struct complaint block_index_complaint
=
139 {"bad aux index at block symbol %s", 0, 0};
141 static struct complaint unknown_ext_complaint
=
142 {"unknown external symbol %s", 0, 0};
144 static struct complaint unknown_sym_complaint
=
145 {"unknown local symbol %s", 0, 0};
147 static struct complaint unknown_st_complaint
=
148 {"with type %d", 0, 0};
150 static struct complaint block_overflow_complaint
=
151 {"block containing %s overfilled", 0, 0};
153 static struct complaint basic_type_complaint
=
154 {"cannot map ECOFF basic type 0x%x for %s", 0, 0};
156 static struct complaint unknown_type_qual_complaint
=
157 {"unknown type qualifier 0x%x", 0, 0};
159 static struct complaint array_index_type_complaint
=
160 {"illegal array index type for %s, assuming int", 0, 0};
162 static struct complaint bad_tag_guess_complaint
=
163 {"guessed tag type of %s incorrectly", 0, 0};
165 static struct complaint block_member_complaint
=
166 {"declaration block contains unhandled symbol type %d", 0, 0};
168 static struct complaint stEnd_complaint
=
169 {"stEnd with storage class %d not handled", 0, 0};
171 static struct complaint unknown_mdebug_symtype_complaint
=
172 {"unknown symbol type 0x%x", 0, 0};
174 static struct complaint stab_unknown_complaint
=
175 {"unknown stabs symbol %s", 0, 0};
177 static struct complaint pdr_for_nonsymbol_complaint
=
178 {"PDR for %s, but no symbol", 0, 0};
180 static struct complaint pdr_static_symbol_complaint
=
181 {"can't handle PDR for static proc at 0x%lx", 0, 0};
183 static struct complaint bad_setjmp_pdr_complaint
=
184 {"fixing bad setjmp PDR from libc", 0, 0};
186 static struct complaint bad_fbitfield_complaint
=
187 {"can't handle TIR fBitfield for %s", 0, 0};
189 static struct complaint bad_continued_complaint
=
190 {"illegal TIR continued for %s", 0, 0};
192 static struct complaint bad_rfd_entry_complaint
=
193 {"bad rfd entry for %s: file %d, index %d", 0, 0};
195 static struct complaint unexpected_type_code_complaint
=
196 {"unexpected type code for %s", 0, 0};
198 static struct complaint unable_to_cross_ref_complaint
=
199 {"unable to cross ref btTypedef for %s", 0, 0};
201 static struct complaint bad_indirect_xref_complaint
=
202 {"unable to cross ref btIndirect for %s", 0, 0};
204 static struct complaint illegal_forward_tq0_complaint
=
205 {"illegal tq0 in forward typedef for %s", 0, 0};
207 static struct complaint illegal_forward_bt_complaint
=
208 {"illegal bt %d in forward typedef for %s", 0, 0};
210 static struct complaint bad_linetable_guess_complaint
=
211 {"guessed size of linetable for %s incorrectly", 0, 0};
213 static struct complaint bad_ext_ifd_complaint
=
214 {"bad ifd for external symbol: %d (max %d)", 0, 0};
216 static struct complaint bad_ext_iss_complaint
=
217 {"bad iss for external symbol: %ld (max %ld)", 0, 0};
219 /* Macros and extra defs */
221 /* Puns: hard to find whether -g was used and how */
223 #define MIN_GLEVEL GLEVEL_0
224 #define compare_glevel(a,b) \
225 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
226 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
228 /* Things that really are local to this module */
230 /* Remember what we deduced to be the source language of this psymtab. */
232 static enum language psymtab_language
= language_unknown
;
238 /* How to parse debugging information for CUR_BFD. */
240 static const struct ecoff_debug_swap
*debug_swap
;
242 /* Pointers to debugging information for CUR_BFD. */
244 static struct ecoff_debug_info
*debug_info
;
246 /* Pointer to current file decriptor record, and its index */
251 /* Index of current symbol */
255 /* Note how much "debuggable" this image is. We would like
256 to see at least one FDR with full symbols */
261 /* When examining .o files, report on undefined symbols */
263 static int n_undef_symbols
, n_undef_labels
, n_undef_vars
, n_undef_procs
;
265 /* Pseudo symbol to use when putting stabs into the symbol table. */
267 static char stabs_symbol
[] = STABS_SYMBOL
;
269 /* Types corresponding to mdebug format bt* basic types. */
271 static struct type
*mdebug_type_void
;
272 static struct type
*mdebug_type_char
;
273 static struct type
*mdebug_type_short
;
274 static struct type
*mdebug_type_int_32
;
275 #define mdebug_type_int mdebug_type_int_32
276 static struct type
*mdebug_type_int_64
;
277 static struct type
*mdebug_type_long_32
;
278 static struct type
*mdebug_type_long_64
;
279 static struct type
*mdebug_type_long_long_64
;
280 static struct type
*mdebug_type_unsigned_char
;
281 static struct type
*mdebug_type_unsigned_short
;
282 static struct type
*mdebug_type_unsigned_int_32
;
283 static struct type
*mdebug_type_unsigned_int_64
;
284 static struct type
*mdebug_type_unsigned_long_32
;
285 static struct type
*mdebug_type_unsigned_long_64
;
286 static struct type
*mdebug_type_unsigned_long_long_64
;
287 static struct type
*mdebug_type_adr_32
;
288 static struct type
*mdebug_type_adr_64
;
289 static struct type
*mdebug_type_float
;
290 static struct type
*mdebug_type_double
;
291 static struct type
*mdebug_type_complex
;
292 static struct type
*mdebug_type_double_complex
;
293 static struct type
*mdebug_type_fixed_dec
;
294 static struct type
*mdebug_type_float_dec
;
295 static struct type
*mdebug_type_string
;
297 /* Types for symbols from files compiled without debugging info. */
299 static struct type
*nodebug_func_symbol_type
;
300 static struct type
*nodebug_var_symbol_type
;
302 /* Nonzero if we have seen ecoff debugging info for a file. */
304 static int found_ecoff_debugging_info
;
306 /* Forward declarations */
309 add_pending
PARAMS ((FDR
*, char *, struct type
*));
311 static struct mdebug_pending
*
312 is_pending_symbol
PARAMS ((FDR
*, char *));
315 pop_parse_stack
PARAMS ((void));
318 push_parse_stack
PARAMS ((void));
321 fdr_name
PARAMS ((FDR
*));
324 mdebug_psymtab_to_symtab
PARAMS ((struct partial_symtab
*));
327 upgrade_type
PARAMS ((int, struct type
**, int, union aux_ext
*, int, char *));
330 parse_partial_symbols
PARAMS ((struct objfile
*,
331 struct section_offsets
*));
334 *get_rfd
PARAMS ((int, int));
337 has_opaque_xref
PARAMS ((FDR
*, SYMR
*));
340 cross_ref
PARAMS ((int, union aux_ext
*, struct type
**, enum type_code
,
341 char **, int, char *));
343 static struct symbol
*
344 new_symbol
PARAMS ((char *));
347 new_type
PARAMS ((char *));
349 static struct block
*
350 new_block
PARAMS ((int));
352 static struct symtab
*
353 new_symtab
PARAMS ((char *, int, int, struct objfile
*));
355 static struct linetable
*
356 new_linetable
PARAMS ((int));
358 static struct blockvector
*
359 new_bvect
PARAMS ((int));
362 parse_symbol
PARAMS ((SYMR
*, union aux_ext
*, char *, int, struct section_offsets
*));
365 parse_type
PARAMS ((int, union aux_ext
*, unsigned int, int *, int, char *));
367 static struct symbol
*
368 mylookup_symbol
PARAMS ((char *, struct block
*, namespace_enum
,
369 enum address_class
));
371 static struct block
*
372 shrink_block
PARAMS ((struct block
*, struct symtab
*));
375 xzalloc
PARAMS ((unsigned int));
378 sort_blocks
PARAMS ((struct symtab
*));
381 compare_blocks
PARAMS ((const void *, const void *));
383 static struct partial_symtab
*
384 new_psymtab
PARAMS ((char *, struct objfile
*, struct section_offsets
*));
387 psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*, char *));
390 add_block
PARAMS ((struct block
*, struct symtab
*));
393 add_symbol
PARAMS ((struct symbol
*, struct block
*));
396 add_line
PARAMS ((struct linetable
*, int, CORE_ADDR
, int));
398 static struct linetable
*
399 shrink_linetable
PARAMS ((struct linetable
*));
402 handle_psymbol_enumerators
PARAMS ((struct objfile
*, FDR
*, int, CORE_ADDR
));
405 mdebug_next_symbol_text
PARAMS ((struct objfile
*));
407 /* Address bounds for the signal trampoline in inferior, if any */
409 CORE_ADDR sigtramp_address
, sigtramp_end
;
411 /* Allocate zeroed memory */
417 PTR p
= xmalloc (size
);
423 /* Exported procedure: Builds a symtab from the PST partial one.
424 Restores the environment in effect when PST was created, delegates
425 most of the work to an ancillary procedure, and sorts
426 and reorders the symtab list at the end */
429 mdebug_psymtab_to_symtab (pst
)
430 struct partial_symtab
*pst
;
438 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
439 gdb_flush (gdb_stdout
);
442 next_symbol_text_func
= mdebug_next_symbol_text
;
444 psymtab_to_symtab_1 (pst
, pst
->filename
);
446 /* Match with global symbols. This only needs to be done once,
447 after all of the symtabs and dependencies have been read in. */
448 scan_file_globals (pst
->objfile
);
451 printf_filtered ("done.\n");
454 /* File-level interface functions */
456 /* Find a file descriptor given its index RF relative to a file CF */
466 fdrs
= debug_info
->fdr
;
468 /* Object files do not have the RFD table, all refs are absolute */
471 (*debug_swap
->swap_rfd_in
) (cur_bfd
,
472 ((char *) debug_info
->external_rfd
474 * debug_swap
->external_rfd_size
)),
479 /* Return a safer print NAME for a file descriptor */
486 return "<stripped file>";
489 return debug_info
->ss
+ f
->issBase
+ f
->rss
;
493 /* Read in and parse the symtab of the file OBJFILE. Symbols from
494 different sections are relocated via the SECTION_OFFSETS. */
497 mdebug_build_psymtabs (objfile
, swap
, info
, section_offsets
)
498 struct objfile
*objfile
;
499 const struct ecoff_debug_swap
*swap
;
500 struct ecoff_debug_info
*info
;
501 struct section_offsets
*section_offsets
;
503 cur_bfd
= objfile
->obfd
;
507 /* Make sure all the FDR information is swapped in. */
508 if (info
->fdr
== (FDR
*) NULL
)
514 info
->fdr
= (FDR
*) obstack_alloc (&objfile
->psymbol_obstack
,
515 (info
->symbolic_header
.ifdMax
517 fdr_src
= info
->external_fdr
;
519 + info
->symbolic_header
.ifdMax
* swap
->external_fdr_size
);
521 for (; fdr_src
< fdr_end
; fdr_src
+= swap
->external_fdr_size
, fdr_ptr
++)
522 (*swap
->swap_fdr_in
) (objfile
->obfd
, fdr_src
, fdr_ptr
);
525 parse_partial_symbols (objfile
, section_offsets
);
528 /* Check to make sure file was compiled with -g. If not, warn the
529 user of this limitation. */
530 if (compare_glevel (max_glevel
, GLEVEL_2
) < 0)
532 if (max_gdbinfo
== 0)
533 printf_unfiltered ("\n%s not compiled with -g, debugging support is limited.\n",
535 printf_unfiltered ("You should compile with -g2 or -g3 for best debugging support.\n");
536 gdb_flush (gdb_stdout
);
541 /* Local utilities */
543 /* Map of FDR indexes to partial symtabs */
547 struct partial_symtab
*pst
; /* the psymtab proper */
548 long n_globals
; /* exported globals (external symbols) */
549 long globals_offset
; /* cumulative */
553 /* Utility stack, used to nest procedures and blocks properly.
554 It is a doubly linked list, to avoid too many alloc/free.
555 Since we might need it quite a few times it is NOT deallocated
558 static struct parse_stack
560 struct parse_stack
*next
, *prev
;
561 struct symtab
*cur_st
; /* Current symtab. */
562 struct block
*cur_block
; /* Block in it. */
564 /* What are we parsing. stFile, or stBlock are for files and
565 blocks. stProc or stStaticProc means we have seen the start of a
566 procedure, but not the start of the block within in. When we see
567 the start of that block, we change it to stNil, without pushing a
568 new block, i.e. stNil means both a procedure and a block. */
572 int maxsyms
; /* Max symbols in this block. */
573 struct type
*cur_type
; /* Type we parse fields for. */
574 int cur_field
; /* Field number in cur_type. */
575 CORE_ADDR procadr
; /* Start addres of this procedure */
576 int numargs
; /* Its argument count */
579 *top_stack
; /* Top stack ptr */
582 /* Enter a new lexical context */
587 struct parse_stack
*new;
589 /* Reuse frames if possible */
590 if (top_stack
&& top_stack
->prev
)
591 new = top_stack
->prev
;
593 new = (struct parse_stack
*) xzalloc (sizeof (struct parse_stack
));
594 /* Initialize new frame with previous content */
597 register struct parse_stack
*prev
= new->prev
;
600 top_stack
->prev
= new;
602 new->next
= top_stack
;
607 /* Exit a lexical context */
615 top_stack
= top_stack
->next
;
619 /* Cross-references might be to things we haven't looked at
620 yet, e.g. type references. To avoid too many type
621 duplications we keep a quick fixup table, an array
622 of lists of references indexed by file descriptor */
624 struct mdebug_pending
626 struct mdebug_pending
*next
; /* link */
627 char *s
; /* the unswapped symbol */
628 struct type
*t
; /* its partial type descriptor */
632 /* The pending information is kept for an entire object file, and used
633 to be in the sym_private field. I took it out when I split
634 mdebugread from mipsread, because this might not be the only type
635 of symbols read from an object file. Instead, we allocate the
636 pending information table when we create the partial symbols, and
637 we store a pointer to the single table in each psymtab. */
639 static struct mdebug_pending
**pending_list
;
641 /* Check whether we already saw symbol SH in file FH */
643 static struct mdebug_pending
*
644 is_pending_symbol (fh
, sh
)
648 int f_idx
= fh
- debug_info
->fdr
;
649 register struct mdebug_pending
*p
;
651 /* Linear search is ok, list is typically no more than 10 deep */
652 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
658 /* Add a new symbol SH of type T */
661 add_pending (fh
, sh
, t
)
666 int f_idx
= fh
- debug_info
->fdr
;
667 struct mdebug_pending
*p
= is_pending_symbol (fh
, sh
);
669 /* Make sure we do not make duplicates */
672 p
= ((struct mdebug_pending
*)
673 obstack_alloc (¤t_objfile
->psymbol_obstack
,
674 sizeof (struct mdebug_pending
)));
677 p
->next
= pending_list
[f_idx
];
678 pending_list
[f_idx
] = p
;
683 /* Parsing Routines proper. */
685 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
686 For blocks, procedures and types we open a new lexical context.
687 This is basically just a big switch on the symbol's type. Argument
688 AX is the base pointer of aux symbols for this file (fh->iauxBase).
689 EXT_SH points to the unswapped symbol, which is needed for struct,
690 union, etc., types; it is NULL for an EXTR. BIGEND says whether
691 aux symbols are big-endian or little-endian. Return count of
692 SYMR's handled (normally one). */
695 parse_symbol (sh
, ax
, ext_sh
, bigend
, section_offsets
)
700 struct section_offsets
*section_offsets
;
702 const bfd_size_type external_sym_size
= debug_swap
->external_sym_size
;
703 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*)) =
704 debug_swap
->swap_sym_in
;
708 struct mdebug_pending
*pend
;
712 enum address_class
class;
714 long svalue
= sh
->value
;
717 if (ext_sh
== (char *) NULL
)
718 name
= debug_info
->ssext
+ sh
->iss
;
720 name
= debug_info
->ss
+ cur_fdr
->issBase
+ sh
->iss
;
725 /* Do not relocate relative values.
726 The value of a stEnd symbol is the displacement from the
727 corresponding start symbol value.
728 The value of a stBlock symbol is the displacement from the
729 procedure address. */
730 if (sh
->st
!= stEnd
&& sh
->st
!= stBlock
)
731 sh
->value
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT
);
738 sh
->value
+= ANOFFSET (section_offsets
, SECT_OFF_DATA
);
742 sh
->value
+= ANOFFSET (section_offsets
, SECT_OFF_BSS
);
751 case stGlobal
: /* external symbol, goes into global block */
753 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack
->cur_st
),
755 s
= new_symbol (name
);
756 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
759 case stStatic
: /* static data, goes into current block. */
761 b
= top_stack
->cur_block
;
762 s
= new_symbol (name
);
763 if (sh
->sc
== scCommon
|| sh
->sc
== scSCommon
)
765 /* It is a FORTRAN common block. At least for SGI Fortran the
766 address is not in the symbol; we need to fix it later in
767 scan_file_globals. */
768 int bucket
= hashname (SYMBOL_NAME (s
));
769 SYMBOL_VALUE_CHAIN (s
) = global_sym_chain
[bucket
];
770 global_sym_chain
[bucket
] = s
;
773 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
776 case stLocal
: /* local variable, goes into current block */
777 if (sh
->sc
== scRegister
)
779 class = LOC_REGISTER
;
780 svalue
= ECOFF_REG_TO_REGNUM (svalue
);
784 b
= top_stack
->cur_block
;
785 s
= new_symbol (name
);
786 SYMBOL_VALUE (s
) = svalue
;
788 data
: /* Common code for symbols describing data */
789 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
790 SYMBOL_CLASS (s
) = class;
793 /* Type could be missing if file is compiled without debugging info. */
794 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
|| sh
->index
== indexNil
)
795 SYMBOL_TYPE (s
) = nodebug_var_symbol_type
;
797 SYMBOL_TYPE (s
) = parse_type (cur_fd
, ax
, sh
->index
, 0, bigend
, name
);
798 /* Value of a data symbol is its memory address */
801 case stParam
: /* arg to procedure, goes into current block */
803 found_ecoff_debugging_info
= 1;
804 top_stack
->numargs
++;
806 /* Special GNU C++ name. */
807 if (is_cplus_marker (name
[0]) && name
[1] == 't' && name
[2] == 0)
808 name
= "this"; /* FIXME, not alloc'd in obstack */
809 s
= new_symbol (name
);
811 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
815 /* Pass by value in register. */
816 SYMBOL_CLASS(s
) = LOC_REGPARM
;
817 svalue
= ECOFF_REG_TO_REGNUM (svalue
);
820 /* Pass by reference on stack. */
821 SYMBOL_CLASS(s
) = LOC_REF_ARG
;
824 /* Pass by reference in register. */
825 SYMBOL_CLASS(s
) = LOC_REGPARM_ADDR
;
826 svalue
= ECOFF_REG_TO_REGNUM (svalue
);
829 /* Pass by value on stack. */
830 SYMBOL_CLASS(s
) = LOC_ARG
;
833 SYMBOL_VALUE (s
) = svalue
;
834 SYMBOL_TYPE (s
) = parse_type (cur_fd
, ax
, sh
->index
, 0, bigend
, name
);
835 add_symbol (s
, top_stack
->cur_block
);
838 case stLabel
: /* label, goes into current block */
839 s
= new_symbol (name
);
840 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
; /* so that it can be used */
841 SYMBOL_CLASS (s
) = LOC_LABEL
; /* but not misused */
842 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
843 SYMBOL_TYPE (s
) = mdebug_type_int
;
844 add_symbol (s
, top_stack
->cur_block
);
847 case stProc
: /* Procedure, usually goes into global block */
848 case stStaticProc
: /* Static procedure, goes into current block */
849 s
= new_symbol (name
);
850 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
851 SYMBOL_CLASS (s
) = LOC_BLOCK
;
852 /* Type of the return value */
853 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
857 t
= parse_type (cur_fd
, ax
, sh
->index
+ 1, 0, bigend
, name
);
858 if (STREQ(name
, "malloc") && t
->code
== TYPE_CODE_VOID
)
860 /* I don't know why, but, at least under Linux/Alpha,
861 when linking against a malloc without debugging
862 symbols, its read as a function returning void---this
863 is bad because it means we cannot call functions with
864 string arguments interactively; i.e., "call
865 printf("howdy\n")" would fail with the error message
866 "program has no memory available". To avoid this, we
867 patch up the type and make it void*
868 instead. (davidm@azstarnet.com)
873 b
= top_stack
->cur_block
;
874 if (sh
->st
== stProc
)
876 struct blockvector
*bv
= BLOCKVECTOR (top_stack
->cur_st
);
877 /* The next test should normally be true, but provides a
878 hook for nested functions (which we don't want to make
880 if (b
== BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
))
881 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
882 /* Irix 5 sometimes has duplicate names for the same
883 function. We want to add such names up at the global
884 level, not as a nested function. */
885 else if (sh
->value
== top_stack
->procadr
)
886 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
890 /* Make a type for the procedure itself */
891 SYMBOL_TYPE (s
) = lookup_function_type (t
);
893 /* Create and enter a new lexical context */
894 b
= new_block (top_stack
->maxsyms
);
895 SYMBOL_BLOCK_VALUE (s
) = b
;
896 BLOCK_FUNCTION (b
) = s
;
897 BLOCK_START (b
) = BLOCK_END (b
) = sh
->value
;
898 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
899 add_block (b
, top_stack
->cur_st
);
901 /* Not if we only have partial info */
902 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
906 top_stack
->cur_block
= b
;
907 top_stack
->blocktype
= sh
->st
;
908 top_stack
->cur_type
= SYMBOL_TYPE (s
);
909 top_stack
->cur_field
= -1;
910 top_stack
->procadr
= sh
->value
;
911 top_stack
->numargs
= 0;
914 /* Beginning of code for structure, union, and enum definitions.
915 They all share a common set of local variables, defined here. */
917 enum type_code type_code
;
923 case stStruct
: /* Start a block defining a struct type */
924 type_code
= TYPE_CODE_STRUCT
;
925 goto structured_common
;
927 case stUnion
: /* Start a block defining a union type */
928 type_code
= TYPE_CODE_UNION
;
929 goto structured_common
;
931 case stEnum
: /* Start a block defining an enum type */
932 type_code
= TYPE_CODE_ENUM
;
933 goto structured_common
;
935 case stBlock
: /* Either a lexical block, or some type */
936 if (sh
->sc
!= scInfo
&& sh
->sc
!= scCommon
&& sh
->sc
!= scSCommon
)
937 goto case_stBlock_code
; /* Lexical block */
939 type_code
= TYPE_CODE_UNDEF
; /* We have a type. */
941 /* Common code for handling struct, union, enum, and/or as-yet-
942 unknown-type blocks of info about structured data. `type_code'
943 has been set to the proper TYPE_CODE, if we know it. */
945 found_ecoff_debugging_info
= 1;
947 top_stack
->blocktype
= stBlock
;
949 /* First count the number of fields and the highest value. */
952 for (ext_tsym
= ext_sh
+ external_sym_size
;
954 ext_tsym
+= external_sym_size
)
958 (*swap_sym_in
) (cur_bfd
, ext_tsym
, &tsym
);
966 if (nfields
== 0 && type_code
== TYPE_CODE_UNDEF
)
967 /* If the type of the member is Nil (or Void),
968 without qualifiers, assume the tag is an
970 Alpha cc -migrate enums are recognized by a zero
971 index and a zero symbol value. */
972 if (tsym
.index
== indexNil
973 || (tsym
.index
== 0 && sh
->value
== 0))
974 type_code
= TYPE_CODE_ENUM
;
977 (*debug_swap
->swap_tir_in
) (bigend
,
978 &ax
[tsym
.index
].a_ti
,
980 if ((tir
.bt
== btNil
|| tir
.bt
== btVoid
)
982 type_code
= TYPE_CODE_ENUM
;
985 if (tsym
.value
> max_value
)
986 max_value
= tsym
.value
;
995 /* This is a no-op; is it trying to tell us something
996 we should be checking? */
997 if (tsym
.sc
== scVariant
); /*UNIMPLEMENTED*/
1001 /* This is something like a struct within a
1002 struct. Skip over the fields of the inner
1003 struct. The -1 is because the for loop will
1004 increment ext_tsym. */
1005 ext_tsym
= ((char *) debug_info
->external_sym
1006 + ((cur_fdr
->isymBase
+ tsym
.index
- 1)
1007 * external_sym_size
));
1013 /* mips cc puts out a typedef for struct x if it is not yet
1014 defined when it encounters
1015 struct y { struct x *xp; };
1020 /* Irix5 cc puts out a stIndirect for struct x if it is not
1021 yet defined when it encounters
1022 struct y { struct x *xp; };
1027 complain (&block_member_complaint
, tsym
.st
);
1032 /* In an stBlock, there is no way to distinguish structs,
1033 unions, and enums at this point. This is a bug in the
1034 original design (that has been fixed with the recent
1035 addition of the stStruct, stUnion, and stEnum symbol
1036 types.) The way you can tell is if/when you see a variable
1037 or field of that type. In that case the variable's type
1038 (in the AUX table) says if the type is struct, union, or
1039 enum, and points back to the stBlock here. So you can
1040 patch the tag kind up later - but only if there actually is
1041 a variable or field of that type.
1043 So until we know for sure, we will guess at this point.
1045 If the first member has index==indexNil or a void type,
1046 assume we have an enumeration.
1047 Otherwise, if there is more than one member, and all
1048 the members have offset 0, assume we have a union.
1049 Otherwise, assume we have a struct.
1051 The heuristic could guess wrong in the case of of an
1052 enumeration with no members or a union with one (or zero)
1053 members, or when all except the last field of a struct have
1054 width zero. These are uncommon and/or illegal situations,
1055 and in any case guessing wrong probably doesn't matter
1058 But if we later do find out we were wrong, we fixup the tag
1059 kind. Members of an enumeration must be handled
1060 differently from struct/union fields, and that is harder to
1061 patch up, but luckily we shouldn't need to. (If there are
1062 any enumeration members, we can tell for sure it's an enum
1065 if (type_code
== TYPE_CODE_UNDEF
)
1066 if (nfields
> 1 && max_value
== 0)
1067 type_code
= TYPE_CODE_UNION
;
1069 type_code
= TYPE_CODE_STRUCT
;
1071 /* Create a new type or use the pending type. */
1072 pend
= is_pending_symbol (cur_fdr
, ext_sh
);
1073 if (pend
== (struct mdebug_pending
*) NULL
)
1075 t
= new_type (NULL
);
1076 add_pending (cur_fdr
, ext_sh
, t
);
1081 /* Do not set the tag name if it is a compiler generated tag name
1082 (.Fxx or .xxfake or empty) for unnamed struct/union/enums.
1083 Alpha cc puts out an sh->iss of zero for those. */
1084 if (sh
->iss
== 0 || name
[0] == '.' || name
[0] == '\0')
1085 TYPE_TAG_NAME (t
) = NULL
;
1087 TYPE_TAG_NAME (t
) = obconcat (¤t_objfile
->symbol_obstack
,
1090 TYPE_CODE (t
) = type_code
;
1091 TYPE_LENGTH (t
) = sh
->value
;
1092 TYPE_NFIELDS (t
) = nfields
;
1093 TYPE_FIELDS (t
) = f
= ((struct field
*)
1095 nfields
* sizeof (struct field
)));
1097 if (type_code
== TYPE_CODE_ENUM
)
1099 int unsigned_enum
= 1;
1101 /* This is a non-empty enum. */
1103 /* DEC c89 has the number of enumerators in the sh.value field,
1104 not the type length, so we have to compensate for that
1105 incompatibility quirk.
1106 This might do the wrong thing for an enum with one or two
1107 enumerators and gcc -gcoff -fshort-enums, but these cases
1108 are hopefully rare enough.
1109 Alpha cc -migrate has a sh.value field of zero, we adjust
1111 if (TYPE_LENGTH (t
) == TYPE_NFIELDS (t
)
1112 || TYPE_LENGTH (t
) == 0)
1113 TYPE_LENGTH (t
) = TARGET_INT_BIT
/ HOST_CHAR_BIT
;
1114 for (ext_tsym
= ext_sh
+ external_sym_size
;
1116 ext_tsym
+= external_sym_size
)
1119 struct symbol
*enum_sym
;
1121 (*swap_sym_in
) (cur_bfd
, ext_tsym
, &tsym
);
1123 if (tsym
.st
!= stMember
)
1126 f
->bitpos
= tsym
.value
;
1128 f
->name
= debug_info
->ss
+ cur_fdr
->issBase
+ tsym
.iss
;
1131 enum_sym
= ((struct symbol
*)
1132 obstack_alloc (¤t_objfile
->symbol_obstack
,
1133 sizeof (struct symbol
)));
1134 memset ((PTR
) enum_sym
, 0, sizeof (struct symbol
));
1135 SYMBOL_NAME (enum_sym
) =
1136 obsavestring (f
->name
, strlen (f
->name
),
1137 ¤t_objfile
->symbol_obstack
);
1138 SYMBOL_CLASS (enum_sym
) = LOC_CONST
;
1139 SYMBOL_TYPE (enum_sym
) = t
;
1140 SYMBOL_NAMESPACE (enum_sym
) = VAR_NAMESPACE
;
1141 SYMBOL_VALUE (enum_sym
) = tsym
.value
;
1142 if (SYMBOL_VALUE (enum_sym
) < 0)
1144 add_symbol (enum_sym
, top_stack
->cur_block
);
1146 /* Skip the stMembers that we've handled. */
1151 TYPE_FLAGS (t
) |= TYPE_FLAG_UNSIGNED
;
1153 /* make this the current type */
1154 top_stack
->cur_type
= t
;
1155 top_stack
->cur_field
= 0;
1157 /* Do not create a symbol for alpha cc unnamed structs. */
1161 /* gcc puts out an empty struct for an opaque struct definitions,
1162 do not create a symbol for it either. */
1163 if (TYPE_NFIELDS (t
) == 0)
1165 TYPE_FLAGS (t
) |= TYPE_FLAG_STUB
;
1169 s
= new_symbol (name
);
1170 SYMBOL_NAMESPACE (s
) = STRUCT_NAMESPACE
;
1171 SYMBOL_CLASS (s
) = LOC_TYPEDEF
;
1172 SYMBOL_VALUE (s
) = 0;
1173 SYMBOL_TYPE (s
) = t
;
1174 add_symbol (s
, top_stack
->cur_block
);
1177 /* End of local variables shared by struct, union, enum, and
1178 block (as yet unknown struct/union/enum) processing. */
1182 found_ecoff_debugging_info
= 1;
1183 /* beginnning of (code) block. Value of symbol
1184 is the displacement from procedure start */
1185 push_parse_stack ();
1187 /* Do not start a new block if this is the outermost block of a
1188 procedure. This allows the LOC_BLOCK symbol to point to the
1189 block with the local variables, so funcname::var works. */
1190 if (top_stack
->blocktype
== stProc
1191 || top_stack
->blocktype
== stStaticProc
)
1193 top_stack
->blocktype
= stNil
;
1197 top_stack
->blocktype
= stBlock
;
1198 b
= new_block (top_stack
->maxsyms
);
1199 BLOCK_START (b
) = sh
->value
+ top_stack
->procadr
;
1200 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
1201 top_stack
->cur_block
= b
;
1202 add_block (b
, top_stack
->cur_st
);
1205 case stEnd
: /* end (of anything) */
1206 if (sh
->sc
== scInfo
|| sh
->sc
== scCommon
|| sh
->sc
== scSCommon
)
1208 /* Finished with type */
1209 top_stack
->cur_type
= 0;
1211 else if (sh
->sc
== scText
&&
1212 (top_stack
->blocktype
== stProc
||
1213 top_stack
->blocktype
== stStaticProc
))
1215 /* Finished with procedure */
1216 struct blockvector
*bv
= BLOCKVECTOR (top_stack
->cur_st
);
1217 struct mips_extra_func_info
*e
;
1219 struct type
*ftype
= top_stack
->cur_type
;
1222 BLOCK_END (top_stack
->cur_block
) += sh
->value
; /* size */
1224 /* Make up special symbol to contain procedure specific info */
1225 s
= new_symbol (MIPS_EFI_SYMBOL_NAME
);
1226 SYMBOL_NAMESPACE (s
) = LABEL_NAMESPACE
;
1227 SYMBOL_CLASS (s
) = LOC_CONST
;
1228 SYMBOL_TYPE (s
) = mdebug_type_void
;
1229 e
= ((struct mips_extra_func_info
*)
1230 obstack_alloc (¤t_objfile
->symbol_obstack
,
1231 sizeof (struct mips_extra_func_info
)));
1232 memset ((PTR
) e
, 0, sizeof (struct mips_extra_func_info
));
1233 SYMBOL_VALUE (s
) = (long) e
;
1234 e
->numargs
= top_stack
->numargs
;
1235 e
->pdr
.framereg
= -1;
1236 add_symbol (s
, top_stack
->cur_block
);
1238 /* Reallocate symbols, saving memory */
1239 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
1241 /* f77 emits proc-level with address bounds==[0,0],
1242 So look for such child blocks, and patch them. */
1243 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS (bv
); i
++)
1245 struct block
*b_bad
= BLOCKVECTOR_BLOCK (bv
, i
);
1246 if (BLOCK_SUPERBLOCK (b_bad
) == b
1247 && BLOCK_START (b_bad
) == top_stack
->procadr
1248 && BLOCK_END (b_bad
) == top_stack
->procadr
)
1250 BLOCK_START (b_bad
) = BLOCK_START (b
);
1251 BLOCK_END (b_bad
) = BLOCK_END (b
);
1255 if (TYPE_NFIELDS (ftype
) <= 0)
1257 /* No parameter type information is recorded with the function's
1258 type. Set that from the type of the parameter symbols. */
1259 int nparams
= top_stack
->numargs
;
1265 TYPE_NFIELDS (ftype
) = nparams
;
1266 TYPE_FIELDS (ftype
) = (struct field
*)
1267 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
1269 for (i
= iparams
= 0; iparams
< nparams
; i
++)
1271 sym
= BLOCK_SYM (b
, i
);
1272 switch (SYMBOL_CLASS (sym
))
1277 case LOC_REGPARM_ADDR
:
1278 TYPE_FIELD_TYPE (ftype
, iparams
) = SYMBOL_TYPE (sym
);
1288 else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
)
1290 /* End of (code) block. The value of the symbol is the
1291 displacement from the procedure`s start address of the
1292 end of this block. */
1293 BLOCK_END (top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1294 shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
1296 else if (sh
->sc
== scText
&& top_stack
->blocktype
== stNil
)
1298 /* End of outermost block. Pop parse stack and ignore. The
1299 following stEnd of stProc will take care of the block. */
1302 else if (sh
->sc
== scText
&& top_stack
->blocktype
== stFile
)
1304 /* End of file. Pop parse stack and ignore. Higher
1305 level code deals with this. */
1309 complain (&stEnd_complaint
, sh
->sc
);
1311 pop_parse_stack (); /* restore previous lexical context */
1314 case stMember
: /* member of struct or union */
1315 f
= &TYPE_FIELDS (top_stack
->cur_type
)[top_stack
->cur_field
++];
1317 f
->bitpos
= sh
->value
;
1319 f
->type
= parse_type (cur_fd
, ax
, sh
->index
, &bitsize
, bigend
, name
);
1320 f
->bitsize
= bitsize
;
1323 case stIndirect
: /* forward declaration on Irix5 */
1324 /* Forward declarations from Irix5 cc are handled by cross_ref,
1328 case stTypedef
: /* type definition */
1329 found_ecoff_debugging_info
= 1;
1331 /* Typedefs for forward declarations and opaque structs from alpha cc
1332 are handled by cross_ref, skip them. */
1336 /* Parse the type or use the pending type. */
1337 pend
= is_pending_symbol (cur_fdr
, ext_sh
);
1338 if (pend
== (struct mdebug_pending
*) NULL
)
1340 t
= parse_type (cur_fd
, ax
, sh
->index
, (int *)NULL
, bigend
, name
);
1341 add_pending (cur_fdr
, ext_sh
, t
);
1346 /* mips cc puts out a typedef with the name of the struct for forward
1347 declarations. These should not go into the symbol table and
1348 TYPE_NAME should not be set for them.
1349 They can't be distinguished from an intentional typedef to
1350 the same name however:
1352 struct x { int ix; int jx; };
1356 struct xx {int ixx; int jxx; };
1357 generates a cross referencing stTypedef for x and xx.
1358 The user visible effect of this is that the type of a pointer
1359 to struct foo sometimes is given as `foo *' instead of `struct foo *'.
1360 The problem is fixed with alpha cc and Irix5 cc. */
1362 /* However if the typedef cross references to an opaque aggregate, it
1363 is safe to omit it from the symbol table. */
1365 if (has_opaque_xref (cur_fdr
, sh
))
1367 s
= new_symbol (name
);
1368 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
1369 SYMBOL_CLASS (s
) = LOC_TYPEDEF
;
1370 SYMBOL_BLOCK_VALUE (s
) = top_stack
->cur_block
;
1371 SYMBOL_TYPE (s
) = t
;
1372 add_symbol (s
, top_stack
->cur_block
);
1374 /* Incomplete definitions of structs should not get a name. */
1375 if (TYPE_NAME (SYMBOL_TYPE (s
)) == NULL
1376 && (TYPE_NFIELDS (SYMBOL_TYPE (s
)) != 0
1377 || (TYPE_CODE (SYMBOL_TYPE (s
)) != TYPE_CODE_STRUCT
1378 && TYPE_CODE (SYMBOL_TYPE (s
)) != TYPE_CODE_UNION
)))
1380 if (TYPE_CODE (SYMBOL_TYPE (s
)) == TYPE_CODE_PTR
1381 || TYPE_CODE (SYMBOL_TYPE (s
)) == TYPE_CODE_FUNC
)
1383 /* If we are giving a name to a type such as "pointer to
1384 foo" or "function returning foo", we better not set
1385 the TYPE_NAME. If the program contains "typedef char
1386 *caddr_t;", we don't want all variables of type char
1387 * to print as caddr_t. This is not just a
1388 consequence of GDB's type management; CC and GCC (at
1389 least through version 2.4) both output variables of
1390 either type char * or caddr_t with the type
1391 refering to the stTypedef symbol for caddr_t. If a future
1392 compiler cleans this up it GDB is not ready for it
1393 yet, but if it becomes ready we somehow need to
1394 disable this check (without breaking the PCC/GCC2.4
1399 Fortunately, this check seems not to be necessary
1400 for anything except pointers or functions. */
1403 TYPE_NAME (SYMBOL_TYPE (s
)) = SYMBOL_NAME (s
);
1407 case stFile
: /* file name */
1408 push_parse_stack ();
1409 top_stack
->blocktype
= sh
->st
;
1412 /* I`ve never seen these for C */
1414 break; /* register relocation */
1416 break; /* forwarding address */
1418 break; /* constant */
1420 complain (&unknown_mdebug_symtype_complaint
, sh
->st
);
1427 /* Parse the type information provided in the raw AX entries for
1428 the symbol SH. Return the bitfield size in BS, in case.
1429 We must byte-swap the AX entries before we use them; BIGEND says whether
1430 they are big-endian or little-endian (from fh->fBigendian). */
1432 static struct type
*
1433 parse_type (fd
, ax
, aux_index
, bs
, bigend
, sym_name
)
1436 unsigned int aux_index
;
1441 /* Null entries in this map are treated specially */
1442 static struct type
**map_bt
[] =
1444 &mdebug_type_void
, /* btNil */
1445 &mdebug_type_adr_32
, /* btAdr */
1446 &mdebug_type_char
, /* btChar */
1447 &mdebug_type_unsigned_char
, /* btUChar */
1448 &mdebug_type_short
, /* btShort */
1449 &mdebug_type_unsigned_short
, /* btUShort */
1450 &mdebug_type_int_32
, /* btInt */
1451 &mdebug_type_unsigned_int_32
, /* btUInt */
1452 &mdebug_type_long_32
, /* btLong */
1453 &mdebug_type_unsigned_long_32
, /* btULong */
1454 &mdebug_type_float
, /* btFloat */
1455 &mdebug_type_double
, /* btDouble */
1462 &mdebug_type_complex
, /* btComplex */
1463 &mdebug_type_double_complex
, /* btDComplex */
1465 &mdebug_type_fixed_dec
, /* btFixedDec */
1466 &mdebug_type_float_dec
, /* btFloatDec */
1467 &mdebug_type_string
, /* btString */
1470 &mdebug_type_void
, /* btVoid */
1471 0, /* DEC C++: Pointer to member */
1472 0, /* DEC C++: Virtual function table */
1473 0, /* DEC C++: Class (Record) */
1474 &mdebug_type_long_64
, /* btLong64 */
1475 &mdebug_type_unsigned_long_64
, /* btULong64 */
1476 &mdebug_type_long_long_64
, /* btLongLong64 */
1477 &mdebug_type_unsigned_long_long_64
, /* btULongLong64 */
1478 &mdebug_type_adr_64
, /* btAdr64 */
1479 &mdebug_type_int_64
, /* btInt64 */
1480 &mdebug_type_unsigned_int_64
, /* btUInt64 */
1484 struct type
*tp
= 0;
1485 enum type_code type_code
= TYPE_CODE_UNDEF
;
1487 /* Handle undefined types, they have indexNil. */
1488 if (aux_index
== indexNil
)
1489 return mdebug_type_int
;
1491 /* Handle corrupt aux indices. */
1492 if (aux_index
>= (debug_info
->fdr
+ fd
)->caux
)
1494 complain (&index_complaint
, sym_name
);
1495 return mdebug_type_int
;
1499 /* Use aux as a type information record, map its basic type. */
1500 (*debug_swap
->swap_tir_in
) (bigend
, &ax
->a_ti
, t
);
1501 if (t
->bt
>= (sizeof (map_bt
) / sizeof (*map_bt
)))
1503 complain (&basic_type_complaint
, t
->bt
, sym_name
);
1504 return mdebug_type_int
;
1508 tp
= *map_bt
[t
->bt
];
1513 /* Cannot use builtin types -- build our own */
1517 type_code
= TYPE_CODE_STRUCT
;
1520 type_code
= TYPE_CODE_UNION
;
1523 type_code
= TYPE_CODE_ENUM
;
1526 type_code
= TYPE_CODE_RANGE
;
1529 type_code
= TYPE_CODE_SET
;
1532 /* alpha cc -migrate uses this for typedefs. The true type will
1533 be obtained by crossreferencing below. */
1534 type_code
= TYPE_CODE_ERROR
;
1537 /* alpha cc uses this for typedefs. The true type will be
1538 obtained by crossreferencing below. */
1539 type_code
= TYPE_CODE_ERROR
;
1542 complain (&basic_type_complaint
, t
->bt
, sym_name
);
1543 return mdebug_type_int
;
1547 /* Move on to next aux */
1552 int width
= AUX_GET_WIDTH (bigend
, ax
);
1554 /* Inhibit core dumps with some cfront generated objects that
1556 if (bs
== (int *)NULL
)
1558 /* Alpha cc -migrate encodes char and unsigned char types
1559 as short and unsigned short types with a field width of 8.
1560 Enum types also have a field width which we ignore for now. */
1561 if (t
->bt
== btShort
&& width
== 8)
1562 tp
= mdebug_type_char
;
1563 else if (t
->bt
== btUShort
&& width
== 8)
1564 tp
= mdebug_type_unsigned_char
;
1565 else if (t
->bt
== btEnum
)
1568 complain (&bad_fbitfield_complaint
, sym_name
);
1575 /* A btIndirect entry cross references to an aux entry containing
1577 if (t
->bt
== btIndirect
)
1584 (*debug_swap
->swap_rndx_in
) (bigend
, &ax
->a_rndx
, rn
);
1586 if (rn
->rfd
== 0xfff)
1588 rf
= AUX_GET_ISYM (bigend
, ax
);
1596 complain (&bad_indirect_xref_complaint
, sym_name
);
1597 return mdebug_type_int
;
1599 xref_fh
= get_rfd (fd
, rf
);
1600 xref_fd
= xref_fh
- debug_info
->fdr
;
1601 tp
= parse_type (xref_fd
, debug_info
->external_aux
+ xref_fh
->iauxBase
,
1602 rn
->index
, (int *) NULL
, xref_fh
->fBigendian
, sym_name
);
1605 /* All these types really point to some (common) MIPS type
1606 definition, and only the type-qualifiers fully identify
1607 them. We'll make the same effort at sharing. */
1608 if (t
->bt
== btStruct
||
1612 /* btSet (I think) implies that the name is a tag name, not a typedef
1613 name. This apparently is a MIPS extension for C sets. */
1618 /* Try to cross reference this type, build new type on failure. */
1619 ax
+= cross_ref (fd
, ax
, &tp
, type_code
, &name
, bigend
, sym_name
);
1620 if (tp
== (struct type
*) NULL
)
1621 tp
= init_type (type_code
, 0, 0, (char *) NULL
, current_objfile
);
1623 /* DEC c89 produces cross references to qualified aggregate types,
1624 dereference them. */
1625 while (TYPE_CODE (tp
) == TYPE_CODE_PTR
1626 || TYPE_CODE (tp
) == TYPE_CODE_ARRAY
)
1627 tp
= tp
->target_type
;
1629 /* Make sure that TYPE_CODE(tp) has an expected type code.
1630 Any type may be returned from cross_ref if file indirect entries
1632 if (TYPE_CODE (tp
) != TYPE_CODE_STRUCT
1633 && TYPE_CODE (tp
) != TYPE_CODE_UNION
1634 && TYPE_CODE (tp
) != TYPE_CODE_ENUM
)
1636 complain (&unexpected_type_code_complaint
, sym_name
);
1641 /* Usually, TYPE_CODE(tp) is already type_code. The main
1642 exception is if we guessed wrong re struct/union/enum.
1643 But for struct vs. union a wrong guess is harmless, so
1644 don't complain(). */
1645 if ((TYPE_CODE (tp
) == TYPE_CODE_ENUM
1646 && type_code
!= TYPE_CODE_ENUM
)
1647 || (TYPE_CODE (tp
) != TYPE_CODE_ENUM
1648 && type_code
== TYPE_CODE_ENUM
))
1650 complain (&bad_tag_guess_complaint
, sym_name
);
1653 if (TYPE_CODE (tp
) != type_code
)
1655 TYPE_CODE (tp
) = type_code
;
1658 /* Do not set the tag name if it is a compiler generated tag name
1659 (.Fxx or .xxfake or empty) for unnamed struct/union/enums. */
1660 if (name
[0] == '.' || name
[0] == '\0')
1661 TYPE_TAG_NAME (tp
) = NULL
;
1662 else if (TYPE_TAG_NAME (tp
) == NULL
1663 || !STREQ (TYPE_TAG_NAME (tp
), name
))
1664 TYPE_TAG_NAME (tp
) = obsavestring (name
, strlen (name
),
1665 ¤t_objfile
->type_obstack
);
1669 /* All these types really point to some (common) MIPS type
1670 definition, and only the type-qualifiers fully identify
1671 them. We'll make the same effort at sharing.
1672 FIXME: We are not doing any guessing on range types. */
1673 if (t
->bt
== btRange
)
1677 /* Try to cross reference this type, build new type on failure. */
1678 ax
+= cross_ref (fd
, ax
, &tp
, type_code
, &name
, bigend
, sym_name
);
1679 if (tp
== (struct type
*) NULL
)
1680 tp
= init_type (type_code
, 0, 0, (char *) NULL
, current_objfile
);
1682 /* Make sure that TYPE_CODE(tp) has an expected type code.
1683 Any type may be returned from cross_ref if file indirect entries
1685 if (TYPE_CODE (tp
) != TYPE_CODE_RANGE
)
1687 complain (&unexpected_type_code_complaint
, sym_name
);
1691 /* Usually, TYPE_CODE(tp) is already type_code. The main
1692 exception is if we guessed wrong re struct/union/enum. */
1693 if (TYPE_CODE (tp
) != type_code
)
1695 complain (&bad_tag_guess_complaint
, sym_name
);
1696 TYPE_CODE (tp
) = type_code
;
1698 if (TYPE_NAME (tp
) == NULL
|| !STREQ (TYPE_NAME (tp
), name
))
1699 TYPE_NAME (tp
) = obsavestring (name
, strlen (name
),
1700 ¤t_objfile
->type_obstack
);
1703 if (t
->bt
== btTypedef
)
1707 /* Try to cross reference this type, it should succeed. */
1708 ax
+= cross_ref (fd
, ax
, &tp
, type_code
, &name
, bigend
, sym_name
);
1709 if (tp
== (struct type
*) NULL
)
1711 complain (&unable_to_cross_ref_complaint
, sym_name
);
1712 tp
= mdebug_type_int
;
1716 /* Deal with range types */
1717 if (t
->bt
== btRange
)
1719 TYPE_NFIELDS (tp
) = 2;
1720 TYPE_FIELDS (tp
) = ((struct field
*)
1721 TYPE_ALLOC (tp
, 2 * sizeof (struct field
)));
1722 TYPE_FIELD_NAME (tp
, 0) = obsavestring ("Low", strlen ("Low"),
1723 ¤t_objfile
->type_obstack
);
1724 TYPE_FIELD_BITPOS (tp
, 0) = AUX_GET_DNLOW (bigend
, ax
);
1726 TYPE_FIELD_NAME (tp
, 1) = obsavestring ("High", strlen ("High"),
1727 ¤t_objfile
->type_obstack
);
1728 TYPE_FIELD_BITPOS (tp
, 1) = AUX_GET_DNHIGH (bigend
, ax
);
1732 /* Parse all the type qualifiers now. If there are more
1733 than 6 the game will continue in the next aux */
1737 #define PARSE_TQ(tq) \
1738 if (t->tq != tqNil) \
1739 ax += upgrade_type(fd, &tp, t->tq, ax, bigend, sym_name); \
1751 /* mips cc 2.x and gcc never put out continued aux entries. */
1755 (*debug_swap
->swap_tir_in
) (bigend
, &ax
->a_ti
, t
);
1759 /* Complain for illegal continuations due to corrupt aux entries. */
1761 complain (&bad_continued_complaint
, sym_name
);
1766 /* Make up a complex type from a basic one. Type is passed by
1767 reference in TPP and side-effected as necessary. The type
1768 qualifier TQ says how to handle the aux symbols at AX for
1769 the symbol SX we are currently analyzing. BIGEND says whether
1770 aux symbols are big-endian or little-endian.
1771 Returns the number of aux symbols we parsed. */
1774 upgrade_type (fd
, tpp
, tq
, ax
, bigend
, sym_name
)
1785 /* Used in array processing */
1796 t
= lookup_pointer_type (*tpp
);
1801 t
= lookup_function_type (*tpp
);
1808 /* Determine and record the domain type (type of index) */
1809 (*debug_swap
->swap_rndx_in
) (bigend
, &ax
->a_rndx
, &rndx
);
1815 rf
= AUX_GET_ISYM (bigend
, ax
);
1818 fh
= get_rfd (fd
, rf
);
1820 indx
= parse_type (fh
- debug_info
->fdr
,
1821 debug_info
->external_aux
+ fh
->iauxBase
,
1822 id
, (int *) NULL
, bigend
, sym_name
);
1824 /* The bounds type should be an integer type, but might be anything
1825 else due to corrupt aux entries. */
1826 if (TYPE_CODE (indx
) != TYPE_CODE_INT
)
1828 complain (&array_index_type_complaint
, sym_name
);
1829 indx
= mdebug_type_int
;
1832 /* Get the bounds, and create the array type. */
1834 lower
= AUX_GET_DNLOW (bigend
, ax
);
1836 upper
= AUX_GET_DNHIGH (bigend
, ax
);
1838 rf
= AUX_GET_WIDTH (bigend
, ax
); /* bit size of array element */
1840 range
= create_range_type ((struct type
*) NULL
, indx
,
1843 t
= create_array_type ((struct type
*) NULL
, *tpp
, range
);
1845 /* We used to fill in the supplied array element bitsize
1846 here if the TYPE_LENGTH of the target type was zero.
1847 This happens for a `pointer to an array of anonymous structs',
1848 but in this case the array element bitsize is also zero,
1849 so nothing is gained.
1850 And we used to check the TYPE_LENGTH of the target type against
1851 the supplied array element bitsize.
1852 gcc causes a mismatch for `pointer to array of object',
1853 since the sdb directives it uses do not have a way of
1854 specifying the bitsize, but it does no harm (the
1855 TYPE_LENGTH should be correct) and we should be able to
1856 ignore the erroneous bitsize from the auxiliary entry safely.
1857 dbx seems to ignore it too. */
1859 /* TYPE_FLAG_TARGET_STUB now takes care of the zero TYPE_LENGTH
1861 if (TYPE_LENGTH (*tpp
) == 0)
1863 TYPE_FLAGS (t
) |= TYPE_FLAG_TARGET_STUB
;
1870 /* Volatile -- currently ignored */
1874 /* Const -- currently ignored */
1878 complain (&unknown_type_qual_complaint
, tq
);
1884 /* Parse a procedure descriptor record PR. Note that the procedure is
1885 parsed _after_ the local symbols, now we just insert the extra
1886 information we need into a MIPS_EFI_SYMBOL_NAME symbol that has
1887 already been placed in the procedure's main block. Note also that
1888 images that have been partially stripped (ld -x) have been deprived
1889 of local symbols, and we have to cope with them here. FIRST_OFF is
1890 the offset of the first procedure for this FDR; we adjust the
1891 address by this amount, but I don't know why. SEARCH_SYMTAB is the symtab
1892 to look for the function which contains the MIPS_EFI_SYMBOL_NAME symbol
1893 in question, or NULL to use top_stack->cur_block. */
1895 static void parse_procedure
PARAMS ((PDR
*, struct symtab
*, CORE_ADDR
,
1896 struct partial_symtab
*));
1899 parse_procedure (pr
, search_symtab
, lowest_pdr_addr
, pst
)
1901 struct symtab
*search_symtab
;
1902 CORE_ADDR lowest_pdr_addr
;
1903 struct partial_symtab
*pst
;
1905 struct symbol
*s
, *i
;
1907 struct mips_extra_func_info
*e
;
1910 /* Simple rule to find files linked "-x" */
1911 if (cur_fdr
->rss
== -1)
1915 /* Static procedure at address pr->adr. Sigh. */
1916 /* FIXME-32x64. assuming pr->adr fits in long. */
1917 complain (&pdr_static_symbol_complaint
, (unsigned long) pr
->adr
);
1925 (*debug_swap
->swap_ext_in
) (cur_bfd
,
1926 ((char *) debug_info
->external_ext
1928 * debug_swap
->external_ext_size
)),
1930 sh_name
= debug_info
->ssext
+ she
.asym
.iss
;
1938 (*debug_swap
->swap_sym_in
) (cur_bfd
,
1939 ((char *) debug_info
->external_sym
1940 + ((cur_fdr
->isymBase
+ pr
->isym
)
1941 * debug_swap
->external_sym_size
)),
1943 sh_name
= debug_info
->ss
+ cur_fdr
->issBase
+ sh
.iss
;
1946 if (search_symtab
!= NULL
)
1949 /* This loses both in the case mentioned (want a static, find a global),
1950 but also if we are looking up a non-mangled name which happens to
1951 match the name of a mangled function. */
1952 /* We have to save the cur_fdr across the call to lookup_symbol.
1953 If the pdr is for a static function and if a global function with
1954 the same name exists, lookup_symbol will eventually read in the symtab
1955 for the global function and clobber cur_fdr. */
1956 FDR
*save_cur_fdr
= cur_fdr
;
1957 s
= lookup_symbol (sh_name
, NULL
, VAR_NAMESPACE
, 0, NULL
);
1958 cur_fdr
= save_cur_fdr
;
1962 BLOCKVECTOR_BLOCK (BLOCKVECTOR (search_symtab
), STATIC_BLOCK
),
1968 s
= mylookup_symbol (sh_name
, top_stack
->cur_block
,
1969 VAR_NAMESPACE
, LOC_BLOCK
);
1973 b
= SYMBOL_BLOCK_VALUE (s
);
1977 complain (&pdr_for_nonsymbol_complaint
, sh_name
);
1981 /* FIXME -- delete. We can't do symbol allocation now; it's all done. */
1982 s
= new_symbol (sh_name
);
1983 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
1984 SYMBOL_CLASS (s
) = LOC_BLOCK
;
1985 /* Donno its type, hope int is ok */
1986 SYMBOL_TYPE (s
) = lookup_function_type (mdebug_type_int
);
1987 add_symbol (s
, top_stack
->cur_block
);
1988 /* Wont have symbols for this one */
1990 SYMBOL_BLOCK_VALUE (s
) = b
;
1991 BLOCK_FUNCTION (b
) = s
;
1992 BLOCK_START (b
) = pr
->adr
;
1993 /* BOUND used to be the end of procedure's text, but the
1994 argument is no longer passed in. */
1995 BLOCK_END (b
) = bound
;
1996 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
1997 add_block (b
, top_stack
->cur_st
);
2001 i
= mylookup_symbol (MIPS_EFI_SYMBOL_NAME
, b
, LABEL_NAMESPACE
, LOC_CONST
);
2005 e
= (struct mips_extra_func_info
*) SYMBOL_VALUE (i
);
2007 e
->pdr
.isym
= (long) s
;
2008 e
->pdr
.adr
+= pst
->textlow
- lowest_pdr_addr
;
2010 /* Correct incorrect setjmp procedure descriptor from the library
2011 to make backtrace through setjmp work. */
2012 if (e
->pdr
.pcreg
== 0 && STREQ (sh_name
, "setjmp"))
2014 complain (&bad_setjmp_pdr_complaint
, 0);
2015 e
->pdr
.pcreg
= RA_REGNUM
;
2016 e
->pdr
.regmask
= 0x80000000;
2017 e
->pdr
.regoffset
= -4;
2021 /* It would be reasonable that functions that have been compiled
2022 without debugging info have a btNil type for their return value,
2023 and functions that are void and are compiled with debugging info
2025 gcc and DEC f77 put out btNil types for both cases, so btNil is mapped
2026 to TYPE_CODE_VOID in parse_type to get the `compiled with debugging info'
2028 The glevel field in cur_fdr could be used to determine the presence
2029 of debugging info, but GCC doesn't always pass the -g switch settings
2030 to the assembler and GAS doesn't set the glevel field from the -g switch
2032 To work around these problems, the return value type of a TYPE_CODE_VOID
2033 function is adjusted accordingly if no debugging info was found in the
2034 compilation unit. */
2036 if (processing_gcc_compilation
== 0
2037 && found_ecoff_debugging_info
== 0
2038 && TYPE_CODE (TYPE_TARGET_TYPE (SYMBOL_TYPE (s
))) == TYPE_CODE_VOID
)
2039 SYMBOL_TYPE (s
) = nodebug_func_symbol_type
;
2042 /* Relocate the extra function info pointed to by the symbol table. */
2045 ecoff_relocate_efi (sym
, delta
)
2049 struct mips_extra_func_info
*e
;
2051 e
= (struct mips_extra_func_info
*) SYMBOL_VALUE (sym
);
2053 e
->pdr
.adr
+= delta
;
2056 /* Parse the external symbol ES. Just call parse_symbol() after
2057 making sure we know where the aux are for it.
2058 BIGEND says whether aux entries are big-endian or little-endian.
2060 This routine clobbers top_stack->cur_block and ->cur_st. */
2062 static void parse_external
PARAMS ((EXTR
*, int, struct section_offsets
*));
2065 parse_external (es
, bigend
, section_offsets
)
2068 struct section_offsets
*section_offsets
;
2072 if (es
->ifd
!= ifdNil
)
2075 cur_fdr
= debug_info
->fdr
+ cur_fd
;
2076 ax
= debug_info
->external_aux
+ cur_fdr
->iauxBase
;
2080 cur_fdr
= debug_info
->fdr
;
2084 /* Reading .o files */
2085 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
)
2088 switch (es
->asym
.st
)
2091 /* These are generated for static symbols in .o files,
2112 /* FIXME: Turn this into a complaint? */
2114 printf_filtered ("Warning: %s `%s' is undefined (in %s)\n",
2115 what
, debug_info
->ssext
+ es
->asym
.iss
,
2116 fdr_name (cur_fdr
));
2120 switch (es
->asym
.st
)
2124 /* There is no need to parse the external procedure symbols.
2125 If they are from objects compiled without -g, their index will
2126 be indexNil, and the symbol definition from the minimal symbol
2127 is preferrable (yielding a function returning int instead of int).
2128 If the index points to a local procedure symbol, the local
2129 symbol already provides the correct type.
2130 Note that the index of the external procedure symbol points
2131 to the local procedure symbol in the local symbol table, and
2132 _not_ to the auxiliary symbol info. */
2136 /* Global common symbols are resolved by the runtime loader,
2138 if (es
->asym
.sc
== scCommon
|| es
->asym
.sc
== scSCommon
)
2141 /* Note that the case of a symbol with indexNil must be handled
2142 anyways by parse_symbol(). */
2143 parse_symbol (&es
->asym
, ax
, (char *) NULL
, bigend
, section_offsets
);
2150 /* Parse the line number info for file descriptor FH into
2151 GDB's linetable LT. MIPS' encoding requires a little bit
2152 of magic to get things out. Note also that MIPS' line
2153 numbers can go back and forth, apparently we can live
2154 with that and do not need to reorder our linetables */
2156 static void parse_lines
PARAMS ((FDR
*, PDR
*, struct linetable
*, int,
2157 struct partial_symtab
*, CORE_ADDR
));
2160 parse_lines (fh
, pr
, lt
, maxlines
, pst
, lowest_pdr_addr
)
2163 struct linetable
*lt
;
2165 struct partial_symtab
*pst
;
2166 CORE_ADDR lowest_pdr_addr
;
2168 unsigned char *base
;
2170 int delta
, count
, lineno
= 0;
2172 if (fh
->cbLine
== 0)
2175 /* Scan by procedure descriptors */
2177 for (j
= 0; j
< fh
->cpd
; j
++, pr
++)
2181 unsigned char *halt
;
2183 /* No code for this one */
2184 if (pr
->iline
== ilineNil
||
2185 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
2188 /* Determine start and end address of compressed line bytes for
2190 base
= debug_info
->line
+ fh
->cbLineOffset
;
2191 if (j
!= (fh
->cpd
- 1))
2192 halt
= base
+ pr
[1].cbLineOffset
;
2194 halt
= base
+ fh
->cbLine
;
2195 base
+= pr
->cbLineOffset
;
2197 adr
= pst
->textlow
+ pr
->adr
- lowest_pdr_addr
;
2199 l
= adr
>> 2; /* in words */
2200 for (lineno
= pr
->lnLow
; base
< halt
; )
2202 count
= *base
& 0x0f;
2203 delta
= *base
++ >> 4;
2208 delta
= (base
[0] << 8) | base
[1];
2209 if (delta
>= 0x8000)
2213 lineno
+= delta
; /* first delta is 0 */
2215 /* Complain if the line table overflows. Could happen
2216 with corrupt binaries. */
2217 if (lt
->nitems
>= maxlines
)
2219 complain (&bad_linetable_guess_complaint
, fdr_name (fh
));
2222 k
= add_line (lt
, lineno
, l
, k
);
2228 /* Master parsing procedure for first-pass reading of file symbols
2229 into a partial_symtab. */
2232 parse_partial_symbols (objfile
, section_offsets
)
2233 struct objfile
*objfile
;
2234 struct section_offsets
*section_offsets
;
2236 const bfd_size_type external_sym_size
= debug_swap
->external_sym_size
;
2237 const bfd_size_type external_rfd_size
= debug_swap
->external_rfd_size
;
2238 const bfd_size_type external_ext_size
= debug_swap
->external_ext_size
;
2239 void (* const swap_ext_in
) PARAMS ((bfd
*, PTR
, EXTR
*))
2240 = debug_swap
->swap_ext_in
;
2241 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
2242 = debug_swap
->swap_sym_in
;
2243 void (* const swap_rfd_in
) PARAMS ((bfd
*, PTR
, RFDT
*))
2244 = debug_swap
->swap_rfd_in
;
2246 HDRR
*hdr
= &debug_info
->symbolic_header
;
2247 /* Running pointers */
2252 register EXTR
*ext_in
;
2255 struct partial_symtab
*pst
;
2256 int textlow_not_set
= 1;
2257 int past_first_source_file
= 0;
2259 /* List of current psymtab's include files */
2260 char **psymtab_include_list
;
2261 int includes_allocated
;
2264 struct pst_map
*fdr_to_pst
;
2265 /* Index within current psymtab dependency list */
2266 struct partial_symtab
**dependency_list
;
2267 int dependencies_used
, dependencies_allocated
;
2268 struct cleanup
*old_chain
;
2270 enum language prev_language
;
2271 asection
*text_sect
;
2272 int relocatable
= 0;
2274 /* Irix 5.2 shared libraries have a fh->adr field of zero, but
2275 the shared libraries are prelinked at a high memory address.
2276 We have to adjust the start address of the object file for this case,
2277 by setting it to the start address of the first procedure in the file.
2278 But we should do no adjustments if we are debugging a .o file, where
2279 the text section (and fh->adr) really starts at zero. */
2280 text_sect
= bfd_get_section_by_name (cur_bfd
, ".text");
2281 if (text_sect
!= NULL
2282 && (bfd_get_section_flags (cur_bfd
, text_sect
) & SEC_RELOC
))
2285 extern_tab
= (EXTR
*) obstack_alloc (&objfile
->psymbol_obstack
,
2286 sizeof (EXTR
) * hdr
->iextMax
);
2288 includes_allocated
= 30;
2290 psymtab_include_list
= (char **) alloca (includes_allocated
*
2292 next_symbol_text_func
= mdebug_next_symbol_text
;
2294 dependencies_allocated
= 30;
2295 dependencies_used
= 0;
2297 (struct partial_symtab
**) alloca (dependencies_allocated
*
2298 sizeof (struct partial_symtab
*));
2300 last_source_file
= NULL
;
2305 * Only parse the Local and External symbols, and the Relative FDR.
2306 * Fixup enough of the loader symtab to be able to use it.
2307 * Allocate space only for the file's portions we need to
2312 max_glevel
= MIN_GLEVEL
;
2314 /* Allocate the map FDR -> PST.
2315 Minor hack: -O3 images might claim some global data belongs
2316 to FDR -1. We`ll go along with that */
2317 fdr_to_pst
= (struct pst_map
*) xzalloc ((hdr
->ifdMax
+ 1) * sizeof *fdr_to_pst
);
2318 old_chain
= make_cleanup (free
, fdr_to_pst
);
2321 struct partial_symtab
*pst
= new_psymtab ("", objfile
, section_offsets
);
2322 fdr_to_pst
[-1].pst
= pst
;
2326 /* Allocate the global pending list. */
2328 ((struct mdebug_pending
**)
2329 obstack_alloc (&objfile
->psymbol_obstack
,
2330 hdr
->ifdMax
* sizeof (struct mdebug_pending
*)));
2331 memset ((PTR
) pending_list
, 0,
2332 hdr
->ifdMax
* sizeof (struct mdebug_pending
*));
2334 /* Pass 0 over external syms: swap them in. */
2335 ext_block
= (EXTR
*) xmalloc (hdr
->iextMax
* sizeof (EXTR
));
2336 make_cleanup (free
, ext_block
);
2338 ext_out
= (char *) debug_info
->external_ext
;
2339 ext_out_end
= ext_out
+ hdr
->iextMax
* external_ext_size
;
2341 for (; ext_out
< ext_out_end
; ext_out
+= external_ext_size
, ext_in
++)
2342 (*swap_ext_in
) (cur_bfd
, ext_out
, ext_in
);
2344 /* Pass 1 over external syms: Presize and partition the list */
2346 ext_in_end
= ext_in
+ hdr
->iextMax
;
2347 for (; ext_in
< ext_in_end
; ext_in
++)
2349 /* See calls to complain below. */
2350 if (ext_in
->ifd
>= -1
2351 && ext_in
->ifd
< hdr
->ifdMax
2352 && ext_in
->asym
.iss
>= 0
2353 && ext_in
->asym
.iss
< hdr
->issExtMax
)
2354 fdr_to_pst
[ext_in
->ifd
].n_globals
++;
2357 /* Pass 1.5 over files: partition out global symbol space */
2359 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++)
2361 fdr_to_pst
[f_idx
].globals_offset
= s_idx
;
2362 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
2363 fdr_to_pst
[f_idx
].n_globals
= 0;
2366 /* Pass 2 over external syms: fill in external symbols */
2368 ext_in_end
= ext_in
+ hdr
->iextMax
;
2369 for (; ext_in
< ext_in_end
; ext_in
++)
2371 enum minimal_symbol_type ms_type
= mst_text
;
2372 CORE_ADDR svalue
= ext_in
->asym
.value
;
2374 /* The Irix 5 native tools seem to sometimes generate bogus
2375 external symbols. */
2376 if (ext_in
->ifd
< -1 || ext_in
->ifd
>= hdr
->ifdMax
)
2378 complain (&bad_ext_ifd_complaint
, ext_in
->ifd
, hdr
->ifdMax
);
2381 if (ext_in
->asym
.iss
< 0 || ext_in
->asym
.iss
>= hdr
->issExtMax
)
2383 complain (&bad_ext_iss_complaint
, ext_in
->asym
.iss
,
2388 extern_tab
[fdr_to_pst
[ext_in
->ifd
].globals_offset
2389 + fdr_to_pst
[ext_in
->ifd
].n_globals
++] = *ext_in
;
2391 if (ext_in
->asym
.sc
== scUndefined
|| ext_in
->asym
.sc
== scNil
)
2394 name
= debug_info
->ssext
+ ext_in
->asym
.iss
;
2395 switch (ext_in
->asym
.st
)
2398 svalue
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT
);
2401 ms_type
= mst_file_text
;
2402 svalue
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT
);
2405 if (ext_in
->asym
.sc
== scCommon
|| ext_in
->asym
.sc
== scSCommon
)
2407 /* The value of a common symbol is its size, not its address.
2411 else if (ext_in
->asym
.sc
== scData
2412 || ext_in
->asym
.sc
== scSData
2413 || ext_in
->asym
.sc
== scRData
2414 || ext_in
->asym
.sc
== scPData
2415 || ext_in
->asym
.sc
== scXData
)
2418 svalue
+= ANOFFSET (section_offsets
, SECT_OFF_DATA
);
2423 svalue
+= ANOFFSET (section_offsets
, SECT_OFF_BSS
);
2427 if (ext_in
->asym
.sc
== scAbs
)
2429 else if (ext_in
->asym
.sc
== scText
2430 || ext_in
->asym
.sc
== scInit
2431 || ext_in
->asym
.sc
== scFini
)
2433 ms_type
= mst_file_text
;
2434 svalue
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT
);
2436 else if (ext_in
->asym
.sc
== scData
2437 || ext_in
->asym
.sc
== scSData
2438 || ext_in
->asym
.sc
== scRData
2439 || ext_in
->asym
.sc
== scPData
2440 || ext_in
->asym
.sc
== scXData
)
2442 ms_type
= mst_file_data
;
2443 svalue
+= ANOFFSET (section_offsets
, SECT_OFF_DATA
);
2447 ms_type
= mst_file_bss
;
2448 svalue
+= ANOFFSET (section_offsets
, SECT_OFF_BSS
);
2452 /* The alpha has the section start addresses in stLocal symbols
2453 whose name starts with a `.'. Skip those but complain for all
2454 other stLocal symbols. */
2459 ms_type
= mst_unknown
;
2460 complain (&unknown_ext_complaint
, name
);
2462 prim_record_minimal_symbol (name
, svalue
, ms_type
, objfile
);
2465 /* Pass 3 over files, over local syms: fill in static symbols */
2466 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++)
2468 struct partial_symtab
*save_pst
;
2472 cur_fdr
= fh
= debug_info
->fdr
+ f_idx
;
2476 fdr_to_pst
[f_idx
].pst
= NULL
;
2480 /* Determine the start address for this object file from the
2481 file header and relocate it, except for Irix 5.2 zero fh->adr. */
2485 if (relocatable
|| textlow
!= 0)
2486 textlow
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT
);
2490 pst
= start_psymtab_common (objfile
, section_offsets
,
2493 objfile
->global_psymbols
.next
,
2494 objfile
->static_psymbols
.next
);
2495 pst
->read_symtab_private
= ((char *)
2496 obstack_alloc (&objfile
->psymbol_obstack
,
2497 sizeof (struct symloc
)));
2498 memset ((PTR
) pst
->read_symtab_private
, 0, sizeof (struct symloc
));
2501 FDR_IDX (pst
) = f_idx
;
2502 CUR_BFD (pst
) = cur_bfd
;
2503 DEBUG_SWAP (pst
) = debug_swap
;
2504 DEBUG_INFO (pst
) = debug_info
;
2505 PENDING_LIST (pst
) = pending_list
;
2507 /* The way to turn this into a symtab is to call... */
2508 pst
->read_symtab
= mdebug_psymtab_to_symtab
;
2510 /* Set up language for the pst.
2511 The language from the FDR is used if it is unambigious (e.g. cfront
2512 with native cc and g++ will set the language to C).
2513 Otherwise we have to deduce the language from the filename.
2514 Native ecoff has every header file in a separate FDR, so
2515 deduce_language_from_filename will return language_unknown for
2516 a header file, which is not what we want.
2517 But the FDRs for the header files are after the FDR for the source
2518 file, so we can assign the language of the source file to the
2519 following header files. Then we save the language in the private
2520 pst data so that we can reuse it when building symtabs. */
2521 prev_language
= psymtab_language
;
2525 case langCplusplusV2
:
2526 psymtab_language
= language_cplus
;
2529 psymtab_language
= deduce_language_from_filename (fdr_name (fh
));
2532 if (psymtab_language
== language_unknown
)
2533 psymtab_language
= prev_language
;
2534 PST_PRIVATE (pst
)->pst_language
= psymtab_language
;
2536 pst
->texthigh
= pst
->textlow
;
2538 /* For stabs-in-ecoff files, the second symbol must be @stab.
2539 This symbol is emitted by mips-tfile to signal that the
2540 current object file uses encapsulated stabs instead of mips
2541 ecoff for local symbols. (It is the second symbol because
2542 the first symbol is the stFile used to signal the start of a
2544 processing_gcc_compilation
= 0;
2547 (*swap_sym_in
) (cur_bfd
,
2548 ((char *) debug_info
->external_sym
2549 + (fh
->isymBase
+ 1) * external_sym_size
),
2551 if (STREQ (debug_info
->ss
+ fh
->issBase
+ sh
.iss
, stabs_symbol
))
2552 processing_gcc_compilation
= 2;
2555 if (processing_gcc_compilation
!= 0)
2557 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++)
2562 (*swap_sym_in
) (cur_bfd
,
2563 (((char *) debug_info
->external_sym
)
2564 + (fh
->isymBase
+ cur_sdx
) * external_sym_size
),
2566 type_code
= ECOFF_UNMARK_STAB (sh
.index
);
2567 if (!ECOFF_IS_STAB (&sh
))
2569 if (sh
.st
== stProc
|| sh
.st
== stStaticProc
)
2574 sh
.value
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT
);
2575 if (sh
.st
== stStaticProc
)
2577 namestring
= debug_info
->ss
+ fh
->issBase
+ sh
.iss
;
2578 prim_record_minimal_symbol_and_info (namestring
,
2585 procaddr
= sh
.value
;
2587 isym
= AUX_GET_ISYM (fh
->fBigendian
,
2588 (debug_info
->external_aux
2591 (*swap_sym_in
) (cur_bfd
,
2592 ((char *) debug_info
->external_sym
2593 + ((fh
->isymBase
+ isym
- 1)
2594 * external_sym_size
)),
2598 long high
= procaddr
+ sh
.value
;
2600 /* Kludge for Irix 5.2 zero fh->adr. */
2602 && (pst
->textlow
== 0 || procaddr
< pst
->textlow
))
2603 pst
->textlow
= procaddr
;
2604 if (high
> pst
->texthigh
)
2605 pst
->texthigh
= high
;
2608 else if (sh
.st
== stStatic
)
2622 namestring
= debug_info
->ss
+ fh
->issBase
+ sh
.iss
;
2623 sh
.value
+= ANOFFSET (section_offsets
, SECT_OFF_DATA
);
2624 prim_record_minimal_symbol_and_info (namestring
,
2633 namestring
= debug_info
->ss
+ fh
->issBase
+ sh
.iss
;
2634 sh
.value
+= ANOFFSET (section_offsets
, SECT_OFF_BSS
);
2635 prim_record_minimal_symbol_and_info (namestring
,
2646 #define SET_NAMESTRING() \
2647 namestring = debug_info->ss + fh->issBase + sh.iss
2648 #define CUR_SYMBOL_TYPE type_code
2649 #define CUR_SYMBOL_VALUE sh.value
2650 #define START_PSYMTAB(ofile,secoff,fname,low,symoff,global_syms,static_syms)\
2652 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps,textlow_not_set) (void)0
2653 #define HANDLE_RBRAC(val) \
2654 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
2655 #include "partial-stab.h"
2660 for (cur_sdx
= 0; cur_sdx
< fh
->csym
;)
2663 enum address_class
class;
2665 (*swap_sym_in
) (cur_bfd
,
2666 ((char *) debug_info
->external_sym
2667 + ((fh
->isymBase
+ cur_sdx
)
2668 * external_sym_size
)),
2671 if (ECOFF_IS_STAB (&sh
))
2677 /* Non absolute static symbols go into the minimal table. */
2678 if (sh
.sc
== scUndefined
|| sh
.sc
== scNil
2679 || (sh
.index
== indexNil
2680 && (sh
.st
!= stStatic
|| sh
.sc
== scAbs
)))
2682 /* FIXME, premature? */
2687 name
= debug_info
->ss
+ fh
->issBase
+ sh
.iss
;
2692 /* The value of a stEnd symbol is the displacement from the
2693 corresponding start symbol value, do not relocate it. */
2695 sh
.value
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT
);
2702 sh
.value
+= ANOFFSET (section_offsets
, SECT_OFF_DATA
);
2706 sh
.value
+= ANOFFSET (section_offsets
, SECT_OFF_BSS
);
2717 prim_record_minimal_symbol_and_info (name
, sh
.value
,
2718 mst_file_text
, NULL
,
2719 SECT_OFF_TEXT
, objfile
);
2724 /* Usually there is a local and a global stProc symbol
2725 for a function. This means that the function name
2726 has already been entered into the mimimal symbol table
2727 while processing the global symbols in pass 2 above.
2728 One notable exception is the PROGRAM name from
2729 f77 compiled executables, it is only put out as
2730 local stProc symbol, and a global MAIN__ stProc symbol
2731 points to it. It doesn't matter though, as gdb is
2732 still able to find the PROGRAM name via the partial
2733 symbol table, and the MAIN__ symbol via the minimal
2735 if (sh
.st
== stProc
)
2736 add_psymbol_to_list (name
, strlen (name
),
2737 VAR_NAMESPACE
, LOC_BLOCK
,
2738 &objfile
->global_psymbols
,
2739 sh
.value
, 0, psymtab_language
, objfile
);
2741 add_psymbol_to_list (name
, strlen (name
),
2742 VAR_NAMESPACE
, LOC_BLOCK
,
2743 &objfile
->static_psymbols
,
2744 sh
.value
, 0, psymtab_language
, objfile
);
2746 /* Skip over procedure to next one. */
2747 if (sh
.index
>= hdr
->iauxMax
)
2749 /* Should not happen, but does when cross-compiling
2750 with the MIPS compiler. FIXME -- pull later. */
2751 complain (&index_complaint
, name
);
2752 new_sdx
= cur_sdx
+ 1; /* Don't skip at all */
2755 new_sdx
= AUX_GET_ISYM (fh
->fBigendian
,
2756 (debug_info
->external_aux
2759 procaddr
= sh
.value
;
2761 if (new_sdx
<= cur_sdx
)
2763 /* This should not happen either... FIXME. */
2764 complain (&aux_index_complaint
, name
);
2765 new_sdx
= cur_sdx
+ 1; /* Don't skip backward */
2769 (*swap_sym_in
) (cur_bfd
,
2770 ((char *) debug_info
->external_sym
2771 + ((fh
->isymBase
+ cur_sdx
- 1)
2772 * external_sym_size
)),
2777 /* Kludge for Irix 5.2 zero fh->adr. */
2779 && (pst
->textlow
== 0 || procaddr
< pst
->textlow
))
2780 pst
->textlow
= procaddr
;
2782 high
= procaddr
+ sh
.value
;
2783 if (high
> pst
->texthigh
)
2784 pst
->texthigh
= high
;
2787 case stStatic
: /* Variable */
2792 || sh
.sc
== scXData
)
2793 prim_record_minimal_symbol_and_info (name
, sh
.value
,
2794 mst_file_data
, NULL
,
2798 prim_record_minimal_symbol_and_info (name
, sh
.value
,
2805 case stIndirect
:/* Irix5 forward declaration */
2806 /* Skip forward declarations from Irix5 cc */
2809 case stTypedef
:/* Typedef */
2810 /* Skip typedefs for forward declarations and opaque
2811 structs from alpha and mips cc. */
2812 if (sh
.iss
== 0 || has_opaque_xref (fh
, &sh
))
2814 class = LOC_TYPEDEF
;
2817 case stConstant
: /* Constant decl */
2824 case stBlock
: /* { }, str, un, enum*/
2825 /* Do not create a partial symbol for cc unnamed aggregates
2826 and gcc empty aggregates. */
2827 if ((sh
.sc
== scInfo
2828 || sh
.sc
== scCommon
|| sh
.sc
== scSCommon
)
2830 && sh
.index
!= cur_sdx
+ 2)
2832 add_psymbol_to_list (name
, strlen (name
),
2833 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2834 &objfile
->static_psymbols
,
2836 psymtab_language
, objfile
);
2838 handle_psymbol_enumerators (objfile
, fh
, sh
.st
, sh
.value
);
2840 /* Skip over the block */
2842 if (new_sdx
<= cur_sdx
)
2844 /* This happens with the Ultrix kernel. */
2845 complain (&block_index_complaint
, name
);
2846 new_sdx
= cur_sdx
+ 1; /* Don't skip backward */
2851 case stFile
: /* File headers */
2852 case stLabel
: /* Labels */
2853 case stEnd
: /* Ends of files */
2856 case stLocal
: /* Local variables */
2857 /* Normally these are skipped because we skip over
2858 all blocks we see. However, these can occur
2859 as visible symbols in a .h file that contains code. */
2863 /* Both complaints are valid: one gives symbol name,
2864 the other the offending symbol type. */
2865 complain (&unknown_sym_complaint
, name
);
2866 complain (&unknown_st_complaint
, sh
.st
);
2870 /* Use this gdb symbol */
2871 add_psymbol_to_list (name
, strlen (name
),
2872 VAR_NAMESPACE
, class,
2873 &objfile
->static_psymbols
, sh
.value
,
2874 0, psymtab_language
, objfile
);
2876 cur_sdx
++; /* Go to next file symbol */
2879 /* Now do enter the external symbols. */
2880 ext_ptr
= &extern_tab
[fdr_to_pst
[f_idx
].globals_offset
];
2881 cur_sdx
= fdr_to_pst
[f_idx
].n_globals
;
2882 PST_PRIVATE (save_pst
)->extern_count
= cur_sdx
;
2883 PST_PRIVATE (save_pst
)->extern_tab
= ext_ptr
;
2884 for (; --cur_sdx
>= 0; ext_ptr
++)
2886 enum address_class
class;
2891 if (ext_ptr
->ifd
!= f_idx
)
2893 psh
= &ext_ptr
->asym
;
2895 /* Do not add undefined symbols to the partial symbol table. */
2896 if (psh
->sc
== scUndefined
|| psh
->sc
== scNil
)
2899 svalue
= psh
->value
;
2903 svalue
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT
);
2910 svalue
+= ANOFFSET (section_offsets
, SECT_OFF_DATA
);
2914 svalue
+= ANOFFSET (section_offsets
, SECT_OFF_BSS
);
2921 /* These are generated for static symbols in .o files,
2926 /* External procedure symbols have been entered
2927 into the minimal symbol table in pass 2 above.
2928 Ignore them, as parse_external will ignore them too. */
2934 complain (&unknown_ext_complaint
,
2935 debug_info
->ssext
+ psh
->iss
);
2936 /* Fall through, pretend it's global. */
2938 /* Global common symbols are resolved by the runtime loader,
2940 if (psh
->sc
== scCommon
|| psh
->sc
== scSCommon
)
2946 name
= debug_info
->ssext
+ psh
->iss
;
2947 add_psymbol_to_list (name
, strlen (name
),
2948 VAR_NAMESPACE
, class,
2949 &objfile
->global_psymbols
,
2951 psymtab_language
, objfile
);
2955 /* Link pst to FDR. end_psymtab returns NULL if the psymtab was
2956 empty and put on the free list. */
2957 fdr_to_pst
[f_idx
].pst
= end_psymtab (save_pst
,
2958 psymtab_include_list
, includes_used
,
2959 -1, save_pst
->texthigh
,
2960 dependency_list
, dependencies_used
, textlow_not_set
);
2962 dependencies_used
= 0;
2964 if (objfile
->ei
.entry_point
>= save_pst
->textlow
&&
2965 objfile
->ei
.entry_point
< save_pst
->texthigh
)
2967 objfile
->ei
.entry_file_lowpc
= save_pst
->textlow
;
2968 objfile
->ei
.entry_file_highpc
= save_pst
->texthigh
;
2971 /* The objfile has its functions reordered if this partial symbol
2972 table overlaps any other partial symbol table.
2973 We cannot assume a reordered objfile if a partial symbol table
2974 is contained within another partial symbol table, as partial symbol
2975 tables for include files with executable code are contained
2976 within the partial symbol table for the including source file,
2977 and we do not want to flag the objfile reordered for these cases.
2979 This strategy works well for Irix-5.2 shared libraries, but we
2980 might have to use a more elaborate (and slower) algorithm for
2982 save_pst
= fdr_to_pst
[f_idx
].pst
;
2983 if (save_pst
!= NULL
2984 && save_pst
->textlow
!= 0
2985 && !(objfile
->flags
& OBJF_REORDERED
))
2987 ALL_OBJFILE_PSYMTABS (objfile
, pst
)
2990 && save_pst
->textlow
>= pst
->textlow
2991 && save_pst
->textlow
< pst
->texthigh
2992 && save_pst
->texthigh
> pst
->texthigh
)
2994 objfile
->flags
|= OBJF_REORDERED
;
3001 /* Now scan the FDRs for dependencies */
3002 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++)
3004 fh
= f_idx
+ debug_info
->fdr
;
3005 pst
= fdr_to_pst
[f_idx
].pst
;
3007 if (pst
== (struct partial_symtab
*)NULL
)
3010 /* This should catch stabs-in-ecoff. */
3014 /* Skip the first file indirect entry as it is a self dependency
3015 for source files or a reverse .h -> .c dependency for header files. */
3016 pst
->number_of_dependencies
= 0;
3018 ((struct partial_symtab
**)
3019 obstack_alloc (&objfile
->psymbol_obstack
,
3021 * sizeof (struct partial_symtab
*))));
3022 for (s_idx
= 1; s_idx
< fh
->crfd
; s_idx
++)
3026 (*swap_rfd_in
) (cur_bfd
,
3027 ((char *) debug_info
->external_rfd
3028 + (fh
->rfdBase
+ s_idx
) * external_rfd_size
),
3030 if (rh
< 0 || rh
>= hdr
->ifdMax
)
3032 complain (&bad_file_number_complaint
, rh
);
3036 /* Skip self dependencies of header files. */
3040 /* Do not add to dependeny list if psymtab was empty. */
3041 if (fdr_to_pst
[rh
].pst
== (struct partial_symtab
*)NULL
)
3043 pst
->dependencies
[pst
->number_of_dependencies
++] = fdr_to_pst
[rh
].pst
;
3047 /* Remove the dummy psymtab created for -O3 images above, if it is
3048 still empty, to enable the detection of stripped executables. */
3049 if (objfile
->psymtabs
->next
== NULL
3050 && objfile
->psymtabs
->number_of_dependencies
== 0
3051 && objfile
->psymtabs
->n_global_syms
== 0
3052 && objfile
->psymtabs
->n_static_syms
== 0)
3053 objfile
->psymtabs
= NULL
;
3054 do_cleanups (old_chain
);
3057 /* If the current psymbol has an enumerated type, we need to add
3058 all the the enum constants to the partial symbol table. */
3061 handle_psymbol_enumerators (objfile
, fh
, stype
, svalue
)
3062 struct objfile
*objfile
;
3067 const bfd_size_type external_sym_size
= debug_swap
->external_sym_size
;
3068 void (* const swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*))
3069 = debug_swap
->swap_sym_in
;
3070 char *ext_sym
= ((char *) debug_info
->external_sym
3071 + ((fh
->isymBase
+ cur_sdx
+ 1) * external_sym_size
));
3081 /* It is an enumerated type if the next symbol entry is a stMember
3082 and its auxiliary index is indexNil or its auxiliary entry
3083 is a plain btNil or btVoid.
3084 Alpha cc -migrate enums are recognized by a zero index and
3085 a zero symbol value. */
3086 (*swap_sym_in
) (cur_bfd
, ext_sym
, &sh
);
3087 if (sh
.st
!= stMember
)
3090 if (sh
.index
== indexNil
3091 || (sh
.index
== 0 && svalue
== 0))
3093 (*debug_swap
->swap_tir_in
) (fh
->fBigendian
,
3094 &(debug_info
->external_aux
3095 + fh
->iauxBase
+ sh
.index
)->a_ti
,
3097 if ((tir
.bt
!= btNil
&& tir
.bt
!= btVoid
) || tir
.tq0
!= tqNil
)
3109 (*swap_sym_in
) (cur_bfd
, ext_sym
, &sh
);
3110 if (sh
.st
!= stMember
)
3112 name
= debug_info
->ss
+ cur_fdr
->issBase
+ sh
.iss
;
3114 /* Note that the value doesn't matter for enum constants
3115 in psymtabs, just in symtabs. */
3116 add_psymbol_to_list (name
, strlen (name
),
3117 VAR_NAMESPACE
, LOC_CONST
,
3118 &objfile
->static_psymbols
, 0,
3119 0, psymtab_language
, objfile
);
3120 ext_sym
+= external_sym_size
;
3125 mdebug_next_symbol_text (objfile
)
3126 struct objfile
*objfile
; /* argument objfile is currently unused */
3131 (*debug_swap
->swap_sym_in
) (cur_bfd
,
3132 ((char *) debug_info
->external_sym
3133 + ((cur_fdr
->isymBase
+ cur_sdx
)
3134 * debug_swap
->external_sym_size
)),
3136 return debug_info
->ss
+ cur_fdr
->issBase
+ sh
.iss
;
3139 /* Ancillary function to psymtab_to_symtab(). Does all the work
3140 for turning the partial symtab PST into a symtab, recurring
3141 first on all dependent psymtabs. The argument FILENAME is
3142 only passed so we can see in debug stack traces what file
3145 This function has a split personality, based on whether the
3146 symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
3147 The flow of control and even the memory allocation differs. FIXME. */
3150 psymtab_to_symtab_1 (pst
, filename
)
3151 struct partial_symtab
*pst
;
3154 bfd_size_type external_sym_size
;
3155 bfd_size_type external_pdr_size
;
3156 void (*swap_sym_in
) PARAMS ((bfd
*, PTR
, SYMR
*));
3157 void (*swap_pdr_in
) PARAMS ((bfd
*, PTR
, PDR
*));
3161 struct linetable
*lines
;
3162 CORE_ADDR lowest_pdr_addr
= 0;
3168 /* Read in all partial symbtabs on which this one is dependent.
3169 NOTE that we do have circular dependencies, sigh. We solved
3170 that by setting pst->readin before this point. */
3172 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
3173 if (!pst
->dependencies
[i
]->readin
)
3175 /* Inform about additional files to be read in. */
3178 fputs_filtered (" ", gdb_stdout
);
3180 fputs_filtered ("and ", gdb_stdout
);
3182 printf_filtered ("%s...",
3183 pst
->dependencies
[i
]->filename
);
3184 wrap_here (""); /* Flush output */
3185 gdb_flush (gdb_stdout
);
3187 /* We only pass the filename for debug purposes */
3188 psymtab_to_symtab_1 (pst
->dependencies
[i
],
3189 pst
->dependencies
[i
]->filename
);
3192 /* Do nothing if this is a dummy psymtab. */
3194 if (pst
->n_global_syms
== 0 && pst
->n_static_syms
== 0
3195 && pst
->textlow
== 0 && pst
->texthigh
== 0)
3198 /* Now read the symbols for this symtab */
3200 cur_bfd
= CUR_BFD (pst
);
3201 debug_swap
= DEBUG_SWAP (pst
);
3202 debug_info
= DEBUG_INFO (pst
);
3203 pending_list
= PENDING_LIST (pst
);
3204 external_sym_size
= debug_swap
->external_sym_size
;
3205 external_pdr_size
= debug_swap
->external_pdr_size
;
3206 swap_sym_in
= debug_swap
->swap_sym_in
;
3207 swap_pdr_in
= debug_swap
->swap_pdr_in
;
3208 current_objfile
= pst
->objfile
;
3209 cur_fd
= FDR_IDX (pst
);
3210 fh
= ((cur_fd
== -1)
3212 : debug_info
->fdr
+ cur_fd
);
3215 /* See comment in parse_partial_symbols about the @stabs sentinel. */
3216 processing_gcc_compilation
= 0;
3217 if (fh
!= (FDR
*) NULL
&& fh
->csym
>= 2)
3221 (*swap_sym_in
) (cur_bfd
,
3222 ((char *) debug_info
->external_sym
3223 + (fh
->isymBase
+ 1) * external_sym_size
),
3225 if (STREQ (debug_info
->ss
+ fh
->issBase
+ sh
.iss
,
3228 /* We indicate that this is a GCC compilation so that certain
3229 features will be enabled in stabsread/dbxread. */
3230 processing_gcc_compilation
= 2;
3234 if (processing_gcc_compilation
!= 0)
3237 /* This symbol table contains stabs-in-ecoff entries. */
3239 /* Parse local symbols first */
3241 if (fh
->csym
<= 2) /* FIXME, this blows psymtab->symtab ptr */
3243 current_objfile
= NULL
;
3246 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++)
3252 (*swap_sym_in
) (cur_bfd
,
3253 (((char *) debug_info
->external_sym
)
3254 + (fh
->isymBase
+ cur_sdx
) * external_sym_size
),
3256 name
= debug_info
->ss
+ fh
->issBase
+ sh
.iss
;
3258 if (ECOFF_IS_STAB (&sh
))
3260 int type_code
= ECOFF_UNMARK_STAB (sh
.index
);
3262 /* We should never get non N_STAB symbols here, but they
3263 should be harmless, so keep process_one_symbol from
3264 complaining about them. */
3265 if (type_code
& N_STAB
)
3267 process_one_symbol (type_code
, 0, valu
, name
,
3268 pst
->section_offsets
, pst
->objfile
);
3270 if (type_code
== N_FUN
)
3272 /* Make up special symbol to contain
3273 procedure specific info */
3274 struct mips_extra_func_info
*e
=
3275 ((struct mips_extra_func_info
*)
3276 obstack_alloc (¤t_objfile
->symbol_obstack
,
3277 sizeof (struct mips_extra_func_info
)));
3278 struct symbol
*s
= new_symbol (MIPS_EFI_SYMBOL_NAME
);
3280 memset ((PTR
) e
, 0, sizeof (struct mips_extra_func_info
));
3281 SYMBOL_NAMESPACE (s
) = LABEL_NAMESPACE
;
3282 SYMBOL_CLASS (s
) = LOC_CONST
;
3283 SYMBOL_TYPE (s
) = mdebug_type_void
;
3284 SYMBOL_VALUE (s
) = (long) e
;
3285 e
->pdr
.framereg
= -1;
3286 add_symbol_to_list (s
, &local_symbols
);
3289 else if (sh
.st
== stLabel
)
3291 if (sh
.index
== indexNil
)
3293 /* This is what the gcc2_compiled and __gnu_compiled_*
3294 show up as. So don't complain. */
3299 /* Handle encoded stab line number. */
3300 valu
+= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT
);
3301 record_line (current_subfile
, sh
.index
, valu
);
3304 else if (sh
.st
== stProc
|| sh
.st
== stStaticProc
3305 || sh
.st
== stStatic
|| sh
.st
== stEnd
)
3306 /* These are generated by gcc-2.x, do not complain */
3309 complain (&stab_unknown_complaint
, name
);
3311 st
= end_symtab (pst
->texthigh
, pst
->objfile
, SECT_OFF_TEXT
);
3314 /* Sort the symbol table now, we are done adding symbols to it.
3315 We must do this before parse_procedure calls lookup_symbol. */
3316 sort_symtab_syms (st
);
3318 /* There used to be a call to sort_blocks here, but this should not
3319 be necessary for stabs symtabs. And as sort_blocks modifies the
3320 start address of the GLOBAL_BLOCK to the FIRST_LOCAL_BLOCK,
3321 it did the wrong thing if the first procedure in a file was
3322 generated via asm statements. */
3324 /* Fill in procedure info next. */
3328 struct cleanup
*old_chain
;
3334 pr_block
= (PDR
*) xmalloc (fh
->cpd
* sizeof (PDR
));
3335 old_chain
= make_cleanup (free
, pr_block
);
3337 pdr_ptr
= ((char *) debug_info
->external_pdr
3338 + fh
->ipdFirst
* external_pdr_size
);
3339 pdr_end
= pdr_ptr
+ fh
->cpd
* external_pdr_size
;
3343 pdr_ptr
+= external_pdr_size
, pdr_in
++)
3345 (*swap_pdr_in
) (cur_bfd
, pdr_ptr
, pdr_in
);
3347 /* Determine lowest PDR address, the PDRs are not always
3349 if (pdr_in
== pr_block
)
3350 lowest_pdr_addr
= pdr_in
->adr
;
3351 else if (pdr_in
->adr
< lowest_pdr_addr
)
3352 lowest_pdr_addr
= pdr_in
->adr
;
3356 pdr_in_end
= pdr_in
+ fh
->cpd
;
3357 for (; pdr_in
< pdr_in_end
; pdr_in
++)
3358 parse_procedure (pdr_in
, st
, lowest_pdr_addr
, pst
);
3360 do_cleanups (old_chain
);
3365 /* This symbol table contains ordinary ecoff entries. */
3371 /* How many symbols will we need */
3372 /* FIXME, this does not count enum values. */
3373 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
3377 st
= new_symtab ("unknown", f_max
, 0, pst
->objfile
);
3381 f_max
+= fh
->csym
+ fh
->cpd
;
3382 maxlines
= 2 * fh
->cline
;
3383 st
= new_symtab (pst
->filename
, 2 * f_max
, maxlines
, pst
->objfile
);
3385 /* The proper language was already determined when building
3386 the psymtab, use it. */
3387 st
->language
= PST_PRIVATE (pst
)->pst_language
;
3390 psymtab_language
= st
->language
;
3392 lines
= LINETABLE (st
);
3394 /* Get a new lexical context */
3396 push_parse_stack ();
3397 top_stack
->cur_st
= st
;
3398 top_stack
->cur_block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (st
),
3400 BLOCK_START (top_stack
->cur_block
) = pst
->textlow
;
3401 BLOCK_END (top_stack
->cur_block
) = 0;
3402 top_stack
->blocktype
= stFile
;
3403 top_stack
->maxsyms
= 2 * f_max
;
3404 top_stack
->cur_type
= 0;
3405 top_stack
->procadr
= 0;
3406 top_stack
->numargs
= 0;
3407 found_ecoff_debugging_info
= 0;
3414 /* Parse local symbols first */
3415 sym_ptr
= ((char *) debug_info
->external_sym
3416 + fh
->isymBase
* external_sym_size
);
3417 sym_end
= sym_ptr
+ fh
->csym
* external_sym_size
;
3418 while (sym_ptr
< sym_end
)
3423 (*swap_sym_in
) (cur_bfd
, sym_ptr
, &sh
);
3424 c
= parse_symbol (&sh
,
3425 debug_info
->external_aux
+ fh
->iauxBase
,
3426 sym_ptr
, fh
->fBigendian
, pst
->section_offsets
);
3427 sym_ptr
+= c
* external_sym_size
;
3430 /* Linenumbers. At the end, check if we can save memory.
3431 parse_lines has to look ahead an arbitrary number of PDR
3432 structures, so we swap them all first. */
3436 struct cleanup
*old_chain
;
3442 pr_block
= (PDR
*) xmalloc (fh
->cpd
* sizeof (PDR
));
3444 old_chain
= make_cleanup (free
, pr_block
);
3446 pdr_ptr
= ((char *) debug_info
->external_pdr
3447 + fh
->ipdFirst
* external_pdr_size
);
3448 pdr_end
= pdr_ptr
+ fh
->cpd
* external_pdr_size
;
3452 pdr_ptr
+= external_pdr_size
, pdr_in
++)
3454 (*swap_pdr_in
) (cur_bfd
, pdr_ptr
, pdr_in
);
3456 /* Determine lowest PDR address, the PDRs are not always
3458 if (pdr_in
== pr_block
)
3459 lowest_pdr_addr
= pdr_in
->adr
;
3460 else if (pdr_in
->adr
< lowest_pdr_addr
)
3461 lowest_pdr_addr
= pdr_in
->adr
;
3464 parse_lines (fh
, pr_block
, lines
, maxlines
, pst
, lowest_pdr_addr
);
3465 if (lines
->nitems
< fh
->cline
)
3466 lines
= shrink_linetable (lines
);
3468 /* Fill in procedure info next. */
3470 pdr_in_end
= pdr_in
+ fh
->cpd
;
3471 for (; pdr_in
< pdr_in_end
; pdr_in
++)
3472 parse_procedure (pdr_in
, 0, lowest_pdr_addr
, pst
);
3474 do_cleanups (old_chain
);
3478 LINETABLE (st
) = lines
;
3480 /* .. and our share of externals.
3481 XXX use the global list to speed up things here. how?
3482 FIXME, Maybe quit once we have found the right number of ext's? */
3483 top_stack
->cur_st
= st
;
3484 top_stack
->cur_block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack
->cur_st
),
3486 top_stack
->blocktype
= stFile
;
3488 = (debug_info
->symbolic_header
.isymMax
3489 + debug_info
->symbolic_header
.ipdMax
3490 + debug_info
->symbolic_header
.iextMax
);
3492 ext_ptr
= PST_PRIVATE (pst
)->extern_tab
;
3493 for (i
= PST_PRIVATE (pst
)->extern_count
; --i
>= 0; ext_ptr
++)
3494 parse_external (ext_ptr
, fh
->fBigendian
, pst
->section_offsets
);
3496 /* If there are undefined symbols, tell the user.
3497 The alpha has an undefined symbol for every symbol that is
3498 from a shared library, so tell the user only if verbose is on. */
3499 if (info_verbose
&& n_undef_symbols
)
3501 printf_filtered ("File %s contains %d unresolved references:",
3502 st
->filename
, n_undef_symbols
);
3503 printf_filtered ("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
3504 n_undef_vars
, n_undef_procs
, n_undef_labels
);
3505 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
3512 /* Sort the symbol table now, we are done adding symbols to it.*/
3513 sort_symtab_syms (st
);
3518 /* Now link the psymtab and the symtab. */
3521 current_objfile
= NULL
;
3524 /* Ancillary parsing procedures. */
3526 /* Return 1 if the symbol pointed to by SH has a cross reference
3527 to an opaque aggregate type, else 0. */
3530 has_opaque_xref (fh
, sh
)
3539 if (sh
->index
== indexNil
)
3542 ax
= debug_info
->external_aux
+ fh
->iauxBase
+ sh
->index
;
3543 (*debug_swap
->swap_tir_in
) (fh
->fBigendian
, &ax
->a_ti
, &tir
);
3544 if (tir
.bt
!= btStruct
&& tir
.bt
!= btUnion
&& tir
.bt
!= btEnum
)
3548 (*debug_swap
->swap_rndx_in
) (fh
->fBigendian
, &ax
->a_rndx
, rn
);
3549 if (rn
->rfd
== 0xfff)
3550 rf
= AUX_GET_ISYM (fh
->fBigendian
, ax
+ 1);
3558 /* Lookup the type at relative index RN. Return it in TPP
3559 if found and in any event come up with its name PNAME.
3560 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
3561 Return value says how many aux symbols we ate. */
3564 cross_ref (fd
, ax
, tpp
, type_code
, pname
, bigend
, sym_name
)
3568 enum type_code type_code
; /* Use to alloc new type if none is found. */
3580 struct mdebug_pending
*pend
;
3582 *tpp
= (struct type
*)NULL
;
3584 (*debug_swap
->swap_rndx_in
) (bigend
, &ax
->a_rndx
, rn
);
3586 /* Escape index means 'the next one' */
3587 if (rn
->rfd
== 0xfff)
3590 rf
= AUX_GET_ISYM (bigend
, ax
+ 1);
3597 /* mips cc uses a rf of -1 for opaque struct definitions.
3598 Set TYPE_FLAG_STUB for these types so that check_typedef will
3599 resolve them if the struct gets defined in another compilation unit. */
3602 *pname
= "<undefined>";
3603 *tpp
= init_type (type_code
, 0, 0, (char *) NULL
, current_objfile
);
3604 TYPE_FLAGS (*tpp
) |= TYPE_FLAG_STUB
;
3608 /* mips cc uses an escaped rn->index of 0 for struct return types
3609 of procedures that were compiled without -g. These will always remain
3611 if (rn
->rfd
== 0xfff && rn
->index
== 0)
3613 *pname
= "<undefined>";
3617 /* Find the relative file descriptor and the symbol in it. */
3618 fh
= get_rfd (fd
, rf
);
3619 xref_fd
= fh
- debug_info
->fdr
;
3621 if (rn
->index
>= fh
->csym
)
3623 /* File indirect entry is corrupt. */
3624 *pname
= "<illegal>";
3625 complain (&bad_rfd_entry_complaint
,
3626 sym_name
, xref_fd
, rn
->index
);
3630 /* If we have processed this symbol then we left a forwarding
3631 pointer to the type in the pending list. If not, we`ll put
3632 it in a list of pending types, to be processed later when
3633 the file will be. In any event, we collect the name for the
3636 esh
= ((char *) debug_info
->external_sym
3637 + ((fh
->isymBase
+ rn
->index
)
3638 * debug_swap
->external_sym_size
));
3639 (*debug_swap
->swap_sym_in
) (cur_bfd
, esh
, &sh
);
3641 /* Make sure that this type of cross reference can be handled. */
3642 if ((sh
.sc
!= scInfo
3643 || (sh
.st
!= stBlock
&& sh
.st
!= stTypedef
&& sh
.st
!= stIndirect
3644 && sh
.st
!= stStruct
&& sh
.st
!= stUnion
3645 && sh
.st
!= stEnum
))
3646 && (sh
.st
!= stBlock
|| (sh
.sc
!= scCommon
&& sh
.sc
!= scSCommon
)))
3648 /* File indirect entry is corrupt. */
3649 *pname
= "<illegal>";
3650 complain (&bad_rfd_entry_complaint
,
3651 sym_name
, xref_fd
, rn
->index
);
3655 *pname
= debug_info
->ss
+ fh
->issBase
+ sh
.iss
;
3657 pend
= is_pending_symbol (fh
, esh
);
3662 /* We have not yet seen this type. */
3664 if ((sh
.iss
== 0 && sh
.st
== stTypedef
) || sh
.st
== stIndirect
)
3668 /* alpha cc puts out a stTypedef with a sh.iss of zero for
3670 a) forward declarations of structs/unions/enums which are not
3671 defined in this compilation unit.
3672 For these the type will be void. This is a bad design decision
3673 as cross referencing across compilation units is impossible
3674 due to the missing name.
3675 b) forward declarations of structs/unions/enums/typedefs which
3676 are defined later in this file or in another file in the same
3677 compilation unit. Irix5 cc uses a stIndirect symbol for this.
3678 Simply cross reference those again to get the true type.
3679 The forward references are not entered in the pending list and
3680 in the symbol table. */
3682 (*debug_swap
->swap_tir_in
) (bigend
,
3683 &(debug_info
->external_aux
3684 + fh
->iauxBase
+ sh
.index
)->a_ti
,
3686 if (tir
.tq0
!= tqNil
)
3687 complain (&illegal_forward_tq0_complaint
, sym_name
);
3691 *tpp
= init_type (type_code
, 0, 0, (char *) NULL
,
3693 *pname
= "<undefined>";
3700 (debug_info
->external_aux
3701 + fh
->iauxBase
+ sh
.index
+ 1),
3702 tpp
, type_code
, pname
,
3703 fh
->fBigendian
, sym_name
);
3707 /* Follow a forward typedef. This might recursively
3708 call cross_ref till we get a non typedef'ed type.
3709 FIXME: This is not correct behaviour, but gdb currently
3710 cannot handle typedefs without type copying. Type
3711 copying is impossible as we might have mutual forward
3712 references between two files and the copied type would not
3713 get filled in when we later parse its definition. */
3714 *tpp
= parse_type (xref_fd
,
3715 debug_info
->external_aux
+ fh
->iauxBase
,
3719 debug_info
->ss
+ fh
->issBase
+ sh
.iss
);
3720 add_pending (fh
, esh
, *tpp
);
3724 complain (&illegal_forward_bt_complaint
, tir
.bt
, sym_name
);
3725 *tpp
= init_type (type_code
, 0, 0, (char *) NULL
,
3731 else if (sh
.st
== stTypedef
)
3733 /* Parse the type for a normal typedef. This might recursively call
3734 cross_ref till we get a non typedef'ed type.
3735 FIXME: This is not correct behaviour, but gdb currently
3736 cannot handle typedefs without type copying. But type copying is
3737 impossible as we might have mutual forward references between
3738 two files and the copied type would not get filled in when
3739 we later parse its definition. */
3740 *tpp
= parse_type (xref_fd
,
3741 debug_info
->external_aux
+ fh
->iauxBase
,
3745 debug_info
->ss
+ fh
->issBase
+ sh
.iss
);
3749 /* Cross reference to a struct/union/enum which is defined
3750 in another file in the same compilation unit but that file
3751 has not been parsed yet.
3752 Initialize the type only, it will be filled in when
3753 it's definition is parsed. */
3754 *tpp
= init_type (type_code
, 0, 0, (char *) NULL
, current_objfile
);
3756 add_pending (fh
, esh
, *tpp
);
3759 /* We used one auxent normally, two if we got a "next one" rf. */
3764 /* Quick&dirty lookup procedure, to avoid the MI ones that require
3765 keeping the symtab sorted */
3767 static struct symbol
*
3768 mylookup_symbol (name
, block
, namespace, class)
3770 register struct block
*block
;
3771 namespace_enum
namespace;
3772 enum address_class
class;
3774 register int bot
, top
, inc
;
3775 register struct symbol
*sym
;
3778 top
= BLOCK_NSYMS (block
);
3782 sym
= BLOCK_SYM (block
, bot
);
3783 if (SYMBOL_NAME (sym
)[0] == inc
3784 && SYMBOL_NAMESPACE (sym
) == namespace
3785 && SYMBOL_CLASS (sym
) == class
3786 && strcmp (SYMBOL_NAME (sym
), name
) == 0)
3790 block
= BLOCK_SUPERBLOCK (block
);
3792 return mylookup_symbol (name
, block
, namespace, class);
3797 /* Add a new symbol S to a block B.
3798 Infrequently, we will need to reallocate the block to make it bigger.
3799 We only detect this case when adding to top_stack->cur_block, since
3800 that's the only time we know how big the block is. FIXME. */
3807 int nsyms
= BLOCK_NSYMS (b
)++;
3808 struct block
*origb
;
3809 struct parse_stack
*stackp
;
3811 if (b
== top_stack
->cur_block
&&
3812 nsyms
>= top_stack
->maxsyms
)
3814 complain (&block_overflow_complaint
, SYMBOL_NAME (s
));
3815 /* In this case shrink_block is actually grow_block, since
3816 BLOCK_NSYMS(b) is larger than its current size. */
3818 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
3820 /* Now run through the stack replacing pointers to the
3821 original block. shrink_block has already done this
3822 for the blockvector and BLOCK_FUNCTION. */
3823 for (stackp
= top_stack
; stackp
; stackp
= stackp
->next
)
3825 if (stackp
->cur_block
== origb
)
3827 stackp
->cur_block
= b
;
3828 stackp
->maxsyms
= BLOCK_NSYMS (b
);
3832 BLOCK_SYM (b
, nsyms
) = s
;
3835 /* Add a new block B to a symtab S */
3842 struct blockvector
*bv
= BLOCKVECTOR (s
);
3844 bv
= (struct blockvector
*) xrealloc ((PTR
) bv
,
3845 (sizeof (struct blockvector
)
3846 + BLOCKVECTOR_NBLOCKS (bv
)
3847 * sizeof (bv
->block
)));
3848 if (bv
!= BLOCKVECTOR (s
))
3849 BLOCKVECTOR (s
) = bv
;
3851 BLOCKVECTOR_BLOCK (bv
, BLOCKVECTOR_NBLOCKS (bv
)++) = b
;
3854 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
3855 MIPS' linenumber encoding might need more than one byte
3856 to describe it, LAST is used to detect these continuation lines.
3858 Combining lines with the same line number seems like a bad idea.
3859 E.g: There could be a line number entry with the same line number after the
3860 prologue and GDB should not ignore it (this is a better way to find
3861 a prologue than mips_skip_prologue).
3862 But due to the compressed line table format there are line number entries
3863 for the same line which are needed to bridge the gap to the next
3864 line number entry. These entries have a bogus address info with them
3865 and we are unable to tell them from intended duplicate line number
3867 This is another reason why -ggdb debugging format is preferable. */
3870 add_line (lt
, lineno
, adr
, last
)
3871 struct linetable
*lt
;
3876 /* DEC c89 sometimes produces zero linenos which confuse gdb.
3877 Change them to something sensible. */
3881 last
= -2; /* make sure we record first line */
3883 if (last
== lineno
) /* skip continuation lines */
3886 lt
->item
[lt
->nitems
].line
= lineno
;
3887 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
3891 /* Sorting and reordering procedures */
3893 /* Blocks with a smaller low bound should come first */
3896 compare_blocks (arg1
, arg2
)
3900 register int addr_diff
;
3901 struct block
**b1
= (struct block
**) arg1
;
3902 struct block
**b2
= (struct block
**) arg2
;
3904 addr_diff
= (BLOCK_START ((*b1
))) - (BLOCK_START ((*b2
)));
3906 return (BLOCK_END ((*b2
))) - (BLOCK_END ((*b1
)));
3910 /* Sort the blocks of a symtab S.
3911 Reorder the blocks in the blockvector by code-address,
3912 as required by some MI search routines */
3918 struct blockvector
*bv
= BLOCKVECTOR (s
);
3920 if (BLOCKVECTOR_NBLOCKS (bv
) <= 2)
3923 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) == 0)
3924 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) = 0;
3925 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) == 0)
3926 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) = 0;
3930 * This is very unfortunate: normally all functions are compiled in
3931 * the order they are found, but if the file is compiled -O3 things
3932 * are very different. It would be nice to find a reliable test
3933 * to detect -O3 images in advance.
3935 if (BLOCKVECTOR_NBLOCKS (bv
) > 3)
3936 qsort (&BLOCKVECTOR_BLOCK (bv
, FIRST_LOCAL_BLOCK
),
3937 BLOCKVECTOR_NBLOCKS (bv
) - FIRST_LOCAL_BLOCK
,
3938 sizeof (struct block
*),
3942 register CORE_ADDR high
= 0;
3943 register int i
, j
= BLOCKVECTOR_NBLOCKS (bv
);
3945 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
3946 if (high
< BLOCK_END (BLOCKVECTOR_BLOCK (bv
, i
)))
3947 high
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, i
));
3948 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) = high
;
3951 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) =
3952 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, FIRST_LOCAL_BLOCK
));
3954 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) =
3955 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
3956 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) =
3957 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
3961 /* Constructor/restructor/destructor procedures */
3963 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
3964 MAXSYMS and linenumbers MAXLINES we'll put in it */
3966 static struct symtab
*
3967 new_symtab (name
, maxsyms
, maxlines
, objfile
)
3971 struct objfile
*objfile
;
3973 struct symtab
*s
= allocate_symtab (name
, objfile
);
3975 LINETABLE (s
) = new_linetable (maxlines
);
3977 /* All symtabs must have at least two blocks */
3978 BLOCKVECTOR (s
) = new_bvect (2);
3979 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
) = new_block (maxsyms
);
3980 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
) = new_block (maxsyms
);
3981 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)) =
3982 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
3984 s
->free_code
= free_linetable
;
3989 /* Allocate a new partial_symtab NAME */
3991 static struct partial_symtab
*
3992 new_psymtab (name
, objfile
, section_offsets
)
3994 struct objfile
*objfile
;
3995 struct section_offsets
*section_offsets
;
3997 struct partial_symtab
*psymtab
;
3999 psymtab
= allocate_psymtab (name
, objfile
);
4000 psymtab
->section_offsets
= section_offsets
;
4002 /* Keep a backpointer to the file's symbols */
4004 psymtab
->read_symtab_private
= ((char *)
4005 obstack_alloc (&objfile
->psymbol_obstack
,
4006 sizeof (struct symloc
)));
4007 memset ((PTR
) psymtab
->read_symtab_private
, 0, sizeof (struct symloc
));
4008 CUR_BFD (psymtab
) = cur_bfd
;
4009 DEBUG_SWAP (psymtab
) = debug_swap
;
4010 DEBUG_INFO (psymtab
) = debug_info
;
4011 PENDING_LIST (psymtab
) = pending_list
;
4013 /* The way to turn this into a symtab is to call... */
4014 psymtab
->read_symtab
= mdebug_psymtab_to_symtab
;
4019 /* Allocate a linetable array of the given SIZE. Since the struct
4020 already includes one item, we subtract one when calculating the
4021 proper size to allocate. */
4023 static struct linetable
*
4024 new_linetable (size
)
4027 struct linetable
*l
;
4029 size
= (size
- 1) * sizeof (l
->item
) + sizeof (struct linetable
);
4030 l
= (struct linetable
*) xmalloc (size
);
4035 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
4036 I am not so sure about the 3.4 ones.
4038 Since the struct linetable already includes one item, we subtract one when
4039 calculating the proper size to allocate. */
4041 static struct linetable
*
4042 shrink_linetable (lt
)
4043 struct linetable
*lt
;
4046 return (struct linetable
*) xrealloc ((PTR
) lt
,
4047 (sizeof (struct linetable
)
4049 * sizeof (lt
->item
))));
4052 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
4054 static struct blockvector
*
4058 struct blockvector
*bv
;
4061 size
= sizeof (struct blockvector
) + nblocks
* sizeof (struct block
*);
4062 bv
= (struct blockvector
*) xzalloc (size
);
4064 BLOCKVECTOR_NBLOCKS (bv
) = nblocks
;
4069 /* Allocate and zero a new block of MAXSYMS symbols */
4071 static struct block
*
4075 int size
= sizeof (struct block
) + (maxsyms
- 1) * sizeof (struct symbol
*);
4077 return (struct block
*) xzalloc (size
);
4080 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
4081 Shrink_block can also be used by add_symbol to grow a block. */
4083 static struct block
*
4089 struct blockvector
*bv
= BLOCKVECTOR (s
);
4092 /* Just reallocate it and fix references to the old one */
4094 new = (struct block
*) xrealloc ((PTR
) b
,
4095 (sizeof (struct block
)
4096 + ((BLOCK_NSYMS (b
) - 1)
4097 * sizeof (struct symbol
*))));
4099 /* Should chase pointers to old one. Fortunately, that`s just
4100 the block`s function and inferior blocks */
4101 if (BLOCK_FUNCTION (new) && SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) == b
)
4102 SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) = new;
4103 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS (bv
); i
++)
4104 if (BLOCKVECTOR_BLOCK (bv
, i
) == b
)
4105 BLOCKVECTOR_BLOCK (bv
, i
) = new;
4106 else if (BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv
, i
)) == b
)
4107 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv
, i
)) = new;
4111 /* Create a new symbol with printname NAME */
4113 static struct symbol
*
4117 struct symbol
*s
= ((struct symbol
*)
4118 obstack_alloc (¤t_objfile
->symbol_obstack
,
4119 sizeof (struct symbol
)));
4121 memset ((PTR
) s
, 0, sizeof (*s
));
4122 SYMBOL_NAME (s
) = obsavestring (name
, strlen (name
),
4123 ¤t_objfile
->symbol_obstack
);
4124 SYMBOL_LANGUAGE (s
) = psymtab_language
;
4125 SYMBOL_INIT_DEMANGLED_NAME (s
, ¤t_objfile
->symbol_obstack
);
4129 /* Create a new type with printname NAME */
4131 static struct type
*
4137 t
= alloc_type (current_objfile
);
4138 TYPE_NAME (t
) = name
;
4139 TYPE_CPLUS_SPECIFIC (t
) = (struct cplus_struct_type
*) &cplus_struct_default
;
4143 /* Read ECOFF debugging information from a BFD section. This is
4144 called from elfread.c. It parses the section into a
4145 ecoff_debug_info struct, and then lets the rest of the file handle
4149 elfmdebug_build_psymtabs (objfile
, swap
, sec
, section_offsets
)
4150 struct objfile
*objfile
;
4151 const struct ecoff_debug_swap
*swap
;
4153 struct section_offsets
*section_offsets
;
4155 bfd
*abfd
= objfile
->obfd
;
4156 struct ecoff_debug_info
*info
;
4158 info
= ((struct ecoff_debug_info
*)
4159 obstack_alloc (&objfile
->psymbol_obstack
,
4160 sizeof (struct ecoff_debug_info
)));
4162 if (!(*swap
->read_debug_info
) (abfd
, sec
, info
))
4163 error ("Error reading ECOFF debugging information: %s",
4164 bfd_errmsg (bfd_get_error ()));
4166 mdebug_build_psymtabs (objfile
, swap
, info
, section_offsets
);
4170 /* Things used for calling functions in the inferior.
4171 These functions are exported to our companion
4172 mips-tdep.c file and are here because they play
4173 with the symbol-table explicitly. */
4175 /* Sigtramp: make sure we have all the necessary information
4176 about the signal trampoline code. Since the official code
4177 from MIPS does not do so, we make up that information ourselves.
4178 If they fix the library (unlikely) this code will neutralize itself. */
4180 /* FIXME: This function is called only by mips-tdep.c. It needs to be
4181 here because it calls functions defined in this file, but perhaps
4182 this could be handled in a better way. */
4189 struct block
*b
, *b0
= NULL
;
4191 sigtramp_address
= -1;
4193 /* We have to handle the following cases here:
4194 a) The Mips library has a sigtramp label within sigvec.
4195 b) Irix has a _sigtramp which we want to use, but it also has sigvec. */
4196 s
= lookup_symbol ("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
4199 b0
= SYMBOL_BLOCK_VALUE (s
);
4200 s
= lookup_symbol ("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
4204 /* No sigvec or no sigtramp inside sigvec, try _sigtramp. */
4205 s
= lookup_symbol ("_sigtramp", 0, VAR_NAMESPACE
, 0, NULL
);
4208 /* But maybe this program uses its own version of sigvec */
4212 /* Did we or MIPSco fix the library ? */
4213 if (SYMBOL_CLASS (s
) == LOC_BLOCK
)
4215 sigtramp_address
= BLOCK_START (SYMBOL_BLOCK_VALUE (s
));
4216 sigtramp_end
= BLOCK_END (SYMBOL_BLOCK_VALUE (s
));
4220 sigtramp_address
= SYMBOL_VALUE (s
);
4221 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
4223 /* But what symtab does it live in ? */
4224 st
= find_pc_symtab (SYMBOL_VALUE (s
));
4227 * Ok, there goes the fix: turn it into a procedure, with all the
4228 * needed info. Note we make it a nested procedure of sigvec,
4229 * which is the way the (assembly) code is actually written.
4231 SYMBOL_NAMESPACE (s
) = VAR_NAMESPACE
;
4232 SYMBOL_CLASS (s
) = LOC_BLOCK
;
4233 SYMBOL_TYPE (s
) = init_type (TYPE_CODE_FUNC
, 4, 0, (char *) NULL
,
4235 TYPE_TARGET_TYPE (SYMBOL_TYPE (s
)) = mdebug_type_void
;
4237 /* Need a block to allocate MIPS_EFI_SYMBOL_NAME in */
4239 SYMBOL_BLOCK_VALUE (s
) = b
;
4240 BLOCK_START (b
) = sigtramp_address
;
4241 BLOCK_END (b
) = sigtramp_end
;
4242 BLOCK_FUNCTION (b
) = s
;
4243 BLOCK_SUPERBLOCK (b
) = BLOCK_SUPERBLOCK (b0
);
4247 /* Make a MIPS_EFI_SYMBOL_NAME entry for it */
4249 struct mips_extra_func_info
*e
=
4250 ((struct mips_extra_func_info
*)
4251 xzalloc (sizeof (struct mips_extra_func_info
)));
4253 e
->numargs
= 0; /* the kernel thinks otherwise */
4254 e
->pdr
.frameoffset
= 32;
4255 e
->pdr
.framereg
= SP_REGNUM
;
4256 /* Note that setting pcreg is no longer strictly necessary as
4257 mips_frame_saved_pc is now aware of signal handler frames. */
4258 e
->pdr
.pcreg
= PC_REGNUM
;
4259 e
->pdr
.regmask
= -2;
4260 /* Offset to saved r31, in the sigtramp case the saved registers
4261 are above the frame in the sigcontext.
4262 We have 4 alignment bytes, 12 bytes for onstack, mask and pc,
4263 32 * 4 bytes for the general registers, 12 bytes for mdhi, mdlo, ownedfp
4264 and 32 * 4 bytes for the floating point registers. */
4265 e
->pdr
.regoffset
= 4 + 12 + 31 * 4;
4266 e
->pdr
.fregmask
= -1;
4267 /* Offset to saved f30 (first saved *double* register). */
4268 e
->pdr
.fregoffset
= 4 + 12 + 32 * 4 + 12 + 30 * 4;
4269 e
->pdr
.isym
= (long) s
;
4270 e
->pdr
.adr
= sigtramp_address
;
4272 current_objfile
= st
->objfile
; /* Keep new_symbol happy */
4273 s
= new_symbol (MIPS_EFI_SYMBOL_NAME
);
4274 SYMBOL_VALUE (s
) = (long) e
;
4275 SYMBOL_NAMESPACE (s
) = LABEL_NAMESPACE
;
4276 SYMBOL_CLASS (s
) = LOC_CONST
;
4277 SYMBOL_TYPE (s
) = mdebug_type_void
;
4278 current_objfile
= NULL
;
4281 BLOCK_SYM (b
, BLOCK_NSYMS (b
)++) = s
;
4285 _initialize_mdebugread ()
4288 init_type (TYPE_CODE_VOID
, 1,
4290 "void", (struct objfile
*) NULL
);
4292 init_type (TYPE_CODE_INT
, 1,
4294 "char", (struct objfile
*) NULL
);
4295 mdebug_type_unsigned_char
=
4296 init_type (TYPE_CODE_INT
, 1,
4298 "unsigned char", (struct objfile
*) NULL
);
4300 init_type (TYPE_CODE_INT
, 2,
4302 "short", (struct objfile
*) NULL
);
4303 mdebug_type_unsigned_short
=
4304 init_type (TYPE_CODE_INT
, 2,
4306 "unsigned short", (struct objfile
*) NULL
);
4307 mdebug_type_int_32
=
4308 init_type (TYPE_CODE_INT
, 4,
4310 "int", (struct objfile
*) NULL
);
4311 mdebug_type_unsigned_int_32
=
4312 init_type (TYPE_CODE_INT
, 4,
4314 "unsigned int", (struct objfile
*) NULL
);
4315 mdebug_type_int_64
=
4316 init_type (TYPE_CODE_INT
, 8,
4318 "int", (struct objfile
*) NULL
);
4319 mdebug_type_unsigned_int_64
=
4320 init_type (TYPE_CODE_INT
, 8,
4322 "unsigned int", (struct objfile
*) NULL
);
4323 mdebug_type_long_32
=
4324 init_type (TYPE_CODE_INT
, 4,
4326 "long", (struct objfile
*) NULL
);
4327 mdebug_type_unsigned_long_32
=
4328 init_type (TYPE_CODE_INT
, 4,
4330 "unsigned long", (struct objfile
*) NULL
);
4331 mdebug_type_long_64
=
4332 init_type (TYPE_CODE_INT
, 8,
4334 "long", (struct objfile
*) NULL
);
4335 mdebug_type_unsigned_long_64
=
4336 init_type (TYPE_CODE_INT
, 8,
4338 "unsigned long", (struct objfile
*) NULL
);
4339 mdebug_type_long_long_64
=
4340 init_type (TYPE_CODE_INT
, 8,
4342 "long long", (struct objfile
*) NULL
);
4343 mdebug_type_unsigned_long_long_64
=
4344 init_type (TYPE_CODE_INT
, 8,
4346 "unsigned long long", (struct objfile
*) NULL
);
4347 mdebug_type_adr_32
=
4348 init_type (TYPE_CODE_PTR
, 4,
4350 "adr_32", (struct objfile
*) NULL
);
4351 TYPE_TARGET_TYPE (mdebug_type_adr_32
) = mdebug_type_void
;
4352 mdebug_type_adr_64
=
4353 init_type (TYPE_CODE_PTR
, 8,
4355 "adr_64", (struct objfile
*) NULL
);
4356 TYPE_TARGET_TYPE (mdebug_type_adr_64
) = mdebug_type_void
;
4358 init_type (TYPE_CODE_FLT
, TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
4360 "float", (struct objfile
*) NULL
);
4361 mdebug_type_double
=
4362 init_type (TYPE_CODE_FLT
, TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
4364 "double", (struct objfile
*) NULL
);
4365 mdebug_type_complex
=
4366 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
,
4368 "complex", (struct objfile
*) NULL
);
4369 TYPE_TARGET_TYPE (mdebug_type_complex
) = mdebug_type_float
;
4370 mdebug_type_double_complex
=
4371 init_type (TYPE_CODE_COMPLEX
, 2 * TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
4373 "double complex", (struct objfile
*) NULL
);
4374 TYPE_TARGET_TYPE (mdebug_type_double_complex
) = mdebug_type_double
;
4376 /* Is a "string" the way btString means it the same as TYPE_CODE_STRING?
4378 mdebug_type_string
=
4379 init_type (TYPE_CODE_STRING
,
4380 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
4382 (struct objfile
*) NULL
);
4384 /* We use TYPE_CODE_INT to print these as integers. Does this do any
4385 good? Would we be better off with TYPE_CODE_ERROR? Should
4386 TYPE_CODE_ERROR print things in hex if it knows the size? */
4387 mdebug_type_fixed_dec
=
4388 init_type (TYPE_CODE_INT
,
4389 TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4391 (struct objfile
*) NULL
);
4393 mdebug_type_float_dec
=
4394 init_type (TYPE_CODE_ERROR
,
4395 TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
,
4396 0, "floating decimal",
4397 (struct objfile
*) NULL
);
4399 nodebug_func_symbol_type
= init_type (TYPE_CODE_FUNC
, 1, 0,
4400 "<function, no debug info>", NULL
);
4401 TYPE_TARGET_TYPE (nodebug_func_symbol_type
) = mdebug_type_int
;
4402 nodebug_var_symbol_type
=
4403 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ HOST_CHAR_BIT
, 0,
4404 "<variable, no debug info>", NULL
);