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 This program 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 2 of the License, or
12 (at your option) any later version.
14 This program 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 this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include "breakpoint.h"
32 /* Need to get C_VERSION and friends. */
35 #include <intel-coff.h>
36 #endif /* not TDESC */
41 #include "internalcoff.h" /* Internal format of COFF symbols in BFD */
42 #include "libcoff.h" /* FIXME secret internal data from BFD */
44 static void add_symbol_to_list ();
45 static void read_coff_symtab ();
46 static void patch_opaque_types ();
47 static struct type
*decode_function_type ();
48 static struct type
*decode_type ();
49 static struct type
*decode_base_type ();
50 static struct type
*read_enum_type ();
51 static struct type
*read_struct_type ();
52 static void finish_block ();
53 static struct blockvector
*make_blockvector ();
54 static struct symbol
*process_coff_symbol ();
55 static int init_stringtab ();
56 static void free_stringtab ();
57 static char *getfilename ();
58 static char *getsymname ();
59 static int init_lineno ();
60 static void enter_linenos ();
61 static void read_one_sym ();
64 extern void free_all_symtabs ();
65 extern void free_all_psymtabs ();
67 /* To be an sdb debug type, type must have at least a basic or primary
68 derived type. Using this rather than checking against T_NULL is
69 said to prevent core dumps if we try to operate on Michael Bloom
72 #define SDB_TYPE(type) (BTYPE(type) | (type & N_TMASK))
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
;
134 int int_sem_val
= 's' << 24 | 'e' << 16 | 'm' << 8 | '.';
136 int last_coffsem
= 2;
138 /* This isn't used currently. */
139 int last_coffsyn
= 0;
141 int debug_info
= 0; /*used by tdesc */
142 extern dc_dcontext_t tdesc_handle
;
143 extern int safe_to_init_tdesc_context
;
146 /* Chain of typedefs of pointers to empty struct/union types.
147 They are chained thru the SYMBOL_VALUE_CHAIN. */
150 static struct symbol
*opaque_type_chain
[HASHSIZE
];
152 /* Record the symbols defined for each context in a list.
153 We don't create a struct block for the context until we
154 know how long to make it. */
158 struct pending
*next
;
159 struct symbol
*symbol
;
162 /* Here are the three lists that symbols are put on. */
164 struct pending
*file_symbols
; /* static at top level, and types */
166 struct pending
*global_symbols
; /* global functions and variables */
168 struct pending
*local_symbols
; /* everything local to lexical context */
170 /* List of unclosed lexical contexts
171 (that will become blocks, eventually). */
175 struct context_stack
*next
;
176 struct pending
*locals
;
177 struct pending_block
*old_blocks
;
179 CORE_ADDR start_addr
;
183 struct context_stack
*context_stack
;
185 /* Nonzero if within a function (so symbols should be local,
186 if nothing says specifically). */
190 /* List of blocks already made (lexical contexts already closed).
191 This is used at the end to make the blockvector. */
195 struct pending_block
*next
;
199 struct pending_block
*pending_blocks
;
201 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
202 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
204 /* Complaints about various problems in the file being read */
206 struct complaint ef_complaint
=
207 {"Unmatched .ef symbol(s) ignored starting at symnum %d", 0, 0};
209 struct complaint lineno_complaint
=
210 {"Line number pointer %d lower than start of line numbers", 0, 0};
213 /* Look up a coff type-number index. Return the address of the slot
214 where the type for that index is stored.
215 The type-number is in INDEX.
217 This can be used for finding the type associated with that index
218 or for associating a new type with the index. */
220 static struct type
**
221 coff_lookup_type (index
)
224 if (index
>= type_vector_length
)
226 int old_vector_length
= type_vector_length
;
228 type_vector_length
*= 2;
229 if (type_vector_length
< index
) {
230 type_vector_length
= index
* 2;
232 type_vector
= (struct typevector
*)
233 xrealloc (type_vector
, sizeof (struct typevector
)
234 + type_vector_length
* sizeof (struct type
*));
235 bzero (&type_vector
->type
[ old_vector_length
],
236 (type_vector_length
- old_vector_length
) * sizeof(struct type
*));
238 return &type_vector
->type
[index
];
241 /* Make sure there is a type allocated for type number index
242 and return the type object.
243 This can create an empty (zeroed) type object. */
246 coff_alloc_type (index
)
249 register struct type
**type_addr
= coff_lookup_type (index
);
250 register struct type
*type
= *type_addr
;
252 /* If we are referring to a type not known at all yet,
253 allocate an empty type for it.
254 We will fill it in later if we find out how. */
257 type
= (struct type
*) obstack_alloc (symbol_obstack
,
258 sizeof (struct type
));
259 bzero (type
, sizeof (struct type
));
265 /* maintain the lists of symbols and blocks */
267 /* Add a symbol to one of the lists of symbols. */
269 add_symbol_to_list (symbol
, listhead
)
270 struct symbol
*symbol
;
271 struct pending
**listhead
;
273 register struct pending
*link
274 = (struct pending
*) xmalloc (sizeof (struct pending
));
276 link
->next
= *listhead
;
277 link
->symbol
= symbol
;
281 /* Take one of the lists of symbols and make a block from it.
282 Put the block on the list of pending blocks. */
285 finish_block (symbol
, listhead
, old_blocks
, start
, end
)
286 struct symbol
*symbol
;
287 struct pending
**listhead
;
288 struct pending_block
*old_blocks
;
289 CORE_ADDR start
, end
;
291 register struct pending
*next
, *next1
;
292 register struct block
*block
;
293 register struct pending_block
*pblock
;
294 struct pending_block
*opblock
;
297 /* Count the length of the list of symbols. */
299 for (next
= *listhead
, i
= 0; next
; next
= next
->next
, i
++);
301 block
= (struct block
*)
302 obstack_alloc (symbol_obstack
, sizeof (struct block
) + (i
- 1) * sizeof (struct symbol
*));
304 /* Copy the symbols into the block. */
306 BLOCK_NSYMS (block
) = i
;
307 for (next
= *listhead
; next
; next
= next
->next
)
308 BLOCK_SYM (block
, --i
) = next
->symbol
;
310 BLOCK_START (block
) = start
;
311 BLOCK_END (block
) = end
;
312 BLOCK_SUPERBLOCK (block
) = 0; /* Filled in when containing block is made */
314 /* Put the block in as the value of the symbol that names it. */
318 SYMBOL_BLOCK_VALUE (symbol
) = block
;
319 BLOCK_FUNCTION (block
) = symbol
;
322 BLOCK_FUNCTION (block
) = 0;
324 /* Now free the links of the list, and empty the list. */
326 for (next
= *listhead
; next
; next
= next1
)
333 /* Install this block as the superblock
334 of all blocks made since the start of this scope
335 that don't have superblocks yet. */
338 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
340 if (BLOCK_SUPERBLOCK (pblock
->block
) == 0)
341 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
345 /* Record this block on the list of all blocks in the file.
346 Put it after opblock, or at the beginning if opblock is 0.
347 This puts the block in the list after all its subblocks. */
349 pblock
= (struct pending_block
*) xmalloc (sizeof (struct pending_block
));
350 pblock
->block
= block
;
353 pblock
->next
= opblock
->next
;
354 opblock
->next
= pblock
;
358 pblock
->next
= pending_blocks
;
359 pending_blocks
= pblock
;
363 static struct blockvector
*
366 register struct pending_block
*next
, *next1
;
367 register struct blockvector
*blockvector
;
370 /* Count the length of the list of blocks. */
372 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
374 blockvector
= (struct blockvector
*)
375 obstack_alloc (symbol_obstack
, sizeof (struct blockvector
) + (i
- 1) * sizeof (struct block
*));
377 /* Copy the blocks into the blockvector.
378 This is done in reverse order, which happens to put
379 the blocks into the proper order (ascending starting address).
380 finish_block has hair to insert each block into the list
381 after its subblocks in order to make sure this is true. */
383 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
384 for (next
= pending_blocks
; next
; next
= next
->next
)
385 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
387 /* Now free the links of the list, and empty the list. */
389 for (next
= pending_blocks
; next
; next
= next1
)
399 /* Manage the vector of line numbers. */
402 record_line (line
, pc
)
406 struct linetable_entry
*e
;
407 /* Make sure line vector is big enough. */
409 if (line_vector_index
+ 2 >= line_vector_length
)
411 line_vector_length
*= 2;
412 line_vector
= (struct linetable
*)
413 xrealloc (line_vector
, sizeof (struct linetable
)
414 + (line_vector_length
415 * sizeof (struct linetable_entry
)));
418 e
= line_vector
->item
+ line_vector_index
++;
419 e
->line
= line
; e
->pc
= pc
;
422 /* Start a new symtab for a new source file.
423 This is called when a COFF ".file" symbol is seen;
424 it indicates the start of data for one original source file. */
433 last_source_file
= 0;
437 /* This isn't used currently. */
442 /* Initialize the source file line number information for this file. */
444 if (line_vector
) /* Unlikely, but maybe possible? */
446 line_vector_index
= 0;
447 line_vector_length
= 1000;
448 prev_line_number
= -2; /* Force first line number to be explicit */
449 line_vector
= (struct linetable
*)
450 xmalloc (sizeof (struct linetable
)
451 + line_vector_length
* sizeof (struct linetable_entry
));
454 /* Save the vital information from when starting to read a file,
455 for use when closing off the current file.
456 NAME is the file name the symbols came from, START_ADDR is the first
457 text address for the file, and SIZE is the number of bytes of text. */
460 complete_symtab (name
, start_addr
, size
)
462 CORE_ADDR start_addr
;
465 last_source_file
= savestring (name
, strlen (name
));
466 cur_src_start_addr
= start_addr
;
467 cur_src_end_addr
= start_addr
+ size
;
469 if (entry_point
< cur_src_end_addr
470 && entry_point
>= cur_src_start_addr
)
472 startup_file_start
= cur_src_start_addr
;
473 startup_file_end
= cur_src_end_addr
;
477 /* Finish the symbol definitions for one main source file,
478 close off all the lexical contexts for that file
479 (creating struct block's for them), then make the
480 struct symtab for that file and put it in the list of all such. */
485 register struct symtab
*symtab
;
486 register struct context_stack
*cstk
;
487 register struct blockvector
*blockvector
;
488 register struct linetable
*lv
;
490 /* Finish the lexical context of the last function in the file. */
494 cstk
= context_stack
;
496 /* Make a block for the local symbols within. */
497 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
498 cstk
->start_addr
, cur_src_end_addr
);
502 /* Ignore a file that has no functions with real debugging info. */
503 if (pending_blocks
== 0 && file_symbols
== 0 && global_symbols
== 0)
507 line_vector_length
= -1;
508 last_source_file
= 0;
512 /* Create the two top-level blocks for this file (STATIC_BLOCK and
514 finish_block (0, &file_symbols
, 0, cur_src_start_addr
, cur_src_end_addr
);
515 finish_block (0, &global_symbols
, 0, cur_src_start_addr
, cur_src_end_addr
);
517 /* Create the blockvector that points to all the file's blocks. */
518 blockvector
= make_blockvector ();
520 /* Now create the symtab object for this source file. */
521 symtab
= (struct symtab
*) xmalloc (sizeof (struct symtab
));
522 symtab
->free_ptr
= 0;
524 /* Fill in its components. */
525 symtab
->blockvector
= blockvector
;
526 symtab
->free_code
= free_linetable
;
527 symtab
->filename
= last_source_file
;
528 symtab
->dirname
= NULL
;
530 lv
->nitems
= line_vector_index
;
531 symtab
->linetable
= (struct linetable
*)
532 xrealloc (lv
, (sizeof (struct linetable
)
533 + lv
->nitems
* sizeof (struct linetable_entry
)));
535 symtab
->line_charpos
= 0;
537 symtab
->language
= language_unknown
;
538 symtab
->fullname
= NULL
;
541 symtab
->coffsem
= last_coffsem
;
543 /* This isn't used currently. Besides, if this is really about "syntax",
544 it shouldn't need to stick around past symbol read-in time. */
545 symtab
->coffsyn
= last_coffsyn
;
549 free_named_symtabs (symtab
->filename
);
551 /* Link the new symtab into the list of such. */
552 symtab
->next
= symtab_list
;
553 symtab_list
= symtab
;
555 /* Reinitialize for beginning of new file. */
557 line_vector_length
= -1;
558 last_source_file
= 0;
562 record_misc_function (name
, address
)
567 /* We don't want TDESC entry points on the misc_function_vector */
568 if (name
[0] == '@') return;
570 /* mf_text isn't true, but apparently COFF doesn't tell us what it really
571 is, so this guess is more useful than mf_unknown. */
572 prim_record_misc_function (savestring (name
, strlen (name
)),
577 /* coff_symfile_init ()
578 is the coff-specific initialization routine for reading symbols.
579 It is passed a struct sym_fns which contains, among other things,
580 the BFD for the file whose symbols are being read, and a slot for
581 a pointer to "private data" which we fill with cookies and other
582 treats for coff_symfile_read ().
584 We will only be called if this is a COFF or COFF-like file.
585 BFD handles figuring out the format of the file, and code in symtab.c
586 uses BFD's determination to vector to us.
588 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
590 struct coff_symfile_info
{
591 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
592 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
596 coff_symfile_init (sf
)
599 bfd
*abfd
= sf
->sym_bfd
;
601 /* Allocate struct to keep track of the symfile */
602 /* FIXME memory leak */
603 sf
->sym_private
= xmalloc (sizeof (struct coff_symfile_info
));
606 safe_to_init_tdesc_context
= 0;
609 /* Save startup file's range of PC addresses to help blockframe.c
610 decide where the bottom of the stack is. */
611 if (bfd_get_file_flags (abfd
) & EXEC_P
)
613 /* Executable file -- record its entry point so we'll recognize
614 the startup file because it contains the entry point. */
615 entry_point
= bfd_get_start_address (abfd
);
619 /* Examination of non-executable.o files. Short-circuit this stuff. */
620 /* ~0 will not be in any file, we hope. */
622 /* set the startup file to be an empty range. */
623 startup_file_start
= 0;
624 startup_file_end
= 0;
628 /* This function is called for every section; it finds the outer limits
629 of the line table (minimum and maximum file offset) so that the
630 mainline code can read the whole thing for efficiency. */
634 find_linenos (abfd
, asect
, vpinfo
)
639 struct coff_symfile_info
*info
;
641 file_ptr offset
, maxoff
;
643 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
644 count
= asect
->lineno_count
;
649 #if !defined (LINESZ)
650 /* Just in case, you never know what to expect from those
651 COFF header files. */
652 #define LINESZ (sizeof (struct lineno))
653 #endif /* No LINESZ. */
654 size
= count
* LINESZ
;
656 info
= (struct coff_symfile_info
*)vpinfo
;
657 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
658 offset
= asect
->line_filepos
;
661 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
662 info
->min_lineno_offset
= offset
;
664 maxoff
= offset
+ size
;
665 if (maxoff
> info
->max_lineno_offset
)
666 info
->max_lineno_offset
= maxoff
;
668 /* While we're at it, find the debug_info. It's in the s_relptr
669 (or, in BFD-speak, rel_filepos) of the text segment section header. */
670 if (strcmp (bfd_section_name (abfd
, asect
), ".text") == 0)
672 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
673 debug_info
= asect
->rel_filepos
;
677 dc_terminate (tdesc_handle
);
685 /* The BFD for this file -- only good while we're actively reading
686 symbols into a psymtab or a symtab. */
688 static bfd
*symfile_bfd
;
690 /* Read a symbol file, after initialization by coff_symfile_init. */
691 /* FIXME! Addr and Mainline are not used yet -- this will not work for
692 shared libraries or add_file! */
696 coff_symfile_read (sf
, addr
, mainline
)
701 struct coff_symfile_info
*info
= (struct coff_symfile_info
*)sf
->sym_private
;
702 bfd
*abfd
= sf
->sym_bfd
;
703 char *name
= bfd_get_filename (abfd
);
708 int stringtab_offset
;
710 symfile_bfd
= abfd
; /* Kludge for swap routines */
712 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
713 desc
= fileno ((FILE *)(abfd
->iostream
)); /* File descriptor */
714 num_symbols
= bfd_get_symcount (abfd
); /* How many syms */
715 symtab_offset
= obj_sym_filepos (abfd
); /* Symbol table file offset */
716 stringtab_offset
= symtab_offset
+ num_symbols
* SYMESZ
; /* String tab */
719 /* Read the line number table, all at once. */
720 info
->min_lineno_offset
= 0;
721 info
->max_lineno_offset
= 0;
722 bfd_map_over_sections (abfd
, find_linenos
, info
);
724 val
= init_lineno (desc
, info
->min_lineno_offset
,
725 info
->max_lineno_offset
- info
->min_lineno_offset
);
727 error ("\"%s\": error reading line numbers\n", name
);
729 /* Now read the string table, all at once. */
731 val
= init_stringtab (desc
, stringtab_offset
);
734 free_all_symtabs (); /* FIXME blows whole symtab */
735 printf ("\"%s\": can't get string table", name
);
739 make_cleanup (free_stringtab
, 0);
741 /* Position to read the symbol table. Do not read it all at once. */
742 val
= lseek (desc
, (long)symtab_offset
, 0);
744 perror_with_name (name
);
746 init_misc_bunches ();
747 make_cleanup (discard_misc_bunches
, 0);
749 /* Now that the executable file is positioned at symbol table,
750 process it and define symbols accordingly. */
752 read_coff_symtab (desc
, num_symbols
);
754 patch_opaque_types ();
756 /* Sort symbols alphabetically within each block. */
758 sort_all_symtab_syms ();
760 /* Go over the misc symbol bunches and install them in vector. */
762 condense_misc_bunches (!mainline
);
764 /* Make a default for file to list. */
766 select_source_symtab (0); /* FIXME, this might be too slow, see dbxread */
772 /* There seems to be nothing to do except free_all_symtabs and set
773 symfile to zero, which is done by our caller. */
776 /* Simplified internal version of coff symbol table information */
780 int c_symnum
; /* symbol number of this entry */
781 int c_nsyms
; /* 1 if syment only, 2 if syment + auxent, etc */
788 /* Given pointers to a symbol table in coff style exec file,
789 analyze them and create struct symtab's describing the symbols.
790 NSYMS is the number of symbols in the symbol table.
791 We read them one at a time using read_one_sym (). */
794 read_coff_symtab (desc
, nsyms
)
798 int newfd
; /* Avoid multiple closes on same desc */
800 register struct context_stack
*new;
801 struct coff_symbol coff_symbol
;
802 register struct coff_symbol
*cs
= &coff_symbol
;
803 static struct internal_syment main_sym
;
804 static union internal_auxent main_aux
;
805 struct coff_symbol fcn_cs_saved
;
806 static struct internal_syment fcn_sym_saved
;
807 static union internal_auxent fcn_aux_saved
;
809 /* A .file is open. */
810 int in_source_file
= 0;
811 int num_object_files
= 0;
812 int next_file_symnum
= -1;
814 /* Name of the current file. */
815 char *filestring
= "";
821 struct cleanup
*old_chain
;
826 fatal ("Too many open files");
827 stream
= fdopen (newfd
, "r");
829 old_chain
= make_cleanup (free_all_symtabs
, 0);
830 make_cleanup (fclose
, stream
);
831 nlist_stream_global
= stream
;
832 nlist_nsyms_global
= nsyms
;
833 last_source_file
= 0;
834 bzero (opaque_type_chain
, sizeof opaque_type_chain
);
836 if (type_vector
) /* Get rid of previous one */
838 type_vector_length
= 160;
839 type_vector
= (struct typevector
*)
840 xmalloc (sizeof (struct typevector
)
841 + type_vector_length
* sizeof (struct type
*));
842 bzero (type_vector
->type
, type_vector_length
* sizeof (struct type
*));
847 while (symnum
< nsyms
)
849 QUIT
; /* Make this command interruptable. */
850 read_one_sym (cs
, &main_sym
, &main_aux
);
853 temp_sem_val
= cs
->c_name
[0] << 24 | cs
->c_name
[1] << 16 |
854 cs
->c_name
[2] << 8 | cs
->c_name
[3];
855 if (int_sem_val
== temp_sem_val
)
856 last_coffsem
= (int) strtol (cs
->c_name
+4, (char **) NULL
, 10);
859 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
861 if (last_source_file
)
865 complete_symtab ("_globals_", 0, first_object_file_end
);
866 /* done with all files, everything from here on out is globals */
869 /* Special case for file with type declarations only, no text. */
870 if (!last_source_file
&& SDB_TYPE (cs
->c_type
)
871 && cs
->c_secnum
== N_DEBUG
)
872 complete_symtab (filestring
, 0, 0);
874 /* Typedefs should not be treated as symbol definitions. */
875 if (ISFCN (cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
877 /* record as misc function. if we get '.bf' next,
878 * then we undo this step
880 record_misc_function (cs
->c_name
, cs
->c_value
);
882 fcn_line_ptr
= main_aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
883 fcn_start_addr
= cs
->c_value
;
885 fcn_sym_saved
= main_sym
;
886 fcn_aux_saved
= main_aux
;
890 switch (cs
->c_sclass
)
899 printf ("Bad n_sclass = %d\n", cs
->c_sclass
);
904 * c_value field contains symnum of next .file entry in table
905 * or symnum of first global after last .file.
907 next_file_symnum
= cs
->c_value
;
908 filestring
= getfilename (&main_aux
);
910 * Complete symbol table for last object file
911 * containing debugging information.
913 if (last_source_file
)
922 if (cs
->c_name
[0] == '.') {
923 if (strcmp (cs
->c_name
, _TEXT
) == 0) {
924 if (++num_object_files
== 1) {
925 /* last address of startup file */
926 first_object_file_end
= cs
->c_value
+
927 main_aux
.x_scn
.x_scnlen
;
929 /* Check for in_source_file deals with case of
930 a file with debugging symbols
931 followed by a later file with no symbols. */
933 complete_symtab (filestring
, cs
->c_value
,
934 main_aux
.x_scn
.x_scnlen
);
937 /* flush rest of '.' symbols */
940 else if (!SDB_TYPE (cs
->c_type
)
941 && cs
->c_name
[0] == 'L'
942 && (strncmp (cs
->c_name
, "LI%", 3) == 0
943 || strncmp (cs
->c_name
, "LF%", 3) == 0
944 || strncmp (cs
->c_name
,"LC%",3) == 0
945 || strncmp (cs
->c_name
,"LP%",3) == 0
946 || strncmp (cs
->c_name
,"LPB%",4) == 0
947 || strncmp (cs
->c_name
,"LBB%",4) == 0
948 || strncmp (cs
->c_name
,"LBE%",4) == 0
949 || strncmp (cs
->c_name
,"LPBX%",5) == 0))
950 /* At least on a 3b1, gcc generates swbeg and string labels
951 that look like this. Ignore them. */
953 /* fall in for static symbols that don't start with '.' */
955 if (cs
->c_sclass
== C_EXT
&&
956 cs
->c_secnum
== N_ABS
&&
957 strcmp (cs
->c_name
, _ETEXT
) == 0)
958 end_of_text_addr
= cs
->c_value
;
959 if (!SDB_TYPE (cs
->c_type
)) {
960 if (cs
->c_secnum
<= 1) { /* text or abs */
961 record_misc_function (cs
->c_name
, cs
->c_value
);
967 (void) process_coff_symbol (cs
, &main_aux
);
971 if (strcmp (cs
->c_name
, ".bf") == 0)
975 /* value contains address of first non-init type code */
976 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
977 contains line number of '{' } */
978 fcn_first_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
980 new = (struct context_stack
*)
981 xmalloc (sizeof (struct context_stack
));
982 new->depth
= depth
= 0;
986 new->old_blocks
= pending_blocks
;
987 new->start_addr
= fcn_start_addr
;
988 fcn_cs_saved
.c_name
= getsymname (&fcn_sym_saved
);
989 new->name
= process_coff_symbol (&fcn_cs_saved
,
992 else if (strcmp (cs
->c_name
, ".ef") == 0)
994 /* the value of .ef is the address of epilogue code;
997 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
998 contains number of lines to '}' */
1002 complain (&ef_complaint
, cs
->c_symnum
);
1003 within_function
= 0;
1006 fcn_last_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
1007 enter_linenos (fcn_line_ptr
, fcn_first_line
, fcn_last_line
);
1009 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1011 #if defined (FUNCTION_EPILOGUE_SIZE)
1012 /* This macro should be defined only on
1014 fcn_aux_saved.x_sym.x_misc.x_fsize
1015 field is always zero.
1016 So use the .bf record information that
1017 points to the epilogue and add the size
1019 cs
->c_value
+ FUNCTION_EPILOGUE_SIZE
1021 fcn_cs_saved
.c_value
+
1022 fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1026 within_function
= 0;
1032 if (strcmp (cs
->c_name
, ".bb") == 0)
1034 new = (struct context_stack
*)
1035 xmalloc (sizeof (struct context_stack
));
1038 new->next
= context_stack
;
1039 context_stack
= new;
1040 new->locals
= local_symbols
;
1041 new->old_blocks
= pending_blocks
;
1042 new->start_addr
= cs
->c_value
;
1046 else if (strcmp (cs
->c_name
, ".eb") == 0)
1048 new = context_stack
;
1049 if (new == 0 || depth
!= new->depth
)
1050 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1052 if (local_symbols
&& context_stack
->next
)
1054 /* Make a block for the local symbols within. */
1055 finish_block (0, &local_symbols
, new->old_blocks
,
1056 new->start_addr
, cs
->c_value
);
1059 local_symbols
= new->locals
;
1060 context_stack
= new->next
;
1067 /* This isn't used currently. */
1068 if (strcmp (cs
->c_name
, ".coffsyn") == 0)
1069 last_coffsyn
= cs
->c_value
;
1072 if ((strcmp (cs
->c_name
, ".coffsem") == 0) &&
1074 last_coffsem
= cs
->c_value
;
1080 if ((strcmp (cs
->c_name
, ".coffsem") == 0) &&
1082 last_coffsem
= cs
->c_value
;
1085 (void) process_coff_symbol (cs
, &main_aux
);
1090 if (last_source_file
)
1093 discard_cleanups (old_chain
);
1096 /* Routines for reading headers and symbols from executable. */
1099 /* Move these XXXMAGIC symbol defns into BFD! */
1101 /* Read COFF file header, check magic number,
1102 and return number of symbols. */
1103 read_file_hdr (chan
, file_hdr
)
1107 lseek (chan
, 0L, 0);
1108 if (myread (chan
, (char *)file_hdr
, FILHSZ
) < 0)
1111 switch (file_hdr
->f_magic
)
1126 #if defined (MC68KWRMAGIC) \
1127 && (!defined (MC68MAGIC) || MC68KWRMAGIC != MC68MAGIC)
1141 case I960ROMAGIC
: /* Intel 960 */
1144 case I960RWMAGIC
: /* Intel 960 */
1146 return file_hdr
->f_nsyms
;
1150 if (BADMAG(file_hdr
))
1153 return file_hdr
->f_nsyms
;
1161 /* Read the next symbol, swap it, and return it in both internal_syment
1162 form, and coff_symbol form. Also return its first auxent, if any,
1163 in internal_auxent form, and skip any other auxents. */
1166 read_one_sym (cs
, sym
, aux
)
1167 register struct coff_symbol
*cs
;
1168 register struct internal_syment
*sym
;
1169 register union internal_auxent
*aux
;
1171 struct external_syment temp_sym
[1];
1172 union external_auxent temp_aux
[1];
1175 cs
->c_symnum
= symnum
;
1176 fread ((char *)temp_sym
, SYMESZ
, 1, nlist_stream_global
);
1177 bfd_coff_swap_sym_in (symfile_bfd
, temp_sym
, sym
);
1178 cs
->c_nsyms
= (sym
->n_numaux
& 0xff) + 1;
1179 if (cs
->c_nsyms
>= 2)
1181 fread ((char *)temp_aux
, AUXESZ
, 1, nlist_stream_global
);
1182 bfd_coff_swap_aux_in (symfile_bfd
, temp_aux
, sym
->n_type
, sym
->n_sclass
, aux
);
1183 /* If more than one aux entry, read past it (only the first aux
1185 for (i
= 2; i
< cs
->c_nsyms
; i
++)
1186 fread ((char *)temp_aux
, AUXESZ
, 1, nlist_stream_global
);
1188 cs
->c_name
= getsymname (sym
);
1189 cs
->c_value
= sym
->n_value
;
1190 cs
->c_sclass
= (sym
->n_sclass
& 0xff);
1191 cs
->c_secnum
= sym
->n_scnum
;
1192 cs
->c_type
= (unsigned) sym
->n_type
;
1193 if (!SDB_TYPE (cs
->c_type
))
1196 symnum
+= cs
->c_nsyms
;
1199 /* Support for string table handling */
1201 static char *stringtab
= NULL
;
1204 init_stringtab (chan
, offset
)
1210 unsigned char lengthbuf
[4];
1218 if (lseek (chan
, offset
, 0) < 0)
1221 val
= myread (chan
, (char *)lengthbuf
, sizeof lengthbuf
);
1222 length
= bfd_h_get_32 (symfile_bfd
, lengthbuf
);
1224 /* If no string table is needed, then the file may end immediately
1225 after the symbols. Just return with `stringtab' set to null. */
1226 if (val
!= sizeof length
|| length
< sizeof length
)
1229 stringtab
= (char *) xmalloc (length
);
1230 if (stringtab
== NULL
)
1233 bcopy (&length
, stringtab
, sizeof length
);
1234 if (length
== sizeof length
) /* Empty table -- just the count */
1237 val
= myread (chan
, stringtab
+ sizeof length
, length
- sizeof length
);
1238 if (val
!= length
- sizeof length
|| stringtab
[length
- 1] != '\0')
1253 getsymname (symbol_entry
)
1254 struct internal_syment
*symbol_entry
;
1256 static char buffer
[SYMNMLEN
+1];
1259 if (symbol_entry
->_n
._n_n
._n_zeroes
== 0)
1261 result
= stringtab
+ symbol_entry
->_n
._n_n
._n_offset
;
1265 strncpy (buffer
, symbol_entry
->_n
._n_name
, SYMNMLEN
);
1266 buffer
[SYMNMLEN
] = '\0';
1273 getfilename (aux_entry
)
1274 union internal_auxent
*aux_entry
;
1276 static char buffer
[BUFSIZ
];
1277 register char *temp
;
1279 extern char *rindex ();
1281 #ifndef COFF_NO_LONG_FILE_NAMES
1282 #if defined (x_zeroes)
1284 if (aux_entry
->x_zeroes
== 0)
1285 strcpy (buffer
, stringtab
+ aux_entry
->x_offset
);
1286 #else /* no x_zeroes */
1287 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1288 strcpy (buffer
, stringtab
+ aux_entry
->x_file
.x_n
.x_offset
);
1289 #endif /* no x_zeroes */
1291 #endif /* COFF_NO_LONG_FILE_NAMES */
1293 #if defined (x_name)
1295 strncpy (buffer
, aux_entry
->x_name
, FILNMLEN
);
1297 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1299 buffer
[FILNMLEN
] = '\0';
1302 if ((temp
= rindex (result
, '/')) != NULL
)
1307 /* Support for line number handling */
1308 static char *linetab
= NULL
;
1309 static long linetab_offset
;
1310 static unsigned long linetab_size
;
1312 /* Read in all the line numbers for fast lookups later. Leave them in
1313 external (unswapped) format in memory; we'll swap them as we enter
1314 them into GDB's data structures. */
1317 init_lineno (chan
, offset
, size
)
1324 linetab_offset
= offset
;
1325 linetab_size
= size
;
1330 if (lseek (chan
, offset
, 0) < 0)
1333 linetab
= (char *) xmalloc (size
);
1335 val
= myread (chan
, linetab
, size
);
1339 make_cleanup (free
, linetab
); /* Be sure it gets de-allocated. */
1343 #if !defined (L_LNNO32)
1344 #define L_LNNO32(lp) ((lp)->l_lnno)
1348 enter_linenos (file_offset
, first_line
, last_line
)
1350 register int first_line
;
1351 register int last_line
;
1353 register char *rawptr
;
1354 struct internal_lineno lptr
;
1356 if (file_offset
< linetab_offset
)
1358 complain (&lineno_complaint
, file_offset
);
1359 if (file_offset
> linetab_size
) /* Too big to be an offset? */
1361 file_offset
+= linetab_offset
; /* Try reading at that linetab offset */
1364 rawptr
= &linetab
[file_offset
- linetab_offset
];
1366 /* skip first line entry for each function */
1368 /* line numbers start at one for the first line of the function */
1372 bfd_coff_swap_lineno_in (symfile_bfd
, (LINENO
*)rawptr
, &lptr
);
1374 if (L_LNNO32 (&lptr
) && L_LNNO32 (&lptr
) <= last_line
)
1375 record_line (first_line
+ L_LNNO32 (&lptr
), lptr
.l_addr
.l_paddr
);
1385 register char *p
= name
;
1386 register int total
= p
[0];
1399 return total
% HASHSIZE
;
1403 patch_type (type
, real_type
)
1405 struct type
*real_type
;
1407 register struct type
*target
= TYPE_TARGET_TYPE (type
);
1408 register struct type
*real_target
= TYPE_TARGET_TYPE (real_type
);
1409 int field_size
= TYPE_NFIELDS (real_target
) * sizeof (struct field
);
1411 TYPE_LENGTH (target
) = TYPE_LENGTH (real_target
);
1412 TYPE_NFIELDS (target
) = TYPE_NFIELDS (real_target
);
1413 TYPE_FIELDS (target
) = (struct field
*)
1414 obstack_alloc (symbol_obstack
, field_size
);
1416 bcopy (TYPE_FIELDS (real_target
), TYPE_FIELDS (target
), field_size
);
1418 if (TYPE_NAME (real_target
))
1420 if (TYPE_NAME (target
))
1421 free (TYPE_NAME (target
));
1422 TYPE_NAME (target
) = concat (TYPE_NAME (real_target
), "", "");
1426 /* Patch up all appropriate typdef symbols in the opaque_type_chains
1427 so that they can be used to print out opaque data structures properly */
1430 patch_opaque_types ()
1434 /* Look at each symbol in the per-file block of each symtab. */
1435 for (s
= symtab_list
; s
; s
= s
->next
)
1437 register struct block
*b
;
1440 /* Go through the per-file symbols only */
1441 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
1442 for (i
= BLOCK_NSYMS (b
) - 1; i
>= 0; i
--)
1444 register struct symbol
*real_sym
;
1446 /* Find completed typedefs to use to fix opaque ones.
1447 Remove syms from the chain when their types are stored,
1448 but search the whole chain, as there may be several syms
1449 from different files with the same name. */
1450 real_sym
= BLOCK_SYM (b
, i
);
1451 if (SYMBOL_CLASS (real_sym
) == LOC_TYPEDEF
&&
1452 SYMBOL_NAMESPACE (real_sym
) == VAR_NAMESPACE
&&
1453 TYPE_CODE (SYMBOL_TYPE (real_sym
)) == TYPE_CODE_PTR
&&
1454 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym
))) != 0)
1456 register char *name
= SYMBOL_NAME (real_sym
);
1457 register int hash
= hashname (name
);
1458 register struct symbol
*sym
, *prev
;
1461 for (sym
= opaque_type_chain
[hash
]; sym
;)
1463 if (name
[0] == SYMBOL_NAME (sym
)[0] &&
1464 !strcmp (name
+ 1, SYMBOL_NAME (sym
) + 1))
1467 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
1469 opaque_type_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
1471 patch_type (SYMBOL_TYPE (sym
), SYMBOL_TYPE (real_sym
));
1474 sym
= SYMBOL_VALUE_CHAIN (prev
);
1476 sym
= opaque_type_chain
[hash
];
1481 sym
= SYMBOL_VALUE_CHAIN (sym
);
1489 #if defined (clipper)
1490 #define BELIEVE_PCC_PROMOTION 1
1493 static struct symbol
*
1494 process_coff_symbol (cs
, aux
)
1495 register struct coff_symbol
*cs
;
1496 register union internal_auxent
*aux
;
1498 register struct symbol
*sym
1499 = (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
1501 #ifdef NAMES_HAVE_UNDERSCORE
1507 bzero (sym
, sizeof (struct symbol
));
1509 name
= (name
[0] == '_' ? name
+ offset
: name
);
1510 SYMBOL_NAME (sym
) = obstack_copy0 (symbol_obstack
, name
, strlen (name
));
1512 /* default assumptions */
1513 SYMBOL_VALUE (sym
) = cs
->c_value
;
1514 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1516 if (ISFCN (cs
->c_type
))
1519 lookup_function_type (decode_function_type (cs
, cs
->c_type
, aux
));
1520 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1521 if (cs
->c_sclass
== C_STAT
)
1522 add_symbol_to_list (sym
, &file_symbols
);
1523 else if (cs
->c_sclass
== C_EXT
)
1524 add_symbol_to_list (sym
, &global_symbols
);
1528 SYMBOL_TYPE (sym
) = decode_type (cs
, cs
->c_type
, aux
);
1529 switch (cs
->c_sclass
)
1535 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1536 add_symbol_to_list (sym
, &local_symbols
);
1540 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1541 SYMBOL_VALUE_ADDRESS (sym
) = (CORE_ADDR
) cs
->c_value
;
1542 add_symbol_to_list (sym
, &global_symbols
);
1546 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1547 SYMBOL_VALUE_ADDRESS (sym
) = (CORE_ADDR
) cs
->c_value
;
1548 if (within_function
) {
1549 /* Static symbol of local scope */
1550 add_symbol_to_list (sym
, &local_symbols
);
1553 /* Static symbol at top level of file */
1554 add_symbol_to_list (sym
, &file_symbols
);
1559 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1560 add_symbol_to_list (sym
, &local_symbols
);
1567 SYMBOL_CLASS (sym
) = LOC_ARG
;
1568 add_symbol_to_list (sym
, &local_symbols
);
1569 #if !defined (BELIEVE_PCC_PROMOTION)
1570 /* If PCC says a parameter is a short or a char,
1571 it is really an int. */
1572 if (SYMBOL_TYPE (sym
) == builtin_type_char
1573 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1574 SYMBOL_TYPE (sym
) = builtin_type_int
;
1575 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1576 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1577 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1582 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1583 add_symbol_to_list (sym
, &local_symbols
);
1584 #if !defined (BELIEVE_PCC_PROMOTION)
1585 /* If PCC says a parameter is a short or a char,
1586 it is really an int. */
1587 if (SYMBOL_TYPE (sym
) == builtin_type_char
1588 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1589 SYMBOL_TYPE (sym
) = builtin_type_int
;
1590 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1591 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1592 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1597 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1598 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1600 /* If type has no name, give it one */
1601 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1602 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1603 TYPE_NAME (SYMBOL_TYPE (sym
))
1604 = concat (SYMBOL_NAME (sym
), "", "");
1606 /* Keep track of any type which points to empty structured type,
1607 so it can be filled from a definition from another file */
1608 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
&&
1609 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym
))) == 0)
1611 register int i
= hashname (SYMBOL_NAME (sym
));
1613 SYMBOL_VALUE_CHAIN (sym
) = opaque_type_chain
[i
];
1614 opaque_type_chain
[i
] = sym
;
1616 add_symbol_to_list (sym
, &file_symbols
);
1622 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1623 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1624 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1625 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1626 TYPE_NAME (SYMBOL_TYPE (sym
))
1628 (cs
->c_sclass
== C_ENTAG
1630 : (cs
->c_sclass
== C_STRTAG
1631 ? "struct " : "union ")),
1633 add_symbol_to_list (sym
, &file_symbols
);
1643 /* Decode a coff type specifier;
1644 return the type that is meant. */
1648 decode_type (cs
, c_type
, aux
)
1649 register struct coff_symbol
*cs
;
1650 unsigned int c_type
;
1651 register union internal_auxent
*aux
;
1653 register struct type
*type
= 0;
1654 unsigned int new_c_type
;
1656 if (c_type
& ~N_BTMASK
)
1658 new_c_type
= DECREF (c_type
);
1661 type
= decode_type (cs
, new_c_type
, aux
);
1662 type
= lookup_pointer_type (type
);
1664 else if (ISFCN (c_type
))
1666 type
= decode_type (cs
, new_c_type
, aux
);
1667 type
= lookup_function_type (type
);
1669 else if (ISARY (c_type
))
1672 register unsigned short *dim
;
1673 struct type
*base_type
;
1675 /* Define an array type. */
1676 /* auxent refers to array, not base type */
1677 if (aux
->x_sym
.x_tagndx
.l
== 0)
1680 /* shift the indices down */
1681 dim
= &aux
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0];
1684 for (i
= 0; *dim
&& i
< DIMNUM
- 1; i
++, dim
++)
1688 type
= (struct type
*)
1689 obstack_alloc (symbol_obstack
, sizeof (struct type
));
1690 bzero (type
, sizeof (struct type
));
1692 base_type
= decode_type (cs
, new_c_type
, aux
);
1694 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
1695 TYPE_TARGET_TYPE (type
) = base_type
;
1696 TYPE_LENGTH (type
) = n
* TYPE_LENGTH (base_type
);
1701 /* Reference to existing type */
1702 if (cs
->c_nsyms
> 1 && aux
->x_sym
.x_tagndx
.l
!= 0)
1704 type
= coff_alloc_type (aux
->x_sym
.x_tagndx
.l
);
1708 return decode_base_type (cs
, BTYPE (c_type
), aux
);
1711 /* Decode a coff type specifier for function definition;
1712 return the type that the function returns. */
1716 decode_function_type (cs
, c_type
, aux
)
1717 register struct coff_symbol
*cs
;
1718 unsigned int c_type
;
1719 register union internal_auxent
*aux
;
1721 if (aux
->x_sym
.x_tagndx
.l
== 0)
1722 cs
->c_nsyms
= 1; /* auxent refers to function, not base type */
1724 return decode_type (cs
, DECREF (c_type
), aux
);
1731 decode_base_type (cs
, c_type
, aux
)
1732 register struct coff_symbol
*cs
;
1733 unsigned int c_type
;
1734 register union internal_auxent
*aux
;
1741 /* shows up with "void (*foo)();" structure members */
1742 return builtin_type_void
;
1745 /* DGUX actually defines both T_ARG and T_VOID to the same value. */
1748 /* Shows up in DGUX, I think. Not sure where. */
1749 return builtin_type_void
; /* shouldn't show up here */
1755 /* Intel 960 COFF has this symbol and meaning. */
1756 return builtin_type_void
;
1760 return builtin_type_char
;
1763 return builtin_type_short
;
1766 return builtin_type_int
;
1769 return builtin_type_long
;
1772 return builtin_type_float
;
1775 return builtin_type_double
;
1778 if (cs
->c_nsyms
!= 2)
1780 /* anonymous structure type */
1781 type
= coff_alloc_type (cs
->c_symnum
);
1782 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1783 TYPE_NAME (type
) = concat ("struct ", "<opaque>", "");
1784 TYPE_LENGTH (type
) = 0;
1785 TYPE_FIELDS (type
) = 0;
1786 TYPE_NFIELDS (type
) = 0;
1790 type
= read_struct_type (cs
->c_symnum
,
1791 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1792 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1797 if (cs
->c_nsyms
!= 2)
1799 /* anonymous union type */
1800 type
= coff_alloc_type (cs
->c_symnum
);
1801 TYPE_NAME (type
) = concat ("union ", "<opaque>", "");
1802 TYPE_LENGTH (type
) = 0;
1803 TYPE_FIELDS (type
) = 0;
1804 TYPE_NFIELDS (type
) = 0;
1808 type
= read_struct_type (cs
->c_symnum
,
1809 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1810 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1812 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1816 return read_enum_type (cs
->c_symnum
,
1817 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1818 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1821 /* shouldn't show up here */
1825 return builtin_type_unsigned_char
;
1828 return builtin_type_unsigned_short
;
1831 return builtin_type_unsigned_int
;
1834 return builtin_type_unsigned_long
;
1836 printf ("unexpected type %d at symnum %d\n", c_type
, cs
->c_symnum
);
1837 return builtin_type_void
;
1840 /* This page contains subroutines of read_type. */
1842 /* Read the description of a structure (or union type)
1843 and return an object describing the type. */
1845 static struct type
*
1846 read_struct_type (index
, length
, lastsym
)
1853 struct nextfield
*next
;
1857 register struct type
*type
;
1858 register struct nextfield
*list
= 0;
1859 struct nextfield
*new;
1863 #ifdef NAMES_HAVE_UNDERSCORE
1868 struct coff_symbol member_sym
;
1869 register struct coff_symbol
*ms
= &member_sym
;
1870 struct internal_syment sub_sym
;
1871 union internal_auxent sub_aux
;
1874 type
= coff_alloc_type (index
);
1875 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1876 TYPE_LENGTH (type
) = length
;
1878 while (!done
&& symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
1880 read_one_sym (ms
, &sub_sym
, &sub_aux
);
1882 name
= (name
[0] == '_' ? name
+ offset
: name
);
1884 switch (ms
->c_sclass
)
1889 /* Get space to record the next field's data. */
1890 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1894 /* Save the data. */
1895 list
->field
.name
= savestring (name
, strlen (name
));
1896 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1897 list
->field
.bitpos
= 8 * ms
->c_value
;
1898 list
->field
.bitsize
= 0;
1904 /* Get space to record the next field's data. */
1905 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1909 /* Save the data. */
1910 list
->field
.name
= savestring (name
, strlen (name
));
1911 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1912 list
->field
.bitpos
= ms
->c_value
;
1913 list
->field
.bitsize
= sub_aux
.x_sym
.x_misc
.x_lnsz
.x_size
;
1922 /* Now create the vector of fields, and record how big it is. */
1924 TYPE_NFIELDS (type
) = nfields
;
1925 TYPE_FIELDS (type
) = (struct field
*)
1926 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nfields
);
1928 /* Copy the saved-up fields into the field vector. */
1930 for (n
= nfields
; list
; list
= list
->next
)
1931 TYPE_FIELD (type
, --n
) = list
->field
;
1936 /* Read a definition of an enumeration type,
1937 and create and return a suitable type object.
1938 Also defines the symbols that represent the values of the type. */
1939 /* Currently assumes it's sizeof (int) and doesn't use length. */
1942 static struct type
*
1943 read_enum_type (index
, length
, lastsym
)
1948 register struct symbol
*sym
;
1949 register struct type
*type
;
1952 struct pending
**symlist
;
1953 struct coff_symbol member_sym
;
1954 register struct coff_symbol
*ms
= &member_sym
;
1955 struct internal_syment sub_sym
;
1956 union internal_auxent sub_aux
;
1957 struct pending
*osyms
, *syms
;
1960 #ifdef NAMES_HAVE_UNDERSCORE
1966 type
= coff_alloc_type (index
);
1967 if (within_function
)
1968 symlist
= &local_symbols
;
1970 symlist
= &file_symbols
;
1973 while (!done
&& symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
1975 read_one_sym (ms
, &sub_sym
, &sub_aux
);
1977 name
= (name
[0] == '_' ? name
+ offset
: name
);
1979 switch (ms
->c_sclass
)
1982 sym
= (struct symbol
*) xmalloc (sizeof (struct symbol
));
1983 bzero (sym
, sizeof (struct symbol
));
1985 SYMBOL_NAME (sym
) = savestring (name
, strlen (name
));
1986 SYMBOL_CLASS (sym
) = LOC_CONST
;
1987 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1988 SYMBOL_VALUE (sym
) = ms
->c_value
;
1989 add_symbol_to_list (sym
, symlist
);
1994 /* Sometimes the linker (on 386/ix 2.0.2 at least) screws
1995 up the count of how many symbols to read. So stop
2002 /* Now fill in the fields of the type-structure. */
2004 /* FIXME: Should be sizeof (int) on target, not host. */
2005 TYPE_LENGTH (type
) = sizeof (int);
2006 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2007 TYPE_NFIELDS (type
) = nsyms
;
2008 TYPE_FIELDS (type
) = (struct field
*)
2009 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nsyms
);
2011 /* Find the symbols for the values and put them into the type.
2012 The symbols can be found in the symlist that we put them on
2013 to cause them to be defined. osyms contains the old value
2014 of that symlist; everything up to there was defined by us. */
2016 for (syms
= *symlist
, n
= nsyms
; syms
!= osyms
; syms
= syms
->next
)
2018 SYMBOL_TYPE (syms
->symbol
) = type
;
2019 TYPE_FIELD_NAME (type
, --n
) = SYMBOL_NAME (syms
->symbol
);
2020 TYPE_FIELD_VALUE (type
, n
) = 0;
2021 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (syms
->symbol
);
2022 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2027 /* Register our ability to parse symbols for coff BFD files */
2029 static struct sym_fns coff_sym_fns
=
2031 /* This assumes that 88kbcs implies TDESC and TDESC implies 88kbcs.
2032 If that's not true, this can be relaxed, but if it is true,
2033 it will just cause users grief if we try to read the wrong kind
2037 #else /* not TDESC */
2039 #endif /* not TDESC */
2040 coff_new_init
, coff_symfile_init
, coff_symfile_read
,
2044 _initialize_coffread ()
2046 add_symtab_fns(&coff_sym_fns
);