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, 1988, 1989 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. */
30 #include <sys/types.h>
36 #include <sys/param.h>
39 static void add_symbol_to_list ();
40 static void read_coff_symtab ();
41 static void patch_opaque_types ();
42 static struct type
*decode_function_type ();
43 static struct type
*decode_type ();
44 static struct type
*decode_base_type ();
45 static struct type
*read_enum_type ();
46 static struct type
*read_struct_type ();
47 static void finish_block ();
48 static struct blockvector
*make_blockvector ();
49 static struct symbol
*process_coff_symbol ();
50 static int init_stringtab ();
51 static void free_stringtab ();
52 static char *getfilename ();
53 static char *getsymname ();
54 static int init_lineno ();
55 static void enter_linenos ();
58 extern void free_all_symtabs ();
59 extern void free_all_psymtabs ();
62 /* Name of source file whose symbol data we are now processing.
63 This comes from a symbol named ".file". */
65 static char *last_source_file
;
67 /* Core address of start and end of text of current source file.
68 This comes from a ".text" symbol where x_nlinno > 0. */
70 static CORE_ADDR cur_src_start_addr
;
71 static CORE_ADDR cur_src_end_addr
;
73 /* Core address of the end of the first object file. */
74 static CORE_ADDR first_object_file_end
;
76 /* End of the text segment of the executable file,
77 as found in the symbol _etext. */
79 static CORE_ADDR end_of_text_addr
;
81 /* The addresses of the symbol table stream and number of symbols
82 of the object file we are reading (as copied into core). */
84 static FILE *nlist_stream_global
;
85 static int nlist_nsyms_global
;
87 /* The file, a.out and text section headers of the symbol file */
89 static FILHDR file_hdr
;
90 static SCNHDR text_hdr
;
91 static AOUTHDR aout_hdr
;
93 /* The index in the symbol table of the last coff symbol that was processed. */
97 /* Vector of types defined so far, indexed by their coff symnum. */
99 static struct typevector
*type_vector
;
101 /* Number of elements allocated for type_vector currently. */
103 static int type_vector_length
;
105 /* Vector of line number information. */
107 static struct linetable
*line_vector
;
109 /* Index of next entry to go in line_vector_index. */
111 static int line_vector_index
;
113 /* Last line number recorded in the line vector. */
115 static int prev_line_number
;
117 /* Number of elements allocated for line_vector currently. */
119 static int line_vector_length
;
121 /* Chain of typedefs of pointers to empty struct/union types.
122 They are chained thru the SYMBOL_VALUE. */
125 static struct symbol
*opaque_type_chain
[HASHSIZE
];
127 /* Record the symbols defined for each context in a list.
128 We don't create a struct block for the context until we
129 know how long to make it. */
133 struct pending
*next
;
134 struct symbol
*symbol
;
137 /* Here are the three lists that symbols are put on. */
139 struct pending
*file_symbols
; /* static at top level, and types */
141 struct pending
*global_symbols
; /* global functions and variables */
143 struct pending
*local_symbols
; /* everything local to lexical context */
145 /* List of unclosed lexical contexts
146 (that will become blocks, eventually). */
150 struct context_stack
*next
;
151 struct pending
*locals
;
152 struct pending_block
*old_blocks
;
154 CORE_ADDR start_addr
;
158 struct context_stack
*context_stack
;
160 /* Nonzero if within a function (so symbols should be local,
161 if nothing says specifically). */
165 /* List of blocks already made (lexical contexts already closed).
166 This is used at the end to make the blockvector. */
170 struct pending_block
*next
;
174 struct pending_block
*pending_blocks
;
176 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
177 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
179 /* File name symbols were loaded from. */
181 static char *symfile
;
183 /* Look up a coff type-number index. Return the address of the slot
184 where the type for that index is stored.
185 The type-number is in INDEX.
187 This can be used for finding the type associated with that index
188 or for associating a new type with the index. */
190 static struct type
**
191 coff_lookup_type (index
)
194 if (index
>= type_vector_length
)
196 int old_vector_length
= type_vector_length
;
198 type_vector_length
*= 2;
199 if (type_vector_length
< index
) {
200 type_vector_length
= index
* 2;
202 type_vector
= (struct typevector
*)
203 xrealloc (type_vector
, sizeof (struct typevector
)
204 + type_vector_length
* sizeof (struct type
*));
205 bzero (&type_vector
->type
[ old_vector_length
],
206 (type_vector_length
- old_vector_length
) * sizeof(struct type
*));
208 return &type_vector
->type
[index
];
211 /* Make sure there is a type allocated for type number index
212 and return the type object.
213 This can create an empty (zeroed) type object. */
216 coff_alloc_type (index
)
219 register struct type
**type_addr
= coff_lookup_type (index
);
220 register struct type
*type
= *type_addr
;
222 /* If we are referring to a type not known at all yet,
223 allocate an empty type for it.
224 We will fill it in later if we find out how. */
227 type
= (struct type
*) obstack_alloc (symbol_obstack
,
228 sizeof (struct type
));
229 bzero (type
, sizeof (struct type
));
235 /* maintain the lists of symbols and blocks */
237 /* Add a symbol to one of the lists of symbols. */
239 add_symbol_to_list (symbol
, listhead
)
240 struct symbol
*symbol
;
241 struct pending
**listhead
;
243 register struct pending
*link
244 = (struct pending
*) xmalloc (sizeof (struct pending
));
246 link
->next
= *listhead
;
247 link
->symbol
= symbol
;
251 /* Take one of the lists of symbols and make a block from it.
252 Put the block on the list of pending blocks. */
255 finish_block (symbol
, listhead
, old_blocks
, start
, end
)
256 struct symbol
*symbol
;
257 struct pending
**listhead
;
258 struct pending_block
*old_blocks
;
259 CORE_ADDR start
, end
;
261 register struct pending
*next
, *next1
;
262 register struct block
*block
;
263 register struct pending_block
*pblock
;
264 struct pending_block
*opblock
;
267 /* Count the length of the list of symbols. */
269 for (next
= *listhead
, i
= 0; next
; next
= next
->next
, i
++);
271 block
= (struct block
*)
272 obstack_alloc (symbol_obstack
, sizeof (struct block
) + (i
- 1) * sizeof (struct symbol
*));
274 /* Copy the symbols into the block. */
276 BLOCK_NSYMS (block
) = i
;
277 for (next
= *listhead
; next
; next
= next
->next
)
278 BLOCK_SYM (block
, --i
) = next
->symbol
;
280 BLOCK_START (block
) = start
;
281 BLOCK_END (block
) = end
;
282 BLOCK_SUPERBLOCK (block
) = 0; /* Filled in when containing block is made */
284 /* Put the block in as the value of the symbol that names it. */
288 SYMBOL_BLOCK_VALUE (symbol
) = block
;
289 BLOCK_FUNCTION (block
) = symbol
;
292 BLOCK_FUNCTION (block
) = 0;
294 /* Now free the links of the list, and empty the list. */
296 for (next
= *listhead
; next
; next
= next1
)
303 /* Install this block as the superblock
304 of all blocks made since the start of this scope
305 that don't have superblocks yet. */
308 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
310 if (BLOCK_SUPERBLOCK (pblock
->block
) == 0)
311 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
315 /* Record this block on the list of all blocks in the file.
316 Put it after opblock, or at the beginning if opblock is 0.
317 This puts the block in the list after all its subblocks. */
319 pblock
= (struct pending_block
*) xmalloc (sizeof (struct pending_block
));
320 pblock
->block
= block
;
323 pblock
->next
= opblock
->next
;
324 opblock
->next
= pblock
;
328 pblock
->next
= pending_blocks
;
329 pending_blocks
= pblock
;
333 static struct blockvector
*
336 register struct pending_block
*next
, *next1
;
337 register struct blockvector
*blockvector
;
340 /* Count the length of the list of blocks. */
342 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
344 blockvector
= (struct blockvector
*)
345 obstack_alloc (symbol_obstack
, sizeof (struct blockvector
) + (i
- 1) * sizeof (struct block
*));
347 /* Copy the blocks into the blockvector.
348 This is done in reverse order, which happens to put
349 the blocks into the proper order (ascending starting address).
350 finish_block has hair to insert each block into the list
351 after its subblocks in order to make sure this is true. */
353 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
354 for (next
= pending_blocks
; next
; next
= next
->next
)
355 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
357 /* Now free the links of the list, and empty the list. */
359 for (next
= pending_blocks
; next
; next
= next1
)
369 /* Manage the vector of line numbers. */
372 record_line (line
, pc
)
376 struct linetable_entry
*e
;
377 /* Make sure line vector is big enough. */
379 if (line_vector_index
+ 2 >= line_vector_length
)
381 line_vector_length
*= 2;
382 line_vector
= (struct linetable
*)
383 xrealloc (line_vector
, sizeof (struct linetable
)
384 + (line_vector_length
385 * sizeof (struct linetable_entry
)));
388 e
= line_vector
->item
+ line_vector_index
++;
389 e
->line
= line
; e
->pc
= pc
;
392 /* Start a new symtab for a new source file.
393 This is called when a COFF ".file" symbol is seen;
394 it indicates the start of data for one original source file. */
403 last_source_file
= 0;
405 /* Initialize the source file information for this file. */
407 line_vector_index
= 0;
408 line_vector_length
= 1000;
409 prev_line_number
= -2; /* Force first line number to be explicit */
410 line_vector
= (struct linetable
*)
411 xmalloc (sizeof (struct linetable
)
412 + line_vector_length
* sizeof (struct linetable_entry
));
415 /* Save the vital information for use when closing off the current file.
416 NAME is the file name the symbols came from, START_ADDR is the first
417 text address for the file, and SIZE is the number of bytes of text. */
420 complete_symtab (name
, start_addr
, size
)
422 CORE_ADDR start_addr
;
425 last_source_file
= savestring (name
, strlen (name
));
426 cur_src_start_addr
= start_addr
;
427 cur_src_end_addr
= start_addr
+ size
;
429 if (aout_hdr
.entry
< cur_src_end_addr
430 && aout_hdr
.entry
>= cur_src_start_addr
)
432 startup_file_start
= cur_src_start_addr
;
433 startup_file_end
= cur_src_end_addr
;
437 /* Finish the symbol definitions for one main source file,
438 close off all the lexical contexts for that file
439 (creating struct block's for them), then make the
440 struct symtab for that file and put it in the list of all such. */
445 register struct symtab
*symtab
;
446 register struct context_stack
*cstk
;
447 register struct blockvector
*blockvector
;
448 register struct linetable
*lv
;
450 /* Finish the lexical context of the last function in the file. */
454 cstk
= context_stack
;
456 /* Make a block for the local symbols within. */
457 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
458 cstk
->start_addr
, cur_src_end_addr
);
462 /* Ignore a file that has no functions with real debugging info. */
463 if (pending_blocks
== 0 && file_symbols
== 0 && global_symbols
== 0)
467 line_vector_length
= -1;
468 last_source_file
= 0;
472 /* Create the two top-level blocks for this file. */
473 finish_block (0, &file_symbols
, 0, cur_src_start_addr
, cur_src_end_addr
);
474 finish_block (0, &global_symbols
, 0, cur_src_start_addr
, cur_src_end_addr
);
476 /* Create the blockvector that points to all the file's blocks. */
477 blockvector
= make_blockvector ();
479 /* Now create the symtab object for this source file. */
480 symtab
= (struct symtab
*) xmalloc (sizeof (struct symtab
));
481 symtab
->free_ptr
= 0;
483 /* Fill in its components. */
484 symtab
->blockvector
= blockvector
;
485 symtab
->free_code
= free_linetable
;
486 symtab
->filename
= last_source_file
;
488 lv
->nitems
= line_vector_index
;
489 symtab
->linetable
= (struct linetable
*)
490 xrealloc (lv
, (sizeof (struct linetable
)
491 + lv
->nitems
* sizeof (struct linetable_entry
)));
493 symtab
->line_charpos
= 0;
495 /* Link the new symtab into the list of such. */
496 symtab
->next
= symtab_list
;
497 symtab_list
= symtab
;
499 /* Reinitialize for beginning of new file. */
501 line_vector_length
= -1;
502 last_source_file
= 0;
505 /* Accumulate the misc functions in bunches of 127.
506 At the end, copy them all into one newly allocated structure. */
508 #define MISC_BUNCH_SIZE 127
512 struct misc_bunch
*next
;
513 struct misc_function contents
[MISC_BUNCH_SIZE
];
516 /* Bunch currently being filled up.
517 The next field points to chain of filled bunches. */
519 static struct misc_bunch
*misc_bunch
;
521 /* Number of slots filled in current bunch. */
523 static int misc_bunch_index
;
525 /* Total number of misc functions recorded so far. */
527 static int misc_count
;
530 init_misc_functions ()
534 misc_bunch_index
= MISC_BUNCH_SIZE
;
538 record_misc_function (name
, address
)
542 register struct misc_bunch
*new;
544 if (misc_bunch_index
== MISC_BUNCH_SIZE
)
546 new = (struct misc_bunch
*) xmalloc (sizeof (struct misc_bunch
));
547 misc_bunch_index
= 0;
548 new->next
= misc_bunch
;
551 misc_bunch
->contents
[misc_bunch_index
].name
= savestring (name
, strlen (name
));
552 misc_bunch
->contents
[misc_bunch_index
].address
= address
;
553 misc_bunch
->contents
[misc_bunch_index
].type
= mf_unknown
;
558 /* if we see a function symbol, we do record_misc_function.
559 * however, if it turns out the next symbol is '.bf', then
560 * we call here to undo the misc definition
563 unrecord_misc_function ()
565 if (misc_bunch_index
== 0)
566 error ("Internal error processing symbol table, at symbol %d.",
574 compare_misc_functions (fn1
, fn2
)
575 struct misc_function
*fn1
, *fn2
;
577 /* Return a signed result based on unsigned comparisons
578 so that we sort into unsigned numeric order. */
579 if (fn1
->address
< fn2
->address
)
581 if (fn1
->address
> fn2
->address
)
587 discard_misc_bunches ()
589 register struct misc_bunch
*next
;
593 next
= misc_bunch
->next
;
600 condense_misc_bunches ()
603 register struct misc_bunch
*bunch
;
604 #ifdef NAMES_HAVE_UNDERSCORE
611 = (struct misc_function
*)
612 xmalloc (misc_count
* sizeof (struct misc_function
));
618 for (i
= 0; i
< misc_bunch_index
; i
++)
622 misc_function_vector
[j
] = bunch
->contents
[i
];
623 tmp
= misc_function_vector
[j
].name
;
624 misc_function_vector
[j
].name
= (tmp
[0] == '_' ? tmp
+ offset
: tmp
);
628 misc_bunch_index
= MISC_BUNCH_SIZE
;
631 misc_function_count
= j
;
633 /* Sort the misc functions by address. */
635 qsort (misc_function_vector
, j
, sizeof (struct misc_function
),
636 compare_misc_functions
);
639 /* Call sort_syms to sort alphabetically
640 the symbols of each block of each symtab. */
643 compare_symbols (s1
, s2
)
644 struct symbol
**s1
, **s2
;
646 /* Names that are less should come first. */
647 register int namediff
= strcmp (SYMBOL_NAME (*s1
), SYMBOL_NAME (*s2
));
648 if (namediff
!= 0) return namediff
;
649 /* For symbols of the same name, registers should come first. */
650 return ((SYMBOL_CLASS (*s2
) == LOC_REGISTER
)
651 - (SYMBOL_CLASS (*s1
) == LOC_REGISTER
));
657 register struct symtab
*s
;
659 register struct blockvector
*bv
;
660 register struct block
*b
;
662 for (s
= symtab_list
; s
; s
= s
->next
)
664 bv
= BLOCKVECTOR (s
);
665 nbl
= BLOCKVECTOR_NBLOCKS (bv
);
666 for (i
= 0; i
< nbl
; i
++)
668 b
= BLOCKVECTOR_BLOCK (bv
, i
);
669 if (BLOCK_SHOULD_SORT (b
))
670 qsort (&BLOCK_SYM (b
, 0), BLOCK_NSYMS (b
),
671 sizeof (struct symbol
*), compare_symbols
);
676 /* This is the symbol-file command. Read the file, analyze its symbols,
677 and add a struct symtab to symtab_list. */
680 symbol_file_command (name
)
687 extern void close ();
689 struct cleanup
*old_chain
;
695 if (symtab_list
&& !query ("Discard symbol table? ", 0))
696 error ("Not confirmed.");
704 name
= tilde_expand (name
);
705 make_cleanup (free
, name
);
707 if (symtab_list
&& !query ("Load new symbol table from \"%s\"? ", name
))
708 error ("Not confirmed.");
717 desc
= openp (getenv ("PATH"), 1, name
, O_RDONLY
, 0, &absolute_name
);
719 perror_with_name (name
);
721 name
= absolute_name
;
724 old_chain
= make_cleanup (close
, desc
);
725 make_cleanup (free_current_contents
, &name
);
727 if ((num_symbols
= read_file_hdr (desc
, &file_hdr
)) < 0)
728 error ("File \"%s\" not in executable format.", name
);
730 /* If an a.out header is present, read it in. If not (e.g. a .o file)
731 deal with its absence. */
732 if (file_hdr
.f_opthdr
== 0
733 || read_aout_hdr (desc
, &aout_hdr
, file_hdr
.f_opthdr
) < 0)
735 /* We will not actually be able to run code, since backtraces would
736 fly off the bottom of the stack (there is no way to reliably
737 detect bottom of stack), but that's fine since the kernel won't
738 run something without an a.out header anyway. Passive examination
739 of .o files is one place this might make sense. */
740 /* ~0 will not be in any file. */
742 /* set the startup file to be an empty range. */
743 startup_file_start
= 0;
744 startup_file_end
= 0;
747 if (num_symbols
== 0)
750 error ("%s does not have a symbol-table.\n", name
);
753 printf ("Reading symbol data from %s...", name
);
756 /* Throw away the old symbol table. */
759 free_all_psymtabs (); /* Make sure that partial_symtab_list */
762 num_sections
= file_hdr
.f_nscns
;
763 symtab_offset
= file_hdr
.f_symptr
;
765 if (read_section_hdr (desc
, _TEXT
, &text_hdr
, num_sections
,
766 file_hdr
.f_opthdr
) < 0)
767 error ("\"%s\": can't read text section header", name
);
769 /* Read the line number table, all at once. */
771 val
= init_lineno (desc
, text_hdr
.s_lnnoptr
, text_hdr
.s_nlnno
);
773 error ("\"%s\": error reading line numbers\n", name
);
775 /* Now read the string table, all at once. */
777 val
= init_stringtab (desc
, symtab_offset
+ num_symbols
* SYMESZ
);
781 printf ("\"%s\": can't get string table", name
);
785 make_cleanup (free_stringtab
, 0);
787 /* Position to read the symbol table. Do not read it all at once. */
788 val
= lseek (desc
, (long)symtab_offset
, 0);
790 perror_with_name (name
);
792 init_misc_functions ();
793 make_cleanup (discard_misc_bunches
, 0);
795 /* Now that the executable file is positioned at symbol table,
796 process it and define symbols accordingly. */
798 read_coff_symtab (desc
, num_symbols
);
800 patch_opaque_types ();
802 /* Sort symbols alphabetically within each block. */
806 /* Go over the misc functions and install them in vector. */
808 condense_misc_bunches ();
810 /* Don't allow char * to have a typename (else would get caddr_t.) */
812 TYPE_NAME (lookup_pointer_type (builtin_type_char
)) = 0;
814 /* Make a default for file to list. */
816 select_source_symtab (0);
818 symfile
= savestring (name
, strlen (name
));
820 do_cleanups (old_chain
);
826 /* Return name of file symbols were loaded from, or 0 if none.. */
834 /* Simplified internal version of coff symbol table information */
838 int c_symnum
; /* symbol number of this entry */
839 int c_nsyms
; /* 1 if syment only, 2 if syment + auxent */
846 /* Given pointers to a symbol table in coff style exec file,
847 analyze them and create struct symtab's describing the symbols.
848 NSYMS is the number of symbols in the symbol table.
849 We read them one at a time using read_one_sym (). */
852 read_coff_symtab (desc
, nsyms
)
856 int newfd
; /* Avoid multiple closes on same desc */
858 register struct context_stack
*new;
859 struct coff_symbol coff_symbol
;
860 register struct coff_symbol
*cs
= &coff_symbol
;
861 static SYMENT main_sym
;
862 static AUXENT main_aux
;
863 struct coff_symbol fcn_cs_saved
;
864 static SYMENT fcn_sym_saved
;
865 static AUXENT fcn_aux_saved
;
867 int num_object_files
= 0;
868 int next_file_symnum
= -1;
870 /* Name of the current file. */
871 char *filestring
= "";
877 struct cleanup
*old_chain
;
882 fatal ("Too many open files");
883 stream
= fdopen (newfd
, "r");
885 old_chain
= make_cleanup (free_all_symtabs
, 0);
886 make_cleanup (fclose
, stream
);
887 nlist_stream_global
= stream
;
888 nlist_nsyms_global
= nsyms
;
889 last_source_file
= 0;
890 bzero (opaque_type_chain
, sizeof opaque_type_chain
);
892 type_vector_length
= 160;
893 type_vector
= (struct typevector
*)
894 xmalloc (sizeof (struct typevector
)
895 + type_vector_length
* sizeof (struct type
*));
896 bzero (type_vector
->type
, type_vector_length
* sizeof (struct type
*));
901 while (symnum
< nsyms
)
903 QUIT
; /* Make this command interruptable. */
904 read_one_sym (cs
, &main_sym
, &main_aux
);
906 if (cs
->c_symnum
== next_file_symnum
&& cs
->c_sclass
!= C_FILE
)
908 CORE_ADDR last_file_end
= cur_src_end_addr
;
910 if (last_source_file
)
914 complete_symtab ("_globals_", 0, first_object_file_end
);
915 /* done with all files, everything from here on out is globals */
918 /* Special case for file with type declarations only, no text. */
919 if (!last_source_file
&& cs
->c_type
!= T_NULL
&& cs
->c_secnum
== N_DEBUG
)
920 complete_symtab (filestring
, 0, 0);
922 /* Typedefs should not be treated as symbol definitions. */
923 if (ISFCN (cs
->c_type
) && cs
->c_sclass
!= C_TPDEF
)
925 /* record as misc function. if we get '.bf' next,
926 * then we undo this step
928 record_misc_function (cs
->c_name
, cs
->c_value
);
930 fcn_line_ptr
= main_aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
931 fcn_start_addr
= cs
->c_value
;
933 fcn_sym_saved
= main_sym
;
934 fcn_aux_saved
= main_aux
;
938 switch (cs
->c_sclass
)
947 printf ("Bad n_sclass = %d\n", cs
->c_sclass
);
952 * c_value field contains symnum of next .file entry in table
953 * or symnum of first global after last .file.
955 next_file_symnum
= cs
->c_value
;
956 filestring
= getfilename (&main_aux
);
958 * Complete symbol table for last object file
959 * containing debugging information.
961 if (last_source_file
)
970 if (cs
->c_name
[0] == '.') {
971 if (strcmp (cs
->c_name
, _TEXT
) == 0) {
972 if (num_object_files
== 1) {
973 /* last address of startup file */
974 first_object_file_end
= cs
->c_value
+
975 main_aux
.x_scn
.x_scnlen
;
977 /* for some reason the old code didn't do
978 * this if this section entry had
979 * main_aux.x_scn.x_nlinno equal to 0
981 complete_symtab (filestring
, cs
->c_value
,
982 main_aux
.x_scn
.x_scnlen
);
984 /* flush rest of '.' symbols */
987 /* fall in for static symbols that don't start with '.' */
989 if (cs
->c_sclass
== C_EXT
&&
990 cs
->c_secnum
== N_ABS
&&
991 strcmp (cs
->c_name
, _ETEXT
) == 0)
992 end_of_text_addr
= cs
->c_value
;
993 if (cs
->c_type
== T_NULL
) {
994 if (cs
->c_secnum
<= 1) { /* text or abs */
995 record_misc_function (cs
->c_name
, cs
->c_value
);
1001 (void) process_coff_symbol (cs
, &main_aux
);
1005 if (strcmp (cs
->c_name
, ".bf") == 0)
1008 /* Don't do this; we want all functions to be on the
1010 unrecord_misc_function ();
1013 within_function
= 1;
1015 /* value contains address of first non-init type code */
1016 /* main_aux.x_sym.x_misc.x_lnsz.x_lnno
1017 contains line number of '{' } */
1018 fcn_first_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
1020 new = (struct context_stack
*)
1021 xmalloc (sizeof (struct context_stack
));
1022 new->depth
= depth
= 0;
1024 context_stack
= new;
1026 new->old_blocks
= pending_blocks
;
1027 new->start_addr
= fcn_start_addr
;
1028 fcn_cs_saved
.c_name
= getsymname (&fcn_sym_saved
);
1029 new->name
= process_coff_symbol (&fcn_cs_saved
,
1032 else if (strcmp (cs
->c_name
, ".ef") == 0)
1034 /* the value of .ef is the address of epilogue code;
1035 * not useful for gdb
1037 /* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
1038 contains number of lines to '}' */
1039 fcn_last_line
= main_aux
.x_sym
.x_misc
.x_lnsz
.x_lnno
;
1040 enter_linenos (fcn_line_ptr
, fcn_first_line
, fcn_last_line
);
1041 new = context_stack
;
1044 error ("Invalid symbol data; .bf/.ef/.bb/.eb symbol mismatch, at symbol %d.",
1047 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1049 fcn_cs_saved
.c_value
+
1050 fcn_aux_saved
.x_sym
.x_misc
.x_fsize
);
1052 within_function
= 0;
1058 if (strcmp (cs
->c_name
, ".bb") == 0)
1060 new = (struct context_stack
*)
1061 xmalloc (sizeof (struct context_stack
));
1064 new->next
= context_stack
;
1065 context_stack
= new;
1066 new->locals
= local_symbols
;
1067 new->old_blocks
= pending_blocks
;
1068 new->start_addr
= cs
->c_value
;
1072 else if (strcmp (cs
->c_name
, ".eb") == 0)
1074 new = context_stack
;
1075 if (new == 0 || depth
!= new->depth
)
1076 error ("Invalid symbol data: .bb/.eb symbol mismatch at symbol %d.",
1078 if (local_symbols
&& context_stack
->next
)
1080 /* Make a block for the local symbols within. */
1081 finish_block (0, &local_symbols
, new->old_blocks
,
1082 new->start_addr
, cs
->c_value
);
1085 local_symbols
= new->locals
;
1086 context_stack
= new->next
;
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. */
1105 /* Read COFF file header, check magic number,
1106 and return number of symbols. */
1107 read_file_hdr (chan
, file_hdr
)
1111 lseek (chan
, 0L, 0);
1112 if (myread (chan
, (char *)file_hdr
, FILHSZ
) < 0)
1115 switch (file_hdr
->f_magic
)
1130 return file_hdr
->f_nsyms
;
1134 if (BADMAG(file_hdr
))
1137 return file_hdr
->f_nsyms
;
1144 read_aout_hdr (chan
, aout_hdr
, size
)
1149 lseek (chan
, (long)FILHSZ
, 0);
1150 if (size
!= sizeof (AOUTHDR
))
1152 if (myread (chan
, (char *)aout_hdr
, size
) != size
)
1157 /* Read a section header. OPTIONAL_HEADER_SIZE is the size of the
1158 optional header (normally f_opthdr from the file header).
1160 Return nonnegative for success, -1 for failure. */
1162 read_section_hdr (chan
, section_name
, section_hdr
, nsects
,
1163 optional_header_size
)
1165 register char *section_name
;
1166 SCNHDR
*section_hdr
;
1167 register int nsects
;
1168 int optional_header_size
;
1172 if (lseek (chan
, FILHSZ
+ optional_header_size
, 0) < 0)
1175 for (i
= 0; i
< nsects
; i
++)
1177 if (myread (chan
, (char *)section_hdr
, SCNHSZ
) < 0)
1179 if (strncmp (section_hdr
->s_name
, section_name
, 8) == 0)
1185 read_one_sym (cs
, sym
, aux
)
1186 register struct coff_symbol
*cs
;
1187 register SYMENT
*sym
;
1188 register AUXENT
*aux
;
1190 cs
->c_symnum
= symnum
;
1191 fread ((char *)sym
, SYMESZ
, 1, nlist_stream_global
);
1192 cs
->c_nsyms
= (sym
->n_numaux
& 0xff) + 1;
1193 if (cs
->c_nsyms
== 2)
1195 /* doc for coff says there is either no aux entry or just one */
1196 fread ((char *)aux
, AUXESZ
, 1, nlist_stream_global
);
1198 else if (cs
->c_nsyms
> 2)
1199 error ("more than one aux symbol table entry at symnum=%d\n", symnum
);
1201 cs
->c_name
= getsymname (sym
);
1202 cs
->c_value
= sym
->n_value
;
1203 cs
->c_sclass
= (sym
->n_sclass
& 0xff);
1204 cs
->c_secnum
= sym
->n_scnum
;
1205 cs
->c_type
= (unsigned) sym
->n_type
;
1207 symnum
+= cs
->c_nsyms
;
1210 /* Support for string table handling */
1212 static char *stringtab
= NULL
;
1215 init_stringtab (chan
, offset
)
1228 if (lseek (chan
, offset
, 0) < 0)
1231 val
= myread (chan
, (char *)&buffer
, sizeof buffer
);
1233 /* If no string table is needed, then the file may end immediately
1234 after the symbols. Just return with `stringtab' set to null. */
1235 if (val
!= sizeof buffer
|| buffer
== 0)
1238 stringtab
= (char *) xmalloc (buffer
);
1239 if (stringtab
== NULL
)
1242 bcopy (&buffer
, stringtab
, sizeof buffer
);
1244 val
= myread (chan
, stringtab
+ sizeof buffer
, buffer
- sizeof buffer
);
1245 if (val
!= buffer
- sizeof buffer
|| stringtab
[buffer
- 1] != '\0')
1260 getsymname (symbol_entry
)
1261 SYMENT
*symbol_entry
;
1263 static char buffer
[SYMNMLEN
+1];
1266 if (symbol_entry
->n_zeroes
== 0)
1268 result
= stringtab
+ symbol_entry
->n_offset
;
1272 strncpy (buffer
, symbol_entry
->n_name
, SYMNMLEN
);
1273 buffer
[SYMNMLEN
] = '\0';
1280 getfilename (aux_entry
)
1283 static char buffer
[BUFSIZ
];
1284 register char *temp
;
1286 extern char *rindex ();
1288 #ifndef COFF_NO_LONG_FILE_NAMES
1289 if (aux_entry
->x_file
.x_foff
!= 0)
1290 strcpy (buffer
, stringtab
+ aux_entry
->x_file
.x_foff
);
1294 strncpy (buffer
, aux_entry
->x_file
.x_fname
, FILNMLEN
);
1295 buffer
[FILNMLEN
] = '\0';
1298 if ((temp
= rindex (result
, '/')) != NULL
)
1303 /* Support for line number handling */
1304 static char *linetab
= NULL
;
1305 static long linetab_offset
;
1306 static int linetab_count
;
1309 init_lineno (chan
, offset
, count
)
1316 if (lseek (chan
, offset
, 0) < 0)
1321 linetab
= (char *) xmalloc (count
* LINESZ
);
1323 val
= myread (chan
, linetab
, count
* LINESZ
);
1324 if (val
!= count
* LINESZ
)
1327 linetab_offset
= offset
;
1328 linetab_count
= count
;
1333 enter_linenos (file_offset
, first_line
, last_line
)
1335 register int first_line
;
1336 register int last_line
;
1338 register char *rawptr
= &linetab
[file_offset
- linetab_offset
];
1341 /* skip first line entry for each function */
1343 /* line numbers start at one for the first line of the function */
1346 /* Bcopy since occaisionally rawptr isn't pointing at long
1348 for (bcopy (rawptr
, &lptr
, LINESZ
);
1349 lptr
.l_lnno
&& lptr
.l_lnno
<= last_line
;
1350 rawptr
+= LINESZ
, bcopy (rawptr
, &lptr
, LINESZ
))
1352 record_line (first_line
+ lptr
.l_lnno
, lptr
.l_addr
.l_paddr
);
1360 register char *p
= name
;
1361 register int total
= p
[0];
1374 return total
% HASHSIZE
;
1378 patch_type (type
, real_type
)
1380 struct type
*real_type
;
1382 register struct type
*target
= TYPE_TARGET_TYPE (type
);
1383 register struct type
*real_target
= TYPE_TARGET_TYPE (real_type
);
1384 int field_size
= TYPE_NFIELDS (real_target
) * sizeof (struct field
);
1386 TYPE_LENGTH (target
) = TYPE_LENGTH (real_target
);
1387 TYPE_NFIELDS (target
) = TYPE_NFIELDS (real_target
);
1388 TYPE_FIELDS (target
) = (struct field
*)
1389 obstack_alloc (symbol_obstack
, field_size
);
1391 bcopy (TYPE_FIELDS (real_target
), TYPE_FIELDS (target
), field_size
);
1393 if (TYPE_NAME (real_target
))
1395 if (TYPE_NAME (target
))
1396 free (TYPE_NAME (target
));
1397 TYPE_NAME (target
) = concat (TYPE_NAME (real_target
), "", "");
1401 /* Patch up all appropriate typdef symbols in the opaque_type_chains
1402 so that they can be used to print out opaque data structures properly */
1405 patch_opaque_types ()
1409 /* Look at each symbol in the per-file block of each symtab. */
1410 for (s
= symtab_list
; s
; s
= s
->next
)
1412 register struct block
*b
;
1415 /* Go through the per-file symbols only */
1416 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), 1);
1417 for (i
= BLOCK_NSYMS (b
) - 1; i
>= 0; i
--)
1419 register struct symbol
*real_sym
;
1421 /* Find completed typedefs to use to fix opaque ones.
1422 Remove syms from the chain when their types are stored,
1423 but search the whole chain, as there may be several syms
1424 from different files with the same name. */
1425 real_sym
= BLOCK_SYM (b
, i
);
1426 if (SYMBOL_CLASS (real_sym
) == LOC_TYPEDEF
&&
1427 SYMBOL_NAMESPACE (real_sym
) == VAR_NAMESPACE
&&
1428 TYPE_CODE (SYMBOL_TYPE (real_sym
)) == TYPE_CODE_PTR
&&
1429 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym
))) != 0)
1431 register char *name
= SYMBOL_NAME (real_sym
);
1432 register int hash
= hashname (name
);
1433 register struct symbol
*sym
, *prev
;
1436 for (sym
= opaque_type_chain
[hash
]; sym
;)
1438 if (name
[0] == SYMBOL_NAME (sym
)[0] &&
1439 !strcmp (name
+ 1, SYMBOL_NAME (sym
) + 1))
1442 SYMBOL_VALUE (prev
) = SYMBOL_VALUE (sym
);
1444 opaque_type_chain
[hash
]
1445 = (struct symbol
*) SYMBOL_VALUE (sym
);
1447 patch_type (SYMBOL_TYPE (sym
), SYMBOL_TYPE (real_sym
));
1450 sym
= (struct symbol
*) SYMBOL_VALUE (prev
);
1452 sym
= opaque_type_chain
[hash
];
1457 sym
= (struct symbol
*) SYMBOL_VALUE (sym
);
1465 static struct symbol
*
1466 process_coff_symbol (cs
, aux
)
1467 register struct coff_symbol
*cs
;
1468 register AUXENT
*aux
;
1470 register struct symbol
*sym
1471 = (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
1474 #ifdef NAMES_HAVE_UNDERSCORE
1480 bzero (sym
, sizeof (struct symbol
));
1482 name
= (name
[0] == '_' ? name
+ offset
: name
);
1483 SYMBOL_NAME (sym
) = obstack_copy0 (symbol_obstack
, name
, strlen (name
));
1485 /* default assumptions */
1486 SYMBOL_VALUE (sym
) = cs
->c_value
;
1487 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1489 if (ISFCN (cs
->c_type
))
1492 lookup_function_type (decode_function_type (cs
, cs
->c_type
, aux
));
1493 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1494 if (cs
->c_sclass
== C_STAT
)
1495 add_symbol_to_list (sym
, &file_symbols
);
1496 else if (cs
->c_sclass
== C_EXT
)
1497 add_symbol_to_list (sym
, &global_symbols
);
1501 SYMBOL_TYPE (sym
) = decode_type (cs
, cs
->c_type
, aux
);
1502 switch (cs
->c_sclass
)
1508 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1509 add_symbol_to_list (sym
, &local_symbols
);
1513 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1514 add_symbol_to_list (sym
, &global_symbols
);
1518 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1519 if (within_function
) {
1520 /* Static symbol of local scope */
1521 add_symbol_to_list (sym
, &local_symbols
);
1524 /* Static symbol at top level of file */
1525 add_symbol_to_list (sym
, &file_symbols
);
1530 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1531 add_symbol_to_list (sym
, &local_symbols
);
1538 SYMBOL_CLASS (sym
) = LOC_ARG
;
1539 add_symbol_to_list (sym
, &local_symbols
);
1541 /* If PCC says a parameter is a short or a char,
1542 it is really an int. */
1543 if (SYMBOL_TYPE (sym
) == builtin_type_char
1544 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1545 SYMBOL_TYPE (sym
) = builtin_type_int
;
1546 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1547 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1548 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1553 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1554 add_symbol_to_list (sym
, &local_symbols
);
1556 /* If PCC says a parameter is a short or a char,
1557 it is really an int. */
1558 if (SYMBOL_TYPE (sym
) == builtin_type_char
1559 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1560 SYMBOL_TYPE (sym
) = builtin_type_int
;
1561 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1562 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1563 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1568 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1569 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1571 /* If type has no name, give it one */
1572 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1573 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1574 TYPE_NAME (SYMBOL_TYPE (sym
))
1575 = concat (SYMBOL_NAME (sym
), "", "");
1577 /* Keep track of any type which points to empty structured type,
1578 so it can be filled from a definition from another file */
1579 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
&&
1580 TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (sym
))) == 0)
1582 register int i
= hashname (SYMBOL_NAME (sym
));
1584 SYMBOL_VALUE (sym
) = (int) opaque_type_chain
[i
];
1585 opaque_type_chain
[i
] = sym
;
1587 add_symbol_to_list (sym
, &file_symbols
);
1593 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1594 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1595 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1596 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1597 TYPE_NAME (SYMBOL_TYPE (sym
))
1599 (cs
->c_sclass
== C_ENTAG
1601 : (cs
->c_sclass
== C_STRTAG
1602 ? "struct " : "union ")),
1604 add_symbol_to_list (sym
, &file_symbols
);
1614 /* Decode a coff type specifier;
1615 return the type that is meant. */
1619 decode_type (cs
, c_type
, aux
)
1620 register struct coff_symbol
*cs
;
1621 unsigned int c_type
;
1622 register AUXENT
*aux
;
1624 register struct type
*type
= 0;
1626 unsigned int new_c_type
;
1628 if (c_type
& ~N_BTMASK
)
1630 new_c_type
= DECREF (c_type
);
1633 type
= decode_type (cs
, new_c_type
, aux
);
1634 type
= lookup_pointer_type (type
);
1636 else if (ISFCN (c_type
))
1638 type
= decode_type (cs
, new_c_type
, aux
);
1639 type
= lookup_function_type (type
);
1641 else if (ISARY (c_type
))
1644 register unsigned short *dim
;
1645 struct type
*base_type
;
1647 /* Define an array type. */
1648 /* auxent refers to array, not base type */
1649 if (aux
->x_sym
.x_tagndx
== 0)
1652 /* shift the indices down */
1653 dim
= &aux
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0];
1656 for (i
= 0; *dim
&& i
< DIMNUM
- 1; i
++, dim
++)
1660 type
= (struct type
*)
1661 obstack_alloc (symbol_obstack
, sizeof (struct type
));
1662 bzero (type
, sizeof (struct type
));
1664 base_type
= decode_type (cs
, new_c_type
, aux
);
1666 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
1667 TYPE_TARGET_TYPE (type
) = base_type
;
1668 TYPE_LENGTH (type
) = n
* TYPE_LENGTH (base_type
);
1673 /* Reference to existing type */
1674 if (cs
->c_nsyms
> 1 && aux
->x_sym
.x_tagndx
!= 0)
1676 type
= coff_alloc_type (aux
->x_sym
.x_tagndx
);
1680 return decode_base_type (cs
, BTYPE (c_type
), aux
);
1683 /* Decode a coff type specifier for function definition;
1684 return the type that the function returns. */
1688 decode_function_type (cs
, c_type
, aux
)
1689 register struct coff_symbol
*cs
;
1690 unsigned int c_type
;
1691 register AUXENT
*aux
;
1693 if (aux
->x_sym
.x_tagndx
== 0)
1694 cs
->c_nsyms
= 1; /* auxent refers to function, not base type */
1696 return decode_type (cs
, DECREF (cs
->c_type
), aux
);
1703 decode_base_type (cs
, c_type
, aux
)
1704 register struct coff_symbol
*cs
;
1705 unsigned int c_type
;
1706 register AUXENT
*aux
;
1713 /* shows up with "void (*foo)();" structure members */
1714 return builtin_type_void
;
1717 /* shouldn't show up here */
1721 return builtin_type_char
;
1724 return builtin_type_short
;
1727 return builtin_type_int
;
1730 return builtin_type_long
;
1733 return builtin_type_float
;
1736 return builtin_type_double
;
1739 if (cs
->c_nsyms
!= 2)
1741 /* anonymous structure type */
1742 type
= coff_alloc_type (cs
->c_symnum
);
1743 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1744 TYPE_NAME (type
) = concat ("struct ", "<opaque>", "");
1745 TYPE_LENGTH (type
) = 0;
1746 TYPE_FIELDS (type
) = 0;
1747 TYPE_NFIELDS (type
) = 0;
1751 type
= read_struct_type (cs
->c_symnum
,
1752 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1753 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1758 if (cs
->c_nsyms
!= 2)
1760 /* anonymous union type */
1761 type
= coff_alloc_type (cs
->c_symnum
);
1762 TYPE_NAME (type
) = concat ("union ", "<opaque>", "");
1763 TYPE_LENGTH (type
) = 0;
1764 TYPE_FIELDS (type
) = 0;
1765 TYPE_NFIELDS (type
) = 0;
1769 type
= read_struct_type (cs
->c_symnum
,
1770 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1771 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1773 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1777 return read_enum_type (cs
->c_symnum
,
1778 aux
->x_sym
.x_misc
.x_lnsz
.x_size
,
1779 aux
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
1782 /* shouldn't show up here */
1786 return builtin_type_unsigned_char
;
1789 return builtin_type_unsigned_short
;
1792 return builtin_type_unsigned_int
;
1795 return builtin_type_unsigned_long
;
1797 printf ("unexpected type %d at symnum %d\n", c_type
, cs
->c_symnum
);
1798 return builtin_type_void
;
1801 /* This page contains subroutines of read_type. */
1803 /* Read the description of a structure (or union type)
1804 and return an object describing the type. */
1806 static struct type
*
1807 read_struct_type (index
, length
, lastsym
)
1814 struct nextfield
*next
;
1818 register struct type
*type
;
1819 register struct nextfield
*list
= 0;
1820 struct nextfield
*new;
1824 #ifdef NAMES_HAVE_UNDERSCORE
1829 struct coff_symbol member_sym
;
1830 register struct coff_symbol
*ms
= &member_sym
;
1835 type
= coff_alloc_type (index
);
1836 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1837 TYPE_LENGTH (type
) = length
;
1839 while (!done
&& symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
1841 read_one_sym (ms
, &sub_sym
, &sub_aux
);
1843 name
= (name
[0] == '_' ? name
+ offset
: name
);
1845 switch (ms
->c_sclass
)
1850 /* Get space to record the next field's data. */
1851 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1855 /* Save the data. */
1856 list
->field
.name
= savestring (name
, strlen (name
));
1857 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1858 list
->field
.bitpos
= 8 * ms
->c_value
;
1859 list
->field
.bitsize
= 0;
1865 /* Get space to record the next field's data. */
1866 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1870 /* Save the data. */
1871 list
->field
.name
= savestring (name
, strlen (name
));
1872 list
->field
.type
= decode_type (ms
, ms
->c_type
, &sub_aux
);
1873 list
->field
.bitpos
= ms
->c_value
;
1874 list
->field
.bitsize
= sub_aux
.x_sym
.x_misc
.x_lnsz
.x_size
;
1883 /* Now create the vector of fields, and record how big it is. */
1885 TYPE_NFIELDS (type
) = nfields
;
1886 TYPE_FIELDS (type
) = (struct field
*)
1887 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nfields
);
1889 /* Copy the saved-up fields into the field vector. */
1891 for (n
= nfields
; list
; list
= list
->next
)
1892 TYPE_FIELD (type
, --n
) = list
->field
;
1897 /* Read a definition of an enumeration type,
1898 and create and return a suitable type object.
1899 Also defines the symbols that represent the values of the type. */
1901 static struct type
*
1902 read_enum_type (index
, length
, lastsym
)
1907 register struct symbol
*sym
;
1908 register struct type
*type
;
1910 struct pending
**symlist
;
1911 struct coff_symbol member_sym
;
1912 register struct coff_symbol
*ms
= &member_sym
;
1915 struct pending
*osyms
, *syms
;
1918 #ifdef NAMES_HAVE_UNDERSCORE
1924 type
= coff_alloc_type (index
);
1925 if (within_function
)
1926 symlist
= &local_symbols
;
1928 symlist
= &file_symbols
;
1931 while (symnum
< lastsym
&& symnum
< nlist_nsyms_global
)
1933 read_one_sym (ms
, &sub_sym
, &sub_aux
);
1935 name
= (name
[0] == '_' ? name
+ offset
: name
);
1937 switch (ms
->c_sclass
)
1940 sym
= (struct symbol
*) xmalloc (sizeof (struct symbol
));
1941 bzero (sym
, sizeof (struct symbol
));
1943 SYMBOL_NAME (sym
) = savestring (name
, strlen (name
));
1944 SYMBOL_CLASS (sym
) = LOC_CONST
;
1945 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1946 SYMBOL_VALUE (sym
) = ms
->c_value
;
1947 add_symbol_to_list (sym
, symlist
);
1956 /* Now fill in the fields of the type-structure. */
1958 TYPE_LENGTH (type
) = sizeof (int);
1959 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
1960 TYPE_NFIELDS (type
) = nsyms
;
1961 TYPE_FIELDS (type
) = (struct field
*)
1962 obstack_alloc (symbol_obstack
, sizeof (struct field
) * nsyms
);
1964 /* Find the symbols for the values and put them into the type.
1965 The symbols can be found in the symlist that we put them on
1966 to cause them to be defined. osyms contains the old value
1967 of that symlist; everything up to there was defined by us. */
1969 for (syms
= *symlist
, n
= nsyms
; syms
!= osyms
; syms
= syms
->next
)
1971 SYMBOL_TYPE (syms
->symbol
) = type
;
1972 TYPE_FIELD_NAME (type
, --n
) = SYMBOL_NAME (syms
->symbol
);
1973 TYPE_FIELD_VALUE (type
, n
) = 0;
1974 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (syms
->symbol
);
1975 TYPE_FIELD_BITSIZE (type
, n
) = 0;
1980 /* This function is really horrible, but to avoid it, there would need
1981 to be more filling in of forward references. THIS SHOULD BE MOVED
1982 OUT OF COFFREAD.C AND DBXREAD.C TO SOME PLACE WHERE IT CAN BE SHARED. */
1984 fill_in_vptr_fieldno (type
)
1987 if (TYPE_VPTR_FIELDNO (type
) < 0)
1988 TYPE_VPTR_FIELDNO (type
) =
1989 fill_in_vptr_fieldno (TYPE_BASECLASS (type
, 1));
1990 return TYPE_VPTR_FIELDNO (type
);
1993 /* partial symbol tables are not implemented in coff, therefore
1994 block_for_pc() (and others) will never decide to call this. */
1996 extern struct symtab
*
1997 psymtab_to_symtab ()
1999 fatal ("error: Someone called psymtab_to_symtab\n");
2002 /* These will stay zero all the time */
2003 struct psymbol_allocation_list global_psymbols
, static_psymbols
;
2009 bzero (&global_psymbols
, sizeof (global_psymbols
));
2010 bzero (&static_psymbols
, sizeof (static_psymbols
));
2012 add_com ("symbol-file", class_files
, symbol_file_command
,
2013 "Load symbol table (in coff format) from executable file FILE.");
2017 #endif /* COFF_FORMAT */