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 <mips/syms.h>
71 #endif /* not CMUCS */
73 #include "coff/mips.h"
74 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
75 #include "aout/aout64.h"
76 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native, now */
77 #include "coff/ecoff-ext.h"
80 struct external_filehdr f
;
81 struct external_aouthdr a
;
84 /* These must match the corresponding definition in gcc/config/xm-mips.h.
85 At some point, these should probably go into a shared include file,
86 but currently gcc and gdb do not share any directories. */
88 #define CODE_MASK 0x8F300
89 #define MIPS_IS_STAB(sym) (((sym)->index & 0xFFF00) == CODE_MASK)
90 #define MIPS_MARK_STAB(code) ((code)+CODE_MASK)
91 #define MIPS_UNMARK_STAB(code) ((code)-CODE_MASK)
92 #define STABS_SYMBOL "@stabs"
94 /* Each partial symbol table entry contains a pointer to private data for the
95 read_symtab() function to use when expanding a partial symbol table entry
96 to a full symbol table entry.
98 For mipsread this structure contains the index of the FDR that this psymtab
99 represents and a pointer to the symbol table header HDRR from the symbol
100 file that the psymtab was created from. */
102 #define PST_PRIVATE(p) ((struct symloc *)(p)->read_symtab_private)
103 #define FDR_IDX(p) (PST_PRIVATE(p)->fdr_idx)
104 #define CUR_HDR(p) (PST_PRIVATE(p)->cur_hdr)
109 EXTR
**extern_tab
; /* Pointer to external symbols for this file. */
110 int extern_count
; /* Size of extern_tab. */
113 /* Things we import explicitly from other modules */
115 extern int info_verbose
;
116 extern struct block
*block_for_pc();
117 extern void sort_symtab_syms();
119 /* Various complaints about symbol reading that don't abort the process */
121 struct complaint bad_file_number_complaint
=
122 {"bad file number %d", 0, 0};
124 struct complaint unknown_ext_complaint
=
125 {"unknown external symbol %s", 0, 0};
127 struct complaint unknown_sym_complaint
=
128 {"unknown local symbol %s", 0, 0};
130 struct complaint unknown_st_complaint
=
131 {"with type %d", 0, 0};
133 struct complaint block_overflow_complaint
=
134 {"block containing %s overfilled", 0, 0};
136 struct complaint basic_type_complaint
=
137 {"cannot map MIPS basic type 0x%x", 0, 0};
139 struct complaint unknown_type_qual_complaint
=
140 {"unknown type qualifier 0x%x", 0, 0};
142 struct complaint array_bitsize_complaint
=
143 {"size of array target type not known, assuming %d bits", 0, 0};
145 struct complaint bad_tag_guess_complaint
=
146 {"guessed tag type incorrectly", 0, 0};
148 /* Macros and extra defs */
150 /* Already-parsed symbols are marked specially */
152 #define stParsed stType
154 /* Puns: hard to find whether -g was used and how */
156 #define MIN_GLEVEL GLEVEL_0
157 #define compare_glevel(a,b) \
158 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
159 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
161 /* When looking at .o files, avoid tripping over bad addresses */
163 #define SAFE_TEXT_ADDR 0x400000
164 #define SAFE_DATA_ADDR 0x10000000
166 #define UNSAFE_DATA_ADDR(p) ((unsigned)p < SAFE_DATA_ADDR || (unsigned)p > 2*SAFE_DATA_ADDR)
168 /* Things that really are local to this module */
170 /* GDB symtable for the current compilation unit */
172 static struct symtab
*cur_stab
;
174 /* MIPS symtab header for the current file */
176 static HDRR
*cur_hdr
;
178 /* Pointer to current file decriptor record, and its index */
183 /* Index of current symbol */
187 /* Note how much "debuggable" this image is. We would like
188 to see at least one FDR with full symbols */
193 /* When examining .o files, report on undefined symbols */
195 static int n_undef_symbols
, n_undef_labels
, n_undef_vars
, n_undef_procs
;
197 /* Pseudo symbol to use when putting stabs into the symbol table. */
199 static char stabs_symbol
[] = STABS_SYMBOL
;
201 /* Extra builtin types */
203 struct type
*builtin_type_complex
;
204 struct type
*builtin_type_double_complex
;
205 struct type
*builtin_type_fixed_dec
;
206 struct type
*builtin_type_float_dec
;
207 struct type
*builtin_type_string
;
209 /* Forward declarations */
212 fixup_symtab
PARAMS ((HDRR
*, char *, int, bfd
*));
215 read_mips_symtab
PARAMS ((struct objfile
*, int));
218 read_the_mips_symtab
PARAMS ((bfd
*, int, CORE_ADDR
));
221 upgrade_type
PARAMS ((struct type
**, int, union aux_ent
*, int));
224 parse_partial_symbols
PARAMS ((int, struct objfile
*));
227 cross_ref
PARAMS ((union aux_ext
*, struct type
**, int, char **, int));
230 fixup_sigtramp
PARAMS ((void));
232 static struct symbol
*
233 new_symbol
PARAMS ((char *));
236 new_type
PARAMS ((char *));
238 static struct block
*
239 new_block
PARAMS ((int));
241 static struct symtab
*
242 new_symtab
PARAMS ((char *, int, int, struct objfile
*));
244 static struct linetable
*
245 new_linetable
PARAMS ((int));
247 static struct blockvector
*
248 new_bvect
PARAMS ((int));
251 parse_type
PARAMS ((union aux_ext
*, int *, int));
253 static struct symbol
*
254 mylookup_symbol
PARAMS ((char *, struct block
*, enum namespace,
255 enum address_class
));
257 static struct block
*
258 shrink_block
PARAMS ((struct block
*, struct symtab
*));
261 xzalloc
PARAMS ((unsigned int));
264 sort_blocks
PARAMS ((struct symtab
*));
267 compare_blocks
PARAMS ((struct block
**, struct block
**));
269 static struct partial_symtab
*
270 new_psymtab
PARAMS ((char *, struct objfile
*));
273 static struct partial_symtab
*
274 parse_fdr
PARAMS ((int, int, struct objfile
*));
278 psymtab_to_symtab_1
PARAMS ((struct partial_symtab
*, char *));
281 add_block
PARAMS ((struct block
*, struct symtab
*));
284 add_symbol
PARAMS ((struct symbol
*, struct block
*));
287 add_line
PARAMS ((struct linetable
*, int, CORE_ADDR
, int));
289 static struct linetable
*
290 shrink_linetable
PARAMS ((struct linetable
*));
293 mips_next_symbol_text
PARAMS ((void));
295 /* Things we export to other modules */
297 /* Address bounds for the signal trampoline in inferior, if any */
298 /* FIXME: Nothing really seems to use this. Why is it here? */
300 CORE_ADDR sigtramp_address
, sigtramp_end
;
303 mipscoff_new_init (ignore
)
304 struct objfile
*ignore
;
309 mipscoff_symfile_init (objfile
)
310 struct objfile
*objfile
;
312 if (objfile
-> sym_private
!= NULL
)
314 mfree (objfile
-> md
, objfile
-> sym_private
);
316 objfile
-> sym_private
= NULL
;
320 mipscoff_symfile_read (objfile
, addr
, mainline
)
321 struct objfile
*objfile
;
325 bfd
*abfd
= objfile
-> obfd
;
328 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
329 desc
= fileno ((FILE *)(abfd
->iostream
)); /* Raw file descriptor */
332 init_minimal_symbol_collection ();
333 make_cleanup (discard_minimal_symbols
, 0);
335 /* Now that the executable file is positioned at symbol table,
336 process it and define symbols accordingly. */
338 read_mips_symtab(objfile
, desc
);
340 /* Install any minimal symbols that have been collected as the current
341 minimal symbols for this objfile. */
343 install_minimal_symbols (objfile
);
346 /* Perform any local cleanups required when we are done with a particular
347 objfile. I.E, we are in the process of discarding all symbol information
348 for an objfile, freeing up all memory held for it, and unlinking the
349 objfile struct from the global list of known objfiles. */
352 mipscoff_symfile_finish (objfile
)
353 struct objfile
*objfile
;
355 if (objfile
-> sym_private
!= NULL
)
357 mfree (objfile
-> md
, objfile
-> sym_private
);
360 /* If we have a file symbol header lying around, blow it away. */
369 /* Allocate zeroed memory */
375 PTR p
= xmalloc(size
);
381 /* Exported procedure: Builds a symtab from the PST partial one.
382 Restores the environment in effect when PST was created, delegates
383 most of the work to an ancillary procedure, and sorts
384 and reorders the symtab list at the end */
387 mipscoff_psymtab_to_symtab(pst
)
388 struct partial_symtab
*pst
;
395 printf_filtered("Reading in symbols for %s...", pst
->filename
);
398 /* Restore the header and list of pending typedefs */
399 cur_hdr
= CUR_HDR(pst
);
401 next_symbol_text_func
= mips_next_symbol_text
;
403 psymtab_to_symtab_1(pst
, pst
->filename
);
405 /* Match with global symbols. This only needs to be done once,
406 after all of the symtabs and dependencies have been read in. */
407 scan_file_globals (pst
->objfile
);
410 printf_filtered("done.\n");
413 /* Exported procedure: Is PC in the signal trampoline code */
416 in_sigtramp(pc
, ignore
)
418 char *ignore
; /* function name */
420 if (sigtramp_address
== 0)
422 return (pc
>= sigtramp_address
&& pc
< sigtramp_end
);
425 /* File-level interface functions */
427 /* Read the symtab information from file FSYM into memory. Also,
428 return address just past end of our text segment in *END_OF_TEXT_SEGP. */
431 read_the_mips_symtab(abfd
, fsym
, end_of_text_segp
)
434 CORE_ADDR
*end_of_text_segp
;
436 int stsize
, st_hdrsize
;
438 struct hdr_ext hdr_ext
;
440 /* Header for executable/object file we read symbols from */
441 struct coff_exec filhdr
;
443 /* We need some info from the initial headers */
445 myread(fsym
, (char *)&filhdr
, sizeof filhdr
);
447 if (end_of_text_segp
)
449 bfd_h_get_32 (abfd
, filhdr
.a
.text_start
) +
450 bfd_h_get_32 (abfd
, filhdr
.a
.tsize
);
452 /* Find and read the symbol table header */
453 st_hdrsize
= bfd_h_get_32 (abfd
, filhdr
.f
.f_nsyms
);
454 st_filptr
= bfd_h_get_32 (abfd
, filhdr
.f
.f_symptr
);
458 lseek(fsym
, st_filptr
, L_SET
);
459 if (st_hdrsize
!= sizeof (hdr_ext
)) { /* Profanity check */
460 error ("Wrong header size: %d, not %d", st_hdrsize
,
463 if (read(fsym
, &hdr_ext
, st_hdrsize
) != st_hdrsize
)
465 ecoff_swap_hdr_in (abfd
, &hdr_ext
, &st_hdr
);
467 /* Find out how large the symbol table is */
468 stsize
= (st_hdr
.cbExtOffset
- (st_filptr
+ st_hdrsize
))
469 + st_hdr
.iextMax
* cbEXTR
;
471 /* Allocate space for the symbol table. Read it in. */
472 cur_hdr
= (HDRR
*) xmalloc(stsize
+ st_hdrsize
);
474 memcpy((PTR
)cur_hdr
, (PTR
)&hdr_ext
, st_hdrsize
);
475 if (read(fsym
, (char *) cur_hdr
+ st_hdrsize
, stsize
) != stsize
)
478 /* Fixup file_pointers in it */
479 fixup_symtab(cur_hdr
, (char *) cur_hdr
+ st_hdrsize
,
480 st_filptr
+ st_hdrsize
, abfd
);
484 error("Short read on %s", bfd_get_filename (abfd
));
488 /* Turn all file-relative pointers in the symtab described by HDR
489 into memory pointers, given that the symtab itself is located
490 at DATA in memory and F_PTR in the file.
492 Byte-swap all the data structures, in place, while we are at it --
493 except AUX entries, which we leave in their original byte order.
494 They will be swapped as they are used instead. (FIXME: we ought to
495 do all the data structures that way.) */
498 fixup_symtab (hdr
, data
, f_ptr
, abfd
)
509 struct rfd_ext
*rbase
;
511 /* This function depends on the external and internal forms
512 of the MIPS symbol table taking identical space. Check this
513 assumption at compile-time. */
514 static check_hdr1
[1 + sizeof (struct hdr_ext
) - sizeof (HDRR
)] = {0};
515 static check_hdr2
[1 + sizeof (HDRR
) - sizeof (struct hdr_ext
)] = {0};
516 static check_fdr1
[1 + sizeof (struct fdr_ext
) - sizeof (FDR
)] = {0};
517 static check_fdr2
[1 + sizeof (FDR
) - sizeof (struct fdr_ext
)] = {0};
518 static check_pdr1
[1 + sizeof (struct pdr_ext
) - sizeof (PDR
)] = {0};
519 static check_pdr2
[1 + sizeof (PDR
) - sizeof (struct pdr_ext
)] = {0};
520 static check_sym1
[1 + sizeof (struct sym_ext
) - sizeof (SYMR
)] = {0};
521 static check_sym2
[1 + sizeof (SYMR
) - sizeof (struct sym_ext
)] = {0};
522 static check_ext1
[1 + sizeof (struct ext_ext
) - sizeof (EXTR
)] = {0};
523 static check_ext2
[1 + sizeof (EXTR
) - sizeof (struct ext_ext
)] = {0};
524 static check_rfd1
[1 + sizeof (struct rfd_ext
) - sizeof (RFDT
)] = {0};
525 static check_rfd2
[1 + sizeof (RFDT
) - sizeof (struct rfd_ext
)] = {0};
527 /* Swap in the header record. */
528 ecoff_swap_hdr_in (abfd
, hdr
, hdr
);
531 * These fields are useless (and empty) by now:
532 * hdr->cbDnOffset, hdr->cbOptOffset
533 * We use them for other internal purposes.
536 hdr
->cbOptOffset
= 0;
539 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
553 /* Fix all the RFD's. */
554 rbase
= (struct rfd_ext
*)(hdr
->cbRfdOffset
);
555 for (i
= 0; i
< hdr
->crfd
; i
++) {
556 ecoff_swap_rfd_in (abfd
, rbase
+i
, (pRFDT
) rbase
+i
);
559 /* Fix all string pointers inside the symtab, and
560 the FDR records. Also fix other miscellany. */
562 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
563 register unsigned code_offset
;
565 /* Header itself, and strings */
566 fh
= (FDR
*) (hdr
->cbFdOffset
) + f_idx
;
568 /* Swap in the FDR */
569 ecoff_swap_fdr_in (abfd
, fh
, fh
);
571 fh
->issBase
+= hdr
->cbSsOffset
;
573 fh
->rss
= (long)fh
->rss
+ fh
->issBase
;
576 fh
->isymBase
= (int)((SYMR
*)(hdr
->cbSymOffset
)+fh
->isymBase
);
578 /* FIXME! Probably don't want to do this here! */
579 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
580 sh
= (SYMR
*)fh
->isymBase
+ s_idx
;
581 ecoff_swap_sym_in (abfd
, sh
, sh
);
583 sh
->iss
= (long) sh
->iss
+ fh
->issBase
;
589 /* cannot fix fh->ipdFirst because it is a short */
590 #define IPDFIRST(h,fh) \
591 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
593 /* Optional symbols (actually used for partial_symtabs) */
599 fh
->iauxBase
= hdr
->cbAuxOffset
+ fh
->iauxBase
* sizeof(union aux_ext
);
600 /* Relative file descriptor table */
601 fh
->rfdBase
= hdr
->cbRfdOffset
+ fh
->rfdBase
* sizeof(RFDT
);
605 fh
->cbLineOffset
+= hdr
->cbLineOffset
;
607 /* Procedure symbols. (XXX This should be done later) */
608 code_offset
= fh
->adr
;
609 for (s_idx
= 0; s_idx
< fh
->cpd
; s_idx
++) {
610 unsigned name
, only_ext
;
612 pr
= (PDR
*)(IPDFIRST(hdr
,fh
)) + s_idx
;
613 ecoff_swap_pdr_in (abfd
, pr
, pr
);
615 /* Simple rule to find files linked "-x" */
616 only_ext
= fh
->rss
== -1;
618 if (pr
->isym
== -1) {
619 /* static function */
623 name
= hdr
->cbExtOffset
+ pr
->isym
* sizeof(EXTR
);
624 sh
= &((EXTR
*)name
)->asym
;
628 sh
= (SYMR
*)fh
->isymBase
+ pr
->isym
;
629 /* Included code ? */
630 if (s_idx
== 0 && pr
->adr
!= 0)
631 code_offset
-= pr
->adr
;
634 /* Turn index into a pointer */
637 /* Fix line numbers */
638 pr
->cbLineOffset
+= fh
->cbLineOffset
;
640 /* Relocate address */
642 pr
->adr
+= code_offset
;
646 /* External symbols: swap in, and fix string */
647 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
648 esh
= (EXTR
*)(hdr
->cbExtOffset
) + s_idx
;
649 ecoff_swap_ext_in (abfd
, esh
, esh
);
650 esh
->asym
.iss
= esh
->asym
.iss
+ hdr
->cbSsExtOffset
;
655 /* Find a file descriptor given its index RF relative to a file CF */
663 f
= (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
664 /* Object files do not have the RFD table, all refs are absolute */
666 return (FDR
*) (cur_hdr
->cbFdOffset
) + rf
;
667 cf
= *((pRFDT
) f
->rfdBase
+ rf
);
668 return (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
671 /* Return a safer print NAME for a file descriptor */
677 if (name
== (char *) -1)
678 return "<stripped file>";
679 if (UNSAFE_DATA_ADDR(name
))
685 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
686 whether we are adding to the general symtab or not.
687 FIXME: INCREMENTAL is currently always zero, though it should not be. */
690 read_mips_symtab (objfile
, desc
)
691 struct objfile
*objfile
;
694 CORE_ADDR end_of_text_seg
;
696 read_the_mips_symtab(objfile
->obfd
, desc
, &end_of_text_seg
);
698 parse_partial_symbols(end_of_text_seg
, objfile
);
702 * Check to make sure file was compiled with -g.
703 * If not, warn the user of this limitation.
705 if (compare_glevel(max_glevel
, GLEVEL_2
) < 0) {
706 if (max_gdbinfo
== 0)
708 "\n%s not compiled with -g, debugging support is limited.\n",
711 "You should compile with -g2 or -g3 for best debugging support.\n");
717 /* Local utilities */
719 /* Map of FDR indexes to partial symtabs */
722 struct partial_symtab
*pst
; /* the psymtab proper */
723 int n_globals
; /* exported globals (external symbols) */
724 int globals_offset
; /* cumulative */
728 /* Utility stack, used to nest procedures and blocks properly.
729 It is a doubly linked list, to avoid too many alloc/free.
730 Since we might need it quite a few times it is NOT deallocated
733 static struct parse_stack
{
734 struct parse_stack
*next
, *prev
;
735 struct symtab
*cur_st
; /* Current symtab. */
736 struct block
*cur_block
; /* Block in it. */
737 int blocktype
; /* What are we parsing. */
738 int maxsyms
; /* Max symbols in this block. */
739 struct type
*cur_type
; /* Type we parse fields for. */
740 int cur_field
; /* Field number in cur_type. */
741 int procadr
; /* Start addres of this procedure */
742 int numargs
; /* Its argument count */
743 } *top_stack
; /* Top stack ptr */
746 /* Enter a new lexical context */
748 static push_parse_stack()
750 struct parse_stack
*new;
752 /* Reuse frames if possible */
753 if (top_stack
&& top_stack
->prev
)
754 new = top_stack
->prev
;
756 new = (struct parse_stack
*) xzalloc(sizeof(struct parse_stack
));
757 /* Initialize new frame with previous content */
759 register struct parse_stack
*prev
= new->prev
;
762 top_stack
->prev
= new;
764 new->next
= top_stack
;
769 /* Exit a lexical context */
771 static pop_parse_stack()
776 top_stack
= top_stack
->next
;
780 /* Cross-references might be to things we haven't looked at
781 yet, e.g. type references. To avoid too many type
782 duplications we keep a quick fixup table, an array
783 of lists of references indexed by file descriptor */
785 static struct mips_pending
{
786 struct mips_pending
*next
; /* link */
787 SYMR
*s
; /* the symbol */
788 struct type
*t
; /* its partial type descriptor */
792 /* Check whether we already saw symbol SH in file FH as undefined */
795 struct mips_pending
*is_pending_symbol(fh
, sh
)
799 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
800 register struct mips_pending
*p
;
802 /* Linear search is ok, list is typically no more than 10 deep */
803 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
809 /* Add a new undef symbol SH of type T */
812 add_pending(fh
, sh
, t
)
817 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
818 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
820 /* Make sure we do not make duplicates */
822 p
= (struct mips_pending
*) xmalloc(sizeof(*p
));
825 p
->next
= pending_list
[f_idx
];
826 pending_list
[f_idx
] = p
;
828 sh
->reserved
= 1; /* for quick check */
831 /* Throw away undef entries when done with file index F_IDX */
832 /* FIXME -- storage leak. This is never called!!! --gnu */
837 register struct mips_pending
*p
, *q
;
839 for (p
= pending_list
[f_idx
]; p
; p
= q
) {
843 pending_list
[f_idx
] = 0;
846 /* The number of args to a procedure is not explicit in the symtab,
847 this is the list of all those we know of.
848 This makes parsing more reasonable and avoids extra passes */
850 static struct numarg
{
851 struct numarg
*next
; /* link */
852 unsigned adr
; /* procedure's start address */
853 unsigned num
; /* arg count */
856 /* Record that the procedure at ADR takes NUM arguments. */
861 struct numarg
*n
= (struct numarg
*) xmalloc(sizeof(struct numarg
));
865 n
->next
= numargs_list
;
869 /* See if we know how many arguments the procedure at ADR takes */
874 struct numarg
*n
= numargs_list
;
876 while (n
&& n
->adr
!= adr
)
878 return (n
) ? n
->num
: -1;
881 /* Release storage when done with this file */
882 /* FIXME -- storage leak. This is never called! --gnu */
887 struct numarg
*n
= numargs_list
, *m
;
898 prepend_tag_kind(tag_name
, type_code
)
908 case TYPE_CODE_STRUCT
:
911 case TYPE_CODE_UNION
:
918 result
= (char*)obstack_alloc (¤t_objfile
->symbol_obstack
,
919 strlen(prefix
) + strlen(tag_name
) + 1);
920 sprintf(result
, "%s%s", prefix
, tag_name
);
925 /* Parsing Routines proper. */
927 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
928 For blocks, procedures and types we open a new lexical context.
929 This is basically just a big switch on the symbol's type.
930 Argument AX is the base pointer of aux symbols for this file (fh->iauxBase).
931 BIGEND says whether aux symbols are big-endian or little-endian.
932 Return count of SYMR's handled (normally one). */
935 parse_symbol(sh
, ax
, bigend
)
946 /* When a symbol is cross-referenced from other files/symbols
947 we mark it explicitly */
948 int pend
= (sh
->reserved
== 1);
949 enum address_class
class;
957 case stGlobal
: /* external symbol, goes into global block */
959 b
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
961 s
= new_symbol(sh
->iss
);
962 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
965 case stStatic
: /* static data, goes into current block. */
967 b
= top_stack
->cur_block
;
968 s
= new_symbol(sh
->iss
);
969 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
972 case stLocal
: /* local variable, goes into current block */
973 if (sh
->sc
== scRegister
) {
974 class = LOC_REGISTER
;
976 sh
->value
+= FP0_REGNUM
-32;
979 b
= top_stack
->cur_block
;
980 s
= new_symbol(sh
->iss
);
981 SYMBOL_VALUE(s
) = sh
->value
;
983 data
: /* Common code for symbols describing data */
984 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
985 SYMBOL_CLASS(s
) = class;
988 /* Type could be missing in a number of cases */
989 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
990 sh
->index
== 0xfffff)
991 SYMBOL_TYPE(s
) = builtin_type_int
; /* undefined? */
993 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, 0, bigend
);
994 /* Value of a data symbol is its memory address */
997 case stParam
: /* arg to procedure, goes into current block */
999 top_stack
->numargs
++;
1001 name
= (char*)sh
->iss
;
1002 /* Special GNU C++ name. */
1003 if (name
[0] == CPLUS_MARKER
&& name
[1] == 't' && name
[2] == 0)
1005 s
= new_symbol(name
);
1007 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1008 if (sh
->sc
== scRegister
) {
1009 SYMBOL_CLASS(s
) = LOC_REGPARM
;
1011 sh
->value
+= FP0_REGNUM
-32;
1013 SYMBOL_CLASS(s
) = LOC_ARG
;
1014 SYMBOL_VALUE(s
) = sh
->value
;
1015 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, 0, bigend
);
1016 add_symbol(s
, top_stack
->cur_block
);
1018 /* FIXME: This has not been tested. See dbxread.c */
1019 /* Add the type of this parameter to the function/procedure
1020 type of this block. */
1021 add_param_to_type(&top_stack
->cur_block
->function
->type
,s
);
1025 case stLabel
: /* label, goes into current block */
1026 s
= new_symbol(sh
->iss
);
1027 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
; /* so that it can be used */
1028 SYMBOL_CLASS(s
) = LOC_LABEL
; /* but not misused */
1029 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
1030 SYMBOL_TYPE(s
) = builtin_type_int
;
1031 add_symbol(s
, top_stack
->cur_block
);
1034 case stProc
: /* Procedure, usually goes into global block */
1035 case stStaticProc
: /* Static procedure, goes into current block */
1036 s
= new_symbol(sh
->iss
);
1037 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1038 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1039 /* Type of the return value */
1040 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
1041 t
= builtin_type_int
;
1043 t
= parse_type(ax
+ sh
->index
+ 1, 0, bigend
);
1044 b
= top_stack
->cur_block
;
1045 if (sh
->st
== stProc
) {
1046 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
1047 /* The next test should normally be true,
1048 but provides a hook for nested functions
1049 (which we don't want to make global). */
1050 if (b
== BLOCKVECTOR_BLOCK(bv
, STATIC_BLOCK
))
1051 b
= BLOCKVECTOR_BLOCK(bv
, GLOBAL_BLOCK
);
1055 /* Make a type for the procedure itself */
1057 /* FIXME: This has not been tested yet! See dbxread.c */
1058 /* Generate a template for the type of this function. The
1059 types of the arguments will be added as we read the symbol
1061 bcopy(SYMBOL_TYPE(s
),lookup_function_type(t
),sizeof(struct type
));
1063 SYMBOL_TYPE(s
) = lookup_function_type (t
);
1066 /* Create and enter a new lexical context */
1067 b
= new_block(top_stack
->maxsyms
);
1068 SYMBOL_BLOCK_VALUE(s
) = b
;
1069 BLOCK_FUNCTION(b
) = s
;
1070 BLOCK_START(b
) = BLOCK_END(b
) = sh
->value
;
1071 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1072 add_block(b
, top_stack
->cur_st
);
1074 /* Not if we only have partial info */
1075 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
1079 top_stack
->cur_block
= b
;
1080 top_stack
->blocktype
= sh
->st
;
1081 top_stack
->cur_type
= SYMBOL_TYPE(s
);
1082 top_stack
->cur_field
= -1;
1083 top_stack
->procadr
= sh
->value
;
1084 top_stack
->numargs
= 0;
1086 sh
->value
= (long) SYMBOL_TYPE(s
);
1090 #ifndef btVoid /* btVoid was added late. */
1093 /* These new symbol types have been recently added to SGI machines. */
1107 case stBlock
: /* Either a lexical block, or some type */
1109 top_stack
->blocktype
= stBlock
;
1110 if (sh
->sc
== scInfo
) { /* structure/union/enum def */
1112 sh
->st
== stStruct
? TYPE_CODE_STRUCT
1113 : sh
->st
== stUnion
? TYPE_CODE_UNION
1114 : sh
->st
== stEnum
? TYPE_CODE_ENUM
1121 s
= new_symbol(sh
->iss
);
1122 SYMBOL_NAMESPACE(s
) = STRUCT_NAMESPACE
;
1123 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1124 SYMBOL_VALUE(s
) = 0;
1125 add_symbol(s
, top_stack
->cur_block
);
1127 /* First count the number of fields. */
1128 for (tsym
= sh
+1; tsym
->st
!= stEnd
; tsym
++)
1129 if (tsym
->st
== stMember
) {
1130 if (nfields
== 0 && type_code
== TYPE_CODE_UNDEF
)
1131 /* If the type of the member is Nil (or Void)
1132 assume the tag is an enumeration. */
1133 if (tsym
->index
== indexNil
)
1134 type_code
= TYPE_CODE_ENUM
;
1136 ecoff_swap_tir_in (bigend
,
1137 &ax
[tsym
->index
].a_ti
,
1139 if (tir
.bt
== btNil
|| tir
.bt
== btVoid
)
1140 type_code
= TYPE_CODE_ENUM
;
1143 if (tsym
->value
> max_value
)
1144 max_value
= tsym
->value
;
1146 else if (tsym
->st
== stBlock
1147 || tsym
->st
== stParsed
) {
1148 if (tsym
->sc
== scVariant
) ; /*UNIMPLEMENTED*/
1149 if (tsym
->index
!= 0)
1150 tsym
= ((SYMR
*)cur_fdr
->isymBase
)
1154 /* There is no guaranteed way to distinguish struct,
1155 unions, and enums at this point. This is a bug in the
1156 original design (that has been fixed with the
1157 recent addition of the stStruct, stUnion, and stEnum
1158 symbol types.) The way you can tell is if/when you
1159 see a variable or field of that type: In that case
1160 the variable's type (in the AUX table) says if the
1161 type is struct, union, or enum,
1162 and points back to the stBlock here.
1163 So you can patch the tag kind up later - but only
1164 if there actually is a variable or field of that type.
1166 So until we know for sure, we will guess at this point.
1168 If the first member has index==indexNil or a void type,
1169 assume we have an enumeration.
1170 Otherwise, if there is more than one member, and all
1171 the members have offset 0, assume we have a union.
1172 Otherwise, assume we have a struct.
1174 The heuristic could guess wrong in the case of
1175 of an enumeration with no members or a union
1176 with one (or zero) members, or when all except the
1177 last field of a struct have width zero.
1178 These are uncommon and/or illegal situations, and
1179 in any case guessing wrong probably doesn't matter much.
1181 But if we later do find out we were wrong,
1182 we fixup the tag kind. Members of an enumeration
1183 must be handled differently from struct/union fields,
1184 and that is harder to patch up, but luckily we
1185 shouldn't need to. (If there are any enumeration
1186 members, we can tell for sure it's an enum here.) */
1188 if (type_code
== TYPE_CODE_UNDEF
)
1189 if (nfields
> 1 && max_value
== 0)
1190 type_code
= TYPE_CODE_UNION
;
1192 type_code
= TYPE_CODE_STRUCT
;
1194 /* If this type was expected, use its partial definition */
1196 t
= is_pending_symbol(cur_fdr
, sh
)->t
;
1198 t
= new_type(prepend_tag_kind((char *)sh
->iss
,
1201 TYPE_CODE(t
) = type_code
;
1202 TYPE_LENGTH(t
) = sh
->value
;
1203 TYPE_NFIELDS(t
) = nfields
;
1204 TYPE_FIELDS(t
) = f
= (struct field
*)
1205 obstack_alloc (¤t_objfile
-> type_obstack
,
1206 nfields
* sizeof (struct field
));
1208 if (type_code
== TYPE_CODE_ENUM
) {
1209 /* This is a non-empty enum. */
1210 for (tsym
= sh
+ 1; tsym
->st
== stMember
; tsym
++) {
1211 struct symbol
*enum_sym
;
1212 f
->bitpos
= tsym
->value
;
1214 f
->name
= (char*)tsym
->iss
;
1217 enum_sym
= (struct symbol
*)
1218 obstack_alloc (¤t_objfile
->symbol_obstack
,
1219 sizeof (struct symbol
));
1220 memset ((PTR
)enum_sym
, 0, sizeof (struct symbol
));
1221 SYMBOL_NAME (enum_sym
) = f
->name
;
1222 SYMBOL_CLASS (enum_sym
) = LOC_CONST
;
1223 SYMBOL_TYPE (enum_sym
) = t
;
1224 SYMBOL_NAMESPACE (enum_sym
) = VAR_NAMESPACE
;
1225 SYMBOL_VALUE (enum_sym
) = tsym
->value
;
1226 add_symbol(enum_sym
, top_stack
->cur_block
);
1228 /* Skip the stMembers that we've handled. */
1234 /* make this the current type */
1235 top_stack
->cur_type
= t
;
1236 top_stack
->cur_field
= 0;
1237 /* Mark that symbol has a type, and say which one */
1238 sh
->value
= (long) t
;
1240 /* beginnning of (code) block. Value of symbol
1241 is the displacement from procedure start */
1242 b
= new_block(top_stack
->maxsyms
);
1243 BLOCK_START(b
) = sh
->value
+ top_stack
->procadr
;
1244 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1245 top_stack
->cur_block
= b
;
1246 add_block(b
, top_stack
->cur_st
);
1250 case stEnd
: /* end (of anything) */
1251 if (sh
->sc
== scInfo
) {
1252 /* Finished with type */
1253 top_stack
->cur_type
= 0;
1254 } else if (sh
->sc
== scText
&&
1255 (top_stack
->blocktype
== stProc
||
1256 top_stack
->blocktype
== stStaticProc
)) {
1257 /* Finished with procedure */
1258 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
1262 BLOCK_END(top_stack
->cur_block
) += sh
->value
; /* size */
1263 got_numargs(top_stack
->procadr
, top_stack
->numargs
);
1264 /* Reallocate symbols, saving memory */
1265 b
= shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1267 /* f77 emits proc-level with address bounds==[0,0],
1268 So look for such child blocks, and patch them. */
1269 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++) {
1270 struct block
*b_bad
= BLOCKVECTOR_BLOCK(bv
,i
);
1271 if (BLOCK_SUPERBLOCK(b_bad
) == b
1272 && BLOCK_START(b_bad
) == top_stack
->procadr
1273 && BLOCK_END(b_bad
) == top_stack
->procadr
) {
1274 BLOCK_START(b_bad
) = BLOCK_START(b
);
1275 BLOCK_END(b_bad
) = BLOCK_END(b
);
1278 } else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
) {
1279 /* End of (code) block. The value of the symbol
1280 is the displacement from the procedure`s start
1281 address of the end of this block. */
1282 BLOCK_END(top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1283 (void) shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1285 pop_parse_stack(); /* restore previous lexical context */
1288 case stMember
: /* member of struct or union */
1289 f
= &TYPE_FIELDS(top_stack
->cur_type
)[top_stack
->cur_field
++];
1290 f
->name
= (char*)sh
->iss
;
1291 f
->bitpos
= sh
->value
;
1293 f
->type
= parse_type(ax
+ sh
->index
, &f
->bitsize
, bigend
);
1296 case stTypedef
: /* type definition */
1297 s
= new_symbol(sh
->iss
);
1298 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1299 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1300 SYMBOL_BLOCK_VALUE(s
) = top_stack
->cur_block
;
1301 add_symbol(s
, top_stack
->cur_block
);
1302 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, 0, bigend
);
1303 sh
->value
= (long) SYMBOL_TYPE(s
);
1306 case stFile
: /* file name */
1308 top_stack
->blocktype
= sh
->st
;
1311 /* I`ve never seen these for C */
1313 break; /* register relocation */
1315 break; /* forwarding address */
1317 break; /* constant */
1319 error("Unknown symbol type %x.", sh
->st
);
1325 /* Parse the type information provided in the raw AX entries for
1326 the symbol SH. Return the bitfield size in BS, in case.
1327 We must byte-swap the AX entries before we use them; BIGEND says whether
1328 they are big-endian or little-endian (from fh->fBigendian). */
1330 static struct type
*
1331 parse_type(ax
, bs
, bigend
)
1336 /* Null entries in this map are treated specially */
1337 static struct type
**map_bt
[] =
1339 &builtin_type_void
, /* btNil */
1341 &builtin_type_char
, /* btChar */
1342 &builtin_type_unsigned_char
, /* btUChar */
1343 &builtin_type_short
, /* btShort */
1344 &builtin_type_unsigned_short
, /* btUShort */
1345 &builtin_type_int
, /* btInt */
1346 &builtin_type_unsigned_int
, /* btUInt */
1347 &builtin_type_long
, /* btLong */
1348 &builtin_type_unsigned_long
, /* btULong */
1349 &builtin_type_float
, /* btFloat */
1350 &builtin_type_double
, /* btDouble */
1357 &builtin_type_complex
, /* btComplex */
1358 &builtin_type_double_complex
, /* btDComplex */
1360 &builtin_type_fixed_dec
, /* btFixedDec */
1361 &builtin_type_float_dec
, /* btFloatDec */
1362 &builtin_type_string
, /* btString */
1365 &builtin_type_void
, /* btVoid */
1369 struct type
*tp
= 0;
1374 /* Use aux as a type information record, map its basic type. */
1376 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1377 if (t
->bt
> (sizeof (map_bt
)/sizeof (*map_bt
))) {
1378 complain (&basic_type_complaint
, t
->bt
);
1379 return builtin_type_int
;
1381 if (map_bt
[t
->bt
]) {
1382 tp
= *map_bt
[t
->bt
];
1386 /* Cannot use builtin types -- build our own */
1389 tp
= lookup_pointer_type (builtin_type_void
);
1393 type_code
= TYPE_CODE_STRUCT
;
1397 type_code
= TYPE_CODE_UNION
;
1401 type_code
= TYPE_CODE_ENUM
;
1405 type_code
= TYPE_CODE_RANGE
;
1409 type_code
= TYPE_CODE_SET
;
1414 complain (&basic_type_complaint
, t
->bt
);
1415 return builtin_type_int
;
1419 /* Skip over any further type qualifiers (FIXME). */
1421 /* This is the way it would work if the compiler worked */
1425 ecoff_swap_tir_in (bigend
, ax
, t1
);
1426 } while (t1
->continued
);
1429 /* Move on to next aux */
1433 *bs
= AUX_GET_WIDTH (bigend
, ax
);
1437 /* All these types really point to some (common) MIPS type
1438 definition, and only the type-qualifiers fully identify
1439 them. We'll make the same effort at sharing. */
1440 if (t
->bt
== btIndirect
||
1441 t
->bt
== btStruct
||
1444 t
->bt
== btTypedef
||
1447 char name
[256], *pn
;
1449 /* Try to cross reference this type */
1450 ax
+= cross_ref(ax
, &tp
, type_code
, &pn
, bigend
);
1451 /* reading .o file ? */
1452 if (UNSAFE_DATA_ADDR(tp
))
1453 tp
= init_type(type_code
, 0, 0, 0, (struct objfile
*) NULL
);
1454 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1455 sprintf(name
, fmt
, pn
);
1457 /* Usually, TYPE_CODE(tp) is already type_code. The main
1458 exception is if we guessed wrong re struct/union/enum. */
1459 if (TYPE_CODE(tp
) != type_code
) {
1460 complain (&bad_tag_guess_complaint
, 0);
1461 TYPE_CODE(tp
) = type_code
;
1463 if (TYPE_NAME(tp
) == NULL
|| strcmp(TYPE_NAME(tp
), name
) != 0)
1464 TYPE_NAME(tp
) = obsavestring(name
, strlen(name
),
1465 ¤t_objfile
-> type_obstack
);
1468 /* Deal with range types */
1469 if (t
->bt
== btRange
) {
1470 TYPE_NFIELDS (tp
) = 2;
1472 (struct field
*) obstack_alloc (¤t_objfile
-> type_obstack
,
1473 2 * sizeof (struct field
));
1474 TYPE_FIELD_NAME (tp
, 0) = obsavestring ("Low", strlen ("Low"),
1475 ¤t_objfile
-> type_obstack
);
1476 TYPE_FIELD_BITPOS (tp
, 0) = AUX_GET_DNLOW (bigend
, ax
);
1478 TYPE_FIELD_NAME (tp
, 1) = obsavestring ("High", strlen ("High"),
1479 ¤t_objfile
-> type_obstack
);
1480 TYPE_FIELD_BITPOS (tp
, 1) = AUX_GET_DNHIGH (bigend
, ax
);
1484 /* Parse all the type qualifiers now. If there are more
1485 than 6 the game will continue in the next aux */
1487 #define PARSE_TQ(tq) \
1488 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, bigend);
1490 again
: PARSE_TQ(tq0
);
1500 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1506 /* Make up a complex type from a basic one. Type is passed by
1507 reference in TPP and side-effected as necessary. The type
1508 qualifier TQ says how to handle the aux symbols at AX for
1509 the symbol SX we are currently analyzing. BIGEND says whether
1510 aux symbols are big-endian or little-endian.
1511 Returns the number of aux symbols we parsed. */
1514 upgrade_type(tpp
, tq
, ax
, bigend
)
1523 /* Used in array processing */
1532 t
= lookup_pointer_type (*tpp
);
1537 t
= lookup_function_type (*tpp
);
1543 t
= init_type(TYPE_CODE_ARRAY
, 0, 0, 0, (struct objfile
*) NULL
);
1544 TYPE_TARGET_TYPE(t
) = *tpp
;
1546 /* Determine and record the domain type (type of index) */
1547 ecoff_swap_rndx_in (bigend
, ax
, &rndx
);
1552 rf
= AUX_GET_ISYM (bigend
, ax
);
1555 fh
= get_rfd(cur_fd
, rf
);
1557 /* Fields are kept in an array */
1558 /* FIXME - Memory leak! */
1559 if (TYPE_NFIELDS(t
))
1560 TYPE_FIELDS(t
) = (struct field
*)
1561 xrealloc((PTR
) TYPE_FIELDS(t
),
1562 (TYPE_NFIELDS(t
)+1) * sizeof(struct field
));
1564 TYPE_FIELDS(t
) = (struct field
*)
1565 xzalloc(sizeof(struct field
));
1566 f
= &(TYPE_FIELD(t
,TYPE_NFIELDS(t
)));
1568 memset((PTR
)f
, 0, sizeof(struct field
));
1570 /* XXX */ f
->type
= parse_type(id
+ (union aux_ext
*)fh
->iauxBase
,
1571 &f
->bitsize
, bigend
);
1574 lower
= AUX_GET_DNLOW (bigend
, ax
);
1576 upper
= AUX_GET_DNHIGH (bigend
, ax
);
1578 rf
= AUX_GET_WIDTH (bigend
, ax
); /* bit size of array element */
1580 /* Check whether supplied array element bit size matches
1581 the known size of the element type. If this complaint
1582 ends up not happening, we can remove this code. It's
1583 here because we aren't sure we understand this *&%&$
1585 id
= TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) << 3; /* bitsize */
1587 /* Most likely an undefined type */
1589 TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) = id
>> 3;
1592 complain (&array_bitsize_complaint
, rf
);
1594 TYPE_LENGTH(t
) = (upper
< 0) ? 0 :
1595 (upper
- lower
+ 1) * (rf
>> 3);
1600 /* Volatile -- currently ignored */
1604 complain (&unknown_type_qual_complaint
, tq
);
1610 /* Parse a procedure descriptor record PR. Note that the procedure
1611 is parsed _after_ the local symbols, now we just make up the
1612 extra information we need into a special symbol that we insert
1613 in the procedure's main block. Note also that images that
1614 have been partially stripped (ld -x) have been deprived
1615 of local symbols, and we have to cope with them here.
1616 The procedure's code ends at BOUND */
1619 parse_procedure(pr
, bound
)
1622 struct symbol
*s
, *i
;
1623 SYMR
*sh
= (SYMR
*)pr
->isym
;
1625 struct mips_extra_func_info
*e
;
1629 /* Reuse the MIPS record */
1630 e
= (struct mips_extra_func_info
*) pr
;
1631 e
->numargs
= lookup_numargs(pr
->adr
);
1633 /* Make up our special symbol */
1634 i
= new_symbol(".gdbinfo.");
1635 SYMBOL_VALUE(i
) = (int)e
;
1636 SYMBOL_NAMESPACE(i
) = LABEL_NAMESPACE
;
1637 SYMBOL_CLASS(i
) = LOC_CONST
;
1638 SYMBOL_TYPE(i
) = builtin_type_void
;
1640 /* Make up a name for static procedures. Sigh. */
1641 if (sh
== (SYMR
*)-1) {
1642 sprintf(name
,".static_procedure@%x",pr
->adr
);
1643 sh_name
= savestring(name
, strlen(name
));
1647 sh_name
= (char*)sh
->iss
;
1648 s
= mylookup_symbol(sh_name
, top_stack
->cur_block
,
1649 VAR_NAMESPACE
, LOC_BLOCK
);
1652 b
= SYMBOL_BLOCK_VALUE(s
);
1654 s
= new_symbol(sh_name
);
1655 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1656 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1657 /* Donno its type, hope int is ok */
1658 SYMBOL_TYPE(s
) = lookup_function_type (builtin_type_int
);
1659 add_symbol(s
, top_stack
->cur_block
);
1660 /* Wont have symbols for this one */
1662 SYMBOL_BLOCK_VALUE(s
) = b
;
1663 BLOCK_FUNCTION(b
) = s
;
1664 BLOCK_START(b
) = pr
->adr
;
1665 BLOCK_END(b
) = bound
;
1666 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1667 add_block(b
, top_stack
->cur_st
);
1673 /* Parse the external symbol ES. Just call parse_symbol() after
1674 making sure we know where the aux are for it. For procedures,
1675 parsing of the PDRs has already provided all the needed
1676 information, we only parse them if SKIP_PROCEDURES is false,
1677 and only if this causes no symbol duplication.
1678 BIGEND says whether aux entries are big-endian or little-endian.
1680 This routine clobbers top_stack->cur_block and ->cur_st. */
1683 parse_external(es
, skip_procedures
, bigend
)
1685 int skip_procedures
;
1690 if (es
->ifd
!= ifdNil
) {
1692 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
) + cur_fd
;
1693 ax
= (union aux_ext
*)cur_fdr
->iauxBase
;
1695 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
);
1698 top_stack
->cur_st
= cur_stab
;
1699 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
1702 /* Reading .o files */
1703 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
) {
1705 switch (es
->asym
.st
) {
1707 case stProc
: what
= "procedure"; n_undef_procs
++; break;
1708 case stGlobal
: what
= "variable"; n_undef_vars
++; break;
1709 case stLabel
: what
= "label"; n_undef_labels
++; break;
1710 default : what
= "symbol"; break;
1714 printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what
,
1715 es
->asym
.iss
, fdr_name((char *)cur_fdr
->rss
));
1719 switch (es
->asym
.st
) {
1721 /* If we have full symbols we do not need more */
1722 if (skip_procedures
)
1724 if (mylookup_symbol (es
->asym
.iss
, top_stack
->cur_block
,
1725 VAR_NAMESPACE
, LOC_BLOCK
))
1731 * Note that the case of a symbol with indexNil
1732 * must be handled anyways by parse_symbol().
1734 parse_symbol(&es
->asym
, ax
, bigend
);
1741 /* Parse the line number info for file descriptor FH into
1742 GDB's linetable LT. MIPS' encoding requires a little bit
1743 of magic to get things out. Note also that MIPS' line
1744 numbers can go back and forth, apparently we can live
1745 with that and do not need to reorder our linetables */
1750 struct linetable
*lt
;
1752 unsigned char *base
= (unsigned char*)fh
->cbLineOffset
;
1754 int delta
, count
, lineno
= 0;
1760 /* Scan by procedure descriptors */
1762 for (pr
= (PDR
*)IPDFIRST(cur_hdr
,fh
); j
< fh
->cpd
; j
++, pr
++) {
1765 /* No code for this one */
1766 if (pr
->iline
== ilineNil
||
1767 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1770 * Aurgh! To know where to stop expanding we
1773 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1774 if (pr
[l
].iline
!= -1)
1776 if (l
== (fh
->cpd
- j
))
1781 * When procedures are moved around the linenumbers
1782 * are attributed to the next procedure up
1784 if (pr
->iline
>= halt
) continue;
1786 base
= (unsigned char*)pr
->cbLineOffset
;
1787 l
= pr
->adr
>> 2; /* in words */
1788 halt
+= (pr
->adr
>> 2) - pr
->iline
;
1789 for (lineno
= pr
->lnLow
; l
< halt
;) {
1790 count
= *base
& 0x0f;
1791 delta
= *base
++ >> 4;
1795 delta
= (base
[0] << 8) | base
[1];
1796 if (delta
>= 0x8000)
1800 lineno
+= delta
;/* first delta is 0 */
1801 k
= add_line(lt
, lineno
, l
, k
);
1808 /* Master parsing procedure for first-pass reading of file symbols
1809 into a partial_symtab.
1811 Parses the symtab described by the global symbolic header CUR_HDR.
1812 END_OF_TEXT_SEG gives the address just after the text segment for
1813 the symtab we are reading. */
1816 parse_partial_symbols(end_of_text_seg
, objfile
)
1817 int end_of_text_seg
;
1818 struct objfile
*objfile
;
1821 /* int stat_idx, h_max;*/
1822 HDRR
*hdr
= cur_hdr
;
1823 /* Running pointers */
1827 struct partial_symtab
*pst
;
1829 int past_first_source_file
= 0;
1831 /* List of current psymtab's include files */
1832 char **psymtab_include_list
;
1833 int includes_allocated
;
1836 struct pst_map
* fdr_to_pst
;
1837 /* Index within current psymtab dependency list */
1838 struct partial_symtab
**dependency_list
;
1839 int dependencies_used
, dependencies_allocated
;
1840 struct cleanup
*old_chain
;
1842 extern_tab
= (EXTR
**)obstack_alloc (&objfile
->psymbol_obstack
,
1843 sizeof(EXTR
*) * hdr
->iextMax
);
1845 includes_allocated
= 30;
1847 psymtab_include_list
= (char **) alloca (includes_allocated
*
1849 next_symbol_text_func
= mips_next_symbol_text
;
1851 dependencies_allocated
= 30;
1852 dependencies_used
= 0;
1854 (struct partial_symtab
**) alloca (dependencies_allocated
*
1855 sizeof (struct partial_symtab
*));
1857 last_source_file
= 0;
1862 * Only parse the Local and External symbols, and the Relative FDR.
1863 * Fixup enough of the loader symtab to be able to use it.
1864 * Allocate space only for the file's portions we need to
1869 max_glevel
= MIN_GLEVEL
;
1871 /* Allocate the map FDR -> PST.
1872 Minor hack: -O3 images might claim some global data belongs
1873 to FDR -1. We`ll go along with that */
1874 fdr_to_pst
= (struct pst_map
*)xzalloc((hdr
->ifdMax
+1) * sizeof *fdr_to_pst
);
1875 old_chain
= make_cleanup (free
, fdr_to_pst
);
1878 struct partial_symtab
* pst
= new_psymtab("", objfile
);
1879 fdr_to_pst
[-1].pst
= pst
;
1883 /* Pass 1 over external syms: Presize and partition the list */
1884 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1885 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1886 fdr_to_pst
[esh
->ifd
].n_globals
++;
1889 /* Pass 1.5 over files: partition out global symbol space */
1891 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++) {
1892 fdr_to_pst
[f_idx
].globals_offset
= s_idx
;
1893 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
1894 fdr_to_pst
[f_idx
].n_globals
= 0;
1897 /* Pass 2 over external syms: fill in external symbols */
1898 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1899 enum minimal_symbol_type ms_type
= mst_text
;
1900 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1902 extern_tab
[fdr_to_pst
[esh
->ifd
].globals_offset
1903 + fdr_to_pst
[esh
->ifd
].n_globals
++] = esh
;
1905 if (esh
->asym
.sc
== scUndefined
|| esh
->asym
.sc
== scNil
)
1908 switch (esh
->asym
.st
) {
1917 ms_type
= mst_unknown
;
1918 complain (&unknown_ext_complaint
,
1919 (char *)(esh
->asym
.iss
));
1921 prim_record_minimal_symbol ((char *)esh
->asym
.iss
,
1926 /* Pass 3 over files, over local syms: fill in static symbols */
1927 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
1928 struct partial_symtab
*save_pst
;
1930 cur_fdr
= fh
= f_idx
+ (FDR
*)(cur_hdr
->cbFdOffset
);
1932 if (fh
->csym
== 0) {
1933 fdr_to_pst
[f_idx
].pst
= NULL
;
1936 pst
= start_psymtab_common (objfile
, 0, (char*)fh
->rss
,
1937 fh
->cpd
? fh
->adr
: 0,
1938 objfile
->global_psymbols
.next
,
1939 objfile
->static_psymbols
.next
);
1940 pst
->read_symtab_private
= (char *)
1941 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
1944 /* Make everything point to everything. */
1945 FDR_IDX(pst
) = f_idx
;
1946 fdr_to_pst
[f_idx
].pst
= pst
;
1947 fh
->ioptBase
= (int)pst
;
1949 CUR_HDR(pst
) = cur_hdr
;
1951 /* The way to turn this into a symtab is to call... */
1952 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
1954 pst
->texthigh
= pst
->textlow
;
1956 #if 0 /* This is done in start_psymtab_common */
1957 pst
->globals_offset
= global_psymbols
.next
- global_psymbols
.list
;
1958 pst
->statics_offset
= static_psymbols
.next
- static_psymbols
.list
;
1960 pst
->n_global_syms
= 0;
1961 pst
->n_static_syms
= 0;
1964 /* The second symbol must be @stab.
1965 This symbol is emitted by mips-tfile to signal
1966 that the current object file uses encapsulated stabs
1967 instead of mips ecoff for local symbols.
1968 (It is the second symbol because the first symbol is
1969 the stFile used to signal the start of a file). */
1971 && strcmp((char *)(((SYMR
*)fh
->isymBase
)[1].iss
),
1972 stabs_symbol
) == 0) {
1973 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++) {
1976 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
1977 type_code
= MIPS_UNMARK_STAB(sh
->index
);
1978 if (!MIPS_IS_STAB(sh
)) {
1979 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
) {
1980 long procaddr
= sh
->value
;
1981 sh
= AUX_GET_ISYM (fh
->fBigendian
,
1982 sh
->index
+ (union aux_ext
*)(fh
->iauxBase
))
1983 + (SYMR
*) fh
->isymBase
- 1;
1984 if (sh
->st
== stEnd
) {
1985 long high
= procaddr
+ sh
->value
;
1986 if (high
> pst
->texthigh
)
1987 pst
->texthigh
= high
;
1992 #define SET_NAMESTRING() namestring = (char*)sh->iss
1993 #define CUR_SYMBOL_TYPE type_code
1994 #define CUR_SYMBOL_VALUE sh->value
1995 #define START_PSYMTAB(ofile,addr,fname,low,symoff,global_syms,static_syms)\
1997 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
1998 #define addr 0 /* FIXME, should be offset of addresses */
1999 #define HANDLE_RBRAC(val) \
2000 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
2001 #include "partial-stab.h"
2006 register struct partial_symbol
*psym
;
2007 for (cur_sdx
= 0; cur_sdx
< fh
->csym
; ) {
2010 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
2012 if (MIPS_IS_STAB(sh
)) {
2017 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
2018 sh
->index
== 0xfffff) {
2019 /* FIXME, premature? */
2024 name
= (char *)(sh
->iss
);
2029 case stProc
: /* Asm labels apparently */
2030 case stStaticProc
: /* Function */
2031 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
2032 VAR_NAMESPACE
, LOC_BLOCK
,
2033 objfile
->static_psymbols
, sh
->value
);
2034 /* Skip over procedure to next one. */
2035 cur_sdx
= AUX_GET_ISYM (fh
->fBigendian
,
2036 sh
->index
+ (union aux_ext
*)fh
->iauxBase
);
2037 procaddr
= sh
->value
;
2039 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
- 1;
2040 if (sh
->st
!= stEnd
)
2042 high
= procaddr
+ sh
->value
;
2043 if (high
> pst
->texthigh
)
2044 pst
->texthigh
= high
;
2046 case stStatic
: /* Variable */
2049 case stTypedef
: /* Typedef */
2050 class = LOC_TYPEDEF
;
2052 case stConstant
: /* Constant decl */
2055 case stBlock
: /* { }, str, un, enum*/
2056 if (sh
->sc
== scInfo
) {
2057 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
2058 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2059 objfile
->static_psymbols
, sh
->value
);
2061 /* Skip over the block */
2062 cur_sdx
= sh
->index
;
2064 case stFile
: /* File headers */
2065 case stLabel
: /* Labels */
2066 case stEnd
: /* Ends of files */
2069 /* Both complaints are valid: one gives symbol name,
2070 the other the offending symbol type. */
2071 complain (&unknown_sym_complaint
, (char *)sh
->iss
);
2072 complain (&unknown_st_complaint
, sh
->st
);
2076 /* Use this gdb symbol */
2077 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
2078 VAR_NAMESPACE
, class,
2079 objfile
->static_psymbols
, sh
->value
);
2081 cur_sdx
++; /* Go to next file symbol */
2084 /* Now do enter the external symbols. */
2085 ext_ptr
= &extern_tab
[fdr_to_pst
[f_idx
].globals_offset
];
2086 cur_sdx
= fdr_to_pst
[f_idx
].n_globals
;
2087 PST_PRIVATE(save_pst
)->extern_count
= cur_sdx
;
2088 PST_PRIVATE(save_pst
)->extern_tab
= ext_ptr
;
2089 for (; --cur_sdx
>= 0; ext_ptr
++) {
2090 enum address_class
class;
2091 if ((*ext_ptr
)->ifd
!= f_idx
)
2093 sh
= &(*ext_ptr
)->asym
;
2102 complain (&unknown_ext_complaint
, sh
->iss
);
2107 if (objfile
->global_psymbols
.next
>=
2108 objfile
->global_psymbols
.list
+ objfile
->global_psymbols
.size
)
2109 extend_psymbol_list (&objfile
->global_psymbols
, objfile
);
2110 psym
= objfile
->global_psymbols
.next
++;
2111 SYMBOL_NAME (psym
) = (char*)sh
->iss
;
2112 SYMBOL_NAMESPACE (psym
) = VAR_NAMESPACE
;
2113 SYMBOL_CLASS (psym
) = class;
2114 SYMBOL_VALUE_ADDRESS (psym
) = (CORE_ADDR
)sh
->value
;
2118 end_psymtab (save_pst
, psymtab_include_list
, includes_used
,
2119 -1, save_pst
->texthigh
,
2120 dependency_list
, dependencies_used
);
2121 if (objfile
-> ei
.entry_point
>= save_pst
->textlow
&&
2122 objfile
-> ei
.entry_point
< save_pst
->texthigh
)
2124 objfile
-> ei
.entry_file_lowpc
= save_pst
->textlow
;
2125 objfile
-> ei
.entry_file_highpc
= save_pst
->texthigh
;
2129 /* Mark the last code address, and remember it for later */
2130 hdr
->cbDnOffset
= end_of_text_seg
;
2132 /* Now scan the FDRs for dependencies */
2133 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
2135 fh
= f_idx
+ (FDR
*)(cur_hdr
->cbFdOffset
);
2136 pst
= fdr_to_pst
[f_idx
].pst
;
2138 /* This should catch stabs-in-ecoff. */
2142 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
2143 /* ...then presumably a .h file: drop reverse depends .h->.c */
2144 for (; s_id0
< fh
->crfd
; s_id0
++) {
2145 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
2147 s_id0
++; /* Skip self-dependency */
2152 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2153 pst
->dependencies
= (struct partial_symtab
**)
2154 obstack_alloc (&objfile
->psymbol_obstack
,
2155 pst
->number_of_dependencies
*
2156 sizeof (struct partial_symtab
*));
2157 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
2158 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
2159 if (*rh
< 0 || *rh
>= hdr
->ifdMax
)
2160 complain(&bad_file_number_complaint
, *rh
);
2162 pst
->dependencies
[s_idx
-s_id0
] = fdr_to_pst
[*rh
].pst
;
2165 do_cleanups (old_chain
);
2170 /* Do the initial analisys of the F_IDX-th file descriptor.
2171 Allocates a partial symtab for it, and builds the list
2172 of dependent files by recursion. LEV says at which level
2173 of recursion we are called (to pretty up debug traces) */
2175 static struct partial_symtab
*
2176 parse_fdr(f_idx
, lev
, objfile
)
2179 struct objfile
*objfile
;
2182 register struct partial_symtab
*pst
;
2185 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + f_idx
;
2187 /* Use this to indicate into which symtab this file was parsed */
2189 return (struct partial_symtab
*) fh
->ioptBase
;
2191 /* Debuggability level */
2192 if (compare_glevel(max_glevel
, fh
->glevel
) < 0)
2193 max_glevel
= fh
->glevel
;
2195 /* Make a new partial_symtab */
2196 pst
= new_psymtab(fh
->rss
, objfile
);
2201 pst
->textlow
= fh
->adr
;
2202 pst
->texthigh
= fh
->cpd
; /* To be fixed later */
2205 /* Make everything point to everything. */
2206 FDR_IDX(pst
) = f_idx
;
2207 fdr_to_pst
[f_idx
].pst
= pst
;
2208 fh
->ioptBase
= (int)pst
;
2210 /* Analyze its dependencies */
2215 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
2216 /* ...then presumably a .h file: drop reverse depends .h->.c */
2217 for (; s_id0
< fh
->crfd
; s_id0
++) {
2218 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
2220 s_id0
++; /* Skip self-dependency */
2225 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2226 pst
->dependencies
= (struct partial_symtab
**)
2227 obstack_alloc (&objfile
->psymbol_obstack
,
2228 pst
->number_of_dependencies
*
2229 sizeof (struct partial_symtab
*));
2230 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
2231 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
2233 pst
->dependencies
[s_idx
-s_id0
] = parse_fdr(*rh
, lev
+1, objfile
);
2241 mips_next_symbol_text ()
2244 return (char*)((SYMR
*)cur_fdr
->isymBase
)[cur_sdx
].iss
;
2247 /* Ancillary function to psymtab_to_symtab(). Does all the work
2248 for turning the partial symtab PST into a symtab, recurring
2249 first on all dependent psymtabs. The argument FILENAME is
2250 only passed so we can see in debug stack traces what file
2254 psymtab_to_symtab_1(pst
, filename
)
2255 struct partial_symtab
*pst
;
2263 struct linetable
*lines
;
2269 /* How many symbols will we need */
2270 /* FIXME, this does not count enum values. */
2271 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
2272 if (FDR_IDX(pst
) == -1) {
2276 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + FDR_IDX(pst
);
2277 f_max
+= fh
->csym
+ fh
->cpd
;
2278 maxlines
= 2 * fh
->cline
;
2281 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2284 && strcmp((char *)(((SYMR
*)fh
->isymBase
)[1].iss
), stabs_symbol
)
2289 st
= new_symtab (pst
->filename
, 2 * f_max
, maxlines
,
2292 st
= new_symtab ("unknown", f_max
, 0, pst
->objfile
);
2293 lines
= LINETABLE(st
);
2294 pending_list
= (struct mips_pending
**) cur_hdr
->cbOptOffset
;
2295 if (pending_list
== 0) {
2296 pending_list
= (struct mips_pending
**)
2297 xzalloc(cur_hdr
->ifdMax
* sizeof(struct mips_pending
*));
2298 cur_hdr
->cbOptOffset
= (int)pending_list
;
2302 /* Read in all partial symbtabs on which this one is dependent.
2303 NOTE that we do have circular dependencies, sigh. We solved
2304 that by setting pst->readin before this point. */
2306 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2307 if (!pst
->dependencies
[i
]->readin
) {
2308 /* Inform about additional files to be read in. */
2311 fputs_filtered (" ", stdout
);
2313 fputs_filtered ("and ", stdout
);
2315 printf_filtered ("%s...",
2316 pst
->dependencies
[i
]->filename
);
2317 wrap_here (""); /* Flush output */
2320 /* We only pass the filename for debug purposes */
2321 psymtab_to_symtab_1(pst
->dependencies
[i
],
2322 pst
->dependencies
[i
]->filename
);
2326 /* Now read the symbols for this symtab */
2328 current_objfile
= pst
-> objfile
;
2330 cur_fd
= FDR_IDX(pst
);
2333 /* Get a new lexical context */
2336 top_stack
->cur_st
= cur_stab
;
2337 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab
),
2339 BLOCK_START(top_stack
->cur_block
) = fh
? fh
->adr
: 0;
2340 BLOCK_END(top_stack
->cur_block
) = 0;
2341 top_stack
->blocktype
= stFile
;
2342 top_stack
->maxsyms
= 2*f_max
;
2343 top_stack
->cur_type
= 0;
2344 top_stack
->procadr
= 0;
2345 top_stack
->numargs
= 0;
2348 /* Parse locals and procedures */
2353 /* Parse local symbols first */
2358 current_objfile
= NULL
;
2361 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++) {
2362 register SYMR
*sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
2363 char *name
= (char*)sh
->iss
;
2364 CORE_ADDR valu
= sh
->value
;
2365 if (MIPS_IS_STAB(sh
)) {
2366 int type_code
= MIPS_UNMARK_STAB(sh
->index
);
2367 process_one_symbol (type_code
, 0, valu
, name
, /*FIXME*/ 0);
2369 else if (sh
->st
== stLabel
&& sh
->index
!= indexNil
) {
2370 /* Handle encoded stab line number. */
2371 record_line (current_subfile
, sh
->index
, valu
);
2374 st
= end_symtab (pst
->texthigh
, 0, 0, pst
->objfile
);
2377 /* BOUND is the highest core address of this file's procedures */
2378 int bound
= cur_fd
== cur_hdr
->ifdMax
- 1 ? cur_hdr
->cbDnOffset
2380 for (cur_sdx
= 0; cur_sdx
< fh
->csym
; ) {
2381 sh
= (SYMR
*) (fh
->isymBase
) + cur_sdx
;
2382 cur_sdx
+= parse_symbol(sh
, (union aux_ent
*)fh
->iauxBase
,
2386 /* Procedures next, note we need to look-ahead to
2387 find out where the procedure's code ends */
2390 for (i
= 0; i
< fh
->cpd
-1; i
++) {
2391 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2392 parse_procedure(pr
, pr
[1].adr
); /* next proc up */
2395 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2396 parse_procedure(pr
, bound
); /* next file up */
2398 /* Linenumbers. At the end, check if we can save memory */
2399 parse_lines(fh
, lines
);
2400 if (lines
->nitems
< fh
->cline
)
2401 lines
= shrink_linetable(lines
);
2407 LINETABLE(st
) = lines
;
2409 /* .. and our share of externals.
2410 XXX use the global list to speed up things here. how ?
2411 FIXME, Maybe quit once we have found the right number of ext's? */
2412 /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
2413 top_stack
->blocktype
= stFile
;
2414 top_stack
->maxsyms
=
2415 cur_hdr
->isymMax
+ cur_hdr
->ipdMax
+ cur_hdr
->iextMax
;
2417 ext_ptr
= PST_PRIVATE(pst
)->extern_tab
;
2418 for (i
= PST_PRIVATE(pst
)->extern_count
; --i
>= 0; ext_ptr
++)
2419 parse_external(*ext_ptr
, 1, fh
->fBigendian
);
2421 /* If there are undefined, tell the user */
2422 if (n_undef_symbols
) {
2423 printf_filtered("File %s contains %d unresolved references:",
2424 st
->filename
, n_undef_symbols
);
2425 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2426 n_undef_vars
, n_undef_procs
, n_undef_labels
);
2427 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
2433 /* Sort the symbol table now, we are done adding symbols to it.*/
2434 sort_symtab_syms(st
);
2438 /* Now link the psymtab and the symtab. */
2441 current_objfile
= NULL
;
2444 /* Ancillary parsing procedures. */
2446 /* Lookup the type at relative index RN. Return it in TPP
2447 if found and in any event come up with its name PNAME.
2448 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
2449 Return value says how many aux symbols we ate. */
2452 cross_ref(ax
, tpp
, type_code
, pname
, bigend
)
2455 int type_code
; /* Use to alloc new type if none is found. */
2463 ecoff_swap_rndx_in (bigend
, ax
, rn
);
2465 /* Escape index means 'the next one' */
2466 if (rn
->rfd
== 0xfff) {
2468 rf
= AUX_GET_ISYM (bigend
, ax
+ 1);
2475 *pname
= "<undefined>";
2478 * Find the relative file descriptor and the symbol in it
2480 FDR
*fh
= get_rfd(cur_fd
, rf
);
2485 * If we have processed this symbol then we left a forwarding
2486 * pointer to the corresponding GDB symbol. If not, we`ll put
2487 * it in a list of pending symbols, to be processed later when
2488 * the file f will be. In any event, we collect the name for
2489 * the type here. Which is why we made a first pass at
2492 sh
= (SYMR
*) (fh
->isymBase
) + rn
->index
;
2494 /* Careful, we might be looking at .o files */
2495 *pname
= (UNSAFE_DATA_ADDR(sh
->iss
)) ? "<undefined>" :
2498 /* Have we parsed it ? */
2499 if ((!UNSAFE_DATA_ADDR(sh
->value
)) && (sh
->st
== stParsed
)) {
2500 t
= (struct type
*) sh
->value
;
2503 /* Avoid duplicates */
2504 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
2508 *tpp
= init_type(type_code
, 0, 0, 0, (struct objfile
*) NULL
);
2509 add_pending(fh
, sh
, *tpp
);
2514 /* We used one auxent normally, two if we got a "next one" rf. */
2519 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2520 keeping the symtab sorted */
2522 static struct symbol
*
2523 mylookup_symbol (name
, block
, namespace, class)
2525 register struct block
*block
;
2526 enum namespace namespace;
2527 enum address_class
class;
2529 register int bot
, top
, inc
;
2530 register struct symbol
*sym
;
2533 top
= BLOCK_NSYMS(block
);
2536 sym
= BLOCK_SYM(block
, bot
);
2537 if (SYMBOL_NAME(sym
)[0] == inc
2538 && SYMBOL_NAMESPACE(sym
) == namespace
2539 && SYMBOL_CLASS(sym
) == class
2540 && !strcmp(SYMBOL_NAME(sym
), name
))
2544 block
= BLOCK_SUPERBLOCK (block
);
2546 return mylookup_symbol (name
, block
, namespace, class);
2551 /* Add a new symbol S to a block B.
2552 Infrequently, we will need to reallocate the block to make it bigger.
2553 We only detect this case when adding to top_stack->cur_block, since
2554 that's the only time we know how big the block is. FIXME. */
2561 int nsyms
= BLOCK_NSYMS(b
)++;
2562 struct block
*origb
;
2563 struct parse_stack
*stackp
;
2565 if (b
== top_stack
->cur_block
&&
2566 nsyms
>= top_stack
->maxsyms
) {
2567 complain (&block_overflow_complaint
, s
->name
);
2568 /* In this case shrink_block is actually grow_block, since
2569 BLOCK_NSYMS(b) is larger than its current size. */
2571 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
2573 /* Now run through the stack replacing pointers to the
2574 original block. shrink_block has already done this
2575 for the blockvector and BLOCK_FUNCTION. */
2576 for (stackp
= top_stack
; stackp
; stackp
= stackp
->next
) {
2577 if (stackp
->cur_block
== origb
) {
2578 stackp
->cur_block
= b
;
2579 stackp
->maxsyms
= BLOCK_NSYMS (b
);
2583 BLOCK_SYM(b
,nsyms
) = s
;
2586 /* Add a new block B to a symtab S */
2593 struct blockvector
*bv
= BLOCKVECTOR(s
);
2595 bv
= (struct blockvector
*)xrealloc((PTR
) bv
,
2596 sizeof(struct blockvector
) +
2597 BLOCKVECTOR_NBLOCKS(bv
)
2598 * sizeof(bv
->block
));
2599 if (bv
!= BLOCKVECTOR(s
))
2600 BLOCKVECTOR(s
) = bv
;
2602 BLOCKVECTOR_BLOCK(bv
, BLOCKVECTOR_NBLOCKS(bv
)++) = b
;
2605 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2606 MIPS' linenumber encoding might need more than one byte
2607 to describe it, LAST is used to detect these continuation lines */
2610 add_line(lt
, lineno
, adr
, last
)
2611 struct linetable
*lt
;
2617 last
= -2; /* make sure we record first line */
2619 if (last
== lineno
) /* skip continuation lines */
2622 lt
->item
[lt
->nitems
].line
= lineno
;
2623 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
2627 /* Sorting and reordering procedures */
2629 /* Blocks with a smaller low bound should come first */
2632 compare_blocks(b1
, b2
)
2633 struct block
**b1
, **b2
;
2635 register int addr_diff
;
2637 addr_diff
= (BLOCK_START((*b1
))) - (BLOCK_START((*b2
)));
2639 return (BLOCK_END((*b1
))) - (BLOCK_END((*b2
)));
2643 /* Sort the blocks of a symtab S.
2644 Reorder the blocks in the blockvector by code-address,
2645 as required by some MI search routines */
2651 struct blockvector
*bv
= BLOCKVECTOR(s
);
2653 if (BLOCKVECTOR_NBLOCKS(bv
) <= 2) {
2655 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) == 0)
2656 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = 0;
2657 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) == 0)
2658 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) = 0;
2662 * This is very unfortunate: normally all functions are compiled in
2663 * the order they are found, but if the file is compiled -O3 things
2664 * are very different. It would be nice to find a reliable test
2665 * to detect -O3 images in advance.
2667 if (BLOCKVECTOR_NBLOCKS(bv
) > 3)
2668 qsort(&BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
),
2669 BLOCKVECTOR_NBLOCKS(bv
) - FIRST_LOCAL_BLOCK
,
2670 sizeof(struct block
*),
2674 register CORE_ADDR high
= 0;
2675 register int i
, j
= BLOCKVECTOR_NBLOCKS(bv
);
2677 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
2678 if (high
< BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
)))
2679 high
= BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
));
2680 BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = high
;
2683 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) =
2684 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
));
2686 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2687 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2688 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2689 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2693 /* Constructor/restructor/destructor procedures */
2695 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2696 MAXSYMS and linenumbers MAXLINES we'll put in it */
2700 new_symtab(name
, maxsyms
, maxlines
, objfile
)
2704 struct objfile
*objfile
;
2706 struct symtab
*s
= allocate_symtab (name
, objfile
);
2708 LINETABLE(s
) = new_linetable(maxlines
);
2710 /* All symtabs must have at least two blocks */
2711 BLOCKVECTOR(s
) = new_bvect(2);
2712 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
) = new_block(maxsyms
);
2713 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), STATIC_BLOCK
) = new_block(maxsyms
);
2714 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
),STATIC_BLOCK
)) =
2715 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
);
2717 s
->free_code
= free_linetable
;
2722 /* Allocate a new partial_symtab NAME */
2724 static struct partial_symtab
*
2725 new_psymtab(name
, objfile
)
2727 struct objfile
*objfile
;
2729 struct partial_symtab
*psymtab
;
2731 /* FIXME -- why (char *) -1 rather than NULL? */
2732 psymtab
= allocate_psymtab (name
== (char *) -1 ? "<no name>" : name
,
2735 /* Keep a backpointer to the file's symbols */
2737 psymtab
-> read_symtab_private
= (char *)
2738 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
2739 CUR_HDR(psymtab
) = cur_hdr
;
2741 /* The way to turn this into a symtab is to call... */
2742 psymtab
->read_symtab
= mipscoff_psymtab_to_symtab
;
2747 /* Allocate a linetable array of the given SIZE. Since the struct
2748 already includes one item, we subtract one when calculating the
2749 proper size to allocate. */
2751 static struct linetable
*
2755 struct linetable
*l
;
2757 size
= (size
-1) * sizeof(l
->item
) + sizeof(struct linetable
);
2758 l
= (struct linetable
*)xmalloc(size
);
2763 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2764 I am not so sure about the 3.4 ones.
2766 Since the struct linetable already includes one item, we subtract one when
2767 calculating the proper size to allocate. */
2769 static struct linetable
*
2770 shrink_linetable(lt
)
2771 struct linetable
* lt
;
2774 return (struct linetable
*) xrealloc ((PTR
)lt
,
2775 sizeof(struct linetable
)
2776 + (lt
->nitems
- 1) * sizeof(lt
->item
));
2779 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2782 struct blockvector
*
2786 struct blockvector
*bv
;
2789 size
= sizeof(struct blockvector
) + nblocks
* sizeof(struct block
*);
2790 bv
= (struct blockvector
*) xzalloc(size
);
2792 BLOCKVECTOR_NBLOCKS(bv
) = nblocks
;
2797 /* Allocate and zero a new block of MAXSYMS symbols */
2804 int size
= sizeof(struct block
) + (maxsyms
-1) * sizeof(struct symbol
*);
2806 return (struct block
*)xzalloc (size
);
2809 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2810 Shrink_block can also be used by add_symbol to grow a block. */
2812 static struct block
*
2818 struct blockvector
*bv
= BLOCKVECTOR(s
);
2821 /* Just reallocate it and fix references to the old one */
2823 new = (struct block
*) xrealloc ((PTR
)b
, sizeof(struct block
) +
2824 (BLOCK_NSYMS(b
)-1) * sizeof(struct symbol
*));
2826 /* Should chase pointers to old one. Fortunately, that`s just
2827 the block`s function and inferior blocks */
2828 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b
)
2829 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2830 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2831 if (BLOCKVECTOR_BLOCK(bv
,i
) == b
)
2832 BLOCKVECTOR_BLOCK(bv
,i
) = new;
2833 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) == b
)
2834 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) = new;
2838 /* Create a new symbol with printname NAME */
2845 struct symbol
*s
= (struct symbol
*)
2846 obstack_alloc (¤t_objfile
->symbol_obstack
, sizeof (struct symbol
));
2848 memset ((PTR
)s
, 0, sizeof (*s
));
2849 SYMBOL_NAME(s
) = name
;
2853 /* Create a new type with printname NAME */
2862 t
= alloc_type (current_objfile
);
2863 TYPE_NAME(t
) = name
;
2864 TYPE_CPLUS_SPECIFIC(t
) = (struct cplus_struct_type
*)
2865 &cplus_struct_default
;
2870 /* Things used for calling functions in the inferior.
2871 These functions are exported to our companion
2872 mips-tdep.c file and are here because they play
2873 with the symbol-table explicitly. */
2875 /* Sigtramp: make sure we have all the necessary information
2876 about the signal trampoline code. Since the official code
2877 from MIPS does not do so, we make up that information ourselves.
2878 If they fix the library (unlikely) this code will neutralize itself. */
2885 struct block
*b
, *b0
;
2887 sigtramp_address
= -1;
2889 /* We know it is sold as sigvec */
2890 s
= lookup_symbol("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
2892 /* Most programs do not play with signals */
2896 b0
= SYMBOL_BLOCK_VALUE(s
);
2898 /* A label of sigvec, to be more precise */
2899 s
= lookup_symbol("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
2901 /* But maybe this program uses its own version of sigvec */
2905 sigtramp_address
= SYMBOL_VALUE(s
);
2906 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
2908 /* Did we or MIPSco fix the library ? */
2909 if (SYMBOL_CLASS(s
) == LOC_BLOCK
)
2912 /* But what symtab does it live in ? */
2913 st
= find_pc_symtab(SYMBOL_VALUE(s
));
2916 * Ok, there goes the fix: turn it into a procedure, with all the
2917 * needed info. Note we make it a nested procedure of sigvec,
2918 * which is the way the (assembly) code is actually written.
2920 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2921 SYMBOL_CLASS(s
) = LOC_BLOCK
;
2922 SYMBOL_TYPE(s
) = init_type(TYPE_CODE_FUNC
, 4, 0, 0, (struct objfile
*) NULL
);
2923 TYPE_TARGET_TYPE(SYMBOL_TYPE(s
)) = builtin_type_void
;
2925 /* Need a block to allocate .gdbinfo. in */
2927 SYMBOL_BLOCK_VALUE(s
) = b
;
2928 BLOCK_START(b
) = sigtramp_address
;
2929 BLOCK_END(b
) = sigtramp_end
;
2930 BLOCK_FUNCTION(b
) = s
;
2931 BLOCK_SUPERBLOCK(b
) = BLOCK_SUPERBLOCK(b0
);
2935 /* Make a .gdbinfo. for it */
2937 struct mips_extra_func_info
*e
=
2938 (struct mips_extra_func_info
*)
2939 xzalloc(sizeof(struct mips_extra_func_info
));
2941 e
->numargs
= 0; /* the kernel thinks otherwise */
2942 /* align_longword(sigcontext + SIGFRAME) */
2943 e
->framesize
= 0x150;
2944 e
->framereg
= SP_REGNUM
;
2947 e
->regoffset
= -(41 * sizeof(int));
2949 e
->fregoffset
= -(37 * sizeof(int));
2952 current_objfile
= st
->objfile
; /* Keep new_symbol happy */
2953 s
= new_symbol(".gdbinfo.");
2954 SYMBOL_VALUE(s
) = (int) e
;
2955 SYMBOL_NAMESPACE(s
) = LABEL_NAMESPACE
;
2956 SYMBOL_CLASS(s
) = LOC_CONST
;
2957 SYMBOL_TYPE(s
) = builtin_type_void
;
2958 current_objfile
= NULL
;
2961 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
2964 /* Initialization */
2966 static struct sym_fns ecoff_sym_fns
=
2968 "ecoff", /* sym_name: name or name prefix of BFD target type */
2969 5, /* sym_namelen: number of significant sym_name chars */
2970 mipscoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
2971 mipscoff_symfile_init
,/* sym_init: read initial info, setup for sym_read() */
2972 mipscoff_symfile_read
,/* sym_read: read a symbol file into symtab */
2973 mipscoff_symfile_finish
,/* sym_finish: finished with file, cleanup */
2974 NULL
/* next: pointer to next struct sym_fns */
2978 _initialize_mipsread ()
2980 add_symtab_fns (&ecoff_sym_fns
);
2982 /* Missing basic types */
2983 builtin_type_string
=
2984 init_type (TYPE_CODE_PASCAL_ARRAY
,
2986 (struct objfile
*) NULL
);
2987 builtin_type_complex
=
2988 init_type(TYPE_CODE_FLT
,
2989 2 * sizeof(float), 0, "complex",
2990 (struct objfile
*) NULL
);
2991 builtin_type_double_complex
=
2992 init_type(TYPE_CODE_FLT
,
2993 2 * sizeof(double), 0, "double_complex",
2994 (struct objfile
*) NULL
);
2995 builtin_type_fixed_dec
=
2996 init_type(TYPE_CODE_INT
, sizeof(int),
2998 (struct objfile
*) NULL
);
2999 builtin_type_float_dec
=
3000 init_type(TYPE_CODE_FLT
, sizeof(double),
3001 0, "floating_decimal",
3002 (struct objfile
*) NULL
);