1 /* Read a symbol table in MIPS' format (Third-Eye).
2 Copyright (C) 1986, 1987, 1989-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. */
39 #include <sys/param.h>
47 #include <mips/syms.h>
51 #endif /* not CMUCS */
56 struct external_filehdr f
;
57 struct external_aouthdr a
;
60 /* Each partial symbol table entry contains a pointer to private data for the
61 read_symtab() function to use when expanding a partial symbol table entry
62 to a full symbol table entry.
64 For mipsread this structure contains the index of the FDR that this psymtab
65 represents and a pointer to the symbol table header HDRR from the symbol
66 file that the psymtab was created from.
68 Note: This code is currently untested. -fnf */
70 #define FDR_IDX(p) (((struct symloc *)((p)->read_symtab_private))->fdr_idx)
71 #define CUR_HDR(p) (((struct symloc *)((p)->read_symtab_private))->cur_hdr)
78 /* Things we import explicitly from other modules */
80 extern int info_verbose
;
81 extern struct block
*block_for_pc();
82 extern void sort_symtab_syms();
84 /* Various complaints about symbol reading that don't abort the process */
86 struct complaint unknown_ext_complaint
=
87 {"unknown external symbol %s", 0, 0};
89 struct complaint unknown_sym_complaint
=
90 {"unknown local symbol %s", 0, 0};
92 struct complaint unknown_st_complaint
=
93 {"with type %d", 0, 0};
95 struct complaint block_overflow_complaint
=
96 {"block containing %s overfilled", 0, 0};
98 struct complaint basic_type_complaint
=
99 {"cannot map MIPS basic type 0x%x", 0, 0};
101 struct complaint unknown_type_qual_complaint
=
102 {"unknown type qualifier 0x%x", 0, 0};
104 struct complaint array_bitsize_complaint
=
105 {"size of array target type not known, assuming %d bits", 0, 0};
107 struct complaint array_parse_complaint
=
108 {"array type with strange relative symbol", 0, 0};
110 /* Macros and extra defs */
112 /* Already-parsed symbols are marked specially */
114 #define stParsed stType
116 /* Puns: hard to find whether -g was used and how */
118 #define MIN_GLEVEL GLEVEL_0
119 #define compare_glevel(a,b) \
120 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
121 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
123 /* When looking at .o files, avoid tripping over bad addresses */
125 #define SAFE_TEXT_ADDR 0x400000
126 #define SAFE_DATA_ADDR 0x10000000
128 #define UNSAFE_DATA_ADDR(p) ((unsigned)p < SAFE_DATA_ADDR || (unsigned)p > 2*SAFE_DATA_ADDR)
130 /* Things that really are local to this module */
132 /* GDB symtable for the current compilation unit */
134 static struct symtab
*cur_stab
;
136 /* MIPS symtab header for the current file */
138 static HDRR
*cur_hdr
;
140 /* Pointer to current file decriptor record, and its index */
145 /* Index of current symbol */
149 /* Note how much "debuggable" this image is. We would like
150 to see at least one FDR with full symbols */
155 /* When examining .o files, report on undefined symbols */
157 static int n_undef_symbols
, n_undef_labels
, n_undef_vars
, n_undef_procs
;
159 /* Extra builtin types */
161 struct type
*builtin_type_complex
;
162 struct type
*builtin_type_double_complex
;
163 struct type
*builtin_type_fixed_dec
;
164 struct type
*builtin_type_float_dec
;
165 struct type
*builtin_type_string
;
169 static struct type
*builtin_type_ptr
;
170 static struct type
*builtin_type_struct
;
171 static struct type
*builtin_type_union
;
172 static struct type
*builtin_type_enum
;
173 static struct type
*builtin_type_range
;
174 static struct type
*builtin_type_set
;
176 /* Forward declarations */
178 static struct symbol
*new_symbol();
179 static struct type
*new_type();
180 static struct field
*new_field();
181 static struct block
*new_block();
182 static struct symtab
*new_symtab();
183 static struct linetable
*new_linetable();
184 static struct blockvector
*new_bvect();
186 static struct type
*parse_type();
187 static struct type
*make_type();
188 static struct symbol
*mylookup_symbol();
189 static struct block
*shrink_block();
191 static int compare_symtabs();
192 static int compare_psymtabs();
193 static int compare_blocks();
195 static struct partial_symtab
*new_psymtab();
196 static struct partial_symtab
*parse_fdr();
197 static int compare_psymbols();
199 static void psymtab_to_symtab_1();
200 static void add_block();
201 static void add_symbol();
202 static int add_line();
203 static void reorder_symtabs();
204 static void reorder_psymtabs();
205 static void shrink_linetable();
207 /* Things we export to other modules */
209 /* Address bounds for the signal trampoline in inferior, if any */
210 /* FIXME: Nothing really seems to use this. Why is it here? */
212 CORE_ADDR sigtramp_address
, sigtramp_end
;
214 /* The entry point (starting address) of the file, if it is an executable. */
216 static CORE_ADDR entry_point
;
218 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
219 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
224 /* If we have a file symbol header lying around, blow it away. */
226 free ((char *)cur_hdr
);
231 mipscoff_symfile_init (sf
)
234 bfd
*abfd
= sf
->sym_bfd
;
235 sf
->sym_private
= NULL
;
237 /* Save startup file's range of PC addresses to help blockframe.c
238 decide where the bottom of the stack is. */
239 if (bfd_get_file_flags (abfd
) & EXEC_P
)
241 /* Executable file -- record its entry point so we'll recognize
242 the startup file because it contains the entry point. */
243 entry_point
= bfd_get_start_address (abfd
);
247 /* Examination of non-executable.o files. Short-circuit this stuff. */
248 /* ~0 will not be in any file, we hope. */
250 /* set the startup file to be an empty range. */
251 startup_file_start
= 0;
252 startup_file_end
= 0;
257 mipscoff_symfile_read(sf
, addr
, mainline
)
262 struct coff_symfile_info
*info
= (struct coff_symfile_info
*)sf
->sym_private
;
263 bfd
*abfd
= sf
->sym_bfd
;
264 char *name
= bfd_get_filename (abfd
);
268 int stringtab_offset
;
270 /* Initialize a variable that we couldn't do at _initialize_ time. */
271 builtin_type_ptr
= lookup_pointer_type (builtin_type_void
);
273 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
274 desc
= fileno ((FILE *)(abfd
->iostream
)); /* Raw file descriptor */
277 /* Position to read the symbol table. */
278 val
= lseek (desc
, (long)symtab_offset
, 0);
280 perror_with_name (name
);
282 init_misc_bunches ();
283 make_cleanup (discard_misc_bunches
, 0);
285 /* Now that the executable file is positioned at symbol table,
286 process it and define symbols accordingly. */
288 read_mips_symtab(abfd
, desc
);
290 /* Go over the misc symbol bunches and install them in vector. */
292 condense_misc_bunches (!mainline
);
295 /* Exported procedure: Allocate zeroed memory */
300 char *p
= xmalloc(size
);
306 /* Exported procedure: Builds a symtab from the PST partial one.
307 Restores the environment in effect when PST was created, delegates
308 most of the work to an ancillary procedure, and sorts
309 and reorders the symtab list at the end */
312 mipscoff_psymtab_to_symtab(pst
)
313 struct partial_symtab
*pst
;
322 printf_filtered("Reading in symbols for %s...", pst
->filename
);
325 /* Restore the header and list of pending typedefs */
326 cur_hdr
= CUR_HDR(pst
);
328 psymtab_to_symtab_1(pst
, pst
->filename
);
333 printf_filtered("done.\n");
336 /* Exported procedure: Is PC in the signal trampoline code */
339 in_sigtramp(pc
, name
)
343 if (sigtramp_address
== 0)
345 return (pc
>= sigtramp_address
&& pc
< sigtramp_end
);
348 /* File-level interface functions */
350 /* Read the symtab information from file FSYM into memory. Also,
351 return address just past end of our text segment in *END_OF_TEXT_SEGP. */
354 read_the_mips_symtab(abfd
, fsym
, end_of_text_segp
)
357 CORE_ADDR
*end_of_text_segp
;
359 int stsize
, st_hdrsize
;
362 /* Header for executable/object file we read symbols from */
363 struct coff_exec filhdr
;
365 /* We get here with DESC pointing to the symtab header. But we need
366 * other info from the initial headers */
368 myread(fsym
, &filhdr
, sizeof filhdr
);
370 if (end_of_text_segp
)
372 bfd_h_get_32 (abfd
, filhdr
.a
.text_start
) +
373 bfd_h_get_32 (abfd
, filhdr
.a
.tsize
);
375 /* Find and read the symbol table header */
376 st_hdrsize
= bfd_h_get_32 (abfd
, filhdr
.f
.f_nsyms
);
377 st_filptr
= bfd_h_get_32 (abfd
, filhdr
.f
.f_symptr
);
381 lseek(fsym
, st_filptr
, L_SET
);
382 if (st_hdrsize
> sizeof (st_hdr
)) /* Profanity check */
384 if (read(fsym
, &st_hdr
, st_hdrsize
) != st_hdrsize
)
387 /* Find out how large the symbol table is */
388 stsize
= (st_hdr
.cbExtOffset
- (st_filptr
+ st_hdrsize
))
389 + st_hdr
.iextMax
* cbEXTR
;
391 /* Allocate space for the symbol table. Read it in. */
392 cur_hdr
= (HDRR
*) xmalloc(stsize
+ st_hdrsize
);
394 bcopy(&st_hdr
, cur_hdr
, st_hdrsize
);
395 if (read(fsym
, (char *) cur_hdr
+ st_hdrsize
, stsize
) != stsize
)
398 /* Fixup file_pointers in it */
399 fixup_symtab(cur_hdr
, (char *) cur_hdr
+ st_hdrsize
,
400 st_filptr
+ st_hdrsize
);
404 error("Short read on %s", symfile
);
408 /* Turn all file-relative pointers in the symtab described by HDR
409 into memory pointers, given that the symtab itself is located
410 at DATA in memory and F_PTR in the file. */
413 fixup_symtab( hdr
, data
, f_ptr
)
425 * These fields are useless (and empty) by now:
426 * hdr->cbDnOffset, hdr->cbOptOffset
427 * We use them for other internal purposes.
430 hdr
->cbOptOffset
= 0;
433 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
449 * Fix all string pointers inside the symtab, and
450 * the FDR records. Also fix other miscellany.
452 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
453 register unsigned code_offset
;
455 /* Header itself, and strings */
456 fh
= (FDR
*) (hdr
->cbFdOffset
) + f_idx
;
457 fh
->issBase
+= hdr
->cbSsOffset
;
459 fh
->rss
= (long)fh
->rss
+ fh
->issBase
;
460 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
461 sh
= (SYMR
*)(hdr
->cbSymOffset
) + fh
->isymBase
+ s_idx
;
462 sh
->iss
= (long) sh
->iss
+ fh
->issBase
;
469 fh
->isymBase
= (int)((SYMR
*)(hdr
->cbSymOffset
)+fh
->isymBase
);
471 /* cannot fix fh->ipdFirst because it is a short */
472 #define IPDFIRST(h,fh) \
473 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
475 /* Optional symbols (actually used for partial_symtabs) */
481 fh
->iauxBase
= hdr
->cbAuxOffset
+ fh
->iauxBase
* sizeof(AUXU
);
482 /* Relative file descriptor table */
483 fh
->rfdBase
= hdr
->cbRfdOffset
+ fh
->rfdBase
* sizeof(RFDT
);
487 fh
->cbLineOffset
+= hdr
->cbLineOffset
;
489 /* Procedure symbols. (XXX This should be done later) */
490 code_offset
= fh
->adr
;
491 for (s_idx
= 0; s_idx
< fh
->cpd
; s_idx
++) {
492 unsigned name
, only_ext
;
494 pr
= (PDR
*)(IPDFIRST(hdr
,fh
)) + s_idx
;
496 /* Simple rule to find files linked "-x" */
497 only_ext
= fh
->rss
== -1;
499 if (pr
->isym
== -1) {
500 /* static function */
504 name
= hdr
->cbExtOffset
+ pr
->isym
* sizeof(EXTR
);
505 sh
= &((EXTR
*)name
)->asym
;
509 sh
= (SYMR
*)fh
->isymBase
+ pr
->isym
;
510 /* Included code ? */
511 if (s_idx
== 0 && pr
->adr
!= 0)
512 code_offset
-= pr
->adr
;
515 /* Turn index into a pointer */
518 /* Fix line numbers */
519 pr
->cbLineOffset
+= fh
->cbLineOffset
;
521 /* Relocate address */
523 pr
->adr
+= code_offset
;
527 /* External symbols: fix string */
528 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
529 esh
= (EXTR
*)(hdr
->cbExtOffset
) + s_idx
;
530 esh
->asym
.iss
= esh
->asym
.iss
+ hdr
->cbSsExtOffset
;
535 /* Find a file descriptor given its index RF relative to a file CF */
543 f
= (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
544 /* Object files do not have the RFD table, all refs are absolute */
546 return (FDR
*) (cur_hdr
->cbFdOffset
) + rf
;
547 cf
= *((pRFDT
) f
->rfdBase
+ rf
);
548 return (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
551 /* Return a safer print NAME for a file descriptor */
557 if (name
== (char *) -1)
558 return "<stripped file>";
559 if (UNSAFE_DATA_ADDR(name
))
565 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
566 whether we are adding to the general symtab or not.
567 FIXME: INCREMENTAL is currently always zero, though it should not be. */
570 read_mips_symtab (abfd
, desc
)
574 CORE_ADDR end_of_text_seg
;
576 read_the_mips_symtab(abfd
, desc
, &end_of_text_seg
);
578 parse_partial_symbols(end_of_text_seg
);
581 * Check to make sure file was compiled with -g.
582 * If not, warn the user of this limitation.
584 if (compare_glevel(max_glevel
, GLEVEL_2
) < 0) {
585 if (max_gdbinfo
== 0)
586 printf("\n%s not compiled with -g, debugging support is limited.", symfile
);
587 printf("\nYou should compile with -g2 or -g3 for best debugging support.\n");
592 /* Local utilities */
594 /* Map of FDR indexes to partial symtabs */
596 static struct pst_map
{
597 struct partial_symtab
*pst
; /* the psymtab proper */
598 int n_globals
; /* globals it exports */
599 int n_statics
; /* statics (locals) it contains */
603 /* Utility stack, used to nest procedures and blocks properly.
604 It is a doubly linked list, to avoid too many alloc/free.
605 Since we might need it quite a few times it is NOT deallocated
608 static struct parse_stack
{
609 struct parse_stack
*next
, *prev
;
610 struct symtab
*cur_st
; /* Current symtab */
611 struct block
*cur_block
; /* Block in it */
612 int blocktype
; /* What are we parsing */
613 int maxsyms
; /* Max symbols in this block */
614 struct type
*cur_type
; /* Type we parse fields for */
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 pending
{
660 struct 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 pending
*is_pending_symbol(fh
, sh
)
673 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
674 register struct 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 pending
*is_pending_type(fh
, t
)
690 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
691 register struct 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 pending
*p
= is_pending_symbol(fh
, sh
);
710 /* Make sure we do not make duplicates */
712 p
= (struct 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 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 */
801 /* When a symbol is cross-referenced from other files/symbols
802 we mark it explicitly */
803 int pend
= (sh
->reserved
== 1);
804 enum address_class
class;
811 case stGlobal
: /* external symbol, goes into global block */
813 b
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
815 s
= new_symbol(sh
->iss
);
816 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
819 case stStatic
: /* static data, goes into current block. */
821 b
= top_stack
->cur_block
;
822 s
= new_symbol(sh
->iss
);
823 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
826 case stLocal
: /* local variable, goes into current block */
827 if (sh
->sc
== scRegister
) {
828 class = LOC_REGISTER
;
833 b
= top_stack
->cur_block
;
834 s
= new_symbol(sh
->iss
);
835 SYMBOL_VALUE(s
) = sh
->value
;
837 data
: /* Common code for symbols describing data */
838 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
839 SYMBOL_CLASS(s
) = class;
842 /* Type could be missing in a number of cases */
843 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
844 sh
->index
== 0xfffff)
845 SYMBOL_TYPE(s
) = builtin_type_int
; /* undefined? */
847 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
848 /* Value of a data symbol is its memory address */
851 case stParam
: /* arg to procedure, goes into current block */
853 top_stack
->numargs
++;
854 s
= new_symbol(sh
->iss
);
855 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
856 if (sh
->sc
== scRegister
) {
857 SYMBOL_CLASS(s
) = LOC_REGPARM
;
861 SYMBOL_CLASS(s
) = LOC_ARG
;
862 SYMBOL_VALUE(s
) = sh
->value
;
863 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
864 add_symbol(s
, top_stack
->cur_block
);
866 /* FIXME: This has not been tested. See dbxread.c */
867 /* Add the type of this parameter to the function/procedure
868 type of this block. */
869 add_param_to_type(&top_stack
->cur_block
->function
->type
,s
);
873 case stLabel
: /* label, goes into current block */
874 s
= new_symbol(sh
->iss
);
875 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
; /* so that it can be used */
876 SYMBOL_CLASS(s
) = LOC_LABEL
; /* but not misused */
877 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
878 SYMBOL_TYPE(s
) = builtin_type_int
;
879 add_symbol(s
, top_stack
->cur_block
);
882 case stProc
: /* Procedure, usually goes into global block */
883 case stStaticProc
: /* Static procedure, goes into current block */
884 s
= new_symbol(sh
->iss
);
885 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
886 SYMBOL_CLASS(s
) = LOC_BLOCK
;
887 /* Type of the return value */
888 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
889 t
= builtin_type_int
;
891 t
= parse_type(ax
+ sh
->index
, sh
, 0);
892 b
= top_stack
->cur_block
;
893 if (sh
->st
== stProc
) {
894 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
895 /* The next test should normally be true,
896 but provides a hook for nested functions
897 (which we don't want to make global). */
898 if (b
== BLOCKVECTOR_BLOCK(bv
, STATIC_BLOCK
))
899 b
= BLOCKVECTOR_BLOCK(bv
, GLOBAL_BLOCK
);
903 /* Make a type for the procedure itself */
905 /* FIXME: This has not been tested yet! See dbxread.c */
906 /* Generate a template for the type of this function. The
907 types of the arguments will be added as we read the symbol
909 bcopy(SYMBOL_TYPE(s
),lookup_function_type(t
),sizeof(struct type
));
911 SYMBOL_TYPE(s
) = lookup_function_type (t
);
914 /* Create and enter a new lexical context */
915 b
= new_block(top_stack
->maxsyms
);
916 SYMBOL_BLOCK_VALUE(s
) = b
;
917 BLOCK_FUNCTION(b
) = s
;
918 BLOCK_START(b
) = BLOCK_END(b
) = sh
->value
;
919 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
920 add_block(b
, top_stack
->cur_st
);
922 /* Not if we only have partial info */
923 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
927 top_stack
->cur_block
= b
;
928 top_stack
->blocktype
= sh
->st
;
929 top_stack
->cur_type
= SYMBOL_TYPE(s
);
930 top_stack
->procadr
= sh
->value
;
931 top_stack
->numargs
= 0;
933 sh
->value
= (long) SYMBOL_TYPE(s
);
936 case stBlock
: /* Either a lexical block, or some type */
938 top_stack
->blocktype
= stBlock
;
939 if (sh
->sc
== scInfo
) { /* structure/union/enum def */
940 s
= new_symbol(sh
->iss
);
941 SYMBOL_NAMESPACE(s
) = STRUCT_NAMESPACE
;
942 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
944 add_symbol(s
, top_stack
->cur_block
);
945 /* If this type was expected, use its partial definition */
947 t
= is_pending_symbol(cur_fdr
, sh
)->t
;
949 /* Uhmm, can`t decide yet. Smash later */
950 t
= new_type(sh
->iss
);
951 TYPE_CODE(t
) = TYPE_CODE_UNDEF
;
952 add_pending(cur_fdr
, sh
, t
);
955 /* make this the current type */
956 top_stack
->cur_type
= t
;
957 TYPE_LENGTH(t
) = sh
->value
;
958 /* Mark that symbol has a type, and say which one */
959 sh
->value
= (long) t
;
961 /* beginnning of (code) block. Value of symbol
962 is the displacement from procedure start */
963 b
= new_block(top_stack
->maxsyms
);
964 BLOCK_START(b
) = sh
->value
+ top_stack
->procadr
;
965 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
966 top_stack
->cur_block
= b
;
967 add_block(b
, top_stack
->cur_st
);
971 case stEnd
: /* end (of anything) */
972 if (sh
->sc
== scInfo
) {
973 /* Finished with type */
974 top_stack
->cur_type
= 0;
975 } else if (sh
->sc
== scText
&&
976 (top_stack
->blocktype
== stProc
||
977 top_stack
->blocktype
== stStaticProc
)) {
978 /* Finished with procedure */
979 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
983 BLOCK_END(top_stack
->cur_block
) += sh
->value
; /* size */
984 got_numargs(top_stack
->procadr
, top_stack
->numargs
);
985 /* Reallocate symbols, saving memory */
986 b
= shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
988 /* f77 emits proc-level with address bounds==[0,0],
989 So look for such child blocks, and patch them. */
990 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++) {
991 struct block
*b_bad
= BLOCKVECTOR_BLOCK(bv
,i
);
992 if (BLOCK_SUPERBLOCK(b_bad
) == b
993 && BLOCK_START(b_bad
) == top_stack
->procadr
994 && BLOCK_END(b_bad
) == top_stack
->procadr
) {
995 BLOCK_START(b_bad
) = BLOCK_START(b
);
996 BLOCK_END(b_bad
) = BLOCK_END(b
);
999 if (entry_point
< BLOCK_END(b
)
1000 && entry_point
>= BLOCK_START(b
)) {
1001 startup_file_start
= BLOCK_START(b
);
1002 startup_file_end
= BLOCK_END(b
);
1004 } else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
) {
1005 /* End of (code) block. The value of the symbol
1006 is the displacement from the procedure`s start
1007 address of the end of this block. */
1008 BLOCK_END(top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1009 (void) shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1011 pop_parse_stack(); /* restore previous lexical context */
1014 case stMember
: /* member of struct/union/enum.. */
1015 f
= new_field(top_stack
->cur_type
, sh
->iss
);
1016 f
->bitpos
= sh
->value
;
1017 f
->type
= parse_type(ax
+ sh
->index
, sh
, &f
->bitsize
);
1020 case stTypedef
: /* type definition */
1021 s
= new_symbol(sh
->iss
);
1022 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1023 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1024 SYMBOL_BLOCK_VALUE(s
) = top_stack
->cur_block
;
1025 add_symbol(s
, top_stack
->cur_block
);
1026 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
1027 sh
->value
= (long) SYMBOL_TYPE(s
);
1030 case stFile
: /* file name */
1032 top_stack
->blocktype
= sh
->st
;
1035 /* I`ve never seen these for C */
1037 break; /* register relocation */
1039 break; /* forwarding address */
1041 break; /* constant */
1043 error("Unknown symbol type %x.", sh
->st
);
1048 /* Parse the type information provided in the AX entries for
1049 the symbol SH. Return the bitfield size in BS, in case. */
1051 static struct type
*parse_type(ax
, sh
, bs
)
1056 /* Null entries in this map are treated specially */
1057 static struct type
**map_bt
[] =
1059 &builtin_type_void
, /* btNil */
1061 &builtin_type_char
, /* btChar */
1062 &builtin_type_unsigned_char
, /* btUChar */
1063 &builtin_type_short
, /* btShort */
1064 &builtin_type_unsigned_short
, /* btUShort */
1065 &builtin_type_int
, /* btInt */
1066 &builtin_type_unsigned_int
, /* btUInt */
1067 &builtin_type_long
, /* btLong */
1068 &builtin_type_unsigned_long
, /* btULong */
1069 &builtin_type_float
, /* btFloat */
1070 &builtin_type_double
, /* btDouble */
1077 &builtin_type_complex
, /* btComplex */
1078 &builtin_type_double_complex
, /* btDComplex */
1080 &builtin_type_fixed_dec
, /* btFixedDec */
1081 &builtin_type_float_dec
, /* btFloatDec */
1082 &builtin_type_string
, /* btString */
1085 &builtin_type_void
, /* btVoid */
1089 struct type
*tp
= 0, *tp1
;
1092 /* Procedures start off by one */
1093 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
)
1096 /* Undefined ? Should not happen */
1097 if (ax
->rndx
.rfd
== 0xfff) {
1098 return builtin_type_void
;
1101 /* Use aux as a type information record, map its basic type */
1103 if (t
->bt
> 26 || t
->bt
== btPicture
) {
1104 complain (&basic_type_complaint
, t
->bt
);
1105 return builtin_type_int
;
1108 tp
= *map_bt
[t
->bt
];
1110 /* Cannot use builtin types, use templates */
1111 tp
= make_type(TYPE_CODE_VOID
, 0, 0, 0);
1114 *tp
= *builtin_type_ptr
;
1117 *tp
= *builtin_type_struct
;
1121 *tp
= *builtin_type_union
;
1125 *tp
= *builtin_type_enum
;
1129 *tp
= *builtin_type_range
;
1132 *tp
= *builtin_type_set
;
1138 /* Move on to next aux */
1141 /* This is the way it would work if the compiler worked */
1142 register TIR
*t1
= t
;
1143 while (t1
->continued
)
1147 /* For bitfields all we need is the width */
1153 /* All these types really point to some (common) MIPS type
1154 definition, and only the type-qualifiers fully identify
1155 them. We`ll make the same effort at sharing */
1156 if (t
->bt
== btIndirect
||
1157 t
->bt
== btStruct
||
1160 t
->bt
== btTypedef
||
1163 char name
[256], *pn
;
1165 /* Try to cross reference this type */
1167 ax
+= cross_ref(ax
, &tp1
, &pn
);
1168 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1169 sprintf(name
, fmt
, pn
);
1171 /* reading .o file ? */
1172 if (UNSAFE_DATA_ADDR(tp1
))
1174 if (TYPE_CODE(tp1
) == TYPE_CODE_UNDEF
) {
1176 * Type was incompletely defined, now we know.
1178 TYPE_CODE(tp1
) = TYPE_CODE(tp
);
1179 TYPE_NAME(tp1
) = obsavestring(name
, strlen(name
));
1180 if (TYPE_CODE(tp1
) == TYPE_CODE_ENUM
) {
1183 for (i
= 0; i
< TYPE_NFIELDS(tp1
); i
++)
1184 make_enum_constant(&TYPE_FIELD(tp1
,i
), tp1
);
1188 /* found as cross ref, rid of our template */
1189 if ((TYPE_FLAGS(tp
) & TYPE_FLAG_PERM
) == 0)
1192 /* stupid idea of prepending "struct" to type names */
1193 if (t
->bt
== btStruct
&& !index(TYPE_NAME(tp
), ' ')) {
1194 sprintf(name
, fmt
, TYPE_NAME(tp
));
1195 TYPE_NAME(tp
) = obsavestring(name
, strlen(name
));
1198 TYPE_NAME(tp
) = savestring(name
, strlen(name
));
1201 /* Deal with range types */
1202 if (t
->bt
== btRange
) {
1205 f
= new_field(tp
, "Low");
1206 f
->bitpos
= ax
->dnLow
;
1208 f
= new_field(tp
, "High");
1209 f
->bitpos
= ax
->dnHigh
;
1213 /* Parse all the type qualifiers now. If there are more
1214 than 6 the game will continue in the next aux */
1216 #define PARSE_TQ(tq) \
1217 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, sh);
1219 again
: PARSE_TQ(tq0
);
1234 /* Make up a complex type from a basic one. Type is passed by
1235 reference in TPP and side-effected as necessary. The type
1236 qualifier TQ says how to handle the aux symbols at AX for
1237 the symbol SX we are currently analyzing.
1238 Returns the number of aux symbols we parsed. */
1241 upgrade_type(tpp
, tq
, ax
, sh
)
1249 /* Used in array processing */
1258 t
= lookup_pointer_type (*tpp
);
1263 t
= lookup_function_type (*tpp
);
1269 t
= make_type(TYPE_CODE_ARRAY
, 0, 0, 0);
1270 TYPE_TARGET_TYPE(t
) = *tpp
;
1272 /* Determine and record the domain type (type of index) */
1273 id
= ax
->rndx
.index
;
1279 fh
= get_rfd(cur_fd
, rf
);
1280 f
= new_field(t
, (char *)0);
1281 bzero(&ss
, sizeof ss
);
1282 /* XXX */ f
->type
= parse_type(fh
->iauxBase
+ id
* sizeof(AUXU
),
1287 * This seems to be a pointer to the end of the Block defining
1288 * the type. Why it is here is magic for me, and I have no
1289 * good use for it anyways.
1291 /* This used to occur because cross_ref returned
1292 the wrong result (ax pointed wrong). FIXME,
1293 delete this code in a while. -- gnu@cygnus jul91 */
1294 complain (&array_parse_complaint
, 0);
1296 id
= (++ax
)->rndx
.index
;
1297 if ((rf
= ax
->rndx
.rfd
) == 0xfff)
1298 rf
= (++ax
)->isym
, off
++;
1300 lower
= (++ax
)->dnLow
;
1301 upper
= (++ax
)->dnHigh
;
1302 rf
= (++ax
)->width
; /* bit size of array element */
1304 /* Check whether supplied array element bit size matches
1305 the known size of the element type. If this complaint
1306 ends up not happening, we can remove this code. It's
1307 here because we aren't sure we understand this *&%&$
1309 id
= TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) << 3; /* bitsize */
1311 /* Most likely an undefined type */
1313 TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) = id
>> 3;
1316 complain (&array_bitsize_complaint
, rf
);
1318 TYPE_LENGTH(t
) = (upper
< 0) ? 0 :
1319 (upper
- lower
+ 1) * (rf
>> 3);
1324 /* Volatile -- currently ignored */
1328 complain (&unknown_type_qual_complaint
, tq
);
1334 /* Parse a procedure descriptor record PR. Note that the procedure
1335 is parsed _after_ the local symbols, now we just make up the
1336 extra information we need into a special symbol that we insert
1337 in the procedure's main block. Note also that images that
1338 have been partially stripped (ld -x) have been deprived
1339 of local symbols, and we have to cope with them here.
1340 The procedure's code ends at BOUND */
1343 parse_procedure(pr
, bound
)
1346 struct symbol
*s
, *i
;
1347 SYMR
*sh
= (SYMR
*)pr
->isym
;
1349 struct mips_extra_func_info
*e
;
1353 /* Reuse the MIPS record */
1354 e
= (struct mips_extra_func_info
*) pr
;
1355 e
->numargs
= lookup_numargs(pr
->adr
);
1357 /* Make up our special symbol */
1358 i
= new_symbol(".gdbinfo.");
1359 SYMBOL_VALUE(i
) = (int)e
;
1360 SYMBOL_NAMESPACE(i
) = LABEL_NAMESPACE
;
1361 SYMBOL_CLASS(i
) = LOC_CONST
;
1362 SYMBOL_TYPE(i
) = builtin_type_void
;
1364 /* Make up a name for static procedures. Sigh. */
1365 if (sh
== (SYMR
*)-1) {
1366 sprintf(name
,".static_procedure@%x",pr
->adr
);
1367 sh_name
= savestring(name
, strlen(name
));
1371 sh_name
= (char*)sh
->iss
;
1372 s
= mylookup_symbol(sh_name
, top_stack
->cur_block
,
1373 VAR_NAMESPACE
, LOC_BLOCK
);
1376 b
= SYMBOL_BLOCK_VALUE(s
);
1378 s
= new_symbol(sh_name
);
1379 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1380 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1381 /* Donno its type, hope int is ok */
1382 SYMBOL_TYPE(s
) = lookup_function_type (builtin_type_int
);
1383 add_symbol(s
, top_stack
->cur_block
);
1384 /* Wont have symbols for this one */
1386 SYMBOL_BLOCK_VALUE(s
) = b
;
1387 BLOCK_FUNCTION(b
) = s
;
1388 BLOCK_START(b
) = pr
->adr
;
1389 BLOCK_END(b
) = bound
;
1390 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1391 add_block(b
, top_stack
->cur_st
);
1397 /* Parse the external symbol ES. Just call parse_symbol() after
1398 making sure we know where the aux are for it. For procedures,
1399 parsing of the PDRs has already provided all the needed
1400 information, we only parse them if SKIP_PROCEDURES is false,
1401 and only if this causes no symbol duplication.
1403 This routine clobbers top_stack->cur_block and ->cur_st. */
1406 parse_external(es
, skip_procedures
)
1411 if (es
->ifd
!= ifdNil
) {
1413 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
) + cur_fd
;
1414 ax
= (AUXU
*)cur_fdr
->iauxBase
;
1416 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
);
1419 top_stack
->cur_st
= cur_stab
;
1420 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
1423 /* Reading .o files */
1424 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
) {
1426 switch (es
->asym
.st
) {
1428 case stProc
: what
= "procedure"; n_undef_procs
++; break;
1429 case stGlobal
: what
= "variable"; n_undef_vars
++; break;
1430 case stLabel
: what
= "label"; n_undef_labels
++; break;
1431 default : what
= "symbol"; break;
1435 printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what
,
1436 es
->asym
.iss
, fdr_name(cur_fdr
->rss
));
1440 switch (es
->asym
.st
) {
1442 /* If we have full symbols we do not need more */
1443 if (skip_procedures
)
1445 if (mylookup_symbol (es
->asym
.iss
, top_stack
->cur_block
,
1446 VAR_NAMESPACE
, LOC_BLOCK
))
1452 * Note that the case of a symbol with indexNil
1453 * must be handled anyways by parse_symbol().
1455 parse_symbol(&es
->asym
, ax
);
1462 /* Parse the line number info for file descriptor FH into
1463 GDB's linetable LT. MIPS' encoding requires a little bit
1464 of magic to get things out. Note also that MIPS' line
1465 numbers can go back and forth, apparently we can live
1466 with that and do not need to reorder our linetables */
1471 struct linetable
*lt
;
1473 unsigned char *base
= (unsigned char*)fh
->cbLineOffset
;
1475 int delta
, count
, lineno
= 0;
1481 /* Scan by procedure descriptors */
1482 i
= 0; j
= 0, k
= 0;
1483 for (pr
= (PDR
*)IPDFIRST(cur_hdr
,fh
); j
< fh
->cpd
; j
++, pr
++) {
1486 /* No code for this one */
1487 if (pr
->iline
== ilineNil
||
1488 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1491 * Aurgh! To know where to stop expanding we
1494 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1495 if (pr
[l
].iline
!= -1)
1497 if (l
== (fh
->cpd
- j
))
1502 * When procedures are moved around the linenumbers
1503 * are attributed to the next procedure up
1505 if (pr
->iline
>= halt
) continue;
1507 base
= (unsigned char*)pr
->cbLineOffset
;
1508 l
= pr
->adr
>> 2; /* in words */
1509 halt
+= (pr
->adr
>> 2) - pr
->iline
;
1510 for (lineno
= pr
->lnLow
; l
< halt
;) {
1511 count
= *base
& 0x0f;
1512 delta
= *base
++ >> 4;
1516 delta
= (base
[0] << 8) | base
[1];
1517 if (delta
>= 0x8000)
1521 lineno
+= delta
;/* first delta is 0 */
1522 k
= add_line(lt
, lineno
, l
, k
);
1529 /* Parse the symbols of the file described by FH, whose index is F_IDX.
1530 BOUND is the highest core address of this file's procedures */
1533 parse_one_file(fh
, f_idx
, bound
)
1540 /* Parse local symbols first */
1542 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
1543 sh
= (SYMR
*) (fh
->isymBase
) + s_idx
;
1545 parse_symbol(sh
, fh
->iauxBase
);
1548 /* Procedures next, note we need to look-ahead to
1549 find out where the procedure's code ends */
1551 for (s_idx
= 0; s_idx
< fh
->cpd
-1; s_idx
++) {
1552 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + s_idx
;
1553 parse_procedure(pr
, pr
[1].adr
); /* next proc up */
1556 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + s_idx
;
1557 parse_procedure(pr
, bound
); /* next file up */
1560 /* Linenumbers. At the end, check if we can save memory */
1561 parse_lines(fh
, LINETABLE(cur_stab
));
1562 if (LINETABLE(cur_stab
)->nitems
< fh
->cline
)
1563 shrink_linetable(cur_stab
);
1566 /* Master parsing procedure for first-pass reading of file symbols
1567 into a partial_symtab.
1569 Parses the symtab described by the global symbolic header CUR_HDR.
1570 END_OF_TEXT_SEG gives the address just after the text segment for
1571 the symtab we are reading. */
1574 parse_partial_symbols(end_of_text_seg
)
1575 int end_of_text_seg
;
1577 int f_idx
, s_idx
, h_max
, stat_idx
;
1579 /* Running pointers */
1584 struct partial_symtab
*pst
;
1589 * Only parse the Local and External symbols, and the Relative FDR.
1590 * Fixup enough of the loader symtab to be able to use it.
1591 * Allocate space only for the file's portions we need to
1597 max_glevel
= MIN_GLEVEL
;
1599 /* Allocate the map FDR -> PST.
1600 Minor hack: -O3 images might claim some global data belongs
1601 to FDR -1. We`ll go along with that */
1602 fdr_to_pst
= (struct pst_map
*)xzalloc((hdr
->ifdMax
+1) * sizeof *fdr_to_pst
);
1605 struct partial_symtab
* pst
= new_psymtab("");
1606 fdr_to_pst
[-1].pst
= pst
;
1610 /* Now scan the FDRs, mostly for dependencies */
1611 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++)
1612 (void) parse_fdr(f_idx
, 1);
1614 /* Take a good guess at how many symbols we might ever need */
1615 h_max
= hdr
->iextMax
;
1617 /* Parse externals: two passes because they can be ordered
1618 in any way, but gdb likes to have them segregated by their
1621 /* Pass 1 over external syms: Presize and partition the list */
1622 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1623 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1624 fdr_to_pst
[esh
->ifd
].n_globals
++;
1627 if (global_psymbols
.list
) {
1628 int origsize
= global_psymbols
.next
- global_psymbols
.list
;
1630 global_psymbols
.list
= (struct partial_symbol
*)
1631 xrealloc (global_psymbols
.list
,
1632 (h_max
+ origsize
) * sizeof(struct partial_symbol
));
1633 global_psymbols
.next
= global_psymbols
.list
+ origsize
;
1634 global_psymbols
.size
= h_max
+ origsize
;
1636 global_psymbols
.list
= (struct partial_symbol
*)
1637 xmalloc (h_max
* sizeof(struct partial_symbol
));
1638 global_psymbols
.next
= global_psymbols
.list
;
1639 global_psymbols
.size
= h_max
;
1642 /* Pass 1.5 over files: partition out global symbol space */
1643 s_idx
= global_psymbols
.next
- global_psymbols
.list
;
1644 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++) {
1645 fdr_to_pst
[f_idx
].pst
->globals_offset
= s_idx
;
1646 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
1649 /* Pass 1.6 over files: partition out static symbol space.
1650 Note that this loop starts at 0, not at -1. */
1651 stat_idx
= static_psymbols
.next
- static_psymbols
.list
;
1652 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
1653 fdr_to_pst
[f_idx
].pst
->statics_offset
= stat_idx
;
1654 fh
= f_idx
+ (FDR
*)(hdr
->cbFdOffset
);
1655 stat_idx
+= fh
->csym
;
1658 /* Now that we know its max size, allocate static symbol list */
1659 if (static_psymbols
.list
) {
1660 int origsize
= static_psymbols
.next
- static_psymbols
.list
;
1662 static_psymbols
.list
= (struct partial_symbol
*)
1663 xrealloc (static_psymbols
.list
,
1664 stat_idx
* sizeof(struct partial_symbol
));
1665 static_psymbols
.next
= static_psymbols
.list
+ origsize
;
1666 static_psymbols
.size
= stat_idx
;
1668 static_psymbols
.list
= (struct partial_symbol
*)
1669 xmalloc (stat_idx
* sizeof(struct partial_symbol
));
1670 static_psymbols
.next
= static_psymbols
.list
;
1671 static_psymbols
.size
= stat_idx
;
1674 /* Pass 2 over external syms: fill in external symbols */
1675 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1676 register struct partial_symbol
*p
;
1677 enum misc_function_type misc_type
= mf_text
;
1678 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1680 if (esh
->asym
.sc
== scUndefined
|| esh
->asym
.sc
== scNil
)
1683 /* Locate the psymtab and the preallocated psymbol. */
1684 pst
= fdr_to_pst
[esh
->ifd
].pst
;
1685 p
= global_psymbols
.list
+ pst
->globals_offset
+
1686 pst
->n_global_syms
++;
1687 SYMBOL_NAME(p
) = (char *)(esh
->asym
.iss
);
1688 SYMBOL_NAMESPACE(p
) = VAR_NAMESPACE
;
1690 switch (esh
->asym
.st
) {
1692 SYMBOL_CLASS(p
) = LOC_BLOCK
;
1693 SYMBOL_VALUE(p
) = esh
->asym
.value
;
1696 SYMBOL_CLASS(p
) = LOC_STATIC
;
1697 SYMBOL_VALUE_ADDRESS(p
) = (CORE_ADDR
)esh
->asym
.value
;
1698 misc_type
= mf_data
;
1701 SYMBOL_CLASS(p
) = LOC_LABEL
;
1702 SYMBOL_VALUE_ADDRESS(p
) = (CORE_ADDR
)esh
->asym
.value
;
1705 misc_type
= mf_unknown
;
1706 complain (&unknown_ext_complaint
, SYMBOL_NAME(p
));
1708 prim_record_misc_function (SYMBOL_NAME(p
),
1713 /* Pass 3 over files, over local syms: fill in static symbols */
1714 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
1715 fh
= f_idx
+ (FDR
*)(cur_hdr
->cbFdOffset
);
1716 pst
= fdr_to_pst
[f_idx
].pst
;
1717 pst
->texthigh
= pst
->textlow
;
1719 for (s_idx
= 0; s_idx
< fh
->csym
; ) {
1720 register struct partial_symbol
*p
;
1722 sh
= s_idx
+ (SYMR
*) fh
->isymBase
;
1724 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
) {
1725 /* FIXME, premature? */
1730 /* Locate the preallocated psymbol. */
1731 p
= static_psymbols
.list
+ pst
->statics_offset
+
1733 SYMBOL_NAME(p
) = (char *)(sh
->iss
);
1734 SYMBOL_VALUE(p
) = sh
->value
;
1735 SYMBOL_NAMESPACE(p
) = VAR_NAMESPACE
;
1738 case stProc
: /* Asm labels apparently */
1739 case stStaticProc
: /* Function */
1740 SYMBOL_CLASS(p
) = LOC_BLOCK
;
1741 pst
->n_static_syms
++; /* Use gdb symbol */
1742 /* Skip over procedure to next one. */
1743 s_idx
= (sh
->index
+ (AUXU
*)fh
->iauxBase
)
1747 long procaddr
= sh
->value
;
1749 sh
= s_idx
+ (SYMR
*) fh
->isymBase
- 1;
1750 if (sh
->st
!= stEnd
)
1752 high
= procaddr
+ sh
->value
;
1753 if (high
> pst
->texthigh
)
1754 pst
->texthigh
= high
;
1757 case stStatic
: /* Variable */
1758 SYMBOL_CLASS(p
) = LOC_STATIC
;
1759 SYMBOL_VALUE_ADDRESS(p
) = (CORE_ADDR
)sh
->value
;
1761 case stTypedef
: /* Typedef */
1762 SYMBOL_CLASS(p
) = LOC_TYPEDEF
;
1764 case stConstant
: /* Constant decl */
1765 SYMBOL_CLASS(p
) = LOC_CONST
;
1767 case stBlock
: /* { }, str, un, enum*/
1768 if (sh
->sc
== scInfo
) {
1769 SYMBOL_NAMESPACE(p
) = STRUCT_NAMESPACE
;
1770 SYMBOL_CLASS(p
) = LOC_TYPEDEF
;
1771 pst
->n_static_syms
++;
1773 /* Skip over the block */
1776 case stFile
: /* File headers */
1777 case stLabel
: /* Labels */
1778 case stEnd
: /* Ends of files */
1781 complain (&unknown_sym_complaint
, SYMBOL_NAME(p
));
1782 complain (&unknown_st_complaint
, sh
->st
);
1786 pst
->n_static_syms
++; /* Use this gdb symbol */
1788 s_idx
++; /* Go to next file symbol */
1790 /* We don't usually record static syms, but some we seem to. chk dbxread. */
1791 /*FIXME*/ prim_record_misc_function (SYMBOL_NAME(p
),
1798 /* The array (of lists) of globals must be sorted. */
1801 /* Now sort the global psymbols. */
1802 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
1803 struct partial_symtab
*pst
= fdr_to_pst
[f_idx
].pst
;
1804 if (pst
->n_global_syms
> 1)
1805 qsort (global_psymbols
.list
+ pst
->globals_offset
,
1806 pst
->n_global_syms
, sizeof (struct partial_symbol
),
1810 /* Mark the last code address, and remember it for later */
1811 hdr
->cbDnOffset
= end_of_text_seg
;
1813 free(&fdr_to_pst
[-1]);
1818 /* Do the initial analisys of the F_IDX-th file descriptor.
1819 Allocates a partial symtab for it, and builds the list
1820 of dependent files by recursion. LEV says at which level
1821 of recursion we are called (to pretty up debug traces) */
1823 static struct partial_symtab
*
1824 parse_fdr(f_idx
, lev
)
1828 register struct partial_symtab
*pst
;
1831 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + f_idx
;
1833 /* Use this to indicate into which symtab this file was parsed */
1835 return (struct partial_symtab
*) fh
->ioptBase
;
1837 /* Debuggability level */
1838 if (compare_glevel(max_glevel
, fh
->glevel
) < 0)
1839 max_glevel
= fh
->glevel
;
1841 /* Make a new partial_symtab */
1842 pst
= new_psymtab(fh
->rss
);
1847 pst
->textlow
= fh
->adr
;
1848 pst
->texthigh
= fh
->cpd
; /* To be fixed later */
1851 /* Make everything point to everything. */
1852 FDR_IDX(pst
) = f_idx
;
1853 fdr_to_pst
[f_idx
].pst
= pst
;
1854 fh
->ioptBase
= (int)pst
;
1856 /* Analyze its dependencies */
1861 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
1862 /* ...then presumably a .h file: drop reverse depends .h->.c */
1863 for (; s_id0
< fh
->crfd
; s_id0
++) {
1864 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
1866 s_id0
++; /* Skip self-dependency */
1871 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
1872 pst
->dependencies
= (struct partial_symtab
**)
1873 obstack_alloc (psymbol_obstack
,
1874 pst
->number_of_dependencies
*
1875 sizeof (struct partial_symtab
*));
1876 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
1877 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
1879 pst
->dependencies
[s_idx
-s_id0
] = parse_fdr(*rh
, lev
+1);
1886 /* Ancillary function to psymtab_to_symtab(). Does all the work
1887 for turning the partial symtab PST into a symtab, recurring
1888 first on all dependent psymtabs. The argument FILENAME is
1889 only passed so we can see in debug stack traces what file
1893 psymtab_to_symtab_1(pst
, filename
)
1894 struct partial_symtab
*pst
;
1905 pending_list
= (struct pending
**) cur_hdr
->cbOptOffset
;
1906 if (pending_list
== 0) {
1907 pending_list
= (struct pending
**)
1908 xzalloc(cur_hdr
->ifdMax
* sizeof(struct pending
*));
1909 cur_hdr
->cbOptOffset
= (int)pending_list
;
1912 /* How many symbols will we need */
1913 /* FIXME, this does not count enum values. */
1914 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
1915 if (FDR_IDX(pst
) == -1) {
1917 st
= new_symtab( "unknown", f_max
, 0);
1919 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + FDR_IDX(pst
);
1920 f_max
+= fh
->csym
+ fh
->cpd
;
1921 st
= new_symtab(pst
->filename
, 2 * f_max
, 2 * fh
->cline
);
1924 /* Read in all partial symbtabs on which this one is dependent.
1925 NOTE that we do have circular dependencies, sigh. We solved
1926 that by setting pst->readin before this point. */
1928 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
1929 if (!pst
->dependencies
[i
]->readin
) {
1930 /* Inform about additional files to be read in. */
1933 fputs_filtered (" ", stdout
);
1935 fputs_filtered ("and ", stdout
);
1937 printf_filtered ("%s...",
1938 pst
->dependencies
[i
]->filename
);
1939 wrap_here (""); /* Flush output */
1942 /* We only pass the filename for debug purposes */
1943 psymtab_to_symtab_1(pst
->dependencies
[i
],
1944 pst
->dependencies
[i
]->filename
);
1947 /* Now read the symbols for this symtab */
1949 cur_fd
= FDR_IDX(pst
);
1953 /* Get a new lexical context */
1956 top_stack
->cur_st
= cur_stab
;
1957 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab
),
1959 BLOCK_START(top_stack
->cur_block
) = fh
? fh
->adr
: 0;
1960 BLOCK_END(top_stack
->cur_block
) = 0;
1961 top_stack
->blocktype
= stFile
;
1962 top_stack
->maxsyms
= 2*f_max
;
1963 top_stack
->cur_type
= 0;
1964 top_stack
->procadr
= 0;
1965 top_stack
->numargs
= 0;
1967 /* Parse locals and procedures */
1969 parse_one_file(fh
, cur_fd
, (cur_fd
== (cur_hdr
->ifdMax
- 1)) ?
1970 cur_hdr
->cbDnOffset
: fh
[1].adr
);
1972 /* .. and our share of externals.
1973 XXX use the global list to speed up things here. how ?
1974 FIXME, Maybe quit once we have found the right number of ext's? */
1975 /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
1976 top_stack
->blocktype
= stFile
;
1977 top_stack
->maxsyms
= cur_hdr
->isymMax
+ cur_hdr
->ipdMax
+ cur_hdr
->iextMax
;
1978 for (i
= 0; i
< cur_hdr
->iextMax
; i
++) {
1979 register EXTR
*esh
= (EXTR
*) (cur_hdr
->cbExtOffset
) + i
;
1980 if (esh
->ifd
== cur_fd
)
1981 parse_external(esh
, 1);
1984 /* If there are undefined, tell the user */
1985 if (n_undef_symbols
) {
1986 printf_filtered("File %s contains %d unresolved references:",
1987 st
->filename
, n_undef_symbols
);
1988 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
1989 n_undef_vars
, n_undef_procs
, n_undef_labels
);
1990 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
1996 * Sort the symbol table now, we are done adding symbols to it.
1998 sort_symtab_syms(st
);
2000 /* Now link the psymtab and the symtab. */
2004 /* Ancillary parsing procedures. */
2006 /* Lookup the type at relative index RN. Return it in TPP
2007 if found and in any event come up with its name PNAME.
2008 Return value says how many aux symbols we ate */
2011 cross_ref(rn
, tpp
, pname
)
2018 /* Escape index means 'the next one' */
2019 if (rn
->rfd
== 0xfff)
2020 rf
= *(unsigned *) (rn
+ 1);
2026 *pname
= "<undefined>";
2029 * Find the relative file descriptor and the symbol in it
2031 FDR
*fh
= get_rfd(cur_fd
, rf
);
2036 * If we have processed this symbol then we left a forwarding
2037 * pointer to the corresponding GDB symbol. If not, we`ll put
2038 * it in a list of pending symbols, to be processed later when
2039 * the file f will be. In any event, we collect the name for
2040 * the type here. Which is why we made a first pass at
2043 sh
= (SYMR
*) (fh
->isymBase
) + rn
->index
;
2045 /* Careful, we might be looking at .o files */
2046 *pname
= (UNSAFE_DATA_ADDR(sh
->iss
)) ? "<undefined>" :
2049 /* Have we parsed it ? */
2050 if ((!UNSAFE_DATA_ADDR(sh
->value
)) && (sh
->st
== stParsed
)) {
2051 t
= (struct type
*) sh
->value
;
2056 /* Avoid duplicates */
2057 p
= is_pending_symbol(fh
, sh
);
2062 add_pending(fh
, sh
, *tpp
);
2066 /* We used one auxent normally, two if we got a "next one" rf. */
2067 return (rn
->rfd
== 0xfff? 2: 1);
2071 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2072 keeping the symtab sorted */
2074 static struct symbol
*
2075 mylookup_symbol (name
, block
, namespace, class)
2077 register struct block
*block
;
2078 enum namespace namespace;
2079 enum address_class
class;
2081 register int bot
, top
, inc
;
2082 register struct symbol
*sym
;
2085 top
= BLOCK_NSYMS(block
);
2088 sym
= BLOCK_SYM(block
, bot
);
2089 if (SYMBOL_NAME(sym
)[0] == inc
2090 && SYMBOL_NAMESPACE(sym
) == namespace
2091 && SYMBOL_CLASS(sym
) == class
2092 && !strcmp(SYMBOL_NAME(sym
), name
))
2096 if (block
= BLOCK_SUPERBLOCK (block
))
2097 return mylookup_symbol (name
, block
, namespace, class);
2102 /* Add a new symbol S to a block B.
2103 Infrequently, we will need to reallocate the block to make it bigger.
2104 We only detect this case when adding to top_stack->cur_block, since
2105 that's the only time we know how big the block is. FIXME. */
2112 int nsyms
= BLOCK_NSYMS(b
)++;
2113 struct block
*origb
;
2114 struct parse_stack
*stackp
;
2116 if (b
== top_stack
->cur_block
&&
2117 nsyms
>= top_stack
->maxsyms
) {
2118 complain (&block_overflow_complaint
, s
->name
);
2119 /* In this case shrink_block is actually grow_block, since
2120 BLOCK_NSYMS(b) is larger than its current size. */
2122 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
2124 /* Now run through the stack replacing pointers to the
2125 original block. shrink_block has already done this
2126 for the blockvector and BLOCK_FUNCTION. */
2127 for (stackp
= top_stack
; stackp
; stackp
= stackp
->next
) {
2128 if (stackp
->cur_block
== origb
) {
2129 stackp
->cur_block
= b
;
2130 stackp
->maxsyms
= BLOCK_NSYMS (b
);
2134 BLOCK_SYM(b
,nsyms
) = s
;
2137 /* Add a new block B to a symtab S */
2144 struct blockvector
*bv
= BLOCKVECTOR(s
);
2146 bv
= (struct blockvector
*)xrealloc(bv
, sizeof(struct blockvector
) +
2147 BLOCKVECTOR_NBLOCKS(bv
) * sizeof(bv
->block
));
2148 if (bv
!= BLOCKVECTOR(s
))
2149 BLOCKVECTOR(s
) = bv
;
2151 BLOCKVECTOR_BLOCK(bv
, BLOCKVECTOR_NBLOCKS(bv
)++) = b
;
2154 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2155 MIPS' linenumber encoding might need more than one byte
2156 to describe it, LAST is used to detect these continuation lines */
2159 add_line(lt
, lineno
, adr
, last
)
2160 struct linetable
*lt
;
2166 last
= -2; /* make sure we record first line */
2168 if (last
== lineno
) /* skip continuation lines */
2171 lt
->item
[lt
->nitems
].line
= lineno
;
2172 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
2178 /* Comparison functions, used when sorting things */
2180 /* Symtabs must be ordered viz the code segments they cover */
2183 compare_symtabs( s1
, s2
)
2184 struct symtab
**s1
, **s2
;
2186 /* "most specific" first */
2188 register struct block
*b1
, *b2
;
2189 b1
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1
),GLOBAL_BLOCK
);
2190 b2
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2
),GLOBAL_BLOCK
);
2191 if (BLOCK_END(b1
) == BLOCK_END(b2
))
2192 return BLOCK_START(b1
) - BLOCK_START(b2
);
2193 return BLOCK_END(b1
) - BLOCK_END(b2
);
2197 /* Partial Symtabs, same */
2200 compare_psymtabs( s1
, s2
)
2201 struct partial_symtab
**s1
, **s2
;
2203 /* Perf twist: put the ones with no code at the end */
2205 register int a
= (*s1
)->textlow
;
2206 register int b
= (*s2
)->textlow
;
2215 /* Partial symbols are compared lexicog by their print names */
2218 compare_psymbols (s1
, s2
)
2219 register struct partial_symbol
*s1
, *s2
;
2222 *st1
= SYMBOL_NAME(s1
),
2223 *st2
= SYMBOL_NAME(s2
);
2225 return (st1
[0] - st2
[0] ? st1
[0] - st2
[0] :
2226 strcmp(st1
+ 1, st2
+ 1));
2229 /* Blocks with a smaller low bound should come first */
2231 static int compare_blocks(b1
,b2
)
2232 struct block
**b1
, **b2
;
2234 register int addr_diff
;
2236 addr_diff
= (BLOCK_START((*b1
))) - (BLOCK_START((*b2
)));
2238 return (BLOCK_END((*b1
))) - (BLOCK_END((*b2
)));
2243 /* Sorting and reordering procedures */
2245 /* Sort the blocks of a symtab S.
2246 Reorder the blocks in the blockvector by code-address,
2247 as required by some MI search routines */
2253 struct blockvector
*bv
= BLOCKVECTOR(s
);
2255 if (BLOCKVECTOR_NBLOCKS(bv
) <= 2) {
2257 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) == 0)
2258 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = 0;
2259 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) == 0)
2260 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) = 0;
2264 * This is very unfortunate: normally all functions are compiled in
2265 * the order they are found, but if the file is compiled -O3 things
2266 * are very different. It would be nice to find a reliable test
2267 * to detect -O3 images in advance.
2269 if (BLOCKVECTOR_NBLOCKS(bv
) > 3)
2270 qsort(&BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
),
2271 BLOCKVECTOR_NBLOCKS(bv
) - FIRST_LOCAL_BLOCK
,
2272 sizeof(struct block
*),
2276 register CORE_ADDR high
= 0;
2277 register int i
, j
= BLOCKVECTOR_NBLOCKS(bv
);
2279 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
2280 if (high
< BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
)))
2281 high
= BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
));
2282 BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = high
;
2285 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) =
2286 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
));
2288 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2289 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2290 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2291 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2294 /* Sort the symtab list, as required by some search procedures.
2295 We want files ordered to make them look right to users, and for
2296 searching (see block_for_pc). */
2302 struct symtab
*stab
;
2303 register struct symtab
**all_symtabs
;
2304 register int symtab_count
;
2309 /* Create an array of pointers to all the symtabs. */
2310 for (symtab_count
= 0, stab
= symtab_list
;
2312 symtab_count
++, stab
= stab
->next
) {
2313 obstack_grow (psymbol_obstack
, &stab
, sizeof (stab
));
2314 /* FIXME: Only sort blocks for new symtabs ??? */
2318 all_symtabs
= (struct symtab
**)
2319 obstack_base (psymbol_obstack
);
2320 qsort((char *)all_symtabs
, symtab_count
,
2321 sizeof(struct symtab
*), compare_symtabs
);
2323 /* Re-construct the symtab list, but now it is sorted. */
2324 for (i
= 0; i
< symtab_count
-1; i
++)
2325 all_symtabs
[i
]->next
= all_symtabs
[i
+1];
2326 all_symtabs
[i
]->next
= 0;
2327 symtab_list
= all_symtabs
[0];
2329 obstack_free (psymbol_obstack
, all_symtabs
);
2332 /* Sort the partial symtab list, as required by some search procedures.
2333 PC lookups stop at the first psymtab such that textlow <= PC < texthigh */
2339 register int all_psymtabs_count
;
2340 struct partial_symtab
*pstab
;
2341 struct partial_symtab
**all_psymtabs
;
2343 if (!partial_symtab_list
)
2346 /* Create an array of pointers to all the partial_symtabs. */
2348 for (all_psymtabs_count
= 0, pstab
= partial_symtab_list
;
2350 all_psymtabs_count
++, pstab
= pstab
->next
)
2351 obstack_grow (psymbol_obstack
, &pstab
, sizeof (pstab
));
2353 all_psymtabs
= (struct partial_symtab
**)
2354 obstack_base (psymbol_obstack
);
2356 qsort((char *)all_psymtabs
, all_psymtabs_count
,
2357 sizeof(struct partial_symtab
*), compare_psymtabs
);
2359 /* Re-construct the partial_symtab_list, but now it is sorted. */
2361 for (i
= 0; i
< all_psymtabs_count
-1; i
++)
2362 all_psymtabs
[i
]->next
= all_psymtabs
[i
+1];
2363 all_psymtabs
[i
]->next
= 0;
2364 partial_symtab_list
= all_psymtabs
[0];
2366 obstack_free (psymbol_obstack
, all_psymtabs
);
2369 /* Constructor/restructor/destructor procedures */
2371 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2372 MAXSYMS and linenumbers MAXLINES we'll put in it */
2376 new_symtab(name
, maxsyms
, maxlines
)
2379 struct symtab
*s
= allocate_symtab (name
);
2381 LINETABLE(s
) = new_linetable(maxlines
);
2383 /* All symtabs must have at least two blocks */
2384 BLOCKVECTOR(s
) = new_bvect(2);
2385 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
) = new_block(maxsyms
);
2386 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), STATIC_BLOCK
) = new_block(maxsyms
);
2387 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
),STATIC_BLOCK
)) =
2388 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
);
2390 s
->free_code
= free_linetable
;
2392 /* Link the new symtab into the list of such. */
2393 s
->next
= symtab_list
;
2399 /* Allocate a new partial_symtab NAME */
2401 static struct partial_symtab
*
2405 struct partial_symtab
*pst
;
2407 pst
= (struct partial_symtab
*)
2408 obstack_alloc (psymbol_obstack
, sizeof (*pst
));
2409 bzero (pst
, sizeof (*pst
));
2411 if (name
== (char*)-1) /* FIXME -- why not null here? */
2412 pst
->filename
= "<no name>";
2414 pst
->filename
= name
;
2416 pst
->next
= partial_symtab_list
;
2417 partial_symtab_list
= pst
;
2419 /* Keep a backpointer to the file's symbols */
2420 pst
->read_symtab_private
= (char *) obstack_alloc (psymbol_obstack
,
2421 sizeof (struct symloc
));
2422 CUR_HDR(pst
) = cur_hdr
;
2424 /* The way to turn this into a symtab is to call... */
2425 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
2431 /* Allocate a linetable array of the given SIZE */
2434 struct linetable
*new_linetable(size
)
2436 struct linetable
*l
;
2438 size
= size
* sizeof(l
->item
) + sizeof(struct linetable
);
2439 l
= (struct linetable
*)xmalloc(size
);
2444 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2445 I am not so sure about the 3.4 ones */
2451 struct linetable
*l
= new_linetable(LINETABLE(s
)->nitems
);
2453 bcopy(LINETABLE(s
), l
,
2454 LINETABLE(s
)->nitems
* sizeof(l
->item
) + sizeof(struct linetable
));
2455 free (LINETABLE(s
));
2459 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2462 struct blockvector
*
2465 struct blockvector
*bv
;
2468 size
= sizeof(struct blockvector
) + nblocks
* sizeof(struct block
*);
2469 bv
= (struct blockvector
*) xzalloc(size
);
2471 BLOCKVECTOR_NBLOCKS(bv
) = nblocks
;
2476 /* Allocate and zero a new block of MAXSYMS symbols */
2482 int size
= sizeof(struct block
) + (maxsyms
-1) * sizeof(struct symbol
*);
2483 struct block
*b
= (struct block
*)xzalloc(size
);
2488 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2489 Shrink_block can also be used by add_symbol to grow a block. */
2491 static struct block
*
2497 struct blockvector
*bv
= BLOCKVECTOR(s
);
2500 /* Just reallocate it and fix references to the old one */
2502 new = (struct block
*) xrealloc ((char *)b
, sizeof(struct block
) +
2503 (BLOCK_NSYMS(b
)-1) * sizeof(struct symbol
*));
2505 /* Should chase pointers to old one. Fortunately, that`s just
2506 the block`s function and inferior blocks */
2507 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b
)
2508 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2509 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2510 if (BLOCKVECTOR_BLOCK(bv
,i
) == b
)
2511 BLOCKVECTOR_BLOCK(bv
,i
) = new;
2512 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) == b
)
2513 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) = new;
2517 /* Create a new symbol with printname NAME */
2524 struct symbol
*s
= (struct symbol
*)
2525 obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
2527 bzero (s
, sizeof (*s
));
2528 SYMBOL_NAME(s
) = name
;
2532 /* Create a new type with printname NAME */
2539 struct type
*t
= (struct type
*)
2540 obstack_alloc (symbol_obstack
, sizeof (struct type
));
2542 bzero (t
, sizeof (*t
));
2543 TYPE_VPTR_FIELDNO (t
) = -1;
2544 TYPE_NAME(t
) = name
;
2548 /* Create and initialize a new type with printname NAME.
2549 CODE and LENGTH are the initial info we put in,
2550 UNS says whether the type is unsigned or not. */
2554 make_type(code
, length
, uns
, name
)
2555 enum type_code code
;
2559 register struct type
*type
;
2561 type
= (struct type
*) xzalloc(sizeof(struct type
));
2562 TYPE_CODE(type
) = code
;
2563 TYPE_LENGTH(type
) = length
;
2564 TYPE_FLAGS(type
) = uns
? TYPE_FLAG_UNSIGNED
: 0;
2565 TYPE_NAME(type
) = name
;
2566 TYPE_VPTR_FIELDNO (type
) = -1;
2571 /* Allocate a new field named NAME to the type TYPE */
2575 new_field(type
,name
)
2581 /* Fields are kept in an array */
2582 if (TYPE_NFIELDS(type
))
2583 TYPE_FIELDS(type
) = (struct field
*)xrealloc(TYPE_FIELDS(type
),
2584 (TYPE_NFIELDS(type
)+1) * sizeof(struct field
));
2586 TYPE_FIELDS(type
) = (struct field
*)xzalloc(sizeof(struct field
));
2587 f
= &(TYPE_FIELD(type
,TYPE_NFIELDS(type
)));
2588 TYPE_NFIELDS(type
)++;
2589 bzero(f
, sizeof(struct field
));
2590 f
->name
= name
; /* Whether or not NAME is zero, this works. */
2594 /* Make an enum constant for a member F of an enumerated type T */
2597 make_enum_constant(f
,t
)
2603 * This is awful, but that`s the way it is supposed to be
2604 * (BTW, no need to free the real 'type', it's a builtin)
2606 f
->type
= (struct type
*) f
->bitpos
;
2608 s
= new_symbol(f
->name
);
2609 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2610 SYMBOL_CLASS(s
) = LOC_CONST
;
2612 SYMBOL_VALUE(s
) = f
->bitpos
;
2613 add_symbol(s
, top_stack
->cur_block
);
2618 /* Things used for calling functions in the inferior.
2619 These functions are exported to our companion
2620 mips-dep.c file and are here because they play
2621 with the symbol-table explicitly. */
2624 /* Need to make a new symbol on the fly for the dummy
2625 frame we put on the stack. Which goes in the.. */
2627 static struct symtab
*dummy_symtab
;
2629 /* Make up a dummy symbol for the code we put at END_PC,
2630 of size SIZE, invoking a function with NARGS arguments
2631 and using a frame of FRAMESIZE bytes */
2633 mips_create_dummy_symbol(end_pc
, size
, nargs
, framesize
)
2637 struct mips_extra_func_info
*gdbinfo
;
2639 /* Allocate symtab if not done already */
2640 if (dummy_symtab
== 0)
2641 dummy_symtab
= new_symtab(".dummy_symtab.", 100, 0);
2643 /* Make a new block. Only needs one symbol */
2645 BLOCK_START(bl
) = end_pc
- size
;
2646 BLOCK_END(bl
) = end_pc
;
2648 BLOCK_SUPERBLOCK(bl
) =
2649 BLOCKVECTOR_BLOCK(BLOCKVECTOR(dummy_symtab
),GLOBAL_BLOCK
);
2650 add_block(bl
, dummy_symtab
);
2651 sort_blocks(dummy_symtab
);
2653 BLOCK_FUNCTION(bl
) = new_symbol("??");
2654 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(bl
)) = bl
;
2655 g
= new_symbol(".gdbinfo.");
2656 BLOCK_SYM(bl
,BLOCK_NSYMS(bl
)++) = g
;
2658 SYMBOL_NAMESPACE(g
) = LABEL_NAMESPACE
;
2659 SYMBOL_CLASS(g
) = LOC_CONST
;
2660 SYMBOL_TYPE(g
) = builtin_type_void
;
2661 gdbinfo
= (struct mips_extra_func_info
*)
2662 xzalloc(sizeof(struct mips_extra_func_info
));
2664 SYMBOL_VALUE(g
) = (long) gdbinfo
;
2666 gdbinfo
->numargs
= nargs
;
2667 gdbinfo
->framesize
= framesize
;
2668 gdbinfo
->framereg
= 29;
2669 gdbinfo
->pcreg
= 31;
2670 gdbinfo
->regmask
= -2;
2671 gdbinfo
->regoffset
= -4;
2672 gdbinfo
->fregmask
= 0; /* XXX */
2673 gdbinfo
->fregoffset
= 0; /* XXX */
2676 /* We just returned from the dummy code at END_PC, drop its symbol */
2678 mips_destroy_dummy_symbol(end_pc
)
2681 struct blockvector
*bv
= BLOCKVECTOR(dummy_symtab
);
2684 bl
= block_for_pc(end_pc
);
2685 free(BLOCK_FUNCTION(bl
));
2686 free(SYMBOL_VALUE(BLOCK_SYM(bl
,0)));
2687 free(BLOCK_SYM(bl
,0));
2689 for (i
= FIRST_LOCAL_BLOCK
; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2690 if (BLOCKVECTOR_BLOCK(bv
,i
) == bl
)
2692 for (; i
< BLOCKVECTOR_NBLOCKS(bv
) - 1; i
++)
2693 BLOCKVECTOR_BLOCK(bv
,i
) = BLOCKVECTOR_BLOCK(bv
,i
+1);
2694 BLOCKVECTOR_NBLOCKS(bv
)--;
2695 sort_blocks(dummy_symtab
);
2700 /* Sigtramp: make sure we have all the necessary information
2701 about the signal trampoline code. Since the official code
2702 from MIPS does not do so, we make up that information ourselves.
2703 If they fix the library (unlikely) this code will neutralize itself. */
2710 struct block
*b
, *b0
;
2712 sigtramp_address
= -1;
2714 /* We know it is sold as sigvec */
2715 s
= lookup_symbol("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
2717 /* Most programs do not play with signals */
2721 b0
= SYMBOL_BLOCK_VALUE(s
);
2723 /* A label of sigvec, to be more precise */
2724 s
= lookup_symbol("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
2726 /* But maybe this program uses its own version of sigvec */
2730 sigtramp_address
= SYMBOL_VALUE(s
);
2731 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
2733 /* Did we or MIPSco fix the library ? */
2734 if (SYMBOL_CLASS(s
) == LOC_BLOCK
)
2737 /* But what symtab does it live in ? */
2738 st
= find_pc_symtab(SYMBOL_VALUE(s
));
2741 * Ok, there goes the fix: turn it into a procedure, with all the
2742 * needed info. Note we make it a nested procedure of sigvec,
2743 * which is the way the (assembly) code is actually written.
2745 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2746 SYMBOL_CLASS(s
) = LOC_BLOCK
;
2747 SYMBOL_TYPE(s
) = make_type(TYPE_CODE_FUNC
, 4, 0, 0);
2748 TYPE_TARGET_TYPE(SYMBOL_TYPE(s
)) = builtin_type_void
;
2750 /* Need a block to allocate .gdbinfo. in */
2752 SYMBOL_BLOCK_VALUE(s
) = b
;
2753 BLOCK_START(b
) = sigtramp_address
;
2754 BLOCK_END(b
) = sigtramp_end
;
2755 BLOCK_FUNCTION(b
) = s
;
2756 BLOCK_SUPERBLOCK(b
) = BLOCK_SUPERBLOCK(b0
);
2760 /* Make a .gdbinfo. for it */
2762 struct mips_extra_func_info
*e
=
2763 (struct mips_extra_func_info
*)
2764 xzalloc(sizeof(struct mips_extra_func_info
));
2766 e
->numargs
= 0; /* the kernel thinks otherwise */
2767 /* align_longword(sigcontext + SIGFRAME) */
2768 e
->framesize
= 0x150;
2769 e
->framereg
= SP_REGNUM
;
2772 e
->regoffset
= -(41 * sizeof(int));
2774 e
->fregoffset
= -(37 * sizeof(int));
2777 s
= new_symbol(".gdbinfo.");
2778 SYMBOL_VALUE(s
) = (int) e
;
2779 SYMBOL_NAMESPACE(s
) = LABEL_NAMESPACE
;
2780 SYMBOL_CLASS(s
) = LOC_CONST
;
2781 SYMBOL_TYPE(s
) = builtin_type_void
;
2784 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
2787 /* Initialization */
2789 static struct sym_fns ecoff_sym_fns
= {"ecoff", 5,
2790 mipscoff_new_init
, mipscoff_symfile_init
,
2791 mipscoff_symfile_read
};
2793 _initialize_mipsread ()
2795 add_symtab_fns (&ecoff_sym_fns
);
2797 /* Missing basic types */
2798 builtin_type_string
= make_type(TYPE_CODE_PASCAL_ARRAY
,
2800 builtin_type_complex
= make_type(TYPE_CODE_FLT
,
2801 2 * sizeof(float), 0, "complex");
2802 builtin_type_double_complex
= make_type(TYPE_CODE_FLT
,
2803 2 * sizeof(double), 0, "double_complex");
2804 builtin_type_fixed_dec
= make_type(TYPE_CODE_INT
, sizeof(int),
2805 0, "fixed_decimal");
2806 builtin_type_float_dec
= make_type(TYPE_CODE_FLT
, sizeof(double),
2807 0, "floating_decimal");
2809 /* Templates types */
2810 builtin_type_struct
= make_type(TYPE_CODE_STRUCT
, 0, 0, 0);
2811 builtin_type_union
= make_type(TYPE_CODE_UNION
, 0, 0, 0);
2812 builtin_type_enum
= make_type(TYPE_CODE_ENUM
, 0, 0, 0);
2813 builtin_type_range
= make_type(TYPE_CODE_RANGE
, 0, 0, 0);
2814 builtin_type_set
= make_type(TYPE_CODE_SET
, 0, 0, 0);
2816 /* We can't do this now because builtin_type_void may not
2817 be set yet. Do it at symbol reading time. */
2818 /* builtin_type_ptr = lookup_pointer_type (builtin_type_void); */