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 #define patch_block_stabs abort /* FIXME scaffolding */
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];
122 if (filenum < 0 || filenum >= n_this_object_header_files)
123 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
124 filenum, index, symnum);
128 /* Type is defined outside of header files.
129 Find it in this object file's type vector. */
130 while (index >= type_vector_length)
132 type_vector_length *= 2;
133 type_vector = (struct type **)
134 xrealloc (type_vector,
135 (type_vector_length * sizeof (struct type *)));
136 bzero (&type_vector[type_vector_length / 2],
137 type_vector_length * sizeof (struct type *) / 2);
139 return &type_vector[index];
143 register int real_filenum = this_object_header_files[filenum];
144 register struct header_file *f;
147 if (real_filenum >= n_header_files)
150 f = &header_files[real_filenum];
152 f_orig_length = f->length;
153 if (index >= f_orig_length)
155 while (index >= f->length)
157 f->vector = (struct type **)
158 xrealloc (f->vector, f->length * sizeof (struct type *));
159 bzero (&f->vector[f_orig_length],
160 (f->length - f_orig_length) * sizeof (struct type *));
162 return &f->vector[index];
166 /* Create a type object. Occaisionally used when you need a type
167 which isn't going to be given a type number. */
172 register struct type *type =
173 (struct type *) obstack_alloc (symbol_obstack, sizeof (struct type));
175 bzero (type, sizeof (struct type));
176 TYPE_VPTR_FIELDNO (type) = -1;
177 TYPE_VPTR_BASETYPE (type) = 0;
181 /* Make sure there is a type allocated for type numbers TYPENUMS
182 and return the type object.
183 This can create an empty (zeroed) type object.
184 OBSOLETE -- call dbx_create_type instead -- FIXME:
185 TYPENUMS may be (-1, -1) to return a new type object that is not
186 put into the type vector, and so may not be referred to by number. */
189 dbx_alloc_type (typenums)
192 register struct type **type_addr;
193 register struct type *type;
195 if (typenums[1] != -1)
197 type_addr = dbx_lookup_type (typenums);
202 abort(); /* FIXME -- Must give a real type number now */
207 /* If we are referring to a type not known at all yet,
208 allocate an empty type for it.
209 We will fill it in later if we find out how. */
212 type = dbx_create_type ();
220 /* maintain the lists of symbols and blocks */
222 /* Add a symbol to one of the lists of symbols. */
224 add_symbol_to_list (symbol, listhead)
225 struct symbol *symbol;
226 struct pending **listhead;
228 /* We keep PENDINGSIZE symbols in each link of the list.
229 If we don't have a link with room in it, add a new link. */
230 if (*listhead == 0 || (*listhead)->nsyms == PENDINGSIZE)
232 register struct pending *link;
235 link = free_pendings;
236 free_pendings = link->next;
239 link = (struct pending *) xmalloc (sizeof (struct pending));
241 link->next = *listhead;
246 (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
249 /* At end of reading syms, or in case of quit,
250 really free as many `struct pending's as we can easily find. */
254 really_free_pendings (foo)
257 struct pending *next, *next1;
259 struct pending_block *bnext, *bnext1;
262 for (next = free_pendings; next; next = next1)
269 #if 0 /* Now we make the links in the symbol_obstack, so don't free them. */
270 for (bnext = pending_blocks; bnext; bnext = bnext1)
272 bnext1 = bnext->next;
278 for (next = file_symbols; next; next = next1)
285 for (next = global_symbols; next; next = next1)
293 /* Take one of the lists of symbols and make a block from it.
294 Keep the order the symbols have in the list (reversed from the input file).
295 Put the block on the list of pending blocks. */
298 finish_block (symbol, listhead, old_blocks, start, end)
299 struct symbol *symbol;
300 struct pending **listhead;
301 struct pending_block *old_blocks;
302 CORE_ADDR start, end;
304 register struct pending *next, *next1;
305 register struct block *block;
306 register struct pending_block *pblock;
307 struct pending_block *opblock;
310 /* Count the length of the list of symbols. */
312 for (next = *listhead, i = 0; next; i += next->nsyms, next = next->next)
315 block = (struct block *) obstack_alloc (symbol_obstack,
316 (sizeof (struct block)
318 * sizeof (struct symbol *))));
320 /* Copy the symbols into the block. */
322 BLOCK_NSYMS (block) = i;
323 for (next = *listhead; next; next = next->next)
326 for (j = next->nsyms - 1; j >= 0; j--)
327 BLOCK_SYM (block, --i) = next->symbol[j];
330 BLOCK_START (block) = start;
331 BLOCK_END (block) = end;
332 BLOCK_SUPERBLOCK (block) = 0; /* Filled in when containing block is made */
333 BLOCK_GCC_COMPILED (block) = processing_gcc_compilation;
335 /* Put the block in as the value of the symbol that names it. */
339 SYMBOL_BLOCK_VALUE (symbol) = block;
340 BLOCK_FUNCTION (block) = symbol;
343 BLOCK_FUNCTION (block) = 0;
345 /* Now "free" the links of the list, and empty the list. */
347 for (next = *listhead; next; next = next1)
350 next->next = free_pendings;
351 free_pendings = next;
355 /* Install this block as the superblock
356 of all blocks made since the start of this scope
357 that don't have superblocks yet. */
360 for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next)
362 if (BLOCK_SUPERBLOCK (pblock->block) == 0) {
364 /* Check to be sure the blocks are nested as we receive them.
365 If the compiler/assembler/linker work, this just burns a small
367 if (BLOCK_START (pblock->block) < BLOCK_START (block)
368 || BLOCK_END (pblock->block) > BLOCK_END (block)) {
369 complain(&innerblock_complaint, symbol? SYMBOL_NAME (symbol):
371 BLOCK_START (pblock->block) = BLOCK_START (block);
372 BLOCK_END (pblock->block) = BLOCK_END (block);
375 BLOCK_SUPERBLOCK (pblock->block) = block;
380 /* Record this block on the list of all blocks in the file.
381 Put it after opblock, or at the beginning if opblock is 0.
382 This puts the block in the list after all its subblocks. */
384 /* Allocate in the symbol_obstack to save time.
385 It wastes a little space. */
386 pblock = (struct pending_block *)
387 obstack_alloc (symbol_obstack,
388 sizeof (struct pending_block));
389 pblock->block = block;
392 pblock->next = opblock->next;
393 opblock->next = pblock;
397 pblock->next = pending_blocks;
398 pending_blocks = pblock;
405 register struct pending_block *next;
406 register struct blockvector *blockvector;
409 /* Count the length of the list of blocks. */
411 for (next = pending_blocks, i = 0; next; next = next->next, i++);
413 blockvector = (struct blockvector *)
414 obstack_alloc (symbol_obstack,
415 (sizeof (struct blockvector)
416 + (i - 1) * sizeof (struct block *)));
418 /* Copy the blocks into the blockvector.
419 This is done in reverse order, which happens to put
420 the blocks into the proper order (ascending starting address).
421 finish_block has hair to insert each block into the list
422 after its subblocks in order to make sure this is true. */
424 BLOCKVECTOR_NBLOCKS (blockvector) = i;
425 for (next = pending_blocks; next; next = next->next) {
426 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
429 #if 0 /* Now we make the links in the obstack, so don't free them. */
430 /* Now free the links of the list, and empty the list. */
432 for (next = pending_blocks; next; next = next1)
440 #if 1 /* FIXME, shut this off after a while to speed up symbol reading. */
441 /* Some compilers output blocks in the wrong order, but we depend
442 on their being in the right order so we can binary search.
443 Check the order and moan about it. FIXME. */
444 if (BLOCKVECTOR_NBLOCKS (blockvector) > 1)
445 for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++) {
446 if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i-1))
447 > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i))) {
448 complain (&blockvector_complaint,
449 BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i)));
457 /* Start recording information about source code that came from an included
458 (or otherwise merged-in) source file with a different name. */
461 start_subfile (name, dirname)
465 register struct subfile *subfile;
467 /* See if this subfile is already known as a subfile of the
468 current main source file. */
470 for (subfile = subfiles; subfile; subfile = subfile->next)
472 if (!strcmp (subfile->name, name))
474 current_subfile = subfile;
479 /* This subfile is not known. Add an entry for it.
480 Make an entry for this subfile in the list of all subfiles
481 of the current main source file. */
483 subfile = (struct subfile *) xmalloc (sizeof (struct subfile));
484 subfile->next = subfiles;
486 current_subfile = subfile;
488 /* Save its name and compilation directory name */
489 subfile->name = obsavestring (name, strlen (name));
491 subfile->dirname = NULL;
493 subfile->dirname = obsavestring (dirname, strlen (dirname));
495 /* Initialize line-number recording for this subfile. */
496 subfile->line_vector = 0;
499 /* Manage the vector of line numbers for each subfile. */
502 record_line (subfile, line, pc)
503 register struct subfile *subfile;
507 struct linetable_entry *e;
508 /* Ignore the dummy line number in libg.o */
513 /* Make sure line vector exists and is big enough. */
514 if (!subfile->line_vector) {
515 subfile->line_vector_length = INITIAL_LINE_VECTOR_LENGTH;
516 subfile->line_vector = (struct linetable *)
517 xmalloc (sizeof (struct linetable)
518 + subfile->line_vector_length * sizeof (struct linetable_entry));
519 subfile->line_vector->nitems = 0;
522 if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length)
524 subfile->line_vector_length *= 2;
525 subfile->line_vector = (struct linetable *)
526 xrealloc (subfile->line_vector, (sizeof (struct linetable)
527 + subfile->line_vector_length * sizeof (struct linetable_entry)));
530 e = subfile->line_vector->item + subfile->line_vector->nitems++;
531 e->line = line; e->pc = pc;
535 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
539 compare_line_numbers (ln1, ln2)
540 struct linetable_entry *ln1, *ln2;
542 return ln1->line - ln2->line;
545 /* Start a new symtab for a new source file.
546 This is called when a dbx symbol of type N_SO is seen;
547 it indicates the start of data for one original source file. */
550 start_symtab (name, dirname, start_addr)
553 CORE_ADDR start_addr;
556 last_source_file = name;
557 last_source_start_addr = start_addr;
560 global_stabs = 0; /* AIX COFF */
561 file_stabs = 0; /* AIX COFF */
564 /* Context stack is initially empty, with room for 10 levels. */
565 context_stack_size = INITIAL_CONTEXT_STACK_SIZE;
566 context_stack = (struct context_stack *)
567 xmalloc (context_stack_size * sizeof (struct context_stack));
568 context_stack_depth = 0;
570 new_object_header_files ();
572 type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
573 type_vector = (struct type **)
574 xmalloc (type_vector_length * sizeof (struct type *));
575 bzero (type_vector, type_vector_length * sizeof (struct type *));
577 /* Initialize the list of sub source files with one entry
578 for this file (the top-level source file). */
582 start_subfile (name, dirname);
585 /* Finish the symbol definitions for one main source file,
586 close off all the lexical contexts for that file
587 (creating struct block's for them), then make the struct symtab
588 for that file and put it in the list of all such.
590 END_ADDR is the address of the end of the file's text. */
593 end_symtab (end_addr, sort_pending, sort_linevec)
598 register struct symtab *symtab;
599 register struct blockvector *blockvector;
600 register struct subfile *subfile;
601 register struct linetable *lv;
602 struct subfile *nextsub;
604 /* Finish the lexical context of the last function in the file;
605 pop the context stack. */
607 if (context_stack_depth > 0)
609 register struct context_stack *cstk;
610 context_stack_depth--;
611 cstk = &context_stack[context_stack_depth];
612 /* Make a block for the local symbols within. */
613 finish_block (cstk->name, &local_symbols, cstk->old_blocks,
614 cstk->start_addr, end_addr);
617 /* It is unfortunate that in aixcoff, pending blocks might not be ordered
618 in this stage. Especially, blocks for static functions will show up at
619 the end. We need to sort them, so tools like `find_pc_function' and
620 `find_pc_block' can work reliably. */
622 /* FIXME! Remove this horrid bubble sort and use qsort!!! */
625 struct pending_block *pb, *pbnext;
627 pb = pending_blocks, pbnext = pb->next;
632 /* swap blocks if unordered! */
634 if (BLOCK_START(pb->block) < BLOCK_START(pbnext->block)) {
635 struct block *tmp = pb->block;
636 pb->block = pbnext->block;
641 pbnext = pbnext->next;
646 /* Cleanup any undefined types that have been left hanging around
647 (this needs to be done before the finish_blocks so that
648 file_symbols is still good). */
649 cleanup_undefined_types ();
652 patch_block_stabs (file_symbols, file_stabs);
658 patch_block_stabs (global_symbols, global_stabs);
663 /* Define the STATIC_BLOCK and GLOBAL_BLOCK, and build the blockvector. */
664 finish_block (0, &file_symbols, 0, last_source_start_addr, end_addr);
665 finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr);
666 blockvector = make_blockvector ();
668 /* Now create the symtab objects proper, one for each subfile. */
669 /* (The main file is the last one on the chain.) */
671 for (subfile = subfiles; subfile; subfile = nextsub)
673 if (subfile->line_vector) {
674 /* First, shrink the linetable to make more memory. */
675 subfile->line_vector = (struct linetable *)
676 xrealloc (subfile->line_vector, (sizeof (struct linetable)
677 + subfile->line_vector->nitems * sizeof (struct linetable_entry)));
680 qsort (subfile->line_vector->item, subfile->line_vector->nitems,
681 sizeof (struct linetable_entry), compare_line_numbers);
684 /* Now, allocate a symbol table. */
685 symtab = allocate_symtab (subfile->name);
687 /* Fill in its components. */
688 symtab->blockvector = blockvector;
689 symtab->linetable = subfile->line_vector;
690 symtab->dirname = subfile->dirname;
691 symtab->free_code = free_linetable;
692 symtab->free_ptr = 0;
694 /* Link the new symtab into the list of such. */
695 symtab->next = symtab_list;
696 symtab_list = symtab;
698 nextsub = subfile->next;
702 free ((char *) type_vector);
704 type_vector_length = -1;
706 last_source_file = 0;
712 /* Initialize anything that needs initializing when starting to read
713 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
725 /* Initialize anything that needs initializing when a completely new
726 symbol file is specified (not just adding some symbols from another
727 file, e.g. a shared library). */
732 /* Empty the hash table of global syms looking for values. */
733 bzero (global_sym_chain, sizeof global_sym_chain);
738 /* Scan through all of the global symbols defined in the object file,
739 assigning values to the debugging symbols that need to be assigned
740 to. Get these symbols from the misc function list. */
748 for (mf = 0; mf < misc_function_count; mf++)
750 char *namestring = misc_function_vector[mf].name;
751 struct symbol *sym, *prev;
755 prev = (struct symbol *) 0;
757 /* Get the hash index and check all the symbols
758 under that hash index. */
760 hash = hashname (namestring);
762 for (sym = global_sym_chain[hash]; sym;)
764 if (*namestring == SYMBOL_NAME (sym)[0]
765 && !strcmp(namestring + 1, SYMBOL_NAME (sym) + 1))
767 /* Splice this symbol out of the hash chain and
768 assign the value we have to it. */
770 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
772 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
774 /* Check to see whether we need to fix up a common block. */
775 /* Note: this code might be executed several times for
776 the same symbol if there are multiple references. */
777 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
778 fix_common_block (sym, misc_function_vector[mf].address);
780 SYMBOL_VALUE_ADDRESS (sym) = misc_function_vector[mf].address;
783 sym = SYMBOL_VALUE_CHAIN (prev);
785 sym = global_sym_chain[hash];
790 sym = SYMBOL_VALUE_CHAIN (sym);
797 /* Read a number by which a type is referred to in dbx data,
798 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
799 Just a single number N is equivalent to (0,N).
800 Return the two numbers by storing them in the vector TYPENUMS.
801 TYPENUMS will then be used as an argument to dbx_lookup_type. */
804 read_type_number (pp, typenums)
806 register int *typenums;
811 typenums[0] = read_number (pp, ',');
812 typenums[1] = read_number (pp, ')');
817 typenums[1] = read_number (pp, 0);
821 /* To handle GNU C++ typename abbreviation, we need to be able to
822 fill in a type's name as soon as space for that type is allocated.
823 `type_synonym_name' is the name of the type being allocated.
824 It is cleared as soon as it is used (lest all allocated types
826 static char *type_synonym_name;
830 define_symbol (valu, string, desc, type)
836 register struct symbol *sym;
837 char *p = (char *) strchr (string, ':');
842 /* Ignore syms with empty names. */
846 /* Ignore old-style symbols from cc -go */
850 sym = (struct symbol *)obstack_alloc (symbol_obstack, sizeof (struct symbol));
852 if (processing_gcc_compilation) {
853 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
854 number of bytes occupied by a type or object, which we ignore. */
855 SYMBOL_LINE(sym) = desc;
857 SYMBOL_LINE(sym) = 0; /* unknown */
860 if (string[0] == CPLUS_MARKER)
862 /* Special GNU C++ names. */
866 SYMBOL_NAME (sym) = "this";
868 case 'v': /* $vtbl_ptr_type */
869 /* Was: SYMBOL_NAME (sym) = "vptr"; */
872 SYMBOL_NAME (sym) = "eh_throw";
876 /* This was an anonymous type that was never fixed up. */
887 = (char *) obstack_alloc (symbol_obstack, ((p - string) + 1));
888 /* Open-coded bcopy--saves function call time. */
890 register char *p1 = string;
891 register char *p2 = SYMBOL_NAME (sym);
898 /* Determine the type of name being defined. */
899 /* The Acorn RISC machine's compiler can put out locals that don't
900 start with "234=" or "(3,4)=", so assume anything other than the
901 deftypes we know how to handle is a local. */
902 /* (Peter Watkins @ Computervision)
903 Handle Sun-style local fortran array types 'ar...' .
904 (gnu@cygnus.com) -- this strchr() handles them properly?
905 (tiemann@cygnus.com) -- 'C' is for catch. */
906 if (!strchr ("cfFGpPrStTvVXC", *p))
911 /* c is a special case, not followed by a type-number.
912 SYMBOL:c=iVALUE for an integer constant symbol.
913 SYMBOL:c=rVALUE for a floating constant symbol.
914 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
915 e.g. "b:c=e6,0" for "const b = blob1"
916 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
920 error ("Invalid symbol data at symtab pos %d.", symnum);
928 SYMBOL_TYPE (sym) = builtin_type_double;
930 (char *) obstack_alloc (symbol_obstack, sizeof (double));
931 bcopy (&d, dbl_valu, sizeof (double));
932 SWAP_TARGET_AND_HOST (dbl_valu, sizeof (double));
933 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
934 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
939 SYMBOL_TYPE (sym) = builtin_type_int;
940 SYMBOL_VALUE (sym) = atoi (p);
941 SYMBOL_CLASS (sym) = LOC_CONST;
945 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
946 e.g. "b:c=e6,0" for "const b = blob1"
947 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
951 read_type_number (&p, typenums);
953 error ("Invalid symbol data: no comma in enum const symbol");
955 SYMBOL_TYPE (sym) = *dbx_lookup_type (typenums);
956 SYMBOL_VALUE (sym) = atoi (p);
957 SYMBOL_CLASS (sym) = LOC_CONST;
961 error ("Invalid symbol data at symtab pos %d.", symnum);
963 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
964 add_symbol_to_list (sym, &file_symbols);
968 /* Now usually comes a number that says which data type,
969 and possibly more stuff to define the type
970 (all of which is handled by read_type) */
972 if (deftype == 'p' && *p == 'F')
973 /* pF is a two-letter code that means a function parameter in Fortran.
974 The type-number specifies the type of the return value.
975 Translate it into a pointer-to-function type. */
979 = lookup_pointer_type (lookup_function_type (read_type (&p)));
983 struct type *type_read;
989 type_synonym_name = obsavestring (SYMBOL_NAME (sym),
990 strlen (SYMBOL_NAME (sym)));
993 type_read = read_type (&p);
995 if ((deftype == 'F' || deftype == 'f')
996 && TYPE_CODE (type_read) != TYPE_CODE_FUNC)
999 /* This code doesn't work -- it needs to realloc and can't. */
1000 struct type *new = (struct type *)
1001 obstack_alloc (symbol_obstack, sizeof (struct type));
1003 /* Generate a template for the type of this function. The
1004 types of the arguments will be added as we read the symbol
1006 *new = *lookup_function_type (type_read);
1007 SYMBOL_TYPE(sym) = new;
1008 in_function_type = new;
1010 SYMBOL_TYPE (sym) = lookup_function_type (type_read);
1014 SYMBOL_TYPE (sym) = type_read;
1020 /* The name of a caught exception. */
1021 SYMBOL_CLASS (sym) = LOC_LABEL;
1022 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1023 SYMBOL_VALUE_ADDRESS (sym) = valu;
1024 add_symbol_to_list (sym, &local_symbols);
1028 SYMBOL_CLASS (sym) = LOC_BLOCK;
1029 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1030 add_symbol_to_list (sym, &file_symbols);
1034 SYMBOL_CLASS (sym) = LOC_BLOCK;
1035 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1036 add_symbol_to_list (sym, &global_symbols);
1040 /* For a class G (global) symbol, it appears that the
1041 value is not correct. It is necessary to search for the
1042 corresponding linker definition to find the value.
1043 These definitions appear at the end of the namelist. */
1044 i = hashname (SYMBOL_NAME (sym));
1045 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
1046 global_sym_chain[i] = sym;
1047 SYMBOL_CLASS (sym) = LOC_STATIC;
1048 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1049 add_symbol_to_list (sym, &global_symbols);
1052 /* This case is faked by a conditional above,
1053 when there is no code letter in the dbx data.
1054 Dbx data never actually contains 'l'. */
1056 SYMBOL_CLASS (sym) = LOC_LOCAL;
1057 SYMBOL_VALUE (sym) = valu;
1058 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1059 add_symbol_to_list (sym, &local_symbols);
1063 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1064 can also be a LOC_LOCAL_ARG depending on symbol type. */
1065 #ifndef DBX_PARM_SYMBOL_CLASS
1066 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1068 SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
1069 SYMBOL_VALUE (sym) = valu;
1070 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1072 /* This doesn't work yet. */
1073 add_param_to_type (&in_function_type, sym);
1075 add_symbol_to_list (sym, &local_symbols);
1077 /* If it's gcc-compiled, if it says `short', believe it. */
1078 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
1081 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
1082 /* This macro is defined on machines (e.g. sparc) where
1083 we should believe the type of a PCC 'short' argument,
1084 but shouldn't believe the address (the address is
1085 the address of the corresponding int). Note that
1086 this is only different from the BELIEVE_PCC_PROMOTION
1087 case on big-endian machines.
1089 My guess is that this correction, as opposed to changing
1090 the parameter to an 'int' (as done below, for PCC
1091 on most machines), is the right thing to do
1092 on all machines, but I don't want to risk breaking
1093 something that already works. On most PCC machines,
1094 the sparc problem doesn't come up because the calling
1095 function has to zero the top bytes (not knowing whether
1096 the called function wants an int or a short), so there
1097 is no practical difference between an int and a short
1098 (except perhaps what happens when the GDB user types
1099 "print short_arg = 0x10000;").
1101 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
1102 actually produces the correct address (we don't need to fix it
1103 up). I made this code adapt so that it will offset the symbol
1104 if it was pointing at an int-aligned location and not
1105 otherwise. This way you can use the same gdb for 4.0.x and
1108 if (0 == SYMBOL_VALUE (sym) % sizeof (int))
1110 if (SYMBOL_TYPE (sym) == builtin_type_char
1111 || SYMBOL_TYPE (sym) == builtin_type_unsigned_char)
1112 SYMBOL_VALUE (sym) += 3;
1113 else if (SYMBOL_TYPE (sym) == builtin_type_short
1114 || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
1115 SYMBOL_VALUE (sym) += 2;
1119 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1121 /* If PCC says a parameter is a short or a char,
1122 it is really an int. */
1123 if (SYMBOL_TYPE (sym) == builtin_type_char
1124 || SYMBOL_TYPE (sym) == builtin_type_short)
1125 SYMBOL_TYPE (sym) = builtin_type_int;
1126 else if (SYMBOL_TYPE (sym) == builtin_type_unsigned_char
1127 || SYMBOL_TYPE (sym) == builtin_type_unsigned_short)
1128 SYMBOL_TYPE (sym) = builtin_type_unsigned_int;
1131 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
1134 SYMBOL_CLASS (sym) = LOC_REGPARM;
1135 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1136 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1137 add_symbol_to_list (sym, &local_symbols);
1141 SYMBOL_CLASS (sym) = LOC_REGISTER;
1142 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1143 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1144 add_symbol_to_list (sym, &local_symbols);
1148 /* Static symbol at top level of file */
1149 SYMBOL_CLASS (sym) = LOC_STATIC;
1150 SYMBOL_VALUE_ADDRESS (sym) = valu;
1151 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1152 add_symbol_to_list (sym, &file_symbols);
1156 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1157 SYMBOL_VALUE (sym) = valu;
1158 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1159 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
1160 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
1161 TYPE_NAME (SYMBOL_TYPE (sym)) =
1162 obsavestring (SYMBOL_NAME (sym),
1163 strlen (SYMBOL_NAME (sym)));
1164 /* C++ vagaries: we may have a type which is derived from
1165 a base type which did not have its name defined when the
1166 derived class was output. We fill in the derived class's
1167 base part member's name here in that case. */
1168 else if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1169 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1170 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
1173 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
1174 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
1175 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
1176 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
1179 add_symbol_to_list (sym, &file_symbols);
1183 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1184 SYMBOL_VALUE (sym) = valu;
1185 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1186 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0
1187 && (TYPE_FLAGS (SYMBOL_TYPE (sym)) & TYPE_FLAG_PERM) == 0)
1188 TYPE_NAME (SYMBOL_TYPE (sym))
1190 (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM
1192 : (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1193 ? "struct " : "union ")),
1195 add_symbol_to_list (sym, &file_symbols);
1199 register struct symbol *typedef_sym
1200 = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
1201 SYMBOL_NAME (typedef_sym) = SYMBOL_NAME (sym);
1202 SYMBOL_TYPE (typedef_sym) = SYMBOL_TYPE (sym);
1204 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
1205 SYMBOL_VALUE (typedef_sym) = valu;
1206 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
1207 add_symbol_to_list (typedef_sym, &file_symbols);
1212 /* Static symbol of local scope */
1213 SYMBOL_CLASS (sym) = LOC_STATIC;
1214 SYMBOL_VALUE_ADDRESS (sym) = valu;
1215 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1216 add_symbol_to_list (sym, &local_symbols);
1220 /* Reference parameter */
1221 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1222 SYMBOL_VALUE (sym) = valu;
1223 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1224 add_symbol_to_list (sym, &local_symbols);
1228 /* This is used by Sun FORTRAN for "function result value".
1229 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1230 that Pascal uses it too, but when I tried it Pascal used
1231 "x:3" (local symbol) instead. */
1232 SYMBOL_CLASS (sym) = LOC_LOCAL;
1233 SYMBOL_VALUE (sym) = valu;
1234 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1235 add_symbol_to_list (sym, &local_symbols);
1239 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype, symnum);
1244 /* What about types defined as forward references inside of a small lexical
1246 /* Add a type to the list of undefined types to be checked through
1247 once this file has been read in. */
1249 add_undefined_type (type)
1252 if (undef_types_length == undef_types_allocated)
1254 undef_types_allocated *= 2;
1255 undef_types = (struct type **)
1256 xrealloc (undef_types,
1257 undef_types_allocated * sizeof (struct type *));
1259 undef_types[undef_types_length++] = type;
1262 /* Add here something to go through each undefined type, see if it's
1263 still undefined, and do a full lookup if so. */
1265 cleanup_undefined_types ()
1269 for (type = undef_types; type < undef_types + undef_types_length; type++)
1271 /* Reasonable test to see if it's been defined since. */
1272 if (TYPE_NFIELDS (*type) == 0)
1274 struct pending *ppt;
1276 /* Name of the type, without "struct" or "union" */
1277 char *typename = TYPE_NAME (*type);
1279 if (!strncmp (typename, "struct ", 7))
1281 if (!strncmp (typename, "union ", 6))
1284 for (ppt = file_symbols; ppt; ppt = ppt->next)
1285 for (i = 0; i < ppt->nsyms; i++)
1287 struct symbol *sym = ppt->symbol[i];
1289 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1290 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
1291 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
1293 && !strcmp (SYMBOL_NAME (sym), typename))
1294 bcopy (SYMBOL_TYPE (sym), *type, sizeof (struct type));
1298 /* It has been defined; don't mark it as a stub. */
1299 TYPE_FLAGS (*type) &= ~TYPE_FLAG_STUB;
1301 undef_types_length = 0;
1304 /* Skip rest of this symbol and return an error type.
1306 General notes on error recovery: error_type always skips to the
1307 end of the symbol (modulo cretinous dbx symbol name continuation).
1308 Thus code like this:
1310 if (*(*pp)++ != ';')
1311 return error_type (pp);
1313 is wrong because if *pp starts out pointing at '\0' (typically as the
1314 result of an earlier error), it will be incremented to point to the
1315 start of the next symbol, which might produce strange results, at least
1316 if you run off the end of the string table. Instead use
1319 return error_type (pp);
1325 foo = error_type (pp);
1329 And in case it isn't obvious, the point of all this hair is so the compiler
1330 can define new types and new syntaxes, and old versions of the
1331 debugger will be able to read the new symbol tables. */
1337 complain (&error_type_complaint, 0);
1340 /* Skip to end of symbol. */
1341 while (**pp != '\0')
1344 /* Check for and handle cretinous dbx symbol name continuation! */
1345 if ((*pp)[-1] == '\\')
1346 *pp = next_symbol_text ();
1350 return builtin_type_error;
1353 /* Read a dbx type reference or definition;
1354 return the type that is meant.
1355 This can be just a number, in which case it references
1356 a type already defined and placed in type_vector.
1357 Or the number can be followed by an =, in which case
1358 it means to define a new type according to the text that
1365 register struct type *type = 0;
1370 /* Read type number if present. The type number may be omitted.
1371 for instance in a two-dimensional array declared with type
1372 "ar1;1;10;ar1;1;10;4". */
1373 if ((**pp >= '0' && **pp <= '9')
1376 read_type_number (pp, typenums);
1378 /* Detect random reference to type not yet defined.
1379 Allocate a type object but leave it zeroed. */
1381 return dbx_alloc_type (typenums);
1387 /* 'typenums=' not present, type is anonymous. Read and return
1388 the definition, but don't put it in the type vector. */
1389 typenums[0] = typenums[1] = -1;
1397 enum type_code code;
1399 /* Used to index through file_symbols. */
1400 struct pending *ppt;
1403 /* Name including "struct", etc. */
1406 /* Name without "struct", etc. */
1407 char *type_name_only;
1413 /* Set the type code according to the following letter. */
1417 code = TYPE_CODE_STRUCT;
1421 code = TYPE_CODE_UNION;
1425 code = TYPE_CODE_ENUM;
1429 return error_type (pp);
1432 to = type_name = (char *)
1433 obstack_alloc (symbol_obstack,
1435 ((char *) strchr (*pp, ':') - (*pp)) + 1));
1437 /* Copy the prefix. */
1439 while (*to++ = *from++)
1443 type_name_only = to;
1445 /* Copy the name. */
1447 while ((*to++ = *from++) != ':')
1451 /* Set the pointer ahead of the name which we just read. */
1455 /* The following hack is clearly wrong, because it doesn't
1456 check whether we are in a baseclass. I tried to reproduce
1457 the case that it is trying to fix, but I couldn't get
1458 g++ to put out a cross reference to a basetype. Perhaps
1459 it doesn't do it anymore. */
1460 /* Note: for C++, the cross reference may be to a base type which
1461 has not yet been seen. In this case, we skip to the comma,
1462 which will mark the end of the base class name. (The ':'
1463 at the end of the base class name will be skipped as well.)
1464 But sometimes (ie. when the cross ref is the last thing on
1465 the line) there will be no ','. */
1466 from = (char *) strchr (*pp, ',');
1472 /* Now check to see whether the type has already been declared. */
1473 /* This is necessary at least in the case where the
1474 program says something like
1476 The compiler puts out a cross-reference; we better find
1477 set the length of the structure correctly so we can
1478 set the length of the array. */
1479 for (ppt = file_symbols; ppt; ppt = ppt->next)
1480 for (i = 0; i < ppt->nsyms; i++)
1482 struct symbol *sym = ppt->symbol[i];
1484 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1485 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
1486 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
1487 && !strcmp (SYMBOL_NAME (sym), type_name_only))
1489 obstack_free (symbol_obstack, type_name);
1490 type = SYMBOL_TYPE (sym);
1495 /* Didn't find the type to which this refers, so we must
1496 be dealing with a forward reference. Allocate a type
1497 structure for it, and keep track of it so we can
1498 fill in the rest of the fields when we get the full
1500 type = dbx_alloc_type (typenums);
1501 TYPE_CODE (type) = code;
1502 TYPE_NAME (type) = type_name;
1504 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
1506 add_undefined_type (type);
1522 read_type_number (pp, xtypenums);
1523 type = *dbx_lookup_type (xtypenums);
1525 type = builtin_type_void;
1526 if (typenums[0] != -1)
1527 *dbx_lookup_type (typenums) = type;
1531 type1 = read_type (pp);
1532 type = lookup_pointer_type (type1);
1533 if (typenums[0] != -1)
1534 *dbx_lookup_type (typenums) = type;
1539 struct type *domain = read_type (pp);
1540 struct type *memtype;
1543 /* Invalid member type data format. */
1544 return error_type (pp);
1547 memtype = read_type (pp);
1548 type = dbx_alloc_type (typenums);
1549 smash_to_member_type (type, domain, memtype);
1554 if ((*pp)[0] == '#')
1556 /* We'll get the parameter types from the name. */
1557 struct type *return_type;
1560 return_type = read_type (pp);
1561 if (*(*pp)++ != ';')
1562 complain (&invalid_member_complaint, symnum);
1563 type = allocate_stub_method (return_type);
1564 if (typenums[0] != -1)
1565 *dbx_lookup_type (typenums) = type;
1569 struct type *domain = read_type (pp);
1570 struct type *return_type;
1573 if (*(*pp)++ != ',')
1574 error ("invalid member type data format, at symtab pos %d.",
1577 return_type = read_type (pp);
1578 args = read_args (pp, ';');
1579 type = dbx_alloc_type (typenums);
1580 smash_to_method_type (type, domain, return_type, args);
1585 type1 = read_type (pp);
1586 type = lookup_reference_type (type1);
1587 if (typenums[0] != -1)
1588 *dbx_lookup_type (typenums) = type;
1592 type1 = read_type (pp);
1593 type = lookup_function_type (type1);
1594 if (typenums[0] != -1)
1595 *dbx_lookup_type (typenums) = type;
1599 type = read_range_type (pp, typenums);
1600 if (typenums[0] != -1)
1601 *dbx_lookup_type (typenums) = type;
1605 type = dbx_alloc_type (typenums);
1606 type = read_enum_type (pp, type);
1607 *dbx_lookup_type (typenums) = type;
1611 type = dbx_alloc_type (typenums);
1612 TYPE_NAME (type) = type_synonym_name;
1613 type_synonym_name = 0;
1614 type = read_struct_type (pp, type);
1618 type = dbx_alloc_type (typenums);
1619 TYPE_NAME (type) = type_synonym_name;
1620 type_synonym_name = 0;
1621 type = read_struct_type (pp, type);
1622 TYPE_CODE (type) = TYPE_CODE_UNION;
1627 return error_type (pp);
1630 type = dbx_alloc_type (typenums);
1631 type = read_array_type (pp, type);
1635 --*pp; /* Go back to the symbol in error */
1636 /* Particularly important if it was \0! */
1637 return error_type (pp);
1644 /* If this is an overriding temporary alteration for a header file's
1645 contents, and this type number is unknown in the global definition,
1646 put this type into the global definition at this type number. */
1647 if (header_file_prev_index >= 0)
1649 register struct type **tp
1650 = explicit_lookup_type (header_file_prev_index, typenums[1]);
1658 /* This page contains subroutines of read_type. */
1660 /* Read the description of a structure (or union type)
1661 and return an object describing the type. */
1664 read_struct_type (pp, type)
1666 register struct type *type;
1668 /* Total number of methods defined in this class.
1669 If the class defines two `f' methods, and one `g' method,
1670 then this will have the value 3. */
1671 int total_length = 0;
1675 struct nextfield *next;
1676 int visibility; /* 0=public, 1=protected, 2=public */
1682 struct next_fnfield *next;
1683 int visibility; /* 0=public, 1=protected, 2=public */
1684 struct fn_field fn_field;
1687 struct next_fnfieldlist
1689 struct next_fnfieldlist *next;
1690 struct fn_fieldlist fn_fieldlist;
1693 register struct nextfield *list = 0;
1694 struct nextfield *new;
1699 register struct next_fnfieldlist *mainlist = 0;
1702 if (TYPE_MAIN_VARIANT (type) == 0)
1704 TYPE_MAIN_VARIANT (type) = type;
1707 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1709 /* First comes the total size in bytes. */
1711 TYPE_LENGTH (type) = read_number (pp, 0);
1713 /* C++: Now, if the class is a derived class, then the next character
1714 will be a '!', followed by the number of base classes derived from.
1715 Each element in the list contains visibility information,
1716 the offset of this base class in the derived structure,
1717 and then the base type. */
1720 int i, n_baseclasses, offset;
1721 struct type *baseclass;
1724 /* Nonzero if it is a virtual baseclass, i.e.,
1728 struct C : public B, public virtual A {};
1730 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
1731 2.0 language feature. */
1736 n_baseclasses = read_number (pp, ',');
1737 TYPE_FIELD_VIRTUAL_BITS (type) =
1738 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (n_baseclasses));
1739 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), n_baseclasses);
1741 for (i = 0; i < n_baseclasses; i++)
1744 *pp = next_symbol_text ();
1755 /* Bad visibility format. */
1756 return error_type (pp);
1769 /* Bad visibility format. */
1770 return error_type (pp);
1773 SET_TYPE_FIELD_VIRTUAL (type, i);
1776 /* Offset of the portion of the object corresponding to
1777 this baseclass. Always zero in the absence of
1778 multiple inheritance. */
1779 offset = read_number (pp, ',');
1780 baseclass = read_type (pp);
1781 *pp += 1; /* skip trailing ';' */
1783 /* Make this baseclass visible for structure-printing purposes. */
1784 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1787 list->visibility = via_public;
1788 list->field.type = baseclass;
1789 list->field.name = type_name_no_tag (baseclass);
1790 list->field.bitpos = offset;
1791 list->field.bitsize = 0; /* this should be an unpacked field! */
1794 TYPE_N_BASECLASSES (type) = n_baseclasses;
1797 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
1798 At the end, we see a semicolon instead of a field.
1800 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
1803 The `?' is a placeholder for one of '/2' (public visibility),
1804 '/1' (protected visibility), '/0' (private visibility), or nothing
1805 (C style symbol table, public visibility). */
1807 /* We better set p right now, in case there are no fields at all... */
1812 /* Check for and handle cretinous dbx symbol name continuation! */
1813 if (**pp == '\\') *pp = next_symbol_text ();
1815 /* Get space to record the next field's data. */
1816 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1820 /* Get the field name. */
1822 if (*p == CPLUS_MARKER)
1824 /* Special GNU C++ name. */
1829 struct type *context;
1840 error ("invalid abbreviation at symtab pos %d.", symnum);
1843 context = read_type (pp);
1844 name = type_name_no_tag (context);
1847 error ("type name unknown at symtab pos %d.", symnum);
1848 TYPE_NAME (context) = name;
1850 list->field.name = obconcat (prefix, name, "");
1853 error ("invalid abbreviation at symtab pos %d.", symnum);
1854 list->field.type = read_type (pp);
1855 (*pp)++; /* Skip the comma. */
1856 list->field.bitpos = read_number (pp, ';');
1857 /* This field is unpacked. */
1858 list->field.bitsize = 0;
1860 /* GNU C++ anonymous type. */
1864 error ("invalid abbreviation at symtab pos %d.", symnum);
1870 while (*p != ':') p++;
1871 list->field.name = obsavestring (*pp, p - *pp);
1873 /* C++: Check to see if we have hit the methods yet. */
1879 /* This means we have a visibility for a field coming. */
1885 list->visibility = 0; /* private */
1890 list->visibility = 1; /* protected */
1895 list->visibility = 2; /* public */
1900 else /* normal dbx-style format. */
1901 list->visibility = 2; /* public */
1903 list->field.type = read_type (pp);
1906 /* Static class member. */
1907 list->field.bitpos = (long)-1;
1909 while (*p != ';') p++;
1910 list->field.bitsize = (long) savestring (*pp, p - *pp);
1915 else if (**pp != ',')
1916 /* Bad structure-type format. */
1917 return error_type (pp);
1919 (*pp)++; /* Skip the comma. */
1920 list->field.bitpos = read_number (pp, ',');
1921 list->field.bitsize = read_number (pp, ';');
1924 /* FIXME-tiemann: Can't the compiler put out something which
1925 lets us distinguish these? (or maybe just not put out anything
1926 for the field). What is the story here? What does the compiler
1927 really do? Also, patch gdb.texinfo for this case; I document
1928 it as a possible problem there. Search for "DBX-style". */
1930 /* This is wrong because this is identical to the symbols
1931 produced for GCC 0-size arrays. For example:
1936 The code which dumped core in such circumstances should be
1937 fixed not to dump core. */
1939 /* g++ -g0 can put out bitpos & bitsize zero for a static
1940 field. This does not give us any way of getting its
1941 class, so we can't know its name. But we can just
1942 ignore the field so we don't dump core and other nasty
1944 if (list->field.bitpos == 0
1945 && list->field.bitsize == 0)
1947 complain (&dbx_class_complaint, 0);
1948 /* Ignore this field. */
1954 /* Detect an unpacked field and mark it as such.
1955 dbx gives a bit size for all fields.
1956 Note that forward refs cannot be packed,
1957 and treat enums as if they had the width of ints. */
1958 if (TYPE_CODE (list->field.type) != TYPE_CODE_INT
1959 && TYPE_CODE (list->field.type) != TYPE_CODE_ENUM)
1960 list->field.bitsize = 0;
1961 if ((list->field.bitsize == 8 * TYPE_LENGTH (list->field.type)
1962 || (TYPE_CODE (list->field.type) == TYPE_CODE_ENUM
1963 && (list->field.bitsize
1964 == 8 * TYPE_LENGTH (builtin_type_int))
1968 list->field.bitpos % 8 == 0)
1969 list->field.bitsize = 0;
1975 /* chill the list of fields: the last entry (at the head)
1976 is a partially constructed entry which we now scrub. */
1979 /* Now create the vector of fields, and record how big it is.
1980 We need this info to record proper virtual function table information
1981 for this class's virtual functions. */
1983 TYPE_NFIELDS (type) = nfields;
1984 TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack,
1985 sizeof (struct field) * nfields);
1987 TYPE_FIELD_PRIVATE_BITS (type) =
1988 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (nfields));
1989 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
1991 TYPE_FIELD_PROTECTED_BITS (type) =
1992 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (nfields));
1993 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
1995 /* Copy the saved-up fields into the field vector. */
1997 for (n = nfields; list; list = list->next)
2000 TYPE_FIELD (type, n) = list->field;
2001 if (list->visibility == 0)
2002 SET_TYPE_FIELD_PRIVATE (type, n);
2003 else if (list->visibility == 1)
2004 SET_TYPE_FIELD_PROTECTED (type, n);
2007 /* Now come the method fields, as NAME::methods
2008 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
2009 At the end, we see a semicolon instead of a field.
2011 For the case of overloaded operators, the format is
2012 OPERATOR::*.methods, where OPERATOR is the string "operator",
2013 `*' holds the place for an operator name (such as `+=')
2014 and `.' marks the end of the operator name. */
2017 /* Now, read in the methods. To simplify matters, we
2018 "unread" the name that has been read, so that we can
2019 start from the top. */
2021 /* For each list of method lists... */
2025 struct next_fnfield *sublist = 0;
2026 struct type *look_ahead_type = NULL;
2028 struct next_fnfieldlist *new_mainlist =
2029 (struct next_fnfieldlist *)alloca (sizeof (struct next_fnfieldlist));
2034 /* read in the name. */
2035 while (*p != ':') p++;
2037 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == CPLUS_MARKER)
2039 /* This lets the user type "break operator+".
2040 We could just put in "+" as the name, but that wouldn't
2042 /* I don't understand what this is trying to do.
2043 It seems completely bogus. -Per Bothner. */
2044 static char opname[32] = {'o', 'p', CPLUS_MARKER};
2045 char *o = opname + 3;
2047 /* Skip past '::'. */
2049 if (**pp == '\\') *pp = next_symbol_text ();
2053 main_fn_name = savestring (opname, o - opname);
2059 main_fn_name = savestring (*pp, p - *pp);
2060 /* Skip past '::'. */
2062 new_mainlist->fn_fieldlist.name = main_fn_name;
2066 struct next_fnfield *new_sublist =
2067 (struct next_fnfield *)alloca (sizeof (struct next_fnfield));
2069 /* Check for and handle cretinous dbx symbol name continuation! */
2070 if (look_ahead_type == NULL) /* Normal case. */
2072 if (**pp == '\\') *pp = next_symbol_text ();
2074 new_sublist->fn_field.type = read_type (pp);
2076 /* Invalid symtab info for method. */
2077 return error_type (pp);
2080 { /* g++ version 1 kludge */
2081 new_sublist->fn_field.type = look_ahead_type;
2082 look_ahead_type = NULL;
2087 while (*p != ';') p++;
2088 /* If this is just a stub, then we don't have the
2090 new_sublist->fn_field.physname = savestring (*pp, p - *pp);
2092 new_sublist->visibility = *(*pp)++ - '0';
2093 if (**pp == '\\') *pp = next_symbol_text ();
2096 case 'A': /* Normal functions. */
2097 new_sublist->fn_field.is_const = 0;
2098 new_sublist->fn_field.is_volatile = 0;
2101 case 'B': /* `const' member functions. */
2102 new_sublist->fn_field.is_const = 1;
2103 new_sublist->fn_field.is_volatile = 0;
2106 case 'C': /* `volatile' member function. */
2107 new_sublist->fn_field.is_const = 0;
2108 new_sublist->fn_field.is_volatile = 1;
2111 case 'D': /* `const volatile' member function. */
2112 new_sublist->fn_field.is_const = 1;
2113 new_sublist->fn_field.is_volatile = 1;
2117 /* This probably just means we're processing a file compiled
2118 with g++ version 1. */
2119 complain(&const_vol_complaint, **pp);
2125 /* virtual member function, followed by index. */
2126 /* The sign bit is set to distinguish pointers-to-methods
2127 from virtual function indicies. Since the array is
2128 in words, the quantity must be shifted left by 1
2129 on 16 bit machine, and by 2 on 32 bit machine, forcing
2130 the sign bit out, and usable as a valid index into
2131 the array. Remove the sign bit here. */
2132 new_sublist->fn_field.voffset =
2133 (0x7fffffff & read_number (pp, ';')) + 2;
2135 if (**pp == '\\') *pp = next_symbol_text ();
2137 if (**pp == ';' || **pp == '\0')
2138 /* Must be g++ version 1. */
2139 new_sublist->fn_field.fcontext = 0;
2142 /* Figure out from whence this virtual function came.
2143 It may belong to virtual function table of
2144 one of its baseclasses. */
2145 look_ahead_type = read_type (pp);
2147 { /* g++ version 1 overloaded methods. */ }
2150 new_sublist->fn_field.fcontext = look_ahead_type;
2152 return error_type (pp);
2155 look_ahead_type = NULL;
2161 /* static member function. */
2162 new_sublist->fn_field.voffset = VOFFSET_STATIC;
2166 /* normal member function. */
2167 new_sublist->fn_field.voffset = 0;
2168 new_sublist->fn_field.fcontext = 0;
2172 new_sublist->next = sublist;
2173 sublist = new_sublist;
2175 if (**pp == '\\') *pp = next_symbol_text ();
2177 while (**pp != ';' && **pp != '\0');
2181 new_mainlist->fn_fieldlist.fn_fields =
2182 (struct fn_field *) obstack_alloc (symbol_obstack,
2183 sizeof (struct fn_field) * length);
2184 TYPE_FN_PRIVATE_BITS (new_mainlist->fn_fieldlist) =
2185 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (length));
2186 B_CLRALL (TYPE_FN_PRIVATE_BITS (new_mainlist->fn_fieldlist), length);
2188 TYPE_FN_PROTECTED_BITS (new_mainlist->fn_fieldlist) =
2189 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (length));
2190 B_CLRALL (TYPE_FN_PROTECTED_BITS (new_mainlist->fn_fieldlist), length);
2192 for (i = length; (i--, sublist); sublist = sublist->next)
2194 new_mainlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
2195 if (sublist->visibility == 0)
2196 B_SET (new_mainlist->fn_fieldlist.private_fn_field_bits, i);
2197 else if (sublist->visibility == 1)
2198 B_SET (new_mainlist->fn_fieldlist.protected_fn_field_bits, i);
2201 new_mainlist->fn_fieldlist.length = length;
2202 new_mainlist->next = mainlist;
2203 mainlist = new_mainlist;
2205 total_length += length;
2207 while (**pp != ';');
2212 TYPE_FN_FIELDLISTS (type) =
2213 (struct fn_fieldlist *) obstack_alloc (symbol_obstack,
2214 sizeof (struct fn_fieldlist) * nfn_fields);
2216 TYPE_NFN_FIELDS (type) = nfn_fields;
2217 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
2221 for (i = 0; i < TYPE_N_BASECLASSES (type); ++i)
2222 TYPE_NFN_FIELDS_TOTAL (type) +=
2223 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type, i));
2226 for (n = nfn_fields; mainlist; mainlist = mainlist->next)
2227 TYPE_FN_FIELDLISTS (type)[--n] = mainlist->fn_fieldlist;
2236 |= TYPE_FLAG_HAS_CONSTRUCTOR | TYPE_FLAG_HAS_DESTRUCTOR;
2239 else if (**pp == '+')
2241 TYPE_FLAGS (type) |= TYPE_FLAG_HAS_CONSTRUCTOR;
2244 else if (**pp == '-')
2246 TYPE_FLAGS (type) |= TYPE_FLAG_HAS_DESTRUCTOR;
2250 /* Read either a '%' or the final ';'. */
2251 if (*(*pp)++ == '%')
2253 /* Now we must record the virtual function table pointer's
2254 field information. */
2261 while (*p != '\0' && *p != ';')
2264 /* Premature end of symbol. */
2265 return error_type (pp);
2267 TYPE_VPTR_BASETYPE (type) = t;
2270 if (TYPE_FIELD_NAME (t, TYPE_N_BASECLASSES (t)) == 0)
2272 /* FIXME-tiemann: what's this? */
2274 TYPE_VPTR_FIELDNO (type) = i = TYPE_N_BASECLASSES (t);
2279 else for (i = TYPE_NFIELDS (t) - 1; i >= TYPE_N_BASECLASSES (t); --i)
2280 if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name,
2281 sizeof (vptr_name) -1))
2283 TYPE_VPTR_FIELDNO (type) = i;
2287 /* Virtual function table field not found. */
2288 return error_type (pp);
2291 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
2299 /* Read a definition of an array type,
2300 and create and return a suitable type object.
2301 Also creates a range type which represents the bounds of that
2304 read_array_type (pp, type)
2306 register struct type *type;
2308 struct type *index_type, *element_type, *range_type;
2312 /* Format of an array type:
2313 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2316 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2317 for these, produce a type like float[][]. */
2319 index_type = read_type (pp);
2321 /* Improper format of array type decl. */
2322 return error_type (pp);
2325 if (!(**pp >= '0' && **pp <= '9'))
2330 lower = read_number (pp, ';');
2332 if (!(**pp >= '0' && **pp <= '9'))
2337 upper = read_number (pp, ';');
2339 element_type = read_type (pp);
2348 /* Create range type. */
2349 range_type = (struct type *) obstack_alloc (symbol_obstack,
2350 sizeof (struct type));
2351 TYPE_CODE (range_type) = TYPE_CODE_RANGE;
2352 TYPE_TARGET_TYPE (range_type) = index_type;
2354 /* This should never be needed. */
2355 TYPE_LENGTH (range_type) = sizeof (int);
2357 TYPE_NFIELDS (range_type) = 2;
2358 TYPE_FIELDS (range_type) =
2359 (struct field *) obstack_alloc (symbol_obstack,
2360 2 * sizeof (struct field));
2361 TYPE_FIELD_BITPOS (range_type, 0) = lower;
2362 TYPE_FIELD_BITPOS (range_type, 1) = upper;
2365 TYPE_CODE (type) = TYPE_CODE_ARRAY;
2366 TYPE_TARGET_TYPE (type) = element_type;
2367 TYPE_LENGTH (type) = (upper - lower + 1) * TYPE_LENGTH (element_type);
2368 TYPE_NFIELDS (type) = 1;
2369 TYPE_FIELDS (type) =
2370 (struct field *) obstack_alloc (symbol_obstack,
2371 sizeof (struct field));
2372 TYPE_FIELD_TYPE (type, 0) = range_type;
2378 /* Read a definition of an enumeration type,
2379 and create and return a suitable type object.
2380 Also defines the symbols that represent the values of the type. */
2383 read_enum_type (pp, type)
2385 register struct type *type;
2390 register struct symbol *sym;
2392 struct pending **symlist;
2393 struct pending *osyms, *syms;
2396 if (within_function)
2397 symlist = &local_symbols;
2399 symlist = &file_symbols;
2401 o_nsyms = osyms ? osyms->nsyms : 0;
2403 /* Read the value-names and their values.
2404 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2405 A semicolon or comman instead of a NAME means the end. */
2406 while (**pp && **pp != ';' && **pp != ',')
2408 /* Check for and handle cretinous dbx symbol name continuation! */
2409 if (**pp == '\\') *pp = next_symbol_text ();
2412 while (*p != ':') p++;
2413 name = obsavestring (*pp, p - *pp);
2415 n = read_number (pp, ',');
2417 sym = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
2418 bzero (sym, sizeof (struct symbol));
2419 SYMBOL_NAME (sym) = name;
2420 SYMBOL_CLASS (sym) = LOC_CONST;
2421 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2422 SYMBOL_VALUE (sym) = n;
2423 add_symbol_to_list (sym, symlist);
2428 (*pp)++; /* Skip the semicolon. */
2430 /* Now fill in the fields of the type-structure. */
2432 TYPE_LENGTH (type) = sizeof (int);
2433 TYPE_CODE (type) = TYPE_CODE_ENUM;
2434 TYPE_NFIELDS (type) = nsyms;
2435 TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack, sizeof (struct field) * nsyms);
2437 /* Find the symbols for the values and put them into the type.
2438 The symbols can be found in the symlist that we put them on
2439 to cause them to be defined. osyms contains the old value
2440 of that symlist; everything up to there was defined by us. */
2441 /* Note that we preserve the order of the enum constants, so
2442 that in something like "enum {FOO, LAST_THING=FOO}" we print
2443 FOO, not LAST_THING. */
2445 for (syms = *symlist, n = 0; syms; syms = syms->next)
2450 for (; j < syms->nsyms; j++,n++)
2452 struct symbol *xsym = syms->symbol[j];
2453 SYMBOL_TYPE (xsym) = type;
2454 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
2455 TYPE_FIELD_VALUE (type, n) = 0;
2456 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
2457 TYPE_FIELD_BITSIZE (type, n) = 0;
2464 /* This screws up perfectly good C programs with enums. FIXME. */
2465 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2466 if(TYPE_NFIELDS(type) == 2 &&
2467 ((!strcmp(TYPE_FIELD_NAME(type,0),"TRUE") &&
2468 !strcmp(TYPE_FIELD_NAME(type,1),"FALSE")) ||
2469 (!strcmp(TYPE_FIELD_NAME(type,1),"TRUE") &&
2470 !strcmp(TYPE_FIELD_NAME(type,0),"FALSE"))))
2471 TYPE_CODE(type) = TYPE_CODE_BOOL;
2477 /* Read a number from the string pointed to by *PP.
2478 The value of *PP is advanced over the number.
2479 If END is nonzero, the character that ends the
2480 number must match END, or an error happens;
2481 and that character is skipped if it does match.
2482 If END is zero, *PP is left pointing to that character.
2484 If the number fits in a long, set *VALUE and set *BITS to 0.
2485 If not, set *BITS to be the number of bits in the number.
2487 If encounter garbage, set *BITS to -1. */
2490 read_huge_number (pp, end, valu, bits)
2511 /* Leading zero means octal. GCC uses this to output values larger
2512 than an int (because that would be hard in decimal). */
2519 upper_limit = LONG_MAX / radix;
2520 while ((c = *p++) >= '0' && c <= ('0' + radix))
2522 if (n <= upper_limit)
2525 n += c - '0'; /* FIXME this overflows anyway */
2530 /* This depends on large values being output in octal, which is
2537 /* Ignore leading zeroes. */
2541 else if (c == '2' || c == '3')
2567 /* Large decimal constants are an error (because it is hard to
2568 count how many bits are in them). */
2574 /* -0x7f is the same as 0x80. So deal with it by adding one to
2575 the number of bits. */
2590 #define MAX_OF_C_TYPE(t) ((1 << (sizeof (t)*8 - 1)) - 1)
2591 #define MIN_OF_C_TYPE(t) (-(1 << (sizeof (t)*8 - 1)))
2594 read_range_type (pp, typenums)
2602 struct type *result_type;
2604 /* First comes a type we are a subrange of.
2605 In C it is usually 0, 1 or the type being defined. */
2606 read_type_number (pp, rangenums);
2607 self_subrange = (rangenums[0] == typenums[0] &&
2608 rangenums[1] == typenums[1]);
2610 /* A semicolon should now follow; skip it. */
2614 /* The remaining two operands are usually lower and upper bounds
2615 of the range. But in some special cases they mean something else. */
2616 read_huge_number (pp, ';', &n2, &n2bits);
2617 read_huge_number (pp, ';', &n3, &n3bits);
2619 if (n2bits == -1 || n3bits == -1)
2620 return error_type (pp);
2622 /* If limits are huge, must be large integral type. */
2623 if (n2bits != 0 || n3bits != 0)
2625 char got_signed = 0;
2626 char got_unsigned = 0;
2627 /* Number of bits in the type. */
2630 /* Range from 0 to <large number> is an unsigned large integral type. */
2631 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
2636 /* Range from <large number> to <large number>-1 is a large signed
2638 else if (n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
2644 /* Check for "long long". */
2645 if (got_signed && nbits == TARGET_LONG_LONG_BIT)
2646 return builtin_type_long_long;
2647 if (got_unsigned && nbits == TARGET_LONG_LONG_BIT)
2648 return builtin_type_unsigned_long_long;
2650 if (got_signed || got_unsigned)
2652 result_type = (struct type *) obstack_alloc (symbol_obstack,
2653 sizeof (struct type));
2654 bzero (result_type, sizeof (struct type));
2655 TYPE_LENGTH (result_type) = nbits / TARGET_CHAR_BIT;
2656 TYPE_MAIN_VARIANT (result_type) = result_type;
2657 TYPE_CODE (result_type) = TYPE_CODE_INT;
2659 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
2663 return error_type (pp);
2666 /* A type defined as a subrange of itself, with bounds both 0, is void. */
2667 if (self_subrange && n2 == 0 && n3 == 0)
2668 return builtin_type_void;
2670 /* If n3 is zero and n2 is not, we want a floating type,
2671 and n2 is the width in bytes.
2673 Fortran programs appear to use this for complex types also,
2674 and they give no way to distinguish between double and single-complex!
2675 We don't have complex types, so we would lose on all fortran files!
2676 So return type `double' for all of those. It won't work right
2677 for the complex values, but at least it makes the file loadable. */
2679 if (n3 == 0 && n2 > 0)
2681 if (n2 == sizeof (float))
2682 return builtin_type_float;
2683 return builtin_type_double;
2686 /* If the upper bound is -1, it must really be an unsigned int. */
2688 else if (n2 == 0 && n3 == -1)
2690 if (sizeof (int) == sizeof (long))
2691 return builtin_type_unsigned_int;
2693 return builtin_type_unsigned_long;
2696 /* Special case: char is defined (Who knows why) as a subrange of
2697 itself with range 0-127. */
2698 else if (self_subrange && n2 == 0 && n3 == 127)
2699 return builtin_type_char;
2701 /* Assumptions made here: Subrange of self is equivalent to subrange
2704 && (self_subrange ||
2705 *dbx_lookup_type (rangenums) == builtin_type_int))
2707 /* an unsigned type */
2709 if (n3 == - sizeof (long long))
2710 return builtin_type_unsigned_long_long;
2712 if (n3 == (unsigned int)~0L)
2713 return builtin_type_unsigned_int;
2714 if (n3 == (unsigned long)~0L)
2715 return builtin_type_unsigned_long;
2716 if (n3 == (unsigned short)~0L)
2717 return builtin_type_unsigned_short;
2718 if (n3 == (unsigned char)~0L)
2719 return builtin_type_unsigned_char;
2722 else if (n3 == 0 && n2 == -sizeof (long long))
2723 return builtin_type_long_long;
2725 else if (n2 == -n3 -1)
2728 if (n3 == (1 << (8 * sizeof (int) - 1)) - 1)
2729 return builtin_type_int;
2730 if (n3 == (1 << (8 * sizeof (long) - 1)) - 1)
2731 return builtin_type_long;
2732 if (n3 == (1 << (8 * sizeof (short) - 1)) - 1)
2733 return builtin_type_short;
2734 if (n3 == (1 << (8 * sizeof (char) - 1)) - 1)
2735 return builtin_type_char;
2738 /* We have a real range type on our hands. Allocate space and
2739 return a real pointer. */
2741 /* At this point I don't have the faintest idea how to deal with
2742 a self_subrange type; I'm going to assume that this is used
2743 as an idiom, and that all of them are special cases. So . . . */
2745 return error_type (pp);
2747 result_type = (struct type *) obstack_alloc (symbol_obstack,
2748 sizeof (struct type));
2749 bzero (result_type, sizeof (struct type));
2751 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
2753 TYPE_TARGET_TYPE (result_type) = *dbx_lookup_type(rangenums);
2754 if (TYPE_TARGET_TYPE (result_type) == 0) {
2755 complain (&range_type_base_complaint, rangenums[1]);
2756 TYPE_TARGET_TYPE (result_type) = builtin_type_int;
2759 TYPE_NFIELDS (result_type) = 2;
2760 TYPE_FIELDS (result_type) =
2761 (struct field *) obstack_alloc (symbol_obstack,
2762 2 * sizeof (struct field));
2763 bzero (TYPE_FIELDS (result_type), 2 * sizeof (struct field));
2764 TYPE_FIELD_BITPOS (result_type, 0) = n2;
2765 TYPE_FIELD_BITPOS (result_type, 1) = n3;
2768 /* Note that TYPE_LENGTH (result_type) is just overridden a few
2769 statements down. What do we really need here? */
2770 /* We have to figure out how many bytes it takes to hold this
2771 range type. I'm going to assume that anything that is pushing
2772 the bounds of a long was taken care of above. */
2773 if (n2 >= MIN_OF_C_TYPE(char) && n3 <= MAX_OF_C_TYPE(char))
2774 TYPE_LENGTH (result_type) = 1;
2775 else if (n2 >= MIN_OF_C_TYPE(short) && n3 <= MAX_OF_C_TYPE(short))
2776 TYPE_LENGTH (result_type) = sizeof (short);
2777 else if (n2 >= MIN_OF_C_TYPE(int) && n3 <= MAX_OF_C_TYPE(int))
2778 TYPE_LENGTH (result_type) = sizeof (int);
2779 else if (n2 >= MIN_OF_C_TYPE(long) && n3 <= MAX_OF_C_TYPE(long))
2780 TYPE_LENGTH (result_type) = sizeof (long);
2782 /* Ranged type doesn't fit within known sizes. */
2783 /* FIXME -- use "long long" here. */
2784 return error_type (pp);
2787 TYPE_LENGTH (result_type) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type));
2792 /* Read a number from the string pointed to by *PP.
2793 The value of *PP is advanced over the number.
2794 If END is nonzero, the character that ends the
2795 number must match END, or an error happens;
2796 and that character is skipped if it does match.
2797 If END is zero, *PP is left pointing to that character. */
2800 read_number (pp, end)
2804 register char *p = *pp;
2805 register long n = 0;
2809 /* Handle an optional leading minus sign. */
2817 /* Read the digits, as far as they go. */
2819 while ((c = *p++) >= '0' && c <= '9')
2827 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c, symnum);
2836 /* Read in an argument list. This is a list of types, separated by commas
2837 and terminated with END. Return the list of types read in, or (struct type
2838 **)-1 if there is an error. */
2844 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
2850 /* Invalid argument list: no ','. */
2851 return (struct type **)-1;
2854 /* Check for and handle cretinous dbx symbol name continuation! */
2856 *pp = next_symbol_text ();
2858 types[n++] = read_type (pp);
2860 *pp += 1; /* get past `end' (the ':' character) */
2864 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
2866 else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
2868 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
2869 bzero (rval + n, sizeof (struct type *));
2873 rval = (struct type **) xmalloc (n * sizeof (struct type *));
2875 bcopy (types, rval, n * sizeof (struct type *));
2879 /* Add a common block's start address to the offset of each symbol
2880 declared to be in it (by being between a BCOMM/ECOMM pair that uses
2881 the common block name). */
2884 fix_common_block (sym, valu)
2888 struct pending *next = (struct pending *) SYMBOL_NAMESPACE (sym);
2889 for ( ; next; next = next->next)
2892 for (j = next->nsyms - 1; j >= 0; j--)
2893 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
2897 /* Initializer for this module */
2899 _initialize_buildsym ()
2901 undef_types_allocated = 20;
2902 undef_types_length = 0;
2903 undef_types = (struct type **) xmalloc (undef_types_allocated *
2904 sizeof (struct type *));