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 /* Since these things are defined differently on various systems I'll
36 (re)define here what I really need in this module. I only assume the
37 three standard COFF structure definitions: filehdr, aouthdr, scnhdr */
38 #define MIPS /* Kludge to get MIPS version of coff */
39 #include "intel-coff.h"
51 #define a_magic a.magic /* magic number */
52 #define a_text a.tsize /* size of text segment */
53 #define a_data a.dsize /* size of initialized data */
54 #define a_bss a.bsize /* size of uninitialized data */
55 #define a_syms f.f_nsyms /* size of symbol table */
56 #define a_entry a.entry /* entry point */
60 (((x).a_magic)!=OMAGIC && ((x).a_magic)!=NMAGIC && ((x).a_magic)!=ZMAGIC)
62 /* Things we import explicitly from other modules */
64 extern int info_verbose
;
65 extern struct block
*block_for_pc();
66 extern void sort_symtab_syms();
68 /* Forward declarations */
70 static void psymtab_to_symtab_1();
72 /* Macros and extra defs */
74 struct complaint unknown_ext_complaint
=
75 {"unknown external symbol %s", 0, 0};
77 /* Already parsed symbols are marked specially */
79 #define stParsed stType
81 /* Puns: hard to find whether -g was used and how */
83 #define MIN_GLEVEL GLEVEL_0
84 #define compare_glevel(a,b) \
85 (((a) == GLEVEL_3) ? ((b) < GLEVEL_3) : \
86 ((b) == GLEVEL_3) ? -1 : (int)((b) - (a)))
88 /* When looking at .o files avoid tripping over bad addresses */
90 #define SAFE_TEXT_ADDR 0x400000
91 #define SAFE_DATA_ADDR 0x10000000
93 #define UNSAFE_DATA_ADDR(p) ((unsigned)p < SAFE_DATA_ADDR || (unsigned)p > 2*SAFE_DATA_ADDR)
96 /* Things we export to other modules */
99 /* Lists of partial symbols */
101 struct psymbol_allocation_list global_psymbols
, static_psymbols
;
103 /* Address bounds for the signal trampoline in inferior, if any */
105 CORE_ADDR sigtramp_address
, sigtramp_end
;
108 /* Functions that we really export */
110 /* THIS DESCRIPTION IS OBSOLETE POST-BFD; FIXME! */
111 /* Basically, this module must provide two functions: symbol_file_command()
112 which loads the symbol table from a file, and add_file_command() which
113 adds more symbols to the symbol table (incrementally).
115 These two functions only do the minimum work necessary for letting the
116 user "name" things symbolically, they do not read the entire symtab.
117 Instead, they read in the external symbols and put them in partial
118 symbol tables. When more extensive information is requested of a
119 file the corresponding partial symbol table is mutated into a full
120 fledged symbol table by going back and reading the relative symbols
121 for real. mipscoff_psymtab_to_symtab() is the function that does this */
123 /* The entry point (starting address) of the file, if it is an executable. */
125 static CORE_ADDR entry_point
;
127 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
128 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
136 mipscoff_symfile_init (sf
)
139 bfd
*abfd
= sf
->sym_bfd
;
140 sf
->sym_private
= NULL
;
141 /* Save startup file's range of PC addresses to help blockframe.c
142 decide where the bottom of the stack is. */
143 if (bfd_get_file_flags (abfd
) & EXEC_P
)
145 /* Executable file -- record its entry point so we'll recognize
146 the startup file because it contains the entry point. */
147 entry_point
= bfd_get_start_address (abfd
);
151 /* Examination of non-executable.o files. Short-circuit this stuff. */
152 /* ~0 will not be in any file, we hope. */
154 /* set the startup file to be an empty range. */
155 startup_file_start
= 0;
156 startup_file_end
= 0;
161 mipscoff_symfile_read(sf
, addr
, mainline
)
166 struct coff_symfile_info
*info
= (struct coff_symfile_info
*)sf
->sym_private
;
167 bfd
*abfd
= sf
->sym_bfd
;
168 char *name
= bfd_get_filename (abfd
);
173 int stringtab_offset
;
175 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
176 desc
= fileno ((FILE *)(abfd
->iostream
)); /* Raw file descriptor */
177 num_symbols
= bfd_get_symcount (abfd
); /* How many syms */
178 /* symtab_offset = obj_sym_filepos (abfd); * Symbol table file offset */
179 /* stringtab_offset = symtab_offset + num_symbols * SYMESZ; * String tab */
183 debug_info
= text_hdr
.s_relptr
;
186 dc_terminate (tdesc_handle
);
192 /* Read the line number table, all at once. */
193 info
->min_lineno_offset
= 0;
194 info
->max_lineno_offset
= 0;
195 bfd_map_over_sections (abfd
, find_linenos
, info
);
197 val
= init_lineno (desc
, info
->min_lineno_offset
,
198 info
->max_lineno_offset
- info
->min_lineno_offset
);
200 error ("\"%s\": error reading line numbers\n", name
);
202 /* Now read the string table, all at once. */
204 val
= init_stringtab (desc
, stringtab_offset
);
207 free_all_symtabs (); /* FIXME blows whole symtab */
208 printf ("\"%s\": can't get string table", name
);
212 make_cleanup (free_stringtab
, 0);
214 /* Position to read the symbol table. Do not read it all at once. */
215 val
= lseek (desc
, (long)symtab_offset
, 0);
217 perror_with_name (name
);
219 init_misc_bunches ();
220 make_cleanup (discard_misc_bunches
, 0);
222 /* Now that the executable file is positioned at symbol table,
223 process it and define symbols accordingly. */
225 printf("Reading symbol data from %s...", name
);
227 read_mips_symtab(desc
, 0);
229 /* patch_opaque_types ();*/
231 /* Sort symbols alphabetically within each block. */
233 sort_all_symtab_syms ();
235 /* Go over the misc symbol bunches and install them in vector. */
237 condense_misc_bunches (0);
239 /* Make a default for file to list. */
241 select_source_symtab (0); /* FIXME, this might be too slow, see dbxread */
245 mipscoff_symfile_discard()
251 /* Exported procedure: Reads symbols from file NAME.
252 Invoked at startup time if executable was given.
253 When invoked cleans up the world */
256 symbol_file_command(name
, from_tty
)
261 struct coff_exec hdr
;
264 struct cleanup
*old_chain
;
269 * Make sure s/he means it
272 if ((symtab_list
|| partial_symtab_list
)
274 && !query("Discard symbol table? ", 0))
275 error("Not confirmed.");
276 destroy_all_symtabs();
280 name
= tilde_expand(name
);
281 make_cleanup(free
, name
);
284 !query("Load new symbol table from \"%s\"? ", name
))
285 error("Not confirmed.");
290 desc
= openp (getenv ("PATH"), 1, name
, O_RDONLY
, 0, &absolute_name
);
292 perror_with_name (name
);
294 name
= absolute_name
;
297 old_chain
= make_cleanup (close
, desc
);
298 make_cleanup (free_current_contents
, &name
);
301 * Check file is indeed executable
303 val
= myread(desc
, &hdr
, sizeof hdr
);
305 perror_with_name(name
);
308 error("File \"%s\" not in executable format.", name
);
310 if (hdr
.a
.entry
< SAFE_TEXT_ADDR
&& access(name
, 1))
311 printf_filtered("Warning: %s is not executable!\n", name
);
313 if (hdr
.a_syms
== 0) {
314 printf_filtered("%s does not have a symbol-table.\n", name
);
319 /* Get the modification time. */
323 if (fstat (desc
, &symstat
) < 0)
324 perror_with_name (name
);
326 symfile_mtime
= symstat
.st_mtime
;
330 * Throw away the old symbol table.
333 destroy_all_symtabs();
335 /* Make a default for file to list. */
337 symfile
= savestring (name
, strlen (name
));
339 /* Prepare to remember misc symbol values */
341 init_misc_bunches ();
342 make_cleanup (discard_misc_bunches
, 0);
345 * Now read the new symbol table
348 read_mips_symtab(desc
, 0);
350 /* Go over the misc symbol bunches and install them in vector. */
352 condense_misc_bunches (0);
354 /* Don't allow char * to have a typename (else would get caddr_t.) */
356 TYPE_NAME (lookup_pointer_type (builtin_type_char
)) = 0;
358 /* Force reinit of the sigtramp info */
359 sigtramp_address
= 0;
361 do_cleanups (old_chain
); /* Descriptor closed here */
363 if (!partial_symtab_list
)
364 printf ("\n(no debugging symbols found)...");
372 This function allows the addition of incrementally linked object files.
373 Since this has a fair amount of code in common with symbol_file_command,
374 it might be worthwhile to consolidate things, as was done with
375 read_dbx_symtab and condense_misc_bunches. */
377 /* Exported procedure: add more symbols from file NAME. */
380 add_file_command(arg_string
)
384 struct coff_exec hdr
;
387 struct cleanup
*old_chain
;
392 error ("add-file takes a file name and an address");
395 error ("add-file takes a file name and an address");
397 arg_string
= tilde_expand (arg_string
);
398 make_cleanup (free
, arg_string
);
400 for( ; *arg_string
== ' '; arg_string
++ );
402 for( ; *arg_string
&& *arg_string
!= ' ' ; arg_string
++ );
403 *arg_string
++ = (char) 0;
406 error ("add-file takes a file name and an address");
408 text_addr
= parse_and_eval_address (arg_string
);
412 if (!query ("add symbol table from filename \"%s\" at text_addr = 0x%x\n",
414 error ("Not confirmed.");
422 desc
= openp(getenv("PATH"), 1, name
, O_RDONLY
, 0, &absolute_name
);
424 perror_with_name(name
);
426 name
= absolute_name
;
428 old_chain
= make_cleanup (close
, desc
);
432 * Check file is indeed executable
434 val
= myread(desc
, &hdr
, sizeof hdr
);
436 perror_with_name(name
);
439 error("File \"%s\" not in executable format.", name
);
441 if (hdr
.a
.entry
< SAFE_TEXT_ADDR
&& access(name
, 1))
442 printf_filtered("Warning: %s is not executable!\n", name
);
444 if (hdr
.a_syms
== 0) {
445 printf_filtered("%s does not have a symbol-table.\n", name
);
455 * Now read the new symbol table
458 symfile
= savestring(name
, strlen(name
));
460 init_misc_bunches ();
461 make_cleanup (discard_misc_bunches
, 0);
462 read_mips_symtab(desc
, 1);
464 /* Go over the misc symbol bunches and install them in vector. */
466 condense_misc_bunches (1);
468 /* Don't allow char * to have a typename (else would get caddr_t.) */
470 TYPE_NAME (lookup_pointer_type (builtin_type_char
)) = 0;
472 do_cleanups (old_chain
);
474 printf_filtered("done.\n");
478 /* Exported procedure: Allocate zeroed memory */
482 char *p
= xmalloc(size
);
488 /* Exported procedure: Builds a symtab from the PST partial one.
489 Restores the environment in effect when PST was created, delegates
490 most of the work to an ancillary procedure, and sorts
491 and reorders the symtab list at the end */
494 static HDRR
*cur_hdr
; /* MIPS symtab header for the current file */
497 mipscoff_psymtab_to_symtab(pst
)
498 struct partial_symtab
*pst
;
507 printf_filtered("Reading in symbols for %s...", pst
->filename
);
510 /* Restore the header and list of pending typedefs */
511 cur_hdr
= (HDRR
*) pst
->ldsymlen
;
513 psymtab_to_symtab_1(pst
);
517 /* Finish up the debug error message. */
519 printf_filtered("done.\n");
522 /* Exported procedure: Is PC in the signal trampoline code */
524 int in_sigtramp(pc
,name
)
527 if (sigtramp_address
== 0)
529 return (pc
>= sigtramp_address
&& pc
< sigtramp_end
);
533 /* Things that really are local to this module */
535 /* All allocated symtabs and psymtabs */
537 static int all_symtabs_count
;
538 static int all_psymtabs_count
;
540 /* GDB symtable for the current compilation unit */
542 static struct symtab
*cur_stab
;
544 /* Header for executable/object file we read symbols from */
546 static struct coff_exec filhdr
;
547 #define END_OF_TEXT_SEGMENT(f) ((f).a.text_start + (f).a.tsize)
549 /* Pointer to current file decriptor record, and its index */
554 /* Index of current symbol */
558 /* Note how much "debuggable" this image is. We would like
559 to see at least one FDR with full symbols */
564 /* When examining .o files, report on undefined symbols */
566 static int n_undef_symbols
, n_undef_labels
, n_undef_vars
, n_undef_procs
;
568 /* Extra builtin types */
570 struct type
*builtin_type_complex
;
571 struct type
*builtin_type_double_complex
;
572 struct type
*builtin_type_fixed_dec
;
573 struct type
*builtin_type_float_dec
;
574 struct type
*builtin_type_string
;
578 static struct type
*builtin_type_ptr
;
579 static struct type
*builtin_type_struct
;
580 static struct type
*builtin_type_union
;
581 static struct type
*builtin_type_enum
;
582 static struct type
*builtin_type_range
;
583 static struct type
*builtin_type_set
;
588 static struct symbol
*new_symbol();
589 static struct type
*new_type();
590 static struct field
*new_field();
591 static struct block
*new_block();
592 static struct symtab
*new_symtab();
593 static struct linetable
*new_linetable();
594 static struct blockvector
*new_bvect();
596 static struct type
*parse_type();
597 static struct type
*make_type();
598 static struct symbol
*mylookup_symbol();
599 static struct block
*shrink_block();
601 static int compare_symtabs();
602 static int compare_psymtabs();
603 static int compare_blocks();
605 static struct partial_symtab
*new_psymtab();
606 static struct partial_symbol
*new_psymbol();
607 static struct partial_symtab
*parse_fdr();
608 static int compare_psymbols();
610 /* File-level interface functions */
612 /* Read the symtab information from file FSYM into memory */
615 read_the_mips_symtab(fsym
)
617 int stsize
, st_hdrsize
;
621 /* Find and read the symbol table header */
622 st_hdrsize
= filhdr
.f
.f_nsyms
;
623 st_filptr
= filhdr
.f
.f_symptr
;
627 lseek(fsym
, st_filptr
, L_SET
);
628 if (read(fsym
, &st_hdr
, st_hdrsize
) != st_hdrsize
)
631 /* Find out how large the symbol table is */
632 stsize
= (st_hdr
.cbExtOffset
- (st_filptr
+ st_hdrsize
))
633 + st_hdr
.iextMax
* cbEXTR
;
635 /* Allocate space for the symbol table. Read it in. */
636 cur_hdr
= (HDRR
*) xmalloc(stsize
+ st_hdrsize
);
638 bcopy(&st_hdr
, cur_hdr
, st_hdrsize
);
639 if (read(fsym
, (char *) cur_hdr
+ st_hdrsize
, stsize
) != stsize
)
642 /* Fixup file_pointers in it */
643 fixup_symtab(cur_hdr
, (char *) cur_hdr
+ st_hdrsize
,
644 st_filptr
+ st_hdrsize
);
648 error("Short read on %s", symfile
);
652 /* Turn all file-relative pointers in the symtab described by HDR
653 into memory pointers, given that the symtab itself is located
654 at DATA in memory and F_PTR in the file. */
657 fixup_symtab( hdr
, data
, f_ptr
)
669 * These fields are useless (and empty) by now:
670 * hdr->cbDnOffset, hdr->cbOptOffset
671 * We use them for other internal purposes.
674 hdr
->cbOptOffset
= 0;
677 if (hdr->off) hdr->off = (unsigned int)data + (hdr->off - f_ptr);
693 * Fix all string pointers inside the symtab, and
694 * the FDR records. Also fix other miscellany.
696 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
697 register unsigned code_offset
;
699 /* Header itself, and strings */
700 fh
= (FDR
*) (hdr
->cbFdOffset
) + f_idx
;
701 fh
->issBase
+= hdr
->cbSsOffset
;
703 fh
->rss
= (long)fh
->rss
+ fh
->issBase
;
704 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
705 sh
= (SYMR
*)(hdr
->cbSymOffset
) + fh
->isymBase
+ s_idx
;
706 sh
->iss
= (long) sh
->iss
+ fh
->issBase
;
713 fh
->isymBase
= (int)((SYMR
*)(hdr
->cbSymOffset
)+fh
->isymBase
);
715 /* cannot fix fh->ipdFirst because it is a short */
716 #define IPDFIRST(h,fh) \
717 ((long)h->cbPdOffset + fh->ipdFirst * sizeof(PDR))
719 /* Optional symbols (actually used for partial_symtabs) */
725 fh
->iauxBase
= hdr
->cbAuxOffset
+ fh
->iauxBase
* sizeof(AUXU
);
726 /* Relative file descriptor table */
727 fh
->rfdBase
= hdr
->cbRfdOffset
+ fh
->rfdBase
* sizeof(RFDT
);
731 fh
->cbLineOffset
+= hdr
->cbLineOffset
;
733 /* Procedure symbols. (XXX This should be done later) */
734 code_offset
= fh
->adr
;
735 for (s_idx
= 0; s_idx
< fh
->cpd
; s_idx
++) {
736 unsigned name
, only_ext
;
738 pr
= (PDR
*)(IPDFIRST(hdr
,fh
)) + s_idx
;
740 /* Simple rule to find files linked "-x" */
741 only_ext
= fh
->rss
== -1;
743 if (pr
->isym
== -1) {
744 /* static function */
748 name
= hdr
->cbExtOffset
+ pr
->isym
* sizeof(EXTR
);
749 sh
= &((EXTR
*)name
)->asym
;
753 sh
= (SYMR
*)fh
->isymBase
+ pr
->isym
;
754 /* Included code ? */
755 if (s_idx
== 0 && pr
->adr
!= 0)
756 code_offset
-= pr
->adr
;
759 /* Turn index into a pointer */
762 /* Fix line numbers */
763 pr
->cbLineOffset
+= fh
->cbLineOffset
;
765 /* Relocate address */
767 pr
->adr
+= code_offset
;
771 /* External symbols: fix string */
772 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
773 esh
= (EXTR
*)(hdr
->cbExtOffset
) + s_idx
;
774 esh
->asym
.iss
= esh
->asym
.iss
+ hdr
->cbSsExtOffset
;
779 /* Find a file descriptor given its index RF relative to a file CF */
782 FDR
*get_rfd( cf
, rf
)
786 f
= (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
787 /* Object files do not have the RFD table, all refs are absolute */
789 return (FDR
*) (cur_hdr
->cbFdOffset
) + rf
;
790 cf
= *((pRFDT
) f
->rfdBase
+ rf
);
791 return (FDR
*) (cur_hdr
->cbFdOffset
) + cf
;
794 /* Return a safer print NAME for a file descriptor */
800 if (name
== (char *) -1)
801 return "<stripped file>";
802 if (UNSAFE_DATA_ADDR(name
))
808 /* Read in and parse the symtab of the file DESC. INCREMENTAL says
809 whether we are adding to the general symtab or not */
812 read_mips_symtab( desc
, incremental
)
815 * We get here with DESC pointing to the symtab header. But we need
816 * other info from the initial headers
819 myread(desc
, &filhdr
, sizeof filhdr
);
821 read_the_mips_symtab(desc
);
823 parse_partial_symbols(cur_hdr
, incremental
);
827 * Check to make sure file was compiled with -g.
828 * If not, warn the user of this limitation.
830 if (compare_glevel(max_glevel
, GLEVEL_2
) < 0) {
831 if (max_gdbinfo
== 0)
832 printf("\n%s not compiled with -g, debugging support is limited.", symfile
);
833 printf("\nYou should compile with -g2 or -g3 for best debugging support.\n");
838 * Dont allow char * to have a typename (else would get
841 TYPE_NAME(lookup_pointer_type(builtin_type_char
)) = 0;
845 /* Local utilities */
848 /* Map of FDR indexes to partial symtabs */
850 static struct pst_map
{
851 struct partial_symtab
*pst
; /* the psymtab proper */
852 int n_globals
; /* globals it exports */
856 /* Utility stack, used to nest procedures and blocks properly.
857 It is a doubly linked list, to avoid too many alloc/free.
858 Since we might need it quite a few times it is NOT deallocated
861 static struct parse_stack
{
862 struct parse_stack
*next
, *prev
;
863 struct symtab
*cur_st
; /* Current symtab */
864 struct block
*cur_block
; /* Block in it */
865 int blocktype
; /* What are we parsing */
866 int maxsyms
; /* Max symbols in this block */
867 struct type
*cur_type
; /* Type we parse fields for */
868 int procadr
; /* Start addres of this procedure */
869 int numargs
; /* Its argument count */
870 } *top_stack
; /* Top stack ptr */
873 /* Enter a new lexical context */
875 static push_parse_stack()
877 struct parse_stack
*new;
879 /* Reuse frames if possible */
880 if (top_stack
&& top_stack
->prev
)
881 new = top_stack
->prev
;
883 new = (struct parse_stack
*) xzalloc(sizeof(struct parse_stack
));
884 /* Initialize new frame with previous content */
886 register struct parse_stack
*prev
= new->prev
;
889 top_stack
->prev
= new;
891 new->next
= top_stack
;
896 /* Exit a lexical context */
898 static pop_parse_stack()
903 top_stack
= top_stack
->next
;
907 /* Cross-references might be to things we haven't looked at
908 yet, e.g. type references. To avoid too many type
909 duplications we keep a quick fixup table, an array
910 of lists of references indexed by file descriptor */
912 static struct pending
{
913 struct pending
*next
; /* link */
914 SYMR
*s
; /* the symbol */
915 struct type
*t
; /* its partial type descriptor */
919 /* Check whether we already saw symbol SH in file FH as undefined */
922 struct pending
*is_pending_symbol(fh
, sh
)
926 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
927 register struct pending
*p
;
929 /* Linear search is ok, list is typically no more than 10 deep */
930 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
936 /* Check whether we already saw type T in file FH as undefined */
939 struct pending
*is_pending_type(fh
, t
)
943 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
944 register struct pending
*p
;
946 for (p
= pending_list
[f_idx
]; p
; p
= p
->next
)
952 /* Add a new undef symbol SH of type T */
955 add_pending(fh
, sh
, t
)
960 int f_idx
= fh
- (FDR
*) cur_hdr
->cbFdOffset
;
961 struct pending
*p
= is_pending_symbol(fh
, sh
);
963 /* Make sure we do not make duplicates */
965 p
= (struct pending
*) xmalloc(sizeof(*p
));
968 p
->next
= pending_list
[f_idx
];
969 pending_list
[f_idx
] = p
;
971 sh
->reserved
= 1; /* for quick check */
974 /* Throw away undef entries when done with file index F_IDX */
979 register struct pending
*p
, *q
;
981 for (p
= pending_list
[f_idx
]; p
; p
= q
) {
985 pending_list
[f_idx
] = 0;
988 /* The number of args to a procedure is not explicit in the symtab,
989 this is the list of all those we know of.
990 This makes parsing more reasonable and avoids extra passes */
992 static struct numarg
{
993 struct numarg
*next
; /* link */
994 unsigned adr
; /* procedure's start address */
995 unsigned num
; /* arg count */
998 /* Record that the procedure at ADR takes NUM arguments. */
1001 got_numargs(adr
,num
)
1003 struct numarg
*n
= (struct numarg
*) xmalloc(sizeof(struct numarg
));
1007 n
->next
= numargs_list
;
1011 /* See if we know how many arguments the procedure at ADR takes */
1016 struct numarg
*n
= numargs_list
;
1018 while (n
&& n
->adr
!= adr
)
1020 return (n
) ? n
->num
: -1;
1023 /* Release storage when done with this file */
1028 struct numarg
*n
= numargs_list
, *m
;
1039 /* Parsing Routines proper. */
1041 /* Parse a single symbol. Mostly just make up a GDB symbol for it.
1042 For blocks, procedures and types we open a new lexical context.
1043 This is basically just a big switch on the symbol's type */
1046 parse_symbol(sh
, ax
)
1054 /* When a symbol is cross-referenced from other files/symbols
1055 we mark it explicitly */
1056 int pend
= (sh
->reserved
== 1);
1057 enum address_class
class;
1064 case stGlobal
: /* external symbol, goes into the primary block */
1066 b
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
), 0);
1069 case stStatic
: /* static data, goes into the current block. */
1071 b
= top_stack
->cur_block
;
1074 case stLocal
: /* local variable, goes into the current block */
1075 if (sh
->sc
== scRegister
) {
1076 class = LOC_REGISTER
;
1081 b
= top_stack
->cur_block
;
1083 data
: /* Common code for symbols describing data */
1084 s
= new_symbol(sh
->iss
);
1085 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1086 SYMBOL_CLASS(s
) = class;
1089 /* Type could be missing in a number of cases */
1090 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
||
1091 sh
->index
== 0xfffff)
1092 SYMBOL_TYPE(s
) = builtin_type_int
; /* undefined? */
1094 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
1095 /* Value of a data symbol is its memory address */
1096 SYMBOL_VALUE(s
) = sh
->value
;
1099 case stParam
: /* argument to procedure, goes into current block */
1101 top_stack
->numargs
++;
1102 s
= new_symbol(sh
->iss
);
1103 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1104 if (sh
->sc
== scRegister
) {
1105 SYMBOL_CLASS(s
) = LOC_REGPARM
;
1109 SYMBOL_CLASS(s
) = LOC_ARG
;
1110 SYMBOL_VALUE(s
) = sh
->value
;
1111 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
1112 add_symbol(s
, top_stack
->cur_block
);
1115 case stLabel
: /* label, we do make a symbol for it */
1116 s
= new_symbol(sh
->iss
);
1117 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
; /* so that it can be used */
1118 SYMBOL_CLASS(s
) = LOC_LABEL
; /* but not misused */
1119 SYMBOL_VALUE(s
) = sh
->value
;
1120 SYMBOL_TYPE(s
) = builtin_type_int
;
1121 add_symbol(s
, top_stack
->cur_block
);
1124 case stProc
: /* Procedure */
1125 case stStaticProc
: /* Static procedure */
1126 s
= new_symbol(sh
->iss
);
1127 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1128 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1129 /* Type of the return value */
1130 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
1131 t
= builtin_type_int
;
1133 t
= parse_type(ax
+ sh
->index
, sh
, 0);
1134 add_symbol(s
, top_stack
->cur_block
);
1136 /* Make a type for the procedure itself */
1137 SYMBOL_TYPE(s
) = lookup_function_type (t
);
1139 /* Create and enter a new lexical context */
1140 b
= new_block(top_stack
->maxsyms
);
1141 SYMBOL_BLOCK_VALUE(s
) = b
;
1142 BLOCK_FUNCTION(b
) = s
;
1143 BLOCK_START(b
) = BLOCK_END(b
) = sh
->value
;
1144 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1145 add_block(b
, top_stack
->cur_st
);
1147 /* Not if we only have partial info */
1148 if (sh
->sc
== scUndefined
|| sh
->sc
== scNil
)
1152 top_stack
->cur_block
= b
;
1153 top_stack
->blocktype
= sh
->st
;
1154 top_stack
->cur_type
= SYMBOL_TYPE(s
);
1155 top_stack
->procadr
= sh
->value
;
1156 top_stack
->numargs
= 0;
1158 sh
->value
= (long) SYMBOL_TYPE(s
);
1161 case stBlock
: /* Either a lexical block, or some type */
1163 top_stack
->blocktype
= stBlock
;
1164 if (sh
->sc
== scInfo
) { /* structure/union/enum def */
1165 s
= new_symbol(sh
->iss
);
1166 SYMBOL_NAMESPACE(s
) = STRUCT_NAMESPACE
;
1167 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1168 SYMBOL_VALUE(s
) = 0;
1169 add_symbol(s
, top_stack
->cur_block
);
1170 /* If this type was expected, use its partial definition */
1172 t
= is_pending_symbol(cur_fdr
, sh
)->t
;
1174 /* Uhmm, can`t decide yet. Smash later */
1175 t
= new_type(sh
->iss
);
1176 TYPE_CODE(t
) = TYPE_CODE_UNDEF
;
1177 add_pending(cur_fdr
, sh
, t
);
1180 /* make this the current type */
1181 top_stack
->cur_type
= t
;
1182 TYPE_LENGTH(t
) = sh
->value
;
1183 /* Mark that symbol has a type, and say which one */
1184 sh
->value
= (long) t
;
1186 /* beginnning of (code) block. Value of symbol
1187 is the displacement from procedure start */
1188 b
= new_block(top_stack
->maxsyms
);
1189 BLOCK_START(b
) = sh
->value
+ top_stack
->procadr
;
1190 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1191 top_stack
->cur_block
= b
;
1192 add_block(b
, top_stack
->cur_st
);
1196 case stEnd
: /* end (of anything) */
1197 if (sh
->sc
== scInfo
) {
1198 /* Finished with type */
1199 top_stack
->cur_type
= 0;
1200 } else if (sh
->sc
== scText
&&
1201 (top_stack
->blocktype
== stProc
||
1202 top_stack
->blocktype
== stStaticProc
)) {
1203 /* Finished with procedure */
1204 struct blockvector
*bv
= BLOCKVECTOR(top_stack
->cur_st
);
1208 BLOCK_END(top_stack
->cur_block
) += sh
->value
; /* size */
1209 got_numargs(top_stack
->procadr
, top_stack
->numargs
);
1210 /* Reallocate symbols, saving memory */
1211 b
= shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1213 /* f77 emits proc-level with address bounds==[0,0],
1214 So look for such child blocks, and patch them. */
1215 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++) {
1216 struct block
*b_bad
= BLOCKVECTOR_BLOCK(bv
,i
);
1217 if (BLOCK_SUPERBLOCK(b_bad
) == b
1218 && BLOCK_START(b_bad
) == top_stack
->procadr
1219 && BLOCK_END(b_bad
) == top_stack
->procadr
) {
1220 BLOCK_START(b_bad
) = BLOCK_START(b
);
1221 BLOCK_END(b_bad
) = BLOCK_END(b
);
1224 } else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
) {
1225 /* End of (code) block. The value of the symbol
1226 is the displacement from the procedure`s start
1227 address of the end of this block. */
1228 BLOCK_END(top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1229 (void) shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1231 pop_parse_stack(); /* restore previous lexical context */
1234 case stMember
: /* member of struct/union/enum.. */
1235 f
= new_field(top_stack
->cur_type
, sh
->iss
);
1236 f
->bitpos
= sh
->value
;
1237 f
->type
= parse_type(ax
+ sh
->index
, sh
, &f
->bitsize
);
1240 case stTypedef
: /* type definition */
1241 s
= new_symbol(sh
->iss
);
1242 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1243 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1244 SYMBOL_BLOCK_VALUE(s
) = top_stack
->cur_block
;
1245 add_symbol(s
, top_stack
->cur_block
);
1246 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
1247 sh
->value
= (long) SYMBOL_TYPE(s
);
1250 case stFile
: /* file name */
1252 top_stack
->blocktype
= sh
->st
;
1255 /* I`ve never seen these for C */
1257 break; /* register relocation */
1259 break; /* forwarding address */
1261 break; /* constant */
1263 error("Unknown symbol type %x.", sh
->st
);
1268 /* Parse the type information provided in the AX entries for
1269 the symbol SH. Return the bitfield size in BS, in case. */
1271 static struct type
*parse_type(ax
, sh
, bs
)
1276 /* Null entries in this map are treated specially */
1277 static struct type
**map_bt
[] =
1279 &builtin_type_void
, /* btNil */
1281 &builtin_type_char
, /* btChar */
1282 &builtin_type_unsigned_char
, /* btUChar */
1283 &builtin_type_short
, /* btShort */
1284 &builtin_type_unsigned_short
, /* btUShort */
1285 &builtin_type_int
, /* btInt */
1286 &builtin_type_unsigned_int
, /* btUInt */
1287 &builtin_type_long
, /* btLong */
1288 &builtin_type_unsigned_long
, /* btULong */
1289 &builtin_type_float
, /* btFloat */
1290 &builtin_type_double
, /* btDouble */
1297 &builtin_type_complex
, /* btComplex */
1298 &builtin_type_double_complex
, /* btDComplex */
1300 &builtin_type_fixed_dec
, /* btFixedDec */
1301 &builtin_type_float_dec
, /* btFloatDec */
1302 &builtin_type_string
, /* btString */
1305 &builtin_type_void
, /* btVoid */
1309 struct type
*tp
= 0, *tp1
;
1312 /* Procedures start off by one */
1313 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
)
1316 /* Undefined ? Should not happen */
1317 if (ax
->rndx
.rfd
== 0xfff) {
1318 return builtin_type_void
;
1321 /* Use aux as a type information record, map its basic type */
1323 if (t
->bt
> 26 || t
->bt
== btPicture
) {
1324 printf_filtered("Internal: cannot map MIPS basic type x%x\n", t
->bt
);
1325 return builtin_type_int
;
1328 tp
= *map_bt
[t
->bt
];
1330 /* Cannot use builtin types, use templates */
1331 tp
= make_type(TYPE_CODE_VOID
, 0, 0, 0);
1334 *tp
= *builtin_type_ptr
;
1337 *tp
= *builtin_type_struct
;
1341 *tp
= *builtin_type_union
;
1345 *tp
= *builtin_type_enum
;
1349 *tp
= *builtin_type_range
;
1352 *tp
= *builtin_type_set
;
1358 /* Move on to next aux */
1361 /* This is the way it would work if the compiler worked */
1362 register TIR
*t1
= t
;
1363 while (t1
->continued
)
1367 /* For bitfields all we need is the width */
1373 /* All these types really point to some (common) MIPS type
1374 definition, and only the type-qualifiers fully identify
1375 them. We`ll make the same effort at sharing */
1376 if (t
->bt
== btIndirect
||
1377 t
->bt
== btStruct
||
1380 t
->bt
== btTypedef
||
1383 char name
[256], *pn
;
1385 /* Try to cross reference this type */
1387 ax
+= cross_ref(ax
, &tp1
, &pn
);
1388 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1389 sprintf(name
, fmt
, pn
);
1391 /* reading .o file ? */
1392 if (UNSAFE_DATA_ADDR(tp1
))
1394 if (TYPE_CODE(tp1
) == TYPE_CODE_UNDEF
) {
1396 * Type was incompletely defined, now we know.
1398 TYPE_CODE(tp1
) = TYPE_CODE(tp
);
1399 TYPE_NAME(tp1
) = obsavestring(name
, strlen(name
));
1400 if (TYPE_CODE(tp1
) == TYPE_CODE_ENUM
) {
1403 for (i
= 0; i
< TYPE_NFIELDS(tp1
); i
++)
1404 make_enum_constant(&TYPE_FIELD(tp1
,i
), tp1
);
1408 /* found as cross ref, rid of our template */
1409 if ((TYPE_FLAGS(tp
) & TYPE_FLAG_PERM
) == 0)
1412 /* stupid idea of prepending "struct" to type names */
1413 if (t
->bt
== btStruct
&& !index(TYPE_NAME(tp
), ' ')) {
1414 sprintf(name
, fmt
, TYPE_NAME(tp
));
1415 TYPE_NAME(tp
) = obsavestring(name
, strlen(name
));
1418 TYPE_NAME(tp
) = savestring(name
, strlen(name
));
1421 /* Deal with range types */
1422 if (t
->bt
== btRange
) {
1425 f
= new_field(tp
, "Low");
1426 f
->bitpos
= ax
->dnLow
;
1428 f
= new_field(tp
, "High");
1429 f
->bitpos
= ax
->dnHigh
;
1433 /* Parse all the type qualifiers now. If there are more
1434 than 6 the game will continue in the next aux */
1436 #define PARSE_TQ(tq) \
1437 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, sh);
1439 again
: PARSE_TQ(tq0
);
1454 /* Make up a complex type from a basic one. Type is passed by
1455 reference in TPP and side-effected as necessary. The type
1456 qualifier TQ says how to handle the aux symbols at AX for
1457 the symbol SX we are currently analyzing.
1458 Returns the number of aux symbols we parsed. */
1461 upgrade_type(tpp
, tq
, ax
, sh
)
1471 t
= lookup_pointer_type (*tpp
);
1472 } else if (tq
== tqProc
) {
1473 t
= lookup_function_type (*tpp
);
1474 } else if (tq
== tqArray
) {
1480 t
= make_type(TYPE_CODE_ARRAY
, 0, 0, 0);
1481 TYPE_TARGET_TYPE(t
) = *tpp
;
1483 /* Pointer to domain type (type of index) */
1484 id
= ax
->rndx
.index
;
1485 if ((rf
= ax
->rndx
.rfd
) == 0xfff)
1486 rf
= (++ax
)->isym
, off
++;
1488 fh
= get_rfd(cur_fd
, rf
);
1489 f
= new_field(t
, 0);
1490 bzero(&ss
, sizeof ss
);
1491 /* XXX */ f
->type
= parse_type(fh
->iauxBase
+ id
* sizeof(AUXU
),
1495 * This seems to be a pointer to the end of the Block defining
1496 * the type. Why it is here is magic for me, and I have no
1497 * good use for it anyways.
1501 id
= (++ax
)->rndx
.index
;
1502 if ((rf
= ax
->rndx
.rfd
) == 0xfff)
1503 rf
= (++ax
)->isym
, off
++;
1505 f
->bitpos
= (++ax
)->dnLow
; /* ?? */
1506 f
->bitsize
= (++ax
)->dnHigh
; /* ?? */
1507 rf
= (++ax
)->width
- 1; /* bit alignment */
1508 id
= TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) << 3; /* bitsize */
1511 /* Most likely an undefined type */
1513 TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) = id
>> 3;
1515 TYPE_LENGTH(t
) = (f
->bitsize
< 0) ? 0 :
1516 (f
->bitsize
- f
->bitpos
+ 1) * (id
>> 3);
1520 printf_filtered("Internal: unknown type qualifier %x\n", tq
);
1529 /* Parse a procedure descriptor record PR. Note that the procedure
1530 is parsed _after_ the local symbols, now we just make up the
1531 extra information we need into a special symbol that we insert
1532 in the procedure's main block. Note also that images that
1533 have been partially stripped (ld -x) have been deprived
1534 of local symbols, and we have to cope with them here.
1535 The procedure's code ends at BOUND */
1538 parse_procedure(pr
, bound
)
1541 struct symbol
*s
, *i
;
1542 SYMR
*sh
= (SYMR
*)pr
->isym
;
1544 struct mips_extra_func_info
*e
;
1548 /* Reuse the MIPS record */
1549 e
= (struct mips_extra_func_info
*) pr
;
1550 e
->numargs
= lookup_numargs(pr
->adr
);
1552 /* Make up our special symbol */
1553 i
= new_symbol(".gdbinfo.");
1554 SYMBOL_VALUE(i
) = (int)e
;
1555 SYMBOL_NAMESPACE(i
) = LABEL_NAMESPACE
;
1556 SYMBOL_CLASS(i
) = LOC_CONST
;
1557 SYMBOL_TYPE(i
) = builtin_type_void
;
1559 /* Make up a name for static procedures. Sigh. */
1560 if (sh
== (SYMR
*)-1) {
1561 sprintf(name
,".static_procedure@%x",pr
->adr
);
1562 sh_name
= savestring(name
, strlen(name
));
1566 sh_name
= (char*)sh
->iss
;
1567 s
= mylookup_symbol(sh_name
, top_stack
->cur_block
,
1568 VAR_NAMESPACE
, LOC_BLOCK
);
1571 b
= SYMBOL_BLOCK_VALUE(s
);
1573 s
= new_symbol(sh_name
);
1574 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1575 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1576 /* Donno its type, hope int is ok */
1577 SYMBOL_TYPE(s
) = lookup_function_type (builtin_type_int
);
1578 add_symbol(s
, top_stack
->cur_block
);
1579 /* Wont have symbols for this one */
1581 SYMBOL_BLOCK_VALUE(s
) = b
;
1582 BLOCK_FUNCTION(b
) = s
;
1583 BLOCK_START(b
) = pr
->adr
;
1584 BLOCK_END(b
) = bound
;
1585 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1586 add_block(b
, top_stack
->cur_st
);
1592 /* Parse the external symbol ES. Just call parse_symbol() after
1593 making sure we know where the aux are for it. For procedures,
1594 parsing of the PDRs has already provided all the needed
1595 information, we only parse them if SKIP_PROCEDURES is false,
1596 and only if this causes no symbol duplication */
1599 parse_external(es
, skip_procedures
)
1604 if (es
->ifd
!= ifdNil
) {
1606 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
) + cur_fd
;
1607 ax
= (AUXU
*)cur_fdr
->iauxBase
;
1609 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
);
1612 top_stack
->cur_st
= cur_stab
;
1613 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),0);
1615 /* Reading .o files */
1616 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
) {
1618 switch (es
->asym
.st
) {
1620 case stProc
: what
= "Procedure"; n_undef_procs
++; break;
1621 case stGlobal
: what
= "Variable"; n_undef_vars
++; break;
1622 case stLabel
: what
= "Label"; n_undef_labels
++; break;
1623 default : what
= "Symbol"; break;
1627 printf_filtered("Warning: %s %s is undefined (in %s)\n", what
,
1628 es
->asym
.iss
, fdr_name(cur_fdr
->rss
));
1632 switch (es
->asym
.st
) {
1634 /* If we have full symbols we do not need more */
1635 if (skip_procedures
)
1637 if (mylookup_symbol (es
->asym
.iss
, top_stack
->cur_block
,
1638 VAR_NAMESPACE
, LOC_BLOCK
))
1644 * Note that the case of a symbol with indexNil
1645 * must be handled anyways by parse_symbol().
1647 parse_symbol(&es
->asym
, ax
);
1654 /* Parse the line number info for file descriptor FH into
1655 GDB's linetable LT. MIPS' encoding requires a little bit
1656 of magic to get things out. Note also that MIPS' line
1657 numbers can go back and forth, apparently we can live
1658 with that and do not need to reorder our linetables */
1663 struct linetable
*lt
;
1665 char *base
= (char*)fh
->cbLineOffset
;
1667 int delta
, count
, lineno
= 0;
1673 /* Scan by procedure descriptors */
1674 i
= 0; j
= 0, k
= 0;
1675 for (pr
= (PDR
*)IPDFIRST(cur_hdr
,fh
); j
< fh
->cpd
; j
++, pr
++) {
1678 /* No code for this one */
1679 if (pr
->iline
== ilineNil
||
1680 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1683 * Aurgh! To know where to stop expanding we
1686 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1687 if (pr
[l
].iline
!= -1)
1689 if (l
== (fh
->cpd
- j
))
1694 * When procedures are moved around the linenumbers
1695 * are attributed to the next procedure up
1697 if (pr
->iline
>= halt
) continue;
1699 base
= (char*)pr
->cbLineOffset
;
1700 l
= pr
->adr
>> 2; /* in words */
1701 halt
+= (pr
->adr
>> 2) - pr
->iline
;
1702 for (lineno
= pr
->lnLow
; l
< halt
;) {
1703 count
= *base
& 0x0f;
1704 delta
= *base
++ >> 4;
1706 delta
= (base
[0] << 8) | (base
[1] & 0xff);
1709 lineno
+= delta
;/* first delta is 0 */
1710 k
= add_line(lt
, lineno
, l
, k
);
1717 /* Parse the symbols of the file described by FH, whose index is F_IDX.
1718 BOUND is the highest core address of this file's procedures */
1721 parse_one_file(fh
, f_idx
, bound
)
1728 /* Parse local symbols first */
1730 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
1731 sh
= (SYMR
*) (fh
->isymBase
) + s_idx
;
1733 parse_symbol(sh
, fh
->iauxBase
);
1736 /* Procedures next, note we need to look-ahead to
1737 find out where the procedure's code ends */
1739 for (s_idx
= 0; s_idx
< fh
->cpd
-1; s_idx
++) {
1740 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + s_idx
;
1741 parse_procedure(pr
, pr
[1].adr
); /* next proc up */
1744 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + s_idx
;
1745 parse_procedure(pr
, bound
); /* next file up */
1748 /* Linenumbers. At the end, check if we can save memory */
1749 parse_lines(fh
, LINETABLE(cur_stab
));
1750 if (LINETABLE(cur_stab
)->nitems
< fh
->cline
)
1751 shrink_linetable(cur_stab
);
1755 /* Master parsing procedure. Parses the symtab described by the
1756 symbolic header HDR. If INCREMENTAL is true we are called
1757 by add-file and must preserve the old symtabs */
1759 parse_partial_symbols(hdr
, incremental
)
1762 int f_idx
, s_idx
, h_max
;
1763 CORE_ADDR dummy
, *prevhigh
;
1764 /* Running pointers */
1772 * Only parse the External symbols, and the Relative FDR.
1773 * Fixup enough of the loader symtab to be able to use it.
1774 * Allocate space only for the file`s portions we need to
1780 max_glevel
= MIN_GLEVEL
;
1782 /* Allocate the map FDR -> PST.
1783 Minor hack: -O3 images might claim some global data belongs
1784 to FDR -1. We`ll go along with that */
1785 fdr_to_pst
= (struct pst_map
*)xzalloc((hdr
->ifdMax
+1) * sizeof *fdr_to_pst
);
1788 struct partial_symtab
* pst
= new_psymtab("");
1789 fdr_to_pst
[-1].pst
= pst
;
1793 /* Now scan the FDRs, mostly for dependencies */
1794 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++)
1795 (void) parse_fdr(f_idx
, 1);
1797 /* Take a good guess at how many symbols we might ever need */
1798 h_max
= hdr
->iextMax
;
1800 /* Parse externals: two passes because they can be ordered
1803 /* Pass 1: Presize and partition the list */
1804 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1805 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1806 fdr_to_pst
[esh
->ifd
].n_globals
++;
1809 if (global_psymbols
.list
) {
1810 global_psymbols
.list
= (struct partial_symbol
*)
1811 xrealloc( global_psymbols
.list
, (h_max
+
1812 global_psymbols
.size
) * sizeof(struct partial_symbol
));
1813 global_psymbols
.next
= global_psymbols
.list
+ global_psymbols
.size
;
1814 global_psymbols
.size
+= h_max
;
1816 global_psymbols
.list
= (struct partial_symbol
*)
1817 xmalloc( h_max
* sizeof(struct partial_symbol
));
1818 global_psymbols
.size
= h_max
;
1819 global_psymbols
.next
= global_psymbols
.list
;
1822 s_idx
= global_psymbols
.next
- global_psymbols
.list
;
1823 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++) {
1824 fdr_to_pst
[f_idx
].pst
->globals_offset
= s_idx
;
1825 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
1828 /* Pass 2: fill in symbols */
1829 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1830 register struct partial_symbol
*p
;
1831 enum misc_function_type misc_type
= mf_text
;
1832 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1834 if (esh
->asym
.sc
== scUndefined
|| esh
->asym
.sc
== scNil
)
1836 p
= new_psymbol(&global_psymbols
, esh
->asym
.iss
, esh
->ifd
);
1837 SYMBOL_VALUE(p
) = esh
->asym
.value
;
1838 SYMBOL_NAMESPACE(p
) = VAR_NAMESPACE
;
1840 switch (esh
->asym
.st
) {
1842 SYMBOL_CLASS(p
) = LOC_BLOCK
;
1845 SYMBOL_CLASS(p
) = LOC_STATIC
;
1846 misc_type
= mf_data
;
1849 SYMBOL_CLASS(p
) = LOC_LABEL
;
1852 misc_type
= mf_unknown
;
1853 complain (&unknown_ext_complaint
, SYMBOL_NAME(p
));
1855 prim_record_misc_function (SYMBOL_NAME(p
),
1861 /* The array (of lists) of globals must be sorted.
1862 Take care, since we are at it, of pst->texthigh.
1864 NOTE: The way we handle textlow/high is incorrect, but good
1865 enough for a first approximation. The case we fail is on a
1866 file "foo.c" that looks like
1868 #include "bar.c" -- this contains proc2()
1870 where proc3() is attributed to bar.c. But since this is a
1871 dependent file it will cause loading of foo.c as well, so
1872 everything will be fine at the end. */
1875 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
1876 struct partial_symtab
*pst
= fdr_to_pst
[f_idx
].pst
;
1877 if (pst
->n_global_syms
> 1)
1878 qsort (global_psymbols
.list
+ pst
->globals_offset
,
1879 pst
->n_global_syms
, sizeof (struct partial_symbol
),
1882 *prevhigh
= pst
->textlow
;
1883 prevhigh
= &pst
->texthigh
;
1887 /* Mark the last code address, and remember it for later */
1888 *prevhigh
= END_OF_TEXT_SEGMENT(filhdr
);
1889 hdr
->cbDnOffset
= END_OF_TEXT_SEGMENT(filhdr
);
1892 free(&fdr_to_pst
[-1]);
1897 /* Do the initial analisys of the F_IDX-th file descriptor.
1898 Allocates a partial symtab for it, and builds the list
1899 of dependent files by recursion. LEV says at which level
1900 of recursion we are called (to pretty up debug traces) */
1902 static struct partial_symtab
*
1903 parse_fdr(f_idx
, lev
)
1907 register struct partial_symtab
*pst
;
1910 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + f_idx
;
1912 /* Use this to indicate into which symtab this file was parsed */
1914 return (struct partial_symtab
*) fh
->ioptBase
;
1916 /* Debuggability level */
1917 if (compare_glevel(max_glevel
, fh
->glevel
) < 0)
1918 max_glevel
= fh
->glevel
;
1920 /* Make a new partial_symtab */
1921 pst
= new_psymtab(fh
->rss
);
1926 pst
->textlow
= fh
->adr
;
1927 pst
->texthigh
= fh
->cpd
; /* To be fixed later */
1929 /* Reverse mapping PST -> FDR */
1930 pst
->ldsymoff
= f_idx
;
1932 fdr_to_pst
[f_idx
].pst
= pst
;
1933 fh
->ioptBase
= (int)pst
;
1935 /* Analyze its dependencies */
1940 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
1941 /* ...then presumably a .h file: drop reverse depends .h->.c */
1942 for (; s_id0
< fh
->crfd
; s_id0
++) {
1943 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
1945 s_id0
++; /* Skip self-dependency */
1950 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
1951 pst
->dependencies
= (struct partial_symtab
**)
1952 obstack_alloc (psymbol_obstack
,
1953 pst
->number_of_dependencies
* sizeof(char*));
1954 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
1955 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
1957 pst
->dependencies
[s_idx
-s_id0
] = parse_fdr(*rh
, lev
+1);
1965 /* Ancillary function to psymtab_to_symtab(). Does all the work
1966 for turning the partial symtab PST into a symtab, recurring
1967 first on all dependent psymtabs */
1969 static void psymtab_to_symtab_1(pst
)
1970 struct partial_symtab
*pst
;
1980 pending_list
= (struct pending
**) cur_hdr
->cbOptOffset
;
1981 if (pending_list
== 0) {
1982 pending_list
= (struct pending
**)
1983 xzalloc(cur_hdr
->ifdMax
* sizeof(struct pending
*));
1984 cur_hdr
->cbOptOffset
= (int)pending_list
;
1987 /* How many symbols will we need */
1988 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
1989 if (pst
->ldsymoff
== -1) {
1991 st
= new_symtab( "unknown", f_max
, 0);
1993 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + pst
->ldsymoff
;
1994 f_max
+= fh
->csym
+ fh
->cpd
;
1995 st
= new_symtab(pst
->filename
, 2 * f_max
, 2 * fh
->cline
);
1999 * Read in all partial symbtabs on which this one is dependent.
2000 * NOTE that we do have circular dependencies, sigh.
2002 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2003 if (!pst
->dependencies
[i
]->readin
) {
2005 * DO NOT inform about additional files that need to
2006 * be read in, it would only annoy the user.
2008 psymtab_to_symtab_1(pst
->dependencies
[i
]);
2011 /* Now read the symbols for this symtab */
2013 cur_fd
= pst
->ldsymoff
;
2017 /* Get a new lexical context */
2020 top_stack
->cur_st
= cur_stab
;
2021 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab
), 0);
2022 BLOCK_START(top_stack
->cur_block
) = fh
? fh
->adr
: 0;
2023 BLOCK_END(top_stack
->cur_block
) = 0;
2024 top_stack
->blocktype
= stFile
;
2025 top_stack
->maxsyms
= f_max
;
2026 top_stack
->cur_type
= 0;
2027 top_stack
->procadr
= 0;
2028 top_stack
->numargs
= 0;
2030 /* Parse locals and procedures */
2032 parse_one_file(fh
, cur_fd
, (cur_fd
== (cur_hdr
->ifdMax
- 1)) ?
2033 cur_hdr
->cbDnOffset
: fh
[1].adr
);
2035 /* .. and our share of externals.
2036 XXX use the global list to speed up things here. how ? */
2037 top_stack
->blocktype
= stFile
;
2038 top_stack
->maxsyms
= cur_hdr
->isymMax
+ cur_hdr
->ipdMax
+ cur_hdr
->iextMax
;
2039 for (i
= 0; i
< cur_hdr
->iextMax
; i
++) {
2040 register EXTR
*esh
= (EXTR
*) (cur_hdr
->cbExtOffset
) + i
;
2041 if (esh
->ifd
== cur_fd
)
2042 parse_external(esh
, 1);
2045 /* If there are undefined, tell the user */
2046 if (n_undef_symbols
) {
2047 printf_filtered("File %s contains %d unresolved references:",
2048 st
->filename
, n_undef_symbols
);
2049 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2050 n_undef_vars
, n_undef_procs
, n_undef_labels
);
2051 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
2057 * Sort the symbol table now, we are done adding symbols to it.
2059 sort_symtab_syms(st
);
2065 /* Ancillary parsing procedures. */
2067 /* Lookup the type at relative index RN. Return it in TPP
2068 if found and in any event come up with its name PNAME.
2069 Return value says how many aux symbols we ate */
2072 cross_ref(rn
, tpp
, pname
)
2079 /* Escape index means 'the next one' */
2080 if (rn
->rfd
== 0xfff)
2081 rf
= *(unsigned *) (rn
+ 1);
2087 *pname
= "<undefined>";
2090 * Find the relative file descriptor and the symbol in it
2092 FDR
*fh
= get_rfd(cur_fd
, rf
);
2097 * If we have processed this symbol then we left a forwarding
2098 * pointer to the corresponding GDB symbol. If not, we`ll put
2099 * it in a list of pending symbols, to be processed later when
2100 * the file f will be. In any event, we collect the name for
2101 * the type here. Which is why we made a first pass at
2104 sh
= (SYMR
*) (fh
->isymBase
) + rn
->index
;
2106 /* Careful, we might be looking at .o files */
2107 *pname
= (UNSAFE_DATA_ADDR(sh
->iss
)) ? "<undefined>" :
2110 /* Have we parsed it ? */
2111 if ((!UNSAFE_DATA_ADDR(sh
->value
)) && (sh
->st
== stParsed
)) {
2112 t
= (struct type
*) sh
->value
;
2117 /* Avoid duplicates */
2118 p
= is_pending_symbol(fh
, sh
);
2123 add_pending(fh
, sh
, *tpp
);
2126 return (rn
->rfd
== 0xfff);
2130 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2131 keeping the symtab sorted */
2133 static struct symbol
*
2134 mylookup_symbol (name
, block
, namespace, class)
2136 register struct block
*block
;
2137 enum namespace namespace;
2138 enum address_class
class;
2140 register int bot
, top
, inc
;
2141 register struct symbol
*sym
;
2144 top
= BLOCK_NSYMS(block
);
2147 sym
= BLOCK_SYM(block
, bot
);
2148 if (SYMBOL_NAME(sym
)[0] == inc
2149 && SYMBOL_NAMESPACE(sym
) == namespace
2150 && SYMBOL_CLASS(sym
) == class
2151 && !strcmp(SYMBOL_NAME(sym
), name
))
2155 if (block
= BLOCK_SUPERBLOCK (block
))
2156 return mylookup_symbol (name
, block
, namespace, class);
2161 /* Add a new symbol S to a block B */
2168 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
2169 if (b
== top_stack
->cur_block
&&
2170 BLOCK_NSYMS(b
) > top_stack
->maxsyms
)
2171 printf_filtered("Internal: block at @%x overfilled (by %d)\n",
2172 b
, BLOCK_NSYMS(b
) - top_stack
->maxsyms
);
2175 /* Add a new block B to a symtab S */
2182 struct blockvector
*bv
= BLOCKVECTOR(s
);
2184 bv
= (struct blockvector
*)xrealloc(bv
, sizeof(struct blockvector
) +
2185 BLOCKVECTOR_NBLOCKS(bv
) * sizeof(bv
->block
));
2186 if (bv
!= BLOCKVECTOR(s
))
2187 BLOCKVECTOR(s
) = bv
;
2189 BLOCKVECTOR_BLOCK(bv
, BLOCKVECTOR_NBLOCKS(bv
)++) = b
;
2192 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2193 MIPS' linenumber encoding might need more than one byte
2194 to describe it, LAST is used to detect these continuation lines */
2197 add_line(lt
, lineno
, adr
, last
)
2198 struct linetable
*lt
;
2202 last
= -2; /* make sure we record first line */
2204 if (last
== lineno
) /* skip continuation lines */
2207 lt
->item
[lt
->nitems
].line
= lineno
;
2208 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
2214 /* Comparison functions, used when sorting things */
2216 /* Symtabs must be ordered viz the code segments they cover */
2219 compare_symtabs( s1
, s2
)
2220 struct symtab
**s1
, **s2
;
2222 /* "most specific" first */
2224 register struct block
*b1
, *b2
;
2225 b1
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1
),0);
2226 b2
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2
),0);
2227 if (BLOCK_END(b1
) == BLOCK_END(b2
))
2228 return BLOCK_START(b1
) - BLOCK_START(b2
);
2229 return BLOCK_END(b1
) - BLOCK_END(b2
);
2233 /* Partial Symtabs, same */
2236 compare_psymtabs( s1
, s2
)
2237 struct partial_symtab
**s1
, **s2
;
2239 /* Perf twist: put the ones with no code at the end */
2241 register int a
= (*s1
)->textlow
;
2242 register int b
= (*s2
)->textlow
;
2251 /* Partial symbols are compared lexicog by their print names */
2254 compare_psymbols (s1
, s2
)
2255 register struct partial_symbol
*s1
, *s2
;
2258 *st1
= SYMBOL_NAME(s1
),
2259 *st2
= SYMBOL_NAME(s2
);
2261 return (st1
[0] - st2
[0] ? st1
[0] - st2
[0] :
2262 strcmp(st1
+ 1, st2
+ 1));
2265 /* Blocks with a smaller low bound should come first */
2267 static int compare_blocks(b1
,b2
)
2268 struct block
**b1
, **b2
;
2270 register int addr_diff
;
2272 addr_diff
= (BLOCK_START((*b1
))) - (BLOCK_START((*b2
)));
2274 return (BLOCK_END((*b1
))) - (BLOCK_END((*b2
)));
2279 /* Sorting and reordering procedures */
2281 /* Sort the blocks of a symtab S.
2282 Reorder the blocks in the blockvector by code-address,
2283 as required by some MI search routines */
2289 struct blockvector
*bv
= BLOCKVECTOR(s
);
2291 if (BLOCKVECTOR_NBLOCKS(bv
) <= 2) {
2293 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,0)) == 0)
2294 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,0)) = 0;
2298 * This is very unfortunate: normally all functions are compiled in
2299 * the order they are found, but if the file is compiled -O3 things
2300 * are very different. It would be nice to find a reliable test
2301 * to detect -O3 images in advance.
2303 if (BLOCKVECTOR_NBLOCKS(bv
) > 3)
2304 qsort(&BLOCKVECTOR_BLOCK(bv
,2),
2305 BLOCKVECTOR_NBLOCKS(bv
) - 2,
2306 sizeof(struct block
*),
2310 register CORE_ADDR high
= 0;
2311 register int i
, j
= BLOCKVECTOR_NBLOCKS(bv
);
2313 for (i
= 2; i
< j
; i
++)
2314 if (high
< BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
)))
2315 high
= BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
));
2316 BLOCK_END(BLOCKVECTOR_BLOCK(bv
,0)) = high
;
2319 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,0)) = BLOCK_START(BLOCKVECTOR_BLOCK(bv
,2));
2321 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,1)) = BLOCK_START(BLOCKVECTOR_BLOCK(bv
,0));
2322 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,1)) = BLOCK_END (BLOCKVECTOR_BLOCK(bv
,0));
2325 /* Sort the symtab list, as required by some search procedures.
2326 We want files ordered to make them look right to users, and for
2327 searching (see block_for_pc). */
2333 struct symtab
*stab
;
2334 struct symtab
**all_symtabs
= (struct symtab
**)
2335 obstack_alloc (psymbol_obstack
,
2336 all_symtabs_count
* sizeof (struct symtab
*));
2338 /* Create an array of pointers to all the symtabs. */
2339 for (i
= 0, stab
= symtab_list
;
2340 i
< all_symtabs_count
;
2341 i
++, stab
= stab
->next
) {
2342 all_symtabs
[i
] = stab
;
2343 /* FIXME: Only do this for new symtabs ??? */
2344 sort_blocks(all_symtabs
[i
]);
2347 qsort(all_symtabs
, all_symtabs_count
,
2348 sizeof(struct symtab
*), compare_symtabs
);
2350 /* Re-construct the symtab list, but now it is sorted. */
2351 for (i
= 0; i
< all_symtabs_count
-1; i
++)
2352 all_symtabs
[i
]->next
= all_symtabs
[i
+1];
2353 all_symtabs
[i
]->next
= 0;
2354 symtab_list
= all_symtabs
[0];
2355 obstack_free (psymbol_obstack
, all_symtabs
);
2358 /* Sort the partial symtab list, as required by some search procedures */
2360 static reorder_psymtabs()
2363 struct partial_symtab
*pstab
;
2366 * PC lookups stop at the first psymtab such that
2367 * textlow <= PC < texthigh
2369 /* Create an array of pointers to all the partial_symtabs. */
2370 struct partial_symtab
**all_psymtabs
= (struct partial_symtab
**)
2371 obstack_alloc (psymbol_obstack
,
2372 all_psymtabs_count
*sizeof(struct partial_symtab
*));
2373 for (i
= 0, pstab
= partial_symtab_list
;
2374 i
< all_psymtabs_count
;
2375 i
++, pstab
= pstab
->next
)
2376 all_psymtabs
[i
] = pstab
;
2378 qsort(all_psymtabs
, all_psymtabs_count
,
2379 sizeof(struct partial_symtab
*), compare_psymtabs
);
2381 /* Re-construct the partial_symtab_list, but now it is sorted. */
2383 for (i
= 0; i
< all_psymtabs_count
-1; i
++)
2384 all_psymtabs
[i
]->next
= all_psymtabs
[i
+1];
2385 all_psymtabs
[i
]->next
= 0;
2386 partial_symtab_list
= all_psymtabs
[0];
2388 obstack_free (psymbol_obstack
, all_psymtabs
);
2393 /* Constructor/restructor/destructor procedures */
2395 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2396 MAXSYMS and linenumbers MAXLINES we'll put in it */
2400 new_symtab(name
, maxsyms
, maxlines
)
2403 struct symtab
*s
= (struct symtab
*) xzalloc(sizeof(struct symtab
));
2406 LINETABLE(s
) = new_linetable(maxlines
);
2410 /* All symtabs must have at least two blocks */
2411 BLOCKVECTOR(s
) = new_bvect(2);
2412 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), 0) = new_block(maxsyms
);
2413 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), 1) = new_block(maxsyms
);
2414 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
),1)) =
2415 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), 0);
2417 s
->free_code
= free_linetable
;
2419 /* Link the new symtab into the list of such. */
2420 s
->next
= symtab_list
;
2423 all_symtabs_count
++;
2428 /* Cleanup before loading a fresh image */
2430 static destroy_all_symtabs()
2437 all_symtabs_count
= 0;
2438 current_source_symtab
= 0;
2442 /* Allocate a new partial_symtab NAME */
2444 static struct partial_symtab
*
2448 struct partial_symtab
*pst
;
2450 pst
= (struct partial_symtab
*)
2451 obstack_alloc (psymbol_obstack
, sizeof (*pst
));
2452 bzero (pst
, sizeof (*pst
));
2454 if (name
== (char*)-1) /* FIXME -- why not null here? */
2455 pst
->filename
= "<no name>";
2457 pst
->filename
= name
;
2459 pst
->next
= partial_symtab_list
;
2460 partial_symtab_list
= pst
;
2461 all_psymtabs_count
++;
2463 /* Keep a backpointer to the file`s symbols */
2464 pst
->ldsymlen
= (int)cur_hdr
;
2466 /* The way to turn this into a symtab is to call... */
2467 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
2473 /* Allocate a new NAME psymbol from LIST, extending it if necessary.
2474 The psymbol belongs to the psymtab at index PST_IDX */
2476 static struct partial_symbol
*
2477 new_psymbol(list
, name
, pst_idx
)
2478 struct psymbol_allocation_list
*list
;
2481 struct partial_symbol
*p
;
2482 struct partial_symtab
*pst
= fdr_to_pst
[pst_idx
].pst
;
2484 /* Lists are pre-sized, we won`t overflow */
2486 p
= list
->list
+ pst
->globals_offset
+ pst
->n_global_syms
++;
2487 SYMBOL_NAME(p
) = name
;
2492 /* Allocate a linetable array of the given SIZE */
2495 struct linetable
*new_linetable(size
)
2497 struct linetable
*l
;
2499 size
= size
* sizeof(l
->item
) + sizeof(struct linetable
);
2500 l
= (struct linetable
*)xmalloc(size
);
2505 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2506 I am not so sure about the 3.4 ones */
2508 static shrink_linetable(s
)
2511 struct linetable
*l
= new_linetable(LINETABLE(s
)->nitems
);
2513 bcopy(LINETABLE(s
), l
,
2514 LINETABLE(s
)->nitems
* sizeof(l
->item
) + sizeof(struct linetable
));
2515 free (LINETABLE(s
));
2519 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2522 struct blockvector
*new_bvect(nblocks
)
2524 struct blockvector
*bv
;
2527 size
= sizeof(struct blockvector
) + nblocks
* sizeof(struct block
*);
2528 bv
= (struct blockvector
*) xzalloc(size
);
2530 BLOCKVECTOR_NBLOCKS(bv
) = nblocks
;
2535 /* Allocate and zero a new block of MAXSYMS symbols */
2538 struct block
*new_block(maxsyms
)
2540 int size
= sizeof(struct block
) + (maxsyms
-1) * sizeof(struct symbol
*);
2541 struct block
*b
= (struct block
*)xzalloc(size
);
2546 /* Ooops, too big. Shrink block B in symtab S to its minimal size */
2548 static struct block
*
2554 struct blockvector
*bv
= BLOCKVECTOR(s
);
2557 /* Just get a new one, copy, and fix references to the old one */
2559 new = (struct block
*)xmalloc(sizeof(struct block
) +
2560 (BLOCK_NSYMS(b
)-1) * sizeof(struct symbol
*));
2562 bcopy(b
, new, sizeof(*new) + (BLOCK_NSYMS(b
) - 1) * sizeof(struct symbol
*));
2564 /* Should chase pointers to old one. Fortunately, that`s just
2565 the block`s function and inferior blocks */
2566 if (BLOCK_FUNCTION(b
) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(b
)) == b
)
2567 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(b
)) = new;
2568 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2569 if (BLOCKVECTOR_BLOCK(bv
,i
) == b
)
2570 BLOCKVECTOR_BLOCK(bv
,i
) = new;
2571 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) == b
)
2572 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) = new;
2577 /* Create a new symbol with printname NAME */
2584 struct symbol
*s
= (struct symbol
*)
2585 obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
2587 bzero (s
, sizeof (*s
));
2588 SYMBOL_NAME(s
) = name
;
2592 /* Create a new type with printname NAME */
2599 struct type
*t
= (struct type
*)
2600 obstack_alloc (symbol_obstack
, sizeof (struct type
));
2602 bzero (t
, sizeof (*t
));
2603 TYPE_NAME(t
) = name
;
2607 /* Create and initialize a new type with printname NAME.
2608 CODE and LENGTH are the initial info we put in,
2609 UNS says whether the type is unsigned or not. */
2613 make_type(code
, length
, uns
, name
)
2614 enum type_code code
;
2618 register struct type
*type
;
2620 type
= (struct type
*) xzalloc(sizeof(struct type
));
2621 TYPE_CODE(type
) = code
;
2622 TYPE_LENGTH(type
) = length
;
2623 TYPE_FLAGS(type
) = uns
? TYPE_FLAG_UNSIGNED
: 0;
2624 TYPE_NAME(type
) = name
;
2629 /* Allocate a new field named NAME to the type TYPE */
2632 struct field
*new_field(type
,name
)
2638 /* Fields are kept in an array */
2639 if (TYPE_NFIELDS(type
))
2640 TYPE_FIELDS(type
) = (struct field
*)xrealloc(TYPE_FIELDS(type
),
2641 (TYPE_NFIELDS(type
)+1) * sizeof(struct field
));
2643 TYPE_FIELDS(type
) = (struct field
*)xzalloc(2*sizeof(struct field
));
2644 f
= &(TYPE_FIELD(type
,TYPE_NFIELDS(type
)++));
2645 bzero(f
, sizeof(struct field
));
2651 /* Make an enum constant for a member F of an enumerated type T */
2654 make_enum_constant(f
,t
)
2660 * This is awful, but that`s the way it is supposed to be
2661 * (BTW, no need to free the real 'type', it's a builtin)
2663 f
->type
= (struct type
*) f
->bitpos
;
2665 s
= new_symbol(f
->name
);
2666 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2667 SYMBOL_CLASS(s
) = LOC_CONST
;
2669 SYMBOL_VALUE(s
) = f
->bitpos
;
2670 add_symbol(s
, top_stack
->cur_block
);
2675 /* Things used for calling functions in the inferior.
2676 These functions are exported to our companion
2677 mips-dep.c file and are here because they play
2678 with the symbol-table explicitly. */
2681 /* Need to make a new symbol on the fly for the dummy
2682 frame we put on the stack. Which goes in the.. */
2684 static struct symtab
*dummy_symtab
;
2686 /* Make up a dummy symbol for the code we put at END_PC,
2687 of size SIZE, invoking a function with NARGS arguments
2688 and using a frame of FRAMESIZE bytes */
2690 mips_create_dummy_symbol(end_pc
, size
, nargs
, framesize
)
2694 struct mips_extra_func_info
*gdbinfo
;
2696 /* Allocate symtab if not done already */
2697 if (dummy_symtab
== 0)
2698 dummy_symtab
= new_symtab(".dummy_symtab.", 100, 0);
2700 /* Make a new block. Only needs one symbol */
2702 BLOCK_START(bl
) = end_pc
- size
;
2703 BLOCK_END(bl
) = end_pc
;
2705 BLOCK_SUPERBLOCK(bl
) = BLOCKVECTOR_BLOCK(BLOCKVECTOR(dummy_symtab
),0);
2706 add_block(bl
, dummy_symtab
);
2707 sort_blocks(dummy_symtab
);
2709 BLOCK_FUNCTION(bl
) = new_symbol("??");
2710 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(bl
)) = bl
;
2711 g
= new_symbol(".gdbinfo.");
2712 BLOCK_SYM(bl
,BLOCK_NSYMS(bl
)++) = g
;
2714 SYMBOL_NAMESPACE(g
) = LABEL_NAMESPACE
;
2715 SYMBOL_CLASS(g
) = LOC_CONST
;
2716 SYMBOL_TYPE(g
) = builtin_type_void
;
2717 gdbinfo
= (struct mips_extra_func_info
*)
2718 xzalloc(sizeof(struct mips_extra_func_info
));
2720 SYMBOL_VALUE(g
) = (long) gdbinfo
;
2722 gdbinfo
->numargs
= nargs
;
2723 gdbinfo
->framesize
= framesize
;
2724 gdbinfo
->framereg
= 29;
2725 gdbinfo
->pcreg
= 31;
2726 gdbinfo
->regmask
= -2;
2727 gdbinfo
->regoffset
= -4;
2728 gdbinfo
->fregmask
= 0; /* XXX */
2729 gdbinfo
->fregoffset
= 0; /* XXX */
2732 /* We just returned from the dummy code at END_PC, drop its symbol */
2734 mips_destroy_dummy_symbol(end_pc
)
2737 struct blockvector
*bv
= BLOCKVECTOR(dummy_symtab
);
2740 bl
= block_for_pc(end_pc
);
2741 free(BLOCK_FUNCTION(bl
));
2742 free(SYMBOL_VALUE(BLOCK_SYM(bl
,0)));
2743 free(BLOCK_SYM(bl
,0));
2745 for (i
= 2; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2746 if (BLOCKVECTOR_BLOCK(bv
,i
) == bl
)
2748 for (; i
< BLOCKVECTOR_NBLOCKS(bv
) - 1; i
++)
2749 BLOCKVECTOR_BLOCK(bv
,i
) = BLOCKVECTOR_BLOCK(bv
,i
+1);
2750 BLOCKVECTOR_NBLOCKS(bv
)--;
2751 sort_blocks(dummy_symtab
);
2756 /* Sigtramp: make sure we have all the necessary information
2757 about the signal trampoline code. Since the official code
2758 from MIPS does not do so, we make up that information ourselves.
2759 If they fix the library (unlikely) this code will neutralize itself. */
2766 struct block
*b
, *b0
;
2768 sigtramp_address
= -1;
2770 /* We know it is sold as sigvec */
2771 s
= lookup_symbol("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
2773 /* Most programs do not play with signals */
2777 b0
= SYMBOL_BLOCK_VALUE(s
);
2779 /* A label of sigvec, to be more precise */
2780 s
= lookup_symbol("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
2782 /* But maybe this program uses its own version of sigvec */
2786 sigtramp_address
= SYMBOL_VALUE(s
);
2787 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
2789 /* Did we or MIPSco fix the library ? */
2790 if (SYMBOL_CLASS(s
) == LOC_BLOCK
)
2793 /* But what symtab does it live in ? */
2794 st
= find_pc_symtab(SYMBOL_VALUE(s
));
2797 * Ok, there goes the fix: turn it into a procedure, with all the
2798 * needed info. Note we make it a nested procedure of sigvec,
2799 * which is the way the (assembly) code is actually written.
2801 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2802 SYMBOL_CLASS(s
) = LOC_BLOCK
;
2803 SYMBOL_TYPE(s
) = make_type(TYPE_CODE_FUNC
, 4, 0, 0);
2804 TYPE_TARGET_TYPE(SYMBOL_TYPE(s
)) = builtin_type_void
;
2806 /* Need a block to allocate .gdbinfo. in */
2808 SYMBOL_BLOCK_VALUE(s
) = b
;
2809 BLOCK_START(b
) = sigtramp_address
;
2810 BLOCK_END(b
) = sigtramp_end
;
2811 BLOCK_FUNCTION(b
) = s
;
2812 BLOCK_SUPERBLOCK(b
) = BLOCK_SUPERBLOCK(b0
);
2816 /* Make a .gdbinfo. for it */
2818 struct mips_extra_func_info
*e
=
2819 (struct mips_extra_func_info
*)
2820 xzalloc(sizeof(struct mips_extra_func_info
));
2822 e
->numargs
= 0; /* the kernel thinks otherwise */
2823 /* align_longword(sigcontext + SIGFRAME) */
2824 e
->framesize
= 0x150;
2825 e
->framereg
= SP_REGNUM
;
2828 e
->regoffset
= -(41 * sizeof(int));
2830 e
->fregoffset
= -(37 * sizeof(int));
2833 s
= new_symbol(".gdbinfo.");
2834 SYMBOL_VALUE(s
) = (int) e
;
2835 SYMBOL_NAMESPACE(s
) = LABEL_NAMESPACE
;
2836 SYMBOL_CLASS(s
) = LOC_CONST
;
2837 SYMBOL_TYPE(s
) = builtin_type_void
;
2840 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
2844 /* Initialization */
2846 static struct sym_fns ecoff_sym_fns
= {"ecoff", 5,
2847 mipscoff_new_init
, mipscoff_symfile_init
,
2848 mipscoff_symfile_read
, mipscoff_symfile_discard
};
2850 _initialize_mipsread ()
2852 add_symtab_fns (&ecoff_sym_fns
);
2854 bzero (&global_psymbols
, sizeof (global_psymbols
));
2855 bzero (&static_psymbols
, sizeof (static_psymbols
));
2857 add_com("add-file", class_files
, add_file_command
,
2858 "Add a new symbol table (in mips format) from file FILE.");
2860 /* Missing basic types */
2861 builtin_type_string
= make_type(TYPE_CODE_PASCAL_ARRAY
,
2863 builtin_type_complex
= make_type(TYPE_CODE_FLT
,
2864 2 * sizeof(float), 0, "complex");
2865 builtin_type_double_complex
= make_type(TYPE_CODE_FLT
,
2866 2 * sizeof(double), 0, "double_complex");
2867 builtin_type_fixed_dec
= make_type(TYPE_CODE_INT
, sizeof(int),
2868 0, "fixed_decimal");
2869 builtin_type_float_dec
= make_type(TYPE_CODE_FLT
, sizeof(double),
2870 0, "floating_decimal");
2872 /* Templates types */
2873 builtin_type_ptr
= lookup_pointer_type (builtin_type_void
);
2874 builtin_type_struct
= make_type(TYPE_CODE_STRUCT
, 0, 0, 0);
2875 builtin_type_union
= make_type(TYPE_CODE_UNION
, 0, 0, 0);
2876 builtin_type_enum
= make_type(TYPE_CODE_ENUM
, 0, 0, 0);
2877 builtin_type_range
= make_type(TYPE_CODE_RANGE
, 0, 0, 0);
2878 builtin_type_set
= make_type(TYPE_CODE_SET
, 0, 0, 0);