1 /* Read coff symbol tables and convert to internal format, for GDB.
2 Contributed by David D. Johnson, Brown University (ddj@cs.brown.edu).
3 Copyright 1987, 1988, 1989, 1990, 1991, 1992, 1993
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #include "breakpoint.h"
30 #include "complaints.h"
35 #include "libbfd.h" /* FIXME secret internal data from BFD */
36 #include "coff/internal.h" /* Internal format of COFF symbols in BFD */
37 #include "libcoff.h" /* FIXME secret internal data from BFD */
39 /* Translate an external name string into a user-visible name. */
40 #define EXTERNAL_NAME(string, abfd) \
41 (string[0] == bfd_get_symbol_leading_char(abfd)? string+1: string)
43 /* To be an sdb debug type, type must have at least a basic or primary
44 derived type. Using this rather than checking against T_NULL is
45 said to prevent core dumps if we try to operate on Michael Bloom
48 #define SDB_TYPE(type) (BTYPE(type) | (type & N_TMASK))
51 * Convert from an sdb register number to an internal gdb register number.
52 * This should be defined in tm.h, if REGISTER_NAMES is not set up
53 * to map one to one onto the sdb register numbers.
55 #ifndef SDB_REG_TO_REGNUM
56 # define SDB_REG_TO_REGNUM(value) (value)
59 /* Core address of start and end of text of current source file.
60 This comes from a ".text" symbol where x_nlinno > 0. */
62 static CORE_ADDR cur_src_start_addr;
63 static CORE_ADDR cur_src_end_addr;
65 /* Core address of the end of the first object file. */
66 static CORE_ADDR first_object_file_end;
68 /* The addresses of the symbol table stream and number of symbols
69 of the object file we are reading (as copied into core). */
71 static FILE *nlist_stream_global;
72 static int nlist_nsyms_global;
74 /* Vector of line number information. */
76 static struct linetable *line_vector;
78 /* Index of next entry to go in line_vector_index. */
80 static int line_vector_index;
82 /* Last line number recorded in the line vector. */
84 static int prev_line_number;
86 /* Number of elements allocated for line_vector currently. */
88 static int line_vector_length;
90 /* Pointers to scratch storage, used for reading raw symbols and auxents. */
92 static char *temp_sym;
93 static char *temp_aux;
95 /* Local variables that hold the shift and mask values for the
96 COFF file that we are currently reading. These come back to us
97 from BFD, and are referenced by their macro names, as well as
98 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
99 macros from ../internalcoff.h . */
101 static unsigned local_n_btmask;
102 static unsigned local_n_btshft;
103 static unsigned local_n_tmask;
104 static unsigned local_n_tshift;
106 #define N_BTMASK local_n_btmask
107 #define N_BTSHFT local_n_btshft
108 #define N_TMASK local_n_tmask
109 #define N_TSHIFT local_n_tshift
111 /* Local variables that hold the sizes in the file of various COFF structures.
112 (We only need to know this to read them from the file -- BFD will then
113 translate the data in them, into `internal_xxx' structs in the right
114 byte order, alignment, etc.) */
116 static unsigned local_linesz;
117 static unsigned local_symesz;
118 static unsigned local_auxesz;
121 /* Chain of typedefs of pointers to empty struct/union types.
122 They are chained thru the SYMBOL_VALUE_CHAIN. */
124 static struct symbol *opaque_type_chain[HASHSIZE];
127 /* The type of the function we are currently reading in. This is
128 used by define_symbol to record the type of arguments to a function. */
130 struct type *in_function_type;
133 struct pending_block *pending_blocks;
135 /* Complaints about various problems in the file being read */
137 struct complaint ef_complaint =
138 {"Unmatched .ef symbol(s) ignored starting at symnum %d", 0, 0};
140 struct complaint bf_no_aux_complaint =
141 {"`.bf' symbol %d has no aux entry", 0, 0};
143 struct complaint ef_no_aux_complaint =
144 {"`.ef' symbol %d has no aux entry", 0, 0};
146 struct complaint lineno_complaint =
147 {"Line number pointer %d lower than start of line numbers", 0, 0};
149 struct complaint unexpected_type_complaint =
150 {"Unexpected type for symbol %s", 0, 0};
152 struct complaint bad_sclass_complaint =
153 {"Bad n_sclass for symbol %s", 0, 0};
155 struct complaint misordered_blocks_complaint =
156 {"Blocks out of order at address %x", 0, 0};
158 struct complaint tagndx_bad_complaint =
159 {"Symbol table entry for %s has bad tagndx value", 0, 0};
161 struct complaint eb_complaint =
162 {"Mismatched .eb symbol ignored starting at symnum %d", 0, 0};
164 /* Simplified internal version of coff symbol table information */
168 int c_symnum; /* symbol number of this entry */
169 int c_naux; /* 0 if syment only, 1 if syment + auxent, etc */
177 coff_read_struct_type PARAMS ((int, int, int));
180 decode_base_type PARAMS ((struct coff_symbol *, unsigned int,
181 union internal_auxent *));
184 decode_type PARAMS ((struct coff_symbol *, unsigned int,
185 union internal_auxent *));
188 decode_function_type PARAMS ((struct coff_symbol *, unsigned int,
189 union internal_auxent *));
192 coff_read_enum_type PARAMS ((int, int, int));
194 static struct symbol *
195 process_coff_symbol PARAMS ((struct coff_symbol *, union internal_auxent *,
199 patch_opaque_types PARAMS ((struct symtab *));
202 patch_type PARAMS ((struct type *, struct type *));
205 enter_linenos PARAMS ((long, int, int));
208 free_linetab PARAMS ((void));
211 init_lineno PARAMS ((int, long, int));
214 getfilename PARAMS ((union internal_auxent *));
217 getsymname PARAMS ((struct internal_syment *));
220 free_stringtab PARAMS ((void));
223 init_stringtab PARAMS ((int, long));
226 read_one_sym PARAMS ((struct coff_symbol *, struct internal_syment *,
227 union internal_auxent *));
230 read_coff_symtab PARAMS ((long, int, struct objfile *));
233 find_linenos PARAMS ((bfd *, sec_ptr, PTR));
236 coff_symfile_init PARAMS ((struct objfile *));
239 coff_new_init PARAMS ((struct objfile *));
242 coff_symfile_read PARAMS ((struct objfile *, struct section_offsets *, int));
245 coff_symfile_finish PARAMS ((struct objfile *));
248 record_minimal_symbol PARAMS ((char *, CORE_ADDR, enum minimal_symbol_type));
251 coff_end_symtab PARAMS ((struct objfile *));
254 complete_symtab PARAMS ((char *, CORE_ADDR, unsigned int));
257 coff_start_symtab PARAMS ((void));
260 coff_record_line PARAMS ((int, CORE_ADDR));
263 coff_alloc_type PARAMS ((int));
265 static struct type **
266 coff_lookup_type PARAMS ((int));
269 /* Look up a coff type-number index. Return the address of the slot
270 where the type for that index is stored.
271 The type-number is in INDEX.
273 This can be used for finding the type associated with that index
274 or for associating a new type with the index. */
276 static struct type **
277 coff_lookup_type (index)
280 if (index >= type_vector_length)
282 int old_vector_length = type_vector_length;
284 type_vector_length *= 2;
285 if (index /* is still */ >= type_vector_length) {
286 type_vector_length = index * 2;
288 type_vector = (struct type **)
289 xrealloc ((char *) type_vector,
290 type_vector_length * sizeof (struct type *));
291 memset (&type_vector[old_vector_length], 0,
292 (type_vector_length - old_vector_length) * sizeof(struct type *));
294 return &type_vector[index];
297 /* Make sure there is a type allocated for type number index
298 and return the type object.
299 This can create an empty (zeroed) type object. */
302 coff_alloc_type (index)
305 register struct type **type_addr = coff_lookup_type (index);
306 register struct type *type = *type_addr;
308 /* If we are referring to a type not known at all yet,
309 allocate an empty type for it.
310 We will fill it in later if we find out how. */
313 type = alloc_type (current_objfile);
319 /* Manage the vector of line numbers. */
322 coff_record_line (line, pc)
326 struct linetable_entry *e;
327 /* Make sure line vector is big enough. */
329 if (line_vector_index + 2 >= line_vector_length)
331 line_vector_length *= 2;
332 line_vector = (struct linetable *)
333 xrealloc ((char *) line_vector, sizeof (struct linetable)
334 + (line_vector_length
335 * sizeof (struct linetable_entry)));
338 e = line_vector->item + line_vector_index++;
339 e->line = line; e->pc = pc;
342 /* Start a new symtab for a new source file.
343 This is called when a COFF ".file" symbol is seen;
344 it indicates the start of data for one original source file. */
350 /* We fill in the filename later. start_symtab
351 puts this pointer into last_source file and in
352 coff_end_symtab we assume we can free() it.
353 FIXME: leaks memory. */
355 /* We never know the directory name for COFF. */
357 /* The start address is irrelevant, since we set
358 last_source_start_addr in coff_end_symtab. */
361 /* Initialize the source file line number information for this file. */
363 if (line_vector) /* Unlikely, but maybe possible? */
364 free ((PTR)line_vector);
365 line_vector_index = 0;
366 line_vector_length = 1000;
367 prev_line_number = -2; /* Force first line number to be explicit */
368 line_vector = (struct linetable *)
369 xmalloc (sizeof (struct linetable)
370 + line_vector_length * sizeof (struct linetable_entry));
373 /* Save the vital information from when starting to read a file,
374 for use when closing off the current file.
375 NAME is the file name the symbols came from, START_ADDR is the first
376 text address for the file, and SIZE is the number of bytes of text. */
379 complete_symtab (name, start_addr, size)
381 CORE_ADDR start_addr;
384 last_source_file = savestring (name, strlen (name));
385 cur_src_start_addr = start_addr;
386 cur_src_end_addr = start_addr + size;
388 if (current_objfile -> ei.entry_point >= cur_src_start_addr &&
389 current_objfile -> ei.entry_point < cur_src_end_addr)
391 current_objfile -> ei.entry_file_lowpc = cur_src_start_addr;
392 current_objfile -> ei.entry_file_highpc = cur_src_end_addr;
396 /* Finish the symbol definitions for one main source file,
397 close off all the lexical contexts for that file
398 (creating struct block's for them), then make the
399 struct symtab for that file and put it in the list of all such. */
402 coff_end_symtab (objfile)
403 struct objfile *objfile;
405 struct symtab *symtab;
407 last_source_start_addr = cur_src_start_addr;
409 /* For COFF, we only have one subfile, so we can just look at
410 subfiles and not worry about there being other elements in the
411 chain. We fill in various fields now because we didn't know them
412 before (or because doing it now is simply an artifact of how this
413 file used to be written). */
414 subfiles->line_vector = line_vector;
415 subfiles->name = last_source_file;
417 /* sort_pending is needed for amdcoff, at least.
418 sort_linevec is needed for the SCO compiler. */
419 symtab = end_symtab (cur_src_end_addr, 1, 1, objfile, 0);
422 free_named_symtabs (symtab->filename);
424 /* Reinitialize for beginning of new file. */
426 line_vector_length = -1;
427 last_source_file = NULL;
431 record_minimal_symbol (name, address, type)
434 enum minimal_symbol_type type;
436 /* We don't want TDESC entry points in the minimal symbol table */
437 if (name[0] == '@') return;
439 prim_record_minimal_symbol (savestring (name, strlen (name)), address, type);
442 /* coff_symfile_init ()
443 is the coff-specific initialization routine for reading symbols.
444 It is passed a struct objfile which contains, among other things,
445 the BFD for the file whose symbols are being read, and a slot for
446 a pointer to "private data" which we fill with cookies and other
447 treats for coff_symfile_read ().
449 We will only be called if this is a COFF or COFF-like file.
450 BFD handles figuring out the format of the file, and code in symtab.c
451 uses BFD's determination to vector to us.
453 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
455 struct coff_symfile_info {
456 file_ptr min_lineno_offset; /* Where in file lowest line#s are */
457 file_ptr max_lineno_offset; /* 1+last byte of line#s in file */
460 static int text_bfd_scnum;
463 coff_symfile_init (objfile)
464 struct objfile *objfile;
467 bfd *abfd = objfile->obfd;
469 /* Allocate struct to keep track of the symfile */
470 objfile -> sym_private = xmmalloc (objfile -> md,
471 sizeof (struct coff_symfile_info));
473 init_entry_point_info (objfile);
475 /* Save the section number for the text section */
476 section = bfd_get_section_by_name(abfd,".text");
478 text_bfd_scnum = section->index;
483 /* This function is called for every section; it finds the outer limits
484 of the line table (minimum and maximum file offset) so that the
485 mainline code can read the whole thing for efficiency. */
489 find_linenos (abfd, asect, vpinfo)
494 struct coff_symfile_info *info;
496 file_ptr offset, maxoff;
498 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
499 count = asect->lineno_count;
504 size = count * local_linesz;
506 info = (struct coff_symfile_info *)vpinfo;
507 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
508 offset = asect->line_filepos;
511 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
512 info->min_lineno_offset = offset;
514 maxoff = offset + size;
515 if (maxoff > info->max_lineno_offset)
516 info->max_lineno_offset = maxoff;
520 /* The BFD for this file -- only good while we're actively reading
521 symbols into a psymtab or a symtab. */
523 static bfd *symfile_bfd;
525 /* Read a symbol file, after initialization by coff_symfile_init. */
526 /* FIXME! Addr and Mainline are not used yet -- this will not work for
527 shared libraries or add_file! */
531 coff_symfile_read (objfile, section_offsets, mainline)
532 struct objfile *objfile;
533 struct section_offsets *section_offsets;
536 struct coff_symfile_info *info;
537 bfd *abfd = objfile->obfd;
538 coff_data_type *cdata = coff_data (abfd);
539 char *name = bfd_get_filename (abfd);
544 int stringtab_offset;
545 struct cleanup *back_to;
547 info = (struct coff_symfile_info *) objfile -> sym_private;
548 symfile_bfd = abfd; /* Kludge for swap routines */
550 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
551 desc = fileno ((FILE *)(abfd->iostream)); /* File descriptor */
552 num_symbols = bfd_get_symcount (abfd); /* How many syms */
553 symtab_offset = cdata->sym_filepos; /* Symbol table file offset */
554 stringtab_offset = symtab_offset + /* String table file offset */
555 num_symbols * cdata->local_symesz;
557 /* Set a few file-statics that give us specific information about
558 the particular COFF file format we're reading. */
559 local_linesz = cdata->local_linesz;
560 local_n_btmask = cdata->local_n_btmask;
561 local_n_btshft = cdata->local_n_btshft;
562 local_n_tmask = cdata->local_n_tmask;
563 local_n_tshift = cdata->local_n_tshift;
564 local_linesz = cdata->local_linesz;
565 local_symesz = cdata->local_symesz;
566 local_auxesz = cdata->local_auxesz;
568 /* Allocate space for raw symbol and aux entries, based on their
569 space requirements as reported by BFD. */
570 temp_sym = (char *) xmalloc
571 (cdata->local_symesz + cdata->local_auxesz);
572 temp_aux = temp_sym + cdata->local_symesz;
573 back_to = make_cleanup (free_current_contents, &temp_sym);
576 /* Read the line number table, all at once. */
577 info->min_lineno_offset = 0;
578 info->max_lineno_offset = 0;
579 bfd_map_over_sections (abfd, find_linenos, (PTR)info);
581 make_cleanup (free_linetab, 0);
582 val = init_lineno (desc, info->min_lineno_offset,
583 info->max_lineno_offset - info->min_lineno_offset);
585 error ("\"%s\": error reading line numbers\n", name);
587 /* Now read the string table, all at once. */
589 make_cleanup (free_stringtab, 0);
590 val = init_stringtab (desc, stringtab_offset);
592 error ("\"%s\": can't get string table", name);
594 init_minimal_symbol_collection ();
595 make_cleanup (discard_minimal_symbols, 0);
597 /* Now that the executable file is positioned at symbol table,
598 process it and define symbols accordingly. */
600 read_coff_symtab ((long)symtab_offset, num_symbols, objfile);
602 /* Sort symbols alphabetically within each block. */
604 sort_all_symtab_syms ();
606 /* Install any minimal symbols that have been collected as the current
607 minimal symbols for this objfile. */
609 install_minimal_symbols (objfile);
611 do_cleanups (back_to);
615 coff_new_init (ignore)
616 struct objfile *ignore;
621 /* Perform any local cleanups required when we are done with a particular
622 objfile. I.E, we are in the process of discarding all symbol information
623 for an objfile, freeing up all memory held for it, and unlinking the
624 objfile struct from the global list of known objfiles. */
627 coff_symfile_finish (objfile)
628 struct objfile *objfile;
630 if (objfile -> sym_private != NULL)
632 mfree (objfile -> md, objfile -> sym_private);
637 /* Given pointers to a symbol table in coff style exec file,
638 analyze them and create struct symtab's describing the symbols.
639 NSYMS is the number of symbols in the symbol table.
640 We read them one at a time using read_one_sym (). */
643 read_coff_symtab (symtab_offset, nsyms, objfile)
646 struct objfile *objfile;
649 register struct context_stack *new;
650 struct coff_symbol coff_symbol;
651 register struct coff_symbol *cs = &coff_symbol;
652 static struct internal_syment main_sym;
653 static union internal_auxent main_aux;
654 struct coff_symbol fcn_cs_saved;
655 static struct internal_syment fcn_sym_saved;
656 static union internal_auxent fcn_aux_saved;
659 /* A .file is open. */
660 int in_source_file = 0;
661 int num_object_files = 0;
662 int next_file_symnum = -1;
664 /* Name of the current file. */
665 char *filestring = "";
667 int fcn_first_line = 0;
668 int fcn_last_line = 0;
669 int fcn_start_addr = 0;
670 long fcn_line_ptr = 0;
673 stream = bfd_cache_lookup(objfile->obfd);
675 perror_with_name(objfile->name);
677 /* Work around a stdio bug in SunOS4.1.1 (this makes me nervous....
678 it's hard to know I've really worked around it. The fix should be
679 harmless, anyway). The symptom of the bug is that the first
680 fread (in read_one_sym), will (in my example) actually get data
681 from file offset 268, when the fseek was to 264 (and ftell shows
682 264). This causes all hell to break loose. I was unable to
683 reproduce this on a short test program which operated on the same
684 file, performing (I think) the same sequence of operations.
686 It stopped happening when I put in this rewind().
688 FIXME: Find out if this has been reported to Sun, whether it has
689 been fixed in a later release, etc. */
693 /* Position to read the symbol table. */
694 val = fseek (stream, (long)symtab_offset, 0);
696 perror_with_name (objfile->name);
698 current_objfile = objfile;
699 nlist_stream_global = stream;
700 nlist_nsyms_global = nsyms;
701 last_source_file = NULL;
702 memset (opaque_type_chain, 0, sizeof opaque_type_chain);
704 if (type_vector) /* Get rid of previous one */
705 free ((PTR)type_vector);
706 type_vector_length = 160;
707 type_vector = (struct type **)
708 xmalloc (type_vector_length * sizeof (struct type *));
709 memset (type_vector, 0, type_vector_length * sizeof (struct type *));
711 coff_start_symtab ();
714 while (symnum < nsyms)
716 QUIT; /* Make this command interruptable. */
717 read_one_sym (cs, &main_sym, &main_aux);
720 temp_sem_val = cs->c_name[0] << 24 | cs->c_name[1] << 16 |
721 cs->c_name[2] << 8 | cs->c_name[3];
722 if (int_sem_val == temp_sem_val)
723 last_coffsem = (int) strtol (cs->c_name+4, (char **) NULL, 10);
726 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
728 if (last_source_file)
729 coff_end_symtab (objfile);
731 coff_start_symtab ();
732 complete_symtab ("_globals_", 0, first_object_file_end);
733 /* done with all files, everything from here on out is globals */
736 /* Special case for file with type declarations only, no text. */
737 if (!last_source_file && SDB_TYPE (cs->c_type)
738 && cs->c_secnum == N_DEBUG)
739 complete_symtab (filestring, 0, 0);
741 /* Typedefs should not be treated as symbol definitions. */
742 if (ISFCN (cs->c_type) && cs->c_sclass != C_TPDEF)
744 /* Record all functions -- external and static -- in minsyms. */
745 record_minimal_symbol (cs->c_name, cs->c_value, mst_text);
747 fcn_line_ptr = main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
748 fcn_start_addr = cs->c_value;
750 fcn_sym_saved = main_sym;
751 fcn_aux_saved = main_aux;
755 switch (cs->c_sclass)
764 complain (&bad_sclass_complaint, cs->c_name);
769 * c_value field contains symnum of next .file entry in table
770 * or symnum of first global after last .file.
772 next_file_symnum = cs->c_value;
773 filestring = getfilename (&main_aux);
775 * Complete symbol table for last object file
776 * containing debugging information.
778 if (last_source_file)
780 coff_end_symtab (objfile);
781 coff_start_symtab ();
787 if (cs->c_name[0] == '.') {
788 if (STREQ (cs->c_name, ".text")) {
789 /* FIXME: don't wire in ".text" as section name
791 if (++num_object_files == 1) {
792 /* last address of startup file */
793 first_object_file_end = cs->c_value +
794 main_aux.x_scn.x_scnlen;
796 /* Check for in_source_file deals with case of
797 a file with debugging symbols
798 followed by a later file with no symbols. */
800 complete_symtab (filestring, cs->c_value,
801 main_aux.x_scn.x_scnlen);
804 /* flush rest of '.' symbols */
807 else if (!SDB_TYPE (cs->c_type)
808 && cs->c_name[0] == 'L'
809 && (strncmp (cs->c_name, "LI%", 3) == 0
810 || strncmp (cs->c_name, "LF%", 3) == 0
811 || strncmp (cs->c_name,"LC%",3) == 0
812 || strncmp (cs->c_name,"LP%",3) == 0
813 || strncmp (cs->c_name,"LPB%",4) == 0
814 || strncmp (cs->c_name,"LBB%",4) == 0
815 || strncmp (cs->c_name,"LBE%",4) == 0
816 || strncmp (cs->c_name,"LPBX%",5) == 0))
817 /* At least on a 3b1, gcc generates swbeg and string labels
818 that look like this. Ignore them. */
820 /* fall in for static symbols that don't start with '.' */
822 /* Record external symbols in minsyms if we don't have debug
823 info for them. FIXME, this is probably the wrong thing
824 to do. Why don't we record them even if we do have
825 debug symbol info? What really belongs in the minsyms
827 if (!SDB_TYPE (cs->c_type)) {
828 /* FIXME: This is BOGUS Will Robinson!
829 Coff should provide the SEC_CODE flag for executable sections,
830 then if we could look up sections by section number we
831 could see if the flags indicate SEC_CODE. If so, then
832 record this symbol as a function in the minimal symbol table.
833 But why are absolute syms recorded as functions, anyway? */
834 if (cs->c_secnum <= text_bfd_scnum+1) {/* text or abs */
835 record_minimal_symbol (cs->c_name, cs->c_value,
839 record_minimal_symbol (cs->c_name, cs->c_value,
844 process_coff_symbol (cs, &main_aux, objfile);
848 if (STREQ (cs->c_name, ".bf"))
852 /* value contains address of first non-init type code */
853 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
854 contains line number of '{' } */
856 complain (&bf_no_aux_complaint, cs->c_symnum);
857 fcn_first_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
859 /* Might want to check that locals are 0 and
860 context_stack_depth is zero, and complain if not. */
863 new = push_context (depth, fcn_start_addr);
864 fcn_cs_saved.c_name = getsymname (&fcn_sym_saved);
865 new->name = process_coff_symbol (&fcn_cs_saved,
866 &fcn_aux_saved, objfile);
868 else if (STREQ (cs->c_name, ".ef"))
870 /* the value of .ef is the address of epilogue code;
871 not useful for gdb. */
872 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
873 contains number of lines to '}' */
874 new = pop_context ();
875 /* Stack must be empty now. */
876 if (context_stack_depth > 0 || new == NULL)
878 complain (&ef_complaint, cs->c_symnum);
884 complain (&ef_no_aux_complaint, cs->c_symnum);
885 fcn_last_line = 0x7FFFFFFF;
889 fcn_last_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
891 enter_linenos (fcn_line_ptr, fcn_first_line, fcn_last_line);
893 finish_block (new->name, &local_symbols, new->old_blocks,
895 #if defined (FUNCTION_EPILOGUE_SIZE)
896 /* This macro should be defined only on
898 fcn_aux_saved.x_sym.x_misc.x_fsize
899 field is always zero.
900 So use the .bf record information that
901 points to the epilogue and add the size
903 cs->c_value + FUNCTION_EPILOGUE_SIZE,
905 fcn_cs_saved.c_value +
906 fcn_aux_saved.x_sym.x_misc.x_fsize,
915 if (STREQ (cs->c_name, ".bb"))
917 push_context (++depth, cs->c_value);
919 else if (STREQ (cs->c_name, ".eb"))
921 new = pop_context ();
922 if (depth-- != new->depth)
924 complain (&eb_complaint, (char *)symnum);
927 if (local_symbols && context_stack_depth > 0)
929 /* Make a block for the local symbols within. */
930 finish_block (0, &local_symbols, new->old_blocks,
931 new->start_addr, cs->c_value, objfile);
933 /* Now pop locals of block just finished. */
934 local_symbols = new->locals;
939 process_coff_symbol (cs, &main_aux, objfile);
944 if (last_source_file)
945 coff_end_symtab (objfile);
947 /* Patch up any opaque types (references to types that are not defined
948 in the file where they are referenced, e.g. "struct foo *bar"). */
949 ALL_OBJFILE_SYMTABS (objfile, s)
950 patch_opaque_types (s);
952 current_objfile = NULL;
955 /* Routines for reading headers and symbols from executable. */
958 /* Move these XXXMAGIC symbol defns into BFD! */
960 /* Read COFF file header, check magic number,
961 and return number of symbols. */
962 read_file_hdr (chan, file_hdr)
967 if (myread (chan, (char *)file_hdr, FILHSZ) < 0)
970 switch (file_hdr->f_magic)
985 #if defined (MC68KWRMAGIC) \
986 && (!defined (MC68MAGIC) || MC68KWRMAGIC != MC68MAGIC)
1000 case I960ROMAGIC: /* Intel 960 */
1003 case I960RWMAGIC: /* Intel 960 */
1005 return file_hdr->f_nsyms;
1009 if (BADMAG(file_hdr))
1012 return file_hdr->f_nsyms;
1020 /* Read the next symbol, swap it, and return it in both internal_syment
1021 form, and coff_symbol form. Also return its first auxent, if any,
1022 in internal_auxent form, and skip any other auxents. */
1025 read_one_sym (cs, sym, aux)
1026 register struct coff_symbol *cs;
1027 register struct internal_syment *sym;
1028 register union internal_auxent *aux;
1032 cs->c_symnum = symnum;
1033 fread (temp_sym, local_symesz, 1, nlist_stream_global);
1034 bfd_coff_swap_sym_in (symfile_bfd, temp_sym, (char *)sym);
1035 cs->c_naux = sym->n_numaux & 0xff;
1036 if (cs->c_naux >= 1)
1038 fread (temp_aux, local_auxesz, 1, nlist_stream_global);
1039 bfd_coff_swap_aux_in (symfile_bfd, temp_aux, sym->n_type, sym->n_sclass,
1041 /* If more than one aux entry, read past it (only the first aux
1043 for (i = 1; i < cs->c_naux; i++)
1044 fread (temp_aux, local_auxesz, 1, nlist_stream_global);
1046 cs->c_name = getsymname (sym);
1047 cs->c_value = sym->n_value;
1048 cs->c_sclass = (sym->n_sclass & 0xff);
1049 cs->c_secnum = sym->n_scnum;
1050 cs->c_type = (unsigned) sym->n_type;
1051 if (!SDB_TYPE (cs->c_type))
1054 symnum += 1 + cs->c_naux;
1057 /* Support for string table handling */
1059 static char *stringtab = NULL;
1062 init_stringtab (chan, offset)
1068 unsigned char lengthbuf[4];
1072 if (lseek (chan, offset, 0) < 0)
1075 val = myread (chan, (char *)lengthbuf, sizeof lengthbuf);
1076 length = bfd_h_get_32 (symfile_bfd, lengthbuf);
1078 /* If no string table is needed, then the file may end immediately
1079 after the symbols. Just return with `stringtab' set to null. */
1080 if (val != sizeof lengthbuf || length < sizeof lengthbuf)
1083 stringtab = (char *) xmalloc (length);
1084 memcpy (stringtab, &length, sizeof length);
1085 if (length == sizeof length) /* Empty table -- just the count */
1088 val = myread (chan, stringtab + sizeof lengthbuf, length - sizeof lengthbuf);
1089 if (val != length - sizeof lengthbuf || stringtab[length - 1] != '\0')
1104 getsymname (symbol_entry)
1105 struct internal_syment *symbol_entry;
1107 static char buffer[SYMNMLEN+1];
1110 if (symbol_entry->_n._n_n._n_zeroes == 0)
1112 result = stringtab + symbol_entry->_n._n_n._n_offset;
1116 strncpy (buffer, symbol_entry->_n._n_name, SYMNMLEN);
1117 buffer[SYMNMLEN] = '\0';
1123 /* Extract the file name from the aux entry of a C_FILE symbol. Return
1124 only the last component of the name. Result is in static storage and
1125 is only good for temporary use. */
1128 getfilename (aux_entry)
1129 union internal_auxent *aux_entry;
1131 static char buffer[BUFSIZ];
1132 register char *temp;
1135 if (aux_entry->x_file.x_n.x_zeroes == 0)
1136 strcpy (buffer, stringtab + aux_entry->x_file.x_n.x_offset);
1139 strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
1140 buffer[FILNMLEN] = '\0';
1143 if ((temp = strrchr (result, '/')) != NULL)
1148 /* Support for line number handling */
1149 static char *linetab = NULL;
1150 static long linetab_offset;
1151 static unsigned long linetab_size;
1153 /* Read in all the line numbers for fast lookups later. Leave them in
1154 external (unswapped) format in memory; we'll swap them as we enter
1155 them into GDB's data structures. */
1158 init_lineno (chan, offset, size)
1165 linetab_offset = offset;
1166 linetab_size = size;
1173 if (lseek (chan, offset, 0) < 0)
1176 /* Allocate the desired table, plus a sentinel */
1177 linetab = (char *) xmalloc (size + local_linesz);
1179 val = myread (chan, linetab, size);
1183 /* Terminate it with an all-zero sentinel record */
1184 memset (linetab + size, 0, local_linesz);
1197 #if !defined (L_LNNO32)
1198 #define L_LNNO32(lp) ((lp)->l_lnno)
1202 enter_linenos (file_offset, first_line, last_line)
1204 register int first_line;
1205 register int last_line;
1207 register char *rawptr;
1208 struct internal_lineno lptr;
1210 if (file_offset < linetab_offset)
1212 complain (&lineno_complaint, file_offset);
1213 if (file_offset > linetab_size) /* Too big to be an offset? */
1215 file_offset += linetab_offset; /* Try reading at that linetab offset */
1218 rawptr = &linetab[file_offset - linetab_offset];
1220 /* skip first line entry for each function */
1221 rawptr += local_linesz;
1222 /* line numbers start at one for the first line of the function */
1226 bfd_coff_swap_lineno_in (symfile_bfd, rawptr, &lptr);
1227 rawptr += local_linesz;
1228 /* The next function, or the sentinel, will have L_LNNO32 zero; we exit. */
1229 if (L_LNNO32 (&lptr) && L_LNNO32 (&lptr) <= last_line)
1230 coff_record_line (first_line + L_LNNO32 (&lptr), lptr.l_addr.l_paddr);
1237 patch_type (type, real_type)
1239 struct type *real_type;
1241 register struct type *target = TYPE_TARGET_TYPE (type);
1242 register struct type *real_target = TYPE_TARGET_TYPE (real_type);
1243 int field_size = TYPE_NFIELDS (real_target) * sizeof (struct field);
1245 TYPE_LENGTH (target) = TYPE_LENGTH (real_target);
1246 TYPE_NFIELDS (target) = TYPE_NFIELDS (real_target);
1247 TYPE_FIELDS (target) = (struct field *) TYPE_ALLOC (target, field_size);
1249 memcpy (TYPE_FIELDS (target), TYPE_FIELDS (real_target), field_size);
1251 if (TYPE_NAME (real_target))
1253 if (TYPE_NAME (target))
1254 free (TYPE_NAME (target));
1255 TYPE_NAME (target) = concat (TYPE_NAME (real_target), NULL);
1259 /* Patch up all appropriate typedef symbols in the opaque_type_chains
1260 so that they can be used to print out opaque data structures properly. */
1263 patch_opaque_types (s)
1266 register struct block *b;
1268 register struct symbol *real_sym;
1270 /* Go through the per-file symbols only */
1271 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
1272 for (i = BLOCK_NSYMS (b) - 1; i >= 0; i--)
1274 /* Find completed typedefs to use to fix opaque ones.
1275 Remove syms from the chain when their types are stored,
1276 but search the whole chain, as there may be several syms
1277 from different files with the same name. */
1278 real_sym = BLOCK_SYM (b, i);
1279 if (SYMBOL_CLASS (real_sym) == LOC_TYPEDEF &&
1280 SYMBOL_NAMESPACE (real_sym) == VAR_NAMESPACE &&
1281 TYPE_CODE (SYMBOL_TYPE (real_sym)) == TYPE_CODE_PTR &&
1282 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym))) != 0)
1284 register char *name = SYMBOL_NAME (real_sym);
1285 register int hash = hashname (name);
1286 register struct symbol *sym, *prev;
1289 for (sym = opaque_type_chain[hash]; sym;)
1291 if (name[0] == SYMBOL_NAME (sym)[0] &&
1292 STREQ (name + 1, SYMBOL_NAME (sym) + 1))
1296 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
1300 opaque_type_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
1303 patch_type (SYMBOL_TYPE (sym), SYMBOL_TYPE (real_sym));
1307 sym = SYMBOL_VALUE_CHAIN (prev);
1311 sym = opaque_type_chain[hash];
1317 sym = SYMBOL_VALUE_CHAIN (sym);
1324 static struct symbol *
1325 process_coff_symbol (cs, aux, objfile)
1326 register struct coff_symbol *cs;
1327 register union internal_auxent *aux;
1328 struct objfile *objfile;
1330 register struct symbol *sym
1331 = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1332 sizeof (struct symbol));
1334 struct type *temptype;
1336 memset (sym, 0, sizeof (struct symbol));
1338 name = EXTERNAL_NAME (name, objfile->obfd);
1339 SYMBOL_NAME (sym) = obstack_copy0 (&objfile->symbol_obstack, name,
1342 /* default assumptions */
1343 SYMBOL_VALUE (sym) = cs->c_value;
1344 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1346 if (ISFCN (cs->c_type))
1349 /* FIXME: This has NOT been tested. The DBX version has.. */
1350 /* Generate a template for the type of this function. The
1351 types of the arguments will be added as we read the symbol
1353 struct type *new = (struct type *)
1354 obstack_alloc (&objfile->symbol_obstack, sizeof (struct type));
1356 memcpy (new, lookup_function_type (decode_function_type (cs, cs->c_type, aux)),
1357 sizeof(struct type));
1358 SYMBOL_TYPE (sym) = new;
1359 in_function_type = SYMBOL_TYPE(sym);
1362 lookup_function_type (decode_function_type (cs, cs->c_type, aux));
1365 SYMBOL_CLASS (sym) = LOC_BLOCK;
1366 if (cs->c_sclass == C_STAT)
1367 add_symbol_to_list (sym, &file_symbols);
1368 else if (cs->c_sclass == C_EXT)
1369 add_symbol_to_list (sym, &global_symbols);
1373 SYMBOL_TYPE (sym) = decode_type (cs, cs->c_type, aux);
1374 switch (cs->c_sclass)
1380 SYMBOL_CLASS (sym) = LOC_LOCAL;
1381 add_symbol_to_list (sym, &local_symbols);
1385 SYMBOL_CLASS (sym) = LOC_STATIC;
1386 SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
1387 add_symbol_to_list (sym, &global_symbols);
1391 SYMBOL_CLASS (sym) = LOC_STATIC;
1392 SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
1393 if (within_function) {
1394 /* Static symbol of local scope */
1395 add_symbol_to_list (sym, &local_symbols);
1398 /* Static symbol at top level of file */
1399 add_symbol_to_list (sym, &file_symbols);
1403 #ifdef C_GLBLREG /* AMD coff */
1407 SYMBOL_CLASS (sym) = LOC_REGISTER;
1408 SYMBOL_VALUE (sym) = SDB_REG_TO_REGNUM(cs->c_value);
1409 add_symbol_to_list (sym, &local_symbols);
1416 SYMBOL_CLASS (sym) = LOC_ARG;
1418 /* FIXME: This has not been tested. */
1419 /* Add parameter to function. */
1420 add_param_to_type(&in_function_type,sym);
1422 add_symbol_to_list (sym, &local_symbols);
1423 #if !defined (BELIEVE_PCC_PROMOTION) && (TARGET_BYTE_ORDER == BIG_ENDIAN)
1424 /* If PCC says a parameter is a short or a char,
1425 aligned on an int boundary, realign it to the "little end"
1427 temptype = lookup_fundamental_type (current_objfile, FT_INTEGER);
1428 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
1429 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
1430 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (temptype))
1432 SYMBOL_VALUE (sym) += TYPE_LENGTH (temptype)
1433 - TYPE_LENGTH (SYMBOL_TYPE (sym));
1439 SYMBOL_CLASS (sym) = LOC_REGPARM;
1440 SYMBOL_VALUE (sym) = SDB_REG_TO_REGNUM(cs->c_value);
1441 add_symbol_to_list (sym, &local_symbols);
1442 #if !defined (BELIEVE_PCC_PROMOTION)
1443 /* FIXME: This should retain the current type, since it's just
1444 a register value. gnu@adobe, 26Feb93 */
1445 /* If PCC says a parameter is a short or a char,
1446 it is really an int. */
1447 temptype = lookup_fundamental_type (current_objfile, FT_INTEGER);
1448 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
1449 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
1451 SYMBOL_TYPE (sym) = TYPE_UNSIGNED (SYMBOL_TYPE (sym))
1452 ? lookup_fundamental_type (current_objfile,
1453 FT_UNSIGNED_INTEGER)
1460 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1461 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1463 /* If type has no name, give it one */
1464 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
1465 TYPE_NAME (SYMBOL_TYPE (sym)) = concat (SYMBOL_NAME (sym), NULL);
1467 /* Keep track of any type which points to empty structured type,
1468 so it can be filled from a definition from another file. A
1469 simple forward reference (TYPE_CODE_UNDEF) is not an
1470 empty structured type, though; the forward references
1471 work themselves out via the magic of coff_lookup_type. */
1472 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR &&
1473 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym))) == 0 &&
1474 TYPE_CODE (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym))) !=
1477 register int i = hashname (SYMBOL_NAME (sym));
1479 SYMBOL_VALUE_CHAIN (sym) = opaque_type_chain[i];
1480 opaque_type_chain[i] = sym;
1482 add_symbol_to_list (sym, &file_symbols);
1488 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1489 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1491 /* Some compilers try to be helpful by inventing "fake"
1492 names for anonymous enums, structures, and unions, like
1493 "~0fake" or ".0fake". Thanks, but no thanks... */
1494 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
1495 if (SYMBOL_NAME(sym) != NULL
1496 && *SYMBOL_NAME(sym) != '~'
1497 && *SYMBOL_NAME(sym) != '.')
1498 TYPE_TAG_NAME (SYMBOL_TYPE (sym)) =
1499 concat (SYMBOL_NAME (sym), NULL);
1501 add_symbol_to_list (sym, &file_symbols);
1511 /* Decode a coff type specifier;
1512 return the type that is meant. */
1516 decode_type (cs, c_type, aux)
1517 register struct coff_symbol *cs;
1518 unsigned int c_type;
1519 register union internal_auxent *aux;
1521 register struct type *type = 0;
1522 unsigned int new_c_type;
1524 if (c_type & ~N_BTMASK)
1526 new_c_type = DECREF (c_type);
1529 type = decode_type (cs, new_c_type, aux);
1530 type = lookup_pointer_type (type);
1532 else if (ISFCN (c_type))
1534 type = decode_type (cs, new_c_type, aux);
1535 type = lookup_function_type (type);
1537 else if (ISARY (c_type))
1540 register unsigned short *dim;
1541 struct type *base_type, *index_type, *range_type;
1543 /* Define an array type. */
1544 /* auxent refers to array, not base type */
1545 if (aux->x_sym.x_tagndx.l == 0)
1548 /* shift the indices down */
1549 dim = &aux->x_sym.x_fcnary.x_ary.x_dimen[0];
1552 for (i = 0; *dim && i < DIMNUM - 1; i++, dim++)
1556 base_type = decode_type (cs, new_c_type, aux);
1557 index_type = lookup_fundamental_type (current_objfile, FT_INTEGER);
1559 create_range_type ((struct type *) NULL, index_type, 0, n - 1);
1561 create_array_type ((struct type *) NULL, base_type, range_type);
1566 /* Reference to existing type. This only occurs with the
1567 struct, union, and enum types. EPI a29k coff
1568 fakes us out by producing aux entries with a nonzero
1569 x_tagndx for definitions of structs, unions, and enums, so we
1570 have to check the c_sclass field. SCO 3.2v4 cc gets confused
1571 with pointers to pointers to defined structs, and generates
1572 negative x_tagndx fields. */
1573 if (cs->c_naux > 0 && aux->x_sym.x_tagndx.l != 0)
1575 if (cs->c_sclass != C_STRTAG
1576 && cs->c_sclass != C_UNTAG
1577 && cs->c_sclass != C_ENTAG
1578 && aux->x_sym.x_tagndx.l >= 0)
1580 type = coff_alloc_type (aux->x_sym.x_tagndx.l);
1583 complain (&tagndx_bad_complaint, cs->c_name);
1584 /* And fall through to decode_base_type... */
1588 return decode_base_type (cs, BTYPE (c_type), aux);
1591 /* Decode a coff type specifier for function definition;
1592 return the type that the function returns. */
1596 decode_function_type (cs, c_type, aux)
1597 register struct coff_symbol *cs;
1598 unsigned int c_type;
1599 register union internal_auxent *aux;
1601 if (aux->x_sym.x_tagndx.l == 0)
1602 cs->c_naux = 0; /* auxent refers to function, not base type */
1604 return decode_type (cs, DECREF (c_type), aux);
1611 decode_base_type (cs, c_type, aux)
1612 register struct coff_symbol *cs;
1613 unsigned int c_type;
1614 register union internal_auxent *aux;
1621 /* shows up with "void (*foo)();" structure members */
1622 return lookup_fundamental_type (current_objfile, FT_VOID);
1625 /* DGUX actually defines both T_ARG and T_VOID to the same value. */
1628 /* Shows up in DGUX, I think. Not sure where. */
1629 return lookup_fundamental_type (current_objfile, FT_VOID); /* shouldn't show up here */
1635 /* Intel 960 COFF has this symbol and meaning. */
1636 return lookup_fundamental_type (current_objfile, FT_VOID);
1640 return lookup_fundamental_type (current_objfile, FT_CHAR);
1643 return lookup_fundamental_type (current_objfile, FT_SHORT);
1646 return lookup_fundamental_type (current_objfile, FT_INTEGER);
1649 return lookup_fundamental_type (current_objfile, FT_LONG);
1652 return lookup_fundamental_type (current_objfile, FT_FLOAT);
1655 return lookup_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT);
1658 if (cs->c_naux != 1)
1660 /* anonymous structure type */
1661 type = coff_alloc_type (cs->c_symnum);
1662 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1663 TYPE_NAME (type) = NULL;
1664 /* This used to set the tag to "<opaque>". But I think setting it
1665 to NULL is right, and the printing code can print it as
1667 TYPE_TAG_NAME (type) = NULL;
1668 INIT_CPLUS_SPECIFIC(type);
1669 TYPE_LENGTH (type) = 0;
1670 TYPE_FIELDS (type) = 0;
1671 TYPE_NFIELDS (type) = 0;
1675 type = coff_read_struct_type (cs->c_symnum,
1676 aux->x_sym.x_misc.x_lnsz.x_size,
1677 aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
1682 if (cs->c_naux != 1)
1684 /* anonymous union type */
1685 type = coff_alloc_type (cs->c_symnum);
1686 TYPE_NAME (type) = NULL;
1687 /* This used to set the tag to "<opaque>". But I think setting it
1688 to NULL is right, and the printing code can print it as
1690 TYPE_TAG_NAME (type) = NULL;
1691 INIT_CPLUS_SPECIFIC(type);
1692 TYPE_LENGTH (type) = 0;
1693 TYPE_FIELDS (type) = 0;
1694 TYPE_NFIELDS (type) = 0;
1698 type = coff_read_struct_type (cs->c_symnum,
1699 aux->x_sym.x_misc.x_lnsz.x_size,
1700 aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
1702 TYPE_CODE (type) = TYPE_CODE_UNION;
1706 if (cs->c_naux != 1)
1708 /* anonymous enum type */
1709 type = coff_alloc_type (cs->c_symnum);
1710 TYPE_CODE (type) = TYPE_CODE_ENUM;
1711 TYPE_NAME (type) = NULL;
1712 /* This used to set the tag to "<opaque>". But I think setting it
1713 to NULL is right, and the printing code can print it as
1715 TYPE_TAG_NAME (type) = NULL;
1716 TYPE_LENGTH (type) = 0;
1717 TYPE_FIELDS (type) = 0;
1718 TYPE_NFIELDS(type) = 0;
1722 type = coff_read_enum_type (cs->c_symnum,
1723 aux->x_sym.x_misc.x_lnsz.x_size,
1724 aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
1729 /* shouldn't show up here */
1733 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_CHAR);
1736 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_SHORT);
1739 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER);
1742 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_LONG);
1744 complain (&unexpected_type_complaint, cs->c_name);
1745 return lookup_fundamental_type (current_objfile, FT_VOID);
1748 /* This page contains subroutines of read_type. */
1750 /* Read the description of a structure (or union type)
1751 and return an object describing the type. */
1753 static struct type *
1754 coff_read_struct_type (index, length, lastsym)
1761 struct nextfield *next;
1765 register struct type *type;
1766 register struct nextfield *list = 0;
1767 struct nextfield *new;
1771 struct coff_symbol member_sym;
1772 register struct coff_symbol *ms = &member_sym;
1773 struct internal_syment sub_sym;
1774 union internal_auxent sub_aux;
1777 type = coff_alloc_type (index);
1778 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1779 INIT_CPLUS_SPECIFIC(type);
1780 TYPE_LENGTH (type) = length;
1782 while (!done && symnum < lastsym && symnum < nlist_nsyms_global)
1784 read_one_sym (ms, &sub_sym, &sub_aux);
1786 name = EXTERNAL_NAME (name, current_objfile->obfd);
1788 switch (ms->c_sclass)
1793 /* Get space to record the next field's data. */
1794 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1798 /* Save the data. */
1799 list->field.name = savestring (name, strlen (name));
1800 list->field.type = decode_type (ms, ms->c_type, &sub_aux);
1801 list->field.bitpos = 8 * ms->c_value;
1802 list->field.bitsize = 0;
1808 /* Get space to record the next field's data. */
1809 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1813 /* Save the data. */
1814 list->field.name = savestring (name, strlen (name));
1815 list->field.type = decode_type (ms, ms->c_type, &sub_aux);
1816 list->field.bitpos = ms->c_value;
1817 list->field.bitsize = sub_aux.x_sym.x_misc.x_lnsz.x_size;
1826 /* Now create the vector of fields, and record how big it is. */
1828 TYPE_NFIELDS (type) = nfields;
1829 TYPE_FIELDS (type) = (struct field *)
1830 TYPE_ALLOC (type, sizeof (struct field) * nfields);
1832 /* Copy the saved-up fields into the field vector. */
1834 for (n = nfields; list; list = list->next)
1835 TYPE_FIELD (type, --n) = list->field;
1840 /* Read a definition of an enumeration type,
1841 and create and return a suitable type object.
1842 Also defines the symbols that represent the values of the type. */
1845 static struct type *
1846 coff_read_enum_type (index, length, lastsym)
1851 register struct symbol *sym;
1852 register struct type *type;
1855 struct pending **symlist;
1856 struct coff_symbol member_sym;
1857 register struct coff_symbol *ms = &member_sym;
1858 struct internal_syment sub_sym;
1859 union internal_auxent sub_aux;
1860 struct pending *osyms, *syms;
1865 type = coff_alloc_type (index);
1866 if (within_function)
1867 symlist = &local_symbols;
1869 symlist = &file_symbols;
1871 o_nsyms = osyms ? osyms->nsyms : 0;
1873 while (!done && symnum < lastsym && symnum < nlist_nsyms_global)
1875 read_one_sym (ms, &sub_sym, &sub_aux);
1877 name = EXTERNAL_NAME (name, current_objfile->obfd);
1879 switch (ms->c_sclass)
1882 sym = (struct symbol *) xmalloc (sizeof (struct symbol));
1883 memset (sym, 0, sizeof (struct symbol));
1885 SYMBOL_NAME (sym) = savestring (name, strlen (name));
1886 SYMBOL_CLASS (sym) = LOC_CONST;
1887 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1888 SYMBOL_VALUE (sym) = ms->c_value;
1889 add_symbol_to_list (sym, symlist);
1894 /* Sometimes the linker (on 386/ix 2.0.2 at least) screws
1895 up the count of how many symbols to read. So stop
1902 /* Now fill in the fields of the type-structure. */
1905 TYPE_LENGTH (type) = length;
1907 TYPE_LENGTH (type) = TARGET_INT_BIT / TARGET_CHAR_BIT; /* Assume ints */
1908 TYPE_CODE (type) = TYPE_CODE_ENUM;
1909 TYPE_NFIELDS (type) = nsyms;
1910 TYPE_FIELDS (type) = (struct field *)
1911 TYPE_ALLOC (type, sizeof (struct field) * nsyms);
1913 /* Find the symbols for the values and put them into the type.
1914 The symbols can be found in the symlist that we put them on
1915 to cause them to be defined. osyms contains the old value
1916 of that symlist; everything up to there was defined by us. */
1917 /* Note that we preserve the order of the enum constants, so
1918 that in something like "enum {FOO, LAST_THING=FOO}" we print
1919 FOO, not LAST_THING. */
1921 for (syms = *symlist, n = 0; syms; syms = syms->next)
1926 for (; j < syms->nsyms; j++,n++)
1928 struct symbol *xsym = syms->symbol[j];
1929 SYMBOL_TYPE (xsym) = type;
1930 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1931 TYPE_FIELD_VALUE (type, n) = 0;
1932 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
1933 TYPE_FIELD_BITSIZE (type, n) = 0;
1940 /* This screws up perfectly good C programs with enums. FIXME. */
1941 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
1942 if(TYPE_NFIELDS(type) == 2 &&
1943 ((STREQ(TYPE_FIELD_NAME(type,0),"TRUE") &&
1944 STREQ(TYPE_FIELD_NAME(type,1),"FALSE")) ||
1945 (STREQ(TYPE_FIELD_NAME(type,1),"TRUE") &&
1946 STREQ(TYPE_FIELD_NAME(type,0),"FALSE"))))
1947 TYPE_CODE(type) = TYPE_CODE_BOOL;
1952 /* Fake up support for relocating symbol addresses. FIXME. */
1954 struct section_offsets coff_symfile_faker = {0};
1956 struct section_offsets *
1957 coff_symfile_offsets (objfile, addr)
1958 struct objfile *objfile;
1961 return &coff_symfile_faker;
1964 /* Register our ability to parse symbols for coff BFD files */
1966 static struct sym_fns coff_sym_fns =
1968 "coff", /* sym_name: name or name prefix of BFD target type */
1969 4, /* sym_namelen: number of significant sym_name chars */
1970 coff_new_init, /* sym_new_init: init anything gbl to entire symtab */
1971 coff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
1972 coff_symfile_read, /* sym_read: read a symbol file into symtab */
1973 coff_symfile_finish, /* sym_finish: finished with file, cleanup */
1974 coff_symfile_offsets, /* sym_offsets: xlate external to internal form */
1975 NULL /* next: pointer to next struct sym_fns */
1979 _initialize_coffread ()
1981 add_symtab_fns(&coff_sym_fns);