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 if (entry_point
< BLOCK_END(b
)
1228 && entry_point
>= BLOCK_START(b
)) {
1229 startup_file_start
= BLOCK_START(b
);
1230 startup_file_end
= BLOCK_END(b
);
1232 } else if (sh
->sc
== scText
&& top_stack
->blocktype
== stBlock
) {
1233 /* End of (code) block. The value of the symbol
1234 is the displacement from the procedure`s start
1235 address of the end of this block. */
1236 BLOCK_END(top_stack
->cur_block
) = sh
->value
+ top_stack
->procadr
;
1237 (void) shrink_block(top_stack
->cur_block
, top_stack
->cur_st
);
1239 pop_parse_stack(); /* restore previous lexical context */
1242 case stMember
: /* member of struct/union/enum.. */
1243 f
= new_field(top_stack
->cur_type
, sh
->iss
);
1244 f
->bitpos
= sh
->value
;
1245 f
->type
= parse_type(ax
+ sh
->index
, sh
, &f
->bitsize
);
1248 case stTypedef
: /* type definition */
1249 s
= new_symbol(sh
->iss
);
1250 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1251 SYMBOL_CLASS(s
) = LOC_TYPEDEF
;
1252 SYMBOL_BLOCK_VALUE(s
) = top_stack
->cur_block
;
1253 add_symbol(s
, top_stack
->cur_block
);
1254 SYMBOL_TYPE(s
) = parse_type(ax
+ sh
->index
, sh
, 0);
1255 sh
->value
= (long) SYMBOL_TYPE(s
);
1258 case stFile
: /* file name */
1260 top_stack
->blocktype
= sh
->st
;
1263 /* I`ve never seen these for C */
1265 break; /* register relocation */
1267 break; /* forwarding address */
1269 break; /* constant */
1271 error("Unknown symbol type %x.", sh
->st
);
1276 /* Parse the type information provided in the AX entries for
1277 the symbol SH. Return the bitfield size in BS, in case. */
1279 static struct type
*parse_type(ax
, sh
, bs
)
1284 /* Null entries in this map are treated specially */
1285 static struct type
**map_bt
[] =
1287 &builtin_type_void
, /* btNil */
1289 &builtin_type_char
, /* btChar */
1290 &builtin_type_unsigned_char
, /* btUChar */
1291 &builtin_type_short
, /* btShort */
1292 &builtin_type_unsigned_short
, /* btUShort */
1293 &builtin_type_int
, /* btInt */
1294 &builtin_type_unsigned_int
, /* btUInt */
1295 &builtin_type_long
, /* btLong */
1296 &builtin_type_unsigned_long
, /* btULong */
1297 &builtin_type_float
, /* btFloat */
1298 &builtin_type_double
, /* btDouble */
1305 &builtin_type_complex
, /* btComplex */
1306 &builtin_type_double_complex
, /* btDComplex */
1308 &builtin_type_fixed_dec
, /* btFixedDec */
1309 &builtin_type_float_dec
, /* btFloatDec */
1310 &builtin_type_string
, /* btString */
1313 &builtin_type_void
, /* btVoid */
1317 struct type
*tp
= 0, *tp1
;
1320 /* Procedures start off by one */
1321 if (sh
->st
== stProc
|| sh
->st
== stStaticProc
)
1324 /* Undefined ? Should not happen */
1325 if (ax
->rndx
.rfd
== 0xfff) {
1326 return builtin_type_void
;
1329 /* Use aux as a type information record, map its basic type */
1331 if (t
->bt
> 26 || t
->bt
== btPicture
) {
1332 printf_filtered("Internal: cannot map MIPS basic type x%x\n", t
->bt
);
1333 return builtin_type_int
;
1336 tp
= *map_bt
[t
->bt
];
1338 /* Cannot use builtin types, use templates */
1339 tp
= make_type(TYPE_CODE_VOID
, 0, 0, 0);
1342 *tp
= *builtin_type_ptr
;
1345 *tp
= *builtin_type_struct
;
1349 *tp
= *builtin_type_union
;
1353 *tp
= *builtin_type_enum
;
1357 *tp
= *builtin_type_range
;
1360 *tp
= *builtin_type_set
;
1366 /* Move on to next aux */
1369 /* This is the way it would work if the compiler worked */
1370 register TIR
*t1
= t
;
1371 while (t1
->continued
)
1375 /* For bitfields all we need is the width */
1381 /* All these types really point to some (common) MIPS type
1382 definition, and only the type-qualifiers fully identify
1383 them. We`ll make the same effort at sharing */
1384 if (t
->bt
== btIndirect
||
1385 t
->bt
== btStruct
||
1388 t
->bt
== btTypedef
||
1391 char name
[256], *pn
;
1393 /* Try to cross reference this type */
1395 ax
+= cross_ref(ax
, &tp1
, &pn
);
1396 /* SOMEONE OUGHT TO FIX DBXREAD TO DROP "STRUCT" */
1397 sprintf(name
, fmt
, pn
);
1399 /* reading .o file ? */
1400 if (UNSAFE_DATA_ADDR(tp1
))
1402 if (TYPE_CODE(tp1
) == TYPE_CODE_UNDEF
) {
1404 * Type was incompletely defined, now we know.
1406 TYPE_CODE(tp1
) = TYPE_CODE(tp
);
1407 TYPE_NAME(tp1
) = obsavestring(name
, strlen(name
));
1408 if (TYPE_CODE(tp1
) == TYPE_CODE_ENUM
) {
1411 for (i
= 0; i
< TYPE_NFIELDS(tp1
); i
++)
1412 make_enum_constant(&TYPE_FIELD(tp1
,i
), tp1
);
1416 /* found as cross ref, rid of our template */
1417 if ((TYPE_FLAGS(tp
) & TYPE_FLAG_PERM
) == 0)
1420 /* stupid idea of prepending "struct" to type names */
1421 if (t
->bt
== btStruct
&& !index(TYPE_NAME(tp
), ' ')) {
1422 sprintf(name
, fmt
, TYPE_NAME(tp
));
1423 TYPE_NAME(tp
) = obsavestring(name
, strlen(name
));
1426 TYPE_NAME(tp
) = savestring(name
, strlen(name
));
1429 /* Deal with range types */
1430 if (t
->bt
== btRange
) {
1433 f
= new_field(tp
, "Low");
1434 f
->bitpos
= ax
->dnLow
;
1436 f
= new_field(tp
, "High");
1437 f
->bitpos
= ax
->dnHigh
;
1441 /* Parse all the type qualifiers now. If there are more
1442 than 6 the game will continue in the next aux */
1444 #define PARSE_TQ(tq) \
1445 if (t->tq != tqNil) ax += upgrade_type(&tp, t->tq, ax, sh);
1447 again
: PARSE_TQ(tq0
);
1462 /* Make up a complex type from a basic one. Type is passed by
1463 reference in TPP and side-effected as necessary. The type
1464 qualifier TQ says how to handle the aux symbols at AX for
1465 the symbol SX we are currently analyzing.
1466 Returns the number of aux symbols we parsed. */
1469 upgrade_type(tpp
, tq
, ax
, sh
)
1479 t
= lookup_pointer_type (*tpp
);
1480 } else if (tq
== tqProc
) {
1481 t
= lookup_function_type (*tpp
);
1482 } else if (tq
== tqArray
) {
1488 t
= make_type(TYPE_CODE_ARRAY
, 0, 0, 0);
1489 TYPE_TARGET_TYPE(t
) = *tpp
;
1491 /* Pointer to domain type (type of index) */
1492 id
= ax
->rndx
.index
;
1493 if ((rf
= ax
->rndx
.rfd
) == 0xfff)
1494 rf
= (++ax
)->isym
, off
++;
1496 fh
= get_rfd(cur_fd
, rf
);
1497 f
= new_field(t
, 0);
1498 bzero(&ss
, sizeof ss
);
1499 /* XXX */ f
->type
= parse_type(fh
->iauxBase
+ id
* sizeof(AUXU
),
1503 * This seems to be a pointer to the end of the Block defining
1504 * the type. Why it is here is magic for me, and I have no
1505 * good use for it anyways.
1509 id
= (++ax
)->rndx
.index
;
1510 if ((rf
= ax
->rndx
.rfd
) == 0xfff)
1511 rf
= (++ax
)->isym
, off
++;
1513 f
->bitpos
= (++ax
)->dnLow
; /* ?? */
1514 f
->bitsize
= (++ax
)->dnHigh
; /* ?? */
1515 rf
= (++ax
)->width
- 1; /* bit alignment */
1516 id
= TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) << 3; /* bitsize */
1519 /* Most likely an undefined type */
1521 TYPE_LENGTH(TYPE_TARGET_TYPE(t
)) = id
>> 3;
1523 TYPE_LENGTH(t
) = (f
->bitsize
< 0) ? 0 :
1524 (f
->bitsize
- f
->bitpos
+ 1) * (id
>> 3);
1528 printf_filtered("Internal: unknown type qualifier %x\n", tq
);
1537 /* Parse a procedure descriptor record PR. Note that the procedure
1538 is parsed _after_ the local symbols, now we just make up the
1539 extra information we need into a special symbol that we insert
1540 in the procedure's main block. Note also that images that
1541 have been partially stripped (ld -x) have been deprived
1542 of local symbols, and we have to cope with them here.
1543 The procedure's code ends at BOUND */
1546 parse_procedure(pr
, bound
)
1549 struct symbol
*s
, *i
;
1550 SYMR
*sh
= (SYMR
*)pr
->isym
;
1552 struct mips_extra_func_info
*e
;
1556 /* Reuse the MIPS record */
1557 e
= (struct mips_extra_func_info
*) pr
;
1558 e
->numargs
= lookup_numargs(pr
->adr
);
1560 /* Make up our special symbol */
1561 i
= new_symbol(".gdbinfo.");
1562 SYMBOL_VALUE(i
) = (int)e
;
1563 SYMBOL_NAMESPACE(i
) = LABEL_NAMESPACE
;
1564 SYMBOL_CLASS(i
) = LOC_CONST
;
1565 SYMBOL_TYPE(i
) = builtin_type_void
;
1567 /* Make up a name for static procedures. Sigh. */
1568 if (sh
== (SYMR
*)-1) {
1569 sprintf(name
,".static_procedure@%x",pr
->adr
);
1570 sh_name
= savestring(name
, strlen(name
));
1574 sh_name
= (char*)sh
->iss
;
1575 s
= mylookup_symbol(sh_name
, top_stack
->cur_block
,
1576 VAR_NAMESPACE
, LOC_BLOCK
);
1579 b
= SYMBOL_BLOCK_VALUE(s
);
1581 s
= new_symbol(sh_name
);
1582 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
1583 SYMBOL_CLASS(s
) = LOC_BLOCK
;
1584 /* Donno its type, hope int is ok */
1585 SYMBOL_TYPE(s
) = lookup_function_type (builtin_type_int
);
1586 add_symbol(s
, top_stack
->cur_block
);
1587 /* Wont have symbols for this one */
1589 SYMBOL_BLOCK_VALUE(s
) = b
;
1590 BLOCK_FUNCTION(b
) = s
;
1591 BLOCK_START(b
) = pr
->adr
;
1592 BLOCK_END(b
) = bound
;
1593 BLOCK_SUPERBLOCK(b
) = top_stack
->cur_block
;
1594 add_block(b
, top_stack
->cur_st
);
1600 /* Parse the external symbol ES. Just call parse_symbol() after
1601 making sure we know where the aux are for it. For procedures,
1602 parsing of the PDRs has already provided all the needed
1603 information, we only parse them if SKIP_PROCEDURES is false,
1604 and only if this causes no symbol duplication */
1607 parse_external(es
, skip_procedures
)
1612 if (es
->ifd
!= ifdNil
) {
1614 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
) + cur_fd
;
1615 ax
= (AUXU
*)cur_fdr
->iauxBase
;
1617 cur_fdr
= (FDR
*)(cur_hdr
->cbFdOffset
);
1620 top_stack
->cur_st
= cur_stab
;
1621 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(top_stack
->cur_st
),
1624 /* Reading .o files */
1625 if (es
->asym
.sc
== scUndefined
|| es
->asym
.sc
== scNil
) {
1627 switch (es
->asym
.st
) {
1629 case stProc
: what
= "Procedure"; n_undef_procs
++; break;
1630 case stGlobal
: what
= "Variable"; n_undef_vars
++; break;
1631 case stLabel
: what
= "Label"; n_undef_labels
++; break;
1632 default : what
= "Symbol"; break;
1636 printf_filtered("Warning: %s %s is undefined (in %s)\n", what
,
1637 es
->asym
.iss
, fdr_name(cur_fdr
->rss
));
1641 switch (es
->asym
.st
) {
1643 /* If we have full symbols we do not need more */
1644 if (skip_procedures
)
1646 if (mylookup_symbol (es
->asym
.iss
, top_stack
->cur_block
,
1647 VAR_NAMESPACE
, LOC_BLOCK
))
1653 * Note that the case of a symbol with indexNil
1654 * must be handled anyways by parse_symbol().
1656 parse_symbol(&es
->asym
, ax
);
1663 /* Parse the line number info for file descriptor FH into
1664 GDB's linetable LT. MIPS' encoding requires a little bit
1665 of magic to get things out. Note also that MIPS' line
1666 numbers can go back and forth, apparently we can live
1667 with that and do not need to reorder our linetables */
1672 struct linetable
*lt
;
1674 char *base
= (char*)fh
->cbLineOffset
;
1676 int delta
, count
, lineno
= 0;
1682 /* Scan by procedure descriptors */
1683 i
= 0; j
= 0, k
= 0;
1684 for (pr
= (PDR
*)IPDFIRST(cur_hdr
,fh
); j
< fh
->cpd
; j
++, pr
++) {
1687 /* No code for this one */
1688 if (pr
->iline
== ilineNil
||
1689 pr
->lnLow
== -1 || pr
->lnHigh
== -1)
1692 * Aurgh! To know where to stop expanding we
1695 for (l
= 1; l
< (fh
->cpd
- j
); l
++)
1696 if (pr
[l
].iline
!= -1)
1698 if (l
== (fh
->cpd
- j
))
1703 * When procedures are moved around the linenumbers
1704 * are attributed to the next procedure up
1706 if (pr
->iline
>= halt
) continue;
1708 base
= (char*)pr
->cbLineOffset
;
1709 l
= pr
->adr
>> 2; /* in words */
1710 halt
+= (pr
->adr
>> 2) - pr
->iline
;
1711 for (lineno
= pr
->lnLow
; l
< halt
;) {
1712 count
= *base
& 0x0f;
1713 delta
= *base
++ >> 4;
1715 delta
= (base
[0] << 8) | (base
[1] & 0xff);
1718 lineno
+= delta
;/* first delta is 0 */
1719 k
= add_line(lt
, lineno
, l
, k
);
1726 /* Parse the symbols of the file described by FH, whose index is F_IDX.
1727 BOUND is the highest core address of this file's procedures */
1730 parse_one_file(fh
, f_idx
, bound
)
1737 /* Parse local symbols first */
1739 for (s_idx
= 0; s_idx
< fh
->csym
; s_idx
++) {
1740 sh
= (SYMR
*) (fh
->isymBase
) + s_idx
;
1742 parse_symbol(sh
, fh
->iauxBase
);
1745 /* Procedures next, note we need to look-ahead to
1746 find out where the procedure's code ends */
1748 for (s_idx
= 0; s_idx
< fh
->cpd
-1; s_idx
++) {
1749 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + s_idx
;
1750 parse_procedure(pr
, pr
[1].adr
); /* next proc up */
1753 pr
= (PDR
*) (IPDFIRST(cur_hdr
, fh
)) + s_idx
;
1754 parse_procedure(pr
, bound
); /* next file up */
1757 /* Linenumbers. At the end, check if we can save memory */
1758 parse_lines(fh
, LINETABLE(cur_stab
));
1759 if (LINETABLE(cur_stab
)->nitems
< fh
->cline
)
1760 shrink_linetable(cur_stab
);
1764 /* Master parsing procedure. Parses the symtab described by the
1765 symbolic header HDR. If INCREMENTAL is true we are called
1766 by add-file and must preserve the old symtabs */
1768 parse_partial_symbols(hdr
, incremental
)
1771 int f_idx
, s_idx
, h_max
;
1772 CORE_ADDR dummy
, *prevhigh
;
1773 /* Running pointers */
1781 * Only parse the External symbols, and the Relative FDR.
1782 * Fixup enough of the loader symtab to be able to use it.
1783 * Allocate space only for the file`s portions we need to
1789 max_glevel
= MIN_GLEVEL
;
1791 /* Allocate the map FDR -> PST.
1792 Minor hack: -O3 images might claim some global data belongs
1793 to FDR -1. We`ll go along with that */
1794 fdr_to_pst
= (struct pst_map
*)xzalloc((hdr
->ifdMax
+1) * sizeof *fdr_to_pst
);
1797 struct partial_symtab
* pst
= new_psymtab("");
1798 fdr_to_pst
[-1].pst
= pst
;
1802 /* Now scan the FDRs, mostly for dependencies */
1803 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++)
1804 (void) parse_fdr(f_idx
, 1);
1806 /* Take a good guess at how many symbols we might ever need */
1807 h_max
= hdr
->iextMax
;
1809 /* Parse externals: two passes because they can be ordered
1812 /* Pass 1: Presize and partition the list */
1813 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1814 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1815 fdr_to_pst
[esh
->ifd
].n_globals
++;
1818 if (global_psymbols
.list
) {
1819 global_psymbols
.list
= (struct partial_symbol
*)
1820 xrealloc( global_psymbols
.list
, (h_max
+
1821 global_psymbols
.size
) * sizeof(struct partial_symbol
));
1822 global_psymbols
.next
= global_psymbols
.list
+ global_psymbols
.size
;
1823 global_psymbols
.size
+= h_max
;
1825 global_psymbols
.list
= (struct partial_symbol
*)
1826 xmalloc( h_max
* sizeof(struct partial_symbol
));
1827 global_psymbols
.size
= h_max
;
1828 global_psymbols
.next
= global_psymbols
.list
;
1831 s_idx
= global_psymbols
.next
- global_psymbols
.list
;
1832 for (f_idx
= -1; f_idx
< hdr
->ifdMax
; f_idx
++) {
1833 fdr_to_pst
[f_idx
].pst
->globals_offset
= s_idx
;
1834 s_idx
+= fdr_to_pst
[f_idx
].n_globals
;
1837 /* Pass 2: fill in symbols */
1838 for (s_idx
= 0; s_idx
< hdr
->iextMax
; s_idx
++) {
1839 register struct partial_symbol
*p
;
1840 enum misc_function_type misc_type
= mf_text
;
1841 esh
= (EXTR
*) (hdr
->cbExtOffset
) + s_idx
;
1843 if (esh
->asym
.sc
== scUndefined
|| esh
->asym
.sc
== scNil
)
1845 p
= new_psymbol(&global_psymbols
, esh
->asym
.iss
, esh
->ifd
);
1846 SYMBOL_VALUE(p
) = esh
->asym
.value
;
1847 SYMBOL_NAMESPACE(p
) = VAR_NAMESPACE
;
1849 switch (esh
->asym
.st
) {
1851 SYMBOL_CLASS(p
) = LOC_BLOCK
;
1854 SYMBOL_CLASS(p
) = LOC_STATIC
;
1855 misc_type
= mf_data
;
1858 SYMBOL_CLASS(p
) = LOC_LABEL
;
1861 misc_type
= mf_unknown
;
1862 complain (&unknown_ext_complaint
, SYMBOL_NAME(p
));
1864 prim_record_misc_function (SYMBOL_NAME(p
),
1870 /* The array (of lists) of globals must be sorted.
1871 Take care, since we are at it, of pst->texthigh.
1873 NOTE: The way we handle textlow/high is incorrect, but good
1874 enough for a first approximation. The case we fail is on a
1875 file "foo.c" that looks like
1877 #include "bar.c" -- this contains proc2()
1879 where proc3() is attributed to bar.c. But since this is a
1880 dependent file it will cause loading of foo.c as well, so
1881 everything will be fine at the end. */
1884 for (f_idx
= 0; f_idx
< hdr
->ifdMax
; f_idx
++) {
1885 struct partial_symtab
*pst
= fdr_to_pst
[f_idx
].pst
;
1886 if (pst
->n_global_syms
> 1)
1887 qsort (global_psymbols
.list
+ pst
->globals_offset
,
1888 pst
->n_global_syms
, sizeof (struct partial_symbol
),
1891 *prevhigh
= pst
->textlow
;
1892 prevhigh
= &pst
->texthigh
;
1896 /* Mark the last code address, and remember it for later */
1897 *prevhigh
= END_OF_TEXT_SEGMENT(filhdr
);
1898 hdr
->cbDnOffset
= END_OF_TEXT_SEGMENT(filhdr
);
1901 free(&fdr_to_pst
[-1]);
1906 /* Do the initial analisys of the F_IDX-th file descriptor.
1907 Allocates a partial symtab for it, and builds the list
1908 of dependent files by recursion. LEV says at which level
1909 of recursion we are called (to pretty up debug traces) */
1911 static struct partial_symtab
*
1912 parse_fdr(f_idx
, lev
)
1916 register struct partial_symtab
*pst
;
1919 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + f_idx
;
1921 /* Use this to indicate into which symtab this file was parsed */
1923 return (struct partial_symtab
*) fh
->ioptBase
;
1925 /* Debuggability level */
1926 if (compare_glevel(max_glevel
, fh
->glevel
) < 0)
1927 max_glevel
= fh
->glevel
;
1929 /* Make a new partial_symtab */
1930 pst
= new_psymtab(fh
->rss
);
1935 pst
->textlow
= fh
->adr
;
1936 pst
->texthigh
= fh
->cpd
; /* To be fixed later */
1938 /* Reverse mapping PST -> FDR */
1939 pst
->ldsymoff
= f_idx
;
1941 fdr_to_pst
[f_idx
].pst
= pst
;
1942 fh
->ioptBase
= (int)pst
;
1944 /* Analyze its dependencies */
1949 if (fh
->cpd
== 0) { /* If there are no functions defined here ... */
1950 /* ...then presumably a .h file: drop reverse depends .h->.c */
1951 for (; s_id0
< fh
->crfd
; s_id0
++) {
1952 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_id0
;
1954 s_id0
++; /* Skip self-dependency */
1959 pst
->number_of_dependencies
= fh
->crfd
- s_id0
;
1960 pst
->dependencies
= (struct partial_symtab
**)
1961 obstack_alloc (psymbol_obstack
,
1962 pst
->number_of_dependencies
* sizeof(char*));
1963 for (s_idx
= s_id0
; s_idx
< fh
->crfd
; s_idx
++) {
1964 RFDT
*rh
= (RFDT
*) (fh
->rfdBase
) + s_idx
;
1966 pst
->dependencies
[s_idx
-s_id0
] = parse_fdr(*rh
, lev
+1);
1974 /* Ancillary function to psymtab_to_symtab(). Does all the work
1975 for turning the partial symtab PST into a symtab, recurring
1976 first on all dependent psymtabs */
1978 static void psymtab_to_symtab_1(pst
)
1979 struct partial_symtab
*pst
;
1989 pending_list
= (struct pending
**) cur_hdr
->cbOptOffset
;
1990 if (pending_list
== 0) {
1991 pending_list
= (struct pending
**)
1992 xzalloc(cur_hdr
->ifdMax
* sizeof(struct pending
*));
1993 cur_hdr
->cbOptOffset
= (int)pending_list
;
1996 /* How many symbols will we need */
1997 f_max
= pst
->n_global_syms
+ pst
->n_static_syms
;
1998 if (pst
->ldsymoff
== -1) {
2000 st
= new_symtab( "unknown", f_max
, 0);
2002 fh
= (FDR
*) (cur_hdr
->cbFdOffset
) + pst
->ldsymoff
;
2003 f_max
+= fh
->csym
+ fh
->cpd
;
2004 st
= new_symtab(pst
->filename
, 2 * f_max
, 2 * fh
->cline
);
2008 * Read in all partial symbtabs on which this one is dependent.
2009 * NOTE that we do have circular dependencies, sigh.
2011 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2012 if (!pst
->dependencies
[i
]->readin
) {
2014 * DO NOT inform about additional files that need to
2015 * be read in, it would only annoy the user.
2017 psymtab_to_symtab_1(pst
->dependencies
[i
]);
2020 /* Now read the symbols for this symtab */
2022 cur_fd
= pst
->ldsymoff
;
2026 /* Get a new lexical context */
2029 top_stack
->cur_st
= cur_stab
;
2030 top_stack
->cur_block
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(cur_stab
),
2032 BLOCK_START(top_stack
->cur_block
) = fh
? fh
->adr
: 0;
2033 BLOCK_END(top_stack
->cur_block
) = 0;
2034 top_stack
->blocktype
= stFile
;
2035 top_stack
->maxsyms
= f_max
;
2036 top_stack
->cur_type
= 0;
2037 top_stack
->procadr
= 0;
2038 top_stack
->numargs
= 0;
2040 /* Parse locals and procedures */
2042 parse_one_file(fh
, cur_fd
, (cur_fd
== (cur_hdr
->ifdMax
- 1)) ?
2043 cur_hdr
->cbDnOffset
: fh
[1].adr
);
2045 /* .. and our share of externals.
2046 XXX use the global list to speed up things here. how ? */
2047 top_stack
->blocktype
= stFile
;
2048 top_stack
->maxsyms
= cur_hdr
->isymMax
+ cur_hdr
->ipdMax
+ cur_hdr
->iextMax
;
2049 for (i
= 0; i
< cur_hdr
->iextMax
; i
++) {
2050 register EXTR
*esh
= (EXTR
*) (cur_hdr
->cbExtOffset
) + i
;
2051 if (esh
->ifd
== cur_fd
)
2052 parse_external(esh
, 1);
2055 /* If there are undefined, tell the user */
2056 if (n_undef_symbols
) {
2057 printf_filtered("File %s contains %d unresolved references:",
2058 st
->filename
, n_undef_symbols
);
2059 printf_filtered("\n\t%4d variables\n\t%4d procedures\n\t%4d labels\n",
2060 n_undef_vars
, n_undef_procs
, n_undef_labels
);
2061 n_undef_symbols
= n_undef_labels
= n_undef_vars
= n_undef_procs
= 0;
2067 * Sort the symbol table now, we are done adding symbols to it.
2069 sort_symtab_syms(st
);
2075 /* Ancillary parsing procedures. */
2077 /* Lookup the type at relative index RN. Return it in TPP
2078 if found and in any event come up with its name PNAME.
2079 Return value says how many aux symbols we ate */
2082 cross_ref(rn
, tpp
, pname
)
2089 /* Escape index means 'the next one' */
2090 if (rn
->rfd
== 0xfff)
2091 rf
= *(unsigned *) (rn
+ 1);
2097 *pname
= "<undefined>";
2100 * Find the relative file descriptor and the symbol in it
2102 FDR
*fh
= get_rfd(cur_fd
, rf
);
2107 * If we have processed this symbol then we left a forwarding
2108 * pointer to the corresponding GDB symbol. If not, we`ll put
2109 * it in a list of pending symbols, to be processed later when
2110 * the file f will be. In any event, we collect the name for
2111 * the type here. Which is why we made a first pass at
2114 sh
= (SYMR
*) (fh
->isymBase
) + rn
->index
;
2116 /* Careful, we might be looking at .o files */
2117 *pname
= (UNSAFE_DATA_ADDR(sh
->iss
)) ? "<undefined>" :
2120 /* Have we parsed it ? */
2121 if ((!UNSAFE_DATA_ADDR(sh
->value
)) && (sh
->st
== stParsed
)) {
2122 t
= (struct type
*) sh
->value
;
2127 /* Avoid duplicates */
2128 p
= is_pending_symbol(fh
, sh
);
2133 add_pending(fh
, sh
, *tpp
);
2136 return (rn
->rfd
== 0xfff);
2140 /* Quick&dirty lookup procedure, to avoid the MI ones that require
2141 keeping the symtab sorted */
2143 static struct symbol
*
2144 mylookup_symbol (name
, block
, namespace, class)
2146 register struct block
*block
;
2147 enum namespace namespace;
2148 enum address_class
class;
2150 register int bot
, top
, inc
;
2151 register struct symbol
*sym
;
2154 top
= BLOCK_NSYMS(block
);
2157 sym
= BLOCK_SYM(block
, bot
);
2158 if (SYMBOL_NAME(sym
)[0] == inc
2159 && SYMBOL_NAMESPACE(sym
) == namespace
2160 && SYMBOL_CLASS(sym
) == class
2161 && !strcmp(SYMBOL_NAME(sym
), name
))
2165 if (block
= BLOCK_SUPERBLOCK (block
))
2166 return mylookup_symbol (name
, block
, namespace, class);
2171 /* Add a new symbol S to a block B */
2178 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
2179 if (b
== top_stack
->cur_block
&&
2180 BLOCK_NSYMS(b
) > top_stack
->maxsyms
)
2181 printf_filtered("Internal: block at @%x overfilled (by %d)\n",
2182 b
, BLOCK_NSYMS(b
) - top_stack
->maxsyms
);
2185 /* Add a new block B to a symtab S */
2192 struct blockvector
*bv
= BLOCKVECTOR(s
);
2194 bv
= (struct blockvector
*)xrealloc(bv
, sizeof(struct blockvector
) +
2195 BLOCKVECTOR_NBLOCKS(bv
) * sizeof(bv
->block
));
2196 if (bv
!= BLOCKVECTOR(s
))
2197 BLOCKVECTOR(s
) = bv
;
2199 BLOCKVECTOR_BLOCK(bv
, BLOCKVECTOR_NBLOCKS(bv
)++) = b
;
2202 /* Add a new linenumber entry (LINENO,ADR) to a linevector LT.
2203 MIPS' linenumber encoding might need more than one byte
2204 to describe it, LAST is used to detect these continuation lines */
2207 add_line(lt
, lineno
, adr
, last
)
2208 struct linetable
*lt
;
2212 last
= -2; /* make sure we record first line */
2214 if (last
== lineno
) /* skip continuation lines */
2217 lt
->item
[lt
->nitems
].line
= lineno
;
2218 lt
->item
[lt
->nitems
++].pc
= adr
<< 2;
2224 /* Comparison functions, used when sorting things */
2226 /* Symtabs must be ordered viz the code segments they cover */
2229 compare_symtabs( s1
, s2
)
2230 struct symtab
**s1
, **s2
;
2232 /* "most specific" first */
2234 register struct block
*b1
, *b2
;
2235 b1
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s1
),GLOBAL_BLOCK
);
2236 b2
= BLOCKVECTOR_BLOCK(BLOCKVECTOR(*s2
),GLOBAL_BLOCK
);
2237 if (BLOCK_END(b1
) == BLOCK_END(b2
))
2238 return BLOCK_START(b1
) - BLOCK_START(b2
);
2239 return BLOCK_END(b1
) - BLOCK_END(b2
);
2243 /* Partial Symtabs, same */
2246 compare_psymtabs( s1
, s2
)
2247 struct partial_symtab
**s1
, **s2
;
2249 /* Perf twist: put the ones with no code at the end */
2251 register int a
= (*s1
)->textlow
;
2252 register int b
= (*s2
)->textlow
;
2261 /* Partial symbols are compared lexicog by their print names */
2264 compare_psymbols (s1
, s2
)
2265 register struct partial_symbol
*s1
, *s2
;
2268 *st1
= SYMBOL_NAME(s1
),
2269 *st2
= SYMBOL_NAME(s2
);
2271 return (st1
[0] - st2
[0] ? st1
[0] - st2
[0] :
2272 strcmp(st1
+ 1, st2
+ 1));
2275 /* Blocks with a smaller low bound should come first */
2277 static int compare_blocks(b1
,b2
)
2278 struct block
**b1
, **b2
;
2280 register int addr_diff
;
2282 addr_diff
= (BLOCK_START((*b1
))) - (BLOCK_START((*b2
)));
2284 return (BLOCK_END((*b1
))) - (BLOCK_END((*b2
)));
2289 /* Sorting and reordering procedures */
2291 /* Sort the blocks of a symtab S.
2292 Reorder the blocks in the blockvector by code-address,
2293 as required by some MI search routines */
2299 struct blockvector
*bv
= BLOCKVECTOR(s
);
2301 if (BLOCKVECTOR_NBLOCKS(bv
) <= 2) {
2303 if (BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) == 0)
2304 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = 0;
2308 * This is very unfortunate: normally all functions are compiled in
2309 * the order they are found, but if the file is compiled -O3 things
2310 * are very different. It would be nice to find a reliable test
2311 * to detect -O3 images in advance.
2313 if (BLOCKVECTOR_NBLOCKS(bv
) > 3)
2314 qsort(&BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
),
2315 BLOCKVECTOR_NBLOCKS(bv
) - FIRST_LOCAL_BLOCK
,
2316 sizeof(struct block
*),
2320 register CORE_ADDR high
= 0;
2321 register int i
, j
= BLOCKVECTOR_NBLOCKS(bv
);
2323 for (i
= FIRST_LOCAL_BLOCK
; i
< j
; i
++)
2324 if (high
< BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
)))
2325 high
= BLOCK_END(BLOCKVECTOR_BLOCK(bv
,i
));
2326 BLOCK_END(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) = high
;
2329 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
)) =
2330 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,FIRST_LOCAL_BLOCK
));
2332 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2333 BLOCK_START(BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2334 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,STATIC_BLOCK
)) =
2335 BLOCK_END (BLOCKVECTOR_BLOCK(bv
,GLOBAL_BLOCK
));
2338 /* Sort the symtab list, as required by some search procedures.
2339 We want files ordered to make them look right to users, and for
2340 searching (see block_for_pc). */
2346 struct symtab
*stab
;
2347 struct symtab
**all_symtabs
= (struct symtab
**)
2348 obstack_alloc (psymbol_obstack
,
2349 all_symtabs_count
* sizeof (struct symtab
*));
2351 /* Create an array of pointers to all the symtabs. */
2352 for (i
= 0, stab
= symtab_list
;
2353 i
< all_symtabs_count
;
2354 i
++, stab
= stab
->next
) {
2355 all_symtabs
[i
] = stab
;
2356 /* FIXME: Only do this for new symtabs ??? */
2357 sort_blocks(all_symtabs
[i
]);
2360 qsort(all_symtabs
, all_symtabs_count
,
2361 sizeof(struct symtab
*), compare_symtabs
);
2363 /* Re-construct the symtab list, but now it is sorted. */
2364 for (i
= 0; i
< all_symtabs_count
-1; i
++)
2365 all_symtabs
[i
]->next
= all_symtabs
[i
+1];
2366 all_symtabs
[i
]->next
= 0;
2367 symtab_list
= all_symtabs
[0];
2368 obstack_free (psymbol_obstack
, all_symtabs
);
2371 /* Sort the partial symtab list, as required by some search procedures */
2373 static reorder_psymtabs()
2376 struct partial_symtab
*pstab
;
2379 * PC lookups stop at the first psymtab such that
2380 * textlow <= PC < texthigh
2382 /* Create an array of pointers to all the partial_symtabs. */
2383 struct partial_symtab
**all_psymtabs
= (struct partial_symtab
**)
2384 obstack_alloc (psymbol_obstack
,
2385 all_psymtabs_count
*sizeof(struct partial_symtab
*));
2386 for (i
= 0, pstab
= partial_symtab_list
;
2387 i
< all_psymtabs_count
;
2388 i
++, pstab
= pstab
->next
)
2389 all_psymtabs
[i
] = pstab
;
2391 qsort(all_psymtabs
, all_psymtabs_count
,
2392 sizeof(struct partial_symtab
*), compare_psymtabs
);
2394 /* Re-construct the partial_symtab_list, but now it is sorted. */
2396 for (i
= 0; i
< all_psymtabs_count
-1; i
++)
2397 all_psymtabs
[i
]->next
= all_psymtabs
[i
+1];
2398 all_psymtabs
[i
]->next
= 0;
2399 partial_symtab_list
= all_psymtabs
[0];
2401 obstack_free (psymbol_obstack
, all_psymtabs
);
2406 /* Constructor/restructor/destructor procedures */
2408 /* Allocate a new symtab for NAME. Needs an estimate of how many symbols
2409 MAXSYMS and linenumbers MAXLINES we'll put in it */
2413 new_symtab(name
, maxsyms
, maxlines
)
2416 struct symtab
*s
= (struct symtab
*) xzalloc(sizeof(struct symtab
));
2419 LINETABLE(s
) = new_linetable(maxlines
);
2423 /* All symtabs must have at least two blocks */
2424 BLOCKVECTOR(s
) = new_bvect(2);
2425 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
) = new_block(maxsyms
);
2426 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), STATIC_BLOCK
) = new_block(maxsyms
);
2427 BLOCK_SUPERBLOCK( BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
),STATIC_BLOCK
)) =
2428 BLOCKVECTOR_BLOCK(BLOCKVECTOR(s
), GLOBAL_BLOCK
);
2430 s
->free_code
= free_linetable
;
2432 /* Link the new symtab into the list of such. */
2433 s
->next
= symtab_list
;
2436 all_symtabs_count
++;
2441 /* Cleanup before loading a fresh image */
2443 static destroy_all_symtabs()
2450 all_symtabs_count
= 0;
2451 current_source_symtab
= 0;
2455 /* Allocate a new partial_symtab NAME */
2457 static struct partial_symtab
*
2461 struct partial_symtab
*pst
;
2463 pst
= (struct partial_symtab
*)
2464 obstack_alloc (psymbol_obstack
, sizeof (*pst
));
2465 bzero (pst
, sizeof (*pst
));
2467 if (name
== (char*)-1) /* FIXME -- why not null here? */
2468 pst
->filename
= "<no name>";
2470 pst
->filename
= name
;
2472 pst
->next
= partial_symtab_list
;
2473 partial_symtab_list
= pst
;
2474 all_psymtabs_count
++;
2476 /* Keep a backpointer to the file`s symbols */
2477 pst
->ldsymlen
= (int)cur_hdr
;
2479 /* The way to turn this into a symtab is to call... */
2480 pst
->read_symtab
= mipscoff_psymtab_to_symtab
;
2486 /* Allocate a new NAME psymbol from LIST, extending it if necessary.
2487 The psymbol belongs to the psymtab at index PST_IDX */
2489 static struct partial_symbol
*
2490 new_psymbol(list
, name
, pst_idx
)
2491 struct psymbol_allocation_list
*list
;
2494 struct partial_symbol
*p
;
2495 struct partial_symtab
*pst
= fdr_to_pst
[pst_idx
].pst
;
2497 /* Lists are pre-sized, we won`t overflow */
2499 p
= list
->list
+ pst
->globals_offset
+ pst
->n_global_syms
++;
2500 SYMBOL_NAME(p
) = name
;
2505 /* Allocate a linetable array of the given SIZE */
2508 struct linetable
*new_linetable(size
)
2510 struct linetable
*l
;
2512 size
= size
* sizeof(l
->item
) + sizeof(struct linetable
);
2513 l
= (struct linetable
*)xmalloc(size
);
2518 /* Oops, too big. Shrink it. This was important with the 2.4 linetables,
2519 I am not so sure about the 3.4 ones */
2521 static shrink_linetable(s
)
2524 struct linetable
*l
= new_linetable(LINETABLE(s
)->nitems
);
2526 bcopy(LINETABLE(s
), l
,
2527 LINETABLE(s
)->nitems
* sizeof(l
->item
) + sizeof(struct linetable
));
2528 free (LINETABLE(s
));
2532 /* Allocate and zero a new blockvector of NBLOCKS blocks. */
2535 struct blockvector
*new_bvect(nblocks
)
2537 struct blockvector
*bv
;
2540 size
= sizeof(struct blockvector
) + nblocks
* sizeof(struct block
*);
2541 bv
= (struct blockvector
*) xzalloc(size
);
2543 BLOCKVECTOR_NBLOCKS(bv
) = nblocks
;
2548 /* Allocate and zero a new block of MAXSYMS symbols */
2551 struct block
*new_block(maxsyms
)
2553 int size
= sizeof(struct block
) + (maxsyms
-1) * sizeof(struct symbol
*);
2554 struct block
*b
= (struct block
*)xzalloc(size
);
2559 /* Ooops, too big. Shrink block B in symtab S to its minimal size */
2561 static struct block
*
2567 struct blockvector
*bv
= BLOCKVECTOR(s
);
2570 /* Just get a new one, copy, and fix references to the old one */
2572 new = (struct block
*)xmalloc(sizeof(struct block
) +
2573 (BLOCK_NSYMS(b
)-1) * sizeof(struct symbol
*));
2575 bcopy(b
, new, sizeof(*new) + (BLOCK_NSYMS(b
) - 1) * sizeof(struct symbol
*));
2577 /* Should chase pointers to old one. Fortunately, that`s just
2578 the block`s function and inferior blocks */
2579 if (BLOCK_FUNCTION(b
) && SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(b
)) == b
)
2580 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(b
)) = new;
2581 for (i
= 0; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2582 if (BLOCKVECTOR_BLOCK(bv
,i
) == b
)
2583 BLOCKVECTOR_BLOCK(bv
,i
) = new;
2584 else if (BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) == b
)
2585 BLOCK_SUPERBLOCK(BLOCKVECTOR_BLOCK(bv
,i
)) = new;
2590 /* Create a new symbol with printname NAME */
2597 struct symbol
*s
= (struct symbol
*)
2598 obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
2600 bzero (s
, sizeof (*s
));
2601 SYMBOL_NAME(s
) = name
;
2605 /* Create a new type with printname NAME */
2612 struct type
*t
= (struct type
*)
2613 obstack_alloc (symbol_obstack
, sizeof (struct type
));
2615 bzero (t
, sizeof (*t
));
2616 TYPE_NAME(t
) = name
;
2620 /* Create and initialize a new type with printname NAME.
2621 CODE and LENGTH are the initial info we put in,
2622 UNS says whether the type is unsigned or not. */
2626 make_type(code
, length
, uns
, name
)
2627 enum type_code code
;
2631 register struct type
*type
;
2633 type
= (struct type
*) xzalloc(sizeof(struct type
));
2634 TYPE_CODE(type
) = code
;
2635 TYPE_LENGTH(type
) = length
;
2636 TYPE_FLAGS(type
) = uns
? TYPE_FLAG_UNSIGNED
: 0;
2637 TYPE_NAME(type
) = name
;
2642 /* Allocate a new field named NAME to the type TYPE */
2645 struct field
*new_field(type
,name
)
2651 /* Fields are kept in an array */
2652 if (TYPE_NFIELDS(type
))
2653 TYPE_FIELDS(type
) = (struct field
*)xrealloc(TYPE_FIELDS(type
),
2654 (TYPE_NFIELDS(type
)+1) * sizeof(struct field
));
2656 TYPE_FIELDS(type
) = (struct field
*)xzalloc(2*sizeof(struct field
));
2657 f
= &(TYPE_FIELD(type
,TYPE_NFIELDS(type
)++));
2658 bzero(f
, sizeof(struct field
));
2664 /* Make an enum constant for a member F of an enumerated type T */
2667 make_enum_constant(f
,t
)
2673 * This is awful, but that`s the way it is supposed to be
2674 * (BTW, no need to free the real 'type', it's a builtin)
2676 f
->type
= (struct type
*) f
->bitpos
;
2678 s
= new_symbol(f
->name
);
2679 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2680 SYMBOL_CLASS(s
) = LOC_CONST
;
2682 SYMBOL_VALUE(s
) = f
->bitpos
;
2683 add_symbol(s
, top_stack
->cur_block
);
2688 /* Things used for calling functions in the inferior.
2689 These functions are exported to our companion
2690 mips-dep.c file and are here because they play
2691 with the symbol-table explicitly. */
2694 /* Need to make a new symbol on the fly for the dummy
2695 frame we put on the stack. Which goes in the.. */
2697 static struct symtab
*dummy_symtab
;
2699 /* Make up a dummy symbol for the code we put at END_PC,
2700 of size SIZE, invoking a function with NARGS arguments
2701 and using a frame of FRAMESIZE bytes */
2703 mips_create_dummy_symbol(end_pc
, size
, nargs
, framesize
)
2707 struct mips_extra_func_info
*gdbinfo
;
2709 /* Allocate symtab if not done already */
2710 if (dummy_symtab
== 0)
2711 dummy_symtab
= new_symtab(".dummy_symtab.", 100, 0);
2713 /* Make a new block. Only needs one symbol */
2715 BLOCK_START(bl
) = end_pc
- size
;
2716 BLOCK_END(bl
) = end_pc
;
2718 BLOCK_SUPERBLOCK(bl
) =
2719 BLOCKVECTOR_BLOCK(BLOCKVECTOR(dummy_symtab
),GLOBAL_BLOCK
);
2720 add_block(bl
, dummy_symtab
);
2721 sort_blocks(dummy_symtab
);
2723 BLOCK_FUNCTION(bl
) = new_symbol("??");
2724 SYMBOL_BLOCK_VALUE(BLOCK_FUNCTION(bl
)) = bl
;
2725 g
= new_symbol(".gdbinfo.");
2726 BLOCK_SYM(bl
,BLOCK_NSYMS(bl
)++) = g
;
2728 SYMBOL_NAMESPACE(g
) = LABEL_NAMESPACE
;
2729 SYMBOL_CLASS(g
) = LOC_CONST
;
2730 SYMBOL_TYPE(g
) = builtin_type_void
;
2731 gdbinfo
= (struct mips_extra_func_info
*)
2732 xzalloc(sizeof(struct mips_extra_func_info
));
2734 SYMBOL_VALUE(g
) = (long) gdbinfo
;
2736 gdbinfo
->numargs
= nargs
;
2737 gdbinfo
->framesize
= framesize
;
2738 gdbinfo
->framereg
= 29;
2739 gdbinfo
->pcreg
= 31;
2740 gdbinfo
->regmask
= -2;
2741 gdbinfo
->regoffset
= -4;
2742 gdbinfo
->fregmask
= 0; /* XXX */
2743 gdbinfo
->fregoffset
= 0; /* XXX */
2746 /* We just returned from the dummy code at END_PC, drop its symbol */
2748 mips_destroy_dummy_symbol(end_pc
)
2751 struct blockvector
*bv
= BLOCKVECTOR(dummy_symtab
);
2754 bl
= block_for_pc(end_pc
);
2755 free(BLOCK_FUNCTION(bl
));
2756 free(SYMBOL_VALUE(BLOCK_SYM(bl
,0)));
2757 free(BLOCK_SYM(bl
,0));
2759 for (i
= FIRST_LOCAL_BLOCK
; i
< BLOCKVECTOR_NBLOCKS(bv
); i
++)
2760 if (BLOCKVECTOR_BLOCK(bv
,i
) == bl
)
2762 for (; i
< BLOCKVECTOR_NBLOCKS(bv
) - 1; i
++)
2763 BLOCKVECTOR_BLOCK(bv
,i
) = BLOCKVECTOR_BLOCK(bv
,i
+1);
2764 BLOCKVECTOR_NBLOCKS(bv
)--;
2765 sort_blocks(dummy_symtab
);
2770 /* Sigtramp: make sure we have all the necessary information
2771 about the signal trampoline code. Since the official code
2772 from MIPS does not do so, we make up that information ourselves.
2773 If they fix the library (unlikely) this code will neutralize itself. */
2780 struct block
*b
, *b0
;
2782 sigtramp_address
= -1;
2784 /* We know it is sold as sigvec */
2785 s
= lookup_symbol("sigvec", 0, VAR_NAMESPACE
, 0, NULL
);
2787 /* Most programs do not play with signals */
2791 b0
= SYMBOL_BLOCK_VALUE(s
);
2793 /* A label of sigvec, to be more precise */
2794 s
= lookup_symbol("sigtramp", b0
, VAR_NAMESPACE
, 0, NULL
);
2796 /* But maybe this program uses its own version of sigvec */
2800 sigtramp_address
= SYMBOL_VALUE(s
);
2801 sigtramp_end
= sigtramp_address
+ 0x88; /* black magic */
2803 /* Did we or MIPSco fix the library ? */
2804 if (SYMBOL_CLASS(s
) == LOC_BLOCK
)
2807 /* But what symtab does it live in ? */
2808 st
= find_pc_symtab(SYMBOL_VALUE(s
));
2811 * Ok, there goes the fix: turn it into a procedure, with all the
2812 * needed info. Note we make it a nested procedure of sigvec,
2813 * which is the way the (assembly) code is actually written.
2815 SYMBOL_NAMESPACE(s
) = VAR_NAMESPACE
;
2816 SYMBOL_CLASS(s
) = LOC_BLOCK
;
2817 SYMBOL_TYPE(s
) = make_type(TYPE_CODE_FUNC
, 4, 0, 0);
2818 TYPE_TARGET_TYPE(SYMBOL_TYPE(s
)) = builtin_type_void
;
2820 /* Need a block to allocate .gdbinfo. in */
2822 SYMBOL_BLOCK_VALUE(s
) = b
;
2823 BLOCK_START(b
) = sigtramp_address
;
2824 BLOCK_END(b
) = sigtramp_end
;
2825 BLOCK_FUNCTION(b
) = s
;
2826 BLOCK_SUPERBLOCK(b
) = BLOCK_SUPERBLOCK(b0
);
2830 /* Make a .gdbinfo. for it */
2832 struct mips_extra_func_info
*e
=
2833 (struct mips_extra_func_info
*)
2834 xzalloc(sizeof(struct mips_extra_func_info
));
2836 e
->numargs
= 0; /* the kernel thinks otherwise */
2837 /* align_longword(sigcontext + SIGFRAME) */
2838 e
->framesize
= 0x150;
2839 e
->framereg
= SP_REGNUM
;
2842 e
->regoffset
= -(41 * sizeof(int));
2844 e
->fregoffset
= -(37 * sizeof(int));
2847 s
= new_symbol(".gdbinfo.");
2848 SYMBOL_VALUE(s
) = (int) e
;
2849 SYMBOL_NAMESPACE(s
) = LABEL_NAMESPACE
;
2850 SYMBOL_CLASS(s
) = LOC_CONST
;
2851 SYMBOL_TYPE(s
) = builtin_type_void
;
2854 BLOCK_SYM(b
,BLOCK_NSYMS(b
)++) = s
;
2858 /* Initialization */
2860 static struct sym_fns ecoff_sym_fns
= {"ecoff", 5,
2861 mipscoff_new_init
, mipscoff_symfile_init
,
2862 mipscoff_symfile_read
, mipscoff_symfile_discard
};
2864 _initialize_mipsread ()
2866 add_symtab_fns (&ecoff_sym_fns
);
2868 bzero (&global_psymbols
, sizeof (global_psymbols
));
2869 bzero (&static_psymbols
, sizeof (static_psymbols
));
2871 add_com("add-file", class_files
, add_file_command
,
2872 "Add a new symbol table (in mips format) from file FILE.");
2874 /* Missing basic types */
2875 builtin_type_string
= make_type(TYPE_CODE_PASCAL_ARRAY
,
2877 builtin_type_complex
= make_type(TYPE_CODE_FLT
,
2878 2 * sizeof(float), 0, "complex");
2879 builtin_type_double_complex
= make_type(TYPE_CODE_FLT
,
2880 2 * sizeof(double), 0, "double_complex");
2881 builtin_type_fixed_dec
= make_type(TYPE_CODE_INT
, sizeof(int),
2882 0, "fixed_decimal");
2883 builtin_type_float_dec
= make_type(TYPE_CODE_FLT
, sizeof(double),
2884 0, "floating_decimal");
2886 /* Templates types */
2887 builtin_type_ptr
= lookup_pointer_type (builtin_type_void
);
2888 builtin_type_struct
= make_type(TYPE_CODE_STRUCT
, 0, 0, 0);
2889 builtin_type_union
= make_type(TYPE_CODE_UNION
, 0, 0, 0);
2890 builtin_type_enum
= make_type(TYPE_CODE_ENUM
, 0, 0, 0);
2891 builtin_type_range
= make_type(TYPE_CODE_RANGE
, 0, 0, 0);
2892 builtin_type_set
= make_type(TYPE_CODE_SET
, 0, 0, 0);