1 /* Read coff symbol tables and convert to internal format, for GDB.
3 Copyright (C) 1987-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. */
25 #include "breakpoint.h"
30 /* Need to get C_VERSION and friends. FIXME, should be in internalcoff.h */
31 #include "coff-m88k.h"
32 #endif /* not TDESC */
37 #include "internalcoff.h" /* Internal format of COFF symbols in BFD */
38 #include "libcoff.h" /* FIXME secret internal data from BFD */
40 static void add_symbol_to_list ();
41 static void read_coff_symtab ();
42 static void patch_opaque_types ();
43 static struct type *decode_function_type ();
44 static struct type *decode_type ();
45 static struct type *decode_base_type ();
46 static struct type *read_enum_type ();
47 static struct type *read_struct_type ();
48 static void finish_block ();
49 static struct blockvector *make_blockvector ();
50 static struct symbol *process_coff_symbol ();
51 static int init_stringtab ();
52 static void free_stringtab ();
53 static char *getfilename ();
54 static char *getsymname ();
55 static int init_lineno ();
56 static void enter_linenos ();
57 static void read_one_sym ();
61 /* To be an sdb debug type, type must have at least a basic or primary
62 derived type. Using this rather than checking against T_NULL is
63 said to prevent core dumps if we try to operate on Michael Bloom
66 #define SDB_TYPE(type) (BTYPE(type) | (type & N_TMASK))
69 * Convert from an sdb register number to an internal gdb register number.
70 * This should be defined in tm.h, if REGISTER_NAMES is not set up
71 * to map one to one onto the sdb register numbers.
73 #ifndef SDB_REG_TO_REGNUM
74 # define SDB_REG_TO_REGNUM(value) (value)
77 /* Name of source file whose symbol data we are now processing.
78 This comes from a symbol named ".file". */
80 static char *last_source_file;
82 /* Core address of start and end of text of current source file.
83 This comes from a ".text" symbol where x_nlinno > 0. */
85 static CORE_ADDR cur_src_start_addr;
86 static CORE_ADDR cur_src_end_addr;
88 /* Core address of the end of the first object file. */
89 static CORE_ADDR first_object_file_end;
91 /* The addresses of the symbol table stream and number of symbols
92 of the object file we are reading (as copied into core). */
94 static FILE *nlist_stream_global;
95 static int nlist_nsyms_global;
97 /* The index in the symbol table of the last coff symbol that was processed. */
101 /* Vector of types defined so far, indexed by their coff symnum. */
103 static struct type **type_vector;
105 /* Number of elements allocated for type_vector currently. */
107 static int type_vector_length;
109 /* Vector of line number information. */
111 static struct linetable *line_vector;
113 /* Index of next entry to go in line_vector_index. */
115 static int line_vector_index;
117 /* Last line number recorded in the line vector. */
119 static int prev_line_number;
121 /* Number of elements allocated for line_vector currently. */
123 static int line_vector_length;
125 /* Pointers to scratch storage, used for reading raw symbols and auxents. */
127 static char *temp_sym;
128 static char *temp_aux;
130 /* Local variables that hold the shift and mask values for the
131 COFF file that we are currently reading. These come back to us
132 from BFD, and are referenced by their macro names, as well as
133 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
134 macros from ../internalcoff.h . */
136 static unsigned local_n_btmask;
137 static unsigned local_n_btshft;
138 static unsigned local_n_tmask;
139 static unsigned local_n_tshift;
141 #define N_BTMASK local_n_btmask
142 #define N_BTSHFT local_n_btshft
143 #define N_TMASK local_n_tmask
144 #define N_TSHIFT local_n_tshift
146 /* Local variables that hold the sizes in the file of various COFF structures.
147 (We only need to know this to read them from the file -- BFD will then
148 translate the data in them, into `internal_xxx' structs in the right
149 byte order, alignment, etc.) */
151 static unsigned local_linesz;
152 static unsigned local_symesz;
153 static unsigned local_auxesz;
159 int int_sem_val = 's' << 24 | 'e' << 16 | 'm' << 8 | '.';
161 int last_coffsem = 2;
163 /* This isn't used currently. */
164 int last_coffsyn = 0;
166 int debug_info = 0; /*used by tdesc */
167 extern dc_dcontext_t tdesc_handle;
168 extern int safe_to_init_tdesc_context;
171 /* Chain of typedefs of pointers to empty struct/union types.
172 They are chained thru the SYMBOL_VALUE_CHAIN. */
175 static struct symbol *opaque_type_chain[HASHSIZE];
177 /* Record the symbols defined for each context in a list.
178 We don't create a struct block for the context until we
179 know how long to make it. */
183 struct pending *next;
184 struct symbol *symbol;
187 /* Here are the three lists that symbols are put on. */
189 struct pending *file_symbols; /* static at top level, and types */
191 struct pending *global_symbols; /* global functions and variables */
193 struct pending *local_symbols; /* everything local to lexical context */
195 /* List of unclosed lexical contexts
196 (that will become blocks, eventually). */
200 struct context_stack *next;
201 struct pending *locals;
202 struct pending_block *old_blocks;
204 CORE_ADDR start_addr;
208 struct context_stack *context_stack;
210 /* Nonzero if within a function (so symbols should be local,
211 if nothing says specifically). */
216 /* The type of the function we are currently reading in. This is
217 used by define_symbol to record the type of arguments to a function. */
219 struct type *in_function_type;
222 /* List of blocks already made (lexical contexts already closed).
223 This is used at the end to make the blockvector. */
227 struct pending_block *next;
231 struct pending_block *pending_blocks;
233 extern CORE_ADDR startup_file_start; /* From blockframe.c */
234 extern CORE_ADDR startup_file_end; /* From blockframe.c */
236 /* Complaints about various problems in the file being read */
238 struct complaint ef_complaint =
239 {"Unmatched .ef symbol(s) ignored starting at symnum %d", 0, 0};
241 struct complaint no_aux_complaint =
242 {"symbol %d without one aux entry", 0, 0};
244 struct complaint lineno_complaint =
245 {"Line number pointer %d lower than start of line numbers", 0, 0};
248 /* Look up a coff type-number index. Return the address of the slot
249 where the type for that index is stored.
250 The type-number is in INDEX.
252 This can be used for finding the type associated with that index
253 or for associating a new type with the index. */
255 static struct type **
256 coff_lookup_type (index)
259 if (index >= type_vector_length)
261 int old_vector_length = type_vector_length;
263 type_vector_length *= 2;
264 if (type_vector_length < index) {
265 type_vector_length = index * 2;
267 type_vector = (struct type **)
268 xrealloc (type_vector, type_vector_length * sizeof (struct type *));
269 bzero (&type_vector[old_vector_length],
270 (type_vector_length - old_vector_length) * sizeof(struct type *));
272 return &type_vector[index];
275 /* Make sure there is a type allocated for type number index
276 and return the type object.
277 This can create an empty (zeroed) type object. */
280 coff_alloc_type (index)
283 register struct type **type_addr = coff_lookup_type (index);
284 register struct type *type = *type_addr;
286 /* If we are referring to a type not known at all yet,
287 allocate an empty type for it.
288 We will fill it in later if we find out how. */
291 type = (struct type *) obstack_alloc (symbol_obstack,
292 sizeof (struct type));
293 bzero (type, sizeof (struct type));
294 TYPE_VPTR_FIELDNO (type) = -1;
300 /* maintain the lists of symbols and blocks */
302 /* Add a symbol to one of the lists of symbols. */
304 add_symbol_to_list (symbol, listhead)
305 struct symbol *symbol;
306 struct pending **listhead;
308 register struct pending *link
309 = (struct pending *) xmalloc (sizeof (struct pending));
311 link->next = *listhead;
312 link->symbol = symbol;
316 /* Take one of the lists of symbols and make a block from it.
317 Put the block on the list of pending blocks. */
320 finish_block (symbol, listhead, old_blocks, start, end)
321 struct symbol *symbol;
322 struct pending **listhead;
323 struct pending_block *old_blocks;
324 CORE_ADDR start, end;
326 register struct pending *next, *next1;
327 register struct block *block;
328 register struct pending_block *pblock;
329 struct pending_block *opblock;
332 /* Count the length of the list of symbols. */
334 for (next = *listhead, i = 0; next; next = next->next, i++);
336 block = (struct block *)
337 obstack_alloc (symbol_obstack, sizeof (struct block) + (i - 1) * sizeof (struct symbol *));
339 /* Copy the symbols into the block. */
341 BLOCK_NSYMS (block) = i;
342 for (next = *listhead; next; next = next->next)
343 BLOCK_SYM (block, --i) = next->symbol;
345 BLOCK_START (block) = start;
346 BLOCK_END (block) = end;
347 BLOCK_SUPERBLOCK (block) = 0; /* Filled in when containing block is made */
349 /* Put the block in as the value of the symbol that names it. */
353 SYMBOL_BLOCK_VALUE (symbol) = block;
354 BLOCK_FUNCTION (block) = symbol;
357 BLOCK_FUNCTION (block) = 0;
359 /* Now free the links of the list, and empty the list. */
361 for (next = *listhead; next; next = next1)
368 /* Install this block as the superblock
369 of all blocks made since the start of this scope
370 that don't have superblocks yet. */
373 for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next)
375 if (BLOCK_SUPERBLOCK (pblock->block) == 0)
376 BLOCK_SUPERBLOCK (pblock->block) = block;
380 /* Record this block on the list of all blocks in the file.
381 Put it after opblock, or at the beginning if opblock is 0.
382 This puts the block in the list after all its subblocks. */
384 pblock = (struct pending_block *) xmalloc (sizeof (struct pending_block));
385 pblock->block = block;
388 pblock->next = opblock->next;
389 opblock->next = pblock;
393 pblock->next = pending_blocks;
394 pending_blocks = pblock;
398 static struct blockvector *
401 register struct pending_block *next, *next1;
402 register struct blockvector *blockvector;
405 /* Count the length of the list of blocks. */
407 for (next = pending_blocks, i = 0; next; next = next->next, i++);
409 blockvector = (struct blockvector *)
410 obstack_alloc (symbol_obstack, sizeof (struct blockvector) + (i - 1) * sizeof (struct block *));
412 /* Copy the blocks into the blockvector.
413 This is done in reverse order, which happens to put
414 the blocks into the proper order (ascending starting address).
415 finish_block has hair to insert each block into the list
416 after its subblocks in order to make sure this is true. */
418 BLOCKVECTOR_NBLOCKS (blockvector) = i;
419 for (next = pending_blocks; next; next = next->next)
420 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
422 /* Now free the links of the list, and empty the list. */
424 for (next = pending_blocks; next; next = next1)
434 /* Manage the vector of line numbers. */
437 record_line (line, pc)
441 struct linetable_entry *e;
442 /* Make sure line vector is big enough. */
444 if (line_vector_index + 2 >= line_vector_length)
446 line_vector_length *= 2;
447 line_vector = (struct linetable *)
448 xrealloc (line_vector, sizeof (struct linetable)
449 + (line_vector_length
450 * sizeof (struct linetable_entry)));
453 e = line_vector->item + line_vector_index++;
454 e->line = line; e->pc = pc;
457 /* Start a new symtab for a new source file.
458 This is called when a COFF ".file" symbol is seen;
459 it indicates the start of data for one original source file. */
468 last_source_file = 0;
472 /* This isn't used currently. */
477 /* Initialize the source file line number information for this file. */
479 if (line_vector) /* Unlikely, but maybe possible? */
481 line_vector_index = 0;
482 line_vector_length = 1000;
483 prev_line_number = -2; /* Force first line number to be explicit */
484 line_vector = (struct linetable *)
485 xmalloc (sizeof (struct linetable)
486 + line_vector_length * sizeof (struct linetable_entry));
489 /* Save the vital information from when starting to read a file,
490 for use when closing off the current file.
491 NAME is the file name the symbols came from, START_ADDR is the first
492 text address for the file, and SIZE is the number of bytes of text. */
495 complete_symtab (name, start_addr, size)
497 CORE_ADDR start_addr;
500 last_source_file = savestring (name, strlen (name));
501 cur_src_start_addr = start_addr;
502 cur_src_end_addr = start_addr + size;
504 if (entry_point < cur_src_end_addr
505 && entry_point >= cur_src_start_addr)
507 startup_file_start = cur_src_start_addr;
508 startup_file_end = cur_src_end_addr;
512 /* Finish the symbol definitions for one main source file,
513 close off all the lexical contexts for that file
514 (creating struct block's for them), then make the
515 struct symtab for that file and put it in the list of all such. */
519 struct objfile *objfile;
521 register struct symtab *symtab;
522 register struct context_stack *cstk;
523 register struct blockvector *blockvector;
524 register struct linetable *lv;
526 /* Finish the lexical context of the last function in the file. */
530 cstk = context_stack;
532 /* Make a block for the local symbols within. */
533 finish_block (cstk->name, &local_symbols, cstk->old_blocks,
534 cstk->start_addr, cur_src_end_addr);
538 /* Ignore a file that has no functions with real debugging info. */
539 if (pending_blocks == 0 && file_symbols == 0 && global_symbols == 0)
543 line_vector_length = -1;
544 last_source_file = 0;
548 /* Create the two top-level blocks for this file (STATIC_BLOCK and
550 finish_block (0, &file_symbols, 0, cur_src_start_addr, cur_src_end_addr);
551 finish_block (0, &global_symbols, 0, cur_src_start_addr, cur_src_end_addr);
553 /* Create the blockvector that points to all the file's blocks. */
554 blockvector = make_blockvector ();
556 /* Now create the symtab object for this source file. */
557 symtab = allocate_symtab (last_source_file, objfile);
559 /* Fill in its components. */
560 symtab->blockvector = blockvector;
561 symtab->free_code = free_linetable;
562 symtab->free_ptr = 0;
563 symtab->filename = last_source_file;
564 symtab->dirname = NULL;
566 lv->nitems = line_vector_index;
567 symtab->linetable = (struct linetable *)
568 xrealloc (lv, (sizeof (struct linetable)
569 + lv->nitems * sizeof (struct linetable_entry)));
572 symtab->coffsem = last_coffsem;
574 /* This isn't used currently. Besides, if this is really about "syntax",
575 it shouldn't need to stick around past symbol read-in time. */
576 symtab->coffsyn = last_coffsyn;
580 free_named_symtabs (symtab->filename);
582 /* Link the new symtab into the list of such. */
583 symtab->next = symtab_list;
584 symtab_list = symtab;
586 /* Reinitialize for beginning of new file. */
588 line_vector_length = -1;
589 last_source_file = 0;
593 record_misc_function (name, address)
598 /* We don't want TDESC entry points on the misc_function_vector */
599 if (name[0] == '@') return;
601 /* mf_text isn't true, but apparently COFF doesn't tell us what it really
602 is, so this guess is more useful than mf_unknown. */
603 prim_record_misc_function (savestring (name, strlen (name)),
608 /* coff_symfile_init ()
609 is the coff-specific initialization routine for reading symbols.
610 It is passed a struct sym_fns which contains, among other things,
611 the BFD for the file whose symbols are being read, and a slot for
612 a pointer to "private data" which we fill with cookies and other
613 treats for coff_symfile_read ().
615 We will only be called if this is a COFF or COFF-like file.
616 BFD handles figuring out the format of the file, and code in symtab.c
617 uses BFD's determination to vector to us.
619 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
621 struct coff_symfile_info {
622 file_ptr min_lineno_offset; /* Where in file lowest line#s are */
623 file_ptr max_lineno_offset; /* 1+last byte of line#s in file */
626 static int text_bfd_scnum;
629 coff_symfile_init (sf)
633 bfd *abfd = sf->sym_bfd;
635 /* Allocate struct to keep track of the symfile */
636 /* FIXME memory leak */
637 sf->sym_private = xmalloc (sizeof (struct coff_symfile_info));
640 safe_to_init_tdesc_context = 0;
643 /* Save startup file's range of PC addresses to help blockframe.c
644 decide where the bottom of the stack is. */
645 if (bfd_get_file_flags (abfd) & EXEC_P)
647 /* Executable file -- record its entry point so we'll recognize
648 the startup file because it contains the entry point. */
649 entry_point = bfd_get_start_address (abfd);
653 /* Examination of non-executable.o files. Short-circuit this stuff. */
654 /* ~0 will not be in any file, we hope. */
656 /* set the startup file to be an empty range. */
657 startup_file_start = 0;
658 startup_file_end = 0;
660 /* Save the section number for the text section */
661 if (section = bfd_get_section_by_name(abfd,".text"))
662 text_bfd_scnum = section->index;
667 /* This function is called for every section; it finds the outer limits
668 of the line table (minimum and maximum file offset) so that the
669 mainline code can read the whole thing for efficiency. */
673 find_linenos (abfd, asect, vpinfo)
678 struct coff_symfile_info *info;
680 file_ptr offset, maxoff;
682 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
683 count = asect->lineno_count;
688 size = count * local_linesz;
690 info = (struct coff_symfile_info *)vpinfo;
691 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
692 offset = asect->line_filepos;
695 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
696 info->min_lineno_offset = offset;
698 maxoff = offset + size;
699 if (maxoff > info->max_lineno_offset)
700 info->max_lineno_offset = maxoff;
702 /* While we're at it, find the debug_info. It's in the s_relptr
703 (or, in BFD-speak, rel_filepos) of the text segment section header. */
704 if (strcmp (bfd_section_name (abfd, asect), ".text") == 0)
706 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
707 debug_info = asect->rel_filepos;
711 dc_terminate (tdesc_handle);
719 /* The BFD for this file -- only good while we're actively reading
720 symbols into a psymtab or a symtab. */
722 static bfd *symfile_bfd;
724 /* Read a symbol file, after initialization by coff_symfile_init. */
725 /* FIXME! Addr and Mainline are not used yet -- this will not work for
726 shared libraries or add_file! */
730 coff_symfile_read (sf, addr, mainline)
735 struct coff_symfile_info *info = (struct coff_symfile_info *)sf->sym_private;
736 bfd *abfd = sf->objfile->obfd;
737 coff_data_type *cdata = coff_data (abfd);
738 char *name = bfd_get_filename (abfd);
743 int stringtab_offset;
745 symfile_bfd = abfd; /* Kludge for swap routines */
747 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
748 desc = fileno ((FILE *)(abfd->iostream)); /* File descriptor */
749 num_symbols = bfd_get_symcount (abfd); /* How many syms */
750 symtab_offset = cdata->sym_filepos; /* Symbol table file offset */
751 stringtab_offset = symtab_offset + /* String table file offset */
752 num_symbols * cdata->local_symesz;
754 /* Set a few file-statics that give us specific information about
755 the particular COFF file format we're reading. */
756 local_linesz = cdata->local_linesz;
757 local_n_btmask = cdata->local_n_btmask;
758 local_n_btshft = cdata->local_n_btshft;
759 local_n_tmask = cdata->local_n_tmask;
760 local_n_tshift = cdata->local_n_tshift;
761 local_linesz = cdata->local_linesz;
762 local_symesz = cdata->local_symesz;
763 local_auxesz = cdata->local_auxesz;
765 /* Allocate space for raw symbol and aux entries, based on their
766 space requirements as reported by BFD. */
767 temp_sym = (char *) xmalloc
768 (cdata->local_symesz + cdata->local_auxesz);
769 temp_aux = temp_sym + cdata->local_symesz;
770 make_cleanup (free_current_contents, &temp_sym);
773 /* Read the line number table, all at once. */
774 info->min_lineno_offset = 0;
775 info->max_lineno_offset = 0;
776 bfd_map_over_sections (abfd, find_linenos, info);
778 val = init_lineno (desc, info->min_lineno_offset,
779 info->max_lineno_offset - info->min_lineno_offset);
781 error ("\"%s\": error reading line numbers\n", name);
783 /* Now read the string table, all at once. */
785 val = init_stringtab (desc, stringtab_offset);
787 error ("\"%s\": can't get string table", name);
788 make_cleanup (free_stringtab, 0);
790 /* Position to read the symbol table. Do not read it all at once. */
791 val = lseek (desc, (long)symtab_offset, 0);
793 perror_with_name (name);
795 init_misc_bunches ();
796 make_cleanup (discard_misc_bunches, 0);
798 /* Now that the executable file is positioned at symbol table,
799 process it and define symbols accordingly. */
801 read_coff_symtab (desc, num_symbols, sf->objfile);
803 patch_opaque_types ();
805 /* Sort symbols alphabetically within each block. */
807 sort_all_symtab_syms ();
809 /* Go over the misc symbol bunches and install them in vector. */
811 condense_misc_bunches (!mainline);
813 /* Make a default for file to list. */
815 select_source_symtab (0); /* FIXME, this might be too slow, see dbxread */
824 /* Simplified internal version of coff symbol table information */
828 int c_symnum; /* symbol number of this entry */
829 int c_naux; /* 0 if syment only, 1 if syment + auxent, etc */
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 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 nlist_stream_global = stream;
883 nlist_nsyms_global = nsyms;
884 last_source_file = 0;
885 bzero (opaque_type_chain, sizeof opaque_type_chain);
887 if (type_vector) /* Get rid of previous one */
889 type_vector_length = 160;
890 type_vector = (struct type **)
891 xmalloc (type_vector_length * sizeof (struct type *));
892 bzero (type_vector, type_vector_length * sizeof (struct type *));
897 while (symnum < nsyms)
899 QUIT; /* Make this command interruptable. */
900 read_one_sym (cs, &main_sym, &main_aux);
903 temp_sem_val = cs->c_name[0] << 24 | cs->c_name[1] << 16 |
904 cs->c_name[2] << 8 | cs->c_name[3];
905 if (int_sem_val == temp_sem_val)
906 last_coffsem = (int) strtol (cs->c_name+4, (char **) NULL, 10);
909 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
911 if (last_source_file)
912 end_symtab (objfile);
915 complete_symtab ("_globals_", 0, first_object_file_end);
916 /* done with all files, everything from here on out is globals */
919 /* Special case for file with type declarations only, no text. */
920 if (!last_source_file && SDB_TYPE (cs->c_type)
921 && cs->c_secnum == N_DEBUG)
922 complete_symtab (filestring, 0, 0);
924 /* Typedefs should not be treated as symbol definitions. */
925 if (ISFCN (cs->c_type) && cs->c_sclass != C_TPDEF)
927 /* record as misc function. if we get '.bf' next,
928 * then we undo this step
930 record_misc_function (cs->c_name, cs->c_value);
932 fcn_line_ptr = main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
933 fcn_start_addr = cs->c_value;
935 fcn_sym_saved = main_sym;
936 fcn_aux_saved = main_aux;
940 switch (cs->c_sclass)
949 printf ("Bad n_sclass = %d\n", cs->c_sclass);
954 * c_value field contains symnum of next .file entry in table
955 * or symnum of first global after last .file.
957 next_file_symnum = cs->c_value;
958 filestring = getfilename (&main_aux);
960 * Complete symbol table for last object file
961 * containing debugging information.
963 if (last_source_file)
965 end_symtab (objfile);
972 if (cs->c_name[0] == '.') {
973 if (strcmp (cs->c_name, ".text") == 0) {
974 /* FIXME: don't wire in ".text" as section name
976 if (++num_object_files == 1) {
977 /* last address of startup file */
978 first_object_file_end = cs->c_value +
979 main_aux.x_scn.x_scnlen;
981 /* Check for in_source_file deals with case of
982 a file with debugging symbols
983 followed by a later file with no symbols. */
985 complete_symtab (filestring, cs->c_value,
986 main_aux.x_scn.x_scnlen);
989 /* flush rest of '.' symbols */
992 else if (!SDB_TYPE (cs->c_type)
993 && cs->c_name[0] == 'L'
994 && (strncmp (cs->c_name, "LI%", 3) == 0
995 || strncmp (cs->c_name, "LF%", 3) == 0
996 || strncmp (cs->c_name,"LC%",3) == 0
997 || strncmp (cs->c_name,"LP%",3) == 0
998 || strncmp (cs->c_name,"LPB%",4) == 0
999 || strncmp (cs->c_name,"LBB%",4) == 0
1000 || strncmp (cs->c_name,"LBE%",4) == 0
1001 || strncmp (cs->c_name,"LPBX%",5) == 0))
1002 /* At least on a 3b1, gcc generates swbeg and string labels
1003 that look like this. Ignore them. */
1005 /* fall in for static symbols that don't start with '.' */
1007 if (!SDB_TYPE (cs->c_type)) {
1008 /* FIXME: This is BOGUS Will Robinson!
1009 Coff should provide the SEC_CODE flag for executable sections,
1010 then if we could look up sections by section number we
1011 could see if the flags indicate SEC_CODE. If so, then
1012 record this symbol as a miscellaneous function. But why
1013 are absolute syms recorded as functions, anyway? */
1014 if (cs->c_secnum <= text_bfd_scnum+1) {/* text or abs */
1015 record_misc_function (cs->c_name, cs->c_value);
1021 (void) process_coff_symbol (cs, &main_aux);
1025 if (strcmp (cs->c_name, ".bf") == 0)
1027 within_function = 1;
1029 /* value contains address of first non-init type code */
1030 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
1031 contains line number of '{' } */
1032 if (cs->c_naux != 1)
1033 complain (no_aux_complaint, cs->c_symnum);
1034 fcn_first_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
1036 new = (struct context_stack *)
1037 xmalloc (sizeof (struct context_stack));
1038 new->depth = depth = 0;
1040 context_stack = new;
1042 new->old_blocks = pending_blocks;
1043 new->start_addr = fcn_start_addr;
1044 fcn_cs_saved.c_name = getsymname (&fcn_sym_saved);
1045 new->name = process_coff_symbol (&fcn_cs_saved,
1048 else if (strcmp (cs->c_name, ".ef") == 0)
1050 /* the value of .ef is the address of epilogue code;
1051 * not useful for gdb
1053 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1054 contains number of lines to '}' */
1055 new = context_stack;
1058 complain (&ef_complaint, cs->c_symnum);
1059 within_function = 0;
1062 if (cs->c_naux != 1) {
1063 complain (no_aux_complaint, cs->c_symnum);
1064 fcn_last_line = 0x7FFFFFFF;
1066 fcn_last_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
1068 enter_linenos (fcn_line_ptr, fcn_first_line, fcn_last_line);
1070 finish_block (new->name, &local_symbols, new->old_blocks,
1072 #if defined (FUNCTION_EPILOGUE_SIZE)
1073 /* This macro should be defined only on
1075 fcn_aux_saved.x_sym.x_misc.x_fsize
1076 field is always zero.
1077 So use the .bf record information that
1078 points to the epilogue and add the size
1080 cs->c_value + FUNCTION_EPILOGUE_SIZE
1082 fcn_cs_saved.c_value +
1083 fcn_aux_saved.x_sym.x_misc.x_fsize
1087 within_function = 0;
1093 if (strcmp (cs->c_name, ".bb") == 0)
1095 new = (struct context_stack *)
1096 xmalloc (sizeof (struct context_stack));
1099 new->next = context_stack;
1100 context_stack = new;
1101 new->locals = local_symbols;
1102 new->old_blocks = pending_blocks;
1103 new->start_addr = cs->c_value;
1107 else if (strcmp (cs->c_name, ".eb") == 0)
1109 new = context_stack;
1110 if (new == 0 || depth != new->depth)
1111 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1113 if (local_symbols && context_stack->next)
1115 /* Make a block for the local symbols within. */
1116 finish_block (0, &local_symbols, new->old_blocks,
1117 new->start_addr, cs->c_value);
1120 local_symbols = new->locals;
1121 context_stack = new->next;
1128 /* This isn't used currently. */
1129 if (strcmp (cs->c_name, ".coffsyn") == 0)
1130 last_coffsyn = cs->c_value;
1133 if ((strcmp (cs->c_name, ".coffsem") == 0) &&
1135 last_coffsem = cs->c_value;
1141 if ((strcmp (cs->c_name, ".coffsem") == 0) &&
1143 last_coffsem = cs->c_value;
1146 (void) process_coff_symbol (cs, &main_aux);
1151 if (last_source_file)
1152 end_symtab (objfile);
1154 discard_cleanups (old_chain);
1157 /* Routines for reading headers and symbols from executable. */
1160 /* Move these XXXMAGIC symbol defns into BFD! */
1162 /* Read COFF file header, check magic number,
1163 and return number of symbols. */
1164 read_file_hdr (chan, file_hdr)
1168 lseek (chan, 0L, 0);
1169 if (myread (chan, (char *)file_hdr, FILHSZ) < 0)
1172 switch (file_hdr->f_magic)
1187 #if defined (MC68KWRMAGIC) \
1188 && (!defined (MC68MAGIC) || MC68KWRMAGIC != MC68MAGIC)
1202 case I960ROMAGIC: /* Intel 960 */
1205 case I960RWMAGIC: /* Intel 960 */
1207 return file_hdr->f_nsyms;
1211 if (BADMAG(file_hdr))
1214 return file_hdr->f_nsyms;
1222 /* Read the next symbol, swap it, and return it in both internal_syment
1223 form, and coff_symbol form. Also return its first auxent, if any,
1224 in internal_auxent form, and skip any other auxents. */
1227 read_one_sym (cs, sym, aux)
1228 register struct coff_symbol *cs;
1229 register struct internal_syment *sym;
1230 register union internal_auxent *aux;
1234 cs->c_symnum = symnum;
1235 fread (temp_sym, local_symesz, 1, nlist_stream_global);
1236 bfd_coff_swap_sym_in (symfile_bfd, temp_sym, (char *)sym);
1237 cs->c_naux = sym->n_numaux & 0xff;
1238 if (cs->c_naux >= 1)
1240 fread (temp_aux, local_auxesz, 1, nlist_stream_global);
1241 bfd_coff_swap_aux_in (symfile_bfd, temp_aux, sym->n_type, sym->n_sclass,
1243 /* If more than one aux entry, read past it (only the first aux
1245 for (i = 1; i < cs->c_naux; i++)
1246 fread (temp_aux, local_auxesz, 1, nlist_stream_global);
1248 cs->c_name = getsymname (sym);
1249 cs->c_value = sym->n_value;
1250 cs->c_sclass = (sym->n_sclass & 0xff);
1251 cs->c_secnum = sym->n_scnum;
1252 cs->c_type = (unsigned) sym->n_type;
1253 if (!SDB_TYPE (cs->c_type))
1256 symnum += 1 + cs->c_naux;
1259 /* Support for string table handling */
1261 static char *stringtab = NULL;
1264 init_stringtab (chan, offset)
1270 unsigned char lengthbuf[4];
1278 if (lseek (chan, offset, 0) < 0)
1281 val = myread (chan, (char *)lengthbuf, sizeof lengthbuf);
1282 length = bfd_h_get_32 (symfile_bfd, lengthbuf);
1284 /* If no string table is needed, then the file may end immediately
1285 after the symbols. Just return with `stringtab' set to null. */
1286 if (val != sizeof length || length < sizeof length)
1289 stringtab = (char *) xmalloc (length);
1290 if (stringtab == NULL)
1293 bcopy (&length, stringtab, sizeof length);
1294 if (length == sizeof length) /* Empty table -- just the count */
1297 val = myread (chan, stringtab + sizeof length, length - sizeof length);
1298 if (val != length - sizeof length || stringtab[length - 1] != '\0')
1313 getsymname (symbol_entry)
1314 struct internal_syment *symbol_entry;
1316 static char buffer[SYMNMLEN+1];
1319 if (symbol_entry->_n._n_n._n_zeroes == 0)
1321 result = stringtab + symbol_entry->_n._n_n._n_offset;
1325 strncpy (buffer, symbol_entry->_n._n_name, SYMNMLEN);
1326 buffer[SYMNMLEN] = '\0';
1333 getfilename (aux_entry)
1334 union internal_auxent *aux_entry;
1336 static char buffer[BUFSIZ];
1337 register char *temp;
1339 extern char *rindex ();
1341 #ifndef COFF_NO_LONG_FILE_NAMES
1342 #if defined (x_zeroes)
1344 if (aux_entry->x_zeroes == 0)
1345 strcpy (buffer, stringtab + aux_entry->x_offset);
1346 #else /* no x_zeroes */
1347 if (aux_entry->x_file.x_n.x_zeroes == 0)
1348 strcpy (buffer, stringtab + aux_entry->x_file.x_n.x_offset);
1349 #endif /* no x_zeroes */
1351 #endif /* COFF_NO_LONG_FILE_NAMES */
1353 #if defined (x_name)
1355 strncpy (buffer, aux_entry->x_name, FILNMLEN);
1357 strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
1359 buffer[FILNMLEN] = '\0';
1362 if ((temp = rindex (result, '/')) != NULL)
1367 /* Support for line number handling */
1368 static char *linetab = NULL;
1369 static long linetab_offset;
1370 static unsigned long linetab_size;
1372 /* Read in all the line numbers for fast lookups later. Leave them in
1373 external (unswapped) format in memory; we'll swap them as we enter
1374 them into GDB's data structures. */
1377 init_lineno (chan, offset, size)
1384 linetab_offset = offset;
1385 linetab_size = size;
1390 if (lseek (chan, offset, 0) < 0)
1393 /* Allocate the desired table, plus a sentinel */
1394 linetab = (char *) xmalloc (size + local_linesz);
1396 val = myread (chan, linetab, size);
1400 /* Terminate it with an all-zero sentinel record */
1401 bzero (linetab + size, local_linesz);
1403 make_cleanup (free, linetab); /* Be sure it gets de-allocated. */
1407 #if !defined (L_LNNO32)
1408 #define L_LNNO32(lp) ((lp)->l_lnno)
1412 enter_linenos (file_offset, first_line, last_line)
1414 register int first_line;
1415 register int last_line;
1417 register char *rawptr;
1418 struct internal_lineno lptr;
1420 if (file_offset < linetab_offset)
1422 complain (&lineno_complaint, file_offset);
1423 if (file_offset > linetab_size) /* Too big to be an offset? */
1425 file_offset += linetab_offset; /* Try reading at that linetab offset */
1428 rawptr = &linetab[file_offset - linetab_offset];
1430 /* skip first line entry for each function */
1431 rawptr += local_linesz;
1432 /* line numbers start at one for the first line of the function */
1436 bfd_coff_swap_lineno_in (symfile_bfd, rawptr, &lptr);
1437 rawptr += local_linesz;
1438 /* The next function, or the sentinel, will have L_LNNO32 zero; we exit. */
1439 if (L_LNNO32 (&lptr) && L_LNNO32 (&lptr) <= last_line)
1440 record_line (first_line + L_LNNO32 (&lptr), lptr.l_addr.l_paddr);
1450 register char *p = name;
1451 register int total = p[0];
1464 return total % HASHSIZE;
1468 patch_type (type, real_type)
1470 struct type *real_type;
1472 register struct type *target = TYPE_TARGET_TYPE (type);
1473 register struct type *real_target = TYPE_TARGET_TYPE (real_type);
1474 int field_size = TYPE_NFIELDS (real_target) * sizeof (struct field);
1476 TYPE_LENGTH (target) = TYPE_LENGTH (real_target);
1477 TYPE_NFIELDS (target) = TYPE_NFIELDS (real_target);
1478 TYPE_FIELDS (target) = (struct field *)
1479 obstack_alloc (symbol_obstack, field_size);
1481 bcopy (TYPE_FIELDS (real_target), TYPE_FIELDS (target), field_size);
1483 if (TYPE_NAME (real_target))
1485 if (TYPE_NAME (target))
1486 free (TYPE_NAME (target));
1487 TYPE_NAME (target) = concat (TYPE_NAME (real_target), NULL);
1491 /* Patch up all appropriate typdef symbols in the opaque_type_chains
1492 so that they can be used to print out opaque data structures properly */
1495 patch_opaque_types ()
1499 /* Look at each symbol in the per-file block of each symtab. */
1500 for (s = symtab_list; s; s = s->next)
1502 register struct block *b;
1505 /* Go through the per-file symbols only */
1506 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
1507 for (i = BLOCK_NSYMS (b) - 1; i >= 0; i--)
1509 register struct symbol *real_sym;
1511 /* Find completed typedefs to use to fix opaque ones.
1512 Remove syms from the chain when their types are stored,
1513 but search the whole chain, as there may be several syms
1514 from different files with the same name. */
1515 real_sym = BLOCK_SYM (b, i);
1516 if (SYMBOL_CLASS (real_sym) == LOC_TYPEDEF &&
1517 SYMBOL_NAMESPACE (real_sym) == VAR_NAMESPACE &&
1518 TYPE_CODE (SYMBOL_TYPE (real_sym)) == TYPE_CODE_PTR &&
1519 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym))) != 0)
1521 register char *name = SYMBOL_NAME (real_sym);
1522 register int hash = hashname (name);
1523 register struct symbol *sym, *prev;
1526 for (sym = opaque_type_chain[hash]; sym;)
1528 if (name[0] == SYMBOL_NAME (sym)[0] &&
1529 !strcmp (name + 1, SYMBOL_NAME (sym) + 1))
1532 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
1534 opaque_type_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
1536 patch_type (SYMBOL_TYPE (sym), SYMBOL_TYPE (real_sym));
1539 sym = SYMBOL_VALUE_CHAIN (prev);
1541 sym = opaque_type_chain[hash];
1546 sym = SYMBOL_VALUE_CHAIN (sym);
1554 #if defined (clipper)
1555 #define BELIEVE_PCC_PROMOTION 1
1558 static struct symbol *
1559 process_coff_symbol (cs, aux)
1560 register struct coff_symbol *cs;
1561 register union internal_auxent *aux;
1563 register struct symbol *sym
1564 = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
1566 #ifdef NAMES_HAVE_UNDERSCORE
1572 bzero (sym, sizeof (struct symbol));
1574 name = (name[0] == '_' ? name + offset : name);
1575 SYMBOL_NAME (sym) = obstack_copy0 (symbol_obstack, name, strlen (name));
1577 /* default assumptions */
1578 SYMBOL_VALUE (sym) = cs->c_value;
1579 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1581 if (ISFCN (cs->c_type))
1584 /* FIXME: This has NOT been tested. The DBX version has.. */
1585 /* Generate a template for the type of this function. The
1586 types of the arguments will be added as we read the symbol
1588 struct type *new = (struct type *)
1589 obstack_alloc (symbol_obstack, sizeof (struct type));
1591 bcopy(lookup_function_type (decode_function_type (cs, cs->c_type, aux)),
1592 new, sizeof(struct type));
1593 SYMBOL_TYPE (sym) = new;
1594 in_function_type = SYMBOL_TYPE(sym);
1597 lookup_function_type (decode_function_type (cs, cs->c_type, aux));
1600 SYMBOL_CLASS (sym) = LOC_BLOCK;
1601 if (cs->c_sclass == C_STAT)
1602 add_symbol_to_list (sym, &file_symbols);
1603 else if (cs->c_sclass == C_EXT)
1604 add_symbol_to_list (sym, &global_symbols);
1608 SYMBOL_TYPE (sym) = decode_type (cs, cs->c_type, aux);
1609 switch (cs->c_sclass)
1615 SYMBOL_CLASS (sym) = LOC_LOCAL;
1616 add_symbol_to_list (sym, &local_symbols);
1620 SYMBOL_CLASS (sym) = LOC_STATIC;
1621 SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
1622 add_symbol_to_list (sym, &global_symbols);
1626 SYMBOL_CLASS (sym) = LOC_STATIC;
1627 SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
1628 if (within_function) {
1629 /* Static symbol of local scope */
1630 add_symbol_to_list (sym, &local_symbols);
1633 /* Static symbol at top level of file */
1634 add_symbol_to_list (sym, &file_symbols);
1638 #ifdef C_GLBLREG /* AMD coff */
1642 SYMBOL_CLASS (sym) = LOC_REGISTER;
1643 SYMBOL_VALUE (sym) = SDB_REG_TO_REGNUM(cs->c_value);
1644 add_symbol_to_list (sym, &local_symbols);
1651 SYMBOL_CLASS (sym) = LOC_ARG;
1653 /* FIXME: This has not bee tested. */
1654 /* Add parameter to function. */
1655 add_param_to_type(&in_function_type,sym);
1657 add_symbol_to_list (sym, &local_symbols);
1658 #if !defined (BELIEVE_PCC_PROMOTION)
1659 /* If PCC says a parameter is a short or a char,
1660 it is really an int. */
1661 if (SYMBOL_TYPE (sym) == builtin_type_char
1662 || SYMBOL_TYPE (sym) == builtin_type_short)
1663 SYMBOL_TYPE (sym) = builtin_type_int;
1664 else if (SYMBOL_TYPE (sym) == builtin_type_unsigned_char
1665 || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
1666 SYMBOL_TYPE (sym) = builtin_type_unsigned_int;
1671 SYMBOL_CLASS (sym) = LOC_REGPARM;
1672 SYMBOL_VALUE (sym) = SDB_REG_TO_REGNUM(cs->c_value);
1673 add_symbol_to_list (sym, &local_symbols);
1674 #if !defined (BELIEVE_PCC_PROMOTION)
1675 /* If PCC says a parameter is a short or a char,
1676 it is really an int. */
1677 if (SYMBOL_TYPE (sym) == builtin_type_char
1678 || SYMBOL_TYPE (sym) == builtin_type_short)
1679 SYMBOL_TYPE (sym) = builtin_type_int;
1680 else if (SYMBOL_TYPE (sym) == builtin_type_unsigned_char
1681 || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
1682 SYMBOL_TYPE (sym) = builtin_type_unsigned_int;
1687 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1688 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1690 /* If type has no name, give it one */
1691 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
1692 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
1693 TYPE_NAME (SYMBOL_TYPE (sym))
1694 = concat (SYMBOL_NAME (sym), NULL);
1696 /* Keep track of any type which points to empty structured type,
1697 so it can be filled from a definition from another file */
1698 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR &&
1699 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym))) == 0)
1701 register int i = hashname (SYMBOL_NAME (sym));
1703 SYMBOL_VALUE_CHAIN (sym) = opaque_type_chain[i];
1704 opaque_type_chain[i] = sym;
1706 add_symbol_to_list (sym, &file_symbols);
1712 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1713 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1714 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
1715 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
1716 TYPE_NAME (SYMBOL_TYPE (sym))
1718 (cs->c_sclass == C_ENTAG
1720 : (cs->c_sclass == C_STRTAG
1721 ? "struct " : "union ")),
1722 SYMBOL_NAME (sym), NULL);
1723 add_symbol_to_list (sym, &file_symbols);
1733 /* Decode a coff type specifier;
1734 return the type that is meant. */
1738 decode_type (cs, c_type, aux)
1739 register struct coff_symbol *cs;
1740 unsigned int c_type;
1741 register union internal_auxent *aux;
1743 register struct type *type = 0;
1744 unsigned int new_c_type;
1746 if (c_type & ~N_BTMASK)
1748 new_c_type = DECREF (c_type);
1751 type = decode_type (cs, new_c_type, aux);
1752 type = lookup_pointer_type (type);
1754 else if (ISFCN (c_type))
1756 type = decode_type (cs, new_c_type, aux);
1757 type = lookup_function_type (type);
1759 else if (ISARY (c_type))
1762 register unsigned short *dim;
1763 struct type *base_type;
1765 /* Define an array type. */
1766 /* auxent refers to array, not base type */
1767 if (aux->x_sym.x_tagndx.l == 0)
1770 /* shift the indices down */
1771 dim = &aux->x_sym.x_fcnary.x_ary.x_dimen[0];
1774 for (i = 0; *dim && i < DIMNUM - 1; i++, dim++)
1778 type = (struct type *)
1779 obstack_alloc (symbol_obstack, sizeof (struct type));
1780 bzero (type, sizeof (struct type));
1782 base_type = decode_type (cs, new_c_type, aux);
1784 TYPE_CODE (type) = TYPE_CODE_ARRAY;
1785 TYPE_TARGET_TYPE (type) = base_type;
1786 TYPE_LENGTH (type) = n * TYPE_LENGTH (base_type);
1791 /* Reference to existing type */
1792 if (cs->c_naux > 0 && aux->x_sym.x_tagndx.l != 0)
1794 type = coff_alloc_type (aux->x_sym.x_tagndx.l);
1798 return decode_base_type (cs, BTYPE (c_type), aux);
1801 /* Decode a coff type specifier for function definition;
1802 return the type that the function returns. */
1806 decode_function_type (cs, c_type, aux)
1807 register struct coff_symbol *cs;
1808 unsigned int c_type;
1809 register union internal_auxent *aux;
1811 if (aux->x_sym.x_tagndx.l == 0)
1812 cs->c_naux = 0; /* auxent refers to function, not base type */
1814 return decode_type (cs, DECREF (c_type), aux);
1821 decode_base_type (cs, c_type, aux)
1822 register struct coff_symbol *cs;
1823 unsigned int c_type;
1824 register union internal_auxent *aux;
1831 /* shows up with "void (*foo)();" structure members */
1832 return builtin_type_void;
1835 /* DGUX actually defines both T_ARG and T_VOID to the same value. */
1838 /* Shows up in DGUX, I think. Not sure where. */
1839 return builtin_type_void; /* shouldn't show up here */
1845 /* Intel 960 COFF has this symbol and meaning. */
1846 return builtin_type_void;
1850 return builtin_type_char;
1853 return builtin_type_short;
1856 return builtin_type_int;
1859 return builtin_type_long;
1862 return builtin_type_float;
1865 return builtin_type_double;
1868 if (cs->c_naux != 1)
1870 /* anonymous structure type */
1871 type = coff_alloc_type (cs->c_symnum);
1872 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1873 TYPE_NAME (type) = concat ("struct ", "<opaque>", NULL);
1874 TYPE_LENGTH (type) = 0;
1875 TYPE_FIELDS (type) = 0;
1876 TYPE_NFIELDS (type) = 0;
1880 type = read_struct_type (cs->c_symnum,
1881 aux->x_sym.x_misc.x_lnsz.x_size,
1882 aux->x_sym.x_fcnary.x_fcn.x_endndx);
1887 if (cs->c_naux != 1)
1889 /* anonymous union type */
1890 type = coff_alloc_type (cs->c_symnum);
1891 TYPE_NAME (type) = concat ("union ", "<opaque>", NULL);
1892 TYPE_LENGTH (type) = 0;
1893 TYPE_FIELDS (type) = 0;
1894 TYPE_NFIELDS (type) = 0;
1898 type = read_struct_type (cs->c_symnum,
1899 aux->x_sym.x_misc.x_lnsz.x_size,
1900 aux->x_sym.x_fcnary.x_fcn.x_endndx);
1902 TYPE_CODE (type) = TYPE_CODE_UNION;
1906 return read_enum_type (cs->c_symnum,
1907 aux->x_sym.x_misc.x_lnsz.x_size,
1908 aux->x_sym.x_fcnary.x_fcn.x_endndx);
1911 /* shouldn't show up here */
1915 return builtin_type_unsigned_char;
1918 return builtin_type_unsigned_short;
1921 return builtin_type_unsigned_int;
1924 return builtin_type_unsigned_long;
1926 printf ("unexpected type %d at symnum %d\n", c_type, cs->c_symnum);
1927 return builtin_type_void;
1930 /* This page contains subroutines of read_type. */
1932 /* Read the description of a structure (or union type)
1933 and return an object describing the type. */
1935 static struct type *
1936 read_struct_type (index, length, lastsym)
1943 struct nextfield *next;
1947 register struct type *type;
1948 register struct nextfield *list = 0;
1949 struct nextfield *new;
1953 #ifdef NAMES_HAVE_UNDERSCORE
1958 struct coff_symbol member_sym;
1959 register struct coff_symbol *ms = &member_sym;
1960 struct internal_syment sub_sym;
1961 union internal_auxent sub_aux;
1964 type = coff_alloc_type (index);
1965 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1966 TYPE_LENGTH (type) = length;
1968 while (!done && symnum < lastsym && symnum < nlist_nsyms_global)
1970 read_one_sym (ms, &sub_sym, &sub_aux);
1972 name = (name[0] == '_' ? name + offset : name);
1974 switch (ms->c_sclass)
1979 /* Get space to record the next field's data. */
1980 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1984 /* Save the data. */
1985 list->field.name = savestring (name, strlen (name));
1986 list->field.type = decode_type (ms, ms->c_type, &sub_aux);
1987 list->field.bitpos = 8 * ms->c_value;
1988 list->field.bitsize = 0;
1994 /* Get space to record the next field's data. */
1995 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1999 /* Save the data. */
2000 list->field.name = savestring (name, strlen (name));
2001 list->field.type = decode_type (ms, ms->c_type, &sub_aux);
2002 list->field.bitpos = ms->c_value;
2003 list->field.bitsize = sub_aux.x_sym.x_misc.x_lnsz.x_size;
2012 /* Now create the vector of fields, and record how big it is. */
2014 TYPE_NFIELDS (type) = nfields;
2015 TYPE_FIELDS (type) = (struct field *)
2016 obstack_alloc (symbol_obstack, sizeof (struct field) * nfields);
2018 /* Copy the saved-up fields into the field vector. */
2020 for (n = nfields; list; list = list->next)
2021 TYPE_FIELD (type, --n) = list->field;
2026 /* Read a definition of an enumeration type,
2027 and create and return a suitable type object.
2028 Also defines the symbols that represent the values of the type. */
2029 /* Currently assumes it's sizeof (int) and doesn't use length. */
2032 static struct type *
2033 read_enum_type (index, length, lastsym)
2038 register struct symbol *sym;
2039 register struct type *type;
2042 struct pending **symlist;
2043 struct coff_symbol member_sym;
2044 register struct coff_symbol *ms = &member_sym;
2045 struct internal_syment sub_sym;
2046 union internal_auxent sub_aux;
2047 struct pending *osyms, *syms;
2050 #ifdef NAMES_HAVE_UNDERSCORE
2056 type = coff_alloc_type (index);
2057 if (within_function)
2058 symlist = &local_symbols;
2060 symlist = &file_symbols;
2063 while (!done && symnum < lastsym && symnum < nlist_nsyms_global)
2065 read_one_sym (ms, &sub_sym, &sub_aux);
2067 name = (name[0] == '_' ? name + offset : name);
2069 switch (ms->c_sclass)
2072 sym = (struct symbol *) xmalloc (sizeof (struct symbol));
2073 bzero (sym, sizeof (struct symbol));
2075 SYMBOL_NAME (sym) = savestring (name, strlen (name));
2076 SYMBOL_CLASS (sym) = LOC_CONST;
2077 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2078 SYMBOL_VALUE (sym) = ms->c_value;
2079 add_symbol_to_list (sym, symlist);
2084 /* Sometimes the linker (on 386/ix 2.0.2 at least) screws
2085 up the count of how many symbols to read. So stop
2092 /* Now fill in the fields of the type-structure. */
2094 /* FIXME: Should be sizeof (int) on target, not host. */
2095 TYPE_LENGTH (type) = sizeof (int);
2096 TYPE_CODE (type) = TYPE_CODE_ENUM;
2097 TYPE_NFIELDS (type) = nsyms;
2098 TYPE_FIELDS (type) = (struct field *)
2099 obstack_alloc (symbol_obstack, sizeof (struct field) * nsyms);
2101 /* Find the symbols for the values and put them into the type.
2102 The symbols can be found in the symlist that we put them on
2103 to cause them to be defined. osyms contains the old value
2104 of that symlist; everything up to there was defined by us. */
2106 for (syms = *symlist, n = nsyms; syms != osyms; syms = syms->next)
2108 SYMBOL_TYPE (syms->symbol) = type;
2109 TYPE_FIELD_NAME (type, --n) = SYMBOL_NAME (syms->symbol);
2110 TYPE_FIELD_VALUE (type, n) = 0;
2111 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (syms->symbol);
2112 TYPE_FIELD_BITSIZE (type, n) = 0;
2114 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2115 if(TYPE_NFIELDS(type) == 2 &&
2116 ((!strcmp(TYPE_FIELD_NAME(type,0),"TRUE") &&
2117 !strcmp(TYPE_FIELD_NAME(type,1),"FALSE")) ||
2118 (!strcmp(TYPE_FIELD_NAME(type,1),"TRUE") &&
2119 !strcmp(TYPE_FIELD_NAME(type,0),"FALSE"))))
2120 TYPE_CODE(type) = TYPE_CODE_BOOL;
2124 /* Register our ability to parse symbols for coff BFD files */
2126 static struct sym_fns coff_sym_fns =
2128 /* This assumes that 88kbcs implies TDESC and TDESC implies 88kbcs.
2129 If that's not true, this can be relaxed, but if it is true,
2130 it will just cause users grief if we try to read the wrong kind
2134 #else /* not TDESC */
2139 # endif /* not i386 */
2140 #endif /* not TDESC */
2141 coff_new_init, coff_symfile_init, coff_symfile_read,
2145 _initialize_coffread ()
2147 add_symtab_fns(&coff_sym_fns);