1 /* Read a symbol table in MIPS' format (Third-Eye).
2 Copyright 1986, 1987, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
3 Contributed by Alessandro Forin (af@cs.cmu.edu) at CMU. Major
4 work by Per Bothner and John Gilmore at Cygnus Support.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
22 /* This module provides three functions: mipscoff_symfile_init,
23 which initializes to read a symbol file; mipscoff_new_init, which
24 discards existing cached information when all symbols are being
25 discarded; and mipscoff_symfile_read, which reads a symbol table
28 mipscoff_symfile_read only does the minimum work necessary for letting the
29 user "name" things symbolically; it does not read the entire symtab.
30 Instead, it reads the external and static symbols and puts them in partial
31 symbol tables. When more extensive information is requested of a
32 file, the corresponding partial symbol table is mutated into a full
33 fledged symbol table by going back and reading the symbols
34 for real. mipscoff_psymtab_to_symtab() is called indirectly through
35 a pointer in the psymtab to do this.
37 ECOFF symbol tables are mostly written in the byte order of the
38 target machine. However, one section of the table (the auxiliary
39 symbol information) is written in the host byte order. There is a
40 bit in the other symbol info which describes which host byte order
41 was used. ECOFF thereby takes the trophy from Intel `b.out' for
42 the most brain-dead adaptation of a file format to byte order.
44 This module can read all four of the known byte-order combinations,
45 on any type of host. However, it does make (and check) the assumption
46 that the external form of a symbol table structure (on disk)
47 occupies the same number of bytes as the internal form (in a struct).
48 Fixing this is possible but requires larger structural changes. */
50 #define TM_FILE_OVERRIDE
59 #include <sys/param.h>
63 #include <mips/syms.h>
70 #endif /* not CMUCS */
72 #include "coff/mips.h"
73 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
74 #include "aout/aout64.h"
75 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native, now */
76 #include "coff/ecoff-ext.h"
79 struct external_filehdr f
;
80 struct external_aouthdr a
;
83 /* These must match the corresponding definition in gcc/config/xm-mips.h.
84 At some point, these should probably go into a shared include file,
85 but currently gcc and gdb do not share any directories. */
87 #define CODE_MASK 0x8F300
88 #define MIPS_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK)
89 #define MIPS_MARK_STAB(code) ((code)+CODE_MASK)
90 #define MIPS_UNMARK_STAB(code) ((code)-CODE_MASK)
91 #define STABS_SYMBOL "@stabs"
93 /* Each partial symbol table entry contains a pointer to private data for the
94 read_symtab() function to use when expanding a partial symbol table entry
95 to a full symbol table entry.
97 For mipsread this structure contains the index of the FDR that this psymtab
98 represents and a pointer to the symbol table header HDRR from the symbol
99 file that the psymtab was created from. */
101 #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
102 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
103 #define CUR_HDR(p) (PST_PRIVATE(p)->cur_hdr)
108 EXTR
**extern_tab
; /* Pointer to external symbols for this file. */
109 int extern_count
; /* Size of extern_tab. */
112 /* Things we import explicitly from other modules */
114 extern int info_verbose
;
115 extern struct block
*block_for_pc();
116 extern void sort_symtab_syms();
118 /* Various complaints about symbol reading that don't abort the process */
120 struct complaint bad_file_number_complaint
=
121 {"bad file number %d", 0, 0};
123 struct complaint unknown_ext_complaint
=
124 {"unknown external symbol %s", 0, 0};
126 struct complaint unknown_sym_complaint
=
127 {"unknown local symbol %s", 0, 0};
129 struct complaint unknown_st_complaint
=
130 {"with type %d", 0, 0};
132 struct complaint block_overflow_complaint
=
133 {"block containing %s overfilled", 0, 0};
135 struct complaint basic_type_complaint
=
136 {"cannot map MIPS basic type 0x%x", 0, 0};
138 struct complaint unknown_type_qual_complaint
=
139 {"unknown type qualifier 0x%x", 0, 0};
141 struct complaint array_bitsize_complaint
=
142 {"size of array target type not known, assuming %d bits", 0, 0};
144 struct complaint bad_tag_guess_complaint
=
145 {"guessed tag type incorrectly", 0, 0};
147 /* Macros and extra defs */
149 /* Already-parsed symbols are marked specially */
151 #define stParsed stType
153 /* Puns: hard to find whether -g was used and how */
155 #define MIN_GLEVEL GLEVEL_0
156 #define compare_glevel(a,b) \
157 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
158 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
160 /* When looking at .o files, avoid tripping over bad addresses */
162 #define SAFE_TEXT_ADDR 0x400000
163 #define SAFE_DATA_ADDR 0x10000000
165 #define UNSAFE_DATA_ADDR(p) ((unsigned)p < SAFE_DATA_ADDR || (unsigned)p > 2*SAFE_DATA_ADDR)
167 /* Things that really are local to this module */
169 /* GDB symtable for the current compilation unit */
171 static struct symtab
*cur_stab
;
173 /* MIPS symtab header for the current file */
175 static HDRR
*cur_hdr
;
177 /* Pointer to current file decriptor record, and its index */
182 /* Index of current symbol */
186 /* Note how much "debuggable" this image is. We would like
187 to see at least one FDR with full symbols */
192 /* When examining .o files, report on undefined symbols */
194 static int n_undef_symbols
, n_undef_labels
, n_undef_vars
, n_undef_procs
;
196 /* Pseudo symbol to use when putting stabs into the symbol table. */
198 static char stabs_symbol
[] = STABS_SYMBOL
;
200 /* Extra builtin types */
202 struct type
*builtin_type_complex
;
203 struct type
*builtin_type_double_complex
;
204 struct type
*builtin_type_fixed_dec
;
205 struct type
*builtin_type_float_dec
;
206 struct type
*builtin_type_string
;
208 /* Forward declarations */
220 parse_partial_symbols();
228 static struct symbol
*new_symbol();
229 static struct type
*new_type();
230 static struct block
*new_block();
231 static struct symtab
*new_symtab();
232 static struct linetable
*new_linetable();
233 static struct blockvector
*new_bvect();
235 static struct type
*parse_type();
236 static struct symbol
*mylookup_symbol();
237 static struct block
*shrink_block();
238 static void sort_blocks();
240 static int compare_symtabs();
241 static int compare_psymtabs();
242 static int compare_blocks();
244 static struct partial_symtab
*new_psymtab();
245 static struct partial_symtab
*parse_fdr();
246 static int compare_psymbols();
248 static void psymtab_to_symtab_1();
249 static void add_block();
250 static void add_symbol();
251 static int add_line();
252 static struct linetable
*shrink_linetable();
253 static char* mips_next_symbol_text ();
256 /* Things we export to other modules */
258 /* Address bounds for the signal trampoline in inferior, if any */
259 /* FIXME: Nothing really seems to use this. Why is it here? */
261 CORE_ADDR sigtramp_address
, sigtramp_end
;
263 /* The entry point (starting address) of the file, if it is an executable. */
265 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
266 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
269 mipscoff_new_init (objfile
)
270 struct objfile
*objfile
;
275 mipscoff_symfile_init (objfile
)
276 struct objfile
*objfile
;
278 if (objfile
-> sym_private
!= NULL
)
280 mfree (objfile
-> md
, objfile
-> sym_private
);
282 objfile
-> sym_private
= NULL
;
286 mipscoff_symfile_read (objfile
, addr
, mainline
)
287 struct objfile
*objfile
;
291 bfd
*abfd
= objfile
-> obfd
;
294 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
295 desc
= fileno ((FILE *)(abfd
->iostream
)); /* Raw file descriptor */
298 init_minimal_symbol_collection ();
299 make_cleanup (discard_minimal_symbols
, 0);
301 /* Now that the executable file is positioned at symbol table,
302 process it and define symbols accordingly. */
304 read_mips_symtab(objfile
, desc
);
306 /* Install any minimal symbols that have been collected as the current
307 minimal symbols for this objfile. */
309 install_minimal_symbols (objfile
);
312 /* Perform any local cleanups required when we are done with a particular
313 objfile. I.E, we are in the process of discarding all symbol information
314 for an objfile, freeing up all memory held for it, and unlinking the
315 objfile struct from the global list of known objfiles. */
318 mipscoff_symfile_finish (objfile
)
319 struct objfile
*objfile
;
321 if (objfile
-> sym_private
!= NULL
)
323 mfree (objfile
-> md
, objfile
-> sym_private
);
326 /* If we have a file symbol header lying around, blow it away. */
330 free ((char *)cur_hdr
);
335 /* Allocate zeroed memory */
340 char *p
= xmalloc(size
);
346 /* Exported procedure: Builds a symtab from the PST partial one.
347 Restores the environment in effect when PST was created, delegates
348 most of the work to an ancillary procedure, and sorts
349 and reorders the symtab list at the end */
352 mipscoff_psymtab_to_symtab(pst
)
353 struct partial_symtab
*pst
;
362 printf_filtered("Reading in symbols for %s...", pst
->filename
);
365 /* Restore the header and list of pending typedefs */
366 cur_hdr
= CUR_HDR(pst
);
368 next_symbol_text_func
= mips_next_symbol_text
;
370 psymtab_to_symtab_1(pst
, pst
->filename
);
372 /* Match with global symbols. This only needs to be done once,
373 after all of the symtabs and dependencies have been read in. */
374 scan_file_globals (pst
->objfile
);
377 printf_filtered("done.\n");
380 /* Exported procedure: Is PC in the signal trampoline code */
383 in_sigtramp(pc
, name
)
387 if (sigtramp_address
== 0)
389 return (pc
>= sigtramp_address
&& pc
< sigtramp_end
);
392 /* File-level interface functions */
394 /* Read the symtab information from file FSYM into memory. Also,
395 return address just past end of our text segment in *END_OF_TEXT_SEGP. */
398 read_the_mips_symtab(abfd
, fsym
, end_of_text_segp
)
401 CORE_ADDR
*end_of_text_segp
;
403 int stsize
, st_hdrsize
;
405 struct hdr_ext hdr_ext
;
407 /* Header for executable/object file we read symbols from */
408 struct coff_exec filhdr
;
410 /* We need some info from the initial headers */
412 myread(fsym
, (char *)&filhdr
, sizeof filhdr
);
414 if (end_of_text_segp
)
416 bfd_h_get_32 (abfd
, filhdr
.a
.text_start
) +
417 bfd_h_get_32 (abfd
, filhdr
.a
.tsize
);
419 /* Find and read the symbol table header */
420 st_hdrsize
= bfd_h_get_32 (abfd
, filhdr
.f
.f_nsyms
);
421 st_filptr
= bfd_h_get_32 (abfd
, filhdr
.f
.f_symptr
);
425 lseek(fsym
, st_filptr
, L_SET
);
426 if (st_hdrsize
!= sizeof (hdr_ext
)) { /* Profanity check */
427 error ("Wrong header size: %d, not %d", st_hdrsize
,
430 if (read(fsym
, &hdr_ext
, st_hdrsize
) != st_hdrsize
)
432 ecoff_swap_hdr_in (abfd
, &hdr_ext
, &st_hdr
);
434 /* Find out how large the symbol table is */
435 stsize
= (st_hdr
.cbExtOffset
- (st_filptr
+ st_hdrsize
))
436 + st_hdr
.iextMax
* cbEXTR
;
438 /* Allocate space for the symbol table. Read it in. */
439 cur_hdr
= (HDRR
*) xmalloc(stsize
+ st_hdrsize
);
441 memcpy(cur_hdr
, &hdr_ext
, st_hdrsize
);
442 if (read(fsym
, (char *) cur_hdr
+ st_hdrsize
, stsize
) != stsize
)
445 /* Fixup file_pointers in it */
446 fixup_symtab(cur_hdr
, (char *) cur_hdr
+ st_hdrsize
,
447 st_filptr
+ st_hdrsize
, abfd
);
451 error("Short read on %s", bfd_get_filename (abfd
));
455 /* Turn all file-relative pointers in the symtab described by HDR
456 into memory pointers, given that the symtab itself is located
457 at DATA in memory and F_PTR in the file.
459 Byte-swap all the data structures, in place, while we are at it --
460 except AUX entries, which we leave in their original byte order.
461 They will be swapped as they are used instead. (FIXME: we ought to
462 do all the data structures that way.) */
465 fixup_symtab (hdr
, data
, f_ptr
, abfd
)
476 struct rfd_ext
*rbase
;
478 /* This function depends on the external and internal forms
479 of the MIPS symbol table taking identical space. Check this
480 assumption at compile-time. */
481 static check_hdr1
[1 + sizeof (struct hdr_ext
) - sizeof (HDRR
)] = {0};
482 static check_hdr2
[1 + sizeof (HDRR
) - sizeof (struct hdr_ext
)] = {0};
483 static check_fdr1
[1 + sizeof (struct fdr_ext
) - sizeof (FDR
)] = {0};
484 static check_fdr2
[1 + sizeof (FDR
) - sizeof (struct fdr_ext
)] = {0};
485 static check_pdr1
[1 + sizeof (struct pdr_ext
) - sizeof (PDR
)] = {0};
486 static check_pdr2
[1 + sizeof (PDR
) - sizeof (struct pdr_ext
)] = {0};
487 static check_sym1
[1 + sizeof (struct sym_ext
) - sizeof (SYMR
)] = {0};
488 static check_sym2
[1 + sizeof (SYMR
) - sizeof (struct sym_ext
)] = {0};
489 static check_ext1
[1 + sizeof (struct ext_ext
) - sizeof (EXTR
)] = {0};
490 static check_ext2
[1 + sizeof (EXTR
) - sizeof (struct ext_ext
)] = {0};
491 static check_rfd1
[1 + sizeof (struct rfd_ext
) - sizeof (RFDT
)] = {0};
492 static check_rfd2
[1 + sizeof (RFDT
) - sizeof (struct rfd_ext
)] = {0};
494 /* Swap in the header record. */
495 ecoff_swap_hdr_in (abfd
, hdr
, hdr
);
498 * These fields are useless (and empty) by now:
499 * hdr->cbDnOffset, hdr->cbOptOffset
500 * We use them for other internal purposes.
503 hdr
->cbOptOffset
= 0;
506 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
520 /* Fix all the RFD's. */
521 rbase
= (struct rfd_ext
*)(hdr
->cbRfdOffset
);
522 for (i
= 0; i
< hdr
->crfd
; i
++) {
523 ecoff_swap_rfd_in (abfd
, rbase
+i
, (pRFDT
) rbase
+i
);
526 /* Fix all string pointers inside the symtab, and
527 the FDR records. Also fix other miscellany. */
529 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
530 register unsigned code_offset
;
532 /* Header itself, and strings */
533 fh
= (FDR
*) (hdr
->cbFdOffset
) + f_idx
;
535 /* Swap in the FDR */
536 ecoff_swap_fdr_in (abfd
, fh
, fh
);
538 fh
->issBase
+= hdr
->cbSsOffset
;
540 fh
->rss
= (long)fh
->rss
+ fh
->issBase
;
543 fh
->isymBase
= (int)((SYMR
*)(hdr
->cbSymOffset
)+fh
->isymBase
);
545 /* FIXME! Probably don't want to do this here! */
546 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
547 sh
= (SYMR
*)fh
->isymBase
+ s_idx
;
548 ecoff_swap_sym_in (abfd
, sh
, sh
);
550 sh
->iss
= (long) sh
->iss
+ fh
->issBase
;
556 /* cannot fix fh->ipdFirst because it is a short */
557 #define IPDFIRST(h,fh) \
558 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
560 /* Optional symbols (actually used for partial_symtabs) */
566 fh
->iauxBase
= hdr
->cbAuxOffset
+ fh
->iauxBase
* sizeof(union aux_ext
);
567 /* Relative file descriptor table */
568 fh
->rfdBase
= hdr
->cbRfdOffset
+ fh
->rfdBase
* sizeof(RFDT
);
572 fh
->cbLineOffset
+= hdr
->cbLineOffset
;
574 /* Procedure symbols. (XXX This should be done later) */
575 code_offset
= fh
->adr
;
576 for (s_idx
= 0; s_idx
< fh
->cpd
; s_idx
++) {
577 unsigned name
, only_ext
;
579 pr
= (PDR
*)(IPDFIRST(hdr
,fh
)) + s_idx
;
580 ecoff_swap_pdr_in (abfd
, pr
, pr
);
582 /* Simple rule to find files linked "-x" */
583 only_ext
= fh
->rss
== -1;
585 if (pr
->isym
== -1) {
586 /* static function */
590 name
= hdr
->cbExtOffset
+ pr
->isym
* sizeof(EXTR
);
591 sh
= &((EXTR
*)name
)->asym
;
595 sh
= (SYMR
*)fh
->isymBase
+ pr
->isym
;
596 /* Included code ? */
597 if (s_idx
== 0 && pr
->adr
!= 0)
598 code_offset
-= pr
->adr
;
601 /* Turn index into a pointer */
604 /* Fix line numbers */
605 pr
->cbLineOffset
+= fh
->cbLineOffset
;
607 /* Relocate address */
609 pr
->adr
+= code_offset
;
613 /* External symbols: swap in, and fix string */
614 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
615 esh
= (EXTR
*)(hdr
->cbExtOffset
) + s_idx
;
616 ecoff_swap_ext_in (abfd
, esh
, esh
);
617 esh
->asym
.iss
= esh
->asym
.iss
+ hdr
->cbSsExtOffset
;
622 /* Find a file descriptor given its index RF relative to a file CF */
630 f
= (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
631 /* Object files do not have the RFD table, all refs are absolute */
633 return (FDR
*) (cur_hdr
->cbFdOffset
) + rf
;
634 cf
= *((pRFDT
) f
->rfdBase
+ rf
);
635 return (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
638 /* Return a safer print NAME for a file descriptor */
644 if (name
== (char *) -1)
645 return "<stripped file>";
646 if (UNSAFE_DATA_ADDR(name
))
652 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
653 whether we are adding to the general symtab or not.
654 FIXME: INCREMENTAL is currently always zero, though it should not be. */
657 read_mips_symtab (objfile
, desc
)
658 struct objfile
*objfile
;
661 CORE_ADDR end_of_text_seg
;
663 read_the_mips_symtab(objfile
->obfd
, desc
, &end_of_text_seg
);
665 parse_partial_symbols(end_of_text_seg
, objfile
);
669 * Check to make sure file was compiled with -g.
670 * If not, warn the user of this limitation.
672 if (compare_glevel(max_glevel
, GLEVEL_2
) < 0) {
673 if (max_gdbinfo
== 0)
675 "\n%s not compiled with -g, debugging support is limited.\n",
678 "You should compile with -g2 or -g3 for best debugging support.\n");
684 /* Local utilities */
686 /* Map of FDR indexes to partial symtabs */
689 struct partial_symtab
*pst
; /* the psymtab proper */
690 int n_globals
; /* exported globals (external symbols) */
691 int globals_offset
; /* cumulative */
695 /* Utility stack, used to nest procedures and blocks properly.
696 It is a doubly linked list, to avoid too many alloc/free.
697 Since we might need it quite a few times it is NOT deallocated
700 static struct parse_stack
{
701 struct parse_stack
*next
, *prev
;
702 struct symtab
*cur_st
; /* Current symtab. */
703 struct block
*cur_block
; /* Block in it. */
704 int blocktype
; /* What are we parsing. */
705 int maxsyms
; /* Max symbols in this block. */
706 struct type
*cur_type
; /* Type we parse fields for. */
707 int cur_field
; /* Field number in cur_type. */
708 int procadr
; /* Start addres of this procedure */
709 int numargs
; /* Its argument count */
710 } *top_stack
; /* Top stack ptr */
713 /* Enter a new lexical context */
715 static push_parse_stack()
717 struct parse_stack
*new;
719 /* Reuse frames if possible */
720 if (top_stack
&& top_stack
->prev
)
721 new = top_stack
->prev
;
723 new = (struct parse_stack
*) xzalloc(sizeof(struct parse_stack
));
724 /* Initialize new frame with previous content */
726 register struct parse_stack
*prev
= new->prev
;
729 top_stack
->prev
= new;
731 new->next
= top_stack
;
736 /* Exit a lexical context */
738 static pop_parse_stack()
743 top_stack
= top_stack
->next
;
747 /* Cross-references might be to things we haven't looked at
748 yet, e.g. type references. To avoid too many type
749 duplications we keep a quick fixup table, an array
750 of lists of references indexed by file descriptor */
752 static struct mips_pending
{
753 struct mips_pending
*next
; /* link */
754 SYMR
*s
; /* the symbol */
755 struct type
*t
; /* its partial type descriptor */
759 /* Check whether we already saw symbol SH in file FH as undefined */
762 struct mips_pending
*is_pending_symbol(fh
, sh
)
766 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
767 register struct mips_pending
*p
;
769 /* Linear search is ok, list is typically no more than 10 deep */
770 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
776 /* Check whether we already saw type T in file FH as undefined */
779 struct mips_pending
*is_pending_type(fh
, t
)
783 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
784 register struct mips_pending
*p
;
786 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
792 /* Add a new undef symbol SH of type T */
795 add_pending(fh
, sh
, t
)
800 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
801 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
803 /* Make sure we do not make duplicates */
805 p
= (struct mips_pending
*) xmalloc(sizeof(*p
));
808 p
->next
= pending_list
[f_idx
];
809 pending_list
[f_idx
] = p
;
811 sh
->reserved
= 1; /* for quick check */
814 /* Throw away undef entries when done with file index F_IDX */
819 register struct mips_pending
*p
, *q
;
821 for (p
= pending_list
[f_idx
]; p
; p
= q
) {
825 pending_list
[f_idx
] = 0;
828 /* The number of args to a procedure is not explicit in the symtab,
829 this is the list of all those we know of.
830 This makes parsing more reasonable and avoids extra passes */
832 static struct numarg
{
833 struct numarg
*next
; /* link */
834 unsigned adr
; /* procedure's start address */
835 unsigned num
; /* arg count */
838 /* Record that the procedure at ADR takes NUM arguments. */
843 struct numarg
*n
= (struct numarg
*) xmalloc(sizeof(struct numarg
));
847 n
->next
= numargs_list
;
851 /* See if we know how many arguments the procedure at ADR takes */
856 struct numarg
*n
= numargs_list
;
858 while (n
&& n
->adr
!= adr
)
860 return (n
) ? n
->num
: -1;
863 /* Release storage when done with this file */
868 struct numarg
*n
= numargs_list
, *m
;
879 prepend_tag_kind(tag_name
, type_code
)
889 case TYPE_CODE_STRUCT
:
892 case TYPE_CODE_UNION
:
899 result
= (char*)obstack_alloc (¤t_objfile
->symbol_obstack
,
900 strlen(prefix
) + strlen(tag_name
) + 1);
901 sprintf(result
, "%s%s", prefix
, tag_name
);
906 /* Parsing Routines proper. */
908 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
909 For blocks, procedures and types we open a new lexical context.
910 This is basically just a big switch on the symbol's type.
911 Argument AX is the base pointer of aux symbols for this file (fh->iauxBase).
912 BIGEND says whether aux symbols are big-endian or little-endian.
913 Return count of SYMR's handled (normally one). */
916 parse_symbol(sh
, ax
, bigend
)
927 /* When a symbol is cross-referenced from other files/symbols
928 we mark it explicitly */
929 int pend
= (sh
->reserved
== 1);
930 enum address_class
class;
938 case stGlobal
: /* external symbol, goes into global block */
940 b
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
942 s
= new_symbol(sh
->iss
);
943 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
946 case stStatic
: /* static data, goes into current block. */
948 b
= top_stack
->cur_block
;
949 s
= new_symbol(sh
->iss
);
950 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
953 case stLocal
: /* local variable, goes into current block */
954 if (sh
->sc
== scRegister
) {
955 class = LOC_REGISTER
;
957 sh
->value
+= FP0_REGNUM
-32;
960 b
= top_stack
->cur_block
;
961 s
= new_symbol(sh
->iss
);
962 SYMBOL_VALUE(s
) = sh
->value
;
964 data
: /* Common code for symbols describing data */
965 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
966 SYMBOL_CLASS(s
) = class;
969 /* Type could be missing in a number of cases */
970 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
971 sh
->index
== 0xfffff)
972 SYMBOL_TYPE(s
) = builtin_type_int
; /* undefined? */
974 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, 0, bigend
);
975 /* Value of a data symbol is its memory address */
978 case stParam
: /* arg to procedure, goes into current block */
980 top_stack
->numargs
++;
982 name
= (char*)sh
->iss
;
983 /* Special GNU C++ name. */
984 if (name
[0] == CPLUS_MARKER
&& name
[1] == 't' && name
[2] == 0)
986 s
= new_symbol(name
);
988 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
989 if (sh
->sc
== scRegister
) {
990 SYMBOL_CLASS(s
) = LOC_REGPARM
;
992 sh
->value
+= FP0_REGNUM
-32;
994 SYMBOL_CLASS(s
) = LOC_ARG
;
995 SYMBOL_VALUE(s
) = sh
->value
;
996 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, 0, bigend
);
997 add_symbol(s
, top_stack
->cur_block
);
999 /* FIXME: This has not been tested. See dbxread.c */
1000 /* Add the type of this parameter to the function/procedure
1001 type of this block. */
1002 add_param_to_type(&top_stack
->cur_block
->function
->type
,s
);
1006 case stLabel
: /* label, goes into current block */
1007 s
= new_symbol(sh
->iss
);
1008 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
; /* so that it can be used */
1009 SYMBOL_CLASS(s
) = LOC_LABEL
; /* but not misused */
1010 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
1011 SYMBOL_TYPE(s
) = builtin_type_int
;
1012 add_symbol(s
, top_stack
->cur_block
);
1015 case stProc
: /* Procedure, usually goes into global block */
1016 case stStaticProc
: /* Static procedure, goes into current block */
1017 s
= new_symbol(sh
->iss
);
1018 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1019 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1020 /* Type of the return value */
1021 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
1022 t
= builtin_type_int
;
1024 t
= parse_type(ax
+ sh
->index
+ 1, 0, bigend
);
1025 b
= top_stack
->cur_block
;
1026 if (sh
->st
== stProc
) {
1027 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
1028 /* The next test should normally be true,
1029 but provides a hook for nested functions
1030 (which we don't want to make global). */
1031 if (b
== BLOCKVECTOR_BLOCK(bv
, STATIC_BLOCK
))
1032 b
= BLOCKVECTOR_BLOCK(bv
, GLOBAL_BLOCK
);
1036 /* Make a type for the procedure itself */
1038 /* FIXME: This has not been tested yet! See dbxread.c */
1039 /* Generate a template for the type of this function. The
1040 types of the arguments will be added as we read the symbol
1042 bcopy(SYMBOL_TYPE(s
),lookup_function_type(t
),sizeof(struct type
));
1044 SYMBOL_TYPE(s
) = lookup_function_type (t
);
1047 /* Create and enter a new lexical context */
1048 b
= new_block(top_stack
->maxsyms
);
1049 SYMBOL_BLOCK_VALUE(s
) = b
;
1050 BLOCK_FUNCTION(b
) = s
;
1051 BLOCK_START(b
) = BLOCK_END(b
) = sh
->value
;
1052 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1053 add_block(b
, top_stack
->cur_st
);
1055 /* Not if we only have partial info */
1056 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
1060 top_stack
->cur_block
= b
;
1061 top_stack
->blocktype
= sh
->st
;
1062 top_stack
->cur_type
= SYMBOL_TYPE(s
);
1063 top_stack
->cur_field
= -1;
1064 top_stack
->procadr
= sh
->value
;
1065 top_stack
->numargs
= 0;
1067 sh
->value
= (long) SYMBOL_TYPE(s
);
1071 #ifndef btVoid /* btVoid was added late. */
1074 /* These new symbol types have been recently added to SGI machines. */
1088 case stBlock
: /* Either a lexical block, or some type */
1090 top_stack
->blocktype
= stBlock
;
1091 if (sh
->sc
== scInfo
) { /* structure/union/enum def */
1093 sh
->st
== stStruct
? TYPE_CODE_STRUCT
1094 : sh
->st
== stUnion
? TYPE_CODE_UNION
1095 : sh
->st
== stEnum
? TYPE_CODE_ENUM
1102 s
= new_symbol(sh
->iss
);
1103 SYMBOL_NAMESPACE(s
) = STRUCT_NAMESPACE
;
1104 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1105 SYMBOL_VALUE(s
) = 0;
1106 add_symbol(s
, top_stack
->cur_block
);
1108 /* First count the number of fields. */
1109 for (tsym
= sh
+1; tsym
->st
!= stEnd
; tsym
++)
1110 if (tsym
->st
== stMember
) {
1111 if (nfields
== 0 && type_code
== TYPE_CODE_UNDEF
)
1112 /* If the type of the member is Nil (or Void)
1113 assume the tag is an enumeration. */
1114 if (tsym
->index
== indexNil
)
1115 type_code
= TYPE_CODE_ENUM
;
1117 ecoff_swap_tir_in (bigend
,
1118 &ax
[tsym
->index
].a_ti
,
1120 if (tir
.bt
== btNil
|| tir
.bt
== btVoid
)
1121 type_code
= TYPE_CODE_ENUM
;
1124 if (tsym
->value
> max_value
)
1125 max_value
= tsym
->value
;
1127 else if (tsym
->st
== stBlock
1128 || tsym
->st
== stParsed
) {
1129 if (tsym
->sc
== scVariant
) ; /*UNIMPLEMENTED*/
1130 if (tsym
->index
!= 0)
1131 tsym
= ((SYMR
*)cur_fdr
->isymBase
)
1135 /* There is no guaranteed way to distinguish struct,
1136 unions, and enums at this point. This is a bug in the
1137 original design (that has been fixed with the
1138 recent addition of the stStruct, stUnion, and stEnum
1139 symbol types.) The way you can tell is if/when you
1140 see a variable or field of that type: In that case
1141 the variable's type (in the AUX table) says if the
1142 type is struct, union, or enum,
1143 and points back to the stBlock here.
1144 So you can patch the tag kind up later - but only
1145 if there actually is a variable or field of that type.
1147 So until we know for sure, we will guess at this point.
1149 If the first member has index==indexNil or a void type,
1150 assume we have an enumeration.
1151 Otherwise, if there is more than one member, and all
1152 the members have offset 0, assume we have a union.
1153 Otherwise, assume we have a struct.
1155 The heuristic could guess wrong in the case of
1156 of an enumeration with no members or a union
1157 with one (or zero) members, or when all except the
1158 last field of a struct have width zero.
1159 These are uncommon and/or illegal situations, and
1160 in any case guessing wrong probably doesn't matter much.
1162 But if we later do find out we were wrong,
1163 we fixup the tag kind. Members of an enumeration
1164 must be handled differently from struct/union fields,
1165 and that is harder to patch up, but luckily we
1166 shouldn't need to. (If there are any enumeration
1167 members, we can tell for sure it's an enum here.) */
1169 if (type_code
== TYPE_CODE_UNDEF
)
1170 if (nfields
> 1 && max_value
== 0)
1171 type_code
= TYPE_CODE_UNION
;
1173 type_code
= TYPE_CODE_STRUCT
;
1175 /* If this type was expected, use its partial definition */
1177 t
= is_pending_symbol(cur_fdr
, sh
)->t
;
1179 t
= new_type(prepend_tag_kind(sh
->iss
, type_code
));
1181 TYPE_CODE(t
) = type_code
;
1182 TYPE_LENGTH(t
) = sh
->value
;
1183 TYPE_NFIELDS(t
) = nfields
;
1184 TYPE_FIELDS(t
) = f
= (struct field
*)
1185 obstack_alloc (¤t_objfile
-> type_obstack
,
1186 nfields
* sizeof (struct field
));
1188 if (type_code
== TYPE_CODE_ENUM
) {
1189 /* This is a non-empty enum. */
1190 for (tsym
= sh
+ 1; tsym
->st
== stMember
; tsym
++) {
1191 struct symbol
*enum_sym
;
1192 f
->bitpos
= tsym
->value
;
1194 f
->name
= (char*)tsym
->iss
;
1197 enum_sym
= (struct symbol
*)
1198 obstack_alloc (¤t_objfile
->symbol_obstack
,
1199 sizeof (struct symbol
));
1200 memset (enum_sym
, 0, sizeof (struct symbol
));
1201 SYMBOL_NAME (enum_sym
) = f
->name
;
1202 SYMBOL_CLASS (enum_sym
) = LOC_CONST
;
1203 SYMBOL_TYPE (enum_sym
) = t
;
1204 SYMBOL_NAMESPACE (enum_sym
) = VAR_NAMESPACE
;
1205 SYMBOL_VALUE (enum_sym
) = tsym
->value
;
1206 add_symbol(enum_sym
, top_stack
->cur_block
);
1208 /* Skip the stMembers that we've handled. */
1214 /* make this the current type */
1215 top_stack
->cur_type
= t
;
1216 top_stack
->cur_field
= 0;
1217 /* Mark that symbol has a type, and say which one */
1218 sh
->value
= (long) t
;
1220 /* beginnning of (code) block. Value of symbol
1221 is the displacement from procedure start */
1222 b
= new_block(top_stack
->maxsyms
);
1223 BLOCK_START(b
) = sh
->value
+ top_stack
->procadr
;
1224 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1225 top_stack
->cur_block
= b
;
1226 add_block(b
, top_stack
->cur_st
);
1230 case stEnd
: /* end (of anything) */
1231 if (sh
->sc
== scInfo
) {
1232 /* Finished with type */
1233 top_stack
->cur_type
= 0;
1234 } else if (sh
->sc
== scText
&&
1235 (top_stack
->blocktype
== stProc
||
1236 top_stack
->blocktype
== stStaticProc
)) {
1237 /* Finished with procedure */
1238 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
1242 BLOCK_END(top_stack
->cur_block
) += sh
->value
; /* size */
1243 got_numargs(top_stack
->procadr
, top_stack
->numargs
);
1244 /* Reallocate symbols, saving memory */
1245 b
= shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1247 /* f77 emits proc-level with address bounds==[0,0],
1248 So look for such child blocks, and patch them. */
1249 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++) {
1250 struct block
*b_bad
= BLOCKVECTOR_BLOCK(bv
,i
);
1251 if (BLOCK_SUPERBLOCK(b_bad
) == b
1252 && BLOCK_START(b_bad
) == top_stack
->procadr
1253 && BLOCK_END(b_bad
) == top_stack
->procadr
) {
1254 BLOCK_START(b_bad
) = BLOCK_START(b
);
1255 BLOCK_END(b_bad
) = BLOCK_END(b
);
1258 } else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
) {
1259 /* End of (code) block. The value of the symbol
1260 is the displacement from the procedure`s start
1261 address of the end of this block. */
1262 BLOCK_END(top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1263 (void) shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1265 pop_parse_stack(); /* restore previous lexical context */
1268 case stMember
: /* member of struct or union */
1269 f
= &TYPE_FIELDS(top_stack
->cur_type
)[top_stack
->cur_field
++];
1270 f
->name
= (char*)sh
->iss
;
1271 f
->bitpos
= sh
->value
;
1273 f
->type
= parse_type(ax
+ sh
->index
, &f
->bitsize
, bigend
);
1276 case stTypedef
: /* type definition */
1277 s
= new_symbol(sh
->iss
);
1278 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1279 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1280 SYMBOL_BLOCK_VALUE(s
) = top_stack
->cur_block
;
1281 add_symbol(s
, top_stack
->cur_block
);
1282 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, 0, bigend
);
1283 sh
->value
= (long) SYMBOL_TYPE(s
);
1286 case stFile
: /* file name */
1288 top_stack
->blocktype
= sh
->st
;
1291 /* I`ve never seen these for C */
1293 break; /* register relocation */
1295 break; /* forwarding address */
1297 break; /* constant */
1299 error("Unknown symbol type %x.", sh
->st
);
1305 /* Parse the type information provided in the raw AX entries for
1306 the symbol SH. Return the bitfield size in BS, in case.
1307 We must byte-swap the AX entries before we use them; BIGEND says whether
1308 they are big-endian or little-endian (from fh->fBigendian). */
1310 static struct type
*parse_type(ax
, bs
, bigend
)
1315 /* Null entries in this map are treated specially */
1316 static struct type
**map_bt
[] =
1318 &builtin_type_void
, /* btNil */
1320 &builtin_type_char
, /* btChar */
1321 &builtin_type_unsigned_char
, /* btUChar */
1322 &builtin_type_short
, /* btShort */
1323 &builtin_type_unsigned_short
, /* btUShort */
1324 &builtin_type_int
, /* btInt */
1325 &builtin_type_unsigned_int
, /* btUInt */
1326 &builtin_type_long
, /* btLong */
1327 &builtin_type_unsigned_long
, /* btULong */
1328 &builtin_type_float
, /* btFloat */
1329 &builtin_type_double
, /* btDouble */
1336 &builtin_type_complex
, /* btComplex */
1337 &builtin_type_double_complex
, /* btDComplex */
1339 &builtin_type_fixed_dec
, /* btFixedDec */
1340 &builtin_type_float_dec
, /* btFloatDec */
1341 &builtin_type_string
, /* btString */
1344 &builtin_type_void
, /* btVoid */
1348 struct type
*tp
= 0;
1354 /* Use aux as a type information record, map its basic type. */
1356 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1357 if (t
->bt
> (sizeof (map_bt
)/sizeof (*map_bt
))) {
1358 complain (&basic_type_complaint
, t
->bt
);
1359 return builtin_type_int
;
1361 if (map_bt
[t
->bt
]) {
1362 tp
= *map_bt
[t
->bt
];
1366 /* Cannot use builtin types -- build our own */
1369 tp
= lookup_pointer_type (builtin_type_void
);
1373 type_code
= TYPE_CODE_STRUCT
;
1377 type_code
= TYPE_CODE_UNION
;
1381 type_code
= TYPE_CODE_ENUM
;
1385 type_code
= TYPE_CODE_RANGE
;
1389 type_code
= TYPE_CODE_SET
;
1394 complain (&basic_type_complaint
, t
->bt
);
1395 return builtin_type_int
;
1399 /* Skip over any further type qualifiers (FIXME). */
1401 /* This is the way it would work if the compiler worked */
1405 ecoff_swap_tir_in (bigend
, ax
, t1
);
1406 } while (t1
->continued
);
1409 /* Move on to next aux */
1413 *bs
= AUX_GET_WIDTH (bigend
, ax
);
1417 /* All these types really point to some (common) MIPS type
1418 definition, and only the type-qualifiers fully identify
1419 them. We'll make the same effort at sharing. */
1420 if (t
->bt
== btIndirect
||
1421 t
->bt
== btStruct
||
1424 t
->bt
== btTypedef
||
1427 char name
[256], *pn
;
1429 /* Try to cross reference this type */
1430 ax
+= cross_ref(ax
, &tp
, type_code
, &pn
, bigend
);
1431 /* reading .o file ? */
1432 if (UNSAFE_DATA_ADDR(tp
))
1433 tp
= init_type(type_code
, 0, 0, 0, (struct objfile
*) NULL
);
1434 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1435 sprintf(name
, fmt
, pn
);
1437 /* Usually, TYPE_CODE(tp) is already type_code. The main
1438 exception is if we guessed wrong re struct/union/enum. */
1439 if (TYPE_CODE(tp
) != type_code
) {
1440 complain (&bad_tag_guess_complaint
, 0);
1441 TYPE_CODE(tp
) = type_code
;
1443 if (TYPE_NAME(tp
) == NULL
|| strcmp(TYPE_NAME(tp
), name
) != 0)
1444 TYPE_NAME(tp
) = obsavestring(name
, strlen(name
),
1445 ¤t_objfile
-> type_obstack
);
1448 /* Deal with range types */
1449 if (t
->bt
== btRange
) {
1452 TYPE_NFIELDS (tp
) = 2;
1454 (struct field
*) obstack_alloc (¤t_objfile
-> type_obstack
,
1455 2 * sizeof (struct field
));
1456 TYPE_FIELD_NAME (tp
, 0) = obsavestring ("Low", strlen ("Low"),
1457 ¤t_objfile
-> type_obstack
);
1458 TYPE_FIELD_BITPOS (tp
, 0) = AUX_GET_DNLOW (bigend
, ax
);
1460 TYPE_FIELD_NAME (tp
, 1) = obsavestring ("High", strlen ("High"),
1461 ¤t_objfile
-> type_obstack
);
1462 TYPE_FIELD_BITPOS (tp
, 1) = AUX_GET_DNHIGH (bigend
, ax
);
1466 /* Parse all the type qualifiers now. If there are more
1467 than 6 the game will continue in the next aux */
1469 #define PARSE_TQ(tq) \
1470 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, bigend);
1472 again
: PARSE_TQ(tq0
);
1482 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1488 /* Make up a complex type from a basic one. Type is passed by
1489 reference in TPP and side-effected as necessary. The type
1490 qualifier TQ says how to handle the aux symbols at AX for
1491 the symbol SX we are currently analyzing. BIGEND says whether
1492 aux symbols are big-endian or little-endian.
1493 Returns the number of aux symbols we parsed. */
1496 upgrade_type(tpp
, tq
, ax
, bigend
)
1504 /* Used in array processing */
1513 t
= lookup_pointer_type (*tpp
);
1518 t
= lookup_function_type (*tpp
);
1524 t
= init_type(TYPE_CODE_ARRAY
, 0, 0, 0, (struct objfile
*) NULL
);
1525 TYPE_TARGET_TYPE(t
) = *tpp
;
1527 /* Determine and record the domain type (type of index) */
1528 ecoff_swap_rndx_in (bigend
, ax
, &rndx
);
1533 rf
= AUX_GET_ISYM (bigend
, ax
);
1536 fh
= get_rfd(cur_fd
, rf
);
1538 /* Fields are kept in an array */
1539 /* FIXME - Memory leak! */
1540 if (TYPE_NFIELDS(t
))
1541 TYPE_FIELDS(t
) = (struct field
*)
1542 xrealloc((char *) TYPE_FIELDS(t
),
1543 (TYPE_NFIELDS(t
)+1) * sizeof(struct field
));
1545 TYPE_FIELDS(t
) = (struct field
*)
1546 xzalloc(sizeof(struct field
));
1547 f
= &(TYPE_FIELD(t
,TYPE_NFIELDS(t
)));
1549 memset(f
, 0, sizeof(struct field
));
1551 /* XXX */ f
->type
= parse_type(fh
->iauxBase
+ id
* sizeof(union aux_ext
),
1552 &f
->bitsize
, bigend
);
1555 lower
= AUX_GET_DNLOW (bigend
, ax
);
1557 upper
= AUX_GET_DNHIGH (bigend
, ax
);
1559 rf
= AUX_GET_WIDTH (bigend
, ax
); /* bit size of array element */
1561 /* Check whether supplied array element bit size matches
1562 the known size of the element type. If this complaint
1563 ends up not happening, we can remove this code. It's
1564 here because we aren't sure we understand this *&%&$
1566 id
= TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) << 3; /* bitsize */
1568 /* Most likely an undefined type */
1570 TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) = id
>> 3;
1573 complain (&array_bitsize_complaint
, rf
);
1575 TYPE_LENGTH(t
) = (upper
< 0) ? 0 :
1576 (upper
- lower
+ 1) * (rf
>> 3);
1581 /* Volatile -- currently ignored */
1585 complain (&unknown_type_qual_complaint
, tq
);
1591 /* Parse a procedure descriptor record PR. Note that the procedure
1592 is parsed _after_ the local symbols, now we just make up the
1593 extra information we need into a special symbol that we insert
1594 in the procedure's main block. Note also that images that
1595 have been partially stripped (ld -x) have been deprived
1596 of local symbols, and we have to cope with them here.
1597 The procedure's code ends at BOUND */
1600 parse_procedure(pr
, bound
)
1603 struct symbol
*s
, *i
;
1604 SYMR
*sh
= (SYMR
*)pr
->isym
;
1606 struct mips_extra_func_info
*e
;
1610 /* Reuse the MIPS record */
1611 e
= (struct mips_extra_func_info
*) pr
;
1612 e
->numargs
= lookup_numargs(pr
->adr
);
1614 /* Make up our special symbol */
1615 i
= new_symbol(".gdbinfo.");
1616 SYMBOL_VALUE(i
) = (int)e
;
1617 SYMBOL_NAMESPACE(i
) = LABEL_NAMESPACE
;
1618 SYMBOL_CLASS(i
) = LOC_CONST
;
1619 SYMBOL_TYPE(i
) = builtin_type_void
;
1621 /* Make up a name for static procedures. Sigh. */
1622 if (sh
== (SYMR
*)-1) {
1623 sprintf(name
,".static_procedure@%x",pr
->adr
);
1624 sh_name
= savestring(name
, strlen(name
));
1628 sh_name
= (char*)sh
->iss
;
1629 s
= mylookup_symbol(sh_name
, top_stack
->cur_block
,
1630 VAR_NAMESPACE
, LOC_BLOCK
);
1633 b
= SYMBOL_BLOCK_VALUE(s
);
1635 s
= new_symbol(sh_name
);
1636 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1637 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1638 /* Donno its type, hope int is ok */
1639 SYMBOL_TYPE(s
) = lookup_function_type (builtin_type_int
);
1640 add_symbol(s
, top_stack
->cur_block
);
1641 /* Wont have symbols for this one */
1643 SYMBOL_BLOCK_VALUE(s
) = b
;
1644 BLOCK_FUNCTION(b
) = s
;
1645 BLOCK_START(b
) = pr
->adr
;
1646 BLOCK_END(b
) = bound
;
1647 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1648 add_block(b
, top_stack
->cur_st
);
1654 /* Parse the external symbol ES. Just call parse_symbol() after
1655 making sure we know where the aux are for it. For procedures,
1656 parsing of the PDRs has already provided all the needed
1657 information, we only parse them if SKIP_PROCEDURES is false,
1658 and only if this causes no symbol duplication.
1659 BIGEND says whether aux entries are big-endian or little-endian.
1661 This routine clobbers top_stack->cur_block and ->cur_st. */
1664 parse_external(es
, skip_procedures
, bigend
)
1666 int skip_procedures
;
1671 if (es
->ifd
!= ifdNil
) {
1673 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
) + cur_fd
;
1674 ax
= (union aux_ext
*)cur_fdr
->iauxBase
;
1676 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
);
1679 top_stack
->cur_st
= cur_stab
;
1680 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
1683 /* Reading .o files */
1684 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
) {
1686 switch (es
->asym
.st
) {
1688 case stProc
: what
= "procedure"; n_undef_procs
++; break;
1689 case stGlobal
: what
= "variable"; n_undef_vars
++; break;
1690 case stLabel
: what
= "label"; n_undef_labels
++; break;
1691 default : what
= "symbol"; break;
1695 printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what
,
1696 es
->asym
.iss
, fdr_name(cur_fdr
->rss
));
1700 switch (es
->asym
.st
) {
1702 /* If we have full symbols we do not need more */
1703 if (skip_procedures
)
1705 if (mylookup_symbol (es
->asym
.iss
, top_stack
->cur_block
,
1706 VAR_NAMESPACE
, LOC_BLOCK
))
1712 * Note that the case of a symbol with indexNil
1713 * must be handled anyways by parse_symbol().
1715 parse_symbol(&es
->asym
, ax
, bigend
);
1722 /* Parse the line number info for file descriptor FH into
1723 GDB's linetable LT. MIPS' encoding requires a little bit
1724 of magic to get things out. Note also that MIPS' line
1725 numbers can go back and forth, apparently we can live
1726 with that and do not need to reorder our linetables */
1731 struct linetable
*lt
;
1733 unsigned char *base
= (unsigned char*)fh
->cbLineOffset
;
1735 int delta
, count
, lineno
= 0;
1741 /* Scan by procedure descriptors */
1742 i
= 0; j
= 0, k
= 0;
1743 for (pr
= (PDR
*)IPDFIRST(cur_hdr
,fh
); j
< fh
->cpd
; j
++, pr
++) {
1746 /* No code for this one */
1747 if (pr
->iline
== ilineNil
||
1748 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1751 * Aurgh! To know where to stop expanding we
1754 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1755 if (pr
[l
].iline
!= -1)
1757 if (l
== (fh
->cpd
- j
))
1762 * When procedures are moved around the linenumbers
1763 * are attributed to the next procedure up
1765 if (pr
->iline
>= halt
) continue;
1767 base
= (unsigned char*)pr
->cbLineOffset
;
1768 l
= pr
->adr
>> 2; /* in words */
1769 halt
+= (pr
->adr
>> 2) - pr
->iline
;
1770 for (lineno
= pr
->lnLow
; l
< halt
;) {
1771 count
= *base
& 0x0f;
1772 delta
= *base
++ >> 4;
1776 delta
= (base
[0] << 8) | base
[1];
1777 if (delta
>= 0x8000)
1781 lineno
+= delta
;/* first delta is 0 */
1782 k
= add_line(lt
, lineno
, l
, k
);
1789 /* Master parsing procedure for first-pass reading of file symbols
1790 into a partial_symtab.
1792 Parses the symtab described by the global symbolic header CUR_HDR.
1793 END_OF_TEXT_SEG gives the address just after the text segment for
1794 the symtab we are reading. */
1797 parse_partial_symbols(end_of_text_seg
, objfile
)
1798 int end_of_text_seg
;
1799 struct objfile
*objfile
;
1802 /* int stat_idx, h_max;*/
1803 HDRR
*hdr
= cur_hdr
;
1804 /* Running pointers */
1809 struct partial_symtab
*pst
;
1811 int past_first_source_file
= 0;
1813 /* List of current psymtab's include files */
1814 char **psymtab_include_list
;
1815 int includes_allocated
;
1818 struct pst_map
* fdr_to_pst
;
1819 /* Index within current psymtab dependency list */
1820 struct partial_symtab
**dependency_list
;
1821 int dependencies_used
, dependencies_allocated
;
1822 struct cleanup
*old_chain
;
1824 extern_tab
= (EXTR
**)obstack_alloc (&objfile
->psymbol_obstack
,
1825 sizeof(EXTR
*) * hdr
->iextMax
);
1827 includes_allocated
= 30;
1829 psymtab_include_list
= (char **) alloca (includes_allocated
*
1831 next_symbol_text_func
= mips_next_symbol_text
;
1833 dependencies_allocated
= 30;
1834 dependencies_used
= 0;
1836 (struct partial_symtab
**) alloca (dependencies_allocated
*
1837 sizeof (struct partial_symtab
*));
1839 last_source_file
= 0;
1844 * Only parse the Local and External symbols, and the Relative FDR.
1845 * Fixup enough of the loader symtab to be able to use it.
1846 * Allocate space only for the file's portions we need to
1851 max_glevel
= MIN_GLEVEL
;
1853 /* Allocate the map FDR -> PST.
1854 Minor hack: -O3 images might claim some global data belongs
1855 to FDR -1. We`ll go along with that */
1856 fdr_to_pst
= (struct pst_map
*)xzalloc((hdr
->ifdMax
+1) * sizeof *fdr_to_pst
);
1857 old_chain
= make_cleanup (free
, fdr_to_pst
);
1860 struct partial_symtab
* pst
= new_psymtab("", objfile
);
1861 fdr_to_pst
[-1].pst
= pst
;
1865 /* Pass 1 over external syms: Presize and partition the list */
1866 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1867 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1868 fdr_to_pst
[esh
->ifd
].n_globals
++;
1871 /* Pass 1.5 over files: partition out global symbol space */
1873 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++) {
1874 fdr_to_pst
[f_idx
].globals_offset
= s_idx
;
1875 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
1876 fdr_to_pst
[f_idx
].n_globals
= 0;
1879 /* Pass 2 over external syms: fill in external symbols */
1880 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1881 enum minimal_symbol_type ms_type
= mst_text
;
1882 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1884 extern_tab
[fdr_to_pst
[esh
->ifd
].globals_offset
1885 + fdr_to_pst
[esh
->ifd
].n_globals
++] = esh
;
1887 if (esh
->asym
.sc
== scUndefined
|| esh
->asym
.sc
== scNil
)
1890 switch (esh
->asym
.st
) {
1899 ms_type
= mst_unknown
;
1900 complain (&unknown_ext_complaint
,
1901 (char *)(esh
->asym
.iss
));
1903 prim_record_minimal_symbol ((char *)(esh
->asym
.iss
),
1908 /* Pass 3 over files, over local syms: fill in static symbols */
1909 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
1910 struct partial_symtab
*save_pst
;
1912 cur_fdr
= fh
= f_idx
+ (FDR
*)(cur_hdr
->cbFdOffset
);
1914 if (fh
->csym
== 0) {
1915 fdr_to_pst
[f_idx
].pst
= NULL
;
1918 pst
= start_psymtab_common (objfile
, 0, (char*)fh
->rss
,
1919 fh
->cpd
? fh
->adr
: 0,
1920 objfile
->global_psymbols
.next
,
1921 objfile
->static_psymbols
.next
);
1922 pst
->read_symtab_private
= (char *)
1923 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
1926 /* Make everything point to everything. */
1927 FDR_IDX(pst
) = f_idx
;
1928 fdr_to_pst
[f_idx
].pst
= pst
;
1929 fh
->ioptBase
= (int)pst
;
1931 CUR_HDR(pst
) = cur_hdr
;
1933 /* The way to turn this into a symtab is to call... */
1934 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
1936 pst
->texthigh
= pst
->textlow
;
1938 #if 0 /* This is done in start_psymtab_common */
1939 pst
->globals_offset
= global_psymbols
.next
- global_psymbols
.list
;
1940 pst
->statics_offset
= static_psymbols
.next
- static_psymbols
.list
;
1942 pst
->n_global_syms
= 0;
1943 pst
->n_static_syms
= 0;
1946 /* The second symbol must be @stab.
1947 This symbol is emitted by mips-tfile to signal
1948 that the current object file uses encapsulated stabs
1949 instead of mips ecoff for local symbols.
1950 (It is the second symbol because the first symbol is
1951 the stFile used to signal the start of a file). */
1953 && strcmp((char *)(((SYMR
*)fh
->isymBase
)[1].iss
),
1954 stabs_symbol
) == 0) {
1955 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++) {
1958 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
1959 type_code
= MIPS_UNMARK_STAB(sh
->index
);
1960 if (!MIPS_IS_STAB(sh
)) {
1961 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
) {
1962 long procaddr
= sh
->value
;
1963 sh
= AUX_GET_ISYM (fh
->fBigendian
,
1964 sh
->index
+ (union aux_ext
*)(fh
->iauxBase
))
1965 + (SYMR
*) fh
->isymBase
- 1;
1966 if (sh
->st
== stEnd
) {
1967 long high
= procaddr
+ sh
->value
;
1968 if (high
> pst
->texthigh
)
1969 pst
->texthigh
= high
;
1974 #define SET_NAMESTRING() namestring = (char*)sh->iss
1975 #define CUR_SYMBOL_TYPE type_code
1976 #define CUR_SYMBOL_VALUE sh->value
1977 #define START_PSYMTAB(ofile,addr,fname,low,symoff,global_syms,static_syms)\
1979 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
1980 #define addr 0 /* FIXME, should be offset of addresses */
1981 #define HANDLE_RBRAC(val) \
1982 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
1983 #include "partial-stab.h"
1988 register struct partial_symbol
*psym
;
1989 for (cur_sdx
= 0; cur_sdx
< fh
->csym
; ) {
1992 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
1994 if (MIPS_IS_STAB(sh
)) {
1999 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
2000 sh
->index
== 0xfffff) {
2001 /* FIXME, premature? */
2006 name
= (char *)(sh
->iss
);
2011 case stProc
: /* Asm labels apparently */
2012 case stStaticProc
: /* Function */
2013 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
2014 VAR_NAMESPACE
, LOC_BLOCK
,
2015 objfile
->static_psymbols
, sh
->value
);
2016 /* Skip over procedure to next one. */
2017 cur_sdx
= AUX_GET_ISYM (fh
->fBigendian
,
2018 sh
->index
+ (union aux_ext
*)fh
->iauxBase
);
2019 procaddr
= sh
->value
;
2021 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
- 1;
2022 if (sh
->st
!= stEnd
)
2024 high
= procaddr
+ sh
->value
;
2025 if (high
> pst
->texthigh
)
2026 pst
->texthigh
= high
;
2028 case stStatic
: /* Variable */
2031 case stTypedef
: /* Typedef */
2032 class = LOC_TYPEDEF
;
2034 case stConstant
: /* Constant decl */
2037 case stBlock
: /* { }, str, un, enum*/
2038 if (sh
->sc
== scInfo
) {
2039 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
2040 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2041 objfile
->static_psymbols
, sh
->value
);
2043 /* Skip over the block */
2044 cur_sdx
= sh
->index
;
2046 case stFile
: /* File headers */
2047 case stLabel
: /* Labels */
2048 case stEnd
: /* Ends of files */
2051 /* Both complaints are valid: one gives symbol name,
2052 the other the offending symbol type. */
2053 complain (&unknown_sym_complaint
, (char *)sh
->iss
);
2054 complain (&unknown_st_complaint
, sh
->st
);
2058 /* Use this gdb symbol */
2059 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
2060 VAR_NAMESPACE
, class,
2061 objfile
->static_psymbols
, sh
->value
);
2063 cur_sdx
++; /* Go to next file symbol */
2066 /* Now do enter the external symbols. */
2067 ext_ptr
= &extern_tab
[fdr_to_pst
[f_idx
].globals_offset
];
2068 cur_sdx
= fdr_to_pst
[f_idx
].n_globals
;
2069 PST_PRIVATE(save_pst
)->extern_count
= cur_sdx
;
2070 PST_PRIVATE(save_pst
)->extern_tab
= ext_ptr
;
2071 for (; --cur_sdx
>= 0; ext_ptr
++) {
2072 enum address_class
class;
2073 if ((*ext_ptr
)->ifd
!= f_idx
)
2075 sh
= &(*ext_ptr
)->asym
;
2084 complain (&unknown_ext_complaint
, sh
->iss
);
2089 if (objfile
->global_psymbols
.next
>=
2090 objfile
->global_psymbols
.list
+ objfile
->global_psymbols
.size
)
2091 extend_psymbol_list (&objfile
->global_psymbols
, objfile
);
2092 psym
= objfile
->global_psymbols
.next
++;
2093 SYMBOL_NAME (psym
) = (char*)sh
->iss
;
2094 SYMBOL_NAMESPACE (psym
) = VAR_NAMESPACE
;
2095 SYMBOL_CLASS (psym
) = class;
2096 SYMBOL_VALUE_ADDRESS (psym
) = (CORE_ADDR
)sh
->value
;
2100 end_psymtab (save_pst
, psymtab_include_list
, includes_used
,
2101 -1, save_pst
->texthigh
,
2102 dependency_list
, dependencies_used
);
2103 if (entry_point
< save_pst
->texthigh
2104 && entry_point
>= save_pst
->textlow
) {
2105 startup_file_start
= save_pst
->textlow
;
2106 startup_file_end
= save_pst
->texthigh
;
2110 /* Mark the last code address, and remember it for later */
2111 hdr
->cbDnOffset
= end_of_text_seg
;
2113 /* Now scan the FDRs for dependencies */
2114 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
2116 fh
= f_idx
+ (FDR
*)(cur_hdr
->cbFdOffset
);
2117 pst
= fdr_to_pst
[f_idx
].pst
;
2119 /* This should catch stabs-in-ecoff. */
2123 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
2124 /* ...then presumably a .h file: drop reverse depends .h->.c */
2125 for (; s_id0
< fh
->crfd
; s_id0
++) {
2126 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
2128 s_id0
++; /* Skip self-dependency */
2133 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2134 pst
->dependencies
= (struct partial_symtab
**)
2135 obstack_alloc (&objfile
->psymbol_obstack
,
2136 pst
->number_of_dependencies
*
2137 sizeof (struct partial_symtab
*));
2138 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
2139 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
2140 if (*rh
< 0 || *rh
>= hdr
->ifdMax
)
2141 complain(&bad_file_number_complaint
, *rh
);
2143 pst
->dependencies
[s_idx
-s_id0
] = fdr_to_pst
[*rh
].pst
;
2146 do_cleanups (old_chain
);
2151 /* Do the initial analisys of the F_IDX-th file descriptor.
2152 Allocates a partial symtab for it, and builds the list
2153 of dependent files by recursion. LEV says at which level
2154 of recursion we are called (to pretty up debug traces) */
2156 static struct partial_symtab
*
2157 parse_fdr(f_idx
, lev
, objfile
)
2160 struct objfile
*objfile
;
2163 register struct partial_symtab
*pst
;
2166 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + f_idx
;
2168 /* Use this to indicate into which symtab this file was parsed */
2170 return (struct partial_symtab
*) fh
->ioptBase
;
2172 /* Debuggability level */
2173 if (compare_glevel(max_glevel
, fh
->glevel
) < 0)
2174 max_glevel
= fh
->glevel
;
2176 /* Make a new partial_symtab */
2177 pst
= new_psymtab(fh
->rss
, objfile
);
2182 pst
->textlow
= fh
->adr
;
2183 pst
->texthigh
= fh
->cpd
; /* To be fixed later */
2186 /* Make everything point to everything. */
2187 FDR_IDX(pst
) = f_idx
;
2188 fdr_to_pst
[f_idx
].pst
= pst
;
2189 fh
->ioptBase
= (int)pst
;
2191 /* Analyze its dependencies */
2196 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
2197 /* ...then presumably a .h file: drop reverse depends .h->.c */
2198 for (; s_id0
< fh
->crfd
; s_id0
++) {
2199 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
2201 s_id0
++; /* Skip self-dependency */
2206 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2207 pst
->dependencies
= (struct partial_symtab
**)
2208 obstack_alloc (&objfile
->psymbol_obstack
,
2209 pst
->number_of_dependencies
*
2210 sizeof (struct partial_symtab
*));
2211 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
2212 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
2214 pst
->dependencies
[s_idx
-s_id0
] = parse_fdr(*rh
, lev
+1, objfile
);
2222 mips_next_symbol_text ()
2225 return (char*)((SYMR
*)cur_fdr
->isymBase
)[cur_sdx
].iss
;
2228 /* Ancillary function to psymtab_to_symtab(). Does all the work
2229 for turning the partial symtab PST into a symtab, recurring
2230 first on all dependent psymtabs. The argument FILENAME is
2231 only passed so we can see in debug stack traces what file
2235 psymtab_to_symtab_1(pst
, filename
)
2236 struct partial_symtab
*pst
;
2244 struct linetable
*lines
;
2250 /* How many symbols will we need */
2251 /* FIXME, this does not count enum values. */
2252 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
2253 if (FDR_IDX(pst
) == -1) {
2257 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + FDR_IDX(pst
);
2258 f_max
+= fh
->csym
+ fh
->cpd
;
2259 maxlines
= 2 * fh
->cline
;
2262 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2265 && strcmp((char *)(((SYMR
*)fh
->isymBase
)[1].iss
), stabs_symbol
)
2270 st
= new_symtab (pst
->filename
, 2 * f_max
, maxlines
,
2273 st
= new_symtab ("unknown", f_max
, 0, pst
->objfile
);
2274 lines
= LINETABLE(st
);
2275 pending_list
= (struct mips_pending
**) cur_hdr
->cbOptOffset
;
2276 if (pending_list
== 0) {
2277 pending_list
= (struct mips_pending
**)
2278 xzalloc(cur_hdr
->ifdMax
* sizeof(struct mips_pending
*));
2279 cur_hdr
->cbOptOffset
= (int)pending_list
;
2283 /* Read in all partial symbtabs on which this one is dependent.
2284 NOTE that we do have circular dependencies, sigh. We solved
2285 that by setting pst->readin before this point. */
2287 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2288 if (!pst
->dependencies
[i
]->readin
) {
2289 /* Inform about additional files to be read in. */
2292 fputs_filtered (" ", stdout
);
2294 fputs_filtered ("and ", stdout
);
2296 printf_filtered ("%s...",
2297 pst
->dependencies
[i
]->filename
);
2298 wrap_here (""); /* Flush output */
2301 /* We only pass the filename for debug purposes */
2302 psymtab_to_symtab_1(pst
->dependencies
[i
],
2303 pst
->dependencies
[i
]->filename
);
2307 /* Now read the symbols for this symtab */
2309 current_objfile
= pst
-> objfile
;
2311 cur_fd
= FDR_IDX(pst
);
2314 /* Get a new lexical context */
2317 top_stack
->cur_st
= cur_stab
;
2318 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab
),
2320 BLOCK_START(top_stack
->cur_block
) = fh
? fh
->adr
: 0;
2321 BLOCK_END(top_stack
->cur_block
) = 0;
2322 top_stack
->blocktype
= stFile
;
2323 top_stack
->maxsyms
= 2*f_max
;
2324 top_stack
->cur_type
= 0;
2325 top_stack
->procadr
= 0;
2326 top_stack
->numargs
= 0;
2329 /* Parse locals and procedures */
2334 char *fh_name
= (char*)fh
->rss
;
2336 /* Parse local symbols first */
2342 current_objfile
= NULL
;
2345 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++) {
2346 register SYMR
*sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
2347 char *name
= (char*)sh
->iss
;
2348 CORE_ADDR valu
= sh
->value
;
2349 if (MIPS_IS_STAB(sh
)) {
2350 int type_code
= MIPS_UNMARK_STAB(sh
->index
);
2351 process_one_symbol (type_code
, 0, valu
, name
, /*FIXME*/ 0);
2353 else if (sh
->st
== stLabel
&& sh
->index
!= indexNil
) {
2354 /* Handle encoded stab line number. */
2355 record_line (current_subfile
, sh
->index
, valu
);
2358 st
= end_symtab (pst
->texthigh
, 0, 0, pst
->objfile
);
2361 /* BOUND is the highest core address of this file's procedures */
2362 int bound
= cur_fd
== cur_hdr
->ifdMax
- 1 ? cur_hdr
->cbDnOffset
2364 for (cur_sdx
= 0; cur_sdx
< fh
->csym
; ) {
2365 sh
= (SYMR
*) (fh
->isymBase
) + cur_sdx
;
2366 cur_sdx
+= parse_symbol(sh
, fh
->iauxBase
, fh
->fBigendian
);
2369 /* Procedures next, note we need to look-ahead to
2370 find out where the procedure's code ends */
2373 for (i
= 0; i
< fh
->cpd
-1; i
++) {
2374 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2375 parse_procedure(pr
, pr
[1].adr
); /* next proc up */
2378 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2379 parse_procedure(pr
, bound
); /* next file up */
2381 /* Linenumbers. At the end, check if we can save memory */
2382 parse_lines(fh
, lines
);
2383 if (lines
->nitems
< fh
->cline
)
2384 lines
= shrink_linetable(lines
);
2390 LINETABLE(st
) = lines
;
2392 /* .. and our share of externals.
2393 XXX use the global list to speed up things here. how ?
2394 FIXME, Maybe quit once we have found the right number of ext's? */
2395 /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
2396 top_stack
->blocktype
= stFile
;
2397 top_stack
->maxsyms
=
2398 cur_hdr
->isymMax
+ cur_hdr
->ipdMax
+ cur_hdr
->iextMax
;
2400 ext_ptr
= PST_PRIVATE(pst
)->extern_tab
;
2401 for (i
= PST_PRIVATE(pst
)->extern_count
; --i
>= 0; ext_ptr
++)
2402 parse_external(*ext_ptr
, 1, fh
->fBigendian
);
2404 /* If there are undefined, tell the user */
2405 if (n_undef_symbols
) {
2406 printf_filtered("File %s contains %d unresolved references:",
2407 st
->filename
, n_undef_symbols
);
2408 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2409 n_undef_vars
, n_undef_procs
, n_undef_labels
);
2410 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
2416 /* Sort the symbol table now, we are done adding symbols to it.*/
2417 sort_symtab_syms(st
);
2421 /* Now link the psymtab and the symtab. */
2424 current_objfile
= NULL
;
2427 /* Ancillary parsing procedures. */
2429 /* Lookup the type at relative index RN. Return it in TPP
2430 if found and in any event come up with its name PNAME.
2431 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
2432 Return value says how many aux symbols we ate. */
2435 cross_ref(ax
, tpp
, type_code
, pname
, bigend
)
2438 int type_code
; /* Use to alloc new type if none is found. */
2446 ecoff_swap_rndx_in (bigend
, ax
, rn
);
2448 /* Escape index means 'the next one' */
2449 if (rn
->rfd
== 0xfff) {
2451 rf
= AUX_GET_ISYM (bigend
, ax
+ 1);
2458 *pname
= "<undefined>";
2461 * Find the relative file descriptor and the symbol in it
2463 FDR
*fh
= get_rfd(cur_fd
, rf
);
2468 * If we have processed this symbol then we left a forwarding
2469 * pointer to the corresponding GDB symbol. If not, we`ll put
2470 * it in a list of pending symbols, to be processed later when
2471 * the file f will be. In any event, we collect the name for
2472 * the type here. Which is why we made a first pass at
2475 sh
= (SYMR
*) (fh
->isymBase
) + rn
->index
;
2477 /* Careful, we might be looking at .o files */
2478 *pname
= (UNSAFE_DATA_ADDR(sh
->iss
)) ? "<undefined>" :
2481 /* Have we parsed it ? */
2482 if ((!UNSAFE_DATA_ADDR(sh
->value
)) && (sh
->st
== stParsed
)) {
2483 t
= (struct type
*) sh
->value
;
2486 /* Avoid duplicates */
2487 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
2491 *tpp
= init_type(type_code
, 0, 0, 0, (struct objfile
*) NULL
);
2492 add_pending(fh
, sh
, *tpp
);
2497 /* We used one auxent normally, two if we got a "next one" rf. */
2502 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2503 keeping the symtab sorted */
2505 static struct symbol
*
2506 mylookup_symbol (name
, block
, namespace, class)
2508 register struct block
*block
;
2509 enum namespace namespace;
2510 enum address_class
class;
2512 register int bot
, top
, inc
;
2513 register struct symbol
*sym
;
2516 top
= BLOCK_NSYMS(block
);
2519 sym
= BLOCK_SYM(block
, bot
);
2520 if (SYMBOL_NAME(sym
)[0] == inc
2521 && SYMBOL_NAMESPACE(sym
) == namespace
2522 && SYMBOL_CLASS(sym
) == class
2523 && !strcmp(SYMBOL_NAME(sym
), name
))
2527 if (block
= BLOCK_SUPERBLOCK (block
))
2528 return mylookup_symbol (name
, block
, namespace, class);
2533 /* Add a new symbol S to a block B.
2534 Infrequently, we will need to reallocate the block to make it bigger.
2535 We only detect this case when adding to top_stack->cur_block, since
2536 that's the only time we know how big the block is. FIXME. */
2543 int nsyms
= BLOCK_NSYMS(b
)++;
2544 struct block
*origb
;
2545 struct parse_stack
*stackp
;
2547 if (b
== top_stack
->cur_block
&&
2548 nsyms
>= top_stack
->maxsyms
) {
2549 complain (&block_overflow_complaint
, s
->name
);
2550 /* In this case shrink_block is actually grow_block, since
2551 BLOCK_NSYMS(b) is larger than its current size. */
2553 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
2555 /* Now run through the stack replacing pointers to the
2556 original block. shrink_block has already done this
2557 for the blockvector and BLOCK_FUNCTION. */
2558 for (stackp
= top_stack
; stackp
; stackp
= stackp
->next
) {
2559 if (stackp
->cur_block
== origb
) {
2560 stackp
->cur_block
= b
;
2561 stackp
->maxsyms
= BLOCK_NSYMS (b
);
2565 BLOCK_SYM(b
,nsyms
) = s
;
2568 /* Add a new block B to a symtab S */
2575 struct blockvector
*bv
= BLOCKVECTOR(s
);
2577 bv
= (struct blockvector
*)xrealloc((char *) bv
,
2578 sizeof(struct blockvector
) +
2579 BLOCKVECTOR_NBLOCKS(bv
)
2580 * sizeof(bv
->block
));
2581 if (bv
!= BLOCKVECTOR(s
))
2582 BLOCKVECTOR(s
) = bv
;
2584 BLOCKVECTOR_BLOCK(bv
, BLOCKVECTOR_NBLOCKS(bv
)++) = b
;
2587 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2588 MIPS' linenumber encoding might need more than one byte
2589 to describe it, LAST is used to detect these continuation lines */
2592 add_line(lt
, lineno
, adr
, last
)
2593 struct linetable
*lt
;
2599 last
= -2; /* make sure we record first line */
2601 if (last
== lineno
) /* skip continuation lines */
2604 lt
->item
[lt
->nitems
].line
= lineno
;
2605 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
2611 /* Comparison functions, used when sorting things */
2613 /* Symtabs must be ordered viz the code segments they cover */
2616 compare_symtabs( s1
, s2
)
2617 struct symtab
**s1
, **s2
;
2619 /* "most specific" first */
2621 register struct block
*b1
, *b2
;
2622 b1
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1
),GLOBAL_BLOCK
);
2623 b2
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2
),GLOBAL_BLOCK
);
2624 if (BLOCK_END(b1
) == BLOCK_END(b2
))
2625 return BLOCK_START(b1
) - BLOCK_START(b2
);
2626 return BLOCK_END(b1
) - BLOCK_END(b2
);
2630 /* Partial Symtabs, same */
2633 compare_psymtabs( s1
, s2
)
2634 struct partial_symtab
**s1
, **s2
;
2636 /* Perf twist: put the ones with no code at the end */
2638 register int a
= (*s1
)->textlow
;
2639 register int b
= (*s2
)->textlow
;
2648 /* Blocks with a smaller low bound should come first */
2650 static int compare_blocks(b1
,b2
)
2651 struct block
**b1
, **b2
;
2653 register int addr_diff
;
2655 addr_diff
= (BLOCK_START((*b1
))) - (BLOCK_START((*b2
)));
2657 return (BLOCK_END((*b1
))) - (BLOCK_END((*b2
)));
2662 /* Sorting and reordering procedures */
2664 /* Sort the blocks of a symtab S.
2665 Reorder the blocks in the blockvector by code-address,
2666 as required by some MI search routines */
2672 struct blockvector
*bv
= BLOCKVECTOR(s
);
2674 if (BLOCKVECTOR_NBLOCKS(bv
) <= 2) {
2676 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) == 0)
2677 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = 0;
2678 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) == 0)
2679 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) = 0;
2683 * This is very unfortunate: normally all functions are compiled in
2684 * the order they are found, but if the file is compiled -O3 things
2685 * are very different. It would be nice to find a reliable test
2686 * to detect -O3 images in advance.
2688 if (BLOCKVECTOR_NBLOCKS(bv
) > 3)
2689 qsort(&BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
),
2690 BLOCKVECTOR_NBLOCKS(bv
) - FIRST_LOCAL_BLOCK
,
2691 sizeof(struct block
*),
2695 register CORE_ADDR high
= 0;
2696 register int i
, j
= BLOCKVECTOR_NBLOCKS(bv
);
2698 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
2699 if (high
< BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
)))
2700 high
= BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
));
2701 BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = high
;
2704 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) =
2705 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
));
2707 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2708 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2709 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2710 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2714 /* Constructor/restructor/destructor procedures */
2716 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2717 MAXSYMS and linenumbers MAXLINES we'll put in it */
2721 new_symtab(name
, maxsyms
, maxlines
, objfile
)
2725 struct objfile
*objfile
;
2727 struct symtab
*s
= allocate_symtab (name
, objfile
);
2729 LINETABLE(s
) = new_linetable(maxlines
);
2731 /* All symtabs must have at least two blocks */
2732 BLOCKVECTOR(s
) = new_bvect(2);
2733 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
) = new_block(maxsyms
);
2734 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), STATIC_BLOCK
) = new_block(maxsyms
);
2735 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
),STATIC_BLOCK
)) =
2736 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
);
2738 s
->free_code
= free_linetable
;
2743 /* Allocate a new partial_symtab NAME */
2745 static struct partial_symtab
*
2746 new_psymtab(name
, objfile
)
2748 struct objfile
*objfile
;
2750 struct partial_symtab
*psymtab
;
2752 /* FIXME -- why (char *) -1 rather than NULL? */
2753 psymtab
= allocate_psymtab (name
== (char *) -1 ? "<no name>" : name
,
2756 /* Keep a backpointer to the file's symbols */
2758 psymtab
-> read_symtab_private
= (char *)
2759 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
2760 CUR_HDR(psymtab
) = cur_hdr
;
2762 /* The way to turn this into a symtab is to call... */
2763 psymtab
->read_symtab
= mipscoff_psymtab_to_symtab
;
2768 /* Allocate a linetable array of the given SIZE */
2770 static struct linetable
*
2773 struct linetable
*l
;
2775 size
= size
* sizeof(l
->item
) + sizeof(struct linetable
);
2776 l
= (struct linetable
*)xmalloc(size
);
2781 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2782 I am not so sure about the 3.4 ones */
2784 static struct linetable
*
2785 shrink_linetable(lt
)
2786 struct linetable
* lt
;
2788 struct linetable
*l
= new_linetable(lt
->nitems
);
2790 memcpy(l
, lt
, lt
->nitems
* sizeof(l
->item
) + sizeof(struct linetable
));
2795 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2798 struct blockvector
*
2801 struct blockvector
*bv
;
2804 size
= sizeof(struct blockvector
) + nblocks
* sizeof(struct block
*);
2805 bv
= (struct blockvector
*) xzalloc(size
);
2807 BLOCKVECTOR_NBLOCKS(bv
) = nblocks
;
2812 /* Allocate and zero a new block of MAXSYMS symbols */
2818 int size
= sizeof(struct block
) + (maxsyms
-1) * sizeof(struct symbol
*);
2819 struct block
*b
= (struct block
*)xzalloc(size
);
2824 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2825 Shrink_block can also be used by add_symbol to grow a block. */
2827 static struct block
*
2833 struct blockvector
*bv
= BLOCKVECTOR(s
);
2836 /* Just reallocate it and fix references to the old one */
2838 new = (struct block
*) xrealloc ((char *)b
, sizeof(struct block
) +
2839 (BLOCK_NSYMS(b
)-1) * sizeof(struct symbol
*));
2841 /* Should chase pointers to old one. Fortunately, that`s just
2842 the block`s function and inferior blocks */
2843 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b
)
2844 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2845 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2846 if (BLOCKVECTOR_BLOCK(bv
,i
) == b
)
2847 BLOCKVECTOR_BLOCK(bv
,i
) = new;
2848 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) == b
)
2849 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) = new;
2853 /* Create a new symbol with printname NAME */
2860 struct symbol
*s
= (struct symbol
*)
2861 obstack_alloc (¤t_objfile
->symbol_obstack
, sizeof (struct symbol
));
2863 memset (s
, 0, sizeof (*s
));
2864 SYMBOL_NAME(s
) = name
;
2868 /* Create a new type with printname NAME */
2877 t
= alloc_type (current_objfile
);
2878 TYPE_NAME(t
) = name
;
2879 TYPE_CPLUS_SPECIFIC(t
) = (struct cplus_struct_type
*)
2880 &cplus_struct_default
;
2885 /* Things used for calling functions in the inferior.
2886 These functions are exported to our companion
2887 mips-tdep.c file and are here because they play
2888 with the symbol-table explicitly. */
2890 /* Sigtramp: make sure we have all the necessary information
2891 about the signal trampoline code. Since the official code
2892 from MIPS does not do so, we make up that information ourselves.
2893 If they fix the library (unlikely) this code will neutralize itself. */
2900 struct block
*b
, *b0
;
2902 sigtramp_address
= -1;
2904 /* We know it is sold as sigvec */
2905 s
= lookup_symbol("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
2907 /* Most programs do not play with signals */
2911 b0
= SYMBOL_BLOCK_VALUE(s
);
2913 /* A label of sigvec, to be more precise */
2914 s
= lookup_symbol("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
2916 /* But maybe this program uses its own version of sigvec */
2920 sigtramp_address
= SYMBOL_VALUE(s
);
2921 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
2923 /* Did we or MIPSco fix the library ? */
2924 if (SYMBOL_CLASS(s
) == LOC_BLOCK
)
2927 /* But what symtab does it live in ? */
2928 st
= find_pc_symtab(SYMBOL_VALUE(s
));
2931 * Ok, there goes the fix: turn it into a procedure, with all the
2932 * needed info. Note we make it a nested procedure of sigvec,
2933 * which is the way the (assembly) code is actually written.
2935 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2936 SYMBOL_CLASS(s
) = LOC_BLOCK
;
2937 SYMBOL_TYPE(s
) = init_type(TYPE_CODE_FUNC
, 4, 0, 0, (struct objfile
*) NULL
);
2938 TYPE_TARGET_TYPE(SYMBOL_TYPE(s
)) = builtin_type_void
;
2940 /* Need a block to allocate .gdbinfo. in */
2942 SYMBOL_BLOCK_VALUE(s
) = b
;
2943 BLOCK_START(b
) = sigtramp_address
;
2944 BLOCK_END(b
) = sigtramp_end
;
2945 BLOCK_FUNCTION(b
) = s
;
2946 BLOCK_SUPERBLOCK(b
) = BLOCK_SUPERBLOCK(b0
);
2950 /* Make a .gdbinfo. for it */
2952 struct mips_extra_func_info
*e
=
2953 (struct mips_extra_func_info
*)
2954 xzalloc(sizeof(struct mips_extra_func_info
));
2956 e
->numargs
= 0; /* the kernel thinks otherwise */
2957 /* align_longword(sigcontext + SIGFRAME) */
2958 e
->framesize
= 0x150;
2959 e
->framereg
= SP_REGNUM
;
2962 e
->regoffset
= -(41 * sizeof(int));
2964 e
->fregoffset
= -(37 * sizeof(int));
2967 s
= new_symbol(".gdbinfo.");
2968 SYMBOL_VALUE(s
) = (int) e
;
2969 SYMBOL_NAMESPACE(s
) = LABEL_NAMESPACE
;
2970 SYMBOL_CLASS(s
) = LOC_CONST
;
2971 SYMBOL_TYPE(s
) = builtin_type_void
;
2974 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
2977 /* Initialization */
2979 static struct sym_fns ecoff_sym_fns
=
2981 "ecoff", /* sym_name: name or name prefix of BFD target type */
2982 5, /* sym_namelen: number of significant sym_name chars */
2983 mipscoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
2984 mipscoff_symfile_init
,/* sym_init: read initial info, setup for sym_read() */
2985 mipscoff_symfile_read
,/* sym_read: read a symbol file into symtab */
2986 mipscoff_symfile_finish
,/* sym_finish: finished with file, cleanup */
2987 NULL
/* next: pointer to next struct sym_fns */
2991 _initialize_mipsread ()
2993 add_symtab_fns (&ecoff_sym_fns
);
2995 /* Missing basic types */
2996 builtin_type_string
=
2997 init_type (TYPE_CODE_PASCAL_ARRAY
,
2999 (struct objfile
*) NULL
);
3000 builtin_type_complex
=
3001 init_type(TYPE_CODE_FLT
,
3002 2 * sizeof(float), 0, "complex",
3003 (struct objfile
*) NULL
);
3004 builtin_type_double_complex
=
3005 init_type(TYPE_CODE_FLT
,
3006 2 * sizeof(double), 0, "double_complex",
3007 (struct objfile
*) NULL
);
3008 builtin_type_fixed_dec
=
3009 init_type(TYPE_CODE_INT
, sizeof(int),
3011 (struct objfile
*) NULL
);
3012 builtin_type_float_dec
=
3013 init_type(TYPE_CODE_FLT
, sizeof(double),
3014 0, "floating_decimal",
3015 (struct objfile
*) NULL
);