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. */
620 find_linenos (abfd
, asect
, vpinfo
)
625 struct coff_symfile_info
*info
;
627 file_ptr offset
, maxoff
;
629 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
630 count
= asect
->lineno_count
;
635 #if !defined (LINESZ)
636 /* Just in case, you never know what to expect from those
637 COFF header files. */
638 #define LINESZ (sizeof (struct lineno))
639 #endif /* No LINESZ. */
640 size
= count
* LINESZ
;
642 info
= (struct coff_symfile_info
*)vpinfo
;
643 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
644 offset
= asect
->line_filepos
;
647 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
648 info
->min_lineno_offset
= offset
;
650 maxoff
= offset
+ size
;
651 if (maxoff
> info
->max_lineno_offset
)
652 info
->max_lineno_offset
= maxoff
;
656 /* Read a symbol file, after initialization by coff_symfile_init. */
657 /* FIXME! Addr and Mainline are not used yet -- this will not work for
658 shared libraries or add_file! */
661 coff_symfile_read (sf
, addr
, mainline
)
666 struct coff_symfile_info
*info
= (struct coff_symfile_info
*)sf
->sym_private
;
667 bfd
*abfd
= sf
->sym_bfd
;
668 char *name
= bfd_get_filename (abfd
);
673 int stringtab_offset
;
675 symfile_bfd
= abfd
; /* Kludge for swap routines */
677 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
678 desc
= fileno ((FILE *)(abfd
->iostream
)); /* File descriptor */
679 num_symbols
= bfd_get_symcount (abfd
); /* How many syms */
680 symtab_offset
= obj_sym_filepos (abfd
); /* Symbol table file offset */
681 stringtab_offset
= symtab_offset
+ num_symbols
* SYMESZ
; /* String tab */
685 debug_info
= text_hdr
.s_relptr
;
688 dc_terminate (tdesc_handle
);
693 /* Read the line number table, all at once. */
694 info
->min_lineno_offset
= 0;
695 info
->max_lineno_offset
= 0;
696 bfd_map_over_sections (abfd
, find_linenos
, info
);
698 val
= init_lineno (desc
, info
->min_lineno_offset
,
699 info
->max_lineno_offset
- info
->min_lineno_offset
);
701 error ("\"%s\": error reading line numbers\n", name
);
703 /* Now read the string table, all at once. */
705 val
= init_stringtab (desc
, stringtab_offset
);
708 free_all_symtabs (); /* FIXME blows whole symtab */
709 printf ("\"%s\": can't get string table", name
);
713 make_cleanup (free_stringtab
, 0);
715 /* Position to read the symbol table. Do not read it all at once. */
716 val
= lseek (desc
, (long)symtab_offset
, 0);
718 perror_with_name (name
);
720 init_misc_bunches ();
721 make_cleanup (discard_misc_bunches
, 0);
723 /* Now that the executable file is positioned at symbol table,
724 process it and define symbols accordingly. */
726 read_coff_symtab (desc
, num_symbols
);
728 patch_opaque_types ();
730 /* Sort symbols alphabetically within each block. */
732 sort_all_symtab_syms ();
734 /* Go over the misc symbol bunches and install them in vector. */
736 condense_misc_bunches (0);
738 /* Make a default for file to list. */
740 select_source_symtab (0); /* FIXME, this might be too slow, see dbxread */
744 coff_symfile_discard ()
746 /* There seems to be nothing to do here. */
752 /* There seems to be nothing to do except free_all_symtabs and set
753 symfile to zero, which is done by our caller. */
756 /* Simplified internal version of coff symbol table information */
760 int c_symnum
; /* symbol number of this entry */
761 int c_nsyms
; /* 1 if syment only, 2 if syment + auxent, etc */
768 /* Given pointers to a symbol table in coff style exec file,
769 analyze them and create struct symtab's describing the symbols.
770 NSYMS is the number of symbols in the symbol table.
771 We read them one at a time using read_one_sym (). */
774 read_coff_symtab (desc
, nsyms
)
778 int newfd
; /* Avoid multiple closes on same desc */
780 register struct context_stack
*new;
781 struct coff_symbol coff_symbol
;
782 register struct coff_symbol
*cs
= &coff_symbol
;
783 static SYMENT main_sym
;
784 static AUXENT main_aux
;
785 struct coff_symbol fcn_cs_saved
;
786 static SYMENT fcn_sym_saved
;
787 static AUXENT fcn_aux_saved
;
789 /* A .file is open. */
790 int in_source_file
= 0;
791 int num_object_files
= 0;
792 int next_file_symnum
= -1;
794 /* Name of the current file. */
795 char *filestring
= "";
801 struct cleanup
*old_chain
;
806 fatal ("Too many open files");
807 stream
= fdopen (newfd
, "r");
809 old_chain
= make_cleanup (free_all_symtabs
, 0);
810 make_cleanup (fclose
, stream
);
811 nlist_stream_global
= stream
;
812 nlist_nsyms_global
= nsyms
;
813 last_source_file
= 0;
814 bzero (opaque_type_chain
, sizeof opaque_type_chain
);
816 type_vector_length
= 160;
817 type_vector
= (struct typevector
*)
818 xmalloc (sizeof (struct typevector
)
819 + type_vector_length
* sizeof (struct type
*));
820 bzero (type_vector
->type
, type_vector_length
* sizeof (struct type
*));
825 while (symnum
< nsyms
)
827 QUIT
; /* Make this command interruptable. */
828 read_one_sym (cs
, &main_sym
, &main_aux
);
831 temp_sem_val
= cs
->c_name
[0] << 24 | cs
->c_name
[1] << 16 |
832 cs
->c_name
[2] << 8 | cs
->c_name
[3];
833 if (int_sem_val
== temp_sem_val
)
834 last_coffsem
= (int) strtol (cs
->c_name
+4, (char **) NULL
, 10);
837 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
839 if (last_source_file
)
843 complete_symtab ("_globals_", 0, first_object_file_end
);
844 /* done with all files, everything from here on out is globals */
847 /* Special case for file with type declarations only, no text. */
848 if (!last_source_file
&& SDB_TYPE (cs
->c_type
)
849 && cs
->c_secnum
== N_DEBUG
)
850 complete_symtab (filestring
, 0, 0);
852 /* Typedefs should not be treated as symbol definitions. */
853 if (ISFCN (cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
855 /* record as misc function. if we get '.bf' next,
856 * then we undo this step
858 record_misc_function (cs
->c_name
, cs
->c_value
);
860 fcn_line_ptr
= main_aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
861 fcn_start_addr
= cs
->c_value
;
863 fcn_sym_saved
= main_sym
;
864 fcn_aux_saved
= main_aux
;
868 switch (cs
->c_sclass
)
877 printf ("Bad n_sclass = %d\n", cs
->c_sclass
);
882 * c_value field contains symnum of next .file entry in table
883 * or symnum of first global after last .file.
885 next_file_symnum
= cs
->c_value
;
886 filestring
= getfilename (&main_aux
);
888 * Complete symbol table for last object file
889 * containing debugging information.
891 if (last_source_file
)
900 if (cs
->c_name
[0] == '.') {
901 if (strcmp (cs
->c_name
, _TEXT
) == 0) {
902 if (++num_object_files
== 1) {
903 /* last address of startup file */
904 first_object_file_end
= cs
->c_value
+
905 main_aux
.x_scn
.x_scnlen
;
907 /* Check for in_source_file deals with case of
908 a file with debugging symbols
909 followed by a later file with no symbols. */
911 complete_symtab (filestring
, cs
->c_value
,
912 main_aux
.x_scn
.x_scnlen
);
915 /* flush rest of '.' symbols */
918 else if (!SDB_TYPE (cs
->c_type
)
919 && cs
->c_name
[0] == 'L'
920 && (strncmp (cs
->c_name
, "LI%", 3) == 0
921 || strncmp (cs
->c_name
, "LF%", 3) == 0
922 || strncmp (cs
->c_name
,"LC%",3) == 0
923 || strncmp (cs
->c_name
,"LP%",3) == 0
924 || strncmp (cs
->c_name
,"LPB%",4) == 0
925 || strncmp (cs
->c_name
,"LBB%",4) == 0
926 || strncmp (cs
->c_name
,"LBE%",4) == 0
927 || strncmp (cs
->c_name
,"LPBX%",5) == 0))
928 /* At least on a 3b1, gcc generates swbeg and string labels
929 that look like this. Ignore them. */
931 /* fall in for static symbols that don't start with '.' */
933 if (cs
->c_sclass
== C_EXT
&&
934 cs
->c_secnum
== N_ABS
&&
935 strcmp (cs
->c_name
, _ETEXT
) == 0)
936 end_of_text_addr
= cs
->c_value
;
937 if (!SDB_TYPE (cs
->c_type
)) {
938 if (cs
->c_secnum
<= 1) { /* text or abs */
939 record_misc_function (cs
->c_name
, cs
->c_value
);
945 (void) process_coff_symbol (cs
, &main_aux
);
949 if (strcmp (cs
->c_name
, ".bf") == 0)
953 /* value contains address of first non-init type code */
954 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
955 contains line number of '{' } */
956 fcn_first_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
958 new = (struct context_stack
*)
959 xmalloc (sizeof (struct context_stack
));
960 new->depth
= depth
= 0;
964 new->old_blocks
= pending_blocks
;
965 new->start_addr
= fcn_start_addr
;
966 fcn_cs_saved
.c_name
= getsymname (&fcn_sym_saved
);
967 new->name
= process_coff_symbol (&fcn_cs_saved
,
970 else if (strcmp (cs
->c_name
, ".ef") == 0)
972 /* the value of .ef is the address of epilogue code;
975 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
976 contains number of lines to '}' */
980 complain (&ef_complaint
, cs
->c_symnum
);
984 fcn_last_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
985 enter_linenos (fcn_line_ptr
, fcn_first_line
, fcn_last_line
);
987 finish_block (new->name
, &local_symbols
, new->old_blocks
,
989 #if defined (FUNCTION_EPILOGUE_SIZE)
990 /* This macro should be defined only on
992 fcn_aux_saved.x_sym.x_misc.x_fsize
993 field is always zero.
994 So use the .bf record information that
995 points to the epilogue and add the size
997 cs
->c_value
+ FUNCTION_EPILOGUE_SIZE
999 fcn_cs_saved
.c_value
+
1000 fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1004 within_function
= 0;
1010 if (strcmp (cs
->c_name
, ".bb") == 0)
1012 new = (struct context_stack
*)
1013 xmalloc (sizeof (struct context_stack
));
1016 new->next
= context_stack
;
1017 context_stack
= new;
1018 new->locals
= local_symbols
;
1019 new->old_blocks
= pending_blocks
;
1020 new->start_addr
= cs
->c_value
;
1024 else if (strcmp (cs
->c_name
, ".eb") == 0)
1026 new = context_stack
;
1027 if (new == 0 || depth
!= new->depth
)
1028 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1030 if (local_symbols
&& context_stack
->next
)
1032 /* Make a block for the local symbols within. */
1033 finish_block (0, &local_symbols
, new->old_blocks
,
1034 new->start_addr
, cs
->c_value
);
1037 local_symbols
= new->locals
;
1038 context_stack
= new->next
;
1044 if (strcmp (cs
->c_name
, ".coffsyn") == 0)
1045 last_coffsyn
= cs
->c_value
;
1046 else if ((strcmp (cs
->c_name
, ".coffsem") == 0) &&
1048 last_coffsem
= cs
->c_value
;
1054 if ((strcmp (cs
->c_name
, ".coffsem") == 0) &&
1056 last_coffsem
= cs
->c_value
;
1059 (void) process_coff_symbol (cs
, &main_aux
);
1064 if (last_source_file
)
1067 discard_cleanups (old_chain
);
1070 /* Routines for reading headers and symbols from executable. */
1073 /* Move these XXXMAGIC symbol defns into BFD! */
1075 /* Read COFF file header, check magic number,
1076 and return number of symbols. */
1077 read_file_hdr (chan
, file_hdr
)
1081 lseek (chan
, 0L, 0);
1082 if (myread (chan
, (char *)file_hdr
, FILHSZ
) < 0)
1085 switch (file_hdr
->f_magic
)
1100 #if defined (MC68KWRMAGIC) \
1101 && (!defined (MC68MAGIC) || MC68KWRMAGIC != MC68MAGIC)
1115 case I960ROMAGIC
: /* Intel 960 */
1118 case I960RWMAGIC
: /* Intel 960 */
1120 return file_hdr
->f_nsyms
;
1124 if (BADMAG(file_hdr
))
1127 return file_hdr
->f_nsyms
;
1137 read_one_sym (cs
, sym
, aux
)
1138 register struct coff_symbol
*cs
;
1139 register SYMENT
*sym
;
1140 register AUXENT
*aux
;
1145 cs
->c_symnum
= symnum
;
1146 fread ((char *)sym
, SYMESZ
, 1, nlist_stream_global
);
1147 bfd_coff_swap_sym (symfile_bfd
, sym
);
1148 cs
->c_nsyms
= (sym
->n_numaux
& 0xff) + 1;
1149 if (cs
->c_nsyms
>= 2)
1151 fread ((char *)aux
, AUXESZ
, 1, nlist_stream_global
);
1152 bfd_coff_swap_aux (symfile_bfd
, aux
, sym
->n_type
, sym
->n_sclass
);
1153 /* If more than one aux entry, read past it (only the first aux
1155 for (i
= 2; i
< cs
->c_nsyms
; i
++)
1156 fread ((char *)&temp_aux
, AUXESZ
, 1, nlist_stream_global
);
1158 cs
->c_name
= getsymname (sym
);
1159 cs
->c_value
= sym
->n_value
;
1160 cs
->c_sclass
= (sym
->n_sclass
& 0xff);
1161 cs
->c_secnum
= sym
->n_scnum
;
1162 cs
->c_type
= (unsigned) sym
->n_type
;
1163 if (!SDB_TYPE (cs
->c_type
))
1166 symnum
+= cs
->c_nsyms
;
1169 /* Support for string table handling */
1171 static char *stringtab
= NULL
;
1174 init_stringtab (chan
, offset
)
1180 unsigned char lengthbuf
[4];
1188 if (lseek (chan
, offset
, 0) < 0)
1191 val
= myread (chan
, (char *)lengthbuf
, sizeof lengthbuf
);
1192 length
= bfd_h_getlong (symfile_bfd
, lengthbuf
);
1194 /* If no string table is needed, then the file may end immediately
1195 after the symbols. Just return with `stringtab' set to null. */
1196 if (val
!= sizeof length
|| length
< sizeof length
)
1199 stringtab
= (char *) xmalloc (length
);
1200 if (stringtab
== NULL
)
1203 bcopy (&length
, stringtab
, sizeof length
);
1204 if (length
== sizeof length
) /* Empty table -- just the count */
1207 val
= myread (chan
, stringtab
+ sizeof length
, length
- sizeof length
);
1208 if (val
!= length
- sizeof length
|| stringtab
[length
- 1] != '\0')
1223 getsymname (symbol_entry
)
1224 SYMENT
*symbol_entry
;
1226 static char buffer
[SYMNMLEN
+1];
1229 if (symbol_entry
->n_zeroes
== 0)
1231 result
= stringtab
+ symbol_entry
->n_offset
;
1235 strncpy (buffer
, symbol_entry
->n_name
, SYMNMLEN
);
1236 buffer
[SYMNMLEN
] = '\0';
1243 getfilename (aux_entry
)
1246 static char buffer
[BUFSIZ
];
1247 register char *temp
;
1249 extern char *rindex ();
1251 #ifndef COFF_NO_LONG_FILE_NAMES
1252 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1253 strcpy (buffer
, stringtab
+ aux_entry
->x_file
.x_n
.x_offset
);
1255 #endif /* COFF_NO_LONG_FILE_NAMES */
1257 #if defined (x_name)
1259 strncpy (buffer
, aux_entry
->x_name
, FILNMLEN
);
1261 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1263 buffer
[FILNMLEN
] = '\0';
1266 if ((temp
= rindex (result
, '/')) != NULL
)
1271 /* Support for line number handling */
1272 static char *linetab
= NULL
;
1273 static long linetab_offset
;
1274 static unsigned long linetab_size
;
1276 /* Read in all the line numbers for fast lookups later. */
1279 init_lineno (chan
, offset
, size
)
1285 register char *p
, *q
;
1287 if (lseek (chan
, offset
, 0) < 0)
1290 linetab
= (char *) xmalloc (size
);
1292 val
= myread (chan
, linetab
, size
);
1296 /* Swap all entries */
1298 for (p
= linetab
; p
< q
; p
+= LINESZ
)
1299 bfd_coff_swap_lineno (symfile_bfd
, (LINENO
*)p
);
1301 linetab_offset
= offset
;
1302 linetab_size
= size
;
1303 make_cleanup (free
, linetab
); /* Be sure it gets de-allocated. */
1307 #if !defined (L_LNNO32)
1308 #define L_LNNO32(lp) ((lp)->l_lnno)
1312 enter_linenos (file_offset
, first_line
, last_line
)
1314 register int first_line
;
1315 register int last_line
;
1317 register char *rawptr
;
1320 if (file_offset
< linetab_offset
)
1322 complain (lineno_complaint
, file_offset
);
1323 if (file_offset
> linetab_size
) /* Too big to be an offset? */
1325 file_offset
+= linetab_offset
; /* Try reading at that linetab offset */
1328 rawptr
= &linetab
[file_offset
- linetab_offset
];
1330 /* skip first line entry for each function */
1332 /* line numbers start at one for the first line of the function */
1335 /* Bcopy since occaisionally rawptr isn't pointing at long
1337 for (bcopy (rawptr
, &lptr
, LINESZ
);
1338 L_LNNO32 (&lptr
) && L_LNNO32 (&lptr
) <= last_line
;
1339 rawptr
+= LINESZ
, bcopy (rawptr
, &lptr
, LINESZ
))
1341 record_line (first_line
+ L_LNNO32 (&lptr
), lptr
.l_addr
.l_paddr
);
1349 register char *p
= name
;
1350 register int total
= p
[0];
1363 return total
% HASHSIZE
;
1367 patch_type (type
, real_type
)
1369 struct type
*real_type
;
1371 register struct type
*target
= TYPE_TARGET_TYPE (type
);
1372 register struct type
*real_target
= TYPE_TARGET_TYPE (real_type
);
1373 int field_size
= TYPE_NFIELDS (real_target
) * sizeof (struct field
);
1375 TYPE_LENGTH (target
) = TYPE_LENGTH (real_target
);
1376 TYPE_NFIELDS (target
) = TYPE_NFIELDS (real_target
);
1377 TYPE_FIELDS (target
) = (struct field
*)
1378 obstack_alloc (symbol_obstack
, field_size
);
1380 bcopy (TYPE_FIELDS (real_target
), TYPE_FIELDS (target
), field_size
);
1382 if (TYPE_NAME (real_target
))
1384 if (TYPE_NAME (target
))
1385 free (TYPE_NAME (target
));
1386 TYPE_NAME (target
) = concat (TYPE_NAME (real_target
), "", "");
1390 /* Patch up all appropriate typdef symbols in the opaque_type_chains
1391 so that they can be used to print out opaque data structures properly */
1394 patch_opaque_types ()
1398 /* Look at each symbol in the per-file block of each symtab. */
1399 for (s
= symtab_list
; s
; s
= s
->next
)
1401 register struct block
*b
;
1404 /* Go through the per-file symbols only */
1405 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
1406 for (i
= BLOCK_NSYMS (b
) - 1; i
>= 0; i
--)
1408 register struct symbol
*real_sym
;
1410 /* Find completed typedefs to use to fix opaque ones.
1411 Remove syms from the chain when their types are stored,
1412 but search the whole chain, as there may be several syms
1413 from different files with the same name. */
1414 real_sym
= BLOCK_SYM (b
, i
);
1415 if (SYMBOL_CLASS (real_sym
) == LOC_TYPEDEF
&&
1416 SYMBOL_NAMESPACE (real_sym
) == VAR_NAMESPACE
&&
1417 TYPE_CODE (SYMBOL_TYPE (real_sym
)) == TYPE_CODE_PTR
&&
1418 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym
))) != 0)
1420 register char *name
= SYMBOL_NAME (real_sym
);
1421 register int hash
= hashname (name
);
1422 register struct symbol
*sym
, *prev
;
1425 for (sym
= opaque_type_chain
[hash
]; sym
;)
1427 if (name
[0] == SYMBOL_NAME (sym
)[0] &&
1428 !strcmp (name
+ 1, SYMBOL_NAME (sym
) + 1))
1431 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
1433 opaque_type_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
1435 patch_type (SYMBOL_TYPE (sym
), SYMBOL_TYPE (real_sym
));
1438 sym
= SYMBOL_VALUE_CHAIN (prev
);
1440 sym
= opaque_type_chain
[hash
];
1445 sym
= SYMBOL_VALUE_CHAIN (sym
);
1453 #if defined (clipper)
1454 #define BELIEVE_PCC_PROMOTION 1
1457 static struct symbol
*
1458 process_coff_symbol (cs
, aux
)
1459 register struct coff_symbol
*cs
;
1460 register AUXENT
*aux
;
1462 register struct symbol
*sym
1463 = (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
1465 #ifdef NAMES_HAVE_UNDERSCORE
1471 bzero (sym
, sizeof (struct symbol
));
1473 name
= (name
[0] == '_' ? name
+ offset
: name
);
1474 SYMBOL_NAME (sym
) = obstack_copy0 (symbol_obstack
, name
, strlen (name
));
1476 /* default assumptions */
1477 SYMBOL_VALUE (sym
) = cs
->c_value
;
1478 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1480 if (ISFCN (cs
->c_type
))
1483 lookup_function_type (decode_function_type (cs
, cs
->c_type
, aux
));
1484 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1485 if (cs
->c_sclass
== C_STAT
)
1486 add_symbol_to_list (sym
, &file_symbols
);
1487 else if (cs
->c_sclass
== C_EXT
)
1488 add_symbol_to_list (sym
, &global_symbols
);
1492 SYMBOL_TYPE (sym
) = decode_type (cs
, cs
->c_type
, aux
);
1493 switch (cs
->c_sclass
)
1499 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1500 add_symbol_to_list (sym
, &local_symbols
);
1504 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1505 SYMBOL_VALUE_ADDRESS (sym
) = (CORE_ADDR
) cs
->c_value
;
1506 add_symbol_to_list (sym
, &global_symbols
);
1510 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1511 SYMBOL_VALUE_ADDRESS (sym
) = (CORE_ADDR
) cs
->c_value
;
1512 if (within_function
) {
1513 /* Static symbol of local scope */
1514 add_symbol_to_list (sym
, &local_symbols
);
1517 /* Static symbol at top level of file */
1518 add_symbol_to_list (sym
, &file_symbols
);
1523 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1524 add_symbol_to_list (sym
, &local_symbols
);
1531 SYMBOL_CLASS (sym
) = LOC_ARG
;
1532 add_symbol_to_list (sym
, &local_symbols
);
1533 #if !defined (BELIEVE_PCC_PROMOTION)
1534 /* If PCC says a parameter is a short or a char,
1535 it is really an int. */
1536 if (SYMBOL_TYPE (sym
) == builtin_type_char
1537 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1538 SYMBOL_TYPE (sym
) = builtin_type_int
;
1539 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1540 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1541 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1546 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1547 add_symbol_to_list (sym
, &local_symbols
);
1548 #if !defined (BELIEVE_PCC_PROMOTION)
1549 /* If PCC says a parameter is a short or a char,
1550 it is really an int. */
1551 if (SYMBOL_TYPE (sym
) == builtin_type_char
1552 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1553 SYMBOL_TYPE (sym
) = builtin_type_int
;
1554 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1555 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1556 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1561 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1562 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1564 /* If type has no name, give it one */
1565 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1566 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1567 TYPE_NAME (SYMBOL_TYPE (sym
))
1568 = concat (SYMBOL_NAME (sym
), "", "");
1570 /* Keep track of any type which points to empty structured type,
1571 so it can be filled from a definition from another file */
1572 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
&&
1573 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym
))) == 0)
1575 register int i
= hashname (SYMBOL_NAME (sym
));
1577 SYMBOL_VALUE_CHAIN (sym
) = opaque_type_chain
[i
];
1578 opaque_type_chain
[i
] = sym
;
1580 add_symbol_to_list (sym
, &file_symbols
);
1586 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1587 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1588 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1589 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1590 TYPE_NAME (SYMBOL_TYPE (sym
))
1592 (cs
->c_sclass
== C_ENTAG
1594 : (cs
->c_sclass
== C_STRTAG
1595 ? "struct " : "union ")),
1597 add_symbol_to_list (sym
, &file_symbols
);
1607 /* Decode a coff type specifier;
1608 return the type that is meant. */
1612 decode_type (cs
, c_type
, aux
)
1613 register struct coff_symbol
*cs
;
1614 unsigned int c_type
;
1615 register AUXENT
*aux
;
1617 register struct type
*type
= 0;
1618 unsigned int new_c_type
;
1620 if (c_type
& ~N_BTMASK
)
1622 new_c_type
= DECREF (c_type
);
1625 type
= decode_type (cs
, new_c_type
, aux
);
1626 type
= lookup_pointer_type (type
);
1628 else if (ISFCN (c_type
))
1630 type
= decode_type (cs
, new_c_type
, aux
);
1631 type
= lookup_function_type (type
);
1633 else if (ISARY (c_type
))
1636 register unsigned short *dim
;
1637 struct type
*base_type
;
1639 /* Define an array type. */
1640 /* auxent refers to array, not base type */
1641 if (aux
->x_sym
.x_tagndx
== 0)
1644 /* shift the indices down */
1645 dim
= &aux
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0];
1648 for (i
= 0; *dim
&& i
< DIMNUM
- 1; i
++, dim
++)
1652 type
= (struct type
*)
1653 obstack_alloc (symbol_obstack
, sizeof (struct type
));
1654 bzero (type
, sizeof (struct type
));
1656 base_type
= decode_type (cs
, new_c_type
, aux
);
1658 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
1659 TYPE_TARGET_TYPE (type
) = base_type
;
1660 TYPE_LENGTH (type
) = n
* TYPE_LENGTH (base_type
);
1665 /* Reference to existing type */
1666 if (cs
->c_nsyms
> 1 && aux
->x_sym
.x_tagndx
!= 0)
1668 type
= coff_alloc_type (aux
->x_sym
.x_tagndx
);
1672 return decode_base_type (cs
, BTYPE (c_type
), aux
);
1675 /* Decode a coff type specifier for function definition;
1676 return the type that the function returns. */
1680 decode_function_type (cs
, c_type
, aux
)
1681 register struct coff_symbol
*cs
;
1682 unsigned int c_type
;
1683 register AUXENT
*aux
;
1685 if (aux
->x_sym
.x_tagndx
== 0)
1686 cs
->c_nsyms
= 1; /* auxent refers to function, not base type */
1688 return decode_type (cs
, DECREF (c_type
), aux
);
1695 decode_base_type (cs
, c_type
, aux
)
1696 register struct coff_symbol
*cs
;
1697 unsigned int c_type
;
1698 register AUXENT
*aux
;
1705 /* shows up with "void (*foo)();" structure members */
1706 return builtin_type_void
;
1710 /* Shows up in DGUX, I think. Not sure where. */
1711 return builtin_type_void
; /* shouldn't show up here */
1716 /* Intel 960 COFF has this symbol and meaning. */
1717 return builtin_type_void
;
1721 return builtin_type_char
;
1724 return builtin_type_short
;
1727 return builtin_type_int
;
1730 return builtin_type_long
;
1733 return builtin_type_float
;
1736 return builtin_type_double
;
1739 if (cs
->c_nsyms
!= 2)
1741 /* anonymous structure type */
1742 type
= coff_alloc_type (cs
->c_symnum
);
1743 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1744 TYPE_NAME (type
) = concat ("struct ", "<opaque>", "");
1745 TYPE_LENGTH (type
) = 0;
1746 TYPE_FIELDS (type
) = 0;
1747 TYPE_NFIELDS (type
) = 0;
1751 type
= read_struct_type (cs
->c_symnum
,
1752 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1753 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1758 if (cs
->c_nsyms
!= 2)
1760 /* anonymous union type */
1761 type
= coff_alloc_type (cs
->c_symnum
);
1762 TYPE_NAME (type
) = concat ("union ", "<opaque>", "");
1763 TYPE_LENGTH (type
) = 0;
1764 TYPE_FIELDS (type
) = 0;
1765 TYPE_NFIELDS (type
) = 0;
1769 type
= read_struct_type (cs
->c_symnum
,
1770 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1771 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1773 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1777 return read_enum_type (cs
->c_symnum
,
1778 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1779 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1782 /* shouldn't show up here */
1786 return builtin_type_unsigned_char
;
1789 return builtin_type_unsigned_short
;
1792 return builtin_type_unsigned_int
;
1795 return builtin_type_unsigned_long
;
1797 printf ("unexpected type %d at symnum %d\n", c_type
, cs
->c_symnum
);
1798 return builtin_type_void
;
1801 /* This page contains subroutines of read_type. */
1803 /* Read the description of a structure (or union type)
1804 and return an object describing the type. */
1806 static struct type
*
1807 read_struct_type (index
, length
, lastsym
)
1814 struct nextfield
*next
;
1818 register struct type
*type
;
1819 register struct nextfield
*list
= 0;
1820 struct nextfield
*new;
1824 #ifdef NAMES_HAVE_UNDERSCORE
1829 struct coff_symbol member_sym
;
1830 register struct coff_symbol
*ms
= &member_sym
;
1835 type
= coff_alloc_type (index
);
1836 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1837 TYPE_LENGTH (type
) = length
;
1839 while (!done
&& symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
1841 read_one_sym (ms
, &sub_sym
, &sub_aux
);
1843 name
= (name
[0] == '_' ? name
+ offset
: name
);
1845 switch (ms
->c_sclass
)
1850 /* Get space to record the next field's data. */
1851 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1855 /* Save the data. */
1856 list
->field
.name
= savestring (name
, strlen (name
));
1857 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1858 list
->field
.bitpos
= 8 * ms
->c_value
;
1859 list
->field
.bitsize
= 0;
1865 /* Get space to record the next field's data. */
1866 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1870 /* Save the data. */
1871 list
->field
.name
= savestring (name
, strlen (name
));
1872 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1873 list
->field
.bitpos
= ms
->c_value
;
1874 list
->field
.bitsize
= sub_aux
.x_sym
.x_misc
.x_lnsz
.x_size
;
1883 /* Now create the vector of fields, and record how big it is. */
1885 TYPE_NFIELDS (type
) = nfields
;
1886 TYPE_FIELDS (type
) = (struct field
*)
1887 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nfields
);
1889 /* Copy the saved-up fields into the field vector. */
1891 for (n
= nfields
; list
; list
= list
->next
)
1892 TYPE_FIELD (type
, --n
) = list
->field
;
1897 /* Read a definition of an enumeration type,
1898 and create and return a suitable type object.
1899 Also defines the symbols that represent the values of the type. */
1901 static struct type
*
1902 read_enum_type (index
, length
, lastsym
)
1907 register struct symbol
*sym
;
1908 register struct type
*type
;
1911 struct pending
**symlist
;
1912 struct coff_symbol member_sym
;
1913 register struct coff_symbol
*ms
= &member_sym
;
1916 struct pending
*osyms
, *syms
;
1919 #ifdef NAMES_HAVE_UNDERSCORE
1925 type
= coff_alloc_type (index
);
1926 if (within_function
)
1927 symlist
= &local_symbols
;
1929 symlist
= &file_symbols
;
1932 while (!done
&& symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
1934 read_one_sym (ms
, &sub_sym
, &sub_aux
);
1936 name
= (name
[0] == '_' ? name
+ offset
: name
);
1938 switch (ms
->c_sclass
)
1941 sym
= (struct symbol
*) xmalloc (sizeof (struct symbol
));
1942 bzero (sym
, sizeof (struct symbol
));
1944 SYMBOL_NAME (sym
) = savestring (name
, strlen (name
));
1945 SYMBOL_CLASS (sym
) = LOC_CONST
;
1946 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1947 SYMBOL_VALUE (sym
) = ms
->c_value
;
1948 add_symbol_to_list (sym
, symlist
);
1953 /* Sometimes the linker (on 386/ix 2.0.2 at least) screws
1954 up the count of how many symbols to read. So stop
1961 /* Now fill in the fields of the type-structure. */
1963 TYPE_LENGTH (type
) = sizeof (int);
1964 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
1965 TYPE_NFIELDS (type
) = nsyms
;
1966 TYPE_FIELDS (type
) = (struct field
*)
1967 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nsyms
);
1969 /* Find the symbols for the values and put them into the type.
1970 The symbols can be found in the symlist that we put them on
1971 to cause them to be defined. osyms contains the old value
1972 of that symlist; everything up to there was defined by us. */
1974 for (syms
= *symlist
, n
= nsyms
; syms
!= osyms
; syms
= syms
->next
)
1976 SYMBOL_TYPE (syms
->symbol
) = type
;
1977 TYPE_FIELD_NAME (type
, --n
) = SYMBOL_NAME (syms
->symbol
);
1978 TYPE_FIELD_VALUE (type
, n
) = 0;
1979 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (syms
->symbol
);
1980 TYPE_FIELD_BITSIZE (type
, n
) = 0;
1985 /* Register our ability to parse symbols for coff BFD files */
1987 static struct sym_fns coff_sym_fns
=
1990 coff_new_init
, coff_symfile_init
,
1991 coff_symfile_read
, coff_symfile_discard
1995 _initialize_coffread ()
1997 add_symtab_fns(&coff_sym_fns
);