1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* Support routines for reading and decoding debugging information in
22 the "stabs" format. This format is used with many systems that use
23 the a.out object file format, as well as some systems that use
24 COFF or ELF where the stabs data is placed in a special section.
25 Avoid placing any object file format specific code in this file. */
32 #include "symfile.h" /* Needed for "struct complaint" */
34 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
37 /* Ask stabsread.h to define the vars it normally declares `extern'. */
39 #include "stabsread.h" /* Our own declarations */
43 dbx_alloc_type
PARAMS ((int [2], struct objfile
*));
46 read_huge_number
PARAMS ((char **, int, long *, int *));
49 patch_block_stabs
PARAMS ((struct pending
*, struct pending_stabs
*,
53 fix_common_block
PARAMS ((struct symbol
*, int));
56 read_range_type
PARAMS ((char **, int [2], struct objfile
*));
59 read_sun_builtin_type
PARAMS ((char **, int [2], struct objfile
*));
62 read_sun_floating_type
PARAMS ((char **, int [2], struct objfile
*));
65 read_enum_type
PARAMS ((char **, struct type
*, struct objfile
*));
68 read_struct_type
PARAMS ((char **, struct type
*, struct objfile
*));
71 read_array_type
PARAMS ((char **, struct type
*, struct objfile
*));
74 read_args
PARAMS ((char **, int, struct objfile
*));
76 static const char vptr_name
[] = { '_','v','p','t','r',CPLUS_MARKER
,'\0' };
77 static const char vb_name
[] = { '_','v','b',CPLUS_MARKER
,'\0' };
79 /* Define this as 1 if a pcc declaration of a char or short argument
80 gives the correct address. Otherwise assume pcc gives the
81 address of the corresponding int, which is not the same on a
82 big-endian machine. */
84 #ifndef BELIEVE_PCC_PROMOTION
85 #define BELIEVE_PCC_PROMOTION 0
88 /* During some calls to read_type (and thus to read_range_type), this
89 contains the name of the type being defined. Range types are only
90 used in C as basic types. We use the name to distinguish the otherwise
91 identical basic types "int" and "long" and their unsigned versions.
92 FIXME, this should disappear with better type management. */
94 static char *long_kludge_name
;
97 struct complaint dbx_class_complaint
=
99 "encountered DBX-style class variable debugging information.\n\
100 You seem to have compiled your program with \
101 \"g++ -g0\" instead of \"g++ -g\".\n\
102 Therefore GDB will not know about your class variables", 0, 0
106 struct complaint invalid_cpp_abbrev_complaint
=
107 {"invalid C++ abbreviation `%s'", 0, 0};
109 struct complaint invalid_cpp_type_complaint
=
110 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
112 struct complaint member_fn_complaint
=
113 {"member function type missing, got '%c'", 0, 0};
115 struct complaint const_vol_complaint
=
116 {"const/volatile indicator missing, got '%c'", 0, 0};
118 struct complaint error_type_complaint
=
119 {"debug info mismatch between compiler and debugger", 0, 0};
121 struct complaint invalid_member_complaint
=
122 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
124 struct complaint range_type_base_complaint
=
125 {"base type %d of range type is not defined", 0, 0};
127 struct complaint reg_value_complaint
=
128 {"register number too large in symbol %s", 0, 0};
130 /* Make a list of forward references which haven't been defined. */
132 static struct type
**undef_types
;
133 static int undef_types_allocated
;
134 static int undef_types_length
;
141 register char *p
= name
;
142 register int total
= p
[0];
157 /* Ensure result is positive. */
160 total
+= (1000 << 6);
162 return (total
% HASHSIZE
);
166 /* Look up a dbx type-number pair. Return the address of the slot
167 where the type for that number-pair is stored.
168 The number-pair is in TYPENUMS.
170 This can be used for finding the type associated with that pair
171 or for associating a new type with the pair. */
174 dbx_lookup_type (typenums
)
177 register int filenum
= typenums
[0];
178 register int index
= typenums
[1];
180 register int real_filenum
;
181 register struct header_file
*f
;
184 if (filenum
== -1) /* -1,-1 is for temporary types. */
187 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
188 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
189 filenum
, index
, symnum
);
193 /* Type is defined outside of header files.
194 Find it in this object file's type vector. */
195 if (index
>= type_vector_length
)
197 old_len
= type_vector_length
;
200 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
201 type_vector
= (struct type
**)
202 malloc (type_vector_length
* sizeof (struct type
*));
204 while (index
>= type_vector_length
)
206 type_vector_length
*= 2;
208 type_vector
= (struct type
**)
209 xrealloc ((char *) type_vector
,
210 (type_vector_length
* sizeof (struct type
*)));
211 memset (&type_vector
[old_len
], 0,
212 (type_vector_length
- old_len
) * sizeof (struct type
*));
214 return (&type_vector
[index
]);
218 real_filenum
= this_object_header_files
[filenum
];
220 if (real_filenum
>= n_header_files
)
225 f
= &header_files
[real_filenum
];
227 f_orig_length
= f
->length
;
228 if (index
>= f_orig_length
)
230 while (index
>= f
->length
)
234 f
->vector
= (struct type
**)
235 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
236 memset (&f
->vector
[f_orig_length
], 0,
237 (f
->length
- f_orig_length
) * sizeof (struct type
*));
239 return (&f
->vector
[index
]);
243 /* Make sure there is a type allocated for type numbers TYPENUMS
244 and return the type object.
245 This can create an empty (zeroed) type object.
246 TYPENUMS may be (-1, -1) to return a new type object that is not
247 put into the type vector, and so may not be referred to by number. */
250 dbx_alloc_type (typenums
, objfile
)
252 struct objfile
*objfile
;
254 register struct type
**type_addr
;
256 if (typenums
[0] == -1)
258 return (alloc_type (objfile
));
261 type_addr
= dbx_lookup_type (typenums
);
263 /* If we are referring to a type not known at all yet,
264 allocate an empty type for it.
265 We will fill it in later if we find out how. */
268 *type_addr
= alloc_type (objfile
);
274 /* for all the stabs in a given stab vector, build appropriate types
275 and fix their symbols in given symbol vector. */
278 patch_block_stabs (symbols
, stabs
, objfile
)
279 struct pending
*symbols
;
280 struct pending_stabs
*stabs
;
281 struct objfile
*objfile
;
291 /* for all the stab entries, find their corresponding symbols and
292 patch their types! */
294 for (ii
= 0; ii
< stabs
->count
; ++ii
)
296 name
= stabs
->stab
[ii
];
297 pp
= (char*) strchr (name
, ':');
298 sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
301 #ifndef IBM6000_TARGET
302 printf ("ERROR! stab symbol not found!\n"); /* FIXME */
308 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
311 lookup_function_type (read_type (&pp
, objfile
));
315 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
323 /* Read a number by which a type is referred to in dbx data,
324 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
325 Just a single number N is equivalent to (0,N).
326 Return the two numbers by storing them in the vector TYPENUMS.
327 TYPENUMS will then be used as an argument to dbx_lookup_type. */
330 read_type_number (pp
, typenums
)
332 register int *typenums
;
337 typenums
[0] = read_number (pp
, ',');
338 typenums
[1] = read_number (pp
, ')');
343 typenums
[1] = read_number (pp
, 0);
348 /* To handle GNU C++ typename abbreviation, we need to be able to
349 fill in a type's name as soon as space for that type is allocated.
350 `type_synonym_name' is the name of the type being allocated.
351 It is cleared as soon as it is used (lest all allocated types
354 static char *type_synonym_name
;
358 define_symbol (valu
, string
, desc
, type
, objfile
)
363 struct objfile
*objfile
;
365 register struct symbol
*sym
;
366 char *p
= (char *) strchr (string
, ':');
370 struct type
*temptype
;
372 /* We would like to eliminate nameless symbols, but keep their types.
373 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
374 to type 2, but, should not creat a symbol to address that type. Since
375 the symbol will be nameless, there is no way any user can refer to it. */
379 /* Ignore syms with empty names. */
383 /* Ignore old-style symbols from cc -go */
387 /* If a nameless stab entry, all we need is the type, not the symbol.
389 nameless
= (p
== string
);
391 sym
= (struct symbol
*)
392 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
393 memset (sym
, 0, sizeof (struct symbol
));
395 if (processing_gcc_compilation
)
397 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
398 number of bytes occupied by a type or object, which we ignore. */
399 SYMBOL_LINE(sym
) = desc
;
403 SYMBOL_LINE(sym
) = 0; /* unknown */
406 if (string
[0] == CPLUS_MARKER
)
408 /* Special GNU C++ names. */
412 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
413 &objfile
-> symbol_obstack
);
416 case 'v': /* $vtbl_ptr_type */
417 /* Was: SYMBOL_NAME (sym) = "vptr"; */
421 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
422 &objfile
-> symbol_obstack
);
426 /* This was an anonymous type that was never fixed up. */
436 SYMBOL_NAME (sym
) = (char *)
437 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
438 /* Open-coded bcopy--saves function call time. */
440 register char *p1
= string
;
441 register char *p2
= SYMBOL_NAME (sym
);
451 /* Determine the type of name being defined. */
452 /* The Acorn RISC machine's compiler can put out locals that don't
453 start with "234=" or "(3,4)=", so assume anything other than the
454 deftypes we know how to handle is a local. */
455 if (!strchr ("cfFGpPrStTvVXCR", *p
))
460 /* c is a special case, not followed by a type-number.
461 SYMBOL:c=iVALUE for an integer constant symbol.
462 SYMBOL:c=rVALUE for a floating constant symbol.
463 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
464 e.g. "b:c=e6,0" for "const b = blob1"
465 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
469 error ("Invalid symbol data at symtab pos %d.", symnum
);
477 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
480 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (double));
481 memcpy (dbl_valu
, &d
, sizeof (double));
482 SWAP_TARGET_AND_HOST (dbl_valu
, sizeof (double));
483 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
484 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
489 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
491 SYMBOL_VALUE (sym
) = atoi (p
);
492 SYMBOL_CLASS (sym
) = LOC_CONST
;
496 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
497 e.g. "b:c=e6,0" for "const b = blob1"
498 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
502 read_type_number (&p
, typenums
);
504 error ("Invalid symbol data: no comma in enum const symbol");
506 SYMBOL_TYPE (sym
) = *dbx_lookup_type (typenums
);
507 SYMBOL_VALUE (sym
) = atoi (p
);
508 SYMBOL_CLASS (sym
) = LOC_CONST
;
512 error ("Invalid symbol data at symtab pos %d.", symnum
);
514 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
515 add_symbol_to_list (sym
, &file_symbols
);
519 /* Now usually comes a number that says which data type,
520 and possibly more stuff to define the type
521 (all of which is handled by read_type) */
523 if (deftype
== 'p' && *p
== 'F')
524 /* pF is a two-letter code that means a function parameter in Fortran.
525 The type-number specifies the type of the return value.
526 Translate it into a pointer-to-function type. */
530 = lookup_pointer_type (lookup_function_type (read_type (&p
, objfile
)));
534 /* The symbol class letter is followed by a type (typically the
535 type of the symbol, or its return-type, or etc). Read it. */
542 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
543 strlen (SYMBOL_NAME (sym
)),
544 &objfile
-> symbol_obstack
);
547 /* Here we save the name of the symbol for read_range_type, which
548 ends up reading in the basic types. In stabs, unfortunately there
549 is no distinction between "int" and "long" types except their
550 names. Until we work out a saner type policy (eliminating most
551 builtin types and using the names specified in the files), we
552 save away the name so that far away from here in read_range_type,
553 we can examine it to decide between "int" and "long". FIXME. */
554 long_kludge_name
= SYMBOL_NAME (sym
);
556 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
562 /* The name of a caught exception. */
563 SYMBOL_CLASS (sym
) = LOC_LABEL
;
564 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
565 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
566 add_symbol_to_list (sym
, &local_symbols
);
570 /* A static function definition. */
571 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
572 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
573 add_symbol_to_list (sym
, &file_symbols
);
574 /* fall into process_function_types. */
576 process_function_types
:
577 /* Function result types are described as the result type in stabs.
578 We need to convert this to the function-returning-type-X type
579 in GDB. E.g. "int" is converted to "function returning int". */
580 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
583 /* This code doesn't work -- it needs to realloc and can't. */
584 /* Attempt to set up to record a function prototype... */
585 struct type
*new = alloc_type (objfile
);
587 /* Generate a template for the type of this function. The
588 types of the arguments will be added as we read the symbol
590 *new = *lookup_function_type (SYMBOL_TYPE(sym
));
591 SYMBOL_TYPE(sym
) = new;
592 TYPE_OBJFILE (new) = objfile
;
593 in_function_type
= new;
595 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
598 /* fall into process_prototype_types */
600 process_prototype_types
:
601 /* Sun acc puts declared types of arguments here. We don't care
602 about their actual types (FIXME -- we should remember the whole
603 function prototype), but the list may define some new types
604 that we have to remember, so we must scan it now. */
607 read_type (&p
, objfile
);
612 /* A global function definition. */
613 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
614 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
615 add_symbol_to_list (sym
, &global_symbols
);
616 goto process_function_types
;
619 /* For a class G (global) symbol, it appears that the
620 value is not correct. It is necessary to search for the
621 corresponding linker definition to find the value.
622 These definitions appear at the end of the namelist. */
623 i
= hashname (SYMBOL_NAME (sym
));
624 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
625 global_sym_chain
[i
] = sym
;
626 SYMBOL_CLASS (sym
) = LOC_STATIC
;
627 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
628 add_symbol_to_list (sym
, &global_symbols
);
631 /* This case is faked by a conditional above,
632 when there is no code letter in the dbx data.
633 Dbx data never actually contains 'l'. */
635 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
636 SYMBOL_VALUE (sym
) = valu
;
637 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
638 add_symbol_to_list (sym
, &local_symbols
);
642 /* Normally this is a parameter, a LOC_ARG. On the i960, it
643 can also be a LOC_LOCAL_ARG depending on symbol type. */
644 #ifndef DBX_PARM_SYMBOL_CLASS
645 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
647 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
648 SYMBOL_VALUE (sym
) = valu
;
649 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
651 /* This doesn't work yet. */
652 add_param_to_type (&in_function_type
, sym
);
654 add_symbol_to_list (sym
, &local_symbols
);
656 /* If it's gcc-compiled, if it says `short', believe it. */
657 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
660 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
661 /* This macro is defined on machines (e.g. sparc) where
662 we should believe the type of a PCC 'short' argument,
663 but shouldn't believe the address (the address is
664 the address of the corresponding int). Note that
665 this is only different from the BELIEVE_PCC_PROMOTION
666 case on big-endian machines.
668 My guess is that this correction, as opposed to changing
669 the parameter to an 'int' (as done below, for PCC
670 on most machines), is the right thing to do
671 on all machines, but I don't want to risk breaking
672 something that already works. On most PCC machines,
673 the sparc problem doesn't come up because the calling
674 function has to zero the top bytes (not knowing whether
675 the called function wants an int or a short), so there
676 is no practical difference between an int and a short
677 (except perhaps what happens when the GDB user types
678 "print short_arg = 0x10000;").
680 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
681 actually produces the correct address (we don't need to fix it
682 up). I made this code adapt so that it will offset the symbol
683 if it was pointing at an int-aligned location and not
684 otherwise. This way you can use the same gdb for 4.0.x and
687 If the parameter is shorter than an int, and is integral
688 (e.g. char, short, or unsigned equivalent), and is claimed to
689 be passed on an integer boundary, don't believe it! Offset the
690 parameter's address to the tail-end of that integer. */
692 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
693 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
694 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
695 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (temptype
))
697 SYMBOL_VALUE (sym
) += TYPE_LENGTH (temptype
)
698 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
702 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
704 /* If PCC says a parameter is a short or a char,
705 it is really an int. */
706 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
707 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
708 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
710 SYMBOL_TYPE (sym
) = TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
711 ? lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
)
716 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
719 /* acc seems to use P to delare the prototypes of functions that
720 are referenced by this file. gdb is not prepared to deal
721 with this extra information. FIXME, it ought to. */
723 goto process_prototype_types
;
725 /* Parameter which is in a register. */
726 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
727 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
728 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
730 complain (®_value_complaint
, SYMBOL_NAME (sym
));
731 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
733 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
734 add_symbol_to_list (sym
, &local_symbols
);
739 /* Register variable (either global or local). */
740 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
741 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
742 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
744 complain (®_value_complaint
, SYMBOL_NAME (sym
));
745 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
747 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
749 add_symbol_to_list (sym
, &local_symbols
);
751 add_symbol_to_list (sym
, &file_symbols
);
755 /* Static symbol at top level of file */
756 SYMBOL_CLASS (sym
) = LOC_STATIC
;
757 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
758 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
759 add_symbol_to_list (sym
, &file_symbols
);
763 /* For a nameless type, we don't want a create a symbol, thus we
764 did not use `sym'. Return without further processing. */
765 if (nameless
) return NULL
;
767 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
768 SYMBOL_VALUE (sym
) = valu
;
769 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
770 /* C++ vagaries: we may have a type which is derived from
771 a base type which did not have its name defined when the
772 derived class was output. We fill in the derived class's
773 base part member's name here in that case. */
774 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
775 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
776 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
777 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
780 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
781 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
782 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
783 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
786 add_symbol_to_list (sym
, &file_symbols
);
790 /* For a nameless type, we don't want a create a symbol, thus we
791 did not use `sym'. Return without further processing. */
792 if (nameless
) return NULL
;
794 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
795 SYMBOL_VALUE (sym
) = valu
;
796 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
797 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
798 TYPE_NAME (SYMBOL_TYPE (sym
))
799 = obconcat (&objfile
-> type_obstack
, "",
800 (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_ENUM
802 : (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
803 ? "struct " : "union ")),
805 add_symbol_to_list (sym
, &file_symbols
);
809 register struct symbol
*typedef_sym
= (struct symbol
*)
810 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
811 memset (typedef_sym
, 0, sizeof (struct symbol
));
812 SYMBOL_NAME (typedef_sym
) = SYMBOL_NAME (sym
);
813 SYMBOL_TYPE (typedef_sym
) = SYMBOL_TYPE (sym
);
815 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
816 SYMBOL_VALUE (typedef_sym
) = valu
;
817 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
818 add_symbol_to_list (typedef_sym
, &file_symbols
);
823 /* Static symbol of local scope */
824 SYMBOL_CLASS (sym
) = LOC_STATIC
;
825 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
826 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
827 add_symbol_to_list (sym
, &local_symbols
);
831 /* Reference parameter */
832 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
833 SYMBOL_VALUE (sym
) = valu
;
834 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
835 add_symbol_to_list (sym
, &local_symbols
);
839 /* This is used by Sun FORTRAN for "function result value".
840 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
841 that Pascal uses it too, but when I tried it Pascal used
842 "x:3" (local symbol) instead. */
843 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
844 SYMBOL_VALUE (sym
) = valu
;
845 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
846 add_symbol_to_list (sym
, &local_symbols
);
850 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype
, symnum
);
856 /* Skip rest of this symbol and return an error type.
858 General notes on error recovery: error_type always skips to the
859 end of the symbol (modulo cretinous dbx symbol name continuation).
863 return error_type (pp);
865 is wrong because if *pp starts out pointing at '\0' (typically as the
866 result of an earlier error), it will be incremented to point to the
867 start of the next symbol, which might produce strange results, at least
868 if you run off the end of the string table. Instead use
871 return error_type (pp);
877 foo = error_type (pp);
881 And in case it isn't obvious, the point of all this hair is so the compiler
882 can define new types and new syntaxes, and old versions of the
883 debugger will be able to read the new symbol tables. */
889 complain (&error_type_complaint
, 0);
892 /* Skip to end of symbol. */
896 /* Check for and handle cretinous dbx symbol name continuation! */
897 if ((*pp
)[-1] == '\\')
898 *pp
= next_symbol_text ();
902 return builtin_type_error
;
906 /* Read a dbx type reference or definition;
907 return the type that is meant.
908 This can be just a number, in which case it references
909 a type already defined and placed in type_vector.
910 Or the number can be followed by an =, in which case
911 it means to define a new type according to the text that
915 read_type (pp
, objfile
)
917 struct objfile
*objfile
;
919 register struct type
*type
= 0;
924 /* Read type number if present. The type number may be omitted.
925 for instance in a two-dimensional array declared with type
926 "ar1;1;10;ar1;1;10;4". */
927 if ((**pp
>= '0' && **pp
<= '9')
930 read_type_number (pp
, typenums
);
932 /* Type is not being defined here. Either it already exists,
933 or this is a forward reference to it. dbx_alloc_type handles
936 return dbx_alloc_type (typenums
, objfile
);
938 /* Type is being defined here. */
939 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
943 /* if such a type already exists, this is an unnecessary duplication
944 of the stab string, which is common in (RS/6000) xlc generated
945 objects. In that case, simply return NULL and let the caller take
948 tt
= *dbx_lookup_type (typenums
);
949 if (tt
&& tt
->length
&& tt
->code
)
958 /* 'typenums=' not present, type is anonymous. Read and return
959 the definition, but don't put it in the type vector. */
960 typenums
[0] = typenums
[1] = -1;
970 /* Used to index through file_symbols. */
974 /* Name including "struct", etc. */
977 /* Name without "struct", etc. */
978 char *type_name_only
;
984 /* Set the type code according to the following letter. */
988 code
= TYPE_CODE_STRUCT
;
992 code
= TYPE_CODE_UNION
;
996 code
= TYPE_CODE_ENUM
;
1000 return error_type (pp
);
1003 to
= type_name
= (char *)
1004 obstack_alloc (&objfile
-> type_obstack
,
1006 ((char *) strchr (*pp
, ':') - (*pp
)) + 1));
1008 /* Copy the prefix. */
1010 while (*to
++ = *from
++)
1014 type_name_only
= to
;
1016 /* Copy the name. */
1018 while ((*to
++ = *from
++) != ':')
1022 /* Set the pointer ahead of the name which we just read. */
1026 /* The following hack is clearly wrong, because it doesn't
1027 check whether we are in a baseclass. I tried to reproduce
1028 the case that it is trying to fix, but I couldn't get
1029 g++ to put out a cross reference to a basetype. Perhaps
1030 it doesn't do it anymore. */
1031 /* Note: for C++, the cross reference may be to a base type which
1032 has not yet been seen. In this case, we skip to the comma,
1033 which will mark the end of the base class name. (The ':'
1034 at the end of the base class name will be skipped as well.)
1035 But sometimes (ie. when the cross ref is the last thing on
1036 the line) there will be no ','. */
1037 from
= (char *) strchr (*pp
, ',');
1043 /* Now check to see whether the type has already been declared. */
1044 /* This is necessary at least in the case where the
1045 program says something like
1047 The compiler puts out a cross-reference; we better find
1048 set the length of the structure correctly so we can
1049 set the length of the array. */
1050 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1051 for (i
= 0; i
< ppt
->nsyms
; i
++)
1053 struct symbol
*sym
= ppt
->symbol
[i
];
1055 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1056 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1057 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1058 && !strcmp (SYMBOL_NAME (sym
), type_name_only
))
1060 obstack_free (&objfile
-> type_obstack
, type_name
);
1061 type
= SYMBOL_TYPE (sym
);
1066 /* Didn't find the type to which this refers, so we must
1067 be dealing with a forward reference. Allocate a type
1068 structure for it, and keep track of it so we can
1069 fill in the rest of the fields when we get the full
1071 type
= dbx_alloc_type (typenums
, objfile
);
1072 TYPE_CODE (type
) = code
;
1073 TYPE_NAME (type
) = type_name
;
1074 INIT_CPLUS_SPECIFIC(type
);
1075 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1077 add_undefined_type (type
);
1081 case '-': /* RS/6000 built-in type */
1083 type
= builtin_type (pp
); /* (in xcoffread.c) */
1098 read_type_number (pp
, xtypenums
);
1099 type
= *dbx_lookup_type (xtypenums
);
1104 type
= lookup_fundamental_type (objfile
, FT_VOID
);
1105 if (typenums
[0] != -1)
1106 *dbx_lookup_type (typenums
) = type
;
1109 /* In the following types, we must be sure to overwrite any existing
1110 type that the typenums refer to, rather than allocating a new one
1111 and making the typenums point to the new one. This is because there
1112 may already be pointers to the existing type (if it had been
1113 forward-referenced), and we must change it to a pointer, function,
1114 reference, or whatever, *in-place*. */
1117 type1
= read_type (pp
, objfile
);
1118 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1121 case '&': /* Reference to another type */
1122 type1
= read_type (pp
, objfile
);
1123 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1126 case 'f': /* Function returning another type */
1127 type1
= read_type (pp
, objfile
);
1128 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1131 case 'k': /* Const qualifier on some type (Sun) */
1132 type
= read_type (pp
, objfile
);
1133 /* FIXME! For now, we ignore const and volatile qualifiers. */
1136 case 'B': /* Volatile qual on some type (Sun) */
1137 type
= read_type (pp
, objfile
);
1138 /* FIXME! For now, we ignore const and volatile qualifiers. */
1141 /* FIXME -- we should be doing smash_to_XXX types here. */
1142 case '@': /* Member (class & variable) type */
1144 struct type
*domain
= read_type (pp
, objfile
);
1145 struct type
*memtype
;
1148 /* Invalid member type data format. */
1149 return error_type (pp
);
1152 memtype
= read_type (pp
, objfile
);
1153 type
= dbx_alloc_type (typenums
, objfile
);
1154 smash_to_member_type (type
, domain
, memtype
);
1158 case '#': /* Method (class & fn) type */
1159 if ((*pp
)[0] == '#')
1161 /* This "minimized" format bogus, because it doesn't yield
1162 enough information. I've changed gcc to not emit it. --Per */
1163 struct type
*return_type
;
1166 return_type
= read_type (pp
, objfile
);
1167 if (*(*pp
)++ != ';')
1168 complain (&invalid_member_complaint
, (char *) symnum
);
1169 type
= allocate_stub_method (return_type
);
1170 if (typenums
[0] != -1)
1171 *dbx_lookup_type (typenums
) = type
;
1175 struct type
*domain
= read_type (pp
, objfile
);
1176 struct type
*return_type
;
1179 if (*(*pp
)++ != ',')
1180 error ("invalid member type data format, at symtab pos %d.",
1183 return_type
= read_type (pp
, objfile
);
1184 args
= read_args (pp
, ';', objfile
);
1185 type
= dbx_alloc_type (typenums
, objfile
);
1186 smash_to_method_type (type
, domain
, return_type
, args
);
1190 case 'r': /* Range type */
1191 type
= read_range_type (pp
, typenums
, objfile
);
1192 if (typenums
[0] != -1)
1193 *dbx_lookup_type (typenums
) = type
;
1196 case 'b': /* Sun ACC builtin int type */
1197 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
1198 if (typenums
[0] != -1)
1199 *dbx_lookup_type (typenums
) = type
;
1202 case 'R': /* Sun ACC builtin float type */
1203 type
= read_sun_floating_type (pp
, typenums
, objfile
);
1204 if (typenums
[0] != -1)
1205 *dbx_lookup_type (typenums
) = type
;
1208 case 'e': /* Enumeration type */
1209 type
= dbx_alloc_type (typenums
, objfile
);
1210 type
= read_enum_type (pp
, type
, objfile
);
1211 *dbx_lookup_type (typenums
) = type
;
1214 case 's': /* Struct type */
1215 type
= dbx_alloc_type (typenums
, objfile
);
1216 if (!TYPE_NAME (type
))
1217 TYPE_NAME (type
) = type_synonym_name
;
1218 type_synonym_name
= 0;
1219 type
= read_struct_type (pp
, type
, objfile
);
1222 case 'u': /* Union type */
1223 type
= dbx_alloc_type (typenums
, objfile
);
1224 if (!TYPE_NAME (type
))
1225 TYPE_NAME (type
) = type_synonym_name
;
1226 type_synonym_name
= 0;
1227 type
= read_struct_type (pp
, type
, objfile
);
1228 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1231 case 'a': /* Array type */
1233 return error_type (pp
);
1236 type
= dbx_alloc_type (typenums
, objfile
);
1237 type
= read_array_type (pp
, type
, objfile
);
1241 --*pp
; /* Go back to the symbol in error */
1242 /* Particularly important if it was \0! */
1243 return error_type (pp
);
1252 /* This page contains subroutines of read_type. */
1254 /* Read the description of a structure (or union type)
1255 and return an object describing the type. */
1257 static struct type
*
1258 read_struct_type (pp
, type
, objfile
)
1260 register struct type
*type
;
1261 struct objfile
*objfile
;
1263 /* Total number of methods defined in this class.
1264 If the class defines two `f' methods, and one `g' method,
1265 then this will have the value 3. */
1266 int total_length
= 0;
1270 struct nextfield
*next
;
1271 int visibility
; /* 0=public, 1=protected, 2=public */
1277 struct next_fnfield
*next
;
1278 struct fn_field fn_field
;
1281 struct next_fnfieldlist
1283 struct next_fnfieldlist
*next
;
1284 struct fn_fieldlist fn_fieldlist
;
1287 register struct nextfield
*list
= 0;
1288 struct nextfield
*new;
1291 int non_public_fields
= 0;
1294 register struct next_fnfieldlist
*mainlist
= 0;
1297 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1298 INIT_CPLUS_SPECIFIC(type
);
1299 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
1301 /* First comes the total size in bytes. */
1303 TYPE_LENGTH (type
) = read_number (pp
, 0);
1305 /* C++: Now, if the class is a derived class, then the next character
1306 will be a '!', followed by the number of base classes derived from.
1307 Each element in the list contains visibility information,
1308 the offset of this base class in the derived structure,
1309 and then the base type. */
1312 int i
, n_baseclasses
, offset
;
1313 struct type
*baseclass
;
1316 /* Nonzero if it is a virtual baseclass, i.e.,
1320 struct C : public B, public virtual A {};
1322 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
1323 2.0 language feature. */
1328 ALLOCATE_CPLUS_STRUCT_TYPE(type
);
1330 n_baseclasses
= read_number (pp
, ',');
1331 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
1332 TYPE_ALLOC (type
, B_BYTES (n_baseclasses
));
1333 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), n_baseclasses
);
1335 for (i
= 0; i
< n_baseclasses
; i
++)
1338 *pp
= next_symbol_text ();
1349 /* Bad visibility format. */
1350 return error_type (pp
);
1358 non_public_fields
++;
1364 /* Bad visibility format. */
1365 return error_type (pp
);
1368 SET_TYPE_FIELD_VIRTUAL (type
, i
);
1371 /* Offset of the portion of the object corresponding to
1372 this baseclass. Always zero in the absence of
1373 multiple inheritance. */
1374 offset
= read_number (pp
, ',');
1375 baseclass
= read_type (pp
, objfile
);
1376 *pp
+= 1; /* skip trailing ';' */
1378 /* Make this baseclass visible for structure-printing purposes. */
1379 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1380 memset (new, 0, sizeof (struct nextfield
));
1383 list
->visibility
= via_public
;
1384 list
->field
.type
= baseclass
;
1385 list
->field
.name
= type_name_no_tag (baseclass
);
1386 list
->field
.bitpos
= offset
;
1387 list
->field
.bitsize
= 0; /* this should be an unpacked field! */
1390 TYPE_N_BASECLASSES (type
) = n_baseclasses
;
1393 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
1394 At the end, we see a semicolon instead of a field.
1396 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
1399 The `?' is a placeholder for one of '/2' (public visibility),
1400 '/1' (protected visibility), '/0' (private visibility), or nothing
1401 (C style symbol table, public visibility). */
1403 /* We better set p right now, in case there are no fields at all... */
1408 /* Check for and handle cretinous dbx symbol name continuation! */
1409 if (**pp
== '\\') *pp
= next_symbol_text ();
1411 /* Get space to record the next field's data. */
1412 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1413 memset (new, 0, sizeof (struct nextfield
));
1417 /* Get the field name. */
1419 if (*p
== CPLUS_MARKER
)
1421 if (*p
== '_') /* GNU C++ anonymous type. */
1423 /* Special GNU C++ name. */
1424 else if (*++p
== 'v')
1428 struct type
*context
;
1439 complain (&invalid_cpp_abbrev_complaint
, *pp
);
1440 prefix
= "INVALID_C++_ABBREV";
1444 context
= read_type (pp
, objfile
);
1445 name
= type_name_no_tag (context
);
1448 complain (&invalid_cpp_type_complaint
, (char *) symnum
);
1451 list
->field
.name
= obconcat (&objfile
-> type_obstack
,
1455 complain (&invalid_cpp_abbrev_complaint
, *pp
);
1456 list
->field
.type
= read_type (pp
, objfile
);
1457 (*pp
)++; /* Skip the comma. */
1458 list
->field
.bitpos
= read_number (pp
, ';');
1459 /* This field is unpacked. */
1460 list
->field
.bitsize
= 0;
1461 list
->visibility
= 0; /* private */
1462 non_public_fields
++;
1468 complain (&invalid_cpp_abbrev_complaint
, *pp
);
1471 while (*p
!= ':') p
++;
1472 list
->field
.name
= obsavestring (*pp
, p
- *pp
,
1473 &objfile
-> type_obstack
);
1475 /* C++: Check to see if we have hit the methods yet. */
1481 /* This means we have a visibility for a field coming. */
1487 list
->visibility
= 0; /* private */
1488 non_public_fields
++;
1493 list
->visibility
= 1; /* protected */
1494 non_public_fields
++;
1499 list
->visibility
= 2; /* public */
1504 else /* normal dbx-style format. */
1505 list
->visibility
= 2; /* public */
1507 list
->field
.type
= read_type (pp
, objfile
);
1512 { /* C++ nested type -as in FOO::BAR */
1513 list
->field
.bitpos
= (long)(-2); /* nested type */
1515 if (TYPE_NAME (list
->field
.type
) == NULL
&& **pp
== '\'')
1517 for (p
= ++(*pp
); *p
!= '\''; ) p
++;
1518 TYPE_NAME (list
->field
.type
) = savestring (*pp
, p
- *pp
);
1520 while (*p
!= ';') p
++;
1521 list
->field
.bitsize
= 0;
1525 { /* Static class member. */
1526 list
->field
.bitpos
= (long)(-1);
1527 while (*p
!= ';') p
++;
1528 list
->field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
1534 else if (**pp
!= ',')
1535 /* Bad structure-type format. */
1536 return error_type (pp
);
1538 (*pp
)++; /* Skip the comma. */
1539 list
->field
.bitpos
= read_number (pp
, ',');
1540 list
->field
.bitsize
= read_number (pp
, ';');
1543 /* FIXME-tiemann: Can't the compiler put out something which
1544 lets us distinguish these? (or maybe just not put out anything
1545 for the field). What is the story here? What does the compiler
1546 really do? Also, patch gdb.texinfo for this case; I document
1547 it as a possible problem there. Search for "DBX-style". */
1549 /* This is wrong because this is identical to the symbols
1550 produced for GCC 0-size arrays. For example:
1555 The code which dumped core in such circumstances should be
1556 fixed not to dump core. */
1558 /* g++ -g0 can put out bitpos & bitsize zero for a static
1559 field. This does not give us any way of getting its
1560 class, so we can't know its name. But we can just
1561 ignore the field so we don't dump core and other nasty
1563 if (list
->field
.bitpos
== 0
1564 && list
->field
.bitsize
== 0)
1566 complain (&dbx_class_complaint
, 0);
1567 /* Ignore this field. */
1573 /* Detect an unpacked field and mark it as such.
1574 dbx gives a bit size for all fields.
1575 Note that forward refs cannot be packed,
1576 and treat enums as if they had the width of ints. */
1577 if (TYPE_CODE (list
->field
.type
) != TYPE_CODE_INT
1578 && TYPE_CODE (list
->field
.type
) != TYPE_CODE_ENUM
)
1579 list
->field
.bitsize
= 0;
1580 if ((list
->field
.bitsize
== 8 * TYPE_LENGTH (list
->field
.type
)
1581 || (TYPE_CODE (list
->field
.type
) == TYPE_CODE_ENUM
1582 && (list
->field
.bitsize
1583 == 8 * TYPE_LENGTH (lookup_fundamental_type (objfile
, FT_INTEGER
)))
1587 list
->field
.bitpos
% 8 == 0)
1588 list
->field
.bitsize
= 0;
1594 /* chill the list of fields: the last entry (at the head)
1595 is a partially constructed entry which we now scrub. */
1598 /* Now create the vector of fields, and record how big it is.
1599 We need this info to record proper virtual function table information
1600 for this class's virtual functions. */
1602 TYPE_NFIELDS (type
) = nfields
;
1603 TYPE_FIELDS (type
) = (struct field
*)
1604 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
1605 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
1607 if (non_public_fields
)
1609 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1611 TYPE_FIELD_PRIVATE_BITS (type
) = (B_TYPE
*)
1612 TYPE_ALLOC (type
, B_BYTES (nfields
));
1613 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1615 TYPE_FIELD_PROTECTED_BITS (type
) = (B_TYPE
*)
1616 TYPE_ALLOC (type
, B_BYTES (nfields
));
1617 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1620 /* Copy the saved-up fields into the field vector. */
1622 for (n
= nfields
; list
; list
= list
->next
)
1625 TYPE_FIELD (type
, n
) = list
->field
;
1626 if (list
->visibility
== 0)
1627 SET_TYPE_FIELD_PRIVATE (type
, n
);
1628 else if (list
->visibility
== 1)
1629 SET_TYPE_FIELD_PROTECTED (type
, n
);
1632 /* Now come the method fields, as NAME::methods
1633 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
1634 At the end, we see a semicolon instead of a field.
1636 For the case of overloaded operators, the format is
1637 op$::*.methods, where $ is the CPLUS_MARKER (usually '$'),
1638 `*' holds the place for an operator name (such as `+=')
1639 and `.' marks the end of the operator name. */
1642 /* Now, read in the methods. To simplify matters, we
1643 "unread" the name that has been read, so that we can
1644 start from the top. */
1646 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1647 /* For each list of method lists... */
1651 struct next_fnfield
*sublist
= 0;
1652 struct type
*look_ahead_type
= NULL
;
1654 struct next_fnfieldlist
*new_mainlist
;
1657 new_mainlist
= (struct next_fnfieldlist
*)
1658 alloca (sizeof (struct next_fnfieldlist
));
1659 memset (new_mainlist
, 0, sizeof (struct next_fnfieldlist
));
1663 /* read in the name. */
1664 while (*p
!= ':') p
++;
1665 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
1667 /* This is a completely wierd case. In order to stuff in the
1668 names that might contain colons (the usual name delimiter),
1669 Mike Tiemann defined a different name format which is
1670 signalled if the identifier is "op$". In that case, the
1671 format is "op$::XXXX." where XXXX is the name. This is
1672 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1673 /* This lets the user type "break operator+".
1674 We could just put in "+" as the name, but that wouldn't
1676 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
1677 char *o
= opname
+ 3;
1679 /* Skip past '::'. */
1681 if (**pp
== '\\') *pp
= next_symbol_text ();
1685 main_fn_name
= savestring (opname
, o
- opname
);
1691 main_fn_name
= savestring (*pp
, p
- *pp
);
1692 /* Skip past '::'. */
1695 new_mainlist
->fn_fieldlist
.name
= main_fn_name
;
1699 struct next_fnfield
*new_sublist
=
1700 (struct next_fnfield
*) alloca (sizeof (struct next_fnfield
));
1701 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
1703 /* Check for and handle cretinous dbx symbol name continuation! */
1704 if (look_ahead_type
== NULL
) /* Normal case. */
1706 if (**pp
== '\\') *pp
= next_symbol_text ();
1708 new_sublist
->fn_field
.type
= read_type (pp
, objfile
);
1710 /* Invalid symtab info for method. */
1711 return error_type (pp
);
1714 { /* g++ version 1 kludge */
1715 new_sublist
->fn_field
.type
= look_ahead_type
;
1716 look_ahead_type
= NULL
;
1721 while (*p
!= ';') p
++;
1723 /* If this is just a stub, then we don't have the
1725 if (TYPE_FLAGS (new_sublist
->fn_field
.type
) & TYPE_FLAG_STUB
)
1726 new_sublist
->fn_field
.is_stub
= 1;
1727 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
1730 /* Set this method's visibility fields. */
1731 switch (*(*pp
)++ - '0')
1734 new_sublist
->fn_field
.is_private
= 1;
1737 new_sublist
->fn_field
.is_protected
= 1;
1741 if (**pp
== '\\') *pp
= next_symbol_text ();
1744 case 'A': /* Normal functions. */
1745 new_sublist
->fn_field
.is_const
= 0;
1746 new_sublist
->fn_field
.is_volatile
= 0;
1749 case 'B': /* `const' member functions. */
1750 new_sublist
->fn_field
.is_const
= 1;
1751 new_sublist
->fn_field
.is_volatile
= 0;
1754 case 'C': /* `volatile' member function. */
1755 new_sublist
->fn_field
.is_const
= 0;
1756 new_sublist
->fn_field
.is_volatile
= 1;
1759 case 'D': /* `const volatile' member function. */
1760 new_sublist
->fn_field
.is_const
= 1;
1761 new_sublist
->fn_field
.is_volatile
= 1;
1764 case '*': /* File compiled with g++ version 1 -- no info */
1769 complain (&const_vol_complaint
, (char *) (long) **pp
);
1776 /* virtual member function, followed by index. */
1777 /* The sign bit is set to distinguish pointers-to-methods
1778 from virtual function indicies. Since the array is
1779 in words, the quantity must be shifted left by 1
1780 on 16 bit machine, and by 2 on 32 bit machine, forcing
1781 the sign bit out, and usable as a valid index into
1782 the array. Remove the sign bit here. */
1783 new_sublist
->fn_field
.voffset
=
1784 (0x7fffffff & read_number (pp
, ';')) + 2;
1786 if (**pp
== '\\') *pp
= next_symbol_text ();
1788 if (**pp
== ';' || **pp
== '\0')
1789 /* Must be g++ version 1. */
1790 new_sublist
->fn_field
.fcontext
= 0;
1793 /* Figure out from whence this virtual function came.
1794 It may belong to virtual function table of
1795 one of its baseclasses. */
1796 look_ahead_type
= read_type (pp
, objfile
);
1798 { /* g++ version 1 overloaded methods. */ }
1801 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
1803 return error_type (pp
);
1806 look_ahead_type
= NULL
;
1812 /* static member function. */
1813 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
1814 if (strncmp (new_sublist
->fn_field
.physname
,
1815 main_fn_name
, strlen (main_fn_name
)))
1816 new_sublist
->fn_field
.is_stub
= 1;
1821 complain (&member_fn_complaint
, (char *) (long) (*pp
)[-1]);
1822 /* Fall through into normal member function. */
1825 /* normal member function. */
1826 new_sublist
->fn_field
.voffset
= 0;
1827 new_sublist
->fn_field
.fcontext
= 0;
1831 new_sublist
->next
= sublist
;
1832 sublist
= new_sublist
;
1834 if (**pp
== '\\') *pp
= next_symbol_text ();
1836 while (**pp
!= ';' && **pp
!= '\0');
1840 new_mainlist
->fn_fieldlist
.fn_fields
= (struct fn_field
*)
1841 obstack_alloc (&objfile
-> type_obstack
,
1842 sizeof (struct fn_field
) * length
);
1843 memset (new_mainlist
->fn_fieldlist
.fn_fields
, 0,
1844 sizeof (struct fn_field
) * length
);
1845 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
1846 new_mainlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
1848 new_mainlist
->fn_fieldlist
.length
= length
;
1849 new_mainlist
->next
= mainlist
;
1850 mainlist
= new_mainlist
;
1852 total_length
+= length
;
1853 if (**pp
== '\\') *pp
= next_symbol_text ();
1855 while (**pp
!= ';');
1863 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
1864 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
1865 memset (TYPE_FN_FIELDLISTS (type
), 0,
1866 sizeof (struct fn_fieldlist
) * nfn_fields
);
1867 TYPE_NFN_FIELDS (type
) = nfn_fields
;
1868 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
1873 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); ++i
)
1875 if (TYPE_CODE (TYPE_BASECLASS (type
, i
)) == TYPE_CODE_UNDEF
)
1876 /* @@ Memory leak on objfile->type_obstack? */
1877 return error_type (pp
);
1878 TYPE_NFN_FIELDS_TOTAL (type
) +=
1879 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, i
));
1883 for (n
= nfn_fields
; mainlist
; mainlist
= mainlist
->next
) {
1884 --n
; /* Circumvent Sun3 compiler bug */
1885 TYPE_FN_FIELDLISTS (type
)[n
] = mainlist
->fn_fieldlist
;
1892 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
1894 /* Obsolete flags that used to indicate the presence
1895 of constructors and/or destructors. */
1899 /* Read either a '%' or the final ';'. */
1900 if (*(*pp
)++ == '%')
1902 /* We'd like to be able to derive the vtable pointer field
1903 from the type information, but when it's inherited, that's
1904 hard. A reason it's hard is because we may read in the
1905 info about a derived class before we read in info about
1906 the base class that provides the vtable pointer field.
1907 Once the base info has been read, we could fill in the info
1908 for the derived classes, but for the fact that by then,
1909 we don't remember who needs what. */
1912 int predicted_fieldno
= -1;
1915 /* Now we must record the virtual function table pointer's
1916 field information. */
1924 /* In version 2, we derive the vfield ourselves. */
1925 for (n
= 0; n
< nfields
; n
++)
1927 if (! strncmp (TYPE_FIELD_NAME (type
, n
), vptr_name
,
1928 sizeof (vptr_name
) -1))
1930 predicted_fieldno
= n
;
1934 if (predicted_fieldno
< 0)
1935 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
1936 if (! TYPE_FIELD_VIRTUAL (type
, n
)
1937 && TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
)) >= 0)
1939 predicted_fieldno
= TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
));
1945 t
= read_type (pp
, objfile
);
1947 while (*p
!= '\0' && *p
!= ';')
1950 /* Premature end of symbol. */
1951 return error_type (pp
);
1953 TYPE_VPTR_BASETYPE (type
) = t
;
1956 if (TYPE_FIELD_NAME (t
, TYPE_N_BASECLASSES (t
)) == 0)
1958 /* FIXME-tiemann: what's this? */
1960 TYPE_VPTR_FIELDNO (type
) = i
= TYPE_N_BASECLASSES (t
);
1965 else for (i
= TYPE_NFIELDS (t
) - 1; i
>= TYPE_N_BASECLASSES (t
); --i
)
1966 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
1967 sizeof (vptr_name
) - 1))
1969 TYPE_VPTR_FIELDNO (type
) = i
;
1973 /* Virtual function table field not found. */
1974 return error_type (pp
);
1977 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
1980 if (TYPE_VPTR_FIELDNO (type
) != predicted_fieldno
)
1981 error ("TYPE_VPTR_FIELDNO miscalculated");
1991 /* Read a definition of an array type,
1992 and create and return a suitable type object.
1993 Also creates a range type which represents the bounds of that
1996 static struct type
*
1997 read_array_type (pp
, type
, objfile
)
1999 register struct type
*type
;
2000 struct objfile
*objfile
;
2002 struct type
*index_type
, *element_type
, *range_type
;
2006 /* Format of an array type:
2007 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2010 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2011 for these, produce a type like float[][]. */
2013 index_type
= read_type (pp
, objfile
);
2015 /* Improper format of array type decl. */
2016 return error_type (pp
);
2019 if (!(**pp
>= '0' && **pp
<= '9'))
2024 lower
= read_number (pp
, ';');
2026 if (!(**pp
>= '0' && **pp
<= '9'))
2031 upper
= read_number (pp
, ';');
2033 element_type
= read_type (pp
, objfile
);
2042 /* Create range type. */
2043 range_type
= alloc_type (objfile
);
2044 TYPE_CODE (range_type
) = TYPE_CODE_RANGE
;
2045 TYPE_TARGET_TYPE (range_type
) = index_type
;
2047 /* This should never be needed. */
2048 TYPE_LENGTH (range_type
) = sizeof (int);
2050 TYPE_NFIELDS (range_type
) = 2;
2051 TYPE_FIELDS (range_type
) = (struct field
*)
2052 TYPE_ALLOC (range_type
, 2 * sizeof (struct field
));
2053 memset (TYPE_FIELDS (range_type
), 0, 2 * sizeof (struct field
));
2054 TYPE_FIELD_BITPOS (range_type
, 0) = lower
;
2055 TYPE_FIELD_BITPOS (range_type
, 1) = upper
;
2058 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
2059 TYPE_TARGET_TYPE (type
) = element_type
;
2060 TYPE_LENGTH (type
) = (upper
- lower
+ 1) * TYPE_LENGTH (element_type
);
2061 TYPE_NFIELDS (type
) = 1;
2062 TYPE_FIELDS (type
) = (struct field
*)
2063 TYPE_ALLOC (type
, sizeof (struct field
));
2064 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
));
2065 TYPE_FIELD_TYPE (type
, 0) = range_type
;
2067 /* If we have an array whose element type is not yet known, but whose
2068 bounds *are* known, record it to be adjusted at the end of the file. */
2069 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2070 add_undefined_type (type
);
2076 /* Read a definition of an enumeration type,
2077 and create and return a suitable type object.
2078 Also defines the symbols that represent the values of the type. */
2080 static struct type
*
2081 read_enum_type (pp
, type
, objfile
)
2083 register struct type
*type
;
2084 struct objfile
*objfile
;
2089 register struct symbol
*sym
;
2091 struct pending
**symlist
;
2092 struct pending
*osyms
, *syms
;
2096 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2097 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2098 to do? For now, force all enum values to file scope. */
2099 if (within_function
)
2100 symlist
= &local_symbols
;
2103 symlist
= &file_symbols
;
2105 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2107 /* Read the value-names and their values.
2108 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2109 A semicolon or comma instead of a NAME means the end. */
2110 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2112 /* Check for and handle cretinous dbx symbol name continuation! */
2113 if (**pp
== '\\') *pp
= next_symbol_text ();
2116 while (*p
!= ':') p
++;
2117 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
2119 n
= read_number (pp
, ',');
2121 sym
= (struct symbol
*)
2122 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
2123 memset (sym
, 0, sizeof (struct symbol
));
2124 SYMBOL_NAME (sym
) = name
;
2125 SYMBOL_CLASS (sym
) = LOC_CONST
;
2126 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2127 SYMBOL_VALUE (sym
) = n
;
2128 add_symbol_to_list (sym
, symlist
);
2133 (*pp
)++; /* Skip the semicolon. */
2135 /* Now fill in the fields of the type-structure. */
2137 TYPE_LENGTH (type
) = sizeof (int);
2138 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2139 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2140 TYPE_NFIELDS (type
) = nsyms
;
2141 TYPE_FIELDS (type
) = (struct field
*)
2142 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
2143 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
2145 /* Find the symbols for the values and put them into the type.
2146 The symbols can be found in the symlist that we put them on
2147 to cause them to be defined. osyms contains the old value
2148 of that symlist; everything up to there was defined by us. */
2149 /* Note that we preserve the order of the enum constants, so
2150 that in something like "enum {FOO, LAST_THING=FOO}" we print
2151 FOO, not LAST_THING. */
2153 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2158 for (; j
< syms
->nsyms
; j
++,n
++)
2160 struct symbol
*xsym
= syms
->symbol
[j
];
2161 SYMBOL_TYPE (xsym
) = type
;
2162 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2163 TYPE_FIELD_VALUE (type
, n
) = 0;
2164 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2165 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2172 /* This screws up perfectly good C programs with enums. FIXME. */
2173 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2174 if(TYPE_NFIELDS(type
) == 2 &&
2175 ((!strcmp(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2176 !strcmp(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2177 (!strcmp(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2178 !strcmp(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2179 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2185 /* Sun's ACC uses a somewhat saner method for specifying the builtin
2186 typedefs in every file (for int, long, etc):
2188 type = b <signed> <width>; <offset>; <nbits>
2189 signed = u or s. Possible c in addition to u or s (for char?).
2190 offset = offset from high order bit to start bit of type.
2191 width is # bytes in object of this type, nbits is # bits in type.
2193 The width/offset stuff appears to be for small objects stored in
2194 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
2197 static struct type
*
2198 read_sun_builtin_type (pp
, typenums
, objfile
)
2201 struct objfile
*objfile
;
2215 return error_type (pp
);
2219 /* For some odd reason, all forms of char put a c here. This is strange
2220 because no other type has this honor. We can safely ignore this because
2221 we actually determine 'char'acterness by the number of bits specified in
2227 /* The first number appears to be the number of bytes occupied
2228 by this type, except that unsigned short is 4 instead of 2.
2229 Since this information is redundant with the third number,
2230 we will ignore it. */
2231 read_number (pp
, ';');
2233 /* The second number is always 0, so ignore it too. */
2234 read_number (pp
, ';');
2236 /* The third number is the number of bits for this type. */
2237 nbits
= read_number (pp
, 0);
2239 /* FIXME. Here we should just be able to make a type of the right
2240 number of bits and signedness. FIXME. */
2242 if (nbits
== TARGET_LONG_LONG_BIT
)
2243 return (lookup_fundamental_type (objfile
,
2244 signed_type
? FT_LONG_LONG
: FT_UNSIGNED_LONG_LONG
));
2246 if (nbits
== TARGET_INT_BIT
)
2248 /* FIXME -- the only way to distinguish `int' from `long'
2249 is to look at its name! */
2252 if (long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
2253 return lookup_fundamental_type (objfile
, FT_LONG
);
2255 return lookup_fundamental_type (objfile
, FT_INTEGER
);
2259 if (long_kludge_name
2260 && ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2261 long_kludge_name
[9] == 'l' /* long */)
2262 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2263 return lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
);
2265 return lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
2269 if (nbits
== TARGET_SHORT_BIT
)
2270 return (lookup_fundamental_type (objfile
,
2271 signed_type
? FT_SHORT
: FT_UNSIGNED_SHORT
));
2273 if (nbits
== TARGET_CHAR_BIT
)
2274 return (lookup_fundamental_type (objfile
,
2275 signed_type
? FT_CHAR
: FT_UNSIGNED_CHAR
));
2278 return lookup_fundamental_type (objfile
, FT_VOID
);
2280 return error_type (pp
);
2283 static struct type
*
2284 read_sun_floating_type (pp
, typenums
, objfile
)
2287 struct objfile
*objfile
;
2291 /* The first number has more details about the type, for example
2292 FN_COMPLEX. See the sun stab.h. */
2293 read_number (pp
, ';');
2295 /* The second number is the number of bytes occupied by this type */
2296 nbytes
= read_number (pp
, ';');
2299 return error_type (pp
);
2301 if (nbytes
== TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
)
2302 return lookup_fundamental_type (objfile
, FT_FLOAT
);
2304 if (nbytes
== TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
2305 return lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
2307 if (nbytes
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
2308 return lookup_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
2310 return error_type (pp
);
2313 /* Read a number from the string pointed to by *PP.
2314 The value of *PP is advanced over the number.
2315 If END is nonzero, the character that ends the
2316 number must match END, or an error happens;
2317 and that character is skipped if it does match.
2318 If END is zero, *PP is left pointing to that character.
2320 If the number fits in a long, set *VALUE and set *BITS to 0.
2321 If not, set *BITS to be the number of bits in the number.
2323 If encounter garbage, set *BITS to -1. */
2326 read_huge_number (pp
, end
, valu
, bits
)
2347 /* Leading zero means octal. GCC uses this to output values larger
2348 than an int (because that would be hard in decimal). */
2355 upper_limit
= LONG_MAX
/ radix
;
2356 while ((c
= *p
++) >= '0' && c
<= ('0' + radix
))
2358 if (n
<= upper_limit
)
2361 n
+= c
- '0'; /* FIXME this overflows anyway */
2366 /* This depends on large values being output in octal, which is
2373 /* Ignore leading zeroes. */
2377 else if (c
== '2' || c
== '3')
2403 /* Large decimal constants are an error (because it is hard to
2404 count how many bits are in them). */
2410 /* -0x7f is the same as 0x80. So deal with it by adding one to
2411 the number of bits. */
2426 static struct type
*
2427 read_range_type (pp
, typenums
, objfile
)
2430 struct objfile
*objfile
;
2436 struct type
*result_type
;
2438 /* First comes a type we are a subrange of.
2439 In C it is usually 0, 1 or the type being defined. */
2440 read_type_number (pp
, rangenums
);
2441 self_subrange
= (rangenums
[0] == typenums
[0] &&
2442 rangenums
[1] == typenums
[1]);
2444 /* A semicolon should now follow; skip it. */
2448 /* The remaining two operands are usually lower and upper bounds
2449 of the range. But in some special cases they mean something else. */
2450 read_huge_number (pp
, ';', &n2
, &n2bits
);
2451 read_huge_number (pp
, ';', &n3
, &n3bits
);
2453 if (n2bits
== -1 || n3bits
== -1)
2454 return error_type (pp
);
2456 /* If limits are huge, must be large integral type. */
2457 if (n2bits
!= 0 || n3bits
!= 0)
2459 char got_signed
= 0;
2460 char got_unsigned
= 0;
2461 /* Number of bits in the type. */
2464 /* Range from 0 to <large number> is an unsigned large integral type. */
2465 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
2470 /* Range from <large number> to <large number>-1 is a large signed
2472 else if (n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
2478 /* Check for "long long". */
2479 if (got_signed
&& nbits
== TARGET_LONG_LONG_BIT
)
2480 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
2481 if (got_unsigned
&& nbits
== TARGET_LONG_LONG_BIT
)
2482 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
2484 if (got_signed
|| got_unsigned
)
2486 result_type
= alloc_type (objfile
);
2487 TYPE_LENGTH (result_type
) = nbits
/ TARGET_CHAR_BIT
;
2488 TYPE_CODE (result_type
) = TYPE_CODE_INT
;
2490 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
2494 return error_type (pp
);
2497 /* A type defined as a subrange of itself, with bounds both 0, is void. */
2498 if (self_subrange
&& n2
== 0 && n3
== 0)
2499 return (lookup_fundamental_type (objfile
, FT_VOID
));
2501 /* If n3 is zero and n2 is not, we want a floating type,
2502 and n2 is the width in bytes.
2504 Fortran programs appear to use this for complex types also,
2505 and they give no way to distinguish between double and single-complex!
2506 We don't have complex types, so we would lose on all fortran files!
2507 So return type `double' for all of those. It won't work right
2508 for the complex values, but at least it makes the file loadable.
2510 FIXME, we may be able to distinguish these by their names. FIXME. */
2512 if (n3
== 0 && n2
> 0)
2514 if (n2
== sizeof (float))
2515 return (lookup_fundamental_type (objfile
, FT_FLOAT
));
2516 return (lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
));
2519 /* If the upper bound is -1, it must really be an unsigned int. */
2521 else if (n2
== 0 && n3
== -1)
2523 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2524 long' is to look at its name! */
2526 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2527 long_kludge_name
[9] == 'l' /* long */)
2528 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2529 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
2531 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
2534 /* Special case: char is defined (Who knows why) as a subrange of
2535 itself with range 0-127. */
2536 else if (self_subrange
&& n2
== 0 && n3
== 127)
2537 return (lookup_fundamental_type (objfile
, FT_CHAR
));
2539 /* Assumptions made here: Subrange of self is equivalent to subrange
2540 of int. FIXME: Host and target type-sizes assumed the same. */
2541 /* FIXME: This is the *only* place in GDB that depends on comparing
2542 some type to a builtin type with ==. Fix it! */
2544 && (self_subrange
||
2545 *dbx_lookup_type (rangenums
) == lookup_fundamental_type (objfile
, FT_INTEGER
)))
2547 /* an unsigned type */
2549 if (n3
== - sizeof (long long))
2550 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
2552 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2553 long' is to look at its name! */
2554 if (n3
== (unsigned long)~0L &&
2555 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2556 long_kludge_name
[9] == 'l' /* long */)
2557 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2558 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
2559 if (n3
== (unsigned int)~0L)
2560 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
2561 if (n3
== (unsigned short)~0L)
2562 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_SHORT
));
2563 if (n3
== (unsigned char)~0L)
2564 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_CHAR
));
2567 else if (n3
== 0 && n2
== -sizeof (long long))
2568 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
2570 else if (n2
== -n3
-1)
2573 /* FIXME -- the only way to distinguish `int' from `long' is to look
2575 if ((n3
==(long)(((unsigned long)1 << (8 * sizeof (long) - 1)) - 1)) &&
2576 long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
2577 return (lookup_fundamental_type (objfile
, FT_LONG
));
2578 if (n3
== (long)(((unsigned long)1 << (8 * sizeof (int) - 1)) - 1))
2579 return (lookup_fundamental_type (objfile
, FT_INTEGER
));
2580 if (n3
== ( 1 << (8 * sizeof (short) - 1)) - 1)
2581 return (lookup_fundamental_type (objfile
, FT_SHORT
));
2582 if (n3
== ( 1 << (8 * sizeof (char) - 1)) - 1)
2583 return (lookup_fundamental_type (objfile
, FT_SIGNED_CHAR
));
2586 /* We have a real range type on our hands. Allocate space and
2587 return a real pointer. */
2589 /* At this point I don't have the faintest idea how to deal with
2590 a self_subrange type; I'm going to assume that this is used
2591 as an idiom, and that all of them are special cases. So . . . */
2593 return error_type (pp
);
2595 result_type
= alloc_type (objfile
);
2597 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
2599 TYPE_TARGET_TYPE (result_type
) = *dbx_lookup_type(rangenums
);
2600 if (TYPE_TARGET_TYPE (result_type
) == 0) {
2601 complain (&range_type_base_complaint
, (char *) rangenums
[1]);
2602 TYPE_TARGET_TYPE (result_type
) = lookup_fundamental_type (objfile
, FT_INTEGER
);
2605 TYPE_NFIELDS (result_type
) = 2;
2606 TYPE_FIELDS (result_type
) = (struct field
*)
2607 TYPE_ALLOC (result_type
, 2 * sizeof (struct field
));
2608 memset (TYPE_FIELDS (result_type
), 0, 2 * sizeof (struct field
));
2609 TYPE_FIELD_BITPOS (result_type
, 0) = n2
;
2610 TYPE_FIELD_BITPOS (result_type
, 1) = n3
;
2612 TYPE_LENGTH (result_type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type
));
2617 /* Read a number from the string pointed to by *PP.
2618 The value of *PP is advanced over the number.
2619 If END is nonzero, the character that ends the
2620 number must match END, or an error happens;
2621 and that character is skipped if it does match.
2622 If END is zero, *PP is left pointing to that character. */
2625 read_number (pp
, end
)
2629 register char *p
= *pp
;
2630 register long n
= 0;
2634 /* Handle an optional leading minus sign. */
2642 /* Read the digits, as far as they go. */
2644 while ((c
= *p
++) >= '0' && c
<= '9')
2652 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c
, symnum
);
2661 /* Read in an argument list. This is a list of types, separated by commas
2662 and terminated with END. Return the list of types read in, or (struct type
2663 **)-1 if there is an error. */
2665 static struct type
**
2666 read_args (pp
, end
, objfile
)
2669 struct objfile
*objfile
;
2671 /* FIXME! Remove this arbitrary limit! */
2672 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
2678 /* Invalid argument list: no ','. */
2679 return (struct type
**)-1;
2682 /* Check for and handle cretinous dbx symbol name continuation! */
2684 *pp
= next_symbol_text ();
2686 types
[n
++] = read_type (pp
, objfile
);
2688 *pp
+= 1; /* get past `end' (the ':' character) */
2692 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
2694 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
2696 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
2697 memset (rval
+ n
, 0, sizeof (struct type
*));
2701 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
2703 memcpy (rval
, types
, n
* sizeof (struct type
*));
2707 /* Add a common block's start address to the offset of each symbol
2708 declared to be in it (by being between a BCOMM/ECOMM pair that uses
2709 the common block name). */
2712 fix_common_block (sym
, valu
)
2716 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
2717 for ( ; next
; next
= next
->next
)
2720 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
2721 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
2727 /* What about types defined as forward references inside of a small lexical
2729 /* Add a type to the list of undefined types to be checked through
2730 once this file has been read in. */
2733 add_undefined_type (type
)
2736 if (undef_types_length
== undef_types_allocated
)
2738 undef_types_allocated
*= 2;
2739 undef_types
= (struct type
**)
2740 xrealloc ((char *) undef_types
,
2741 undef_types_allocated
* sizeof (struct type
*));
2743 undef_types
[undef_types_length
++] = type
;
2746 /* Go through each undefined type, see if it's still undefined, and fix it
2747 up if possible. We have two kinds of undefined types:
2749 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
2750 Fix: update array length using the element bounds
2751 and the target type's length.
2752 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
2753 yet defined at the time a pointer to it was made.
2754 Fix: Do a full lookup on the struct/union tag. */
2756 cleanup_undefined_types ()
2760 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
2762 switch (TYPE_CODE (*type
))
2765 case TYPE_CODE_STRUCT
:
2766 case TYPE_CODE_UNION
:
2767 case TYPE_CODE_ENUM
:
2769 /* Check if it has been defined since. */
2770 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
2772 struct pending
*ppt
;
2774 /* Name of the type, without "struct" or "union" */
2775 char *typename
= TYPE_NAME (*type
);
2777 if (!strncmp (typename
, "struct ", 7))
2779 if (!strncmp (typename
, "union ", 6))
2781 if (!strncmp (typename
, "enum ", 5))
2784 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
2786 for (i
= 0; i
< ppt
->nsyms
; i
++)
2788 struct symbol
*sym
= ppt
->symbol
[i
];
2790 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
2791 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
2792 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
2794 && !strcmp (SYMBOL_NAME (sym
), typename
))
2796 memcpy (*type
, SYMBOL_TYPE (sym
),
2797 sizeof (struct type
));
2805 case TYPE_CODE_ARRAY
:
2807 struct type
*range_type
;
2810 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
2812 if (TYPE_NFIELDS (*type
) != 1)
2814 range_type
= TYPE_FIELD_TYPE (*type
, 0);
2815 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
2818 /* Now recompute the length of the array type, based on its
2819 number of elements and the target type's length. */
2820 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
2821 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
2822 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
2823 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
2829 error ("GDB internal error. cleanup_undefined_types with bad type %d.", TYPE_CODE (*type
));
2833 undef_types_length
= 0;
2836 /* Scan through all of the global symbols defined in the object file,
2837 assigning values to the debugging symbols that need to be assigned
2838 to. Get these symbols from the minimal symbol table. */
2841 scan_file_globals (objfile
)
2842 struct objfile
*objfile
;
2845 struct minimal_symbol
*msymbol
;
2846 struct symbol
*sym
, *prev
;
2848 if (objfile
->msymbols
== 0) /* Beware the null file. */
2851 for (msymbol
= objfile
-> msymbols
; msymbol
-> name
!= NULL
; msymbol
++)
2857 /* Get the hash index and check all the symbols
2858 under that hash index. */
2860 hash
= hashname (msymbol
-> name
);
2862 for (sym
= global_sym_chain
[hash
]; sym
;)
2864 if (*(msymbol
-> name
) == SYMBOL_NAME (sym
)[0]
2865 && !strcmp(msymbol
-> name
+ 1, SYMBOL_NAME (sym
) + 1))
2867 /* Splice this symbol out of the hash chain and
2868 assign the value we have to it. */
2871 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
2875 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
2878 /* Check to see whether we need to fix up a common block. */
2879 /* Note: this code might be executed several times for
2880 the same symbol if there are multiple references. */
2882 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2884 fix_common_block (sym
, msymbol
-> address
);
2888 SYMBOL_VALUE_ADDRESS (sym
) = msymbol
-> address
;
2893 sym
= SYMBOL_VALUE_CHAIN (prev
);
2897 sym
= global_sym_chain
[hash
];
2903 sym
= SYMBOL_VALUE_CHAIN (sym
);
2909 /* Initialize anything that needs initializing when starting to read
2910 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
2918 /* Initialize anything that needs initializing when a completely new
2919 symbol file is specified (not just adding some symbols from another
2920 file, e.g. a shared library). */
2923 stabsread_new_init ()
2925 /* Empty the hash table of global syms looking for values. */
2926 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
2929 /* Initialize anything that needs initializing at the same time as
2930 start_symtab() is called. */
2934 global_stabs
= NULL
; /* AIX COFF */
2935 /* Leave FILENUM of 0 free for builtin types and this file's types. */
2936 n_this_object_header_files
= 1;
2937 type_vector_length
= 0;
2938 type_vector
= (struct type
**) 0;
2941 /* Call after end_symtab() */
2947 free ((char *) type_vector
);
2950 type_vector_length
= 0;
2951 previous_stab_code
= 0;
2955 finish_global_stabs (objfile
)
2956 struct objfile
*objfile
;
2960 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
2961 free ((PTR
) global_stabs
);
2962 global_stabs
= NULL
;
2966 /* Initializer for this module */
2969 _initialize_stabsread ()
2971 undef_types_allocated
= 20;
2972 undef_types_length
= 0;
2973 undef_types
= (struct type
**)
2974 xmalloc (undef_types_allocated
* sizeof (struct type
*));