1 /* Read a symbol table in ECOFF format (Third-Eye).
2 Copyright 1986, 87, 89, 90, 91, 92, 93, 94, 95, 96, 97, 1998
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,
23 Boston, MA 02111-1307, USA. */
25 /* This module provides the function mdebug_build_psymtabs. It reads
26 ECOFF debugging information into partial symbol tables. The
27 debugging information is read from two structures. A struct
28 ecoff_debug_swap includes the sizes of each ECOFF structure and
29 swapping routines; these are fixed for a particular target. A
30 struct ecoff_debug_info points to the debugging information for a
31 particular object file.
33 ECOFF symbol tables are mostly written in the byte order of the
34 target machine. However, one section of the table (the auxiliary
35 symbol information) is written in the host byte order. There is a
36 bit in the other symbol info which describes which host byte order
37 was used. ECOFF thereby takes the trophy from Intel `b.out' for
38 the most brain-dead adaptation of a file format to byte order.
40 This module can read all four of the known byte-order combinations,
41 on any type of host. */
51 #include "stabsread.h"
52 #include "complaints.h"
55 /* These are needed if the tm.h file does not contain the necessary
56 mips specific definitions. */
58 #ifndef MIPS_EFI_SYMBOL_NAME
59 #define MIPS_EFI_SYMBOL_NAME "__GDB_EFI_INFO__"
60 extern void ecoff_relocate_efi (struct symbol *, CORE_ADDR);
62 #include "coff/symconst.h"
63 typedef struct mips_extra_func_info
68 *mips_extra_func_info_t;
75 #include <sys/types.h>
79 #include "gdb_string.h"
81 #include "gdb-stabs.h"
85 #include "coff/ecoff.h" /* COFF-like aspects of ecoff files */
87 #include "libaout.h" /* Private BFD a.out information. */
88 #include "aout/aout64.h"
89 #include "aout/stab_gnu.h" /* STABS information */
91 #include "expression.h"
92 #include "language.h" /* Needed inside partial-stab.h */
94 extern void _initialize_mdebugread (void);
96 /* Provide a way to test if we have both ECOFF and ELF symbol tables.
97 We use this define in order to know whether we should override a
98 symbol's ECOFF section with its ELF section. This is necessary in
99 case the symbol's ELF section could not be represented in ECOFF. */
100 #define ECOFF_IN_ELF(bfd) (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
101 && bfd_get_section_by_name (bfd, ".mdebug") != NULL)
104 /* We put a pointer to this structure in the read_symtab_private field
109 /* Index of the FDR that this psymtab represents. */
111 /* The BFD that the psymtab was created from. */
113 const struct ecoff_debug_swap *debug_swap;
114 struct ecoff_debug_info *debug_info;
115 struct mdebug_pending **pending_list;
116 /* Pointer to external symbols for this file. */
118 /* Size of extern_tab. */
120 enum language pst_language;
123 #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
124 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
125 #define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd)
126 #define DEBUG_SWAP(p) (PST_PRIVATE(p)->debug_swap)
127 #define DEBUG_INFO(p) (PST_PRIVATE(p)->debug_info)
128 #define PENDING_LIST(p) (PST_PRIVATE(p)->pending_list)
130 #define SC_IS_TEXT(sc) ((sc) == scText \
131 || (sc) == scRConst \
134 #define SC_IS_DATA(sc) ((sc) == scData \
139 #define SC_IS_COMMON(sc) ((sc) == scCommon || (sc) == scSCommon)
140 #define SC_IS_BSS(sc) ((sc) == scBss || (sc) == scSBss)
141 #define SC_IS_UNDEF(sc) ((sc) == scUndefined || (sc) == scSUndefined)
144 /* Things we import explicitly from other modules */
146 extern int info_verbose;
148 /* Various complaints about symbol reading that don't abort the process */
150 static struct complaint bad_file_number_complaint =
151 {"bad file number %d", 0, 0};
153 static struct complaint index_complaint =
154 {"bad aux index at symbol %s", 0, 0};
156 static struct complaint aux_index_complaint =
157 {"bad proc end in aux found from symbol %s", 0, 0};
159 static struct complaint block_index_complaint =
160 {"bad aux index at block symbol %s", 0, 0};
162 static struct complaint unknown_ext_complaint =
163 {"unknown external symbol %s", 0, 0};
165 static struct complaint unknown_sym_complaint =
166 {"unknown local symbol %s", 0, 0};
168 static struct complaint unknown_st_complaint =
169 {"with type %d", 0, 0};
171 static struct complaint block_overflow_complaint =
172 {"block containing %s overfilled", 0, 0};
174 static struct complaint basic_type_complaint =
175 {"cannot map ECOFF basic type 0x%x for %s", 0, 0};
177 static struct complaint unknown_type_qual_complaint =
178 {"unknown type qualifier 0x%x", 0, 0};
180 static struct complaint array_index_type_complaint =
181 {"illegal array index type for %s, assuming int", 0, 0};
183 static struct complaint bad_tag_guess_complaint =
184 {"guessed tag type of %s incorrectly", 0, 0};
186 static struct complaint block_member_complaint =
187 {"declaration block contains unhandled symbol type %d", 0, 0};
189 static struct complaint stEnd_complaint =
190 {"stEnd with storage class %d not handled", 0, 0};
192 static struct complaint unknown_mdebug_symtype_complaint =
193 {"unknown symbol type 0x%x", 0, 0};
195 static struct complaint stab_unknown_complaint =
196 {"unknown stabs symbol %s", 0, 0};
198 static struct complaint pdr_for_nonsymbol_complaint =
199 {"PDR for %s, but no symbol", 0, 0};
201 static struct complaint pdr_static_symbol_complaint =
202 {"can't handle PDR for static proc at 0x%lx", 0, 0};
204 static struct complaint bad_setjmp_pdr_complaint =
205 {"fixing bad setjmp PDR from libc", 0, 0};
207 static struct complaint bad_fbitfield_complaint =
208 {"can't handle TIR fBitfield for %s", 0, 0};
210 static struct complaint bad_continued_complaint =
211 {"illegal TIR continued for %s", 0, 0};
213 static struct complaint bad_rfd_entry_complaint =
214 {"bad rfd entry for %s: file %d, index %d", 0, 0};
216 static struct complaint unexpected_type_code_complaint =
217 {"unexpected type code for %s", 0, 0};
219 static struct complaint unable_to_cross_ref_complaint =
220 {"unable to cross ref btTypedef for %s", 0, 0};
222 static struct complaint bad_indirect_xref_complaint =
223 {"unable to cross ref btIndirect for %s", 0, 0};
225 static struct complaint illegal_forward_tq0_complaint =
226 {"illegal tq0 in forward typedef for %s", 0, 0};
228 static struct complaint illegal_forward_bt_complaint =
229 {"illegal bt %d in forward typedef for %s", 0, 0};
231 static struct complaint bad_linetable_guess_complaint =
232 {"guessed size of linetable for %s incorrectly", 0, 0};
234 static struct complaint bad_ext_ifd_complaint =
235 {"bad ifd for external symbol: %d (max %d)", 0, 0};
237 static struct complaint bad_ext_iss_complaint =
238 {"bad iss for external symbol: %ld (max %ld)", 0, 0};
240 /* Macros and extra defs */
242 /* Puns: hard to find whether -g was used and how */
244 #define MIN_GLEVEL GLEVEL_0
245 #define compare_glevel(a,b) \
246 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
247 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
249 /* Things that really are local to this module */
251 /* Remember what we deduced to be the source language of this psymtab. */
253 static enum language psymtab_language = language_unknown;
259 /* How to parse debugging information for CUR_BFD. */
261 static const struct ecoff_debug_swap *debug_swap;
263 /* Pointers to debugging information for CUR_BFD. */
265 static struct ecoff_debug_info *debug_info;
267 /* Pointer to current file decriptor record, and its index */
272 /* Index of current symbol */
276 /* Note how much "debuggable" this image is. We would like
277 to see at least one FDR with full symbols */
279 static int max_gdbinfo;
280 static int max_glevel;
282 /* When examining .o files, report on undefined symbols */
284 static int n_undef_symbols, n_undef_labels, n_undef_vars, n_undef_procs;
286 /* Pseudo symbol to use when putting stabs into the symbol table. */
288 static char stabs_symbol[] = STABS_SYMBOL;
290 /* Types corresponding to mdebug format bt* basic types. */
292 static struct type *mdebug_type_void;
293 static struct type *mdebug_type_char;
294 static struct type *mdebug_type_short;
295 static struct type *mdebug_type_int_32;
296 #define mdebug_type_int mdebug_type_int_32
297 static struct type *mdebug_type_int_64;
298 static struct type *mdebug_type_long_32;
299 static struct type *mdebug_type_long_64;
300 static struct type *mdebug_type_long_long_64;
301 static struct type *mdebug_type_unsigned_char;
302 static struct type *mdebug_type_unsigned_short;
303 static struct type *mdebug_type_unsigned_int_32;
304 static struct type *mdebug_type_unsigned_int_64;
305 static struct type *mdebug_type_unsigned_long_32;
306 static struct type *mdebug_type_unsigned_long_64;
307 static struct type *mdebug_type_unsigned_long_long_64;
308 static struct type *mdebug_type_adr_32;
309 static struct type *mdebug_type_adr_64;
310 static struct type *mdebug_type_float;
311 static struct type *mdebug_type_double;
312 static struct type *mdebug_type_complex;
313 static struct type *mdebug_type_double_complex;
314 static struct type *mdebug_type_fixed_dec;
315 static struct type *mdebug_type_float_dec;
316 static struct type *mdebug_type_string;
318 /* Types for symbols from files compiled without debugging info. */
320 static struct type *nodebug_func_symbol_type;
321 static struct type *nodebug_var_symbol_type;
323 /* Nonzero if we have seen ecoff debugging info for a file. */
325 static int found_ecoff_debugging_info;
327 /* Forward declarations */
329 static void add_pending (FDR *, char *, struct type *);
331 static struct mdebug_pending *is_pending_symbol (FDR *, char *);
333 static void pop_parse_stack (void);
335 static void push_parse_stack (void);
337 static char *fdr_name (FDR *);
339 static void mdebug_psymtab_to_symtab (struct partial_symtab *);
342 upgrade_type (int, struct type **, int, union aux_ext *, int, char *);
344 static void parse_partial_symbols (struct objfile *);
346 static FDR * get_rfd (int, int);
348 static int has_opaque_xref (FDR *, SYMR *);
351 cross_ref (int, union aux_ext *, struct type **, enum type_code,
352 char **, int, char *);
354 static struct symbol *new_symbol (char *);
356 static struct type *new_type (char *);
358 static struct block *new_block (int);
360 static struct symtab *new_symtab (char *, int, int, struct objfile *);
362 static struct linetable *new_linetable (int);
364 static struct blockvector *new_bvect (int);
367 parse_symbol (SYMR *, union aux_ext *, char *, int, struct section_offsets *,
370 static struct type *parse_type (int, union aux_ext *, unsigned int, int *,
373 static struct symbol *mylookup_symbol (char *, struct block *, namespace_enum,
376 static struct block *shrink_block (struct block *, struct symtab *);
378 static PTR xzalloc (unsigned int);
380 static void sort_blocks (struct symtab *);
382 static int compare_blocks (const void *, const void *);
384 static struct partial_symtab *new_psymtab (char *, struct objfile *);
386 static void psymtab_to_symtab_1 (struct partial_symtab *, char *);
388 static void add_block (struct block *, struct symtab *);
390 static void add_symbol (struct symbol *, struct block *);
392 static int add_line (struct linetable *, int, CORE_ADDR, int);
394 static struct linetable *shrink_linetable (struct linetable *);
397 handle_psymbol_enumerators (struct objfile *, FDR *, int, CORE_ADDR);
399 static char *mdebug_next_symbol_text (struct objfile *);
401 /* Address bounds for the signal trampoline in inferior, if any */
403 CORE_ADDR sigtramp_address, sigtramp_end;
405 /* Allocate zeroed memory */
408 xzalloc (unsigned int size)
410 PTR p = xmalloc (size);
416 /* Exported procedure: Builds a symtab from the PST partial one.
417 Restores the environment in effect when PST was created, delegates
418 most of the work to an ancillary procedure, and sorts
419 and reorders the symtab list at the end */
422 mdebug_psymtab_to_symtab (struct partial_symtab *pst)
430 printf_filtered ("Reading in symbols for %s...", pst->filename);
431 gdb_flush (gdb_stdout);
434 next_symbol_text_func = mdebug_next_symbol_text;
436 psymtab_to_symtab_1 (pst, pst->filename);
438 /* Match with global symbols. This only needs to be done once,
439 after all of the symtabs and dependencies have been read in. */
440 scan_file_globals (pst->objfile);
443 printf_filtered ("done.\n");
446 /* File-level interface functions */
448 /* Find a file descriptor given its index RF relative to a file CF */
451 get_rfd (int cf, int rf)
457 fdrs = debug_info->fdr;
459 /* Object files do not have the RFD table, all refs are absolute */
462 (*debug_swap->swap_rfd_in) (cur_bfd,
463 ((char *) debug_info->external_rfd
465 * debug_swap->external_rfd_size)),
470 /* Return a safer print NAME for a file descriptor */
476 return "<stripped file>";
479 return debug_info->ss + f->issBase + f->rss;
483 /* Read in and parse the symtab of the file OBJFILE. Symbols from
484 different sections are relocated via the SECTION_OFFSETS. */
487 mdebug_build_psymtabs (struct objfile *objfile,
488 const struct ecoff_debug_swap *swap,
489 struct ecoff_debug_info *info)
491 cur_bfd = objfile->obfd;
495 /* Make sure all the FDR information is swapped in. */
496 if (info->fdr == (FDR *) NULL)
502 info->fdr = (FDR *) obstack_alloc (&objfile->psymbol_obstack,
503 (info->symbolic_header.ifdMax
505 fdr_src = info->external_fdr;
507 + info->symbolic_header.ifdMax * swap->external_fdr_size);
509 for (; fdr_src < fdr_end; fdr_src += swap->external_fdr_size, fdr_ptr++)
510 (*swap->swap_fdr_in) (objfile->obfd, fdr_src, fdr_ptr);
513 parse_partial_symbols (objfile);
516 /* Check to make sure file was compiled with -g. If not, warn the
517 user of this limitation. */
518 if (compare_glevel (max_glevel, GLEVEL_2) < 0)
520 if (max_gdbinfo == 0)
521 printf_unfiltered ("\n%s not compiled with -g, debugging support is limited.\n",
523 printf_unfiltered ("You should compile with -g2 or -g3 for best debugging support.\n");
524 gdb_flush (gdb_stdout);
529 /* Local utilities */
531 /* Map of FDR indexes to partial symtabs */
535 struct partial_symtab *pst; /* the psymtab proper */
536 long n_globals; /* exported globals (external symbols) */
537 long globals_offset; /* cumulative */
541 /* Utility stack, used to nest procedures and blocks properly.
542 It is a doubly linked list, to avoid too many alloc/free.
543 Since we might need it quite a few times it is NOT deallocated
546 static struct parse_stack
548 struct parse_stack *next, *prev;
549 struct symtab *cur_st; /* Current symtab. */
550 struct block *cur_block; /* Block in it. */
552 /* What are we parsing. stFile, or stBlock are for files and
553 blocks. stProc or stStaticProc means we have seen the start of a
554 procedure, but not the start of the block within in. When we see
555 the start of that block, we change it to stNil, without pushing a
556 new block, i.e. stNil means both a procedure and a block. */
560 int maxsyms; /* Max symbols in this block. */
561 struct type *cur_type; /* Type we parse fields for. */
562 int cur_field; /* Field number in cur_type. */
563 CORE_ADDR procadr; /* Start addres of this procedure */
564 int numargs; /* Its argument count */
567 *top_stack; /* Top stack ptr */
570 /* Enter a new lexical context */
573 push_parse_stack (void)
575 struct parse_stack *new;
577 /* Reuse frames if possible */
578 if (top_stack && top_stack->prev)
579 new = top_stack->prev;
581 new = (struct parse_stack *) xzalloc (sizeof (struct parse_stack));
582 /* Initialize new frame with previous content */
585 register struct parse_stack *prev = new->prev;
588 top_stack->prev = new;
590 new->next = top_stack;
595 /* Exit a lexical context */
598 pop_parse_stack (void)
603 top_stack = top_stack->next;
607 /* Cross-references might be to things we haven't looked at
608 yet, e.g. type references. To avoid too many type
609 duplications we keep a quick fixup table, an array
610 of lists of references indexed by file descriptor */
612 struct mdebug_pending
614 struct mdebug_pending *next; /* link */
615 char *s; /* the unswapped symbol */
616 struct type *t; /* its partial type descriptor */
620 /* The pending information is kept for an entire object file, and used
621 to be in the sym_private field. I took it out when I split
622 mdebugread from mipsread, because this might not be the only type
623 of symbols read from an object file. Instead, we allocate the
624 pending information table when we create the partial symbols, and
625 we store a pointer to the single table in each psymtab. */
627 static struct mdebug_pending **pending_list;
629 /* Check whether we already saw symbol SH in file FH */
631 static struct mdebug_pending *
632 is_pending_symbol (FDR *fh, char *sh)
634 int f_idx = fh - debug_info->fdr;
635 register struct mdebug_pending *p;
637 /* Linear search is ok, list is typically no more than 10 deep */
638 for (p = pending_list[f_idx]; p; p = p->next)
644 /* Add a new symbol SH of type T */
647 add_pending (FDR *fh, char *sh, struct type *t)
649 int f_idx = fh - debug_info->fdr;
650 struct mdebug_pending *p = is_pending_symbol (fh, sh);
652 /* Make sure we do not make duplicates */
655 p = ((struct mdebug_pending *)
656 obstack_alloc (¤t_objfile->psymbol_obstack,
657 sizeof (struct mdebug_pending)));
660 p->next = pending_list[f_idx];
661 pending_list[f_idx] = p;
666 /* Parsing Routines proper. */
668 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
669 For blocks, procedures and types we open a new lexical context.
670 This is basically just a big switch on the symbol's type. Argument
671 AX is the base pointer of aux symbols for this file (fh->iauxBase).
672 EXT_SH points to the unswapped symbol, which is needed for struct,
673 union, etc., types; it is NULL for an EXTR. BIGEND says whether
674 aux symbols are big-endian or little-endian. Return count of
675 SYMR's handled (normally one). */
678 parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
679 struct section_offsets *section_offsets, struct objfile *objfile)
681 const bfd_size_type external_sym_size = debug_swap->external_sym_size;
682 void (*const swap_sym_in) (bfd *, PTR, SYMR *) = debug_swap->swap_sym_in;
686 struct mdebug_pending *pend;
690 enum address_class class;
692 long svalue = sh->value;
695 if (ext_sh == (char *) NULL)
696 name = debug_info->ssext + sh->iss;
698 name = debug_info->ss + cur_fdr->issBase + sh->iss;
704 /* Do not relocate relative values.
705 The value of a stEnd symbol is the displacement from the
706 corresponding start symbol value.
707 The value of a stBlock symbol is the displacement from the
708 procedure address. */
709 if (sh->st != stEnd && sh->st != stBlock)
710 sh->value += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
717 sh->value += ANOFFSET (section_offsets, SECT_OFF_DATA (objfile));
721 sh->value += ANOFFSET (section_offsets, SECT_OFF_BSS (objfile));
730 case stGlobal: /* external symbol, goes into global block */
732 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
734 s = new_symbol (name);
735 SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
738 case stStatic: /* static data, goes into current block. */
740 b = top_stack->cur_block;
741 s = new_symbol (name);
742 if (SC_IS_COMMON (sh->sc))
744 /* It is a FORTRAN common block. At least for SGI Fortran the
745 address is not in the symbol; we need to fix it later in
746 scan_file_globals. */
747 int bucket = hashname (SYMBOL_NAME (s));
748 SYMBOL_VALUE_CHAIN (s) = global_sym_chain[bucket];
749 global_sym_chain[bucket] = s;
752 SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
755 case stLocal: /* local variable, goes into current block */
756 if (sh->sc == scRegister)
758 class = LOC_REGISTER;
759 svalue = ECOFF_REG_TO_REGNUM (svalue);
763 b = top_stack->cur_block;
764 s = new_symbol (name);
765 SYMBOL_VALUE (s) = svalue;
767 data: /* Common code for symbols describing data */
768 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
769 SYMBOL_CLASS (s) = class;
772 /* Type could be missing if file is compiled without debugging info. */
773 if (SC_IS_UNDEF (sh->sc)
774 || sh->sc == scNil || sh->index == indexNil)
775 SYMBOL_TYPE (s) = nodebug_var_symbol_type;
777 SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name);
778 /* Value of a data symbol is its memory address */
781 case stParam: /* arg to procedure, goes into current block */
783 found_ecoff_debugging_info = 1;
784 top_stack->numargs++;
786 /* Special GNU C++ name. */
787 if (is_cplus_marker (name[0]) && name[1] == 't' && name[2] == 0)
788 name = "this"; /* FIXME, not alloc'd in obstack */
789 s = new_symbol (name);
791 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
795 /* Pass by value in register. */
796 SYMBOL_CLASS (s) = LOC_REGPARM;
797 svalue = ECOFF_REG_TO_REGNUM (svalue);
800 /* Pass by reference on stack. */
801 SYMBOL_CLASS (s) = LOC_REF_ARG;
804 /* Pass by reference in register. */
805 SYMBOL_CLASS (s) = LOC_REGPARM_ADDR;
806 svalue = ECOFF_REG_TO_REGNUM (svalue);
809 /* Pass by value on stack. */
810 SYMBOL_CLASS (s) = LOC_ARG;
813 SYMBOL_VALUE (s) = svalue;
814 SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name);
815 add_symbol (s, top_stack->cur_block);
818 case stLabel: /* label, goes into current block */
819 s = new_symbol (name);
820 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE; /* so that it can be used */
821 SYMBOL_CLASS (s) = LOC_LABEL; /* but not misused */
822 SYMBOL_VALUE_ADDRESS (s) = (CORE_ADDR) sh->value;
823 SYMBOL_TYPE (s) = mdebug_type_int;
824 add_symbol (s, top_stack->cur_block);
827 case stProc: /* Procedure, usually goes into global block */
828 case stStaticProc: /* Static procedure, goes into current block */
829 s = new_symbol (name);
830 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
831 SYMBOL_CLASS (s) = LOC_BLOCK;
832 /* Type of the return value */
833 if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil)
837 t = parse_type (cur_fd, ax, sh->index + 1, 0, bigend, name);
838 if (STREQ (name, "malloc") && t->code == TYPE_CODE_VOID)
840 /* I don't know why, but, at least under Alpha GNU/Linux,
841 when linking against a malloc without debugging
842 symbols, its read as a function returning void---this
843 is bad because it means we cannot call functions with
844 string arguments interactively; i.e., "call
845 printf("howdy\n")" would fail with the error message
846 "program has no memory available". To avoid this, we
847 patch up the type and make it void*
848 instead. (davidm@azstarnet.com)
850 t = make_pointer_type (t, NULL);
853 b = top_stack->cur_block;
854 if (sh->st == stProc)
856 struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
857 /* The next test should normally be true, but provides a
858 hook for nested functions (which we don't want to make
860 if (b == BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK))
861 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
862 /* Irix 5 sometimes has duplicate names for the same
863 function. We want to add such names up at the global
864 level, not as a nested function. */
865 else if (sh->value == top_stack->procadr)
866 b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
870 /* Make a type for the procedure itself */
871 SYMBOL_TYPE (s) = lookup_function_type (t);
873 /* Create and enter a new lexical context */
874 b = new_block (top_stack->maxsyms);
875 SYMBOL_BLOCK_VALUE (s) = b;
876 BLOCK_FUNCTION (b) = s;
877 BLOCK_START (b) = BLOCK_END (b) = sh->value;
878 BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
879 add_block (b, top_stack->cur_st);
881 /* Not if we only have partial info */
882 if (SC_IS_UNDEF (sh->sc) || sh->sc == scNil)
886 top_stack->cur_block = b;
887 top_stack->blocktype = sh->st;
888 top_stack->cur_type = SYMBOL_TYPE (s);
889 top_stack->cur_field = -1;
890 top_stack->procadr = sh->value;
891 top_stack->numargs = 0;
894 /* Beginning of code for structure, union, and enum definitions.
895 They all share a common set of local variables, defined here. */
897 enum type_code type_code;
903 case stStruct: /* Start a block defining a struct type */
904 type_code = TYPE_CODE_STRUCT;
905 goto structured_common;
907 case stUnion: /* Start a block defining a union type */
908 type_code = TYPE_CODE_UNION;
909 goto structured_common;
911 case stEnum: /* Start a block defining an enum type */
912 type_code = TYPE_CODE_ENUM;
913 goto structured_common;
915 case stBlock: /* Either a lexical block, or some type */
916 if (sh->sc != scInfo && !SC_IS_COMMON (sh->sc))
917 goto case_stBlock_code; /* Lexical block */
919 type_code = TYPE_CODE_UNDEF; /* We have a type. */
921 /* Common code for handling struct, union, enum, and/or as-yet-
922 unknown-type blocks of info about structured data. `type_code'
923 has been set to the proper TYPE_CODE, if we know it. */
925 found_ecoff_debugging_info = 1;
927 top_stack->blocktype = stBlock;
929 /* First count the number of fields and the highest value. */
932 for (ext_tsym = ext_sh + external_sym_size;
934 ext_tsym += external_sym_size)
938 (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
946 if (nfields == 0 && type_code == TYPE_CODE_UNDEF)
948 /* If the type of the member is Nil (or Void),
949 without qualifiers, assume the tag is an
951 Alpha cc -migrate enums are recognized by a zero
952 index and a zero symbol value.
953 DU 4.0 cc enums are recognized by a member type of
954 btEnum without qualifiers and a zero symbol value. */
955 if (tsym.index == indexNil
956 || (tsym.index == 0 && sh->value == 0))
957 type_code = TYPE_CODE_ENUM;
960 (*debug_swap->swap_tir_in) (bigend,
961 &ax[tsym.index].a_ti,
963 if ((tir.bt == btNil || tir.bt == btVoid
964 || (tir.bt == btEnum && sh->value == 0))
966 type_code = TYPE_CODE_ENUM;
970 if (tsym.value > max_value)
971 max_value = tsym.value;
980 /* This is a no-op; is it trying to tell us something
981 we should be checking? */
982 if (tsym.sc == scVariant); /*UNIMPLEMENTED */
986 /* This is something like a struct within a
987 struct. Skip over the fields of the inner
988 struct. The -1 is because the for loop will
989 increment ext_tsym. */
990 ext_tsym = ((char *) debug_info->external_sym
991 + ((cur_fdr->isymBase + tsym.index - 1)
992 * external_sym_size));
998 /* mips cc puts out a typedef for struct x if it is not yet
999 defined when it encounters
1000 struct y { struct x *xp; };
1005 /* Irix5 cc puts out a stIndirect for struct x if it is not
1006 yet defined when it encounters
1007 struct y { struct x *xp; };
1012 complain (&block_member_complaint, tsym.st);
1017 /* In an stBlock, there is no way to distinguish structs,
1018 unions, and enums at this point. This is a bug in the
1019 original design (that has been fixed with the recent
1020 addition of the stStruct, stUnion, and stEnum symbol
1021 types.) The way you can tell is if/when you see a variable
1022 or field of that type. In that case the variable's type
1023 (in the AUX table) says if the type is struct, union, or
1024 enum, and points back to the stBlock here. So you can
1025 patch the tag kind up later - but only if there actually is
1026 a variable or field of that type.
1028 So until we know for sure, we will guess at this point.
1030 If the first member has index==indexNil or a void type,
1031 assume we have an enumeration.
1032 Otherwise, if there is more than one member, and all
1033 the members have offset 0, assume we have a union.
1034 Otherwise, assume we have a struct.
1036 The heuristic could guess wrong in the case of of an
1037 enumeration with no members or a union with one (or zero)
1038 members, or when all except the last field of a struct have
1039 width zero. These are uncommon and/or illegal situations,
1040 and in any case guessing wrong probably doesn't matter
1043 But if we later do find out we were wrong, we fixup the tag
1044 kind. Members of an enumeration must be handled
1045 differently from struct/union fields, and that is harder to
1046 patch up, but luckily we shouldn't need to. (If there are
1047 any enumeration members, we can tell for sure it's an enum
1050 if (type_code == TYPE_CODE_UNDEF)
1052 if (nfields > 1 && max_value == 0)
1053 type_code = TYPE_CODE_UNION;
1055 type_code = TYPE_CODE_STRUCT;
1058 /* Create a new type or use the pending type. */
1059 pend = is_pending_symbol (cur_fdr, ext_sh);
1060 if (pend == (struct mdebug_pending *) NULL)
1062 t = new_type (NULL);
1063 add_pending (cur_fdr, ext_sh, t);
1068 /* Do not set the tag name if it is a compiler generated tag name
1069 (.Fxx or .xxfake or empty) for unnamed struct/union/enums.
1070 Alpha cc puts out an sh->iss of zero for those. */
1071 if (sh->iss == 0 || name[0] == '.' || name[0] == '\0')
1072 TYPE_TAG_NAME (t) = NULL;
1074 TYPE_TAG_NAME (t) = obconcat (¤t_objfile->symbol_obstack,
1077 TYPE_CODE (t) = type_code;
1078 TYPE_LENGTH (t) = sh->value;
1079 TYPE_NFIELDS (t) = nfields;
1080 TYPE_FIELDS (t) = f = ((struct field *)
1082 nfields * sizeof (struct field)));
1084 if (type_code == TYPE_CODE_ENUM)
1086 int unsigned_enum = 1;
1088 /* This is a non-empty enum. */
1090 /* DEC c89 has the number of enumerators in the sh.value field,
1091 not the type length, so we have to compensate for that
1092 incompatibility quirk.
1093 This might do the wrong thing for an enum with one or two
1094 enumerators and gcc -gcoff -fshort-enums, but these cases
1095 are hopefully rare enough.
1096 Alpha cc -migrate has a sh.value field of zero, we adjust
1098 if (TYPE_LENGTH (t) == TYPE_NFIELDS (t)
1099 || TYPE_LENGTH (t) == 0)
1100 TYPE_LENGTH (t) = TARGET_INT_BIT / HOST_CHAR_BIT;
1101 for (ext_tsym = ext_sh + external_sym_size;
1103 ext_tsym += external_sym_size)
1106 struct symbol *enum_sym;
1108 (*swap_sym_in) (cur_bfd, ext_tsym, &tsym);
1110 if (tsym.st != stMember)
1113 FIELD_BITPOS (*f) = tsym.value;
1114 FIELD_TYPE (*f) = t;
1115 FIELD_NAME (*f) = debug_info->ss + cur_fdr->issBase + tsym.iss;
1116 FIELD_BITSIZE (*f) = 0;
1118 enum_sym = ((struct symbol *)
1119 obstack_alloc (¤t_objfile->symbol_obstack,
1120 sizeof (struct symbol)));
1121 memset ((PTR) enum_sym, 0, sizeof (struct symbol));
1122 SYMBOL_NAME (enum_sym) =
1123 obsavestring (f->name, strlen (f->name),
1124 ¤t_objfile->symbol_obstack);
1125 SYMBOL_CLASS (enum_sym) = LOC_CONST;
1126 SYMBOL_TYPE (enum_sym) = t;
1127 SYMBOL_NAMESPACE (enum_sym) = VAR_NAMESPACE;
1128 SYMBOL_VALUE (enum_sym) = tsym.value;
1129 if (SYMBOL_VALUE (enum_sym) < 0)
1131 add_symbol (enum_sym, top_stack->cur_block);
1133 /* Skip the stMembers that we've handled. */
1138 TYPE_FLAGS (t) |= TYPE_FLAG_UNSIGNED;
1140 /* make this the current type */
1141 top_stack->cur_type = t;
1142 top_stack->cur_field = 0;
1144 /* Do not create a symbol for alpha cc unnamed structs. */
1148 /* gcc puts out an empty struct for an opaque struct definitions,
1149 do not create a symbol for it either. */
1150 if (TYPE_NFIELDS (t) == 0)
1152 TYPE_FLAGS (t) |= TYPE_FLAG_STUB;
1156 s = new_symbol (name);
1157 SYMBOL_NAMESPACE (s) = STRUCT_NAMESPACE;
1158 SYMBOL_CLASS (s) = LOC_TYPEDEF;
1159 SYMBOL_VALUE (s) = 0;
1160 SYMBOL_TYPE (s) = t;
1161 add_symbol (s, top_stack->cur_block);
1164 /* End of local variables shared by struct, union, enum, and
1165 block (as yet unknown struct/union/enum) processing. */
1169 found_ecoff_debugging_info = 1;
1170 /* beginnning of (code) block. Value of symbol
1171 is the displacement from procedure start */
1172 push_parse_stack ();
1174 /* Do not start a new block if this is the outermost block of a
1175 procedure. This allows the LOC_BLOCK symbol to point to the
1176 block with the local variables, so funcname::var works. */
1177 if (top_stack->blocktype == stProc
1178 || top_stack->blocktype == stStaticProc)
1180 top_stack->blocktype = stNil;
1184 top_stack->blocktype = stBlock;
1185 b = new_block (top_stack->maxsyms);
1186 BLOCK_START (b) = sh->value + top_stack->procadr;
1187 BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
1188 top_stack->cur_block = b;
1189 add_block (b, top_stack->cur_st);
1192 case stEnd: /* end (of anything) */
1193 if (sh->sc == scInfo || SC_IS_COMMON (sh->sc))
1195 /* Finished with type */
1196 top_stack->cur_type = 0;
1198 else if (sh->sc == scText &&
1199 (top_stack->blocktype == stProc ||
1200 top_stack->blocktype == stStaticProc))
1202 /* Finished with procedure */
1203 struct blockvector *bv = BLOCKVECTOR (top_stack->cur_st);
1204 struct mips_extra_func_info *e;
1206 struct type *ftype = top_stack->cur_type;
1209 BLOCK_END (top_stack->cur_block) += sh->value; /* size */
1211 /* Make up special symbol to contain procedure specific info */
1212 s = new_symbol (MIPS_EFI_SYMBOL_NAME);
1213 SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
1214 SYMBOL_CLASS (s) = LOC_CONST;
1215 SYMBOL_TYPE (s) = mdebug_type_void;
1216 e = ((struct mips_extra_func_info *)
1217 obstack_alloc (¤t_objfile->symbol_obstack,
1218 sizeof (struct mips_extra_func_info)));
1219 memset ((PTR) e, 0, sizeof (struct mips_extra_func_info));
1220 SYMBOL_VALUE (s) = (long) e;
1221 e->numargs = top_stack->numargs;
1222 e->pdr.framereg = -1;
1223 add_symbol (s, top_stack->cur_block);
1225 /* Reallocate symbols, saving memory */
1226 b = shrink_block (top_stack->cur_block, top_stack->cur_st);
1228 /* f77 emits proc-level with address bounds==[0,0],
1229 So look for such child blocks, and patch them. */
1230 for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
1232 struct block *b_bad = BLOCKVECTOR_BLOCK (bv, i);
1233 if (BLOCK_SUPERBLOCK (b_bad) == b
1234 && BLOCK_START (b_bad) == top_stack->procadr
1235 && BLOCK_END (b_bad) == top_stack->procadr)
1237 BLOCK_START (b_bad) = BLOCK_START (b);
1238 BLOCK_END (b_bad) = BLOCK_END (b);
1242 if (TYPE_NFIELDS (ftype) <= 0)
1244 /* No parameter type information is recorded with the function's
1245 type. Set that from the type of the parameter symbols. */
1246 int nparams = top_stack->numargs;
1252 TYPE_NFIELDS (ftype) = nparams;
1253 TYPE_FIELDS (ftype) = (struct field *)
1254 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
1256 for (i = iparams = 0; iparams < nparams; i++)
1258 sym = BLOCK_SYM (b, i);
1259 switch (SYMBOL_CLASS (sym))
1264 case LOC_REGPARM_ADDR:
1265 TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym);
1275 else if (sh->sc == scText && top_stack->blocktype == stBlock)
1277 /* End of (code) block. The value of the symbol is the
1278 displacement from the procedure`s start address of the
1279 end of this block. */
1280 BLOCK_END (top_stack->cur_block) = sh->value + top_stack->procadr;
1281 shrink_block (top_stack->cur_block, top_stack->cur_st);
1283 else if (sh->sc == scText && top_stack->blocktype == stNil)
1285 /* End of outermost block. Pop parse stack and ignore. The
1286 following stEnd of stProc will take care of the block. */
1289 else if (sh->sc == scText && top_stack->blocktype == stFile)
1291 /* End of file. Pop parse stack and ignore. Higher
1292 level code deals with this. */
1296 complain (&stEnd_complaint, sh->sc);
1298 pop_parse_stack (); /* restore previous lexical context */
1301 case stMember: /* member of struct or union */
1302 f = &TYPE_FIELDS (top_stack->cur_type)[top_stack->cur_field++];
1303 FIELD_NAME (*f) = name;
1304 FIELD_BITPOS (*f) = sh->value;
1306 FIELD_TYPE (*f) = parse_type (cur_fd, ax, sh->index, &bitsize, bigend, name);
1307 FIELD_BITSIZE (*f) = bitsize;
1310 case stIndirect: /* forward declaration on Irix5 */
1311 /* Forward declarations from Irix5 cc are handled by cross_ref,
1315 case stTypedef: /* type definition */
1316 found_ecoff_debugging_info = 1;
1318 /* Typedefs for forward declarations and opaque structs from alpha cc
1319 are handled by cross_ref, skip them. */
1323 /* Parse the type or use the pending type. */
1324 pend = is_pending_symbol (cur_fdr, ext_sh);
1325 if (pend == (struct mdebug_pending *) NULL)
1327 t = parse_type (cur_fd, ax, sh->index, (int *) NULL, bigend, name);
1328 add_pending (cur_fdr, ext_sh, t);
1333 /* mips cc puts out a typedef with the name of the struct for forward
1334 declarations. These should not go into the symbol table and
1335 TYPE_NAME should not be set for them.
1336 They can't be distinguished from an intentional typedef to
1337 the same name however:
1339 struct x { int ix; int jx; };
1343 struct xx {int ixx; int jxx; };
1344 generates a cross referencing stTypedef for x and xx.
1345 The user visible effect of this is that the type of a pointer
1346 to struct foo sometimes is given as `foo *' instead of `struct foo *'.
1347 The problem is fixed with alpha cc and Irix5 cc. */
1349 /* However if the typedef cross references to an opaque aggregate, it
1350 is safe to omit it from the symbol table. */
1352 if (has_opaque_xref (cur_fdr, sh))
1354 s = new_symbol (name);
1355 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
1356 SYMBOL_CLASS (s) = LOC_TYPEDEF;
1357 SYMBOL_BLOCK_VALUE (s) = top_stack->cur_block;
1358 SYMBOL_TYPE (s) = t;
1359 add_symbol (s, top_stack->cur_block);
1361 /* Incomplete definitions of structs should not get a name. */
1362 if (TYPE_NAME (SYMBOL_TYPE (s)) == NULL
1363 && (TYPE_NFIELDS (SYMBOL_TYPE (s)) != 0
1364 || (TYPE_CODE (SYMBOL_TYPE (s)) != TYPE_CODE_STRUCT
1365 && TYPE_CODE (SYMBOL_TYPE (s)) != TYPE_CODE_UNION)))
1367 if (TYPE_CODE (SYMBOL_TYPE (s)) == TYPE_CODE_PTR
1368 || TYPE_CODE (SYMBOL_TYPE (s)) == TYPE_CODE_FUNC)
1370 /* If we are giving a name to a type such as "pointer to
1371 foo" or "function returning foo", we better not set
1372 the TYPE_NAME. If the program contains "typedef char
1373 *caddr_t;", we don't want all variables of type char
1374 * to print as caddr_t. This is not just a
1375 consequence of GDB's type management; CC and GCC (at
1376 least through version 2.4) both output variables of
1377 either type char * or caddr_t with the type
1378 refering to the stTypedef symbol for caddr_t. If a future
1379 compiler cleans this up it GDB is not ready for it
1380 yet, but if it becomes ready we somehow need to
1381 disable this check (without breaking the PCC/GCC2.4
1386 Fortunately, this check seems not to be necessary
1387 for anything except pointers or functions. */
1390 TYPE_NAME (SYMBOL_TYPE (s)) = SYMBOL_NAME (s);
1394 case stFile: /* file name */
1395 push_parse_stack ();
1396 top_stack->blocktype = sh->st;
1399 /* I`ve never seen these for C */
1401 break; /* register relocation */
1403 break; /* forwarding address */
1405 break; /* constant */
1407 complain (&unknown_mdebug_symtype_complaint, sh->st);
1414 /* Parse the type information provided in the raw AX entries for
1415 the symbol SH. Return the bitfield size in BS, in case.
1416 We must byte-swap the AX entries before we use them; BIGEND says whether
1417 they are big-endian or little-endian (from fh->fBigendian). */
1419 static struct type *
1420 parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
1421 int bigend, char *sym_name)
1423 /* Null entries in this map are treated specially */
1424 static struct type **map_bt[] =
1426 &mdebug_type_void, /* btNil */
1427 &mdebug_type_adr_32, /* btAdr */
1428 &mdebug_type_char, /* btChar */
1429 &mdebug_type_unsigned_char, /* btUChar */
1430 &mdebug_type_short, /* btShort */
1431 &mdebug_type_unsigned_short, /* btUShort */
1432 &mdebug_type_int_32, /* btInt */
1433 &mdebug_type_unsigned_int_32, /* btUInt */
1434 &mdebug_type_long_32, /* btLong */
1435 &mdebug_type_unsigned_long_32, /* btULong */
1436 &mdebug_type_float, /* btFloat */
1437 &mdebug_type_double, /* btDouble */
1444 &mdebug_type_complex, /* btComplex */
1445 &mdebug_type_double_complex, /* btDComplex */
1447 &mdebug_type_fixed_dec, /* btFixedDec */
1448 &mdebug_type_float_dec, /* btFloatDec */
1449 &mdebug_type_string, /* btString */
1452 &mdebug_type_void, /* btVoid */
1453 0, /* DEC C++: Pointer to member */
1454 0, /* DEC C++: Virtual function table */
1455 0, /* DEC C++: Class (Record) */
1456 &mdebug_type_long_64, /* btLong64 */
1457 &mdebug_type_unsigned_long_64, /* btULong64 */
1458 &mdebug_type_long_long_64, /* btLongLong64 */
1459 &mdebug_type_unsigned_long_long_64, /* btULongLong64 */
1460 &mdebug_type_adr_64, /* btAdr64 */
1461 &mdebug_type_int_64, /* btInt64 */
1462 &mdebug_type_unsigned_int_64, /* btUInt64 */
1466 struct type *tp = 0;
1467 enum type_code type_code = TYPE_CODE_UNDEF;
1469 /* Handle undefined types, they have indexNil. */
1470 if (aux_index == indexNil)
1471 return mdebug_type_int;
1473 /* Handle corrupt aux indices. */
1474 if (aux_index >= (debug_info->fdr + fd)->caux)
1476 complain (&index_complaint, sym_name);
1477 return mdebug_type_int;
1481 /* Use aux as a type information record, map its basic type. */
1482 (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t);
1483 if (t->bt >= (sizeof (map_bt) / sizeof (*map_bt)))
1485 complain (&basic_type_complaint, t->bt, sym_name);
1486 return mdebug_type_int;
1490 tp = *map_bt[t->bt];
1495 /* Cannot use builtin types -- build our own */
1499 type_code = TYPE_CODE_STRUCT;
1502 type_code = TYPE_CODE_UNION;
1505 type_code = TYPE_CODE_ENUM;
1508 type_code = TYPE_CODE_RANGE;
1511 type_code = TYPE_CODE_SET;
1514 /* alpha cc -migrate uses this for typedefs. The true type will
1515 be obtained by crossreferencing below. */
1516 type_code = TYPE_CODE_ERROR;
1519 /* alpha cc uses this for typedefs. The true type will be
1520 obtained by crossreferencing below. */
1521 type_code = TYPE_CODE_ERROR;
1524 complain (&basic_type_complaint, t->bt, sym_name);
1525 return mdebug_type_int;
1529 /* Move on to next aux */
1534 int width = AUX_GET_WIDTH (bigend, ax);
1536 /* Inhibit core dumps with some cfront generated objects that
1538 if (bs == (int *) NULL)
1540 /* Alpha cc -migrate encodes char and unsigned char types
1541 as short and unsigned short types with a field width of 8.
1542 Enum types also have a field width which we ignore for now. */
1543 if (t->bt == btShort && width == 8)
1544 tp = mdebug_type_char;
1545 else if (t->bt == btUShort && width == 8)
1546 tp = mdebug_type_unsigned_char;
1547 else if (t->bt == btEnum)
1550 complain (&bad_fbitfield_complaint, sym_name);
1557 /* A btIndirect entry cross references to an aux entry containing
1559 if (t->bt == btIndirect)
1566 (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn);
1568 if (rn->rfd == 0xfff)
1570 rf = AUX_GET_ISYM (bigend, ax);
1578 complain (&bad_indirect_xref_complaint, sym_name);
1579 return mdebug_type_int;
1581 xref_fh = get_rfd (fd, rf);
1582 xref_fd = xref_fh - debug_info->fdr;
1583 tp = parse_type (xref_fd, debug_info->external_aux + xref_fh->iauxBase,
1584 rn->index, (int *) NULL, xref_fh->fBigendian, sym_name);
1587 /* All these types really point to some (common) MIPS type
1588 definition, and only the type-qualifiers fully identify
1589 them. We'll make the same effort at sharing. */
1590 if (t->bt == btStruct ||
1594 /* btSet (I think) implies that the name is a tag name, not a typedef
1595 name. This apparently is a MIPS extension for C sets. */
1600 /* Try to cross reference this type, build new type on failure. */
1601 ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
1602 if (tp == (struct type *) NULL)
1603 tp = init_type (type_code, 0, 0, (char *) NULL, current_objfile);
1605 /* DEC c89 produces cross references to qualified aggregate types,
1606 dereference them. */
1607 while (TYPE_CODE (tp) == TYPE_CODE_PTR
1608 || TYPE_CODE (tp) == TYPE_CODE_ARRAY)
1609 tp = tp->target_type;
1611 /* Make sure that TYPE_CODE(tp) has an expected type code.
1612 Any type may be returned from cross_ref if file indirect entries
1614 if (TYPE_CODE (tp) != TYPE_CODE_STRUCT
1615 && TYPE_CODE (tp) != TYPE_CODE_UNION
1616 && TYPE_CODE (tp) != TYPE_CODE_ENUM)
1618 complain (&unexpected_type_code_complaint, sym_name);
1623 /* Usually, TYPE_CODE(tp) is already type_code. The main
1624 exception is if we guessed wrong re struct/union/enum.
1625 But for struct vs. union a wrong guess is harmless, so
1626 don't complain(). */
1627 if ((TYPE_CODE (tp) == TYPE_CODE_ENUM
1628 && type_code != TYPE_CODE_ENUM)
1629 || (TYPE_CODE (tp) != TYPE_CODE_ENUM
1630 && type_code == TYPE_CODE_ENUM))
1632 complain (&bad_tag_guess_complaint, sym_name);
1635 if (TYPE_CODE (tp) != type_code)
1637 TYPE_CODE (tp) = type_code;
1640 /* Do not set the tag name if it is a compiler generated tag name
1641 (.Fxx or .xxfake or empty) for unnamed struct/union/enums. */
1642 if (name[0] == '.' || name[0] == '\0')
1643 TYPE_TAG_NAME (tp) = NULL;
1644 else if (TYPE_TAG_NAME (tp) == NULL
1645 || !STREQ (TYPE_TAG_NAME (tp), name))
1646 TYPE_TAG_NAME (tp) = obsavestring (name, strlen (name),
1647 ¤t_objfile->type_obstack);
1651 /* All these types really point to some (common) MIPS type
1652 definition, and only the type-qualifiers fully identify
1653 them. We'll make the same effort at sharing.
1654 FIXME: We are not doing any guessing on range types. */
1655 if (t->bt == btRange)
1659 /* Try to cross reference this type, build new type on failure. */
1660 ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
1661 if (tp == (struct type *) NULL)
1662 tp = init_type (type_code, 0, 0, (char *) NULL, current_objfile);
1664 /* Make sure that TYPE_CODE(tp) has an expected type code.
1665 Any type may be returned from cross_ref if file indirect entries
1667 if (TYPE_CODE (tp) != TYPE_CODE_RANGE)
1669 complain (&unexpected_type_code_complaint, sym_name);
1673 /* Usually, TYPE_CODE(tp) is already type_code. The main
1674 exception is if we guessed wrong re struct/union/enum. */
1675 if (TYPE_CODE (tp) != type_code)
1677 complain (&bad_tag_guess_complaint, sym_name);
1678 TYPE_CODE (tp) = type_code;
1680 if (TYPE_NAME (tp) == NULL || !STREQ (TYPE_NAME (tp), name))
1681 TYPE_NAME (tp) = obsavestring (name, strlen (name),
1682 ¤t_objfile->type_obstack);
1685 if (t->bt == btTypedef)
1689 /* Try to cross reference this type, it should succeed. */
1690 ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
1691 if (tp == (struct type *) NULL)
1693 complain (&unable_to_cross_ref_complaint, sym_name);
1694 tp = mdebug_type_int;
1698 /* Deal with range types */
1699 if (t->bt == btRange)
1701 TYPE_NFIELDS (tp) = 2;
1702 TYPE_FIELDS (tp) = ((struct field *)
1703 TYPE_ALLOC (tp, 2 * sizeof (struct field)));
1704 TYPE_FIELD_NAME (tp, 0) = obsavestring ("Low", strlen ("Low"),
1705 ¤t_objfile->type_obstack);
1706 TYPE_FIELD_BITPOS (tp, 0) = AUX_GET_DNLOW (bigend, ax);
1708 TYPE_FIELD_NAME (tp, 1) = obsavestring ("High", strlen ("High"),
1709 ¤t_objfile->type_obstack);
1710 TYPE_FIELD_BITPOS (tp, 1) = AUX_GET_DNHIGH (bigend, ax);
1714 /* Parse all the type qualifiers now. If there are more
1715 than 6 the game will continue in the next aux */
1719 #define PARSE_TQ(tq) \
1720 if (t->tq != tqNil) \
1721 ax += upgrade_type(fd, &tp, t->tq, ax, bigend, sym_name); \
1733 /* mips cc 2.x and gcc never put out continued aux entries. */
1737 (*debug_swap->swap_tir_in) (bigend, &ax->a_ti, t);
1741 /* Complain for illegal continuations due to corrupt aux entries. */
1743 complain (&bad_continued_complaint, sym_name);
1748 /* Make up a complex type from a basic one. Type is passed by
1749 reference in TPP and side-effected as necessary. The type
1750 qualifier TQ says how to handle the aux symbols at AX for
1751 the symbol SX we are currently analyzing. BIGEND says whether
1752 aux symbols are big-endian or little-endian.
1753 Returns the number of aux symbols we parsed. */
1756 upgrade_type (int fd, struct type **tpp, int tq, union aux_ext *ax, int bigend,
1762 /* Used in array processing */
1773 t = lookup_pointer_type (*tpp);
1778 t = lookup_function_type (*tpp);
1785 /* Determine and record the domain type (type of index) */
1786 (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, &rndx);
1792 rf = AUX_GET_ISYM (bigend, ax);
1795 fh = get_rfd (fd, rf);
1797 indx = parse_type (fh - debug_info->fdr,
1798 debug_info->external_aux + fh->iauxBase,
1799 id, (int *) NULL, bigend, sym_name);
1801 /* The bounds type should be an integer type, but might be anything
1802 else due to corrupt aux entries. */
1803 if (TYPE_CODE (indx) != TYPE_CODE_INT)
1805 complain (&array_index_type_complaint, sym_name);
1806 indx = mdebug_type_int;
1809 /* Get the bounds, and create the array type. */
1811 lower = AUX_GET_DNLOW (bigend, ax);
1813 upper = AUX_GET_DNHIGH (bigend, ax);
1815 rf = AUX_GET_WIDTH (bigend, ax); /* bit size of array element */
1817 range = create_range_type ((struct type *) NULL, indx,
1820 t = create_array_type ((struct type *) NULL, *tpp, range);
1822 /* We used to fill in the supplied array element bitsize
1823 here if the TYPE_LENGTH of the target type was zero.
1824 This happens for a `pointer to an array of anonymous structs',
1825 but in this case the array element bitsize is also zero,
1826 so nothing is gained.
1827 And we used to check the TYPE_LENGTH of the target type against
1828 the supplied array element bitsize.
1829 gcc causes a mismatch for `pointer to array of object',
1830 since the sdb directives it uses do not have a way of
1831 specifying the bitsize, but it does no harm (the
1832 TYPE_LENGTH should be correct) and we should be able to
1833 ignore the erroneous bitsize from the auxiliary entry safely.
1834 dbx seems to ignore it too. */
1836 /* TYPE_FLAG_TARGET_STUB now takes care of the zero TYPE_LENGTH
1838 if (TYPE_LENGTH (*tpp) == 0)
1840 TYPE_FLAGS (t) |= TYPE_FLAG_TARGET_STUB;
1847 /* Volatile -- currently ignored */
1851 /* Const -- currently ignored */
1855 complain (&unknown_type_qual_complaint, tq);
1861 /* Parse a procedure descriptor record PR. Note that the procedure is
1862 parsed _after_ the local symbols, now we just insert the extra
1863 information we need into a MIPS_EFI_SYMBOL_NAME symbol that has
1864 already been placed in the procedure's main block. Note also that
1865 images that have been partially stripped (ld -x) have been deprived
1866 of local symbols, and we have to cope with them here. FIRST_OFF is
1867 the offset of the first procedure for this FDR; we adjust the
1868 address by this amount, but I don't know why. SEARCH_SYMTAB is the symtab
1869 to look for the function which contains the MIPS_EFI_SYMBOL_NAME symbol
1870 in question, or NULL to use top_stack->cur_block. */
1872 static void parse_procedure (PDR *, struct symtab *, struct partial_symtab *);
1875 parse_procedure (PDR *pr, struct symtab *search_symtab,
1876 struct partial_symtab *pst)
1878 struct symbol *s, *i;
1880 struct mips_extra_func_info *e;
1883 /* Simple rule to find files linked "-x" */
1884 if (cur_fdr->rss == -1)
1888 /* Static procedure at address pr->adr. Sigh. */
1889 /* FIXME-32x64. assuming pr->adr fits in long. */
1890 complain (&pdr_static_symbol_complaint, (unsigned long) pr->adr);
1898 (*debug_swap->swap_ext_in) (cur_bfd,
1899 ((char *) debug_info->external_ext
1901 * debug_swap->external_ext_size)),
1903 sh_name = debug_info->ssext + she.asym.iss;
1911 (*debug_swap->swap_sym_in) (cur_bfd,
1912 ((char *) debug_info->external_sym
1913 + ((cur_fdr->isymBase + pr->isym)
1914 * debug_swap->external_sym_size)),
1916 sh_name = debug_info->ss + cur_fdr->issBase + sh.iss;
1919 if (search_symtab != NULL)
1922 /* This loses both in the case mentioned (want a static, find a global),
1923 but also if we are looking up a non-mangled name which happens to
1924 match the name of a mangled function. */
1925 /* We have to save the cur_fdr across the call to lookup_symbol.
1926 If the pdr is for a static function and if a global function with
1927 the same name exists, lookup_symbol will eventually read in the symtab
1928 for the global function and clobber cur_fdr. */
1929 FDR *save_cur_fdr = cur_fdr;
1930 s = lookup_symbol (sh_name, NULL, VAR_NAMESPACE, 0, NULL);
1931 cur_fdr = save_cur_fdr;
1935 BLOCKVECTOR_BLOCK (BLOCKVECTOR (search_symtab), STATIC_BLOCK),
1941 s = mylookup_symbol (sh_name, top_stack->cur_block,
1942 VAR_NAMESPACE, LOC_BLOCK);
1946 b = SYMBOL_BLOCK_VALUE (s);
1950 complain (&pdr_for_nonsymbol_complaint, sh_name);
1954 /* FIXME -- delete. We can't do symbol allocation now; it's all done. */
1955 s = new_symbol (sh_name);
1956 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
1957 SYMBOL_CLASS (s) = LOC_BLOCK;
1958 /* Donno its type, hope int is ok */
1959 SYMBOL_TYPE (s) = lookup_function_type (mdebug_type_int);
1960 add_symbol (s, top_stack->cur_block);
1961 /* Wont have symbols for this one */
1963 SYMBOL_BLOCK_VALUE (s) = b;
1964 BLOCK_FUNCTION (b) = s;
1965 BLOCK_START (b) = pr->adr;
1966 /* BOUND used to be the end of procedure's text, but the
1967 argument is no longer passed in. */
1968 BLOCK_END (b) = bound;
1969 BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
1970 add_block (b, top_stack->cur_st);
1974 i = mylookup_symbol (MIPS_EFI_SYMBOL_NAME, b, LABEL_NAMESPACE, LOC_CONST);
1978 e = (struct mips_extra_func_info *) SYMBOL_VALUE (i);
1980 e->pdr.isym = (long) s;
1982 /* GDB expects the absolute function start address for the
1983 procedure descriptor in e->pdr.adr.
1984 As the address in the procedure descriptor is usually relative,
1985 we would have to relocate e->pdr.adr with cur_fdr->adr and
1986 ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (pst->objfile)).
1987 Unfortunately cur_fdr->adr and e->pdr.adr are both absolute
1988 in shared libraries on some systems, and on other systems
1989 e->pdr.adr is sometimes offset by a bogus value.
1990 To work around these problems, we replace e->pdr.adr with
1991 the start address of the function. */
1992 e->pdr.adr = BLOCK_START (b);
1994 /* Correct incorrect setjmp procedure descriptor from the library
1995 to make backtrace through setjmp work. */
1996 if (e->pdr.pcreg == 0 && STREQ (sh_name, "setjmp"))
1998 complain (&bad_setjmp_pdr_complaint, 0);
1999 e->pdr.pcreg = RA_REGNUM;
2000 e->pdr.regmask = 0x80000000;
2001 e->pdr.regoffset = -4;
2005 /* It would be reasonable that functions that have been compiled
2006 without debugging info have a btNil type for their return value,
2007 and functions that are void and are compiled with debugging info
2009 gcc and DEC f77 put out btNil types for both cases, so btNil is mapped
2010 to TYPE_CODE_VOID in parse_type to get the `compiled with debugging info'
2012 The glevel field in cur_fdr could be used to determine the presence
2013 of debugging info, but GCC doesn't always pass the -g switch settings
2014 to the assembler and GAS doesn't set the glevel field from the -g switch
2016 To work around these problems, the return value type of a TYPE_CODE_VOID
2017 function is adjusted accordingly if no debugging info was found in the
2018 compilation unit. */
2020 if (processing_gcc_compilation == 0
2021 && found_ecoff_debugging_info == 0
2022 && TYPE_CODE (TYPE_TARGET_TYPE (SYMBOL_TYPE (s))) == TYPE_CODE_VOID)
2023 SYMBOL_TYPE (s) = nodebug_func_symbol_type;
2026 /* Relocate the extra function info pointed to by the symbol table. */
2029 ecoff_relocate_efi (struct symbol *sym, CORE_ADDR delta)
2031 struct mips_extra_func_info *e;
2033 e = (struct mips_extra_func_info *) SYMBOL_VALUE (sym);
2035 e->pdr.adr += delta;
2038 /* Parse the external symbol ES. Just call parse_symbol() after
2039 making sure we know where the aux are for it.
2040 BIGEND says whether aux entries are big-endian or little-endian.
2042 This routine clobbers top_stack->cur_block and ->cur_st. */
2044 static void parse_external (EXTR *, int, struct section_offsets *,
2048 parse_external (EXTR *es, int bigend, struct section_offsets *section_offsets,
2049 struct objfile *objfile)
2053 if (es->ifd != ifdNil)
2056 cur_fdr = debug_info->fdr + cur_fd;
2057 ax = debug_info->external_aux + cur_fdr->iauxBase;
2061 cur_fdr = debug_info->fdr;
2065 /* Reading .o files */
2066 if (SC_IS_UNDEF (es->asym.sc) || es->asym.sc == scNil)
2069 switch (es->asym.st)
2072 /* These are generated for static symbols in .o files,
2093 /* FIXME: Turn this into a complaint? */
2095 printf_filtered ("Warning: %s `%s' is undefined (in %s)\n",
2096 what, debug_info->ssext + es->asym.iss,
2097 fdr_name (cur_fdr));
2101 switch (es->asym.st)
2105 /* There is no need to parse the external procedure symbols.
2106 If they are from objects compiled without -g, their index will
2107 be indexNil, and the symbol definition from the minimal symbol
2108 is preferrable (yielding a function returning int instead of int).
2109 If the index points to a local procedure symbol, the local
2110 symbol already provides the correct type.
2111 Note that the index of the external procedure symbol points
2112 to the local procedure symbol in the local symbol table, and
2113 _not_ to the auxiliary symbol info. */
2117 /* Global common symbols are resolved by the runtime loader,
2119 if (SC_IS_COMMON (es->asym.sc))
2122 /* Note that the case of a symbol with indexNil must be handled
2123 anyways by parse_symbol(). */
2124 parse_symbol (&es->asym, ax, (char *) NULL, bigend, section_offsets, objfile);
2131 /* Parse the line number info for file descriptor FH into
2132 GDB's linetable LT. MIPS' encoding requires a little bit
2133 of magic to get things out. Note also that MIPS' line
2134 numbers can go back and forth, apparently we can live
2135 with that and do not need to reorder our linetables */
2137 static void parse_lines (FDR *, PDR *, struct linetable *, int,
2138 struct partial_symtab *, CORE_ADDR);
2141 parse_lines (FDR *fh, PDR *pr, struct linetable *lt, int maxlines,
2142 struct partial_symtab *pst, CORE_ADDR lowest_pdr_addr)
2144 unsigned char *base;
2146 int delta, count, lineno = 0;
2148 if (fh->cbLine == 0)
2151 /* Scan by procedure descriptors */
2153 for (j = 0; j < fh->cpd; j++, pr++)
2157 unsigned char *halt;
2159 /* No code for this one */
2160 if (pr->iline == ilineNil ||
2161 pr->lnLow == -1 || pr->lnHigh == -1)
2164 /* Determine start and end address of compressed line bytes for
2166 base = debug_info->line + fh->cbLineOffset;
2167 if (j != (fh->cpd - 1))
2168 halt = base + pr[1].cbLineOffset;
2170 halt = base + fh->cbLine;
2171 base += pr->cbLineOffset;
2173 adr = pst->textlow + pr->adr - lowest_pdr_addr;
2175 l = adr >> 2; /* in words */
2176 for (lineno = pr->lnLow; base < halt;)
2178 count = *base & 0x0f;
2179 delta = *base++ >> 4;
2184 delta = (base[0] << 8) | base[1];
2185 if (delta >= 0x8000)
2189 lineno += delta; /* first delta is 0 */
2191 /* Complain if the line table overflows. Could happen
2192 with corrupt binaries. */
2193 if (lt->nitems >= maxlines)
2195 complain (&bad_linetable_guess_complaint, fdr_name (fh));
2198 k = add_line (lt, lineno, l, k);
2204 /* Master parsing procedure for first-pass reading of file symbols
2205 into a partial_symtab. */
2208 parse_partial_symbols (struct objfile *objfile)
2210 const bfd_size_type external_sym_size = debug_swap->external_sym_size;
2211 const bfd_size_type external_rfd_size = debug_swap->external_rfd_size;
2212 const bfd_size_type external_ext_size = debug_swap->external_ext_size;
2213 void (*const swap_ext_in) (bfd *, PTR, EXTR *) = debug_swap->swap_ext_in;
2214 void (*const swap_sym_in) (bfd *, PTR, SYMR *) = debug_swap->swap_sym_in;
2215 void (*const swap_rfd_in) (bfd *, PTR, RFDT *) = debug_swap->swap_rfd_in;
2217 HDRR *hdr = &debug_info->symbolic_header;
2218 /* Running pointers */
2223 register EXTR *ext_in;
2226 struct partial_symtab *pst;
2227 int textlow_not_set = 1;
2228 int past_first_source_file = 0;
2230 /* List of current psymtab's include files */
2231 char **psymtab_include_list;
2232 int includes_allocated;
2235 struct pst_map *fdr_to_pst;
2236 /* Index within current psymtab dependency list */
2237 struct partial_symtab **dependency_list;
2238 int dependencies_used, dependencies_allocated;
2239 struct cleanup *old_chain;
2241 enum language prev_language;
2242 asection *text_sect;
2243 int relocatable = 0;
2245 /* Irix 5.2 shared libraries have a fh->adr field of zero, but
2246 the shared libraries are prelinked at a high memory address.
2247 We have to adjust the start address of the object file for this case,
2248 by setting it to the start address of the first procedure in the file.
2249 But we should do no adjustments if we are debugging a .o file, where
2250 the text section (and fh->adr) really starts at zero. */
2251 text_sect = bfd_get_section_by_name (cur_bfd, ".text");
2252 if (text_sect != NULL
2253 && (bfd_get_section_flags (cur_bfd, text_sect) & SEC_RELOC))
2256 extern_tab = (EXTR *) obstack_alloc (&objfile->psymbol_obstack,
2257 sizeof (EXTR) * hdr->iextMax);
2259 includes_allocated = 30;
2261 psymtab_include_list = (char **) alloca (includes_allocated *
2263 next_symbol_text_func = mdebug_next_symbol_text;
2265 dependencies_allocated = 30;
2266 dependencies_used = 0;
2268 (struct partial_symtab **) alloca (dependencies_allocated *
2269 sizeof (struct partial_symtab *));
2271 last_source_file = NULL;
2276 * Only parse the Local and External symbols, and the Relative FDR.
2277 * Fixup enough of the loader symtab to be able to use it.
2278 * Allocate space only for the file's portions we need to
2283 max_glevel = MIN_GLEVEL;
2285 /* Allocate the map FDR -> PST.
2286 Minor hack: -O3 images might claim some global data belongs
2287 to FDR -1. We`ll go along with that */
2288 fdr_to_pst = (struct pst_map *) xzalloc ((hdr->ifdMax + 1) * sizeof *fdr_to_pst);
2289 old_chain = make_cleanup (xfree, fdr_to_pst);
2292 struct partial_symtab *pst = new_psymtab ("", objfile);
2293 fdr_to_pst[-1].pst = pst;
2297 /* Allocate the global pending list. */
2299 ((struct mdebug_pending **)
2300 obstack_alloc (&objfile->psymbol_obstack,
2301 hdr->ifdMax * sizeof (struct mdebug_pending *)));
2302 memset ((PTR) pending_list, 0,
2303 hdr->ifdMax * sizeof (struct mdebug_pending *));
2305 /* Pass 0 over external syms: swap them in. */
2306 ext_block = (EXTR *) xmalloc (hdr->iextMax * sizeof (EXTR));
2307 make_cleanup (xfree, ext_block);
2309 ext_out = (char *) debug_info->external_ext;
2310 ext_out_end = ext_out + hdr->iextMax * external_ext_size;
2312 for (; ext_out < ext_out_end; ext_out += external_ext_size, ext_in++)
2313 (*swap_ext_in) (cur_bfd, ext_out, ext_in);
2315 /* Pass 1 over external syms: Presize and partition the list */
2317 ext_in_end = ext_in + hdr->iextMax;
2318 for (; ext_in < ext_in_end; ext_in++)
2320 /* See calls to complain below. */
2321 if (ext_in->ifd >= -1
2322 && ext_in->ifd < hdr->ifdMax
2323 && ext_in->asym.iss >= 0
2324 && ext_in->asym.iss < hdr->issExtMax)
2325 fdr_to_pst[ext_in->ifd].n_globals++;
2328 /* Pass 1.5 over files: partition out global symbol space */
2330 for (f_idx = -1; f_idx < hdr->ifdMax; f_idx++)
2332 fdr_to_pst[f_idx].globals_offset = s_idx;
2333 s_idx += fdr_to_pst[f_idx].n_globals;
2334 fdr_to_pst[f_idx].n_globals = 0;
2339 For ECOFF in ELF, we skip the creation of the minimal symbols.
2340 The ECOFF symbols should be a subset of the Elf symbols, and the
2341 section information of the elf symbols will be more accurate.
2342 FIXME! What about Irix 5's native linker?
2344 By default, Elf sections which don't exist in ECOFF
2345 get put in ECOFF's absolute section by the gnu linker.
2346 Since absolute sections don't get relocated, we
2347 end up calculating an address different from that of
2348 the symbol's minimal symbol (created earlier from the
2351 To fix this, either :
2352 1) don't create the duplicate symbol
2353 (assumes ECOFF symtab is a subset of the ELF symtab;
2354 assumes no side-effects result from ignoring ECOFF symbol)
2355 2) create it, only if lookup for existing symbol in ELF's minimal
2358 assumes no side-effects result from ignoring ECOFF symbol)
2359 3) create it, but lookup ELF's minimal symbol and use it's section
2360 during relocation, then modify "uniqify" phase to merge and
2361 eliminate the duplicate symbol
2362 (highly inefficient)
2364 I've implemented #1 here...
2365 Skip the creation of the minimal symbols based on the ECOFF
2368 /* Pass 2 over external syms: fill in external symbols */
2370 ext_in_end = ext_in + hdr->iextMax;
2371 for (; ext_in < ext_in_end; ext_in++)
2373 enum minimal_symbol_type ms_type = mst_text;
2374 CORE_ADDR svalue = ext_in->asym.value;
2376 /* The Irix 5 native tools seem to sometimes generate bogus
2377 external symbols. */
2378 if (ext_in->ifd < -1 || ext_in->ifd >= hdr->ifdMax)
2380 complain (&bad_ext_ifd_complaint, ext_in->ifd, hdr->ifdMax);
2383 if (ext_in->asym.iss < 0 || ext_in->asym.iss >= hdr->issExtMax)
2385 complain (&bad_ext_iss_complaint, ext_in->asym.iss,
2390 extern_tab[fdr_to_pst[ext_in->ifd].globals_offset
2391 + fdr_to_pst[ext_in->ifd].n_globals++] = *ext_in;
2394 if (SC_IS_UNDEF (ext_in->asym.sc) || ext_in->asym.sc == scNil)
2398 /* Pass 3 over files, over local syms: fill in static symbols */
2399 name = debug_info->ssext + ext_in->asym.iss;
2401 /* Process ECOFF Symbol Types and Storage Classes */
2402 switch (ext_in->asym.st)
2405 /* Beginnning of Procedure */
2406 svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2409 /* Load time only static procs */
2410 ms_type = mst_file_text;
2411 svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2414 /* External symbol */
2415 if (SC_IS_COMMON (ext_in->asym.sc))
2417 /* The value of a common symbol is its size, not its address.
2421 else if (SC_IS_DATA (ext_in->asym.sc))
2424 svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2426 else if (SC_IS_BSS (ext_in->asym.sc))
2429 svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
2436 if (SC_IS_TEXT (ext_in->asym.sc))
2438 ms_type = mst_file_text;
2439 svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2441 else if (SC_IS_DATA (ext_in->asym.sc))
2443 ms_type = mst_file_data;
2444 svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2446 else if (SC_IS_BSS (ext_in->asym.sc))
2448 ms_type = mst_file_bss;
2449 svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
2456 /* The alpha has the section start addresses in stLocal symbols
2457 whose name starts with a `.'. Skip those but complain for all
2458 other stLocal symbols.
2459 Irix6 puts the section start addresses in stNil symbols, skip
2465 ms_type = mst_unknown;
2466 complain (&unknown_ext_complaint, name);
2468 if (!ECOFF_IN_ELF (cur_bfd))
2469 prim_record_minimal_symbol (name, svalue, ms_type, objfile);
2472 /* Pass 3 over files, over local syms: fill in static symbols */
2473 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
2475 struct partial_symtab *save_pst;
2479 cur_fdr = fh = debug_info->fdr + f_idx;
2483 fdr_to_pst[f_idx].pst = NULL;
2487 /* Determine the start address for this object file from the
2488 file header and relocate it, except for Irix 5.2 zero fh->adr. */
2492 if (relocatable || textlow != 0)
2493 textlow += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2497 pst = start_psymtab_common (objfile, objfile->section_offsets,
2500 objfile->global_psymbols.next,
2501 objfile->static_psymbols.next);
2502 pst->read_symtab_private = ((char *)
2503 obstack_alloc (&objfile->psymbol_obstack,
2504 sizeof (struct symloc)));
2505 memset ((PTR) pst->read_symtab_private, 0, sizeof (struct symloc));
2508 FDR_IDX (pst) = f_idx;
2509 CUR_BFD (pst) = cur_bfd;
2510 DEBUG_SWAP (pst) = debug_swap;
2511 DEBUG_INFO (pst) = debug_info;
2512 PENDING_LIST (pst) = pending_list;
2514 /* The way to turn this into a symtab is to call... */
2515 pst->read_symtab = mdebug_psymtab_to_symtab;
2517 /* Set up language for the pst.
2518 The language from the FDR is used if it is unambigious (e.g. cfront
2519 with native cc and g++ will set the language to C).
2520 Otherwise we have to deduce the language from the filename.
2521 Native ecoff has every header file in a separate FDR, so
2522 deduce_language_from_filename will return language_unknown for
2523 a header file, which is not what we want.
2524 But the FDRs for the header files are after the FDR for the source
2525 file, so we can assign the language of the source file to the
2526 following header files. Then we save the language in the private
2527 pst data so that we can reuse it when building symtabs. */
2528 prev_language = psymtab_language;
2532 case langCplusplusV2:
2533 psymtab_language = language_cplus;
2536 psymtab_language = deduce_language_from_filename (fdr_name (fh));
2539 if (psymtab_language == language_unknown)
2540 psymtab_language = prev_language;
2541 PST_PRIVATE (pst)->pst_language = psymtab_language;
2543 pst->texthigh = pst->textlow;
2545 /* For stabs-in-ecoff files, the second symbol must be @stab.
2546 This symbol is emitted by mips-tfile to signal that the
2547 current object file uses encapsulated stabs instead of mips
2548 ecoff for local symbols. (It is the second symbol because
2549 the first symbol is the stFile used to signal the start of a
2551 processing_gcc_compilation = 0;
2554 (*swap_sym_in) (cur_bfd,
2555 ((char *) debug_info->external_sym
2556 + (fh->isymBase + 1) * external_sym_size),
2558 if (STREQ (debug_info->ss + fh->issBase + sh.iss, stabs_symbol))
2559 processing_gcc_compilation = 2;
2562 if (processing_gcc_compilation != 0)
2564 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
2569 (*swap_sym_in) (cur_bfd,
2570 (((char *) debug_info->external_sym)
2571 + (fh->isymBase + cur_sdx) * external_sym_size),
2573 type_code = ECOFF_UNMARK_STAB (sh.index);
2574 if (!ECOFF_IS_STAB (&sh))
2576 if (sh.st == stProc || sh.st == stStaticProc)
2581 sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2582 if (sh.st == stStaticProc)
2584 namestring = debug_info->ss + fh->issBase + sh.iss;
2585 prim_record_minimal_symbol_and_info (namestring,
2589 SECT_OFF_TEXT (objfile),
2593 procaddr = sh.value;
2595 isym = AUX_GET_ISYM (fh->fBigendian,
2596 (debug_info->external_aux
2599 (*swap_sym_in) (cur_bfd,
2600 ((char *) debug_info->external_sym
2601 + ((fh->isymBase + isym - 1)
2602 * external_sym_size)),
2606 CORE_ADDR high = procaddr + sh.value;
2608 /* Kludge for Irix 5.2 zero fh->adr. */
2610 && (pst->textlow == 0 || procaddr < pst->textlow))
2611 pst->textlow = procaddr;
2612 if (high > pst->texthigh)
2613 pst->texthigh = high;
2616 else if (sh.st == stStatic)
2631 namestring = debug_info->ss + fh->issBase + sh.iss;
2632 sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2633 prim_record_minimal_symbol_and_info (namestring,
2637 SECT_OFF_DATA (objfile),
2643 /* FIXME! Shouldn't this use cases for bss,
2644 then have the default be abs? */
2645 namestring = debug_info->ss + fh->issBase + sh.iss;
2646 sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
2647 prim_record_minimal_symbol_and_info (namestring,
2651 SECT_OFF_BSS (objfile),
2659 /* Handle stabs continuation */
2661 char *stabstring = debug_info->ss + fh->issBase + sh.iss;
2662 int len = strlen (stabstring);
2663 while (stabstring[len - 1] == '\\')
2666 char *stabstring1 = stabstring;
2670 /* Ignore continuation char from 1st string */
2673 /* Read next stabstring */
2675 (*swap_sym_in) (cur_bfd,
2676 (((char *) debug_info->external_sym)
2677 + (fh->isymBase + cur_sdx)
2678 * external_sym_size),
2680 stabstring2 = debug_info->ss + fh->issBase + sh2.iss;
2681 len2 = strlen (stabstring2);
2683 /* Concatinate stabstring2 with stabstring1 */
2685 && stabstring != debug_info->ss + fh->issBase + sh.iss)
2686 stabstring = xrealloc (stabstring, len + len2 + 1);
2688 stabstring = xmalloc (len + len2 + 1);
2689 strcpy (stabstring, stabstring1);
2690 strcpy (stabstring + len, stabstring2);
2694 #define SET_NAMESTRING() \
2695 namestring = stabstring
2696 #define CUR_SYMBOL_TYPE type_code
2697 #define CUR_SYMBOL_VALUE sh.value
2698 #define START_PSYMTAB(ofile,fname,low,symoff,global_syms,static_syms)\
2700 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps,textlow_not_set) (void)0
2701 #define HANDLE_RBRAC(val) \
2702 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
2703 #include "partial-stab.h"
2706 && stabstring != debug_info->ss + fh->issBase + sh.iss)
2709 /* end - Handle continuation */
2714 for (cur_sdx = 0; cur_sdx < fh->csym;)
2717 enum address_class class;
2719 (*swap_sym_in) (cur_bfd,
2720 ((char *) debug_info->external_sym
2721 + ((fh->isymBase + cur_sdx)
2722 * external_sym_size)),
2725 if (ECOFF_IS_STAB (&sh))
2731 /* Non absolute static symbols go into the minimal table. */
2732 if (SC_IS_UNDEF (sh.sc) || sh.sc == scNil
2733 || (sh.index == indexNil
2734 && (sh.st != stStatic || sh.sc == scAbs)))
2736 /* FIXME, premature? */
2741 name = debug_info->ss + fh->issBase + sh.iss;
2747 /* The value of a stEnd symbol is the displacement from the
2748 corresponding start symbol value, do not relocate it. */
2750 sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2757 sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2761 sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
2772 prim_record_minimal_symbol_and_info (name, sh.value,
2773 mst_file_text, NULL,
2774 SECT_OFF_TEXT (objfile), NULL,
2780 /* Usually there is a local and a global stProc symbol
2781 for a function. This means that the function name
2782 has already been entered into the mimimal symbol table
2783 while processing the global symbols in pass 2 above.
2784 One notable exception is the PROGRAM name from
2785 f77 compiled executables, it is only put out as
2786 local stProc symbol, and a global MAIN__ stProc symbol
2787 points to it. It doesn't matter though, as gdb is
2788 still able to find the PROGRAM name via the partial
2789 symbol table, and the MAIN__ symbol via the minimal
2791 if (sh.st == stProc)
2792 add_psymbol_to_list (name, strlen (name),
2793 VAR_NAMESPACE, LOC_BLOCK,
2794 &objfile->global_psymbols,
2795 0, sh.value, psymtab_language, objfile);
2797 add_psymbol_to_list (name, strlen (name),
2798 VAR_NAMESPACE, LOC_BLOCK,
2799 &objfile->static_psymbols,
2800 0, sh.value, psymtab_language, objfile);
2802 /* Skip over procedure to next one. */
2803 if (sh.index >= hdr->iauxMax)
2805 /* Should not happen, but does when cross-compiling
2806 with the MIPS compiler. FIXME -- pull later. */
2807 complain (&index_complaint, name);
2808 new_sdx = cur_sdx + 1; /* Don't skip at all */
2811 new_sdx = AUX_GET_ISYM (fh->fBigendian,
2812 (debug_info->external_aux
2815 procaddr = sh.value;
2817 if (new_sdx <= cur_sdx)
2819 /* This should not happen either... FIXME. */
2820 complain (&aux_index_complaint, name);
2821 new_sdx = cur_sdx + 1; /* Don't skip backward */
2825 (*swap_sym_in) (cur_bfd,
2826 ((char *) debug_info->external_sym
2827 + ((fh->isymBase + cur_sdx - 1)
2828 * external_sym_size)),
2833 /* Kludge for Irix 5.2 zero fh->adr. */
2835 && (pst->textlow == 0 || procaddr < pst->textlow))
2836 pst->textlow = procaddr;
2838 high = procaddr + sh.value;
2839 if (high > pst->texthigh)
2840 pst->texthigh = high;
2843 case stStatic: /* Variable */
2844 if (SC_IS_DATA (sh.sc))
2845 prim_record_minimal_symbol_and_info (name, sh.value,
2846 mst_file_data, NULL,
2847 SECT_OFF_DATA (objfile),
2851 prim_record_minimal_symbol_and_info (name, sh.value,
2853 SECT_OFF_BSS (objfile),
2859 case stIndirect: /* Irix5 forward declaration */
2860 /* Skip forward declarations from Irix5 cc */
2863 case stTypedef: /* Typedef */
2864 /* Skip typedefs for forward declarations and opaque
2865 structs from alpha and mips cc. */
2866 if (sh.iss == 0 || has_opaque_xref (fh, &sh))
2868 class = LOC_TYPEDEF;
2871 case stConstant: /* Constant decl */
2878 case stBlock: /* { }, str, un, enum */
2879 /* Do not create a partial symbol for cc unnamed aggregates
2880 and gcc empty aggregates. */
2881 if ((sh.sc == scInfo
2882 || SC_IS_COMMON (sh.sc))
2884 && sh.index != cur_sdx + 2)
2886 add_psymbol_to_list (name, strlen (name),
2887 STRUCT_NAMESPACE, LOC_TYPEDEF,
2888 &objfile->static_psymbols,
2890 psymtab_language, objfile);
2892 handle_psymbol_enumerators (objfile, fh, sh.st, sh.value);
2894 /* Skip over the block */
2896 if (new_sdx <= cur_sdx)
2898 /* This happens with the Ultrix kernel. */
2899 complain (&block_index_complaint, name);
2900 new_sdx = cur_sdx + 1; /* Don't skip backward */
2905 case stFile: /* File headers */
2906 case stLabel: /* Labels */
2907 case stEnd: /* Ends of files */
2910 case stLocal: /* Local variables */
2911 /* Normally these are skipped because we skip over
2912 all blocks we see. However, these can occur
2913 as visible symbols in a .h file that contains code. */
2917 /* Both complaints are valid: one gives symbol name,
2918 the other the offending symbol type. */
2919 complain (&unknown_sym_complaint, name);
2920 complain (&unknown_st_complaint, sh.st);
2924 /* Use this gdb symbol */
2925 add_psymbol_to_list (name, strlen (name),
2926 VAR_NAMESPACE, class,
2927 &objfile->static_psymbols,
2928 0, sh.value, psymtab_language, objfile);
2930 cur_sdx++; /* Go to next file symbol */
2933 /* Now do enter the external symbols. */
2934 ext_ptr = &extern_tab[fdr_to_pst[f_idx].globals_offset];
2935 cur_sdx = fdr_to_pst[f_idx].n_globals;
2936 PST_PRIVATE (save_pst)->extern_count = cur_sdx;
2937 PST_PRIVATE (save_pst)->extern_tab = ext_ptr;
2938 for (; --cur_sdx >= 0; ext_ptr++)
2940 enum address_class class;
2945 if (ext_ptr->ifd != f_idx)
2947 psh = &ext_ptr->asym;
2949 /* Do not add undefined symbols to the partial symbol table. */
2950 if (SC_IS_UNDEF (psh->sc) || psh->sc == scNil)
2953 svalue = psh->value;
2958 svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
2965 svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
2969 svalue += ANOFFSET (objfile->section_offsets, SECT_OFF_BSS (objfile));
2976 /* These are generated for static symbols in .o files,
2981 /* External procedure symbols have been entered
2982 into the minimal symbol table in pass 2 above.
2983 Ignore them, as parse_external will ignore them too. */
2989 complain (&unknown_ext_complaint,
2990 debug_info->ssext + psh->iss);
2991 /* Fall through, pretend it's global. */
2993 /* Global common symbols are resolved by the runtime loader,
2995 if (SC_IS_COMMON (psh->sc))
3001 name = debug_info->ssext + psh->iss;
3002 add_psymbol_to_list (name, strlen (name),
3003 VAR_NAMESPACE, class,
3004 &objfile->global_psymbols,
3006 psymtab_language, objfile);
3010 /* Link pst to FDR. end_psymtab returns NULL if the psymtab was
3011 empty and put on the free list. */
3012 fdr_to_pst[f_idx].pst = end_psymtab (save_pst,
3013 psymtab_include_list, includes_used,
3014 -1, save_pst->texthigh,
3015 dependency_list, dependencies_used, textlow_not_set);
3017 dependencies_used = 0;
3019 if (objfile->ei.entry_point >= save_pst->textlow &&
3020 objfile->ei.entry_point < save_pst->texthigh)
3022 objfile->ei.entry_file_lowpc = save_pst->textlow;
3023 objfile->ei.entry_file_highpc = save_pst->texthigh;
3026 /* The objfile has its functions reordered if this partial symbol
3027 table overlaps any other partial symbol table.
3028 We cannot assume a reordered objfile if a partial symbol table
3029 is contained within another partial symbol table, as partial symbol
3030 tables for include files with executable code are contained
3031 within the partial symbol table for the including source file,
3032 and we do not want to flag the objfile reordered for these cases.
3034 This strategy works well for Irix-5.2 shared libraries, but we
3035 might have to use a more elaborate (and slower) algorithm for
3037 save_pst = fdr_to_pst[f_idx].pst;
3038 if (save_pst != NULL
3039 && save_pst->textlow != 0
3040 && !(objfile->flags & OBJF_REORDERED))
3042 ALL_OBJFILE_PSYMTABS (objfile, pst)
3045 && save_pst->textlow >= pst->textlow
3046 && save_pst->textlow < pst->texthigh
3047 && save_pst->texthigh > pst->texthigh)
3049 objfile->flags |= OBJF_REORDERED;
3056 /* Now scan the FDRs for dependencies */
3057 for (f_idx = 0; f_idx < hdr->ifdMax; f_idx++)
3059 fh = f_idx + debug_info->fdr;
3060 pst = fdr_to_pst[f_idx].pst;
3062 if (pst == (struct partial_symtab *) NULL)
3065 /* This should catch stabs-in-ecoff. */
3069 /* Skip the first file indirect entry as it is a self dependency
3070 for source files or a reverse .h -> .c dependency for header files. */
3071 pst->number_of_dependencies = 0;
3073 ((struct partial_symtab **)
3074 obstack_alloc (&objfile->psymbol_obstack,
3076 * sizeof (struct partial_symtab *))));
3077 for (s_idx = 1; s_idx < fh->crfd; s_idx++)
3081 (*swap_rfd_in) (cur_bfd,
3082 ((char *) debug_info->external_rfd
3083 + (fh->rfdBase + s_idx) * external_rfd_size),
3085 if (rh < 0 || rh >= hdr->ifdMax)
3087 complain (&bad_file_number_complaint, rh);
3091 /* Skip self dependencies of header files. */
3095 /* Do not add to dependeny list if psymtab was empty. */
3096 if (fdr_to_pst[rh].pst == (struct partial_symtab *) NULL)
3098 pst->dependencies[pst->number_of_dependencies++] = fdr_to_pst[rh].pst;
3102 /* Remove the dummy psymtab created for -O3 images above, if it is
3103 still empty, to enable the detection of stripped executables. */
3104 if (objfile->psymtabs->next == NULL
3105 && objfile->psymtabs->number_of_dependencies == 0
3106 && objfile->psymtabs->n_global_syms == 0
3107 && objfile->psymtabs->n_static_syms == 0)
3108 objfile->psymtabs = NULL;
3109 do_cleanups (old_chain);
3112 /* If the current psymbol has an enumerated type, we need to add
3113 all the the enum constants to the partial symbol table. */
3116 handle_psymbol_enumerators (struct objfile *objfile, FDR *fh, int stype,
3119 const bfd_size_type external_sym_size = debug_swap->external_sym_size;
3120 void (*const swap_sym_in) (bfd *, PTR, SYMR *) = debug_swap->swap_sym_in;
3121 char *ext_sym = ((char *) debug_info->external_sym
3122 + ((fh->isymBase + cur_sdx + 1) * external_sym_size));
3132 /* It is an enumerated type if the next symbol entry is a stMember
3133 and its auxiliary index is indexNil or its auxiliary entry
3134 is a plain btNil or btVoid.
3135 Alpha cc -migrate enums are recognized by a zero index and
3136 a zero symbol value.
3137 DU 4.0 cc enums are recognized by a member type of btEnum without
3138 qualifiers and a zero symbol value. */
3139 (*swap_sym_in) (cur_bfd, ext_sym, &sh);
3140 if (sh.st != stMember)
3143 if (sh.index == indexNil
3144 || (sh.index == 0 && svalue == 0))
3146 (*debug_swap->swap_tir_in) (fh->fBigendian,
3147 &(debug_info->external_aux
3148 + fh->iauxBase + sh.index)->a_ti,
3150 if ((tir.bt != btNil
3152 && (tir.bt != btEnum || svalue != 0))
3153 || tir.tq0 != tqNil)
3165 (*swap_sym_in) (cur_bfd, ext_sym, &sh);
3166 if (sh.st != stMember)
3168 name = debug_info->ss + cur_fdr->issBase + sh.iss;
3170 /* Note that the value doesn't matter for enum constants
3171 in psymtabs, just in symtabs. */
3172 add_psymbol_to_list (name, strlen (name),
3173 VAR_NAMESPACE, LOC_CONST,
3174 &objfile->static_psymbols, 0,
3175 (CORE_ADDR) 0, psymtab_language, objfile);
3176 ext_sym += external_sym_size;
3180 /* Get the next symbol. OBJFILE is unused. */
3183 mdebug_next_symbol_text (struct objfile *objfile)
3188 (*debug_swap->swap_sym_in) (cur_bfd,
3189 ((char *) debug_info->external_sym
3190 + ((cur_fdr->isymBase + cur_sdx)
3191 * debug_swap->external_sym_size)),
3193 return debug_info->ss + cur_fdr->issBase + sh.iss;
3196 /* Ancillary function to psymtab_to_symtab(). Does all the work
3197 for turning the partial symtab PST into a symtab, recurring
3198 first on all dependent psymtabs. The argument FILENAME is
3199 only passed so we can see in debug stack traces what file
3202 This function has a split personality, based on whether the
3203 symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
3204 The flow of control and even the memory allocation differs. FIXME. */
3207 psymtab_to_symtab_1 (struct partial_symtab *pst, char *filename)
3209 bfd_size_type external_sym_size;
3210 bfd_size_type external_pdr_size;
3211 void (*swap_sym_in) (bfd *, PTR, SYMR *);
3212 void (*swap_pdr_in) (bfd *, PTR, PDR *);
3216 struct linetable *lines;
3217 CORE_ADDR lowest_pdr_addr = 0;
3223 /* Read in all partial symbtabs on which this one is dependent.
3224 NOTE that we do have circular dependencies, sigh. We solved
3225 that by setting pst->readin before this point. */
3227 for (i = 0; i < pst->number_of_dependencies; i++)
3228 if (!pst->dependencies[i]->readin)
3230 /* Inform about additional files to be read in. */
3233 fputs_filtered (" ", gdb_stdout);
3235 fputs_filtered ("and ", gdb_stdout);
3237 printf_filtered ("%s...",
3238 pst->dependencies[i]->filename);
3239 wrap_here (""); /* Flush output */
3240 gdb_flush (gdb_stdout);
3242 /* We only pass the filename for debug purposes */
3243 psymtab_to_symtab_1 (pst->dependencies[i],
3244 pst->dependencies[i]->filename);
3247 /* Do nothing if this is a dummy psymtab. */
3249 if (pst->n_global_syms == 0 && pst->n_static_syms == 0
3250 && pst->textlow == 0 && pst->texthigh == 0)
3253 /* Now read the symbols for this symtab */
3255 cur_bfd = CUR_BFD (pst);
3256 debug_swap = DEBUG_SWAP (pst);
3257 debug_info = DEBUG_INFO (pst);
3258 pending_list = PENDING_LIST (pst);
3259 external_sym_size = debug_swap->external_sym_size;
3260 external_pdr_size = debug_swap->external_pdr_size;
3261 swap_sym_in = debug_swap->swap_sym_in;
3262 swap_pdr_in = debug_swap->swap_pdr_in;
3263 current_objfile = pst->objfile;
3264 cur_fd = FDR_IDX (pst);
3265 fh = ((cur_fd == -1)
3267 : debug_info->fdr + cur_fd);
3270 /* See comment in parse_partial_symbols about the @stabs sentinel. */
3271 processing_gcc_compilation = 0;
3272 if (fh != (FDR *) NULL && fh->csym >= 2)
3276 (*swap_sym_in) (cur_bfd,
3277 ((char *) debug_info->external_sym
3278 + (fh->isymBase + 1) * external_sym_size),
3280 if (STREQ (debug_info->ss + fh->issBase + sh.iss,
3283 /* We indicate that this is a GCC compilation so that certain
3284 features will be enabled in stabsread/dbxread. */
3285 processing_gcc_compilation = 2;
3289 if (processing_gcc_compilation != 0)
3292 /* This symbol table contains stabs-in-ecoff entries. */
3294 /* Parse local symbols first */
3296 if (fh->csym <= 2) /* FIXME, this blows psymtab->symtab ptr */
3298 current_objfile = NULL;
3301 for (cur_sdx = 2; cur_sdx < fh->csym; cur_sdx++)
3307 (*swap_sym_in) (cur_bfd,
3308 (((char *) debug_info->external_sym)
3309 + (fh->isymBase + cur_sdx) * external_sym_size),
3311 name = debug_info->ss + fh->issBase + sh.iss;
3313 /* XXX This is a hack. It will go away! */
3314 if (ECOFF_IS_STAB (&sh) || (name[0] == '#'))
3316 int type_code = ECOFF_UNMARK_STAB (sh.index);
3318 /* We should never get non N_STAB symbols here, but they
3319 should be harmless, so keep process_one_symbol from
3320 complaining about them. */
3321 if (type_code & N_STAB)
3323 process_one_symbol (type_code, 0, valu, name,
3324 pst->section_offsets, pst->objfile);
3326 /* Similarly a hack. */
3327 else if (name[0] == '#')
3329 process_one_symbol (N_SLINE, 0, valu, name,
3330 pst->section_offsets, pst->objfile);
3332 if (type_code == N_FUN)
3334 /* Make up special symbol to contain
3335 procedure specific info */
3336 struct mips_extra_func_info *e =
3337 ((struct mips_extra_func_info *)
3338 obstack_alloc (¤t_objfile->symbol_obstack,
3339 sizeof (struct mips_extra_func_info)));
3340 struct symbol *s = new_symbol (MIPS_EFI_SYMBOL_NAME);
3342 memset ((PTR) e, 0, sizeof (struct mips_extra_func_info));
3343 SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
3344 SYMBOL_CLASS (s) = LOC_CONST;
3345 SYMBOL_TYPE (s) = mdebug_type_void;
3346 SYMBOL_VALUE (s) = (long) e;
3347 e->pdr.framereg = -1;
3348 add_symbol_to_list (s, &local_symbols);
3351 else if (sh.st == stLabel)
3353 if (sh.index == indexNil)
3355 /* This is what the gcc2_compiled and __gnu_compiled_*
3356 show up as. So don't complain. */
3361 /* Handle encoded stab line number. */
3362 valu += ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (pst->objfile));
3363 record_line (current_subfile, sh.index, valu);
3366 else if (sh.st == stProc || sh.st == stStaticProc
3367 || sh.st == stStatic || sh.st == stEnd)
3368 /* These are generated by gcc-2.x, do not complain */
3371 complain (&stab_unknown_complaint, name);
3373 st = end_symtab (pst->texthigh, pst->objfile, SECT_OFF_TEXT (pst->objfile));
3376 /* Sort the symbol table now, we are done adding symbols to it.
3377 We must do this before parse_procedure calls lookup_symbol. */
3378 sort_symtab_syms (st);
3380 /* There used to be a call to sort_blocks here, but this should not
3381 be necessary for stabs symtabs. And as sort_blocks modifies the
3382 start address of the GLOBAL_BLOCK to the FIRST_LOCAL_BLOCK,
3383 it did the wrong thing if the first procedure in a file was
3384 generated via asm statements. */
3386 /* Fill in procedure info next. */
3390 struct cleanup *old_chain;
3396 pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR));
3397 old_chain = make_cleanup (xfree, pr_block);
3399 pdr_ptr = ((char *) debug_info->external_pdr
3400 + fh->ipdFirst * external_pdr_size);
3401 pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
3405 pdr_ptr += external_pdr_size, pdr_in++)
3407 (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in);
3409 /* Determine lowest PDR address, the PDRs are not always
3411 if (pdr_in == pr_block)
3412 lowest_pdr_addr = pdr_in->adr;
3413 else if (pdr_in->adr < lowest_pdr_addr)
3414 lowest_pdr_addr = pdr_in->adr;
3418 pdr_in_end = pdr_in + fh->cpd;
3419 for (; pdr_in < pdr_in_end; pdr_in++)
3420 parse_procedure (pdr_in, st, pst);
3422 do_cleanups (old_chain);
3427 /* This symbol table contains ordinary ecoff entries. */
3433 /* How many symbols will we need */
3434 /* FIXME, this does not count enum values. */
3435 f_max = pst->n_global_syms + pst->n_static_syms;
3439 st = new_symtab ("unknown", f_max, 0, pst->objfile);
3443 f_max += fh->csym + fh->cpd;
3444 maxlines = 2 * fh->cline;
3445 st = new_symtab (pst->filename, 2 * f_max, maxlines, pst->objfile);
3447 /* The proper language was already determined when building
3448 the psymtab, use it. */
3449 st->language = PST_PRIVATE (pst)->pst_language;
3452 psymtab_language = st->language;
3454 lines = LINETABLE (st);
3456 /* Get a new lexical context */
3458 push_parse_stack ();
3459 top_stack->cur_st = st;
3460 top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (st),
3462 BLOCK_START (top_stack->cur_block) = pst->textlow;
3463 BLOCK_END (top_stack->cur_block) = 0;
3464 top_stack->blocktype = stFile;
3465 top_stack->maxsyms = 2 * f_max;
3466 top_stack->cur_type = 0;
3467 top_stack->procadr = 0;
3468 top_stack->numargs = 0;
3469 found_ecoff_debugging_info = 0;
3476 /* Parse local symbols first */
3477 sym_ptr = ((char *) debug_info->external_sym
3478 + fh->isymBase * external_sym_size);
3479 sym_end = sym_ptr + fh->csym * external_sym_size;
3480 while (sym_ptr < sym_end)
3485 (*swap_sym_in) (cur_bfd, sym_ptr, &sh);
3486 c = parse_symbol (&sh,
3487 debug_info->external_aux + fh->iauxBase,
3488 sym_ptr, fh->fBigendian, pst->section_offsets, pst->objfile);
3489 sym_ptr += c * external_sym_size;
3492 /* Linenumbers. At the end, check if we can save memory.
3493 parse_lines has to look ahead an arbitrary number of PDR
3494 structures, so we swap them all first. */
3498 struct cleanup *old_chain;
3504 pr_block = (PDR *) xmalloc (fh->cpd * sizeof (PDR));
3506 old_chain = make_cleanup (xfree, pr_block);
3508 pdr_ptr = ((char *) debug_info->external_pdr
3509 + fh->ipdFirst * external_pdr_size);
3510 pdr_end = pdr_ptr + fh->cpd * external_pdr_size;
3514 pdr_ptr += external_pdr_size, pdr_in++)
3516 (*swap_pdr_in) (cur_bfd, pdr_ptr, pdr_in);
3518 /* Determine lowest PDR address, the PDRs are not always
3520 if (pdr_in == pr_block)
3521 lowest_pdr_addr = pdr_in->adr;
3522 else if (pdr_in->adr < lowest_pdr_addr)
3523 lowest_pdr_addr = pdr_in->adr;
3526 parse_lines (fh, pr_block, lines, maxlines, pst, lowest_pdr_addr);
3527 if (lines->nitems < fh->cline)
3528 lines = shrink_linetable (lines);
3530 /* Fill in procedure info next. */
3532 pdr_in_end = pdr_in + fh->cpd;
3533 for (; pdr_in < pdr_in_end; pdr_in++)
3534 parse_procedure (pdr_in, 0, pst);
3536 do_cleanups (old_chain);
3540 LINETABLE (st) = lines;
3542 /* .. and our share of externals.
3543 XXX use the global list to speed up things here. how?
3544 FIXME, Maybe quit once we have found the right number of ext's? */
3545 top_stack->cur_st = st;
3546 top_stack->cur_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack->cur_st),
3548 top_stack->blocktype = stFile;
3550 = (debug_info->symbolic_header.isymMax
3551 + debug_info->symbolic_header.ipdMax
3552 + debug_info->symbolic_header.iextMax);
3554 ext_ptr = PST_PRIVATE (pst)->extern_tab;
3555 for (i = PST_PRIVATE (pst)->extern_count; --i >= 0; ext_ptr++)
3556 parse_external (ext_ptr, fh->fBigendian, pst->section_offsets, pst->objfile);
3558 /* If there are undefined symbols, tell the user.
3559 The alpha has an undefined symbol for every symbol that is
3560 from a shared library, so tell the user only if verbose is on. */
3561 if (info_verbose && n_undef_symbols)
3563 printf_filtered ("File %s contains %d unresolved references:",
3564 st->filename, n_undef_symbols);
3565 printf_filtered ("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
3566 n_undef_vars, n_undef_procs, n_undef_labels);
3567 n_undef_symbols = n_undef_labels = n_undef_vars = n_undef_procs = 0;
3574 /* Sort the symbol table now, we are done adding symbols to it. */
3575 sort_symtab_syms (st);
3580 /* Now link the psymtab and the symtab. */
3583 current_objfile = NULL;
3586 /* Ancillary parsing procedures. */
3588 /* Return 1 if the symbol pointed to by SH has a cross reference
3589 to an opaque aggregate type, else 0. */
3592 has_opaque_xref (FDR *fh, SYMR *sh)
3599 if (sh->index == indexNil)
3602 ax = debug_info->external_aux + fh->iauxBase + sh->index;
3603 (*debug_swap->swap_tir_in) (fh->fBigendian, &ax->a_ti, &tir);
3604 if (tir.bt != btStruct && tir.bt != btUnion && tir.bt != btEnum)
3608 (*debug_swap->swap_rndx_in) (fh->fBigendian, &ax->a_rndx, rn);
3609 if (rn->rfd == 0xfff)
3610 rf = AUX_GET_ISYM (fh->fBigendian, ax + 1);
3618 /* Lookup the type at relative index RN. Return it in TPP
3619 if found and in any event come up with its name PNAME.
3620 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
3621 Return value says how many aux symbols we ate. */
3624 cross_ref (int fd, union aux_ext *ax, struct type **tpp, enum type_code type_code, /* Use to alloc new type if none is found. */
3625 char **pname, int bigend, char *sym_name)
3634 struct mdebug_pending *pend;
3636 *tpp = (struct type *) NULL;
3638 (*debug_swap->swap_rndx_in) (bigend, &ax->a_rndx, rn);
3640 /* Escape index means 'the next one' */
3641 if (rn->rfd == 0xfff)
3644 rf = AUX_GET_ISYM (bigend, ax + 1);
3651 /* mips cc uses a rf of -1 for opaque struct definitions.
3652 Set TYPE_FLAG_STUB for these types so that check_typedef will
3653 resolve them if the struct gets defined in another compilation unit. */
3656 *pname = "<undefined>";
3657 *tpp = init_type (type_code, 0, 0, (char *) NULL, current_objfile);
3658 TYPE_FLAGS (*tpp) |= TYPE_FLAG_STUB;
3662 /* mips cc uses an escaped rn->index of 0 for struct return types
3663 of procedures that were compiled without -g. These will always remain
3665 if (rn->rfd == 0xfff && rn->index == 0)
3667 *pname = "<undefined>";
3671 /* Find the relative file descriptor and the symbol in it. */
3672 fh = get_rfd (fd, rf);
3673 xref_fd = fh - debug_info->fdr;
3675 if (rn->index >= fh->csym)
3677 /* File indirect entry is corrupt. */
3678 *pname = "<illegal>";
3679 complain (&bad_rfd_entry_complaint,
3680 sym_name, xref_fd, rn->index);
3684 /* If we have processed this symbol then we left a forwarding
3685 pointer to the type in the pending list. If not, we`ll put
3686 it in a list of pending types, to be processed later when
3687 the file will be. In any event, we collect the name for the
3690 esh = ((char *) debug_info->external_sym
3691 + ((fh->isymBase + rn->index)
3692 * debug_swap->external_sym_size));
3693 (*debug_swap->swap_sym_in) (cur_bfd, esh, &sh);
3695 /* Make sure that this type of cross reference can be handled. */
3696 if ((sh.sc != scInfo
3697 || (sh.st != stBlock && sh.st != stTypedef && sh.st != stIndirect
3698 && sh.st != stStruct && sh.st != stUnion
3699 && sh.st != stEnum))
3700 && (sh.st != stBlock || !SC_IS_COMMON (sh.sc)))
3702 /* File indirect entry is corrupt. */
3703 *pname = "<illegal>";
3704 complain (&bad_rfd_entry_complaint,
3705 sym_name, xref_fd, rn->index);
3709 *pname = debug_info->ss + fh->issBase + sh.iss;
3711 pend = is_pending_symbol (fh, esh);
3716 /* We have not yet seen this type. */
3718 if ((sh.iss == 0 && sh.st == stTypedef) || sh.st == stIndirect)
3722 /* alpha cc puts out a stTypedef with a sh.iss of zero for
3724 a) forward declarations of structs/unions/enums which are not
3725 defined in this compilation unit.
3726 For these the type will be void. This is a bad design decision
3727 as cross referencing across compilation units is impossible
3728 due to the missing name.
3729 b) forward declarations of structs/unions/enums/typedefs which
3730 are defined later in this file or in another file in the same
3731 compilation unit. Irix5 cc uses a stIndirect symbol for this.
3732 Simply cross reference those again to get the true type.
3733 The forward references are not entered in the pending list and
3734 in the symbol table. */
3736 (*debug_swap->swap_tir_in) (bigend,
3737 &(debug_info->external_aux
3738 + fh->iauxBase + sh.index)->a_ti,
3740 if (tir.tq0 != tqNil)
3741 complain (&illegal_forward_tq0_complaint, sym_name);
3745 *tpp = init_type (type_code, 0, 0, (char *) NULL,
3747 *pname = "<undefined>";
3754 (debug_info->external_aux
3755 + fh->iauxBase + sh.index + 1),
3756 tpp, type_code, pname,
3757 fh->fBigendian, sym_name);
3761 /* Follow a forward typedef. This might recursively
3762 call cross_ref till we get a non typedef'ed type.
3763 FIXME: This is not correct behaviour, but gdb currently
3764 cannot handle typedefs without type copying. Type
3765 copying is impossible as we might have mutual forward
3766 references between two files and the copied type would not
3767 get filled in when we later parse its definition. */
3768 *tpp = parse_type (xref_fd,
3769 debug_info->external_aux + fh->iauxBase,
3773 debug_info->ss + fh->issBase + sh.iss);
3774 add_pending (fh, esh, *tpp);
3778 complain (&illegal_forward_bt_complaint, tir.bt, sym_name);
3779 *tpp = init_type (type_code, 0, 0, (char *) NULL,
3785 else if (sh.st == stTypedef)
3787 /* Parse the type for a normal typedef. This might recursively call
3788 cross_ref till we get a non typedef'ed type.
3789 FIXME: This is not correct behaviour, but gdb currently
3790 cannot handle typedefs without type copying. But type copying is
3791 impossible as we might have mutual forward references between
3792 two files and the copied type would not get filled in when
3793 we later parse its definition. */
3794 *tpp = parse_type (xref_fd,
3795 debug_info->external_aux + fh->iauxBase,
3799 debug_info->ss + fh->issBase + sh.iss);
3803 /* Cross reference to a struct/union/enum which is defined
3804 in another file in the same compilation unit but that file
3805 has not been parsed yet.
3806 Initialize the type only, it will be filled in when
3807 it's definition is parsed. */
3808 *tpp = init_type (type_code, 0, 0, (char *) NULL, current_objfile);
3810 add_pending (fh, esh, *tpp);
3813 /* We used one auxent normally, two if we got a "next one" rf. */
3818 /* Quick&dirty lookup procedure, to avoid the MI ones that require
3819 keeping the symtab sorted */
3821 static struct symbol *
3822 mylookup_symbol (char *name, register struct block *block,
3823 namespace_enum namespace, enum address_class class)
3825 register int bot, top, inc;
3826 register struct symbol *sym;
3829 top = BLOCK_NSYMS (block);
3833 sym = BLOCK_SYM (block, bot);
3834 if (SYMBOL_NAME (sym)[0] == inc
3835 && SYMBOL_NAMESPACE (sym) == namespace
3836 && SYMBOL_CLASS (sym) == class
3837 && strcmp (SYMBOL_NAME (sym), name) == 0)
3841 block = BLOCK_SUPERBLOCK (block);
3843 return mylookup_symbol (name, block, namespace, class);
3848 /* Add a new symbol S to a block B.
3849 Infrequently, we will need to reallocate the block to make it bigger.
3850 We only detect this case when adding to top_stack->cur_block, since
3851 that's the only time we know how big the block is. FIXME. */
3854 add_symbol (struct symbol *s, struct block *b)
3856 int nsyms = BLOCK_NSYMS (b)++;
3857 struct block *origb;
3858 struct parse_stack *stackp;
3860 if (b == top_stack->cur_block &&
3861 nsyms >= top_stack->maxsyms)
3863 complain (&block_overflow_complaint, SYMBOL_NAME (s));
3864 /* In this case shrink_block is actually grow_block, since
3865 BLOCK_NSYMS(b) is larger than its current size. */
3867 b = shrink_block (top_stack->cur_block, top_stack->cur_st);
3869 /* Now run through the stack replacing pointers to the
3870 original block. shrink_block has already done this
3871 for the blockvector and BLOCK_FUNCTION. */
3872 for (stackp = top_stack; stackp; stackp = stackp->next)
3874 if (stackp->cur_block == origb)
3876 stackp->cur_block = b;
3877 stackp->maxsyms = BLOCK_NSYMS (b);
3881 BLOCK_SYM (b, nsyms) = s;
3884 /* Add a new block B to a symtab S */
3887 add_block (struct block *b, struct symtab *s)
3889 struct blockvector *bv = BLOCKVECTOR (s);
3891 bv = (struct blockvector *) xrealloc ((PTR) bv,
3892 (sizeof (struct blockvector)
3893 + BLOCKVECTOR_NBLOCKS (bv)
3894 * sizeof (bv->block)));
3895 if (bv != BLOCKVECTOR (s))
3896 BLOCKVECTOR (s) = bv;
3898 BLOCKVECTOR_BLOCK (bv, BLOCKVECTOR_NBLOCKS (bv)++) = b;
3901 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
3902 MIPS' linenumber encoding might need more than one byte
3903 to describe it, LAST is used to detect these continuation lines.
3905 Combining lines with the same line number seems like a bad idea.
3906 E.g: There could be a line number entry with the same line number after the
3907 prologue and GDB should not ignore it (this is a better way to find
3908 a prologue than mips_skip_prologue).
3909 But due to the compressed line table format there are line number entries
3910 for the same line which are needed to bridge the gap to the next
3911 line number entry. These entries have a bogus address info with them
3912 and we are unable to tell them from intended duplicate line number
3914 This is another reason why -ggdb debugging format is preferable. */
3917 add_line (struct linetable *lt, int lineno, CORE_ADDR adr, int last)
3919 /* DEC c89 sometimes produces zero linenos which confuse gdb.
3920 Change them to something sensible. */
3924 last = -2; /* make sure we record first line */
3926 if (last == lineno) /* skip continuation lines */
3929 lt->item[lt->nitems].line = lineno;
3930 lt->item[lt->nitems++].pc = adr << 2;
3934 /* Sorting and reordering procedures */
3936 /* Blocks with a smaller low bound should come first */
3939 compare_blocks (const PTR arg1, const PTR arg2)
3941 register int addr_diff;
3942 struct block **b1 = (struct block **) arg1;
3943 struct block **b2 = (struct block **) arg2;
3945 addr_diff = (BLOCK_START ((*b1))) - (BLOCK_START ((*b2)));
3947 return (BLOCK_END ((*b2))) - (BLOCK_END ((*b1)));
3951 /* Sort the blocks of a symtab S.
3952 Reorder the blocks in the blockvector by code-address,
3953 as required by some MI search routines */
3956 sort_blocks (struct symtab *s)
3958 struct blockvector *bv = BLOCKVECTOR (s);
3960 if (BLOCKVECTOR_NBLOCKS (bv) <= 2)
3963 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) == 0)
3964 BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = 0;
3965 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) == 0)
3966 BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) = 0;
3970 * This is very unfortunate: normally all functions are compiled in
3971 * the order they are found, but if the file is compiled -O3 things
3972 * are very different. It would be nice to find a reliable test
3973 * to detect -O3 images in advance.
3975 if (BLOCKVECTOR_NBLOCKS (bv) > 3)
3976 qsort (&BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK),
3977 BLOCKVECTOR_NBLOCKS (bv) - FIRST_LOCAL_BLOCK,
3978 sizeof (struct block *),
3982 register CORE_ADDR high = 0;
3983 register int i, j = BLOCKVECTOR_NBLOCKS (bv);
3985 for (i = FIRST_LOCAL_BLOCK; i < j; i++)
3986 if (high < BLOCK_END (BLOCKVECTOR_BLOCK (bv, i)))
3987 high = BLOCK_END (BLOCKVECTOR_BLOCK (bv, i));
3988 BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) = high;
3991 BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)) =
3992 BLOCK_START (BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK));
3994 BLOCK_START (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
3995 BLOCK_START (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
3996 BLOCK_END (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
3997 BLOCK_END (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK));
4001 /* Constructor/restructor/destructor procedures */
4003 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
4004 MAXSYMS and linenumbers MAXLINES we'll put in it */
4006 static struct symtab *
4007 new_symtab (char *name, int maxsyms, int maxlines, struct objfile *objfile)
4009 struct symtab *s = allocate_symtab (name, objfile);
4011 LINETABLE (s) = new_linetable (maxlines);
4013 /* All symtabs must have at least two blocks */
4014 BLOCKVECTOR (s) = new_bvect (2);
4015 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK) = new_block (maxsyms);
4016 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK) = new_block (maxsyms);
4017 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK)) =
4018 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
4020 s->free_code = free_linetable;
4021 s->debugformat = obsavestring ("ECOFF", 5,
4022 &objfile->symbol_obstack);
4026 /* Allocate a new partial_symtab NAME */
4028 static struct partial_symtab *
4029 new_psymtab (char *name, struct objfile *objfile)
4031 struct partial_symtab *psymtab;
4033 psymtab = allocate_psymtab (name, objfile);
4034 psymtab->section_offsets = objfile->section_offsets;
4036 /* Keep a backpointer to the file's symbols */
4038 psymtab->read_symtab_private = ((char *)
4039 obstack_alloc (&objfile->psymbol_obstack,
4040 sizeof (struct symloc)));
4041 memset ((PTR) psymtab->read_symtab_private, 0, sizeof (struct symloc));
4042 CUR_BFD (psymtab) = cur_bfd;
4043 DEBUG_SWAP (psymtab) = debug_swap;
4044 DEBUG_INFO (psymtab) = debug_info;
4045 PENDING_LIST (psymtab) = pending_list;
4047 /* The way to turn this into a symtab is to call... */
4048 psymtab->read_symtab = mdebug_psymtab_to_symtab;
4053 /* Allocate a linetable array of the given SIZE. Since the struct
4054 already includes one item, we subtract one when calculating the
4055 proper size to allocate. */
4057 static struct linetable *
4058 new_linetable (int size)
4060 struct linetable *l;
4062 size = (size - 1) * sizeof (l->item) + sizeof (struct linetable);
4063 l = (struct linetable *) xmalloc (size);
4068 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
4069 I am not so sure about the 3.4 ones.
4071 Since the struct linetable already includes one item, we subtract one when
4072 calculating the proper size to allocate. */
4074 static struct linetable *
4075 shrink_linetable (struct linetable *lt)
4078 return (struct linetable *) xrealloc ((PTR) lt,
4079 (sizeof (struct linetable)
4081 * sizeof (lt->item))));
4084 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
4086 static struct blockvector *
4087 new_bvect (int nblocks)
4089 struct blockvector *bv;
4092 size = sizeof (struct blockvector) + nblocks * sizeof (struct block *);
4093 bv = (struct blockvector *) xzalloc (size);
4095 BLOCKVECTOR_NBLOCKS (bv) = nblocks;
4100 /* Allocate and zero a new block of MAXSYMS symbols */
4102 static struct block *
4103 new_block (int maxsyms)
4105 int size = sizeof (struct block) + (maxsyms - 1) * sizeof (struct symbol *);
4107 return (struct block *) xzalloc (size);
4110 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
4111 Shrink_block can also be used by add_symbol to grow a block. */
4113 static struct block *
4114 shrink_block (struct block *b, struct symtab *s)
4117 struct blockvector *bv = BLOCKVECTOR (s);
4120 /* Just reallocate it and fix references to the old one */
4122 new = (struct block *) xrealloc ((PTR) b,
4123 (sizeof (struct block)
4124 + ((BLOCK_NSYMS (b) - 1)
4125 * sizeof (struct symbol *))));
4127 /* Should chase pointers to old one. Fortunately, that`s just
4128 the block`s function and inferior blocks */
4129 if (BLOCK_FUNCTION (new) && SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) == b)
4130 SYMBOL_BLOCK_VALUE (BLOCK_FUNCTION (new)) = new;
4131 for (i = 0; i < BLOCKVECTOR_NBLOCKS (bv); i++)
4132 if (BLOCKVECTOR_BLOCK (bv, i) == b)
4133 BLOCKVECTOR_BLOCK (bv, i) = new;
4134 else if (BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) == b)
4135 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, i)) = new;
4139 /* Create a new symbol with printname NAME */
4141 static struct symbol *
4142 new_symbol (char *name)
4144 struct symbol *s = ((struct symbol *)
4145 obstack_alloc (¤t_objfile->symbol_obstack,
4146 sizeof (struct symbol)));
4148 memset ((PTR) s, 0, sizeof (*s));
4149 SYMBOL_NAME (s) = obsavestring (name, strlen (name),
4150 ¤t_objfile->symbol_obstack);
4151 SYMBOL_LANGUAGE (s) = psymtab_language;
4152 SYMBOL_INIT_DEMANGLED_NAME (s, ¤t_objfile->symbol_obstack);
4156 /* Create a new type with printname NAME */
4158 static struct type *
4159 new_type (char *name)
4163 t = alloc_type (current_objfile);
4164 TYPE_NAME (t) = name;
4165 TYPE_CPLUS_SPECIFIC (t) = (struct cplus_struct_type *) &cplus_struct_default;
4169 /* Read ECOFF debugging information from a BFD section. This is
4170 called from elfread.c. It parses the section into a
4171 ecoff_debug_info struct, and then lets the rest of the file handle
4175 elfmdebug_build_psymtabs (struct objfile *objfile,
4176 const struct ecoff_debug_swap *swap, asection *sec)
4178 bfd *abfd = objfile->obfd;
4179 struct ecoff_debug_info *info;
4181 info = ((struct ecoff_debug_info *)
4182 obstack_alloc (&objfile->psymbol_obstack,
4183 sizeof (struct ecoff_debug_info)));
4185 if (!(*swap->read_debug_info) (abfd, sec, info))
4186 error ("Error reading ECOFF debugging information: %s",
4187 bfd_errmsg (bfd_get_error ()));
4189 mdebug_build_psymtabs (objfile, swap, info);
4193 /* Things used for calling functions in the inferior.
4194 These functions are exported to our companion
4195 mips-tdep.c file and are here because they play
4196 with the symbol-table explicitly. */
4198 /* Sigtramp: make sure we have all the necessary information
4199 about the signal trampoline code. Since the official code
4200 from MIPS does not do so, we make up that information ourselves.
4201 If they fix the library (unlikely) this code will neutralize itself. */
4203 /* FIXME: This function is called only by mips-tdep.c. It needs to be
4204 here because it calls functions defined in this file, but perhaps
4205 this could be handled in a better way. Only compile it in when
4206 tm-mips.h is included. */
4211 fixup_sigtramp (void)
4215 struct block *b, *b0 = NULL;
4217 sigtramp_address = -1;
4219 /* We have to handle the following cases here:
4220 a) The Mips library has a sigtramp label within sigvec.
4221 b) Irix has a _sigtramp which we want to use, but it also has sigvec. */
4222 s = lookup_symbol ("sigvec", 0, VAR_NAMESPACE, 0, NULL);
4225 b0 = SYMBOL_BLOCK_VALUE (s);
4226 s = lookup_symbol ("sigtramp", b0, VAR_NAMESPACE, 0, NULL);
4230 /* No sigvec or no sigtramp inside sigvec, try _sigtramp. */
4231 s = lookup_symbol ("_sigtramp", 0, VAR_NAMESPACE, 0, NULL);
4234 /* But maybe this program uses its own version of sigvec */
4238 /* Did we or MIPSco fix the library ? */
4239 if (SYMBOL_CLASS (s) == LOC_BLOCK)
4241 sigtramp_address = BLOCK_START (SYMBOL_BLOCK_VALUE (s));
4242 sigtramp_end = BLOCK_END (SYMBOL_BLOCK_VALUE (s));
4246 sigtramp_address = SYMBOL_VALUE (s);
4247 sigtramp_end = sigtramp_address + 0x88; /* black magic */
4249 /* But what symtab does it live in ? */
4250 st = find_pc_symtab (SYMBOL_VALUE (s));
4253 * Ok, there goes the fix: turn it into a procedure, with all the
4254 * needed info. Note we make it a nested procedure of sigvec,
4255 * which is the way the (assembly) code is actually written.
4257 SYMBOL_NAMESPACE (s) = VAR_NAMESPACE;
4258 SYMBOL_CLASS (s) = LOC_BLOCK;
4259 SYMBOL_TYPE (s) = init_type (TYPE_CODE_FUNC, 4, 0, (char *) NULL,
4261 TYPE_TARGET_TYPE (SYMBOL_TYPE (s)) = mdebug_type_void;
4263 /* Need a block to allocate MIPS_EFI_SYMBOL_NAME in */
4265 SYMBOL_BLOCK_VALUE (s) = b;
4266 BLOCK_START (b) = sigtramp_address;
4267 BLOCK_END (b) = sigtramp_end;
4268 BLOCK_FUNCTION (b) = s;
4269 BLOCK_SUPERBLOCK (b) = BLOCK_SUPERBLOCK (b0);
4273 /* Make a MIPS_EFI_SYMBOL_NAME entry for it */
4275 struct mips_extra_func_info *e =
4276 ((struct mips_extra_func_info *)
4277 xzalloc (sizeof (struct mips_extra_func_info)));
4279 e->numargs = 0; /* the kernel thinks otherwise */
4280 e->pdr.frameoffset = 32;
4281 e->pdr.framereg = SP_REGNUM;
4282 /* Note that setting pcreg is no longer strictly necessary as
4283 mips_frame_saved_pc is now aware of signal handler frames. */
4284 e->pdr.pcreg = PC_REGNUM;
4285 e->pdr.regmask = -2;
4286 /* Offset to saved r31, in the sigtramp case the saved registers
4287 are above the frame in the sigcontext.
4288 We have 4 alignment bytes, 12 bytes for onstack, mask and pc,
4289 32 * 4 bytes for the general registers, 12 bytes for mdhi, mdlo, ownedfp
4290 and 32 * 4 bytes for the floating point registers. */
4291 e->pdr.regoffset = 4 + 12 + 31 * 4;
4292 e->pdr.fregmask = -1;
4293 /* Offset to saved f30 (first saved *double* register). */
4294 e->pdr.fregoffset = 4 + 12 + 32 * 4 + 12 + 30 * 4;
4295 e->pdr.isym = (long) s;
4296 e->pdr.adr = sigtramp_address;
4298 current_objfile = st->objfile; /* Keep new_symbol happy */
4299 s = new_symbol (MIPS_EFI_SYMBOL_NAME);
4300 SYMBOL_VALUE (s) = (long) e;
4301 SYMBOL_NAMESPACE (s) = LABEL_NAMESPACE;
4302 SYMBOL_CLASS (s) = LOC_CONST;
4303 SYMBOL_TYPE (s) = mdebug_type_void;
4304 current_objfile = NULL;
4307 BLOCK_SYM (b, BLOCK_NSYMS (b)++) = s;
4310 #endif /* TM_MIPS_H */
4313 _initialize_mdebugread (void)
4316 init_type (TYPE_CODE_VOID, 1,
4318 "void", (struct objfile *) NULL);
4320 init_type (TYPE_CODE_INT, 1,
4322 "char", (struct objfile *) NULL);
4323 mdebug_type_unsigned_char =
4324 init_type (TYPE_CODE_INT, 1,
4326 "unsigned char", (struct objfile *) NULL);
4328 init_type (TYPE_CODE_INT, 2,
4330 "short", (struct objfile *) NULL);
4331 mdebug_type_unsigned_short =
4332 init_type (TYPE_CODE_INT, 2,
4334 "unsigned short", (struct objfile *) NULL);
4335 mdebug_type_int_32 =
4336 init_type (TYPE_CODE_INT, 4,
4338 "int", (struct objfile *) NULL);
4339 mdebug_type_unsigned_int_32 =
4340 init_type (TYPE_CODE_INT, 4,
4342 "unsigned int", (struct objfile *) NULL);
4343 mdebug_type_int_64 =
4344 init_type (TYPE_CODE_INT, 8,
4346 "int", (struct objfile *) NULL);
4347 mdebug_type_unsigned_int_64 =
4348 init_type (TYPE_CODE_INT, 8,
4350 "unsigned int", (struct objfile *) NULL);
4351 mdebug_type_long_32 =
4352 init_type (TYPE_CODE_INT, 4,
4354 "long", (struct objfile *) NULL);
4355 mdebug_type_unsigned_long_32 =
4356 init_type (TYPE_CODE_INT, 4,
4358 "unsigned long", (struct objfile *) NULL);
4359 mdebug_type_long_64 =
4360 init_type (TYPE_CODE_INT, 8,
4362 "long", (struct objfile *) NULL);
4363 mdebug_type_unsigned_long_64 =
4364 init_type (TYPE_CODE_INT, 8,
4366 "unsigned long", (struct objfile *) NULL);
4367 mdebug_type_long_long_64 =
4368 init_type (TYPE_CODE_INT, 8,
4370 "long long", (struct objfile *) NULL);
4371 mdebug_type_unsigned_long_long_64 =
4372 init_type (TYPE_CODE_INT, 8,
4374 "unsigned long long", (struct objfile *) NULL);
4375 mdebug_type_adr_32 =
4376 init_type (TYPE_CODE_PTR, 4,
4378 "adr_32", (struct objfile *) NULL);
4379 TYPE_TARGET_TYPE (mdebug_type_adr_32) = mdebug_type_void;
4380 mdebug_type_adr_64 =
4381 init_type (TYPE_CODE_PTR, 8,
4383 "adr_64", (struct objfile *) NULL);
4384 TYPE_TARGET_TYPE (mdebug_type_adr_64) = mdebug_type_void;
4386 init_type (TYPE_CODE_FLT, TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
4388 "float", (struct objfile *) NULL);
4389 mdebug_type_double =
4390 init_type (TYPE_CODE_FLT, TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
4392 "double", (struct objfile *) NULL);
4393 mdebug_type_complex =
4394 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_FLOAT_BIT / TARGET_CHAR_BIT,
4396 "complex", (struct objfile *) NULL);
4397 TYPE_TARGET_TYPE (mdebug_type_complex) = mdebug_type_float;
4398 mdebug_type_double_complex =
4399 init_type (TYPE_CODE_COMPLEX, 2 * TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
4401 "double complex", (struct objfile *) NULL);
4402 TYPE_TARGET_TYPE (mdebug_type_double_complex) = mdebug_type_double;
4404 /* Is a "string" the way btString means it the same as TYPE_CODE_STRING?
4406 mdebug_type_string =
4407 init_type (TYPE_CODE_STRING,
4408 TARGET_CHAR_BIT / TARGET_CHAR_BIT,
4410 (struct objfile *) NULL);
4412 /* We use TYPE_CODE_INT to print these as integers. Does this do any
4413 good? Would we be better off with TYPE_CODE_ERROR? Should
4414 TYPE_CODE_ERROR print things in hex if it knows the size? */
4415 mdebug_type_fixed_dec =
4416 init_type (TYPE_CODE_INT,
4417 TARGET_INT_BIT / TARGET_CHAR_BIT,
4419 (struct objfile *) NULL);
4421 mdebug_type_float_dec =
4422 init_type (TYPE_CODE_ERROR,
4423 TARGET_DOUBLE_BIT / TARGET_CHAR_BIT,
4424 0, "floating decimal",
4425 (struct objfile *) NULL);
4427 nodebug_func_symbol_type = init_type (TYPE_CODE_FUNC, 1, 0,
4428 "<function, no debug info>", NULL);
4429 TYPE_TARGET_TYPE (nodebug_func_symbol_type) = mdebug_type_int;
4430 nodebug_var_symbol_type =
4431 init_type (TYPE_CODE_INT, TARGET_INT_BIT / HOST_CHAR_BIT, 0,
4432 "<variable, no debug info>", NULL);