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"
29 #include "libcoff.h" /* FIXME secret internal data from BFD */
32 #include <intel-coff.h>
36 static void add_symbol_to_list ();
37 static void read_coff_symtab ();
38 static void patch_opaque_types ();
39 static struct type
*decode_function_type ();
40 static struct type
*decode_type ();
41 static struct type
*decode_base_type ();
42 static struct type
*read_enum_type ();
43 static struct type
*read_struct_type ();
44 static void finish_block ();
45 static struct blockvector
*make_blockvector ();
46 static struct symbol
*process_coff_symbol ();
47 static int init_stringtab ();
48 static void free_stringtab ();
49 static char *getfilename ();
50 static char *getsymname ();
51 static int init_lineno ();
52 static void enter_linenos ();
53 static void read_one_sym ();
56 extern void free_all_symtabs ();
57 extern void free_all_psymtabs ();
59 /* external routines from the BFD library -- undocumented interface used
60 by GDB to read symbols. Move to libcoff.h. FIXME-SOMEDAY! */
61 extern void bfd_coff_swap_sym (/* symfile_bfd, &sym */);
62 extern void bfd_coff_swap_aux (/* symfile_bfd, &aux, type, sclass */);
63 extern void bfd_coff_swap_lineno (/* symfile_bfd, &lineno */);
66 /* Name of source file whose symbol data we are now processing.
67 This comes from a symbol named ".file". */
69 static char *last_source_file
;
71 /* Core address of start and end of text of current source file.
72 This comes from a ".text" symbol where x_nlinno > 0. */
74 static CORE_ADDR cur_src_start_addr
;
75 static CORE_ADDR cur_src_end_addr
;
77 /* Core address of the end of the first object file. */
78 static CORE_ADDR first_object_file_end
;
80 /* End of the text segment of the executable file,
81 as found in the symbol _etext. */
83 static CORE_ADDR end_of_text_addr
;
85 /* The addresses of the symbol table stream and number of symbols
86 of the object file we are reading (as copied into core). */
88 static FILE *nlist_stream_global
;
89 static int nlist_nsyms_global
;
91 /* The entry point (starting address) of the file, if it is an executable. */
93 static CORE_ADDR entry_point
;
95 /* The index in the symbol table of the last coff symbol that was processed. */
99 /* Vector of types defined so far, indexed by their coff symnum. */
101 static struct typevector
*type_vector
;
103 /* Number of elements allocated for type_vector currently. */
105 static int type_vector_length
;
107 /* Vector of line number information. */
109 static struct linetable
*line_vector
;
111 /* Index of next entry to go in line_vector_index. */
113 static int line_vector_index
;
115 /* Last line number recorded in the line vector. */
117 static int prev_line_number
;
119 /* Number of elements allocated for line_vector currently. */
121 static int line_vector_length
;
125 int int_sem_val
= 's' << 24 | 'e' << 16 | 'm' << 8 | '.';
127 int last_coffsem
= 2;
128 int last_coffsyn
= 0;
129 int debug_info
= 0; /*used by tdesc */
130 extern int tdesc_handle
;
131 extern int safe_to_init_tdesc_context
;
134 /* Chain of typedefs of pointers to empty struct/union types.
135 They are chained thru the SYMBOL_VALUE_CHAIN. */
138 static struct symbol
*opaque_type_chain
[HASHSIZE
];
140 /* Record the symbols defined for each context in a list.
141 We don't create a struct block for the context until we
142 know how long to make it. */
146 struct pending
*next
;
147 struct symbol
*symbol
;
150 /* Here are the three lists that symbols are put on. */
152 struct pending
*file_symbols
; /* static at top level, and types */
154 struct pending
*global_symbols
; /* global functions and variables */
156 struct pending
*local_symbols
; /* everything local to lexical context */
158 /* List of unclosed lexical contexts
159 (that will become blocks, eventually). */
163 struct context_stack
*next
;
164 struct pending
*locals
;
165 struct pending_block
*old_blocks
;
167 CORE_ADDR start_addr
;
171 struct context_stack
*context_stack
;
173 /* Nonzero if within a function (so symbols should be local,
174 if nothing says specifically). */
178 /* List of blocks already made (lexical contexts already closed).
179 This is used at the end to make the blockvector. */
183 struct pending_block
*next
;
187 struct pending_block
*pending_blocks
;
189 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
190 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
192 /* Complaints about various problems in the file being read */
194 struct complaint ef_complaint
=
195 {"Unmatched .ef symbol(s) ignored starting at symnum %d", 0, 0};
198 /* Look up a coff type-number index. Return the address of the slot
199 where the type for that index is stored.
200 The type-number is in INDEX.
202 This can be used for finding the type associated with that index
203 or for associating a new type with the index. */
205 static struct type
**
206 coff_lookup_type (index
)
209 if (index
>= type_vector_length
)
211 int old_vector_length
= type_vector_length
;
213 type_vector_length
*= 2;
214 if (type_vector_length
< index
) {
215 type_vector_length
= index
* 2;
217 type_vector
= (struct typevector
*)
218 xrealloc (type_vector
, sizeof (struct typevector
)
219 + type_vector_length
* sizeof (struct type
*));
220 bzero (&type_vector
->type
[ old_vector_length
],
221 (type_vector_length
- old_vector_length
) * sizeof(struct type
*));
223 return &type_vector
->type
[index
];
226 /* Make sure there is a type allocated for type number index
227 and return the type object.
228 This can create an empty (zeroed) type object. */
231 coff_alloc_type (index
)
234 register struct type
**type_addr
= coff_lookup_type (index
);
235 register struct type
*type
= *type_addr
;
237 /* If we are referring to a type not known at all yet,
238 allocate an empty type for it.
239 We will fill it in later if we find out how. */
242 type
= (struct type
*) obstack_alloc (symbol_obstack
,
243 sizeof (struct type
));
244 bzero (type
, sizeof (struct type
));
250 /* maintain the lists of symbols and blocks */
252 /* Add a symbol to one of the lists of symbols. */
254 add_symbol_to_list (symbol
, listhead
)
255 struct symbol
*symbol
;
256 struct pending
**listhead
;
258 register struct pending
*link
259 = (struct pending
*) xmalloc (sizeof (struct pending
));
261 link
->next
= *listhead
;
262 link
->symbol
= symbol
;
266 /* Take one of the lists of symbols and make a block from it.
267 Put the block on the list of pending blocks. */
270 finish_block (symbol
, listhead
, old_blocks
, start
, end
)
271 struct symbol
*symbol
;
272 struct pending
**listhead
;
273 struct pending_block
*old_blocks
;
274 CORE_ADDR start
, end
;
276 register struct pending
*next
, *next1
;
277 register struct block
*block
;
278 register struct pending_block
*pblock
;
279 struct pending_block
*opblock
;
282 /* Count the length of the list of symbols. */
284 for (next
= *listhead
, i
= 0; next
; next
= next
->next
, i
++);
286 block
= (struct block
*)
287 obstack_alloc (symbol_obstack
, sizeof (struct block
) + (i
- 1) * sizeof (struct symbol
*));
289 /* Copy the symbols into the block. */
291 BLOCK_NSYMS (block
) = i
;
292 for (next
= *listhead
; next
; next
= next
->next
)
293 BLOCK_SYM (block
, --i
) = next
->symbol
;
295 BLOCK_START (block
) = start
;
296 BLOCK_END (block
) = end
;
297 BLOCK_SUPERBLOCK (block
) = 0; /* Filled in when containing block is made */
299 /* Put the block in as the value of the symbol that names it. */
303 SYMBOL_BLOCK_VALUE (symbol
) = block
;
304 BLOCK_FUNCTION (block
) = symbol
;
307 BLOCK_FUNCTION (block
) = 0;
309 /* Now free the links of the list, and empty the list. */
311 for (next
= *listhead
; next
; next
= next1
)
318 /* Install this block as the superblock
319 of all blocks made since the start of this scope
320 that don't have superblocks yet. */
323 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
325 if (BLOCK_SUPERBLOCK (pblock
->block
) == 0)
326 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
330 /* Record this block on the list of all blocks in the file.
331 Put it after opblock, or at the beginning if opblock is 0.
332 This puts the block in the list after all its subblocks. */
334 pblock
= (struct pending_block
*) xmalloc (sizeof (struct pending_block
));
335 pblock
->block
= block
;
338 pblock
->next
= opblock
->next
;
339 opblock
->next
= pblock
;
343 pblock
->next
= pending_blocks
;
344 pending_blocks
= pblock
;
348 static struct blockvector
*
351 register struct pending_block
*next
, *next1
;
352 register struct blockvector
*blockvector
;
355 /* Count the length of the list of blocks. */
357 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
359 blockvector
= (struct blockvector
*)
360 obstack_alloc (symbol_obstack
, sizeof (struct blockvector
) + (i
- 1) * sizeof (struct block
*));
362 /* Copy the blocks into the blockvector.
363 This is done in reverse order, which happens to put
364 the blocks into the proper order (ascending starting address).
365 finish_block has hair to insert each block into the list
366 after its subblocks in order to make sure this is true. */
368 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
369 for (next
= pending_blocks
; next
; next
= next
->next
)
370 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
372 /* Now free the links of the list, and empty the list. */
374 for (next
= pending_blocks
; next
; next
= next1
)
384 /* Manage the vector of line numbers. */
387 record_line (line
, pc
)
391 struct linetable_entry
*e
;
392 /* Make sure line vector is big enough. */
394 if (line_vector_index
+ 2 >= line_vector_length
)
396 line_vector_length
*= 2;
397 line_vector
= (struct linetable
*)
398 xrealloc (line_vector
, sizeof (struct linetable
)
399 + (line_vector_length
400 * sizeof (struct linetable_entry
)));
403 e
= line_vector
->item
+ line_vector_index
++;
404 e
->line
= line
; e
->pc
= pc
;
407 /* Start a new symtab for a new source file.
408 This is called when a COFF ".file" symbol is seen;
409 it indicates the start of data for one original source file. */
418 last_source_file
= 0;
424 /* Initialize the source file information for this file. */
426 line_vector_index
= 0;
427 line_vector_length
= 1000;
428 prev_line_number
= -2; /* Force first line number to be explicit */
429 line_vector
= (struct linetable
*)
430 xmalloc (sizeof (struct linetable
)
431 + line_vector_length
* sizeof (struct linetable_entry
));
434 /* Save the vital information from when starting to read a file,
435 for use when closing off the current file.
436 NAME is the file name the symbols came from, START_ADDR is the first
437 text address for the file, and SIZE is the number of bytes of text. */
440 complete_symtab (name
, start_addr
, size
)
442 CORE_ADDR start_addr
;
445 last_source_file
= savestring (name
, strlen (name
));
446 cur_src_start_addr
= start_addr
;
447 cur_src_end_addr
= start_addr
+ size
;
449 if (entry_point
< cur_src_end_addr
450 && entry_point
>= cur_src_start_addr
)
452 startup_file_start
= cur_src_start_addr
;
453 startup_file_end
= cur_src_end_addr
;
457 /* Finish the symbol definitions for one main source file,
458 close off all the lexical contexts for that file
459 (creating struct block's for them), then make the
460 struct symtab for that file and put it in the list of all such. */
465 register struct symtab
*symtab
;
466 register struct context_stack
*cstk
;
467 register struct blockvector
*blockvector
;
468 register struct linetable
*lv
;
470 /* Finish the lexical context of the last function in the file. */
474 cstk
= context_stack
;
476 /* Make a block for the local symbols within. */
477 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
478 cstk
->start_addr
, cur_src_end_addr
);
482 /* Ignore a file that has no functions with real debugging info. */
483 if (pending_blocks
== 0 && file_symbols
== 0 && global_symbols
== 0)
487 line_vector_length
= -1;
488 last_source_file
= 0;
492 /* Create the two top-level blocks for this file. */
493 finish_block (0, &file_symbols
, 0, cur_src_start_addr
, cur_src_end_addr
);
494 finish_block (0, &global_symbols
, 0, cur_src_start_addr
, cur_src_end_addr
);
496 /* Create the blockvector that points to all the file's blocks. */
497 blockvector
= make_blockvector ();
499 /* Now create the symtab object for this source file. */
500 symtab
= (struct symtab
*) xmalloc (sizeof (struct symtab
));
501 symtab
->free_ptr
= 0;
503 /* Fill in its components. */
504 symtab
->blockvector
= blockvector
;
505 symtab
->free_code
= free_linetable
;
506 symtab
->filename
= last_source_file
;
508 lv
->nitems
= line_vector_index
;
509 symtab
->linetable
= (struct linetable
*)
510 xrealloc (lv
, (sizeof (struct linetable
)
511 + lv
->nitems
* sizeof (struct linetable_entry
)));
513 symtab
->line_charpos
= 0;
516 symtab
->coffsem
= last_coffsem
;
517 symtab
->coffsyn
= last_coffsyn
;
520 /* Link the new symtab into the list of such. */
521 symtab
->next
= symtab_list
;
522 symtab_list
= symtab
;
524 /* Reinitialize for beginning of new file. */
526 line_vector_length
= -1;
527 last_source_file
= 0;
531 record_misc_function (name
, address
)
536 /* We don't want TDESC entry points on the misc_function_vector */
537 if (name
[0] == '@') return;
539 /* mf_text isn't true, but apparently COFF doesn't tell us what it really
540 is, so this guess is more useful than mf_unknown. */
541 prim_record_misc_function (savestring (name
, strlen (name
)),
546 /* coff_symfile_init ()
547 is the coff-specific initialization routine for reading symbols.
548 It is passed a struct sym_fns which contains, among other things,
549 the BFD for the file whose symbols are being read, and a slot for
550 a pointer to "private data" which we fill with cookies and other
551 treats for coff_symfile_read ().
553 We will only be called if this is a COFF or COFF-like file.
554 BFD handles figuring out the format of the file, and code in symtab.c
555 uses BFD's determination to vector to us.
557 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
559 struct coff_symfile_info
{
560 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
561 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
565 coff_symfile_init (sf
)
568 bfd
*abfd
= sf
->sym_bfd
;
570 /* Allocate struct to keep track of the symfile */
571 /* FIXME memory leak */
572 sf
->sym_private
= xmalloc (sizeof (struct coff_symfile_info
));
575 safe_to_init_tdesc_context
= 0;
578 /* Save startup file's range of PC addresses to help blockframe.c
579 decide where the bottom of the stack is. */
580 if (bfd_get_file_flags (abfd
) & EXEC_P
)
582 /* Executable file -- record its entry point so we'll recognize
583 the startup file because it contains the entry point. */
584 entry_point
= bfd_get_start_address (abfd
);
588 /* Examination of non-executable.o files. Short-circuit this stuff. */
589 /* ~0 will not be in any file, we hope. */
591 /* set the startup file to be an empty range. */
592 startup_file_start
= 0;
593 startup_file_end
= 0;
597 /* This function is called for every section; it finds the outer limits
598 of the line table (minimum and maximum file offset) so that the
599 mainline code can read the whole thing for efficiency. */
602 find_linenos (abfd
, asect
, vpinfo
)
607 struct coff_symfile_info
*info
;
609 file_ptr offset
, maxoff
;
611 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
612 count
= asect
->lineno_count
;
617 size
= count
* sizeof (struct lineno
);
619 info
= (struct coff_symfile_info
*)vpinfo
;
620 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
621 offset
= asect
->line_filepos
;
624 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
625 info
->min_lineno_offset
= offset
;
627 maxoff
= offset
+ size
;
628 if (maxoff
> info
->max_lineno_offset
)
629 info
->max_lineno_offset
= maxoff
;
633 /* Read a symbol file, after initialization by coff_symfile_init. */
634 /* FIXME! Addr and Mainline are not used yet -- this will not work for
635 shared libraries or add_file! */
638 coff_symfile_read (sf
, addr
, mainline
)
643 struct coff_symfile_info
*info
= (struct coff_symfile_info
*)sf
->sym_private
;
644 bfd
*abfd
= sf
->sym_bfd
;
645 char *name
= bfd_get_filename (abfd
);
650 int stringtab_offset
;
652 symfile_bfd
= abfd
; /* Kludge for swap routines */
654 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
655 desc
= fileno ((FILE *)(abfd
->iostream
)); /* File descriptor */
656 num_symbols
= bfd_get_symcount (abfd
); /* How many syms */
657 symtab_offset
= obj_sym_filepos (abfd
); /* Symbol table file offset */
658 stringtab_offset
= symtab_offset
+ num_symbols
* SYMESZ
; /* String tab */
662 debug_info
= text_hdr
.s_relptr
;
665 dc_terminate (tdesc_handle
);
670 /* Read the line number table, all at once. */
671 info
->min_lineno_offset
= 0;
672 info
->max_lineno_offset
= 0;
673 bfd_map_over_sections (abfd
, find_linenos
, info
);
675 val
= init_lineno (desc
, info
->min_lineno_offset
,
676 info
->max_lineno_offset
- info
->min_lineno_offset
);
678 error ("\"%s\": error reading line numbers\n", name
);
680 /* Now read the string table, all at once. */
682 val
= init_stringtab (desc
, stringtab_offset
);
685 free_all_symtabs (); /* FIXME blows whole symtab */
686 printf ("\"%s\": can't get string table", name
);
690 make_cleanup (free_stringtab
, 0);
692 /* Position to read the symbol table. Do not read it all at once. */
693 val
= lseek (desc
, (long)symtab_offset
, 0);
695 perror_with_name (name
);
697 init_misc_bunches ();
698 make_cleanup (discard_misc_bunches
, 0);
700 /* Now that the executable file is positioned at symbol table,
701 process it and define symbols accordingly. */
703 read_coff_symtab (desc
, num_symbols
);
705 patch_opaque_types ();
707 /* Sort symbols alphabetically within each block. */
709 sort_all_symtab_syms ();
711 /* Go over the misc symbol bunches and install them in vector. */
713 condense_misc_bunches (0);
715 /* Make a default for file to list. */
717 select_source_symtab (0); /* FIXME, this might be too slow, see dbxread */
721 coff_symfile_discard ()
723 /* There seems to be nothing to do here. */
729 /* There seems to be nothing to do except free_all_symtabs and set
730 symfile to zero, which is done by our caller. */
733 /* Simplified internal version of coff symbol table information */
737 int c_symnum
; /* symbol number of this entry */
738 int c_nsyms
; /* 1 if syment only, 2 if syment + auxent, etc */
745 /* Given pointers to a symbol table in coff style exec file,
746 analyze them and create struct symtab's describing the symbols.
747 NSYMS is the number of symbols in the symbol table.
748 We read them one at a time using read_one_sym (). */
751 read_coff_symtab (desc
, nsyms
)
755 int newfd
; /* Avoid multiple closes on same desc */
757 register struct context_stack
*new;
758 struct coff_symbol coff_symbol
;
759 register struct coff_symbol
*cs
= &coff_symbol
;
760 static SYMENT main_sym
;
761 static AUXENT main_aux
;
762 struct coff_symbol fcn_cs_saved
;
763 static SYMENT fcn_sym_saved
;
764 static AUXENT fcn_aux_saved
;
766 /* A .file is open. */
767 int in_source_file
= 0;
768 int num_object_files
= 0;
769 int next_file_symnum
= -1;
771 /* Name of the current file. */
772 char *filestring
= "";
778 struct cleanup
*old_chain
;
783 fatal ("Too many open files");
784 stream
= fdopen (newfd
, "r");
786 old_chain
= make_cleanup (free_all_symtabs
, 0);
787 make_cleanup (fclose
, stream
);
788 nlist_stream_global
= stream
;
789 nlist_nsyms_global
= nsyms
;
790 last_source_file
= 0;
791 bzero (opaque_type_chain
, sizeof opaque_type_chain
);
793 type_vector_length
= 160;
794 type_vector
= (struct typevector
*)
795 xmalloc (sizeof (struct typevector
)
796 + type_vector_length
* sizeof (struct type
*));
797 bzero (type_vector
->type
, type_vector_length
* sizeof (struct type
*));
802 while (symnum
< nsyms
)
804 QUIT
; /* Make this command interruptable. */
805 read_one_sym (cs
, &main_sym
, &main_aux
);
808 temp_sem_val
= cs
->c_name
[0] << 24 | cs
->c_name
[1] << 16 |
809 cs
->c_name
[2] << 8 | cs
->c_name
[3];
810 if (int_sem_val
== temp_sem_val
)
811 last_coffsem
= (int) strtol (cs
->c_name
+4, (char **) NULL
, 10);
814 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
816 if (last_source_file
)
820 complete_symtab ("_globals_", 0, first_object_file_end
);
821 /* done with all files, everything from here on out is globals */
824 /* Special case for file with type declarations only, no text. */
825 if (!last_source_file
&& cs
->c_type
!= T_NULL
&& cs
->c_secnum
== N_DEBUG
)
826 complete_symtab (filestring
, 0, 0);
828 /* Typedefs should not be treated as symbol definitions. */
829 if (ISFCN (cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
831 /* record as misc function. if we get '.bf' next,
832 * then we undo this step
834 record_misc_function (cs
->c_name
, cs
->c_value
);
836 fcn_line_ptr
= main_aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
837 fcn_start_addr
= cs
->c_value
;
839 fcn_sym_saved
= main_sym
;
840 fcn_aux_saved
= main_aux
;
844 switch (cs
->c_sclass
)
853 printf ("Bad n_sclass = %d\n", cs
->c_sclass
);
858 * c_value field contains symnum of next .file entry in table
859 * or symnum of first global after last .file.
861 next_file_symnum
= cs
->c_value
;
862 filestring
= getfilename (&main_aux
);
864 * Complete symbol table for last object file
865 * containing debugging information.
867 if (last_source_file
)
876 if (cs
->c_name
[0] == '.') {
877 if (strcmp (cs
->c_name
, _TEXT
) == 0) {
878 if (++num_object_files
== 1) {
879 /* last address of startup file */
880 first_object_file_end
= cs
->c_value
+
881 main_aux
.x_scn
.x_scnlen
;
883 /* Check for in_source_file deals with case of
884 a file with debugging symbols
885 followed by a later file with no symbols. */
887 complete_symtab (filestring
, cs
->c_value
,
888 main_aux
.x_scn
.x_scnlen
);
891 /* flush rest of '.' symbols */
894 else if (cs
->c_type
== T_NULL
895 && cs
->c_name
[0] == 'L'
896 && (strncmp (cs
->c_name
, "LI%", 3) == 0
897 || strncmp (cs
->c_name
,"LC%",3) == 0
898 || strncmp (cs
->c_name
,"LP%",3) == 0
899 || strncmp (cs
->c_name
,"LPB%",4) == 0
900 || strncmp (cs
->c_name
,"LBB%",4) == 0
901 || strncmp (cs
->c_name
,"LBE%",4) == 0
902 || strncmp (cs
->c_name
,"LPBX%",5) == 0))
903 /* At least on a 3b1, gcc generates swbeg and string labels
904 that look like this. Ignore them. */
906 /* fall in for static symbols that don't start with '.' */
908 if (cs
->c_sclass
== C_EXT
&&
909 cs
->c_secnum
== N_ABS
&&
910 strcmp (cs
->c_name
, _ETEXT
) == 0)
911 end_of_text_addr
= cs
->c_value
;
912 if (cs
->c_type
== T_NULL
) {
913 if (cs
->c_secnum
<= 1) { /* text or abs */
914 record_misc_function (cs
->c_name
, cs
->c_value
);
920 (void) process_coff_symbol (cs
, &main_aux
);
924 if (strcmp (cs
->c_name
, ".bf") == 0)
928 /* value contains address of first non-init type code */
929 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
930 contains line number of '{' } */
931 fcn_first_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
933 new = (struct context_stack
*)
934 xmalloc (sizeof (struct context_stack
));
935 new->depth
= depth
= 0;
939 new->old_blocks
= pending_blocks
;
940 new->start_addr
= fcn_start_addr
;
941 fcn_cs_saved
.c_name
= getsymname (&fcn_sym_saved
);
942 new->name
= process_coff_symbol (&fcn_cs_saved
,
945 else if (strcmp (cs
->c_name
, ".ef") == 0)
947 /* the value of .ef is the address of epilogue code;
950 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
951 contains number of lines to '}' */
955 complain (&ef_complaint
, cs
->c_symnum
);
959 fcn_last_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
960 enter_linenos (fcn_line_ptr
, fcn_first_line
, fcn_last_line
);
962 finish_block (new->name
, &local_symbols
, new->old_blocks
,
964 #if defined (FUNCTION_EPILOGUE_SIZE)
965 /* This macro should be defined only on
967 fcn_aux_saved.x_sym.x_misc.x_fsize
968 field is always zero.
969 So use the .bf record information that
970 points to the epilogue and add the size
972 cs
->c_value
+ FUNCTION_EPILOGUE_SIZE
974 fcn_cs_saved
.c_value
+
975 fcn_aux_saved
.x_sym
.x_misc
.x_fsize
985 if (strcmp (cs
->c_name
, ".bb") == 0)
987 new = (struct context_stack
*)
988 xmalloc (sizeof (struct context_stack
));
991 new->next
= context_stack
;
993 new->locals
= local_symbols
;
994 new->old_blocks
= pending_blocks
;
995 new->start_addr
= cs
->c_value
;
999 else if (strcmp (cs
->c_name
, ".eb") == 0)
1001 new = context_stack
;
1002 if (new == 0 || depth
!= new->depth
)
1003 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1005 if (local_symbols
&& context_stack
->next
)
1007 /* Make a block for the local symbols within. */
1008 finish_block (0, &local_symbols
, new->old_blocks
,
1009 new->start_addr
, cs
->c_value
);
1012 local_symbols
= new->locals
;
1013 context_stack
= new->next
;
1019 if (strcmp (cs
->c_name
, ".coffsyn") == 0)
1020 last_coffsyn
= cs
->c_value
;
1021 else if ((strcmp (cs
->c_name
, ".coffsem") == 0) &&
1023 last_coffsem
= cs
->c_value
;
1029 if ((strcmp (cs
->c_name
, ".coffsem") == 0) &&
1031 last_coffsem
= cs
->c_value
;
1034 (void) process_coff_symbol (cs
, &main_aux
);
1039 if (last_source_file
)
1042 discard_cleanups (old_chain
);
1045 /* Routines for reading headers and symbols from executable. */
1048 /* Move these XXXMAGIC symbol defns into BFD! */
1050 /* Read COFF file header, check magic number,
1051 and return number of symbols. */
1052 read_file_hdr (chan
, file_hdr
)
1056 lseek (chan
, 0L, 0);
1057 if (myread (chan
, (char *)file_hdr
, FILHSZ
) < 0)
1060 switch (file_hdr
->f_magic
)
1075 #if defined (MC68KWRMAGIC) \
1076 && (!defined (MC68MAGIC) || MC68KWRMAGIC != MC68MAGIC)
1090 case I960ROMAGIC
: /* Intel 960 */
1093 case I960RWMAGIC
: /* Intel 960 */
1095 return file_hdr
->f_nsyms
;
1099 if (BADMAG(file_hdr
))
1102 return file_hdr
->f_nsyms
;
1112 read_one_sym (cs
, sym
, aux
)
1113 register struct coff_symbol
*cs
;
1114 register SYMENT
*sym
;
1115 register AUXENT
*aux
;
1120 cs
->c_symnum
= symnum
;
1121 fread ((char *)sym
, SYMESZ
, 1, nlist_stream_global
);
1122 bfd_coff_swap_sym (symfile_bfd
, sym
);
1123 cs
->c_nsyms
= (sym
->n_numaux
& 0xff) + 1;
1124 if (cs
->c_nsyms
>= 2)
1126 fread ((char *)aux
, AUXESZ
, 1, nlist_stream_global
);
1127 bfd_coff_swap_aux (symfile_bfd
, aux
, sym
->n_type
, sym
->n_sclass
);
1128 /* If more than one aux entry, read past it (only the first aux
1130 for (i
= 2; i
< cs
->c_nsyms
; i
++)
1131 fread ((char *)&temp_aux
, AUXESZ
, 1, nlist_stream_global
);
1133 cs
->c_name
= getsymname (sym
);
1134 cs
->c_value
= sym
->n_value
;
1135 cs
->c_sclass
= (sym
->n_sclass
& 0xff);
1136 cs
->c_secnum
= sym
->n_scnum
;
1137 cs
->c_type
= (unsigned) sym
->n_type
;
1139 symnum
+= cs
->c_nsyms
;
1142 /* Support for string table handling */
1144 static char *stringtab
= NULL
;
1147 init_stringtab (chan
, offset
)
1153 unsigned char lengthbuf
[4];
1161 if (lseek (chan
, offset
, 0) < 0)
1164 val
= myread (chan
, (char *)lengthbuf
, sizeof lengthbuf
);
1165 length
= bfd_h_getlong (symfile_bfd
, lengthbuf
);
1167 /* If no string table is needed, then the file may end immediately
1168 after the symbols. Just return with `stringtab' set to null. */
1169 if (val
!= sizeof length
|| length
< sizeof length
)
1172 stringtab
= (char *) xmalloc (length
);
1173 if (stringtab
== NULL
)
1176 bcopy (&length
, stringtab
, sizeof length
);
1177 if (length
== sizeof length
) /* Empty table -- just the count */
1180 val
= myread (chan
, stringtab
+ sizeof length
, length
- sizeof length
);
1181 if (val
!= length
- sizeof length
|| stringtab
[length
- 1] != '\0')
1196 getsymname (symbol_entry
)
1197 SYMENT
*symbol_entry
;
1199 static char buffer
[SYMNMLEN
+1];
1202 if (symbol_entry
->n_zeroes
== 0)
1204 result
= stringtab
+ symbol_entry
->n_offset
;
1208 strncpy (buffer
, symbol_entry
->n_name
, SYMNMLEN
);
1209 buffer
[SYMNMLEN
] = '\0';
1216 getfilename (aux_entry
)
1219 static char buffer
[BUFSIZ
];
1220 register char *temp
;
1222 extern char *rindex ();
1224 #ifndef COFF_NO_LONG_FILE_NAMES
1225 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1226 strcpy (buffer
, stringtab
+ aux_entry
->x_file
.x_n
.x_offset
);
1228 #endif /* COFF_NO_LONG_FILE_NAMES */
1230 #if defined (x_name)
1232 strncpy (buffer
, aux_entry
->x_name
, FILNMLEN
);
1234 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1236 buffer
[FILNMLEN
] = '\0';
1239 if ((temp
= rindex (result
, '/')) != NULL
)
1244 /* Support for line number handling */
1245 static char *linetab
= NULL
;
1246 static long linetab_offset
;
1247 static unsigned long linetab_size
;
1249 /* Read in all the line numbers for fast lookups later. */
1252 init_lineno (chan
, offset
, size
)
1258 register char *p
, *q
;
1260 if (lseek (chan
, offset
, 0) < 0)
1263 linetab
= (char *) xmalloc (size
);
1265 val
= myread (chan
, linetab
, size
);
1269 /* Swap all entries */
1271 for (p
= linetab
; p
< q
; p
+= LINESZ
)
1272 bfd_coff_swap_lineno (symfile_bfd
, (LINENO
*)p
);
1274 linetab_offset
= offset
;
1275 linetab_size
= size
;
1276 make_cleanup (free
, linetab
); /* Be sure it gets de-allocated. */
1280 #if !defined (L_LNNO32)
1281 #define L_LNNO32(lp) ((lp)->l_lnno)
1285 enter_linenos (file_offset
, first_line
, last_line
)
1287 register int first_line
;
1288 register int last_line
;
1290 register char *rawptr
;
1293 if (file_offset
< linetab_offset
)
1295 fprintf (stderr
, "\nInvalid symbol file: file_offset < linetab_offset.");
1299 rawptr
= &linetab
[file_offset
- linetab_offset
];
1301 /* skip first line entry for each function */
1303 /* line numbers start at one for the first line of the function */
1306 /* Bcopy since occaisionally rawptr isn't pointing at long
1307 boundaries. FIXME we need to byteswap here!!! */
1308 for (bcopy (rawptr
, &lptr
, LINESZ
);
1309 L_LNNO32 (&lptr
) && L_LNNO32 (&lptr
) <= last_line
;
1310 rawptr
+= LINESZ
, bcopy (rawptr
, &lptr
, LINESZ
))
1312 record_line (first_line
+ L_LNNO32 (&lptr
), lptr
.l_addr
.l_paddr
);
1320 register char *p
= name
;
1321 register int total
= p
[0];
1334 return total
% HASHSIZE
;
1338 patch_type (type
, real_type
)
1340 struct type
*real_type
;
1342 register struct type
*target
= TYPE_TARGET_TYPE (type
);
1343 register struct type
*real_target
= TYPE_TARGET_TYPE (real_type
);
1344 int field_size
= TYPE_NFIELDS (real_target
) * sizeof (struct field
);
1346 TYPE_LENGTH (target
) = TYPE_LENGTH (real_target
);
1347 TYPE_NFIELDS (target
) = TYPE_NFIELDS (real_target
);
1348 TYPE_FIELDS (target
) = (struct field
*)
1349 obstack_alloc (symbol_obstack
, field_size
);
1351 bcopy (TYPE_FIELDS (real_target
), TYPE_FIELDS (target
), field_size
);
1353 if (TYPE_NAME (real_target
))
1355 if (TYPE_NAME (target
))
1356 free (TYPE_NAME (target
));
1357 TYPE_NAME (target
) = concat (TYPE_NAME (real_target
), "", "");
1361 /* Patch up all appropriate typdef symbols in the opaque_type_chains
1362 so that they can be used to print out opaque data structures properly */
1365 patch_opaque_types ()
1369 /* Look at each symbol in the per-file block of each symtab. */
1370 for (s
= symtab_list
; s
; s
= s
->next
)
1372 register struct block
*b
;
1375 /* Go through the per-file symbols only */
1376 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), 1);
1377 for (i
= BLOCK_NSYMS (b
) - 1; i
>= 0; i
--)
1379 register struct symbol
*real_sym
;
1381 /* Find completed typedefs to use to fix opaque ones.
1382 Remove syms from the chain when their types are stored,
1383 but search the whole chain, as there may be several syms
1384 from different files with the same name. */
1385 real_sym
= BLOCK_SYM (b
, i
);
1386 if (SYMBOL_CLASS (real_sym
) == LOC_TYPEDEF
&&
1387 SYMBOL_NAMESPACE (real_sym
) == VAR_NAMESPACE
&&
1388 TYPE_CODE (SYMBOL_TYPE (real_sym
)) == TYPE_CODE_PTR
&&
1389 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym
))) != 0)
1391 register char *name
= SYMBOL_NAME (real_sym
);
1392 register int hash
= hashname (name
);
1393 register struct symbol
*sym
, *prev
;
1396 for (sym
= opaque_type_chain
[hash
]; sym
;)
1398 if (name
[0] == SYMBOL_NAME (sym
)[0] &&
1399 !strcmp (name
+ 1, SYMBOL_NAME (sym
) + 1))
1402 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
1404 opaque_type_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
1406 patch_type (SYMBOL_TYPE (sym
), SYMBOL_TYPE (real_sym
));
1409 sym
= SYMBOL_VALUE_CHAIN (prev
);
1411 sym
= opaque_type_chain
[hash
];
1416 sym
= SYMBOL_VALUE_CHAIN (sym
);
1424 #if defined (clipper)
1425 #define BELIEVE_PCC_PROMOTION 1
1428 static struct symbol
*
1429 process_coff_symbol (cs
, aux
)
1430 register struct coff_symbol
*cs
;
1431 register AUXENT
*aux
;
1433 register struct symbol
*sym
1434 = (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
1436 #ifdef NAMES_HAVE_UNDERSCORE
1442 bzero (sym
, sizeof (struct symbol
));
1444 name
= (name
[0] == '_' ? name
+ offset
: name
);
1445 SYMBOL_NAME (sym
) = obstack_copy0 (symbol_obstack
, name
, strlen (name
));
1447 /* default assumptions */
1448 SYMBOL_VALUE (sym
) = cs
->c_value
;
1449 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1451 if (ISFCN (cs
->c_type
))
1454 lookup_function_type (decode_function_type (cs
, cs
->c_type
, aux
));
1455 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1456 if (cs
->c_sclass
== C_STAT
)
1457 add_symbol_to_list (sym
, &file_symbols
);
1458 else if (cs
->c_sclass
== C_EXT
)
1459 add_symbol_to_list (sym
, &global_symbols
);
1463 SYMBOL_TYPE (sym
) = decode_type (cs
, cs
->c_type
, aux
);
1464 switch (cs
->c_sclass
)
1470 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1471 add_symbol_to_list (sym
, &local_symbols
);
1475 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1476 SYMBOL_VALUE_ADDRESS (sym
) = (CORE_ADDR
) cs
->c_value
;
1477 add_symbol_to_list (sym
, &global_symbols
);
1481 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1482 SYMBOL_VALUE_ADDRESS (sym
) = (CORE_ADDR
) cs
->c_value
;
1483 if (within_function
) {
1484 /* Static symbol of local scope */
1485 add_symbol_to_list (sym
, &local_symbols
);
1488 /* Static symbol at top level of file */
1489 add_symbol_to_list (sym
, &file_symbols
);
1494 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1495 add_symbol_to_list (sym
, &local_symbols
);
1502 SYMBOL_CLASS (sym
) = LOC_ARG
;
1503 add_symbol_to_list (sym
, &local_symbols
);
1504 #if !defined (BELIEVE_PCC_PROMOTION)
1505 /* If PCC says a parameter is a short or a char,
1506 it is really an int. */
1507 if (SYMBOL_TYPE (sym
) == builtin_type_char
1508 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1509 SYMBOL_TYPE (sym
) = builtin_type_int
;
1510 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1511 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1512 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1517 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1518 add_symbol_to_list (sym
, &local_symbols
);
1519 #if !defined (BELIEVE_PCC_PROMOTION)
1520 /* If PCC says a parameter is a short or a char,
1521 it is really an int. */
1522 if (SYMBOL_TYPE (sym
) == builtin_type_char
1523 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1524 SYMBOL_TYPE (sym
) = builtin_type_int
;
1525 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1526 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1527 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1532 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1533 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1535 /* If type has no name, give it one */
1536 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1537 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1538 TYPE_NAME (SYMBOL_TYPE (sym
))
1539 = concat (SYMBOL_NAME (sym
), "", "");
1541 /* Keep track of any type which points to empty structured type,
1542 so it can be filled from a definition from another file */
1543 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
&&
1544 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym
))) == 0)
1546 register int i
= hashname (SYMBOL_NAME (sym
));
1548 SYMBOL_VALUE_CHAIN (sym
) = opaque_type_chain
[i
];
1549 opaque_type_chain
[i
] = sym
;
1551 add_symbol_to_list (sym
, &file_symbols
);
1557 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1558 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1559 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1560 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1561 TYPE_NAME (SYMBOL_TYPE (sym
))
1563 (cs
->c_sclass
== C_ENTAG
1565 : (cs
->c_sclass
== C_STRTAG
1566 ? "struct " : "union ")),
1568 add_symbol_to_list (sym
, &file_symbols
);
1578 /* Decode a coff type specifier;
1579 return the type that is meant. */
1583 decode_type (cs
, c_type
, aux
)
1584 register struct coff_symbol
*cs
;
1585 unsigned int c_type
;
1586 register AUXENT
*aux
;
1588 register struct type
*type
= 0;
1589 unsigned int new_c_type
;
1591 if (c_type
& ~N_BTMASK
)
1593 new_c_type
= DECREF (c_type
);
1596 type
= decode_type (cs
, new_c_type
, aux
);
1597 type
= lookup_pointer_type (type
);
1599 else if (ISFCN (c_type
))
1601 type
= decode_type (cs
, new_c_type
, aux
);
1602 type
= lookup_function_type (type
);
1604 else if (ISARY (c_type
))
1607 register unsigned short *dim
;
1608 struct type
*base_type
;
1610 /* Define an array type. */
1611 /* auxent refers to array, not base type */
1612 if (aux
->x_sym
.x_tagndx
== 0)
1615 /* shift the indices down */
1616 dim
= &aux
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0];
1619 for (i
= 0; *dim
&& i
< DIMNUM
- 1; i
++, dim
++)
1623 type
= (struct type
*)
1624 obstack_alloc (symbol_obstack
, sizeof (struct type
));
1625 bzero (type
, sizeof (struct type
));
1627 base_type
= decode_type (cs
, new_c_type
, aux
);
1629 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
1630 TYPE_TARGET_TYPE (type
) = base_type
;
1631 TYPE_LENGTH (type
) = n
* TYPE_LENGTH (base_type
);
1636 /* Reference to existing type */
1637 if (cs
->c_nsyms
> 1 && aux
->x_sym
.x_tagndx
!= 0)
1639 type
= coff_alloc_type (aux
->x_sym
.x_tagndx
);
1643 return decode_base_type (cs
, BTYPE (c_type
), aux
);
1646 /* Decode a coff type specifier for function definition;
1647 return the type that the function returns. */
1651 decode_function_type (cs
, c_type
, aux
)
1652 register struct coff_symbol
*cs
;
1653 unsigned int c_type
;
1654 register AUXENT
*aux
;
1656 if (aux
->x_sym
.x_tagndx
== 0)
1657 cs
->c_nsyms
= 1; /* auxent refers to function, not base type */
1659 return decode_type (cs
, DECREF (c_type
), aux
);
1666 decode_base_type (cs
, c_type
, aux
)
1667 register struct coff_symbol
*cs
;
1668 unsigned int c_type
;
1669 register AUXENT
*aux
;
1676 /* shows up with "void (*foo)();" structure members */
1677 return builtin_type_void
;
1681 /* Shows up in DGUX, I think. Not sure where. */
1682 return builtin_type_void
; /* shouldn't show up here */
1687 /* Intel 960 COFF has this symbol and meaning. */
1688 return builtin_type_void
;
1692 return builtin_type_char
;
1695 return builtin_type_short
;
1698 return builtin_type_int
;
1701 return builtin_type_long
;
1704 return builtin_type_float
;
1707 return builtin_type_double
;
1710 if (cs
->c_nsyms
!= 2)
1712 /* anonymous structure type */
1713 type
= coff_alloc_type (cs
->c_symnum
);
1714 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1715 TYPE_NAME (type
) = concat ("struct ", "<opaque>", "");
1716 TYPE_LENGTH (type
) = 0;
1717 TYPE_FIELDS (type
) = 0;
1718 TYPE_NFIELDS (type
) = 0;
1722 type
= read_struct_type (cs
->c_symnum
,
1723 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1724 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1729 if (cs
->c_nsyms
!= 2)
1731 /* anonymous union type */
1732 type
= coff_alloc_type (cs
->c_symnum
);
1733 TYPE_NAME (type
) = concat ("union ", "<opaque>", "");
1734 TYPE_LENGTH (type
) = 0;
1735 TYPE_FIELDS (type
) = 0;
1736 TYPE_NFIELDS (type
) = 0;
1740 type
= read_struct_type (cs
->c_symnum
,
1741 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1742 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1744 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1748 return read_enum_type (cs
->c_symnum
,
1749 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1750 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1753 /* shouldn't show up here */
1757 return builtin_type_unsigned_char
;
1760 return builtin_type_unsigned_short
;
1763 return builtin_type_unsigned_int
;
1766 return builtin_type_unsigned_long
;
1768 printf ("unexpected type %d at symnum %d\n", c_type
, cs
->c_symnum
);
1769 return builtin_type_void
;
1772 /* This page contains subroutines of read_type. */
1774 /* Read the description of a structure (or union type)
1775 and return an object describing the type. */
1777 static struct type
*
1778 read_struct_type (index
, length
, lastsym
)
1785 struct nextfield
*next
;
1789 register struct type
*type
;
1790 register struct nextfield
*list
= 0;
1791 struct nextfield
*new;
1795 #ifdef NAMES_HAVE_UNDERSCORE
1800 struct coff_symbol member_sym
;
1801 register struct coff_symbol
*ms
= &member_sym
;
1806 type
= coff_alloc_type (index
);
1807 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1808 TYPE_LENGTH (type
) = length
;
1810 while (!done
&& symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
1812 read_one_sym (ms
, &sub_sym
, &sub_aux
);
1814 name
= (name
[0] == '_' ? name
+ offset
: name
);
1816 switch (ms
->c_sclass
)
1821 /* Get space to record the next field's data. */
1822 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1826 /* Save the data. */
1827 list
->field
.name
= savestring (name
, strlen (name
));
1828 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1829 list
->field
.bitpos
= 8 * ms
->c_value
;
1830 list
->field
.bitsize
= 0;
1836 /* Get space to record the next field's data. */
1837 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1841 /* Save the data. */
1842 list
->field
.name
= savestring (name
, strlen (name
));
1843 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1844 list
->field
.bitpos
= ms
->c_value
;
1845 list
->field
.bitsize
= sub_aux
.x_sym
.x_misc
.x_lnsz
.x_size
;
1854 /* Now create the vector of fields, and record how big it is. */
1856 TYPE_NFIELDS (type
) = nfields
;
1857 TYPE_FIELDS (type
) = (struct field
*)
1858 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nfields
);
1860 /* Copy the saved-up fields into the field vector. */
1862 for (n
= nfields
; list
; list
= list
->next
)
1863 TYPE_FIELD (type
, --n
) = list
->field
;
1868 /* Read a definition of an enumeration type,
1869 and create and return a suitable type object.
1870 Also defines the symbols that represent the values of the type. */
1872 static struct type
*
1873 read_enum_type (index
, length
, lastsym
)
1878 register struct symbol
*sym
;
1879 register struct type
*type
;
1882 struct pending
**symlist
;
1883 struct coff_symbol member_sym
;
1884 register struct coff_symbol
*ms
= &member_sym
;
1887 struct pending
*osyms
, *syms
;
1890 #ifdef NAMES_HAVE_UNDERSCORE
1896 type
= coff_alloc_type (index
);
1897 if (within_function
)
1898 symlist
= &local_symbols
;
1900 symlist
= &file_symbols
;
1903 while (!done
&& symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
1905 read_one_sym (ms
, &sub_sym
, &sub_aux
);
1907 name
= (name
[0] == '_' ? name
+ offset
: name
);
1909 switch (ms
->c_sclass
)
1912 sym
= (struct symbol
*) xmalloc (sizeof (struct symbol
));
1913 bzero (sym
, sizeof (struct symbol
));
1915 SYMBOL_NAME (sym
) = savestring (name
, strlen (name
));
1916 SYMBOL_CLASS (sym
) = LOC_CONST
;
1917 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1918 SYMBOL_VALUE (sym
) = ms
->c_value
;
1919 add_symbol_to_list (sym
, symlist
);
1924 /* Sometimes the linker (on 386/ix 2.0.2 at least) screws
1925 up the count of how many symbols to read. So stop
1932 /* Now fill in the fields of the type-structure. */
1934 TYPE_LENGTH (type
) = sizeof (int);
1935 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
1936 TYPE_NFIELDS (type
) = nsyms
;
1937 TYPE_FIELDS (type
) = (struct field
*)
1938 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nsyms
);
1940 /* Find the symbols for the values and put them into the type.
1941 The symbols can be found in the symlist that we put them on
1942 to cause them to be defined. osyms contains the old value
1943 of that symlist; everything up to there was defined by us. */
1945 for (syms
= *symlist
, n
= nsyms
; syms
!= osyms
; syms
= syms
->next
)
1947 SYMBOL_TYPE (syms
->symbol
) = type
;
1948 TYPE_FIELD_NAME (type
, --n
) = SYMBOL_NAME (syms
->symbol
);
1949 TYPE_FIELD_VALUE (type
, n
) = 0;
1950 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (syms
->symbol
);
1951 TYPE_FIELD_BITSIZE (type
, n
) = 0;
1956 /* Register our ability to parse symbols for coff BFD files */
1958 static struct sym_fns coff_sym_fns
=
1961 coff_new_init
, coff_symfile_init
,
1962 coff_symfile_read
, coff_symfile_discard
1966 _initialize_coffread ()
1968 add_symtab_fns(&coff_sym_fns
);