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 /* Things we import explicitly from other modules */
62 extern int info_verbose
;
63 extern struct block
*block_for_pc();
64 extern void sort_symtab_syms();
66 /* Various complaints about symbol reading that don't abort the process */
68 struct complaint unknown_ext_complaint
=
69 {"unknown external symbol %s", 0, 0};
71 struct complaint unknown_sym_complaint
=
72 {"unknown local symbol %s", 0, 0};
74 struct complaint unknown_st_complaint
=
75 {"with type %d", 0, 0};
77 struct complaint block_overflow_complaint
=
78 {"block containing %s overfilled", 0, 0};
80 struct complaint basic_type_complaint
=
81 {"cannot map MIPS basic type 0x%x", 0, 0};
83 struct complaint unknown_type_qual_complaint
=
84 {"unknown type qualifier 0x%x", 0, 0};
86 struct complaint array_bitsize_complaint
=
87 {"size of array target type not known, assuming %d bits", 0, 0};
89 struct complaint array_parse_complaint
=
90 {"array type with strange relative symbol", 0, 0};
92 /* Macros and extra defs */
94 /* Already-parsed symbols are marked specially */
96 #define stParsed stType
98 /* Puns: hard to find whether -g was used and how */
100 #define MIN_GLEVEL GLEVEL_0
101 #define compare_glevel(a,b) \
102 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
103 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
105 /* When looking at .o files, avoid tripping over bad addresses */
107 #define SAFE_TEXT_ADDR 0x400000
108 #define SAFE_DATA_ADDR 0x10000000
110 #define UNSAFE_DATA_ADDR(p) ((unsigned)p < SAFE_DATA_ADDR || (unsigned)p > 2*SAFE_DATA_ADDR)
112 /* Things that really are local to this module */
114 /* GDB symtable for the current compilation unit */
116 static struct symtab
*cur_stab
;
118 /* MIPS symtab header for the current file */
120 static HDRR
*cur_hdr
;
122 /* Pointer to current file decriptor record, and its index */
127 /* Index of current symbol */
131 /* Note how much "debuggable" this image is. We would like
132 to see at least one FDR with full symbols */
137 /* When examining .o files, report on undefined symbols */
139 static int n_undef_symbols
, n_undef_labels
, n_undef_vars
, n_undef_procs
;
141 /* Extra builtin types */
143 struct type
*builtin_type_complex
;
144 struct type
*builtin_type_double_complex
;
145 struct type
*builtin_type_fixed_dec
;
146 struct type
*builtin_type_float_dec
;
147 struct type
*builtin_type_string
;
151 static struct type
*builtin_type_ptr
;
152 static struct type
*builtin_type_struct
;
153 static struct type
*builtin_type_union
;
154 static struct type
*builtin_type_enum
;
155 static struct type
*builtin_type_range
;
156 static struct type
*builtin_type_set
;
158 /* Forward declarations */
160 static struct symbol
*new_symbol();
161 static struct type
*new_type();
162 static struct field
*new_field();
163 static struct block
*new_block();
164 static struct symtab
*new_symtab();
165 static struct linetable
*new_linetable();
166 static struct blockvector
*new_bvect();
168 static struct type
*parse_type();
169 static struct type
*make_type();
170 static struct symbol
*mylookup_symbol();
171 static struct block
*shrink_block();
173 static int compare_symtabs();
174 static int compare_psymtabs();
175 static int compare_blocks();
177 static struct partial_symtab
*new_psymtab();
178 static struct partial_symtab
*parse_fdr();
179 static int compare_psymbols();
181 static void psymtab_to_symtab_1();
182 static void add_block();
183 static void add_symbol();
184 static int add_line();
185 static void reorder_symtabs();
186 static void reorder_psymtabs();
187 static void shrink_linetable();
189 /* Things we export to other modules */
191 /* Address bounds for the signal trampoline in inferior, if any */
192 /* FIXME: Nothing really seems to use this. Why is it here? */
194 CORE_ADDR sigtramp_address
, sigtramp_end
;
196 /* The entry point (starting address) of the file, if it is an executable. */
198 static CORE_ADDR entry_point
;
200 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
201 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
206 /* If we have a file symbol header lying around, blow it away. */
208 free ((char *)cur_hdr
);
213 mipscoff_symfile_init (sf
)
216 bfd
*abfd
= sf
->sym_bfd
;
217 sf
->sym_private
= NULL
;
219 /* Save startup file's range of PC addresses to help blockframe.c
220 decide where the bottom of the stack is. */
221 if (bfd_get_file_flags (abfd
) & EXEC_P
)
223 /* Executable file -- record its entry point so we'll recognize
224 the startup file because it contains the entry point. */
225 entry_point
= bfd_get_start_address (abfd
);
229 /* Examination of non-executable.o files. Short-circuit this stuff. */
230 /* ~0 will not be in any file, we hope. */
232 /* set the startup file to be an empty range. */
233 startup_file_start
= 0;
234 startup_file_end
= 0;
239 mipscoff_symfile_read(sf
, addr
, mainline
)
244 struct coff_symfile_info
*info
= (struct coff_symfile_info
*)sf
->sym_private
;
245 bfd
*abfd
= sf
->sym_bfd
;
246 char *name
= bfd_get_filename (abfd
);
250 int stringtab_offset
;
252 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
253 desc
= fileno ((FILE *)(abfd
->iostream
)); /* Raw file descriptor */
256 /* Position to read the symbol table. */
257 val
= lseek (desc
, (long)symtab_offset
, 0);
259 perror_with_name (name
);
261 init_misc_bunches ();
262 make_cleanup (discard_misc_bunches
, 0);
264 /* Now that the executable file is positioned at symbol table,
265 process it and define symbols accordingly. */
267 read_mips_symtab(abfd
, desc
);
269 /* Go over the misc symbol bunches and install them in vector. */
271 condense_misc_bunches (!mainline
);
274 /* Exported procedure: Allocate zeroed memory */
278 char *p
= xmalloc(size
);
284 /* Exported procedure: Builds a symtab from the PST partial one.
285 Restores the environment in effect when PST was created, delegates
286 most of the work to an ancillary procedure, and sorts
287 and reorders the symtab list at the end */
290 mipscoff_psymtab_to_symtab(pst
)
291 struct partial_symtab
*pst
;
300 printf_filtered("Reading in symbols for %s...", pst
->filename
);
303 /* Restore the header and list of pending typedefs */
304 /* FIXME, we should use private data that is a proper pointer. */
305 cur_hdr
= (HDRR
*) pst
->ldsymlen
;
307 psymtab_to_symtab_1(pst
, pst
->filename
);
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 bcopy(&st_hdr
, cur_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", symfile
);
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
;
439 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
440 sh
= (SYMR
*)(hdr
->cbSymOffset
) + fh
->isymBase
+ s_idx
;
441 sh
->iss
= (long) sh
->iss
+ fh
->issBase
;
448 fh
->isymBase
= (int)((SYMR
*)(hdr
->cbSymOffset
)+fh
->isymBase
);
450 /* cannot fix fh->ipdFirst because it is a short */
451 #define IPDFIRST(h,fh) \
452 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
454 /* Optional symbols (actually used for partial_symtabs) */
460 fh
->iauxBase
= hdr
->cbAuxOffset
+ fh
->iauxBase
* sizeof(AUXU
);
461 /* Relative file descriptor table */
462 fh
->rfdBase
= hdr
->cbRfdOffset
+ fh
->rfdBase
* sizeof(RFDT
);
466 fh
->cbLineOffset
+= hdr
->cbLineOffset
;
468 /* Procedure symbols. (XXX This should be done later) */
469 code_offset
= fh
->adr
;
470 for (s_idx
= 0; s_idx
< fh
->cpd
; s_idx
++) {
471 unsigned name
, only_ext
;
473 pr
= (PDR
*)(IPDFIRST(hdr
,fh
)) + s_idx
;
475 /* Simple rule to find files linked "-x" */
476 only_ext
= fh
->rss
== -1;
478 if (pr
->isym
== -1) {
479 /* static function */
483 name
= hdr
->cbExtOffset
+ pr
->isym
* sizeof(EXTR
);
484 sh
= &((EXTR
*)name
)->asym
;
488 sh
= (SYMR
*)fh
->isymBase
+ pr
->isym
;
489 /* Included code ? */
490 if (s_idx
== 0 && pr
->adr
!= 0)
491 code_offset
-= pr
->adr
;
494 /* Turn index into a pointer */
497 /* Fix line numbers */
498 pr
->cbLineOffset
+= fh
->cbLineOffset
;
500 /* Relocate address */
502 pr
->adr
+= code_offset
;
506 /* External symbols: fix string */
507 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
508 esh
= (EXTR
*)(hdr
->cbExtOffset
) + s_idx
;
509 esh
->asym
.iss
= esh
->asym
.iss
+ hdr
->cbSsExtOffset
;
514 /* Find a file descriptor given its index RF relative to a file CF */
522 f
= (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
523 /* Object files do not have the RFD table, all refs are absolute */
525 return (FDR
*) (cur_hdr
->cbFdOffset
) + rf
;
526 cf
= *((pRFDT
) f
->rfdBase
+ rf
);
527 return (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
530 /* Return a safer print NAME for a file descriptor */
536 if (name
== (char *) -1)
537 return "<stripped file>";
538 if (UNSAFE_DATA_ADDR(name
))
544 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
545 whether we are adding to the general symtab or not.
546 FIXME: INCREMENTAL is currently always zero, though it should not be. */
549 read_mips_symtab (abfd
, desc
)
553 CORE_ADDR end_of_text_seg
;
555 read_the_mips_symtab(abfd
, desc
, &end_of_text_seg
);
557 parse_partial_symbols(end_of_text_seg
);
560 * Check to make sure file was compiled with -g.
561 * If not, warn the user of this limitation.
563 if (compare_glevel(max_glevel
, GLEVEL_2
) < 0) {
564 if (max_gdbinfo
== 0)
565 printf("\n%s not compiled with -g, debugging support is limited.", symfile
);
566 printf("\nYou should compile with -g2 or -g3 for best debugging support.\n");
571 /* Local utilities */
573 /* Map of FDR indexes to partial symtabs */
575 static struct pst_map
{
576 struct partial_symtab
*pst
; /* the psymtab proper */
577 int n_globals
; /* globals it exports */
578 int n_statics
; /* statics (locals) it contains */
582 /* Utility stack, used to nest procedures and blocks properly.
583 It is a doubly linked list, to avoid too many alloc/free.
584 Since we might need it quite a few times it is NOT deallocated
587 static struct parse_stack
{
588 struct parse_stack
*next
, *prev
;
589 struct symtab
*cur_st
; /* Current symtab */
590 struct block
*cur_block
; /* Block in it */
591 int blocktype
; /* What are we parsing */
592 int maxsyms
; /* Max symbols in this block */
593 struct type
*cur_type
; /* Type we parse fields for */
594 int procadr
; /* Start addres of this procedure */
595 int numargs
; /* Its argument count */
596 } *top_stack
; /* Top stack ptr */
599 /* Enter a new lexical context */
601 static push_parse_stack()
603 struct parse_stack
*new;
605 /* Reuse frames if possible */
606 if (top_stack
&& top_stack
->prev
)
607 new = top_stack
->prev
;
609 new = (struct parse_stack
*) xzalloc(sizeof(struct parse_stack
));
610 /* Initialize new frame with previous content */
612 register struct parse_stack
*prev
= new->prev
;
615 top_stack
->prev
= new;
617 new->next
= top_stack
;
622 /* Exit a lexical context */
624 static pop_parse_stack()
629 top_stack
= top_stack
->next
;
633 /* Cross-references might be to things we haven't looked at
634 yet, e.g. type references. To avoid too many type
635 duplications we keep a quick fixup table, an array
636 of lists of references indexed by file descriptor */
638 static struct pending
{
639 struct pending
*next
; /* link */
640 SYMR
*s
; /* the symbol */
641 struct type
*t
; /* its partial type descriptor */
645 /* Check whether we already saw symbol SH in file FH as undefined */
648 struct pending
*is_pending_symbol(fh
, sh
)
652 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
653 register struct pending
*p
;
655 /* Linear search is ok, list is typically no more than 10 deep */
656 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
662 /* Check whether we already saw type T in file FH as undefined */
665 struct pending
*is_pending_type(fh
, t
)
669 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
670 register struct pending
*p
;
672 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
678 /* Add a new undef symbol SH of type T */
681 add_pending(fh
, sh
, t
)
686 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
687 struct pending
*p
= is_pending_symbol(fh
, sh
);
689 /* Make sure we do not make duplicates */
691 p
= (struct pending
*) xmalloc(sizeof(*p
));
694 p
->next
= pending_list
[f_idx
];
695 pending_list
[f_idx
] = p
;
697 sh
->reserved
= 1; /* for quick check */
700 /* Throw away undef entries when done with file index F_IDX */
705 register struct pending
*p
, *q
;
707 for (p
= pending_list
[f_idx
]; p
; p
= q
) {
711 pending_list
[f_idx
] = 0;
714 /* The number of args to a procedure is not explicit in the symtab,
715 this is the list of all those we know of.
716 This makes parsing more reasonable and avoids extra passes */
718 static struct numarg
{
719 struct numarg
*next
; /* link */
720 unsigned adr
; /* procedure's start address */
721 unsigned num
; /* arg count */
724 /* Record that the procedure at ADR takes NUM arguments. */
729 struct numarg
*n
= (struct numarg
*) xmalloc(sizeof(struct numarg
));
733 n
->next
= numargs_list
;
737 /* See if we know how many arguments the procedure at ADR takes */
742 struct numarg
*n
= numargs_list
;
744 while (n
&& n
->adr
!= adr
)
746 return (n
) ? n
->num
: -1;
749 /* Release storage when done with this file */
754 struct numarg
*n
= numargs_list
, *m
;
765 /* Parsing Routines proper. */
767 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
768 For blocks, procedures and types we open a new lexical context.
769 This is basically just a big switch on the symbol's type */
780 /* When a symbol is cross-referenced from other files/symbols
781 we mark it explicitly */
782 int pend
= (sh
->reserved
== 1);
783 enum address_class
class;
790 case stGlobal
: /* external symbol, goes into global block */
792 b
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
794 s
= new_symbol(sh
->iss
);
795 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
798 case stStatic
: /* static data, goes into current block. */
800 b
= top_stack
->cur_block
;
801 s
= new_symbol(sh
->iss
);
802 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
805 case stLocal
: /* local variable, goes into current block */
806 if (sh
->sc
== scRegister
) {
807 class = LOC_REGISTER
;
812 b
= top_stack
->cur_block
;
813 s
= new_symbol(sh
->iss
);
814 SYMBOL_VALUE(s
) = sh
->value
;
816 data
: /* Common code for symbols describing data */
817 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
818 SYMBOL_CLASS(s
) = class;
821 /* Type could be missing in a number of cases */
822 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
823 sh
->index
== 0xfffff)
824 SYMBOL_TYPE(s
) = builtin_type_int
; /* undefined? */
826 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
827 /* Value of a data symbol is its memory address */
830 case stParam
: /* arg to procedure, goes into current block */
832 top_stack
->numargs
++;
833 s
= new_symbol(sh
->iss
);
834 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
835 if (sh
->sc
== scRegister
) {
836 SYMBOL_CLASS(s
) = LOC_REGPARM
;
840 SYMBOL_CLASS(s
) = LOC_ARG
;
841 SYMBOL_VALUE(s
) = sh
->value
;
842 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
843 add_symbol(s
, top_stack
->cur_block
);
846 case stLabel
: /* label, goes into current block */
847 s
= new_symbol(sh
->iss
);
848 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
; /* so that it can be used */
849 SYMBOL_CLASS(s
) = LOC_LABEL
; /* but not misused */
850 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
851 SYMBOL_TYPE(s
) = builtin_type_int
;
852 add_symbol(s
, top_stack
->cur_block
);
855 case stProc
: /* Procedure, goes into current block? FIXME */
856 case stStaticProc
: /* Static procedure, goes into current block */
857 s
= new_symbol(sh
->iss
);
858 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
859 SYMBOL_CLASS(s
) = LOC_BLOCK
;
860 /* Type of the return value */
861 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
862 t
= builtin_type_int
;
864 t
= parse_type(ax
+ sh
->index
, sh
, 0);
865 add_symbol(s
, top_stack
->cur_block
);
867 /* Make a type for the procedure itself */
868 SYMBOL_TYPE(s
) = lookup_function_type (t
);
870 /* Create and enter a new lexical context */
871 b
= new_block(top_stack
->maxsyms
);
872 SYMBOL_BLOCK_VALUE(s
) = b
;
873 BLOCK_FUNCTION(b
) = s
;
874 BLOCK_START(b
) = BLOCK_END(b
) = sh
->value
;
875 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
876 add_block(b
, top_stack
->cur_st
);
878 /* Not if we only have partial info */
879 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
883 top_stack
->cur_block
= b
;
884 top_stack
->blocktype
= sh
->st
;
885 top_stack
->cur_type
= SYMBOL_TYPE(s
);
886 top_stack
->procadr
= sh
->value
;
887 top_stack
->numargs
= 0;
889 sh
->value
= (long) SYMBOL_TYPE(s
);
892 case stBlock
: /* Either a lexical block, or some type */
894 top_stack
->blocktype
= stBlock
;
895 if (sh
->sc
== scInfo
) { /* structure/union/enum def */
896 s
= new_symbol(sh
->iss
);
897 SYMBOL_NAMESPACE(s
) = STRUCT_NAMESPACE
;
898 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
900 add_symbol(s
, top_stack
->cur_block
);
901 /* If this type was expected, use its partial definition */
903 t
= is_pending_symbol(cur_fdr
, sh
)->t
;
905 /* Uhmm, can`t decide yet. Smash later */
906 t
= new_type(sh
->iss
);
907 TYPE_CODE(t
) = TYPE_CODE_UNDEF
;
908 add_pending(cur_fdr
, sh
, t
);
911 /* make this the current type */
912 top_stack
->cur_type
= t
;
913 TYPE_LENGTH(t
) = sh
->value
;
914 /* Mark that symbol has a type, and say which one */
915 sh
->value
= (long) t
;
917 /* beginnning of (code) block. Value of symbol
918 is the displacement from procedure start */
919 b
= new_block(top_stack
->maxsyms
);
920 BLOCK_START(b
) = sh
->value
+ top_stack
->procadr
;
921 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
922 top_stack
->cur_block
= b
;
923 add_block(b
, top_stack
->cur_st
);
927 case stEnd
: /* end (of anything) */
928 if (sh
->sc
== scInfo
) {
929 /* Finished with type */
930 top_stack
->cur_type
= 0;
931 } else if (sh
->sc
== scText
&&
932 (top_stack
->blocktype
== stProc
||
933 top_stack
->blocktype
== stStaticProc
)) {
934 /* Finished with procedure */
935 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
939 BLOCK_END(top_stack
->cur_block
) += sh
->value
; /* size */
940 got_numargs(top_stack
->procadr
, top_stack
->numargs
);
941 /* Reallocate symbols, saving memory */
942 b
= shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
944 /* f77 emits proc-level with address bounds==[0,0],
945 So look for such child blocks, and patch them. */
946 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++) {
947 struct block
*b_bad
= BLOCKVECTOR_BLOCK(bv
,i
);
948 if (BLOCK_SUPERBLOCK(b_bad
) == b
949 && BLOCK_START(b_bad
) == top_stack
->procadr
950 && BLOCK_END(b_bad
) == top_stack
->procadr
) {
951 BLOCK_START(b_bad
) = BLOCK_START(b
);
952 BLOCK_END(b_bad
) = BLOCK_END(b
);
955 if (entry_point
< BLOCK_END(b
)
956 && entry_point
>= BLOCK_START(b
)) {
957 startup_file_start
= BLOCK_START(b
);
958 startup_file_end
= BLOCK_END(b
);
960 } else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
) {
961 /* End of (code) block. The value of the symbol
962 is the displacement from the procedure`s start
963 address of the end of this block. */
964 BLOCK_END(top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
965 (void) shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
967 pop_parse_stack(); /* restore previous lexical context */
970 case stMember
: /* member of struct/union/enum.. */
971 f
= new_field(top_stack
->cur_type
, sh
->iss
);
972 f
->bitpos
= sh
->value
;
973 f
->type
= parse_type(ax
+ sh
->index
, sh
, &f
->bitsize
);
976 case stTypedef
: /* type definition */
977 s
= new_symbol(sh
->iss
);
978 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
979 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
980 SYMBOL_BLOCK_VALUE(s
) = top_stack
->cur_block
;
981 add_symbol(s
, top_stack
->cur_block
);
982 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
983 sh
->value
= (long) SYMBOL_TYPE(s
);
986 case stFile
: /* file name */
988 top_stack
->blocktype
= sh
->st
;
991 /* I`ve never seen these for C */
993 break; /* register relocation */
995 break; /* forwarding address */
997 break; /* constant */
999 error("Unknown symbol type %x.", sh
->st
);
1004 /* Parse the type information provided in the AX entries for
1005 the symbol SH. Return the bitfield size in BS, in case. */
1007 static struct type
*parse_type(ax
, sh
, bs
)
1012 /* Null entries in this map are treated specially */
1013 static struct type
**map_bt
[] =
1015 &builtin_type_void
, /* btNil */
1017 &builtin_type_char
, /* btChar */
1018 &builtin_type_unsigned_char
, /* btUChar */
1019 &builtin_type_short
, /* btShort */
1020 &builtin_type_unsigned_short
, /* btUShort */
1021 &builtin_type_int
, /* btInt */
1022 &builtin_type_unsigned_int
, /* btUInt */
1023 &builtin_type_long
, /* btLong */
1024 &builtin_type_unsigned_long
, /* btULong */
1025 &builtin_type_float
, /* btFloat */
1026 &builtin_type_double
, /* btDouble */
1033 &builtin_type_complex
, /* btComplex */
1034 &builtin_type_double_complex
, /* btDComplex */
1036 &builtin_type_fixed_dec
, /* btFixedDec */
1037 &builtin_type_float_dec
, /* btFloatDec */
1038 &builtin_type_string
, /* btString */
1041 &builtin_type_void
, /* btVoid */
1045 struct type
*tp
= 0, *tp1
;
1048 /* Procedures start off by one */
1049 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
)
1052 /* Undefined ? Should not happen */
1053 if (ax
->rndx
.rfd
== 0xfff) {
1054 return builtin_type_void
;
1057 /* Use aux as a type information record, map its basic type */
1059 if (t
->bt
> 26 || t
->bt
== btPicture
) {
1060 complain (&basic_type_complaint
, t
->bt
);
1061 return builtin_type_int
;
1064 tp
= *map_bt
[t
->bt
];
1066 /* Cannot use builtin types, use templates */
1067 tp
= make_type(TYPE_CODE_VOID
, 0, 0, 0);
1070 *tp
= *builtin_type_ptr
;
1073 *tp
= *builtin_type_struct
;
1077 *tp
= *builtin_type_union
;
1081 *tp
= *builtin_type_enum
;
1085 *tp
= *builtin_type_range
;
1088 *tp
= *builtin_type_set
;
1094 /* Move on to next aux */
1097 /* This is the way it would work if the compiler worked */
1098 register TIR
*t1
= t
;
1099 while (t1
->continued
)
1103 /* For bitfields all we need is the width */
1109 /* All these types really point to some (common) MIPS type
1110 definition, and only the type-qualifiers fully identify
1111 them. We`ll make the same effort at sharing */
1112 if (t
->bt
== btIndirect
||
1113 t
->bt
== btStruct
||
1116 t
->bt
== btTypedef
||
1119 char name
[256], *pn
;
1121 /* Try to cross reference this type */
1123 ax
+= cross_ref(ax
, &tp1
, &pn
);
1124 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1125 sprintf(name
, fmt
, pn
);
1127 /* reading .o file ? */
1128 if (UNSAFE_DATA_ADDR(tp1
))
1130 if (TYPE_CODE(tp1
) == TYPE_CODE_UNDEF
) {
1132 * Type was incompletely defined, now we know.
1134 TYPE_CODE(tp1
) = TYPE_CODE(tp
);
1135 TYPE_NAME(tp1
) = obsavestring(name
, strlen(name
));
1136 if (TYPE_CODE(tp1
) == TYPE_CODE_ENUM
) {
1139 for (i
= 0; i
< TYPE_NFIELDS(tp1
); i
++)
1140 make_enum_constant(&TYPE_FIELD(tp1
,i
), tp1
);
1144 /* found as cross ref, rid of our template */
1145 if ((TYPE_FLAGS(tp
) & TYPE_FLAG_PERM
) == 0)
1148 /* stupid idea of prepending "struct" to type names */
1149 if (t
->bt
== btStruct
&& !index(TYPE_NAME(tp
), ' ')) {
1150 sprintf(name
, fmt
, TYPE_NAME(tp
));
1151 TYPE_NAME(tp
) = obsavestring(name
, strlen(name
));
1154 TYPE_NAME(tp
) = savestring(name
, strlen(name
));
1157 /* Deal with range types */
1158 if (t
->bt
== btRange
) {
1161 f
= new_field(tp
, "Low");
1162 f
->bitpos
= ax
->dnLow
;
1164 f
= new_field(tp
, "High");
1165 f
->bitpos
= ax
->dnHigh
;
1169 /* Parse all the type qualifiers now. If there are more
1170 than 6 the game will continue in the next aux */
1172 #define PARSE_TQ(tq) \
1173 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, sh);
1175 again
: PARSE_TQ(tq0
);
1190 /* Make up a complex type from a basic one. Type is passed by
1191 reference in TPP and side-effected as necessary. The type
1192 qualifier TQ says how to handle the aux symbols at AX for
1193 the symbol SX we are currently analyzing.
1194 Returns the number of aux symbols we parsed. */
1197 upgrade_type(tpp
, tq
, ax
, sh
)
1205 /* Used in array processing */
1214 t
= lookup_pointer_type (*tpp
);
1219 t
= lookup_function_type (*tpp
);
1225 t
= make_type(TYPE_CODE_ARRAY
, 0, 0, 0);
1226 TYPE_TARGET_TYPE(t
) = *tpp
;
1228 /* Determine and record the domain type (type of index) */
1229 id
= ax
->rndx
.index
;
1235 fh
= get_rfd(cur_fd
, rf
);
1236 f
= new_field(t
, (char *)0);
1237 bzero(&ss
, sizeof ss
);
1238 /* XXX */ f
->type
= parse_type(fh
->iauxBase
+ id
* sizeof(AUXU
),
1243 * This seems to be a pointer to the end of the Block defining
1244 * the type. Why it is here is magic for me, and I have no
1245 * good use for it anyways.
1247 /* This used to occur because cross_ref returned
1248 the wrong result (ax pointed wrong). FIXME,
1249 delete this code in a while. -- gnu@cygnus jul91 */
1250 complain (&array_parse_complaint
, 0);
1252 id
= (++ax
)->rndx
.index
;
1253 if ((rf
= ax
->rndx
.rfd
) == 0xfff)
1254 rf
= (++ax
)->isym
, off
++;
1256 lower
= (++ax
)->dnLow
;
1257 upper
= (++ax
)->dnHigh
;
1258 rf
= (++ax
)->width
; /* bit size of array element */
1260 /* Check whether supplied array element bit size matches
1261 the known size of the element type. If this complaint
1262 ends up not happening, we can remove this code. It's
1263 here because we aren't sure we understand this *&%&$
1265 id
= TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) << 3; /* bitsize */
1267 /* Most likely an undefined type */
1269 TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) = id
>> 3;
1272 complain (&array_bitsize_complaint
, rf
);
1274 TYPE_LENGTH(t
) = (upper
< 0) ? 0 :
1275 (upper
- lower
+ 1) * (rf
>> 3);
1280 /* Volatile -- currently ignored */
1284 complain (&unknown_type_qual_complaint
, tq
);
1290 /* Parse a procedure descriptor record PR. Note that the procedure
1291 is parsed _after_ the local symbols, now we just make up the
1292 extra information we need into a special symbol that we insert
1293 in the procedure's main block. Note also that images that
1294 have been partially stripped (ld -x) have been deprived
1295 of local symbols, and we have to cope with them here.
1296 The procedure's code ends at BOUND */
1299 parse_procedure(pr
, bound
)
1302 struct symbol
*s
, *i
;
1303 SYMR
*sh
= (SYMR
*)pr
->isym
;
1305 struct mips_extra_func_info
*e
;
1309 /* Reuse the MIPS record */
1310 e
= (struct mips_extra_func_info
*) pr
;
1311 e
->numargs
= lookup_numargs(pr
->adr
);
1313 /* Make up our special symbol */
1314 i
= new_symbol(".gdbinfo.");
1315 SYMBOL_VALUE(i
) = (int)e
;
1316 SYMBOL_NAMESPACE(i
) = LABEL_NAMESPACE
;
1317 SYMBOL_CLASS(i
) = LOC_CONST
;
1318 SYMBOL_TYPE(i
) = builtin_type_void
;
1320 /* Make up a name for static procedures. Sigh. */
1321 if (sh
== (SYMR
*)-1) {
1322 sprintf(name
,".static_procedure@%x",pr
->adr
);
1323 sh_name
= savestring(name
, strlen(name
));
1327 sh_name
= (char*)sh
->iss
;
1328 s
= mylookup_symbol(sh_name
, top_stack
->cur_block
,
1329 VAR_NAMESPACE
, LOC_BLOCK
);
1332 b
= SYMBOL_BLOCK_VALUE(s
);
1334 s
= new_symbol(sh_name
);
1335 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1336 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1337 /* Donno its type, hope int is ok */
1338 SYMBOL_TYPE(s
) = lookup_function_type (builtin_type_int
);
1339 add_symbol(s
, top_stack
->cur_block
);
1340 /* Wont have symbols for this one */
1342 SYMBOL_BLOCK_VALUE(s
) = b
;
1343 BLOCK_FUNCTION(b
) = s
;
1344 BLOCK_START(b
) = pr
->adr
;
1345 BLOCK_END(b
) = bound
;
1346 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1347 add_block(b
, top_stack
->cur_st
);
1353 /* Parse the external symbol ES. Just call parse_symbol() after
1354 making sure we know where the aux are for it. For procedures,
1355 parsing of the PDRs has already provided all the needed
1356 information, we only parse them if SKIP_PROCEDURES is false,
1357 and only if this causes no symbol duplication.
1359 This routine clobbers top_stack->cur_block and ->cur_st. */
1362 parse_external(es
, skip_procedures
)
1367 if (es
->ifd
!= ifdNil
) {
1369 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
) + cur_fd
;
1370 ax
= (AUXU
*)cur_fdr
->iauxBase
;
1372 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
);
1375 top_stack
->cur_st
= cur_stab
;
1376 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
1379 /* Reading .o files */
1380 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
) {
1382 switch (es
->asym
.st
) {
1384 case stProc
: what
= "procedure"; n_undef_procs
++; break;
1385 case stGlobal
: what
= "variable"; n_undef_vars
++; break;
1386 case stLabel
: what
= "label"; n_undef_labels
++; break;
1387 default : what
= "symbol"; break;
1391 printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what
,
1392 es
->asym
.iss
, fdr_name(cur_fdr
->rss
));
1396 switch (es
->asym
.st
) {
1398 /* If we have full symbols we do not need more */
1399 if (skip_procedures
)
1401 if (mylookup_symbol (es
->asym
.iss
, top_stack
->cur_block
,
1402 VAR_NAMESPACE
, LOC_BLOCK
))
1408 * Note that the case of a symbol with indexNil
1409 * must be handled anyways by parse_symbol().
1411 parse_symbol(&es
->asym
, ax
);
1418 /* Parse the line number info for file descriptor FH into
1419 GDB's linetable LT. MIPS' encoding requires a little bit
1420 of magic to get things out. Note also that MIPS' line
1421 numbers can go back and forth, apparently we can live
1422 with that and do not need to reorder our linetables */
1427 struct linetable
*lt
;
1429 unsigned char *base
= (unsigned char*)fh
->cbLineOffset
;
1431 int delta
, count
, lineno
= 0;
1437 /* Scan by procedure descriptors */
1438 i
= 0; j
= 0, k
= 0;
1439 for (pr
= (PDR
*)IPDFIRST(cur_hdr
,fh
); j
< fh
->cpd
; j
++, pr
++) {
1442 /* No code for this one */
1443 if (pr
->iline
== ilineNil
||
1444 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1447 * Aurgh! To know where to stop expanding we
1450 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1451 if (pr
[l
].iline
!= -1)
1453 if (l
== (fh
->cpd
- j
))
1458 * When procedures are moved around the linenumbers
1459 * are attributed to the next procedure up
1461 if (pr
->iline
>= halt
) continue;
1463 base
= (unsigned char*)pr
->cbLineOffset
;
1464 l
= pr
->adr
>> 2; /* in words */
1465 halt
+= (pr
->adr
>> 2) - pr
->iline
;
1466 for (lineno
= pr
->lnLow
; l
< halt
;) {
1467 count
= *base
& 0x0f;
1468 delta
= *base
++ >> 4;
1472 delta
= (base
[0] << 8) | base
[1];
1475 lineno
+= delta
;/* first delta is 0 */
1476 k
= add_line(lt
, lineno
, l
, k
);
1483 /* Parse the symbols of the file described by FH, whose index is F_IDX.
1484 BOUND is the highest core address of this file's procedures */
1487 parse_one_file(fh
, f_idx
, bound
)
1494 /* Parse local symbols first */
1496 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
1497 sh
= (SYMR
*) (fh
->isymBase
) + s_idx
;
1499 parse_symbol(sh
, fh
->iauxBase
);
1502 /* Procedures next, note we need to look-ahead to
1503 find out where the procedure's code ends */
1505 for (s_idx
= 0; s_idx
< fh
->cpd
-1; s_idx
++) {
1506 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + s_idx
;
1507 parse_procedure(pr
, pr
[1].adr
); /* next proc up */
1510 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + s_idx
;
1511 parse_procedure(pr
, bound
); /* next file up */
1514 /* Linenumbers. At the end, check if we can save memory */
1515 parse_lines(fh
, LINETABLE(cur_stab
));
1516 if (LINETABLE(cur_stab
)->nitems
< fh
->cline
)
1517 shrink_linetable(cur_stab
);
1520 /* Master parsing procedure for first-pass reading of file symbols
1521 into a partial_symtab.
1523 Parses the symtab described by the global symbolic header CUR_HDR.
1524 END_OF_TEXT_SEG gives the address just after the text segment for
1525 the symtab we are reading. */
1528 parse_partial_symbols(end_of_text_seg
)
1529 int end_of_text_seg
;
1531 int f_idx
, s_idx
, h_max
, stat_idx
;
1532 CORE_ADDR dummy
, *prevhigh
;
1534 /* Running pointers */
1539 struct partial_symtab
*pst
;
1544 * Only parse the Local and External symbols, and the Relative FDR.
1545 * Fixup enough of the loader symtab to be able to use it.
1546 * Allocate space only for the file`s portions we need to
1552 max_glevel
= MIN_GLEVEL
;
1554 /* Allocate the map FDR -> PST.
1555 Minor hack: -O3 images might claim some global data belongs
1556 to FDR -1. We`ll go along with that */
1557 fdr_to_pst
= (struct pst_map
*)xzalloc((hdr
->ifdMax
+1) * sizeof *fdr_to_pst
);
1560 struct partial_symtab
* pst
= new_psymtab("");
1561 fdr_to_pst
[-1].pst
= pst
;
1565 /* Now scan the FDRs, mostly for dependencies */
1566 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++)
1567 (void) parse_fdr(f_idx
, 1);
1569 /* Take a good guess at how many symbols we might ever need */
1570 h_max
= hdr
->iextMax
;
1572 /* Parse externals: two passes because they can be ordered
1573 in any way, but gdb likes to have them segregated by their
1576 /* Pass 1 over external syms: Presize and partition the list */
1577 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1578 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1579 fdr_to_pst
[esh
->ifd
].n_globals
++;
1582 if (global_psymbols
.list
) {
1583 int origsize
= global_psymbols
.next
- global_psymbols
.list
;
1585 global_psymbols
.list
= (struct partial_symbol
*)
1586 xrealloc (global_psymbols
.list
,
1587 (h_max
+ origsize
) * sizeof(struct partial_symbol
));
1588 global_psymbols
.next
= global_psymbols
.list
+ origsize
;
1589 global_psymbols
.size
= h_max
+ origsize
;
1591 global_psymbols
.list
= (struct partial_symbol
*)
1592 xmalloc (h_max
* sizeof(struct partial_symbol
));
1593 global_psymbols
.next
= global_psymbols
.list
;
1594 global_psymbols
.size
= h_max
;
1597 /* Pass 1.5 over files: partition out global symbol space */
1598 s_idx
= global_psymbols
.next
- global_psymbols
.list
;
1599 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++) {
1600 fdr_to_pst
[f_idx
].pst
->globals_offset
= s_idx
;
1601 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
1604 /* Pass 1.6 over files: partition out static symbol space.
1605 Note that this loop starts at 0, not at -1. */
1606 stat_idx
= static_psymbols
.next
- static_psymbols
.list
;
1607 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
1608 fdr_to_pst
[f_idx
].pst
->statics_offset
= stat_idx
;
1609 fh
= f_idx
+ (FDR
*)(hdr
->cbFdOffset
);
1610 stat_idx
+= fh
->csym
;
1613 /* Now that we know its max size, allocate static symbol list */
1614 if (static_psymbols
.list
) {
1615 int origsize
= static_psymbols
.next
- static_psymbols
.list
;
1617 static_psymbols
.list
= (struct partial_symbol
*)
1618 xrealloc (static_psymbols
.list
,
1619 stat_idx
* sizeof(struct partial_symbol
));
1620 static_psymbols
.next
= static_psymbols
.list
+ origsize
;
1621 static_psymbols
.size
= stat_idx
;
1623 static_psymbols
.list
= (struct partial_symbol
*)
1624 xmalloc (stat_idx
* sizeof(struct partial_symbol
));
1625 static_psymbols
.next
= static_psymbols
.list
;
1626 static_psymbols
.size
= stat_idx
;
1629 /* Pass 2 over external syms: fill in external symbols */
1630 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1631 register struct partial_symbol
*p
;
1632 enum misc_function_type misc_type
= mf_text
;
1633 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1635 if (esh
->asym
.sc
== scUndefined
|| esh
->asym
.sc
== scNil
)
1638 /* Locate the psymtab and the preallocated psymbol. */
1639 pst
= fdr_to_pst
[esh
->ifd
].pst
;
1640 p
= global_psymbols
.list
+ pst
->globals_offset
+
1641 pst
->n_global_syms
++;
1642 SYMBOL_NAME(p
) = (char *)(esh
->asym
.iss
);
1643 SYMBOL_NAMESPACE(p
) = VAR_NAMESPACE
;
1645 switch (esh
->asym
.st
) {
1647 SYMBOL_CLASS(p
) = LOC_BLOCK
;
1648 SYMBOL_VALUE(p
) = esh
->asym
.value
;
1651 SYMBOL_CLASS(p
) = LOC_STATIC
;
1652 SYMBOL_VALUE_ADDRESS(p
) = (CORE_ADDR
)esh
->asym
.value
;
1653 misc_type
= mf_data
;
1656 SYMBOL_CLASS(p
) = LOC_LABEL
;
1657 SYMBOL_VALUE_ADDRESS(p
) = (CORE_ADDR
)esh
->asym
.value
;
1660 misc_type
= mf_unknown
;
1661 complain (&unknown_ext_complaint
, SYMBOL_NAME(p
));
1663 prim_record_misc_function (SYMBOL_NAME(p
),
1668 /* Pass 3 over files, over local syms: fill in static symbols */
1669 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
1670 fh
= f_idx
+ (FDR
*)(cur_hdr
->cbFdOffset
);
1671 pst
= fdr_to_pst
[f_idx
].pst
;
1673 for (s_idx
= 0; s_idx
< fh
->csym
; ) {
1674 register struct partial_symbol
*p
;
1676 sh
= s_idx
+ (SYMR
*) fh
->isymBase
;
1678 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
) {
1679 /* FIXME, premature? */
1684 /* Locate the preallocated psymbol. */
1685 p
= static_psymbols
.list
+ pst
->statics_offset
+
1687 SYMBOL_NAME(p
) = (char *)(sh
->iss
);
1688 SYMBOL_VALUE(p
) = sh
->value
;
1689 SYMBOL_NAMESPACE(p
) = VAR_NAMESPACE
;
1692 case stProc
: /* Asm labels apparently */
1693 case stStaticProc
: /* Function */
1694 SYMBOL_CLASS(p
) = LOC_BLOCK
;
1695 pst
->n_static_syms
++; /* Use gdb symbol */
1696 /* Skip over procedure to next one. */
1697 s_idx
= (sh
->index
+ (AUXU
*)fh
->iauxBase
)
1700 case stStatic
: /* Variable */
1701 SYMBOL_CLASS(p
) = LOC_STATIC
;
1702 SYMBOL_VALUE_ADDRESS(p
) = (CORE_ADDR
)sh
->value
;
1704 case stTypedef
: /* Typedef */
1705 SYMBOL_CLASS(p
) = LOC_TYPEDEF
;
1707 case stConstant
: /* Constant decl */
1708 SYMBOL_CLASS(p
) = LOC_CONST
;
1710 case stBlock
: /* { }, str, un, enum */
1711 /* Eventually we want struct names and enum
1712 values out of here. FIXME */
1713 /* Skip over the block */
1716 case stFile
: /* File headers */
1717 case stLabel
: /* Labels */
1718 case stEnd
: /* Ends of files */
1721 complain (&unknown_sym_complaint
, SYMBOL_NAME(p
));
1722 complain (&unknown_st_complaint
, sh
->st
);
1726 pst
->n_static_syms
++; /* Use this gdb symbol */
1728 s_idx
++; /* Go to next file symbol */
1730 /* We don't usually record static syms, but some we seem to. chk dbxread. */
1731 /*FIXME*/ prim_record_misc_function (SYMBOL_NAME(p
),
1738 /* The array (of lists) of globals must be sorted.
1739 Take care, since we are at it, of pst->texthigh.
1741 NOTE: The way we handle textlow/high is incorrect, but good
1742 enough for a first approximation. The case we fail is on a
1743 file "foo.c" that looks like
1745 #include "bar.c" -- this contains proc2()
1747 where proc3() is attributed to bar.c. But since this is a
1748 dependent file it will cause loading of foo.c as well, so
1749 everything will be fine at the end. */
1751 /* First, sort the psymtabs by their textlow addresses. */
1754 /* Now, rip through and fill in "texthigh" from the textlow
1755 of the following psymtab. Slimy but it might work.
1756 Sort the global psymbols while we're at it. */
1758 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
1759 struct partial_symtab
*pst
= fdr_to_pst
[f_idx
].pst
;
1760 if (pst
->n_global_syms
> 1)
1761 qsort (global_psymbols
.list
+ pst
->globals_offset
,
1762 pst
->n_global_syms
, sizeof (struct partial_symbol
),
1765 *prevhigh
= pst
->textlow
;
1766 prevhigh
= &pst
->texthigh
;
1770 /* Mark the last code address, and remember it for later */
1771 *prevhigh
= end_of_text_seg
;
1772 hdr
->cbDnOffset
= end_of_text_seg
;
1774 free(&fdr_to_pst
[-1]);
1779 /* Do the initial analisys of the F_IDX-th file descriptor.
1780 Allocates a partial symtab for it, and builds the list
1781 of dependent files by recursion. LEV says at which level
1782 of recursion we are called (to pretty up debug traces) */
1784 static struct partial_symtab
*
1785 parse_fdr(f_idx
, lev
)
1789 register struct partial_symtab
*pst
;
1792 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + f_idx
;
1794 /* Use this to indicate into which symtab this file was parsed */
1796 return (struct partial_symtab
*) fh
->ioptBase
;
1798 /* Debuggability level */
1799 if (compare_glevel(max_glevel
, fh
->glevel
) < 0)
1800 max_glevel
= fh
->glevel
;
1802 /* Make a new partial_symtab */
1803 pst
= new_psymtab(fh
->rss
);
1808 pst
->textlow
= fh
->adr
;
1809 pst
->texthigh
= fh
->cpd
; /* To be fixed later */
1812 /* Make everything point to everything. */
1813 pst
->ldsymoff
= f_idx
;
1814 fdr_to_pst
[f_idx
].pst
= pst
;
1815 fh
->ioptBase
= (int)pst
;
1817 /* Analyze its dependencies */
1822 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
1823 /* ...then presumably a .h file: drop reverse depends .h->.c */
1824 for (; s_id0
< fh
->crfd
; s_id0
++) {
1825 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
1827 s_id0
++; /* Skip self-dependency */
1832 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
1833 pst
->dependencies
= (struct partial_symtab
**)
1834 obstack_alloc (psymbol_obstack
,
1835 pst
->number_of_dependencies
*
1836 sizeof (struct partial_symtab
*));
1837 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
1838 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
1840 pst
->dependencies
[s_idx
-s_id0
] = parse_fdr(*rh
, lev
+1);
1847 /* Ancillary function to psymtab_to_symtab(). Does all the work
1848 for turning the partial symtab PST into a symtab, recurring
1849 first on all dependent psymtabs. The argument FILENAME is
1850 only passed so we can see in debug stack traces what file
1854 psymtab_to_symtab_1(pst
, filename
)
1855 struct partial_symtab
*pst
;
1866 pending_list
= (struct pending
**) cur_hdr
->cbOptOffset
;
1867 if (pending_list
== 0) {
1868 pending_list
= (struct pending
**)
1869 xzalloc(cur_hdr
->ifdMax
* sizeof(struct pending
*));
1870 cur_hdr
->cbOptOffset
= (int)pending_list
;
1873 /* How many symbols will we need */
1874 /* FIXME, this does not count enum values. */
1875 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
1876 if (pst
->ldsymoff
== -1) {
1878 st
= new_symtab( "unknown", f_max
, 0);
1880 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + pst
->ldsymoff
;
1881 f_max
+= fh
->csym
+ fh
->cpd
;
1882 st
= new_symtab(pst
->filename
, 2 * f_max
, 2 * fh
->cline
);
1885 /* Read in all partial symbtabs on which this one is dependent.
1886 NOTE that we do have circular dependencies, sigh. We solved
1887 that by setting pst->readin before this point. */
1889 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
1890 if (!pst
->dependencies
[i
]->readin
) {
1891 /* Inform about additional files to be read in. */
1894 fputs_filtered (" ", stdout
);
1896 fputs_filtered ("and ", stdout
);
1898 printf_filtered ("%s...",
1899 pst
->dependencies
[i
]->filename
);
1900 wrap_here (""); /* Flush output */
1903 /* We only pass the filename for debug purposes */
1904 psymtab_to_symtab_1(pst
->dependencies
[i
],
1905 pst
->dependencies
[i
]->filename
);
1908 /* Now read the symbols for this symtab */
1910 cur_fd
= pst
->ldsymoff
;
1914 /* Get a new lexical context */
1917 top_stack
->cur_st
= cur_stab
;
1918 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab
),
1920 BLOCK_START(top_stack
->cur_block
) = fh
? fh
->adr
: 0;
1921 BLOCK_END(top_stack
->cur_block
) = 0;
1922 top_stack
->blocktype
= stFile
;
1923 top_stack
->maxsyms
= 2*f_max
;
1924 top_stack
->cur_type
= 0;
1925 top_stack
->procadr
= 0;
1926 top_stack
->numargs
= 0;
1928 /* Parse locals and procedures */
1930 parse_one_file(fh
, cur_fd
, (cur_fd
== (cur_hdr
->ifdMax
- 1)) ?
1931 cur_hdr
->cbDnOffset
: fh
[1].adr
);
1933 /* .. and our share of externals.
1934 XXX use the global list to speed up things here. how ?
1935 FIXME, Maybe quit once we have found the right number of ext's? */
1936 /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
1937 top_stack
->blocktype
= stFile
;
1938 top_stack
->maxsyms
= cur_hdr
->isymMax
+ cur_hdr
->ipdMax
+ cur_hdr
->iextMax
;
1939 for (i
= 0; i
< cur_hdr
->iextMax
; i
++) {
1940 register EXTR
*esh
= (EXTR
*) (cur_hdr
->cbExtOffset
) + i
;
1941 if (esh
->ifd
== cur_fd
)
1942 parse_external(esh
, 1);
1945 /* If there are undefined, tell the user */
1946 if (n_undef_symbols
) {
1947 printf_filtered("File %s contains %d unresolved references:",
1948 st
->filename
, n_undef_symbols
);
1949 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
1950 n_undef_vars
, n_undef_procs
, n_undef_labels
);
1951 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
1957 * Sort the symbol table now, we are done adding symbols to it.
1959 sort_symtab_syms(st
);
1961 /* Now link the psymtab and the symtab. */
1965 /* Ancillary parsing procedures. */
1967 /* Lookup the type at relative index RN. Return it in TPP
1968 if found and in any event come up with its name PNAME.
1969 Return value says how many aux symbols we ate */
1972 cross_ref(rn
, tpp
, pname
)
1979 /* Escape index means 'the next one' */
1980 if (rn
->rfd
== 0xfff)
1981 rf
= *(unsigned *) (rn
+ 1);
1987 *pname
= "<undefined>";
1990 * Find the relative file descriptor and the symbol in it
1992 FDR
*fh
= get_rfd(cur_fd
, rf
);
1997 * If we have processed this symbol then we left a forwarding
1998 * pointer to the corresponding GDB symbol. If not, we`ll put
1999 * it in a list of pending symbols, to be processed later when
2000 * the file f will be. In any event, we collect the name for
2001 * the type here. Which is why we made a first pass at
2004 sh
= (SYMR
*) (fh
->isymBase
) + rn
->index
;
2006 /* Careful, we might be looking at .o files */
2007 *pname
= (UNSAFE_DATA_ADDR(sh
->iss
)) ? "<undefined>" :
2010 /* Have we parsed it ? */
2011 if ((!UNSAFE_DATA_ADDR(sh
->value
)) && (sh
->st
== stParsed
)) {
2012 t
= (struct type
*) sh
->value
;
2017 /* Avoid duplicates */
2018 p
= is_pending_symbol(fh
, sh
);
2023 add_pending(fh
, sh
, *tpp
);
2027 /* We used one auxent normally, two if we got a "next one" rf. */
2028 return (rn
->rfd
== 0xfff? 2: 1);
2032 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2033 keeping the symtab sorted */
2035 static struct symbol
*
2036 mylookup_symbol (name
, block
, namespace, class)
2038 register struct block
*block
;
2039 enum namespace namespace;
2040 enum address_class
class;
2042 register int bot
, top
, inc
;
2043 register struct symbol
*sym
;
2046 top
= BLOCK_NSYMS(block
);
2049 sym
= BLOCK_SYM(block
, bot
);
2050 if (SYMBOL_NAME(sym
)[0] == inc
2051 && SYMBOL_NAMESPACE(sym
) == namespace
2052 && SYMBOL_CLASS(sym
) == class
2053 && !strcmp(SYMBOL_NAME(sym
), name
))
2057 if (block
= BLOCK_SUPERBLOCK (block
))
2058 return mylookup_symbol (name
, block
, namespace, class);
2063 /* Add a new symbol S to a block B.
2064 Infrequently, we will need to reallocate the block to make it bigger.
2065 We only detect this case when adding to top_stack->cur_block, since
2066 that's the only time we know how big the block is. FIXME. */
2073 int nsyms
= BLOCK_NSYMS(b
)++;
2074 struct block
*origb
;
2075 struct parse_stack
*stackp
;
2077 if (b
== top_stack
->cur_block
&&
2078 nsyms
>= top_stack
->maxsyms
) {
2079 complain (&block_overflow_complaint
, s
->name
);
2080 /* In this case shrink_block is actually grow_block, since
2081 BLOCK_NSYMS(b) is larger than its current size. */
2083 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
2085 /* Now run through the stack replacing pointers to the
2086 original block. shrink_block has already done this
2087 for the blockvector and BLOCK_FUNCTION. */
2088 for (stackp
= top_stack
; stackp
; stackp
= stackp
->next
) {
2089 if (stackp
->cur_block
== origb
) {
2090 stackp
->cur_block
= b
;
2091 stackp
->maxsyms
= BLOCK_NSYMS (b
);
2095 BLOCK_SYM(b
,nsyms
) = s
;
2098 /* Add a new block B to a symtab S */
2105 struct blockvector
*bv
= BLOCKVECTOR(s
);
2107 bv
= (struct blockvector
*)xrealloc(bv
, sizeof(struct blockvector
) +
2108 BLOCKVECTOR_NBLOCKS(bv
) * sizeof(bv
->block
));
2109 if (bv
!= BLOCKVECTOR(s
))
2110 BLOCKVECTOR(s
) = bv
;
2112 BLOCKVECTOR_BLOCK(bv
, BLOCKVECTOR_NBLOCKS(bv
)++) = b
;
2115 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2116 MIPS' linenumber encoding might need more than one byte
2117 to describe it, LAST is used to detect these continuation lines */
2120 add_line(lt
, lineno
, adr
, last
)
2121 struct linetable
*lt
;
2127 last
= -2; /* make sure we record first line */
2129 if (last
== lineno
) /* skip continuation lines */
2132 lt
->item
[lt
->nitems
].line
= lineno
;
2133 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
2139 /* Comparison functions, used when sorting things */
2141 /* Symtabs must be ordered viz the code segments they cover */
2144 compare_symtabs( s1
, s2
)
2145 struct symtab
**s1
, **s2
;
2147 /* "most specific" first */
2149 register struct block
*b1
, *b2
;
2150 b1
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1
),GLOBAL_BLOCK
);
2151 b2
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2
),GLOBAL_BLOCK
);
2152 if (BLOCK_END(b1
) == BLOCK_END(b2
))
2153 return BLOCK_START(b1
) - BLOCK_START(b2
);
2154 return BLOCK_END(b1
) - BLOCK_END(b2
);
2158 /* Partial Symtabs, same */
2161 compare_psymtabs( s1
, s2
)
2162 struct partial_symtab
**s1
, **s2
;
2164 /* Perf twist: put the ones with no code at the end */
2166 register int a
= (*s1
)->textlow
;
2167 register int b
= (*s2
)->textlow
;
2176 /* Partial symbols are compared lexicog by their print names */
2179 compare_psymbols (s1
, s2
)
2180 register struct partial_symbol
*s1
, *s2
;
2183 *st1
= SYMBOL_NAME(s1
),
2184 *st2
= SYMBOL_NAME(s2
);
2186 return (st1
[0] - st2
[0] ? st1
[0] - st2
[0] :
2187 strcmp(st1
+ 1, st2
+ 1));
2190 /* Blocks with a smaller low bound should come first */
2192 static int compare_blocks(b1
,b2
)
2193 struct block
**b1
, **b2
;
2195 register int addr_diff
;
2197 addr_diff
= (BLOCK_START((*b1
))) - (BLOCK_START((*b2
)));
2199 return (BLOCK_END((*b1
))) - (BLOCK_END((*b2
)));
2204 /* Sorting and reordering procedures */
2206 /* Sort the blocks of a symtab S.
2207 Reorder the blocks in the blockvector by code-address,
2208 as required by some MI search routines */
2214 struct blockvector
*bv
= BLOCKVECTOR(s
);
2216 if (BLOCKVECTOR_NBLOCKS(bv
) <= 2) {
2218 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) == 0)
2219 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = 0;
2220 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) == 0)
2221 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) = 0;
2225 * This is very unfortunate: normally all functions are compiled in
2226 * the order they are found, but if the file is compiled -O3 things
2227 * are very different. It would be nice to find a reliable test
2228 * to detect -O3 images in advance.
2230 if (BLOCKVECTOR_NBLOCKS(bv
) > 3)
2231 qsort(&BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
),
2232 BLOCKVECTOR_NBLOCKS(bv
) - FIRST_LOCAL_BLOCK
,
2233 sizeof(struct block
*),
2237 register CORE_ADDR high
= 0;
2238 register int i
, j
= BLOCKVECTOR_NBLOCKS(bv
);
2240 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
2241 if (high
< BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
)))
2242 high
= BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
));
2243 BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = high
;
2246 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) =
2247 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
));
2249 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2250 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2251 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2252 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2255 /* Sort the symtab list, as required by some search procedures.
2256 We want files ordered to make them look right to users, and for
2257 searching (see block_for_pc). */
2263 struct symtab
*stab
;
2264 register struct symtab
**all_symtabs
;
2265 register int symtab_count
;
2270 /* Create an array of pointers to all the symtabs. */
2271 for (symtab_count
= 0, stab
= symtab_list
;
2273 symtab_count
++, stab
= stab
->next
) {
2274 obstack_grow (psymbol_obstack
, &stab
, sizeof (stab
));
2275 /* FIXME: Only sort blocks for new symtabs ??? */
2279 all_symtabs
= (struct symtab
**)
2280 obstack_base (psymbol_obstack
);
2281 qsort((char *)all_symtabs
, symtab_count
,
2282 sizeof(struct symtab
*), compare_symtabs
);
2284 /* Re-construct the symtab list, but now it is sorted. */
2285 for (i
= 0; i
< symtab_count
-1; i
++)
2286 all_symtabs
[i
]->next
= all_symtabs
[i
+1];
2287 all_symtabs
[i
]->next
= 0;
2288 symtab_list
= all_symtabs
[0];
2290 obstack_free (psymbol_obstack
, all_symtabs
);
2293 /* Sort the partial symtab list, as required by some search procedures.
2294 PC lookups stop at the first psymtab such that textlow <= PC < texthigh */
2300 register int all_psymtabs_count
;
2301 struct partial_symtab
*pstab
;
2302 struct partial_symtab
**all_psymtabs
;
2304 if (!partial_symtab_list
)
2307 /* Create an array of pointers to all the partial_symtabs. */
2309 for (all_psymtabs_count
= 0, pstab
= partial_symtab_list
;
2311 all_psymtabs_count
++, pstab
= pstab
->next
)
2312 obstack_grow (psymbol_obstack
, &pstab
, sizeof (pstab
));
2314 all_psymtabs
= (struct partial_symtab
**)
2315 obstack_base (psymbol_obstack
);
2317 qsort((char *)all_psymtabs
, all_psymtabs_count
,
2318 sizeof(struct partial_symtab
*), compare_psymtabs
);
2320 /* Re-construct the partial_symtab_list, but now it is sorted. */
2322 for (i
= 0; i
< all_psymtabs_count
-1; i
++)
2323 all_psymtabs
[i
]->next
= all_psymtabs
[i
+1];
2324 all_psymtabs
[i
]->next
= 0;
2325 partial_symtab_list
= all_psymtabs
[0];
2327 obstack_free (psymbol_obstack
, all_psymtabs
);
2330 /* Constructor/restructor/destructor procedures */
2332 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2333 MAXSYMS and linenumbers MAXLINES we'll put in it */
2337 new_symtab(name
, maxsyms
, maxlines
)
2340 struct symtab
*s
= (struct symtab
*) xzalloc(sizeof(struct symtab
));
2343 LINETABLE(s
) = new_linetable(maxlines
);
2347 /* All symtabs must have at least two blocks */
2348 BLOCKVECTOR(s
) = new_bvect(2);
2349 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
) = new_block(maxsyms
);
2350 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), STATIC_BLOCK
) = new_block(maxsyms
);
2351 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
),STATIC_BLOCK
)) =
2352 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
);
2354 s
->free_code
= free_linetable
;
2356 /* Link the new symtab into the list of such. */
2357 s
->next
= symtab_list
;
2363 /* Allocate a new partial_symtab NAME */
2365 static struct partial_symtab
*
2369 struct partial_symtab
*pst
;
2371 pst
= (struct partial_symtab
*)
2372 obstack_alloc (psymbol_obstack
, sizeof (*pst
));
2373 bzero (pst
, sizeof (*pst
));
2375 if (name
== (char*)-1) /* FIXME -- why not null here? */
2376 pst
->filename
= "<no name>";
2378 pst
->filename
= name
;
2380 pst
->next
= partial_symtab_list
;
2381 partial_symtab_list
= pst
;
2383 /* Keep a backpointer to the file`s symbols */
2384 /* FIXME, we should use private data that is a proper pointer. */
2385 pst
->ldsymlen
= (int)cur_hdr
;
2387 /* The way to turn this into a symtab is to call... */
2388 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
2394 /* Allocate a linetable array of the given SIZE */
2397 struct linetable
*new_linetable(size
)
2399 struct linetable
*l
;
2401 size
= size
* sizeof(l
->item
) + sizeof(struct linetable
);
2402 l
= (struct linetable
*)xmalloc(size
);
2407 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2408 I am not so sure about the 3.4 ones */
2414 struct linetable
*l
= new_linetable(LINETABLE(s
)->nitems
);
2416 bcopy(LINETABLE(s
), l
,
2417 LINETABLE(s
)->nitems
* sizeof(l
->item
) + sizeof(struct linetable
));
2418 free (LINETABLE(s
));
2422 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2425 struct blockvector
*
2428 struct blockvector
*bv
;
2431 size
= sizeof(struct blockvector
) + nblocks
* sizeof(struct block
*);
2432 bv
= (struct blockvector
*) xzalloc(size
);
2434 BLOCKVECTOR_NBLOCKS(bv
) = nblocks
;
2439 /* Allocate and zero a new block of MAXSYMS symbols */
2445 int size
= sizeof(struct block
) + (maxsyms
-1) * sizeof(struct symbol
*);
2446 struct block
*b
= (struct block
*)xzalloc(size
);
2451 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2452 Shrink_block can also be used by add_symbol to grow a block. */
2454 static struct block
*
2460 struct blockvector
*bv
= BLOCKVECTOR(s
);
2463 /* Just reallocate it and fix references to the old one */
2465 new = (struct block
*) xrealloc ((char *)b
, sizeof(struct block
) +
2466 (BLOCK_NSYMS(b
)-1) * sizeof(struct symbol
*));
2468 /* Should chase pointers to old one. Fortunately, that`s just
2469 the block`s function and inferior blocks */
2470 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b
)
2471 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2472 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2473 if (BLOCKVECTOR_BLOCK(bv
,i
) == b
)
2474 BLOCKVECTOR_BLOCK(bv
,i
) = new;
2475 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) == b
)
2476 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) = new;
2480 /* Create a new symbol with printname NAME */
2487 struct symbol
*s
= (struct symbol
*)
2488 obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
2490 bzero (s
, sizeof (*s
));
2491 SYMBOL_NAME(s
) = name
;
2495 /* Create a new type with printname NAME */
2502 struct type
*t
= (struct type
*)
2503 obstack_alloc (symbol_obstack
, sizeof (struct type
));
2505 bzero (t
, sizeof (*t
));
2506 TYPE_NAME(t
) = name
;
2510 /* Create and initialize a new type with printname NAME.
2511 CODE and LENGTH are the initial info we put in,
2512 UNS says whether the type is unsigned or not. */
2516 make_type(code
, length
, uns
, name
)
2517 enum type_code code
;
2521 register struct type
*type
;
2523 type
= (struct type
*) xzalloc(sizeof(struct type
));
2524 TYPE_CODE(type
) = code
;
2525 TYPE_LENGTH(type
) = length
;
2526 TYPE_FLAGS(type
) = uns
? TYPE_FLAG_UNSIGNED
: 0;
2527 TYPE_NAME(type
) = name
;
2532 /* Allocate a new field named NAME to the type TYPE */
2536 new_field(type
,name
)
2542 /* Fields are kept in an array */
2543 if (TYPE_NFIELDS(type
))
2544 TYPE_FIELDS(type
) = (struct field
*)xrealloc(TYPE_FIELDS(type
),
2545 (TYPE_NFIELDS(type
)+1) * sizeof(struct field
));
2547 TYPE_FIELDS(type
) = (struct field
*)xzalloc(sizeof(struct field
));
2548 f
= &(TYPE_FIELD(type
,TYPE_NFIELDS(type
)));
2549 TYPE_NFIELDS(type
)++;
2550 bzero(f
, sizeof(struct field
));
2551 f
->name
= name
; /* Whether or not NAME is zero, this works. */
2555 /* Make an enum constant for a member F of an enumerated type T */
2558 make_enum_constant(f
,t
)
2564 * This is awful, but that`s the way it is supposed to be
2565 * (BTW, no need to free the real 'type', it's a builtin)
2567 f
->type
= (struct type
*) f
->bitpos
;
2569 s
= new_symbol(f
->name
);
2570 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2571 SYMBOL_CLASS(s
) = LOC_CONST
;
2573 SYMBOL_VALUE(s
) = f
->bitpos
;
2574 add_symbol(s
, top_stack
->cur_block
);
2579 /* Things used for calling functions in the inferior.
2580 These functions are exported to our companion
2581 mips-dep.c file and are here because they play
2582 with the symbol-table explicitly. */
2585 /* Need to make a new symbol on the fly for the dummy
2586 frame we put on the stack. Which goes in the.. */
2588 static struct symtab
*dummy_symtab
;
2590 /* Make up a dummy symbol for the code we put at END_PC,
2591 of size SIZE, invoking a function with NARGS arguments
2592 and using a frame of FRAMESIZE bytes */
2594 mips_create_dummy_symbol(end_pc
, size
, nargs
, framesize
)
2598 struct mips_extra_func_info
*gdbinfo
;
2600 /* Allocate symtab if not done already */
2601 if (dummy_symtab
== 0)
2602 dummy_symtab
= new_symtab(".dummy_symtab.", 100, 0);
2604 /* Make a new block. Only needs one symbol */
2606 BLOCK_START(bl
) = end_pc
- size
;
2607 BLOCK_END(bl
) = end_pc
;
2609 BLOCK_SUPERBLOCK(bl
) =
2610 BLOCKVECTOR_BLOCK(BLOCKVECTOR(dummy_symtab
),GLOBAL_BLOCK
);
2611 add_block(bl
, dummy_symtab
);
2612 sort_blocks(dummy_symtab
);
2614 BLOCK_FUNCTION(bl
) = new_symbol("??");
2615 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(bl
)) = bl
;
2616 g
= new_symbol(".gdbinfo.");
2617 BLOCK_SYM(bl
,BLOCK_NSYMS(bl
)++) = g
;
2619 SYMBOL_NAMESPACE(g
) = LABEL_NAMESPACE
;
2620 SYMBOL_CLASS(g
) = LOC_CONST
;
2621 SYMBOL_TYPE(g
) = builtin_type_void
;
2622 gdbinfo
= (struct mips_extra_func_info
*)
2623 xzalloc(sizeof(struct mips_extra_func_info
));
2625 SYMBOL_VALUE(g
) = (long) gdbinfo
;
2627 gdbinfo
->numargs
= nargs
;
2628 gdbinfo
->framesize
= framesize
;
2629 gdbinfo
->framereg
= 29;
2630 gdbinfo
->pcreg
= 31;
2631 gdbinfo
->regmask
= -2;
2632 gdbinfo
->regoffset
= -4;
2633 gdbinfo
->fregmask
= 0; /* XXX */
2634 gdbinfo
->fregoffset
= 0; /* XXX */
2637 /* We just returned from the dummy code at END_PC, drop its symbol */
2639 mips_destroy_dummy_symbol(end_pc
)
2642 struct blockvector
*bv
= BLOCKVECTOR(dummy_symtab
);
2645 bl
= block_for_pc(end_pc
);
2646 free(BLOCK_FUNCTION(bl
));
2647 free(SYMBOL_VALUE(BLOCK_SYM(bl
,0)));
2648 free(BLOCK_SYM(bl
,0));
2650 for (i
= FIRST_LOCAL_BLOCK
; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2651 if (BLOCKVECTOR_BLOCK(bv
,i
) == bl
)
2653 for (; i
< BLOCKVECTOR_NBLOCKS(bv
) - 1; i
++)
2654 BLOCKVECTOR_BLOCK(bv
,i
) = BLOCKVECTOR_BLOCK(bv
,i
+1);
2655 BLOCKVECTOR_NBLOCKS(bv
)--;
2656 sort_blocks(dummy_symtab
);
2661 /* Sigtramp: make sure we have all the necessary information
2662 about the signal trampoline code. Since the official code
2663 from MIPS does not do so, we make up that information ourselves.
2664 If they fix the library (unlikely) this code will neutralize itself. */
2671 struct block
*b
, *b0
;
2673 sigtramp_address
= -1;
2675 /* We know it is sold as sigvec */
2676 s
= lookup_symbol("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
2678 /* Most programs do not play with signals */
2682 b0
= SYMBOL_BLOCK_VALUE(s
);
2684 /* A label of sigvec, to be more precise */
2685 s
= lookup_symbol("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
2687 /* But maybe this program uses its own version of sigvec */
2691 sigtramp_address
= SYMBOL_VALUE(s
);
2692 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
2694 /* Did we or MIPSco fix the library ? */
2695 if (SYMBOL_CLASS(s
) == LOC_BLOCK
)
2698 /* But what symtab does it live in ? */
2699 st
= find_pc_symtab(SYMBOL_VALUE(s
));
2702 * Ok, there goes the fix: turn it into a procedure, with all the
2703 * needed info. Note we make it a nested procedure of sigvec,
2704 * which is the way the (assembly) code is actually written.
2706 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2707 SYMBOL_CLASS(s
) = LOC_BLOCK
;
2708 SYMBOL_TYPE(s
) = make_type(TYPE_CODE_FUNC
, 4, 0, 0);
2709 TYPE_TARGET_TYPE(SYMBOL_TYPE(s
)) = builtin_type_void
;
2711 /* Need a block to allocate .gdbinfo. in */
2713 SYMBOL_BLOCK_VALUE(s
) = b
;
2714 BLOCK_START(b
) = sigtramp_address
;
2715 BLOCK_END(b
) = sigtramp_end
;
2716 BLOCK_FUNCTION(b
) = s
;
2717 BLOCK_SUPERBLOCK(b
) = BLOCK_SUPERBLOCK(b0
);
2721 /* Make a .gdbinfo. for it */
2723 struct mips_extra_func_info
*e
=
2724 (struct mips_extra_func_info
*)
2725 xzalloc(sizeof(struct mips_extra_func_info
));
2727 e
->numargs
= 0; /* the kernel thinks otherwise */
2728 /* align_longword(sigcontext + SIGFRAME) */
2729 e
->framesize
= 0x150;
2730 e
->framereg
= SP_REGNUM
;
2733 e
->regoffset
= -(41 * sizeof(int));
2735 e
->fregoffset
= -(37 * sizeof(int));
2738 s
= new_symbol(".gdbinfo.");
2739 SYMBOL_VALUE(s
) = (int) e
;
2740 SYMBOL_NAMESPACE(s
) = LABEL_NAMESPACE
;
2741 SYMBOL_CLASS(s
) = LOC_CONST
;
2742 SYMBOL_TYPE(s
) = builtin_type_void
;
2745 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
2748 /* Initialization */
2750 static struct sym_fns ecoff_sym_fns
= {"ecoff", 5,
2751 mipscoff_new_init
, mipscoff_symfile_init
,
2752 mipscoff_symfile_read
};
2754 _initialize_mipsread ()
2756 add_symtab_fns (&ecoff_sym_fns
);
2758 /* Missing basic types */
2759 builtin_type_string
= make_type(TYPE_CODE_PASCAL_ARRAY
,
2761 builtin_type_complex
= make_type(TYPE_CODE_FLT
,
2762 2 * sizeof(float), 0, "complex");
2763 builtin_type_double_complex
= make_type(TYPE_CODE_FLT
,
2764 2 * sizeof(double), 0, "double_complex");
2765 builtin_type_fixed_dec
= make_type(TYPE_CODE_INT
, sizeof(int),
2766 0, "fixed_decimal");
2767 builtin_type_float_dec
= make_type(TYPE_CODE_FLT
, sizeof(double),
2768 0, "floating_decimal");
2770 /* Templates types */
2771 builtin_type_ptr
= lookup_pointer_type (builtin_type_void
);
2772 builtin_type_struct
= make_type(TYPE_CODE_STRUCT
, 0, 0, 0);
2773 builtin_type_union
= make_type(TYPE_CODE_UNION
, 0, 0, 0);
2774 builtin_type_enum
= make_type(TYPE_CODE_ENUM
, 0, 0, 0);
2775 builtin_type_range
= make_type(TYPE_CODE_RANGE
, 0, 0, 0);
2776 builtin_type_set
= make_type(TYPE_CODE_SET
, 0, 0, 0);