1 /* Read coff symbol tables and convert to internal format, for GDB.
2 Copyright 1987, 88, 89, 90, 91, 92, 93, 94, 96, 97, 1998
3 Free Software Foundation, Inc.
4 Contributed by David D. Johnson, Brown University (ddj@cs.brown.edu).
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
27 #include "breakpoint.h"
32 #include "gdb_string.h"
35 #include "coff/internal.h" /* Internal format of COFF symbols in BFD */
36 #include "libcoff.h" /* FIXME secret internal data from BFD */
41 #include "gdb-stabs.h"
42 #include "stabsread.h"
43 #include "complaints.h"
46 extern void _initialize_coffread PARAMS ((void));
48 struct coff_symfile_info
50 file_ptr min_lineno_offset; /* Where in file lowest line#s are */
51 file_ptr max_lineno_offset; /* 1+last byte of line#s in file */
53 CORE_ADDR textaddr; /* Addr of .text section. */
54 unsigned int textsize; /* Size of .text section. */
55 struct stab_section_list *stabsects; /* .stab sections. */
56 asection *stabstrsect; /* Section pointer for .stab section */
60 /* Translate an external name string into a user-visible name. */
61 #define EXTERNAL_NAME(string, abfd) \
62 (string[0] == bfd_get_symbol_leading_char(abfd)? string+1: string)
64 /* To be an sdb debug type, type must have at least a basic or primary
65 derived type. Using this rather than checking against T_NULL is
66 said to prevent core dumps if we try to operate on Michael Bloom
69 #define SDB_TYPE(type) (BTYPE(type) | (type & N_TMASK))
71 /* Convert from an sdb register number to an internal gdb register number.
72 This should be defined in tm.h, if REGISTER_NAMES is not set up
73 to map one to one onto the sdb register numbers. */
75 #ifndef SDB_REG_TO_REGNUM
76 #define SDB_REG_TO_REGNUM(value) (value)
79 /* Core address of start and end of text of current source file.
80 This comes from a ".text" symbol where x_nlinno > 0. */
82 static CORE_ADDR current_source_start_addr;
83 static CORE_ADDR current_source_end_addr;
85 /* The addresses of the symbol table stream and number of symbols
86 of the object file we are reading (as copied into core). */
88 static bfd *nlist_bfd_global;
89 static int nlist_nsyms_global;
92 /* Pointers to scratch storage, used for reading raw symbols and auxents. */
94 static char *temp_sym;
95 static char *temp_aux;
97 /* Local variables that hold the shift and mask values for the
98 COFF file that we are currently reading. These come back to us
99 from BFD, and are referenced by their macro names, as well as
100 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
101 macros from include/coff/internal.h . */
103 static unsigned local_n_btmask;
104 static unsigned local_n_btshft;
105 static unsigned local_n_tmask;
106 static unsigned local_n_tshift;
108 #define N_BTMASK local_n_btmask
109 #define N_BTSHFT local_n_btshft
110 #define N_TMASK local_n_tmask
111 #define N_TSHIFT local_n_tshift
113 /* Local variables that hold the sizes in the file of various COFF structures.
114 (We only need to know this to read them from the file -- BFD will then
115 translate the data in them, into `internal_xxx' structs in the right
116 byte order, alignment, etc.) */
118 static unsigned local_linesz;
119 static unsigned local_symesz;
120 static unsigned local_auxesz;
122 /* This is set if this is a PE format file. */
126 /* Chain of typedefs of pointers to empty struct/union types.
127 They are chained thru the SYMBOL_VALUE_CHAIN. */
129 static struct symbol *opaque_type_chain[HASHSIZE];
131 /* Complaints about various problems in the file being read */
133 struct complaint ef_complaint =
134 {"Unmatched .ef symbol(s) ignored starting at symnum %d", 0, 0};
136 struct complaint ef_stack_complaint =
137 {"`.ef' symbol without matching `.bf' symbol ignored starting at symnum %d", 0, 0};
139 struct complaint eb_stack_complaint =
140 {"`.eb' symbol without matching `.bb' symbol 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 */
171 int c_symnum; /* symbol number of this entry */
172 int c_naux; /* 0 if syment only, 1 if syment + auxent, etc */
179 extern void stabsread_clear_cache PARAMS ((void));
181 static struct type *coff_read_struct_type PARAMS ((int, int, int));
183 static struct type *decode_base_type PARAMS ((struct coff_symbol *,
185 union internal_auxent *));
187 static struct type *decode_type PARAMS ((struct coff_symbol *, unsigned int,
188 union internal_auxent *));
190 static struct type *decode_function_type PARAMS ((struct coff_symbol *,
192 union internal_auxent *));
194 static struct type *coff_read_enum_type PARAMS ((int, int, int));
196 static struct symbol *process_coff_symbol PARAMS ((struct coff_symbol *,
197 union internal_auxent *,
200 static void patch_opaque_types PARAMS ((struct symtab *));
202 static void patch_type PARAMS ((struct type *, struct type *));
204 static void enter_linenos PARAMS ((long, int, int, struct objfile *));
206 static void free_linetab PARAMS ((void));
208 static int init_lineno PARAMS ((bfd *, long, int));
210 static char *getsymname PARAMS ((struct internal_syment *));
212 static char *coff_getfilename PARAMS ((union internal_auxent *));
214 static void free_stringtab PARAMS ((void));
216 static int init_stringtab PARAMS ((bfd *, long));
218 static void read_one_sym PARAMS ((struct coff_symbol *,
219 struct internal_syment *,
220 union internal_auxent *));
222 static void coff_symtab_read PARAMS ((long, int, struct objfile *));
224 static void find_linenos PARAMS ((bfd *, sec_ptr, PTR));
226 static void coff_symfile_init PARAMS ((struct objfile *));
228 static void coff_new_init PARAMS ((struct objfile *));
230 static void coff_symfile_read PARAMS ((struct objfile *, 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 ((char *));
244 static struct type *coff_alloc_type PARAMS ((int));
246 static struct type **coff_lookup_type PARAMS ((int));
248 static void coff_locate_sections PARAMS ((bfd *, asection *, PTR));
250 /* We are called once per section from coff_symfile_read. We
251 need to examine each section we are passed, check to see
252 if it is something we are interested in processing, and
253 if so, stash away some access information for the section.
255 FIXME: The section names should not be hardwired strings (what
256 should they be? I don't think most object file formats have enough
257 section flags to specify what kind of debug section it is
261 coff_locate_sections (abfd, sectp, csip)
266 register struct coff_symfile_info *csi;
269 csi = (struct coff_symfile_info *) csip;
270 name = bfd_get_section_name (abfd, sectp);
271 if (STREQ (name, ".text"))
273 csi->textaddr = bfd_section_vma (abfd, sectp);
274 csi->textsize += bfd_section_size (abfd, sectp);
276 else if (strncmp (name, ".text", sizeof ".text" - 1) == 0)
278 csi->textsize += bfd_section_size (abfd, sectp);
280 else if (STREQ (name, ".stabstr"))
282 csi->stabstrsect = sectp;
284 else if (strncmp (name, ".stab", sizeof ".stab" - 1) == 0)
288 /* We can have multiple .stab sections if linked with
290 for (s = name + sizeof ".stab" - 1; *s != '\0'; s++)
295 struct stab_section_list *n, **pn;
297 n = ((struct stab_section_list *)
298 xmalloc (sizeof (struct stab_section_list)));
301 for (pn = &csi->stabsects; *pn != NULL; pn = &(*pn)->next)
305 /* This will be run after coffstab_build_psymtabs is called
306 in coff_symfile_read, at which point we no longer need
308 make_cleanup (free, n);
313 /* Return the section_offsets* that CS points to. */
314 static int cs_to_section PARAMS ((struct coff_symbol *, struct objfile *));
316 struct find_targ_sec_arg
322 static void find_targ_sec PARAMS ((bfd *, asection *, void *));
325 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)
332 *args->resultp = sect;
335 /* Return the section number (SECT_OFF_*) that CS points to. */
337 cs_to_section (cs, objfile)
338 struct coff_symbol *cs;
339 struct objfile *objfile;
341 asection *sect = NULL;
342 struct find_targ_sec_arg args;
343 int off = SECT_OFF_TEXT;
345 args.targ_index = cs->c_secnum;
346 args.resultp = §
347 bfd_map_over_sections (objfile->obfd, find_targ_sec, &args);
350 /* This is the section. Figure out what SECT_OFF_* code it is. */
351 if (bfd_get_section_flags (abfd, sect) & SEC_CODE)
353 else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)
361 /* Return the address of the section of a COFF symbol. */
363 static CORE_ADDR cs_section_address PARAMS ((struct coff_symbol *, bfd *));
366 cs_section_address (cs, abfd)
367 struct coff_symbol *cs;
370 asection *sect = NULL;
371 struct find_targ_sec_arg args;
374 args.targ_index = cs->c_secnum;
375 args.resultp = §
376 bfd_map_over_sections (abfd, find_targ_sec, &args);
378 addr = bfd_get_section_vma (objfile->obfd, sect);
382 /* Look up a coff type-number index. Return the address of the slot
383 where the type for that index is stored.
384 The type-number is in INDEX.
386 This can be used for finding the type associated with that index
387 or for associating a new type with the index. */
389 static struct type **
390 coff_lookup_type (index)
393 if (index >= type_vector_length)
395 int old_vector_length = type_vector_length;
397 type_vector_length *= 2;
398 if (index /* is still */ >= type_vector_length)
399 type_vector_length = index * 2;
401 type_vector = (struct type **)
402 xrealloc ((char *) type_vector,
403 type_vector_length * sizeof (struct type *));
404 memset (&type_vector[old_vector_length], 0,
405 (type_vector_length - old_vector_length) * sizeof (struct type *));
407 return &type_vector[index];
410 /* Make sure there is a type allocated for type number index
411 and return the type object.
412 This can create an empty (zeroed) type object. */
415 coff_alloc_type (index)
418 register struct type **type_addr = coff_lookup_type (index);
419 register struct type *type = *type_addr;
421 /* If we are referring to a type not known at all yet,
422 allocate an empty type for it.
423 We will fill it in later if we find out how. */
426 type = alloc_type (current_objfile);
432 /* Start a new symtab for a new source file.
433 This is called when a COFF ".file" symbol is seen;
434 it indicates the start of data for one original source file. */
437 coff_start_symtab (name)
441 /* We fill in the filename later. start_symtab puts
442 this pointer into last_source_file and we put it in
443 subfiles->name, which end_symtab frees; that's why
444 it must be malloc'd. */
445 savestring (name, strlen (name)),
446 /* We never know the directory name for COFF. */
448 /* The start address is irrelevant, since we set
449 last_source_start_addr in coff_end_symtab. */
451 record_debugformat ("COFF");
454 /* Save the vital information from when starting to read a file,
455 for use when closing off the current file.
456 NAME is the file name the symbols came from, START_ADDR is the first
457 text address for the file, and SIZE is the number of bytes of text. */
460 complete_symtab (name, start_addr, size)
462 CORE_ADDR start_addr;
465 if (last_source_file != NULL)
466 free (last_source_file);
467 last_source_file = savestring (name, strlen (name));
468 current_source_start_addr = start_addr;
469 current_source_end_addr = start_addr + size;
471 if (current_objfile->ei.entry_point >= current_source_start_addr &&
472 current_objfile->ei.entry_point < current_source_end_addr)
474 current_objfile->ei.entry_file_lowpc = current_source_start_addr;
475 current_objfile->ei.entry_file_highpc = current_source_end_addr;
479 /* Finish the symbol definitions for one main source file,
480 close off all the lexical contexts for that file
481 (creating struct block's for them), then make the
482 struct symtab for that file and put it in the list of all such. */
485 coff_end_symtab (objfile)
486 struct objfile *objfile;
488 struct symtab *symtab;
490 last_source_start_addr = current_source_start_addr;
492 symtab = end_symtab (current_source_end_addr, objfile, 0);
495 free_named_symtabs (symtab->filename);
497 /* Reinitialize for beginning of new file. */
498 last_source_file = NULL;
502 record_minimal_symbol (name, address, type, objfile)
505 enum minimal_symbol_type type;
506 struct objfile *objfile;
508 /* We don't want TDESC entry points in the minimal symbol table */
512 prim_record_minimal_symbol (name, address, type, objfile);
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 /* Allocate struct to keep track of stab reading. */
533 objfile->sym_stab_info = (struct dbx_symfile_info *)
534 xmmalloc (objfile->md, sizeof (struct dbx_symfile_info));
536 memset ((PTR) objfile->sym_stab_info, 0, sizeof (struct dbx_symfile_info));
538 /* Allocate struct to keep track of the symfile */
539 objfile->sym_private = xmmalloc (objfile->md,
540 sizeof (struct coff_symfile_info));
542 memset (objfile->sym_private, 0, sizeof (struct coff_symfile_info));
544 /* COFF objects may be reordered, so set OBJF_REORDERED. If we
545 find this causes a significant slowdown in gdb then we could
546 set it in the debug symbol readers only when necessary. */
547 objfile->flags |= OBJF_REORDERED;
549 init_entry_point_info (objfile);
552 /* This function is called for every section; it finds the outer limits
553 of the line table (minimum and maximum file offset) so that the
554 mainline code can read the whole thing for efficiency. */
558 find_linenos (abfd, asect, vpinfo)
563 struct coff_symfile_info *info;
565 file_ptr offset, maxoff;
567 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
568 count = asect->lineno_count;
573 size = count * local_linesz;
575 info = (struct coff_symfile_info *) vpinfo;
576 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
577 offset = asect->line_filepos;
580 if (offset < info->min_lineno_offset || info->min_lineno_offset == 0)
581 info->min_lineno_offset = offset;
583 maxoff = offset + size;
584 if (maxoff > info->max_lineno_offset)
585 info->max_lineno_offset = maxoff;
589 /* The BFD for this file -- only good while we're actively reading
590 symbols into a psymtab or a symtab. */
592 static bfd *symfile_bfd;
594 /* Read a symbol file, after initialization by coff_symfile_init. */
598 coff_symfile_read (objfile, mainline)
599 struct objfile *objfile;
602 struct coff_symfile_info *info;
603 struct dbx_symfile_info *dbxinfo;
604 bfd *abfd = objfile->obfd;
605 coff_data_type *cdata = coff_data (abfd);
606 char *name = bfd_get_filename (abfd);
610 int stringtab_offset;
611 struct cleanup *back_to;
614 info = (struct coff_symfile_info *) objfile->sym_private;
615 dbxinfo = objfile->sym_stab_info;
616 symfile_bfd = abfd; /* Kludge for swap routines */
618 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
619 num_symbols = bfd_get_symcount (abfd); /* How many syms */
620 symtab_offset = cdata->sym_filepos; /* Symbol table file offset */
621 stringtab_offset = symtab_offset + /* String table file offset */
622 num_symbols * cdata->local_symesz;
624 /* Set a few file-statics that give us specific information about
625 the particular COFF file format we're reading. */
626 local_n_btmask = cdata->local_n_btmask;
627 local_n_btshft = cdata->local_n_btshft;
628 local_n_tmask = cdata->local_n_tmask;
629 local_n_tshift = cdata->local_n_tshift;
630 local_linesz = cdata->local_linesz;
631 local_symesz = cdata->local_symesz;
632 local_auxesz = cdata->local_auxesz;
634 /* Allocate space for raw symbol and aux entries, based on their
635 space requirements as reported by BFD. */
636 temp_sym = (char *) xmalloc
637 (cdata->local_symesz + cdata->local_auxesz);
638 temp_aux = temp_sym + cdata->local_symesz;
639 back_to = make_cleanup ((make_cleanup_func) free_current_contents, &temp_sym);
641 /* We need to know whether this is a PE file, because in PE files,
642 unlike standard COFF files, symbol values are stored as offsets
643 from the section address, rather than as absolute addresses.
644 FIXME: We should use BFD to read the symbol table, and thus avoid
646 pe_file = strncmp (bfd_get_target (objfile->obfd), "pe", 2) == 0;
650 /* Read the line number table, all at once. */
651 info->min_lineno_offset = 0;
652 info->max_lineno_offset = 0;
653 bfd_map_over_sections (abfd, find_linenos, (PTR) info);
655 make_cleanup ((make_cleanup_func) free_linetab, 0);
656 val = init_lineno (abfd, info->min_lineno_offset,
657 info->max_lineno_offset - info->min_lineno_offset);
659 error ("\"%s\": error reading line numbers\n", name);
661 /* Now read the string table, all at once. */
663 make_cleanup ((make_cleanup_func) free_stringtab, 0);
664 val = init_stringtab (abfd, stringtab_offset);
666 error ("\"%s\": can't get string table", name);
668 init_minimal_symbol_collection ();
669 make_cleanup ((make_cleanup_func) discard_minimal_symbols, 0);
671 /* Now that the executable file is positioned at symbol table,
672 process it and define symbols accordingly. */
674 coff_symtab_read ((long) symtab_offset, num_symbols, objfile);
676 /* Sort symbols alphabetically within each block. */
681 for (s = objfile->symtabs; s != NULL; s = s->next)
682 sort_symtab_syms (s);
685 /* Install any minimal symbols that have been collected as the current
686 minimal symbols for this objfile. */
688 install_minimal_symbols (objfile);
690 bfd_map_over_sections (abfd, coff_locate_sections, (PTR) info);
694 if (!info->stabstrsect)
699 ("The debugging information in `%s' is corrupted.\n"
700 "The file has a `.stabs' section, but no `.stabstr' section.\n"),
702 return_to_top_level (RETURN_ERROR);
705 /* FIXME: dubious. Why can't we use something normal like
706 bfd_get_section_contents? */
707 bfd_seek (abfd, abfd->where, 0);
709 stabstrsize = bfd_section_size (abfd, info->stabstrsect);
711 coffstab_build_psymtabs (objfile,
713 info->textaddr, info->textsize,
715 info->stabstrsect->filepos, stabstrsize);
718 do_cleanups (back_to);
722 coff_new_init (ignore)
723 struct objfile *ignore;
727 /* Perform any local cleanups required when we are done with a particular
728 objfile. I.E, we are in the process of discarding all symbol information
729 for an objfile, freeing up all memory held for it, and unlinking the
730 objfile struct from the global list of known objfiles. */
733 coff_symfile_finish (objfile)
734 struct objfile *objfile;
736 if (objfile->sym_private != NULL)
738 mfree (objfile->md, objfile->sym_private);
741 /* Let stabs reader clean up */
742 stabsread_clear_cache ();
746 /* Given pointers to a symbol table in coff style exec file,
747 analyze them and create struct symtab's describing the symbols.
748 NSYMS is the number of symbols in the symbol table.
749 We read them one at a time using read_one_sym (). */
752 coff_symtab_read (symtab_offset, nsyms, objfile)
755 struct objfile *objfile;
757 register struct context_stack *new;
758 struct coff_symbol coff_symbol;
759 register struct coff_symbol *cs = &coff_symbol;
760 static struct internal_syment main_sym;
761 static union internal_auxent main_aux;
762 struct coff_symbol fcn_cs_saved;
763 static struct internal_syment fcn_sym_saved;
764 static union internal_auxent fcn_aux_saved;
766 /* A .file is open. */
767 int in_source_file = 0;
768 int next_file_symnum = -1;
769 /* Name of the current file. */
770 char *filestring = "";
772 int fcn_first_line = 0;
773 CORE_ADDR fcn_first_line_addr;
774 int fcn_last_line = 0;
775 int fcn_start_addr = 0;
776 long fcn_line_ptr = 0;
780 /* Work around a stdio bug in SunOS4.1.1 (this makes me nervous....
781 it's hard to know I've really worked around it. The fix should be
782 harmless, anyway). The symptom of the bug is that the first
783 fread (in read_one_sym), will (in my example) actually get data
784 from file offset 268, when the fseek was to 264 (and ftell shows
785 264). This causes all hell to break loose. I was unable to
786 reproduce this on a short test program which operated on the same
787 file, performing (I think) the same sequence of operations.
789 It stopped happening when I put in this (former) rewind().
791 FIXME: Find out if this has been reported to Sun, whether it has
792 been fixed in a later release, etc. */
794 bfd_seek (objfile->obfd, 0, 0);
796 /* Position to read the symbol table. */
797 val = bfd_seek (objfile->obfd, (long) symtab_offset, 0);
799 perror_with_name (objfile->name);
801 current_objfile = objfile;
802 nlist_bfd_global = objfile->obfd;
803 nlist_nsyms_global = nsyms;
804 last_source_file = NULL;
805 memset (opaque_type_chain, 0, sizeof opaque_type_chain);
807 if (type_vector) /* Get rid of previous one */
808 free ((PTR) type_vector);
809 type_vector_length = 160;
810 type_vector = (struct type **)
811 xmalloc (type_vector_length * sizeof (struct type *));
812 memset (type_vector, 0, type_vector_length * sizeof (struct type *));
814 coff_start_symtab ("");
817 while (symnum < nsyms)
819 QUIT; /* Make this command interruptable. */
821 read_one_sym (cs, &main_sym, &main_aux);
823 if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
825 if (last_source_file)
826 coff_end_symtab (objfile);
828 coff_start_symtab ("_globals_");
829 complete_symtab ("_globals_", 0, 0);
830 /* done with all files, everything from here on out is globals */
833 /* Special case for file with type declarations only, no text. */
834 if (!last_source_file && SDB_TYPE (cs->c_type)
835 && cs->c_secnum == N_DEBUG)
836 complete_symtab (filestring, 0, 0);
838 /* Typedefs should not be treated as symbol definitions. */
839 if (ISFCN (cs->c_type) && cs->c_sclass != C_TPDEF)
841 /* Record all functions -- external and static -- in minsyms. */
842 tmpaddr = cs->c_value + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT);
843 record_minimal_symbol (cs->c_name, tmpaddr, mst_text, objfile);
845 fcn_line_ptr = main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
846 fcn_start_addr = tmpaddr;
848 fcn_sym_saved = main_sym;
849 fcn_aux_saved = main_aux;
853 switch (cs->c_sclass)
862 complain (&bad_sclass_complaint, cs->c_name);
866 /* c_value field contains symnum of next .file entry in table
867 or symnum of first global after last .file. */
868 next_file_symnum = cs->c_value;
870 filestring = coff_getfilename (&main_aux);
874 /* Complete symbol table for last object file
875 containing debugging information. */
876 if (last_source_file)
878 coff_end_symtab (objfile);
879 coff_start_symtab (filestring);
884 /* C_LABEL is used for labels and static functions. Including
885 it here allows gdb to see static functions when no debug
886 info is available. */
888 /* However, labels within a function can make weird backtraces,
889 so filter them out (from phdm@macqel.be). */
895 case C_THUMBSTATFUNC:
896 if (cs->c_name[0] == '.')
898 if (STREQ (cs->c_name, ".text"))
900 /* FIXME: don't wire in ".text" as section name
902 /* Check for in_source_file deals with case of
903 a file with debugging symbols
904 followed by a later file with no symbols. */
906 complete_symtab (filestring,
907 cs->c_value + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT),
908 main_aux.x_scn.x_scnlen);
911 /* flush rest of '.' symbols */
914 else if (!SDB_TYPE (cs->c_type)
915 && cs->c_name[0] == 'L'
916 && (strncmp (cs->c_name, "LI%", 3) == 0
917 || strncmp (cs->c_name, "LF%", 3) == 0
918 || strncmp (cs->c_name, "LC%", 3) == 0
919 || strncmp (cs->c_name, "LP%", 3) == 0
920 || strncmp (cs->c_name, "LPB%", 4) == 0
921 || strncmp (cs->c_name, "LBB%", 4) == 0
922 || strncmp (cs->c_name, "LBE%", 4) == 0
923 || strncmp (cs->c_name, "LPBX%", 5) == 0))
924 /* At least on a 3b1, gcc generates swbeg and string labels
925 that look like this. Ignore them. */
927 /* fall in for static symbols that don't start with '.' */
932 /* Record it in the minimal symbols regardless of
933 SDB_TYPE. This parallels what we do for other debug
934 formats, and probably is needed to make
935 print_address_symbolic work right without the (now
936 gone) "set fast-symbolic-addr off" kludge. */
938 /* FIXME: should use mst_abs, and not relocate, if absolute. */
939 enum minimal_symbol_type ms_type;
942 if (cs->c_secnum == N_UNDEF)
944 /* This is a common symbol. See if the target
945 environment knows where it has been relocated to. */
947 if (target_lookup_symbol (cs->c_name, &reladdr))
949 /* Error in lookup; ignore symbol. */
953 /* The address has already been relocated; make sure that
954 objfile_relocate doesn't relocate it again. */
956 ms_type = cs->c_sclass == C_EXT
957 || cs->c_sclass == C_THUMBEXT ?
958 mst_bss : mst_file_bss;
962 sec = cs_to_section (cs, objfile);
963 tmpaddr = cs->c_value;
964 if (cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXTFUNC
965 || cs->c_sclass == C_THUMBEXT)
966 tmpaddr += ANOFFSET (objfile->section_offsets, sec);
971 case SECT_OFF_RODATA:
973 cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXTFUNC
974 || cs->c_sclass == C_THUMBEXT ?
975 mst_text : mst_file_text;
976 #ifdef SMASH_TEXT_ADDRESS
977 if (tmpaddr & 1) /* FIXME: delete this line */
978 SMASH_TEXT_ADDRESS (tmpaddr);
983 cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXT ?
984 mst_data : mst_file_data;
988 cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXT ?
989 mst_data : mst_file_data;
992 ms_type = mst_unknown;
997 if (cs->c_name[0] != '@' /* Skip tdesc symbols */ )
999 struct minimal_symbol *msym;
1001 msym = prim_record_minimal_symbol_and_info
1002 (cs->c_name, tmpaddr, ms_type, (char *) cs->c_sclass, sec,
1004 #ifdef COFF_MAKE_MSYMBOL_SPECIAL
1006 COFF_MAKE_MSYMBOL_SPECIAL (cs->c_sclass, msym);
1009 if (SDB_TYPE (cs->c_type))
1012 sym = process_coff_symbol
1013 (cs, &main_aux, objfile);
1014 SYMBOL_VALUE (sym) = tmpaddr;
1015 SYMBOL_SECTION (sym) = sec;
1021 if (STREQ (cs->c_name, ".bf"))
1023 within_function = 1;
1025 /* value contains address of first non-init type code */
1026 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
1027 contains line number of '{' } */
1028 if (cs->c_naux != 1)
1029 complain (&bf_no_aux_complaint, cs->c_symnum);
1030 fcn_first_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
1031 fcn_first_line_addr = cs->c_value;
1033 /* Might want to check that locals are 0 and
1034 context_stack_depth is zero, and complain if not. */
1037 new = push_context (depth, fcn_start_addr);
1038 fcn_cs_saved.c_name = getsymname (&fcn_sym_saved);
1040 process_coff_symbol (&fcn_cs_saved, &fcn_aux_saved, objfile);
1042 else if (STREQ (cs->c_name, ".ef"))
1044 /* the value of .ef is the address of epilogue code;
1045 not useful for gdb. */
1046 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1047 contains number of lines to '}' */
1049 if (context_stack_depth <= 0)
1050 { /* We attempted to pop an empty context stack */
1051 complain (&ef_stack_complaint, cs->c_symnum);
1052 within_function = 0;
1056 new = pop_context ();
1057 /* Stack must be empty now. */
1058 if (context_stack_depth > 0 || new == NULL)
1060 complain (&ef_complaint, cs->c_symnum);
1061 within_function = 0;
1064 if (cs->c_naux != 1)
1066 complain (&ef_no_aux_complaint, cs->c_symnum);
1067 fcn_last_line = 0x7FFFFFFF;
1071 fcn_last_line = main_aux.x_sym.x_misc.x_lnsz.x_lnno;
1073 /* fcn_first_line is the line number of the opening '{'.
1074 Do not record it - because it would affect gdb's idea
1075 of the line number of the first statement of the function -
1076 except for one-line functions, for which it is also the line
1077 number of all the statements and of the closing '}', and
1078 for which we do not have any other statement-line-number. */
1079 if (fcn_last_line == 1)
1080 record_line (current_subfile, fcn_first_line,
1081 fcn_first_line_addr);
1083 enter_linenos (fcn_line_ptr, fcn_first_line, fcn_last_line,
1086 finish_block (new->name, &local_symbols, new->old_blocks,
1088 #if defined (FUNCTION_EPILOGUE_SIZE)
1089 /* This macro should be defined only on
1091 fcn_aux_saved.x_sym.x_misc.x_fsize
1092 field is always zero.
1093 So use the .bf record information that
1094 points to the epilogue and add the size
1097 + FUNCTION_EPILOGUE_SIZE
1098 + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT),
1100 fcn_cs_saved.c_value
1101 + fcn_aux_saved.x_sym.x_misc.x_fsize
1102 + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT),
1106 within_function = 0;
1111 if (STREQ (cs->c_name, ".bb"))
1113 tmpaddr = cs->c_value;
1114 tmpaddr += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT);
1115 push_context (++depth, tmpaddr);
1117 else if (STREQ (cs->c_name, ".eb"))
1119 if (context_stack_depth <= 0)
1120 { /* We attempted to pop an empty context stack */
1121 complain (&eb_stack_complaint, cs->c_symnum);
1125 new = pop_context ();
1126 if (depth-- != new->depth)
1128 complain (&eb_complaint, symnum);
1131 if (local_symbols && context_stack_depth > 0)
1134 cs->c_value + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT);
1135 /* Make a block for the local symbols within. */
1136 finish_block (0, &local_symbols, new->old_blocks,
1137 new->start_addr, tmpaddr, objfile);
1139 /* Now pop locals of block just finished. */
1140 local_symbols = new->locals;
1145 process_coff_symbol (cs, &main_aux, objfile);
1150 if (last_source_file)
1151 coff_end_symtab (objfile);
1153 /* Patch up any opaque types (references to types that are not defined
1154 in the file where they are referenced, e.g. "struct foo *bar"). */
1155 ALL_OBJFILE_SYMTABS (objfile, s)
1156 patch_opaque_types (s);
1158 current_objfile = NULL;
1161 /* Routines for reading headers and symbols from executable. */
1163 /* Read the next symbol, swap it, and return it in both internal_syment
1164 form, and coff_symbol form. Also return its first auxent, if any,
1165 in internal_auxent form, and skip any other auxents. */
1168 read_one_sym (cs, sym, aux)
1169 register struct coff_symbol *cs;
1170 register struct internal_syment *sym;
1171 register union internal_auxent *aux;
1175 cs->c_symnum = symnum;
1176 bfd_read (temp_sym, local_symesz, 1, nlist_bfd_global);
1177 bfd_coff_swap_sym_in (symfile_bfd, temp_sym, (char *) sym);
1178 cs->c_naux = sym->n_numaux & 0xff;
1179 if (cs->c_naux >= 1)
1181 bfd_read (temp_aux, local_auxesz, 1, nlist_bfd_global);
1182 bfd_coff_swap_aux_in (symfile_bfd, temp_aux, sym->n_type, sym->n_sclass,
1183 0, cs->c_naux, (char *) aux);
1184 /* If more than one aux entry, read past it (only the first aux
1186 for (i = 1; i < cs->c_naux; i++)
1187 bfd_read (temp_aux, local_auxesz, 1, nlist_bfd_global);
1189 cs->c_name = getsymname (sym);
1190 cs->c_value = sym->n_value;
1191 cs->c_sclass = (sym->n_sclass & 0xff);
1192 cs->c_secnum = sym->n_scnum;
1193 cs->c_type = (unsigned) sym->n_type;
1194 if (!SDB_TYPE (cs->c_type))
1198 if (cs->c_sclass & 128)
1199 printf ("thumb symbol %s, class 0x%x\n", cs->c_name, cs->c_sclass);
1202 symnum += 1 + cs->c_naux;
1204 /* The PE file format stores symbol values as offsets within the
1205 section, rather than as absolute addresses. We correct that
1206 here, if the symbol has an appropriate storage class. FIXME: We
1207 should use BFD to read the symbols, rather than duplicating the
1211 switch (cs->c_sclass)
1215 case C_THUMBEXTFUNC:
1220 case C_THUMBSTATFUNC:
1226 if (cs->c_secnum != 0)
1227 cs->c_value += cs_section_address (cs, symfile_bfd);
1233 /* Support for string table handling */
1235 static char *stringtab = NULL;
1238 init_stringtab (abfd, offset)
1244 unsigned char lengthbuf[4];
1248 /* If the file is stripped, the offset might be zero, indicating no
1249 string table. Just return with `stringtab' set to null. */
1253 if (bfd_seek (abfd, offset, 0) < 0)
1256 val = bfd_read ((char *) lengthbuf, sizeof lengthbuf, 1, abfd);
1257 length = bfd_h_get_32 (symfile_bfd, lengthbuf);
1259 /* If no string table is needed, then the file may end immediately
1260 after the symbols. Just return with `stringtab' set to null. */
1261 if (val != sizeof lengthbuf || length < sizeof lengthbuf)
1264 stringtab = (char *) xmalloc (length);
1265 /* This is in target format (probably not very useful, and not currently
1266 used), not host format. */
1267 memcpy (stringtab, lengthbuf, sizeof lengthbuf);
1268 if (length == sizeof length) /* Empty table -- just the count */
1271 val = bfd_read (stringtab + sizeof lengthbuf, length - sizeof lengthbuf, 1, abfd);
1272 if (val != length - sizeof lengthbuf || stringtab[length - 1] != '\0')
1287 getsymname (symbol_entry)
1288 struct internal_syment *symbol_entry;
1290 static char buffer[SYMNMLEN + 1];
1293 if (symbol_entry->_n._n_n._n_zeroes == 0)
1295 /* FIXME: Probably should be detecting corrupt symbol files by
1296 seeing whether offset points to within the stringtab. */
1297 result = stringtab + symbol_entry->_n._n_n._n_offset;
1301 strncpy (buffer, symbol_entry->_n._n_name, SYMNMLEN);
1302 buffer[SYMNMLEN] = '\0';
1308 /* Extract the file name from the aux entry of a C_FILE symbol. Return
1309 only the last component of the name. Result is in static storage and
1310 is only good for temporary use. */
1313 coff_getfilename (aux_entry)
1314 union internal_auxent *aux_entry;
1316 static char buffer[BUFSIZ];
1317 register char *temp;
1320 if (aux_entry->x_file.x_n.x_zeroes == 0)
1321 strcpy (buffer, stringtab + aux_entry->x_file.x_n.x_offset);
1324 strncpy (buffer, aux_entry->x_file.x_fname, FILNMLEN);
1325 buffer[FILNMLEN] = '\0';
1329 /* FIXME: We should not be throwing away the information about what
1330 directory. It should go into dirname of the symtab, or some such
1332 if ((temp = strrchr (result, '/')) != NULL)
1337 /* Support for line number handling. */
1339 static char *linetab = NULL;
1340 static long linetab_offset;
1341 static unsigned long linetab_size;
1343 /* Read in all the line numbers for fast lookups later. Leave them in
1344 external (unswapped) format in memory; we'll swap them as we enter
1345 them into GDB's data structures. */
1348 init_lineno (abfd, offset, size)
1355 linetab_offset = offset;
1356 linetab_size = size;
1363 if (bfd_seek (abfd, offset, 0) < 0)
1366 /* Allocate the desired table, plus a sentinel */
1367 linetab = (char *) xmalloc (size + local_linesz);
1369 val = bfd_read (linetab, size, 1, abfd);
1373 /* Terminate it with an all-zero sentinel record */
1374 memset (linetab + size, 0, local_linesz);
1387 #if !defined (L_LNNO32)
1388 #define L_LNNO32(lp) ((lp)->l_lnno)
1392 enter_linenos (file_offset, first_line, last_line, objfile)
1394 register int first_line;
1395 register int last_line;
1396 struct objfile *objfile;
1398 register char *rawptr;
1399 struct internal_lineno lptr;
1403 if (file_offset < linetab_offset)
1405 complain (&lineno_complaint, file_offset);
1406 if (file_offset > linetab_size) /* Too big to be an offset? */
1408 file_offset += linetab_offset; /* Try reading at that linetab offset */
1411 rawptr = &linetab[file_offset - linetab_offset];
1413 /* skip first line entry for each function */
1414 rawptr += local_linesz;
1415 /* line numbers start at one for the first line of the function */
1420 bfd_coff_swap_lineno_in (symfile_bfd, rawptr, &lptr);
1421 rawptr += local_linesz;
1422 /* The next function, or the sentinel, will have L_LNNO32 zero; we exit. */
1423 if (L_LNNO32 (&lptr) && L_LNNO32 (&lptr) <= last_line)
1424 record_line (current_subfile, first_line + L_LNNO32 (&lptr),
1426 + ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT));
1433 patch_type (type, real_type)
1435 struct type *real_type;
1437 register struct type *target = TYPE_TARGET_TYPE (type);
1438 register struct type *real_target = TYPE_TARGET_TYPE (real_type);
1439 int field_size = TYPE_NFIELDS (real_target) * sizeof (struct field);
1441 TYPE_LENGTH (target) = TYPE_LENGTH (real_target);
1442 TYPE_NFIELDS (target) = TYPE_NFIELDS (real_target);
1443 TYPE_FIELDS (target) = (struct field *) TYPE_ALLOC (target, field_size);
1445 memcpy (TYPE_FIELDS (target), TYPE_FIELDS (real_target), field_size);
1447 if (TYPE_NAME (real_target))
1449 if (TYPE_NAME (target))
1450 free (TYPE_NAME (target));
1451 TYPE_NAME (target) = concat (TYPE_NAME (real_target), NULL);
1455 /* Patch up all appropriate typedef symbols in the opaque_type_chains
1456 so that they can be used to print out opaque data structures properly. */
1459 patch_opaque_types (s)
1462 register struct block *b;
1464 register struct symbol *real_sym;
1466 /* Go through the per-file symbols only */
1467 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
1468 for (i = BLOCK_NSYMS (b) - 1; i >= 0; i--)
1470 /* Find completed typedefs to use to fix opaque ones.
1471 Remove syms from the chain when their types are stored,
1472 but search the whole chain, as there may be several syms
1473 from different files with the same name. */
1474 real_sym = BLOCK_SYM (b, i);
1475 if (SYMBOL_CLASS (real_sym) == LOC_TYPEDEF &&
1476 SYMBOL_NAMESPACE (real_sym) == VAR_NAMESPACE &&
1477 TYPE_CODE (SYMBOL_TYPE (real_sym)) == TYPE_CODE_PTR &&
1478 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym))) != 0)
1480 register char *name = SYMBOL_NAME (real_sym);
1481 register int hash = hashname (name);
1482 register struct symbol *sym, *prev;
1485 for (sym = opaque_type_chain[hash]; sym;)
1487 if (name[0] == SYMBOL_NAME (sym)[0] &&
1488 STREQ (name + 1, SYMBOL_NAME (sym) + 1))
1492 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
1496 opaque_type_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
1499 patch_type (SYMBOL_TYPE (sym), SYMBOL_TYPE (real_sym));
1503 sym = SYMBOL_VALUE_CHAIN (prev);
1507 sym = opaque_type_chain[hash];
1513 sym = SYMBOL_VALUE_CHAIN (sym);
1520 static struct symbol *
1521 process_coff_symbol (cs, aux, objfile)
1522 register struct coff_symbol *cs;
1523 register union internal_auxent *aux;
1524 struct objfile *objfile;
1526 register struct symbol *sym
1527 = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
1528 sizeof (struct symbol));
1531 memset (sym, 0, sizeof (struct symbol));
1533 name = EXTERNAL_NAME (name, objfile->obfd);
1534 SYMBOL_NAME (sym) = obsavestring (name, strlen (name),
1535 &objfile->symbol_obstack);
1536 SYMBOL_LANGUAGE (sym) = language_auto;
1537 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1539 /* default assumptions */
1540 SYMBOL_VALUE (sym) = cs->c_value;
1541 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1542 SYMBOL_SECTION (sym) = cs_to_section (cs, objfile);
1544 if (ISFCN (cs->c_type))
1546 SYMBOL_VALUE (sym) += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT);
1548 lookup_function_type (decode_function_type (cs, cs->c_type, aux));
1550 SYMBOL_CLASS (sym) = LOC_BLOCK;
1551 if (cs->c_sclass == C_STAT || cs->c_sclass == C_THUMBSTAT
1552 || cs->c_sclass == C_THUMBSTATFUNC)
1553 add_symbol_to_list (sym, &file_symbols);
1554 else if (cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXT
1555 || cs->c_sclass == C_THUMBEXTFUNC)
1556 add_symbol_to_list (sym, &global_symbols);
1560 SYMBOL_TYPE (sym) = decode_type (cs, cs->c_type, aux);
1561 switch (cs->c_sclass)
1567 SYMBOL_CLASS (sym) = LOC_LOCAL;
1568 add_symbol_to_list (sym, &local_symbols);
1572 case C_THUMBEXTFUNC:
1574 SYMBOL_CLASS (sym) = LOC_STATIC;
1575 SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
1576 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT);
1577 add_symbol_to_list (sym, &global_symbols);
1581 case C_THUMBSTATFUNC:
1583 SYMBOL_CLASS (sym) = LOC_STATIC;
1584 SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
1585 SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT);
1586 if (within_function)
1588 /* Static symbol of local scope */
1589 add_symbol_to_list (sym, &local_symbols);
1593 /* Static symbol at top level of file */
1594 add_symbol_to_list (sym, &file_symbols);
1598 #ifdef C_GLBLREG /* AMD coff */
1602 SYMBOL_CLASS (sym) = LOC_REGISTER;
1603 SYMBOL_VALUE (sym) = SDB_REG_TO_REGNUM (cs->c_value);
1604 add_symbol_to_list (sym, &local_symbols);
1612 SYMBOL_CLASS (sym) = LOC_ARG;
1613 add_symbol_to_list (sym, &local_symbols);
1614 #if !defined (BELIEVE_PCC_PROMOTION)
1615 if (TARGET_BYTE_ORDER == BIG_ENDIAN)
1617 /* If PCC says a parameter is a short or a char,
1618 aligned on an int boundary, realign it to the
1619 "little end" of the int. */
1620 struct type *temptype;
1621 temptype = lookup_fundamental_type (current_objfile,
1623 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
1624 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
1625 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (temptype))
1627 SYMBOL_VALUE (sym) +=
1628 TYPE_LENGTH (temptype)
1629 - TYPE_LENGTH (SYMBOL_TYPE (sym));
1636 SYMBOL_CLASS (sym) = LOC_REGPARM;
1637 SYMBOL_VALUE (sym) = SDB_REG_TO_REGNUM (cs->c_value);
1638 add_symbol_to_list (sym, &local_symbols);
1639 #if !defined (BELIEVE_PCC_PROMOTION)
1640 /* FIXME: This should retain the current type, since it's just
1641 a register value. gnu@adobe, 26Feb93 */
1643 /* If PCC says a parameter is a short or a char,
1644 it is really an int. */
1645 struct type *temptype;
1647 lookup_fundamental_type (current_objfile, FT_INTEGER);
1648 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
1649 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
1652 (TYPE_UNSIGNED (SYMBOL_TYPE (sym))
1653 ? lookup_fundamental_type (current_objfile,
1654 FT_UNSIGNED_INTEGER)
1662 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1663 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1665 /* If type has no name, give it one */
1666 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
1668 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
1669 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
1671 /* If we are giving a name to a type such as "pointer to
1672 foo" or "function returning foo", we better not set
1673 the TYPE_NAME. If the program contains "typedef char
1674 *caddr_t;", we don't want all variables of type char
1675 * to print as caddr_t. This is not just a
1676 consequence of GDB's type management; CC and GCC (at
1677 least through version 2.4) both output variables of
1678 either type char * or caddr_t with the type
1679 refering to the C_TPDEF symbol for caddr_t. If a future
1680 compiler cleans this up it GDB is not ready for it
1681 yet, but if it becomes ready we somehow need to
1682 disable this check (without breaking the PCC/GCC2.4
1687 Fortunately, this check seems not to be necessary
1688 for anything except pointers or functions. */
1692 TYPE_NAME (SYMBOL_TYPE (sym)) =
1693 concat (SYMBOL_NAME (sym), NULL);
1696 /* Ignore vendor section for Harris CX/UX targets. */
1697 else if (cs->c_name[0] == '$')
1699 #endif /* CXUX_TARGET */
1701 /* Keep track of any type which points to empty structured type,
1702 so it can be filled from a definition from another file. A
1703 simple forward reference (TYPE_CODE_UNDEF) is not an
1704 empty structured type, though; the forward references
1705 work themselves out via the magic of coff_lookup_type. */
1706 if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR &&
1707 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym))) == 0 &&
1708 TYPE_CODE (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym))) !=
1711 register int i = hashname (SYMBOL_NAME (sym));
1713 SYMBOL_VALUE_CHAIN (sym) = opaque_type_chain[i];
1714 opaque_type_chain[i] = sym;
1716 add_symbol_to_list (sym, &file_symbols);
1722 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1723 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1725 /* Some compilers try to be helpful by inventing "fake"
1726 names for anonymous enums, structures, and unions, like
1727 "~0fake" or ".0fake". Thanks, but no thanks... */
1728 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
1729 if (SYMBOL_NAME (sym) != NULL
1730 && *SYMBOL_NAME (sym) != '~'
1731 && *SYMBOL_NAME (sym) != '.')
1732 TYPE_TAG_NAME (SYMBOL_TYPE (sym)) =
1733 concat (SYMBOL_NAME (sym), NULL);
1735 add_symbol_to_list (sym, &file_symbols);
1745 /* Decode a coff type specifier; return the type that is meant. */
1747 static struct type *
1748 decode_type (cs, c_type, aux)
1749 register struct coff_symbol *cs;
1750 unsigned int c_type;
1751 register union internal_auxent *aux;
1753 register struct type *type = 0;
1754 unsigned int new_c_type;
1756 if (c_type & ~N_BTMASK)
1758 new_c_type = DECREF (c_type);
1761 type = decode_type (cs, new_c_type, aux);
1762 type = lookup_pointer_type (type);
1764 else if (ISFCN (c_type))
1766 type = decode_type (cs, new_c_type, aux);
1767 type = lookup_function_type (type);
1769 else if (ISARY (c_type))
1772 register unsigned short *dim;
1773 struct type *base_type, *index_type, *range_type;
1775 /* Define an array type. */
1776 /* auxent refers to array, not base type */
1777 if (aux->x_sym.x_tagndx.l == 0)
1780 /* shift the indices down */
1781 dim = &aux->x_sym.x_fcnary.x_ary.x_dimen[0];
1784 for (i = 0; *dim && i < DIMNUM - 1; i++, dim++)
1788 base_type = decode_type (cs, new_c_type, aux);
1789 index_type = lookup_fundamental_type (current_objfile, FT_INTEGER);
1791 create_range_type ((struct type *) NULL, index_type, 0, n - 1);
1793 create_array_type ((struct type *) NULL, base_type, range_type);
1798 /* Reference to existing type. This only occurs with the
1799 struct, union, and enum types. EPI a29k coff
1800 fakes us out by producing aux entries with a nonzero
1801 x_tagndx for definitions of structs, unions, and enums, so we
1802 have to check the c_sclass field. SCO 3.2v4 cc gets confused
1803 with pointers to pointers to defined structs, and generates
1804 negative x_tagndx fields. */
1805 if (cs->c_naux > 0 && aux->x_sym.x_tagndx.l != 0)
1807 if (cs->c_sclass != C_STRTAG
1808 && cs->c_sclass != C_UNTAG
1809 && cs->c_sclass != C_ENTAG
1810 && aux->x_sym.x_tagndx.l >= 0)
1812 type = coff_alloc_type (aux->x_sym.x_tagndx.l);
1817 complain (&tagndx_bad_complaint, cs->c_name);
1818 /* And fall through to decode_base_type... */
1822 return decode_base_type (cs, BTYPE (c_type), aux);
1825 /* Decode a coff type specifier for function definition;
1826 return the type that the function returns. */
1828 static struct type *
1829 decode_function_type (cs, c_type, aux)
1830 register struct coff_symbol *cs;
1831 unsigned int c_type;
1832 register union internal_auxent *aux;
1834 if (aux->x_sym.x_tagndx.l == 0)
1835 cs->c_naux = 0; /* auxent refers to function, not base type */
1837 return decode_type (cs, DECREF (c_type), aux);
1842 static struct type *
1843 decode_base_type (cs, c_type, aux)
1844 register struct coff_symbol *cs;
1845 unsigned int c_type;
1846 register union internal_auxent *aux;
1853 /* shows up with "void (*foo)();" structure members */
1854 return lookup_fundamental_type (current_objfile, FT_VOID);
1857 /* DGUX actually defines both T_ARG and T_VOID to the same value. */
1860 /* Shows up in DGUX, I think. Not sure where. */
1861 return lookup_fundamental_type (current_objfile, FT_VOID); /* shouldn't show up here */
1867 /* Intel 960 COFF has this symbol and meaning. */
1868 return lookup_fundamental_type (current_objfile, FT_VOID);
1872 return lookup_fundamental_type (current_objfile, FT_CHAR);
1875 return lookup_fundamental_type (current_objfile, FT_SHORT);
1878 return lookup_fundamental_type (current_objfile, FT_INTEGER);
1881 if (cs->c_sclass == C_FIELD
1882 && aux->x_sym.x_misc.x_lnsz.x_size > TARGET_LONG_BIT)
1883 return lookup_fundamental_type (current_objfile, FT_LONG_LONG);
1885 return lookup_fundamental_type (current_objfile, FT_LONG);
1888 return lookup_fundamental_type (current_objfile, FT_FLOAT);
1891 return lookup_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT);
1894 return lookup_fundamental_type (current_objfile, FT_EXT_PREC_FLOAT);
1897 if (cs->c_naux != 1)
1899 /* anonymous structure type */
1900 type = coff_alloc_type (cs->c_symnum);
1901 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1902 TYPE_NAME (type) = NULL;
1903 /* This used to set the tag to "<opaque>". But I think setting it
1904 to NULL is right, and the printing code can print it as
1906 TYPE_TAG_NAME (type) = NULL;
1907 INIT_CPLUS_SPECIFIC (type);
1908 TYPE_LENGTH (type) = 0;
1909 TYPE_FIELDS (type) = 0;
1910 TYPE_NFIELDS (type) = 0;
1914 type = coff_read_struct_type (cs->c_symnum,
1915 aux->x_sym.x_misc.x_lnsz.x_size,
1916 aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
1921 if (cs->c_naux != 1)
1923 /* anonymous union type */
1924 type = coff_alloc_type (cs->c_symnum);
1925 TYPE_NAME (type) = NULL;
1926 /* This used to set the tag to "<opaque>". But I think setting it
1927 to NULL is right, and the printing code can print it as
1929 TYPE_TAG_NAME (type) = NULL;
1930 INIT_CPLUS_SPECIFIC (type);
1931 TYPE_LENGTH (type) = 0;
1932 TYPE_FIELDS (type) = 0;
1933 TYPE_NFIELDS (type) = 0;
1937 type = coff_read_struct_type (cs->c_symnum,
1938 aux->x_sym.x_misc.x_lnsz.x_size,
1939 aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
1941 TYPE_CODE (type) = TYPE_CODE_UNION;
1945 if (cs->c_naux != 1)
1947 /* anonymous enum type */
1948 type = coff_alloc_type (cs->c_symnum);
1949 TYPE_CODE (type) = TYPE_CODE_ENUM;
1950 TYPE_NAME (type) = NULL;
1951 /* This used to set the tag to "<opaque>". But I think setting it
1952 to NULL is right, and the printing code can print it as
1954 TYPE_TAG_NAME (type) = NULL;
1955 TYPE_LENGTH (type) = 0;
1956 TYPE_FIELDS (type) = 0;
1957 TYPE_NFIELDS (type) = 0;
1961 type = coff_read_enum_type (cs->c_symnum,
1962 aux->x_sym.x_misc.x_lnsz.x_size,
1963 aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
1968 /* shouldn't show up here */
1972 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_CHAR);
1975 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_SHORT);
1978 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER);
1981 if (cs->c_sclass == C_FIELD
1982 && aux->x_sym.x_misc.x_lnsz.x_size > TARGET_LONG_BIT)
1983 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_LONG_LONG);
1985 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_LONG);
1987 complain (&unexpected_type_complaint, cs->c_name);
1988 return lookup_fundamental_type (current_objfile, FT_VOID);
1991 /* This page contains subroutines of read_type. */
1993 /* Read the description of a structure (or union type) and return an
1994 object describing the type. */
1996 static struct type *
1997 coff_read_struct_type (index, length, lastsym)
2004 struct nextfield *next;
2008 register struct type *type;
2009 register struct nextfield *list = 0;
2010 struct nextfield *new;
2014 struct coff_symbol member_sym;
2015 register struct coff_symbol *ms = &member_sym;
2016 struct internal_syment sub_sym;
2017 union internal_auxent sub_aux;
2020 type = coff_alloc_type (index);
2021 TYPE_CODE (type) = TYPE_CODE_STRUCT;
2022 INIT_CPLUS_SPECIFIC (type);
2023 TYPE_LENGTH (type) = length;
2025 while (!done && symnum < lastsym && symnum < nlist_nsyms_global)
2027 read_one_sym (ms, &sub_sym, &sub_aux);
2029 name = EXTERNAL_NAME (name, current_objfile->obfd);
2031 switch (ms->c_sclass)
2036 /* Get space to record the next field's data. */
2037 new = (struct nextfield *) alloca (sizeof (struct nextfield));
2041 /* Save the data. */
2045 ¤t_objfile->symbol_obstack);
2046 FIELD_TYPE (list->field) = decode_type (ms, ms->c_type, &sub_aux);
2047 FIELD_BITPOS (list->field) = 8 * ms->c_value;
2048 FIELD_BITSIZE (list->field) = 0;
2054 /* Get space to record the next field's data. */
2055 new = (struct nextfield *) alloca (sizeof (struct nextfield));
2059 /* Save the data. */
2063 ¤t_objfile->symbol_obstack);
2064 FIELD_TYPE (list->field) = decode_type (ms, ms->c_type, &sub_aux);
2065 FIELD_BITPOS (list->field) = ms->c_value;
2066 FIELD_BITSIZE (list->field) = sub_aux.x_sym.x_misc.x_lnsz.x_size;
2075 /* Now create the vector of fields, and record how big it is. */
2077 TYPE_NFIELDS (type) = nfields;
2078 TYPE_FIELDS (type) = (struct field *)
2079 TYPE_ALLOC (type, sizeof (struct field) * nfields);
2081 /* Copy the saved-up fields into the field vector. */
2083 for (n = nfields; list; list = list->next)
2084 TYPE_FIELD (type, --n) = list->field;
2089 /* Read a definition of an enumeration type,
2090 and create and return a suitable type object.
2091 Also defines the symbols that represent the values of the type. */
2094 static struct type *
2095 coff_read_enum_type (index, length, lastsym)
2100 register struct symbol *sym;
2101 register struct type *type;
2104 struct pending **symlist;
2105 struct coff_symbol member_sym;
2106 register struct coff_symbol *ms = &member_sym;
2107 struct internal_syment sub_sym;
2108 union internal_auxent sub_aux;
2109 struct pending *osyms, *syms;
2113 int unsigned_enum = 1;
2115 type = coff_alloc_type (index);
2116 if (within_function)
2117 symlist = &local_symbols;
2119 symlist = &file_symbols;
2121 o_nsyms = osyms ? osyms->nsyms : 0;
2123 while (!done && symnum < lastsym && symnum < nlist_nsyms_global)
2125 read_one_sym (ms, &sub_sym, &sub_aux);
2127 name = EXTERNAL_NAME (name, current_objfile->obfd);
2129 switch (ms->c_sclass)
2132 sym = (struct symbol *) obstack_alloc
2133 (¤t_objfile->symbol_obstack,
2134 sizeof (struct symbol));
2135 memset (sym, 0, sizeof (struct symbol));
2138 obsavestring (name, strlen (name),
2139 ¤t_objfile->symbol_obstack);
2140 SYMBOL_CLASS (sym) = LOC_CONST;
2141 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2142 SYMBOL_VALUE (sym) = ms->c_value;
2143 add_symbol_to_list (sym, symlist);
2148 /* Sometimes the linker (on 386/ix 2.0.2 at least) screws
2149 up the count of how many symbols to read. So stop
2156 /* Now fill in the fields of the type-structure. */
2159 TYPE_LENGTH (type) = length;
2161 TYPE_LENGTH (type) = TARGET_INT_BIT / TARGET_CHAR_BIT; /* Assume ints */
2162 TYPE_CODE (type) = TYPE_CODE_ENUM;
2163 TYPE_NFIELDS (type) = nsyms;
2164 TYPE_FIELDS (type) = (struct field *)
2165 TYPE_ALLOC (type, sizeof (struct field) * nsyms);
2167 /* Find the symbols for the values and put them into the type.
2168 The symbols can be found in the symlist that we put them on
2169 to cause them to be defined. osyms contains the old value
2170 of that symlist; everything up to there was defined by us. */
2171 /* Note that we preserve the order of the enum constants, so
2172 that in something like "enum {FOO, LAST_THING=FOO}" we print
2173 FOO, not LAST_THING. */
2175 for (syms = *symlist, n = 0; syms; syms = syms->next)
2181 for (; j < syms->nsyms; j++, n++)
2183 struct symbol *xsym = syms->symbol[j];
2184 SYMBOL_TYPE (xsym) = type;
2185 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
2186 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
2187 if (SYMBOL_VALUE (xsym) < 0)
2189 TYPE_FIELD_BITSIZE (type, n) = 0;
2196 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
2201 /* Register our ability to parse symbols for coff BFD files. */
2203 static struct sym_fns coff_sym_fns =
2205 bfd_target_coff_flavour,
2206 coff_new_init, /* sym_new_init: init anything gbl to entire symtab */
2207 coff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
2208 coff_symfile_read, /* sym_read: read a symbol file into symtab */
2209 coff_symfile_finish, /* sym_finish: finished with file, cleanup */
2210 default_symfile_offsets, /* sym_offsets: xlate external to internal form */
2211 NULL /* next: pointer to next struct sym_fns */
2215 _initialize_coffread ()
2217 add_symtab_fns (&coff_sym_fns);