1 /* Read coff symbol tables and convert to internal format, for GDB.
2 Copyright 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994
3 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"
32 #include "coff/internal.h" /* Internal format of COFF symbols in BFD */
33 #include "libcoff.h" /* FIXME secret internal data from BFD */
38 #include "gdb-stabs.h"
39 #include "stabsread.h"
40 #include "complaints.h"
42 struct coff_symfile_info {
43 file_ptr min_lineno_offset; /* Where in file lowest line#s are */
44 file_ptr max_lineno_offset; /* 1+last byte of line#s in file */
46 asection *stabsect; /* Section pointer for .stab section */
47 asection *stabstrsect; /* Section pointer for .stab section */
48 asection *stabindexsect; /* Section pointer for .stab.index section */
52 /* Translate an external name string into a user-visible name. */
53 #define EXTERNAL_NAME(string, abfd) \
54 (string[0] == bfd_get_symbol_leading_char(abfd)? string+1: string)
56 /* To be an sdb debug type, type must have at least a basic or primary
57 derived type. Using this rather than checking against T_NULL is
58 said to prevent core dumps if we try to operate on Michael Bloom
61 #define SDB_TYPE(type) (BTYPE(type) | (type & N_TMASK))
63 /* Convert from an sdb register number to an internal gdb register number.
64 This should be defined in tm.h, if REGISTER_NAMES is not set up
65 to map one to one onto the sdb register numbers. */
67 #ifndef SDB_REG_TO_REGNUM
68 # define SDB_REG_TO_REGNUM(value) (value)
71 /* Core address of start and end of text of current source file.
72 This comes from a ".text" symbol where x_nlinno > 0. */
74 static CORE_ADDR current_source_start_addr;
75 static CORE_ADDR current_source_end_addr;
77 /* The addresses of the symbol table stream and number of symbols
78 of the object file we are reading (as copied into core). */
80 static bfd *nlist_bfd_global;
81 static int nlist_nsyms_global;
83 /* Vector of line number information. */
85 static struct linetable *line_vector;
87 /* Index of next entry to go in line_vector_index. */
89 static int line_vector_index;
91 /* Last line number recorded in the line vector. */
93 static int prev_line_number;
95 /* Number of elements allocated for line_vector currently. */
97 static int line_vector_length;
99 /* Pointers to scratch storage, used for reading raw symbols and auxents. */
101 static char *temp_sym;
102 static char *temp_aux;
104 /* Local variables that hold the shift and mask values for the
105 COFF file that we are currently reading. These come back to us
106 from BFD, and are referenced by their macro names, as well as
107 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
108 macros from include/coff/internal.h . */
110 static unsigned local_n_btmask;
111 static unsigned local_n_btshft;
112 static unsigned local_n_tmask;
113 static unsigned local_n_tshift;
115 #define N_BTMASK local_n_btmask
116 #define N_BTSHFT local_n_btshft
117 #define N_TMASK local_n_tmask
118 #define N_TSHIFT local_n_tshift
120 /* Local variables that hold the sizes in the file of various COFF structures.
121 (We only need to know this to read them from the file -- BFD will then
122 translate the data in them, into `internal_xxx' structs in the right
123 byte order, alignment, etc.) */
125 static unsigned local_linesz;
126 static unsigned local_symesz;
127 static unsigned local_auxesz;
129 /* Chain of typedefs of pointers to empty struct/union types.
130 They are chained thru the SYMBOL_VALUE_CHAIN. */
132 static struct symbol *opaque_type_chain[HASHSIZE];
135 /* The type of the function we are currently reading in. This is
136 used by define_symbol to record the type of arguments to a function. */
138 struct type *in_function_type;
141 /* Complaints about various problems in the file being read */
143 struct complaint ef_complaint =
144 {"Unmatched .ef symbol(s) ignored starting at symnum %d", 0, 0};
146 struct complaint bf_no_aux_complaint =
147 {"`.bf' symbol %d has no aux entry", 0, 0};
149 struct complaint ef_no_aux_complaint =
150 {"`.ef' symbol %d has no aux entry", 0, 0};
152 struct complaint lineno_complaint =
153 {"Line number pointer %d lower than start of line numbers", 0, 0};
155 struct complaint unexpected_type_complaint =
156 {"Unexpected type for symbol %s", 0, 0};
158 struct complaint bad_sclass_complaint =
159 {"Bad n_sclass for symbol %s", 0, 0};
161 struct complaint misordered_blocks_complaint =
162 {"Blocks out of order at address %x", 0, 0};
164 struct complaint tagndx_bad_complaint =
165 {"Symbol table entry for %s has bad tagndx value", 0, 0};
167 struct complaint eb_complaint =
168 {"Mismatched .eb symbol ignored starting at symnum %d", 0, 0};
170 /* Simplified internal version of coff symbol table information */
174 int c_symnum; /* symbol number of this entry */
175 int c_naux; /* 0 if syment only, 1 if syment + auxent, etc */
182 static struct type *coff_read_struct_type PARAMS ((int, int, int));
184 static struct type *decode_base_type PARAMS ((struct coff_symbol *,
186 union internal_auxent *));
188 static struct type *decode_type PARAMS ((struct coff_symbol *, unsigned int,
189 union internal_auxent *));
191 static struct type *decode_function_type PARAMS ((struct coff_symbol *,
193 union internal_auxent *));
195 static struct type *coff_read_enum_type PARAMS ((int, int, int));
197 static struct symbol *process_coff_symbol PARAMS ((struct coff_symbol *,
198 union internal_auxent *,
199 struct section_offsets *,
202 static void patch_opaque_types PARAMS ((struct symtab *));
204 static void patch_type PARAMS ((struct type *, struct type *));
206 static void enter_linenos PARAMS ((long, int, int, struct section_offsets *));
208 static void free_linetab PARAMS ((void));
210 static int init_lineno PARAMS ((bfd *, long, int));
212 static char *getsymname PARAMS ((struct internal_syment *));
214 static void free_stringtab PARAMS ((void));
216 static int init_stringtab PARAMS ((bfd *, long));
218 static void read_one_sym PARAMS ((struct coff_symbol *,
219 struct internal_syment *,
220 union internal_auxent *));
222 static void coff_symtab_read PARAMS ((long, int, struct section_offsets *,
225 static void find_linenos PARAMS ((bfd *, sec_ptr, PTR));
227 static void coff_symfile_init PARAMS ((struct objfile *));
229 static void coff_new_init PARAMS ((struct objfile *));
231 static void coff_symfile_read PARAMS ((struct objfile *,
232 struct section_offsets *, int));
234 static void coff_symfile_finish PARAMS ((struct objfile *));
236 static void record_minimal_symbol PARAMS ((char *, CORE_ADDR,
237 enum minimal_symbol_type,
240 static void coff_end_symtab PARAMS ((struct objfile *));
242 static void complete_symtab PARAMS ((char *, CORE_ADDR, unsigned int));
244 static void coff_start_symtab PARAMS ((void));
246 static void coff_record_line PARAMS ((int, CORE_ADDR));
248 static struct type *coff_alloc_type PARAMS ((int));
250 static struct type **coff_lookup_type PARAMS ((int));
252 static void coff_locate_sections PARAMS ((bfd *, asection *, PTR));
254 /* We are called once per section from coff_symfile_read. We
255 need to examine each section we are passed, check to see
256 if it is something we are interested in processing, and
257 if so, stash away some access information for the section.
259 FIXME: The section names should not be hardwired strings (what
260 should they be? I don't think most object file formats have enough
261 section flags to specify what kind of debug section it is
265 coff_locate_sections (ignore_abfd, sectp, csip)
270 register struct coff_symfile_info *csi;
272 csi = (struct coff_symfile_info *) csip;
273 if (STREQ (sectp->name, ".stab"))
275 csi->stabsect = sectp;
277 else if (STREQ (sectp->name, ".stabstr"))
279 csi->stabstrsect = sectp;
281 else if (STREQ (sectp->name, ".stab.index"))
283 csi->stabindexsect = sectp;
287 /* Look up a coff type-number index. Return the address of the slot
288 where the type for that index is stored.
289 The type-number is in INDEX.
291 This can be used for finding the type associated with that index
292 or for associating a new type with the index. */
294 static struct type **
295 coff_lookup_type (index)
298 if (index >= type_vector_length)
300 int old_vector_length = type_vector_length;
302 type_vector_length *= 2;
303 if (index /* is still */ >= type_vector_length)
304 type_vector_length = index * 2;
306 type_vector = (struct type **)
307 xrealloc ((char *) type_vector,
308 type_vector_length * sizeof (struct type *));
309 memset (&type_vector[old_vector_length], 0,
310 (type_vector_length - old_vector_length) * sizeof(struct type *));
312 return &type_vector[index];
315 /* Make sure there is a type allocated for type number index
316 and return the type object.
317 This can create an empty (zeroed) type object. */
320 coff_alloc_type (index)
323 register struct type **type_addr = coff_lookup_type (index);
324 register struct type *type = *type_addr;
326 /* If we are referring to a type not known at all yet,
327 allocate an empty type for it.
328 We will fill it in later if we find out how. */
331 type = alloc_type (current_objfile);
337 /* Record a line number entry for line LINE at address PC.
338 FIXME: Use record_line instead. */
341 coff_record_line (line, pc)
345 struct linetable_entry *e;
346 /* Make sure line vector is big enough. */
348 if (line_vector_index + 2 >= line_vector_length)
350 line_vector_length *= 2;
351 line_vector = (struct linetable *)
352 xrealloc ((char *) line_vector, sizeof (struct linetable)
353 + (line_vector_length
354 * sizeof (struct linetable_entry)));
357 e = line_vector->item + line_vector_index++;
358 e->line = line; e->pc = pc;
361 /* Start a new symtab for a new source file.
362 This is called when a COFF ".file" symbol is seen;
363 it indicates the start of data for one original source file. */
369 /* We fill in the filename later. start_symtab
370 puts this pointer into last_source file and in
371 coff_end_symtab we assume we can free() it.
372 FIXME: leaks memory. */
374 /* We never know the directory name for COFF. */
376 /* The start address is irrelevant, since we set
377 last_source_start_addr in coff_end_symtab. */
380 /* Initialize the source file line number information for this file. */
382 if (line_vector) /* Unlikely, but maybe possible? */
383 free ((PTR)line_vector);
384 line_vector_index = 0;
385 line_vector_length = 1000;
386 prev_line_number = -2; /* Force first line number to be explicit */
387 line_vector = (struct linetable *)
388 xmalloc (sizeof (struct linetable)
389 + line_vector_length * sizeof (struct linetable_entry));
392 /* Save the vital information from when starting to read a file,
393 for use when closing off the current file.
394 NAME is the file name the symbols came from, START_ADDR is the first
395 text address for the file, and SIZE is the number of bytes of text. */
398 complete_symtab (name, start_addr, size)
400 CORE_ADDR start_addr;
403 last_source_file = savestring (name, strlen (name));
404 current_source_start_addr = start_addr;
405 current_source_end_addr = start_addr + size;
407 if (current_objfile -> ei.entry_point >= current_source_start_addr &&
408 current_objfile -> ei.entry_point < current_source_end_addr)
410 current_objfile -> ei.entry_file_lowpc = current_source_start_addr;
411 current_objfile -> ei.entry_file_highpc = current_source_end_addr;
415 /* Finish the symbol definitions for one main source file,
416 close off all the lexical contexts for that file
417 (creating struct block's for them), then make the
418 struct symtab for that file and put it in the list of all such. */
421 coff_end_symtab (objfile)
422 struct objfile *objfile;
424 struct symtab *symtab;
426 last_source_start_addr = current_source_start_addr;
428 /* For no good reason, this file stores the number of entries in a
429 separate variable instead of in line_vector->nitems. Fix it. */
431 line_vector->nitems = line_vector_index;
433 /* For COFF, we only have one subfile, so we can just look at
434 subfiles and not worry about there being other elements in the
435 chain. We fill in various fields now because we didn't know them
436 before (or because doing it now is simply an artifact of how this
437 file used to be written). */
438 subfiles->line_vector = line_vector;
439 subfiles->name = last_source_file;
441 /* sort_pending is needed for amdcoff, at least.
442 sort_linevec is needed for the SCO compiler. */
443 symtab = end_symtab (current_source_end_addr, 1, 1, objfile, 0);
446 free_named_symtabs (symtab->filename);
448 /* Reinitialize for beginning of new file. */
450 line_vector_length = -1;
451 last_source_file = NULL;
455 record_minimal_symbol (name, address, type, objfile)
458 enum minimal_symbol_type type;
459 struct objfile *objfile;
461 /* We don't want TDESC entry points in the minimal symbol table */
462 if (name[0] == '@') return;
464 prim_record_minimal_symbol (savestring (name, strlen (name)), address, type,
468 /* coff_symfile_init ()
469 is the coff-specific initialization routine for reading symbols.
470 It is passed a struct objfile which contains, among other things,
471 the BFD for the file whose symbols are being read, and a slot for
472 a pointer to "private data" which we fill with cookies and other
473 treats for coff_symfile_read ().
475 We will only be called if this is a COFF or COFF-like file.
476 BFD handles figuring out the format of the file, and code in symtab.c
477 uses BFD's determination to vector to us.
479 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
481 static int text_bfd_scnum;
484 coff_symfile_init (objfile)
485 struct objfile *objfile;
488 bfd *abfd = objfile->obfd;
490 /* Allocate struct to keep track of stab reading. */
491 objfile->sym_stab_info = (PTR)
492 xmmalloc (objfile -> md, sizeof (struct dbx_symfile_info));
494 memset ((PTR) objfile->sym_stab_info, 0, sizeof (struct dbx_symfile_info));
496 /* Allocate struct to keep track of the symfile */
497 objfile -> sym_private = xmmalloc (objfile -> md,
498 sizeof (struct coff_symfile_info));
500 memset (objfile->sym_private, 0, sizeof (struct coff_symfile_info));
502 init_entry_point_info (objfile);
504 /* Save the section number for the text section */
505 section = bfd_get_section_by_name (abfd, ".text");
507 text_bfd_scnum = section->index;
512 /* This function is called for every section; it finds the outer limits
513 of the line table (minimum and maximum file offset) so that the
514 mainline code can read the whole thing for efficiency. */
518 find_linenos (abfd, asect, vpinfo)
523 struct coff_symfile_info *info;
525 file_ptr offset, maxoff;
527 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
528 count = asect->lineno_count;
533 size = count * local_linesz;
535 info = (struct coff_symfile_info *)vpinfo;
536 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
537 offset = asect->line_filepos;
540 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
541 info->min_lineno_offset = offset;
543 maxoff = offset + size;
544 if (maxoff > info->max_lineno_offset)
545 info->max_lineno_offset = maxoff;
549 /* The BFD for this file -- only good while we're actively reading
550 symbols into a psymtab or a symtab. */
552 static bfd *symfile_bfd;
554 /* Read a symbol file, after initialization by coff_symfile_init. */
558 coff_symfile_read (objfile, section_offsets, mainline)
559 struct objfile *objfile;
560 struct section_offsets *section_offsets;
563 struct coff_symfile_info *info;
564 struct dbx_symfile_info *dbxinfo;
565 bfd *abfd = objfile->obfd;
566 coff_data_type *cdata = coff_data (abfd);
567 char *name = bfd_get_filename (abfd);
571 int stringtab_offset;
572 struct cleanup *back_to;
573 int stabsize, stabstrsize;
575 info = (struct coff_symfile_info *) objfile -> sym_private;
576 dbxinfo = (struct dbx_symfile_info *) objfile->sym_stab_info;
577 symfile_bfd = abfd; /* Kludge for swap routines */
579 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
580 num_symbols = bfd_get_symcount (abfd); /* How many syms */
581 symtab_offset = cdata->sym_filepos; /* Symbol table file offset */
582 stringtab_offset = symtab_offset + /* String table file offset */
583 num_symbols * cdata->local_symesz;
585 /* Set a few file-statics that give us specific information about
586 the particular COFF file format we're reading. */
587 local_linesz = cdata->local_linesz;
588 local_n_btmask = cdata->local_n_btmask;
589 local_n_btshft = cdata->local_n_btshft;
590 local_n_tmask = cdata->local_n_tmask;
591 local_n_tshift = cdata->local_n_tshift;
592 local_linesz = cdata->local_linesz;
593 local_symesz = cdata->local_symesz;
594 local_auxesz = cdata->local_auxesz;
596 /* Allocate space for raw symbol and aux entries, based on their
597 space requirements as reported by BFD. */
598 temp_sym = (char *) xmalloc
599 (cdata->local_symesz + cdata->local_auxesz);
600 temp_aux = temp_sym + cdata->local_symesz;
601 back_to = make_cleanup (free_current_contents, &temp_sym);
604 /* Read the line number table, all at once. */
605 info->min_lineno_offset = 0;
606 info->max_lineno_offset = 0;
607 bfd_map_over_sections (abfd, find_linenos, (PTR) info);
609 make_cleanup (free_linetab, 0);
610 val = init_lineno (abfd, info->min_lineno_offset,
611 info->max_lineno_offset - info->min_lineno_offset);
613 error ("\"%s\": error reading line numbers\n", name);
615 /* Now read the string table, all at once. */
617 make_cleanup (free_stringtab, 0);
618 val = init_stringtab (abfd, stringtab_offset);
620 error ("\"%s\": can't get string table", name);
622 init_minimal_symbol_collection ();
623 make_cleanup (discard_minimal_symbols, 0);
625 /* Now that the executable file is positioned at symbol table,
626 process it and define symbols accordingly. */
628 coff_symtab_read ((long) symtab_offset, num_symbols, section_offsets,
631 /* Sort symbols alphabetically within each block. */
636 for (s = objfile -> symtabs; s != NULL; s = s -> next)
637 sort_symtab_syms (s);
640 /* Install any minimal symbols that have been collected as the current
641 minimal symbols for this objfile. */
643 install_minimal_symbols (objfile);
645 bfd_map_over_sections (abfd, coff_locate_sections, (PTR) info);
649 /* FIXME: dubious. Why can't we use something normal like
650 bfd_get_section_contents? */
651 bfd_seek (abfd, abfd->where, 0);
653 stabsize = bfd_section_size (abfd, info->stabsect);
654 stabstrsize = bfd_section_size (abfd, info->stabstrsect);
656 coffstab_build_psymtabs (objfile,
659 info->stabsect->filepos, stabsize,
660 info->stabstrsect->filepos, stabstrsize);
663 do_cleanups (back_to);
667 coff_new_init (ignore)
668 struct objfile *ignore;
672 /* Perform any local cleanups required when we are done with a particular
673 objfile. I.E, we are in the process of discarding all symbol information
674 for an objfile, freeing up all memory held for it, and unlinking the
675 objfile struct from the global list of known objfiles. */
678 coff_symfile_finish (objfile)
679 struct objfile *objfile;
681 if (objfile -> sym_private != NULL)
683 mfree (objfile -> md, objfile -> sym_private);
688 /* Given pointers to a symbol table in coff style exec file,
689 analyze them and create struct symtab's describing the symbols.
690 NSYMS is the number of symbols in the symbol table.
691 We read them one at a time using read_one_sym (). */
694 coff_symtab_read (symtab_offset, nsyms, section_offsets, objfile)
697 struct section_offsets *section_offsets;
698 struct objfile *objfile;
700 register struct context_stack *new;
701 struct coff_symbol coff_symbol;
702 register struct coff_symbol *cs = &coff_symbol;
703 static struct internal_syment main_sym;
704 static union internal_auxent main_aux;
705 struct coff_symbol fcn_cs_saved;
706 static struct internal_syment fcn_sym_saved;
707 static union internal_auxent fcn_aux_saved;
709 /* A .file is open. */
710 int in_source_file = 0;
711 int next_file_symnum = -1;
712 /* Name of the current file. */
713 char *filestring = "";
715 int fcn_first_line = 0;
716 int fcn_last_line = 0;
717 int fcn_start_addr = 0;
718 long fcn_line_ptr = 0;
722 /* Work around a stdio bug in SunOS4.1.1 (this makes me nervous....
723 it's hard to know I've really worked around it. The fix should be
724 harmless, anyway). The symptom of the bug is that the first
725 fread (in read_one_sym), will (in my example) actually get data
726 from file offset 268, when the fseek was to 264 (and ftell shows
727 264). This causes all hell to break loose. I was unable to
728 reproduce this on a short test program which operated on the same
729 file, performing (I think) the same sequence of operations.
731 It stopped happening when I put in this (former) rewind().
733 FIXME: Find out if this has been reported to Sun, whether it has
734 been fixed in a later release, etc. */
736 bfd_seek (objfile->obfd, 0, 0);
738 /* Position to read the symbol table. */
739 val = bfd_seek (objfile->obfd, (long) symtab_offset, 0);
741 perror_with_name (objfile->name);
743 current_objfile = objfile;
744 nlist_bfd_global = objfile->obfd;
745 nlist_nsyms_global = nsyms;
746 last_source_file = NULL;
747 memset (opaque_type_chain, 0, sizeof opaque_type_chain);
749 if (type_vector) /* Get rid of previous one */
750 free ((PTR) type_vector);
751 type_vector_length = 160;
752 type_vector = (struct type **)
753 xmalloc (type_vector_length * sizeof (struct type *));
754 memset (type_vector, 0, type_vector_length * sizeof (struct type *));
756 coff_start_symtab ();
759 while (symnum < nsyms)
761 QUIT; /* Make this command interruptable. */
763 read_one_sym (cs, &main_sym, &main_aux);
766 temp_sem_val = cs->c_name[0] << 24 | cs->c_name[1] << 16 |
767 cs->c_name[2] << 8 | cs->c_name[3];
768 if (int_sem_val == temp_sem_val)
769 last_coffsem = (int) strtol (cs->c_name+4, (char **) NULL, 10);
772 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
774 if (last_source_file)
775 coff_end_symtab (objfile);
777 coff_start_symtab ();
778 complete_symtab ("_globals_", 0, 0);
779 /* done with all files, everything from here on out is globals */
782 /* Special case for file with type declarations only, no text. */
783 if (!last_source_file && SDB_TYPE (cs->c_type)
784 && cs->c_secnum == N_DEBUG)
785 complete_symtab (filestring, 0, 0);
787 /* Typedefs should not be treated as symbol definitions. */
788 if (ISFCN (cs->c_type) && cs->c_sclass != C_TPDEF)
790 /* Record all functions -- external and static -- in minsyms. */
791 tmpaddr = cs->c_value + ANOFFSET (section_offsets, SECT_OFF_TEXT);
792 record_minimal_symbol (cs->c_name, tmpaddr, mst_text, objfile);
794 fcn_line_ptr = main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
795 fcn_start_addr = tmpaddr;
797 fcn_sym_saved = main_sym;
798 fcn_aux_saved = main_aux;
802 switch (cs->c_sclass)
811 complain (&bad_sclass_complaint, cs->c_name);
815 /* c_value field contains symnum of next .file entry in table
816 or symnum of first global after last .file. */
817 next_file_symnum = cs->c_value;
819 filestring = coff_getfilename (&main_aux);
823 /* Complete symbol table for last object file
824 containing debugging information. */
825 if (last_source_file)
827 coff_end_symtab (objfile);
828 coff_start_symtab ();
834 if (cs->c_name[0] == '.')
836 if (STREQ (cs->c_name, ".text")) {
837 /* FIXME: don't wire in ".text" as section name
839 /* Check for in_source_file deals with case of
840 a file with debugging symbols
841 followed by a later file with no symbols. */
843 complete_symtab (filestring,
844 cs->c_value + ANOFFSET (section_offsets, SECT_OFF_TEXT),
845 main_aux.x_scn.x_scnlen);
848 /* flush rest of '.' symbols */
851 else if (!SDB_TYPE (cs->c_type)
852 && cs->c_name[0] == 'L'
853 && (strncmp (cs->c_name, "LI%", 3) == 0
854 || strncmp (cs->c_name, "LF%", 3) == 0
855 || strncmp (cs->c_name,"LC%",3) == 0
856 || strncmp (cs->c_name,"LP%",3) == 0
857 || strncmp (cs->c_name,"LPB%",4) == 0
858 || strncmp (cs->c_name,"LBB%",4) == 0
859 || strncmp (cs->c_name,"LBE%",4) == 0
860 || strncmp (cs->c_name,"LPBX%",5) == 0))
861 /* At least on a 3b1, gcc generates swbeg and string labels
862 that look like this. Ignore them. */
864 /* fall in for static symbols that don't start with '.' */
866 /* Record it in the minimal symbols regardless of SDB_TYPE.
867 This parallels what we do for other debug formats, and
868 probably is needed to make print_address_symbolic work right
869 without the (now gone) "set fast-symbolic-addr off" kludge. */
871 /* FIXME: This bogusly assumes the sections are in a certain
872 order, text (SEC_CODE) sections are before data sections,
874 if (cs->c_secnum <= text_bfd_scnum+1)
876 /* text or absolute. (FIXME, should use mst_abs if
878 tmpaddr = cs->c_value;
879 if (cs->c_sclass != C_STAT)
880 tmpaddr += ANOFFSET (section_offsets, SECT_OFF_TEXT);
881 record_minimal_symbol
882 (cs->c_name, tmpaddr,
883 cs->c_sclass == C_STAT ? mst_file_text : mst_text,
888 tmpaddr = cs->c_value;
889 if (cs->c_sclass != C_STAT)
890 tmpaddr += ANOFFSET (section_offsets, SECT_OFF_DATA);
891 record_minimal_symbol
892 (cs->c_name, tmpaddr,
893 cs->c_sclass == C_STAT ? mst_file_data : mst_data,
896 if (SDB_TYPE (cs->c_type))
897 process_coff_symbol (cs, &main_aux, section_offsets, objfile);
901 if (STREQ (cs->c_name, ".bf"))
905 /* value contains address of first non-init type code */
906 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
907 contains line number of '{' } */
909 complain (&bf_no_aux_complaint, cs->c_symnum);
910 fcn_first_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
912 /* Might want to check that locals are 0 and
913 context_stack_depth is zero, and complain if not. */
916 new = push_context (depth, fcn_start_addr);
917 fcn_cs_saved.c_name = getsymname (&fcn_sym_saved);
919 process_coff_symbol (&fcn_cs_saved, &fcn_aux_saved,
920 section_offsets, objfile);
922 else if (STREQ (cs->c_name, ".ef"))
924 /* the value of .ef is the address of epilogue code;
925 not useful for gdb. */
926 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
927 contains number of lines to '}' */
928 new = pop_context ();
929 /* Stack must be empty now. */
930 if (context_stack_depth > 0 || new == NULL)
932 complain (&ef_complaint, cs->c_symnum);
938 complain (&ef_no_aux_complaint, cs->c_symnum);
939 fcn_last_line = 0x7FFFFFFF;
943 fcn_last_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
945 enter_linenos (fcn_line_ptr, fcn_first_line, fcn_last_line,
948 finish_block (new->name, &local_symbols, new->old_blocks,
950 #if defined (FUNCTION_EPILOGUE_SIZE)
951 /* This macro should be defined only on
953 fcn_aux_saved.x_sym.x_misc.x_fsize
954 field is always zero.
955 So use the .bf record information that
956 points to the epilogue and add the size
959 + FUNCTION_EPILOGUE_SIZE
960 + ANOFFSET (section_offsets, SECT_OFF_TEXT),
963 + fcn_aux_saved.x_sym.x_misc.x_fsize
964 + ANOFFSET (section_offsets, SECT_OFF_TEXT),
973 if (STREQ (cs->c_name, ".bb"))
975 tmpaddr = cs->c_value;
976 tmpaddr += ANOFFSET (section_offsets, SECT_OFF_TEXT);
977 push_context (++depth, tmpaddr);
979 else if (STREQ (cs->c_name, ".eb"))
981 new = pop_context ();
982 if (depth-- != new->depth)
984 complain (&eb_complaint, symnum);
987 if (local_symbols && context_stack_depth > 0)
990 cs->c_value + ANOFFSET (section_offsets, SECT_OFF_TEXT);
991 /* Make a block for the local symbols within. */
992 finish_block (0, &local_symbols, new->old_blocks,
993 new->start_addr, tmpaddr, objfile);
995 /* Now pop locals of block just finished. */
996 local_symbols = new->locals;
1001 process_coff_symbol (cs, &main_aux, section_offsets, objfile);
1006 if (last_source_file)
1007 coff_end_symtab (objfile);
1009 /* Patch up any opaque types (references to types that are not defined
1010 in the file where they are referenced, e.g. "struct foo *bar"). */
1011 ALL_OBJFILE_SYMTABS (objfile, s)
1012 patch_opaque_types (s);
1014 current_objfile = NULL;
1017 /* Routines for reading headers and symbols from executable. */
1019 /* Read the next symbol, swap it, and return it in both internal_syment
1020 form, and coff_symbol form. Also return its first auxent, if any,
1021 in internal_auxent form, and skip any other auxents. */
1024 read_one_sym (cs, sym, aux)
1025 register struct coff_symbol *cs;
1026 register struct internal_syment *sym;
1027 register union internal_auxent *aux;
1031 cs->c_symnum = symnum;
1032 bfd_read (temp_sym, local_symesz, 1, nlist_bfd_global);
1033 bfd_coff_swap_sym_in (symfile_bfd, temp_sym, (char *)sym);
1034 cs->c_naux = sym->n_numaux & 0xff;
1035 if (cs->c_naux >= 1)
1037 bfd_read (temp_aux, local_auxesz, 1, nlist_bfd_global);
1038 bfd_coff_swap_aux_in (symfile_bfd, temp_aux, sym->n_type, sym->n_sclass,
1039 0, cs->c_naux, (char *)aux);
1040 /* If more than one aux entry, read past it (only the first aux
1042 for (i = 1; i < cs->c_naux; i++)
1043 bfd_read (temp_aux, local_auxesz, 1, nlist_bfd_global);
1045 cs->c_name = getsymname (sym);
1046 cs->c_value = sym->n_value;
1047 cs->c_sclass = (sym->n_sclass & 0xff);
1048 cs->c_secnum = sym->n_scnum;
1049 cs->c_type = (unsigned) sym->n_type;
1050 if (!SDB_TYPE (cs->c_type))
1053 symnum += 1 + cs->c_naux;
1056 /* Support for string table handling */
1058 static char *stringtab = NULL;
1061 init_stringtab (abfd, offset)
1067 unsigned char lengthbuf[4];
1071 /* If the file is stripped, the offset might be zero, indicating no
1072 string table. Just return with `stringtab' set to null. */
1076 if (bfd_seek (abfd, offset, 0) < 0)
1079 val = bfd_read ((char *)lengthbuf, sizeof lengthbuf, 1, abfd);
1080 length = bfd_h_get_32 (symfile_bfd, lengthbuf);
1082 /* If no string table is needed, then the file may end immediately
1083 after the symbols. Just return with `stringtab' set to null. */
1084 if (val != sizeof lengthbuf || length < sizeof lengthbuf)
1087 stringtab = (char *) xmalloc (length);
1088 memcpy (stringtab, &length, sizeof length);
1089 if (length == sizeof length) /* Empty table -- just the count */
1092 val = bfd_read (stringtab + sizeof lengthbuf, length - sizeof lengthbuf, 1, abfd);
1093 if (val != length - sizeof lengthbuf || stringtab[length - 1] != '\0')
1108 getsymname (symbol_entry)
1109 struct internal_syment *symbol_entry;
1111 static char buffer[SYMNMLEN+1];
1114 if (symbol_entry->_n._n_n._n_zeroes == 0)
1116 result = stringtab + symbol_entry->_n._n_n._n_offset;
1120 strncpy (buffer, symbol_entry->_n._n_name, SYMNMLEN);
1121 buffer[SYMNMLEN] = '\0';
1127 /* Extract the file name from the aux entry of a C_FILE symbol. Return
1128 only the last component of the name. Result is in static storage and
1129 is only good for temporary use. */
1132 coff_getfilename (aux_entry)
1133 union internal_auxent *aux_entry;
1135 static char buffer[BUFSIZ];
1136 register char *temp;
1139 if (aux_entry->x_file.x_n.x_zeroes == 0)
1140 strcpy (buffer, stringtab + aux_entry->x_file.x_n.x_offset);
1143 strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
1144 buffer[FILNMLEN] = '\0';
1147 if ((temp = strrchr (result, '/')) != NULL)
1152 /* Support for line number handling. */
1154 static char *linetab = NULL;
1155 static long linetab_offset;
1156 static unsigned long linetab_size;
1158 /* Read in all the line numbers for fast lookups later. Leave them in
1159 external (unswapped) format in memory; we'll swap them as we enter
1160 them into GDB's data structures. */
1163 init_lineno (abfd, offset, size)
1170 linetab_offset = offset;
1171 linetab_size = size;
1178 if (bfd_seek (abfd, offset, 0) < 0)
1181 /* Allocate the desired table, plus a sentinel */
1182 linetab = (char *) xmalloc (size + local_linesz);
1184 val = bfd_read (linetab, size, 1, abfd);
1188 /* Terminate it with an all-zero sentinel record */
1189 memset (linetab + size, 0, local_linesz);
1202 #if !defined (L_LNNO32)
1203 #define L_LNNO32(lp) ((lp)->l_lnno)
1207 enter_linenos (file_offset, first_line, last_line, section_offsets)
1209 register int first_line;
1210 register int last_line;
1211 struct section_offsets *section_offsets;
1213 register char *rawptr;
1214 struct internal_lineno lptr;
1216 if (file_offset < linetab_offset)
1218 complain (&lineno_complaint, file_offset);
1219 if (file_offset > linetab_size) /* Too big to be an offset? */
1221 file_offset += linetab_offset; /* Try reading at that linetab offset */
1224 rawptr = &linetab[file_offset - linetab_offset];
1226 /* skip first line entry for each function */
1227 rawptr += local_linesz;
1228 /* line numbers start at one for the first line of the function */
1232 bfd_coff_swap_lineno_in (symfile_bfd, rawptr, &lptr);
1233 rawptr += local_linesz;
1234 /* The next function, or the sentinel, will have L_LNNO32 zero; we exit. */
1235 if (L_LNNO32 (&lptr) && L_LNNO32 (&lptr) <= last_line)
1236 coff_record_line (first_line + L_LNNO32 (&lptr),
1238 + ANOFFSET (section_offsets, SECT_OFF_TEXT));
1245 patch_type (type, real_type)
1247 struct type *real_type;
1249 register struct type *target = TYPE_TARGET_TYPE (type);
1250 register struct type *real_target = TYPE_TARGET_TYPE (real_type);
1251 int field_size = TYPE_NFIELDS (real_target) * sizeof (struct field);
1253 TYPE_LENGTH (target) = TYPE_LENGTH (real_target);
1254 TYPE_NFIELDS (target) = TYPE_NFIELDS (real_target);
1255 TYPE_FIELDS (target) = (struct field *) TYPE_ALLOC (target, field_size);
1257 memcpy (TYPE_FIELDS (target), TYPE_FIELDS (real_target), field_size);
1259 if (TYPE_NAME (real_target))
1261 if (TYPE_NAME (target))
1262 free (TYPE_NAME (target));
1263 TYPE_NAME (target) = concat (TYPE_NAME (real_target), NULL);
1267 /* Patch up all appropriate typedef symbols in the opaque_type_chains
1268 so that they can be used to print out opaque data structures properly. */
1271 patch_opaque_types (s)
1274 register struct block *b;
1276 register struct symbol *real_sym;
1278 /* Go through the per-file symbols only */
1279 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
1280 for (i = BLOCK_NSYMS (b) - 1; i >= 0; i--)
1282 /* Find completed typedefs to use to fix opaque ones.
1283 Remove syms from the chain when their types are stored,
1284 but search the whole chain, as there may be several syms
1285 from different files with the same name. */
1286 real_sym = BLOCK_SYM (b, i);
1287 if (SYMBOL_CLASS (real_sym) == LOC_TYPEDEF &&
1288 SYMBOL_NAMESPACE (real_sym) == VAR_NAMESPACE &&
1289 TYPE_CODE (SYMBOL_TYPE (real_sym)) == TYPE_CODE_PTR &&
1290 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym))) != 0)
1292 register char *name = SYMBOL_NAME (real_sym);
1293 register int hash = hashname (name);
1294 register struct symbol *sym, *prev;
1297 for (sym = opaque_type_chain[hash]; sym;)
1299 if (name[0] == SYMBOL_NAME (sym)[0] &&
1300 STREQ (name + 1, SYMBOL_NAME (sym) + 1))
1304 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
1308 opaque_type_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
1311 patch_type (SYMBOL_TYPE (sym), SYMBOL_TYPE (real_sym));
1315 sym = SYMBOL_VALUE_CHAIN (prev);
1319 sym = opaque_type_chain[hash];
1325 sym = SYMBOL_VALUE_CHAIN (sym);
1332 static struct symbol *
1333 process_coff_symbol (cs, aux, section_offsets, objfile)
1334 register struct coff_symbol *cs;
1335 register union internal_auxent *aux;
1336 struct section_offsets *section_offsets;
1337 struct objfile *objfile;
1339 register struct symbol *sym
1340 = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1341 sizeof (struct symbol));
1344 memset (sym, 0, sizeof (struct symbol));
1346 name = EXTERNAL_NAME (name, objfile->obfd);
1347 SYMBOL_NAME (sym) = obstack_copy0 (&objfile->symbol_obstack, name,
1350 /* default assumptions */
1351 SYMBOL_VALUE (sym) = cs->c_value;
1352 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1354 if (ISFCN (cs->c_type))
1356 SYMBOL_VALUE (sym) += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1358 /* FIXME: This has NOT been tested. The DBX version has.. */
1359 /* Generate a template for the type of this function. The
1360 types of the arguments will be added as we read the symbol
1362 struct type *new = (struct type *)
1363 obstack_alloc (&objfile->symbol_obstack, sizeof (struct type));
1365 memcpy (new, lookup_function_type (decode_function_type (cs, cs->c_type, aux)),
1366 sizeof(struct type));
1367 SYMBOL_TYPE (sym) = new;
1368 in_function_type = SYMBOL_TYPE(sym);
1371 lookup_function_type (decode_function_type (cs, cs->c_type, aux));
1374 SYMBOL_CLASS (sym) = LOC_BLOCK;
1375 if (cs->c_sclass == C_STAT)
1376 add_symbol_to_list (sym, &file_symbols);
1377 else if (cs->c_sclass == C_EXT)
1378 add_symbol_to_list (sym, &global_symbols);
1382 SYMBOL_TYPE (sym) = decode_type (cs, cs->c_type, aux);
1383 switch (cs->c_sclass)
1389 SYMBOL_CLASS (sym) = LOC_LOCAL;
1390 add_symbol_to_list (sym, &local_symbols);
1394 SYMBOL_CLASS (sym) = LOC_STATIC;
1395 SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
1396 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1397 add_symbol_to_list (sym, &global_symbols);
1401 SYMBOL_CLASS (sym) = LOC_STATIC;
1402 SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
1403 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1404 if (within_function) {
1405 /* Static symbol of local scope */
1406 add_symbol_to_list (sym, &local_symbols);
1409 /* Static symbol at top level of file */
1410 add_symbol_to_list (sym, &file_symbols);
1414 #ifdef C_GLBLREG /* AMD coff */
1418 SYMBOL_CLASS (sym) = LOC_REGISTER;
1419 SYMBOL_VALUE (sym) = SDB_REG_TO_REGNUM(cs->c_value);
1420 add_symbol_to_list (sym, &local_symbols);
1427 SYMBOL_CLASS (sym) = LOC_ARG;
1429 /* FIXME: This has not been tested. */
1430 /* Add parameter to function. */
1431 add_param_to_type(&in_function_type,sym);
1433 add_symbol_to_list (sym, &local_symbols);
1434 #if !defined (BELIEVE_PCC_PROMOTION) && (TARGET_BYTE_ORDER == BIG_ENDIAN)
1436 /* If PCC says a parameter is a short or a char,
1437 aligned on an int boundary, realign it to the "little end"
1439 struct type *temptype;
1440 temptype = lookup_fundamental_type (current_objfile, FT_INTEGER);
1441 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
1442 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
1443 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (temptype))
1445 SYMBOL_VALUE (sym) +=
1446 TYPE_LENGTH (temptype)
1447 - TYPE_LENGTH (SYMBOL_TYPE (sym));
1454 SYMBOL_CLASS (sym) = LOC_REGPARM;
1455 SYMBOL_VALUE (sym) = SDB_REG_TO_REGNUM(cs->c_value);
1456 add_symbol_to_list (sym, &local_symbols);
1457 #if !defined (BELIEVE_PCC_PROMOTION)
1458 /* FIXME: This should retain the current type, since it's just
1459 a register value. gnu@adobe, 26Feb93 */
1461 /* If PCC says a parameter is a short or a char,
1462 it is really an int. */
1463 struct type *temptype;
1465 lookup_fundamental_type (current_objfile, FT_INTEGER);
1466 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
1467 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
1470 (TYPE_UNSIGNED (SYMBOL_TYPE (sym))
1471 ? lookup_fundamental_type (current_objfile,
1472 FT_UNSIGNED_INTEGER)
1480 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1481 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1483 /* If type has no name, give it one */
1484 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
1486 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
1487 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
1489 /* If we are giving a name to a type such as "pointer to
1490 foo" or "function returning foo", we better not set
1491 the TYPE_NAME. If the program contains "typedef char
1492 *caddr_t;", we don't want all variables of type char
1493 * to print as caddr_t. This is not just a
1494 consequence of GDB's type management; CC and GCC (at
1495 least through version 2.4) both output variables of
1496 either type char * or caddr_t with the type
1497 refering to the C_TPDEF symbol for caddr_t. If a future
1498 compiler cleans this up it GDB is not ready for it
1499 yet, but if it becomes ready we somehow need to
1500 disable this check (without breaking the PCC/GCC2.4
1505 Fortunately, this check seems not to be necessary
1506 for anything except pointers or functions. */
1510 TYPE_NAME (SYMBOL_TYPE (sym)) =
1511 concat (SYMBOL_NAME (sym), NULL);
1514 /* Ignore vendor section for Harris CX/UX targets. */
1515 else if (cs->c_name[0] == '$')
1517 #endif /* CXUX_TARGET */
1519 /* Keep track of any type which points to empty structured type,
1520 so it can be filled from a definition from another file. A
1521 simple forward reference (TYPE_CODE_UNDEF) is not an
1522 empty structured type, though; the forward references
1523 work themselves out via the magic of coff_lookup_type. */
1524 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR &&
1525 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym))) == 0 &&
1526 TYPE_CODE (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym))) !=
1529 register int i = hashname (SYMBOL_NAME (sym));
1531 SYMBOL_VALUE_CHAIN (sym) = opaque_type_chain[i];
1532 opaque_type_chain[i] = sym;
1534 add_symbol_to_list (sym, &file_symbols);
1540 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1541 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1543 /* Some compilers try to be helpful by inventing "fake"
1544 names for anonymous enums, structures, and unions, like
1545 "~0fake" or ".0fake". Thanks, but no thanks... */
1546 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
1547 if (SYMBOL_NAME(sym) != NULL
1548 && *SYMBOL_NAME(sym) != '~'
1549 && *SYMBOL_NAME(sym) != '.')
1550 TYPE_TAG_NAME (SYMBOL_TYPE (sym)) =
1551 concat (SYMBOL_NAME (sym), NULL);
1553 add_symbol_to_list (sym, &file_symbols);
1563 /* Decode a coff type specifier; return the type that is meant. */
1565 static struct type *
1566 decode_type (cs, c_type, aux)
1567 register struct coff_symbol *cs;
1568 unsigned int c_type;
1569 register union internal_auxent *aux;
1571 register struct type *type = 0;
1572 unsigned int new_c_type;
1574 if (c_type & ~N_BTMASK)
1576 new_c_type = DECREF (c_type);
1579 type = decode_type (cs, new_c_type, aux);
1580 type = lookup_pointer_type (type);
1582 else if (ISFCN (c_type))
1584 type = decode_type (cs, new_c_type, aux);
1585 type = lookup_function_type (type);
1587 else if (ISARY (c_type))
1590 register unsigned short *dim;
1591 struct type *base_type, *index_type, *range_type;
1593 /* Define an array type. */
1594 /* auxent refers to array, not base type */
1595 if (aux->x_sym.x_tagndx.l == 0)
1598 /* shift the indices down */
1599 dim = &aux->x_sym.x_fcnary.x_ary.x_dimen[0];
1602 for (i = 0; *dim && i < DIMNUM - 1; i++, dim++)
1606 base_type = decode_type (cs, new_c_type, aux);
1607 index_type = lookup_fundamental_type (current_objfile, FT_INTEGER);
1609 create_range_type ((struct type *) NULL, index_type, 0, n - 1);
1611 create_array_type ((struct type *) NULL, base_type, range_type);
1616 /* Reference to existing type. This only occurs with the
1617 struct, union, and enum types. EPI a29k coff
1618 fakes us out by producing aux entries with a nonzero
1619 x_tagndx for definitions of structs, unions, and enums, so we
1620 have to check the c_sclass field. SCO 3.2v4 cc gets confused
1621 with pointers to pointers to defined structs, and generates
1622 negative x_tagndx fields. */
1623 if (cs->c_naux > 0 && aux->x_sym.x_tagndx.l != 0)
1625 if (cs->c_sclass != C_STRTAG
1626 && cs->c_sclass != C_UNTAG
1627 && cs->c_sclass != C_ENTAG
1628 && aux->x_sym.x_tagndx.l >= 0)
1630 type = coff_alloc_type (aux->x_sym.x_tagndx.l);
1635 complain (&tagndx_bad_complaint, cs->c_name);
1636 /* And fall through to decode_base_type... */
1640 return decode_base_type (cs, BTYPE (c_type), aux);
1643 /* Decode a coff type specifier for function definition;
1644 return the type that the function returns. */
1646 static struct type *
1647 decode_function_type (cs, c_type, aux)
1648 register struct coff_symbol *cs;
1649 unsigned int c_type;
1650 register union internal_auxent *aux;
1652 if (aux->x_sym.x_tagndx.l == 0)
1653 cs->c_naux = 0; /* auxent refers to function, not base type */
1655 return decode_type (cs, DECREF (c_type), aux);
1660 static struct type *
1661 decode_base_type (cs, c_type, aux)
1662 register struct coff_symbol *cs;
1663 unsigned int c_type;
1664 register union internal_auxent *aux;
1671 /* shows up with "void (*foo)();" structure members */
1672 return lookup_fundamental_type (current_objfile, FT_VOID);
1675 /* DGUX actually defines both T_ARG and T_VOID to the same value. */
1678 /* Shows up in DGUX, I think. Not sure where. */
1679 return lookup_fundamental_type (current_objfile, FT_VOID); /* shouldn't show up here */
1685 /* Intel 960 COFF has this symbol and meaning. */
1686 return lookup_fundamental_type (current_objfile, FT_VOID);
1690 return lookup_fundamental_type (current_objfile, FT_CHAR);
1693 return lookup_fundamental_type (current_objfile, FT_SHORT);
1696 return lookup_fundamental_type (current_objfile, FT_INTEGER);
1699 return lookup_fundamental_type (current_objfile, FT_LONG);
1702 return lookup_fundamental_type (current_objfile, FT_FLOAT);
1705 return lookup_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT);
1708 if (cs->c_naux != 1)
1710 /* anonymous structure type */
1711 type = coff_alloc_type (cs->c_symnum);
1712 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1713 TYPE_NAME (type) = NULL;
1714 /* This used to set the tag to "<opaque>". But I think setting it
1715 to NULL is right, and the printing code can print it as
1717 TYPE_TAG_NAME (type) = NULL;
1718 INIT_CPLUS_SPECIFIC(type);
1719 TYPE_LENGTH (type) = 0;
1720 TYPE_FIELDS (type) = 0;
1721 TYPE_NFIELDS (type) = 0;
1725 type = coff_read_struct_type (cs->c_symnum,
1726 aux->x_sym.x_misc.x_lnsz.x_size,
1727 aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
1732 if (cs->c_naux != 1)
1734 /* anonymous union type */
1735 type = coff_alloc_type (cs->c_symnum);
1736 TYPE_NAME (type) = NULL;
1737 /* This used to set the tag to "<opaque>". But I think setting it
1738 to NULL is right, and the printing code can print it as
1740 TYPE_TAG_NAME (type) = NULL;
1741 INIT_CPLUS_SPECIFIC(type);
1742 TYPE_LENGTH (type) = 0;
1743 TYPE_FIELDS (type) = 0;
1744 TYPE_NFIELDS (type) = 0;
1748 type = coff_read_struct_type (cs->c_symnum,
1749 aux->x_sym.x_misc.x_lnsz.x_size,
1750 aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
1752 TYPE_CODE (type) = TYPE_CODE_UNION;
1756 if (cs->c_naux != 1)
1758 /* anonymous enum type */
1759 type = coff_alloc_type (cs->c_symnum);
1760 TYPE_CODE (type) = TYPE_CODE_ENUM;
1761 TYPE_NAME (type) = NULL;
1762 /* This used to set the tag to "<opaque>". But I think setting it
1763 to NULL is right, and the printing code can print it as
1765 TYPE_TAG_NAME (type) = NULL;
1766 TYPE_LENGTH (type) = 0;
1767 TYPE_FIELDS (type) = 0;
1768 TYPE_NFIELDS(type) = 0;
1772 type = coff_read_enum_type (cs->c_symnum,
1773 aux->x_sym.x_misc.x_lnsz.x_size,
1774 aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
1779 /* shouldn't show up here */
1783 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_CHAR);
1786 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_SHORT);
1789 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER);
1792 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_LONG);
1794 complain (&unexpected_type_complaint, cs->c_name);
1795 return lookup_fundamental_type (current_objfile, FT_VOID);
1798 /* This page contains subroutines of read_type. */
1800 /* Read the description of a structure (or union type) and return an
1801 object describing the type. */
1803 static struct type *
1804 coff_read_struct_type (index, length, lastsym)
1811 struct nextfield *next;
1815 register struct type *type;
1816 register struct nextfield *list = 0;
1817 struct nextfield *new;
1821 struct coff_symbol member_sym;
1822 register struct coff_symbol *ms = &member_sym;
1823 struct internal_syment sub_sym;
1824 union internal_auxent sub_aux;
1827 type = coff_alloc_type (index);
1828 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1829 INIT_CPLUS_SPECIFIC(type);
1830 TYPE_LENGTH (type) = length;
1832 while (!done && symnum < lastsym && symnum < nlist_nsyms_global)
1834 read_one_sym (ms, &sub_sym, &sub_aux);
1836 name = EXTERNAL_NAME (name, current_objfile->obfd);
1838 switch (ms->c_sclass)
1843 /* Get space to record the next field's data. */
1844 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1848 /* Save the data. */
1849 list->field.name = savestring (name, strlen (name));
1850 list->field.type = decode_type (ms, ms->c_type, &sub_aux);
1851 list->field.bitpos = 8 * ms->c_value;
1852 list->field.bitsize = 0;
1858 /* Get space to record the next field's data. */
1859 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1863 /* Save the data. */
1864 list->field.name = savestring (name, strlen (name));
1865 list->field.type = decode_type (ms, ms->c_type, &sub_aux);
1866 list->field.bitpos = ms->c_value;
1867 list->field.bitsize = sub_aux.x_sym.x_misc.x_lnsz.x_size;
1876 /* Now create the vector of fields, and record how big it is. */
1878 TYPE_NFIELDS (type) = nfields;
1879 TYPE_FIELDS (type) = (struct field *)
1880 TYPE_ALLOC (type, sizeof (struct field) * nfields);
1882 /* Copy the saved-up fields into the field vector. */
1884 for (n = nfields; list; list = list->next)
1885 TYPE_FIELD (type, --n) = list->field;
1890 /* Read a definition of an enumeration type,
1891 and create and return a suitable type object.
1892 Also defines the symbols that represent the values of the type. */
1895 static struct type *
1896 coff_read_enum_type (index, length, lastsym)
1901 register struct symbol *sym;
1902 register struct type *type;
1905 struct pending **symlist;
1906 struct coff_symbol member_sym;
1907 register struct coff_symbol *ms = &member_sym;
1908 struct internal_syment sub_sym;
1909 union internal_auxent sub_aux;
1910 struct pending *osyms, *syms;
1915 type = coff_alloc_type (index);
1916 if (within_function)
1917 symlist = &local_symbols;
1919 symlist = &file_symbols;
1921 o_nsyms = osyms ? osyms->nsyms : 0;
1923 while (!done && symnum < lastsym && symnum < nlist_nsyms_global)
1925 read_one_sym (ms, &sub_sym, &sub_aux);
1927 name = EXTERNAL_NAME (name, current_objfile->obfd);
1929 switch (ms->c_sclass)
1932 sym = (struct symbol *) xmalloc (sizeof (struct symbol));
1933 memset (sym, 0, sizeof (struct symbol));
1935 SYMBOL_NAME (sym) = savestring (name, strlen (name));
1936 SYMBOL_CLASS (sym) = LOC_CONST;
1937 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1938 SYMBOL_VALUE (sym) = ms->c_value;
1939 add_symbol_to_list (sym, symlist);
1944 /* Sometimes the linker (on 386/ix 2.0.2 at least) screws
1945 up the count of how many symbols to read. So stop
1952 /* Now fill in the fields of the type-structure. */
1955 TYPE_LENGTH (type) = length;
1957 TYPE_LENGTH (type) = TARGET_INT_BIT / TARGET_CHAR_BIT; /* Assume ints */
1958 TYPE_CODE (type) = TYPE_CODE_ENUM;
1959 TYPE_NFIELDS (type) = nsyms;
1960 TYPE_FIELDS (type) = (struct field *)
1961 TYPE_ALLOC (type, sizeof (struct field) * nsyms);
1963 /* Find the symbols for the values and put them into the type.
1964 The symbols can be found in the symlist that we put them on
1965 to cause them to be defined. osyms contains the old value
1966 of that symlist; everything up to there was defined by us. */
1967 /* Note that we preserve the order of the enum constants, so
1968 that in something like "enum {FOO, LAST_THING=FOO}" we print
1969 FOO, not LAST_THING. */
1971 for (syms = *symlist, n = 0; syms; syms = syms->next)
1977 for (; j < syms->nsyms; j++,n++)
1979 struct symbol *xsym = syms->symbol[j];
1980 SYMBOL_TYPE (xsym) = type;
1981 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
1982 TYPE_FIELD_VALUE (type, n) = 0;
1983 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
1984 TYPE_FIELD_BITSIZE (type, n) = 0;
1993 struct section_offsets *
1994 coff_symfile_offsets (objfile, addr)
1995 struct objfile *objfile;
1998 struct section_offsets *section_offsets;
2001 objfile->num_sections = SECT_OFF_MAX;
2002 section_offsets = (struct section_offsets *)
2003 obstack_alloc (&objfile -> psymbol_obstack,
2004 sizeof (struct section_offsets)
2005 + sizeof (section_offsets->offsets) * (SECT_OFF_MAX-1));
2007 for (i = 0; i < SECT_OFF_MAX; i++)
2008 ANOFFSET (section_offsets, i) = addr;
2010 return section_offsets;
2013 /* Register our ability to parse symbols for coff BFD files. */
2015 static struct sym_fns coff_sym_fns =
2017 bfd_target_coff_flavour,
2018 coff_new_init, /* sym_new_init: init anything gbl to entire symtab */
2019 coff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
2020 coff_symfile_read, /* sym_read: read a symbol file into symtab */
2021 coff_symfile_finish, /* sym_finish: finished with file, cleanup */
2022 coff_symfile_offsets, /* sym_offsets: xlate external to internal form */
2023 NULL /* next: pointer to next struct sym_fns */
2027 _initialize_coffread ()
2029 add_symtab_fns (&coff_sym_fns);