1 /* Read a symbol table in ECOFF format (Third-Eye).
3 Copyright (C) 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
4 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007, 2008
5 Free Software Foundation, Inc.
7 Original version contributed by Alessandro Forin (af@cs.cmu.edu) at
8 CMU. Major work by Per Bothner, John Gilmore and Ian Lance Taylor
11 This file is part of GDB.
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 3 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 /* This module provides the function mdebug_build_psymtabs. It reads
27 ECOFF debugging information into partial symbol tables. The
28 debugging information is read from two structures. A struct
29 ecoff_debug_swap includes the sizes of each ECOFF structure and
30 swapping routines; these are fixed for a particular target. A
31 struct ecoff_debug_info points to the debugging information for a
32 particular object file.
34 ECOFF symbol tables are mostly written in the byte order of the
35 target machine. However, one section of the table (the auxiliary
36 symbol information) is written in the host byte order. There is a
37 bit in the other symbol info which describes which host byte order
38 was used. ECOFF thereby takes the trophy from Intel `b.out' for
39 the most brain-dead adaptation of a file format to byte order.
41 This module can read all four of the known byte-order combinations,
42 on any type of host. */
49 #include "gdb_obstack.h"
51 #include "stabsread.h"
52 #include "complaints.h"
54 #include "gdb_assert.h"
56 #include "dictionary.h"
57 #include "mdebugread.h"
59 #include "gdb_string.h"
63 #include "coff/ecoff.h" /* COFF-like aspects of ecoff files */
65 #include "libaout.h" /* Private BFD a.out information. */
66 #include "aout/aout64.h"
67 #include "aout/stab_gnu.h" /* STABS information */
69 #include "expression.h"
71 extern void _initialize_mdebugread (void);
73 /* Provide a way to test if we have both ECOFF and ELF symbol tables.
74 We use this define in order to know whether we should override a
75 symbol's ECOFF section with its ELF section. This is necessary in
76 case the symbol's ELF section could not be represented in ECOFF. */
77 #define ECOFF_IN_ELF(bfd) (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
78 && bfd_get_section_by_name (bfd, ".mdebug") != NULL)
81 /* We put a pointer to this structure in the read_symtab_private field
86 /* Index of the FDR that this psymtab represents. */
88 /* The BFD that the psymtab was created from. */
90 const struct ecoff_debug_swap
*debug_swap
;
91 struct ecoff_debug_info
*debug_info
;
92 struct mdebug_pending
**pending_list
;
93 /* Pointer to external symbols for this file. */
95 /* Size of extern_tab. */
97 enum language pst_language
;
100 #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
101 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
102 #define CUR_BFD(p) (PST_PRIVATE(p)->cur_bfd)
103 #define DEBUG_SWAP(p) (PST_PRIVATE(p)->debug_swap)
104 #define DEBUG_INFO(p) (PST_PRIVATE(p)->debug_info)
105 #define PENDING_LIST(p) (PST_PRIVATE(p)->pending_list)
107 #define SC_IS_TEXT(sc) ((sc) == scText \
108 || (sc) == scRConst \
111 #define SC_IS_DATA(sc) ((sc) == scData \
116 #define SC_IS_COMMON(sc) ((sc) == scCommon || (sc) == scSCommon)
117 #define SC_IS_BSS(sc) ((sc) == scBss)
118 #define SC_IS_SBSS(sc) ((sc) == scSBss)
119 #define SC_IS_UNDEF(sc) ((sc) == scUndefined || (sc) == scSUndefined)
121 /* Various complaints about symbol reading that don't abort the process */
123 index_complaint (const char *arg1
)
125 complaint (&symfile_complaints
, _("bad aux index at symbol %s"), arg1
);
129 unknown_ext_complaint (const char *arg1
)
131 complaint (&symfile_complaints
, _("unknown external symbol %s"), arg1
);
135 basic_type_complaint (int arg1
, const char *arg2
)
137 complaint (&symfile_complaints
, _("cannot map ECOFF basic type 0x%x for %s"),
142 bad_tag_guess_complaint (const char *arg1
)
144 complaint (&symfile_complaints
, _("guessed tag type of %s incorrectly"), arg1
);
148 bad_rfd_entry_complaint (const char *arg1
, int arg2
, int arg3
)
150 complaint (&symfile_complaints
, _("bad rfd entry for %s: file %d, index %d"),
155 unexpected_type_code_complaint (const char *arg1
)
157 complaint (&symfile_complaints
, _("unexpected type code for %s"), arg1
);
160 /* Macros and extra defs */
162 /* Puns: hard to find whether -g was used and how */
164 #define MIN_GLEVEL GLEVEL_0
165 #define compare_glevel(a,b) \
166 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
167 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
169 /* Things that really are local to this module */
171 /* Remember what we deduced to be the source language of this psymtab. */
173 static enum language psymtab_language
= language_unknown
;
179 /* How to parse debugging information for CUR_BFD. */
181 static const struct ecoff_debug_swap
*debug_swap
;
183 /* Pointers to debugging information for CUR_BFD. */
185 static struct ecoff_debug_info
*debug_info
;
187 /* Pointer to current file decriptor record, and its index */
192 /* Index of current symbol */
196 /* Note how much "debuggable" this image is. We would like
197 to see at least one FDR with full symbols */
199 static int max_gdbinfo
;
200 static int max_glevel
;
202 /* When examining .o files, report on undefined symbols */
204 static int n_undef_symbols
, n_undef_labels
, n_undef_vars
, n_undef_procs
;
206 /* Pseudo symbol to use when putting stabs into the symbol table. */
208 static char stabs_symbol
[] = STABS_SYMBOL
;
210 /* Types corresponding to mdebug format bt* basic types. */
212 static struct type
*mdebug_type_void
;
213 static struct type
*mdebug_type_char
;
214 static struct type
*mdebug_type_short
;
215 static struct type
*mdebug_type_int_32
;
216 #define mdebug_type_int mdebug_type_int_32
217 static struct type
*mdebug_type_int_64
;
218 static struct type
*mdebug_type_long_32
;
219 static struct type
*mdebug_type_long_64
;
220 static struct type
*mdebug_type_long_long_64
;
221 static struct type
*mdebug_type_unsigned_char
;
222 static struct type
*mdebug_type_unsigned_short
;
223 static struct type
*mdebug_type_unsigned_int_32
;
224 static struct type
*mdebug_type_unsigned_int_64
;
225 static struct type
*mdebug_type_unsigned_long_32
;
226 static struct type
*mdebug_type_unsigned_long_64
;
227 static struct type
*mdebug_type_unsigned_long_long_64
;
228 static struct type
*mdebug_type_adr_32
;
229 static struct type
*mdebug_type_adr_64
;
230 static struct type
*mdebug_type_float
;
231 static struct type
*mdebug_type_double
;
232 static struct type
*mdebug_type_complex
;
233 static struct type
*mdebug_type_double_complex
;
234 static struct type
*mdebug_type_fixed_dec
;
235 static struct type
*mdebug_type_float_dec
;
236 static struct type
*mdebug_type_string
;
238 /* Nonzero if we have seen ecoff debugging info for a file. */
240 static int found_ecoff_debugging_info
;
242 /* Forward declarations */
244 static int upgrade_type (int, struct type
**, int, union aux_ext
*,
247 static void parse_partial_symbols (struct objfile
*);
249 static int has_opaque_xref (FDR
*, SYMR
*);
251 static int cross_ref (int, union aux_ext
*, struct type
**, enum type_code
,
252 char **, int, char *);
254 static struct symbol
*new_symbol (char *);
256 static struct type
*new_type (char *);
258 enum block_type
{ FUNCTION_BLOCK
, NON_FUNCTION_BLOCK
};
260 static struct block
*new_block (enum block_type
);
262 static struct symtab
*new_symtab (char *, int, struct objfile
*);
264 static struct linetable
*new_linetable (int);
266 static struct blockvector
*new_bvect (int);
268 static struct type
*parse_type (int, union aux_ext
*, unsigned int, int *,
271 static struct symbol
*mylookup_symbol (char *, struct block
*, domain_enum
,
274 static void sort_blocks (struct symtab
*);
276 static struct partial_symtab
*new_psymtab (char *, struct objfile
*);
278 static void psymtab_to_symtab_1 (struct partial_symtab
*, char *);
280 static void add_block (struct block
*, struct symtab
*);
282 static void add_symbol (struct symbol
*, struct symtab
*, struct block
*);
284 static int add_line (struct linetable
*, int, CORE_ADDR
, int);
286 static struct linetable
*shrink_linetable (struct linetable
*);
288 static void handle_psymbol_enumerators (struct objfile
*, FDR
*, int,
291 static char *mdebug_next_symbol_text (struct objfile
*);
293 /* Exported procedure: Builds a symtab from the PST partial one.
294 Restores the environment in effect when PST was created, delegates
295 most of the work to an ancillary procedure, and sorts
296 and reorders the symtab list at the end */
299 mdebug_psymtab_to_symtab (struct partial_symtab
*pst
)
307 printf_filtered (_("Reading in symbols for %s..."), pst
->filename
);
308 gdb_flush (gdb_stdout
);
311 next_symbol_text_func
= mdebug_next_symbol_text
;
313 psymtab_to_symtab_1 (pst
, pst
->filename
);
315 /* Match with global symbols. This only needs to be done once,
316 after all of the symtabs and dependencies have been read in. */
317 scan_file_globals (pst
->objfile
);
320 printf_filtered (_("done.\n"));
323 /* File-level interface functions */
325 /* Find a file descriptor given its index RF relative to a file CF */
328 get_rfd (int cf
, int rf
)
334 fdrs
= debug_info
->fdr
;
336 /* Object files do not have the RFD table, all refs are absolute */
339 (*debug_swap
->swap_rfd_in
) (cur_bfd
,
340 ((char *) debug_info
->external_rfd
342 * debug_swap
->external_rfd_size
)),
347 /* Return a safer print NAME for a file descriptor */
353 return "<stripped file>";
356 return debug_info
->ss
+ f
->issBase
+ f
->rss
;
360 /* Read in and parse the symtab of the file OBJFILE. Symbols from
361 different sections are relocated via the SECTION_OFFSETS. */
364 mdebug_build_psymtabs (struct objfile
*objfile
,
365 const struct ecoff_debug_swap
*swap
,
366 struct ecoff_debug_info
*info
)
368 cur_bfd
= objfile
->obfd
;
372 stabsread_new_init ();
373 buildsym_new_init ();
374 free_header_files ();
375 init_header_files ();
377 /* Make sure all the FDR information is swapped in. */
378 if (info
->fdr
== (FDR
*) NULL
)
384 info
->fdr
= (FDR
*) obstack_alloc (&objfile
->objfile_obstack
,
385 (info
->symbolic_header
.ifdMax
387 fdr_src
= info
->external_fdr
;
389 + info
->symbolic_header
.ifdMax
* swap
->external_fdr_size
);
391 for (; fdr_src
< fdr_end
; fdr_src
+= swap
->external_fdr_size
, fdr_ptr
++)
392 (*swap
->swap_fdr_in
) (objfile
->obfd
, fdr_src
, fdr_ptr
);
395 parse_partial_symbols (objfile
);
398 /* Check to make sure file was compiled with -g. If not, warn the
399 user of this limitation. */
400 if (compare_glevel (max_glevel
, GLEVEL_2
) < 0)
402 if (max_gdbinfo
== 0)
403 printf_unfiltered (_("\n%s not compiled with -g, debugging support is limited.\n"),
405 printf_unfiltered (_("You should compile with -g2 or -g3 for best debugging support.\n"));
406 gdb_flush (gdb_stdout
);
411 /* Local utilities */
413 /* Map of FDR indexes to partial symtabs */
417 struct partial_symtab
*pst
; /* the psymtab proper */
418 long n_globals
; /* exported globals (external symbols) */
419 long globals_offset
; /* cumulative */
423 /* Utility stack, used to nest procedures and blocks properly.
424 It is a doubly linked list, to avoid too many alloc/free.
425 Since we might need it quite a few times it is NOT deallocated
428 static struct parse_stack
430 struct parse_stack
*next
, *prev
;
431 struct symtab
*cur_st
; /* Current symtab. */
432 struct block
*cur_block
; /* Block in it. */
434 /* What are we parsing. stFile, or stBlock are for files and
435 blocks. stProc or stStaticProc means we have seen the start of a
436 procedure, but not the start of the block within in. When we see
437 the start of that block, we change it to stNil, without pushing a
438 new block, i.e. stNil means both a procedure and a block. */
442 struct type
*cur_type
; /* Type we parse fields for. */
443 int cur_field
; /* Field number in cur_type. */
444 CORE_ADDR procadr
; /* Start addres of this procedure */
445 int numargs
; /* Its argument count */
448 *top_stack
; /* Top stack ptr */
451 /* Enter a new lexical context */
454 push_parse_stack (void)
456 struct parse_stack
*new;
458 /* Reuse frames if possible */
459 if (top_stack
&& top_stack
->prev
)
460 new = top_stack
->prev
;
462 new = (struct parse_stack
*) xzalloc (sizeof (struct parse_stack
));
463 /* Initialize new frame with previous content */
466 struct parse_stack
*prev
= new->prev
;
469 top_stack
->prev
= new;
471 new->next
= top_stack
;
476 /* Exit a lexical context */
479 pop_parse_stack (void)
484 top_stack
= top_stack
->next
;
488 /* Cross-references might be to things we haven't looked at
489 yet, e.g. type references. To avoid too many type
490 duplications we keep a quick fixup table, an array
491 of lists of references indexed by file descriptor */
493 struct mdebug_pending
495 struct mdebug_pending
*next
; /* link */
496 char *s
; /* the unswapped symbol */
497 struct type
*t
; /* its partial type descriptor */
501 /* The pending information is kept for an entire object file, and used
502 to be in the deprecated_sym_private field. I took it out when I
503 split mdebugread from mipsread, because this might not be the only
504 type of symbols read from an object file. Instead, we allocate the
505 pending information table when we create the partial symbols, and
506 we store a pointer to the single table in each psymtab. */
508 static struct mdebug_pending
**pending_list
;
510 /* Check whether we already saw symbol SH in file FH */
512 static struct mdebug_pending
*
513 is_pending_symbol (FDR
*fh
, char *sh
)
515 int f_idx
= fh
- debug_info
->fdr
;
516 struct mdebug_pending
*p
;
518 /* Linear search is ok, list is typically no more than 10 deep */
519 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
525 /* Add a new symbol SH of type T */
528 add_pending (FDR
*fh
, char *sh
, struct type
*t
)
530 int f_idx
= fh
- debug_info
->fdr
;
531 struct mdebug_pending
*p
= is_pending_symbol (fh
, sh
);
533 /* Make sure we do not make duplicates */
536 p
= ((struct mdebug_pending
*)
537 obstack_alloc (¤t_objfile
->objfile_obstack
,
538 sizeof (struct mdebug_pending
)));
541 p
->next
= pending_list
[f_idx
];
542 pending_list
[f_idx
] = p
;
547 /* Parsing Routines proper. */
549 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
550 For blocks, procedures and types we open a new lexical context.
551 This is basically just a big switch on the symbol's type. Argument
552 AX is the base pointer of aux symbols for this file (fh->iauxBase).
553 EXT_SH points to the unswapped symbol, which is needed for struct,
554 union, etc., types; it is NULL for an EXTR. BIGEND says whether
555 aux symbols are big-endian or little-endian. Return count of
556 SYMR's handled (normally one). */
559 parse_symbol (SYMR
*sh
, union aux_ext
*ax
, char *ext_sh
, int bigend
,
560 struct section_offsets
*section_offsets
, struct objfile
*objfile
)
562 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
563 const bfd_size_type external_sym_size
= debug_swap
->external_sym_size
;
564 void (*const swap_sym_in
) (bfd
*, void *, SYMR
*) = debug_swap
->swap_sym_in
;
568 struct mdebug_pending
*pend
;
572 enum address_class
class;
574 long svalue
= sh
->value
;
577 if (ext_sh
== (char *) NULL
)
578 name
= debug_info
->ssext
+ sh
->iss
;
580 name
= debug_info
->ss
+ cur_fdr
->issBase
+ sh
->iss
;
586 /* Do not relocate relative values.
587 The value of a stEnd symbol is the displacement from the
588 corresponding start symbol value.
589 The value of a stBlock symbol is the displacement from the
590 procedure address. */
591 if (sh
->st
!= stEnd
&& sh
->st
!= stBlock
)
592 sh
->value
+= ANOFFSET (section_offsets
, SECT_OFF_TEXT (objfile
));
599 sh
->value
+= ANOFFSET (section_offsets
, SECT_OFF_DATA (objfile
));
603 sh
->value
+= ANOFFSET (section_offsets
, SECT_OFF_BSS (objfile
));
612 case stGlobal
: /* external symbol, goes into global block */
614 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack
->cur_st
),
616 s
= new_symbol (name
);
617 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
620 case stStatic
: /* static data, goes into current block. */
622 b
= top_stack
->cur_block
;
623 s
= new_symbol (name
);
624 if (SC_IS_COMMON (sh
->sc
))
626 /* It is a FORTRAN common block. At least for SGI Fortran the
627 address is not in the symbol; we need to fix it later in
628 scan_file_globals. */
629 int bucket
= hashname (SYMBOL_LINKAGE_NAME (s
));
630 SYMBOL_VALUE_CHAIN (s
) = global_sym_chain
[bucket
];
631 global_sym_chain
[bucket
] = s
;
634 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
637 case stLocal
: /* local variable, goes into current block */
638 if (sh
->sc
== scRegister
)
640 class = LOC_REGISTER
;
641 svalue
= gdbarch_ecoff_reg_to_regnum (current_gdbarch
, svalue
);
645 b
= top_stack
->cur_block
;
646 s
= new_symbol (name
);
647 SYMBOL_VALUE (s
) = svalue
;
649 data
: /* Common code for symbols describing data */
650 SYMBOL_DOMAIN (s
) = VAR_DOMAIN
;
651 SYMBOL_CLASS (s
) = class;
652 add_symbol (s
, top_stack
->cur_st
, b
);
654 /* Type could be missing if file is compiled without debugging info. */
655 if (SC_IS_UNDEF (sh
->sc
)
656 || sh
->sc
== scNil
|| sh
->index
== indexNil
)
657 SYMBOL_TYPE (s
) = builtin_type (gdbarch
)->nodebug_data_symbol
;
659 SYMBOL_TYPE (s
) = parse_type (cur_fd
, ax
, sh
->index
, 0, bigend
, name
);
660 /* Value of a data symbol is its memory address */
663 case stParam
: /* arg to procedure, goes into current block */
665 found_ecoff_debugging_info
= 1;
666 top_stack
->numargs
++;
668 /* Special GNU C++ name. */
669 if (is_cplus_marker (name
[0]) && name
[1] == 't' && name
[2] == 0)
670 name
= "this"; /* FIXME, not alloc'd in obstack */
671 s
= new_symbol (name
);
673 SYMBOL_DOMAIN (s
) = VAR_DOMAIN
;
674 SYMBOL_IS_ARGUMENT (s
) = 1;
678 /* Pass by value in register. */
679 SYMBOL_CLASS (s
) = LOC_REGISTER
;
680 svalue
= gdbarch_ecoff_reg_to_regnum (current_gdbarch
, svalue
);
683 /* Pass by reference on stack. */
684 SYMBOL_CLASS (s
) = LOC_REF_ARG
;
687 /* Pass by reference in register. */
688 SYMBOL_CLASS (s
) = LOC_REGPARM_ADDR
;
689 svalue
= gdbarch_ecoff_reg_to_regnum (current_gdbarch
, svalue
);
692 /* Pass by value on stack. */
693 SYMBOL_CLASS (s
) = LOC_ARG
;
696 SYMBOL_VALUE (s
) = svalue
;
697 SYMBOL_TYPE (s
) = parse_type (cur_fd
, ax
, sh
->index
, 0, bigend
, name
);
698 add_symbol (s
, top_stack
->cur_st
, top_stack
->cur_block
);
701 case stLabel
: /* label, goes into current block */
702 s
= new_symbol (name
);
703 SYMBOL_DOMAIN (s
) = VAR_DOMAIN
; /* so that it can be used */
704 SYMBOL_CLASS (s
) = LOC_LABEL
; /* but not misused */
705 SYMBOL_VALUE_ADDRESS (s
) = (CORE_ADDR
) sh
->value
;
706 SYMBOL_TYPE (s
) = mdebug_type_int
;
707 add_symbol (s
, top_stack
->cur_st
, top_stack
->cur_block
);
710 case stProc
: /* Procedure, usually goes into global block */
711 case stStaticProc
: /* Static procedure, goes into current block */
712 /* For stProc symbol records, we need to check the storage class
713 as well, as only (stProc, scText) entries represent "real"
714 procedures - See the Compaq document titled "Object File /
715 Symbol Table Format Specification" for more information.
716 If the storage class is not scText, we discard the whole block
717 of symbol records for this stProc. */
718 if (sh
->st
== stProc
&& sh
->sc
!= scText
)
720 char *ext_tsym
= ext_sh
;
721 int keep_counting
= 1;
724 while (keep_counting
)
726 ext_tsym
+= external_sym_size
;
727 (*swap_sym_in
) (cur_bfd
, ext_tsym
, &tsym
);
737 complaint (&symfile_complaints
,
738 _("unknown symbol type 0x%x"), sh
->st
);
744 s
= new_symbol (name
);
745 SYMBOL_DOMAIN (s
) = VAR_DOMAIN
;
746 SYMBOL_CLASS (s
) = LOC_BLOCK
;
747 /* Type of the return value */
748 if (SC_IS_UNDEF (sh
->sc
) || sh
->sc
== scNil
)
752 t
= parse_type (cur_fd
, ax
, sh
->index
+ 1, 0, bigend
, name
);
753 if (strcmp (name
, "malloc") == 0
754 && TYPE_CODE (t
) == TYPE_CODE_VOID
)
756 /* I don't know why, but, at least under Alpha GNU/Linux,
757 when linking against a malloc without debugging
758 symbols, its read as a function returning void---this
759 is bad because it means we cannot call functions with
760 string arguments interactively; i.e., "call
761 printf("howdy\n")" would fail with the error message
762 "program has no memory available". To avoid this, we
763 patch up the type and make it void*
764 instead. (davidm@azstarnet.com)
766 t
= make_pointer_type (t
, NULL
);
769 b
= top_stack
->cur_block
;
770 if (sh
->st
== stProc
)
772 struct blockvector
*bv
= BLOCKVECTOR (top_stack
->cur_st
);
773 /* The next test should normally be true, but provides a
774 hook for nested functions (which we don't want to make
776 if (b
== BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
))
777 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
778 /* Irix 5 sometimes has duplicate names for the same
779 function. We want to add such names up at the global
780 level, not as a nested function. */
781 else if (sh
->value
== top_stack
->procadr
)
782 b
= BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
);
784 add_symbol (s
, top_stack
->cur_st
, b
);
786 /* Make a type for the procedure itself */
787 SYMBOL_TYPE (s
) = lookup_function_type (t
);
789 /* All functions in C++ have prototypes. For C we don't have enough
790 information in the debug info. */
791 if (SYMBOL_LANGUAGE (s
) == language_cplus
)
792 TYPE_PROTOTYPED (SYMBOL_TYPE (s
)) = 1;
794 /* Create and enter a new lexical context */
795 b
= new_block (FUNCTION_BLOCK
);
796 SYMBOL_BLOCK_VALUE (s
) = b
;
797 BLOCK_FUNCTION (b
) = s
;
798 BLOCK_START (b
) = BLOCK_END (b
) = sh
->value
;
799 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
800 add_block (b
, top_stack
->cur_st
);
802 /* Not if we only have partial info */
803 if (SC_IS_UNDEF (sh
->sc
) || sh
->sc
== scNil
)
807 top_stack
->cur_block
= b
;
808 top_stack
->blocktype
= sh
->st
;
809 top_stack
->cur_type
= SYMBOL_TYPE (s
);
810 top_stack
->cur_field
= -1;
811 top_stack
->procadr
= sh
->value
;
812 top_stack
->numargs
= 0;
815 /* Beginning of code for structure, union, and enum definitions.
816 They all share a common set of local variables, defined here. */
818 enum type_code type_code
;
824 case stStruct
: /* Start a block defining a struct type */
825 type_code
= TYPE_CODE_STRUCT
;
826 goto structured_common
;
828 case stUnion
: /* Start a block defining a union type */
829 type_code
= TYPE_CODE_UNION
;
830 goto structured_common
;
832 case stEnum
: /* Start a block defining an enum type */
833 type_code
= TYPE_CODE_ENUM
;
834 goto structured_common
;
836 case stBlock
: /* Either a lexical block, or some type */
837 if (sh
->sc
!= scInfo
&& !SC_IS_COMMON (sh
->sc
))
838 goto case_stBlock_code
; /* Lexical block */
840 type_code
= TYPE_CODE_UNDEF
; /* We have a type. */
842 /* Common code for handling struct, union, enum, and/or as-yet-
843 unknown-type blocks of info about structured data. `type_code'
844 has been set to the proper TYPE_CODE, if we know it. */
846 found_ecoff_debugging_info
= 1;
848 top_stack
->blocktype
= stBlock
;
850 /* First count the number of fields and the highest value. */
853 for (ext_tsym
= ext_sh
+ external_sym_size
;
855 ext_tsym
+= external_sym_size
)
859 (*swap_sym_in
) (cur_bfd
, ext_tsym
, &tsym
);
864 /* C++ encodes class types as structures where there the
865 methods are encoded as stProc. The scope of stProc
866 symbols also ends with stEnd, thus creating a risk of
867 taking the wrong stEnd symbol record as the end of
868 the current struct, which would cause GDB to undercount
869 the real number of fields in this struct. To make sure
870 we really reached the right stEnd symbol record, we
871 check the associated name, and match it against the
872 struct name. Since method names are mangled while
873 the class name is not, there is no risk of having a
874 method whose name is identical to the class name
875 (in particular constructor method names are different
876 from the class name). There is therefore no risk that
877 this check stops the count on the StEnd of a method.
879 Also, assume that we're really at the end when tsym.iss
881 if (tsym
.iss
== issNull
882 || strcmp (debug_info
->ss
+ cur_fdr
->issBase
+ tsym
.iss
,
888 if (nfields
== 0 && type_code
== TYPE_CODE_UNDEF
)
890 /* If the type of the member is Nil (or Void),
891 without qualifiers, assume the tag is an
893 Alpha cc -migrate enums are recognized by a zero
894 index and a zero symbol value.
895 DU 4.0 cc enums are recognized by a member type of
896 btEnum without qualifiers and a zero symbol value. */
897 if (tsym
.index
== indexNil
898 || (tsym
.index
== 0 && sh
->value
== 0))
899 type_code
= TYPE_CODE_ENUM
;
902 (*debug_swap
->swap_tir_in
) (bigend
,
903 &ax
[tsym
.index
].a_ti
,
905 if ((tir
.bt
== btNil
|| tir
.bt
== btVoid
906 || (tir
.bt
== btEnum
&& sh
->value
== 0))
908 type_code
= TYPE_CODE_ENUM
;
912 if (tsym
.value
> max_value
)
913 max_value
= tsym
.value
;
922 /* This is a no-op; is it trying to tell us something
923 we should be checking? */
924 if (tsym
.sc
== scVariant
); /*UNIMPLEMENTED */
928 /* This is something like a struct within a
929 struct. Skip over the fields of the inner
930 struct. The -1 is because the for loop will
931 increment ext_tsym. */
932 ext_tsym
= ((char *) debug_info
->external_sym
933 + ((cur_fdr
->isymBase
+ tsym
.index
- 1)
934 * external_sym_size
));
940 /* mips cc puts out a typedef for struct x if it is not yet
941 defined when it encounters
942 struct y { struct x *xp; };
947 /* Irix5 cc puts out a stIndirect for struct x if it is not
948 yet defined when it encounters
949 struct y { struct x *xp; };
954 complaint (&symfile_complaints
,
955 _("declaration block contains unhandled symbol type %d"),
961 /* In an stBlock, there is no way to distinguish structs,
962 unions, and enums at this point. This is a bug in the
963 original design (that has been fixed with the recent
964 addition of the stStruct, stUnion, and stEnum symbol
965 types.) The way you can tell is if/when you see a variable
966 or field of that type. In that case the variable's type
967 (in the AUX table) says if the type is struct, union, or
968 enum, and points back to the stBlock here. So you can
969 patch the tag kind up later - but only if there actually is
970 a variable or field of that type.
972 So until we know for sure, we will guess at this point.
974 If the first member has index==indexNil or a void type,
975 assume we have an enumeration.
976 Otherwise, if there is more than one member, and all
977 the members have offset 0, assume we have a union.
978 Otherwise, assume we have a struct.
980 The heuristic could guess wrong in the case of of an
981 enumeration with no members or a union with one (or zero)
982 members, or when all except the last field of a struct have
983 width zero. These are uncommon and/or illegal situations,
984 and in any case guessing wrong probably doesn't matter
987 But if we later do find out we were wrong, we fixup the tag
988 kind. Members of an enumeration must be handled
989 differently from struct/union fields, and that is harder to
990 patch up, but luckily we shouldn't need to. (If there are
991 any enumeration members, we can tell for sure it's an enum
994 if (type_code
== TYPE_CODE_UNDEF
)
996 if (nfields
> 1 && max_value
== 0)
997 type_code
= TYPE_CODE_UNION
;
999 type_code
= TYPE_CODE_STRUCT
;
1002 /* Create a new type or use the pending type. */
1003 pend
= is_pending_symbol (cur_fdr
, ext_sh
);
1004 if (pend
== (struct mdebug_pending
*) NULL
)
1006 t
= new_type (NULL
);
1007 add_pending (cur_fdr
, ext_sh
, t
);
1012 /* Do not set the tag name if it is a compiler generated tag name
1013 (.Fxx or .xxfake or empty) for unnamed struct/union/enums.
1014 Alpha cc puts out an sh->iss of zero for those. */
1015 if (sh
->iss
== 0 || name
[0] == '.' || name
[0] == '\0')
1016 TYPE_TAG_NAME (t
) = NULL
;
1018 TYPE_TAG_NAME (t
) = obconcat (¤t_objfile
->objfile_obstack
,
1021 TYPE_CODE (t
) = type_code
;
1022 TYPE_LENGTH (t
) = sh
->value
;
1023 TYPE_NFIELDS (t
) = nfields
;
1024 TYPE_FIELDS (t
) = f
= ((struct field
*)
1026 nfields
* sizeof (struct field
)));
1028 if (type_code
== TYPE_CODE_ENUM
)
1030 int unsigned_enum
= 1;
1032 /* This is a non-empty enum. */
1034 /* DEC c89 has the number of enumerators in the sh.value field,
1035 not the type length, so we have to compensate for that
1036 incompatibility quirk.
1037 This might do the wrong thing for an enum with one or two
1038 enumerators and gcc -gcoff -fshort-enums, but these cases
1039 are hopefully rare enough.
1040 Alpha cc -migrate has a sh.value field of zero, we adjust
1042 if (TYPE_LENGTH (t
) == TYPE_NFIELDS (t
)
1043 || TYPE_LENGTH (t
) == 0)
1044 TYPE_LENGTH (t
) = gdbarch_int_bit (gdbarch
) / HOST_CHAR_BIT
;
1045 for (ext_tsym
= ext_sh
+ external_sym_size
;
1047 ext_tsym
+= external_sym_size
)
1050 struct symbol
*enum_sym
;
1052 (*swap_sym_in
) (cur_bfd
, ext_tsym
, &tsym
);
1054 if (tsym
.st
!= stMember
)
1057 FIELD_BITPOS (*f
) = tsym
.value
;
1058 FIELD_TYPE (*f
) = t
;
1059 FIELD_NAME (*f
) = debug_info
->ss
+ cur_fdr
->issBase
+ tsym
.iss
;
1060 FIELD_BITSIZE (*f
) = 0;
1061 FIELD_STATIC_KIND (*f
) = 0;
1063 enum_sym
= ((struct symbol
*)
1064 obstack_alloc (¤t_objfile
->objfile_obstack
,
1065 sizeof (struct symbol
)));
1066 memset (enum_sym
, 0, sizeof (struct symbol
));
1067 SYMBOL_SET_LINKAGE_NAME
1068 (enum_sym
, obsavestring (f
->name
, strlen (f
->name
),
1069 ¤t_objfile
->objfile_obstack
));
1070 SYMBOL_CLASS (enum_sym
) = LOC_CONST
;
1071 SYMBOL_TYPE (enum_sym
) = t
;
1072 SYMBOL_DOMAIN (enum_sym
) = VAR_DOMAIN
;
1073 SYMBOL_VALUE (enum_sym
) = tsym
.value
;
1074 if (SYMBOL_VALUE (enum_sym
) < 0)
1076 add_symbol (enum_sym
, top_stack
->cur_st
, top_stack
->cur_block
);
1078 /* Skip the stMembers that we've handled. */
1083 TYPE_UNSIGNED (t
) = 1;
1085 /* make this the current type */
1086 top_stack
->cur_type
= t
;
1087 top_stack
->cur_field
= 0;
1089 /* Do not create a symbol for alpha cc unnamed structs. */
1093 /* gcc puts out an empty struct for an opaque struct definitions,
1094 do not create a symbol for it either. */
1095 if (TYPE_NFIELDS (t
) == 0)
1101 s
= new_symbol (name
);
1102 SYMBOL_DOMAIN (s
) = STRUCT_DOMAIN
;
1103 SYMBOL_CLASS (s
) = LOC_TYPEDEF
;
1104 SYMBOL_VALUE (s
) = 0;
1105 SYMBOL_TYPE (s
) = t
;
1106 add_symbol (s
, top_stack
->cur_st
, top_stack
->cur_block
);
1109 /* End of local variables shared by struct, union, enum, and
1110 block (as yet unknown struct/union/enum) processing. */
1114 found_ecoff_debugging_info
= 1;
1115 /* beginnning of (code) block. Value of symbol
1116 is the displacement from procedure start */
1117 push_parse_stack ();
1119 /* Do not start a new block if this is the outermost block of a
1120 procedure. This allows the LOC_BLOCK symbol to point to the
1121 block with the local variables, so funcname::var works. */
1122 if (top_stack
->blocktype
== stProc
1123 || top_stack
->blocktype
== stStaticProc
)
1125 top_stack
->blocktype
= stNil
;
1129 top_stack
->blocktype
= stBlock
;
1130 b
= new_block (NON_FUNCTION_BLOCK
);
1131 BLOCK_START (b
) = sh
->value
+ top_stack
->procadr
;
1132 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
1133 top_stack
->cur_block
= b
;
1134 add_block (b
, top_stack
->cur_st
);
1137 case stEnd
: /* end (of anything) */
1138 if (sh
->sc
== scInfo
|| SC_IS_COMMON (sh
->sc
))
1140 /* Finished with type */
1141 top_stack
->cur_type
= 0;
1143 else if (sh
->sc
== scText
&&
1144 (top_stack
->blocktype
== stProc
||
1145 top_stack
->blocktype
== stStaticProc
))
1147 /* Finished with procedure */
1148 struct blockvector
*bv
= BLOCKVECTOR (top_stack
->cur_st
);
1149 struct mdebug_extra_func_info
*e
;
1150 struct block
*b
= top_stack
->cur_block
;
1151 struct type
*ftype
= top_stack
->cur_type
;
1154 BLOCK_END (top_stack
->cur_block
) += sh
->value
; /* size */
1156 /* Make up special symbol to contain procedure specific info */
1157 s
= new_symbol (MDEBUG_EFI_SYMBOL_NAME
);
1158 SYMBOL_DOMAIN (s
) = LABEL_DOMAIN
;
1159 SYMBOL_CLASS (s
) = LOC_CONST
;
1160 SYMBOL_TYPE (s
) = mdebug_type_void
;
1161 e
= ((struct mdebug_extra_func_info
*)
1162 obstack_alloc (¤t_objfile
->objfile_obstack
,
1163 sizeof (struct mdebug_extra_func_info
)));
1164 memset (e
, 0, sizeof (struct mdebug_extra_func_info
));
1165 SYMBOL_VALUE (s
) = (long) e
;
1166 e
->numargs
= top_stack
->numargs
;
1167 e
->pdr
.framereg
= -1;
1168 add_symbol (s
, top_stack
->cur_st
, top_stack
->cur_block
);
1170 /* f77 emits proc-level with address bounds==[0,0],
1171 So look for such child blocks, and patch them. */
1172 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS (bv
); i
++)
1174 struct block
*b_bad
= BLOCKVECTOR_BLOCK (bv
, i
);
1175 if (BLOCK_SUPERBLOCK (b_bad
) == b
1176 && BLOCK_START (b_bad
) == top_stack
->procadr
1177 && BLOCK_END (b_bad
) == top_stack
->procadr
)
1179 BLOCK_START (b_bad
) = BLOCK_START (b
);
1180 BLOCK_END (b_bad
) = BLOCK_END (b
);
1184 if (TYPE_NFIELDS (ftype
) <= 0)
1186 /* No parameter type information is recorded with the function's
1187 type. Set that from the type of the parameter symbols. */
1188 int nparams
= top_stack
->numargs
;
1194 struct dict_iterator iter
;
1195 TYPE_NFIELDS (ftype
) = nparams
;
1196 TYPE_FIELDS (ftype
) = (struct field
*)
1197 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
1200 ALL_BLOCK_SYMBOLS (b
, iter
, sym
)
1202 if (iparams
== nparams
)
1205 if (SYMBOL_IS_ARGUMENT (sym
))
1207 TYPE_FIELD_TYPE (ftype
, iparams
) = SYMBOL_TYPE (sym
);
1208 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
1215 else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
)
1217 /* End of (code) block. The value of the symbol is the
1218 displacement from the procedure`s start address of the
1219 end of this block. */
1220 BLOCK_END (top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1222 else if (sh
->sc
== scText
&& top_stack
->blocktype
== stNil
)
1224 /* End of outermost block. Pop parse stack and ignore. The
1225 following stEnd of stProc will take care of the block. */
1228 else if (sh
->sc
== scText
&& top_stack
->blocktype
== stFile
)
1230 /* End of file. Pop parse stack and ignore. Higher
1231 level code deals with this. */
1235 complaint (&symfile_complaints
,
1236 _("stEnd with storage class %d not handled"), sh
->sc
);
1238 pop_parse_stack (); /* restore previous lexical context */
1241 case stMember
: /* member of struct or union */
1242 f
= &TYPE_FIELDS (top_stack
->cur_type
)[top_stack
->cur_field
++];
1243 FIELD_NAME (*f
) = name
;
1244 FIELD_BITPOS (*f
) = sh
->value
;
1246 FIELD_TYPE (*f
) = parse_type (cur_fd
, ax
, sh
->index
, &bitsize
, bigend
, name
);
1247 FIELD_BITSIZE (*f
) = bitsize
;
1248 FIELD_STATIC_KIND (*f
) = 0;
1251 case stIndirect
: /* forward declaration on Irix5 */
1252 /* Forward declarations from Irix5 cc are handled by cross_ref,
1256 case stTypedef
: /* type definition */
1257 found_ecoff_debugging_info
= 1;
1259 /* Typedefs for forward declarations and opaque structs from alpha cc
1260 are handled by cross_ref, skip them. */
1264 /* Parse the type or use the pending type. */
1265 pend
= is_pending_symbol (cur_fdr
, ext_sh
);
1266 if (pend
== (struct mdebug_pending
*) NULL
)
1268 t
= parse_type (cur_fd
, ax
, sh
->index
, (int *) NULL
, bigend
, name
);
1269 add_pending (cur_fdr
, ext_sh
, t
);
1274 /* mips cc puts out a typedef with the name of the struct for forward
1275 declarations. These should not go into the symbol table and
1276 TYPE_NAME should not be set for them.
1277 They can't be distinguished from an intentional typedef to
1278 the same name however:
1280 struct x { int ix; int jx; };
1284 struct xx {int ixx; int jxx; };
1285 generates a cross referencing stTypedef for x and xx.
1286 The user visible effect of this is that the type of a pointer
1287 to struct foo sometimes is given as `foo *' instead of `struct foo *'.
1288 The problem is fixed with alpha cc and Irix5 cc. */
1290 /* However if the typedef cross references to an opaque aggregate, it
1291 is safe to omit it from the symbol table. */
1293 if (has_opaque_xref (cur_fdr
, sh
))
1295 s
= new_symbol (name
);
1296 SYMBOL_DOMAIN (s
) = VAR_DOMAIN
;
1297 SYMBOL_CLASS (s
) = LOC_TYPEDEF
;
1298 SYMBOL_BLOCK_VALUE (s
) = top_stack
->cur_block
;
1299 SYMBOL_TYPE (s
) = t
;
1300 add_symbol (s
, top_stack
->cur_st
, top_stack
->cur_block
);
1302 /* Incomplete definitions of structs should not get a name. */
1303 if (TYPE_NAME (SYMBOL_TYPE (s
)) == NULL
1304 && (TYPE_NFIELDS (SYMBOL_TYPE (s
)) != 0
1305 || (TYPE_CODE (SYMBOL_TYPE (s
)) != TYPE_CODE_STRUCT
1306 && TYPE_CODE (SYMBOL_TYPE (s
)) != TYPE_CODE_UNION
)))
1308 if (TYPE_CODE (SYMBOL_TYPE (s
)) == TYPE_CODE_PTR
1309 || TYPE_CODE (SYMBOL_TYPE (s
)) == TYPE_CODE_FUNC
)
1311 /* If we are giving a name to a type such as "pointer to
1312 foo" or "function returning foo", we better not set
1313 the TYPE_NAME. If the program contains "typedef char
1314 *caddr_t;", we don't want all variables of type char
1315 * to print as caddr_t. This is not just a
1316 consequence of GDB's type management; CC and GCC (at
1317 least through version 2.4) both output variables of
1318 either type char * or caddr_t with the type
1319 refering to the stTypedef symbol for caddr_t. If a future
1320 compiler cleans this up it GDB is not ready for it
1321 yet, but if it becomes ready we somehow need to
1322 disable this check (without breaking the PCC/GCC2.4
1327 Fortunately, this check seems not to be necessary
1328 for anything except pointers or functions. */
1331 TYPE_NAME (SYMBOL_TYPE (s
)) = SYMBOL_LINKAGE_NAME (s
);
1335 case stFile
: /* file name */
1336 push_parse_stack ();
1337 top_stack
->blocktype
= sh
->st
;
1340 /* I`ve never seen these for C */
1342 break; /* register relocation */
1344 break; /* forwarding address */
1346 break; /* constant */
1348 complaint (&symfile_complaints
, _("unknown symbol type 0x%x"), sh
->st
);
1355 /* Parse the type information provided in the raw AX entries for
1356 the symbol SH. Return the bitfield size in BS, in case.
1357 We must byte-swap the AX entries before we use them; BIGEND says whether
1358 they are big-endian or little-endian (from fh->fBigendian). */
1360 static struct type
*
1361 parse_type (int fd
, union aux_ext
*ax
, unsigned int aux_index
, int *bs
,
1362 int bigend
, char *sym_name
)
1364 /* Null entries in this map are treated specially */
1365 static struct type
**map_bt
[] =
1367 &mdebug_type_void
, /* btNil */
1368 &mdebug_type_adr_32
, /* btAdr */
1369 &mdebug_type_char
, /* btChar */
1370 &mdebug_type_unsigned_char
, /* btUChar */
1371 &mdebug_type_short
, /* btShort */
1372 &mdebug_type_unsigned_short
, /* btUShort */
1373 &mdebug_type_int_32
, /* btInt */
1374 &mdebug_type_unsigned_int_32
, /* btUInt */
1375 &mdebug_type_long_32
, /* btLong */
1376 &mdebug_type_unsigned_long_32
, /* btULong */
1377 &mdebug_type_float
, /* btFloat */
1378 &mdebug_type_double
, /* btDouble */
1385 &mdebug_type_complex
, /* btComplex */
1386 &mdebug_type_double_complex
, /* btDComplex */
1388 &mdebug_type_fixed_dec
, /* btFixedDec */
1389 &mdebug_type_float_dec
, /* btFloatDec */
1390 &mdebug_type_string
, /* btString */
1393 &mdebug_type_void
, /* btVoid */
1394 0, /* DEC C++: Pointer to member */
1395 0, /* DEC C++: Virtual function table */
1396 0, /* DEC C++: Class (Record) */
1397 &mdebug_type_long_64
, /* btLong64 */
1398 &mdebug_type_unsigned_long_64
, /* btULong64 */
1399 &mdebug_type_long_long_64
, /* btLongLong64 */
1400 &mdebug_type_unsigned_long_long_64
, /* btULongLong64 */
1401 &mdebug_type_adr_64
, /* btAdr64 */
1402 &mdebug_type_int_64
, /* btInt64 */
1403 &mdebug_type_unsigned_int_64
, /* btUInt64 */
1407 struct type
*tp
= 0;
1408 enum type_code type_code
= TYPE_CODE_UNDEF
;
1410 /* Handle undefined types, they have indexNil. */
1411 if (aux_index
== indexNil
)
1412 return mdebug_type_int
;
1414 /* Handle corrupt aux indices. */
1415 if (aux_index
>= (debug_info
->fdr
+ fd
)->caux
)
1417 index_complaint (sym_name
);
1418 return mdebug_type_int
;
1422 /* Use aux as a type information record, map its basic type. */
1423 (*debug_swap
->swap_tir_in
) (bigend
, &ax
->a_ti
, t
);
1424 if (t
->bt
>= (sizeof (map_bt
) / sizeof (*map_bt
)))
1426 basic_type_complaint (t
->bt
, sym_name
);
1427 return mdebug_type_int
;
1431 tp
= *map_bt
[t
->bt
];
1436 /* Cannot use builtin types -- build our own */
1440 type_code
= TYPE_CODE_STRUCT
;
1443 type_code
= TYPE_CODE_UNION
;
1446 type_code
= TYPE_CODE_ENUM
;
1449 type_code
= TYPE_CODE_RANGE
;
1452 type_code
= TYPE_CODE_SET
;
1455 /* alpha cc -migrate uses this for typedefs. The true type will
1456 be obtained by crossreferencing below. */
1457 type_code
= TYPE_CODE_ERROR
;
1460 /* alpha cc uses this for typedefs. The true type will be
1461 obtained by crossreferencing below. */
1462 type_code
= TYPE_CODE_ERROR
;
1465 basic_type_complaint (t
->bt
, sym_name
);
1466 return mdebug_type_int
;
1470 /* Move on to next aux */
1475 int width
= AUX_GET_WIDTH (bigend
, ax
);
1476 /* Inhibit core dumps if TIR is corrupted. */
1477 if (bs
== (int *) NULL
)
1479 /* Alpha cc -migrate encodes char and unsigned char types
1480 as short and unsigned short types with a field width of 8.
1481 Enum types also have a field width which we ignore for now. */
1482 if (t
->bt
== btShort
&& width
== 8)
1483 tp
= mdebug_type_char
;
1484 else if (t
->bt
== btUShort
&& width
== 8)
1485 tp
= mdebug_type_unsigned_char
;
1486 else if (t
->bt
== btEnum
)
1489 complaint (&symfile_complaints
, _("can't handle TIR fBitfield for %s"),
1497 /* A btIndirect entry cross references to an aux entry containing
1499 if (t
->bt
== btIndirect
)
1506 (*debug_swap
->swap_rndx_in
) (bigend
, &ax
->a_rndx
, rn
);
1508 if (rn
->rfd
== 0xfff)
1510 rf
= AUX_GET_ISYM (bigend
, ax
);
1518 complaint (&symfile_complaints
,
1519 _("unable to cross ref btIndirect for %s"), sym_name
);
1520 return mdebug_type_int
;
1522 xref_fh
= get_rfd (fd
, rf
);
1523 xref_fd
= xref_fh
- debug_info
->fdr
;
1524 tp
= parse_type (xref_fd
, debug_info
->external_aux
+ xref_fh
->iauxBase
,
1525 rn
->index
, (int *) NULL
, xref_fh
->fBigendian
, sym_name
);
1528 /* All these types really point to some (common) MIPS type
1529 definition, and only the type-qualifiers fully identify
1530 them. We'll make the same effort at sharing. */
1531 if (t
->bt
== btStruct
||
1535 /* btSet (I think) implies that the name is a tag name, not a typedef
1536 name. This apparently is a MIPS extension for C sets. */
1541 /* Try to cross reference this type, build new type on failure. */
1542 ax
+= cross_ref (fd
, ax
, &tp
, type_code
, &name
, bigend
, sym_name
);
1543 if (tp
== (struct type
*) NULL
)
1544 tp
= init_type (type_code
, 0, 0, (char *) NULL
, current_objfile
);
1546 /* DEC c89 produces cross references to qualified aggregate types,
1547 dereference them. */
1548 while (TYPE_CODE (tp
) == TYPE_CODE_PTR
1549 || TYPE_CODE (tp
) == TYPE_CODE_ARRAY
)
1550 tp
= TYPE_TARGET_TYPE (tp
);
1552 /* Make sure that TYPE_CODE(tp) has an expected type code.
1553 Any type may be returned from cross_ref if file indirect entries
1555 if (TYPE_CODE (tp
) != TYPE_CODE_STRUCT
1556 && TYPE_CODE (tp
) != TYPE_CODE_UNION
1557 && TYPE_CODE (tp
) != TYPE_CODE_ENUM
)
1559 unexpected_type_code_complaint (sym_name
);
1564 /* Usually, TYPE_CODE(tp) is already type_code. The main
1565 exception is if we guessed wrong re struct/union/enum.
1566 But for struct vs. union a wrong guess is harmless, so
1567 don't complain(). */
1568 if ((TYPE_CODE (tp
) == TYPE_CODE_ENUM
1569 && type_code
!= TYPE_CODE_ENUM
)
1570 || (TYPE_CODE (tp
) != TYPE_CODE_ENUM
1571 && type_code
== TYPE_CODE_ENUM
))
1573 bad_tag_guess_complaint (sym_name
);
1576 if (TYPE_CODE (tp
) != type_code
)
1578 TYPE_CODE (tp
) = type_code
;
1581 /* Do not set the tag name if it is a compiler generated tag name
1582 (.Fxx or .xxfake or empty) for unnamed struct/union/enums. */
1583 if (name
[0] == '.' || name
[0] == '\0')
1584 TYPE_TAG_NAME (tp
) = NULL
;
1585 else if (TYPE_TAG_NAME (tp
) == NULL
1586 || strcmp (TYPE_TAG_NAME (tp
), name
) != 0)
1587 TYPE_TAG_NAME (tp
) = obsavestring (name
, strlen (name
),
1588 ¤t_objfile
->objfile_obstack
);
1592 /* All these types really point to some (common) MIPS type
1593 definition, and only the type-qualifiers fully identify
1594 them. We'll make the same effort at sharing.
1595 FIXME: We are not doing any guessing on range types. */
1596 if (t
->bt
== btRange
)
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 /* Make sure that TYPE_CODE(tp) has an expected type code.
1606 Any type may be returned from cross_ref if file indirect entries
1608 if (TYPE_CODE (tp
) != TYPE_CODE_RANGE
)
1610 unexpected_type_code_complaint (sym_name
);
1614 /* Usually, TYPE_CODE(tp) is already type_code. The main
1615 exception is if we guessed wrong re struct/union/enum. */
1616 if (TYPE_CODE (tp
) != type_code
)
1618 bad_tag_guess_complaint (sym_name
);
1619 TYPE_CODE (tp
) = type_code
;
1621 if (TYPE_NAME (tp
) == NULL
1622 || strcmp (TYPE_NAME (tp
), name
) != 0)
1623 TYPE_NAME (tp
) = obsavestring (name
, strlen (name
),
1624 ¤t_objfile
->objfile_obstack
);
1627 if (t
->bt
== btTypedef
)
1631 /* Try to cross reference this type, it should succeed. */
1632 ax
+= cross_ref (fd
, ax
, &tp
, type_code
, &name
, bigend
, sym_name
);
1633 if (tp
== (struct type
*) NULL
)
1635 complaint (&symfile_complaints
,
1636 _("unable to cross ref btTypedef for %s"), sym_name
);
1637 tp
= mdebug_type_int
;
1641 /* Deal with range types */
1642 if (t
->bt
== btRange
)
1644 TYPE_NFIELDS (tp
) = 2;
1645 TYPE_FIELDS (tp
) = ((struct field
*)
1646 TYPE_ALLOC (tp
, 2 * sizeof (struct field
)));
1647 TYPE_FIELD_NAME (tp
, 0) = obsavestring ("Low", strlen ("Low"),
1648 ¤t_objfile
->objfile_obstack
);
1649 TYPE_FIELD_BITPOS (tp
, 0) = AUX_GET_DNLOW (bigend
, ax
);
1651 TYPE_FIELD_NAME (tp
, 1) = obsavestring ("High", strlen ("High"),
1652 ¤t_objfile
->objfile_obstack
);
1653 TYPE_FIELD_BITPOS (tp
, 1) = AUX_GET_DNHIGH (bigend
, ax
);
1657 /* Parse all the type qualifiers now. If there are more
1658 than 6 the game will continue in the next aux */
1662 #define PARSE_TQ(tq) \
1663 if (t->tq != tqNil) \
1664 ax += upgrade_type(fd, &tp, t->tq, ax, bigend, sym_name); \
1676 /* mips cc 2.x and gcc never put out continued aux entries. */
1680 (*debug_swap
->swap_tir_in
) (bigend
, &ax
->a_ti
, t
);
1684 /* Complain for illegal continuations due to corrupt aux entries. */
1686 complaint (&symfile_complaints
, _("illegal TIR continued for %s"), sym_name
);
1691 /* Make up a complex type from a basic one. Type is passed by
1692 reference in TPP and side-effected as necessary. The type
1693 qualifier TQ says how to handle the aux symbols at AX for
1694 the symbol SX we are currently analyzing. BIGEND says whether
1695 aux symbols are big-endian or little-endian.
1696 Returns the number of aux symbols we parsed. */
1699 upgrade_type (int fd
, struct type
**tpp
, int tq
, union aux_ext
*ax
, int bigend
,
1705 /* Used in array processing */
1716 t
= lookup_pointer_type (*tpp
);
1721 t
= lookup_function_type (*tpp
);
1728 /* Determine and record the domain type (type of index) */
1729 (*debug_swap
->swap_rndx_in
) (bigend
, &ax
->a_rndx
, &rndx
);
1735 rf
= AUX_GET_ISYM (bigend
, ax
);
1738 fh
= get_rfd (fd
, rf
);
1740 indx
= parse_type (fh
- debug_info
->fdr
,
1741 debug_info
->external_aux
+ fh
->iauxBase
,
1742 id
, (int *) NULL
, bigend
, sym_name
);
1744 /* The bounds type should be an integer type, but might be anything
1745 else due to corrupt aux entries. */
1746 if (TYPE_CODE (indx
) != TYPE_CODE_INT
)
1748 complaint (&symfile_complaints
,
1749 _("illegal array index type for %s, assuming int"), sym_name
);
1750 indx
= mdebug_type_int
;
1753 /* Get the bounds, and create the array type. */
1755 lower
= AUX_GET_DNLOW (bigend
, ax
);
1757 upper
= AUX_GET_DNHIGH (bigend
, ax
);
1759 rf
= AUX_GET_WIDTH (bigend
, ax
); /* bit size of array element */
1761 range
= create_range_type ((struct type
*) NULL
, indx
,
1764 t
= create_array_type ((struct type
*) NULL
, *tpp
, range
);
1766 /* We used to fill in the supplied array element bitsize
1767 here if the TYPE_LENGTH of the target type was zero.
1768 This happens for a `pointer to an array of anonymous structs',
1769 but in this case the array element bitsize is also zero,
1770 so nothing is gained.
1771 And we used to check the TYPE_LENGTH of the target type against
1772 the supplied array element bitsize.
1773 gcc causes a mismatch for `pointer to array of object',
1774 since the sdb directives it uses do not have a way of
1775 specifying the bitsize, but it does no harm (the
1776 TYPE_LENGTH should be correct) and we should be able to
1777 ignore the erroneous bitsize from the auxiliary entry safely.
1778 dbx seems to ignore it too. */
1780 /* TYPE_FLAG_TARGET_STUB now takes care of the zero TYPE_LENGTH
1782 if (TYPE_LENGTH (*tpp
) == 0)
1784 TYPE_TARGET_STUB (t
) = 1;
1791 /* Volatile -- currently ignored */
1795 /* Const -- currently ignored */
1799 complaint (&symfile_complaints
, _("unknown type qualifier 0x%x"), tq
);
1805 /* Parse a procedure descriptor record PR. Note that the procedure is
1806 parsed _after_ the local symbols, now we just insert the extra
1807 information we need into a MDEBUG_EFI_SYMBOL_NAME symbol that has
1808 already been placed in the procedure's main block. Note also that
1809 images that have been partially stripped (ld -x) have been deprived
1810 of local symbols, and we have to cope with them here. FIRST_OFF is
1811 the offset of the first procedure for this FDR; we adjust the
1812 address by this amount, but I don't know why. SEARCH_SYMTAB is the symtab
1813 to look for the function which contains the MDEBUG_EFI_SYMBOL_NAME symbol
1814 in question, or NULL to use top_stack->cur_block. */
1816 static void parse_procedure (PDR
*, struct symtab
*, struct partial_symtab
*);
1819 parse_procedure (PDR
*pr
, struct symtab
*search_symtab
,
1820 struct partial_symtab
*pst
)
1822 struct gdbarch
*gdbarch
= get_objfile_arch (pst
->objfile
);
1823 struct symbol
*s
, *i
;
1825 struct mdebug_extra_func_info
*e
;
1828 /* Simple rule to find files linked "-x" */
1829 if (cur_fdr
->rss
== -1)
1833 /* Static procedure at address pr->adr. Sigh. */
1834 /* FIXME-32x64. assuming pr->adr fits in long. */
1835 complaint (&symfile_complaints
,
1836 _("can't handle PDR for static proc at 0x%lx"),
1837 (unsigned long) pr
->adr
);
1845 (*debug_swap
->swap_ext_in
) (cur_bfd
,
1846 ((char *) debug_info
->external_ext
1848 * debug_swap
->external_ext_size
)),
1850 sh_name
= debug_info
->ssext
+ she
.asym
.iss
;
1858 (*debug_swap
->swap_sym_in
) (cur_bfd
,
1859 ((char *) debug_info
->external_sym
1860 + ((cur_fdr
->isymBase
+ pr
->isym
)
1861 * debug_swap
->external_sym_size
)),
1863 sh_name
= debug_info
->ss
+ cur_fdr
->issBase
+ sh
.iss
;
1866 if (search_symtab
!= NULL
)
1869 /* This loses both in the case mentioned (want a static, find a global),
1870 but also if we are looking up a non-mangled name which happens to
1871 match the name of a mangled function. */
1872 /* We have to save the cur_fdr across the call to lookup_symbol.
1873 If the pdr is for a static function and if a global function with
1874 the same name exists, lookup_symbol will eventually read in the symtab
1875 for the global function and clobber cur_fdr. */
1876 FDR
*save_cur_fdr
= cur_fdr
;
1877 s
= lookup_symbol (sh_name
, NULL
, VAR_DOMAIN
, 0);
1878 cur_fdr
= save_cur_fdr
;
1882 BLOCKVECTOR_BLOCK (BLOCKVECTOR (search_symtab
), STATIC_BLOCK
),
1888 s
= mylookup_symbol (sh_name
, top_stack
->cur_block
,
1889 VAR_DOMAIN
, LOC_BLOCK
);
1893 b
= SYMBOL_BLOCK_VALUE (s
);
1897 complaint (&symfile_complaints
, _("PDR for %s, but no symbol"), sh_name
);
1901 /* FIXME -- delete. We can't do symbol allocation now; it's all done. */
1902 s
= new_symbol (sh_name
);
1903 SYMBOL_DOMAIN (s
) = VAR_DOMAIN
;
1904 SYMBOL_CLASS (s
) = LOC_BLOCK
;
1905 /* Donno its type, hope int is ok */
1906 SYMBOL_TYPE (s
) = lookup_function_type (mdebug_type_int
);
1907 add_symbol (s
, top_stack
->cur_st
, top_stack
->cur_block
);
1908 /* Wont have symbols for this one */
1910 SYMBOL_BLOCK_VALUE (s
) = b
;
1911 BLOCK_FUNCTION (b
) = s
;
1912 BLOCK_START (b
) = pr
->adr
;
1913 /* BOUND used to be the end of procedure's text, but the
1914 argument is no longer passed in. */
1915 BLOCK_END (b
) = bound
;
1916 BLOCK_SUPERBLOCK (b
) = top_stack
->cur_block
;
1917 add_block (b
, top_stack
->cur_st
);
1921 i
= mylookup_symbol (MDEBUG_EFI_SYMBOL_NAME
, b
, LABEL_DOMAIN
, LOC_CONST
);
1925 e
= (struct mdebug_extra_func_info
*) SYMBOL_VALUE (i
);
1927 e
->pdr
.isym
= (long) s
;
1929 /* GDB expects the absolute function start address for the
1930 procedure descriptor in e->pdr.adr.
1931 As the address in the procedure descriptor is usually relative,
1932 we would have to relocate e->pdr.adr with cur_fdr->adr and
1933 ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (pst->objfile)).
1934 Unfortunately cur_fdr->adr and e->pdr.adr are both absolute
1935 in shared libraries on some systems, and on other systems
1936 e->pdr.adr is sometimes offset by a bogus value.
1937 To work around these problems, we replace e->pdr.adr with
1938 the start address of the function. */
1939 e
->pdr
.adr
= BLOCK_START (b
);
1942 /* It would be reasonable that functions that have been compiled
1943 without debugging info have a btNil type for their return value,
1944 and functions that are void and are compiled with debugging info
1946 gcc and DEC f77 put out btNil types for both cases, so btNil is mapped
1947 to TYPE_CODE_VOID in parse_type to get the `compiled with debugging info'
1949 The glevel field in cur_fdr could be used to determine the presence
1950 of debugging info, but GCC doesn't always pass the -g switch settings
1951 to the assembler and GAS doesn't set the glevel field from the -g switch
1953 To work around these problems, the return value type of a TYPE_CODE_VOID
1954 function is adjusted accordingly if no debugging info was found in the
1955 compilation unit. */
1957 if (processing_gcc_compilation
== 0
1958 && found_ecoff_debugging_info
== 0
1959 && TYPE_CODE (TYPE_TARGET_TYPE (SYMBOL_TYPE (s
))) == TYPE_CODE_VOID
)
1960 SYMBOL_TYPE (s
) = builtin_type (gdbarch
)->nodebug_text_symbol
;
1963 /* Parse the external symbol ES. Just call parse_symbol() after
1964 making sure we know where the aux are for it.
1965 BIGEND says whether aux entries are big-endian or little-endian.
1967 This routine clobbers top_stack->cur_block and ->cur_st. */
1969 static void parse_external (EXTR
*, int, struct section_offsets
*,
1973 parse_external (EXTR
*es
, int bigend
, struct section_offsets
*section_offsets
,
1974 struct objfile
*objfile
)
1978 if (es
->ifd
!= ifdNil
)
1981 cur_fdr
= debug_info
->fdr
+ cur_fd
;
1982 ax
= debug_info
->external_aux
+ cur_fdr
->iauxBase
;
1986 cur_fdr
= debug_info
->fdr
;
1990 /* Reading .o files */
1991 if (SC_IS_UNDEF (es
->asym
.sc
) || es
->asym
.sc
== scNil
)
1994 switch (es
->asym
.st
)
1997 /* These are generated for static symbols in .o files,
2018 /* FIXME: Turn this into a complaint? */
2020 printf_filtered (_("Warning: %s `%s' is undefined (in %s)\n"),
2021 what
, debug_info
->ssext
+ es
->asym
.iss
,
2022 fdr_name (cur_fdr
));
2026 switch (es
->asym
.st
)
2030 /* There is no need to parse the external procedure symbols.
2031 If they are from objects compiled without -g, their index will
2032 be indexNil, and the symbol definition from the minimal symbol
2033 is preferrable (yielding a function returning int instead of int).
2034 If the index points to a local procedure symbol, the local
2035 symbol already provides the correct type.
2036 Note that the index of the external procedure symbol points
2037 to the local procedure symbol in the local symbol table, and
2038 _not_ to the auxiliary symbol info. */
2042 /* Global common symbols are resolved by the runtime loader,
2044 if (SC_IS_COMMON (es
->asym
.sc
))
2047 /* Note that the case of a symbol with indexNil must be handled
2048 anyways by parse_symbol(). */
2049 parse_symbol (&es
->asym
, ax
, (char *) NULL
, bigend
, section_offsets
, objfile
);
2056 /* Parse the line number info for file descriptor FH into
2057 GDB's linetable LT. MIPS' encoding requires a little bit
2058 of magic to get things out. Note also that MIPS' line
2059 numbers can go back and forth, apparently we can live
2060 with that and do not need to reorder our linetables */
2062 static void parse_lines (FDR
*, PDR
*, struct linetable
*, int,
2063 struct partial_symtab
*, CORE_ADDR
);
2066 parse_lines (FDR
*fh
, PDR
*pr
, struct linetable
*lt
, int maxlines
,
2067 struct partial_symtab
*pst
, CORE_ADDR lowest_pdr_addr
)
2069 unsigned char *base
;
2071 int delta
, count
, lineno
= 0;
2073 if (fh
->cbLine
== 0)
2076 /* Scan by procedure descriptors */
2078 for (j
= 0; j
< fh
->cpd
; j
++, pr
++)
2082 unsigned char *halt
;
2084 /* No code for this one */
2085 if (pr
->iline
== ilineNil
||
2086 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
2089 /* Determine start and end address of compressed line bytes for
2091 base
= debug_info
->line
+ fh
->cbLineOffset
;
2092 if (j
!= (fh
->cpd
- 1))
2093 halt
= base
+ pr
[1].cbLineOffset
;
2095 halt
= base
+ fh
->cbLine
;
2096 base
+= pr
->cbLineOffset
;
2098 adr
= pst
->textlow
+ pr
->adr
- lowest_pdr_addr
;
2100 l
= adr
>> 2; /* in words */
2101 for (lineno
= pr
->lnLow
; base
< halt
;)
2103 count
= *base
& 0x0f;
2104 delta
= *base
++ >> 4;
2109 delta
= (base
[0] << 8) | base
[1];
2110 if (delta
>= 0x8000)
2114 lineno
+= delta
; /* first delta is 0 */
2116 /* Complain if the line table overflows. Could happen
2117 with corrupt binaries. */
2118 if (lt
->nitems
>= maxlines
)
2120 complaint (&symfile_complaints
,
2121 _("guessed size of linetable for %s incorrectly"),
2125 k
= add_line (lt
, lineno
, l
, k
);
2132 function_outside_compilation_unit_complaint (const char *arg1
)
2134 complaint (&symfile_complaints
,
2135 _("function `%s' appears to be defined outside of all compilation units"),
2139 /* Use the STORAGE_CLASS to compute which section the given symbol
2140 belongs to, and then records this new minimal symbol. */
2143 record_minimal_symbol (const char *name
, const CORE_ADDR address
,
2144 enum minimal_symbol_type ms_type
, int storage_class
,
2145 struct objfile
*objfile
)
2148 asection
*bfd_section
;
2150 switch (storage_class
)
2153 section
= SECT_OFF_TEXT (objfile
);
2154 bfd_section
= bfd_get_section_by_name (cur_bfd
, ".text");
2157 section
= SECT_OFF_DATA (objfile
);
2158 bfd_section
= bfd_get_section_by_name (cur_bfd
, ".data");
2161 section
= SECT_OFF_BSS (objfile
);
2162 bfd_section
= bfd_get_section_by_name (cur_bfd
, ".bss");
2165 section
= get_section_index (objfile
, ".sdata");
2166 bfd_section
= bfd_get_section_by_name (cur_bfd
, ".sdata");
2169 section
= get_section_index (objfile
, ".sbss");
2170 bfd_section
= bfd_get_section_by_name (cur_bfd
, ".sbss");
2173 section
= get_section_index (objfile
, ".rdata");
2174 bfd_section
= bfd_get_section_by_name (cur_bfd
, ".rdata");
2177 section
= get_section_index (objfile
, ".init");
2178 bfd_section
= bfd_get_section_by_name (cur_bfd
, ".init");
2181 section
= get_section_index (objfile
, ".xdata");
2182 bfd_section
= bfd_get_section_by_name (cur_bfd
, ".xdata");
2185 section
= get_section_index (objfile
, ".pdata");
2186 bfd_section
= bfd_get_section_by_name (cur_bfd
, ".pdata");
2189 section
= get_section_index (objfile
, ".fini");
2190 bfd_section
= bfd_get_section_by_name (cur_bfd
, ".fini");
2193 section
= get_section_index (objfile
, ".rconst");
2194 bfd_section
= bfd_get_section_by_name (cur_bfd
, ".rconst");
2198 section
= get_section_index (objfile
, ".tlsdata");
2199 bfd_section
= bfd_get_section_by_name (cur_bfd
, ".tlsdata");
2204 section
= get_section_index (objfile
, ".tlsbss");
2205 bfd_section
= bfd_get_section_by_name (cur_bfd
, ".tlsbss");
2209 /* This kind of symbol is not associated to a section. */
2214 prim_record_minimal_symbol_and_info (name
, address
, ms_type
, NULL
,
2215 section
, bfd_section
, objfile
);
2218 /* Master parsing procedure for first-pass reading of file symbols
2219 into a partial_symtab. */
2222 parse_partial_symbols (struct objfile
*objfile
)
2224 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2225 const bfd_size_type external_sym_size
= debug_swap
->external_sym_size
;
2226 const bfd_size_type external_rfd_size
= debug_swap
->external_rfd_size
;
2227 const bfd_size_type external_ext_size
= debug_swap
->external_ext_size
;
2228 void (*const swap_ext_in
) (bfd
*, void *, EXTR
*) = debug_swap
->swap_ext_in
;
2229 void (*const swap_sym_in
) (bfd
*, void *, SYMR
*) = debug_swap
->swap_sym_in
;
2230 void (*const swap_rfd_in
) (bfd
*, void *, RFDT
*) = debug_swap
->swap_rfd_in
;
2232 HDRR
*hdr
= &debug_info
->symbolic_header
;
2233 /* Running pointers */
2241 struct partial_symtab
*pst
;
2242 int textlow_not_set
= 1;
2243 int past_first_source_file
= 0;
2245 /* List of current psymtab's include files */
2246 char **psymtab_include_list
;
2247 int includes_allocated
;
2250 struct pst_map
*fdr_to_pst
;
2251 /* Index within current psymtab dependency list */
2252 struct partial_symtab
**dependency_list
;
2253 int dependencies_used
, dependencies_allocated
;
2254 struct cleanup
*old_chain
;
2256 enum language prev_language
;
2257 asection
*text_sect
;
2258 int relocatable
= 0;
2260 /* Irix 5.2 shared libraries have a fh->adr field of zero, but
2261 the shared libraries are prelinked at a high memory address.
2262 We have to adjust the start address of the object file for this case,
2263 by setting it to the start address of the first procedure in the file.
2264 But we should do no adjustments if we are debugging a .o file, where
2265 the text section (and fh->adr) really starts at zero. */
2266 text_sect
= bfd_get_section_by_name (cur_bfd
, ".text");
2267 if (text_sect
!= NULL
2268 && (bfd_get_section_flags (cur_bfd
, text_sect
) & SEC_RELOC
))
2271 extern_tab
= (EXTR
*) obstack_alloc (&objfile
->objfile_obstack
,
2272 sizeof (EXTR
) * hdr
->iextMax
);
2274 includes_allocated
= 30;
2276 psymtab_include_list
= (char **) alloca (includes_allocated
*
2278 next_symbol_text_func
= mdebug_next_symbol_text
;
2280 dependencies_allocated
= 30;
2281 dependencies_used
= 0;
2283 (struct partial_symtab
**) alloca (dependencies_allocated
*
2284 sizeof (struct partial_symtab
*));
2286 last_source_file
= NULL
;
2291 * Only parse the Local and External symbols, and the Relative FDR.
2292 * Fixup enough of the loader symtab to be able to use it.
2293 * Allocate space only for the file's portions we need to
2298 max_glevel
= MIN_GLEVEL
;
2300 /* Allocate the map FDR -> PST.
2301 Minor hack: -O3 images might claim some global data belongs
2302 to FDR -1. We`ll go along with that */
2303 fdr_to_pst
= (struct pst_map
*) xzalloc ((hdr
->ifdMax
+ 1) * sizeof *fdr_to_pst
);
2304 old_chain
= make_cleanup (xfree
, fdr_to_pst
);
2307 struct partial_symtab
*pst
= new_psymtab ("", objfile
);
2308 fdr_to_pst
[-1].pst
= pst
;
2312 /* Allocate the global pending list. */
2314 ((struct mdebug_pending
**)
2315 obstack_alloc (&objfile
->objfile_obstack
,
2316 hdr
->ifdMax
* sizeof (struct mdebug_pending
*)));
2317 memset (pending_list
, 0,
2318 hdr
->ifdMax
* sizeof (struct mdebug_pending
*));
2320 /* Pass 0 over external syms: swap them in. */
2321 ext_block
= (EXTR
*) xmalloc (hdr
->iextMax
* sizeof (EXTR
));
2322 make_cleanup (xfree
, ext_block
);
2324 ext_out
= (char *) debug_info
->external_ext
;
2325 ext_out_end
= ext_out
+ hdr
->iextMax
* external_ext_size
;
2327 for (; ext_out
< ext_out_end
; ext_out
+= external_ext_size
, ext_in
++)
2328 (*swap_ext_in
) (cur_bfd
, ext_out
, ext_in
);
2330 /* Pass 1 over external syms: Presize and partition the list */
2332 ext_in_end
= ext_in
+ hdr
->iextMax
;
2333 for (; ext_in
< ext_in_end
; ext_in
++)
2335 /* See calls to complain below. */
2336 if (ext_in
->ifd
>= -1
2337 && ext_in
->ifd
< hdr
->ifdMax
2338 && ext_in
->asym
.iss
>= 0
2339 && ext_in
->asym
.iss
< hdr
->issExtMax
)
2340 fdr_to_pst
[ext_in
->ifd
].n_globals
++;
2343 /* Pass 1.5 over files: partition out global symbol space */
2345 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++)
2347 fdr_to_pst
[f_idx
].globals_offset
= s_idx
;
2348 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
2349 fdr_to_pst
[f_idx
].n_globals
= 0;
2354 For ECOFF in ELF, we skip the creation of the minimal symbols.
2355 The ECOFF symbols should be a subset of the Elf symbols, and the
2356 section information of the elf symbols will be more accurate.
2357 FIXME! What about Irix 5's native linker?
2359 By default, Elf sections which don't exist in ECOFF
2360 get put in ECOFF's absolute section by the gnu linker.
2361 Since absolute sections don't get relocated, we
2362 end up calculating an address different from that of
2363 the symbol's minimal symbol (created earlier from the
2366 To fix this, either :
2367 1) don't create the duplicate symbol
2368 (assumes ECOFF symtab is a subset of the ELF symtab;
2369 assumes no side-effects result from ignoring ECOFF symbol)
2370 2) create it, only if lookup for existing symbol in ELF's minimal
2373 assumes no side-effects result from ignoring ECOFF symbol)
2374 3) create it, but lookup ELF's minimal symbol and use it's section
2375 during relocation, then modify "uniqify" phase to merge and
2376 eliminate the duplicate symbol
2377 (highly inefficient)
2379 I've implemented #1 here...
2380 Skip the creation of the minimal symbols based on the ECOFF
2383 /* Pass 2 over external syms: fill in external symbols */
2385 ext_in_end
= ext_in
+ hdr
->iextMax
;
2386 for (; ext_in
< ext_in_end
; ext_in
++)
2388 enum minimal_symbol_type ms_type
= mst_text
;
2389 CORE_ADDR svalue
= ext_in
->asym
.value
;
2391 /* The Irix 5 native tools seem to sometimes generate bogus
2392 external symbols. */
2393 if (ext_in
->ifd
< -1 || ext_in
->ifd
>= hdr
->ifdMax
)
2395 complaint (&symfile_complaints
,
2396 _("bad ifd for external symbol: %d (max %ld)"), ext_in
->ifd
,
2400 if (ext_in
->asym
.iss
< 0 || ext_in
->asym
.iss
>= hdr
->issExtMax
)
2402 complaint (&symfile_complaints
,
2403 _("bad iss for external symbol: %ld (max %ld)"),
2404 ext_in
->asym
.iss
, hdr
->issExtMax
);
2408 extern_tab
[fdr_to_pst
[ext_in
->ifd
].globals_offset
2409 + fdr_to_pst
[ext_in
->ifd
].n_globals
++] = *ext_in
;
2412 if (SC_IS_UNDEF (ext_in
->asym
.sc
) || ext_in
->asym
.sc
== scNil
)
2416 /* Pass 3 over files, over local syms: fill in static symbols */
2417 name
= debug_info
->ssext
+ ext_in
->asym
.iss
;
2419 /* Process ECOFF Symbol Types and Storage Classes */
2420 switch (ext_in
->asym
.st
)
2423 /* Beginnning of Procedure */
2424 svalue
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2427 /* Load time only static procs */
2428 ms_type
= mst_file_text
;
2429 svalue
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2432 /* External symbol */
2433 if (SC_IS_COMMON (ext_in
->asym
.sc
))
2435 /* The value of a common symbol is its size, not its address.
2439 else if (SC_IS_DATA (ext_in
->asym
.sc
))
2442 svalue
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
2444 else if (SC_IS_BSS (ext_in
->asym
.sc
))
2447 svalue
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_BSS (objfile
));
2449 else if (SC_IS_SBSS (ext_in
->asym
.sc
))
2452 svalue
+= ANOFFSET (objfile
->section_offsets
,
2453 get_section_index (objfile
, ".sbss"));
2461 /* On certain platforms, some extra label symbols can be
2462 generated by the linker. One possible usage for this kind
2463 of symbols is to represent the address of the begining of a
2464 given section. For instance, on Tru64 5.1, the address of
2465 the _ftext label is the start address of the .text section.
2467 The storage class of these symbols is usually directly
2468 related to the section to which the symbol refers. For
2469 instance, on Tru64 5.1, the storage class for the _fdata
2470 label is scData, refering to the .data section.
2472 It is actually possible that the section associated to the
2473 storage class of the label does not exist. On True64 5.1
2474 for instance, the libm.so shared library does not contain
2475 any .data section, although it contains a _fpdata label
2476 which storage class is scData... Since these symbols are
2477 usually useless for the debugger user anyway, we just
2478 discard these symbols.
2481 if (SC_IS_TEXT (ext_in
->asym
.sc
))
2483 if (objfile
->sect_index_text
== -1)
2486 ms_type
= mst_file_text
;
2487 svalue
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2489 else if (SC_IS_DATA (ext_in
->asym
.sc
))
2491 if (objfile
->sect_index_data
== -1)
2494 ms_type
= mst_file_data
;
2495 svalue
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
2497 else if (SC_IS_BSS (ext_in
->asym
.sc
))
2499 if (objfile
->sect_index_bss
== -1)
2502 ms_type
= mst_file_bss
;
2503 svalue
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_BSS (objfile
));
2505 else if (SC_IS_SBSS (ext_in
->asym
.sc
))
2507 const int sbss_sect_index
= get_section_index (objfile
, ".sbss");
2509 if (sbss_sect_index
== -1)
2512 ms_type
= mst_file_bss
;
2513 svalue
+= ANOFFSET (objfile
->section_offsets
, sbss_sect_index
);
2520 /* The alpha has the section start addresses in stLocal symbols
2521 whose name starts with a `.'. Skip those but complain for all
2522 other stLocal symbols.
2523 Irix6 puts the section start addresses in stNil symbols, skip
2529 ms_type
= mst_unknown
;
2530 unknown_ext_complaint (name
);
2532 if (!ECOFF_IN_ELF (cur_bfd
))
2533 record_minimal_symbol (name
, svalue
, ms_type
, ext_in
->asym
.sc
,
2537 /* Pass 3 over files, over local syms: fill in static symbols */
2538 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++)
2540 struct partial_symtab
*save_pst
;
2544 cur_fdr
= fh
= debug_info
->fdr
+ f_idx
;
2548 fdr_to_pst
[f_idx
].pst
= NULL
;
2552 /* Determine the start address for this object file from the
2553 file header and relocate it, except for Irix 5.2 zero fh->adr. */
2557 if (relocatable
|| textlow
!= 0)
2558 textlow
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2562 pst
= start_psymtab_common (objfile
, objfile
->section_offsets
,
2565 objfile
->global_psymbols
.next
,
2566 objfile
->static_psymbols
.next
);
2567 pst
->read_symtab_private
= ((char *)
2568 obstack_alloc (&objfile
->objfile_obstack
,
2569 sizeof (struct symloc
)));
2570 memset (pst
->read_symtab_private
, 0, sizeof (struct symloc
));
2573 FDR_IDX (pst
) = f_idx
;
2574 CUR_BFD (pst
) = cur_bfd
;
2575 DEBUG_SWAP (pst
) = debug_swap
;
2576 DEBUG_INFO (pst
) = debug_info
;
2577 PENDING_LIST (pst
) = pending_list
;
2579 /* The way to turn this into a symtab is to call... */
2580 pst
->read_symtab
= mdebug_psymtab_to_symtab
;
2582 /* Set up language for the pst.
2583 The language from the FDR is used if it is unambigious (e.g. cfront
2584 with native cc and g++ will set the language to C).
2585 Otherwise we have to deduce the language from the filename.
2586 Native ecoff has every header file in a separate FDR, so
2587 deduce_language_from_filename will return language_unknown for
2588 a header file, which is not what we want.
2589 But the FDRs for the header files are after the FDR for the source
2590 file, so we can assign the language of the source file to the
2591 following header files. Then we save the language in the private
2592 pst data so that we can reuse it when building symtabs. */
2593 prev_language
= psymtab_language
;
2597 case langCplusplusV2
:
2598 psymtab_language
= language_cplus
;
2601 psymtab_language
= deduce_language_from_filename (fdr_name (fh
));
2604 if (psymtab_language
== language_unknown
)
2605 psymtab_language
= prev_language
;
2606 PST_PRIVATE (pst
)->pst_language
= psymtab_language
;
2608 pst
->texthigh
= pst
->textlow
;
2610 /* For stabs-in-ecoff files, the second symbol must be @stab.
2611 This symbol is emitted by mips-tfile to signal that the
2612 current object file uses encapsulated stabs instead of mips
2613 ecoff for local symbols. (It is the second symbol because
2614 the first symbol is the stFile used to signal the start of a
2616 processing_gcc_compilation
= 0;
2619 (*swap_sym_in
) (cur_bfd
,
2620 ((char *) debug_info
->external_sym
2621 + (fh
->isymBase
+ 1) * external_sym_size
),
2623 if (strcmp (debug_info
->ss
+ fh
->issBase
+ sh
.iss
,
2625 processing_gcc_compilation
= 2;
2628 if (processing_gcc_compilation
!= 0)
2630 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++)
2635 (*swap_sym_in
) (cur_bfd
,
2636 (((char *) debug_info
->external_sym
)
2637 + (fh
->isymBase
+ cur_sdx
) * external_sym_size
),
2639 type_code
= ECOFF_UNMARK_STAB (sh
.index
);
2640 if (!ECOFF_IS_STAB (&sh
))
2642 if (sh
.st
== stProc
|| sh
.st
== stStaticProc
)
2647 sh
.value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2648 if (sh
.st
== stStaticProc
)
2650 namestring
= debug_info
->ss
+ fh
->issBase
+ sh
.iss
;
2651 record_minimal_symbol (namestring
, sh
.value
,
2652 mst_file_text
, sh
.sc
,
2655 procaddr
= sh
.value
;
2657 isym
= AUX_GET_ISYM (fh
->fBigendian
,
2658 (debug_info
->external_aux
2661 (*swap_sym_in
) (cur_bfd
,
2662 ((char *) debug_info
->external_sym
2663 + ((fh
->isymBase
+ isym
- 1)
2664 * external_sym_size
)),
2668 CORE_ADDR high
= procaddr
+ sh
.value
;
2670 /* Kludge for Irix 5.2 zero fh->adr. */
2672 && (pst
->textlow
== 0 || procaddr
< pst
->textlow
))
2673 pst
->textlow
= procaddr
;
2674 if (high
> pst
->texthigh
)
2675 pst
->texthigh
= high
;
2678 else if (sh
.st
== stStatic
)
2693 namestring
= debug_info
->ss
+ fh
->issBase
+ sh
.iss
;
2694 sh
.value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
2695 record_minimal_symbol (namestring
, sh
.value
,
2696 mst_file_data
, sh
.sc
,
2701 /* FIXME! Shouldn't this use cases for bss,
2702 then have the default be abs? */
2703 namestring
= debug_info
->ss
+ fh
->issBase
+ sh
.iss
;
2704 sh
.value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_BSS (objfile
));
2705 record_minimal_symbol (namestring
, sh
.value
,
2706 mst_file_bss
, sh
.sc
,
2713 /* Handle stabs continuation */
2715 char *stabstring
= debug_info
->ss
+ fh
->issBase
+ sh
.iss
;
2716 int len
= strlen (stabstring
);
2717 while (stabstring
[len
- 1] == '\\')
2720 char *stabstring1
= stabstring
;
2724 /* Ignore continuation char from 1st string */
2727 /* Read next stabstring */
2729 (*swap_sym_in
) (cur_bfd
,
2730 (((char *) debug_info
->external_sym
)
2731 + (fh
->isymBase
+ cur_sdx
)
2732 * external_sym_size
),
2734 stabstring2
= debug_info
->ss
+ fh
->issBase
+ sh2
.iss
;
2735 len2
= strlen (stabstring2
);
2737 /* Concatinate stabstring2 with stabstring1 */
2739 && stabstring
!= debug_info
->ss
+ fh
->issBase
+ sh
.iss
)
2740 stabstring
= xrealloc (stabstring
, len
+ len2
+ 1);
2743 stabstring
= xmalloc (len
+ len2
+ 1);
2744 strcpy (stabstring
, stabstring1
);
2746 strcpy (stabstring
+ len
, stabstring2
);
2754 * Standard, external, non-debugger, symbols
2757 case N_TEXT
| N_EXT
:
2758 case N_NBTEXT
| N_EXT
:
2759 sh
.value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2762 case N_DATA
| N_EXT
:
2763 case N_NBDATA
| N_EXT
:
2764 sh
.value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
2769 case N_NBBSS
| N_EXT
:
2770 case N_SETV
| N_EXT
: /* FIXME, is this in BSS? */
2771 sh
.value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_BSS (objfile
));
2778 /* Standard, local, non-debugger, symbols */
2782 /* We need to be able to deal with both N_FN or N_TEXT,
2783 because we have no way of knowing whether the sys-supplied ld
2784 or GNU ld was used to make the executable. Sequents throw
2785 in another wrinkle -- they renumbered N_FN. */
2793 sh
.value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
2796 case N_UNDF
| N_EXT
:
2797 continue; /* Just undefined, not COMMON */
2802 /* Lots of symbol types we can just ignore. */
2809 /* Keep going . . . */
2812 * Special symbol types for GNU
2815 case N_INDR
| N_EXT
:
2817 case N_SETA
| N_EXT
:
2819 case N_SETT
| N_EXT
:
2821 case N_SETD
| N_EXT
:
2823 case N_SETB
| N_EXT
:
2834 static int prev_so_symnum
= -10;
2835 static int first_so_symnum
;
2837 int prev_textlow_not_set
;
2839 valu
= sh
.value
+ ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
2841 prev_textlow_not_set
= textlow_not_set
;
2843 /* A zero value is probably an indication for the SunPRO 3.0
2844 compiler. end_psymtab explicitly tests for zero, so
2845 don't relocate it. */
2848 && gdbarch_sofun_address_maybe_missing (gdbarch
))
2850 textlow_not_set
= 1;
2854 textlow_not_set
= 0;
2856 past_first_source_file
= 1;
2858 if (prev_so_symnum
!= symnum
- 1)
2859 { /* Here if prev stab wasn't N_SO */
2860 first_so_symnum
= symnum
;
2864 pst
= (struct partial_symtab
*) 0;
2866 dependencies_used
= 0;
2870 prev_so_symnum
= symnum
;
2872 /* End the current partial symtab and start a new one */
2874 /* SET_NAMESTRING ();*/
2875 namestring
= stabstring
;
2877 /* Null name means end of .o file. Don't start a new one. */
2878 if (*namestring
== '\000')
2881 /* Some compilers (including gcc) emit a pair of initial N_SOs.
2882 The first one is a directory name; the second the file name.
2883 If pst exists, is empty, and has a filename ending in '/',
2884 we assume the previous N_SO was a directory name. */
2886 p
= strrchr (namestring
, '/');
2887 if (p
&& *(p
+ 1) == '\000')
2888 continue; /* Simply ignore directory name SOs */
2890 /* Some other compilers (C++ ones in particular) emit useless
2891 SOs for non-existant .c files. We ignore all subsequent SOs that
2892 immediately follow the first. */
2904 enum language tmp_language
;
2905 /* Mark down an include file in the current psymtab */
2907 /* SET_NAMESTRING ();*/
2908 namestring
= stabstring
;
2910 tmp_language
= deduce_language_from_filename (namestring
);
2912 /* Only change the psymtab's language if we've learned
2913 something useful (eg. tmp_language is not language_unknown).
2914 In addition, to match what start_subfile does, never change
2916 if (tmp_language
!= language_unknown
2917 && (tmp_language
!= language_c
2918 || psymtab_language
!= language_cplus
))
2919 psymtab_language
= tmp_language
;
2921 /* In C++, one may expect the same filename to come round many
2922 times, when code is coming alternately from the main file
2923 and from inline functions in other files. So I check to see
2924 if this is a file we've seen before -- either the main
2925 source file, or a previously included file.
2927 This seems to be a lot of time to be spending on N_SOL, but
2928 things like "break c-exp.y:435" need to work (I
2929 suppose the psymtab_include_list could be hashed or put
2930 in a binary tree, if profiling shows this is a major hog). */
2931 if (pst
&& strcmp (namestring
, pst
->filename
) == 0)
2935 for (i
= 0; i
< includes_used
; i
++)
2936 if (strcmp (namestring
,
2937 psymtab_include_list
[i
]) == 0)
2946 psymtab_include_list
[includes_used
++] = namestring
;
2947 if (includes_used
>= includes_allocated
)
2949 char **orig
= psymtab_include_list
;
2951 psymtab_include_list
= (char **)
2952 alloca ((includes_allocated
*= 2) *
2954 memcpy (psymtab_include_list
, orig
,
2955 includes_used
* sizeof (char *));
2959 case N_LSYM
: /* Typedef or automatic variable. */
2960 case N_STSYM
: /* Data seg var -- static */
2961 case N_LCSYM
: /* BSS " */
2962 case N_ROSYM
: /* Read-only data seg var -- static. */
2963 case N_NBSTS
: /* Gould nobase. */
2964 case N_NBLCS
: /* symbols. */
2966 case N_GSYM
: /* Global (extern) variable; can be
2967 data or bss (sigh FIXME). */
2969 /* Following may probably be ignored; I'll leave them here
2970 for now (until I do Pascal and Modula 2 extensions). */
2972 case N_PC
: /* I may or may not need this; I
2974 case N_M2C
: /* I suspect that I can ignore this here. */
2975 case N_SCOPE
: /* Same. */
2977 /* SET_NAMESTRING ();*/
2978 namestring
= stabstring
;
2979 p
= (char *) strchr (namestring
, ':');
2981 continue; /* Not a debugging symbol. */
2985 /* Main processing section for debugging symbols which
2986 the initial read through the symbol tables needs to worry
2987 about. If we reach this point, the symbol which we are
2988 considering is definitely one we are interested in.
2989 p must also contain the (valid) index into the namestring
2990 which indicates the debugging type symbol. */
2995 sh
.value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
2997 if (gdbarch_static_transform_name_p (gdbarch
))
2998 namestring
= gdbarch_static_transform_name
2999 (gdbarch
, namestring
);
3001 add_psymbol_to_list (namestring
, p
- namestring
,
3002 VAR_DOMAIN
, LOC_STATIC
,
3003 &objfile
->static_psymbols
,
3005 psymtab_language
, objfile
);
3008 sh
.value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
3009 /* The addresses in these entries are reported to be
3010 wrong. See the code that reads 'G's for symtabs. */
3011 add_psymbol_to_list (namestring
, p
- namestring
,
3012 VAR_DOMAIN
, LOC_STATIC
,
3013 &objfile
->global_psymbols
,
3015 psymtab_language
, objfile
);
3019 /* When a 'T' entry is defining an anonymous enum, it
3020 may have a name which is the empty string, or a
3021 single space. Since they're not really defining a
3022 symbol, those shouldn't go in the partial symbol
3023 table. We do pick up the elements of such enums at
3024 'check_enum:', below. */
3025 if (p
>= namestring
+ 2
3026 || (p
== namestring
+ 1
3027 && namestring
[0] != ' '))
3029 add_psymbol_to_list (namestring
, p
- namestring
,
3030 STRUCT_DOMAIN
, LOC_TYPEDEF
,
3031 &objfile
->static_psymbols
,
3033 psymtab_language
, objfile
);
3036 /* Also a typedef with the same name. */
3037 add_psymbol_to_list (namestring
, p
- namestring
,
3038 VAR_DOMAIN
, LOC_TYPEDEF
,
3039 &objfile
->static_psymbols
,
3041 psymtab_language
, objfile
);
3047 if (p
!= namestring
) /* a name is there, not just :T... */
3049 add_psymbol_to_list (namestring
, p
- namestring
,
3050 VAR_DOMAIN
, LOC_TYPEDEF
,
3051 &objfile
->static_psymbols
,
3053 psymtab_language
, objfile
);
3056 /* If this is an enumerated type, we need to
3057 add all the enum constants to the partial symbol
3058 table. This does not cover enums without names, e.g.
3059 "enum {a, b} c;" in C, but fortunately those are
3060 rare. There is no way for GDB to find those from the
3061 enum type without spending too much time on it. Thus
3062 to solve this problem, the compiler needs to put out the
3063 enum in a nameless type. GCC2 does this. */
3065 /* We are looking for something of the form
3066 <name> ":" ("t" | "T") [<number> "="] "e"
3067 {<constant> ":" <value> ","} ";". */
3069 /* Skip over the colon and the 't' or 'T'. */
3071 /* This type may be given a number. Also, numbers can come
3072 in pairs like (0,26). Skip over it. */
3073 while ((*p
>= '0' && *p
<= '9')
3074 || *p
== '(' || *p
== ',' || *p
== ')'
3080 /* The aix4 compiler emits extra crud before the members. */
3083 /* Skip over the type (?). */
3087 /* Skip over the colon. */
3091 /* We have found an enumerated type. */
3092 /* According to comments in read_enum_type
3093 a comma could end it instead of a semicolon.
3094 I don't know where that happens.
3096 while (*p
&& *p
!= ';' && *p
!= ',')
3100 /* Check for and handle cretinous dbx symbol name
3102 if (*p
== '\\' || (*p
== '?' && p
[1] == '\0'))
3103 p
= next_symbol_text (objfile
);
3105 /* Point to the character after the name
3106 of the enum constant. */
3107 for (q
= p
; *q
&& *q
!= ':'; q
++)
3109 /* Note that the value doesn't matter for
3110 enum constants in psymtabs, just in symtabs. */
3111 add_psymbol_to_list (p
, q
- p
,
3112 VAR_DOMAIN
, LOC_CONST
,
3113 &objfile
->static_psymbols
, 0,
3114 0, psymtab_language
, objfile
);
3115 /* Point past the name. */
3117 /* Skip over the value. */
3118 while (*p
&& *p
!= ',')
3120 /* Advance past the comma. */
3127 /* Constant, e.g. from "const" in Pascal. */
3128 add_psymbol_to_list (namestring
, p
- namestring
,
3129 VAR_DOMAIN
, LOC_CONST
,
3130 &objfile
->static_psymbols
, sh
.value
,
3131 0, psymtab_language
, objfile
);
3137 int name_len
= p
- namestring
;
3138 char *name
= xmalloc (name_len
+ 1);
3139 memcpy (name
, namestring
, name_len
);
3140 name
[name_len
] = '\0';
3141 function_outside_compilation_unit_complaint (name
);
3144 sh
.value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3145 add_psymbol_to_list (namestring
, p
- namestring
,
3146 VAR_DOMAIN
, LOC_BLOCK
,
3147 &objfile
->static_psymbols
,
3149 psymtab_language
, objfile
);
3152 /* Global functions were ignored here, but now they
3153 are put into the global psymtab like one would expect.
3154 They're also in the minimal symbol table. */
3158 int name_len
= p
- namestring
;
3159 char *name
= xmalloc (name_len
+ 1);
3160 memcpy (name
, namestring
, name_len
);
3161 name
[name_len
] = '\0';
3162 function_outside_compilation_unit_complaint (name
);
3165 sh
.value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3166 add_psymbol_to_list (namestring
, p
- namestring
,
3167 VAR_DOMAIN
, LOC_BLOCK
,
3168 &objfile
->global_psymbols
,
3170 psymtab_language
, objfile
);
3173 /* Two things show up here (hopefully); static symbols of
3174 local scope (static used inside braces) or extensions
3175 of structure symbols. We can ignore both. */
3189 case '#': /* for symbol identification (used in live ranges) */
3193 /* It is a C++ nested symbol. We don't need to record it
3194 (I don't think); if we try to look up foo::bar::baz,
3195 then symbols for the symtab containing foo should get
3196 read in, I think. */
3197 /* Someone says sun cc puts out symbols like
3198 /foo/baz/maclib::/usr/local/bin/maclib,
3199 which would get here with a symbol type of ':'. */
3203 /* Unexpected symbol descriptor. The second and subsequent stabs
3204 of a continued stab can show up here. The question is
3205 whether they ever can mimic a normal stab--it would be
3206 nice if not, since we certainly don't want to spend the
3207 time searching to the end of every string looking for
3210 complaint (&symfile_complaints
,
3211 _("unknown symbol descriptor `%c'"), p
[1]);
3213 /* Ignore it; perhaps it is an extension that we don't
3222 /* Solaris 2 end of module, finish current partial
3223 symbol table. END_PSYMTAB will set
3224 pst->texthigh to the proper value, which is
3225 necessary if a module compiled without
3226 debugging info follows this module. */
3228 && gdbarch_sofun_address_maybe_missing (gdbarch
))
3230 pst
= (struct partial_symtab
*) 0;
3232 dependencies_used
= 0;
3237 if (sh
.value
> save_pst
->texthigh
)
3238 save_pst
->texthigh
= sh
.value
;
3243 case N_SSYM
: /* Claim: Structure or union element.
3244 Hopefully, I can ignore this. */
3245 case N_ENTRY
: /* Alternate entry point; can ignore. */
3246 case N_MAIN
: /* Can definitely ignore this. */
3247 case N_CATCH
: /* These are GNU C++ extensions */
3248 case N_EHDECL
: /* that can safely be ignored here. */
3258 case N_NSYMS
: /* Ultrix 4.0: symbol count */
3259 case N_DEFD
: /* GNU Modula-2 */
3260 case N_ALIAS
: /* SunPro F77: alias name, ignore for now. */
3262 case N_OBJ
: /* useless types from Solaris */
3264 /* These symbols aren't interesting; don't worry about them */
3269 /* If we haven't found it yet, ignore it. It's probably some
3270 new type we don't know about yet. */
3271 complaint (&symfile_complaints
, _("unknown symbol type %s"),
3272 hex_string (type_code
)); /*CUR_SYMBOL_TYPE*/
3276 && stabstring
!= debug_info
->ss
+ fh
->issBase
+ sh
.iss
)
3279 /* end - Handle continuation */
3284 for (cur_sdx
= 0; cur_sdx
< fh
->csym
;)
3287 enum address_class
class;
3289 (*swap_sym_in
) (cur_bfd
,
3290 ((char *) debug_info
->external_sym
3291 + ((fh
->isymBase
+ cur_sdx
)
3292 * external_sym_size
)),
3295 if (ECOFF_IS_STAB (&sh
))
3301 /* Non absolute static symbols go into the minimal table. */
3302 if (SC_IS_UNDEF (sh
.sc
) || sh
.sc
== scNil
3303 || (sh
.index
== indexNil
3304 && (sh
.st
!= stStatic
|| sh
.sc
== scAbs
)))
3306 /* FIXME, premature? */
3311 name
= debug_info
->ss
+ fh
->issBase
+ sh
.iss
;
3317 /* The value of a stEnd symbol is the displacement from the
3318 corresponding start symbol value, do not relocate it. */
3320 sh
.value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3327 sh
.value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
3331 sh
.value
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_BSS (objfile
));
3342 prim_record_minimal_symbol_and_info (name
, sh
.value
,
3343 mst_file_text
, NULL
,
3344 SECT_OFF_TEXT (objfile
), NULL
,
3350 /* Ignore all parameter symbol records. */
3351 if (sh
.index
>= hdr
->iauxMax
)
3353 /* Should not happen, but does when cross-compiling
3354 with the MIPS compiler. FIXME -- pull later. */
3355 index_complaint (name
);
3356 new_sdx
= cur_sdx
+ 1; /* Don't skip at all */
3359 new_sdx
= AUX_GET_ISYM (fh
->fBigendian
,
3360 (debug_info
->external_aux
3364 if (new_sdx
<= cur_sdx
)
3366 /* This should not happen either... FIXME. */
3367 complaint (&symfile_complaints
,
3368 _("bad proc end in aux found from symbol %s"),
3370 new_sdx
= cur_sdx
+ 1; /* Don't skip backward */
3373 /* For stProc symbol records, we need to check the
3374 storage class as well, as only (stProc, scText)
3375 entries represent "real" procedures - See the
3376 Compaq document titled "Object File / Symbol Table
3377 Format Specification" for more information. If the
3378 storage class is not scText, we discard the whole
3379 block of symbol records for this stProc. */
3380 if (sh
.st
== stProc
&& sh
.sc
!= scText
)
3383 /* Usually there is a local and a global stProc symbol
3384 for a function. This means that the function name
3385 has already been entered into the mimimal symbol table
3386 while processing the global symbols in pass 2 above.
3387 One notable exception is the PROGRAM name from
3388 f77 compiled executables, it is only put out as
3389 local stProc symbol, and a global MAIN__ stProc symbol
3390 points to it. It doesn't matter though, as gdb is
3391 still able to find the PROGRAM name via the partial
3392 symbol table, and the MAIN__ symbol via the minimal
3394 if (sh
.st
== stProc
)
3395 add_psymbol_to_list (name
, strlen (name
),
3396 VAR_DOMAIN
, LOC_BLOCK
,
3397 &objfile
->global_psymbols
,
3398 0, sh
.value
, psymtab_language
, objfile
);
3400 add_psymbol_to_list (name
, strlen (name
),
3401 VAR_DOMAIN
, LOC_BLOCK
,
3402 &objfile
->static_psymbols
,
3403 0, sh
.value
, psymtab_language
, objfile
);
3405 procaddr
= sh
.value
;
3408 (*swap_sym_in
) (cur_bfd
,
3409 ((char *) debug_info
->external_sym
3410 + ((fh
->isymBase
+ cur_sdx
- 1)
3411 * external_sym_size
)),
3416 /* Kludge for Irix 5.2 zero fh->adr. */
3418 && (pst
->textlow
== 0 || procaddr
< pst
->textlow
))
3419 pst
->textlow
= procaddr
;
3421 high
= procaddr
+ sh
.value
;
3422 if (high
> pst
->texthigh
)
3423 pst
->texthigh
= high
;
3426 case stStatic
: /* Variable */
3427 if (SC_IS_DATA (sh
.sc
))
3428 prim_record_minimal_symbol_and_info (name
, sh
.value
,
3429 mst_file_data
, NULL
,
3430 SECT_OFF_DATA (objfile
),
3434 prim_record_minimal_symbol_and_info (name
, sh
.value
,
3436 SECT_OFF_BSS (objfile
),
3442 case stIndirect
: /* Irix5 forward declaration */
3443 /* Skip forward declarations from Irix5 cc */
3446 case stTypedef
: /* Typedef */
3447 /* Skip typedefs for forward declarations and opaque
3448 structs from alpha and mips cc. */
3449 if (sh
.iss
== 0 || has_opaque_xref (fh
, &sh
))
3451 class = LOC_TYPEDEF
;
3454 case stConstant
: /* Constant decl */
3461 case stBlock
: /* { }, str, un, enum */
3462 /* Do not create a partial symbol for cc unnamed aggregates
3463 and gcc empty aggregates. */
3464 if ((sh
.sc
== scInfo
3465 || SC_IS_COMMON (sh
.sc
))
3467 && sh
.index
!= cur_sdx
+ 2)
3469 add_psymbol_to_list (name
, strlen (name
),
3470 STRUCT_DOMAIN
, LOC_TYPEDEF
,
3471 &objfile
->static_psymbols
,
3473 psymtab_language
, objfile
);
3475 handle_psymbol_enumerators (objfile
, fh
, sh
.st
, sh
.value
);
3477 /* Skip over the block */
3479 if (new_sdx
<= cur_sdx
)
3481 /* This happens with the Ultrix kernel. */
3482 complaint (&symfile_complaints
,
3483 _("bad aux index at block symbol %s"), name
);
3484 new_sdx
= cur_sdx
+ 1; /* Don't skip backward */
3489 case stFile
: /* File headers */
3490 case stLabel
: /* Labels */
3491 case stEnd
: /* Ends of files */
3494 case stLocal
: /* Local variables */
3495 /* Normally these are skipped because we skip over
3496 all blocks we see. However, these can occur
3497 as visible symbols in a .h file that contains code. */
3501 /* Both complaints are valid: one gives symbol name,
3502 the other the offending symbol type. */
3503 complaint (&symfile_complaints
, _("unknown local symbol %s"),
3505 complaint (&symfile_complaints
, _("with type %d"), sh
.st
);
3509 /* Use this gdb symbol */
3510 add_psymbol_to_list (name
, strlen (name
),
3512 &objfile
->static_psymbols
,
3513 0, sh
.value
, psymtab_language
, objfile
);
3515 cur_sdx
++; /* Go to next file symbol */
3518 /* Now do enter the external symbols. */
3519 ext_ptr
= &extern_tab
[fdr_to_pst
[f_idx
].globals_offset
];
3520 cur_sdx
= fdr_to_pst
[f_idx
].n_globals
;
3521 PST_PRIVATE (save_pst
)->extern_count
= cur_sdx
;
3522 PST_PRIVATE (save_pst
)->extern_tab
= ext_ptr
;
3523 for (; --cur_sdx
>= 0; ext_ptr
++)
3525 enum address_class
class;
3530 if (ext_ptr
->ifd
!= f_idx
)
3531 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
3532 psh
= &ext_ptr
->asym
;
3534 /* Do not add undefined symbols to the partial symbol table. */
3535 if (SC_IS_UNDEF (psh
->sc
) || psh
->sc
== scNil
)
3538 svalue
= psh
->value
;
3543 svalue
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_TEXT (objfile
));
3550 svalue
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_DATA (objfile
));
3554 svalue
+= ANOFFSET (objfile
->section_offsets
, SECT_OFF_BSS (objfile
));
3561 /* These are generated for static symbols in .o files,
3566 /* External procedure symbols have been entered
3567 into the minimal symbol table in pass 2 above.
3568 Ignore them, as parse_external will ignore them too. */
3574 unknown_ext_complaint (debug_info
->ssext
+ psh
->iss
);
3575 /* Fall through, pretend it's global. */
3577 /* Global common symbols are resolved by the runtime loader,
3579 if (SC_IS_COMMON (psh
->sc
))
3585 name
= debug_info
->ssext
+ psh
->iss
;
3586 add_psymbol_to_list (name
, strlen (name
),
3588 &objfile
->global_psymbols
,
3590 psymtab_language
, objfile
);
3594 /* Link pst to FDR. end_psymtab returns NULL if the psymtab was
3595 empty and put on the free list. */
3596 fdr_to_pst
[f_idx
].pst
= end_psymtab (save_pst
,
3597 psymtab_include_list
, includes_used
,
3598 -1, save_pst
->texthigh
,
3599 dependency_list
, dependencies_used
, textlow_not_set
);
3601 dependencies_used
= 0;
3603 /* The objfile has its functions reordered if this partial symbol
3604 table overlaps any other partial symbol table.
3605 We cannot assume a reordered objfile if a partial symbol table
3606 is contained within another partial symbol table, as partial symbol
3607 tables for include files with executable code are contained
3608 within the partial symbol table for the including source file,
3609 and we do not want to flag the objfile reordered for these cases.
3611 This strategy works well for Irix-5.2 shared libraries, but we
3612 might have to use a more elaborate (and slower) algorithm for
3614 save_pst
= fdr_to_pst
[f_idx
].pst
;
3615 if (save_pst
!= NULL
3616 && save_pst
->textlow
!= 0
3617 && !(objfile
->flags
& OBJF_REORDERED
))
3619 ALL_OBJFILE_PSYMTABS (objfile
, pst
)
3622 && save_pst
->textlow
>= pst
->textlow
3623 && save_pst
->textlow
< pst
->texthigh
3624 && save_pst
->texthigh
> pst
->texthigh
)
3626 objfile
->flags
|= OBJF_REORDERED
;
3633 /* Now scan the FDRs for dependencies */
3634 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++)
3636 fh
= f_idx
+ debug_info
->fdr
;
3637 pst
= fdr_to_pst
[f_idx
].pst
;
3639 if (pst
== (struct partial_symtab
*) NULL
)
3642 /* This should catch stabs-in-ecoff. */
3646 /* Skip the first file indirect entry as it is a self dependency
3647 for source files or a reverse .h -> .c dependency for header files. */
3648 pst
->number_of_dependencies
= 0;
3650 ((struct partial_symtab
**)
3651 obstack_alloc (&objfile
->objfile_obstack
,
3653 * sizeof (struct partial_symtab
*))));
3654 for (s_idx
= 1; s_idx
< fh
->crfd
; s_idx
++)
3658 (*swap_rfd_in
) (cur_bfd
,
3659 ((char *) debug_info
->external_rfd
3660 + (fh
->rfdBase
+ s_idx
) * external_rfd_size
),
3662 if (rh
< 0 || rh
>= hdr
->ifdMax
)
3664 complaint (&symfile_complaints
, _("bad file number %ld"), rh
);
3668 /* Skip self dependencies of header files. */
3672 /* Do not add to dependeny list if psymtab was empty. */
3673 if (fdr_to_pst
[rh
].pst
== (struct partial_symtab
*) NULL
)
3675 pst
->dependencies
[pst
->number_of_dependencies
++] = fdr_to_pst
[rh
].pst
;
3679 /* Remove the dummy psymtab created for -O3 images above, if it is
3680 still empty, to enable the detection of stripped executables. */
3681 if (objfile
->psymtabs
->next
== NULL
3682 && objfile
->psymtabs
->number_of_dependencies
== 0
3683 && objfile
->psymtabs
->n_global_syms
== 0
3684 && objfile
->psymtabs
->n_static_syms
== 0)
3685 objfile
->psymtabs
= NULL
;
3686 do_cleanups (old_chain
);
3689 /* If the current psymbol has an enumerated type, we need to add
3690 all the the enum constants to the partial symbol table. */
3693 handle_psymbol_enumerators (struct objfile
*objfile
, FDR
*fh
, int stype
,
3696 const bfd_size_type external_sym_size
= debug_swap
->external_sym_size
;
3697 void (*const swap_sym_in
) (bfd
*, void *, SYMR
*) = debug_swap
->swap_sym_in
;
3698 char *ext_sym
= ((char *) debug_info
->external_sym
3699 + ((fh
->isymBase
+ cur_sdx
+ 1) * external_sym_size
));
3709 /* It is an enumerated type if the next symbol entry is a stMember
3710 and its auxiliary index is indexNil or its auxiliary entry
3711 is a plain btNil or btVoid.
3712 Alpha cc -migrate enums are recognized by a zero index and
3713 a zero symbol value.
3714 DU 4.0 cc enums are recognized by a member type of btEnum without
3715 qualifiers and a zero symbol value. */
3716 (*swap_sym_in
) (cur_bfd
, ext_sym
, &sh
);
3717 if (sh
.st
!= stMember
)
3720 if (sh
.index
== indexNil
3721 || (sh
.index
== 0 && svalue
== 0))
3723 (*debug_swap
->swap_tir_in
) (fh
->fBigendian
,
3724 &(debug_info
->external_aux
3725 + fh
->iauxBase
+ sh
.index
)->a_ti
,
3727 if ((tir
.bt
!= btNil
3729 && (tir
.bt
!= btEnum
|| svalue
!= 0))
3730 || tir
.tq0
!= tqNil
)
3742 (*swap_sym_in
) (cur_bfd
, ext_sym
, &sh
);
3743 if (sh
.st
!= stMember
)
3745 name
= debug_info
->ss
+ cur_fdr
->issBase
+ sh
.iss
;
3747 /* Note that the value doesn't matter for enum constants
3748 in psymtabs, just in symtabs. */
3749 add_psymbol_to_list (name
, strlen (name
),
3750 VAR_DOMAIN
, LOC_CONST
,
3751 &objfile
->static_psymbols
, 0,
3752 (CORE_ADDR
) 0, psymtab_language
, objfile
);
3753 ext_sym
+= external_sym_size
;
3757 /* Get the next symbol. OBJFILE is unused. */
3760 mdebug_next_symbol_text (struct objfile
*objfile
)
3765 (*debug_swap
->swap_sym_in
) (cur_bfd
,
3766 ((char *) debug_info
->external_sym
3767 + ((cur_fdr
->isymBase
+ cur_sdx
)
3768 * debug_swap
->external_sym_size
)),
3770 return debug_info
->ss
+ cur_fdr
->issBase
+ sh
.iss
;
3773 /* Ancillary function to psymtab_to_symtab(). Does all the work
3774 for turning the partial symtab PST into a symtab, recurring
3775 first on all dependent psymtabs. The argument FILENAME is
3776 only passed so we can see in debug stack traces what file
3779 This function has a split personality, based on whether the
3780 symbol table contains ordinary ecoff symbols, or stabs-in-ecoff.
3781 The flow of control and even the memory allocation differs. FIXME. */
3784 psymtab_to_symtab_1 (struct partial_symtab
*pst
, char *filename
)
3786 bfd_size_type external_sym_size
;
3787 bfd_size_type external_pdr_size
;
3788 void (*swap_sym_in
) (bfd
*, void *, SYMR
*);
3789 void (*swap_pdr_in
) (bfd
*, void *, PDR
*);
3791 struct symtab
*st
= NULL
;
3793 struct linetable
*lines
;
3794 CORE_ADDR lowest_pdr_addr
= 0;
3795 int last_symtab_ended
= 0;
3801 /* Read in all partial symbtabs on which this one is dependent.
3802 NOTE that we do have circular dependencies, sigh. We solved
3803 that by setting pst->readin before this point. */
3805 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
3806 if (!pst
->dependencies
[i
]->readin
)
3808 /* Inform about additional files to be read in. */
3811 fputs_filtered (" ", gdb_stdout
);
3813 fputs_filtered ("and ", gdb_stdout
);
3815 printf_filtered ("%s...",
3816 pst
->dependencies
[i
]->filename
);
3817 wrap_here (""); /* Flush output */
3818 gdb_flush (gdb_stdout
);
3820 /* We only pass the filename for debug purposes */
3821 psymtab_to_symtab_1 (pst
->dependencies
[i
],
3822 pst
->dependencies
[i
]->filename
);
3825 /* Do nothing if this is a dummy psymtab. */
3827 if (pst
->n_global_syms
== 0 && pst
->n_static_syms
== 0
3828 && pst
->textlow
== 0 && pst
->texthigh
== 0)
3831 /* Now read the symbols for this symtab */
3833 cur_bfd
= CUR_BFD (pst
);
3834 debug_swap
= DEBUG_SWAP (pst
);
3835 debug_info
= DEBUG_INFO (pst
);
3836 pending_list
= PENDING_LIST (pst
);
3837 external_sym_size
= debug_swap
->external_sym_size
;
3838 external_pdr_size
= debug_swap
->external_pdr_size
;
3839 swap_sym_in
= debug_swap
->swap_sym_in
;
3840 swap_pdr_in
= debug_swap
->swap_pdr_in
;
3841 current_objfile
= pst
->objfile
;
3842 cur_fd
= FDR_IDX (pst
);
3843 fh
= ((cur_fd
== -1)
3845 : debug_info
->fdr
+ cur_fd
);
3848 /* See comment in parse_partial_symbols about the @stabs sentinel. */
3849 processing_gcc_compilation
= 0;
3850 if (fh
!= (FDR
*) NULL
&& fh
->csym
>= 2)
3854 (*swap_sym_in
) (cur_bfd
,
3855 ((char *) debug_info
->external_sym
3856 + (fh
->isymBase
+ 1) * external_sym_size
),
3858 if (strcmp (debug_info
->ss
+ fh
->issBase
+ sh
.iss
,
3861 /* We indicate that this is a GCC compilation so that certain
3862 features will be enabled in stabsread/dbxread. */
3863 processing_gcc_compilation
= 2;
3867 if (processing_gcc_compilation
!= 0)
3870 /* This symbol table contains stabs-in-ecoff entries. */
3872 /* Parse local symbols first */
3874 if (fh
->csym
<= 2) /* FIXME, this blows psymtab->symtab ptr */
3876 current_objfile
= NULL
;
3879 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++)
3885 (*swap_sym_in
) (cur_bfd
,
3886 (((char *) debug_info
->external_sym
)
3887 + (fh
->isymBase
+ cur_sdx
) * external_sym_size
),
3889 name
= debug_info
->ss
+ fh
->issBase
+ sh
.iss
;
3891 /* XXX This is a hack. It will go away! */
3892 if (ECOFF_IS_STAB (&sh
) || (name
[0] == '#'))
3894 int type_code
= ECOFF_UNMARK_STAB (sh
.index
);
3896 /* We should never get non N_STAB symbols here, but they
3897 should be harmless, so keep process_one_symbol from
3898 complaining about them. */
3899 if (type_code
& N_STAB
)
3901 /* If we found a trailing N_SO with no name, process
3902 it here instead of in process_one_symbol, so we
3903 can keep a handle to its symtab. The symtab
3904 would otherwise be ended twice, once in
3905 process_one_symbol, and once after this loop. */
3906 if (type_code
== N_SO
3908 && previous_stab_code
!= (unsigned char) N_SO
3911 valu
+= ANOFFSET (pst
->section_offsets
,
3912 SECT_OFF_TEXT (pst
->objfile
));
3913 previous_stab_code
= N_SO
;
3914 st
= end_symtab (valu
, pst
->objfile
,
3915 SECT_OFF_TEXT (pst
->objfile
));
3917 last_symtab_ended
= 1;
3921 last_symtab_ended
= 0;
3922 process_one_symbol (type_code
, 0, valu
, name
,
3923 pst
->section_offsets
, pst
->objfile
);
3926 /* Similarly a hack. */
3927 else if (name
[0] == '#')
3929 process_one_symbol (N_SLINE
, 0, valu
, name
,
3930 pst
->section_offsets
, pst
->objfile
);
3932 if (type_code
== N_FUN
)
3934 /* Make up special symbol to contain
3935 procedure specific info */
3936 struct mdebug_extra_func_info
*e
=
3937 ((struct mdebug_extra_func_info
*)
3938 obstack_alloc (¤t_objfile
->objfile_obstack
,
3939 sizeof (struct mdebug_extra_func_info
)));
3940 struct symbol
*s
= new_symbol (MDEBUG_EFI_SYMBOL_NAME
);
3942 memset (e
, 0, sizeof (struct mdebug_extra_func_info
));
3943 SYMBOL_DOMAIN (s
) = LABEL_DOMAIN
;
3944 SYMBOL_CLASS (s
) = LOC_CONST
;
3945 SYMBOL_TYPE (s
) = mdebug_type_void
;
3946 SYMBOL_VALUE (s
) = (long) e
;
3947 e
->pdr
.framereg
= -1;
3948 add_symbol_to_list (s
, &local_symbols
);
3951 else if (sh
.st
== stLabel
)
3953 if (sh
.index
== indexNil
)
3955 /* This is what the gcc2_compiled and __gnu_compiled_*
3956 show up as. So don't complain. */
3961 /* Handle encoded stab line number. */
3962 valu
+= ANOFFSET (pst
->section_offsets
, SECT_OFF_TEXT (pst
->objfile
));
3963 record_line (current_subfile
, sh
.index
, valu
);
3966 else if (sh
.st
== stProc
|| sh
.st
== stStaticProc
3967 || sh
.st
== stStatic
|| sh
.st
== stEnd
)
3968 /* These are generated by gcc-2.x, do not complain */
3971 complaint (&symfile_complaints
, _("unknown stabs symbol %s"), name
);
3974 if (! last_symtab_ended
)
3976 st
= end_symtab (pst
->texthigh
, pst
->objfile
, SECT_OFF_TEXT (pst
->objfile
));
3980 /* There used to be a call to sort_blocks here, but this should not
3981 be necessary for stabs symtabs. And as sort_blocks modifies the
3982 start address of the GLOBAL_BLOCK to the FIRST_LOCAL_BLOCK,
3983 it did the wrong thing if the first procedure in a file was
3984 generated via asm statements. */
3986 /* Fill in procedure info next. */
3990 struct cleanup
*old_chain
;
3996 pr_block
= (PDR
*) xmalloc (fh
->cpd
* sizeof (PDR
));
3997 old_chain
= make_cleanup (xfree
, pr_block
);
3999 pdr_ptr
= ((char *) debug_info
->external_pdr
4000 + fh
->ipdFirst
* external_pdr_size
);
4001 pdr_end
= pdr_ptr
+ fh
->cpd
* external_pdr_size
;
4005 pdr_ptr
+= external_pdr_size
, pdr_in
++)
4007 (*swap_pdr_in
) (cur_bfd
, pdr_ptr
, pdr_in
);
4009 /* Determine lowest PDR address, the PDRs are not always
4011 if (pdr_in
== pr_block
)
4012 lowest_pdr_addr
= pdr_in
->adr
;
4013 else if (pdr_in
->adr
< lowest_pdr_addr
)
4014 lowest_pdr_addr
= pdr_in
->adr
;
4018 pdr_in_end
= pdr_in
+ fh
->cpd
;
4019 for (; pdr_in
< pdr_in_end
; pdr_in
++)
4020 parse_procedure (pdr_in
, st
, pst
);
4022 do_cleanups (old_chain
);
4027 /* This symbol table contains ordinary ecoff entries. */
4036 st
= new_symtab ("unknown", 0, pst
->objfile
);
4040 maxlines
= 2 * fh
->cline
;
4041 st
= new_symtab (pst
->filename
, maxlines
, pst
->objfile
);
4043 /* The proper language was already determined when building
4044 the psymtab, use it. */
4045 st
->language
= PST_PRIVATE (pst
)->pst_language
;
4048 psymtab_language
= st
->language
;
4050 lines
= LINETABLE (st
);
4052 /* Get a new lexical context */
4054 push_parse_stack ();
4055 top_stack
->cur_st
= st
;
4056 top_stack
->cur_block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (st
),
4058 BLOCK_START (top_stack
->cur_block
) = pst
->textlow
;
4059 BLOCK_END (top_stack
->cur_block
) = 0;
4060 top_stack
->blocktype
= stFile
;
4061 top_stack
->cur_type
= 0;
4062 top_stack
->procadr
= 0;
4063 top_stack
->numargs
= 0;
4064 found_ecoff_debugging_info
= 0;
4071 /* Parse local symbols first */
4072 sym_ptr
= ((char *) debug_info
->external_sym
4073 + fh
->isymBase
* external_sym_size
);
4074 sym_end
= sym_ptr
+ fh
->csym
* external_sym_size
;
4075 while (sym_ptr
< sym_end
)
4080 (*swap_sym_in
) (cur_bfd
, sym_ptr
, &sh
);
4081 c
= parse_symbol (&sh
,
4082 debug_info
->external_aux
+ fh
->iauxBase
,
4083 sym_ptr
, fh
->fBigendian
, pst
->section_offsets
, pst
->objfile
);
4084 sym_ptr
+= c
* external_sym_size
;
4087 /* Linenumbers. At the end, check if we can save memory.
4088 parse_lines has to look ahead an arbitrary number of PDR
4089 structures, so we swap them all first. */
4093 struct cleanup
*old_chain
;
4099 pr_block
= (PDR
*) xmalloc (fh
->cpd
* sizeof (PDR
));
4101 old_chain
= make_cleanup (xfree
, pr_block
);
4103 pdr_ptr
= ((char *) debug_info
->external_pdr
4104 + fh
->ipdFirst
* external_pdr_size
);
4105 pdr_end
= pdr_ptr
+ fh
->cpd
* external_pdr_size
;
4109 pdr_ptr
+= external_pdr_size
, pdr_in
++)
4111 (*swap_pdr_in
) (cur_bfd
, pdr_ptr
, pdr_in
);
4113 /* Determine lowest PDR address, the PDRs are not always
4115 if (pdr_in
== pr_block
)
4116 lowest_pdr_addr
= pdr_in
->adr
;
4117 else if (pdr_in
->adr
< lowest_pdr_addr
)
4118 lowest_pdr_addr
= pdr_in
->adr
;
4121 parse_lines (fh
, pr_block
, lines
, maxlines
, pst
, lowest_pdr_addr
);
4122 if (lines
->nitems
< fh
->cline
)
4123 lines
= shrink_linetable (lines
);
4125 /* Fill in procedure info next. */
4127 pdr_in_end
= pdr_in
+ fh
->cpd
;
4128 for (; pdr_in
< pdr_in_end
; pdr_in
++)
4129 parse_procedure (pdr_in
, 0, pst
);
4131 do_cleanups (old_chain
);
4135 LINETABLE (st
) = lines
;
4137 /* .. and our share of externals.
4138 XXX use the global list to speed up things here. how?
4139 FIXME, Maybe quit once we have found the right number of ext's? */
4140 top_stack
->cur_st
= st
;
4141 top_stack
->cur_block
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (top_stack
->cur_st
),
4143 top_stack
->blocktype
= stFile
;
4145 ext_ptr
= PST_PRIVATE (pst
)->extern_tab
;
4146 for (i
= PST_PRIVATE (pst
)->extern_count
; --i
>= 0; ext_ptr
++)
4147 parse_external (ext_ptr
, fh
->fBigendian
, pst
->section_offsets
, pst
->objfile
);
4149 /* If there are undefined symbols, tell the user.
4150 The alpha has an undefined symbol for every symbol that is
4151 from a shared library, so tell the user only if verbose is on. */
4152 if (info_verbose
&& n_undef_symbols
)
4154 printf_filtered (_("File %s contains %d unresolved references:"),
4155 st
->filename
, n_undef_symbols
);
4156 printf_filtered ("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
4157 n_undef_vars
, n_undef_procs
, n_undef_labels
);
4158 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
4168 /* Now link the psymtab and the symtab. */
4171 current_objfile
= NULL
;
4174 /* Ancillary parsing procedures. */
4176 /* Return 1 if the symbol pointed to by SH has a cross reference
4177 to an opaque aggregate type, else 0. */
4180 has_opaque_xref (FDR
*fh
, SYMR
*sh
)
4187 if (sh
->index
== indexNil
)
4190 ax
= debug_info
->external_aux
+ fh
->iauxBase
+ sh
->index
;
4191 (*debug_swap
->swap_tir_in
) (fh
->fBigendian
, &ax
->a_ti
, &tir
);
4192 if (tir
.bt
!= btStruct
&& tir
.bt
!= btUnion
&& tir
.bt
!= btEnum
)
4196 (*debug_swap
->swap_rndx_in
) (fh
->fBigendian
, &ax
->a_rndx
, rn
);
4197 if (rn
->rfd
== 0xfff)
4198 rf
= AUX_GET_ISYM (fh
->fBigendian
, ax
+ 1);
4206 /* Lookup the type at relative index RN. Return it in TPP
4207 if found and in any event come up with its name PNAME.
4208 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
4209 Return value says how many aux symbols we ate. */
4212 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. */
4213 char **pname
, int bigend
, char *sym_name
)
4222 struct mdebug_pending
*pend
;
4224 *tpp
= (struct type
*) NULL
;
4226 (*debug_swap
->swap_rndx_in
) (bigend
, &ax
->a_rndx
, rn
);
4228 /* Escape index means 'the next one' */
4229 if (rn
->rfd
== 0xfff)
4232 rf
= AUX_GET_ISYM (bigend
, ax
+ 1);
4239 /* mips cc uses a rf of -1 for opaque struct definitions.
4240 Set TYPE_FLAG_STUB for these types so that check_typedef will
4241 resolve them if the struct gets defined in another compilation unit. */
4244 *pname
= "<undefined>";
4245 *tpp
= init_type (type_code
, 0, TYPE_FLAG_STUB
, (char *) NULL
, current_objfile
);
4249 /* mips cc uses an escaped rn->index of 0 for struct return types
4250 of procedures that were compiled without -g. These will always remain
4252 if (rn
->rfd
== 0xfff && rn
->index
== 0)
4254 *pname
= "<undefined>";
4258 /* Find the relative file descriptor and the symbol in it. */
4259 fh
= get_rfd (fd
, rf
);
4260 xref_fd
= fh
- debug_info
->fdr
;
4262 if (rn
->index
>= fh
->csym
)
4264 /* File indirect entry is corrupt. */
4265 *pname
= "<illegal>";
4266 bad_rfd_entry_complaint (sym_name
, xref_fd
, rn
->index
);
4270 /* If we have processed this symbol then we left a forwarding
4271 pointer to the type in the pending list. If not, we`ll put
4272 it in a list of pending types, to be processed later when
4273 the file will be. In any event, we collect the name for the
4276 esh
= ((char *) debug_info
->external_sym
4277 + ((fh
->isymBase
+ rn
->index
)
4278 * debug_swap
->external_sym_size
));
4279 (*debug_swap
->swap_sym_in
) (cur_bfd
, esh
, &sh
);
4281 /* Make sure that this type of cross reference can be handled. */
4282 if ((sh
.sc
!= scInfo
4283 || (sh
.st
!= stBlock
&& sh
.st
!= stTypedef
&& sh
.st
!= stIndirect
4284 && sh
.st
!= stStruct
&& sh
.st
!= stUnion
4285 && sh
.st
!= stEnum
))
4286 && (sh
.st
!= stBlock
|| !SC_IS_COMMON (sh
.sc
)))
4288 /* File indirect entry is corrupt. */
4289 *pname
= "<illegal>";
4290 bad_rfd_entry_complaint (sym_name
, xref_fd
, rn
->index
);
4294 *pname
= debug_info
->ss
+ fh
->issBase
+ sh
.iss
;
4296 pend
= is_pending_symbol (fh
, esh
);
4301 /* We have not yet seen this type. */
4303 if ((sh
.iss
== 0 && sh
.st
== stTypedef
) || sh
.st
== stIndirect
)
4307 /* alpha cc puts out a stTypedef with a sh.iss of zero for
4309 a) forward declarations of structs/unions/enums which are not
4310 defined in this compilation unit.
4311 For these the type will be void. This is a bad design decision
4312 as cross referencing across compilation units is impossible
4313 due to the missing name.
4314 b) forward declarations of structs/unions/enums/typedefs which
4315 are defined later in this file or in another file in the same
4316 compilation unit. Irix5 cc uses a stIndirect symbol for this.
4317 Simply cross reference those again to get the true type.
4318 The forward references are not entered in the pending list and
4319 in the symbol table. */
4321 (*debug_swap
->swap_tir_in
) (bigend
,
4322 &(debug_info
->external_aux
4323 + fh
->iauxBase
+ sh
.index
)->a_ti
,
4325 if (tir
.tq0
!= tqNil
)
4326 complaint (&symfile_complaints
,
4327 _("illegal tq0 in forward typedef for %s"), sym_name
);
4331 *tpp
= init_type (type_code
, 0, 0, (char *) NULL
,
4333 *pname
= "<undefined>";
4340 (debug_info
->external_aux
4341 + fh
->iauxBase
+ sh
.index
+ 1),
4342 tpp
, type_code
, pname
,
4343 fh
->fBigendian
, sym_name
);
4347 /* Follow a forward typedef. This might recursively
4348 call cross_ref till we get a non typedef'ed type.
4349 FIXME: This is not correct behaviour, but gdb currently
4350 cannot handle typedefs without type copying. Type
4351 copying is impossible as we might have mutual forward
4352 references between two files and the copied type would not
4353 get filled in when we later parse its definition. */
4354 *tpp
= parse_type (xref_fd
,
4355 debug_info
->external_aux
+ fh
->iauxBase
,
4359 debug_info
->ss
+ fh
->issBase
+ sh
.iss
);
4360 add_pending (fh
, esh
, *tpp
);
4364 complaint (&symfile_complaints
,
4365 _("illegal bt %d in forward typedef for %s"), tir
.bt
,
4367 *tpp
= init_type (type_code
, 0, 0, (char *) NULL
,
4373 else if (sh
.st
== stTypedef
)
4375 /* Parse the type for a normal typedef. This might recursively call
4376 cross_ref till we get a non typedef'ed type.
4377 FIXME: This is not correct behaviour, but gdb currently
4378 cannot handle typedefs without type copying. But type copying is
4379 impossible as we might have mutual forward references between
4380 two files and the copied type would not get filled in when
4381 we later parse its definition. */
4382 *tpp
= parse_type (xref_fd
,
4383 debug_info
->external_aux
+ fh
->iauxBase
,
4387 debug_info
->ss
+ fh
->issBase
+ sh
.iss
);
4391 /* Cross reference to a struct/union/enum which is defined
4392 in another file in the same compilation unit but that file
4393 has not been parsed yet.
4394 Initialize the type only, it will be filled in when
4395 it's definition is parsed. */
4396 *tpp
= init_type (type_code
, 0, 0, (char *) NULL
, current_objfile
);
4398 add_pending (fh
, esh
, *tpp
);
4401 /* We used one auxent normally, two if we got a "next one" rf. */
4406 /* Quick&dirty lookup procedure, to avoid the MI ones that require
4407 keeping the symtab sorted */
4409 static struct symbol
*
4410 mylookup_symbol (char *name
, struct block
*block
,
4411 domain_enum domain
, enum address_class
class)
4413 struct dict_iterator iter
;
4418 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
4420 if (SYMBOL_LINKAGE_NAME (sym
)[0] == inc
4421 && SYMBOL_DOMAIN (sym
) == domain
4422 && SYMBOL_CLASS (sym
) == class
4423 && strcmp (SYMBOL_LINKAGE_NAME (sym
), name
) == 0)
4427 block
= BLOCK_SUPERBLOCK (block
);
4429 return mylookup_symbol (name
, block
, domain
, class);
4434 /* Add a new symbol S to a block B. */
4437 add_symbol (struct symbol
*s
, struct symtab
*symtab
, struct block
*b
)
4439 SYMBOL_SYMTAB (s
) = symtab
;
4440 dict_add_symbol (BLOCK_DICT (b
), s
);
4443 /* Add a new block B to a symtab S */
4446 add_block (struct block
*b
, struct symtab
*s
)
4448 struct blockvector
*bv
= BLOCKVECTOR (s
);
4450 bv
= (struct blockvector
*) xrealloc ((void *) bv
,
4451 (sizeof (struct blockvector
)
4452 + BLOCKVECTOR_NBLOCKS (bv
)
4453 * sizeof (bv
->block
)));
4454 if (bv
!= BLOCKVECTOR (s
))
4455 BLOCKVECTOR (s
) = bv
;
4457 BLOCKVECTOR_BLOCK (bv
, BLOCKVECTOR_NBLOCKS (bv
)++) = b
;
4460 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
4461 MIPS' linenumber encoding might need more than one byte
4462 to describe it, LAST is used to detect these continuation lines.
4464 Combining lines with the same line number seems like a bad idea.
4465 E.g: There could be a line number entry with the same line number after the
4466 prologue and GDB should not ignore it (this is a better way to find
4467 a prologue than mips_skip_prologue).
4468 But due to the compressed line table format there are line number entries
4469 for the same line which are needed to bridge the gap to the next
4470 line number entry. These entries have a bogus address info with them
4471 and we are unable to tell them from intended duplicate line number
4473 This is another reason why -ggdb debugging format is preferable. */
4476 add_line (struct linetable
*lt
, int lineno
, CORE_ADDR adr
, int last
)
4478 /* DEC c89 sometimes produces zero linenos which confuse gdb.
4479 Change them to something sensible. */
4483 last
= -2; /* make sure we record first line */
4485 if (last
== lineno
) /* skip continuation lines */
4488 lt
->item
[lt
->nitems
].line
= lineno
;
4489 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
4493 /* Sorting and reordering procedures */
4495 /* Blocks with a smaller low bound should come first */
4498 compare_blocks (const void *arg1
, const void *arg2
)
4501 struct block
**b1
= (struct block
**) arg1
;
4502 struct block
**b2
= (struct block
**) arg2
;
4504 addr_diff
= (BLOCK_START ((*b1
))) - (BLOCK_START ((*b2
)));
4506 return (BLOCK_END ((*b2
))) - (BLOCK_END ((*b1
)));
4510 /* Sort the blocks of a symtab S.
4511 Reorder the blocks in the blockvector by code-address,
4512 as required by some MI search routines */
4515 sort_blocks (struct symtab
*s
)
4517 struct blockvector
*bv
= BLOCKVECTOR (s
);
4519 if (BLOCKVECTOR_NBLOCKS (bv
) <= 2)
4522 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) == 0)
4523 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) = 0;
4524 if (BLOCK_END (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) == 0)
4525 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) = 0;
4529 * This is very unfortunate: normally all functions are compiled in
4530 * the order they are found, but if the file is compiled -O3 things
4531 * are very different. It would be nice to find a reliable test
4532 * to detect -O3 images in advance.
4534 if (BLOCKVECTOR_NBLOCKS (bv
) > 3)
4535 qsort (&BLOCKVECTOR_BLOCK (bv
, FIRST_LOCAL_BLOCK
),
4536 BLOCKVECTOR_NBLOCKS (bv
) - FIRST_LOCAL_BLOCK
,
4537 sizeof (struct block
*),
4542 int i
, j
= BLOCKVECTOR_NBLOCKS (bv
);
4544 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
4545 if (high
< BLOCK_END (BLOCKVECTOR_BLOCK (bv
, i
)))
4546 high
= BLOCK_END (BLOCKVECTOR_BLOCK (bv
, i
));
4547 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) = high
;
4550 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
)) =
4551 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, FIRST_LOCAL_BLOCK
));
4553 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) =
4554 BLOCK_START (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
4555 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
)) =
4556 BLOCK_END (BLOCKVECTOR_BLOCK (bv
, GLOBAL_BLOCK
));
4560 /* Constructor/restructor/destructor procedures */
4562 /* Allocate a new symtab for NAME. Needs an estimate of how many
4563 linenumbers MAXLINES we'll put in it */
4565 static struct symtab
*
4566 new_symtab (char *name
, int maxlines
, struct objfile
*objfile
)
4568 struct symtab
*s
= allocate_symtab (name
, objfile
);
4570 LINETABLE (s
) = new_linetable (maxlines
);
4572 /* All symtabs must have at least two blocks */
4573 BLOCKVECTOR (s
) = new_bvect (2);
4574 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
)
4575 = new_block (NON_FUNCTION_BLOCK
);
4576 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)
4577 = new_block (NON_FUNCTION_BLOCK
);
4578 BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)) =
4579 BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
4581 s
->free_code
= free_linetable
;
4582 s
->debugformat
= obsavestring ("ECOFF", 5,
4583 &objfile
->objfile_obstack
);
4587 /* Allocate a new partial_symtab NAME */
4589 static struct partial_symtab
*
4590 new_psymtab (char *name
, struct objfile
*objfile
)
4592 struct partial_symtab
*psymtab
;
4594 psymtab
= allocate_psymtab (name
, objfile
);
4595 psymtab
->section_offsets
= objfile
->section_offsets
;
4597 /* Keep a backpointer to the file's symbols */
4599 psymtab
->read_symtab_private
= ((char *)
4600 obstack_alloc (&objfile
->objfile_obstack
,
4601 sizeof (struct symloc
)));
4602 memset (psymtab
->read_symtab_private
, 0, sizeof (struct symloc
));
4603 CUR_BFD (psymtab
) = cur_bfd
;
4604 DEBUG_SWAP (psymtab
) = debug_swap
;
4605 DEBUG_INFO (psymtab
) = debug_info
;
4606 PENDING_LIST (psymtab
) = pending_list
;
4608 /* The way to turn this into a symtab is to call... */
4609 psymtab
->read_symtab
= mdebug_psymtab_to_symtab
;
4614 /* Allocate a linetable array of the given SIZE. Since the struct
4615 already includes one item, we subtract one when calculating the
4616 proper size to allocate. */
4618 static struct linetable
*
4619 new_linetable (int size
)
4621 struct linetable
*l
;
4623 size
= (size
- 1) * sizeof (l
->item
) + sizeof (struct linetable
);
4624 l
= (struct linetable
*) xmalloc (size
);
4629 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
4630 I am not so sure about the 3.4 ones.
4632 Since the struct linetable already includes one item, we subtract one when
4633 calculating the proper size to allocate. */
4635 static struct linetable
*
4636 shrink_linetable (struct linetable
*lt
)
4639 return (struct linetable
*) xrealloc ((void *) lt
,
4640 (sizeof (struct linetable
)
4642 * sizeof (lt
->item
))));
4645 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
4647 static struct blockvector
*
4648 new_bvect (int nblocks
)
4650 struct blockvector
*bv
;
4653 size
= sizeof (struct blockvector
) + nblocks
* sizeof (struct block
*);
4654 bv
= (struct blockvector
*) xzalloc (size
);
4656 BLOCKVECTOR_NBLOCKS (bv
) = nblocks
;
4661 /* Allocate and zero a new block, and set its BLOCK_DICT. If function
4662 is non-zero, assume the block is associated to a function, and make
4663 sure that the symbols are stored linearly; otherwise, store them
4666 static struct block
*
4667 new_block (enum block_type type
)
4669 /* FIXME: carlton/2003-09-11: This should use allocate_block to
4670 allocate the block. Which, in turn, suggests that the block
4671 should be allocated on an obstack. */
4672 struct block
*retval
= xzalloc (sizeof (struct block
));
4674 if (type
== FUNCTION_BLOCK
)
4675 BLOCK_DICT (retval
) = dict_create_linear_expandable ();
4677 BLOCK_DICT (retval
) = dict_create_hashed_expandable ();
4682 /* Create a new symbol with printname NAME */
4684 static struct symbol
*
4685 new_symbol (char *name
)
4687 struct symbol
*s
= ((struct symbol
*)
4688 obstack_alloc (¤t_objfile
->objfile_obstack
,
4689 sizeof (struct symbol
)));
4691 memset (s
, 0, sizeof (*s
));
4692 SYMBOL_LANGUAGE (s
) = psymtab_language
;
4693 SYMBOL_SET_NAMES (s
, name
, strlen (name
), current_objfile
);
4697 /* Create a new type with printname NAME */
4699 static struct type
*
4700 new_type (char *name
)
4704 t
= alloc_type (current_objfile
);
4705 TYPE_NAME (t
) = name
;
4706 TYPE_CPLUS_SPECIFIC (t
) = (struct cplus_struct_type
*) &cplus_struct_default
;
4710 /* Read ECOFF debugging information from a BFD section. This is
4711 called from elfread.c. It parses the section into a
4712 ecoff_debug_info struct, and then lets the rest of the file handle
4716 elfmdebug_build_psymtabs (struct objfile
*objfile
,
4717 const struct ecoff_debug_swap
*swap
, asection
*sec
)
4719 bfd
*abfd
= objfile
->obfd
;
4720 struct ecoff_debug_info
*info
;
4721 struct cleanup
*back_to
;
4723 /* FIXME: It's not clear whether we should be getting minimal symbol
4724 information from .mdebug in an ELF file, or whether we will.
4725 Re-initialize the minimal symbol reader in case we do. */
4727 init_minimal_symbol_collection ();
4728 back_to
= make_cleanup_discard_minimal_symbols ();
4730 info
= ((struct ecoff_debug_info
*)
4731 obstack_alloc (&objfile
->objfile_obstack
,
4732 sizeof (struct ecoff_debug_info
)));
4734 if (!(*swap
->read_debug_info
) (abfd
, sec
, info
))
4735 error (_("Error reading ECOFF debugging information: %s"),
4736 bfd_errmsg (bfd_get_error ()));
4738 mdebug_build_psymtabs (objfile
, swap
, info
);
4740 install_minimal_symbols (objfile
);
4741 do_cleanups (back_to
);
4745 _initialize_mdebugread (void)
4748 init_type (TYPE_CODE_VOID
, 1,
4750 "void", (struct objfile
*) NULL
);
4752 init_type (TYPE_CODE_INT
, 1,
4754 "char", (struct objfile
*) NULL
);
4755 mdebug_type_unsigned_char
=
4756 init_type (TYPE_CODE_INT
, 1,
4758 "unsigned char", (struct objfile
*) NULL
);
4760 init_type (TYPE_CODE_INT
, 2,
4762 "short", (struct objfile
*) NULL
);
4763 mdebug_type_unsigned_short
=
4764 init_type (TYPE_CODE_INT
, 2,
4766 "unsigned short", (struct objfile
*) NULL
);
4767 mdebug_type_int_32
=
4768 init_type (TYPE_CODE_INT
, 4,
4770 "int", (struct objfile
*) NULL
);
4771 mdebug_type_unsigned_int_32
=
4772 init_type (TYPE_CODE_INT
, 4,
4774 "unsigned int", (struct objfile
*) NULL
);
4775 mdebug_type_int_64
=
4776 init_type (TYPE_CODE_INT
, 8,
4778 "int", (struct objfile
*) NULL
);
4779 mdebug_type_unsigned_int_64
=
4780 init_type (TYPE_CODE_INT
, 8,
4782 "unsigned int", (struct objfile
*) NULL
);
4783 mdebug_type_long_32
=
4784 init_type (TYPE_CODE_INT
, 4,
4786 "long", (struct objfile
*) NULL
);
4787 mdebug_type_unsigned_long_32
=
4788 init_type (TYPE_CODE_INT
, 4,
4790 "unsigned long", (struct objfile
*) NULL
);
4791 mdebug_type_long_64
=
4792 init_type (TYPE_CODE_INT
, 8,
4794 "long", (struct objfile
*) NULL
);
4795 mdebug_type_unsigned_long_64
=
4796 init_type (TYPE_CODE_INT
, 8,
4798 "unsigned long", (struct objfile
*) NULL
);
4799 mdebug_type_long_long_64
=
4800 init_type (TYPE_CODE_INT
, 8,
4802 "long long", (struct objfile
*) NULL
);
4803 mdebug_type_unsigned_long_long_64
=
4804 init_type (TYPE_CODE_INT
, 8,
4806 "unsigned long long", (struct objfile
*) NULL
);
4807 mdebug_type_adr_32
=
4808 init_type (TYPE_CODE_PTR
, 4,
4810 "adr_32", (struct objfile
*) NULL
);
4811 TYPE_TARGET_TYPE (mdebug_type_adr_32
) = mdebug_type_void
;
4812 mdebug_type_adr_64
=
4813 init_type (TYPE_CODE_PTR
, 8,
4815 "adr_64", (struct objfile
*) NULL
);
4816 TYPE_TARGET_TYPE (mdebug_type_adr_64
) = mdebug_type_void
;
4818 init_type (TYPE_CODE_FLT
,
4819 gdbarch_float_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
4820 0, "float", (struct objfile
*) NULL
);
4821 mdebug_type_double
=
4822 init_type (TYPE_CODE_FLT
,
4823 gdbarch_double_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
4824 0, "double", (struct objfile
*) NULL
);
4825 mdebug_type_complex
=
4826 init_type (TYPE_CODE_COMPLEX
,
4827 2 * gdbarch_float_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
4828 0, "complex", (struct objfile
*) NULL
);
4829 TYPE_TARGET_TYPE (mdebug_type_complex
) = mdebug_type_float
;
4830 mdebug_type_double_complex
=
4831 init_type (TYPE_CODE_COMPLEX
,
4832 2 * gdbarch_double_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
4833 0, "double complex", (struct objfile
*) NULL
);
4834 TYPE_TARGET_TYPE (mdebug_type_double_complex
) = mdebug_type_double
;
4836 /* Is a "string" the way btString means it the same as TYPE_CODE_STRING?
4838 mdebug_type_string
=
4839 init_type (TYPE_CODE_STRING
,
4840 TARGET_CHAR_BIT
/ TARGET_CHAR_BIT
,
4842 (struct objfile
*) NULL
);
4844 /* We use TYPE_CODE_INT to print these as integers. Does this do any
4845 good? Would we be better off with TYPE_CODE_ERROR? Should
4846 TYPE_CODE_ERROR print things in hex if it knows the size? */
4847 mdebug_type_fixed_dec
=
4848 init_type (TYPE_CODE_INT
,
4849 gdbarch_int_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
4851 (struct objfile
*) NULL
);
4853 mdebug_type_float_dec
=
4854 init_type (TYPE_CODE_ERROR
,
4855 gdbarch_double_bit (current_gdbarch
) / TARGET_CHAR_BIT
,
4856 0, "floating decimal",
4857 (struct objfile
*) NULL
);