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 */
221 parse_partial_symbols();
229 static struct symbol
*new_symbol();
230 static struct type
*new_type();
231 static struct block
*new_block();
232 static struct symtab
*new_symtab();
233 static struct linetable
*new_linetable();
234 static struct blockvector
*new_bvect();
236 static struct type
*parse_type();
237 static struct symbol
*mylookup_symbol();
238 static struct block
*shrink_block();
239 static void sort_blocks();
241 static int compare_symtabs();
242 static int compare_psymtabs();
243 static int compare_blocks();
245 static struct partial_symtab
*new_psymtab();
246 static struct partial_symtab
*parse_fdr();
247 static int compare_psymbols();
249 static void psymtab_to_symtab_1();
250 static void add_block();
251 static void add_symbol();
252 static int add_line();
253 static struct linetable
*shrink_linetable();
254 static char* mips_next_symbol_text ();
257 /* Things we export to other modules */
259 /* Address bounds for the signal trampoline in inferior, if any */
260 /* FIXME: Nothing really seems to use this. Why is it here? */
262 CORE_ADDR sigtramp_address
, sigtramp_end
;
265 mipscoff_new_init (objfile
)
266 struct objfile
*objfile
;
271 mipscoff_symfile_init (objfile
)
272 struct objfile
*objfile
;
274 if (objfile
-> sym_private
!= NULL
)
276 mfree (objfile
-> md
, objfile
-> sym_private
);
278 objfile
-> sym_private
= NULL
;
282 mipscoff_symfile_read (objfile
, addr
, mainline
)
283 struct objfile
*objfile
;
287 bfd
*abfd
= objfile
-> obfd
;
290 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
291 desc
= fileno ((FILE *)(abfd
->iostream
)); /* Raw file descriptor */
294 init_minimal_symbol_collection ();
295 make_cleanup (discard_minimal_symbols
, 0);
297 /* Now that the executable file is positioned at symbol table,
298 process it and define symbols accordingly. */
300 read_mips_symtab(objfile
, desc
);
302 /* Install any minimal symbols that have been collected as the current
303 minimal symbols for this objfile. */
305 install_minimal_symbols (objfile
);
308 /* Perform any local cleanups required when we are done with a particular
309 objfile. I.E, we are in the process of discarding all symbol information
310 for an objfile, freeing up all memory held for it, and unlinking the
311 objfile struct from the global list of known objfiles. */
314 mipscoff_symfile_finish (objfile
)
315 struct objfile
*objfile
;
317 if (objfile
-> sym_private
!= NULL
)
319 mfree (objfile
-> md
, objfile
-> sym_private
);
322 /* If we have a file symbol header lying around, blow it away. */
326 free ((char *)cur_hdr
);
331 /* Allocate zeroed memory */
336 char *p
= xmalloc(size
);
342 /* Exported procedure: Builds a symtab from the PST partial one.
343 Restores the environment in effect when PST was created, delegates
344 most of the work to an ancillary procedure, and sorts
345 and reorders the symtab list at the end */
348 mipscoff_psymtab_to_symtab(pst
)
349 struct partial_symtab
*pst
;
358 printf_filtered("Reading in symbols for %s...", pst
->filename
);
361 /* Restore the header and list of pending typedefs */
362 cur_hdr
= CUR_HDR(pst
);
364 next_symbol_text_func
= mips_next_symbol_text
;
366 psymtab_to_symtab_1(pst
, pst
->filename
);
368 /* Match with global symbols. This only needs to be done once,
369 after all of the symtabs and dependencies have been read in. */
370 scan_file_globals (pst
->objfile
);
373 printf_filtered("done.\n");
376 /* Exported procedure: Is PC in the signal trampoline code */
379 in_sigtramp(pc
, name
)
383 if (sigtramp_address
== 0)
385 return (pc
>= sigtramp_address
&& pc
< sigtramp_end
);
388 /* File-level interface functions */
390 /* Read the symtab information from file FSYM into memory. Also,
391 return address just past end of our text segment in *END_OF_TEXT_SEGP. */
394 read_the_mips_symtab(abfd
, fsym
, end_of_text_segp
)
397 CORE_ADDR
*end_of_text_segp
;
399 int stsize
, st_hdrsize
;
401 struct hdr_ext hdr_ext
;
403 /* Header for executable/object file we read symbols from */
404 struct coff_exec filhdr
;
406 /* We need some info from the initial headers */
408 myread(fsym
, (char *)&filhdr
, sizeof filhdr
);
410 if (end_of_text_segp
)
412 bfd_h_get_32 (abfd
, filhdr
.a
.text_start
) +
413 bfd_h_get_32 (abfd
, filhdr
.a
.tsize
);
415 /* Find and read the symbol table header */
416 st_hdrsize
= bfd_h_get_32 (abfd
, filhdr
.f
.f_nsyms
);
417 st_filptr
= bfd_h_get_32 (abfd
, filhdr
.f
.f_symptr
);
421 lseek(fsym
, st_filptr
, L_SET
);
422 if (st_hdrsize
!= sizeof (hdr_ext
)) { /* Profanity check */
423 error ("Wrong header size: %d, not %d", st_hdrsize
,
426 if (read(fsym
, &hdr_ext
, st_hdrsize
) != st_hdrsize
)
428 ecoff_swap_hdr_in (abfd
, &hdr_ext
, &st_hdr
);
430 /* Find out how large the symbol table is */
431 stsize
= (st_hdr
.cbExtOffset
- (st_filptr
+ st_hdrsize
))
432 + st_hdr
.iextMax
* cbEXTR
;
434 /* Allocate space for the symbol table. Read it in. */
435 cur_hdr
= (HDRR
*) xmalloc(stsize
+ st_hdrsize
);
437 memcpy(cur_hdr
, &hdr_ext
, st_hdrsize
);
438 if (read(fsym
, (char *) cur_hdr
+ st_hdrsize
, stsize
) != stsize
)
441 /* Fixup file_pointers in it */
442 fixup_symtab(cur_hdr
, (char *) cur_hdr
+ st_hdrsize
,
443 st_filptr
+ st_hdrsize
, abfd
);
447 error("Short read on %s", bfd_get_filename (abfd
));
451 /* Turn all file-relative pointers in the symtab described by HDR
452 into memory pointers, given that the symtab itself is located
453 at DATA in memory and F_PTR in the file.
455 Byte-swap all the data structures, in place, while we are at it --
456 except AUX entries, which we leave in their original byte order.
457 They will be swapped as they are used instead. (FIXME: we ought to
458 do all the data structures that way.) */
461 fixup_symtab (hdr
, data
, f_ptr
, abfd
)
472 struct rfd_ext
*rbase
;
474 /* This function depends on the external and internal forms
475 of the MIPS symbol table taking identical space. Check this
476 assumption at compile-time. */
477 static check_hdr1
[1 + sizeof (struct hdr_ext
) - sizeof (HDRR
)] = {0};
478 static check_hdr2
[1 + sizeof (HDRR
) - sizeof (struct hdr_ext
)] = {0};
479 static check_fdr1
[1 + sizeof (struct fdr_ext
) - sizeof (FDR
)] = {0};
480 static check_fdr2
[1 + sizeof (FDR
) - sizeof (struct fdr_ext
)] = {0};
481 static check_pdr1
[1 + sizeof (struct pdr_ext
) - sizeof (PDR
)] = {0};
482 static check_pdr2
[1 + sizeof (PDR
) - sizeof (struct pdr_ext
)] = {0};
483 static check_sym1
[1 + sizeof (struct sym_ext
) - sizeof (SYMR
)] = {0};
484 static check_sym2
[1 + sizeof (SYMR
) - sizeof (struct sym_ext
)] = {0};
485 static check_ext1
[1 + sizeof (struct ext_ext
) - sizeof (EXTR
)] = {0};
486 static check_ext2
[1 + sizeof (EXTR
) - sizeof (struct ext_ext
)] = {0};
487 static check_rfd1
[1 + sizeof (struct rfd_ext
) - sizeof (RFDT
)] = {0};
488 static check_rfd2
[1 + sizeof (RFDT
) - sizeof (struct rfd_ext
)] = {0};
490 /* Swap in the header record. */
491 ecoff_swap_hdr_in (abfd
, hdr
, hdr
);
494 * These fields are useless (and empty) by now:
495 * hdr->cbDnOffset, hdr->cbOptOffset
496 * We use them for other internal purposes.
499 hdr
->cbOptOffset
= 0;
502 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
516 /* Fix all the RFD's. */
517 rbase
= (struct rfd_ext
*)(hdr
->cbRfdOffset
);
518 for (i
= 0; i
< hdr
->crfd
; i
++) {
519 ecoff_swap_rfd_in (abfd
, rbase
+i
, (pRFDT
) rbase
+i
);
522 /* Fix all string pointers inside the symtab, and
523 the FDR records. Also fix other miscellany. */
525 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
526 register unsigned code_offset
;
528 /* Header itself, and strings */
529 fh
= (FDR
*) (hdr
->cbFdOffset
) + f_idx
;
531 /* Swap in the FDR */
532 ecoff_swap_fdr_in (abfd
, fh
, fh
);
534 fh
->issBase
+= hdr
->cbSsOffset
;
536 fh
->rss
= (long)fh
->rss
+ fh
->issBase
;
539 fh
->isymBase
= (int)((SYMR
*)(hdr
->cbSymOffset
)+fh
->isymBase
);
541 /* FIXME! Probably don't want to do this here! */
542 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
543 sh
= (SYMR
*)fh
->isymBase
+ s_idx
;
544 ecoff_swap_sym_in (abfd
, sh
, sh
);
546 sh
->iss
= (long) sh
->iss
+ fh
->issBase
;
552 /* cannot fix fh->ipdFirst because it is a short */
553 #define IPDFIRST(h,fh) \
554 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
556 /* Optional symbols (actually used for partial_symtabs) */
562 fh
->iauxBase
= hdr
->cbAuxOffset
+ fh
->iauxBase
* sizeof(union aux_ext
);
563 /* Relative file descriptor table */
564 fh
->rfdBase
= hdr
->cbRfdOffset
+ fh
->rfdBase
* sizeof(RFDT
);
568 fh
->cbLineOffset
+= hdr
->cbLineOffset
;
570 /* Procedure symbols. (XXX This should be done later) */
571 code_offset
= fh
->adr
;
572 for (s_idx
= 0; s_idx
< fh
->cpd
; s_idx
++) {
573 unsigned name
, only_ext
;
575 pr
= (PDR
*)(IPDFIRST(hdr
,fh
)) + s_idx
;
576 ecoff_swap_pdr_in (abfd
, pr
, pr
);
578 /* Simple rule to find files linked "-x" */
579 only_ext
= fh
->rss
== -1;
581 if (pr
->isym
== -1) {
582 /* static function */
586 name
= hdr
->cbExtOffset
+ pr
->isym
* sizeof(EXTR
);
587 sh
= &((EXTR
*)name
)->asym
;
591 sh
= (SYMR
*)fh
->isymBase
+ pr
->isym
;
592 /* Included code ? */
593 if (s_idx
== 0 && pr
->adr
!= 0)
594 code_offset
-= pr
->adr
;
597 /* Turn index into a pointer */
600 /* Fix line numbers */
601 pr
->cbLineOffset
+= fh
->cbLineOffset
;
603 /* Relocate address */
605 pr
->adr
+= code_offset
;
609 /* External symbols: swap in, and fix string */
610 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
611 esh
= (EXTR
*)(hdr
->cbExtOffset
) + s_idx
;
612 ecoff_swap_ext_in (abfd
, esh
, esh
);
613 esh
->asym
.iss
= esh
->asym
.iss
+ hdr
->cbSsExtOffset
;
618 /* Find a file descriptor given its index RF relative to a file CF */
626 f
= (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
627 /* Object files do not have the RFD table, all refs are absolute */
629 return (FDR
*) (cur_hdr
->cbFdOffset
) + rf
;
630 cf
= *((pRFDT
) f
->rfdBase
+ rf
);
631 return (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
634 /* Return a safer print NAME for a file descriptor */
640 if (name
== (char *) -1)
641 return "<stripped file>";
642 if (UNSAFE_DATA_ADDR(name
))
648 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
649 whether we are adding to the general symtab or not.
650 FIXME: INCREMENTAL is currently always zero, though it should not be. */
653 read_mips_symtab (objfile
, desc
)
654 struct objfile
*objfile
;
657 CORE_ADDR end_of_text_seg
;
659 read_the_mips_symtab(objfile
->obfd
, desc
, &end_of_text_seg
);
661 parse_partial_symbols(end_of_text_seg
, objfile
);
665 * Check to make sure file was compiled with -g.
666 * If not, warn the user of this limitation.
668 if (compare_glevel(max_glevel
, GLEVEL_2
) < 0) {
669 if (max_gdbinfo
== 0)
671 "\n%s not compiled with -g, debugging support is limited.\n",
674 "You should compile with -g2 or -g3 for best debugging support.\n");
680 /* Local utilities */
682 /* Map of FDR indexes to partial symtabs */
685 struct partial_symtab
*pst
; /* the psymtab proper */
686 int n_globals
; /* exported globals (external symbols) */
687 int globals_offset
; /* cumulative */
691 /* Utility stack, used to nest procedures and blocks properly.
692 It is a doubly linked list, to avoid too many alloc/free.
693 Since we might need it quite a few times it is NOT deallocated
696 static struct parse_stack
{
697 struct parse_stack
*next
, *prev
;
698 struct symtab
*cur_st
; /* Current symtab. */
699 struct block
*cur_block
; /* Block in it. */
700 int blocktype
; /* What are we parsing. */
701 int maxsyms
; /* Max symbols in this block. */
702 struct type
*cur_type
; /* Type we parse fields for. */
703 int cur_field
; /* Field number in cur_type. */
704 int procadr
; /* Start addres of this procedure */
705 int numargs
; /* Its argument count */
706 } *top_stack
; /* Top stack ptr */
709 /* Enter a new lexical context */
711 static push_parse_stack()
713 struct parse_stack
*new;
715 /* Reuse frames if possible */
716 if (top_stack
&& top_stack
->prev
)
717 new = top_stack
->prev
;
719 new = (struct parse_stack
*) xzalloc(sizeof(struct parse_stack
));
720 /* Initialize new frame with previous content */
722 register struct parse_stack
*prev
= new->prev
;
725 top_stack
->prev
= new;
727 new->next
= top_stack
;
732 /* Exit a lexical context */
734 static pop_parse_stack()
739 top_stack
= top_stack
->next
;
743 /* Cross-references might be to things we haven't looked at
744 yet, e.g. type references. To avoid too many type
745 duplications we keep a quick fixup table, an array
746 of lists of references indexed by file descriptor */
748 static struct mips_pending
{
749 struct mips_pending
*next
; /* link */
750 SYMR
*s
; /* the symbol */
751 struct type
*t
; /* its partial type descriptor */
755 /* Check whether we already saw symbol SH in file FH as undefined */
758 struct mips_pending
*is_pending_symbol(fh
, sh
)
762 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
763 register struct mips_pending
*p
;
765 /* Linear search is ok, list is typically no more than 10 deep */
766 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
772 /* Check whether we already saw type T in file FH as undefined */
775 struct mips_pending
*is_pending_type(fh
, t
)
779 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
780 register struct mips_pending
*p
;
782 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
788 /* Add a new undef symbol SH of type T */
791 add_pending(fh
, sh
, t
)
796 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
797 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
799 /* Make sure we do not make duplicates */
801 p
= (struct mips_pending
*) xmalloc(sizeof(*p
));
804 p
->next
= pending_list
[f_idx
];
805 pending_list
[f_idx
] = p
;
807 sh
->reserved
= 1; /* for quick check */
810 /* Throw away undef entries when done with file index F_IDX */
815 register struct mips_pending
*p
, *q
;
817 for (p
= pending_list
[f_idx
]; p
; p
= q
) {
821 pending_list
[f_idx
] = 0;
824 /* The number of args to a procedure is not explicit in the symtab,
825 this is the list of all those we know of.
826 This makes parsing more reasonable and avoids extra passes */
828 static struct numarg
{
829 struct numarg
*next
; /* link */
830 unsigned adr
; /* procedure's start address */
831 unsigned num
; /* arg count */
834 /* Record that the procedure at ADR takes NUM arguments. */
839 struct numarg
*n
= (struct numarg
*) xmalloc(sizeof(struct numarg
));
843 n
->next
= numargs_list
;
847 /* See if we know how many arguments the procedure at ADR takes */
852 struct numarg
*n
= numargs_list
;
854 while (n
&& n
->adr
!= adr
)
856 return (n
) ? n
->num
: -1;
859 /* Release storage when done with this file */
864 struct numarg
*n
= numargs_list
, *m
;
875 prepend_tag_kind(tag_name
, type_code
)
885 case TYPE_CODE_STRUCT
:
888 case TYPE_CODE_UNION
:
895 result
= (char*)obstack_alloc (¤t_objfile
->symbol_obstack
,
896 strlen(prefix
) + strlen(tag_name
) + 1);
897 sprintf(result
, "%s%s", prefix
, tag_name
);
902 /* Parsing Routines proper. */
904 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
905 For blocks, procedures and types we open a new lexical context.
906 This is basically just a big switch on the symbol's type.
907 Argument AX is the base pointer of aux symbols for this file (fh->iauxBase).
908 BIGEND says whether aux symbols are big-endian or little-endian.
909 Return count of SYMR's handled (normally one). */
912 parse_symbol(sh
, ax
, bigend
)
923 /* When a symbol is cross-referenced from other files/symbols
924 we mark it explicitly */
925 int pend
= (sh
->reserved
== 1);
926 enum address_class
class;
934 case stGlobal
: /* external symbol, goes into global block */
936 b
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
938 s
= new_symbol(sh
->iss
);
939 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
942 case stStatic
: /* static data, goes into current block. */
944 b
= top_stack
->cur_block
;
945 s
= new_symbol(sh
->iss
);
946 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
949 case stLocal
: /* local variable, goes into current block */
950 if (sh
->sc
== scRegister
) {
951 class = LOC_REGISTER
;
953 sh
->value
+= FP0_REGNUM
-32;
956 b
= top_stack
->cur_block
;
957 s
= new_symbol(sh
->iss
);
958 SYMBOL_VALUE(s
) = sh
->value
;
960 data
: /* Common code for symbols describing data */
961 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
962 SYMBOL_CLASS(s
) = class;
965 /* Type could be missing in a number of cases */
966 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
967 sh
->index
== 0xfffff)
968 SYMBOL_TYPE(s
) = builtin_type_int
; /* undefined? */
970 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, 0, bigend
);
971 /* Value of a data symbol is its memory address */
974 case stParam
: /* arg to procedure, goes into current block */
976 top_stack
->numargs
++;
978 name
= (char*)sh
->iss
;
979 /* Special GNU C++ name. */
980 if (name
[0] == CPLUS_MARKER
&& name
[1] == 't' && name
[2] == 0)
982 s
= new_symbol(name
);
984 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
985 if (sh
->sc
== scRegister
) {
986 SYMBOL_CLASS(s
) = LOC_REGPARM
;
988 sh
->value
+= FP0_REGNUM
-32;
990 SYMBOL_CLASS(s
) = LOC_ARG
;
991 SYMBOL_VALUE(s
) = sh
->value
;
992 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, 0, bigend
);
993 add_symbol(s
, top_stack
->cur_block
);
995 /* FIXME: This has not been tested. See dbxread.c */
996 /* Add the type of this parameter to the function/procedure
997 type of this block. */
998 add_param_to_type(&top_stack
->cur_block
->function
->type
,s
);
1002 case stLabel
: /* label, goes into current block */
1003 s
= new_symbol(sh
->iss
);
1004 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
; /* so that it can be used */
1005 SYMBOL_CLASS(s
) = LOC_LABEL
; /* but not misused */
1006 SYMBOL_VALUE_ADDRESS(s
) = (CORE_ADDR
)sh
->value
;
1007 SYMBOL_TYPE(s
) = builtin_type_int
;
1008 add_symbol(s
, top_stack
->cur_block
);
1011 case stProc
: /* Procedure, usually goes into global block */
1012 case stStaticProc
: /* Static procedure, goes into current block */
1013 s
= new_symbol(sh
->iss
);
1014 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1015 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1016 /* Type of the return value */
1017 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
1018 t
= builtin_type_int
;
1020 t
= parse_type(ax
+ sh
->index
+ 1, 0, bigend
);
1021 b
= top_stack
->cur_block
;
1022 if (sh
->st
== stProc
) {
1023 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
1024 /* The next test should normally be true,
1025 but provides a hook for nested functions
1026 (which we don't want to make global). */
1027 if (b
== BLOCKVECTOR_BLOCK(bv
, STATIC_BLOCK
))
1028 b
= BLOCKVECTOR_BLOCK(bv
, GLOBAL_BLOCK
);
1032 /* Make a type for the procedure itself */
1034 /* FIXME: This has not been tested yet! See dbxread.c */
1035 /* Generate a template for the type of this function. The
1036 types of the arguments will be added as we read the symbol
1038 bcopy(SYMBOL_TYPE(s
),lookup_function_type(t
),sizeof(struct type
));
1040 SYMBOL_TYPE(s
) = lookup_function_type (t
);
1043 /* Create and enter a new lexical context */
1044 b
= new_block(top_stack
->maxsyms
);
1045 SYMBOL_BLOCK_VALUE(s
) = b
;
1046 BLOCK_FUNCTION(b
) = s
;
1047 BLOCK_START(b
) = BLOCK_END(b
) = sh
->value
;
1048 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1049 add_block(b
, top_stack
->cur_st
);
1051 /* Not if we only have partial info */
1052 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
1056 top_stack
->cur_block
= b
;
1057 top_stack
->blocktype
= sh
->st
;
1058 top_stack
->cur_type
= SYMBOL_TYPE(s
);
1059 top_stack
->cur_field
= -1;
1060 top_stack
->procadr
= sh
->value
;
1061 top_stack
->numargs
= 0;
1063 sh
->value
= (long) SYMBOL_TYPE(s
);
1067 #ifndef btVoid /* btVoid was added late. */
1070 /* These new symbol types have been recently added to SGI machines. */
1084 case stBlock
: /* Either a lexical block, or some type */
1086 top_stack
->blocktype
= stBlock
;
1087 if (sh
->sc
== scInfo
) { /* structure/union/enum def */
1089 sh
->st
== stStruct
? TYPE_CODE_STRUCT
1090 : sh
->st
== stUnion
? TYPE_CODE_UNION
1091 : sh
->st
== stEnum
? TYPE_CODE_ENUM
1098 s
= new_symbol(sh
->iss
);
1099 SYMBOL_NAMESPACE(s
) = STRUCT_NAMESPACE
;
1100 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1101 SYMBOL_VALUE(s
) = 0;
1102 add_symbol(s
, top_stack
->cur_block
);
1104 /* First count the number of fields. */
1105 for (tsym
= sh
+1; tsym
->st
!= stEnd
; tsym
++)
1106 if (tsym
->st
== stMember
) {
1107 if (nfields
== 0 && type_code
== TYPE_CODE_UNDEF
)
1108 /* If the type of the member is Nil (or Void)
1109 assume the tag is an enumeration. */
1110 if (tsym
->index
== indexNil
)
1111 type_code
= TYPE_CODE_ENUM
;
1113 ecoff_swap_tir_in (bigend
,
1114 &ax
[tsym
->index
].a_ti
,
1116 if (tir
.bt
== btNil
|| tir
.bt
== btVoid
)
1117 type_code
= TYPE_CODE_ENUM
;
1120 if (tsym
->value
> max_value
)
1121 max_value
= tsym
->value
;
1123 else if (tsym
->st
== stBlock
1124 || tsym
->st
== stParsed
) {
1125 if (tsym
->sc
== scVariant
) ; /*UNIMPLEMENTED*/
1126 if (tsym
->index
!= 0)
1127 tsym
= ((SYMR
*)cur_fdr
->isymBase
)
1131 /* There is no guaranteed way to distinguish struct,
1132 unions, and enums at this point. This is a bug in the
1133 original design (that has been fixed with the
1134 recent addition of the stStruct, stUnion, and stEnum
1135 symbol types.) The way you can tell is if/when you
1136 see a variable or field of that type: In that case
1137 the variable's type (in the AUX table) says if the
1138 type is struct, union, or enum,
1139 and points back to the stBlock here.
1140 So you can patch the tag kind up later - but only
1141 if there actually is a variable or field of that type.
1143 So until we know for sure, we will guess at this point.
1145 If the first member has index==indexNil or a void type,
1146 assume we have an enumeration.
1147 Otherwise, if there is more than one member, and all
1148 the members have offset 0, assume we have a union.
1149 Otherwise, assume we have a struct.
1151 The heuristic could guess wrong in the case of
1152 of an enumeration with no members or a union
1153 with one (or zero) members, or when all except the
1154 last field of a struct have width zero.
1155 These are uncommon and/or illegal situations, and
1156 in any case guessing wrong probably doesn't matter much.
1158 But if we later do find out we were wrong,
1159 we fixup the tag kind. Members of an enumeration
1160 must be handled differently from struct/union fields,
1161 and that is harder to patch up, but luckily we
1162 shouldn't need to. (If there are any enumeration
1163 members, we can tell for sure it's an enum here.) */
1165 if (type_code
== TYPE_CODE_UNDEF
)
1166 if (nfields
> 1 && max_value
== 0)
1167 type_code
= TYPE_CODE_UNION
;
1169 type_code
= TYPE_CODE_STRUCT
;
1171 /* If this type was expected, use its partial definition */
1173 t
= is_pending_symbol(cur_fdr
, sh
)->t
;
1175 t
= new_type(prepend_tag_kind(sh
->iss
, type_code
));
1177 TYPE_CODE(t
) = type_code
;
1178 TYPE_LENGTH(t
) = sh
->value
;
1179 TYPE_NFIELDS(t
) = nfields
;
1180 TYPE_FIELDS(t
) = f
= (struct field
*)
1181 obstack_alloc (¤t_objfile
-> type_obstack
,
1182 nfields
* sizeof (struct field
));
1184 if (type_code
== TYPE_CODE_ENUM
) {
1185 /* This is a non-empty enum. */
1186 for (tsym
= sh
+ 1; tsym
->st
== stMember
; tsym
++) {
1187 struct symbol
*enum_sym
;
1188 f
->bitpos
= tsym
->value
;
1190 f
->name
= (char*)tsym
->iss
;
1193 enum_sym
= (struct symbol
*)
1194 obstack_alloc (¤t_objfile
->symbol_obstack
,
1195 sizeof (struct symbol
));
1196 memset (enum_sym
, 0, sizeof (struct symbol
));
1197 SYMBOL_NAME (enum_sym
) = f
->name
;
1198 SYMBOL_CLASS (enum_sym
) = LOC_CONST
;
1199 SYMBOL_TYPE (enum_sym
) = t
;
1200 SYMBOL_NAMESPACE (enum_sym
) = VAR_NAMESPACE
;
1201 SYMBOL_VALUE (enum_sym
) = tsym
->value
;
1202 add_symbol(enum_sym
, top_stack
->cur_block
);
1204 /* Skip the stMembers that we've handled. */
1210 /* make this the current type */
1211 top_stack
->cur_type
= t
;
1212 top_stack
->cur_field
= 0;
1213 /* Mark that symbol has a type, and say which one */
1214 sh
->value
= (long) t
;
1216 /* beginnning of (code) block. Value of symbol
1217 is the displacement from procedure start */
1218 b
= new_block(top_stack
->maxsyms
);
1219 BLOCK_START(b
) = sh
->value
+ top_stack
->procadr
;
1220 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1221 top_stack
->cur_block
= b
;
1222 add_block(b
, top_stack
->cur_st
);
1226 case stEnd
: /* end (of anything) */
1227 if (sh
->sc
== scInfo
) {
1228 /* Finished with type */
1229 top_stack
->cur_type
= 0;
1230 } else if (sh
->sc
== scText
&&
1231 (top_stack
->blocktype
== stProc
||
1232 top_stack
->blocktype
== stStaticProc
)) {
1233 /* Finished with procedure */
1234 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
1238 BLOCK_END(top_stack
->cur_block
) += sh
->value
; /* size */
1239 got_numargs(top_stack
->procadr
, top_stack
->numargs
);
1240 /* Reallocate symbols, saving memory */
1241 b
= shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1243 /* f77 emits proc-level with address bounds==[0,0],
1244 So look for such child blocks, and patch them. */
1245 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++) {
1246 struct block
*b_bad
= BLOCKVECTOR_BLOCK(bv
,i
);
1247 if (BLOCK_SUPERBLOCK(b_bad
) == b
1248 && BLOCK_START(b_bad
) == top_stack
->procadr
1249 && BLOCK_END(b_bad
) == top_stack
->procadr
) {
1250 BLOCK_START(b_bad
) = BLOCK_START(b
);
1251 BLOCK_END(b_bad
) = BLOCK_END(b
);
1254 } else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
) {
1255 /* End of (code) block. The value of the symbol
1256 is the displacement from the procedure`s start
1257 address of the end of this block. */
1258 BLOCK_END(top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1259 (void) shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1261 pop_parse_stack(); /* restore previous lexical context */
1264 case stMember
: /* member of struct or union */
1265 f
= &TYPE_FIELDS(top_stack
->cur_type
)[top_stack
->cur_field
++];
1266 f
->name
= (char*)sh
->iss
;
1267 f
->bitpos
= sh
->value
;
1269 f
->type
= parse_type(ax
+ sh
->index
, &f
->bitsize
, bigend
);
1272 case stTypedef
: /* type definition */
1273 s
= new_symbol(sh
->iss
);
1274 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1275 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1276 SYMBOL_BLOCK_VALUE(s
) = top_stack
->cur_block
;
1277 add_symbol(s
, top_stack
->cur_block
);
1278 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, 0, bigend
);
1279 sh
->value
= (long) SYMBOL_TYPE(s
);
1282 case stFile
: /* file name */
1284 top_stack
->blocktype
= sh
->st
;
1287 /* I`ve never seen these for C */
1289 break; /* register relocation */
1291 break; /* forwarding address */
1293 break; /* constant */
1295 error("Unknown symbol type %x.", sh
->st
);
1301 /* Parse the type information provided in the raw AX entries for
1302 the symbol SH. Return the bitfield size in BS, in case.
1303 We must byte-swap the AX entries before we use them; BIGEND says whether
1304 they are big-endian or little-endian (from fh->fBigendian). */
1306 static struct type
*parse_type(ax
, bs
, bigend
)
1311 /* Null entries in this map are treated specially */
1312 static struct type
**map_bt
[] =
1314 &builtin_type_void
, /* btNil */
1316 &builtin_type_char
, /* btChar */
1317 &builtin_type_unsigned_char
, /* btUChar */
1318 &builtin_type_short
, /* btShort */
1319 &builtin_type_unsigned_short
, /* btUShort */
1320 &builtin_type_int
, /* btInt */
1321 &builtin_type_unsigned_int
, /* btUInt */
1322 &builtin_type_long
, /* btLong */
1323 &builtin_type_unsigned_long
, /* btULong */
1324 &builtin_type_float
, /* btFloat */
1325 &builtin_type_double
, /* btDouble */
1332 &builtin_type_complex
, /* btComplex */
1333 &builtin_type_double_complex
, /* btDComplex */
1335 &builtin_type_fixed_dec
, /* btFixedDec */
1336 &builtin_type_float_dec
, /* btFloatDec */
1337 &builtin_type_string
, /* btString */
1340 &builtin_type_void
, /* btVoid */
1344 struct type
*tp
= 0;
1350 /* Use aux as a type information record, map its basic type. */
1352 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1353 if (t
->bt
> (sizeof (map_bt
)/sizeof (*map_bt
))) {
1354 complain (&basic_type_complaint
, t
->bt
);
1355 return builtin_type_int
;
1357 if (map_bt
[t
->bt
]) {
1358 tp
= *map_bt
[t
->bt
];
1362 /* Cannot use builtin types -- build our own */
1365 tp
= lookup_pointer_type (builtin_type_void
);
1369 type_code
= TYPE_CODE_STRUCT
;
1373 type_code
= TYPE_CODE_UNION
;
1377 type_code
= TYPE_CODE_ENUM
;
1381 type_code
= TYPE_CODE_RANGE
;
1385 type_code
= TYPE_CODE_SET
;
1390 complain (&basic_type_complaint
, t
->bt
);
1391 return builtin_type_int
;
1395 /* Skip over any further type qualifiers (FIXME). */
1397 /* This is the way it would work if the compiler worked */
1401 ecoff_swap_tir_in (bigend
, ax
, t1
);
1402 } while (t1
->continued
);
1405 /* Move on to next aux */
1409 *bs
= AUX_GET_WIDTH (bigend
, ax
);
1413 /* All these types really point to some (common) MIPS type
1414 definition, and only the type-qualifiers fully identify
1415 them. We'll make the same effort at sharing. */
1416 if (t
->bt
== btIndirect
||
1417 t
->bt
== btStruct
||
1420 t
->bt
== btTypedef
||
1423 char name
[256], *pn
;
1425 /* Try to cross reference this type */
1426 ax
+= cross_ref(ax
, &tp
, type_code
, &pn
, bigend
);
1427 /* reading .o file ? */
1428 if (UNSAFE_DATA_ADDR(tp
))
1429 tp
= init_type(type_code
, 0, 0, 0, (struct objfile
*) NULL
);
1430 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1431 sprintf(name
, fmt
, pn
);
1433 /* Usually, TYPE_CODE(tp) is already type_code. The main
1434 exception is if we guessed wrong re struct/union/enum. */
1435 if (TYPE_CODE(tp
) != type_code
) {
1436 complain (&bad_tag_guess_complaint
, 0);
1437 TYPE_CODE(tp
) = type_code
;
1439 if (TYPE_NAME(tp
) == NULL
|| strcmp(TYPE_NAME(tp
), name
) != 0)
1440 TYPE_NAME(tp
) = obsavestring(name
, strlen(name
),
1441 ¤t_objfile
-> type_obstack
);
1444 /* Deal with range types */
1445 if (t
->bt
== btRange
) {
1448 TYPE_NFIELDS (tp
) = 2;
1450 (struct field
*) obstack_alloc (¤t_objfile
-> type_obstack
,
1451 2 * sizeof (struct field
));
1452 TYPE_FIELD_NAME (tp
, 0) = obsavestring ("Low", strlen ("Low"),
1453 ¤t_objfile
-> type_obstack
);
1454 TYPE_FIELD_BITPOS (tp
, 0) = AUX_GET_DNLOW (bigend
, ax
);
1456 TYPE_FIELD_NAME (tp
, 1) = obsavestring ("High", strlen ("High"),
1457 ¤t_objfile
-> type_obstack
);
1458 TYPE_FIELD_BITPOS (tp
, 1) = AUX_GET_DNHIGH (bigend
, ax
);
1462 /* Parse all the type qualifiers now. If there are more
1463 than 6 the game will continue in the next aux */
1465 #define PARSE_TQ(tq) \
1466 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, bigend);
1468 again
: PARSE_TQ(tq0
);
1478 ecoff_swap_tir_in (bigend
, &tax
->a_ti
, t
);
1484 /* Make up a complex type from a basic one. Type is passed by
1485 reference in TPP and side-effected as necessary. The type
1486 qualifier TQ says how to handle the aux symbols at AX for
1487 the symbol SX we are currently analyzing. BIGEND says whether
1488 aux symbols are big-endian or little-endian.
1489 Returns the number of aux symbols we parsed. */
1492 upgrade_type(tpp
, tq
, ax
, bigend
)
1500 /* Used in array processing */
1509 t
= lookup_pointer_type (*tpp
);
1514 t
= lookup_function_type (*tpp
);
1520 t
= init_type(TYPE_CODE_ARRAY
, 0, 0, 0, (struct objfile
*) NULL
);
1521 TYPE_TARGET_TYPE(t
) = *tpp
;
1523 /* Determine and record the domain type (type of index) */
1524 ecoff_swap_rndx_in (bigend
, ax
, &rndx
);
1529 rf
= AUX_GET_ISYM (bigend
, ax
);
1532 fh
= get_rfd(cur_fd
, rf
);
1534 /* Fields are kept in an array */
1535 /* FIXME - Memory leak! */
1536 if (TYPE_NFIELDS(t
))
1537 TYPE_FIELDS(t
) = (struct field
*)
1538 xrealloc((char *) TYPE_FIELDS(t
),
1539 (TYPE_NFIELDS(t
)+1) * sizeof(struct field
));
1541 TYPE_FIELDS(t
) = (struct field
*)
1542 xzalloc(sizeof(struct field
));
1543 f
= &(TYPE_FIELD(t
,TYPE_NFIELDS(t
)));
1545 memset(f
, 0, sizeof(struct field
));
1547 /* XXX */ f
->type
= parse_type(fh
->iauxBase
+ id
* sizeof(union aux_ext
),
1548 &f
->bitsize
, bigend
);
1551 lower
= AUX_GET_DNLOW (bigend
, ax
);
1553 upper
= AUX_GET_DNHIGH (bigend
, ax
);
1555 rf
= AUX_GET_WIDTH (bigend
, ax
); /* bit size of array element */
1557 /* Check whether supplied array element bit size matches
1558 the known size of the element type. If this complaint
1559 ends up not happening, we can remove this code. It's
1560 here because we aren't sure we understand this *&%&$
1562 id
= TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) << 3; /* bitsize */
1564 /* Most likely an undefined type */
1566 TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) = id
>> 3;
1569 complain (&array_bitsize_complaint
, rf
);
1571 TYPE_LENGTH(t
) = (upper
< 0) ? 0 :
1572 (upper
- lower
+ 1) * (rf
>> 3);
1577 /* Volatile -- currently ignored */
1581 complain (&unknown_type_qual_complaint
, tq
);
1587 /* Parse a procedure descriptor record PR. Note that the procedure
1588 is parsed _after_ the local symbols, now we just make up the
1589 extra information we need into a special symbol that we insert
1590 in the procedure's main block. Note also that images that
1591 have been partially stripped (ld -x) have been deprived
1592 of local symbols, and we have to cope with them here.
1593 The procedure's code ends at BOUND */
1596 parse_procedure(pr
, bound
)
1599 struct symbol
*s
, *i
;
1600 SYMR
*sh
= (SYMR
*)pr
->isym
;
1602 struct mips_extra_func_info
*e
;
1606 /* Reuse the MIPS record */
1607 e
= (struct mips_extra_func_info
*) pr
;
1608 e
->numargs
= lookup_numargs(pr
->adr
);
1610 /* Make up our special symbol */
1611 i
= new_symbol(".gdbinfo.");
1612 SYMBOL_VALUE(i
) = (int)e
;
1613 SYMBOL_NAMESPACE(i
) = LABEL_NAMESPACE
;
1614 SYMBOL_CLASS(i
) = LOC_CONST
;
1615 SYMBOL_TYPE(i
) = builtin_type_void
;
1617 /* Make up a name for static procedures. Sigh. */
1618 if (sh
== (SYMR
*)-1) {
1619 sprintf(name
,".static_procedure@%x",pr
->adr
);
1620 sh_name
= savestring(name
, strlen(name
));
1624 sh_name
= (char*)sh
->iss
;
1625 s
= mylookup_symbol(sh_name
, top_stack
->cur_block
,
1626 VAR_NAMESPACE
, LOC_BLOCK
);
1629 b
= SYMBOL_BLOCK_VALUE(s
);
1631 s
= new_symbol(sh_name
);
1632 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1633 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1634 /* Donno its type, hope int is ok */
1635 SYMBOL_TYPE(s
) = lookup_function_type (builtin_type_int
);
1636 add_symbol(s
, top_stack
->cur_block
);
1637 /* Wont have symbols for this one */
1639 SYMBOL_BLOCK_VALUE(s
) = b
;
1640 BLOCK_FUNCTION(b
) = s
;
1641 BLOCK_START(b
) = pr
->adr
;
1642 BLOCK_END(b
) = bound
;
1643 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1644 add_block(b
, top_stack
->cur_st
);
1650 /* Parse the external symbol ES. Just call parse_symbol() after
1651 making sure we know where the aux are for it. For procedures,
1652 parsing of the PDRs has already provided all the needed
1653 information, we only parse them if SKIP_PROCEDURES is false,
1654 and only if this causes no symbol duplication.
1655 BIGEND says whether aux entries are big-endian or little-endian.
1657 This routine clobbers top_stack->cur_block and ->cur_st. */
1660 parse_external(es
, skip_procedures
, bigend
)
1662 int skip_procedures
;
1667 if (es
->ifd
!= ifdNil
) {
1669 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
) + cur_fd
;
1670 ax
= (union aux_ext
*)cur_fdr
->iauxBase
;
1672 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
);
1675 top_stack
->cur_st
= cur_stab
;
1676 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
1679 /* Reading .o files */
1680 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
) {
1682 switch (es
->asym
.st
) {
1684 case stProc
: what
= "procedure"; n_undef_procs
++; break;
1685 case stGlobal
: what
= "variable"; n_undef_vars
++; break;
1686 case stLabel
: what
= "label"; n_undef_labels
++; break;
1687 default : what
= "symbol"; break;
1691 printf_filtered("Warning: %s `%s' is undefined (in %s)\n", what
,
1692 es
->asym
.iss
, fdr_name(cur_fdr
->rss
));
1696 switch (es
->asym
.st
) {
1698 /* If we have full symbols we do not need more */
1699 if (skip_procedures
)
1701 if (mylookup_symbol (es
->asym
.iss
, top_stack
->cur_block
,
1702 VAR_NAMESPACE
, LOC_BLOCK
))
1708 * Note that the case of a symbol with indexNil
1709 * must be handled anyways by parse_symbol().
1711 parse_symbol(&es
->asym
, ax
, bigend
);
1718 /* Parse the line number info for file descriptor FH into
1719 GDB's linetable LT. MIPS' encoding requires a little bit
1720 of magic to get things out. Note also that MIPS' line
1721 numbers can go back and forth, apparently we can live
1722 with that and do not need to reorder our linetables */
1727 struct linetable
*lt
;
1729 unsigned char *base
= (unsigned char*)fh
->cbLineOffset
;
1731 int delta
, count
, lineno
= 0;
1737 /* Scan by procedure descriptors */
1738 i
= 0; j
= 0, k
= 0;
1739 for (pr
= (PDR
*)IPDFIRST(cur_hdr
,fh
); j
< fh
->cpd
; j
++, pr
++) {
1742 /* No code for this one */
1743 if (pr
->iline
== ilineNil
||
1744 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1747 * Aurgh! To know where to stop expanding we
1750 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1751 if (pr
[l
].iline
!= -1)
1753 if (l
== (fh
->cpd
- j
))
1758 * When procedures are moved around the linenumbers
1759 * are attributed to the next procedure up
1761 if (pr
->iline
>= halt
) continue;
1763 base
= (unsigned char*)pr
->cbLineOffset
;
1764 l
= pr
->adr
>> 2; /* in words */
1765 halt
+= (pr
->adr
>> 2) - pr
->iline
;
1766 for (lineno
= pr
->lnLow
; l
< halt
;) {
1767 count
= *base
& 0x0f;
1768 delta
= *base
++ >> 4;
1772 delta
= (base
[0] << 8) | base
[1];
1773 if (delta
>= 0x8000)
1777 lineno
+= delta
;/* first delta is 0 */
1778 k
= add_line(lt
, lineno
, l
, k
);
1785 /* Master parsing procedure for first-pass reading of file symbols
1786 into a partial_symtab.
1788 Parses the symtab described by the global symbolic header CUR_HDR.
1789 END_OF_TEXT_SEG gives the address just after the text segment for
1790 the symtab we are reading. */
1793 parse_partial_symbols(end_of_text_seg
, objfile
)
1794 int end_of_text_seg
;
1795 struct objfile
*objfile
;
1798 /* int stat_idx, h_max;*/
1799 HDRR
*hdr
= cur_hdr
;
1800 /* Running pointers */
1805 struct partial_symtab
*pst
;
1807 int past_first_source_file
= 0;
1809 /* List of current psymtab's include files */
1810 char **psymtab_include_list
;
1811 int includes_allocated
;
1814 struct pst_map
* fdr_to_pst
;
1815 /* Index within current psymtab dependency list */
1816 struct partial_symtab
**dependency_list
;
1817 int dependencies_used
, dependencies_allocated
;
1818 struct cleanup
*old_chain
;
1820 extern_tab
= (EXTR
**)obstack_alloc (&objfile
->psymbol_obstack
,
1821 sizeof(EXTR
*) * hdr
->iextMax
);
1823 includes_allocated
= 30;
1825 psymtab_include_list
= (char **) alloca (includes_allocated
*
1827 next_symbol_text_func
= mips_next_symbol_text
;
1829 dependencies_allocated
= 30;
1830 dependencies_used
= 0;
1832 (struct partial_symtab
**) alloca (dependencies_allocated
*
1833 sizeof (struct partial_symtab
*));
1835 last_source_file
= 0;
1840 * Only parse the Local and External symbols, and the Relative FDR.
1841 * Fixup enough of the loader symtab to be able to use it.
1842 * Allocate space only for the file's portions we need to
1847 max_glevel
= MIN_GLEVEL
;
1849 /* Allocate the map FDR -> PST.
1850 Minor hack: -O3 images might claim some global data belongs
1851 to FDR -1. We`ll go along with that */
1852 fdr_to_pst
= (struct pst_map
*)xzalloc((hdr
->ifdMax
+1) * sizeof *fdr_to_pst
);
1853 old_chain
= make_cleanup (free
, fdr_to_pst
);
1856 struct partial_symtab
* pst
= new_psymtab("", objfile
);
1857 fdr_to_pst
[-1].pst
= pst
;
1861 /* Pass 1 over external syms: Presize and partition the list */
1862 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1863 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1864 fdr_to_pst
[esh
->ifd
].n_globals
++;
1867 /* Pass 1.5 over files: partition out global symbol space */
1869 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++) {
1870 fdr_to_pst
[f_idx
].globals_offset
= s_idx
;
1871 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
1872 fdr_to_pst
[f_idx
].n_globals
= 0;
1875 /* Pass 2 over external syms: fill in external symbols */
1876 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1877 enum minimal_symbol_type ms_type
= mst_text
;
1878 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1880 extern_tab
[fdr_to_pst
[esh
->ifd
].globals_offset
1881 + fdr_to_pst
[esh
->ifd
].n_globals
++] = esh
;
1883 if (esh
->asym
.sc
== scUndefined
|| esh
->asym
.sc
== scNil
)
1886 switch (esh
->asym
.st
) {
1895 ms_type
= mst_unknown
;
1896 complain (&unknown_ext_complaint
,
1897 (char *)(esh
->asym
.iss
));
1899 prim_record_minimal_symbol ((char *)(esh
->asym
.iss
),
1904 /* Pass 3 over files, over local syms: fill in static symbols */
1905 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
1906 struct partial_symtab
*save_pst
;
1908 cur_fdr
= fh
= f_idx
+ (FDR
*)(cur_hdr
->cbFdOffset
);
1910 if (fh
->csym
== 0) {
1911 fdr_to_pst
[f_idx
].pst
= NULL
;
1914 pst
= start_psymtab_common (objfile
, 0, (char*)fh
->rss
,
1915 fh
->cpd
? fh
->adr
: 0,
1916 objfile
->global_psymbols
.next
,
1917 objfile
->static_psymbols
.next
);
1918 pst
->read_symtab_private
= (char *)
1919 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
1922 /* Make everything point to everything. */
1923 FDR_IDX(pst
) = f_idx
;
1924 fdr_to_pst
[f_idx
].pst
= pst
;
1925 fh
->ioptBase
= (int)pst
;
1927 CUR_HDR(pst
) = cur_hdr
;
1929 /* The way to turn this into a symtab is to call... */
1930 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
1932 pst
->texthigh
= pst
->textlow
;
1934 #if 0 /* This is done in start_psymtab_common */
1935 pst
->globals_offset
= global_psymbols
.next
- global_psymbols
.list
;
1936 pst
->statics_offset
= static_psymbols
.next
- static_psymbols
.list
;
1938 pst
->n_global_syms
= 0;
1939 pst
->n_static_syms
= 0;
1942 /* The second symbol must be @stab.
1943 This symbol is emitted by mips-tfile to signal
1944 that the current object file uses encapsulated stabs
1945 instead of mips ecoff for local symbols.
1946 (It is the second symbol because the first symbol is
1947 the stFile used to signal the start of a file). */
1949 && strcmp((char *)(((SYMR
*)fh
->isymBase
)[1].iss
),
1950 stabs_symbol
) == 0) {
1951 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++) {
1954 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
1955 type_code
= MIPS_UNMARK_STAB(sh
->index
);
1956 if (!MIPS_IS_STAB(sh
)) {
1957 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
) {
1958 long procaddr
= sh
->value
;
1959 sh
= AUX_GET_ISYM (fh
->fBigendian
,
1960 sh
->index
+ (union aux_ext
*)(fh
->iauxBase
))
1961 + (SYMR
*) fh
->isymBase
- 1;
1962 if (sh
->st
== stEnd
) {
1963 long high
= procaddr
+ sh
->value
;
1964 if (high
> pst
->texthigh
)
1965 pst
->texthigh
= high
;
1970 #define SET_NAMESTRING() namestring = (char*)sh->iss
1971 #define CUR_SYMBOL_TYPE type_code
1972 #define CUR_SYMBOL_VALUE sh->value
1973 #define START_PSYMTAB(ofile,addr,fname,low,symoff,global_syms,static_syms)\
1975 #define END_PSYMTAB(pst,ilist,ninc,c_off,c_text,dep_list,n_deps) (void)0
1976 #define addr 0 /* FIXME, should be offset of addresses */
1977 #define HANDLE_RBRAC(val) \
1978 if ((val) > save_pst->texthigh) save_pst->texthigh = (val);
1979 #include "partial-stab.h"
1984 register struct partial_symbol
*psym
;
1985 for (cur_sdx
= 0; cur_sdx
< fh
->csym
; ) {
1988 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
1990 if (MIPS_IS_STAB(sh
)) {
1995 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
1996 sh
->index
== 0xfffff) {
1997 /* FIXME, premature? */
2002 name
= (char *)(sh
->iss
);
2007 case stProc
: /* Asm labels apparently */
2008 case stStaticProc
: /* Function */
2009 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
2010 VAR_NAMESPACE
, LOC_BLOCK
,
2011 objfile
->static_psymbols
, sh
->value
);
2012 /* Skip over procedure to next one. */
2013 cur_sdx
= AUX_GET_ISYM (fh
->fBigendian
,
2014 sh
->index
+ (union aux_ext
*)fh
->iauxBase
);
2015 procaddr
= sh
->value
;
2017 sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
- 1;
2018 if (sh
->st
!= stEnd
)
2020 high
= procaddr
+ sh
->value
;
2021 if (high
> pst
->texthigh
)
2022 pst
->texthigh
= high
;
2024 case stStatic
: /* Variable */
2027 case stTypedef
: /* Typedef */
2028 class = LOC_TYPEDEF
;
2030 case stConstant
: /* Constant decl */
2033 case stBlock
: /* { }, str, un, enum*/
2034 if (sh
->sc
== scInfo
) {
2035 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
2036 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2037 objfile
->static_psymbols
, sh
->value
);
2039 /* Skip over the block */
2040 cur_sdx
= sh
->index
;
2042 case stFile
: /* File headers */
2043 case stLabel
: /* Labels */
2044 case stEnd
: /* Ends of files */
2047 /* Both complaints are valid: one gives symbol name,
2048 the other the offending symbol type. */
2049 complain (&unknown_sym_complaint
, (char *)sh
->iss
);
2050 complain (&unknown_st_complaint
, sh
->st
);
2054 /* Use this gdb symbol */
2055 ADD_PSYMBOL_TO_LIST(name
, strlen(name
),
2056 VAR_NAMESPACE
, class,
2057 objfile
->static_psymbols
, sh
->value
);
2059 cur_sdx
++; /* Go to next file symbol */
2062 /* Now do enter the external symbols. */
2063 ext_ptr
= &extern_tab
[fdr_to_pst
[f_idx
].globals_offset
];
2064 cur_sdx
= fdr_to_pst
[f_idx
].n_globals
;
2065 PST_PRIVATE(save_pst
)->extern_count
= cur_sdx
;
2066 PST_PRIVATE(save_pst
)->extern_tab
= ext_ptr
;
2067 for (; --cur_sdx
>= 0; ext_ptr
++) {
2068 enum address_class
class;
2069 if ((*ext_ptr
)->ifd
!= f_idx
)
2071 sh
= &(*ext_ptr
)->asym
;
2080 complain (&unknown_ext_complaint
, sh
->iss
);
2085 if (objfile
->global_psymbols
.next
>=
2086 objfile
->global_psymbols
.list
+ objfile
->global_psymbols
.size
)
2087 extend_psymbol_list (&objfile
->global_psymbols
, objfile
);
2088 psym
= objfile
->global_psymbols
.next
++;
2089 SYMBOL_NAME (psym
) = (char*)sh
->iss
;
2090 SYMBOL_NAMESPACE (psym
) = VAR_NAMESPACE
;
2091 SYMBOL_CLASS (psym
) = class;
2092 SYMBOL_VALUE_ADDRESS (psym
) = (CORE_ADDR
)sh
->value
;
2096 end_psymtab (save_pst
, psymtab_include_list
, includes_used
,
2097 -1, save_pst
->texthigh
,
2098 dependency_list
, dependencies_used
);
2099 if (objfile
-> ei
.entry_point
>= save_pst
->textlow
&&
2100 objfile
-> ei
.entry_point
< save_pst
->texthigh
)
2102 objfile
-> ei
.entry_file_lowpc
= save_pst
->textlow
;
2103 objfile
-> ei
.entry_file_highpc
= save_pst
->texthigh
;
2107 /* Mark the last code address, and remember it for later */
2108 hdr
->cbDnOffset
= end_of_text_seg
;
2110 /* Now scan the FDRs for dependencies */
2111 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
2113 fh
= f_idx
+ (FDR
*)(cur_hdr
->cbFdOffset
);
2114 pst
= fdr_to_pst
[f_idx
].pst
;
2116 /* This should catch stabs-in-ecoff. */
2120 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
2121 /* ...then presumably a .h file: drop reverse depends .h->.c */
2122 for (; s_id0
< fh
->crfd
; s_id0
++) {
2123 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
2125 s_id0
++; /* Skip self-dependency */
2130 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2131 pst
->dependencies
= (struct partial_symtab
**)
2132 obstack_alloc (&objfile
->psymbol_obstack
,
2133 pst
->number_of_dependencies
*
2134 sizeof (struct partial_symtab
*));
2135 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
2136 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
2137 if (*rh
< 0 || *rh
>= hdr
->ifdMax
)
2138 complain(&bad_file_number_complaint
, *rh
);
2140 pst
->dependencies
[s_idx
-s_id0
] = fdr_to_pst
[*rh
].pst
;
2143 do_cleanups (old_chain
);
2148 /* Do the initial analisys of the F_IDX-th file descriptor.
2149 Allocates a partial symtab for it, and builds the list
2150 of dependent files by recursion. LEV says at which level
2151 of recursion we are called (to pretty up debug traces) */
2153 static struct partial_symtab
*
2154 parse_fdr(f_idx
, lev
, objfile
)
2157 struct objfile
*objfile
;
2160 register struct partial_symtab
*pst
;
2163 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + f_idx
;
2165 /* Use this to indicate into which symtab this file was parsed */
2167 return (struct partial_symtab
*) fh
->ioptBase
;
2169 /* Debuggability level */
2170 if (compare_glevel(max_glevel
, fh
->glevel
) < 0)
2171 max_glevel
= fh
->glevel
;
2173 /* Make a new partial_symtab */
2174 pst
= new_psymtab(fh
->rss
, objfile
);
2179 pst
->textlow
= fh
->adr
;
2180 pst
->texthigh
= fh
->cpd
; /* To be fixed later */
2183 /* Make everything point to everything. */
2184 FDR_IDX(pst
) = f_idx
;
2185 fdr_to_pst
[f_idx
].pst
= pst
;
2186 fh
->ioptBase
= (int)pst
;
2188 /* Analyze its dependencies */
2193 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
2194 /* ...then presumably a .h file: drop reverse depends .h->.c */
2195 for (; s_id0
< fh
->crfd
; s_id0
++) {
2196 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
2198 s_id0
++; /* Skip self-dependency */
2203 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
2204 pst
->dependencies
= (struct partial_symtab
**)
2205 obstack_alloc (&objfile
->psymbol_obstack
,
2206 pst
->number_of_dependencies
*
2207 sizeof (struct partial_symtab
*));
2208 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
2209 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
2211 pst
->dependencies
[s_idx
-s_id0
] = parse_fdr(*rh
, lev
+1, objfile
);
2219 mips_next_symbol_text ()
2222 return (char*)((SYMR
*)cur_fdr
->isymBase
)[cur_sdx
].iss
;
2225 /* Ancillary function to psymtab_to_symtab(). Does all the work
2226 for turning the partial symtab PST into a symtab, recurring
2227 first on all dependent psymtabs. The argument FILENAME is
2228 only passed so we can see in debug stack traces what file
2232 psymtab_to_symtab_1(pst
, filename
)
2233 struct partial_symtab
*pst
;
2241 struct linetable
*lines
;
2247 /* How many symbols will we need */
2248 /* FIXME, this does not count enum values. */
2249 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
2250 if (FDR_IDX(pst
) == -1) {
2254 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + FDR_IDX(pst
);
2255 f_max
+= fh
->csym
+ fh
->cpd
;
2256 maxlines
= 2 * fh
->cline
;
2259 /* See comment in parse_partial_symbols about the @stabs sentinel. */
2262 && strcmp((char *)(((SYMR
*)fh
->isymBase
)[1].iss
), stabs_symbol
)
2267 st
= new_symtab (pst
->filename
, 2 * f_max
, maxlines
,
2270 st
= new_symtab ("unknown", f_max
, 0, pst
->objfile
);
2271 lines
= LINETABLE(st
);
2272 pending_list
= (struct mips_pending
**) cur_hdr
->cbOptOffset
;
2273 if (pending_list
== 0) {
2274 pending_list
= (struct mips_pending
**)
2275 xzalloc(cur_hdr
->ifdMax
* sizeof(struct mips_pending
*));
2276 cur_hdr
->cbOptOffset
= (int)pending_list
;
2280 /* Read in all partial symbtabs on which this one is dependent.
2281 NOTE that we do have circular dependencies, sigh. We solved
2282 that by setting pst->readin before this point. */
2284 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2285 if (!pst
->dependencies
[i
]->readin
) {
2286 /* Inform about additional files to be read in. */
2289 fputs_filtered (" ", stdout
);
2291 fputs_filtered ("and ", stdout
);
2293 printf_filtered ("%s...",
2294 pst
->dependencies
[i
]->filename
);
2295 wrap_here (""); /* Flush output */
2298 /* We only pass the filename for debug purposes */
2299 psymtab_to_symtab_1(pst
->dependencies
[i
],
2300 pst
->dependencies
[i
]->filename
);
2304 /* Now read the symbols for this symtab */
2306 current_objfile
= pst
-> objfile
;
2308 cur_fd
= FDR_IDX(pst
);
2311 /* Get a new lexical context */
2314 top_stack
->cur_st
= cur_stab
;
2315 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab
),
2317 BLOCK_START(top_stack
->cur_block
) = fh
? fh
->adr
: 0;
2318 BLOCK_END(top_stack
->cur_block
) = 0;
2319 top_stack
->blocktype
= stFile
;
2320 top_stack
->maxsyms
= 2*f_max
;
2321 top_stack
->cur_type
= 0;
2322 top_stack
->procadr
= 0;
2323 top_stack
->numargs
= 0;
2326 /* Parse locals and procedures */
2331 char *fh_name
= (char*)fh
->rss
;
2333 /* Parse local symbols first */
2339 current_objfile
= NULL
;
2342 for (cur_sdx
= 2; cur_sdx
< fh
->csym
; cur_sdx
++) {
2343 register SYMR
*sh
= cur_sdx
+ (SYMR
*) fh
->isymBase
;
2344 char *name
= (char*)sh
->iss
;
2345 CORE_ADDR valu
= sh
->value
;
2346 if (MIPS_IS_STAB(sh
)) {
2347 int type_code
= MIPS_UNMARK_STAB(sh
->index
);
2348 process_one_symbol (type_code
, 0, valu
, name
, /*FIXME*/ 0);
2350 else if (sh
->st
== stLabel
&& sh
->index
!= indexNil
) {
2351 /* Handle encoded stab line number. */
2352 record_line (current_subfile
, sh
->index
, valu
);
2355 st
= end_symtab (pst
->texthigh
, 0, 0, pst
->objfile
);
2358 /* BOUND is the highest core address of this file's procedures */
2359 int bound
= cur_fd
== cur_hdr
->ifdMax
- 1 ? cur_hdr
->cbDnOffset
2361 for (cur_sdx
= 0; cur_sdx
< fh
->csym
; ) {
2362 sh
= (SYMR
*) (fh
->isymBase
) + cur_sdx
;
2363 cur_sdx
+= parse_symbol(sh
, fh
->iauxBase
, fh
->fBigendian
);
2366 /* Procedures next, note we need to look-ahead to
2367 find out where the procedure's code ends */
2370 for (i
= 0; i
< fh
->cpd
-1; i
++) {
2371 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2372 parse_procedure(pr
, pr
[1].adr
); /* next proc up */
2375 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + i
;
2376 parse_procedure(pr
, bound
); /* next file up */
2378 /* Linenumbers. At the end, check if we can save memory */
2379 parse_lines(fh
, lines
);
2380 if (lines
->nitems
< fh
->cline
)
2381 lines
= shrink_linetable(lines
);
2387 LINETABLE(st
) = lines
;
2389 /* .. and our share of externals.
2390 XXX use the global list to speed up things here. how ?
2391 FIXME, Maybe quit once we have found the right number of ext's? */
2392 /* parse_external clobbers top_stack->cur_block and ->cur_st here. */
2393 top_stack
->blocktype
= stFile
;
2394 top_stack
->maxsyms
=
2395 cur_hdr
->isymMax
+ cur_hdr
->ipdMax
+ cur_hdr
->iextMax
;
2397 ext_ptr
= PST_PRIVATE(pst
)->extern_tab
;
2398 for (i
= PST_PRIVATE(pst
)->extern_count
; --i
>= 0; ext_ptr
++)
2399 parse_external(*ext_ptr
, 1, fh
->fBigendian
);
2401 /* If there are undefined, tell the user */
2402 if (n_undef_symbols
) {
2403 printf_filtered("File %s contains %d unresolved references:",
2404 st
->filename
, n_undef_symbols
);
2405 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2406 n_undef_vars
, n_undef_procs
, n_undef_labels
);
2407 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
2413 /* Sort the symbol table now, we are done adding symbols to it.*/
2414 sort_symtab_syms(st
);
2418 /* Now link the psymtab and the symtab. */
2421 current_objfile
= NULL
;
2424 /* Ancillary parsing procedures. */
2426 /* Lookup the type at relative index RN. Return it in TPP
2427 if found and in any event come up with its name PNAME.
2428 BIGEND says whether aux symbols are big-endian or not (from fh->fBigendian).
2429 Return value says how many aux symbols we ate. */
2432 cross_ref(ax
, tpp
, type_code
, pname
, bigend
)
2435 int type_code
; /* Use to alloc new type if none is found. */
2443 ecoff_swap_rndx_in (bigend
, ax
, rn
);
2445 /* Escape index means 'the next one' */
2446 if (rn
->rfd
== 0xfff) {
2448 rf
= AUX_GET_ISYM (bigend
, ax
+ 1);
2455 *pname
= "<undefined>";
2458 * Find the relative file descriptor and the symbol in it
2460 FDR
*fh
= get_rfd(cur_fd
, rf
);
2465 * If we have processed this symbol then we left a forwarding
2466 * pointer to the corresponding GDB symbol. If not, we`ll put
2467 * it in a list of pending symbols, to be processed later when
2468 * the file f will be. In any event, we collect the name for
2469 * the type here. Which is why we made a first pass at
2472 sh
= (SYMR
*) (fh
->isymBase
) + rn
->index
;
2474 /* Careful, we might be looking at .o files */
2475 *pname
= (UNSAFE_DATA_ADDR(sh
->iss
)) ? "<undefined>" :
2478 /* Have we parsed it ? */
2479 if ((!UNSAFE_DATA_ADDR(sh
->value
)) && (sh
->st
== stParsed
)) {
2480 t
= (struct type
*) sh
->value
;
2483 /* Avoid duplicates */
2484 struct mips_pending
*p
= is_pending_symbol(fh
, sh
);
2488 *tpp
= init_type(type_code
, 0, 0, 0, (struct objfile
*) NULL
);
2489 add_pending(fh
, sh
, *tpp
);
2494 /* We used one auxent normally, two if we got a "next one" rf. */
2499 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2500 keeping the symtab sorted */
2502 static struct symbol
*
2503 mylookup_symbol (name
, block
, namespace, class)
2505 register struct block
*block
;
2506 enum namespace namespace;
2507 enum address_class
class;
2509 register int bot
, top
, inc
;
2510 register struct symbol
*sym
;
2513 top
= BLOCK_NSYMS(block
);
2516 sym
= BLOCK_SYM(block
, bot
);
2517 if (SYMBOL_NAME(sym
)[0] == inc
2518 && SYMBOL_NAMESPACE(sym
) == namespace
2519 && SYMBOL_CLASS(sym
) == class
2520 && !strcmp(SYMBOL_NAME(sym
), name
))
2524 if (block
= BLOCK_SUPERBLOCK (block
))
2525 return mylookup_symbol (name
, block
, namespace, class);
2530 /* Add a new symbol S to a block B.
2531 Infrequently, we will need to reallocate the block to make it bigger.
2532 We only detect this case when adding to top_stack->cur_block, since
2533 that's the only time we know how big the block is. FIXME. */
2540 int nsyms
= BLOCK_NSYMS(b
)++;
2541 struct block
*origb
;
2542 struct parse_stack
*stackp
;
2544 if (b
== top_stack
->cur_block
&&
2545 nsyms
>= top_stack
->maxsyms
) {
2546 complain (&block_overflow_complaint
, s
->name
);
2547 /* In this case shrink_block is actually grow_block, since
2548 BLOCK_NSYMS(b) is larger than its current size. */
2550 b
= shrink_block (top_stack
->cur_block
, top_stack
->cur_st
);
2552 /* Now run through the stack replacing pointers to the
2553 original block. shrink_block has already done this
2554 for the blockvector and BLOCK_FUNCTION. */
2555 for (stackp
= top_stack
; stackp
; stackp
= stackp
->next
) {
2556 if (stackp
->cur_block
== origb
) {
2557 stackp
->cur_block
= b
;
2558 stackp
->maxsyms
= BLOCK_NSYMS (b
);
2562 BLOCK_SYM(b
,nsyms
) = s
;
2565 /* Add a new block B to a symtab S */
2572 struct blockvector
*bv
= BLOCKVECTOR(s
);
2574 bv
= (struct blockvector
*)xrealloc((char *) bv
,
2575 sizeof(struct blockvector
) +
2576 BLOCKVECTOR_NBLOCKS(bv
)
2577 * sizeof(bv
->block
));
2578 if (bv
!= BLOCKVECTOR(s
))
2579 BLOCKVECTOR(s
) = bv
;
2581 BLOCKVECTOR_BLOCK(bv
, BLOCKVECTOR_NBLOCKS(bv
)++) = b
;
2584 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2585 MIPS' linenumber encoding might need more than one byte
2586 to describe it, LAST is used to detect these continuation lines */
2589 add_line(lt
, lineno
, adr
, last
)
2590 struct linetable
*lt
;
2596 last
= -2; /* make sure we record first line */
2598 if (last
== lineno
) /* skip continuation lines */
2601 lt
->item
[lt
->nitems
].line
= lineno
;
2602 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
2608 /* Comparison functions, used when sorting things */
2610 /* Symtabs must be ordered viz the code segments they cover */
2613 compare_symtabs( s1
, s2
)
2614 struct symtab
**s1
, **s2
;
2616 /* "most specific" first */
2618 register struct block
*b1
, *b2
;
2619 b1
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1
),GLOBAL_BLOCK
);
2620 b2
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2
),GLOBAL_BLOCK
);
2621 if (BLOCK_END(b1
) == BLOCK_END(b2
))
2622 return BLOCK_START(b1
) - BLOCK_START(b2
);
2623 return BLOCK_END(b1
) - BLOCK_END(b2
);
2627 /* Partial Symtabs, same */
2630 compare_psymtabs( s1
, s2
)
2631 struct partial_symtab
**s1
, **s2
;
2633 /* Perf twist: put the ones with no code at the end */
2635 register int a
= (*s1
)->textlow
;
2636 register int b
= (*s2
)->textlow
;
2645 /* Blocks with a smaller low bound should come first */
2647 static int compare_blocks(b1
,b2
)
2648 struct block
**b1
, **b2
;
2650 register int addr_diff
;
2652 addr_diff
= (BLOCK_START((*b1
))) - (BLOCK_START((*b2
)));
2654 return (BLOCK_END((*b1
))) - (BLOCK_END((*b2
)));
2659 /* Sorting and reordering procedures */
2661 /* Sort the blocks of a symtab S.
2662 Reorder the blocks in the blockvector by code-address,
2663 as required by some MI search routines */
2669 struct blockvector
*bv
= BLOCKVECTOR(s
);
2671 if (BLOCKVECTOR_NBLOCKS(bv
) <= 2) {
2673 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) == 0)
2674 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = 0;
2675 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) == 0)
2676 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) = 0;
2680 * This is very unfortunate: normally all functions are compiled in
2681 * the order they are found, but if the file is compiled -O3 things
2682 * are very different. It would be nice to find a reliable test
2683 * to detect -O3 images in advance.
2685 if (BLOCKVECTOR_NBLOCKS(bv
) > 3)
2686 qsort(&BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
),
2687 BLOCKVECTOR_NBLOCKS(bv
) - FIRST_LOCAL_BLOCK
,
2688 sizeof(struct block
*),
2692 register CORE_ADDR high
= 0;
2693 register int i
, j
= BLOCKVECTOR_NBLOCKS(bv
);
2695 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
2696 if (high
< BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
)))
2697 high
= BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
));
2698 BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = high
;
2701 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) =
2702 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
));
2704 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2705 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2706 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2707 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2711 /* Constructor/restructor/destructor procedures */
2713 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2714 MAXSYMS and linenumbers MAXLINES we'll put in it */
2718 new_symtab(name
, maxsyms
, maxlines
, objfile
)
2722 struct objfile
*objfile
;
2724 struct symtab
*s
= allocate_symtab (name
, objfile
);
2726 LINETABLE(s
) = new_linetable(maxlines
);
2728 /* All symtabs must have at least two blocks */
2729 BLOCKVECTOR(s
) = new_bvect(2);
2730 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
) = new_block(maxsyms
);
2731 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), STATIC_BLOCK
) = new_block(maxsyms
);
2732 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
),STATIC_BLOCK
)) =
2733 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
);
2735 s
->free_code
= free_linetable
;
2740 /* Allocate a new partial_symtab NAME */
2742 static struct partial_symtab
*
2743 new_psymtab(name
, objfile
)
2745 struct objfile
*objfile
;
2747 struct partial_symtab
*psymtab
;
2749 /* FIXME -- why (char *) -1 rather than NULL? */
2750 psymtab
= allocate_psymtab (name
== (char *) -1 ? "<no name>" : name
,
2753 /* Keep a backpointer to the file's symbols */
2755 psymtab
-> read_symtab_private
= (char *)
2756 obstack_alloc (&objfile
->psymbol_obstack
, sizeof (struct symloc
));
2757 CUR_HDR(psymtab
) = cur_hdr
;
2759 /* The way to turn this into a symtab is to call... */
2760 psymtab
->read_symtab
= mipscoff_psymtab_to_symtab
;
2765 /* Allocate a linetable array of the given SIZE */
2767 static struct linetable
*
2770 struct linetable
*l
;
2772 size
= size
* sizeof(l
->item
) + sizeof(struct linetable
);
2773 l
= (struct linetable
*)xmalloc(size
);
2778 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2779 I am not so sure about the 3.4 ones */
2781 static struct linetable
*
2782 shrink_linetable(lt
)
2783 struct linetable
* lt
;
2785 struct linetable
*l
= new_linetable(lt
->nitems
);
2787 memcpy(l
, lt
, lt
->nitems
* sizeof(l
->item
) + sizeof(struct linetable
));
2792 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2795 struct blockvector
*
2798 struct blockvector
*bv
;
2801 size
= sizeof(struct blockvector
) + nblocks
* sizeof(struct block
*);
2802 bv
= (struct blockvector
*) xzalloc(size
);
2804 BLOCKVECTOR_NBLOCKS(bv
) = nblocks
;
2809 /* Allocate and zero a new block of MAXSYMS symbols */
2815 int size
= sizeof(struct block
) + (maxsyms
-1) * sizeof(struct symbol
*);
2816 struct block
*b
= (struct block
*)xzalloc(size
);
2821 /* Ooops, too big. Shrink block B in symtab S to its minimal size.
2822 Shrink_block can also be used by add_symbol to grow a block. */
2824 static struct block
*
2830 struct blockvector
*bv
= BLOCKVECTOR(s
);
2833 /* Just reallocate it and fix references to the old one */
2835 new = (struct block
*) xrealloc ((char *)b
, sizeof(struct block
) +
2836 (BLOCK_NSYMS(b
)-1) * sizeof(struct symbol
*));
2838 /* Should chase pointers to old one. Fortunately, that`s just
2839 the block`s function and inferior blocks */
2840 if (BLOCK_FUNCTION(new) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) == b
)
2841 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(new)) = new;
2842 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2843 if (BLOCKVECTOR_BLOCK(bv
,i
) == b
)
2844 BLOCKVECTOR_BLOCK(bv
,i
) = new;
2845 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) == b
)
2846 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) = new;
2850 /* Create a new symbol with printname NAME */
2857 struct symbol
*s
= (struct symbol
*)
2858 obstack_alloc (¤t_objfile
->symbol_obstack
, sizeof (struct symbol
));
2860 memset (s
, 0, sizeof (*s
));
2861 SYMBOL_NAME(s
) = name
;
2865 /* Create a new type with printname NAME */
2874 t
= alloc_type (current_objfile
);
2875 TYPE_NAME(t
) = name
;
2876 TYPE_CPLUS_SPECIFIC(t
) = (struct cplus_struct_type
*)
2877 &cplus_struct_default
;
2882 /* Things used for calling functions in the inferior.
2883 These functions are exported to our companion
2884 mips-tdep.c file and are here because they play
2885 with the symbol-table explicitly. */
2887 /* Sigtramp: make sure we have all the necessary information
2888 about the signal trampoline code. Since the official code
2889 from MIPS does not do so, we make up that information ourselves.
2890 If they fix the library (unlikely) this code will neutralize itself. */
2897 struct block
*b
, *b0
;
2899 sigtramp_address
= -1;
2901 /* We know it is sold as sigvec */
2902 s
= lookup_symbol("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
2904 /* Most programs do not play with signals */
2908 b0
= SYMBOL_BLOCK_VALUE(s
);
2910 /* A label of sigvec, to be more precise */
2911 s
= lookup_symbol("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
2913 /* But maybe this program uses its own version of sigvec */
2917 sigtramp_address
= SYMBOL_VALUE(s
);
2918 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
2920 /* Did we or MIPSco fix the library ? */
2921 if (SYMBOL_CLASS(s
) == LOC_BLOCK
)
2924 /* But what symtab does it live in ? */
2925 st
= find_pc_symtab(SYMBOL_VALUE(s
));
2928 * Ok, there goes the fix: turn it into a procedure, with all the
2929 * needed info. Note we make it a nested procedure of sigvec,
2930 * which is the way the (assembly) code is actually written.
2932 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2933 SYMBOL_CLASS(s
) = LOC_BLOCK
;
2934 SYMBOL_TYPE(s
) = init_type(TYPE_CODE_FUNC
, 4, 0, 0, (struct objfile
*) NULL
);
2935 TYPE_TARGET_TYPE(SYMBOL_TYPE(s
)) = builtin_type_void
;
2937 /* Need a block to allocate .gdbinfo. in */
2939 SYMBOL_BLOCK_VALUE(s
) = b
;
2940 BLOCK_START(b
) = sigtramp_address
;
2941 BLOCK_END(b
) = sigtramp_end
;
2942 BLOCK_FUNCTION(b
) = s
;
2943 BLOCK_SUPERBLOCK(b
) = BLOCK_SUPERBLOCK(b0
);
2947 /* Make a .gdbinfo. for it */
2949 struct mips_extra_func_info
*e
=
2950 (struct mips_extra_func_info
*)
2951 xzalloc(sizeof(struct mips_extra_func_info
));
2953 e
->numargs
= 0; /* the kernel thinks otherwise */
2954 /* align_longword(sigcontext + SIGFRAME) */
2955 e
->framesize
= 0x150;
2956 e
->framereg
= SP_REGNUM
;
2959 e
->regoffset
= -(41 * sizeof(int));
2961 e
->fregoffset
= -(37 * sizeof(int));
2964 s
= new_symbol(".gdbinfo.");
2965 SYMBOL_VALUE(s
) = (int) e
;
2966 SYMBOL_NAMESPACE(s
) = LABEL_NAMESPACE
;
2967 SYMBOL_CLASS(s
) = LOC_CONST
;
2968 SYMBOL_TYPE(s
) = builtin_type_void
;
2971 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
2974 /* Initialization */
2976 static struct sym_fns ecoff_sym_fns
=
2978 "ecoff", /* sym_name: name or name prefix of BFD target type */
2979 5, /* sym_namelen: number of significant sym_name chars */
2980 mipscoff_new_init
, /* sym_new_init: init anything gbl to entire symtab */
2981 mipscoff_symfile_init
,/* sym_init: read initial info, setup for sym_read() */
2982 mipscoff_symfile_read
,/* sym_read: read a symbol file into symtab */
2983 mipscoff_symfile_finish
,/* sym_finish: finished with file, cleanup */
2984 NULL
/* next: pointer to next struct sym_fns */
2988 _initialize_mipsread ()
2990 add_symtab_fns (&ecoff_sym_fns
);
2992 /* Missing basic types */
2993 builtin_type_string
=
2994 init_type (TYPE_CODE_PASCAL_ARRAY
,
2996 (struct objfile
*) NULL
);
2997 builtin_type_complex
=
2998 init_type(TYPE_CODE_FLT
,
2999 2 * sizeof(float), 0, "complex",
3000 (struct objfile
*) NULL
);
3001 builtin_type_double_complex
=
3002 init_type(TYPE_CODE_FLT
,
3003 2 * sizeof(double), 0, "double_complex",
3004 (struct objfile
*) NULL
);
3005 builtin_type_fixed_dec
=
3006 init_type(TYPE_CODE_INT
, sizeof(int),
3008 (struct objfile
*) NULL
);
3009 builtin_type_float_dec
=
3010 init_type(TYPE_CODE_FLT
, sizeof(double),
3011 0, "floating_decimal",
3012 (struct objfile
*) NULL
);