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"
43 struct coff_symfile_info {
44 file_ptr min_lineno_offset; /* Where in file lowest line#s are */
45 file_ptr max_lineno_offset; /* 1+last byte of line#s in file */
47 asection *stabsect; /* Section pointer for .stab section */
48 asection *stabstrsect; /* Section pointer for .stab section */
49 asection *stabindexsect; /* Section pointer for .stab.index section */
53 /* Translate an external name string into a user-visible name. */
54 #define EXTERNAL_NAME(string, abfd) \
55 (string[0] == bfd_get_symbol_leading_char(abfd)? string+1: string)
57 /* To be an sdb debug type, type must have at least a basic or primary
58 derived type. Using this rather than checking against T_NULL is
59 said to prevent core dumps if we try to operate on Michael Bloom
62 #define SDB_TYPE(type) (BTYPE(type) | (type & N_TMASK))
64 /* Convert from an sdb register number to an internal gdb register number.
65 This should be defined in tm.h, if REGISTER_NAMES is not set up
66 to map one to one onto the sdb register numbers. */
68 #ifndef SDB_REG_TO_REGNUM
69 # define SDB_REG_TO_REGNUM(value) (value)
72 /* Core address of start and end of text of current source file.
73 This comes from a ".text" symbol where x_nlinno > 0. */
75 static CORE_ADDR current_source_start_addr;
76 static CORE_ADDR current_source_end_addr;
78 /* The addresses of the symbol table stream and number of symbols
79 of the object file we are reading (as copied into core). */
81 static bfd *nlist_bfd_global;
82 static int nlist_nsyms_global;
84 /* Vector of line number information. */
86 static struct linetable *line_vector;
88 /* Index of next entry to go in line_vector_index. */
90 static int line_vector_index;
92 /* Last line number recorded in the line vector. */
94 static int prev_line_number;
96 /* Number of elements allocated for line_vector currently. */
98 static int line_vector_length;
100 /* Pointers to scratch storage, used for reading raw symbols and auxents. */
102 static char *temp_sym;
103 static char *temp_aux;
105 /* Local variables that hold the shift and mask values for the
106 COFF file that we are currently reading. These come back to us
107 from BFD, and are referenced by their macro names, as well as
108 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
109 macros from include/coff/internal.h . */
111 static unsigned local_n_btmask;
112 static unsigned local_n_btshft;
113 static unsigned local_n_tmask;
114 static unsigned local_n_tshift;
116 #define N_BTMASK local_n_btmask
117 #define N_BTSHFT local_n_btshft
118 #define N_TMASK local_n_tmask
119 #define N_TSHIFT local_n_tshift
121 /* Local variables that hold the sizes in the file of various COFF structures.
122 (We only need to know this to read them from the file -- BFD will then
123 translate the data in them, into `internal_xxx' structs in the right
124 byte order, alignment, etc.) */
126 static unsigned local_linesz;
127 static unsigned local_symesz;
128 static unsigned local_auxesz;
130 /* Chain of typedefs of pointers to empty struct/union types.
131 They are chained thru the SYMBOL_VALUE_CHAIN. */
133 static struct symbol *opaque_type_chain[HASHSIZE];
136 /* The type of the function we are currently reading in. This is
137 used by define_symbol to record the type of arguments to a function. */
139 struct type *in_function_type;
142 /* Complaints about various problems in the file being read */
144 struct complaint ef_complaint =
145 {"Unmatched .ef symbol(s) ignored starting at symnum %d", 0, 0};
147 struct complaint bf_no_aux_complaint =
148 {"`.bf' symbol %d has no aux entry", 0, 0};
150 struct complaint ef_no_aux_complaint =
151 {"`.ef' symbol %d has no aux entry", 0, 0};
153 struct complaint lineno_complaint =
154 {"Line number pointer %d lower than start of line numbers", 0, 0};
156 struct complaint unexpected_type_complaint =
157 {"Unexpected type for symbol %s", 0, 0};
159 struct complaint bad_sclass_complaint =
160 {"Bad n_sclass for symbol %s", 0, 0};
162 struct complaint misordered_blocks_complaint =
163 {"Blocks out of order at address %x", 0, 0};
165 struct complaint tagndx_bad_complaint =
166 {"Symbol table entry for %s has bad tagndx value", 0, 0};
168 struct complaint eb_complaint =
169 {"Mismatched .eb symbol ignored starting at symnum %d", 0, 0};
171 /* Simplified internal version of coff symbol table information */
175 int c_symnum; /* symbol number of this entry */
176 int c_naux; /* 0 if syment only, 1 if syment + auxent, etc */
183 static struct type *coff_read_struct_type PARAMS ((int, int, int));
185 static struct type *decode_base_type PARAMS ((struct coff_symbol *,
187 union internal_auxent *));
189 static struct type *decode_type PARAMS ((struct coff_symbol *, unsigned int,
190 union internal_auxent *));
192 static struct type *decode_function_type PARAMS ((struct coff_symbol *,
194 union internal_auxent *));
196 static struct type *coff_read_enum_type PARAMS ((int, int, int));
198 static struct symbol *process_coff_symbol PARAMS ((struct coff_symbol *,
199 union internal_auxent *,
200 struct section_offsets *,
203 static void patch_opaque_types PARAMS ((struct symtab *));
205 static void patch_type PARAMS ((struct type *, struct type *));
207 static void enter_linenos PARAMS ((long, int, int, struct section_offsets *));
209 static void free_linetab PARAMS ((void));
211 static int init_lineno PARAMS ((bfd *, long, int));
213 static char *getsymname PARAMS ((struct internal_syment *));
215 static void free_stringtab PARAMS ((void));
217 static int init_stringtab PARAMS ((bfd *, long));
219 static void read_one_sym PARAMS ((struct coff_symbol *,
220 struct internal_syment *,
221 union internal_auxent *));
223 static void coff_symtab_read PARAMS ((long, int, struct section_offsets *,
226 static void find_linenos PARAMS ((bfd *, sec_ptr, PTR));
228 static void coff_symfile_init PARAMS ((struct objfile *));
230 static void coff_new_init PARAMS ((struct objfile *));
232 static void coff_symfile_read PARAMS ((struct objfile *,
233 struct section_offsets *, int));
235 static void coff_symfile_finish PARAMS ((struct objfile *));
237 static void record_minimal_symbol PARAMS ((char *, CORE_ADDR,
238 enum minimal_symbol_type,
241 static void coff_end_symtab PARAMS ((struct objfile *));
243 static void complete_symtab PARAMS ((char *, CORE_ADDR, unsigned int));
245 static void coff_start_symtab PARAMS ((void));
247 static void coff_record_line PARAMS ((int, CORE_ADDR));
249 static struct type *coff_alloc_type PARAMS ((int));
251 static struct type **coff_lookup_type PARAMS ((int));
253 static void coff_locate_sections PARAMS ((bfd *, asection *, PTR));
255 /* We are called once per section from coff_symfile_read. We
256 need to examine each section we are passed, check to see
257 if it is something we are interested in processing, and
258 if so, stash away some access information for the section.
260 FIXME: The section names should not be hardwired strings (what
261 should they be? I don't think most object file formats have enough
262 section flags to specify what kind of debug section it is
266 coff_locate_sections (ignore_abfd, sectp, csip)
271 register struct coff_symfile_info *csi;
273 csi = (struct coff_symfile_info *) csip;
274 if (STREQ (sectp->name, ".stab"))
276 csi->stabsect = sectp;
278 else if (STREQ (sectp->name, ".stabstr"))
280 csi->stabstrsect = sectp;
282 else if (STREQ (sectp->name, ".stab.index"))
284 csi->stabindexsect = sectp;
288 /* Return the section_offsets* that CS points to. */
289 static int cs_to_section PARAMS ((struct coff_symbol *, struct objfile *));
291 struct find_targ_sec_arg {
296 static void find_targ_sec PARAMS ((bfd *, asection *, void *));
298 static void find_targ_sec (abfd, sect, obj)
303 struct find_targ_sec_arg *args = (struct find_targ_sec_arg *)obj;
304 if (sect->target_index == args->targ_index)
306 /* This is the section. Figure out what SECT_OFF_* code it is. */
307 if (bfd_get_section_flags (abfd, sect) & SEC_CODE)
308 *args->resultp = SECT_OFF_TEXT;
309 else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)
310 *args->resultp = SECT_OFF_DATA;
312 *args->resultp = SECT_OFF_BSS;
316 /* Return the section number (SECT_OFF_*) that CS points to. */
318 cs_to_section (cs, objfile)
319 struct coff_symbol *cs;
320 struct objfile *objfile;
322 int off = SECT_OFF_TEXT;
323 struct find_targ_sec_arg args;
324 args.targ_index = cs->c_secnum;
326 bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
330 /* Look up a coff type-number index. Return the address of the slot
331 where the type for that index is stored.
332 The type-number is in INDEX.
334 This can be used for finding the type associated with that index
335 or for associating a new type with the index. */
337 static struct type **
338 coff_lookup_type (index)
341 if (index >= type_vector_length)
343 int old_vector_length = type_vector_length;
345 type_vector_length *= 2;
346 if (index /* is still */ >= type_vector_length)
347 type_vector_length = index * 2;
349 type_vector = (struct type **)
350 xrealloc ((char *) type_vector,
351 type_vector_length * sizeof (struct type *));
352 memset (&type_vector[old_vector_length], 0,
353 (type_vector_length - old_vector_length) * sizeof(struct type *));
355 return &type_vector[index];
358 /* Make sure there is a type allocated for type number index
359 and return the type object.
360 This can create an empty (zeroed) type object. */
363 coff_alloc_type (index)
366 register struct type **type_addr = coff_lookup_type (index);
367 register struct type *type = *type_addr;
369 /* If we are referring to a type not known at all yet,
370 allocate an empty type for it.
371 We will fill it in later if we find out how. */
374 type = alloc_type (current_objfile);
380 /* Record a line number entry for line LINE at address PC.
381 FIXME: Use record_line instead. */
384 coff_record_line (line, pc)
388 struct linetable_entry *e;
389 /* Make sure line vector is big enough. */
391 if (line_vector_index + 2 >= line_vector_length)
393 line_vector_length *= 2;
394 line_vector = (struct linetable *)
395 xrealloc ((char *) line_vector, sizeof (struct linetable)
396 + (line_vector_length
397 * sizeof (struct linetable_entry)));
400 e = line_vector->item + line_vector_index++;
401 e->line = line; e->pc = pc;
404 /* Start a new symtab for a new source file.
405 This is called when a COFF ".file" symbol is seen;
406 it indicates the start of data for one original source file. */
412 /* We fill in the filename later. start_symtab puts
413 this pointer into last_source_file and we put it in
414 subfiles->name, which end_symtab frees; that's why
415 it must be malloc'd. */
417 /* We never know the directory name for COFF. */
419 /* The start address is irrelevant, since we set
420 last_source_start_addr in coff_end_symtab. */
423 /* Initialize the source file line number information for this file. */
425 if (line_vector) /* Unlikely, but maybe possible? */
426 free ((PTR)line_vector);
427 line_vector_index = 0;
428 line_vector_length = 1000;
429 prev_line_number = -2; /* Force first line number to be explicit */
430 line_vector = (struct linetable *)
431 xmalloc (sizeof (struct linetable)
432 + line_vector_length * sizeof (struct linetable_entry));
435 /* Save the vital information from when starting to read a file,
436 for use when closing off the current file.
437 NAME is the file name the symbols came from, START_ADDR is the first
438 text address for the file, and SIZE is the number of bytes of text. */
441 complete_symtab (name, start_addr, size)
443 CORE_ADDR start_addr;
446 if (last_source_file != NULL)
447 free (last_source_file);
448 last_source_file = savestring (name, strlen (name));
449 current_source_start_addr = start_addr;
450 current_source_end_addr = start_addr + size;
452 if (current_objfile -> ei.entry_point >= current_source_start_addr &&
453 current_objfile -> ei.entry_point < current_source_end_addr)
455 current_objfile -> ei.entry_file_lowpc = current_source_start_addr;
456 current_objfile -> ei.entry_file_highpc = current_source_end_addr;
460 /* Finish the symbol definitions for one main source file,
461 close off all the lexical contexts for that file
462 (creating struct block's for them), then make the
463 struct symtab for that file and put it in the list of all such. */
466 coff_end_symtab (objfile)
467 struct objfile *objfile;
469 struct symtab *symtab;
471 last_source_start_addr = current_source_start_addr;
473 /* For no good reason, this file stores the number of entries in a
474 separate variable instead of in line_vector->nitems. Fix it. */
476 line_vector->nitems = line_vector_index;
478 /* For COFF, we only have one subfile, so we can just look at
479 subfiles and not worry about there being other elements in the
480 chain. We fill in various fields now because we didn't know them
481 before (or because doing it now is simply an artifact of how this
482 file used to be written). */
483 subfiles->line_vector = line_vector;
484 subfiles->name = last_source_file;
486 /* sort_pending is needed for amdcoff, at least.
487 sort_linevec is needed for the SCO compiler. */
488 symtab = end_symtab (current_source_end_addr, 1, 1, objfile, 0);
491 free_named_symtabs (symtab->filename);
493 /* Reinitialize for beginning of new file. */
495 line_vector_length = -1;
496 last_source_file = NULL;
500 record_minimal_symbol (name, address, type, objfile)
503 enum minimal_symbol_type type;
504 struct objfile *objfile;
506 /* We don't want TDESC entry points in the minimal symbol table */
507 if (name[0] == '@') return;
509 prim_record_minimal_symbol
510 (obsavestring (name, strlen (name), &objfile->symbol_obstack),
515 /* coff_symfile_init ()
516 is the coff-specific initialization routine for reading symbols.
517 It is passed a struct objfile which contains, among other things,
518 the BFD for the file whose symbols are being read, and a slot for
519 a pointer to "private data" which we fill with cookies and other
520 treats for coff_symfile_read ().
522 We will only be called if this is a COFF or COFF-like file.
523 BFD handles figuring out the format of the file, and code in symtab.c
524 uses BFD's determination to vector to us.
526 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
529 coff_symfile_init (objfile)
530 struct objfile *objfile;
532 bfd *abfd = objfile->obfd;
534 /* Allocate struct to keep track of stab reading. */
535 objfile->sym_stab_info = (PTR)
536 xmmalloc (objfile -> md, sizeof (struct dbx_symfile_info));
538 memset ((PTR) objfile->sym_stab_info, 0, sizeof (struct dbx_symfile_info));
540 /* Allocate struct to keep track of the symfile */
541 objfile -> sym_private = xmmalloc (objfile -> md,
542 sizeof (struct coff_symfile_info));
544 memset (objfile->sym_private, 0, sizeof (struct coff_symfile_info));
546 init_entry_point_info (objfile);
549 /* This function is called for every section; it finds the outer limits
550 of the line table (minimum and maximum file offset) so that the
551 mainline code can read the whole thing for efficiency. */
555 find_linenos (abfd, asect, vpinfo)
560 struct coff_symfile_info *info;
562 file_ptr offset, maxoff;
564 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
565 count = asect->lineno_count;
570 size = count * local_linesz;
572 info = (struct coff_symfile_info *)vpinfo;
573 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
574 offset = asect->line_filepos;
577 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
578 info->min_lineno_offset = offset;
580 maxoff = offset + size;
581 if (maxoff > info->max_lineno_offset)
582 info->max_lineno_offset = maxoff;
586 /* The BFD for this file -- only good while we're actively reading
587 symbols into a psymtab or a symtab. */
589 static bfd *symfile_bfd;
591 /* Read a symbol file, after initialization by coff_symfile_init. */
595 coff_symfile_read (objfile, section_offsets, mainline)
596 struct objfile *objfile;
597 struct section_offsets *section_offsets;
600 struct coff_symfile_info *info;
601 struct dbx_symfile_info *dbxinfo;
602 bfd *abfd = objfile->obfd;
603 coff_data_type *cdata = coff_data (abfd);
604 char *name = bfd_get_filename (abfd);
608 int stringtab_offset;
609 struct cleanup *back_to;
610 int stabsize, stabstrsize;
612 info = (struct coff_symfile_info *) objfile -> sym_private;
613 dbxinfo = (struct dbx_symfile_info *) objfile->sym_stab_info;
614 symfile_bfd = abfd; /* Kludge for swap routines */
616 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
617 num_symbols = bfd_get_symcount (abfd); /* How many syms */
618 symtab_offset = cdata->sym_filepos; /* Symbol table file offset */
619 stringtab_offset = symtab_offset + /* String table file offset */
620 num_symbols * cdata->local_symesz;
622 /* Set a few file-statics that give us specific information about
623 the particular COFF file format we're reading. */
624 local_linesz = cdata->local_linesz;
625 local_n_btmask = cdata->local_n_btmask;
626 local_n_btshft = cdata->local_n_btshft;
627 local_n_tmask = cdata->local_n_tmask;
628 local_n_tshift = cdata->local_n_tshift;
629 local_linesz = cdata->local_linesz;
630 local_symesz = cdata->local_symesz;
631 local_auxesz = cdata->local_auxesz;
633 /* Allocate space for raw symbol and aux entries, based on their
634 space requirements as reported by BFD. */
635 temp_sym = (char *) xmalloc
636 (cdata->local_symesz + cdata->local_auxesz);
637 temp_aux = temp_sym + cdata->local_symesz;
638 back_to = make_cleanup (free_current_contents, &temp_sym);
641 /* Read the line number table, all at once. */
642 info->min_lineno_offset = 0;
643 info->max_lineno_offset = 0;
644 bfd_map_over_sections (abfd, find_linenos, (PTR) info);
646 make_cleanup (free_linetab, 0);
647 val = init_lineno (abfd, info->min_lineno_offset,
648 info->max_lineno_offset - info->min_lineno_offset);
650 error ("\"%s\": error reading line numbers\n", name);
652 /* Now read the string table, all at once. */
654 make_cleanup (free_stringtab, 0);
655 val = init_stringtab (abfd, stringtab_offset);
657 error ("\"%s\": can't get string table", name);
659 init_minimal_symbol_collection ();
660 make_cleanup (discard_minimal_symbols, 0);
662 /* Now that the executable file is positioned at symbol table,
663 process it and define symbols accordingly. */
665 coff_symtab_read ((long) symtab_offset, num_symbols, section_offsets,
668 /* Sort symbols alphabetically within each block. */
673 for (s = objfile -> symtabs; s != NULL; s = s -> next)
674 sort_symtab_syms (s);
677 /* Install any minimal symbols that have been collected as the current
678 minimal symbols for this objfile. */
680 install_minimal_symbols (objfile);
682 bfd_map_over_sections (abfd, coff_locate_sections, (PTR) info);
686 /* FIXME: dubious. Why can't we use something normal like
687 bfd_get_section_contents? */
688 bfd_seek (abfd, abfd->where, 0);
690 stabsize = bfd_section_size (abfd, info->stabsect);
691 stabstrsize = bfd_section_size (abfd, info->stabstrsect);
693 coffstab_build_psymtabs (objfile,
696 info->stabsect->filepos, stabsize,
697 info->stabstrsect->filepos, stabstrsize);
700 do_cleanups (back_to);
704 coff_new_init (ignore)
705 struct objfile *ignore;
709 /* Perform any local cleanups required when we are done with a particular
710 objfile. I.E, we are in the process of discarding all symbol information
711 for an objfile, freeing up all memory held for it, and unlinking the
712 objfile struct from the global list of known objfiles. */
715 coff_symfile_finish (objfile)
716 struct objfile *objfile;
718 if (objfile -> sym_private != NULL)
720 mfree (objfile -> md, objfile -> sym_private);
725 /* Given pointers to a symbol table in coff style exec file,
726 analyze them and create struct symtab's describing the symbols.
727 NSYMS is the number of symbols in the symbol table.
728 We read them one at a time using read_one_sym (). */
731 coff_symtab_read (symtab_offset, nsyms, section_offsets, objfile)
734 struct section_offsets *section_offsets;
735 struct objfile *objfile;
737 register struct context_stack *new;
738 struct coff_symbol coff_symbol;
739 register struct coff_symbol *cs = &coff_symbol;
740 static struct internal_syment main_sym;
741 static union internal_auxent main_aux;
742 struct coff_symbol fcn_cs_saved;
743 static struct internal_syment fcn_sym_saved;
744 static union internal_auxent fcn_aux_saved;
746 /* A .file is open. */
747 int in_source_file = 0;
748 int next_file_symnum = -1;
749 /* Name of the current file. */
750 char *filestring = "";
752 int fcn_first_line = 0;
753 int fcn_last_line = 0;
754 int fcn_start_addr = 0;
755 long fcn_line_ptr = 0;
759 /* Work around a stdio bug in SunOS4.1.1 (this makes me nervous....
760 it's hard to know I've really worked around it. The fix should be
761 harmless, anyway). The symptom of the bug is that the first
762 fread (in read_one_sym), will (in my example) actually get data
763 from file offset 268, when the fseek was to 264 (and ftell shows
764 264). This causes all hell to break loose. I was unable to
765 reproduce this on a short test program which operated on the same
766 file, performing (I think) the same sequence of operations.
768 It stopped happening when I put in this (former) rewind().
770 FIXME: Find out if this has been reported to Sun, whether it has
771 been fixed in a later release, etc. */
773 bfd_seek (objfile->obfd, 0, 0);
775 /* Position to read the symbol table. */
776 val = bfd_seek (objfile->obfd, (long) symtab_offset, 0);
778 perror_with_name (objfile->name);
780 current_objfile = objfile;
781 nlist_bfd_global = objfile->obfd;
782 nlist_nsyms_global = nsyms;
783 last_source_file = NULL;
784 memset (opaque_type_chain, 0, sizeof opaque_type_chain);
786 if (type_vector) /* Get rid of previous one */
787 free ((PTR) type_vector);
788 type_vector_length = 160;
789 type_vector = (struct type **)
790 xmalloc (type_vector_length * sizeof (struct type *));
791 memset (type_vector, 0, type_vector_length * sizeof (struct type *));
793 coff_start_symtab ();
796 while (symnum < nsyms)
798 QUIT; /* Make this command interruptable. */
800 read_one_sym (cs, &main_sym, &main_aux);
803 temp_sem_val = cs->c_name[0] << 24 | cs->c_name[1] << 16 |
804 cs->c_name[2] << 8 | cs->c_name[3];
805 if (int_sem_val == temp_sem_val)
806 last_coffsem = (int) strtol (cs->c_name+4, (char **) NULL, 10);
809 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
811 if (last_source_file)
812 coff_end_symtab (objfile);
814 coff_start_symtab ();
815 complete_symtab ("_globals_", 0, 0);
816 /* done with all files, everything from here on out is globals */
819 /* Special case for file with type declarations only, no text. */
820 if (!last_source_file && SDB_TYPE (cs->c_type)
821 && cs->c_secnum == N_DEBUG)
822 complete_symtab (filestring, 0, 0);
824 /* Typedefs should not be treated as symbol definitions. */
825 if (ISFCN (cs->c_type) && cs->c_sclass != C_TPDEF)
827 /* Record all functions -- external and static -- in minsyms. */
828 tmpaddr = cs->c_value + ANOFFSET (section_offsets, SECT_OFF_TEXT);
829 record_minimal_symbol (cs->c_name, tmpaddr, mst_text, objfile);
831 fcn_line_ptr = main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
832 fcn_start_addr = tmpaddr;
834 fcn_sym_saved = main_sym;
835 fcn_aux_saved = main_aux;
839 switch (cs->c_sclass)
848 complain (&bad_sclass_complaint, cs->c_name);
852 /* c_value field contains symnum of next .file entry in table
853 or symnum of first global after last .file. */
854 next_file_symnum = cs->c_value;
856 filestring = coff_getfilename (&main_aux);
860 /* Complete symbol table for last object file
861 containing debugging information. */
862 if (last_source_file)
864 coff_end_symtab (objfile);
865 coff_start_symtab ();
871 if (cs->c_name[0] == '.')
873 if (STREQ (cs->c_name, ".text")) {
874 /* FIXME: don't wire in ".text" as section name
876 /* Check for in_source_file deals with case of
877 a file with debugging symbols
878 followed by a later file with no symbols. */
880 complete_symtab (filestring,
881 cs->c_value + ANOFFSET (section_offsets, SECT_OFF_TEXT),
882 main_aux.x_scn.x_scnlen);
885 /* flush rest of '.' symbols */
888 else if (!SDB_TYPE (cs->c_type)
889 && cs->c_name[0] == 'L'
890 && (strncmp (cs->c_name, "LI%", 3) == 0
891 || strncmp (cs->c_name, "LF%", 3) == 0
892 || strncmp (cs->c_name,"LC%",3) == 0
893 || strncmp (cs->c_name,"LP%",3) == 0
894 || strncmp (cs->c_name,"LPB%",4) == 0
895 || strncmp (cs->c_name,"LBB%",4) == 0
896 || strncmp (cs->c_name,"LBE%",4) == 0
897 || strncmp (cs->c_name,"LPBX%",5) == 0))
898 /* At least on a 3b1, gcc generates swbeg and string labels
899 that look like this. Ignore them. */
901 /* fall in for static symbols that don't start with '.' */
904 /* Record it in the minimal symbols regardless of
905 SDB_TYPE. This parallels what we do for other debug
906 formats, and probably is needed to make
907 print_address_symbolic work right without the (now
908 gone) "set fast-symbolic-addr off" kludge. */
910 /* FIXME: should use mst_abs, and not relocate, if absolute. */
911 enum minimal_symbol_type ms_type;
914 if (cs->c_secnum == N_UNDEF)
916 /* This is a common symbol. See if the target
917 environment knows where it has been relocated to. */
919 if (target_lookup_symbol (cs->c_name, &reladdr))
921 /* Error in lookup; ignore symbol. */
925 /* The address has already been relocated; make sure that
926 objfile_relocate doesn't relocate it again. */
928 ms_type = cs->c_sclass == C_STAT ? mst_file_bss : mst_bss;
932 sec = cs_to_section (cs, objfile);
933 tmpaddr = cs->c_value;
934 if (cs->c_sclass != C_STAT)
935 tmpaddr += ANOFFSET (section_offsets, sec);
940 case SECT_OFF_RODATA:
942 cs->c_sclass == C_STAT ? mst_file_text : mst_text;
946 cs->c_sclass == C_STAT ? mst_file_data : mst_data;
950 cs->c_sclass == C_STAT ? mst_file_bss : mst_bss;
953 ms_type = mst_unknown;
958 if (cs->c_name[0] != '@' /* Skip tdesc symbols */)
959 prim_record_minimal_symbol_and_info
960 (obsavestring (cs->c_name, strlen (cs->c_name),
961 &objfile->symbol_obstack),
968 if (SDB_TYPE (cs->c_type))
971 sym = process_coff_symbol
972 (cs, &main_aux, section_offsets, objfile);
973 SYMBOL_VALUE (sym) = tmpaddr;
974 SYMBOL_SECTION (sym) = sec;
980 if (STREQ (cs->c_name, ".bf"))
984 /* value contains address of first non-init type code */
985 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
986 contains line number of '{' } */
988 complain (&bf_no_aux_complaint, cs->c_symnum);
989 fcn_first_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
991 /* Might want to check that locals are 0 and
992 context_stack_depth is zero, and complain if not. */
995 new = push_context (depth, fcn_start_addr);
996 fcn_cs_saved.c_name = getsymname (&fcn_sym_saved);
998 process_coff_symbol (&fcn_cs_saved, &fcn_aux_saved,
999 section_offsets, objfile);
1001 else if (STREQ (cs->c_name, ".ef"))
1003 /* the value of .ef is the address of epilogue code;
1004 not useful for gdb. */
1005 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1006 contains number of lines to '}' */
1007 new = pop_context ();
1008 /* Stack must be empty now. */
1009 if (context_stack_depth > 0 || new == NULL)
1011 complain (&ef_complaint, cs->c_symnum);
1012 within_function = 0;
1015 if (cs->c_naux != 1)
1017 complain (&ef_no_aux_complaint, cs->c_symnum);
1018 fcn_last_line = 0x7FFFFFFF;
1022 fcn_last_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
1024 enter_linenos (fcn_line_ptr, fcn_first_line, fcn_last_line,
1027 finish_block (new->name, &local_symbols, new->old_blocks,
1029 #if defined (FUNCTION_EPILOGUE_SIZE)
1030 /* This macro should be defined only on
1032 fcn_aux_saved.x_sym.x_misc.x_fsize
1033 field is always zero.
1034 So use the .bf record information that
1035 points to the epilogue and add the size
1038 + FUNCTION_EPILOGUE_SIZE
1039 + ANOFFSET (section_offsets, SECT_OFF_TEXT),
1041 fcn_cs_saved.c_value
1042 + fcn_aux_saved.x_sym.x_misc.x_fsize
1043 + ANOFFSET (section_offsets, SECT_OFF_TEXT),
1047 within_function = 0;
1052 if (STREQ (cs->c_name, ".bb"))
1054 tmpaddr = cs->c_value;
1055 tmpaddr += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1056 push_context (++depth, tmpaddr);
1058 else if (STREQ (cs->c_name, ".eb"))
1060 new = pop_context ();
1061 if (depth-- != new->depth)
1063 complain (&eb_complaint, symnum);
1066 if (local_symbols && context_stack_depth > 0)
1069 cs->c_value + ANOFFSET (section_offsets, SECT_OFF_TEXT);
1070 /* Make a block for the local symbols within. */
1071 finish_block (0, &local_symbols, new->old_blocks,
1072 new->start_addr, tmpaddr, objfile);
1074 /* Now pop locals of block just finished. */
1075 local_symbols = new->locals;
1080 process_coff_symbol (cs, &main_aux, section_offsets, objfile);
1085 if (last_source_file)
1086 coff_end_symtab (objfile);
1088 /* Patch up any opaque types (references to types that are not defined
1089 in the file where they are referenced, e.g. "struct foo *bar"). */
1090 ALL_OBJFILE_SYMTABS (objfile, s)
1091 patch_opaque_types (s);
1093 current_objfile = NULL;
1096 /* Routines for reading headers and symbols from executable. */
1098 /* Read the next symbol, swap it, and return it in both internal_syment
1099 form, and coff_symbol form. Also return its first auxent, if any,
1100 in internal_auxent form, and skip any other auxents. */
1103 read_one_sym (cs, sym, aux)
1104 register struct coff_symbol *cs;
1105 register struct internal_syment *sym;
1106 register union internal_auxent *aux;
1110 cs->c_symnum = symnum;
1111 bfd_read (temp_sym, local_symesz, 1, nlist_bfd_global);
1112 bfd_coff_swap_sym_in (symfile_bfd, temp_sym, (char *)sym);
1113 cs->c_naux = sym->n_numaux & 0xff;
1114 if (cs->c_naux >= 1)
1116 bfd_read (temp_aux, local_auxesz, 1, nlist_bfd_global);
1117 bfd_coff_swap_aux_in (symfile_bfd, temp_aux, sym->n_type, sym->n_sclass,
1118 0, cs->c_naux, (char *)aux);
1119 /* If more than one aux entry, read past it (only the first aux
1121 for (i = 1; i < cs->c_naux; i++)
1122 bfd_read (temp_aux, local_auxesz, 1, nlist_bfd_global);
1124 cs->c_name = getsymname (sym);
1125 cs->c_value = sym->n_value;
1126 cs->c_sclass = (sym->n_sclass & 0xff);
1127 cs->c_secnum = sym->n_scnum;
1128 cs->c_type = (unsigned) sym->n_type;
1129 if (!SDB_TYPE (cs->c_type))
1132 symnum += 1 + cs->c_naux;
1135 /* Support for string table handling */
1137 static char *stringtab = NULL;
1140 init_stringtab (abfd, offset)
1146 unsigned char lengthbuf[4];
1150 /* If the file is stripped, the offset might be zero, indicating no
1151 string table. Just return with `stringtab' set to null. */
1155 if (bfd_seek (abfd, offset, 0) < 0)
1158 val = bfd_read ((char *)lengthbuf, sizeof lengthbuf, 1, abfd);
1159 length = bfd_h_get_32 (symfile_bfd, lengthbuf);
1161 /* If no string table is needed, then the file may end immediately
1162 after the symbols. Just return with `stringtab' set to null. */
1163 if (val != sizeof lengthbuf || length < sizeof lengthbuf)
1166 stringtab = (char *) xmalloc (length);
1167 /* This is in target format (probably not very useful, and not currently
1168 used), not host format. */
1169 memcpy (stringtab, lengthbuf, sizeof lengthbuf);
1170 if (length == sizeof length) /* Empty table -- just the count */
1173 val = bfd_read (stringtab + sizeof lengthbuf, length - sizeof lengthbuf, 1, abfd);
1174 if (val != length - sizeof lengthbuf || stringtab[length - 1] != '\0')
1189 getsymname (symbol_entry)
1190 struct internal_syment *symbol_entry;
1192 static char buffer[SYMNMLEN+1];
1195 if (symbol_entry->_n._n_n._n_zeroes == 0)
1197 /* FIXME: Probably should be detecting corrupt symbol files by
1198 seeing whether offset points to within the stringtab. */
1199 result = stringtab + symbol_entry->_n._n_n._n_offset;
1203 strncpy (buffer, symbol_entry->_n._n_name, SYMNMLEN);
1204 buffer[SYMNMLEN] = '\0';
1210 /* Extract the file name from the aux entry of a C_FILE symbol. Return
1211 only the last component of the name. Result is in static storage and
1212 is only good for temporary use. */
1215 coff_getfilename (aux_entry)
1216 union internal_auxent *aux_entry;
1218 static char buffer[BUFSIZ];
1219 register char *temp;
1222 if (aux_entry->x_file.x_n.x_zeroes == 0)
1223 strcpy (buffer, stringtab + aux_entry->x_file.x_n.x_offset);
1226 strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
1227 buffer[FILNMLEN] = '\0';
1231 /* FIXME: We should not be throwing away the information about what
1232 directory. It should go into dirname of the symtab, or some such
1234 if ((temp = strrchr (result, '/')) != NULL)
1239 /* Support for line number handling. */
1241 static char *linetab = NULL;
1242 static long linetab_offset;
1243 static unsigned long linetab_size;
1245 /* Read in all the line numbers for fast lookups later. Leave them in
1246 external (unswapped) format in memory; we'll swap them as we enter
1247 them into GDB's data structures. */
1250 init_lineno (abfd, offset, size)
1257 linetab_offset = offset;
1258 linetab_size = size;
1265 if (bfd_seek (abfd, offset, 0) < 0)
1268 /* Allocate the desired table, plus a sentinel */
1269 linetab = (char *) xmalloc (size + local_linesz);
1271 val = bfd_read (linetab, size, 1, abfd);
1275 /* Terminate it with an all-zero sentinel record */
1276 memset (linetab + size, 0, local_linesz);
1289 #if !defined (L_LNNO32)
1290 #define L_LNNO32(lp) ((lp)->l_lnno)
1294 enter_linenos (file_offset, first_line, last_line, section_offsets)
1296 register int first_line;
1297 register int last_line;
1298 struct section_offsets *section_offsets;
1300 register char *rawptr;
1301 struct internal_lineno lptr;
1303 if (file_offset < linetab_offset)
1305 complain (&lineno_complaint, file_offset);
1306 if (file_offset > linetab_size) /* Too big to be an offset? */
1308 file_offset += linetab_offset; /* Try reading at that linetab offset */
1311 rawptr = &linetab[file_offset - linetab_offset];
1313 /* skip first line entry for each function */
1314 rawptr += local_linesz;
1315 /* line numbers start at one for the first line of the function */
1319 bfd_coff_swap_lineno_in (symfile_bfd, rawptr, &lptr);
1320 rawptr += local_linesz;
1321 /* The next function, or the sentinel, will have L_LNNO32 zero; we exit. */
1322 if (L_LNNO32 (&lptr) && L_LNNO32 (&lptr) <= last_line)
1323 coff_record_line (first_line + L_LNNO32 (&lptr),
1325 + ANOFFSET (section_offsets, SECT_OFF_TEXT));
1332 patch_type (type, real_type)
1334 struct type *real_type;
1336 register struct type *target = TYPE_TARGET_TYPE (type);
1337 register struct type *real_target = TYPE_TARGET_TYPE (real_type);
1338 int field_size = TYPE_NFIELDS (real_target) * sizeof (struct field);
1340 TYPE_LENGTH (target) = TYPE_LENGTH (real_target);
1341 TYPE_NFIELDS (target) = TYPE_NFIELDS (real_target);
1342 TYPE_FIELDS (target) = (struct field *) TYPE_ALLOC (target, field_size);
1344 memcpy (TYPE_FIELDS (target), TYPE_FIELDS (real_target), field_size);
1346 if (TYPE_NAME (real_target))
1348 if (TYPE_NAME (target))
1349 free (TYPE_NAME (target));
1350 TYPE_NAME (target) = concat (TYPE_NAME (real_target), NULL);
1354 /* Patch up all appropriate typedef symbols in the opaque_type_chains
1355 so that they can be used to print out opaque data structures properly. */
1358 patch_opaque_types (s)
1361 register struct block *b;
1363 register struct symbol *real_sym;
1365 /* Go through the per-file symbols only */
1366 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
1367 for (i = BLOCK_NSYMS (b) - 1; i >= 0; i--)
1369 /* Find completed typedefs to use to fix opaque ones.
1370 Remove syms from the chain when their types are stored,
1371 but search the whole chain, as there may be several syms
1372 from different files with the same name. */
1373 real_sym = BLOCK_SYM (b, i);
1374 if (SYMBOL_CLASS (real_sym) == LOC_TYPEDEF &&
1375 SYMBOL_NAMESPACE (real_sym) == VAR_NAMESPACE &&
1376 TYPE_CODE (SYMBOL_TYPE (real_sym)) == TYPE_CODE_PTR &&
1377 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym))) != 0)
1379 register char *name = SYMBOL_NAME (real_sym);
1380 register int hash = hashname (name);
1381 register struct symbol *sym, *prev;
1384 for (sym = opaque_type_chain[hash]; sym;)
1386 if (name[0] == SYMBOL_NAME (sym)[0] &&
1387 STREQ (name + 1, SYMBOL_NAME (sym) + 1))
1391 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
1395 opaque_type_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
1398 patch_type (SYMBOL_TYPE (sym), SYMBOL_TYPE (real_sym));
1402 sym = SYMBOL_VALUE_CHAIN (prev);
1406 sym = opaque_type_chain[hash];
1412 sym = SYMBOL_VALUE_CHAIN (sym);
1419 static struct symbol *
1420 process_coff_symbol (cs, aux, section_offsets, objfile)
1421 register struct coff_symbol *cs;
1422 register union internal_auxent *aux;
1423 struct section_offsets *section_offsets;
1424 struct objfile *objfile;
1426 register struct symbol *sym
1427 = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1428 sizeof (struct symbol));
1431 memset (sym, 0, sizeof (struct symbol));
1433 name = EXTERNAL_NAME (name, objfile->obfd);
1434 SYMBOL_NAME (sym) = obstack_copy0 (&objfile->symbol_obstack, name,
1437 /* default assumptions */
1438 SYMBOL_VALUE (sym) = cs->c_value;
1439 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1440 SYMBOL_SECTION (sym) = cs_to_section (cs, objfile);
1442 if (ISFCN (cs->c_type))
1444 SYMBOL_VALUE (sym) += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1446 /* FIXME: This has NOT been tested. The DBX version has.. */
1447 /* Generate a template for the type of this function. The
1448 types of the arguments will be added as we read the symbol
1450 struct type *new = (struct type *)
1451 obstack_alloc (&objfile->symbol_obstack, sizeof (struct type));
1453 memcpy (new, lookup_function_type (decode_function_type (cs, cs->c_type, aux)),
1454 sizeof(struct type));
1455 SYMBOL_TYPE (sym) = new;
1456 in_function_type = SYMBOL_TYPE(sym);
1459 lookup_function_type (decode_function_type (cs, cs->c_type, aux));
1462 SYMBOL_CLASS (sym) = LOC_BLOCK;
1463 if (cs->c_sclass == C_STAT)
1464 add_symbol_to_list (sym, &file_symbols);
1465 else if (cs->c_sclass == C_EXT)
1466 add_symbol_to_list (sym, &global_symbols);
1470 SYMBOL_TYPE (sym) = decode_type (cs, cs->c_type, aux);
1471 switch (cs->c_sclass)
1477 SYMBOL_CLASS (sym) = LOC_LOCAL;
1478 add_symbol_to_list (sym, &local_symbols);
1482 SYMBOL_CLASS (sym) = LOC_STATIC;
1483 SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
1484 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1485 add_symbol_to_list (sym, &global_symbols);
1489 SYMBOL_CLASS (sym) = LOC_STATIC;
1490 SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
1491 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1492 if (within_function) {
1493 /* Static symbol of local scope */
1494 add_symbol_to_list (sym, &local_symbols);
1497 /* Static symbol at top level of file */
1498 add_symbol_to_list (sym, &file_symbols);
1502 #ifdef C_GLBLREG /* AMD coff */
1506 SYMBOL_CLASS (sym) = LOC_REGISTER;
1507 SYMBOL_VALUE (sym) = SDB_REG_TO_REGNUM(cs->c_value);
1508 add_symbol_to_list (sym, &local_symbols);
1515 SYMBOL_CLASS (sym) = LOC_ARG;
1517 /* FIXME: This has not been tested. */
1518 /* Add parameter to function. */
1519 add_param_to_type(&in_function_type,sym);
1521 add_symbol_to_list (sym, &local_symbols);
1522 #if !defined (BELIEVE_PCC_PROMOTION)
1523 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
1525 /* If PCC says a parameter is a short or a char,
1526 aligned on an int boundary, realign it to the
1527 "little end" of the int. */
1528 struct type *temptype;
1529 temptype = lookup_fundamental_type (current_objfile,
1531 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
1532 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
1533 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (temptype))
1535 SYMBOL_VALUE (sym) +=
1536 TYPE_LENGTH (temptype)
1537 - TYPE_LENGTH (SYMBOL_TYPE (sym));
1544 SYMBOL_CLASS (sym) = LOC_REGPARM;
1545 SYMBOL_VALUE (sym) = SDB_REG_TO_REGNUM(cs->c_value);
1546 add_symbol_to_list (sym, &local_symbols);
1547 #if !defined (BELIEVE_PCC_PROMOTION)
1548 /* FIXME: This should retain the current type, since it's just
1549 a register value. gnu@adobe, 26Feb93 */
1551 /* If PCC says a parameter is a short or a char,
1552 it is really an int. */
1553 struct type *temptype;
1555 lookup_fundamental_type (current_objfile, FT_INTEGER);
1556 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
1557 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
1560 (TYPE_UNSIGNED (SYMBOL_TYPE (sym))
1561 ? lookup_fundamental_type (current_objfile,
1562 FT_UNSIGNED_INTEGER)
1570 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1571 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1573 /* If type has no name, give it one */
1574 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
1576 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
1577 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
1579 /* If we are giving a name to a type such as "pointer to
1580 foo" or "function returning foo", we better not set
1581 the TYPE_NAME. If the program contains "typedef char
1582 *caddr_t;", we don't want all variables of type char
1583 * to print as caddr_t. This is not just a
1584 consequence of GDB's type management; CC and GCC (at
1585 least through version 2.4) both output variables of
1586 either type char * or caddr_t with the type
1587 refering to the C_TPDEF symbol for caddr_t. If a future
1588 compiler cleans this up it GDB is not ready for it
1589 yet, but if it becomes ready we somehow need to
1590 disable this check (without breaking the PCC/GCC2.4
1595 Fortunately, this check seems not to be necessary
1596 for anything except pointers or functions. */
1600 TYPE_NAME (SYMBOL_TYPE (sym)) =
1601 concat (SYMBOL_NAME (sym), NULL);
1604 /* Ignore vendor section for Harris CX/UX targets. */
1605 else if (cs->c_name[0] == '$')
1607 #endif /* CXUX_TARGET */
1609 /* Keep track of any type which points to empty structured type,
1610 so it can be filled from a definition from another file. A
1611 simple forward reference (TYPE_CODE_UNDEF) is not an
1612 empty structured type, though; the forward references
1613 work themselves out via the magic of coff_lookup_type. */
1614 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR &&
1615 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym))) == 0 &&
1616 TYPE_CODE (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym))) !=
1619 register int i = hashname (SYMBOL_NAME (sym));
1621 SYMBOL_VALUE_CHAIN (sym) = opaque_type_chain[i];
1622 opaque_type_chain[i] = sym;
1624 add_symbol_to_list (sym, &file_symbols);
1630 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1631 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1633 /* Some compilers try to be helpful by inventing "fake"
1634 names for anonymous enums, structures, and unions, like
1635 "~0fake" or ".0fake". Thanks, but no thanks... */
1636 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
1637 if (SYMBOL_NAME(sym) != NULL
1638 && *SYMBOL_NAME(sym) != '~'
1639 && *SYMBOL_NAME(sym) != '.')
1640 TYPE_TAG_NAME (SYMBOL_TYPE (sym)) =
1641 concat (SYMBOL_NAME (sym), NULL);
1643 add_symbol_to_list (sym, &file_symbols);
1653 /* Decode a coff type specifier; return the type that is meant. */
1655 static struct type *
1656 decode_type (cs, c_type, aux)
1657 register struct coff_symbol *cs;
1658 unsigned int c_type;
1659 register union internal_auxent *aux;
1661 register struct type *type = 0;
1662 unsigned int new_c_type;
1664 if (c_type & ~N_BTMASK)
1666 new_c_type = DECREF (c_type);
1669 type = decode_type (cs, new_c_type, aux);
1670 type = lookup_pointer_type (type);
1672 else if (ISFCN (c_type))
1674 type = decode_type (cs, new_c_type, aux);
1675 type = lookup_function_type (type);
1677 else if (ISARY (c_type))
1680 register unsigned short *dim;
1681 struct type *base_type, *index_type, *range_type;
1683 /* Define an array type. */
1684 /* auxent refers to array, not base type */
1685 if (aux->x_sym.x_tagndx.l == 0)
1688 /* shift the indices down */
1689 dim = &aux->x_sym.x_fcnary.x_ary.x_dimen[0];
1692 for (i = 0; *dim && i < DIMNUM - 1; i++, dim++)
1696 base_type = decode_type (cs, new_c_type, aux);
1697 index_type = lookup_fundamental_type (current_objfile, FT_INTEGER);
1699 create_range_type ((struct type *) NULL, index_type, 0, n - 1);
1701 create_array_type ((struct type *) NULL, base_type, range_type);
1706 /* Reference to existing type. This only occurs with the
1707 struct, union, and enum types. EPI a29k coff
1708 fakes us out by producing aux entries with a nonzero
1709 x_tagndx for definitions of structs, unions, and enums, so we
1710 have to check the c_sclass field. SCO 3.2v4 cc gets confused
1711 with pointers to pointers to defined structs, and generates
1712 negative x_tagndx fields. */
1713 if (cs->c_naux > 0 && aux->x_sym.x_tagndx.l != 0)
1715 if (cs->c_sclass != C_STRTAG
1716 && cs->c_sclass != C_UNTAG
1717 && cs->c_sclass != C_ENTAG
1718 && aux->x_sym.x_tagndx.l >= 0)
1720 type = coff_alloc_type (aux->x_sym.x_tagndx.l);
1725 complain (&tagndx_bad_complaint, cs->c_name);
1726 /* And fall through to decode_base_type... */
1730 return decode_base_type (cs, BTYPE (c_type), aux);
1733 /* Decode a coff type specifier for function definition;
1734 return the type that the function returns. */
1736 static struct type *
1737 decode_function_type (cs, c_type, aux)
1738 register struct coff_symbol *cs;
1739 unsigned int c_type;
1740 register union internal_auxent *aux;
1742 if (aux->x_sym.x_tagndx.l == 0)
1743 cs->c_naux = 0; /* auxent refers to function, not base type */
1745 return decode_type (cs, DECREF (c_type), aux);
1750 static struct type *
1751 decode_base_type (cs, c_type, aux)
1752 register struct coff_symbol *cs;
1753 unsigned int c_type;
1754 register union internal_auxent *aux;
1761 /* shows up with "void (*foo)();" structure members */
1762 return lookup_fundamental_type (current_objfile, FT_VOID);
1765 /* DGUX actually defines both T_ARG and T_VOID to the same value. */
1768 /* Shows up in DGUX, I think. Not sure where. */
1769 return lookup_fundamental_type (current_objfile, FT_VOID); /* shouldn't show up here */
1775 /* Intel 960 COFF has this symbol and meaning. */
1776 return lookup_fundamental_type (current_objfile, FT_VOID);
1780 return lookup_fundamental_type (current_objfile, FT_CHAR);
1783 return lookup_fundamental_type (current_objfile, FT_SHORT);
1786 return lookup_fundamental_type (current_objfile, FT_INTEGER);
1789 return lookup_fundamental_type (current_objfile, FT_LONG);
1792 return lookup_fundamental_type (current_objfile, FT_FLOAT);
1795 return lookup_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT);
1798 if (cs->c_naux != 1)
1800 /* anonymous structure type */
1801 type = coff_alloc_type (cs->c_symnum);
1802 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1803 TYPE_NAME (type) = NULL;
1804 /* This used to set the tag to "<opaque>". But I think setting it
1805 to NULL is right, and the printing code can print it as
1807 TYPE_TAG_NAME (type) = NULL;
1808 INIT_CPLUS_SPECIFIC(type);
1809 TYPE_LENGTH (type) = 0;
1810 TYPE_FIELDS (type) = 0;
1811 TYPE_NFIELDS (type) = 0;
1815 type = coff_read_struct_type (cs->c_symnum,
1816 aux->x_sym.x_misc.x_lnsz.x_size,
1817 aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
1822 if (cs->c_naux != 1)
1824 /* anonymous union type */
1825 type = coff_alloc_type (cs->c_symnum);
1826 TYPE_NAME (type) = NULL;
1827 /* This used to set the tag to "<opaque>". But I think setting it
1828 to NULL is right, and the printing code can print it as
1830 TYPE_TAG_NAME (type) = NULL;
1831 INIT_CPLUS_SPECIFIC(type);
1832 TYPE_LENGTH (type) = 0;
1833 TYPE_FIELDS (type) = 0;
1834 TYPE_NFIELDS (type) = 0;
1838 type = coff_read_struct_type (cs->c_symnum,
1839 aux->x_sym.x_misc.x_lnsz.x_size,
1840 aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
1842 TYPE_CODE (type) = TYPE_CODE_UNION;
1846 if (cs->c_naux != 1)
1848 /* anonymous enum type */
1849 type = coff_alloc_type (cs->c_symnum);
1850 TYPE_CODE (type) = TYPE_CODE_ENUM;
1851 TYPE_NAME (type) = NULL;
1852 /* This used to set the tag to "<opaque>". But I think setting it
1853 to NULL is right, and the printing code can print it as
1855 TYPE_TAG_NAME (type) = NULL;
1856 TYPE_LENGTH (type) = 0;
1857 TYPE_FIELDS (type) = 0;
1858 TYPE_NFIELDS(type) = 0;
1862 type = coff_read_enum_type (cs->c_symnum,
1863 aux->x_sym.x_misc.x_lnsz.x_size,
1864 aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
1869 /* shouldn't show up here */
1873 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_CHAR);
1876 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_SHORT);
1879 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER);
1882 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_LONG);
1884 complain (&unexpected_type_complaint, cs->c_name);
1885 return lookup_fundamental_type (current_objfile, FT_VOID);
1888 /* This page contains subroutines of read_type. */
1890 /* Read the description of a structure (or union type) and return an
1891 object describing the type. */
1893 static struct type *
1894 coff_read_struct_type (index, length, lastsym)
1901 struct nextfield *next;
1905 register struct type *type;
1906 register struct nextfield *list = 0;
1907 struct nextfield *new;
1911 struct coff_symbol member_sym;
1912 register struct coff_symbol *ms = &member_sym;
1913 struct internal_syment sub_sym;
1914 union internal_auxent sub_aux;
1917 type = coff_alloc_type (index);
1918 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1919 INIT_CPLUS_SPECIFIC(type);
1920 TYPE_LENGTH (type) = length;
1922 while (!done && symnum < lastsym && symnum < nlist_nsyms_global)
1924 read_one_sym (ms, &sub_sym, &sub_aux);
1926 name = EXTERNAL_NAME (name, current_objfile->obfd);
1928 switch (ms->c_sclass)
1933 /* Get space to record the next field's data. */
1934 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1938 /* Save the data. */
1942 ¤t_objfile->symbol_obstack);
1943 list->field.type = decode_type (ms, ms->c_type, &sub_aux);
1944 list->field.bitpos = 8 * ms->c_value;
1945 list->field.bitsize = 0;
1951 /* Get space to record the next field's data. */
1952 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1956 /* Save the data. */
1960 ¤t_objfile->symbol_obstack);
1961 list->field.type = decode_type (ms, ms->c_type, &sub_aux);
1962 list->field.bitpos = ms->c_value;
1963 list->field.bitsize = sub_aux.x_sym.x_misc.x_lnsz.x_size;
1972 /* Now create the vector of fields, and record how big it is. */
1974 TYPE_NFIELDS (type) = nfields;
1975 TYPE_FIELDS (type) = (struct field *)
1976 TYPE_ALLOC (type, sizeof (struct field) * nfields);
1978 /* Copy the saved-up fields into the field vector. */
1980 for (n = nfields; list; list = list->next)
1981 TYPE_FIELD (type, --n) = list->field;
1986 /* Read a definition of an enumeration type,
1987 and create and return a suitable type object.
1988 Also defines the symbols that represent the values of the type. */
1991 static struct type *
1992 coff_read_enum_type (index, length, lastsym)
1997 register struct symbol *sym;
1998 register struct type *type;
2001 struct pending **symlist;
2002 struct coff_symbol member_sym;
2003 register struct coff_symbol *ms = &member_sym;
2004 struct internal_syment sub_sym;
2005 union internal_auxent sub_aux;
2006 struct pending *osyms, *syms;
2011 type = coff_alloc_type (index);
2012 if (within_function)
2013 symlist = &local_symbols;
2015 symlist = &file_symbols;
2017 o_nsyms = osyms ? osyms->nsyms : 0;
2019 while (!done && symnum < lastsym && symnum < nlist_nsyms_global)
2021 read_one_sym (ms, &sub_sym, &sub_aux);
2023 name = EXTERNAL_NAME (name, current_objfile->obfd);
2025 switch (ms->c_sclass)
2028 sym = (struct symbol *) obstack_alloc
2029 (¤t_objfile->symbol_obstack,
2030 sizeof (struct symbol));
2031 memset (sym, 0, sizeof (struct symbol));
2034 obsavestring (name, strlen (name),
2035 ¤t_objfile->symbol_obstack);
2036 SYMBOL_CLASS (sym) = LOC_CONST;
2037 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2038 SYMBOL_VALUE (sym) = ms->c_value;
2039 add_symbol_to_list (sym, symlist);
2044 /* Sometimes the linker (on 386/ix 2.0.2 at least) screws
2045 up the count of how many symbols to read. So stop
2052 /* Now fill in the fields of the type-structure. */
2055 TYPE_LENGTH (type) = length;
2057 TYPE_LENGTH (type) = TARGET_INT_BIT / TARGET_CHAR_BIT; /* Assume ints */
2058 TYPE_CODE (type) = TYPE_CODE_ENUM;
2059 TYPE_NFIELDS (type) = nsyms;
2060 TYPE_FIELDS (type) = (struct field *)
2061 TYPE_ALLOC (type, sizeof (struct field) * nsyms);
2063 /* Find the symbols for the values and put them into the type.
2064 The symbols can be found in the symlist that we put them on
2065 to cause them to be defined. osyms contains the old value
2066 of that symlist; everything up to there was defined by us. */
2067 /* Note that we preserve the order of the enum constants, so
2068 that in something like "enum {FOO, LAST_THING=FOO}" we print
2069 FOO, not LAST_THING. */
2071 for (syms = *symlist, n = 0; syms; syms = syms->next)
2077 for (; j < syms->nsyms; j++,n++)
2079 struct symbol *xsym = syms->symbol[j];
2080 SYMBOL_TYPE (xsym) = type;
2081 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
2082 TYPE_FIELD_VALUE (type, n) = 0;
2083 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
2084 TYPE_FIELD_BITSIZE (type, n) = 0;
2093 struct section_offsets *
2094 coff_symfile_offsets (objfile, addr)
2095 struct objfile *objfile;
2098 struct section_offsets *section_offsets;
2101 objfile->num_sections = SECT_OFF_MAX;
2102 section_offsets = (struct section_offsets *)
2103 obstack_alloc (&objfile -> psymbol_obstack,
2104 sizeof (struct section_offsets)
2105 + sizeof (section_offsets->offsets) * (SECT_OFF_MAX-1));
2107 for (i = 0; i < SECT_OFF_MAX; i++)
2108 ANOFFSET (section_offsets, i) = addr;
2110 return section_offsets;
2113 /* Register our ability to parse symbols for coff BFD files. */
2115 static struct sym_fns coff_sym_fns =
2117 bfd_target_coff_flavour,
2118 coff_new_init, /* sym_new_init: init anything gbl to entire symtab */
2119 coff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
2120 coff_symfile_read, /* sym_read: read a symbol file into symtab */
2121 coff_symfile_finish, /* sym_finish: finished with file, cleanup */
2122 coff_symfile_offsets, /* sym_offsets: xlate external to internal form */
2123 NULL /* next: pointer to next struct sym_fns */
2127 _initialize_coffread ()
2129 add_symtab_fns (&coff_sym_fns);