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 unknown_ext_complaint
=
101 {"unknown external symbol %s", 0, 0};
103 struct complaint unknown_sym_complaint
=
104 {"unknown local symbol %s", 0, 0};
106 struct complaint unknown_st_complaint
=
107 {"with type %d", 0, 0};
109 struct complaint block_overflow_complaint
=
110 {"block containing %s overfilled", 0, 0};
112 struct complaint basic_type_complaint
=
113 {"cannot map MIPS basic type 0x%x", 0, 0};
115 struct complaint unknown_type_qual_complaint
=
116 {"unknown type qualifier 0x%x", 0, 0};
118 struct complaint array_bitsize_complaint
=
119 {"size of array target type not known, assuming %d bits", 0, 0};
121 struct complaint array_parse_complaint
=
122 {"array type with strange relative symbol", 0, 0};
124 struct complaint bad_tag_guess_complaint
=
125 {"guessed tag type incorrectly", 0, 0};
127 /* Macros and extra defs */
129 /* Already-parsed symbols are marked specially */
131 #define stParsed stType
133 /* Puns: hard to find whether -g was used and how */
135 #define MIN_GLEVEL GLEVEL_0
136 #define compare_glevel(a,b) \
137 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
138 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
140 /* When looking at .o files, avoid tripping over bad addresses */
142 #define SAFE_TEXT_ADDR 0x400000
143 #define SAFE_DATA_ADDR 0x10000000
145 #define UNSAFE_DATA_ADDR(p) ((unsigned)p < SAFE_DATA_ADDR || (unsigned)p > 2*SAFE_DATA_ADDR)
147 /* Things that really are local to this module */
149 /* GDB symtable for the current compilation unit */
151 static struct symtab
*cur_stab
;
153 /* MIPS symtab header for the current file */
155 static HDRR
*cur_hdr
;
157 /* Pointer to current file decriptor record, and its index */
162 /* Index of current symbol */
166 /* Note how much "debuggable" this image is. We would like
167 to see at least one FDR with full symbols */
172 /* When examining .o files, report on undefined symbols */
174 static int n_undef_symbols
, n_undef_labels
, n_undef_vars
, n_undef_procs
;
176 /* Pseudo symbol to use when putting stabs into the symbol table. */
178 static char stabs_symbol
[] = STABS_SYMBOL
;
180 /* Extra builtin types */
182 struct type
*builtin_type_complex
;
183 struct type
*builtin_type_double_complex
;
184 struct type
*builtin_type_fixed_dec
;
185 struct type
*builtin_type_float_dec
;
186 struct type
*builtin_type_string
;
188 /* Forward declarations */
190 static struct symbol
*new_symbol();
191 static struct type
*new_type();
192 static struct block
*new_block();
193 static struct symtab
*new_symtab();
194 static struct linetable
*new_linetable();
195 static struct blockvector
*new_bvect();
197 static struct type
*parse_type();
198 static struct type
*make_type();
199 static struct symbol
*mylookup_symbol();
200 static struct block
*shrink_block();
201 static void sort_blocks();
203 static int compare_symtabs();
204 static int compare_psymtabs();
205 static int compare_blocks();
207 static struct partial_symtab
*new_psymtab();
208 static struct partial_symtab
*parse_fdr();
209 static int compare_psymbols();
211 static void psymtab_to_symtab_1();
212 static void add_block();
213 static void add_symbol();
214 static int add_line();
215 static struct linetable
*shrink_linetable();
216 static char* mips_next_symbol_text ();
219 /* Things we export to other modules */
221 /* Address bounds for the signal trampoline in inferior, if any */
222 /* FIXME: Nothing really seems to use this. Why is it here? */
224 CORE_ADDR sigtramp_address
, sigtramp_end
;
226 /* The entry point (starting address) of the file, if it is an executable. */
228 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
229 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
234 /* If we have a file symbol header lying around, blow it away. */
236 free ((char *)cur_hdr
);
241 mipscoff_symfile_init (sf
)
244 sf
->sym_private
= NULL
;
248 mipscoff_symfile_read(sf
, addr
, mainline
)
253 struct coff_symfile_info
*info
= (struct coff_symfile_info
*)sf
->sym_private
;
254 bfd
*abfd
= sf
->objfile
->obfd
;
255 char *name
= bfd_get_filename (abfd
);
259 int stringtab_offset
;
261 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
262 desc
= fileno ((FILE *)(abfd
->iostream
)); /* Raw file descriptor */
265 /* Position to read the symbol table. */
266 val
= lseek (desc
, (long)symtab_offset
, 0);
268 perror_with_name (name
);
270 init_misc_bunches ();
271 make_cleanup (discard_misc_bunches
, 0);
273 /* Now that the executable file is positioned at symbol table,
274 process it and define symbols accordingly. */
276 read_mips_symtab(sf
->objfile
, desc
);
278 /* Go over the misc symbol bunches and install them in vector. */
280 condense_misc_bunches (!mainline
);
283 /* Exported procedure: Allocate zeroed memory */
288 char *p
= xmalloc(size
);
294 /* Exported procedure: Builds a symtab from the PST partial one.
295 Restores the environment in effect when PST was created, delegates
296 most of the work to an ancillary procedure, and sorts
297 and reorders the symtab list at the end */
300 mipscoff_psymtab_to_symtab(pst
)
301 struct partial_symtab
*pst
;
310 printf_filtered("Reading in symbols for %s...", pst
->filename
);
313 /* Restore the header and list of pending typedefs */
314 cur_hdr
= CUR_HDR(pst
);
316 next_symbol_text_func
= mips_next_symbol_text
;
318 psymtab_to_symtab_1(pst
, pst
->filename
);
320 /* Match with global symbols. This only needs to be done once,
321 after all of the symtabs and dependencies have been read in. */
322 scan_file_globals ();
325 printf_filtered("done.\n");
328 /* Exported procedure: Is PC in the signal trampoline code */
331 in_sigtramp(pc
, name
)
335 if (sigtramp_address
== 0)
337 return (pc
>= sigtramp_address
&& pc
< sigtramp_end
);
340 /* File-level interface functions */
342 /* Read the symtab information from file FSYM into memory. Also,
343 return address just past end of our text segment in *END_OF_TEXT_SEGP. */
346 read_the_mips_symtab(abfd
, fsym
, end_of_text_segp
)
349 CORE_ADDR
*end_of_text_segp
;
351 int stsize
, st_hdrsize
;
354 /* Header for executable/object file we read symbols from */
355 struct coff_exec filhdr
;
357 /* We get here with DESC pointing to the symtab header. But we need
358 * other info from the initial headers */
360 myread(fsym
, &filhdr
, sizeof filhdr
);
362 if (end_of_text_segp
)
364 bfd_h_get_32 (abfd
, filhdr
.a
.text_start
) +
365 bfd_h_get_32 (abfd
, filhdr
.a
.tsize
);
367 /* Find and read the symbol table header */
368 st_hdrsize
= bfd_h_get_32 (abfd
, filhdr
.f
.f_nsyms
);
369 st_filptr
= bfd_h_get_32 (abfd
, filhdr
.f
.f_symptr
);
373 lseek(fsym
, st_filptr
, L_SET
);
374 if (st_hdrsize
> sizeof (st_hdr
)) /* Profanity check */
376 if (read(fsym
, &st_hdr
, st_hdrsize
) != st_hdrsize
)
379 /* Find out how large the symbol table is */
380 stsize
= (st_hdr
.cbExtOffset
- (st_filptr
+ st_hdrsize
))
381 + st_hdr
.iextMax
* cbEXTR
;
383 /* Allocate space for the symbol table. Read it in. */
384 cur_hdr
= (HDRR
*) xmalloc(stsize
+ st_hdrsize
);
386 memcpy(cur_hdr
, &st_hdr
, st_hdrsize
);
387 if (read(fsym
, (char *) cur_hdr
+ st_hdrsize
, stsize
) != stsize
)
390 /* Fixup file_pointers in it */
391 fixup_symtab(cur_hdr
, (char *) cur_hdr
+ st_hdrsize
,
392 st_filptr
+ st_hdrsize
);
396 error("Short read on %s", bfd_get_filename (abfd
));
400 /* Turn all file-relative pointers in the symtab described by HDR
401 into memory pointers, given that the symtab itself is located
402 at DATA in memory and F_PTR in the file. */
405 fixup_symtab( hdr
, data
, f_ptr
)
417 * These fields are useless (and empty) by now:
418 * hdr->cbDnOffset, hdr->cbOptOffset
419 * We use them for other internal purposes.
422 hdr
->cbOptOffset
= 0;
425 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
441 * Fix all string pointers inside the symtab, and
442 * the FDR records. Also fix other miscellany.
444 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
445 register unsigned code_offset
;
447 /* Header itself, and strings */
448 fh
= (FDR
*) (hdr
->cbFdOffset
) + f_idx
;
449 fh
->issBase
+= hdr
->cbSsOffset
;
451 fh
->rss
= (long)fh
->rss
+ fh
->issBase
;
454 fh
->isymBase
= (int)((SYMR
*)(hdr
->cbSymOffset
)+fh
->isymBase
);
456 /* FIXME! Probably don't want to do this here! */
457 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
458 sh
= (SYMR
*)fh
->isymBase
+ s_idx
;
459 sh
->iss
= (long) sh
->iss
+ fh
->issBase
;
465 /* cannot fix fh->ipdFirst because it is a short */
466 #define IPDFIRST(h,fh) \
467 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
469 /* Optional symbols (actually used for partial_symtabs) */
475 fh
->iauxBase
= hdr
->cbAuxOffset
+ fh
->iauxBase
* sizeof(AUXU
);
476 /* Relative file descriptor table */
477 fh
->rfdBase
= hdr
->cbRfdOffset
+ fh
->rfdBase
* sizeof(RFDT
);
481 fh
->cbLineOffset
+= hdr
->cbLineOffset
;
483 /* Procedure symbols. (XXX This should be done later) */
484 code_offset
= fh
->adr
;
485 for (s_idx
= 0; s_idx
< fh
->cpd
; s_idx
++) {
486 unsigned name
, only_ext
;
488 pr
= (PDR
*)(IPDFIRST(hdr
,fh
)) + s_idx
;
490 /* Simple rule to find files linked "-x" */
491 only_ext
= fh
->rss
== -1;
493 if (pr
->isym
== -1) {
494 /* static function */
498 name
= hdr
->cbExtOffset
+ pr
->isym
* sizeof(EXTR
);
499 sh
= &((EXTR
*)name
)->asym
;
503 sh
= (SYMR
*)fh
->isymBase
+ pr
->isym
;
504 /* Included code ? */
505 if (s_idx
== 0 && pr
->adr
!= 0)
506 code_offset
-= pr
->adr
;
509 /* Turn index into a pointer */
512 /* Fix line numbers */
513 pr
->cbLineOffset
+= fh
->cbLineOffset
;
515 /* Relocate address */
517 pr
->adr
+= code_offset
;
521 /* External symbols: fix string */
522 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
523 esh
= (EXTR
*)(hdr
->cbExtOffset
) + s_idx
;
524 esh
->asym
.iss
= esh
->asym
.iss
+ hdr
->cbSsExtOffset
;
529 /* Find a file descriptor given its index RF relative to a file CF */
537 f
= (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
538 /* Object files do not have the RFD table, all refs are absolute */
540 return (FDR
*) (cur_hdr
->cbFdOffset
) + rf
;
541 cf
= *((pRFDT
) f
->rfdBase
+ rf
);
542 return (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
545 /* Return a safer print NAME for a file descriptor */
551 if (name
== (char *) -1)
552 return "<stripped file>";
553 if (UNSAFE_DATA_ADDR(name
))
559 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
560 whether we are adding to the general symtab or not.
561 FIXME: INCREMENTAL is currently always zero, though it should not be. */
564 read_mips_symtab (objfile
, desc
)
565 struct objfile
*objfile
;
568 CORE_ADDR end_of_text_seg
;
570 read_the_mips_symtab(objfile
->obfd
, desc
, &end_of_text_seg
);
572 parse_partial_symbols(end_of_text_seg
, objfile
);
576 * Check to make sure file was compiled with -g.
577 * If not, warn the user of this limitation.
579 if (compare_glevel(max_glevel
, GLEVEL_2
) < 0) {
580 if (max_gdbinfo
== 0)
582 "\n%s not compiled with -g, debugging support is limited.\n",
585 "You should compile with -g2 or -g3 for best debugging support.\n");
591 /* Local utilities */
593 /* Map of FDR indexes to partial symtabs */
596 struct partial_symtab
*pst
; /* the psymtab proper */
597 int n_globals
; /* exported globals (external symbols) */
598 int globals_offset
; /* cumulative */
602 /* Utility stack, used to nest procedures and blocks properly.
603 It is a doubly linked list, to avoid too many alloc/free.
604 Since we might need it quite a few times it is NOT deallocated
607 static struct parse_stack
{
608 struct parse_stack
*next
, *prev
;
609 struct symtab
*cur_st
; /* Current symtab. */
610 struct block
*cur_block
; /* Block in it. */
611 int blocktype
; /* What are we parsing. */
612 int maxsyms
; /* Max symbols in this block. */
613 struct type
*cur_type
; /* Type we parse fields for. */
614 int cur_field
; /* Field number in cur_type. */
615 int procadr
; /* Start addres of this procedure */
616 int numargs
; /* Its argument count */
617 } *top_stack
; /* Top stack ptr */
620 /* Enter a new lexical context */
622 static push_parse_stack()
624 struct parse_stack
*new;
626 /* Reuse frames if possible */
627 if (top_stack
&& top_stack
->prev
)
628 new = top_stack
->prev
;
630 new = (struct parse_stack
*) xzalloc(sizeof(struct parse_stack
));
631 /* Initialize new frame with previous content */
633 register struct parse_stack
*prev
= new->prev
;
636 top_stack
->prev
= new;
638 new->next
= top_stack
;
643 /* Exit a lexical context */
645 static pop_parse_stack()
650 top_stack
= top_stack
->next
;
654 /* Cross-references might be to things we haven't looked at
655 yet, e.g. type references. To avoid too many type
656 duplications we keep a quick fixup table, an array
657 of lists of references indexed by file descriptor */
659 static struct mips_pending
{
660 struct mips_pending
*next
; /* link */
661 SYMR
*s
; /* the symbol */
662 struct type
*t
; /* its partial type descriptor */
666 /* Check whether we already saw symbol SH in file FH as undefined */
669 struct mips_pending
*is_pending_symbol(fh
, sh
)
673 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
674 register struct mips_pending
*p
;
676 /* Linear search is ok, list is typically no more than 10 deep */
677 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
683 /* Check whether we already saw type T in file FH as undefined */
686 struct mips_pending
*is_pending_type(fh
, t
)
690 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
691 register struct mips_pending
*p
;
693 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
699 /* Add a new undef symbol SH of type T */
702 add_pending(fh
, sh
, t
)
707 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
708 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
710 /* Make sure we do not make duplicates */
712 p
= (struct mips_pending
*) xmalloc(sizeof(*p
));
715 p
->next
= pending_list
[f_idx
];
716 pending_list
[f_idx
] = p
;
718 sh
->reserved
= 1; /* for quick check */
721 /* Throw away undef entries when done with file index F_IDX */
726 register struct mips_pending
*p
, *q
;
728 for (p
= pending_list
[f_idx
]; p
; p
= q
) {
732 pending_list
[f_idx
] = 0;
735 /* The number of args to a procedure is not explicit in the symtab,
736 this is the list of all those we know of.
737 This makes parsing more reasonable and avoids extra passes */
739 static struct numarg
{
740 struct numarg
*next
; /* link */
741 unsigned adr
; /* procedure's start address */
742 unsigned num
; /* arg count */
745 /* Record that the procedure at ADR takes NUM arguments. */
750 struct numarg
*n
= (struct numarg
*) xmalloc(sizeof(struct numarg
));
754 n
->next
= numargs_list
;
758 /* See if we know how many arguments the procedure at ADR takes */
763 struct numarg
*n
= numargs_list
;
765 while (n
&& n
->adr
!= adr
)
767 return (n
) ? n
->num
: -1;
770 /* Release storage when done with this file */
775 struct numarg
*n
= numargs_list
, *m
;
786 prepend_tag_kind(tag_name
, type_code
)
796 case TYPE_CODE_STRUCT
:
799 case TYPE_CODE_UNION
:
806 result
= (char*)obstack_alloc (symbol_obstack
,
807 strlen(prefix
) + strlen(tag_name
) + 1);
808 sprintf(result
, "%s%s", prefix
, tag_name
);
813 /* Parsing Routines proper. */
815 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
816 For blocks, procedures and types we open a new lexical context.
817 This is basically just a big switch on the symbol's type.
818 Return count of SYMR's handled (normally one). */
831 /* When a symbol is cross-referenced from other files/symbols
832 we mark it explicitly */
833 int pend
= (sh
->reserved
== 1);
834 enum address_class
class;
841 case stGlobal
: /* external symbol, goes into global block */
843 b
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
845 s
= new_symbol(sh
->iss
);
846 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
849 case stStatic
: /* static data, goes into current block. */
851 b
= top_stack
->cur_block
;
852 s
= new_symbol(sh
->iss
);
853 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
856 case stLocal
: /* local variable, goes into current block */
857 if (sh
->sc
== scRegister
) {
858 class = LOC_REGISTER
;
860 sh
->value
+= FP0_REGNUM
-32;
863 b
= top_stack
->cur_block
;
864 s
= new_symbol(sh
->iss
);
865 SYMBOL_VALUE(s
) = sh
->value
;
867 data
: /* Common code for symbols describing data */
868 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
869 SYMBOL_CLASS(s
) = class;
872 /* Type could be missing in a number of cases */
873 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
874 sh
->index
== 0xfffff)
875 SYMBOL_TYPE(s
) = builtin_type_int
; /* undefined? */
877 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
878 /* Value of a data symbol is its memory address */
881 case stParam
: /* arg to procedure, goes into current block */
883 top_stack
->numargs
++;
885 name
= (char*)sh
->iss
;
886 /* Special GNU C++ name. */
887 if (name
[0] == CPLUS_MARKER
&& name
[1] == 't' && name
[2] == 0)
889 s
= new_symbol(name
);
891 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
892 if (sh
->sc
== scRegister
) {
893 SYMBOL_CLASS(s
) = LOC_REGPARM
;
895 sh
->value
+= FP0_REGNUM
-32;
897 SYMBOL_CLASS(s
) = LOC_ARG
;
898 SYMBOL_VALUE(s
) = sh
->value
;
899 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
900 add_symbol(s
, top_stack
->cur_block
);
902 /* FIXME: This has not been tested. See dbxread.c */
903 /* Add the type of this parameter to the function/procedure
904 type of this block. */
905 add_param_to_type(&top_stack
->cur_block
->function
->type
,s
);
909 case stLabel
: /* label, goes into current block */
910 s
= new_symbol(sh
->iss
);
911 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
; /* so that it can be used */
912 SYMBOL_CLASS(s
) = LOC_LABEL
; /* but not misused */
913 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
914 SYMBOL_TYPE(s
) = builtin_type_int
;
915 add_symbol(s
, top_stack
->cur_block
);
918 case stProc
: /* Procedure, usually goes into global block */
919 case stStaticProc
: /* Static procedure, goes into current block */
920 s
= new_symbol(sh
->iss
);
921 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
922 SYMBOL_CLASS(s
) = LOC_BLOCK
;
923 /* Type of the return value */
924 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
925 t
= builtin_type_int
;
927 t
= parse_type(ax
+ sh
->index
, sh
, 0);
928 b
= top_stack
->cur_block
;
929 if (sh
->st
== stProc
) {
930 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
931 /* The next test should normally be true,
932 but provides a hook for nested functions
933 (which we don't want to make global). */
934 if (b
== BLOCKVECTOR_BLOCK(bv
, STATIC_BLOCK
))
935 b
= BLOCKVECTOR_BLOCK(bv
, GLOBAL_BLOCK
);
939 /* Make a type for the procedure itself */
941 /* FIXME: This has not been tested yet! See dbxread.c */
942 /* Generate a template for the type of this function. The
943 types of the arguments will be added as we read the symbol
945 bcopy(SYMBOL_TYPE(s
),lookup_function_type(t
),sizeof(struct type
));
947 SYMBOL_TYPE(s
) = lookup_function_type (t
);
950 /* Create and enter a new lexical context */
951 b
= new_block(top_stack
->maxsyms
);
952 SYMBOL_BLOCK_VALUE(s
) = b
;
953 BLOCK_FUNCTION(b
) = s
;
954 BLOCK_START(b
) = BLOCK_END(b
) = sh
->value
;
955 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
956 add_block(b
, top_stack
->cur_st
);
958 /* Not if we only have partial info */
959 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
963 top_stack
->cur_block
= b
;
964 top_stack
->blocktype
= sh
->st
;
965 top_stack
->cur_type
= SYMBOL_TYPE(s
);
966 top_stack
->cur_field
= -1;
967 top_stack
->procadr
= sh
->value
;
968 top_stack
->numargs
= 0;
970 sh
->value
= (long) SYMBOL_TYPE(s
);
974 #ifndef btVoid /* btVoid was added late. */
977 /* These new symbol types have been recently added to SGI machines. */
991 case stBlock
: /* Either a lexical block, or some type */
993 top_stack
->blocktype
= stBlock
;
994 if (sh
->sc
== scInfo
) { /* structure/union/enum def */
996 sh
->st
== stStruct
? TYPE_CODE_STRUCT
997 : sh
->st
== stUnion
? TYPE_CODE_UNION
998 : sh
->st
== stEnum
? TYPE_CODE_ENUM
1005 s
= new_symbol(sh
->iss
);
1006 SYMBOL_NAMESPACE(s
) = STRUCT_NAMESPACE
;
1007 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1008 SYMBOL_VALUE(s
) = 0;
1009 add_symbol(s
, top_stack
->cur_block
);
1011 /* First count the number of fields. */
1012 for (tsym
= sh
+1; tsym
->st
!= stEnd
; tsym
++)
1013 if (tsym
->st
== stMember
) {
1014 if (nfields
== 0 && type_code
== TYPE_CODE_UNDEF
)
1015 /* If the type of the member is Nil (or Void)
1016 assume the tag is an enumeration. */
1017 if (tsym
->index
== indexNil
1018 || ax
[tsym
->index
].ti
.bt
== btNil
1019 || ax
[tsym
->index
].ti
.bt
== btVoid
)
1020 type_code
= TYPE_CODE_ENUM
;
1022 if (tsym
->value
> max_value
)
1023 max_value
= tsym
->value
;
1025 else if (tsym
->st
== stBlock
1026 || tsym
->st
== stParsed
) {
1027 if (tsym
->sc
== scVariant
) ; /*UNIMPLEMENTED*/
1028 if (tsym
->index
!= 0)
1029 tsym
= ((SYMR
*)cur_fdr
->isymBase
)
1034 /* There is no guaranteed way to distinguish struct,
1035 unions, and enums at this point. This is a bug in the
1036 original design (that has been fixed with the
1037 recent addition of the stStruct, stUnion, and stEnum
1038 symbol types.) The way you can tell is if/when you
1039 see a variable or field of that type: In that case
1040 the variable's type (in the AUX table) says if the
1041 type is struct, union, or enum,
1042 and points back to the stBlock here.
1043 So you can patch the tag kind up later - but only
1044 if there actually is a variable or field of that type.
1046 So until we know for sure, we will guess at this point.
1048 If the first member has index==indexNil or a void type,
1049 assume we have an enumeration.
1050 Otherwise, if there is more than one member, and all
1051 the members have offset 0, assume we have a union.
1052 Otherwise, assume we have a struct.
1054 The heuristic could guess wrong in the case of
1055 of an enumeration with no members or a union
1056 with one (or zero) members, or when all except the
1057 last field of a struct have width zero.
1058 These are uncommon and/or illegal situations, and
1059 in any case guessing wrong probably doesn't matter much.
1061 But if we later do find out we were wrong,
1062 we fixup the tag kind. Members of an enumeration
1063 must be handled differently from struct/union fields,
1064 and that is harder to patch up, but luckily we
1065 shouldn't need to. (If there are any enumeration
1066 members, we can tell for sure it's an enum here.) */
1068 if (type_code
== TYPE_CODE_UNDEF
)
1069 if (nfields
> 1 && max_value
== 0)
1070 type_code
= TYPE_CODE_UNION
;
1072 type_code
= TYPE_CODE_STRUCT
;
1074 /* If this type was expected, use its partial definition */
1076 t
= is_pending_symbol(cur_fdr
, sh
)->t
;
1078 t
= new_type(prepend_tag_kind(sh
->iss
, type_code
));
1080 TYPE_CODE(t
) = type_code
;
1081 TYPE_LENGTH(t
) = sh
->value
;
1082 TYPE_NFIELDS(t
) = nfields
;
1083 TYPE_FIELDS(t
) = f
= (struct field
*)
1084 obstack_alloc (symbol_obstack
,
1085 nfields
* sizeof (struct field
));
1087 if (type_code
== TYPE_CODE_ENUM
) {
1088 /* This is a non-empty enum. */
1089 for (tsym
= sh
+ 1; tsym
->st
== stMember
; tsym
++) {
1090 struct symbol
*enum_sym
;
1091 f
->bitpos
= tsym
->value
;
1093 f
->name
= (char*)tsym
->iss
;
1096 enum_sym
= (struct symbol
*)
1097 obstack_alloc (symbol_obstack
,
1098 sizeof (struct symbol
));
1099 memset (enum_sym
, 0, sizeof (struct symbol
));
1100 SYMBOL_NAME (enum_sym
) = f
->name
;
1101 SYMBOL_CLASS (enum_sym
) = LOC_CONST
;
1102 SYMBOL_TYPE (enum_sym
) = t
;
1103 SYMBOL_NAMESPACE (enum_sym
) = VAR_NAMESPACE
;
1104 SYMBOL_VALUE (enum_sym
) = tsym
->value
;
1105 add_symbol(enum_sym
, top_stack
->cur_block
);
1107 /* Skip the stMembers that we've handled. */
1113 /* make this the current type */
1114 top_stack
->cur_type
= t
;
1115 top_stack
->cur_field
= 0;
1116 /* Mark that symbol has a type, and say which one */
1117 sh
->value
= (long) t
;
1119 /* beginnning of (code) block. Value of symbol
1120 is the displacement from procedure start */
1121 b
= new_block(top_stack
->maxsyms
);
1122 BLOCK_START(b
) = sh
->value
+ top_stack
->procadr
;
1123 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1124 top_stack
->cur_block
= b
;
1125 add_block(b
, top_stack
->cur_st
);
1129 case stEnd
: /* end (of anything) */
1130 if (sh
->sc
== scInfo
) {
1131 /* Finished with type */
1132 top_stack
->cur_type
= 0;
1133 } else if (sh
->sc
== scText
&&
1134 (top_stack
->blocktype
== stProc
||
1135 top_stack
->blocktype
== stStaticProc
)) {
1136 /* Finished with procedure */
1137 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
1141 BLOCK_END(top_stack
->cur_block
) += sh
->value
; /* size */
1142 got_numargs(top_stack
->procadr
, top_stack
->numargs
);
1143 /* Reallocate symbols, saving memory */
1144 b
= shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1146 /* f77 emits proc-level with address bounds==[0,0],
1147 So look for such child blocks, and patch them. */
1148 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++) {
1149 struct block
*b_bad
= BLOCKVECTOR_BLOCK(bv
,i
);
1150 if (BLOCK_SUPERBLOCK(b_bad
) == b
1151 && BLOCK_START(b_bad
) == top_stack
->procadr
1152 && BLOCK_END(b_bad
) == top_stack
->procadr
) {
1153 BLOCK_START(b_bad
) = BLOCK_START(b
);
1154 BLOCK_END(b_bad
) = BLOCK_END(b
);
1157 } else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
) {
1158 /* End of (code) block. The value of the symbol
1159 is the displacement from the procedure`s start
1160 address of the end of this block. */
1161 BLOCK_END(top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1162 (void) shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1164 pop_parse_stack(); /* restore previous lexical context */
1167 case stMember
: /* member of struct or union */
1168 f
= &TYPE_FIELDS(top_stack
->cur_type
)[top_stack
->cur_field
++];
1169 f
->name
= (char*)sh
->iss
;
1170 f
->bitpos
= sh
->value
;
1172 f
->type
= parse_type(ax
+ sh
->index
, sh
, &f
->bitsize
);
1175 case stTypedef
: /* type definition */
1176 s
= new_symbol(sh
->iss
);
1177 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1178 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1179 SYMBOL_BLOCK_VALUE(s
) = top_stack
->cur_block
;
1180 add_symbol(s
, top_stack
->cur_block
);
1181 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
1182 sh
->value
= (long) SYMBOL_TYPE(s
);
1185 case stFile
: /* file name */
1187 top_stack
->blocktype
= sh
->st
;
1190 /* I`ve never seen these for C */
1192 break; /* register relocation */
1194 break; /* forwarding address */
1196 break; /* constant */
1198 error("Unknown symbol type %x.", sh
->st
);
1204 /* Parse the type information provided in the AX entries for
1205 the symbol SH. Return the bitfield size in BS, in case. */
1207 static struct type
*parse_type(ax
, sh
, bs
)
1212 /* Null entries in this map are treated specially */
1213 static struct type
**map_bt
[] =
1215 &builtin_type_void
, /* btNil */
1217 &builtin_type_char
, /* btChar */
1218 &builtin_type_unsigned_char
, /* btUChar */
1219 &builtin_type_short
, /* btShort */
1220 &builtin_type_unsigned_short
, /* btUShort */
1221 &builtin_type_int
, /* btInt */
1222 &builtin_type_unsigned_int
, /* btUInt */
1223 &builtin_type_long
, /* btLong */
1224 &builtin_type_unsigned_long
, /* btULong */
1225 &builtin_type_float
, /* btFloat */
1226 &builtin_type_double
, /* btDouble */
1233 &builtin_type_complex
, /* btComplex */
1234 &builtin_type_double_complex
, /* btDComplex */
1236 &builtin_type_fixed_dec
, /* btFixedDec */
1237 &builtin_type_float_dec
, /* btFloatDec */
1238 &builtin_type_string
, /* btString */
1241 &builtin_type_void
, /* btVoid */
1245 struct type
*tp
= 0;
1250 /* Procedures start off by one */
1251 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
)
1254 /* Undefined ? Should not happen */
1255 if (ax
->rndx
.rfd
== 0xfff) {
1256 return builtin_type_void
;
1259 /* Use aux as a type information record, map its basic type */
1261 if (t
->bt
> (sizeof (map_bt
)/sizeof (*map_bt
))) {
1262 complain (&basic_type_complaint
, t
->bt
);
1263 return builtin_type_int
;
1265 if (map_bt
[t
->bt
]) {
1266 tp
= *map_bt
[t
->bt
];
1270 /* Cannot use builtin types -- build our own */
1273 tp
= lookup_pointer_type (builtin_type_void
);
1277 type_code
= TYPE_CODE_STRUCT
;
1281 type_code
= TYPE_CODE_UNION
;
1285 type_code
= TYPE_CODE_ENUM
;
1289 type_code
= TYPE_CODE_RANGE
;
1293 type_code
= TYPE_CODE_SET
;
1298 complain (&basic_type_complaint
, t
->bt
);
1299 return builtin_type_int
;
1303 /* Move on to next aux */
1306 /* This is the way it would work if the compiler worked */
1307 register TIR
*t1
= t
;
1308 while (t1
->continued
)
1317 /* All these types really point to some (common) MIPS type
1318 definition, and only the type-qualifiers fully identify
1319 them. We'll make the same effort at sharing. */
1320 if (t
->bt
== btIndirect
||
1321 t
->bt
== btStruct
||
1324 t
->bt
== btTypedef
||
1327 char name
[256], *pn
;
1329 /* Try to cross reference this type */
1330 ax
+= cross_ref(ax
, &tp
, type_code
, &pn
);
1331 /* reading .o file ? */
1332 if (UNSAFE_DATA_ADDR(tp
))
1333 tp
= make_type(type_code
, 0, 0, 0);
1334 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1335 sprintf(name
, fmt
, pn
);
1337 /* Usually, TYPE_CODE(tp) is already type_code. The main
1338 exception is if we guessed wrong re struct/union/enum. */
1339 if (TYPE_CODE(tp
) != type_code
) {
1340 complain (&bad_tag_guess_complaint
, 0);
1341 TYPE_CODE(tp
) = type_code
;
1343 if (TYPE_NAME(tp
) == NULL
|| strcmp(TYPE_NAME(tp
), name
) != 0)
1344 TYPE_NAME(tp
) = obsavestring(name
, strlen(name
));
1347 /* Deal with range types */
1348 if (t
->bt
== btRange
) {
1351 TYPE_NFIELDS (tp
) = 2;
1353 (struct field
*) obstack_alloc (symbol_obstack
,
1354 2 * sizeof (struct field
));
1355 TYPE_FIELD_NAME (tp
, 0) = "Low";
1356 TYPE_FIELD_BITPOS (tp
, 0) = ax
->dnLow
;
1358 TYPE_FIELD_NAME (tp
, 1) = "High";
1359 TYPE_FIELD_BITPOS (tp
, 1) = ax
->dnHigh
;
1363 /* Parse all the type qualifiers now. If there are more
1364 than 6 the game will continue in the next aux */
1366 #define PARSE_TQ(tq) \
1367 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, sh);
1369 again
: PARSE_TQ(tq0
);
1384 /* Make up a complex type from a basic one. Type is passed by
1385 reference in TPP and side-effected as necessary. The type
1386 qualifier TQ says how to handle the aux symbols at AX for
1387 the symbol SX we are currently analyzing.
1388 Returns the number of aux symbols we parsed. */
1391 upgrade_type(tpp
, tq
, ax
, sh
)
1399 /* Used in array processing */
1408 t
= lookup_pointer_type (*tpp
);
1413 t
= lookup_function_type (*tpp
);
1419 t
= make_type(TYPE_CODE_ARRAY
, 0, 0, 0);
1420 TYPE_TARGET_TYPE(t
) = *tpp
;
1422 /* Determine and record the domain type (type of index) */
1423 id
= ax
->rndx
.index
;
1429 fh
= get_rfd(cur_fd
, rf
);
1431 /* Fields are kept in an array */
1432 /* FIXME - Memory leak! */
1433 if (TYPE_NFIELDS(t
))
1434 TYPE_FIELDS(t
) = (struct field
*)
1435 xrealloc(TYPE_FIELDS(t
),
1436 (TYPE_NFIELDS(t
)+1) * sizeof(struct field
));
1438 TYPE_FIELDS(t
) = (struct field
*)
1439 xzalloc(sizeof(struct field
));
1440 f
= &(TYPE_FIELD(t
,TYPE_NFIELDS(t
)));
1442 memset(f
, 0, sizeof(struct field
));
1444 memset(&ss
, 0, sizeof ss
);
1445 /* XXX */ f
->type
= parse_type(fh
->iauxBase
+ id
* sizeof(AUXU
),
1450 * This seems to be a pointer to the end of the Block defining
1451 * the type. Why it is here is magic for me, and I have no
1452 * good use for it anyways.
1454 /* This used to occur because cross_ref returned
1455 the wrong result (ax pointed wrong). FIXME,
1456 delete this code in a while. -- gnu@cygnus jul91 */
1457 complain (&array_parse_complaint
, 0);
1459 id
= (++ax
)->rndx
.index
;
1460 if ((rf
= ax
->rndx
.rfd
) == 0xfff)
1461 rf
= (++ax
)->isym
, off
++;
1463 lower
= (++ax
)->dnLow
;
1464 upper
= (++ax
)->dnHigh
;
1465 rf
= (++ax
)->width
; /* bit size of array element */
1467 /* Check whether supplied array element bit size matches
1468 the known size of the element type. If this complaint
1469 ends up not happening, we can remove this code. It's
1470 here because we aren't sure we understand this *&%&$
1472 id
= TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) << 3; /* bitsize */
1474 /* Most likely an undefined type */
1476 TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) = id
>> 3;
1479 complain (&array_bitsize_complaint
, rf
);
1481 TYPE_LENGTH(t
) = (upper
< 0) ? 0 :
1482 (upper
- lower
+ 1) * (rf
>> 3);
1487 /* Volatile -- currently ignored */
1491 complain (&unknown_type_qual_complaint
, tq
);
1497 /* Parse a procedure descriptor record PR. Note that the procedure
1498 is parsed _after_ the local symbols, now we just make up the
1499 extra information we need into a special symbol that we insert
1500 in the procedure's main block. Note also that images that
1501 have been partially stripped (ld -x) have been deprived
1502 of local symbols, and we have to cope with them here.
1503 The procedure's code ends at BOUND */
1506 parse_procedure(pr
, bound
)
1509 struct symbol
*s
, *i
;
1510 SYMR
*sh
= (SYMR
*)pr
->isym
;
1512 struct mips_extra_func_info
*e
;
1516 /* Reuse the MIPS record */
1517 e
= (struct mips_extra_func_info
*) pr
;
1518 e
->numargs
= lookup_numargs(pr
->adr
);
1520 /* Make up our special symbol */
1521 i
= new_symbol(".gdbinfo.");
1522 SYMBOL_VALUE(i
) = (int)e
;
1523 SYMBOL_NAMESPACE(i
) = LABEL_NAMESPACE
;
1524 SYMBOL_CLASS(i
) = LOC_CONST
;
1525 SYMBOL_TYPE(i
) = builtin_type_void
;
1527 /* Make up a name for static procedures. Sigh. */
1528 if (sh
== (SYMR
*)-1) {
1529 sprintf(name
,".static_procedure@%x",pr
->adr
);
1530 sh_name
= savestring(name
, strlen(name
));
1534 sh_name
= (char*)sh
->iss
;
1535 s
= mylookup_symbol(sh_name
, top_stack
->cur_block
,
1536 VAR_NAMESPACE
, LOC_BLOCK
);
1539 b
= SYMBOL_BLOCK_VALUE(s
);
1541 s
= new_symbol(sh_name
);
1542 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1543 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1544 /* Donno its type, hope int is ok */
1545 SYMBOL_TYPE(s
) = lookup_function_type (builtin_type_int
);
1546 add_symbol(s
, top_stack
->cur_block
);
1547 /* Wont have symbols for this one */
1549 SYMBOL_BLOCK_VALUE(s
) = b
;
1550 BLOCK_FUNCTION(b
) = s
;
1551 BLOCK_START(b
) = pr
->adr
;
1552 BLOCK_END(b
) = bound
;
1553 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1554 add_block(b
, top_stack
->cur_st
);
1560 /* Parse the external symbol ES. Just call parse_symbol() after
1561 making sure we know where the aux are for it. For procedures,
1562 parsing of the PDRs has already provided all the needed
1563 information, we only parse them if SKIP_PROCEDURES is false,
1564 and only if this causes no symbol duplication.
1566 This routine clobbers top_stack->cur_block and ->cur_st. */
1569 parse_external(es
, skip_procedures
)
1574 if (es
->ifd
!= ifdNil
) {
1576 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
) + cur_fd
;
1577 ax
= (AUXU
*)cur_fdr
->iauxBase
;
1579 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
);
1582 top_stack
->cur_st
= cur_stab
;
1583 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
1586 /* Reading .o files */
1587 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
) {
1589 switch (es
->asym
.st
) {
1591 case stProc
: what
= "procedure"; n_undef_procs
++; break;
1592 case stGlobal
: what
= "variable"; n_undef_vars
++; break;
1593 case stLabel
: what
= "label"; n_undef_labels
++; break;
1594 default : what
= "symbol"; break;
1598 printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what
,
1599 es
->asym
.iss
, fdr_name(cur_fdr
->rss
));
1603 switch (es
->asym
.st
) {
1605 /* If we have full symbols we do not need more */
1606 if (skip_procedures
)
1608 if (mylookup_symbol (es
->asym
.iss
, top_stack
->cur_block
,
1609 VAR_NAMESPACE
, LOC_BLOCK
))
1615 * Note that the case of a symbol with indexNil
1616 * must be handled anyways by parse_symbol().
1618 parse_symbol(&es
->asym
, ax
);
1625 /* Parse the line number info for file descriptor FH into
1626 GDB's linetable LT. MIPS' encoding requires a little bit
1627 of magic to get things out. Note also that MIPS' line
1628 numbers can go back and forth, apparently we can live
1629 with that and do not need to reorder our linetables */
1634 struct linetable
*lt
;
1636 unsigned char *base
= (unsigned char*)fh
->cbLineOffset
;
1638 int delta
, count
, lineno
= 0;
1644 /* Scan by procedure descriptors */
1645 i
= 0; j
= 0, k
= 0;
1646 for (pr
= (PDR
*)IPDFIRST(cur_hdr
,fh
); j
< fh
->cpd
; j
++, pr
++) {
1649 /* No code for this one */
1650 if (pr
->iline
== ilineNil
||
1651 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1654 * Aurgh! To know where to stop expanding we
1657 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1658 if (pr
[l
].iline
!= -1)
1660 if (l
== (fh
->cpd
- j
))
1665 * When procedures are moved around the linenumbers
1666 * are attributed to the next procedure up
1668 if (pr
->iline
>= halt
) continue;
1670 base
= (unsigned char*)pr
->cbLineOffset
;
1671 l
= pr
->adr
>> 2; /* in words */
1672 halt
+= (pr
->adr
>> 2) - pr
->iline
;
1673 for (lineno
= pr
->lnLow
; l
< halt
;) {
1674 count
= *base
& 0x0f;
1675 delta
= *base
++ >> 4;
1679 delta
= (base
[0] << 8) | base
[1];
1680 if (delta
>= 0x8000)
1684 lineno
+= delta
;/* first delta is 0 */
1685 k
= add_line(lt
, lineno
, l
, k
);
1692 /* Master parsing procedure for first-pass reading of file symbols
1693 into a partial_symtab.
1695 Parses the symtab described by the global symbolic header CUR_HDR.
1696 END_OF_TEXT_SEG gives the address just after the text segment for
1697 the symtab we are reading. */
1700 parse_partial_symbols(end_of_text_seg
, objfile
)
1701 int end_of_text_seg
;
1702 struct objfile
*objfile
;
1705 /* int stat_idx, h_max;*/
1706 HDRR
*hdr
= cur_hdr
;
1707 /* Running pointers */
1712 struct partial_symtab
*pst
;
1714 int past_first_source_file
= 0;
1716 /* List of current psymtab's include files */
1717 char **psymtab_include_list
;
1718 int includes_allocated
;
1721 struct pst_map
* fdr_to_pst
;
1722 /* Index within current psymtab dependency list */
1723 struct partial_symtab
**dependency_list
;
1724 int dependencies_used
, dependencies_allocated
;
1725 struct cleanup
*old_chain
;
1727 extern_tab
= (EXTR
**)obstack_alloc (psymbol_obstack
,
1728 sizeof(EXTR
*) * hdr
->iextMax
);
1730 includes_allocated
= 30;
1732 psymtab_include_list
= (char **) alloca (includes_allocated
*
1734 next_symbol_text_func
= mips_next_symbol_text
;
1736 dependencies_allocated
= 30;
1737 dependencies_used
= 0;
1739 (struct partial_symtab
**) alloca (dependencies_allocated
*
1740 sizeof (struct partial_symtab
*));
1742 last_source_file
= 0;
1747 * Only parse the Local and External symbols, and the Relative FDR.
1748 * Fixup enough of the loader symtab to be able to use it.
1749 * Allocate space only for the file's portions we need to
1754 max_glevel
= MIN_GLEVEL
;
1756 /* Allocate the map FDR -> PST.
1757 Minor hack: -O3 images might claim some global data belongs
1758 to FDR -1. We`ll go along with that */
1759 fdr_to_pst
= (struct pst_map
*)xzalloc((hdr
->ifdMax
+1) * sizeof *fdr_to_pst
);
1760 old_chain
= make_cleanup (free
, fdr_to_pst
);
1763 struct partial_symtab
* pst
= new_psymtab("", objfile
);
1764 fdr_to_pst
[-1].pst
= pst
;
1768 /* Pass 1 over external syms: Presize and partition the list */
1769 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1770 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1771 fdr_to_pst
[esh
->ifd
].n_globals
++;
1774 /* Pass 1.5 over files: partition out global symbol space */
1776 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++) {
1777 fdr_to_pst
[f_idx
].globals_offset
= s_idx
;
1778 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
1779 fdr_to_pst
[f_idx
].n_globals
= 0;
1782 /* Pass 2 over external syms: fill in external symbols */
1783 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1784 enum misc_function_type misc_type
= mf_text
;
1785 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1787 extern_tab
[fdr_to_pst
[esh
->ifd
].globals_offset
1788 + fdr_to_pst
[esh
->ifd
].n_globals
++] = esh
;
1790 if (esh
->asym
.sc
== scUndefined
|| esh
->asym
.sc
== scNil
)
1793 switch (esh
->asym
.st
) {
1797 misc_type
= mf_data
;
1802 misc_type
= mf_unknown
;
1803 complain (&unknown_ext_complaint
,
1804 (char *)(esh
->asym
.iss
));
1806 prim_record_misc_function ((char *)(esh
->asym
.iss
),
1811 /* Pass 3 over files, over local syms: fill in static symbols */
1812 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
1813 struct partial_symtab
*save_pst
;
1815 cur_fdr
= fh
= f_idx
+ (FDR
*)(cur_hdr
->cbFdOffset
);
1817 if (fh
->csym
== 0) {
1818 fdr_to_pst
[f_idx
].pst
= NULL
;
1821 pst
= start_psymtab_common (objfile
, 0, (char*)fh
->rss
,
1822 fh
->cpd
? fh
->adr
: 0,
1823 global_psymbols
.next
,
1824 static_psymbols
.next
);
1825 pst
->read_symtab_private
= (char *)
1826 obstack_alloc (psymbol_obstack
, sizeof (struct symloc
));
1829 /* Make everything point to everything. */
1830 FDR_IDX(pst
) = f_idx
;
1831 fdr_to_pst
[f_idx
].pst
= pst
;
1832 fh
->ioptBase
= (int)pst
;
1834 CUR_HDR(pst
) = cur_hdr
;
1836 /* The way to turn this into a symtab is to call... */
1837 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
1839 pst
->texthigh
= pst
->textlow
;
1841 pst
->globals_offset
= global_psymbols
.next
- global_psymbols
.list
;
1842 pst
->statics_offset
= static_psymbols
.next
- static_psymbols
.list
;
1844 pst
->n_global_syms
= 0;
1845 pst
->n_static_syms
= 0;
1847 /* The second symbol must be @stab.
1848 This symbol is emitted by mips-tfile to signal
1849 that the current object file uses encapsulated stabs
1850 instead of mips ecoff for local symbols.
1851 (It is the second symbol because the first symbol is
1852 the stFile used to signal the start of a file). */
1854 && strcmp(((SYMR
*)fh
->isymBase
)[1].iss
, stabs_symbol
) == 0) {
1855 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++) {
1858 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
1859 type_code
= MIPS_UNMARK_STAB(sh
->index
);
1860 if (!MIPS_IS_STAB(sh
)) {
1861 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
) {
1862 long procaddr
= sh
->value
;
1863 sh
= (sh
->index
+ (AUXU
*)fh
->iauxBase
)->isym
1864 + (SYMR
*) fh
->isymBase
- 1;
1865 if (sh
->st
== stEnd
) {
1866 long high
= procaddr
+ sh
->value
;
1867 if (high
> pst
->texthigh
)
1868 pst
->texthigh
= high
;
1873 #define SET_NAMESTRING() namestring = (char*)sh->iss
1874 #define CUR_SYMBOL_TYPE type_code
1875 #define CUR_SYMBOL_VALUE sh->value
1876 #define START_PSYMTAB(ofile,addr,fname,low,symoff,global_syms,static_syms)\
1878 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
1879 #define addr 0 /* FIXME, should be offset of addresses */
1880 #define HANDLE_RBRAC(val) \
1881 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
1882 #include "partial-stab.h"
1887 register struct partial_symbol
*psym
;
1888 for (cur_sdx
= 0; cur_sdx
< fh
->csym
; ) {
1889 register struct partial_symbol
*p
;
1892 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
1894 if (MIPS_IS_STAB(sh
)) {
1899 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
1900 sh
->index
== 0xfffff) {
1901 /* FIXME, premature? */
1906 name
= (char *)(sh
->iss
);
1911 case stProc
: /* Asm labels apparently */
1912 case stStaticProc
: /* Function */
1913 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
1914 VAR_NAMESPACE
, LOC_BLOCK
,
1915 static_psymbols
, sh
->value
);
1916 /* Skip over procedure to next one. */
1917 cur_sdx
= (sh
->index
+ (AUXU
*)fh
->iauxBase
)->isym
;
1918 procaddr
= sh
->value
;
1920 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
- 1;
1921 if (sh
->st
!= stEnd
)
1923 high
= procaddr
+ sh
->value
;
1924 if (high
> pst
->texthigh
)
1925 pst
->texthigh
= high
;
1927 case stStatic
: /* Variable */
1930 case stTypedef
: /* Typedef */
1931 class = LOC_TYPEDEF
;
1933 case stConstant
: /* Constant decl */
1936 case stBlock
: /* { }, str, un, enum*/
1937 if (sh
->sc
== scInfo
) {
1938 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
1939 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
1940 static_psymbols
, sh
->value
);
1942 /* Skip over the block */
1943 cur_sdx
= sh
->index
;
1945 case stFile
: /* File headers */
1946 case stLabel
: /* Labels */
1947 case stEnd
: /* Ends of files */
1950 complain (&unknown_sym_complaint
, SYMBOL_NAME(p
));
1951 complain (&unknown_st_complaint
, sh
->st
);
1955 /* Use this gdb symbol */
1956 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
1957 VAR_NAMESPACE
, class,
1958 static_psymbols
, sh
->value
);
1960 cur_sdx
++; /* Go to next file symbol */
1963 /* Now do enter the external symbols. */
1964 ext_ptr
= &extern_tab
[fdr_to_pst
[f_idx
].globals_offset
];
1965 cur_sdx
= fdr_to_pst
[f_idx
].n_globals
;
1966 PST_PRIVATE(save_pst
)->extern_count
= cur_sdx
;
1967 PST_PRIVATE(save_pst
)->extern_tab
= ext_ptr
;
1968 for (; --cur_sdx
>= 0; ext_ptr
++) {
1969 enum address_class
class;
1970 if ((*ext_ptr
)->ifd
!= f_idx
)
1972 sh
= &(*ext_ptr
)->asym
;
1981 complain (&unknown_ext_complaint
, sh
->iss
);
1986 if (global_psymbols
.next
>=
1987 global_psymbols
.list
+ global_psymbols
.size
)
1988 extend_psymbol_list (&global_psymbols
);
1989 psym
= global_psymbols
.next
++;
1990 SYMBOL_NAME (psym
) = (char*)sh
->iss
;
1991 SYMBOL_NAMESPACE (psym
) = VAR_NAMESPACE
;
1992 SYMBOL_CLASS (psym
) = class;
1993 SYMBOL_VALUE_ADDRESS (psym
) = (CORE_ADDR
)sh
->value
;
1997 end_psymtab (save_pst
, psymtab_include_list
, includes_used
,
1998 -1, save_pst
->texthigh
,
1999 dependency_list
, dependencies_used
,
2000 global_psymbols
.next
, static_psymbols
.next
);
2001 if (entry_point
< save_pst
->texthigh
2002 && entry_point
>= save_pst
->textlow
) {
2003 startup_file_start
= save_pst
->textlow
;
2004 startup_file_end
= save_pst
->texthigh
;
2008 /* Mark the last code address, and remember it for later */
2009 hdr
->cbDnOffset
= end_of_text_seg
;
2011 do_cleanups (old_chain
);
2016 /* Do the initial analisys of the F_IDX-th file descriptor.
2017 Allocates a partial symtab for it, and builds the list
2018 of dependent files by recursion. LEV says at which level
2019 of recursion we are called (to pretty up debug traces) */
2021 static struct partial_symtab
*
2022 parse_fdr(f_idx
, lev
, objfile
)
2025 struct objfile
*objfile
;
2028 register struct partial_symtab
*pst
;
2031 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + f_idx
;
2033 /* Use this to indicate into which symtab this file was parsed */
2035 return (struct partial_symtab
*) fh
->ioptBase
;
2037 /* Debuggability level */
2038 if (compare_glevel(max_glevel
, fh
->glevel
) < 0)
2039 max_glevel
= fh
->glevel
;
2041 /* Make a new partial_symtab */
2042 pst
= new_psymtab(fh
->rss
, objfile
);
2047 pst
->textlow
= fh
->adr
;
2048 pst
->texthigh
= fh
->cpd
; /* To be fixed later */
2051 /* Make everything point to everything. */
2052 FDR_IDX(pst
) = f_idx
;
2053 fdr_to_pst
[f_idx
].pst
= pst
;
2054 fh
->ioptBase
= (int)pst
;
2056 /* Analyze its dependencies */
2061 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
2062 /* ...then presumably a .h file: drop reverse depends .h->.c */
2063 for (; s_id0
< fh
->crfd
; s_id0
++) {
2064 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
2066 s_id0
++; /* Skip self-dependency */
2071 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2072 pst
->dependencies
= (struct partial_symtab
**)
2073 obstack_alloc (psymbol_obstack
,
2074 pst
->number_of_dependencies
*
2075 sizeof (struct partial_symtab
*));
2076 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
2077 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
2079 pst
->dependencies
[s_idx
-s_id0
] = parse_fdr(*rh
, lev
+1, objfile
);
2087 mips_next_symbol_text ()
2090 return (char*)((SYMR
*)cur_fdr
->isymBase
)[cur_sdx
].iss
;
2093 /* Ancillary function to psymtab_to_symtab(). Does all the work
2094 for turning the partial symtab PST into a symtab, recurring
2095 first on all dependent psymtabs. The argument FILENAME is
2096 only passed so we can see in debug stack traces what file
2100 psymtab_to_symtab_1(pst
, filename
)
2101 struct partial_symtab
*pst
;
2109 struct linetable
*lines
;
2115 /* How many symbols will we need */
2116 /* FIXME, this does not count enum values. */
2117 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
2118 if (FDR_IDX(pst
) == -1) {
2122 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + FDR_IDX(pst
);
2123 f_max
+= fh
->csym
+ fh
->cpd
;
2124 maxlines
= 2 * fh
->cline
;
2127 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2130 && strcmp(((SYMR
*)fh
->isymBase
)[1].iss
, stabs_symbol
) == 0;
2134 st
= new_symtab (pst
->filename
, 2 * f_max
, maxlines
,
2137 st
= new_symtab ("unknown", f_max
, 0, pst
->objfile
);
2138 lines
= LINETABLE(st
);
2139 pending_list
= (struct mips_pending
**) cur_hdr
->cbOptOffset
;
2140 if (pending_list
== 0) {
2141 pending_list
= (struct mips_pending
**)
2142 xzalloc(cur_hdr
->ifdMax
* sizeof(struct mips_pending
*));
2143 cur_hdr
->cbOptOffset
= (int)pending_list
;
2147 /* Read in all partial symbtabs on which this one is dependent.
2148 NOTE that we do have circular dependencies, sigh. We solved
2149 that by setting pst->readin before this point. */
2151 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2152 if (!pst
->dependencies
[i
]->readin
) {
2153 /* Inform about additional files to be read in. */
2156 fputs_filtered (" ", stdout
);
2158 fputs_filtered ("and ", stdout
);
2160 printf_filtered ("%s...",
2161 pst
->dependencies
[i
]->filename
);
2162 wrap_here (""); /* Flush output */
2165 /* We only pass the filename for debug purposes */
2166 psymtab_to_symtab_1(pst
->dependencies
[i
],
2167 pst
->dependencies
[i
]->filename
);
2171 /* Now read the symbols for this symtab */
2174 cur_fd
= FDR_IDX(pst
);
2177 /* Get a new lexical context */
2180 top_stack
->cur_st
= cur_stab
;
2181 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab
),
2183 BLOCK_START(top_stack
->cur_block
) = fh
? fh
->adr
: 0;
2184 BLOCK_END(top_stack
->cur_block
) = 0;
2185 top_stack
->blocktype
= stFile
;
2186 top_stack
->maxsyms
= 2*f_max
;
2187 top_stack
->cur_type
= 0;
2188 top_stack
->procadr
= 0;
2189 top_stack
->numargs
= 0;
2192 /* Parse locals and procedures */
2197 char *fh_name
= (char*)fh
->rss
;
2199 /* Parse local symbols first */
2205 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++) {
2206 register SYMR
*sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
2207 char *name
= (char*)sh
->iss
;
2208 CORE_ADDR valu
= sh
->value
;
2209 if (MIPS_IS_STAB(sh
)) {
2210 int type_code
= MIPS_UNMARK_STAB(sh
->index
);
2211 process_one_symbol (type_code
, 0, valu
, name
, /*FIXME*/ 0);
2213 else if (sh
->st
== stLabel
&& sh
->index
!= indexNil
) {
2214 /* Handle encoded stab line number. */
2215 record_line (current_subfile
, sh
->index
, valu
);
2218 st
= end_symtab (pst
->texthigh
, 0, 0, pst
->objfile
);
2221 /* BOUND is the highest core address of this file's procedures */
2222 int bound
= cur_fd
== cur_hdr
->ifdMax
- 1 ? cur_hdr
->cbDnOffset
2224 for (cur_sdx
= 0; cur_sdx
< fh
->csym
; ) {
2225 sh
= (SYMR
*) (fh
->isymBase
) + cur_sdx
;
2226 cur_sdx
+= parse_symbol(sh
, fh
->iauxBase
);
2229 /* Procedures next, note we need to look-ahead to
2230 find out where the procedure's code ends */
2232 for (i
= 0; i
< fh
->cpd
-1; i
++) {
2233 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2234 parse_procedure(pr
, pr
[1].adr
); /* next proc up */
2237 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2238 parse_procedure(pr
, bound
); /* next file up */
2240 /* Linenumbers. At the end, check if we can save memory */
2241 parse_lines(fh
, lines
);
2242 if (lines
->nitems
< fh
->cline
)
2243 lines
= shrink_linetable(lines
);
2249 LINETABLE(st
) = lines
;
2251 /* .. and our share of externals.
2252 XXX use the global list to speed up things here. how ?
2253 FIXME, Maybe quit once we have found the right number of ext's? */
2254 /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
2255 top_stack
->blocktype
= stFile
;
2256 top_stack
->maxsyms
=
2257 cur_hdr
->isymMax
+ cur_hdr
->ipdMax
+ cur_hdr
->iextMax
;
2259 ext_ptr
= PST_PRIVATE(pst
)->extern_tab
;
2260 for (i
= PST_PRIVATE(pst
)->extern_count
; --i
>= 0; ext_ptr
++)
2261 parse_external(*ext_ptr
, 1);
2263 /* If there are undefined, tell the user */
2264 if (n_undef_symbols
) {
2265 printf_filtered("File %s contains %d unresolved references:",
2266 st
->filename
, n_undef_symbols
);
2267 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2268 n_undef_vars
, n_undef_procs
, n_undef_labels
);
2269 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
2275 /* Sort the symbol table now, we are done adding symbols to it.*/
2276 sort_symtab_syms(st
);
2280 /* Now link the psymtab and the symtab. */
2284 /* Ancillary parsing procedures. */
2286 /* Lookup the type at relative index RN. Return it in TPP
2287 if found and in any event come up with its name PNAME.
2288 Return value says how many aux symbols we ate */
2291 cross_ref(rn
, tpp
, type_code
, pname
)
2294 int type_code
; /* Use to alloc new type if none is found. */
2299 /* Escape index means 'the next one' */
2300 if (rn
->rfd
== 0xfff)
2301 rf
= *(unsigned *) (rn
+ 1);
2307 *pname
= "<undefined>";
2310 * Find the relative file descriptor and the symbol in it
2312 FDR
*fh
= get_rfd(cur_fd
, rf
);
2317 * If we have processed this symbol then we left a forwarding
2318 * pointer to the corresponding GDB symbol. If not, we`ll put
2319 * it in a list of pending symbols, to be processed later when
2320 * the file f will be. In any event, we collect the name for
2321 * the type here. Which is why we made a first pass at
2324 sh
= (SYMR
*) (fh
->isymBase
) + rn
->index
;
2326 /* Careful, we might be looking at .o files */
2327 *pname
= (UNSAFE_DATA_ADDR(sh
->iss
)) ? "<undefined>" :
2330 /* Have we parsed it ? */
2331 if ((!UNSAFE_DATA_ADDR(sh
->value
)) && (sh
->st
== stParsed
)) {
2332 t
= (struct type
*) sh
->value
;
2335 /* Avoid duplicates */
2336 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
2340 *tpp
= make_type(type_code
, 0, 0, 0);
2341 add_pending(fh
, sh
, *tpp
);
2346 /* We used one auxent normally, two if we got a "next one" rf. */
2347 return (rn
->rfd
== 0xfff? 2: 1);
2351 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2352 keeping the symtab sorted */
2354 static struct symbol
*
2355 mylookup_symbol (name
, block
, namespace, class)
2357 register struct block
*block
;
2358 enum namespace namespace;
2359 enum address_class
class;
2361 register int bot
, top
, inc
;
2362 register struct symbol
*sym
;
2365 top
= BLOCK_NSYMS(block
);
2368 sym
= BLOCK_SYM(block
, bot
);
2369 if (SYMBOL_NAME(sym
)[0] == inc
2370 && SYMBOL_NAMESPACE(sym
) == namespace
2371 && SYMBOL_CLASS(sym
) == class
2372 && !strcmp(SYMBOL_NAME(sym
), name
))
2376 if (block
= BLOCK_SUPERBLOCK (block
))
2377 return mylookup_symbol (name
, block
, namespace, class);
2382 /* Add a new symbol S to a block B.
2383 Infrequently, we will need to reallocate the block to make it bigger.
2384 We only detect this case when adding to top_stack->cur_block, since
2385 that's the only time we know how big the block is. FIXME. */
2392 int nsyms
= BLOCK_NSYMS(b
)++;
2393 struct block
*origb
;
2394 struct parse_stack
*stackp
;
2396 if (b
== top_stack
->cur_block
&&
2397 nsyms
>= top_stack
->maxsyms
) {
2398 complain (&block_overflow_complaint
, s
->name
);
2399 /* In this case shrink_block is actually grow_block, since
2400 BLOCK_NSYMS(b) is larger than its current size. */
2402 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
2404 /* Now run through the stack replacing pointers to the
2405 original block. shrink_block has already done this
2406 for the blockvector and BLOCK_FUNCTION. */
2407 for (stackp
= top_stack
; stackp
; stackp
= stackp
->next
) {
2408 if (stackp
->cur_block
== origb
) {
2409 stackp
->cur_block
= b
;
2410 stackp
->maxsyms
= BLOCK_NSYMS (b
);
2414 BLOCK_SYM(b
,nsyms
) = s
;
2417 /* Add a new block B to a symtab S */
2424 struct blockvector
*bv
= BLOCKVECTOR(s
);
2426 bv
= (struct blockvector
*)xrealloc(bv
, sizeof(struct blockvector
) +
2427 BLOCKVECTOR_NBLOCKS(bv
) * sizeof(bv
->block
));
2428 if (bv
!= BLOCKVECTOR(s
))
2429 BLOCKVECTOR(s
) = bv
;
2431 BLOCKVECTOR_BLOCK(bv
, BLOCKVECTOR_NBLOCKS(bv
)++) = b
;
2434 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2435 MIPS' linenumber encoding might need more than one byte
2436 to describe it, LAST is used to detect these continuation lines */
2439 add_line(lt
, lineno
, adr
, last
)
2440 struct linetable
*lt
;
2446 last
= -2; /* make sure we record first line */
2448 if (last
== lineno
) /* skip continuation lines */
2451 lt
->item
[lt
->nitems
].line
= lineno
;
2452 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
2458 /* Comparison functions, used when sorting things */
2460 /* Symtabs must be ordered viz the code segments they cover */
2463 compare_symtabs( s1
, s2
)
2464 struct symtab
**s1
, **s2
;
2466 /* "most specific" first */
2468 register struct block
*b1
, *b2
;
2469 b1
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1
),GLOBAL_BLOCK
);
2470 b2
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2
),GLOBAL_BLOCK
);
2471 if (BLOCK_END(b1
) == BLOCK_END(b2
))
2472 return BLOCK_START(b1
) - BLOCK_START(b2
);
2473 return BLOCK_END(b1
) - BLOCK_END(b2
);
2477 /* Partial Symtabs, same */
2480 compare_psymtabs( s1
, s2
)
2481 struct partial_symtab
**s1
, **s2
;
2483 /* Perf twist: put the ones with no code at the end */
2485 register int a
= (*s1
)->textlow
;
2486 register int b
= (*s2
)->textlow
;
2495 /* Blocks with a smaller low bound should come first */
2497 static int compare_blocks(b1
,b2
)
2498 struct block
**b1
, **b2
;
2500 register int addr_diff
;
2502 addr_diff
= (BLOCK_START((*b1
))) - (BLOCK_START((*b2
)));
2504 return (BLOCK_END((*b1
))) - (BLOCK_END((*b2
)));
2509 /* Sorting and reordering procedures */
2511 /* Sort the blocks of a symtab S.
2512 Reorder the blocks in the blockvector by code-address,
2513 as required by some MI search routines */
2519 struct blockvector
*bv
= BLOCKVECTOR(s
);
2521 if (BLOCKVECTOR_NBLOCKS(bv
) <= 2) {
2523 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) == 0)
2524 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = 0;
2525 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) == 0)
2526 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) = 0;
2530 * This is very unfortunate: normally all functions are compiled in
2531 * the order they are found, but if the file is compiled -O3 things
2532 * are very different. It would be nice to find a reliable test
2533 * to detect -O3 images in advance.
2535 if (BLOCKVECTOR_NBLOCKS(bv
) > 3)
2536 qsort(&BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
),
2537 BLOCKVECTOR_NBLOCKS(bv
) - FIRST_LOCAL_BLOCK
,
2538 sizeof(struct block
*),
2542 register CORE_ADDR high
= 0;
2543 register int i
, j
= BLOCKVECTOR_NBLOCKS(bv
);
2545 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
2546 if (high
< BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
)))
2547 high
= BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
));
2548 BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = high
;
2551 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) =
2552 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
));
2554 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2555 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2556 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2557 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2561 /* Constructor/restructor/destructor procedures */
2563 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2564 MAXSYMS and linenumbers MAXLINES we'll put in it */
2568 new_symtab(name
, maxsyms
, maxlines
, objfile
)
2571 struct symtab
*s
= allocate_symtab (name
, objfile
);
2573 LINETABLE(s
) = new_linetable(maxlines
);
2575 /* All symtabs must have at least two blocks */
2576 BLOCKVECTOR(s
) = new_bvect(2);
2577 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
) = new_block(maxsyms
);
2578 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), STATIC_BLOCK
) = new_block(maxsyms
);
2579 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
),STATIC_BLOCK
)) =
2580 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
);
2582 s
->free_code
= free_linetable
;
2584 /* Link the new symtab into the list of such. */
2585 s
->next
= symtab_list
;
2591 /* Allocate a new partial_symtab NAME */
2593 static struct partial_symtab
*
2594 new_psymtab(name
, objfile
)
2596 struct objfile
*objfile
;
2598 struct partial_symtab
*pst
;
2600 pst
= (struct partial_symtab
*)
2601 obstack_alloc (psymbol_obstack
, sizeof (*pst
));
2602 memset (pst
, 0, sizeof (*pst
));
2604 if (name
== (char*)-1) /* FIXME -- why not null here? */
2605 pst
->filename
= "<no name>";
2607 pst
->filename
= name
;
2609 /* Chain it to its object file */
2610 pst
->objfile
= objfile
;
2611 pst
->objfile_chain
= objfile
->psymtabs
;
2612 objfile
->psymtabs
= pst
;
2614 pst
->next
= partial_symtab_list
;
2615 partial_symtab_list
= pst
;
2617 /* Keep a backpointer to the file's symbols */
2618 pst
->read_symtab_private
= (char *) obstack_alloc (psymbol_obstack
,
2619 sizeof (struct symloc
));
2620 CUR_HDR(pst
) = cur_hdr
;
2622 /* The way to turn this into a symtab is to call... */
2623 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
2629 /* Allocate a linetable array of the given SIZE */
2631 static struct linetable
*
2634 struct linetable
*l
;
2636 size
= size
* sizeof(l
->item
) + sizeof(struct linetable
);
2637 l
= (struct linetable
*)xmalloc(size
);
2642 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2643 I am not so sure about the 3.4 ones */
2645 static struct linetable
*
2646 shrink_linetable(lt
)
2647 struct linetable
* lt
;
2649 struct linetable
*l
= new_linetable(lt
->nitems
);
2651 memcpy(l
, lt
, lt
->nitems
* sizeof(l
->item
) + sizeof(struct linetable
));
2656 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2659 struct blockvector
*
2662 struct blockvector
*bv
;
2665 size
= sizeof(struct blockvector
) + nblocks
* sizeof(struct block
*);
2666 bv
= (struct blockvector
*) xzalloc(size
);
2668 BLOCKVECTOR_NBLOCKS(bv
) = nblocks
;
2673 /* Allocate and zero a new block of MAXSYMS symbols */
2679 int size
= sizeof(struct block
) + (maxsyms
-1) * sizeof(struct symbol
*);
2680 struct block
*b
= (struct block
*)xzalloc(size
);
2685 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2686 Shrink_block can also be used by add_symbol to grow a block. */
2688 static struct block
*
2694 struct blockvector
*bv
= BLOCKVECTOR(s
);
2697 /* Just reallocate it and fix references to the old one */
2699 new = (struct block
*) xrealloc ((char *)b
, sizeof(struct block
) +
2700 (BLOCK_NSYMS(b
)-1) * sizeof(struct symbol
*));
2702 /* Should chase pointers to old one. Fortunately, that`s just
2703 the block`s function and inferior blocks */
2704 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b
)
2705 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2706 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2707 if (BLOCKVECTOR_BLOCK(bv
,i
) == b
)
2708 BLOCKVECTOR_BLOCK(bv
,i
) = new;
2709 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) == b
)
2710 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) = new;
2714 /* Create a new symbol with printname NAME */
2721 struct symbol
*s
= (struct symbol
*)
2722 obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
2724 memset (s
, 0, sizeof (*s
));
2725 SYMBOL_NAME(s
) = name
;
2729 /* Create a new type with printname NAME */
2736 struct type
*t
= (struct type
*)
2737 obstack_alloc (symbol_obstack
, sizeof (struct type
));
2739 memset (t
, 0, sizeof (*t
));
2740 TYPE_VPTR_FIELDNO (t
) = -1;
2741 TYPE_NAME(t
) = name
;
2742 TYPE_CPLUS_SPECIFIC(t
) = &cplus_struct_default
;
2746 /* Create and initialize a new type with printname NAME.
2747 CODE and LENGTH are the initial info we put in,
2748 UNS says whether the type is unsigned or not. */
2752 make_type(code
, length
, uns
, name
)
2753 enum type_code code
;
2757 register struct type
*type
;
2759 /* FIXME, I don't think this ever gets freed. */
2760 type
= (struct type
*) xzalloc(sizeof(struct type
));
2761 TYPE_CODE(type
) = code
;
2762 TYPE_LENGTH(type
) = length
;
2763 TYPE_FLAGS(type
) = uns
? TYPE_FLAG_UNSIGNED
: 0;
2764 TYPE_NAME(type
) = name
;
2765 TYPE_VPTR_FIELDNO (type
) = -1;
2767 if (code
!= TYPE_CODE_METHOD
&& code
!= TYPE_CODE_FUNC
)
2768 TYPE_CPLUS_SPECIFIC(type
) = &cplus_struct_default
;
2772 /* Things used for calling functions in the inferior.
2773 These functions are exported to our companion
2774 mips-tdep.c file and are here because they play
2775 with the symbol-table explicitly. */
2777 /* Sigtramp: make sure we have all the necessary information
2778 about the signal trampoline code. Since the official code
2779 from MIPS does not do so, we make up that information ourselves.
2780 If they fix the library (unlikely) this code will neutralize itself. */
2787 struct block
*b
, *b0
;
2789 sigtramp_address
= -1;
2791 /* We know it is sold as sigvec */
2792 s
= lookup_symbol("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
2794 /* Most programs do not play with signals */
2798 b0
= SYMBOL_BLOCK_VALUE(s
);
2800 /* A label of sigvec, to be more precise */
2801 s
= lookup_symbol("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
2803 /* But maybe this program uses its own version of sigvec */
2807 sigtramp_address
= SYMBOL_VALUE(s
);
2808 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
2810 /* Did we or MIPSco fix the library ? */
2811 if (SYMBOL_CLASS(s
) == LOC_BLOCK
)
2814 /* But what symtab does it live in ? */
2815 st
= find_pc_symtab(SYMBOL_VALUE(s
));
2818 * Ok, there goes the fix: turn it into a procedure, with all the
2819 * needed info. Note we make it a nested procedure of sigvec,
2820 * which is the way the (assembly) code is actually written.
2822 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2823 SYMBOL_CLASS(s
) = LOC_BLOCK
;
2824 SYMBOL_TYPE(s
) = make_type(TYPE_CODE_FUNC
, 4, 0, 0);
2825 TYPE_TARGET_TYPE(SYMBOL_TYPE(s
)) = builtin_type_void
;
2827 /* Need a block to allocate .gdbinfo. in */
2829 SYMBOL_BLOCK_VALUE(s
) = b
;
2830 BLOCK_START(b
) = sigtramp_address
;
2831 BLOCK_END(b
) = sigtramp_end
;
2832 BLOCK_FUNCTION(b
) = s
;
2833 BLOCK_SUPERBLOCK(b
) = BLOCK_SUPERBLOCK(b0
);
2837 /* Make a .gdbinfo. for it */
2839 struct mips_extra_func_info
*e
=
2840 (struct mips_extra_func_info
*)
2841 xzalloc(sizeof(struct mips_extra_func_info
));
2843 e
->numargs
= 0; /* the kernel thinks otherwise */
2844 /* align_longword(sigcontext + SIGFRAME) */
2845 e
->framesize
= 0x150;
2846 e
->framereg
= SP_REGNUM
;
2849 e
->regoffset
= -(41 * sizeof(int));
2851 e
->fregoffset
= -(37 * sizeof(int));
2854 s
= new_symbol(".gdbinfo.");
2855 SYMBOL_VALUE(s
) = (int) e
;
2856 SYMBOL_NAMESPACE(s
) = LABEL_NAMESPACE
;
2857 SYMBOL_CLASS(s
) = LOC_CONST
;
2858 SYMBOL_TYPE(s
) = builtin_type_void
;
2861 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
2864 /* Initialization */
2866 static struct sym_fns ecoff_sym_fns
= {"ecoff", 5,
2867 mipscoff_new_init
, mipscoff_symfile_init
,
2868 mipscoff_symfile_read
};
2870 _initialize_mipsread ()
2872 add_symtab_fns (&ecoff_sym_fns
);
2874 /* Missing basic types */
2875 builtin_type_string
= make_type(TYPE_CODE_PASCAL_ARRAY
,
2877 builtin_type_complex
= make_type(TYPE_CODE_FLT
,
2878 2 * sizeof(float), 0, "complex");
2879 builtin_type_double_complex
= make_type(TYPE_CODE_FLT
,
2880 2 * sizeof(double), 0, "double_complex");
2881 builtin_type_fixed_dec
= make_type(TYPE_CODE_INT
, sizeof(int),
2882 0, "fixed_decimal");
2883 builtin_type_float_dec
= make_type(TYPE_CODE_FLT
, sizeof(double),
2884 0, "floating_decimal");