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"
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 bf_no_aux_complaint =
143 {"`.bf' symbol %d has no aux entry", 0, 0};
145 struct complaint ef_no_aux_complaint =
146 {"`.ef' symbol %d has no aux entry", 0, 0};
148 struct complaint lineno_complaint =
149 {"Line number pointer %d lower than start of line numbers", 0, 0};
151 struct complaint unexpected_type_complaint =
152 {"Unexpected type for symbol %s", 0, 0};
154 struct complaint bad_sclass_complaint =
155 {"Bad n_sclass for symbol %s", 0, 0};
157 struct complaint misordered_blocks_complaint =
158 {"Blocks out of order at address %x", 0, 0};
160 struct complaint tagndx_bad_complaint =
161 {"Symbol table entry for %s has bad tagndx value", 0, 0};
163 struct complaint eb_complaint =
164 {"Mismatched .eb symbol ignored starting at symnum %d", 0, 0};
166 /* Simplified internal version of coff symbol table information */
170 int c_symnum; /* symbol number of this entry */
171 int c_naux; /* 0 if syment only, 1 if syment + auxent, etc */
178 static struct type *coff_read_struct_type PARAMS ((int, int, int));
180 static struct type *decode_base_type PARAMS ((struct coff_symbol *,
182 union internal_auxent *));
184 static struct type *decode_type PARAMS ((struct coff_symbol *, unsigned int,
185 union internal_auxent *));
187 static struct type *decode_function_type PARAMS ((struct coff_symbol *,
189 union internal_auxent *));
191 static struct type *coff_read_enum_type PARAMS ((int, int, int));
193 static struct symbol *process_coff_symbol PARAMS ((struct coff_symbol *,
194 union internal_auxent *,
195 struct section_offsets *,
198 static void patch_opaque_types PARAMS ((struct symtab *));
200 static void patch_type PARAMS ((struct type *, struct type *));
202 static void enter_linenos PARAMS ((long, int, int, struct section_offsets *));
204 static void free_linetab PARAMS ((void));
206 static int init_lineno PARAMS ((bfd *, long, int));
208 static char *getsymname PARAMS ((struct internal_syment *));
210 static char *coff_getfilename PARAMS ((union internal_auxent *));
212 static void free_stringtab PARAMS ((void));
214 static int init_stringtab PARAMS ((bfd *, long));
216 static void read_one_sym PARAMS ((struct coff_symbol *,
217 struct internal_syment *,
218 union internal_auxent *));
220 static void coff_symtab_read PARAMS ((long, int, struct section_offsets *,
223 static void find_linenos PARAMS ((bfd *, sec_ptr, PTR));
225 static void coff_symfile_init PARAMS ((struct objfile *));
227 static void coff_new_init PARAMS ((struct objfile *));
229 static void coff_symfile_read PARAMS ((struct objfile *,
230 struct section_offsets *, int));
232 static void coff_symfile_finish PARAMS ((struct objfile *));
234 static void record_minimal_symbol PARAMS ((char *, CORE_ADDR,
235 enum minimal_symbol_type,
238 static void coff_end_symtab PARAMS ((struct objfile *));
240 static void complete_symtab PARAMS ((char *, CORE_ADDR, unsigned int));
242 static void coff_start_symtab PARAMS ((void));
244 static void coff_record_line PARAMS ((int, CORE_ADDR));
246 static struct type *coff_alloc_type PARAMS ((int));
248 static struct type **coff_lookup_type PARAMS ((int));
250 static void coff_locate_sections PARAMS ((bfd *, asection *, PTR));
252 /* We are called once per section from coff_symfile_read. We
253 need to examine each section we are passed, check to see
254 if it is something we are interested in processing, and
255 if so, stash away some access information for the section.
257 FIXME: The section names should not be hardwired strings (what
258 should they be? I don't think most object file formats have enough
259 section flags to specify what kind of debug section it is
263 coff_locate_sections (abfd, sectp, csip)
268 register struct coff_symfile_info *csi;
271 csi = (struct coff_symfile_info *) csip;
272 name = bfd_get_section_name (abfd, sectp);
273 if (STREQ (name, ".text"))
275 csi->textaddr = bfd_section_vma (abfd, sectp);
276 csi->textsize += bfd_section_size (abfd, sectp);
278 else if (strncmp (name, ".text", sizeof ".text" - 1) == 0)
280 csi->textsize += bfd_section_size (abfd, sectp);
282 else if (STREQ (name, ".stabstr"))
284 csi->stabstrsect = sectp;
286 else if (strncmp (name, ".stab", sizeof ".stab" - 1) == 0)
290 /* We can have multiple .stab sections if linked with
292 for (s = name + sizeof ".stab" - 1; *s != '\0'; s++)
297 struct stab_section_list *n, **pn;
299 n = ((struct stab_section_list *)
300 xmalloc (sizeof (struct stab_section_list)));
303 for (pn = &csi->stabsects; *pn != NULL; pn = &(*pn)->next)
307 /* This will be run after coffstab_build_psymtabs is called
308 in coff_symfile_read, at which point we no longer need
310 make_cleanup (free, n);
315 /* Return the section_offsets* that CS points to. */
316 static int cs_to_section PARAMS ((struct coff_symbol *, struct objfile *));
318 struct find_targ_sec_arg {
323 static void find_targ_sec PARAMS ((bfd *, asection *, void *));
325 static void find_targ_sec (abfd, sect, obj)
330 struct find_targ_sec_arg *args = (struct find_targ_sec_arg *)obj;
331 if (sect->target_index == args->targ_index)
333 /* This is the section. Figure out what SECT_OFF_* code it is. */
334 if (bfd_get_section_flags (abfd, sect) & SEC_CODE)
335 *args->resultp = SECT_OFF_TEXT;
336 else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)
337 *args->resultp = SECT_OFF_DATA;
339 *args->resultp = SECT_OFF_BSS;
343 /* Return the section number (SECT_OFF_*) that CS points to. */
345 cs_to_section (cs, objfile)
346 struct coff_symbol *cs;
347 struct objfile *objfile;
349 int off = SECT_OFF_TEXT;
350 struct find_targ_sec_arg args;
351 args.targ_index = cs->c_secnum;
353 bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
357 /* Look up a coff type-number index. Return the address of the slot
358 where the type for that index is stored.
359 The type-number is in INDEX.
361 This can be used for finding the type associated with that index
362 or for associating a new type with the index. */
364 static struct type **
365 coff_lookup_type (index)
368 if (index >= type_vector_length)
370 int old_vector_length = type_vector_length;
372 type_vector_length *= 2;
373 if (index /* is still */ >= type_vector_length)
374 type_vector_length = index * 2;
376 type_vector = (struct type **)
377 xrealloc ((char *) type_vector,
378 type_vector_length * sizeof (struct type *));
379 memset (&type_vector[old_vector_length], 0,
380 (type_vector_length - old_vector_length) * sizeof(struct type *));
382 return &type_vector[index];
385 /* Make sure there is a type allocated for type number index
386 and return the type object.
387 This can create an empty (zeroed) type object. */
390 coff_alloc_type (index)
393 register struct type **type_addr = coff_lookup_type (index);
394 register struct type *type = *type_addr;
396 /* If we are referring to a type not known at all yet,
397 allocate an empty type for it.
398 We will fill it in later if we find out how. */
401 type = alloc_type (current_objfile);
407 /* Record a line number entry for line LINE at address PC.
408 FIXME: Use record_line instead. */
411 coff_record_line (line, pc)
415 struct linetable_entry *e;
416 /* Make sure line vector is big enough. */
418 if (line_vector_index + 2 >= line_vector_length)
420 line_vector_length *= 2;
421 line_vector = (struct linetable *)
422 xrealloc ((char *) line_vector, sizeof (struct linetable)
423 + (line_vector_length
424 * sizeof (struct linetable_entry)));
427 e = line_vector->item + line_vector_index++;
428 e->line = line; e->pc = pc;
431 /* Start a new symtab for a new source file.
432 This is called when a COFF ".file" symbol is seen;
433 it indicates the start of data for one original source file. */
439 /* We fill in the filename later. start_symtab puts
440 this pointer into last_source_file and we put it in
441 subfiles->name, which end_symtab frees; that's why
442 it must be malloc'd. */
444 /* We never know the directory name for COFF. */
446 /* The start address is irrelevant, since we set
447 last_source_start_addr in coff_end_symtab. */
450 /* Initialize the source file line number information for this file. */
452 if (line_vector) /* Unlikely, but maybe possible? */
453 free ((PTR)line_vector);
454 line_vector_index = 0;
455 line_vector_length = 1000;
456 prev_line_number = -2; /* Force first line number to be explicit */
457 line_vector = (struct linetable *)
458 xmalloc (sizeof (struct linetable)
459 + line_vector_length * sizeof (struct linetable_entry));
462 /* Save the vital information from when starting to read a file,
463 for use when closing off the current file.
464 NAME is the file name the symbols came from, START_ADDR is the first
465 text address for the file, and SIZE is the number of bytes of text. */
468 complete_symtab (name, start_addr, size)
470 CORE_ADDR start_addr;
473 if (last_source_file != NULL)
474 free (last_source_file);
475 last_source_file = savestring (name, strlen (name));
476 current_source_start_addr = start_addr;
477 current_source_end_addr = start_addr + size;
479 if (current_objfile -> ei.entry_point >= current_source_start_addr &&
480 current_objfile -> ei.entry_point < current_source_end_addr)
482 current_objfile -> ei.entry_file_lowpc = current_source_start_addr;
483 current_objfile -> ei.entry_file_highpc = current_source_end_addr;
487 /* Finish the symbol definitions for one main source file,
488 close off all the lexical contexts for that file
489 (creating struct block's for them), then make the
490 struct symtab for that file and put it in the list of all such. */
493 coff_end_symtab (objfile)
494 struct objfile *objfile;
496 struct symtab *symtab;
498 last_source_start_addr = current_source_start_addr;
500 /* For no good reason, this file stores the number of entries in a
501 separate variable instead of in line_vector->nitems. Fix it. */
503 line_vector->nitems = line_vector_index;
505 /* For COFF, we only have one subfile, so we can just look at
506 subfiles and not worry about there being other elements in the
507 chain. We fill in various fields now because we didn't know them
508 before (or because doing it now is simply an artifact of how this
509 file used to be written). */
510 subfiles->line_vector = line_vector;
511 subfiles->name = last_source_file;
513 /* sort_pending is needed for amdcoff, at least.
514 sort_linevec is needed for the SCO compiler. */
515 symtab = end_symtab (current_source_end_addr, 1, 1, objfile, 0);
518 free_named_symtabs (symtab->filename);
520 /* Reinitialize for beginning of new file. */
522 line_vector_length = -1;
523 last_source_file = NULL;
527 record_minimal_symbol (name, address, type, objfile)
530 enum minimal_symbol_type type;
531 struct objfile *objfile;
533 /* We don't want TDESC entry points in the minimal symbol table */
534 if (name[0] == '@') return;
536 prim_record_minimal_symbol
537 (obsavestring (name, strlen (name), &objfile->symbol_obstack),
542 /* coff_symfile_init ()
543 is the coff-specific initialization routine for reading symbols.
544 It is passed a struct objfile which contains, among other things,
545 the BFD for the file whose symbols are being read, and a slot for
546 a pointer to "private data" which we fill with cookies and other
547 treats for coff_symfile_read ().
549 We will only be called if this is a COFF or COFF-like file.
550 BFD handles figuring out the format of the file, and code in symtab.c
551 uses BFD's determination to vector to us.
553 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
556 coff_symfile_init (objfile)
557 struct objfile *objfile;
559 /* Allocate struct to keep track of stab reading. */
560 objfile->sym_stab_info = (PTR)
561 xmmalloc (objfile->md, sizeof (struct dbx_symfile_info));
563 memset ((PTR) objfile->sym_stab_info, 0, sizeof (struct dbx_symfile_info));
565 /* Allocate struct to keep track of the symfile */
566 objfile->sym_private = xmmalloc (objfile->md,
567 sizeof (struct coff_symfile_info));
569 memset (objfile->sym_private, 0, sizeof (struct coff_symfile_info));
571 init_entry_point_info (objfile);
574 /* This function is called for every section; it finds the outer limits
575 of the line table (minimum and maximum file offset) so that the
576 mainline code can read the whole thing for efficiency. */
580 find_linenos (abfd, asect, vpinfo)
585 struct coff_symfile_info *info;
587 file_ptr offset, maxoff;
589 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
590 count = asect->lineno_count;
595 size = count * local_linesz;
597 info = (struct coff_symfile_info *)vpinfo;
598 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
599 offset = asect->line_filepos;
602 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
603 info->min_lineno_offset = offset;
605 maxoff = offset + size;
606 if (maxoff > info->max_lineno_offset)
607 info->max_lineno_offset = maxoff;
611 /* The BFD for this file -- only good while we're actively reading
612 symbols into a psymtab or a symtab. */
614 static bfd *symfile_bfd;
616 /* Read a symbol file, after initialization by coff_symfile_init. */
620 coff_symfile_read (objfile, section_offsets, mainline)
621 struct objfile *objfile;
622 struct section_offsets *section_offsets;
625 struct coff_symfile_info *info;
626 struct dbx_symfile_info *dbxinfo;
627 bfd *abfd = objfile->obfd;
628 coff_data_type *cdata = coff_data (abfd);
629 char *name = bfd_get_filename (abfd);
633 int stringtab_offset;
634 struct cleanup *back_to;
637 info = (struct coff_symfile_info *) objfile -> sym_private;
638 dbxinfo = (struct dbx_symfile_info *) objfile->sym_stab_info;
639 symfile_bfd = abfd; /* Kludge for swap routines */
641 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
642 num_symbols = bfd_get_symcount (abfd); /* How many syms */
643 symtab_offset = cdata->sym_filepos; /* Symbol table file offset */
644 stringtab_offset = symtab_offset + /* String table file offset */
645 num_symbols * cdata->local_symesz;
647 /* Set a few file-statics that give us specific information about
648 the particular COFF file format we're reading. */
649 local_linesz = cdata->local_linesz;
650 local_n_btmask = cdata->local_n_btmask;
651 local_n_btshft = cdata->local_n_btshft;
652 local_n_tmask = cdata->local_n_tmask;
653 local_n_tshift = cdata->local_n_tshift;
654 local_linesz = cdata->local_linesz;
655 local_symesz = cdata->local_symesz;
656 local_auxesz = cdata->local_auxesz;
658 /* Allocate space for raw symbol and aux entries, based on their
659 space requirements as reported by BFD. */
660 temp_sym = (char *) xmalloc
661 (cdata->local_symesz + cdata->local_auxesz);
662 temp_aux = temp_sym + cdata->local_symesz;
663 back_to = make_cleanup (free_current_contents, &temp_sym);
666 /* Read the line number table, all at once. */
667 info->min_lineno_offset = 0;
668 info->max_lineno_offset = 0;
669 bfd_map_over_sections (abfd, find_linenos, (PTR) info);
671 make_cleanup (free_linetab, 0);
672 val = init_lineno (abfd, info->min_lineno_offset,
673 info->max_lineno_offset - info->min_lineno_offset);
675 error ("\"%s\": error reading line numbers\n", name);
677 /* Now read the string table, all at once. */
679 make_cleanup (free_stringtab, 0);
680 val = init_stringtab (abfd, stringtab_offset);
682 error ("\"%s\": can't get string table", name);
684 init_minimal_symbol_collection ();
685 make_cleanup (discard_minimal_symbols, 0);
687 /* Now that the executable file is positioned at symbol table,
688 process it and define symbols accordingly. */
690 coff_symtab_read ((long) symtab_offset, num_symbols, section_offsets,
693 /* Sort symbols alphabetically within each block. */
698 for (s = objfile -> symtabs; s != NULL; s = s -> next)
699 sort_symtab_syms (s);
702 /* Install any minimal symbols that have been collected as the current
703 minimal symbols for this objfile. */
705 install_minimal_symbols (objfile);
707 bfd_map_over_sections (abfd, coff_locate_sections, (PTR) info);
711 /* FIXME: dubious. Why can't we use something normal like
712 bfd_get_section_contents? */
713 bfd_seek (abfd, abfd->where, 0);
715 stabstrsize = bfd_section_size (abfd, info->stabstrsect);
717 coffstab_build_psymtabs (objfile,
720 info->textaddr, info->textsize,
722 info->stabstrsect->filepos, stabstrsize);
725 do_cleanups (back_to);
729 coff_new_init (ignore)
730 struct objfile *ignore;
734 /* Perform any local cleanups required when we are done with a particular
735 objfile. I.E, we are in the process of discarding all symbol information
736 for an objfile, freeing up all memory held for it, and unlinking the
737 objfile struct from the global list of known objfiles. */
740 coff_symfile_finish (objfile)
741 struct objfile *objfile;
743 if (objfile -> sym_private != NULL)
745 mfree (objfile -> md, objfile -> sym_private);
750 /* Given pointers to a symbol table in coff style exec file,
751 analyze them and create struct symtab's describing the symbols.
752 NSYMS is the number of symbols in the symbol table.
753 We read them one at a time using read_one_sym (). */
756 coff_symtab_read (symtab_offset, nsyms, section_offsets, objfile)
759 struct section_offsets *section_offsets;
760 struct objfile *objfile;
762 register struct context_stack *new;
763 struct coff_symbol coff_symbol;
764 register struct coff_symbol *cs = &coff_symbol;
765 static struct internal_syment main_sym;
766 static union internal_auxent main_aux;
767 struct coff_symbol fcn_cs_saved;
768 static struct internal_syment fcn_sym_saved;
769 static union internal_auxent fcn_aux_saved;
771 /* A .file is open. */
772 int in_source_file = 0;
773 int next_file_symnum = -1;
774 /* Name of the current file. */
775 char *filestring = "";
777 int fcn_first_line = 0;
778 int fcn_last_line = 0;
779 int fcn_start_addr = 0;
780 long fcn_line_ptr = 0;
784 /* Work around a stdio bug in SunOS4.1.1 (this makes me nervous....
785 it's hard to know I've really worked around it. The fix should be
786 harmless, anyway). The symptom of the bug is that the first
787 fread (in read_one_sym), will (in my example) actually get data
788 from file offset 268, when the fseek was to 264 (and ftell shows
789 264). This causes all hell to break loose. I was unable to
790 reproduce this on a short test program which operated on the same
791 file, performing (I think) the same sequence of operations.
793 It stopped happening when I put in this (former) rewind().
795 FIXME: Find out if this has been reported to Sun, whether it has
796 been fixed in a later release, etc. */
798 bfd_seek (objfile->obfd, 0, 0);
800 /* Position to read the symbol table. */
801 val = bfd_seek (objfile->obfd, (long) symtab_offset, 0);
803 perror_with_name (objfile->name);
805 current_objfile = objfile;
806 nlist_bfd_global = objfile->obfd;
807 nlist_nsyms_global = nsyms;
808 last_source_file = NULL;
809 memset (opaque_type_chain, 0, sizeof opaque_type_chain);
811 if (type_vector) /* Get rid of previous one */
812 free ((PTR) type_vector);
813 type_vector_length = 160;
814 type_vector = (struct type **)
815 xmalloc (type_vector_length * sizeof (struct type *));
816 memset (type_vector, 0, type_vector_length * sizeof (struct type *));
818 coff_start_symtab ();
821 while (symnum < nsyms)
823 QUIT; /* Make this command interruptable. */
825 read_one_sym (cs, &main_sym, &main_aux);
828 temp_sem_val = cs->c_name[0] << 24 | cs->c_name[1] << 16 |
829 cs->c_name[2] << 8 | cs->c_name[3];
830 if (int_sem_val == temp_sem_val)
831 last_coffsem = (int) strtol (cs->c_name+4, (char **) NULL, 10);
834 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
836 if (last_source_file)
837 coff_end_symtab (objfile);
839 coff_start_symtab ();
840 complete_symtab ("_globals_", 0, 0);
841 /* done with all files, everything from here on out is globals */
844 /* Special case for file with type declarations only, no text. */
845 if (!last_source_file && SDB_TYPE (cs->c_type)
846 && cs->c_secnum == N_DEBUG)
847 complete_symtab (filestring, 0, 0);
849 /* Typedefs should not be treated as symbol definitions. */
850 if (ISFCN (cs->c_type) && cs->c_sclass != C_TPDEF)
852 /* Record all functions -- external and static -- in minsyms. */
853 tmpaddr = cs->c_value + ANOFFSET (section_offsets, SECT_OFF_TEXT);
854 record_minimal_symbol (cs->c_name, tmpaddr, mst_text, objfile);
856 fcn_line_ptr = main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
857 fcn_start_addr = tmpaddr;
859 fcn_sym_saved = main_sym;
860 fcn_aux_saved = main_aux;
864 switch (cs->c_sclass)
873 complain (&bad_sclass_complaint, cs->c_name);
877 /* c_value field contains symnum of next .file entry in table
878 or symnum of first global after last .file. */
879 next_file_symnum = cs->c_value;
881 filestring = coff_getfilename (&main_aux);
885 /* Complete symbol table for last object file
886 containing debugging information. */
887 if (last_source_file)
889 coff_end_symtab (objfile);
890 coff_start_symtab ();
896 if (cs->c_name[0] == '.')
898 if (STREQ (cs->c_name, ".text")) {
899 /* FIXME: don't wire in ".text" as section name
901 /* Check for in_source_file deals with case of
902 a file with debugging symbols
903 followed by a later file with no symbols. */
905 complete_symtab (filestring,
906 cs->c_value + ANOFFSET (section_offsets, SECT_OFF_TEXT),
907 main_aux.x_scn.x_scnlen);
910 /* flush rest of '.' symbols */
913 else if (!SDB_TYPE (cs->c_type)
914 && cs->c_name[0] == 'L'
915 && (strncmp (cs->c_name, "LI%", 3) == 0
916 || strncmp (cs->c_name, "LF%", 3) == 0
917 || strncmp (cs->c_name,"LC%",3) == 0
918 || strncmp (cs->c_name,"LP%",3) == 0
919 || strncmp (cs->c_name,"LPB%",4) == 0
920 || strncmp (cs->c_name,"LBB%",4) == 0
921 || strncmp (cs->c_name,"LBE%",4) == 0
922 || strncmp (cs->c_name,"LPBX%",5) == 0))
923 /* At least on a 3b1, gcc generates swbeg and string labels
924 that look like this. Ignore them. */
926 /* fall in for static symbols that don't start with '.' */
929 /* Record it in the minimal symbols regardless of
930 SDB_TYPE. This parallels what we do for other debug
931 formats, and probably is needed to make
932 print_address_symbolic work right without the (now
933 gone) "set fast-symbolic-addr off" kludge. */
935 /* FIXME: should use mst_abs, and not relocate, if absolute. */
936 enum minimal_symbol_type ms_type;
939 if (cs->c_secnum == N_UNDEF)
941 /* This is a common symbol. See if the target
942 environment knows where it has been relocated to. */
944 if (target_lookup_symbol (cs->c_name, &reladdr))
946 /* Error in lookup; ignore symbol. */
950 /* The address has already been relocated; make sure that
951 objfile_relocate doesn't relocate it again. */
953 ms_type = cs->c_sclass == C_STAT ? mst_file_bss : mst_bss;
957 sec = cs_to_section (cs, objfile);
958 tmpaddr = cs->c_value;
959 if (cs->c_sclass != C_STAT)
960 tmpaddr += ANOFFSET (section_offsets, sec);
965 case SECT_OFF_RODATA:
967 cs->c_sclass == C_STAT ? mst_file_text : mst_text;
971 cs->c_sclass == C_STAT ? mst_file_data : mst_data;
975 cs->c_sclass == C_STAT ? mst_file_bss : mst_bss;
978 ms_type = mst_unknown;
983 if (cs->c_name[0] != '@' /* Skip tdesc symbols */)
984 prim_record_minimal_symbol_and_info
985 (obsavestring (cs->c_name, strlen (cs->c_name),
986 &objfile->symbol_obstack),
993 if (SDB_TYPE (cs->c_type))
996 sym = process_coff_symbol
997 (cs, &main_aux, section_offsets, objfile);
998 SYMBOL_VALUE (sym) = tmpaddr;
999 SYMBOL_SECTION (sym) = sec;
1005 if (STREQ (cs->c_name, ".bf"))
1007 within_function = 1;
1009 /* value contains address of first non-init type code */
1010 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
1011 contains line number of '{' } */
1012 if (cs->c_naux != 1)
1013 complain (&bf_no_aux_complaint, cs->c_symnum);
1014 fcn_first_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
1016 /* Might want to check that locals are 0 and
1017 context_stack_depth is zero, and complain if not. */
1020 new = push_context (depth, fcn_start_addr);
1021 fcn_cs_saved.c_name = getsymname (&fcn_sym_saved);
1023 process_coff_symbol (&fcn_cs_saved, &fcn_aux_saved,
1024 section_offsets, objfile);
1026 else if (STREQ (cs->c_name, ".ef"))
1028 /* the value of .ef is the address of epilogue code;
1029 not useful for gdb. */
1030 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1031 contains number of lines to '}' */
1032 new = pop_context ();
1033 /* Stack must be empty now. */
1034 if (context_stack_depth > 0 || new == NULL)
1036 complain (&ef_complaint, cs->c_symnum);
1037 within_function = 0;
1040 if (cs->c_naux != 1)
1042 complain (&ef_no_aux_complaint, cs->c_symnum);
1043 fcn_last_line = 0x7FFFFFFF;
1047 fcn_last_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
1049 enter_linenos (fcn_line_ptr, fcn_first_line, fcn_last_line,
1052 finish_block (new->name, &local_symbols, new->old_blocks,
1054 #if defined (FUNCTION_EPILOGUE_SIZE)
1055 /* This macro should be defined only on
1057 fcn_aux_saved.x_sym.x_misc.x_fsize
1058 field is always zero.
1059 So use the .bf record information that
1060 points to the epilogue and add the size
1063 + FUNCTION_EPILOGUE_SIZE
1064 + ANOFFSET (section_offsets, SECT_OFF_TEXT),
1066 fcn_cs_saved.c_value
1067 + fcn_aux_saved.x_sym.x_misc.x_fsize
1068 + ANOFFSET (section_offsets, SECT_OFF_TEXT),
1072 within_function = 0;
1077 if (STREQ (cs->c_name, ".bb"))
1079 tmpaddr = cs->c_value;
1080 tmpaddr += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1081 push_context (++depth, tmpaddr);
1083 else if (STREQ (cs->c_name, ".eb"))
1085 new = pop_context ();
1086 if (depth-- != new->depth)
1088 complain (&eb_complaint, symnum);
1091 if (local_symbols && context_stack_depth > 0)
1094 cs->c_value + ANOFFSET (section_offsets, SECT_OFF_TEXT);
1095 /* Make a block for the local symbols within. */
1096 finish_block (0, &local_symbols, new->old_blocks,
1097 new->start_addr, tmpaddr, objfile);
1099 /* Now pop locals of block just finished. */
1100 local_symbols = new->locals;
1105 process_coff_symbol (cs, &main_aux, section_offsets, objfile);
1110 if (last_source_file)
1111 coff_end_symtab (objfile);
1113 /* Patch up any opaque types (references to types that are not defined
1114 in the file where they are referenced, e.g. "struct foo *bar"). */
1115 ALL_OBJFILE_SYMTABS (objfile, s)
1116 patch_opaque_types (s);
1118 current_objfile = NULL;
1121 /* Routines for reading headers and symbols from executable. */
1123 /* Read the next symbol, swap it, and return it in both internal_syment
1124 form, and coff_symbol form. Also return its first auxent, if any,
1125 in internal_auxent form, and skip any other auxents. */
1128 read_one_sym (cs, sym, aux)
1129 register struct coff_symbol *cs;
1130 register struct internal_syment *sym;
1131 register union internal_auxent *aux;
1135 cs->c_symnum = symnum;
1136 bfd_read (temp_sym, local_symesz, 1, nlist_bfd_global);
1137 bfd_coff_swap_sym_in (symfile_bfd, temp_sym, (char *)sym);
1138 cs->c_naux = sym->n_numaux & 0xff;
1139 if (cs->c_naux >= 1)
1141 bfd_read (temp_aux, local_auxesz, 1, nlist_bfd_global);
1142 bfd_coff_swap_aux_in (symfile_bfd, temp_aux, sym->n_type, sym->n_sclass,
1143 0, cs->c_naux, (char *)aux);
1144 /* If more than one aux entry, read past it (only the first aux
1146 for (i = 1; i < cs->c_naux; i++)
1147 bfd_read (temp_aux, local_auxesz, 1, nlist_bfd_global);
1149 cs->c_name = getsymname (sym);
1150 cs->c_value = sym->n_value;
1151 cs->c_sclass = (sym->n_sclass & 0xff);
1152 cs->c_secnum = sym->n_scnum;
1153 cs->c_type = (unsigned) sym->n_type;
1154 if (!SDB_TYPE (cs->c_type))
1157 symnum += 1 + cs->c_naux;
1160 /* Support for string table handling */
1162 static char *stringtab = NULL;
1165 init_stringtab (abfd, offset)
1171 unsigned char lengthbuf[4];
1175 /* If the file is stripped, the offset might be zero, indicating no
1176 string table. Just return with `stringtab' set to null. */
1180 if (bfd_seek (abfd, offset, 0) < 0)
1183 val = bfd_read ((char *)lengthbuf, sizeof lengthbuf, 1, abfd);
1184 length = bfd_h_get_32 (symfile_bfd, lengthbuf);
1186 /* If no string table is needed, then the file may end immediately
1187 after the symbols. Just return with `stringtab' set to null. */
1188 if (val != sizeof lengthbuf || length < sizeof lengthbuf)
1191 stringtab = (char *) xmalloc (length);
1192 /* This is in target format (probably not very useful, and not currently
1193 used), not host format. */
1194 memcpy (stringtab, lengthbuf, sizeof lengthbuf);
1195 if (length == sizeof length) /* Empty table -- just the count */
1198 val = bfd_read (stringtab + sizeof lengthbuf, length - sizeof lengthbuf, 1, abfd);
1199 if (val != length - sizeof lengthbuf || stringtab[length - 1] != '\0')
1214 getsymname (symbol_entry)
1215 struct internal_syment *symbol_entry;
1217 static char buffer[SYMNMLEN+1];
1220 if (symbol_entry->_n._n_n._n_zeroes == 0)
1222 /* FIXME: Probably should be detecting corrupt symbol files by
1223 seeing whether offset points to within the stringtab. */
1224 result = stringtab + symbol_entry->_n._n_n._n_offset;
1228 strncpy (buffer, symbol_entry->_n._n_name, SYMNMLEN);
1229 buffer[SYMNMLEN] = '\0';
1235 /* Extract the file name from the aux entry of a C_FILE symbol. Return
1236 only the last component of the name. Result is in static storage and
1237 is only good for temporary use. */
1240 coff_getfilename (aux_entry)
1241 union internal_auxent *aux_entry;
1243 static char buffer[BUFSIZ];
1244 register char *temp;
1247 if (aux_entry->x_file.x_n.x_zeroes == 0)
1248 strcpy (buffer, stringtab + aux_entry->x_file.x_n.x_offset);
1251 strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
1252 buffer[FILNMLEN] = '\0';
1256 /* FIXME: We should not be throwing away the information about what
1257 directory. It should go into dirname of the symtab, or some such
1259 if ((temp = strrchr (result, '/')) != NULL)
1264 /* Support for line number handling. */
1266 static char *linetab = NULL;
1267 static long linetab_offset;
1268 static unsigned long linetab_size;
1270 /* Read in all the line numbers for fast lookups later. Leave them in
1271 external (unswapped) format in memory; we'll swap them as we enter
1272 them into GDB's data structures. */
1275 init_lineno (abfd, offset, size)
1282 linetab_offset = offset;
1283 linetab_size = size;
1290 if (bfd_seek (abfd, offset, 0) < 0)
1293 /* Allocate the desired table, plus a sentinel */
1294 linetab = (char *) xmalloc (size + local_linesz);
1296 val = bfd_read (linetab, size, 1, abfd);
1300 /* Terminate it with an all-zero sentinel record */
1301 memset (linetab + size, 0, local_linesz);
1314 #if !defined (L_LNNO32)
1315 #define L_LNNO32(lp) ((lp)->l_lnno)
1319 enter_linenos (file_offset, first_line, last_line, section_offsets)
1321 register int first_line;
1322 register int last_line;
1323 struct section_offsets *section_offsets;
1325 register char *rawptr;
1326 struct internal_lineno lptr;
1330 if (file_offset < linetab_offset)
1332 complain (&lineno_complaint, file_offset);
1333 if (file_offset > linetab_size) /* Too big to be an offset? */
1335 file_offset += linetab_offset; /* Try reading at that linetab offset */
1338 rawptr = &linetab[file_offset - linetab_offset];
1340 /* skip first line entry for each function */
1341 rawptr += local_linesz;
1342 /* line numbers start at one for the first line of the function */
1346 bfd_coff_swap_lineno_in (symfile_bfd, rawptr, &lptr);
1347 rawptr += local_linesz;
1348 /* The next function, or the sentinel, will have L_LNNO32 zero; we exit. */
1349 if (L_LNNO32 (&lptr) && L_LNNO32 (&lptr) <= last_line)
1350 coff_record_line (first_line + L_LNNO32 (&lptr),
1352 + ANOFFSET (section_offsets, SECT_OFF_TEXT));
1359 patch_type (type, real_type)
1361 struct type *real_type;
1363 register struct type *target = TYPE_TARGET_TYPE (type);
1364 register struct type *real_target = TYPE_TARGET_TYPE (real_type);
1365 int field_size = TYPE_NFIELDS (real_target) * sizeof (struct field);
1367 TYPE_LENGTH (target) = TYPE_LENGTH (real_target);
1368 TYPE_NFIELDS (target) = TYPE_NFIELDS (real_target);
1369 TYPE_FIELDS (target) = (struct field *) TYPE_ALLOC (target, field_size);
1371 memcpy (TYPE_FIELDS (target), TYPE_FIELDS (real_target), field_size);
1373 if (TYPE_NAME (real_target))
1375 if (TYPE_NAME (target))
1376 free (TYPE_NAME (target));
1377 TYPE_NAME (target) = concat (TYPE_NAME (real_target), NULL);
1381 /* Patch up all appropriate typedef symbols in the opaque_type_chains
1382 so that they can be used to print out opaque data structures properly. */
1385 patch_opaque_types (s)
1388 register struct block *b;
1390 register struct symbol *real_sym;
1392 /* Go through the per-file symbols only */
1393 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
1394 for (i = BLOCK_NSYMS (b) - 1; i >= 0; i--)
1396 /* Find completed typedefs to use to fix opaque ones.
1397 Remove syms from the chain when their types are stored,
1398 but search the whole chain, as there may be several syms
1399 from different files with the same name. */
1400 real_sym = BLOCK_SYM (b, i);
1401 if (SYMBOL_CLASS (real_sym) == LOC_TYPEDEF &&
1402 SYMBOL_NAMESPACE (real_sym) == VAR_NAMESPACE &&
1403 TYPE_CODE (SYMBOL_TYPE (real_sym)) == TYPE_CODE_PTR &&
1404 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym))) != 0)
1406 register char *name = SYMBOL_NAME (real_sym);
1407 register int hash = hashname (name);
1408 register struct symbol *sym, *prev;
1411 for (sym = opaque_type_chain[hash]; sym;)
1413 if (name[0] == SYMBOL_NAME (sym)[0] &&
1414 STREQ (name + 1, SYMBOL_NAME (sym) + 1))
1418 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
1422 opaque_type_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
1425 patch_type (SYMBOL_TYPE (sym), SYMBOL_TYPE (real_sym));
1429 sym = SYMBOL_VALUE_CHAIN (prev);
1433 sym = opaque_type_chain[hash];
1439 sym = SYMBOL_VALUE_CHAIN (sym);
1446 static struct symbol *
1447 process_coff_symbol (cs, aux, section_offsets, objfile)
1448 register struct coff_symbol *cs;
1449 register union internal_auxent *aux;
1450 struct section_offsets *section_offsets;
1451 struct objfile *objfile;
1453 register struct symbol *sym
1454 = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1455 sizeof (struct symbol));
1458 memset (sym, 0, sizeof (struct symbol));
1460 name = EXTERNAL_NAME (name, objfile->obfd);
1461 SYMBOL_NAME (sym) = obstack_copy0 (&objfile->symbol_obstack, name,
1464 /* default assumptions */
1465 SYMBOL_VALUE (sym) = cs->c_value;
1466 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1467 SYMBOL_SECTION (sym) = cs_to_section (cs, objfile);
1469 if (ISFCN (cs->c_type))
1471 SYMBOL_VALUE (sym) += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1473 lookup_function_type (decode_function_type (cs, cs->c_type, aux));
1475 SYMBOL_CLASS (sym) = LOC_BLOCK;
1476 if (cs->c_sclass == C_STAT)
1477 add_symbol_to_list (sym, &file_symbols);
1478 else if (cs->c_sclass == C_EXT)
1479 add_symbol_to_list (sym, &global_symbols);
1483 SYMBOL_TYPE (sym) = decode_type (cs, cs->c_type, aux);
1484 switch (cs->c_sclass)
1490 SYMBOL_CLASS (sym) = LOC_LOCAL;
1491 add_symbol_to_list (sym, &local_symbols);
1495 SYMBOL_CLASS (sym) = LOC_STATIC;
1496 SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
1497 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1498 add_symbol_to_list (sym, &global_symbols);
1502 SYMBOL_CLASS (sym) = LOC_STATIC;
1503 SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
1504 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (section_offsets, SECT_OFF_TEXT);
1505 if (within_function) {
1506 /* Static symbol of local scope */
1507 add_symbol_to_list (sym, &local_symbols);
1510 /* Static symbol at top level of file */
1511 add_symbol_to_list (sym, &file_symbols);
1515 #ifdef C_GLBLREG /* AMD coff */
1519 SYMBOL_CLASS (sym) = LOC_REGISTER;
1520 SYMBOL_VALUE (sym) = SDB_REG_TO_REGNUM(cs->c_value);
1521 add_symbol_to_list (sym, &local_symbols);
1528 SYMBOL_CLASS (sym) = LOC_ARG;
1529 add_symbol_to_list (sym, &local_symbols);
1530 #if !defined (BELIEVE_PCC_PROMOTION)
1531 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
1533 /* If PCC says a parameter is a short or a char,
1534 aligned on an int boundary, realign it to the
1535 "little end" of the int. */
1536 struct type *temptype;
1537 temptype = lookup_fundamental_type (current_objfile,
1539 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
1540 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
1541 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (temptype))
1543 SYMBOL_VALUE (sym) +=
1544 TYPE_LENGTH (temptype)
1545 - TYPE_LENGTH (SYMBOL_TYPE (sym));
1552 SYMBOL_CLASS (sym) = LOC_REGPARM;
1553 SYMBOL_VALUE (sym) = SDB_REG_TO_REGNUM(cs->c_value);
1554 add_symbol_to_list (sym, &local_symbols);
1555 #if !defined (BELIEVE_PCC_PROMOTION)
1556 /* FIXME: This should retain the current type, since it's just
1557 a register value. gnu@adobe, 26Feb93 */
1559 /* If PCC says a parameter is a short or a char,
1560 it is really an int. */
1561 struct type *temptype;
1563 lookup_fundamental_type (current_objfile, FT_INTEGER);
1564 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
1565 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
1568 (TYPE_UNSIGNED (SYMBOL_TYPE (sym))
1569 ? lookup_fundamental_type (current_objfile,
1570 FT_UNSIGNED_INTEGER)
1578 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1579 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1581 /* If type has no name, give it one */
1582 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
1584 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
1585 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
1587 /* If we are giving a name to a type such as "pointer to
1588 foo" or "function returning foo", we better not set
1589 the TYPE_NAME. If the program contains "typedef char
1590 *caddr_t;", we don't want all variables of type char
1591 * to print as caddr_t. This is not just a
1592 consequence of GDB's type management; CC and GCC (at
1593 least through version 2.4) both output variables of
1594 either type char * or caddr_t with the type
1595 refering to the C_TPDEF symbol for caddr_t. If a future
1596 compiler cleans this up it GDB is not ready for it
1597 yet, but if it becomes ready we somehow need to
1598 disable this check (without breaking the PCC/GCC2.4
1603 Fortunately, this check seems not to be necessary
1604 for anything except pointers or functions. */
1608 TYPE_NAME (SYMBOL_TYPE (sym)) =
1609 concat (SYMBOL_NAME (sym), NULL);
1612 /* Ignore vendor section for Harris CX/UX targets. */
1613 else if (cs->c_name[0] == '$')
1615 #endif /* CXUX_TARGET */
1617 /* Keep track of any type which points to empty structured type,
1618 so it can be filled from a definition from another file. A
1619 simple forward reference (TYPE_CODE_UNDEF) is not an
1620 empty structured type, though; the forward references
1621 work themselves out via the magic of coff_lookup_type. */
1622 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR &&
1623 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym))) == 0 &&
1624 TYPE_CODE (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym))) !=
1627 register int i = hashname (SYMBOL_NAME (sym));
1629 SYMBOL_VALUE_CHAIN (sym) = opaque_type_chain[i];
1630 opaque_type_chain[i] = sym;
1632 add_symbol_to_list (sym, &file_symbols);
1638 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1639 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1641 /* Some compilers try to be helpful by inventing "fake"
1642 names for anonymous enums, structures, and unions, like
1643 "~0fake" or ".0fake". Thanks, but no thanks... */
1644 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
1645 if (SYMBOL_NAME(sym) != NULL
1646 && *SYMBOL_NAME(sym) != '~'
1647 && *SYMBOL_NAME(sym) != '.')
1648 TYPE_TAG_NAME (SYMBOL_TYPE (sym)) =
1649 concat (SYMBOL_NAME (sym), NULL);
1651 add_symbol_to_list (sym, &file_symbols);
1661 /* Decode a coff type specifier; return the type that is meant. */
1663 static struct type *
1664 decode_type (cs, c_type, aux)
1665 register struct coff_symbol *cs;
1666 unsigned int c_type;
1667 register union internal_auxent *aux;
1669 register struct type *type = 0;
1670 unsigned int new_c_type;
1672 if (c_type & ~N_BTMASK)
1674 new_c_type = DECREF (c_type);
1677 type = decode_type (cs, new_c_type, aux);
1678 type = lookup_pointer_type (type);
1680 else if (ISFCN (c_type))
1682 type = decode_type (cs, new_c_type, aux);
1683 type = lookup_function_type (type);
1685 else if (ISARY (c_type))
1688 register unsigned short *dim;
1689 struct type *base_type, *index_type, *range_type;
1691 /* Define an array type. */
1692 /* auxent refers to array, not base type */
1693 if (aux->x_sym.x_tagndx.l == 0)
1696 /* shift the indices down */
1697 dim = &aux->x_sym.x_fcnary.x_ary.x_dimen[0];
1700 for (i = 0; *dim && i < DIMNUM - 1; i++, dim++)
1704 base_type = decode_type (cs, new_c_type, aux);
1705 index_type = lookup_fundamental_type (current_objfile, FT_INTEGER);
1707 create_range_type ((struct type *) NULL, index_type, 0, n - 1);
1709 create_array_type ((struct type *) NULL, base_type, range_type);
1714 /* Reference to existing type. This only occurs with the
1715 struct, union, and enum types. EPI a29k coff
1716 fakes us out by producing aux entries with a nonzero
1717 x_tagndx for definitions of structs, unions, and enums, so we
1718 have to check the c_sclass field. SCO 3.2v4 cc gets confused
1719 with pointers to pointers to defined structs, and generates
1720 negative x_tagndx fields. */
1721 if (cs->c_naux > 0 && aux->x_sym.x_tagndx.l != 0)
1723 if (cs->c_sclass != C_STRTAG
1724 && cs->c_sclass != C_UNTAG
1725 && cs->c_sclass != C_ENTAG
1726 && aux->x_sym.x_tagndx.l >= 0)
1728 type = coff_alloc_type (aux->x_sym.x_tagndx.l);
1733 complain (&tagndx_bad_complaint, cs->c_name);
1734 /* And fall through to decode_base_type... */
1738 return decode_base_type (cs, BTYPE (c_type), aux);
1741 /* Decode a coff type specifier for function definition;
1742 return the type that the function returns. */
1744 static struct type *
1745 decode_function_type (cs, c_type, aux)
1746 register struct coff_symbol *cs;
1747 unsigned int c_type;
1748 register union internal_auxent *aux;
1750 if (aux->x_sym.x_tagndx.l == 0)
1751 cs->c_naux = 0; /* auxent refers to function, not base type */
1753 return decode_type (cs, DECREF (c_type), aux);
1758 static struct type *
1759 decode_base_type (cs, c_type, aux)
1760 register struct coff_symbol *cs;
1761 unsigned int c_type;
1762 register union internal_auxent *aux;
1769 /* shows up with "void (*foo)();" structure members */
1770 return lookup_fundamental_type (current_objfile, FT_VOID);
1773 /* DGUX actually defines both T_ARG and T_VOID to the same value. */
1776 /* Shows up in DGUX, I think. Not sure where. */
1777 return lookup_fundamental_type (current_objfile, FT_VOID); /* shouldn't show up here */
1783 /* Intel 960 COFF has this symbol and meaning. */
1784 return lookup_fundamental_type (current_objfile, FT_VOID);
1788 return lookup_fundamental_type (current_objfile, FT_CHAR);
1791 return lookup_fundamental_type (current_objfile, FT_SHORT);
1794 return lookup_fundamental_type (current_objfile, FT_INTEGER);
1797 return lookup_fundamental_type (current_objfile, FT_LONG);
1800 return lookup_fundamental_type (current_objfile, FT_FLOAT);
1803 return lookup_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT);
1806 if (cs->c_naux != 1)
1808 /* anonymous structure type */
1809 type = coff_alloc_type (cs->c_symnum);
1810 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1811 TYPE_NAME (type) = NULL;
1812 /* This used to set the tag to "<opaque>". But I think setting it
1813 to NULL is right, and the printing code can print it as
1815 TYPE_TAG_NAME (type) = NULL;
1816 INIT_CPLUS_SPECIFIC(type);
1817 TYPE_LENGTH (type) = 0;
1818 TYPE_FIELDS (type) = 0;
1819 TYPE_NFIELDS (type) = 0;
1823 type = coff_read_struct_type (cs->c_symnum,
1824 aux->x_sym.x_misc.x_lnsz.x_size,
1825 aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
1830 if (cs->c_naux != 1)
1832 /* anonymous union type */
1833 type = coff_alloc_type (cs->c_symnum);
1834 TYPE_NAME (type) = NULL;
1835 /* This used to set the tag to "<opaque>". But I think setting it
1836 to NULL is right, and the printing code can print it as
1838 TYPE_TAG_NAME (type) = NULL;
1839 INIT_CPLUS_SPECIFIC(type);
1840 TYPE_LENGTH (type) = 0;
1841 TYPE_FIELDS (type) = 0;
1842 TYPE_NFIELDS (type) = 0;
1846 type = coff_read_struct_type (cs->c_symnum,
1847 aux->x_sym.x_misc.x_lnsz.x_size,
1848 aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
1850 TYPE_CODE (type) = TYPE_CODE_UNION;
1854 if (cs->c_naux != 1)
1856 /* anonymous enum type */
1857 type = coff_alloc_type (cs->c_symnum);
1858 TYPE_CODE (type) = TYPE_CODE_ENUM;
1859 TYPE_NAME (type) = NULL;
1860 /* This used to set the tag to "<opaque>". But I think setting it
1861 to NULL is right, and the printing code can print it as
1863 TYPE_TAG_NAME (type) = NULL;
1864 TYPE_LENGTH (type) = 0;
1865 TYPE_FIELDS (type) = 0;
1866 TYPE_NFIELDS(type) = 0;
1870 type = coff_read_enum_type (cs->c_symnum,
1871 aux->x_sym.x_misc.x_lnsz.x_size,
1872 aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
1877 /* shouldn't show up here */
1881 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_CHAR);
1884 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_SHORT);
1887 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER);
1890 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_LONG);
1892 complain (&unexpected_type_complaint, cs->c_name);
1893 return lookup_fundamental_type (current_objfile, FT_VOID);
1896 /* This page contains subroutines of read_type. */
1898 /* Read the description of a structure (or union type) and return an
1899 object describing the type. */
1901 static struct type *
1902 coff_read_struct_type (index, length, lastsym)
1909 struct nextfield *next;
1913 register struct type *type;
1914 register struct nextfield *list = 0;
1915 struct nextfield *new;
1919 struct coff_symbol member_sym;
1920 register struct coff_symbol *ms = &member_sym;
1921 struct internal_syment sub_sym;
1922 union internal_auxent sub_aux;
1925 type = coff_alloc_type (index);
1926 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1927 INIT_CPLUS_SPECIFIC(type);
1928 TYPE_LENGTH (type) = length;
1930 while (!done && symnum < lastsym && symnum < nlist_nsyms_global)
1932 read_one_sym (ms, &sub_sym, &sub_aux);
1934 name = EXTERNAL_NAME (name, current_objfile->obfd);
1936 switch (ms->c_sclass)
1941 /* Get space to record the next field's data. */
1942 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1946 /* Save the data. */
1950 ¤t_objfile->symbol_obstack);
1951 list->field.type = decode_type (ms, ms->c_type, &sub_aux);
1952 list->field.bitpos = 8 * ms->c_value;
1953 list->field.bitsize = 0;
1959 /* Get space to record the next field's data. */
1960 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1964 /* Save the data. */
1968 ¤t_objfile->symbol_obstack);
1969 list->field.type = decode_type (ms, ms->c_type, &sub_aux);
1970 list->field.bitpos = ms->c_value;
1971 list->field.bitsize = sub_aux.x_sym.x_misc.x_lnsz.x_size;
1980 /* Now create the vector of fields, and record how big it is. */
1982 TYPE_NFIELDS (type) = nfields;
1983 TYPE_FIELDS (type) = (struct field *)
1984 TYPE_ALLOC (type, sizeof (struct field) * nfields);
1986 /* Copy the saved-up fields into the field vector. */
1988 for (n = nfields; list; list = list->next)
1989 TYPE_FIELD (type, --n) = list->field;
1994 /* Read a definition of an enumeration type,
1995 and create and return a suitable type object.
1996 Also defines the symbols that represent the values of the type. */
1999 static struct type *
2000 coff_read_enum_type (index, length, lastsym)
2005 register struct symbol *sym;
2006 register struct type *type;
2009 struct pending **symlist;
2010 struct coff_symbol member_sym;
2011 register struct coff_symbol *ms = &member_sym;
2012 struct internal_syment sub_sym;
2013 union internal_auxent sub_aux;
2014 struct pending *osyms, *syms;
2019 type = coff_alloc_type (index);
2020 if (within_function)
2021 symlist = &local_symbols;
2023 symlist = &file_symbols;
2025 o_nsyms = osyms ? osyms->nsyms : 0;
2027 while (!done && symnum < lastsym && symnum < nlist_nsyms_global)
2029 read_one_sym (ms, &sub_sym, &sub_aux);
2031 name = EXTERNAL_NAME (name, current_objfile->obfd);
2033 switch (ms->c_sclass)
2036 sym = (struct symbol *) obstack_alloc
2037 (¤t_objfile->symbol_obstack,
2038 sizeof (struct symbol));
2039 memset (sym, 0, sizeof (struct symbol));
2042 obsavestring (name, strlen (name),
2043 ¤t_objfile->symbol_obstack);
2044 SYMBOL_CLASS (sym) = LOC_CONST;
2045 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2046 SYMBOL_VALUE (sym) = ms->c_value;
2047 add_symbol_to_list (sym, symlist);
2052 /* Sometimes the linker (on 386/ix 2.0.2 at least) screws
2053 up the count of how many symbols to read. So stop
2060 /* Now fill in the fields of the type-structure. */
2063 TYPE_LENGTH (type) = length;
2065 TYPE_LENGTH (type) = TARGET_INT_BIT / TARGET_CHAR_BIT; /* Assume ints */
2066 TYPE_CODE (type) = TYPE_CODE_ENUM;
2067 TYPE_NFIELDS (type) = nsyms;
2068 TYPE_FIELDS (type) = (struct field *)
2069 TYPE_ALLOC (type, sizeof (struct field) * nsyms);
2071 /* Find the symbols for the values and put them into the type.
2072 The symbols can be found in the symlist that we put them on
2073 to cause them to be defined. osyms contains the old value
2074 of that symlist; everything up to there was defined by us. */
2075 /* Note that we preserve the order of the enum constants, so
2076 that in something like "enum {FOO, LAST_THING=FOO}" we print
2077 FOO, not LAST_THING. */
2079 for (syms = *symlist, n = 0; syms; syms = syms->next)
2085 for (; j < syms->nsyms; j++,n++)
2087 struct symbol *xsym = syms->symbol[j];
2088 SYMBOL_TYPE (xsym) = type;
2089 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
2090 TYPE_FIELD_VALUE (type, n) = 0;
2091 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
2092 TYPE_FIELD_BITSIZE (type, n) = 0;
2101 struct section_offsets *
2102 coff_symfile_offsets (objfile, addr)
2103 struct objfile *objfile;
2106 struct section_offsets *section_offsets;
2109 objfile->num_sections = SECT_OFF_MAX;
2110 section_offsets = (struct section_offsets *)
2111 obstack_alloc (&objfile -> psymbol_obstack,
2112 sizeof (struct section_offsets)
2113 + sizeof (section_offsets->offsets) * SECT_OFF_MAX);
2115 for (i = 0; i < SECT_OFF_MAX; i++)
2116 ANOFFSET (section_offsets, i) = addr;
2118 return section_offsets;
2121 /* Register our ability to parse symbols for coff BFD files. */
2123 static struct sym_fns coff_sym_fns =
2125 bfd_target_coff_flavour,
2126 coff_new_init, /* sym_new_init: init anything gbl to entire symtab */
2127 coff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
2128 coff_symfile_read, /* sym_read: read a symbol file into symtab */
2129 coff_symfile_finish, /* sym_finish: finished with file, cleanup */
2130 coff_symfile_offsets, /* sym_offsets: xlate external to internal form */
2131 NULL /* next: pointer to next struct sym_fns */
2135 _initialize_coffread ()
2137 add_symtab_fns (&coff_sym_fns);