1 /* Read coff symbol tables and convert to internal format, for GDB.
2 Design and support routines derived from dbxread.c, and UMAX COFF
3 specific routines written 9/1/87 by David D. Johnson, Brown University.
4 Revised 11/27/87 ddj@cs.brown.edu
5 Copyright (C) 1987-1991 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
27 #include "breakpoint.h"
32 /* Need to get C_VERSION and friends. */
35 #include <intel-coff.h>
36 #endif /* not TDESC */
41 #include "libcoff.h" /* FIXME secret internal data from BFD */
43 static void add_symbol_to_list ();
44 static void read_coff_symtab ();
45 static void patch_opaque_types ();
46 static struct type
*decode_function_type ();
47 static struct type
*decode_type ();
48 static struct type
*decode_base_type ();
49 static struct type
*read_enum_type ();
50 static struct type
*read_struct_type ();
51 static void finish_block ();
52 static struct blockvector
*make_blockvector ();
53 static struct symbol
*process_coff_symbol ();
54 static int init_stringtab ();
55 static void free_stringtab ();
56 static char *getfilename ();
57 static char *getsymname ();
58 static int init_lineno ();
59 static void enter_linenos ();
60 static void read_one_sym ();
63 extern void free_all_symtabs ();
64 extern void free_all_psymtabs ();
66 /* To be an sdb debug type, type must have at least a basic or primary
67 derived type. Using this rather than checking against T_NULL is
68 said to prevent core dumps if we try to operate on Michael Bloom
71 #define SDB_TYPE(type) (BTYPE(type) | (type & N_TMASK))
73 /* external routines from the BFD library -- undocumented interface used
74 by GDB to read symbols. Move to libcoff.h. FIXME-SOMEDAY! */
75 extern void bfd_coff_swap_sym_in (/* symfile_bfd, &sym */);
76 extern void bfd_coff_swap_aux_in (/* symfile_bfd, &aux, type, sclass */);
77 extern void bfd_coff_swap_lineno_in (/* symfile_bfd, &lineno */);
78 extern void bfd_coff_swap_scnhdr_in (/* bfd, scnhdr_ext, scnhdr_int */);
80 extern void bfd_coff_swap_sym (/* symfile_bfd, &sym */);
81 extern void bfd_coff_swap_aux (/* symfile_bfd, &aux, type, sclass */);
82 extern void bfd_coff_swap_lineno (/* symfile_bfd, &lineno */);
85 /* Name of source file whose symbol data we are now processing.
86 This comes from a symbol named ".file". */
88 static char *last_source_file
;
90 /* Core address of start and end of text of current source file.
91 This comes from a ".text" symbol where x_nlinno > 0. */
93 static CORE_ADDR cur_src_start_addr
;
94 static CORE_ADDR cur_src_end_addr
;
96 /* Core address of the end of the first object file. */
97 static CORE_ADDR first_object_file_end
;
99 /* End of the text segment of the executable file,
100 as found in the symbol _etext. */
102 static CORE_ADDR end_of_text_addr
;
104 /* The addresses of the symbol table stream and number of symbols
105 of the object file we are reading (as copied into core). */
107 static FILE *nlist_stream_global
;
108 static int nlist_nsyms_global
;
110 /* The entry point (starting address) of the file, if it is an executable. */
112 static CORE_ADDR entry_point
;
114 /* The index in the symbol table of the last coff symbol that was processed. */
118 /* Vector of types defined so far, indexed by their coff symnum. */
120 static struct typevector
*type_vector
;
122 /* Number of elements allocated for type_vector currently. */
124 static int type_vector_length
;
126 /* Vector of line number information. */
128 static struct linetable
*line_vector
;
130 /* Index of next entry to go in line_vector_index. */
132 static int line_vector_index
;
134 /* Last line number recorded in the line vector. */
136 static int prev_line_number
;
138 /* Number of elements allocated for line_vector currently. */
140 static int line_vector_length
;
145 int int_sem_val
= 's' << 24 | 'e' << 16 | 'm' << 8 | '.';
147 int last_coffsem
= 2;
149 /* This isn't used currently. */
150 int last_coffsyn
= 0;
152 int debug_info
= 0; /*used by tdesc */
153 extern dc_dcontext_t tdesc_handle
;
154 extern int safe_to_init_tdesc_context
;
157 /* Chain of typedefs of pointers to empty struct/union types.
158 They are chained thru the SYMBOL_VALUE_CHAIN. */
161 static struct symbol
*opaque_type_chain
[HASHSIZE
];
163 /* Record the symbols defined for each context in a list.
164 We don't create a struct block for the context until we
165 know how long to make it. */
169 struct pending
*next
;
170 struct symbol
*symbol
;
173 /* Here are the three lists that symbols are put on. */
175 struct pending
*file_symbols
; /* static at top level, and types */
177 struct pending
*global_symbols
; /* global functions and variables */
179 struct pending
*local_symbols
; /* everything local to lexical context */
181 /* List of unclosed lexical contexts
182 (that will become blocks, eventually). */
186 struct context_stack
*next
;
187 struct pending
*locals
;
188 struct pending_block
*old_blocks
;
190 CORE_ADDR start_addr
;
194 struct context_stack
*context_stack
;
196 /* Nonzero if within a function (so symbols should be local,
197 if nothing says specifically). */
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 lineno_complaint
=
221 {"Line number pointer %d lower than start of line numbers", 0, 0};
224 /* Look up a coff type-number index. Return the address of the slot
225 where the type for that index is stored.
226 The type-number is in INDEX.
228 This can be used for finding the type associated with that index
229 or for associating a new type with the index. */
231 static struct type
**
232 coff_lookup_type (index
)
235 if (index
>= type_vector_length
)
237 int old_vector_length
= type_vector_length
;
239 type_vector_length
*= 2;
240 if (type_vector_length
< index
) {
241 type_vector_length
= index
* 2;
243 type_vector
= (struct typevector
*)
244 xrealloc (type_vector
, sizeof (struct typevector
)
245 + type_vector_length
* sizeof (struct type
*));
246 bzero (&type_vector
->type
[ old_vector_length
],
247 (type_vector_length
- old_vector_length
) * sizeof(struct type
*));
249 return &type_vector
->type
[index
];
252 /* Make sure there is a type allocated for type number index
253 and return the type object.
254 This can create an empty (zeroed) type object. */
257 coff_alloc_type (index
)
260 register struct type
**type_addr
= coff_lookup_type (index
);
261 register struct type
*type
= *type_addr
;
263 /* If we are referring to a type not known at all yet,
264 allocate an empty type for it.
265 We will fill it in later if we find out how. */
268 type
= (struct type
*) obstack_alloc (symbol_obstack
,
269 sizeof (struct type
));
270 bzero (type
, sizeof (struct type
));
276 /* maintain the lists of symbols and blocks */
278 /* Add a symbol to one of the lists of symbols. */
280 add_symbol_to_list (symbol
, listhead
)
281 struct symbol
*symbol
;
282 struct pending
**listhead
;
284 register struct pending
*link
285 = (struct pending
*) xmalloc (sizeof (struct pending
));
287 link
->next
= *listhead
;
288 link
->symbol
= symbol
;
292 /* Take one of the lists of symbols and make a block from it.
293 Put the block on the list of pending blocks. */
296 finish_block (symbol
, listhead
, old_blocks
, start
, end
)
297 struct symbol
*symbol
;
298 struct pending
**listhead
;
299 struct pending_block
*old_blocks
;
300 CORE_ADDR start
, end
;
302 register struct pending
*next
, *next1
;
303 register struct block
*block
;
304 register struct pending_block
*pblock
;
305 struct pending_block
*opblock
;
308 /* Count the length of the list of symbols. */
310 for (next
= *listhead
, i
= 0; next
; next
= next
->next
, i
++);
312 block
= (struct block
*)
313 obstack_alloc (symbol_obstack
, sizeof (struct block
) + (i
- 1) * sizeof (struct symbol
*));
315 /* Copy the symbols into the block. */
317 BLOCK_NSYMS (block
) = i
;
318 for (next
= *listhead
; next
; next
= next
->next
)
319 BLOCK_SYM (block
, --i
) = next
->symbol
;
321 BLOCK_START (block
) = start
;
322 BLOCK_END (block
) = end
;
323 BLOCK_SUPERBLOCK (block
) = 0; /* Filled in when containing block is made */
325 /* Put the block in as the value of the symbol that names it. */
329 SYMBOL_BLOCK_VALUE (symbol
) = block
;
330 BLOCK_FUNCTION (block
) = symbol
;
333 BLOCK_FUNCTION (block
) = 0;
335 /* Now free the links of the list, and empty the list. */
337 for (next
= *listhead
; next
; next
= next1
)
344 /* Install this block as the superblock
345 of all blocks made since the start of this scope
346 that don't have superblocks yet. */
349 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
351 if (BLOCK_SUPERBLOCK (pblock
->block
) == 0)
352 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
356 /* Record this block on the list of all blocks in the file.
357 Put it after opblock, or at the beginning if opblock is 0.
358 This puts the block in the list after all its subblocks. */
360 pblock
= (struct pending_block
*) xmalloc (sizeof (struct pending_block
));
361 pblock
->block
= block
;
364 pblock
->next
= opblock
->next
;
365 opblock
->next
= pblock
;
369 pblock
->next
= pending_blocks
;
370 pending_blocks
= pblock
;
374 static struct blockvector
*
377 register struct pending_block
*next
, *next1
;
378 register struct blockvector
*blockvector
;
381 /* Count the length of the list of blocks. */
383 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
385 blockvector
= (struct blockvector
*)
386 obstack_alloc (symbol_obstack
, sizeof (struct blockvector
) + (i
- 1) * sizeof (struct block
*));
388 /* Copy the blocks into the blockvector.
389 This is done in reverse order, which happens to put
390 the blocks into the proper order (ascending starting address).
391 finish_block has hair to insert each block into the list
392 after its subblocks in order to make sure this is true. */
394 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
395 for (next
= pending_blocks
; next
; next
= next
->next
)
396 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
398 /* Now free the links of the list, and empty the list. */
400 for (next
= pending_blocks
; next
; next
= next1
)
410 /* Manage the vector of line numbers. */
413 record_line (line
, pc
)
417 struct linetable_entry
*e
;
418 /* Make sure line vector is big enough. */
420 if (line_vector_index
+ 2 >= line_vector_length
)
422 line_vector_length
*= 2;
423 line_vector
= (struct linetable
*)
424 xrealloc (line_vector
, sizeof (struct linetable
)
425 + (line_vector_length
426 * sizeof (struct linetable_entry
)));
429 e
= line_vector
->item
+ line_vector_index
++;
430 e
->line
= line
; e
->pc
= pc
;
433 /* Start a new symtab for a new source file.
434 This is called when a COFF ".file" symbol is seen;
435 it indicates the start of data for one original source file. */
444 last_source_file
= 0;
448 /* This isn't used currently. */
453 /* Initialize the source file information for this file. */
455 line_vector_index
= 0;
456 line_vector_length
= 1000;
457 prev_line_number
= -2; /* Force first line number to be explicit */
458 line_vector
= (struct linetable
*)
459 xmalloc (sizeof (struct linetable
)
460 + line_vector_length
* sizeof (struct linetable_entry
));
463 /* Save the vital information from when starting to read a file,
464 for use when closing off the current file.
465 NAME is the file name the symbols came from, START_ADDR is the first
466 text address for the file, and SIZE is the number of bytes of text. */
469 complete_symtab (name
, start_addr
, size
)
471 CORE_ADDR start_addr
;
474 last_source_file
= savestring (name
, strlen (name
));
475 cur_src_start_addr
= start_addr
;
476 cur_src_end_addr
= start_addr
+ size
;
478 if (entry_point
< cur_src_end_addr
479 && entry_point
>= cur_src_start_addr
)
481 startup_file_start
= cur_src_start_addr
;
482 startup_file_end
= cur_src_end_addr
;
486 /* Finish the symbol definitions for one main source file,
487 close off all the lexical contexts for that file
488 (creating struct block's for them), then make the
489 struct symtab for that file and put it in the list of all such. */
494 register struct symtab
*symtab
;
495 register struct context_stack
*cstk
;
496 register struct blockvector
*blockvector
;
497 register struct linetable
*lv
;
499 /* Finish the lexical context of the last function in the file. */
503 cstk
= context_stack
;
505 /* Make a block for the local symbols within. */
506 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
507 cstk
->start_addr
, cur_src_end_addr
);
511 /* Ignore a file that has no functions with real debugging info. */
512 if (pending_blocks
== 0 && file_symbols
== 0 && global_symbols
== 0)
516 line_vector_length
= -1;
517 last_source_file
= 0;
521 /* Create the two top-level blocks for this file (STATIC_BLOCK and
523 finish_block (0, &file_symbols
, 0, cur_src_start_addr
, cur_src_end_addr
);
524 finish_block (0, &global_symbols
, 0, cur_src_start_addr
, cur_src_end_addr
);
526 /* Create the blockvector that points to all the file's blocks. */
527 blockvector
= make_blockvector ();
529 /* Now create the symtab object for this source file. */
530 symtab
= (struct symtab
*) xmalloc (sizeof (struct symtab
));
531 symtab
->free_ptr
= 0;
533 /* Fill in its components. */
534 symtab
->blockvector
= blockvector
;
535 symtab
->free_code
= free_linetable
;
536 symtab
->filename
= last_source_file
;
537 symtab
->dirname
= NULL
;
539 lv
->nitems
= line_vector_index
;
540 symtab
->linetable
= (struct linetable
*)
541 xrealloc (lv
, (sizeof (struct linetable
)
542 + lv
->nitems
* sizeof (struct linetable_entry
)));
544 symtab
->line_charpos
= 0;
546 symtab
->language
= language_unknown
;
547 symtab
->fullname
= NULL
;
550 symtab
->coffsem
= last_coffsem
;
552 /* This isn't used currently. Besides, if this is really about "syntax",
553 it shouldn't need to stick around past symbol read-in time. */
554 symtab
->coffsyn
= last_coffsyn
;
558 free_named_symtabs (symtab
->filename
);
560 /* Link the new symtab into the list of such. */
561 symtab
->next
= symtab_list
;
562 symtab_list
= symtab
;
564 /* Reinitialize for beginning of new file. */
566 line_vector_length
= -1;
567 last_source_file
= 0;
571 record_misc_function (name
, address
)
576 /* We don't want TDESC entry points on the misc_function_vector */
577 if (name
[0] == '@') return;
579 /* mf_text isn't true, but apparently COFF doesn't tell us what it really
580 is, so this guess is more useful than mf_unknown. */
581 prim_record_misc_function (savestring (name
, strlen (name
)),
586 /* coff_symfile_init ()
587 is the coff-specific initialization routine for reading symbols.
588 It is passed a struct sym_fns which contains, among other things,
589 the BFD for the file whose symbols are being read, and a slot for
590 a pointer to "private data" which we fill with cookies and other
591 treats for coff_symfile_read ().
593 We will only be called if this is a COFF or COFF-like file.
594 BFD handles figuring out the format of the file, and code in symtab.c
595 uses BFD's determination to vector to us.
597 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
599 struct coff_symfile_info
{
600 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
601 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
605 coff_symfile_init (sf
)
608 bfd
*abfd
= sf
->sym_bfd
;
610 /* Allocate struct to keep track of the symfile */
611 /* FIXME memory leak */
612 sf
->sym_private
= xmalloc (sizeof (struct coff_symfile_info
));
615 safe_to_init_tdesc_context
= 0;
618 /* Save startup file's range of PC addresses to help blockframe.c
619 decide where the bottom of the stack is. */
620 if (bfd_get_file_flags (abfd
) & EXEC_P
)
622 /* Executable file -- record its entry point so we'll recognize
623 the startup file because it contains the entry point. */
624 entry_point
= bfd_get_start_address (abfd
);
628 /* Examination of non-executable.o files. Short-circuit this stuff. */
629 /* ~0 will not be in any file, we hope. */
631 /* set the startup file to be an empty range. */
632 startup_file_start
= 0;
633 startup_file_end
= 0;
637 /* This function is called for every section; it finds the outer limits
638 of the line table (minimum and maximum file offset) so that the
639 mainline code can read the whole thing for efficiency. */
643 find_linenos (abfd
, asect
, vpinfo
)
648 struct coff_symfile_info
*info
;
650 file_ptr offset
, maxoff
;
652 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
653 count
= asect
->lineno_count
;
658 #if !defined (LINESZ)
659 /* Just in case, you never know what to expect from those
660 COFF header files. */
661 #define LINESZ (sizeof (struct lineno))
662 #endif /* No LINESZ. */
663 size
= count
* LINESZ
;
665 info
= (struct coff_symfile_info
*)vpinfo
;
666 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
667 offset
= asect
->line_filepos
;
670 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
671 info
->min_lineno_offset
= offset
;
673 maxoff
= offset
+ size
;
674 if (maxoff
> info
->max_lineno_offset
)
675 info
->max_lineno_offset
= maxoff
;
677 /* While we're at it, find the debug_info. It's in the s_relptr
678 (or, in BFD-speak, rel_filepos) of the text segment section header. */
679 if (strcmp (bfd_section_name (abfd
, asect
), ".text") == 0)
681 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
682 debug_info
= asect
->rel_filepos
;
686 dc_terminate (tdesc_handle
);
694 /* The BFD for this file -- only good while we're actively reading
695 symbols into a psymtab or a symtab. */
697 static bfd
*symfile_bfd
;
699 /* Read a symbol file, after initialization by coff_symfile_init. */
700 /* FIXME! Addr and Mainline are not used yet -- this will not work for
701 shared libraries or add_file! */
704 coff_symfile_read (sf
, addr
, mainline
)
709 struct coff_symfile_info
*info
= (struct coff_symfile_info
*)sf
->sym_private
;
710 bfd
*abfd
= sf
->sym_bfd
;
711 char *name
= bfd_get_filename (abfd
);
716 int stringtab_offset
;
718 symfile_bfd
= abfd
; /* Kludge for swap routines */
720 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
721 desc
= fileno ((FILE *)(abfd
->iostream
)); /* File descriptor */
722 num_symbols
= bfd_get_symcount (abfd
); /* How many syms */
723 symtab_offset
= obj_sym_filepos (abfd
); /* Symbol table file offset */
724 stringtab_offset
= symtab_offset
+ num_symbols
* SYMESZ
; /* String tab */
727 /* Read the line number table, all at once. */
728 info
->min_lineno_offset
= 0;
729 info
->max_lineno_offset
= 0;
730 bfd_map_over_sections (abfd
, find_linenos
, info
);
732 val
= init_lineno (desc
, info
->min_lineno_offset
,
733 info
->max_lineno_offset
- info
->min_lineno_offset
);
735 error ("\"%s\": error reading line numbers\n", name
);
737 /* Now read the string table, all at once. */
739 val
= init_stringtab (desc
, stringtab_offset
);
742 free_all_symtabs (); /* FIXME blows whole symtab */
743 printf ("\"%s\": can't get string table", name
);
747 make_cleanup (free_stringtab
, 0);
749 /* Position to read the symbol table. Do not read it all at once. */
750 val
= lseek (desc
, (long)symtab_offset
, 0);
752 perror_with_name (name
);
754 init_misc_bunches ();
755 make_cleanup (discard_misc_bunches
, 0);
757 /* Now that the executable file is positioned at symbol table,
758 process it and define symbols accordingly. */
760 read_coff_symtab (desc
, num_symbols
);
762 patch_opaque_types ();
764 /* Sort symbols alphabetically within each block. */
766 sort_all_symtab_syms ();
768 /* Go over the misc symbol bunches and install them in vector. */
770 condense_misc_bunches (0);
772 /* Make a default for file to list. */
774 select_source_symtab (0); /* FIXME, this might be too slow, see dbxread */
778 coff_symfile_discard ()
780 /* There seems to be nothing to do here. */
786 /* There seems to be nothing to do except free_all_symtabs and set
787 symfile to zero, which is done by our caller. */
790 /* Simplified internal version of coff symbol table information */
794 int c_symnum
; /* symbol number of this entry */
795 int c_nsyms
; /* 1 if syment only, 2 if syment + auxent, etc */
802 /* Given pointers to a symbol table in coff style exec file,
803 analyze them and create struct symtab's describing the symbols.
804 NSYMS is the number of symbols in the symbol table.
805 We read them one at a time using read_one_sym (). */
808 read_coff_symtab (desc
, nsyms
)
812 int newfd
; /* Avoid multiple closes on same desc */
814 register struct context_stack
*new;
815 struct coff_symbol coff_symbol
;
816 register struct coff_symbol
*cs
= &coff_symbol
;
817 static struct internal_syment main_sym
;
818 static union internal_auxent main_aux
;
819 struct coff_symbol fcn_cs_saved
;
820 static struct internal_syment fcn_sym_saved
;
821 static union internal_auxent fcn_aux_saved
;
823 /* A .file is open. */
824 int in_source_file
= 0;
825 int num_object_files
= 0;
826 int next_file_symnum
= -1;
828 /* Name of the current file. */
829 char *filestring
= "";
835 struct cleanup
*old_chain
;
840 fatal ("Too many open files");
841 stream
= fdopen (newfd
, "r");
843 old_chain
= make_cleanup (free_all_symtabs
, 0);
844 make_cleanup (fclose
, stream
);
845 nlist_stream_global
= stream
;
846 nlist_nsyms_global
= nsyms
;
847 last_source_file
= 0;
848 bzero (opaque_type_chain
, sizeof opaque_type_chain
);
850 type_vector_length
= 160;
851 type_vector
= (struct typevector
*)
852 xmalloc (sizeof (struct typevector
)
853 + type_vector_length
* sizeof (struct type
*));
854 bzero (type_vector
->type
, type_vector_length
* sizeof (struct type
*));
859 while (symnum
< nsyms
)
861 QUIT
; /* Make this command interruptable. */
862 read_one_sym (cs
, &main_sym
, &main_aux
);
865 temp_sem_val
= cs
->c_name
[0] << 24 | cs
->c_name
[1] << 16 |
866 cs
->c_name
[2] << 8 | cs
->c_name
[3];
867 if (int_sem_val
== temp_sem_val
)
868 last_coffsem
= (int) strtol (cs
->c_name
+4, (char **) NULL
, 10);
871 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
873 if (last_source_file
)
877 complete_symtab ("_globals_", 0, first_object_file_end
);
878 /* done with all files, everything from here on out is globals */
881 /* Special case for file with type declarations only, no text. */
882 if (!last_source_file
&& SDB_TYPE (cs
->c_type
)
883 && cs
->c_secnum
== N_DEBUG
)
884 complete_symtab (filestring
, 0, 0);
886 /* Typedefs should not be treated as symbol definitions. */
887 if (ISFCN (cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
889 /* record as misc function. if we get '.bf' next,
890 * then we undo this step
892 record_misc_function (cs
->c_name
, cs
->c_value
);
894 fcn_line_ptr
= main_aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
895 fcn_start_addr
= cs
->c_value
;
897 fcn_sym_saved
= main_sym
;
898 fcn_aux_saved
= main_aux
;
902 switch (cs
->c_sclass
)
911 printf ("Bad n_sclass = %d\n", cs
->c_sclass
);
916 * c_value field contains symnum of next .file entry in table
917 * or symnum of first global after last .file.
919 next_file_symnum
= cs
->c_value
;
920 filestring
= getfilename (&main_aux
);
922 * Complete symbol table for last object file
923 * containing debugging information.
925 if (last_source_file
)
934 if (cs
->c_name
[0] == '.') {
935 if (strcmp (cs
->c_name
, _TEXT
) == 0) {
936 if (++num_object_files
== 1) {
937 /* last address of startup file */
938 first_object_file_end
= cs
->c_value
+
939 main_aux
.x_scn
.x_scnlen
;
941 /* Check for in_source_file deals with case of
942 a file with debugging symbols
943 followed by a later file with no symbols. */
945 complete_symtab (filestring
, cs
->c_value
,
946 main_aux
.x_scn
.x_scnlen
);
949 /* flush rest of '.' symbols */
952 else if (!SDB_TYPE (cs
->c_type
)
953 && cs
->c_name
[0] == 'L'
954 && (strncmp (cs
->c_name
, "LI%", 3) == 0
955 || strncmp (cs
->c_name
, "LF%", 3) == 0
956 || strncmp (cs
->c_name
,"LC%",3) == 0
957 || strncmp (cs
->c_name
,"LP%",3) == 0
958 || strncmp (cs
->c_name
,"LPB%",4) == 0
959 || strncmp (cs
->c_name
,"LBB%",4) == 0
960 || strncmp (cs
->c_name
,"LBE%",4) == 0
961 || strncmp (cs
->c_name
,"LPBX%",5) == 0))
962 /* At least on a 3b1, gcc generates swbeg and string labels
963 that look like this. Ignore them. */
965 /* fall in for static symbols that don't start with '.' */
967 if (cs
->c_sclass
== C_EXT
&&
968 cs
->c_secnum
== N_ABS
&&
969 strcmp (cs
->c_name
, _ETEXT
) == 0)
970 end_of_text_addr
= cs
->c_value
;
971 if (!SDB_TYPE (cs
->c_type
)) {
972 if (cs
->c_secnum
<= 1) { /* text or abs */
973 record_misc_function (cs
->c_name
, cs
->c_value
);
979 (void) process_coff_symbol (cs
, &main_aux
);
983 if (strcmp (cs
->c_name
, ".bf") == 0)
987 /* value contains address of first non-init type code */
988 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
989 contains line number of '{' } */
990 fcn_first_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
992 new = (struct context_stack
*)
993 xmalloc (sizeof (struct context_stack
));
994 new->depth
= depth
= 0;
998 new->old_blocks
= pending_blocks
;
999 new->start_addr
= fcn_start_addr
;
1000 fcn_cs_saved
.c_name
= getsymname (&fcn_sym_saved
);
1001 new->name
= process_coff_symbol (&fcn_cs_saved
,
1004 else if (strcmp (cs
->c_name
, ".ef") == 0)
1006 /* the value of .ef is the address of epilogue code;
1007 * not useful for gdb
1009 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1010 contains number of lines to '}' */
1011 new = context_stack
;
1014 complain (&ef_complaint
, cs
->c_symnum
);
1015 within_function
= 0;
1018 fcn_last_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
1019 enter_linenos (fcn_line_ptr
, fcn_first_line
, fcn_last_line
);
1021 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1023 #if defined (FUNCTION_EPILOGUE_SIZE)
1024 /* This macro should be defined only on
1026 fcn_aux_saved.x_sym.x_misc.x_fsize
1027 field is always zero.
1028 So use the .bf record information that
1029 points to the epilogue and add the size
1031 cs
->c_value
+ FUNCTION_EPILOGUE_SIZE
1033 fcn_cs_saved
.c_value
+
1034 fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1038 within_function
= 0;
1044 if (strcmp (cs
->c_name
, ".bb") == 0)
1046 new = (struct context_stack
*)
1047 xmalloc (sizeof (struct context_stack
));
1050 new->next
= context_stack
;
1051 context_stack
= new;
1052 new->locals
= local_symbols
;
1053 new->old_blocks
= pending_blocks
;
1054 new->start_addr
= cs
->c_value
;
1058 else if (strcmp (cs
->c_name
, ".eb") == 0)
1060 new = context_stack
;
1061 if (new == 0 || depth
!= new->depth
)
1062 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1064 if (local_symbols
&& context_stack
->next
)
1066 /* Make a block for the local symbols within. */
1067 finish_block (0, &local_symbols
, new->old_blocks
,
1068 new->start_addr
, cs
->c_value
);
1071 local_symbols
= new->locals
;
1072 context_stack
= new->next
;
1079 /* This isn't used currently. */
1080 if (strcmp (cs
->c_name
, ".coffsyn") == 0)
1081 last_coffsyn
= cs
->c_value
;
1084 if ((strcmp (cs
->c_name
, ".coffsem") == 0) &&
1086 last_coffsem
= cs
->c_value
;
1092 if ((strcmp (cs
->c_name
, ".coffsem") == 0) &&
1094 last_coffsem
= cs
->c_value
;
1097 (void) process_coff_symbol (cs
, &main_aux
);
1102 if (last_source_file
)
1105 discard_cleanups (old_chain
);
1108 /* Routines for reading headers and symbols from executable. */
1111 /* Move these XXXMAGIC symbol defns into BFD! */
1113 /* Read COFF file header, check magic number,
1114 and return number of symbols. */
1115 read_file_hdr (chan
, file_hdr
)
1119 lseek (chan
, 0L, 0);
1120 if (myread (chan
, (char *)file_hdr
, FILHSZ
) < 0)
1123 switch (file_hdr
->f_magic
)
1138 #if defined (MC68KWRMAGIC) \
1139 && (!defined (MC68MAGIC) || MC68KWRMAGIC != MC68MAGIC)
1153 case I960ROMAGIC
: /* Intel 960 */
1156 case I960RWMAGIC
: /* Intel 960 */
1158 return file_hdr
->f_nsyms
;
1162 if (BADMAG(file_hdr
))
1165 return file_hdr
->f_nsyms
;
1173 /* Read the next symbol, swap it, and return it in both internal_syment
1174 form, and coff_symbol form. Also return its first auxent, if any,
1175 in internal_auxent form, and skip any other auxents. */
1178 read_one_sym (cs
, sym
, aux
)
1179 register struct coff_symbol
*cs
;
1180 register struct internal_syment
*sym
;
1181 register union internal_auxent
*aux
;
1183 struct external_syment temp_sym
[1];
1184 union external_auxent temp_aux
[1];
1187 cs
->c_symnum
= symnum
;
1188 fread ((char *)temp_sym
, SYMESZ
, 1, nlist_stream_global
);
1189 bfd_coff_swap_sym_in (symfile_bfd
, temp_sym
, sym
);
1190 cs
->c_nsyms
= (sym
->n_numaux
& 0xff) + 1;
1191 if (cs
->c_nsyms
>= 2)
1193 fread ((char *)temp_aux
, AUXESZ
, 1, nlist_stream_global
);
1194 bfd_coff_swap_aux_in (symfile_bfd
, temp_aux
, sym
->n_type
, sym
->n_sclass
, aux
);
1195 /* If more than one aux entry, read past it (only the first aux
1197 for (i
= 2; i
< cs
->c_nsyms
; i
++)
1198 fread ((char *)temp_aux
, AUXESZ
, 1, nlist_stream_global
);
1200 cs
->c_name
= getsymname (sym
);
1201 cs
->c_value
= sym
->n_value
;
1202 cs
->c_sclass
= (sym
->n_sclass
& 0xff);
1203 cs
->c_secnum
= sym
->n_scnum
;
1204 cs
->c_type
= (unsigned) sym
->n_type
;
1205 if (!SDB_TYPE (cs
->c_type
))
1208 symnum
+= cs
->c_nsyms
;
1211 /* Support for string table handling */
1213 static char *stringtab
= NULL
;
1216 init_stringtab (chan
, offset
)
1222 unsigned char lengthbuf
[4];
1230 if (lseek (chan
, offset
, 0) < 0)
1233 val
= myread (chan
, (char *)lengthbuf
, sizeof lengthbuf
);
1234 length
= bfd_h_get_32 (symfile_bfd
, lengthbuf
);
1236 /* If no string table is needed, then the file may end immediately
1237 after the symbols. Just return with `stringtab' set to null. */
1238 if (val
!= sizeof length
|| length
< sizeof length
)
1241 stringtab
= (char *) xmalloc (length
);
1242 if (stringtab
== NULL
)
1245 bcopy (&length
, stringtab
, sizeof length
);
1246 if (length
== sizeof length
) /* Empty table -- just the count */
1249 val
= myread (chan
, stringtab
+ sizeof length
, length
- sizeof length
);
1250 if (val
!= length
- sizeof length
|| stringtab
[length
- 1] != '\0')
1265 getsymname (symbol_entry
)
1266 struct internal_syment
*symbol_entry
;
1268 static char buffer
[SYMNMLEN
+1];
1271 if (symbol_entry
->_n
._n_n
._n_zeroes
== 0)
1273 result
= stringtab
+ symbol_entry
->_n
._n_n
._n_offset
;
1277 strncpy (buffer
, symbol_entry
->_n
._n_name
, SYMNMLEN
);
1278 buffer
[SYMNMLEN
] = '\0';
1285 getfilename (aux_entry
)
1286 union internal_auxent
*aux_entry
;
1288 static char buffer
[BUFSIZ
];
1289 register char *temp
;
1291 extern char *rindex ();
1293 #ifndef COFF_NO_LONG_FILE_NAMES
1294 #if defined (x_zeroes)
1296 if (aux_entry
->x_zeroes
== 0)
1297 strcpy (buffer
, stringtab
+ aux_entry
->x_offset
);
1298 #else /* no x_zeroes */
1299 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1300 strcpy (buffer
, stringtab
+ aux_entry
->x_file
.x_n
.x_offset
);
1301 #endif /* no x_zeroes */
1303 #endif /* COFF_NO_LONG_FILE_NAMES */
1305 #if defined (x_name)
1307 strncpy (buffer
, aux_entry
->x_name
, FILNMLEN
);
1309 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1311 buffer
[FILNMLEN
] = '\0';
1314 if ((temp
= rindex (result
, '/')) != NULL
)
1319 /* Support for line number handling */
1320 static char *linetab
= NULL
;
1321 static long linetab_offset
;
1322 static unsigned long linetab_size
;
1324 /* Read in all the line numbers for fast lookups later. Leave them in
1325 external (unswapped) format in memory; we'll swap them as we enter
1326 them into GDB's data structures. */
1329 init_lineno (chan
, offset
, size
)
1336 if (lseek (chan
, offset
, 0) < 0)
1339 linetab
= (char *) xmalloc (size
);
1341 val
= myread (chan
, linetab
, size
);
1345 linetab_offset
= offset
;
1346 linetab_size
= size
;
1347 make_cleanup (free
, linetab
); /* Be sure it gets de-allocated. */
1351 #if !defined (L_LNNO32)
1352 #define L_LNNO32(lp) ((lp)->l_lnno)
1356 enter_linenos (file_offset
, first_line
, last_line
)
1358 register int first_line
;
1359 register int last_line
;
1361 register char *rawptr
;
1362 struct internal_lineno lptr
;
1364 if (file_offset
< linetab_offset
)
1366 complain (&lineno_complaint
, file_offset
);
1367 if (file_offset
> linetab_size
) /* Too big to be an offset? */
1369 file_offset
+= linetab_offset
; /* Try reading at that linetab offset */
1372 rawptr
= &linetab
[file_offset
- linetab_offset
];
1374 /* skip first line entry for each function */
1376 /* line numbers start at one for the first line of the function */
1380 bfd_coff_swap_lineno_in (symfile_bfd
, (LINENO
*)rawptr
, &lptr
);
1382 if (L_LNNO32 (&lptr
) && L_LNNO32 (&lptr
) <= last_line
)
1383 record_line (first_line
+ L_LNNO32 (&lptr
), lptr
.l_addr
.l_paddr
);
1393 register char *p
= name
;
1394 register int total
= p
[0];
1407 return total
% HASHSIZE
;
1411 patch_type (type
, real_type
)
1413 struct type
*real_type
;
1415 register struct type
*target
= TYPE_TARGET_TYPE (type
);
1416 register struct type
*real_target
= TYPE_TARGET_TYPE (real_type
);
1417 int field_size
= TYPE_NFIELDS (real_target
) * sizeof (struct field
);
1419 TYPE_LENGTH (target
) = TYPE_LENGTH (real_target
);
1420 TYPE_NFIELDS (target
) = TYPE_NFIELDS (real_target
);
1421 TYPE_FIELDS (target
) = (struct field
*)
1422 obstack_alloc (symbol_obstack
, field_size
);
1424 bcopy (TYPE_FIELDS (real_target
), TYPE_FIELDS (target
), field_size
);
1426 if (TYPE_NAME (real_target
))
1428 if (TYPE_NAME (target
))
1429 free (TYPE_NAME (target
));
1430 TYPE_NAME (target
) = concat (TYPE_NAME (real_target
), "", "");
1434 /* Patch up all appropriate typdef symbols in the opaque_type_chains
1435 so that they can be used to print out opaque data structures properly */
1438 patch_opaque_types ()
1442 /* Look at each symbol in the per-file block of each symtab. */
1443 for (s
= symtab_list
; s
; s
= s
->next
)
1445 register struct block
*b
;
1448 /* Go through the per-file symbols only */
1449 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
1450 for (i
= BLOCK_NSYMS (b
) - 1; i
>= 0; i
--)
1452 register struct symbol
*real_sym
;
1454 /* Find completed typedefs to use to fix opaque ones.
1455 Remove syms from the chain when their types are stored,
1456 but search the whole chain, as there may be several syms
1457 from different files with the same name. */
1458 real_sym
= BLOCK_SYM (b
, i
);
1459 if (SYMBOL_CLASS (real_sym
) == LOC_TYPEDEF
&&
1460 SYMBOL_NAMESPACE (real_sym
) == VAR_NAMESPACE
&&
1461 TYPE_CODE (SYMBOL_TYPE (real_sym
)) == TYPE_CODE_PTR
&&
1462 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym
))) != 0)
1464 register char *name
= SYMBOL_NAME (real_sym
);
1465 register int hash
= hashname (name
);
1466 register struct symbol
*sym
, *prev
;
1469 for (sym
= opaque_type_chain
[hash
]; sym
;)
1471 if (name
[0] == SYMBOL_NAME (sym
)[0] &&
1472 !strcmp (name
+ 1, SYMBOL_NAME (sym
) + 1))
1475 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
1477 opaque_type_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
1479 patch_type (SYMBOL_TYPE (sym
), SYMBOL_TYPE (real_sym
));
1482 sym
= SYMBOL_VALUE_CHAIN (prev
);
1484 sym
= opaque_type_chain
[hash
];
1489 sym
= SYMBOL_VALUE_CHAIN (sym
);
1497 #if defined (clipper)
1498 #define BELIEVE_PCC_PROMOTION 1
1501 static struct symbol
*
1502 process_coff_symbol (cs
, aux
)
1503 register struct coff_symbol
*cs
;
1504 register union internal_auxent
*aux
;
1506 register struct symbol
*sym
1507 = (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
1509 #ifdef NAMES_HAVE_UNDERSCORE
1515 bzero (sym
, sizeof (struct symbol
));
1517 name
= (name
[0] == '_' ? name
+ offset
: name
);
1518 SYMBOL_NAME (sym
) = obstack_copy0 (symbol_obstack
, name
, strlen (name
));
1520 /* default assumptions */
1521 SYMBOL_VALUE (sym
) = cs
->c_value
;
1522 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1524 if (ISFCN (cs
->c_type
))
1527 lookup_function_type (decode_function_type (cs
, cs
->c_type
, aux
));
1528 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1529 if (cs
->c_sclass
== C_STAT
)
1530 add_symbol_to_list (sym
, &file_symbols
);
1531 else if (cs
->c_sclass
== C_EXT
)
1532 add_symbol_to_list (sym
, &global_symbols
);
1536 SYMBOL_TYPE (sym
) = decode_type (cs
, cs
->c_type
, aux
);
1537 switch (cs
->c_sclass
)
1543 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1544 add_symbol_to_list (sym
, &local_symbols
);
1548 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1549 SYMBOL_VALUE_ADDRESS (sym
) = (CORE_ADDR
) cs
->c_value
;
1550 add_symbol_to_list (sym
, &global_symbols
);
1554 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1555 SYMBOL_VALUE_ADDRESS (sym
) = (CORE_ADDR
) cs
->c_value
;
1556 if (within_function
) {
1557 /* Static symbol of local scope */
1558 add_symbol_to_list (sym
, &local_symbols
);
1561 /* Static symbol at top level of file */
1562 add_symbol_to_list (sym
, &file_symbols
);
1567 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1568 add_symbol_to_list (sym
, &local_symbols
);
1575 SYMBOL_CLASS (sym
) = LOC_ARG
;
1576 add_symbol_to_list (sym
, &local_symbols
);
1577 #if !defined (BELIEVE_PCC_PROMOTION)
1578 /* If PCC says a parameter is a short or a char,
1579 it is really an int. */
1580 if (SYMBOL_TYPE (sym
) == builtin_type_char
1581 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1582 SYMBOL_TYPE (sym
) = builtin_type_int
;
1583 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1584 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1585 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1590 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1591 add_symbol_to_list (sym
, &local_symbols
);
1592 #if !defined (BELIEVE_PCC_PROMOTION)
1593 /* If PCC says a parameter is a short or a char,
1594 it is really an int. */
1595 if (SYMBOL_TYPE (sym
) == builtin_type_char
1596 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1597 SYMBOL_TYPE (sym
) = builtin_type_int
;
1598 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1599 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1600 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1605 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1606 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1608 /* If type has no name, give it one */
1609 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1610 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1611 TYPE_NAME (SYMBOL_TYPE (sym
))
1612 = concat (SYMBOL_NAME (sym
), "", "");
1614 /* Keep track of any type which points to empty structured type,
1615 so it can be filled from a definition from another file */
1616 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
&&
1617 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym
))) == 0)
1619 register int i
= hashname (SYMBOL_NAME (sym
));
1621 SYMBOL_VALUE_CHAIN (sym
) = opaque_type_chain
[i
];
1622 opaque_type_chain
[i
] = sym
;
1624 add_symbol_to_list (sym
, &file_symbols
);
1630 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1631 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1632 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1633 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1634 TYPE_NAME (SYMBOL_TYPE (sym
))
1636 (cs
->c_sclass
== C_ENTAG
1638 : (cs
->c_sclass
== C_STRTAG
1639 ? "struct " : "union ")),
1641 add_symbol_to_list (sym
, &file_symbols
);
1651 /* Decode a coff type specifier;
1652 return the type that is meant. */
1656 decode_type (cs
, c_type
, aux
)
1657 register struct coff_symbol
*cs
;
1658 unsigned int c_type
;
1659 register union internal_auxent
*aux
;
1661 register struct type
*type
= 0;
1662 unsigned int new_c_type
;
1664 if (c_type
& ~N_BTMASK
)
1666 new_c_type
= DECREF (c_type
);
1669 type
= decode_type (cs
, new_c_type
, aux
);
1670 type
= lookup_pointer_type (type
);
1672 else if (ISFCN (c_type
))
1674 type
= decode_type (cs
, new_c_type
, aux
);
1675 type
= lookup_function_type (type
);
1677 else if (ISARY (c_type
))
1680 register unsigned short *dim
;
1681 struct type
*base_type
;
1683 /* Define an array type. */
1684 /* auxent refers to array, not base type */
1685 if (aux
->x_sym
.x_tagndx
== 0)
1688 /* shift the indices down */
1689 dim
= &aux
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0];
1692 for (i
= 0; *dim
&& i
< DIMNUM
- 1; i
++, dim
++)
1696 type
= (struct type
*)
1697 obstack_alloc (symbol_obstack
, sizeof (struct type
));
1698 bzero (type
, sizeof (struct type
));
1700 base_type
= decode_type (cs
, new_c_type
, aux
);
1702 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
1703 TYPE_TARGET_TYPE (type
) = base_type
;
1704 TYPE_LENGTH (type
) = n
* TYPE_LENGTH (base_type
);
1709 /* Reference to existing type */
1710 if (cs
->c_nsyms
> 1 && aux
->x_sym
.x_tagndx
!= 0)
1712 type
= coff_alloc_type (aux
->x_sym
.x_tagndx
);
1716 return decode_base_type (cs
, BTYPE (c_type
), aux
);
1719 /* Decode a coff type specifier for function definition;
1720 return the type that the function returns. */
1724 decode_function_type (cs
, c_type
, aux
)
1725 register struct coff_symbol
*cs
;
1726 unsigned int c_type
;
1727 register union internal_auxent
*aux
;
1729 if (aux
->x_sym
.x_tagndx
== 0)
1730 cs
->c_nsyms
= 1; /* auxent refers to function, not base type */
1732 return decode_type (cs
, DECREF (c_type
), aux
);
1739 decode_base_type (cs
, c_type
, aux
)
1740 register struct coff_symbol
*cs
;
1741 unsigned int c_type
;
1742 register union internal_auxent
*aux
;
1749 /* shows up with "void (*foo)();" structure members */
1750 return builtin_type_void
;
1753 /* DGUX actually defines both T_ARG and T_VOID to the same value. */
1756 /* Shows up in DGUX, I think. Not sure where. */
1757 return builtin_type_void
; /* shouldn't show up here */
1763 /* Intel 960 COFF has this symbol and meaning. */
1764 return builtin_type_void
;
1768 return builtin_type_char
;
1771 return builtin_type_short
;
1774 return builtin_type_int
;
1777 return builtin_type_long
;
1780 return builtin_type_float
;
1783 return builtin_type_double
;
1786 if (cs
->c_nsyms
!= 2)
1788 /* anonymous structure type */
1789 type
= coff_alloc_type (cs
->c_symnum
);
1790 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1791 TYPE_NAME (type
) = concat ("struct ", "<opaque>", "");
1792 TYPE_LENGTH (type
) = 0;
1793 TYPE_FIELDS (type
) = 0;
1794 TYPE_NFIELDS (type
) = 0;
1798 type
= read_struct_type (cs
->c_symnum
,
1799 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1800 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1805 if (cs
->c_nsyms
!= 2)
1807 /* anonymous union type */
1808 type
= coff_alloc_type (cs
->c_symnum
);
1809 TYPE_NAME (type
) = concat ("union ", "<opaque>", "");
1810 TYPE_LENGTH (type
) = 0;
1811 TYPE_FIELDS (type
) = 0;
1812 TYPE_NFIELDS (type
) = 0;
1816 type
= read_struct_type (cs
->c_symnum
,
1817 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1818 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1820 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1824 return read_enum_type (cs
->c_symnum
,
1825 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1826 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1829 /* shouldn't show up here */
1833 return builtin_type_unsigned_char
;
1836 return builtin_type_unsigned_short
;
1839 return builtin_type_unsigned_int
;
1842 return builtin_type_unsigned_long
;
1844 printf ("unexpected type %d at symnum %d\n", c_type
, cs
->c_symnum
);
1845 return builtin_type_void
;
1848 /* This page contains subroutines of read_type. */
1850 /* Read the description of a structure (or union type)
1851 and return an object describing the type. */
1853 static struct type
*
1854 read_struct_type (index
, length
, lastsym
)
1861 struct nextfield
*next
;
1865 register struct type
*type
;
1866 register struct nextfield
*list
= 0;
1867 struct nextfield
*new;
1871 #ifdef NAMES_HAVE_UNDERSCORE
1876 struct coff_symbol member_sym
;
1877 register struct coff_symbol
*ms
= &member_sym
;
1878 struct internal_syment sub_sym
;
1879 union internal_auxent sub_aux
;
1882 type
= coff_alloc_type (index
);
1883 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1884 TYPE_LENGTH (type
) = length
;
1886 while (!done
&& symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
1888 read_one_sym (ms
, &sub_sym
, &sub_aux
);
1890 name
= (name
[0] == '_' ? name
+ offset
: name
);
1892 switch (ms
->c_sclass
)
1897 /* Get space to record the next field's data. */
1898 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1902 /* Save the data. */
1903 list
->field
.name
= savestring (name
, strlen (name
));
1904 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1905 list
->field
.bitpos
= 8 * ms
->c_value
;
1906 list
->field
.bitsize
= 0;
1912 /* Get space to record the next field's data. */
1913 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1917 /* Save the data. */
1918 list
->field
.name
= savestring (name
, strlen (name
));
1919 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1920 list
->field
.bitpos
= ms
->c_value
;
1921 list
->field
.bitsize
= sub_aux
.x_sym
.x_misc
.x_lnsz
.x_size
;
1930 /* Now create the vector of fields, and record how big it is. */
1932 TYPE_NFIELDS (type
) = nfields
;
1933 TYPE_FIELDS (type
) = (struct field
*)
1934 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nfields
);
1936 /* Copy the saved-up fields into the field vector. */
1938 for (n
= nfields
; list
; list
= list
->next
)
1939 TYPE_FIELD (type
, --n
) = list
->field
;
1944 /* Read a definition of an enumeration type,
1945 and create and return a suitable type object.
1946 Also defines the symbols that represent the values of the type. */
1947 /* Currently assumes it's sizeof (int) and doesn't use length. */
1949 static struct type
*
1950 read_enum_type (index
, length
, lastsym
)
1955 register struct symbol
*sym
;
1956 register struct type
*type
;
1959 struct pending
**symlist
;
1960 struct coff_symbol member_sym
;
1961 register struct coff_symbol
*ms
= &member_sym
;
1962 struct internal_syment sub_sym
;
1963 union internal_auxent sub_aux
;
1964 struct pending
*osyms
, *syms
;
1967 #ifdef NAMES_HAVE_UNDERSCORE
1973 type
= coff_alloc_type (index
);
1974 if (within_function
)
1975 symlist
= &local_symbols
;
1977 symlist
= &file_symbols
;
1980 while (!done
&& symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
1982 read_one_sym (ms
, &sub_sym
, &sub_aux
);
1984 name
= (name
[0] == '_' ? name
+ offset
: name
);
1986 switch (ms
->c_sclass
)
1989 sym
= (struct symbol
*) xmalloc (sizeof (struct symbol
));
1990 bzero (sym
, sizeof (struct symbol
));
1992 SYMBOL_NAME (sym
) = savestring (name
, strlen (name
));
1993 SYMBOL_CLASS (sym
) = LOC_CONST
;
1994 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1995 SYMBOL_VALUE (sym
) = ms
->c_value
;
1996 add_symbol_to_list (sym
, symlist
);
2001 /* Sometimes the linker (on 386/ix 2.0.2 at least) screws
2002 up the count of how many symbols to read. So stop
2009 /* Now fill in the fields of the type-structure. */
2011 /* FIXME: Should be sizeof (int) on target, not host. */
2012 TYPE_LENGTH (type
) = sizeof (int);
2013 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2014 TYPE_NFIELDS (type
) = nsyms
;
2015 TYPE_FIELDS (type
) = (struct field
*)
2016 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nsyms
);
2018 /* Find the symbols for the values and put them into the type.
2019 The symbols can be found in the symlist that we put them on
2020 to cause them to be defined. osyms contains the old value
2021 of that symlist; everything up to there was defined by us. */
2023 for (syms
= *symlist
, n
= nsyms
; syms
!= osyms
; syms
= syms
->next
)
2025 SYMBOL_TYPE (syms
->symbol
) = type
;
2026 TYPE_FIELD_NAME (type
, --n
) = SYMBOL_NAME (syms
->symbol
);
2027 TYPE_FIELD_VALUE (type
, n
) = 0;
2028 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (syms
->symbol
);
2029 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2034 /* Register our ability to parse symbols for coff BFD files */
2036 static struct sym_fns coff_sym_fns
=
2038 /* This assumes that 88kbcs implies TDESC and TDESC implies 88kbcs.
2039 If that's not true, this can be relaxed, but if it is true,
2040 it will just cause users grief if we try to read the wrong kind
2044 #else /* not TDESC */
2046 #endif /* not TDESC */
2047 coff_new_init
, coff_symfile_init
,
2048 coff_symfile_read
, coff_symfile_discard
2052 _initialize_coffread ()
2054 add_symtab_fns(&coff_sym_fns
);