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
60 #include <sys/param.h>
64 #include "coff/mips.h"
65 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
66 #include "aout/aout64.h"
67 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native, now */
68 #include "coff/ecoff-ext.h"
71 struct external_filehdr f
;
72 struct external_aouthdr a
;
75 /* These must match the corresponding definition in gcc/config/xm-mips.h.
76 At some point, these should probably go into a shared include file,
77 but currently gcc and gdb do not share any directories. */
79 #define CODE_MASK 0x8F300
80 #define MIPS_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK)
81 #define MIPS_MARK_STAB(code) ((code)+CODE_MASK)
82 #define MIPS_UNMARK_STAB(code) ((code)-CODE_MASK)
83 #define STABS_SYMBOL "@stabs"
85 /* Each partial symbol table entry contains a pointer to private data for the
86 read_symtab() function to use when expanding a partial symbol table entry
87 to a full symbol table entry.
89 For mipsread this structure contains the index of the FDR that this psymtab
90 represents and a pointer to the symbol table header HDRR from the symbol
91 file that the psymtab was created from. */
93 #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
94 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
95 #define CUR_HDR(p) (PST_PRIVATE(p)->cur_hdr)
100 EXTR
**extern_tab
; /* Pointer to external symbols for this file. */
101 int extern_count
; /* Size of extern_tab. */
104 /* Things we import explicitly from other modules */
106 extern int info_verbose
;
107 extern struct block
*block_for_pc();
108 extern void sort_symtab_syms();
110 /* Various complaints about symbol reading that don't abort the process */
112 struct complaint bad_file_number_complaint
=
113 {"bad file number %d", 0, 0};
115 struct complaint unknown_ext_complaint
=
116 {"unknown external symbol %s", 0, 0};
118 struct complaint unknown_sym_complaint
=
119 {"unknown local symbol %s", 0, 0};
121 struct complaint unknown_st_complaint
=
122 {"with type %d", 0, 0};
124 struct complaint block_overflow_complaint
=
125 {"block containing %s overfilled", 0, 0};
127 struct complaint basic_type_complaint
=
128 {"cannot map MIPS basic type 0x%x", 0, 0};
130 struct complaint unknown_type_qual_complaint
=
131 {"unknown type qualifier 0x%x", 0, 0};
133 struct complaint array_bitsize_complaint
=
134 {"size of array target type not known, assuming %d bits", 0, 0};
136 struct complaint bad_tag_guess_complaint
=
137 {"guessed tag type incorrectly", 0, 0};
139 /* Macros and extra defs */
141 /* Already-parsed symbols are marked specially */
143 #define stParsed stType
145 /* Puns: hard to find whether -g was used and how */
147 #define MIN_GLEVEL GLEVEL_0
148 #define compare_glevel(a,b) \
149 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
150 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
152 /* When looking at .o files, avoid tripping over bad addresses */
154 #define SAFE_TEXT_ADDR 0x400000
155 #define SAFE_DATA_ADDR 0x10000000
157 #define UNSAFE_DATA_ADDR(p) ((unsigned)p < SAFE_DATA_ADDR || (unsigned)p > 2*SAFE_DATA_ADDR)
159 /* Things that really are local to this module */
161 /* GDB symtable for the current compilation unit */
163 static struct symtab
*cur_stab
;
165 /* MIPS symtab header for the current file */
167 static HDRR
*cur_hdr
;
169 /* Pointer to current file decriptor record, and its index */
174 /* Index of current symbol */
178 /* Note how much "debuggable" this image is. We would like
179 to see at least one FDR with full symbols */
184 /* When examining .o files, report on undefined symbols */
186 static int n_undef_symbols
, n_undef_labels
, n_undef_vars
, n_undef_procs
;
188 /* Pseudo symbol to use when putting stabs into the symbol table. */
190 static char stabs_symbol
[] = STABS_SYMBOL
;
192 /* Extra builtin types */
194 struct type
*builtin_type_complex
;
195 struct type
*builtin_type_double_complex
;
196 struct type
*builtin_type_fixed_dec
;
197 struct type
*builtin_type_float_dec
;
198 struct type
*builtin_type_string
;
200 /* Forward declarations */
203 fixup_symtab
PARAMS ((HDRR
*, char *, int, bfd
*));
206 read_mips_symtab
PARAMS ((struct objfile
*, int));
209 read_the_mips_symtab
PARAMS ((bfd
*, int, CORE_ADDR
));
212 upgrade_type
PARAMS ((struct type
**, int, union aux_ent
*, int));
215 parse_partial_symbols
PARAMS ((int, struct objfile
*));
218 cross_ref
PARAMS ((union aux_ext
*, struct type
**, int, char **, int));
221 fixup_sigtramp
PARAMS ((void));
223 static struct symbol
*
224 new_symbol
PARAMS ((char *));
227 new_type
PARAMS ((char *));
229 static struct block
*
230 new_block
PARAMS ((int));
232 static struct symtab
*
233 new_symtab
PARAMS ((char *, int, int, struct objfile
*));
235 static struct linetable
*
236 new_linetable
PARAMS ((int));
238 static struct blockvector
*
239 new_bvect
PARAMS ((int));
242 parse_type
PARAMS ((union aux_ext
*, int *, int));
244 static struct symbol
*
245 mylookup_symbol
PARAMS ((char *, struct block
*, enum namespace,
246 enum address_class
));
248 static struct block
*
249 shrink_block
PARAMS ((struct block
*, struct symtab
*));
252 xzalloc
PARAMS ((unsigned int));
255 sort_blocks
PARAMS ((struct symtab
*));
258 compare_blocks
PARAMS ((struct block
**, struct block
**));
260 static struct partial_symtab
*
261 new_psymtab
PARAMS ((char *, struct objfile
*));
264 static struct partial_symtab
*
265 parse_fdr
PARAMS ((int, int, struct objfile
*));
269 psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*, char *));
272 add_block
PARAMS ((struct block
*, struct symtab
*));
275 add_symbol
PARAMS ((struct symbol
*, struct block
*));
278 add_line
PARAMS ((struct linetable
*, int, CORE_ADDR
, int));
280 static struct linetable
*
281 shrink_linetable
PARAMS ((struct linetable
*));
284 mips_next_symbol_text
PARAMS ((void));
286 /* Things we export to other modules */
288 /* Address bounds for the signal trampoline in inferior, if any */
289 /* FIXME: Nothing really seems to use this. Why is it here? */
291 CORE_ADDR sigtramp_address
, sigtramp_end
;
294 mipscoff_new_init (ignore
)
295 struct objfile
*ignore
;
300 mipscoff_symfile_init (objfile
)
301 struct objfile
*objfile
;
303 if (objfile
-> sym_private
!= NULL
)
305 mfree (objfile
-> md
, objfile
-> sym_private
);
307 objfile
-> sym_private
= NULL
;
311 mipscoff_symfile_read (objfile
, addr
, mainline
)
312 struct objfile
*objfile
;
316 bfd
*abfd
= objfile
-> obfd
;
319 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
320 desc
= fileno ((FILE *)(abfd
->iostream
)); /* Raw file descriptor */
323 init_minimal_symbol_collection ();
324 make_cleanup (discard_minimal_symbols
, 0);
326 /* Now that the executable file is positioned at symbol table,
327 process it and define symbols accordingly. */
329 read_mips_symtab(objfile
, desc
);
331 /* Install any minimal symbols that have been collected as the current
332 minimal symbols for this objfile. */
334 install_minimal_symbols (objfile
);
337 /* Perform any local cleanups required when we are done with a particular
338 objfile. I.E, we are in the process of discarding all symbol information
339 for an objfile, freeing up all memory held for it, and unlinking the
340 objfile struct from the global list of known objfiles. */
343 mipscoff_symfile_finish (objfile
)
344 struct objfile
*objfile
;
346 if (objfile
-> sym_private
!= NULL
)
348 mfree (objfile
-> md
, objfile
-> sym_private
);
351 /* If we have a file symbol header lying around, blow it away. */
360 /* Allocate zeroed memory */
366 PTR p
= xmalloc(size
);
372 /* Exported procedure: Builds a symtab from the PST partial one.
373 Restores the environment in effect when PST was created, delegates
374 most of the work to an ancillary procedure, and sorts
375 and reorders the symtab list at the end */
378 mipscoff_psymtab_to_symtab(pst
)
379 struct partial_symtab
*pst
;
386 printf_filtered("Reading in symbols for %s...", pst
->filename
);
389 /* Restore the header and list of pending typedefs */
390 cur_hdr
= CUR_HDR(pst
);
392 next_symbol_text_func
= mips_next_symbol_text
;
394 psymtab_to_symtab_1(pst
, pst
->filename
);
396 /* Match with global symbols. This only needs to be done once,
397 after all of the symtabs and dependencies have been read in. */
398 scan_file_globals (pst
->objfile
);
401 printf_filtered("done.\n");
404 /* Exported procedure: Is PC in the signal trampoline code */
407 in_sigtramp(pc
, ignore
)
409 char *ignore
; /* function name */
411 if (sigtramp_address
== 0)
413 return (pc
>= sigtramp_address
&& pc
< sigtramp_end
);
416 /* File-level interface functions */
418 /* Read the symtab information from file FSYM into memory. Also,
419 return address just past end of our text segment in *END_OF_TEXT_SEGP. */
422 read_the_mips_symtab(abfd
, fsym
, end_of_text_segp
)
425 CORE_ADDR
*end_of_text_segp
;
427 int stsize
, st_hdrsize
;
429 struct hdr_ext hdr_ext
;
431 /* Header for executable/object file we read symbols from */
432 struct coff_exec filhdr
;
434 /* We need some info from the initial headers */
436 myread(fsym
, (char *)&filhdr
, sizeof filhdr
);
438 if (end_of_text_segp
)
440 bfd_h_get_32 (abfd
, filhdr
.a
.text_start
) +
441 bfd_h_get_32 (abfd
, filhdr
.a
.tsize
);
443 /* Find and read the symbol table header */
444 st_hdrsize
= bfd_h_get_32 (abfd
, filhdr
.f
.f_nsyms
);
445 st_filptr
= bfd_h_get_32 (abfd
, filhdr
.f
.f_symptr
);
449 lseek(fsym
, st_filptr
, L_SET
);
450 if (st_hdrsize
!= sizeof (hdr_ext
)) { /* Profanity check */
451 error ("Wrong header size: %d, not %d", st_hdrsize
,
454 if (read(fsym
, &hdr_ext
, st_hdrsize
) != st_hdrsize
)
456 ecoff_swap_hdr_in (abfd
, &hdr_ext
, &st_hdr
);
458 /* Find out how large the symbol table is */
459 stsize
= (st_hdr
.cbExtOffset
- (st_filptr
+ st_hdrsize
))
460 + st_hdr
.iextMax
* cbEXTR
;
462 /* Allocate space for the symbol table. Read it in. */
463 cur_hdr
= (HDRR
*) xmalloc(stsize
+ st_hdrsize
);
465 memcpy((PTR
)cur_hdr
, (PTR
)&hdr_ext
, st_hdrsize
);
466 if (read(fsym
, (char *) cur_hdr
+ st_hdrsize
, stsize
) != stsize
)
469 /* Fixup file_pointers in it */
470 fixup_symtab(cur_hdr
, (char *) cur_hdr
+ st_hdrsize
,
471 st_filptr
+ st_hdrsize
, abfd
);
475 error("Short read on %s", bfd_get_filename (abfd
));
479 /* Turn all file-relative pointers in the symtab described by HDR
480 into memory pointers, given that the symtab itself is located
481 at DATA in memory and F_PTR in the file.
483 Byte-swap all the data structures, in place, while we are at it --
484 except AUX entries, which we leave in their original byte order.
485 They will be swapped as they are used instead. (FIXME: we ought to
486 do all the data structures that way.) */
489 fixup_symtab (hdr
, data
, f_ptr
, abfd
)
500 struct rfd_ext
*rbase
;
502 /* This function depends on the external and internal forms
503 of the MIPS symbol table taking identical space. Check this
504 assumption at compile-time. */
505 static check_hdr1
[1 + sizeof (struct hdr_ext
) - sizeof (HDRR
)] = {0};
506 static check_hdr2
[1 + sizeof (HDRR
) - sizeof (struct hdr_ext
)] = {0};
507 static check_fdr1
[1 + sizeof (struct fdr_ext
) - sizeof (FDR
)] = {0};
508 static check_fdr2
[1 + sizeof (FDR
) - sizeof (struct fdr_ext
)] = {0};
509 static check_pdr1
[1 + sizeof (struct pdr_ext
) - sizeof (PDR
)] = {0};
510 static check_pdr2
[1 + sizeof (PDR
) - sizeof (struct pdr_ext
)] = {0};
511 static check_sym1
[1 + sizeof (struct sym_ext
) - sizeof (SYMR
)] = {0};
512 static check_sym2
[1 + sizeof (SYMR
) - sizeof (struct sym_ext
)] = {0};
513 static check_ext1
[1 + sizeof (struct ext_ext
) - sizeof (EXTR
)] = {0};
514 static check_ext2
[1 + sizeof (EXTR
) - sizeof (struct ext_ext
)] = {0};
515 static check_rfd1
[1 + sizeof (struct rfd_ext
) - sizeof (RFDT
)] = {0};
516 static check_rfd2
[1 + sizeof (RFDT
) - sizeof (struct rfd_ext
)] = {0};
518 /* Swap in the header record. */
519 ecoff_swap_hdr_in (abfd
, hdr
, hdr
);
522 * These fields are useless (and empty) by now:
523 * hdr->cbDnOffset, hdr->cbOptOffset
524 * We use them for other internal purposes.
527 hdr
->cbOptOffset
= 0;
530 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
544 /* Fix all the RFD's. */
545 rbase
= (struct rfd_ext
*)(hdr
->cbRfdOffset
);
546 for (i
= 0; i
< hdr
->crfd
; i
++) {
547 ecoff_swap_rfd_in (abfd
, rbase
+i
, (pRFDT
) rbase
+i
);
550 /* Fix all string pointers inside the symtab, and
551 the FDR records. Also fix other miscellany. */
553 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
554 register unsigned code_offset
;
556 /* Header itself, and strings */
557 fh
= (FDR
*) (hdr
->cbFdOffset
) + f_idx
;
559 /* Swap in the FDR */
560 ecoff_swap_fdr_in (abfd
, fh
, fh
);
562 fh
->issBase
+= hdr
->cbSsOffset
;
564 fh
->rss
= (long)fh
->rss
+ fh
->issBase
;
567 fh
->isymBase
= (int)((SYMR
*)(hdr
->cbSymOffset
)+fh
->isymBase
);
569 /* FIXME! Probably don't want to do this here! */
570 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
571 sh
= (SYMR
*)fh
->isymBase
+ s_idx
;
572 ecoff_swap_sym_in (abfd
, sh
, sh
);
574 sh
->iss
= (long) sh
->iss
+ fh
->issBase
;
580 /* cannot fix fh->ipdFirst because it is a short */
581 #define IPDFIRST(h,fh) \
582 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
584 /* Optional symbols (actually used for partial_symtabs) */
590 fh
->iauxBase
= hdr
->cbAuxOffset
+ fh
->iauxBase
* sizeof(union aux_ext
);
591 /* Relative file descriptor table */
592 fh
->rfdBase
= hdr
->cbRfdOffset
+ fh
->rfdBase
* sizeof(RFDT
);
596 fh
->cbLineOffset
+= hdr
->cbLineOffset
;
598 /* Procedure symbols. (XXX This should be done later) */
599 code_offset
= fh
->adr
;
600 for (s_idx
= 0; s_idx
< fh
->cpd
; s_idx
++) {
601 unsigned name
, only_ext
;
603 pr
= (PDR
*)(IPDFIRST(hdr
,fh
)) + s_idx
;
604 ecoff_swap_pdr_in (abfd
, pr
, pr
);
606 /* Simple rule to find files linked "-x" */
607 only_ext
= fh
->rss
== -1;
609 if (pr
->isym
== -1) {
610 /* static function */
614 name
= hdr
->cbExtOffset
+ pr
->isym
* sizeof(EXTR
);
615 sh
= &((EXTR
*)name
)->asym
;
619 sh
= (SYMR
*)fh
->isymBase
+ pr
->isym
;
620 /* Included code ? */
621 if (s_idx
== 0 && pr
->adr
!= 0)
622 code_offset
-= pr
->adr
;
625 /* Turn index into a pointer */
628 /* Fix line numbers */
629 pr
->cbLineOffset
+= fh
->cbLineOffset
;
631 /* Relocate address */
633 pr
->adr
+= code_offset
;
637 /* External symbols: swap in, and fix string */
638 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
639 esh
= (EXTR
*)(hdr
->cbExtOffset
) + s_idx
;
640 ecoff_swap_ext_in (abfd
, esh
, esh
);
641 esh
->asym
.iss
= esh
->asym
.iss
+ hdr
->cbSsExtOffset
;
646 /* Find a file descriptor given its index RF relative to a file CF */
654 f
= (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
655 /* Object files do not have the RFD table, all refs are absolute */
657 return (FDR
*) (cur_hdr
->cbFdOffset
) + rf
;
658 cf
= *((pRFDT
) f
->rfdBase
+ rf
);
659 return (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
662 /* Return a safer print NAME for a file descriptor */
668 if (name
== (char *) -1)
669 return "<stripped file>";
670 if (UNSAFE_DATA_ADDR(name
))
676 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
677 whether we are adding to the general symtab or not.
678 FIXME: INCREMENTAL is currently always zero, though it should not be. */
681 read_mips_symtab (objfile
, desc
)
682 struct objfile
*objfile
;
685 CORE_ADDR end_of_text_seg
;
687 read_the_mips_symtab(objfile
->obfd
, desc
, &end_of_text_seg
);
689 parse_partial_symbols(end_of_text_seg
, objfile
);
693 * Check to make sure file was compiled with -g.
694 * If not, warn the user of this limitation.
696 if (compare_glevel(max_glevel
, GLEVEL_2
) < 0) {
697 if (max_gdbinfo
== 0)
699 "\n%s not compiled with -g, debugging support is limited.\n",
702 "You should compile with -g2 or -g3 for best debugging support.\n");
708 /* Local utilities */
710 /* Map of FDR indexes to partial symtabs */
713 struct partial_symtab
*pst
; /* the psymtab proper */
714 int n_globals
; /* exported globals (external symbols) */
715 int globals_offset
; /* cumulative */
719 /* Utility stack, used to nest procedures and blocks properly.
720 It is a doubly linked list, to avoid too many alloc/free.
721 Since we might need it quite a few times it is NOT deallocated
724 static struct parse_stack
{
725 struct parse_stack
*next
, *prev
;
726 struct symtab
*cur_st
; /* Current symtab. */
727 struct block
*cur_block
; /* Block in it. */
728 int blocktype
; /* What are we parsing. */
729 int maxsyms
; /* Max symbols in this block. */
730 struct type
*cur_type
; /* Type we parse fields for. */
731 int cur_field
; /* Field number in cur_type. */
732 int procadr
; /* Start addres of this procedure */
733 int numargs
; /* Its argument count */
734 } *top_stack
; /* Top stack ptr */
737 /* Enter a new lexical context */
742 struct parse_stack
*new;
744 /* Reuse frames if possible */
745 if (top_stack
&& top_stack
->prev
)
746 new = top_stack
->prev
;
748 new = (struct parse_stack
*) xzalloc(sizeof(struct parse_stack
));
749 /* Initialize new frame with previous content */
751 register struct parse_stack
*prev
= new->prev
;
754 top_stack
->prev
= new;
756 new->next
= top_stack
;
761 /* Exit a lexical context */
769 top_stack
= top_stack
->next
;
773 /* Cross-references might be to things we haven't looked at
774 yet, e.g. type references. To avoid too many type
775 duplications we keep a quick fixup table, an array
776 of lists of references indexed by file descriptor */
778 static struct mips_pending
{
779 struct mips_pending
*next
; /* link */
780 SYMR
*s
; /* the symbol */
781 struct type
*t
; /* its partial type descriptor */
785 /* Check whether we already saw symbol SH in file FH as undefined */
787 static struct mips_pending
*
788 is_pending_symbol(fh
, sh
)
792 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
793 register struct mips_pending
*p
;
795 /* Linear search is ok, list is typically no more than 10 deep */
796 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
802 /* Add a new undef symbol SH of type T */
805 add_pending(fh
, sh
, t
)
810 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
811 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
813 /* Make sure we do not make duplicates */
815 p
= (struct mips_pending
*) xmalloc(sizeof(*p
));
818 p
->next
= pending_list
[f_idx
];
819 pending_list
[f_idx
] = p
;
821 sh
->reserved
= 1; /* for quick check */
824 /* Throw away undef entries when done with file index F_IDX */
825 /* FIXME -- storage leak. This is never called!!! --gnu */
830 register struct mips_pending
*p
, *q
;
832 for (p
= pending_list
[f_idx
]; p
; p
= q
) {
836 pending_list
[f_idx
] = 0;
840 prepend_tag_kind(tag_name
, type_code
)
850 case TYPE_CODE_STRUCT
:
853 case TYPE_CODE_UNION
:
860 result
= (char*)obstack_alloc (¤t_objfile
->symbol_obstack
,
861 strlen(prefix
) + strlen(tag_name
) + 1);
862 sprintf(result
, "%s%s", prefix
, tag_name
);
867 /* Parsing Routines proper. */
869 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
870 For blocks, procedures and types we open a new lexical context.
871 This is basically just a big switch on the symbol's type.
872 Argument AX is the base pointer of aux symbols for this file (fh->iauxBase).
873 BIGEND says whether aux symbols are big-endian or little-endian.
874 Return count of SYMR's handled (normally one). */
877 parse_symbol(sh
, ax
, bigend
)
888 /* When a symbol is cross-referenced from other files/symbols
889 we mark it explicitly */
890 int pend
= (sh
->reserved
== 1);
891 enum address_class
class;
899 case stGlobal
: /* external symbol, goes into global block */
901 b
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
903 s
= new_symbol(sh
->iss
);
904 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
907 case stStatic
: /* static data, goes into current block. */
909 b
= top_stack
->cur_block
;
910 s
= new_symbol(sh
->iss
);
911 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
914 case stLocal
: /* local variable, goes into current block */
915 if (sh
->sc
== scRegister
) {
916 class = LOC_REGISTER
;
918 sh
->value
+= FP0_REGNUM
-32;
921 b
= top_stack
->cur_block
;
922 s
= new_symbol(sh
->iss
);
923 SYMBOL_VALUE(s
) = sh
->value
;
925 data
: /* Common code for symbols describing data */
926 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
927 SYMBOL_CLASS(s
) = class;
930 /* Type could be missing in a number of cases */
931 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
932 sh
->index
== 0xfffff)
933 SYMBOL_TYPE(s
) = builtin_type_int
; /* undefined? */
935 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, 0, bigend
);
936 /* Value of a data symbol is its memory address */
939 case stParam
: /* arg to procedure, goes into current block */
941 top_stack
->numargs
++;
943 name
= (char*)sh
->iss
;
944 /* Special GNU C++ name. */
945 if (name
[0] == CPLUS_MARKER
&& name
[1] == 't' && name
[2] == 0)
947 s
= new_symbol(name
);
949 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
950 if (sh
->sc
== scRegister
) {
951 SYMBOL_CLASS(s
) = LOC_REGPARM
;
953 sh
->value
+= FP0_REGNUM
-32;
955 SYMBOL_CLASS(s
) = LOC_ARG
;
956 SYMBOL_VALUE(s
) = sh
->value
;
957 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, 0, bigend
);
958 add_symbol(s
, top_stack
->cur_block
);
960 /* FIXME: This has not been tested. See dbxread.c */
961 /* Add the type of this parameter to the function/procedure
962 type of this block. */
963 add_param_to_type(&top_stack
->cur_block
->function
->type
,s
);
967 case stLabel
: /* label, goes into current block */
968 s
= new_symbol(sh
->iss
);
969 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
; /* so that it can be used */
970 SYMBOL_CLASS(s
) = LOC_LABEL
; /* but not misused */
971 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
972 SYMBOL_TYPE(s
) = builtin_type_int
;
973 add_symbol(s
, top_stack
->cur_block
);
976 case stProc
: /* Procedure, usually goes into global block */
977 case stStaticProc
: /* Static procedure, goes into current block */
978 s
= new_symbol(sh
->iss
);
979 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
980 SYMBOL_CLASS(s
) = LOC_BLOCK
;
981 /* Type of the return value */
982 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
983 t
= builtin_type_int
;
985 t
= parse_type(ax
+ sh
->index
+ 1, 0, bigend
);
986 b
= top_stack
->cur_block
;
987 if (sh
->st
== stProc
) {
988 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
989 /* The next test should normally be true,
990 but provides a hook for nested functions
991 (which we don't want to make global). */
992 if (b
== BLOCKVECTOR_BLOCK(bv
, STATIC_BLOCK
))
993 b
= BLOCKVECTOR_BLOCK(bv
, GLOBAL_BLOCK
);
997 /* Make a type for the procedure itself */
999 /* FIXME: This has not been tested yet! See dbxread.c */
1000 /* Generate a template for the type of this function. The
1001 types of the arguments will be added as we read the symbol
1003 bcopy(SYMBOL_TYPE(s
),lookup_function_type(t
),sizeof(struct type
));
1005 SYMBOL_TYPE(s
) = lookup_function_type (t
);
1008 /* Create and enter a new lexical context */
1009 b
= new_block(top_stack
->maxsyms
);
1010 SYMBOL_BLOCK_VALUE(s
) = b
;
1011 BLOCK_FUNCTION(b
) = s
;
1012 BLOCK_START(b
) = BLOCK_END(b
) = sh
->value
;
1013 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1014 add_block(b
, top_stack
->cur_st
);
1016 /* Not if we only have partial info */
1017 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
1021 top_stack
->cur_block
= b
;
1022 top_stack
->blocktype
= sh
->st
;
1023 top_stack
->cur_type
= SYMBOL_TYPE(s
);
1024 top_stack
->cur_field
= -1;
1025 top_stack
->procadr
= sh
->value
;
1026 top_stack
->numargs
= 0;
1028 sh
->value
= (long) SYMBOL_TYPE(s
);
1032 #ifndef btVoid /* btVoid was added late. */
1035 /* These new symbol types have been recently added to SGI machines. */
1049 case stBlock
: /* Either a lexical block, or some type */
1051 top_stack
->blocktype
= stBlock
;
1052 if (sh
->sc
== scInfo
) { /* structure/union/enum def */
1054 sh
->st
== stStruct
? TYPE_CODE_STRUCT
1055 : sh
->st
== stUnion
? TYPE_CODE_UNION
1056 : sh
->st
== stEnum
? TYPE_CODE_ENUM
1063 s
= new_symbol(sh
->iss
);
1064 SYMBOL_NAMESPACE(s
) = STRUCT_NAMESPACE
;
1065 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1066 SYMBOL_VALUE(s
) = 0;
1067 add_symbol(s
, top_stack
->cur_block
);
1069 /* First count the number of fields. */
1070 for (tsym
= sh
+1; tsym
->st
!= stEnd
; tsym
++)
1071 if (tsym
->st
== stMember
) {
1072 if (nfields
== 0 && type_code
== TYPE_CODE_UNDEF
)
1073 /* If the type of the member is Nil (or Void)
1074 assume the tag is an enumeration. */
1075 if (tsym
->index
== indexNil
)
1076 type_code
= TYPE_CODE_ENUM
;
1078 ecoff_swap_tir_in (bigend
,
1079 &ax
[tsym
->index
].a_ti
,
1081 if (tir
.bt
== btNil
|| tir
.bt
== btVoid
)
1082 type_code
= TYPE_CODE_ENUM
;
1085 if (tsym
->value
> max_value
)
1086 max_value
= tsym
->value
;
1088 else if (tsym
->st
== stBlock
1089 || tsym
->st
== stUnion
1090 || tsym
->st
== stEnum
1091 || tsym
->st
== stStruct
1092 || tsym
->st
== stParsed
) {
1093 if (tsym
->sc
== scVariant
) ; /*UNIMPLEMENTED*/
1094 if (tsym
->index
!= 0)
1095 tsym
= ((SYMR
*)cur_fdr
->isymBase
)
1099 /* There is no guaranteed way to distinguish struct,
1100 unions, and enums at this point. This is a bug in the
1101 original design (that has been fixed with the
1102 recent addition of the stStruct, stUnion, and stEnum
1103 symbol types.) The way you can tell is if/when you
1104 see a variable or field of that type: In that case
1105 the variable's type (in the AUX table) says if the
1106 type is struct, union, or enum,
1107 and points back to the stBlock here.
1108 So you can patch the tag kind up later - but only
1109 if there actually is a variable or field of that type.
1111 So until we know for sure, we will guess at this point.
1113 If the first member has index==indexNil or a void type,
1114 assume we have an enumeration.
1115 Otherwise, if there is more than one member, and all
1116 the members have offset 0, assume we have a union.
1117 Otherwise, assume we have a struct.
1119 The heuristic could guess wrong in the case of
1120 of an enumeration with no members or a union
1121 with one (or zero) members, or when all except the
1122 last field of a struct have width zero.
1123 These are uncommon and/or illegal situations, and
1124 in any case guessing wrong probably doesn't matter much.
1126 But if we later do find out we were wrong,
1127 we fixup the tag kind. Members of an enumeration
1128 must be handled differently from struct/union fields,
1129 and that is harder to patch up, but luckily we
1130 shouldn't need to. (If there are any enumeration
1131 members, we can tell for sure it's an enum here.) */
1133 if (type_code
== TYPE_CODE_UNDEF
)
1134 if (nfields
> 1 && max_value
== 0)
1135 type_code
= TYPE_CODE_UNION
;
1137 type_code
= TYPE_CODE_STRUCT
;
1139 /* If this type was expected, use its partial definition */
1141 t
= is_pending_symbol(cur_fdr
, sh
)->t
;
1143 t
= new_type(prepend_tag_kind((char *)sh
->iss
,
1146 TYPE_CODE(t
) = type_code
;
1147 TYPE_LENGTH(t
) = sh
->value
;
1148 TYPE_NFIELDS(t
) = nfields
;
1149 TYPE_FIELDS(t
) = f
= (struct field
*)
1150 obstack_alloc (¤t_objfile
-> type_obstack
,
1151 nfields
* sizeof (struct field
));
1153 if (type_code
== TYPE_CODE_ENUM
) {
1154 /* This is a non-empty enum. */
1155 for (tsym
= sh
+ 1; tsym
->st
== stMember
; tsym
++) {
1156 struct symbol
*enum_sym
;
1157 f
->bitpos
= tsym
->value
;
1159 f
->name
= (char*)tsym
->iss
;
1162 enum_sym
= (struct symbol
*)
1163 obstack_alloc (¤t_objfile
->symbol_obstack
,
1164 sizeof (struct symbol
));
1165 memset ((PTR
)enum_sym
, 0, sizeof (struct symbol
));
1166 SYMBOL_NAME (enum_sym
) = f
->name
;
1167 SYMBOL_CLASS (enum_sym
) = LOC_CONST
;
1168 SYMBOL_TYPE (enum_sym
) = t
;
1169 SYMBOL_NAMESPACE (enum_sym
) = VAR_NAMESPACE
;
1170 SYMBOL_VALUE (enum_sym
) = tsym
->value
;
1171 add_symbol(enum_sym
, top_stack
->cur_block
);
1173 /* Skip the stMembers that we've handled. */
1179 /* make this the current type */
1180 top_stack
->cur_type
= t
;
1181 top_stack
->cur_field
= 0;
1182 /* Mark that symbol has a type, and say which one */
1183 sh
->value
= (long) t
;
1185 /* beginnning of (code) block. Value of symbol
1186 is the displacement from procedure start */
1187 b
= new_block(top_stack
->maxsyms
);
1188 BLOCK_START(b
) = sh
->value
+ top_stack
->procadr
;
1189 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1190 top_stack
->cur_block
= b
;
1191 add_block(b
, top_stack
->cur_st
);
1195 case stEnd
: /* end (of anything) */
1196 if (sh
->sc
== scInfo
) {
1197 /* Finished with type */
1198 top_stack
->cur_type
= 0;
1199 } else if (sh
->sc
== scText
&&
1200 (top_stack
->blocktype
== stProc
||
1201 top_stack
->blocktype
== stStaticProc
)) {
1202 /* Finished with procedure */
1203 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
1204 struct mips_extra_func_info
*e
;
1208 BLOCK_END(top_stack
->cur_block
) += sh
->value
; /* size */
1210 /* Make up special symbol to contain procedure specific
1212 s
= new_symbol(".gdbinfo.");
1213 SYMBOL_NAMESPACE(s
) = LABEL_NAMESPACE
;
1214 SYMBOL_CLASS(s
) = LOC_CONST
;
1215 SYMBOL_TYPE(s
) = builtin_type_void
;
1216 e
= (struct mips_extra_func_info
*)
1217 obstack_alloc (¤t_objfile
->symbol_obstack
,
1218 sizeof (struct mips_extra_func_info
));
1219 SYMBOL_VALUE(s
) = (int)e
;
1220 e
->numargs
= top_stack
->numargs
;
1221 add_symbol(s
, top_stack
->cur_block
);
1223 /* Reallocate symbols, saving memory */
1224 b
= shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1226 /* f77 emits proc-level with address bounds==[0,0],
1227 So look for such child blocks, and patch them. */
1228 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++) {
1229 struct block
*b_bad
= BLOCKVECTOR_BLOCK(bv
,i
);
1230 if (BLOCK_SUPERBLOCK(b_bad
) == b
1231 && BLOCK_START(b_bad
) == top_stack
->procadr
1232 && BLOCK_END(b_bad
) == top_stack
->procadr
) {
1233 BLOCK_START(b_bad
) = BLOCK_START(b
);
1234 BLOCK_END(b_bad
) = BLOCK_END(b
);
1237 } else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
) {
1238 /* End of (code) block. The value of the symbol
1239 is the displacement from the procedure`s start
1240 address of the end of this block. */
1241 BLOCK_END(top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1242 (void) shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1244 pop_parse_stack(); /* restore previous lexical context */
1247 case stMember
: /* member of struct or union */
1248 f
= &TYPE_FIELDS(top_stack
->cur_type
)[top_stack
->cur_field
++];
1249 f
->name
= (char*)sh
->iss
;
1250 f
->bitpos
= sh
->value
;
1252 f
->type
= parse_type(ax
+ sh
->index
, &f
->bitsize
, bigend
);
1255 case stTypedef
: /* type definition */
1256 s
= new_symbol(sh
->iss
);
1257 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1258 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1259 SYMBOL_BLOCK_VALUE(s
) = top_stack
->cur_block
;
1260 add_symbol(s
, top_stack
->cur_block
);
1261 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, 0, bigend
);
1262 sh
->value
= (long) SYMBOL_TYPE(s
);
1265 case stFile
: /* file name */
1267 top_stack
->blocktype
= sh
->st
;
1270 /* I`ve never seen these for C */
1272 break; /* register relocation */
1274 break; /* forwarding address */
1276 break; /* constant */
1278 error("Unknown symbol type %x.", sh
->st
);
1284 /* Parse the type information provided in the raw AX entries for
1285 the symbol SH. Return the bitfield size in BS, in case.
1286 We must byte-swap the AX entries before we use them; BIGEND says whether
1287 they are big-endian or little-endian (from fh->fBigendian). */
1289 static struct type
*
1290 parse_type(ax
, bs
, bigend
)
1295 /* Null entries in this map are treated specially */
1296 static struct type
**map_bt
[] =
1298 &builtin_type_void
, /* btNil */
1300 &builtin_type_char
, /* btChar */
1301 &builtin_type_unsigned_char
, /* btUChar */
1302 &builtin_type_short
, /* btShort */
1303 &builtin_type_unsigned_short
, /* btUShort */
1304 &builtin_type_int
, /* btInt */
1305 &builtin_type_unsigned_int
, /* btUInt */
1306 &builtin_type_long
, /* btLong */
1307 &builtin_type_unsigned_long
, /* btULong */
1308 &builtin_type_float
, /* btFloat */
1309 &builtin_type_double
, /* btDouble */
1316 &builtin_type_complex
, /* btComplex */
1317 &builtin_type_double_complex
, /* btDComplex */
1319 &builtin_type_fixed_dec
, /* btFixedDec */
1320 &builtin_type_float_dec
, /* btFloatDec */
1321 &builtin_type_string
, /* btString */
1324 &builtin_type_void
, /* btVoid */
1328 struct type
*tp
= 0;
1333 /* Use aux as a type information record, map its basic type. */
1335 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1336 if (t
->bt
> (sizeof (map_bt
)/sizeof (*map_bt
))) {
1337 complain (&basic_type_complaint
, t
->bt
);
1338 return builtin_type_int
;
1340 if (map_bt
[t
->bt
]) {
1341 tp
= *map_bt
[t
->bt
];
1345 /* Cannot use builtin types -- build our own */
1348 tp
= lookup_pointer_type (builtin_type_void
);
1352 type_code
= TYPE_CODE_STRUCT
;
1356 type_code
= TYPE_CODE_UNION
;
1360 type_code
= TYPE_CODE_ENUM
;
1364 type_code
= TYPE_CODE_RANGE
;
1368 type_code
= TYPE_CODE_SET
;
1373 complain (&basic_type_complaint
, t
->bt
);
1374 return builtin_type_int
;
1378 /* Skip over any further type qualifiers (FIXME). */
1380 /* This is the way it would work if the compiler worked */
1384 ecoff_swap_tir_in (bigend
, ax
, t1
);
1385 } while (t1
->continued
);
1388 /* Move on to next aux */
1392 *bs
= AUX_GET_WIDTH (bigend
, ax
);
1396 /* All these types really point to some (common) MIPS type
1397 definition, and only the type-qualifiers fully identify
1398 them. We'll make the same effort at sharing. */
1399 if (t
->bt
== btIndirect
||
1400 t
->bt
== btStruct
||
1403 t
->bt
== btTypedef
||
1406 char name
[256], *pn
;
1408 /* Try to cross reference this type */
1409 ax
+= cross_ref(ax
, &tp
, type_code
, &pn
, bigend
);
1410 /* reading .o file ? */
1411 if (UNSAFE_DATA_ADDR(tp
))
1412 tp
= init_type(type_code
, 0, 0, 0, (struct objfile
*) NULL
);
1413 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1414 sprintf(name
, fmt
, pn
);
1416 /* Usually, TYPE_CODE(tp) is already type_code. The main
1417 exception is if we guessed wrong re struct/union/enum. */
1418 if (TYPE_CODE(tp
) != type_code
) {
1419 complain (&bad_tag_guess_complaint
, 0);
1420 TYPE_CODE(tp
) = type_code
;
1422 if (TYPE_NAME(tp
) == NULL
|| strcmp(TYPE_NAME(tp
), name
) != 0)
1423 TYPE_NAME(tp
) = obsavestring(name
, strlen(name
),
1424 ¤t_objfile
-> type_obstack
);
1427 /* Deal with range types */
1428 if (t
->bt
== btRange
) {
1429 TYPE_NFIELDS (tp
) = 2;
1431 (struct field
*) obstack_alloc (¤t_objfile
-> type_obstack
,
1432 2 * sizeof (struct field
));
1433 TYPE_FIELD_NAME (tp
, 0) = obsavestring ("Low", strlen ("Low"),
1434 ¤t_objfile
-> type_obstack
);
1435 TYPE_FIELD_BITPOS (tp
, 0) = AUX_GET_DNLOW (bigend
, ax
);
1437 TYPE_FIELD_NAME (tp
, 1) = obsavestring ("High", strlen ("High"),
1438 ¤t_objfile
-> type_obstack
);
1439 TYPE_FIELD_BITPOS (tp
, 1) = AUX_GET_DNHIGH (bigend
, ax
);
1443 /* Parse all the type qualifiers now. If there are more
1444 than 6 the game will continue in the next aux */
1446 #define PARSE_TQ(tq) \
1447 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, bigend);
1449 again
: PARSE_TQ(tq0
);
1459 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1465 /* Make up a complex type from a basic one. Type is passed by
1466 reference in TPP and side-effected as necessary. The type
1467 qualifier TQ says how to handle the aux symbols at AX for
1468 the symbol SX we are currently analyzing. BIGEND says whether
1469 aux symbols are big-endian or little-endian.
1470 Returns the number of aux symbols we parsed. */
1473 upgrade_type(tpp
, tq
, ax
, bigend
)
1482 /* Used in array processing */
1491 t
= lookup_pointer_type (*tpp
);
1496 t
= lookup_function_type (*tpp
);
1502 t
= init_type(TYPE_CODE_ARRAY
, 0, 0, 0, (struct objfile
*) NULL
);
1503 TYPE_TARGET_TYPE(t
) = *tpp
;
1505 /* Determine and record the domain type (type of index) */
1506 ecoff_swap_rndx_in (bigend
, ax
, &rndx
);
1511 rf
= AUX_GET_ISYM (bigend
, ax
);
1514 fh
= get_rfd(cur_fd
, rf
);
1516 /* Fields are kept in an array */
1517 /* FIXME - Memory leak! */
1518 if (TYPE_NFIELDS(t
))
1519 TYPE_FIELDS(t
) = (struct field
*)
1520 xrealloc((PTR
) TYPE_FIELDS(t
),
1521 (TYPE_NFIELDS(t
)+1) * sizeof(struct field
));
1523 TYPE_FIELDS(t
) = (struct field
*)
1524 xzalloc(sizeof(struct field
));
1525 f
= &(TYPE_FIELD(t
,TYPE_NFIELDS(t
)));
1527 memset((PTR
)f
, 0, sizeof(struct field
));
1529 /* XXX */ f
->type
= parse_type(id
+ (union aux_ext
*)fh
->iauxBase
,
1530 &f
->bitsize
, bigend
);
1533 lower
= AUX_GET_DNLOW (bigend
, ax
);
1535 upper
= AUX_GET_DNHIGH (bigend
, ax
);
1537 rf
= AUX_GET_WIDTH (bigend
, ax
); /* bit size of array element */
1539 /* Check whether supplied array element bit size matches
1540 the known size of the element type. If this complaint
1541 ends up not happening, we can remove this code. It's
1542 here because we aren't sure we understand this *&%&$
1544 id
= TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) << 3; /* bitsize */
1546 /* Most likely an undefined type */
1548 TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) = id
>> 3;
1551 complain (&array_bitsize_complaint
, rf
);
1553 TYPE_LENGTH(t
) = (upper
< 0) ? 0 :
1554 (upper
- lower
+ 1) * (rf
>> 3);
1559 /* Volatile -- currently ignored */
1563 complain (&unknown_type_qual_complaint
, tq
);
1569 /* Parse a procedure descriptor record PR. Note that the procedure
1570 is parsed _after_ the local symbols, now we just make up the
1571 extra information we need into a special symbol that we insert
1572 in the procedure's main block. Note also that images that
1573 have been partially stripped (ld -x) have been deprived
1574 of local symbols, and we have to cope with them here.
1575 The procedure's code ends at BOUND */
1578 parse_procedure(pr
, bound
)
1581 struct symbol
*s
, *i
;
1582 SYMR
*sh
= (SYMR
*)pr
->isym
;
1584 struct mips_extra_func_info
*e
;
1588 /* Make up a name for static procedures. Sigh. */
1589 if (sh
== (SYMR
*)-1) {
1590 sprintf(name
,".static_procedure@%x",pr
->adr
);
1591 sh_name
= savestring(name
, strlen(name
));
1595 sh_name
= (char*)sh
->iss
;
1596 s
= mylookup_symbol(sh_name
, top_stack
->cur_block
,
1597 VAR_NAMESPACE
, LOC_BLOCK
);
1600 b
= SYMBOL_BLOCK_VALUE(s
);
1602 s
= new_symbol(sh_name
);
1603 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1604 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1605 /* Donno its type, hope int is ok */
1606 SYMBOL_TYPE(s
) = lookup_function_type (builtin_type_int
);
1607 add_symbol(s
, top_stack
->cur_block
);
1608 /* Wont have symbols for this one */
1610 SYMBOL_BLOCK_VALUE(s
) = b
;
1611 BLOCK_FUNCTION(b
) = s
;
1612 BLOCK_START(b
) = pr
->adr
;
1613 BLOCK_END(b
) = bound
;
1614 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1615 add_block(b
, top_stack
->cur_st
);
1618 i
= mylookup_symbol(".gdbinfo.", b
, LABEL_NAMESPACE
, LOC_CONST
);
1622 e
= (struct mips_extra_func_info
*)SYMBOL_VALUE(i
);
1624 e
->pdr
.isym
= (long)s
;
1628 /* Parse the external symbol ES. Just call parse_symbol() after
1629 making sure we know where the aux are for it. For procedures,
1630 parsing of the PDRs has already provided all the needed
1631 information, we only parse them if SKIP_PROCEDURES is false,
1632 and only if this causes no symbol duplication.
1633 BIGEND says whether aux entries are big-endian or little-endian.
1635 This routine clobbers top_stack->cur_block and ->cur_st. */
1638 parse_external(es
, skip_procedures
, bigend
)
1640 int skip_procedures
;
1645 if (es
->ifd
!= ifdNil
) {
1647 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
) + cur_fd
;
1648 ax
= (union aux_ext
*)cur_fdr
->iauxBase
;
1650 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
);
1653 top_stack
->cur_st
= cur_stab
;
1654 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
1657 /* Reading .o files */
1658 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
) {
1660 switch (es
->asym
.st
) {
1662 case stProc
: what
= "procedure"; n_undef_procs
++; break;
1663 case stGlobal
: what
= "variable"; n_undef_vars
++; break;
1664 case stLabel
: what
= "label"; n_undef_labels
++; break;
1665 default : what
= "symbol"; break;
1669 printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what
,
1670 es
->asym
.iss
, fdr_name((char *)cur_fdr
->rss
));
1674 switch (es
->asym
.st
) {
1676 /* If we have full symbols we do not need more */
1677 if (skip_procedures
)
1679 if (mylookup_symbol (es
->asym
.iss
, top_stack
->cur_block
,
1680 VAR_NAMESPACE
, LOC_BLOCK
))
1686 * Note that the case of a symbol with indexNil
1687 * must be handled anyways by parse_symbol().
1689 parse_symbol(&es
->asym
, ax
, bigend
);
1696 /* Parse the line number info for file descriptor FH into
1697 GDB's linetable LT. MIPS' encoding requires a little bit
1698 of magic to get things out. Note also that MIPS' line
1699 numbers can go back and forth, apparently we can live
1700 with that and do not need to reorder our linetables */
1705 struct linetable
*lt
;
1707 unsigned char *base
= (unsigned char*)fh
->cbLineOffset
;
1709 int delta
, count
, lineno
= 0;
1715 /* Scan by procedure descriptors */
1717 for (pr
= (PDR
*)IPDFIRST(cur_hdr
,fh
); j
< fh
->cpd
; j
++, pr
++) {
1720 /* No code for this one */
1721 if (pr
->iline
== ilineNil
||
1722 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1725 * Aurgh! To know where to stop expanding we
1728 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1729 if (pr
[l
].iline
!= -1)
1731 if (l
== (fh
->cpd
- j
))
1736 * When procedures are moved around the linenumbers
1737 * are attributed to the next procedure up
1739 if (pr
->iline
>= halt
) continue;
1741 base
= (unsigned char*)pr
->cbLineOffset
;
1742 l
= pr
->adr
>> 2; /* in words */
1743 halt
+= (pr
->adr
>> 2) - pr
->iline
;
1744 for (lineno
= pr
->lnLow
; l
< halt
;) {
1745 count
= *base
& 0x0f;
1746 delta
= *base
++ >> 4;
1750 delta
= (base
[0] << 8) | base
[1];
1751 if (delta
>= 0x8000)
1755 lineno
+= delta
;/* first delta is 0 */
1756 k
= add_line(lt
, lineno
, l
, k
);
1763 /* Master parsing procedure for first-pass reading of file symbols
1764 into a partial_symtab.
1766 Parses the symtab described by the global symbolic header CUR_HDR.
1767 END_OF_TEXT_SEG gives the address just after the text segment for
1768 the symtab we are reading. */
1771 parse_partial_symbols(end_of_text_seg
, objfile
)
1772 int end_of_text_seg
;
1773 struct objfile
*objfile
;
1776 /* int stat_idx, h_max;*/
1777 HDRR
*hdr
= cur_hdr
;
1778 /* Running pointers */
1782 struct partial_symtab
*pst
;
1784 int past_first_source_file
= 0;
1786 /* List of current psymtab's include files */
1787 char **psymtab_include_list
;
1788 int includes_allocated
;
1791 struct pst_map
* fdr_to_pst
;
1792 /* Index within current psymtab dependency list */
1793 struct partial_symtab
**dependency_list
;
1794 int dependencies_used
, dependencies_allocated
;
1795 struct cleanup
*old_chain
;
1797 extern_tab
= (EXTR
**)obstack_alloc (&objfile
->psymbol_obstack
,
1798 sizeof(EXTR
*) * hdr
->iextMax
);
1800 includes_allocated
= 30;
1802 psymtab_include_list
= (char **) alloca (includes_allocated
*
1804 next_symbol_text_func
= mips_next_symbol_text
;
1806 dependencies_allocated
= 30;
1807 dependencies_used
= 0;
1809 (struct partial_symtab
**) alloca (dependencies_allocated
*
1810 sizeof (struct partial_symtab
*));
1812 last_source_file
= 0;
1817 * Only parse the Local and External symbols, and the Relative FDR.
1818 * Fixup enough of the loader symtab to be able to use it.
1819 * Allocate space only for the file's portions we need to
1824 max_glevel
= MIN_GLEVEL
;
1826 /* Allocate the map FDR -> PST.
1827 Minor hack: -O3 images might claim some global data belongs
1828 to FDR -1. We`ll go along with that */
1829 fdr_to_pst
= (struct pst_map
*)xzalloc((hdr
->ifdMax
+1) * sizeof *fdr_to_pst
);
1830 old_chain
= make_cleanup (free
, fdr_to_pst
);
1833 struct partial_symtab
* pst
= new_psymtab("", objfile
);
1834 fdr_to_pst
[-1].pst
= pst
;
1838 /* Pass 1 over external syms: Presize and partition the list */
1839 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1840 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1841 fdr_to_pst
[esh
->ifd
].n_globals
++;
1844 /* Pass 1.5 over files: partition out global symbol space */
1846 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++) {
1847 fdr_to_pst
[f_idx
].globals_offset
= s_idx
;
1848 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
1849 fdr_to_pst
[f_idx
].n_globals
= 0;
1852 /* Pass 2 over external syms: fill in external symbols */
1853 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1854 enum minimal_symbol_type ms_type
= mst_text
;
1855 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1857 extern_tab
[fdr_to_pst
[esh
->ifd
].globals_offset
1858 + fdr_to_pst
[esh
->ifd
].n_globals
++] = esh
;
1860 if (esh
->asym
.sc
== scUndefined
|| esh
->asym
.sc
== scNil
)
1863 switch (esh
->asym
.st
) {
1872 ms_type
= mst_unknown
;
1873 complain (&unknown_ext_complaint
,
1874 (char *)(esh
->asym
.iss
));
1876 prim_record_minimal_symbol ((char *)esh
->asym
.iss
,
1881 /* Pass 3 over files, over local syms: fill in static symbols */
1882 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
1883 struct partial_symtab
*save_pst
;
1885 cur_fdr
= fh
= f_idx
+ (FDR
*)(cur_hdr
->cbFdOffset
);
1887 if (fh
->csym
== 0) {
1888 fdr_to_pst
[f_idx
].pst
= NULL
;
1891 pst
= start_psymtab_common (objfile
, 0, (char*)fh
->rss
,
1892 fh
->cpd
? fh
->adr
: 0,
1893 objfile
->global_psymbols
.next
,
1894 objfile
->static_psymbols
.next
);
1895 pst
->read_symtab_private
= (char *)
1896 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
1899 /* Make everything point to everything. */
1900 FDR_IDX(pst
) = f_idx
;
1901 fdr_to_pst
[f_idx
].pst
= pst
;
1902 fh
->ioptBase
= (int)pst
;
1904 CUR_HDR(pst
) = cur_hdr
;
1906 /* The way to turn this into a symtab is to call... */
1907 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
1909 pst
->texthigh
= pst
->textlow
;
1911 #if 0 /* This is done in start_psymtab_common */
1912 pst
->globals_offset
= global_psymbols
.next
- global_psymbols
.list
;
1913 pst
->statics_offset
= static_psymbols
.next
- static_psymbols
.list
;
1915 pst
->n_global_syms
= 0;
1916 pst
->n_static_syms
= 0;
1919 /* The second symbol must be @stab.
1920 This symbol is emitted by mips-tfile to signal
1921 that the current object file uses encapsulated stabs
1922 instead of mips ecoff for local symbols.
1923 (It is the second symbol because the first symbol is
1924 the stFile used to signal the start of a file). */
1926 && strcmp((char *)(((SYMR
*)fh
->isymBase
)[1].iss
),
1927 stabs_symbol
) == 0) {
1928 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++) {
1931 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
1932 type_code
= MIPS_UNMARK_STAB(sh
->index
);
1933 if (!MIPS_IS_STAB(sh
)) {
1934 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
) {
1935 long procaddr
= sh
->value
;
1936 sh
= AUX_GET_ISYM (fh
->fBigendian
,
1937 sh
->index
+ (union aux_ext
*)(fh
->iauxBase
))
1938 + (SYMR
*) fh
->isymBase
- 1;
1939 if (sh
->st
== stEnd
) {
1940 long high
= procaddr
+ sh
->value
;
1941 if (high
> pst
->texthigh
)
1942 pst
->texthigh
= high
;
1947 #define SET_NAMESTRING() namestring = (char*)sh->iss
1948 #define CUR_SYMBOL_TYPE type_code
1949 #define CUR_SYMBOL_VALUE sh->value
1950 #define START_PSYMTAB(ofile,addr,fname,low,symoff,global_syms,static_syms)\
1952 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
1953 #define addr 0 /* FIXME, should be offset of addresses */
1954 #define HANDLE_RBRAC(val) \
1955 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
1956 #include "partial-stab.h"
1961 register struct partial_symbol
*psym
;
1962 for (cur_sdx
= 0; cur_sdx
< fh
->csym
; ) {
1965 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
1967 if (MIPS_IS_STAB(sh
)) {
1972 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
1973 sh
->index
== 0xfffff) {
1974 /* FIXME, premature? */
1979 name
= (char *)(sh
->iss
);
1984 case stProc
: /* Asm labels apparently */
1985 case stStaticProc
: /* Function */
1986 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
1987 VAR_NAMESPACE
, LOC_BLOCK
,
1988 objfile
->static_psymbols
, sh
->value
);
1989 /* Skip over procedure to next one. */
1990 cur_sdx
= AUX_GET_ISYM (fh
->fBigendian
,
1991 sh
->index
+ (union aux_ext
*)fh
->iauxBase
);
1992 procaddr
= sh
->value
;
1994 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
- 1;
1995 if (sh
->st
!= stEnd
)
1997 high
= procaddr
+ sh
->value
;
1998 if (high
> pst
->texthigh
)
1999 pst
->texthigh
= high
;
2001 case stStatic
: /* Variable */
2004 case stTypedef
: /* Typedef */
2005 class = LOC_TYPEDEF
;
2007 case stConstant
: /* Constant decl */
2013 case stBlock
: /* { }, str, un, enum*/
2014 if (sh
->sc
== scInfo
) {
2015 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
2016 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2017 objfile
->static_psymbols
, sh
->value
);
2019 /* Skip over the block */
2020 cur_sdx
= sh
->index
;
2022 case stFile
: /* File headers */
2023 case stLabel
: /* Labels */
2024 case stEnd
: /* Ends of files */
2027 /* Both complaints are valid: one gives symbol name,
2028 the other the offending symbol type. */
2029 complain (&unknown_sym_complaint
, (char *)sh
->iss
);
2030 complain (&unknown_st_complaint
, sh
->st
);
2034 /* Use this gdb symbol */
2035 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
2036 VAR_NAMESPACE
, class,
2037 objfile
->static_psymbols
, sh
->value
);
2039 cur_sdx
++; /* Go to next file symbol */
2042 /* Now do enter the external symbols. */
2043 ext_ptr
= &extern_tab
[fdr_to_pst
[f_idx
].globals_offset
];
2044 cur_sdx
= fdr_to_pst
[f_idx
].n_globals
;
2045 PST_PRIVATE(save_pst
)->extern_count
= cur_sdx
;
2046 PST_PRIVATE(save_pst
)->extern_tab
= ext_ptr
;
2047 for (; --cur_sdx
>= 0; ext_ptr
++) {
2048 enum address_class
class;
2049 if ((*ext_ptr
)->ifd
!= f_idx
)
2051 sh
= &(*ext_ptr
)->asym
;
2060 complain (&unknown_ext_complaint
, sh
->iss
);
2065 if (objfile
->global_psymbols
.next
>=
2066 objfile
->global_psymbols
.list
+ objfile
->global_psymbols
.size
)
2067 extend_psymbol_list (&objfile
->global_psymbols
, objfile
);
2068 psym
= objfile
->global_psymbols
.next
++;
2069 SYMBOL_NAME (psym
) = (char*)sh
->iss
;
2070 SYMBOL_NAMESPACE (psym
) = VAR_NAMESPACE
;
2071 SYMBOL_CLASS (psym
) = class;
2072 SYMBOL_VALUE_ADDRESS (psym
) = (CORE_ADDR
)sh
->value
;
2076 end_psymtab (save_pst
, psymtab_include_list
, includes_used
,
2077 -1, save_pst
->texthigh
,
2078 dependency_list
, dependencies_used
);
2079 if (objfile
-> ei
.entry_point
>= save_pst
->textlow
&&
2080 objfile
-> ei
.entry_point
< save_pst
->texthigh
)
2082 objfile
-> ei
.entry_file_lowpc
= save_pst
->textlow
;
2083 objfile
-> ei
.entry_file_highpc
= save_pst
->texthigh
;
2087 /* Mark the last code address, and remember it for later */
2088 hdr
->cbDnOffset
= end_of_text_seg
;
2090 /* Now scan the FDRs for dependencies */
2091 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
2093 fh
= f_idx
+ (FDR
*)(cur_hdr
->cbFdOffset
);
2094 pst
= fdr_to_pst
[f_idx
].pst
;
2096 /* This should catch stabs-in-ecoff. */
2100 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
2101 /* ...then presumably a .h file: drop reverse depends .h->.c */
2102 for (; s_id0
< fh
->crfd
; s_id0
++) {
2103 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
2105 s_id0
++; /* Skip self-dependency */
2110 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2111 pst
->dependencies
= (struct partial_symtab
**)
2112 obstack_alloc (&objfile
->psymbol_obstack
,
2113 pst
->number_of_dependencies
*
2114 sizeof (struct partial_symtab
*));
2115 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
2116 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
2117 if (*rh
< 0 || *rh
>= hdr
->ifdMax
)
2118 complain(&bad_file_number_complaint
, *rh
);
2120 pst
->dependencies
[s_idx
-s_id0
] = fdr_to_pst
[*rh
].pst
;
2123 do_cleanups (old_chain
);
2128 /* Do the initial analisys of the F_IDX-th file descriptor.
2129 Allocates a partial symtab for it, and builds the list
2130 of dependent files by recursion. LEV says at which level
2131 of recursion we are called (to pretty up debug traces) */
2133 static struct partial_symtab
*
2134 parse_fdr(f_idx
, lev
, objfile
)
2137 struct objfile
*objfile
;
2140 register struct partial_symtab
*pst
;
2143 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + f_idx
;
2145 /* Use this to indicate into which symtab this file was parsed */
2147 return (struct partial_symtab
*) fh
->ioptBase
;
2149 /* Debuggability level */
2150 if (compare_glevel(max_glevel
, fh
->glevel
) < 0)
2151 max_glevel
= fh
->glevel
;
2153 /* Make a new partial_symtab */
2154 pst
= new_psymtab(fh
->rss
, objfile
);
2159 pst
->textlow
= fh
->adr
;
2160 pst
->texthigh
= fh
->cpd
; /* To be fixed later */
2163 /* Make everything point to everything. */
2164 FDR_IDX(pst
) = f_idx
;
2165 fdr_to_pst
[f_idx
].pst
= pst
;
2166 fh
->ioptBase
= (int)pst
;
2168 /* Analyze its dependencies */
2173 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
2174 /* ...then presumably a .h file: drop reverse depends .h->.c */
2175 for (; s_id0
< fh
->crfd
; s_id0
++) {
2176 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
2178 s_id0
++; /* Skip self-dependency */
2183 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2184 pst
->dependencies
= (struct partial_symtab
**)
2185 obstack_alloc (&objfile
->psymbol_obstack
,
2186 pst
->number_of_dependencies
*
2187 sizeof (struct partial_symtab
*));
2188 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
2189 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
2191 pst
->dependencies
[s_idx
-s_id0
] = parse_fdr(*rh
, lev
+1, objfile
);
2199 mips_next_symbol_text ()
2202 return (char*)((SYMR
*)cur_fdr
->isymBase
)[cur_sdx
].iss
;
2205 /* Ancillary function to psymtab_to_symtab(). Does all the work
2206 for turning the partial symtab PST into a symtab, recurring
2207 first on all dependent psymtabs. The argument FILENAME is
2208 only passed so we can see in debug stack traces what file
2212 psymtab_to_symtab_1(pst
, filename
)
2213 struct partial_symtab
*pst
;
2221 struct linetable
*lines
;
2227 /* How many symbols will we need */
2228 /* FIXME, this does not count enum values. */
2229 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
2230 if (FDR_IDX(pst
) == -1) {
2234 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + FDR_IDX(pst
);
2235 f_max
+= fh
->csym
+ fh
->cpd
;
2236 maxlines
= 2 * fh
->cline
;
2239 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2242 && strcmp((char *)(((SYMR
*)fh
->isymBase
)[1].iss
), stabs_symbol
)
2247 st
= new_symtab (pst
->filename
, 2 * f_max
, maxlines
,
2250 st
= new_symtab ("unknown", f_max
, 0, pst
->objfile
);
2251 lines
= LINETABLE(st
);
2252 pending_list
= (struct mips_pending
**) cur_hdr
->cbOptOffset
;
2253 if (pending_list
== 0) {
2254 pending_list
= (struct mips_pending
**)
2255 xzalloc(cur_hdr
->ifdMax
* sizeof(struct mips_pending
*));
2256 cur_hdr
->cbOptOffset
= (int)pending_list
;
2260 /* Read in all partial symbtabs on which this one is dependent.
2261 NOTE that we do have circular dependencies, sigh. We solved
2262 that by setting pst->readin before this point. */
2264 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2265 if (!pst
->dependencies
[i
]->readin
) {
2266 /* Inform about additional files to be read in. */
2269 fputs_filtered (" ", stdout
);
2271 fputs_filtered ("and ", stdout
);
2273 printf_filtered ("%s...",
2274 pst
->dependencies
[i
]->filename
);
2275 wrap_here (""); /* Flush output */
2278 /* We only pass the filename for debug purposes */
2279 psymtab_to_symtab_1(pst
->dependencies
[i
],
2280 pst
->dependencies
[i
]->filename
);
2284 /* Now read the symbols for this symtab */
2286 current_objfile
= pst
-> objfile
;
2288 cur_fd
= FDR_IDX(pst
);
2291 /* Get a new lexical context */
2294 top_stack
->cur_st
= cur_stab
;
2295 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab
),
2297 BLOCK_START(top_stack
->cur_block
) = fh
? fh
->adr
: 0;
2298 BLOCK_END(top_stack
->cur_block
) = 0;
2299 top_stack
->blocktype
= stFile
;
2300 top_stack
->maxsyms
= 2*f_max
;
2301 top_stack
->cur_type
= 0;
2302 top_stack
->procadr
= 0;
2303 top_stack
->numargs
= 0;
2306 /* Parse locals and procedures */
2311 /* Parse local symbols first */
2316 current_objfile
= NULL
;
2319 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++) {
2320 register SYMR
*sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
2321 char *name
= (char*)sh
->iss
;
2322 CORE_ADDR valu
= sh
->value
;
2323 if (MIPS_IS_STAB(sh
)) {
2324 int type_code
= MIPS_UNMARK_STAB(sh
->index
);
2325 process_one_symbol (type_code
, 0, valu
, name
, /*FIXME*/ 0);
2327 else if (sh
->st
== stLabel
&& sh
->index
!= indexNil
) {
2328 /* Handle encoded stab line number. */
2329 record_line (current_subfile
, sh
->index
, valu
);
2332 st
= end_symtab (pst
->texthigh
, 0, 0, pst
->objfile
);
2335 /* BOUND is the highest core address of this file's procedures */
2336 int bound
= cur_fd
== cur_hdr
->ifdMax
- 1 ? cur_hdr
->cbDnOffset
2338 for (cur_sdx
= 0; cur_sdx
< fh
->csym
; ) {
2339 sh
= (SYMR
*) (fh
->isymBase
) + cur_sdx
;
2340 cur_sdx
+= parse_symbol(sh
, (union aux_ent
*)fh
->iauxBase
,
2344 /* Procedures next, note we need to look-ahead to
2345 find out where the procedure's code ends */
2348 for (i
= 0; i
< fh
->cpd
-1; i
++) {
2349 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2350 parse_procedure(pr
, pr
[1].adr
); /* next proc up */
2353 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2354 parse_procedure(pr
, bound
); /* next file up */
2356 /* Linenumbers. At the end, check if we can save memory */
2357 parse_lines(fh
, lines
);
2358 if (lines
->nitems
< fh
->cline
)
2359 lines
= shrink_linetable(lines
);
2365 LINETABLE(st
) = lines
;
2367 /* .. and our share of externals.
2368 XXX use the global list to speed up things here. how ?
2369 FIXME, Maybe quit once we have found the right number of ext's? */
2370 /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
2371 top_stack
->blocktype
= stFile
;
2372 top_stack
->maxsyms
=
2373 cur_hdr
->isymMax
+ cur_hdr
->ipdMax
+ cur_hdr
->iextMax
;
2375 ext_ptr
= PST_PRIVATE(pst
)->extern_tab
;
2376 for (i
= PST_PRIVATE(pst
)->extern_count
; --i
>= 0; ext_ptr
++)
2377 parse_external(*ext_ptr
, 1, fh
->fBigendian
);
2379 /* If there are undefined, tell the user */
2380 if (n_undef_symbols
) {
2381 printf_filtered("File %s contains %d unresolved references:",
2382 st
->filename
, n_undef_symbols
);
2383 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2384 n_undef_vars
, n_undef_procs
, n_undef_labels
);
2385 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
2391 /* Sort the symbol table now, we are done adding symbols to it.*/
2392 sort_symtab_syms(st
);
2396 /* Now link the psymtab and the symtab. */
2399 current_objfile
= NULL
;
2402 /* Ancillary parsing procedures. */
2404 /* Lookup the type at relative index RN. Return it in TPP
2405 if found and in any event come up with its name PNAME.
2406 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
2407 Return value says how many aux symbols we ate. */
2410 cross_ref(ax
, tpp
, type_code
, pname
, bigend
)
2413 int type_code
; /* Use to alloc new type if none is found. */
2421 ecoff_swap_rndx_in (bigend
, ax
, rn
);
2423 /* Escape index means 'the next one' */
2424 if (rn
->rfd
== 0xfff) {
2426 rf
= AUX_GET_ISYM (bigend
, ax
+ 1);
2433 *pname
= "<undefined>";
2436 * Find the relative file descriptor and the symbol in it
2438 FDR
*fh
= get_rfd(cur_fd
, rf
);
2443 * If we have processed this symbol then we left a forwarding
2444 * pointer to the corresponding GDB symbol. If not, we`ll put
2445 * it in a list of pending symbols, to be processed later when
2446 * the file f will be. In any event, we collect the name for
2447 * the type here. Which is why we made a first pass at
2450 sh
= (SYMR
*) (fh
->isymBase
) + rn
->index
;
2452 /* Careful, we might be looking at .o files */
2453 *pname
= (UNSAFE_DATA_ADDR(sh
->iss
)) ? "<undefined>" :
2456 /* Have we parsed it ? */
2457 if ((!UNSAFE_DATA_ADDR(sh
->value
)) && (sh
->st
== stParsed
)) {
2458 t
= (struct type
*) sh
->value
;
2461 /* Avoid duplicates */
2462 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
2466 *tpp
= init_type(type_code
, 0, 0, 0, (struct objfile
*) NULL
);
2467 add_pending(fh
, sh
, *tpp
);
2472 /* We used one auxent normally, two if we got a "next one" rf. */
2477 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2478 keeping the symtab sorted */
2480 static struct symbol
*
2481 mylookup_symbol (name
, block
, namespace, class)
2483 register struct block
*block
;
2484 enum namespace namespace;
2485 enum address_class
class;
2487 register int bot
, top
, inc
;
2488 register struct symbol
*sym
;
2491 top
= BLOCK_NSYMS(block
);
2494 sym
= BLOCK_SYM(block
, bot
);
2495 if (SYMBOL_NAME(sym
)[0] == inc
2496 && SYMBOL_NAMESPACE(sym
) == namespace
2497 && SYMBOL_CLASS(sym
) == class
2498 && !strcmp(SYMBOL_NAME(sym
), name
))
2502 block
= BLOCK_SUPERBLOCK (block
);
2504 return mylookup_symbol (name
, block
, namespace, class);
2509 /* Add a new symbol S to a block B.
2510 Infrequently, we will need to reallocate the block to make it bigger.
2511 We only detect this case when adding to top_stack->cur_block, since
2512 that's the only time we know how big the block is. FIXME. */
2519 int nsyms
= BLOCK_NSYMS(b
)++;
2520 struct block
*origb
;
2521 struct parse_stack
*stackp
;
2523 if (b
== top_stack
->cur_block
&&
2524 nsyms
>= top_stack
->maxsyms
) {
2525 complain (&block_overflow_complaint
, s
->name
);
2526 /* In this case shrink_block is actually grow_block, since
2527 BLOCK_NSYMS(b) is larger than its current size. */
2529 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
2531 /* Now run through the stack replacing pointers to the
2532 original block. shrink_block has already done this
2533 for the blockvector and BLOCK_FUNCTION. */
2534 for (stackp
= top_stack
; stackp
; stackp
= stackp
->next
) {
2535 if (stackp
->cur_block
== origb
) {
2536 stackp
->cur_block
= b
;
2537 stackp
->maxsyms
= BLOCK_NSYMS (b
);
2541 BLOCK_SYM(b
,nsyms
) = s
;
2544 /* Add a new block B to a symtab S */
2551 struct blockvector
*bv
= BLOCKVECTOR(s
);
2553 bv
= (struct blockvector
*)xrealloc((PTR
) bv
,
2554 sizeof(struct blockvector
) +
2555 BLOCKVECTOR_NBLOCKS(bv
)
2556 * sizeof(bv
->block
));
2557 if (bv
!= BLOCKVECTOR(s
))
2558 BLOCKVECTOR(s
) = bv
;
2560 BLOCKVECTOR_BLOCK(bv
, BLOCKVECTOR_NBLOCKS(bv
)++) = b
;
2563 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2564 MIPS' linenumber encoding might need more than one byte
2565 to describe it, LAST is used to detect these continuation lines */
2568 add_line(lt
, lineno
, adr
, last
)
2569 struct linetable
*lt
;
2575 last
= -2; /* make sure we record first line */
2577 if (last
== lineno
) /* skip continuation lines */
2580 lt
->item
[lt
->nitems
].line
= lineno
;
2581 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
2585 /* Sorting and reordering procedures */
2587 /* Blocks with a smaller low bound should come first */
2590 compare_blocks(b1
, b2
)
2591 struct block
**b1
, **b2
;
2593 register int addr_diff
;
2595 addr_diff
= (BLOCK_START((*b1
))) - (BLOCK_START((*b2
)));
2597 return (BLOCK_END((*b1
))) - (BLOCK_END((*b2
)));
2601 /* Sort the blocks of a symtab S.
2602 Reorder the blocks in the blockvector by code-address,
2603 as required by some MI search routines */
2609 struct blockvector
*bv
= BLOCKVECTOR(s
);
2611 if (BLOCKVECTOR_NBLOCKS(bv
) <= 2) {
2613 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) == 0)
2614 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = 0;
2615 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) == 0)
2616 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) = 0;
2620 * This is very unfortunate: normally all functions are compiled in
2621 * the order they are found, but if the file is compiled -O3 things
2622 * are very different. It would be nice to find a reliable test
2623 * to detect -O3 images in advance.
2625 if (BLOCKVECTOR_NBLOCKS(bv
) > 3)
2626 qsort(&BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
),
2627 BLOCKVECTOR_NBLOCKS(bv
) - FIRST_LOCAL_BLOCK
,
2628 sizeof(struct block
*),
2632 register CORE_ADDR high
= 0;
2633 register int i
, j
= BLOCKVECTOR_NBLOCKS(bv
);
2635 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
2636 if (high
< BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
)))
2637 high
= BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
));
2638 BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = high
;
2641 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) =
2642 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
));
2644 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2645 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2646 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2647 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2651 /* Constructor/restructor/destructor procedures */
2653 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2654 MAXSYMS and linenumbers MAXLINES we'll put in it */
2656 static struct symtab
*
2657 new_symtab(name
, maxsyms
, maxlines
, objfile
)
2661 struct objfile
*objfile
;
2663 struct symtab
*s
= allocate_symtab (name
, objfile
);
2665 LINETABLE(s
) = new_linetable(maxlines
);
2667 /* All symtabs must have at least two blocks */
2668 BLOCKVECTOR(s
) = new_bvect(2);
2669 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
) = new_block(maxsyms
);
2670 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), STATIC_BLOCK
) = new_block(maxsyms
);
2671 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
),STATIC_BLOCK
)) =
2672 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
);
2674 s
->free_code
= free_linetable
;
2679 /* Allocate a new partial_symtab NAME */
2681 static struct partial_symtab
*
2682 new_psymtab(name
, objfile
)
2684 struct objfile
*objfile
;
2686 struct partial_symtab
*psymtab
;
2688 /* FIXME -- why (char *) -1 rather than NULL? */
2689 psymtab
= allocate_psymtab (name
== (char *) -1 ? "<no name>" : name
,
2692 /* Keep a backpointer to the file's symbols */
2694 psymtab
-> read_symtab_private
= (char *)
2695 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
2696 CUR_HDR(psymtab
) = cur_hdr
;
2698 /* The way to turn this into a symtab is to call... */
2699 psymtab
->read_symtab
= mipscoff_psymtab_to_symtab
;
2704 /* Allocate a linetable array of the given SIZE. Since the struct
2705 already includes one item, we subtract one when calculating the
2706 proper size to allocate. */
2708 static struct linetable
*
2712 struct linetable
*l
;
2714 size
= (size
-1) * sizeof(l
->item
) + sizeof(struct linetable
);
2715 l
= (struct linetable
*)xmalloc(size
);
2720 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2721 I am not so sure about the 3.4 ones.
2723 Since the struct linetable already includes one item, we subtract one when
2724 calculating the proper size to allocate. */
2726 static struct linetable
*
2727 shrink_linetable(lt
)
2728 struct linetable
* lt
;
2731 return (struct linetable
*) xrealloc ((PTR
)lt
,
2732 sizeof(struct linetable
)
2733 + (lt
->nitems
- 1) * sizeof(lt
->item
));
2736 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2738 static struct blockvector
*
2742 struct blockvector
*bv
;
2745 size
= sizeof(struct blockvector
) + nblocks
* sizeof(struct block
*);
2746 bv
= (struct blockvector
*) xzalloc(size
);
2748 BLOCKVECTOR_NBLOCKS(bv
) = nblocks
;
2753 /* Allocate and zero a new block of MAXSYMS symbols */
2755 static struct block
*
2759 int size
= sizeof(struct block
) + (maxsyms
-1) * sizeof(struct symbol
*);
2761 return (struct block
*)xzalloc (size
);
2764 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2765 Shrink_block can also be used by add_symbol to grow a block. */
2767 static struct block
*
2773 struct blockvector
*bv
= BLOCKVECTOR(s
);
2776 /* Just reallocate it and fix references to the old one */
2778 new = (struct block
*) xrealloc ((PTR
)b
, sizeof(struct block
) +
2779 (BLOCK_NSYMS(b
)-1) * sizeof(struct symbol
*));
2781 /* Should chase pointers to old one. Fortunately, that`s just
2782 the block`s function and inferior blocks */
2783 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b
)
2784 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2785 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2786 if (BLOCKVECTOR_BLOCK(bv
,i
) == b
)
2787 BLOCKVECTOR_BLOCK(bv
,i
) = new;
2788 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) == b
)
2789 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) = new;
2793 /* Create a new symbol with printname NAME */
2795 static struct symbol
*
2799 struct symbol
*s
= (struct symbol
*)
2800 obstack_alloc (¤t_objfile
->symbol_obstack
, sizeof (struct symbol
));
2802 memset ((PTR
)s
, 0, sizeof (*s
));
2803 SYMBOL_NAME(s
) = name
;
2807 /* Create a new type with printname NAME */
2809 static struct type
*
2815 t
= alloc_type (current_objfile
);
2816 TYPE_NAME(t
) = name
;
2817 TYPE_CPLUS_SPECIFIC(t
) = (struct cplus_struct_type
*)
2818 &cplus_struct_default
;
2823 /* Things used for calling functions in the inferior.
2824 These functions are exported to our companion
2825 mips-tdep.c file and are here because they play
2826 with the symbol-table explicitly. */
2828 /* Sigtramp: make sure we have all the necessary information
2829 about the signal trampoline code. Since the official code
2830 from MIPS does not do so, we make up that information ourselves.
2831 If they fix the library (unlikely) this code will neutralize itself. */
2838 struct block
*b
, *b0
;
2840 sigtramp_address
= -1;
2842 /* We know it is sold as sigvec */
2843 s
= lookup_symbol("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
2845 /* Most programs do not play with signals */
2847 s
= lookup_symbol("_sigtramp", 0, VAR_NAMESPACE
, 0, NULL
);
2850 b0
= SYMBOL_BLOCK_VALUE(s
);
2852 /* A label of sigvec, to be more precise */
2853 s
= lookup_symbol("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
2856 /* But maybe this program uses its own version of sigvec */
2860 /* Did we or MIPSco fix the library ? */
2861 if (SYMBOL_CLASS(s
) == LOC_BLOCK
)
2863 sigtramp_address
= BLOCK_START(SYMBOL_BLOCK_VALUE(s
));
2864 sigtramp_end
= BLOCK_END(SYMBOL_BLOCK_VALUE(s
));
2868 sigtramp_address
= SYMBOL_VALUE(s
);
2869 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
2871 /* But what symtab does it live in ? */
2872 st
= find_pc_symtab(SYMBOL_VALUE(s
));
2875 * Ok, there goes the fix: turn it into a procedure, with all the
2876 * needed info. Note we make it a nested procedure of sigvec,
2877 * which is the way the (assembly) code is actually written.
2879 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2880 SYMBOL_CLASS(s
) = LOC_BLOCK
;
2881 SYMBOL_TYPE(s
) = init_type(TYPE_CODE_FUNC
, 4, 0, 0, (struct objfile
*) NULL
);
2882 TYPE_TARGET_TYPE(SYMBOL_TYPE(s
)) = builtin_type_void
;
2884 /* Need a block to allocate .gdbinfo. in */
2886 SYMBOL_BLOCK_VALUE(s
) = b
;
2887 BLOCK_START(b
) = sigtramp_address
;
2888 BLOCK_END(b
) = sigtramp_end
;
2889 BLOCK_FUNCTION(b
) = s
;
2890 BLOCK_SUPERBLOCK(b
) = BLOCK_SUPERBLOCK(b0
);
2894 /* Make a .gdbinfo. for it */
2896 struct mips_extra_func_info
*e
=
2897 (struct mips_extra_func_info
*)
2898 xzalloc(sizeof(struct mips_extra_func_info
));
2900 e
->numargs
= 0; /* the kernel thinks otherwise */
2901 /* align_longword(sigcontext + SIGFRAME) */
2902 e
->pdr
.frameoffset
= 0x150;
2903 e
->pdr
.framereg
= SP_REGNUM
;
2905 e
->pdr
.regmask
= -2;
2906 e
->pdr
.regoffset
= -(41 * sizeof(int));
2907 e
->pdr
.fregmask
= -1;
2908 e
->pdr
.fregoffset
= -(37 * sizeof(int));
2909 e
->pdr
.isym
= (long)s
;
2911 current_objfile
= st
->objfile
; /* Keep new_symbol happy */
2912 s
= new_symbol(".gdbinfo.");
2913 SYMBOL_VALUE(s
) = (int) e
;
2914 SYMBOL_NAMESPACE(s
) = LABEL_NAMESPACE
;
2915 SYMBOL_CLASS(s
) = LOC_CONST
;
2916 SYMBOL_TYPE(s
) = builtin_type_void
;
2917 current_objfile
= NULL
;
2920 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
2923 /* Initialization */
2925 static struct sym_fns ecoff_sym_fns
=
2927 "ecoff", /* sym_name: name or name prefix of BFD target type */
2928 5, /* sym_namelen: number of significant sym_name chars */
2929 mipscoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
2930 mipscoff_symfile_init
,/* sym_init: read initial info, setup for sym_read() */
2931 mipscoff_symfile_read
,/* sym_read: read a symbol file into symtab */
2932 mipscoff_symfile_finish
,/* sym_finish: finished with file, cleanup */
2933 NULL
/* next: pointer to next struct sym_fns */
2938 _initialize_mipsread ()
2940 add_symtab_fns (&ecoff_sym_fns
);
2942 /* Missing basic types */
2943 builtin_type_string
=
2944 init_type (TYPE_CODE_PASCAL_ARRAY
,
2946 (struct objfile
*) NULL
);
2947 builtin_type_complex
=
2948 init_type(TYPE_CODE_FLT
,
2949 2 * sizeof(float), 0, "complex",
2950 (struct objfile
*) NULL
);
2951 builtin_type_double_complex
=
2952 init_type(TYPE_CODE_FLT
,
2953 2 * sizeof(double), 0, "double_complex",
2954 (struct objfile
*) NULL
);
2955 builtin_type_fixed_dec
=
2956 init_type(TYPE_CODE_INT
, sizeof(int),
2958 (struct objfile
*) NULL
);
2959 builtin_type_float_dec
=
2960 init_type(TYPE_CODE_FLT
, sizeof(double),
2961 0, "floating_decimal",
2962 (struct objfile
*) NULL
);