1 /* Read coff symbol tables and convert to internal format, for GDB.
2 Design and support routines derived from dbxread.c, and UMAX COFF
3 specific routines written 9/1/87 by David D. Johnson, Brown University.
4 Revised 11/27/87 ddj@cs.brown.edu
5 Copyright (C) 1987-1991 Free Software Foundation, Inc.
7 This file is part of GDB.
9 GDB is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 1, or (at your option)
14 GDB is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GDB; see the file COPYING. If not, write to
21 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include "breakpoint.h"
31 #include <intel-coff.h>
35 #include "libcoff.h" /* FIXME secret internal data from BFD */
37 static void add_symbol_to_list ();
38 static void read_coff_symtab ();
39 static void patch_opaque_types ();
40 static struct type
*decode_function_type ();
41 static struct type
*decode_type ();
42 static struct type
*decode_base_type ();
43 static struct type
*read_enum_type ();
44 static struct type
*read_struct_type ();
45 static void finish_block ();
46 static struct blockvector
*make_blockvector ();
47 static struct symbol
*process_coff_symbol ();
48 static int init_stringtab ();
49 static void free_stringtab ();
50 static char *getfilename ();
51 static char *getsymname ();
52 static int init_lineno ();
53 static void enter_linenos ();
54 static void read_one_sym ();
57 extern void free_all_symtabs ();
58 extern void free_all_psymtabs ();
60 /* To be an sdb debug type, type must have at least a basic or primary
61 derived type. Using this rather than checking against T_NULL is
62 said to prevent core dumps if we try to operate on Michael Bloom
65 #define SDB_TYPE(type) (BTYPE(type) | (type & N_TMASK))
67 /* external routines from the BFD library -- undocumented interface used
68 by GDB to read symbols. Move to libcoff.h. FIXME-SOMEDAY! */
69 extern void bfd_coff_swap_sym (/* symfile_bfd, &sym */);
70 extern void bfd_coff_swap_aux (/* symfile_bfd, &aux, type, sclass */);
71 extern void bfd_coff_swap_lineno (/* symfile_bfd, &lineno */);
74 /* Name of source file whose symbol data we are now processing.
75 This comes from a symbol named ".file". */
77 static char *last_source_file
;
79 /* Core address of start and end of text of current source file.
80 This comes from a ".text" symbol where x_nlinno > 0. */
82 static CORE_ADDR cur_src_start_addr
;
83 static CORE_ADDR cur_src_end_addr
;
85 /* Core address of the end of the first object file. */
86 static CORE_ADDR first_object_file_end
;
88 /* End of the text segment of the executable file,
89 as found in the symbol _etext. */
91 static CORE_ADDR end_of_text_addr
;
93 /* The addresses of the symbol table stream and number of symbols
94 of the object file we are reading (as copied into core). */
96 static FILE *nlist_stream_global
;
97 static int nlist_nsyms_global
;
99 /* The entry point (starting address) of the file, if it is an executable. */
101 static CORE_ADDR entry_point
;
103 /* The index in the symbol table of the last coff symbol that was processed. */
107 /* Vector of types defined so far, indexed by their coff symnum. */
109 static struct typevector
*type_vector
;
111 /* Number of elements allocated for type_vector currently. */
113 static int type_vector_length
;
115 /* Vector of line number information. */
117 static struct linetable
*line_vector
;
119 /* Index of next entry to go in line_vector_index. */
121 static int line_vector_index
;
123 /* Last line number recorded in the line vector. */
125 static int prev_line_number
;
127 /* Number of elements allocated for line_vector currently. */
129 static int line_vector_length
;
133 int int_sem_val
= 's' << 24 | 'e' << 16 | 'm' << 8 | '.';
135 int last_coffsem
= 2;
136 int last_coffsyn
= 0;
137 int debug_info
= 0; /*used by tdesc */
138 extern int tdesc_handle
;
139 extern int safe_to_init_tdesc_context
;
142 /* Chain of typedefs of pointers to empty struct/union types.
143 They are chained thru the SYMBOL_VALUE_CHAIN. */
146 static struct symbol
*opaque_type_chain
[HASHSIZE
];
148 /* Record the symbols defined for each context in a list.
149 We don't create a struct block for the context until we
150 know how long to make it. */
154 struct pending
*next
;
155 struct symbol
*symbol
;
158 /* Here are the three lists that symbols are put on. */
160 struct pending
*file_symbols
; /* static at top level, and types */
162 struct pending
*global_symbols
; /* global functions and variables */
164 struct pending
*local_symbols
; /* everything local to lexical context */
166 /* List of unclosed lexical contexts
167 (that will become blocks, eventually). */
171 struct context_stack
*next
;
172 struct pending
*locals
;
173 struct pending_block
*old_blocks
;
175 CORE_ADDR start_addr
;
179 struct context_stack
*context_stack
;
181 /* Nonzero if within a function (so symbols should be local,
182 if nothing says specifically). */
186 /* List of blocks already made (lexical contexts already closed).
187 This is used at the end to make the blockvector. */
191 struct pending_block
*next
;
195 struct pending_block
*pending_blocks
;
197 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
198 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
200 /* Complaints about various problems in the file being read */
202 struct complaint ef_complaint
=
203 {"Unmatched .ef symbol(s) ignored starting at symnum %d", 0, 0};
205 struct complaint lineno_complaint
=
206 {"Line number pointer %d lower than start of line numbers", 0, 0};
209 /* Look up a coff type-number index. Return the address of the slot
210 where the type for that index is stored.
211 The type-number is in INDEX.
213 This can be used for finding the type associated with that index
214 or for associating a new type with the index. */
216 static struct type
**
217 coff_lookup_type (index
)
220 if (index
>= type_vector_length
)
222 int old_vector_length
= type_vector_length
;
224 type_vector_length
*= 2;
225 if (type_vector_length
< index
) {
226 type_vector_length
= index
* 2;
228 type_vector
= (struct typevector
*)
229 xrealloc (type_vector
, sizeof (struct typevector
)
230 + type_vector_length
* sizeof (struct type
*));
231 bzero (&type_vector
->type
[ old_vector_length
],
232 (type_vector_length
- old_vector_length
) * sizeof(struct type
*));
234 return &type_vector
->type
[index
];
237 /* Make sure there is a type allocated for type number index
238 and return the type object.
239 This can create an empty (zeroed) type object. */
242 coff_alloc_type (index
)
245 register struct type
**type_addr
= coff_lookup_type (index
);
246 register struct type
*type
= *type_addr
;
248 /* If we are referring to a type not known at all yet,
249 allocate an empty type for it.
250 We will fill it in later if we find out how. */
253 type
= (struct type
*) obstack_alloc (symbol_obstack
,
254 sizeof (struct type
));
255 bzero (type
, sizeof (struct type
));
261 /* maintain the lists of symbols and blocks */
263 /* Add a symbol to one of the lists of symbols. */
265 add_symbol_to_list (symbol
, listhead
)
266 struct symbol
*symbol
;
267 struct pending
**listhead
;
269 register struct pending
*link
270 = (struct pending
*) xmalloc (sizeof (struct pending
));
272 link
->next
= *listhead
;
273 link
->symbol
= symbol
;
277 /* Take one of the lists of symbols and make a block from it.
278 Put the block on the list of pending blocks. */
281 finish_block (symbol
, listhead
, old_blocks
, start
, end
)
282 struct symbol
*symbol
;
283 struct pending
**listhead
;
284 struct pending_block
*old_blocks
;
285 CORE_ADDR start
, end
;
287 register struct pending
*next
, *next1
;
288 register struct block
*block
;
289 register struct pending_block
*pblock
;
290 struct pending_block
*opblock
;
293 /* Count the length of the list of symbols. */
295 for (next
= *listhead
, i
= 0; next
; next
= next
->next
, i
++);
297 block
= (struct block
*)
298 obstack_alloc (symbol_obstack
, sizeof (struct block
) + (i
- 1) * sizeof (struct symbol
*));
300 /* Copy the symbols into the block. */
302 BLOCK_NSYMS (block
) = i
;
303 for (next
= *listhead
; next
; next
= next
->next
)
304 BLOCK_SYM (block
, --i
) = next
->symbol
;
306 BLOCK_START (block
) = start
;
307 BLOCK_END (block
) = end
;
308 BLOCK_SUPERBLOCK (block
) = 0; /* Filled in when containing block is made */
310 /* Put the block in as the value of the symbol that names it. */
314 SYMBOL_BLOCK_VALUE (symbol
) = block
;
315 BLOCK_FUNCTION (block
) = symbol
;
318 BLOCK_FUNCTION (block
) = 0;
320 /* Now free the links of the list, and empty the list. */
322 for (next
= *listhead
; next
; next
= next1
)
329 /* Install this block as the superblock
330 of all blocks made since the start of this scope
331 that don't have superblocks yet. */
334 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
336 if (BLOCK_SUPERBLOCK (pblock
->block
) == 0)
337 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
341 /* Record this block on the list of all blocks in the file.
342 Put it after opblock, or at the beginning if opblock is 0.
343 This puts the block in the list after all its subblocks. */
345 pblock
= (struct pending_block
*) xmalloc (sizeof (struct pending_block
));
346 pblock
->block
= block
;
349 pblock
->next
= opblock
->next
;
350 opblock
->next
= pblock
;
354 pblock
->next
= pending_blocks
;
355 pending_blocks
= pblock
;
359 static struct blockvector
*
362 register struct pending_block
*next
, *next1
;
363 register struct blockvector
*blockvector
;
366 /* Count the length of the list of blocks. */
368 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
370 blockvector
= (struct blockvector
*)
371 obstack_alloc (symbol_obstack
, sizeof (struct blockvector
) + (i
- 1) * sizeof (struct block
*));
373 /* Copy the blocks into the blockvector.
374 This is done in reverse order, which happens to put
375 the blocks into the proper order (ascending starting address).
376 finish_block has hair to insert each block into the list
377 after its subblocks in order to make sure this is true. */
379 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
380 for (next
= pending_blocks
; next
; next
= next
->next
)
381 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
383 /* Now free the links of the list, and empty the list. */
385 for (next
= pending_blocks
; next
; next
= next1
)
395 /* Manage the vector of line numbers. */
398 record_line (line
, pc
)
402 struct linetable_entry
*e
;
403 /* Make sure line vector is big enough. */
405 if (line_vector_index
+ 2 >= line_vector_length
)
407 line_vector_length
*= 2;
408 line_vector
= (struct linetable
*)
409 xrealloc (line_vector
, sizeof (struct linetable
)
410 + (line_vector_length
411 * sizeof (struct linetable_entry
)));
414 e
= line_vector
->item
+ line_vector_index
++;
415 e
->line
= line
; e
->pc
= pc
;
418 /* Start a new symtab for a new source file.
419 This is called when a COFF ".file" symbol is seen;
420 it indicates the start of data for one original source file. */
429 last_source_file
= 0;
435 /* Initialize the source file information for this file. */
437 line_vector_index
= 0;
438 line_vector_length
= 1000;
439 prev_line_number
= -2; /* Force first line number to be explicit */
440 line_vector
= (struct linetable
*)
441 xmalloc (sizeof (struct linetable
)
442 + line_vector_length
* sizeof (struct linetable_entry
));
445 /* Save the vital information from when starting to read a file,
446 for use when closing off the current file.
447 NAME is the file name the symbols came from, START_ADDR is the first
448 text address for the file, and SIZE is the number of bytes of text. */
451 complete_symtab (name
, start_addr
, size
)
453 CORE_ADDR start_addr
;
456 last_source_file
= savestring (name
, strlen (name
));
457 cur_src_start_addr
= start_addr
;
458 cur_src_end_addr
= start_addr
+ size
;
460 if (entry_point
< cur_src_end_addr
461 && entry_point
>= cur_src_start_addr
)
463 startup_file_start
= cur_src_start_addr
;
464 startup_file_end
= cur_src_end_addr
;
468 /* Finish the symbol definitions for one main source file,
469 close off all the lexical contexts for that file
470 (creating struct block's for them), then make the
471 struct symtab for that file and put it in the list of all such. */
476 register struct symtab
*symtab
;
477 register struct context_stack
*cstk
;
478 register struct blockvector
*blockvector
;
479 register struct linetable
*lv
;
481 /* Finish the lexical context of the last function in the file. */
485 cstk
= context_stack
;
487 /* Make a block for the local symbols within. */
488 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
489 cstk
->start_addr
, cur_src_end_addr
);
493 /* Ignore a file that has no functions with real debugging info. */
494 if (pending_blocks
== 0 && file_symbols
== 0 && global_symbols
== 0)
498 line_vector_length
= -1;
499 last_source_file
= 0;
503 /* Create the two top-level blocks for this file (STATIC_BLOCK and
505 finish_block (0, &file_symbols
, 0, cur_src_start_addr
, cur_src_end_addr
);
506 finish_block (0, &global_symbols
, 0, cur_src_start_addr
, cur_src_end_addr
);
508 /* Create the blockvector that points to all the file's blocks. */
509 blockvector
= make_blockvector ();
511 /* Now create the symtab object for this source file. */
512 symtab
= (struct symtab
*) xmalloc (sizeof (struct symtab
));
513 symtab
->free_ptr
= 0;
515 /* Fill in its components. */
516 symtab
->blockvector
= blockvector
;
517 symtab
->free_code
= free_linetable
;
518 symtab
->filename
= last_source_file
;
519 symtab
->dirname
= NULL
;
521 lv
->nitems
= line_vector_index
;
522 symtab
->linetable
= (struct linetable
*)
523 xrealloc (lv
, (sizeof (struct linetable
)
524 + lv
->nitems
* sizeof (struct linetable_entry
)));
526 symtab
->line_charpos
= 0;
528 symtab
->language
= language_unknown
;
529 symtab
->fullname
= NULL
;
532 symtab
->coffsem
= last_coffsem
;
533 symtab
->coffsyn
= last_coffsyn
;
536 free_named_symtabs (symtab
->filename
);
538 /* Link the new symtab into the list of such. */
539 symtab
->next
= symtab_list
;
540 symtab_list
= symtab
;
542 /* Reinitialize for beginning of new file. */
544 line_vector_length
= -1;
545 last_source_file
= 0;
549 record_misc_function (name
, address
)
554 /* We don't want TDESC entry points on the misc_function_vector */
555 if (name
[0] == '@') return;
557 /* mf_text isn't true, but apparently COFF doesn't tell us what it really
558 is, so this guess is more useful than mf_unknown. */
559 prim_record_misc_function (savestring (name
, strlen (name
)),
564 /* coff_symfile_init ()
565 is the coff-specific initialization routine for reading symbols.
566 It is passed a struct sym_fns which contains, among other things,
567 the BFD for the file whose symbols are being read, and a slot for
568 a pointer to "private data" which we fill with cookies and other
569 treats for coff_symfile_read ().
571 We will only be called if this is a COFF or COFF-like file.
572 BFD handles figuring out the format of the file, and code in symtab.c
573 uses BFD's determination to vector to us.
575 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
577 struct coff_symfile_info
{
578 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
579 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
583 coff_symfile_init (sf
)
586 bfd
*abfd
= sf
->sym_bfd
;
588 /* Allocate struct to keep track of the symfile */
589 /* FIXME memory leak */
590 sf
->sym_private
= xmalloc (sizeof (struct coff_symfile_info
));
593 safe_to_init_tdesc_context
= 0;
596 /* Save startup file's range of PC addresses to help blockframe.c
597 decide where the bottom of the stack is. */
598 if (bfd_get_file_flags (abfd
) & EXEC_P
)
600 /* Executable file -- record its entry point so we'll recognize
601 the startup file because it contains the entry point. */
602 entry_point
= bfd_get_start_address (abfd
);
606 /* Examination of non-executable.o files. Short-circuit this stuff. */
607 /* ~0 will not be in any file, we hope. */
609 /* set the startup file to be an empty range. */
610 startup_file_start
= 0;
611 startup_file_end
= 0;
615 /* This function is called for every section; it finds the outer limits
616 of the line table (minimum and maximum file offset) so that the
617 mainline code can read the whole thing for efficiency. */
621 find_linenos (abfd
, asect
, vpinfo
)
626 struct coff_symfile_info
*info
;
628 file_ptr offset
, maxoff
;
630 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
631 count
= asect
->lineno_count
;
636 #if !defined (LINESZ)
637 /* Just in case, you never know what to expect from those
638 COFF header files. */
639 #define LINESZ (sizeof (struct lineno))
640 #endif /* No LINESZ. */
641 size
= count
* LINESZ
;
643 info
= (struct coff_symfile_info
*)vpinfo
;
644 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
645 offset
= asect
->line_filepos
;
648 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
649 info
->min_lineno_offset
= offset
;
651 maxoff
= offset
+ size
;
652 if (maxoff
> info
->max_lineno_offset
)
653 info
->max_lineno_offset
= maxoff
;
657 /* The BFD for this file -- only good while we're actively reading
658 symbols into a psymtab or a symtab. */
660 static bfd
*symfile_bfd
;
662 /* Read a symbol file, after initialization by coff_symfile_init. */
663 /* FIXME! Addr and Mainline are not used yet -- this will not work for
664 shared libraries or add_file! */
667 coff_symfile_read (sf
, addr
, mainline
)
672 struct coff_symfile_info
*info
= (struct coff_symfile_info
*)sf
->sym_private
;
673 bfd
*abfd
= sf
->sym_bfd
;
674 char *name
= bfd_get_filename (abfd
);
679 int stringtab_offset
;
681 symfile_bfd
= abfd
; /* Kludge for swap routines */
683 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
684 desc
= fileno ((FILE *)(abfd
->iostream
)); /* File descriptor */
685 num_symbols
= bfd_get_symcount (abfd
); /* How many syms */
686 symtab_offset
= obj_sym_filepos (abfd
); /* Symbol table file offset */
687 stringtab_offset
= symtab_offset
+ num_symbols
* SYMESZ
; /* String tab */
691 debug_info
= text_hdr
.s_relptr
;
694 dc_terminate (tdesc_handle
);
699 /* Read the line number table, all at once. */
700 info
->min_lineno_offset
= 0;
701 info
->max_lineno_offset
= 0;
702 bfd_map_over_sections (abfd
, find_linenos
, info
);
704 val
= init_lineno (desc
, info
->min_lineno_offset
,
705 info
->max_lineno_offset
- info
->min_lineno_offset
);
707 error ("\"%s\": error reading line numbers\n", name
);
709 /* Now read the string table, all at once. */
711 val
= init_stringtab (desc
, stringtab_offset
);
714 free_all_symtabs (); /* FIXME blows whole symtab */
715 printf ("\"%s\": can't get string table", name
);
719 make_cleanup (free_stringtab
, 0);
721 /* Position to read the symbol table. Do not read it all at once. */
722 val
= lseek (desc
, (long)symtab_offset
, 0);
724 perror_with_name (name
);
726 init_misc_bunches ();
727 make_cleanup (discard_misc_bunches
, 0);
729 /* Now that the executable file is positioned at symbol table,
730 process it and define symbols accordingly. */
732 read_coff_symtab (desc
, num_symbols
);
734 patch_opaque_types ();
736 /* Sort symbols alphabetically within each block. */
738 sort_all_symtab_syms ();
740 /* Go over the misc symbol bunches and install them in vector. */
742 condense_misc_bunches (0);
744 /* Make a default for file to list. */
746 select_source_symtab (0); /* FIXME, this might be too slow, see dbxread */
750 coff_symfile_discard ()
752 /* There seems to be nothing to do here. */
758 /* There seems to be nothing to do except free_all_symtabs and set
759 symfile to zero, which is done by our caller. */
762 /* Simplified internal version of coff symbol table information */
766 int c_symnum
; /* symbol number of this entry */
767 int c_nsyms
; /* 1 if syment only, 2 if syment + auxent, etc */
774 /* Given pointers to a symbol table in coff style exec file,
775 analyze them and create struct symtab's describing the symbols.
776 NSYMS is the number of symbols in the symbol table.
777 We read them one at a time using read_one_sym (). */
780 read_coff_symtab (desc
, nsyms
)
784 int newfd
; /* Avoid multiple closes on same desc */
786 register struct context_stack
*new;
787 struct coff_symbol coff_symbol
;
788 register struct coff_symbol
*cs
= &coff_symbol
;
789 static SYMENT main_sym
;
790 static AUXENT main_aux
;
791 struct coff_symbol fcn_cs_saved
;
792 static SYMENT fcn_sym_saved
;
793 static AUXENT fcn_aux_saved
;
795 /* A .file is open. */
796 int in_source_file
= 0;
797 int num_object_files
= 0;
798 int next_file_symnum
= -1;
800 /* Name of the current file. */
801 char *filestring
= "";
807 struct cleanup
*old_chain
;
812 fatal ("Too many open files");
813 stream
= fdopen (newfd
, "r");
815 old_chain
= make_cleanup (free_all_symtabs
, 0);
816 make_cleanup (fclose
, stream
);
817 nlist_stream_global
= stream
;
818 nlist_nsyms_global
= nsyms
;
819 last_source_file
= 0;
820 bzero (opaque_type_chain
, sizeof opaque_type_chain
);
822 type_vector_length
= 160;
823 type_vector
= (struct typevector
*)
824 xmalloc (sizeof (struct typevector
)
825 + type_vector_length
* sizeof (struct type
*));
826 bzero (type_vector
->type
, type_vector_length
* sizeof (struct type
*));
831 while (symnum
< nsyms
)
833 QUIT
; /* Make this command interruptable. */
834 read_one_sym (cs
, &main_sym
, &main_aux
);
837 temp_sem_val
= cs
->c_name
[0] << 24 | cs
->c_name
[1] << 16 |
838 cs
->c_name
[2] << 8 | cs
->c_name
[3];
839 if (int_sem_val
== temp_sem_val
)
840 last_coffsem
= (int) strtol (cs
->c_name
+4, (char **) NULL
, 10);
843 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
845 if (last_source_file
)
849 complete_symtab ("_globals_", 0, first_object_file_end
);
850 /* done with all files, everything from here on out is globals */
853 /* Special case for file with type declarations only, no text. */
854 if (!last_source_file
&& SDB_TYPE (cs
->c_type
)
855 && cs
->c_secnum
== N_DEBUG
)
856 complete_symtab (filestring
, 0, 0);
858 /* Typedefs should not be treated as symbol definitions. */
859 if (ISFCN (cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
861 /* record as misc function. if we get '.bf' next,
862 * then we undo this step
864 record_misc_function (cs
->c_name
, cs
->c_value
);
866 fcn_line_ptr
= main_aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
867 fcn_start_addr
= cs
->c_value
;
869 fcn_sym_saved
= main_sym
;
870 fcn_aux_saved
= main_aux
;
874 switch (cs
->c_sclass
)
883 printf ("Bad n_sclass = %d\n", cs
->c_sclass
);
888 * c_value field contains symnum of next .file entry in table
889 * or symnum of first global after last .file.
891 next_file_symnum
= cs
->c_value
;
892 filestring
= getfilename (&main_aux
);
894 * Complete symbol table for last object file
895 * containing debugging information.
897 if (last_source_file
)
906 if (cs
->c_name
[0] == '.') {
907 if (strcmp (cs
->c_name
, _TEXT
) == 0) {
908 if (++num_object_files
== 1) {
909 /* last address of startup file */
910 first_object_file_end
= cs
->c_value
+
911 main_aux
.x_scn
.x_scnlen
;
913 /* Check for in_source_file deals with case of
914 a file with debugging symbols
915 followed by a later file with no symbols. */
917 complete_symtab (filestring
, cs
->c_value
,
918 main_aux
.x_scn
.x_scnlen
);
921 /* flush rest of '.' symbols */
924 else if (!SDB_TYPE (cs
->c_type
)
925 && cs
->c_name
[0] == 'L'
926 && (strncmp (cs
->c_name
, "LI%", 3) == 0
927 || strncmp (cs
->c_name
, "LF%", 3) == 0
928 || strncmp (cs
->c_name
,"LC%",3) == 0
929 || strncmp (cs
->c_name
,"LP%",3) == 0
930 || strncmp (cs
->c_name
,"LPB%",4) == 0
931 || strncmp (cs
->c_name
,"LBB%",4) == 0
932 || strncmp (cs
->c_name
,"LBE%",4) == 0
933 || strncmp (cs
->c_name
,"LPBX%",5) == 0))
934 /* At least on a 3b1, gcc generates swbeg and string labels
935 that look like this. Ignore them. */
937 /* fall in for static symbols that don't start with '.' */
939 if (cs
->c_sclass
== C_EXT
&&
940 cs
->c_secnum
== N_ABS
&&
941 strcmp (cs
->c_name
, _ETEXT
) == 0)
942 end_of_text_addr
= cs
->c_value
;
943 if (!SDB_TYPE (cs
->c_type
)) {
944 if (cs
->c_secnum
<= 1) { /* text or abs */
945 record_misc_function (cs
->c_name
, cs
->c_value
);
951 (void) process_coff_symbol (cs
, &main_aux
);
955 if (strcmp (cs
->c_name
, ".bf") == 0)
959 /* value contains address of first non-init type code */
960 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
961 contains line number of '{' } */
962 fcn_first_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
964 new = (struct context_stack
*)
965 xmalloc (sizeof (struct context_stack
));
966 new->depth
= depth
= 0;
970 new->old_blocks
= pending_blocks
;
971 new->start_addr
= fcn_start_addr
;
972 fcn_cs_saved
.c_name
= getsymname (&fcn_sym_saved
);
973 new->name
= process_coff_symbol (&fcn_cs_saved
,
976 else if (strcmp (cs
->c_name
, ".ef") == 0)
978 /* the value of .ef is the address of epilogue code;
981 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
982 contains number of lines to '}' */
986 complain (&ef_complaint
, cs
->c_symnum
);
990 fcn_last_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
991 enter_linenos (fcn_line_ptr
, fcn_first_line
, fcn_last_line
);
993 finish_block (new->name
, &local_symbols
, new->old_blocks
,
995 #if defined (FUNCTION_EPILOGUE_SIZE)
996 /* This macro should be defined only on
998 fcn_aux_saved.x_sym.x_misc.x_fsize
999 field is always zero.
1000 So use the .bf record information that
1001 points to the epilogue and add the size
1003 cs
->c_value
+ FUNCTION_EPILOGUE_SIZE
1005 fcn_cs_saved
.c_value
+
1006 fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1010 within_function
= 0;
1016 if (strcmp (cs
->c_name
, ".bb") == 0)
1018 new = (struct context_stack
*)
1019 xmalloc (sizeof (struct context_stack
));
1022 new->next
= context_stack
;
1023 context_stack
= new;
1024 new->locals
= local_symbols
;
1025 new->old_blocks
= pending_blocks
;
1026 new->start_addr
= cs
->c_value
;
1030 else if (strcmp (cs
->c_name
, ".eb") == 0)
1032 new = context_stack
;
1033 if (new == 0 || depth
!= new->depth
)
1034 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1036 if (local_symbols
&& context_stack
->next
)
1038 /* Make a block for the local symbols within. */
1039 finish_block (0, &local_symbols
, new->old_blocks
,
1040 new->start_addr
, cs
->c_value
);
1043 local_symbols
= new->locals
;
1044 context_stack
= new->next
;
1050 if (strcmp (cs
->c_name
, ".coffsyn") == 0)
1051 last_coffsyn
= cs
->c_value
;
1052 else if ((strcmp (cs
->c_name
, ".coffsem") == 0) &&
1054 last_coffsem
= cs
->c_value
;
1060 if ((strcmp (cs
->c_name
, ".coffsem") == 0) &&
1062 last_coffsem
= cs
->c_value
;
1065 (void) process_coff_symbol (cs
, &main_aux
);
1070 if (last_source_file
)
1073 discard_cleanups (old_chain
);
1076 /* Routines for reading headers and symbols from executable. */
1079 /* Move these XXXMAGIC symbol defns into BFD! */
1081 /* Read COFF file header, check magic number,
1082 and return number of symbols. */
1083 read_file_hdr (chan
, file_hdr
)
1087 lseek (chan
, 0L, 0);
1088 if (myread (chan
, (char *)file_hdr
, FILHSZ
) < 0)
1091 switch (file_hdr
->f_magic
)
1106 #if defined (MC68KWRMAGIC) \
1107 && (!defined (MC68MAGIC) || MC68KWRMAGIC != MC68MAGIC)
1121 case I960ROMAGIC
: /* Intel 960 */
1124 case I960RWMAGIC
: /* Intel 960 */
1126 return file_hdr
->f_nsyms
;
1130 if (BADMAG(file_hdr
))
1133 return file_hdr
->f_nsyms
;
1143 read_one_sym (cs
, sym
, aux
)
1144 register struct coff_symbol
*cs
;
1145 register SYMENT
*sym
;
1146 register AUXENT
*aux
;
1151 cs
->c_symnum
= symnum
;
1152 fread ((char *)sym
, SYMESZ
, 1, nlist_stream_global
);
1153 bfd_coff_swap_sym (symfile_bfd
, sym
);
1154 cs
->c_nsyms
= (sym
->n_numaux
& 0xff) + 1;
1155 if (cs
->c_nsyms
>= 2)
1157 fread ((char *)aux
, AUXESZ
, 1, nlist_stream_global
);
1158 bfd_coff_swap_aux (symfile_bfd
, aux
, sym
->n_type
, sym
->n_sclass
);
1159 /* If more than one aux entry, read past it (only the first aux
1161 for (i
= 2; i
< cs
->c_nsyms
; i
++)
1162 fread ((char *)&temp_aux
, AUXESZ
, 1, nlist_stream_global
);
1164 cs
->c_name
= getsymname (sym
);
1165 cs
->c_value
= sym
->n_value
;
1166 cs
->c_sclass
= (sym
->n_sclass
& 0xff);
1167 cs
->c_secnum
= sym
->n_scnum
;
1168 cs
->c_type
= (unsigned) sym
->n_type
;
1169 if (!SDB_TYPE (cs
->c_type
))
1172 symnum
+= cs
->c_nsyms
;
1175 /* Support for string table handling */
1177 static char *stringtab
= NULL
;
1180 init_stringtab (chan
, offset
)
1186 unsigned char lengthbuf
[4];
1194 if (lseek (chan
, offset
, 0) < 0)
1197 val
= myread (chan
, (char *)lengthbuf
, sizeof lengthbuf
);
1198 length
= bfd_h_getlong (symfile_bfd
, lengthbuf
);
1200 /* If no string table is needed, then the file may end immediately
1201 after the symbols. Just return with `stringtab' set to null. */
1202 if (val
!= sizeof length
|| length
< sizeof length
)
1205 stringtab
= (char *) xmalloc (length
);
1206 if (stringtab
== NULL
)
1209 bcopy (&length
, stringtab
, sizeof length
);
1210 if (length
== sizeof length
) /* Empty table -- just the count */
1213 val
= myread (chan
, stringtab
+ sizeof length
, length
- sizeof length
);
1214 if (val
!= length
- sizeof length
|| stringtab
[length
- 1] != '\0')
1229 getsymname (symbol_entry
)
1230 SYMENT
*symbol_entry
;
1232 static char buffer
[SYMNMLEN
+1];
1235 if (symbol_entry
->n_zeroes
== 0)
1237 result
= stringtab
+ symbol_entry
->n_offset
;
1241 strncpy (buffer
, symbol_entry
->n_name
, SYMNMLEN
);
1242 buffer
[SYMNMLEN
] = '\0';
1249 getfilename (aux_entry
)
1252 static char buffer
[BUFSIZ
];
1253 register char *temp
;
1255 extern char *rindex ();
1257 #ifndef COFF_NO_LONG_FILE_NAMES
1258 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1259 strcpy (buffer
, stringtab
+ aux_entry
->x_file
.x_n
.x_offset
);
1261 #endif /* COFF_NO_LONG_FILE_NAMES */
1263 #if defined (x_name)
1265 strncpy (buffer
, aux_entry
->x_name
, FILNMLEN
);
1267 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1269 buffer
[FILNMLEN
] = '\0';
1272 if ((temp
= rindex (result
, '/')) != NULL
)
1277 /* Support for line number handling */
1278 static char *linetab
= NULL
;
1279 static long linetab_offset
;
1280 static unsigned long linetab_size
;
1282 /* Read in all the line numbers for fast lookups later. */
1285 init_lineno (chan
, offset
, size
)
1291 register char *p
, *q
;
1293 if (lseek (chan
, offset
, 0) < 0)
1296 linetab
= (char *) xmalloc (size
);
1298 val
= myread (chan
, linetab
, size
);
1302 /* Swap all entries */
1304 for (p
= linetab
; p
< q
; p
+= LINESZ
)
1305 bfd_coff_swap_lineno (symfile_bfd
, (LINENO
*)p
);
1307 linetab_offset
= offset
;
1308 linetab_size
= size
;
1309 make_cleanup (free
, linetab
); /* Be sure it gets de-allocated. */
1313 #if !defined (L_LNNO32)
1314 #define L_LNNO32(lp) ((lp)->l_lnno)
1318 enter_linenos (file_offset
, first_line
, last_line
)
1320 register int first_line
;
1321 register int last_line
;
1323 register char *rawptr
;
1326 if (file_offset
< linetab_offset
)
1328 complain (lineno_complaint
, file_offset
);
1329 if (file_offset
> linetab_size
) /* Too big to be an offset? */
1331 file_offset
+= linetab_offset
; /* Try reading at that linetab offset */
1334 rawptr
= &linetab
[file_offset
- linetab_offset
];
1336 /* skip first line entry for each function */
1338 /* line numbers start at one for the first line of the function */
1341 /* Bcopy since occaisionally rawptr isn't pointing at long
1343 for (bcopy (rawptr
, &lptr
, LINESZ
);
1344 L_LNNO32 (&lptr
) && L_LNNO32 (&lptr
) <= last_line
;
1345 rawptr
+= LINESZ
, bcopy (rawptr
, &lptr
, LINESZ
))
1347 record_line (first_line
+ L_LNNO32 (&lptr
), lptr
.l_addr
.l_paddr
);
1355 register char *p
= name
;
1356 register int total
= p
[0];
1369 return total
% HASHSIZE
;
1373 patch_type (type
, real_type
)
1375 struct type
*real_type
;
1377 register struct type
*target
= TYPE_TARGET_TYPE (type
);
1378 register struct type
*real_target
= TYPE_TARGET_TYPE (real_type
);
1379 int field_size
= TYPE_NFIELDS (real_target
) * sizeof (struct field
);
1381 TYPE_LENGTH (target
) = TYPE_LENGTH (real_target
);
1382 TYPE_NFIELDS (target
) = TYPE_NFIELDS (real_target
);
1383 TYPE_FIELDS (target
) = (struct field
*)
1384 obstack_alloc (symbol_obstack
, field_size
);
1386 bcopy (TYPE_FIELDS (real_target
), TYPE_FIELDS (target
), field_size
);
1388 if (TYPE_NAME (real_target
))
1390 if (TYPE_NAME (target
))
1391 free (TYPE_NAME (target
));
1392 TYPE_NAME (target
) = concat (TYPE_NAME (real_target
), "", "");
1396 /* Patch up all appropriate typdef symbols in the opaque_type_chains
1397 so that they can be used to print out opaque data structures properly */
1400 patch_opaque_types ()
1404 /* Look at each symbol in the per-file block of each symtab. */
1405 for (s
= symtab_list
; s
; s
= s
->next
)
1407 register struct block
*b
;
1410 /* Go through the per-file symbols only */
1411 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
1412 for (i
= BLOCK_NSYMS (b
) - 1; i
>= 0; i
--)
1414 register struct symbol
*real_sym
;
1416 /* Find completed typedefs to use to fix opaque ones.
1417 Remove syms from the chain when their types are stored,
1418 but search the whole chain, as there may be several syms
1419 from different files with the same name. */
1420 real_sym
= BLOCK_SYM (b
, i
);
1421 if (SYMBOL_CLASS (real_sym
) == LOC_TYPEDEF
&&
1422 SYMBOL_NAMESPACE (real_sym
) == VAR_NAMESPACE
&&
1423 TYPE_CODE (SYMBOL_TYPE (real_sym
)) == TYPE_CODE_PTR
&&
1424 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym
))) != 0)
1426 register char *name
= SYMBOL_NAME (real_sym
);
1427 register int hash
= hashname (name
);
1428 register struct symbol
*sym
, *prev
;
1431 for (sym
= opaque_type_chain
[hash
]; sym
;)
1433 if (name
[0] == SYMBOL_NAME (sym
)[0] &&
1434 !strcmp (name
+ 1, SYMBOL_NAME (sym
) + 1))
1437 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
1439 opaque_type_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
1441 patch_type (SYMBOL_TYPE (sym
), SYMBOL_TYPE (real_sym
));
1444 sym
= SYMBOL_VALUE_CHAIN (prev
);
1446 sym
= opaque_type_chain
[hash
];
1451 sym
= SYMBOL_VALUE_CHAIN (sym
);
1459 #if defined (clipper)
1460 #define BELIEVE_PCC_PROMOTION 1
1463 static struct symbol
*
1464 process_coff_symbol (cs
, aux
)
1465 register struct coff_symbol
*cs
;
1466 register AUXENT
*aux
;
1468 register struct symbol
*sym
1469 = (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
1471 #ifdef NAMES_HAVE_UNDERSCORE
1477 bzero (sym
, sizeof (struct symbol
));
1479 name
= (name
[0] == '_' ? name
+ offset
: name
);
1480 SYMBOL_NAME (sym
) = obstack_copy0 (symbol_obstack
, name
, strlen (name
));
1482 /* default assumptions */
1483 SYMBOL_VALUE (sym
) = cs
->c_value
;
1484 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1486 if (ISFCN (cs
->c_type
))
1489 lookup_function_type (decode_function_type (cs
, cs
->c_type
, aux
));
1490 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1491 if (cs
->c_sclass
== C_STAT
)
1492 add_symbol_to_list (sym
, &file_symbols
);
1493 else if (cs
->c_sclass
== C_EXT
)
1494 add_symbol_to_list (sym
, &global_symbols
);
1498 SYMBOL_TYPE (sym
) = decode_type (cs
, cs
->c_type
, aux
);
1499 switch (cs
->c_sclass
)
1505 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1506 add_symbol_to_list (sym
, &local_symbols
);
1510 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1511 SYMBOL_VALUE_ADDRESS (sym
) = (CORE_ADDR
) cs
->c_value
;
1512 add_symbol_to_list (sym
, &global_symbols
);
1516 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1517 SYMBOL_VALUE_ADDRESS (sym
) = (CORE_ADDR
) cs
->c_value
;
1518 if (within_function
) {
1519 /* Static symbol of local scope */
1520 add_symbol_to_list (sym
, &local_symbols
);
1523 /* Static symbol at top level of file */
1524 add_symbol_to_list (sym
, &file_symbols
);
1529 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1530 add_symbol_to_list (sym
, &local_symbols
);
1537 SYMBOL_CLASS (sym
) = LOC_ARG
;
1538 add_symbol_to_list (sym
, &local_symbols
);
1539 #if !defined (BELIEVE_PCC_PROMOTION)
1540 /* If PCC says a parameter is a short or a char,
1541 it is really an int. */
1542 if (SYMBOL_TYPE (sym
) == builtin_type_char
1543 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1544 SYMBOL_TYPE (sym
) = builtin_type_int
;
1545 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1546 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1547 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1552 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1553 add_symbol_to_list (sym
, &local_symbols
);
1554 #if !defined (BELIEVE_PCC_PROMOTION)
1555 /* If PCC says a parameter is a short or a char,
1556 it is really an int. */
1557 if (SYMBOL_TYPE (sym
) == builtin_type_char
1558 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1559 SYMBOL_TYPE (sym
) = builtin_type_int
;
1560 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1561 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1562 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1567 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1568 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1570 /* If type has no name, give it one */
1571 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1572 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1573 TYPE_NAME (SYMBOL_TYPE (sym
))
1574 = concat (SYMBOL_NAME (sym
), "", "");
1576 /* Keep track of any type which points to empty structured type,
1577 so it can be filled from a definition from another file */
1578 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
&&
1579 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym
))) == 0)
1581 register int i
= hashname (SYMBOL_NAME (sym
));
1583 SYMBOL_VALUE_CHAIN (sym
) = opaque_type_chain
[i
];
1584 opaque_type_chain
[i
] = sym
;
1586 add_symbol_to_list (sym
, &file_symbols
);
1592 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1593 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1594 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1595 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1596 TYPE_NAME (SYMBOL_TYPE (sym
))
1598 (cs
->c_sclass
== C_ENTAG
1600 : (cs
->c_sclass
== C_STRTAG
1601 ? "struct " : "union ")),
1603 add_symbol_to_list (sym
, &file_symbols
);
1613 /* Decode a coff type specifier;
1614 return the type that is meant. */
1618 decode_type (cs
, c_type
, aux
)
1619 register struct coff_symbol
*cs
;
1620 unsigned int c_type
;
1621 register AUXENT
*aux
;
1623 register struct type
*type
= 0;
1624 unsigned int new_c_type
;
1626 if (c_type
& ~N_BTMASK
)
1628 new_c_type
= DECREF (c_type
);
1631 type
= decode_type (cs
, new_c_type
, aux
);
1632 type
= lookup_pointer_type (type
);
1634 else if (ISFCN (c_type
))
1636 type
= decode_type (cs
, new_c_type
, aux
);
1637 type
= lookup_function_type (type
);
1639 else if (ISARY (c_type
))
1642 register unsigned short *dim
;
1643 struct type
*base_type
;
1645 /* Define an array type. */
1646 /* auxent refers to array, not base type */
1647 if (aux
->x_sym
.x_tagndx
== 0)
1650 /* shift the indices down */
1651 dim
= &aux
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0];
1654 for (i
= 0; *dim
&& i
< DIMNUM
- 1; i
++, dim
++)
1658 type
= (struct type
*)
1659 obstack_alloc (symbol_obstack
, sizeof (struct type
));
1660 bzero (type
, sizeof (struct type
));
1662 base_type
= decode_type (cs
, new_c_type
, aux
);
1664 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
1665 TYPE_TARGET_TYPE (type
) = base_type
;
1666 TYPE_LENGTH (type
) = n
* TYPE_LENGTH (base_type
);
1671 /* Reference to existing type */
1672 if (cs
->c_nsyms
> 1 && aux
->x_sym
.x_tagndx
!= 0)
1674 type
= coff_alloc_type (aux
->x_sym
.x_tagndx
);
1678 return decode_base_type (cs
, BTYPE (c_type
), aux
);
1681 /* Decode a coff type specifier for function definition;
1682 return the type that the function returns. */
1686 decode_function_type (cs
, c_type
, aux
)
1687 register struct coff_symbol
*cs
;
1688 unsigned int c_type
;
1689 register AUXENT
*aux
;
1691 if (aux
->x_sym
.x_tagndx
== 0)
1692 cs
->c_nsyms
= 1; /* auxent refers to function, not base type */
1694 return decode_type (cs
, DECREF (c_type
), aux
);
1701 decode_base_type (cs
, c_type
, aux
)
1702 register struct coff_symbol
*cs
;
1703 unsigned int c_type
;
1704 register AUXENT
*aux
;
1711 /* shows up with "void (*foo)();" structure members */
1712 return builtin_type_void
;
1716 /* Shows up in DGUX, I think. Not sure where. */
1717 return builtin_type_void
; /* shouldn't show up here */
1722 /* Intel 960 COFF has this symbol and meaning. */
1723 return builtin_type_void
;
1727 return builtin_type_char
;
1730 return builtin_type_short
;
1733 return builtin_type_int
;
1736 return builtin_type_long
;
1739 return builtin_type_float
;
1742 return builtin_type_double
;
1745 if (cs
->c_nsyms
!= 2)
1747 /* anonymous structure type */
1748 type
= coff_alloc_type (cs
->c_symnum
);
1749 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1750 TYPE_NAME (type
) = concat ("struct ", "<opaque>", "");
1751 TYPE_LENGTH (type
) = 0;
1752 TYPE_FIELDS (type
) = 0;
1753 TYPE_NFIELDS (type
) = 0;
1757 type
= read_struct_type (cs
->c_symnum
,
1758 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1759 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1764 if (cs
->c_nsyms
!= 2)
1766 /* anonymous union type */
1767 type
= coff_alloc_type (cs
->c_symnum
);
1768 TYPE_NAME (type
) = concat ("union ", "<opaque>", "");
1769 TYPE_LENGTH (type
) = 0;
1770 TYPE_FIELDS (type
) = 0;
1771 TYPE_NFIELDS (type
) = 0;
1775 type
= read_struct_type (cs
->c_symnum
,
1776 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1777 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1779 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1783 return read_enum_type (cs
->c_symnum
,
1784 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1785 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1788 /* shouldn't show up here */
1792 return builtin_type_unsigned_char
;
1795 return builtin_type_unsigned_short
;
1798 return builtin_type_unsigned_int
;
1801 return builtin_type_unsigned_long
;
1803 printf ("unexpected type %d at symnum %d\n", c_type
, cs
->c_symnum
);
1804 return builtin_type_void
;
1807 /* This page contains subroutines of read_type. */
1809 /* Read the description of a structure (or union type)
1810 and return an object describing the type. */
1812 static struct type
*
1813 read_struct_type (index
, length
, lastsym
)
1820 struct nextfield
*next
;
1824 register struct type
*type
;
1825 register struct nextfield
*list
= 0;
1826 struct nextfield
*new;
1830 #ifdef NAMES_HAVE_UNDERSCORE
1835 struct coff_symbol member_sym
;
1836 register struct coff_symbol
*ms
= &member_sym
;
1841 type
= coff_alloc_type (index
);
1842 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1843 TYPE_LENGTH (type
) = length
;
1845 while (!done
&& symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
1847 read_one_sym (ms
, &sub_sym
, &sub_aux
);
1849 name
= (name
[0] == '_' ? name
+ offset
: name
);
1851 switch (ms
->c_sclass
)
1856 /* Get space to record the next field's data. */
1857 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1861 /* Save the data. */
1862 list
->field
.name
= savestring (name
, strlen (name
));
1863 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1864 list
->field
.bitpos
= 8 * ms
->c_value
;
1865 list
->field
.bitsize
= 0;
1871 /* Get space to record the next field's data. */
1872 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1876 /* Save the data. */
1877 list
->field
.name
= savestring (name
, strlen (name
));
1878 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1879 list
->field
.bitpos
= ms
->c_value
;
1880 list
->field
.bitsize
= sub_aux
.x_sym
.x_misc
.x_lnsz
.x_size
;
1889 /* Now create the vector of fields, and record how big it is. */
1891 TYPE_NFIELDS (type
) = nfields
;
1892 TYPE_FIELDS (type
) = (struct field
*)
1893 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nfields
);
1895 /* Copy the saved-up fields into the field vector. */
1897 for (n
= nfields
; list
; list
= list
->next
)
1898 TYPE_FIELD (type
, --n
) = list
->field
;
1903 /* Read a definition of an enumeration type,
1904 and create and return a suitable type object.
1905 Also defines the symbols that represent the values of the type. */
1906 /* Currently assumes it's sizeof (int) and doesn't use length. */
1908 static struct type
*
1909 read_enum_type (index
, length
, lastsym
)
1914 register struct symbol
*sym
;
1915 register struct type
*type
;
1918 struct pending
**symlist
;
1919 struct coff_symbol member_sym
;
1920 register struct coff_symbol
*ms
= &member_sym
;
1923 struct pending
*osyms
, *syms
;
1926 #ifdef NAMES_HAVE_UNDERSCORE
1932 type
= coff_alloc_type (index
);
1933 if (within_function
)
1934 symlist
= &local_symbols
;
1936 symlist
= &file_symbols
;
1939 while (!done
&& symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
1941 read_one_sym (ms
, &sub_sym
, &sub_aux
);
1943 name
= (name
[0] == '_' ? name
+ offset
: name
);
1945 switch (ms
->c_sclass
)
1948 sym
= (struct symbol
*) xmalloc (sizeof (struct symbol
));
1949 bzero (sym
, sizeof (struct symbol
));
1951 SYMBOL_NAME (sym
) = savestring (name
, strlen (name
));
1952 SYMBOL_CLASS (sym
) = LOC_CONST
;
1953 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1954 SYMBOL_VALUE (sym
) = ms
->c_value
;
1955 add_symbol_to_list (sym
, symlist
);
1960 /* Sometimes the linker (on 386/ix 2.0.2 at least) screws
1961 up the count of how many symbols to read. So stop
1968 /* Now fill in the fields of the type-structure. */
1970 /* FIXME: Should be sizeof (int) on target, not host. */
1971 TYPE_LENGTH (type
) = sizeof (int);
1972 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
1973 TYPE_NFIELDS (type
) = nsyms
;
1974 TYPE_FIELDS (type
) = (struct field
*)
1975 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nsyms
);
1977 /* Find the symbols for the values and put them into the type.
1978 The symbols can be found in the symlist that we put them on
1979 to cause them to be defined. osyms contains the old value
1980 of that symlist; everything up to there was defined by us. */
1982 for (syms
= *symlist
, n
= nsyms
; syms
!= osyms
; syms
= syms
->next
)
1984 SYMBOL_TYPE (syms
->symbol
) = type
;
1985 TYPE_FIELD_NAME (type
, --n
) = SYMBOL_NAME (syms
->symbol
);
1986 TYPE_FIELD_VALUE (type
, n
) = 0;
1987 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (syms
->symbol
);
1988 TYPE_FIELD_BITSIZE (type
, n
) = 0;
1993 /* Register our ability to parse symbols for coff BFD files */
1995 static struct sym_fns coff_sym_fns
=
1998 coff_new_init
, coff_symfile_init
,
1999 coff_symfile_read
, coff_symfile_discard
2003 _initialize_coffread ()
2005 add_symtab_fns(&coff_sym_fns
);