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