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 GDB 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 1, or (at your option)
12 GDB 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 GDB; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include <sys/param.h>
32 #include <mips/syms.h>
35 #endif /* not CMUCS */
37 /* Since these things are defined differently on various systems I'll
38 (re)define here what I really need in this module. I only assume the
39 three standard COFF structure definitions: filehdr, aouthdr, scnhdr */
40 #define MIPS /* Kludge to get MIPS version of coff */
41 #include "intel-coff.h"
53 #define a_magic a.magic /* magic number */
54 #define a_text a.tsize /* size of text segment */
55 #define a_data a.dsize /* size of initialized data */
56 #define a_bss a.bsize /* size of uninitialized data */
57 #define a_syms f.f_nsyms /* size of symbol table */
58 #define a_entry a.entry /* entry point */
62 (((x).a_magic)!=OMAGIC && ((x).a_magic)!=NMAGIC && ((x).a_magic)!=ZMAGIC)
64 /* Things we import explicitly from other modules */
66 extern int info_verbose
;
67 extern struct block
*block_for_pc();
68 extern void sort_symtab_syms();
70 /* Forward declarations */
72 static void psymtab_to_symtab_1();
74 /* Macros and extra defs */
76 struct complaint unknown_ext_complaint
=
77 {"unknown external symbol %s", 0, 0};
79 /* Already parsed symbols are marked specially */
81 #define stParsed stType
83 /* Puns: hard to find whether -g was used and how */
85 #define MIN_GLEVEL GLEVEL_0
86 #define compare_glevel(a,b) \
87 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
88 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
90 /* When looking at .o files avoid tripping over bad addresses */
92 #define SAFE_TEXT_ADDR 0x400000
93 #define SAFE_DATA_ADDR 0x10000000
95 #define UNSAFE_DATA_ADDR(p) ((unsigned)p < SAFE_DATA_ADDR || (unsigned)p > 2*SAFE_DATA_ADDR)
98 /* Things we export to other modules */
101 /* Lists of partial symbols */
103 struct psymbol_allocation_list global_psymbols
, static_psymbols
;
105 /* Address bounds for the signal trampoline in inferior, if any */
107 CORE_ADDR sigtramp_address
, sigtramp_end
;
110 /* Functions that we really export */
112 /* THIS DESCRIPTION IS OBSOLETE POST-BFD; FIXME! */
113 /* Basically, this module must provide two functions: symbol_file_command()
114 which loads the symbol table from a file, and add_file_command() which
115 adds more symbols to the symbol table (incrementally).
117 These two functions only do the minimum work necessary for letting the
118 user "name" things symbolically, they do not read the entire symtab.
119 Instead, they read in the external symbols and put them in partial
120 symbol tables. When more extensive information is requested of a
121 file the corresponding partial symbol table is mutated into a full
122 fledged symbol table by going back and reading the relative symbols
123 for real. mipscoff_psymtab_to_symtab() is the function that does this */
125 /* The entry point (starting address) of the file, if it is an executable. */
127 static CORE_ADDR entry_point
;
129 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
130 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
138 mipscoff_symfile_init (sf
)
141 bfd
*abfd
= sf
->sym_bfd
;
142 sf
->sym_private
= NULL
;
143 /* Save startup file's range of PC addresses to help blockframe.c
144 decide where the bottom of the stack is. */
145 if (bfd_get_file_flags (abfd
) & EXEC_P
)
147 /* Executable file -- record its entry point so we'll recognize
148 the startup file because it contains the entry point. */
149 entry_point
= bfd_get_start_address (abfd
);
153 /* Examination of non-executable.o files. Short-circuit this stuff. */
154 /* ~0 will not be in any file, we hope. */
156 /* set the startup file to be an empty range. */
157 startup_file_start
= 0;
158 startup_file_end
= 0;
163 mipscoff_symfile_read(sf
, addr
, mainline
)
168 struct coff_symfile_info
*info
= (struct coff_symfile_info
*)sf
->sym_private
;
169 bfd
*abfd
= sf
->sym_bfd
;
170 char *name
= bfd_get_filename (abfd
);
175 int stringtab_offset
;
177 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
178 desc
= fileno ((FILE *)(abfd
->iostream
)); /* Raw file descriptor */
179 num_symbols
= bfd_get_symcount (abfd
); /* How many syms */
180 /* symtab_offset = obj_sym_filepos (abfd); * Symbol table file offset */
181 /* stringtab_offset = symtab_offset + num_symbols * SYMESZ; * String tab */
185 debug_info
= text_hdr
.s_relptr
;
188 dc_terminate (tdesc_handle
);
194 /* Read the line number table, all at once. */
195 info
->min_lineno_offset
= 0;
196 info
->max_lineno_offset
= 0;
197 bfd_map_over_sections (abfd
, find_linenos
, info
);
199 val
= init_lineno (desc
, info
->min_lineno_offset
,
200 info
->max_lineno_offset
- info
->min_lineno_offset
);
202 error ("\"%s\": error reading line numbers\n", name
);
204 /* Now read the string table, all at once. */
206 val
= init_stringtab (desc
, stringtab_offset
);
209 free_all_symtabs (); /* FIXME blows whole symtab */
210 printf ("\"%s\": can't get string table", name
);
214 make_cleanup (free_stringtab
, 0);
216 /* Position to read the symbol table. Do not read it all at once. */
217 val
= lseek (desc
, (long)symtab_offset
, 0);
219 perror_with_name (name
);
221 init_misc_bunches ();
222 make_cleanup (discard_misc_bunches
, 0);
224 /* Now that the executable file is positioned at symbol table,
225 process it and define symbols accordingly. */
227 read_mips_symtab(desc
, 0);
229 /* patch_opaque_types ();*/
231 /* Sort symbols alphabetically within each block. */
233 sort_all_symtab_syms ();
235 /* Go over the misc symbol bunches and install them in vector. */
237 condense_misc_bunches (0);
239 /* Make a default for file to list. */
241 select_source_symtab (0); /* FIXME, this might be too slow, see dbxread */
245 mipscoff_symfile_discard()
249 /* Exported procedure: Allocate zeroed memory */
253 char *p
= xmalloc(size
);
259 /* Exported procedure: Builds a symtab from the PST partial one.
260 Restores the environment in effect when PST was created, delegates
261 most of the work to an ancillary procedure, and sorts
262 and reorders the symtab list at the end */
265 static HDRR
*cur_hdr
; /* MIPS symtab header for the current file */
268 mipscoff_psymtab_to_symtab(pst
)
269 struct partial_symtab
*pst
;
278 printf_filtered("Reading in symbols for %s...", pst
->filename
);
281 /* Restore the header and list of pending typedefs */
282 cur_hdr
= (HDRR
*) pst
->ldsymlen
;
284 psymtab_to_symtab_1(pst
);
288 /* Finish up the debug error message. */
290 printf_filtered("done.\n");
293 /* Exported procedure: Is PC in the signal trampoline code */
295 int in_sigtramp(pc
,name
)
298 if (sigtramp_address
== 0)
300 return (pc
>= sigtramp_address
&& pc
< sigtramp_end
);
304 /* Things that really are local to this module */
306 /* All allocated symtabs and psymtabs */
308 static int all_symtabs_count
;
309 static int all_psymtabs_count
;
311 /* GDB symtable for the current compilation unit */
313 static struct symtab
*cur_stab
;
315 /* Header for executable/object file we read symbols from */
317 static struct coff_exec filhdr
;
318 #define END_OF_TEXT_SEGMENT(f) ((f).a.text_start + (f).a.tsize)
320 /* Pointer to current file decriptor record, and its index */
325 /* Index of current symbol */
329 /* Note how much "debuggable" this image is. We would like
330 to see at least one FDR with full symbols */
335 /* When examining .o files, report on undefined symbols */
337 static int n_undef_symbols
, n_undef_labels
, n_undef_vars
, n_undef_procs
;
339 /* Extra builtin types */
341 struct type
*builtin_type_complex
;
342 struct type
*builtin_type_double_complex
;
343 struct type
*builtin_type_fixed_dec
;
344 struct type
*builtin_type_float_dec
;
345 struct type
*builtin_type_string
;
349 static struct type
*builtin_type_ptr
;
350 static struct type
*builtin_type_struct
;
351 static struct type
*builtin_type_union
;
352 static struct type
*builtin_type_enum
;
353 static struct type
*builtin_type_range
;
354 static struct type
*builtin_type_set
;
359 static struct symbol
*new_symbol();
360 static struct type
*new_type();
361 static struct field
*new_field();
362 static struct block
*new_block();
363 static struct symtab
*new_symtab();
364 static struct linetable
*new_linetable();
365 static struct blockvector
*new_bvect();
367 static struct type
*parse_type();
368 static struct type
*make_type();
369 static struct symbol
*mylookup_symbol();
370 static struct block
*shrink_block();
372 static int compare_symtabs();
373 static int compare_psymtabs();
374 static int compare_blocks();
376 static struct partial_symtab
*new_psymtab();
377 static struct partial_symbol
*new_psymbol();
378 static struct partial_symtab
*parse_fdr();
379 static int compare_psymbols();
381 /* File-level interface functions */
383 /* Read the symtab information from file FSYM into memory */
386 read_the_mips_symtab(fsym
)
388 int stsize
, st_hdrsize
;
392 /* Find and read the symbol table header */
393 st_hdrsize
= filhdr
.f
.f_nsyms
;
394 st_filptr
= filhdr
.f
.f_symptr
;
398 lseek(fsym
, st_filptr
, L_SET
);
399 if (read(fsym
, &st_hdr
, st_hdrsize
) != st_hdrsize
)
402 /* Find out how large the symbol table is */
403 stsize
= (st_hdr
.cbExtOffset
- (st_filptr
+ st_hdrsize
))
404 + st_hdr
.iextMax
* cbEXTR
;
406 /* Allocate space for the symbol table. Read it in. */
407 cur_hdr
= (HDRR
*) xmalloc(stsize
+ st_hdrsize
);
409 bcopy(&st_hdr
, cur_hdr
, st_hdrsize
);
410 if (read(fsym
, (char *) cur_hdr
+ st_hdrsize
, stsize
) != stsize
)
413 /* Fixup file_pointers in it */
414 fixup_symtab(cur_hdr
, (char *) cur_hdr
+ st_hdrsize
,
415 st_filptr
+ st_hdrsize
);
419 error("Short read on %s", symfile
);
423 /* Turn all file-relative pointers in the symtab described by HDR
424 into memory pointers, given that the symtab itself is located
425 at DATA in memory and F_PTR in the file. */
428 fixup_symtab( hdr
, data
, f_ptr
)
440 * These fields are useless (and empty) by now:
441 * hdr->cbDnOffset, hdr->cbOptOffset
442 * We use them for other internal purposes.
445 hdr
->cbOptOffset
= 0;
448 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
464 * Fix all string pointers inside the symtab, and
465 * the FDR records. Also fix other miscellany.
467 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
468 register unsigned code_offset
;
470 /* Header itself, and strings */
471 fh
= (FDR
*) (hdr
->cbFdOffset
) + f_idx
;
472 fh
->issBase
+= hdr
->cbSsOffset
;
474 fh
->rss
= (long)fh
->rss
+ fh
->issBase
;
475 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
476 sh
= (SYMR
*)(hdr
->cbSymOffset
) + fh
->isymBase
+ s_idx
;
477 sh
->iss
= (long) sh
->iss
+ fh
->issBase
;
484 fh
->isymBase
= (int)((SYMR
*)(hdr
->cbSymOffset
)+fh
->isymBase
);
486 /* cannot fix fh->ipdFirst because it is a short */
487 #define IPDFIRST(h,fh) \
488 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
490 /* Optional symbols (actually used for partial_symtabs) */
496 fh
->iauxBase
= hdr
->cbAuxOffset
+ fh
->iauxBase
* sizeof(AUXU
);
497 /* Relative file descriptor table */
498 fh
->rfdBase
= hdr
->cbRfdOffset
+ fh
->rfdBase
* sizeof(RFDT
);
502 fh
->cbLineOffset
+= hdr
->cbLineOffset
;
504 /* Procedure symbols. (XXX This should be done later) */
505 code_offset
= fh
->adr
;
506 for (s_idx
= 0; s_idx
< fh
->cpd
; s_idx
++) {
507 unsigned name
, only_ext
;
509 pr
= (PDR
*)(IPDFIRST(hdr
,fh
)) + s_idx
;
511 /* Simple rule to find files linked "-x" */
512 only_ext
= fh
->rss
== -1;
514 if (pr
->isym
== -1) {
515 /* static function */
519 name
= hdr
->cbExtOffset
+ pr
->isym
* sizeof(EXTR
);
520 sh
= &((EXTR
*)name
)->asym
;
524 sh
= (SYMR
*)fh
->isymBase
+ pr
->isym
;
525 /* Included code ? */
526 if (s_idx
== 0 && pr
->adr
!= 0)
527 code_offset
-= pr
->adr
;
530 /* Turn index into a pointer */
533 /* Fix line numbers */
534 pr
->cbLineOffset
+= fh
->cbLineOffset
;
536 /* Relocate address */
538 pr
->adr
+= code_offset
;
542 /* External symbols: fix string */
543 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
544 esh
= (EXTR
*)(hdr
->cbExtOffset
) + s_idx
;
545 esh
->asym
.iss
= esh
->asym
.iss
+ hdr
->cbSsExtOffset
;
550 /* Find a file descriptor given its index RF relative to a file CF */
553 FDR
*get_rfd( cf
, rf
)
557 f
= (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
558 /* Object files do not have the RFD table, all refs are absolute */
560 return (FDR
*) (cur_hdr
->cbFdOffset
) + rf
;
561 cf
= *((pRFDT
) f
->rfdBase
+ rf
);
562 return (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
565 /* Return a safer print NAME for a file descriptor */
571 if (name
== (char *) -1)
572 return "<stripped file>";
573 if (UNSAFE_DATA_ADDR(name
))
579 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
580 whether we are adding to the general symtab or not */
583 read_mips_symtab( desc
, incremental
)
586 * We get here with DESC pointing to the symtab header. But we need
587 * other info from the initial headers
590 myread(desc
, &filhdr
, sizeof filhdr
);
592 read_the_mips_symtab(desc
);
594 parse_partial_symbols(cur_hdr
, incremental
);
598 * Check to make sure file was compiled with -g.
599 * If not, warn the user of this limitation.
601 if (compare_glevel(max_glevel
, GLEVEL_2
) < 0) {
602 if (max_gdbinfo
== 0)
603 printf("\n%s not compiled with -g, debugging support is limited.", symfile
);
604 printf("\nYou should compile with -g2 or -g3 for best debugging support.\n");
609 * Dont allow char * to have a typename (else would get
612 TYPE_NAME(lookup_pointer_type(builtin_type_char
)) = 0;
616 /* Local utilities */
619 /* Map of FDR indexes to partial symtabs */
621 static struct pst_map
{
622 struct partial_symtab
*pst
; /* the psymtab proper */
623 int n_globals
; /* globals it exports */
627 /* Utility stack, used to nest procedures and blocks properly.
628 It is a doubly linked list, to avoid too many alloc/free.
629 Since we might need it quite a few times it is NOT deallocated
632 static struct parse_stack
{
633 struct parse_stack
*next
, *prev
;
634 struct symtab
*cur_st
; /* Current symtab */
635 struct block
*cur_block
; /* Block in it */
636 int blocktype
; /* What are we parsing */
637 int maxsyms
; /* Max symbols in this block */
638 struct type
*cur_type
; /* Type we parse fields for */
639 int procadr
; /* Start addres of this procedure */
640 int numargs
; /* Its argument count */
641 } *top_stack
; /* Top stack ptr */
644 /* Enter a new lexical context */
646 static push_parse_stack()
648 struct parse_stack
*new;
650 /* Reuse frames if possible */
651 if (top_stack
&& top_stack
->prev
)
652 new = top_stack
->prev
;
654 new = (struct parse_stack
*) xzalloc(sizeof(struct parse_stack
));
655 /* Initialize new frame with previous content */
657 register struct parse_stack
*prev
= new->prev
;
660 top_stack
->prev
= new;
662 new->next
= top_stack
;
667 /* Exit a lexical context */
669 static pop_parse_stack()
674 top_stack
= top_stack
->next
;
678 /* Cross-references might be to things we haven't looked at
679 yet, e.g. type references. To avoid too many type
680 duplications we keep a quick fixup table, an array
681 of lists of references indexed by file descriptor */
683 static struct pending
{
684 struct pending
*next
; /* link */
685 SYMR
*s
; /* the symbol */
686 struct type
*t
; /* its partial type descriptor */
690 /* Check whether we already saw symbol SH in file FH as undefined */
693 struct pending
*is_pending_symbol(fh
, sh
)
697 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
698 register struct pending
*p
;
700 /* Linear search is ok, list is typically no more than 10 deep */
701 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
707 /* Check whether we already saw type T in file FH as undefined */
710 struct pending
*is_pending_type(fh
, t
)
714 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
715 register struct pending
*p
;
717 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
723 /* Add a new undef symbol SH of type T */
726 add_pending(fh
, sh
, t
)
731 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
732 struct pending
*p
= is_pending_symbol(fh
, sh
);
734 /* Make sure we do not make duplicates */
736 p
= (struct pending
*) xmalloc(sizeof(*p
));
739 p
->next
= pending_list
[f_idx
];
740 pending_list
[f_idx
] = p
;
742 sh
->reserved
= 1; /* for quick check */
745 /* Throw away undef entries when done with file index F_IDX */
750 register struct pending
*p
, *q
;
752 for (p
= pending_list
[f_idx
]; p
; p
= q
) {
756 pending_list
[f_idx
] = 0;
759 /* The number of args to a procedure is not explicit in the symtab,
760 this is the list of all those we know of.
761 This makes parsing more reasonable and avoids extra passes */
763 static struct numarg
{
764 struct numarg
*next
; /* link */
765 unsigned adr
; /* procedure's start address */
766 unsigned num
; /* arg count */
769 /* Record that the procedure at ADR takes NUM arguments. */
774 struct numarg
*n
= (struct numarg
*) xmalloc(sizeof(struct numarg
));
778 n
->next
= numargs_list
;
782 /* See if we know how many arguments the procedure at ADR takes */
787 struct numarg
*n
= numargs_list
;
789 while (n
&& n
->adr
!= adr
)
791 return (n
) ? n
->num
: -1;
794 /* Release storage when done with this file */
799 struct numarg
*n
= numargs_list
, *m
;
810 /* Parsing Routines proper. */
812 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
813 For blocks, procedures and types we open a new lexical context.
814 This is basically just a big switch on the symbol's type */
825 /* When a symbol is cross-referenced from other files/symbols
826 we mark it explicitly */
827 int pend
= (sh
->reserved
== 1);
828 enum address_class
class;
835 case stGlobal
: /* external symbol, goes into the primary block */
837 b
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
841 case stStatic
: /* static data, goes into the current block. */
843 b
= top_stack
->cur_block
;
846 case stLocal
: /* local variable, goes into the current block */
847 if (sh
->sc
== scRegister
) {
848 class = LOC_REGISTER
;
853 b
= top_stack
->cur_block
;
855 data
: /* Common code for symbols describing data */
856 s
= new_symbol(sh
->iss
);
857 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
858 SYMBOL_CLASS(s
) = class;
861 /* Type could be missing in a number of cases */
862 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
863 sh
->index
== 0xfffff)
864 SYMBOL_TYPE(s
) = builtin_type_int
; /* undefined? */
866 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
867 /* Value of a data symbol is its memory address */
868 SYMBOL_VALUE(s
) = sh
->value
;
871 case stParam
: /* argument to procedure, goes into current block */
873 top_stack
->numargs
++;
874 s
= new_symbol(sh
->iss
);
875 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
876 if (sh
->sc
== scRegister
) {
877 SYMBOL_CLASS(s
) = LOC_REGPARM
;
881 SYMBOL_CLASS(s
) = LOC_ARG
;
882 SYMBOL_VALUE(s
) = sh
->value
;
883 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
884 add_symbol(s
, top_stack
->cur_block
);
887 case stLabel
: /* label, we do make a symbol for it */
888 s
= new_symbol(sh
->iss
);
889 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
; /* so that it can be used */
890 SYMBOL_CLASS(s
) = LOC_LABEL
; /* but not misused */
891 SYMBOL_VALUE(s
) = sh
->value
;
892 SYMBOL_TYPE(s
) = builtin_type_int
;
893 add_symbol(s
, top_stack
->cur_block
);
896 case stProc
: /* Procedure */
897 case stStaticProc
: /* Static procedure */
898 s
= new_symbol(sh
->iss
);
899 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
900 SYMBOL_CLASS(s
) = LOC_BLOCK
;
901 /* Type of the return value */
902 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
903 t
= builtin_type_int
;
905 t
= parse_type(ax
+ sh
->index
, sh
, 0);
906 add_symbol(s
, top_stack
->cur_block
);
908 /* Make a type for the procedure itself */
909 SYMBOL_TYPE(s
) = lookup_function_type (t
);
911 /* Create and enter a new lexical context */
912 b
= new_block(top_stack
->maxsyms
);
913 SYMBOL_BLOCK_VALUE(s
) = b
;
914 BLOCK_FUNCTION(b
) = s
;
915 BLOCK_START(b
) = BLOCK_END(b
) = sh
->value
;
916 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
917 add_block(b
, top_stack
->cur_st
);
919 /* Not if we only have partial info */
920 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
924 top_stack
->cur_block
= b
;
925 top_stack
->blocktype
= sh
->st
;
926 top_stack
->cur_type
= SYMBOL_TYPE(s
);
927 top_stack
->procadr
= sh
->value
;
928 top_stack
->numargs
= 0;
930 sh
->value
= (long) SYMBOL_TYPE(s
);
933 case stBlock
: /* Either a lexical block, or some type */
935 top_stack
->blocktype
= stBlock
;
936 if (sh
->sc
== scInfo
) { /* structure/union/enum def */
937 s
= new_symbol(sh
->iss
);
938 SYMBOL_NAMESPACE(s
) = STRUCT_NAMESPACE
;
939 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
941 add_symbol(s
, top_stack
->cur_block
);
942 /* If this type was expected, use its partial definition */
944 t
= is_pending_symbol(cur_fdr
, sh
)->t
;
946 /* Uhmm, can`t decide yet. Smash later */
947 t
= new_type(sh
->iss
);
948 TYPE_CODE(t
) = TYPE_CODE_UNDEF
;
949 add_pending(cur_fdr
, sh
, t
);
952 /* make this the current type */
953 top_stack
->cur_type
= t
;
954 TYPE_LENGTH(t
) = sh
->value
;
955 /* Mark that symbol has a type, and say which one */
956 sh
->value
= (long) t
;
958 /* beginnning of (code) block. Value of symbol
959 is the displacement from procedure start */
960 b
= new_block(top_stack
->maxsyms
);
961 BLOCK_START(b
) = sh
->value
+ top_stack
->procadr
;
962 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
963 top_stack
->cur_block
= b
;
964 add_block(b
, top_stack
->cur_st
);
968 case stEnd
: /* end (of anything) */
969 if (sh
->sc
== scInfo
) {
970 /* Finished with type */
971 top_stack
->cur_type
= 0;
972 } else if (sh
->sc
== scText
&&
973 (top_stack
->blocktype
== stProc
||
974 top_stack
->blocktype
== stStaticProc
)) {
975 /* Finished with procedure */
976 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
980 BLOCK_END(top_stack
->cur_block
) += sh
->value
; /* size */
981 got_numargs(top_stack
->procadr
, top_stack
->numargs
);
982 /* Reallocate symbols, saving memory */
983 b
= shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
985 /* f77 emits proc-level with address bounds==[0,0],
986 So look for such child blocks, and patch them. */
987 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++) {
988 struct block
*b_bad
= BLOCKVECTOR_BLOCK(bv
,i
);
989 if (BLOCK_SUPERBLOCK(b_bad
) == b
990 && BLOCK_START(b_bad
) == top_stack
->procadr
991 && BLOCK_END(b_bad
) == top_stack
->procadr
) {
992 BLOCK_START(b_bad
) = BLOCK_START(b
);
993 BLOCK_END(b_bad
) = BLOCK_END(b
);
996 if (entry_point
< BLOCK_END(b
)
997 && entry_point
>= BLOCK_START(b
)) {
998 startup_file_start
= BLOCK_START(b
);
999 startup_file_end
= BLOCK_END(b
);
1001 } else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
) {
1002 /* End of (code) block. The value of the symbol
1003 is the displacement from the procedure`s start
1004 address of the end of this block. */
1005 BLOCK_END(top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1006 (void) shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1008 pop_parse_stack(); /* restore previous lexical context */
1011 case stMember
: /* member of struct/union/enum.. */
1012 f
= new_field(top_stack
->cur_type
, sh
->iss
);
1013 f
->bitpos
= sh
->value
;
1014 f
->type
= parse_type(ax
+ sh
->index
, sh
, &f
->bitsize
);
1017 case stTypedef
: /* type definition */
1018 s
= new_symbol(sh
->iss
);
1019 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1020 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1021 SYMBOL_BLOCK_VALUE(s
) = top_stack
->cur_block
;
1022 add_symbol(s
, top_stack
->cur_block
);
1023 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
1024 sh
->value
= (long) SYMBOL_TYPE(s
);
1027 case stFile
: /* file name */
1029 top_stack
->blocktype
= sh
->st
;
1032 /* I`ve never seen these for C */
1034 break; /* register relocation */
1036 break; /* forwarding address */
1038 break; /* constant */
1040 error("Unknown symbol type %x.", sh
->st
);
1045 /* Parse the type information provided in the AX entries for
1046 the symbol SH. Return the bitfield size in BS, in case. */
1048 static struct type
*parse_type(ax
, sh
, bs
)
1053 /* Null entries in this map are treated specially */
1054 static struct type
**map_bt
[] =
1056 &builtin_type_void
, /* btNil */
1058 &builtin_type_char
, /* btChar */
1059 &builtin_type_unsigned_char
, /* btUChar */
1060 &builtin_type_short
, /* btShort */
1061 &builtin_type_unsigned_short
, /* btUShort */
1062 &builtin_type_int
, /* btInt */
1063 &builtin_type_unsigned_int
, /* btUInt */
1064 &builtin_type_long
, /* btLong */
1065 &builtin_type_unsigned_long
, /* btULong */
1066 &builtin_type_float
, /* btFloat */
1067 &builtin_type_double
, /* btDouble */
1074 &builtin_type_complex
, /* btComplex */
1075 &builtin_type_double_complex
, /* btDComplex */
1077 &builtin_type_fixed_dec
, /* btFixedDec */
1078 &builtin_type_float_dec
, /* btFloatDec */
1079 &builtin_type_string
, /* btString */
1082 &builtin_type_void
, /* btVoid */
1086 struct type
*tp
= 0, *tp1
;
1089 /* Procedures start off by one */
1090 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
)
1093 /* Undefined ? Should not happen */
1094 if (ax
->rndx
.rfd
== 0xfff) {
1095 return builtin_type_void
;
1098 /* Use aux as a type information record, map its basic type */
1100 if (t
->bt
> 26 || t
->bt
== btPicture
) {
1101 printf_filtered("Internal: cannot map MIPS basic type x%x\n", t
->bt
);
1102 return builtin_type_int
;
1105 tp
= *map_bt
[t
->bt
];
1107 /* Cannot use builtin types, use templates */
1108 tp
= make_type(TYPE_CODE_VOID
, 0, 0, 0);
1111 *tp
= *builtin_type_ptr
;
1114 *tp
= *builtin_type_struct
;
1118 *tp
= *builtin_type_union
;
1122 *tp
= *builtin_type_enum
;
1126 *tp
= *builtin_type_range
;
1129 *tp
= *builtin_type_set
;
1135 /* Move on to next aux */
1138 /* This is the way it would work if the compiler worked */
1139 register TIR
*t1
= t
;
1140 while (t1
->continued
)
1144 /* For bitfields all we need is the width */
1150 /* All these types really point to some (common) MIPS type
1151 definition, and only the type-qualifiers fully identify
1152 them. We`ll make the same effort at sharing */
1153 if (t
->bt
== btIndirect
||
1154 t
->bt
== btStruct
||
1157 t
->bt
== btTypedef
||
1160 char name
[256], *pn
;
1162 /* Try to cross reference this type */
1164 ax
+= cross_ref(ax
, &tp1
, &pn
);
1165 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1166 sprintf(name
, fmt
, pn
);
1168 /* reading .o file ? */
1169 if (UNSAFE_DATA_ADDR(tp1
))
1171 if (TYPE_CODE(tp1
) == TYPE_CODE_UNDEF
) {
1173 * Type was incompletely defined, now we know.
1175 TYPE_CODE(tp1
) = TYPE_CODE(tp
);
1176 TYPE_NAME(tp1
) = obsavestring(name
, strlen(name
));
1177 if (TYPE_CODE(tp1
) == TYPE_CODE_ENUM
) {
1180 for (i
= 0; i
< TYPE_NFIELDS(tp1
); i
++)
1181 make_enum_constant(&TYPE_FIELD(tp1
,i
), tp1
);
1185 /* found as cross ref, rid of our template */
1186 if ((TYPE_FLAGS(tp
) & TYPE_FLAG_PERM
) == 0)
1189 /* stupid idea of prepending "struct" to type names */
1190 if (t
->bt
== btStruct
&& !index(TYPE_NAME(tp
), ' ')) {
1191 sprintf(name
, fmt
, TYPE_NAME(tp
));
1192 TYPE_NAME(tp
) = obsavestring(name
, strlen(name
));
1195 TYPE_NAME(tp
) = savestring(name
, strlen(name
));
1198 /* Deal with range types */
1199 if (t
->bt
== btRange
) {
1202 f
= new_field(tp
, "Low");
1203 f
->bitpos
= ax
->dnLow
;
1205 f
= new_field(tp
, "High");
1206 f
->bitpos
= ax
->dnHigh
;
1210 /* Parse all the type qualifiers now. If there are more
1211 than 6 the game will continue in the next aux */
1213 #define PARSE_TQ(tq) \
1214 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, sh);
1216 again
: PARSE_TQ(tq0
);
1231 /* Make up a complex type from a basic one. Type is passed by
1232 reference in TPP and side-effected as necessary. The type
1233 qualifier TQ says how to handle the aux symbols at AX for
1234 the symbol SX we are currently analyzing.
1235 Returns the number of aux symbols we parsed. */
1238 upgrade_type(tpp
, tq
, ax
, sh
)
1248 t
= lookup_pointer_type (*tpp
);
1249 } else if (tq
== tqProc
) {
1250 t
= lookup_function_type (*tpp
);
1251 } else if (tq
== tqArray
) {
1257 t
= make_type(TYPE_CODE_ARRAY
, 0, 0, 0);
1258 TYPE_TARGET_TYPE(t
) = *tpp
;
1260 /* Pointer to domain type (type of index) */
1261 id
= ax
->rndx
.index
;
1262 if ((rf
= ax
->rndx
.rfd
) == 0xfff)
1263 rf
= (++ax
)->isym
, off
++;
1265 fh
= get_rfd(cur_fd
, rf
);
1266 f
= new_field(t
, 0);
1267 bzero(&ss
, sizeof ss
);
1268 /* XXX */ f
->type
= parse_type(fh
->iauxBase
+ id
* sizeof(AUXU
),
1272 * This seems to be a pointer to the end of the Block defining
1273 * the type. Why it is here is magic for me, and I have no
1274 * good use for it anyways.
1278 id
= (++ax
)->rndx
.index
;
1279 if ((rf
= ax
->rndx
.rfd
) == 0xfff)
1280 rf
= (++ax
)->isym
, off
++;
1282 f
->bitpos
= (++ax
)->dnLow
; /* ?? */
1283 f
->bitsize
= (++ax
)->dnHigh
; /* ?? */
1284 rf
= (++ax
)->width
- 1; /* bit alignment */
1285 id
= TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) << 3; /* bitsize */
1288 /* Most likely an undefined type */
1290 TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) = id
>> 3;
1292 TYPE_LENGTH(t
) = (f
->bitsize
< 0) ? 0 :
1293 (f
->bitsize
- f
->bitpos
+ 1) * (id
>> 3);
1297 printf_filtered("Internal: unknown type qualifier %x\n", tq
);
1306 /* Parse a procedure descriptor record PR. Note that the procedure
1307 is parsed _after_ the local symbols, now we just make up the
1308 extra information we need into a special symbol that we insert
1309 in the procedure's main block. Note also that images that
1310 have been partially stripped (ld -x) have been deprived
1311 of local symbols, and we have to cope with them here.
1312 The procedure's code ends at BOUND */
1315 parse_procedure(pr
, bound
)
1318 struct symbol
*s
, *i
;
1319 SYMR
*sh
= (SYMR
*)pr
->isym
;
1321 struct mips_extra_func_info
*e
;
1325 /* Reuse the MIPS record */
1326 e
= (struct mips_extra_func_info
*) pr
;
1327 e
->numargs
= lookup_numargs(pr
->adr
);
1329 /* Make up our special symbol */
1330 i
= new_symbol(".gdbinfo.");
1331 SYMBOL_VALUE(i
) = (int)e
;
1332 SYMBOL_NAMESPACE(i
) = LABEL_NAMESPACE
;
1333 SYMBOL_CLASS(i
) = LOC_CONST
;
1334 SYMBOL_TYPE(i
) = builtin_type_void
;
1336 /* Make up a name for static procedures. Sigh. */
1337 if (sh
== (SYMR
*)-1) {
1338 sprintf(name
,".static_procedure@%x",pr
->adr
);
1339 sh_name
= savestring(name
, strlen(name
));
1343 sh_name
= (char*)sh
->iss
;
1344 s
= mylookup_symbol(sh_name
, top_stack
->cur_block
,
1345 VAR_NAMESPACE
, LOC_BLOCK
);
1348 b
= SYMBOL_BLOCK_VALUE(s
);
1350 s
= new_symbol(sh_name
);
1351 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1352 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1353 /* Donno its type, hope int is ok */
1354 SYMBOL_TYPE(s
) = lookup_function_type (builtin_type_int
);
1355 add_symbol(s
, top_stack
->cur_block
);
1356 /* Wont have symbols for this one */
1358 SYMBOL_BLOCK_VALUE(s
) = b
;
1359 BLOCK_FUNCTION(b
) = s
;
1360 BLOCK_START(b
) = pr
->adr
;
1361 BLOCK_END(b
) = bound
;
1362 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1363 add_block(b
, top_stack
->cur_st
);
1369 /* Parse the external symbol ES. Just call parse_symbol() after
1370 making sure we know where the aux are for it. For procedures,
1371 parsing of the PDRs has already provided all the needed
1372 information, we only parse them if SKIP_PROCEDURES is false,
1373 and only if this causes no symbol duplication */
1376 parse_external(es
, skip_procedures
)
1381 if (es
->ifd
!= ifdNil
) {
1383 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
) + cur_fd
;
1384 ax
= (AUXU
*)cur_fdr
->iauxBase
;
1386 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
);
1389 top_stack
->cur_st
= cur_stab
;
1390 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
1393 /* Reading .o files */
1394 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
) {
1396 switch (es
->asym
.st
) {
1398 case stProc
: what
= "Procedure"; n_undef_procs
++; break;
1399 case stGlobal
: what
= "Variable"; n_undef_vars
++; break;
1400 case stLabel
: what
= "Label"; n_undef_labels
++; break;
1401 default : what
= "Symbol"; break;
1405 printf_filtered("Warning: %s %s is undefined (in %s)\n", what
,
1406 es
->asym
.iss
, fdr_name(cur_fdr
->rss
));
1410 switch (es
->asym
.st
) {
1412 /* If we have full symbols we do not need more */
1413 if (skip_procedures
)
1415 if (mylookup_symbol (es
->asym
.iss
, top_stack
->cur_block
,
1416 VAR_NAMESPACE
, LOC_BLOCK
))
1422 * Note that the case of a symbol with indexNil
1423 * must be handled anyways by parse_symbol().
1425 parse_symbol(&es
->asym
, ax
);
1432 /* Parse the line number info for file descriptor FH into
1433 GDB's linetable LT. MIPS' encoding requires a little bit
1434 of magic to get things out. Note also that MIPS' line
1435 numbers can go back and forth, apparently we can live
1436 with that and do not need to reorder our linetables */
1441 struct linetable
*lt
;
1443 char *base
= (char*)fh
->cbLineOffset
;
1445 int delta
, count
, lineno
= 0;
1451 /* Scan by procedure descriptors */
1452 i
= 0; j
= 0, k
= 0;
1453 for (pr
= (PDR
*)IPDFIRST(cur_hdr
,fh
); j
< fh
->cpd
; j
++, pr
++) {
1456 /* No code for this one */
1457 if (pr
->iline
== ilineNil
||
1458 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1461 * Aurgh! To know where to stop expanding we
1464 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1465 if (pr
[l
].iline
!= -1)
1467 if (l
== (fh
->cpd
- j
))
1472 * When procedures are moved around the linenumbers
1473 * are attributed to the next procedure up
1475 if (pr
->iline
>= halt
) continue;
1477 base
= (char*)pr
->cbLineOffset
;
1478 l
= pr
->adr
>> 2; /* in words */
1479 halt
+= (pr
->adr
>> 2) - pr
->iline
;
1480 for (lineno
= pr
->lnLow
; l
< halt
;) {
1481 count
= *base
& 0x0f;
1482 delta
= *base
++ >> 4;
1484 delta
= (base
[0] << 8) | (base
[1] & 0xff);
1487 lineno
+= delta
;/* first delta is 0 */
1488 k
= add_line(lt
, lineno
, l
, k
);
1495 /* Parse the symbols of the file described by FH, whose index is F_IDX.
1496 BOUND is the highest core address of this file's procedures */
1499 parse_one_file(fh
, f_idx
, bound
)
1506 /* Parse local symbols first */
1508 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
1509 sh
= (SYMR
*) (fh
->isymBase
) + s_idx
;
1511 parse_symbol(sh
, fh
->iauxBase
);
1514 /* Procedures next, note we need to look-ahead to
1515 find out where the procedure's code ends */
1517 for (s_idx
= 0; s_idx
< fh
->cpd
-1; s_idx
++) {
1518 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + s_idx
;
1519 parse_procedure(pr
, pr
[1].adr
); /* next proc up */
1522 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + s_idx
;
1523 parse_procedure(pr
, bound
); /* next file up */
1526 /* Linenumbers. At the end, check if we can save memory */
1527 parse_lines(fh
, LINETABLE(cur_stab
));
1528 if (LINETABLE(cur_stab
)->nitems
< fh
->cline
)
1529 shrink_linetable(cur_stab
);
1533 /* Master parsing procedure. Parses the symtab described by the
1534 symbolic header HDR. If INCREMENTAL is true we are called
1535 by add-file and must preserve the old symtabs */
1537 parse_partial_symbols(hdr
, incremental
)
1540 int f_idx
, s_idx
, h_max
;
1541 CORE_ADDR dummy
, *prevhigh
;
1542 /* Running pointers */
1550 * Only parse the External symbols, and the Relative FDR.
1551 * Fixup enough of the loader symtab to be able to use it.
1552 * Allocate space only for the file`s portions we need to
1558 max_glevel
= MIN_GLEVEL
;
1560 /* Allocate the map FDR -> PST.
1561 Minor hack: -O3 images might claim some global data belongs
1562 to FDR -1. We`ll go along with that */
1563 fdr_to_pst
= (struct pst_map
*)xzalloc((hdr
->ifdMax
+1) * sizeof *fdr_to_pst
);
1566 struct partial_symtab
* pst
= new_psymtab("");
1567 fdr_to_pst
[-1].pst
= pst
;
1571 /* Now scan the FDRs, mostly for dependencies */
1572 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++)
1573 (void) parse_fdr(f_idx
, 1);
1575 /* Take a good guess at how many symbols we might ever need */
1576 h_max
= hdr
->iextMax
;
1578 /* Parse externals: two passes because they can be ordered
1581 /* Pass 1: Presize and partition the list */
1582 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1583 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1584 fdr_to_pst
[esh
->ifd
].n_globals
++;
1587 if (global_psymbols
.list
) {
1588 global_psymbols
.list
= (struct partial_symbol
*)
1589 xrealloc( global_psymbols
.list
, (h_max
+
1590 global_psymbols
.size
) * sizeof(struct partial_symbol
));
1591 global_psymbols
.next
= global_psymbols
.list
+ global_psymbols
.size
;
1592 global_psymbols
.size
+= h_max
;
1594 global_psymbols
.list
= (struct partial_symbol
*)
1595 xmalloc( h_max
* sizeof(struct partial_symbol
));
1596 global_psymbols
.size
= h_max
;
1597 global_psymbols
.next
= global_psymbols
.list
;
1600 s_idx
= global_psymbols
.next
- global_psymbols
.list
;
1601 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++) {
1602 fdr_to_pst
[f_idx
].pst
->globals_offset
= s_idx
;
1603 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
1606 /* Pass 2: fill in symbols */
1607 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1608 register struct partial_symbol
*p
;
1609 enum misc_function_type misc_type
= mf_text
;
1610 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1612 if (esh
->asym
.sc
== scUndefined
|| esh
->asym
.sc
== scNil
)
1614 p
= new_psymbol(&global_psymbols
, esh
->asym
.iss
, esh
->ifd
);
1615 SYMBOL_VALUE(p
) = esh
->asym
.value
;
1616 SYMBOL_NAMESPACE(p
) = VAR_NAMESPACE
;
1618 switch (esh
->asym
.st
) {
1620 SYMBOL_CLASS(p
) = LOC_BLOCK
;
1623 SYMBOL_CLASS(p
) = LOC_STATIC
;
1624 misc_type
= mf_data
;
1627 SYMBOL_CLASS(p
) = LOC_LABEL
;
1630 misc_type
= mf_unknown
;
1631 complain (&unknown_ext_complaint
, SYMBOL_NAME(p
));
1633 prim_record_misc_function (SYMBOL_NAME(p
),
1639 /* The array (of lists) of globals must be sorted.
1640 Take care, since we are at it, of pst->texthigh.
1642 NOTE: The way we handle textlow/high is incorrect, but good
1643 enough for a first approximation. The case we fail is on a
1644 file "foo.c" that looks like
1646 #include "bar.c" -- this contains proc2()
1648 where proc3() is attributed to bar.c. But since this is a
1649 dependent file it will cause loading of foo.c as well, so
1650 everything will be fine at the end. */
1653 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
1654 struct partial_symtab
*pst
= fdr_to_pst
[f_idx
].pst
;
1655 if (pst
->n_global_syms
> 1)
1656 qsort (global_psymbols
.list
+ pst
->globals_offset
,
1657 pst
->n_global_syms
, sizeof (struct partial_symbol
),
1660 *prevhigh
= pst
->textlow
;
1661 prevhigh
= &pst
->texthigh
;
1665 /* Mark the last code address, and remember it for later */
1666 *prevhigh
= END_OF_TEXT_SEGMENT(filhdr
);
1667 hdr
->cbDnOffset
= END_OF_TEXT_SEGMENT(filhdr
);
1670 free(&fdr_to_pst
[-1]);
1675 /* Do the initial analisys of the F_IDX-th file descriptor.
1676 Allocates a partial symtab for it, and builds the list
1677 of dependent files by recursion. LEV says at which level
1678 of recursion we are called (to pretty up debug traces) */
1680 static struct partial_symtab
*
1681 parse_fdr(f_idx
, lev
)
1685 register struct partial_symtab
*pst
;
1688 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + f_idx
;
1690 /* Use this to indicate into which symtab this file was parsed */
1692 return (struct partial_symtab
*) fh
->ioptBase
;
1694 /* Debuggability level */
1695 if (compare_glevel(max_glevel
, fh
->glevel
) < 0)
1696 max_glevel
= fh
->glevel
;
1698 /* Make a new partial_symtab */
1699 pst
= new_psymtab(fh
->rss
);
1704 pst
->textlow
= fh
->adr
;
1705 pst
->texthigh
= fh
->cpd
; /* To be fixed later */
1707 /* Reverse mapping PST -> FDR */
1708 pst
->ldsymoff
= f_idx
;
1710 fdr_to_pst
[f_idx
].pst
= pst
;
1711 fh
->ioptBase
= (int)pst
;
1713 /* Analyze its dependencies */
1718 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
1719 /* ...then presumably a .h file: drop reverse depends .h->.c */
1720 for (; s_id0
< fh
->crfd
; s_id0
++) {
1721 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
1723 s_id0
++; /* Skip self-dependency */
1728 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
1729 pst
->dependencies
= (struct partial_symtab
**)
1730 obstack_alloc (psymbol_obstack
,
1731 pst
->number_of_dependencies
* sizeof(char*));
1732 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
1733 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
1735 pst
->dependencies
[s_idx
-s_id0
] = parse_fdr(*rh
, lev
+1);
1743 /* Ancillary function to psymtab_to_symtab(). Does all the work
1744 for turning the partial symtab PST into a symtab, recurring
1745 first on all dependent psymtabs */
1747 static void psymtab_to_symtab_1(pst
)
1748 struct partial_symtab
*pst
;
1758 pending_list
= (struct pending
**) cur_hdr
->cbOptOffset
;
1759 if (pending_list
== 0) {
1760 pending_list
= (struct pending
**)
1761 xzalloc(cur_hdr
->ifdMax
* sizeof(struct pending
*));
1762 cur_hdr
->cbOptOffset
= (int)pending_list
;
1765 /* How many symbols will we need */
1766 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
1767 if (pst
->ldsymoff
== -1) {
1769 st
= new_symtab( "unknown", f_max
, 0);
1771 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + pst
->ldsymoff
;
1772 f_max
+= fh
->csym
+ fh
->cpd
;
1773 st
= new_symtab(pst
->filename
, 2 * f_max
, 2 * fh
->cline
);
1777 * Read in all partial symbtabs on which this one is dependent.
1778 * NOTE that we do have circular dependencies, sigh.
1780 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
1781 if (!pst
->dependencies
[i
]->readin
) {
1783 * DO NOT inform about additional files that need to
1784 * be read in, it would only annoy the user.
1786 psymtab_to_symtab_1(pst
->dependencies
[i
]);
1789 /* Now read the symbols for this symtab */
1791 cur_fd
= pst
->ldsymoff
;
1795 /* Get a new lexical context */
1798 top_stack
->cur_st
= cur_stab
;
1799 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab
),
1801 BLOCK_START(top_stack
->cur_block
) = fh
? fh
->adr
: 0;
1802 BLOCK_END(top_stack
->cur_block
) = 0;
1803 top_stack
->blocktype
= stFile
;
1804 top_stack
->maxsyms
= f_max
;
1805 top_stack
->cur_type
= 0;
1806 top_stack
->procadr
= 0;
1807 top_stack
->numargs
= 0;
1809 /* Parse locals and procedures */
1811 parse_one_file(fh
, cur_fd
, (cur_fd
== (cur_hdr
->ifdMax
- 1)) ?
1812 cur_hdr
->cbDnOffset
: fh
[1].adr
);
1814 /* .. and our share of externals.
1815 XXX use the global list to speed up things here. how ? */
1816 top_stack
->blocktype
= stFile
;
1817 top_stack
->maxsyms
= cur_hdr
->isymMax
+ cur_hdr
->ipdMax
+ cur_hdr
->iextMax
;
1818 for (i
= 0; i
< cur_hdr
->iextMax
; i
++) {
1819 register EXTR
*esh
= (EXTR
*) (cur_hdr
->cbExtOffset
) + i
;
1820 if (esh
->ifd
== cur_fd
)
1821 parse_external(esh
, 1);
1824 /* If there are undefined, tell the user */
1825 if (n_undef_symbols
) {
1826 printf_filtered("File %s contains %d unresolved references:",
1827 st
->filename
, n_undef_symbols
);
1828 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
1829 n_undef_vars
, n_undef_procs
, n_undef_labels
);
1830 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
1836 * Sort the symbol table now, we are done adding symbols to it.
1838 sort_symtab_syms(st
);
1844 /* Ancillary parsing procedures. */
1846 /* Lookup the type at relative index RN. Return it in TPP
1847 if found and in any event come up with its name PNAME.
1848 Return value says how many aux symbols we ate */
1851 cross_ref(rn
, tpp
, pname
)
1858 /* Escape index means 'the next one' */
1859 if (rn
->rfd
== 0xfff)
1860 rf
= *(unsigned *) (rn
+ 1);
1866 *pname
= "<undefined>";
1869 * Find the relative file descriptor and the symbol in it
1871 FDR
*fh
= get_rfd(cur_fd
, rf
);
1876 * If we have processed this symbol then we left a forwarding
1877 * pointer to the corresponding GDB symbol. If not, we`ll put
1878 * it in a list of pending symbols, to be processed later when
1879 * the file f will be. In any event, we collect the name for
1880 * the type here. Which is why we made a first pass at
1883 sh
= (SYMR
*) (fh
->isymBase
) + rn
->index
;
1885 /* Careful, we might be looking at .o files */
1886 *pname
= (UNSAFE_DATA_ADDR(sh
->iss
)) ? "<undefined>" :
1889 /* Have we parsed it ? */
1890 if ((!UNSAFE_DATA_ADDR(sh
->value
)) && (sh
->st
== stParsed
)) {
1891 t
= (struct type
*) sh
->value
;
1896 /* Avoid duplicates */
1897 p
= is_pending_symbol(fh
, sh
);
1902 add_pending(fh
, sh
, *tpp
);
1905 return (rn
->rfd
== 0xfff);
1909 /* Quick&dirty lookup procedure, to avoid the MI ones that require
1910 keeping the symtab sorted */
1912 static struct symbol
*
1913 mylookup_symbol (name
, block
, namespace, class)
1915 register struct block
*block
;
1916 enum namespace namespace;
1917 enum address_class
class;
1919 register int bot
, top
, inc
;
1920 register struct symbol
*sym
;
1923 top
= BLOCK_NSYMS(block
);
1926 sym
= BLOCK_SYM(block
, bot
);
1927 if (SYMBOL_NAME(sym
)[0] == inc
1928 && SYMBOL_NAMESPACE(sym
) == namespace
1929 && SYMBOL_CLASS(sym
) == class
1930 && !strcmp(SYMBOL_NAME(sym
), name
))
1934 if (block
= BLOCK_SUPERBLOCK (block
))
1935 return mylookup_symbol (name
, block
, namespace, class);
1940 /* Add a new symbol S to a block B */
1947 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
1948 if (b
== top_stack
->cur_block
&&
1949 BLOCK_NSYMS(b
) > top_stack
->maxsyms
)
1950 printf_filtered("Internal: block at @%x overfilled (by %d)\n",
1951 b
, BLOCK_NSYMS(b
) - top_stack
->maxsyms
);
1954 /* Add a new block B to a symtab S */
1961 struct blockvector
*bv
= BLOCKVECTOR(s
);
1963 bv
= (struct blockvector
*)xrealloc(bv
, sizeof(struct blockvector
) +
1964 BLOCKVECTOR_NBLOCKS(bv
) * sizeof(bv
->block
));
1965 if (bv
!= BLOCKVECTOR(s
))
1966 BLOCKVECTOR(s
) = bv
;
1968 BLOCKVECTOR_BLOCK(bv
, BLOCKVECTOR_NBLOCKS(bv
)++) = b
;
1971 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
1972 MIPS' linenumber encoding might need more than one byte
1973 to describe it, LAST is used to detect these continuation lines */
1976 add_line(lt
, lineno
, adr
, last
)
1977 struct linetable
*lt
;
1981 last
= -2; /* make sure we record first line */
1983 if (last
== lineno
) /* skip continuation lines */
1986 lt
->item
[lt
->nitems
].line
= lineno
;
1987 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
1993 /* Comparison functions, used when sorting things */
1995 /* Symtabs must be ordered viz the code segments they cover */
1998 compare_symtabs( s1
, s2
)
1999 struct symtab
**s1
, **s2
;
2001 /* "most specific" first */
2003 register struct block
*b1
, *b2
;
2004 b1
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1
),GLOBAL_BLOCK
);
2005 b2
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2
),GLOBAL_BLOCK
);
2006 if (BLOCK_END(b1
) == BLOCK_END(b2
))
2007 return BLOCK_START(b1
) - BLOCK_START(b2
);
2008 return BLOCK_END(b1
) - BLOCK_END(b2
);
2012 /* Partial Symtabs, same */
2015 compare_psymtabs( s1
, s2
)
2016 struct partial_symtab
**s1
, **s2
;
2018 /* Perf twist: put the ones with no code at the end */
2020 register int a
= (*s1
)->textlow
;
2021 register int b
= (*s2
)->textlow
;
2030 /* Partial symbols are compared lexicog by their print names */
2033 compare_psymbols (s1
, s2
)
2034 register struct partial_symbol
*s1
, *s2
;
2037 *st1
= SYMBOL_NAME(s1
),
2038 *st2
= SYMBOL_NAME(s2
);
2040 return (st1
[0] - st2
[0] ? st1
[0] - st2
[0] :
2041 strcmp(st1
+ 1, st2
+ 1));
2044 /* Blocks with a smaller low bound should come first */
2046 static int compare_blocks(b1
,b2
)
2047 struct block
**b1
, **b2
;
2049 register int addr_diff
;
2051 addr_diff
= (BLOCK_START((*b1
))) - (BLOCK_START((*b2
)));
2053 return (BLOCK_END((*b1
))) - (BLOCK_END((*b2
)));
2058 /* Sorting and reordering procedures */
2060 /* Sort the blocks of a symtab S.
2061 Reorder the blocks in the blockvector by code-address,
2062 as required by some MI search routines */
2068 struct blockvector
*bv
= BLOCKVECTOR(s
);
2070 if (BLOCKVECTOR_NBLOCKS(bv
) <= 2) {
2072 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) == 0)
2073 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = 0;
2077 * This is very unfortunate: normally all functions are compiled in
2078 * the order they are found, but if the file is compiled -O3 things
2079 * are very different. It would be nice to find a reliable test
2080 * to detect -O3 images in advance.
2082 if (BLOCKVECTOR_NBLOCKS(bv
) > 3)
2083 qsort(&BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
),
2084 BLOCKVECTOR_NBLOCKS(bv
) - FIRST_LOCAL_BLOCK
,
2085 sizeof(struct block
*),
2089 register CORE_ADDR high
= 0;
2090 register int i
, j
= BLOCKVECTOR_NBLOCKS(bv
);
2092 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
2093 if (high
< BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
)))
2094 high
= BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
));
2095 BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = high
;
2098 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) =
2099 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
));
2101 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2102 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2103 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2104 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2107 /* Sort the symtab list, as required by some search procedures.
2108 We want files ordered to make them look right to users, and for
2109 searching (see block_for_pc). */
2115 struct symtab
*stab
;
2116 struct symtab
**all_symtabs
= (struct symtab
**)
2117 obstack_alloc (psymbol_obstack
,
2118 all_symtabs_count
* sizeof (struct symtab
*));
2120 /* Create an array of pointers to all the symtabs. */
2121 for (i
= 0, stab
= symtab_list
;
2122 i
< all_symtabs_count
;
2123 i
++, stab
= stab
->next
) {
2124 all_symtabs
[i
] = stab
;
2125 /* FIXME: Only do this for new symtabs ??? */
2126 sort_blocks(all_symtabs
[i
]);
2129 qsort(all_symtabs
, all_symtabs_count
,
2130 sizeof(struct symtab
*), compare_symtabs
);
2132 /* Re-construct the symtab list, but now it is sorted. */
2133 for (i
= 0; i
< all_symtabs_count
-1; i
++)
2134 all_symtabs
[i
]->next
= all_symtabs
[i
+1];
2135 all_symtabs
[i
]->next
= 0;
2136 symtab_list
= all_symtabs
[0];
2137 obstack_free (psymbol_obstack
, all_symtabs
);
2140 /* Sort the partial symtab list, as required by some search procedures */
2142 static reorder_psymtabs()
2145 struct partial_symtab
*pstab
;
2148 * PC lookups stop at the first psymtab such that
2149 * textlow <= PC < texthigh
2151 /* Create an array of pointers to all the partial_symtabs. */
2152 struct partial_symtab
**all_psymtabs
= (struct partial_symtab
**)
2153 obstack_alloc (psymbol_obstack
,
2154 all_psymtabs_count
*sizeof(struct partial_symtab
*));
2155 for (i
= 0, pstab
= partial_symtab_list
;
2156 i
< all_psymtabs_count
;
2157 i
++, pstab
= pstab
->next
)
2158 all_psymtabs
[i
] = pstab
;
2160 qsort(all_psymtabs
, all_psymtabs_count
,
2161 sizeof(struct partial_symtab
*), compare_psymtabs
);
2163 /* Re-construct the partial_symtab_list, but now it is sorted. */
2165 for (i
= 0; i
< all_psymtabs_count
-1; i
++)
2166 all_psymtabs
[i
]->next
= all_psymtabs
[i
+1];
2167 all_psymtabs
[i
]->next
= 0;
2168 partial_symtab_list
= all_psymtabs
[0];
2170 obstack_free (psymbol_obstack
, all_psymtabs
);
2175 /* Constructor/restructor/destructor procedures */
2177 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2178 MAXSYMS and linenumbers MAXLINES we'll put in it */
2182 new_symtab(name
, maxsyms
, maxlines
)
2185 struct symtab
*s
= (struct symtab
*) xzalloc(sizeof(struct symtab
));
2188 LINETABLE(s
) = new_linetable(maxlines
);
2192 /* All symtabs must have at least two blocks */
2193 BLOCKVECTOR(s
) = new_bvect(2);
2194 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
) = new_block(maxsyms
);
2195 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), STATIC_BLOCK
) = new_block(maxsyms
);
2196 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
),STATIC_BLOCK
)) =
2197 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
);
2199 s
->free_code
= free_linetable
;
2201 /* Link the new symtab into the list of such. */
2202 s
->next
= symtab_list
;
2205 all_symtabs_count
++;
2210 /* Cleanup before loading a fresh image */
2212 static destroy_all_symtabs()
2219 all_symtabs_count
= 0;
2220 current_source_symtab
= 0;
2224 /* Allocate a new partial_symtab NAME */
2226 static struct partial_symtab
*
2230 struct partial_symtab
*pst
;
2232 pst
= (struct partial_symtab
*)
2233 obstack_alloc (psymbol_obstack
, sizeof (*pst
));
2234 bzero (pst
, sizeof (*pst
));
2236 if (name
== (char*)-1) /* FIXME -- why not null here? */
2237 pst
->filename
= "<no name>";
2239 pst
->filename
= name
;
2241 pst
->next
= partial_symtab_list
;
2242 partial_symtab_list
= pst
;
2243 all_psymtabs_count
++;
2245 /* Keep a backpointer to the file`s symbols */
2246 pst
->ldsymlen
= (int)cur_hdr
;
2248 /* The way to turn this into a symtab is to call... */
2249 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
2255 /* Allocate a new NAME psymbol from LIST, extending it if necessary.
2256 The psymbol belongs to the psymtab at index PST_IDX */
2258 static struct partial_symbol
*
2259 new_psymbol(list
, name
, pst_idx
)
2260 struct psymbol_allocation_list
*list
;
2263 struct partial_symbol
*p
;
2264 struct partial_symtab
*pst
= fdr_to_pst
[pst_idx
].pst
;
2266 /* Lists are pre-sized, we won`t overflow */
2268 p
= list
->list
+ pst
->globals_offset
+ pst
->n_global_syms
++;
2269 SYMBOL_NAME(p
) = name
;
2274 /* Allocate a linetable array of the given SIZE */
2277 struct linetable
*new_linetable(size
)
2279 struct linetable
*l
;
2281 size
= size
* sizeof(l
->item
) + sizeof(struct linetable
);
2282 l
= (struct linetable
*)xmalloc(size
);
2287 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2288 I am not so sure about the 3.4 ones */
2290 static shrink_linetable(s
)
2293 struct linetable
*l
= new_linetable(LINETABLE(s
)->nitems
);
2295 bcopy(LINETABLE(s
), l
,
2296 LINETABLE(s
)->nitems
* sizeof(l
->item
) + sizeof(struct linetable
));
2297 free (LINETABLE(s
));
2301 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2304 struct blockvector
*new_bvect(nblocks
)
2306 struct blockvector
*bv
;
2309 size
= sizeof(struct blockvector
) + nblocks
* sizeof(struct block
*);
2310 bv
= (struct blockvector
*) xzalloc(size
);
2312 BLOCKVECTOR_NBLOCKS(bv
) = nblocks
;
2317 /* Allocate and zero a new block of MAXSYMS symbols */
2320 struct block
*new_block(maxsyms
)
2322 int size
= sizeof(struct block
) + (maxsyms
-1) * sizeof(struct symbol
*);
2323 struct block
*b
= (struct block
*)xzalloc(size
);
2328 /* Ooops, too big. Shrink block B in symtab S to its minimal size */
2330 static struct block
*
2336 struct blockvector
*bv
= BLOCKVECTOR(s
);
2339 /* Just get a new one, copy, and fix references to the old one */
2341 new = (struct block
*)xmalloc(sizeof(struct block
) +
2342 (BLOCK_NSYMS(b
)-1) * sizeof(struct symbol
*));
2344 bcopy(b
, new, sizeof(*new) + (BLOCK_NSYMS(b
) - 1) * sizeof(struct symbol
*));
2346 /* Should chase pointers to old one. Fortunately, that`s just
2347 the block`s function and inferior blocks */
2348 if (BLOCK_FUNCTION(b
) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(b
)) == b
)
2349 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(b
)) = new;
2350 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2351 if (BLOCKVECTOR_BLOCK(bv
,i
) == b
)
2352 BLOCKVECTOR_BLOCK(bv
,i
) = new;
2353 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) == b
)
2354 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) = new;
2359 /* Create a new symbol with printname NAME */
2366 struct symbol
*s
= (struct symbol
*)
2367 obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
2369 bzero (s
, sizeof (*s
));
2370 SYMBOL_NAME(s
) = name
;
2374 /* Create a new type with printname NAME */
2381 struct type
*t
= (struct type
*)
2382 obstack_alloc (symbol_obstack
, sizeof (struct type
));
2384 bzero (t
, sizeof (*t
));
2385 TYPE_NAME(t
) = name
;
2389 /* Create and initialize a new type with printname NAME.
2390 CODE and LENGTH are the initial info we put in,
2391 UNS says whether the type is unsigned or not. */
2395 make_type(code
, length
, uns
, name
)
2396 enum type_code code
;
2400 register struct type
*type
;
2402 type
= (struct type
*) xzalloc(sizeof(struct type
));
2403 TYPE_CODE(type
) = code
;
2404 TYPE_LENGTH(type
) = length
;
2405 TYPE_FLAGS(type
) = uns
? TYPE_FLAG_UNSIGNED
: 0;
2406 TYPE_NAME(type
) = name
;
2411 /* Allocate a new field named NAME to the type TYPE */
2414 struct field
*new_field(type
,name
)
2420 /* Fields are kept in an array */
2421 if (TYPE_NFIELDS(type
))
2422 TYPE_FIELDS(type
) = (struct field
*)xrealloc(TYPE_FIELDS(type
),
2423 (TYPE_NFIELDS(type
)+1) * sizeof(struct field
));
2425 TYPE_FIELDS(type
) = (struct field
*)xzalloc(2*sizeof(struct field
));
2426 f
= &(TYPE_FIELD(type
,TYPE_NFIELDS(type
)++));
2427 bzero(f
, sizeof(struct field
));
2433 /* Make an enum constant for a member F of an enumerated type T */
2436 make_enum_constant(f
,t
)
2442 * This is awful, but that`s the way it is supposed to be
2443 * (BTW, no need to free the real 'type', it's a builtin)
2445 f
->type
= (struct type
*) f
->bitpos
;
2447 s
= new_symbol(f
->name
);
2448 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2449 SYMBOL_CLASS(s
) = LOC_CONST
;
2451 SYMBOL_VALUE(s
) = f
->bitpos
;
2452 add_symbol(s
, top_stack
->cur_block
);
2457 /* Things used for calling functions in the inferior.
2458 These functions are exported to our companion
2459 mips-dep.c file and are here because they play
2460 with the symbol-table explicitly. */
2463 /* Need to make a new symbol on the fly for the dummy
2464 frame we put on the stack. Which goes in the.. */
2466 static struct symtab
*dummy_symtab
;
2468 /* Make up a dummy symbol for the code we put at END_PC,
2469 of size SIZE, invoking a function with NARGS arguments
2470 and using a frame of FRAMESIZE bytes */
2472 mips_create_dummy_symbol(end_pc
, size
, nargs
, framesize
)
2476 struct mips_extra_func_info
*gdbinfo
;
2478 /* Allocate symtab if not done already */
2479 if (dummy_symtab
== 0)
2480 dummy_symtab
= new_symtab(".dummy_symtab.", 100, 0);
2482 /* Make a new block. Only needs one symbol */
2484 BLOCK_START(bl
) = end_pc
- size
;
2485 BLOCK_END(bl
) = end_pc
;
2487 BLOCK_SUPERBLOCK(bl
) =
2488 BLOCKVECTOR_BLOCK(BLOCKVECTOR(dummy_symtab
),GLOBAL_BLOCK
);
2489 add_block(bl
, dummy_symtab
);
2490 sort_blocks(dummy_symtab
);
2492 BLOCK_FUNCTION(bl
) = new_symbol("??");
2493 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(bl
)) = bl
;
2494 g
= new_symbol(".gdbinfo.");
2495 BLOCK_SYM(bl
,BLOCK_NSYMS(bl
)++) = g
;
2497 SYMBOL_NAMESPACE(g
) = LABEL_NAMESPACE
;
2498 SYMBOL_CLASS(g
) = LOC_CONST
;
2499 SYMBOL_TYPE(g
) = builtin_type_void
;
2500 gdbinfo
= (struct mips_extra_func_info
*)
2501 xzalloc(sizeof(struct mips_extra_func_info
));
2503 SYMBOL_VALUE(g
) = (long) gdbinfo
;
2505 gdbinfo
->numargs
= nargs
;
2506 gdbinfo
->framesize
= framesize
;
2507 gdbinfo
->framereg
= 29;
2508 gdbinfo
->pcreg
= 31;
2509 gdbinfo
->regmask
= -2;
2510 gdbinfo
->regoffset
= -4;
2511 gdbinfo
->fregmask
= 0; /* XXX */
2512 gdbinfo
->fregoffset
= 0; /* XXX */
2515 /* We just returned from the dummy code at END_PC, drop its symbol */
2517 mips_destroy_dummy_symbol(end_pc
)
2520 struct blockvector
*bv
= BLOCKVECTOR(dummy_symtab
);
2523 bl
= block_for_pc(end_pc
);
2524 free(BLOCK_FUNCTION(bl
));
2525 free(SYMBOL_VALUE(BLOCK_SYM(bl
,0)));
2526 free(BLOCK_SYM(bl
,0));
2528 for (i
= FIRST_LOCAL_BLOCK
; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2529 if (BLOCKVECTOR_BLOCK(bv
,i
) == bl
)
2531 for (; i
< BLOCKVECTOR_NBLOCKS(bv
) - 1; i
++)
2532 BLOCKVECTOR_BLOCK(bv
,i
) = BLOCKVECTOR_BLOCK(bv
,i
+1);
2533 BLOCKVECTOR_NBLOCKS(bv
)--;
2534 sort_blocks(dummy_symtab
);
2539 /* Sigtramp: make sure we have all the necessary information
2540 about the signal trampoline code. Since the official code
2541 from MIPS does not do so, we make up that information ourselves.
2542 If they fix the library (unlikely) this code will neutralize itself. */
2549 struct block
*b
, *b0
;
2551 sigtramp_address
= -1;
2553 /* We know it is sold as sigvec */
2554 s
= lookup_symbol("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
2556 /* Most programs do not play with signals */
2560 b0
= SYMBOL_BLOCK_VALUE(s
);
2562 /* A label of sigvec, to be more precise */
2563 s
= lookup_symbol("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
2565 /* But maybe this program uses its own version of sigvec */
2569 sigtramp_address
= SYMBOL_VALUE(s
);
2570 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
2572 /* Did we or MIPSco fix the library ? */
2573 if (SYMBOL_CLASS(s
) == LOC_BLOCK
)
2576 /* But what symtab does it live in ? */
2577 st
= find_pc_symtab(SYMBOL_VALUE(s
));
2580 * Ok, there goes the fix: turn it into a procedure, with all the
2581 * needed info. Note we make it a nested procedure of sigvec,
2582 * which is the way the (assembly) code is actually written.
2584 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2585 SYMBOL_CLASS(s
) = LOC_BLOCK
;
2586 SYMBOL_TYPE(s
) = make_type(TYPE_CODE_FUNC
, 4, 0, 0);
2587 TYPE_TARGET_TYPE(SYMBOL_TYPE(s
)) = builtin_type_void
;
2589 /* Need a block to allocate .gdbinfo. in */
2591 SYMBOL_BLOCK_VALUE(s
) = b
;
2592 BLOCK_START(b
) = sigtramp_address
;
2593 BLOCK_END(b
) = sigtramp_end
;
2594 BLOCK_FUNCTION(b
) = s
;
2595 BLOCK_SUPERBLOCK(b
) = BLOCK_SUPERBLOCK(b0
);
2599 /* Make a .gdbinfo. for it */
2601 struct mips_extra_func_info
*e
=
2602 (struct mips_extra_func_info
*)
2603 xzalloc(sizeof(struct mips_extra_func_info
));
2605 e
->numargs
= 0; /* the kernel thinks otherwise */
2606 /* align_longword(sigcontext + SIGFRAME) */
2607 e
->framesize
= 0x150;
2608 e
->framereg
= SP_REGNUM
;
2611 e
->regoffset
= -(41 * sizeof(int));
2613 e
->fregoffset
= -(37 * sizeof(int));
2616 s
= new_symbol(".gdbinfo.");
2617 SYMBOL_VALUE(s
) = (int) e
;
2618 SYMBOL_NAMESPACE(s
) = LABEL_NAMESPACE
;
2619 SYMBOL_CLASS(s
) = LOC_CONST
;
2620 SYMBOL_TYPE(s
) = builtin_type_void
;
2623 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
2627 /* Initialization */
2629 static struct sym_fns ecoff_sym_fns
= {"ecoff", 5,
2630 mipscoff_new_init
, mipscoff_symfile_init
,
2631 mipscoff_symfile_read
, mipscoff_symfile_discard
};
2633 _initialize_mipsread ()
2635 add_symtab_fns (&ecoff_sym_fns
);
2637 bzero (&global_psymbols
, sizeof (global_psymbols
));
2638 bzero (&static_psymbols
, sizeof (static_psymbols
));
2640 /* Missing basic types */
2641 builtin_type_string
= make_type(TYPE_CODE_PASCAL_ARRAY
,
2643 builtin_type_complex
= make_type(TYPE_CODE_FLT
,
2644 2 * sizeof(float), 0, "complex");
2645 builtin_type_double_complex
= make_type(TYPE_CODE_FLT
,
2646 2 * sizeof(double), 0, "double_complex");
2647 builtin_type_fixed_dec
= make_type(TYPE_CODE_INT
, sizeof(int),
2648 0, "fixed_decimal");
2649 builtin_type_float_dec
= make_type(TYPE_CODE_FLT
, sizeof(double),
2650 0, "floating_decimal");
2652 /* Templates types */
2653 builtin_type_ptr
= lookup_pointer_type (builtin_type_void
);
2654 builtin_type_struct
= make_type(TYPE_CODE_STRUCT
, 0, 0, 0);
2655 builtin_type_union
= make_type(TYPE_CODE_UNION
, 0, 0, 0);
2656 builtin_type_enum
= make_type(TYPE_CODE_ENUM
, 0, 0, 0);
2657 builtin_type_range
= make_type(TYPE_CODE_RANGE
, 0, 0, 0);
2658 builtin_type_set
= make_type(TYPE_CODE_SET
, 0, 0, 0);