1 /* Read coff symbol tables and convert to internal format, for GDB.
2 Design and support routines derived from dbxread.c, and UMAX COFF
3 specific routines written 9/1/87 by David D. Johnson, Brown University.
5 Copyright (C) 1987-1991 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include "breakpoint.h"
32 /* Need to get C_VERSION and friends. */
35 #include <intel-coff.h>
36 #endif /* not TDESC */
41 #include "internalcoff.h" /* Internal format of COFF symbols in BFD */
42 #include "libcoff.h" /* FIXME secret internal data from BFD */
44 static void add_symbol_to_list ();
45 static void read_coff_symtab ();
46 static void patch_opaque_types ();
47 static struct type *decode_function_type ();
48 static struct type *decode_type ();
49 static struct type *decode_base_type ();
50 static struct type *read_enum_type ();
51 static struct type *read_struct_type ();
52 static void finish_block ();
53 static struct blockvector *make_blockvector ();
54 static struct symbol *process_coff_symbol ();
55 static int init_stringtab ();
56 static void free_stringtab ();
57 static char *getfilename ();
58 static char *getsymname ();
59 static int init_lineno ();
60 static void enter_linenos ();
61 static void read_one_sym ();
64 extern void free_all_symtabs ();
65 extern void free_all_psymtabs ();
67 /* To be an sdb debug type, type must have at least a basic or primary
68 derived type. Using this rather than checking against T_NULL is
69 said to prevent core dumps if we try to operate on Michael Bloom
72 #define SDB_TYPE(type) (BTYPE(type) | (type & N_TMASK))
74 /* Name of source file whose symbol data we are now processing.
75 This comes from a symbol named ".file". */
77 static char *last_source_file;
79 /* Core address of start and end of text of current source file.
80 This comes from a ".text" symbol where x_nlinno > 0. */
82 static CORE_ADDR cur_src_start_addr;
83 static CORE_ADDR cur_src_end_addr;
85 /* Core address of the end of the first object file. */
86 static CORE_ADDR first_object_file_end;
88 /* End of the text segment of the executable file,
89 as found in the symbol _etext. */
91 static CORE_ADDR end_of_text_addr;
93 /* The addresses of the symbol table stream and number of symbols
94 of the object file we are reading (as copied into core). */
96 static FILE *nlist_stream_global;
97 static int nlist_nsyms_global;
99 /* The entry point (starting address) of the file, if it is an executable. */
101 static CORE_ADDR entry_point;
103 /* The index in the symbol table of the last coff symbol that was processed. */
107 /* Vector of types defined so far, indexed by their coff symnum. */
109 static struct typevector *type_vector;
111 /* Number of elements allocated for type_vector currently. */
113 static int type_vector_length;
115 /* Vector of line number information. */
117 static struct linetable *line_vector;
119 /* Index of next entry to go in line_vector_index. */
121 static int line_vector_index;
123 /* Last line number recorded in the line vector. */
125 static int prev_line_number;
127 /* Number of elements allocated for line_vector currently. */
129 static int line_vector_length;
134 int int_sem_val = 's' << 24 | 'e' << 16 | 'm' << 8 | '.';
136 int last_coffsem = 2;
138 /* This isn't used currently. */
139 int last_coffsyn = 0;
141 int debug_info = 0; /*used by tdesc */
142 extern dc_dcontext_t tdesc_handle;
143 extern int safe_to_init_tdesc_context;
146 /* Chain of typedefs of pointers to empty struct/union types.
147 They are chained thru the SYMBOL_VALUE_CHAIN. */
150 static struct symbol *opaque_type_chain[HASHSIZE];
152 /* Record the symbols defined for each context in a list.
153 We don't create a struct block for the context until we
154 know how long to make it. */
158 struct pending *next;
159 struct symbol *symbol;
162 /* Here are the three lists that symbols are put on. */
164 struct pending *file_symbols; /* static at top level, and types */
166 struct pending *global_symbols; /* global functions and variables */
168 struct pending *local_symbols; /* everything local to lexical context */
170 /* List of unclosed lexical contexts
171 (that will become blocks, eventually). */
175 struct context_stack *next;
176 struct pending *locals;
177 struct pending_block *old_blocks;
179 CORE_ADDR start_addr;
183 struct context_stack *context_stack;
185 /* Nonzero if within a function (so symbols should be local,
186 if nothing says specifically). */
190 /* List of blocks already made (lexical contexts already closed).
191 This is used at the end to make the blockvector. */
195 struct pending_block *next;
199 struct pending_block *pending_blocks;
201 extern CORE_ADDR startup_file_start; /* From blockframe.c */
202 extern CORE_ADDR startup_file_end; /* From blockframe.c */
204 /* Complaints about various problems in the file being read */
206 struct complaint ef_complaint =
207 {"Unmatched .ef symbol(s) ignored starting at symnum %d", 0, 0};
209 struct complaint lineno_complaint =
210 {"Line number pointer %d lower than start of line numbers", 0, 0};
213 /* Look up a coff type-number index. Return the address of the slot
214 where the type for that index is stored.
215 The type-number is in INDEX.
217 This can be used for finding the type associated with that index
218 or for associating a new type with the index. */
220 static struct type **
221 coff_lookup_type (index)
224 if (index >= type_vector_length)
226 int old_vector_length = type_vector_length;
228 type_vector_length *= 2;
229 if (type_vector_length < index) {
230 type_vector_length = index * 2;
232 type_vector = (struct typevector *)
233 xrealloc (type_vector, sizeof (struct typevector)
234 + type_vector_length * sizeof (struct type *));
235 bzero (&type_vector->type[ old_vector_length ],
236 (type_vector_length - old_vector_length) * sizeof(struct type *));
238 return &type_vector->type[index];
241 /* Make sure there is a type allocated for type number index
242 and return the type object.
243 This can create an empty (zeroed) type object. */
246 coff_alloc_type (index)
249 register struct type **type_addr = coff_lookup_type (index);
250 register struct type *type = *type_addr;
252 /* If we are referring to a type not known at all yet,
253 allocate an empty type for it.
254 We will fill it in later if we find out how. */
257 type = (struct type *) obstack_alloc (symbol_obstack,
258 sizeof (struct type));
259 bzero (type, sizeof (struct type));
265 /* maintain the lists of symbols and blocks */
267 /* Add a symbol to one of the lists of symbols. */
269 add_symbol_to_list (symbol, listhead)
270 struct symbol *symbol;
271 struct pending **listhead;
273 register struct pending *link
274 = (struct pending *) xmalloc (sizeof (struct pending));
276 link->next = *listhead;
277 link->symbol = symbol;
281 /* Take one of the lists of symbols and make a block from it.
282 Put the block on the list of pending blocks. */
285 finish_block (symbol, listhead, old_blocks, start, end)
286 struct symbol *symbol;
287 struct pending **listhead;
288 struct pending_block *old_blocks;
289 CORE_ADDR start, end;
291 register struct pending *next, *next1;
292 register struct block *block;
293 register struct pending_block *pblock;
294 struct pending_block *opblock;
297 /* Count the length of the list of symbols. */
299 for (next = *listhead, i = 0; next; next = next->next, i++);
301 block = (struct block *)
302 obstack_alloc (symbol_obstack, sizeof (struct block) + (i - 1) * sizeof (struct symbol *));
304 /* Copy the symbols into the block. */
306 BLOCK_NSYMS (block) = i;
307 for (next = *listhead; next; next = next->next)
308 BLOCK_SYM (block, --i) = next->symbol;
310 BLOCK_START (block) = start;
311 BLOCK_END (block) = end;
312 BLOCK_SUPERBLOCK (block) = 0; /* Filled in when containing block is made */
314 /* Put the block in as the value of the symbol that names it. */
318 SYMBOL_BLOCK_VALUE (symbol) = block;
319 BLOCK_FUNCTION (block) = symbol;
322 BLOCK_FUNCTION (block) = 0;
324 /* Now free the links of the list, and empty the list. */
326 for (next = *listhead; next; next = next1)
333 /* Install this block as the superblock
334 of all blocks made since the start of this scope
335 that don't have superblocks yet. */
338 for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next)
340 if (BLOCK_SUPERBLOCK (pblock->block) == 0)
341 BLOCK_SUPERBLOCK (pblock->block) = block;
345 /* Record this block on the list of all blocks in the file.
346 Put it after opblock, or at the beginning if opblock is 0.
347 This puts the block in the list after all its subblocks. */
349 pblock = (struct pending_block *) xmalloc (sizeof (struct pending_block));
350 pblock->block = block;
353 pblock->next = opblock->next;
354 opblock->next = pblock;
358 pblock->next = pending_blocks;
359 pending_blocks = pblock;
363 static struct blockvector *
366 register struct pending_block *next, *next1;
367 register struct blockvector *blockvector;
370 /* Count the length of the list of blocks. */
372 for (next = pending_blocks, i = 0; next; next = next->next, i++);
374 blockvector = (struct blockvector *)
375 obstack_alloc (symbol_obstack, sizeof (struct blockvector) + (i - 1) * sizeof (struct block *));
377 /* Copy the blocks into the blockvector.
378 This is done in reverse order, which happens to put
379 the blocks into the proper order (ascending starting address).
380 finish_block has hair to insert each block into the list
381 after its subblocks in order to make sure this is true. */
383 BLOCKVECTOR_NBLOCKS (blockvector) = i;
384 for (next = pending_blocks; next; next = next->next)
385 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
387 /* Now free the links of the list, and empty the list. */
389 for (next = pending_blocks; next; next = next1)
399 /* Manage the vector of line numbers. */
402 record_line (line, pc)
406 struct linetable_entry *e;
407 /* Make sure line vector is big enough. */
409 if (line_vector_index + 2 >= line_vector_length)
411 line_vector_length *= 2;
412 line_vector = (struct linetable *)
413 xrealloc (line_vector, sizeof (struct linetable)
414 + (line_vector_length
415 * sizeof (struct linetable_entry)));
418 e = line_vector->item + line_vector_index++;
419 e->line = line; e->pc = pc;
422 /* Start a new symtab for a new source file.
423 This is called when a COFF ".file" symbol is seen;
424 it indicates the start of data for one original source file. */
433 last_source_file = 0;
437 /* This isn't used currently. */
442 /* Initialize the source file information for this file. */
444 line_vector_index = 0;
445 line_vector_length = 1000;
446 prev_line_number = -2; /* Force first line number to be explicit */
447 line_vector = (struct linetable *)
448 xmalloc (sizeof (struct linetable)
449 + line_vector_length * sizeof (struct linetable_entry));
452 /* Save the vital information from when starting to read a file,
453 for use when closing off the current file.
454 NAME is the file name the symbols came from, START_ADDR is the first
455 text address for the file, and SIZE is the number of bytes of text. */
458 complete_symtab (name, start_addr, size)
460 CORE_ADDR start_addr;
463 last_source_file = savestring (name, strlen (name));
464 cur_src_start_addr = start_addr;
465 cur_src_end_addr = start_addr + size;
467 if (entry_point < cur_src_end_addr
468 && entry_point >= cur_src_start_addr)
470 startup_file_start = cur_src_start_addr;
471 startup_file_end = cur_src_end_addr;
475 /* Finish the symbol definitions for one main source file,
476 close off all the lexical contexts for that file
477 (creating struct block's for them), then make the
478 struct symtab for that file and put it in the list of all such. */
483 register struct symtab *symtab;
484 register struct context_stack *cstk;
485 register struct blockvector *blockvector;
486 register struct linetable *lv;
488 /* Finish the lexical context of the last function in the file. */
492 cstk = context_stack;
494 /* Make a block for the local symbols within. */
495 finish_block (cstk->name, &local_symbols, cstk->old_blocks,
496 cstk->start_addr, cur_src_end_addr);
500 /* Ignore a file that has no functions with real debugging info. */
501 if (pending_blocks == 0 && file_symbols == 0 && global_symbols == 0)
505 line_vector_length = -1;
506 last_source_file = 0;
510 /* Create the two top-level blocks for this file (STATIC_BLOCK and
512 finish_block (0, &file_symbols, 0, cur_src_start_addr, cur_src_end_addr);
513 finish_block (0, &global_symbols, 0, cur_src_start_addr, cur_src_end_addr);
515 /* Create the blockvector that points to all the file's blocks. */
516 blockvector = make_blockvector ();
518 /* Now create the symtab object for this source file. */
519 symtab = (struct symtab *) xmalloc (sizeof (struct symtab));
520 symtab->free_ptr = 0;
522 /* Fill in its components. */
523 symtab->blockvector = blockvector;
524 symtab->free_code = free_linetable;
525 symtab->filename = last_source_file;
526 symtab->dirname = NULL;
528 lv->nitems = line_vector_index;
529 symtab->linetable = (struct linetable *)
530 xrealloc (lv, (sizeof (struct linetable)
531 + lv->nitems * sizeof (struct linetable_entry)));
533 symtab->line_charpos = 0;
535 symtab->language = language_unknown;
536 symtab->fullname = NULL;
539 symtab->coffsem = last_coffsem;
541 /* This isn't used currently. Besides, if this is really about "syntax",
542 it shouldn't need to stick around past symbol read-in time. */
543 symtab->coffsyn = last_coffsyn;
547 free_named_symtabs (symtab->filename);
549 /* Link the new symtab into the list of such. */
550 symtab->next = symtab_list;
551 symtab_list = symtab;
553 /* Reinitialize for beginning of new file. */
555 line_vector_length = -1;
556 last_source_file = 0;
560 record_misc_function (name, address)
565 /* We don't want TDESC entry points on the misc_function_vector */
566 if (name[0] == '@') return;
568 /* mf_text isn't true, but apparently COFF doesn't tell us what it really
569 is, so this guess is more useful than mf_unknown. */
570 prim_record_misc_function (savestring (name, strlen (name)),
575 /* coff_symfile_init ()
576 is the coff-specific initialization routine for reading symbols.
577 It is passed a struct sym_fns which contains, among other things,
578 the BFD for the file whose symbols are being read, and a slot for
579 a pointer to "private data" which we fill with cookies and other
580 treats for coff_symfile_read ().
582 We will only be called if this is a COFF or COFF-like file.
583 BFD handles figuring out the format of the file, and code in symtab.c
584 uses BFD's determination to vector to us.
586 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
588 struct coff_symfile_info {
589 file_ptr min_lineno_offset; /* Where in file lowest line#s are */
590 file_ptr max_lineno_offset; /* 1+last byte of line#s in file */
594 coff_symfile_init (sf)
597 bfd *abfd = sf->sym_bfd;
599 /* Allocate struct to keep track of the symfile */
600 /* FIXME memory leak */
601 sf->sym_private = xmalloc (sizeof (struct coff_symfile_info));
604 safe_to_init_tdesc_context = 0;
607 /* Save startup file's range of PC addresses to help blockframe.c
608 decide where the bottom of the stack is. */
609 if (bfd_get_file_flags (abfd) & EXEC_P)
611 /* Executable file -- record its entry point so we'll recognize
612 the startup file because it contains the entry point. */
613 entry_point = bfd_get_start_address (abfd);
617 /* Examination of non-executable.o files. Short-circuit this stuff. */
618 /* ~0 will not be in any file, we hope. */
620 /* set the startup file to be an empty range. */
621 startup_file_start = 0;
622 startup_file_end = 0;
626 /* This function is called for every section; it finds the outer limits
627 of the line table (minimum and maximum file offset) so that the
628 mainline code can read the whole thing for efficiency. */
632 find_linenos (abfd, asect, vpinfo)
637 struct coff_symfile_info *info;
639 file_ptr offset, maxoff;
641 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
642 count = asect->lineno_count;
647 #if !defined (LINESZ)
648 /* Just in case, you never know what to expect from those
649 COFF header files. */
650 #define LINESZ (sizeof (struct lineno))
651 #endif /* No LINESZ. */
652 size = count * LINESZ;
654 info = (struct coff_symfile_info *)vpinfo;
655 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
656 offset = asect->line_filepos;
659 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
660 info->min_lineno_offset = offset;
662 maxoff = offset + size;
663 if (maxoff > info->max_lineno_offset)
664 info->max_lineno_offset = maxoff;
666 /* While we're at it, find the debug_info. It's in the s_relptr
667 (or, in BFD-speak, rel_filepos) of the text segment section header. */
668 if (strcmp (bfd_section_name (abfd, asect), ".text") == 0)
670 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
671 debug_info = asect->rel_filepos;
675 dc_terminate (tdesc_handle);
683 /* The BFD for this file -- only good while we're actively reading
684 symbols into a psymtab or a symtab. */
686 static bfd *symfile_bfd;
688 /* Read a symbol file, after initialization by coff_symfile_init. */
689 /* FIXME! Addr and Mainline are not used yet -- this will not work for
690 shared libraries or add_file! */
693 coff_symfile_read (sf, addr, mainline)
698 struct coff_symfile_info *info = (struct coff_symfile_info *)sf->sym_private;
699 bfd *abfd = sf->sym_bfd;
700 char *name = bfd_get_filename (abfd);
705 int stringtab_offset;
707 symfile_bfd = abfd; /* Kludge for swap routines */
709 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
710 desc = fileno ((FILE *)(abfd->iostream)); /* File descriptor */
711 num_symbols = bfd_get_symcount (abfd); /* How many syms */
712 symtab_offset = obj_sym_filepos (abfd); /* Symbol table file offset */
713 stringtab_offset = symtab_offset + num_symbols * SYMESZ; /* String tab */
716 /* Read the line number table, all at once. */
717 info->min_lineno_offset = 0;
718 info->max_lineno_offset = 0;
719 bfd_map_over_sections (abfd, find_linenos, info);
721 val = init_lineno (desc, info->min_lineno_offset,
722 info->max_lineno_offset - info->min_lineno_offset);
724 error ("\"%s\": error reading line numbers\n", name);
726 /* Now read the string table, all at once. */
728 val = init_stringtab (desc, stringtab_offset);
731 free_all_symtabs (); /* FIXME blows whole symtab */
732 printf ("\"%s\": can't get string table", name);
736 make_cleanup (free_stringtab, 0);
738 /* Position to read the symbol table. Do not read it all at once. */
739 val = lseek (desc, (long)symtab_offset, 0);
741 perror_with_name (name);
743 init_misc_bunches ();
744 make_cleanup (discard_misc_bunches, 0);
746 /* Now that the executable file is positioned at symbol table,
747 process it and define symbols accordingly. */
749 read_coff_symtab (desc, num_symbols);
751 patch_opaque_types ();
753 /* Sort symbols alphabetically within each block. */
755 sort_all_symtab_syms ();
757 /* Go over the misc symbol bunches and install them in vector. */
759 condense_misc_bunches (0);
761 /* Make a default for file to list. */
763 select_source_symtab (0); /* FIXME, this might be too slow, see dbxread */
767 coff_symfile_discard ()
769 /* There seems to be nothing to do here. */
775 /* There seems to be nothing to do except free_all_symtabs and set
776 symfile to zero, which is done by our caller. */
779 /* Simplified internal version of coff symbol table information */
783 int c_symnum; /* symbol number of this entry */
784 int c_nsyms; /* 1 if syment only, 2 if syment + auxent, etc */
791 /* Given pointers to a symbol table in coff style exec file,
792 analyze them and create struct symtab's describing the symbols.
793 NSYMS is the number of symbols in the symbol table.
794 We read them one at a time using read_one_sym (). */
797 read_coff_symtab (desc, nsyms)
801 int newfd; /* Avoid multiple closes on same desc */
803 register struct context_stack *new;
804 struct coff_symbol coff_symbol;
805 register struct coff_symbol *cs = &coff_symbol;
806 static struct internal_syment main_sym;
807 static union internal_auxent main_aux;
808 struct coff_symbol fcn_cs_saved;
809 static struct internal_syment fcn_sym_saved;
810 static union internal_auxent fcn_aux_saved;
812 /* A .file is open. */
813 int in_source_file = 0;
814 int num_object_files = 0;
815 int next_file_symnum = -1;
817 /* Name of the current file. */
818 char *filestring = "";
824 struct cleanup *old_chain;
829 fatal ("Too many open files");
830 stream = fdopen (newfd, "r");
832 old_chain = make_cleanup (free_all_symtabs, 0);
833 make_cleanup (fclose, stream);
834 nlist_stream_global = stream;
835 nlist_nsyms_global = nsyms;
836 last_source_file = 0;
837 bzero (opaque_type_chain, sizeof opaque_type_chain);
839 type_vector_length = 160;
840 type_vector = (struct typevector *)
841 xmalloc (sizeof (struct typevector)
842 + type_vector_length * sizeof (struct type *));
843 bzero (type_vector->type, type_vector_length * sizeof (struct type *));
848 while (symnum < nsyms)
850 QUIT; /* Make this command interruptable. */
851 read_one_sym (cs, &main_sym, &main_aux);
854 temp_sem_val = cs->c_name[0] << 24 | cs->c_name[1] << 16 |
855 cs->c_name[2] << 8 | cs->c_name[3];
856 if (int_sem_val == temp_sem_val)
857 last_coffsem = (int) strtol (cs->c_name+4, (char **) NULL, 10);
860 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
862 if (last_source_file)
866 complete_symtab ("_globals_", 0, first_object_file_end);
867 /* done with all files, everything from here on out is globals */
870 /* Special case for file with type declarations only, no text. */
871 if (!last_source_file && SDB_TYPE (cs->c_type)
872 && cs->c_secnum == N_DEBUG)
873 complete_symtab (filestring, 0, 0);
875 /* Typedefs should not be treated as symbol definitions. */
876 if (ISFCN (cs->c_type) && cs->c_sclass != C_TPDEF)
878 /* record as misc function. if we get '.bf' next,
879 * then we undo this step
881 record_misc_function (cs->c_name, cs->c_value);
883 fcn_line_ptr = main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
884 fcn_start_addr = cs->c_value;
886 fcn_sym_saved = main_sym;
887 fcn_aux_saved = main_aux;
891 switch (cs->c_sclass)
900 printf ("Bad n_sclass = %d\n", cs->c_sclass);
905 * c_value field contains symnum of next .file entry in table
906 * or symnum of first global after last .file.
908 next_file_symnum = cs->c_value;
909 filestring = getfilename (&main_aux);
911 * Complete symbol table for last object file
912 * containing debugging information.
914 if (last_source_file)
923 if (cs->c_name[0] == '.') {
924 if (strcmp (cs->c_name, _TEXT) == 0) {
925 if (++num_object_files == 1) {
926 /* last address of startup file */
927 first_object_file_end = cs->c_value +
928 main_aux.x_scn.x_scnlen;
930 /* Check for in_source_file deals with case of
931 a file with debugging symbols
932 followed by a later file with no symbols. */
934 complete_symtab (filestring, cs->c_value,
935 main_aux.x_scn.x_scnlen);
938 /* flush rest of '.' symbols */
941 else if (!SDB_TYPE (cs->c_type)
942 && cs->c_name[0] == 'L'
943 && (strncmp (cs->c_name, "LI%", 3) == 0
944 || strncmp (cs->c_name, "LF%", 3) == 0
945 || strncmp (cs->c_name,"LC%",3) == 0
946 || strncmp (cs->c_name,"LP%",3) == 0
947 || strncmp (cs->c_name,"LPB%",4) == 0
948 || strncmp (cs->c_name,"LBB%",4) == 0
949 || strncmp (cs->c_name,"LBE%",4) == 0
950 || strncmp (cs->c_name,"LPBX%",5) == 0))
951 /* At least on a 3b1, gcc generates swbeg and string labels
952 that look like this. Ignore them. */
954 /* fall in for static symbols that don't start with '.' */
956 if (cs->c_sclass == C_EXT &&
957 cs->c_secnum == N_ABS &&
958 strcmp (cs->c_name, _ETEXT) == 0)
959 end_of_text_addr = cs->c_value;
960 if (!SDB_TYPE (cs->c_type)) {
961 if (cs->c_secnum <= 1) { /* text or abs */
962 record_misc_function (cs->c_name, cs->c_value);
968 (void) process_coff_symbol (cs, &main_aux);
972 if (strcmp (cs->c_name, ".bf") == 0)
976 /* value contains address of first non-init type code */
977 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
978 contains line number of '{' } */
979 fcn_first_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
981 new = (struct context_stack *)
982 xmalloc (sizeof (struct context_stack));
983 new->depth = depth = 0;
987 new->old_blocks = pending_blocks;
988 new->start_addr = fcn_start_addr;
989 fcn_cs_saved.c_name = getsymname (&fcn_sym_saved);
990 new->name = process_coff_symbol (&fcn_cs_saved,
993 else if (strcmp (cs->c_name, ".ef") == 0)
995 /* the value of .ef is the address of epilogue code;
998 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
999 contains number of lines to '}' */
1000 new = context_stack;
1003 complain (&ef_complaint, cs->c_symnum);
1004 within_function = 0;
1007 fcn_last_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
1008 enter_linenos (fcn_line_ptr, fcn_first_line, fcn_last_line);
1010 finish_block (new->name, &local_symbols, new->old_blocks,
1012 #if defined (FUNCTION_EPILOGUE_SIZE)
1013 /* This macro should be defined only on
1015 fcn_aux_saved.x_sym.x_misc.x_fsize
1016 field is always zero.
1017 So use the .bf record information that
1018 points to the epilogue and add the size
1020 cs->c_value + FUNCTION_EPILOGUE_SIZE
1022 fcn_cs_saved.c_value +
1023 fcn_aux_saved.x_sym.x_misc.x_fsize
1027 within_function = 0;
1033 if (strcmp (cs->c_name, ".bb") == 0)
1035 new = (struct context_stack *)
1036 xmalloc (sizeof (struct context_stack));
1039 new->next = context_stack;
1040 context_stack = new;
1041 new->locals = local_symbols;
1042 new->old_blocks = pending_blocks;
1043 new->start_addr = cs->c_value;
1047 else if (strcmp (cs->c_name, ".eb") == 0)
1049 new = context_stack;
1050 if (new == 0 || depth != new->depth)
1051 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1053 if (local_symbols && context_stack->next)
1055 /* Make a block for the local symbols within. */
1056 finish_block (0, &local_symbols, new->old_blocks,
1057 new->start_addr, cs->c_value);
1060 local_symbols = new->locals;
1061 context_stack = new->next;
1068 /* This isn't used currently. */
1069 if (strcmp (cs->c_name, ".coffsyn") == 0)
1070 last_coffsyn = cs->c_value;
1073 if ((strcmp (cs->c_name, ".coffsem") == 0) &&
1075 last_coffsem = cs->c_value;
1081 if ((strcmp (cs->c_name, ".coffsem") == 0) &&
1083 last_coffsem = cs->c_value;
1086 (void) process_coff_symbol (cs, &main_aux);
1091 if (last_source_file)
1094 discard_cleanups (old_chain);
1097 /* Routines for reading headers and symbols from executable. */
1100 /* Move these XXXMAGIC symbol defns into BFD! */
1102 /* Read COFF file header, check magic number,
1103 and return number of symbols. */
1104 read_file_hdr (chan, file_hdr)
1108 lseek (chan, 0L, 0);
1109 if (myread (chan, (char *)file_hdr, FILHSZ) < 0)
1112 switch (file_hdr->f_magic)
1127 #if defined (MC68KWRMAGIC) \
1128 && (!defined (MC68MAGIC) || MC68KWRMAGIC != MC68MAGIC)
1142 case I960ROMAGIC: /* Intel 960 */
1145 case I960RWMAGIC: /* Intel 960 */
1147 return file_hdr->f_nsyms;
1151 if (BADMAG(file_hdr))
1154 return file_hdr->f_nsyms;
1162 /* Read the next symbol, swap it, and return it in both internal_syment
1163 form, and coff_symbol form. Also return its first auxent, if any,
1164 in internal_auxent form, and skip any other auxents. */
1167 read_one_sym (cs, sym, aux)
1168 register struct coff_symbol *cs;
1169 register struct internal_syment *sym;
1170 register union internal_auxent *aux;
1172 struct external_syment temp_sym[1];
1173 union external_auxent temp_aux[1];
1176 cs->c_symnum = symnum;
1177 fread ((char *)temp_sym, SYMESZ, 1, nlist_stream_global);
1178 bfd_coff_swap_sym_in (symfile_bfd, temp_sym, sym);
1179 cs->c_nsyms = (sym->n_numaux & 0xff) + 1;
1180 if (cs->c_nsyms >= 2)
1182 fread ((char *)temp_aux, AUXESZ, 1, nlist_stream_global);
1183 bfd_coff_swap_aux_in (symfile_bfd, temp_aux, sym->n_type, sym->n_sclass, aux);
1184 /* If more than one aux entry, read past it (only the first aux
1186 for (i = 2; i < cs->c_nsyms; i++)
1187 fread ((char *)temp_aux, AUXESZ, 1, nlist_stream_global);
1189 cs->c_name = getsymname (sym);
1190 cs->c_value = sym->n_value;
1191 cs->c_sclass = (sym->n_sclass & 0xff);
1192 cs->c_secnum = sym->n_scnum;
1193 cs->c_type = (unsigned) sym->n_type;
1194 if (!SDB_TYPE (cs->c_type))
1197 symnum += cs->c_nsyms;
1200 /* Support for string table handling */
1202 static char *stringtab = NULL;
1205 init_stringtab (chan, offset)
1211 unsigned char lengthbuf[4];
1219 if (lseek (chan, offset, 0) < 0)
1222 val = myread (chan, (char *)lengthbuf, sizeof lengthbuf);
1223 length = bfd_h_get_32 (symfile_bfd, lengthbuf);
1225 /* If no string table is needed, then the file may end immediately
1226 after the symbols. Just return with `stringtab' set to null. */
1227 if (val != sizeof length || length < sizeof length)
1230 stringtab = (char *) xmalloc (length);
1231 if (stringtab == NULL)
1234 bcopy (&length, stringtab, sizeof length);
1235 if (length == sizeof length) /* Empty table -- just the count */
1238 val = myread (chan, stringtab + sizeof length, length - sizeof length);
1239 if (val != length - sizeof length || stringtab[length - 1] != '\0')
1254 getsymname (symbol_entry)
1255 struct internal_syment *symbol_entry;
1257 static char buffer[SYMNMLEN+1];
1260 if (symbol_entry->_n._n_n._n_zeroes == 0)
1262 result = stringtab + symbol_entry->_n._n_n._n_offset;
1266 strncpy (buffer, symbol_entry->_n._n_name, SYMNMLEN);
1267 buffer[SYMNMLEN] = '\0';
1274 getfilename (aux_entry)
1275 union internal_auxent *aux_entry;
1277 static char buffer[BUFSIZ];
1278 register char *temp;
1280 extern char *rindex ();
1282 #ifndef COFF_NO_LONG_FILE_NAMES
1283 #if defined (x_zeroes)
1285 if (aux_entry->x_zeroes == 0)
1286 strcpy (buffer, stringtab + aux_entry->x_offset);
1287 #else /* no x_zeroes */
1288 if (aux_entry->x_file.x_n.x_zeroes == 0)
1289 strcpy (buffer, stringtab + aux_entry->x_file.x_n.x_offset);
1290 #endif /* no x_zeroes */
1292 #endif /* COFF_NO_LONG_FILE_NAMES */
1294 #if defined (x_name)
1296 strncpy (buffer, aux_entry->x_name, FILNMLEN);
1298 strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
1300 buffer[FILNMLEN] = '\0';
1303 if ((temp = rindex (result, '/')) != NULL)
1308 /* Support for line number handling */
1309 static char *linetab = NULL;
1310 static long linetab_offset;
1311 static unsigned long linetab_size;
1313 /* Read in all the line numbers for fast lookups later. Leave them in
1314 external (unswapped) format in memory; we'll swap them as we enter
1315 them into GDB's data structures. */
1318 init_lineno (chan, offset, size)
1325 if (lseek (chan, offset, 0) < 0)
1328 linetab = (char *) xmalloc (size);
1330 val = myread (chan, linetab, size);
1334 linetab_offset = offset;
1335 linetab_size = size;
1336 make_cleanup (free, linetab); /* Be sure it gets de-allocated. */
1340 #if !defined (L_LNNO32)
1341 #define L_LNNO32(lp) ((lp)->l_lnno)
1345 enter_linenos (file_offset, first_line, last_line)
1347 register int first_line;
1348 register int last_line;
1350 register char *rawptr;
1351 struct internal_lineno lptr;
1353 if (file_offset < linetab_offset)
1355 complain (&lineno_complaint, file_offset);
1356 if (file_offset > linetab_size) /* Too big to be an offset? */
1358 file_offset += linetab_offset; /* Try reading at that linetab offset */
1361 rawptr = &linetab[file_offset - linetab_offset];
1363 /* skip first line entry for each function */
1365 /* line numbers start at one for the first line of the function */
1369 bfd_coff_swap_lineno_in (symfile_bfd, (LINENO *)rawptr, &lptr);
1371 if (L_LNNO32 (&lptr) && L_LNNO32 (&lptr) <= last_line)
1372 record_line (first_line + L_LNNO32 (&lptr), lptr.l_addr.l_paddr);
1382 register char *p = name;
1383 register int total = p[0];
1396 return total % HASHSIZE;
1400 patch_type (type, real_type)
1402 struct type *real_type;
1404 register struct type *target = TYPE_TARGET_TYPE (type);
1405 register struct type *real_target = TYPE_TARGET_TYPE (real_type);
1406 int field_size = TYPE_NFIELDS (real_target) * sizeof (struct field);
1408 TYPE_LENGTH (target) = TYPE_LENGTH (real_target);
1409 TYPE_NFIELDS (target) = TYPE_NFIELDS (real_target);
1410 TYPE_FIELDS (target) = (struct field *)
1411 obstack_alloc (symbol_obstack, field_size);
1413 bcopy (TYPE_FIELDS (real_target), TYPE_FIELDS (target), field_size);
1415 if (TYPE_NAME (real_target))
1417 if (TYPE_NAME (target))
1418 free (TYPE_NAME (target));
1419 TYPE_NAME (target) = concat (TYPE_NAME (real_target), "", "");
1423 /* Patch up all appropriate typdef symbols in the opaque_type_chains
1424 so that they can be used to print out opaque data structures properly */
1427 patch_opaque_types ()
1431 /* Look at each symbol in the per-file block of each symtab. */
1432 for (s = symtab_list; s; s = s->next)
1434 register struct block *b;
1437 /* Go through the per-file symbols only */
1438 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
1439 for (i = BLOCK_NSYMS (b) - 1; i >= 0; i--)
1441 register struct symbol *real_sym;
1443 /* Find completed typedefs to use to fix opaque ones.
1444 Remove syms from the chain when their types are stored,
1445 but search the whole chain, as there may be several syms
1446 from different files with the same name. */
1447 real_sym = BLOCK_SYM (b, i);
1448 if (SYMBOL_CLASS (real_sym) == LOC_TYPEDEF &&
1449 SYMBOL_NAMESPACE (real_sym) == VAR_NAMESPACE &&
1450 TYPE_CODE (SYMBOL_TYPE (real_sym)) == TYPE_CODE_PTR &&
1451 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym))) != 0)
1453 register char *name = SYMBOL_NAME (real_sym);
1454 register int hash = hashname (name);
1455 register struct symbol *sym, *prev;
1458 for (sym = opaque_type_chain[hash]; sym;)
1460 if (name[0] == SYMBOL_NAME (sym)[0] &&
1461 !strcmp (name + 1, SYMBOL_NAME (sym) + 1))
1464 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
1466 opaque_type_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
1468 patch_type (SYMBOL_TYPE (sym), SYMBOL_TYPE (real_sym));
1471 sym = SYMBOL_VALUE_CHAIN (prev);
1473 sym = opaque_type_chain[hash];
1478 sym = SYMBOL_VALUE_CHAIN (sym);
1486 #if defined (clipper)
1487 #define BELIEVE_PCC_PROMOTION 1
1490 static struct symbol *
1491 process_coff_symbol (cs, aux)
1492 register struct coff_symbol *cs;
1493 register union internal_auxent *aux;
1495 register struct symbol *sym
1496 = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
1498 #ifdef NAMES_HAVE_UNDERSCORE
1504 bzero (sym, sizeof (struct symbol));
1506 name = (name[0] == '_' ? name + offset : name);
1507 SYMBOL_NAME (sym) = obstack_copy0 (symbol_obstack, name, strlen (name));
1509 /* default assumptions */
1510 SYMBOL_VALUE (sym) = cs->c_value;
1511 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1513 if (ISFCN (cs->c_type))
1516 lookup_function_type (decode_function_type (cs, cs->c_type, aux));
1517 SYMBOL_CLASS (sym) = LOC_BLOCK;
1518 if (cs->c_sclass == C_STAT)
1519 add_symbol_to_list (sym, &file_symbols);
1520 else if (cs->c_sclass == C_EXT)
1521 add_symbol_to_list (sym, &global_symbols);
1525 SYMBOL_TYPE (sym) = decode_type (cs, cs->c_type, aux);
1526 switch (cs->c_sclass)
1532 SYMBOL_CLASS (sym) = LOC_LOCAL;
1533 add_symbol_to_list (sym, &local_symbols);
1537 SYMBOL_CLASS (sym) = LOC_STATIC;
1538 SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
1539 add_symbol_to_list (sym, &global_symbols);
1543 SYMBOL_CLASS (sym) = LOC_STATIC;
1544 SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
1545 if (within_function) {
1546 /* Static symbol of local scope */
1547 add_symbol_to_list (sym, &local_symbols);
1550 /* Static symbol at top level of file */
1551 add_symbol_to_list (sym, &file_symbols);
1556 SYMBOL_CLASS (sym) = LOC_REGISTER;
1557 add_symbol_to_list (sym, &local_symbols);
1564 SYMBOL_CLASS (sym) = LOC_ARG;
1565 add_symbol_to_list (sym, &local_symbols);
1566 #if !defined (BELIEVE_PCC_PROMOTION)
1567 /* If PCC says a parameter is a short or a char,
1568 it is really an int. */
1569 if (SYMBOL_TYPE (sym) == builtin_type_char
1570 || SYMBOL_TYPE (sym) == builtin_type_short)
1571 SYMBOL_TYPE (sym) = builtin_type_int;
1572 else if (SYMBOL_TYPE (sym) == builtin_type_unsigned_char
1573 || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
1574 SYMBOL_TYPE (sym) = builtin_type_unsigned_int;
1579 SYMBOL_CLASS (sym) = LOC_REGPARM;
1580 add_symbol_to_list (sym, &local_symbols);
1581 #if !defined (BELIEVE_PCC_PROMOTION)
1582 /* If PCC says a parameter is a short or a char,
1583 it is really an int. */
1584 if (SYMBOL_TYPE (sym) == builtin_type_char
1585 || SYMBOL_TYPE (sym) == builtin_type_short)
1586 SYMBOL_TYPE (sym) = builtin_type_int;
1587 else if (SYMBOL_TYPE (sym) == builtin_type_unsigned_char
1588 || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
1589 SYMBOL_TYPE (sym) = builtin_type_unsigned_int;
1594 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1595 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1597 /* If type has no name, give it one */
1598 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
1599 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
1600 TYPE_NAME (SYMBOL_TYPE (sym))
1601 = concat (SYMBOL_NAME (sym), "", "");
1603 /* Keep track of any type which points to empty structured type,
1604 so it can be filled from a definition from another file */
1605 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR &&
1606 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym))) == 0)
1608 register int i = hashname (SYMBOL_NAME (sym));
1610 SYMBOL_VALUE_CHAIN (sym) = opaque_type_chain[i];
1611 opaque_type_chain[i] = sym;
1613 add_symbol_to_list (sym, &file_symbols);
1619 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1620 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1621 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
1622 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
1623 TYPE_NAME (SYMBOL_TYPE (sym))
1625 (cs->c_sclass == C_ENTAG
1627 : (cs->c_sclass == C_STRTAG
1628 ? "struct " : "union ")),
1630 add_symbol_to_list (sym, &file_symbols);
1640 /* Decode a coff type specifier;
1641 return the type that is meant. */
1645 decode_type (cs, c_type, aux)
1646 register struct coff_symbol *cs;
1647 unsigned int c_type;
1648 register union internal_auxent *aux;
1650 register struct type *type = 0;
1651 unsigned int new_c_type;
1653 if (c_type & ~N_BTMASK)
1655 new_c_type = DECREF (c_type);
1658 type = decode_type (cs, new_c_type, aux);
1659 type = lookup_pointer_type (type);
1661 else if (ISFCN (c_type))
1663 type = decode_type (cs, new_c_type, aux);
1664 type = lookup_function_type (type);
1666 else if (ISARY (c_type))
1669 register unsigned short *dim;
1670 struct type *base_type;
1672 /* Define an array type. */
1673 /* auxent refers to array, not base type */
1674 if (aux->x_sym.x_tagndx.l == 0)
1677 /* shift the indices down */
1678 dim = &aux->x_sym.x_fcnary.x_ary.x_dimen[0];
1681 for (i = 0; *dim && i < DIMNUM - 1; i++, dim++)
1685 type = (struct type *)
1686 obstack_alloc (symbol_obstack, sizeof (struct type));
1687 bzero (type, sizeof (struct type));
1689 base_type = decode_type (cs, new_c_type, aux);
1691 TYPE_CODE (type) = TYPE_CODE_ARRAY;
1692 TYPE_TARGET_TYPE (type) = base_type;
1693 TYPE_LENGTH (type) = n * TYPE_LENGTH (base_type);
1698 /* Reference to existing type */
1699 if (cs->c_nsyms > 1 && aux->x_sym.x_tagndx.l != 0)
1701 type = coff_alloc_type (aux->x_sym.x_tagndx);
1705 return decode_base_type (cs, BTYPE (c_type), aux);
1708 /* Decode a coff type specifier for function definition;
1709 return the type that the function returns. */
1713 decode_function_type (cs, c_type, aux)
1714 register struct coff_symbol *cs;
1715 unsigned int c_type;
1716 register union internal_auxent *aux;
1718 if (aux->x_sym.x_tagndx.l == 0)
1719 cs->c_nsyms = 1; /* auxent refers to function, not base type */
1721 return decode_type (cs, DECREF (c_type), aux);
1728 decode_base_type (cs, c_type, aux)
1729 register struct coff_symbol *cs;
1730 unsigned int c_type;
1731 register union internal_auxent *aux;
1738 /* shows up with "void (*foo)();" structure members */
1739 return builtin_type_void;
1742 /* DGUX actually defines both T_ARG and T_VOID to the same value. */
1745 /* Shows up in DGUX, I think. Not sure where. */
1746 return builtin_type_void; /* shouldn't show up here */
1752 /* Intel 960 COFF has this symbol and meaning. */
1753 return builtin_type_void;
1757 return builtin_type_char;
1760 return builtin_type_short;
1763 return builtin_type_int;
1766 return builtin_type_long;
1769 return builtin_type_float;
1772 return builtin_type_double;
1775 if (cs->c_nsyms != 2)
1777 /* anonymous structure type */
1778 type = coff_alloc_type (cs->c_symnum);
1779 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1780 TYPE_NAME (type) = concat ("struct ", "<opaque>", "");
1781 TYPE_LENGTH (type) = 0;
1782 TYPE_FIELDS (type) = 0;
1783 TYPE_NFIELDS (type) = 0;
1787 type = read_struct_type (cs->c_symnum,
1788 aux->x_sym.x_misc.x_lnsz.x_size,
1789 aux->x_sym.x_fcnary.x_fcn.x_endndx);
1794 if (cs->c_nsyms != 2)
1796 /* anonymous union type */
1797 type = coff_alloc_type (cs->c_symnum);
1798 TYPE_NAME (type) = concat ("union ", "<opaque>", "");
1799 TYPE_LENGTH (type) = 0;
1800 TYPE_FIELDS (type) = 0;
1801 TYPE_NFIELDS (type) = 0;
1805 type = read_struct_type (cs->c_symnum,
1806 aux->x_sym.x_misc.x_lnsz.x_size,
1807 aux->x_sym.x_fcnary.x_fcn.x_endndx);
1809 TYPE_CODE (type) = TYPE_CODE_UNION;
1813 return read_enum_type (cs->c_symnum,
1814 aux->x_sym.x_misc.x_lnsz.x_size,
1815 aux->x_sym.x_fcnary.x_fcn.x_endndx);
1818 /* shouldn't show up here */
1822 return builtin_type_unsigned_char;
1825 return builtin_type_unsigned_short;
1828 return builtin_type_unsigned_int;
1831 return builtin_type_unsigned_long;
1833 printf ("unexpected type %d at symnum %d\n", c_type, cs->c_symnum);
1834 return builtin_type_void;
1837 /* This page contains subroutines of read_type. */
1839 /* Read the description of a structure (or union type)
1840 and return an object describing the type. */
1842 static struct type *
1843 read_struct_type (index, length, lastsym)
1850 struct nextfield *next;
1854 register struct type *type;
1855 register struct nextfield *list = 0;
1856 struct nextfield *new;
1860 #ifdef NAMES_HAVE_UNDERSCORE
1865 struct coff_symbol member_sym;
1866 register struct coff_symbol *ms = &member_sym;
1867 struct internal_syment sub_sym;
1868 union internal_auxent sub_aux;
1871 type = coff_alloc_type (index);
1872 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1873 TYPE_LENGTH (type) = length;
1875 while (!done && symnum < lastsym && symnum < nlist_nsyms_global)
1877 read_one_sym (ms, &sub_sym, &sub_aux);
1879 name = (name[0] == '_' ? name + offset : name);
1881 switch (ms->c_sclass)
1886 /* Get space to record the next field's data. */
1887 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1891 /* Save the data. */
1892 list->field.name = savestring (name, strlen (name));
1893 list->field.type = decode_type (ms, ms->c_type, &sub_aux);
1894 list->field.bitpos = 8 * ms->c_value;
1895 list->field.bitsize = 0;
1901 /* Get space to record the next field's data. */
1902 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1906 /* Save the data. */
1907 list->field.name = savestring (name, strlen (name));
1908 list->field.type = decode_type (ms, ms->c_type, &sub_aux);
1909 list->field.bitpos = ms->c_value;
1910 list->field.bitsize = sub_aux.x_sym.x_misc.x_lnsz.x_size;
1919 /* Now create the vector of fields, and record how big it is. */
1921 TYPE_NFIELDS (type) = nfields;
1922 TYPE_FIELDS (type) = (struct field *)
1923 obstack_alloc (symbol_obstack, sizeof (struct field) * nfields);
1925 /* Copy the saved-up fields into the field vector. */
1927 for (n = nfields; list; list = list->next)
1928 TYPE_FIELD (type, --n) = list->field;
1933 /* Read a definition of an enumeration type,
1934 and create and return a suitable type object.
1935 Also defines the symbols that represent the values of the type. */
1936 /* Currently assumes it's sizeof (int) and doesn't use length. */
1938 static struct type *
1939 read_enum_type (index, length, lastsym)
1944 register struct symbol *sym;
1945 register struct type *type;
1948 struct pending **symlist;
1949 struct coff_symbol member_sym;
1950 register struct coff_symbol *ms = &member_sym;
1951 struct internal_syment sub_sym;
1952 union internal_auxent sub_aux;
1953 struct pending *osyms, *syms;
1956 #ifdef NAMES_HAVE_UNDERSCORE
1962 type = coff_alloc_type (index);
1963 if (within_function)
1964 symlist = &local_symbols;
1966 symlist = &file_symbols;
1969 while (!done && symnum < lastsym && symnum < nlist_nsyms_global)
1971 read_one_sym (ms, &sub_sym, &sub_aux);
1973 name = (name[0] == '_' ? name + offset : name);
1975 switch (ms->c_sclass)
1978 sym = (struct symbol *) xmalloc (sizeof (struct symbol));
1979 bzero (sym, sizeof (struct symbol));
1981 SYMBOL_NAME (sym) = savestring (name, strlen (name));
1982 SYMBOL_CLASS (sym) = LOC_CONST;
1983 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1984 SYMBOL_VALUE (sym) = ms->c_value;
1985 add_symbol_to_list (sym, symlist);
1990 /* Sometimes the linker (on 386/ix 2.0.2 at least) screws
1991 up the count of how many symbols to read. So stop
1998 /* Now fill in the fields of the type-structure. */
2000 /* FIXME: Should be sizeof (int) on target, not host. */
2001 TYPE_LENGTH (type) = sizeof (int);
2002 TYPE_CODE (type) = TYPE_CODE_ENUM;
2003 TYPE_NFIELDS (type) = nsyms;
2004 TYPE_FIELDS (type) = (struct field *)
2005 obstack_alloc (symbol_obstack, sizeof (struct field) * nsyms);
2007 /* Find the symbols for the values and put them into the type.
2008 The symbols can be found in the symlist that we put them on
2009 to cause them to be defined. osyms contains the old value
2010 of that symlist; everything up to there was defined by us. */
2012 for (syms = *symlist, n = nsyms; syms != osyms; syms = syms->next)
2014 SYMBOL_TYPE (syms->symbol) = type;
2015 TYPE_FIELD_NAME (type, --n) = SYMBOL_NAME (syms->symbol);
2016 TYPE_FIELD_VALUE (type, n) = 0;
2017 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (syms->symbol);
2018 TYPE_FIELD_BITSIZE (type, n) = 0;
2023 /* Register our ability to parse symbols for coff BFD files */
2025 static struct sym_fns coff_sym_fns =
2027 /* This assumes that 88kbcs implies TDESC and TDESC implies 88kbcs.
2028 If that's not true, this can be relaxed, but if it is true,
2029 it will just cause users grief if we try to read the wrong kind
2033 #else /* not TDESC */
2035 #endif /* not TDESC */
2036 coff_new_init, coff_symfile_init,
2037 coff_symfile_read, coff_symfile_discard
2041 _initialize_coffread ()
2043 add_symtab_fns(&coff_sym_fns);