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. */
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 (/* symfile_bfd, &sym */);
76 extern void bfd_coff_swap_aux (/* symfile_bfd, &aux, type, sclass */);
77 extern void bfd_coff_swap_lineno (/* symfile_bfd, &lineno */);
80 /* Name of source file whose symbol data we are now processing.
81 This comes from a symbol named ".file". */
83 static char *last_source_file
;
85 /* Core address of start and end of text of current source file.
86 This comes from a ".text" symbol where x_nlinno > 0. */
88 static CORE_ADDR cur_src_start_addr
;
89 static CORE_ADDR cur_src_end_addr
;
91 /* Core address of the end of the first object file. */
92 static CORE_ADDR first_object_file_end
;
94 /* End of the text segment of the executable file,
95 as found in the symbol _etext. */
97 static CORE_ADDR end_of_text_addr
;
99 /* The addresses of the symbol table stream and number of symbols
100 of the object file we are reading (as copied into core). */
102 static FILE *nlist_stream_global
;
103 static int nlist_nsyms_global
;
105 /* The entry point (starting address) of the file, if it is an executable. */
107 static CORE_ADDR entry_point
;
109 /* The index in the symbol table of the last coff symbol that was processed. */
113 /* Vector of types defined so far, indexed by their coff symnum. */
115 static struct typevector
*type_vector
;
117 /* Number of elements allocated for type_vector currently. */
119 static int type_vector_length
;
121 /* Vector of line number information. */
123 static struct linetable
*line_vector
;
125 /* Index of next entry to go in line_vector_index. */
127 static int line_vector_index
;
129 /* Last line number recorded in the line vector. */
131 static int prev_line_number
;
133 /* Number of elements allocated for line_vector currently. */
135 static int line_vector_length
;
140 int int_sem_val
= 's' << 24 | 'e' << 16 | 'm' << 8 | '.';
142 int last_coffsem
= 2;
144 /* This isn't used currently. */
145 int last_coffsyn
= 0;
147 int debug_info
= 0; /*used by tdesc */
148 extern dc_dcontext_t tdesc_handle
;
149 extern int safe_to_init_tdesc_context
;
152 /* Chain of typedefs of pointers to empty struct/union types.
153 They are chained thru the SYMBOL_VALUE_CHAIN. */
156 static struct symbol
*opaque_type_chain
[HASHSIZE
];
158 /* Record the symbols defined for each context in a list.
159 We don't create a struct block for the context until we
160 know how long to make it. */
164 struct pending
*next
;
165 struct symbol
*symbol
;
168 /* Here are the three lists that symbols are put on. */
170 struct pending
*file_symbols
; /* static at top level, and types */
172 struct pending
*global_symbols
; /* global functions and variables */
174 struct pending
*local_symbols
; /* everything local to lexical context */
176 /* List of unclosed lexical contexts
177 (that will become blocks, eventually). */
181 struct context_stack
*next
;
182 struct pending
*locals
;
183 struct pending_block
*old_blocks
;
185 CORE_ADDR start_addr
;
189 struct context_stack
*context_stack
;
191 /* Nonzero if within a function (so symbols should be local,
192 if nothing says specifically). */
196 /* List of blocks already made (lexical contexts already closed).
197 This is used at the end to make the blockvector. */
201 struct pending_block
*next
;
205 struct pending_block
*pending_blocks
;
207 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
208 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
210 /* Complaints about various problems in the file being read */
212 struct complaint ef_complaint
=
213 {"Unmatched .ef symbol(s) ignored starting at symnum %d", 0, 0};
215 struct complaint lineno_complaint
=
216 {"Line number pointer %d lower than start of line numbers", 0, 0};
219 /* Look up a coff type-number index. Return the address of the slot
220 where the type for that index is stored.
221 The type-number is in INDEX.
223 This can be used for finding the type associated with that index
224 or for associating a new type with the index. */
226 static struct type
**
227 coff_lookup_type (index
)
230 if (index
>= type_vector_length
)
232 int old_vector_length
= type_vector_length
;
234 type_vector_length
*= 2;
235 if (type_vector_length
< index
) {
236 type_vector_length
= index
* 2;
238 type_vector
= (struct typevector
*)
239 xrealloc (type_vector
, sizeof (struct typevector
)
240 + type_vector_length
* sizeof (struct type
*));
241 bzero (&type_vector
->type
[ old_vector_length
],
242 (type_vector_length
- old_vector_length
) * sizeof(struct type
*));
244 return &type_vector
->type
[index
];
247 /* Make sure there is a type allocated for type number index
248 and return the type object.
249 This can create an empty (zeroed) type object. */
252 coff_alloc_type (index
)
255 register struct type
**type_addr
= coff_lookup_type (index
);
256 register struct type
*type
= *type_addr
;
258 /* If we are referring to a type not known at all yet,
259 allocate an empty type for it.
260 We will fill it in later if we find out how. */
263 type
= (struct type
*) obstack_alloc (symbol_obstack
,
264 sizeof (struct type
));
265 bzero (type
, sizeof (struct type
));
271 /* maintain the lists of symbols and blocks */
273 /* Add a symbol to one of the lists of symbols. */
275 add_symbol_to_list (symbol
, listhead
)
276 struct symbol
*symbol
;
277 struct pending
**listhead
;
279 register struct pending
*link
280 = (struct pending
*) xmalloc (sizeof (struct pending
));
282 link
->next
= *listhead
;
283 link
->symbol
= symbol
;
287 /* Take one of the lists of symbols and make a block from it.
288 Put the block on the list of pending blocks. */
291 finish_block (symbol
, listhead
, old_blocks
, start
, end
)
292 struct symbol
*symbol
;
293 struct pending
**listhead
;
294 struct pending_block
*old_blocks
;
295 CORE_ADDR start
, end
;
297 register struct pending
*next
, *next1
;
298 register struct block
*block
;
299 register struct pending_block
*pblock
;
300 struct pending_block
*opblock
;
303 /* Count the length of the list of symbols. */
305 for (next
= *listhead
, i
= 0; next
; next
= next
->next
, i
++);
307 block
= (struct block
*)
308 obstack_alloc (symbol_obstack
, sizeof (struct block
) + (i
- 1) * sizeof (struct symbol
*));
310 /* Copy the symbols into the block. */
312 BLOCK_NSYMS (block
) = i
;
313 for (next
= *listhead
; next
; next
= next
->next
)
314 BLOCK_SYM (block
, --i
) = next
->symbol
;
316 BLOCK_START (block
) = start
;
317 BLOCK_END (block
) = end
;
318 BLOCK_SUPERBLOCK (block
) = 0; /* Filled in when containing block is made */
320 /* Put the block in as the value of the symbol that names it. */
324 SYMBOL_BLOCK_VALUE (symbol
) = block
;
325 BLOCK_FUNCTION (block
) = symbol
;
328 BLOCK_FUNCTION (block
) = 0;
330 /* Now free the links of the list, and empty the list. */
332 for (next
= *listhead
; next
; next
= next1
)
339 /* Install this block as the superblock
340 of all blocks made since the start of this scope
341 that don't have superblocks yet. */
344 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
346 if (BLOCK_SUPERBLOCK (pblock
->block
) == 0)
347 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
351 /* Record this block on the list of all blocks in the file.
352 Put it after opblock, or at the beginning if opblock is 0.
353 This puts the block in the list after all its subblocks. */
355 pblock
= (struct pending_block
*) xmalloc (sizeof (struct pending_block
));
356 pblock
->block
= block
;
359 pblock
->next
= opblock
->next
;
360 opblock
->next
= pblock
;
364 pblock
->next
= pending_blocks
;
365 pending_blocks
= pblock
;
369 static struct blockvector
*
372 register struct pending_block
*next
, *next1
;
373 register struct blockvector
*blockvector
;
376 /* Count the length of the list of blocks. */
378 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
380 blockvector
= (struct blockvector
*)
381 obstack_alloc (symbol_obstack
, sizeof (struct blockvector
) + (i
- 1) * sizeof (struct block
*));
383 /* Copy the blocks into the blockvector.
384 This is done in reverse order, which happens to put
385 the blocks into the proper order (ascending starting address).
386 finish_block has hair to insert each block into the list
387 after its subblocks in order to make sure this is true. */
389 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
390 for (next
= pending_blocks
; next
; next
= next
->next
)
391 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
393 /* Now free the links of the list, and empty the list. */
395 for (next
= pending_blocks
; next
; next
= next1
)
405 /* Manage the vector of line numbers. */
408 record_line (line
, pc
)
412 struct linetable_entry
*e
;
413 /* Make sure line vector is big enough. */
415 if (line_vector_index
+ 2 >= line_vector_length
)
417 line_vector_length
*= 2;
418 line_vector
= (struct linetable
*)
419 xrealloc (line_vector
, sizeof (struct linetable
)
420 + (line_vector_length
421 * sizeof (struct linetable_entry
)));
424 e
= line_vector
->item
+ line_vector_index
++;
425 e
->line
= line
; e
->pc
= pc
;
428 /* Start a new symtab for a new source file.
429 This is called when a COFF ".file" symbol is seen;
430 it indicates the start of data for one original source file. */
439 last_source_file
= 0;
443 /* This isn't used currently. */
448 /* Initialize the source file information for this file. */
450 line_vector_index
= 0;
451 line_vector_length
= 1000;
452 prev_line_number
= -2; /* Force first line number to be explicit */
453 line_vector
= (struct linetable
*)
454 xmalloc (sizeof (struct linetable
)
455 + line_vector_length
* sizeof (struct linetable_entry
));
458 /* Save the vital information from when starting to read a file,
459 for use when closing off the current file.
460 NAME is the file name the symbols came from, START_ADDR is the first
461 text address for the file, and SIZE is the number of bytes of text. */
464 complete_symtab (name
, start_addr
, size
)
466 CORE_ADDR start_addr
;
469 last_source_file
= savestring (name
, strlen (name
));
470 cur_src_start_addr
= start_addr
;
471 cur_src_end_addr
= start_addr
+ size
;
473 if (entry_point
< cur_src_end_addr
474 && entry_point
>= cur_src_start_addr
)
476 startup_file_start
= cur_src_start_addr
;
477 startup_file_end
= cur_src_end_addr
;
481 /* Finish the symbol definitions for one main source file,
482 close off all the lexical contexts for that file
483 (creating struct block's for them), then make the
484 struct symtab for that file and put it in the list of all such. */
489 register struct symtab
*symtab
;
490 register struct context_stack
*cstk
;
491 register struct blockvector
*blockvector
;
492 register struct linetable
*lv
;
494 /* Finish the lexical context of the last function in the file. */
498 cstk
= context_stack
;
500 /* Make a block for the local symbols within. */
501 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
502 cstk
->start_addr
, cur_src_end_addr
);
506 /* Ignore a file that has no functions with real debugging info. */
507 if (pending_blocks
== 0 && file_symbols
== 0 && global_symbols
== 0)
511 line_vector_length
= -1;
512 last_source_file
= 0;
516 /* Create the two top-level blocks for this file (STATIC_BLOCK and
518 finish_block (0, &file_symbols
, 0, cur_src_start_addr
, cur_src_end_addr
);
519 finish_block (0, &global_symbols
, 0, cur_src_start_addr
, cur_src_end_addr
);
521 /* Create the blockvector that points to all the file's blocks. */
522 blockvector
= make_blockvector ();
524 /* Now create the symtab object for this source file. */
525 symtab
= (struct symtab
*) xmalloc (sizeof (struct symtab
));
526 symtab
->free_ptr
= 0;
528 /* Fill in its components. */
529 symtab
->blockvector
= blockvector
;
530 symtab
->free_code
= free_linetable
;
531 symtab
->filename
= last_source_file
;
532 symtab
->dirname
= NULL
;
534 lv
->nitems
= line_vector_index
;
535 symtab
->linetable
= (struct linetable
*)
536 xrealloc (lv
, (sizeof (struct linetable
)
537 + lv
->nitems
* sizeof (struct linetable_entry
)));
539 symtab
->line_charpos
= 0;
541 symtab
->language
= language_unknown
;
542 symtab
->fullname
= NULL
;
545 symtab
->coffsem
= last_coffsem
;
547 /* This isn't used currently. Besides, if this is really about "syntax",
548 it shouldn't need to stick around past symbol read-in time. */
549 symtab
->coffsyn
= last_coffsyn
;
553 free_named_symtabs (symtab
->filename
);
555 /* Link the new symtab into the list of such. */
556 symtab
->next
= symtab_list
;
557 symtab_list
= symtab
;
559 /* Reinitialize for beginning of new file. */
561 line_vector_length
= -1;
562 last_source_file
= 0;
566 record_misc_function (name
, address
)
571 /* We don't want TDESC entry points on the misc_function_vector */
572 if (name
[0] == '@') return;
574 /* mf_text isn't true, but apparently COFF doesn't tell us what it really
575 is, so this guess is more useful than mf_unknown. */
576 prim_record_misc_function (savestring (name
, strlen (name
)),
581 /* coff_symfile_init ()
582 is the coff-specific initialization routine for reading symbols.
583 It is passed a struct sym_fns which contains, among other things,
584 the BFD for the file whose symbols are being read, and a slot for
585 a pointer to "private data" which we fill with cookies and other
586 treats for coff_symfile_read ().
588 We will only be called if this is a COFF or COFF-like file.
589 BFD handles figuring out the format of the file, and code in symtab.c
590 uses BFD's determination to vector to us.
592 The ultimate result is a new symtab (or, FIXME, eventually a psymtab). */
594 struct coff_symfile_info
{
595 file_ptr min_lineno_offset
; /* Where in file lowest line#s are */
596 file_ptr max_lineno_offset
; /* 1+last byte of line#s in file */
600 coff_symfile_init (sf
)
603 bfd
*abfd
= sf
->sym_bfd
;
605 /* Allocate struct to keep track of the symfile */
606 /* FIXME memory leak */
607 sf
->sym_private
= xmalloc (sizeof (struct coff_symfile_info
));
610 safe_to_init_tdesc_context
= 0;
613 /* Save startup file's range of PC addresses to help blockframe.c
614 decide where the bottom of the stack is. */
615 if (bfd_get_file_flags (abfd
) & EXEC_P
)
617 /* Executable file -- record its entry point so we'll recognize
618 the startup file because it contains the entry point. */
619 entry_point
= bfd_get_start_address (abfd
);
623 /* Examination of non-executable.o files. Short-circuit this stuff. */
624 /* ~0 will not be in any file, we hope. */
626 /* set the startup file to be an empty range. */
627 startup_file_start
= 0;
628 startup_file_end
= 0;
632 /* This function is called for every section; it finds the outer limits
633 of the line table (minimum and maximum file offset) so that the
634 mainline code can read the whole thing for efficiency. */
638 find_linenos (abfd
, asect
, vpinfo
)
643 struct coff_symfile_info
*info
;
645 file_ptr offset
, maxoff
;
647 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
648 count
= asect
->lineno_count
;
653 #if !defined (LINESZ)
654 /* Just in case, you never know what to expect from those
655 COFF header files. */
656 #define LINESZ (sizeof (struct lineno))
657 #endif /* No LINESZ. */
658 size
= count
* LINESZ
;
660 info
= (struct coff_symfile_info
*)vpinfo
;
661 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
662 offset
= asect
->line_filepos
;
665 if (offset
< info
->min_lineno_offset
|| info
->min_lineno_offset
== 0)
666 info
->min_lineno_offset
= offset
;
668 maxoff
= offset
+ size
;
669 if (maxoff
> info
->max_lineno_offset
)
670 info
->max_lineno_offset
= maxoff
;
672 /* While we're at it, find the debug_info. It's in the s_relptr
673 (or, in BFD-speak, rel_filepos) of the text segment section header. */
674 if (strcmp (bfd_section_name (abfd
, asect
), ".text") == 0)
676 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
677 debug_info
= asect
->rel_filepos
;
681 dc_terminate (tdesc_handle
);
689 /* The BFD for this file -- only good while we're actively reading
690 symbols into a psymtab or a symtab. */
692 static bfd
*symfile_bfd
;
694 /* Read a symbol file, after initialization by coff_symfile_init. */
695 /* FIXME! Addr and Mainline are not used yet -- this will not work for
696 shared libraries or add_file! */
699 coff_symfile_read (sf
, addr
, mainline
)
704 struct coff_symfile_info
*info
= (struct coff_symfile_info
*)sf
->sym_private
;
705 bfd
*abfd
= sf
->sym_bfd
;
706 char *name
= bfd_get_filename (abfd
);
711 int stringtab_offset
;
713 symfile_bfd
= abfd
; /* Kludge for swap routines */
715 /* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
716 desc
= fileno ((FILE *)(abfd
->iostream
)); /* File descriptor */
717 num_symbols
= bfd_get_symcount (abfd
); /* How many syms */
718 symtab_offset
= obj_sym_filepos (abfd
); /* Symbol table file offset */
719 stringtab_offset
= symtab_offset
+ num_symbols
* SYMESZ
; /* String tab */
722 /* Read the line number table, all at once. */
723 info
->min_lineno_offset
= 0;
724 info
->max_lineno_offset
= 0;
725 bfd_map_over_sections (abfd
, find_linenos
, info
);
727 val
= init_lineno (desc
, info
->min_lineno_offset
,
728 info
->max_lineno_offset
- info
->min_lineno_offset
);
730 error ("\"%s\": error reading line numbers\n", name
);
732 /* Now read the string table, all at once. */
734 val
= init_stringtab (desc
, stringtab_offset
);
737 free_all_symtabs (); /* FIXME blows whole symtab */
738 printf ("\"%s\": can't get string table", name
);
742 make_cleanup (free_stringtab
, 0);
744 /* Position to read the symbol table. Do not read it all at once. */
745 val
= lseek (desc
, (long)symtab_offset
, 0);
747 perror_with_name (name
);
749 init_misc_bunches ();
750 make_cleanup (discard_misc_bunches
, 0);
752 /* Now that the executable file is positioned at symbol table,
753 process it and define symbols accordingly. */
755 read_coff_symtab (desc
, num_symbols
);
757 patch_opaque_types ();
759 /* Sort symbols alphabetically within each block. */
761 sort_all_symtab_syms ();
763 /* Go over the misc symbol bunches and install them in vector. */
765 condense_misc_bunches (0);
767 /* Make a default for file to list. */
769 select_source_symtab (0); /* FIXME, this might be too slow, see dbxread */
773 coff_symfile_discard ()
775 /* There seems to be nothing to do here. */
781 /* There seems to be nothing to do except free_all_symtabs and set
782 symfile to zero, which is done by our caller. */
785 /* Simplified internal version of coff symbol table information */
789 int c_symnum
; /* symbol number of this entry */
790 int c_nsyms
; /* 1 if syment only, 2 if syment + auxent, etc */
797 /* Given pointers to a symbol table in coff style exec file,
798 analyze them and create struct symtab's describing the symbols.
799 NSYMS is the number of symbols in the symbol table.
800 We read them one at a time using read_one_sym (). */
803 read_coff_symtab (desc
, nsyms
)
807 int newfd
; /* Avoid multiple closes on same desc */
809 register struct context_stack
*new;
810 struct coff_symbol coff_symbol
;
811 register struct coff_symbol
*cs
= &coff_symbol
;
812 static SYMENT main_sym
;
813 static AUXENT main_aux
;
814 struct coff_symbol fcn_cs_saved
;
815 static SYMENT fcn_sym_saved
;
816 static AUXENT fcn_aux_saved
;
818 /* A .file is open. */
819 int in_source_file
= 0;
820 int num_object_files
= 0;
821 int next_file_symnum
= -1;
823 /* Name of the current file. */
824 char *filestring
= "";
830 struct cleanup
*old_chain
;
835 fatal ("Too many open files");
836 stream
= fdopen (newfd
, "r");
838 old_chain
= make_cleanup (free_all_symtabs
, 0);
839 make_cleanup (fclose
, stream
);
840 nlist_stream_global
= stream
;
841 nlist_nsyms_global
= nsyms
;
842 last_source_file
= 0;
843 bzero (opaque_type_chain
, sizeof opaque_type_chain
);
845 type_vector_length
= 160;
846 type_vector
= (struct typevector
*)
847 xmalloc (sizeof (struct typevector
)
848 + type_vector_length
* sizeof (struct type
*));
849 bzero (type_vector
->type
, type_vector_length
* sizeof (struct type
*));
854 while (symnum
< nsyms
)
856 QUIT
; /* Make this command interruptable. */
857 read_one_sym (cs
, &main_sym
, &main_aux
);
860 temp_sem_val
= cs
->c_name
[0] << 24 | cs
->c_name
[1] << 16 |
861 cs
->c_name
[2] << 8 | cs
->c_name
[3];
862 if (int_sem_val
== temp_sem_val
)
863 last_coffsem
= (int) strtol (cs
->c_name
+4, (char **) NULL
, 10);
866 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
868 if (last_source_file
)
872 complete_symtab ("_globals_", 0, first_object_file_end
);
873 /* done with all files, everything from here on out is globals */
876 /* Special case for file with type declarations only, no text. */
877 if (!last_source_file
&& SDB_TYPE (cs
->c_type
)
878 && cs
->c_secnum
== N_DEBUG
)
879 complete_symtab (filestring
, 0, 0);
881 /* Typedefs should not be treated as symbol definitions. */
882 if (ISFCN (cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
884 /* record as misc function. if we get '.bf' next,
885 * then we undo this step
887 record_misc_function (cs
->c_name
, cs
->c_value
);
889 fcn_line_ptr
= main_aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
890 fcn_start_addr
= cs
->c_value
;
892 fcn_sym_saved
= main_sym
;
893 fcn_aux_saved
= main_aux
;
897 switch (cs
->c_sclass
)
906 printf ("Bad n_sclass = %d\n", cs
->c_sclass
);
911 * c_value field contains symnum of next .file entry in table
912 * or symnum of first global after last .file.
914 next_file_symnum
= cs
->c_value
;
915 filestring
= getfilename (&main_aux
);
917 * Complete symbol table for last object file
918 * containing debugging information.
920 if (last_source_file
)
929 if (cs
->c_name
[0] == '.') {
930 if (strcmp (cs
->c_name
, _TEXT
) == 0) {
931 if (++num_object_files
== 1) {
932 /* last address of startup file */
933 first_object_file_end
= cs
->c_value
+
934 main_aux
.x_scn
.x_scnlen
;
936 /* Check for in_source_file deals with case of
937 a file with debugging symbols
938 followed by a later file with no symbols. */
940 complete_symtab (filestring
, cs
->c_value
,
941 main_aux
.x_scn
.x_scnlen
);
944 /* flush rest of '.' symbols */
947 else if (!SDB_TYPE (cs
->c_type
)
948 && cs
->c_name
[0] == 'L'
949 && (strncmp (cs
->c_name
, "LI%", 3) == 0
950 || strncmp (cs
->c_name
, "LF%", 3) == 0
951 || strncmp (cs
->c_name
,"LC%",3) == 0
952 || strncmp (cs
->c_name
,"LP%",3) == 0
953 || strncmp (cs
->c_name
,"LPB%",4) == 0
954 || strncmp (cs
->c_name
,"LBB%",4) == 0
955 || strncmp (cs
->c_name
,"LBE%",4) == 0
956 || strncmp (cs
->c_name
,"LPBX%",5) == 0))
957 /* At least on a 3b1, gcc generates swbeg and string labels
958 that look like this. Ignore them. */
960 /* fall in for static symbols that don't start with '.' */
962 if (cs
->c_sclass
== C_EXT
&&
963 cs
->c_secnum
== N_ABS
&&
964 strcmp (cs
->c_name
, _ETEXT
) == 0)
965 end_of_text_addr
= cs
->c_value
;
966 if (!SDB_TYPE (cs
->c_type
)) {
967 if (cs
->c_secnum
<= 1) { /* text or abs */
968 record_misc_function (cs
->c_name
, cs
->c_value
);
974 (void) process_coff_symbol (cs
, &main_aux
);
978 if (strcmp (cs
->c_name
, ".bf") == 0)
982 /* value contains address of first non-init type code */
983 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
984 contains line number of '{' } */
985 fcn_first_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
987 new = (struct context_stack
*)
988 xmalloc (sizeof (struct context_stack
));
989 new->depth
= depth
= 0;
993 new->old_blocks
= pending_blocks
;
994 new->start_addr
= fcn_start_addr
;
995 fcn_cs_saved
.c_name
= getsymname (&fcn_sym_saved
);
996 new->name
= process_coff_symbol (&fcn_cs_saved
,
999 else if (strcmp (cs
->c_name
, ".ef") == 0)
1001 /* the value of .ef is the address of epilogue code;
1002 * not useful for gdb
1004 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1005 contains number of lines to '}' */
1006 new = context_stack
;
1009 complain (&ef_complaint
, cs
->c_symnum
);
1010 within_function
= 0;
1013 fcn_last_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
1014 enter_linenos (fcn_line_ptr
, fcn_first_line
, fcn_last_line
);
1016 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1018 #if defined (FUNCTION_EPILOGUE_SIZE)
1019 /* This macro should be defined only on
1021 fcn_aux_saved.x_sym.x_misc.x_fsize
1022 field is always zero.
1023 So use the .bf record information that
1024 points to the epilogue and add the size
1026 cs
->c_value
+ FUNCTION_EPILOGUE_SIZE
1028 fcn_cs_saved
.c_value
+
1029 fcn_aux_saved
.x_sym
.x_misc
.x_fsize
1033 within_function
= 0;
1039 if (strcmp (cs
->c_name
, ".bb") == 0)
1041 new = (struct context_stack
*)
1042 xmalloc (sizeof (struct context_stack
));
1045 new->next
= context_stack
;
1046 context_stack
= new;
1047 new->locals
= local_symbols
;
1048 new->old_blocks
= pending_blocks
;
1049 new->start_addr
= cs
->c_value
;
1053 else if (strcmp (cs
->c_name
, ".eb") == 0)
1055 new = context_stack
;
1056 if (new == 0 || depth
!= new->depth
)
1057 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1059 if (local_symbols
&& context_stack
->next
)
1061 /* Make a block for the local symbols within. */
1062 finish_block (0, &local_symbols
, new->old_blocks
,
1063 new->start_addr
, cs
->c_value
);
1066 local_symbols
= new->locals
;
1067 context_stack
= new->next
;
1074 /* This isn't used currently. */
1075 if (strcmp (cs
->c_name
, ".coffsyn") == 0)
1076 last_coffsyn
= cs
->c_value
;
1079 if ((strcmp (cs
->c_name
, ".coffsem") == 0) &&
1081 last_coffsem
= cs
->c_value
;
1087 if ((strcmp (cs
->c_name
, ".coffsem") == 0) &&
1089 last_coffsem
= cs
->c_value
;
1092 (void) process_coff_symbol (cs
, &main_aux
);
1097 if (last_source_file
)
1100 discard_cleanups (old_chain
);
1103 /* Routines for reading headers and symbols from executable. */
1106 /* Move these XXXMAGIC symbol defns into BFD! */
1108 /* Read COFF file header, check magic number,
1109 and return number of symbols. */
1110 read_file_hdr (chan
, file_hdr
)
1114 lseek (chan
, 0L, 0);
1115 if (myread (chan
, (char *)file_hdr
, FILHSZ
) < 0)
1118 switch (file_hdr
->f_magic
)
1133 #if defined (MC68KWRMAGIC) \
1134 && (!defined (MC68MAGIC) || MC68KWRMAGIC != MC68MAGIC)
1148 case I960ROMAGIC
: /* Intel 960 */
1151 case I960RWMAGIC
: /* Intel 960 */
1153 return file_hdr
->f_nsyms
;
1157 if (BADMAG(file_hdr
))
1160 return file_hdr
->f_nsyms
;
1170 read_one_sym (cs
, sym
, aux
)
1171 register struct coff_symbol
*cs
;
1172 register SYMENT
*sym
;
1173 register AUXENT
*aux
;
1178 cs
->c_symnum
= symnum
;
1179 fread ((char *)sym
, SYMESZ
, 1, nlist_stream_global
);
1180 bfd_coff_swap_sym (symfile_bfd
, sym
);
1181 cs
->c_nsyms
= (sym
->n_numaux
& 0xff) + 1;
1182 if (cs
->c_nsyms
>= 2)
1184 fread ((char *)aux
, AUXESZ
, 1, nlist_stream_global
);
1185 bfd_coff_swap_aux (symfile_bfd
, aux
, sym
->n_type
, sym
->n_sclass
);
1186 /* If more than one aux entry, read past it (only the first aux
1188 for (i
= 2; i
< cs
->c_nsyms
; i
++)
1189 fread ((char *)&temp_aux
, AUXESZ
, 1, nlist_stream_global
);
1191 cs
->c_name
= getsymname (sym
);
1192 cs
->c_value
= sym
->n_value
;
1193 cs
->c_sclass
= (sym
->n_sclass
& 0xff);
1194 cs
->c_secnum
= sym
->n_scnum
;
1195 cs
->c_type
= (unsigned) sym
->n_type
;
1196 if (!SDB_TYPE (cs
->c_type
))
1199 symnum
+= cs
->c_nsyms
;
1202 /* Support for string table handling */
1204 static char *stringtab
= NULL
;
1207 init_stringtab (chan
, offset
)
1213 unsigned char lengthbuf
[4];
1221 if (lseek (chan
, offset
, 0) < 0)
1224 val
= myread (chan
, (char *)lengthbuf
, sizeof lengthbuf
);
1225 length
= bfd_h_getlong (symfile_bfd
, lengthbuf
);
1227 /* If no string table is needed, then the file may end immediately
1228 after the symbols. Just return with `stringtab' set to null. */
1229 if (val
!= sizeof length
|| length
< sizeof length
)
1232 stringtab
= (char *) xmalloc (length
);
1233 if (stringtab
== NULL
)
1236 bcopy (&length
, stringtab
, sizeof length
);
1237 if (length
== sizeof length
) /* Empty table -- just the count */
1240 val
= myread (chan
, stringtab
+ sizeof length
, length
- sizeof length
);
1241 if (val
!= length
- sizeof length
|| stringtab
[length
- 1] != '\0')
1256 getsymname (symbol_entry
)
1257 SYMENT
*symbol_entry
;
1259 static char buffer
[SYMNMLEN
+1];
1262 if (symbol_entry
->n_zeroes
== 0)
1264 result
= stringtab
+ symbol_entry
->n_offset
;
1268 strncpy (buffer
, symbol_entry
->n_name
, SYMNMLEN
);
1269 buffer
[SYMNMLEN
] = '\0';
1276 getfilename (aux_entry
)
1279 static char buffer
[BUFSIZ
];
1280 register char *temp
;
1282 extern char *rindex ();
1284 #ifndef COFF_NO_LONG_FILE_NAMES
1285 #if defined (x_zeroes)
1287 if (aux_entry
->x_zeroes
== 0)
1288 strcpy (buffer
, stringtab
+ aux_entry
->x_offset
);
1289 #else /* no x_zeroes */
1290 if (aux_entry
->x_file
.x_n
.x_zeroes
== 0)
1291 strcpy (buffer
, stringtab
+ aux_entry
->x_file
.x_n
.x_offset
);
1292 #endif /* no x_zeroes */
1294 #endif /* COFF_NO_LONG_FILE_NAMES */
1296 #if defined (x_name)
1298 strncpy (buffer
, aux_entry
->x_name
, FILNMLEN
);
1300 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1302 buffer
[FILNMLEN
] = '\0';
1305 if ((temp
= rindex (result
, '/')) != NULL
)
1310 /* Support for line number handling */
1311 static char *linetab
= NULL
;
1312 static long linetab_offset
;
1313 static unsigned long linetab_size
;
1315 /* Read in all the line numbers for fast lookups later. */
1318 init_lineno (chan
, offset
, size
)
1324 register char *p
, *q
;
1326 if (lseek (chan
, offset
, 0) < 0)
1329 linetab
= (char *) xmalloc (size
);
1331 val
= myread (chan
, linetab
, size
);
1335 /* Swap all entries */
1337 for (p
= linetab
; p
< q
; p
+= LINESZ
)
1338 bfd_coff_swap_lineno (symfile_bfd
, (LINENO
*)p
);
1340 linetab_offset
= offset
;
1341 linetab_size
= size
;
1342 make_cleanup (free
, linetab
); /* Be sure it gets de-allocated. */
1346 #if !defined (L_LNNO32)
1347 #define L_LNNO32(lp) ((lp)->l_lnno)
1351 enter_linenos (file_offset
, first_line
, last_line
)
1353 register int first_line
;
1354 register int last_line
;
1356 register char *rawptr
;
1359 if (file_offset
< linetab_offset
)
1361 complain (&lineno_complaint
, file_offset
);
1362 if (file_offset
> linetab_size
) /* Too big to be an offset? */
1364 file_offset
+= linetab_offset
; /* Try reading at that linetab offset */
1367 rawptr
= &linetab
[file_offset
- linetab_offset
];
1369 /* skip first line entry for each function */
1371 /* line numbers start at one for the first line of the function */
1374 /* Bcopy since occaisionally rawptr isn't pointing at long
1376 for (bcopy (rawptr
, &lptr
, LINESZ
);
1377 L_LNNO32 (&lptr
) && L_LNNO32 (&lptr
) <= last_line
;
1378 rawptr
+= LINESZ
, bcopy (rawptr
, &lptr
, LINESZ
))
1380 record_line (first_line
+ L_LNNO32 (&lptr
), lptr
.l_addr
.l_paddr
);
1388 register char *p
= name
;
1389 register int total
= p
[0];
1402 return total
% HASHSIZE
;
1406 patch_type (type
, real_type
)
1408 struct type
*real_type
;
1410 register struct type
*target
= TYPE_TARGET_TYPE (type
);
1411 register struct type
*real_target
= TYPE_TARGET_TYPE (real_type
);
1412 int field_size
= TYPE_NFIELDS (real_target
) * sizeof (struct field
);
1414 TYPE_LENGTH (target
) = TYPE_LENGTH (real_target
);
1415 TYPE_NFIELDS (target
) = TYPE_NFIELDS (real_target
);
1416 TYPE_FIELDS (target
) = (struct field
*)
1417 obstack_alloc (symbol_obstack
, field_size
);
1419 bcopy (TYPE_FIELDS (real_target
), TYPE_FIELDS (target
), field_size
);
1421 if (TYPE_NAME (real_target
))
1423 if (TYPE_NAME (target
))
1424 free (TYPE_NAME (target
));
1425 TYPE_NAME (target
) = concat (TYPE_NAME (real_target
), "", "");
1429 /* Patch up all appropriate typdef symbols in the opaque_type_chains
1430 so that they can be used to print out opaque data structures properly */
1433 patch_opaque_types ()
1437 /* Look at each symbol in the per-file block of each symtab. */
1438 for (s
= symtab_list
; s
; s
= s
->next
)
1440 register struct block
*b
;
1443 /* Go through the per-file symbols only */
1444 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
1445 for (i
= BLOCK_NSYMS (b
) - 1; i
>= 0; i
--)
1447 register struct symbol
*real_sym
;
1449 /* Find completed typedefs to use to fix opaque ones.
1450 Remove syms from the chain when their types are stored,
1451 but search the whole chain, as there may be several syms
1452 from different files with the same name. */
1453 real_sym
= BLOCK_SYM (b
, i
);
1454 if (SYMBOL_CLASS (real_sym
) == LOC_TYPEDEF
&&
1455 SYMBOL_NAMESPACE (real_sym
) == VAR_NAMESPACE
&&
1456 TYPE_CODE (SYMBOL_TYPE (real_sym
)) == TYPE_CODE_PTR
&&
1457 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym
))) != 0)
1459 register char *name
= SYMBOL_NAME (real_sym
);
1460 register int hash
= hashname (name
);
1461 register struct symbol
*sym
, *prev
;
1464 for (sym
= opaque_type_chain
[hash
]; sym
;)
1466 if (name
[0] == SYMBOL_NAME (sym
)[0] &&
1467 !strcmp (name
+ 1, SYMBOL_NAME (sym
) + 1))
1470 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
1472 opaque_type_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
1474 patch_type (SYMBOL_TYPE (sym
), SYMBOL_TYPE (real_sym
));
1477 sym
= SYMBOL_VALUE_CHAIN (prev
);
1479 sym
= opaque_type_chain
[hash
];
1484 sym
= SYMBOL_VALUE_CHAIN (sym
);
1492 #if defined (clipper)
1493 #define BELIEVE_PCC_PROMOTION 1
1496 static struct symbol
*
1497 process_coff_symbol (cs
, aux
)
1498 register struct coff_symbol
*cs
;
1499 register AUXENT
*aux
;
1501 register struct symbol
*sym
1502 = (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
1504 #ifdef NAMES_HAVE_UNDERSCORE
1510 bzero (sym
, sizeof (struct symbol
));
1512 name
= (name
[0] == '_' ? name
+ offset
: name
);
1513 SYMBOL_NAME (sym
) = obstack_copy0 (symbol_obstack
, name
, strlen (name
));
1515 /* default assumptions */
1516 SYMBOL_VALUE (sym
) = cs
->c_value
;
1517 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1519 if (ISFCN (cs
->c_type
))
1522 lookup_function_type (decode_function_type (cs
, cs
->c_type
, aux
));
1523 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1524 if (cs
->c_sclass
== C_STAT
)
1525 add_symbol_to_list (sym
, &file_symbols
);
1526 else if (cs
->c_sclass
== C_EXT
)
1527 add_symbol_to_list (sym
, &global_symbols
);
1531 SYMBOL_TYPE (sym
) = decode_type (cs
, cs
->c_type
, aux
);
1532 switch (cs
->c_sclass
)
1538 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1539 add_symbol_to_list (sym
, &local_symbols
);
1543 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1544 SYMBOL_VALUE_ADDRESS (sym
) = (CORE_ADDR
) cs
->c_value
;
1545 add_symbol_to_list (sym
, &global_symbols
);
1549 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1550 SYMBOL_VALUE_ADDRESS (sym
) = (CORE_ADDR
) cs
->c_value
;
1551 if (within_function
) {
1552 /* Static symbol of local scope */
1553 add_symbol_to_list (sym
, &local_symbols
);
1556 /* Static symbol at top level of file */
1557 add_symbol_to_list (sym
, &file_symbols
);
1562 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1563 add_symbol_to_list (sym
, &local_symbols
);
1570 SYMBOL_CLASS (sym
) = LOC_ARG
;
1571 add_symbol_to_list (sym
, &local_symbols
);
1572 #if !defined (BELIEVE_PCC_PROMOTION)
1573 /* If PCC says a parameter is a short or a char,
1574 it is really an int. */
1575 if (SYMBOL_TYPE (sym
) == builtin_type_char
1576 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1577 SYMBOL_TYPE (sym
) = builtin_type_int
;
1578 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1579 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1580 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1585 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1586 add_symbol_to_list (sym
, &local_symbols
);
1587 #if !defined (BELIEVE_PCC_PROMOTION)
1588 /* If PCC says a parameter is a short or a char,
1589 it is really an int. */
1590 if (SYMBOL_TYPE (sym
) == builtin_type_char
1591 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1592 SYMBOL_TYPE (sym
) = builtin_type_int
;
1593 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1594 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1595 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1600 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1601 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1603 /* If type has no name, give it one */
1604 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1605 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1606 TYPE_NAME (SYMBOL_TYPE (sym
))
1607 = concat (SYMBOL_NAME (sym
), "", "");
1609 /* Keep track of any type which points to empty structured type,
1610 so it can be filled from a definition from another file */
1611 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
&&
1612 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym
))) == 0)
1614 register int i
= hashname (SYMBOL_NAME (sym
));
1616 SYMBOL_VALUE_CHAIN (sym
) = opaque_type_chain
[i
];
1617 opaque_type_chain
[i
] = sym
;
1619 add_symbol_to_list (sym
, &file_symbols
);
1625 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1626 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1627 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1628 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1629 TYPE_NAME (SYMBOL_TYPE (sym
))
1631 (cs
->c_sclass
== C_ENTAG
1633 : (cs
->c_sclass
== C_STRTAG
1634 ? "struct " : "union ")),
1636 add_symbol_to_list (sym
, &file_symbols
);
1646 /* Decode a coff type specifier;
1647 return the type that is meant. */
1651 decode_type (cs
, c_type
, aux
)
1652 register struct coff_symbol
*cs
;
1653 unsigned int c_type
;
1654 register AUXENT
*aux
;
1656 register struct type
*type
= 0;
1657 unsigned int new_c_type
;
1659 if (c_type
& ~N_BTMASK
)
1661 new_c_type
= DECREF (c_type
);
1664 type
= decode_type (cs
, new_c_type
, aux
);
1665 type
= lookup_pointer_type (type
);
1667 else if (ISFCN (c_type
))
1669 type
= decode_type (cs
, new_c_type
, aux
);
1670 type
= lookup_function_type (type
);
1672 else if (ISARY (c_type
))
1675 register unsigned short *dim
;
1676 struct type
*base_type
;
1678 /* Define an array type. */
1679 /* auxent refers to array, not base type */
1680 if (aux
->x_sym
.x_tagndx
== 0)
1683 /* shift the indices down */
1684 dim
= &aux
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0];
1687 for (i
= 0; *dim
&& i
< DIMNUM
- 1; i
++, dim
++)
1691 type
= (struct type
*)
1692 obstack_alloc (symbol_obstack
, sizeof (struct type
));
1693 bzero (type
, sizeof (struct type
));
1695 base_type
= decode_type (cs
, new_c_type
, aux
);
1697 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
1698 TYPE_TARGET_TYPE (type
) = base_type
;
1699 TYPE_LENGTH (type
) = n
* TYPE_LENGTH (base_type
);
1704 /* Reference to existing type */
1705 if (cs
->c_nsyms
> 1 && aux
->x_sym
.x_tagndx
!= 0)
1707 type
= coff_alloc_type (aux
->x_sym
.x_tagndx
);
1711 return decode_base_type (cs
, BTYPE (c_type
), aux
);
1714 /* Decode a coff type specifier for function definition;
1715 return the type that the function returns. */
1719 decode_function_type (cs
, c_type
, aux
)
1720 register struct coff_symbol
*cs
;
1721 unsigned int c_type
;
1722 register AUXENT
*aux
;
1724 if (aux
->x_sym
.x_tagndx
== 0)
1725 cs
->c_nsyms
= 1; /* auxent refers to function, not base type */
1727 return decode_type (cs
, DECREF (c_type
), aux
);
1734 decode_base_type (cs
, c_type
, aux
)
1735 register struct coff_symbol
*cs
;
1736 unsigned int c_type
;
1737 register AUXENT
*aux
;
1744 /* shows up with "void (*foo)();" structure members */
1745 return builtin_type_void
;
1748 /* DGUX actually defines both T_ARG and T_VOID to the same value. */
1751 /* Shows up in DGUX, I think. Not sure where. */
1752 return builtin_type_void
; /* shouldn't show up here */
1758 /* Intel 960 COFF has this symbol and meaning. */
1759 return builtin_type_void
;
1763 return builtin_type_char
;
1766 return builtin_type_short
;
1769 return builtin_type_int
;
1772 return builtin_type_long
;
1775 return builtin_type_float
;
1778 return builtin_type_double
;
1781 if (cs
->c_nsyms
!= 2)
1783 /* anonymous structure type */
1784 type
= coff_alloc_type (cs
->c_symnum
);
1785 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1786 TYPE_NAME (type
) = concat ("struct ", "<opaque>", "");
1787 TYPE_LENGTH (type
) = 0;
1788 TYPE_FIELDS (type
) = 0;
1789 TYPE_NFIELDS (type
) = 0;
1793 type
= read_struct_type (cs
->c_symnum
,
1794 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1795 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1800 if (cs
->c_nsyms
!= 2)
1802 /* anonymous union type */
1803 type
= coff_alloc_type (cs
->c_symnum
);
1804 TYPE_NAME (type
) = concat ("union ", "<opaque>", "");
1805 TYPE_LENGTH (type
) = 0;
1806 TYPE_FIELDS (type
) = 0;
1807 TYPE_NFIELDS (type
) = 0;
1811 type
= read_struct_type (cs
->c_symnum
,
1812 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1813 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1815 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1819 return read_enum_type (cs
->c_symnum
,
1820 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1821 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1824 /* shouldn't show up here */
1828 return builtin_type_unsigned_char
;
1831 return builtin_type_unsigned_short
;
1834 return builtin_type_unsigned_int
;
1837 return builtin_type_unsigned_long
;
1839 printf ("unexpected type %d at symnum %d\n", c_type
, cs
->c_symnum
);
1840 return builtin_type_void
;
1843 /* This page contains subroutines of read_type. */
1845 /* Read the description of a structure (or union type)
1846 and return an object describing the type. */
1848 static struct type
*
1849 read_struct_type (index
, length
, lastsym
)
1856 struct nextfield
*next
;
1860 register struct type
*type
;
1861 register struct nextfield
*list
= 0;
1862 struct nextfield
*new;
1866 #ifdef NAMES_HAVE_UNDERSCORE
1871 struct coff_symbol member_sym
;
1872 register struct coff_symbol
*ms
= &member_sym
;
1877 type
= coff_alloc_type (index
);
1878 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1879 TYPE_LENGTH (type
) = length
;
1881 while (!done
&& symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
1883 read_one_sym (ms
, &sub_sym
, &sub_aux
);
1885 name
= (name
[0] == '_' ? name
+ offset
: name
);
1887 switch (ms
->c_sclass
)
1892 /* Get space to record the next field's data. */
1893 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1897 /* Save the data. */
1898 list
->field
.name
= savestring (name
, strlen (name
));
1899 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1900 list
->field
.bitpos
= 8 * ms
->c_value
;
1901 list
->field
.bitsize
= 0;
1907 /* Get space to record the next field's data. */
1908 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1912 /* Save the data. */
1913 list
->field
.name
= savestring (name
, strlen (name
));
1914 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1915 list
->field
.bitpos
= ms
->c_value
;
1916 list
->field
.bitsize
= sub_aux
.x_sym
.x_misc
.x_lnsz
.x_size
;
1925 /* Now create the vector of fields, and record how big it is. */
1927 TYPE_NFIELDS (type
) = nfields
;
1928 TYPE_FIELDS (type
) = (struct field
*)
1929 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nfields
);
1931 /* Copy the saved-up fields into the field vector. */
1933 for (n
= nfields
; list
; list
= list
->next
)
1934 TYPE_FIELD (type
, --n
) = list
->field
;
1939 /* Read a definition of an enumeration type,
1940 and create and return a suitable type object.
1941 Also defines the symbols that represent the values of the type. */
1942 /* Currently assumes it's sizeof (int) and doesn't use length. */
1944 static struct type
*
1945 read_enum_type (index
, length
, lastsym
)
1950 register struct symbol
*sym
;
1951 register struct type
*type
;
1954 struct pending
**symlist
;
1955 struct coff_symbol member_sym
;
1956 register struct coff_symbol
*ms
= &member_sym
;
1959 struct pending
*osyms
, *syms
;
1962 #ifdef NAMES_HAVE_UNDERSCORE
1968 type
= coff_alloc_type (index
);
1969 if (within_function
)
1970 symlist
= &local_symbols
;
1972 symlist
= &file_symbols
;
1975 while (!done
&& symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
1977 read_one_sym (ms
, &sub_sym
, &sub_aux
);
1979 name
= (name
[0] == '_' ? name
+ offset
: name
);
1981 switch (ms
->c_sclass
)
1984 sym
= (struct symbol
*) xmalloc (sizeof (struct symbol
));
1985 bzero (sym
, sizeof (struct symbol
));
1987 SYMBOL_NAME (sym
) = savestring (name
, strlen (name
));
1988 SYMBOL_CLASS (sym
) = LOC_CONST
;
1989 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1990 SYMBOL_VALUE (sym
) = ms
->c_value
;
1991 add_symbol_to_list (sym
, symlist
);
1996 /* Sometimes the linker (on 386/ix 2.0.2 at least) screws
1997 up the count of how many symbols to read. So stop
2004 /* Now fill in the fields of the type-structure. */
2006 /* FIXME: Should be sizeof (int) on target, not host. */
2007 TYPE_LENGTH (type
) = sizeof (int);
2008 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2009 TYPE_NFIELDS (type
) = nsyms
;
2010 TYPE_FIELDS (type
) = (struct field
*)
2011 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nsyms
);
2013 /* Find the symbols for the values and put them into the type.
2014 The symbols can be found in the symlist that we put them on
2015 to cause them to be defined. osyms contains the old value
2016 of that symlist; everything up to there was defined by us. */
2018 for (syms
= *symlist
, n
= nsyms
; syms
!= osyms
; syms
= syms
->next
)
2020 SYMBOL_TYPE (syms
->symbol
) = type
;
2021 TYPE_FIELD_NAME (type
, --n
) = SYMBOL_NAME (syms
->symbol
);
2022 TYPE_FIELD_VALUE (type
, n
) = 0;
2023 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (syms
->symbol
);
2024 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2029 /* Register our ability to parse symbols for coff BFD files */
2031 static struct sym_fns coff_sym_fns
=
2033 /* This assumes that 88kbcs implies TDESC and TDESC implies 88kbcs.
2034 If that's not true, this can be relaxed, but if it is true,
2035 it will just cause users grief if we try to read the wrong kind
2039 #else /* not TDESC */
2041 #endif /* not TDESC */
2042 coff_new_init
, coff_symfile_init
,
2043 coff_symfile_read
, coff_symfile_discard
2047 _initialize_coffread ()
2049 add_symtab_fns(&coff_sym_fns
);