1 /* Read coff symbol tables and convert to internal format, for GDB.
2 Contributed by David D. Johnson, Brown University (ddj@cs.brown.edu).
3 Copyright (C) 1987-1991 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #include "breakpoint.h"
30 /* Need to get C_VERSION and friends. FIXME, should be in internalcoff.h */
32 #endif /* not TDESC */
37 #include "internalcoff.h" /* Internal format of COFF symbols in BFD */
38 #include "libcoff.h" /* FIXME secret internal data from BFD */
40 static void add_symbol_to_list ();
41 static void read_coff_symtab ();
42 static void patch_opaque_types ();
43 static struct type
*decode_function_type ();
44 static struct type
*decode_type ();
45 static struct type
*decode_base_type ();
46 static struct type
*read_enum_type ();
47 static struct type
*read_struct_type ();
48 static void finish_block ();
49 static struct blockvector
*make_blockvector ();
50 static struct symbol
*process_coff_symbol ();
51 static int init_stringtab ();
52 static void free_stringtab ();
53 static char *getfilename ();
54 static char *getsymname ();
55 static int init_lineno ();
56 static void enter_linenos ();
57 static void read_one_sym ();
60 extern void free_all_symtabs ();
61 extern void free_all_psymtabs ();
63 /* To be an sdb debug type, type must have at least a basic or primary
64 derived type. Using this rather than checking against T_NULL is
65 said to prevent core dumps if we try to operate on Michael Bloom
68 #define SDB_TYPE(type) (BTYPE(type) | (type & N_TMASK))
71 * Convert from an sdb register number to an internal gdb register number.
72 * This should be defined in tm.h, if REGISTER_NAMES is not set up
73 * to map one to one onto the sdb register numbers.
75 #ifndef SDB_REG_TO_REGNUM
76 # define SDB_REG_TO_REGNUM(value) (value)
79 /* Name of source file whose symbol data we are now processing.
80 This comes from a symbol named ".file". */
82 static char *last_source_file
;
84 /* Core address of start and end of text of current source file.
85 This comes from a ".text" symbol where x_nlinno > 0. */
87 static CORE_ADDR cur_src_start_addr
;
88 static CORE_ADDR cur_src_end_addr
;
90 /* Core address of the end of the first object file. */
91 static CORE_ADDR first_object_file_end
;
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 index in the symbol table of the last coff symbol that was processed. */
103 /* Vector of types defined so far, indexed by their coff symnum. */
105 static struct type
**type_vector
;
107 /* Number of elements allocated for type_vector currently. */
109 static int type_vector_length
;
111 /* Vector of line number information. */
113 static struct linetable
*line_vector
;
115 /* Index of next entry to go in line_vector_index. */
117 static int line_vector_index
;
119 /* Last line number recorded in the line vector. */
121 static int prev_line_number
;
123 /* Number of elements allocated for line_vector currently. */
125 static int line_vector_length
;
127 /* Pointers to scratch storage, used for reading raw symbols and auxents. */
129 static char *temp_sym
;
130 static char *temp_aux
;
132 /* Local variables that hold the shift and mask values for the
133 COFF file that we are currently reading. These come back to us
134 from BFD, and are referenced by their macro names, as well as
135 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
136 macros from ../internalcoff.h . */
138 static unsigned local_n_btmask
;
139 static unsigned local_n_btshft
;
140 static unsigned local_n_tmask
;
141 static unsigned local_n_tshift
;
143 #define N_BTMASK local_n_btmask
144 #define N_BTSHFT local_n_btshft
145 #define N_TMASK local_n_tmask
146 #define N_TSHIFT local_n_tshift
148 /* Local variables that hold the sizes in the file of various COFF structures.
149 (We only need to know this to read them from the file -- BFD will then
150 translate the data in them, into `internal_xxx' structs in the right
151 byte order, alignment, etc.) */
153 static unsigned local_linesz
;
154 static unsigned local_symesz
;
155 static unsigned local_auxesz
;
161 int int_sem_val
= 's' << 24 | 'e' << 16 | 'm' << 8 | '.';
163 int last_coffsem
= 2;
165 /* This isn't used currently. */
166 int last_coffsyn
= 0;
168 int debug_info
= 0; /*used by tdesc */
169 extern dc_dcontext_t tdesc_handle
;
170 extern int safe_to_init_tdesc_context
;
173 /* Chain of typedefs of pointers to empty struct/union types.
174 They are chained thru the SYMBOL_VALUE_CHAIN. */
177 static struct symbol
*opaque_type_chain
[HASHSIZE
];
179 /* Record the symbols defined for each context in a list.
180 We don't create a struct block for the context until we
181 know how long to make it. */
185 struct pending
*next
;
186 struct symbol
*symbol
;
189 /* Here are the three lists that symbols are put on. */
191 struct pending
*file_symbols
; /* static at top level, and types */
193 struct pending
*global_symbols
; /* global functions and variables */
195 struct pending
*local_symbols
; /* everything local to lexical context */
197 /* List of unclosed lexical contexts
198 (that will become blocks, eventually). */
202 struct context_stack
*next
;
203 struct pending
*locals
;
204 struct pending_block
*old_blocks
;
206 CORE_ADDR start_addr
;
210 struct context_stack
*context_stack
;
212 /* Nonzero if within a function (so symbols should be local,
213 if nothing says specifically). */
218 /* The type of the function we are currently reading in. This is
219 used by define_symbol to record the type of arguments to a function. */
221 struct type
*in_function_type
;
224 /* List of blocks already made (lexical contexts already closed).
225 This is used at the end to make the blockvector. */
229 struct pending_block
*next
;
233 struct pending_block
*pending_blocks
;
235 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
236 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
238 /* Complaints about various problems in the file being read */
240 struct complaint ef_complaint
=
241 {"Unmatched .ef symbol(s) ignored starting at symnum %d", 0, 0};
243 struct complaint lineno_complaint
=
244 {"Line number pointer %d lower than start of line numbers", 0, 0};
247 /* Look up a coff type-number index. Return the address of the slot
248 where the type for that index is stored.
249 The type-number is in INDEX.
251 This can be used for finding the type associated with that index
252 or for associating a new type with the index. */
254 static struct type
**
255 coff_lookup_type (index
)
258 if (index
>= type_vector_length
)
260 int old_vector_length
= type_vector_length
;
262 type_vector_length
*= 2;
263 if (type_vector_length
< index
) {
264 type_vector_length
= index
* 2;
266 type_vector
= (struct type
**)
267 xrealloc (type_vector
, type_vector_length
* sizeof (struct type
*));
268 bzero (&type_vector
[old_vector_length
],
269 (type_vector_length
- old_vector_length
) * sizeof(struct type
*));
271 return &type_vector
[index
];
274 /* Make sure there is a type allocated for type number index
275 and return the type object.
276 This can create an empty (zeroed) type object. */
279 coff_alloc_type (index
)
282 register struct type
**type_addr
= coff_lookup_type (index
);
283 register struct type
*type
= *type_addr
;
285 /* If we are referring to a type not known at all yet,
286 allocate an empty type for it.
287 We will fill it in later if we find out how. */
290 type
= (struct type
*) obstack_alloc (symbol_obstack
,
291 sizeof (struct type
));
292 bzero (type
, sizeof (struct type
));
293 TYPE_VPTR_FIELDNO (type
) = -1;
299 /* maintain the lists of symbols and blocks */
301 /* Add a symbol to one of the lists of symbols. */
303 add_symbol_to_list (symbol
, listhead
)
304 struct symbol
*symbol
;
305 struct pending
**listhead
;
307 register struct pending
*link
308 = (struct pending
*) xmalloc (sizeof (struct pending
));
310 link
->next
= *listhead
;
311 link
->symbol
= symbol
;
315 /* Take one of the lists of symbols and make a block from it.
316 Put the block on the list of pending blocks. */
319 finish_block (symbol
, listhead
, old_blocks
, start
, end
)
320 struct symbol
*symbol
;
321 struct pending
**listhead
;
322 struct pending_block
*old_blocks
;
323 CORE_ADDR start
, end
;
325 register struct pending
*next
, *next1
;
326 register struct block
*block
;
327 register struct pending_block
*pblock
;
328 struct pending_block
*opblock
;
331 /* Count the length of the list of symbols. */
333 for (next
= *listhead
, i
= 0; next
; next
= next
->next
, i
++);
335 block
= (struct block
*)
336 obstack_alloc (symbol_obstack
, sizeof (struct block
) + (i
- 1) * sizeof (struct symbol
*));
338 /* Copy the symbols into the block. */
340 BLOCK_NSYMS (block
) = i
;
341 for (next
= *listhead
; next
; next
= next
->next
)
342 BLOCK_SYM (block
, --i
) = next
->symbol
;
344 BLOCK_START (block
) = start
;
345 BLOCK_END (block
) = end
;
346 BLOCK_SUPERBLOCK (block
) = 0; /* Filled in when containing block is made */
348 /* Put the block in as the value of the symbol that names it. */
352 SYMBOL_BLOCK_VALUE (symbol
) = block
;
353 BLOCK_FUNCTION (block
) = symbol
;
356 BLOCK_FUNCTION (block
) = 0;
358 /* Now free the links of the list, and empty the list. */
360 for (next
= *listhead
; next
; next
= next1
)
367 /* Install this block as the superblock
368 of all blocks made since the start of this scope
369 that don't have superblocks yet. */
372 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
374 if (BLOCK_SUPERBLOCK (pblock
->block
) == 0)
375 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
379 /* Record this block on the list of all blocks in the file.
380 Put it after opblock, or at the beginning if opblock is 0.
381 This puts the block in the list after all its subblocks. */
383 pblock
= (struct pending_block
*) xmalloc (sizeof (struct pending_block
));
384 pblock
->block
= block
;
387 pblock
->next
= opblock
->next
;
388 opblock
->next
= pblock
;
392 pblock
->next
= pending_blocks
;
393 pending_blocks
= pblock
;
397 static struct blockvector
*
400 register struct pending_block
*next
, *next1
;
401 register struct blockvector
*blockvector
;
404 /* Count the length of the list of blocks. */
406 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
408 blockvector
= (struct blockvector
*)
409 obstack_alloc (symbol_obstack
, sizeof (struct blockvector
) + (i
- 1) * sizeof (struct block
*));
411 /* Copy the blocks into the blockvector.
412 This is done in reverse order, which happens to put
413 the blocks into the proper order (ascending starting address).
414 finish_block has hair to insert each block into the list
415 after its subblocks in order to make sure this is true. */
417 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
418 for (next
= pending_blocks
; next
; next
= next
->next
)
419 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
421 /* Now free the links of the list, and empty the list. */
423 for (next
= pending_blocks
; next
; next
= next1
)
433 /* Manage the vector of line numbers. */
436 record_line (line
, pc
)
440 struct linetable_entry
*e
;
441 /* Make sure line vector is big enough. */
443 if (line_vector_index
+ 2 >= line_vector_length
)
445 line_vector_length
*= 2;
446 line_vector
= (struct linetable
*)
447 xrealloc (line_vector
, sizeof (struct linetable
)
448 + (line_vector_length
449 * sizeof (struct linetable_entry
)));
452 e
= line_vector
->item
+ line_vector_index
++;
453 e
->line
= line
; e
->pc
= pc
;
456 /* Start a new symtab for a new source file.
457 This is called when a COFF ".file" symbol is seen;
458 it indicates the start of data for one original source file. */
467 last_source_file
= 0;
471 /* This isn't used currently. */
476 /* Initialize the source file line number information for this file. */
478 if (line_vector
) /* Unlikely, but maybe possible? */
480 line_vector_index
= 0;
481 line_vector_length
= 1000;
482 prev_line_number
= -2; /* Force first line number to be explicit */
483 line_vector
= (struct linetable
*)
484 xmalloc (sizeof (struct linetable
)
485 + line_vector_length
* sizeof (struct linetable_entry
));
488 /* Save the vital information from when starting to read a file,
489 for use when closing off the current file.
490 NAME is the file name the symbols came from, START_ADDR is the first
491 text address for the file, and SIZE is the number of bytes of text. */
494 complete_symtab (name
, start_addr
, size
)
496 CORE_ADDR start_addr
;
499 last_source_file
= savestring (name
, strlen (name
));
500 cur_src_start_addr
= start_addr
;
501 cur_src_end_addr
= start_addr
+ size
;
503 if (entry_point
< cur_src_end_addr
504 && entry_point
>= cur_src_start_addr
)
506 startup_file_start
= cur_src_start_addr
;
507 startup_file_end
= cur_src_end_addr
;
511 /* Finish the symbol definitions for one main source file,
512 close off all the lexical contexts for that file
513 (creating struct block's for them), then make the
514 struct symtab for that file and put it in the list of all such. */
519 register struct symtab
*symtab
;
520 register struct context_stack
*cstk
;
521 register struct blockvector
*blockvector
;
522 register struct linetable
*lv
;
524 /* Finish the lexical context of the last function in the file. */
528 cstk
= context_stack
;
530 /* Make a block for the local symbols within. */
531 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
532 cstk
->start_addr
, cur_src_end_addr
);
536 /* Ignore a file that has no functions with real debugging info. */
537 if (pending_blocks
== 0 && file_symbols
== 0 && global_symbols
== 0)
541 line_vector_length
= -1;
542 last_source_file
= 0;
546 /* Create the two top-level blocks for this file (STATIC_BLOCK and
548 finish_block (0, &file_symbols
, 0, cur_src_start_addr
, cur_src_end_addr
);
549 finish_block (0, &global_symbols
, 0, cur_src_start_addr
, cur_src_end_addr
);
551 /* Create the blockvector that points to all the file's blocks. */
552 blockvector
= make_blockvector ();
554 /* Now create the symtab object for this source file. */
555 symtab
= allocate_symtab (last_source_file
);
557 /* Fill in its components. */
558 symtab
->blockvector
= blockvector
;
559 symtab
->free_code
= free_linetable
;
560 symtab
->free_ptr
= 0;
561 symtab
->filename
= last_source_file
;
562 symtab
->dirname
= NULL
;
564 lv
->nitems
= line_vector_index
;
565 symtab
->linetable
= (struct linetable
*)
566 xrealloc (lv
, (sizeof (struct linetable
)
567 + lv
->nitems
* sizeof (struct linetable_entry
)));
570 symtab
->coffsem
= last_coffsem
;
572 /* This isn't used currently. Besides, if this is really about "syntax",
573 it shouldn't need to stick around past symbol read-in time. */
574 symtab
->coffsyn
= last_coffsyn
;
578 free_named_symtabs (symtab
->filename
);
580 /* Link the new symtab into the list of such. */
581 symtab
->next
= symtab_list
;
582 symtab_list
= symtab
;
584 /* Reinitialize for beginning of new file. */
586 line_vector_length
= -1;
587 last_source_file
= 0;
591 record_misc_function (name
, address
)
596 /* We don't want TDESC entry points on the misc_function_vector */
597 if (name
[0] == '@') return;
599 /* mf_text isn't true, but apparently COFF doesn't tell us what it really
600 is, so this guess is more useful than mf_unknown. */
601 prim_record_misc_function (savestring (name
, strlen (name
)),
606 /* coff_symfile_init ()
607 is the coff-specific initialization routine for reading symbols.
608 It is passed a struct sym_fns which contains, among other things,
609 the BFD for the file whose symbols are being read, and a slot for
610 a pointer to "private data" which we fill with cookies and other
611 treats for coff_symfile_read ().
613 We will only be called if this is a COFF or COFF-like file.
614 BFD handles figuring out the format of the file, and code in symtab.c
615 uses BFD's determination to vector to us.
617 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
619 struct coff_symfile_info
{
620 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
621 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
624 static int text_bfd_scnum
;
627 coff_symfile_init (sf
)
631 bfd
*abfd
= sf
->sym_bfd
;
633 /* Allocate struct to keep track of the symfile */
634 /* FIXME memory leak */
635 sf
->sym_private
= xmalloc (sizeof (struct coff_symfile_info
));
638 safe_to_init_tdesc_context
= 0;
641 /* Save startup file's range of PC addresses to help blockframe.c
642 decide where the bottom of the stack is. */
643 if (bfd_get_file_flags (abfd
) & EXEC_P
)
645 /* Executable file -- record its entry point so we'll recognize
646 the startup file because it contains the entry point. */
647 entry_point
= bfd_get_start_address (abfd
);
651 /* Examination of non-executable.o files. Short-circuit this stuff. */
652 /* ~0 will not be in any file, we hope. */
654 /* set the startup file to be an empty range. */
655 startup_file_start
= 0;
656 startup_file_end
= 0;
658 /* Save the section number for the text section */
659 if (section
= bfd_get_section_by_name(abfd
,".text"))
660 text_bfd_scnum
= section
->index
;
665 /* This function is called for every section; it finds the outer limits
666 of the line table (minimum and maximum file offset) so that the
667 mainline code can read the whole thing for efficiency. */
671 find_linenos (abfd
, asect
, vpinfo
)
676 struct coff_symfile_info
*info
;
678 file_ptr offset
, maxoff
;
680 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
681 count
= asect
->lineno_count
;
686 size
= count
* local_linesz
;
688 info
= (struct coff_symfile_info
*)vpinfo
;
689 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
690 offset
= asect
->line_filepos
;
693 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
694 info
->min_lineno_offset
= offset
;
696 maxoff
= offset
+ size
;
697 if (maxoff
> info
->max_lineno_offset
)
698 info
->max_lineno_offset
= maxoff
;
700 /* While we're at it, find the debug_info. It's in the s_relptr
701 (or, in BFD-speak, rel_filepos) of the text segment section header. */
702 if (strcmp (bfd_section_name (abfd
, asect
), ".text") == 0)
704 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
705 debug_info
= asect
->rel_filepos
;
709 dc_terminate (tdesc_handle
);
717 /* The BFD for this file -- only good while we're actively reading
718 symbols into a psymtab or a symtab. */
720 static bfd
*symfile_bfd
;
722 /* Read a symbol file, after initialization by coff_symfile_init. */
723 /* FIXME! Addr and Mainline are not used yet -- this will not work for
724 shared libraries or add_file! */
728 coff_symfile_read (sf
, addr
, mainline
)
733 struct coff_symfile_info
*info
= (struct coff_symfile_info
*)sf
->sym_private
;
734 bfd
*abfd
= sf
->sym_bfd
;
735 coff_data_type
*cdata
= coff_data (abfd
);
736 char *name
= bfd_get_filename (abfd
);
741 int stringtab_offset
;
743 symfile_bfd
= abfd
; /* Kludge for swap routines */
745 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
746 desc
= fileno ((FILE *)(abfd
->iostream
)); /* File descriptor */
747 num_symbols
= bfd_get_symcount (abfd
); /* How many syms */
748 symtab_offset
= cdata
->sym_filepos
; /* Symbol table file offset */
749 stringtab_offset
= symtab_offset
+ /* String table file offset */
750 num_symbols
* cdata
->local_symesz
;
752 /* Set a few file-statics that give us specific information about
753 the particular COFF file format we're reading. */
754 local_linesz
= cdata
->local_linesz
;
755 local_n_btmask
= cdata
->local_n_btmask
;
756 local_n_btshft
= cdata
->local_n_btshft
;
757 local_n_tmask
= cdata
->local_n_tmask
;
758 local_n_tshift
= cdata
->local_n_tshift
;
759 local_linesz
= cdata
->local_linesz
;
760 local_symesz
= cdata
->local_symesz
;
761 local_auxesz
= cdata
->local_auxesz
;
763 /* Allocate space for raw symbol and aux entries, based on their
764 space requirements as reported by BFD. */
765 temp_sym
= (char *) xmalloc
766 (cdata
->local_symesz
+ cdata
->local_auxesz
);
767 temp_aux
= temp_sym
+ cdata
->local_symesz
;
768 make_cleanup (free_current_contents
, &temp_sym
);
771 /* Read the line number table, all at once. */
772 info
->min_lineno_offset
= 0;
773 info
->max_lineno_offset
= 0;
774 bfd_map_over_sections (abfd
, find_linenos
, info
);
776 val
= init_lineno (desc
, info
->min_lineno_offset
,
777 info
->max_lineno_offset
- info
->min_lineno_offset
);
779 error ("\"%s\": error reading line numbers\n", name
);
781 /* Now read the string table, all at once. */
783 val
= init_stringtab (desc
, stringtab_offset
);
786 free_all_symtabs (); /* FIXME blows whole symtab */
787 printf ("\"%s\": can't get string table", name
);
791 make_cleanup (free_stringtab
, 0);
793 /* Position to read the symbol table. Do not read it all at once. */
794 val
= lseek (desc
, (long)symtab_offset
, 0);
796 perror_with_name (name
);
798 init_misc_bunches ();
799 make_cleanup (discard_misc_bunches
, 0);
801 /* Now that the executable file is positioned at symbol table,
802 process it and define symbols accordingly. */
804 read_coff_symtab (desc
, num_symbols
);
806 patch_opaque_types ();
808 /* Sort symbols alphabetically within each block. */
810 sort_all_symtab_syms ();
812 /* Go over the misc symbol bunches and install them in vector. */
814 condense_misc_bunches (!mainline
);
816 /* Make a default for file to list. */
818 select_source_symtab (0); /* FIXME, this might be too slow, see dbxread */
824 /* There seems to be nothing to do except free_all_symtabs and set
825 symfile to zero, which is done by our caller. */
828 /* Simplified internal version of coff symbol table information */
832 int c_symnum
; /* symbol number of this entry */
833 int c_nsyms
; /* 1 if syment only, 2 if syment + auxent, etc */
840 /* Given pointers to a symbol table in coff style exec file,
841 analyze them and create struct symtab's describing the symbols.
842 NSYMS is the number of symbols in the symbol table.
843 We read them one at a time using read_one_sym (). */
846 read_coff_symtab (desc
, nsyms
)
850 int newfd
; /* Avoid multiple closes on same desc */
852 register struct context_stack
*new;
853 struct coff_symbol coff_symbol
;
854 register struct coff_symbol
*cs
= &coff_symbol
;
855 static struct internal_syment main_sym
;
856 static union internal_auxent main_aux
;
857 struct coff_symbol fcn_cs_saved
;
858 static struct internal_syment fcn_sym_saved
;
859 static union internal_auxent fcn_aux_saved
;
861 /* A .file is open. */
862 int in_source_file
= 0;
863 int num_object_files
= 0;
864 int next_file_symnum
= -1;
866 /* Name of the current file. */
867 char *filestring
= "";
873 struct cleanup
*old_chain
;
878 fatal ("Too many open files");
879 stream
= fdopen (newfd
, "r");
881 old_chain
= make_cleanup (free_all_symtabs
, 0);
882 make_cleanup (fclose
, stream
);
883 nlist_stream_global
= stream
;
884 nlist_nsyms_global
= nsyms
;
885 last_source_file
= 0;
886 bzero (opaque_type_chain
, sizeof opaque_type_chain
);
888 if (type_vector
) /* Get rid of previous one */
890 type_vector_length
= 160;
891 type_vector
= (struct type
**)
892 xmalloc (type_vector_length
* sizeof (struct type
*));
893 bzero (type_vector
, type_vector_length
* sizeof (struct type
*));
898 while (symnum
< nsyms
)
900 QUIT
; /* Make this command interruptable. */
901 read_one_sym (cs
, &main_sym
, &main_aux
);
904 temp_sem_val
= cs
->c_name
[0] << 24 | cs
->c_name
[1] << 16 |
905 cs
->c_name
[2] << 8 | cs
->c_name
[3];
906 if (int_sem_val
== temp_sem_val
)
907 last_coffsem
= (int) strtol (cs
->c_name
+4, (char **) NULL
, 10);
910 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
912 if (last_source_file
)
916 complete_symtab ("_globals_", 0, first_object_file_end
);
917 /* done with all files, everything from here on out is globals */
920 /* Special case for file with type declarations only, no text. */
921 if (!last_source_file
&& SDB_TYPE (cs
->c_type
)
922 && cs
->c_secnum
== N_DEBUG
)
923 complete_symtab (filestring
, 0, 0);
925 /* Typedefs should not be treated as symbol definitions. */
926 if (ISFCN (cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
928 /* record as misc function. if we get '.bf' next,
929 * then we undo this step
931 record_misc_function (cs
->c_name
, cs
->c_value
);
933 fcn_line_ptr
= main_aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
934 fcn_start_addr
= cs
->c_value
;
936 fcn_sym_saved
= main_sym
;
937 fcn_aux_saved
= main_aux
;
941 switch (cs
->c_sclass
)
950 printf ("Bad n_sclass = %d\n", cs
->c_sclass
);
955 * c_value field contains symnum of next .file entry in table
956 * or symnum of first global after last .file.
958 next_file_symnum
= cs
->c_value
;
959 filestring
= getfilename (&main_aux
);
961 * Complete symbol table for last object file
962 * containing debugging information.
964 if (last_source_file
)
973 if (cs
->c_name
[0] == '.') {
974 if (strcmp (cs
->c_name
, ".text") == 0) {
975 /* FIXME: don't wire in ".text" as section name
977 if (++num_object_files
== 1) {
978 /* last address of startup file */
979 first_object_file_end
= cs
->c_value
+
980 main_aux
.x_scn
.x_scnlen
;
982 /* Check for in_source_file deals with case of
983 a file with debugging symbols
984 followed by a later file with no symbols. */
986 complete_symtab (filestring
, cs
->c_value
,
987 main_aux
.x_scn
.x_scnlen
);
990 /* flush rest of '.' symbols */
993 else if (!SDB_TYPE (cs
->c_type
)
994 && cs
->c_name
[0] == 'L'
995 && (strncmp (cs
->c_name
, "LI%", 3) == 0
996 || strncmp (cs
->c_name
, "LF%", 3) == 0
997 || strncmp (cs
->c_name
,"LC%",3) == 0
998 || strncmp (cs
->c_name
,"LP%",3) == 0
999 || strncmp (cs
->c_name
,"LPB%",4) == 0
1000 || strncmp (cs
->c_name
,"LBB%",4) == 0
1001 || strncmp (cs
->c_name
,"LBE%",4) == 0
1002 || strncmp (cs
->c_name
,"LPBX%",5) == 0))
1003 /* At least on a 3b1, gcc generates swbeg and string labels
1004 that look like this. Ignore them. */
1006 /* fall in for static symbols that don't start with '.' */
1008 if (!SDB_TYPE (cs
->c_type
)) {
1009 /* FIXME: This is BOGUS Will Robinson!
1010 Coff should provide the SEC_CODE flag for executable sections,
1011 then if we could look up sections by section number we
1012 could see if the flags indicate SEC_CODE. If so, then
1013 record this symbol as a miscellaneous function. But why
1014 are absolute syms recorded as functions, anyway? */
1015 if (cs
->c_secnum
<= text_bfd_scnum
+1) {/* text or abs */
1016 record_misc_function (cs
->c_name
, cs
->c_value
);
1022 (void) process_coff_symbol (cs
, &main_aux
);
1026 if (strcmp (cs
->c_name
, ".bf") == 0)
1028 within_function
= 1;
1030 /* value contains address of first non-init type code */
1031 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
1032 contains line number of '{' } */
1033 fcn_first_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
1035 new = (struct context_stack
*)
1036 xmalloc (sizeof (struct context_stack
));
1037 new->depth
= depth
= 0;
1039 context_stack
= new;
1041 new->old_blocks
= pending_blocks
;
1042 new->start_addr
= fcn_start_addr
;
1043 fcn_cs_saved
.c_name
= getsymname (&fcn_sym_saved
);
1044 new->name
= process_coff_symbol (&fcn_cs_saved
,
1047 else if (strcmp (cs
->c_name
, ".ef") == 0)
1049 /* the value of .ef is the address of epilogue code;
1050 * not useful for gdb
1052 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1053 contains number of lines to '}' */
1054 new = context_stack
;
1057 complain (&ef_complaint
, cs
->c_symnum
);
1058 within_function
= 0;
1061 fcn_last_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
1062 enter_linenos (fcn_line_ptr
, fcn_first_line
, fcn_last_line
);
1064 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1066 #if defined (FUNCTION_EPILOGUE_SIZE)
1067 /* This macro should be defined only on
1069 fcn_aux_saved.x_sym.x_misc.x_fsize
1070 field is always zero.
1071 So use the .bf record information that
1072 points to the epilogue and add the size
1074 cs
->c_value
+ FUNCTION_EPILOGUE_SIZE
1076 fcn_cs_saved
.c_value
+
1077 fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1081 within_function
= 0;
1087 if (strcmp (cs
->c_name
, ".bb") == 0)
1089 new = (struct context_stack
*)
1090 xmalloc (sizeof (struct context_stack
));
1093 new->next
= context_stack
;
1094 context_stack
= new;
1095 new->locals
= local_symbols
;
1096 new->old_blocks
= pending_blocks
;
1097 new->start_addr
= cs
->c_value
;
1101 else if (strcmp (cs
->c_name
, ".eb") == 0)
1103 new = context_stack
;
1104 if (new == 0 || depth
!= new->depth
)
1105 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1107 if (local_symbols
&& context_stack
->next
)
1109 /* Make a block for the local symbols within. */
1110 finish_block (0, &local_symbols
, new->old_blocks
,
1111 new->start_addr
, cs
->c_value
);
1114 local_symbols
= new->locals
;
1115 context_stack
= new->next
;
1122 /* This isn't used currently. */
1123 if (strcmp (cs
->c_name
, ".coffsyn") == 0)
1124 last_coffsyn
= cs
->c_value
;
1127 if ((strcmp (cs
->c_name
, ".coffsem") == 0) &&
1129 last_coffsem
= cs
->c_value
;
1135 if ((strcmp (cs
->c_name
, ".coffsem") == 0) &&
1137 last_coffsem
= cs
->c_value
;
1140 (void) process_coff_symbol (cs
, &main_aux
);
1145 if (last_source_file
)
1148 discard_cleanups (old_chain
);
1151 /* Routines for reading headers and symbols from executable. */
1154 /* Move these XXXMAGIC symbol defns into BFD! */
1156 /* Read COFF file header, check magic number,
1157 and return number of symbols. */
1158 read_file_hdr (chan
, file_hdr
)
1162 lseek (chan
, 0L, 0);
1163 if (myread (chan
, (char *)file_hdr
, FILHSZ
) < 0)
1166 switch (file_hdr
->f_magic
)
1181 #if defined (MC68KWRMAGIC) \
1182 && (!defined (MC68MAGIC) || MC68KWRMAGIC != MC68MAGIC)
1196 case I960ROMAGIC
: /* Intel 960 */
1199 case I960RWMAGIC
: /* Intel 960 */
1201 return file_hdr
->f_nsyms
;
1205 if (BADMAG(file_hdr
))
1208 return file_hdr
->f_nsyms
;
1216 /* Read the next symbol, swap it, and return it in both internal_syment
1217 form, and coff_symbol form. Also return its first auxent, if any,
1218 in internal_auxent form, and skip any other auxents. */
1221 read_one_sym (cs
, sym
, aux
)
1222 register struct coff_symbol
*cs
;
1223 register struct internal_syment
*sym
;
1224 register union internal_auxent
*aux
;
1228 cs
->c_symnum
= symnum
;
1229 fread (temp_sym
, local_symesz
, 1, nlist_stream_global
);
1230 bfd_coff_swap_sym_in (symfile_bfd
, temp_sym
, (char *)sym
);
1231 cs
->c_nsyms
= (sym
->n_numaux
& 0xff) + 1;
1232 if (cs
->c_nsyms
>= 2)
1234 fread (temp_aux
, local_auxesz
, 1, nlist_stream_global
);
1235 bfd_coff_swap_aux_in (symfile_bfd
, temp_aux
, sym
->n_type
, sym
->n_sclass
,
1237 /* If more than one aux entry, read past it (only the first aux
1239 for (i
= 2; i
< cs
->c_nsyms
; i
++)
1240 fread (temp_aux
, local_auxesz
, 1, nlist_stream_global
);
1242 cs
->c_name
= getsymname (sym
);
1243 cs
->c_value
= sym
->n_value
;
1244 cs
->c_sclass
= (sym
->n_sclass
& 0xff);
1245 cs
->c_secnum
= sym
->n_scnum
;
1246 cs
->c_type
= (unsigned) sym
->n_type
;
1247 if (!SDB_TYPE (cs
->c_type
))
1250 symnum
+= cs
->c_nsyms
;
1253 /* Support for string table handling */
1255 static char *stringtab
= NULL
;
1258 init_stringtab (chan
, offset
)
1264 unsigned char lengthbuf
[4];
1272 if (lseek (chan
, offset
, 0) < 0)
1275 val
= myread (chan
, (char *)lengthbuf
, sizeof lengthbuf
);
1276 length
= bfd_h_get_32 (symfile_bfd
, lengthbuf
);
1278 /* If no string table is needed, then the file may end immediately
1279 after the symbols. Just return with `stringtab' set to null. */
1280 if (val
!= sizeof length
|| length
< sizeof length
)
1283 stringtab
= (char *) xmalloc (length
);
1284 if (stringtab
== NULL
)
1287 bcopy (&length
, stringtab
, sizeof length
);
1288 if (length
== sizeof length
) /* Empty table -- just the count */
1291 val
= myread (chan
, stringtab
+ sizeof length
, length
- sizeof length
);
1292 if (val
!= length
- sizeof length
|| stringtab
[length
- 1] != '\0')
1307 getsymname (symbol_entry
)
1308 struct internal_syment
*symbol_entry
;
1310 static char buffer
[SYMNMLEN
+1];
1313 if (symbol_entry
->_n
._n_n
._n_zeroes
== 0)
1315 result
= stringtab
+ symbol_entry
->_n
._n_n
._n_offset
;
1319 strncpy (buffer
, symbol_entry
->_n
._n_name
, SYMNMLEN
);
1320 buffer
[SYMNMLEN
] = '\0';
1327 getfilename (aux_entry
)
1328 union internal_auxent
*aux_entry
;
1330 static char buffer
[BUFSIZ
];
1331 register char *temp
;
1333 extern char *rindex ();
1335 #ifndef COFF_NO_LONG_FILE_NAMES
1336 #if defined (x_zeroes)
1338 if (aux_entry
->x_zeroes
== 0)
1339 strcpy (buffer
, stringtab
+ aux_entry
->x_offset
);
1340 #else /* no x_zeroes */
1341 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1342 strcpy (buffer
, stringtab
+ aux_entry
->x_file
.x_n
.x_offset
);
1343 #endif /* no x_zeroes */
1345 #endif /* COFF_NO_LONG_FILE_NAMES */
1347 #if defined (x_name)
1349 strncpy (buffer
, aux_entry
->x_name
, FILNMLEN
);
1351 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1353 buffer
[FILNMLEN
] = '\0';
1356 if ((temp
= rindex (result
, '/')) != NULL
)
1361 /* Support for line number handling */
1362 static char *linetab
= NULL
;
1363 static long linetab_offset
;
1364 static unsigned long linetab_size
;
1366 /* Read in all the line numbers for fast lookups later. Leave them in
1367 external (unswapped) format in memory; we'll swap them as we enter
1368 them into GDB's data structures. */
1371 init_lineno (chan
, offset
, size
)
1378 linetab_offset
= offset
;
1379 linetab_size
= size
;
1384 if (lseek (chan
, offset
, 0) < 0)
1387 linetab
= (char *) xmalloc (size
);
1389 val
= myread (chan
, linetab
, size
);
1393 make_cleanup (free
, linetab
); /* Be sure it gets de-allocated. */
1397 #if !defined (L_LNNO32)
1398 #define L_LNNO32(lp) ((lp)->l_lnno)
1402 enter_linenos (file_offset
, first_line
, last_line
)
1404 register int first_line
;
1405 register int last_line
;
1407 register char *rawptr
;
1408 struct internal_lineno lptr
;
1410 if (file_offset
< linetab_offset
)
1412 complain (&lineno_complaint
, file_offset
);
1413 if (file_offset
> linetab_size
) /* Too big to be an offset? */
1415 file_offset
+= linetab_offset
; /* Try reading at that linetab offset */
1418 rawptr
= &linetab
[file_offset
- linetab_offset
];
1420 /* skip first line entry for each function */
1421 rawptr
+= local_linesz
;
1422 /* line numbers start at one for the first line of the function */
1426 bfd_coff_swap_lineno_in (symfile_bfd
, rawptr
, &lptr
);
1427 rawptr
+= local_linesz
;
1428 if (L_LNNO32 (&lptr
) && L_LNNO32 (&lptr
) <= last_line
)
1429 record_line (first_line
+ L_LNNO32 (&lptr
), lptr
.l_addr
.l_paddr
);
1439 register char *p
= name
;
1440 register int total
= p
[0];
1453 return total
% HASHSIZE
;
1457 patch_type (type
, real_type
)
1459 struct type
*real_type
;
1461 register struct type
*target
= TYPE_TARGET_TYPE (type
);
1462 register struct type
*real_target
= TYPE_TARGET_TYPE (real_type
);
1463 int field_size
= TYPE_NFIELDS (real_target
) * sizeof (struct field
);
1465 TYPE_LENGTH (target
) = TYPE_LENGTH (real_target
);
1466 TYPE_NFIELDS (target
) = TYPE_NFIELDS (real_target
);
1467 TYPE_FIELDS (target
) = (struct field
*)
1468 obstack_alloc (symbol_obstack
, field_size
);
1470 bcopy (TYPE_FIELDS (real_target
), TYPE_FIELDS (target
), field_size
);
1472 if (TYPE_NAME (real_target
))
1474 if (TYPE_NAME (target
))
1475 free (TYPE_NAME (target
));
1476 TYPE_NAME (target
) = concat (TYPE_NAME (real_target
), "", "");
1480 /* Patch up all appropriate typdef symbols in the opaque_type_chains
1481 so that they can be used to print out opaque data structures properly */
1484 patch_opaque_types ()
1488 /* Look at each symbol in the per-file block of each symtab. */
1489 for (s
= symtab_list
; s
; s
= s
->next
)
1491 register struct block
*b
;
1494 /* Go through the per-file symbols only */
1495 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
1496 for (i
= BLOCK_NSYMS (b
) - 1; i
>= 0; i
--)
1498 register struct symbol
*real_sym
;
1500 /* Find completed typedefs to use to fix opaque ones.
1501 Remove syms from the chain when their types are stored,
1502 but search the whole chain, as there may be several syms
1503 from different files with the same name. */
1504 real_sym
= BLOCK_SYM (b
, i
);
1505 if (SYMBOL_CLASS (real_sym
) == LOC_TYPEDEF
&&
1506 SYMBOL_NAMESPACE (real_sym
) == VAR_NAMESPACE
&&
1507 TYPE_CODE (SYMBOL_TYPE (real_sym
)) == TYPE_CODE_PTR
&&
1508 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym
))) != 0)
1510 register char *name
= SYMBOL_NAME (real_sym
);
1511 register int hash
= hashname (name
);
1512 register struct symbol
*sym
, *prev
;
1515 for (sym
= opaque_type_chain
[hash
]; sym
;)
1517 if (name
[0] == SYMBOL_NAME (sym
)[0] &&
1518 !strcmp (name
+ 1, SYMBOL_NAME (sym
) + 1))
1521 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
1523 opaque_type_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
1525 patch_type (SYMBOL_TYPE (sym
), SYMBOL_TYPE (real_sym
));
1528 sym
= SYMBOL_VALUE_CHAIN (prev
);
1530 sym
= opaque_type_chain
[hash
];
1535 sym
= SYMBOL_VALUE_CHAIN (sym
);
1543 #if defined (clipper)
1544 #define BELIEVE_PCC_PROMOTION 1
1547 static struct symbol
*
1548 process_coff_symbol (cs
, aux
)
1549 register struct coff_symbol
*cs
;
1550 register union internal_auxent
*aux
;
1552 register struct symbol
*sym
1553 = (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
1555 #ifdef NAMES_HAVE_UNDERSCORE
1561 bzero (sym
, sizeof (struct symbol
));
1563 name
= (name
[0] == '_' ? name
+ offset
: name
);
1564 SYMBOL_NAME (sym
) = obstack_copy0 (symbol_obstack
, name
, strlen (name
));
1566 /* default assumptions */
1567 SYMBOL_VALUE (sym
) = cs
->c_value
;
1568 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1570 if (ISFCN (cs
->c_type
))
1573 /* FIXME: This has NOT been tested. The DBX version has.. */
1574 /* Generate a template for the type of this function. The
1575 types of the arguments will be added as we read the symbol
1577 struct type
*new = (struct type
*)
1578 obstack_alloc (symbol_obstack
, sizeof (struct type
));
1580 bcopy(lookup_function_type (decode_function_type (cs
, cs
->c_type
, aux
)),
1581 new, sizeof(struct type
));
1582 SYMBOL_TYPE (sym
) = new;
1583 in_function_type
= SYMBOL_TYPE(sym
);
1586 lookup_function_type (decode_function_type (cs
, cs
->c_type
, aux
));
1589 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1590 if (cs
->c_sclass
== C_STAT
)
1591 add_symbol_to_list (sym
, &file_symbols
);
1592 else if (cs
->c_sclass
== C_EXT
)
1593 add_symbol_to_list (sym
, &global_symbols
);
1597 SYMBOL_TYPE (sym
) = decode_type (cs
, cs
->c_type
, aux
);
1598 switch (cs
->c_sclass
)
1604 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1605 add_symbol_to_list (sym
, &local_symbols
);
1609 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1610 SYMBOL_VALUE_ADDRESS (sym
) = (CORE_ADDR
) cs
->c_value
;
1611 add_symbol_to_list (sym
, &global_symbols
);
1615 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1616 SYMBOL_VALUE_ADDRESS (sym
) = (CORE_ADDR
) cs
->c_value
;
1617 if (within_function
) {
1618 /* Static symbol of local scope */
1619 add_symbol_to_list (sym
, &local_symbols
);
1622 /* Static symbol at top level of file */
1623 add_symbol_to_list (sym
, &file_symbols
);
1627 #ifdef C_GLBLREG /* AMD coff */
1631 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1632 SYMBOL_VALUE (sym
) = SDB_REG_TO_REGNUM(cs
->c_value
);
1633 add_symbol_to_list (sym
, &local_symbols
);
1640 SYMBOL_CLASS (sym
) = LOC_ARG
;
1642 /* FIXME: This has not bee tested. */
1643 /* Add parameter to function. */
1644 add_param_to_type(&in_function_type
,sym
);
1646 add_symbol_to_list (sym
, &local_symbols
);
1647 #if !defined (BELIEVE_PCC_PROMOTION)
1648 /* If PCC says a parameter is a short or a char,
1649 it is really an int. */
1650 if (SYMBOL_TYPE (sym
) == builtin_type_char
1651 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1652 SYMBOL_TYPE (sym
) = builtin_type_int
;
1653 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1654 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1655 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1660 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1661 SYMBOL_VALUE (sym
) = SDB_REG_TO_REGNUM(cs
->c_value
);
1662 add_symbol_to_list (sym
, &local_symbols
);
1663 #if !defined (BELIEVE_PCC_PROMOTION)
1664 /* If PCC says a parameter is a short or a char,
1665 it is really an int. */
1666 if (SYMBOL_TYPE (sym
) == builtin_type_char
1667 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1668 SYMBOL_TYPE (sym
) = builtin_type_int
;
1669 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1670 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1671 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1676 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1677 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1679 /* If type has no name, give it one */
1680 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1681 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1682 TYPE_NAME (SYMBOL_TYPE (sym
))
1683 = concat (SYMBOL_NAME (sym
), "", "");
1685 /* Keep track of any type which points to empty structured type,
1686 so it can be filled from a definition from another file */
1687 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
&&
1688 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym
))) == 0)
1690 register int i
= hashname (SYMBOL_NAME (sym
));
1692 SYMBOL_VALUE_CHAIN (sym
) = opaque_type_chain
[i
];
1693 opaque_type_chain
[i
] = sym
;
1695 add_symbol_to_list (sym
, &file_symbols
);
1701 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1702 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1703 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1704 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1705 TYPE_NAME (SYMBOL_TYPE (sym
))
1707 (cs
->c_sclass
== C_ENTAG
1709 : (cs
->c_sclass
== C_STRTAG
1710 ? "struct " : "union ")),
1712 add_symbol_to_list (sym
, &file_symbols
);
1722 /* Decode a coff type specifier;
1723 return the type that is meant. */
1727 decode_type (cs
, c_type
, aux
)
1728 register struct coff_symbol
*cs
;
1729 unsigned int c_type
;
1730 register union internal_auxent
*aux
;
1732 register struct type
*type
= 0;
1733 unsigned int new_c_type
;
1735 if (c_type
& ~N_BTMASK
)
1737 new_c_type
= DECREF (c_type
);
1740 type
= decode_type (cs
, new_c_type
, aux
);
1741 type
= lookup_pointer_type (type
);
1743 else if (ISFCN (c_type
))
1745 type
= decode_type (cs
, new_c_type
, aux
);
1746 type
= lookup_function_type (type
);
1748 else if (ISARY (c_type
))
1751 register unsigned short *dim
;
1752 struct type
*base_type
;
1754 /* Define an array type. */
1755 /* auxent refers to array, not base type */
1756 if (aux
->x_sym
.x_tagndx
.l
== 0)
1759 /* shift the indices down */
1760 dim
= &aux
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0];
1763 for (i
= 0; *dim
&& i
< DIMNUM
- 1; i
++, dim
++)
1767 type
= (struct type
*)
1768 obstack_alloc (symbol_obstack
, sizeof (struct type
));
1769 bzero (type
, sizeof (struct type
));
1771 base_type
= decode_type (cs
, new_c_type
, aux
);
1773 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
1774 TYPE_TARGET_TYPE (type
) = base_type
;
1775 TYPE_LENGTH (type
) = n
* TYPE_LENGTH (base_type
);
1780 /* Reference to existing type */
1781 if (cs
->c_nsyms
> 1 && aux
->x_sym
.x_tagndx
.l
!= 0)
1783 type
= coff_alloc_type (aux
->x_sym
.x_tagndx
.l
);
1787 return decode_base_type (cs
, BTYPE (c_type
), aux
);
1790 /* Decode a coff type specifier for function definition;
1791 return the type that the function returns. */
1795 decode_function_type (cs
, c_type
, aux
)
1796 register struct coff_symbol
*cs
;
1797 unsigned int c_type
;
1798 register union internal_auxent
*aux
;
1800 if (aux
->x_sym
.x_tagndx
.l
== 0)
1801 cs
->c_nsyms
= 1; /* auxent refers to function, not base type */
1803 return decode_type (cs
, DECREF (c_type
), aux
);
1810 decode_base_type (cs
, c_type
, aux
)
1811 register struct coff_symbol
*cs
;
1812 unsigned int c_type
;
1813 register union internal_auxent
*aux
;
1820 /* shows up with "void (*foo)();" structure members */
1821 return builtin_type_void
;
1824 /* DGUX actually defines both T_ARG and T_VOID to the same value. */
1827 /* Shows up in DGUX, I think. Not sure where. */
1828 return builtin_type_void
; /* shouldn't show up here */
1834 /* Intel 960 COFF has this symbol and meaning. */
1835 return builtin_type_void
;
1839 return builtin_type_char
;
1842 return builtin_type_short
;
1845 return builtin_type_int
;
1848 return builtin_type_long
;
1851 return builtin_type_float
;
1854 return builtin_type_double
;
1857 if (cs
->c_nsyms
!= 2)
1859 /* anonymous structure type */
1860 type
= coff_alloc_type (cs
->c_symnum
);
1861 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1862 TYPE_NAME (type
) = concat ("struct ", "<opaque>", "");
1863 TYPE_LENGTH (type
) = 0;
1864 TYPE_FIELDS (type
) = 0;
1865 TYPE_NFIELDS (type
) = 0;
1869 type
= read_struct_type (cs
->c_symnum
,
1870 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1871 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1876 if (cs
->c_nsyms
!= 2)
1878 /* anonymous union type */
1879 type
= coff_alloc_type (cs
->c_symnum
);
1880 TYPE_NAME (type
) = concat ("union ", "<opaque>", "");
1881 TYPE_LENGTH (type
) = 0;
1882 TYPE_FIELDS (type
) = 0;
1883 TYPE_NFIELDS (type
) = 0;
1887 type
= read_struct_type (cs
->c_symnum
,
1888 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1889 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1891 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1895 return read_enum_type (cs
->c_symnum
,
1896 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1897 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1900 /* shouldn't show up here */
1904 return builtin_type_unsigned_char
;
1907 return builtin_type_unsigned_short
;
1910 return builtin_type_unsigned_int
;
1913 return builtin_type_unsigned_long
;
1915 printf ("unexpected type %d at symnum %d\n", c_type
, cs
->c_symnum
);
1916 return builtin_type_void
;
1919 /* This page contains subroutines of read_type. */
1921 /* Read the description of a structure (or union type)
1922 and return an object describing the type. */
1924 static struct type
*
1925 read_struct_type (index
, length
, lastsym
)
1932 struct nextfield
*next
;
1936 register struct type
*type
;
1937 register struct nextfield
*list
= 0;
1938 struct nextfield
*new;
1942 #ifdef NAMES_HAVE_UNDERSCORE
1947 struct coff_symbol member_sym
;
1948 register struct coff_symbol
*ms
= &member_sym
;
1949 struct internal_syment sub_sym
;
1950 union internal_auxent sub_aux
;
1953 type
= coff_alloc_type (index
);
1954 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1955 TYPE_LENGTH (type
) = length
;
1957 while (!done
&& symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
1959 read_one_sym (ms
, &sub_sym
, &sub_aux
);
1961 name
= (name
[0] == '_' ? name
+ offset
: name
);
1963 switch (ms
->c_sclass
)
1968 /* Get space to record the next field's data. */
1969 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1973 /* Save the data. */
1974 list
->field
.name
= savestring (name
, strlen (name
));
1975 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1976 list
->field
.bitpos
= 8 * ms
->c_value
;
1977 list
->field
.bitsize
= 0;
1983 /* Get space to record the next field's data. */
1984 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1988 /* Save the data. */
1989 list
->field
.name
= savestring (name
, strlen (name
));
1990 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1991 list
->field
.bitpos
= ms
->c_value
;
1992 list
->field
.bitsize
= sub_aux
.x_sym
.x_misc
.x_lnsz
.x_size
;
2001 /* Now create the vector of fields, and record how big it is. */
2003 TYPE_NFIELDS (type
) = nfields
;
2004 TYPE_FIELDS (type
) = (struct field
*)
2005 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nfields
);
2007 /* Copy the saved-up fields into the field vector. */
2009 for (n
= nfields
; list
; list
= list
->next
)
2010 TYPE_FIELD (type
, --n
) = list
->field
;
2015 /* Read a definition of an enumeration type,
2016 and create and return a suitable type object.
2017 Also defines the symbols that represent the values of the type. */
2018 /* Currently assumes it's sizeof (int) and doesn't use length. */
2021 static struct type
*
2022 read_enum_type (index
, length
, lastsym
)
2027 register struct symbol
*sym
;
2028 register struct type
*type
;
2031 struct pending
**symlist
;
2032 struct coff_symbol member_sym
;
2033 register struct coff_symbol
*ms
= &member_sym
;
2034 struct internal_syment sub_sym
;
2035 union internal_auxent sub_aux
;
2036 struct pending
*osyms
, *syms
;
2039 #ifdef NAMES_HAVE_UNDERSCORE
2045 type
= coff_alloc_type (index
);
2046 if (within_function
)
2047 symlist
= &local_symbols
;
2049 symlist
= &file_symbols
;
2052 while (!done
&& symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
2054 read_one_sym (ms
, &sub_sym
, &sub_aux
);
2056 name
= (name
[0] == '_' ? name
+ offset
: name
);
2058 switch (ms
->c_sclass
)
2061 sym
= (struct symbol
*) xmalloc (sizeof (struct symbol
));
2062 bzero (sym
, sizeof (struct symbol
));
2064 SYMBOL_NAME (sym
) = savestring (name
, strlen (name
));
2065 SYMBOL_CLASS (sym
) = LOC_CONST
;
2066 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2067 SYMBOL_VALUE (sym
) = ms
->c_value
;
2068 add_symbol_to_list (sym
, symlist
);
2073 /* Sometimes the linker (on 386/ix 2.0.2 at least) screws
2074 up the count of how many symbols to read. So stop
2081 /* Now fill in the fields of the type-structure. */
2083 /* FIXME: Should be sizeof (int) on target, not host. */
2084 TYPE_LENGTH (type
) = sizeof (int);
2085 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2086 TYPE_NFIELDS (type
) = nsyms
;
2087 TYPE_FIELDS (type
) = (struct field
*)
2088 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nsyms
);
2090 /* Find the symbols for the values and put them into the type.
2091 The symbols can be found in the symlist that we put them on
2092 to cause them to be defined. osyms contains the old value
2093 of that symlist; everything up to there was defined by us. */
2095 for (syms
= *symlist
, n
= nsyms
; syms
!= osyms
; syms
= syms
->next
)
2097 SYMBOL_TYPE (syms
->symbol
) = type
;
2098 TYPE_FIELD_NAME (type
, --n
) = SYMBOL_NAME (syms
->symbol
);
2099 TYPE_FIELD_VALUE (type
, n
) = 0;
2100 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (syms
->symbol
);
2101 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2103 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2104 if(TYPE_NFIELDS(type
) == 2 &&
2105 ((!strcmp(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2106 !strcmp(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2107 (!strcmp(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2108 !strcmp(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2109 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2113 /* Register our ability to parse symbols for coff BFD files */
2115 static struct sym_fns coff_sym_fns
=
2117 /* This assumes that 88kbcs implies TDESC and TDESC implies 88kbcs.
2118 If that's not true, this can be relaxed, but if it is true,
2119 it will just cause users grief if we try to read the wrong kind
2123 #else /* not TDESC */
2128 # endif /* not i386 */
2129 #endif /* not TDESC */
2130 coff_new_init
, coff_symfile_init
, coff_symfile_read
,
2134 _initialize_coffread ()
2136 add_symtab_fns(&coff_sym_fns
);