1 /* Read coff symbol tables and convert to internal format, for GDB.
3 Copyright 1987, 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program 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 2 of the License, or
10 (at your option) any later version.
12 This program 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 this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include "breakpoint.h"
33 #include "coff/internal.h" /* Internal format of COFF symbols in BFD */
34 #include "libcoff.h" /* FIXME secret internal data from BFD */
36 /* To be an sdb debug type, type must have at least a basic or primary
37 derived type. Using this rather than checking against T_NULL is
38 said to prevent core dumps if we try to operate on Michael Bloom
41 #define SDB_TYPE(type) (BTYPE(type) | (type & N_TMASK))
44 * Convert from an sdb register number to an internal gdb register number.
45 * This should be defined in tm.h, if REGISTER_NAMES is not set up
46 * to map one to one onto the sdb register numbers.
48 #ifndef SDB_REG_TO_REGNUM
49 # define SDB_REG_TO_REGNUM(value) (value)
52 /* Core address of start and end of text of current source file.
53 This comes from a ".text" symbol where x_nlinno > 0. */
55 static CORE_ADDR cur_src_start_addr;
56 static CORE_ADDR cur_src_end_addr;
58 /* Core address of the end of the first object file. */
59 static CORE_ADDR first_object_file_end;
61 /* The addresses of the symbol table stream and number of symbols
62 of the object file we are reading (as copied into core). */
64 static FILE *nlist_stream_global;
65 static int nlist_nsyms_global;
67 /* Vector of line number information. */
69 static struct linetable *line_vector;
71 /* Index of next entry to go in line_vector_index. */
73 static int line_vector_index;
75 /* Last line number recorded in the line vector. */
77 static int prev_line_number;
79 /* Number of elements allocated for line_vector currently. */
81 static int line_vector_length;
83 /* Pointers to scratch storage, used for reading raw symbols and auxents. */
85 static char *temp_sym;
86 static char *temp_aux;
88 /* Local variables that hold the shift and mask values for the
89 COFF file that we are currently reading. These come back to us
90 from BFD, and are referenced by their macro names, as well as
91 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
92 macros from ../internalcoff.h . */
94 static unsigned local_n_btmask;
95 static unsigned local_n_btshft;
96 static unsigned local_n_tmask;
97 static unsigned local_n_tshift;
99 #define N_BTMASK local_n_btmask
100 #define N_BTSHFT local_n_btshft
101 #define N_TMASK local_n_tmask
102 #define N_TSHIFT local_n_tshift
104 /* Local variables that hold the sizes in the file of various COFF structures.
105 (We only need to know this to read them from the file -- BFD will then
106 translate the data in them, into `internal_xxx' structs in the right
107 byte order, alignment, etc.) */
109 static unsigned local_linesz;
110 static unsigned local_symesz;
111 static unsigned local_auxesz;
114 /* Chain of typedefs of pointers to empty struct/union types.
115 They are chained thru the SYMBOL_VALUE_CHAIN. */
117 static struct symbol *opaque_type_chain[HASHSIZE];
119 /* Record the symbols defined for each context in a list.
120 We don't create a struct block for the context until we
121 know how long to make it. */
125 struct coff_pending *next;
126 struct symbol *symbol;
129 /* Here are the three lists that symbols are put on. */
131 struct coff_pending *coff_file_symbols; /* static at top level, and types */
133 struct coff_pending *coff_global_symbols; /* global functions and variables */
135 struct coff_pending *coff_local_symbols; /* everything local to lexical context */
137 /* List of unclosed lexical contexts
138 (that will become blocks, eventually). */
140 struct coff_context_stack
142 struct coff_context_stack *next;
143 struct coff_pending *locals;
144 struct pending_block *old_blocks;
146 CORE_ADDR start_addr;
150 struct coff_context_stack *coff_context_stack;
152 /* Nonzero if within a function (so symbols should be local,
153 if nothing says specifically). */
158 /* The type of the function we are currently reading in. This is
159 used by define_symbol to record the type of arguments to a function. */
161 struct type *in_function_type;
164 struct pending_block *pending_blocks;
166 /* Complaints about various problems in the file being read */
168 struct complaint ef_complaint =
169 {"Unmatched .ef symbol(s) ignored starting at symnum %d", 0, 0};
171 struct complaint bf_no_aux_complaint =
172 {"`.bf' symbol %d has no aux entry", 0, 0};
174 struct complaint ef_no_aux_complaint =
175 {"`.ef' symbol %d has no aux entry", 0, 0};
177 struct complaint lineno_complaint =
178 {"Line number pointer %d lower than start of line numbers", 0, 0};
180 struct complaint unexpected_type_complaint =
181 {"Unexpected type for symbol %s", 0, 0};
183 struct complaint bad_sclass_complaint =
184 {"Bad n_sclass for symbol %s", 0, 0};
186 /* Simplified internal version of coff symbol table information */
190 int c_symnum; /* symbol number of this entry */
191 int c_naux; /* 0 if syment only, 1 if syment + auxent, etc */
199 coff_read_struct_type PARAMS ((int, int, int));
202 decode_base_type PARAMS ((struct coff_symbol *, unsigned int,
203 union internal_auxent *));
206 decode_type PARAMS ((struct coff_symbol *, unsigned int,
207 union internal_auxent *));
210 decode_function_type PARAMS ((struct coff_symbol *, unsigned int,
211 union internal_auxent *));
214 coff_read_enum_type PARAMS ((int, int, int));
216 static struct blockvector *
217 make_blockvector PARAMS ((struct objfile *));
219 static struct symbol *
220 process_coff_symbol PARAMS ((struct coff_symbol *, union internal_auxent *,
224 patch_opaque_types PARAMS ((struct objfile *, struct symtab *, PTR, PTR, PTR));
227 patch_type PARAMS ((struct type *, struct type *));
230 enter_linenos PARAMS ((long, int, int));
233 init_lineno PARAMS ((int, long, int));
236 getfilename PARAMS ((union internal_auxent *));
239 getsymname PARAMS ((struct internal_syment *));
242 free_stringtab PARAMS ((void));
245 init_stringtab PARAMS ((int, long));
248 read_one_sym PARAMS ((struct coff_symbol *, struct internal_syment *,
249 union internal_auxent *));
252 read_coff_symtab PARAMS ((int, int, struct objfile *));
255 find_linenos PARAMS ((bfd *, sec_ptr, PTR));
258 coff_symfile_init PARAMS ((struct objfile *));
261 coff_new_init PARAMS ((struct objfile *));
264 coff_symfile_read PARAMS ((struct objfile *, CORE_ADDR, int));
267 coff_symfile_finish PARAMS ((struct objfile *));
270 record_minimal_symbol PARAMS ((char *, CORE_ADDR));
273 coff_end_symtab PARAMS ((struct objfile *));
276 complete_symtab PARAMS ((char *, CORE_ADDR, unsigned int));
279 coff_start_symtab PARAMS ((void));
282 coff_record_line PARAMS ((int, CORE_ADDR));
285 coff_finish_block PARAMS ((struct symbol *, struct coff_pending **,
286 struct pending_block *, CORE_ADDR, CORE_ADDR,
290 coff_add_symbol_to_list PARAMS ((struct symbol *, struct coff_pending **));
293 coff_alloc_type PARAMS ((int));
295 static struct type **
296 coff_lookup_type PARAMS ((int));
299 /* Look up a coff type-number index. Return the address of the slot
300 where the type for that index is stored.
301 The type-number is in INDEX.
303 This can be used for finding the type associated with that index
304 or for associating a new type with the index. */
306 static struct type **
307 coff_lookup_type (index)
310 if (index >= type_vector_length)
312 int old_vector_length = type_vector_length;
314 type_vector_length *= 2;
315 if (type_vector_length < index) {
316 type_vector_length = index * 2;
318 type_vector = (struct type **)
319 xrealloc ((char *) type_vector,
320 type_vector_length * sizeof (struct type *));
321 bzero (&type_vector[old_vector_length],
322 (type_vector_length - old_vector_length) * sizeof(struct type *));
324 return &type_vector[index];
327 /* Make sure there is a type allocated for type number index
328 and return the type object.
329 This can create an empty (zeroed) type object. */
332 coff_alloc_type (index)
335 register struct type **type_addr = coff_lookup_type (index);
336 register struct type *type = *type_addr;
338 /* If we are referring to a type not known at all yet,
339 allocate an empty type for it.
340 We will fill it in later if we find out how. */
343 type = alloc_type (current_objfile);
349 /* maintain the lists of symbols and blocks */
351 /* Add a symbol to one of the lists of symbols. */
353 coff_add_symbol_to_list (symbol, listhead)
354 struct symbol *symbol;
355 struct coff_pending **listhead;
357 register struct coff_pending *link
358 = (struct coff_pending *) xmalloc (sizeof (struct coff_pending));
360 link->next = *listhead;
361 link->symbol = symbol;
365 /* Take one of the lists of symbols and make a block from it.
366 Put the block on the list of pending blocks. */
369 coff_finish_block (symbol, listhead, old_blocks, start, end, objfile)
370 struct symbol *symbol;
371 struct coff_pending **listhead;
372 struct pending_block *old_blocks;
373 CORE_ADDR start, end;
374 struct objfile *objfile;
376 register struct coff_pending *next, *next1;
377 register struct block *block;
378 register struct pending_block *pblock;
379 struct pending_block *opblock;
382 /* Count the length of the list of symbols. */
384 for (next = *listhead, i = 0; next; next = next->next, i++);
386 block = (struct block *)
387 obstack_alloc (&objfile->symbol_obstack, sizeof (struct block) + (i - 1) * sizeof (struct symbol *));
389 /* Copy the symbols into the block. */
391 BLOCK_NSYMS (block) = i;
392 for (next = *listhead; next; next = next->next)
393 BLOCK_SYM (block, --i) = next->symbol;
395 BLOCK_START (block) = start;
396 BLOCK_END (block) = end;
397 BLOCK_SUPERBLOCK (block) = 0; /* Filled in when containing block is made */
399 /* Put the block in as the value of the symbol that names it. */
403 SYMBOL_BLOCK_VALUE (symbol) = block;
404 BLOCK_FUNCTION (block) = symbol;
407 BLOCK_FUNCTION (block) = 0;
409 /* Now free the links of the list, and empty the list. */
411 for (next = *listhead; next; next = next1)
418 /* Install this block as the superblock
419 of all blocks made since the start of this scope
420 that don't have superblocks yet. */
423 for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next)
425 if (BLOCK_SUPERBLOCK (pblock->block) == 0)
426 BLOCK_SUPERBLOCK (pblock->block) = block;
430 /* Record this block on the list of all blocks in the file.
431 Put it after opblock, or at the beginning if opblock is 0.
432 This puts the block in the list after all its subblocks. */
434 pblock = (struct pending_block *) xmalloc (sizeof (struct pending_block));
435 pblock->block = block;
438 pblock->next = opblock->next;
439 opblock->next = pblock;
443 pblock->next = pending_blocks;
444 pending_blocks = pblock;
448 static struct blockvector *
449 make_blockvector (objfile)
450 struct objfile *objfile;
452 register struct pending_block *next, *next1;
453 register struct blockvector *blockvector;
456 /* Count the length of the list of blocks. */
458 for (next = pending_blocks, i = 0; next; next = next->next, i++);
460 blockvector = (struct blockvector *)
461 obstack_alloc (&objfile->symbol_obstack, sizeof (struct blockvector) + (i - 1) * sizeof (struct block *));
463 /* Copy the blocks into the blockvector.
464 This is done in reverse order, which happens to put
465 the blocks into the proper order (ascending starting address).
466 coff_finish_block has hair to insert each block into the list
467 after its subblocks in order to make sure this is true. */
469 BLOCKVECTOR_NBLOCKS (blockvector) = i;
470 for (next = pending_blocks; next; next = next->next)
471 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
473 /* Now free the links of the list, and empty the list. */
475 for (next = pending_blocks; next; next = next1)
485 /* Manage the vector of line numbers. */
488 coff_record_line (line, pc)
492 struct linetable_entry *e;
493 /* Make sure line vector is big enough. */
495 if (line_vector_index + 2 >= line_vector_length)
497 line_vector_length *= 2;
498 line_vector = (struct linetable *)
499 xrealloc ((char *) line_vector, sizeof (struct linetable)
500 + (line_vector_length
501 * sizeof (struct linetable_entry)));
504 e = line_vector->item + line_vector_index++;
505 e->line = line; e->pc = pc;
508 /* Start a new symtab for a new source file.
509 This is called when a COFF ".file" symbol is seen;
510 it indicates the start of data for one original source file. */
515 coff_file_symbols = 0;
516 coff_global_symbols = 0;
517 coff_context_stack = 0;
519 last_source_file = 0;
521 /* Initialize the source file line number information for this file. */
523 if (line_vector) /* Unlikely, but maybe possible? */
525 line_vector_index = 0;
526 line_vector_length = 1000;
527 prev_line_number = -2; /* Force first line number to be explicit */
528 line_vector = (struct linetable *)
529 xmalloc (sizeof (struct linetable)
530 + line_vector_length * sizeof (struct linetable_entry));
533 /* Save the vital information from when starting to read a file,
534 for use when closing off the current file.
535 NAME is the file name the symbols came from, START_ADDR is the first
536 text address for the file, and SIZE is the number of bytes of text. */
539 complete_symtab (name, start_addr, size)
541 CORE_ADDR start_addr;
544 last_source_file = savestring (name, strlen (name));
545 cur_src_start_addr = start_addr;
546 cur_src_end_addr = start_addr + size;
548 if (current_objfile -> ei.entry_point >= cur_src_start_addr &&
549 current_objfile -> ei.entry_point < cur_src_end_addr)
551 current_objfile -> ei.entry_file_lowpc = cur_src_start_addr;
552 current_objfile -> ei.entry_file_highpc = cur_src_end_addr;
556 /* Finish the symbol definitions for one main source file,
557 close off all the lexical contexts for that file
558 (creating struct block's for them), then make the
559 struct symtab for that file and put it in the list of all such. */
562 coff_end_symtab (objfile)
563 struct objfile *objfile;
565 register struct symtab *symtab;
566 register struct coff_context_stack *cstk;
567 register struct blockvector *blockvector;
568 register struct linetable *lv;
570 /* Finish the lexical context of the last function in the file. */
572 if (coff_context_stack)
574 cstk = coff_context_stack;
575 coff_context_stack = 0;
576 /* Make a block for the local symbols within. */
577 coff_finish_block (cstk->name, &coff_local_symbols, cstk->old_blocks,
578 cstk->start_addr, cur_src_end_addr, objfile);
582 /* Ignore a file that has no functions with real debugging info. */
583 if (pending_blocks == 0 && coff_file_symbols == 0 && coff_global_symbols == 0)
587 line_vector_length = -1;
588 last_source_file = 0;
592 /* Create the two top-level blocks for this file (STATIC_BLOCK and
594 coff_finish_block (0, &coff_file_symbols, 0, cur_src_start_addr, cur_src_end_addr, objfile);
595 coff_finish_block (0, &coff_global_symbols, 0, cur_src_start_addr, cur_src_end_addr, objfile);
597 /* Create the blockvector that points to all the file's blocks. */
598 blockvector = make_blockvector (objfile);
600 /* Now create the symtab object for this source file. */
601 symtab = allocate_symtab (last_source_file, objfile);
603 /* Fill in its components. */
604 symtab->blockvector = blockvector;
605 symtab->free_code = free_linetable;
606 symtab->free_ptr = 0;
607 symtab->filename = last_source_file;
608 symtab->dirname = NULL;
610 lv->nitems = line_vector_index;
611 symtab->linetable = (struct linetable *)
612 xrealloc ((char *) lv, (sizeof (struct linetable)
613 + lv->nitems * sizeof (struct linetable_entry)));
615 free_named_symtabs (symtab->filename);
617 /* Reinitialize for beginning of new file. */
619 line_vector_length = -1;
620 last_source_file = 0;
624 record_minimal_symbol (name, address)
628 /* We don't want TDESC entry points in the minimal symbol table */
629 if (name[0] == '@') return;
631 /* mst_text isn't true, but apparently COFF doesn't tell us what it really
632 is, so this guess is more useful than mst_unknown. */
633 prim_record_minimal_symbol (savestring (name, strlen (name)),
638 /* coff_symfile_init ()
639 is the coff-specific initialization routine for reading symbols.
640 It is passed a struct objfile which contains, among other things,
641 the BFD for the file whose symbols are being read, and a slot for
642 a pointer to "private data" which we fill with cookies and other
643 treats for coff_symfile_read ().
645 We will only be called if this is a COFF or COFF-like file.
646 BFD handles figuring out the format of the file, and code in symtab.c
647 uses BFD's determination to vector to us.
649 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
651 struct coff_symfile_info {
652 file_ptr min_lineno_offset; /* Where in file lowest line#s are */
653 file_ptr max_lineno_offset; /* 1+last byte of line#s in file */
656 static int text_bfd_scnum;
659 coff_symfile_init (objfile)
660 struct objfile *objfile;
663 bfd *abfd = objfile->obfd;
665 /* Allocate struct to keep track of the symfile */
666 objfile -> sym_private = xmmalloc (objfile -> md,
667 sizeof (struct coff_symfile_info));
669 init_entry_point_info (objfile);
671 /* Save the section number for the text section */
672 if (section = bfd_get_section_by_name(abfd,".text"))
673 text_bfd_scnum = section->index;
678 /* This function is called for every section; it finds the outer limits
679 of the line table (minimum and maximum file offset) so that the
680 mainline code can read the whole thing for efficiency. */
684 find_linenos (abfd, asect, vpinfo)
689 struct coff_symfile_info *info;
691 file_ptr offset, maxoff;
693 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
694 count = asect->lineno_count;
699 size = count * local_linesz;
701 info = (struct coff_symfile_info *)vpinfo;
702 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
703 offset = asect->line_filepos;
706 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
707 info->min_lineno_offset = offset;
709 maxoff = offset + size;
710 if (maxoff > info->max_lineno_offset)
711 info->max_lineno_offset = maxoff;
715 /* The BFD for this file -- only good while we're actively reading
716 symbols into a psymtab or a symtab. */
718 static bfd *symfile_bfd;
720 /* Read a symbol file, after initialization by coff_symfile_init. */
721 /* FIXME! Addr and Mainline are not used yet -- this will not work for
722 shared libraries or add_file! */
726 coff_symfile_read (objfile, addr, mainline)
727 struct objfile *objfile;
731 struct coff_symfile_info *info;
732 bfd *abfd = objfile->obfd;
733 coff_data_type *cdata = coff_data (abfd);
734 char *name = bfd_get_filename (abfd);
739 int stringtab_offset;
741 info = (struct coff_symfile_info *) objfile -> sym_private;
742 symfile_bfd = abfd; /* Kludge for swap routines */
744 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
745 desc = fileno ((FILE *)(abfd->iostream)); /* File descriptor */
746 num_symbols = bfd_get_symcount (abfd); /* How many syms */
747 symtab_offset = cdata->sym_filepos; /* Symbol table file offset */
748 stringtab_offset = symtab_offset + /* String table file offset */
749 num_symbols * cdata->local_symesz;
751 /* Set a few file-statics that give us specific information about
752 the particular COFF file format we're reading. */
753 local_linesz = cdata->local_linesz;
754 local_n_btmask = cdata->local_n_btmask;
755 local_n_btshft = cdata->local_n_btshft;
756 local_n_tmask = cdata->local_n_tmask;
757 local_n_tshift = cdata->local_n_tshift;
758 local_linesz = cdata->local_linesz;
759 local_symesz = cdata->local_symesz;
760 local_auxesz = cdata->local_auxesz;
762 /* Allocate space for raw symbol and aux entries, based on their
763 space requirements as reported by BFD. */
764 temp_sym = (char *) xmalloc
765 (cdata->local_symesz + cdata->local_auxesz);
766 temp_aux = temp_sym + cdata->local_symesz;
767 make_cleanup (free_current_contents, &temp_sym);
770 /* Read the line number table, all at once. */
771 info->min_lineno_offset = 0;
772 info->max_lineno_offset = 0;
773 bfd_map_over_sections (abfd, find_linenos, info);
775 val = init_lineno (desc, info->min_lineno_offset,
776 info->max_lineno_offset - info->min_lineno_offset);
778 error ("\"%s\": error reading line numbers\n", name);
780 /* Now read the string table, all at once. */
782 val = init_stringtab (desc, stringtab_offset);
784 error ("\"%s\": can't get string table", name);
785 make_cleanup (free_stringtab, 0);
787 /* Position to read the symbol table. Do not read it all at once. */
788 val = lseek (desc, (long)symtab_offset, 0);
790 perror_with_name (name);
792 init_minimal_symbol_collection ();
793 make_cleanup (discard_minimal_symbols, 0);
795 /* Now that the executable file is positioned at symbol table,
796 process it and define symbols accordingly. */
798 read_coff_symtab (desc, num_symbols, objfile);
800 iterate_over_symtabs (patch_opaque_types, (PTR) NULL, (PTR) NULL,
803 /* Sort symbols alphabetically within each block. */
805 sort_all_symtab_syms ();
807 /* Install any minimal symbols that have been collected as the current
808 minimal symbols for this objfile. */
810 install_minimal_symbols (objfile);
814 coff_new_init (objfile)
815 struct objfile *objfile;
820 /* Perform any local cleanups required when we are done with a particular
821 objfile. I.E, we are in the process of discarding all symbol information
822 for an objfile, freeing up all memory held for it, and unlinking the
823 objfile struct from the global list of known objfiles. */
826 coff_symfile_finish (objfile)
827 struct objfile *objfile;
829 if (objfile -> sym_private != NULL)
831 mfree (objfile -> md, objfile -> sym_private);
836 /* Given pointers to a symbol table in coff style exec file,
837 analyze them and create struct symtab's describing the symbols.
838 NSYMS is the number of symbols in the symbol table.
839 We read them one at a time using read_one_sym (). */
842 read_coff_symtab (desc, nsyms, objfile)
845 struct objfile *objfile;
847 int newfd; /* Avoid multiple closes on same desc */
849 register struct coff_context_stack *new;
850 struct coff_symbol coff_symbol;
851 register struct coff_symbol *cs = &coff_symbol;
852 static struct internal_syment main_sym;
853 static union internal_auxent main_aux;
854 struct coff_symbol fcn_cs_saved;
855 static struct internal_syment fcn_sym_saved;
856 static union internal_auxent fcn_aux_saved;
858 /* A .file is open. */
859 int in_source_file = 0;
860 int num_object_files = 0;
861 int next_file_symnum = -1;
863 /* Name of the current file. */
864 char *filestring = "";
870 struct cleanup *old_chain;
875 fatal ("Too many open files");
876 stream = fdopen (newfd, "r");
878 /* These cleanups will be discarded below if we succeed. */
879 old_chain = make_cleanup (free_objfile, objfile);
880 make_cleanup (fclose, stream);
882 current_objfile = objfile;
883 nlist_stream_global = stream;
884 nlist_nsyms_global = nsyms;
885 last_source_file = 0;
886 bzero (opaque_type_chain, sizeof opaque_type_chain);
888 if (type_vector) /* Get rid of previous one */
890 type_vector_length = 160;
891 type_vector = (struct type **)
892 xmalloc (type_vector_length * sizeof (struct type *));
893 bzero (type_vector, type_vector_length * sizeof (struct type *));
895 coff_start_symtab ();
898 while (symnum < nsyms)
900 QUIT; /* Make this command interruptable. */
901 read_one_sym (cs, &main_sym, &main_aux);
904 temp_sem_val = cs->c_name[0] << 24 | cs->c_name[1] << 16 |
905 cs->c_name[2] << 8 | cs->c_name[3];
906 if (int_sem_val == temp_sem_val)
907 last_coffsem = (int) strtol (cs->c_name+4, (char **) NULL, 10);
910 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
912 if (last_source_file)
913 coff_end_symtab (objfile);
915 coff_start_symtab ();
916 complete_symtab ("_globals_", 0, first_object_file_end);
917 /* done with all files, everything from here on out is globals */
920 /* Special case for file with type declarations only, no text. */
921 if (!last_source_file && SDB_TYPE (cs->c_type)
922 && cs->c_secnum == N_DEBUG)
923 complete_symtab (filestring, 0, 0);
925 /* Typedefs should not be treated as symbol definitions. */
926 if (ISFCN (cs->c_type) && cs->c_sclass != C_TPDEF)
928 /* record as a minimal symbol. if we get '.bf' next,
929 * then we undo this step
931 record_minimal_symbol (cs->c_name, cs->c_value);
933 fcn_line_ptr = main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
934 fcn_start_addr = cs->c_value;
936 fcn_sym_saved = main_sym;
937 fcn_aux_saved = main_aux;
941 switch (cs->c_sclass)
950 complain (&bad_sclass_complaint, cs->c_name);
955 * c_value field contains symnum of next .file entry in table
956 * or symnum of first global after last .file.
958 next_file_symnum = cs->c_value;
959 filestring = getfilename (&main_aux);
961 * Complete symbol table for last object file
962 * containing debugging information.
964 if (last_source_file)
966 coff_end_symtab (objfile);
967 coff_start_symtab ();
973 if (cs->c_name[0] == '.') {
974 if (strcmp (cs->c_name, ".text") == 0) {
975 /* FIXME: don't wire in ".text" as section name
977 if (++num_object_files == 1) {
978 /* last address of startup file */
979 first_object_file_end = cs->c_value +
980 main_aux.x_scn.x_scnlen;
982 /* Check for in_source_file deals with case of
983 a file with debugging symbols
984 followed by a later file with no symbols. */
986 complete_symtab (filestring, cs->c_value,
987 main_aux.x_scn.x_scnlen);
990 /* flush rest of '.' symbols */
993 else if (!SDB_TYPE (cs->c_type)
994 && cs->c_name[0] == 'L'
995 && (strncmp (cs->c_name, "LI%", 3) == 0
996 || strncmp (cs->c_name, "LF%", 3) == 0
997 || strncmp (cs->c_name,"LC%",3) == 0
998 || strncmp (cs->c_name,"LP%",3) == 0
999 || strncmp (cs->c_name,"LPB%",4) == 0
1000 || strncmp (cs->c_name,"LBB%",4) == 0
1001 || strncmp (cs->c_name,"LBE%",4) == 0
1002 || strncmp (cs->c_name,"LPBX%",5) == 0))
1003 /* At least on a 3b1, gcc generates swbeg and string labels
1004 that look like this. Ignore them. */
1006 /* fall in for static symbols that don't start with '.' */
1008 if (!SDB_TYPE (cs->c_type)) {
1009 /* FIXME: This is BOGUS Will Robinson!
1010 Coff should provide the SEC_CODE flag for executable sections,
1011 then if we could look up sections by section number we
1012 could see if the flags indicate SEC_CODE. If so, then
1013 record this symbol as a function in the minimal symbol table.
1014 But why are absolute syms recorded as functions, anyway? */
1015 if (cs->c_secnum <= text_bfd_scnum+1) {/* text or abs */
1016 record_minimal_symbol (cs->c_name, cs->c_value);
1022 (void) process_coff_symbol (cs, &main_aux, objfile);
1026 if (strcmp (cs->c_name, ".bf") == 0)
1028 within_function = 1;
1030 /* value contains address of first non-init type code */
1031 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
1032 contains line number of '{' } */
1033 if (cs->c_naux != 1)
1034 complain (&bf_no_aux_complaint, (char *) cs->c_symnum);
1035 fcn_first_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
1037 new = (struct coff_context_stack *)
1038 xmalloc (sizeof (struct coff_context_stack));
1039 new->depth = depth = 0;
1041 coff_context_stack = new;
1043 new->old_blocks = pending_blocks;
1044 new->start_addr = fcn_start_addr;
1045 fcn_cs_saved.c_name = getsymname (&fcn_sym_saved);
1046 new->name = process_coff_symbol (&fcn_cs_saved,
1047 &fcn_aux_saved, objfile);
1049 else if (strcmp (cs->c_name, ".ef") == 0)
1051 /* the value of .ef is the address of epilogue code;
1052 * not useful for gdb
1054 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1055 contains number of lines to '}' */
1056 new = coff_context_stack;
1059 complain (&ef_complaint, (char *) cs->c_symnum);
1060 within_function = 0;
1063 if (cs->c_naux != 1) {
1064 complain (&ef_no_aux_complaint, (char *) cs->c_symnum);
1065 fcn_last_line = 0x7FFFFFFF;
1067 fcn_last_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
1069 enter_linenos (fcn_line_ptr, fcn_first_line, fcn_last_line);
1071 coff_finish_block (new->name, &coff_local_symbols, new->old_blocks,
1073 #if defined (FUNCTION_EPILOGUE_SIZE)
1074 /* This macro should be defined only on
1076 fcn_aux_saved.x_sym.x_misc.x_fsize
1077 field is always zero.
1078 So use the .bf record information that
1079 points to the epilogue and add the size
1081 cs->c_value + FUNCTION_EPILOGUE_SIZE,
1083 fcn_cs_saved.c_value +
1084 fcn_aux_saved.x_sym.x_misc.x_fsize,
1088 coff_context_stack = 0;
1089 within_function = 0;
1095 if (strcmp (cs->c_name, ".bb") == 0)
1097 new = (struct coff_context_stack *)
1098 xmalloc (sizeof (struct coff_context_stack));
1101 new->next = coff_context_stack;
1102 coff_context_stack = new;
1103 new->locals = coff_local_symbols;
1104 new->old_blocks = pending_blocks;
1105 new->start_addr = cs->c_value;
1107 coff_local_symbols = 0;
1109 else if (strcmp (cs->c_name, ".eb") == 0)
1111 new = coff_context_stack;
1112 if (new == 0 || depth != new->depth)
1113 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1115 if (coff_local_symbols && coff_context_stack->next)
1117 /* Make a block for the local symbols within. */
1118 coff_finish_block (0, &coff_local_symbols, new->old_blocks,
1119 new->start_addr, cs->c_value, objfile);
1122 coff_local_symbols = new->locals;
1123 coff_context_stack = new->next;
1129 (void) process_coff_symbol (cs, &main_aux, objfile);
1134 if (last_source_file)
1135 coff_end_symtab (objfile);
1137 discard_cleanups (old_chain);
1138 current_objfile = NULL;
1141 /* Routines for reading headers and symbols from executable. */
1144 /* Move these XXXMAGIC symbol defns into BFD! */
1146 /* Read COFF file header, check magic number,
1147 and return number of symbols. */
1148 read_file_hdr (chan, file_hdr)
1152 lseek (chan, 0L, 0);
1153 if (myread (chan, (char *)file_hdr, FILHSZ) < 0)
1156 switch (file_hdr->f_magic)
1171 #if defined (MC68KWRMAGIC) \
1172 && (!defined (MC68MAGIC) || MC68KWRMAGIC != MC68MAGIC)
1186 case I960ROMAGIC: /* Intel 960 */
1189 case I960RWMAGIC: /* Intel 960 */
1191 return file_hdr->f_nsyms;
1195 if (BADMAG(file_hdr))
1198 return file_hdr->f_nsyms;
1206 /* Read the next symbol, swap it, and return it in both internal_syment
1207 form, and coff_symbol form. Also return its first auxent, if any,
1208 in internal_auxent form, and skip any other auxents. */
1211 read_one_sym (cs, sym, aux)
1212 register struct coff_symbol *cs;
1213 register struct internal_syment *sym;
1214 register union internal_auxent *aux;
1218 cs->c_symnum = symnum;
1219 fread (temp_sym, local_symesz, 1, nlist_stream_global);
1220 bfd_coff_swap_sym_in (symfile_bfd, temp_sym, (char *)sym);
1221 cs->c_naux = sym->n_numaux & 0xff;
1222 if (cs->c_naux >= 1)
1224 fread (temp_aux, local_auxesz, 1, nlist_stream_global);
1225 bfd_coff_swap_aux_in (symfile_bfd, temp_aux, sym->n_type, sym->n_sclass,
1227 /* If more than one aux entry, read past it (only the first aux
1229 for (i = 1; i < cs->c_naux; i++)
1230 fread (temp_aux, local_auxesz, 1, nlist_stream_global);
1232 cs->c_name = getsymname (sym);
1233 cs->c_value = sym->n_value;
1234 cs->c_sclass = (sym->n_sclass & 0xff);
1235 cs->c_secnum = sym->n_scnum;
1236 cs->c_type = (unsigned) sym->n_type;
1237 if (!SDB_TYPE (cs->c_type))
1240 symnum += 1 + cs->c_naux;
1243 /* Support for string table handling */
1245 static char *stringtab = NULL;
1248 init_stringtab (chan, offset)
1254 unsigned char lengthbuf[4];
1262 if (lseek (chan, offset, 0) < 0)
1265 val = myread (chan, (char *)lengthbuf, sizeof lengthbuf);
1266 length = bfd_h_get_32 (symfile_bfd, lengthbuf);
1268 /* If no string table is needed, then the file may end immediately
1269 after the symbols. Just return with `stringtab' set to null. */
1270 if (val != sizeof length || length < sizeof length)
1273 stringtab = (char *) xmalloc (length);
1274 if (stringtab == NULL)
1277 bcopy (&length, stringtab, sizeof length);
1278 if (length == sizeof length) /* Empty table -- just the count */
1281 val = myread (chan, stringtab + sizeof length, length - sizeof length);
1282 if (val != length - sizeof length || stringtab[length - 1] != '\0')
1297 getsymname (symbol_entry)
1298 struct internal_syment *symbol_entry;
1300 static char buffer[SYMNMLEN+1];
1303 if (symbol_entry->_n._n_n._n_zeroes == 0)
1305 result = stringtab + symbol_entry->_n._n_n._n_offset;
1309 strncpy (buffer, symbol_entry->_n._n_name, SYMNMLEN);
1310 buffer[SYMNMLEN] = '\0';
1317 getfilename (aux_entry)
1318 union internal_auxent *aux_entry;
1320 static char buffer[BUFSIZ];
1321 register char *temp;
1324 #ifndef COFF_NO_LONG_FILE_NAMES
1325 #if defined (x_zeroes)
1327 if (aux_entry->x_zeroes == 0)
1328 strcpy (buffer, stringtab + aux_entry->x_offset);
1329 #else /* no x_zeroes */
1330 if (aux_entry->x_file.x_n.x_zeroes == 0)
1331 strcpy (buffer, stringtab + aux_entry->x_file.x_n.x_offset);
1332 #endif /* no x_zeroes */
1334 #endif /* COFF_NO_LONG_FILE_NAMES */
1336 #if defined (x_name)
1338 strncpy (buffer, aux_entry->x_name, FILNMLEN);
1340 strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
1342 buffer[FILNMLEN] = '\0';
1345 if ((temp = strrchr (result, '/')) != NULL)
1350 /* Support for line number handling */
1351 static char *linetab = NULL;
1352 static long linetab_offset;
1353 static unsigned long linetab_size;
1355 /* Read in all the line numbers for fast lookups later. Leave them in
1356 external (unswapped) format in memory; we'll swap them as we enter
1357 them into GDB's data structures. */
1360 init_lineno (chan, offset, size)
1367 linetab_offset = offset;
1368 linetab_size = size;
1373 if (lseek (chan, offset, 0) < 0)
1376 /* Allocate the desired table, plus a sentinel */
1377 linetab = (char *) xmalloc (size + local_linesz);
1379 val = myread (chan, linetab, size);
1383 /* Terminate it with an all-zero sentinel record */
1384 bzero (linetab + size, local_linesz);
1386 make_cleanup (free, linetab); /* Be sure it gets de-allocated. */
1390 #if !defined (L_LNNO32)
1391 #define L_LNNO32(lp) ((lp)->l_lnno)
1395 enter_linenos (file_offset, first_line, last_line)
1397 register int first_line;
1398 register int last_line;
1400 register char *rawptr;
1401 struct internal_lineno lptr;
1403 if (file_offset < linetab_offset)
1405 complain (&lineno_complaint, (char *) file_offset);
1406 if (file_offset > linetab_size) /* Too big to be an offset? */
1408 file_offset += linetab_offset; /* Try reading at that linetab offset */
1411 rawptr = &linetab[file_offset - linetab_offset];
1413 /* skip first line entry for each function */
1414 rawptr += local_linesz;
1415 /* line numbers start at one for the first line of the function */
1419 bfd_coff_swap_lineno_in (symfile_bfd, rawptr, &lptr);
1420 rawptr += local_linesz;
1421 /* The next function, or the sentinel, will have L_LNNO32 zero; we exit. */
1422 if (L_LNNO32 (&lptr) && L_LNNO32 (&lptr) <= last_line)
1423 coff_record_line (first_line + L_LNNO32 (&lptr), lptr.l_addr.l_paddr);
1430 patch_type (type, real_type)
1432 struct type *real_type;
1434 register struct type *target = TYPE_TARGET_TYPE (type);
1435 register struct type *real_target = TYPE_TARGET_TYPE (real_type);
1436 int field_size = TYPE_NFIELDS (real_target) * sizeof (struct field);
1438 TYPE_LENGTH (target) = TYPE_LENGTH (real_target);
1439 TYPE_NFIELDS (target) = TYPE_NFIELDS (real_target);
1440 TYPE_FIELDS (target) = (struct field *)
1441 obstack_alloc (¤t_objfile -> type_obstack, field_size);
1443 bcopy (TYPE_FIELDS (real_target), TYPE_FIELDS (target), field_size);
1445 if (TYPE_NAME (real_target))
1447 if (TYPE_NAME (target))
1448 free (TYPE_NAME (target));
1449 TYPE_NAME (target) = concat (TYPE_NAME (real_target), NULL);
1453 /* Patch up all appropriate typedef symbols in the opaque_type_chains
1454 so that they can be used to print out opaque data structures properly.
1456 This is called via iterate_over_symtabs, and thus simply returns NULL
1457 for each time it is called, to indicate that the iteration should
1462 patch_opaque_types (objfile, s, arg1, arg2, arg3)
1463 struct objfile *objfile;
1469 register struct block *b;
1471 register struct symbol *real_sym;
1473 /* Go through the per-file symbols only */
1474 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
1475 for (i = BLOCK_NSYMS (b) - 1; i >= 0; i--)
1477 /* Find completed typedefs to use to fix opaque ones.
1478 Remove syms from the chain when their types are stored,
1479 but search the whole chain, as there may be several syms
1480 from different files with the same name. */
1481 real_sym = BLOCK_SYM (b, i);
1482 if (SYMBOL_CLASS (real_sym) == LOC_TYPEDEF &&
1483 SYMBOL_NAMESPACE (real_sym) == VAR_NAMESPACE &&
1484 TYPE_CODE (SYMBOL_TYPE (real_sym)) == TYPE_CODE_PTR &&
1485 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym))) != 0)
1487 register char *name = SYMBOL_NAME (real_sym);
1488 register int hash = hashname (name);
1489 register struct symbol *sym, *prev;
1492 for (sym = opaque_type_chain[hash]; sym;)
1494 if (name[0] == SYMBOL_NAME (sym)[0] &&
1495 !strcmp (name + 1, SYMBOL_NAME (sym) + 1))
1499 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
1503 opaque_type_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
1506 patch_type (SYMBOL_TYPE (sym), SYMBOL_TYPE (real_sym));
1510 sym = SYMBOL_VALUE_CHAIN (prev);
1514 sym = opaque_type_chain[hash];
1520 sym = SYMBOL_VALUE_CHAIN (sym);
1528 static struct symbol *
1529 process_coff_symbol (cs, aux, objfile)
1530 register struct coff_symbol *cs;
1531 register union internal_auxent *aux;
1532 struct objfile *objfile;
1534 register struct symbol *sym
1535 = (struct symbol *) obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
1537 #ifdef NAMES_HAVE_UNDERSCORE
1542 struct type *temptype;
1544 bzero (sym, sizeof (struct symbol));
1546 name = (name[0] == '_' ? name + offset : name);
1547 SYMBOL_NAME (sym) = obstack_copy0 (&objfile->symbol_obstack, name, strlen (name));
1549 /* default assumptions */
1550 SYMBOL_VALUE (sym) = cs->c_value;
1551 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1553 if (ISFCN (cs->c_type))
1556 /* FIXME: This has NOT been tested. The DBX version has.. */
1557 /* Generate a template for the type of this function. The
1558 types of the arguments will be added as we read the symbol
1560 struct type *new = (struct type *)
1561 obstack_alloc (&objfile->symbol_obstack, sizeof (struct type));
1563 bcopy(lookup_function_type (decode_function_type (cs, cs->c_type, aux)),
1564 new, sizeof(struct type));
1565 SYMBOL_TYPE (sym) = new;
1566 in_function_type = SYMBOL_TYPE(sym);
1569 lookup_function_type (decode_function_type (cs, cs->c_type, aux));
1572 SYMBOL_CLASS (sym) = LOC_BLOCK;
1573 if (cs->c_sclass == C_STAT)
1574 coff_add_symbol_to_list (sym, &coff_file_symbols);
1575 else if (cs->c_sclass == C_EXT)
1576 coff_add_symbol_to_list (sym, &coff_global_symbols);
1580 SYMBOL_TYPE (sym) = decode_type (cs, cs->c_type, aux);
1581 switch (cs->c_sclass)
1587 SYMBOL_CLASS (sym) = LOC_LOCAL;
1588 coff_add_symbol_to_list (sym, &coff_local_symbols);
1592 SYMBOL_CLASS (sym) = LOC_STATIC;
1593 SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
1594 coff_add_symbol_to_list (sym, &coff_global_symbols);
1598 SYMBOL_CLASS (sym) = LOC_STATIC;
1599 SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
1600 if (within_function) {
1601 /* Static symbol of local scope */
1602 coff_add_symbol_to_list (sym, &coff_local_symbols);
1605 /* Static symbol at top level of file */
1606 coff_add_symbol_to_list (sym, &coff_file_symbols);
1610 #ifdef C_GLBLREG /* AMD coff */
1614 SYMBOL_CLASS (sym) = LOC_REGISTER;
1615 SYMBOL_VALUE (sym) = SDB_REG_TO_REGNUM(cs->c_value);
1616 coff_add_symbol_to_list (sym, &coff_local_symbols);
1623 SYMBOL_CLASS (sym) = LOC_ARG;
1625 /* FIXME: This has not been tested. */
1626 /* Add parameter to function. */
1627 add_param_to_type(&in_function_type,sym);
1629 coff_add_symbol_to_list (sym, &coff_local_symbols);
1630 #if !defined (BELIEVE_PCC_PROMOTION)
1631 /* If PCC says a parameter is a short or a char,
1632 it is really an int. */
1633 temptype = lookup_fundamental_type (current_objfile, FT_INTEGER);
1634 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
1635 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
1637 SYMBOL_TYPE (sym) = TYPE_UNSIGNED (SYMBOL_TYPE (sym))
1638 ? lookup_fundamental_type (current_objfile,
1639 FT_UNSIGNED_INTEGER)
1646 SYMBOL_CLASS (sym) = LOC_REGPARM;
1647 SYMBOL_VALUE (sym) = SDB_REG_TO_REGNUM(cs->c_value);
1648 coff_add_symbol_to_list (sym, &coff_local_symbols);
1649 #if !defined (BELIEVE_PCC_PROMOTION)
1650 /* If PCC says a parameter is a short or a char,
1651 it is really an int. */
1652 temptype = lookup_fundamental_type (current_objfile, FT_INTEGER);
1653 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
1654 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
1656 SYMBOL_TYPE (sym) = TYPE_UNSIGNED (SYMBOL_TYPE (sym))
1657 ? lookup_fundamental_type (current_objfile,
1658 FT_UNSIGNED_INTEGER)
1665 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1666 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1668 /* If type has no name, give it one */
1669 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
1670 TYPE_NAME (SYMBOL_TYPE (sym)) = concat (SYMBOL_NAME (sym), NULL);
1672 /* Keep track of any type which points to empty structured type,
1673 so it can be filled from a definition from another file */
1674 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR &&
1675 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym))) == 0)
1677 register int i = hashname (SYMBOL_NAME (sym));
1679 SYMBOL_VALUE_CHAIN (sym) = opaque_type_chain[i];
1680 opaque_type_chain[i] = sym;
1682 coff_add_symbol_to_list (sym, &coff_file_symbols);
1688 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1689 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1690 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
1691 TYPE_NAME (SYMBOL_TYPE (sym))
1693 (cs->c_sclass == C_ENTAG
1695 : (cs->c_sclass == C_STRTAG
1696 ? "struct " : "union ")),
1697 SYMBOL_NAME (sym), NULL);
1698 coff_add_symbol_to_list (sym, &coff_file_symbols);
1708 /* Decode a coff type specifier;
1709 return the type that is meant. */
1713 decode_type (cs, c_type, aux)
1714 register struct coff_symbol *cs;
1715 unsigned int c_type;
1716 register union internal_auxent *aux;
1718 register struct type *type = 0;
1719 unsigned int new_c_type;
1721 if (c_type & ~N_BTMASK)
1723 new_c_type = DECREF (c_type);
1726 type = decode_type (cs, new_c_type, aux);
1727 type = lookup_pointer_type (type);
1729 else if (ISFCN (c_type))
1731 type = decode_type (cs, new_c_type, aux);
1732 type = lookup_function_type (type);
1734 else if (ISARY (c_type))
1737 register unsigned short *dim;
1738 struct type *base_type;
1740 /* Define an array type. */
1741 /* auxent refers to array, not base type */
1742 if (aux->x_sym.x_tagndx.l == 0)
1745 /* shift the indices down */
1746 dim = &aux->x_sym.x_fcnary.x_ary.x_dimen[0];
1749 for (i = 0; *dim && i < DIMNUM - 1; i++, dim++)
1753 type = (struct type *)
1754 obstack_alloc (¤t_objfile -> type_obstack,
1755 sizeof (struct type));
1756 bzero (type, sizeof (struct type));
1757 TYPE_OBJFILE (type) = current_objfile;
1759 base_type = decode_type (cs, new_c_type, aux);
1761 TYPE_CODE (type) = TYPE_CODE_ARRAY;
1762 TYPE_TARGET_TYPE (type) = base_type;
1763 TYPE_LENGTH (type) = n * TYPE_LENGTH (base_type);
1768 /* Reference to existing type */
1769 if (cs->c_naux > 0 && aux->x_sym.x_tagndx.l != 0)
1771 type = coff_alloc_type (aux->x_sym.x_tagndx.l);
1775 return decode_base_type (cs, BTYPE (c_type), aux);
1778 /* Decode a coff type specifier for function definition;
1779 return the type that the function returns. */
1783 decode_function_type (cs, c_type, aux)
1784 register struct coff_symbol *cs;
1785 unsigned int c_type;
1786 register union internal_auxent *aux;
1788 if (aux->x_sym.x_tagndx.l == 0)
1789 cs->c_naux = 0; /* auxent refers to function, not base type */
1791 return decode_type (cs, DECREF (c_type), aux);
1798 decode_base_type (cs, c_type, aux)
1799 register struct coff_symbol *cs;
1800 unsigned int c_type;
1801 register union internal_auxent *aux;
1808 /* shows up with "void (*foo)();" structure members */
1809 return lookup_fundamental_type (current_objfile, FT_VOID);
1812 /* DGUX actually defines both T_ARG and T_VOID to the same value. */
1815 /* Shows up in DGUX, I think. Not sure where. */
1816 return lookup_fundamental_type (current_objfile, FT_VOID); /* shouldn't show up here */
1822 /* Intel 960 COFF has this symbol and meaning. */
1823 return lookup_fundamental_type (current_objfile, FT_VOID);
1827 return lookup_fundamental_type (current_objfile, FT_CHAR);
1830 return lookup_fundamental_type (current_objfile, FT_SHORT);
1833 return lookup_fundamental_type (current_objfile, FT_INTEGER);
1836 return lookup_fundamental_type (current_objfile, FT_LONG);
1839 return lookup_fundamental_type (current_objfile, FT_FLOAT);
1842 return lookup_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT);
1845 if (cs->c_naux != 1)
1847 /* anonymous structure type */
1848 type = coff_alloc_type (cs->c_symnum);
1849 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1850 TYPE_NAME (type) = concat ("struct ", "<opaque>", NULL);
1851 INIT_CPLUS_SPECIFIC(type);
1852 TYPE_LENGTH (type) = 0;
1853 TYPE_FIELDS (type) = 0;
1854 TYPE_NFIELDS (type) = 0;
1858 type = coff_read_struct_type (cs->c_symnum,
1859 aux->x_sym.x_misc.x_lnsz.x_size,
1860 aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
1865 if (cs->c_naux != 1)
1867 /* anonymous union type */
1868 type = coff_alloc_type (cs->c_symnum);
1869 TYPE_NAME (type) = concat ("union ", "<opaque>", NULL);
1870 INIT_CPLUS_SPECIFIC(type);
1871 TYPE_LENGTH (type) = 0;
1872 TYPE_LENGTH (type) = 0;
1873 TYPE_FIELDS (type) = 0;
1874 TYPE_NFIELDS (type) = 0;
1878 type = coff_read_struct_type (cs->c_symnum,
1879 aux->x_sym.x_misc.x_lnsz.x_size,
1880 aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
1882 TYPE_CODE (type) = TYPE_CODE_UNION;
1886 return coff_read_enum_type (cs->c_symnum,
1887 aux->x_sym.x_misc.x_lnsz.x_size,
1888 aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
1891 /* shouldn't show up here */
1895 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_CHAR);
1898 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_SHORT);
1901 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER);
1904 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_LONG);
1906 complain (&unexpected_type_complaint, cs->c_name);
1907 return lookup_fundamental_type (current_objfile, FT_VOID);
1910 /* This page contains subroutines of read_type. */
1912 /* Read the description of a structure (or union type)
1913 and return an object describing the type. */
1915 static struct type *
1916 coff_read_struct_type (index, length, lastsym)
1923 struct nextfield *next;
1927 register struct type *type;
1928 register struct nextfield *list = 0;
1929 struct nextfield *new;
1933 #ifdef NAMES_HAVE_UNDERSCORE
1938 struct coff_symbol member_sym;
1939 register struct coff_symbol *ms = &member_sym;
1940 struct internal_syment sub_sym;
1941 union internal_auxent sub_aux;
1944 type = coff_alloc_type (index);
1945 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1946 INIT_CPLUS_SPECIFIC(type);
1947 TYPE_LENGTH (type) = length;
1949 while (!done && symnum < lastsym && symnum < nlist_nsyms_global)
1951 read_one_sym (ms, &sub_sym, &sub_aux);
1953 name = (name[0] == '_' ? name + offset : name);
1955 switch (ms->c_sclass)
1960 /* Get space to record the next field's data. */
1961 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1965 /* Save the data. */
1966 list->field.name = savestring (name, strlen (name));
1967 list->field.type = decode_type (ms, ms->c_type, &sub_aux);
1968 list->field.bitpos = 8 * ms->c_value;
1969 list->field.bitsize = 0;
1975 /* Get space to record the next field's data. */
1976 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1980 /* Save the data. */
1981 list->field.name = savestring (name, strlen (name));
1982 list->field.type = decode_type (ms, ms->c_type, &sub_aux);
1983 list->field.bitpos = ms->c_value;
1984 list->field.bitsize = sub_aux.x_sym.x_misc.x_lnsz.x_size;
1993 /* Now create the vector of fields, and record how big it is. */
1995 TYPE_NFIELDS (type) = nfields;
1996 TYPE_FIELDS (type) = (struct field *)
1997 obstack_alloc (¤t_objfile -> type_obstack,
1998 sizeof (struct field) * nfields);
2000 /* Copy the saved-up fields into the field vector. */
2002 for (n = nfields; list; list = list->next)
2003 TYPE_FIELD (type, --n) = list->field;
2008 /* Read a definition of an enumeration type,
2009 and create and return a suitable type object.
2010 Also defines the symbols that represent the values of the type. */
2011 /* Currently assumes it's sizeof (int) and doesn't use length. */
2014 static struct type *
2015 coff_read_enum_type (index, length, lastsym)
2020 register struct symbol *sym;
2021 register struct type *type;
2024 struct coff_pending **symlist;
2025 struct coff_symbol member_sym;
2026 register struct coff_symbol *ms = &member_sym;
2027 struct internal_syment sub_sym;
2028 union internal_auxent sub_aux;
2029 struct coff_pending *osyms, *syms;
2032 #ifdef NAMES_HAVE_UNDERSCORE
2038 type = coff_alloc_type (index);
2039 if (within_function)
2040 symlist = &coff_local_symbols;
2042 symlist = &coff_file_symbols;
2045 while (!done && symnum < lastsym && symnum < nlist_nsyms_global)
2047 read_one_sym (ms, &sub_sym, &sub_aux);
2049 name = (name[0] == '_' ? name + offset : name);
2051 switch (ms->c_sclass)
2054 sym = (struct symbol *) xmalloc (sizeof (struct symbol));
2055 bzero (sym, sizeof (struct symbol));
2057 SYMBOL_NAME (sym) = savestring (name, strlen (name));
2058 SYMBOL_CLASS (sym) = LOC_CONST;
2059 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2060 SYMBOL_VALUE (sym) = ms->c_value;
2061 coff_add_symbol_to_list (sym, symlist);
2066 /* Sometimes the linker (on 386/ix 2.0.2 at least) screws
2067 up the count of how many symbols to read. So stop
2074 /* Now fill in the fields of the type-structure. */
2076 TYPE_LENGTH (type) = TARGET_INT_BIT / TARGET_CHAR_BIT;
2077 TYPE_CODE (type) = TYPE_CODE_ENUM;
2078 TYPE_NFIELDS (type) = nsyms;
2079 TYPE_FIELDS (type) = (struct field *)
2080 obstack_alloc (¤t_objfile -> type_obstack,
2081 sizeof (struct field) * nsyms);
2083 /* Find the symbols for the values and put them into the type.
2084 The symbols can be found in the symlist that we put them on
2085 to cause them to be defined. osyms contains the old value
2086 of that symlist; everything up to there was defined by us. */
2088 for (syms = *symlist, n = nsyms; syms != osyms; syms = syms->next)
2090 SYMBOL_TYPE (syms->symbol) = type;
2091 TYPE_FIELD_NAME (type, --n) = SYMBOL_NAME (syms->symbol);
2092 TYPE_FIELD_VALUE (type, n) = 0;
2093 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (syms->symbol);
2094 TYPE_FIELD_BITSIZE (type, n) = 0;
2096 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2097 if(TYPE_NFIELDS(type) == 2 &&
2098 ((!strcmp(TYPE_FIELD_NAME(type,0),"TRUE") &&
2099 !strcmp(TYPE_FIELD_NAME(type,1),"FALSE")) ||
2100 (!strcmp(TYPE_FIELD_NAME(type,1),"TRUE") &&
2101 !strcmp(TYPE_FIELD_NAME(type,0),"FALSE"))))
2102 TYPE_CODE(type) = TYPE_CODE_BOOL;
2106 /* Register our ability to parse symbols for coff BFD files */
2108 static struct sym_fns coff_sym_fns =
2110 "coff", /* sym_name: name or name prefix of BFD target type */
2111 4, /* sym_namelen: number of significant sym_name chars */
2112 coff_new_init, /* sym_new_init: init anything gbl to entire symtab */
2113 coff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
2114 coff_symfile_read, /* sym_read: read a symbol file into symtab */
2115 coff_symfile_finish, /* sym_finish: finished with file, cleanup */
2116 NULL /* next: pointer to next struct sym_fns */
2120 _initialize_coffread ()
2122 add_symtab_fns(&coff_sym_fns);