1 /* Read coff symbol tables and convert to internal format, for GDB.
2 Copyright 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 #include "breakpoint.h"
30 #include "gdb_string.h"
33 #include "coff/internal.h" /* Internal format of COFF symbols in BFD */
34 #include "libcoff.h" /* FIXME secret internal data from BFD */
39 #include "gdb-stabs.h"
40 #include "stabsread.h"
41 #include "complaints.h"
44 struct coff_symfile_info {
45 file_ptr min_lineno_offset; /* Where in file lowest line#s are */
46 file_ptr max_lineno_offset; /* 1+last byte of line#s in file */
48 CORE_ADDR textaddr; /* Addr of .text section. */
49 unsigned int textsize; /* Size of .text section. */
50 struct stab_section_list *stabsects; /* .stab sections. */
51 asection *stabstrsect; /* Section pointer for .stab section */
55 /* Translate an external name string into a user-visible name. */
56 #define EXTERNAL_NAME(string, abfd) \
57 (string[0] == bfd_get_symbol_leading_char(abfd)? string+1: string)
59 /* To be an sdb debug type, type must have at least a basic or primary
60 derived type. Using this rather than checking against T_NULL is
61 said to prevent core dumps if we try to operate on Michael Bloom
64 #define SDB_TYPE(type) (BTYPE(type) | (type & N_TMASK))
66 /* Convert from an sdb register number to an internal gdb register number.
67 This should be defined in tm.h, if REGISTER_NAMES is not set up
68 to map one to one onto the sdb register numbers. */
70 #ifndef SDB_REG_TO_REGNUM
71 # define SDB_REG_TO_REGNUM(value) (value)
74 /* Core address of start and end of text of current source file.
75 This comes from a ".text" symbol where x_nlinno > 0. */
77 static CORE_ADDR current_source_start_addr;
78 static CORE_ADDR current_source_end_addr;
80 /* The addresses of the symbol table stream and number of symbols
81 of the object file we are reading (as copied into core). */
83 static bfd *nlist_bfd_global;
84 static int nlist_nsyms_global;
86 /* Vector of line number information. */
88 static struct linetable *line_vector;
90 /* Index of next entry to go in line_vector_index. */
92 static int line_vector_index;
94 /* Last line number recorded in the line vector. */
96 static int prev_line_number;
98 /* Number of elements allocated for line_vector currently. */
100 static int line_vector_length;
102 /* Pointers to scratch storage, used for reading raw symbols and auxents. */
104 static char *temp_sym;
105 static char *temp_aux;
107 /* Local variables that hold the shift and mask values for the
108 COFF file that we are currently reading. These come back to us
109 from BFD, and are referenced by their macro names, as well as
110 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
111 macros from include/coff/internal.h . */
113 static unsigned local_n_btmask;
114 static unsigned local_n_btshft;
115 static unsigned local_n_tmask;
116 static unsigned local_n_tshift;
118 #define N_BTMASK local_n_btmask
119 #define N_BTSHFT local_n_btshft
120 #define N_TMASK local_n_tmask
121 #define N_TSHIFT local_n_tshift
123 /* Local variables that hold the sizes in the file of various COFF structures.
124 (We only need to know this to read them from the file -- BFD will then
125 translate the data in them, into `internal_xxx' structs in the right
126 byte order, alignment, etc.) */
128 static unsigned local_linesz;
129 static unsigned local_symesz;
130 static unsigned local_auxesz;
132 /* Chain of typedefs of pointers to empty struct/union types.
133 They are chained thru the SYMBOL_VALUE_CHAIN. */
135 static struct symbol *opaque_type_chain[HASHSIZE];
137 /* Complaints about various problems in the file being read */
139 struct complaint ef_complaint =
140 {"Unmatched .ef symbol(s) ignored starting at symnum %d", 0, 0};
142 struct complaint ef_stack_complaint =
143 {"`.ef' symbol without matching `.bf' symbol ignored starting at symnum %d", 0, 0};
145 struct complaint eb_stack_complaint =
146 {"`.eb' symbol without matching `.bb' symbol ignored starting at symnum %d", 0, 0};
148 struct complaint bf_no_aux_complaint =
149 {"`.bf' symbol %d has no aux entry", 0, 0};
151 struct complaint ef_no_aux_complaint =
152 {"`.ef' symbol %d has no aux entry", 0, 0};
154 struct complaint lineno_complaint =
155 {"Line number pointer %d lower than start of line numbers", 0, 0};
157 struct complaint unexpected_type_complaint =
158 {"Unexpected type for symbol %s", 0, 0};
160 struct complaint bad_sclass_complaint =
161 {"Bad n_sclass for symbol %s", 0, 0};
163 struct complaint misordered_blocks_complaint =
164 {"Blocks out of order at address %x", 0, 0};
166 struct complaint tagndx_bad_complaint =
167 {"Symbol table entry for %s has bad tagndx value", 0, 0};
169 struct complaint eb_complaint =
170 {"Mismatched .eb symbol ignored starting at symnum %d", 0, 0};
172 /* Simplified internal version of coff symbol table information */
176 int c_symnum; /* symbol number of this entry */
177 int c_naux; /* 0 if syment only, 1 if syment + auxent, etc */
184 static struct type *coff_read_struct_type PARAMS ((int, int, int));
186 static struct type *decode_base_type PARAMS ((struct coff_symbol *,
188 union internal_auxent *));
190 static struct type *decode_type PARAMS ((struct coff_symbol *, unsigned int,
191 union internal_auxent *));
193 static struct type *decode_function_type PARAMS ((struct coff_symbol *,
195 union internal_auxent *));
197 static struct type *coff_read_enum_type PARAMS ((int, int, int));
199 static struct symbol *process_coff_symbol PARAMS ((struct coff_symbol *,
200 union internal_auxent *,
201 struct section_offsets *,
204 static void patch_opaque_types PARAMS ((struct symtab *));
206 static void patch_type PARAMS ((struct type *, struct type *));
208 static void enter_linenos PARAMS ((long, int, int, struct section_offsets *));
210 static void free_linetab PARAMS ((void));
212 static int init_lineno PARAMS ((bfd *, long, int));
214 static char *getsymname PARAMS ((struct internal_syment *));
216 static char *coff_getfilename PARAMS ((union internal_auxent *));
218 static void free_stringtab PARAMS ((void));
220 static int init_stringtab PARAMS ((bfd *, long));
222 static void read_one_sym PARAMS ((struct coff_symbol *,
223 struct internal_syment *,
224 union internal_auxent *));
226 static void coff_symtab_read PARAMS ((long, int, struct section_offsets *,
229 static void find_linenos PARAMS ((bfd *, sec_ptr, PTR));
231 static void coff_symfile_init PARAMS ((struct objfile *));
233 static void coff_new_init PARAMS ((struct objfile *));
235 static void coff_symfile_read PARAMS ((struct objfile *,
236 struct section_offsets *, int));
238 static void coff_symfile_finish PARAMS ((struct objfile *));
240 static void record_minimal_symbol PARAMS ((char *, CORE_ADDR,
241 enum minimal_symbol_type,
244 static void coff_end_symtab PARAMS ((struct objfile *));
246 static void complete_symtab PARAMS ((char *, CORE_ADDR, unsigned int));
248 static void coff_start_symtab PARAMS ((void));
250 static void coff_record_line PARAMS ((int, CORE_ADDR));
252 static struct type *coff_alloc_type PARAMS ((int));
254 static struct type **coff_lookup_type PARAMS ((int));
256 static void coff_locate_sections PARAMS ((bfd *, asection *, PTR));
258 /* We are called once per section from coff_symfile_read. We
259 need to examine each section we are passed, check to see
260 if it is something we are interested in processing, and
261 if so, stash away some access information for the section.
263 FIXME: The section names should not be hardwired strings (what
264 should they be? I don't think most object file formats have enough
265 section flags to specify what kind of debug section it is
269 coff_locate_sections (abfd, sectp, csip)
274 register struct coff_symfile_info *csi;
277 csi = (struct coff_symfile_info *) csip;
278 name = bfd_get_section_name (abfd, sectp);
279 if (STREQ (name, ".text"))
281 csi->textaddr = bfd_section_vma (abfd, sectp);
282 csi->textsize += bfd_section_size (abfd, sectp);
284 else if (strncmp (name, ".text", sizeof ".text" - 1) == 0)
286 csi->textsize += bfd_section_size (abfd, sectp);
288 else if (STREQ (name, ".stabstr"))
290 csi->stabstrsect = sectp;
292 else if (strncmp (name, ".stab", sizeof ".stab" - 1) == 0)
296 /* We can have multiple .stab sections if linked with
298 for (s = name + sizeof ".stab" - 1; *s != '\0'; s++)
303 struct stab_section_list *n, **pn;
305 n = ((struct stab_section_list *)
306 xmalloc (sizeof (struct stab_section_list)));
309 for (pn = &csi->stabsects; *pn != NULL; pn = &(*pn)->next)
313 /* This will be run after coffstab_build_psymtabs is called
314 in coff_symfile_read, at which point we no longer need
316 make_cleanup (free, n);
321 /* Return the section_offsets* that CS points to. */
322 static int cs_to_section PARAMS ((struct coff_symbol *, struct objfile *));
324 struct find_targ_sec_arg {
329 static void find_targ_sec PARAMS ((bfd *, asection *, void *));
331 static void find_targ_sec (abfd, sect, obj)
336 struct find_targ_sec_arg *args = (struct find_targ_sec_arg *)obj;
337 if (sect->target_index == args->targ_index)
339 /* This is the section. Figure out what SECT_OFF_* code it is. */
340 if (bfd_get_section_flags (abfd, sect) & SEC_CODE)
341 *args->resultp = SECT_OFF_TEXT;
342 else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)
343 *args->resultp = SECT_OFF_DATA;
345 *args->resultp = SECT_OFF_BSS;
349 /* Return the section number (SECT_OFF_*) that CS points to. */
351 cs_to_section (cs, objfile)
352 struct coff_symbol *cs;
353 struct objfile *objfile;
355 int off = SECT_OFF_TEXT;
356 struct find_targ_sec_arg args;
357 args.targ_index = cs->c_secnum;
359 bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
363 /* Look up a coff type-number index. Return the address of the slot
364 where the type for that index is stored.
365 The type-number is in INDEX.
367 This can be used for finding the type associated with that index
368 or for associating a new type with the index. */
370 static struct type **
371 coff_lookup_type (index)
374 if (index >= type_vector_length)
376 int old_vector_length = type_vector_length;
378 type_vector_length *= 2;
379 if (index /* is still */ >= type_vector_length)
380 type_vector_length = index * 2;
382 type_vector = (struct type **)
383 xrealloc ((char *) type_vector,
384 type_vector_length * sizeof (struct type *));
385 memset (&type_vector[old_vector_length], 0,
386 (type_vector_length - old_vector_length) * sizeof(struct type *));
388 return &type_vector[index];
391 /* Make sure there is a type allocated for type number index
392 and return the type object.
393 This can create an empty (zeroed) type object. */
396 coff_alloc_type (index)
399 register struct type **type_addr = coff_lookup_type (index);
400 register struct type *type = *type_addr;
402 /* If we are referring to a type not known at all yet,
403 allocate an empty type for it.
404 We will fill it in later if we find out how. */
407 type = alloc_type (current_objfile);
413 /* Record a line number entry for line LINE at address PC.
414 FIXME: Use record_line instead. */
417 coff_record_line (line, pc)
421 struct linetable_entry *e;
422 /* Make sure line vector is big enough. */
424 if (line_vector_index + 2 >= line_vector_length)
426 line_vector_length *= 2;
427 line_vector = (struct linetable *)
428 xrealloc ((char *) line_vector, sizeof (struct linetable)
429 + (line_vector_length
430 * sizeof (struct linetable_entry)));
433 e = line_vector->item + line_vector_index++;
434 e->line = line; e->pc = pc;
437 /* Start a new symtab for a new source file.
438 This is called when a COFF ".file" symbol is seen;
439 it indicates the start of data for one original source file. */
445 /* We fill in the filename later. start_symtab puts
446 this pointer into last_source_file and we put it in
447 subfiles->name, which end_symtab frees; that's why
448 it must be malloc'd. */
450 /* We never know the directory name for COFF. */
452 /* The start address is irrelevant, since we set
453 last_source_start_addr in coff_end_symtab. */
456 /* Initialize the source file line number information for this file. */
458 if (line_vector) /* Unlikely, but maybe possible? */
459 free ((PTR)line_vector);
460 line_vector_index = 0;
461 line_vector_length = 1000;
462 prev_line_number = -2; /* Force first line number to be explicit */
463 line_vector = (struct linetable *)
464 xmalloc (sizeof (struct linetable)
465 + line_vector_length * sizeof (struct linetable_entry));
468 /* Save the vital information from when starting to read a file,
469 for use when closing off the current file.
470 NAME is the file name the symbols came from, START_ADDR is the first
471 text address for the file, and SIZE is the number of bytes of text. */
474 complete_symtab (name, start_addr, size)
476 CORE_ADDR start_addr;
479 if (last_source_file != NULL)
480 free (last_source_file);
481 last_source_file = savestring (name, strlen (name));
482 current_source_start_addr = start_addr;
483 current_source_end_addr = start_addr + size;
485 if (current_objfile -> ei.entry_point >= current_source_start_addr &&
486 current_objfile -> ei.entry_point < current_source_end_addr)
488 current_objfile -> ei.entry_file_lowpc = current_source_start_addr;
489 current_objfile -> ei.entry_file_highpc = current_source_end_addr;
493 /* Finish the symbol definitions for one main source file,
494 close off all the lexical contexts for that file
495 (creating struct block's for them), then make the
496 struct symtab for that file and put it in the list of all such. */
499 coff_end_symtab (objfile)
500 struct objfile *objfile;
502 struct symtab *symtab;
504 last_source_start_addr = current_source_start_addr;
506 /* For no good reason, this file stores the number of entries in a
507 separate variable instead of in line_vector->nitems. Fix it. */
509 line_vector->nitems = line_vector_index;
511 /* For COFF, we only have one subfile, so we can just look at
512 subfiles and not worry about there being other elements in the
513 chain. We fill in various fields now because we didn't know them
514 before (or because doing it now is simply an artifact of how this
515 file used to be written). */
516 subfiles->line_vector = line_vector;
517 subfiles->name = last_source_file;
519 symtab = end_symtab (current_source_end_addr, objfile, 0);
522 free_named_symtabs (symtab->filename);
524 /* Reinitialize for beginning of new file. */
526 line_vector_length = -1;
527 last_source_file = NULL;
531 record_minimal_symbol (name, address, type, objfile)
534 enum minimal_symbol_type type;
535 struct objfile *objfile;
537 /* We don't want TDESC entry points in the minimal symbol table */
538 if (name[0] == '@') return;
540 prim_record_minimal_symbol
541 (obsavestring (name, strlen (name), &objfile->symbol_obstack),
546 /* coff_symfile_init ()
547 is the coff-specific initialization routine for reading symbols.
548 It is passed a struct objfile which contains, among other things,
549 the BFD for the file whose symbols are being read, and a slot for
550 a pointer to "private data" which we fill with cookies and other
551 treats for coff_symfile_read ().
553 We will only be called if this is a COFF or COFF-like file.
554 BFD handles figuring out the format of the file, and code in symtab.c
555 uses BFD's determination to vector to us.
557 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
560 coff_symfile_init (objfile)
561 struct objfile *objfile;
563 /* Allocate struct to keep track of stab reading. */
564 objfile->sym_stab_info = (PTR)
565 xmmalloc (objfile->md, sizeof (struct dbx_symfile_info));
567 memset ((PTR) objfile->sym_stab_info, 0, sizeof (struct dbx_symfile_info));
569 /* Allocate struct to keep track of the symfile */
570 objfile->sym_private = xmmalloc (objfile->md,
571 sizeof (struct coff_symfile_info));
573 memset (objfile->sym_private, 0, sizeof (struct coff_symfile_info));
575 /* COFF objects may be reordered, so set OBJF_REORDERED. If we
576 find this causes a significant slowdown in gdb then we could
577 set it in the debug symbol readers only when necessary. */
578 objfile->flags |= OBJF_REORDERED;
580 init_entry_point_info (objfile);
583 /* This function is called for every section; it finds the outer limits
584 of the line table (minimum and maximum file offset) so that the
585 mainline code can read the whole thing for efficiency. */
589 find_linenos (abfd, asect, vpinfo)
594 struct coff_symfile_info *info;
596 file_ptr offset, maxoff;
598 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
599 count = asect->lineno_count;
604 size = count * local_linesz;
606 info = (struct coff_symfile_info *)vpinfo;
607 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
608 offset = asect->line_filepos;
611 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
612 info->min_lineno_offset = offset;
614 maxoff = offset + size;
615 if (maxoff > info->max_lineno_offset)
616 info->max_lineno_offset = maxoff;
620 /* The BFD for this file -- only good while we're actively reading
621 symbols into a psymtab or a symtab. */
623 static bfd *symfile_bfd;
625 /* Read a symbol file, after initialization by coff_symfile_init. */
629 coff_symfile_read (objfile, section_offsets, mainline)
630 struct objfile *objfile;
631 struct section_offsets *section_offsets;
634 struct coff_symfile_info *info;
635 struct dbx_symfile_info *dbxinfo;
636 bfd *abfd = objfile->obfd;
637 coff_data_type *cdata = coff_data (abfd);
638 char *name = bfd_get_filename (abfd);
642 int stringtab_offset;
643 struct cleanup *back_to;
646 info = (struct coff_symfile_info *) objfile -> sym_private;
647 dbxinfo = (struct dbx_symfile_info *) objfile->sym_stab_info;
648 symfile_bfd = abfd; /* Kludge for swap routines */
650 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
651 num_symbols = bfd_get_symcount (abfd); /* How many syms */
652 symtab_offset = cdata->sym_filepos; /* Symbol table file offset */
653 stringtab_offset = symtab_offset + /* String table file offset */
654 num_symbols * cdata->local_symesz;
656 /* Set a few file-statics that give us specific information about
657 the particular COFF file format we're reading. */
658 local_linesz = cdata->local_linesz;
659 local_n_btmask = cdata->local_n_btmask;
660 local_n_btshft = cdata->local_n_btshft;
661 local_n_tmask = cdata->local_n_tmask;
662 local_n_tshift = cdata->local_n_tshift;
663 local_linesz = cdata->local_linesz;
664 local_symesz = cdata->local_symesz;
665 local_auxesz = cdata->local_auxesz;
667 /* Allocate space for raw symbol and aux entries, based on their
668 space requirements as reported by BFD. */
669 temp_sym = (char *) xmalloc
670 (cdata->local_symesz + cdata->local_auxesz);
671 temp_aux = temp_sym + cdata->local_symesz;
672 back_to = make_cleanup (free_current_contents, &temp_sym);
675 /* Read the line number table, all at once. */
676 info->min_lineno_offset = 0;
677 info->max_lineno_offset = 0;
678 bfd_map_over_sections (abfd, find_linenos, (PTR) info);
680 make_cleanup (free_linetab, 0);
681 val = init_lineno (abfd, info->min_lineno_offset,
682 info->max_lineno_offset - info->min_lineno_offset);
684 error ("\"%s\": error reading line numbers\n", name);
686 /* Now read the string table, all at once. */
688 make_cleanup (free_stringtab, 0);
689 val = init_stringtab (abfd, stringtab_offset);
691 error ("\"%s\": can't get string table", name);
693 init_minimal_symbol_collection ();
694 make_cleanup (discard_minimal_symbols, 0);
696 /* Now that the executable file is positioned at symbol table,
697 process it and define symbols accordingly. */
699 coff_symtab_read ((long) symtab_offset, num_symbols, section_offsets,
702 /* Sort symbols alphabetically within each block. */
707 for (s = objfile -> symtabs; s != NULL; s = s -> next)
708 sort_symtab_syms (s);
711 /* Install any minimal symbols that have been collected as the current
712 minimal symbols for this objfile. */
714 install_minimal_symbols (objfile);
716 bfd_map_over_sections (abfd, coff_locate_sections, (PTR) info);
720 /* FIXME: dubious. Why can't we use something normal like
721 bfd_get_section_contents? */
722 bfd_seek (abfd, abfd->where, 0);
724 stabstrsize = bfd_section_size (abfd, info->stabstrsect);
726 coffstab_build_psymtabs (objfile,
729 info->textaddr, info->textsize,
731 info->stabstrsect->filepos, stabstrsize);
734 do_cleanups (back_to);
738 coff_new_init (ignore)
739 struct objfile *ignore;
743 /* Perform any local cleanups required when we are done with a particular
744 objfile. I.E, we are in the process of discarding all symbol information
745 for an objfile, freeing up all memory held for it, and unlinking the
746 objfile struct from the global list of known objfiles. */
749 coff_symfile_finish (objfile)
750 struct objfile *objfile;
752 if (objfile -> sym_private != NULL)
754 mfree (objfile -> md, objfile -> sym_private);
759 /* Given pointers to a symbol table in coff style exec file,
760 analyze them and create struct symtab's describing the symbols.
761 NSYMS is the number of symbols in the symbol table.
762 We read them one at a time using read_one_sym (). */
765 coff_symtab_read (symtab_offset, nsyms, section_offsets, objfile)
768 struct section_offsets *section_offsets;
769 struct objfile *objfile;
771 register struct context_stack *new;
772 struct coff_symbol coff_symbol;
773 register struct coff_symbol *cs = &coff_symbol;
774 static struct internal_syment main_sym;
775 static union internal_auxent main_aux;
776 struct coff_symbol fcn_cs_saved;
777 static struct internal_syment fcn_sym_saved;
778 static union internal_auxent fcn_aux_saved;
780 /* A .file is open. */
781 int in_source_file = 0;
782 int next_file_symnum = -1;
783 /* Name of the current file. */
784 char *filestring = "";
786 int fcn_first_line = 0;
787 int fcn_last_line = 0;
788 int fcn_start_addr = 0;
789 long fcn_line_ptr = 0;
793 /* Work around a stdio bug in SunOS4.1.1 (this makes me nervous....
794 it's hard to know I've really worked around it. The fix should be
795 harmless, anyway). The symptom of the bug is that the first
796 fread (in read_one_sym), will (in my example) actually get data
797 from file offset 268, when the fseek was to 264 (and ftell shows
798 264). This causes all hell to break loose. I was unable to
799 reproduce this on a short test program which operated on the same
800 file, performing (I think) the same sequence of operations.
802 It stopped happening when I put in this (former) rewind().
804 FIXME: Find out if this has been reported to Sun, whether it has
805 been fixed in a later release, etc. */
807 bfd_seek (objfile->obfd, 0, 0);
809 /* Position to read the symbol table. */
810 val = bfd_seek (objfile->obfd, (long) symtab_offset, 0);
812 perror_with_name (objfile->name);
814 current_objfile = objfile;
815 nlist_bfd_global = objfile->obfd;
816 nlist_nsyms_global = nsyms;
817 last_source_file = NULL;
818 memset (opaque_type_chain, 0, sizeof opaque_type_chain);
820 if (type_vector) /* Get rid of previous one */
821 free ((PTR) type_vector);
822 type_vector_length = 160;
823 type_vector = (struct type **)
824 xmalloc (type_vector_length * sizeof (struct type *));
825 memset (type_vector, 0, type_vector_length * sizeof (struct type *));
827 coff_start_symtab ();
830 while (symnum < nsyms)
832 QUIT; /* Make this command interruptable. */
834 read_one_sym (cs, &main_sym, &main_aux);
837 temp_sem_val = cs->c_name[0] << 24 | cs->c_name[1] << 16 |
838 cs->c_name[2] << 8 | cs->c_name[3];
839 if (int_sem_val == temp_sem_val)
840 last_coffsem = (int) strtol (cs->c_name+4, (char **) NULL, 10);
843 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
845 if (last_source_file)
846 coff_end_symtab (objfile);
848 coff_start_symtab ();
849 complete_symtab ("_globals_", 0, 0);
850 /* done with all files, everything from here on out is globals */
853 /* Special case for file with type declarations only, no text. */
854 if (!last_source_file && SDB_TYPE (cs->c_type)
855 && cs->c_secnum == N_DEBUG)
856 complete_symtab (filestring, 0, 0);
858 /* Typedefs should not be treated as symbol definitions. */
859 if (ISFCN (cs->c_type) && cs->c_sclass != C_TPDEF)
861 /* Record all functions -- external and static -- in minsyms. */
862 tmpaddr = cs->c_value + ANOFFSET (section_offsets, SECT_OFF_TEXT);
863 record_minimal_symbol (cs->c_name, tmpaddr, mst_text, objfile);
865 fcn_line_ptr = main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
866 fcn_start_addr = tmpaddr;
868 fcn_sym_saved = main_sym;
869 fcn_aux_saved = main_aux;
873 switch (cs->c_sclass)
882 complain (&bad_sclass_complaint, cs->c_name);
886 /* c_value field contains symnum of next .file entry in table
887 or symnum of first global after last .file. */
888 next_file_symnum = cs->c_value;
890 filestring = coff_getfilename (&main_aux);
894 /* Complete symbol table for last object file
895 containing debugging information. */
896 if (last_source_file)
898 coff_end_symtab (objfile);
899 coff_start_symtab ();
904 /* C_LABEL is used for labels and static functions. Including
905 it here allows gdb to see static functions when no debug
906 info is available. */
909 if (cs->c_name[0] == '.')
911 if (STREQ (cs->c_name, ".text")) {
912 /* FIXME: don't wire in ".text" as section name
914 /* Check for in_source_file deals with case of
915 a file with debugging symbols
916 followed by a later file with no symbols. */
918 complete_symtab (filestring,
919 cs->c_value + ANOFFSET (section_offsets, SECT_OFF_TEXT),
920 main_aux.x_scn.x_scnlen);
923 /* flush rest of '.' symbols */
926 else if (!SDB_TYPE (cs->c_type)
927 && cs->c_name[0] == 'L'
928 && (strncmp (cs->c_name, "LI%", 3) == 0
929 || strncmp (cs->c_name, "LF%", 3) == 0
930 || strncmp (cs->c_name,"LC%",3) == 0
931 || strncmp (cs->c_name,"LP%",3) == 0
932 || strncmp (cs->c_name,"LPB%",4) == 0
933 || strncmp (cs->c_name,"LBB%",4) == 0
934 || strncmp (cs->c_name,"LBE%",4) == 0
935 || strncmp (cs->c_name,"LPBX%",5) == 0))
936 /* At least on a 3b1, gcc generates swbeg and string labels
937 that look like this. Ignore them. */
939 /* fall in for static symbols that don't start with '.' */
942 /* Record it in the minimal symbols regardless of
943 SDB_TYPE. This parallels what we do for other debug
944 formats, and probably is needed to make
945 print_address_symbolic work right without the (now
946 gone) "set fast-symbolic-addr off" kludge. */
948 /* FIXME: should use mst_abs, and not relocate, if absolute. */
949 enum minimal_symbol_type ms_type;
952 if (cs->c_secnum == N_UNDEF)
954 /* This is a common symbol. See if the target
955 environment knows where it has been relocated to. */
957 if (target_lookup_symbol (cs->c_name, &reladdr))
959 /* Error in lookup; ignore symbol. */
963 /* The address has already been relocated; make sure that
964 objfile_relocate doesn't relocate it again. */
966 ms_type = cs->c_sclass == C_STAT ? mst_file_bss : mst_bss;
970 sec = cs_to_section (cs, objfile);
971 tmpaddr = cs->c_value;
972 if (cs->c_sclass != C_STAT)
973 tmpaddr += ANOFFSET (section_offsets, sec);
978 case SECT_OFF_RODATA:
980 cs->c_sclass == C_STAT ? mst_file_text : mst_text;
984 cs->c_sclass == C_STAT ? mst_file_data : mst_data;
988 cs->c_sclass == C_STAT ? mst_file_bss : mst_bss;
991 ms_type = mst_unknown;
996 if (cs->c_name[0] != '@' /* Skip tdesc symbols */)
997 prim_record_minimal_symbol_and_info
998 (obsavestring (cs->c_name, strlen (cs->c_name),
999 &objfile->symbol_obstack),
1006 if (SDB_TYPE (cs->c_type))
1009 sym = process_coff_symbol
1010 (cs, &main_aux, section_offsets, objfile);
1011 SYMBOL_VALUE (sym) = tmpaddr;
1012 SYMBOL_SECTION (sym) = sec;
1018 if (STREQ (cs->c_name, ".bf"))
1020 within_function = 1;
1022 /* value contains address of first non-init type code */
1023 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
1024 contains line number of '{' } */
1025 if (cs->c_naux != 1)
1026 complain (&bf_no_aux_complaint, cs->c_symnum);
1027 fcn_first_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
1029 /* Might want to check that locals are 0 and
1030 context_stack_depth is zero, and complain if not. */
1033 new = push_context (depth, fcn_start_addr);
1034 fcn_cs_saved.c_name = getsymname (&fcn_sym_saved);
1036 process_coff_symbol (&fcn_cs_saved, &fcn_aux_saved,
1037 section_offsets, objfile);
1039 else if (STREQ (cs->c_name, ".ef"))
1041 /* the value of .ef is the address of epilogue code;
1042 not useful for gdb. */
1043 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1044 contains number of lines to '}' */
1046 if (context_stack_depth <= 0)
1047 { /* We attempted to pop an empty context stack */
1048 complain (&ef_stack_complaint, cs->c_symnum);
1049 within_function = 0;
1053 new = pop_context ();
1054 /* Stack must be empty now. */
1055 if (context_stack_depth > 0 || new == NULL)
1057 complain (&ef_complaint, cs->c_symnum);
1058 within_function = 0;
1061 if (cs->c_naux != 1)
1063 complain (&ef_no_aux_complaint, cs->c_symnum);
1064 fcn_last_line = 0x7FFFFFFF;
1068 fcn_last_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
1070 enter_linenos (fcn_line_ptr, fcn_first_line, fcn_last_line,
1073 finish_block (new->name, &local_symbols, new->old_blocks,
1075 #if defined (FUNCTION_EPILOGUE_SIZE)
1076 /* This macro should be defined only on
1078 fcn_aux_saved.x_sym.x_misc.x_fsize
1079 field is always zero.
1080 So use the .bf record information that
1081 points to the epilogue and add the size
1084 + FUNCTION_EPILOGUE_SIZE
1085 + ANOFFSET (section_offsets, SECT_OFF_TEXT),
1087 fcn_cs_saved.c_value
1088 + fcn_aux_saved.x_sym.x_misc.x_fsize
1089 + ANOFFSET (section_offsets, SECT_OFF_TEXT),
1093 within_function = 0;
1098 if (STREQ (cs->c_name, ".bb"))
1100 tmpaddr = cs->c_value;
1101 tmpaddr += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1102 push_context (++depth, tmpaddr);
1104 else if (STREQ (cs->c_name, ".eb"))
1106 if (context_stack_depth <= 0)
1107 { /* We attempted to pop an empty context stack */
1108 complain (&eb_stack_complaint, cs->c_symnum);
1112 new = pop_context ();
1113 if (depth-- != new->depth)
1115 complain (&eb_complaint, symnum);
1118 if (local_symbols && context_stack_depth > 0)
1121 cs->c_value + ANOFFSET (section_offsets, SECT_OFF_TEXT);
1122 /* Make a block for the local symbols within. */
1123 finish_block (0, &local_symbols, new->old_blocks,
1124 new->start_addr, tmpaddr, objfile);
1126 /* Now pop locals of block just finished. */
1127 local_symbols = new->locals;
1132 process_coff_symbol (cs, &main_aux, section_offsets, objfile);
1137 if (last_source_file)
1138 coff_end_symtab (objfile);
1140 /* Patch up any opaque types (references to types that are not defined
1141 in the file where they are referenced, e.g. "struct foo *bar"). */
1142 ALL_OBJFILE_SYMTABS (objfile, s)
1143 patch_opaque_types (s);
1145 current_objfile = NULL;
1148 /* Routines for reading headers and symbols from executable. */
1150 /* Read the next symbol, swap it, and return it in both internal_syment
1151 form, and coff_symbol form. Also return its first auxent, if any,
1152 in internal_auxent form, and skip any other auxents. */
1155 read_one_sym (cs, sym, aux)
1156 register struct coff_symbol *cs;
1157 register struct internal_syment *sym;
1158 register union internal_auxent *aux;
1162 cs->c_symnum = symnum;
1163 bfd_read (temp_sym, local_symesz, 1, nlist_bfd_global);
1164 bfd_coff_swap_sym_in (symfile_bfd, temp_sym, (char *)sym);
1165 cs->c_naux = sym->n_numaux & 0xff;
1166 if (cs->c_naux >= 1)
1168 bfd_read (temp_aux, local_auxesz, 1, nlist_bfd_global);
1169 bfd_coff_swap_aux_in (symfile_bfd, temp_aux, sym->n_type, sym->n_sclass,
1170 0, cs->c_naux, (char *)aux);
1171 /* If more than one aux entry, read past it (only the first aux
1173 for (i = 1; i < cs->c_naux; i++)
1174 bfd_read (temp_aux, local_auxesz, 1, nlist_bfd_global);
1176 cs->c_name = getsymname (sym);
1177 cs->c_value = sym->n_value;
1178 cs->c_sclass = (sym->n_sclass & 0xff);
1179 cs->c_secnum = sym->n_scnum;
1180 cs->c_type = (unsigned) sym->n_type;
1181 if (!SDB_TYPE (cs->c_type))
1184 symnum += 1 + cs->c_naux;
1187 /* Support for string table handling */
1189 static char *stringtab = NULL;
1192 init_stringtab (abfd, offset)
1198 unsigned char lengthbuf[4];
1202 /* If the file is stripped, the offset might be zero, indicating no
1203 string table. Just return with `stringtab' set to null. */
1207 if (bfd_seek (abfd, offset, 0) < 0)
1210 val = bfd_read ((char *)lengthbuf, sizeof lengthbuf, 1, abfd);
1211 length = bfd_h_get_32 (symfile_bfd, lengthbuf);
1213 /* If no string table is needed, then the file may end immediately
1214 after the symbols. Just return with `stringtab' set to null. */
1215 if (val != sizeof lengthbuf || length < sizeof lengthbuf)
1218 stringtab = (char *) xmalloc (length);
1219 /* This is in target format (probably not very useful, and not currently
1220 used), not host format. */
1221 memcpy (stringtab, lengthbuf, sizeof lengthbuf);
1222 if (length == sizeof length) /* Empty table -- just the count */
1225 val = bfd_read (stringtab + sizeof lengthbuf, length - sizeof lengthbuf, 1, abfd);
1226 if (val != length - sizeof lengthbuf || stringtab[length - 1] != '\0')
1241 getsymname (symbol_entry)
1242 struct internal_syment *symbol_entry;
1244 static char buffer[SYMNMLEN+1];
1247 if (symbol_entry->_n._n_n._n_zeroes == 0)
1249 /* FIXME: Probably should be detecting corrupt symbol files by
1250 seeing whether offset points to within the stringtab. */
1251 result = stringtab + symbol_entry->_n._n_n._n_offset;
1255 strncpy (buffer, symbol_entry->_n._n_name, SYMNMLEN);
1256 buffer[SYMNMLEN] = '\0';
1262 /* Extract the file name from the aux entry of a C_FILE symbol. Return
1263 only the last component of the name. Result is in static storage and
1264 is only good for temporary use. */
1267 coff_getfilename (aux_entry)
1268 union internal_auxent *aux_entry;
1270 static char buffer[BUFSIZ];
1271 register char *temp;
1274 if (aux_entry->x_file.x_n.x_zeroes == 0)
1275 strcpy (buffer, stringtab + aux_entry->x_file.x_n.x_offset);
1278 strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
1279 buffer[FILNMLEN] = '\0';
1283 /* FIXME: We should not be throwing away the information about what
1284 directory. It should go into dirname of the symtab, or some such
1286 if ((temp = strrchr (result, '/')) != NULL)
1291 /* Support for line number handling. */
1293 static char *linetab = NULL;
1294 static long linetab_offset;
1295 static unsigned long linetab_size;
1297 /* Read in all the line numbers for fast lookups later. Leave them in
1298 external (unswapped) format in memory; we'll swap them as we enter
1299 them into GDB's data structures. */
1302 init_lineno (abfd, offset, size)
1309 linetab_offset = offset;
1310 linetab_size = size;
1317 if (bfd_seek (abfd, offset, 0) < 0)
1320 /* Allocate the desired table, plus a sentinel */
1321 linetab = (char *) xmalloc (size + local_linesz);
1323 val = bfd_read (linetab, size, 1, abfd);
1327 /* Terminate it with an all-zero sentinel record */
1328 memset (linetab + size, 0, local_linesz);
1341 #if !defined (L_LNNO32)
1342 #define L_LNNO32(lp) ((lp)->l_lnno)
1346 enter_linenos (file_offset, first_line, last_line, section_offsets)
1348 register int first_line;
1349 register int last_line;
1350 struct section_offsets *section_offsets;
1352 register char *rawptr;
1353 struct internal_lineno lptr;
1357 if (file_offset < linetab_offset)
1359 complain (&lineno_complaint, file_offset);
1360 if (file_offset > linetab_size) /* Too big to be an offset? */
1362 file_offset += linetab_offset; /* Try reading at that linetab offset */
1365 rawptr = &linetab[file_offset - linetab_offset];
1367 /* skip first line entry for each function */
1368 rawptr += local_linesz;
1369 /* line numbers start at one for the first line of the function */
1373 bfd_coff_swap_lineno_in (symfile_bfd, rawptr, &lptr);
1374 rawptr += local_linesz;
1375 /* The next function, or the sentinel, will have L_LNNO32 zero; we exit. */
1376 if (L_LNNO32 (&lptr) && L_LNNO32 (&lptr) <= last_line)
1377 coff_record_line (first_line + L_LNNO32 (&lptr),
1379 + ANOFFSET (section_offsets, SECT_OFF_TEXT));
1386 patch_type (type, real_type)
1388 struct type *real_type;
1390 register struct type *target = TYPE_TARGET_TYPE (type);
1391 register struct type *real_target = TYPE_TARGET_TYPE (real_type);
1392 int field_size = TYPE_NFIELDS (real_target) * sizeof (struct field);
1394 TYPE_LENGTH (target) = TYPE_LENGTH (real_target);
1395 TYPE_NFIELDS (target) = TYPE_NFIELDS (real_target);
1396 TYPE_FIELDS (target) = (struct field *) TYPE_ALLOC (target, field_size);
1398 memcpy (TYPE_FIELDS (target), TYPE_FIELDS (real_target), field_size);
1400 if (TYPE_NAME (real_target))
1402 if (TYPE_NAME (target))
1403 free (TYPE_NAME (target));
1404 TYPE_NAME (target) = concat (TYPE_NAME (real_target), NULL);
1408 /* Patch up all appropriate typedef symbols in the opaque_type_chains
1409 so that they can be used to print out opaque data structures properly. */
1412 patch_opaque_types (s)
1415 register struct block *b;
1417 register struct symbol *real_sym;
1419 /* Go through the per-file symbols only */
1420 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
1421 for (i = BLOCK_NSYMS (b) - 1; i >= 0; i--)
1423 /* Find completed typedefs to use to fix opaque ones.
1424 Remove syms from the chain when their types are stored,
1425 but search the whole chain, as there may be several syms
1426 from different files with the same name. */
1427 real_sym = BLOCK_SYM (b, i);
1428 if (SYMBOL_CLASS (real_sym) == LOC_TYPEDEF &&
1429 SYMBOL_NAMESPACE (real_sym) == VAR_NAMESPACE &&
1430 TYPE_CODE (SYMBOL_TYPE (real_sym)) == TYPE_CODE_PTR &&
1431 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym))) != 0)
1433 register char *name = SYMBOL_NAME (real_sym);
1434 register int hash = hashname (name);
1435 register struct symbol *sym, *prev;
1438 for (sym = opaque_type_chain[hash]; sym;)
1440 if (name[0] == SYMBOL_NAME (sym)[0] &&
1441 STREQ (name + 1, SYMBOL_NAME (sym) + 1))
1445 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
1449 opaque_type_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
1452 patch_type (SYMBOL_TYPE (sym), SYMBOL_TYPE (real_sym));
1456 sym = SYMBOL_VALUE_CHAIN (prev);
1460 sym = opaque_type_chain[hash];
1466 sym = SYMBOL_VALUE_CHAIN (sym);
1473 static struct symbol *
1474 process_coff_symbol (cs, aux, section_offsets, objfile)
1475 register struct coff_symbol *cs;
1476 register union internal_auxent *aux;
1477 struct section_offsets *section_offsets;
1478 struct objfile *objfile;
1480 register struct symbol *sym
1481 = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1482 sizeof (struct symbol));
1485 memset (sym, 0, sizeof (struct symbol));
1487 name = EXTERNAL_NAME (name, objfile->obfd);
1488 SYMBOL_NAME (sym) = obstack_copy0 (&objfile->symbol_obstack, name,
1491 /* default assumptions */
1492 SYMBOL_VALUE (sym) = cs->c_value;
1493 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1494 SYMBOL_SECTION (sym) = cs_to_section (cs, objfile);
1496 if (ISFCN (cs->c_type))
1498 SYMBOL_VALUE (sym) += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1500 lookup_function_type (decode_function_type (cs, cs->c_type, aux));
1502 SYMBOL_CLASS (sym) = LOC_BLOCK;
1503 if (cs->c_sclass == C_STAT)
1504 add_symbol_to_list (sym, &file_symbols);
1505 else if (cs->c_sclass == C_EXT)
1506 add_symbol_to_list (sym, &global_symbols);
1510 SYMBOL_TYPE (sym) = decode_type (cs, cs->c_type, aux);
1511 switch (cs->c_sclass)
1517 SYMBOL_CLASS (sym) = LOC_LOCAL;
1518 add_symbol_to_list (sym, &local_symbols);
1522 SYMBOL_CLASS (sym) = LOC_STATIC;
1523 SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
1524 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1525 add_symbol_to_list (sym, &global_symbols);
1529 SYMBOL_CLASS (sym) = LOC_STATIC;
1530 SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
1531 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1532 if (within_function) {
1533 /* Static symbol of local scope */
1534 add_symbol_to_list (sym, &local_symbols);
1537 /* Static symbol at top level of file */
1538 add_symbol_to_list (sym, &file_symbols);
1542 #ifdef C_GLBLREG /* AMD coff */
1546 SYMBOL_CLASS (sym) = LOC_REGISTER;
1547 SYMBOL_VALUE (sym) = SDB_REG_TO_REGNUM(cs->c_value);
1548 add_symbol_to_list (sym, &local_symbols);
1555 SYMBOL_CLASS (sym) = LOC_ARG;
1556 add_symbol_to_list (sym, &local_symbols);
1557 #if !defined (BELIEVE_PCC_PROMOTION)
1558 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
1560 /* If PCC says a parameter is a short or a char,
1561 aligned on an int boundary, realign it to the
1562 "little end" of the int. */
1563 struct type *temptype;
1564 temptype = lookup_fundamental_type (current_objfile,
1566 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
1567 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
1568 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (temptype))
1570 SYMBOL_VALUE (sym) +=
1571 TYPE_LENGTH (temptype)
1572 - TYPE_LENGTH (SYMBOL_TYPE (sym));
1579 SYMBOL_CLASS (sym) = LOC_REGPARM;
1580 SYMBOL_VALUE (sym) = SDB_REG_TO_REGNUM(cs->c_value);
1581 add_symbol_to_list (sym, &local_symbols);
1582 #if !defined (BELIEVE_PCC_PROMOTION)
1583 /* FIXME: This should retain the current type, since it's just
1584 a register value. gnu@adobe, 26Feb93 */
1586 /* If PCC says a parameter is a short or a char,
1587 it is really an int. */
1588 struct type *temptype;
1590 lookup_fundamental_type (current_objfile, FT_INTEGER);
1591 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
1592 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
1595 (TYPE_UNSIGNED (SYMBOL_TYPE (sym))
1596 ? lookup_fundamental_type (current_objfile,
1597 FT_UNSIGNED_INTEGER)
1605 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1606 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1608 /* If type has no name, give it one */
1609 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
1611 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
1612 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
1614 /* If we are giving a name to a type such as "pointer to
1615 foo" or "function returning foo", we better not set
1616 the TYPE_NAME. If the program contains "typedef char
1617 *caddr_t;", we don't want all variables of type char
1618 * to print as caddr_t. This is not just a
1619 consequence of GDB's type management; CC and GCC (at
1620 least through version 2.4) both output variables of
1621 either type char * or caddr_t with the type
1622 refering to the C_TPDEF symbol for caddr_t. If a future
1623 compiler cleans this up it GDB is not ready for it
1624 yet, but if it becomes ready we somehow need to
1625 disable this check (without breaking the PCC/GCC2.4
1630 Fortunately, this check seems not to be necessary
1631 for anything except pointers or functions. */
1635 TYPE_NAME (SYMBOL_TYPE (sym)) =
1636 concat (SYMBOL_NAME (sym), NULL);
1639 /* Ignore vendor section for Harris CX/UX targets. */
1640 else if (cs->c_name[0] == '$')
1642 #endif /* CXUX_TARGET */
1644 /* Keep track of any type which points to empty structured type,
1645 so it can be filled from a definition from another file. A
1646 simple forward reference (TYPE_CODE_UNDEF) is not an
1647 empty structured type, though; the forward references
1648 work themselves out via the magic of coff_lookup_type. */
1649 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR &&
1650 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym))) == 0 &&
1651 TYPE_CODE (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym))) !=
1654 register int i = hashname (SYMBOL_NAME (sym));
1656 SYMBOL_VALUE_CHAIN (sym) = opaque_type_chain[i];
1657 opaque_type_chain[i] = sym;
1659 add_symbol_to_list (sym, &file_symbols);
1665 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1666 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1668 /* Some compilers try to be helpful by inventing "fake"
1669 names for anonymous enums, structures, and unions, like
1670 "~0fake" or ".0fake". Thanks, but no thanks... */
1671 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
1672 if (SYMBOL_NAME(sym) != NULL
1673 && *SYMBOL_NAME(sym) != '~'
1674 && *SYMBOL_NAME(sym) != '.')
1675 TYPE_TAG_NAME (SYMBOL_TYPE (sym)) =
1676 concat (SYMBOL_NAME (sym), NULL);
1678 add_symbol_to_list (sym, &file_symbols);
1688 /* Decode a coff type specifier; return the type that is meant. */
1690 static struct type *
1691 decode_type (cs, c_type, aux)
1692 register struct coff_symbol *cs;
1693 unsigned int c_type;
1694 register union internal_auxent *aux;
1696 register struct type *type = 0;
1697 unsigned int new_c_type;
1699 if (c_type & ~N_BTMASK)
1701 new_c_type = DECREF (c_type);
1704 type = decode_type (cs, new_c_type, aux);
1705 type = lookup_pointer_type (type);
1707 else if (ISFCN (c_type))
1709 type = decode_type (cs, new_c_type, aux);
1710 type = lookup_function_type (type);
1712 else if (ISARY (c_type))
1715 register unsigned short *dim;
1716 struct type *base_type, *index_type, *range_type;
1718 /* Define an array type. */
1719 /* auxent refers to array, not base type */
1720 if (aux->x_sym.x_tagndx.l == 0)
1723 /* shift the indices down */
1724 dim = &aux->x_sym.x_fcnary.x_ary.x_dimen[0];
1727 for (i = 0; *dim && i < DIMNUM - 1; i++, dim++)
1731 base_type = decode_type (cs, new_c_type, aux);
1732 index_type = lookup_fundamental_type (current_objfile, FT_INTEGER);
1734 create_range_type ((struct type *) NULL, index_type, 0, n - 1);
1736 create_array_type ((struct type *) NULL, base_type, range_type);
1741 /* Reference to existing type. This only occurs with the
1742 struct, union, and enum types. EPI a29k coff
1743 fakes us out by producing aux entries with a nonzero
1744 x_tagndx for definitions of structs, unions, and enums, so we
1745 have to check the c_sclass field. SCO 3.2v4 cc gets confused
1746 with pointers to pointers to defined structs, and generates
1747 negative x_tagndx fields. */
1748 if (cs->c_naux > 0 && aux->x_sym.x_tagndx.l != 0)
1750 if (cs->c_sclass != C_STRTAG
1751 && cs->c_sclass != C_UNTAG
1752 && cs->c_sclass != C_ENTAG
1753 && aux->x_sym.x_tagndx.l >= 0)
1755 type = coff_alloc_type (aux->x_sym.x_tagndx.l);
1760 complain (&tagndx_bad_complaint, cs->c_name);
1761 /* And fall through to decode_base_type... */
1765 return decode_base_type (cs, BTYPE (c_type), aux);
1768 /* Decode a coff type specifier for function definition;
1769 return the type that the function returns. */
1771 static struct type *
1772 decode_function_type (cs, c_type, aux)
1773 register struct coff_symbol *cs;
1774 unsigned int c_type;
1775 register union internal_auxent *aux;
1777 if (aux->x_sym.x_tagndx.l == 0)
1778 cs->c_naux = 0; /* auxent refers to function, not base type */
1780 return decode_type (cs, DECREF (c_type), aux);
1785 static struct type *
1786 decode_base_type (cs, c_type, aux)
1787 register struct coff_symbol *cs;
1788 unsigned int c_type;
1789 register union internal_auxent *aux;
1796 /* shows up with "void (*foo)();" structure members */
1797 return lookup_fundamental_type (current_objfile, FT_VOID);
1800 /* DGUX actually defines both T_ARG and T_VOID to the same value. */
1803 /* Shows up in DGUX, I think. Not sure where. */
1804 return lookup_fundamental_type (current_objfile, FT_VOID); /* shouldn't show up here */
1810 /* Intel 960 COFF has this symbol and meaning. */
1811 return lookup_fundamental_type (current_objfile, FT_VOID);
1815 return lookup_fundamental_type (current_objfile, FT_CHAR);
1818 return lookup_fundamental_type (current_objfile, FT_SHORT);
1821 return lookup_fundamental_type (current_objfile, FT_INTEGER);
1824 return lookup_fundamental_type (current_objfile, FT_LONG);
1827 return lookup_fundamental_type (current_objfile, FT_FLOAT);
1830 return lookup_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT);
1833 return lookup_fundamental_type (current_objfile, FT_EXT_PREC_FLOAT);
1836 if (cs->c_naux != 1)
1838 /* anonymous structure type */
1839 type = coff_alloc_type (cs->c_symnum);
1840 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1841 TYPE_NAME (type) = NULL;
1842 /* This used to set the tag to "<opaque>". But I think setting it
1843 to NULL is right, and the printing code can print it as
1845 TYPE_TAG_NAME (type) = NULL;
1846 INIT_CPLUS_SPECIFIC(type);
1847 TYPE_LENGTH (type) = 0;
1848 TYPE_FIELDS (type) = 0;
1849 TYPE_NFIELDS (type) = 0;
1853 type = coff_read_struct_type (cs->c_symnum,
1854 aux->x_sym.x_misc.x_lnsz.x_size,
1855 aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
1860 if (cs->c_naux != 1)
1862 /* anonymous union type */
1863 type = coff_alloc_type (cs->c_symnum);
1864 TYPE_NAME (type) = NULL;
1865 /* This used to set the tag to "<opaque>". But I think setting it
1866 to NULL is right, and the printing code can print it as
1868 TYPE_TAG_NAME (type) = NULL;
1869 INIT_CPLUS_SPECIFIC(type);
1870 TYPE_LENGTH (type) = 0;
1871 TYPE_FIELDS (type) = 0;
1872 TYPE_NFIELDS (type) = 0;
1876 type = coff_read_struct_type (cs->c_symnum,
1877 aux->x_sym.x_misc.x_lnsz.x_size,
1878 aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
1880 TYPE_CODE (type) = TYPE_CODE_UNION;
1884 if (cs->c_naux != 1)
1886 /* anonymous enum type */
1887 type = coff_alloc_type (cs->c_symnum);
1888 TYPE_CODE (type) = TYPE_CODE_ENUM;
1889 TYPE_NAME (type) = NULL;
1890 /* This used to set the tag to "<opaque>". But I think setting it
1891 to NULL is right, and the printing code can print it as
1893 TYPE_TAG_NAME (type) = NULL;
1894 TYPE_LENGTH (type) = 0;
1895 TYPE_FIELDS (type) = 0;
1896 TYPE_NFIELDS(type) = 0;
1900 type = coff_read_enum_type (cs->c_symnum,
1901 aux->x_sym.x_misc.x_lnsz.x_size,
1902 aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
1907 /* shouldn't show up here */
1911 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_CHAR);
1914 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_SHORT);
1917 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER);
1920 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_LONG);
1922 complain (&unexpected_type_complaint, cs->c_name);
1923 return lookup_fundamental_type (current_objfile, FT_VOID);
1926 /* This page contains subroutines of read_type. */
1928 /* Read the description of a structure (or union type) and return an
1929 object describing the type. */
1931 static struct type *
1932 coff_read_struct_type (index, length, lastsym)
1939 struct nextfield *next;
1943 register struct type *type;
1944 register struct nextfield *list = 0;
1945 struct nextfield *new;
1949 struct coff_symbol member_sym;
1950 register struct coff_symbol *ms = &member_sym;
1951 struct internal_syment sub_sym;
1952 union internal_auxent sub_aux;
1955 type = coff_alloc_type (index);
1956 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1957 INIT_CPLUS_SPECIFIC(type);
1958 TYPE_LENGTH (type) = length;
1960 while (!done && symnum < lastsym && symnum < nlist_nsyms_global)
1962 read_one_sym (ms, &sub_sym, &sub_aux);
1964 name = EXTERNAL_NAME (name, current_objfile->obfd);
1966 switch (ms->c_sclass)
1971 /* Get space to record the next field's data. */
1972 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1976 /* Save the data. */
1980 ¤t_objfile->symbol_obstack);
1981 list->field.type = decode_type (ms, ms->c_type, &sub_aux);
1982 list->field.bitpos = 8 * ms->c_value;
1983 list->field.bitsize = 0;
1989 /* Get space to record the next field's data. */
1990 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1994 /* Save the data. */
1998 ¤t_objfile->symbol_obstack);
1999 list->field.type = decode_type (ms, ms->c_type, &sub_aux);
2000 list->field.bitpos = ms->c_value;
2001 list->field.bitsize = sub_aux.x_sym.x_misc.x_lnsz.x_size;
2010 /* Now create the vector of fields, and record how big it is. */
2012 TYPE_NFIELDS (type) = nfields;
2013 TYPE_FIELDS (type) = (struct field *)
2014 TYPE_ALLOC (type, sizeof (struct field) * nfields);
2016 /* Copy the saved-up fields into the field vector. */
2018 for (n = nfields; list; list = list->next)
2019 TYPE_FIELD (type, --n) = list->field;
2024 /* Read a definition of an enumeration type,
2025 and create and return a suitable type object.
2026 Also defines the symbols that represent the values of the type. */
2029 static struct type *
2030 coff_read_enum_type (index, length, lastsym)
2035 register struct symbol *sym;
2036 register struct type *type;
2039 struct pending **symlist;
2040 struct coff_symbol member_sym;
2041 register struct coff_symbol *ms = &member_sym;
2042 struct internal_syment sub_sym;
2043 union internal_auxent sub_aux;
2044 struct pending *osyms, *syms;
2049 type = coff_alloc_type (index);
2050 if (within_function)
2051 symlist = &local_symbols;
2053 symlist = &file_symbols;
2055 o_nsyms = osyms ? osyms->nsyms : 0;
2057 while (!done && symnum < lastsym && symnum < nlist_nsyms_global)
2059 read_one_sym (ms, &sub_sym, &sub_aux);
2061 name = EXTERNAL_NAME (name, current_objfile->obfd);
2063 switch (ms->c_sclass)
2066 sym = (struct symbol *) obstack_alloc
2067 (¤t_objfile->symbol_obstack,
2068 sizeof (struct symbol));
2069 memset (sym, 0, sizeof (struct symbol));
2072 obsavestring (name, strlen (name),
2073 ¤t_objfile->symbol_obstack);
2074 SYMBOL_CLASS (sym) = LOC_CONST;
2075 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2076 SYMBOL_VALUE (sym) = ms->c_value;
2077 add_symbol_to_list (sym, symlist);
2082 /* Sometimes the linker (on 386/ix 2.0.2 at least) screws
2083 up the count of how many symbols to read. So stop
2090 /* Now fill in the fields of the type-structure. */
2093 TYPE_LENGTH (type) = length;
2095 TYPE_LENGTH (type) = TARGET_INT_BIT / TARGET_CHAR_BIT; /* Assume ints */
2096 TYPE_CODE (type) = TYPE_CODE_ENUM;
2097 TYPE_NFIELDS (type) = nsyms;
2098 TYPE_FIELDS (type) = (struct field *)
2099 TYPE_ALLOC (type, sizeof (struct field) * nsyms);
2101 /* Find the symbols for the values and put them into the type.
2102 The symbols can be found in the symlist that we put them on
2103 to cause them to be defined. osyms contains the old value
2104 of that symlist; everything up to there was defined by us. */
2105 /* Note that we preserve the order of the enum constants, so
2106 that in something like "enum {FOO, LAST_THING=FOO}" we print
2107 FOO, not LAST_THING. */
2109 for (syms = *symlist, n = 0; syms; syms = syms->next)
2115 for (; j < syms->nsyms; j++,n++)
2117 struct symbol *xsym = syms->symbol[j];
2118 SYMBOL_TYPE (xsym) = type;
2119 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
2120 TYPE_FIELD_VALUE (type, n) = 0;
2121 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
2122 TYPE_FIELD_BITSIZE (type, n) = 0;
2131 /* Register our ability to parse symbols for coff BFD files. */
2133 static struct sym_fns coff_sym_fns =
2135 bfd_target_coff_flavour,
2136 coff_new_init, /* sym_new_init: init anything gbl to entire symtab */
2137 coff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
2138 coff_symfile_read, /* sym_read: read a symbol file into symtab */
2139 coff_symfile_finish, /* sym_finish: finished with file, cleanup */
2140 default_symfile_offsets,
2141 /* sym_offsets: xlate external to internal form */
2142 NULL /* next: pointer to next struct sym_fns */
2146 _initialize_coffread ()
2148 add_symtab_fns (&coff_sym_fns);