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 gcc/config/xm-mips.h.
64 At some point, these should probably go into a shared include file,
65 but currently gcc and gdb do not share any directories. */
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 PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
82 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
83 #define CUR_HDR(p) (PST_PRIVATE(p)->cur_hdr)
88 EXTR
**extern_tab
; /* Pointer to external symbols for this file. */
89 int extern_count
; /* Size of extern_tab. */
92 /* Things we import explicitly from other modules */
94 extern int info_verbose
;
95 extern struct block
*block_for_pc();
96 extern void sort_symtab_syms();
98 /* Various complaints about symbol reading that don't abort the process */
100 struct complaint unknown_ext_complaint
=
101 {"unknown external symbol %s", 0, 0};
103 struct complaint unknown_sym_complaint
=
104 {"unknown local symbol %s", 0, 0};
106 struct complaint unknown_st_complaint
=
107 {"with type %d", 0, 0};
109 struct complaint block_overflow_complaint
=
110 {"block containing %s overfilled", 0, 0};
112 struct complaint basic_type_complaint
=
113 {"cannot map MIPS basic type 0x%x", 0, 0};
115 struct complaint unknown_type_qual_complaint
=
116 {"unknown type qualifier 0x%x", 0, 0};
118 struct complaint array_bitsize_complaint
=
119 {"size of array target type not known, assuming %d bits", 0, 0};
121 struct complaint array_parse_complaint
=
122 {"array type with strange relative symbol", 0, 0};
124 struct complaint bad_tag_guess_complaint
=
125 {"guessed tag type incorrectly", 0, 0};
127 /* Macros and extra defs */
129 /* Already-parsed symbols are marked specially */
131 #define stParsed stType
133 /* Puns: hard to find whether -g was used and how */
135 #define MIN_GLEVEL GLEVEL_0
136 #define compare_glevel(a,b) \
137 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
138 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
140 /* When looking at .o files, avoid tripping over bad addresses */
142 #define SAFE_TEXT_ADDR 0x400000
143 #define SAFE_DATA_ADDR 0x10000000
145 #define UNSAFE_DATA_ADDR(p) ((unsigned)p < SAFE_DATA_ADDR || (unsigned)p > 2*SAFE_DATA_ADDR)
147 /* Things that really are local to this module */
149 /* GDB symtable for the current compilation unit */
151 static struct symtab
*cur_stab
;
153 /* MIPS symtab header for the current file */
155 static HDRR
*cur_hdr
;
157 /* Pointer to current file decriptor record, and its index */
162 /* Index of current symbol */
166 /* Note how much "debuggable" this image is. We would like
167 to see at least one FDR with full symbols */
172 /* When examining .o files, report on undefined symbols */
174 static int n_undef_symbols
, n_undef_labels
, n_undef_vars
, n_undef_procs
;
176 /* Pseudo symbol to use when putting stabs into the symbol table. */
178 static char stabs_symbol
[] = STABS_SYMBOL
;
180 /* Extra builtin types */
182 struct type
*builtin_type_complex
;
183 struct type
*builtin_type_double_complex
;
184 struct type
*builtin_type_fixed_dec
;
185 struct type
*builtin_type_float_dec
;
186 struct type
*builtin_type_string
;
188 /* Forward declarations */
190 static struct symbol
*new_symbol();
191 static struct type
*new_type();
192 static struct block
*new_block();
193 static struct symtab
*new_symtab();
194 static struct linetable
*new_linetable();
195 static struct blockvector
*new_bvect();
197 static struct type
*parse_type();
198 static struct type
*make_type();
199 static struct symbol
*mylookup_symbol();
200 static struct block
*shrink_block();
201 static void sort_blocks();
203 static int compare_symtabs();
204 static int compare_psymtabs();
205 static int compare_blocks();
207 static struct partial_symtab
*new_psymtab();
208 static struct partial_symtab
*parse_fdr();
209 static int compare_psymbols();
211 static void psymtab_to_symtab_1();
212 static void add_block();
213 static void add_symbol();
214 static int add_line();
215 static struct linetable
*shrink_linetable();
216 static char* mips_next_symbol_text ();
219 /* Things we export to other modules */
221 /* Address bounds for the signal trampoline in inferior, if any */
222 /* FIXME: Nothing really seems to use this. Why is it here? */
224 CORE_ADDR sigtramp_address
, sigtramp_end
;
226 /* The entry point (starting address) of the file, if it is an executable. */
228 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
229 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
234 /* If we have a file symbol header lying around, blow it away. */
236 free ((char *)cur_hdr
);
241 mipscoff_symfile_init (sf
)
244 sf
->sym_private
= NULL
;
248 mipscoff_symfile_read(sf
, addr
, mainline
)
253 struct coff_symfile_info
*info
= (struct coff_symfile_info
*)sf
->sym_private
;
254 bfd
*abfd
= sf
->objfile
->obfd
;
255 char *name
= bfd_get_filename (abfd
);
259 int stringtab_offset
;
261 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
262 desc
= fileno ((FILE *)(abfd
->iostream
)); /* Raw file descriptor */
265 /* Position to read the symbol table. */
266 val
= lseek (desc
, (long)symtab_offset
, 0);
268 perror_with_name (name
);
270 init_misc_bunches ();
271 make_cleanup (discard_misc_bunches
, 0);
273 /* Now that the executable file is positioned at symbol table,
274 process it and define symbols accordingly. */
276 read_mips_symtab(sf
->objfile
, desc
);
278 /* Go over the misc symbol bunches and install them in vector. */
280 condense_misc_bunches (!mainline
);
283 /* Exported procedure: Allocate zeroed memory */
288 char *p
= xmalloc(size
);
294 /* Exported procedure: Builds a symtab from the PST partial one.
295 Restores the environment in effect when PST was created, delegates
296 most of the work to an ancillary procedure, and sorts
297 and reorders the symtab list at the end */
300 mipscoff_psymtab_to_symtab(pst
)
301 struct partial_symtab
*pst
;
310 printf_filtered("Reading in symbols for %s...", pst
->filename
);
313 /* Restore the header and list of pending typedefs */
314 cur_hdr
= CUR_HDR(pst
);
316 next_symbol_text_func
= mips_next_symbol_text
;
318 psymtab_to_symtab_1(pst
, pst
->filename
);
320 /* Match with global symbols. This only needs to be done once,
321 after all of the symtabs and dependencies have been read in. */
322 scan_file_globals ();
325 printf_filtered("done.\n");
328 /* Exported procedure: Is PC in the signal trampoline code */
331 in_sigtramp(pc
, name
)
335 if (sigtramp_address
== 0)
337 return (pc
>= sigtramp_address
&& pc
< sigtramp_end
);
340 /* File-level interface functions */
342 /* Read the symtab information from file FSYM into memory. Also,
343 return address just past end of our text segment in *END_OF_TEXT_SEGP. */
346 read_the_mips_symtab(abfd
, fsym
, end_of_text_segp
)
349 CORE_ADDR
*end_of_text_segp
;
351 int stsize
, st_hdrsize
;
354 /* Header for executable/object file we read symbols from */
355 struct coff_exec filhdr
;
357 /* We get here with DESC pointing to the symtab header. But we need
358 * other info from the initial headers */
360 myread(fsym
, &filhdr
, sizeof filhdr
);
362 if (end_of_text_segp
)
364 bfd_h_get_32 (abfd
, filhdr
.a
.text_start
) +
365 bfd_h_get_32 (abfd
, filhdr
.a
.tsize
);
367 /* Find and read the symbol table header */
368 st_hdrsize
= bfd_h_get_32 (abfd
, filhdr
.f
.f_nsyms
);
369 st_filptr
= bfd_h_get_32 (abfd
, filhdr
.f
.f_symptr
);
373 lseek(fsym
, st_filptr
, L_SET
);
374 if (st_hdrsize
> sizeof (st_hdr
)) /* Profanity check */
376 if (read(fsym
, &st_hdr
, st_hdrsize
) != st_hdrsize
)
379 /* Find out how large the symbol table is */
380 stsize
= (st_hdr
.cbExtOffset
- (st_filptr
+ st_hdrsize
))
381 + st_hdr
.iextMax
* cbEXTR
;
383 /* Allocate space for the symbol table. Read it in. */
384 cur_hdr
= (HDRR
*) xmalloc(stsize
+ st_hdrsize
);
386 memcpy(cur_hdr
, &st_hdr
, st_hdrsize
);
387 if (read(fsym
, (char *) cur_hdr
+ st_hdrsize
, stsize
) != stsize
)
390 /* Fixup file_pointers in it */
391 fixup_symtab(cur_hdr
, (char *) cur_hdr
+ st_hdrsize
,
392 st_filptr
+ st_hdrsize
);
396 error("Short read on %s", bfd_get_filename (abfd
));
400 /* Turn all file-relative pointers in the symtab described by HDR
401 into memory pointers, given that the symtab itself is located
402 at DATA in memory and F_PTR in the file. */
405 fixup_symtab( hdr
, data
, f_ptr
)
417 * These fields are useless (and empty) by now:
418 * hdr->cbDnOffset, hdr->cbOptOffset
419 * We use them for other internal purposes.
422 hdr
->cbOptOffset
= 0;
425 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
441 * Fix all string pointers inside the symtab, and
442 * the FDR records. Also fix other miscellany.
444 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
445 register unsigned code_offset
;
447 /* Header itself, and strings */
448 fh
= (FDR
*) (hdr
->cbFdOffset
) + f_idx
;
449 fh
->issBase
+= hdr
->cbSsOffset
;
451 fh
->rss
= (long)fh
->rss
+ fh
->issBase
;
454 fh
->isymBase
= (int)((SYMR
*)(hdr
->cbSymOffset
)+fh
->isymBase
);
456 /* FIXME! Probably don't want to do this here! */
457 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
458 sh
= (SYMR
*)fh
->isymBase
+ s_idx
;
459 sh
->iss
= (long) sh
->iss
+ fh
->issBase
;
465 /* cannot fix fh->ipdFirst because it is a short */
466 #define IPDFIRST(h,fh) \
467 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
469 /* Optional symbols (actually used for partial_symtabs) */
475 fh
->iauxBase
= hdr
->cbAuxOffset
+ fh
->iauxBase
* sizeof(AUXU
);
476 /* Relative file descriptor table */
477 fh
->rfdBase
= hdr
->cbRfdOffset
+ fh
->rfdBase
* sizeof(RFDT
);
481 fh
->cbLineOffset
+= hdr
->cbLineOffset
;
483 /* Procedure symbols. (XXX This should be done later) */
484 code_offset
= fh
->adr
;
485 for (s_idx
= 0; s_idx
< fh
->cpd
; s_idx
++) {
486 unsigned name
, only_ext
;
488 pr
= (PDR
*)(IPDFIRST(hdr
,fh
)) + s_idx
;
490 /* Simple rule to find files linked "-x" */
491 only_ext
= fh
->rss
== -1;
493 if (pr
->isym
== -1) {
494 /* static function */
498 name
= hdr
->cbExtOffset
+ pr
->isym
* sizeof(EXTR
);
499 sh
= &((EXTR
*)name
)->asym
;
503 sh
= (SYMR
*)fh
->isymBase
+ pr
->isym
;
504 /* Included code ? */
505 if (s_idx
== 0 && pr
->adr
!= 0)
506 code_offset
-= pr
->adr
;
509 /* Turn index into a pointer */
512 /* Fix line numbers */
513 pr
->cbLineOffset
+= fh
->cbLineOffset
;
515 /* Relocate address */
517 pr
->adr
+= code_offset
;
521 /* External symbols: fix string */
522 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
523 esh
= (EXTR
*)(hdr
->cbExtOffset
) + s_idx
;
524 esh
->asym
.iss
= esh
->asym
.iss
+ hdr
->cbSsExtOffset
;
529 /* Find a file descriptor given its index RF relative to a file CF */
537 f
= (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
538 /* Object files do not have the RFD table, all refs are absolute */
540 return (FDR
*) (cur_hdr
->cbFdOffset
) + rf
;
541 cf
= *((pRFDT
) f
->rfdBase
+ rf
);
542 return (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
545 /* Return a safer print NAME for a file descriptor */
551 if (name
== (char *) -1)
552 return "<stripped file>";
553 if (UNSAFE_DATA_ADDR(name
))
559 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
560 whether we are adding to the general symtab or not.
561 FIXME: INCREMENTAL is currently always zero, though it should not be. */
564 read_mips_symtab (objfile
, desc
)
565 struct objfile
*objfile
;
568 CORE_ADDR end_of_text_seg
;
570 read_the_mips_symtab(objfile
->obfd
, desc
, &end_of_text_seg
);
572 parse_partial_symbols(end_of_text_seg
, objfile
);
576 * Check to make sure file was compiled with -g.
577 * If not, warn the user of this limitation.
579 if (compare_glevel(max_glevel
, GLEVEL_2
) < 0) {
580 if (max_gdbinfo
== 0)
582 "\n%s not compiled with -g, debugging support is limited.\n",
585 "You should compile with -g2 or -g3 for best debugging support.\n");
591 /* Local utilities */
593 /* Map of FDR indexes to partial symtabs */
596 struct partial_symtab
*pst
; /* the psymtab proper */
597 int n_globals
; /* exported globals (external symbols) */
598 int globals_offset
; /* cumulative */
602 /* Utility stack, used to nest procedures and blocks properly.
603 It is a doubly linked list, to avoid too many alloc/free.
604 Since we might need it quite a few times it is NOT deallocated
607 static struct parse_stack
{
608 struct parse_stack
*next
, *prev
;
609 struct symtab
*cur_st
; /* Current symtab. */
610 struct block
*cur_block
; /* Block in it. */
611 int blocktype
; /* What are we parsing. */
612 int maxsyms
; /* Max symbols in this block. */
613 struct type
*cur_type
; /* Type we parse fields for. */
614 int cur_field
; /* Field number in cur_type. */
615 int procadr
; /* Start addres of this procedure */
616 int numargs
; /* Its argument count */
617 } *top_stack
; /* Top stack ptr */
620 /* Enter a new lexical context */
622 static push_parse_stack()
624 struct parse_stack
*new;
626 /* Reuse frames if possible */
627 if (top_stack
&& top_stack
->prev
)
628 new = top_stack
->prev
;
630 new = (struct parse_stack
*) xzalloc(sizeof(struct parse_stack
));
631 /* Initialize new frame with previous content */
633 register struct parse_stack
*prev
= new->prev
;
636 top_stack
->prev
= new;
638 new->next
= top_stack
;
643 /* Exit a lexical context */
645 static pop_parse_stack()
650 top_stack
= top_stack
->next
;
654 /* Cross-references might be to things we haven't looked at
655 yet, e.g. type references. To avoid too many type
656 duplications we keep a quick fixup table, an array
657 of lists of references indexed by file descriptor */
659 static struct mips_pending
{
660 struct mips_pending
*next
; /* link */
661 SYMR
*s
; /* the symbol */
662 struct type
*t
; /* its partial type descriptor */
666 /* Check whether we already saw symbol SH in file FH as undefined */
669 struct mips_pending
*is_pending_symbol(fh
, sh
)
673 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
674 register struct mips_pending
*p
;
676 /* Linear search is ok, list is typically no more than 10 deep */
677 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
683 /* Check whether we already saw type T in file FH as undefined */
686 struct mips_pending
*is_pending_type(fh
, t
)
690 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
691 register struct mips_pending
*p
;
693 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
699 /* Add a new undef symbol SH of type T */
702 add_pending(fh
, sh
, t
)
707 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
708 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
710 /* Make sure we do not make duplicates */
712 p
= (struct mips_pending
*) xmalloc(sizeof(*p
));
715 p
->next
= pending_list
[f_idx
];
716 pending_list
[f_idx
] = p
;
718 sh
->reserved
= 1; /* for quick check */
721 /* Throw away undef entries when done with file index F_IDX */
726 register struct mips_pending
*p
, *q
;
728 for (p
= pending_list
[f_idx
]; p
; p
= q
) {
732 pending_list
[f_idx
] = 0;
735 /* The number of args to a procedure is not explicit in the symtab,
736 this is the list of all those we know of.
737 This makes parsing more reasonable and avoids extra passes */
739 static struct numarg
{
740 struct numarg
*next
; /* link */
741 unsigned adr
; /* procedure's start address */
742 unsigned num
; /* arg count */
745 /* Record that the procedure at ADR takes NUM arguments. */
750 struct numarg
*n
= (struct numarg
*) xmalloc(sizeof(struct numarg
));
754 n
->next
= numargs_list
;
758 /* See if we know how many arguments the procedure at ADR takes */
763 struct numarg
*n
= numargs_list
;
765 while (n
&& n
->adr
!= adr
)
767 return (n
) ? n
->num
: -1;
770 /* Release storage when done with this file */
775 struct numarg
*n
= numargs_list
, *m
;
786 /* Parsing Routines proper. */
788 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
789 For blocks, procedures and types we open a new lexical context.
790 This is basically just a big switch on the symbol's type.
791 Return count of SYMR's handled (normally one). */
804 /* When a symbol is cross-referenced from other files/symbols
805 we mark it explicitly */
806 int pend
= (sh
->reserved
== 1);
807 enum address_class
class;
814 case stGlobal
: /* external symbol, goes into global block */
816 b
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
818 s
= new_symbol(sh
->iss
);
819 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
822 case stStatic
: /* static data, goes into current block. */
824 b
= top_stack
->cur_block
;
825 s
= new_symbol(sh
->iss
);
826 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
829 case stLocal
: /* local variable, goes into current block */
830 if (sh
->sc
== scRegister
) {
831 class = LOC_REGISTER
;
836 b
= top_stack
->cur_block
;
837 s
= new_symbol(sh
->iss
);
838 SYMBOL_VALUE(s
) = sh
->value
;
840 data
: /* Common code for symbols describing data */
841 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
842 SYMBOL_CLASS(s
) = class;
845 /* Type could be missing in a number of cases */
846 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
847 sh
->index
== 0xfffff)
848 SYMBOL_TYPE(s
) = builtin_type_int
; /* undefined? */
850 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
851 /* Value of a data symbol is its memory address */
854 case stParam
: /* arg to procedure, goes into current block */
856 top_stack
->numargs
++;
858 name
= (char*)sh
->iss
;
859 /* Special GNU C++ name. */
860 if (name
[0] == CPLUS_MARKER
&& name
[1] == 't' && name
[2] == 0)
862 s
= new_symbol(name
);
864 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
865 if (sh
->sc
== scRegister
) {
866 SYMBOL_CLASS(s
) = LOC_REGPARM
;
870 SYMBOL_CLASS(s
) = LOC_ARG
;
871 SYMBOL_VALUE(s
) = sh
->value
;
872 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
873 add_symbol(s
, top_stack
->cur_block
);
875 /* FIXME: This has not been tested. See dbxread.c */
876 /* Add the type of this parameter to the function/procedure
877 type of this block. */
878 add_param_to_type(&top_stack
->cur_block
->function
->type
,s
);
882 case stLabel
: /* label, goes into current block */
883 s
= new_symbol(sh
->iss
);
884 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
; /* so that it can be used */
885 SYMBOL_CLASS(s
) = LOC_LABEL
; /* but not misused */
886 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
887 SYMBOL_TYPE(s
) = builtin_type_int
;
888 add_symbol(s
, top_stack
->cur_block
);
891 case stProc
: /* Procedure, usually goes into global block */
892 case stStaticProc
: /* Static procedure, goes into current block */
893 s
= new_symbol(sh
->iss
);
894 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
895 SYMBOL_CLASS(s
) = LOC_BLOCK
;
896 /* Type of the return value */
897 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
898 t
= builtin_type_int
;
900 t
= parse_type(ax
+ sh
->index
, sh
, 0);
901 b
= top_stack
->cur_block
;
902 if (sh
->st
== stProc
) {
903 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
904 /* The next test should normally be true,
905 but provides a hook for nested functions
906 (which we don't want to make global). */
907 if (b
== BLOCKVECTOR_BLOCK(bv
, STATIC_BLOCK
))
908 b
= BLOCKVECTOR_BLOCK(bv
, GLOBAL_BLOCK
);
912 /* Make a type for the procedure itself */
914 /* FIXME: This has not been tested yet! See dbxread.c */
915 /* Generate a template for the type of this function. The
916 types of the arguments will be added as we read the symbol
918 bcopy(SYMBOL_TYPE(s
),lookup_function_type(t
),sizeof(struct type
));
920 SYMBOL_TYPE(s
) = lookup_function_type (t
);
923 /* Create and enter a new lexical context */
924 b
= new_block(top_stack
->maxsyms
);
925 SYMBOL_BLOCK_VALUE(s
) = b
;
926 BLOCK_FUNCTION(b
) = s
;
927 BLOCK_START(b
) = BLOCK_END(b
) = sh
->value
;
928 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
929 add_block(b
, top_stack
->cur_st
);
931 /* Not if we only have partial info */
932 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
936 top_stack
->cur_block
= b
;
937 top_stack
->blocktype
= sh
->st
;
938 top_stack
->cur_type
= SYMBOL_TYPE(s
);
939 top_stack
->cur_field
= -1;
940 top_stack
->procadr
= sh
->value
;
941 top_stack
->numargs
= 0;
943 sh
->value
= (long) SYMBOL_TYPE(s
);
947 #ifndef btVoid /* btVoid was added late. */
950 /* These new symbol types have been recently added to SGI machines. */
964 case stBlock
: /* Either a lexical block, or some type */
966 top_stack
->blocktype
= stBlock
;
967 if (sh
->sc
== scInfo
) { /* structure/union/enum def */
969 sh
->st
== stStruct
? TYPE_CODE_STRUCT
970 : sh
->st
== stUnion
? TYPE_CODE_UNION
971 : sh
->st
== stEnum
? TYPE_CODE_ENUM
978 s
= new_symbol(sh
->iss
);
979 SYMBOL_NAMESPACE(s
) = STRUCT_NAMESPACE
;
980 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
982 add_symbol(s
, top_stack
->cur_block
);
983 /* If this type was expected, use its partial definition */
985 t
= is_pending_symbol(cur_fdr
, sh
)->t
;
987 t
= new_type(sh
->iss
);
989 /* First count the number of fields. */
990 for (tsym
= sh
+1; tsym
->st
!= stEnd
; tsym
++)
991 if (tsym
->st
== stMember
) {
992 if (nfields
== 0 && type_code
== TYPE_CODE_UNDEF
)
993 /* If the type of the member is Void,
994 assume the tag is an enumeration. */
995 if (tsym
->index
== indexNil
996 || ax
[tsym
->index
].ti
.bt
== btVoid
)
997 type_code
= TYPE_CODE_ENUM
;
999 if (tsym
->value
> max_value
)
1000 max_value
= tsym
->value
;
1002 else if (tsym
->st
== stBlock
1003 || tsym
->st
== stParsed
) {
1004 if (tsym
->sc
== scVariant
) ; /*UNIMPLEMENTED*/
1005 if (tsym
->index
!= 0)
1006 tsym
= ((SYMR
*)cur_fdr
->isymBase
)
1011 /* There is no guaranteed way to distinguish struct,
1012 unions, and enums at this point. This is a bug in the
1013 original design (that has been fixed with the
1014 recent addition of the stStruct, stUnion, and stEnum
1015 symbol types.) The way you can tell is if/when you
1016 see a variable or field of that type: In that case
1017 the variable's type (in the AUX table) says if the
1018 type is struct, union, or enum,
1019 and points back to the stBlock here.
1020 So you can patch the tag kind up later - but only
1021 if there actually is a variable or field of that type.
1023 So until we know for sure, we will guess at this point.
1025 If the first member has index==indexNil or a void type,
1026 assume we have an enumeration.
1027 Otherwise, if all the members have offset 0,
1028 assume we have a union.
1029 Otherwise, assume we have a struct.
1031 The heuristic could guess wrong in the case of
1032 of an enumeration with no members or a union
1033 with one (or zero) members, or when all except the
1034 last field of a struct have width zero.
1035 These are uncommon and/or illegal situations, and
1036 in any case guessing wrong probably doesn't matter much.
1038 But if we later do find out we were wrong,
1039 we fixup the tag kind. Members of an enumeration
1040 must be handled differently from struct/union fields,
1041 and that is harder to patch up, but luckily we
1042 shouldn't need to. (If there are any enumeration
1043 members, we can tell for sure it's an enum here.) */
1045 if (type_code
== TYPE_CODE_UNDEF
)
1046 if (max_value
== 0) type_code
= TYPE_CODE_UNION
;
1047 else type_code
= TYPE_CODE_STRUCT
;
1049 TYPE_CODE(t
) = type_code
;
1050 TYPE_NFIELDS(t
) = nfields
;
1051 TYPE_FIELDS(t
) = f
= (struct field
*)
1052 obstack_alloc (symbol_obstack
,
1053 nfields
* sizeof (struct field
));
1055 if (type_code
== TYPE_CODE_ENUM
) {
1056 /* This is a non-empty enum. */
1057 while (sh
[1].st
== stMember
) {
1058 struct symbol
*enum_sym
;
1060 f
->bitpos
= sh
->value
;
1062 f
->name
= (char*)sh
->iss
;
1065 enum_sym
= (struct symbol
*)
1066 obstack_alloc (symbol_obstack
,
1067 sizeof (struct symbol
));
1068 memset (enum_sym
, 0, sizeof (struct symbol
));
1069 SYMBOL_NAME (enum_sym
) = f
->name
;
1070 SYMBOL_CLASS (enum_sym
) = LOC_CONST
;
1071 SYMBOL_TYPE (enum_sym
) = t
;
1072 SYMBOL_NAMESPACE (enum_sym
) = VAR_NAMESPACE
;
1073 SYMBOL_VALUE (enum_sym
) = sh
->value
;
1074 add_symbol(enum_sym
, top_stack
->cur_block
);
1076 /* Skip the stMembers that we've handled. */
1082 /* make this the current type */
1083 top_stack
->cur_type
= t
;
1084 top_stack
->cur_field
= 0;
1085 TYPE_LENGTH(t
) = sh
->value
;
1086 /* Mark that symbol has a type, and say which one */
1087 sh
->value
= (long) t
;
1089 /* beginnning of (code) block. Value of symbol
1090 is the displacement from procedure start */
1091 b
= new_block(top_stack
->maxsyms
);
1092 BLOCK_START(b
) = sh
->value
+ top_stack
->procadr
;
1093 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1094 top_stack
->cur_block
= b
;
1095 add_block(b
, top_stack
->cur_st
);
1099 case stEnd
: /* end (of anything) */
1100 if (sh
->sc
== scInfo
) {
1101 /* Finished with type */
1102 top_stack
->cur_type
= 0;
1103 } else if (sh
->sc
== scText
&&
1104 (top_stack
->blocktype
== stProc
||
1105 top_stack
->blocktype
== stStaticProc
)) {
1106 /* Finished with procedure */
1107 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
1111 BLOCK_END(top_stack
->cur_block
) += sh
->value
; /* size */
1112 got_numargs(top_stack
->procadr
, top_stack
->numargs
);
1113 /* Reallocate symbols, saving memory */
1114 b
= shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1116 /* f77 emits proc-level with address bounds==[0,0],
1117 So look for such child blocks, and patch them. */
1118 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++) {
1119 struct block
*b_bad
= BLOCKVECTOR_BLOCK(bv
,i
);
1120 if (BLOCK_SUPERBLOCK(b_bad
) == b
1121 && BLOCK_START(b_bad
) == top_stack
->procadr
1122 && BLOCK_END(b_bad
) == top_stack
->procadr
) {
1123 BLOCK_START(b_bad
) = BLOCK_START(b
);
1124 BLOCK_END(b_bad
) = BLOCK_END(b
);
1127 } else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
) {
1128 /* End of (code) block. The value of the symbol
1129 is the displacement from the procedure`s start
1130 address of the end of this block. */
1131 BLOCK_END(top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1132 (void) shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1134 pop_parse_stack(); /* restore previous lexical context */
1137 case stMember
: /* member of struct or union */
1138 f
= &TYPE_FIELDS(top_stack
->cur_type
)[top_stack
->cur_field
++];
1139 f
->name
= (char*)sh
->iss
;
1140 f
->bitpos
= sh
->value
;
1142 f
->type
= parse_type(ax
+ sh
->index
, sh
, &f
->bitsize
);
1145 case stTypedef
: /* type definition */
1146 s
= new_symbol(sh
->iss
);
1147 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1148 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1149 SYMBOL_BLOCK_VALUE(s
) = top_stack
->cur_block
;
1150 add_symbol(s
, top_stack
->cur_block
);
1151 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
1152 sh
->value
= (long) SYMBOL_TYPE(s
);
1155 case stFile
: /* file name */
1157 top_stack
->blocktype
= sh
->st
;
1160 /* I`ve never seen these for C */
1162 break; /* register relocation */
1164 break; /* forwarding address */
1166 break; /* constant */
1168 error("Unknown symbol type %x.", sh
->st
);
1174 /* Parse the type information provided in the AX entries for
1175 the symbol SH. Return the bitfield size in BS, in case. */
1177 static struct type
*parse_type(ax
, sh
, bs
)
1182 /* Null entries in this map are treated specially */
1183 static struct type
**map_bt
[] =
1185 &builtin_type_void
, /* btNil */
1187 &builtin_type_char
, /* btChar */
1188 &builtin_type_unsigned_char
, /* btUChar */
1189 &builtin_type_short
, /* btShort */
1190 &builtin_type_unsigned_short
, /* btUShort */
1191 &builtin_type_int
, /* btInt */
1192 &builtin_type_unsigned_int
, /* btUInt */
1193 &builtin_type_long
, /* btLong */
1194 &builtin_type_unsigned_long
, /* btULong */
1195 &builtin_type_float
, /* btFloat */
1196 &builtin_type_double
, /* btDouble */
1203 &builtin_type_complex
, /* btComplex */
1204 &builtin_type_double_complex
, /* btDComplex */
1206 &builtin_type_fixed_dec
, /* btFixedDec */
1207 &builtin_type_float_dec
, /* btFloatDec */
1208 &builtin_type_string
, /* btString */
1211 &builtin_type_void
, /* btVoid */
1215 struct type
*tp
= 0;
1220 /* Procedures start off by one */
1221 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
)
1224 /* Undefined ? Should not happen */
1225 if (ax
->rndx
.rfd
== 0xfff) {
1226 return builtin_type_void
;
1229 /* Use aux as a type information record, map its basic type */
1231 if (t
->bt
> (sizeof (map_bt
)/sizeof (*map_bt
))) {
1232 complain (&basic_type_complaint
, t
->bt
);
1233 return builtin_type_int
;
1235 if (map_bt
[t
->bt
]) {
1236 tp
= *map_bt
[t
->bt
];
1240 /* Cannot use builtin types -- build our own */
1243 tp
= lookup_pointer_type (builtin_type_void
);
1247 type_code
= TYPE_CODE_STRUCT
;
1251 type_code
= TYPE_CODE_UNION
;
1255 type_code
= TYPE_CODE_ENUM
;
1259 type_code
= TYPE_CODE_RANGE
;
1263 type_code
= TYPE_CODE_SET
;
1268 complain (&basic_type_complaint
, t
->bt
);
1269 return builtin_type_int
;
1273 /* Move on to next aux */
1276 /* This is the way it would work if the compiler worked */
1277 register TIR
*t1
= t
;
1278 while (t1
->continued
)
1287 /* All these types really point to some (common) MIPS type
1288 definition, and only the type-qualifiers fully identify
1289 them. We'll make the same effort at sharing. */
1290 if (t
->bt
== btIndirect
||
1291 t
->bt
== btStruct
||
1294 t
->bt
== btTypedef
||
1297 char name
[256], *pn
;
1299 /* Try to cross reference this type */
1300 ax
+= cross_ref(ax
, &tp
, type_code
, &pn
);
1301 /* reading .o file ? */
1302 if (UNSAFE_DATA_ADDR(tp
))
1303 tp
= make_type(type_code
, 0, 0, 0);
1304 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1305 sprintf(name
, fmt
, pn
);
1307 /* Usually, TYPE_CODE(tp) is already type_code. The main
1308 exception is if we guessed wrong re struct/union/enum. */
1309 if (TYPE_CODE(tp
) != type_code
) {
1310 complain (&bad_tag_guess_complaint
, 0);
1311 TYPE_CODE(tp
) = type_code
;
1313 TYPE_NAME(tp
) = obsavestring(pn
, strlen(pn
));
1316 /* Deal with range types */
1317 if (t
->bt
== btRange
) {
1320 TYPE_NFIELDS (tp
) = 2;
1322 (struct field
*) obstack_alloc (symbol_obstack
,
1323 2 * sizeof (struct field
));
1324 TYPE_FIELD_NAME (tp
, 0) = "Low";
1325 TYPE_FIELD_BITPOS (tp
, 0) = ax
->dnLow
;
1327 TYPE_FIELD_NAME (tp
, 1) = "High";
1328 TYPE_FIELD_BITPOS (tp
, 1) = ax
->dnHigh
;
1332 /* Parse all the type qualifiers now. If there are more
1333 than 6 the game will continue in the next aux */
1335 #define PARSE_TQ(tq) \
1336 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, sh);
1338 again
: PARSE_TQ(tq0
);
1353 /* Make up a complex type from a basic one. Type is passed by
1354 reference in TPP and side-effected as necessary. The type
1355 qualifier TQ says how to handle the aux symbols at AX for
1356 the symbol SX we are currently analyzing.
1357 Returns the number of aux symbols we parsed. */
1360 upgrade_type(tpp
, tq
, ax
, sh
)
1368 /* Used in array processing */
1377 t
= lookup_pointer_type (*tpp
);
1382 t
= lookup_function_type (*tpp
);
1388 t
= make_type(TYPE_CODE_ARRAY
, 0, 0, 0);
1389 TYPE_TARGET_TYPE(t
) = *tpp
;
1391 /* Determine and record the domain type (type of index) */
1392 id
= ax
->rndx
.index
;
1398 fh
= get_rfd(cur_fd
, rf
);
1400 /* Fields are kept in an array */
1401 /* FIXME - Memory leak! */
1402 if (TYPE_NFIELDS(t
))
1403 TYPE_FIELDS(t
) = (struct field
*)
1404 xrealloc(TYPE_FIELDS(t
),
1405 (TYPE_NFIELDS(t
)+1) * sizeof(struct field
));
1407 TYPE_FIELDS(t
) = (struct field
*)
1408 xzalloc(sizeof(struct field
));
1409 f
= &(TYPE_FIELD(t
,TYPE_NFIELDS(t
)));
1411 memset(f
, 0, sizeof(struct field
));
1413 memset(&ss
, 0, sizeof ss
);
1414 /* XXX */ f
->type
= parse_type(fh
->iauxBase
+ id
* sizeof(AUXU
),
1419 * This seems to be a pointer to the end of the Block defining
1420 * the type. Why it is here is magic for me, and I have no
1421 * good use for it anyways.
1423 /* This used to occur because cross_ref returned
1424 the wrong result (ax pointed wrong). FIXME,
1425 delete this code in a while. -- gnu@cygnus jul91 */
1426 complain (&array_parse_complaint
, 0);
1428 id
= (++ax
)->rndx
.index
;
1429 if ((rf
= ax
->rndx
.rfd
) == 0xfff)
1430 rf
= (++ax
)->isym
, off
++;
1432 lower
= (++ax
)->dnLow
;
1433 upper
= (++ax
)->dnHigh
;
1434 rf
= (++ax
)->width
; /* bit size of array element */
1436 /* Check whether supplied array element bit size matches
1437 the known size of the element type. If this complaint
1438 ends up not happening, we can remove this code. It's
1439 here because we aren't sure we understand this *&%&$
1441 id
= TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) << 3; /* bitsize */
1443 /* Most likely an undefined type */
1445 TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) = id
>> 3;
1448 complain (&array_bitsize_complaint
, rf
);
1450 TYPE_LENGTH(t
) = (upper
< 0) ? 0 :
1451 (upper
- lower
+ 1) * (rf
>> 3);
1456 /* Volatile -- currently ignored */
1460 complain (&unknown_type_qual_complaint
, tq
);
1466 /* Parse a procedure descriptor record PR. Note that the procedure
1467 is parsed _after_ the local symbols, now we just make up the
1468 extra information we need into a special symbol that we insert
1469 in the procedure's main block. Note also that images that
1470 have been partially stripped (ld -x) have been deprived
1471 of local symbols, and we have to cope with them here.
1472 The procedure's code ends at BOUND */
1475 parse_procedure(pr
, bound
)
1478 struct symbol
*s
, *i
;
1479 SYMR
*sh
= (SYMR
*)pr
->isym
;
1481 struct mips_extra_func_info
*e
;
1485 /* Reuse the MIPS record */
1486 e
= (struct mips_extra_func_info
*) pr
;
1487 e
->numargs
= lookup_numargs(pr
->adr
);
1489 /* Make up our special symbol */
1490 i
= new_symbol(".gdbinfo.");
1491 SYMBOL_VALUE(i
) = (int)e
;
1492 SYMBOL_NAMESPACE(i
) = LABEL_NAMESPACE
;
1493 SYMBOL_CLASS(i
) = LOC_CONST
;
1494 SYMBOL_TYPE(i
) = builtin_type_void
;
1496 /* Make up a name for static procedures. Sigh. */
1497 if (sh
== (SYMR
*)-1) {
1498 sprintf(name
,".static_procedure@%x",pr
->adr
);
1499 sh_name
= savestring(name
, strlen(name
));
1503 sh_name
= (char*)sh
->iss
;
1504 s
= mylookup_symbol(sh_name
, top_stack
->cur_block
,
1505 VAR_NAMESPACE
, LOC_BLOCK
);
1508 b
= SYMBOL_BLOCK_VALUE(s
);
1510 s
= new_symbol(sh_name
);
1511 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1512 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1513 /* Donno its type, hope int is ok */
1514 SYMBOL_TYPE(s
) = lookup_function_type (builtin_type_int
);
1515 add_symbol(s
, top_stack
->cur_block
);
1516 /* Wont have symbols for this one */
1518 SYMBOL_BLOCK_VALUE(s
) = b
;
1519 BLOCK_FUNCTION(b
) = s
;
1520 BLOCK_START(b
) = pr
->adr
;
1521 BLOCK_END(b
) = bound
;
1522 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1523 add_block(b
, top_stack
->cur_st
);
1529 /* Parse the external symbol ES. Just call parse_symbol() after
1530 making sure we know where the aux are for it. For procedures,
1531 parsing of the PDRs has already provided all the needed
1532 information, we only parse them if SKIP_PROCEDURES is false,
1533 and only if this causes no symbol duplication.
1535 This routine clobbers top_stack->cur_block and ->cur_st. */
1538 parse_external(es
, skip_procedures
)
1543 if (es
->ifd
!= ifdNil
) {
1545 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
) + cur_fd
;
1546 ax
= (AUXU
*)cur_fdr
->iauxBase
;
1548 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
);
1551 top_stack
->cur_st
= cur_stab
;
1552 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
1555 /* Reading .o files */
1556 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
) {
1558 switch (es
->asym
.st
) {
1560 case stProc
: what
= "procedure"; n_undef_procs
++; break;
1561 case stGlobal
: what
= "variable"; n_undef_vars
++; break;
1562 case stLabel
: what
= "label"; n_undef_labels
++; break;
1563 default : what
= "symbol"; break;
1567 printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what
,
1568 es
->asym
.iss
, fdr_name(cur_fdr
->rss
));
1572 switch (es
->asym
.st
) {
1574 /* If we have full symbols we do not need more */
1575 if (skip_procedures
)
1577 if (mylookup_symbol (es
->asym
.iss
, top_stack
->cur_block
,
1578 VAR_NAMESPACE
, LOC_BLOCK
))
1584 * Note that the case of a symbol with indexNil
1585 * must be handled anyways by parse_symbol().
1587 parse_symbol(&es
->asym
, ax
);
1594 /* Parse the line number info for file descriptor FH into
1595 GDB's linetable LT. MIPS' encoding requires a little bit
1596 of magic to get things out. Note also that MIPS' line
1597 numbers can go back and forth, apparently we can live
1598 with that and do not need to reorder our linetables */
1603 struct linetable
*lt
;
1605 unsigned char *base
= (unsigned char*)fh
->cbLineOffset
;
1607 int delta
, count
, lineno
= 0;
1613 /* Scan by procedure descriptors */
1614 i
= 0; j
= 0, k
= 0;
1615 for (pr
= (PDR
*)IPDFIRST(cur_hdr
,fh
); j
< fh
->cpd
; j
++, pr
++) {
1618 /* No code for this one */
1619 if (pr
->iline
== ilineNil
||
1620 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1623 * Aurgh! To know where to stop expanding we
1626 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1627 if (pr
[l
].iline
!= -1)
1629 if (l
== (fh
->cpd
- j
))
1634 * When procedures are moved around the linenumbers
1635 * are attributed to the next procedure up
1637 if (pr
->iline
>= halt
) continue;
1639 base
= (unsigned char*)pr
->cbLineOffset
;
1640 l
= pr
->adr
>> 2; /* in words */
1641 halt
+= (pr
->adr
>> 2) - pr
->iline
;
1642 for (lineno
= pr
->lnLow
; l
< halt
;) {
1643 count
= *base
& 0x0f;
1644 delta
= *base
++ >> 4;
1648 delta
= (base
[0] << 8) | base
[1];
1649 if (delta
>= 0x8000)
1653 lineno
+= delta
;/* first delta is 0 */
1654 k
= add_line(lt
, lineno
, l
, k
);
1661 /* Master parsing procedure for first-pass reading of file symbols
1662 into a partial_symtab.
1664 Parses the symtab described by the global symbolic header CUR_HDR.
1665 END_OF_TEXT_SEG gives the address just after the text segment for
1666 the symtab we are reading. */
1669 parse_partial_symbols(end_of_text_seg
, objfile
)
1670 int end_of_text_seg
;
1671 struct objfile
*objfile
;
1674 /* int stat_idx, h_max;*/
1675 HDRR
*hdr
= cur_hdr
;
1676 /* Running pointers */
1681 struct partial_symtab
*pst
;
1683 int past_first_source_file
= 0;
1685 /* List of current psymtab's include files */
1686 char **psymtab_include_list
;
1687 int includes_allocated
;
1690 struct pst_map
* fdr_to_pst
;
1691 /* Index within current psymtab dependency list */
1692 struct partial_symtab
**dependency_list
;
1693 int dependencies_used
, dependencies_allocated
;
1694 struct cleanup
*old_chain
;
1696 extern_tab
= (EXTR
**)obstack_alloc (psymbol_obstack
,
1697 sizeof(EXTR
*) * hdr
->iextMax
);
1699 includes_allocated
= 30;
1701 psymtab_include_list
= (char **) alloca (includes_allocated
*
1703 next_symbol_text_func
= mips_next_symbol_text
;
1705 dependencies_allocated
= 30;
1706 dependencies_used
= 0;
1708 (struct partial_symtab
**) alloca (dependencies_allocated
*
1709 sizeof (struct partial_symtab
*));
1711 last_source_file
= 0;
1716 * Only parse the Local and External symbols, and the Relative FDR.
1717 * Fixup enough of the loader symtab to be able to use it.
1718 * Allocate space only for the file's portions we need to
1723 max_glevel
= MIN_GLEVEL
;
1725 /* Allocate the map FDR -> PST.
1726 Minor hack: -O3 images might claim some global data belongs
1727 to FDR -1. We`ll go along with that */
1728 fdr_to_pst
= (struct pst_map
*)xzalloc((hdr
->ifdMax
+1) * sizeof *fdr_to_pst
);
1729 old_chain
= make_cleanup (free
, fdr_to_pst
);
1732 struct partial_symtab
* pst
= new_psymtab("", objfile
);
1733 fdr_to_pst
[-1].pst
= pst
;
1737 /* Pass 1 over external syms: Presize and partition the list */
1738 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1739 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1740 fdr_to_pst
[esh
->ifd
].n_globals
++;
1743 /* Pass 1.5 over files: partition out global symbol space */
1745 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++) {
1746 fdr_to_pst
[f_idx
].globals_offset
= s_idx
;
1747 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
1748 fdr_to_pst
[f_idx
].n_globals
= 0;
1751 /* Pass 2 over external syms: fill in external symbols */
1752 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1753 enum misc_function_type misc_type
= mf_text
;
1754 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1756 extern_tab
[fdr_to_pst
[esh
->ifd
].globals_offset
1757 + fdr_to_pst
[esh
->ifd
].n_globals
++] = esh
;
1759 if (esh
->asym
.sc
== scUndefined
|| esh
->asym
.sc
== scNil
)
1762 switch (esh
->asym
.st
) {
1766 misc_type
= mf_data
;
1771 misc_type
= mf_unknown
;
1772 complain (&unknown_ext_complaint
,
1773 (char *)(esh
->asym
.iss
));
1775 prim_record_misc_function ((char *)(esh
->asym
.iss
),
1780 /* Pass 3 over files, over local syms: fill in static symbols */
1781 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
1782 struct partial_symtab
*save_pst
;
1784 cur_fdr
= fh
= f_idx
+ (FDR
*)(cur_hdr
->cbFdOffset
);
1786 if (fh
->csym
== 0) {
1787 fdr_to_pst
[f_idx
].pst
= NULL
;
1790 pst
= start_psymtab_common (objfile
, 0, (char*)fh
->rss
,
1791 fh
->cpd
? fh
->adr
: 0,
1792 global_psymbols
.next
,
1793 static_psymbols
.next
);
1794 pst
->read_symtab_private
= (char *)
1795 obstack_alloc (psymbol_obstack
, sizeof (struct symloc
));
1798 /* Make everything point to everything. */
1799 FDR_IDX(pst
) = f_idx
;
1800 fdr_to_pst
[f_idx
].pst
= pst
;
1801 fh
->ioptBase
= (int)pst
;
1803 CUR_HDR(pst
) = cur_hdr
;
1805 /* The way to turn this into a symtab is to call... */
1806 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
1808 pst
->texthigh
= pst
->textlow
;
1810 pst
->globals_offset
= global_psymbols
.next
- global_psymbols
.list
;
1811 pst
->statics_offset
= static_psymbols
.next
- static_psymbols
.list
;
1813 pst
->n_global_syms
= 0;
1814 pst
->n_static_syms
= 0;
1816 /* The second symbol must be @stab.
1817 This symbol is emitted by mips-tfile to signal
1818 that the current object file uses encapsulated stabs
1819 instead of mips ecoff for local symbols.
1820 (It is the second symbol because the first symbol is
1821 the stFile used to signal the start of a file). */
1823 && strcmp(((SYMR
*)fh
->isymBase
)[1].iss
, stabs_symbol
) == 0) {
1824 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++) {
1827 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
1828 type_code
= MIPS_UNMARK_STAB(sh
->index
);
1829 if (!MIPS_IS_STAB(sh
)) {
1830 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
) {
1831 long procaddr
= sh
->value
;
1832 sh
= (sh
->index
+ (AUXU
*)fh
->iauxBase
)->isym
1833 + (SYMR
*) fh
->isymBase
- 1;
1834 if (sh
->st
== stEnd
) {
1835 long high
= procaddr
+ sh
->value
;
1836 if (high
> pst
->texthigh
)
1837 pst
->texthigh
= high
;
1842 #define SET_NAMESTRING() namestring = (char*)sh->iss
1843 #define CUR_SYMBOL_TYPE type_code
1844 #define CUR_SYMBOL_VALUE sh->value
1845 #define START_PSYMTAB(ofile,addr,fname,low,symoff,global_syms,static_syms)\
1847 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
1848 #define addr 0 /* FIXME, should be offset of addresses */
1849 #define HANDLE_RBRAC(val) \
1850 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
1851 #include "partial-stab.h"
1856 register struct partial_symbol
*psym
;
1857 for (cur_sdx
= 0; cur_sdx
< fh
->csym
; ) {
1858 register struct partial_symbol
*p
;
1861 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
1863 if (MIPS_IS_STAB(sh
)) {
1868 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
1869 sh
->index
== 0xfffff) {
1870 /* FIXME, premature? */
1875 name
= (char *)(sh
->iss
);
1880 case stProc
: /* Asm labels apparently */
1881 case stStaticProc
: /* Function */
1882 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
1883 VAR_NAMESPACE
, LOC_BLOCK
,
1884 static_psymbols
, sh
->value
);
1885 /* Skip over procedure to next one. */
1886 cur_sdx
= (sh
->index
+ (AUXU
*)fh
->iauxBase
)->isym
;
1887 procaddr
= sh
->value
;
1889 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
- 1;
1890 if (sh
->st
!= stEnd
)
1892 high
= procaddr
+ sh
->value
;
1893 if (high
> pst
->texthigh
)
1894 pst
->texthigh
= high
;
1896 case stStatic
: /* Variable */
1899 case stTypedef
: /* Typedef */
1900 class = LOC_TYPEDEF
;
1902 case stConstant
: /* Constant decl */
1905 case stBlock
: /* { }, str, un, enum*/
1906 if (sh
->sc
== scInfo
) {
1907 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
1908 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1909 static_psymbols
, sh
->value
);
1911 /* Skip over the block */
1912 cur_sdx
= sh
->index
;
1914 case stFile
: /* File headers */
1915 case stLabel
: /* Labels */
1916 case stEnd
: /* Ends of files */
1919 complain (&unknown_sym_complaint
, SYMBOL_NAME(p
));
1920 complain (&unknown_st_complaint
, sh
->st
);
1924 /* Use this gdb symbol */
1925 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
1926 VAR_NAMESPACE
, class,
1927 static_psymbols
, sh
->value
);
1929 cur_sdx
++; /* Go to next file symbol */
1932 /* Now do enter the external symbols. */
1933 ext_ptr
= &extern_tab
[fdr_to_pst
[f_idx
].globals_offset
];
1934 cur_sdx
= fdr_to_pst
[f_idx
].n_globals
;
1935 PST_PRIVATE(save_pst
)->extern_count
= cur_sdx
;
1936 PST_PRIVATE(save_pst
)->extern_tab
= ext_ptr
;
1937 for (; --cur_sdx
>= 0; ext_ptr
++) {
1938 enum address_class
class;
1939 if ((*ext_ptr
)->ifd
!= f_idx
)
1941 sh
= &(*ext_ptr
)->asym
;
1950 complain (&unknown_ext_complaint
, sh
->iss
);
1955 if (global_psymbols
.next
>=
1956 global_psymbols
.list
+ global_psymbols
.size
)
1957 extend_psymbol_list (&global_psymbols
);
1958 psym
= global_psymbols
.next
++;
1959 SYMBOL_NAME (psym
) = (char*)sh
->iss
;
1960 SYMBOL_NAMESPACE (psym
) = VAR_NAMESPACE
;
1961 SYMBOL_CLASS (psym
) = class;
1962 SYMBOL_VALUE_ADDRESS (psym
) = (CORE_ADDR
)sh
->value
;
1966 end_psymtab (save_pst
, psymtab_include_list
, includes_used
,
1967 -1, save_pst
->texthigh
,
1968 dependency_list
, dependencies_used
,
1969 global_psymbols
.next
, static_psymbols
.next
);
1970 if (entry_point
< save_pst
->texthigh
1971 && entry_point
>= save_pst
->textlow
) {
1972 startup_file_start
= save_pst
->textlow
;
1973 startup_file_end
= save_pst
->texthigh
;
1977 /* Mark the last code address, and remember it for later */
1978 hdr
->cbDnOffset
= end_of_text_seg
;
1980 do_cleanups (old_chain
);
1985 /* Do the initial analisys of the F_IDX-th file descriptor.
1986 Allocates a partial symtab for it, and builds the list
1987 of dependent files by recursion. LEV says at which level
1988 of recursion we are called (to pretty up debug traces) */
1990 static struct partial_symtab
*
1991 parse_fdr(f_idx
, lev
, objfile
)
1994 struct objfile
*objfile
;
1997 register struct partial_symtab
*pst
;
2000 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + f_idx
;
2002 /* Use this to indicate into which symtab this file was parsed */
2004 return (struct partial_symtab
*) fh
->ioptBase
;
2006 /* Debuggability level */
2007 if (compare_glevel(max_glevel
, fh
->glevel
) < 0)
2008 max_glevel
= fh
->glevel
;
2010 /* Make a new partial_symtab */
2011 pst
= new_psymtab(fh
->rss
, objfile
);
2016 pst
->textlow
= fh
->adr
;
2017 pst
->texthigh
= fh
->cpd
; /* To be fixed later */
2020 /* Make everything point to everything. */
2021 FDR_IDX(pst
) = f_idx
;
2022 fdr_to_pst
[f_idx
].pst
= pst
;
2023 fh
->ioptBase
= (int)pst
;
2025 /* Analyze its dependencies */
2030 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
2031 /* ...then presumably a .h file: drop reverse depends .h->.c */
2032 for (; s_id0
< fh
->crfd
; s_id0
++) {
2033 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
2035 s_id0
++; /* Skip self-dependency */
2040 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2041 pst
->dependencies
= (struct partial_symtab
**)
2042 obstack_alloc (psymbol_obstack
,
2043 pst
->number_of_dependencies
*
2044 sizeof (struct partial_symtab
*));
2045 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
2046 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
2048 pst
->dependencies
[s_idx
-s_id0
] = parse_fdr(*rh
, lev
+1, objfile
);
2056 mips_next_symbol_text ()
2059 return (char*)((SYMR
*)cur_fdr
->isymBase
)[cur_sdx
].iss
;
2062 /* Ancillary function to psymtab_to_symtab(). Does all the work
2063 for turning the partial symtab PST into a symtab, recurring
2064 first on all dependent psymtabs. The argument FILENAME is
2065 only passed so we can see in debug stack traces what file
2069 psymtab_to_symtab_1(pst
, filename
)
2070 struct partial_symtab
*pst
;
2078 struct linetable
*lines
;
2084 /* How many symbols will we need */
2085 /* FIXME, this does not count enum values. */
2086 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
2087 if (FDR_IDX(pst
) == -1) {
2091 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + FDR_IDX(pst
);
2092 f_max
+= fh
->csym
+ fh
->cpd
;
2093 maxlines
= 2 * fh
->cline
;
2096 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2099 && strcmp(((SYMR
*)fh
->isymBase
)[1].iss
, stabs_symbol
) == 0;
2103 st
= new_symtab (pst
->filename
, 2 * f_max
, maxlines
,
2106 st
= new_symtab ("unknown", f_max
, 0, pst
->objfile
);
2107 lines
= LINETABLE(st
);
2108 pending_list
= (struct mips_pending
**) cur_hdr
->cbOptOffset
;
2109 if (pending_list
== 0) {
2110 pending_list
= (struct mips_pending
**)
2111 xzalloc(cur_hdr
->ifdMax
* sizeof(struct mips_pending
*));
2112 cur_hdr
->cbOptOffset
= (int)pending_list
;
2116 /* Read in all partial symbtabs on which this one is dependent.
2117 NOTE that we do have circular dependencies, sigh. We solved
2118 that by setting pst->readin before this point. */
2120 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2121 if (!pst
->dependencies
[i
]->readin
) {
2122 /* Inform about additional files to be read in. */
2125 fputs_filtered (" ", stdout
);
2127 fputs_filtered ("and ", stdout
);
2129 printf_filtered ("%s...",
2130 pst
->dependencies
[i
]->filename
);
2131 wrap_here (""); /* Flush output */
2134 /* We only pass the filename for debug purposes */
2135 psymtab_to_symtab_1(pst
->dependencies
[i
],
2136 pst
->dependencies
[i
]->filename
);
2140 /* Now read the symbols for this symtab */
2143 cur_fd
= FDR_IDX(pst
);
2146 /* Get a new lexical context */
2149 top_stack
->cur_st
= cur_stab
;
2150 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab
),
2152 BLOCK_START(top_stack
->cur_block
) = fh
? fh
->adr
: 0;
2153 BLOCK_END(top_stack
->cur_block
) = 0;
2154 top_stack
->blocktype
= stFile
;
2155 top_stack
->maxsyms
= 2*f_max
;
2156 top_stack
->cur_type
= 0;
2157 top_stack
->procadr
= 0;
2158 top_stack
->numargs
= 0;
2161 /* Parse locals and procedures */
2166 char *fh_name
= (char*)fh
->rss
;
2168 /* Parse local symbols first */
2174 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++) {
2175 register SYMR
*sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
2176 char *name
= (char*)sh
->iss
;
2177 CORE_ADDR valu
= sh
->value
;
2178 if (MIPS_IS_STAB(sh
)) {
2179 int type_code
= MIPS_UNMARK_STAB(sh
->index
);
2180 process_one_symbol (type_code
, 0, valu
, name
, /*FIXME*/ 0);
2182 else if (sh
->st
== stLabel
&& sh
->index
!= indexNil
) {
2183 /* Handle encoded stab line number. */
2184 record_line (current_subfile
, sh
->index
, valu
);
2187 st
= end_symtab (pst
->texthigh
, 0, 0, pst
->objfile
);
2190 /* BOUND is the highest core address of this file's procedures */
2191 int bound
= cur_fd
== cur_hdr
->ifdMax
- 1 ? cur_hdr
->cbDnOffset
2193 for (cur_sdx
= 0; cur_sdx
< fh
->csym
; ) {
2194 sh
= (SYMR
*) (fh
->isymBase
) + cur_sdx
;
2195 cur_sdx
+= parse_symbol(sh
, fh
->iauxBase
);
2198 /* Procedures next, note we need to look-ahead to
2199 find out where the procedure's code ends */
2201 for (i
= 0; i
< fh
->cpd
-1; i
++) {
2202 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2203 parse_procedure(pr
, pr
[1].adr
); /* next proc up */
2206 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2207 parse_procedure(pr
, bound
); /* next file up */
2209 /* Linenumbers. At the end, check if we can save memory */
2210 parse_lines(fh
, lines
);
2211 if (lines
->nitems
< fh
->cline
)
2212 lines
= shrink_linetable(lines
);
2218 LINETABLE(st
) = lines
;
2220 /* .. and our share of externals.
2221 XXX use the global list to speed up things here. how ?
2222 FIXME, Maybe quit once we have found the right number of ext's? */
2223 /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
2224 top_stack
->blocktype
= stFile
;
2225 top_stack
->maxsyms
=
2226 cur_hdr
->isymMax
+ cur_hdr
->ipdMax
+ cur_hdr
->iextMax
;
2228 ext_ptr
= PST_PRIVATE(pst
)->extern_tab
;
2229 for (i
= PST_PRIVATE(pst
)->extern_count
; --i
>= 0; ext_ptr
++)
2230 parse_external(*ext_ptr
, 1);
2232 /* If there are undefined, tell the user */
2233 if (n_undef_symbols
) {
2234 printf_filtered("File %s contains %d unresolved references:",
2235 st
->filename
, n_undef_symbols
);
2236 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2237 n_undef_vars
, n_undef_procs
, n_undef_labels
);
2238 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
2244 /* Sort the symbol table now, we are done adding symbols to it.*/
2245 sort_symtab_syms(st
);
2249 /* Now link the psymtab and the symtab. */
2253 /* Ancillary parsing procedures. */
2255 /* Lookup the type at relative index RN. Return it in TPP
2256 if found and in any event come up with its name PNAME.
2257 Return value says how many aux symbols we ate */
2260 cross_ref(rn
, tpp
, type_code
, pname
)
2263 int type_code
; /* Use to alloc new type if none is found. */
2268 /* Escape index means 'the next one' */
2269 if (rn
->rfd
== 0xfff)
2270 rf
= *(unsigned *) (rn
+ 1);
2276 *pname
= "<undefined>";
2279 * Find the relative file descriptor and the symbol in it
2281 FDR
*fh
= get_rfd(cur_fd
, rf
);
2286 * If we have processed this symbol then we left a forwarding
2287 * pointer to the corresponding GDB symbol. If not, we`ll put
2288 * it in a list of pending symbols, to be processed later when
2289 * the file f will be. In any event, we collect the name for
2290 * the type here. Which is why we made a first pass at
2293 sh
= (SYMR
*) (fh
->isymBase
) + rn
->index
;
2295 /* Careful, we might be looking at .o files */
2296 *pname
= (UNSAFE_DATA_ADDR(sh
->iss
)) ? "<undefined>" :
2299 /* Have we parsed it ? */
2300 if ((!UNSAFE_DATA_ADDR(sh
->value
)) && (sh
->st
== stParsed
)) {
2301 t
= (struct type
*) sh
->value
;
2304 /* Avoid duplicates */
2305 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
2309 *tpp
= make_type(type_code
, 0, 0, 0);
2310 add_pending(fh
, sh
, *tpp
);
2315 /* We used one auxent normally, two if we got a "next one" rf. */
2316 return (rn
->rfd
== 0xfff? 2: 1);
2320 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2321 keeping the symtab sorted */
2323 static struct symbol
*
2324 mylookup_symbol (name
, block
, namespace, class)
2326 register struct block
*block
;
2327 enum namespace namespace;
2328 enum address_class
class;
2330 register int bot
, top
, inc
;
2331 register struct symbol
*sym
;
2334 top
= BLOCK_NSYMS(block
);
2337 sym
= BLOCK_SYM(block
, bot
);
2338 if (SYMBOL_NAME(sym
)[0] == inc
2339 && SYMBOL_NAMESPACE(sym
) == namespace
2340 && SYMBOL_CLASS(sym
) == class
2341 && !strcmp(SYMBOL_NAME(sym
), name
))
2345 if (block
= BLOCK_SUPERBLOCK (block
))
2346 return mylookup_symbol (name
, block
, namespace, class);
2351 /* Add a new symbol S to a block B.
2352 Infrequently, we will need to reallocate the block to make it bigger.
2353 We only detect this case when adding to top_stack->cur_block, since
2354 that's the only time we know how big the block is. FIXME. */
2361 int nsyms
= BLOCK_NSYMS(b
)++;
2362 struct block
*origb
;
2363 struct parse_stack
*stackp
;
2365 if (b
== top_stack
->cur_block
&&
2366 nsyms
>= top_stack
->maxsyms
) {
2367 complain (&block_overflow_complaint
, s
->name
);
2368 /* In this case shrink_block is actually grow_block, since
2369 BLOCK_NSYMS(b) is larger than its current size. */
2371 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
2373 /* Now run through the stack replacing pointers to the
2374 original block. shrink_block has already done this
2375 for the blockvector and BLOCK_FUNCTION. */
2376 for (stackp
= top_stack
; stackp
; stackp
= stackp
->next
) {
2377 if (stackp
->cur_block
== origb
) {
2378 stackp
->cur_block
= b
;
2379 stackp
->maxsyms
= BLOCK_NSYMS (b
);
2383 BLOCK_SYM(b
,nsyms
) = s
;
2386 /* Add a new block B to a symtab S */
2393 struct blockvector
*bv
= BLOCKVECTOR(s
);
2395 bv
= (struct blockvector
*)xrealloc(bv
, sizeof(struct blockvector
) +
2396 BLOCKVECTOR_NBLOCKS(bv
) * sizeof(bv
->block
));
2397 if (bv
!= BLOCKVECTOR(s
))
2398 BLOCKVECTOR(s
) = bv
;
2400 BLOCKVECTOR_BLOCK(bv
, BLOCKVECTOR_NBLOCKS(bv
)++) = b
;
2403 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2404 MIPS' linenumber encoding might need more than one byte
2405 to describe it, LAST is used to detect these continuation lines */
2408 add_line(lt
, lineno
, adr
, last
)
2409 struct linetable
*lt
;
2415 last
= -2; /* make sure we record first line */
2417 if (last
== lineno
) /* skip continuation lines */
2420 lt
->item
[lt
->nitems
].line
= lineno
;
2421 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
2427 /* Comparison functions, used when sorting things */
2429 /* Symtabs must be ordered viz the code segments they cover */
2432 compare_symtabs( s1
, s2
)
2433 struct symtab
**s1
, **s2
;
2435 /* "most specific" first */
2437 register struct block
*b1
, *b2
;
2438 b1
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1
),GLOBAL_BLOCK
);
2439 b2
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2
),GLOBAL_BLOCK
);
2440 if (BLOCK_END(b1
) == BLOCK_END(b2
))
2441 return BLOCK_START(b1
) - BLOCK_START(b2
);
2442 return BLOCK_END(b1
) - BLOCK_END(b2
);
2446 /* Partial Symtabs, same */
2449 compare_psymtabs( s1
, s2
)
2450 struct partial_symtab
**s1
, **s2
;
2452 /* Perf twist: put the ones with no code at the end */
2454 register int a
= (*s1
)->textlow
;
2455 register int b
= (*s2
)->textlow
;
2464 /* Blocks with a smaller low bound should come first */
2466 static int compare_blocks(b1
,b2
)
2467 struct block
**b1
, **b2
;
2469 register int addr_diff
;
2471 addr_diff
= (BLOCK_START((*b1
))) - (BLOCK_START((*b2
)));
2473 return (BLOCK_END((*b1
))) - (BLOCK_END((*b2
)));
2478 /* Sorting and reordering procedures */
2480 /* Sort the blocks of a symtab S.
2481 Reorder the blocks in the blockvector by code-address,
2482 as required by some MI search routines */
2488 struct blockvector
*bv
= BLOCKVECTOR(s
);
2490 if (BLOCKVECTOR_NBLOCKS(bv
) <= 2) {
2492 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) == 0)
2493 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = 0;
2494 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) == 0)
2495 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) = 0;
2499 * This is very unfortunate: normally all functions are compiled in
2500 * the order they are found, but if the file is compiled -O3 things
2501 * are very different. It would be nice to find a reliable test
2502 * to detect -O3 images in advance.
2504 if (BLOCKVECTOR_NBLOCKS(bv
) > 3)
2505 qsort(&BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
),
2506 BLOCKVECTOR_NBLOCKS(bv
) - FIRST_LOCAL_BLOCK
,
2507 sizeof(struct block
*),
2511 register CORE_ADDR high
= 0;
2512 register int i
, j
= BLOCKVECTOR_NBLOCKS(bv
);
2514 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
2515 if (high
< BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
)))
2516 high
= BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
));
2517 BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = high
;
2520 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) =
2521 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
));
2523 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2524 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2525 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2526 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2530 /* Constructor/restructor/destructor procedures */
2532 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2533 MAXSYMS and linenumbers MAXLINES we'll put in it */
2537 new_symtab(name
, maxsyms
, maxlines
, objfile
)
2540 struct symtab
*s
= allocate_symtab (name
, objfile
);
2542 LINETABLE(s
) = new_linetable(maxlines
);
2544 /* All symtabs must have at least two blocks */
2545 BLOCKVECTOR(s
) = new_bvect(2);
2546 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
) = new_block(maxsyms
);
2547 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), STATIC_BLOCK
) = new_block(maxsyms
);
2548 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
),STATIC_BLOCK
)) =
2549 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
);
2551 s
->free_code
= free_linetable
;
2553 /* Link the new symtab into the list of such. */
2554 s
->next
= symtab_list
;
2560 /* Allocate a new partial_symtab NAME */
2562 static struct partial_symtab
*
2563 new_psymtab(name
, objfile
)
2565 struct objfile
*objfile
;
2567 struct partial_symtab
*pst
;
2569 pst
= (struct partial_symtab
*)
2570 obstack_alloc (psymbol_obstack
, sizeof (*pst
));
2571 memset (pst
, 0, sizeof (*pst
));
2573 if (name
== (char*)-1) /* FIXME -- why not null here? */
2574 pst
->filename
= "<no name>";
2576 pst
->filename
= name
;
2578 /* Chain it to its object file */
2579 pst
->objfile
= objfile
;
2580 pst
->objfile_chain
= objfile
->psymtabs
;
2581 objfile
->psymtabs
= pst
;
2583 pst
->next
= partial_symtab_list
;
2584 partial_symtab_list
= pst
;
2586 /* Keep a backpointer to the file's symbols */
2587 pst
->read_symtab_private
= (char *) obstack_alloc (psymbol_obstack
,
2588 sizeof (struct symloc
));
2589 CUR_HDR(pst
) = cur_hdr
;
2591 /* The way to turn this into a symtab is to call... */
2592 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
2598 /* Allocate a linetable array of the given SIZE */
2600 static struct linetable
*
2603 struct linetable
*l
;
2605 size
= size
* sizeof(l
->item
) + sizeof(struct linetable
);
2606 l
= (struct linetable
*)xmalloc(size
);
2611 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2612 I am not so sure about the 3.4 ones */
2614 static struct linetable
*
2615 shrink_linetable(lt
)
2616 struct linetable
* lt
;
2618 struct linetable
*l
= new_linetable(lt
->nitems
);
2620 memcpy(l
, lt
, lt
->nitems
* sizeof(l
->item
) + sizeof(struct linetable
));
2625 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2628 struct blockvector
*
2631 struct blockvector
*bv
;
2634 size
= sizeof(struct blockvector
) + nblocks
* sizeof(struct block
*);
2635 bv
= (struct blockvector
*) xzalloc(size
);
2637 BLOCKVECTOR_NBLOCKS(bv
) = nblocks
;
2642 /* Allocate and zero a new block of MAXSYMS symbols */
2648 int size
= sizeof(struct block
) + (maxsyms
-1) * sizeof(struct symbol
*);
2649 struct block
*b
= (struct block
*)xzalloc(size
);
2654 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2655 Shrink_block can also be used by add_symbol to grow a block. */
2657 static struct block
*
2663 struct blockvector
*bv
= BLOCKVECTOR(s
);
2666 /* Just reallocate it and fix references to the old one */
2668 new = (struct block
*) xrealloc ((char *)b
, sizeof(struct block
) +
2669 (BLOCK_NSYMS(b
)-1) * sizeof(struct symbol
*));
2671 /* Should chase pointers to old one. Fortunately, that`s just
2672 the block`s function and inferior blocks */
2673 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b
)
2674 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2675 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2676 if (BLOCKVECTOR_BLOCK(bv
,i
) == b
)
2677 BLOCKVECTOR_BLOCK(bv
,i
) = new;
2678 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) == b
)
2679 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) = new;
2683 /* Create a new symbol with printname NAME */
2690 struct symbol
*s
= (struct symbol
*)
2691 obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
2693 memset (s
, 0, sizeof (*s
));
2694 SYMBOL_NAME(s
) = name
;
2698 /* Create a new type with printname NAME */
2705 struct type
*t
= (struct type
*)
2706 obstack_alloc (symbol_obstack
, sizeof (struct type
));
2708 memset (t
, 0, sizeof (*t
));
2709 TYPE_VPTR_FIELDNO (t
) = -1;
2710 TYPE_NAME(t
) = name
;
2711 TYPE_CPLUS_SPECIFIC(t
) = &cplus_struct_default
;
2715 /* Create and initialize a new type with printname NAME.
2716 CODE and LENGTH are the initial info we put in,
2717 UNS says whether the type is unsigned or not. */
2721 make_type(code
, length
, uns
, name
)
2722 enum type_code code
;
2726 register struct type
*type
;
2728 /* FIXME, I don't think this ever gets freed. */
2729 type
= (struct type
*) xzalloc(sizeof(struct type
));
2730 TYPE_CODE(type
) = code
;
2731 TYPE_LENGTH(type
) = length
;
2732 TYPE_FLAGS(type
) = uns
? TYPE_FLAG_UNSIGNED
: 0;
2733 TYPE_NAME(type
) = name
;
2734 TYPE_VPTR_FIELDNO (type
) = -1;
2736 if (code
!= TYPE_CODE_METHOD
&& code
!= TYPE_CODE_FUNC
)
2737 TYPE_CPLUS_SPECIFIC(type
) = &cplus_struct_default
;
2741 /* Things used for calling functions in the inferior.
2742 These functions are exported to our companion
2743 mips-tdep.c file and are here because they play
2744 with the symbol-table explicitly. */
2746 /* Sigtramp: make sure we have all the necessary information
2747 about the signal trampoline code. Since the official code
2748 from MIPS does not do so, we make up that information ourselves.
2749 If they fix the library (unlikely) this code will neutralize itself. */
2756 struct block
*b
, *b0
;
2758 sigtramp_address
= -1;
2760 /* We know it is sold as sigvec */
2761 s
= lookup_symbol("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
2763 /* Most programs do not play with signals */
2767 b0
= SYMBOL_BLOCK_VALUE(s
);
2769 /* A label of sigvec, to be more precise */
2770 s
= lookup_symbol("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
2772 /* But maybe this program uses its own version of sigvec */
2776 sigtramp_address
= SYMBOL_VALUE(s
);
2777 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
2779 /* Did we or MIPSco fix the library ? */
2780 if (SYMBOL_CLASS(s
) == LOC_BLOCK
)
2783 /* But what symtab does it live in ? */
2784 st
= find_pc_symtab(SYMBOL_VALUE(s
));
2787 * Ok, there goes the fix: turn it into a procedure, with all the
2788 * needed info. Note we make it a nested procedure of sigvec,
2789 * which is the way the (assembly) code is actually written.
2791 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2792 SYMBOL_CLASS(s
) = LOC_BLOCK
;
2793 SYMBOL_TYPE(s
) = make_type(TYPE_CODE_FUNC
, 4, 0, 0);
2794 TYPE_TARGET_TYPE(SYMBOL_TYPE(s
)) = builtin_type_void
;
2796 /* Need a block to allocate .gdbinfo. in */
2798 SYMBOL_BLOCK_VALUE(s
) = b
;
2799 BLOCK_START(b
) = sigtramp_address
;
2800 BLOCK_END(b
) = sigtramp_end
;
2801 BLOCK_FUNCTION(b
) = s
;
2802 BLOCK_SUPERBLOCK(b
) = BLOCK_SUPERBLOCK(b0
);
2806 /* Make a .gdbinfo. for it */
2808 struct mips_extra_func_info
*e
=
2809 (struct mips_extra_func_info
*)
2810 xzalloc(sizeof(struct mips_extra_func_info
));
2812 e
->numargs
= 0; /* the kernel thinks otherwise */
2813 /* align_longword(sigcontext + SIGFRAME) */
2814 e
->framesize
= 0x150;
2815 e
->framereg
= SP_REGNUM
;
2818 e
->regoffset
= -(41 * sizeof(int));
2820 e
->fregoffset
= -(37 * sizeof(int));
2823 s
= new_symbol(".gdbinfo.");
2824 SYMBOL_VALUE(s
) = (int) e
;
2825 SYMBOL_NAMESPACE(s
) = LABEL_NAMESPACE
;
2826 SYMBOL_CLASS(s
) = LOC_CONST
;
2827 SYMBOL_TYPE(s
) = builtin_type_void
;
2830 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
2833 /* Initialization */
2835 static struct sym_fns ecoff_sym_fns
= {"ecoff", 5,
2836 mipscoff_new_init
, mipscoff_symfile_init
,
2837 mipscoff_symfile_read
};
2839 _initialize_mipsread ()
2841 add_symtab_fns (&ecoff_sym_fns
);
2843 /* Missing basic types */
2844 builtin_type_string
= make_type(TYPE_CODE_PASCAL_ARRAY
,
2846 builtin_type_complex
= make_type(TYPE_CODE_FLT
,
2847 2 * sizeof(float), 0, "complex");
2848 builtin_type_double_complex
= make_type(TYPE_CODE_FLT
,
2849 2 * sizeof(double), 0, "double_complex");
2850 builtin_type_fixed_dec
= make_type(TYPE_CODE_INT
, sizeof(int),
2851 0, "fixed_decimal");
2852 builtin_type_float_dec
= make_type(TYPE_CODE_FLT
, sizeof(double),
2853 0, "floating_decimal");