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. */
65 #define CODE_MASK 0x8F300
66 #define MIPS_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK)
67 #define MIPS_MARK_STAB(code) ((code)+CODE_MASK)
68 #define MIPS_UNMARK_STAB(code) ((code)-CODE_MASK)
70 /* Each partial symbol table entry contains a pointer to private data for the
71 read_symtab() function to use when expanding a partial symbol table entry
72 to a full symbol table entry.
74 For mipsread this structure contains the index of the FDR that this psymtab
75 represents and a pointer to the symbol table header HDRR from the symbol
76 file that the psymtab was created from. */
78 #define FDR_IDX(p) (((struct symloc *)((p)->read_symtab_private))->fdr_idx)
79 #define CUR_HDR(p) (((struct symloc *)((p)->read_symtab_private))->cur_hdr)
86 /* Things we import explicitly from other modules */
88 extern int info_verbose
;
89 extern struct block
*block_for_pc();
90 extern void sort_symtab_syms();
92 /* Various complaints about symbol reading that don't abort the process */
94 struct complaint unknown_ext_complaint
=
95 {"unknown external symbol %s", 0, 0};
97 struct complaint unknown_sym_complaint
=
98 {"unknown local symbol %s", 0, 0};
100 struct complaint unknown_st_complaint
=
101 {"with type %d", 0, 0};
103 struct complaint block_overflow_complaint
=
104 {"block containing %s overfilled", 0, 0};
106 struct complaint basic_type_complaint
=
107 {"cannot map MIPS basic type 0x%x", 0, 0};
109 struct complaint unknown_type_qual_complaint
=
110 {"unknown type qualifier 0x%x", 0, 0};
112 struct complaint array_bitsize_complaint
=
113 {"size of array target type not known, assuming %d bits", 0, 0};
115 struct complaint array_parse_complaint
=
116 {"array type with strange relative symbol", 0, 0};
118 /* Macros and extra defs */
120 /* Already-parsed symbols are marked specially */
122 #define stParsed stType
124 /* Puns: hard to find whether -g was used and how */
126 #define MIN_GLEVEL GLEVEL_0
127 #define compare_glevel(a,b) \
128 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
129 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
131 /* When looking at .o files, avoid tripping over bad addresses */
133 #define SAFE_TEXT_ADDR 0x400000
134 #define SAFE_DATA_ADDR 0x10000000
136 #define UNSAFE_DATA_ADDR(p) ((unsigned)p < SAFE_DATA_ADDR || (unsigned)p > 2*SAFE_DATA_ADDR)
138 /* Things that really are local to this module */
140 /* GDB symtable for the current compilation unit */
142 static struct symtab
*cur_stab
;
144 /* MIPS symtab header for the current file */
146 static HDRR
*cur_hdr
;
148 /* Pointer to current file decriptor record, and its index */
153 /* Index of current symbol */
157 /* Note how much "debuggable" this image is. We would like
158 to see at least one FDR with full symbols */
163 /* When examining .o files, report on undefined symbols */
165 static int n_undef_symbols
, n_undef_labels
, n_undef_vars
, n_undef_procs
;
167 /* Pseudo symbol to use when putting stabs into the symbol table. */
169 static char stabs_symbol
[] = "@stabs";
171 /* Extra builtin types */
173 struct type
*builtin_type_complex
;
174 struct type
*builtin_type_double_complex
;
175 struct type
*builtin_type_fixed_dec
;
176 struct type
*builtin_type_float_dec
;
177 struct type
*builtin_type_string
;
179 /* Forward declarations */
181 static struct symbol
*new_symbol();
182 static struct type
*new_type();
183 static struct block
*new_block();
184 static struct symtab
*new_symtab();
185 static struct linetable
*new_linetable();
186 static struct blockvector
*new_bvect();
188 static struct type
*parse_type();
189 static struct type
*make_type();
190 static struct symbol
*mylookup_symbol();
191 static struct block
*shrink_block();
192 static void sort_blocks();
194 static int compare_symtabs();
195 static int compare_psymtabs();
196 static int compare_blocks();
198 static struct partial_symtab
*new_psymtab();
199 static struct partial_symtab
*parse_fdr();
200 static int compare_psymbols();
202 static void psymtab_to_symtab_1();
203 static void add_block();
204 static void add_symbol();
205 static int add_line();
206 static struct linetable
*shrink_linetable();
208 /* Things we export to other modules */
210 /* Address bounds for the signal trampoline in inferior, if any */
211 /* FIXME: Nothing really seems to use this. Why is it here? */
213 CORE_ADDR sigtramp_address
, sigtramp_end
;
215 /* The entry point (starting address) of the file, if it is an executable. */
217 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
218 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
223 /* If we have a file symbol header lying around, blow it away. */
225 free ((char *)cur_hdr
);
230 mipscoff_symfile_init (sf
)
233 sf
->sym_private
= NULL
;
237 mipscoff_symfile_read(sf
, addr
, mainline
)
242 struct coff_symfile_info
*info
= (struct coff_symfile_info
*)sf
->sym_private
;
243 bfd
*abfd
= sf
->objfile
->obfd
;
244 char *name
= bfd_get_filename (abfd
);
248 int stringtab_offset
;
250 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
251 desc
= fileno ((FILE *)(abfd
->iostream
)); /* Raw file descriptor */
254 /* Position to read the symbol table. */
255 val
= lseek (desc
, (long)symtab_offset
, 0);
257 perror_with_name (name
);
259 init_misc_bunches ();
260 make_cleanup (discard_misc_bunches
, 0);
262 /* Now that the executable file is positioned at symbol table,
263 process it and define symbols accordingly. */
265 read_mips_symtab(sf
->objfile
, desc
);
267 /* Go over the misc symbol bunches and install them in vector. */
269 condense_misc_bunches (!mainline
);
272 /* Exported procedure: Allocate zeroed memory */
277 char *p
= xmalloc(size
);
283 /* Exported procedure: Builds a symtab from the PST partial one.
284 Restores the environment in effect when PST was created, delegates
285 most of the work to an ancillary procedure, and sorts
286 and reorders the symtab list at the end */
289 mipscoff_psymtab_to_symtab(pst
)
290 struct partial_symtab
*pst
;
299 printf_filtered("Reading in symbols for %s...", pst
->filename
);
302 /* Restore the header and list of pending typedefs */
303 cur_hdr
= CUR_HDR(pst
);
305 psymtab_to_symtab_1(pst
, pst
->filename
);
307 /* Match with global symbols. This only needs to be done once,
308 after all of the symtabs and dependencies have been read in. */
309 scan_file_globals ();
312 printf_filtered("done.\n");
315 /* Exported procedure: Is PC in the signal trampoline code */
318 in_sigtramp(pc
, name
)
322 if (sigtramp_address
== 0)
324 return (pc
>= sigtramp_address
&& pc
< sigtramp_end
);
327 /* File-level interface functions */
329 /* Read the symtab information from file FSYM into memory. Also,
330 return address just past end of our text segment in *END_OF_TEXT_SEGP. */
333 read_the_mips_symtab(abfd
, fsym
, end_of_text_segp
)
336 CORE_ADDR
*end_of_text_segp
;
338 int stsize
, st_hdrsize
;
341 /* Header for executable/object file we read symbols from */
342 struct coff_exec filhdr
;
344 /* We get here with DESC pointing to the symtab header. But we need
345 * other info from the initial headers */
347 myread(fsym
, &filhdr
, sizeof filhdr
);
349 if (end_of_text_segp
)
351 bfd_h_get_32 (abfd
, filhdr
.a
.text_start
) +
352 bfd_h_get_32 (abfd
, filhdr
.a
.tsize
);
354 /* Find and read the symbol table header */
355 st_hdrsize
= bfd_h_get_32 (abfd
, filhdr
.f
.f_nsyms
);
356 st_filptr
= bfd_h_get_32 (abfd
, filhdr
.f
.f_symptr
);
360 lseek(fsym
, st_filptr
, L_SET
);
361 if (st_hdrsize
> sizeof (st_hdr
)) /* Profanity check */
363 if (read(fsym
, &st_hdr
, st_hdrsize
) != st_hdrsize
)
366 /* Find out how large the symbol table is */
367 stsize
= (st_hdr
.cbExtOffset
- (st_filptr
+ st_hdrsize
))
368 + st_hdr
.iextMax
* cbEXTR
;
370 /* Allocate space for the symbol table. Read it in. */
371 cur_hdr
= (HDRR
*) xmalloc(stsize
+ st_hdrsize
);
373 memcpy(cur_hdr
, &st_hdr
, st_hdrsize
);
374 if (read(fsym
, (char *) cur_hdr
+ st_hdrsize
, stsize
) != stsize
)
377 /* Fixup file_pointers in it */
378 fixup_symtab(cur_hdr
, (char *) cur_hdr
+ st_hdrsize
,
379 st_filptr
+ st_hdrsize
);
383 error("Short read on %s", bfd_get_filename (abfd
));
387 /* Turn all file-relative pointers in the symtab described by HDR
388 into memory pointers, given that the symtab itself is located
389 at DATA in memory and F_PTR in the file. */
392 fixup_symtab( hdr
, data
, f_ptr
)
404 * These fields are useless (and empty) by now:
405 * hdr->cbDnOffset, hdr->cbOptOffset
406 * We use them for other internal purposes.
409 hdr
->cbOptOffset
= 0;
412 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
428 * Fix all string pointers inside the symtab, and
429 * the FDR records. Also fix other miscellany.
431 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
432 register unsigned code_offset
;
434 /* Header itself, and strings */
435 fh
= (FDR
*) (hdr
->cbFdOffset
) + f_idx
;
436 fh
->issBase
+= hdr
->cbSsOffset
;
438 fh
->rss
= (long)fh
->rss
+ fh
->issBase
;
441 fh
->isymBase
= (int)((SYMR
*)(hdr
->cbSymOffset
)+fh
->isymBase
);
443 /* FIXME! Probably don't want to do this here! */
444 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
445 sh
= (SYMR
*)fh
->isymBase
+ s_idx
;
446 sh
->iss
= (long) sh
->iss
+ fh
->issBase
;
452 /* cannot fix fh->ipdFirst because it is a short */
453 #define IPDFIRST(h,fh) \
454 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
456 /* Optional symbols (actually used for partial_symtabs) */
462 fh
->iauxBase
= hdr
->cbAuxOffset
+ fh
->iauxBase
* sizeof(AUXU
);
463 /* Relative file descriptor table */
464 fh
->rfdBase
= hdr
->cbRfdOffset
+ fh
->rfdBase
* sizeof(RFDT
);
468 fh
->cbLineOffset
+= hdr
->cbLineOffset
;
470 /* Procedure symbols. (XXX This should be done later) */
471 code_offset
= fh
->adr
;
472 for (s_idx
= 0; s_idx
< fh
->cpd
; s_idx
++) {
473 unsigned name
, only_ext
;
475 pr
= (PDR
*)(IPDFIRST(hdr
,fh
)) + s_idx
;
477 /* Simple rule to find files linked "-x" */
478 only_ext
= fh
->rss
== -1;
480 if (pr
->isym
== -1) {
481 /* static function */
485 name
= hdr
->cbExtOffset
+ pr
->isym
* sizeof(EXTR
);
486 sh
= &((EXTR
*)name
)->asym
;
490 sh
= (SYMR
*)fh
->isymBase
+ pr
->isym
;
491 /* Included code ? */
492 if (s_idx
== 0 && pr
->adr
!= 0)
493 code_offset
-= pr
->adr
;
496 /* Turn index into a pointer */
499 /* Fix line numbers */
500 pr
->cbLineOffset
+= fh
->cbLineOffset
;
502 /* Relocate address */
504 pr
->adr
+= code_offset
;
508 /* External symbols: fix string */
509 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
510 esh
= (EXTR
*)(hdr
->cbExtOffset
) + s_idx
;
511 esh
->asym
.iss
= esh
->asym
.iss
+ hdr
->cbSsExtOffset
;
516 /* Find a file descriptor given its index RF relative to a file CF */
524 f
= (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
525 /* Object files do not have the RFD table, all refs are absolute */
527 return (FDR
*) (cur_hdr
->cbFdOffset
) + rf
;
528 cf
= *((pRFDT
) f
->rfdBase
+ rf
);
529 return (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
532 /* Return a safer print NAME for a file descriptor */
538 if (name
== (char *) -1)
539 return "<stripped file>";
540 if (UNSAFE_DATA_ADDR(name
))
546 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
547 whether we are adding to the general symtab or not.
548 FIXME: INCREMENTAL is currently always zero, though it should not be. */
551 read_mips_symtab (objfile
, desc
)
552 struct objfile
*objfile
;
555 CORE_ADDR end_of_text_seg
;
557 read_the_mips_symtab(objfile
->obfd
, desc
, &end_of_text_seg
);
559 parse_partial_symbols(end_of_text_seg
, objfile
);
563 * Check to make sure file was compiled with -g.
564 * If not, warn the user of this limitation.
566 if (compare_glevel(max_glevel
, GLEVEL_2
) < 0) {
567 if (max_gdbinfo
== 0)
569 "\n%s not compiled with -g, debugging support is limited.\n",
572 "You should compile with -g2 or -g3 for best debugging support.\n");
578 /* Local utilities */
580 /* Map of FDR indexes to partial symtabs */
582 static struct pst_map
{
583 struct partial_symtab
*pst
; /* the psymtab proper */
587 /* Utility stack, used to nest procedures and blocks properly.
588 It is a doubly linked list, to avoid too many alloc/free.
589 Since we might need it quite a few times it is NOT deallocated
592 static struct parse_stack
{
593 struct parse_stack
*next
, *prev
;
594 struct symtab
*cur_st
; /* Current symtab. */
595 struct block
*cur_block
; /* Block in it. */
596 int blocktype
; /* What are we parsing. */
597 int maxsyms
; /* Max symbols in this block. */
598 struct type
*cur_type
; /* Type we parse fields for. */
599 int cur_field
; /* Field number in cur_type. */
600 int procadr
; /* Start addres of this procedure */
601 int numargs
; /* Its argument count */
602 } *top_stack
; /* Top stack ptr */
605 /* Enter a new lexical context */
607 static push_parse_stack()
609 struct parse_stack
*new;
611 /* Reuse frames if possible */
612 if (top_stack
&& top_stack
->prev
)
613 new = top_stack
->prev
;
615 new = (struct parse_stack
*) xzalloc(sizeof(struct parse_stack
));
616 /* Initialize new frame with previous content */
618 register struct parse_stack
*prev
= new->prev
;
621 top_stack
->prev
= new;
623 new->next
= top_stack
;
628 /* Exit a lexical context */
630 static pop_parse_stack()
635 top_stack
= top_stack
->next
;
639 /* Cross-references might be to things we haven't looked at
640 yet, e.g. type references. To avoid too many type
641 duplications we keep a quick fixup table, an array
642 of lists of references indexed by file descriptor */
644 static struct mips_pending
{
645 struct mips_pending
*next
; /* link */
646 SYMR
*s
; /* the symbol */
647 struct type
*t
; /* its partial type descriptor */
651 /* Check whether we already saw symbol SH in file FH as undefined */
654 struct mips_pending
*is_pending_symbol(fh
, sh
)
658 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
659 register struct mips_pending
*p
;
661 /* Linear search is ok, list is typically no more than 10 deep */
662 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
668 /* Check whether we already saw type T in file FH as undefined */
671 struct mips_pending
*is_pending_type(fh
, t
)
675 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
676 register struct mips_pending
*p
;
678 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
684 /* Add a new undef symbol SH of type T */
687 add_pending(fh
, sh
, t
)
692 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
693 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
695 /* Make sure we do not make duplicates */
697 p
= (struct mips_pending
*) xmalloc(sizeof(*p
));
700 p
->next
= pending_list
[f_idx
];
701 pending_list
[f_idx
] = p
;
703 sh
->reserved
= 1; /* for quick check */
706 /* Throw away undef entries when done with file index F_IDX */
711 register struct mips_pending
*p
, *q
;
713 for (p
= pending_list
[f_idx
]; p
; p
= q
) {
717 pending_list
[f_idx
] = 0;
720 /* The number of args to a procedure is not explicit in the symtab,
721 this is the list of all those we know of.
722 This makes parsing more reasonable and avoids extra passes */
724 static struct numarg
{
725 struct numarg
*next
; /* link */
726 unsigned adr
; /* procedure's start address */
727 unsigned num
; /* arg count */
730 /* Record that the procedure at ADR takes NUM arguments. */
735 struct numarg
*n
= (struct numarg
*) xmalloc(sizeof(struct numarg
));
739 n
->next
= numargs_list
;
743 /* See if we know how many arguments the procedure at ADR takes */
748 struct numarg
*n
= numargs_list
;
750 while (n
&& n
->adr
!= adr
)
752 return (n
) ? n
->num
: -1;
755 /* Release storage when done with this file */
760 struct numarg
*n
= numargs_list
, *m
;
771 /* Parsing Routines proper. */
773 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
774 For blocks, procedures and types we open a new lexical context.
775 This is basically just a big switch on the symbol's type.
776 Return count of SYMR's handled (normally one). */
789 /* When a symbol is cross-referenced from other files/symbols
790 we mark it explicitly */
791 int pend
= (sh
->reserved
== 1);
792 enum address_class
class;
799 case stGlobal
: /* external symbol, goes into global block */
801 b
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
803 s
= new_symbol(sh
->iss
);
804 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
807 case stStatic
: /* static data, goes into current block. */
809 b
= top_stack
->cur_block
;
810 s
= new_symbol(sh
->iss
);
811 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
814 case stLocal
: /* local variable, goes into current block */
815 if (sh
->sc
== scRegister
) {
816 class = LOC_REGISTER
;
821 b
= top_stack
->cur_block
;
822 s
= new_symbol(sh
->iss
);
823 SYMBOL_VALUE(s
) = sh
->value
;
825 data
: /* Common code for symbols describing data */
826 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
827 SYMBOL_CLASS(s
) = class;
830 /* Type could be missing in a number of cases */
831 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
832 sh
->index
== 0xfffff)
833 SYMBOL_TYPE(s
) = builtin_type_int
; /* undefined? */
835 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
836 /* Value of a data symbol is its memory address */
839 case stParam
: /* arg to procedure, goes into current block */
841 top_stack
->numargs
++;
843 name
= (char*)sh
->iss
;
844 /* Special GNU C++ name. */
845 if (name
[0] == CPLUS_MARKER
&& name
[1] == 't' && name
[2] == 0)
847 s
= new_symbol(name
);
849 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
850 if (sh
->sc
== scRegister
) {
851 SYMBOL_CLASS(s
) = LOC_REGPARM
;
855 SYMBOL_CLASS(s
) = LOC_ARG
;
856 SYMBOL_VALUE(s
) = sh
->value
;
857 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
858 add_symbol(s
, top_stack
->cur_block
);
860 /* FIXME: This has not been tested. See dbxread.c */
861 /* Add the type of this parameter to the function/procedure
862 type of this block. */
863 add_param_to_type(&top_stack
->cur_block
->function
->type
,s
);
867 case stLabel
: /* label, goes into current block */
868 s
= new_symbol(sh
->iss
);
869 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
; /* so that it can be used */
870 SYMBOL_CLASS(s
) = LOC_LABEL
; /* but not misused */
871 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
872 SYMBOL_TYPE(s
) = builtin_type_int
;
873 add_symbol(s
, top_stack
->cur_block
);
876 case stProc
: /* Procedure, usually goes into global block */
877 case stStaticProc
: /* Static procedure, goes into current block */
878 s
= new_symbol(sh
->iss
);
879 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
880 SYMBOL_CLASS(s
) = LOC_BLOCK
;
881 /* Type of the return value */
882 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
883 t
= builtin_type_int
;
885 t
= parse_type(ax
+ sh
->index
, sh
, 0);
886 b
= top_stack
->cur_block
;
887 if (sh
->st
== stProc
) {
888 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
889 /* The next test should normally be true,
890 but provides a hook for nested functions
891 (which we don't want to make global). */
892 if (b
== BLOCKVECTOR_BLOCK(bv
, STATIC_BLOCK
))
893 b
= BLOCKVECTOR_BLOCK(bv
, GLOBAL_BLOCK
);
897 /* Make a type for the procedure itself */
899 /* FIXME: This has not been tested yet! See dbxread.c */
900 /* Generate a template for the type of this function. The
901 types of the arguments will be added as we read the symbol
903 bcopy(SYMBOL_TYPE(s
),lookup_function_type(t
),sizeof(struct type
));
905 SYMBOL_TYPE(s
) = lookup_function_type (t
);
908 /* Create and enter a new lexical context */
909 b
= new_block(top_stack
->maxsyms
);
910 SYMBOL_BLOCK_VALUE(s
) = b
;
911 BLOCK_FUNCTION(b
) = s
;
912 BLOCK_START(b
) = BLOCK_END(b
) = sh
->value
;
913 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
914 add_block(b
, top_stack
->cur_st
);
916 /* Not if we only have partial info */
917 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
921 top_stack
->cur_block
= b
;
922 top_stack
->blocktype
= sh
->st
;
923 top_stack
->cur_type
= SYMBOL_TYPE(s
);
924 top_stack
->cur_field
= -1;
925 top_stack
->procadr
= sh
->value
;
926 top_stack
->numargs
= 0;
928 sh
->value
= (long) SYMBOL_TYPE(s
);
931 case stBlock
: /* Either a lexical block, or some type */
933 top_stack
->blocktype
= stBlock
;
934 if (sh
->sc
== scInfo
) { /* structure/union/enum def */
935 int type_code
= TYPE_CODE_UNDEF
;
937 s
= new_symbol(sh
->iss
);
938 SYMBOL_NAMESPACE(s
) = STRUCT_NAMESPACE
;
939 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
941 add_symbol(s
, top_stack
->cur_block
);
942 /* If this type was expected, use its partial definition */
944 t
= is_pending_symbol(cur_fdr
, sh
)->t
;
951 /* First count the number of fields. */
952 for (tsym
= sh
+1; tsym
->st
!= stEnd
; tsym
++)
953 if (tsym
->st
== stMember
) {
955 if (tsym
->index
== indexNil
956 || ax
[tsym
->index
].ti
.bt
==26)/*btVoid*/
957 type_code
= TYPE_CODE_ENUM
;
959 if (tsym
->value
> max_value
)
960 max_value
= tsym
->value
;
962 else if (tsym
->st
== stBlock
963 || tsym
->st
== stParsed
) {
964 if (tsym
->sc
== scVariant
) ; /*UNIMPLEMENTED*/
965 if (tsym
->index
!= 0)
966 tsym
= ((SYMR
*)cur_fdr
->isymBase
)
970 t
= new_type(sh
->iss
);
972 /* Guess the type code. */
973 if (type_code
== TYPE_CODE_UNDEF
)
974 if (max_value
== 0) type_code
= TYPE_CODE_UNION
;
975 else type_code
= TYPE_CODE_STRUCT
;
977 TYPE_CODE(t
) = type_code
;
978 TYPE_NFIELDS(t
) = nfields
;
979 TYPE_FIELDS(t
) = f
= (struct field
*)
980 obstack_alloc (symbol_obstack
,
981 nfields
* sizeof (struct field
));
983 if (type_code
== TYPE_CODE_ENUM
) {
984 /* This is a non-empty enum. */
985 while (sh
[1].st
== stMember
) {
986 struct symbol
*enum_sym
;
988 f
->bitpos
= sh
->value
;
990 f
->name
= (char*)sh
->iss
;
993 enum_sym
= (struct symbol
*)
994 obstack_alloc (symbol_obstack
,
995 sizeof (struct symbol
));
996 memset (enum_sym
, 0, sizeof (struct symbol
));
997 SYMBOL_NAME (enum_sym
) = f
->name
;
998 SYMBOL_CLASS (enum_sym
) = LOC_CONST
;
999 SYMBOL_TYPE (enum_sym
) = t
;
1000 SYMBOL_NAMESPACE (enum_sym
) = VAR_NAMESPACE
;
1001 SYMBOL_VALUE (enum_sym
) = sh
->value
;
1002 add_symbol(enum_sym
, top_stack
->cur_block
);
1009 /* Uhmm, can`t decide yet. Guess. */
1010 add_pending(cur_fdr
, sh
, t
);
1014 /* make this the current type */
1015 top_stack
->cur_type
= t
;
1016 top_stack
->cur_field
= 0;
1017 TYPE_LENGTH(t
) = sh
->value
;
1018 /* Mark that symbol has a type, and say which one */
1019 sh
->value
= (long) t
;
1021 /* beginnning of (code) block. Value of symbol
1022 is the displacement from procedure start */
1023 b
= new_block(top_stack
->maxsyms
);
1024 BLOCK_START(b
) = sh
->value
+ top_stack
->procadr
;
1025 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1026 top_stack
->cur_block
= b
;
1027 add_block(b
, top_stack
->cur_st
);
1031 case stEnd
: /* end (of anything) */
1032 if (sh
->sc
== scInfo
) {
1033 /* Finished with type */
1034 top_stack
->cur_type
= 0;
1035 } else if (sh
->sc
== scText
&&
1036 (top_stack
->blocktype
== stProc
||
1037 top_stack
->blocktype
== stStaticProc
)) {
1038 /* Finished with procedure */
1039 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
1043 BLOCK_END(top_stack
->cur_block
) += sh
->value
; /* size */
1044 got_numargs(top_stack
->procadr
, top_stack
->numargs
);
1045 /* Reallocate symbols, saving memory */
1046 b
= shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1048 /* f77 emits proc-level with address bounds==[0,0],
1049 So look for such child blocks, and patch them. */
1050 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++) {
1051 struct block
*b_bad
= BLOCKVECTOR_BLOCK(bv
,i
);
1052 if (BLOCK_SUPERBLOCK(b_bad
) == b
1053 && BLOCK_START(b_bad
) == top_stack
->procadr
1054 && BLOCK_END(b_bad
) == top_stack
->procadr
) {
1055 BLOCK_START(b_bad
) = BLOCK_START(b
);
1056 BLOCK_END(b_bad
) = BLOCK_END(b
);
1059 if (entry_point
< BLOCK_END(b
)
1060 && entry_point
>= BLOCK_START(b
)) {
1061 startup_file_start
= BLOCK_START(b
);
1062 startup_file_end
= BLOCK_END(b
);
1064 } else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
) {
1065 /* End of (code) block. The value of the symbol
1066 is the displacement from the procedure`s start
1067 address of the end of this block. */
1068 BLOCK_END(top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1069 (void) shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1071 pop_parse_stack(); /* restore previous lexical context */
1074 case stMember
: /* member of struct or union */
1075 f
= &TYPE_FIELDS(top_stack
->cur_type
)[top_stack
->cur_field
++];
1076 f
->name
= (char*)sh
->iss
;
1077 f
->bitpos
= sh
->value
;
1079 f
->type
= parse_type(ax
+ sh
->index
, sh
, &f
->bitsize
);
1082 case stTypedef
: /* type definition */
1083 s
= new_symbol(sh
->iss
);
1084 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1085 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1086 SYMBOL_BLOCK_VALUE(s
) = top_stack
->cur_block
;
1087 add_symbol(s
, top_stack
->cur_block
);
1088 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
1089 sh
->value
= (long) SYMBOL_TYPE(s
);
1092 case stFile
: /* file name */
1094 top_stack
->blocktype
= sh
->st
;
1097 /* I`ve never seen these for C */
1099 break; /* register relocation */
1101 break; /* forwarding address */
1103 break; /* constant */
1105 error("Unknown symbol type %x.", sh
->st
);
1111 /* Parse the type information provided in the AX entries for
1112 the symbol SH. Return the bitfield size in BS, in case. */
1114 static struct type
*parse_type(ax
, sh
, bs
)
1119 /* Null entries in this map are treated specially */
1120 static struct type
**map_bt
[] =
1122 &builtin_type_void
, /* btNil */
1124 &builtin_type_char
, /* btChar */
1125 &builtin_type_unsigned_char
, /* btUChar */
1126 &builtin_type_short
, /* btShort */
1127 &builtin_type_unsigned_short
, /* btUShort */
1128 &builtin_type_int
, /* btInt */
1129 &builtin_type_unsigned_int
, /* btUInt */
1130 &builtin_type_long
, /* btLong */
1131 &builtin_type_unsigned_long
, /* btULong */
1132 &builtin_type_float
, /* btFloat */
1133 &builtin_type_double
, /* btDouble */
1140 &builtin_type_complex
, /* btComplex */
1141 &builtin_type_double_complex
, /* btDComplex */
1143 &builtin_type_fixed_dec
, /* btFixedDec */
1144 &builtin_type_float_dec
, /* btFloatDec */
1145 &builtin_type_string
, /* btString */
1148 &builtin_type_void
, /* btVoid */
1152 struct type
*tp
= 0;
1157 /* Procedures start off by one */
1158 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
)
1161 /* Undefined ? Should not happen */
1162 if (ax
->rndx
.rfd
== 0xfff) {
1163 return builtin_type_void
;
1166 /* Use aux as a type information record, map its basic type */
1168 if (t
->bt
> (sizeof (map_bt
)/sizeof (*map_bt
))) {
1169 complain (&basic_type_complaint
, t
->bt
);
1170 return builtin_type_int
;
1172 if (map_bt
[t
->bt
]) {
1173 tp
= *map_bt
[t
->bt
];
1177 /* Cannot use builtin types -- build our own */
1180 tp
= lookup_pointer_type (builtin_type_void
);
1184 type_code
= TYPE_CODE_STRUCT
;
1188 type_code
= TYPE_CODE_UNION
;
1192 type_code
= TYPE_CODE_ENUM
;
1196 type_code
= TYPE_CODE_RANGE
;
1200 type_code
= TYPE_CODE_SET
;
1205 complain (&basic_type_complaint
, t
->bt
);
1206 return builtin_type_int
;
1210 /* Move on to next aux */
1213 /* This is the way it would work if the compiler worked */
1214 register TIR
*t1
= t
;
1215 while (t1
->continued
)
1224 /* All these types really point to some (common) MIPS type
1225 definition, and only the type-qualifiers fully identify
1226 them. We'll make the same effort at sharing. */
1227 if (t
->bt
== btIndirect
||
1228 t
->bt
== btStruct
||
1231 t
->bt
== btTypedef
||
1234 char name
[256], *pn
;
1236 /* Try to cross reference this type */
1237 ax
+= cross_ref(ax
, &tp
, type_code
, &pn
);
1238 /* reading .o file ? */
1239 if (UNSAFE_DATA_ADDR(tp
))
1240 tp
= make_type(type_code
, 0, 0, 0);
1241 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1242 sprintf(name
, fmt
, pn
);
1244 /* Usually, TYPE_CODE(tp) is already type_code. The main
1245 exception is if we guessed wrong re struct/union/enum. */
1246 TYPE_CODE(tp
) = type_code
;
1247 TYPE_NAME(tp
) = obsavestring(pn
, strlen(pn
));
1250 /* Deal with range types */
1251 if (t
->bt
== btRange
) {
1254 TYPE_NFIELDS (tp
) = 2;
1256 (struct field
*) obstack_alloc (symbol_obstack
,
1257 2 * sizeof (struct field
));
1258 TYPE_FIELD_NAME (tp
, 0) = "Low";
1259 TYPE_FIELD_BITPOS (tp
, 0) = ax
->dnLow
;
1261 TYPE_FIELD_NAME (tp
, 1) = "High";
1262 TYPE_FIELD_BITPOS (tp
, 1) = ax
->dnHigh
;
1266 /* Parse all the type qualifiers now. If there are more
1267 than 6 the game will continue in the next aux */
1269 #define PARSE_TQ(tq) \
1270 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, sh);
1272 again
: PARSE_TQ(tq0
);
1287 /* Make up a complex type from a basic one. Type is passed by
1288 reference in TPP and side-effected as necessary. The type
1289 qualifier TQ says how to handle the aux symbols at AX for
1290 the symbol SX we are currently analyzing.
1291 Returns the number of aux symbols we parsed. */
1294 upgrade_type(tpp
, tq
, ax
, sh
)
1302 /* Used in array processing */
1311 t
= lookup_pointer_type (*tpp
);
1316 t
= lookup_function_type (*tpp
);
1322 t
= make_type(TYPE_CODE_ARRAY
, 0, 0, 0);
1323 TYPE_TARGET_TYPE(t
) = *tpp
;
1325 /* Determine and record the domain type (type of index) */
1326 id
= ax
->rndx
.index
;
1332 fh
= get_rfd(cur_fd
, rf
);
1334 /* Fields are kept in an array */
1335 /* FIXME - Memory leak! */
1336 if (TYPE_NFIELDS(t
))
1337 TYPE_FIELDS(t
) = (struct field
*)
1338 xrealloc(TYPE_FIELDS(t
),
1339 (TYPE_NFIELDS(t
)+1) * sizeof(struct field
));
1341 TYPE_FIELDS(t
) = (struct field
*)
1342 xzalloc(sizeof(struct field
));
1343 f
= &(TYPE_FIELD(t
,TYPE_NFIELDS(t
)));
1345 memset(f
, 0, sizeof(struct field
));
1347 memset(&ss
, 0, sizeof ss
);
1348 /* XXX */ f
->type
= parse_type(fh
->iauxBase
+ id
* sizeof(AUXU
),
1353 * This seems to be a pointer to the end of the Block defining
1354 * the type. Why it is here is magic for me, and I have no
1355 * good use for it anyways.
1357 /* This used to occur because cross_ref returned
1358 the wrong result (ax pointed wrong). FIXME,
1359 delete this code in a while. -- gnu@cygnus jul91 */
1360 complain (&array_parse_complaint
, 0);
1362 id
= (++ax
)->rndx
.index
;
1363 if ((rf
= ax
->rndx
.rfd
) == 0xfff)
1364 rf
= (++ax
)->isym
, off
++;
1366 lower
= (++ax
)->dnLow
;
1367 upper
= (++ax
)->dnHigh
;
1368 rf
= (++ax
)->width
; /* bit size of array element */
1370 /* Check whether supplied array element bit size matches
1371 the known size of the element type. If this complaint
1372 ends up not happening, we can remove this code. It's
1373 here because we aren't sure we understand this *&%&$
1375 id
= TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) << 3; /* bitsize */
1377 /* Most likely an undefined type */
1379 TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) = id
>> 3;
1382 complain (&array_bitsize_complaint
, rf
);
1384 TYPE_LENGTH(t
) = (upper
< 0) ? 0 :
1385 (upper
- lower
+ 1) * (rf
>> 3);
1390 /* Volatile -- currently ignored */
1394 complain (&unknown_type_qual_complaint
, tq
);
1400 /* Parse a procedure descriptor record PR. Note that the procedure
1401 is parsed _after_ the local symbols, now we just make up the
1402 extra information we need into a special symbol that we insert
1403 in the procedure's main block. Note also that images that
1404 have been partially stripped (ld -x) have been deprived
1405 of local symbols, and we have to cope with them here.
1406 The procedure's code ends at BOUND */
1409 parse_procedure(pr
, bound
)
1412 struct symbol
*s
, *i
;
1413 SYMR
*sh
= (SYMR
*)pr
->isym
;
1415 struct mips_extra_func_info
*e
;
1419 /* Reuse the MIPS record */
1420 e
= (struct mips_extra_func_info
*) pr
;
1421 e
->numargs
= lookup_numargs(pr
->adr
);
1423 /* Make up our special symbol */
1424 i
= new_symbol(".gdbinfo.");
1425 SYMBOL_VALUE(i
) = (int)e
;
1426 SYMBOL_NAMESPACE(i
) = LABEL_NAMESPACE
;
1427 SYMBOL_CLASS(i
) = LOC_CONST
;
1428 SYMBOL_TYPE(i
) = builtin_type_void
;
1430 /* Make up a name for static procedures. Sigh. */
1431 if (sh
== (SYMR
*)-1) {
1432 sprintf(name
,".static_procedure@%x",pr
->adr
);
1433 sh_name
= savestring(name
, strlen(name
));
1437 sh_name
= (char*)sh
->iss
;
1438 s
= mylookup_symbol(sh_name
, top_stack
->cur_block
,
1439 VAR_NAMESPACE
, LOC_BLOCK
);
1442 b
= SYMBOL_BLOCK_VALUE(s
);
1444 s
= new_symbol(sh_name
);
1445 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1446 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1447 /* Donno its type, hope int is ok */
1448 SYMBOL_TYPE(s
) = lookup_function_type (builtin_type_int
);
1449 add_symbol(s
, top_stack
->cur_block
);
1450 /* Wont have symbols for this one */
1452 SYMBOL_BLOCK_VALUE(s
) = b
;
1453 BLOCK_FUNCTION(b
) = s
;
1454 BLOCK_START(b
) = pr
->adr
;
1455 BLOCK_END(b
) = bound
;
1456 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1457 add_block(b
, top_stack
->cur_st
);
1463 /* Parse the external symbol ES. Just call parse_symbol() after
1464 making sure we know where the aux are for it. For procedures,
1465 parsing of the PDRs has already provided all the needed
1466 information, we only parse them if SKIP_PROCEDURES is false,
1467 and only if this causes no symbol duplication.
1469 This routine clobbers top_stack->cur_block and ->cur_st. */
1472 parse_external(es
, skip_procedures
)
1477 if (es
->ifd
!= ifdNil
) {
1479 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
) + cur_fd
;
1480 ax
= (AUXU
*)cur_fdr
->iauxBase
;
1482 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
);
1485 top_stack
->cur_st
= cur_stab
;
1486 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
1489 /* Reading .o files */
1490 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
) {
1492 switch (es
->asym
.st
) {
1494 case stProc
: what
= "procedure"; n_undef_procs
++; break;
1495 case stGlobal
: what
= "variable"; n_undef_vars
++; break;
1496 case stLabel
: what
= "label"; n_undef_labels
++; break;
1497 default : what
= "symbol"; break;
1501 printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what
,
1502 es
->asym
.iss
, fdr_name(cur_fdr
->rss
));
1506 switch (es
->asym
.st
) {
1508 /* If we have full symbols we do not need more */
1509 if (skip_procedures
)
1511 if (mylookup_symbol (es
->asym
.iss
, top_stack
->cur_block
,
1512 VAR_NAMESPACE
, LOC_BLOCK
))
1518 * Note that the case of a symbol with indexNil
1519 * must be handled anyways by parse_symbol().
1521 parse_symbol(&es
->asym
, ax
);
1528 /* Parse the line number info for file descriptor FH into
1529 GDB's linetable LT. MIPS' encoding requires a little bit
1530 of magic to get things out. Note also that MIPS' line
1531 numbers can go back and forth, apparently we can live
1532 with that and do not need to reorder our linetables */
1537 struct linetable
*lt
;
1539 unsigned char *base
= (unsigned char*)fh
->cbLineOffset
;
1541 int delta
, count
, lineno
= 0;
1547 /* Scan by procedure descriptors */
1548 i
= 0; j
= 0, k
= 0;
1549 for (pr
= (PDR
*)IPDFIRST(cur_hdr
,fh
); j
< fh
->cpd
; j
++, pr
++) {
1552 /* No code for this one */
1553 if (pr
->iline
== ilineNil
||
1554 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1557 * Aurgh! To know where to stop expanding we
1560 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1561 if (pr
[l
].iline
!= -1)
1563 if (l
== (fh
->cpd
- j
))
1568 * When procedures are moved around the linenumbers
1569 * are attributed to the next procedure up
1571 if (pr
->iline
>= halt
) continue;
1573 base
= (unsigned char*)pr
->cbLineOffset
;
1574 l
= pr
->adr
>> 2; /* in words */
1575 halt
+= (pr
->adr
>> 2) - pr
->iline
;
1576 for (lineno
= pr
->lnLow
; l
< halt
;) {
1577 count
= *base
& 0x0f;
1578 delta
= *base
++ >> 4;
1582 delta
= (base
[0] << 8) | base
[1];
1583 if (delta
>= 0x8000)
1587 lineno
+= delta
;/* first delta is 0 */
1588 k
= add_line(lt
, lineno
, l
, k
);
1595 /* Master parsing procedure for first-pass reading of file symbols
1596 into a partial_symtab.
1598 Parses the symtab described by the global symbolic header CUR_HDR.
1599 END_OF_TEXT_SEG gives the address just after the text segment for
1600 the symtab we are reading. */
1603 parse_partial_symbols(end_of_text_seg
, objfile
)
1604 int end_of_text_seg
;
1605 struct objfile
*objfile
;
1608 /* int stat_idx, h_max;*/
1610 /* Running pointers */
1615 struct partial_symtab
*pst
;
1617 int past_first_source_file
= 0;
1619 /* List of current psymtab's include files */
1620 char **psymtab_include_list
;
1621 int includes_allocated
;
1624 /* Index within current psymtab dependency list */
1625 struct partial_symtab
**dependency_list
;
1626 int dependencies_used
, dependencies_allocated
;
1628 includes_allocated
= 30;
1630 psymtab_include_list
= (char **) alloca (includes_allocated
*
1633 dependencies_allocated
= 30;
1634 dependencies_used
= 0;
1636 (struct partial_symtab
**) alloca (dependencies_allocated
*
1637 sizeof (struct partial_symtab
*));
1639 last_source_file
= 0;
1644 * Only parse the Local and External symbols, and the Relative FDR.
1645 * Fixup enough of the loader symtab to be able to use it.
1646 * Allocate space only for the file's portions we need to
1652 max_glevel
= MIN_GLEVEL
;
1654 /* Allocate the map FDR -> PST.
1655 Minor hack: -O3 images might claim some global data belongs
1656 to FDR -1. We`ll go along with that */
1657 fdr_to_pst
= (struct pst_map
*)xzalloc((hdr
->ifdMax
+1) * sizeof *fdr_to_pst
);
1660 struct partial_symtab
* pst
= new_psymtab("", objfile
);
1661 fdr_to_pst
[-1].pst
= pst
;
1665 /* Pass 2 over external syms: fill in external symbols */
1666 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1667 register struct partial_symbol
*p
;
1668 enum misc_function_type misc_type
= mf_text
;
1669 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1671 if (esh
->asym
.sc
== scUndefined
|| esh
->asym
.sc
== scNil
)
1674 switch (esh
->asym
.st
) {
1678 misc_type
= mf_data
;
1683 misc_type
= mf_unknown
;
1684 complain (&unknown_ext_complaint
, SYMBOL_NAME(p
));
1686 prim_record_misc_function ((char *)(esh
->asym
.iss
),
1691 /* Pass 3 over files, over local syms: fill in static symbols */
1692 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
1693 struct partial_symtab
*save_pst
;
1695 fh
= f_idx
+ (FDR
*)(cur_hdr
->cbFdOffset
);
1696 if (fh
->csym
== 0) {
1697 fdr_to_pst
[f_idx
].pst
= NULL
;
1700 pst
= start_psymtab (objfile
, 0, (char*)fh
->rss
,
1701 fh
->cpd
? fh
->adr
: 0,
1703 global_psymbols
.next
,
1704 static_psymbols
.next
);
1706 /* Make everything point to everything. */
1707 FDR_IDX(pst
) = f_idx
;
1708 fdr_to_pst
[f_idx
].pst
= pst
;
1709 fh
->ioptBase
= (int)pst
;
1711 CUR_HDR(pst
) = cur_hdr
;
1713 /* The way to turn this into a symtab is to call... */
1714 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
1716 pst
->texthigh
= pst
->textlow
;
1718 pst
->globals_offset
= global_psymbols
.next
- global_psymbols
.list
;
1719 pst
->statics_offset
= static_psymbols
.next
- static_psymbols
.list
;
1721 pst
->n_global_syms
= 0;
1722 pst
->n_static_syms
= 0;
1725 /* The second symbol must be @stab. */
1727 && strcmp(((SYMR
*)fh
->isymBase
)[1].iss
, stabs_symbol
) == 0) {
1728 for (s_idx
= 2; s_idx
< fh
->csym
; s_idx
++) {
1731 sh
= s_idx
+ (SYMR
*) fh
->isymBase
;
1732 type_code
= MIPS_UNMARK_STAB(sh
->index
);
1734 if (type_code
== 0x84 && s_idx
== 2) continue;
1735 if (!MIPS_IS_STAB(sh
)) {
1736 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
) {
1737 long procaddr
= sh
->value
;
1738 sh
= (sh
->index
+ (AUXU
*)fh
->iauxBase
)->isym
1739 + (SYMR
*) fh
->isymBase
- 1;
1740 if (sh
->st
== stEnd
) {
1741 long high
= procaddr
+ sh
->value
;
1742 if (high
> pst
->texthigh
)
1743 pst
->texthigh
= high
;
1748 #define SET_NAMESTRING() namestring = (char*)sh->iss
1749 #define CUR_SYMBOL_TYPE type_code
1750 #define CUR_SYMBOL_VALUE sh->value
1751 #define CHECK_SECOND_N_SO() \
1752 if (s_idx < fh->csym \
1753 && MIPS_UNMARK_STAB(((SYMR *)fh->isymBase)[s_idx+1].index) == (unsigned char)N_SO)\
1756 sh = s_idx + (SYMR *) fh->isymBase;\
1758 valu = CUR_SYMBOL_VALUE;\
1761 #define START_PSYMTAB(ofile,addr,fname,low,symoff,global_syms,static_syms)\
1763 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
1765 #define HANDLE_RBRAC(val) \
1766 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
1767 /* FIXME: Handle start_file_start and _end */
1768 /* FIXME: Handle enums - but must deal with next_symbol_text. */
1769 #include "partial-stab.h"
1774 for (s_idx
= 0; s_idx
< fh
->csym
; ) {
1775 register struct partial_symbol
*p
;
1778 sh
= s_idx
+ (SYMR
*) fh
->isymBase
;
1780 if (MIPS_IS_STAB(sh
)) {
1785 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
1786 sh
->index
== 0xfffff) {
1787 /* FIXME, premature? */
1792 name
= (char *)(sh
->iss
);
1797 case stProc
: /* Asm labels apparently */
1798 case stStaticProc
: /* Function */
1799 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
1800 VAR_NAMESPACE
, LOC_BLOCK
,
1801 static_psymbols
, sh
->value
);
1802 /* Skip over procedure to next one. */
1803 s_idx
= (sh
->index
+ (AUXU
*)fh
->iauxBase
)->isym
;
1804 procaddr
= sh
->value
;
1806 sh
= s_idx
+ (SYMR
*) fh
->isymBase
- 1;
1807 if (sh
->st
!= stEnd
)
1809 high
= procaddr
+ sh
->value
;
1810 if (high
> pst
->texthigh
)
1811 pst
->texthigh
= high
;
1813 case stStatic
: /* Variable */
1816 case stTypedef
: /* Typedef */
1817 class = LOC_TYPEDEF
;
1819 case stConstant
: /* Constant decl */
1822 case stBlock
: /* { }, str, un, enum*/
1823 if (sh
->sc
== scInfo
) {
1824 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
1825 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1826 static_psymbols
, sh
->value
);
1828 /* Skip over the block */
1831 case stFile
: /* File headers */
1832 case stLabel
: /* Labels */
1833 case stEnd
: /* Ends of files */
1836 complain (&unknown_sym_complaint
, SYMBOL_NAME(p
));
1837 complain (&unknown_st_complaint
, sh
->st
);
1841 /* Use this gdb symbol */
1842 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
1843 VAR_NAMESPACE
, class,
1844 static_psymbols
, sh
->value
);
1846 s_idx
++; /* Go to next file symbol */
1849 end_psymtab (save_pst
, psymtab_include_list
, includes_used
,
1850 -1, save_pst
->texthigh
,
1851 dependency_list
, dependencies_used
,
1852 global_psymbols
.next
, static_psymbols
.next
);
1855 /* Mark the last code address, and remember it for later */
1856 hdr
->cbDnOffset
= end_of_text_seg
;
1858 free(&fdr_to_pst
[-1]);
1863 /* Do the initial analisys of the F_IDX-th file descriptor.
1864 Allocates a partial symtab for it, and builds the list
1865 of dependent files by recursion. LEV says at which level
1866 of recursion we are called (to pretty up debug traces) */
1868 static struct partial_symtab
*
1869 parse_fdr(f_idx
, lev
, objfile
)
1872 struct objfile
*objfile
;
1875 register struct partial_symtab
*pst
;
1878 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + f_idx
;
1880 /* Use this to indicate into which symtab this file was parsed */
1882 return (struct partial_symtab
*) fh
->ioptBase
;
1884 /* Debuggability level */
1885 if (compare_glevel(max_glevel
, fh
->glevel
) < 0)
1886 max_glevel
= fh
->glevel
;
1888 /* Make a new partial_symtab */
1889 pst
= new_psymtab(fh
->rss
, objfile
);
1894 pst
->textlow
= fh
->adr
;
1895 pst
->texthigh
= fh
->cpd
; /* To be fixed later */
1898 /* Make everything point to everything. */
1899 FDR_IDX(pst
) = f_idx
;
1900 fdr_to_pst
[f_idx
].pst
= pst
;
1901 fh
->ioptBase
= (int)pst
;
1903 /* Analyze its dependencies */
1908 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
1909 /* ...then presumably a .h file: drop reverse depends .h->.c */
1910 for (; s_id0
< fh
->crfd
; s_id0
++) {
1911 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
1913 s_id0
++; /* Skip self-dependency */
1918 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
1919 pst
->dependencies
= (struct partial_symtab
**)
1920 obstack_alloc (psymbol_obstack
,
1921 pst
->number_of_dependencies
*
1922 sizeof (struct partial_symtab
*));
1923 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
1924 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
1926 pst
->dependencies
[s_idx
-s_id0
] = parse_fdr(*rh
, lev
+1, objfile
);
1932 #ifdef READ_MIPS_FORMAT
1939 return (char*)((SYMR
*)cur_fdr
->isymBase
)[s_idx
].iss
;
1943 /* Ancillary function to psymtab_to_symtab(). Does all the work
1944 for turning the partial symtab PST into a symtab, recurring
1945 first on all dependent psymtabs. The argument FILENAME is
1946 only passed so we can see in debug stack traces what file
1950 psymtab_to_symtab_1(pst
, filename
)
1951 struct partial_symtab
*pst
;
1959 struct linetable
*lines
;
1965 /* How many symbols will we need */
1966 /* FIXME, this does not count enum values. */
1967 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
1968 if (FDR_IDX(pst
) == -1) {
1972 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + FDR_IDX(pst
);
1973 f_max
+= fh
->csym
+ fh
->cpd
;
1974 maxlines
= 2 * fh
->cline
;
1979 && strcmp(((SYMR
*)fh
->isymBase
)[1].iss
, stabs_symbol
) == 0;
1983 st
= new_symtab (pst
->filename
, 2 * f_max
, maxlines
,
1986 st
= new_symtab ("unknown", f_max
, 0, pst
->objfile
);
1987 lines
= LINETABLE(st
);
1988 pending_list
= (struct mips_pending
**) cur_hdr
->cbOptOffset
;
1989 if (pending_list
== 0) {
1990 pending_list
= (struct mips_pending
**)
1991 xzalloc(cur_hdr
->ifdMax
* sizeof(struct mips_pending
*));
1992 cur_hdr
->cbOptOffset
= (int)pending_list
;
1996 /* Read in all partial symbtabs on which this one is dependent.
1997 NOTE that we do have circular dependencies, sigh. We solved
1998 that by setting pst->readin before this point. */
2000 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2001 if (!pst
->dependencies
[i
]->readin
) {
2002 /* Inform about additional files to be read in. */
2005 fputs_filtered (" ", stdout
);
2007 fputs_filtered ("and ", stdout
);
2009 printf_filtered ("%s...",
2010 pst
->dependencies
[i
]->filename
);
2011 wrap_here (""); /* Flush output */
2014 /* We only pass the filename for debug purposes */
2015 psymtab_to_symtab_1(pst
->dependencies
[i
],
2016 pst
->dependencies
[i
]->filename
);
2020 /* Now read the symbols for this symtab */
2023 cur_fd
= FDR_IDX(pst
);
2026 /* Get a new lexical context */
2029 top_stack
->cur_st
= cur_stab
;
2030 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab
),
2032 BLOCK_START(top_stack
->cur_block
) = fh
? fh
->adr
: 0;
2033 BLOCK_END(top_stack
->cur_block
) = 0;
2034 top_stack
->blocktype
= stFile
;
2035 top_stack
->maxsyms
= 2*f_max
;
2036 top_stack
->cur_type
= 0;
2037 top_stack
->procadr
= 0;
2038 top_stack
->numargs
= 0;
2041 /* Parse locals and procedures */
2046 char *fh_name
= (char*)fh
->rss
;
2048 /* Parse local symbols first */
2054 for (s_idx
= 2; s_idx
< fh
->csym
; s_idx
++) {
2055 register SYMR
*sh
= s_idx
+ (SYMR
*) fh
->isymBase
;
2056 char *name
= (char*)sh
->iss
;
2057 CORE_ADDR valu
= sh
->value
;
2058 if (MIPS_IS_STAB(sh
)) {
2059 int type_code
= MIPS_UNMARK_STAB(sh
->index
);
2061 if (type_code
== 0x84 && s_idx
== 2) continue;
2062 process_one_symbol (type_code
, 0, valu
, name
);
2064 else if (sh
->st
== stLabel
&& sh
->index
!= indexNil
) {
2065 /* Handle encoded stab line number. */
2066 record_line (current_subfile
, sh
->index
, valu
);
2069 st
= end_symtab (pst
->texthigh
, 0, 0, pst
->objfile
);
2072 /* BOUND is the highest core address of this file's procedures */
2073 int bound
= cur_fd
== cur_hdr
->ifdMax
- 1 ? cur_hdr
->cbDnOffset
2075 for (s_idx
= 0; s_idx
< fh
->csym
; ) {
2076 sh
= (SYMR
*) (fh
->isymBase
) + s_idx
;
2078 s_idx
+= parse_symbol(sh
, fh
->iauxBase
);
2081 /* Procedures next, note we need to look-ahead to
2082 find out where the procedure's code ends */
2084 for (s_idx
= 0; s_idx
< fh
->cpd
-1; s_idx
++) {
2085 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + s_idx
;
2086 parse_procedure(pr
, pr
[1].adr
); /* next proc up */
2089 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + s_idx
;
2090 parse_procedure(pr
, bound
); /* next file up */
2092 /* Linenumbers. At the end, check if we can save memory */
2093 parse_lines(fh
, lines
);
2094 if (lines
->nitems
< fh
->cline
)
2095 lines
= shrink_linetable(lines
);
2100 LINETABLE(st
) = lines
;
2102 /* .. and our share of externals.
2103 XXX use the global list to speed up things here. how ?
2104 FIXME, Maybe quit once we have found the right number of ext's? */
2105 /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
2106 top_stack
->blocktype
= stFile
;
2107 top_stack
->maxsyms
=
2108 cur_hdr
->isymMax
+ cur_hdr
->ipdMax
+ cur_hdr
->iextMax
;
2110 for (i
= 0; i
< cur_hdr
->iextMax
; i
++) {
2111 register EXTR
*esh
= (EXTR
*) (cur_hdr
->cbExtOffset
) + i
;
2112 if (esh
->ifd
== cur_fd
)
2113 parse_external(esh
, 1);
2116 /* If there are undefined, tell the user */
2117 if (n_undef_symbols
) {
2118 printf_filtered("File %s contains %d unresolved references:",
2119 st
->filename
, n_undef_symbols
);
2120 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2121 n_undef_vars
, n_undef_procs
, n_undef_labels
);
2122 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
2128 /* Sort the symbol table now, we are done adding symbols to it.*/
2129 sort_symtab_syms(st
);
2133 /* Now link the psymtab and the symtab. */
2137 /* Ancillary parsing procedures. */
2139 /* Lookup the type at relative index RN. Return it in TPP
2140 if found and in any event come up with its name PNAME.
2141 Return value says how many aux symbols we ate */
2144 cross_ref(rn
, tpp
, type_code
, pname
)
2147 int type_code
; /* Use to alloc new type if none is found. */
2152 /* Escape index means 'the next one' */
2153 if (rn
->rfd
== 0xfff)
2154 rf
= *(unsigned *) (rn
+ 1);
2160 *pname
= "<undefined>";
2163 * Find the relative file descriptor and the symbol in it
2165 FDR
*fh
= get_rfd(cur_fd
, rf
);
2170 * If we have processed this symbol then we left a forwarding
2171 * pointer to the corresponding GDB symbol. If not, we`ll put
2172 * it in a list of pending symbols, to be processed later when
2173 * the file f will be. In any event, we collect the name for
2174 * the type here. Which is why we made a first pass at
2177 sh
= (SYMR
*) (fh
->isymBase
) + rn
->index
;
2179 /* Careful, we might be looking at .o files */
2180 *pname
= (UNSAFE_DATA_ADDR(sh
->iss
)) ? "<undefined>" :
2183 /* Have we parsed it ? */
2184 if ((!UNSAFE_DATA_ADDR(sh
->value
)) && (sh
->st
== stParsed
)) {
2185 t
= (struct type
*) sh
->value
;
2188 /* Avoid duplicates */
2189 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
2193 *tpp
= make_type(type_code
, 0, 0, 0);
2194 add_pending(fh
, sh
, *tpp
);
2199 /* We used one auxent normally, two if we got a "next one" rf. */
2200 return (rn
->rfd
== 0xfff? 2: 1);
2204 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2205 keeping the symtab sorted */
2207 static struct symbol
*
2208 mylookup_symbol (name
, block
, namespace, class)
2210 register struct block
*block
;
2211 enum namespace namespace;
2212 enum address_class
class;
2214 register int bot
, top
, inc
;
2215 register struct symbol
*sym
;
2218 top
= BLOCK_NSYMS(block
);
2221 sym
= BLOCK_SYM(block
, bot
);
2222 if (SYMBOL_NAME(sym
)[0] == inc
2223 && SYMBOL_NAMESPACE(sym
) == namespace
2224 && SYMBOL_CLASS(sym
) == class
2225 && !strcmp(SYMBOL_NAME(sym
), name
))
2229 if (block
= BLOCK_SUPERBLOCK (block
))
2230 return mylookup_symbol (name
, block
, namespace, class);
2235 /* Add a new symbol S to a block B.
2236 Infrequently, we will need to reallocate the block to make it bigger.
2237 We only detect this case when adding to top_stack->cur_block, since
2238 that's the only time we know how big the block is. FIXME. */
2245 int nsyms
= BLOCK_NSYMS(b
)++;
2246 struct block
*origb
;
2247 struct parse_stack
*stackp
;
2249 if (b
== top_stack
->cur_block
&&
2250 nsyms
>= top_stack
->maxsyms
) {
2251 complain (&block_overflow_complaint
, s
->name
);
2252 /* In this case shrink_block is actually grow_block, since
2253 BLOCK_NSYMS(b) is larger than its current size. */
2255 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
2257 /* Now run through the stack replacing pointers to the
2258 original block. shrink_block has already done this
2259 for the blockvector and BLOCK_FUNCTION. */
2260 for (stackp
= top_stack
; stackp
; stackp
= stackp
->next
) {
2261 if (stackp
->cur_block
== origb
) {
2262 stackp
->cur_block
= b
;
2263 stackp
->maxsyms
= BLOCK_NSYMS (b
);
2267 BLOCK_SYM(b
,nsyms
) = s
;
2270 /* Add a new block B to a symtab S */
2277 struct blockvector
*bv
= BLOCKVECTOR(s
);
2279 bv
= (struct blockvector
*)xrealloc(bv
, sizeof(struct blockvector
) +
2280 BLOCKVECTOR_NBLOCKS(bv
) * sizeof(bv
->block
));
2281 if (bv
!= BLOCKVECTOR(s
))
2282 BLOCKVECTOR(s
) = bv
;
2284 BLOCKVECTOR_BLOCK(bv
, BLOCKVECTOR_NBLOCKS(bv
)++) = b
;
2287 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2288 MIPS' linenumber encoding might need more than one byte
2289 to describe it, LAST is used to detect these continuation lines */
2292 add_line(lt
, lineno
, adr
, last
)
2293 struct linetable
*lt
;
2299 last
= -2; /* make sure we record first line */
2301 if (last
== lineno
) /* skip continuation lines */
2304 lt
->item
[lt
->nitems
].line
= lineno
;
2305 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
2311 /* Comparison functions, used when sorting things */
2313 /* Symtabs must be ordered viz the code segments they cover */
2316 compare_symtabs( s1
, s2
)
2317 struct symtab
**s1
, **s2
;
2319 /* "most specific" first */
2321 register struct block
*b1
, *b2
;
2322 b1
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1
),GLOBAL_BLOCK
);
2323 b2
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2
),GLOBAL_BLOCK
);
2324 if (BLOCK_END(b1
) == BLOCK_END(b2
))
2325 return BLOCK_START(b1
) - BLOCK_START(b2
);
2326 return BLOCK_END(b1
) - BLOCK_END(b2
);
2330 /* Partial Symtabs, same */
2333 compare_psymtabs( s1
, s2
)
2334 struct partial_symtab
**s1
, **s2
;
2336 /* Perf twist: put the ones with no code at the end */
2338 register int a
= (*s1
)->textlow
;
2339 register int b
= (*s2
)->textlow
;
2348 /* Blocks with a smaller low bound should come first */
2350 static int compare_blocks(b1
,b2
)
2351 struct block
**b1
, **b2
;
2353 register int addr_diff
;
2355 addr_diff
= (BLOCK_START((*b1
))) - (BLOCK_START((*b2
)));
2357 return (BLOCK_END((*b1
))) - (BLOCK_END((*b2
)));
2362 /* Sorting and reordering procedures */
2364 /* Sort the blocks of a symtab S.
2365 Reorder the blocks in the blockvector by code-address,
2366 as required by some MI search routines */
2372 struct blockvector
*bv
= BLOCKVECTOR(s
);
2374 if (BLOCKVECTOR_NBLOCKS(bv
) <= 2) {
2376 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) == 0)
2377 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = 0;
2378 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) == 0)
2379 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) = 0;
2383 * This is very unfortunate: normally all functions are compiled in
2384 * the order they are found, but if the file is compiled -O3 things
2385 * are very different. It would be nice to find a reliable test
2386 * to detect -O3 images in advance.
2388 if (BLOCKVECTOR_NBLOCKS(bv
) > 3)
2389 qsort(&BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
),
2390 BLOCKVECTOR_NBLOCKS(bv
) - FIRST_LOCAL_BLOCK
,
2391 sizeof(struct block
*),
2395 register CORE_ADDR high
= 0;
2396 register int i
, j
= BLOCKVECTOR_NBLOCKS(bv
);
2398 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
2399 if (high
< BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
)))
2400 high
= BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
));
2401 BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = high
;
2404 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) =
2405 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
));
2407 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2408 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2409 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2410 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2414 /* Constructor/restructor/destructor procedures */
2416 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2417 MAXSYMS and linenumbers MAXLINES we'll put in it */
2421 new_symtab(name
, maxsyms
, maxlines
, objfile
)
2424 struct symtab
*s
= allocate_symtab (name
, objfile
);
2426 LINETABLE(s
) = new_linetable(maxlines
);
2428 /* All symtabs must have at least two blocks */
2429 BLOCKVECTOR(s
) = new_bvect(2);
2430 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
) = new_block(maxsyms
);
2431 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), STATIC_BLOCK
) = new_block(maxsyms
);
2432 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
),STATIC_BLOCK
)) =
2433 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
);
2435 s
->free_code
= free_linetable
;
2437 /* Link the new symtab into the list of such. */
2438 s
->next
= symtab_list
;
2444 /* Allocate a new partial_symtab NAME */
2446 static struct partial_symtab
*
2447 new_psymtab(name
, objfile
)
2449 struct objfile
*objfile
;
2451 struct partial_symtab
*pst
;
2453 pst
= (struct partial_symtab
*)
2454 obstack_alloc (psymbol_obstack
, sizeof (*pst
));
2455 memset (pst
, 0, sizeof (*pst
));
2457 if (name
== (char*)-1) /* FIXME -- why not null here? */
2458 pst
->filename
= "<no name>";
2460 pst
->filename
= name
;
2462 /* Chain it to its object file */
2463 pst
->objfile
= objfile
;
2464 pst
->objfile_chain
= objfile
->psymtabs
;
2465 objfile
->psymtabs
= pst
;
2467 pst
->next
= partial_symtab_list
;
2468 partial_symtab_list
= pst
;
2470 /* Keep a backpointer to the file's symbols */
2471 pst
->read_symtab_private
= (char *) obstack_alloc (psymbol_obstack
,
2472 sizeof (struct symloc
));
2473 CUR_HDR(pst
) = cur_hdr
;
2475 /* The way to turn this into a symtab is to call... */
2476 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
2482 /* Allocate a linetable array of the given SIZE */
2484 static struct linetable
*
2487 struct linetable
*l
;
2489 size
= size
* sizeof(l
->item
) + sizeof(struct linetable
);
2490 l
= (struct linetable
*)xmalloc(size
);
2495 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2496 I am not so sure about the 3.4 ones */
2498 static struct linetable
*
2499 shrink_linetable(lt
)
2500 struct linetable
* lt
;
2502 struct linetable
*l
= new_linetable(lt
->nitems
);
2504 memcpy(l
, lt
, lt
->nitems
* sizeof(l
->item
) + sizeof(struct linetable
));
2509 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2512 struct blockvector
*
2515 struct blockvector
*bv
;
2518 size
= sizeof(struct blockvector
) + nblocks
* sizeof(struct block
*);
2519 bv
= (struct blockvector
*) xzalloc(size
);
2521 BLOCKVECTOR_NBLOCKS(bv
) = nblocks
;
2526 /* Allocate and zero a new block of MAXSYMS symbols */
2532 int size
= sizeof(struct block
) + (maxsyms
-1) * sizeof(struct symbol
*);
2533 struct block
*b
= (struct block
*)xzalloc(size
);
2538 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2539 Shrink_block can also be used by add_symbol to grow a block. */
2541 static struct block
*
2547 struct blockvector
*bv
= BLOCKVECTOR(s
);
2550 /* Just reallocate it and fix references to the old one */
2552 new = (struct block
*) xrealloc ((char *)b
, sizeof(struct block
) +
2553 (BLOCK_NSYMS(b
)-1) * sizeof(struct symbol
*));
2555 /* Should chase pointers to old one. Fortunately, that`s just
2556 the block`s function and inferior blocks */
2557 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b
)
2558 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2559 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2560 if (BLOCKVECTOR_BLOCK(bv
,i
) == b
)
2561 BLOCKVECTOR_BLOCK(bv
,i
) = new;
2562 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) == b
)
2563 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) = new;
2567 /* Create a new symbol with printname NAME */
2574 struct symbol
*s
= (struct symbol
*)
2575 obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
2577 memset (s
, 0, sizeof (*s
));
2578 SYMBOL_NAME(s
) = name
;
2582 /* Create a new type with printname NAME */
2589 struct type
*t
= (struct type
*)
2590 obstack_alloc (symbol_obstack
, sizeof (struct type
));
2592 memset (t
, 0, sizeof (*t
));
2593 TYPE_VPTR_FIELDNO (t
) = -1;
2594 TYPE_NAME(t
) = name
;
2595 TYPE_CPLUS_SPECIFIC(t
) = &cplus_struct_default
;
2599 /* Create and initialize a new type with printname NAME.
2600 CODE and LENGTH are the initial info we put in,
2601 UNS says whether the type is unsigned or not. */
2605 make_type(code
, length
, uns
, name
)
2606 enum type_code code
;
2610 register struct type
*type
;
2612 /* FIXME, I don't think this ever gets freed. */
2613 type
= (struct type
*) xzalloc(sizeof(struct type
));
2614 TYPE_CODE(type
) = code
;
2615 TYPE_LENGTH(type
) = length
;
2616 TYPE_FLAGS(type
) = uns
? TYPE_FLAG_UNSIGNED
: 0;
2617 TYPE_NAME(type
) = name
;
2618 TYPE_VPTR_FIELDNO (type
) = -1;
2620 if (code
!= TYPE_CODE_METHOD
&& code
!= TYPE_CODE_FUNC
)
2621 TYPE_CPLUS_SPECIFIC(type
) = &cplus_struct_default
;
2625 /* Things used for calling functions in the inferior.
2626 These functions are exported to our companion
2627 mips-tdep.c file and are here because they play
2628 with the symbol-table explicitly. */
2630 /* Sigtramp: make sure we have all the necessary information
2631 about the signal trampoline code. Since the official code
2632 from MIPS does not do so, we make up that information ourselves.
2633 If they fix the library (unlikely) this code will neutralize itself. */
2640 struct block
*b
, *b0
;
2642 sigtramp_address
= -1;
2644 /* We know it is sold as sigvec */
2645 s
= lookup_symbol("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
2647 /* Most programs do not play with signals */
2651 b0
= SYMBOL_BLOCK_VALUE(s
);
2653 /* A label of sigvec, to be more precise */
2654 s
= lookup_symbol("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
2656 /* But maybe this program uses its own version of sigvec */
2660 sigtramp_address
= SYMBOL_VALUE(s
);
2661 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
2663 /* Did we or MIPSco fix the library ? */
2664 if (SYMBOL_CLASS(s
) == LOC_BLOCK
)
2667 /* But what symtab does it live in ? */
2668 st
= find_pc_symtab(SYMBOL_VALUE(s
));
2671 * Ok, there goes the fix: turn it into a procedure, with all the
2672 * needed info. Note we make it a nested procedure of sigvec,
2673 * which is the way the (assembly) code is actually written.
2675 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2676 SYMBOL_CLASS(s
) = LOC_BLOCK
;
2677 SYMBOL_TYPE(s
) = make_type(TYPE_CODE_FUNC
, 4, 0, 0);
2678 TYPE_TARGET_TYPE(SYMBOL_TYPE(s
)) = builtin_type_void
;
2680 /* Need a block to allocate .gdbinfo. in */
2682 SYMBOL_BLOCK_VALUE(s
) = b
;
2683 BLOCK_START(b
) = sigtramp_address
;
2684 BLOCK_END(b
) = sigtramp_end
;
2685 BLOCK_FUNCTION(b
) = s
;
2686 BLOCK_SUPERBLOCK(b
) = BLOCK_SUPERBLOCK(b0
);
2690 /* Make a .gdbinfo. for it */
2692 struct mips_extra_func_info
*e
=
2693 (struct mips_extra_func_info
*)
2694 xzalloc(sizeof(struct mips_extra_func_info
));
2696 e
->numargs
= 0; /* the kernel thinks otherwise */
2697 /* align_longword(sigcontext + SIGFRAME) */
2698 e
->framesize
= 0x150;
2699 e
->framereg
= SP_REGNUM
;
2702 e
->regoffset
= -(41 * sizeof(int));
2704 e
->fregoffset
= -(37 * sizeof(int));
2707 s
= new_symbol(".gdbinfo.");
2708 SYMBOL_VALUE(s
) = (int) e
;
2709 SYMBOL_NAMESPACE(s
) = LABEL_NAMESPACE
;
2710 SYMBOL_CLASS(s
) = LOC_CONST
;
2711 SYMBOL_TYPE(s
) = builtin_type_void
;
2714 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
2717 /* Initialization */
2719 static struct sym_fns ecoff_sym_fns
= {"ecoff", 5,
2720 mipscoff_new_init
, mipscoff_symfile_init
,
2721 mipscoff_symfile_read
};
2723 _initialize_mipsread ()
2725 add_symtab_fns (&ecoff_sym_fns
);
2727 /* Missing basic types */
2728 builtin_type_string
= make_type(TYPE_CODE_PASCAL_ARRAY
,
2730 builtin_type_complex
= make_type(TYPE_CODE_FLT
,
2731 2 * sizeof(float), 0, "complex");
2732 builtin_type_double_complex
= make_type(TYPE_CODE_FLT
,
2733 2 * sizeof(double), 0, "double_complex");
2734 builtin_type_fixed_dec
= make_type(TYPE_CODE_INT
, sizeof(int),
2735 0, "fixed_decimal");
2736 builtin_type_float_dec
= make_type(TYPE_CODE_FLT
, sizeof(double),
2737 0, "floating_decimal");