1 /* Build symbol tables in GDB's internal format.
2 Copyright (C) 1986-1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* This module provides subroutines used for creating and adding to
21 the symbol table. These routines are called from various symbol-
22 file-reading routines.
24 They originated in dbxread.c of gdb-4.2, and were split out to
25 make xcoffread.c more maintainable by sharing code. */
31 #include "breakpoint.h"
32 #include "gdbcore.h" /* for bfd stuff for symfile.h */
33 #include "symfile.h" /* Needed for "struct complaint" */
34 #include "stab.gnu.h" /* We always use GNU stabs, not native */
39 /* Ask buildsym.h to define the vars it normally declares `extern'. */
41 #include "buildsym.h" /* Our own declarations */
45 extern double atof ();
47 /* Things we export from outside, and probably shouldn't. FIXME. */
48 extern void new_object_header_files ();
49 extern char *next_symbol_text ();
50 extern int hashname ();
51 extern void patch_block_stabs (); /* AIX xcoffread.c */
52 extern struct type *builtin_type (); /* AIX xcoffread.c */
55 static void cleanup_undefined_types ();
56 static void fix_common_block ();
58 static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' };
59 static const char vb_name[] = { '_','v','b',CPLUS_MARKER,'\0' };
61 /* Define this as 1 if a pcc declaration of a char or short argument
62 gives the correct address. Otherwise assume pcc gives the
63 address of the corresponding int, which is not the same on a
64 big-endian machine. */
66 #ifndef BELIEVE_PCC_PROMOTION
67 #define BELIEVE_PCC_PROMOTION 0
70 /* Make a list of forward references which haven't been defined. */
71 static struct type **undef_types;
72 static int undef_types_allocated, undef_types_length;
74 /* Initial sizes of data structures. These are realloc'd larger if needed,
75 and realloc'd down to the size actually used, when completed. */
77 #define INITIAL_CONTEXT_STACK_SIZE 10
78 #define INITIAL_TYPE_VECTOR_LENGTH 160
79 #define INITIAL_LINE_VECTOR_LENGTH 1000
81 /* Complaints about the symbols we have encountered. */
83 struct complaint innerblock_complaint =
84 {"inner block not inside outer block in %s", 0, 0};
86 struct complaint blockvector_complaint =
87 {"block at %x out of order", 0, 0};
90 struct complaint dbx_class_complaint =
91 {"encountered DBX-style class variable debugging information.\n\
92 You seem to have compiled your program with \
93 \"g++ -g0\" instead of \"g++ -g\".\n\
94 Therefore GDB will not know about your class variables", 0, 0};
97 struct complaint const_vol_complaint =
98 {"const/volatile indicator missing (ok if using g++ v1.x), got '%c'", 0, 0};
100 struct complaint error_type_complaint =
101 {"debug info mismatch between compiler and debugger", 0, 0};
103 struct complaint invalid_member_complaint =
104 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
106 struct complaint range_type_base_complaint =
107 {"base type %d of range type is not defined", 0, 0};
109 /* Look up a dbx type-number pair. Return the address of the slot
110 where the type for that number-pair is stored.
111 The number-pair is in TYPENUMS.
113 This can be used for finding the type associated with that pair
114 or for associating a new type with the pair. */
117 dbx_lookup_type (typenums)
120 register int filenum = typenums[0], index = typenums[1];
123 if (filenum < 0 || filenum >= n_this_object_header_files)
124 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
125 filenum, index, symnum);
129 /* Type is defined outside of header files.
130 Find it in this object file's type vector. */
131 if (index >= type_vector_length)
133 old_len = type_vector_length;
135 type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
136 type_vector = (struct type **)
137 malloc (type_vector_length * sizeof (struct type *));
139 while (index >= type_vector_length)
140 type_vector_length *= 2;
141 type_vector = (struct type **)
142 xrealloc (type_vector,
143 (type_vector_length * sizeof (struct type *)));
144 bzero (&type_vector[old_len],
145 (type_vector_length - old_len) * sizeof (struct type *));
147 return &type_vector[index];
151 register int real_filenum = this_object_header_files[filenum];
152 register struct header_file *f;
155 if (real_filenum >= n_header_files)
158 f = &header_files[real_filenum];
160 f_orig_length = f->length;
161 if (index >= f_orig_length)
163 while (index >= f->length)
165 f->vector = (struct type **)
166 xrealloc (f->vector, f->length * sizeof (struct type *));
167 bzero (&f->vector[f_orig_length],
168 (f->length - f_orig_length) * sizeof (struct type *));
170 return &f->vector[index];
174 /* Create a type object. Occaisionally used when you need a type
175 which isn't going to be given a type number. */
180 register struct type *type =
181 (struct type *) obstack_alloc (symbol_obstack, sizeof (struct type));
183 bzero (type, sizeof (struct type));
184 TYPE_VPTR_FIELDNO (type) = -1;
185 TYPE_VPTR_BASETYPE (type) = 0;
189 /* Make sure there is a type allocated for type numbers TYPENUMS
190 and return the type object.
191 This can create an empty (zeroed) type object.
192 TYPENUMS may be (-1, -1) to return a new type object that is not
193 put into the type vector, and so may not be referred to by number. */
196 dbx_alloc_type (typenums)
199 register struct type **type_addr;
200 register struct type *type;
202 if (typenums[0] != -1)
204 type_addr = dbx_lookup_type (typenums);
213 /* If we are referring to a type not known at all yet,
214 allocate an empty type for it.
215 We will fill it in later if we find out how. */
218 type = dbx_create_type ();
226 /* maintain the lists of symbols and blocks */
228 /* Add a symbol to one of the lists of symbols. */
230 add_symbol_to_list (symbol, listhead)
231 struct symbol *symbol;
232 struct pending **listhead;
234 /* We keep PENDINGSIZE symbols in each link of the list.
235 If we don't have a link with room in it, add a new link. */
236 if (*listhead == 0 || (*listhead)->nsyms == PENDINGSIZE)
238 register struct pending *link;
241 link = free_pendings;
242 free_pendings = link->next;
245 link = (struct pending *) xmalloc (sizeof (struct pending));
247 link->next = *listhead;
252 (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
255 /* Find a symbol on a pending list. */
257 find_symbol_in_list (list, name, length)
258 struct pending *list;
265 for (j = list->nsyms; --j >= 0; ) {
266 char *pp = SYMBOL_NAME (list->symbol[j]);
267 if (*pp == *name && strncmp (pp, name, length) == 0 && pp[length] == '\0')
268 return list->symbol[j];
275 /* At end of reading syms, or in case of quit,
276 really free as many `struct pending's as we can easily find. */
280 really_free_pendings (foo)
283 struct pending *next, *next1;
285 struct pending_block *bnext, *bnext1;
288 for (next = free_pendings; next; next = next1)
295 #if 0 /* Now we make the links in the symbol_obstack, so don't free them. */
296 for (bnext = pending_blocks; bnext; bnext = bnext1)
298 bnext1 = bnext->next;
304 for (next = file_symbols; next; next = next1)
311 for (next = global_symbols; next; next = next1)
319 /* Take one of the lists of symbols and make a block from it.
320 Keep the order the symbols have in the list (reversed from the input file).
321 Put the block on the list of pending blocks. */
324 finish_block (symbol, listhead, old_blocks, start, end)
325 struct symbol *symbol;
326 struct pending **listhead;
327 struct pending_block *old_blocks;
328 CORE_ADDR start, end;
330 register struct pending *next, *next1;
331 register struct block *block;
332 register struct pending_block *pblock;
333 struct pending_block *opblock;
336 /* Count the length of the list of symbols. */
338 for (next = *listhead, i = 0;
340 i += next->nsyms, next = next->next)
343 block = (struct block *) obstack_alloc (symbol_obstack,
344 (sizeof (struct block) + ((i - 1) * sizeof (struct symbol *))));
346 /* Copy the symbols into the block. */
348 BLOCK_NSYMS (block) = i;
349 for (next = *listhead; next; next = next->next)
352 for (j = next->nsyms - 1; j >= 0; j--)
353 BLOCK_SYM (block, --i) = next->symbol[j];
356 BLOCK_START (block) = start;
357 BLOCK_END (block) = end;
358 BLOCK_SUPERBLOCK (block) = 0; /* Filled in when containing block is made */
359 BLOCK_GCC_COMPILED (block) = processing_gcc_compilation;
361 /* Put the block in as the value of the symbol that names it. */
365 SYMBOL_BLOCK_VALUE (symbol) = block;
366 BLOCK_FUNCTION (block) = symbol;
369 BLOCK_FUNCTION (block) = 0;
371 /* Now "free" the links of the list, and empty the list. */
373 for (next = *listhead; next; next = next1)
376 next->next = free_pendings;
377 free_pendings = next;
381 /* Install this block as the superblock
382 of all blocks made since the start of this scope
383 that don't have superblocks yet. */
386 for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next)
388 if (BLOCK_SUPERBLOCK (pblock->block) == 0) {
390 /* Check to be sure the blocks are nested as we receive them.
391 If the compiler/assembler/linker work, this just burns a small
393 if (BLOCK_START (pblock->block) < BLOCK_START (block)
394 || BLOCK_END (pblock->block) > BLOCK_END (block)) {
395 complain(&innerblock_complaint, symbol? SYMBOL_NAME (symbol):
397 BLOCK_START (pblock->block) = BLOCK_START (block);
398 BLOCK_END (pblock->block) = BLOCK_END (block);
401 BLOCK_SUPERBLOCK (pblock->block) = block;
406 /* Record this block on the list of all blocks in the file.
407 Put it after opblock, or at the beginning if opblock is 0.
408 This puts the block in the list after all its subblocks. */
410 /* Allocate in the symbol_obstack to save time.
411 It wastes a little space. */
412 pblock = (struct pending_block *)
413 obstack_alloc (symbol_obstack,
414 sizeof (struct pending_block));
415 pblock->block = block;
418 pblock->next = opblock->next;
419 opblock->next = pblock;
423 pblock->next = pending_blocks;
424 pending_blocks = pblock;
431 register struct pending_block *next;
432 register struct blockvector *blockvector;
435 /* Count the length of the list of blocks. */
437 for (next = pending_blocks, i = 0; next; next = next->next, i++);
439 blockvector = (struct blockvector *)
440 obstack_alloc (symbol_obstack,
441 (sizeof (struct blockvector)
442 + (i - 1) * sizeof (struct block *)));
444 /* Copy the blocks into the blockvector.
445 This is done in reverse order, which happens to put
446 the blocks into the proper order (ascending starting address).
447 finish_block has hair to insert each block into the list
448 after its subblocks in order to make sure this is true. */
450 BLOCKVECTOR_NBLOCKS (blockvector) = i;
451 for (next = pending_blocks; next; next = next->next) {
452 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
455 #if 0 /* Now we make the links in the obstack, so don't free them. */
456 /* Now free the links of the list, and empty the list. */
458 for (next = pending_blocks; next; next = next1)
466 #if 1 /* FIXME, shut this off after a while to speed up symbol reading. */
467 /* Some compilers output blocks in the wrong order, but we depend
468 on their being in the right order so we can binary search.
469 Check the order and moan about it. FIXME. */
470 if (BLOCKVECTOR_NBLOCKS (blockvector) > 1)
471 for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++) {
472 if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i-1))
473 > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i))) {
474 complain (&blockvector_complaint,
475 BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i)));
483 /* Start recording information about source code that came from an included
484 (or otherwise merged-in) source file with a different name. */
487 start_subfile (name, dirname)
491 register struct subfile *subfile;
493 /* See if this subfile is already known as a subfile of the
494 current main source file. */
496 for (subfile = subfiles; subfile; subfile = subfile->next)
498 if (!strcmp (subfile->name, name))
500 current_subfile = subfile;
505 /* This subfile is not known. Add an entry for it.
506 Make an entry for this subfile in the list of all subfiles
507 of the current main source file. */
509 subfile = (struct subfile *) xmalloc (sizeof (struct subfile));
510 subfile->next = subfiles;
512 current_subfile = subfile;
514 /* Save its name and compilation directory name */
515 subfile->name = obsavestring (name, strlen (name));
517 subfile->dirname = NULL;
519 subfile->dirname = obsavestring (dirname, strlen (dirname));
521 /* Initialize line-number recording for this subfile. */
522 subfile->line_vector = 0;
525 /* Handle the N_BINCL and N_EINCL symbol types
526 that act like N_SOL for switching source files
527 (different subfiles, as we call them) within one object file,
528 but using a stack rather than in an arbitrary order. */
533 register struct subfile_stack *tem
534 = (struct subfile_stack *) xmalloc (sizeof (struct subfile_stack));
536 tem->next = subfile_stack;
538 if (current_subfile == 0 || current_subfile->name == 0)
540 tem->name = current_subfile->name;
541 tem->prev_index = header_file_prev_index;
548 register struct subfile_stack *link = subfile_stack;
554 subfile_stack = link->next;
555 header_file_prev_index = link->prev_index;
561 /* Manage the vector of line numbers for each subfile. */
564 record_line (subfile, line, pc)
565 register struct subfile *subfile;
569 struct linetable_entry *e;
570 /* Ignore the dummy line number in libg.o */
575 /* Make sure line vector exists and is big enough. */
576 if (!subfile->line_vector) {
577 subfile->line_vector_length = INITIAL_LINE_VECTOR_LENGTH;
578 subfile->line_vector = (struct linetable *)
579 xmalloc (sizeof (struct linetable)
580 + subfile->line_vector_length * sizeof (struct linetable_entry));
581 subfile->line_vector->nitems = 0;
584 if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length)
586 subfile->line_vector_length *= 2;
587 subfile->line_vector = (struct linetable *)
588 xrealloc (subfile->line_vector, (sizeof (struct linetable)
589 + subfile->line_vector_length * sizeof (struct linetable_entry)));
592 e = subfile->line_vector->item + subfile->line_vector->nitems++;
593 e->line = line; e->pc = pc;
597 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
601 compare_line_numbers (ln1, ln2)
602 struct linetable_entry *ln1, *ln2;
604 return ln1->line - ln2->line;
607 /* Start a new symtab for a new source file.
608 This is called when a dbx symbol of type N_SO is seen;
609 it indicates the start of data for one original source file. */
612 start_symtab (name, dirname, start_addr)
615 CORE_ADDR start_addr;
618 last_source_file = name;
619 last_source_start_addr = start_addr;
622 global_stabs = 0; /* AIX COFF */
623 file_stabs = 0; /* AIX COFF */
626 /* Context stack is initially empty. Allocate first one with room for
627 10 levels; reuse it forever afterward. */
628 if (context_stack == 0) {
629 context_stack_size = INITIAL_CONTEXT_STACK_SIZE;
630 context_stack = (struct context_stack *)
631 xmalloc (context_stack_size * sizeof (struct context_stack));
633 context_stack_depth = 0;
635 new_object_header_files ();
637 type_vector_length = 0;
638 type_vector = (struct type **) 0;
640 /* Initialize the list of sub source files with one entry
641 for this file (the top-level source file). */
645 start_subfile (name, dirname);
648 /* Finish the symbol definitions for one main source file,
649 close off all the lexical contexts for that file
650 (creating struct block's for them), then make the struct symtab
651 for that file and put it in the list of all such.
653 END_ADDR is the address of the end of the file's text. */
656 end_symtab (end_addr, sort_pending, sort_linevec, objfile)
660 struct objfile *objfile;
662 register struct symtab *symtab;
663 register struct blockvector *blockvector;
664 register struct subfile *subfile;
665 struct subfile *nextsub;
667 /* Finish the lexical context of the last function in the file;
668 pop the context stack. */
670 if (context_stack_depth > 0)
672 register struct context_stack *cstk;
673 context_stack_depth--;
674 cstk = &context_stack[context_stack_depth];
675 /* Make a block for the local symbols within. */
676 finish_block (cstk->name, &local_symbols, cstk->old_blocks,
677 cstk->start_addr, end_addr);
679 /* Debug: if context stack still has something in it, we are in
681 if (context_stack_depth > 0)
685 /* It is unfortunate that in aixcoff, pending blocks might not be ordered
686 in this stage. Especially, blocks for static functions will show up at
687 the end. We need to sort them, so tools like `find_pc_function' and
688 `find_pc_block' can work reliably. */
689 if (sort_pending && pending_blocks) {
690 /* FIXME! Remove this horrid bubble sort and use qsort!!! */
693 struct pending_block *pb, *pbnext;
695 pb = pending_blocks, pbnext = pb->next;
700 /* swap blocks if unordered! */
702 if (BLOCK_START(pb->block) < BLOCK_START(pbnext->block)) {
703 struct block *tmp = pb->block;
704 pb->block = pbnext->block;
709 pbnext = pbnext->next;
714 /* Cleanup any undefined types that have been left hanging around
715 (this needs to be done before the finish_blocks so that
716 file_symbols is still good). */
717 cleanup_undefined_types ();
719 /* Hooks for xcoffread.c */
721 patch_block_stabs (file_symbols, file_stabs);
727 patch_block_stabs (global_symbols, global_stabs);
732 if (pending_blocks == 0
734 && global_symbols == 0) {
735 /* Ignore symtabs that have no functions with real debugging info */
738 /* Define the STATIC_BLOCK and GLOBAL_BLOCK, and build the blockvector. */
739 finish_block (0, &file_symbols, 0, last_source_start_addr, end_addr);
740 finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr);
741 blockvector = make_blockvector ();
744 /* Now create the symtab objects proper, one for each subfile. */
745 /* (The main file is the last one on the chain.) */
747 for (subfile = subfiles; subfile; subfile = nextsub)
749 /* If we have blocks of symbols, make a symtab.
750 Otherwise, just ignore this file and any line number info in it. */
753 if (subfile->line_vector) {
754 /* First, shrink the linetable to make more memory. */
755 subfile->line_vector = (struct linetable *)
756 xrealloc (subfile->line_vector, (sizeof (struct linetable)
757 + subfile->line_vector->nitems * sizeof (struct linetable_entry)));
760 qsort (subfile->line_vector->item, subfile->line_vector->nitems,
761 sizeof (struct linetable_entry), compare_line_numbers);
764 /* Now, allocate a symbol table. */
765 symtab = allocate_symtab (subfile->name, objfile);
767 /* Fill in its components. */
768 symtab->blockvector = blockvector;
769 symtab->linetable = subfile->line_vector;
770 symtab->dirname = subfile->dirname;
771 symtab->free_code = free_linetable;
772 symtab->free_ptr = 0;
774 /* Link the new symtab into the list of such. */
775 symtab->next = symtab_list;
776 symtab_list = symtab;
778 /* No blocks for this file. Delete any line number info we have
780 if (subfile->line_vector)
781 free (subfile->line_vector);
784 nextsub = subfile->next;
789 free ((char *) type_vector);
791 type_vector_length = 0;
793 last_source_file = 0;
800 /* Push a context block. Args are an identifying nesting level (checkable
801 when you pop it), and the starting PC address of this context. */
803 struct context_stack *
804 push_context (desc, valu)
808 register struct context_stack *new;
810 if (context_stack_depth == context_stack_size)
812 context_stack_size *= 2;
813 context_stack = (struct context_stack *)
814 xrealloc (context_stack,
816 * sizeof (struct context_stack)));
819 new = &context_stack[context_stack_depth++];
821 new->locals = local_symbols;
822 new->old_blocks = pending_blocks;
823 new->start_addr = valu;
831 /* Initialize anything that needs initializing when starting to read
832 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
844 /* Initialize anything that needs initializing when a completely new
845 symbol file is specified (not just adding some symbols from another
846 file, e.g. a shared library). */
851 /* Empty the hash table of global syms looking for values. */
852 bzero (global_sym_chain, sizeof global_sym_chain);
857 /* Scan through all of the global symbols defined in the object file,
858 assigning values to the debugging symbols that need to be assigned
859 to. Get these symbols from the misc function list. */
867 for (mf = 0; mf < misc_function_count; mf++)
869 char *namestring = misc_function_vector[mf].name;
870 struct symbol *sym, *prev;
874 prev = (struct symbol *) 0;
876 /* Get the hash index and check all the symbols
877 under that hash index. */
879 hash = hashname (namestring);
881 for (sym = global_sym_chain[hash]; sym;)
883 if (*namestring == SYMBOL_NAME (sym)[0]
884 && !strcmp(namestring + 1, SYMBOL_NAME (sym) + 1))
886 /* Splice this symbol out of the hash chain and
887 assign the value we have to it. */
889 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
891 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
893 /* Check to see whether we need to fix up a common block. */
894 /* Note: this code might be executed several times for
895 the same symbol if there are multiple references. */
896 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
897 fix_common_block (sym, misc_function_vector[mf].address);
899 SYMBOL_VALUE_ADDRESS (sym) = misc_function_vector[mf].address;
902 sym = SYMBOL_VALUE_CHAIN (prev);
904 sym = global_sym_chain[hash];
909 sym = SYMBOL_VALUE_CHAIN (sym);
916 /* Read a number by which a type is referred to in dbx data,
917 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
918 Just a single number N is equivalent to (0,N).
919 Return the two numbers by storing them in the vector TYPENUMS.
920 TYPENUMS will then be used as an argument to dbx_lookup_type. */
923 read_type_number (pp, typenums)
925 register int *typenums;
930 typenums[0] = read_number (pp, ',');
931 typenums[1] = read_number (pp, ')');
936 typenums[1] = read_number (pp, 0);
940 /* To handle GNU C++ typename abbreviation, we need to be able to
941 fill in a type's name as soon as space for that type is allocated.
942 `type_synonym_name' is the name of the type being allocated.
943 It is cleared as soon as it is used (lest all allocated types
945 static char *type_synonym_name;
949 define_symbol (valu, string, desc, type)
955 register struct symbol *sym;
956 char *p = (char *) strchr (string, ':');
961 /* Ignore syms with empty names. */
965 /* Ignore old-style symbols from cc -go */
969 sym = (struct symbol *)obstack_alloc (symbol_obstack, sizeof (struct symbol));
971 if (processing_gcc_compilation) {
972 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
973 number of bytes occupied by a type or object, which we ignore. */
974 SYMBOL_LINE(sym) = desc;
976 SYMBOL_LINE(sym) = 0; /* unknown */
979 if (string[0] == CPLUS_MARKER)
981 /* Special GNU C++ names. */
985 SYMBOL_NAME (sym) = "this";
987 case 'v': /* $vtbl_ptr_type */
988 /* Was: SYMBOL_NAME (sym) = "vptr"; */
991 SYMBOL_NAME (sym) = "eh_throw";
995 /* This was an anonymous type that was never fixed up. */
1006 = (char *) obstack_alloc (symbol_obstack, ((p - string) + 1));
1007 /* Open-coded bcopy--saves function call time. */
1009 register char *p1 = string;
1010 register char *p2 = SYMBOL_NAME (sym);
1017 /* Determine the type of name being defined. */
1018 /* The Acorn RISC machine's compiler can put out locals that don't
1019 start with "234=" or "(3,4)=", so assume anything other than the
1020 deftypes we know how to handle is a local. */
1021 /* (Peter Watkins @ Computervision)
1022 Handle Sun-style local fortran array types 'ar...' .
1025 if (!strchr ("cfFGpPrStTvVXC", *p))
1030 /* c is a special case, not followed by a type-number.
1031 SYMBOL:c=iVALUE for an integer constant symbol.
1032 SYMBOL:c=rVALUE for a floating constant symbol.
1033 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1034 e.g. "b:c=e6,0" for "const b = blob1"
1035 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1039 error ("Invalid symbol data at symtab pos %d.", symnum);
1044 double d = atof (p);
1047 SYMBOL_TYPE (sym) = builtin_type_double;
1049 (char *) obstack_alloc (symbol_obstack, sizeof (double));
1050 bcopy (&d, dbl_valu, sizeof (double));
1051 SWAP_TARGET_AND_HOST (dbl_valu, sizeof (double));
1052 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
1053 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
1058 SYMBOL_TYPE (sym) = builtin_type_int;
1059 SYMBOL_VALUE (sym) = atoi (p);
1060 SYMBOL_CLASS (sym) = LOC_CONST;
1064 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1065 e.g. "b:c=e6,0" for "const b = blob1"
1066 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1070 read_type_number (&p, typenums);
1072 error ("Invalid symbol data: no comma in enum const symbol");
1074 SYMBOL_TYPE (sym) = *dbx_lookup_type (typenums);
1075 SYMBOL_VALUE (sym) = atoi (p);
1076 SYMBOL_CLASS (sym) = LOC_CONST;
1080 error ("Invalid symbol data at symtab pos %d.", symnum);
1082 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1083 add_symbol_to_list (sym, &file_symbols);
1087 /* Now usually comes a number that says which data type,
1088 and possibly more stuff to define the type
1089 (all of which is handled by read_type) */
1091 if (deftype == 'p' && *p == 'F')
1092 /* pF is a two-letter code that means a function parameter in Fortran.
1093 The type-number specifies the type of the return value.
1094 Translate it into a pointer-to-function type. */
1098 = lookup_pointer_type (lookup_function_type (read_type (&p)));
1102 struct type *type_read;
1103 synonym = *p == 't';
1108 type_synonym_name = obsavestring (SYMBOL_NAME (sym),
1109 strlen (SYMBOL_NAME (sym)));
1112 type_read = read_type (&p);
1114 if ((deftype == 'F' || deftype == 'f')
1115 && TYPE_CODE (type_read) != TYPE_CODE_FUNC)
1118 /* This code doesn't work -- it needs to realloc and can't. */
1119 struct type *new = (struct type *)
1120 obstack_alloc (symbol_obstack, sizeof (struct type));
1122 /* Generate a template for the type of this function. The
1123 types of the arguments will be added as we read the symbol
1125 *new = *lookup_function_type (type_read);
1126 SYMBOL_TYPE(sym) = new;
1127 in_function_type = new;
1129 SYMBOL_TYPE (sym) = lookup_function_type (type_read);
1133 SYMBOL_TYPE (sym) = type_read;
1139 /* The name of a caught exception. */
1140 SYMBOL_CLASS (sym) = LOC_LABEL;
1141 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1142 SYMBOL_VALUE_ADDRESS (sym) = valu;
1143 add_symbol_to_list (sym, &local_symbols);
1147 SYMBOL_CLASS (sym) = LOC_BLOCK;
1148 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1149 add_symbol_to_list (sym, &file_symbols);
1153 SYMBOL_CLASS (sym) = LOC_BLOCK;
1154 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1155 add_symbol_to_list (sym, &global_symbols);
1159 /* For a class G (global) symbol, it appears that the
1160 value is not correct. It is necessary to search for the
1161 corresponding linker definition to find the value.
1162 These definitions appear at the end of the namelist. */
1163 i = hashname (SYMBOL_NAME (sym));
1164 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
1165 global_sym_chain[i] = sym;
1166 SYMBOL_CLASS (sym) = LOC_STATIC;
1167 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1168 add_symbol_to_list (sym, &global_symbols);
1171 /* This case is faked by a conditional above,
1172 when there is no code letter in the dbx data.
1173 Dbx data never actually contains 'l'. */
1175 SYMBOL_CLASS (sym) = LOC_LOCAL;
1176 SYMBOL_VALUE (sym) = valu;
1177 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1178 add_symbol_to_list (sym, &local_symbols);
1182 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1183 can also be a LOC_LOCAL_ARG depending on symbol type. */
1184 #ifndef DBX_PARM_SYMBOL_CLASS
1185 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1187 SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
1188 SYMBOL_VALUE (sym) = valu;
1189 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1191 /* This doesn't work yet. */
1192 add_param_to_type (&in_function_type, sym);
1194 add_symbol_to_list (sym, &local_symbols);
1196 /* If it's gcc-compiled, if it says `short', believe it. */
1197 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
1200 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
1201 /* This macro is defined on machines (e.g. sparc) where
1202 we should believe the type of a PCC 'short' argument,
1203 but shouldn't believe the address (the address is
1204 the address of the corresponding int). Note that
1205 this is only different from the BELIEVE_PCC_PROMOTION
1206 case on big-endian machines.
1208 My guess is that this correction, as opposed to changing
1209 the parameter to an 'int' (as done below, for PCC
1210 on most machines), is the right thing to do
1211 on all machines, but I don't want to risk breaking
1212 something that already works. On most PCC machines,
1213 the sparc problem doesn't come up because the calling
1214 function has to zero the top bytes (not knowing whether
1215 the called function wants an int or a short), so there
1216 is no practical difference between an int and a short
1217 (except perhaps what happens when the GDB user types
1218 "print short_arg = 0x10000;").
1221 actually produces the correct address (we don't need to fix it
1222 up). I made this code adapt so that it will offset the symbol
1223 if it was pointing at an int-aligned location and not
1224 otherwise. This way you can use the same gdb for 4.0.x and
1227 if (0 == SYMBOL_VALUE (sym) % sizeof (int))
1229 if (SYMBOL_TYPE (sym) == builtin_type_char
1230 || SYMBOL_TYPE (sym) == builtin_type_unsigned_char)
1231 SYMBOL_VALUE (sym) += 3;
1232 else if (SYMBOL_TYPE (sym) == builtin_type_short
1233 || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
1234 SYMBOL_VALUE (sym) += 2;
1238 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1240 /* If PCC says a parameter is a short or a char,
1241 it is really an int. */
1242 if (SYMBOL_TYPE (sym) == builtin_type_char
1243 || SYMBOL_TYPE (sym) == builtin_type_short)
1244 SYMBOL_TYPE (sym) = builtin_type_int;
1245 else if (SYMBOL_TYPE (sym) == builtin_type_unsigned_char
1246 || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
1247 SYMBOL_TYPE (sym) = builtin_type_unsigned_int;
1250 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
1253 SYMBOL_CLASS (sym) = LOC_REGPARM;
1254 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1255 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1256 add_symbol_to_list (sym, &local_symbols);
1260 SYMBOL_CLASS (sym) = LOC_REGISTER;
1261 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1262 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1263 add_symbol_to_list (sym, &local_symbols);
1267 /* Static symbol at top level of file */
1268 SYMBOL_CLASS (sym) = LOC_STATIC;
1269 SYMBOL_VALUE_ADDRESS (sym) = valu;
1270 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1271 add_symbol_to_list (sym, &file_symbols);
1275 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1276 SYMBOL_VALUE (sym) = valu;
1277 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1278 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
1279 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
1280 TYPE_NAME (SYMBOL_TYPE (sym)) =
1281 obsavestring (SYMBOL_NAME (sym),
1282 strlen (SYMBOL_NAME (sym)));
1283 /* C++ vagaries: we may have a type which is derived from
1284 a base type which did not have its name defined when the
1285 derived class was output. We fill in the derived class's
1286 base part member's name here in that case. */
1287 else if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1288 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1289 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
1292 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
1293 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
1294 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
1295 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
1298 add_symbol_to_list (sym, &file_symbols);
1302 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1303 SYMBOL_VALUE (sym) = valu;
1304 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1305 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
1306 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
1307 TYPE_NAME (SYMBOL_TYPE (sym))
1309 (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM
1311 : (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1312 ? "struct " : "union ")),
1314 add_symbol_to_list (sym, &file_symbols);
1318 register struct symbol *typedef_sym
1319 = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
1320 SYMBOL_NAME (typedef_sym) = SYMBOL_NAME (sym);
1321 SYMBOL_TYPE (typedef_sym) = SYMBOL_TYPE (sym);
1323 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
1324 SYMBOL_VALUE (typedef_sym) = valu;
1325 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
1326 add_symbol_to_list (typedef_sym, &file_symbols);
1331 /* Static symbol of local scope */
1332 SYMBOL_CLASS (sym) = LOC_STATIC;
1333 SYMBOL_VALUE_ADDRESS (sym) = valu;
1334 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1335 add_symbol_to_list (sym, &local_symbols);
1339 /* Reference parameter */
1340 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1341 SYMBOL_VALUE (sym) = valu;
1342 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1343 add_symbol_to_list (sym, &local_symbols);
1347 /* This is used by Sun FORTRAN for "function result value".
1348 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1349 that Pascal uses it too, but when I tried it Pascal used
1350 "x:3" (local symbol) instead. */
1351 SYMBOL_CLASS (sym) = LOC_LOCAL;
1352 SYMBOL_VALUE (sym) = valu;
1353 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1354 add_symbol_to_list (sym, &local_symbols);
1358 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype, symnum);
1363 /* What about types defined as forward references inside of a small lexical
1365 /* Add a type to the list of undefined types to be checked through
1366 once this file has been read in. */
1368 add_undefined_type (type)
1371 if (undef_types_length == undef_types_allocated)
1373 undef_types_allocated *= 2;
1374 undef_types = (struct type **)
1375 xrealloc (undef_types,
1376 undef_types_allocated * sizeof (struct type *));
1378 undef_types[undef_types_length++] = type;
1381 /* Add here something to go through each undefined type, see if it's
1382 still undefined, and do a full lookup if so. */
1384 cleanup_undefined_types ()
1388 for (type = undef_types; type < undef_types + undef_types_length; type++)
1390 /* Reasonable test to see if it's been defined since. */
1391 if (TYPE_NFIELDS (*type) == 0)
1393 struct pending *ppt;
1395 /* Name of the type, without "struct" or "union" */
1396 char *typename = TYPE_NAME (*type);
1398 if (!strncmp (typename, "struct ", 7))
1400 if (!strncmp (typename, "union ", 6))
1403 for (ppt = file_symbols; ppt; ppt = ppt->next)
1404 for (i = 0; i < ppt->nsyms; i++)
1406 struct symbol *sym = ppt->symbol[i];
1408 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1409 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
1410 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
1412 && !strcmp (SYMBOL_NAME (sym), typename))
1413 bcopy (SYMBOL_TYPE (sym), *type, sizeof (struct type));
1417 /* It has been defined; don't mark it as a stub. */
1418 TYPE_FLAGS (*type) &= ~TYPE_FLAG_STUB;
1420 undef_types_length = 0;
1423 /* Skip rest of this symbol and return an error type.
1425 General notes on error recovery: error_type always skips to the
1426 end of the symbol (modulo cretinous dbx symbol name continuation).
1427 Thus code like this:
1429 if (*(*pp)++ != ';')
1430 return error_type (pp);
1432 is wrong because if *pp starts out pointing at '\0' (typically as the
1433 result of an earlier error), it will be incremented to point to the
1434 start of the next symbol, which might produce strange results, at least
1435 if you run off the end of the string table. Instead use
1438 return error_type (pp);
1444 foo = error_type (pp);
1448 And in case it isn't obvious, the point of all this hair is so the compiler
1449 can define new types and new syntaxes, and old versions of the
1450 debugger will be able to read the new symbol tables. */
1456 complain (&error_type_complaint, 0);
1459 /* Skip to end of symbol. */
1460 while (**pp != '\0')
1463 /* Check for and handle cretinous dbx symbol name continuation! */
1464 if ((*pp)[-1] == '\\')
1465 *pp = next_symbol_text ();
1469 return builtin_type_error;
1472 /* Read a dbx type reference or definition;
1473 return the type that is meant.
1474 This can be just a number, in which case it references
1475 a type already defined and placed in type_vector.
1476 Or the number can be followed by an =, in which case
1477 it means to define a new type according to the text that
1484 register struct type *type = 0;
1489 /* Read type number if present. The type number may be omitted.
1490 for instance in a two-dimensional array declared with type
1491 "ar1;1;10;ar1;1;10;4". */
1492 if ((**pp >= '0' && **pp <= '9')
1495 read_type_number (pp, typenums);
1497 /* Type is not being defined here. Either it already exists,
1498 or this is a forward reference to it. dbx_alloc_type handles
1501 return dbx_alloc_type (typenums);
1503 /* Type is being defined here. */
1504 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
1508 /* if such a type already exists, this is an unnecessary duplication
1509 of the stab string, which is common in (RS/6000) xlc generated
1510 objects. In that case, simply return NULL and let the caller take
1513 tt = *dbx_lookup_type (typenums);
1514 if (tt && tt->length && tt->code)
1523 /* 'typenums=' not present, type is anonymous. Read and return
1524 the definition, but don't put it in the type vector. */
1525 typenums[0] = typenums[1] = -1;
1533 enum type_code code;
1535 /* Used to index through file_symbols. */
1536 struct pending *ppt;
1539 /* Name including "struct", etc. */
1542 /* Name without "struct", etc. */
1543 char *type_name_only;
1549 /* Set the type code according to the following letter. */
1553 code = TYPE_CODE_STRUCT;
1557 code = TYPE_CODE_UNION;
1561 code = TYPE_CODE_ENUM;
1565 return error_type (pp);
1568 to = type_name = (char *)
1569 obstack_alloc (symbol_obstack,
1571 ((char *) strchr (*pp, ':') - (*pp)) + 1));
1573 /* Copy the prefix. */
1575 while (*to++ = *from++)
1579 type_name_only = to;
1581 /* Copy the name. */
1583 while ((*to++ = *from++) != ':')
1587 /* Set the pointer ahead of the name which we just read. */
1591 /* The following hack is clearly wrong, because it doesn't
1592 check whether we are in a baseclass. I tried to reproduce
1593 the case that it is trying to fix, but I couldn't get
1594 g++ to put out a cross reference to a basetype. Perhaps
1595 it doesn't do it anymore. */
1596 /* Note: for C++, the cross reference may be to a base type which
1597 has not yet been seen. In this case, we skip to the comma,
1598 which will mark the end of the base class name. (The ':'
1599 at the end of the base class name will be skipped as well.)
1600 But sometimes (ie. when the cross ref is the last thing on
1601 the line) there will be no ','. */
1602 from = (char *) strchr (*pp, ',');
1608 /* Now check to see whether the type has already been declared. */
1609 /* This is necessary at least in the case where the
1610 program says something like
1612 The compiler puts out a cross-reference; we better find
1613 set the length of the structure correctly so we can
1614 set the length of the array. */
1615 for (ppt = file_symbols; ppt; ppt = ppt->next)
1616 for (i = 0; i < ppt->nsyms; i++)
1618 struct symbol *sym = ppt->symbol[i];
1620 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1621 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
1622 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
1623 && !strcmp (SYMBOL_NAME (sym), type_name_only))
1625 obstack_free (symbol_obstack, type_name);
1626 type = SYMBOL_TYPE (sym);
1631 /* Didn't find the type to which this refers, so we must
1632 be dealing with a forward reference. Allocate a type
1633 structure for it, and keep track of it so we can
1634 fill in the rest of the fields when we get the full
1636 type = dbx_alloc_type (typenums);
1637 TYPE_CODE (type) = code;
1638 TYPE_NAME (type) = type_name;
1640 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
1642 add_undefined_type (type);
1646 case '-': /* RS/6000 built-in type */
1648 type = builtin_type (pp); /* (in xcoffread.c) */
1663 read_type_number (pp, xtypenums);
1664 type = *dbx_lookup_type (xtypenums);
1669 type = builtin_type_void;
1670 if (typenums[0] != -1)
1671 *dbx_lookup_type (typenums) = type;
1675 type1 = read_type (pp);
1676 /* FIXME -- we should be doing smash_to_XXX types here. */
1678 /* postponed type decoration should be allowed. */
1679 if (typenums[1] > 0 && typenums[1] < type_vector_length &&
1680 (type = type_vector[typenums[1]])) {
1681 smash_to_pointer_type (type, type1);
1685 type = lookup_pointer_type (type1);
1686 if (typenums[0] != -1)
1687 *dbx_lookup_type (typenums) = type;
1692 struct type *domain = read_type (pp);
1693 struct type *memtype;
1696 /* Invalid member type data format. */
1697 return error_type (pp);
1700 memtype = read_type (pp);
1701 type = dbx_alloc_type (typenums);
1702 smash_to_member_type (type, domain, memtype);
1707 if ((*pp)[0] == '#')
1709 /* We'll get the parameter types from the name. */
1710 struct type *return_type;
1713 return_type = read_type (pp);
1714 if (*(*pp)++ != ';')
1715 complain (&invalid_member_complaint, symnum);
1716 type = allocate_stub_method (return_type);
1717 if (typenums[0] != -1)
1718 *dbx_lookup_type (typenums) = type;
1722 struct type *domain = read_type (pp);
1723 struct type *return_type;
1726 if (*(*pp)++ != ',')
1727 error ("invalid member type data format, at symtab pos %d.",
1730 return_type = read_type (pp);
1731 args = read_args (pp, ';');
1732 type = dbx_alloc_type (typenums);
1733 smash_to_method_type (type, domain, return_type, args);
1738 type1 = read_type (pp);
1739 type = lookup_reference_type (type1);
1740 if (typenums[0] != -1)
1741 *dbx_lookup_type (typenums) = type;
1745 type1 = read_type (pp);
1746 type = lookup_function_type (type1);
1747 if (typenums[0] != -1)
1748 *dbx_lookup_type (typenums) = type;
1752 type = read_range_type (pp, typenums);
1753 if (typenums[0] != -1)
1754 *dbx_lookup_type (typenums) = type;
1758 type = dbx_alloc_type (typenums);
1759 type = read_enum_type (pp, type);
1760 *dbx_lookup_type (typenums) = type;
1764 type = dbx_alloc_type (typenums);
1765 TYPE_NAME (type) = type_synonym_name;
1766 type_synonym_name = 0;
1767 type = read_struct_type (pp, type);
1771 type = dbx_alloc_type (typenums);
1772 TYPE_NAME (type) = type_synonym_name;
1773 type_synonym_name = 0;
1774 type = read_struct_type (pp, type);
1775 TYPE_CODE (type) = TYPE_CODE_UNION;
1780 return error_type (pp);
1783 type = dbx_alloc_type (typenums);
1784 type = read_array_type (pp, type);
1788 --*pp; /* Go back to the symbol in error */
1789 /* Particularly important if it was \0! */
1790 return error_type (pp);
1797 /* If this is an overriding temporary alteration for a header file's
1798 contents, and this type number is unknown in the global definition,
1799 put this type into the global definition at this type number. */
1800 if (header_file_prev_index >= 0)
1802 register struct type **tp
1803 = explicit_lookup_type (header_file_prev_index, typenums[1]);
1811 /* This page contains subroutines of read_type. */
1813 /* Read the description of a structure (or union type)
1814 and return an object describing the type. */
1817 read_struct_type (pp, type)
1819 register struct type *type;
1821 /* Total number of methods defined in this class.
1822 If the class defines two `f' methods, and one `g' method,
1823 then this will have the value 3. */
1824 int total_length = 0;
1828 struct nextfield *next;
1829 int visibility; /* 0=public, 1=protected, 2=public */
1835 struct next_fnfield *next;
1836 int visibility; /* 0=public, 1=protected, 2=public */
1837 struct fn_field fn_field;
1840 struct next_fnfieldlist
1842 struct next_fnfieldlist *next;
1843 struct fn_fieldlist fn_fieldlist;
1846 register struct nextfield *list = 0;
1847 struct nextfield *new;
1852 register struct next_fnfieldlist *mainlist = 0;
1855 if (TYPE_MAIN_VARIANT (type) == 0)
1857 TYPE_MAIN_VARIANT (type) = type;
1860 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1862 /* First comes the total size in bytes. */
1864 TYPE_LENGTH (type) = read_number (pp, 0);
1866 /* C++: Now, if the class is a derived class, then the next character
1867 will be a '!', followed by the number of base classes derived from.
1868 Each element in the list contains visibility information,
1869 the offset of this base class in the derived structure,
1870 and then the base type. */
1873 int i, n_baseclasses, offset;
1874 struct type *baseclass;
1877 /* Nonzero if it is a virtual baseclass, i.e.,
1881 struct C : public B, public virtual A {};
1883 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
1884 2.0 language feature. */
1889 n_baseclasses = read_number (pp, ',');
1890 TYPE_FIELD_VIRTUAL_BITS (type) =
1891 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (n_baseclasses));
1892 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), n_baseclasses);
1894 for (i = 0; i < n_baseclasses; i++)
1897 *pp = next_symbol_text ();
1908 /* Bad visibility format. */
1909 return error_type (pp);
1922 /* Bad visibility format. */
1923 return error_type (pp);
1926 SET_TYPE_FIELD_VIRTUAL (type, i);
1929 /* Offset of the portion of the object corresponding to
1930 this baseclass. Always zero in the absence of
1931 multiple inheritance. */
1932 offset = read_number (pp, ',');
1933 baseclass = read_type (pp);
1934 *pp += 1; /* skip trailing ';' */
1936 /* Make this baseclass visible for structure-printing purposes. */
1937 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1940 list->visibility = via_public;
1941 list->field.type = baseclass;
1942 list->field.name = type_name_no_tag (baseclass);
1943 list->field.bitpos = offset;
1944 list->field.bitsize = 0; /* this should be an unpacked field! */
1947 TYPE_N_BASECLASSES (type) = n_baseclasses;
1950 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
1951 At the end, we see a semicolon instead of a field.
1953 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
1956 The `?' is a placeholder for one of '/2' (public visibility),
1957 '/1' (protected visibility), '/0' (private visibility), or nothing
1958 (C style symbol table, public visibility). */
1960 /* We better set p right now, in case there are no fields at all... */
1965 /* Check for and handle cretinous dbx symbol name continuation! */
1966 if (**pp == '\\') *pp = next_symbol_text ();
1968 /* Get space to record the next field's data. */
1969 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1973 /* Get the field name. */
1975 if (*p == CPLUS_MARKER)
1977 /* Special GNU C++ name. */
1982 struct type *context;
1993 error ("invalid abbreviation at symtab pos %d.", symnum);
1996 context = read_type (pp);
1997 name = type_name_no_tag (context);
2000 error ("type name unknown at symtab pos %d.", symnum);
2001 TYPE_NAME (context) = name;
2003 list->field.name = obconcat (prefix, name, "");
2006 error ("invalid abbreviation at symtab pos %d.", symnum);
2007 list->field.type = read_type (pp);
2008 (*pp)++; /* Skip the comma. */
2009 list->field.bitpos = read_number (pp, ';');
2010 /* This field is unpacked. */
2011 list->field.bitsize = 0;
2013 /* GNU C++ anonymous type. */
2017 error ("invalid abbreviation at symtab pos %d.", symnum);
2023 while (*p != ':') p++;
2024 list->field.name = obsavestring (*pp, p - *pp);
2026 /* C++: Check to see if we have hit the methods yet. */
2032 /* This means we have a visibility for a field coming. */
2038 list->visibility = 0; /* private */
2043 list->visibility = 1; /* protected */
2048 list->visibility = 2; /* public */
2053 else /* normal dbx-style format. */
2054 list->visibility = 2; /* public */
2056 list->field.type = read_type (pp);
2059 /* Static class member. */
2060 list->field.bitpos = (long)-1;
2062 while (*p != ';') p++;
2063 list->field.bitsize = (long) savestring (*pp, p - *pp);
2068 else if (**pp != ',')
2069 /* Bad structure-type format. */
2070 return error_type (pp);
2072 (*pp)++; /* Skip the comma. */
2073 list->field.bitpos = read_number (pp, ',');
2074 list->field.bitsize = read_number (pp, ';');
2077 /* FIXME-tiemann: Can't the compiler put out something which
2078 lets us distinguish these? (or maybe just not put out anything
2079 for the field). What is the story here? What does the compiler
2080 really do? Also, patch gdb.texinfo for this case; I document
2081 it as a possible problem there. Search for "DBX-style". */
2083 /* This is wrong because this is identical to the symbols
2084 produced for GCC 0-size arrays. For example:
2089 The code which dumped core in such circumstances should be
2090 fixed not to dump core. */
2092 /* g++ -g0 can put out bitpos & bitsize zero for a static
2093 field. This does not give us any way of getting its
2094 class, so we can't know its name. But we can just
2095 ignore the field so we don't dump core and other nasty
2097 if (list->field.bitpos == 0
2098 && list->field.bitsize == 0)
2100 complain (&dbx_class_complaint, 0);
2101 /* Ignore this field. */
2107 /* Detect an unpacked field and mark it as such.
2108 dbx gives a bit size for all fields.
2109 Note that forward refs cannot be packed,
2110 and treat enums as if they had the width of ints. */
2111 if (TYPE_CODE (list->field.type) != TYPE_CODE_INT
2112 && TYPE_CODE (list->field.type) != TYPE_CODE_ENUM)
2113 list->field.bitsize = 0;
2114 if ((list->field.bitsize == 8 * TYPE_LENGTH (list->field.type)
2115 || (TYPE_CODE (list->field.type) == TYPE_CODE_ENUM
2116 && (list->field.bitsize
2117 == 8 * TYPE_LENGTH (builtin_type_int))
2121 list->field.bitpos % 8 == 0)
2122 list->field.bitsize = 0;
2128 /* chill the list of fields: the last entry (at the head)
2129 is a partially constructed entry which we now scrub. */
2132 /* Now create the vector of fields, and record how big it is.
2133 We need this info to record proper virtual function table information
2134 for this class's virtual functions. */
2136 TYPE_NFIELDS (type) = nfields;
2137 TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack,
2138 sizeof (struct field) * nfields);
2140 TYPE_FIELD_PRIVATE_BITS (type) =
2141 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (nfields));
2142 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
2144 TYPE_FIELD_PROTECTED_BITS (type) =
2145 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (nfields));
2146 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
2148 /* Copy the saved-up fields into the field vector. */
2150 for (n = nfields; list; list = list->next)
2153 TYPE_FIELD (type, n) = list->field;
2154 if (list->visibility == 0)
2155 SET_TYPE_FIELD_PRIVATE (type, n);
2156 else if (list->visibility == 1)
2157 SET_TYPE_FIELD_PROTECTED (type, n);
2160 /* Now come the method fields, as NAME::methods
2161 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
2162 At the end, we see a semicolon instead of a field.
2164 For the case of overloaded operators, the format is
2165 OPERATOR::*.methods, where OPERATOR is the string "operator",
2166 `*' holds the place for an operator name (such as `+=')
2167 and `.' marks the end of the operator name. */
2170 /* Now, read in the methods. To simplify matters, we
2171 "unread" the name that has been read, so that we can
2172 start from the top. */
2174 /* For each list of method lists... */
2178 struct next_fnfield *sublist = 0;
2179 struct type *look_ahead_type = NULL;
2181 struct next_fnfieldlist *new_mainlist =
2182 (struct next_fnfieldlist *)alloca (sizeof (struct next_fnfieldlist));
2187 /* read in the name. */
2188 while (*p != ':') p++;
2190 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == CPLUS_MARKER)
2192 /* This lets the user type "break operator+".
2193 We could just put in "+" as the name, but that wouldn't
2195 /* I don't understand what this is trying to do.
2196 It seems completely bogus. -Per Bothner. */
2197 static char opname[32] = {'o', 'p', CPLUS_MARKER};
2198 char *o = opname + 3;
2200 /* Skip past '::'. */
2202 if (**pp == '\\') *pp = next_symbol_text ();
2206 main_fn_name = savestring (opname, o - opname);
2212 main_fn_name = savestring (*pp, p - *pp);
2213 /* Skip past '::'. */
2215 new_mainlist->fn_fieldlist.name = main_fn_name;
2219 struct next_fnfield *new_sublist =
2220 (struct next_fnfield *)alloca (sizeof (struct next_fnfield));
2222 /* Check for and handle cretinous dbx symbol name continuation! */
2223 if (look_ahead_type == NULL) /* Normal case. */
2225 if (**pp == '\\') *pp = next_symbol_text ();
2227 new_sublist->fn_field.type = read_type (pp);
2229 /* Invalid symtab info for method. */
2230 return error_type (pp);
2233 { /* g++ version 1 kludge */
2234 new_sublist->fn_field.type = look_ahead_type;
2235 look_ahead_type = NULL;
2240 while (*p != ';') p++;
2241 /* If this is just a stub, then we don't have the
2243 new_sublist->fn_field.physname = savestring (*pp, p - *pp);
2245 new_sublist->visibility = *(*pp)++ - '0';
2246 if (**pp == '\\') *pp = next_symbol_text ();
2249 case 'A': /* Normal functions. */
2250 new_sublist->fn_field.is_const = 0;
2251 new_sublist->fn_field.is_volatile = 0;
2254 case 'B': /* `const' member functions. */
2255 new_sublist->fn_field.is_const = 1;
2256 new_sublist->fn_field.is_volatile = 0;
2259 case 'C': /* `volatile' member function. */
2260 new_sublist->fn_field.is_const = 0;
2261 new_sublist->fn_field.is_volatile = 1;
2264 case 'D': /* `const volatile' member function. */
2265 new_sublist->fn_field.is_const = 1;
2266 new_sublist->fn_field.is_volatile = 1;
2270 /* This probably just means we're processing a file compiled
2271 with g++ version 1. */
2272 complain(&const_vol_complaint, **pp);
2278 /* virtual member function, followed by index. */
2279 /* The sign bit is set to distinguish pointers-to-methods
2280 from virtual function indicies. Since the array is
2281 in words, the quantity must be shifted left by 1
2282 on 16 bit machine, and by 2 on 32 bit machine, forcing
2283 the sign bit out, and usable as a valid index into
2284 the array. Remove the sign bit here. */
2285 new_sublist->fn_field.voffset =
2286 (0x7fffffff & read_number (pp, ';')) + 2;
2288 if (**pp == '\\') *pp = next_symbol_text ();
2290 if (**pp == ';' || **pp == '\0')
2291 /* Must be g++ version 1. */
2292 new_sublist->fn_field.fcontext = 0;
2295 /* Figure out from whence this virtual function came.
2296 It may belong to virtual function table of
2297 one of its baseclasses. */
2298 look_ahead_type = read_type (pp);
2300 { /* g++ version 1 overloaded methods. */ }
2303 new_sublist->fn_field.fcontext = look_ahead_type;
2305 return error_type (pp);
2308 look_ahead_type = NULL;
2314 /* static member function. */
2315 new_sublist->fn_field.voffset = VOFFSET_STATIC;
2319 /* normal member function. */
2320 new_sublist->fn_field.voffset = 0;
2321 new_sublist->fn_field.fcontext = 0;
2325 new_sublist->next = sublist;
2326 sublist = new_sublist;
2328 if (**pp == '\\') *pp = next_symbol_text ();
2330 while (**pp != ';' && **pp != '\0');
2334 new_mainlist->fn_fieldlist.fn_fields =
2335 (struct fn_field *) obstack_alloc (symbol_obstack,
2336 sizeof (struct fn_field) * length);
2337 TYPE_FN_PRIVATE_BITS (new_mainlist->fn_fieldlist) =
2338 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (length));
2339 B_CLRALL (TYPE_FN_PRIVATE_BITS (new_mainlist->fn_fieldlist), length);
2341 TYPE_FN_PROTECTED_BITS (new_mainlist->fn_fieldlist) =
2342 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (length));
2343 B_CLRALL (TYPE_FN_PROTECTED_BITS (new_mainlist->fn_fieldlist), length);
2345 for (i = length; (i--, sublist); sublist = sublist->next)
2347 new_mainlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
2348 if (sublist->visibility == 0)
2349 B_SET (new_mainlist->fn_fieldlist.private_fn_field_bits, i);
2350 else if (sublist->visibility == 1)
2351 B_SET (new_mainlist->fn_fieldlist.protected_fn_field_bits, i);
2354 new_mainlist->fn_fieldlist.length = length;
2355 new_mainlist->next = mainlist;
2356 mainlist = new_mainlist;
2358 total_length += length;
2360 while (**pp != ';');
2365 TYPE_FN_FIELDLISTS (type) =
2366 (struct fn_fieldlist *) obstack_alloc (symbol_obstack,
2367 sizeof (struct fn_fieldlist) * nfn_fields);
2369 TYPE_NFN_FIELDS (type) = nfn_fields;
2370 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
2374 for (i = 0; i < TYPE_N_BASECLASSES (type); ++i)
2375 TYPE_NFN_FIELDS_TOTAL (type) +=
2376 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type, i));
2379 for (n = nfn_fields; mainlist; mainlist = mainlist->next)
2380 TYPE_FN_FIELDLISTS (type)[--n] = mainlist->fn_fieldlist;
2386 if (**pp == '=' || **pp == '+' || **pp == '-')
2388 /* Obsolete flags that used to indicate the presence
2389 of constructors and/or destructors. */
2393 /* Read either a '%' or the final ';'. */
2394 if (*(*pp)++ == '%')
2396 /* Now we must record the virtual function table pointer's
2397 field information. */
2404 while (*p != '\0' && *p != ';')
2407 /* Premature end of symbol. */
2408 return error_type (pp);
2410 TYPE_VPTR_BASETYPE (type) = t;
2413 if (TYPE_FIELD_NAME (t, TYPE_N_BASECLASSES (t)) == 0)
2415 /* FIXME-tiemann: what's this? */
2417 TYPE_VPTR_FIELDNO (type) = i = TYPE_N_BASECLASSES (t);
2422 else for (i = TYPE_NFIELDS (t) - 1; i >= TYPE_N_BASECLASSES (t); --i)
2423 if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name,
2424 sizeof (vptr_name) -1))
2426 TYPE_VPTR_FIELDNO (type) = i;
2430 /* Virtual function table field not found. */
2431 return error_type (pp);
2434 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
2442 /* Read a definition of an array type,
2443 and create and return a suitable type object.
2444 Also creates a range type which represents the bounds of that
2447 read_array_type (pp, type)
2449 register struct type *type;
2451 struct type *index_type, *element_type, *range_type;
2455 /* Format of an array type:
2456 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2459 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2460 for these, produce a type like float[][]. */
2462 index_type = read_type (pp);
2464 /* Improper format of array type decl. */
2465 return error_type (pp);
2468 if (!(**pp >= '0' && **pp <= '9'))
2473 lower = read_number (pp, ';');
2475 if (!(**pp >= '0' && **pp <= '9'))
2480 upper = read_number (pp, ';');
2482 element_type = read_type (pp);
2491 /* Create range type. */
2492 range_type = (struct type *) obstack_alloc (symbol_obstack,
2493 sizeof (struct type));
2494 TYPE_CODE (range_type) = TYPE_CODE_RANGE;
2495 TYPE_TARGET_TYPE (range_type) = index_type;
2497 /* This should never be needed. */
2498 TYPE_LENGTH (range_type) = sizeof (int);
2500 TYPE_NFIELDS (range_type) = 2;
2501 TYPE_FIELDS (range_type) =
2502 (struct field *) obstack_alloc (symbol_obstack,
2503 2 * sizeof (struct field));
2504 TYPE_FIELD_BITPOS (range_type, 0) = lower;
2505 TYPE_FIELD_BITPOS (range_type, 1) = upper;
2508 TYPE_CODE (type) = TYPE_CODE_ARRAY;
2509 TYPE_TARGET_TYPE (type) = element_type;
2510 TYPE_LENGTH (type) = (upper - lower + 1) * TYPE_LENGTH (element_type);
2511 TYPE_NFIELDS (type) = 1;
2512 TYPE_FIELDS (type) =
2513 (struct field *) obstack_alloc (symbol_obstack,
2514 sizeof (struct field));
2515 TYPE_FIELD_TYPE (type, 0) = range_type;
2521 /* Read a definition of an enumeration type,
2522 and create and return a suitable type object.
2523 Also defines the symbols that represent the values of the type. */
2526 read_enum_type (pp, type)
2528 register struct type *type;
2533 register struct symbol *sym;
2535 struct pending **symlist;
2536 struct pending *osyms, *syms;
2539 if (within_function)
2540 symlist = &local_symbols;
2542 symlist = &file_symbols;
2544 o_nsyms = osyms ? osyms->nsyms : 0;
2546 /* Read the value-names and their values.
2547 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2548 A semicolon or comman instead of a NAME means the end. */
2549 while (**pp && **pp != ';' && **pp != ',')
2551 /* Check for and handle cretinous dbx symbol name continuation! */
2552 if (**pp == '\\') *pp = next_symbol_text ();
2555 while (*p != ':') p++;
2556 name = obsavestring (*pp, p - *pp);
2558 n = read_number (pp, ',');
2560 sym = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
2561 bzero (sym, sizeof (struct symbol));
2562 SYMBOL_NAME (sym) = name;
2563 SYMBOL_CLASS (sym) = LOC_CONST;
2564 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2565 SYMBOL_VALUE (sym) = n;
2566 add_symbol_to_list (sym, symlist);
2571 (*pp)++; /* Skip the semicolon. */
2573 /* Now fill in the fields of the type-structure. */
2575 TYPE_LENGTH (type) = sizeof (int);
2576 TYPE_CODE (type) = TYPE_CODE_ENUM;
2577 TYPE_NFIELDS (type) = nsyms;
2578 TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack, sizeof (struct field) * nsyms);
2580 /* Find the symbols for the values and put them into the type.
2581 The symbols can be found in the symlist that we put them on
2582 to cause them to be defined. osyms contains the old value
2583 of that symlist; everything up to there was defined by us. */
2584 /* Note that we preserve the order of the enum constants, so
2585 that in something like "enum {FOO, LAST_THING=FOO}" we print
2586 FOO, not LAST_THING. */
2588 for (syms = *symlist, n = 0; syms; syms = syms->next)
2593 for (; j < syms->nsyms; j++,n++)
2595 struct symbol *xsym = syms->symbol[j];
2596 SYMBOL_TYPE (xsym) = type;
2597 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
2598 TYPE_FIELD_VALUE (type, n) = 0;
2599 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
2600 TYPE_FIELD_BITSIZE (type, n) = 0;
2607 /* This screws up perfectly good C programs with enums. FIXME. */
2608 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2609 if(TYPE_NFIELDS(type) == 2 &&
2610 ((!strcmp(TYPE_FIELD_NAME(type,0),"TRUE") &&
2611 !strcmp(TYPE_FIELD_NAME(type,1),"FALSE")) ||
2612 (!strcmp(TYPE_FIELD_NAME(type,1),"TRUE") &&
2613 !strcmp(TYPE_FIELD_NAME(type,0),"FALSE"))))
2614 TYPE_CODE(type) = TYPE_CODE_BOOL;
2620 /* Read a number from the string pointed to by *PP.
2621 The value of *PP is advanced over the number.
2622 If END is nonzero, the character that ends the
2623 number must match END, or an error happens;
2624 and that character is skipped if it does match.
2625 If END is zero, *PP is left pointing to that character.
2627 If the number fits in a long, set *VALUE and set *BITS to 0.
2628 If not, set *BITS to be the number of bits in the number.
2630 If encounter garbage, set *BITS to -1. */
2633 read_huge_number (pp, end, valu, bits)
2654 /* Leading zero means octal. GCC uses this to output values larger
2655 than an int (because that would be hard in decimal). */
2662 upper_limit = LONG_MAX / radix;
2663 while ((c = *p++) >= '0' && c <= ('0' + radix))
2665 if (n <= upper_limit)
2668 n += c - '0'; /* FIXME this overflows anyway */
2673 /* This depends on large values being output in octal, which is
2680 /* Ignore leading zeroes. */
2684 else if (c == '2' || c == '3')
2710 /* Large decimal constants are an error (because it is hard to
2711 count how many bits are in them). */
2717 /* -0x7f is the same as 0x80. So deal with it by adding one to
2718 the number of bits. */
2733 #define MAX_OF_C_TYPE(t) ((1 << (sizeof (t)*8 - 1)) - 1)
2734 #define MIN_OF_C_TYPE(t) (-(1 << (sizeof (t)*8 - 1)))
2737 read_range_type (pp, typenums)
2745 struct type *result_type;
2747 /* First comes a type we are a subrange of.
2748 In C it is usually 0, 1 or the type being defined. */
2749 read_type_number (pp, rangenums);
2750 self_subrange = (rangenums[0] == typenums[0] &&
2751 rangenums[1] == typenums[1]);
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 read_huge_number (pp, ';', &n2, &n2bits);
2760 read_huge_number (pp, ';', &n3, &n3bits);
2762 if (n2bits == -1 || n3bits == -1)
2763 return error_type (pp);
2765 /* If limits are huge, must be large integral type. */
2766 if (n2bits != 0 || n3bits != 0)
2768 char got_signed = 0;
2769 char got_unsigned = 0;
2770 /* Number of bits in the type. */
2773 /* Range from 0 to <large number> is an unsigned large integral type. */
2774 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
2779 /* Range from <large number> to <large number>-1 is a large signed
2781 else if (n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
2787 /* Check for "long long". */
2788 if (got_signed && nbits == TARGET_LONG_LONG_BIT)
2789 return builtin_type_long_long;
2790 if (got_unsigned && nbits == TARGET_LONG_LONG_BIT)
2791 return builtin_type_unsigned_long_long;
2793 if (got_signed || got_unsigned)
2795 result_type = (struct type *) obstack_alloc (symbol_obstack,
2796 sizeof (struct type));
2797 bzero (result_type, sizeof (struct type));
2798 TYPE_LENGTH (result_type) = nbits / TARGET_CHAR_BIT;
2799 TYPE_MAIN_VARIANT (result_type) = result_type;
2800 TYPE_CODE (result_type) = TYPE_CODE_INT;
2802 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
2806 return error_type (pp);
2809 /* A type defined as a subrange of itself, with bounds both 0, is void. */
2810 if (self_subrange && n2 == 0 && n3 == 0)
2811 return builtin_type_void;
2813 /* If n3 is zero and n2 is not, we want a floating type,
2814 and n2 is the width in bytes.
2816 Fortran programs appear to use this for complex types also,
2817 and they give no way to distinguish between double and single-complex!
2818 We don't have complex types, so we would lose on all fortran files!
2819 So return type `double' for all of those. It won't work right
2820 for the complex values, but at least it makes the file loadable. */
2822 if (n3 == 0 && n2 > 0)
2824 if (n2 == sizeof (float))
2825 return builtin_type_float;
2826 return builtin_type_double;
2829 /* If the upper bound is -1, it must really be an unsigned int. */
2831 else if (n2 == 0 && n3 == -1)
2833 /* FIXME -- this confuses host and target type sizes. */
2834 if (sizeof (int) == sizeof (long))
2835 return builtin_type_unsigned_int;
2837 return builtin_type_unsigned_long;
2840 /* Special case: char is defined (Who knows why) as a subrange of
2841 itself with range 0-127. */
2842 else if (self_subrange && n2 == 0 && n3 == 127)
2843 return builtin_type_char;
2845 /* Assumptions made here: Subrange of self is equivalent to subrange
2846 of int. FIXME: Host and target type-sizes assumed the same. */
2848 && (self_subrange ||
2849 *dbx_lookup_type (rangenums) == builtin_type_int))
2851 /* an unsigned type */
2853 if (n3 == - sizeof (long long))
2854 return builtin_type_unsigned_long_long;
2856 if (n3 == (unsigned int)~0L)
2857 return builtin_type_unsigned_int;
2858 if (n3 == (unsigned long)~0L)
2859 return builtin_type_unsigned_long;
2860 if (n3 == (unsigned short)~0L)
2861 return builtin_type_unsigned_short;
2862 if (n3 == (unsigned char)~0L)
2863 return builtin_type_unsigned_char;
2866 else if (n3 == 0 && n2 == -sizeof (long long))
2867 return builtin_type_long_long;
2869 else if (n2 == -n3 -1)
2872 if (n3 == (1 << (8 * sizeof (int) - 1)) - 1)
2873 return builtin_type_int;
2874 if (n3 == (1 << (8 * sizeof (long) - 1)) - 1)
2875 return builtin_type_long;
2876 if (n3 == (1 << (8 * sizeof (short) - 1)) - 1)
2877 return builtin_type_short;
2878 if (n3 == (1 << (8 * sizeof (char) - 1)) - 1)
2879 return builtin_type_char;
2882 /* We have a real range type on our hands. Allocate space and
2883 return a real pointer. */
2885 /* At this point I don't have the faintest idea how to deal with
2886 a self_subrange type; I'm going to assume that this is used
2887 as an idiom, and that all of them are special cases. So . . . */
2889 return error_type (pp);
2891 result_type = (struct type *) obstack_alloc (symbol_obstack,
2892 sizeof (struct type));
2893 bzero (result_type, sizeof (struct type));
2895 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
2897 TYPE_TARGET_TYPE (result_type) = *dbx_lookup_type(rangenums);
2898 if (TYPE_TARGET_TYPE (result_type) == 0) {
2899 complain (&range_type_base_complaint, rangenums[1]);
2900 TYPE_TARGET_TYPE (result_type) = builtin_type_int;
2903 TYPE_NFIELDS (result_type) = 2;
2904 TYPE_FIELDS (result_type) =
2905 (struct field *) obstack_alloc (symbol_obstack,
2906 2 * sizeof (struct field));
2907 bzero (TYPE_FIELDS (result_type), 2 * sizeof (struct field));
2908 TYPE_FIELD_BITPOS (result_type, 0) = n2;
2909 TYPE_FIELD_BITPOS (result_type, 1) = n3;
2912 /* Note that TYPE_LENGTH (result_type) is just overridden a few
2913 statements down. What do we really need here? */
2914 /* We have to figure out how many bytes it takes to hold this
2915 range type. I'm going to assume that anything that is pushing
2916 the bounds of a long was taken care of above. */
2917 if (n2 >= MIN_OF_C_TYPE(char) && n3 <= MAX_OF_C_TYPE(char))
2918 TYPE_LENGTH (result_type) = 1;
2919 else if (n2 >= MIN_OF_C_TYPE(short) && n3 <= MAX_OF_C_TYPE(short))
2920 TYPE_LENGTH (result_type) = sizeof (short);
2921 else if (n2 >= MIN_OF_C_TYPE(int) && n3 <= MAX_OF_C_TYPE(int))
2922 TYPE_LENGTH (result_type) = sizeof (int);
2923 else if (n2 >= MIN_OF_C_TYPE(long) && n3 <= MAX_OF_C_TYPE(long))
2924 TYPE_LENGTH (result_type) = sizeof (long);
2926 /* Ranged type doesn't fit within known sizes. */
2927 /* FIXME -- use "long long" here. */
2928 return error_type (pp);
2931 TYPE_LENGTH (result_type) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type));
2936 /* Read a number from the string pointed to by *PP.
2937 The value of *PP is advanced over the number.
2938 If END is nonzero, the character that ends the
2939 number must match END, or an error happens;
2940 and that character is skipped if it does match.
2941 If END is zero, *PP is left pointing to that character. */
2944 read_number (pp, end)
2948 register char *p = *pp;
2949 register long n = 0;
2953 /* Handle an optional leading minus sign. */
2961 /* Read the digits, as far as they go. */
2963 while ((c = *p++) >= '0' && c <= '9')
2971 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c, symnum);
2980 /* Read in an argument list. This is a list of types, separated by commas
2981 and terminated with END. Return the list of types read in, or (struct type
2982 **)-1 if there is an error. */
2988 /* FIXME! Remove this arbitrary limit! */
2989 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
2995 /* Invalid argument list: no ','. */
2996 return (struct type **)-1;
2999 /* Check for and handle cretinous dbx symbol name continuation! */
3001 *pp = next_symbol_text ();
3003 types[n++] = read_type (pp);
3005 *pp += 1; /* get past `end' (the ':' character) */
3009 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
3011 else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
3013 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
3014 bzero (rval + n, sizeof (struct type *));
3018 rval = (struct type **) xmalloc (n * sizeof (struct type *));
3020 bcopy (types, rval, n * sizeof (struct type *));
3024 /* Add a common block's start address to the offset of each symbol
3025 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3026 the common block name). */
3029 fix_common_block (sym, valu)
3033 struct pending *next = (struct pending *) SYMBOL_NAMESPACE (sym);
3034 for ( ; next; next = next->next)
3037 for (j = next->nsyms - 1; j >= 0; j--)
3038 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
3042 /* Initializer for this module */
3044 _initialize_buildsym ()
3046 undef_types_allocated = 20;
3047 undef_types_length = 0;
3048 undef_types = (struct type **) xmalloc (undef_types_allocated *
3049 sizeof (struct type *));