1 /* Read coff symbol tables and convert to internal format, for GDB.
2 Contributed by David D. Johnson, Brown University (ddj@cs.brown.edu).
3 Copyright 1987, 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include "breakpoint.h"
31 #include "coff/internal.h" /* Internal format of COFF symbols in BFD */
32 #include "libcoff.h" /* FIXME secret internal data from BFD */
34 static void add_symbol_to_list ();
35 static void read_coff_symtab ();
36 static void patch_opaque_types ();
37 static struct type
*decode_function_type ();
38 static struct type
*decode_type ();
39 static struct type
*decode_base_type ();
40 static struct type
*read_enum_type ();
41 static struct type
*read_struct_type ();
42 static void finish_block ();
43 static struct blockvector
*make_blockvector ();
44 static struct symbol
*process_coff_symbol ();
45 static int init_stringtab ();
46 static void free_stringtab ();
47 static char *getfilename ();
48 static char *getsymname ();
49 static int init_lineno ();
50 static void enter_linenos ();
51 static void read_one_sym ();
55 /* To be an sdb debug type, type must have at least a basic or primary
56 derived type. Using this rather than checking against T_NULL is
57 said to prevent core dumps if we try to operate on Michael Bloom
60 #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 /* Name of source file whose symbol data we are now processing.
72 This comes from a symbol named ".file". */
74 static char *last_source_file
;
76 /* Core address of start and end of text of current source file.
77 This comes from a ".text" symbol where x_nlinno > 0. */
79 static CORE_ADDR cur_src_start_addr
;
80 static CORE_ADDR cur_src_end_addr
;
82 /* Core address of the end of the first object file. */
83 static CORE_ADDR first_object_file_end
;
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 FILE *nlist_stream_global
;
89 static int nlist_nsyms_global
;
91 /* The index in the symbol table of the last coff symbol that was processed. */
95 /* Vector of types defined so far, indexed by their coff symnum. */
97 static struct type
**type_vector
;
99 /* Number of elements allocated for type_vector currently. */
101 static int type_vector_length
;
103 /* Vector of line number information. */
105 static struct linetable
*line_vector
;
107 /* Index of next entry to go in line_vector_index. */
109 static int line_vector_index
;
111 /* Last line number recorded in the line vector. */
113 static int prev_line_number
;
115 /* Number of elements allocated for line_vector currently. */
117 static int line_vector_length
;
119 /* Pointers to scratch storage, used for reading raw symbols and auxents. */
121 static char *temp_sym
;
122 static char *temp_aux
;
124 /* Local variables that hold the shift and mask values for the
125 COFF file that we are currently reading. These come back to us
126 from BFD, and are referenced by their macro names, as well as
127 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
128 macros from ../internalcoff.h . */
130 static unsigned local_n_btmask
;
131 static unsigned local_n_btshft
;
132 static unsigned local_n_tmask
;
133 static unsigned local_n_tshift
;
135 #define N_BTMASK local_n_btmask
136 #define N_BTSHFT local_n_btshft
137 #define N_TMASK local_n_tmask
138 #define N_TSHIFT local_n_tshift
140 /* Local variables that hold the sizes in the file of various COFF structures.
141 (We only need to know this to read them from the file -- BFD will then
142 translate the data in them, into `internal_xxx' structs in the right
143 byte order, alignment, etc.) */
145 static unsigned local_linesz
;
146 static unsigned local_symesz
;
147 static unsigned local_auxesz
;
150 /* Chain of typedefs of pointers to empty struct/union types.
151 They are chained thru the SYMBOL_VALUE_CHAIN. */
154 static struct symbol
*opaque_type_chain
[HASHSIZE
];
156 /* Record the symbols defined for each context in a list.
157 We don't create a struct block for the context until we
158 know how long to make it. */
162 struct pending
*next
;
163 struct symbol
*symbol
;
166 /* Here are the three lists that symbols are put on. */
168 struct pending
*file_symbols
; /* static at top level, and types */
170 struct pending
*global_symbols
; /* global functions and variables */
172 struct pending
*local_symbols
; /* everything local to lexical context */
174 /* List of unclosed lexical contexts
175 (that will become blocks, eventually). */
179 struct context_stack
*next
;
180 struct pending
*locals
;
181 struct pending_block
*old_blocks
;
183 CORE_ADDR start_addr
;
187 struct context_stack
*context_stack
;
189 /* Nonzero if within a function (so symbols should be local,
190 if nothing says specifically). */
195 /* The type of the function we are currently reading in. This is
196 used by define_symbol to record the type of arguments to a function. */
198 struct type
*in_function_type
;
201 /* List of blocks already made (lexical contexts already closed).
202 This is used at the end to make the blockvector. */
206 struct pending_block
*next
;
210 struct pending_block
*pending_blocks
;
212 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
213 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
215 /* Complaints about various problems in the file being read */
217 struct complaint ef_complaint
=
218 {"Unmatched .ef symbol(s) ignored starting at symnum %d", 0, 0};
220 struct complaint bf_no_aux_complaint
=
221 {"`.bf' symbol %d has no aux entry", 0, 0};
223 struct complaint ef_no_aux_complaint
=
224 {"`.ef' symbol %d has no aux entry", 0, 0};
226 struct complaint lineno_complaint
=
227 {"Line number pointer %d lower than start of line numbers", 0, 0};
229 struct complaint unexpected_type_complaint
=
230 {"Unexpected type for symbol %s", 0, 0};
232 struct complaint bad_sclass_complaint
=
233 {"Bad n_sclass for symbol %s", 0, 0};
235 /* Look up a coff type-number index. Return the address of the slot
236 where the type for that index is stored.
237 The type-number is in INDEX.
239 This can be used for finding the type associated with that index
240 or for associating a new type with the index. */
242 static struct type
**
243 coff_lookup_type (index
)
246 if (index
>= type_vector_length
)
248 int old_vector_length
= type_vector_length
;
250 type_vector_length
*= 2;
251 if (type_vector_length
< index
) {
252 type_vector_length
= index
* 2;
254 type_vector
= (struct type
**)
255 xrealloc (type_vector
, type_vector_length
* sizeof (struct type
*));
256 bzero (&type_vector
[old_vector_length
],
257 (type_vector_length
- old_vector_length
) * sizeof(struct type
*));
259 return &type_vector
[index
];
262 /* Make sure there is a type allocated for type number index
263 and return the type object.
264 This can create an empty (zeroed) type object. */
267 coff_alloc_type (index
)
270 register struct type
**type_addr
= coff_lookup_type (index
);
271 register struct type
*type
= *type_addr
;
273 /* If we are referring to a type not known at all yet,
274 allocate an empty type for it.
275 We will fill it in later if we find out how. */
278 type
= (struct type
*) obstack_alloc (symbol_obstack
,
279 sizeof (struct type
));
280 bzero (type
, sizeof (struct type
));
281 TYPE_VPTR_FIELDNO (type
) = -1;
287 /* maintain the lists of symbols and blocks */
289 /* Add a symbol to one of the lists of symbols. */
291 add_symbol_to_list (symbol
, listhead
)
292 struct symbol
*symbol
;
293 struct pending
**listhead
;
295 register struct pending
*link
296 = (struct pending
*) xmalloc (sizeof (struct pending
));
298 link
->next
= *listhead
;
299 link
->symbol
= symbol
;
303 /* Take one of the lists of symbols and make a block from it.
304 Put the block on the list of pending blocks. */
307 finish_block (symbol
, listhead
, old_blocks
, start
, end
)
308 struct symbol
*symbol
;
309 struct pending
**listhead
;
310 struct pending_block
*old_blocks
;
311 CORE_ADDR start
, end
;
313 register struct pending
*next
, *next1
;
314 register struct block
*block
;
315 register struct pending_block
*pblock
;
316 struct pending_block
*opblock
;
319 /* Count the length of the list of symbols. */
321 for (next
= *listhead
, i
= 0; next
; next
= next
->next
, i
++);
323 block
= (struct block
*)
324 obstack_alloc (symbol_obstack
, sizeof (struct block
) + (i
- 1) * sizeof (struct symbol
*));
326 /* Copy the symbols into the block. */
328 BLOCK_NSYMS (block
) = i
;
329 for (next
= *listhead
; next
; next
= next
->next
)
330 BLOCK_SYM (block
, --i
) = next
->symbol
;
332 BLOCK_START (block
) = start
;
333 BLOCK_END (block
) = end
;
334 BLOCK_SUPERBLOCK (block
) = 0; /* Filled in when containing block is made */
336 /* Put the block in as the value of the symbol that names it. */
340 SYMBOL_BLOCK_VALUE (symbol
) = block
;
341 BLOCK_FUNCTION (block
) = symbol
;
344 BLOCK_FUNCTION (block
) = 0;
346 /* Now free the links of the list, and empty the list. */
348 for (next
= *listhead
; next
; next
= next1
)
355 /* Install this block as the superblock
356 of all blocks made since the start of this scope
357 that don't have superblocks yet. */
360 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
362 if (BLOCK_SUPERBLOCK (pblock
->block
) == 0)
363 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
367 /* Record this block on the list of all blocks in the file.
368 Put it after opblock, or at the beginning if opblock is 0.
369 This puts the block in the list after all its subblocks. */
371 pblock
= (struct pending_block
*) xmalloc (sizeof (struct pending_block
));
372 pblock
->block
= block
;
375 pblock
->next
= opblock
->next
;
376 opblock
->next
= pblock
;
380 pblock
->next
= pending_blocks
;
381 pending_blocks
= pblock
;
385 static struct blockvector
*
388 register struct pending_block
*next
, *next1
;
389 register struct blockvector
*blockvector
;
392 /* Count the length of the list of blocks. */
394 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
396 blockvector
= (struct blockvector
*)
397 obstack_alloc (symbol_obstack
, sizeof (struct blockvector
) + (i
- 1) * sizeof (struct block
*));
399 /* Copy the blocks into the blockvector.
400 This is done in reverse order, which happens to put
401 the blocks into the proper order (ascending starting address).
402 finish_block has hair to insert each block into the list
403 after its subblocks in order to make sure this is true. */
405 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
406 for (next
= pending_blocks
; next
; next
= next
->next
)
407 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
409 /* Now free the links of the list, and empty the list. */
411 for (next
= pending_blocks
; next
; next
= next1
)
421 /* Manage the vector of line numbers. */
424 record_line (line
, pc
)
428 struct linetable_entry
*e
;
429 /* Make sure line vector is big enough. */
431 if (line_vector_index
+ 2 >= line_vector_length
)
433 line_vector_length
*= 2;
434 line_vector
= (struct linetable
*)
435 xrealloc (line_vector
, sizeof (struct linetable
)
436 + (line_vector_length
437 * sizeof (struct linetable_entry
)));
440 e
= line_vector
->item
+ line_vector_index
++;
441 e
->line
= line
; e
->pc
= pc
;
444 /* Start a new symtab for a new source file.
445 This is called when a COFF ".file" symbol is seen;
446 it indicates the start of data for one original source file. */
455 last_source_file
= 0;
457 /* Initialize the source file line number information for this file. */
459 if (line_vector
) /* Unlikely, but maybe possible? */
461 line_vector_index
= 0;
462 line_vector_length
= 1000;
463 prev_line_number
= -2; /* Force first line number to be explicit */
464 line_vector
= (struct linetable
*)
465 xmalloc (sizeof (struct linetable
)
466 + line_vector_length
* sizeof (struct linetable_entry
));
469 /* Save the vital information from when starting to read a file,
470 for use when closing off the current file.
471 NAME is the file name the symbols came from, START_ADDR is the first
472 text address for the file, and SIZE is the number of bytes of text. */
475 complete_symtab (name
, start_addr
, size
)
477 CORE_ADDR start_addr
;
480 last_source_file
= savestring (name
, strlen (name
));
481 cur_src_start_addr
= start_addr
;
482 cur_src_end_addr
= start_addr
+ size
;
484 if (entry_point
< cur_src_end_addr
485 && entry_point
>= cur_src_start_addr
)
487 startup_file_start
= cur_src_start_addr
;
488 startup_file_end
= cur_src_end_addr
;
492 /* Finish the symbol definitions for one main source file,
493 close off all the lexical contexts for that file
494 (creating struct block's for them), then make the
495 struct symtab for that file and put it in the list of all such. */
499 struct objfile
*objfile
;
501 register struct symtab
*symtab
;
502 register struct context_stack
*cstk
;
503 register struct blockvector
*blockvector
;
504 register struct linetable
*lv
;
506 /* Finish the lexical context of the last function in the file. */
510 cstk
= context_stack
;
512 /* Make a block for the local symbols within. */
513 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
514 cstk
->start_addr
, cur_src_end_addr
);
518 /* Ignore a file that has no functions with real debugging info. */
519 if (pending_blocks
== 0 && file_symbols
== 0 && global_symbols
== 0)
523 line_vector_length
= -1;
524 last_source_file
= 0;
528 /* Create the two top-level blocks for this file (STATIC_BLOCK and
530 finish_block (0, &file_symbols
, 0, cur_src_start_addr
, cur_src_end_addr
);
531 finish_block (0, &global_symbols
, 0, cur_src_start_addr
, cur_src_end_addr
);
533 /* Create the blockvector that points to all the file's blocks. */
534 blockvector
= make_blockvector ();
536 /* Now create the symtab object for this source file. */
537 symtab
= allocate_symtab (last_source_file
, objfile
);
539 /* Fill in its components. */
540 symtab
->blockvector
= blockvector
;
541 symtab
->free_code
= free_linetable
;
542 symtab
->free_ptr
= 0;
543 symtab
->filename
= last_source_file
;
544 symtab
->dirname
= NULL
;
546 lv
->nitems
= line_vector_index
;
547 symtab
->linetable
= (struct linetable
*)
548 xrealloc (lv
, (sizeof (struct linetable
)
549 + lv
->nitems
* sizeof (struct linetable_entry
)));
551 free_named_symtabs (symtab
->filename
);
553 /* Link the new symtab into the list of such. */
554 symtab
->next
= symtab_list
;
555 symtab_list
= symtab
;
557 /* Reinitialize for beginning of new file. */
559 line_vector_length
= -1;
560 last_source_file
= 0;
564 record_misc_function (name
, address
)
568 /* We don't want TDESC entry points on the misc_function_vector */
569 if (name
[0] == '@') return;
571 /* mf_text isn't true, but apparently COFF doesn't tell us what it really
572 is, so this guess is more useful than mf_unknown. */
573 prim_record_misc_function (savestring (name
, strlen (name
)),
578 /* coff_symfile_init ()
579 is the coff-specific initialization routine for reading symbols.
580 It is passed a struct sym_fns which contains, among other things,
581 the BFD for the file whose symbols are being read, and a slot for
582 a pointer to "private data" which we fill with cookies and other
583 treats for coff_symfile_read ().
585 We will only be called if this is a COFF or COFF-like file.
586 BFD handles figuring out the format of the file, and code in symtab.c
587 uses BFD's determination to vector to us.
589 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
591 struct coff_symfile_info
{
592 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
593 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
596 static int text_bfd_scnum
;
599 coff_symfile_init (sf
)
603 bfd
*abfd
= sf
->sym_bfd
;
605 /* Allocate struct to keep track of the symfile */
606 /* FIXME memory leak */
607 sf
->sym_private
= xmalloc (sizeof (struct coff_symfile_info
));
609 /* Save startup file's range of PC addresses to help blockframe.c
610 decide where the bottom of the stack is. */
611 if (bfd_get_file_flags (abfd
) & EXEC_P
)
613 /* Executable file -- record its entry point so we'll recognize
614 the startup file because it contains the entry point. */
615 entry_point
= bfd_get_start_address (abfd
);
619 /* Examination of non-executable.o files. Short-circuit this stuff. */
620 /* ~0 will not be in any file, we hope. */
622 /* set the startup file to be an empty range. */
623 startup_file_start
= 0;
624 startup_file_end
= 0;
626 /* Save the section number for the text section */
627 if (section
= bfd_get_section_by_name(abfd
,".text"))
628 text_bfd_scnum
= section
->index
;
633 /* This function is called for every section; it finds the outer limits
634 of the line table (minimum and maximum file offset) so that the
635 mainline code can read the whole thing for efficiency. */
639 find_linenos (abfd
, asect
, vpinfo
)
644 struct coff_symfile_info
*info
;
646 file_ptr offset
, maxoff
;
648 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
649 count
= asect
->lineno_count
;
654 size
= count
* local_linesz
;
656 info
= (struct coff_symfile_info
*)vpinfo
;
657 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
658 offset
= asect
->line_filepos
;
661 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
662 info
->min_lineno_offset
= offset
;
664 maxoff
= offset
+ size
;
665 if (maxoff
> info
->max_lineno_offset
)
666 info
->max_lineno_offset
= maxoff
;
670 /* The BFD for this file -- only good while we're actively reading
671 symbols into a psymtab or a symtab. */
673 static bfd
*symfile_bfd
;
675 /* Read a symbol file, after initialization by coff_symfile_init. */
676 /* FIXME! Addr and Mainline are not used yet -- this will not work for
677 shared libraries or add_file! */
681 coff_symfile_read (sf
, addr
, mainline
)
686 struct coff_symfile_info
*info
= (struct coff_symfile_info
*)sf
->sym_private
;
687 bfd
*abfd
= sf
->objfile
->obfd
;
688 coff_data_type
*cdata
= coff_data (abfd
);
689 char *name
= bfd_get_filename (abfd
);
694 int stringtab_offset
;
696 symfile_bfd
= abfd
; /* Kludge for swap routines */
698 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
699 desc
= fileno ((FILE *)(abfd
->iostream
)); /* File descriptor */
700 num_symbols
= bfd_get_symcount (abfd
); /* How many syms */
701 symtab_offset
= cdata
->sym_filepos
; /* Symbol table file offset */
702 stringtab_offset
= symtab_offset
+ /* String table file offset */
703 num_symbols
* cdata
->local_symesz
;
705 /* Set a few file-statics that give us specific information about
706 the particular COFF file format we're reading. */
707 local_linesz
= cdata
->local_linesz
;
708 local_n_btmask
= cdata
->local_n_btmask
;
709 local_n_btshft
= cdata
->local_n_btshft
;
710 local_n_tmask
= cdata
->local_n_tmask
;
711 local_n_tshift
= cdata
->local_n_tshift
;
712 local_linesz
= cdata
->local_linesz
;
713 local_symesz
= cdata
->local_symesz
;
714 local_auxesz
= cdata
->local_auxesz
;
716 /* Allocate space for raw symbol and aux entries, based on their
717 space requirements as reported by BFD. */
718 temp_sym
= (char *) xmalloc
719 (cdata
->local_symesz
+ cdata
->local_auxesz
);
720 temp_aux
= temp_sym
+ cdata
->local_symesz
;
721 make_cleanup (free_current_contents
, &temp_sym
);
724 /* Read the line number table, all at once. */
725 info
->min_lineno_offset
= 0;
726 info
->max_lineno_offset
= 0;
727 bfd_map_over_sections (abfd
, find_linenos
, info
);
729 val
= init_lineno (desc
, info
->min_lineno_offset
,
730 info
->max_lineno_offset
- info
->min_lineno_offset
);
732 error ("\"%s\": error reading line numbers\n", name
);
734 /* Now read the string table, all at once. */
736 val
= init_stringtab (desc
, stringtab_offset
);
738 error ("\"%s\": can't get string table", name
);
739 make_cleanup (free_stringtab
, 0);
741 /* Position to read the symbol table. Do not read it all at once. */
742 val
= lseek (desc
, (long)symtab_offset
, 0);
744 perror_with_name (name
);
746 init_misc_bunches ();
747 make_cleanup (discard_misc_bunches
, 0);
749 /* Now that the executable file is positioned at symbol table,
750 process it and define symbols accordingly. */
752 read_coff_symtab (desc
, num_symbols
, sf
->objfile
);
754 patch_opaque_types ();
756 /* Sort symbols alphabetically within each block. */
758 sort_all_symtab_syms ();
760 /* Go over the misc symbol bunches and install them in vector. */
762 condense_misc_bunches (!mainline
);
771 /* Simplified internal version of coff symbol table information */
775 int c_symnum
; /* symbol number of this entry */
776 int c_naux
; /* 0 if syment only, 1 if syment + auxent, etc */
783 /* Given pointers to a symbol table in coff style exec file,
784 analyze them and create struct symtab's describing the symbols.
785 NSYMS is the number of symbols in the symbol table.
786 We read them one at a time using read_one_sym (). */
789 read_coff_symtab (desc
, nsyms
, objfile
)
792 struct objfile
*objfile
;
794 int newfd
; /* Avoid multiple closes on same desc */
796 register struct context_stack
*new;
797 struct coff_symbol coff_symbol
;
798 register struct coff_symbol
*cs
= &coff_symbol
;
799 static struct internal_syment main_sym
;
800 static union internal_auxent main_aux
;
801 struct coff_symbol fcn_cs_saved
;
802 static struct internal_syment fcn_sym_saved
;
803 static union internal_auxent fcn_aux_saved
;
805 /* A .file is open. */
806 int in_source_file
= 0;
807 int num_object_files
= 0;
808 int next_file_symnum
= -1;
810 /* Name of the current file. */
811 char *filestring
= "";
817 struct cleanup
*old_chain
;
822 fatal ("Too many open files");
823 stream
= fdopen (newfd
, "r");
825 /* These cleanups will be discarded below if we succeed. */
826 old_chain
= make_cleanup (free_objfile
, objfile
);
827 make_cleanup (fclose
, stream
);
829 nlist_stream_global
= stream
;
830 nlist_nsyms_global
= nsyms
;
831 last_source_file
= 0;
832 bzero (opaque_type_chain
, sizeof opaque_type_chain
);
834 if (type_vector
) /* Get rid of previous one */
836 type_vector_length
= 160;
837 type_vector
= (struct type
**)
838 xmalloc (type_vector_length
* sizeof (struct type
*));
839 bzero (type_vector
, type_vector_length
* sizeof (struct type
*));
844 while (symnum
< nsyms
)
846 QUIT
; /* Make this command interruptable. */
847 read_one_sym (cs
, &main_sym
, &main_aux
);
850 temp_sem_val
= cs
->c_name
[0] << 24 | cs
->c_name
[1] << 16 |
851 cs
->c_name
[2] << 8 | cs
->c_name
[3];
852 if (int_sem_val
== temp_sem_val
)
853 last_coffsem
= (int) strtol (cs
->c_name
+4, (char **) NULL
, 10);
856 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
858 if (last_source_file
)
859 end_symtab (objfile
);
862 complete_symtab ("_globals_", 0, first_object_file_end
);
863 /* done with all files, everything from here on out is globals */
866 /* Special case for file with type declarations only, no text. */
867 if (!last_source_file
&& SDB_TYPE (cs
->c_type
)
868 && cs
->c_secnum
== N_DEBUG
)
869 complete_symtab (filestring
, 0, 0);
871 /* Typedefs should not be treated as symbol definitions. */
872 if (ISFCN (cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
874 /* record as misc function. if we get '.bf' next,
875 * then we undo this step
877 record_misc_function (cs
->c_name
, cs
->c_value
);
879 fcn_line_ptr
= main_aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
880 fcn_start_addr
= cs
->c_value
;
882 fcn_sym_saved
= main_sym
;
883 fcn_aux_saved
= main_aux
;
887 switch (cs
->c_sclass
)
896 complain (&bad_sclass_complaint
, cs
->c_name
);
901 * c_value field contains symnum of next .file entry in table
902 * or symnum of first global after last .file.
904 next_file_symnum
= cs
->c_value
;
905 filestring
= getfilename (&main_aux
);
907 * Complete symbol table for last object file
908 * containing debugging information.
910 if (last_source_file
)
912 end_symtab (objfile
);
919 if (cs
->c_name
[0] == '.') {
920 if (strcmp (cs
->c_name
, ".text") == 0) {
921 /* FIXME: don't wire in ".text" as section name
923 if (++num_object_files
== 1) {
924 /* last address of startup file */
925 first_object_file_end
= cs
->c_value
+
926 main_aux
.x_scn
.x_scnlen
;
928 /* Check for in_source_file deals with case of
929 a file with debugging symbols
930 followed by a later file with no symbols. */
932 complete_symtab (filestring
, cs
->c_value
,
933 main_aux
.x_scn
.x_scnlen
);
936 /* flush rest of '.' symbols */
939 else if (!SDB_TYPE (cs
->c_type
)
940 && cs
->c_name
[0] == 'L'
941 && (strncmp (cs
->c_name
, "LI%", 3) == 0
942 || strncmp (cs
->c_name
, "LF%", 3) == 0
943 || strncmp (cs
->c_name
,"LC%",3) == 0
944 || strncmp (cs
->c_name
,"LP%",3) == 0
945 || strncmp (cs
->c_name
,"LPB%",4) == 0
946 || strncmp (cs
->c_name
,"LBB%",4) == 0
947 || strncmp (cs
->c_name
,"LBE%",4) == 0
948 || strncmp (cs
->c_name
,"LPBX%",5) == 0))
949 /* At least on a 3b1, gcc generates swbeg and string labels
950 that look like this. Ignore them. */
952 /* fall in for static symbols that don't start with '.' */
954 if (!SDB_TYPE (cs
->c_type
)) {
955 /* FIXME: This is BOGUS Will Robinson!
956 Coff should provide the SEC_CODE flag for executable sections,
957 then if we could look up sections by section number we
958 could see if the flags indicate SEC_CODE. If so, then
959 record this symbol as a miscellaneous function. But why
960 are absolute syms recorded as functions, anyway? */
961 if (cs
->c_secnum
<= text_bfd_scnum
+1) {/* text or abs */
962 record_misc_function (cs
->c_name
, cs
->c_value
);
968 (void) process_coff_symbol (cs
, &main_aux
);
972 if (strcmp (cs
->c_name
, ".bf") == 0)
976 /* value contains address of first non-init type code */
977 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
978 contains line number of '{' } */
980 complain (&bf_no_aux_complaint
, cs
->c_symnum
);
981 fcn_first_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
983 new = (struct context_stack
*)
984 xmalloc (sizeof (struct context_stack
));
985 new->depth
= depth
= 0;
989 new->old_blocks
= pending_blocks
;
990 new->start_addr
= fcn_start_addr
;
991 fcn_cs_saved
.c_name
= getsymname (&fcn_sym_saved
);
992 new->name
= process_coff_symbol (&fcn_cs_saved
,
995 else if (strcmp (cs
->c_name
, ".ef") == 0)
997 /* the value of .ef is the address of epilogue code;
1000 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1001 contains number of lines to '}' */
1002 new = context_stack
;
1005 complain (&ef_complaint
, cs
->c_symnum
);
1006 within_function
= 0;
1009 if (cs
->c_naux
!= 1) {
1010 complain (&ef_no_aux_complaint
, cs
->c_symnum
);
1011 fcn_last_line
= 0x7FFFFFFF;
1013 fcn_last_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
1015 enter_linenos (fcn_line_ptr
, fcn_first_line
, fcn_last_line
);
1017 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1019 #if defined (FUNCTION_EPILOGUE_SIZE)
1020 /* This macro should be defined only on
1022 fcn_aux_saved.x_sym.x_misc.x_fsize
1023 field is always zero.
1024 So use the .bf record information that
1025 points to the epilogue and add the size
1027 cs
->c_value
+ FUNCTION_EPILOGUE_SIZE
1029 fcn_cs_saved
.c_value
+
1030 fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1034 within_function
= 0;
1040 if (strcmp (cs
->c_name
, ".bb") == 0)
1042 new = (struct context_stack
*)
1043 xmalloc (sizeof (struct context_stack
));
1046 new->next
= context_stack
;
1047 context_stack
= new;
1048 new->locals
= local_symbols
;
1049 new->old_blocks
= pending_blocks
;
1050 new->start_addr
= cs
->c_value
;
1054 else if (strcmp (cs
->c_name
, ".eb") == 0)
1056 new = context_stack
;
1057 if (new == 0 || depth
!= new->depth
)
1058 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1060 if (local_symbols
&& context_stack
->next
)
1062 /* Make a block for the local symbols within. */
1063 finish_block (0, &local_symbols
, new->old_blocks
,
1064 new->start_addr
, cs
->c_value
);
1067 local_symbols
= new->locals
;
1068 context_stack
= new->next
;
1074 (void) process_coff_symbol (cs
, &main_aux
);
1079 if (last_source_file
)
1080 end_symtab (objfile
);
1082 discard_cleanups (old_chain
);
1085 /* Routines for reading headers and symbols from executable. */
1088 /* Move these XXXMAGIC symbol defns into BFD! */
1090 /* Read COFF file header, check magic number,
1091 and return number of symbols. */
1092 read_file_hdr (chan
, file_hdr
)
1096 lseek (chan
, 0L, 0);
1097 if (myread (chan
, (char *)file_hdr
, FILHSZ
) < 0)
1100 switch (file_hdr
->f_magic
)
1115 #if defined (MC68KWRMAGIC) \
1116 && (!defined (MC68MAGIC) || MC68KWRMAGIC != MC68MAGIC)
1130 case I960ROMAGIC
: /* Intel 960 */
1133 case I960RWMAGIC
: /* Intel 960 */
1135 return file_hdr
->f_nsyms
;
1139 if (BADMAG(file_hdr
))
1142 return file_hdr
->f_nsyms
;
1150 /* Read the next symbol, swap it, and return it in both internal_syment
1151 form, and coff_symbol form. Also return its first auxent, if any,
1152 in internal_auxent form, and skip any other auxents. */
1155 read_one_sym (cs
, sym
, aux
)
1156 register struct coff_symbol
*cs
;
1157 register struct internal_syment
*sym
;
1158 register union internal_auxent
*aux
;
1162 cs
->c_symnum
= symnum
;
1163 fread (temp_sym
, local_symesz
, 1, nlist_stream_global
);
1164 bfd_coff_swap_sym_in (symfile_bfd
, temp_sym
, (char *)sym
);
1165 cs
->c_naux
= sym
->n_numaux
& 0xff;
1166 if (cs
->c_naux
>= 1)
1168 fread (temp_aux
, local_auxesz
, 1, nlist_stream_global
);
1169 bfd_coff_swap_aux_in (symfile_bfd
, temp_aux
, sym
->n_type
, sym
->n_sclass
,
1171 /* If more than one aux entry, read past it (only the first aux
1173 for (i
= 1; i
< cs
->c_naux
; i
++)
1174 fread (temp_aux
, local_auxesz
, 1, nlist_stream_global
);
1176 cs
->c_name
= getsymname (sym
);
1177 cs
->c_value
= sym
->n_value
;
1178 cs
->c_sclass
= (sym
->n_sclass
& 0xff);
1179 cs
->c_secnum
= sym
->n_scnum
;
1180 cs
->c_type
= (unsigned) sym
->n_type
;
1181 if (!SDB_TYPE (cs
->c_type
))
1184 symnum
+= 1 + cs
->c_naux
;
1187 /* Support for string table handling */
1189 static char *stringtab
= NULL
;
1192 init_stringtab (chan
, offset
)
1198 unsigned char lengthbuf
[4];
1206 if (lseek (chan
, offset
, 0) < 0)
1209 val
= myread (chan
, (char *)lengthbuf
, sizeof lengthbuf
);
1210 length
= bfd_h_get_32 (symfile_bfd
, lengthbuf
);
1212 /* If no string table is needed, then the file may end immediately
1213 after the symbols. Just return with `stringtab' set to null. */
1214 if (val
!= sizeof length
|| length
< sizeof length
)
1217 stringtab
= (char *) xmalloc (length
);
1218 if (stringtab
== NULL
)
1221 bcopy (&length
, stringtab
, sizeof length
);
1222 if (length
== sizeof length
) /* Empty table -- just the count */
1225 val
= myread (chan
, stringtab
+ sizeof length
, length
- sizeof length
);
1226 if (val
!= length
- sizeof length
|| stringtab
[length
- 1] != '\0')
1241 getsymname (symbol_entry
)
1242 struct internal_syment
*symbol_entry
;
1244 static char buffer
[SYMNMLEN
+1];
1247 if (symbol_entry
->_n
._n_n
._n_zeroes
== 0)
1249 result
= stringtab
+ symbol_entry
->_n
._n_n
._n_offset
;
1253 strncpy (buffer
, symbol_entry
->_n
._n_name
, SYMNMLEN
);
1254 buffer
[SYMNMLEN
] = '\0';
1261 getfilename (aux_entry
)
1262 union internal_auxent
*aux_entry
;
1264 static char buffer
[BUFSIZ
];
1265 register char *temp
;
1267 extern char *rindex ();
1269 #ifndef COFF_NO_LONG_FILE_NAMES
1270 #if defined (x_zeroes)
1272 if (aux_entry
->x_zeroes
== 0)
1273 strcpy (buffer
, stringtab
+ aux_entry
->x_offset
);
1274 #else /* no x_zeroes */
1275 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1276 strcpy (buffer
, stringtab
+ aux_entry
->x_file
.x_n
.x_offset
);
1277 #endif /* no x_zeroes */
1279 #endif /* COFF_NO_LONG_FILE_NAMES */
1281 #if defined (x_name)
1283 strncpy (buffer
, aux_entry
->x_name
, FILNMLEN
);
1285 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1287 buffer
[FILNMLEN
] = '\0';
1290 if ((temp
= rindex (result
, '/')) != NULL
)
1295 /* Support for line number handling */
1296 static char *linetab
= NULL
;
1297 static long linetab_offset
;
1298 static unsigned long linetab_size
;
1300 /* Read in all the line numbers for fast lookups later. Leave them in
1301 external (unswapped) format in memory; we'll swap them as we enter
1302 them into GDB's data structures. */
1305 init_lineno (chan
, offset
, size
)
1312 linetab_offset
= offset
;
1313 linetab_size
= size
;
1318 if (lseek (chan
, offset
, 0) < 0)
1321 /* Allocate the desired table, plus a sentinel */
1322 linetab
= (char *) xmalloc (size
+ local_linesz
);
1324 val
= myread (chan
, linetab
, size
);
1328 /* Terminate it with an all-zero sentinel record */
1329 bzero (linetab
+ size
, local_linesz
);
1331 make_cleanup (free
, linetab
); /* Be sure it gets de-allocated. */
1335 #if !defined (L_LNNO32)
1336 #define L_LNNO32(lp) ((lp)->l_lnno)
1340 enter_linenos (file_offset
, first_line
, last_line
)
1342 register int first_line
;
1343 register int last_line
;
1345 register char *rawptr
;
1346 struct internal_lineno lptr
;
1348 if (file_offset
< linetab_offset
)
1350 complain (&lineno_complaint
, file_offset
);
1351 if (file_offset
> linetab_size
) /* Too big to be an offset? */
1353 file_offset
+= linetab_offset
; /* Try reading at that linetab offset */
1356 rawptr
= &linetab
[file_offset
- linetab_offset
];
1358 /* skip first line entry for each function */
1359 rawptr
+= local_linesz
;
1360 /* line numbers start at one for the first line of the function */
1364 bfd_coff_swap_lineno_in (symfile_bfd
, rawptr
, &lptr
);
1365 rawptr
+= local_linesz
;
1366 /* The next function, or the sentinel, will have L_LNNO32 zero; we exit. */
1367 if (L_LNNO32 (&lptr
) && L_LNNO32 (&lptr
) <= last_line
)
1368 record_line (first_line
+ L_LNNO32 (&lptr
), lptr
.l_addr
.l_paddr
);
1378 register char *p
= name
;
1379 register int total
= p
[0];
1392 return total
% HASHSIZE
;
1396 patch_type (type
, real_type
)
1398 struct type
*real_type
;
1400 register struct type
*target
= TYPE_TARGET_TYPE (type
);
1401 register struct type
*real_target
= TYPE_TARGET_TYPE (real_type
);
1402 int field_size
= TYPE_NFIELDS (real_target
) * sizeof (struct field
);
1404 TYPE_LENGTH (target
) = TYPE_LENGTH (real_target
);
1405 TYPE_NFIELDS (target
) = TYPE_NFIELDS (real_target
);
1406 TYPE_FIELDS (target
) = (struct field
*)
1407 obstack_alloc (symbol_obstack
, field_size
);
1409 bcopy (TYPE_FIELDS (real_target
), TYPE_FIELDS (target
), field_size
);
1411 if (TYPE_NAME (real_target
))
1413 if (TYPE_NAME (target
))
1414 free (TYPE_NAME (target
));
1415 TYPE_NAME (target
) = concat (TYPE_NAME (real_target
), NULL
);
1419 /* Patch up all appropriate typedef symbols in the opaque_type_chains
1420 so that they can be used to print out opaque data structures properly */
1423 patch_opaque_types ()
1427 /* Look at each symbol in the per-file block of each symtab. */
1428 for (s
= symtab_list
; s
; s
= s
->next
)
1430 register struct block
*b
;
1433 /* Go through the per-file symbols only */
1434 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
1435 for (i
= BLOCK_NSYMS (b
) - 1; i
>= 0; i
--)
1437 register struct symbol
*real_sym
;
1439 /* Find completed typedefs to use to fix opaque ones.
1440 Remove syms from the chain when their types are stored,
1441 but search the whole chain, as there may be several syms
1442 from different files with the same name. */
1443 real_sym
= BLOCK_SYM (b
, i
);
1444 if (SYMBOL_CLASS (real_sym
) == LOC_TYPEDEF
&&
1445 SYMBOL_NAMESPACE (real_sym
) == VAR_NAMESPACE
&&
1446 TYPE_CODE (SYMBOL_TYPE (real_sym
)) == TYPE_CODE_PTR
&&
1447 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym
))) != 0)
1449 register char *name
= SYMBOL_NAME (real_sym
);
1450 register int hash
= hashname (name
);
1451 register struct symbol
*sym
, *prev
;
1454 for (sym
= opaque_type_chain
[hash
]; sym
;)
1456 if (name
[0] == SYMBOL_NAME (sym
)[0] &&
1457 !strcmp (name
+ 1, SYMBOL_NAME (sym
) + 1))
1460 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
1462 opaque_type_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
1464 patch_type (SYMBOL_TYPE (sym
), SYMBOL_TYPE (real_sym
));
1467 sym
= SYMBOL_VALUE_CHAIN (prev
);
1469 sym
= opaque_type_chain
[hash
];
1474 sym
= SYMBOL_VALUE_CHAIN (sym
);
1482 static struct symbol
*
1483 process_coff_symbol (cs
, aux
)
1484 register struct coff_symbol
*cs
;
1485 register union internal_auxent
*aux
;
1487 register struct symbol
*sym
1488 = (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
1490 #ifdef NAMES_HAVE_UNDERSCORE
1496 bzero (sym
, sizeof (struct symbol
));
1498 name
= (name
[0] == '_' ? name
+ offset
: name
);
1499 SYMBOL_NAME (sym
) = obstack_copy0 (symbol_obstack
, name
, strlen (name
));
1501 /* default assumptions */
1502 SYMBOL_VALUE (sym
) = cs
->c_value
;
1503 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1505 if (ISFCN (cs
->c_type
))
1508 /* FIXME: This has NOT been tested. The DBX version has.. */
1509 /* Generate a template for the type of this function. The
1510 types of the arguments will be added as we read the symbol
1512 struct type
*new = (struct type
*)
1513 obstack_alloc (symbol_obstack
, sizeof (struct type
));
1515 bcopy(lookup_function_type (decode_function_type (cs
, cs
->c_type
, aux
)),
1516 new, sizeof(struct type
));
1517 SYMBOL_TYPE (sym
) = new;
1518 in_function_type
= SYMBOL_TYPE(sym
);
1521 lookup_function_type (decode_function_type (cs
, cs
->c_type
, aux
));
1524 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1525 if (cs
->c_sclass
== C_STAT
)
1526 add_symbol_to_list (sym
, &file_symbols
);
1527 else if (cs
->c_sclass
== C_EXT
)
1528 add_symbol_to_list (sym
, &global_symbols
);
1532 SYMBOL_TYPE (sym
) = decode_type (cs
, cs
->c_type
, aux
);
1533 switch (cs
->c_sclass
)
1539 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1540 add_symbol_to_list (sym
, &local_symbols
);
1544 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1545 SYMBOL_VALUE_ADDRESS (sym
) = (CORE_ADDR
) cs
->c_value
;
1546 add_symbol_to_list (sym
, &global_symbols
);
1550 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1551 SYMBOL_VALUE_ADDRESS (sym
) = (CORE_ADDR
) cs
->c_value
;
1552 if (within_function
) {
1553 /* Static symbol of local scope */
1554 add_symbol_to_list (sym
, &local_symbols
);
1557 /* Static symbol at top level of file */
1558 add_symbol_to_list (sym
, &file_symbols
);
1562 #ifdef C_GLBLREG /* AMD coff */
1566 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1567 SYMBOL_VALUE (sym
) = SDB_REG_TO_REGNUM(cs
->c_value
);
1568 add_symbol_to_list (sym
, &local_symbols
);
1575 SYMBOL_CLASS (sym
) = LOC_ARG
;
1577 /* FIXME: This has not been tested. */
1578 /* Add parameter to function. */
1579 add_param_to_type(&in_function_type
,sym
);
1581 add_symbol_to_list (sym
, &local_symbols
);
1582 #if !defined (BELIEVE_PCC_PROMOTION)
1583 /* If PCC says a parameter is a short or a char,
1584 it is really an int. */
1585 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (builtin_type_int
)
1586 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
) {
1587 SYMBOL_TYPE (sym
) = TYPE_UNSIGNED (SYMBOL_TYPE (sym
))?
1588 builtin_type_unsigned_int
:
1595 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1596 SYMBOL_VALUE (sym
) = SDB_REG_TO_REGNUM(cs
->c_value
);
1597 add_symbol_to_list (sym
, &local_symbols
);
1598 #if !defined (BELIEVE_PCC_PROMOTION)
1599 /* If PCC says a parameter is a short or a char,
1600 it is really an int. */
1601 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (builtin_type_int
)
1602 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
) {
1603 SYMBOL_TYPE (sym
) = TYPE_UNSIGNED (SYMBOL_TYPE (sym
))?
1604 builtin_type_unsigned_int
:
1611 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1612 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1614 /* If type has no name, give it one */
1615 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1616 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1617 TYPE_NAME (SYMBOL_TYPE (sym
))
1618 = concat (SYMBOL_NAME (sym
), NULL
);
1620 /* Keep track of any type which points to empty structured type,
1621 so it can be filled from a definition from another file */
1622 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
&&
1623 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym
))) == 0)
1625 register int i
= hashname (SYMBOL_NAME (sym
));
1627 SYMBOL_VALUE_CHAIN (sym
) = opaque_type_chain
[i
];
1628 opaque_type_chain
[i
] = sym
;
1630 add_symbol_to_list (sym
, &file_symbols
);
1636 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1637 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1638 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1639 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1640 TYPE_NAME (SYMBOL_TYPE (sym
))
1642 (cs
->c_sclass
== C_ENTAG
1644 : (cs
->c_sclass
== C_STRTAG
1645 ? "struct " : "union ")),
1646 SYMBOL_NAME (sym
), NULL
);
1647 add_symbol_to_list (sym
, &file_symbols
);
1657 /* Decode a coff type specifier;
1658 return the type that is meant. */
1662 decode_type (cs
, c_type
, aux
)
1663 register struct coff_symbol
*cs
;
1664 unsigned int c_type
;
1665 register union internal_auxent
*aux
;
1667 register struct type
*type
= 0;
1668 unsigned int new_c_type
;
1670 if (c_type
& ~N_BTMASK
)
1672 new_c_type
= DECREF (c_type
);
1675 type
= decode_type (cs
, new_c_type
, aux
);
1676 type
= lookup_pointer_type (type
);
1678 else if (ISFCN (c_type
))
1680 type
= decode_type (cs
, new_c_type
, aux
);
1681 type
= lookup_function_type (type
);
1683 else if (ISARY (c_type
))
1686 register unsigned short *dim
;
1687 struct type
*base_type
;
1689 /* Define an array type. */
1690 /* auxent refers to array, not base type */
1691 if (aux
->x_sym
.x_tagndx
.l
== 0)
1694 /* shift the indices down */
1695 dim
= &aux
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0];
1698 for (i
= 0; *dim
&& i
< DIMNUM
- 1; i
++, dim
++)
1702 type
= (struct type
*)
1703 obstack_alloc (symbol_obstack
, sizeof (struct type
));
1704 bzero (type
, sizeof (struct type
));
1706 base_type
= decode_type (cs
, new_c_type
, aux
);
1708 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
1709 TYPE_TARGET_TYPE (type
) = base_type
;
1710 TYPE_LENGTH (type
) = n
* TYPE_LENGTH (base_type
);
1715 /* Reference to existing type */
1716 if (cs
->c_naux
> 0 && aux
->x_sym
.x_tagndx
.l
!= 0)
1718 type
= coff_alloc_type (aux
->x_sym
.x_tagndx
.l
);
1722 return decode_base_type (cs
, BTYPE (c_type
), aux
);
1725 /* Decode a coff type specifier for function definition;
1726 return the type that the function returns. */
1730 decode_function_type (cs
, c_type
, aux
)
1731 register struct coff_symbol
*cs
;
1732 unsigned int c_type
;
1733 register union internal_auxent
*aux
;
1735 if (aux
->x_sym
.x_tagndx
.l
== 0)
1736 cs
->c_naux
= 0; /* auxent refers to function, not base type */
1738 return decode_type (cs
, DECREF (c_type
), aux
);
1745 decode_base_type (cs
, c_type
, aux
)
1746 register struct coff_symbol
*cs
;
1747 unsigned int c_type
;
1748 register union internal_auxent
*aux
;
1755 /* shows up with "void (*foo)();" structure members */
1756 return builtin_type_void
;
1759 /* DGUX actually defines both T_ARG and T_VOID to the same value. */
1762 /* Shows up in DGUX, I think. Not sure where. */
1763 return builtin_type_void
; /* shouldn't show up here */
1769 /* Intel 960 COFF has this symbol and meaning. */
1770 return builtin_type_void
;
1774 return builtin_type_char
;
1777 return builtin_type_short
;
1780 return builtin_type_int
;
1783 return builtin_type_long
;
1786 return builtin_type_float
;
1789 return builtin_type_double
;
1792 if (cs
->c_naux
!= 1)
1794 /* anonymous structure type */
1795 type
= coff_alloc_type (cs
->c_symnum
);
1796 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1797 TYPE_NAME (type
) = concat ("struct ", "<opaque>", NULL
);
1798 TYPE_CPLUS_SPECIFIC(type
) = &cplus_struct_default
;
1799 TYPE_LENGTH (type
) = 0;
1800 TYPE_FIELDS (type
) = 0;
1801 TYPE_NFIELDS (type
) = 0;
1805 type
= read_struct_type (cs
->c_symnum
,
1806 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1807 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1812 if (cs
->c_naux
!= 1)
1814 /* anonymous union type */
1815 type
= coff_alloc_type (cs
->c_symnum
);
1816 TYPE_NAME (type
) = concat ("union ", "<opaque>", NULL
);
1817 TYPE_CPLUS_SPECIFIC(type
) = &cplus_struct_default
;
1818 TYPE_LENGTH (type
) = 0;
1819 TYPE_LENGTH (type
) = 0;
1820 TYPE_FIELDS (type
) = 0;
1821 TYPE_NFIELDS (type
) = 0;
1825 type
= read_struct_type (cs
->c_symnum
,
1826 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1827 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1829 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1833 return read_enum_type (cs
->c_symnum
,
1834 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1835 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1838 /* shouldn't show up here */
1842 return builtin_type_unsigned_char
;
1845 return builtin_type_unsigned_short
;
1848 return builtin_type_unsigned_int
;
1851 return builtin_type_unsigned_long
;
1853 complain (&unexpected_type_complaint
, cs
->c_name
);
1854 return builtin_type_void
;
1857 /* This page contains subroutines of read_type. */
1859 /* Read the description of a structure (or union type)
1860 and return an object describing the type. */
1862 static struct type
*
1863 read_struct_type (index
, length
, lastsym
)
1870 struct nextfield
*next
;
1874 register struct type
*type
;
1875 register struct nextfield
*list
= 0;
1876 struct nextfield
*new;
1880 #ifdef NAMES_HAVE_UNDERSCORE
1885 struct coff_symbol member_sym
;
1886 register struct coff_symbol
*ms
= &member_sym
;
1887 struct internal_syment sub_sym
;
1888 union internal_auxent sub_aux
;
1891 type
= coff_alloc_type (index
);
1892 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1893 TYPE_CPLUS_SPECIFIC(type
) = &cplus_struct_default
;
1894 TYPE_LENGTH (type
) = length
;
1896 while (!done
&& symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
1898 read_one_sym (ms
, &sub_sym
, &sub_aux
);
1900 name
= (name
[0] == '_' ? name
+ offset
: name
);
1902 switch (ms
->c_sclass
)
1907 /* Get space to record the next field's data. */
1908 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1912 /* Save the data. */
1913 list
->field
.name
= savestring (name
, strlen (name
));
1914 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1915 list
->field
.bitpos
= 8 * ms
->c_value
;
1916 list
->field
.bitsize
= 0;
1922 /* Get space to record the next field's data. */
1923 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1927 /* Save the data. */
1928 list
->field
.name
= savestring (name
, strlen (name
));
1929 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1930 list
->field
.bitpos
= ms
->c_value
;
1931 list
->field
.bitsize
= sub_aux
.x_sym
.x_misc
.x_lnsz
.x_size
;
1940 /* Now create the vector of fields, and record how big it is. */
1942 TYPE_NFIELDS (type
) = nfields
;
1943 TYPE_FIELDS (type
) = (struct field
*)
1944 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nfields
);
1946 /* Copy the saved-up fields into the field vector. */
1948 for (n
= nfields
; list
; list
= list
->next
)
1949 TYPE_FIELD (type
, --n
) = list
->field
;
1954 /* Read a definition of an enumeration type,
1955 and create and return a suitable type object.
1956 Also defines the symbols that represent the values of the type. */
1957 /* Currently assumes it's sizeof (int) and doesn't use length. */
1960 static struct type
*
1961 read_enum_type (index
, length
, lastsym
)
1966 register struct symbol
*sym
;
1967 register struct type
*type
;
1970 struct pending
**symlist
;
1971 struct coff_symbol member_sym
;
1972 register struct coff_symbol
*ms
= &member_sym
;
1973 struct internal_syment sub_sym
;
1974 union internal_auxent sub_aux
;
1975 struct pending
*osyms
, *syms
;
1978 #ifdef NAMES_HAVE_UNDERSCORE
1984 type
= coff_alloc_type (index
);
1985 if (within_function
)
1986 symlist
= &local_symbols
;
1988 symlist
= &file_symbols
;
1991 while (!done
&& symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
1993 read_one_sym (ms
, &sub_sym
, &sub_aux
);
1995 name
= (name
[0] == '_' ? name
+ offset
: name
);
1997 switch (ms
->c_sclass
)
2000 sym
= (struct symbol
*) xmalloc (sizeof (struct symbol
));
2001 bzero (sym
, sizeof (struct symbol
));
2003 SYMBOL_NAME (sym
) = savestring (name
, strlen (name
));
2004 SYMBOL_CLASS (sym
) = LOC_CONST
;
2005 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2006 SYMBOL_VALUE (sym
) = ms
->c_value
;
2007 add_symbol_to_list (sym
, symlist
);
2012 /* Sometimes the linker (on 386/ix 2.0.2 at least) screws
2013 up the count of how many symbols to read. So stop
2020 /* Now fill in the fields of the type-structure. */
2022 /* FIXME: Should be sizeof (int) on target, not host. */
2023 TYPE_LENGTH (type
) = sizeof (int);
2024 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2025 TYPE_NFIELDS (type
) = nsyms
;
2026 TYPE_FIELDS (type
) = (struct field
*)
2027 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nsyms
);
2029 /* Find the symbols for the values and put them into the type.
2030 The symbols can be found in the symlist that we put them on
2031 to cause them to be defined. osyms contains the old value
2032 of that symlist; everything up to there was defined by us. */
2034 for (syms
= *symlist
, n
= nsyms
; syms
!= osyms
; syms
= syms
->next
)
2036 SYMBOL_TYPE (syms
->symbol
) = type
;
2037 TYPE_FIELD_NAME (type
, --n
) = SYMBOL_NAME (syms
->symbol
);
2038 TYPE_FIELD_VALUE (type
, n
) = 0;
2039 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (syms
->symbol
);
2040 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2042 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2043 if(TYPE_NFIELDS(type
) == 2 &&
2044 ((!strcmp(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2045 !strcmp(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2046 (!strcmp(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2047 !strcmp(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2048 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2052 /* Register our ability to parse symbols for coff BFD files */
2054 static struct sym_fns coff_sym_fns
=
2057 coff_new_init
, coff_symfile_init
, coff_symfile_read
,
2061 _initialize_coffread ()
2063 add_symtab_fns(&coff_sym_fns
);