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 struct coff_symfile_info
*info
= (struct coff_symfile_info
*)sf
->sym_private
;
291 bfd
*abfd
= sf
->objfile
->obfd
;
292 char *name
= bfd_get_filename (abfd
);
296 int stringtab_offset
;
298 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
299 desc
= fileno ((FILE *)(abfd
->iostream
)); /* Raw file descriptor */
302 /* Position to read the symbol table. */
303 val
= lseek (desc
, (long)symtab_offset
, 0);
305 perror_with_name (name
);
307 init_minimal_symbol_collection ();
308 make_cleanup (discard_minimal_symbols
, 0);
310 /* Now that the executable file is positioned at symbol table,
311 process it and define symbols accordingly. */
313 read_mips_symtab(sf
->objfile
, desc
);
315 /* Install any minimal symbols that have been collected as the current
316 minimal symbols for this objfile. */
318 install_minimal_symbols (sf
-> objfile
);
321 /* Allocate zeroed memory */
326 char *p
= xmalloc(size
);
332 /* Exported procedure: Builds a symtab from the PST partial one.
333 Restores the environment in effect when PST was created, delegates
334 most of the work to an ancillary procedure, and sorts
335 and reorders the symtab list at the end */
338 mipscoff_psymtab_to_symtab(pst
)
339 struct partial_symtab
*pst
;
348 printf_filtered("Reading in symbols for %s...", pst
->filename
);
351 /* Restore the header and list of pending typedefs */
352 cur_hdr
= CUR_HDR(pst
);
354 next_symbol_text_func
= mips_next_symbol_text
;
356 psymtab_to_symtab_1(pst
, pst
->filename
);
358 /* Match with global symbols. This only needs to be done once,
359 after all of the symtabs and dependencies have been read in. */
360 scan_file_globals (pst
->objfile
);
363 printf_filtered("done.\n");
366 /* Exported procedure: Is PC in the signal trampoline code */
369 in_sigtramp(pc
, name
)
373 if (sigtramp_address
== 0)
375 return (pc
>= sigtramp_address
&& pc
< sigtramp_end
);
378 /* File-level interface functions */
380 /* Read the symtab information from file FSYM into memory. Also,
381 return address just past end of our text segment in *END_OF_TEXT_SEGP. */
384 read_the_mips_symtab(abfd
, fsym
, end_of_text_segp
)
387 CORE_ADDR
*end_of_text_segp
;
389 int stsize
, st_hdrsize
;
391 struct hdr_ext hdr_ext
;
393 /* Header for executable/object file we read symbols from */
394 struct coff_exec filhdr
;
396 /* We get here with DESC pointing to the symtab header. But we need
397 * other info from the initial headers */
399 myread(fsym
, (char *)&filhdr
, sizeof filhdr
);
401 if (end_of_text_segp
)
403 bfd_h_get_32 (abfd
, filhdr
.a
.text_start
) +
404 bfd_h_get_32 (abfd
, filhdr
.a
.tsize
);
406 /* Find and read the symbol table header */
407 st_hdrsize
= bfd_h_get_32 (abfd
, filhdr
.f
.f_nsyms
);
408 st_filptr
= bfd_h_get_32 (abfd
, filhdr
.f
.f_symptr
);
412 lseek(fsym
, st_filptr
, L_SET
);
413 if (st_hdrsize
!= sizeof (hdr_ext
)) { /* Profanity check */
414 error ("Wrong header size: %d, not %d", st_hdrsize
,
417 if (read(fsym
, &hdr_ext
, st_hdrsize
) != st_hdrsize
)
419 ecoff_swap_hdr_in (abfd
, &hdr_ext
, &st_hdr
);
421 /* Find out how large the symbol table is */
422 stsize
= (st_hdr
.cbExtOffset
- (st_filptr
+ st_hdrsize
))
423 + st_hdr
.iextMax
* cbEXTR
;
425 /* Allocate space for the symbol table. Read it in. */
426 cur_hdr
= (HDRR
*) xmalloc(stsize
+ st_hdrsize
);
428 memcpy(cur_hdr
, &hdr_ext
, st_hdrsize
);
429 if (read(fsym
, (char *) cur_hdr
+ st_hdrsize
, stsize
) != stsize
)
432 /* Fixup file_pointers in it */
433 fixup_symtab(cur_hdr
, (char *) cur_hdr
+ st_hdrsize
,
434 st_filptr
+ st_hdrsize
, abfd
);
438 error("Short read on %s", bfd_get_filename (abfd
));
442 /* Turn all file-relative pointers in the symtab described by HDR
443 into memory pointers, given that the symtab itself is located
444 at DATA in memory and F_PTR in the file.
446 Byte-swap all the data structures, in place, while we are at it --
447 except AUX entries, which we leave in their original byte order.
448 They will be swapped as they are used instead. (FIXME: we ought to
449 do all the data structures that way.) */
452 fixup_symtab (hdr
, data
, f_ptr
, abfd
)
464 /* This function depends on the external and internal forms
465 of the MIPS symbol table taking identical space. Check this
466 assumption at compile-time. */
467 static check_hdr1
[1 + sizeof (struct hdr_ext
) - sizeof (HDRR
)] = {0};
468 static check_hdr2
[1 + sizeof (HDRR
) - sizeof (struct hdr_ext
)] = {0};
469 static check_fdr1
[1 + sizeof (struct fdr_ext
) - sizeof (FDR
)] = {0};
470 static check_fdr2
[1 + sizeof (FDR
) - sizeof (struct fdr_ext
)] = {0};
471 static check_pdr1
[1 + sizeof (struct pdr_ext
) - sizeof (PDR
)] = {0};
472 static check_pdr2
[1 + sizeof (PDR
) - sizeof (struct pdr_ext
)] = {0};
473 static check_sym1
[1 + sizeof (struct sym_ext
) - sizeof (SYMR
)] = {0};
474 static check_sym2
[1 + sizeof (SYMR
) - sizeof (struct sym_ext
)] = {0};
475 static check_ext1
[1 + sizeof (struct ext_ext
) - sizeof (EXTR
)] = {0};
476 static check_ext2
[1 + sizeof (EXTR
) - sizeof (struct ext_ext
)] = {0};
478 /* Swap in the header record. */
479 ecoff_swap_hdr_in (abfd
, hdr
, hdr
);
482 * These fields are useless (and empty) by now:
483 * hdr->cbDnOffset, hdr->cbOptOffset
484 * We use them for other internal purposes.
487 hdr
->cbOptOffset
= 0;
490 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
505 /* Fix all string pointers inside the symtab, and
506 the FDR records. Also fix other miscellany. */
508 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
509 register unsigned code_offset
;
511 /* Header itself, and strings */
512 fh
= (FDR
*) (hdr
->cbFdOffset
) + f_idx
;
514 /* Swap in the FDR */
515 ecoff_swap_fdr_in (abfd
, fh
, fh
);
517 fh
->issBase
+= hdr
->cbSsOffset
;
519 fh
->rss
= (long)fh
->rss
+ fh
->issBase
;
522 fh
->isymBase
= (int)((SYMR
*)(hdr
->cbSymOffset
)+fh
->isymBase
);
524 /* FIXME! Probably don't want to do this here! */
525 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
526 sh
= (SYMR
*)fh
->isymBase
+ s_idx
;
527 ecoff_swap_sym_in (abfd
, sh
, sh
);
529 sh
->iss
= (long) sh
->iss
+ fh
->issBase
;
535 /* cannot fix fh->ipdFirst because it is a short */
536 #define IPDFIRST(h,fh) \
537 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
539 /* Optional symbols (actually used for partial_symtabs) */
545 fh
->iauxBase
= hdr
->cbAuxOffset
+ fh
->iauxBase
* sizeof(union aux_ext
);
546 /* Relative file descriptor table */
547 fh
->rfdBase
= hdr
->cbRfdOffset
+ fh
->rfdBase
* sizeof(RFDT
);
551 fh
->cbLineOffset
+= hdr
->cbLineOffset
;
553 /* Procedure symbols. (XXX This should be done later) */
554 code_offset
= fh
->adr
;
555 for (s_idx
= 0; s_idx
< fh
->cpd
; s_idx
++) {
556 unsigned name
, only_ext
;
558 pr
= (PDR
*)(IPDFIRST(hdr
,fh
)) + s_idx
;
559 ecoff_swap_pdr_in (abfd
, pr
, pr
);
561 /* Simple rule to find files linked "-x" */
562 only_ext
= fh
->rss
== -1;
564 if (pr
->isym
== -1) {
565 /* static function */
569 name
= hdr
->cbExtOffset
+ pr
->isym
* sizeof(EXTR
);
570 sh
= &((EXTR
*)name
)->asym
;
574 sh
= (SYMR
*)fh
->isymBase
+ pr
->isym
;
575 /* Included code ? */
576 if (s_idx
== 0 && pr
->adr
!= 0)
577 code_offset
-= pr
->adr
;
580 /* Turn index into a pointer */
583 /* Fix line numbers */
584 pr
->cbLineOffset
+= fh
->cbLineOffset
;
586 /* Relocate address */
588 pr
->adr
+= code_offset
;
592 /* External symbols: swap in, and fix string */
593 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
594 esh
= (EXTR
*)(hdr
->cbExtOffset
) + s_idx
;
595 ecoff_swap_ext_in (abfd
, esh
, esh
);
596 esh
->asym
.iss
= esh
->asym
.iss
+ hdr
->cbSsExtOffset
;
601 /* Find a file descriptor given its index RF relative to a file CF */
609 f
= (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
610 /* Object files do not have the RFD table, all refs are absolute */
612 return (FDR
*) (cur_hdr
->cbFdOffset
) + rf
;
613 cf
= *((pRFDT
) f
->rfdBase
+ rf
);
614 return (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
617 /* Return a safer print NAME for a file descriptor */
623 if (name
== (char *) -1)
624 return "<stripped file>";
625 if (UNSAFE_DATA_ADDR(name
))
631 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
632 whether we are adding to the general symtab or not.
633 FIXME: INCREMENTAL is currently always zero, though it should not be. */
636 read_mips_symtab (objfile
, desc
)
637 struct objfile
*objfile
;
640 CORE_ADDR end_of_text_seg
;
642 read_the_mips_symtab(objfile
->obfd
, desc
, &end_of_text_seg
);
644 parse_partial_symbols(end_of_text_seg
, objfile
);
648 * Check to make sure file was compiled with -g.
649 * If not, warn the user of this limitation.
651 if (compare_glevel(max_glevel
, GLEVEL_2
) < 0) {
652 if (max_gdbinfo
== 0)
654 "\n%s not compiled with -g, debugging support is limited.\n",
657 "You should compile with -g2 or -g3 for best debugging support.\n");
663 /* Local utilities */
665 /* Map of FDR indexes to partial symtabs */
668 struct partial_symtab
*pst
; /* the psymtab proper */
669 int n_globals
; /* exported globals (external symbols) */
670 int globals_offset
; /* cumulative */
674 /* Utility stack, used to nest procedures and blocks properly.
675 It is a doubly linked list, to avoid too many alloc/free.
676 Since we might need it quite a few times it is NOT deallocated
679 static struct parse_stack
{
680 struct parse_stack
*next
, *prev
;
681 struct symtab
*cur_st
; /* Current symtab. */
682 struct block
*cur_block
; /* Block in it. */
683 int blocktype
; /* What are we parsing. */
684 int maxsyms
; /* Max symbols in this block. */
685 struct type
*cur_type
; /* Type we parse fields for. */
686 int cur_field
; /* Field number in cur_type. */
687 int procadr
; /* Start addres of this procedure */
688 int numargs
; /* Its argument count */
689 } *top_stack
; /* Top stack ptr */
692 /* Enter a new lexical context */
694 static push_parse_stack()
696 struct parse_stack
*new;
698 /* Reuse frames if possible */
699 if (top_stack
&& top_stack
->prev
)
700 new = top_stack
->prev
;
702 new = (struct parse_stack
*) xzalloc(sizeof(struct parse_stack
));
703 /* Initialize new frame with previous content */
705 register struct parse_stack
*prev
= new->prev
;
708 top_stack
->prev
= new;
710 new->next
= top_stack
;
715 /* Exit a lexical context */
717 static pop_parse_stack()
722 top_stack
= top_stack
->next
;
726 /* Cross-references might be to things we haven't looked at
727 yet, e.g. type references. To avoid too many type
728 duplications we keep a quick fixup table, an array
729 of lists of references indexed by file descriptor */
731 static struct mips_pending
{
732 struct mips_pending
*next
; /* link */
733 SYMR
*s
; /* the symbol */
734 struct type
*t
; /* its partial type descriptor */
738 /* Check whether we already saw symbol SH in file FH as undefined */
741 struct mips_pending
*is_pending_symbol(fh
, sh
)
745 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
746 register struct mips_pending
*p
;
748 /* Linear search is ok, list is typically no more than 10 deep */
749 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
755 /* Check whether we already saw type T in file FH as undefined */
758 struct mips_pending
*is_pending_type(fh
, t
)
762 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
763 register struct mips_pending
*p
;
765 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
771 /* Add a new undef symbol SH of type T */
774 add_pending(fh
, sh
, t
)
779 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
780 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
782 /* Make sure we do not make duplicates */
784 p
= (struct mips_pending
*) xmalloc(sizeof(*p
));
787 p
->next
= pending_list
[f_idx
];
788 pending_list
[f_idx
] = p
;
790 sh
->reserved
= 1; /* for quick check */
793 /* Throw away undef entries when done with file index F_IDX */
798 register struct mips_pending
*p
, *q
;
800 for (p
= pending_list
[f_idx
]; p
; p
= q
) {
804 pending_list
[f_idx
] = 0;
807 /* The number of args to a procedure is not explicit in the symtab,
808 this is the list of all those we know of.
809 This makes parsing more reasonable and avoids extra passes */
811 static struct numarg
{
812 struct numarg
*next
; /* link */
813 unsigned adr
; /* procedure's start address */
814 unsigned num
; /* arg count */
817 /* Record that the procedure at ADR takes NUM arguments. */
822 struct numarg
*n
= (struct numarg
*) xmalloc(sizeof(struct numarg
));
826 n
->next
= numargs_list
;
830 /* See if we know how many arguments the procedure at ADR takes */
835 struct numarg
*n
= numargs_list
;
837 while (n
&& n
->adr
!= adr
)
839 return (n
) ? n
->num
: -1;
842 /* Release storage when done with this file */
847 struct numarg
*n
= numargs_list
, *m
;
858 prepend_tag_kind(tag_name
, type_code
)
868 case TYPE_CODE_STRUCT
:
871 case TYPE_CODE_UNION
:
878 result
= (char*)obstack_alloc (¤t_objfile
->symbol_obstack
,
879 strlen(prefix
) + strlen(tag_name
) + 1);
880 sprintf(result
, "%s%s", prefix
, tag_name
);
885 /* Parsing Routines proper. */
887 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
888 For blocks, procedures and types we open a new lexical context.
889 This is basically just a big switch on the symbol's type.
890 Argument AX is the base pointer of aux symbols for this file (fh->iauxBase).
891 BIGEND says whether aux symbols are big-endian or little-endian.
892 Return count of SYMR's handled (normally one). */
895 parse_symbol(sh
, ax
, bigend
)
906 /* When a symbol is cross-referenced from other files/symbols
907 we mark it explicitly */
908 int pend
= (sh
->reserved
== 1);
909 enum address_class
class;
917 case stGlobal
: /* external symbol, goes into global block */
919 b
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
921 s
= new_symbol(sh
->iss
);
922 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
925 case stStatic
: /* static data, goes into current block. */
927 b
= top_stack
->cur_block
;
928 s
= new_symbol(sh
->iss
);
929 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
932 case stLocal
: /* local variable, goes into current block */
933 if (sh
->sc
== scRegister
) {
934 class = LOC_REGISTER
;
936 sh
->value
+= FP0_REGNUM
-32;
939 b
= top_stack
->cur_block
;
940 s
= new_symbol(sh
->iss
);
941 SYMBOL_VALUE(s
) = sh
->value
;
943 data
: /* Common code for symbols describing data */
944 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
945 SYMBOL_CLASS(s
) = class;
948 /* Type could be missing in a number of cases */
949 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
950 sh
->index
== 0xfffff)
951 SYMBOL_TYPE(s
) = builtin_type_int
; /* undefined? */
953 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, 0, bigend
);
954 /* Value of a data symbol is its memory address */
957 case stParam
: /* arg to procedure, goes into current block */
959 top_stack
->numargs
++;
961 name
= (char*)sh
->iss
;
962 /* Special GNU C++ name. */
963 if (name
[0] == CPLUS_MARKER
&& name
[1] == 't' && name
[2] == 0)
965 s
= new_symbol(name
);
967 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
968 if (sh
->sc
== scRegister
) {
969 SYMBOL_CLASS(s
) = LOC_REGPARM
;
971 sh
->value
+= FP0_REGNUM
-32;
973 SYMBOL_CLASS(s
) = LOC_ARG
;
974 SYMBOL_VALUE(s
) = sh
->value
;
975 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, 0, bigend
);
976 add_symbol(s
, top_stack
->cur_block
);
978 /* FIXME: This has not been tested. See dbxread.c */
979 /* Add the type of this parameter to the function/procedure
980 type of this block. */
981 add_param_to_type(&top_stack
->cur_block
->function
->type
,s
);
985 case stLabel
: /* label, goes into current block */
986 s
= new_symbol(sh
->iss
);
987 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
; /* so that it can be used */
988 SYMBOL_CLASS(s
) = LOC_LABEL
; /* but not misused */
989 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
990 SYMBOL_TYPE(s
) = builtin_type_int
;
991 add_symbol(s
, top_stack
->cur_block
);
994 case stProc
: /* Procedure, usually goes into global block */
995 case stStaticProc
: /* Static procedure, goes into current block */
996 s
= new_symbol(sh
->iss
);
997 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
998 SYMBOL_CLASS(s
) = LOC_BLOCK
;
999 /* Type of the return value */
1000 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
1001 t
= builtin_type_int
;
1003 t
= parse_type(ax
+ sh
->index
+ 1, 0, bigend
);
1004 b
= top_stack
->cur_block
;
1005 if (sh
->st
== stProc
) {
1006 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
1007 /* The next test should normally be true,
1008 but provides a hook for nested functions
1009 (which we don't want to make global). */
1010 if (b
== BLOCKVECTOR_BLOCK(bv
, STATIC_BLOCK
))
1011 b
= BLOCKVECTOR_BLOCK(bv
, GLOBAL_BLOCK
);
1015 /* Make a type for the procedure itself */
1017 /* FIXME: This has not been tested yet! See dbxread.c */
1018 /* Generate a template for the type of this function. The
1019 types of the arguments will be added as we read the symbol
1021 bcopy(SYMBOL_TYPE(s
),lookup_function_type(t
),sizeof(struct type
));
1023 SYMBOL_TYPE(s
) = lookup_function_type (t
);
1026 /* Create and enter a new lexical context */
1027 b
= new_block(top_stack
->maxsyms
);
1028 SYMBOL_BLOCK_VALUE(s
) = b
;
1029 BLOCK_FUNCTION(b
) = s
;
1030 BLOCK_START(b
) = BLOCK_END(b
) = sh
->value
;
1031 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1032 add_block(b
, top_stack
->cur_st
);
1034 /* Not if we only have partial info */
1035 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
1039 top_stack
->cur_block
= b
;
1040 top_stack
->blocktype
= sh
->st
;
1041 top_stack
->cur_type
= SYMBOL_TYPE(s
);
1042 top_stack
->cur_field
= -1;
1043 top_stack
->procadr
= sh
->value
;
1044 top_stack
->numargs
= 0;
1046 sh
->value
= (long) SYMBOL_TYPE(s
);
1050 #ifndef btVoid /* btVoid was added late. */
1053 /* These new symbol types have been recently added to SGI machines. */
1067 case stBlock
: /* Either a lexical block, or some type */
1069 top_stack
->blocktype
= stBlock
;
1070 if (sh
->sc
== scInfo
) { /* structure/union/enum def */
1072 sh
->st
== stStruct
? TYPE_CODE_STRUCT
1073 : sh
->st
== stUnion
? TYPE_CODE_UNION
1074 : sh
->st
== stEnum
? TYPE_CODE_ENUM
1081 s
= new_symbol(sh
->iss
);
1082 SYMBOL_NAMESPACE(s
) = STRUCT_NAMESPACE
;
1083 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1084 SYMBOL_VALUE(s
) = 0;
1085 add_symbol(s
, top_stack
->cur_block
);
1087 /* First count the number of fields. */
1088 for (tsym
= sh
+1; tsym
->st
!= stEnd
; tsym
++)
1089 if (tsym
->st
== stMember
) {
1090 if (nfields
== 0 && type_code
== TYPE_CODE_UNDEF
)
1091 /* If the type of the member is Nil (or Void)
1092 assume the tag is an enumeration. */
1093 if (tsym
->index
== indexNil
)
1094 type_code
= TYPE_CODE_ENUM
;
1096 ecoff_swap_tir_in (bigend
,
1097 &ax
[tsym
->index
].a_ti
,
1099 if (tir
.bt
== btNil
|| tir
.bt
== btVoid
)
1100 type_code
= TYPE_CODE_ENUM
;
1103 if (tsym
->value
> max_value
)
1104 max_value
= tsym
->value
;
1106 else if (tsym
->st
== stBlock
1107 || tsym
->st
== stParsed
) {
1108 if (tsym
->sc
== scVariant
) ; /*UNIMPLEMENTED*/
1109 if (tsym
->index
!= 0)
1110 tsym
= ((SYMR
*)cur_fdr
->isymBase
)
1114 /* There is no guaranteed way to distinguish struct,
1115 unions, and enums at this point. This is a bug in the
1116 original design (that has been fixed with the
1117 recent addition of the stStruct, stUnion, and stEnum
1118 symbol types.) The way you can tell is if/when you
1119 see a variable or field of that type: In that case
1120 the variable's type (in the AUX table) says if the
1121 type is struct, union, or enum,
1122 and points back to the stBlock here.
1123 So you can patch the tag kind up later - but only
1124 if there actually is a variable or field of that type.
1126 So until we know for sure, we will guess at this point.
1128 If the first member has index==indexNil or a void type,
1129 assume we have an enumeration.
1130 Otherwise, if there is more than one member, and all
1131 the members have offset 0, assume we have a union.
1132 Otherwise, assume we have a struct.
1134 The heuristic could guess wrong in the case of
1135 of an enumeration with no members or a union
1136 with one (or zero) members, or when all except the
1137 last field of a struct have width zero.
1138 These are uncommon and/or illegal situations, and
1139 in any case guessing wrong probably doesn't matter much.
1141 But if we later do find out we were wrong,
1142 we fixup the tag kind. Members of an enumeration
1143 must be handled differently from struct/union fields,
1144 and that is harder to patch up, but luckily we
1145 shouldn't need to. (If there are any enumeration
1146 members, we can tell for sure it's an enum here.) */
1148 if (type_code
== TYPE_CODE_UNDEF
)
1149 if (nfields
> 1 && max_value
== 0)
1150 type_code
= TYPE_CODE_UNION
;
1152 type_code
= TYPE_CODE_STRUCT
;
1154 /* If this type was expected, use its partial definition */
1156 t
= is_pending_symbol(cur_fdr
, sh
)->t
;
1158 t
= new_type(prepend_tag_kind(sh
->iss
, type_code
));
1160 TYPE_CODE(t
) = type_code
;
1161 TYPE_LENGTH(t
) = sh
->value
;
1162 TYPE_NFIELDS(t
) = nfields
;
1163 TYPE_FIELDS(t
) = f
= (struct field
*)
1164 obstack_alloc (¤t_objfile
-> type_obstack
,
1165 nfields
* sizeof (struct field
));
1167 if (type_code
== TYPE_CODE_ENUM
) {
1168 /* This is a non-empty enum. */
1169 for (tsym
= sh
+ 1; tsym
->st
== stMember
; tsym
++) {
1170 struct symbol
*enum_sym
;
1171 f
->bitpos
= tsym
->value
;
1173 f
->name
= (char*)tsym
->iss
;
1176 enum_sym
= (struct symbol
*)
1177 obstack_alloc (¤t_objfile
->symbol_obstack
,
1178 sizeof (struct symbol
));
1179 memset (enum_sym
, 0, sizeof (struct symbol
));
1180 SYMBOL_NAME (enum_sym
) = f
->name
;
1181 SYMBOL_CLASS (enum_sym
) = LOC_CONST
;
1182 SYMBOL_TYPE (enum_sym
) = t
;
1183 SYMBOL_NAMESPACE (enum_sym
) = VAR_NAMESPACE
;
1184 SYMBOL_VALUE (enum_sym
) = tsym
->value
;
1185 add_symbol(enum_sym
, top_stack
->cur_block
);
1187 /* Skip the stMembers that we've handled. */
1193 /* make this the current type */
1194 top_stack
->cur_type
= t
;
1195 top_stack
->cur_field
= 0;
1196 /* Mark that symbol has a type, and say which one */
1197 sh
->value
= (long) t
;
1199 /* beginnning of (code) block. Value of symbol
1200 is the displacement from procedure start */
1201 b
= new_block(top_stack
->maxsyms
);
1202 BLOCK_START(b
) = sh
->value
+ top_stack
->procadr
;
1203 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1204 top_stack
->cur_block
= b
;
1205 add_block(b
, top_stack
->cur_st
);
1209 case stEnd
: /* end (of anything) */
1210 if (sh
->sc
== scInfo
) {
1211 /* Finished with type */
1212 top_stack
->cur_type
= 0;
1213 } else if (sh
->sc
== scText
&&
1214 (top_stack
->blocktype
== stProc
||
1215 top_stack
->blocktype
== stStaticProc
)) {
1216 /* Finished with procedure */
1217 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
1221 BLOCK_END(top_stack
->cur_block
) += sh
->value
; /* size */
1222 got_numargs(top_stack
->procadr
, top_stack
->numargs
);
1223 /* Reallocate symbols, saving memory */
1224 b
= shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1226 /* f77 emits proc-level with address bounds==[0,0],
1227 So look for such child blocks, and patch them. */
1228 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++) {
1229 struct block
*b_bad
= BLOCKVECTOR_BLOCK(bv
,i
);
1230 if (BLOCK_SUPERBLOCK(b_bad
) == b
1231 && BLOCK_START(b_bad
) == top_stack
->procadr
1232 && BLOCK_END(b_bad
) == top_stack
->procadr
) {
1233 BLOCK_START(b_bad
) = BLOCK_START(b
);
1234 BLOCK_END(b_bad
) = BLOCK_END(b
);
1237 } else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
) {
1238 /* End of (code) block. The value of the symbol
1239 is the displacement from the procedure`s start
1240 address of the end of this block. */
1241 BLOCK_END(top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1242 (void) shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1244 pop_parse_stack(); /* restore previous lexical context */
1247 case stMember
: /* member of struct or union */
1248 f
= &TYPE_FIELDS(top_stack
->cur_type
)[top_stack
->cur_field
++];
1249 f
->name
= (char*)sh
->iss
;
1250 f
->bitpos
= sh
->value
;
1252 f
->type
= parse_type(ax
+ sh
->index
, &f
->bitsize
, bigend
);
1255 case stTypedef
: /* type definition */
1256 s
= new_symbol(sh
->iss
);
1257 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1258 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1259 SYMBOL_BLOCK_VALUE(s
) = top_stack
->cur_block
;
1260 add_symbol(s
, top_stack
->cur_block
);
1261 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, 0, bigend
);
1262 sh
->value
= (long) SYMBOL_TYPE(s
);
1265 case stFile
: /* file name */
1267 top_stack
->blocktype
= sh
->st
;
1270 /* I`ve never seen these for C */
1272 break; /* register relocation */
1274 break; /* forwarding address */
1276 break; /* constant */
1278 error("Unknown symbol type %x.", sh
->st
);
1284 /* Parse the type information provided in the raw AX entries for
1285 the symbol SH. Return the bitfield size in BS, in case.
1286 We must byte-swap the AX entries before we use them; BIGEND says whether
1287 they are big-endian or little-endian (from fh->fBigendian). */
1289 static struct type
*parse_type(ax
, bs
, bigend
)
1294 /* Null entries in this map are treated specially */
1295 static struct type
**map_bt
[] =
1297 &builtin_type_void
, /* btNil */
1299 &builtin_type_char
, /* btChar */
1300 &builtin_type_unsigned_char
, /* btUChar */
1301 &builtin_type_short
, /* btShort */
1302 &builtin_type_unsigned_short
, /* btUShort */
1303 &builtin_type_int
, /* btInt */
1304 &builtin_type_unsigned_int
, /* btUInt */
1305 &builtin_type_long
, /* btLong */
1306 &builtin_type_unsigned_long
, /* btULong */
1307 &builtin_type_float
, /* btFloat */
1308 &builtin_type_double
, /* btDouble */
1315 &builtin_type_complex
, /* btComplex */
1316 &builtin_type_double_complex
, /* btDComplex */
1318 &builtin_type_fixed_dec
, /* btFixedDec */
1319 &builtin_type_float_dec
, /* btFloatDec */
1320 &builtin_type_string
, /* btString */
1323 &builtin_type_void
, /* btVoid */
1327 struct type
*tp
= 0;
1333 /* Use aux as a type information record, map its basic type. */
1335 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1336 if (t
->bt
> (sizeof (map_bt
)/sizeof (*map_bt
))) {
1337 complain (&basic_type_complaint
, t
->bt
);
1338 return builtin_type_int
;
1340 if (map_bt
[t
->bt
]) {
1341 tp
= *map_bt
[t
->bt
];
1345 /* Cannot use builtin types -- build our own */
1348 tp
= lookup_pointer_type (builtin_type_void
);
1352 type_code
= TYPE_CODE_STRUCT
;
1356 type_code
= TYPE_CODE_UNION
;
1360 type_code
= TYPE_CODE_ENUM
;
1364 type_code
= TYPE_CODE_RANGE
;
1368 type_code
= TYPE_CODE_SET
;
1373 complain (&basic_type_complaint
, t
->bt
);
1374 return builtin_type_int
;
1378 /* Skip over any further type qualifiers (FIXME). */
1380 /* This is the way it would work if the compiler worked */
1384 ecoff_swap_tir_in (bigend
, ax
, t1
);
1385 } while (t1
->continued
);
1388 /* Move on to next aux */
1392 *bs
= AUX_GET_WIDTH (bigend
, ax
);
1396 /* All these types really point to some (common) MIPS type
1397 definition, and only the type-qualifiers fully identify
1398 them. We'll make the same effort at sharing. */
1399 if (t
->bt
== btIndirect
||
1400 t
->bt
== btStruct
||
1403 t
->bt
== btTypedef
||
1406 char name
[256], *pn
;
1408 /* Try to cross reference this type */
1409 ax
+= cross_ref(ax
, &tp
, type_code
, &pn
, bigend
);
1410 /* reading .o file ? */
1411 if (UNSAFE_DATA_ADDR(tp
))
1412 tp
= init_type(type_code
, 0, 0, 0, (struct objfile
*) NULL
);
1413 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1414 sprintf(name
, fmt
, pn
);
1416 /* Usually, TYPE_CODE(tp) is already type_code. The main
1417 exception is if we guessed wrong re struct/union/enum. */
1418 if (TYPE_CODE(tp
) != type_code
) {
1419 complain (&bad_tag_guess_complaint
, 0);
1420 TYPE_CODE(tp
) = type_code
;
1422 if (TYPE_NAME(tp
) == NULL
|| strcmp(TYPE_NAME(tp
), name
) != 0)
1423 TYPE_NAME(tp
) = obsavestring(name
, strlen(name
),
1424 ¤t_objfile
-> type_obstack
);
1427 /* Deal with range types */
1428 if (t
->bt
== btRange
) {
1431 TYPE_NFIELDS (tp
) = 2;
1433 (struct field
*) obstack_alloc (¤t_objfile
-> type_obstack
,
1434 2 * sizeof (struct field
));
1435 TYPE_FIELD_NAME (tp
, 0) = obsavestring ("Low", strlen ("Low"),
1436 ¤t_objfile
-> type_obstack
);
1437 TYPE_FIELD_BITPOS (tp
, 0) = AUX_GET_DNLOW (bigend
, ax
);
1439 TYPE_FIELD_NAME (tp
, 1) = obsavestring ("High", strlen ("High"),
1440 ¤t_objfile
-> type_obstack
);
1441 TYPE_FIELD_BITPOS (tp
, 1) = AUX_GET_DNHIGH (bigend
, ax
);
1445 /* Parse all the type qualifiers now. If there are more
1446 than 6 the game will continue in the next aux */
1448 #define PARSE_TQ(tq) \
1449 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, bigend);
1451 again
: PARSE_TQ(tq0
);
1461 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1467 /* Make up a complex type from a basic one. Type is passed by
1468 reference in TPP and side-effected as necessary. The type
1469 qualifier TQ says how to handle the aux symbols at AX for
1470 the symbol SX we are currently analyzing. BIGEND says whether
1471 aux symbols are big-endian or little-endian.
1472 Returns the number of aux symbols we parsed. */
1475 upgrade_type(tpp
, tq
, ax
, bigend
)
1483 /* Used in array processing */
1492 t
= lookup_pointer_type (*tpp
);
1497 t
= lookup_function_type (*tpp
);
1503 t
= init_type(TYPE_CODE_ARRAY
, 0, 0, 0, (struct objfile
*) NULL
);
1504 TYPE_TARGET_TYPE(t
) = *tpp
;
1506 /* Determine and record the domain type (type of index) */
1507 ecoff_swap_rndx_in (bigend
, ax
, &rndx
);
1512 rf
= AUX_GET_ISYM (bigend
, ax
);
1515 fh
= get_rfd(cur_fd
, rf
);
1517 /* Fields are kept in an array */
1518 /* FIXME - Memory leak! */
1519 if (TYPE_NFIELDS(t
))
1520 TYPE_FIELDS(t
) = (struct field
*)
1521 xrealloc((char *) TYPE_FIELDS(t
),
1522 (TYPE_NFIELDS(t
)+1) * sizeof(struct field
));
1524 TYPE_FIELDS(t
) = (struct field
*)
1525 xzalloc(sizeof(struct field
));
1526 f
= &(TYPE_FIELD(t
,TYPE_NFIELDS(t
)));
1528 memset(f
, 0, sizeof(struct field
));
1530 /* XXX */ f
->type
= parse_type(fh
->iauxBase
+ id
* sizeof(union aux_ext
),
1531 &f
->bitsize
, bigend
);
1534 lower
= AUX_GET_DNLOW (bigend
, ax
);
1536 upper
= AUX_GET_DNHIGH (bigend
, ax
);
1538 rf
= AUX_GET_WIDTH (bigend
, ax
); /* bit size of array element */
1540 /* Check whether supplied array element bit size matches
1541 the known size of the element type. If this complaint
1542 ends up not happening, we can remove this code. It's
1543 here because we aren't sure we understand this *&%&$
1545 id
= TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) << 3; /* bitsize */
1547 /* Most likely an undefined type */
1549 TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) = id
>> 3;
1552 complain (&array_bitsize_complaint
, rf
);
1554 TYPE_LENGTH(t
) = (upper
< 0) ? 0 :
1555 (upper
- lower
+ 1) * (rf
>> 3);
1560 /* Volatile -- currently ignored */
1564 complain (&unknown_type_qual_complaint
, tq
);
1570 /* Parse a procedure descriptor record PR. Note that the procedure
1571 is parsed _after_ the local symbols, now we just make up the
1572 extra information we need into a special symbol that we insert
1573 in the procedure's main block. Note also that images that
1574 have been partially stripped (ld -x) have been deprived
1575 of local symbols, and we have to cope with them here.
1576 The procedure's code ends at BOUND */
1579 parse_procedure(pr
, bound
)
1582 struct symbol
*s
, *i
;
1583 SYMR
*sh
= (SYMR
*)pr
->isym
;
1585 struct mips_extra_func_info
*e
;
1589 /* Reuse the MIPS record */
1590 e
= (struct mips_extra_func_info
*) pr
;
1591 e
->numargs
= lookup_numargs(pr
->adr
);
1593 /* Make up our special symbol */
1594 i
= new_symbol(".gdbinfo.");
1595 SYMBOL_VALUE(i
) = (int)e
;
1596 SYMBOL_NAMESPACE(i
) = LABEL_NAMESPACE
;
1597 SYMBOL_CLASS(i
) = LOC_CONST
;
1598 SYMBOL_TYPE(i
) = builtin_type_void
;
1600 /* Make up a name for static procedures. Sigh. */
1601 if (sh
== (SYMR
*)-1) {
1602 sprintf(name
,".static_procedure@%x",pr
->adr
);
1603 sh_name
= savestring(name
, strlen(name
));
1607 sh_name
= (char*)sh
->iss
;
1608 s
= mylookup_symbol(sh_name
, top_stack
->cur_block
,
1609 VAR_NAMESPACE
, LOC_BLOCK
);
1612 b
= SYMBOL_BLOCK_VALUE(s
);
1614 s
= new_symbol(sh_name
);
1615 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1616 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1617 /* Donno its type, hope int is ok */
1618 SYMBOL_TYPE(s
) = lookup_function_type (builtin_type_int
);
1619 add_symbol(s
, top_stack
->cur_block
);
1620 /* Wont have symbols for this one */
1622 SYMBOL_BLOCK_VALUE(s
) = b
;
1623 BLOCK_FUNCTION(b
) = s
;
1624 BLOCK_START(b
) = pr
->adr
;
1625 BLOCK_END(b
) = bound
;
1626 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1627 add_block(b
, top_stack
->cur_st
);
1633 /* Parse the external symbol ES. Just call parse_symbol() after
1634 making sure we know where the aux are for it. For procedures,
1635 parsing of the PDRs has already provided all the needed
1636 information, we only parse them if SKIP_PROCEDURES is false,
1637 and only if this causes no symbol duplication.
1638 BIGEND says whether aux entries are big-endian or little-endian.
1640 This routine clobbers top_stack->cur_block and ->cur_st. */
1643 parse_external(es
, skip_procedures
, bigend
)
1645 int skip_procedures
;
1650 if (es
->ifd
!= ifdNil
) {
1652 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
) + cur_fd
;
1653 ax
= (union aux_ext
*)cur_fdr
->iauxBase
;
1655 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
);
1658 top_stack
->cur_st
= cur_stab
;
1659 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
1662 /* Reading .o files */
1663 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
) {
1665 switch (es
->asym
.st
) {
1667 case stProc
: what
= "procedure"; n_undef_procs
++; break;
1668 case stGlobal
: what
= "variable"; n_undef_vars
++; break;
1669 case stLabel
: what
= "label"; n_undef_labels
++; break;
1670 default : what
= "symbol"; break;
1674 printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what
,
1675 es
->asym
.iss
, fdr_name(cur_fdr
->rss
));
1679 switch (es
->asym
.st
) {
1681 /* If we have full symbols we do not need more */
1682 if (skip_procedures
)
1684 if (mylookup_symbol (es
->asym
.iss
, top_stack
->cur_block
,
1685 VAR_NAMESPACE
, LOC_BLOCK
))
1691 * Note that the case of a symbol with indexNil
1692 * must be handled anyways by parse_symbol().
1694 parse_symbol(&es
->asym
, ax
, bigend
);
1701 /* Parse the line number info for file descriptor FH into
1702 GDB's linetable LT. MIPS' encoding requires a little bit
1703 of magic to get things out. Note also that MIPS' line
1704 numbers can go back and forth, apparently we can live
1705 with that and do not need to reorder our linetables */
1710 struct linetable
*lt
;
1712 unsigned char *base
= (unsigned char*)fh
->cbLineOffset
;
1714 int delta
, count
, lineno
= 0;
1720 /* Scan by procedure descriptors */
1721 i
= 0; j
= 0, k
= 0;
1722 for (pr
= (PDR
*)IPDFIRST(cur_hdr
,fh
); j
< fh
->cpd
; j
++, pr
++) {
1725 /* No code for this one */
1726 if (pr
->iline
== ilineNil
||
1727 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1730 * Aurgh! To know where to stop expanding we
1733 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1734 if (pr
[l
].iline
!= -1)
1736 if (l
== (fh
->cpd
- j
))
1741 * When procedures are moved around the linenumbers
1742 * are attributed to the next procedure up
1744 if (pr
->iline
>= halt
) continue;
1746 base
= (unsigned char*)pr
->cbLineOffset
;
1747 l
= pr
->adr
>> 2; /* in words */
1748 halt
+= (pr
->adr
>> 2) - pr
->iline
;
1749 for (lineno
= pr
->lnLow
; l
< halt
;) {
1750 count
= *base
& 0x0f;
1751 delta
= *base
++ >> 4;
1755 delta
= (base
[0] << 8) | base
[1];
1756 if (delta
>= 0x8000)
1760 lineno
+= delta
;/* first delta is 0 */
1761 k
= add_line(lt
, lineno
, l
, k
);
1768 /* Master parsing procedure for first-pass reading of file symbols
1769 into a partial_symtab.
1771 Parses the symtab described by the global symbolic header CUR_HDR.
1772 END_OF_TEXT_SEG gives the address just after the text segment for
1773 the symtab we are reading. */
1776 parse_partial_symbols(end_of_text_seg
, objfile
)
1777 int end_of_text_seg
;
1778 struct objfile
*objfile
;
1781 /* int stat_idx, h_max;*/
1782 HDRR
*hdr
= cur_hdr
;
1783 /* 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
; ) {
1969 register struct partial_symbol
*p
;
1972 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
1974 if (MIPS_IS_STAB(sh
)) {
1979 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
1980 sh
->index
== 0xfffff) {
1981 /* FIXME, premature? */
1986 name
= (char *)(sh
->iss
);
1991 case stProc
: /* Asm labels apparently */
1992 case stStaticProc
: /* Function */
1993 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
1994 VAR_NAMESPACE
, LOC_BLOCK
,
1995 objfile
->static_psymbols
, sh
->value
);
1996 /* Skip over procedure to next one. */
1997 cur_sdx
= AUX_GET_ISYM (fh
->fBigendian
,
1998 sh
->index
+ (union aux_ext
*)fh
->iauxBase
);
1999 procaddr
= sh
->value
;
2001 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
- 1;
2002 if (sh
->st
!= stEnd
)
2004 high
= procaddr
+ sh
->value
;
2005 if (high
> pst
->texthigh
)
2006 pst
->texthigh
= high
;
2008 case stStatic
: /* Variable */
2011 case stTypedef
: /* Typedef */
2012 class = LOC_TYPEDEF
;
2014 case stConstant
: /* Constant decl */
2017 case stBlock
: /* { }, str, un, enum*/
2018 if (sh
->sc
== scInfo
) {
2019 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
2020 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2021 objfile
->static_psymbols
, sh
->value
);
2023 /* Skip over the block */
2024 cur_sdx
= sh
->index
;
2026 case stFile
: /* File headers */
2027 case stLabel
: /* Labels */
2028 case stEnd
: /* Ends of files */
2031 complain (&unknown_sym_complaint
, SYMBOL_NAME(p
));
2032 complain (&unknown_st_complaint
, sh
->st
);
2036 /* Use this gdb symbol */
2037 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
2038 VAR_NAMESPACE
, class,
2039 objfile
->static_psymbols
, sh
->value
);
2041 cur_sdx
++; /* Go to next file symbol */
2044 /* Now do enter the external symbols. */
2045 ext_ptr
= &extern_tab
[fdr_to_pst
[f_idx
].globals_offset
];
2046 cur_sdx
= fdr_to_pst
[f_idx
].n_globals
;
2047 PST_PRIVATE(save_pst
)->extern_count
= cur_sdx
;
2048 PST_PRIVATE(save_pst
)->extern_tab
= ext_ptr
;
2049 for (; --cur_sdx
>= 0; ext_ptr
++) {
2050 enum address_class
class;
2051 if ((*ext_ptr
)->ifd
!= f_idx
)
2053 sh
= &(*ext_ptr
)->asym
;
2062 complain (&unknown_ext_complaint
, sh
->iss
);
2067 if (objfile
->global_psymbols
.next
>=
2068 objfile
->global_psymbols
.list
+ objfile
->global_psymbols
.size
)
2069 extend_psymbol_list (&objfile
->global_psymbols
, objfile
);
2070 psym
= objfile
->global_psymbols
.next
++;
2071 SYMBOL_NAME (psym
) = (char*)sh
->iss
;
2072 SYMBOL_NAMESPACE (psym
) = VAR_NAMESPACE
;
2073 SYMBOL_CLASS (psym
) = class;
2074 SYMBOL_VALUE_ADDRESS (psym
) = (CORE_ADDR
)sh
->value
;
2078 end_psymtab (save_pst
, psymtab_include_list
, includes_used
,
2079 -1, save_pst
->texthigh
,
2080 dependency_list
, dependencies_used
);
2081 if (entry_point
< save_pst
->texthigh
2082 && entry_point
>= save_pst
->textlow
) {
2083 startup_file_start
= save_pst
->textlow
;
2084 startup_file_end
= save_pst
->texthigh
;
2088 /* Mark the last code address, and remember it for later */
2089 hdr
->cbDnOffset
= end_of_text_seg
;
2091 /* Now scan the FDRs for dependencies */
2092 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
2094 fh
= f_idx
+ (FDR
*)(cur_hdr
->cbFdOffset
);
2095 pst
= fdr_to_pst
[f_idx
].pst
;
2097 /* This should catch stabs-in-ecoff. */
2101 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
2102 /* ...then presumably a .h file: drop reverse depends .h->.c */
2103 for (; s_id0
< fh
->crfd
; s_id0
++) {
2104 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
2106 s_id0
++; /* Skip self-dependency */
2111 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2112 pst
->dependencies
= (struct partial_symtab
**)
2113 obstack_alloc (&objfile
->psymbol_obstack
,
2114 pst
->number_of_dependencies
*
2115 sizeof (struct partial_symtab
*));
2116 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
2117 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
2118 if (*rh
< 0 || *rh
>= hdr
->ifdMax
)
2119 complain(&bad_file_number_complaint
, *rh
);
2121 pst
->dependencies
[s_idx
-s_id0
] = fdr_to_pst
[*rh
].pst
;
2124 do_cleanups (old_chain
);
2129 /* Do the initial analisys of the F_IDX-th file descriptor.
2130 Allocates a partial symtab for it, and builds the list
2131 of dependent files by recursion. LEV says at which level
2132 of recursion we are called (to pretty up debug traces) */
2134 static struct partial_symtab
*
2135 parse_fdr(f_idx
, lev
, objfile
)
2138 struct objfile
*objfile
;
2141 register struct partial_symtab
*pst
;
2144 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + f_idx
;
2146 /* Use this to indicate into which symtab this file was parsed */
2148 return (struct partial_symtab
*) fh
->ioptBase
;
2150 /* Debuggability level */
2151 if (compare_glevel(max_glevel
, fh
->glevel
) < 0)
2152 max_glevel
= fh
->glevel
;
2154 /* Make a new partial_symtab */
2155 pst
= new_psymtab(fh
->rss
, objfile
);
2160 pst
->textlow
= fh
->adr
;
2161 pst
->texthigh
= fh
->cpd
; /* To be fixed later */
2164 /* Make everything point to everything. */
2165 FDR_IDX(pst
) = f_idx
;
2166 fdr_to_pst
[f_idx
].pst
= pst
;
2167 fh
->ioptBase
= (int)pst
;
2169 /* Analyze its dependencies */
2174 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
2175 /* ...then presumably a .h file: drop reverse depends .h->.c */
2176 for (; s_id0
< fh
->crfd
; s_id0
++) {
2177 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
2179 s_id0
++; /* Skip self-dependency */
2184 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2185 pst
->dependencies
= (struct partial_symtab
**)
2186 obstack_alloc (&objfile
->psymbol_obstack
,
2187 pst
->number_of_dependencies
*
2188 sizeof (struct partial_symtab
*));
2189 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
2190 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
2192 pst
->dependencies
[s_idx
-s_id0
] = parse_fdr(*rh
, lev
+1, objfile
);
2200 mips_next_symbol_text ()
2203 return (char*)((SYMR
*)cur_fdr
->isymBase
)[cur_sdx
].iss
;
2206 /* Ancillary function to psymtab_to_symtab(). Does all the work
2207 for turning the partial symtab PST into a symtab, recurring
2208 first on all dependent psymtabs. The argument FILENAME is
2209 only passed so we can see in debug stack traces what file
2213 psymtab_to_symtab_1(pst
, filename
)
2214 struct partial_symtab
*pst
;
2222 struct linetable
*lines
;
2228 /* How many symbols will we need */
2229 /* FIXME, this does not count enum values. */
2230 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
2231 if (FDR_IDX(pst
) == -1) {
2235 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + FDR_IDX(pst
);
2236 f_max
+= fh
->csym
+ fh
->cpd
;
2237 maxlines
= 2 * fh
->cline
;
2240 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2243 && strcmp((char *)(((SYMR
*)fh
->isymBase
)[1].iss
), stabs_symbol
)
2248 st
= new_symtab (pst
->filename
, 2 * f_max
, maxlines
,
2251 st
= new_symtab ("unknown", f_max
, 0, pst
->objfile
);
2252 lines
= LINETABLE(st
);
2253 pending_list
= (struct mips_pending
**) cur_hdr
->cbOptOffset
;
2254 if (pending_list
== 0) {
2255 pending_list
= (struct mips_pending
**)
2256 xzalloc(cur_hdr
->ifdMax
* sizeof(struct mips_pending
*));
2257 cur_hdr
->cbOptOffset
= (int)pending_list
;
2261 /* Read in all partial symbtabs on which this one is dependent.
2262 NOTE that we do have circular dependencies, sigh. We solved
2263 that by setting pst->readin before this point. */
2265 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2266 if (!pst
->dependencies
[i
]->readin
) {
2267 /* Inform about additional files to be read in. */
2270 fputs_filtered (" ", stdout
);
2272 fputs_filtered ("and ", stdout
);
2274 printf_filtered ("%s...",
2275 pst
->dependencies
[i
]->filename
);
2276 wrap_here (""); /* Flush output */
2279 /* We only pass the filename for debug purposes */
2280 psymtab_to_symtab_1(pst
->dependencies
[i
],
2281 pst
->dependencies
[i
]->filename
);
2285 /* Now read the symbols for this symtab */
2287 current_objfile
= pst
-> objfile
;
2289 cur_fd
= FDR_IDX(pst
);
2292 /* Get a new lexical context */
2295 top_stack
->cur_st
= cur_stab
;
2296 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab
),
2298 BLOCK_START(top_stack
->cur_block
) = fh
? fh
->adr
: 0;
2299 BLOCK_END(top_stack
->cur_block
) = 0;
2300 top_stack
->blocktype
= stFile
;
2301 top_stack
->maxsyms
= 2*f_max
;
2302 top_stack
->cur_type
= 0;
2303 top_stack
->procadr
= 0;
2304 top_stack
->numargs
= 0;
2307 /* Parse locals and procedures */
2312 char *fh_name
= (char*)fh
->rss
;
2314 /* Parse local symbols first */
2320 current_objfile
= NULL
;
2323 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++) {
2324 register SYMR
*sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
2325 char *name
= (char*)sh
->iss
;
2326 CORE_ADDR valu
= sh
->value
;
2327 if (MIPS_IS_STAB(sh
)) {
2328 int type_code
= MIPS_UNMARK_STAB(sh
->index
);
2329 process_one_symbol (type_code
, 0, valu
, name
, /*FIXME*/ 0);
2331 else if (sh
->st
== stLabel
&& sh
->index
!= indexNil
) {
2332 /* Handle encoded stab line number. */
2333 record_line (current_subfile
, sh
->index
, valu
);
2336 st
= end_symtab (pst
->texthigh
, 0, 0, pst
->objfile
);
2339 /* BOUND is the highest core address of this file's procedures */
2340 int bound
= cur_fd
== cur_hdr
->ifdMax
- 1 ? cur_hdr
->cbDnOffset
2342 for (cur_sdx
= 0; cur_sdx
< fh
->csym
; ) {
2343 sh
= (SYMR
*) (fh
->isymBase
) + cur_sdx
;
2344 cur_sdx
+= parse_symbol(sh
, fh
->iauxBase
, fh
->fBigendian
);
2347 /* Procedures next, note we need to look-ahead to
2348 find out where the procedure's code ends */
2351 for (i
= 0; i
< fh
->cpd
-1; i
++) {
2352 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2353 parse_procedure(pr
, pr
[1].adr
); /* next proc up */
2356 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2357 parse_procedure(pr
, bound
); /* next file up */
2359 /* Linenumbers. At the end, check if we can save memory */
2360 parse_lines(fh
, lines
);
2361 if (lines
->nitems
< fh
->cline
)
2362 lines
= shrink_linetable(lines
);
2368 LINETABLE(st
) = lines
;
2370 /* .. and our share of externals.
2371 XXX use the global list to speed up things here. how ?
2372 FIXME, Maybe quit once we have found the right number of ext's? */
2373 /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
2374 top_stack
->blocktype
= stFile
;
2375 top_stack
->maxsyms
=
2376 cur_hdr
->isymMax
+ cur_hdr
->ipdMax
+ cur_hdr
->iextMax
;
2378 ext_ptr
= PST_PRIVATE(pst
)->extern_tab
;
2379 for (i
= PST_PRIVATE(pst
)->extern_count
; --i
>= 0; ext_ptr
++)
2380 parse_external(*ext_ptr
, 1, fh
->fBigendian
);
2382 /* If there are undefined, tell the user */
2383 if (n_undef_symbols
) {
2384 printf_filtered("File %s contains %d unresolved references:",
2385 st
->filename
, n_undef_symbols
);
2386 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2387 n_undef_vars
, n_undef_procs
, n_undef_labels
);
2388 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
2394 /* Sort the symbol table now, we are done adding symbols to it.*/
2395 sort_symtab_syms(st
);
2399 /* Now link the psymtab and the symtab. */
2402 current_objfile
= NULL
;
2405 /* Ancillary parsing procedures. */
2407 /* Lookup the type at relative index RN. Return it in TPP
2408 if found and in any event come up with its name PNAME.
2409 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
2410 Return value says how many aux symbols we ate. */
2413 cross_ref(ax
, tpp
, type_code
, pname
, bigend
)
2416 int type_code
; /* Use to alloc new type if none is found. */
2424 ecoff_swap_rndx_in (bigend
, ax
, rn
);
2426 /* Escape index means 'the next one' */
2427 if (rn
->rfd
== 0xfff) {
2429 rf
= AUX_GET_ISYM (bigend
, ax
+ 1);
2436 *pname
= "<undefined>";
2439 * Find the relative file descriptor and the symbol in it
2441 FDR
*fh
= get_rfd(cur_fd
, rf
);
2446 * If we have processed this symbol then we left a forwarding
2447 * pointer to the corresponding GDB symbol. If not, we`ll put
2448 * it in a list of pending symbols, to be processed later when
2449 * the file f will be. In any event, we collect the name for
2450 * the type here. Which is why we made a first pass at
2453 sh
= (SYMR
*) (fh
->isymBase
) + rn
->index
;
2455 /* Careful, we might be looking at .o files */
2456 *pname
= (UNSAFE_DATA_ADDR(sh
->iss
)) ? "<undefined>" :
2459 /* Have we parsed it ? */
2460 if ((!UNSAFE_DATA_ADDR(sh
->value
)) && (sh
->st
== stParsed
)) {
2461 t
= (struct type
*) sh
->value
;
2464 /* Avoid duplicates */
2465 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
2469 *tpp
= init_type(type_code
, 0, 0, 0, (struct objfile
*) NULL
);
2470 add_pending(fh
, sh
, *tpp
);
2475 /* We used one auxent normally, two if we got a "next one" rf. */
2480 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2481 keeping the symtab sorted */
2483 static struct symbol
*
2484 mylookup_symbol (name
, block
, namespace, class)
2486 register struct block
*block
;
2487 enum namespace namespace;
2488 enum address_class
class;
2490 register int bot
, top
, inc
;
2491 register struct symbol
*sym
;
2494 top
= BLOCK_NSYMS(block
);
2497 sym
= BLOCK_SYM(block
, bot
);
2498 if (SYMBOL_NAME(sym
)[0] == inc
2499 && SYMBOL_NAMESPACE(sym
) == namespace
2500 && SYMBOL_CLASS(sym
) == class
2501 && !strcmp(SYMBOL_NAME(sym
), name
))
2505 if (block
= BLOCK_SUPERBLOCK (block
))
2506 return mylookup_symbol (name
, block
, namespace, class);
2511 /* Add a new symbol S to a block B.
2512 Infrequently, we will need to reallocate the block to make it bigger.
2513 We only detect this case when adding to top_stack->cur_block, since
2514 that's the only time we know how big the block is. FIXME. */
2521 int nsyms
= BLOCK_NSYMS(b
)++;
2522 struct block
*origb
;
2523 struct parse_stack
*stackp
;
2525 if (b
== top_stack
->cur_block
&&
2526 nsyms
>= top_stack
->maxsyms
) {
2527 complain (&block_overflow_complaint
, s
->name
);
2528 /* In this case shrink_block is actually grow_block, since
2529 BLOCK_NSYMS(b) is larger than its current size. */
2531 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
2533 /* Now run through the stack replacing pointers to the
2534 original block. shrink_block has already done this
2535 for the blockvector and BLOCK_FUNCTION. */
2536 for (stackp
= top_stack
; stackp
; stackp
= stackp
->next
) {
2537 if (stackp
->cur_block
== origb
) {
2538 stackp
->cur_block
= b
;
2539 stackp
->maxsyms
= BLOCK_NSYMS (b
);
2543 BLOCK_SYM(b
,nsyms
) = s
;
2546 /* Add a new block B to a symtab S */
2553 struct blockvector
*bv
= BLOCKVECTOR(s
);
2555 bv
= (struct blockvector
*)xrealloc((char *) bv
,
2556 sizeof(struct blockvector
) +
2557 BLOCKVECTOR_NBLOCKS(bv
)
2558 * sizeof(bv
->block
));
2559 if (bv
!= BLOCKVECTOR(s
))
2560 BLOCKVECTOR(s
) = bv
;
2562 BLOCKVECTOR_BLOCK(bv
, BLOCKVECTOR_NBLOCKS(bv
)++) = b
;
2565 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2566 MIPS' linenumber encoding might need more than one byte
2567 to describe it, LAST is used to detect these continuation lines */
2570 add_line(lt
, lineno
, adr
, last
)
2571 struct linetable
*lt
;
2577 last
= -2; /* make sure we record first line */
2579 if (last
== lineno
) /* skip continuation lines */
2582 lt
->item
[lt
->nitems
].line
= lineno
;
2583 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
2589 /* Comparison functions, used when sorting things */
2591 /* Symtabs must be ordered viz the code segments they cover */
2594 compare_symtabs( s1
, s2
)
2595 struct symtab
**s1
, **s2
;
2597 /* "most specific" first */
2599 register struct block
*b1
, *b2
;
2600 b1
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1
),GLOBAL_BLOCK
);
2601 b2
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2
),GLOBAL_BLOCK
);
2602 if (BLOCK_END(b1
) == BLOCK_END(b2
))
2603 return BLOCK_START(b1
) - BLOCK_START(b2
);
2604 return BLOCK_END(b1
) - BLOCK_END(b2
);
2608 /* Partial Symtabs, same */
2611 compare_psymtabs( s1
, s2
)
2612 struct partial_symtab
**s1
, **s2
;
2614 /* Perf twist: put the ones with no code at the end */
2616 register int a
= (*s1
)->textlow
;
2617 register int b
= (*s2
)->textlow
;
2626 /* Blocks with a smaller low bound should come first */
2628 static int compare_blocks(b1
,b2
)
2629 struct block
**b1
, **b2
;
2631 register int addr_diff
;
2633 addr_diff
= (BLOCK_START((*b1
))) - (BLOCK_START((*b2
)));
2635 return (BLOCK_END((*b1
))) - (BLOCK_END((*b2
)));
2640 /* Sorting and reordering procedures */
2642 /* Sort the blocks of a symtab S.
2643 Reorder the blocks in the blockvector by code-address,
2644 as required by some MI search routines */
2650 struct blockvector
*bv
= BLOCKVECTOR(s
);
2652 if (BLOCKVECTOR_NBLOCKS(bv
) <= 2) {
2654 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) == 0)
2655 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = 0;
2656 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) == 0)
2657 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) = 0;
2661 * This is very unfortunate: normally all functions are compiled in
2662 * the order they are found, but if the file is compiled -O3 things
2663 * are very different. It would be nice to find a reliable test
2664 * to detect -O3 images in advance.
2666 if (BLOCKVECTOR_NBLOCKS(bv
) > 3)
2667 qsort(&BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
),
2668 BLOCKVECTOR_NBLOCKS(bv
) - FIRST_LOCAL_BLOCK
,
2669 sizeof(struct block
*),
2673 register CORE_ADDR high
= 0;
2674 register int i
, j
= BLOCKVECTOR_NBLOCKS(bv
);
2676 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
2677 if (high
< BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
)))
2678 high
= BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
));
2679 BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = high
;
2682 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) =
2683 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
));
2685 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2686 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2687 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2688 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2692 /* Constructor/restructor/destructor procedures */
2694 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2695 MAXSYMS and linenumbers MAXLINES we'll put in it */
2699 new_symtab(name
, maxsyms
, maxlines
, objfile
)
2703 struct objfile
*objfile
;
2705 struct symtab
*s
= allocate_symtab (name
, objfile
);
2707 LINETABLE(s
) = new_linetable(maxlines
);
2709 /* All symtabs must have at least two blocks */
2710 BLOCKVECTOR(s
) = new_bvect(2);
2711 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
) = new_block(maxsyms
);
2712 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), STATIC_BLOCK
) = new_block(maxsyms
);
2713 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
),STATIC_BLOCK
)) =
2714 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
);
2716 s
->free_code
= free_linetable
;
2721 /* Allocate a new partial_symtab NAME */
2723 static struct partial_symtab
*
2724 new_psymtab(name
, objfile
)
2726 struct objfile
*objfile
;
2728 struct partial_symtab
*psymtab
;
2730 /* FIXME -- why (char *) -1 rather than NULL? */
2731 psymtab
= allocate_psymtab (name
== (char *) -1 ? "<no name>" : name
,
2734 /* Keep a backpointer to the file's symbols */
2736 psymtab
-> read_symtab_private
= (char *)
2737 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
2738 CUR_HDR(psymtab
) = cur_hdr
;
2740 /* The way to turn this into a symtab is to call... */
2741 psymtab
->read_symtab
= mipscoff_psymtab_to_symtab
;
2746 /* Allocate a linetable array of the given SIZE */
2748 static struct linetable
*
2751 struct linetable
*l
;
2753 size
= size
* sizeof(l
->item
) + sizeof(struct linetable
);
2754 l
= (struct linetable
*)xmalloc(size
);
2759 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2760 I am not so sure about the 3.4 ones */
2762 static struct linetable
*
2763 shrink_linetable(lt
)
2764 struct linetable
* lt
;
2766 struct linetable
*l
= new_linetable(lt
->nitems
);
2768 memcpy(l
, lt
, lt
->nitems
* sizeof(l
->item
) + sizeof(struct linetable
));
2773 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2776 struct blockvector
*
2779 struct blockvector
*bv
;
2782 size
= sizeof(struct blockvector
) + nblocks
* sizeof(struct block
*);
2783 bv
= (struct blockvector
*) xzalloc(size
);
2785 BLOCKVECTOR_NBLOCKS(bv
) = nblocks
;
2790 /* Allocate and zero a new block of MAXSYMS symbols */
2796 int size
= sizeof(struct block
) + (maxsyms
-1) * sizeof(struct symbol
*);
2797 struct block
*b
= (struct block
*)xzalloc(size
);
2802 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2803 Shrink_block can also be used by add_symbol to grow a block. */
2805 static struct block
*
2811 struct blockvector
*bv
= BLOCKVECTOR(s
);
2814 /* Just reallocate it and fix references to the old one */
2816 new = (struct block
*) xrealloc ((char *)b
, sizeof(struct block
) +
2817 (BLOCK_NSYMS(b
)-1) * sizeof(struct symbol
*));
2819 /* Should chase pointers to old one. Fortunately, that`s just
2820 the block`s function and inferior blocks */
2821 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b
)
2822 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2823 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2824 if (BLOCKVECTOR_BLOCK(bv
,i
) == b
)
2825 BLOCKVECTOR_BLOCK(bv
,i
) = new;
2826 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) == b
)
2827 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) = new;
2831 /* Create a new symbol with printname NAME */
2838 struct symbol
*s
= (struct symbol
*)
2839 obstack_alloc (¤t_objfile
->symbol_obstack
, sizeof (struct symbol
));
2841 memset (s
, 0, sizeof (*s
));
2842 SYMBOL_NAME(s
) = name
;
2846 /* Create a new type with printname NAME */
2855 t
= alloc_type (current_objfile
);
2856 TYPE_NAME(t
) = name
;
2857 TYPE_CPLUS_SPECIFIC(t
) = (struct cplus_struct_type
*)
2858 &cplus_struct_default
;
2863 /* Things used for calling functions in the inferior.
2864 These functions are exported to our companion
2865 mips-tdep.c file and are here because they play
2866 with the symbol-table explicitly. */
2868 /* Sigtramp: make sure we have all the necessary information
2869 about the signal trampoline code. Since the official code
2870 from MIPS does not do so, we make up that information ourselves.
2871 If they fix the library (unlikely) this code will neutralize itself. */
2878 struct block
*b
, *b0
;
2880 sigtramp_address
= -1;
2882 /* We know it is sold as sigvec */
2883 s
= lookup_symbol("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
2885 /* Most programs do not play with signals */
2889 b0
= SYMBOL_BLOCK_VALUE(s
);
2891 /* A label of sigvec, to be more precise */
2892 s
= lookup_symbol("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
2894 /* But maybe this program uses its own version of sigvec */
2898 sigtramp_address
= SYMBOL_VALUE(s
);
2899 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
2901 /* Did we or MIPSco fix the library ? */
2902 if (SYMBOL_CLASS(s
) == LOC_BLOCK
)
2905 /* But what symtab does it live in ? */
2906 st
= find_pc_symtab(SYMBOL_VALUE(s
));
2909 * Ok, there goes the fix: turn it into a procedure, with all the
2910 * needed info. Note we make it a nested procedure of sigvec,
2911 * which is the way the (assembly) code is actually written.
2913 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2914 SYMBOL_CLASS(s
) = LOC_BLOCK
;
2915 SYMBOL_TYPE(s
) = init_type(TYPE_CODE_FUNC
, 4, 0, 0, (struct objfile
*) NULL
);
2916 TYPE_TARGET_TYPE(SYMBOL_TYPE(s
)) = builtin_type_void
;
2918 /* Need a block to allocate .gdbinfo. in */
2920 SYMBOL_BLOCK_VALUE(s
) = b
;
2921 BLOCK_START(b
) = sigtramp_address
;
2922 BLOCK_END(b
) = sigtramp_end
;
2923 BLOCK_FUNCTION(b
) = s
;
2924 BLOCK_SUPERBLOCK(b
) = BLOCK_SUPERBLOCK(b0
);
2928 /* Make a .gdbinfo. for it */
2930 struct mips_extra_func_info
*e
=
2931 (struct mips_extra_func_info
*)
2932 xzalloc(sizeof(struct mips_extra_func_info
));
2934 e
->numargs
= 0; /* the kernel thinks otherwise */
2935 /* align_longword(sigcontext + SIGFRAME) */
2936 e
->framesize
= 0x150;
2937 e
->framereg
= SP_REGNUM
;
2940 e
->regoffset
= -(41 * sizeof(int));
2942 e
->fregoffset
= -(37 * sizeof(int));
2945 s
= new_symbol(".gdbinfo.");
2946 SYMBOL_VALUE(s
) = (int) e
;
2947 SYMBOL_NAMESPACE(s
) = LABEL_NAMESPACE
;
2948 SYMBOL_CLASS(s
) = LOC_CONST
;
2949 SYMBOL_TYPE(s
) = builtin_type_void
;
2952 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
2955 /* Initialization */
2957 static struct sym_fns ecoff_sym_fns
= {"ecoff", 5,
2958 mipscoff_new_init
, mipscoff_symfile_init
,
2959 mipscoff_symfile_read
};
2961 _initialize_mipsread ()
2963 add_symtab_fns (&ecoff_sym_fns
);
2965 /* Missing basic types */
2966 builtin_type_string
=
2967 init_type (TYPE_CODE_PASCAL_ARRAY
,
2969 (struct objfile
*) NULL
);
2970 builtin_type_complex
=
2971 init_type(TYPE_CODE_FLT
,
2972 2 * sizeof(float), 0, "complex",
2973 (struct objfile
*) NULL
);
2974 builtin_type_double_complex
=
2975 init_type(TYPE_CODE_FLT
,
2976 2 * sizeof(double), 0, "double_complex",
2977 (struct objfile
*) NULL
);
2978 builtin_type_fixed_dec
=
2979 init_type(TYPE_CODE_INT
, sizeof(int),
2981 (struct objfile
*) NULL
);
2982 builtin_type_float_dec
=
2983 init_type(TYPE_CODE_FLT
, sizeof(double),
2984 0, "floating_decimal",
2985 (struct objfile
*) NULL
);