1 /* Read a symbol table in MIPS' format (Third-Eye).
2 Copyright 1986, 1987, 1989, 1990, 1991 Free Software Foundation, Inc.
3 Contributed by Alessandro Forin (af@cs.cmu.edu) at CMU.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This module provides three functions: mipscoff_symfile_init,
22 which initializes to read a symbol file; mipscoff_new_init, which
23 discards existing cached information when all symbols are being
24 discarded; and mipscoff_symfile_read, which reads a symbol table
27 mipscoff_symfile_read only does the minimum work necessary for letting the
28 user "name" things symbolically; it does not read the entire symtab.
29 Instead, it reads the external and static symbols and puts them in partial
30 symbol tables. When more extensive information is requested of a
31 file, the corresponding partial symbol table is mutated into a full
32 fledged symbol table by going back and reading the symbols
33 for real. mipscoff_psymtab_to_symtab() is called indirectly through
34 a pointer in the psymtab to do this. */
43 #include <sys/param.h>
47 #include <mips/syms.h>
51 #endif /* not CMUCS */
53 #include "coff/mips.h"
54 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
55 #include "aout/aout64.h"
56 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native, now */
59 struct external_filehdr f
;
60 struct external_aouthdr a
;
63 /* These must match the corresponding definition in gcc/config/xm-mips.h.
64 At some point, these should probably go into a shared include file,
65 but currently gcc and gdb do not share any directories. */
67 #define CODE_MASK 0x8F300
68 #define MIPS_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK)
69 #define MIPS_MARK_STAB(code) ((code)+CODE_MASK)
70 #define MIPS_UNMARK_STAB(code) ((code)-CODE_MASK)
71 #define STABS_SYMBOL "@stabs"
73 /* Each partial symbol table entry contains a pointer to private data for the
74 read_symtab() function to use when expanding a partial symbol table entry
75 to a full symbol table entry.
77 For mipsread this structure contains the index of the FDR that this psymtab
78 represents and a pointer to the symbol table header HDRR from the symbol
79 file that the psymtab was created from. */
81 #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
82 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
83 #define CUR_HDR(p) (PST_PRIVATE(p)->cur_hdr)
88 EXTR
**extern_tab
; /* Pointer to external symbols for this file. */
89 int extern_count
; /* Size of extern_tab. */
92 /* Things we import explicitly from other modules */
94 extern int info_verbose
;
95 extern struct block
*block_for_pc();
96 extern void sort_symtab_syms();
98 /* Various complaints about symbol reading that don't abort the process */
100 struct complaint bad_file_number_complaint
=
101 {"bad file number %d", 0, 0};
103 struct complaint unknown_ext_complaint
=
104 {"unknown external symbol %s", 0, 0};
106 struct complaint unknown_sym_complaint
=
107 {"unknown local symbol %s", 0, 0};
109 struct complaint unknown_st_complaint
=
110 {"with type %d", 0, 0};
112 struct complaint block_overflow_complaint
=
113 {"block containing %s overfilled", 0, 0};
115 struct complaint basic_type_complaint
=
116 {"cannot map MIPS basic type 0x%x", 0, 0};
118 struct complaint unknown_type_qual_complaint
=
119 {"unknown type qualifier 0x%x", 0, 0};
121 struct complaint array_bitsize_complaint
=
122 {"size of array target type not known, assuming %d bits", 0, 0};
124 struct complaint array_parse_complaint
=
125 {"array type with strange relative symbol", 0, 0};
127 struct complaint bad_tag_guess_complaint
=
128 {"guessed tag type incorrectly", 0, 0};
130 /* Macros and extra defs */
132 /* Already-parsed symbols are marked specially */
134 #define stParsed stType
136 /* Puns: hard to find whether -g was used and how */
138 #define MIN_GLEVEL GLEVEL_0
139 #define compare_glevel(a,b) \
140 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
141 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
143 /* When looking at .o files, avoid tripping over bad addresses */
145 #define SAFE_TEXT_ADDR 0x400000
146 #define SAFE_DATA_ADDR 0x10000000
148 #define UNSAFE_DATA_ADDR(p) ((unsigned)p < SAFE_DATA_ADDR || (unsigned)p > 2*SAFE_DATA_ADDR)
150 /* Things that really are local to this module */
152 /* GDB symtable for the current compilation unit */
154 static struct symtab
*cur_stab
;
156 /* MIPS symtab header for the current file */
158 static HDRR
*cur_hdr
;
160 /* Pointer to current file decriptor record, and its index */
165 /* Index of current symbol */
169 /* Note how much "debuggable" this image is. We would like
170 to see at least one FDR with full symbols */
175 /* When examining .o files, report on undefined symbols */
177 static int n_undef_symbols
, n_undef_labels
, n_undef_vars
, n_undef_procs
;
179 /* Pseudo symbol to use when putting stabs into the symbol table. */
181 static char stabs_symbol
[] = STABS_SYMBOL
;
183 /* Extra builtin types */
185 struct type
*builtin_type_complex
;
186 struct type
*builtin_type_double_complex
;
187 struct type
*builtin_type_fixed_dec
;
188 struct type
*builtin_type_float_dec
;
189 struct type
*builtin_type_string
;
191 /* Forward declarations */
193 static struct symbol
*new_symbol();
194 static struct type
*new_type();
195 static struct block
*new_block();
196 static struct symtab
*new_symtab();
197 static struct linetable
*new_linetable();
198 static struct blockvector
*new_bvect();
200 static struct type
*parse_type();
201 static struct symbol
*mylookup_symbol();
202 static struct block
*shrink_block();
203 static void sort_blocks();
205 static int compare_symtabs();
206 static int compare_psymtabs();
207 static int compare_blocks();
209 static struct partial_symtab
*new_psymtab();
210 static struct partial_symtab
*parse_fdr();
211 static int compare_psymbols();
213 static void psymtab_to_symtab_1();
214 static void add_block();
215 static void add_symbol();
216 static int add_line();
217 static struct linetable
*shrink_linetable();
218 static char* mips_next_symbol_text ();
221 /* Things we export to other modules */
223 /* Address bounds for the signal trampoline in inferior, if any */
224 /* FIXME: Nothing really seems to use this. Why is it here? */
226 CORE_ADDR sigtramp_address
, sigtramp_end
;
228 /* The entry point (starting address) of the file, if it is an executable. */
230 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
231 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
236 /* If we have a file symbol header lying around, blow it away. */
238 free ((char *)cur_hdr
);
243 mipscoff_symfile_init (sf
)
246 sf
->sym_private
= NULL
;
250 mipscoff_symfile_read(sf
, addr
, mainline
)
255 struct coff_symfile_info
*info
= (struct coff_symfile_info
*)sf
->sym_private
;
256 bfd
*abfd
= sf
->objfile
->obfd
;
257 char *name
= bfd_get_filename (abfd
);
261 int stringtab_offset
;
263 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
264 desc
= fileno ((FILE *)(abfd
->iostream
)); /* Raw file descriptor */
267 /* Position to read the symbol table. */
268 val
= lseek (desc
, (long)symtab_offset
, 0);
270 perror_with_name (name
);
272 init_minimal_symbol_collection ();
273 make_cleanup (discard_minimal_symbols
, 0);
275 /* Now that the executable file is positioned at symbol table,
276 process it and define symbols accordingly. */
278 read_mips_symtab(sf
->objfile
, desc
);
280 /* Install any minimal symbols that have been collected as the current
281 minimal symbols for this objfile. */
283 install_minimal_symbols (sf
-> objfile
);
286 /* Exported procedure: Allocate zeroed memory */
291 char *p
= xmalloc(size
);
297 /* Exported procedure: Builds a symtab from the PST partial one.
298 Restores the environment in effect when PST was created, delegates
299 most of the work to an ancillary procedure, and sorts
300 and reorders the symtab list at the end */
303 mipscoff_psymtab_to_symtab(pst
)
304 struct partial_symtab
*pst
;
313 printf_filtered("Reading in symbols for %s...", pst
->filename
);
316 /* Restore the header and list of pending typedefs */
317 cur_hdr
= CUR_HDR(pst
);
319 next_symbol_text_func
= mips_next_symbol_text
;
321 psymtab_to_symtab_1(pst
, pst
->filename
);
323 /* Match with global symbols. This only needs to be done once,
324 after all of the symtabs and dependencies have been read in. */
325 scan_file_globals (pst
->objfile
);
328 printf_filtered("done.\n");
331 /* Exported procedure: Is PC in the signal trampoline code */
334 in_sigtramp(pc
, name
)
338 if (sigtramp_address
== 0)
340 return (pc
>= sigtramp_address
&& pc
< sigtramp_end
);
343 /* File-level interface functions */
345 /* Read the symtab information from file FSYM into memory. Also,
346 return address just past end of our text segment in *END_OF_TEXT_SEGP. */
349 read_the_mips_symtab(abfd
, fsym
, end_of_text_segp
)
352 CORE_ADDR
*end_of_text_segp
;
354 int stsize
, st_hdrsize
;
357 /* Header for executable/object file we read symbols from */
358 struct coff_exec filhdr
;
360 /* We get here with DESC pointing to the symtab header. But we need
361 * other info from the initial headers */
363 myread(fsym
, &filhdr
, sizeof filhdr
);
365 if (end_of_text_segp
)
367 bfd_h_get_32 (abfd
, filhdr
.a
.text_start
) +
368 bfd_h_get_32 (abfd
, filhdr
.a
.tsize
);
370 /* Find and read the symbol table header */
371 st_hdrsize
= bfd_h_get_32 (abfd
, filhdr
.f
.f_nsyms
);
372 st_filptr
= bfd_h_get_32 (abfd
, filhdr
.f
.f_symptr
);
376 lseek(fsym
, st_filptr
, L_SET
);
377 if (st_hdrsize
> sizeof (st_hdr
)) /* Profanity check */
379 if (read(fsym
, &st_hdr
, st_hdrsize
) != st_hdrsize
)
382 /* Find out how large the symbol table is */
383 stsize
= (st_hdr
.cbExtOffset
- (st_filptr
+ st_hdrsize
))
384 + st_hdr
.iextMax
* cbEXTR
;
386 /* Allocate space for the symbol table. Read it in. */
387 cur_hdr
= (HDRR
*) xmalloc(stsize
+ st_hdrsize
);
389 memcpy(cur_hdr
, &st_hdr
, st_hdrsize
);
390 if (read(fsym
, (char *) cur_hdr
+ st_hdrsize
, stsize
) != stsize
)
393 /* Fixup file_pointers in it */
394 fixup_symtab(cur_hdr
, (char *) cur_hdr
+ st_hdrsize
,
395 st_filptr
+ st_hdrsize
);
399 error("Short read on %s", bfd_get_filename (abfd
));
403 /* Turn all file-relative pointers in the symtab described by HDR
404 into memory pointers, given that the symtab itself is located
405 at DATA in memory and F_PTR in the file. */
408 fixup_symtab( hdr
, data
, f_ptr
)
420 * These fields are useless (and empty) by now:
421 * hdr->cbDnOffset, hdr->cbOptOffset
422 * We use them for other internal purposes.
425 hdr
->cbOptOffset
= 0;
428 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
444 * Fix all string pointers inside the symtab, and
445 * the FDR records. Also fix other miscellany.
447 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
448 register unsigned code_offset
;
450 /* Header itself, and strings */
451 fh
= (FDR
*) (hdr
->cbFdOffset
) + f_idx
;
452 fh
->issBase
+= hdr
->cbSsOffset
;
454 fh
->rss
= (long)fh
->rss
+ fh
->issBase
;
457 fh
->isymBase
= (int)((SYMR
*)(hdr
->cbSymOffset
)+fh
->isymBase
);
459 /* FIXME! Probably don't want to do this here! */
460 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
461 sh
= (SYMR
*)fh
->isymBase
+ s_idx
;
462 sh
->iss
= (long) sh
->iss
+ fh
->issBase
;
468 /* cannot fix fh->ipdFirst because it is a short */
469 #define IPDFIRST(h,fh) \
470 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
472 /* Optional symbols (actually used for partial_symtabs) */
478 fh
->iauxBase
= hdr
->cbAuxOffset
+ fh
->iauxBase
* sizeof(AUXU
);
479 /* Relative file descriptor table */
480 fh
->rfdBase
= hdr
->cbRfdOffset
+ fh
->rfdBase
* sizeof(RFDT
);
484 fh
->cbLineOffset
+= hdr
->cbLineOffset
;
486 /* Procedure symbols. (XXX This should be done later) */
487 code_offset
= fh
->adr
;
488 for (s_idx
= 0; s_idx
< fh
->cpd
; s_idx
++) {
489 unsigned name
, only_ext
;
491 pr
= (PDR
*)(IPDFIRST(hdr
,fh
)) + s_idx
;
493 /* Simple rule to find files linked "-x" */
494 only_ext
= fh
->rss
== -1;
496 if (pr
->isym
== -1) {
497 /* static function */
501 name
= hdr
->cbExtOffset
+ pr
->isym
* sizeof(EXTR
);
502 sh
= &((EXTR
*)name
)->asym
;
506 sh
= (SYMR
*)fh
->isymBase
+ pr
->isym
;
507 /* Included code ? */
508 if (s_idx
== 0 && pr
->adr
!= 0)
509 code_offset
-= pr
->adr
;
512 /* Turn index into a pointer */
515 /* Fix line numbers */
516 pr
->cbLineOffset
+= fh
->cbLineOffset
;
518 /* Relocate address */
520 pr
->adr
+= code_offset
;
524 /* External symbols: fix string */
525 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
526 esh
= (EXTR
*)(hdr
->cbExtOffset
) + s_idx
;
527 esh
->asym
.iss
= esh
->asym
.iss
+ hdr
->cbSsExtOffset
;
532 /* Find a file descriptor given its index RF relative to a file CF */
540 f
= (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
541 /* Object files do not have the RFD table, all refs are absolute */
543 return (FDR
*) (cur_hdr
->cbFdOffset
) + rf
;
544 cf
= *((pRFDT
) f
->rfdBase
+ rf
);
545 return (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
548 /* Return a safer print NAME for a file descriptor */
554 if (name
== (char *) -1)
555 return "<stripped file>";
556 if (UNSAFE_DATA_ADDR(name
))
562 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
563 whether we are adding to the general symtab or not.
564 FIXME: INCREMENTAL is currently always zero, though it should not be. */
567 read_mips_symtab (objfile
, desc
)
568 struct objfile
*objfile
;
571 CORE_ADDR end_of_text_seg
;
573 read_the_mips_symtab(objfile
->obfd
, desc
, &end_of_text_seg
);
575 parse_partial_symbols(end_of_text_seg
, objfile
);
579 * Check to make sure file was compiled with -g.
580 * If not, warn the user of this limitation.
582 if (compare_glevel(max_glevel
, GLEVEL_2
) < 0) {
583 if (max_gdbinfo
== 0)
585 "\n%s not compiled with -g, debugging support is limited.\n",
588 "You should compile with -g2 or -g3 for best debugging support.\n");
594 /* Local utilities */
596 /* Map of FDR indexes to partial symtabs */
599 struct partial_symtab
*pst
; /* the psymtab proper */
600 int n_globals
; /* exported globals (external symbols) */
601 int globals_offset
; /* cumulative */
605 /* Utility stack, used to nest procedures and blocks properly.
606 It is a doubly linked list, to avoid too many alloc/free.
607 Since we might need it quite a few times it is NOT deallocated
610 static struct parse_stack
{
611 struct parse_stack
*next
, *prev
;
612 struct symtab
*cur_st
; /* Current symtab. */
613 struct block
*cur_block
; /* Block in it. */
614 int blocktype
; /* What are we parsing. */
615 int maxsyms
; /* Max symbols in this block. */
616 struct type
*cur_type
; /* Type we parse fields for. */
617 int cur_field
; /* Field number in cur_type. */
618 int procadr
; /* Start addres of this procedure */
619 int numargs
; /* Its argument count */
620 } *top_stack
; /* Top stack ptr */
623 /* Enter a new lexical context */
625 static push_parse_stack()
627 struct parse_stack
*new;
629 /* Reuse frames if possible */
630 if (top_stack
&& top_stack
->prev
)
631 new = top_stack
->prev
;
633 new = (struct parse_stack
*) xzalloc(sizeof(struct parse_stack
));
634 /* Initialize new frame with previous content */
636 register struct parse_stack
*prev
= new->prev
;
639 top_stack
->prev
= new;
641 new->next
= top_stack
;
646 /* Exit a lexical context */
648 static pop_parse_stack()
653 top_stack
= top_stack
->next
;
657 /* Cross-references might be to things we haven't looked at
658 yet, e.g. type references. To avoid too many type
659 duplications we keep a quick fixup table, an array
660 of lists of references indexed by file descriptor */
662 static struct mips_pending
{
663 struct mips_pending
*next
; /* link */
664 SYMR
*s
; /* the symbol */
665 struct type
*t
; /* its partial type descriptor */
669 /* Check whether we already saw symbol SH in file FH as undefined */
672 struct mips_pending
*is_pending_symbol(fh
, sh
)
676 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
677 register struct mips_pending
*p
;
679 /* Linear search is ok, list is typically no more than 10 deep */
680 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
686 /* Check whether we already saw type T in file FH as undefined */
689 struct mips_pending
*is_pending_type(fh
, t
)
693 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
694 register struct mips_pending
*p
;
696 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
702 /* Add a new undef symbol SH of type T */
705 add_pending(fh
, sh
, t
)
710 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
711 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
713 /* Make sure we do not make duplicates */
715 p
= (struct mips_pending
*) xmalloc(sizeof(*p
));
718 p
->next
= pending_list
[f_idx
];
719 pending_list
[f_idx
] = p
;
721 sh
->reserved
= 1; /* for quick check */
724 /* Throw away undef entries when done with file index F_IDX */
729 register struct mips_pending
*p
, *q
;
731 for (p
= pending_list
[f_idx
]; p
; p
= q
) {
735 pending_list
[f_idx
] = 0;
738 /* The number of args to a procedure is not explicit in the symtab,
739 this is the list of all those we know of.
740 This makes parsing more reasonable and avoids extra passes */
742 static struct numarg
{
743 struct numarg
*next
; /* link */
744 unsigned adr
; /* procedure's start address */
745 unsigned num
; /* arg count */
748 /* Record that the procedure at ADR takes NUM arguments. */
753 struct numarg
*n
= (struct numarg
*) xmalloc(sizeof(struct numarg
));
757 n
->next
= numargs_list
;
761 /* See if we know how many arguments the procedure at ADR takes */
766 struct numarg
*n
= numargs_list
;
768 while (n
&& n
->adr
!= adr
)
770 return (n
) ? n
->num
: -1;
773 /* Release storage when done with this file */
778 struct numarg
*n
= numargs_list
, *m
;
789 prepend_tag_kind(tag_name
, type_code
)
799 case TYPE_CODE_STRUCT
:
802 case TYPE_CODE_UNION
:
809 result
= (char*)obstack_alloc (symbol_obstack
,
810 strlen(prefix
) + strlen(tag_name
) + 1);
811 sprintf(result
, "%s%s", prefix
, tag_name
);
816 /* Parsing Routines proper. */
818 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
819 For blocks, procedures and types we open a new lexical context.
820 This is basically just a big switch on the symbol's type.
821 Return count of SYMR's handled (normally one). */
834 /* When a symbol is cross-referenced from other files/symbols
835 we mark it explicitly */
836 int pend
= (sh
->reserved
== 1);
837 enum address_class
class;
844 case stGlobal
: /* external symbol, goes into global block */
846 b
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
848 s
= new_symbol(sh
->iss
);
849 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
852 case stStatic
: /* static data, goes into current block. */
854 b
= top_stack
->cur_block
;
855 s
= new_symbol(sh
->iss
);
856 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
859 case stLocal
: /* local variable, goes into current block */
860 if (sh
->sc
== scRegister
) {
861 class = LOC_REGISTER
;
863 sh
->value
+= FP0_REGNUM
-32;
866 b
= top_stack
->cur_block
;
867 s
= new_symbol(sh
->iss
);
868 SYMBOL_VALUE(s
) = sh
->value
;
870 data
: /* Common code for symbols describing data */
871 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
872 SYMBOL_CLASS(s
) = class;
875 /* Type could be missing in a number of cases */
876 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
877 sh
->index
== 0xfffff)
878 SYMBOL_TYPE(s
) = builtin_type_int
; /* undefined? */
880 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
881 /* Value of a data symbol is its memory address */
884 case stParam
: /* arg to procedure, goes into current block */
886 top_stack
->numargs
++;
888 name
= (char*)sh
->iss
;
889 /* Special GNU C++ name. */
890 if (name
[0] == CPLUS_MARKER
&& name
[1] == 't' && name
[2] == 0)
892 s
= new_symbol(name
);
894 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
895 if (sh
->sc
== scRegister
) {
896 SYMBOL_CLASS(s
) = LOC_REGPARM
;
898 sh
->value
+= FP0_REGNUM
-32;
900 SYMBOL_CLASS(s
) = LOC_ARG
;
901 SYMBOL_VALUE(s
) = sh
->value
;
902 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
903 add_symbol(s
, top_stack
->cur_block
);
905 /* FIXME: This has not been tested. See dbxread.c */
906 /* Add the type of this parameter to the function/procedure
907 type of this block. */
908 add_param_to_type(&top_stack
->cur_block
->function
->type
,s
);
912 case stLabel
: /* label, goes into current block */
913 s
= new_symbol(sh
->iss
);
914 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
; /* so that it can be used */
915 SYMBOL_CLASS(s
) = LOC_LABEL
; /* but not misused */
916 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
917 SYMBOL_TYPE(s
) = builtin_type_int
;
918 add_symbol(s
, top_stack
->cur_block
);
921 case stProc
: /* Procedure, usually goes into global block */
922 case stStaticProc
: /* Static procedure, goes into current block */
923 s
= new_symbol(sh
->iss
);
924 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
925 SYMBOL_CLASS(s
) = LOC_BLOCK
;
926 /* Type of the return value */
927 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
928 t
= builtin_type_int
;
930 t
= parse_type(ax
+ sh
->index
, sh
, 0);
931 b
= top_stack
->cur_block
;
932 if (sh
->st
== stProc
) {
933 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
934 /* The next test should normally be true,
935 but provides a hook for nested functions
936 (which we don't want to make global). */
937 if (b
== BLOCKVECTOR_BLOCK(bv
, STATIC_BLOCK
))
938 b
= BLOCKVECTOR_BLOCK(bv
, GLOBAL_BLOCK
);
942 /* Make a type for the procedure itself */
944 /* FIXME: This has not been tested yet! See dbxread.c */
945 /* Generate a template for the type of this function. The
946 types of the arguments will be added as we read the symbol
948 bcopy(SYMBOL_TYPE(s
),lookup_function_type(t
),sizeof(struct type
));
950 SYMBOL_TYPE(s
) = lookup_function_type (t
);
953 /* Create and enter a new lexical context */
954 b
= new_block(top_stack
->maxsyms
);
955 SYMBOL_BLOCK_VALUE(s
) = b
;
956 BLOCK_FUNCTION(b
) = s
;
957 BLOCK_START(b
) = BLOCK_END(b
) = sh
->value
;
958 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
959 add_block(b
, top_stack
->cur_st
);
961 /* Not if we only have partial info */
962 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
966 top_stack
->cur_block
= b
;
967 top_stack
->blocktype
= sh
->st
;
968 top_stack
->cur_type
= SYMBOL_TYPE(s
);
969 top_stack
->cur_field
= -1;
970 top_stack
->procadr
= sh
->value
;
971 top_stack
->numargs
= 0;
973 sh
->value
= (long) SYMBOL_TYPE(s
);
977 #ifndef btVoid /* btVoid was added late. */
980 /* These new symbol types have been recently added to SGI machines. */
994 case stBlock
: /* Either a lexical block, or some type */
996 top_stack
->blocktype
= stBlock
;
997 if (sh
->sc
== scInfo
) { /* structure/union/enum def */
999 sh
->st
== stStruct
? TYPE_CODE_STRUCT
1000 : sh
->st
== stUnion
? TYPE_CODE_UNION
1001 : sh
->st
== stEnum
? TYPE_CODE_ENUM
1008 s
= new_symbol(sh
->iss
);
1009 SYMBOL_NAMESPACE(s
) = STRUCT_NAMESPACE
;
1010 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1011 SYMBOL_VALUE(s
) = 0;
1012 add_symbol(s
, top_stack
->cur_block
);
1014 /* First count the number of fields. */
1015 for (tsym
= sh
+1; tsym
->st
!= stEnd
; tsym
++)
1016 if (tsym
->st
== stMember
) {
1017 if (nfields
== 0 && type_code
== TYPE_CODE_UNDEF
)
1018 /* If the type of the member is Nil (or Void)
1019 assume the tag is an enumeration. */
1020 if (tsym
->index
== indexNil
1021 || ax
[tsym
->index
].ti
.bt
== btNil
1022 || ax
[tsym
->index
].ti
.bt
== btVoid
)
1023 type_code
= TYPE_CODE_ENUM
;
1025 if (tsym
->value
> max_value
)
1026 max_value
= tsym
->value
;
1028 else if (tsym
->st
== stBlock
1029 || tsym
->st
== stParsed
) {
1030 if (tsym
->sc
== scVariant
) ; /*UNIMPLEMENTED*/
1031 if (tsym
->index
!= 0)
1032 tsym
= ((SYMR
*)cur_fdr
->isymBase
)
1037 /* There is no guaranteed way to distinguish struct,
1038 unions, and enums at this point. This is a bug in the
1039 original design (that has been fixed with the
1040 recent addition of the stStruct, stUnion, and stEnum
1041 symbol types.) The way you can tell is if/when you
1042 see a variable or field of that type: In that case
1043 the variable's type (in the AUX table) says if the
1044 type is struct, union, or enum,
1045 and points back to the stBlock here.
1046 So you can patch the tag kind up later - but only
1047 if there actually is a variable or field of that type.
1049 So until we know for sure, we will guess at this point.
1051 If the first member has index==indexNil or a void type,
1052 assume we have an enumeration.
1053 Otherwise, if there is more than one member, and all
1054 the members have offset 0, assume we have a union.
1055 Otherwise, assume we have a struct.
1057 The heuristic could guess wrong in the case of
1058 of an enumeration with no members or a union
1059 with one (or zero) members, or when all except the
1060 last field of a struct have width zero.
1061 These are uncommon and/or illegal situations, and
1062 in any case guessing wrong probably doesn't matter much.
1064 But if we later do find out we were wrong,
1065 we fixup the tag kind. Members of an enumeration
1066 must be handled differently from struct/union fields,
1067 and that is harder to patch up, but luckily we
1068 shouldn't need to. (If there are any enumeration
1069 members, we can tell for sure it's an enum here.) */
1071 if (type_code
== TYPE_CODE_UNDEF
)
1072 if (nfields
> 1 && max_value
== 0)
1073 type_code
= TYPE_CODE_UNION
;
1075 type_code
= TYPE_CODE_STRUCT
;
1077 /* If this type was expected, use its partial definition */
1079 t
= is_pending_symbol(cur_fdr
, sh
)->t
;
1081 t
= new_type(prepend_tag_kind(sh
->iss
, type_code
));
1083 TYPE_CODE(t
) = type_code
;
1084 TYPE_LENGTH(t
) = sh
->value
;
1085 TYPE_NFIELDS(t
) = nfields
;
1086 TYPE_FIELDS(t
) = f
= (struct field
*)
1087 obstack_alloc (¤t_objfile
-> type_obstack
,
1088 nfields
* sizeof (struct field
));
1090 if (type_code
== TYPE_CODE_ENUM
) {
1091 /* This is a non-empty enum. */
1092 for (tsym
= sh
+ 1; tsym
->st
== stMember
; tsym
++) {
1093 struct symbol
*enum_sym
;
1094 f
->bitpos
= tsym
->value
;
1096 f
->name
= (char*)tsym
->iss
;
1099 enum_sym
= (struct symbol
*)
1100 obstack_alloc (&objfile
->symbol_obstack
,
1101 sizeof (struct symbol
));
1102 memset (enum_sym
, 0, sizeof (struct symbol
));
1103 SYMBOL_NAME (enum_sym
) = f
->name
;
1104 SYMBOL_CLASS (enum_sym
) = LOC_CONST
;
1105 SYMBOL_TYPE (enum_sym
) = t
;
1106 SYMBOL_NAMESPACE (enum_sym
) = VAR_NAMESPACE
;
1107 SYMBOL_VALUE (enum_sym
) = tsym
->value
;
1108 add_symbol(enum_sym
, top_stack
->cur_block
);
1110 /* Skip the stMembers that we've handled. */
1116 /* make this the current type */
1117 top_stack
->cur_type
= t
;
1118 top_stack
->cur_field
= 0;
1119 /* Mark that symbol has a type, and say which one */
1120 sh
->value
= (long) t
;
1122 /* beginnning of (code) block. Value of symbol
1123 is the displacement from procedure start */
1124 b
= new_block(top_stack
->maxsyms
);
1125 BLOCK_START(b
) = sh
->value
+ top_stack
->procadr
;
1126 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1127 top_stack
->cur_block
= b
;
1128 add_block(b
, top_stack
->cur_st
);
1132 case stEnd
: /* end (of anything) */
1133 if (sh
->sc
== scInfo
) {
1134 /* Finished with type */
1135 top_stack
->cur_type
= 0;
1136 } else if (sh
->sc
== scText
&&
1137 (top_stack
->blocktype
== stProc
||
1138 top_stack
->blocktype
== stStaticProc
)) {
1139 /* Finished with procedure */
1140 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
1144 BLOCK_END(top_stack
->cur_block
) += sh
->value
; /* size */
1145 got_numargs(top_stack
->procadr
, top_stack
->numargs
);
1146 /* Reallocate symbols, saving memory */
1147 b
= shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1149 /* f77 emits proc-level with address bounds==[0,0],
1150 So look for such child blocks, and patch them. */
1151 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++) {
1152 struct block
*b_bad
= BLOCKVECTOR_BLOCK(bv
,i
);
1153 if (BLOCK_SUPERBLOCK(b_bad
) == b
1154 && BLOCK_START(b_bad
) == top_stack
->procadr
1155 && BLOCK_END(b_bad
) == top_stack
->procadr
) {
1156 BLOCK_START(b_bad
) = BLOCK_START(b
);
1157 BLOCK_END(b_bad
) = BLOCK_END(b
);
1160 } else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
) {
1161 /* End of (code) block. The value of the symbol
1162 is the displacement from the procedure`s start
1163 address of the end of this block. */
1164 BLOCK_END(top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1165 (void) shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1167 pop_parse_stack(); /* restore previous lexical context */
1170 case stMember
: /* member of struct or union */
1171 f
= &TYPE_FIELDS(top_stack
->cur_type
)[top_stack
->cur_field
++];
1172 f
->name
= (char*)sh
->iss
;
1173 f
->bitpos
= sh
->value
;
1175 f
->type
= parse_type(ax
+ sh
->index
, sh
, &f
->bitsize
);
1178 case stTypedef
: /* type definition */
1179 s
= new_symbol(sh
->iss
);
1180 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1181 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1182 SYMBOL_BLOCK_VALUE(s
) = top_stack
->cur_block
;
1183 add_symbol(s
, top_stack
->cur_block
);
1184 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
1185 sh
->value
= (long) SYMBOL_TYPE(s
);
1188 case stFile
: /* file name */
1190 top_stack
->blocktype
= sh
->st
;
1193 /* I`ve never seen these for C */
1195 break; /* register relocation */
1197 break; /* forwarding address */
1199 break; /* constant */
1201 error("Unknown symbol type %x.", sh
->st
);
1207 /* Parse the type information provided in the AX entries for
1208 the symbol SH. Return the bitfield size in BS, in case. */
1210 static struct type
*parse_type(ax
, sh
, bs
)
1215 /* Null entries in this map are treated specially */
1216 static struct type
**map_bt
[] =
1218 &builtin_type_void
, /* btNil */
1220 &builtin_type_char
, /* btChar */
1221 &builtin_type_unsigned_char
, /* btUChar */
1222 &builtin_type_short
, /* btShort */
1223 &builtin_type_unsigned_short
, /* btUShort */
1224 &builtin_type_int
, /* btInt */
1225 &builtin_type_unsigned_int
, /* btUInt */
1226 &builtin_type_long
, /* btLong */
1227 &builtin_type_unsigned_long
, /* btULong */
1228 &builtin_type_float
, /* btFloat */
1229 &builtin_type_double
, /* btDouble */
1236 &builtin_type_complex
, /* btComplex */
1237 &builtin_type_double_complex
, /* btDComplex */
1239 &builtin_type_fixed_dec
, /* btFixedDec */
1240 &builtin_type_float_dec
, /* btFloatDec */
1241 &builtin_type_string
, /* btString */
1244 &builtin_type_void
, /* btVoid */
1248 struct type
*tp
= 0;
1253 /* Procedures start off by one */
1254 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
)
1257 /* Undefined ? Should not happen */
1258 if (ax
->rndx
.rfd
== 0xfff) {
1259 return builtin_type_void
;
1262 /* Use aux as a type information record, map its basic type */
1264 if (t
->bt
> (sizeof (map_bt
)/sizeof (*map_bt
))) {
1265 complain (&basic_type_complaint
, t
->bt
);
1266 return builtin_type_int
;
1268 if (map_bt
[t
->bt
]) {
1269 tp
= *map_bt
[t
->bt
];
1273 /* Cannot use builtin types -- build our own */
1276 tp
= lookup_pointer_type (builtin_type_void
);
1280 type_code
= TYPE_CODE_STRUCT
;
1284 type_code
= TYPE_CODE_UNION
;
1288 type_code
= TYPE_CODE_ENUM
;
1292 type_code
= TYPE_CODE_RANGE
;
1296 type_code
= TYPE_CODE_SET
;
1301 complain (&basic_type_complaint
, t
->bt
);
1302 return builtin_type_int
;
1306 /* Move on to next aux */
1309 /* This is the way it would work if the compiler worked */
1310 register TIR
*t1
= t
;
1311 while (t1
->continued
)
1320 /* All these types really point to some (common) MIPS type
1321 definition, and only the type-qualifiers fully identify
1322 them. We'll make the same effort at sharing. */
1323 if (t
->bt
== btIndirect
||
1324 t
->bt
== btStruct
||
1327 t
->bt
== btTypedef
||
1330 char name
[256], *pn
;
1332 /* Try to cross reference this type */
1333 ax
+= cross_ref(ax
, &tp
, type_code
, &pn
);
1334 /* reading .o file ? */
1335 if (UNSAFE_DATA_ADDR(tp
))
1336 tp
= init_type(type_code
, 0, 0, 0, (struct objfile
*) NULL
);
1337 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1338 sprintf(name
, fmt
, pn
);
1340 /* Usually, TYPE_CODE(tp) is already type_code. The main
1341 exception is if we guessed wrong re struct/union/enum. */
1342 if (TYPE_CODE(tp
) != type_code
) {
1343 complain (&bad_tag_guess_complaint
, 0);
1344 TYPE_CODE(tp
) = type_code
;
1346 if (TYPE_NAME(tp
) == NULL
|| strcmp(TYPE_NAME(tp
), name
) != 0)
1347 TYPE_NAME(tp
) = obsavestring(name
, strlen(name
),
1348 ¤t_objfile
-> type_obstack
);
1351 /* Deal with range types */
1352 if (t
->bt
== btRange
) {
1355 TYPE_NFIELDS (tp
) = 2;
1357 (struct field
*) obstack_alloc (¤t_objfile
-> type_obstack
,
1358 2 * sizeof (struct field
));
1359 TYPE_FIELD_NAME (tp
, 0) = obsavestring ("Low", strlen ("Low"),
1360 ¤t_objfile
-> type_obstack
);
1361 TYPE_FIELD_BITPOS (tp
, 0) = ax
->dnLow
;
1363 TYPE_FIELD_NAME (tp
, 1) = obsavestring ("High", strlen ("High"),
1364 ¤t_objfile
-> type_obstack
);
1365 TYPE_FIELD_BITPOS (tp
, 1) = ax
->dnHigh
;
1369 /* Parse all the type qualifiers now. If there are more
1370 than 6 the game will continue in the next aux */
1372 #define PARSE_TQ(tq) \
1373 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, sh);
1375 again
: PARSE_TQ(tq0
);
1390 /* Make up a complex type from a basic one. Type is passed by
1391 reference in TPP and side-effected as necessary. The type
1392 qualifier TQ says how to handle the aux symbols at AX for
1393 the symbol SX we are currently analyzing.
1394 Returns the number of aux symbols we parsed. */
1397 upgrade_type(tpp
, tq
, ax
, sh
)
1405 /* Used in array processing */
1414 t
= lookup_pointer_type (*tpp
);
1419 t
= lookup_function_type (*tpp
);
1425 t
= init_type(TYPE_CODE_ARRAY
, 0, 0, 0, (struct objfile
*) NULL
);
1426 TYPE_TARGET_TYPE(t
) = *tpp
;
1428 /* Determine and record the domain type (type of index) */
1429 id
= ax
->rndx
.index
;
1435 fh
= get_rfd(cur_fd
, rf
);
1437 /* Fields are kept in an array */
1438 /* FIXME - Memory leak! */
1439 if (TYPE_NFIELDS(t
))
1440 TYPE_FIELDS(t
) = (struct field
*)
1441 xrealloc(TYPE_FIELDS(t
),
1442 (TYPE_NFIELDS(t
)+1) * sizeof(struct field
));
1444 TYPE_FIELDS(t
) = (struct field
*)
1445 xzalloc(sizeof(struct field
));
1446 f
= &(TYPE_FIELD(t
,TYPE_NFIELDS(t
)));
1448 memset(f
, 0, sizeof(struct field
));
1450 memset(&ss
, 0, sizeof ss
);
1451 /* XXX */ f
->type
= parse_type(fh
->iauxBase
+ id
* sizeof(AUXU
),
1456 * This seems to be a pointer to the end of the Block defining
1457 * the type. Why it is here is magic for me, and I have no
1458 * good use for it anyways.
1460 /* This used to occur because cross_ref returned
1461 the wrong result (ax pointed wrong). FIXME,
1462 delete this code in a while. -- gnu@cygnus jul91 */
1463 complain (&array_parse_complaint
, 0);
1465 id
= (++ax
)->rndx
.index
;
1466 if ((rf
= ax
->rndx
.rfd
) == 0xfff)
1467 rf
= (++ax
)->isym
, off
++;
1469 lower
= (++ax
)->dnLow
;
1470 upper
= (++ax
)->dnHigh
;
1471 rf
= (++ax
)->width
; /* bit size of array element */
1473 /* Check whether supplied array element bit size matches
1474 the known size of the element type. If this complaint
1475 ends up not happening, we can remove this code. It's
1476 here because we aren't sure we understand this *&%&$
1478 id
= TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) << 3; /* bitsize */
1480 /* Most likely an undefined type */
1482 TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) = id
>> 3;
1485 complain (&array_bitsize_complaint
, rf
);
1487 TYPE_LENGTH(t
) = (upper
< 0) ? 0 :
1488 (upper
- lower
+ 1) * (rf
>> 3);
1493 /* Volatile -- currently ignored */
1497 complain (&unknown_type_qual_complaint
, tq
);
1503 /* Parse a procedure descriptor record PR. Note that the procedure
1504 is parsed _after_ the local symbols, now we just make up the
1505 extra information we need into a special symbol that we insert
1506 in the procedure's main block. Note also that images that
1507 have been partially stripped (ld -x) have been deprived
1508 of local symbols, and we have to cope with them here.
1509 The procedure's code ends at BOUND */
1512 parse_procedure(pr
, bound
)
1515 struct symbol
*s
, *i
;
1516 SYMR
*sh
= (SYMR
*)pr
->isym
;
1518 struct mips_extra_func_info
*e
;
1522 /* Reuse the MIPS record */
1523 e
= (struct mips_extra_func_info
*) pr
;
1524 e
->numargs
= lookup_numargs(pr
->adr
);
1526 /* Make up our special symbol */
1527 i
= new_symbol(".gdbinfo.");
1528 SYMBOL_VALUE(i
) = (int)e
;
1529 SYMBOL_NAMESPACE(i
) = LABEL_NAMESPACE
;
1530 SYMBOL_CLASS(i
) = LOC_CONST
;
1531 SYMBOL_TYPE(i
) = builtin_type_void
;
1533 /* Make up a name for static procedures. Sigh. */
1534 if (sh
== (SYMR
*)-1) {
1535 sprintf(name
,".static_procedure@%x",pr
->adr
);
1536 sh_name
= savestring(name
, strlen(name
));
1540 sh_name
= (char*)sh
->iss
;
1541 s
= mylookup_symbol(sh_name
, top_stack
->cur_block
,
1542 VAR_NAMESPACE
, LOC_BLOCK
);
1545 b
= SYMBOL_BLOCK_VALUE(s
);
1547 s
= new_symbol(sh_name
);
1548 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1549 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1550 /* Donno its type, hope int is ok */
1551 SYMBOL_TYPE(s
) = lookup_function_type (builtin_type_int
);
1552 add_symbol(s
, top_stack
->cur_block
);
1553 /* Wont have symbols for this one */
1555 SYMBOL_BLOCK_VALUE(s
) = b
;
1556 BLOCK_FUNCTION(b
) = s
;
1557 BLOCK_START(b
) = pr
->adr
;
1558 BLOCK_END(b
) = bound
;
1559 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1560 add_block(b
, top_stack
->cur_st
);
1566 /* Parse the external symbol ES. Just call parse_symbol() after
1567 making sure we know where the aux are for it. For procedures,
1568 parsing of the PDRs has already provided all the needed
1569 information, we only parse them if SKIP_PROCEDURES is false,
1570 and only if this causes no symbol duplication.
1572 This routine clobbers top_stack->cur_block and ->cur_st. */
1575 parse_external(es
, skip_procedures
)
1580 if (es
->ifd
!= ifdNil
) {
1582 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
) + cur_fd
;
1583 ax
= (AUXU
*)cur_fdr
->iauxBase
;
1585 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
);
1588 top_stack
->cur_st
= cur_stab
;
1589 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
1592 /* Reading .o files */
1593 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
) {
1595 switch (es
->asym
.st
) {
1597 case stProc
: what
= "procedure"; n_undef_procs
++; break;
1598 case stGlobal
: what
= "variable"; n_undef_vars
++; break;
1599 case stLabel
: what
= "label"; n_undef_labels
++; break;
1600 default : what
= "symbol"; break;
1604 printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what
,
1605 es
->asym
.iss
, fdr_name(cur_fdr
->rss
));
1609 switch (es
->asym
.st
) {
1611 /* If we have full symbols we do not need more */
1612 if (skip_procedures
)
1614 if (mylookup_symbol (es
->asym
.iss
, top_stack
->cur_block
,
1615 VAR_NAMESPACE
, LOC_BLOCK
))
1621 * Note that the case of a symbol with indexNil
1622 * must be handled anyways by parse_symbol().
1624 parse_symbol(&es
->asym
, ax
);
1631 /* Parse the line number info for file descriptor FH into
1632 GDB's linetable LT. MIPS' encoding requires a little bit
1633 of magic to get things out. Note also that MIPS' line
1634 numbers can go back and forth, apparently we can live
1635 with that and do not need to reorder our linetables */
1640 struct linetable
*lt
;
1642 unsigned char *base
= (unsigned char*)fh
->cbLineOffset
;
1644 int delta
, count
, lineno
= 0;
1650 /* Scan by procedure descriptors */
1651 i
= 0; j
= 0, k
= 0;
1652 for (pr
= (PDR
*)IPDFIRST(cur_hdr
,fh
); j
< fh
->cpd
; j
++, pr
++) {
1655 /* No code for this one */
1656 if (pr
->iline
== ilineNil
||
1657 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1660 * Aurgh! To know where to stop expanding we
1663 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1664 if (pr
[l
].iline
!= -1)
1666 if (l
== (fh
->cpd
- j
))
1671 * When procedures are moved around the linenumbers
1672 * are attributed to the next procedure up
1674 if (pr
->iline
>= halt
) continue;
1676 base
= (unsigned char*)pr
->cbLineOffset
;
1677 l
= pr
->adr
>> 2; /* in words */
1678 halt
+= (pr
->adr
>> 2) - pr
->iline
;
1679 for (lineno
= pr
->lnLow
; l
< halt
;) {
1680 count
= *base
& 0x0f;
1681 delta
= *base
++ >> 4;
1685 delta
= (base
[0] << 8) | base
[1];
1686 if (delta
>= 0x8000)
1690 lineno
+= delta
;/* first delta is 0 */
1691 k
= add_line(lt
, lineno
, l
, k
);
1698 /* Master parsing procedure for first-pass reading of file symbols
1699 into a partial_symtab.
1701 Parses the symtab described by the global symbolic header CUR_HDR.
1702 END_OF_TEXT_SEG gives the address just after the text segment for
1703 the symtab we are reading. */
1706 parse_partial_symbols(end_of_text_seg
, objfile
)
1707 int end_of_text_seg
;
1708 struct objfile
*objfile
;
1711 /* int stat_idx, h_max;*/
1712 HDRR
*hdr
= cur_hdr
;
1713 /* Running pointers */
1718 struct partial_symtab
*pst
;
1720 int past_first_source_file
= 0;
1722 /* List of current psymtab's include files */
1723 char **psymtab_include_list
;
1724 int includes_allocated
;
1727 struct pst_map
* fdr_to_pst
;
1728 /* Index within current psymtab dependency list */
1729 struct partial_symtab
**dependency_list
;
1730 int dependencies_used
, dependencies_allocated
;
1731 struct cleanup
*old_chain
;
1733 extern_tab
= (EXTR
**)obstack_alloc (psymbol_obstack
,
1734 sizeof(EXTR
*) * hdr
->iextMax
);
1736 includes_allocated
= 30;
1738 psymtab_include_list
= (char **) alloca (includes_allocated
*
1740 next_symbol_text_func
= mips_next_symbol_text
;
1742 dependencies_allocated
= 30;
1743 dependencies_used
= 0;
1745 (struct partial_symtab
**) alloca (dependencies_allocated
*
1746 sizeof (struct partial_symtab
*));
1748 last_source_file
= 0;
1753 * Only parse the Local and External symbols, and the Relative FDR.
1754 * Fixup enough of the loader symtab to be able to use it.
1755 * Allocate space only for the file's portions we need to
1760 max_glevel
= MIN_GLEVEL
;
1762 /* Allocate the map FDR -> PST.
1763 Minor hack: -O3 images might claim some global data belongs
1764 to FDR -1. We`ll go along with that */
1765 fdr_to_pst
= (struct pst_map
*)xzalloc((hdr
->ifdMax
+1) * sizeof *fdr_to_pst
);
1766 old_chain
= make_cleanup (free
, fdr_to_pst
);
1769 struct partial_symtab
* pst
= new_psymtab("", objfile
);
1770 fdr_to_pst
[-1].pst
= pst
;
1774 /* Pass 1 over external syms: Presize and partition the list */
1775 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1776 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1777 fdr_to_pst
[esh
->ifd
].n_globals
++;
1780 /* Pass 1.5 over files: partition out global symbol space */
1782 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++) {
1783 fdr_to_pst
[f_idx
].globals_offset
= s_idx
;
1784 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
1785 fdr_to_pst
[f_idx
].n_globals
= 0;
1788 /* Pass 2 over external syms: fill in external symbols */
1789 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1790 enum minimal_symbol_type ms_type
= mst_text
;
1791 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1793 extern_tab
[fdr_to_pst
[esh
->ifd
].globals_offset
1794 + fdr_to_pst
[esh
->ifd
].n_globals
++] = esh
;
1796 if (esh
->asym
.sc
== scUndefined
|| esh
->asym
.sc
== scNil
)
1799 switch (esh
->asym
.st
) {
1808 ms_type
= mst_unknown
;
1809 complain (&unknown_ext_complaint
,
1810 (char *)(esh
->asym
.iss
));
1812 prim_record_minimal_symbol ((char *)(esh
->asym
.iss
),
1817 /* Pass 3 over files, over local syms: fill in static symbols */
1818 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
1819 struct partial_symtab
*save_pst
;
1821 cur_fdr
= fh
= f_idx
+ (FDR
*)(cur_hdr
->cbFdOffset
);
1823 if (fh
->csym
== 0) {
1824 fdr_to_pst
[f_idx
].pst
= NULL
;
1827 pst
= start_psymtab_common (objfile
, 0, (char*)fh
->rss
,
1828 fh
->cpd
? fh
->adr
: 0,
1829 global_psymbols
.next
,
1830 static_psymbols
.next
);
1831 pst
->read_symtab_private
= (char *)
1832 obstack_alloc (psymbol_obstack
, sizeof (struct symloc
));
1835 /* Make everything point to everything. */
1836 FDR_IDX(pst
) = f_idx
;
1837 fdr_to_pst
[f_idx
].pst
= pst
;
1838 fh
->ioptBase
= (int)pst
;
1840 CUR_HDR(pst
) = cur_hdr
;
1842 /* The way to turn this into a symtab is to call... */
1843 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
1845 pst
->texthigh
= pst
->textlow
;
1847 #if 0 /* This is done in start_psymtab_common */
1848 pst
->globals_offset
= global_psymbols
.next
- global_psymbols
.list
;
1849 pst
->statics_offset
= static_psymbols
.next
- static_psymbols
.list
;
1851 pst
->n_global_syms
= 0;
1852 pst
->n_static_syms
= 0;
1855 /* The second symbol must be @stab.
1856 This symbol is emitted by mips-tfile to signal
1857 that the current object file uses encapsulated stabs
1858 instead of mips ecoff for local symbols.
1859 (It is the second symbol because the first symbol is
1860 the stFile used to signal the start of a file). */
1862 && strcmp(((SYMR
*)fh
->isymBase
)[1].iss
, stabs_symbol
) == 0) {
1863 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++) {
1866 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
1867 type_code
= MIPS_UNMARK_STAB(sh
->index
);
1868 if (!MIPS_IS_STAB(sh
)) {
1869 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
) {
1870 long procaddr
= sh
->value
;
1871 sh
= (sh
->index
+ (AUXU
*)fh
->iauxBase
)->isym
1872 + (SYMR
*) fh
->isymBase
- 1;
1873 if (sh
->st
== stEnd
) {
1874 long high
= procaddr
+ sh
->value
;
1875 if (high
> pst
->texthigh
)
1876 pst
->texthigh
= high
;
1881 #define SET_NAMESTRING() namestring = (char*)sh->iss
1882 #define CUR_SYMBOL_TYPE type_code
1883 #define CUR_SYMBOL_VALUE sh->value
1884 #define START_PSYMTAB(ofile,addr,fname,low,symoff,global_syms,static_syms)\
1886 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
1887 #define addr 0 /* FIXME, should be offset of addresses */
1888 #define HANDLE_RBRAC(val) \
1889 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
1890 #include "partial-stab.h"
1895 register struct partial_symbol
*psym
;
1896 for (cur_sdx
= 0; cur_sdx
< fh
->csym
; ) {
1897 register struct partial_symbol
*p
;
1900 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
1902 if (MIPS_IS_STAB(sh
)) {
1907 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
1908 sh
->index
== 0xfffff) {
1909 /* FIXME, premature? */
1914 name
= (char *)(sh
->iss
);
1919 case stProc
: /* Asm labels apparently */
1920 case stStaticProc
: /* Function */
1921 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
1922 VAR_NAMESPACE
, LOC_BLOCK
,
1923 static_psymbols
, sh
->value
);
1924 /* Skip over procedure to next one. */
1925 cur_sdx
= (sh
->index
+ (AUXU
*)fh
->iauxBase
)->isym
;
1926 procaddr
= sh
->value
;
1928 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
- 1;
1929 if (sh
->st
!= stEnd
)
1931 high
= procaddr
+ sh
->value
;
1932 if (high
> pst
->texthigh
)
1933 pst
->texthigh
= high
;
1935 case stStatic
: /* Variable */
1938 case stTypedef
: /* Typedef */
1939 class = LOC_TYPEDEF
;
1941 case stConstant
: /* Constant decl */
1944 case stBlock
: /* { }, str, un, enum*/
1945 if (sh
->sc
== scInfo
) {
1946 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
1947 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1948 static_psymbols
, sh
->value
);
1950 /* Skip over the block */
1951 cur_sdx
= sh
->index
;
1953 case stFile
: /* File headers */
1954 case stLabel
: /* Labels */
1955 case stEnd
: /* Ends of files */
1958 complain (&unknown_sym_complaint
, SYMBOL_NAME(p
));
1959 complain (&unknown_st_complaint
, sh
->st
);
1963 /* Use this gdb symbol */
1964 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
1965 VAR_NAMESPACE
, class,
1966 static_psymbols
, sh
->value
);
1968 cur_sdx
++; /* Go to next file symbol */
1971 /* Now do enter the external symbols. */
1972 ext_ptr
= &extern_tab
[fdr_to_pst
[f_idx
].globals_offset
];
1973 cur_sdx
= fdr_to_pst
[f_idx
].n_globals
;
1974 PST_PRIVATE(save_pst
)->extern_count
= cur_sdx
;
1975 PST_PRIVATE(save_pst
)->extern_tab
= ext_ptr
;
1976 for (; --cur_sdx
>= 0; ext_ptr
++) {
1977 enum address_class
class;
1978 if ((*ext_ptr
)->ifd
!= f_idx
)
1980 sh
= &(*ext_ptr
)->asym
;
1989 complain (&unknown_ext_complaint
, sh
->iss
);
1994 if (global_psymbols
.next
>=
1995 global_psymbols
.list
+ global_psymbols
.size
)
1996 extend_psymbol_list (&global_psymbols
, objfile
);
1997 psym
= global_psymbols
.next
++;
1998 SYMBOL_NAME (psym
) = (char*)sh
->iss
;
1999 SYMBOL_NAMESPACE (psym
) = VAR_NAMESPACE
;
2000 SYMBOL_CLASS (psym
) = class;
2001 SYMBOL_VALUE_ADDRESS (psym
) = (CORE_ADDR
)sh
->value
;
2005 end_psymtab (save_pst
, psymtab_include_list
, includes_used
,
2006 -1, save_pst
->texthigh
,
2007 dependency_list
, dependencies_used
,
2008 global_psymbols
.next
, static_psymbols
.next
);
2009 if (entry_point
< save_pst
->texthigh
2010 && entry_point
>= save_pst
->textlow
) {
2011 startup_file_start
= save_pst
->textlow
;
2012 startup_file_end
= save_pst
->texthigh
;
2016 /* Mark the last code address, and remember it for later */
2017 hdr
->cbDnOffset
= end_of_text_seg
;
2019 /* Now scan the FDRs for dependencies */
2020 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
2022 fh
= f_idx
+ (FDR
*)(cur_hdr
->cbFdOffset
);
2023 pst
= fdr_to_pst
[f_idx
].pst
;
2025 /* This should catch stabs-in-ecoff. */
2029 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
2030 /* ...then presumably a .h file: drop reverse depends .h->.c */
2031 for (; s_id0
< fh
->crfd
; s_id0
++) {
2032 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
2034 s_id0
++; /* Skip self-dependency */
2039 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2040 pst
->dependencies
= (struct partial_symtab
**)
2041 obstack_alloc (psymbol_obstack
,
2042 pst
->number_of_dependencies
*
2043 sizeof (struct partial_symtab
*));
2044 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
2045 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
2046 if (*rh
< 0 || *rh
>= hdr
->ifdMax
)
2047 complain(&bad_file_number_complaint
, *rh
);
2049 pst
->dependencies
[s_idx
-s_id0
] = fdr_to_pst
[*rh
].pst
;
2052 do_cleanups (old_chain
);
2057 /* Do the initial analisys of the F_IDX-th file descriptor.
2058 Allocates a partial symtab for it, and builds the list
2059 of dependent files by recursion. LEV says at which level
2060 of recursion we are called (to pretty up debug traces) */
2062 static struct partial_symtab
*
2063 parse_fdr(f_idx
, lev
, objfile
)
2066 struct objfile
*objfile
;
2069 register struct partial_symtab
*pst
;
2072 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + f_idx
;
2074 /* Use this to indicate into which symtab this file was parsed */
2076 return (struct partial_symtab
*) fh
->ioptBase
;
2078 /* Debuggability level */
2079 if (compare_glevel(max_glevel
, fh
->glevel
) < 0)
2080 max_glevel
= fh
->glevel
;
2082 /* Make a new partial_symtab */
2083 pst
= new_psymtab(fh
->rss
, objfile
);
2088 pst
->textlow
= fh
->adr
;
2089 pst
->texthigh
= fh
->cpd
; /* To be fixed later */
2092 /* Make everything point to everything. */
2093 FDR_IDX(pst
) = f_idx
;
2094 fdr_to_pst
[f_idx
].pst
= pst
;
2095 fh
->ioptBase
= (int)pst
;
2097 /* Analyze its dependencies */
2102 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
2103 /* ...then presumably a .h file: drop reverse depends .h->.c */
2104 for (; s_id0
< fh
->crfd
; s_id0
++) {
2105 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
2107 s_id0
++; /* Skip self-dependency */
2112 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2113 pst
->dependencies
= (struct partial_symtab
**)
2114 obstack_alloc (&objfile
->psymbol_obstack
,
2115 pst
->number_of_dependencies
*
2116 sizeof (struct partial_symtab
*));
2117 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
2118 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
2120 pst
->dependencies
[s_idx
-s_id0
] = parse_fdr(*rh
, lev
+1, objfile
);
2128 mips_next_symbol_text ()
2131 return (char*)((SYMR
*)cur_fdr
->isymBase
)[cur_sdx
].iss
;
2134 /* Ancillary function to psymtab_to_symtab(). Does all the work
2135 for turning the partial symtab PST into a symtab, recurring
2136 first on all dependent psymtabs. The argument FILENAME is
2137 only passed so we can see in debug stack traces what file
2141 psymtab_to_symtab_1(pst
, filename
)
2142 struct partial_symtab
*pst
;
2150 struct linetable
*lines
;
2156 /* How many symbols will we need */
2157 /* FIXME, this does not count enum values. */
2158 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
2159 if (FDR_IDX(pst
) == -1) {
2163 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + FDR_IDX(pst
);
2164 f_max
+= fh
->csym
+ fh
->cpd
;
2165 maxlines
= 2 * fh
->cline
;
2168 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2171 && strcmp(((SYMR
*)fh
->isymBase
)[1].iss
, stabs_symbol
) == 0;
2175 st
= new_symtab (pst
->filename
, 2 * f_max
, maxlines
,
2178 st
= new_symtab ("unknown", f_max
, 0, pst
->objfile
);
2179 lines
= LINETABLE(st
);
2180 pending_list
= (struct mips_pending
**) cur_hdr
->cbOptOffset
;
2181 if (pending_list
== 0) {
2182 pending_list
= (struct mips_pending
**)
2183 xzalloc(cur_hdr
->ifdMax
* sizeof(struct mips_pending
*));
2184 cur_hdr
->cbOptOffset
= (int)pending_list
;
2188 /* Read in all partial symbtabs on which this one is dependent.
2189 NOTE that we do have circular dependencies, sigh. We solved
2190 that by setting pst->readin before this point. */
2192 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2193 if (!pst
->dependencies
[i
]->readin
) {
2194 /* Inform about additional files to be read in. */
2197 fputs_filtered (" ", stdout
);
2199 fputs_filtered ("and ", stdout
);
2201 printf_filtered ("%s...",
2202 pst
->dependencies
[i
]->filename
);
2203 wrap_here (""); /* Flush output */
2206 /* We only pass the filename for debug purposes */
2207 psymtab_to_symtab_1(pst
->dependencies
[i
],
2208 pst
->dependencies
[i
]->filename
);
2212 /* Now read the symbols for this symtab */
2214 current_objfile
= pst
-> objfile
;
2216 cur_fd
= FDR_IDX(pst
);
2219 /* Get a new lexical context */
2222 top_stack
->cur_st
= cur_stab
;
2223 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab
),
2225 BLOCK_START(top_stack
->cur_block
) = fh
? fh
->adr
: 0;
2226 BLOCK_END(top_stack
->cur_block
) = 0;
2227 top_stack
->blocktype
= stFile
;
2228 top_stack
->maxsyms
= 2*f_max
;
2229 top_stack
->cur_type
= 0;
2230 top_stack
->procadr
= 0;
2231 top_stack
->numargs
= 0;
2234 /* Parse locals and procedures */
2239 char *fh_name
= (char*)fh
->rss
;
2241 /* Parse local symbols first */
2247 current_objfile
= NULL
;
2250 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++) {
2251 register SYMR
*sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
2252 char *name
= (char*)sh
->iss
;
2253 CORE_ADDR valu
= sh
->value
;
2254 if (MIPS_IS_STAB(sh
)) {
2255 int type_code
= MIPS_UNMARK_STAB(sh
->index
);
2256 process_one_symbol (type_code
, 0, valu
, name
, /*FIXME*/ 0);
2258 else if (sh
->st
== stLabel
&& sh
->index
!= indexNil
) {
2259 /* Handle encoded stab line number. */
2260 record_line (current_subfile
, sh
->index
, valu
);
2263 st
= end_symtab (pst
->texthigh
, 0, 0, pst
->objfile
);
2266 /* BOUND is the highest core address of this file's procedures */
2267 int bound
= cur_fd
== cur_hdr
->ifdMax
- 1 ? cur_hdr
->cbDnOffset
2269 for (cur_sdx
= 0; cur_sdx
< fh
->csym
; ) {
2270 sh
= (SYMR
*) (fh
->isymBase
) + cur_sdx
;
2271 cur_sdx
+= parse_symbol(sh
, fh
->iauxBase
);
2274 /* Procedures next, note we need to look-ahead to
2275 find out where the procedure's code ends */
2277 for (i
= 0; i
< fh
->cpd
-1; i
++) {
2278 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2279 parse_procedure(pr
, pr
[1].adr
); /* next proc up */
2282 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2283 parse_procedure(pr
, bound
); /* next file up */
2285 /* Linenumbers. At the end, check if we can save memory */
2286 parse_lines(fh
, lines
);
2287 if (lines
->nitems
< fh
->cline
)
2288 lines
= shrink_linetable(lines
);
2294 LINETABLE(st
) = lines
;
2296 /* .. and our share of externals.
2297 XXX use the global list to speed up things here. how ?
2298 FIXME, Maybe quit once we have found the right number of ext's? */
2299 /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
2300 top_stack
->blocktype
= stFile
;
2301 top_stack
->maxsyms
=
2302 cur_hdr
->isymMax
+ cur_hdr
->ipdMax
+ cur_hdr
->iextMax
;
2304 ext_ptr
= PST_PRIVATE(pst
)->extern_tab
;
2305 for (i
= PST_PRIVATE(pst
)->extern_count
; --i
>= 0; ext_ptr
++)
2306 parse_external(*ext_ptr
, 1);
2308 /* If there are undefined, tell the user */
2309 if (n_undef_symbols
) {
2310 printf_filtered("File %s contains %d unresolved references:",
2311 st
->filename
, n_undef_symbols
);
2312 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2313 n_undef_vars
, n_undef_procs
, n_undef_labels
);
2314 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
2320 /* Sort the symbol table now, we are done adding symbols to it.*/
2321 sort_symtab_syms(st
);
2325 /* Now link the psymtab and the symtab. */
2328 current_objfile
= NULL
;
2331 /* Ancillary parsing procedures. */
2333 /* Lookup the type at relative index RN. Return it in TPP
2334 if found and in any event come up with its name PNAME.
2335 Return value says how many aux symbols we ate */
2338 cross_ref(rn
, tpp
, type_code
, pname
)
2341 int type_code
; /* Use to alloc new type if none is found. */
2346 /* Escape index means 'the next one' */
2347 if (rn
->rfd
== 0xfff)
2348 rf
= *(unsigned *) (rn
+ 1);
2354 *pname
= "<undefined>";
2357 * Find the relative file descriptor and the symbol in it
2359 FDR
*fh
= get_rfd(cur_fd
, rf
);
2364 * If we have processed this symbol then we left a forwarding
2365 * pointer to the corresponding GDB symbol. If not, we`ll put
2366 * it in a list of pending symbols, to be processed later when
2367 * the file f will be. In any event, we collect the name for
2368 * the type here. Which is why we made a first pass at
2371 sh
= (SYMR
*) (fh
->isymBase
) + rn
->index
;
2373 /* Careful, we might be looking at .o files */
2374 *pname
= (UNSAFE_DATA_ADDR(sh
->iss
)) ? "<undefined>" :
2377 /* Have we parsed it ? */
2378 if ((!UNSAFE_DATA_ADDR(sh
->value
)) && (sh
->st
== stParsed
)) {
2379 t
= (struct type
*) sh
->value
;
2382 /* Avoid duplicates */
2383 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
2387 *tpp
= init_type(type_code
, 0, 0, 0, (struct objfile
*) NULL
);
2388 add_pending(fh
, sh
, *tpp
);
2393 /* We used one auxent normally, two if we got a "next one" rf. */
2394 return (rn
->rfd
== 0xfff? 2: 1);
2398 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2399 keeping the symtab sorted */
2401 static struct symbol
*
2402 mylookup_symbol (name
, block
, namespace, class)
2404 register struct block
*block
;
2405 enum namespace namespace;
2406 enum address_class
class;
2408 register int bot
, top
, inc
;
2409 register struct symbol
*sym
;
2412 top
= BLOCK_NSYMS(block
);
2415 sym
= BLOCK_SYM(block
, bot
);
2416 if (SYMBOL_NAME(sym
)[0] == inc
2417 && SYMBOL_NAMESPACE(sym
) == namespace
2418 && SYMBOL_CLASS(sym
) == class
2419 && !strcmp(SYMBOL_NAME(sym
), name
))
2423 if (block
= BLOCK_SUPERBLOCK (block
))
2424 return mylookup_symbol (name
, block
, namespace, class);
2429 /* Add a new symbol S to a block B.
2430 Infrequently, we will need to reallocate the block to make it bigger.
2431 We only detect this case when adding to top_stack->cur_block, since
2432 that's the only time we know how big the block is. FIXME. */
2439 int nsyms
= BLOCK_NSYMS(b
)++;
2440 struct block
*origb
;
2441 struct parse_stack
*stackp
;
2443 if (b
== top_stack
->cur_block
&&
2444 nsyms
>= top_stack
->maxsyms
) {
2445 complain (&block_overflow_complaint
, s
->name
);
2446 /* In this case shrink_block is actually grow_block, since
2447 BLOCK_NSYMS(b) is larger than its current size. */
2449 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
2451 /* Now run through the stack replacing pointers to the
2452 original block. shrink_block has already done this
2453 for the blockvector and BLOCK_FUNCTION. */
2454 for (stackp
= top_stack
; stackp
; stackp
= stackp
->next
) {
2455 if (stackp
->cur_block
== origb
) {
2456 stackp
->cur_block
= b
;
2457 stackp
->maxsyms
= BLOCK_NSYMS (b
);
2461 BLOCK_SYM(b
,nsyms
) = s
;
2464 /* Add a new block B to a symtab S */
2471 struct blockvector
*bv
= BLOCKVECTOR(s
);
2473 bv
= (struct blockvector
*)xrealloc(bv
, sizeof(struct blockvector
) +
2474 BLOCKVECTOR_NBLOCKS(bv
) * sizeof(bv
->block
));
2475 if (bv
!= BLOCKVECTOR(s
))
2476 BLOCKVECTOR(s
) = bv
;
2478 BLOCKVECTOR_BLOCK(bv
, BLOCKVECTOR_NBLOCKS(bv
)++) = b
;
2481 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2482 MIPS' linenumber encoding might need more than one byte
2483 to describe it, LAST is used to detect these continuation lines */
2486 add_line(lt
, lineno
, adr
, last
)
2487 struct linetable
*lt
;
2493 last
= -2; /* make sure we record first line */
2495 if (last
== lineno
) /* skip continuation lines */
2498 lt
->item
[lt
->nitems
].line
= lineno
;
2499 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
2505 /* Comparison functions, used when sorting things */
2507 /* Symtabs must be ordered viz the code segments they cover */
2510 compare_symtabs( s1
, s2
)
2511 struct symtab
**s1
, **s2
;
2513 /* "most specific" first */
2515 register struct block
*b1
, *b2
;
2516 b1
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1
),GLOBAL_BLOCK
);
2517 b2
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2
),GLOBAL_BLOCK
);
2518 if (BLOCK_END(b1
) == BLOCK_END(b2
))
2519 return BLOCK_START(b1
) - BLOCK_START(b2
);
2520 return BLOCK_END(b1
) - BLOCK_END(b2
);
2524 /* Partial Symtabs, same */
2527 compare_psymtabs( s1
, s2
)
2528 struct partial_symtab
**s1
, **s2
;
2530 /* Perf twist: put the ones with no code at the end */
2532 register int a
= (*s1
)->textlow
;
2533 register int b
= (*s2
)->textlow
;
2542 /* Blocks with a smaller low bound should come first */
2544 static int compare_blocks(b1
,b2
)
2545 struct block
**b1
, **b2
;
2547 register int addr_diff
;
2549 addr_diff
= (BLOCK_START((*b1
))) - (BLOCK_START((*b2
)));
2551 return (BLOCK_END((*b1
))) - (BLOCK_END((*b2
)));
2556 /* Sorting and reordering procedures */
2558 /* Sort the blocks of a symtab S.
2559 Reorder the blocks in the blockvector by code-address,
2560 as required by some MI search routines */
2566 struct blockvector
*bv
= BLOCKVECTOR(s
);
2568 if (BLOCKVECTOR_NBLOCKS(bv
) <= 2) {
2570 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) == 0)
2571 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = 0;
2572 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) == 0)
2573 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) = 0;
2577 * This is very unfortunate: normally all functions are compiled in
2578 * the order they are found, but if the file is compiled -O3 things
2579 * are very different. It would be nice to find a reliable test
2580 * to detect -O3 images in advance.
2582 if (BLOCKVECTOR_NBLOCKS(bv
) > 3)
2583 qsort(&BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
),
2584 BLOCKVECTOR_NBLOCKS(bv
) - FIRST_LOCAL_BLOCK
,
2585 sizeof(struct block
*),
2589 register CORE_ADDR high
= 0;
2590 register int i
, j
= BLOCKVECTOR_NBLOCKS(bv
);
2592 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
2593 if (high
< BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
)))
2594 high
= BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
));
2595 BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = high
;
2598 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) =
2599 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
));
2601 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2602 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2603 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2604 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2608 /* Constructor/restructor/destructor procedures */
2610 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2611 MAXSYMS and linenumbers MAXLINES we'll put in it */
2615 new_symtab(name
, maxsyms
, maxlines
, objfile
)
2618 struct symtab
*s
= allocate_symtab (name
, objfile
);
2620 LINETABLE(s
) = new_linetable(maxlines
);
2622 /* All symtabs must have at least two blocks */
2623 BLOCKVECTOR(s
) = new_bvect(2);
2624 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
) = new_block(maxsyms
);
2625 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), STATIC_BLOCK
) = new_block(maxsyms
);
2626 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
),STATIC_BLOCK
)) =
2627 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
);
2629 s
->free_code
= free_linetable
;
2634 /* Allocate a new partial_symtab NAME */
2636 static struct partial_symtab
*
2637 new_psymtab(name
, objfile
)
2639 struct objfile
*objfile
;
2641 struct partial_symtab
*psymtab
;
2643 /* FIXME -- why (char *) -1 rather than NULL? */
2644 psymtab
= allocate_psymtab (name
== (char *) -1 ? "<no name>" : name
,
2647 /* Keep a backpointer to the file's symbols */
2649 psymtab
-> read_symtab_private
= (char *)
2650 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
2651 CUR_HDR(psymtab
) = cur_hdr
;
2653 /* The way to turn this into a symtab is to call... */
2654 psymtab
->read_symtab
= mipscoff_psymtab_to_symtab
;
2659 /* Allocate a linetable array of the given SIZE */
2661 static struct linetable
*
2664 struct linetable
*l
;
2666 size
= size
* sizeof(l
->item
) + sizeof(struct linetable
);
2667 l
= (struct linetable
*)xmalloc(size
);
2672 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2673 I am not so sure about the 3.4 ones */
2675 static struct linetable
*
2676 shrink_linetable(lt
)
2677 struct linetable
* lt
;
2679 struct linetable
*l
= new_linetable(lt
->nitems
);
2681 memcpy(l
, lt
, lt
->nitems
* sizeof(l
->item
) + sizeof(struct linetable
));
2686 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2689 struct blockvector
*
2692 struct blockvector
*bv
;
2695 size
= sizeof(struct blockvector
) + nblocks
* sizeof(struct block
*);
2696 bv
= (struct blockvector
*) xzalloc(size
);
2698 BLOCKVECTOR_NBLOCKS(bv
) = nblocks
;
2703 /* Allocate and zero a new block of MAXSYMS symbols */
2709 int size
= sizeof(struct block
) + (maxsyms
-1) * sizeof(struct symbol
*);
2710 struct block
*b
= (struct block
*)xzalloc(size
);
2715 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2716 Shrink_block can also be used by add_symbol to grow a block. */
2718 static struct block
*
2724 struct blockvector
*bv
= BLOCKVECTOR(s
);
2727 /* Just reallocate it and fix references to the old one */
2729 new = (struct block
*) xrealloc ((char *)b
, sizeof(struct block
) +
2730 (BLOCK_NSYMS(b
)-1) * sizeof(struct symbol
*));
2732 /* Should chase pointers to old one. Fortunately, that`s just
2733 the block`s function and inferior blocks */
2734 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b
)
2735 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2736 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2737 if (BLOCKVECTOR_BLOCK(bv
,i
) == b
)
2738 BLOCKVECTOR_BLOCK(bv
,i
) = new;
2739 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) == b
)
2740 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) = new;
2744 /* Create a new symbol with printname NAME */
2751 struct symbol
*s
= (struct symbol
*)
2752 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
2754 memset (s
, 0, sizeof (*s
));
2755 SYMBOL_NAME(s
) = name
;
2759 /* Create a new type with printname NAME */
2768 t
= alloc_type (current_objfile
);
2769 TYPE_NAME(t
) = name
;
2770 TYPE_CPLUS_SPECIFIC(t
) = &cplus_struct_default
;
2775 /* Things used for calling functions in the inferior.
2776 These functions are exported to our companion
2777 mips-tdep.c file and are here because they play
2778 with the symbol-table explicitly. */
2780 /* Sigtramp: make sure we have all the necessary information
2781 about the signal trampoline code. Since the official code
2782 from MIPS does not do so, we make up that information ourselves.
2783 If they fix the library (unlikely) this code will neutralize itself. */
2790 struct block
*b
, *b0
;
2792 sigtramp_address
= -1;
2794 /* We know it is sold as sigvec */
2795 s
= lookup_symbol("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
2797 /* Most programs do not play with signals */
2801 b0
= SYMBOL_BLOCK_VALUE(s
);
2803 /* A label of sigvec, to be more precise */
2804 s
= lookup_symbol("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
2806 /* But maybe this program uses its own version of sigvec */
2810 sigtramp_address
= SYMBOL_VALUE(s
);
2811 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
2813 /* Did we or MIPSco fix the library ? */
2814 if (SYMBOL_CLASS(s
) == LOC_BLOCK
)
2817 /* But what symtab does it live in ? */
2818 st
= find_pc_symtab(SYMBOL_VALUE(s
));
2821 * Ok, there goes the fix: turn it into a procedure, with all the
2822 * needed info. Note we make it a nested procedure of sigvec,
2823 * which is the way the (assembly) code is actually written.
2825 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2826 SYMBOL_CLASS(s
) = LOC_BLOCK
;
2827 SYMBOL_TYPE(s
) = init_type(TYPE_CODE_FUNC
, 4, 0, 0, (struct objfile
*) NULL
);
2828 TYPE_TARGET_TYPE(SYMBOL_TYPE(s
)) = builtin_type_void
;
2830 /* Need a block to allocate .gdbinfo. in */
2832 SYMBOL_BLOCK_VALUE(s
) = b
;
2833 BLOCK_START(b
) = sigtramp_address
;
2834 BLOCK_END(b
) = sigtramp_end
;
2835 BLOCK_FUNCTION(b
) = s
;
2836 BLOCK_SUPERBLOCK(b
) = BLOCK_SUPERBLOCK(b0
);
2840 /* Make a .gdbinfo. for it */
2842 struct mips_extra_func_info
*e
=
2843 (struct mips_extra_func_info
*)
2844 xzalloc(sizeof(struct mips_extra_func_info
));
2846 e
->numargs
= 0; /* the kernel thinks otherwise */
2847 /* align_longword(sigcontext + SIGFRAME) */
2848 e
->framesize
= 0x150;
2849 e
->framereg
= SP_REGNUM
;
2852 e
->regoffset
= -(41 * sizeof(int));
2854 e
->fregoffset
= -(37 * sizeof(int));
2857 s
= new_symbol(".gdbinfo.");
2858 SYMBOL_VALUE(s
) = (int) e
;
2859 SYMBOL_NAMESPACE(s
) = LABEL_NAMESPACE
;
2860 SYMBOL_CLASS(s
) = LOC_CONST
;
2861 SYMBOL_TYPE(s
) = builtin_type_void
;
2864 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
2867 /* Initialization */
2869 static struct sym_fns ecoff_sym_fns
= {"ecoff", 5,
2870 mipscoff_new_init
, mipscoff_symfile_init
,
2871 mipscoff_symfile_read
};
2873 _initialize_mipsread ()
2875 add_symtab_fns (&ecoff_sym_fns
);
2877 /* Missing basic types */
2878 builtin_type_string
=
2879 init_type (TYPE_CODE_PASCAL_ARRAY
,
2881 (struct objfile
*) NULL
);
2882 builtin_type_complex
=
2883 init_type(TYPE_CODE_FLT
,
2884 2 * sizeof(float), 0, "complex",
2885 (struct objfile
*) NULL
);
2886 builtin_type_double_complex
=
2887 init_type(TYPE_CODE_FLT
,
2888 2 * sizeof(double), 0, "double_complex",
2889 (struct objfile
*) NULL
);
2890 builtin_type_fixed_dec
=
2891 init_type(TYPE_CODE_INT
, sizeof(int),
2893 (struct objfile
*) NULL
);
2894 builtin_type_float_dec
=
2895 init_type(TYPE_CODE_FLT
, sizeof(double),
2896 0, "floating_decimal",
2897 (struct objfile
*) NULL
);