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
59 #include <sys/param.h>
63 #include <mips/syms.h>
70 #endif /* not CMUCS */
72 #include "coff/mips.h"
73 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
74 #include "aout/aout64.h"
75 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native, now */
76 #include "coff/ecoff-ext.h"
79 struct external_filehdr f
;
80 struct external_aouthdr a
;
83 /* These must match the corresponding definition in gcc/config/xm-mips.h.
84 At some point, these should probably go into a shared include file,
85 but currently gcc and gdb do not share any directories. */
87 #define CODE_MASK 0x8F300
88 #define MIPS_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK)
89 #define MIPS_MARK_STAB(code) ((code)+CODE_MASK)
90 #define MIPS_UNMARK_STAB(code) ((code)-CODE_MASK)
91 #define STABS_SYMBOL "@stabs"
93 /* Each partial symbol table entry contains a pointer to private data for the
94 read_symtab() function to use when expanding a partial symbol table entry
95 to a full symbol table entry.
97 For mipsread this structure contains the index of the FDR that this psymtab
98 represents and a pointer to the symbol table header HDRR from the symbol
99 file that the psymtab was created from. */
101 #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
102 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
103 #define CUR_HDR(p) (PST_PRIVATE(p)->cur_hdr)
108 EXTR
**extern_tab
; /* Pointer to external symbols for this file. */
109 int extern_count
; /* Size of extern_tab. */
112 /* Things we import explicitly from other modules */
114 extern int info_verbose
;
115 extern struct block
*block_for_pc();
116 extern void sort_symtab_syms();
118 /* Various complaints about symbol reading that don't abort the process */
120 struct complaint bad_file_number_complaint
=
121 {"bad file number %d", 0, 0};
123 struct complaint unknown_ext_complaint
=
124 {"unknown external symbol %s", 0, 0};
126 struct complaint unknown_sym_complaint
=
127 {"unknown local symbol %s", 0, 0};
129 struct complaint unknown_st_complaint
=
130 {"with type %d", 0, 0};
132 struct complaint block_overflow_complaint
=
133 {"block containing %s overfilled", 0, 0};
135 struct complaint basic_type_complaint
=
136 {"cannot map MIPS basic type 0x%x", 0, 0};
138 struct complaint unknown_type_qual_complaint
=
139 {"unknown type qualifier 0x%x", 0, 0};
141 struct complaint array_bitsize_complaint
=
142 {"size of array target type not known, assuming %d bits", 0, 0};
144 struct complaint bad_tag_guess_complaint
=
145 {"guessed tag type incorrectly", 0, 0};
147 /* Macros and extra defs */
149 /* Already-parsed symbols are marked specially */
151 #define stParsed stType
153 /* Puns: hard to find whether -g was used and how */
155 #define MIN_GLEVEL GLEVEL_0
156 #define compare_glevel(a,b) \
157 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
158 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
160 /* When looking at .o files, avoid tripping over bad addresses */
162 #define SAFE_TEXT_ADDR 0x400000
163 #define SAFE_DATA_ADDR 0x10000000
165 #define UNSAFE_DATA_ADDR(p) ((unsigned)p < SAFE_DATA_ADDR || (unsigned)p > 2*SAFE_DATA_ADDR)
167 /* Things that really are local to this module */
169 /* GDB symtable for the current compilation unit */
171 static struct symtab
*cur_stab
;
173 /* MIPS symtab header for the current file */
175 static HDRR
*cur_hdr
;
177 /* Pointer to current file decriptor record, and its index */
182 /* Index of current symbol */
186 /* Note how much "debuggable" this image is. We would like
187 to see at least one FDR with full symbols */
192 /* When examining .o files, report on undefined symbols */
194 static int n_undef_symbols
, n_undef_labels
, n_undef_vars
, n_undef_procs
;
196 /* Pseudo symbol to use when putting stabs into the symbol table. */
198 static char stabs_symbol
[] = STABS_SYMBOL
;
200 /* Extra builtin types */
202 struct type
*builtin_type_complex
;
203 struct type
*builtin_type_double_complex
;
204 struct type
*builtin_type_fixed_dec
;
205 struct type
*builtin_type_float_dec
;
206 struct type
*builtin_type_string
;
208 /* Forward declarations */
220 parse_partial_symbols();
228 static struct symbol
*new_symbol();
229 static struct type
*new_type();
230 static struct block
*new_block();
231 static struct symtab
*new_symtab();
232 static struct linetable
*new_linetable();
233 static struct blockvector
*new_bvect();
235 static struct type
*parse_type();
236 static struct symbol
*mylookup_symbol();
237 static struct block
*shrink_block();
238 static void sort_blocks();
240 static int compare_symtabs();
241 static int compare_psymtabs();
242 static int compare_blocks();
244 static struct partial_symtab
*new_psymtab();
245 static struct partial_symtab
*parse_fdr();
246 static int compare_psymbols();
248 static void psymtab_to_symtab_1();
249 static void add_block();
250 static void add_symbol();
251 static int add_line();
252 static struct linetable
*shrink_linetable();
253 static char* mips_next_symbol_text ();
256 /* Things we export to other modules */
258 /* Address bounds for the signal trampoline in inferior, if any */
259 /* FIXME: Nothing really seems to use this. Why is it here? */
261 CORE_ADDR sigtramp_address
, sigtramp_end
;
263 /* The entry point (starting address) of the file, if it is an executable. */
265 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
266 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
271 /* If we have a file symbol header lying around, blow it away. */
273 free ((char *)cur_hdr
);
278 mipscoff_symfile_init (sf
)
281 sf
->sym_private
= NULL
;
285 mipscoff_symfile_read(sf
, addr
, mainline
)
290 bfd
*abfd
= sf
->objfile
->obfd
;
293 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
294 desc
= fileno ((FILE *)(abfd
->iostream
)); /* Raw file descriptor */
297 init_minimal_symbol_collection ();
298 make_cleanup (discard_minimal_symbols
, 0);
300 /* Now that the executable file is positioned at symbol table,
301 process it and define symbols accordingly. */
303 read_mips_symtab(sf
->objfile
, desc
);
305 /* Install any minimal symbols that have been collected as the current
306 minimal symbols for this objfile. */
308 install_minimal_symbols (sf
-> objfile
);
311 /* Allocate zeroed memory */
316 char *p
= xmalloc(size
);
322 /* Exported procedure: Builds a symtab from the PST partial one.
323 Restores the environment in effect when PST was created, delegates
324 most of the work to an ancillary procedure, and sorts
325 and reorders the symtab list at the end */
328 mipscoff_psymtab_to_symtab(pst
)
329 struct partial_symtab
*pst
;
338 printf_filtered("Reading in symbols for %s...", pst
->filename
);
341 /* Restore the header and list of pending typedefs */
342 cur_hdr
= CUR_HDR(pst
);
344 next_symbol_text_func
= mips_next_symbol_text
;
346 psymtab_to_symtab_1(pst
, pst
->filename
);
348 /* Match with global symbols. This only needs to be done once,
349 after all of the symtabs and dependencies have been read in. */
350 scan_file_globals (pst
->objfile
);
353 printf_filtered("done.\n");
356 /* Exported procedure: Is PC in the signal trampoline code */
359 in_sigtramp(pc
, name
)
363 if (sigtramp_address
== 0)
365 return (pc
>= sigtramp_address
&& pc
< sigtramp_end
);
368 /* File-level interface functions */
370 /* Read the symtab information from file FSYM into memory. Also,
371 return address just past end of our text segment in *END_OF_TEXT_SEGP. */
374 read_the_mips_symtab(abfd
, fsym
, end_of_text_segp
)
377 CORE_ADDR
*end_of_text_segp
;
379 int stsize
, st_hdrsize
;
381 struct hdr_ext hdr_ext
;
383 /* Header for executable/object file we read symbols from */
384 struct coff_exec filhdr
;
386 /* We need some info from the initial headers */
388 myread(fsym
, (char *)&filhdr
, sizeof filhdr
);
390 if (end_of_text_segp
)
392 bfd_h_get_32 (abfd
, filhdr
.a
.text_start
) +
393 bfd_h_get_32 (abfd
, filhdr
.a
.tsize
);
395 /* Find and read the symbol table header */
396 st_hdrsize
= bfd_h_get_32 (abfd
, filhdr
.f
.f_nsyms
);
397 st_filptr
= bfd_h_get_32 (abfd
, filhdr
.f
.f_symptr
);
401 lseek(fsym
, st_filptr
, L_SET
);
402 if (st_hdrsize
!= sizeof (hdr_ext
)) { /* Profanity check */
403 error ("Wrong header size: %d, not %d", st_hdrsize
,
406 if (read(fsym
, &hdr_ext
, st_hdrsize
) != st_hdrsize
)
408 ecoff_swap_hdr_in (abfd
, &hdr_ext
, &st_hdr
);
410 /* Find out how large the symbol table is */
411 stsize
= (st_hdr
.cbExtOffset
- (st_filptr
+ st_hdrsize
))
412 + st_hdr
.iextMax
* cbEXTR
;
414 /* Allocate space for the symbol table. Read it in. */
415 cur_hdr
= (HDRR
*) xmalloc(stsize
+ st_hdrsize
);
417 memcpy(cur_hdr
, &hdr_ext
, st_hdrsize
);
418 if (read(fsym
, (char *) cur_hdr
+ st_hdrsize
, stsize
) != stsize
)
421 /* Fixup file_pointers in it */
422 fixup_symtab(cur_hdr
, (char *) cur_hdr
+ st_hdrsize
,
423 st_filptr
+ st_hdrsize
, abfd
);
427 error("Short read on %s", bfd_get_filename (abfd
));
431 /* Turn all file-relative pointers in the symtab described by HDR
432 into memory pointers, given that the symtab itself is located
433 at DATA in memory and F_PTR in the file.
435 Byte-swap all the data structures, in place, while we are at it --
436 except AUX entries, which we leave in their original byte order.
437 They will be swapped as they are used instead. (FIXME: we ought to
438 do all the data structures that way.) */
441 fixup_symtab (hdr
, data
, f_ptr
, abfd
)
452 struct rfd_ext
*rbase
;
454 /* This function depends on the external and internal forms
455 of the MIPS symbol table taking identical space. Check this
456 assumption at compile-time. */
457 static check_hdr1
[1 + sizeof (struct hdr_ext
) - sizeof (HDRR
)] = {0};
458 static check_hdr2
[1 + sizeof (HDRR
) - sizeof (struct hdr_ext
)] = {0};
459 static check_fdr1
[1 + sizeof (struct fdr_ext
) - sizeof (FDR
)] = {0};
460 static check_fdr2
[1 + sizeof (FDR
) - sizeof (struct fdr_ext
)] = {0};
461 static check_pdr1
[1 + sizeof (struct pdr_ext
) - sizeof (PDR
)] = {0};
462 static check_pdr2
[1 + sizeof (PDR
) - sizeof (struct pdr_ext
)] = {0};
463 static check_sym1
[1 + sizeof (struct sym_ext
) - sizeof (SYMR
)] = {0};
464 static check_sym2
[1 + sizeof (SYMR
) - sizeof (struct sym_ext
)] = {0};
465 static check_ext1
[1 + sizeof (struct ext_ext
) - sizeof (EXTR
)] = {0};
466 static check_ext2
[1 + sizeof (EXTR
) - sizeof (struct ext_ext
)] = {0};
467 static check_rfd1
[1 + sizeof (struct rfd_ext
) - sizeof (RFDT
)] = {0};
468 static check_rfd2
[1 + sizeof (RFDT
) - sizeof (struct rfd_ext
)] = {0};
470 /* Swap in the header record. */
471 ecoff_swap_hdr_in (abfd
, hdr
, hdr
);
474 * These fields are useless (and empty) by now:
475 * hdr->cbDnOffset, hdr->cbOptOffset
476 * We use them for other internal purposes.
479 hdr
->cbOptOffset
= 0;
482 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
496 /* Fix all the RFD's. */
497 rbase
= (struct rfd_ext
*)(hdr
->cbRfdOffset
);
498 for (i
= 0; i
< hdr
->crfd
; i
++) {
499 ecoff_swap_rfd_in (abfd
, rbase
+i
, (pRFDT
) rbase
+i
);
502 /* Fix all string pointers inside the symtab, and
503 the FDR records. Also fix other miscellany. */
505 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
506 register unsigned code_offset
;
508 /* Header itself, and strings */
509 fh
= (FDR
*) (hdr
->cbFdOffset
) + f_idx
;
511 /* Swap in the FDR */
512 ecoff_swap_fdr_in (abfd
, fh
, fh
);
514 fh
->issBase
+= hdr
->cbSsOffset
;
516 fh
->rss
= (long)fh
->rss
+ fh
->issBase
;
519 fh
->isymBase
= (int)((SYMR
*)(hdr
->cbSymOffset
)+fh
->isymBase
);
521 /* FIXME! Probably don't want to do this here! */
522 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
523 sh
= (SYMR
*)fh
->isymBase
+ s_idx
;
524 ecoff_swap_sym_in (abfd
, sh
, sh
);
526 sh
->iss
= (long) sh
->iss
+ fh
->issBase
;
532 /* cannot fix fh->ipdFirst because it is a short */
533 #define IPDFIRST(h,fh) \
534 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
536 /* Optional symbols (actually used for partial_symtabs) */
542 fh
->iauxBase
= hdr
->cbAuxOffset
+ fh
->iauxBase
* sizeof(union aux_ext
);
543 /* Relative file descriptor table */
544 fh
->rfdBase
= hdr
->cbRfdOffset
+ fh
->rfdBase
* sizeof(RFDT
);
548 fh
->cbLineOffset
+= hdr
->cbLineOffset
;
550 /* Procedure symbols. (XXX This should be done later) */
551 code_offset
= fh
->adr
;
552 for (s_idx
= 0; s_idx
< fh
->cpd
; s_idx
++) {
553 unsigned name
, only_ext
;
555 pr
= (PDR
*)(IPDFIRST(hdr
,fh
)) + s_idx
;
556 ecoff_swap_pdr_in (abfd
, pr
, pr
);
558 /* Simple rule to find files linked "-x" */
559 only_ext
= fh
->rss
== -1;
561 if (pr
->isym
== -1) {
562 /* static function */
566 name
= hdr
->cbExtOffset
+ pr
->isym
* sizeof(EXTR
);
567 sh
= &((EXTR
*)name
)->asym
;
571 sh
= (SYMR
*)fh
->isymBase
+ pr
->isym
;
572 /* Included code ? */
573 if (s_idx
== 0 && pr
->adr
!= 0)
574 code_offset
-= pr
->adr
;
577 /* Turn index into a pointer */
580 /* Fix line numbers */
581 pr
->cbLineOffset
+= fh
->cbLineOffset
;
583 /* Relocate address */
585 pr
->adr
+= code_offset
;
589 /* External symbols: swap in, and fix string */
590 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
591 esh
= (EXTR
*)(hdr
->cbExtOffset
) + s_idx
;
592 ecoff_swap_ext_in (abfd
, esh
, esh
);
593 esh
->asym
.iss
= esh
->asym
.iss
+ hdr
->cbSsExtOffset
;
598 /* Find a file descriptor given its index RF relative to a file CF */
606 f
= (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
607 /* Object files do not have the RFD table, all refs are absolute */
609 return (FDR
*) (cur_hdr
->cbFdOffset
) + rf
;
610 cf
= *((pRFDT
) f
->rfdBase
+ rf
);
611 return (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
614 /* Return a safer print NAME for a file descriptor */
620 if (name
== (char *) -1)
621 return "<stripped file>";
622 if (UNSAFE_DATA_ADDR(name
))
628 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
629 whether we are adding to the general symtab or not.
630 FIXME: INCREMENTAL is currently always zero, though it should not be. */
633 read_mips_symtab (objfile
, desc
)
634 struct objfile
*objfile
;
637 CORE_ADDR end_of_text_seg
;
639 read_the_mips_symtab(objfile
->obfd
, desc
, &end_of_text_seg
);
641 parse_partial_symbols(end_of_text_seg
, objfile
);
645 * Check to make sure file was compiled with -g.
646 * If not, warn the user of this limitation.
648 if (compare_glevel(max_glevel
, GLEVEL_2
) < 0) {
649 if (max_gdbinfo
== 0)
651 "\n%s not compiled with -g, debugging support is limited.\n",
654 "You should compile with -g2 or -g3 for best debugging support.\n");
660 /* Local utilities */
662 /* Map of FDR indexes to partial symtabs */
665 struct partial_symtab
*pst
; /* the psymtab proper */
666 int n_globals
; /* exported globals (external symbols) */
667 int globals_offset
; /* cumulative */
671 /* Utility stack, used to nest procedures and blocks properly.
672 It is a doubly linked list, to avoid too many alloc/free.
673 Since we might need it quite a few times it is NOT deallocated
676 static struct parse_stack
{
677 struct parse_stack
*next
, *prev
;
678 struct symtab
*cur_st
; /* Current symtab. */
679 struct block
*cur_block
; /* Block in it. */
680 int blocktype
; /* What are we parsing. */
681 int maxsyms
; /* Max symbols in this block. */
682 struct type
*cur_type
; /* Type we parse fields for. */
683 int cur_field
; /* Field number in cur_type. */
684 int procadr
; /* Start addres of this procedure */
685 int numargs
; /* Its argument count */
686 } *top_stack
; /* Top stack ptr */
689 /* Enter a new lexical context */
691 static push_parse_stack()
693 struct parse_stack
*new;
695 /* Reuse frames if possible */
696 if (top_stack
&& top_stack
->prev
)
697 new = top_stack
->prev
;
699 new = (struct parse_stack
*) xzalloc(sizeof(struct parse_stack
));
700 /* Initialize new frame with previous content */
702 register struct parse_stack
*prev
= new->prev
;
705 top_stack
->prev
= new;
707 new->next
= top_stack
;
712 /* Exit a lexical context */
714 static pop_parse_stack()
719 top_stack
= top_stack
->next
;
723 /* Cross-references might be to things we haven't looked at
724 yet, e.g. type references. To avoid too many type
725 duplications we keep a quick fixup table, an array
726 of lists of references indexed by file descriptor */
728 static struct mips_pending
{
729 struct mips_pending
*next
; /* link */
730 SYMR
*s
; /* the symbol */
731 struct type
*t
; /* its partial type descriptor */
735 /* Check whether we already saw symbol SH in file FH as undefined */
738 struct mips_pending
*is_pending_symbol(fh
, sh
)
742 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
743 register struct mips_pending
*p
;
745 /* Linear search is ok, list is typically no more than 10 deep */
746 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
752 /* Check whether we already saw type T in file FH as undefined */
755 struct mips_pending
*is_pending_type(fh
, t
)
759 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
760 register struct mips_pending
*p
;
762 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
768 /* Add a new undef symbol SH of type T */
771 add_pending(fh
, sh
, t
)
776 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
777 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
779 /* Make sure we do not make duplicates */
781 p
= (struct mips_pending
*) xmalloc(sizeof(*p
));
784 p
->next
= pending_list
[f_idx
];
785 pending_list
[f_idx
] = p
;
787 sh
->reserved
= 1; /* for quick check */
790 /* Throw away undef entries when done with file index F_IDX */
795 register struct mips_pending
*p
, *q
;
797 for (p
= pending_list
[f_idx
]; p
; p
= q
) {
801 pending_list
[f_idx
] = 0;
804 /* The number of args to a procedure is not explicit in the symtab,
805 this is the list of all those we know of.
806 This makes parsing more reasonable and avoids extra passes */
808 static struct numarg
{
809 struct numarg
*next
; /* link */
810 unsigned adr
; /* procedure's start address */
811 unsigned num
; /* arg count */
814 /* Record that the procedure at ADR takes NUM arguments. */
819 struct numarg
*n
= (struct numarg
*) xmalloc(sizeof(struct numarg
));
823 n
->next
= numargs_list
;
827 /* See if we know how many arguments the procedure at ADR takes */
832 struct numarg
*n
= numargs_list
;
834 while (n
&& n
->adr
!= adr
)
836 return (n
) ? n
->num
: -1;
839 /* Release storage when done with this file */
844 struct numarg
*n
= numargs_list
, *m
;
855 prepend_tag_kind(tag_name
, type_code
)
865 case TYPE_CODE_STRUCT
:
868 case TYPE_CODE_UNION
:
875 result
= (char*)obstack_alloc (¤t_objfile
->symbol_obstack
,
876 strlen(prefix
) + strlen(tag_name
) + 1);
877 sprintf(result
, "%s%s", prefix
, tag_name
);
882 /* Parsing Routines proper. */
884 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
885 For blocks, procedures and types we open a new lexical context.
886 This is basically just a big switch on the symbol's type.
887 Argument AX is the base pointer of aux symbols for this file (fh->iauxBase).
888 BIGEND says whether aux symbols are big-endian or little-endian.
889 Return count of SYMR's handled (normally one). */
892 parse_symbol(sh
, ax
, bigend
)
903 /* When a symbol is cross-referenced from other files/symbols
904 we mark it explicitly */
905 int pend
= (sh
->reserved
== 1);
906 enum address_class
class;
914 case stGlobal
: /* external symbol, goes into global block */
916 b
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
918 s
= new_symbol(sh
->iss
);
919 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
922 case stStatic
: /* static data, goes into current block. */
924 b
= top_stack
->cur_block
;
925 s
= new_symbol(sh
->iss
);
926 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
929 case stLocal
: /* local variable, goes into current block */
930 if (sh
->sc
== scRegister
) {
931 class = LOC_REGISTER
;
933 sh
->value
+= FP0_REGNUM
-32;
936 b
= top_stack
->cur_block
;
937 s
= new_symbol(sh
->iss
);
938 SYMBOL_VALUE(s
) = sh
->value
;
940 data
: /* Common code for symbols describing data */
941 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
942 SYMBOL_CLASS(s
) = class;
945 /* Type could be missing in a number of cases */
946 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
947 sh
->index
== 0xfffff)
948 SYMBOL_TYPE(s
) = builtin_type_int
; /* undefined? */
950 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, 0, bigend
);
951 /* Value of a data symbol is its memory address */
954 case stParam
: /* arg to procedure, goes into current block */
956 top_stack
->numargs
++;
958 name
= (char*)sh
->iss
;
959 /* Special GNU C++ name. */
960 if (name
[0] == CPLUS_MARKER
&& name
[1] == 't' && name
[2] == 0)
962 s
= new_symbol(name
);
964 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
965 if (sh
->sc
== scRegister
) {
966 SYMBOL_CLASS(s
) = LOC_REGPARM
;
968 sh
->value
+= FP0_REGNUM
-32;
970 SYMBOL_CLASS(s
) = LOC_ARG
;
971 SYMBOL_VALUE(s
) = sh
->value
;
972 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, 0, bigend
);
973 add_symbol(s
, top_stack
->cur_block
);
975 /* FIXME: This has not been tested. See dbxread.c */
976 /* Add the type of this parameter to the function/procedure
977 type of this block. */
978 add_param_to_type(&top_stack
->cur_block
->function
->type
,s
);
982 case stLabel
: /* label, goes into current block */
983 s
= new_symbol(sh
->iss
);
984 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
; /* so that it can be used */
985 SYMBOL_CLASS(s
) = LOC_LABEL
; /* but not misused */
986 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
987 SYMBOL_TYPE(s
) = builtin_type_int
;
988 add_symbol(s
, top_stack
->cur_block
);
991 case stProc
: /* Procedure, usually goes into global block */
992 case stStaticProc
: /* Static procedure, goes into current block */
993 s
= new_symbol(sh
->iss
);
994 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
995 SYMBOL_CLASS(s
) = LOC_BLOCK
;
996 /* Type of the return value */
997 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
998 t
= builtin_type_int
;
1000 t
= parse_type(ax
+ sh
->index
+ 1, 0, bigend
);
1001 b
= top_stack
->cur_block
;
1002 if (sh
->st
== stProc
) {
1003 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
1004 /* The next test should normally be true,
1005 but provides a hook for nested functions
1006 (which we don't want to make global). */
1007 if (b
== BLOCKVECTOR_BLOCK(bv
, STATIC_BLOCK
))
1008 b
= BLOCKVECTOR_BLOCK(bv
, GLOBAL_BLOCK
);
1012 /* Make a type for the procedure itself */
1014 /* FIXME: This has not been tested yet! See dbxread.c */
1015 /* Generate a template for the type of this function. The
1016 types of the arguments will be added as we read the symbol
1018 bcopy(SYMBOL_TYPE(s
),lookup_function_type(t
),sizeof(struct type
));
1020 SYMBOL_TYPE(s
) = lookup_function_type (t
);
1023 /* Create and enter a new lexical context */
1024 b
= new_block(top_stack
->maxsyms
);
1025 SYMBOL_BLOCK_VALUE(s
) = b
;
1026 BLOCK_FUNCTION(b
) = s
;
1027 BLOCK_START(b
) = BLOCK_END(b
) = sh
->value
;
1028 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1029 add_block(b
, top_stack
->cur_st
);
1031 /* Not if we only have partial info */
1032 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
1036 top_stack
->cur_block
= b
;
1037 top_stack
->blocktype
= sh
->st
;
1038 top_stack
->cur_type
= SYMBOL_TYPE(s
);
1039 top_stack
->cur_field
= -1;
1040 top_stack
->procadr
= sh
->value
;
1041 top_stack
->numargs
= 0;
1043 sh
->value
= (long) SYMBOL_TYPE(s
);
1047 #ifndef btVoid /* btVoid was added late. */
1050 /* These new symbol types have been recently added to SGI machines. */
1064 case stBlock
: /* Either a lexical block, or some type */
1066 top_stack
->blocktype
= stBlock
;
1067 if (sh
->sc
== scInfo
) { /* structure/union/enum def */
1069 sh
->st
== stStruct
? TYPE_CODE_STRUCT
1070 : sh
->st
== stUnion
? TYPE_CODE_UNION
1071 : sh
->st
== stEnum
? TYPE_CODE_ENUM
1078 s
= new_symbol(sh
->iss
);
1079 SYMBOL_NAMESPACE(s
) = STRUCT_NAMESPACE
;
1080 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1081 SYMBOL_VALUE(s
) = 0;
1082 add_symbol(s
, top_stack
->cur_block
);
1084 /* First count the number of fields. */
1085 for (tsym
= sh
+1; tsym
->st
!= stEnd
; tsym
++)
1086 if (tsym
->st
== stMember
) {
1087 if (nfields
== 0 && type_code
== TYPE_CODE_UNDEF
)
1088 /* If the type of the member is Nil (or Void)
1089 assume the tag is an enumeration. */
1090 if (tsym
->index
== indexNil
)
1091 type_code
= TYPE_CODE_ENUM
;
1093 ecoff_swap_tir_in (bigend
,
1094 &ax
[tsym
->index
].a_ti
,
1096 if (tir
.bt
== btNil
|| tir
.bt
== btVoid
)
1097 type_code
= TYPE_CODE_ENUM
;
1100 if (tsym
->value
> max_value
)
1101 max_value
= tsym
->value
;
1103 else if (tsym
->st
== stBlock
1104 || tsym
->st
== stParsed
) {
1105 if (tsym
->sc
== scVariant
) ; /*UNIMPLEMENTED*/
1106 if (tsym
->index
!= 0)
1107 tsym
= ((SYMR
*)cur_fdr
->isymBase
)
1111 /* There is no guaranteed way to distinguish struct,
1112 unions, and enums at this point. This is a bug in the
1113 original design (that has been fixed with the
1114 recent addition of the stStruct, stUnion, and stEnum
1115 symbol types.) The way you can tell is if/when you
1116 see a variable or field of that type: In that case
1117 the variable's type (in the AUX table) says if the
1118 type is struct, union, or enum,
1119 and points back to the stBlock here.
1120 So you can patch the tag kind up later - but only
1121 if there actually is a variable or field of that type.
1123 So until we know for sure, we will guess at this point.
1125 If the first member has index==indexNil or a void type,
1126 assume we have an enumeration.
1127 Otherwise, if there is more than one member, and all
1128 the members have offset 0, assume we have a union.
1129 Otherwise, assume we have a struct.
1131 The heuristic could guess wrong in the case of
1132 of an enumeration with no members or a union
1133 with one (or zero) members, or when all except the
1134 last field of a struct have width zero.
1135 These are uncommon and/or illegal situations, and
1136 in any case guessing wrong probably doesn't matter much.
1138 But if we later do find out we were wrong,
1139 we fixup the tag kind. Members of an enumeration
1140 must be handled differently from struct/union fields,
1141 and that is harder to patch up, but luckily we
1142 shouldn't need to. (If there are any enumeration
1143 members, we can tell for sure it's an enum here.) */
1145 if (type_code
== TYPE_CODE_UNDEF
)
1146 if (nfields
> 1 && max_value
== 0)
1147 type_code
= TYPE_CODE_UNION
;
1149 type_code
= TYPE_CODE_STRUCT
;
1151 /* If this type was expected, use its partial definition */
1153 t
= is_pending_symbol(cur_fdr
, sh
)->t
;
1155 t
= new_type(prepend_tag_kind(sh
->iss
, type_code
));
1157 TYPE_CODE(t
) = type_code
;
1158 TYPE_LENGTH(t
) = sh
->value
;
1159 TYPE_NFIELDS(t
) = nfields
;
1160 TYPE_FIELDS(t
) = f
= (struct field
*)
1161 obstack_alloc (¤t_objfile
-> type_obstack
,
1162 nfields
* sizeof (struct field
));
1164 if (type_code
== TYPE_CODE_ENUM
) {
1165 /* This is a non-empty enum. */
1166 for (tsym
= sh
+ 1; tsym
->st
== stMember
; tsym
++) {
1167 struct symbol
*enum_sym
;
1168 f
->bitpos
= tsym
->value
;
1170 f
->name
= (char*)tsym
->iss
;
1173 enum_sym
= (struct symbol
*)
1174 obstack_alloc (¤t_objfile
->symbol_obstack
,
1175 sizeof (struct symbol
));
1176 memset (enum_sym
, 0, sizeof (struct symbol
));
1177 SYMBOL_NAME (enum_sym
) = f
->name
;
1178 SYMBOL_CLASS (enum_sym
) = LOC_CONST
;
1179 SYMBOL_TYPE (enum_sym
) = t
;
1180 SYMBOL_NAMESPACE (enum_sym
) = VAR_NAMESPACE
;
1181 SYMBOL_VALUE (enum_sym
) = tsym
->value
;
1182 add_symbol(enum_sym
, top_stack
->cur_block
);
1184 /* Skip the stMembers that we've handled. */
1190 /* make this the current type */
1191 top_stack
->cur_type
= t
;
1192 top_stack
->cur_field
= 0;
1193 /* Mark that symbol has a type, and say which one */
1194 sh
->value
= (long) t
;
1196 /* beginnning of (code) block. Value of symbol
1197 is the displacement from procedure start */
1198 b
= new_block(top_stack
->maxsyms
);
1199 BLOCK_START(b
) = sh
->value
+ top_stack
->procadr
;
1200 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1201 top_stack
->cur_block
= b
;
1202 add_block(b
, top_stack
->cur_st
);
1206 case stEnd
: /* end (of anything) */
1207 if (sh
->sc
== scInfo
) {
1208 /* Finished with type */
1209 top_stack
->cur_type
= 0;
1210 } else if (sh
->sc
== scText
&&
1211 (top_stack
->blocktype
== stProc
||
1212 top_stack
->blocktype
== stStaticProc
)) {
1213 /* Finished with procedure */
1214 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
1218 BLOCK_END(top_stack
->cur_block
) += sh
->value
; /* size */
1219 got_numargs(top_stack
->procadr
, top_stack
->numargs
);
1220 /* Reallocate symbols, saving memory */
1221 b
= shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1223 /* f77 emits proc-level with address bounds==[0,0],
1224 So look for such child blocks, and patch them. */
1225 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++) {
1226 struct block
*b_bad
= BLOCKVECTOR_BLOCK(bv
,i
);
1227 if (BLOCK_SUPERBLOCK(b_bad
) == b
1228 && BLOCK_START(b_bad
) == top_stack
->procadr
1229 && BLOCK_END(b_bad
) == top_stack
->procadr
) {
1230 BLOCK_START(b_bad
) = BLOCK_START(b
);
1231 BLOCK_END(b_bad
) = BLOCK_END(b
);
1234 } else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
) {
1235 /* End of (code) block. The value of the symbol
1236 is the displacement from the procedure`s start
1237 address of the end of this block. */
1238 BLOCK_END(top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1239 (void) shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1241 pop_parse_stack(); /* restore previous lexical context */
1244 case stMember
: /* member of struct or union */
1245 f
= &TYPE_FIELDS(top_stack
->cur_type
)[top_stack
->cur_field
++];
1246 f
->name
= (char*)sh
->iss
;
1247 f
->bitpos
= sh
->value
;
1249 f
->type
= parse_type(ax
+ sh
->index
, &f
->bitsize
, bigend
);
1252 case stTypedef
: /* type definition */
1253 s
= new_symbol(sh
->iss
);
1254 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1255 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1256 SYMBOL_BLOCK_VALUE(s
) = top_stack
->cur_block
;
1257 add_symbol(s
, top_stack
->cur_block
);
1258 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, 0, bigend
);
1259 sh
->value
= (long) SYMBOL_TYPE(s
);
1262 case stFile
: /* file name */
1264 top_stack
->blocktype
= sh
->st
;
1267 /* I`ve never seen these for C */
1269 break; /* register relocation */
1271 break; /* forwarding address */
1273 break; /* constant */
1275 error("Unknown symbol type %x.", sh
->st
);
1281 /* Parse the type information provided in the raw AX entries for
1282 the symbol SH. Return the bitfield size in BS, in case.
1283 We must byte-swap the AX entries before we use them; BIGEND says whether
1284 they are big-endian or little-endian (from fh->fBigendian). */
1286 static struct type
*parse_type(ax
, bs
, bigend
)
1291 /* Null entries in this map are treated specially */
1292 static struct type
**map_bt
[] =
1294 &builtin_type_void
, /* btNil */
1296 &builtin_type_char
, /* btChar */
1297 &builtin_type_unsigned_char
, /* btUChar */
1298 &builtin_type_short
, /* btShort */
1299 &builtin_type_unsigned_short
, /* btUShort */
1300 &builtin_type_int
, /* btInt */
1301 &builtin_type_unsigned_int
, /* btUInt */
1302 &builtin_type_long
, /* btLong */
1303 &builtin_type_unsigned_long
, /* btULong */
1304 &builtin_type_float
, /* btFloat */
1305 &builtin_type_double
, /* btDouble */
1312 &builtin_type_complex
, /* btComplex */
1313 &builtin_type_double_complex
, /* btDComplex */
1315 &builtin_type_fixed_dec
, /* btFixedDec */
1316 &builtin_type_float_dec
, /* btFloatDec */
1317 &builtin_type_string
, /* btString */
1320 &builtin_type_void
, /* btVoid */
1324 struct type
*tp
= 0;
1330 /* Use aux as a type information record, map its basic type. */
1332 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1333 if (t
->bt
> (sizeof (map_bt
)/sizeof (*map_bt
))) {
1334 complain (&basic_type_complaint
, t
->bt
);
1335 return builtin_type_int
;
1337 if (map_bt
[t
->bt
]) {
1338 tp
= *map_bt
[t
->bt
];
1342 /* Cannot use builtin types -- build our own */
1345 tp
= lookup_pointer_type (builtin_type_void
);
1349 type_code
= TYPE_CODE_STRUCT
;
1353 type_code
= TYPE_CODE_UNION
;
1357 type_code
= TYPE_CODE_ENUM
;
1361 type_code
= TYPE_CODE_RANGE
;
1365 type_code
= TYPE_CODE_SET
;
1370 complain (&basic_type_complaint
, t
->bt
);
1371 return builtin_type_int
;
1375 /* Skip over any further type qualifiers (FIXME). */
1377 /* This is the way it would work if the compiler worked */
1381 ecoff_swap_tir_in (bigend
, ax
, t1
);
1382 } while (t1
->continued
);
1385 /* Move on to next aux */
1389 *bs
= AUX_GET_WIDTH (bigend
, ax
);
1393 /* All these types really point to some (common) MIPS type
1394 definition, and only the type-qualifiers fully identify
1395 them. We'll make the same effort at sharing. */
1396 if (t
->bt
== btIndirect
||
1397 t
->bt
== btStruct
||
1400 t
->bt
== btTypedef
||
1403 char name
[256], *pn
;
1405 /* Try to cross reference this type */
1406 ax
+= cross_ref(ax
, &tp
, type_code
, &pn
, bigend
);
1407 /* reading .o file ? */
1408 if (UNSAFE_DATA_ADDR(tp
))
1409 tp
= init_type(type_code
, 0, 0, 0, (struct objfile
*) NULL
);
1410 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1411 sprintf(name
, fmt
, pn
);
1413 /* Usually, TYPE_CODE(tp) is already type_code. The main
1414 exception is if we guessed wrong re struct/union/enum. */
1415 if (TYPE_CODE(tp
) != type_code
) {
1416 complain (&bad_tag_guess_complaint
, 0);
1417 TYPE_CODE(tp
) = type_code
;
1419 if (TYPE_NAME(tp
) == NULL
|| strcmp(TYPE_NAME(tp
), name
) != 0)
1420 TYPE_NAME(tp
) = obsavestring(name
, strlen(name
),
1421 ¤t_objfile
-> type_obstack
);
1424 /* Deal with range types */
1425 if (t
->bt
== btRange
) {
1428 TYPE_NFIELDS (tp
) = 2;
1430 (struct field
*) obstack_alloc (¤t_objfile
-> type_obstack
,
1431 2 * sizeof (struct field
));
1432 TYPE_FIELD_NAME (tp
, 0) = obsavestring ("Low", strlen ("Low"),
1433 ¤t_objfile
-> type_obstack
);
1434 TYPE_FIELD_BITPOS (tp
, 0) = AUX_GET_DNLOW (bigend
, ax
);
1436 TYPE_FIELD_NAME (tp
, 1) = obsavestring ("High", strlen ("High"),
1437 ¤t_objfile
-> type_obstack
);
1438 TYPE_FIELD_BITPOS (tp
, 1) = AUX_GET_DNHIGH (bigend
, ax
);
1442 /* Parse all the type qualifiers now. If there are more
1443 than 6 the game will continue in the next aux */
1445 #define PARSE_TQ(tq) \
1446 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, bigend);
1448 again
: PARSE_TQ(tq0
);
1458 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1464 /* Make up a complex type from a basic one. Type is passed by
1465 reference in TPP and side-effected as necessary. The type
1466 qualifier TQ says how to handle the aux symbols at AX for
1467 the symbol SX we are currently analyzing. BIGEND says whether
1468 aux symbols are big-endian or little-endian.
1469 Returns the number of aux symbols we parsed. */
1472 upgrade_type(tpp
, tq
, ax
, bigend
)
1480 /* Used in array processing */
1489 t
= lookup_pointer_type (*tpp
);
1494 t
= lookup_function_type (*tpp
);
1500 t
= init_type(TYPE_CODE_ARRAY
, 0, 0, 0, (struct objfile
*) NULL
);
1501 TYPE_TARGET_TYPE(t
) = *tpp
;
1503 /* Determine and record the domain type (type of index) */
1504 ecoff_swap_rndx_in (bigend
, ax
, &rndx
);
1509 rf
= AUX_GET_ISYM (bigend
, ax
);
1512 fh
= get_rfd(cur_fd
, rf
);
1514 /* Fields are kept in an array */
1515 /* FIXME - Memory leak! */
1516 if (TYPE_NFIELDS(t
))
1517 TYPE_FIELDS(t
) = (struct field
*)
1518 xrealloc((char *) TYPE_FIELDS(t
),
1519 (TYPE_NFIELDS(t
)+1) * sizeof(struct field
));
1521 TYPE_FIELDS(t
) = (struct field
*)
1522 xzalloc(sizeof(struct field
));
1523 f
= &(TYPE_FIELD(t
,TYPE_NFIELDS(t
)));
1525 memset(f
, 0, sizeof(struct field
));
1527 /* XXX */ f
->type
= parse_type(fh
->iauxBase
+ id
* sizeof(union aux_ext
),
1528 &f
->bitsize
, bigend
);
1531 lower
= AUX_GET_DNLOW (bigend
, ax
);
1533 upper
= AUX_GET_DNHIGH (bigend
, ax
);
1535 rf
= AUX_GET_WIDTH (bigend
, ax
); /* bit size of array element */
1537 /* Check whether supplied array element bit size matches
1538 the known size of the element type. If this complaint
1539 ends up not happening, we can remove this code. It's
1540 here because we aren't sure we understand this *&%&$
1542 id
= TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) << 3; /* bitsize */
1544 /* Most likely an undefined type */
1546 TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) = id
>> 3;
1549 complain (&array_bitsize_complaint
, rf
);
1551 TYPE_LENGTH(t
) = (upper
< 0) ? 0 :
1552 (upper
- lower
+ 1) * (rf
>> 3);
1557 /* Volatile -- currently ignored */
1561 complain (&unknown_type_qual_complaint
, tq
);
1567 /* Parse a procedure descriptor record PR. Note that the procedure
1568 is parsed _after_ the local symbols, now we just make up the
1569 extra information we need into a special symbol that we insert
1570 in the procedure's main block. Note also that images that
1571 have been partially stripped (ld -x) have been deprived
1572 of local symbols, and we have to cope with them here.
1573 The procedure's code ends at BOUND */
1576 parse_procedure(pr
, bound
)
1579 struct symbol
*s
, *i
;
1580 SYMR
*sh
= (SYMR
*)pr
->isym
;
1582 struct mips_extra_func_info
*e
;
1586 /* Reuse the MIPS record */
1587 e
= (struct mips_extra_func_info
*) pr
;
1588 e
->numargs
= lookup_numargs(pr
->adr
);
1590 /* Make up our special symbol */
1591 i
= new_symbol(".gdbinfo.");
1592 SYMBOL_VALUE(i
) = (int)e
;
1593 SYMBOL_NAMESPACE(i
) = LABEL_NAMESPACE
;
1594 SYMBOL_CLASS(i
) = LOC_CONST
;
1595 SYMBOL_TYPE(i
) = builtin_type_void
;
1597 /* Make up a name for static procedures. Sigh. */
1598 if (sh
== (SYMR
*)-1) {
1599 sprintf(name
,".static_procedure@%x",pr
->adr
);
1600 sh_name
= savestring(name
, strlen(name
));
1604 sh_name
= (char*)sh
->iss
;
1605 s
= mylookup_symbol(sh_name
, top_stack
->cur_block
,
1606 VAR_NAMESPACE
, LOC_BLOCK
);
1609 b
= SYMBOL_BLOCK_VALUE(s
);
1611 s
= new_symbol(sh_name
);
1612 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1613 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1614 /* Donno its type, hope int is ok */
1615 SYMBOL_TYPE(s
) = lookup_function_type (builtin_type_int
);
1616 add_symbol(s
, top_stack
->cur_block
);
1617 /* Wont have symbols for this one */
1619 SYMBOL_BLOCK_VALUE(s
) = b
;
1620 BLOCK_FUNCTION(b
) = s
;
1621 BLOCK_START(b
) = pr
->adr
;
1622 BLOCK_END(b
) = bound
;
1623 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1624 add_block(b
, top_stack
->cur_st
);
1630 /* Parse the external symbol ES. Just call parse_symbol() after
1631 making sure we know where the aux are for it. For procedures,
1632 parsing of the PDRs has already provided all the needed
1633 information, we only parse them if SKIP_PROCEDURES is false,
1634 and only if this causes no symbol duplication.
1635 BIGEND says whether aux entries are big-endian or little-endian.
1637 This routine clobbers top_stack->cur_block and ->cur_st. */
1640 parse_external(es
, skip_procedures
, bigend
)
1642 int skip_procedures
;
1647 if (es
->ifd
!= ifdNil
) {
1649 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
) + cur_fd
;
1650 ax
= (union aux_ext
*)cur_fdr
->iauxBase
;
1652 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
);
1655 top_stack
->cur_st
= cur_stab
;
1656 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
1659 /* Reading .o files */
1660 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
) {
1662 switch (es
->asym
.st
) {
1664 case stProc
: what
= "procedure"; n_undef_procs
++; break;
1665 case stGlobal
: what
= "variable"; n_undef_vars
++; break;
1666 case stLabel
: what
= "label"; n_undef_labels
++; break;
1667 default : what
= "symbol"; break;
1671 printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what
,
1672 es
->asym
.iss
, fdr_name(cur_fdr
->rss
));
1676 switch (es
->asym
.st
) {
1678 /* If we have full symbols we do not need more */
1679 if (skip_procedures
)
1681 if (mylookup_symbol (es
->asym
.iss
, top_stack
->cur_block
,
1682 VAR_NAMESPACE
, LOC_BLOCK
))
1688 * Note that the case of a symbol with indexNil
1689 * must be handled anyways by parse_symbol().
1691 parse_symbol(&es
->asym
, ax
, bigend
);
1698 /* Parse the line number info for file descriptor FH into
1699 GDB's linetable LT. MIPS' encoding requires a little bit
1700 of magic to get things out. Note also that MIPS' line
1701 numbers can go back and forth, apparently we can live
1702 with that and do not need to reorder our linetables */
1707 struct linetable
*lt
;
1709 unsigned char *base
= (unsigned char*)fh
->cbLineOffset
;
1711 int delta
, count
, lineno
= 0;
1717 /* Scan by procedure descriptors */
1718 i
= 0; j
= 0, k
= 0;
1719 for (pr
= (PDR
*)IPDFIRST(cur_hdr
,fh
); j
< fh
->cpd
; j
++, pr
++) {
1722 /* No code for this one */
1723 if (pr
->iline
== ilineNil
||
1724 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1727 * Aurgh! To know where to stop expanding we
1730 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1731 if (pr
[l
].iline
!= -1)
1733 if (l
== (fh
->cpd
- j
))
1738 * When procedures are moved around the linenumbers
1739 * are attributed to the next procedure up
1741 if (pr
->iline
>= halt
) continue;
1743 base
= (unsigned char*)pr
->cbLineOffset
;
1744 l
= pr
->adr
>> 2; /* in words */
1745 halt
+= (pr
->adr
>> 2) - pr
->iline
;
1746 for (lineno
= pr
->lnLow
; l
< halt
;) {
1747 count
= *base
& 0x0f;
1748 delta
= *base
++ >> 4;
1752 delta
= (base
[0] << 8) | base
[1];
1753 if (delta
>= 0x8000)
1757 lineno
+= delta
;/* first delta is 0 */
1758 k
= add_line(lt
, lineno
, l
, k
);
1765 /* Master parsing procedure for first-pass reading of file symbols
1766 into a partial_symtab.
1768 Parses the symtab described by the global symbolic header CUR_HDR.
1769 END_OF_TEXT_SEG gives the address just after the text segment for
1770 the symtab we are reading. */
1773 parse_partial_symbols(end_of_text_seg
, objfile
)
1774 int end_of_text_seg
;
1775 struct objfile
*objfile
;
1778 /* int stat_idx, h_max;*/
1779 HDRR
*hdr
= cur_hdr
;
1780 /* Running pointers */
1785 struct partial_symtab
*pst
;
1787 int past_first_source_file
= 0;
1789 /* List of current psymtab's include files */
1790 char **psymtab_include_list
;
1791 int includes_allocated
;
1794 struct pst_map
* fdr_to_pst
;
1795 /* Index within current psymtab dependency list */
1796 struct partial_symtab
**dependency_list
;
1797 int dependencies_used
, dependencies_allocated
;
1798 struct cleanup
*old_chain
;
1800 extern_tab
= (EXTR
**)obstack_alloc (&objfile
->psymbol_obstack
,
1801 sizeof(EXTR
*) * hdr
->iextMax
);
1803 includes_allocated
= 30;
1805 psymtab_include_list
= (char **) alloca (includes_allocated
*
1807 next_symbol_text_func
= mips_next_symbol_text
;
1809 dependencies_allocated
= 30;
1810 dependencies_used
= 0;
1812 (struct partial_symtab
**) alloca (dependencies_allocated
*
1813 sizeof (struct partial_symtab
*));
1815 last_source_file
= 0;
1820 * Only parse the Local and External symbols, and the Relative FDR.
1821 * Fixup enough of the loader symtab to be able to use it.
1822 * Allocate space only for the file's portions we need to
1827 max_glevel
= MIN_GLEVEL
;
1829 /* Allocate the map FDR -> PST.
1830 Minor hack: -O3 images might claim some global data belongs
1831 to FDR -1. We`ll go along with that */
1832 fdr_to_pst
= (struct pst_map
*)xzalloc((hdr
->ifdMax
+1) * sizeof *fdr_to_pst
);
1833 old_chain
= make_cleanup (free
, fdr_to_pst
);
1836 struct partial_symtab
* pst
= new_psymtab("", objfile
);
1837 fdr_to_pst
[-1].pst
= pst
;
1841 /* Pass 1 over external syms: Presize and partition the list */
1842 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1843 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1844 fdr_to_pst
[esh
->ifd
].n_globals
++;
1847 /* Pass 1.5 over files: partition out global symbol space */
1849 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++) {
1850 fdr_to_pst
[f_idx
].globals_offset
= s_idx
;
1851 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
1852 fdr_to_pst
[f_idx
].n_globals
= 0;
1855 /* Pass 2 over external syms: fill in external symbols */
1856 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1857 enum minimal_symbol_type ms_type
= mst_text
;
1858 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1860 extern_tab
[fdr_to_pst
[esh
->ifd
].globals_offset
1861 + fdr_to_pst
[esh
->ifd
].n_globals
++] = esh
;
1863 if (esh
->asym
.sc
== scUndefined
|| esh
->asym
.sc
== scNil
)
1866 switch (esh
->asym
.st
) {
1875 ms_type
= mst_unknown
;
1876 complain (&unknown_ext_complaint
,
1877 (char *)(esh
->asym
.iss
));
1879 prim_record_minimal_symbol ((char *)(esh
->asym
.iss
),
1884 /* Pass 3 over files, over local syms: fill in static symbols */
1885 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
1886 struct partial_symtab
*save_pst
;
1888 cur_fdr
= fh
= f_idx
+ (FDR
*)(cur_hdr
->cbFdOffset
);
1890 if (fh
->csym
== 0) {
1891 fdr_to_pst
[f_idx
].pst
= NULL
;
1894 pst
= start_psymtab_common (objfile
, 0, (char*)fh
->rss
,
1895 fh
->cpd
? fh
->adr
: 0,
1896 objfile
->global_psymbols
.next
,
1897 objfile
->static_psymbols
.next
);
1898 pst
->read_symtab_private
= (char *)
1899 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
1902 /* Make everything point to everything. */
1903 FDR_IDX(pst
) = f_idx
;
1904 fdr_to_pst
[f_idx
].pst
= pst
;
1905 fh
->ioptBase
= (int)pst
;
1907 CUR_HDR(pst
) = cur_hdr
;
1909 /* The way to turn this into a symtab is to call... */
1910 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
1912 pst
->texthigh
= pst
->textlow
;
1914 #if 0 /* This is done in start_psymtab_common */
1915 pst
->globals_offset
= global_psymbols
.next
- global_psymbols
.list
;
1916 pst
->statics_offset
= static_psymbols
.next
- static_psymbols
.list
;
1918 pst
->n_global_syms
= 0;
1919 pst
->n_static_syms
= 0;
1922 /* The second symbol must be @stab.
1923 This symbol is emitted by mips-tfile to signal
1924 that the current object file uses encapsulated stabs
1925 instead of mips ecoff for local symbols.
1926 (It is the second symbol because the first symbol is
1927 the stFile used to signal the start of a file). */
1929 && strcmp((char *)(((SYMR
*)fh
->isymBase
)[1].iss
),
1930 stabs_symbol
) == 0) {
1931 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++) {
1934 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
1935 type_code
= MIPS_UNMARK_STAB(sh
->index
);
1936 if (!MIPS_IS_STAB(sh
)) {
1937 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
) {
1938 long procaddr
= sh
->value
;
1939 sh
= AUX_GET_ISYM (fh
->fBigendian
,
1940 sh
->index
+ (union aux_ext
*)(fh
->iauxBase
))
1941 + (SYMR
*) fh
->isymBase
- 1;
1942 if (sh
->st
== stEnd
) {
1943 long high
= procaddr
+ sh
->value
;
1944 if (high
> pst
->texthigh
)
1945 pst
->texthigh
= high
;
1950 #define SET_NAMESTRING() namestring = (char*)sh->iss
1951 #define CUR_SYMBOL_TYPE type_code
1952 #define CUR_SYMBOL_VALUE sh->value
1953 #define START_PSYMTAB(ofile,addr,fname,low,symoff,global_syms,static_syms)\
1955 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
1956 #define addr 0 /* FIXME, should be offset of addresses */
1957 #define HANDLE_RBRAC(val) \
1958 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
1959 #include "partial-stab.h"
1964 register struct partial_symbol
*psym
;
1965 for (cur_sdx
= 0; cur_sdx
< fh
->csym
; ) {
1968 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
1970 if (MIPS_IS_STAB(sh
)) {
1975 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
1976 sh
->index
== 0xfffff) {
1977 /* FIXME, premature? */
1982 name
= (char *)(sh
->iss
);
1987 case stProc
: /* Asm labels apparently */
1988 case stStaticProc
: /* Function */
1989 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
1990 VAR_NAMESPACE
, LOC_BLOCK
,
1991 objfile
->static_psymbols
, sh
->value
);
1992 /* Skip over procedure to next one. */
1993 cur_sdx
= AUX_GET_ISYM (fh
->fBigendian
,
1994 sh
->index
+ (union aux_ext
*)fh
->iauxBase
);
1995 procaddr
= sh
->value
;
1997 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
- 1;
1998 if (sh
->st
!= stEnd
)
2000 high
= procaddr
+ sh
->value
;
2001 if (high
> pst
->texthigh
)
2002 pst
->texthigh
= high
;
2004 case stStatic
: /* Variable */
2007 case stTypedef
: /* Typedef */
2008 class = LOC_TYPEDEF
;
2010 case stConstant
: /* Constant decl */
2013 case stBlock
: /* { }, str, un, enum*/
2014 if (sh
->sc
== scInfo
) {
2015 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
2016 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2017 objfile
->static_psymbols
, sh
->value
);
2019 /* Skip over the block */
2020 cur_sdx
= sh
->index
;
2022 case stFile
: /* File headers */
2023 case stLabel
: /* Labels */
2024 case stEnd
: /* Ends of files */
2027 /* Both complaints are valid: one gives symbol name,
2028 the other the offending symbol type. */
2029 complain (&unknown_sym_complaint
, (char *)sh
->iss
);
2030 complain (&unknown_st_complaint
, sh
->st
);
2034 /* Use this gdb symbol */
2035 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
2036 VAR_NAMESPACE
, class,
2037 objfile
->static_psymbols
, sh
->value
);
2039 cur_sdx
++; /* Go to next file symbol */
2042 /* Now do enter the external symbols. */
2043 ext_ptr
= &extern_tab
[fdr_to_pst
[f_idx
].globals_offset
];
2044 cur_sdx
= fdr_to_pst
[f_idx
].n_globals
;
2045 PST_PRIVATE(save_pst
)->extern_count
= cur_sdx
;
2046 PST_PRIVATE(save_pst
)->extern_tab
= ext_ptr
;
2047 for (; --cur_sdx
>= 0; ext_ptr
++) {
2048 enum address_class
class;
2049 if ((*ext_ptr
)->ifd
!= f_idx
)
2051 sh
= &(*ext_ptr
)->asym
;
2060 complain (&unknown_ext_complaint
, sh
->iss
);
2065 if (objfile
->global_psymbols
.next
>=
2066 objfile
->global_psymbols
.list
+ objfile
->global_psymbols
.size
)
2067 extend_psymbol_list (&objfile
->global_psymbols
, objfile
);
2068 psym
= objfile
->global_psymbols
.next
++;
2069 SYMBOL_NAME (psym
) = (char*)sh
->iss
;
2070 SYMBOL_NAMESPACE (psym
) = VAR_NAMESPACE
;
2071 SYMBOL_CLASS (psym
) = class;
2072 SYMBOL_VALUE_ADDRESS (psym
) = (CORE_ADDR
)sh
->value
;
2076 end_psymtab (save_pst
, psymtab_include_list
, includes_used
,
2077 -1, save_pst
->texthigh
,
2078 dependency_list
, dependencies_used
);
2079 if (entry_point
< save_pst
->texthigh
2080 && entry_point
>= save_pst
->textlow
) {
2081 startup_file_start
= save_pst
->textlow
;
2082 startup_file_end
= save_pst
->texthigh
;
2086 /* Mark the last code address, and remember it for later */
2087 hdr
->cbDnOffset
= end_of_text_seg
;
2089 /* Now scan the FDRs for dependencies */
2090 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
2092 fh
= f_idx
+ (FDR
*)(cur_hdr
->cbFdOffset
);
2093 pst
= fdr_to_pst
[f_idx
].pst
;
2095 /* This should catch stabs-in-ecoff. */
2099 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
2100 /* ...then presumably a .h file: drop reverse depends .h->.c */
2101 for (; s_id0
< fh
->crfd
; s_id0
++) {
2102 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
2104 s_id0
++; /* Skip self-dependency */
2109 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2110 pst
->dependencies
= (struct partial_symtab
**)
2111 obstack_alloc (&objfile
->psymbol_obstack
,
2112 pst
->number_of_dependencies
*
2113 sizeof (struct partial_symtab
*));
2114 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
2115 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
2116 if (*rh
< 0 || *rh
>= hdr
->ifdMax
)
2117 complain(&bad_file_number_complaint
, *rh
);
2119 pst
->dependencies
[s_idx
-s_id0
] = fdr_to_pst
[*rh
].pst
;
2122 do_cleanups (old_chain
);
2127 /* Do the initial analisys of the F_IDX-th file descriptor.
2128 Allocates a partial symtab for it, and builds the list
2129 of dependent files by recursion. LEV says at which level
2130 of recursion we are called (to pretty up debug traces) */
2132 static struct partial_symtab
*
2133 parse_fdr(f_idx
, lev
, objfile
)
2136 struct objfile
*objfile
;
2139 register struct partial_symtab
*pst
;
2142 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + f_idx
;
2144 /* Use this to indicate into which symtab this file was parsed */
2146 return (struct partial_symtab
*) fh
->ioptBase
;
2148 /* Debuggability level */
2149 if (compare_glevel(max_glevel
, fh
->glevel
) < 0)
2150 max_glevel
= fh
->glevel
;
2152 /* Make a new partial_symtab */
2153 pst
= new_psymtab(fh
->rss
, objfile
);
2158 pst
->textlow
= fh
->adr
;
2159 pst
->texthigh
= fh
->cpd
; /* To be fixed later */
2162 /* Make everything point to everything. */
2163 FDR_IDX(pst
) = f_idx
;
2164 fdr_to_pst
[f_idx
].pst
= pst
;
2165 fh
->ioptBase
= (int)pst
;
2167 /* Analyze its dependencies */
2172 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
2173 /* ...then presumably a .h file: drop reverse depends .h->.c */
2174 for (; s_id0
< fh
->crfd
; s_id0
++) {
2175 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
2177 s_id0
++; /* Skip self-dependency */
2182 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2183 pst
->dependencies
= (struct partial_symtab
**)
2184 obstack_alloc (&objfile
->psymbol_obstack
,
2185 pst
->number_of_dependencies
*
2186 sizeof (struct partial_symtab
*));
2187 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
2188 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
2190 pst
->dependencies
[s_idx
-s_id0
] = parse_fdr(*rh
, lev
+1, objfile
);
2198 mips_next_symbol_text ()
2201 return (char*)((SYMR
*)cur_fdr
->isymBase
)[cur_sdx
].iss
;
2204 /* Ancillary function to psymtab_to_symtab(). Does all the work
2205 for turning the partial symtab PST into a symtab, recurring
2206 first on all dependent psymtabs. The argument FILENAME is
2207 only passed so we can see in debug stack traces what file
2211 psymtab_to_symtab_1(pst
, filename
)
2212 struct partial_symtab
*pst
;
2220 struct linetable
*lines
;
2226 /* How many symbols will we need */
2227 /* FIXME, this does not count enum values. */
2228 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
2229 if (FDR_IDX(pst
) == -1) {
2233 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + FDR_IDX(pst
);
2234 f_max
+= fh
->csym
+ fh
->cpd
;
2235 maxlines
= 2 * fh
->cline
;
2238 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2241 && strcmp((char *)(((SYMR
*)fh
->isymBase
)[1].iss
), stabs_symbol
)
2246 st
= new_symtab (pst
->filename
, 2 * f_max
, maxlines
,
2249 st
= new_symtab ("unknown", f_max
, 0, pst
->objfile
);
2250 lines
= LINETABLE(st
);
2251 pending_list
= (struct mips_pending
**) cur_hdr
->cbOptOffset
;
2252 if (pending_list
== 0) {
2253 pending_list
= (struct mips_pending
**)
2254 xzalloc(cur_hdr
->ifdMax
* sizeof(struct mips_pending
*));
2255 cur_hdr
->cbOptOffset
= (int)pending_list
;
2259 /* Read in all partial symbtabs on which this one is dependent.
2260 NOTE that we do have circular dependencies, sigh. We solved
2261 that by setting pst->readin before this point. */
2263 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2264 if (!pst
->dependencies
[i
]->readin
) {
2265 /* Inform about additional files to be read in. */
2268 fputs_filtered (" ", stdout
);
2270 fputs_filtered ("and ", stdout
);
2272 printf_filtered ("%s...",
2273 pst
->dependencies
[i
]->filename
);
2274 wrap_here (""); /* Flush output */
2277 /* We only pass the filename for debug purposes */
2278 psymtab_to_symtab_1(pst
->dependencies
[i
],
2279 pst
->dependencies
[i
]->filename
);
2283 /* Now read the symbols for this symtab */
2285 current_objfile
= pst
-> objfile
;
2287 cur_fd
= FDR_IDX(pst
);
2290 /* Get a new lexical context */
2293 top_stack
->cur_st
= cur_stab
;
2294 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab
),
2296 BLOCK_START(top_stack
->cur_block
) = fh
? fh
->adr
: 0;
2297 BLOCK_END(top_stack
->cur_block
) = 0;
2298 top_stack
->blocktype
= stFile
;
2299 top_stack
->maxsyms
= 2*f_max
;
2300 top_stack
->cur_type
= 0;
2301 top_stack
->procadr
= 0;
2302 top_stack
->numargs
= 0;
2305 /* Parse locals and procedures */
2310 char *fh_name
= (char*)fh
->rss
;
2312 /* Parse local symbols first */
2318 current_objfile
= NULL
;
2321 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++) {
2322 register SYMR
*sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
2323 char *name
= (char*)sh
->iss
;
2324 CORE_ADDR valu
= sh
->value
;
2325 if (MIPS_IS_STAB(sh
)) {
2326 int type_code
= MIPS_UNMARK_STAB(sh
->index
);
2327 process_one_symbol (type_code
, 0, valu
, name
, /*FIXME*/ 0);
2329 else if (sh
->st
== stLabel
&& sh
->index
!= indexNil
) {
2330 /* Handle encoded stab line number. */
2331 record_line (current_subfile
, sh
->index
, valu
);
2334 st
= end_symtab (pst
->texthigh
, 0, 0, pst
->objfile
);
2337 /* BOUND is the highest core address of this file's procedures */
2338 int bound
= cur_fd
== cur_hdr
->ifdMax
- 1 ? cur_hdr
->cbDnOffset
2340 for (cur_sdx
= 0; cur_sdx
< fh
->csym
; ) {
2341 sh
= (SYMR
*) (fh
->isymBase
) + cur_sdx
;
2342 cur_sdx
+= parse_symbol(sh
, fh
->iauxBase
, fh
->fBigendian
);
2345 /* Procedures next, note we need to look-ahead to
2346 find out where the procedure's code ends */
2349 for (i
= 0; i
< fh
->cpd
-1; i
++) {
2350 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2351 parse_procedure(pr
, pr
[1].adr
); /* next proc up */
2354 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2355 parse_procedure(pr
, bound
); /* next file up */
2357 /* Linenumbers. At the end, check if we can save memory */
2358 parse_lines(fh
, lines
);
2359 if (lines
->nitems
< fh
->cline
)
2360 lines
= shrink_linetable(lines
);
2366 LINETABLE(st
) = lines
;
2368 /* .. and our share of externals.
2369 XXX use the global list to speed up things here. how ?
2370 FIXME, Maybe quit once we have found the right number of ext's? */
2371 /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
2372 top_stack
->blocktype
= stFile
;
2373 top_stack
->maxsyms
=
2374 cur_hdr
->isymMax
+ cur_hdr
->ipdMax
+ cur_hdr
->iextMax
;
2376 ext_ptr
= PST_PRIVATE(pst
)->extern_tab
;
2377 for (i
= PST_PRIVATE(pst
)->extern_count
; --i
>= 0; ext_ptr
++)
2378 parse_external(*ext_ptr
, 1, fh
->fBigendian
);
2380 /* If there are undefined, tell the user */
2381 if (n_undef_symbols
) {
2382 printf_filtered("File %s contains %d unresolved references:",
2383 st
->filename
, n_undef_symbols
);
2384 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2385 n_undef_vars
, n_undef_procs
, n_undef_labels
);
2386 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
2392 /* Sort the symbol table now, we are done adding symbols to it.*/
2393 sort_symtab_syms(st
);
2397 /* Now link the psymtab and the symtab. */
2400 current_objfile
= NULL
;
2403 /* Ancillary parsing procedures. */
2405 /* Lookup the type at relative index RN. Return it in TPP
2406 if found and in any event come up with its name PNAME.
2407 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
2408 Return value says how many aux symbols we ate. */
2411 cross_ref(ax
, tpp
, type_code
, pname
, bigend
)
2414 int type_code
; /* Use to alloc new type if none is found. */
2422 ecoff_swap_rndx_in (bigend
, ax
, rn
);
2424 /* Escape index means 'the next one' */
2425 if (rn
->rfd
== 0xfff) {
2427 rf
= AUX_GET_ISYM (bigend
, ax
+ 1);
2434 *pname
= "<undefined>";
2437 * Find the relative file descriptor and the symbol in it
2439 FDR
*fh
= get_rfd(cur_fd
, rf
);
2444 * If we have processed this symbol then we left a forwarding
2445 * pointer to the corresponding GDB symbol. If not, we`ll put
2446 * it in a list of pending symbols, to be processed later when
2447 * the file f will be. In any event, we collect the name for
2448 * the type here. Which is why we made a first pass at
2451 sh
= (SYMR
*) (fh
->isymBase
) + rn
->index
;
2453 /* Careful, we might be looking at .o files */
2454 *pname
= (UNSAFE_DATA_ADDR(sh
->iss
)) ? "<undefined>" :
2457 /* Have we parsed it ? */
2458 if ((!UNSAFE_DATA_ADDR(sh
->value
)) && (sh
->st
== stParsed
)) {
2459 t
= (struct type
*) sh
->value
;
2462 /* Avoid duplicates */
2463 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
2467 *tpp
= init_type(type_code
, 0, 0, 0, (struct objfile
*) NULL
);
2468 add_pending(fh
, sh
, *tpp
);
2473 /* We used one auxent normally, two if we got a "next one" rf. */
2478 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2479 keeping the symtab sorted */
2481 static struct symbol
*
2482 mylookup_symbol (name
, block
, namespace, class)
2484 register struct block
*block
;
2485 enum namespace namespace;
2486 enum address_class
class;
2488 register int bot
, top
, inc
;
2489 register struct symbol
*sym
;
2492 top
= BLOCK_NSYMS(block
);
2495 sym
= BLOCK_SYM(block
, bot
);
2496 if (SYMBOL_NAME(sym
)[0] == inc
2497 && SYMBOL_NAMESPACE(sym
) == namespace
2498 && SYMBOL_CLASS(sym
) == class
2499 && !strcmp(SYMBOL_NAME(sym
), name
))
2503 if (block
= BLOCK_SUPERBLOCK (block
))
2504 return mylookup_symbol (name
, block
, namespace, class);
2509 /* Add a new symbol S to a block B.
2510 Infrequently, we will need to reallocate the block to make it bigger.
2511 We only detect this case when adding to top_stack->cur_block, since
2512 that's the only time we know how big the block is. FIXME. */
2519 int nsyms
= BLOCK_NSYMS(b
)++;
2520 struct block
*origb
;
2521 struct parse_stack
*stackp
;
2523 if (b
== top_stack
->cur_block
&&
2524 nsyms
>= top_stack
->maxsyms
) {
2525 complain (&block_overflow_complaint
, s
->name
);
2526 /* In this case shrink_block is actually grow_block, since
2527 BLOCK_NSYMS(b) is larger than its current size. */
2529 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
2531 /* Now run through the stack replacing pointers to the
2532 original block. shrink_block has already done this
2533 for the blockvector and BLOCK_FUNCTION. */
2534 for (stackp
= top_stack
; stackp
; stackp
= stackp
->next
) {
2535 if (stackp
->cur_block
== origb
) {
2536 stackp
->cur_block
= b
;
2537 stackp
->maxsyms
= BLOCK_NSYMS (b
);
2541 BLOCK_SYM(b
,nsyms
) = s
;
2544 /* Add a new block B to a symtab S */
2551 struct blockvector
*bv
= BLOCKVECTOR(s
);
2553 bv
= (struct blockvector
*)xrealloc((char *) bv
,
2554 sizeof(struct blockvector
) +
2555 BLOCKVECTOR_NBLOCKS(bv
)
2556 * sizeof(bv
->block
));
2557 if (bv
!= BLOCKVECTOR(s
))
2558 BLOCKVECTOR(s
) = bv
;
2560 BLOCKVECTOR_BLOCK(bv
, BLOCKVECTOR_NBLOCKS(bv
)++) = b
;
2563 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2564 MIPS' linenumber encoding might need more than one byte
2565 to describe it, LAST is used to detect these continuation lines */
2568 add_line(lt
, lineno
, adr
, last
)
2569 struct linetable
*lt
;
2575 last
= -2; /* make sure we record first line */
2577 if (last
== lineno
) /* skip continuation lines */
2580 lt
->item
[lt
->nitems
].line
= lineno
;
2581 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
2587 /* Comparison functions, used when sorting things */
2589 /* Symtabs must be ordered viz the code segments they cover */
2592 compare_symtabs( s1
, s2
)
2593 struct symtab
**s1
, **s2
;
2595 /* "most specific" first */
2597 register struct block
*b1
, *b2
;
2598 b1
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1
),GLOBAL_BLOCK
);
2599 b2
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2
),GLOBAL_BLOCK
);
2600 if (BLOCK_END(b1
) == BLOCK_END(b2
))
2601 return BLOCK_START(b1
) - BLOCK_START(b2
);
2602 return BLOCK_END(b1
) - BLOCK_END(b2
);
2606 /* Partial Symtabs, same */
2609 compare_psymtabs( s1
, s2
)
2610 struct partial_symtab
**s1
, **s2
;
2612 /* Perf twist: put the ones with no code at the end */
2614 register int a
= (*s1
)->textlow
;
2615 register int b
= (*s2
)->textlow
;
2624 /* Blocks with a smaller low bound should come first */
2626 static int compare_blocks(b1
,b2
)
2627 struct block
**b1
, **b2
;
2629 register int addr_diff
;
2631 addr_diff
= (BLOCK_START((*b1
))) - (BLOCK_START((*b2
)));
2633 return (BLOCK_END((*b1
))) - (BLOCK_END((*b2
)));
2638 /* Sorting and reordering procedures */
2640 /* Sort the blocks of a symtab S.
2641 Reorder the blocks in the blockvector by code-address,
2642 as required by some MI search routines */
2648 struct blockvector
*bv
= BLOCKVECTOR(s
);
2650 if (BLOCKVECTOR_NBLOCKS(bv
) <= 2) {
2652 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) == 0)
2653 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = 0;
2654 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) == 0)
2655 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) = 0;
2659 * This is very unfortunate: normally all functions are compiled in
2660 * the order they are found, but if the file is compiled -O3 things
2661 * are very different. It would be nice to find a reliable test
2662 * to detect -O3 images in advance.
2664 if (BLOCKVECTOR_NBLOCKS(bv
) > 3)
2665 qsort(&BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
),
2666 BLOCKVECTOR_NBLOCKS(bv
) - FIRST_LOCAL_BLOCK
,
2667 sizeof(struct block
*),
2671 register CORE_ADDR high
= 0;
2672 register int i
, j
= BLOCKVECTOR_NBLOCKS(bv
);
2674 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
2675 if (high
< BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
)))
2676 high
= BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
));
2677 BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = high
;
2680 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) =
2681 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
));
2683 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2684 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2685 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2686 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2690 /* Constructor/restructor/destructor procedures */
2692 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2693 MAXSYMS and linenumbers MAXLINES we'll put in it */
2697 new_symtab(name
, maxsyms
, maxlines
, objfile
)
2701 struct objfile
*objfile
;
2703 struct symtab
*s
= allocate_symtab (name
, objfile
);
2705 LINETABLE(s
) = new_linetable(maxlines
);
2707 /* All symtabs must have at least two blocks */
2708 BLOCKVECTOR(s
) = new_bvect(2);
2709 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
) = new_block(maxsyms
);
2710 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), STATIC_BLOCK
) = new_block(maxsyms
);
2711 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
),STATIC_BLOCK
)) =
2712 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
);
2714 s
->free_code
= free_linetable
;
2719 /* Allocate a new partial_symtab NAME */
2721 static struct partial_symtab
*
2722 new_psymtab(name
, objfile
)
2724 struct objfile
*objfile
;
2726 struct partial_symtab
*psymtab
;
2728 /* FIXME -- why (char *) -1 rather than NULL? */
2729 psymtab
= allocate_psymtab (name
== (char *) -1 ? "<no name>" : name
,
2732 /* Keep a backpointer to the file's symbols */
2734 psymtab
-> read_symtab_private
= (char *)
2735 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
2736 CUR_HDR(psymtab
) = cur_hdr
;
2738 /* The way to turn this into a symtab is to call... */
2739 psymtab
->read_symtab
= mipscoff_psymtab_to_symtab
;
2744 /* Allocate a linetable array of the given SIZE */
2746 static struct linetable
*
2749 struct linetable
*l
;
2751 size
= size
* sizeof(l
->item
) + sizeof(struct linetable
);
2752 l
= (struct linetable
*)xmalloc(size
);
2757 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2758 I am not so sure about the 3.4 ones */
2760 static struct linetable
*
2761 shrink_linetable(lt
)
2762 struct linetable
* lt
;
2764 struct linetable
*l
= new_linetable(lt
->nitems
);
2766 memcpy(l
, lt
, lt
->nitems
* sizeof(l
->item
) + sizeof(struct linetable
));
2771 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2774 struct blockvector
*
2777 struct blockvector
*bv
;
2780 size
= sizeof(struct blockvector
) + nblocks
* sizeof(struct block
*);
2781 bv
= (struct blockvector
*) xzalloc(size
);
2783 BLOCKVECTOR_NBLOCKS(bv
) = nblocks
;
2788 /* Allocate and zero a new block of MAXSYMS symbols */
2794 int size
= sizeof(struct block
) + (maxsyms
-1) * sizeof(struct symbol
*);
2795 struct block
*b
= (struct block
*)xzalloc(size
);
2800 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2801 Shrink_block can also be used by add_symbol to grow a block. */
2803 static struct block
*
2809 struct blockvector
*bv
= BLOCKVECTOR(s
);
2812 /* Just reallocate it and fix references to the old one */
2814 new = (struct block
*) xrealloc ((char *)b
, sizeof(struct block
) +
2815 (BLOCK_NSYMS(b
)-1) * sizeof(struct symbol
*));
2817 /* Should chase pointers to old one. Fortunately, that`s just
2818 the block`s function and inferior blocks */
2819 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b
)
2820 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2821 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2822 if (BLOCKVECTOR_BLOCK(bv
,i
) == b
)
2823 BLOCKVECTOR_BLOCK(bv
,i
) = new;
2824 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) == b
)
2825 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) = new;
2829 /* Create a new symbol with printname NAME */
2836 struct symbol
*s
= (struct symbol
*)
2837 obstack_alloc (¤t_objfile
->symbol_obstack
, sizeof (struct symbol
));
2839 memset (s
, 0, sizeof (*s
));
2840 SYMBOL_NAME(s
) = name
;
2844 /* Create a new type with printname NAME */
2853 t
= alloc_type (current_objfile
);
2854 TYPE_NAME(t
) = name
;
2855 TYPE_CPLUS_SPECIFIC(t
) = (struct cplus_struct_type
*)
2856 &cplus_struct_default
;
2861 /* Things used for calling functions in the inferior.
2862 These functions are exported to our companion
2863 mips-tdep.c file and are here because they play
2864 with the symbol-table explicitly. */
2866 /* Sigtramp: make sure we have all the necessary information
2867 about the signal trampoline code. Since the official code
2868 from MIPS does not do so, we make up that information ourselves.
2869 If they fix the library (unlikely) this code will neutralize itself. */
2876 struct block
*b
, *b0
;
2878 sigtramp_address
= -1;
2880 /* We know it is sold as sigvec */
2881 s
= lookup_symbol("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
2883 /* Most programs do not play with signals */
2887 b0
= SYMBOL_BLOCK_VALUE(s
);
2889 /* A label of sigvec, to be more precise */
2890 s
= lookup_symbol("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
2892 /* But maybe this program uses its own version of sigvec */
2896 sigtramp_address
= SYMBOL_VALUE(s
);
2897 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
2899 /* Did we or MIPSco fix the library ? */
2900 if (SYMBOL_CLASS(s
) == LOC_BLOCK
)
2903 /* But what symtab does it live in ? */
2904 st
= find_pc_symtab(SYMBOL_VALUE(s
));
2907 * Ok, there goes the fix: turn it into a procedure, with all the
2908 * needed info. Note we make it a nested procedure of sigvec,
2909 * which is the way the (assembly) code is actually written.
2911 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2912 SYMBOL_CLASS(s
) = LOC_BLOCK
;
2913 SYMBOL_TYPE(s
) = init_type(TYPE_CODE_FUNC
, 4, 0, 0, (struct objfile
*) NULL
);
2914 TYPE_TARGET_TYPE(SYMBOL_TYPE(s
)) = builtin_type_void
;
2916 /* Need a block to allocate .gdbinfo. in */
2918 SYMBOL_BLOCK_VALUE(s
) = b
;
2919 BLOCK_START(b
) = sigtramp_address
;
2920 BLOCK_END(b
) = sigtramp_end
;
2921 BLOCK_FUNCTION(b
) = s
;
2922 BLOCK_SUPERBLOCK(b
) = BLOCK_SUPERBLOCK(b0
);
2926 /* Make a .gdbinfo. for it */
2928 struct mips_extra_func_info
*e
=
2929 (struct mips_extra_func_info
*)
2930 xzalloc(sizeof(struct mips_extra_func_info
));
2932 e
->numargs
= 0; /* the kernel thinks otherwise */
2933 /* align_longword(sigcontext + SIGFRAME) */
2934 e
->framesize
= 0x150;
2935 e
->framereg
= SP_REGNUM
;
2938 e
->regoffset
= -(41 * sizeof(int));
2940 e
->fregoffset
= -(37 * sizeof(int));
2943 s
= new_symbol(".gdbinfo.");
2944 SYMBOL_VALUE(s
) = (int) e
;
2945 SYMBOL_NAMESPACE(s
) = LABEL_NAMESPACE
;
2946 SYMBOL_CLASS(s
) = LOC_CONST
;
2947 SYMBOL_TYPE(s
) = builtin_type_void
;
2950 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
2953 /* Initialization */
2955 static struct sym_fns ecoff_sym_fns
= {"ecoff", 5,
2956 mipscoff_new_init
, mipscoff_symfile_init
,
2957 mipscoff_symfile_read
};
2959 _initialize_mipsread ()
2961 add_symtab_fns (&ecoff_sym_fns
);
2963 /* Missing basic types */
2964 builtin_type_string
=
2965 init_type (TYPE_CODE_PASCAL_ARRAY
,
2967 (struct objfile
*) NULL
);
2968 builtin_type_complex
=
2969 init_type(TYPE_CODE_FLT
,
2970 2 * sizeof(float), 0, "complex",
2971 (struct objfile
*) NULL
);
2972 builtin_type_double_complex
=
2973 init_type(TYPE_CODE_FLT
,
2974 2 * sizeof(double), 0, "double_complex",
2975 (struct objfile
*) NULL
);
2976 builtin_type_fixed_dec
=
2977 init_type(TYPE_CODE_INT
, sizeof(int),
2979 (struct objfile
*) NULL
);
2980 builtin_type_float_dec
=
2981 init_type(TYPE_CODE_FLT
, sizeof(double),
2982 0, "floating_decimal",
2983 (struct objfile
*) NULL
);