1 /* Read a symbol table in MIPS' format (Third-Eye).
2 Copyright 1986, 1987, 1989, 1990, 1991 Free Software Foundation, Inc.
3 Contributed by Alessandro Forin (af@cs.cmu.edu) at CMU.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This module provides three functions: mipscoff_symfile_init,
22 which initializes to read a symbol file; mipscoff_new_init, which
23 discards existing cached information when all symbols are being
24 discarded; and mipscoff_symfile_read, which reads a symbol table
27 mipscoff_symfile_read only does the minimum work necessary for letting the
28 user "name" things symbolically; it does not read the entire symtab.
29 Instead, it reads the external and static symbols and puts them in partial
30 symbol tables. When more extensive information is requested of a
31 file, the corresponding partial symbol table is mutated into a full
32 fledged symbol table by going back and reading the symbols
33 for real. mipscoff_psymtab_to_symtab() is called indirectly through
34 a pointer in the psymtab to do this. */
43 #include <sys/param.h>
47 #include <mips/syms.h>
51 #endif /* not CMUCS */
53 #include "coff/mips.h"
54 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
55 #include "aout/aout64.h"
56 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native, now */
59 struct external_filehdr f
;
60 struct external_aouthdr a
;
63 /* These must match the corresponding definition in mips-tfile.c.
64 At some point, these should probably go into an include file,
65 but currently gcc does use/need the ../include directory. */
67 #define CODE_MASK 0x8F300
68 #define MIPS_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK)
69 #define MIPS_MARK_STAB(code) ((code)+CODE_MASK)
70 #define MIPS_UNMARK_STAB(code) ((code)-CODE_MASK)
71 #define STABS_SYMBOL "@stabs"
73 /* Each partial symbol table entry contains a pointer to private data for the
74 read_symtab() function to use when expanding a partial symbol table entry
75 to a full symbol table entry.
77 For mipsread this structure contains the index of the FDR that this psymtab
78 represents and a pointer to the symbol table header HDRR from the symbol
79 file that the psymtab was created from. */
81 #define FDR_IDX(p) (((struct symloc *)((p)->read_symtab_private))->fdr_idx)
82 #define CUR_HDR(p) (((struct symloc *)((p)->read_symtab_private))->cur_hdr)
89 /* Things we import explicitly from other modules */
91 extern int info_verbose
;
92 extern struct block
*block_for_pc();
93 extern void sort_symtab_syms();
95 /* Various complaints about symbol reading that don't abort the process */
97 struct complaint unknown_ext_complaint
=
98 {"unknown external symbol %s", 0, 0};
100 struct complaint unknown_sym_complaint
=
101 {"unknown local symbol %s", 0, 0};
103 struct complaint unknown_st_complaint
=
104 {"with type %d", 0, 0};
106 struct complaint block_overflow_complaint
=
107 {"block containing %s overfilled", 0, 0};
109 struct complaint basic_type_complaint
=
110 {"cannot map MIPS basic type 0x%x", 0, 0};
112 struct complaint unknown_type_qual_complaint
=
113 {"unknown type qualifier 0x%x", 0, 0};
115 struct complaint array_bitsize_complaint
=
116 {"size of array target type not known, assuming %d bits", 0, 0};
118 struct complaint array_parse_complaint
=
119 {"array type with strange relative symbol", 0, 0};
121 struct complaint bad_tag_guess_complaint
=
122 {"guessed tag type incorrectly", 0, 0};
124 /* Macros and extra defs */
126 /* Already-parsed symbols are marked specially */
128 #define stParsed stType
130 /* Puns: hard to find whether -g was used and how */
132 #define MIN_GLEVEL GLEVEL_0
133 #define compare_glevel(a,b) \
134 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
135 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
137 /* When looking at .o files, avoid tripping over bad addresses */
139 #define SAFE_TEXT_ADDR 0x400000
140 #define SAFE_DATA_ADDR 0x10000000
142 #define UNSAFE_DATA_ADDR(p) ((unsigned)p < SAFE_DATA_ADDR || (unsigned)p > 2*SAFE_DATA_ADDR)
144 /* Things that really are local to this module */
146 /* GDB symtable for the current compilation unit */
148 static struct symtab
*cur_stab
;
150 /* MIPS symtab header for the current file */
152 static HDRR
*cur_hdr
;
154 /* Pointer to current file decriptor record, and its index */
159 /* Index of current symbol */
163 /* Note how much "debuggable" this image is. We would like
164 to see at least one FDR with full symbols */
169 /* When examining .o files, report on undefined symbols */
171 static int n_undef_symbols
, n_undef_labels
, n_undef_vars
, n_undef_procs
;
173 /* Pseudo symbol to use when putting stabs into the symbol table. */
175 static char stabs_symbol
[] = STABS_SYMBOL
;
177 /* Extra builtin types */
179 struct type
*builtin_type_complex
;
180 struct type
*builtin_type_double_complex
;
181 struct type
*builtin_type_fixed_dec
;
182 struct type
*builtin_type_float_dec
;
183 struct type
*builtin_type_string
;
185 /* Forward declarations */
187 static struct symbol
*new_symbol();
188 static struct type
*new_type();
189 static struct block
*new_block();
190 static struct symtab
*new_symtab();
191 static struct linetable
*new_linetable();
192 static struct blockvector
*new_bvect();
194 static struct type
*parse_type();
195 static struct type
*make_type();
196 static struct symbol
*mylookup_symbol();
197 static struct block
*shrink_block();
198 static void sort_blocks();
200 static int compare_symtabs();
201 static int compare_psymtabs();
202 static int compare_blocks();
204 static struct partial_symtab
*new_psymtab();
205 static struct partial_symtab
*parse_fdr();
206 static int compare_psymbols();
208 static void psymtab_to_symtab_1();
209 static void add_block();
210 static void add_symbol();
211 static int add_line();
212 static struct linetable
*shrink_linetable();
213 static char* mips_next_symbol_text ();
216 /* Things we export to other modules */
218 /* Address bounds for the signal trampoline in inferior, if any */
219 /* FIXME: Nothing really seems to use this. Why is it here? */
221 CORE_ADDR sigtramp_address
, sigtramp_end
;
223 /* The entry point (starting address) of the file, if it is an executable. */
225 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
226 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
231 /* If we have a file symbol header lying around, blow it away. */
233 free ((char *)cur_hdr
);
238 mipscoff_symfile_init (sf
)
241 sf
->sym_private
= NULL
;
245 mipscoff_symfile_read(sf
, addr
, mainline
)
250 struct coff_symfile_info
*info
= (struct coff_symfile_info
*)sf
->sym_private
;
251 bfd
*abfd
= sf
->objfile
->obfd
;
252 char *name
= bfd_get_filename (abfd
);
256 int stringtab_offset
;
258 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
259 desc
= fileno ((FILE *)(abfd
->iostream
)); /* Raw file descriptor */
262 /* Position to read the symbol table. */
263 val
= lseek (desc
, (long)symtab_offset
, 0);
265 perror_with_name (name
);
267 init_misc_bunches ();
268 make_cleanup (discard_misc_bunches
, 0);
270 /* Now that the executable file is positioned at symbol table,
271 process it and define symbols accordingly. */
273 read_mips_symtab(sf
->objfile
, desc
);
275 /* Go over the misc symbol bunches and install them in vector. */
277 condense_misc_bunches (!mainline
);
280 /* Exported procedure: Allocate zeroed memory */
285 char *p
= xmalloc(size
);
291 /* Exported procedure: Builds a symtab from the PST partial one.
292 Restores the environment in effect when PST was created, delegates
293 most of the work to an ancillary procedure, and sorts
294 and reorders the symtab list at the end */
297 mipscoff_psymtab_to_symtab(pst
)
298 struct partial_symtab
*pst
;
307 printf_filtered("Reading in symbols for %s...", pst
->filename
);
310 /* Restore the header and list of pending typedefs */
311 cur_hdr
= CUR_HDR(pst
);
313 next_symbol_text_func
= mips_next_symbol_text
;
315 psymtab_to_symtab_1(pst
, pst
->filename
);
317 /* Match with global symbols. This only needs to be done once,
318 after all of the symtabs and dependencies have been read in. */
319 scan_file_globals ();
322 printf_filtered("done.\n");
325 /* Exported procedure: Is PC in the signal trampoline code */
328 in_sigtramp(pc
, name
)
332 if (sigtramp_address
== 0)
334 return (pc
>= sigtramp_address
&& pc
< sigtramp_end
);
337 /* File-level interface functions */
339 /* Read the symtab information from file FSYM into memory. Also,
340 return address just past end of our text segment in *END_OF_TEXT_SEGP. */
343 read_the_mips_symtab(abfd
, fsym
, end_of_text_segp
)
346 CORE_ADDR
*end_of_text_segp
;
348 int stsize
, st_hdrsize
;
351 /* Header for executable/object file we read symbols from */
352 struct coff_exec filhdr
;
354 /* We get here with DESC pointing to the symtab header. But we need
355 * other info from the initial headers */
357 myread(fsym
, &filhdr
, sizeof filhdr
);
359 if (end_of_text_segp
)
361 bfd_h_get_32 (abfd
, filhdr
.a
.text_start
) +
362 bfd_h_get_32 (abfd
, filhdr
.a
.tsize
);
364 /* Find and read the symbol table header */
365 st_hdrsize
= bfd_h_get_32 (abfd
, filhdr
.f
.f_nsyms
);
366 st_filptr
= bfd_h_get_32 (abfd
, filhdr
.f
.f_symptr
);
370 lseek(fsym
, st_filptr
, L_SET
);
371 if (st_hdrsize
> sizeof (st_hdr
)) /* Profanity check */
373 if (read(fsym
, &st_hdr
, st_hdrsize
) != st_hdrsize
)
376 /* Find out how large the symbol table is */
377 stsize
= (st_hdr
.cbExtOffset
- (st_filptr
+ st_hdrsize
))
378 + st_hdr
.iextMax
* cbEXTR
;
380 /* Allocate space for the symbol table. Read it in. */
381 cur_hdr
= (HDRR
*) xmalloc(stsize
+ st_hdrsize
);
383 memcpy(cur_hdr
, &st_hdr
, st_hdrsize
);
384 if (read(fsym
, (char *) cur_hdr
+ st_hdrsize
, stsize
) != stsize
)
387 /* Fixup file_pointers in it */
388 fixup_symtab(cur_hdr
, (char *) cur_hdr
+ st_hdrsize
,
389 st_filptr
+ st_hdrsize
);
393 error("Short read on %s", bfd_get_filename (abfd
));
397 /* Turn all file-relative pointers in the symtab described by HDR
398 into memory pointers, given that the symtab itself is located
399 at DATA in memory and F_PTR in the file. */
402 fixup_symtab( hdr
, data
, f_ptr
)
414 * These fields are useless (and empty) by now:
415 * hdr->cbDnOffset, hdr->cbOptOffset
416 * We use them for other internal purposes.
419 hdr
->cbOptOffset
= 0;
422 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
438 * Fix all string pointers inside the symtab, and
439 * the FDR records. Also fix other miscellany.
441 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
442 register unsigned code_offset
;
444 /* Header itself, and strings */
445 fh
= (FDR
*) (hdr
->cbFdOffset
) + f_idx
;
446 fh
->issBase
+= hdr
->cbSsOffset
;
448 fh
->rss
= (long)fh
->rss
+ fh
->issBase
;
451 fh
->isymBase
= (int)((SYMR
*)(hdr
->cbSymOffset
)+fh
->isymBase
);
453 /* FIXME! Probably don't want to do this here! */
454 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
455 sh
= (SYMR
*)fh
->isymBase
+ s_idx
;
456 sh
->iss
= (long) sh
->iss
+ fh
->issBase
;
462 /* cannot fix fh->ipdFirst because it is a short */
463 #define IPDFIRST(h,fh) \
464 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
466 /* Optional symbols (actually used for partial_symtabs) */
472 fh
->iauxBase
= hdr
->cbAuxOffset
+ fh
->iauxBase
* sizeof(AUXU
);
473 /* Relative file descriptor table */
474 fh
->rfdBase
= hdr
->cbRfdOffset
+ fh
->rfdBase
* sizeof(RFDT
);
478 fh
->cbLineOffset
+= hdr
->cbLineOffset
;
480 /* Procedure symbols. (XXX This should be done later) */
481 code_offset
= fh
->adr
;
482 for (s_idx
= 0; s_idx
< fh
->cpd
; s_idx
++) {
483 unsigned name
, only_ext
;
485 pr
= (PDR
*)(IPDFIRST(hdr
,fh
)) + s_idx
;
487 /* Simple rule to find files linked "-x" */
488 only_ext
= fh
->rss
== -1;
490 if (pr
->isym
== -1) {
491 /* static function */
495 name
= hdr
->cbExtOffset
+ pr
->isym
* sizeof(EXTR
);
496 sh
= &((EXTR
*)name
)->asym
;
500 sh
= (SYMR
*)fh
->isymBase
+ pr
->isym
;
501 /* Included code ? */
502 if (s_idx
== 0 && pr
->adr
!= 0)
503 code_offset
-= pr
->adr
;
506 /* Turn index into a pointer */
509 /* Fix line numbers */
510 pr
->cbLineOffset
+= fh
->cbLineOffset
;
512 /* Relocate address */
514 pr
->adr
+= code_offset
;
518 /* External symbols: fix string */
519 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
520 esh
= (EXTR
*)(hdr
->cbExtOffset
) + s_idx
;
521 esh
->asym
.iss
= esh
->asym
.iss
+ hdr
->cbSsExtOffset
;
526 /* Find a file descriptor given its index RF relative to a file CF */
534 f
= (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
535 /* Object files do not have the RFD table, all refs are absolute */
537 return (FDR
*) (cur_hdr
->cbFdOffset
) + rf
;
538 cf
= *((pRFDT
) f
->rfdBase
+ rf
);
539 return (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
542 /* Return a safer print NAME for a file descriptor */
548 if (name
== (char *) -1)
549 return "<stripped file>";
550 if (UNSAFE_DATA_ADDR(name
))
556 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
557 whether we are adding to the general symtab or not.
558 FIXME: INCREMENTAL is currently always zero, though it should not be. */
561 read_mips_symtab (objfile
, desc
)
562 struct objfile
*objfile
;
565 CORE_ADDR end_of_text_seg
;
567 read_the_mips_symtab(objfile
->obfd
, desc
, &end_of_text_seg
);
569 parse_partial_symbols(end_of_text_seg
, objfile
);
573 * Check to make sure file was compiled with -g.
574 * If not, warn the user of this limitation.
576 if (compare_glevel(max_glevel
, GLEVEL_2
) < 0) {
577 if (max_gdbinfo
== 0)
579 "\n%s not compiled with -g, debugging support is limited.\n",
582 "You should compile with -g2 or -g3 for best debugging support.\n");
588 /* Local utilities */
590 /* Map of FDR indexes to partial symtabs */
592 static struct pst_map
{
593 struct partial_symtab
*pst
; /* the psymtab proper */
597 /* Utility stack, used to nest procedures and blocks properly.
598 It is a doubly linked list, to avoid too many alloc/free.
599 Since we might need it quite a few times it is NOT deallocated
602 static struct parse_stack
{
603 struct parse_stack
*next
, *prev
;
604 struct symtab
*cur_st
; /* Current symtab. */
605 struct block
*cur_block
; /* Block in it. */
606 int blocktype
; /* What are we parsing. */
607 int maxsyms
; /* Max symbols in this block. */
608 struct type
*cur_type
; /* Type we parse fields for. */
609 int cur_field
; /* Field number in cur_type. */
610 int procadr
; /* Start addres of this procedure */
611 int numargs
; /* Its argument count */
612 } *top_stack
; /* Top stack ptr */
615 /* Enter a new lexical context */
617 static push_parse_stack()
619 struct parse_stack
*new;
621 /* Reuse frames if possible */
622 if (top_stack
&& top_stack
->prev
)
623 new = top_stack
->prev
;
625 new = (struct parse_stack
*) xzalloc(sizeof(struct parse_stack
));
626 /* Initialize new frame with previous content */
628 register struct parse_stack
*prev
= new->prev
;
631 top_stack
->prev
= new;
633 new->next
= top_stack
;
638 /* Exit a lexical context */
640 static pop_parse_stack()
645 top_stack
= top_stack
->next
;
649 /* Cross-references might be to things we haven't looked at
650 yet, e.g. type references. To avoid too many type
651 duplications we keep a quick fixup table, an array
652 of lists of references indexed by file descriptor */
654 static struct mips_pending
{
655 struct mips_pending
*next
; /* link */
656 SYMR
*s
; /* the symbol */
657 struct type
*t
; /* its partial type descriptor */
661 /* Check whether we already saw symbol SH in file FH as undefined */
664 struct mips_pending
*is_pending_symbol(fh
, sh
)
668 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
669 register struct mips_pending
*p
;
671 /* Linear search is ok, list is typically no more than 10 deep */
672 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
678 /* Check whether we already saw type T in file FH as undefined */
681 struct mips_pending
*is_pending_type(fh
, t
)
685 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
686 register struct mips_pending
*p
;
688 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
694 /* Add a new undef symbol SH of type T */
697 add_pending(fh
, sh
, t
)
702 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
703 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
705 /* Make sure we do not make duplicates */
707 p
= (struct mips_pending
*) xmalloc(sizeof(*p
));
710 p
->next
= pending_list
[f_idx
];
711 pending_list
[f_idx
] = p
;
713 sh
->reserved
= 1; /* for quick check */
716 /* Throw away undef entries when done with file index F_IDX */
721 register struct mips_pending
*p
, *q
;
723 for (p
= pending_list
[f_idx
]; p
; p
= q
) {
727 pending_list
[f_idx
] = 0;
730 /* The number of args to a procedure is not explicit in the symtab,
731 this is the list of all those we know of.
732 This makes parsing more reasonable and avoids extra passes */
734 static struct numarg
{
735 struct numarg
*next
; /* link */
736 unsigned adr
; /* procedure's start address */
737 unsigned num
; /* arg count */
740 /* Record that the procedure at ADR takes NUM arguments. */
745 struct numarg
*n
= (struct numarg
*) xmalloc(sizeof(struct numarg
));
749 n
->next
= numargs_list
;
753 /* See if we know how many arguments the procedure at ADR takes */
758 struct numarg
*n
= numargs_list
;
760 while (n
&& n
->adr
!= adr
)
762 return (n
) ? n
->num
: -1;
765 /* Release storage when done with this file */
770 struct numarg
*n
= numargs_list
, *m
;
781 /* Parsing Routines proper. */
783 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
784 For blocks, procedures and types we open a new lexical context.
785 This is basically just a big switch on the symbol's type.
786 Return count of SYMR's handled (normally one). */
799 /* When a symbol is cross-referenced from other files/symbols
800 we mark it explicitly */
801 int pend
= (sh
->reserved
== 1);
802 enum address_class
class;
809 case stGlobal
: /* external symbol, goes into global block */
811 b
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
813 s
= new_symbol(sh
->iss
);
814 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
817 case stStatic
: /* static data, goes into current block. */
819 b
= top_stack
->cur_block
;
820 s
= new_symbol(sh
->iss
);
821 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
824 case stLocal
: /* local variable, goes into current block */
825 if (sh
->sc
== scRegister
) {
826 class = LOC_REGISTER
;
831 b
= top_stack
->cur_block
;
832 s
= new_symbol(sh
->iss
);
833 SYMBOL_VALUE(s
) = sh
->value
;
835 data
: /* Common code for symbols describing data */
836 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
837 SYMBOL_CLASS(s
) = class;
840 /* Type could be missing in a number of cases */
841 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
842 sh
->index
== 0xfffff)
843 SYMBOL_TYPE(s
) = builtin_type_int
; /* undefined? */
845 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
846 /* Value of a data symbol is its memory address */
849 case stParam
: /* arg to procedure, goes into current block */
851 top_stack
->numargs
++;
853 name
= (char*)sh
->iss
;
854 /* Special GNU C++ name. */
855 if (name
[0] == CPLUS_MARKER
&& name
[1] == 't' && name
[2] == 0)
857 s
= new_symbol(name
);
859 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
860 if (sh
->sc
== scRegister
) {
861 SYMBOL_CLASS(s
) = LOC_REGPARM
;
865 SYMBOL_CLASS(s
) = LOC_ARG
;
866 SYMBOL_VALUE(s
) = sh
->value
;
867 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
868 add_symbol(s
, top_stack
->cur_block
);
870 /* FIXME: This has not been tested. See dbxread.c */
871 /* Add the type of this parameter to the function/procedure
872 type of this block. */
873 add_param_to_type(&top_stack
->cur_block
->function
->type
,s
);
877 case stLabel
: /* label, goes into current block */
878 s
= new_symbol(sh
->iss
);
879 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
; /* so that it can be used */
880 SYMBOL_CLASS(s
) = LOC_LABEL
; /* but not misused */
881 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
882 SYMBOL_TYPE(s
) = builtin_type_int
;
883 add_symbol(s
, top_stack
->cur_block
);
886 case stProc
: /* Procedure, usually goes into global block */
887 case stStaticProc
: /* Static procedure, goes into current block */
888 s
= new_symbol(sh
->iss
);
889 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
890 SYMBOL_CLASS(s
) = LOC_BLOCK
;
891 /* Type of the return value */
892 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
893 t
= builtin_type_int
;
895 t
= parse_type(ax
+ sh
->index
, sh
, 0);
896 b
= top_stack
->cur_block
;
897 if (sh
->st
== stProc
) {
898 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
899 /* The next test should normally be true,
900 but provides a hook for nested functions
901 (which we don't want to make global). */
902 if (b
== BLOCKVECTOR_BLOCK(bv
, STATIC_BLOCK
))
903 b
= BLOCKVECTOR_BLOCK(bv
, GLOBAL_BLOCK
);
907 /* Make a type for the procedure itself */
909 /* FIXME: This has not been tested yet! See dbxread.c */
910 /* Generate a template for the type of this function. The
911 types of the arguments will be added as we read the symbol
913 bcopy(SYMBOL_TYPE(s
),lookup_function_type(t
),sizeof(struct type
));
915 SYMBOL_TYPE(s
) = lookup_function_type (t
);
918 /* Create and enter a new lexical context */
919 b
= new_block(top_stack
->maxsyms
);
920 SYMBOL_BLOCK_VALUE(s
) = b
;
921 BLOCK_FUNCTION(b
) = s
;
922 BLOCK_START(b
) = BLOCK_END(b
) = sh
->value
;
923 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
924 add_block(b
, top_stack
->cur_st
);
926 /* Not if we only have partial info */
927 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
931 top_stack
->cur_block
= b
;
932 top_stack
->blocktype
= sh
->st
;
933 top_stack
->cur_type
= SYMBOL_TYPE(s
);
934 top_stack
->cur_field
= -1;
935 top_stack
->procadr
= sh
->value
;
936 top_stack
->numargs
= 0;
938 sh
->value
= (long) SYMBOL_TYPE(s
);
942 #ifndef btVoid /* btVoid was added late. */
945 /* These new symbol types have been recently added to SGI machines. */
959 case stBlock
: /* Either a lexical block, or some type */
961 top_stack
->blocktype
= stBlock
;
962 if (sh
->sc
== scInfo
) { /* structure/union/enum def */
964 sh
->st
== stStruct
? TYPE_CODE_STRUCT
965 : sh
->st
== stUnion
? TYPE_CODE_UNION
966 : sh
->st
== stEnum
? TYPE_CODE_ENUM
973 s
= new_symbol(sh
->iss
);
974 SYMBOL_NAMESPACE(s
) = STRUCT_NAMESPACE
;
975 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
977 add_symbol(s
, top_stack
->cur_block
);
978 /* If this type was expected, use its partial definition */
980 t
= is_pending_symbol(cur_fdr
, sh
)->t
;
982 t
= new_type(sh
->iss
);
984 /* First count the number of fields. */
985 for (tsym
= sh
+1; tsym
->st
!= stEnd
; tsym
++)
986 if (tsym
->st
== stMember
) {
987 if (nfields
== 0 && type_code
== TYPE_CODE_UNDEF
)
988 /* If the type of the member is Void,
989 assume the tag is an enumeration. */
990 if (tsym
->index
== indexNil
991 || ax
[tsym
->index
].ti
.bt
== btVoid
)
992 type_code
= TYPE_CODE_ENUM
;
994 if (tsym
->value
> max_value
)
995 max_value
= tsym
->value
;
997 else if (tsym
->st
== stBlock
998 || tsym
->st
== stParsed
) {
999 if (tsym
->sc
== scVariant
) ; /*UNIMPLEMENTED*/
1000 if (tsym
->index
!= 0)
1001 tsym
= ((SYMR
*)cur_fdr
->isymBase
)
1006 /* There is no guaranteed way to distinguish struct,
1007 unions, and enums at this point. This is a bug in the
1008 original design (that has been fixed with the
1009 recent addition of the stStruct, stUnion, and stEnum
1010 symbol types.) The way you can tell is if/when you
1011 see a variable or field of that type: In that case
1012 the variable's type (in the AUX table) says if the
1013 type is struct, union, or enum,
1014 and points back to the stBlock here.
1015 So you can patch the tag kind up later - but only
1016 if there actually is a variable or field of that type.
1018 So until we know for sure, we will guess at this point.
1020 If the first member has index==indexNil or a void type,
1021 assume we have an enumeration.
1022 Otherwise, if all the members have offset 0,
1023 assume we have a union.
1024 Otherwise, assume we have a struct.
1026 The heuristic could guess wrong in the case of
1027 of an enumeration with no members or a union
1028 with one (or zero) members, or when all except the
1029 last field of a struct have width zero.
1030 These are uncommon and/or illegal situations, and
1031 in any case guessing wrong probably doesn't matter much.
1033 But if we later do find out we were wrong,
1034 we fixup the tag kind. Members of an enumeration
1035 must be handled differently from struct/union fields,
1036 and that is harder to patch up, but luckily we
1037 shouldn't need to. (If there are any enumeration
1038 members, we can tell for sure it's an enum here.) */
1040 if (type_code
== TYPE_CODE_UNDEF
)
1041 if (max_value
== 0) type_code
= TYPE_CODE_UNION
;
1042 else type_code
= TYPE_CODE_STRUCT
;
1044 TYPE_CODE(t
) = type_code
;
1045 TYPE_NFIELDS(t
) = nfields
;
1046 TYPE_FIELDS(t
) = f
= (struct field
*)
1047 obstack_alloc (symbol_obstack
,
1048 nfields
* sizeof (struct field
));
1050 if (type_code
== TYPE_CODE_ENUM
) {
1051 /* This is a non-empty enum. */
1052 while (sh
[1].st
== stMember
) {
1053 struct symbol
*enum_sym
;
1055 f
->bitpos
= sh
->value
;
1057 f
->name
= (char*)sh
->iss
;
1060 enum_sym
= (struct symbol
*)
1061 obstack_alloc (symbol_obstack
,
1062 sizeof (struct symbol
));
1063 memset (enum_sym
, 0, sizeof (struct symbol
));
1064 SYMBOL_NAME (enum_sym
) = f
->name
;
1065 SYMBOL_CLASS (enum_sym
) = LOC_CONST
;
1066 SYMBOL_TYPE (enum_sym
) = t
;
1067 SYMBOL_NAMESPACE (enum_sym
) = VAR_NAMESPACE
;
1068 SYMBOL_VALUE (enum_sym
) = sh
->value
;
1069 add_symbol(enum_sym
, top_stack
->cur_block
);
1071 /* Skip the stMembers that we've handled. */
1077 /* make this the current type */
1078 top_stack
->cur_type
= t
;
1079 top_stack
->cur_field
= 0;
1080 TYPE_LENGTH(t
) = sh
->value
;
1081 /* Mark that symbol has a type, and say which one */
1082 sh
->value
= (long) t
;
1084 /* beginnning of (code) block. Value of symbol
1085 is the displacement from procedure start */
1086 b
= new_block(top_stack
->maxsyms
);
1087 BLOCK_START(b
) = sh
->value
+ top_stack
->procadr
;
1088 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1089 top_stack
->cur_block
= b
;
1090 add_block(b
, top_stack
->cur_st
);
1094 case stEnd
: /* end (of anything) */
1095 if (sh
->sc
== scInfo
) {
1096 /* Finished with type */
1097 top_stack
->cur_type
= 0;
1098 } else if (sh
->sc
== scText
&&
1099 (top_stack
->blocktype
== stProc
||
1100 top_stack
->blocktype
== stStaticProc
)) {
1101 /* Finished with procedure */
1102 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
1106 BLOCK_END(top_stack
->cur_block
) += sh
->value
; /* size */
1107 got_numargs(top_stack
->procadr
, top_stack
->numargs
);
1108 /* Reallocate symbols, saving memory */
1109 b
= shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1111 /* f77 emits proc-level with address bounds==[0,0],
1112 So look for such child blocks, and patch them. */
1113 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++) {
1114 struct block
*b_bad
= BLOCKVECTOR_BLOCK(bv
,i
);
1115 if (BLOCK_SUPERBLOCK(b_bad
) == b
1116 && BLOCK_START(b_bad
) == top_stack
->procadr
1117 && BLOCK_END(b_bad
) == top_stack
->procadr
) {
1118 BLOCK_START(b_bad
) = BLOCK_START(b
);
1119 BLOCK_END(b_bad
) = BLOCK_END(b
);
1122 } else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
) {
1123 /* End of (code) block. The value of the symbol
1124 is the displacement from the procedure`s start
1125 address of the end of this block. */
1126 BLOCK_END(top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1127 (void) shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1129 pop_parse_stack(); /* restore previous lexical context */
1132 case stMember
: /* member of struct or union */
1133 f
= &TYPE_FIELDS(top_stack
->cur_type
)[top_stack
->cur_field
++];
1134 f
->name
= (char*)sh
->iss
;
1135 f
->bitpos
= sh
->value
;
1137 f
->type
= parse_type(ax
+ sh
->index
, sh
, &f
->bitsize
);
1140 case stTypedef
: /* type definition */
1141 s
= new_symbol(sh
->iss
);
1142 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1143 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1144 SYMBOL_BLOCK_VALUE(s
) = top_stack
->cur_block
;
1145 add_symbol(s
, top_stack
->cur_block
);
1146 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
1147 sh
->value
= (long) SYMBOL_TYPE(s
);
1150 case stFile
: /* file name */
1152 top_stack
->blocktype
= sh
->st
;
1155 /* I`ve never seen these for C */
1157 break; /* register relocation */
1159 break; /* forwarding address */
1161 break; /* constant */
1163 error("Unknown symbol type %x.", sh
->st
);
1169 /* Parse the type information provided in the AX entries for
1170 the symbol SH. Return the bitfield size in BS, in case. */
1172 static struct type
*parse_type(ax
, sh
, bs
)
1177 /* Null entries in this map are treated specially */
1178 static struct type
**map_bt
[] =
1180 &builtin_type_void
, /* btNil */
1182 &builtin_type_char
, /* btChar */
1183 &builtin_type_unsigned_char
, /* btUChar */
1184 &builtin_type_short
, /* btShort */
1185 &builtin_type_unsigned_short
, /* btUShort */
1186 &builtin_type_int
, /* btInt */
1187 &builtin_type_unsigned_int
, /* btUInt */
1188 &builtin_type_long
, /* btLong */
1189 &builtin_type_unsigned_long
, /* btULong */
1190 &builtin_type_float
, /* btFloat */
1191 &builtin_type_double
, /* btDouble */
1198 &builtin_type_complex
, /* btComplex */
1199 &builtin_type_double_complex
, /* btDComplex */
1201 &builtin_type_fixed_dec
, /* btFixedDec */
1202 &builtin_type_float_dec
, /* btFloatDec */
1203 &builtin_type_string
, /* btString */
1206 &builtin_type_void
, /* btVoid */
1210 struct type
*tp
= 0;
1215 /* Procedures start off by one */
1216 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
)
1219 /* Undefined ? Should not happen */
1220 if (ax
->rndx
.rfd
== 0xfff) {
1221 return builtin_type_void
;
1224 /* Use aux as a type information record, map its basic type */
1226 if (t
->bt
> (sizeof (map_bt
)/sizeof (*map_bt
))) {
1227 complain (&basic_type_complaint
, t
->bt
);
1228 return builtin_type_int
;
1230 if (map_bt
[t
->bt
]) {
1231 tp
= *map_bt
[t
->bt
];
1235 /* Cannot use builtin types -- build our own */
1238 tp
= lookup_pointer_type (builtin_type_void
);
1242 type_code
= TYPE_CODE_STRUCT
;
1246 type_code
= TYPE_CODE_UNION
;
1250 type_code
= TYPE_CODE_ENUM
;
1254 type_code
= TYPE_CODE_RANGE
;
1258 type_code
= TYPE_CODE_SET
;
1263 complain (&basic_type_complaint
, t
->bt
);
1264 return builtin_type_int
;
1268 /* Move on to next aux */
1271 /* This is the way it would work if the compiler worked */
1272 register TIR
*t1
= t
;
1273 while (t1
->continued
)
1282 /* All these types really point to some (common) MIPS type
1283 definition, and only the type-qualifiers fully identify
1284 them. We'll make the same effort at sharing. */
1285 if (t
->bt
== btIndirect
||
1286 t
->bt
== btStruct
||
1289 t
->bt
== btTypedef
||
1292 char name
[256], *pn
;
1294 /* Try to cross reference this type */
1295 ax
+= cross_ref(ax
, &tp
, type_code
, &pn
);
1296 /* reading .o file ? */
1297 if (UNSAFE_DATA_ADDR(tp
))
1298 tp
= make_type(type_code
, 0, 0, 0);
1299 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1300 sprintf(name
, fmt
, pn
);
1302 /* Usually, TYPE_CODE(tp) is already type_code. The main
1303 exception is if we guessed wrong re struct/union/enum. */
1304 if (TYPE_CODE(tp
) != type_code
) {
1305 complain (&bad_tag_guess_complaint
, 0);
1306 TYPE_CODE(tp
) = type_code
;
1308 TYPE_NAME(tp
) = obsavestring(pn
, strlen(pn
));
1311 /* Deal with range types */
1312 if (t
->bt
== btRange
) {
1315 TYPE_NFIELDS (tp
) = 2;
1317 (struct field
*) obstack_alloc (symbol_obstack
,
1318 2 * sizeof (struct field
));
1319 TYPE_FIELD_NAME (tp
, 0) = "Low";
1320 TYPE_FIELD_BITPOS (tp
, 0) = ax
->dnLow
;
1322 TYPE_FIELD_NAME (tp
, 1) = "High";
1323 TYPE_FIELD_BITPOS (tp
, 1) = ax
->dnHigh
;
1327 /* Parse all the type qualifiers now. If there are more
1328 than 6 the game will continue in the next aux */
1330 #define PARSE_TQ(tq) \
1331 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, sh);
1333 again
: PARSE_TQ(tq0
);
1348 /* Make up a complex type from a basic one. Type is passed by
1349 reference in TPP and side-effected as necessary. The type
1350 qualifier TQ says how to handle the aux symbols at AX for
1351 the symbol SX we are currently analyzing.
1352 Returns the number of aux symbols we parsed. */
1355 upgrade_type(tpp
, tq
, ax
, sh
)
1363 /* Used in array processing */
1372 t
= lookup_pointer_type (*tpp
);
1377 t
= lookup_function_type (*tpp
);
1383 t
= make_type(TYPE_CODE_ARRAY
, 0, 0, 0);
1384 TYPE_TARGET_TYPE(t
) = *tpp
;
1386 /* Determine and record the domain type (type of index) */
1387 id
= ax
->rndx
.index
;
1393 fh
= get_rfd(cur_fd
, rf
);
1395 /* Fields are kept in an array */
1396 /* FIXME - Memory leak! */
1397 if (TYPE_NFIELDS(t
))
1398 TYPE_FIELDS(t
) = (struct field
*)
1399 xrealloc(TYPE_FIELDS(t
),
1400 (TYPE_NFIELDS(t
)+1) * sizeof(struct field
));
1402 TYPE_FIELDS(t
) = (struct field
*)
1403 xzalloc(sizeof(struct field
));
1404 f
= &(TYPE_FIELD(t
,TYPE_NFIELDS(t
)));
1406 memset(f
, 0, sizeof(struct field
));
1408 memset(&ss
, 0, sizeof ss
);
1409 /* XXX */ f
->type
= parse_type(fh
->iauxBase
+ id
* sizeof(AUXU
),
1414 * This seems to be a pointer to the end of the Block defining
1415 * the type. Why it is here is magic for me, and I have no
1416 * good use for it anyways.
1418 /* This used to occur because cross_ref returned
1419 the wrong result (ax pointed wrong). FIXME,
1420 delete this code in a while. -- gnu@cygnus jul91 */
1421 complain (&array_parse_complaint
, 0);
1423 id
= (++ax
)->rndx
.index
;
1424 if ((rf
= ax
->rndx
.rfd
) == 0xfff)
1425 rf
= (++ax
)->isym
, off
++;
1427 lower
= (++ax
)->dnLow
;
1428 upper
= (++ax
)->dnHigh
;
1429 rf
= (++ax
)->width
; /* bit size of array element */
1431 /* Check whether supplied array element bit size matches
1432 the known size of the element type. If this complaint
1433 ends up not happening, we can remove this code. It's
1434 here because we aren't sure we understand this *&%&$
1436 id
= TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) << 3; /* bitsize */
1438 /* Most likely an undefined type */
1440 TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) = id
>> 3;
1443 complain (&array_bitsize_complaint
, rf
);
1445 TYPE_LENGTH(t
) = (upper
< 0) ? 0 :
1446 (upper
- lower
+ 1) * (rf
>> 3);
1451 /* Volatile -- currently ignored */
1455 complain (&unknown_type_qual_complaint
, tq
);
1461 /* Parse a procedure descriptor record PR. Note that the procedure
1462 is parsed _after_ the local symbols, now we just make up the
1463 extra information we need into a special symbol that we insert
1464 in the procedure's main block. Note also that images that
1465 have been partially stripped (ld -x) have been deprived
1466 of local symbols, and we have to cope with them here.
1467 The procedure's code ends at BOUND */
1470 parse_procedure(pr
, bound
)
1473 struct symbol
*s
, *i
;
1474 SYMR
*sh
= (SYMR
*)pr
->isym
;
1476 struct mips_extra_func_info
*e
;
1480 /* Reuse the MIPS record */
1481 e
= (struct mips_extra_func_info
*) pr
;
1482 e
->numargs
= lookup_numargs(pr
->adr
);
1484 /* Make up our special symbol */
1485 i
= new_symbol(".gdbinfo.");
1486 SYMBOL_VALUE(i
) = (int)e
;
1487 SYMBOL_NAMESPACE(i
) = LABEL_NAMESPACE
;
1488 SYMBOL_CLASS(i
) = LOC_CONST
;
1489 SYMBOL_TYPE(i
) = builtin_type_void
;
1491 /* Make up a name for static procedures. Sigh. */
1492 if (sh
== (SYMR
*)-1) {
1493 sprintf(name
,".static_procedure@%x",pr
->adr
);
1494 sh_name
= savestring(name
, strlen(name
));
1498 sh_name
= (char*)sh
->iss
;
1499 s
= mylookup_symbol(sh_name
, top_stack
->cur_block
,
1500 VAR_NAMESPACE
, LOC_BLOCK
);
1503 b
= SYMBOL_BLOCK_VALUE(s
);
1505 s
= new_symbol(sh_name
);
1506 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1507 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1508 /* Donno its type, hope int is ok */
1509 SYMBOL_TYPE(s
) = lookup_function_type (builtin_type_int
);
1510 add_symbol(s
, top_stack
->cur_block
);
1511 /* Wont have symbols for this one */
1513 SYMBOL_BLOCK_VALUE(s
) = b
;
1514 BLOCK_FUNCTION(b
) = s
;
1515 BLOCK_START(b
) = pr
->adr
;
1516 BLOCK_END(b
) = bound
;
1517 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1518 add_block(b
, top_stack
->cur_st
);
1524 /* Parse the external symbol ES. Just call parse_symbol() after
1525 making sure we know where the aux are for it. For procedures,
1526 parsing of the PDRs has already provided all the needed
1527 information, we only parse them if SKIP_PROCEDURES is false,
1528 and only if this causes no symbol duplication.
1530 This routine clobbers top_stack->cur_block and ->cur_st. */
1533 parse_external(es
, skip_procedures
)
1538 if (es
->ifd
!= ifdNil
) {
1540 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
) + cur_fd
;
1541 ax
= (AUXU
*)cur_fdr
->iauxBase
;
1543 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
);
1546 top_stack
->cur_st
= cur_stab
;
1547 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
1550 /* Reading .o files */
1551 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
) {
1553 switch (es
->asym
.st
) {
1555 case stProc
: what
= "procedure"; n_undef_procs
++; break;
1556 case stGlobal
: what
= "variable"; n_undef_vars
++; break;
1557 case stLabel
: what
= "label"; n_undef_labels
++; break;
1558 default : what
= "symbol"; break;
1562 printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what
,
1563 es
->asym
.iss
, fdr_name(cur_fdr
->rss
));
1567 switch (es
->asym
.st
) {
1569 /* If we have full symbols we do not need more */
1570 if (skip_procedures
)
1572 if (mylookup_symbol (es
->asym
.iss
, top_stack
->cur_block
,
1573 VAR_NAMESPACE
, LOC_BLOCK
))
1579 * Note that the case of a symbol with indexNil
1580 * must be handled anyways by parse_symbol().
1582 parse_symbol(&es
->asym
, ax
);
1589 /* Parse the line number info for file descriptor FH into
1590 GDB's linetable LT. MIPS' encoding requires a little bit
1591 of magic to get things out. Note also that MIPS' line
1592 numbers can go back and forth, apparently we can live
1593 with that and do not need to reorder our linetables */
1598 struct linetable
*lt
;
1600 unsigned char *base
= (unsigned char*)fh
->cbLineOffset
;
1602 int delta
, count
, lineno
= 0;
1608 /* Scan by procedure descriptors */
1609 i
= 0; j
= 0, k
= 0;
1610 for (pr
= (PDR
*)IPDFIRST(cur_hdr
,fh
); j
< fh
->cpd
; j
++, pr
++) {
1613 /* No code for this one */
1614 if (pr
->iline
== ilineNil
||
1615 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1618 * Aurgh! To know where to stop expanding we
1621 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1622 if (pr
[l
].iline
!= -1)
1624 if (l
== (fh
->cpd
- j
))
1629 * When procedures are moved around the linenumbers
1630 * are attributed to the next procedure up
1632 if (pr
->iline
>= halt
) continue;
1634 base
= (unsigned char*)pr
->cbLineOffset
;
1635 l
= pr
->adr
>> 2; /* in words */
1636 halt
+= (pr
->adr
>> 2) - pr
->iline
;
1637 for (lineno
= pr
->lnLow
; l
< halt
;) {
1638 count
= *base
& 0x0f;
1639 delta
= *base
++ >> 4;
1643 delta
= (base
[0] << 8) | base
[1];
1644 if (delta
>= 0x8000)
1648 lineno
+= delta
;/* first delta is 0 */
1649 k
= add_line(lt
, lineno
, l
, k
);
1656 /* Master parsing procedure for first-pass reading of file symbols
1657 into a partial_symtab.
1659 Parses the symtab described by the global symbolic header CUR_HDR.
1660 END_OF_TEXT_SEG gives the address just after the text segment for
1661 the symtab we are reading. */
1664 parse_partial_symbols(end_of_text_seg
, objfile
)
1665 int end_of_text_seg
;
1666 struct objfile
*objfile
;
1669 /* int stat_idx, h_max;*/
1671 /* Running pointers */
1676 struct partial_symtab
*pst
;
1678 int past_first_source_file
= 0;
1680 /* List of current psymtab's include files */
1681 char **psymtab_include_list
;
1682 int includes_allocated
;
1685 /* Index within current psymtab dependency list */
1686 struct partial_symtab
**dependency_list
;
1687 int dependencies_used
, dependencies_allocated
;
1689 includes_allocated
= 30;
1691 psymtab_include_list
= (char **) alloca (includes_allocated
*
1693 next_symbol_text_func
= mips_next_symbol_text
;
1695 dependencies_allocated
= 30;
1696 dependencies_used
= 0;
1698 (struct partial_symtab
**) alloca (dependencies_allocated
*
1699 sizeof (struct partial_symtab
*));
1701 last_source_file
= 0;
1706 * Only parse the Local and External symbols, and the Relative FDR.
1707 * Fixup enough of the loader symtab to be able to use it.
1708 * Allocate space only for the file's portions we need to
1714 max_glevel
= MIN_GLEVEL
;
1716 /* Allocate the map FDR -> PST.
1717 Minor hack: -O3 images might claim some global data belongs
1718 to FDR -1. We`ll go along with that */
1719 fdr_to_pst
= (struct pst_map
*)xzalloc((hdr
->ifdMax
+1) * sizeof *fdr_to_pst
);
1722 struct partial_symtab
* pst
= new_psymtab("", objfile
);
1723 fdr_to_pst
[-1].pst
= pst
;
1727 /* Pass 2 over external syms: fill in external symbols */
1728 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1729 register struct partial_symbol
*p
;
1730 enum misc_function_type misc_type
= mf_text
;
1731 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1733 if (esh
->asym
.sc
== scUndefined
|| esh
->asym
.sc
== scNil
)
1736 switch (esh
->asym
.st
) {
1740 misc_type
= mf_data
;
1745 misc_type
= mf_unknown
;
1746 complain (&unknown_ext_complaint
, SYMBOL_NAME(p
));
1748 prim_record_misc_function ((char *)(esh
->asym
.iss
),
1753 /* Pass 3 over files, over local syms: fill in static symbols */
1754 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
1755 struct partial_symtab
*save_pst
;
1757 cur_fdr
= fh
= f_idx
+ (FDR
*)(cur_hdr
->cbFdOffset
);
1759 if (fh
->csym
== 0) {
1760 fdr_to_pst
[f_idx
].pst
= NULL
;
1763 pst
= start_psymtab (objfile
, 0, (char*)fh
->rss
,
1764 fh
->cpd
? fh
->adr
: 0,
1766 global_psymbols
.next
,
1767 static_psymbols
.next
);
1769 /* Make everything point to everything. */
1770 FDR_IDX(pst
) = f_idx
;
1771 fdr_to_pst
[f_idx
].pst
= pst
;
1772 fh
->ioptBase
= (int)pst
;
1774 CUR_HDR(pst
) = cur_hdr
;
1776 /* The way to turn this into a symtab is to call... */
1777 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
1779 pst
->texthigh
= pst
->textlow
;
1781 pst
->globals_offset
= global_psymbols
.next
- global_psymbols
.list
;
1782 pst
->statics_offset
= static_psymbols
.next
- static_psymbols
.list
;
1784 pst
->n_global_syms
= 0;
1785 pst
->n_static_syms
= 0;
1787 /* The second symbol must be @stab.
1788 This symbol is emitted by mips-tfile to signal
1789 that the current object file uses encapsulated stabs
1790 instead of mips ecoff for local symbols.
1791 (It is the second symbol because the first symbol is
1792 the stFile used to signal the start of a file). */
1794 && strcmp(((SYMR
*)fh
->isymBase
)[1].iss
, stabs_symbol
) == 0) {
1795 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++) {
1798 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
1799 type_code
= MIPS_UNMARK_STAB(sh
->index
);
1800 if (!MIPS_IS_STAB(sh
)) {
1801 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
) {
1802 long procaddr
= sh
->value
;
1803 sh
= (sh
->index
+ (AUXU
*)fh
->iauxBase
)->isym
1804 + (SYMR
*) fh
->isymBase
- 1;
1805 if (sh
->st
== stEnd
) {
1806 long high
= procaddr
+ sh
->value
;
1807 if (high
> pst
->texthigh
)
1808 pst
->texthigh
= high
;
1813 #define SET_NAMESTRING() namestring = (char*)sh->iss
1814 #define CUR_SYMBOL_TYPE type_code
1815 #define CUR_SYMBOL_VALUE sh->value
1816 #define START_PSYMTAB(ofile,addr,fname,low,symoff,global_syms,static_syms)\
1818 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
1819 #define addr 0 /* FIXME, should be offset of addresses */
1820 #define HANDLE_RBRAC(val) \
1821 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
1822 #include "partial-stab.h"
1827 for (cur_sdx
= 0; cur_sdx
< fh
->csym
; ) {
1828 register struct partial_symbol
*p
;
1831 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
1833 if (MIPS_IS_STAB(sh
)) {
1838 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
1839 sh
->index
== 0xfffff) {
1840 /* FIXME, premature? */
1845 name
= (char *)(sh
->iss
);
1850 case stProc
: /* Asm labels apparently */
1851 case stStaticProc
: /* Function */
1852 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
1853 VAR_NAMESPACE
, LOC_BLOCK
,
1854 static_psymbols
, sh
->value
);
1855 /* Skip over procedure to next one. */
1856 cur_sdx
= (sh
->index
+ (AUXU
*)fh
->iauxBase
)->isym
;
1857 procaddr
= sh
->value
;
1859 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
- 1;
1860 if (sh
->st
!= stEnd
)
1862 high
= procaddr
+ sh
->value
;
1863 if (high
> pst
->texthigh
)
1864 pst
->texthigh
= high
;
1866 case stStatic
: /* Variable */
1869 case stTypedef
: /* Typedef */
1870 class = LOC_TYPEDEF
;
1872 case stConstant
: /* Constant decl */
1875 case stBlock
: /* { }, str, un, enum*/
1876 if (sh
->sc
== scInfo
) {
1877 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
1878 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1879 static_psymbols
, sh
->value
);
1881 /* Skip over the block */
1882 cur_sdx
= sh
->index
;
1884 case stFile
: /* File headers */
1885 case stLabel
: /* Labels */
1886 case stEnd
: /* Ends of files */
1889 complain (&unknown_sym_complaint
, SYMBOL_NAME(p
));
1890 complain (&unknown_st_complaint
, sh
->st
);
1894 /* Use this gdb symbol */
1895 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
1896 VAR_NAMESPACE
, class,
1897 static_psymbols
, sh
->value
);
1899 cur_sdx
++; /* Go to next file symbol */
1902 end_psymtab (save_pst
, psymtab_include_list
, includes_used
,
1903 -1, save_pst
->texthigh
,
1904 dependency_list
, dependencies_used
,
1905 global_psymbols
.next
, static_psymbols
.next
);
1906 if (entry_point
< save_pst
->texthigh
1907 && entry_point
>= save_pst
->textlow
) {
1908 startup_file_start
= save_pst
->textlow
;
1909 startup_file_end
= save_pst
->texthigh
;
1913 /* Mark the last code address, and remember it for later */
1914 hdr
->cbDnOffset
= end_of_text_seg
;
1916 free(&fdr_to_pst
[-1]);
1921 /* Do the initial analisys of the F_IDX-th file descriptor.
1922 Allocates a partial symtab for it, and builds the list
1923 of dependent files by recursion. LEV says at which level
1924 of recursion we are called (to pretty up debug traces) */
1926 static struct partial_symtab
*
1927 parse_fdr(f_idx
, lev
, objfile
)
1930 struct objfile
*objfile
;
1933 register struct partial_symtab
*pst
;
1936 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + f_idx
;
1938 /* Use this to indicate into which symtab this file was parsed */
1940 return (struct partial_symtab
*) fh
->ioptBase
;
1942 /* Debuggability level */
1943 if (compare_glevel(max_glevel
, fh
->glevel
) < 0)
1944 max_glevel
= fh
->glevel
;
1946 /* Make a new partial_symtab */
1947 pst
= new_psymtab(fh
->rss
, objfile
);
1952 pst
->textlow
= fh
->adr
;
1953 pst
->texthigh
= fh
->cpd
; /* To be fixed later */
1956 /* Make everything point to everything. */
1957 FDR_IDX(pst
) = f_idx
;
1958 fdr_to_pst
[f_idx
].pst
= pst
;
1959 fh
->ioptBase
= (int)pst
;
1961 /* Analyze its dependencies */
1966 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
1967 /* ...then presumably a .h file: drop reverse depends .h->.c */
1968 for (; s_id0
< fh
->crfd
; s_id0
++) {
1969 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
1971 s_id0
++; /* Skip self-dependency */
1976 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
1977 pst
->dependencies
= (struct partial_symtab
**)
1978 obstack_alloc (psymbol_obstack
,
1979 pst
->number_of_dependencies
*
1980 sizeof (struct partial_symtab
*));
1981 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
1982 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
1984 pst
->dependencies
[s_idx
-s_id0
] = parse_fdr(*rh
, lev
+1, objfile
);
1991 mips_next_symbol_text ()
1994 return (char*)((SYMR
*)cur_fdr
->isymBase
)[cur_sdx
].iss
;
1997 /* Ancillary function to psymtab_to_symtab(). Does all the work
1998 for turning the partial symtab PST into a symtab, recurring
1999 first on all dependent psymtabs. The argument FILENAME is
2000 only passed so we can see in debug stack traces what file
2004 psymtab_to_symtab_1(pst
, filename
)
2005 struct partial_symtab
*pst
;
2013 struct linetable
*lines
;
2019 /* How many symbols will we need */
2020 /* FIXME, this does not count enum values. */
2021 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
2022 if (FDR_IDX(pst
) == -1) {
2026 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + FDR_IDX(pst
);
2027 f_max
+= fh
->csym
+ fh
->cpd
;
2028 maxlines
= 2 * fh
->cline
;
2031 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2034 && strcmp(((SYMR
*)fh
->isymBase
)[1].iss
, stabs_symbol
) == 0;
2038 st
= new_symtab (pst
->filename
, 2 * f_max
, maxlines
,
2041 st
= new_symtab ("unknown", f_max
, 0, pst
->objfile
);
2042 lines
= LINETABLE(st
);
2043 pending_list
= (struct mips_pending
**) cur_hdr
->cbOptOffset
;
2044 if (pending_list
== 0) {
2045 pending_list
= (struct mips_pending
**)
2046 xzalloc(cur_hdr
->ifdMax
* sizeof(struct mips_pending
*));
2047 cur_hdr
->cbOptOffset
= (int)pending_list
;
2051 /* Read in all partial symbtabs on which this one is dependent.
2052 NOTE that we do have circular dependencies, sigh. We solved
2053 that by setting pst->readin before this point. */
2055 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2056 if (!pst
->dependencies
[i
]->readin
) {
2057 /* Inform about additional files to be read in. */
2060 fputs_filtered (" ", stdout
);
2062 fputs_filtered ("and ", stdout
);
2064 printf_filtered ("%s...",
2065 pst
->dependencies
[i
]->filename
);
2066 wrap_here (""); /* Flush output */
2069 /* We only pass the filename for debug purposes */
2070 psymtab_to_symtab_1(pst
->dependencies
[i
],
2071 pst
->dependencies
[i
]->filename
);
2075 /* Now read the symbols for this symtab */
2078 cur_fd
= FDR_IDX(pst
);
2081 /* Get a new lexical context */
2084 top_stack
->cur_st
= cur_stab
;
2085 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab
),
2087 BLOCK_START(top_stack
->cur_block
) = fh
? fh
->adr
: 0;
2088 BLOCK_END(top_stack
->cur_block
) = 0;
2089 top_stack
->blocktype
= stFile
;
2090 top_stack
->maxsyms
= 2*f_max
;
2091 top_stack
->cur_type
= 0;
2092 top_stack
->procadr
= 0;
2093 top_stack
->numargs
= 0;
2096 /* Parse locals and procedures */
2101 char *fh_name
= (char*)fh
->rss
;
2103 /* Parse local symbols first */
2109 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++) {
2110 register SYMR
*sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
2111 char *name
= (char*)sh
->iss
;
2112 CORE_ADDR valu
= sh
->value
;
2113 if (MIPS_IS_STAB(sh
)) {
2114 int type_code
= MIPS_UNMARK_STAB(sh
->index
);
2115 process_one_symbol (type_code
, 0, valu
, name
, /*FIXME*/ 0);
2117 else if (sh
->st
== stLabel
&& sh
->index
!= indexNil
) {
2118 /* Handle encoded stab line number. */
2119 record_line (current_subfile
, sh
->index
, valu
);
2122 st
= end_symtab (pst
->texthigh
, 0, 0, pst
->objfile
);
2125 /* BOUND is the highest core address of this file's procedures */
2126 int bound
= cur_fd
== cur_hdr
->ifdMax
- 1 ? cur_hdr
->cbDnOffset
2128 for (cur_sdx
= 0; cur_sdx
< fh
->csym
; ) {
2129 sh
= (SYMR
*) (fh
->isymBase
) + cur_sdx
;
2130 cur_sdx
+= parse_symbol(sh
, fh
->iauxBase
);
2133 /* Procedures next, note we need to look-ahead to
2134 find out where the procedure's code ends */
2136 for (i
= 0; i
< fh
->cpd
-1; i
++) {
2137 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2138 parse_procedure(pr
, pr
[1].adr
); /* next proc up */
2141 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2142 parse_procedure(pr
, bound
); /* next file up */
2144 /* Linenumbers. At the end, check if we can save memory */
2145 parse_lines(fh
, lines
);
2146 if (lines
->nitems
< fh
->cline
)
2147 lines
= shrink_linetable(lines
);
2152 LINETABLE(st
) = lines
;
2154 /* .. and our share of externals.
2155 XXX use the global list to speed up things here. how ?
2156 FIXME, Maybe quit once we have found the right number of ext's? */
2157 /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
2158 top_stack
->blocktype
= stFile
;
2159 top_stack
->maxsyms
=
2160 cur_hdr
->isymMax
+ cur_hdr
->ipdMax
+ cur_hdr
->iextMax
;
2162 for (i
= 0; i
< cur_hdr
->iextMax
; i
++) {
2163 register EXTR
*esh
= (EXTR
*) (cur_hdr
->cbExtOffset
) + i
;
2164 if (esh
->ifd
== cur_fd
)
2165 parse_external(esh
, 1);
2168 /* If there are undefined, tell the user */
2169 if (n_undef_symbols
) {
2170 printf_filtered("File %s contains %d unresolved references:",
2171 st
->filename
, n_undef_symbols
);
2172 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2173 n_undef_vars
, n_undef_procs
, n_undef_labels
);
2174 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
2180 /* Sort the symbol table now, we are done adding symbols to it.*/
2181 sort_symtab_syms(st
);
2185 /* Now link the psymtab and the symtab. */
2189 /* Ancillary parsing procedures. */
2191 /* Lookup the type at relative index RN. Return it in TPP
2192 if found and in any event come up with its name PNAME.
2193 Return value says how many aux symbols we ate */
2196 cross_ref(rn
, tpp
, type_code
, pname
)
2199 int type_code
; /* Use to alloc new type if none is found. */
2204 /* Escape index means 'the next one' */
2205 if (rn
->rfd
== 0xfff)
2206 rf
= *(unsigned *) (rn
+ 1);
2212 *pname
= "<undefined>";
2215 * Find the relative file descriptor and the symbol in it
2217 FDR
*fh
= get_rfd(cur_fd
, rf
);
2222 * If we have processed this symbol then we left a forwarding
2223 * pointer to the corresponding GDB symbol. If not, we`ll put
2224 * it in a list of pending symbols, to be processed later when
2225 * the file f will be. In any event, we collect the name for
2226 * the type here. Which is why we made a first pass at
2229 sh
= (SYMR
*) (fh
->isymBase
) + rn
->index
;
2231 /* Careful, we might be looking at .o files */
2232 *pname
= (UNSAFE_DATA_ADDR(sh
->iss
)) ? "<undefined>" :
2235 /* Have we parsed it ? */
2236 if ((!UNSAFE_DATA_ADDR(sh
->value
)) && (sh
->st
== stParsed
)) {
2237 t
= (struct type
*) sh
->value
;
2240 /* Avoid duplicates */
2241 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
2245 *tpp
= make_type(type_code
, 0, 0, 0);
2246 add_pending(fh
, sh
, *tpp
);
2251 /* We used one auxent normally, two if we got a "next one" rf. */
2252 return (rn
->rfd
== 0xfff? 2: 1);
2256 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2257 keeping the symtab sorted */
2259 static struct symbol
*
2260 mylookup_symbol (name
, block
, namespace, class)
2262 register struct block
*block
;
2263 enum namespace namespace;
2264 enum address_class
class;
2266 register int bot
, top
, inc
;
2267 register struct symbol
*sym
;
2270 top
= BLOCK_NSYMS(block
);
2273 sym
= BLOCK_SYM(block
, bot
);
2274 if (SYMBOL_NAME(sym
)[0] == inc
2275 && SYMBOL_NAMESPACE(sym
) == namespace
2276 && SYMBOL_CLASS(sym
) == class
2277 && !strcmp(SYMBOL_NAME(sym
), name
))
2281 if (block
= BLOCK_SUPERBLOCK (block
))
2282 return mylookup_symbol (name
, block
, namespace, class);
2287 /* Add a new symbol S to a block B.
2288 Infrequently, we will need to reallocate the block to make it bigger.
2289 We only detect this case when adding to top_stack->cur_block, since
2290 that's the only time we know how big the block is. FIXME. */
2297 int nsyms
= BLOCK_NSYMS(b
)++;
2298 struct block
*origb
;
2299 struct parse_stack
*stackp
;
2301 if (b
== top_stack
->cur_block
&&
2302 nsyms
>= top_stack
->maxsyms
) {
2303 complain (&block_overflow_complaint
, s
->name
);
2304 /* In this case shrink_block is actually grow_block, since
2305 BLOCK_NSYMS(b) is larger than its current size. */
2307 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
2309 /* Now run through the stack replacing pointers to the
2310 original block. shrink_block has already done this
2311 for the blockvector and BLOCK_FUNCTION. */
2312 for (stackp
= top_stack
; stackp
; stackp
= stackp
->next
) {
2313 if (stackp
->cur_block
== origb
) {
2314 stackp
->cur_block
= b
;
2315 stackp
->maxsyms
= BLOCK_NSYMS (b
);
2319 BLOCK_SYM(b
,nsyms
) = s
;
2322 /* Add a new block B to a symtab S */
2329 struct blockvector
*bv
= BLOCKVECTOR(s
);
2331 bv
= (struct blockvector
*)xrealloc(bv
, sizeof(struct blockvector
) +
2332 BLOCKVECTOR_NBLOCKS(bv
) * sizeof(bv
->block
));
2333 if (bv
!= BLOCKVECTOR(s
))
2334 BLOCKVECTOR(s
) = bv
;
2336 BLOCKVECTOR_BLOCK(bv
, BLOCKVECTOR_NBLOCKS(bv
)++) = b
;
2339 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2340 MIPS' linenumber encoding might need more than one byte
2341 to describe it, LAST is used to detect these continuation lines */
2344 add_line(lt
, lineno
, adr
, last
)
2345 struct linetable
*lt
;
2351 last
= -2; /* make sure we record first line */
2353 if (last
== lineno
) /* skip continuation lines */
2356 lt
->item
[lt
->nitems
].line
= lineno
;
2357 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
2363 /* Comparison functions, used when sorting things */
2365 /* Symtabs must be ordered viz the code segments they cover */
2368 compare_symtabs( s1
, s2
)
2369 struct symtab
**s1
, **s2
;
2371 /* "most specific" first */
2373 register struct block
*b1
, *b2
;
2374 b1
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1
),GLOBAL_BLOCK
);
2375 b2
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2
),GLOBAL_BLOCK
);
2376 if (BLOCK_END(b1
) == BLOCK_END(b2
))
2377 return BLOCK_START(b1
) - BLOCK_START(b2
);
2378 return BLOCK_END(b1
) - BLOCK_END(b2
);
2382 /* Partial Symtabs, same */
2385 compare_psymtabs( s1
, s2
)
2386 struct partial_symtab
**s1
, **s2
;
2388 /* Perf twist: put the ones with no code at the end */
2390 register int a
= (*s1
)->textlow
;
2391 register int b
= (*s2
)->textlow
;
2400 /* Blocks with a smaller low bound should come first */
2402 static int compare_blocks(b1
,b2
)
2403 struct block
**b1
, **b2
;
2405 register int addr_diff
;
2407 addr_diff
= (BLOCK_START((*b1
))) - (BLOCK_START((*b2
)));
2409 return (BLOCK_END((*b1
))) - (BLOCK_END((*b2
)));
2414 /* Sorting and reordering procedures */
2416 /* Sort the blocks of a symtab S.
2417 Reorder the blocks in the blockvector by code-address,
2418 as required by some MI search routines */
2424 struct blockvector
*bv
= BLOCKVECTOR(s
);
2426 if (BLOCKVECTOR_NBLOCKS(bv
) <= 2) {
2428 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) == 0)
2429 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = 0;
2430 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) == 0)
2431 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) = 0;
2435 * This is very unfortunate: normally all functions are compiled in
2436 * the order they are found, but if the file is compiled -O3 things
2437 * are very different. It would be nice to find a reliable test
2438 * to detect -O3 images in advance.
2440 if (BLOCKVECTOR_NBLOCKS(bv
) > 3)
2441 qsort(&BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
),
2442 BLOCKVECTOR_NBLOCKS(bv
) - FIRST_LOCAL_BLOCK
,
2443 sizeof(struct block
*),
2447 register CORE_ADDR high
= 0;
2448 register int i
, j
= BLOCKVECTOR_NBLOCKS(bv
);
2450 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
2451 if (high
< BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
)))
2452 high
= BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
));
2453 BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = high
;
2456 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) =
2457 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
));
2459 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2460 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2461 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2462 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2466 /* Constructor/restructor/destructor procedures */
2468 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2469 MAXSYMS and linenumbers MAXLINES we'll put in it */
2473 new_symtab(name
, maxsyms
, maxlines
, objfile
)
2476 struct symtab
*s
= allocate_symtab (name
, objfile
);
2478 LINETABLE(s
) = new_linetable(maxlines
);
2480 /* All symtabs must have at least two blocks */
2481 BLOCKVECTOR(s
) = new_bvect(2);
2482 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
) = new_block(maxsyms
);
2483 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), STATIC_BLOCK
) = new_block(maxsyms
);
2484 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
),STATIC_BLOCK
)) =
2485 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
);
2487 s
->free_code
= free_linetable
;
2489 /* Link the new symtab into the list of such. */
2490 s
->next
= symtab_list
;
2496 /* Allocate a new partial_symtab NAME */
2498 static struct partial_symtab
*
2499 new_psymtab(name
, objfile
)
2501 struct objfile
*objfile
;
2503 struct partial_symtab
*pst
;
2505 pst
= (struct partial_symtab
*)
2506 obstack_alloc (psymbol_obstack
, sizeof (*pst
));
2507 memset (pst
, 0, sizeof (*pst
));
2509 if (name
== (char*)-1) /* FIXME -- why not null here? */
2510 pst
->filename
= "<no name>";
2512 pst
->filename
= name
;
2514 /* Chain it to its object file */
2515 pst
->objfile
= objfile
;
2516 pst
->objfile_chain
= objfile
->psymtabs
;
2517 objfile
->psymtabs
= pst
;
2519 pst
->next
= partial_symtab_list
;
2520 partial_symtab_list
= pst
;
2522 /* Keep a backpointer to the file's symbols */
2523 pst
->read_symtab_private
= (char *) obstack_alloc (psymbol_obstack
,
2524 sizeof (struct symloc
));
2525 CUR_HDR(pst
) = cur_hdr
;
2527 /* The way to turn this into a symtab is to call... */
2528 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
2534 /* Allocate a linetable array of the given SIZE */
2536 static struct linetable
*
2539 struct linetable
*l
;
2541 size
= size
* sizeof(l
->item
) + sizeof(struct linetable
);
2542 l
= (struct linetable
*)xmalloc(size
);
2547 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2548 I am not so sure about the 3.4 ones */
2550 static struct linetable
*
2551 shrink_linetable(lt
)
2552 struct linetable
* lt
;
2554 struct linetable
*l
= new_linetable(lt
->nitems
);
2556 memcpy(l
, lt
, lt
->nitems
* sizeof(l
->item
) + sizeof(struct linetable
));
2561 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2564 struct blockvector
*
2567 struct blockvector
*bv
;
2570 size
= sizeof(struct blockvector
) + nblocks
* sizeof(struct block
*);
2571 bv
= (struct blockvector
*) xzalloc(size
);
2573 BLOCKVECTOR_NBLOCKS(bv
) = nblocks
;
2578 /* Allocate and zero a new block of MAXSYMS symbols */
2584 int size
= sizeof(struct block
) + (maxsyms
-1) * sizeof(struct symbol
*);
2585 struct block
*b
= (struct block
*)xzalloc(size
);
2590 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2591 Shrink_block can also be used by add_symbol to grow a block. */
2593 static struct block
*
2599 struct blockvector
*bv
= BLOCKVECTOR(s
);
2602 /* Just reallocate it and fix references to the old one */
2604 new = (struct block
*) xrealloc ((char *)b
, sizeof(struct block
) +
2605 (BLOCK_NSYMS(b
)-1) * sizeof(struct symbol
*));
2607 /* Should chase pointers to old one. Fortunately, that`s just
2608 the block`s function and inferior blocks */
2609 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b
)
2610 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2611 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2612 if (BLOCKVECTOR_BLOCK(bv
,i
) == b
)
2613 BLOCKVECTOR_BLOCK(bv
,i
) = new;
2614 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) == b
)
2615 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) = new;
2619 /* Create a new symbol with printname NAME */
2626 struct symbol
*s
= (struct symbol
*)
2627 obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
2629 memset (s
, 0, sizeof (*s
));
2630 SYMBOL_NAME(s
) = name
;
2634 /* Create a new type with printname NAME */
2641 struct type
*t
= (struct type
*)
2642 obstack_alloc (symbol_obstack
, sizeof (struct type
));
2644 memset (t
, 0, sizeof (*t
));
2645 TYPE_VPTR_FIELDNO (t
) = -1;
2646 TYPE_NAME(t
) = name
;
2647 TYPE_CPLUS_SPECIFIC(t
) = &cplus_struct_default
;
2651 /* Create and initialize a new type with printname NAME.
2652 CODE and LENGTH are the initial info we put in,
2653 UNS says whether the type is unsigned or not. */
2657 make_type(code
, length
, uns
, name
)
2658 enum type_code code
;
2662 register struct type
*type
;
2664 /* FIXME, I don't think this ever gets freed. */
2665 type
= (struct type
*) xzalloc(sizeof(struct type
));
2666 TYPE_CODE(type
) = code
;
2667 TYPE_LENGTH(type
) = length
;
2668 TYPE_FLAGS(type
) = uns
? TYPE_FLAG_UNSIGNED
: 0;
2669 TYPE_NAME(type
) = name
;
2670 TYPE_VPTR_FIELDNO (type
) = -1;
2672 if (code
!= TYPE_CODE_METHOD
&& code
!= TYPE_CODE_FUNC
)
2673 TYPE_CPLUS_SPECIFIC(type
) = &cplus_struct_default
;
2677 /* Things used for calling functions in the inferior.
2678 These functions are exported to our companion
2679 mips-tdep.c file and are here because they play
2680 with the symbol-table explicitly. */
2682 /* Sigtramp: make sure we have all the necessary information
2683 about the signal trampoline code. Since the official code
2684 from MIPS does not do so, we make up that information ourselves.
2685 If they fix the library (unlikely) this code will neutralize itself. */
2692 struct block
*b
, *b0
;
2694 sigtramp_address
= -1;
2696 /* We know it is sold as sigvec */
2697 s
= lookup_symbol("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
2699 /* Most programs do not play with signals */
2703 b0
= SYMBOL_BLOCK_VALUE(s
);
2705 /* A label of sigvec, to be more precise */
2706 s
= lookup_symbol("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
2708 /* But maybe this program uses its own version of sigvec */
2712 sigtramp_address
= SYMBOL_VALUE(s
);
2713 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
2715 /* Did we or MIPSco fix the library ? */
2716 if (SYMBOL_CLASS(s
) == LOC_BLOCK
)
2719 /* But what symtab does it live in ? */
2720 st
= find_pc_symtab(SYMBOL_VALUE(s
));
2723 * Ok, there goes the fix: turn it into a procedure, with all the
2724 * needed info. Note we make it a nested procedure of sigvec,
2725 * which is the way the (assembly) code is actually written.
2727 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2728 SYMBOL_CLASS(s
) = LOC_BLOCK
;
2729 SYMBOL_TYPE(s
) = make_type(TYPE_CODE_FUNC
, 4, 0, 0);
2730 TYPE_TARGET_TYPE(SYMBOL_TYPE(s
)) = builtin_type_void
;
2732 /* Need a block to allocate .gdbinfo. in */
2734 SYMBOL_BLOCK_VALUE(s
) = b
;
2735 BLOCK_START(b
) = sigtramp_address
;
2736 BLOCK_END(b
) = sigtramp_end
;
2737 BLOCK_FUNCTION(b
) = s
;
2738 BLOCK_SUPERBLOCK(b
) = BLOCK_SUPERBLOCK(b0
);
2742 /* Make a .gdbinfo. for it */
2744 struct mips_extra_func_info
*e
=
2745 (struct mips_extra_func_info
*)
2746 xzalloc(sizeof(struct mips_extra_func_info
));
2748 e
->numargs
= 0; /* the kernel thinks otherwise */
2749 /* align_longword(sigcontext + SIGFRAME) */
2750 e
->framesize
= 0x150;
2751 e
->framereg
= SP_REGNUM
;
2754 e
->regoffset
= -(41 * sizeof(int));
2756 e
->fregoffset
= -(37 * sizeof(int));
2759 s
= new_symbol(".gdbinfo.");
2760 SYMBOL_VALUE(s
) = (int) e
;
2761 SYMBOL_NAMESPACE(s
) = LABEL_NAMESPACE
;
2762 SYMBOL_CLASS(s
) = LOC_CONST
;
2763 SYMBOL_TYPE(s
) = builtin_type_void
;
2766 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
2769 /* Initialization */
2771 static struct sym_fns ecoff_sym_fns
= {"ecoff", 5,
2772 mipscoff_new_init
, mipscoff_symfile_init
,
2773 mipscoff_symfile_read
};
2775 _initialize_mipsread ()
2777 add_symtab_fns (&ecoff_sym_fns
);
2779 /* Missing basic types */
2780 builtin_type_string
= make_type(TYPE_CODE_PASCAL_ARRAY
,
2782 builtin_type_complex
= make_type(TYPE_CODE_FLT
,
2783 2 * sizeof(float), 0, "complex");
2784 builtin_type_double_complex
= make_type(TYPE_CODE_FLT
,
2785 2 * sizeof(double), 0, "double_complex");
2786 builtin_type_fixed_dec
= make_type(TYPE_CODE_INT
, sizeof(int),
2787 0, "fixed_decimal");
2788 builtin_type_float_dec
= make_type(TYPE_CODE_FLT
, sizeof(double),
2789 0, "floating_decimal");