1 /* Read coff symbol tables and convert to internal format, for GDB.
2 Design and support routines derived from dbxread.c, and UMAX COFF
3 specific routines written 9/1/87 by David D. Johnson, Brown University.
4 Revised 11/27/87 ddj@cs.brown.edu
5 Copyright (C) 1987-1991 Free Software Foundation, Inc.
7 This file is part of GDB.
9 GDB is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 1, or (at your option)
14 GDB is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GDB; see the file COPYING. If not, write to
21 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
28 #include "breakpoint.h"
35 /* Need to get C_VERSION and friends. */
38 #include <intel-coff.h>
39 #endif /* not TDESC */
44 #include "libcoff.h" /* FIXME secret internal data from BFD */
46 static void add_symbol_to_list ();
47 static void read_coff_symtab ();
48 static void patch_opaque_types ();
49 static struct type
*decode_function_type ();
50 static struct type
*decode_type ();
51 static struct type
*decode_base_type ();
52 static struct type
*read_enum_type ();
53 static struct type
*read_struct_type ();
54 static void finish_block ();
55 static struct blockvector
*make_blockvector ();
56 static struct symbol
*process_coff_symbol ();
57 static int init_stringtab ();
58 static void free_stringtab ();
59 static char *getfilename ();
60 static char *getsymname ();
61 static int init_lineno ();
62 static void enter_linenos ();
63 static void read_one_sym ();
66 extern void free_all_symtabs ();
67 extern void free_all_psymtabs ();
69 /* To be an sdb debug type, type must have at least a basic or primary
70 derived type. Using this rather than checking against T_NULL is
71 said to prevent core dumps if we try to operate on Michael Bloom
74 #define SDB_TYPE(type) (BTYPE(type) | (type & N_TMASK))
76 /* external routines from the BFD library -- undocumented interface used
77 by GDB to read symbols. Move to libcoff.h. FIXME-SOMEDAY! */
78 extern void bfd_coff_swap_sym (/* symfile_bfd, &sym */);
79 extern void bfd_coff_swap_aux (/* symfile_bfd, &aux, type, sclass */);
80 extern void bfd_coff_swap_lineno (/* symfile_bfd, &lineno */);
83 /* Name of source file whose symbol data we are now processing.
84 This comes from a symbol named ".file". */
86 static char *last_source_file
;
88 /* Core address of start and end of text of current source file.
89 This comes from a ".text" symbol where x_nlinno > 0. */
91 static CORE_ADDR cur_src_start_addr
;
92 static CORE_ADDR cur_src_end_addr
;
94 /* Core address of the end of the first object file. */
95 static CORE_ADDR first_object_file_end
;
97 /* End of the text segment of the executable file,
98 as found in the symbol _etext. */
100 static CORE_ADDR end_of_text_addr
;
102 /* The addresses of the symbol table stream and number of symbols
103 of the object file we are reading (as copied into core). */
105 static FILE *nlist_stream_global
;
106 static int nlist_nsyms_global
;
108 /* The entry point (starting address) of the file, if it is an executable. */
110 static CORE_ADDR entry_point
;
112 /* The index in the symbol table of the last coff symbol that was processed. */
116 /* Vector of types defined so far, indexed by their coff symnum. */
118 static struct typevector
*type_vector
;
120 /* Number of elements allocated for type_vector currently. */
122 static int type_vector_length
;
124 /* Vector of line number information. */
126 static struct linetable
*line_vector
;
128 /* Index of next entry to go in line_vector_index. */
130 static int line_vector_index
;
132 /* Last line number recorded in the line vector. */
134 static int prev_line_number
;
136 /* Number of elements allocated for line_vector currently. */
138 static int line_vector_length
;
143 int int_sem_val
= 's' << 24 | 'e' << 16 | 'm' << 8 | '.';
145 int last_coffsem
= 2;
147 /* This isn't used currently. */
148 int last_coffsyn
= 0;
150 int debug_info
= 0; /*used by tdesc */
151 extern dc_dcontext_t tdesc_handle
;
152 extern int safe_to_init_tdesc_context
;
155 /* Chain of typedefs of pointers to empty struct/union types.
156 They are chained thru the SYMBOL_VALUE_CHAIN. */
159 static struct symbol
*opaque_type_chain
[HASHSIZE
];
161 /* Record the symbols defined for each context in a list.
162 We don't create a struct block for the context until we
163 know how long to make it. */
167 struct pending
*next
;
168 struct symbol
*symbol
;
171 /* Here are the three lists that symbols are put on. */
173 struct pending
*file_symbols
; /* static at top level, and types */
175 struct pending
*global_symbols
; /* global functions and variables */
177 struct pending
*local_symbols
; /* everything local to lexical context */
179 /* List of unclosed lexical contexts
180 (that will become blocks, eventually). */
184 struct context_stack
*next
;
185 struct pending
*locals
;
186 struct pending_block
*old_blocks
;
188 CORE_ADDR start_addr
;
192 struct context_stack
*context_stack
;
194 /* Nonzero if within a function (so symbols should be local,
195 if nothing says specifically). */
199 /* List of blocks already made (lexical contexts already closed).
200 This is used at the end to make the blockvector. */
204 struct pending_block
*next
;
208 struct pending_block
*pending_blocks
;
210 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
211 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
213 /* Complaints about various problems in the file being read */
215 struct complaint ef_complaint
=
216 {"Unmatched .ef symbol(s) ignored starting at symnum %d", 0, 0};
218 struct complaint lineno_complaint
=
219 {"Line number pointer %d lower than start of line numbers", 0, 0};
222 /* Look up a coff type-number index. Return the address of the slot
223 where the type for that index is stored.
224 The type-number is in INDEX.
226 This can be used for finding the type associated with that index
227 or for associating a new type with the index. */
229 static struct type
**
230 coff_lookup_type (index
)
233 if (index
>= type_vector_length
)
235 int old_vector_length
= type_vector_length
;
237 type_vector_length
*= 2;
238 if (type_vector_length
< index
) {
239 type_vector_length
= index
* 2;
241 type_vector
= (struct typevector
*)
242 xrealloc (type_vector
, sizeof (struct typevector
)
243 + type_vector_length
* sizeof (struct type
*));
244 bzero (&type_vector
->type
[ old_vector_length
],
245 (type_vector_length
- old_vector_length
) * sizeof(struct type
*));
247 return &type_vector
->type
[index
];
250 /* Make sure there is a type allocated for type number index
251 and return the type object.
252 This can create an empty (zeroed) type object. */
255 coff_alloc_type (index
)
258 register struct type
**type_addr
= coff_lookup_type (index
);
259 register struct type
*type
= *type_addr
;
261 /* If we are referring to a type not known at all yet,
262 allocate an empty type for it.
263 We will fill it in later if we find out how. */
266 type
= (struct type
*) obstack_alloc (symbol_obstack
,
267 sizeof (struct type
));
268 bzero (type
, sizeof (struct type
));
274 /* maintain the lists of symbols and blocks */
276 /* Add a symbol to one of the lists of symbols. */
278 add_symbol_to_list (symbol
, listhead
)
279 struct symbol
*symbol
;
280 struct pending
**listhead
;
282 register struct pending
*link
283 = (struct pending
*) xmalloc (sizeof (struct pending
));
285 link
->next
= *listhead
;
286 link
->symbol
= symbol
;
290 /* Take one of the lists of symbols and make a block from it.
291 Put the block on the list of pending blocks. */
294 finish_block (symbol
, listhead
, old_blocks
, start
, end
)
295 struct symbol
*symbol
;
296 struct pending
**listhead
;
297 struct pending_block
*old_blocks
;
298 CORE_ADDR start
, end
;
300 register struct pending
*next
, *next1
;
301 register struct block
*block
;
302 register struct pending_block
*pblock
;
303 struct pending_block
*opblock
;
306 /* Count the length of the list of symbols. */
308 for (next
= *listhead
, i
= 0; next
; next
= next
->next
, i
++);
310 block
= (struct block
*)
311 obstack_alloc (symbol_obstack
, sizeof (struct block
) + (i
- 1) * sizeof (struct symbol
*));
313 /* Copy the symbols into the block. */
315 BLOCK_NSYMS (block
) = i
;
316 for (next
= *listhead
; next
; next
= next
->next
)
317 BLOCK_SYM (block
, --i
) = next
->symbol
;
319 BLOCK_START (block
) = start
;
320 BLOCK_END (block
) = end
;
321 BLOCK_SUPERBLOCK (block
) = 0; /* Filled in when containing block is made */
323 /* Put the block in as the value of the symbol that names it. */
327 SYMBOL_BLOCK_VALUE (symbol
) = block
;
328 BLOCK_FUNCTION (block
) = symbol
;
331 BLOCK_FUNCTION (block
) = 0;
333 /* Now free the links of the list, and empty the list. */
335 for (next
= *listhead
; next
; next
= next1
)
342 /* Install this block as the superblock
343 of all blocks made since the start of this scope
344 that don't have superblocks yet. */
347 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
349 if (BLOCK_SUPERBLOCK (pblock
->block
) == 0)
350 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
354 /* Record this block on the list of all blocks in the file.
355 Put it after opblock, or at the beginning if opblock is 0.
356 This puts the block in the list after all its subblocks. */
358 pblock
= (struct pending_block
*) xmalloc (sizeof (struct pending_block
));
359 pblock
->block
= block
;
362 pblock
->next
= opblock
->next
;
363 opblock
->next
= pblock
;
367 pblock
->next
= pending_blocks
;
368 pending_blocks
= pblock
;
372 static struct blockvector
*
375 register struct pending_block
*next
, *next1
;
376 register struct blockvector
*blockvector
;
379 /* Count the length of the list of blocks. */
381 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
383 blockvector
= (struct blockvector
*)
384 obstack_alloc (symbol_obstack
, sizeof (struct blockvector
) + (i
- 1) * sizeof (struct block
*));
386 /* Copy the blocks into the blockvector.
387 This is done in reverse order, which happens to put
388 the blocks into the proper order (ascending starting address).
389 finish_block has hair to insert each block into the list
390 after its subblocks in order to make sure this is true. */
392 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
393 for (next
= pending_blocks
; next
; next
= next
->next
)
394 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
396 /* Now free the links of the list, and empty the list. */
398 for (next
= pending_blocks
; next
; next
= next1
)
408 /* Manage the vector of line numbers. */
411 record_line (line
, pc
)
415 struct linetable_entry
*e
;
416 /* Make sure line vector is big enough. */
418 if (line_vector_index
+ 2 >= line_vector_length
)
420 line_vector_length
*= 2;
421 line_vector
= (struct linetable
*)
422 xrealloc (line_vector
, sizeof (struct linetable
)
423 + (line_vector_length
424 * sizeof (struct linetable_entry
)));
427 e
= line_vector
->item
+ line_vector_index
++;
428 e
->line
= line
; e
->pc
= pc
;
431 /* Start a new symtab for a new source file.
432 This is called when a COFF ".file" symbol is seen;
433 it indicates the start of data for one original source file. */
442 last_source_file
= 0;
446 /* This isn't used currently. */
451 /* Initialize the source file information for this file. */
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. */
492 register struct symtab
*symtab
;
493 register struct context_stack
*cstk
;
494 register struct blockvector
*blockvector
;
495 register struct linetable
*lv
;
497 /* Finish the lexical context of the last function in the file. */
501 cstk
= context_stack
;
503 /* Make a block for the local symbols within. */
504 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
505 cstk
->start_addr
, cur_src_end_addr
);
509 /* Ignore a file that has no functions with real debugging info. */
510 if (pending_blocks
== 0 && file_symbols
== 0 && global_symbols
== 0)
514 line_vector_length
= -1;
515 last_source_file
= 0;
519 /* Create the two top-level blocks for this file (STATIC_BLOCK and
521 finish_block (0, &file_symbols
, 0, cur_src_start_addr
, cur_src_end_addr
);
522 finish_block (0, &global_symbols
, 0, cur_src_start_addr
, cur_src_end_addr
);
524 /* Create the blockvector that points to all the file's blocks. */
525 blockvector
= make_blockvector ();
527 /* Now create the symtab object for this source file. */
528 symtab
= (struct symtab
*) xmalloc (sizeof (struct symtab
));
529 symtab
->free_ptr
= 0;
531 /* Fill in its components. */
532 symtab
->blockvector
= blockvector
;
533 symtab
->free_code
= free_linetable
;
534 symtab
->filename
= last_source_file
;
535 symtab
->dirname
= NULL
;
537 lv
->nitems
= line_vector_index
;
538 symtab
->linetable
= (struct linetable
*)
539 xrealloc (lv
, (sizeof (struct linetable
)
540 + lv
->nitems
* sizeof (struct linetable_entry
)));
542 symtab
->line_charpos
= 0;
544 symtab
->language
= language_unknown
;
545 symtab
->fullname
= NULL
;
548 symtab
->coffsem
= last_coffsem
;
550 /* This isn't used currently. Besides, if this is really about "syntax",
551 it shouldn't need to stick around past symbol read-in time. */
552 symtab
->coffsyn
= last_coffsyn
;
556 free_named_symtabs (symtab
->filename
);
558 /* Link the new symtab into the list of such. */
559 symtab
->next
= symtab_list
;
560 symtab_list
= symtab
;
562 /* Reinitialize for beginning of new file. */
564 line_vector_length
= -1;
565 last_source_file
= 0;
569 record_misc_function (name
, address
)
574 /* We don't want TDESC entry points on the misc_function_vector */
575 if (name
[0] == '@') return;
577 /* mf_text isn't true, but apparently COFF doesn't tell us what it really
578 is, so this guess is more useful than mf_unknown. */
579 prim_record_misc_function (savestring (name
, strlen (name
)),
584 /* coff_symfile_init ()
585 is the coff-specific initialization routine for reading symbols.
586 It is passed a struct sym_fns which contains, among other things,
587 the BFD for the file whose symbols are being read, and a slot for
588 a pointer to "private data" which we fill with cookies and other
589 treats for coff_symfile_read ().
591 We will only be called if this is a COFF or COFF-like file.
592 BFD handles figuring out the format of the file, and code in symtab.c
593 uses BFD's determination to vector to us.
595 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
597 struct coff_symfile_info
{
598 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
599 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
603 coff_symfile_init (sf
)
606 bfd
*abfd
= sf
->sym_bfd
;
608 /* Allocate struct to keep track of the symfile */
609 /* FIXME memory leak */
610 sf
->sym_private
= xmalloc (sizeof (struct coff_symfile_info
));
613 safe_to_init_tdesc_context
= 0;
616 /* Save startup file's range of PC addresses to help blockframe.c
617 decide where the bottom of the stack is. */
618 if (bfd_get_file_flags (abfd
) & EXEC_P
)
620 /* Executable file -- record its entry point so we'll recognize
621 the startup file because it contains the entry point. */
622 entry_point
= bfd_get_start_address (abfd
);
626 /* Examination of non-executable.o files. Short-circuit this stuff. */
627 /* ~0 will not be in any file, we hope. */
629 /* set the startup file to be an empty range. */
630 startup_file_start
= 0;
631 startup_file_end
= 0;
635 /* This function is called for every section; it finds the outer limits
636 of the line table (minimum and maximum file offset) so that the
637 mainline code can read the whole thing for efficiency. */
641 find_linenos (abfd
, asect
, vpinfo
)
646 struct coff_symfile_info
*info
;
648 file_ptr offset
, maxoff
;
650 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
651 count
= asect
->lineno_count
;
656 #if !defined (LINESZ)
657 /* Just in case, you never know what to expect from those
658 COFF header files. */
659 #define LINESZ (sizeof (struct lineno))
660 #endif /* No LINESZ. */
661 size
= count
* LINESZ
;
663 info
= (struct coff_symfile_info
*)vpinfo
;
664 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
665 offset
= asect
->line_filepos
;
668 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
669 info
->min_lineno_offset
= offset
;
671 maxoff
= offset
+ size
;
672 if (maxoff
> info
->max_lineno_offset
)
673 info
->max_lineno_offset
= maxoff
;
675 /* While we're at it, find the debug_info. It's in the s_relptr
676 (or, in BFD-speak, rel_filepos) of the text segment section header. */
677 if (strcmp (bfd_section_name (abfd
, asect
), ".text") == 0)
679 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
680 debug_info
= asect
->rel_filepos
;
684 dc_terminate (tdesc_handle
);
692 /* The BFD for this file -- only good while we're actively reading
693 symbols into a psymtab or a symtab. */
695 static bfd
*symfile_bfd
;
697 /* Read a symbol file, after initialization by coff_symfile_init. */
698 /* FIXME! Addr and Mainline are not used yet -- this will not work for
699 shared libraries or add_file! */
702 coff_symfile_read (sf
, addr
, mainline
)
707 struct coff_symfile_info
*info
= (struct coff_symfile_info
*)sf
->sym_private
;
708 bfd
*abfd
= sf
->sym_bfd
;
709 char *name
= bfd_get_filename (abfd
);
714 int stringtab_offset
;
716 symfile_bfd
= abfd
; /* Kludge for swap routines */
718 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
719 desc
= fileno ((FILE *)(abfd
->iostream
)); /* File descriptor */
720 num_symbols
= bfd_get_symcount (abfd
); /* How many syms */
721 symtab_offset
= obj_sym_filepos (abfd
); /* Symbol table file offset */
722 stringtab_offset
= symtab_offset
+ num_symbols
* SYMESZ
; /* String tab */
725 /* Read the line number table, all at once. */
726 info
->min_lineno_offset
= 0;
727 info
->max_lineno_offset
= 0;
728 bfd_map_over_sections (abfd
, find_linenos
, info
);
730 val
= init_lineno (desc
, info
->min_lineno_offset
,
731 info
->max_lineno_offset
- info
->min_lineno_offset
);
733 error ("\"%s\": error reading line numbers\n", name
);
735 /* Now read the string table, all at once. */
737 val
= init_stringtab (desc
, stringtab_offset
);
740 free_all_symtabs (); /* FIXME blows whole symtab */
741 printf ("\"%s\": can't get string table", name
);
745 make_cleanup (free_stringtab
, 0);
747 /* Position to read the symbol table. Do not read it all at once. */
748 val
= lseek (desc
, (long)symtab_offset
, 0);
750 perror_with_name (name
);
752 init_misc_bunches ();
753 make_cleanup (discard_misc_bunches
, 0);
755 /* Now that the executable file is positioned at symbol table,
756 process it and define symbols accordingly. */
758 read_coff_symtab (desc
, num_symbols
);
760 patch_opaque_types ();
762 /* Sort symbols alphabetically within each block. */
764 sort_all_symtab_syms ();
766 /* Go over the misc symbol bunches and install them in vector. */
768 condense_misc_bunches (0);
770 /* Make a default for file to list. */
772 select_source_symtab (0); /* FIXME, this might be too slow, see dbxread */
776 coff_symfile_discard ()
778 /* There seems to be nothing to do here. */
784 /* There seems to be nothing to do except free_all_symtabs and set
785 symfile to zero, which is done by our caller. */
788 /* Simplified internal version of coff symbol table information */
792 int c_symnum
; /* symbol number of this entry */
793 int c_nsyms
; /* 1 if syment only, 2 if syment + auxent, etc */
800 /* Given pointers to a symbol table in coff style exec file,
801 analyze them and create struct symtab's describing the symbols.
802 NSYMS is the number of symbols in the symbol table.
803 We read them one at a time using read_one_sym (). */
806 read_coff_symtab (desc
, nsyms
)
810 int newfd
; /* Avoid multiple closes on same desc */
812 register struct context_stack
*new;
813 struct coff_symbol coff_symbol
;
814 register struct coff_symbol
*cs
= &coff_symbol
;
815 static SYMENT main_sym
;
816 static AUXENT main_aux
;
817 struct coff_symbol fcn_cs_saved
;
818 static SYMENT fcn_sym_saved
;
819 static AUXENT fcn_aux_saved
;
821 /* A .file is open. */
822 int in_source_file
= 0;
823 int num_object_files
= 0;
824 int next_file_symnum
= -1;
826 /* Name of the current file. */
827 char *filestring
= "";
833 struct cleanup
*old_chain
;
838 fatal ("Too many open files");
839 stream
= fdopen (newfd
, "r");
841 old_chain
= make_cleanup (free_all_symtabs
, 0);
842 make_cleanup (fclose
, stream
);
843 nlist_stream_global
= stream
;
844 nlist_nsyms_global
= nsyms
;
845 last_source_file
= 0;
846 bzero (opaque_type_chain
, sizeof opaque_type_chain
);
848 type_vector_length
= 160;
849 type_vector
= (struct typevector
*)
850 xmalloc (sizeof (struct typevector
)
851 + type_vector_length
* sizeof (struct type
*));
852 bzero (type_vector
->type
, type_vector_length
* sizeof (struct type
*));
857 while (symnum
< nsyms
)
859 QUIT
; /* Make this command interruptable. */
860 read_one_sym (cs
, &main_sym
, &main_aux
);
863 temp_sem_val
= cs
->c_name
[0] << 24 | cs
->c_name
[1] << 16 |
864 cs
->c_name
[2] << 8 | cs
->c_name
[3];
865 if (int_sem_val
== temp_sem_val
)
866 last_coffsem
= (int) strtol (cs
->c_name
+4, (char **) NULL
, 10);
869 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
871 if (last_source_file
)
875 complete_symtab ("_globals_", 0, first_object_file_end
);
876 /* done with all files, everything from here on out is globals */
879 /* Special case for file with type declarations only, no text. */
880 if (!last_source_file
&& SDB_TYPE (cs
->c_type
)
881 && cs
->c_secnum
== N_DEBUG
)
882 complete_symtab (filestring
, 0, 0);
884 /* Typedefs should not be treated as symbol definitions. */
885 if (ISFCN (cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
887 /* record as misc function. if we get '.bf' next,
888 * then we undo this step
890 record_misc_function (cs
->c_name
, cs
->c_value
);
892 fcn_line_ptr
= main_aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
893 fcn_start_addr
= cs
->c_value
;
895 fcn_sym_saved
= main_sym
;
896 fcn_aux_saved
= main_aux
;
900 switch (cs
->c_sclass
)
909 printf ("Bad n_sclass = %d\n", cs
->c_sclass
);
914 * c_value field contains symnum of next .file entry in table
915 * or symnum of first global after last .file.
917 next_file_symnum
= cs
->c_value
;
918 filestring
= getfilename (&main_aux
);
920 * Complete symbol table for last object file
921 * containing debugging information.
923 if (last_source_file
)
932 if (cs
->c_name
[0] == '.') {
933 if (strcmp (cs
->c_name
, _TEXT
) == 0) {
934 if (++num_object_files
== 1) {
935 /* last address of startup file */
936 first_object_file_end
= cs
->c_value
+
937 main_aux
.x_scn
.x_scnlen
;
939 /* Check for in_source_file deals with case of
940 a file with debugging symbols
941 followed by a later file with no symbols. */
943 complete_symtab (filestring
, cs
->c_value
,
944 main_aux
.x_scn
.x_scnlen
);
947 /* flush rest of '.' symbols */
950 else if (!SDB_TYPE (cs
->c_type
)
951 && cs
->c_name
[0] == 'L'
952 && (strncmp (cs
->c_name
, "LI%", 3) == 0
953 || strncmp (cs
->c_name
, "LF%", 3) == 0
954 || strncmp (cs
->c_name
,"LC%",3) == 0
955 || strncmp (cs
->c_name
,"LP%",3) == 0
956 || strncmp (cs
->c_name
,"LPB%",4) == 0
957 || strncmp (cs
->c_name
,"LBB%",4) == 0
958 || strncmp (cs
->c_name
,"LBE%",4) == 0
959 || strncmp (cs
->c_name
,"LPBX%",5) == 0))
960 /* At least on a 3b1, gcc generates swbeg and string labels
961 that look like this. Ignore them. */
963 /* fall in for static symbols that don't start with '.' */
965 if (cs
->c_sclass
== C_EXT
&&
966 cs
->c_secnum
== N_ABS
&&
967 strcmp (cs
->c_name
, _ETEXT
) == 0)
968 end_of_text_addr
= cs
->c_value
;
969 if (!SDB_TYPE (cs
->c_type
)) {
970 if (cs
->c_secnum
<= 1) { /* text or abs */
971 record_misc_function (cs
->c_name
, cs
->c_value
);
977 (void) process_coff_symbol (cs
, &main_aux
);
981 if (strcmp (cs
->c_name
, ".bf") == 0)
985 /* value contains address of first non-init type code */
986 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
987 contains line number of '{' } */
988 fcn_first_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
990 new = (struct context_stack
*)
991 xmalloc (sizeof (struct context_stack
));
992 new->depth
= depth
= 0;
996 new->old_blocks
= pending_blocks
;
997 new->start_addr
= fcn_start_addr
;
998 fcn_cs_saved
.c_name
= getsymname (&fcn_sym_saved
);
999 new->name
= process_coff_symbol (&fcn_cs_saved
,
1002 else if (strcmp (cs
->c_name
, ".ef") == 0)
1004 /* the value of .ef is the address of epilogue code;
1005 * not useful for gdb
1007 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1008 contains number of lines to '}' */
1009 new = context_stack
;
1012 complain (&ef_complaint
, cs
->c_symnum
);
1013 within_function
= 0;
1016 fcn_last_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
1017 enter_linenos (fcn_line_ptr
, fcn_first_line
, fcn_last_line
);
1019 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1021 #if defined (FUNCTION_EPILOGUE_SIZE)
1022 /* This macro should be defined only on
1024 fcn_aux_saved.x_sym.x_misc.x_fsize
1025 field is always zero.
1026 So use the .bf record information that
1027 points to the epilogue and add the size
1029 cs
->c_value
+ FUNCTION_EPILOGUE_SIZE
1031 fcn_cs_saved
.c_value
+
1032 fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1036 within_function
= 0;
1042 if (strcmp (cs
->c_name
, ".bb") == 0)
1044 new = (struct context_stack
*)
1045 xmalloc (sizeof (struct context_stack
));
1048 new->next
= context_stack
;
1049 context_stack
= new;
1050 new->locals
= local_symbols
;
1051 new->old_blocks
= pending_blocks
;
1052 new->start_addr
= cs
->c_value
;
1056 else if (strcmp (cs
->c_name
, ".eb") == 0)
1058 new = context_stack
;
1059 if (new == 0 || depth
!= new->depth
)
1060 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1062 if (local_symbols
&& context_stack
->next
)
1064 /* Make a block for the local symbols within. */
1065 finish_block (0, &local_symbols
, new->old_blocks
,
1066 new->start_addr
, cs
->c_value
);
1069 local_symbols
= new->locals
;
1070 context_stack
= new->next
;
1077 /* This isn't used currently. */
1078 if (strcmp (cs
->c_name
, ".coffsyn") == 0)
1079 last_coffsyn
= cs
->c_value
;
1082 if ((strcmp (cs
->c_name
, ".coffsem") == 0) &&
1084 last_coffsem
= cs
->c_value
;
1090 if ((strcmp (cs
->c_name
, ".coffsem") == 0) &&
1092 last_coffsem
= cs
->c_value
;
1095 (void) process_coff_symbol (cs
, &main_aux
);
1100 if (last_source_file
)
1103 discard_cleanups (old_chain
);
1106 /* Routines for reading headers and symbols from executable. */
1109 /* Move these XXXMAGIC symbol defns into BFD! */
1111 /* Read COFF file header, check magic number,
1112 and return number of symbols. */
1113 read_file_hdr (chan
, file_hdr
)
1117 lseek (chan
, 0L, 0);
1118 if (myread (chan
, (char *)file_hdr
, FILHSZ
) < 0)
1121 switch (file_hdr
->f_magic
)
1136 #if defined (MC68KWRMAGIC) \
1137 && (!defined (MC68MAGIC) || MC68KWRMAGIC != MC68MAGIC)
1151 case I960ROMAGIC
: /* Intel 960 */
1154 case I960RWMAGIC
: /* Intel 960 */
1156 return file_hdr
->f_nsyms
;
1160 if (BADMAG(file_hdr
))
1163 return file_hdr
->f_nsyms
;
1173 read_one_sym (cs
, sym
, aux
)
1174 register struct coff_symbol
*cs
;
1175 register SYMENT
*sym
;
1176 register AUXENT
*aux
;
1181 cs
->c_symnum
= symnum
;
1182 fread ((char *)sym
, SYMESZ
, 1, nlist_stream_global
);
1183 bfd_coff_swap_sym (symfile_bfd
, sym
);
1184 cs
->c_nsyms
= (sym
->n_numaux
& 0xff) + 1;
1185 if (cs
->c_nsyms
>= 2)
1187 fread ((char *)aux
, AUXESZ
, 1, nlist_stream_global
);
1188 bfd_coff_swap_aux (symfile_bfd
, aux
, sym
->n_type
, sym
->n_sclass
);
1189 /* If more than one aux entry, read past it (only the first aux
1191 for (i
= 2; i
< cs
->c_nsyms
; i
++)
1192 fread ((char *)&temp_aux
, AUXESZ
, 1, nlist_stream_global
);
1194 cs
->c_name
= getsymname (sym
);
1195 cs
->c_value
= sym
->n_value
;
1196 cs
->c_sclass
= (sym
->n_sclass
& 0xff);
1197 cs
->c_secnum
= sym
->n_scnum
;
1198 cs
->c_type
= (unsigned) sym
->n_type
;
1199 if (!SDB_TYPE (cs
->c_type
))
1202 symnum
+= cs
->c_nsyms
;
1205 /* Support for string table handling */
1207 static char *stringtab
= NULL
;
1210 init_stringtab (chan
, offset
)
1216 unsigned char lengthbuf
[4];
1224 if (lseek (chan
, offset
, 0) < 0)
1227 val
= myread (chan
, (char *)lengthbuf
, sizeof lengthbuf
);
1228 length
= bfd_h_getlong (symfile_bfd
, lengthbuf
);
1230 /* If no string table is needed, then the file may end immediately
1231 after the symbols. Just return with `stringtab' set to null. */
1232 if (val
!= sizeof length
|| length
< sizeof length
)
1235 stringtab
= (char *) xmalloc (length
);
1236 if (stringtab
== NULL
)
1239 bcopy (&length
, stringtab
, sizeof length
);
1240 if (length
== sizeof length
) /* Empty table -- just the count */
1243 val
= myread (chan
, stringtab
+ sizeof length
, length
- sizeof length
);
1244 if (val
!= length
- sizeof length
|| stringtab
[length
- 1] != '\0')
1259 getsymname (symbol_entry
)
1260 SYMENT
*symbol_entry
;
1262 static char buffer
[SYMNMLEN
+1];
1265 if (symbol_entry
->n_zeroes
== 0)
1267 result
= stringtab
+ symbol_entry
->n_offset
;
1271 strncpy (buffer
, symbol_entry
->n_name
, SYMNMLEN
);
1272 buffer
[SYMNMLEN
] = '\0';
1279 getfilename (aux_entry
)
1282 static char buffer
[BUFSIZ
];
1283 register char *temp
;
1285 extern char *rindex ();
1287 #ifndef COFF_NO_LONG_FILE_NAMES
1288 #if defined (x_zeroes)
1290 if (aux_entry
->x_zeroes
== 0)
1291 strcpy (buffer
, stringtab
+ aux_entry
->x_offset
);
1292 #else /* no x_zeroes */
1293 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1294 strcpy (buffer
, stringtab
+ aux_entry
->x_file
.x_n
.x_offset
);
1295 #endif /* no x_zeroes */
1297 #endif /* COFF_NO_LONG_FILE_NAMES */
1299 #if defined (x_name)
1301 strncpy (buffer
, aux_entry
->x_name
, FILNMLEN
);
1303 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1305 buffer
[FILNMLEN
] = '\0';
1308 if ((temp
= rindex (result
, '/')) != NULL
)
1313 /* Support for line number handling */
1314 static char *linetab
= NULL
;
1315 static long linetab_offset
;
1316 static unsigned long linetab_size
;
1318 /* Read in all the line numbers for fast lookups later. */
1321 init_lineno (chan
, offset
, size
)
1327 register char *p
, *q
;
1329 if (lseek (chan
, offset
, 0) < 0)
1332 linetab
= (char *) xmalloc (size
);
1334 val
= myread (chan
, linetab
, size
);
1338 /* Swap all entries */
1340 for (p
= linetab
; p
< q
; p
+= LINESZ
)
1341 bfd_coff_swap_lineno (symfile_bfd
, (LINENO
*)p
);
1343 linetab_offset
= offset
;
1344 linetab_size
= size
;
1345 make_cleanup (free
, linetab
); /* Be sure it gets de-allocated. */
1349 #if !defined (L_LNNO32)
1350 #define L_LNNO32(lp) ((lp)->l_lnno)
1354 enter_linenos (file_offset
, first_line
, last_line
)
1356 register int first_line
;
1357 register int last_line
;
1359 register char *rawptr
;
1362 if (file_offset
< linetab_offset
)
1364 complain (&lineno_complaint
, file_offset
);
1365 if (file_offset
> linetab_size
) /* Too big to be an offset? */
1367 file_offset
+= linetab_offset
; /* Try reading at that linetab offset */
1370 rawptr
= &linetab
[file_offset
- linetab_offset
];
1372 /* skip first line entry for each function */
1374 /* line numbers start at one for the first line of the function */
1377 /* Bcopy since occaisionally rawptr isn't pointing at long
1379 for (bcopy (rawptr
, &lptr
, LINESZ
);
1380 L_LNNO32 (&lptr
) && L_LNNO32 (&lptr
) <= last_line
;
1381 rawptr
+= LINESZ
, bcopy (rawptr
, &lptr
, LINESZ
))
1383 record_line (first_line
+ L_LNNO32 (&lptr
), lptr
.l_addr
.l_paddr
);
1391 register char *p
= name
;
1392 register int total
= p
[0];
1405 return total
% HASHSIZE
;
1409 patch_type (type
, real_type
)
1411 struct type
*real_type
;
1413 register struct type
*target
= TYPE_TARGET_TYPE (type
);
1414 register struct type
*real_target
= TYPE_TARGET_TYPE (real_type
);
1415 int field_size
= TYPE_NFIELDS (real_target
) * sizeof (struct field
);
1417 TYPE_LENGTH (target
) = TYPE_LENGTH (real_target
);
1418 TYPE_NFIELDS (target
) = TYPE_NFIELDS (real_target
);
1419 TYPE_FIELDS (target
) = (struct field
*)
1420 obstack_alloc (symbol_obstack
, field_size
);
1422 bcopy (TYPE_FIELDS (real_target
), TYPE_FIELDS (target
), field_size
);
1424 if (TYPE_NAME (real_target
))
1426 if (TYPE_NAME (target
))
1427 free (TYPE_NAME (target
));
1428 TYPE_NAME (target
) = concat (TYPE_NAME (real_target
), "", "");
1432 /* Patch up all appropriate typdef symbols in the opaque_type_chains
1433 so that they can be used to print out opaque data structures properly */
1436 patch_opaque_types ()
1440 /* Look at each symbol in the per-file block of each symtab. */
1441 for (s
= symtab_list
; s
; s
= s
->next
)
1443 register struct block
*b
;
1446 /* Go through the per-file symbols only */
1447 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
1448 for (i
= BLOCK_NSYMS (b
) - 1; i
>= 0; i
--)
1450 register struct symbol
*real_sym
;
1452 /* Find completed typedefs to use to fix opaque ones.
1453 Remove syms from the chain when their types are stored,
1454 but search the whole chain, as there may be several syms
1455 from different files with the same name. */
1456 real_sym
= BLOCK_SYM (b
, i
);
1457 if (SYMBOL_CLASS (real_sym
) == LOC_TYPEDEF
&&
1458 SYMBOL_NAMESPACE (real_sym
) == VAR_NAMESPACE
&&
1459 TYPE_CODE (SYMBOL_TYPE (real_sym
)) == TYPE_CODE_PTR
&&
1460 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym
))) != 0)
1462 register char *name
= SYMBOL_NAME (real_sym
);
1463 register int hash
= hashname (name
);
1464 register struct symbol
*sym
, *prev
;
1467 for (sym
= opaque_type_chain
[hash
]; sym
;)
1469 if (name
[0] == SYMBOL_NAME (sym
)[0] &&
1470 !strcmp (name
+ 1, SYMBOL_NAME (sym
) + 1))
1473 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
1475 opaque_type_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
1477 patch_type (SYMBOL_TYPE (sym
), SYMBOL_TYPE (real_sym
));
1480 sym
= SYMBOL_VALUE_CHAIN (prev
);
1482 sym
= opaque_type_chain
[hash
];
1487 sym
= SYMBOL_VALUE_CHAIN (sym
);
1495 #if defined (clipper)
1496 #define BELIEVE_PCC_PROMOTION 1
1499 static struct symbol
*
1500 process_coff_symbol (cs
, aux
)
1501 register struct coff_symbol
*cs
;
1502 register AUXENT
*aux
;
1504 register struct symbol
*sym
1505 = (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
1507 #ifdef NAMES_HAVE_UNDERSCORE
1513 bzero (sym
, sizeof (struct symbol
));
1515 name
= (name
[0] == '_' ? name
+ offset
: name
);
1516 SYMBOL_NAME (sym
) = obstack_copy0 (symbol_obstack
, name
, strlen (name
));
1518 /* default assumptions */
1519 SYMBOL_VALUE (sym
) = cs
->c_value
;
1520 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1522 if (ISFCN (cs
->c_type
))
1525 lookup_function_type (decode_function_type (cs
, cs
->c_type
, aux
));
1526 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1527 if (cs
->c_sclass
== C_STAT
)
1528 add_symbol_to_list (sym
, &file_symbols
);
1529 else if (cs
->c_sclass
== C_EXT
)
1530 add_symbol_to_list (sym
, &global_symbols
);
1534 SYMBOL_TYPE (sym
) = decode_type (cs
, cs
->c_type
, aux
);
1535 switch (cs
->c_sclass
)
1541 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1542 add_symbol_to_list (sym
, &local_symbols
);
1546 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1547 SYMBOL_VALUE_ADDRESS (sym
) = (CORE_ADDR
) cs
->c_value
;
1548 add_symbol_to_list (sym
, &global_symbols
);
1552 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1553 SYMBOL_VALUE_ADDRESS (sym
) = (CORE_ADDR
) cs
->c_value
;
1554 if (within_function
) {
1555 /* Static symbol of local scope */
1556 add_symbol_to_list (sym
, &local_symbols
);
1559 /* Static symbol at top level of file */
1560 add_symbol_to_list (sym
, &file_symbols
);
1565 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1566 add_symbol_to_list (sym
, &local_symbols
);
1573 SYMBOL_CLASS (sym
) = LOC_ARG
;
1574 add_symbol_to_list (sym
, &local_symbols
);
1575 #if !defined (BELIEVE_PCC_PROMOTION)
1576 /* If PCC says a parameter is a short or a char,
1577 it is really an int. */
1578 if (SYMBOL_TYPE (sym
) == builtin_type_char
1579 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1580 SYMBOL_TYPE (sym
) = builtin_type_int
;
1581 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1582 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1583 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1588 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1589 add_symbol_to_list (sym
, &local_symbols
);
1590 #if !defined (BELIEVE_PCC_PROMOTION)
1591 /* If PCC says a parameter is a short or a char,
1592 it is really an int. */
1593 if (SYMBOL_TYPE (sym
) == builtin_type_char
1594 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1595 SYMBOL_TYPE (sym
) = builtin_type_int
;
1596 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1597 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1598 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1603 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1604 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1606 /* If type has no name, give it one */
1607 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1608 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1609 TYPE_NAME (SYMBOL_TYPE (sym
))
1610 = concat (SYMBOL_NAME (sym
), "", "");
1612 /* Keep track of any type which points to empty structured type,
1613 so it can be filled from a definition from another file */
1614 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
&&
1615 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym
))) == 0)
1617 register int i
= hashname (SYMBOL_NAME (sym
));
1619 SYMBOL_VALUE_CHAIN (sym
) = opaque_type_chain
[i
];
1620 opaque_type_chain
[i
] = sym
;
1622 add_symbol_to_list (sym
, &file_symbols
);
1628 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1629 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1630 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1631 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1632 TYPE_NAME (SYMBOL_TYPE (sym
))
1634 (cs
->c_sclass
== C_ENTAG
1636 : (cs
->c_sclass
== C_STRTAG
1637 ? "struct " : "union ")),
1639 add_symbol_to_list (sym
, &file_symbols
);
1649 /* Decode a coff type specifier;
1650 return the type that is meant. */
1654 decode_type (cs
, c_type
, aux
)
1655 register struct coff_symbol
*cs
;
1656 unsigned int c_type
;
1657 register AUXENT
*aux
;
1659 register struct type
*type
= 0;
1660 unsigned int new_c_type
;
1662 if (c_type
& ~N_BTMASK
)
1664 new_c_type
= DECREF (c_type
);
1667 type
= decode_type (cs
, new_c_type
, aux
);
1668 type
= lookup_pointer_type (type
);
1670 else if (ISFCN (c_type
))
1672 type
= decode_type (cs
, new_c_type
, aux
);
1673 type
= lookup_function_type (type
);
1675 else if (ISARY (c_type
))
1678 register unsigned short *dim
;
1679 struct type
*base_type
;
1681 /* Define an array type. */
1682 /* auxent refers to array, not base type */
1683 if (aux
->x_sym
.x_tagndx
== 0)
1686 /* shift the indices down */
1687 dim
= &aux
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0];
1690 for (i
= 0; *dim
&& i
< DIMNUM
- 1; i
++, dim
++)
1694 type
= (struct type
*)
1695 obstack_alloc (symbol_obstack
, sizeof (struct type
));
1696 bzero (type
, sizeof (struct type
));
1698 base_type
= decode_type (cs
, new_c_type
, aux
);
1700 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
1701 TYPE_TARGET_TYPE (type
) = base_type
;
1702 TYPE_LENGTH (type
) = n
* TYPE_LENGTH (base_type
);
1707 /* Reference to existing type */
1708 if (cs
->c_nsyms
> 1 && aux
->x_sym
.x_tagndx
!= 0)
1710 type
= coff_alloc_type (aux
->x_sym
.x_tagndx
);
1714 return decode_base_type (cs
, BTYPE (c_type
), aux
);
1717 /* Decode a coff type specifier for function definition;
1718 return the type that the function returns. */
1722 decode_function_type (cs
, c_type
, aux
)
1723 register struct coff_symbol
*cs
;
1724 unsigned int c_type
;
1725 register AUXENT
*aux
;
1727 if (aux
->x_sym
.x_tagndx
== 0)
1728 cs
->c_nsyms
= 1; /* auxent refers to function, not base type */
1730 return decode_type (cs
, DECREF (c_type
), aux
);
1737 decode_base_type (cs
, c_type
, aux
)
1738 register struct coff_symbol
*cs
;
1739 unsigned int c_type
;
1740 register AUXENT
*aux
;
1747 /* shows up with "void (*foo)();" structure members */
1748 return builtin_type_void
;
1751 /* DGUX actually defines both T_ARG and T_VOID to the same value. */
1754 /* Shows up in DGUX, I think. Not sure where. */
1755 return builtin_type_void
; /* shouldn't show up here */
1761 /* Intel 960 COFF has this symbol and meaning. */
1762 return builtin_type_void
;
1766 return builtin_type_char
;
1769 return builtin_type_short
;
1772 return builtin_type_int
;
1775 return builtin_type_long
;
1778 return builtin_type_float
;
1781 return builtin_type_double
;
1784 if (cs
->c_nsyms
!= 2)
1786 /* anonymous structure type */
1787 type
= coff_alloc_type (cs
->c_symnum
);
1788 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1789 TYPE_NAME (type
) = concat ("struct ", "<opaque>", "");
1790 TYPE_LENGTH (type
) = 0;
1791 TYPE_FIELDS (type
) = 0;
1792 TYPE_NFIELDS (type
) = 0;
1796 type
= read_struct_type (cs
->c_symnum
,
1797 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1798 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1803 if (cs
->c_nsyms
!= 2)
1805 /* anonymous union type */
1806 type
= coff_alloc_type (cs
->c_symnum
);
1807 TYPE_NAME (type
) = concat ("union ", "<opaque>", "");
1808 TYPE_LENGTH (type
) = 0;
1809 TYPE_FIELDS (type
) = 0;
1810 TYPE_NFIELDS (type
) = 0;
1814 type
= read_struct_type (cs
->c_symnum
,
1815 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1816 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1818 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1822 return read_enum_type (cs
->c_symnum
,
1823 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1824 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1827 /* shouldn't show up here */
1831 return builtin_type_unsigned_char
;
1834 return builtin_type_unsigned_short
;
1837 return builtin_type_unsigned_int
;
1840 return builtin_type_unsigned_long
;
1842 printf ("unexpected type %d at symnum %d\n", c_type
, cs
->c_symnum
);
1843 return builtin_type_void
;
1846 /* This page contains subroutines of read_type. */
1848 /* Read the description of a structure (or union type)
1849 and return an object describing the type. */
1851 static struct type
*
1852 read_struct_type (index
, length
, lastsym
)
1859 struct nextfield
*next
;
1863 register struct type
*type
;
1864 register struct nextfield
*list
= 0;
1865 struct nextfield
*new;
1869 #ifdef NAMES_HAVE_UNDERSCORE
1874 struct coff_symbol member_sym
;
1875 register struct coff_symbol
*ms
= &member_sym
;
1880 type
= coff_alloc_type (index
);
1881 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1882 TYPE_LENGTH (type
) = length
;
1884 while (!done
&& symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
1886 read_one_sym (ms
, &sub_sym
, &sub_aux
);
1888 name
= (name
[0] == '_' ? name
+ offset
: name
);
1890 switch (ms
->c_sclass
)
1895 /* Get space to record the next field's data. */
1896 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1900 /* Save the data. */
1901 list
->field
.name
= savestring (name
, strlen (name
));
1902 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1903 list
->field
.bitpos
= 8 * ms
->c_value
;
1904 list
->field
.bitsize
= 0;
1910 /* Get space to record the next field's data. */
1911 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1915 /* Save the data. */
1916 list
->field
.name
= savestring (name
, strlen (name
));
1917 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1918 list
->field
.bitpos
= ms
->c_value
;
1919 list
->field
.bitsize
= sub_aux
.x_sym
.x_misc
.x_lnsz
.x_size
;
1928 /* Now create the vector of fields, and record how big it is. */
1930 TYPE_NFIELDS (type
) = nfields
;
1931 TYPE_FIELDS (type
) = (struct field
*)
1932 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nfields
);
1934 /* Copy the saved-up fields into the field vector. */
1936 for (n
= nfields
; list
; list
= list
->next
)
1937 TYPE_FIELD (type
, --n
) = list
->field
;
1942 /* Read a definition of an enumeration type,
1943 and create and return a suitable type object.
1944 Also defines the symbols that represent the values of the type. */
1945 /* Currently assumes it's sizeof (int) and doesn't use length. */
1947 static struct type
*
1948 read_enum_type (index
, length
, lastsym
)
1953 register struct symbol
*sym
;
1954 register struct type
*type
;
1957 struct pending
**symlist
;
1958 struct coff_symbol member_sym
;
1959 register struct coff_symbol
*ms
= &member_sym
;
1962 struct pending
*osyms
, *syms
;
1965 #ifdef NAMES_HAVE_UNDERSCORE
1971 type
= coff_alloc_type (index
);
1972 if (within_function
)
1973 symlist
= &local_symbols
;
1975 symlist
= &file_symbols
;
1978 while (!done
&& symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
1980 read_one_sym (ms
, &sub_sym
, &sub_aux
);
1982 name
= (name
[0] == '_' ? name
+ offset
: name
);
1984 switch (ms
->c_sclass
)
1987 sym
= (struct symbol
*) xmalloc (sizeof (struct symbol
));
1988 bzero (sym
, sizeof (struct symbol
));
1990 SYMBOL_NAME (sym
) = savestring (name
, strlen (name
));
1991 SYMBOL_CLASS (sym
) = LOC_CONST
;
1992 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1993 SYMBOL_VALUE (sym
) = ms
->c_value
;
1994 add_symbol_to_list (sym
, symlist
);
1999 /* Sometimes the linker (on 386/ix 2.0.2 at least) screws
2000 up the count of how many symbols to read. So stop
2007 /* Now fill in the fields of the type-structure. */
2009 /* FIXME: Should be sizeof (int) on target, not host. */
2010 TYPE_LENGTH (type
) = sizeof (int);
2011 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2012 TYPE_NFIELDS (type
) = nsyms
;
2013 TYPE_FIELDS (type
) = (struct field
*)
2014 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nsyms
);
2016 /* Find the symbols for the values and put them into the type.
2017 The symbols can be found in the symlist that we put them on
2018 to cause them to be defined. osyms contains the old value
2019 of that symlist; everything up to there was defined by us. */
2021 for (syms
= *symlist
, n
= nsyms
; syms
!= osyms
; syms
= syms
->next
)
2023 SYMBOL_TYPE (syms
->symbol
) = type
;
2024 TYPE_FIELD_NAME (type
, --n
) = SYMBOL_NAME (syms
->symbol
);
2025 TYPE_FIELD_VALUE (type
, n
) = 0;
2026 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (syms
->symbol
);
2027 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2032 /* Register our ability to parse symbols for coff BFD files */
2034 static struct sym_fns coff_sym_fns
=
2036 /* This assumes that 88kbcs implies TDESC and TDESC implies 88kbcs.
2037 If that's not true, this can be relaxed, but if it is true,
2038 it will just cause users grief if we try to read the wrong kind
2042 #else /* not TDESC */
2044 #endif /* not TDESC */
2045 coff_new_init
, coff_symfile_init
,
2046 coff_symfile_read
, coff_symfile_discard
2050 _initialize_coffread ()
2052 add_symtab_fns(&coff_sym_fns
);
2055 #endif /* NO_COFF */