1 /* Read dbx symbol tables and convert to internal format, for GDB.
2 Copyright (C) 1986, 1987, 1988 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@mcc.com)
5 GDB is distributed in the hope that it will be useful, but WITHOUT ANY
6 WARRANTY. No author or distributor accepts responsibility to anyone
7 for the consequences of using it or for whether it serves any
8 particular purpose or works at all, unless he says so in writing.
9 Refer to the GDB General Public License for full details.
11 Everyone is granted permission to copy, modify and redistribute GDB,
12 but only under the conditions described in the GDB General Public
13 License. A copy of this license is supposed to have been given to you
14 along with GDB so you can know your rights and responsibilities. It
15 should be in a file named COPYING. Among other things, the copyright
16 notice and this notice must be preserved on all copies.
18 In other words, go ahead and share GDB, but don't try to stop
19 anyone else from sharing it farther. Help stamp out software hoarding!
24 #ifdef READ_DBX_FORMAT
30 #include <sys/param.h>
33 #include "initialize.h"
36 static void add_symbol_to_list ();
37 static void read_dbx_symtab ();
38 static void process_one_symbol ();
39 static struct type
*read_type ();
40 static struct type
*read_range_type ();
41 static struct type
*read_enum_type ();
42 static struct type
*read_struct_type ();
43 static long read_number ();
44 static void finish_block ();
45 static struct blockvector
*make_blockvector ();
46 static struct symbol
*define_symbol ();
47 static void start_subfile ();
48 static int hashname ();
49 static void hash_symsegs ();
51 extern struct symtab
*read_symsegs ();
52 extern void free_all_symtabs ();
55 static struct type
**read_args ();
59 /* Chain of symtabs made from reading the file's symsegs.
60 These symtabs do not go into symtab_list themselves,
61 but the information is copied from them when appropriate
62 to make the symtabs that will exist permanently. */
64 static struct symtab
*symseg_chain
;
66 /* Symseg symbol table for the file whose data we are now processing.
67 It is one of those in symseg_chain. Or 0, for a compilation that
70 static struct symtab
*current_symseg
;
72 /* Name of source file whose symbol data we are now processing.
73 This comes from a symbol of type N_SO. */
75 static char *last_source_file
;
77 /* Core address of start of text of current source file.
78 This too comes from the N_SO symbol. */
80 static CORE_ADDR last_source_start_addr
;
82 /* End of the text segment of the executable file,
83 as found in the symbol _etext. */
85 static CORE_ADDR end_of_text_addr
;
87 /* The list of sub-source-files within the current individual compilation.
88 Each file gets its own symtab with its own linetable and associated info,
89 but they all share one blockvector. */
95 struct linetable
*line_vector
;
96 int line_vector_length
;
97 int line_vector_index
;
101 static struct subfile
*subfiles
;
103 static struct subfile
*current_subfile
;
105 /* The addresses of the symbol table stream and the string table
106 of the object file we are reading (as copied into core). */
108 static FILE *nlist_stream_global
;
109 static int nlist_size_global
;
110 static char *stringtab_global
;
112 /* The index in nlist_global of the last dbx symbol to be processed. */
116 /* Vector of types defined so far, indexed by their dbx type numbers.
117 (In newer sun systems, dbx uses a pair of numbers in parens,
118 as in "(SUBFILENUM,NUMWITHINSUBFILE)". Then these numbers must be
119 translated through the type_translations hash table to get
120 the index into the type vector.) */
122 static struct typevector
*type_vector
;
124 /* Number of elements allocated for type_vector currently. */
126 static int type_vector_length
;
128 /* Vector of line number information. */
130 static struct linetable
*line_vector
;
132 /* Index of next entry to go in line_vector_index. */
134 static int line_vector_index
;
136 /* Last line number recorded in the line vector. */
138 static int prev_line_number
;
140 /* Number of elements allocated for line_vector currently. */
142 static int line_vector_length
;
144 /* Chain of global symbols whose values are not known yet.
145 They are chained thru the SYMBOL_VALUE, since we don't
146 have the correct data for that slot yet. */
149 static struct symbol
*global_sym_chain
[HASHSIZE
];
151 /* Record the symbols defined for each context in a list.
152 We don't create a struct block for the context until we
153 know how long to make it. */
157 struct pending
*next
;
158 struct symbol
*symbol
;
161 /* Here are the three lists that symbols are put on. */
163 struct pending
*file_symbols
; /* static at top level, and types */
165 struct pending
*global_symbols
; /* global functions and variables */
167 struct pending
*local_symbols
; /* everything local to lexical context */
169 /* List of unclosed lexical contexts
170 (that will become blocks, eventually). */
174 struct context_stack
*next
;
175 struct pending
*locals
;
176 struct pending_block
*old_blocks
;
178 CORE_ADDR start_addr
;
182 struct context_stack
*context_stack
;
184 /* Nonzero if within a function (so symbols should be local,
185 if nothing says specifically). */
189 /* List of blocks already made (lexical contexts already closed).
190 This is used at the end to make the blockvector. */
194 struct pending_block
*next
;
198 struct pending_block
*pending_blocks
;
200 extern CORE_ADDR first_object_file_end
; /* From blockframe.c */
202 /* File name symbols were loaded from. */
204 static char *symfile
;
206 /* Support for Sun changes to dbx symbol format */
208 /* For each identified header file, we have a table of types defined
211 header_files maps header file names to their type tables.
212 It is a vector of n_header_files elements.
213 Each element describes one header file.
214 It contains a vector of types.
216 Sometimes it can happen that the same header file produces
217 different results when included in different places.
218 This can result from conditionals or from different
219 things done before including the file.
220 When this happens, there are multiple entries for the file in this table,
221 one entry for each distinct set of results.
222 The entries are distinguished by the INSTANCE field.
223 The INSTANCE field appears in the N_BINCL and N_EXCL symbol table and is
224 used to match header-file references to their corresponding data. */
228 char *name
; /* Name of header file */
229 int instance
; /* Numeric code distinguishing instances
230 of one header file that produced
231 different results when included.
232 It comes from the N_BINCL or N_EXCL. */
233 struct type
**vector
; /* Pointer to vector of types */
234 int length
; /* Allocated length (# elts) of that vector */
237 static struct header_file
*header_files
;
239 static int n_header_files
;
241 static int n_allocated_header_files
;
243 /* Within each object file, various header files are assigned numbers.
244 A type is defined or referred to with a pair of numbers
245 (FILENUM,TYPENUM) where FILENUM is the number of the header file
246 and TYPENUM is the number within that header file.
247 TYPENUM is the index within the vector of types for that header file.
249 FILENUM == 1 is special; it refers to the main source of the object file,
250 and not to any header file. FILENUM != 1 is interpreted by looking it up
251 in the following table, which contains indices in header_files. */
253 static int *this_object_header_files
;
255 static int n_this_object_header_files
;
257 static int n_allocated_this_object_header_files
;
259 /* When a header file is getting special overriding definitions
260 for one source file, record here the header_files index
261 of its normal definition vector.
262 At other times, this is -1. */
264 static int header_file_prev_index
;
266 /* At the start of reading dbx symbols, allocate our tables. */
271 n_allocated_header_files
= 10;
272 header_files
= (struct header_file
*) xmalloc (10 * sizeof (struct header_file
));
275 n_allocated_this_object_header_files
= 10;
276 this_object_header_files
= (int *) xmalloc (10 * sizeof (int));
279 /* At the end of reading dbx symbols, free our tables. */
285 for (i
= 0; i
< n_header_files
; i
++)
286 free (header_files
[i
].name
);
288 free (this_object_header_files
);
291 /* Called at the start of each object file's symbols.
292 Clear out the mapping of header file numbers to header files. */
295 new_object_header_files ()
297 /* Leave FILENUM of 0 free for builtin types and this file's types. */
298 n_this_object_header_files
= 1;
299 header_file_prev_index
= -1;
302 /* Add header file number I for this object file
303 at the next successive FILENUM. */
306 add_this_object_header_file (i
)
309 if (n_this_object_header_files
== n_allocated_this_object_header_files
)
311 n_allocated_this_object_header_files
*= 2;
312 this_object_header_files
313 = (int *) xrealloc (this_object_header_files
,
314 n_allocated_this_object_header_files
* sizeof (int));
317 this_object_header_files
[n_this_object_header_files
++] = i
;
320 /* Add to this file an "old" header file, one already seen in
321 a previous object file. NAME is the header file's name.
322 INSTANCE is its instance code, to select among multiple
323 symbol tables for the same header file. */
326 add_old_header_file (name
, instance
)
330 register struct header_file
*p
= header_files
;
333 for (i
= 0; i
< n_header_files
; i
++)
334 if (!strcmp (p
[i
].name
, name
) && instance
== p
[i
].instance
)
336 add_this_object_header_file (i
);
339 error ("Invalid symbol data: \"repeated\" header file that hasn't been seen before, at symtab pos %d.",
343 /* Add to this file a "new" header file: definitions for its types follow.
344 NAME is the header file's name.
345 Most often this happens only once for each distinct header file,
346 but not necessarily. If it happens more than once, INSTANCE has
347 a different value each time, and references to the header file
348 use INSTANCE values to select among them.
350 dbx output contains "begin" and "end" markers for each new header file,
351 but at this level we just need to know which files there have been;
352 so we record the file when its "begin" is seen and ignore the "end". */
355 add_new_header_file (name
, instance
)
360 register struct header_file
*p
= header_files
;
361 header_file_prev_index
= -1;
364 /* This code was used before I knew about the instance codes.
365 My first hypothesis is that it is not necessary now
366 that instance codes are handled. */
368 /* Has this header file a previous definition?
369 If so, make a new entry anyway so that this use in this source file
370 gets a separate entry. Later source files get the old entry.
371 Record here the index of the old entry, so that any type indices
372 not previously defined can get defined in the old entry as
373 well as in the new one. */
375 for (i
= 0; i
< n_header_files
; i
++)
376 if (!strcmp (p
[i
].name
, name
))
378 header_file_prev_index
= i
;
383 /* Make sure there is room for one more header file. */
385 if (n_header_files
== n_allocated_header_files
)
387 n_allocated_header_files
*= 2;
389 = (struct header_file
*) xrealloc (header_files
, n_allocated_header_files
* sizeof (struct header_file
));
392 /* Create an entry for this header file. */
394 i
= n_header_files
++;
395 header_files
[i
].name
= name
;
396 header_files
[i
].instance
= instance
;
397 header_files
[i
].length
= 10;
398 header_files
[i
].vector
399 = (struct type
**) xmalloc (10 * sizeof (struct type
*));
400 bzero (header_files
[i
].vector
, 10 * sizeof (struct type
*));
402 add_this_object_header_file (i
);
405 /* Look up a dbx type-number pair. Return the address of the slot
406 where the type for that number-pair is stored.
407 The number-pair is in TYPENUMS.
409 This can be used for finding the type associated with that pair
410 or for associating a new type with the pair. */
412 static struct type
**
413 dbx_lookup_type (typenums
)
416 register int filenum
= typenums
[0], index
= typenums
[1];
418 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
419 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
420 filenum
, index
, symnum
);
424 /* Type is defined outside of header files.
425 Find it in this object file's type vector. */
426 if (index
>= type_vector_length
)
428 type_vector_length
*= 2;
429 type_vector
= (struct typevector
*)
430 xrealloc (type_vector
, sizeof (struct typevector
) + type_vector_length
* sizeof (struct type
*));
431 bzero (&type_vector
->type
[type_vector_length
/ 2],
432 type_vector_length
* sizeof (struct type
*) / 2);
434 return &type_vector
->type
[index
];
438 register int real_filenum
= this_object_header_files
[filenum
];
439 register struct header_file
*f
;
441 if (real_filenum
>= n_header_files
)
444 f
= &header_files
[real_filenum
];
446 if (index
>= f
->length
)
449 f
->vector
= (struct type
**)
450 xrealloc (f
->vector
, f
->length
* sizeof (struct type
*));
451 bzero (&f
->vector
[f
->length
/ 2],
452 f
->length
* sizeof (struct type
*) / 2);
454 return &f
->vector
[index
];
458 /* Make sure there is a type allocated for type numbers TYPENUMS
459 and return the type object.
460 This can create an empty (zeroed) type object. */
463 dbx_alloc_type (typenums
)
466 register struct type
**type_addr
= dbx_lookup_type (typenums
);
467 register struct type
*type
= *type_addr
;
469 /* If we are referring to a type not known at all yet,
470 allocate an empty type for it.
471 We will fill it in later if we find out how. */
474 type
= (struct type
*) obstack_alloc (symbol_obstack
,
475 sizeof (struct type
));
476 bzero (type
, sizeof (struct type
));
477 TYPE_VPTR_FIELDNO (type
) = -1;
484 static struct type
**
485 explicit_lookup_type (real_filenum
, index
)
486 int real_filenum
, index
;
488 register struct header_file
*f
= &header_files
[real_filenum
];
490 if (index
>= f
->length
)
493 f
->vector
= (struct type
**)
494 xrealloc (f
->vector
, f
->length
* sizeof (struct type
*));
495 bzero (&f
->vector
[f
->length
/ 2],
496 f
->length
* sizeof (struct type
*) / 2);
498 return &f
->vector
[index
];
502 /* maintain the lists of symbols and blocks */
504 /* Add a symbol to one of the lists of symbols. */
506 add_symbol_to_list (symbol
, listhead
)
507 struct symbol
*symbol
;
508 struct pending
**listhead
;
510 register struct pending
*link
511 = (struct pending
*) xmalloc (sizeof (struct pending
));
513 link
->next
= *listhead
;
514 link
->symbol
= symbol
;
518 /* Take one of the lists of symbols and make a block from it.
519 Put the block on the list of pending blocks. */
522 finish_block (symbol
, listhead
, old_blocks
, start
, end
)
523 struct symbol
*symbol
;
524 struct pending
**listhead
;
525 struct pending_block
*old_blocks
;
526 CORE_ADDR start
, end
;
528 register struct pending
*next
, *next1
;
529 register struct block
*block
;
530 register struct pending_block
*pblock
;
531 struct pending_block
*opblock
;
534 /* Count the length of the list of symbols. */
536 for (next
= *listhead
, i
= 0; next
; next
= next
->next
, i
++);
538 block
= (struct block
*) obstack_alloc (symbol_obstack
,
539 sizeof (struct block
) + (i
- 1) * sizeof (struct symbol
*));
541 /* Copy the symbols into the block. */
543 BLOCK_NSYMS (block
) = i
;
544 for (next
= *listhead
; next
; next
= next
->next
)
545 BLOCK_SYM (block
, --i
) = next
->symbol
;
547 BLOCK_START (block
) = start
;
548 BLOCK_END (block
) = end
;
549 BLOCK_SUPERBLOCK (block
) = 0; /* Filled in when containing block is made */
551 /* Put the block in as the value of the symbol that names it. */
555 SYMBOL_BLOCK_VALUE (symbol
) = block
;
556 BLOCK_FUNCTION (block
) = symbol
;
559 BLOCK_FUNCTION (block
) = 0;
561 /* Now free the links of the list, and empty the list. */
563 for (next
= *listhead
; next
; next
= next1
)
570 /* Install this block as the superblock
571 of all blocks made since the start of this scope
572 that don't have superblocks yet. */
575 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
577 if (BLOCK_SUPERBLOCK (pblock
->block
) == 0)
578 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
582 /* Record this block on the list of all blocks in the file.
583 Put it after opblock, or at the beginning if opblock is 0.
584 This puts the block in the list after all its subblocks. */
586 pblock
= (struct pending_block
*) xmalloc (sizeof (struct pending_block
));
587 pblock
->block
= block
;
590 pblock
->next
= opblock
->next
;
591 opblock
->next
= pblock
;
595 pblock
->next
= pending_blocks
;
596 pending_blocks
= pblock
;
600 static struct blockvector
*
603 register struct pending_block
*next
, *next1
;
604 register struct blockvector
*blockvector
;
607 /* Count the length of the list of blocks. */
609 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
611 blockvector
= (struct blockvector
*) obstack_alloc (symbol_obstack
, sizeof (struct blockvector
) + (i
- 1) * sizeof (struct block
*));
613 /* Copy the blocks into the blockvector.
614 This is done in reverse order, which happens to put
615 the blocks into the proper order (ascending starting address).
616 finish_block has hair to insert each block into the list
617 after its subblocks in order to make sure this is true. */
619 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
620 for (next
= pending_blocks
; next
; next
= next
->next
)
621 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
623 /* Now free the links of the list, and empty the list. */
625 for (next
= pending_blocks
; next
; next
= next1
)
635 /* Manage the vector of line numbers. */
638 record_line (line
, pc
)
642 /* Ignore the dummy line number in libg.o */
647 /* Make sure line vector is big enough. */
649 if (line_vector_index
+ 1 >= line_vector_length
)
651 line_vector_length
*= 2;
652 line_vector
= (struct linetable
*)
653 xrealloc (line_vector
,
654 sizeof (struct linetable
) + line_vector_length
* sizeof (int));
655 current_subfile
->line_vector
= line_vector
;
658 /* If this line is not continguous with previous one recorded,
659 record a line-number entry for it. */
660 if (line
!= prev_line_number
+ 1)
661 line_vector
->item
[line_vector_index
++] = - line
;
662 prev_line_number
= line
;
664 /* Record the core address of the line. */
665 line_vector
->item
[line_vector_index
++] = pc
;
668 /* Start a new symtab for a new source file.
669 This is called when a dbx symbol of type N_SO is seen;
670 it indicates the start of data for one original source file. */
673 start_symtab (name
, start_addr
)
675 CORE_ADDR start_addr
;
677 register struct symtab
*s
;
679 last_source_file
= name
;
680 last_source_start_addr
= start_addr
;
686 new_object_header_files ();
688 for (s
= symseg_chain
; s
; s
= s
->next
)
689 if (s
->ldsymoff
== symnum
* sizeof (struct nlist
))
695 type_vector_length
= 160;
696 type_vector
= (struct typevector
*) xmalloc (sizeof (struct typevector
) + type_vector_length
* sizeof (struct type
*));
697 bzero (type_vector
->type
, type_vector_length
* sizeof (struct type
*));
699 /* Initialize the list of sub source files with one entry
700 for this file (the top-level source file). */
704 start_subfile (name
);
707 /* Handle an N_SOL symbol, which indicates the start of
708 code that came from an included (or otherwise merged-in)
709 source file with a different name. */
715 register struct subfile
*subfile
;
717 /* Save the current subfile's line vector data. */
721 current_subfile
->line_vector_index
= line_vector_index
;
722 current_subfile
->line_vector_length
= line_vector_length
;
723 current_subfile
->prev_line_number
= prev_line_number
;
726 /* See if this subfile is already known as a subfile of the
727 current main source file. */
729 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
731 if (!strcmp (subfile
->name
, name
))
733 line_vector
= subfile
->line_vector
;
734 line_vector_index
= subfile
->line_vector_index
;
735 line_vector_length
= subfile
->line_vector_length
;
736 prev_line_number
= subfile
->prev_line_number
;
737 current_subfile
= subfile
;
742 /* This subfile is not known. Add an entry for it. */
744 line_vector_index
= 0;
745 line_vector_length
= 1000;
746 prev_line_number
= -2; /* Force first line number to be explicit */
747 line_vector
= (struct linetable
*)
748 xmalloc (sizeof (struct linetable
) + line_vector_length
* sizeof (int));
750 /* Make an entry for this subfile in the list of all subfiles
751 of the current main source file. */
753 subfile
= (struct subfile
*) xmalloc (sizeof (struct subfile
));
754 subfile
->next
= subfiles
;
755 subfile
->name
= savestring (name
, strlen (name
));
756 subfile
->line_vector
= line_vector
;
758 current_subfile
= subfile
;
761 /* Finish the symbol definitions for one main source file,
762 close off all the lexical contexts for that file
763 (creating struct block's for them), then make the struct symtab
764 for that file and put it in the list of all such.
766 END_ADDR is the address of the end of the file's text. */
769 end_symtab (end_addr
)
772 register struct symtab
*symtab
;
773 register struct context_stack
*cstk
;
774 register struct blockvector
*blockvector
;
775 register struct subfile
*subfile
;
776 register struct linetable
*lv
;
777 struct subfile
*nextsub
;
779 if (current_symseg
!= 0)
781 last_source_file
= 0;
786 /* Finish the lexical context of the last function in the file. */
790 cstk
= context_stack
;
791 /* Make a block for the local symbols within. */
792 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
793 cstk
->start_addr
, end_addr
);
797 /* Finish defining all the blocks of this symtab. */
798 finish_block (0, &file_symbols
, 0, last_source_start_addr
, end_addr
);
799 finish_block (0, &global_symbols
, 0, last_source_start_addr
, end_addr
);
800 blockvector
= make_blockvector ();
802 current_subfile
->line_vector_index
= line_vector_index
;
804 /* Now create the symtab objects proper, one for each subfile. */
805 /* (The main file is one of them.) */
807 for (subfile
= subfiles
; subfile
; subfile
= nextsub
)
809 symtab
= (struct symtab
*) xmalloc (sizeof (struct symtab
));
810 symtab
->free_ptr
= 0;
812 /* Fill in its components. */
813 symtab
->blockvector
= blockvector
;
814 type_vector
->length
= type_vector_length
;
815 symtab
->typevector
= type_vector
;
816 symtab
->free_code
= free_linetable
;
817 if (subfile
->next
== 0)
818 symtab
->free_ptr
= (char *) type_vector
;
820 symtab
->filename
= subfile
->name
;
821 lv
= subfile
->line_vector
;
822 lv
->nitems
= subfile
->line_vector_index
;
823 symtab
->linetable
= (struct linetable
*)
824 xrealloc (lv
, sizeof (struct linetable
) + lv
->nitems
* sizeof (int));
826 symtab
->line_charpos
= 0;
828 /* Link the new symtab into the list of such. */
829 symtab
->next
= symtab_list
;
830 symtab_list
= symtab
;
832 nextsub
= subfile
->next
;
837 type_vector_length
= -1;
839 line_vector_length
= -1;
840 last_source_file
= 0;
845 /* Handle the N_BINCL and N_EINCL symbol types
846 that act like N_SOL for switching source files
847 (different subfiles, as we call them) within one object file,
848 but using a stack rather than in an arbitrary order. */
852 struct subfile_stack
*next
;
857 struct subfile_stack
*subfile_stack
;
862 register struct subfile_stack
*tem
863 = (struct subfile_stack
*) xmalloc (sizeof (struct subfile_stack
));
865 tem
->next
= subfile_stack
;
867 if (current_subfile
== 0 || current_subfile
->name
== 0)
869 tem
->name
= current_subfile
->name
;
870 tem
->prev_index
= header_file_prev_index
;
877 register struct subfile_stack
*link
= subfile_stack
;
883 subfile_stack
= link
->next
;
884 header_file_prev_index
= link
->prev_index
;
889 #endif /* Have N_BINCL */
891 /* Accumulate the misc functions in bunches of 127.
892 At the end, copy them all into one newly allocated structure. */
894 #define MISC_BUNCH_SIZE 127
898 struct misc_bunch
*next
;
899 struct misc_function contents
[MISC_BUNCH_SIZE
];
902 /* Bunch currently being filled up.
903 The next field points to chain of filled bunches. */
905 static struct misc_bunch
*misc_bunch
;
907 /* Number of slots filled in current bunch. */
909 static int misc_bunch_index
;
911 /* Total number of misc functions recorded so far. */
913 static int misc_count
;
916 init_misc_functions ()
920 misc_bunch_index
= MISC_BUNCH_SIZE
;
924 record_misc_function (name
, address
)
928 register struct misc_bunch
*new;
930 if (misc_bunch_index
== MISC_BUNCH_SIZE
)
932 new = (struct misc_bunch
*) xmalloc (sizeof (struct misc_bunch
));
933 misc_bunch_index
= 0;
934 new->next
= misc_bunch
;
937 misc_bunch
->contents
[misc_bunch_index
].name
= name
;
938 misc_bunch
->contents
[misc_bunch_index
].address
= address
;
944 compare_misc_functions (fn1
, fn2
)
945 struct misc_function
*fn1
, *fn2
;
947 /* Return a signed result based on unsigned comparisons
948 so that we sort into unsigned numeric order. */
949 if (fn1
->address
< fn2
->address
)
951 if (fn1
->address
> fn2
->address
)
957 discard_misc_bunches ()
959 register struct misc_bunch
*next
;
963 next
= misc_bunch
->next
;
970 condense_misc_bunches ()
973 register struct misc_bunch
*bunch
;
974 #ifdef NAMES_HAVE_UNDERSCORE
981 = (struct misc_function
*)
982 xmalloc (misc_count
* sizeof (struct misc_function
));
988 for (i
= 0; i
< misc_bunch_index
; i
++)
990 misc_function_vector
[j
] = bunch
->contents
[i
];
991 misc_function_vector
[j
].name
992 = concat (misc_function_vector
[j
].name
993 + (misc_function_vector
[j
].name
[0] == '_' ? offset
: 0),
998 misc_bunch_index
= MISC_BUNCH_SIZE
;
1001 misc_function_count
= j
;
1003 /* Sort the misc functions by address. */
1005 qsort (misc_function_vector
, j
, sizeof (struct misc_function
),
1006 compare_misc_functions
);
1009 /* Call sort_syms to sort alphabetically
1010 the symbols of each block of each symtab. */
1013 compare_symbols (s1
, s2
)
1014 struct symbol
**s1
, **s2
;
1016 /* Names that are less should come first. */
1017 register int namediff
= strcmp (SYMBOL_NAME (*s1
), SYMBOL_NAME (*s2
));
1018 if (namediff
!= 0) return namediff
;
1019 /* For symbols of the same name, registers should come first. */
1020 return ((SYMBOL_CLASS (*s2
) == LOC_REGISTER
)
1021 - (SYMBOL_CLASS (*s1
) == LOC_REGISTER
));
1027 register struct symtab
*s
;
1028 register int i
, nbl
;
1029 register struct blockvector
*bv
;
1030 register struct block
*b
;
1032 for (s
= symtab_list
; s
; s
= s
->next
)
1034 bv
= BLOCKVECTOR (s
);
1035 nbl
= BLOCKVECTOR_NBLOCKS (bv
);
1036 for (i
= 0; i
< nbl
; i
++)
1038 b
= BLOCKVECTOR_BLOCK (bv
, i
);
1039 qsort (&BLOCK_SYM (b
, 0), BLOCK_NSYMS (b
),
1040 sizeof (struct symbol
*), compare_symbols
);
1045 /* This is the symbol-file command. Read the file, analyze its symbols,
1046 and add a struct symtab to symtab_list. */
1049 symbol_file_command (name
)
1054 struct nlist
*nlist
;
1058 extern void close ();
1059 struct cleanup
*old_chain
;
1060 struct symtab
*symseg
;
1066 if (symtab_list
&& !query ("Discard symbol table? ", 0))
1067 error ("Not confirmed.");
1068 free_all_symtabs ();
1072 if (symtab_list
&& !query ("Load new symbol table from \"%s\"? ", name
))
1073 error ("Not confirmed.");
1080 char *absolute_name
;
1081 desc
= openp (getenv ("PATH"), 1, name
, O_RDONLY
, 0, &absolute_name
);
1083 perror_with_name (name
);
1085 name
= absolute_name
;
1088 old_chain
= make_cleanup (close
, desc
);
1089 make_cleanup (free_current_contents
, &name
);
1091 val
= myread (desc
, &hdr
, sizeof hdr
);
1093 perror_with_name (name
);
1096 error ("File \"%s\" not in executable format.", name
);
1098 if (hdr
.a_syms
== 0)
1100 free_all_symtabs ();
1101 printf ("%s does not have a symbol-table.\n", name
);
1106 printf ("Reading symbol data from %s...", name
);
1109 /* Now read the string table, all at once. */
1110 val
= lseek (desc
, N_SYMOFF (hdr
) + hdr
.a_syms
, 0);
1112 perror_with_name (name
);
1113 val
= myread (desc
, &buffer
, sizeof buffer
);
1115 perror_with_name (name
);
1116 stringtab
= (char *) alloca (buffer
);
1117 if (stringtab
== NULL
)
1119 free_all_symtabs ();
1120 printf("%s: symbol table too large for alloca: %d bytes.\n", name
,
1125 bcopy (&buffer
, stringtab
, sizeof buffer
);
1126 val
= myread (desc
, stringtab
+ sizeof buffer
, buffer
- sizeof buffer
);
1128 perror_with_name (name
);
1130 /* Throw away the old symbol table. */
1132 free_all_symtabs ();
1134 #ifdef READ_GDB_SYMSEGS
1135 /* That puts us at the symsegs. Read them. */
1136 symseg_chain
= read_symsegs (desc
, name
);
1139 /* Free the symtabs made by read_symsegs, but not their contents,
1140 which have been copied into symtabs on symtab_list. */
1141 for (symseg
= symseg_chain
; symseg
; symseg
= symseg
->next
)
1144 struct sourcevector
*sv
= (struct sourcevector
*) symseg
->linetable
;
1146 for (i
= 0; i
< sv
->length
; i
++)
1149 struct source
*source
= sv
->source
[i
];
1151 = (struct symtab
*) xmalloc (sizeof (struct symtab
));
1153 bcopy (symseg
, sp1
, sizeof (struct symtab
));
1154 sp1
->filename
= savestring (source
->name
, strlen (source
->name
));
1155 sp1
->linetable
= &source
->contents
;
1156 sp1
->free_code
= free_nothing
;
1157 sp1
->free_ptr
= (i
== 0) ? (char *) symseg
: 0;
1159 sp1
->next
= symtab_list
;
1164 /* Where people are using the 4.2 ld program, must not check for
1165 symsegs, because that ld puts randonm garbage at the end of
1166 the output file and that would trigger an error message. */
1170 /* Position to read the symbol table. Do not read it all at once. */
1171 val
= lseek (desc
, N_SYMOFF (hdr
), 0);
1173 perror_with_name (name
);
1175 init_misc_functions ();
1176 make_cleanup (discard_misc_bunches
, 0);
1177 init_header_files ();
1178 make_cleanup (free_header_files
, 0);
1180 /* Now that the symbol table data of the executable file are all in core,
1181 process them and define symbols accordingly. Closes desc. */
1183 read_dbx_symtab (desc
, stringtab
, hdr
.a_syms
/ sizeof (struct nlist
));
1185 /* Sort symbols alphabetically within each block. */
1189 /* Go over the misc functions and install them in vector. */
1191 condense_misc_bunches ();
1193 /* Don't allow char * to have a typename (else would get caddr_t.) */
1195 TYPE_NAME (lookup_pointer_type (builtin_type_char
)) = 0;
1197 /* Make a default for file to list. */
1199 select_source_symtab (symtab_list
);
1201 symfile
= savestring (name
, strlen (name
));
1203 do_cleanups (old_chain
);
1205 /* Free the symtabs made by read_symsegs, but not their contents,
1206 which have been copied into symtabs on symtab_list. */
1207 while (symseg_chain
)
1209 register struct symtab
*s
= symseg_chain
->next
;
1210 free (symseg_chain
);
1218 /* Return name of file symbols were loaded from, or 0 if none.. */
1226 /* Given pointers to a a.out symbol table in core containing dbx style data,
1227 analyze them and create struct symtab's describing the symbols.
1228 NLISTLEN is the number of symbols in the symbol table.
1229 We read them one at a time using stdio.
1230 All symbol names are given as offsets relative to STRINGTAB. */
1233 read_dbx_symtab (desc
, stringtab
, nlistlen
)
1235 register char *stringtab
;
1236 register int nlistlen
;
1238 FILE *stream
= fdopen (desc
, "r");
1240 register char *namestring
;
1241 register struct symbol
*sym
, *prev
;
1243 int num_object_files
= 0;
1244 struct cleanup
*old_chain
;
1250 old_chain
= make_cleanup (free_all_symtabs
, 0);
1251 nlist_stream_global
= stream
;
1252 nlist_size_global
= nlistlen
;
1253 stringtab_global
= stringtab
;
1254 last_source_file
= 0;
1255 bzero (global_sym_chain
, sizeof global_sym_chain
);
1257 for (symnum
= 0; symnum
< nlistlen
; symnum
++)
1259 QUIT
; /* allow this to be interruptable */
1260 fread (&buf
, sizeof buf
, 1, stream
);
1261 namestring
= buf
.n_un
.n_strx
? buf
.n_un
.n_strx
+ stringtab
: "";
1262 if (buf
.n_type
& N_STAB
)
1263 process_one_symbol (buf
.n_type
, buf
.n_desc
,
1264 buf
.n_value
, namestring
);
1265 /* A static text symbol whose name ends in ".o"
1266 can only mean the start of another object file.
1267 So end the symtab of the source file we have been processing.
1268 This is how we avoid counting the libraries as part
1269 or the last source file.
1270 Also this way we find end of first object file (crt0). */
1271 else if (buf
.n_type
== N_TEXT
1272 && !strcmp (namestring
+ strlen (namestring
) - 2, ".o"))
1274 if (num_object_files
++ == 1)
1275 first_object_file_end
= buf
.n_value
;
1276 if (last_source_file
)
1277 end_symtab (buf
.n_value
);
1279 else if (buf
.n_type
& N_EXT
|| buf
.n_type
== N_TEXT
)
1283 /* Record the location of _etext. */
1284 if (buf
.n_type
== (N_TEXT
| N_EXT
)
1285 && !strcmp (namestring
, "_etext"))
1286 end_of_text_addr
= buf
.n_value
;
1288 /* Global symbol: see if we came across a dbx definition
1289 for a corresponding symbol. If so, store the value.
1290 Remove syms from the chain when their values are stored,
1291 but search the whole chain, as there may be several syms
1292 from different files with the same name. */
1293 if (buf
.n_type
& N_EXT
)
1296 #ifdef NAMES_HAVE_UNDERSCORE
1297 hash
= hashname (namestring
+ 1);
1298 #else /* not NAMES_HAVE_UNDERSCORE */
1299 hash
= hashname (namestring
);
1300 #endif /* not NAMES_HAVE_UNDERSCORE */
1301 for (sym
= global_sym_chain
[hash
];
1305 #ifdef NAMES_HAVE_UNDERSCORE
1307 && namestring
[1] == SYMBOL_NAME (sym
)[0]
1309 !strcmp (namestring
+ 2, SYMBOL_NAME (sym
) + 1)
1310 #else /* NAMES_HAVE_UNDERSCORE */
1311 namestring
[0] == SYMBOL_NAME (sym
)[0]
1313 !strcmp (namestring
+ 1, SYMBOL_NAME (sym
) + 1)
1314 #endif /* NAMES_HAVE_UNDERSCORE */
1318 SYMBOL_VALUE (prev
) = SYMBOL_VALUE (sym
);
1320 global_sym_chain
[hash
]
1321 = (struct symbol
*) SYMBOL_VALUE (sym
);
1322 SYMBOL_VALUE (sym
) = buf
.n_value
;
1324 sym
= (struct symbol
*) SYMBOL_VALUE (prev
);
1326 sym
= global_sym_chain
[hash
];
1333 sym
= (struct symbol
*) SYMBOL_VALUE (sym
);
1338 /* Defined global or text symbol: record as a misc function
1339 if it didn't give its address to a debugger symbol above. */
1340 if (buf
.n_type
<= (N_TYPE
| N_EXT
)
1341 && buf
.n_type
!= N_EXT
1343 record_misc_function (namestring
, buf
.n_value
);
1347 if (last_source_file
)
1348 end_symtab (end_of_text_addr
);
1351 discard_cleanups (old_chain
);
1354 /* dbx allows the text of a symbol name to be continued into the
1355 next symbol name! When such a continuation is encountered
1356 (a \ at the end of the text of a name)
1357 call this function to get the continuation. */
1363 fread (&buf
, sizeof buf
, 1, nlist_stream_global
);
1365 return buf
.n_un
.n_strx
+ stringtab_global
;
1372 register char *p
= name
;
1373 register int total
= p
[0];
1386 return total
% HASHSIZE
;
1389 /* Put all appropriate global symbols in the symseg data
1390 onto the hash chains so that their addresses will be stored
1391 when seen later in loader global symbols. */
1396 /* Look at each symbol in each block in each symseg symtab. */
1398 for (s
= symseg_chain
; s
; s
= s
->next
)
1401 for (n
= BLOCKVECTOR_NBLOCKS (BLOCKVECTOR (s
)) - 1; n
>= 0; n
--)
1403 register struct block
*b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), n
);
1405 for (i
= BLOCK_NSYMS (b
) - 1; i
>= 0; i
--)
1407 register struct symbol
*sym
= BLOCK_SYM (b
, i
);
1409 /* Put the symbol on a chain if its value is an address
1410 that is figured out by the loader. */
1412 if (SYMBOL_CLASS (sym
) == LOC_EXTERNAL
)
1414 register int hash
= hashname (SYMBOL_NAME (sym
));
1415 SYMBOL_VALUE (sym
) = (int) global_sym_chain
[hash
];
1416 global_sym_chain
[hash
] = sym
;
1417 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1425 process_one_symbol (type
, desc
, value
, name
)
1430 register struct context_stack
*new;
1432 /* Something is wrong if we see real data before
1433 seeing a source file name. */
1436 if (type
== N_NSYMS
) return;
1439 if (type
!= N_SO
&& last_source_file
== 0)
1440 error ("Invalid symbol data: does not start by identifying a source file.");
1446 /* Either of these types of symbols indicates the start of
1447 a new function. We must process its "name" normally for dbx,
1448 but also record the start of a new lexical context, and possibly
1449 also the end of the lexical context for the previous function. */
1450 new = context_stack
;
1451 within_function
= 1;
1454 /* Make a block for the local symbols within. */
1455 finish_block (new->name
, &local_symbols
, new->old_blocks
,
1456 new->start_addr
, value
);
1460 new = (struct context_stack
*) xmalloc (sizeof (struct context_stack
));
1463 context_stack
= new;
1466 new->old_blocks
= pending_blocks
;
1467 new->start_addr
= value
;
1468 new->name
= define_symbol (value
, name
, desc
);
1473 /* This "symbol" just indicates the start of an inner lexical
1474 context within a function. */
1475 new = (struct context_stack
*) xmalloc (sizeof (struct context_stack
));
1477 new->next
= context_stack
;
1478 context_stack
= new;
1479 new->locals
= local_symbols
;
1480 new->old_blocks
= pending_blocks
;
1481 new->start_addr
= value
;
1487 /* This "symbol" just indicates the end of an inner lexical
1488 context that was started with N_RBRAC. */
1489 new = context_stack
;
1490 if (new == 0 || desc
!= new->depth
)
1491 error ("Invalid symbol data: N_LBRAC/N_RBRAC symbol mismatch, symtab pos %d.", symnum
);
1492 local_symbols
= new->locals
;
1493 context_stack
= new->next
;
1494 /* If this is not the outermost LBRAC...RBRAC pair in the
1495 function, its local symbols preceded it, and are the ones
1496 just recovered from the context stack. Defined the block for them.
1498 If this is the outermost LBRAC...RBRAC pair, there is no
1499 need to do anything; leave the symbols that preceded it
1500 to be attached to the function's own block. */
1501 if (local_symbols
&& context_stack
->next
)
1503 /* Muzzle a compiler bug that makes end > start. */
1504 if (new->start_addr
> value
)
1505 new->start_addr
= value
;
1506 /* Make a block for the local symbols within. */
1507 finish_block (0, &local_symbols
, new->old_blocks
,
1508 new->start_addr
+ last_source_start_addr
,
1509 value
+ last_source_start_addr
);
1515 /* This kind of symbol supposedly indicates the start
1516 of an object file. In fact this type does not appear. */
1520 /* This type of symbol indicates the start of data
1521 for one source file.
1522 Finish the symbol table of the previous source file
1523 (if any) and start accumulating a new symbol table. */
1524 if (last_source_file
)
1526 start_symtab (name
, value
);
1530 /* This type of symbol indicates the start of data for
1531 a sub-source-file, one whose contents were copied or
1532 included in the compilation of the main source file
1533 (whose name was given in the N_SO symbol.) */
1534 start_subfile (name
);
1540 add_new_header_file (name
, value
);
1541 start_subfile (name
);
1545 start_subfile (pop_subfile ());
1549 add_old_header_file (name
, value
);
1551 #endif /* have N_BINCL */
1554 /* This type of "symbol" really just records
1555 one line-number -- core-address correspondence.
1556 Enter it in the line list for this symbol table. */
1557 record_line (desc
, value
);
1562 define_symbol (value
, name
, desc
);
1566 /************************ READ_ADDL_SYM() ***********************************/
1569 read_addl_syms (desc
, stringtab
, nlistlen
, text_addr
, text_size
)
1571 register char *stringtab
;
1572 register int nlistlen
;
1576 FILE *stream
= fdopen (desc
, "r");
1578 register char *namestring
;
1579 register struct symbol
*sym
, *prev
;
1581 int num_object_files
= 0;
1587 nlist_stream_global
= stream
;
1588 nlist_size_global
= nlistlen
;
1589 stringtab_global
= stringtab
;
1590 last_source_file
= 0;
1591 bzero (global_sym_chain
, sizeof global_sym_chain
);
1593 for (symnum
= 0; symnum
< nlistlen
; symnum
++)
1597 fread (&buf
, sizeof buf
, 1, stream
);
1599 type
= buf
.n_type
& N_TYPE
;
1600 if( (type
== N_TEXT
) || (type
== N_DATA
) || (type
== N_BSS
) )
1602 buf
.n_value
+= text_addr
;
1603 } /* Right?? ###### */
1606 namestring
= buf
.n_un
.n_strx
? buf
.n_un
.n_strx
+ stringtab
: "";
1607 if (buf
.n_type
& N_STAB
)
1608 process_one_symbol (buf
.n_type
, buf
.n_desc
,
1609 buf
.n_value
, namestring
);
1610 /* A static text symbol whose name ends in ".o"
1611 can only mean the start of another object file.
1612 So end the symtab of the source file we have been processing.
1613 This is how we avoid counting the libraries as part
1614 or the last source file.
1615 Also this way we find end of first object file (crt0). */
1616 else if (buf
.n_type
== N_TEXT
1617 && !strcmp (namestring
+ strlen (namestring
) - 2, ".o"))
1619 if (num_object_files
++ == 1)
1620 first_object_file_end
= buf
.n_value
;
1621 if (last_source_file
)
1623 end_symtab (buf
.n_value
); /* All this not used##### */
1626 else if (buf
.n_type
& N_EXT
|| buf
.n_type
== N_TEXT
)
1630 /* Record the location of _etext. */
1631 if (buf
.n_type
== (N_TEXT
| N_EXT
)
1632 && !strcmp (namestring
, "_etext"))
1634 end_of_text_addr
= buf
.n_value
;
1637 /* Global symbol: see if we came across a dbx definition
1638 for a corresponding symbol. If so, store the value.
1639 Remove syms from the chain when their values are stored,
1640 but search the whole chain, as there may be several syms
1641 from different files with the same name. */
1642 if (buf
.n_type
& N_EXT
)
1645 #ifdef NAMES_HAVE_UNDERSCORE
1646 hash
= hashname (namestring
+ 1);
1647 #else /* not NAMES_HAVE_UNDERSCORE */
1648 hash
= hashname (namestring
);
1649 #endif /* not NAMES_HAVE_UNDERSCORE */
1650 for (sym
= global_sym_chain
[hash
];
1654 #ifdef NAMES_HAVE_UNDERSCORE
1656 && namestring
[1] == SYMBOL_NAME (sym
)[0]
1658 !strcmp (namestring
+ 2, SYMBOL_NAME (sym
) + 1)
1659 #else /* NAMES_HAVE_UNDERSCORE */
1660 namestring
[0] == SYMBOL_NAME (sym
)[0]
1662 !strcmp (namestring
+ 1, SYMBOL_NAME (sym
) + 1)
1663 #endif /* NAMES_HAVE_UNDERSCORE */
1667 SYMBOL_VALUE (prev
) = SYMBOL_VALUE (sym
);
1669 global_sym_chain
[hash
]
1670 = (struct symbol
*) SYMBOL_VALUE (sym
);
1671 SYMBOL_VALUE (sym
) = buf
.n_value
;
1673 sym
= (struct symbol
*) SYMBOL_VALUE (prev
);
1675 sym
= global_sym_chain
[hash
];
1682 sym
= (struct symbol
*) SYMBOL_VALUE (sym
);
1687 /* Defined global or text symbol: record as a misc function
1688 if it didn't give its address to a debugger symbol above. */
1689 if (buf
.n_type
<= (N_TYPE
| N_EXT
)
1690 && buf
.n_type
!= N_EXT
1692 record_misc_function (namestring
, buf
.n_value
);
1696 if (last_source_file
)
1698 end_symtab (text_addr
+ text_size
);
1704 /***************************** CONDENSE_ADDL_MISC_BUNCHES *******************/
1707 condense_addl_misc_bunches ()
1710 register struct misc_bunch
*bunch
;
1711 #ifdef NAMES_HAVE_UNDERSCORE
1717 misc_function_vector
1718 = (struct misc_function
*) xrealloc (misc_function_vector
,
1719 (misc_count
+ misc_function_count
) * sizeof (struct misc_function
));
1721 j
= misc_function_count
;
1725 for (i
= 0; i
< misc_bunch_index
; i
++)
1727 misc_function_vector
[j
] = bunch
->contents
[i
];
1728 misc_function_vector
[j
].name
1729 = concat (misc_function_vector
[j
].name
1730 + (misc_function_vector
[j
].name
[0] == '_' ? offset
: 0),
1734 bunch
= bunch
->next
;
1735 misc_bunch_index
= MISC_BUNCH_SIZE
;
1738 misc_function_count
+= misc_count
;
1740 /* Sort the misc functions by address. */
1742 qsort (misc_function_vector
, misc_function_count
,
1743 sizeof (struct misc_function
), compare_misc_functions
);
1746 /**************************** ADD_FILE_COMMAND() ****************************/
1747 /* This function allows the addition of incrementally linked object files.
1748 Useful for debugging `sun_kick'. */
1751 add_file_command (arg_string
)
1756 struct nlist
*nlist
;
1760 extern void close ();
1761 struct cleanup
*old_chain
;
1765 for( ; *arg_string
== ' '; arg_string
++ );
1767 for( ; *arg_string
!= ' ' ; arg_string
++ );
1768 *arg_string
++ = (char) 0;
1769 for( ; *arg_string
== ' '; arg_string
++ );
1770 text_addr
= (unsigned) atoi(arg_string
);
1772 printf("filename \"%s\", and text_addr = 0x%x\n", name
, text_addr
);
1778 if (symtab_list
&& !query ("Discard symbol table? ", 0))
1779 error ("Not confirmed.");
1780 free_all_symtabs ();
1784 /* if (symtab_list && !query ("Add new symbols from \"%s\"? ", name))
1785 error ("Not confirmed.");
1788 char *absolute_name
;
1789 desc
= openp (getenv ("PATH"), 1, name
, O_RDONLY
, 0, &absolute_name
);
1791 perror_with_name (name
);
1793 name
= absolute_name
;
1796 old_chain
= make_cleanup (close
, desc
);
1797 make_cleanup (free_current_contents
, &name
);
1799 val
= myread (desc
, &hdr
, sizeof hdr
);
1801 perror_with_name (name
);
1804 error ("File \"%s\" has a bad header.", name
);
1806 if (hdr
.a_syms
== 0)
1808 printf ("%s does not have a symbol-table.\n", name
);
1813 /* Now read the string table, all at once. */
1814 val
= lseek (desc
, N_SYMOFF (hdr
) + hdr
.a_syms
, 0);
1816 perror_with_name (name
);
1817 val
= myread (desc
, &buffer
, sizeof buffer
);
1819 perror_with_name (name
);
1820 stringtab
= (char *) alloca (buffer
);
1821 bcopy (&buffer
, stringtab
, sizeof buffer
);
1822 val
= myread (desc
, stringtab
+ sizeof buffer
, buffer
- sizeof buffer
);
1824 perror_with_name (name
);
1826 /* That puts us at the symsegs. Read them. ########## Also need other
1827 changes if they exist. */
1830 /* Position to read the symbol table. Do not read it all at once. */
1831 val
= lseek (desc
, N_SYMOFF (hdr
), 0);
1833 perror_with_name (name
);
1835 printf ("Reading symbol data from %s...", name
);
1838 init_misc_functions ();
1839 make_cleanup (discard_misc_bunches
, 0);
1840 init_header_files ();
1841 make_cleanup (free_header_files
, 0);
1843 read_addl_syms (desc
, stringtab
, hdr
.a_syms
/ sizeof(struct nlist
)
1844 ,text_addr
, hdr
.a_text
) ;
1846 /* Sort symbols alphabetically within each block. */
1850 /* Go over the all misc functions and install them in vector. */
1852 condense_addl_misc_bunches ();
1854 /* Don't allow char * to have a typename (else would get caddr_t.) */
1856 TYPE_NAME (lookup_pointer_type (builtin_type_char
)) = 0;
1858 /* Make a default for file to list. */
1860 select_source_symtab (symtab_list
);
1862 do_cleanups (old_chain
);
1864 /* Free the symtabs made by read_symsegs, but not their contents,
1865 which have been copied into symtabs on symtab_list. */
1866 while (symseg_chain
)
1868 register struct symtab
*s
= symseg_chain
->next
;
1869 free (symseg_chain
);
1877 static struct symbol
*
1878 define_symbol (value
, string
, desc
)
1883 register struct symbol
*sym
1884 = (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
1885 char *p
= (char *) index (string
, ':');
1889 bzero (sym
, sizeof (struct symbol
));
1890 SYMBOL_NAME (sym
) = obstack_copy0 (symbol_obstack
, string
, p
- string
);
1892 /* Determine the type of name being defined. */
1893 if ((*p
>= '0' && *p
<= '9') || *p
== '(')
1898 /* c is a special case, not followed by a type-number.
1899 SYMBOL:c=iVALUE for an integer constant symbol.
1900 SYMBOL:c=rVALUE for a floating constant symbol. */
1904 error ("Invalid symbol data at symtab pos %d.", symnum
);
1909 double d
= atof (p
);
1912 SYMBOL_TYPE (sym
) = builtin_type_double
;
1913 value
= (char *) obstack_alloc (symbol_obstack
, sizeof (double));
1914 bcopy (&d
, value
, sizeof (double));
1915 SYMBOL_VALUE_BYTES (sym
) = value
;
1916 SYMBOL_CLASS (sym
) = LOC_CONST
;
1921 SYMBOL_TYPE (sym
) = builtin_type_int
;
1922 SYMBOL_VALUE (sym
) = atoi (p
);
1923 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
1927 error ("Invalid symbol data at symtab pos %d.", symnum
);
1929 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1930 add_symbol_to_list (sym
, &file_symbols
);
1934 /* Now usually comes a number that says which data type,
1935 and possibly more stuff to define the type
1936 (all of which is handled by read_type) */
1938 if (deftype
== 'p' && *p
== 'F')
1939 /* pF is a two-letter code that means a function parameter in Fortran.
1940 The type-number specifies the type of the return value.
1941 Translate it into a pointer-to-function type. */
1945 = lookup_pointer_type (lookup_function_type (read_type (&p
)));
1948 SYMBOL_TYPE (sym
) = read_type (&p
);
1953 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1954 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1955 add_symbol_to_list (sym
, &file_symbols
);
1959 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1960 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1961 add_symbol_to_list (sym
, &global_symbols
);
1965 /* For a class G (global) symbol, it appears that the
1966 value is not correct. It is necessary to search for the
1967 corresponding linker definition to find the value.
1968 These definitions appear at the end of the namelist. */
1969 i
= hashname (SYMBOL_NAME (sym
));
1970 SYMBOL_VALUE (sym
) = (int) global_sym_chain
[i
];
1971 global_sym_chain
[i
] = sym
;
1972 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1973 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1974 add_symbol_to_list (sym
, &global_symbols
);
1977 /* This case is faked by a conditional above,
1978 when there is no code letter in the dbx data.
1979 Dbx data never actually contains 'l'. */
1981 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1982 SYMBOL_VALUE (sym
) = value
;
1983 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1984 add_symbol_to_list (sym
, &local_symbols
);
1988 SYMBOL_CLASS (sym
) = LOC_ARG
;
1989 SYMBOL_VALUE (sym
) = value
;
1990 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1991 add_symbol_to_list (sym
, &local_symbols
);
1992 /* DESC == 0 implies compiled with GCC.
1993 In this case, if it says `short', believe it. */
1996 /* If PCC says a parameter is a short or a char,
1997 it is really an int. */
1998 if (SYMBOL_TYPE (sym
) == builtin_type_char
1999 || SYMBOL_TYPE (sym
) == builtin_type_short
)
2000 SYMBOL_TYPE (sym
) = builtin_type_int
;
2001 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
2002 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
2003 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
2007 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
2008 SYMBOL_VALUE (sym
) = value
;
2009 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2010 add_symbol_to_list (sym
, &local_symbols
);
2014 /* Static symbol at top level of file */
2015 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2016 SYMBOL_VALUE (sym
) = value
;
2017 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2018 add_symbol_to_list (sym
, &file_symbols
);
2022 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2023 SYMBOL_VALUE (sym
) = value
;
2024 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2025 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
2026 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
2027 TYPE_NAME (SYMBOL_TYPE (sym
)) = concat (SYMBOL_NAME (sym
), "", "");
2028 /* C++ vagaries: we may have a type which is derived from
2029 a base type which did not have its name defined when the
2030 derived class was output. We fill in the derived class's
2031 base part member's name here in that case. */
2032 else if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
2033 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
2034 && TYPE_BASECLASS (SYMBOL_TYPE (sym
))
2035 && TYPE_FIELD_NAME (SYMBOL_TYPE (sym
), 0) == 0)
2036 TYPE_FIELD_NAME (SYMBOL_TYPE (sym
), 0) = TYPE_NAME (TYPE_BASECLASS (SYMBOL_TYPE (sym
)));
2038 add_symbol_to_list (sym
, &file_symbols
);
2042 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
2043 SYMBOL_VALUE (sym
) = value
;
2044 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
2045 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
2046 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
2047 TYPE_NAME (SYMBOL_TYPE (sym
))
2049 (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_ENUM
2051 : (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
2052 ? "struct " : "union ")),
2054 add_symbol_to_list (sym
, &file_symbols
);
2059 /* Static symbol of local scope */
2060 SYMBOL_CLASS (sym
) = LOC_STATIC
;
2061 SYMBOL_VALUE (sym
) = value
;
2062 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2063 add_symbol_to_list (sym
, &local_symbols
);
2067 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype
, symnum
);
2072 /* Read a number by which a type is referred to in dbx data,
2073 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
2074 Just a single number N is equivalent to (0,N).
2075 Return the two numbers by storing them in the vector TYPENUMS.
2076 TYPENUMS will then be used as an argument to dbx_lookup_type. */
2079 read_type_number (pp
, typenums
)
2081 register int *typenums
;
2086 typenums
[0] = read_number (pp
, ',');
2087 typenums
[1] = read_number (pp
, ')');
2092 typenums
[1] = read_number (pp
, 0);
2096 /* Read a dbx type reference or definition;
2097 return the type that is meant.
2098 This can be just a number, in which case it references
2099 a type already defined and placed in type_vector.
2100 Or the number can be followed by an =, in which case
2101 it means to define a new type according to the text that
2109 register struct type
*type
= 0;
2115 read_type_number (pp
, typenums
);
2117 /* Detect random reference to type not yet defined.
2118 Allocate a type object but leave it zeroed. */
2120 return dbx_alloc_type (typenums
);
2126 type
= dbx_alloc_type (typenums
);
2127 /* Set the type code according to the following letter. */
2131 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2134 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2137 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2140 /* Skip the name the cross-ref points to. */
2141 /* Note: for C++, the cross reference may be to a base type which
2142 has not yet been seen. In this case, we skip to the comma,
2143 which will mark the end of the base class name. (The ':'
2144 at the end of the base class name will be skipped as well.) */
2145 *pp
= (char *) index (*pp
, ',');
2146 /* Just allocate the type and leave it zero if nothing known */
2147 return dbx_alloc_type (typenums
);
2161 read_type_number (pp
, xtypenums
);
2162 type
= *dbx_lookup_type (xtypenums
);
2164 type
= builtin_type_void
;
2165 *dbx_lookup_type (typenums
) = type
;
2169 type
= dbx_alloc_type (typenums
);
2170 smash_to_pointer_type (type
, read_type (pp
));
2175 struct type
*domain
= read_type (pp
);
2177 struct type
*ptrtype
;
2179 if (*(*pp
)++ != ',')
2180 error ("invalid member pointer data format, at symtab pos %d.",
2183 ptrtype
= read_type (pp
);
2184 type
= dbx_alloc_type (typenums
);
2185 smash_to_member_pointer_type (type
, domain
, ptrtype
);
2190 type
= dbx_alloc_type (typenums
);
2191 smash_to_reference_type (type
, read_type (pp
));
2195 type
= dbx_alloc_type (typenums
);
2196 smash_to_function_type (type
, read_type (pp
));
2200 type
= read_range_type (pp
, typenums
);
2201 *dbx_lookup_type (typenums
) = type
;
2205 type
= dbx_alloc_type (typenums
);
2206 type
= read_enum_type (pp
, type
);
2207 *dbx_lookup_type (typenums
) = type
;
2211 type
= dbx_alloc_type (typenums
);
2212 type
= read_struct_type (pp
, type
);
2216 type
= dbx_alloc_type (typenums
);
2217 type
= read_struct_type (pp
, type
);
2218 TYPE_CODE (type
) = TYPE_CODE_UNION
;
2222 /* Define an array type. */
2223 type
= dbx_alloc_type (typenums
);
2225 /* dbx expresses array types in terms of a range type for the index,
2226 and that range type is specified right inside the array type spec
2227 making ar1;MIN;MAX;VALTYPE */
2228 if (!strncmp (*pp
, "r1;0;", 5))
2230 else if (!strncmp (*pp
, "r(0,1);0;", 9))
2234 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
2235 /* In Fortran, an upper bound may be T... meaning a parameter specifies
2236 the length of the data. In this case, just pretend the bound is 1.
2237 This happens only for array parameters, which are really passed
2238 as pointers anyway, and we will translate them into such. */
2246 n
= read_number (pp
, ';') + 1;
2247 TYPE_TARGET_TYPE (type
) = read_type (pp
);
2248 TYPE_LENGTH (type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) * n
;
2252 error ("Invalid symbol data: unrecognized type-code `%c' at symtab pos %d.",
2260 /* If this is an overriding temporary alteration for a header file's
2261 contents, and this type number is unknown in the global definition,
2262 put this type into the global definition at this type number. */
2263 if (header_file_prev_index
>= 0)
2265 register struct type
**tp
2266 = explicit_lookup_type (header_file_prev_index
, typenums
[1]);
2274 /* This page contains subroutines of read_type. */
2276 /* Read the description of a structure (or union type)
2277 and return an object describing the type. */
2279 static struct type
*
2280 read_struct_type (pp
, type
)
2282 register struct type
*type
;
2286 struct nextfield
*next
;
2293 struct next_fnfield
*next
;
2295 struct fn_field fn_field
;
2298 struct next_fnfieldlist
2300 struct next_fnfieldlist
*next
;
2301 struct fn_fieldlist fn_fieldlist
;
2304 register struct nextfield
*list
= 0;
2305 struct nextfield
*new;
2312 register struct next_fnfieldlist
*mainlist
= 0;
2314 struct type
*baseclass
= NULL
;
2315 int read_possible_virtual_info
= 0;
2317 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
2319 /* First comes the total size in bytes. */
2321 TYPE_LENGTH (type
) = read_number (pp
, 0);
2323 /* C++: Now, if the class is a derived class, then the next character
2324 will be a '!', followed by the type of the base class. Allocate
2325 pretend that that base class is a sub-structure of this one,
2326 with its field name being the type name of the derived class. This
2327 cannot cause a naming conflict, since field names cannot be
2328 type names. This will magically recurse itself to gound terms
2329 when all is read and done. */
2339 TYPE_VIA_PROTECTED (type
) = 1;
2342 TYPE_VIA_PUBLIC (type
) = 1;
2345 error ("Invalid symbol data: bad visibility format at symtab pos %d.",
2349 if (**pp
== '\\') *pp
= next_symbol_text ();
2350 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
2354 baseclass
= read_type (pp
);
2355 list
->field
.type
= baseclass
;
2356 list
->field
.name
= TYPE_NAME (baseclass
);
2357 *pp
+= 1; /* skip ',' */
2358 list
->field
.bitpos
= 0;
2359 list
->field
.bitsize
= 0; /* this should be an unpacked field! */
2363 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
2364 At the end, we see a semicolon instead of a field.
2366 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2369 The `?' is a placeholder for one of '+' (public visibility),
2370 '0' (protected visibility), and '-' (private visibility). */
2376 /* Check for and handle cretinous dbx symbol name continuation! */
2377 if (**pp
== '\\') *pp
= next_symbol_text ();
2379 /* Get space to record the next field's data. */
2380 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
2384 /* Read the data. */
2386 while (*p
!= ':') p
++;
2387 list
->field
.name
= savestring (*pp
, p
- *pp
);
2389 /* Check to see if we have hit the methods yet. */
2395 /* This means we have a visibility for a field coming. */
2416 /* else normal dbx-style format. */
2418 list
->field
.type
= read_type (pp
);
2421 list
->field
.bitpos
= (long)-1;
2423 while (*p
!= ';') p
++;
2424 list
->field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2429 else if (**pp
!= ',')
2430 error ("Invalid symbol data: bad structure-type format at symtab pos %d.",
2432 (*pp
)++; /* Skip the comma. */
2433 list
->field
.bitpos
= read_number (pp
, ',');
2434 list
->field
.bitsize
= read_number (pp
, ';');
2435 /* Detect an unpacked field and mark it as such.
2436 dbx gives a bit size for all fields.
2437 Also detect forward refs to structures and unions,
2438 and treat enums as if they had the width of ints. */
2439 if ((list
->field
.bitsize
== 8 * TYPE_LENGTH (list
->field
.type
)
2440 || TYPE_CODE (list
->field
.type
) == TYPE_CODE_STRUCT
2441 || TYPE_CODE (list
->field
.type
) == TYPE_CODE_UNION
2442 || (TYPE_CODE (list
->field
.type
) == TYPE_CODE_ENUM
2443 && list
->field
.bitsize
== 8 * TYPE_LENGTH (builtin_type_int
)))
2445 list
->field
.bitpos
% 8 == 0)
2446 list
->field
.bitsize
= 0;
2450 /* Now come the method fields, as NAME::methods
2451 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
2452 At the end, we see a semicolon instead of a field.
2454 For the case of overloaded operators, the format is
2455 OPERATOR::*.methods, where OPERATOR is the string "operator",
2456 `*' holds the place for an operator name (such as `+=')
2457 and `.' marks the end of the operator name. */
2460 /* Now, read in the methods. To simplify matters, we
2461 "unread" the name that has been read, so that we can
2462 start from the top. */
2466 /* chill the list of fields: the last entry (at the head)
2467 is a partially constructed entry which we now scrub. */
2470 /* For each list of method lists... */
2474 struct next_fnfield
*sublist
= 0;
2475 struct fn_field
*fn_fields
= 0;
2477 struct next_fnfieldlist
*new_mainlist
=
2478 (struct next_fnfieldlist
*)alloca (sizeof (struct next_fnfieldlist
));
2480 /* read in the name. */
2481 while (*p
!= ':') p
++;
2482 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == '$')
2484 static char opname
[32] = "operator ";
2485 char *o
= opname
+ 9;
2487 /* Skip past '::'. */
2491 new_mainlist
->fn_fieldlist
.name
= savestring (opname
, o
- opname
);
2498 new_mainlist
->fn_fieldlist
.name
= savestring (*pp
, p
- *pp
);
2499 /* Skip past '::'. */
2505 struct next_fnfield
*new_sublist
=
2506 (struct next_fnfield
*)alloca (sizeof (struct next_fnfield
));
2508 /* Check for and handle cretinous dbx symbol name continuation! */
2509 if (**pp
== '\\') *pp
= next_symbol_text ();
2511 new_sublist
->fn_field
.type
= read_type (pp
);
2512 new_sublist
->fn_field
.args
= read_args (pp
, ':');
2514 while (*p
!= ';') p
++;
2515 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
2517 new_sublist
->visibility
= *(*pp
)++ - '0';
2518 if (**pp
== '\\') *pp
= next_symbol_text ();
2520 if (*(*pp
)++ == '*')
2521 new_sublist
->fn_field
.voffset
= read_number (pp
, ';') + 1;
2523 new_sublist
->fn_field
.voffset
= 0;
2525 new_sublist
->next
= sublist
;
2526 sublist
= new_sublist
;
2529 while (**pp
!= ';');
2533 new_mainlist
->fn_fieldlist
.fn_fields
=
2534 (struct fn_field
*) obstack_alloc (symbol_obstack
,
2535 sizeof (struct fn_field
) * length
);
2536 TYPE_FN_PRIVATE_BITS (new_mainlist
->fn_fieldlist
) =
2537 (int *) obstack_alloc (symbol_obstack
,
2538 sizeof (int) * (1 + (length
>> 5)));
2540 TYPE_FN_PROTECTED_BITS (new_mainlist
->fn_fieldlist
) =
2541 (int *) obstack_alloc (symbol_obstack
,
2542 sizeof (int) * (1 + (length
>> 5)));
2544 for (i
= length
; sublist
; sublist
= sublist
->next
)
2546 new_mainlist
->fn_fieldlist
.fn_fields
[--i
] = sublist
->fn_field
;
2547 if (sublist
->visibility
== 0)
2548 B_SET (new_mainlist
->fn_fieldlist
.private_fn_field_bits
, i
);
2549 else if (sublist
->visibility
== 1)
2550 B_SET (new_mainlist
->fn_fieldlist
.protected_fn_field_bits
, i
);
2553 new_mainlist
->fn_fieldlist
.length
= length
;
2554 new_mainlist
->next
= mainlist
;
2555 mainlist
= new_mainlist
;
2558 while (**pp
!= ';');
2564 read_possible_virtual_info
= 1;
2569 TYPE_HAS_DESTRUCTOR (type
) = 1;
2570 TYPE_HAS_CONSTRUCTOR (type
) = 1;
2573 else if (**pp
== '+')
2575 TYPE_HAS_CONSTRUCTOR (type
) = 1;
2581 /* Now create the vector of fields, and record how big it is. */
2583 TYPE_NFIELDS (type
) = nfields
;
2584 TYPE_FIELDS (type
) = (struct field
*) obstack_alloc (symbol_obstack
,
2585 sizeof (struct field
) * nfields
);
2586 TYPE_FIELD_PRIVATE_BITS (type
) =
2587 (int *) obstack_alloc (symbol_obstack
,
2588 sizeof (int) * (1 + (nfields
>> 5)));
2589 TYPE_FIELD_PROTECTED_BITS (type
) =
2590 (int *) obstack_alloc (symbol_obstack
,
2591 sizeof (int) * (1 + (nfields
>> 5)));
2593 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2594 TYPE_NFN_FIELDS_TOTAL (type
) = nfn_fields
;
2596 TYPE_NFN_FIELDS_TOTAL (type
) += TYPE_NFN_FIELDS_TOTAL (baseclass
);
2598 TYPE_FN_FIELDLISTS (type
) =
2599 (struct fn_fieldlist
*) obstack_alloc (symbol_obstack
,
2600 sizeof (struct fn_fieldlist
) * nfn_fields
);
2602 /* Copy the saved-up fields into the field vector. */
2604 for (n
= nfields
; list
; list
= list
->next
)
2606 TYPE_FIELD (type
, --n
) = list
->field
;
2607 if (list
->visibility
== 0)
2608 SET_TYPE_FIELD_PRIVATE (type
, n
);
2609 else if (list
->visibility
== 1)
2610 SET_TYPE_FIELD_PROTECTED (type
, n
);
2613 for (n
= nfn_fields
; mainlist
; mainlist
= mainlist
->next
)
2614 TYPE_FN_FIELDLISTS (type
)[--n
] = mainlist
->fn_fieldlist
;
2616 TYPE_BASECLASS (type
) = baseclass
;
2618 if (read_possible_virtual_info
)
2620 /* Read either a '%' or the final ';'. */
2621 if (*(*pp
)++ == '%')
2623 /* Now we must record the virtual function table pointer's
2624 field information. */
2631 while (*p
!= ';') p
++;
2632 TYPE_VPTR_BASETYPE (type
) = t
;
2635 if (TYPE_FIELD_NAME (t
, 0) == 0)
2636 TYPE_VPTR_FIELDNO (type
) = i
= 0;
2637 else for (i
= TYPE_NFIELDS (t
) - 1; i
>= 0; --i
)
2638 if (! strncmp (TYPE_FIELD_NAME (t
, i
), *pp
,
2639 strlen (TYPE_FIELD_NAME (t
, i
))))
2641 TYPE_VPTR_FIELDNO (type
) = i
;
2645 error ("virtual function table field not found");
2648 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
));
2653 TYPE_VPTR_BASETYPE (type
) = 0;
2654 TYPE_VPTR_FIELDNO (type
) = -1;
2659 TYPE_VPTR_BASETYPE (type
) = 0;
2660 TYPE_VPTR_FIELDNO (type
) = -1;
2666 /* Read a definition of an enumeration type,
2667 and create and return a suitable type object.
2668 Also defines the symbols that represent the values of the type. */
2670 static struct type
*
2671 read_enum_type (pp
, type
)
2673 register struct type
*type
;
2678 register struct symbol
*sym
;
2680 struct pending
**symlist
;
2681 struct pending
*osyms
, *syms
;
2683 if (within_function
)
2684 symlist
= &local_symbols
;
2686 symlist
= &file_symbols
;
2689 /* Read the value-names and their values.
2690 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2691 A semicolon instead of a NAME means the end. */
2692 while (**pp
&& **pp
!= ';')
2694 /* Check for and handle cretinous dbx symbol name continuation! */
2695 if (**pp
== '\\') *pp
= next_symbol_text ();
2698 while (*p
!= ':') p
++;
2699 name
= savestring (*pp
, p
- *pp
);
2701 n
= read_number (pp
, ',');
2703 sym
= (struct symbol
*) xmalloc (sizeof (struct symbol
));
2704 bzero (sym
, sizeof (struct symbol
));
2705 SYMBOL_NAME (sym
) = name
;
2706 SYMBOL_CLASS (sym
) = LOC_CONST
;
2707 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2708 SYMBOL_VALUE (sym
) = n
;
2709 add_symbol_to_list (sym
, symlist
);
2713 (*pp
)++; /* Skip the semicolon. */
2715 /* Now fill in the fields of the type-structure. */
2717 TYPE_LENGTH (type
) = sizeof (int);
2718 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2719 TYPE_NFIELDS (type
) = nsyms
;
2720 TYPE_FIELDS (type
) = (struct field
*) obstack_alloc (symbol_obstack
, sizeof (struct field
) * nsyms
);
2722 /* Find the symbols for the values and put them into the type.
2723 The symbols can be found in the symlist that we put them on
2724 to cause them to be defined. osyms contains the old value
2725 of that symlist; everything up to there was defined by us. */
2727 for (syms
= *symlist
, n
= nsyms
; syms
!= osyms
; syms
= syms
->next
)
2729 SYMBOL_TYPE (syms
->symbol
) = type
;
2730 TYPE_FIELD_NAME (type
, --n
) = SYMBOL_NAME (syms
->symbol
);
2731 TYPE_FIELD_VALUE (type
, n
) = SYMBOL_VALUE (syms
->symbol
);
2732 TYPE_FIELD_BITPOS (type
, n
) = 0;
2733 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2739 static struct type
*
2740 read_range_type (pp
, typenums
)
2748 /* First comes a type we are a subrange of.
2749 In practice it is usually 0, 1 or the type being defined. */
2750 read_type_number (pp
, rangenums
);
2753 /* A semicolon should now follow; skip it. */
2757 /* The remaining two operands are usually lower and upper bounds
2758 of the range. But in some special cases they mean something else. */
2759 n2
= read_number (pp
, ';');
2760 n3
= read_number (pp
, ';');
2762 /* A type defined as a subrange of itself, with bounds both 0, is void. */
2763 if (rangenums
[0] == typenums
[0] && rangenums
[1] == typenums
[1]
2764 && n2
== 0 && n3
== 0)
2765 return builtin_type_void
;
2767 /* If n3 is zero and n2 is not, we want a floating type,
2768 and n2 is the width in bytes.
2770 Fortran programs appear to use this for complex types also,
2771 and they give no way to distinguish between double and single-complex!
2772 We don't have complex types, so we would lose on all fortran files!
2773 So return type `double' for all of those. It won't work right
2774 for the complex values, but at least it makes the file loadable. */
2776 if (n3
== 0 && n2
> 0)
2778 if (n2
== sizeof (float))
2779 return builtin_type_float
;
2780 return builtin_type_double
;
2783 /* If the upper bound is -1, it must really be an unsigned int. */
2785 else if (n2
== 0 && n3
== -1)
2787 if (sizeof (int) == sizeof (long))
2788 return builtin_type_unsigned_int
;
2790 return builtin_type_unsigned_long
;
2793 /* Detect unsigned subranges of int. Int is normally 1.
2794 Note that `char' is usually given bounds of 0 to 127,
2795 and would therefore appear unsigned; but it is described
2796 as a subrange of itself, so we reject it here. */
2798 else if (n2
== 0 && n1
== 1)
2800 /* an unsigned type */
2801 if (n3
== (1 << (8 * sizeof (int))) - 1)
2802 return builtin_type_unsigned_int
;
2803 if (n3
== (1 << (8 * sizeof (short))) - 1)
2804 return builtin_type_unsigned_short
;
2805 if (n3
== (1 << (8 * sizeof (char))) - 1)
2806 return builtin_type_unsigned_char
;
2811 if (n3
== (1 << (8 * sizeof (int) - 1)) - 1)
2812 return builtin_type_int
;
2813 if (n3
== (1 << (8 * sizeof (long) - 1)) - 1)
2814 return builtin_type_long
;
2815 if (n3
== (1 << (8 * sizeof (short) - 1)) - 1)
2816 return builtin_type_short
;
2817 if (n3
== (1 << (8 * sizeof (char) - 1)) - 1)
2818 return builtin_type_char
;
2820 error ("Invalid symbol data: range type spec %s at symtab pos %d.",
2824 /* Read a number from the string pointed to by *PP.
2825 The value of *PP is advanced over the number.
2826 If END is nonzero, the character that ends the
2827 number must match END, or an error happens;
2828 and that character is skipped if it does match.
2829 If END is zero, *PP is left pointing to that character. */
2832 read_number (pp
, end
)
2836 register char *p
= *pp
;
2837 register long n
= 0;
2841 /* Handle an optional leading minus sign. */
2849 /* Read the digits, as far as they go. */
2851 while ((c
= *p
++) >= '0' && c
<= '9')
2859 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c
, symnum
);
2868 /* Read in an argument list. This is a list of types. It is terminated with
2869 a ':', FYI. Return the list of types read in. */
2870 static struct type
**
2875 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
2881 error ("Invalid argument list: no ',', at symtab pos %d", symnum
);
2883 types
[n
++] = read_type (pp
);
2885 *pp
+= 1; /* get past `end' (the ':' character) */
2889 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
2893 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
2895 bcopy (types
, rval
, n
* sizeof (struct type
*));
2899 /* This function is really horrible, but to avoid it, there would need
2900 to be more filling in of forward references. */
2902 fill_in_vptr_fieldno (type
)
2905 if (TYPE_VPTR_FIELDNO (type
) < 0)
2906 TYPE_VPTR_FIELDNO (type
) = fill_in_vptr_fieldno (TYPE_BASECLASS (type
));
2907 return TYPE_VPTR_FIELDNO (type
);
2915 add_com ("symbol-file", class_files
, symbol_file_command
,
2916 "Load symbol table (in dbx format) from executable file FILE.");
2918 add_com ("add-file", class_files
, add_file_command
,
2919 "Load the symbols from FILE, assuming its codes is at TEXT_START.") ;
2924 #endif /* READ_DBX_FORMAT */