1 /* Read a symbol table in MIPS' format (Third-Eye).
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
3 Contributed by Alessandro Forin (af@cs.cmu.edu) at CMU. Major
4 work by Per Bothner and John Gilmore at Cygnus Support.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
22 /* This module provides three functions: mipscoff_symfile_init,
23 which initializes to read a symbol file; mipscoff_new_init, which
24 discards existing cached information when all symbols are being
25 discarded; and mipscoff_symfile_read, which reads a symbol table
28 mipscoff_symfile_read only does the minimum work necessary for letting the
29 user "name" things symbolically; it does not read the entire symtab.
30 Instead, it reads the external and static symbols and puts them in partial
31 symbol tables. When more extensive information is requested of a
32 file, the corresponding partial symbol table is mutated into a full
33 fledged symbol table by going back and reading the symbols
34 for real. mipscoff_psymtab_to_symtab() is called indirectly through
35 a pointer in the psymtab to do this.
37 ECOFF symbol tables are mostly written in the byte order of the
38 target machine. However, one section of the table (the auxiliary
39 symbol information) is written in the host byte order. There is a
40 bit in the other symbol info which describes which host byte order
41 was used. ECOFF thereby takes the trophy from Intel `b.out' for
42 the most brain-dead adaptation of a file format to byte order.
44 This module can read all four of the known byte-order combinations,
45 on any type of host. However, it does make (and check) the assumption
46 that the external form of a symbol table structure (on disk)
47 occupies the same number of bytes as the internal form (in a struct).
48 Fixing this is possible but requires larger structural changes. */
50 #define TM_FILE_OVERRIDE
60 #include <sys/param.h>
64 #include "coff/mips.h"
66 #include "coff/symconst.h"
68 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
69 #include "aout/aout64.h"
70 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native, now */
71 #include "coff/ecoff-ext.h"
74 struct external_filehdr f
;
75 struct external_aouthdr a
;
78 /* These must match the corresponding definition in gcc/config/xm-mips.h.
79 At some point, these should probably go into a shared include file,
80 but currently gcc and gdb do not share any directories. */
82 #define CODE_MASK 0x8F300
83 #define MIPS_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK)
84 #define MIPS_MARK_STAB(code) ((code)+CODE_MASK)
85 #define MIPS_UNMARK_STAB(code) ((code)-CODE_MASK)
86 #define STABS_SYMBOL "@stabs"
88 /* Each partial symbol table entry contains a pointer to private data for the
89 read_symtab() function to use when expanding a partial symbol table entry
90 to a full symbol table entry.
92 For mipsread this structure contains the index of the FDR that this psymtab
93 represents and a pointer to the symbol table header HDRR from the symbol
94 file that the psymtab was created from. */
96 #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
97 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
98 #define CUR_HDR(p) (PST_PRIVATE(p)->cur_hdr)
103 EXTR
**extern_tab
; /* Pointer to external symbols for this file. */
104 int extern_count
; /* Size of extern_tab. */
107 /* Things we import explicitly from other modules */
109 extern int info_verbose
;
110 extern struct block
*block_for_pc();
111 extern void sort_symtab_syms();
113 /* Various complaints about symbol reading that don't abort the process */
115 struct complaint bad_file_number_complaint
=
116 {"bad file number %d", 0, 0};
118 struct complaint unknown_ext_complaint
=
119 {"unknown external symbol %s", 0, 0};
121 struct complaint unknown_sym_complaint
=
122 {"unknown local symbol %s", 0, 0};
124 struct complaint unknown_st_complaint
=
125 {"with type %d", 0, 0};
127 struct complaint block_overflow_complaint
=
128 {"block containing %s overfilled", 0, 0};
130 struct complaint basic_type_complaint
=
131 {"cannot map MIPS basic type 0x%x", 0, 0};
133 struct complaint unknown_type_qual_complaint
=
134 {"unknown type qualifier 0x%x", 0, 0};
136 struct complaint array_bitsize_complaint
=
137 {"size of array target type not known, assuming %d bits", 0, 0};
139 struct complaint bad_tag_guess_complaint
=
140 {"guessed tag type incorrectly", 0, 0};
142 /* Macros and extra defs */
144 /* Already-parsed symbols are marked specially */
146 #define stParsed stType
148 /* Puns: hard to find whether -g was used and how */
150 #define MIN_GLEVEL GLEVEL_0
151 #define compare_glevel(a,b) \
152 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
153 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
155 /* When looking at .o files, avoid tripping over bad addresses */
157 #define SAFE_TEXT_ADDR 0x400000
158 #define SAFE_DATA_ADDR 0x10000000
160 #define UNSAFE_DATA_ADDR(p) ((unsigned)p < SAFE_DATA_ADDR || (unsigned)p > 2*SAFE_DATA_ADDR)
162 /* Things that really are local to this module */
164 /* GDB symtable for the current compilation unit */
166 static struct symtab
*cur_stab
;
168 /* MIPS symtab header for the current file */
170 static HDRR
*cur_hdr
;
172 /* Pointer to current file decriptor record, and its index */
177 /* Index of current symbol */
181 /* Note how much "debuggable" this image is. We would like
182 to see at least one FDR with full symbols */
187 /* When examining .o files, report on undefined symbols */
189 static int n_undef_symbols
, n_undef_labels
, n_undef_vars
, n_undef_procs
;
191 /* Pseudo symbol to use when putting stabs into the symbol table. */
193 static char stabs_symbol
[] = STABS_SYMBOL
;
195 /* Extra builtin types */
197 struct type
*builtin_type_complex
;
198 struct type
*builtin_type_double_complex
;
199 struct type
*builtin_type_fixed_dec
;
200 struct type
*builtin_type_float_dec
;
201 struct type
*builtin_type_string
;
203 /* Forward declarations */
206 fixup_symtab
PARAMS ((HDRR
*, char *, int, bfd
*));
209 read_mips_symtab
PARAMS ((struct objfile
*, int));
212 read_the_mips_symtab
PARAMS ((bfd
*, int, CORE_ADDR
*));
215 upgrade_type
PARAMS ((struct type
**, int, union aux_ext
*, int));
218 parse_partial_symbols
PARAMS ((int, struct objfile
*));
221 cross_ref
PARAMS ((union aux_ext
*, struct type
**, enum type_code
, char **,
225 fixup_sigtramp
PARAMS ((void));
227 static struct symbol
*
228 new_symbol
PARAMS ((char *));
231 new_type
PARAMS ((char *));
233 static struct block
*
234 new_block
PARAMS ((int));
236 static struct symtab
*
237 new_symtab
PARAMS ((char *, int, int, struct objfile
*));
239 static struct linetable
*
240 new_linetable
PARAMS ((int));
242 static struct blockvector
*
243 new_bvect
PARAMS ((int));
246 parse_type
PARAMS ((union aux_ext
*, int *, int));
248 static struct symbol
*
249 mylookup_symbol
PARAMS ((char *, struct block
*, enum namespace,
250 enum address_class
));
252 static struct block
*
253 shrink_block
PARAMS ((struct block
*, struct symtab
*));
256 xzalloc
PARAMS ((unsigned int));
259 sort_blocks
PARAMS ((struct symtab
*));
262 compare_blocks
PARAMS ((struct block
**, struct block
**));
264 static struct partial_symtab
*
265 new_psymtab
PARAMS ((char *, struct objfile
*));
268 static struct partial_symtab
*
269 parse_fdr
PARAMS ((int, int, struct objfile
*));
273 psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*, char *));
276 add_block
PARAMS ((struct block
*, struct symtab
*));
279 add_symbol
PARAMS ((struct symbol
*, struct block
*));
282 add_line
PARAMS ((struct linetable
*, int, CORE_ADDR
, int));
284 static struct linetable
*
285 shrink_linetable
PARAMS ((struct linetable
*));
288 mips_next_symbol_text
PARAMS ((void));
290 /* Things we export to other modules */
292 /* Address bounds for the signal trampoline in inferior, if any */
293 /* FIXME: Nothing really seems to use this. Why is it here? */
295 CORE_ADDR sigtramp_address
, sigtramp_end
;
298 mipscoff_new_init (ignore
)
299 struct objfile
*ignore
;
304 mipscoff_symfile_init (objfile
)
305 struct objfile
*objfile
;
307 if (objfile
-> sym_private
!= NULL
)
309 mfree (objfile
-> md
, objfile
-> sym_private
);
311 objfile
-> sym_private
= NULL
;
315 mipscoff_symfile_read (objfile
, addr
, mainline
)
316 struct objfile
*objfile
;
320 bfd
*abfd
= objfile
-> obfd
;
323 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
324 desc
= fileno ((FILE *)(abfd
->iostream
)); /* Raw file descriptor */
327 init_minimal_symbol_collection ();
328 make_cleanup (discard_minimal_symbols
, 0);
330 /* Now that the executable file is positioned at symbol table,
331 process it and define symbols accordingly. */
333 read_mips_symtab(objfile
, desc
);
335 /* Install any minimal symbols that have been collected as the current
336 minimal symbols for this objfile. */
338 install_minimal_symbols (objfile
);
341 /* Perform any local cleanups required when we are done with a particular
342 objfile. I.E, we are in the process of discarding all symbol information
343 for an objfile, freeing up all memory held for it, and unlinking the
344 objfile struct from the global list of known objfiles. */
347 mipscoff_symfile_finish (objfile
)
348 struct objfile
*objfile
;
350 if (objfile
-> sym_private
!= NULL
)
352 mfree (objfile
-> md
, objfile
-> sym_private
);
355 /* If we have a file symbol header lying around, blow it away. */
364 /* Allocate zeroed memory */
370 PTR p
= xmalloc(size
);
376 /* Exported procedure: Builds a symtab from the PST partial one.
377 Restores the environment in effect when PST was created, delegates
378 most of the work to an ancillary procedure, and sorts
379 and reorders the symtab list at the end */
382 mipscoff_psymtab_to_symtab(pst
)
383 struct partial_symtab
*pst
;
390 printf_filtered("Reading in symbols for %s...", pst
->filename
);
393 /* Restore the header and list of pending typedefs */
394 cur_hdr
= CUR_HDR(pst
);
396 next_symbol_text_func
= mips_next_symbol_text
;
398 psymtab_to_symtab_1(pst
, pst
->filename
);
400 /* Match with global symbols. This only needs to be done once,
401 after all of the symtabs and dependencies have been read in. */
402 scan_file_globals (pst
->objfile
);
405 printf_filtered("done.\n");
408 /* Exported procedure: Is PC in the signal trampoline code */
411 in_sigtramp(pc
, ignore
)
413 char *ignore
; /* function name */
415 if (sigtramp_address
== 0)
417 return (pc
>= sigtramp_address
&& pc
< sigtramp_end
);
420 /* File-level interface functions */
422 /* Read the symtab information from file FSYM into memory. Also,
423 return address just past end of our text segment in *END_OF_TEXT_SEGP. */
426 read_the_mips_symtab(abfd
, fsym
, end_of_text_segp
)
429 CORE_ADDR
*end_of_text_segp
;
431 int stsize
, st_hdrsize
;
433 struct hdr_ext hdr_ext
;
435 /* Header for executable/object file we read symbols from */
436 struct coff_exec filhdr
;
438 /* We need some info from the initial headers */
440 myread(fsym
, (char *)&filhdr
, sizeof filhdr
);
442 if (end_of_text_segp
)
444 bfd_h_get_32 (abfd
, filhdr
.a
.text_start
) +
445 bfd_h_get_32 (abfd
, filhdr
.a
.tsize
);
447 /* Find and read the symbol table header */
448 st_hdrsize
= bfd_h_get_32 (abfd
, filhdr
.f
.f_nsyms
);
449 st_filptr
= bfd_h_get_32 (abfd
, filhdr
.f
.f_symptr
);
453 lseek(fsym
, st_filptr
, L_SET
);
454 if (st_hdrsize
!= sizeof (hdr_ext
)) { /* Profanity check */
455 error ("Wrong header size: %d, not %d", st_hdrsize
,
458 if (read(fsym
, &hdr_ext
, st_hdrsize
) != st_hdrsize
)
460 ecoff_swap_hdr_in (abfd
, &hdr_ext
, &st_hdr
);
462 /* Find out how large the symbol table is */
463 stsize
= (st_hdr
.cbExtOffset
- (st_filptr
+ st_hdrsize
))
464 + st_hdr
.iextMax
* cbEXTR
;
466 /* Allocate space for the symbol table. Read it in. */
467 cur_hdr
= (HDRR
*) xmalloc(stsize
+ st_hdrsize
);
469 memcpy((PTR
)cur_hdr
, (PTR
)&hdr_ext
, st_hdrsize
);
470 if (read(fsym
, (char *) cur_hdr
+ st_hdrsize
, stsize
) != stsize
)
473 /* Fixup file_pointers in it */
474 fixup_symtab(cur_hdr
, (char *) cur_hdr
+ st_hdrsize
,
475 st_filptr
+ st_hdrsize
, abfd
);
479 error("Short read on %s", bfd_get_filename (abfd
));
483 /* Turn all file-relative pointers in the symtab described by HDR
484 into memory pointers, given that the symtab itself is located
485 at DATA in memory and F_PTR in the file.
487 Byte-swap all the data structures, in place, while we are at it --
488 except AUX entries, which we leave in their original byte order.
489 They will be swapped as they are used instead. (FIXME: we ought to
490 do all the data structures that way.) */
493 fixup_symtab (hdr
, data
, f_ptr
, abfd
)
504 struct rfd_ext
*rbase
;
506 /* This function depends on the external and internal forms
507 of the MIPS symbol table taking identical space. Check this
508 assumption at compile-time. */
509 static check_hdr1
[1 + sizeof (struct hdr_ext
) - sizeof (HDRR
)] = {0};
510 static check_hdr2
[1 + sizeof (HDRR
) - sizeof (struct hdr_ext
)] = {0};
511 static check_fdr1
[1 + sizeof (struct fdr_ext
) - sizeof (FDR
)] = {0};
512 static check_fdr2
[1 + sizeof (FDR
) - sizeof (struct fdr_ext
)] = {0};
513 static check_pdr1
[1 + sizeof (struct pdr_ext
) - sizeof (PDR
)] = {0};
514 static check_pdr2
[1 + sizeof (PDR
) - sizeof (struct pdr_ext
)] = {0};
515 static check_sym1
[1 + sizeof (struct sym_ext
) - sizeof (SYMR
)] = {0};
516 static check_sym2
[1 + sizeof (SYMR
) - sizeof (struct sym_ext
)] = {0};
517 static check_ext1
[1 + sizeof (struct ext_ext
) - sizeof (EXTR
)] = {0};
518 static check_ext2
[1 + sizeof (EXTR
) - sizeof (struct ext_ext
)] = {0};
519 static check_rfd1
[1 + sizeof (struct rfd_ext
) - sizeof (RFDT
)] = {0};
520 static check_rfd2
[1 + sizeof (RFDT
) - sizeof (struct rfd_ext
)] = {0};
522 /* Swap in the header record. */
523 ecoff_swap_hdr_in (abfd
, hdr
, hdr
);
526 * These fields are useless (and empty) by now:
527 * hdr->cbDnOffset, hdr->cbOptOffset
528 * We use them for other internal purposes.
531 hdr
->cbOptOffset
= 0;
534 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
548 /* Fix all the RFD's. */
549 rbase
= (struct rfd_ext
*)(hdr
->cbRfdOffset
);
550 for (i
= 0; i
< hdr
->crfd
; i
++) {
551 ecoff_swap_rfd_in (abfd
, rbase
+i
, (pRFDT
) rbase
+i
);
554 /* Fix all string pointers inside the symtab, and
555 the FDR records. Also fix other miscellany. */
557 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
558 register unsigned code_offset
;
560 /* Header itself, and strings */
561 fh
= (FDR
*) (hdr
->cbFdOffset
) + f_idx
;
563 /* Swap in the FDR */
564 ecoff_swap_fdr_in (abfd
, fh
, fh
);
566 fh
->issBase
+= hdr
->cbSsOffset
;
568 fh
->rss
= (long)fh
->rss
+ fh
->issBase
;
571 fh
->isymBase
= (int)((SYMR
*)(hdr
->cbSymOffset
)+fh
->isymBase
);
573 /* FIXME! Probably don't want to do this here! */
574 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
575 sh
= (SYMR
*)fh
->isymBase
+ s_idx
;
576 ecoff_swap_sym_in (abfd
, sh
, sh
);
578 sh
->iss
= (long) sh
->iss
+ fh
->issBase
;
584 /* cannot fix fh->ipdFirst because it is a short */
585 #define IPDFIRST(h,fh) \
586 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
588 /* Optional symbols (actually used for partial_symtabs) */
594 fh
->iauxBase
= hdr
->cbAuxOffset
+ fh
->iauxBase
* sizeof(union aux_ext
);
595 /* Relative file descriptor table */
596 fh
->rfdBase
= hdr
->cbRfdOffset
+ fh
->rfdBase
* sizeof(RFDT
);
600 fh
->cbLineOffset
+= hdr
->cbLineOffset
;
602 /* Procedure symbols. (XXX This should be done later) */
603 code_offset
= fh
->adr
;
604 for (s_idx
= 0; s_idx
< fh
->cpd
; s_idx
++) {
605 unsigned name
, only_ext
;
607 pr
= (PDR
*)(IPDFIRST(hdr
,fh
)) + s_idx
;
608 ecoff_swap_pdr_in (abfd
, pr
, pr
);
610 /* Simple rule to find files linked "-x" */
611 only_ext
= fh
->rss
== -1;
613 if (pr
->isym
== -1) {
614 /* static function */
618 name
= hdr
->cbExtOffset
+ pr
->isym
* sizeof(EXTR
);
619 sh
= &((EXTR
*)name
)->asym
;
623 sh
= (SYMR
*)fh
->isymBase
+ pr
->isym
;
624 /* Included code ? */
625 if (s_idx
== 0 && pr
->adr
!= 0)
626 code_offset
-= pr
->adr
;
629 /* Turn index into a pointer */
632 /* Fix line numbers */
633 pr
->cbLineOffset
+= fh
->cbLineOffset
;
635 /* Relocate address */
637 pr
->adr
+= code_offset
;
641 /* External symbols: swap in, and fix string */
642 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
643 esh
= (EXTR
*)(hdr
->cbExtOffset
) + s_idx
;
644 ecoff_swap_ext_in (abfd
, esh
, esh
);
645 esh
->asym
.iss
= esh
->asym
.iss
+ hdr
->cbSsExtOffset
;
650 /* Find a file descriptor given its index RF relative to a file CF */
658 f
= (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
659 /* Object files do not have the RFD table, all refs are absolute */
661 return (FDR
*) (cur_hdr
->cbFdOffset
) + rf
;
662 cf
= *((pRFDT
) f
->rfdBase
+ rf
);
663 return (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
666 /* Return a safer print NAME for a file descriptor */
672 if (name
== (char *) -1)
673 return "<stripped file>";
674 if (UNSAFE_DATA_ADDR(name
))
680 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
681 whether we are adding to the general symtab or not.
682 FIXME: INCREMENTAL is currently always zero, though it should not be. */
685 read_mips_symtab (objfile
, desc
)
686 struct objfile
*objfile
;
689 CORE_ADDR end_of_text_seg
;
691 read_the_mips_symtab(objfile
->obfd
, desc
, &end_of_text_seg
);
693 parse_partial_symbols(end_of_text_seg
, objfile
);
697 * Check to make sure file was compiled with -g.
698 * If not, warn the user of this limitation.
700 if (compare_glevel(max_glevel
, GLEVEL_2
) < 0) {
701 if (max_gdbinfo
== 0)
703 "\n%s not compiled with -g, debugging support is limited.\n",
706 "You should compile with -g2 or -g3 for best debugging support.\n");
712 /* Local utilities */
714 /* Map of FDR indexes to partial symtabs */
717 struct partial_symtab
*pst
; /* the psymtab proper */
718 int n_globals
; /* exported globals (external symbols) */
719 int globals_offset
; /* cumulative */
723 /* Utility stack, used to nest procedures and blocks properly.
724 It is a doubly linked list, to avoid too many alloc/free.
725 Since we might need it quite a few times it is NOT deallocated
728 static struct parse_stack
{
729 struct parse_stack
*next
, *prev
;
730 struct symtab
*cur_st
; /* Current symtab. */
731 struct block
*cur_block
; /* Block in it. */
732 int blocktype
; /* What are we parsing. */
733 int maxsyms
; /* Max symbols in this block. */
734 struct type
*cur_type
; /* Type we parse fields for. */
735 int cur_field
; /* Field number in cur_type. */
736 int procadr
; /* Start addres of this procedure */
737 int numargs
; /* Its argument count */
738 } *top_stack
; /* Top stack ptr */
741 /* Enter a new lexical context */
746 struct parse_stack
*new;
748 /* Reuse frames if possible */
749 if (top_stack
&& top_stack
->prev
)
750 new = top_stack
->prev
;
752 new = (struct parse_stack
*) xzalloc(sizeof(struct parse_stack
));
753 /* Initialize new frame with previous content */
755 register struct parse_stack
*prev
= new->prev
;
758 top_stack
->prev
= new;
760 new->next
= top_stack
;
765 /* Exit a lexical context */
773 top_stack
= top_stack
->next
;
777 /* Cross-references might be to things we haven't looked at
778 yet, e.g. type references. To avoid too many type
779 duplications we keep a quick fixup table, an array
780 of lists of references indexed by file descriptor */
782 static struct mips_pending
{
783 struct mips_pending
*next
; /* link */
784 SYMR
*s
; /* the symbol */
785 struct type
*t
; /* its partial type descriptor */
789 /* Check whether we already saw symbol SH in file FH as undefined */
791 static struct mips_pending
*
792 is_pending_symbol(fh
, sh
)
796 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
797 register struct mips_pending
*p
;
799 /* Linear search is ok, list is typically no more than 10 deep */
800 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
806 /* Add a new undef symbol SH of type T */
809 add_pending(fh
, sh
, t
)
814 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
815 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
817 /* Make sure we do not make duplicates */
819 p
= (struct mips_pending
*) xmalloc(sizeof(*p
));
822 p
->next
= pending_list
[f_idx
];
823 pending_list
[f_idx
] = p
;
825 sh
->reserved
= 1; /* for quick check */
828 /* Throw away undef entries when done with file index F_IDX */
829 /* FIXME -- storage leak. This is never called!!! --gnu */
835 register struct mips_pending
*p
, *q
;
837 for (p
= pending_list
[f_idx
]; p
; p
= q
) {
841 pending_list
[f_idx
] = 0;
845 prepend_tag_kind(tag_name
, type_code
)
847 enum type_code type_code
;
855 case TYPE_CODE_STRUCT
:
858 case TYPE_CODE_UNION
:
865 result
= (char*)obstack_alloc (¤t_objfile
->symbol_obstack
,
866 strlen(prefix
) + strlen(tag_name
) + 1);
867 sprintf(result
, "%s%s", prefix
, tag_name
);
872 /* Parsing Routines proper. */
874 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
875 For blocks, procedures and types we open a new lexical context.
876 This is basically just a big switch on the symbol's type.
877 Argument AX is the base pointer of aux symbols for this file (fh->iauxBase).
878 BIGEND says whether aux symbols are big-endian or little-endian.
879 Return count of SYMR's handled (normally one). */
882 parse_symbol(sh
, ax
, bigend
)
893 /* When a symbol is cross-referenced from other files/symbols
894 we mark it explicitly */
895 int pend
= (sh
->reserved
== 1);
896 enum address_class
class;
904 case stGlobal
: /* external symbol, goes into global block */
906 b
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
908 s
= new_symbol((char *)sh
->iss
);
909 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
912 case stStatic
: /* static data, goes into current block. */
914 b
= top_stack
->cur_block
;
915 s
= new_symbol((char *)sh
->iss
);
916 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
919 case stLocal
: /* local variable, goes into current block */
920 if (sh
->sc
== scRegister
) {
921 class = LOC_REGISTER
;
923 sh
->value
+= FP0_REGNUM
-32;
926 b
= top_stack
->cur_block
;
927 s
= new_symbol((char *)sh
->iss
);
928 SYMBOL_VALUE(s
) = sh
->value
;
930 data
: /* Common code for symbols describing data */
931 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
932 SYMBOL_CLASS(s
) = class;
935 /* Type could be missing in a number of cases */
936 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
937 sh
->index
== 0xfffff)
938 SYMBOL_TYPE(s
) = builtin_type_int
; /* undefined? */
940 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, 0, bigend
);
941 /* Value of a data symbol is its memory address */
944 case stParam
: /* arg to procedure, goes into current block */
946 top_stack
->numargs
++;
948 name
= (char*)sh
->iss
;
949 /* Special GNU C++ name. */
950 if (name
[0] == CPLUS_MARKER
&& name
[1] == 't' && name
[2] == 0)
952 s
= new_symbol(name
);
954 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
955 if (sh
->sc
== scRegister
) {
956 SYMBOL_CLASS(s
) = LOC_REGPARM
;
958 sh
->value
+= FP0_REGNUM
-32;
960 SYMBOL_CLASS(s
) = LOC_ARG
;
961 SYMBOL_VALUE(s
) = sh
->value
;
962 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, 0, bigend
);
963 add_symbol(s
, top_stack
->cur_block
);
965 /* FIXME: This has not been tested. See dbxread.c */
966 /* Add the type of this parameter to the function/procedure
967 type of this block. */
968 add_param_to_type(&top_stack
->cur_block
->function
->type
,s
);
972 case stLabel
: /* label, goes into current block */
973 s
= new_symbol((char *)sh
->iss
);
974 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
; /* so that it can be used */
975 SYMBOL_CLASS(s
) = LOC_LABEL
; /* but not misused */
976 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
977 SYMBOL_TYPE(s
) = builtin_type_int
;
978 add_symbol(s
, top_stack
->cur_block
);
981 case stProc
: /* Procedure, usually goes into global block */
982 case stStaticProc
: /* Static procedure, goes into current block */
983 s
= new_symbol((char *)sh
->iss
);
984 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
985 SYMBOL_CLASS(s
) = LOC_BLOCK
;
986 /* Type of the return value */
987 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
988 t
= builtin_type_int
;
990 t
= parse_type(ax
+ sh
->index
+ 1, 0, bigend
);
991 b
= top_stack
->cur_block
;
992 if (sh
->st
== stProc
) {
993 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
994 /* The next test should normally be true,
995 but provides a hook for nested functions
996 (which we don't want to make global). */
997 if (b
== BLOCKVECTOR_BLOCK(bv
, STATIC_BLOCK
))
998 b
= BLOCKVECTOR_BLOCK(bv
, GLOBAL_BLOCK
);
1002 /* Make a type for the procedure itself */
1004 /* FIXME: This has not been tested yet! See dbxread.c */
1005 /* Generate a template for the type of this function. The
1006 types of the arguments will be added as we read the symbol
1008 bcopy(SYMBOL_TYPE(s
),lookup_function_type(t
),sizeof(struct type
));
1010 SYMBOL_TYPE(s
) = lookup_function_type (t
);
1013 /* Create and enter a new lexical context */
1014 b
= new_block(top_stack
->maxsyms
);
1015 SYMBOL_BLOCK_VALUE(s
) = b
;
1016 BLOCK_FUNCTION(b
) = s
;
1017 BLOCK_START(b
) = BLOCK_END(b
) = sh
->value
;
1018 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1019 add_block(b
, top_stack
->cur_st
);
1021 /* Not if we only have partial info */
1022 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
1026 top_stack
->cur_block
= b
;
1027 top_stack
->blocktype
= sh
->st
;
1028 top_stack
->cur_type
= SYMBOL_TYPE(s
);
1029 top_stack
->cur_field
= -1;
1030 top_stack
->procadr
= sh
->value
;
1031 top_stack
->numargs
= 0;
1033 sh
->value
= (long) SYMBOL_TYPE(s
);
1037 #ifndef btVoid /* btVoid was added late. */
1040 /* These new symbol types have been recently added to SGI machines. */
1054 case stBlock
: /* Either a lexical block, or some type */
1056 top_stack
->blocktype
= stBlock
;
1057 if (sh
->sc
== scInfo
) { /* structure/union/enum def */
1058 enum type_code type_code
=
1059 sh
->st
== stStruct
? TYPE_CODE_STRUCT
1060 : sh
->st
== stUnion
? TYPE_CODE_UNION
1061 : sh
->st
== stEnum
? TYPE_CODE_ENUM
1068 s
= new_symbol((char *)sh
->iss
);
1069 SYMBOL_NAMESPACE(s
) = STRUCT_NAMESPACE
;
1070 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1071 SYMBOL_VALUE(s
) = 0;
1072 add_symbol(s
, top_stack
->cur_block
);
1074 /* First count the number of fields. */
1075 for (tsym
= sh
+1; tsym
->st
!= stEnd
; tsym
++)
1076 if (tsym
->st
== stMember
) {
1077 if (nfields
== 0 && type_code
== TYPE_CODE_UNDEF
)
1078 /* If the type of the member is Nil (or Void)
1079 assume the tag is an enumeration. */
1080 if (tsym
->index
== indexNil
)
1081 type_code
= TYPE_CODE_ENUM
;
1083 ecoff_swap_tir_in (bigend
,
1084 &ax
[tsym
->index
].a_ti
,
1086 if (tir
.bt
== btNil
|| tir
.bt
== btVoid
)
1087 type_code
= TYPE_CODE_ENUM
;
1090 if (tsym
->value
> max_value
)
1091 max_value
= tsym
->value
;
1093 else if (tsym
->st
== stBlock
1094 || tsym
->st
== stUnion
1095 || tsym
->st
== stEnum
1096 || tsym
->st
== stStruct
1097 || tsym
->st
== stParsed
) {
1098 if (tsym
->sc
== scVariant
) ; /*UNIMPLEMENTED*/
1099 if (tsym
->index
!= 0)
1100 tsym
= ((SYMR
*)cur_fdr
->isymBase
)
1104 /* There is no guaranteed way to distinguish struct,
1105 unions, and enums at this point. This is a bug in the
1106 original design (that has been fixed with the
1107 recent addition of the stStruct, stUnion, and stEnum
1108 symbol types.) The way you can tell is if/when you
1109 see a variable or field of that type: In that case
1110 the variable's type (in the AUX table) says if the
1111 type is struct, union, or enum,
1112 and points back to the stBlock here.
1113 So you can patch the tag kind up later - but only
1114 if there actually is a variable or field of that type.
1116 So until we know for sure, we will guess at this point.
1118 If the first member has index==indexNil or a void type,
1119 assume we have an enumeration.
1120 Otherwise, if there is more than one member, and all
1121 the members have offset 0, assume we have a union.
1122 Otherwise, assume we have a struct.
1124 The heuristic could guess wrong in the case of
1125 of an enumeration with no members or a union
1126 with one (or zero) members, or when all except the
1127 last field of a struct have width zero.
1128 These are uncommon and/or illegal situations, and
1129 in any case guessing wrong probably doesn't matter much.
1131 But if we later do find out we were wrong,
1132 we fixup the tag kind. Members of an enumeration
1133 must be handled differently from struct/union fields,
1134 and that is harder to patch up, but luckily we
1135 shouldn't need to. (If there are any enumeration
1136 members, we can tell for sure it's an enum here.) */
1138 if (type_code
== TYPE_CODE_UNDEF
)
1139 if (nfields
> 1 && max_value
== 0)
1140 type_code
= TYPE_CODE_UNION
;
1142 type_code
= TYPE_CODE_STRUCT
;
1144 /* If this type was expected, use its partial definition */
1146 t
= is_pending_symbol(cur_fdr
, sh
)->t
;
1148 t
= new_type(prepend_tag_kind((char *)sh
->iss
,
1151 TYPE_CODE(t
) = type_code
;
1152 TYPE_LENGTH(t
) = sh
->value
;
1153 TYPE_NFIELDS(t
) = nfields
;
1154 TYPE_FIELDS(t
) = f
= (struct field
*)
1155 obstack_alloc (¤t_objfile
-> type_obstack
,
1156 nfields
* sizeof (struct field
));
1158 if (type_code
== TYPE_CODE_ENUM
) {
1159 /* This is a non-empty enum. */
1160 for (tsym
= sh
+ 1; tsym
->st
== stMember
; tsym
++) {
1161 struct symbol
*enum_sym
;
1162 f
->bitpos
= tsym
->value
;
1164 f
->name
= (char*)tsym
->iss
;
1167 enum_sym
= (struct symbol
*)
1168 obstack_alloc (¤t_objfile
->symbol_obstack
,
1169 sizeof (struct symbol
));
1170 memset ((PTR
)enum_sym
, 0, sizeof (struct symbol
));
1171 SYMBOL_NAME (enum_sym
) = f
->name
;
1172 SYMBOL_CLASS (enum_sym
) = LOC_CONST
;
1173 SYMBOL_TYPE (enum_sym
) = t
;
1174 SYMBOL_NAMESPACE (enum_sym
) = VAR_NAMESPACE
;
1175 SYMBOL_VALUE (enum_sym
) = tsym
->value
;
1176 add_symbol(enum_sym
, top_stack
->cur_block
);
1178 /* Skip the stMembers that we've handled. */
1184 /* make this the current type */
1185 top_stack
->cur_type
= t
;
1186 top_stack
->cur_field
= 0;
1187 /* Mark that symbol has a type, and say which one */
1188 sh
->value
= (long) t
;
1190 /* beginnning of (code) block. Value of symbol
1191 is the displacement from procedure start */
1192 b
= new_block(top_stack
->maxsyms
);
1193 BLOCK_START(b
) = sh
->value
+ top_stack
->procadr
;
1194 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1195 top_stack
->cur_block
= b
;
1196 add_block(b
, top_stack
->cur_st
);
1200 case stEnd
: /* end (of anything) */
1201 if (sh
->sc
== scInfo
) {
1202 /* Finished with type */
1203 top_stack
->cur_type
= 0;
1204 } else if (sh
->sc
== scText
&&
1205 (top_stack
->blocktype
== stProc
||
1206 top_stack
->blocktype
== stStaticProc
)) {
1207 /* Finished with procedure */
1208 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
1209 struct mips_extra_func_info
*e
;
1213 BLOCK_END(top_stack
->cur_block
) += sh
->value
; /* size */
1215 /* Make up special symbol to contain procedure specific
1217 s
= new_symbol(".gdbinfo.");
1218 SYMBOL_NAMESPACE(s
) = LABEL_NAMESPACE
;
1219 SYMBOL_CLASS(s
) = LOC_CONST
;
1220 SYMBOL_TYPE(s
) = builtin_type_void
;
1221 e
= (struct mips_extra_func_info
*)
1222 obstack_alloc (¤t_objfile
->symbol_obstack
,
1223 sizeof (struct mips_extra_func_info
));
1224 SYMBOL_VALUE(s
) = (int)e
;
1225 e
->numargs
= top_stack
->numargs
;
1226 add_symbol(s
, top_stack
->cur_block
);
1228 /* Reallocate symbols, saving memory */
1229 b
= shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1231 /* f77 emits proc-level with address bounds==[0,0],
1232 So look for such child blocks, and patch them. */
1233 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++) {
1234 struct block
*b_bad
= BLOCKVECTOR_BLOCK(bv
,i
);
1235 if (BLOCK_SUPERBLOCK(b_bad
) == b
1236 && BLOCK_START(b_bad
) == top_stack
->procadr
1237 && BLOCK_END(b_bad
) == top_stack
->procadr
) {
1238 BLOCK_START(b_bad
) = BLOCK_START(b
);
1239 BLOCK_END(b_bad
) = BLOCK_END(b
);
1242 } else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
) {
1243 /* End of (code) block. The value of the symbol
1244 is the displacement from the procedure`s start
1245 address of the end of this block. */
1246 BLOCK_END(top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1247 (void) shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1249 pop_parse_stack(); /* restore previous lexical context */
1252 case stMember
: /* member of struct or union */
1253 f
= &TYPE_FIELDS(top_stack
->cur_type
)[top_stack
->cur_field
++];
1254 f
->name
= (char*)sh
->iss
;
1255 f
->bitpos
= sh
->value
;
1257 f
->type
= parse_type(ax
+ sh
->index
, &f
->bitsize
, bigend
);
1260 case stTypedef
: /* type definition */
1261 s
= new_symbol((char *)sh
->iss
);
1262 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1263 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1264 SYMBOL_BLOCK_VALUE(s
) = top_stack
->cur_block
;
1265 add_symbol(s
, top_stack
->cur_block
);
1266 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, 0, bigend
);
1267 sh
->value
= (long) SYMBOL_TYPE(s
);
1270 case stFile
: /* file name */
1272 top_stack
->blocktype
= sh
->st
;
1275 /* I`ve never seen these for C */
1277 break; /* register relocation */
1279 break; /* forwarding address */
1281 break; /* constant */
1283 error("Unknown symbol type %x.", sh
->st
);
1289 /* Parse the type information provided in the raw AX entries for
1290 the symbol SH. Return the bitfield size in BS, in case.
1291 We must byte-swap the AX entries before we use them; BIGEND says whether
1292 they are big-endian or little-endian (from fh->fBigendian). */
1294 static struct type
*
1295 parse_type(ax
, bs
, bigend
)
1300 /* Null entries in this map are treated specially */
1301 static struct type
**map_bt
[] =
1303 &builtin_type_void
, /* btNil */
1305 &builtin_type_char
, /* btChar */
1306 &builtin_type_unsigned_char
, /* btUChar */
1307 &builtin_type_short
, /* btShort */
1308 &builtin_type_unsigned_short
, /* btUShort */
1309 &builtin_type_int
, /* btInt */
1310 &builtin_type_unsigned_int
, /* btUInt */
1311 &builtin_type_long
, /* btLong */
1312 &builtin_type_unsigned_long
, /* btULong */
1313 &builtin_type_float
, /* btFloat */
1314 &builtin_type_double
, /* btDouble */
1321 &builtin_type_complex
, /* btComplex */
1322 &builtin_type_double_complex
, /* btDComplex */
1324 &builtin_type_fixed_dec
, /* btFixedDec */
1325 &builtin_type_float_dec
, /* btFloatDec */
1326 &builtin_type_string
, /* btString */
1329 &builtin_type_void
, /* btVoid */
1333 struct type
*tp
= 0;
1336 enum type_code type_code
;
1338 /* Use aux as a type information record, map its basic type. */
1340 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1341 if (t
->bt
> (sizeof (map_bt
)/sizeof (*map_bt
))) {
1342 complain (&basic_type_complaint
, (char *)t
->bt
);
1343 return builtin_type_int
;
1345 if (map_bt
[t
->bt
]) {
1346 tp
= *map_bt
[t
->bt
];
1350 /* Cannot use builtin types -- build our own */
1353 tp
= lookup_pointer_type (builtin_type_void
);
1357 type_code
= TYPE_CODE_STRUCT
;
1361 type_code
= TYPE_CODE_UNION
;
1365 type_code
= TYPE_CODE_ENUM
;
1369 type_code
= TYPE_CODE_RANGE
;
1373 type_code
= TYPE_CODE_SET
;
1378 complain (&basic_type_complaint
, (char *)t
->bt
);
1379 return builtin_type_int
;
1383 /* Skip over any further type qualifiers (FIXME). */
1385 /* This is the way it would work if the compiler worked */
1389 ecoff_swap_tir_in (bigend
, ax
, t1
);
1390 } while (t1
->continued
);
1393 /* Move on to next aux */
1397 *bs
= AUX_GET_WIDTH (bigend
, ax
);
1401 /* All these types really point to some (common) MIPS type
1402 definition, and only the type-qualifiers fully identify
1403 them. We'll make the same effort at sharing. */
1404 if (t
->bt
== btIndirect
||
1405 t
->bt
== btStruct
||
1408 t
->bt
== btTypedef
||
1411 char name
[256], *pn
;
1413 /* Try to cross reference this type */
1414 ax
+= cross_ref(ax
, &tp
, type_code
, &pn
, bigend
);
1415 /* reading .o file ? */
1416 if (UNSAFE_DATA_ADDR(tp
))
1417 tp
= init_type(type_code
, 0, 0, 0, (struct objfile
*) NULL
);
1418 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1419 sprintf(name
, fmt
, pn
);
1421 /* Usually, TYPE_CODE(tp) is already type_code. The main
1422 exception is if we guessed wrong re struct/union/enum. */
1423 if (TYPE_CODE(tp
) != type_code
) {
1424 complain (&bad_tag_guess_complaint
, 0);
1425 TYPE_CODE(tp
) = type_code
;
1427 if (TYPE_NAME(tp
) == NULL
|| strcmp(TYPE_NAME(tp
), name
) != 0)
1428 TYPE_NAME(tp
) = obsavestring(name
, strlen(name
),
1429 ¤t_objfile
-> type_obstack
);
1432 /* Deal with range types */
1433 if (t
->bt
== btRange
) {
1434 TYPE_NFIELDS (tp
) = 2;
1436 (struct field
*) obstack_alloc (¤t_objfile
-> type_obstack
,
1437 2 * sizeof (struct field
));
1438 TYPE_FIELD_NAME (tp
, 0) = obsavestring ("Low", strlen ("Low"),
1439 ¤t_objfile
-> type_obstack
);
1440 TYPE_FIELD_BITPOS (tp
, 0) = AUX_GET_DNLOW (bigend
, ax
);
1442 TYPE_FIELD_NAME (tp
, 1) = obsavestring ("High", strlen ("High"),
1443 ¤t_objfile
-> type_obstack
);
1444 TYPE_FIELD_BITPOS (tp
, 1) = AUX_GET_DNHIGH (bigend
, ax
);
1448 /* Parse all the type qualifiers now. If there are more
1449 than 6 the game will continue in the next aux */
1451 #define PARSE_TQ(tq) \
1452 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, bigend);
1454 again
: PARSE_TQ(tq0
);
1464 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1470 /* Make up a complex type from a basic one. Type is passed by
1471 reference in TPP and side-effected as necessary. The type
1472 qualifier TQ says how to handle the aux symbols at AX for
1473 the symbol SX we are currently analyzing. BIGEND says whether
1474 aux symbols are big-endian or little-endian.
1475 Returns the number of aux symbols we parsed. */
1478 upgrade_type(tpp
, tq
, ax
, bigend
)
1487 /* Used in array processing */
1496 t
= lookup_pointer_type (*tpp
);
1501 t
= lookup_function_type (*tpp
);
1507 t
= init_type(TYPE_CODE_ARRAY
, 0, 0, 0, (struct objfile
*) NULL
);
1508 TYPE_TARGET_TYPE(t
) = *tpp
;
1510 /* Determine and record the domain type (type of index) */
1511 ecoff_swap_rndx_in (bigend
, ax
, &rndx
);
1516 rf
= AUX_GET_ISYM (bigend
, ax
);
1519 fh
= get_rfd(cur_fd
, rf
);
1521 /* Fields are kept in an array */
1522 /* FIXME - Memory leak! */
1523 if (TYPE_NFIELDS(t
))
1524 TYPE_FIELDS(t
) = (struct field
*)
1525 xrealloc((PTR
) TYPE_FIELDS(t
),
1526 (TYPE_NFIELDS(t
)+1) * sizeof(struct field
));
1528 TYPE_FIELDS(t
) = (struct field
*)
1529 xzalloc(sizeof(struct field
));
1530 f
= &(TYPE_FIELD(t
,TYPE_NFIELDS(t
)));
1532 memset((PTR
)f
, 0, sizeof(struct field
));
1534 /* XXX */ f
->type
= parse_type(id
+ (union aux_ext
*)fh
->iauxBase
,
1535 &f
->bitsize
, bigend
);
1538 lower
= AUX_GET_DNLOW (bigend
, ax
);
1540 upper
= AUX_GET_DNHIGH (bigend
, ax
);
1542 rf
= AUX_GET_WIDTH (bigend
, ax
); /* bit size of array element */
1544 /* Check whether supplied array element bit size matches
1545 the known size of the element type. If this complaint
1546 ends up not happening, we can remove this code. It's
1547 here because we aren't sure we understand this *&%&$
1549 id
= TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) << 3; /* bitsize */
1551 /* Most likely an undefined type */
1553 TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) = id
>> 3;
1556 complain (&array_bitsize_complaint
, (char *)rf
);
1558 TYPE_LENGTH(t
) = (upper
< 0) ? 0 :
1559 (upper
- lower
+ 1) * (rf
>> 3);
1564 /* Volatile -- currently ignored */
1568 complain (&unknown_type_qual_complaint
, (char *)tq
);
1574 /* Parse a procedure descriptor record PR. Note that the procedure
1575 is parsed _after_ the local symbols, now we just make up the
1576 extra information we need into a special symbol that we insert
1577 in the procedure's main block. Note also that images that
1578 have been partially stripped (ld -x) have been deprived
1579 of local symbols, and we have to cope with them here.
1580 The procedure's code ends at BOUND */
1583 parse_procedure(pr
, bound
)
1587 struct symbol
*s
, *i
;
1588 SYMR
*sh
= (SYMR
*)pr
->isym
;
1590 struct mips_extra_func_info
*e
;
1594 /* Make up a name for static procedures. Sigh. */
1595 if (sh
== (SYMR
*)-1) {
1596 sprintf(name
,".static_procedure@%x",pr
->adr
);
1597 sh_name
= savestring(name
, strlen(name
));
1601 sh_name
= (char*)sh
->iss
;
1602 s
= mylookup_symbol(sh_name
, top_stack
->cur_block
,
1603 VAR_NAMESPACE
, LOC_BLOCK
);
1606 b
= SYMBOL_BLOCK_VALUE(s
);
1608 s
= new_symbol(sh_name
);
1609 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1610 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1611 /* Donno its type, hope int is ok */
1612 SYMBOL_TYPE(s
) = lookup_function_type (builtin_type_int
);
1613 add_symbol(s
, top_stack
->cur_block
);
1614 /* Wont have symbols for this one */
1616 SYMBOL_BLOCK_VALUE(s
) = b
;
1617 BLOCK_FUNCTION(b
) = s
;
1618 BLOCK_START(b
) = pr
->adr
;
1619 BLOCK_END(b
) = bound
;
1620 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1621 add_block(b
, top_stack
->cur_st
);
1624 i
= mylookup_symbol(".gdbinfo.", b
, LABEL_NAMESPACE
, LOC_CONST
);
1628 e
= (struct mips_extra_func_info
*)SYMBOL_VALUE(i
);
1630 e
->pdr
.isym
= (long)s
;
1634 /* Parse the external symbol ES. Just call parse_symbol() after
1635 making sure we know where the aux are for it. For procedures,
1636 parsing of the PDRs has already provided all the needed
1637 information, we only parse them if SKIP_PROCEDURES is false,
1638 and only if this causes no symbol duplication.
1639 BIGEND says whether aux entries are big-endian or little-endian.
1641 This routine clobbers top_stack->cur_block and ->cur_st. */
1644 parse_external(es
, skip_procedures
, bigend
)
1646 int skip_procedures
;
1651 if (es
->ifd
!= ifdNil
) {
1653 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
) + cur_fd
;
1654 ax
= (union aux_ext
*)cur_fdr
->iauxBase
;
1656 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
);
1659 top_stack
->cur_st
= cur_stab
;
1660 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
1663 /* Reading .o files */
1664 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
) {
1666 switch (es
->asym
.st
) {
1668 case stProc
: what
= "procedure"; n_undef_procs
++; break;
1669 case stGlobal
: what
= "variable"; n_undef_vars
++; break;
1670 case stLabel
: what
= "label"; n_undef_labels
++; break;
1671 default : what
= "symbol"; break;
1675 printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what
,
1676 es
->asym
.iss
, fdr_name((char *)cur_fdr
->rss
));
1680 switch (es
->asym
.st
) {
1682 /* If we have full symbols we do not need more */
1683 if (skip_procedures
)
1685 if (mylookup_symbol ((char *)es
->asym
.iss
, top_stack
->cur_block
,
1686 VAR_NAMESPACE
, LOC_BLOCK
))
1692 * Note that the case of a symbol with indexNil
1693 * must be handled anyways by parse_symbol().
1695 parse_symbol(&es
->asym
, ax
, bigend
);
1702 /* Parse the line number info for file descriptor FH into
1703 GDB's linetable LT. MIPS' encoding requires a little bit
1704 of magic to get things out. Note also that MIPS' line
1705 numbers can go back and forth, apparently we can live
1706 with that and do not need to reorder our linetables */
1711 struct linetable
*lt
;
1713 unsigned char *base
= (unsigned char*)fh
->cbLineOffset
;
1715 int delta
, count
, lineno
= 0;
1721 /* Scan by procedure descriptors */
1723 for (pr
= (PDR
*)IPDFIRST(cur_hdr
,fh
); j
< fh
->cpd
; j
++, pr
++) {
1726 /* No code for this one */
1727 if (pr
->iline
== ilineNil
||
1728 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1731 * Aurgh! To know where to stop expanding we
1734 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1735 if (pr
[l
].iline
!= -1)
1737 if (l
== (fh
->cpd
- j
))
1742 * When procedures are moved around the linenumbers
1743 * are attributed to the next procedure up
1745 if (pr
->iline
>= halt
) continue;
1747 base
= (unsigned char*)pr
->cbLineOffset
;
1748 l
= pr
->adr
>> 2; /* in words */
1749 halt
+= (pr
->adr
>> 2) - pr
->iline
;
1750 for (lineno
= pr
->lnLow
; l
< halt
;) {
1751 count
= *base
& 0x0f;
1752 delta
= *base
++ >> 4;
1756 delta
= (base
[0] << 8) | base
[1];
1757 if (delta
>= 0x8000)
1761 lineno
+= delta
;/* first delta is 0 */
1762 k
= add_line(lt
, lineno
, l
, k
);
1769 /* Master parsing procedure for first-pass reading of file symbols
1770 into a partial_symtab.
1772 Parses the symtab described by the global symbolic header CUR_HDR.
1773 END_OF_TEXT_SEG gives the address just after the text segment for
1774 the symtab we are reading. */
1777 parse_partial_symbols(end_of_text_seg
, objfile
)
1778 int end_of_text_seg
;
1779 struct objfile
*objfile
;
1782 /* int stat_idx, h_max;*/
1783 HDRR
*hdr
= cur_hdr
;
1784 /* Running pointers */
1788 struct partial_symtab
*pst
;
1790 int past_first_source_file
= 0;
1792 /* List of current psymtab's include files */
1793 char **psymtab_include_list
;
1794 int includes_allocated
;
1797 struct pst_map
* fdr_to_pst
;
1798 /* Index within current psymtab dependency list */
1799 struct partial_symtab
**dependency_list
;
1800 int dependencies_used
, dependencies_allocated
;
1801 struct cleanup
*old_chain
;
1803 extern_tab
= (EXTR
**)obstack_alloc (&objfile
->psymbol_obstack
,
1804 sizeof(EXTR
*) * hdr
->iextMax
);
1806 includes_allocated
= 30;
1808 psymtab_include_list
= (char **) alloca (includes_allocated
*
1810 next_symbol_text_func
= mips_next_symbol_text
;
1812 dependencies_allocated
= 30;
1813 dependencies_used
= 0;
1815 (struct partial_symtab
**) alloca (dependencies_allocated
*
1816 sizeof (struct partial_symtab
*));
1818 last_source_file
= 0;
1823 * Only parse the Local and External symbols, and the Relative FDR.
1824 * Fixup enough of the loader symtab to be able to use it.
1825 * Allocate space only for the file's portions we need to
1830 max_glevel
= MIN_GLEVEL
;
1832 /* Allocate the map FDR -> PST.
1833 Minor hack: -O3 images might claim some global data belongs
1834 to FDR -1. We`ll go along with that */
1835 fdr_to_pst
= (struct pst_map
*)xzalloc((hdr
->ifdMax
+1) * sizeof *fdr_to_pst
);
1836 old_chain
= make_cleanup (free
, fdr_to_pst
);
1839 struct partial_symtab
* pst
= new_psymtab("", objfile
);
1840 fdr_to_pst
[-1].pst
= pst
;
1844 /* Pass 1 over external syms: Presize and partition the list */
1845 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1846 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1847 fdr_to_pst
[esh
->ifd
].n_globals
++;
1850 /* Pass 1.5 over files: partition out global symbol space */
1852 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++) {
1853 fdr_to_pst
[f_idx
].globals_offset
= s_idx
;
1854 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
1855 fdr_to_pst
[f_idx
].n_globals
= 0;
1858 /* Pass 2 over external syms: fill in external symbols */
1859 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1860 enum minimal_symbol_type ms_type
= mst_text
;
1861 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1863 extern_tab
[fdr_to_pst
[esh
->ifd
].globals_offset
1864 + fdr_to_pst
[esh
->ifd
].n_globals
++] = esh
;
1866 if (esh
->asym
.sc
== scUndefined
|| esh
->asym
.sc
== scNil
)
1869 switch (esh
->asym
.st
) {
1878 ms_type
= mst_unknown
;
1879 complain (&unknown_ext_complaint
,
1880 (char *)(esh
->asym
.iss
));
1882 prim_record_minimal_symbol ((char *)esh
->asym
.iss
,
1887 /* Pass 3 over files, over local syms: fill in static symbols */
1888 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
1889 struct partial_symtab
*save_pst
;
1891 cur_fdr
= fh
= f_idx
+ (FDR
*)(cur_hdr
->cbFdOffset
);
1893 if (fh
->csym
== 0) {
1894 fdr_to_pst
[f_idx
].pst
= NULL
;
1897 pst
= start_psymtab_common (objfile
, 0, (char*)fh
->rss
,
1898 fh
->cpd
? fh
->adr
: 0,
1899 objfile
->global_psymbols
.next
,
1900 objfile
->static_psymbols
.next
);
1901 pst
->read_symtab_private
= (char *)
1902 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
1905 /* Make everything point to everything. */
1906 FDR_IDX(pst
) = f_idx
;
1907 fdr_to_pst
[f_idx
].pst
= pst
;
1908 fh
->ioptBase
= (int)pst
;
1910 CUR_HDR(pst
) = cur_hdr
;
1912 /* The way to turn this into a symtab is to call... */
1913 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
1915 pst
->texthigh
= pst
->textlow
;
1917 #if 0 /* This is done in start_psymtab_common */
1918 pst
->globals_offset
= global_psymbols
.next
- global_psymbols
.list
;
1919 pst
->statics_offset
= static_psymbols
.next
- static_psymbols
.list
;
1921 pst
->n_global_syms
= 0;
1922 pst
->n_static_syms
= 0;
1925 /* The second symbol must be @stab.
1926 This symbol is emitted by mips-tfile to signal
1927 that the current object file uses encapsulated stabs
1928 instead of mips ecoff for local symbols.
1929 (It is the second symbol because the first symbol is
1930 the stFile used to signal the start of a file). */
1932 && strcmp((char *)(((SYMR
*)fh
->isymBase
)[1].iss
),
1933 stabs_symbol
) == 0) {
1934 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++) {
1937 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
1938 type_code
= MIPS_UNMARK_STAB(sh
->index
);
1939 if (!MIPS_IS_STAB(sh
)) {
1940 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
) {
1941 long procaddr
= sh
->value
;
1942 sh
= AUX_GET_ISYM (fh
->fBigendian
,
1943 sh
->index
+ (union aux_ext
*)(fh
->iauxBase
))
1944 + (SYMR
*) fh
->isymBase
- 1;
1945 if (sh
->st
== stEnd
) {
1946 long high
= procaddr
+ sh
->value
;
1947 if (high
> pst
->texthigh
)
1948 pst
->texthigh
= high
;
1953 #define SET_NAMESTRING() namestring = (char*)sh->iss
1954 #define CUR_SYMBOL_TYPE type_code
1955 #define CUR_SYMBOL_VALUE sh->value
1956 #define START_PSYMTAB(ofile,addr,fname,low,symoff,global_syms,static_syms)\
1958 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
1959 #define addr 0 /* FIXME, should be offset of addresses */
1960 #define HANDLE_RBRAC(val) \
1961 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
1962 #include "partial-stab.h"
1967 register struct partial_symbol
*psym
;
1968 for (cur_sdx
= 0; cur_sdx
< fh
->csym
; ) {
1970 enum address_class
class;
1971 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
1973 if (MIPS_IS_STAB(sh
)) {
1978 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
1979 sh
->index
== 0xfffff) {
1980 /* FIXME, premature? */
1985 name
= (char *)(sh
->iss
);
1990 case stProc
: /* Asm labels apparently */
1991 case stStaticProc
: /* Function */
1992 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
1993 VAR_NAMESPACE
, LOC_BLOCK
,
1994 objfile
->static_psymbols
, sh
->value
);
1995 /* Skip over procedure to next one. */
1996 cur_sdx
= AUX_GET_ISYM (fh
->fBigendian
,
1997 sh
->index
+ (union aux_ext
*)fh
->iauxBase
);
1998 procaddr
= sh
->value
;
2000 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
- 1;
2001 if (sh
->st
!= stEnd
)
2003 high
= procaddr
+ sh
->value
;
2004 if (high
> pst
->texthigh
)
2005 pst
->texthigh
= high
;
2007 case stStatic
: /* Variable */
2010 case stTypedef
: /* Typedef */
2011 class = LOC_TYPEDEF
;
2013 case stConstant
: /* Constant decl */
2019 case stBlock
: /* { }, str, un, enum*/
2020 if (sh
->sc
== scInfo
) {
2021 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
2022 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2023 objfile
->static_psymbols
, sh
->value
);
2025 /* Skip over the block */
2026 cur_sdx
= sh
->index
;
2028 case stFile
: /* File headers */
2029 case stLabel
: /* Labels */
2030 case stEnd
: /* Ends of files */
2033 /* Both complaints are valid: one gives symbol name,
2034 the other the offending symbol type. */
2035 complain (&unknown_sym_complaint
, (char *)sh
->iss
);
2036 complain (&unknown_st_complaint
, (char *)sh
->st
);
2040 /* Use this gdb symbol */
2041 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
2042 VAR_NAMESPACE
, class,
2043 objfile
->static_psymbols
, sh
->value
);
2045 cur_sdx
++; /* Go to next file symbol */
2048 /* Now do enter the external symbols. */
2049 ext_ptr
= &extern_tab
[fdr_to_pst
[f_idx
].globals_offset
];
2050 cur_sdx
= fdr_to_pst
[f_idx
].n_globals
;
2051 PST_PRIVATE(save_pst
)->extern_count
= cur_sdx
;
2052 PST_PRIVATE(save_pst
)->extern_tab
= ext_ptr
;
2053 for (; --cur_sdx
>= 0; ext_ptr
++) {
2054 enum address_class
class;
2055 if ((*ext_ptr
)->ifd
!= f_idx
)
2057 sh
= &(*ext_ptr
)->asym
;
2066 complain (&unknown_ext_complaint
, (char *)sh
->iss
);
2071 if (objfile
->global_psymbols
.next
>=
2072 objfile
->global_psymbols
.list
+ objfile
->global_psymbols
.size
)
2073 extend_psymbol_list (&objfile
->global_psymbols
, objfile
);
2074 psym
= objfile
->global_psymbols
.next
++;
2075 SYMBOL_NAME (psym
) = (char*)sh
->iss
;
2076 SYMBOL_NAMESPACE (psym
) = VAR_NAMESPACE
;
2077 SYMBOL_CLASS (psym
) = class;
2078 SYMBOL_VALUE_ADDRESS (psym
) = (CORE_ADDR
)sh
->value
;
2082 end_psymtab (save_pst
, psymtab_include_list
, includes_used
,
2083 -1, save_pst
->texthigh
,
2084 dependency_list
, dependencies_used
);
2085 if (objfile
-> ei
.entry_point
>= save_pst
->textlow
&&
2086 objfile
-> ei
.entry_point
< save_pst
->texthigh
)
2088 objfile
-> ei
.entry_file_lowpc
= save_pst
->textlow
;
2089 objfile
-> ei
.entry_file_highpc
= save_pst
->texthigh
;
2093 /* Mark the last code address, and remember it for later */
2094 hdr
->cbDnOffset
= end_of_text_seg
;
2096 /* Now scan the FDRs for dependencies */
2097 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
2099 fh
= f_idx
+ (FDR
*)(cur_hdr
->cbFdOffset
);
2100 pst
= fdr_to_pst
[f_idx
].pst
;
2102 /* This should catch stabs-in-ecoff. */
2106 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
2107 /* ...then presumably a .h file: drop reverse depends .h->.c */
2108 for (; s_id0
< fh
->crfd
; s_id0
++) {
2109 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
2111 s_id0
++; /* Skip self-dependency */
2116 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2117 pst
->dependencies
= (struct partial_symtab
**)
2118 obstack_alloc (&objfile
->psymbol_obstack
,
2119 pst
->number_of_dependencies
*
2120 sizeof (struct partial_symtab
*));
2121 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
2122 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
2123 if (*rh
< 0 || *rh
>= hdr
->ifdMax
)
2124 complain(&bad_file_number_complaint
, (char *)*rh
);
2126 pst
->dependencies
[s_idx
-s_id0
] = fdr_to_pst
[*rh
].pst
;
2129 do_cleanups (old_chain
);
2134 /* Do the initial analisys of the F_IDX-th file descriptor.
2135 Allocates a partial symtab for it, and builds the list
2136 of dependent files by recursion. LEV says at which level
2137 of recursion we are called (to pretty up debug traces) */
2139 static struct partial_symtab
*
2140 parse_fdr(f_idx
, lev
, objfile
)
2143 struct objfile
*objfile
;
2146 register struct partial_symtab
*pst
;
2149 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + f_idx
;
2151 /* Use this to indicate into which symtab this file was parsed */
2153 return (struct partial_symtab
*) fh
->ioptBase
;
2155 /* Debuggability level */
2156 if (compare_glevel(max_glevel
, fh
->glevel
) < 0)
2157 max_glevel
= fh
->glevel
;
2159 /* Make a new partial_symtab */
2160 pst
= new_psymtab(fh
->rss
, objfile
);
2165 pst
->textlow
= fh
->adr
;
2166 pst
->texthigh
= fh
->cpd
; /* To be fixed later */
2169 /* Make everything point to everything. */
2170 FDR_IDX(pst
) = f_idx
;
2171 fdr_to_pst
[f_idx
].pst
= pst
;
2172 fh
->ioptBase
= (int)pst
;
2174 /* Analyze its dependencies */
2179 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
2180 /* ...then presumably a .h file: drop reverse depends .h->.c */
2181 for (; s_id0
< fh
->crfd
; s_id0
++) {
2182 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
2184 s_id0
++; /* Skip self-dependency */
2189 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2190 pst
->dependencies
= (struct partial_symtab
**)
2191 obstack_alloc (&objfile
->psymbol_obstack
,
2192 pst
->number_of_dependencies
*
2193 sizeof (struct partial_symtab
*));
2194 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
2195 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
2197 pst
->dependencies
[s_idx
-s_id0
] = parse_fdr(*rh
, lev
+1, objfile
);
2205 mips_next_symbol_text ()
2208 return (char*)((SYMR
*)cur_fdr
->isymBase
)[cur_sdx
].iss
;
2211 /* Ancillary function to psymtab_to_symtab(). Does all the work
2212 for turning the partial symtab PST into a symtab, recurring
2213 first on all dependent psymtabs. The argument FILENAME is
2214 only passed so we can see in debug stack traces what file
2218 psymtab_to_symtab_1(pst
, filename
)
2219 struct partial_symtab
*pst
;
2227 struct linetable
*lines
;
2233 /* How many symbols will we need */
2234 /* FIXME, this does not count enum values. */
2235 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
2236 if (FDR_IDX(pst
) == -1) {
2240 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + FDR_IDX(pst
);
2241 f_max
+= fh
->csym
+ fh
->cpd
;
2242 maxlines
= 2 * fh
->cline
;
2245 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2248 && strcmp((char *)(((SYMR
*)fh
->isymBase
)[1].iss
), stabs_symbol
)
2253 st
= new_symtab (pst
->filename
, 2 * f_max
, maxlines
,
2256 st
= new_symtab ("unknown", f_max
, 0, pst
->objfile
);
2257 lines
= LINETABLE(st
);
2258 pending_list
= (struct mips_pending
**) cur_hdr
->cbOptOffset
;
2259 if (pending_list
== 0) {
2260 pending_list
= (struct mips_pending
**)
2261 xzalloc(cur_hdr
->ifdMax
* sizeof(struct mips_pending
*));
2262 cur_hdr
->cbOptOffset
= (int)pending_list
;
2266 /* Read in all partial symbtabs on which this one is dependent.
2267 NOTE that we do have circular dependencies, sigh. We solved
2268 that by setting pst->readin before this point. */
2270 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2271 if (!pst
->dependencies
[i
]->readin
) {
2272 /* Inform about additional files to be read in. */
2275 fputs_filtered (" ", stdout
);
2277 fputs_filtered ("and ", stdout
);
2279 printf_filtered ("%s...",
2280 pst
->dependencies
[i
]->filename
);
2281 wrap_here (""); /* Flush output */
2284 /* We only pass the filename for debug purposes */
2285 psymtab_to_symtab_1(pst
->dependencies
[i
],
2286 pst
->dependencies
[i
]->filename
);
2290 /* Now read the symbols for this symtab */
2292 current_objfile
= pst
-> objfile
;
2294 cur_fd
= FDR_IDX(pst
);
2297 /* Get a new lexical context */
2300 top_stack
->cur_st
= cur_stab
;
2301 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab
),
2303 BLOCK_START(top_stack
->cur_block
) = fh
? fh
->adr
: 0;
2304 BLOCK_END(top_stack
->cur_block
) = 0;
2305 top_stack
->blocktype
= stFile
;
2306 top_stack
->maxsyms
= 2*f_max
;
2307 top_stack
->cur_type
= 0;
2308 top_stack
->procadr
= 0;
2309 top_stack
->numargs
= 0;
2312 /* Parse locals and procedures */
2317 /* Parse local symbols first */
2322 current_objfile
= NULL
;
2325 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++) {
2326 register SYMR
*sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
2327 char *name
= (char*)sh
->iss
;
2328 CORE_ADDR valu
= sh
->value
;
2329 if (MIPS_IS_STAB(sh
)) {
2330 int type_code
= MIPS_UNMARK_STAB(sh
->index
);
2331 process_one_symbol (type_code
, 0, valu
, name
, /*FIXME*/ 0,
2334 else if (sh
->st
== stLabel
&& sh
->index
!= indexNil
) {
2335 /* Handle encoded stab line number. */
2336 record_line (current_subfile
, sh
->index
, valu
);
2339 st
= end_symtab (pst
->texthigh
, 0, 0, pst
->objfile
);
2342 /* BOUND is the highest core address of this file's procedures */
2343 int bound
= cur_fd
== cur_hdr
->ifdMax
- 1 ? cur_hdr
->cbDnOffset
2345 for (cur_sdx
= 0; cur_sdx
< fh
->csym
; ) {
2346 sh
= (SYMR
*) (fh
->isymBase
) + cur_sdx
;
2347 cur_sdx
+= parse_symbol(sh
, (union aux_ent
*)fh
->iauxBase
,
2351 /* Procedures next, note we need to look-ahead to
2352 find out where the procedure's code ends */
2355 for (i
= 0; i
< fh
->cpd
-1; i
++) {
2356 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2357 parse_procedure(pr
, pr
[1].adr
); /* next proc up */
2360 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2361 parse_procedure(pr
, bound
); /* next file up */
2363 /* Linenumbers. At the end, check if we can save memory */
2364 parse_lines(fh
, lines
);
2365 if (lines
->nitems
< fh
->cline
)
2366 lines
= shrink_linetable(lines
);
2372 LINETABLE(st
) = lines
;
2374 /* .. and our share of externals.
2375 XXX use the global list to speed up things here. how ?
2376 FIXME, Maybe quit once we have found the right number of ext's? */
2377 /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
2378 top_stack
->blocktype
= stFile
;
2379 top_stack
->maxsyms
=
2380 cur_hdr
->isymMax
+ cur_hdr
->ipdMax
+ cur_hdr
->iextMax
;
2382 ext_ptr
= PST_PRIVATE(pst
)->extern_tab
;
2383 for (i
= PST_PRIVATE(pst
)->extern_count
; --i
>= 0; ext_ptr
++)
2384 parse_external(*ext_ptr
, 1, fh
->fBigendian
);
2386 /* If there are undefined, tell the user */
2387 if (n_undef_symbols
) {
2388 printf_filtered("File %s contains %d unresolved references:",
2389 st
->filename
, n_undef_symbols
);
2390 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2391 n_undef_vars
, n_undef_procs
, n_undef_labels
);
2392 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
2398 /* Sort the symbol table now, we are done adding symbols to it.*/
2399 sort_symtab_syms(st
);
2403 /* Now link the psymtab and the symtab. */
2406 current_objfile
= NULL
;
2409 /* Ancillary parsing procedures. */
2411 /* Lookup the type at relative index RN. Return it in TPP
2412 if found and in any event come up with its name PNAME.
2413 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
2414 Return value says how many aux symbols we ate. */
2417 cross_ref(ax
, tpp
, type_code
, pname
, bigend
)
2420 enum type_code type_code
; /* Use to alloc new type if none is found. */
2428 ecoff_swap_rndx_in (bigend
, ax
, rn
);
2430 /* Escape index means 'the next one' */
2431 if (rn
->rfd
== 0xfff) {
2433 rf
= AUX_GET_ISYM (bigend
, ax
+ 1);
2440 *pname
= "<undefined>";
2443 * Find the relative file descriptor and the symbol in it
2445 FDR
*fh
= get_rfd(cur_fd
, rf
);
2450 * If we have processed this symbol then we left a forwarding
2451 * pointer to the corresponding GDB symbol. If not, we`ll put
2452 * it in a list of pending symbols, to be processed later when
2453 * the file f will be. In any event, we collect the name for
2454 * the type here. Which is why we made a first pass at
2457 sh
= (SYMR
*) (fh
->isymBase
) + rn
->index
;
2459 /* Careful, we might be looking at .o files */
2460 *pname
= (UNSAFE_DATA_ADDR(sh
->iss
)) ? "<undefined>" :
2463 /* Have we parsed it ? */
2464 if ((!UNSAFE_DATA_ADDR(sh
->value
)) && (sh
->st
== stParsed
)) {
2465 t
= (struct type
*) sh
->value
;
2468 /* Avoid duplicates */
2469 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
2473 *tpp
= init_type(type_code
, 0, 0, 0, (struct objfile
*) NULL
);
2474 add_pending(fh
, sh
, *tpp
);
2479 /* We used one auxent normally, two if we got a "next one" rf. */
2484 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2485 keeping the symtab sorted */
2487 static struct symbol
*
2488 mylookup_symbol (name
, block
, namespace, class)
2490 register struct block
*block
;
2491 enum namespace namespace;
2492 enum address_class
class;
2494 register int bot
, top
, inc
;
2495 register struct symbol
*sym
;
2498 top
= BLOCK_NSYMS(block
);
2501 sym
= BLOCK_SYM(block
, bot
);
2502 if (SYMBOL_NAME(sym
)[0] == inc
2503 && SYMBOL_NAMESPACE(sym
) == namespace
2504 && SYMBOL_CLASS(sym
) == class
2505 && !strcmp(SYMBOL_NAME(sym
), name
))
2509 block
= BLOCK_SUPERBLOCK (block
);
2511 return mylookup_symbol (name
, block
, namespace, class);
2516 /* Add a new symbol S to a block B.
2517 Infrequently, we will need to reallocate the block to make it bigger.
2518 We only detect this case when adding to top_stack->cur_block, since
2519 that's the only time we know how big the block is. FIXME. */
2526 int nsyms
= BLOCK_NSYMS(b
)++;
2527 struct block
*origb
;
2528 struct parse_stack
*stackp
;
2530 if (b
== top_stack
->cur_block
&&
2531 nsyms
>= top_stack
->maxsyms
) {
2532 complain (&block_overflow_complaint
, s
->name
);
2533 /* In this case shrink_block is actually grow_block, since
2534 BLOCK_NSYMS(b) is larger than its current size. */
2536 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
2538 /* Now run through the stack replacing pointers to the
2539 original block. shrink_block has already done this
2540 for the blockvector and BLOCK_FUNCTION. */
2541 for (stackp
= top_stack
; stackp
; stackp
= stackp
->next
) {
2542 if (stackp
->cur_block
== origb
) {
2543 stackp
->cur_block
= b
;
2544 stackp
->maxsyms
= BLOCK_NSYMS (b
);
2548 BLOCK_SYM(b
,nsyms
) = s
;
2551 /* Add a new block B to a symtab S */
2558 struct blockvector
*bv
= BLOCKVECTOR(s
);
2560 bv
= (struct blockvector
*)xrealloc((PTR
) bv
,
2561 sizeof(struct blockvector
) +
2562 BLOCKVECTOR_NBLOCKS(bv
)
2563 * sizeof(bv
->block
));
2564 if (bv
!= BLOCKVECTOR(s
))
2565 BLOCKVECTOR(s
) = bv
;
2567 BLOCKVECTOR_BLOCK(bv
, BLOCKVECTOR_NBLOCKS(bv
)++) = b
;
2570 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2571 MIPS' linenumber encoding might need more than one byte
2572 to describe it, LAST is used to detect these continuation lines */
2575 add_line(lt
, lineno
, adr
, last
)
2576 struct linetable
*lt
;
2582 last
= -2; /* make sure we record first line */
2584 if (last
== lineno
) /* skip continuation lines */
2587 lt
->item
[lt
->nitems
].line
= lineno
;
2588 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
2592 /* Sorting and reordering procedures */
2594 /* Blocks with a smaller low bound should come first */
2597 compare_blocks(b1
, b2
)
2598 struct block
**b1
, **b2
;
2600 register int addr_diff
;
2602 addr_diff
= (BLOCK_START((*b1
))) - (BLOCK_START((*b2
)));
2604 return (BLOCK_END((*b1
))) - (BLOCK_END((*b2
)));
2608 /* Sort the blocks of a symtab S.
2609 Reorder the blocks in the blockvector by code-address,
2610 as required by some MI search routines */
2616 struct blockvector
*bv
= BLOCKVECTOR(s
);
2618 if (BLOCKVECTOR_NBLOCKS(bv
) <= 2) {
2620 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) == 0)
2621 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = 0;
2622 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) == 0)
2623 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) = 0;
2627 * This is very unfortunate: normally all functions are compiled in
2628 * the order they are found, but if the file is compiled -O3 things
2629 * are very different. It would be nice to find a reliable test
2630 * to detect -O3 images in advance.
2632 if (BLOCKVECTOR_NBLOCKS(bv
) > 3)
2633 qsort(&BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
),
2634 BLOCKVECTOR_NBLOCKS(bv
) - FIRST_LOCAL_BLOCK
,
2635 sizeof(struct block
*),
2639 register CORE_ADDR high
= 0;
2640 register int i
, j
= BLOCKVECTOR_NBLOCKS(bv
);
2642 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
2643 if (high
< BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
)))
2644 high
= BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
));
2645 BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = high
;
2648 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) =
2649 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
));
2651 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2652 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2653 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2654 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2658 /* Constructor/restructor/destructor procedures */
2660 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2661 MAXSYMS and linenumbers MAXLINES we'll put in it */
2663 static struct symtab
*
2664 new_symtab(name
, maxsyms
, maxlines
, objfile
)
2668 struct objfile
*objfile
;
2670 struct symtab
*s
= allocate_symtab (name
, objfile
);
2672 LINETABLE(s
) = new_linetable(maxlines
);
2674 /* All symtabs must have at least two blocks */
2675 BLOCKVECTOR(s
) = new_bvect(2);
2676 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
) = new_block(maxsyms
);
2677 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), STATIC_BLOCK
) = new_block(maxsyms
);
2678 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
),STATIC_BLOCK
)) =
2679 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
);
2681 s
->free_code
= free_linetable
;
2686 /* Allocate a new partial_symtab NAME */
2688 static struct partial_symtab
*
2689 new_psymtab(name
, objfile
)
2691 struct objfile
*objfile
;
2693 struct partial_symtab
*psymtab
;
2695 /* FIXME -- why (char *) -1 rather than NULL? */
2696 psymtab
= allocate_psymtab (name
== (char *) -1 ? "<no name>" : name
,
2699 /* Keep a backpointer to the file's symbols */
2701 psymtab
-> read_symtab_private
= (char *)
2702 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
2703 CUR_HDR(psymtab
) = cur_hdr
;
2705 /* The way to turn this into a symtab is to call... */
2706 psymtab
->read_symtab
= mipscoff_psymtab_to_symtab
;
2711 /* Allocate a linetable array of the given SIZE. Since the struct
2712 already includes one item, we subtract one when calculating the
2713 proper size to allocate. */
2715 static struct linetable
*
2719 struct linetable
*l
;
2721 size
= (size
-1) * sizeof(l
->item
) + sizeof(struct linetable
);
2722 l
= (struct linetable
*)xmalloc(size
);
2727 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2728 I am not so sure about the 3.4 ones.
2730 Since the struct linetable already includes one item, we subtract one when
2731 calculating the proper size to allocate. */
2733 static struct linetable
*
2734 shrink_linetable(lt
)
2735 struct linetable
* lt
;
2738 return (struct linetable
*) xrealloc ((PTR
)lt
,
2739 sizeof(struct linetable
)
2740 + (lt
->nitems
- 1) * sizeof(lt
->item
));
2743 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2745 static struct blockvector
*
2749 struct blockvector
*bv
;
2752 size
= sizeof(struct blockvector
) + nblocks
* sizeof(struct block
*);
2753 bv
= (struct blockvector
*) xzalloc(size
);
2755 BLOCKVECTOR_NBLOCKS(bv
) = nblocks
;
2760 /* Allocate and zero a new block of MAXSYMS symbols */
2762 static struct block
*
2766 int size
= sizeof(struct block
) + (maxsyms
-1) * sizeof(struct symbol
*);
2768 return (struct block
*)xzalloc (size
);
2771 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2772 Shrink_block can also be used by add_symbol to grow a block. */
2774 static struct block
*
2780 struct blockvector
*bv
= BLOCKVECTOR(s
);
2783 /* Just reallocate it and fix references to the old one */
2785 new = (struct block
*) xrealloc ((PTR
)b
, sizeof(struct block
) +
2786 (BLOCK_NSYMS(b
)-1) * sizeof(struct symbol
*));
2788 /* Should chase pointers to old one. Fortunately, that`s just
2789 the block`s function and inferior blocks */
2790 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b
)
2791 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2792 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2793 if (BLOCKVECTOR_BLOCK(bv
,i
) == b
)
2794 BLOCKVECTOR_BLOCK(bv
,i
) = new;
2795 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) == b
)
2796 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) = new;
2800 /* Create a new symbol with printname NAME */
2802 static struct symbol
*
2806 struct symbol
*s
= (struct symbol
*)
2807 obstack_alloc (¤t_objfile
->symbol_obstack
, sizeof (struct symbol
));
2809 memset ((PTR
)s
, 0, sizeof (*s
));
2810 SYMBOL_NAME(s
) = name
;
2814 /* Create a new type with printname NAME */
2816 static struct type
*
2822 t
= alloc_type (current_objfile
);
2823 TYPE_NAME(t
) = name
;
2824 TYPE_CPLUS_SPECIFIC(t
) = (struct cplus_struct_type
*)
2825 &cplus_struct_default
;
2830 /* Things used for calling functions in the inferior.
2831 These functions are exported to our companion
2832 mips-tdep.c file and are here because they play
2833 with the symbol-table explicitly. */
2835 /* Sigtramp: make sure we have all the necessary information
2836 about the signal trampoline code. Since the official code
2837 from MIPS does not do so, we make up that information ourselves.
2838 If they fix the library (unlikely) this code will neutralize itself. */
2845 struct block
*b
, *b0
;
2847 sigtramp_address
= -1;
2849 /* We know it is sold as sigvec */
2850 s
= lookup_symbol("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
2852 /* Most programs do not play with signals */
2854 s
= lookup_symbol("_sigtramp", 0, VAR_NAMESPACE
, 0, NULL
);
2857 b0
= SYMBOL_BLOCK_VALUE(s
);
2859 /* A label of sigvec, to be more precise */
2860 s
= lookup_symbol("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
2863 /* But maybe this program uses its own version of sigvec */
2867 /* Did we or MIPSco fix the library ? */
2868 if (SYMBOL_CLASS(s
) == LOC_BLOCK
)
2870 sigtramp_address
= BLOCK_START(SYMBOL_BLOCK_VALUE(s
));
2871 sigtramp_end
= BLOCK_END(SYMBOL_BLOCK_VALUE(s
));
2875 sigtramp_address
= SYMBOL_VALUE(s
);
2876 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
2878 /* But what symtab does it live in ? */
2879 st
= find_pc_symtab(SYMBOL_VALUE(s
));
2882 * Ok, there goes the fix: turn it into a procedure, with all the
2883 * needed info. Note we make it a nested procedure of sigvec,
2884 * which is the way the (assembly) code is actually written.
2886 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2887 SYMBOL_CLASS(s
) = LOC_BLOCK
;
2888 SYMBOL_TYPE(s
) = init_type(TYPE_CODE_FUNC
, 4, 0, 0, (struct objfile
*) NULL
);
2889 TYPE_TARGET_TYPE(SYMBOL_TYPE(s
)) = builtin_type_void
;
2891 /* Need a block to allocate .gdbinfo. in */
2893 SYMBOL_BLOCK_VALUE(s
) = b
;
2894 BLOCK_START(b
) = sigtramp_address
;
2895 BLOCK_END(b
) = sigtramp_end
;
2896 BLOCK_FUNCTION(b
) = s
;
2897 BLOCK_SUPERBLOCK(b
) = BLOCK_SUPERBLOCK(b0
);
2901 /* Make a .gdbinfo. for it */
2903 struct mips_extra_func_info
*e
=
2904 (struct mips_extra_func_info
*)
2905 xzalloc(sizeof(struct mips_extra_func_info
));
2907 e
->numargs
= 0; /* the kernel thinks otherwise */
2908 /* align_longword(sigcontext + SIGFRAME) */
2909 e
->pdr
.frameoffset
= 0x150;
2910 e
->pdr
.framereg
= SP_REGNUM
;
2912 e
->pdr
.regmask
= -2;
2913 e
->pdr
.regoffset
= -(41 * sizeof(int));
2914 e
->pdr
.fregmask
= -1;
2915 e
->pdr
.fregoffset
= -(37 * sizeof(int));
2916 e
->pdr
.isym
= (long)s
;
2918 current_objfile
= st
->objfile
; /* Keep new_symbol happy */
2919 s
= new_symbol(".gdbinfo.");
2920 SYMBOL_VALUE(s
) = (int) e
;
2921 SYMBOL_NAMESPACE(s
) = LABEL_NAMESPACE
;
2922 SYMBOL_CLASS(s
) = LOC_CONST
;
2923 SYMBOL_TYPE(s
) = builtin_type_void
;
2924 current_objfile
= NULL
;
2927 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
2930 /* Initialization */
2932 static struct sym_fns ecoff_sym_fns
=
2934 "ecoff", /* sym_name: name or name prefix of BFD target type */
2935 5, /* sym_namelen: number of significant sym_name chars */
2936 mipscoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
2937 mipscoff_symfile_init
,/* sym_init: read initial info, setup for sym_read() */
2938 mipscoff_symfile_read
,/* sym_read: read a symbol file into symtab */
2939 mipscoff_symfile_finish
,/* sym_finish: finished with file, cleanup */
2940 NULL
/* next: pointer to next struct sym_fns */
2945 _initialize_mipsread ()
2947 add_symtab_fns (&ecoff_sym_fns
);
2949 /* Missing basic types */
2950 builtin_type_string
=
2951 init_type (TYPE_CODE_PASCAL_ARRAY
,
2953 (struct objfile
*) NULL
);
2954 builtin_type_complex
=
2955 init_type(TYPE_CODE_FLT
,
2956 2 * sizeof(float), 0, "complex",
2957 (struct objfile
*) NULL
);
2958 builtin_type_double_complex
=
2959 init_type(TYPE_CODE_FLT
,
2960 2 * sizeof(double), 0, "double_complex",
2961 (struct objfile
*) NULL
);
2962 builtin_type_fixed_dec
=
2963 init_type(TYPE_CODE_INT
, sizeof(int),
2965 (struct objfile
*) NULL
);
2966 builtin_type_float_dec
=
2967 init_type(TYPE_CODE_FLT
, sizeof(double),
2968 0, "floating_decimal",
2969 (struct objfile
*) NULL
);