1 /* Read a symbol table in MIPS' format (Third-Eye).
2 Copyright (C) 1986, 1987, 1989-1991 Free Software Foundation, Inc.
3 Contributed by Alessandro Forin (af@cs.cmu.edu) at CMU
5 This file is part of GDB.
7 GDB is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 1, or (at your option)
12 GDB is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GDB; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include <sys/param.h>
32 #include <mips/syms.h>
35 #endif /* not CMUCS */
37 /* Since these things are defined differently on various systems I'll
38 (re)define here what I really need in this module. I only assume the
39 three standard COFF structure definitions: filehdr, aouthdr, scnhdr */
40 #define MIPS /* Kludge to get MIPS version of coff */
41 #include "intel-coff.h"
53 #define a_magic a.magic /* magic number */
54 #define a_text a.tsize /* size of text segment */
55 #define a_data a.dsize /* size of initialized data */
56 #define a_bss a.bsize /* size of uninitialized data */
57 #define a_syms f.f_nsyms /* size of symbol table */
58 #define a_entry a.entry /* entry point */
62 (((x).a_magic)!=OMAGIC && ((x).a_magic)!=NMAGIC && ((x).a_magic)!=ZMAGIC)
64 /* Things we import explicitly from other modules */
66 extern int info_verbose
;
67 extern struct block
*block_for_pc();
68 extern void sort_symtab_syms();
70 /* Forward declarations */
72 static void psymtab_to_symtab_1();
74 /* Macros and extra defs */
76 struct complaint unknown_ext_complaint
=
77 {"unknown external symbol %s", 0, 0};
79 /* Already parsed symbols are marked specially */
81 #define stParsed stType
83 /* Puns: hard to find whether -g was used and how */
85 #define MIN_GLEVEL GLEVEL_0
86 #define compare_glevel(a,b) \
87 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
88 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
90 /* When looking at .o files avoid tripping over bad addresses */
92 #define SAFE_TEXT_ADDR 0x400000
93 #define SAFE_DATA_ADDR 0x10000000
95 #define UNSAFE_DATA_ADDR(p) ((unsigned)p < SAFE_DATA_ADDR || (unsigned)p > 2*SAFE_DATA_ADDR)
98 /* Things we export to other modules */
101 /* Lists of partial symbols */
103 struct psymbol_allocation_list global_psymbols
, static_psymbols
;
105 /* Address bounds for the signal trampoline in inferior, if any */
107 CORE_ADDR sigtramp_address
, sigtramp_end
;
110 /* Functions that we really export */
112 /* THIS DESCRIPTION IS OBSOLETE POST-BFD; FIXME! */
113 /* Basically, this module must provide two functions: symbol_file_command()
114 which loads the symbol table from a file, and add_file_command() which
115 adds more symbols to the symbol table (incrementally).
117 These two functions only do the minimum work necessary for letting the
118 user "name" things symbolically, they do not read the entire symtab.
119 Instead, they read in the external symbols and put them in partial
120 symbol tables. When more extensive information is requested of a
121 file the corresponding partial symbol table is mutated into a full
122 fledged symbol table by going back and reading the relative symbols
123 for real. mipscoff_psymtab_to_symtab() is the function that does this */
125 /* The entry point (starting address) of the file, if it is an executable. */
127 static CORE_ADDR entry_point
;
129 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
130 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
138 mipscoff_symfile_init (sf
)
141 bfd
*abfd
= sf
->sym_bfd
;
142 sf
->sym_private
= NULL
;
143 /* Save startup file's range of PC addresses to help blockframe.c
144 decide where the bottom of the stack is. */
145 if (bfd_get_file_flags (abfd
) & EXEC_P
)
147 /* Executable file -- record its entry point so we'll recognize
148 the startup file because it contains the entry point. */
149 entry_point
= bfd_get_start_address (abfd
);
153 /* Examination of non-executable.o files. Short-circuit this stuff. */
154 /* ~0 will not be in any file, we hope. */
156 /* set the startup file to be an empty range. */
157 startup_file_start
= 0;
158 startup_file_end
= 0;
163 mipscoff_symfile_read(sf
, addr
, mainline
)
168 struct coff_symfile_info
*info
= (struct coff_symfile_info
*)sf
->sym_private
;
169 bfd
*abfd
= sf
->sym_bfd
;
170 char *name
= bfd_get_filename (abfd
);
175 int stringtab_offset
;
177 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
178 desc
= fileno ((FILE *)(abfd
->iostream
)); /* Raw file descriptor */
179 num_symbols
= bfd_get_symcount (abfd
); /* How many syms */
180 /* symtab_offset = obj_sym_filepos (abfd); * Symbol table file offset */
181 /* stringtab_offset = symtab_offset + num_symbols * SYMESZ; * String tab */
185 debug_info
= text_hdr
.s_relptr
;
188 dc_terminate (tdesc_handle
);
194 /* Read the line number table, all at once. */
195 info
->min_lineno_offset
= 0;
196 info
->max_lineno_offset
= 0;
197 bfd_map_over_sections (abfd
, find_linenos
, info
);
199 val
= init_lineno (desc
, info
->min_lineno_offset
,
200 info
->max_lineno_offset
- info
->min_lineno_offset
);
202 error ("\"%s\": error reading line numbers\n", name
);
204 /* Now read the string table, all at once. */
206 val
= init_stringtab (desc
, stringtab_offset
);
209 free_all_symtabs (); /* FIXME blows whole symtab */
210 printf ("\"%s\": can't get string table", name
);
214 make_cleanup (free_stringtab
, 0);
216 /* Position to read the symbol table. Do not read it all at once. */
217 val
= lseek (desc
, (long)symtab_offset
, 0);
219 perror_with_name (name
);
221 init_misc_bunches ();
222 make_cleanup (discard_misc_bunches
, 0);
224 /* Now that the executable file is positioned at symbol table,
225 process it and define symbols accordingly. */
227 printf("Reading symbol data from %s...", name
);
229 read_mips_symtab(desc
, 0);
231 /* patch_opaque_types ();*/
233 /* Sort symbols alphabetically within each block. */
235 sort_all_symtab_syms ();
237 /* Go over the misc symbol bunches and install them in vector. */
239 condense_misc_bunches (0);
241 /* Make a default for file to list. */
243 select_source_symtab (0); /* FIXME, this might be too slow, see dbxread */
247 mipscoff_symfile_discard()
253 /* Exported procedure: Reads symbols from file NAME.
254 Invoked at startup time if executable was given.
255 When invoked cleans up the world */
258 symbol_file_command(name
, from_tty
)
263 struct coff_exec hdr
;
266 struct cleanup
*old_chain
;
271 * Make sure s/he means it
274 if ((symtab_list
|| partial_symtab_list
)
276 && !query("Discard symbol table? ", 0))
277 error("Not confirmed.");
278 destroy_all_symtabs();
282 name
= tilde_expand(name
);
283 make_cleanup(free
, name
);
286 !query("Load new symbol table from \"%s\"? ", name
))
287 error("Not confirmed.");
292 desc
= openp (getenv ("PATH"), 1, name
, O_RDONLY
, 0, &absolute_name
);
294 perror_with_name (name
);
296 name
= absolute_name
;
299 old_chain
= make_cleanup (close
, desc
);
300 make_cleanup (free_current_contents
, &name
);
303 * Check file is indeed executable
305 val
= myread(desc
, &hdr
, sizeof hdr
);
307 perror_with_name(name
);
310 error("File \"%s\" not in executable format.", name
);
312 if (hdr
.a
.entry
< SAFE_TEXT_ADDR
&& access(name
, 1))
313 printf_filtered("Warning: %s is not executable!\n", name
);
315 if (hdr
.a_syms
== 0) {
316 printf_filtered("%s does not have a symbol-table.\n", name
);
321 /* Get the modification time. */
325 if (fstat (desc
, &symstat
) < 0)
326 perror_with_name (name
);
328 symfile_mtime
= symstat
.st_mtime
;
332 * Throw away the old symbol table.
335 destroy_all_symtabs();
337 /* Make a default for file to list. */
339 symfile
= savestring (name
, strlen (name
));
341 /* Prepare to remember misc symbol values */
343 init_misc_bunches ();
344 make_cleanup (discard_misc_bunches
, 0);
347 * Now read the new symbol table
350 read_mips_symtab(desc
, 0);
352 /* Go over the misc symbol bunches and install them in vector. */
354 condense_misc_bunches (0);
356 /* Don't allow char * to have a typename (else would get caddr_t.) */
358 TYPE_NAME (lookup_pointer_type (builtin_type_char
)) = 0;
360 /* Force reinit of the sigtramp info */
361 sigtramp_address
= 0;
363 do_cleanups (old_chain
); /* Descriptor closed here */
365 if (!partial_symtab_list
)
366 printf ("\n(no debugging symbols found)...");
374 This function allows the addition of incrementally linked object files.
375 Since this has a fair amount of code in common with symbol_file_command,
376 it might be worthwhile to consolidate things, as was done with
377 read_dbx_symtab and condense_misc_bunches. */
379 /* Exported procedure: add more symbols from file NAME. */
382 add_file_command(arg_string
)
386 struct coff_exec hdr
;
389 struct cleanup
*old_chain
;
394 error ("add-file takes a file name and an address");
397 error ("add-file takes a file name and an address");
399 arg_string
= tilde_expand (arg_string
);
400 make_cleanup (free
, arg_string
);
402 for( ; *arg_string
== ' '; arg_string
++ );
404 for( ; *arg_string
&& *arg_string
!= ' ' ; arg_string
++ );
405 *arg_string
++ = (char) 0;
408 error ("add-file takes a file name and an address");
410 text_addr
= parse_and_eval_address (arg_string
);
414 if (!query ("add symbol table from filename \"%s\" at text_addr = 0x%x\n",
416 error ("Not confirmed.");
424 desc
= openp(getenv("PATH"), 1, name
, O_RDONLY
, 0, &absolute_name
);
426 perror_with_name(name
);
428 name
= absolute_name
;
430 old_chain
= make_cleanup (close
, desc
);
434 * Check file is indeed executable
436 val
= myread(desc
, &hdr
, sizeof hdr
);
438 perror_with_name(name
);
441 error("File \"%s\" not in executable format.", name
);
443 if (hdr
.a
.entry
< SAFE_TEXT_ADDR
&& access(name
, 1))
444 printf_filtered("Warning: %s is not executable!\n", name
);
446 if (hdr
.a_syms
== 0) {
447 printf_filtered("%s does not have a symbol-table.\n", name
);
457 * Now read the new symbol table
460 symfile
= savestring(name
, strlen(name
));
462 init_misc_bunches ();
463 make_cleanup (discard_misc_bunches
, 0);
464 read_mips_symtab(desc
, 1);
466 /* Go over the misc symbol bunches and install them in vector. */
468 condense_misc_bunches (1);
470 /* Don't allow char * to have a typename (else would get caddr_t.) */
472 TYPE_NAME (lookup_pointer_type (builtin_type_char
)) = 0;
474 do_cleanups (old_chain
);
476 printf_filtered("done.\n");
480 /* Exported procedure: Allocate zeroed memory */
484 char *p
= xmalloc(size
);
490 /* Exported procedure: Builds a symtab from the PST partial one.
491 Restores the environment in effect when PST was created, delegates
492 most of the work to an ancillary procedure, and sorts
493 and reorders the symtab list at the end */
496 static HDRR
*cur_hdr
; /* MIPS symtab header for the current file */
499 mipscoff_psymtab_to_symtab(pst
)
500 struct partial_symtab
*pst
;
509 printf_filtered("Reading in symbols for %s...", pst
->filename
);
512 /* Restore the header and list of pending typedefs */
513 cur_hdr
= (HDRR
*) pst
->ldsymlen
;
515 psymtab_to_symtab_1(pst
);
519 /* Finish up the debug error message. */
521 printf_filtered("done.\n");
524 /* Exported procedure: Is PC in the signal trampoline code */
526 int in_sigtramp(pc
,name
)
529 if (sigtramp_address
== 0)
531 return (pc
>= sigtramp_address
&& pc
< sigtramp_end
);
535 /* Things that really are local to this module */
537 /* All allocated symtabs and psymtabs */
539 static int all_symtabs_count
;
540 static int all_psymtabs_count
;
542 /* GDB symtable for the current compilation unit */
544 static struct symtab
*cur_stab
;
546 /* Header for executable/object file we read symbols from */
548 static struct coff_exec filhdr
;
549 #define END_OF_TEXT_SEGMENT(f) ((f).a.text_start + (f).a.tsize)
551 /* Pointer to current file decriptor record, and its index */
556 /* Index of current symbol */
560 /* Note how much "debuggable" this image is. We would like
561 to see at least one FDR with full symbols */
566 /* When examining .o files, report on undefined symbols */
568 static int n_undef_symbols
, n_undef_labels
, n_undef_vars
, n_undef_procs
;
570 /* Extra builtin types */
572 struct type
*builtin_type_complex
;
573 struct type
*builtin_type_double_complex
;
574 struct type
*builtin_type_fixed_dec
;
575 struct type
*builtin_type_float_dec
;
576 struct type
*builtin_type_string
;
580 static struct type
*builtin_type_ptr
;
581 static struct type
*builtin_type_struct
;
582 static struct type
*builtin_type_union
;
583 static struct type
*builtin_type_enum
;
584 static struct type
*builtin_type_range
;
585 static struct type
*builtin_type_set
;
590 static struct symbol
*new_symbol();
591 static struct type
*new_type();
592 static struct field
*new_field();
593 static struct block
*new_block();
594 static struct symtab
*new_symtab();
595 static struct linetable
*new_linetable();
596 static struct blockvector
*new_bvect();
598 static struct type
*parse_type();
599 static struct type
*make_type();
600 static struct symbol
*mylookup_symbol();
601 static struct block
*shrink_block();
603 static int compare_symtabs();
604 static int compare_psymtabs();
605 static int compare_blocks();
607 static struct partial_symtab
*new_psymtab();
608 static struct partial_symbol
*new_psymbol();
609 static struct partial_symtab
*parse_fdr();
610 static int compare_psymbols();
612 /* File-level interface functions */
614 /* Read the symtab information from file FSYM into memory */
617 read_the_mips_symtab(fsym
)
619 int stsize
, st_hdrsize
;
623 /* Find and read the symbol table header */
624 st_hdrsize
= filhdr
.f
.f_nsyms
;
625 st_filptr
= filhdr
.f
.f_symptr
;
629 lseek(fsym
, st_filptr
, L_SET
);
630 if (read(fsym
, &st_hdr
, st_hdrsize
) != st_hdrsize
)
633 /* Find out how large the symbol table is */
634 stsize
= (st_hdr
.cbExtOffset
- (st_filptr
+ st_hdrsize
))
635 + st_hdr
.iextMax
* cbEXTR
;
637 /* Allocate space for the symbol table. Read it in. */
638 cur_hdr
= (HDRR
*) xmalloc(stsize
+ st_hdrsize
);
640 bcopy(&st_hdr
, cur_hdr
, st_hdrsize
);
641 if (read(fsym
, (char *) cur_hdr
+ st_hdrsize
, stsize
) != stsize
)
644 /* Fixup file_pointers in it */
645 fixup_symtab(cur_hdr
, (char *) cur_hdr
+ st_hdrsize
,
646 st_filptr
+ st_hdrsize
);
650 error("Short read on %s", symfile
);
654 /* Turn all file-relative pointers in the symtab described by HDR
655 into memory pointers, given that the symtab itself is located
656 at DATA in memory and F_PTR in the file. */
659 fixup_symtab( hdr
, data
, f_ptr
)
671 * These fields are useless (and empty) by now:
672 * hdr->cbDnOffset, hdr->cbOptOffset
673 * We use them for other internal purposes.
676 hdr
->cbOptOffset
= 0;
679 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
695 * Fix all string pointers inside the symtab, and
696 * the FDR records. Also fix other miscellany.
698 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
699 register unsigned code_offset
;
701 /* Header itself, and strings */
702 fh
= (FDR
*) (hdr
->cbFdOffset
) + f_idx
;
703 fh
->issBase
+= hdr
->cbSsOffset
;
705 fh
->rss
= (long)fh
->rss
+ fh
->issBase
;
706 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
707 sh
= (SYMR
*)(hdr
->cbSymOffset
) + fh
->isymBase
+ s_idx
;
708 sh
->iss
= (long) sh
->iss
+ fh
->issBase
;
715 fh
->isymBase
= (int)((SYMR
*)(hdr
->cbSymOffset
)+fh
->isymBase
);
717 /* cannot fix fh->ipdFirst because it is a short */
718 #define IPDFIRST(h,fh) \
719 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
721 /* Optional symbols (actually used for partial_symtabs) */
727 fh
->iauxBase
= hdr
->cbAuxOffset
+ fh
->iauxBase
* sizeof(AUXU
);
728 /* Relative file descriptor table */
729 fh
->rfdBase
= hdr
->cbRfdOffset
+ fh
->rfdBase
* sizeof(RFDT
);
733 fh
->cbLineOffset
+= hdr
->cbLineOffset
;
735 /* Procedure symbols. (XXX This should be done later) */
736 code_offset
= fh
->adr
;
737 for (s_idx
= 0; s_idx
< fh
->cpd
; s_idx
++) {
738 unsigned name
, only_ext
;
740 pr
= (PDR
*)(IPDFIRST(hdr
,fh
)) + s_idx
;
742 /* Simple rule to find files linked "-x" */
743 only_ext
= fh
->rss
== -1;
745 if (pr
->isym
== -1) {
746 /* static function */
750 name
= hdr
->cbExtOffset
+ pr
->isym
* sizeof(EXTR
);
751 sh
= &((EXTR
*)name
)->asym
;
755 sh
= (SYMR
*)fh
->isymBase
+ pr
->isym
;
756 /* Included code ? */
757 if (s_idx
== 0 && pr
->adr
!= 0)
758 code_offset
-= pr
->adr
;
761 /* Turn index into a pointer */
764 /* Fix line numbers */
765 pr
->cbLineOffset
+= fh
->cbLineOffset
;
767 /* Relocate address */
769 pr
->adr
+= code_offset
;
773 /* External symbols: fix string */
774 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
775 esh
= (EXTR
*)(hdr
->cbExtOffset
) + s_idx
;
776 esh
->asym
.iss
= esh
->asym
.iss
+ hdr
->cbSsExtOffset
;
781 /* Find a file descriptor given its index RF relative to a file CF */
784 FDR
*get_rfd( cf
, rf
)
788 f
= (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
789 /* Object files do not have the RFD table, all refs are absolute */
791 return (FDR
*) (cur_hdr
->cbFdOffset
) + rf
;
792 cf
= *((pRFDT
) f
->rfdBase
+ rf
);
793 return (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
796 /* Return a safer print NAME for a file descriptor */
802 if (name
== (char *) -1)
803 return "<stripped file>";
804 if (UNSAFE_DATA_ADDR(name
))
810 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
811 whether we are adding to the general symtab or not */
814 read_mips_symtab( desc
, incremental
)
817 * We get here with DESC pointing to the symtab header. But we need
818 * other info from the initial headers
821 myread(desc
, &filhdr
, sizeof filhdr
);
823 read_the_mips_symtab(desc
);
825 parse_partial_symbols(cur_hdr
, incremental
);
829 * Check to make sure file was compiled with -g.
830 * If not, warn the user of this limitation.
832 if (compare_glevel(max_glevel
, GLEVEL_2
) < 0) {
833 if (max_gdbinfo
== 0)
834 printf("\n%s not compiled with -g, debugging support is limited.", symfile
);
835 printf("\nYou should compile with -g2 or -g3 for best debugging support.\n");
840 * Dont allow char * to have a typename (else would get
843 TYPE_NAME(lookup_pointer_type(builtin_type_char
)) = 0;
847 /* Local utilities */
850 /* Map of FDR indexes to partial symtabs */
852 static struct pst_map
{
853 struct partial_symtab
*pst
; /* the psymtab proper */
854 int n_globals
; /* globals it exports */
858 /* Utility stack, used to nest procedures and blocks properly.
859 It is a doubly linked list, to avoid too many alloc/free.
860 Since we might need it quite a few times it is NOT deallocated
863 static struct parse_stack
{
864 struct parse_stack
*next
, *prev
;
865 struct symtab
*cur_st
; /* Current symtab */
866 struct block
*cur_block
; /* Block in it */
867 int blocktype
; /* What are we parsing */
868 int maxsyms
; /* Max symbols in this block */
869 struct type
*cur_type
; /* Type we parse fields for */
870 int procadr
; /* Start addres of this procedure */
871 int numargs
; /* Its argument count */
872 } *top_stack
; /* Top stack ptr */
875 /* Enter a new lexical context */
877 static push_parse_stack()
879 struct parse_stack
*new;
881 /* Reuse frames if possible */
882 if (top_stack
&& top_stack
->prev
)
883 new = top_stack
->prev
;
885 new = (struct parse_stack
*) xzalloc(sizeof(struct parse_stack
));
886 /* Initialize new frame with previous content */
888 register struct parse_stack
*prev
= new->prev
;
891 top_stack
->prev
= new;
893 new->next
= top_stack
;
898 /* Exit a lexical context */
900 static pop_parse_stack()
905 top_stack
= top_stack
->next
;
909 /* Cross-references might be to things we haven't looked at
910 yet, e.g. type references. To avoid too many type
911 duplications we keep a quick fixup table, an array
912 of lists of references indexed by file descriptor */
914 static struct pending
{
915 struct pending
*next
; /* link */
916 SYMR
*s
; /* the symbol */
917 struct type
*t
; /* its partial type descriptor */
921 /* Check whether we already saw symbol SH in file FH as undefined */
924 struct pending
*is_pending_symbol(fh
, sh
)
928 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
929 register struct pending
*p
;
931 /* Linear search is ok, list is typically no more than 10 deep */
932 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
938 /* Check whether we already saw type T in file FH as undefined */
941 struct pending
*is_pending_type(fh
, t
)
945 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
946 register struct pending
*p
;
948 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
954 /* Add a new undef symbol SH of type T */
957 add_pending(fh
, sh
, t
)
962 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
963 struct pending
*p
= is_pending_symbol(fh
, sh
);
965 /* Make sure we do not make duplicates */
967 p
= (struct pending
*) xmalloc(sizeof(*p
));
970 p
->next
= pending_list
[f_idx
];
971 pending_list
[f_idx
] = p
;
973 sh
->reserved
= 1; /* for quick check */
976 /* Throw away undef entries when done with file index F_IDX */
981 register struct pending
*p
, *q
;
983 for (p
= pending_list
[f_idx
]; p
; p
= q
) {
987 pending_list
[f_idx
] = 0;
990 /* The number of args to a procedure is not explicit in the symtab,
991 this is the list of all those we know of.
992 This makes parsing more reasonable and avoids extra passes */
994 static struct numarg
{
995 struct numarg
*next
; /* link */
996 unsigned adr
; /* procedure's start address */
997 unsigned num
; /* arg count */
1000 /* Record that the procedure at ADR takes NUM arguments. */
1003 got_numargs(adr
,num
)
1005 struct numarg
*n
= (struct numarg
*) xmalloc(sizeof(struct numarg
));
1009 n
->next
= numargs_list
;
1013 /* See if we know how many arguments the procedure at ADR takes */
1018 struct numarg
*n
= numargs_list
;
1020 while (n
&& n
->adr
!= adr
)
1022 return (n
) ? n
->num
: -1;
1025 /* Release storage when done with this file */
1030 struct numarg
*n
= numargs_list
, *m
;
1041 /* Parsing Routines proper. */
1043 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
1044 For blocks, procedures and types we open a new lexical context.
1045 This is basically just a big switch on the symbol's type */
1048 parse_symbol(sh
, ax
)
1056 /* When a symbol is cross-referenced from other files/symbols
1057 we mark it explicitly */
1058 int pend
= (sh
->reserved
== 1);
1059 enum address_class
class;
1066 case stGlobal
: /* external symbol, goes into the primary block */
1068 b
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
1072 case stStatic
: /* static data, goes into the current block. */
1074 b
= top_stack
->cur_block
;
1077 case stLocal
: /* local variable, goes into the current block */
1078 if (sh
->sc
== scRegister
) {
1079 class = LOC_REGISTER
;
1084 b
= top_stack
->cur_block
;
1086 data
: /* Common code for symbols describing data */
1087 s
= new_symbol(sh
->iss
);
1088 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1089 SYMBOL_CLASS(s
) = class;
1092 /* Type could be missing in a number of cases */
1093 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
1094 sh
->index
== 0xfffff)
1095 SYMBOL_TYPE(s
) = builtin_type_int
; /* undefined? */
1097 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
1098 /* Value of a data symbol is its memory address */
1099 SYMBOL_VALUE(s
) = sh
->value
;
1102 case stParam
: /* argument to procedure, goes into current block */
1104 top_stack
->numargs
++;
1105 s
= new_symbol(sh
->iss
);
1106 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1107 if (sh
->sc
== scRegister
) {
1108 SYMBOL_CLASS(s
) = LOC_REGPARM
;
1112 SYMBOL_CLASS(s
) = LOC_ARG
;
1113 SYMBOL_VALUE(s
) = sh
->value
;
1114 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
1115 add_symbol(s
, top_stack
->cur_block
);
1118 case stLabel
: /* label, we do make a symbol for it */
1119 s
= new_symbol(sh
->iss
);
1120 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
; /* so that it can be used */
1121 SYMBOL_CLASS(s
) = LOC_LABEL
; /* but not misused */
1122 SYMBOL_VALUE(s
) = sh
->value
;
1123 SYMBOL_TYPE(s
) = builtin_type_int
;
1124 add_symbol(s
, top_stack
->cur_block
);
1127 case stProc
: /* Procedure */
1128 case stStaticProc
: /* Static procedure */
1129 s
= new_symbol(sh
->iss
);
1130 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1131 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1132 /* Type of the return value */
1133 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
1134 t
= builtin_type_int
;
1136 t
= parse_type(ax
+ sh
->index
, sh
, 0);
1137 add_symbol(s
, top_stack
->cur_block
);
1139 /* Make a type for the procedure itself */
1140 SYMBOL_TYPE(s
) = lookup_function_type (t
);
1142 /* Create and enter a new lexical context */
1143 b
= new_block(top_stack
->maxsyms
);
1144 SYMBOL_BLOCK_VALUE(s
) = b
;
1145 BLOCK_FUNCTION(b
) = s
;
1146 BLOCK_START(b
) = BLOCK_END(b
) = sh
->value
;
1147 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1148 add_block(b
, top_stack
->cur_st
);
1150 /* Not if we only have partial info */
1151 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
1155 top_stack
->cur_block
= b
;
1156 top_stack
->blocktype
= sh
->st
;
1157 top_stack
->cur_type
= SYMBOL_TYPE(s
);
1158 top_stack
->procadr
= sh
->value
;
1159 top_stack
->numargs
= 0;
1161 sh
->value
= (long) SYMBOL_TYPE(s
);
1164 case stBlock
: /* Either a lexical block, or some type */
1166 top_stack
->blocktype
= stBlock
;
1167 if (sh
->sc
== scInfo
) { /* structure/union/enum def */
1168 s
= new_symbol(sh
->iss
);
1169 SYMBOL_NAMESPACE(s
) = STRUCT_NAMESPACE
;
1170 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1171 SYMBOL_VALUE(s
) = 0;
1172 add_symbol(s
, top_stack
->cur_block
);
1173 /* If this type was expected, use its partial definition */
1175 t
= is_pending_symbol(cur_fdr
, sh
)->t
;
1177 /* Uhmm, can`t decide yet. Smash later */
1178 t
= new_type(sh
->iss
);
1179 TYPE_CODE(t
) = TYPE_CODE_UNDEF
;
1180 add_pending(cur_fdr
, sh
, t
);
1183 /* make this the current type */
1184 top_stack
->cur_type
= t
;
1185 TYPE_LENGTH(t
) = sh
->value
;
1186 /* Mark that symbol has a type, and say which one */
1187 sh
->value
= (long) t
;
1189 /* beginnning of (code) block. Value of symbol
1190 is the displacement from procedure start */
1191 b
= new_block(top_stack
->maxsyms
);
1192 BLOCK_START(b
) = sh
->value
+ top_stack
->procadr
;
1193 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1194 top_stack
->cur_block
= b
;
1195 add_block(b
, top_stack
->cur_st
);
1199 case stEnd
: /* end (of anything) */
1200 if (sh
->sc
== scInfo
) {
1201 /* Finished with type */
1202 top_stack
->cur_type
= 0;
1203 } else if (sh
->sc
== scText
&&
1204 (top_stack
->blocktype
== stProc
||
1205 top_stack
->blocktype
== stStaticProc
)) {
1206 /* Finished with procedure */
1207 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
1211 BLOCK_END(top_stack
->cur_block
) += sh
->value
; /* size */
1212 got_numargs(top_stack
->procadr
, top_stack
->numargs
);
1213 /* Reallocate symbols, saving memory */
1214 b
= shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1216 /* f77 emits proc-level with address bounds==[0,0],
1217 So look for such child blocks, and patch them. */
1218 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++) {
1219 struct block
*b_bad
= BLOCKVECTOR_BLOCK(bv
,i
);
1220 if (BLOCK_SUPERBLOCK(b_bad
) == b
1221 && BLOCK_START(b_bad
) == top_stack
->procadr
1222 && BLOCK_END(b_bad
) == top_stack
->procadr
) {
1223 BLOCK_START(b_bad
) = BLOCK_START(b
);
1224 BLOCK_END(b_bad
) = BLOCK_END(b
);
1227 } else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
) {
1228 /* End of (code) block. The value of the symbol
1229 is the displacement from the procedure`s start
1230 address of the end of this block. */
1231 BLOCK_END(top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1232 (void) shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1234 pop_parse_stack(); /* restore previous lexical context */
1237 case stMember
: /* member of struct/union/enum.. */
1238 f
= new_field(top_stack
->cur_type
, sh
->iss
);
1239 f
->bitpos
= sh
->value
;
1240 f
->type
= parse_type(ax
+ sh
->index
, sh
, &f
->bitsize
);
1243 case stTypedef
: /* type definition */
1244 s
= new_symbol(sh
->iss
);
1245 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1246 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1247 SYMBOL_BLOCK_VALUE(s
) = top_stack
->cur_block
;
1248 add_symbol(s
, top_stack
->cur_block
);
1249 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
1250 sh
->value
= (long) SYMBOL_TYPE(s
);
1253 case stFile
: /* file name */
1255 top_stack
->blocktype
= sh
->st
;
1258 /* I`ve never seen these for C */
1260 break; /* register relocation */
1262 break; /* forwarding address */
1264 break; /* constant */
1266 error("Unknown symbol type %x.", sh
->st
);
1271 /* Parse the type information provided in the AX entries for
1272 the symbol SH. Return the bitfield size in BS, in case. */
1274 static struct type
*parse_type(ax
, sh
, bs
)
1279 /* Null entries in this map are treated specially */
1280 static struct type
**map_bt
[] =
1282 &builtin_type_void
, /* btNil */
1284 &builtin_type_char
, /* btChar */
1285 &builtin_type_unsigned_char
, /* btUChar */
1286 &builtin_type_short
, /* btShort */
1287 &builtin_type_unsigned_short
, /* btUShort */
1288 &builtin_type_int
, /* btInt */
1289 &builtin_type_unsigned_int
, /* btUInt */
1290 &builtin_type_long
, /* btLong */
1291 &builtin_type_unsigned_long
, /* btULong */
1292 &builtin_type_float
, /* btFloat */
1293 &builtin_type_double
, /* btDouble */
1300 &builtin_type_complex
, /* btComplex */
1301 &builtin_type_double_complex
, /* btDComplex */
1303 &builtin_type_fixed_dec
, /* btFixedDec */
1304 &builtin_type_float_dec
, /* btFloatDec */
1305 &builtin_type_string
, /* btString */
1308 &builtin_type_void
, /* btVoid */
1312 struct type
*tp
= 0, *tp1
;
1315 /* Procedures start off by one */
1316 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
)
1319 /* Undefined ? Should not happen */
1320 if (ax
->rndx
.rfd
== 0xfff) {
1321 return builtin_type_void
;
1324 /* Use aux as a type information record, map its basic type */
1326 if (t
->bt
> 26 || t
->bt
== btPicture
) {
1327 printf_filtered("Internal: cannot map MIPS basic type x%x\n", t
->bt
);
1328 return builtin_type_int
;
1331 tp
= *map_bt
[t
->bt
];
1333 /* Cannot use builtin types, use templates */
1334 tp
= make_type(TYPE_CODE_VOID
, 0, 0, 0);
1337 *tp
= *builtin_type_ptr
;
1340 *tp
= *builtin_type_struct
;
1344 *tp
= *builtin_type_union
;
1348 *tp
= *builtin_type_enum
;
1352 *tp
= *builtin_type_range
;
1355 *tp
= *builtin_type_set
;
1361 /* Move on to next aux */
1364 /* This is the way it would work if the compiler worked */
1365 register TIR
*t1
= t
;
1366 while (t1
->continued
)
1370 /* For bitfields all we need is the width */
1376 /* All these types really point to some (common) MIPS type
1377 definition, and only the type-qualifiers fully identify
1378 them. We`ll make the same effort at sharing */
1379 if (t
->bt
== btIndirect
||
1380 t
->bt
== btStruct
||
1383 t
->bt
== btTypedef
||
1386 char name
[256], *pn
;
1388 /* Try to cross reference this type */
1390 ax
+= cross_ref(ax
, &tp1
, &pn
);
1391 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1392 sprintf(name
, fmt
, pn
);
1394 /* reading .o file ? */
1395 if (UNSAFE_DATA_ADDR(tp1
))
1397 if (TYPE_CODE(tp1
) == TYPE_CODE_UNDEF
) {
1399 * Type was incompletely defined, now we know.
1401 TYPE_CODE(tp1
) = TYPE_CODE(tp
);
1402 TYPE_NAME(tp1
) = obsavestring(name
, strlen(name
));
1403 if (TYPE_CODE(tp1
) == TYPE_CODE_ENUM
) {
1406 for (i
= 0; i
< TYPE_NFIELDS(tp1
); i
++)
1407 make_enum_constant(&TYPE_FIELD(tp1
,i
), tp1
);
1411 /* found as cross ref, rid of our template */
1412 if ((TYPE_FLAGS(tp
) & TYPE_FLAG_PERM
) == 0)
1415 /* stupid idea of prepending "struct" to type names */
1416 if (t
->bt
== btStruct
&& !index(TYPE_NAME(tp
), ' ')) {
1417 sprintf(name
, fmt
, TYPE_NAME(tp
));
1418 TYPE_NAME(tp
) = obsavestring(name
, strlen(name
));
1421 TYPE_NAME(tp
) = savestring(name
, strlen(name
));
1424 /* Deal with range types */
1425 if (t
->bt
== btRange
) {
1428 f
= new_field(tp
, "Low");
1429 f
->bitpos
= ax
->dnLow
;
1431 f
= new_field(tp
, "High");
1432 f
->bitpos
= ax
->dnHigh
;
1436 /* Parse all the type qualifiers now. If there are more
1437 than 6 the game will continue in the next aux */
1439 #define PARSE_TQ(tq) \
1440 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, sh);
1442 again
: PARSE_TQ(tq0
);
1457 /* Make up a complex type from a basic one. Type is passed by
1458 reference in TPP and side-effected as necessary. The type
1459 qualifier TQ says how to handle the aux symbols at AX for
1460 the symbol SX we are currently analyzing.
1461 Returns the number of aux symbols we parsed. */
1464 upgrade_type(tpp
, tq
, ax
, sh
)
1474 t
= lookup_pointer_type (*tpp
);
1475 } else if (tq
== tqProc
) {
1476 t
= lookup_function_type (*tpp
);
1477 } else if (tq
== tqArray
) {
1483 t
= make_type(TYPE_CODE_ARRAY
, 0, 0, 0);
1484 TYPE_TARGET_TYPE(t
) = *tpp
;
1486 /* Pointer to domain type (type of index) */
1487 id
= ax
->rndx
.index
;
1488 if ((rf
= ax
->rndx
.rfd
) == 0xfff)
1489 rf
= (++ax
)->isym
, off
++;
1491 fh
= get_rfd(cur_fd
, rf
);
1492 f
= new_field(t
, 0);
1493 bzero(&ss
, sizeof ss
);
1494 /* XXX */ f
->type
= parse_type(fh
->iauxBase
+ id
* sizeof(AUXU
),
1498 * This seems to be a pointer to the end of the Block defining
1499 * the type. Why it is here is magic for me, and I have no
1500 * good use for it anyways.
1504 id
= (++ax
)->rndx
.index
;
1505 if ((rf
= ax
->rndx
.rfd
) == 0xfff)
1506 rf
= (++ax
)->isym
, off
++;
1508 f
->bitpos
= (++ax
)->dnLow
; /* ?? */
1509 f
->bitsize
= (++ax
)->dnHigh
; /* ?? */
1510 rf
= (++ax
)->width
- 1; /* bit alignment */
1511 id
= TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) << 3; /* bitsize */
1514 /* Most likely an undefined type */
1516 TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) = id
>> 3;
1518 TYPE_LENGTH(t
) = (f
->bitsize
< 0) ? 0 :
1519 (f
->bitsize
- f
->bitpos
+ 1) * (id
>> 3);
1523 printf_filtered("Internal: unknown type qualifier %x\n", tq
);
1532 /* Parse a procedure descriptor record PR. Note that the procedure
1533 is parsed _after_ the local symbols, now we just make up the
1534 extra information we need into a special symbol that we insert
1535 in the procedure's main block. Note also that images that
1536 have been partially stripped (ld -x) have been deprived
1537 of local symbols, and we have to cope with them here.
1538 The procedure's code ends at BOUND */
1541 parse_procedure(pr
, bound
)
1544 struct symbol
*s
, *i
;
1545 SYMR
*sh
= (SYMR
*)pr
->isym
;
1547 struct mips_extra_func_info
*e
;
1551 /* Reuse the MIPS record */
1552 e
= (struct mips_extra_func_info
*) pr
;
1553 e
->numargs
= lookup_numargs(pr
->adr
);
1555 /* Make up our special symbol */
1556 i
= new_symbol(".gdbinfo.");
1557 SYMBOL_VALUE(i
) = (int)e
;
1558 SYMBOL_NAMESPACE(i
) = LABEL_NAMESPACE
;
1559 SYMBOL_CLASS(i
) = LOC_CONST
;
1560 SYMBOL_TYPE(i
) = builtin_type_void
;
1562 /* Make up a name for static procedures. Sigh. */
1563 if (sh
== (SYMR
*)-1) {
1564 sprintf(name
,".static_procedure@%x",pr
->adr
);
1565 sh_name
= savestring(name
, strlen(name
));
1569 sh_name
= (char*)sh
->iss
;
1570 s
= mylookup_symbol(sh_name
, top_stack
->cur_block
,
1571 VAR_NAMESPACE
, LOC_BLOCK
);
1574 b
= SYMBOL_BLOCK_VALUE(s
);
1576 s
= new_symbol(sh_name
);
1577 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1578 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1579 /* Donno its type, hope int is ok */
1580 SYMBOL_TYPE(s
) = lookup_function_type (builtin_type_int
);
1581 add_symbol(s
, top_stack
->cur_block
);
1582 /* Wont have symbols for this one */
1584 SYMBOL_BLOCK_VALUE(s
) = b
;
1585 BLOCK_FUNCTION(b
) = s
;
1586 BLOCK_START(b
) = pr
->adr
;
1587 BLOCK_END(b
) = bound
;
1588 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1589 add_block(b
, top_stack
->cur_st
);
1595 /* Parse the external symbol ES. Just call parse_symbol() after
1596 making sure we know where the aux are for it. For procedures,
1597 parsing of the PDRs has already provided all the needed
1598 information, we only parse them if SKIP_PROCEDURES is false,
1599 and only if this causes no symbol duplication */
1602 parse_external(es
, skip_procedures
)
1607 if (es
->ifd
!= ifdNil
) {
1609 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
) + cur_fd
;
1610 ax
= (AUXU
*)cur_fdr
->iauxBase
;
1612 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
);
1615 top_stack
->cur_st
= cur_stab
;
1616 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
1619 /* Reading .o files */
1620 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
) {
1622 switch (es
->asym
.st
) {
1624 case stProc
: what
= "Procedure"; n_undef_procs
++; break;
1625 case stGlobal
: what
= "Variable"; n_undef_vars
++; break;
1626 case stLabel
: what
= "Label"; n_undef_labels
++; break;
1627 default : what
= "Symbol"; break;
1631 printf_filtered("Warning: %s %s is undefined (in %s)\n", what
,
1632 es
->asym
.iss
, fdr_name(cur_fdr
->rss
));
1636 switch (es
->asym
.st
) {
1638 /* If we have full symbols we do not need more */
1639 if (skip_procedures
)
1641 if (mylookup_symbol (es
->asym
.iss
, top_stack
->cur_block
,
1642 VAR_NAMESPACE
, LOC_BLOCK
))
1648 * Note that the case of a symbol with indexNil
1649 * must be handled anyways by parse_symbol().
1651 parse_symbol(&es
->asym
, ax
);
1658 /* Parse the line number info for file descriptor FH into
1659 GDB's linetable LT. MIPS' encoding requires a little bit
1660 of magic to get things out. Note also that MIPS' line
1661 numbers can go back and forth, apparently we can live
1662 with that and do not need to reorder our linetables */
1667 struct linetable
*lt
;
1669 char *base
= (char*)fh
->cbLineOffset
;
1671 int delta
, count
, lineno
= 0;
1677 /* Scan by procedure descriptors */
1678 i
= 0; j
= 0, k
= 0;
1679 for (pr
= (PDR
*)IPDFIRST(cur_hdr
,fh
); j
< fh
->cpd
; j
++, pr
++) {
1682 /* No code for this one */
1683 if (pr
->iline
== ilineNil
||
1684 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1687 * Aurgh! To know where to stop expanding we
1690 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1691 if (pr
[l
].iline
!= -1)
1693 if (l
== (fh
->cpd
- j
))
1698 * When procedures are moved around the linenumbers
1699 * are attributed to the next procedure up
1701 if (pr
->iline
>= halt
) continue;
1703 base
= (char*)pr
->cbLineOffset
;
1704 l
= pr
->adr
>> 2; /* in words */
1705 halt
+= (pr
->adr
>> 2) - pr
->iline
;
1706 for (lineno
= pr
->lnLow
; l
< halt
;) {
1707 count
= *base
& 0x0f;
1708 delta
= *base
++ >> 4;
1710 delta
= (base
[0] << 8) | (base
[1] & 0xff);
1713 lineno
+= delta
;/* first delta is 0 */
1714 k
= add_line(lt
, lineno
, l
, k
);
1721 /* Parse the symbols of the file described by FH, whose index is F_IDX.
1722 BOUND is the highest core address of this file's procedures */
1725 parse_one_file(fh
, f_idx
, bound
)
1732 /* Parse local symbols first */
1734 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
1735 sh
= (SYMR
*) (fh
->isymBase
) + s_idx
;
1737 parse_symbol(sh
, fh
->iauxBase
);
1740 /* Procedures next, note we need to look-ahead to
1741 find out where the procedure's code ends */
1743 for (s_idx
= 0; s_idx
< fh
->cpd
-1; s_idx
++) {
1744 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + s_idx
;
1745 parse_procedure(pr
, pr
[1].adr
); /* next proc up */
1748 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + s_idx
;
1749 parse_procedure(pr
, bound
); /* next file up */
1752 /* Linenumbers. At the end, check if we can save memory */
1753 parse_lines(fh
, LINETABLE(cur_stab
));
1754 if (LINETABLE(cur_stab
)->nitems
< fh
->cline
)
1755 shrink_linetable(cur_stab
);
1759 /* Master parsing procedure. Parses the symtab described by the
1760 symbolic header HDR. If INCREMENTAL is true we are called
1761 by add-file and must preserve the old symtabs */
1763 parse_partial_symbols(hdr
, incremental
)
1766 int f_idx
, s_idx
, h_max
;
1767 CORE_ADDR dummy
, *prevhigh
;
1768 /* Running pointers */
1776 * Only parse the External symbols, and the Relative FDR.
1777 * Fixup enough of the loader symtab to be able to use it.
1778 * Allocate space only for the file`s portions we need to
1784 max_glevel
= MIN_GLEVEL
;
1786 /* Allocate the map FDR -> PST.
1787 Minor hack: -O3 images might claim some global data belongs
1788 to FDR -1. We`ll go along with that */
1789 fdr_to_pst
= (struct pst_map
*)xzalloc((hdr
->ifdMax
+1) * sizeof *fdr_to_pst
);
1792 struct partial_symtab
* pst
= new_psymtab("");
1793 fdr_to_pst
[-1].pst
= pst
;
1797 /* Now scan the FDRs, mostly for dependencies */
1798 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++)
1799 (void) parse_fdr(f_idx
, 1);
1801 /* Take a good guess at how many symbols we might ever need */
1802 h_max
= hdr
->iextMax
;
1804 /* Parse externals: two passes because they can be ordered
1807 /* Pass 1: Presize and partition the list */
1808 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1809 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1810 fdr_to_pst
[esh
->ifd
].n_globals
++;
1813 if (global_psymbols
.list
) {
1814 global_psymbols
.list
= (struct partial_symbol
*)
1815 xrealloc( global_psymbols
.list
, (h_max
+
1816 global_psymbols
.size
) * sizeof(struct partial_symbol
));
1817 global_psymbols
.next
= global_psymbols
.list
+ global_psymbols
.size
;
1818 global_psymbols
.size
+= h_max
;
1820 global_psymbols
.list
= (struct partial_symbol
*)
1821 xmalloc( h_max
* sizeof(struct partial_symbol
));
1822 global_psymbols
.size
= h_max
;
1823 global_psymbols
.next
= global_psymbols
.list
;
1826 s_idx
= global_psymbols
.next
- global_psymbols
.list
;
1827 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++) {
1828 fdr_to_pst
[f_idx
].pst
->globals_offset
= s_idx
;
1829 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
1832 /* Pass 2: fill in symbols */
1833 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1834 register struct partial_symbol
*p
;
1835 enum misc_function_type misc_type
= mf_text
;
1836 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1838 if (esh
->asym
.sc
== scUndefined
|| esh
->asym
.sc
== scNil
)
1840 p
= new_psymbol(&global_psymbols
, esh
->asym
.iss
, esh
->ifd
);
1841 SYMBOL_VALUE(p
) = esh
->asym
.value
;
1842 SYMBOL_NAMESPACE(p
) = VAR_NAMESPACE
;
1844 switch (esh
->asym
.st
) {
1846 SYMBOL_CLASS(p
) = LOC_BLOCK
;
1849 SYMBOL_CLASS(p
) = LOC_STATIC
;
1850 misc_type
= mf_data
;
1853 SYMBOL_CLASS(p
) = LOC_LABEL
;
1856 misc_type
= mf_unknown
;
1857 complain (&unknown_ext_complaint
, SYMBOL_NAME(p
));
1859 prim_record_misc_function (SYMBOL_NAME(p
),
1865 /* The array (of lists) of globals must be sorted.
1866 Take care, since we are at it, of pst->texthigh.
1868 NOTE: The way we handle textlow/high is incorrect, but good
1869 enough for a first approximation. The case we fail is on a
1870 file "foo.c" that looks like
1872 #include "bar.c" -- this contains proc2()
1874 where proc3() is attributed to bar.c. But since this is a
1875 dependent file it will cause loading of foo.c as well, so
1876 everything will be fine at the end. */
1879 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
1880 struct partial_symtab
*pst
= fdr_to_pst
[f_idx
].pst
;
1881 if (pst
->n_global_syms
> 1)
1882 qsort (global_psymbols
.list
+ pst
->globals_offset
,
1883 pst
->n_global_syms
, sizeof (struct partial_symbol
),
1886 *prevhigh
= pst
->textlow
;
1887 prevhigh
= &pst
->texthigh
;
1891 /* Mark the last code address, and remember it for later */
1892 *prevhigh
= END_OF_TEXT_SEGMENT(filhdr
);
1893 hdr
->cbDnOffset
= END_OF_TEXT_SEGMENT(filhdr
);
1896 free(&fdr_to_pst
[-1]);
1901 /* Do the initial analisys of the F_IDX-th file descriptor.
1902 Allocates a partial symtab for it, and builds the list
1903 of dependent files by recursion. LEV says at which level
1904 of recursion we are called (to pretty up debug traces) */
1906 static struct partial_symtab
*
1907 parse_fdr(f_idx
, lev
)
1911 register struct partial_symtab
*pst
;
1914 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + f_idx
;
1916 /* Use this to indicate into which symtab this file was parsed */
1918 return (struct partial_symtab
*) fh
->ioptBase
;
1920 /* Debuggability level */
1921 if (compare_glevel(max_glevel
, fh
->glevel
) < 0)
1922 max_glevel
= fh
->glevel
;
1924 /* Make a new partial_symtab */
1925 pst
= new_psymtab(fh
->rss
);
1930 pst
->textlow
= fh
->adr
;
1931 pst
->texthigh
= fh
->cpd
; /* To be fixed later */
1933 /* Reverse mapping PST -> FDR */
1934 pst
->ldsymoff
= f_idx
;
1936 fdr_to_pst
[f_idx
].pst
= pst
;
1937 fh
->ioptBase
= (int)pst
;
1939 /* Analyze its dependencies */
1944 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
1945 /* ...then presumably a .h file: drop reverse depends .h->.c */
1946 for (; s_id0
< fh
->crfd
; s_id0
++) {
1947 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
1949 s_id0
++; /* Skip self-dependency */
1954 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
1955 pst
->dependencies
= (struct partial_symtab
**)
1956 obstack_alloc (psymbol_obstack
,
1957 pst
->number_of_dependencies
* sizeof(char*));
1958 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
1959 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
1961 pst
->dependencies
[s_idx
-s_id0
] = parse_fdr(*rh
, lev
+1);
1969 /* Ancillary function to psymtab_to_symtab(). Does all the work
1970 for turning the partial symtab PST into a symtab, recurring
1971 first on all dependent psymtabs */
1973 static void psymtab_to_symtab_1(pst
)
1974 struct partial_symtab
*pst
;
1984 pending_list
= (struct pending
**) cur_hdr
->cbOptOffset
;
1985 if (pending_list
== 0) {
1986 pending_list
= (struct pending
**)
1987 xzalloc(cur_hdr
->ifdMax
* sizeof(struct pending
*));
1988 cur_hdr
->cbOptOffset
= (int)pending_list
;
1991 /* How many symbols will we need */
1992 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
1993 if (pst
->ldsymoff
== -1) {
1995 st
= new_symtab( "unknown", f_max
, 0);
1997 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + pst
->ldsymoff
;
1998 f_max
+= fh
->csym
+ fh
->cpd
;
1999 st
= new_symtab(pst
->filename
, 2 * f_max
, 2 * fh
->cline
);
2003 * Read in all partial symbtabs on which this one is dependent.
2004 * NOTE that we do have circular dependencies, sigh.
2006 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2007 if (!pst
->dependencies
[i
]->readin
) {
2009 * DO NOT inform about additional files that need to
2010 * be read in, it would only annoy the user.
2012 psymtab_to_symtab_1(pst
->dependencies
[i
]);
2015 /* Now read the symbols for this symtab */
2017 cur_fd
= pst
->ldsymoff
;
2021 /* Get a new lexical context */
2024 top_stack
->cur_st
= cur_stab
;
2025 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab
),
2027 BLOCK_START(top_stack
->cur_block
) = fh
? fh
->adr
: 0;
2028 BLOCK_END(top_stack
->cur_block
) = 0;
2029 top_stack
->blocktype
= stFile
;
2030 top_stack
->maxsyms
= f_max
;
2031 top_stack
->cur_type
= 0;
2032 top_stack
->procadr
= 0;
2033 top_stack
->numargs
= 0;
2035 /* Parse locals and procedures */
2037 parse_one_file(fh
, cur_fd
, (cur_fd
== (cur_hdr
->ifdMax
- 1)) ?
2038 cur_hdr
->cbDnOffset
: fh
[1].adr
);
2040 /* .. and our share of externals.
2041 XXX use the global list to speed up things here. how ? */
2042 top_stack
->blocktype
= stFile
;
2043 top_stack
->maxsyms
= cur_hdr
->isymMax
+ cur_hdr
->ipdMax
+ cur_hdr
->iextMax
;
2044 for (i
= 0; i
< cur_hdr
->iextMax
; i
++) {
2045 register EXTR
*esh
= (EXTR
*) (cur_hdr
->cbExtOffset
) + i
;
2046 if (esh
->ifd
== cur_fd
)
2047 parse_external(esh
, 1);
2050 /* If there are undefined, tell the user */
2051 if (n_undef_symbols
) {
2052 printf_filtered("File %s contains %d unresolved references:",
2053 st
->filename
, n_undef_symbols
);
2054 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2055 n_undef_vars
, n_undef_procs
, n_undef_labels
);
2056 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
2062 * Sort the symbol table now, we are done adding symbols to it.
2064 sort_symtab_syms(st
);
2070 /* Ancillary parsing procedures. */
2072 /* Lookup the type at relative index RN. Return it in TPP
2073 if found and in any event come up with its name PNAME.
2074 Return value says how many aux symbols we ate */
2077 cross_ref(rn
, tpp
, pname
)
2084 /* Escape index means 'the next one' */
2085 if (rn
->rfd
== 0xfff)
2086 rf
= *(unsigned *) (rn
+ 1);
2092 *pname
= "<undefined>";
2095 * Find the relative file descriptor and the symbol in it
2097 FDR
*fh
= get_rfd(cur_fd
, rf
);
2102 * If we have processed this symbol then we left a forwarding
2103 * pointer to the corresponding GDB symbol. If not, we`ll put
2104 * it in a list of pending symbols, to be processed later when
2105 * the file f will be. In any event, we collect the name for
2106 * the type here. Which is why we made a first pass at
2109 sh
= (SYMR
*) (fh
->isymBase
) + rn
->index
;
2111 /* Careful, we might be looking at .o files */
2112 *pname
= (UNSAFE_DATA_ADDR(sh
->iss
)) ? "<undefined>" :
2115 /* Have we parsed it ? */
2116 if ((!UNSAFE_DATA_ADDR(sh
->value
)) && (sh
->st
== stParsed
)) {
2117 t
= (struct type
*) sh
->value
;
2122 /* Avoid duplicates */
2123 p
= is_pending_symbol(fh
, sh
);
2128 add_pending(fh
, sh
, *tpp
);
2131 return (rn
->rfd
== 0xfff);
2135 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2136 keeping the symtab sorted */
2138 static struct symbol
*
2139 mylookup_symbol (name
, block
, namespace, class)
2141 register struct block
*block
;
2142 enum namespace namespace;
2143 enum address_class
class;
2145 register int bot
, top
, inc
;
2146 register struct symbol
*sym
;
2149 top
= BLOCK_NSYMS(block
);
2152 sym
= BLOCK_SYM(block
, bot
);
2153 if (SYMBOL_NAME(sym
)[0] == inc
2154 && SYMBOL_NAMESPACE(sym
) == namespace
2155 && SYMBOL_CLASS(sym
) == class
2156 && !strcmp(SYMBOL_NAME(sym
), name
))
2160 if (block
= BLOCK_SUPERBLOCK (block
))
2161 return mylookup_symbol (name
, block
, namespace, class);
2166 /* Add a new symbol S to a block B */
2173 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
2174 if (b
== top_stack
->cur_block
&&
2175 BLOCK_NSYMS(b
) > top_stack
->maxsyms
)
2176 printf_filtered("Internal: block at @%x overfilled (by %d)\n",
2177 b
, BLOCK_NSYMS(b
) - top_stack
->maxsyms
);
2180 /* Add a new block B to a symtab S */
2187 struct blockvector
*bv
= BLOCKVECTOR(s
);
2189 bv
= (struct blockvector
*)xrealloc(bv
, sizeof(struct blockvector
) +
2190 BLOCKVECTOR_NBLOCKS(bv
) * sizeof(bv
->block
));
2191 if (bv
!= BLOCKVECTOR(s
))
2192 BLOCKVECTOR(s
) = bv
;
2194 BLOCKVECTOR_BLOCK(bv
, BLOCKVECTOR_NBLOCKS(bv
)++) = b
;
2197 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2198 MIPS' linenumber encoding might need more than one byte
2199 to describe it, LAST is used to detect these continuation lines */
2202 add_line(lt
, lineno
, adr
, last
)
2203 struct linetable
*lt
;
2207 last
= -2; /* make sure we record first line */
2209 if (last
== lineno
) /* skip continuation lines */
2212 lt
->item
[lt
->nitems
].line
= lineno
;
2213 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
2219 /* Comparison functions, used when sorting things */
2221 /* Symtabs must be ordered viz the code segments they cover */
2224 compare_symtabs( s1
, s2
)
2225 struct symtab
**s1
, **s2
;
2227 /* "most specific" first */
2229 register struct block
*b1
, *b2
;
2230 b1
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1
),GLOBAL_BLOCK
);
2231 b2
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2
),GLOBAL_BLOCK
);
2232 if (BLOCK_END(b1
) == BLOCK_END(b2
))
2233 return BLOCK_START(b1
) - BLOCK_START(b2
);
2234 return BLOCK_END(b1
) - BLOCK_END(b2
);
2238 /* Partial Symtabs, same */
2241 compare_psymtabs( s1
, s2
)
2242 struct partial_symtab
**s1
, **s2
;
2244 /* Perf twist: put the ones with no code at the end */
2246 register int a
= (*s1
)->textlow
;
2247 register int b
= (*s2
)->textlow
;
2256 /* Partial symbols are compared lexicog by their print names */
2259 compare_psymbols (s1
, s2
)
2260 register struct partial_symbol
*s1
, *s2
;
2263 *st1
= SYMBOL_NAME(s1
),
2264 *st2
= SYMBOL_NAME(s2
);
2266 return (st1
[0] - st2
[0] ? st1
[0] - st2
[0] :
2267 strcmp(st1
+ 1, st2
+ 1));
2270 /* Blocks with a smaller low bound should come first */
2272 static int compare_blocks(b1
,b2
)
2273 struct block
**b1
, **b2
;
2275 register int addr_diff
;
2277 addr_diff
= (BLOCK_START((*b1
))) - (BLOCK_START((*b2
)));
2279 return (BLOCK_END((*b1
))) - (BLOCK_END((*b2
)));
2284 /* Sorting and reordering procedures */
2286 /* Sort the blocks of a symtab S.
2287 Reorder the blocks in the blockvector by code-address,
2288 as required by some MI search routines */
2294 struct blockvector
*bv
= BLOCKVECTOR(s
);
2296 if (BLOCKVECTOR_NBLOCKS(bv
) <= 2) {
2298 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) == 0)
2299 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = 0;
2303 * This is very unfortunate: normally all functions are compiled in
2304 * the order they are found, but if the file is compiled -O3 things
2305 * are very different. It would be nice to find a reliable test
2306 * to detect -O3 images in advance.
2308 if (BLOCKVECTOR_NBLOCKS(bv
) > 3)
2309 qsort(&BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
),
2310 BLOCKVECTOR_NBLOCKS(bv
) - FIRST_LOCAL_BLOCK
,
2311 sizeof(struct block
*),
2315 register CORE_ADDR high
= 0;
2316 register int i
, j
= BLOCKVECTOR_NBLOCKS(bv
);
2318 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
2319 if (high
< BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
)))
2320 high
= BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
));
2321 BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = high
;
2324 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) =
2325 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
));
2327 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2328 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2329 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2330 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2333 /* Sort the symtab list, as required by some search procedures.
2334 We want files ordered to make them look right to users, and for
2335 searching (see block_for_pc). */
2341 struct symtab
*stab
;
2342 struct symtab
**all_symtabs
= (struct symtab
**)
2343 obstack_alloc (psymbol_obstack
,
2344 all_symtabs_count
* sizeof (struct symtab
*));
2346 /* Create an array of pointers to all the symtabs. */
2347 for (i
= 0, stab
= symtab_list
;
2348 i
< all_symtabs_count
;
2349 i
++, stab
= stab
->next
) {
2350 all_symtabs
[i
] = stab
;
2351 /* FIXME: Only do this for new symtabs ??? */
2352 sort_blocks(all_symtabs
[i
]);
2355 qsort(all_symtabs
, all_symtabs_count
,
2356 sizeof(struct symtab
*), compare_symtabs
);
2358 /* Re-construct the symtab list, but now it is sorted. */
2359 for (i
= 0; i
< all_symtabs_count
-1; i
++)
2360 all_symtabs
[i
]->next
= all_symtabs
[i
+1];
2361 all_symtabs
[i
]->next
= 0;
2362 symtab_list
= all_symtabs
[0];
2363 obstack_free (psymbol_obstack
, all_symtabs
);
2366 /* Sort the partial symtab list, as required by some search procedures */
2368 static reorder_psymtabs()
2371 struct partial_symtab
*pstab
;
2374 * PC lookups stop at the first psymtab such that
2375 * textlow <= PC < texthigh
2377 /* Create an array of pointers to all the partial_symtabs. */
2378 struct partial_symtab
**all_psymtabs
= (struct partial_symtab
**)
2379 obstack_alloc (psymbol_obstack
,
2380 all_psymtabs_count
*sizeof(struct partial_symtab
*));
2381 for (i
= 0, pstab
= partial_symtab_list
;
2382 i
< all_psymtabs_count
;
2383 i
++, pstab
= pstab
->next
)
2384 all_psymtabs
[i
] = pstab
;
2386 qsort(all_psymtabs
, all_psymtabs_count
,
2387 sizeof(struct partial_symtab
*), compare_psymtabs
);
2389 /* Re-construct the partial_symtab_list, but now it is sorted. */
2391 for (i
= 0; i
< all_psymtabs_count
-1; i
++)
2392 all_psymtabs
[i
]->next
= all_psymtabs
[i
+1];
2393 all_psymtabs
[i
]->next
= 0;
2394 partial_symtab_list
= all_psymtabs
[0];
2396 obstack_free (psymbol_obstack
, all_psymtabs
);
2401 /* Constructor/restructor/destructor procedures */
2403 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2404 MAXSYMS and linenumbers MAXLINES we'll put in it */
2408 new_symtab(name
, maxsyms
, maxlines
)
2411 struct symtab
*s
= (struct symtab
*) xzalloc(sizeof(struct symtab
));
2414 LINETABLE(s
) = new_linetable(maxlines
);
2418 /* All symtabs must have at least two blocks */
2419 BLOCKVECTOR(s
) = new_bvect(2);
2420 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
) = new_block(maxsyms
);
2421 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), STATIC_BLOCK
) = new_block(maxsyms
);
2422 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
),STATIC_BLOCK
)) =
2423 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
);
2425 s
->free_code
= free_linetable
;
2427 /* Link the new symtab into the list of such. */
2428 s
->next
= symtab_list
;
2431 all_symtabs_count
++;
2436 /* Cleanup before loading a fresh image */
2438 static destroy_all_symtabs()
2445 all_symtabs_count
= 0;
2446 current_source_symtab
= 0;
2450 /* Allocate a new partial_symtab NAME */
2452 static struct partial_symtab
*
2456 struct partial_symtab
*pst
;
2458 pst
= (struct partial_symtab
*)
2459 obstack_alloc (psymbol_obstack
, sizeof (*pst
));
2460 bzero (pst
, sizeof (*pst
));
2462 if (name
== (char*)-1) /* FIXME -- why not null here? */
2463 pst
->filename
= "<no name>";
2465 pst
->filename
= name
;
2467 pst
->next
= partial_symtab_list
;
2468 partial_symtab_list
= pst
;
2469 all_psymtabs_count
++;
2471 /* Keep a backpointer to the file`s symbols */
2472 pst
->ldsymlen
= (int)cur_hdr
;
2474 /* The way to turn this into a symtab is to call... */
2475 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
2481 /* Allocate a new NAME psymbol from LIST, extending it if necessary.
2482 The psymbol belongs to the psymtab at index PST_IDX */
2484 static struct partial_symbol
*
2485 new_psymbol(list
, name
, pst_idx
)
2486 struct psymbol_allocation_list
*list
;
2489 struct partial_symbol
*p
;
2490 struct partial_symtab
*pst
= fdr_to_pst
[pst_idx
].pst
;
2492 /* Lists are pre-sized, we won`t overflow */
2494 p
= list
->list
+ pst
->globals_offset
+ pst
->n_global_syms
++;
2495 SYMBOL_NAME(p
) = name
;
2500 /* Allocate a linetable array of the given SIZE */
2503 struct linetable
*new_linetable(size
)
2505 struct linetable
*l
;
2507 size
= size
* sizeof(l
->item
) + sizeof(struct linetable
);
2508 l
= (struct linetable
*)xmalloc(size
);
2513 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2514 I am not so sure about the 3.4 ones */
2516 static shrink_linetable(s
)
2519 struct linetable
*l
= new_linetable(LINETABLE(s
)->nitems
);
2521 bcopy(LINETABLE(s
), l
,
2522 LINETABLE(s
)->nitems
* sizeof(l
->item
) + sizeof(struct linetable
));
2523 free (LINETABLE(s
));
2527 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2530 struct blockvector
*new_bvect(nblocks
)
2532 struct blockvector
*bv
;
2535 size
= sizeof(struct blockvector
) + nblocks
* sizeof(struct block
*);
2536 bv
= (struct blockvector
*) xzalloc(size
);
2538 BLOCKVECTOR_NBLOCKS(bv
) = nblocks
;
2543 /* Allocate and zero a new block of MAXSYMS symbols */
2546 struct block
*new_block(maxsyms
)
2548 int size
= sizeof(struct block
) + (maxsyms
-1) * sizeof(struct symbol
*);
2549 struct block
*b
= (struct block
*)xzalloc(size
);
2554 /* Ooops, too big. Shrink block B in symtab S to its minimal size */
2556 static struct block
*
2562 struct blockvector
*bv
= BLOCKVECTOR(s
);
2565 /* Just get a new one, copy, and fix references to the old one */
2567 new = (struct block
*)xmalloc(sizeof(struct block
) +
2568 (BLOCK_NSYMS(b
)-1) * sizeof(struct symbol
*));
2570 bcopy(b
, new, sizeof(*new) + (BLOCK_NSYMS(b
) - 1) * sizeof(struct symbol
*));
2572 /* Should chase pointers to old one. Fortunately, that`s just
2573 the block`s function and inferior blocks */
2574 if (BLOCK_FUNCTION(b
) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(b
)) == b
)
2575 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(b
)) = new;
2576 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2577 if (BLOCKVECTOR_BLOCK(bv
,i
) == b
)
2578 BLOCKVECTOR_BLOCK(bv
,i
) = new;
2579 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) == b
)
2580 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) = new;
2585 /* Create a new symbol with printname NAME */
2592 struct symbol
*s
= (struct symbol
*)
2593 obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
2595 bzero (s
, sizeof (*s
));
2596 SYMBOL_NAME(s
) = name
;
2600 /* Create a new type with printname NAME */
2607 struct type
*t
= (struct type
*)
2608 obstack_alloc (symbol_obstack
, sizeof (struct type
));
2610 bzero (t
, sizeof (*t
));
2611 TYPE_NAME(t
) = name
;
2615 /* Create and initialize a new type with printname NAME.
2616 CODE and LENGTH are the initial info we put in,
2617 UNS says whether the type is unsigned or not. */
2621 make_type(code
, length
, uns
, name
)
2622 enum type_code code
;
2626 register struct type
*type
;
2628 type
= (struct type
*) xzalloc(sizeof(struct type
));
2629 TYPE_CODE(type
) = code
;
2630 TYPE_LENGTH(type
) = length
;
2631 TYPE_FLAGS(type
) = uns
? TYPE_FLAG_UNSIGNED
: 0;
2632 TYPE_NAME(type
) = name
;
2637 /* Allocate a new field named NAME to the type TYPE */
2640 struct field
*new_field(type
,name
)
2646 /* Fields are kept in an array */
2647 if (TYPE_NFIELDS(type
))
2648 TYPE_FIELDS(type
) = (struct field
*)xrealloc(TYPE_FIELDS(type
),
2649 (TYPE_NFIELDS(type
)+1) * sizeof(struct field
));
2651 TYPE_FIELDS(type
) = (struct field
*)xzalloc(2*sizeof(struct field
));
2652 f
= &(TYPE_FIELD(type
,TYPE_NFIELDS(type
)++));
2653 bzero(f
, sizeof(struct field
));
2659 /* Make an enum constant for a member F of an enumerated type T */
2662 make_enum_constant(f
,t
)
2668 * This is awful, but that`s the way it is supposed to be
2669 * (BTW, no need to free the real 'type', it's a builtin)
2671 f
->type
= (struct type
*) f
->bitpos
;
2673 s
= new_symbol(f
->name
);
2674 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2675 SYMBOL_CLASS(s
) = LOC_CONST
;
2677 SYMBOL_VALUE(s
) = f
->bitpos
;
2678 add_symbol(s
, top_stack
->cur_block
);
2683 /* Things used for calling functions in the inferior.
2684 These functions are exported to our companion
2685 mips-dep.c file and are here because they play
2686 with the symbol-table explicitly. */
2689 /* Need to make a new symbol on the fly for the dummy
2690 frame we put on the stack. Which goes in the.. */
2692 static struct symtab
*dummy_symtab
;
2694 /* Make up a dummy symbol for the code we put at END_PC,
2695 of size SIZE, invoking a function with NARGS arguments
2696 and using a frame of FRAMESIZE bytes */
2698 mips_create_dummy_symbol(end_pc
, size
, nargs
, framesize
)
2702 struct mips_extra_func_info
*gdbinfo
;
2704 /* Allocate symtab if not done already */
2705 if (dummy_symtab
== 0)
2706 dummy_symtab
= new_symtab(".dummy_symtab.", 100, 0);
2708 /* Make a new block. Only needs one symbol */
2710 BLOCK_START(bl
) = end_pc
- size
;
2711 BLOCK_END(bl
) = end_pc
;
2713 BLOCK_SUPERBLOCK(bl
) =
2714 BLOCKVECTOR_BLOCK(BLOCKVECTOR(dummy_symtab
),GLOBAL_BLOCK
);
2715 add_block(bl
, dummy_symtab
);
2716 sort_blocks(dummy_symtab
);
2718 BLOCK_FUNCTION(bl
) = new_symbol("??");
2719 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(bl
)) = bl
;
2720 g
= new_symbol(".gdbinfo.");
2721 BLOCK_SYM(bl
,BLOCK_NSYMS(bl
)++) = g
;
2723 SYMBOL_NAMESPACE(g
) = LABEL_NAMESPACE
;
2724 SYMBOL_CLASS(g
) = LOC_CONST
;
2725 SYMBOL_TYPE(g
) = builtin_type_void
;
2726 gdbinfo
= (struct mips_extra_func_info
*)
2727 xzalloc(sizeof(struct mips_extra_func_info
));
2729 SYMBOL_VALUE(g
) = (long) gdbinfo
;
2731 gdbinfo
->numargs
= nargs
;
2732 gdbinfo
->framesize
= framesize
;
2733 gdbinfo
->framereg
= 29;
2734 gdbinfo
->pcreg
= 31;
2735 gdbinfo
->regmask
= -2;
2736 gdbinfo
->regoffset
= -4;
2737 gdbinfo
->fregmask
= 0; /* XXX */
2738 gdbinfo
->fregoffset
= 0; /* XXX */
2741 /* We just returned from the dummy code at END_PC, drop its symbol */
2743 mips_destroy_dummy_symbol(end_pc
)
2746 struct blockvector
*bv
= BLOCKVECTOR(dummy_symtab
);
2749 bl
= block_for_pc(end_pc
);
2750 free(BLOCK_FUNCTION(bl
));
2751 free(SYMBOL_VALUE(BLOCK_SYM(bl
,0)));
2752 free(BLOCK_SYM(bl
,0));
2754 for (i
= FIRST_LOCAL_BLOCK
; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2755 if (BLOCKVECTOR_BLOCK(bv
,i
) == bl
)
2757 for (; i
< BLOCKVECTOR_NBLOCKS(bv
) - 1; i
++)
2758 BLOCKVECTOR_BLOCK(bv
,i
) = BLOCKVECTOR_BLOCK(bv
,i
+1);
2759 BLOCKVECTOR_NBLOCKS(bv
)--;
2760 sort_blocks(dummy_symtab
);
2765 /* Sigtramp: make sure we have all the necessary information
2766 about the signal trampoline code. Since the official code
2767 from MIPS does not do so, we make up that information ourselves.
2768 If they fix the library (unlikely) this code will neutralize itself. */
2775 struct block
*b
, *b0
;
2777 sigtramp_address
= -1;
2779 /* We know it is sold as sigvec */
2780 s
= lookup_symbol("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
2782 /* Most programs do not play with signals */
2786 b0
= SYMBOL_BLOCK_VALUE(s
);
2788 /* A label of sigvec, to be more precise */
2789 s
= lookup_symbol("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
2791 /* But maybe this program uses its own version of sigvec */
2795 sigtramp_address
= SYMBOL_VALUE(s
);
2796 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
2798 /* Did we or MIPSco fix the library ? */
2799 if (SYMBOL_CLASS(s
) == LOC_BLOCK
)
2802 /* But what symtab does it live in ? */
2803 st
= find_pc_symtab(SYMBOL_VALUE(s
));
2806 * Ok, there goes the fix: turn it into a procedure, with all the
2807 * needed info. Note we make it a nested procedure of sigvec,
2808 * which is the way the (assembly) code is actually written.
2810 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2811 SYMBOL_CLASS(s
) = LOC_BLOCK
;
2812 SYMBOL_TYPE(s
) = make_type(TYPE_CODE_FUNC
, 4, 0, 0);
2813 TYPE_TARGET_TYPE(SYMBOL_TYPE(s
)) = builtin_type_void
;
2815 /* Need a block to allocate .gdbinfo. in */
2817 SYMBOL_BLOCK_VALUE(s
) = b
;
2818 BLOCK_START(b
) = sigtramp_address
;
2819 BLOCK_END(b
) = sigtramp_end
;
2820 BLOCK_FUNCTION(b
) = s
;
2821 BLOCK_SUPERBLOCK(b
) = BLOCK_SUPERBLOCK(b0
);
2825 /* Make a .gdbinfo. for it */
2827 struct mips_extra_func_info
*e
=
2828 (struct mips_extra_func_info
*)
2829 xzalloc(sizeof(struct mips_extra_func_info
));
2831 e
->numargs
= 0; /* the kernel thinks otherwise */
2832 /* align_longword(sigcontext + SIGFRAME) */
2833 e
->framesize
= 0x150;
2834 e
->framereg
= SP_REGNUM
;
2837 e
->regoffset
= -(41 * sizeof(int));
2839 e
->fregoffset
= -(37 * sizeof(int));
2842 s
= new_symbol(".gdbinfo.");
2843 SYMBOL_VALUE(s
) = (int) e
;
2844 SYMBOL_NAMESPACE(s
) = LABEL_NAMESPACE
;
2845 SYMBOL_CLASS(s
) = LOC_CONST
;
2846 SYMBOL_TYPE(s
) = builtin_type_void
;
2849 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
2853 /* Initialization */
2855 static struct sym_fns ecoff_sym_fns
= {"ecoff", 5,
2856 mipscoff_new_init
, mipscoff_symfile_init
,
2857 mipscoff_symfile_read
, mipscoff_symfile_discard
};
2859 _initialize_mipsread ()
2861 add_symtab_fns (&ecoff_sym_fns
);
2863 bzero (&global_psymbols
, sizeof (global_psymbols
));
2864 bzero (&static_psymbols
, sizeof (static_psymbols
));
2866 add_com("add-file", class_files
, add_file_command
,
2867 "Add a new symbol table (in mips format) from file FILE.");
2869 /* Missing basic types */
2870 builtin_type_string
= make_type(TYPE_CODE_PASCAL_ARRAY
,
2872 builtin_type_complex
= make_type(TYPE_CODE_FLT
,
2873 2 * sizeof(float), 0, "complex");
2874 builtin_type_double_complex
= make_type(TYPE_CODE_FLT
,
2875 2 * sizeof(double), 0, "double_complex");
2876 builtin_type_fixed_dec
= make_type(TYPE_CODE_INT
, sizeof(int),
2877 0, "fixed_decimal");
2878 builtin_type_float_dec
= make_type(TYPE_CODE_FLT
, sizeof(double),
2879 0, "floating_decimal");
2881 /* Templates types */
2882 builtin_type_ptr
= lookup_pointer_type (builtin_type_void
);
2883 builtin_type_struct
= make_type(TYPE_CODE_STRUCT
, 0, 0, 0);
2884 builtin_type_union
= make_type(TYPE_CODE_UNION
, 0, 0, 0);
2885 builtin_type_enum
= make_type(TYPE_CODE_ENUM
, 0, 0, 0);
2886 builtin_type_range
= make_type(TYPE_CODE_RANGE
, 0, 0, 0);
2887 builtin_type_set
= make_type(TYPE_CODE_SET
, 0, 0, 0);