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. */
24 #include "breakpoint.h"
31 #include "internalcoff.h" /* Internal format of COFF symbols in BFD */
32 #include "libcoff.h" /* FIXME secret internal data from BFD */
34 static void add_symbol_to_list ();
35 static void read_coff_symtab ();
36 static void patch_opaque_types ();
37 static struct type
*decode_function_type ();
38 static struct type
*decode_type ();
39 static struct type
*decode_base_type ();
40 static struct type
*read_enum_type ();
41 static struct type
*read_struct_type ();
42 static void finish_block ();
43 static struct blockvector
*make_blockvector ();
44 static struct symbol
*process_coff_symbol ();
45 static int init_stringtab ();
46 static void free_stringtab ();
47 static char *getfilename ();
48 static char *getsymname ();
49 static int init_lineno ();
50 static void enter_linenos ();
51 static void read_one_sym ();
55 /* To be an sdb debug type, type must have at least a basic or primary
56 derived type. Using this rather than checking against T_NULL is
57 said to prevent core dumps if we try to operate on Michael Bloom
60 #define SDB_TYPE(type) (BTYPE(type) | (type & N_TMASK))
63 * Convert from an sdb register number to an internal gdb register number.
64 * This should be defined in tm.h, if REGISTER_NAMES is not set up
65 * to map one to one onto the sdb register numbers.
67 #ifndef SDB_REG_TO_REGNUM
68 # define SDB_REG_TO_REGNUM(value) (value)
71 /* Name of source file whose symbol data we are now processing.
72 This comes from a symbol named ".file". */
74 static char *last_source_file
;
76 /* Core address of start and end of text of current source file.
77 This comes from a ".text" symbol where x_nlinno > 0. */
79 static CORE_ADDR cur_src_start_addr
;
80 static CORE_ADDR cur_src_end_addr
;
82 /* Core address of the end of the first object file. */
83 static CORE_ADDR first_object_file_end
;
85 /* The addresses of the symbol table stream and number of symbols
86 of the object file we are reading (as copied into core). */
88 static FILE *nlist_stream_global
;
89 static int nlist_nsyms_global
;
91 /* The index in the symbol table of the last coff symbol that was processed. */
95 /* Vector of types defined so far, indexed by their coff symnum. */
97 static struct type
**type_vector
;
99 /* Number of elements allocated for type_vector currently. */
101 static int type_vector_length
;
103 /* Vector of line number information. */
105 static struct linetable
*line_vector
;
107 /* Index of next entry to go in line_vector_index. */
109 static int line_vector_index
;
111 /* Last line number recorded in the line vector. */
113 static int prev_line_number
;
115 /* Number of elements allocated for line_vector currently. */
117 static int line_vector_length
;
119 /* Pointers to scratch storage, used for reading raw symbols and auxents. */
121 static char *temp_sym
;
122 static char *temp_aux
;
124 /* Local variables that hold the shift and mask values for the
125 COFF file that we are currently reading. These come back to us
126 from BFD, and are referenced by their macro names, as well as
127 internally to the BTYPE, ISPTR, ISFCN, ISARY, ISTAG, and DECREF
128 macros from ../internalcoff.h . */
130 static unsigned local_n_btmask
;
131 static unsigned local_n_btshft
;
132 static unsigned local_n_tmask
;
133 static unsigned local_n_tshift
;
135 #define N_BTMASK local_n_btmask
136 #define N_BTSHFT local_n_btshft
137 #define N_TMASK local_n_tmask
138 #define N_TSHIFT local_n_tshift
140 /* Local variables that hold the sizes in the file of various COFF structures.
141 (We only need to know this to read them from the file -- BFD will then
142 translate the data in them, into `internal_xxx' structs in the right
143 byte order, alignment, etc.) */
145 static unsigned local_linesz
;
146 static unsigned local_symesz
;
147 static unsigned local_auxesz
;
150 /* Chain of typedefs of pointers to empty struct/union types.
151 They are chained thru the SYMBOL_VALUE_CHAIN. */
154 static struct symbol
*opaque_type_chain
[HASHSIZE
];
156 /* Record the symbols defined for each context in a list.
157 We don't create a struct block for the context until we
158 know how long to make it. */
162 struct pending
*next
;
163 struct symbol
*symbol
;
166 /* Here are the three lists that symbols are put on. */
168 struct pending
*file_symbols
; /* static at top level, and types */
170 struct pending
*global_symbols
; /* global functions and variables */
172 struct pending
*local_symbols
; /* everything local to lexical context */
174 /* List of unclosed lexical contexts
175 (that will become blocks, eventually). */
179 struct context_stack
*next
;
180 struct pending
*locals
;
181 struct pending_block
*old_blocks
;
183 CORE_ADDR start_addr
;
187 struct context_stack
*context_stack
;
189 /* Nonzero if within a function (so symbols should be local,
190 if nothing says specifically). */
195 /* The type of the function we are currently reading in. This is
196 used by define_symbol to record the type of arguments to a function. */
198 struct type
*in_function_type
;
201 /* List of blocks already made (lexical contexts already closed).
202 This is used at the end to make the blockvector. */
206 struct pending_block
*next
;
210 struct pending_block
*pending_blocks
;
212 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
213 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
215 /* Complaints about various problems in the file being read */
217 struct complaint ef_complaint
=
218 {"Unmatched .ef symbol(s) ignored starting at symnum %d", 0, 0};
220 struct complaint no_aux_complaint
=
221 {"symbol %d without one aux entry", 0, 0};
223 struct complaint lineno_complaint
=
224 {"Line number pointer %d lower than start of line numbers", 0, 0};
227 /* Look up a coff type-number index. Return the address of the slot
228 where the type for that index is stored.
229 The type-number is in INDEX.
231 This can be used for finding the type associated with that index
232 or for associating a new type with the index. */
234 static struct type
**
235 coff_lookup_type (index
)
238 if (index
>= type_vector_length
)
240 int old_vector_length
= type_vector_length
;
242 type_vector_length
*= 2;
243 if (type_vector_length
< index
) {
244 type_vector_length
= index
* 2;
246 type_vector
= (struct type
**)
247 xrealloc (type_vector
, type_vector_length
* sizeof (struct type
*));
248 bzero (&type_vector
[old_vector_length
],
249 (type_vector_length
- old_vector_length
) * sizeof(struct type
*));
251 return &type_vector
[index
];
254 /* Make sure there is a type allocated for type number index
255 and return the type object.
256 This can create an empty (zeroed) type object. */
259 coff_alloc_type (index
)
262 register struct type
**type_addr
= coff_lookup_type (index
);
263 register struct type
*type
= *type_addr
;
265 /* If we are referring to a type not known at all yet,
266 allocate an empty type for it.
267 We will fill it in later if we find out how. */
270 type
= (struct type
*) obstack_alloc (symbol_obstack
,
271 sizeof (struct type
));
272 bzero (type
, sizeof (struct type
));
273 TYPE_VPTR_FIELDNO (type
) = -1;
279 /* maintain the lists of symbols and blocks */
281 /* Add a symbol to one of the lists of symbols. */
283 add_symbol_to_list (symbol
, listhead
)
284 struct symbol
*symbol
;
285 struct pending
**listhead
;
287 register struct pending
*link
288 = (struct pending
*) xmalloc (sizeof (struct pending
));
290 link
->next
= *listhead
;
291 link
->symbol
= symbol
;
295 /* Take one of the lists of symbols and make a block from it.
296 Put the block on the list of pending blocks. */
299 finish_block (symbol
, listhead
, old_blocks
, start
, end
)
300 struct symbol
*symbol
;
301 struct pending
**listhead
;
302 struct pending_block
*old_blocks
;
303 CORE_ADDR start
, end
;
305 register struct pending
*next
, *next1
;
306 register struct block
*block
;
307 register struct pending_block
*pblock
;
308 struct pending_block
*opblock
;
311 /* Count the length of the list of symbols. */
313 for (next
= *listhead
, i
= 0; next
; next
= next
->next
, i
++);
315 block
= (struct block
*)
316 obstack_alloc (symbol_obstack
, sizeof (struct block
) + (i
- 1) * sizeof (struct symbol
*));
318 /* Copy the symbols into the block. */
320 BLOCK_NSYMS (block
) = i
;
321 for (next
= *listhead
; next
; next
= next
->next
)
322 BLOCK_SYM (block
, --i
) = next
->symbol
;
324 BLOCK_START (block
) = start
;
325 BLOCK_END (block
) = end
;
326 BLOCK_SUPERBLOCK (block
) = 0; /* Filled in when containing block is made */
328 /* Put the block in as the value of the symbol that names it. */
332 SYMBOL_BLOCK_VALUE (symbol
) = block
;
333 BLOCK_FUNCTION (block
) = symbol
;
336 BLOCK_FUNCTION (block
) = 0;
338 /* Now free the links of the list, and empty the list. */
340 for (next
= *listhead
; next
; next
= next1
)
347 /* Install this block as the superblock
348 of all blocks made since the start of this scope
349 that don't have superblocks yet. */
352 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
354 if (BLOCK_SUPERBLOCK (pblock
->block
) == 0)
355 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
359 /* Record this block on the list of all blocks in the file.
360 Put it after opblock, or at the beginning if opblock is 0.
361 This puts the block in the list after all its subblocks. */
363 pblock
= (struct pending_block
*) xmalloc (sizeof (struct pending_block
));
364 pblock
->block
= block
;
367 pblock
->next
= opblock
->next
;
368 opblock
->next
= pblock
;
372 pblock
->next
= pending_blocks
;
373 pending_blocks
= pblock
;
377 static struct blockvector
*
380 register struct pending_block
*next
, *next1
;
381 register struct blockvector
*blockvector
;
384 /* Count the length of the list of blocks. */
386 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
388 blockvector
= (struct blockvector
*)
389 obstack_alloc (symbol_obstack
, sizeof (struct blockvector
) + (i
- 1) * sizeof (struct block
*));
391 /* Copy the blocks into the blockvector.
392 This is done in reverse order, which happens to put
393 the blocks into the proper order (ascending starting address).
394 finish_block has hair to insert each block into the list
395 after its subblocks in order to make sure this is true. */
397 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
398 for (next
= pending_blocks
; next
; next
= next
->next
)
399 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
401 /* Now free the links of the list, and empty the list. */
403 for (next
= pending_blocks
; next
; next
= next1
)
413 /* Manage the vector of line numbers. */
416 record_line (line
, pc
)
420 struct linetable_entry
*e
;
421 /* Make sure line vector is big enough. */
423 if (line_vector_index
+ 2 >= line_vector_length
)
425 line_vector_length
*= 2;
426 line_vector
= (struct linetable
*)
427 xrealloc (line_vector
, sizeof (struct linetable
)
428 + (line_vector_length
429 * sizeof (struct linetable_entry
)));
432 e
= line_vector
->item
+ line_vector_index
++;
433 e
->line
= line
; e
->pc
= pc
;
436 /* Start a new symtab for a new source file.
437 This is called when a COFF ".file" symbol is seen;
438 it indicates the start of data for one original source file. */
447 last_source_file
= 0;
449 /* Initialize the source file line number information for this file. */
451 if (line_vector
) /* Unlikely, but maybe possible? */
453 line_vector_index
= 0;
454 line_vector_length
= 1000;
455 prev_line_number
= -2; /* Force first line number to be explicit */
456 line_vector
= (struct linetable
*)
457 xmalloc (sizeof (struct linetable
)
458 + line_vector_length
* sizeof (struct linetable_entry
));
461 /* Save the vital information from when starting to read a file,
462 for use when closing off the current file.
463 NAME is the file name the symbols came from, START_ADDR is the first
464 text address for the file, and SIZE is the number of bytes of text. */
467 complete_symtab (name
, start_addr
, size
)
469 CORE_ADDR start_addr
;
472 last_source_file
= savestring (name
, strlen (name
));
473 cur_src_start_addr
= start_addr
;
474 cur_src_end_addr
= start_addr
+ size
;
476 if (entry_point
< cur_src_end_addr
477 && entry_point
>= cur_src_start_addr
)
479 startup_file_start
= cur_src_start_addr
;
480 startup_file_end
= cur_src_end_addr
;
484 /* Finish the symbol definitions for one main source file,
485 close off all the lexical contexts for that file
486 (creating struct block's for them), then make the
487 struct symtab for that file and put it in the list of all such. */
491 struct objfile
*objfile
;
493 register struct symtab
*symtab
;
494 register struct context_stack
*cstk
;
495 register struct blockvector
*blockvector
;
496 register struct linetable
*lv
;
498 /* Finish the lexical context of the last function in the file. */
502 cstk
= context_stack
;
504 /* Make a block for the local symbols within. */
505 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
506 cstk
->start_addr
, cur_src_end_addr
);
510 /* Ignore a file that has no functions with real debugging info. */
511 if (pending_blocks
== 0 && file_symbols
== 0 && global_symbols
== 0)
515 line_vector_length
= -1;
516 last_source_file
= 0;
520 /* Create the two top-level blocks for this file (STATIC_BLOCK and
522 finish_block (0, &file_symbols
, 0, cur_src_start_addr
, cur_src_end_addr
);
523 finish_block (0, &global_symbols
, 0, cur_src_start_addr
, cur_src_end_addr
);
525 /* Create the blockvector that points to all the file's blocks. */
526 blockvector
= make_blockvector ();
528 /* Now create the symtab object for this source file. */
529 symtab
= allocate_symtab (last_source_file
, objfile
);
531 /* Fill in its components. */
532 symtab
->blockvector
= blockvector
;
533 symtab
->free_code
= free_linetable
;
534 symtab
->free_ptr
= 0;
535 symtab
->filename
= last_source_file
;
536 symtab
->dirname
= NULL
;
538 lv
->nitems
= line_vector_index
;
539 symtab
->linetable
= (struct linetable
*)
540 xrealloc (lv
, (sizeof (struct linetable
)
541 + lv
->nitems
* sizeof (struct linetable_entry
)));
543 free_named_symtabs (symtab
->filename
);
545 /* Link the new symtab into the list of such. */
546 symtab
->next
= symtab_list
;
547 symtab_list
= symtab
;
549 /* Reinitialize for beginning of new file. */
551 line_vector_length
= -1;
552 last_source_file
= 0;
556 record_misc_function (name
, address
)
560 /* We don't want TDESC entry points on the misc_function_vector */
561 if (name
[0] == '@') return;
563 /* mf_text isn't true, but apparently COFF doesn't tell us what it really
564 is, so this guess is more useful than mf_unknown. */
565 prim_record_misc_function (savestring (name
, strlen (name
)),
570 /* coff_symfile_init ()
571 is the coff-specific initialization routine for reading symbols.
572 It is passed a struct sym_fns which contains, among other things,
573 the BFD for the file whose symbols are being read, and a slot for
574 a pointer to "private data" which we fill with cookies and other
575 treats for coff_symfile_read ().
577 We will only be called if this is a COFF or COFF-like file.
578 BFD handles figuring out the format of the file, and code in symtab.c
579 uses BFD's determination to vector to us.
581 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
583 struct coff_symfile_info
{
584 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
585 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
588 static int text_bfd_scnum
;
591 coff_symfile_init (sf
)
595 bfd
*abfd
= sf
->sym_bfd
;
597 /* Allocate struct to keep track of the symfile */
598 /* FIXME memory leak */
599 sf
->sym_private
= xmalloc (sizeof (struct coff_symfile_info
));
601 /* Save startup file's range of PC addresses to help blockframe.c
602 decide where the bottom of the stack is. */
603 if (bfd_get_file_flags (abfd
) & EXEC_P
)
605 /* Executable file -- record its entry point so we'll recognize
606 the startup file because it contains the entry point. */
607 entry_point
= bfd_get_start_address (abfd
);
611 /* Examination of non-executable.o files. Short-circuit this stuff. */
612 /* ~0 will not be in any file, we hope. */
614 /* set the startup file to be an empty range. */
615 startup_file_start
= 0;
616 startup_file_end
= 0;
618 /* Save the section number for the text section */
619 if (section
= bfd_get_section_by_name(abfd
,".text"))
620 text_bfd_scnum
= section
->index
;
625 /* This function is called for every section; it finds the outer limits
626 of the line table (minimum and maximum file offset) so that the
627 mainline code can read the whole thing for efficiency. */
631 find_linenos (abfd
, asect
, vpinfo
)
636 struct coff_symfile_info
*info
;
638 file_ptr offset
, maxoff
;
640 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
641 count
= asect
->lineno_count
;
646 size
= count
* local_linesz
;
648 info
= (struct coff_symfile_info
*)vpinfo
;
649 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
650 offset
= asect
->line_filepos
;
653 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
654 info
->min_lineno_offset
= offset
;
656 maxoff
= offset
+ size
;
657 if (maxoff
> info
->max_lineno_offset
)
658 info
->max_lineno_offset
= maxoff
;
662 /* The BFD for this file -- only good while we're actively reading
663 symbols into a psymtab or a symtab. */
665 static bfd
*symfile_bfd
;
667 /* Read a symbol file, after initialization by coff_symfile_init. */
668 /* FIXME! Addr and Mainline are not used yet -- this will not work for
669 shared libraries or add_file! */
673 coff_symfile_read (sf
, addr
, mainline
)
678 struct coff_symfile_info
*info
= (struct coff_symfile_info
*)sf
->sym_private
;
679 bfd
*abfd
= sf
->objfile
->obfd
;
680 coff_data_type
*cdata
= coff_data (abfd
);
681 char *name
= bfd_get_filename (abfd
);
686 int stringtab_offset
;
688 symfile_bfd
= abfd
; /* Kludge for swap routines */
690 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
691 desc
= fileno ((FILE *)(abfd
->iostream
)); /* File descriptor */
692 num_symbols
= bfd_get_symcount (abfd
); /* How many syms */
693 symtab_offset
= cdata
->sym_filepos
; /* Symbol table file offset */
694 stringtab_offset
= symtab_offset
+ /* String table file offset */
695 num_symbols
* cdata
->local_symesz
;
697 /* Set a few file-statics that give us specific information about
698 the particular COFF file format we're reading. */
699 local_linesz
= cdata
->local_linesz
;
700 local_n_btmask
= cdata
->local_n_btmask
;
701 local_n_btshft
= cdata
->local_n_btshft
;
702 local_n_tmask
= cdata
->local_n_tmask
;
703 local_n_tshift
= cdata
->local_n_tshift
;
704 local_linesz
= cdata
->local_linesz
;
705 local_symesz
= cdata
->local_symesz
;
706 local_auxesz
= cdata
->local_auxesz
;
708 /* Allocate space for raw symbol and aux entries, based on their
709 space requirements as reported by BFD. */
710 temp_sym
= (char *) xmalloc
711 (cdata
->local_symesz
+ cdata
->local_auxesz
);
712 temp_aux
= temp_sym
+ cdata
->local_symesz
;
713 make_cleanup (free_current_contents
, &temp_sym
);
716 /* Read the line number table, all at once. */
717 info
->min_lineno_offset
= 0;
718 info
->max_lineno_offset
= 0;
719 bfd_map_over_sections (abfd
, find_linenos
, info
);
721 val
= init_lineno (desc
, info
->min_lineno_offset
,
722 info
->max_lineno_offset
- info
->min_lineno_offset
);
724 error ("\"%s\": error reading line numbers\n", name
);
726 /* Now read the string table, all at once. */
728 val
= init_stringtab (desc
, stringtab_offset
);
730 error ("\"%s\": can't get string table", name
);
731 make_cleanup (free_stringtab
, 0);
733 /* Position to read the symbol table. Do not read it all at once. */
734 val
= lseek (desc
, (long)symtab_offset
, 0);
736 perror_with_name (name
);
738 init_misc_bunches ();
739 make_cleanup (discard_misc_bunches
, 0);
741 /* Now that the executable file is positioned at symbol table,
742 process it and define symbols accordingly. */
744 read_coff_symtab (desc
, num_symbols
, sf
->objfile
);
746 patch_opaque_types ();
748 /* Sort symbols alphabetically within each block. */
750 sort_all_symtab_syms ();
752 /* Go over the misc symbol bunches and install them in vector. */
754 condense_misc_bunches (!mainline
);
756 /* Make a default for file to list. */
758 select_source_symtab (0); /* FIXME, this might be too slow, see dbxread */
767 /* Simplified internal version of coff symbol table information */
771 int c_symnum
; /* symbol number of this entry */
772 int c_naux
; /* 0 if syment only, 1 if syment + auxent, etc */
779 /* Given pointers to a symbol table in coff style exec file,
780 analyze them and create struct symtab's describing the symbols.
781 NSYMS is the number of symbols in the symbol table.
782 We read them one at a time using read_one_sym (). */
785 read_coff_symtab (desc
, nsyms
, objfile
)
788 struct objfile
*objfile
;
790 int newfd
; /* Avoid multiple closes on same desc */
792 register struct context_stack
*new;
793 struct coff_symbol coff_symbol
;
794 register struct coff_symbol
*cs
= &coff_symbol
;
795 static struct internal_syment main_sym
;
796 static union internal_auxent main_aux
;
797 struct coff_symbol fcn_cs_saved
;
798 static struct internal_syment fcn_sym_saved
;
799 static union internal_auxent fcn_aux_saved
;
801 /* A .file is open. */
802 int in_source_file
= 0;
803 int num_object_files
= 0;
804 int next_file_symnum
= -1;
806 /* Name of the current file. */
807 char *filestring
= "";
813 struct cleanup
*old_chain
;
818 fatal ("Too many open files");
819 stream
= fdopen (newfd
, "r");
821 /* These cleanups will be discarded below if we succeed. */
822 old_chain
= make_cleanup (free_objfile
, objfile
);
823 make_cleanup (fclose
, stream
);
825 nlist_stream_global
= stream
;
826 nlist_nsyms_global
= nsyms
;
827 last_source_file
= 0;
828 bzero (opaque_type_chain
, sizeof opaque_type_chain
);
830 if (type_vector
) /* Get rid of previous one */
832 type_vector_length
= 160;
833 type_vector
= (struct type
**)
834 xmalloc (type_vector_length
* sizeof (struct type
*));
835 bzero (type_vector
, type_vector_length
* sizeof (struct type
*));
840 while (symnum
< nsyms
)
842 QUIT
; /* Make this command interruptable. */
843 read_one_sym (cs
, &main_sym
, &main_aux
);
846 temp_sem_val
= cs
->c_name
[0] << 24 | cs
->c_name
[1] << 16 |
847 cs
->c_name
[2] << 8 | cs
->c_name
[3];
848 if (int_sem_val
== temp_sem_val
)
849 last_coffsem
= (int) strtol (cs
->c_name
+4, (char **) NULL
, 10);
852 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
854 if (last_source_file
)
855 end_symtab (objfile
);
858 complete_symtab ("_globals_", 0, first_object_file_end
);
859 /* done with all files, everything from here on out is globals */
862 /* Special case for file with type declarations only, no text. */
863 if (!last_source_file
&& SDB_TYPE (cs
->c_type
)
864 && cs
->c_secnum
== N_DEBUG
)
865 complete_symtab (filestring
, 0, 0);
867 /* Typedefs should not be treated as symbol definitions. */
868 if (ISFCN (cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
870 /* record as misc function. if we get '.bf' next,
871 * then we undo this step
873 record_misc_function (cs
->c_name
, cs
->c_value
);
875 fcn_line_ptr
= main_aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
876 fcn_start_addr
= cs
->c_value
;
878 fcn_sym_saved
= main_sym
;
879 fcn_aux_saved
= main_aux
;
883 switch (cs
->c_sclass
)
892 printf ("Bad n_sclass = %d\n", cs
->c_sclass
);
897 * c_value field contains symnum of next .file entry in table
898 * or symnum of first global after last .file.
900 next_file_symnum
= cs
->c_value
;
901 filestring
= getfilename (&main_aux
);
903 * Complete symbol table for last object file
904 * containing debugging information.
906 if (last_source_file
)
908 end_symtab (objfile
);
915 if (cs
->c_name
[0] == '.') {
916 if (strcmp (cs
->c_name
, ".text") == 0) {
917 /* FIXME: don't wire in ".text" as section name
919 if (++num_object_files
== 1) {
920 /* last address of startup file */
921 first_object_file_end
= cs
->c_value
+
922 main_aux
.x_scn
.x_scnlen
;
924 /* Check for in_source_file deals with case of
925 a file with debugging symbols
926 followed by a later file with no symbols. */
928 complete_symtab (filestring
, cs
->c_value
,
929 main_aux
.x_scn
.x_scnlen
);
932 /* flush rest of '.' symbols */
935 else if (!SDB_TYPE (cs
->c_type
)
936 && cs
->c_name
[0] == 'L'
937 && (strncmp (cs
->c_name
, "LI%", 3) == 0
938 || strncmp (cs
->c_name
, "LF%", 3) == 0
939 || strncmp (cs
->c_name
,"LC%",3) == 0
940 || strncmp (cs
->c_name
,"LP%",3) == 0
941 || strncmp (cs
->c_name
,"LPB%",4) == 0
942 || strncmp (cs
->c_name
,"LBB%",4) == 0
943 || strncmp (cs
->c_name
,"LBE%",4) == 0
944 || strncmp (cs
->c_name
,"LPBX%",5) == 0))
945 /* At least on a 3b1, gcc generates swbeg and string labels
946 that look like this. Ignore them. */
948 /* fall in for static symbols that don't start with '.' */
950 if (!SDB_TYPE (cs
->c_type
)) {
951 /* FIXME: This is BOGUS Will Robinson!
952 Coff should provide the SEC_CODE flag for executable sections,
953 then if we could look up sections by section number we
954 could see if the flags indicate SEC_CODE. If so, then
955 record this symbol as a miscellaneous function. But why
956 are absolute syms recorded as functions, anyway? */
957 if (cs
->c_secnum
<= text_bfd_scnum
+1) {/* text or abs */
958 record_misc_function (cs
->c_name
, cs
->c_value
);
964 (void) process_coff_symbol (cs
, &main_aux
);
968 if (strcmp (cs
->c_name
, ".bf") == 0)
972 /* value contains address of first non-init type code */
973 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
974 contains line number of '{' } */
976 complain (no_aux_complaint
, cs
->c_symnum
);
977 fcn_first_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
979 new = (struct context_stack
*)
980 xmalloc (sizeof (struct context_stack
));
981 new->depth
= depth
= 0;
985 new->old_blocks
= pending_blocks
;
986 new->start_addr
= fcn_start_addr
;
987 fcn_cs_saved
.c_name
= getsymname (&fcn_sym_saved
);
988 new->name
= process_coff_symbol (&fcn_cs_saved
,
991 else if (strcmp (cs
->c_name
, ".ef") == 0)
993 /* the value of .ef is the address of epilogue code;
996 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
997 contains number of lines to '}' */
1001 complain (&ef_complaint
, cs
->c_symnum
);
1002 within_function
= 0;
1005 if (cs
->c_naux
!= 1) {
1006 complain (no_aux_complaint
, cs
->c_symnum
);
1007 fcn_last_line
= 0x7FFFFFFF;
1009 fcn_last_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
1011 enter_linenos (fcn_line_ptr
, fcn_first_line
, fcn_last_line
);
1013 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1015 #if defined (FUNCTION_EPILOGUE_SIZE)
1016 /* This macro should be defined only on
1018 fcn_aux_saved.x_sym.x_misc.x_fsize
1019 field is always zero.
1020 So use the .bf record information that
1021 points to the epilogue and add the size
1023 cs
->c_value
+ FUNCTION_EPILOGUE_SIZE
1025 fcn_cs_saved
.c_value
+
1026 fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1030 within_function
= 0;
1036 if (strcmp (cs
->c_name
, ".bb") == 0)
1038 new = (struct context_stack
*)
1039 xmalloc (sizeof (struct context_stack
));
1042 new->next
= context_stack
;
1043 context_stack
= new;
1044 new->locals
= local_symbols
;
1045 new->old_blocks
= pending_blocks
;
1046 new->start_addr
= cs
->c_value
;
1050 else if (strcmp (cs
->c_name
, ".eb") == 0)
1052 new = context_stack
;
1053 if (new == 0 || depth
!= new->depth
)
1054 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1056 if (local_symbols
&& context_stack
->next
)
1058 /* Make a block for the local symbols within. */
1059 finish_block (0, &local_symbols
, new->old_blocks
,
1060 new->start_addr
, cs
->c_value
);
1063 local_symbols
= new->locals
;
1064 context_stack
= new->next
;
1070 (void) process_coff_symbol (cs
, &main_aux
);
1075 if (last_source_file
)
1076 end_symtab (objfile
);
1078 discard_cleanups (old_chain
);
1081 /* Routines for reading headers and symbols from executable. */
1084 /* Move these XXXMAGIC symbol defns into BFD! */
1086 /* Read COFF file header, check magic number,
1087 and return number of symbols. */
1088 read_file_hdr (chan
, file_hdr
)
1092 lseek (chan
, 0L, 0);
1093 if (myread (chan
, (char *)file_hdr
, FILHSZ
) < 0)
1096 switch (file_hdr
->f_magic
)
1111 #if defined (MC68KWRMAGIC) \
1112 && (!defined (MC68MAGIC) || MC68KWRMAGIC != MC68MAGIC)
1126 case I960ROMAGIC
: /* Intel 960 */
1129 case I960RWMAGIC
: /* Intel 960 */
1131 return file_hdr
->f_nsyms
;
1135 if (BADMAG(file_hdr
))
1138 return file_hdr
->f_nsyms
;
1146 /* Read the next symbol, swap it, and return it in both internal_syment
1147 form, and coff_symbol form. Also return its first auxent, if any,
1148 in internal_auxent form, and skip any other auxents. */
1151 read_one_sym (cs
, sym
, aux
)
1152 register struct coff_symbol
*cs
;
1153 register struct internal_syment
*sym
;
1154 register union internal_auxent
*aux
;
1158 cs
->c_symnum
= symnum
;
1159 fread (temp_sym
, local_symesz
, 1, nlist_stream_global
);
1160 bfd_coff_swap_sym_in (symfile_bfd
, temp_sym
, (char *)sym
);
1161 cs
->c_naux
= sym
->n_numaux
& 0xff;
1162 if (cs
->c_naux
>= 1)
1164 fread (temp_aux
, local_auxesz
, 1, nlist_stream_global
);
1165 bfd_coff_swap_aux_in (symfile_bfd
, temp_aux
, sym
->n_type
, sym
->n_sclass
,
1167 /* If more than one aux entry, read past it (only the first aux
1169 for (i
= 1; i
< cs
->c_naux
; i
++)
1170 fread (temp_aux
, local_auxesz
, 1, nlist_stream_global
);
1172 cs
->c_name
= getsymname (sym
);
1173 cs
->c_value
= sym
->n_value
;
1174 cs
->c_sclass
= (sym
->n_sclass
& 0xff);
1175 cs
->c_secnum
= sym
->n_scnum
;
1176 cs
->c_type
= (unsigned) sym
->n_type
;
1177 if (!SDB_TYPE (cs
->c_type
))
1180 symnum
+= 1 + cs
->c_naux
;
1183 /* Support for string table handling */
1185 static char *stringtab
= NULL
;
1188 init_stringtab (chan
, offset
)
1194 unsigned char lengthbuf
[4];
1202 if (lseek (chan
, offset
, 0) < 0)
1205 val
= myread (chan
, (char *)lengthbuf
, sizeof lengthbuf
);
1206 length
= bfd_h_get_32 (symfile_bfd
, lengthbuf
);
1208 /* If no string table is needed, then the file may end immediately
1209 after the symbols. Just return with `stringtab' set to null. */
1210 if (val
!= sizeof length
|| length
< sizeof length
)
1213 stringtab
= (char *) xmalloc (length
);
1214 if (stringtab
== NULL
)
1217 bcopy (&length
, stringtab
, sizeof length
);
1218 if (length
== sizeof length
) /* Empty table -- just the count */
1221 val
= myread (chan
, stringtab
+ sizeof length
, length
- sizeof length
);
1222 if (val
!= length
- sizeof length
|| stringtab
[length
- 1] != '\0')
1237 getsymname (symbol_entry
)
1238 struct internal_syment
*symbol_entry
;
1240 static char buffer
[SYMNMLEN
+1];
1243 if (symbol_entry
->_n
._n_n
._n_zeroes
== 0)
1245 result
= stringtab
+ symbol_entry
->_n
._n_n
._n_offset
;
1249 strncpy (buffer
, symbol_entry
->_n
._n_name
, SYMNMLEN
);
1250 buffer
[SYMNMLEN
] = '\0';
1257 getfilename (aux_entry
)
1258 union internal_auxent
*aux_entry
;
1260 static char buffer
[BUFSIZ
];
1261 register char *temp
;
1263 extern char *rindex ();
1265 #ifndef COFF_NO_LONG_FILE_NAMES
1266 #if defined (x_zeroes)
1268 if (aux_entry
->x_zeroes
== 0)
1269 strcpy (buffer
, stringtab
+ aux_entry
->x_offset
);
1270 #else /* no x_zeroes */
1271 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1272 strcpy (buffer
, stringtab
+ aux_entry
->x_file
.x_n
.x_offset
);
1273 #endif /* no x_zeroes */
1275 #endif /* COFF_NO_LONG_FILE_NAMES */
1277 #if defined (x_name)
1279 strncpy (buffer
, aux_entry
->x_name
, FILNMLEN
);
1281 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1283 buffer
[FILNMLEN
] = '\0';
1286 if ((temp
= rindex (result
, '/')) != NULL
)
1291 /* Support for line number handling */
1292 static char *linetab
= NULL
;
1293 static long linetab_offset
;
1294 static unsigned long linetab_size
;
1296 /* Read in all the line numbers for fast lookups later. Leave them in
1297 external (unswapped) format in memory; we'll swap them as we enter
1298 them into GDB's data structures. */
1301 init_lineno (chan
, offset
, size
)
1308 linetab_offset
= offset
;
1309 linetab_size
= size
;
1314 if (lseek (chan
, offset
, 0) < 0)
1317 /* Allocate the desired table, plus a sentinel */
1318 linetab
= (char *) xmalloc (size
+ local_linesz
);
1320 val
= myread (chan
, linetab
, size
);
1324 /* Terminate it with an all-zero sentinel record */
1325 bzero (linetab
+ size
, local_linesz
);
1327 make_cleanup (free
, linetab
); /* Be sure it gets de-allocated. */
1331 #if !defined (L_LNNO32)
1332 #define L_LNNO32(lp) ((lp)->l_lnno)
1336 enter_linenos (file_offset
, first_line
, last_line
)
1338 register int first_line
;
1339 register int last_line
;
1341 register char *rawptr
;
1342 struct internal_lineno lptr
;
1344 if (file_offset
< linetab_offset
)
1346 complain (&lineno_complaint
, file_offset
);
1347 if (file_offset
> linetab_size
) /* Too big to be an offset? */
1349 file_offset
+= linetab_offset
; /* Try reading at that linetab offset */
1352 rawptr
= &linetab
[file_offset
- linetab_offset
];
1354 /* skip first line entry for each function */
1355 rawptr
+= local_linesz
;
1356 /* line numbers start at one for the first line of the function */
1360 bfd_coff_swap_lineno_in (symfile_bfd
, rawptr
, &lptr
);
1361 rawptr
+= local_linesz
;
1362 /* The next function, or the sentinel, will have L_LNNO32 zero; we exit. */
1363 if (L_LNNO32 (&lptr
) && L_LNNO32 (&lptr
) <= last_line
)
1364 record_line (first_line
+ L_LNNO32 (&lptr
), lptr
.l_addr
.l_paddr
);
1374 register char *p
= name
;
1375 register int total
= p
[0];
1388 return total
% HASHSIZE
;
1392 patch_type (type
, real_type
)
1394 struct type
*real_type
;
1396 register struct type
*target
= TYPE_TARGET_TYPE (type
);
1397 register struct type
*real_target
= TYPE_TARGET_TYPE (real_type
);
1398 int field_size
= TYPE_NFIELDS (real_target
) * sizeof (struct field
);
1400 TYPE_LENGTH (target
) = TYPE_LENGTH (real_target
);
1401 TYPE_NFIELDS (target
) = TYPE_NFIELDS (real_target
);
1402 TYPE_FIELDS (target
) = (struct field
*)
1403 obstack_alloc (symbol_obstack
, field_size
);
1405 bcopy (TYPE_FIELDS (real_target
), TYPE_FIELDS (target
), field_size
);
1407 if (TYPE_NAME (real_target
))
1409 if (TYPE_NAME (target
))
1410 free (TYPE_NAME (target
));
1411 TYPE_NAME (target
) = concat (TYPE_NAME (real_target
), NULL
);
1415 /* Patch up all appropriate typdef symbols in the opaque_type_chains
1416 so that they can be used to print out opaque data structures properly */
1419 patch_opaque_types ()
1423 /* Look at each symbol in the per-file block of each symtab. */
1424 for (s
= symtab_list
; s
; s
= s
->next
)
1426 register struct block
*b
;
1429 /* Go through the per-file symbols only */
1430 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
1431 for (i
= BLOCK_NSYMS (b
) - 1; i
>= 0; i
--)
1433 register struct symbol
*real_sym
;
1435 /* Find completed typedefs to use to fix opaque ones.
1436 Remove syms from the chain when their types are stored,
1437 but search the whole chain, as there may be several syms
1438 from different files with the same name. */
1439 real_sym
= BLOCK_SYM (b
, i
);
1440 if (SYMBOL_CLASS (real_sym
) == LOC_TYPEDEF
&&
1441 SYMBOL_NAMESPACE (real_sym
) == VAR_NAMESPACE
&&
1442 TYPE_CODE (SYMBOL_TYPE (real_sym
)) == TYPE_CODE_PTR
&&
1443 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym
))) != 0)
1445 register char *name
= SYMBOL_NAME (real_sym
);
1446 register int hash
= hashname (name
);
1447 register struct symbol
*sym
, *prev
;
1450 for (sym
= opaque_type_chain
[hash
]; sym
;)
1452 if (name
[0] == SYMBOL_NAME (sym
)[0] &&
1453 !strcmp (name
+ 1, SYMBOL_NAME (sym
) + 1))
1456 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
1458 opaque_type_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
1460 patch_type (SYMBOL_TYPE (sym
), SYMBOL_TYPE (real_sym
));
1463 sym
= SYMBOL_VALUE_CHAIN (prev
);
1465 sym
= opaque_type_chain
[hash
];
1470 sym
= SYMBOL_VALUE_CHAIN (sym
);
1478 #if defined (clipper)
1479 #define BELIEVE_PCC_PROMOTION 1
1482 static struct symbol
*
1483 process_coff_symbol (cs
, aux
)
1484 register struct coff_symbol
*cs
;
1485 register union internal_auxent
*aux
;
1487 register struct symbol
*sym
1488 = (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
1490 #ifdef NAMES_HAVE_UNDERSCORE
1496 bzero (sym
, sizeof (struct symbol
));
1498 name
= (name
[0] == '_' ? name
+ offset
: name
);
1499 SYMBOL_NAME (sym
) = obstack_copy0 (symbol_obstack
, name
, strlen (name
));
1501 /* default assumptions */
1502 SYMBOL_VALUE (sym
) = cs
->c_value
;
1503 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1505 if (ISFCN (cs
->c_type
))
1508 /* FIXME: This has NOT been tested. The DBX version has.. */
1509 /* Generate a template for the type of this function. The
1510 types of the arguments will be added as we read the symbol
1512 struct type
*new = (struct type
*)
1513 obstack_alloc (symbol_obstack
, sizeof (struct type
));
1515 bcopy(lookup_function_type (decode_function_type (cs
, cs
->c_type
, aux
)),
1516 new, sizeof(struct type
));
1517 SYMBOL_TYPE (sym
) = new;
1518 in_function_type
= SYMBOL_TYPE(sym
);
1521 lookup_function_type (decode_function_type (cs
, cs
->c_type
, aux
));
1524 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1525 if (cs
->c_sclass
== C_STAT
)
1526 add_symbol_to_list (sym
, &file_symbols
);
1527 else if (cs
->c_sclass
== C_EXT
)
1528 add_symbol_to_list (sym
, &global_symbols
);
1532 SYMBOL_TYPE (sym
) = decode_type (cs
, cs
->c_type
, aux
);
1533 switch (cs
->c_sclass
)
1539 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1540 add_symbol_to_list (sym
, &local_symbols
);
1544 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1545 SYMBOL_VALUE_ADDRESS (sym
) = (CORE_ADDR
) cs
->c_value
;
1546 add_symbol_to_list (sym
, &global_symbols
);
1550 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1551 SYMBOL_VALUE_ADDRESS (sym
) = (CORE_ADDR
) cs
->c_value
;
1552 if (within_function
) {
1553 /* Static symbol of local scope */
1554 add_symbol_to_list (sym
, &local_symbols
);
1557 /* Static symbol at top level of file */
1558 add_symbol_to_list (sym
, &file_symbols
);
1562 #ifdef C_GLBLREG /* AMD coff */
1566 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1567 SYMBOL_VALUE (sym
) = SDB_REG_TO_REGNUM(cs
->c_value
);
1568 add_symbol_to_list (sym
, &local_symbols
);
1575 SYMBOL_CLASS (sym
) = LOC_ARG
;
1577 /* FIXME: This has not bee tested. */
1578 /* Add parameter to function. */
1579 add_param_to_type(&in_function_type
,sym
);
1581 add_symbol_to_list (sym
, &local_symbols
);
1582 #if !defined (BELIEVE_PCC_PROMOTION)
1583 /* If PCC says a parameter is a short or a char,
1584 it is really an int. */
1585 if (SYMBOL_TYPE (sym
) == builtin_type_char
1586 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1587 SYMBOL_TYPE (sym
) = builtin_type_int
;
1588 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1589 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1590 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1595 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1596 SYMBOL_VALUE (sym
) = SDB_REG_TO_REGNUM(cs
->c_value
);
1597 add_symbol_to_list (sym
, &local_symbols
);
1598 #if !defined (BELIEVE_PCC_PROMOTION)
1599 /* If PCC says a parameter is a short or a char,
1600 it is really an int. */
1601 if (SYMBOL_TYPE (sym
) == builtin_type_char
1602 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1603 SYMBOL_TYPE (sym
) = builtin_type_int
;
1604 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1605 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1606 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1611 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1612 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1614 /* If type has no name, give it one */
1615 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1616 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1617 TYPE_NAME (SYMBOL_TYPE (sym
))
1618 = concat (SYMBOL_NAME (sym
), NULL
);
1620 /* Keep track of any type which points to empty structured type,
1621 so it can be filled from a definition from another file */
1622 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
&&
1623 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym
))) == 0)
1625 register int i
= hashname (SYMBOL_NAME (sym
));
1627 SYMBOL_VALUE_CHAIN (sym
) = opaque_type_chain
[i
];
1628 opaque_type_chain
[i
] = sym
;
1630 add_symbol_to_list (sym
, &file_symbols
);
1636 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1637 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1638 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1639 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1640 TYPE_NAME (SYMBOL_TYPE (sym
))
1642 (cs
->c_sclass
== C_ENTAG
1644 : (cs
->c_sclass
== C_STRTAG
1645 ? "struct " : "union ")),
1646 SYMBOL_NAME (sym
), NULL
);
1647 add_symbol_to_list (sym
, &file_symbols
);
1657 /* Decode a coff type specifier;
1658 return the type that is meant. */
1662 decode_type (cs
, c_type
, aux
)
1663 register struct coff_symbol
*cs
;
1664 unsigned int c_type
;
1665 register union internal_auxent
*aux
;
1667 register struct type
*type
= 0;
1668 unsigned int new_c_type
;
1670 if (c_type
& ~N_BTMASK
)
1672 new_c_type
= DECREF (c_type
);
1675 type
= decode_type (cs
, new_c_type
, aux
);
1676 type
= lookup_pointer_type (type
);
1678 else if (ISFCN (c_type
))
1680 type
= decode_type (cs
, new_c_type
, aux
);
1681 type
= lookup_function_type (type
);
1683 else if (ISARY (c_type
))
1686 register unsigned short *dim
;
1687 struct type
*base_type
;
1689 /* Define an array type. */
1690 /* auxent refers to array, not base type */
1691 if (aux
->x_sym
.x_tagndx
.l
== 0)
1694 /* shift the indices down */
1695 dim
= &aux
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0];
1698 for (i
= 0; *dim
&& i
< DIMNUM
- 1; i
++, dim
++)
1702 type
= (struct type
*)
1703 obstack_alloc (symbol_obstack
, sizeof (struct type
));
1704 bzero (type
, sizeof (struct type
));
1706 base_type
= decode_type (cs
, new_c_type
, aux
);
1708 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
1709 TYPE_TARGET_TYPE (type
) = base_type
;
1710 TYPE_LENGTH (type
) = n
* TYPE_LENGTH (base_type
);
1715 /* Reference to existing type */
1716 if (cs
->c_naux
> 0 && aux
->x_sym
.x_tagndx
.l
!= 0)
1718 type
= coff_alloc_type (aux
->x_sym
.x_tagndx
.l
);
1722 return decode_base_type (cs
, BTYPE (c_type
), aux
);
1725 /* Decode a coff type specifier for function definition;
1726 return the type that the function returns. */
1730 decode_function_type (cs
, c_type
, aux
)
1731 register struct coff_symbol
*cs
;
1732 unsigned int c_type
;
1733 register union internal_auxent
*aux
;
1735 if (aux
->x_sym
.x_tagndx
.l
== 0)
1736 cs
->c_naux
= 0; /* auxent refers to function, not base type */
1738 return decode_type (cs
, DECREF (c_type
), aux
);
1745 decode_base_type (cs
, c_type
, aux
)
1746 register struct coff_symbol
*cs
;
1747 unsigned int c_type
;
1748 register union internal_auxent
*aux
;
1755 /* shows up with "void (*foo)();" structure members */
1756 return builtin_type_void
;
1759 /* DGUX actually defines both T_ARG and T_VOID to the same value. */
1762 /* Shows up in DGUX, I think. Not sure where. */
1763 return builtin_type_void
; /* shouldn't show up here */
1769 /* Intel 960 COFF has this symbol and meaning. */
1770 return builtin_type_void
;
1774 return builtin_type_char
;
1777 return builtin_type_short
;
1780 return builtin_type_int
;
1783 return builtin_type_long
;
1786 return builtin_type_float
;
1789 return builtin_type_double
;
1792 if (cs
->c_naux
!= 1)
1794 /* anonymous structure type */
1795 type
= coff_alloc_type (cs
->c_symnum
);
1796 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1797 TYPE_NAME (type
) = concat ("struct ", "<opaque>", NULL
);
1798 TYPE_CPLUS_SPECIFIC (type
)
1799 = (struct cplus_struct_type
*) obstack_alloc (symbol_obstack
, sizeof (struct cplus_struct_type
));
1800 bzero (TYPE_CPLUS_SPECIFIC (type
), sizeof (struct cplus_struct_type
));
1801 TYPE_LENGTH (type
) = 0;
1802 TYPE_FIELDS (type
) = 0;
1803 TYPE_NFIELDS (type
) = 0;
1807 type
= read_struct_type (cs
->c_symnum
,
1808 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1809 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1814 if (cs
->c_naux
!= 1)
1816 /* anonymous union type */
1817 type
= coff_alloc_type (cs
->c_symnum
);
1818 TYPE_NAME (type
) = concat ("union ", "<opaque>", NULL
);
1819 TYPE_CPLUS_SPECIFIC (type
) = (struct cplus_struct_type
*)
1820 obstack_alloc (symbol_obstack
, sizeof (struct cplus_struct_type
));
1821 bzero (TYPE_CPLUS_SPECIFIC (type
), sizeof (struct cplus_struct_type
));
1822 TYPE_LENGTH (type
) = 0;
1823 TYPE_LENGTH (type
) = 0;
1824 TYPE_FIELDS (type
) = 0;
1825 TYPE_NFIELDS (type
) = 0;
1829 type
= read_struct_type (cs
->c_symnum
,
1830 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1831 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1833 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1837 return read_enum_type (cs
->c_symnum
,
1838 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1839 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1842 /* shouldn't show up here */
1846 return builtin_type_unsigned_char
;
1849 return builtin_type_unsigned_short
;
1852 return builtin_type_unsigned_int
;
1855 return builtin_type_unsigned_long
;
1857 printf ("unexpected type %d at symnum %d\n", c_type
, cs
->c_symnum
);
1858 return builtin_type_void
;
1861 /* This page contains subroutines of read_type. */
1863 /* Read the description of a structure (or union type)
1864 and return an object describing the type. */
1866 static struct type
*
1867 read_struct_type (index
, length
, lastsym
)
1874 struct nextfield
*next
;
1878 register struct type
*type
;
1879 register struct nextfield
*list
= 0;
1880 struct nextfield
*new;
1884 #ifdef NAMES_HAVE_UNDERSCORE
1889 struct coff_symbol member_sym
;
1890 register struct coff_symbol
*ms
= &member_sym
;
1891 struct internal_syment sub_sym
;
1892 union internal_auxent sub_aux
;
1895 type
= coff_alloc_type (index
);
1896 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1897 TYPE_CPLUS_SPECIFIC (type
)
1898 = (struct cplus_struct_type
*) obstack_alloc (symbol_obstack
, sizeof (struct cplus_struct_type
));
1899 bzero (TYPE_CPLUS_SPECIFIC (type
), sizeof (struct cplus_struct_type
));
1900 TYPE_LENGTH (type
) = length
;
1902 while (!done
&& symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
1904 read_one_sym (ms
, &sub_sym
, &sub_aux
);
1906 name
= (name
[0] == '_' ? name
+ offset
: name
);
1908 switch (ms
->c_sclass
)
1913 /* Get space to record the next field's data. */
1914 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1918 /* Save the data. */
1919 list
->field
.name
= savestring (name
, strlen (name
));
1920 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1921 list
->field
.bitpos
= 8 * ms
->c_value
;
1922 list
->field
.bitsize
= 0;
1928 /* Get space to record the next field's data. */
1929 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1933 /* Save the data. */
1934 list
->field
.name
= savestring (name
, strlen (name
));
1935 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1936 list
->field
.bitpos
= ms
->c_value
;
1937 list
->field
.bitsize
= sub_aux
.x_sym
.x_misc
.x_lnsz
.x_size
;
1946 /* Now create the vector of fields, and record how big it is. */
1948 TYPE_NFIELDS (type
) = nfields
;
1949 TYPE_FIELDS (type
) = (struct field
*)
1950 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nfields
);
1952 /* Copy the saved-up fields into the field vector. */
1954 for (n
= nfields
; list
; list
= list
->next
)
1955 TYPE_FIELD (type
, --n
) = list
->field
;
1960 /* Read a definition of an enumeration type,
1961 and create and return a suitable type object.
1962 Also defines the symbols that represent the values of the type. */
1963 /* Currently assumes it's sizeof (int) and doesn't use length. */
1966 static struct type
*
1967 read_enum_type (index
, length
, lastsym
)
1972 register struct symbol
*sym
;
1973 register struct type
*type
;
1976 struct pending
**symlist
;
1977 struct coff_symbol member_sym
;
1978 register struct coff_symbol
*ms
= &member_sym
;
1979 struct internal_syment sub_sym
;
1980 union internal_auxent sub_aux
;
1981 struct pending
*osyms
, *syms
;
1984 #ifdef NAMES_HAVE_UNDERSCORE
1990 type
= coff_alloc_type (index
);
1991 if (within_function
)
1992 symlist
= &local_symbols
;
1994 symlist
= &file_symbols
;
1997 while (!done
&& symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
1999 read_one_sym (ms
, &sub_sym
, &sub_aux
);
2001 name
= (name
[0] == '_' ? name
+ offset
: name
);
2003 switch (ms
->c_sclass
)
2006 sym
= (struct symbol
*) xmalloc (sizeof (struct symbol
));
2007 bzero (sym
, sizeof (struct symbol
));
2009 SYMBOL_NAME (sym
) = savestring (name
, strlen (name
));
2010 SYMBOL_CLASS (sym
) = LOC_CONST
;
2011 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2012 SYMBOL_VALUE (sym
) = ms
->c_value
;
2013 add_symbol_to_list (sym
, symlist
);
2018 /* Sometimes the linker (on 386/ix 2.0.2 at least) screws
2019 up the count of how many symbols to read. So stop
2026 /* Now fill in the fields of the type-structure. */
2028 /* FIXME: Should be sizeof (int) on target, not host. */
2029 TYPE_LENGTH (type
) = sizeof (int);
2030 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2031 TYPE_NFIELDS (type
) = nsyms
;
2032 TYPE_FIELDS (type
) = (struct field
*)
2033 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nsyms
);
2035 /* Find the symbols for the values and put them into the type.
2036 The symbols can be found in the symlist that we put them on
2037 to cause them to be defined. osyms contains the old value
2038 of that symlist; everything up to there was defined by us. */
2040 for (syms
= *symlist
, n
= nsyms
; syms
!= osyms
; syms
= syms
->next
)
2042 SYMBOL_TYPE (syms
->symbol
) = type
;
2043 TYPE_FIELD_NAME (type
, --n
) = SYMBOL_NAME (syms
->symbol
);
2044 TYPE_FIELD_VALUE (type
, n
) = 0;
2045 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (syms
->symbol
);
2046 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2048 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2049 if(TYPE_NFIELDS(type
) == 2 &&
2050 ((!strcmp(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2051 !strcmp(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2052 (!strcmp(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2053 !strcmp(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2054 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2058 /* Register our ability to parse symbols for coff BFD files */
2060 static struct sym_fns coff_sym_fns
=
2063 coff_new_init
, coff_symfile_init
, coff_symfile_read
,
2067 _initialize_coffread ()
2069 add_symtab_fns(&coff_sym_fns
);