1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993
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. */
34 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
36 #include "complaints.h"
41 /* Ask stabsread.h to define the vars it normally declares `extern'. */
43 #include "stabsread.h" /* Our own declarations */
46 /* The routines that read and process a complete stabs for a C struct or
47 C++ class pass lists of data member fields and lists of member function
48 fields in an instance of a field_info structure, as defined below.
49 This is part of some reorganization of low level C++ support and is
50 expected to eventually go away... (FIXME) */
56 struct nextfield
*next
;
60 struct next_fnfieldlist
62 struct next_fnfieldlist
*next
;
63 struct fn_fieldlist fn_fieldlist
;
68 dbx_alloc_type
PARAMS ((int [2], struct objfile
*));
70 static long read_huge_number
PARAMS ((char **, int, int *));
72 static struct type
*error_type
PARAMS ((char **));
75 patch_block_stabs
PARAMS ((struct pending
*, struct pending_stabs
*,
79 fix_common_block
PARAMS ((struct symbol
*, int));
82 read_type_number
PARAMS ((char **, int *));
85 read_range_type
PARAMS ((char **, int [2], struct objfile
*));
88 read_sun_builtin_type
PARAMS ((char **, int [2], struct objfile
*));
91 read_sun_floating_type
PARAMS ((char **, int [2], struct objfile
*));
94 read_enum_type
PARAMS ((char **, struct type
*, struct objfile
*));
97 rs6000_builtin_type
PARAMS ((int));
100 read_member_functions
PARAMS ((struct field_info
*, char **, struct type
*,
104 read_struct_fields
PARAMS ((struct field_info
*, char **, struct type
*,
108 read_baseclasses
PARAMS ((struct field_info
*, char **, struct type
*,
112 read_tilde_fields
PARAMS ((struct field_info
*, char **, struct type
*,
116 attach_fn_fields_to_type
PARAMS ((struct field_info
*, struct type
*));
119 attach_fields_to_type
PARAMS ((struct field_info
*, struct type
*,
123 read_struct_type
PARAMS ((char **, struct type
*, struct objfile
*));
126 read_array_type
PARAMS ((char **, struct type
*, struct objfile
*));
128 static struct type
**
129 read_args
PARAMS ((char **, int, struct objfile
*));
132 read_cpp_abbrev
PARAMS ((struct field_info
*, char **, struct type
*,
135 static const char vptr_name
[] = { '_','v','p','t','r',CPLUS_MARKER
,'\0' };
136 static const char vb_name
[] = { '_','v','b',CPLUS_MARKER
,'\0' };
138 /* Define this as 1 if a pcc declaration of a char or short argument
139 gives the correct address. Otherwise assume pcc gives the
140 address of the corresponding int, which is not the same on a
141 big-endian machine. */
143 #ifndef BELIEVE_PCC_PROMOTION
144 #define BELIEVE_PCC_PROMOTION 0
148 /* I think this can go away, all current uses have been removed.
149 GCC emits a few crazy types which can only be distinguished by the
150 name (complex, long long on some machines), but I'd say fix GCC. */
152 /* During some calls to read_type (and thus to read_range_type), this
153 contains the name of the type being defined. Range types are only
154 used in C as basic types. We use the name to distinguish the otherwise
155 identical basic types "int" and "long" and their unsigned versions.
156 FIXME, this should disappear with better type management. */
158 static char *long_kludge_name
;
162 struct complaint dbx_class_complaint
=
164 "encountered DBX-style class variable debugging information.\n\
165 You seem to have compiled your program with \
166 \"g++ -g0\" instead of \"g++ -g\".\n\
167 Therefore GDB will not know about your class variables", 0, 0
171 struct complaint invalid_cpp_abbrev_complaint
=
172 {"invalid C++ abbreviation `%s'", 0, 0};
174 struct complaint invalid_cpp_type_complaint
=
175 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
177 struct complaint member_fn_complaint
=
178 {"member function type missing, got '%c'", 0, 0};
180 struct complaint const_vol_complaint
=
181 {"const/volatile indicator missing, got '%c'", 0, 0};
183 struct complaint error_type_complaint
=
184 {"debug info mismatch between compiler and debugger", 0, 0};
186 struct complaint invalid_member_complaint
=
187 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
189 struct complaint range_type_base_complaint
=
190 {"base type %d of range type is not defined", 0, 0};
192 struct complaint reg_value_complaint
=
193 {"register number too large in symbol %s", 0, 0};
195 struct complaint vtbl_notfound_complaint
=
196 {"virtual function table pointer not found when defining class `%s'", 0, 0};
198 struct complaint unrecognized_cplus_name_complaint
=
199 {"Unknown C++ symbol name `%s'", 0, 0};
201 struct complaint rs6000_builtin_complaint
=
202 {"Unknown builtin type %d", 0, 0};
204 struct complaint stabs_general_complaint
=
207 /* Make a list of forward references which haven't been defined. */
209 static struct type
**undef_types
;
210 static int undef_types_allocated
;
211 static int undef_types_length
;
213 /* Check for and handle cretinous stabs symbol name continuation! */
214 #define STABS_CONTINUE(pp) \
216 if (**(pp) == '\\') *(pp) = next_symbol_text (); \
220 /* Look up a dbx type-number pair. Return the address of the slot
221 where the type for that number-pair is stored.
222 The number-pair is in TYPENUMS.
224 This can be used for finding the type associated with that pair
225 or for associating a new type with the pair. */
228 dbx_lookup_type (typenums
)
231 register int filenum
= typenums
[0];
232 register int index
= typenums
[1];
234 register int real_filenum
;
235 register struct header_file
*f
;
238 if (filenum
== -1) /* -1,-1 is for temporary types. */
241 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
243 static struct complaint msg
= {"\
244 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
246 complain (&msg
, filenum
, index
, symnum
);
254 /* Caller wants address of address of type. We think
255 that negative (rs6k builtin) types will never appear as
256 "lvalues", (nor should they), so we stuff the real type
257 pointer into a temp, and return its address. If referenced,
258 this will do the right thing. */
259 static struct type
*temp_type
;
261 temp_type
= rs6000_builtin_type(index
);
265 /* Type is defined outside of header files.
266 Find it in this object file's type vector. */
267 if (index
>= type_vector_length
)
269 old_len
= type_vector_length
;
272 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
273 type_vector
= (struct type
**)
274 malloc (type_vector_length
* sizeof (struct type
*));
276 while (index
>= type_vector_length
)
278 type_vector_length
*= 2;
280 type_vector
= (struct type
**)
281 xrealloc ((char *) type_vector
,
282 (type_vector_length
* sizeof (struct type
*)));
283 memset (&type_vector
[old_len
], 0,
284 (type_vector_length
- old_len
) * sizeof (struct type
*));
286 return (&type_vector
[index
]);
290 real_filenum
= this_object_header_files
[filenum
];
292 if (real_filenum
>= n_header_files
)
294 struct type
*temp_type
;
295 struct type
**temp_type_p
;
297 warning ("GDB internal error: bad real_filenum");
300 temp_type
= init_type (TYPE_CODE_ERROR
, 0, 0, NULL
, NULL
);
301 temp_type_p
= (struct type
**) xmalloc (sizeof (struct type
*));
302 *temp_type_p
= temp_type
;
306 f
= &header_files
[real_filenum
];
308 f_orig_length
= f
->length
;
309 if (index
>= f_orig_length
)
311 while (index
>= f
->length
)
315 f
->vector
= (struct type
**)
316 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
317 memset (&f
->vector
[f_orig_length
], 0,
318 (f
->length
- f_orig_length
) * sizeof (struct type
*));
320 return (&f
->vector
[index
]);
324 /* Make sure there is a type allocated for type numbers TYPENUMS
325 and return the type object.
326 This can create an empty (zeroed) type object.
327 TYPENUMS may be (-1, -1) to return a new type object that is not
328 put into the type vector, and so may not be referred to by number. */
331 dbx_alloc_type (typenums
, objfile
)
333 struct objfile
*objfile
;
335 register struct type
**type_addr
;
337 if (typenums
[0] == -1)
339 return (alloc_type (objfile
));
342 type_addr
= dbx_lookup_type (typenums
);
344 /* If we are referring to a type not known at all yet,
345 allocate an empty type for it.
346 We will fill it in later if we find out how. */
349 *type_addr
= alloc_type (objfile
);
355 /* for all the stabs in a given stab vector, build appropriate types
356 and fix their symbols in given symbol vector. */
359 patch_block_stabs (symbols
, stabs
, objfile
)
360 struct pending
*symbols
;
361 struct pending_stabs
*stabs
;
362 struct objfile
*objfile
;
372 /* for all the stab entries, find their corresponding symbols and
373 patch their types! */
375 for (ii
= 0; ii
< stabs
->count
; ++ii
)
377 name
= stabs
->stab
[ii
];
378 pp
= (char*) strchr (name
, ':');
379 sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
382 /* On xcoff, if a global is defined and never referenced,
383 ld will remove it from the executable. There is then
384 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
385 sym
= (struct symbol
*)
386 obstack_alloc (&objfile
->symbol_obstack
,
387 sizeof (struct symbol
));
389 memset (sym
, 0, sizeof (struct symbol
));
390 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
391 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
393 obstack_copy0 (&objfile
->symbol_obstack
, name
, pp
- name
);
395 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
397 /* I don't think the linker does this with functions,
398 so as far as I know this is never executed.
399 But it doesn't hurt to check. */
401 lookup_function_type (read_type (&pp
, objfile
));
405 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
407 add_symbol_to_list (sym
, &global_symbols
);
412 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
415 lookup_function_type (read_type (&pp
, objfile
));
419 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
427 /* Read a number by which a type is referred to in dbx data,
428 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
429 Just a single number N is equivalent to (0,N).
430 Return the two numbers by storing them in the vector TYPENUMS.
431 TYPENUMS will then be used as an argument to dbx_lookup_type.
433 Returns 0 for success, -1 for error. */
436 read_type_number (pp
, typenums
)
438 register int *typenums
;
444 typenums
[0] = read_huge_number (pp
, ',', &nbits
);
445 if (nbits
!= 0) return -1;
446 typenums
[1] = read_huge_number (pp
, ')', &nbits
);
447 if (nbits
!= 0) return -1;
452 typenums
[1] = read_huge_number (pp
, 0, &nbits
);
453 if (nbits
!= 0) return -1;
459 /* To handle GNU C++ typename abbreviation, we need to be able to
460 fill in a type's name as soon as space for that type is allocated.
461 `type_synonym_name' is the name of the type being allocated.
462 It is cleared as soon as it is used (lest all allocated types
465 static char *type_synonym_name
;
469 define_symbol (valu
, string
, desc
, type
, objfile
)
474 struct objfile
*objfile
;
476 register struct symbol
*sym
;
477 char *p
= (char *) strchr (string
, ':');
482 /* We would like to eliminate nameless symbols, but keep their types.
483 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
484 to type 2, but, should not create a symbol to address that type. Since
485 the symbol will be nameless, there is no way any user can refer to it. */
489 /* Ignore syms with empty names. */
493 /* Ignore old-style symbols from cc -go */
497 /* If a nameless stab entry, all we need is the type, not the symbol.
498 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
499 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
501 sym
= (struct symbol
*)
502 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
503 memset (sym
, 0, sizeof (struct symbol
));
505 if (processing_gcc_compilation
)
507 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
508 number of bytes occupied by a type or object, which we ignore. */
509 SYMBOL_LINE(sym
) = desc
;
513 SYMBOL_LINE(sym
) = 0; /* unknown */
516 if (string
[0] == CPLUS_MARKER
)
518 /* Special GNU C++ names. */
522 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
523 &objfile
-> symbol_obstack
);
526 case 'v': /* $vtbl_ptr_type */
527 /* Was: SYMBOL_NAME (sym) = "vptr"; */
531 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
532 &objfile
-> symbol_obstack
);
536 /* This was an anonymous type that was never fixed up. */
540 complain (&unrecognized_cplus_name_complaint
, string
);
541 goto normal
; /* Do *something* with it */
547 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
548 SYMBOL_NAME (sym
) = (char *)
549 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
550 /* Open-coded memcpy--saves function call time. */
551 /* FIXME: Does it really? Try replacing with simple strcpy and
552 try it on an executable with a large symbol table. */
553 /* FIXME: considering that gcc can open code memcpy anyway, I
554 doubt it. xoxorich. */
556 register char *p1
= string
;
557 register char *p2
= SYMBOL_NAME (sym
);
565 /* If this symbol is from a C++ compilation, then attempt to cache the
566 demangled form for future reference. This is a typical time versus
567 space tradeoff, that was decided in favor of time because it sped up
568 C++ symbol lookups by a factor of about 20. */
570 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
574 /* Determine the type of name being defined. */
576 /* Getting GDB to correctly skip the symbol on an undefined symbol
577 descriptor and not ever dump core is a very dodgy proposition if
578 we do things this way. I say the acorn RISC machine can just
579 fix their compiler. */
580 /* The Acorn RISC machine's compiler can put out locals that don't
581 start with "234=" or "(3,4)=", so assume anything other than the
582 deftypes we know how to handle is a local. */
583 if (!strchr ("cfFGpPrStTvVXCR", *p
))
585 if (isdigit (*p
) || *p
== '(' || *p
== '-')
594 /* c is a special case, not followed by a type-number.
595 SYMBOL:c=iVALUE for an integer constant symbol.
596 SYMBOL:c=rVALUE for a floating constant symbol.
597 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
598 e.g. "b:c=e6,0" for "const b = blob1"
599 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
602 SYMBOL_CLASS (sym
) = LOC_CONST
;
603 SYMBOL_TYPE (sym
) = error_type (&p
);
604 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
605 add_symbol_to_list (sym
, &file_symbols
);
616 /* FIXME: lookup_fundamental_type is a hack. We should be
617 creating a type especially for the type of float constants.
618 Problem is, what type should it be? We currently have to
619 read this in host floating point format, but what type
620 represents a host format "double"?
622 Also, what should the name of this type be? Should we
623 be using 'S' constants (see stabs.texinfo) instead? */
625 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
628 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (double));
629 memcpy (dbl_valu
, &d
, sizeof (double));
630 /* Put it in target byte order, but it's still in host
631 floating point format. */
632 SWAP_TARGET_AND_HOST (dbl_valu
, sizeof (double));
633 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
634 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
639 /* Defining integer constants this way is kind of silly,
640 since 'e' constants allows the compiler to give not
641 only the value, but the type as well. C has at least
642 int, long, unsigned int, and long long as constant
643 types; other languages probably should have at least
644 unsigned as well as signed constants. */
646 /* We just need one int constant type for all objfiles.
647 It doesn't depend on languages or anything (arguably its
648 name should be a language-specific name for a type of
649 that size, but I'm inclined to say that if the compiler
650 wants a nice name for the type, it can use 'e'). */
651 static struct type
*int_const_type
;
653 /* Yes, this is as long as a *host* int. That is because we
655 if (int_const_type
== NULL
)
657 init_type (TYPE_CODE_INT
,
658 sizeof (int) * HOST_CHAR_BIT
/ TARGET_CHAR_BIT
, 0,
660 (struct objfile
*)NULL
);
661 SYMBOL_TYPE (sym
) = int_const_type
;
662 SYMBOL_VALUE (sym
) = atoi (p
);
663 SYMBOL_CLASS (sym
) = LOC_CONST
;
667 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
668 can be represented as integral.
669 e.g. "b:c=e6,0" for "const b = blob1"
670 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
672 SYMBOL_CLASS (sym
) = LOC_CONST
;
673 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
677 SYMBOL_TYPE (sym
) = error_type (&p
);
682 /* If the value is too big to fit in an int (perhaps because
683 it is unsigned), or something like that, we silently get
684 a bogus value. The type and everything else about it is
685 correct. Ideally, we should be using whatever we have
686 available for parsing unsigned and long long values,
688 SYMBOL_VALUE (sym
) = atoi (p
);
693 SYMBOL_CLASS (sym
) = LOC_CONST
;
694 SYMBOL_TYPE (sym
) = error_type (&p
);
697 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
698 add_symbol_to_list (sym
, &file_symbols
);
702 /* The name of a caught exception. */
703 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
704 SYMBOL_CLASS (sym
) = LOC_LABEL
;
705 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
706 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
707 add_symbol_to_list (sym
, &local_symbols
);
711 /* A static function definition. */
712 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
713 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
714 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
715 add_symbol_to_list (sym
, &file_symbols
);
716 /* fall into process_function_types. */
718 process_function_types
:
719 /* Function result types are described as the result type in stabs.
720 We need to convert this to the function-returning-type-X type
721 in GDB. E.g. "int" is converted to "function returning int". */
722 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
725 /* This code doesn't work -- it needs to realloc and can't. */
726 /* Attempt to set up to record a function prototype... */
727 struct type
*new = alloc_type (objfile
);
729 /* Generate a template for the type of this function. The
730 types of the arguments will be added as we read the symbol
732 *new = *lookup_function_type (SYMBOL_TYPE(sym
));
733 SYMBOL_TYPE(sym
) = new;
734 TYPE_OBJFILE (new) = objfile
;
735 in_function_type
= new;
737 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
740 /* fall into process_prototype_types */
742 process_prototype_types
:
743 /* Sun acc puts declared types of arguments here. We don't care
744 about their actual types (FIXME -- we should remember the whole
745 function prototype), but the list may define some new types
746 that we have to remember, so we must scan it now. */
749 read_type (&p
, objfile
);
754 /* A global function definition. */
755 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
756 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
757 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
758 add_symbol_to_list (sym
, &global_symbols
);
759 goto process_function_types
;
762 /* For a class G (global) symbol, it appears that the
763 value is not correct. It is necessary to search for the
764 corresponding linker definition to find the value.
765 These definitions appear at the end of the namelist. */
766 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
767 i
= hashname (SYMBOL_NAME (sym
));
768 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
769 global_sym_chain
[i
] = sym
;
770 SYMBOL_CLASS (sym
) = LOC_STATIC
;
771 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
772 add_symbol_to_list (sym
, &global_symbols
);
775 /* This case is faked by a conditional above,
776 when there is no code letter in the dbx data.
777 Dbx data never actually contains 'l'. */
779 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
780 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
781 SYMBOL_VALUE (sym
) = valu
;
782 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
783 add_symbol_to_list (sym
, &local_symbols
);
788 /* pF is a two-letter code that means a function parameter in Fortran.
789 The type-number specifies the type of the return value.
790 Translate it into a pointer-to-function type. */
794 = lookup_pointer_type
795 (lookup_function_type (read_type (&p
, objfile
)));
798 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
800 /* Normally this is a parameter, a LOC_ARG. On the i960, it
801 can also be a LOC_LOCAL_ARG depending on symbol type. */
802 #ifndef DBX_PARM_SYMBOL_CLASS
803 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
806 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
807 SYMBOL_VALUE (sym
) = valu
;
808 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
810 /* This doesn't work yet. */
811 add_param_to_type (&in_function_type
, sym
);
813 add_symbol_to_list (sym
, &local_symbols
);
815 /* If it's gcc-compiled, if it says `short', believe it. */
816 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
819 #if !BELIEVE_PCC_PROMOTION
821 /* This is the signed type which arguments get promoted to. */
822 static struct type
*pcc_promotion_type
;
823 /* This is the unsigned type which arguments get promoted to. */
824 static struct type
*pcc_unsigned_promotion_type
;
826 /* Call it "int" because this is mainly C lossage. */
827 if (pcc_promotion_type
== NULL
)
829 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
832 if (pcc_unsigned_promotion_type
== NULL
)
833 pcc_unsigned_promotion_type
=
834 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
835 TYPE_FLAG_UNSIGNED
, "unsigned int", NULL
);
837 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
838 /* This macro is defined on machines (e.g. sparc) where
839 we should believe the type of a PCC 'short' argument,
840 but shouldn't believe the address (the address is
841 the address of the corresponding int). Note that
842 this is only different from the BELIEVE_PCC_PROMOTION
843 case on big-endian machines.
845 My guess is that this correction, as opposed to changing
846 the parameter to an 'int' (as done below, for PCC
847 on most machines), is the right thing to do
848 on all machines, but I don't want to risk breaking
849 something that already works. On most PCC machines,
850 the sparc problem doesn't come up because the calling
851 function has to zero the top bytes (not knowing whether
852 the called function wants an int or a short), so there
853 is no practical difference between an int and a short
854 (except perhaps what happens when the GDB user types
855 "print short_arg = 0x10000;").
857 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
858 actually produces the correct address (we don't need to fix it
859 up). I made this code adapt so that it will offset the symbol
860 if it was pointing at an int-aligned location and not
861 otherwise. This way you can use the same gdb for 4.0.x and
864 If the parameter is shorter than an int, and is integral
865 (e.g. char, short, or unsigned equivalent), and is claimed to
866 be passed on an integer boundary, don't believe it! Offset the
867 parameter's address to the tail-end of that integer. */
869 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
870 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
871 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (pcc_promotion_type
))
873 SYMBOL_VALUE (sym
) += TYPE_LENGTH (pcc_promotion_type
)
874 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
878 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
880 /* If PCC says a parameter is a short or a char,
881 it is really an int. */
882 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
883 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
886 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
887 ? pcc_unsigned_promotion_type
888 : pcc_promotion_type
;
892 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
894 #endif /* !BELIEVE_PCC_PROMOTION. */
897 /* acc seems to use P to delare the prototypes of functions that
898 are referenced by this file. gdb is not prepared to deal
899 with this extra information. FIXME, it ought to. */
902 read_type (&p
, objfile
);
903 goto process_prototype_types
;
908 /* Parameter which is in a register. */
909 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
910 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
911 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
912 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
914 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
915 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
917 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
918 add_symbol_to_list (sym
, &local_symbols
);
922 /* Register variable (either global or local). */
923 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
924 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
925 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
926 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
928 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
929 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
931 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
934 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
935 name to represent an argument passed in a register.
936 GCC uses 'P' for the same case. So if we find such a symbol pair
937 we combine it into one 'P' symbol.
938 Note that this code illegally combines
939 main(argc) int argc; { register int argc = 1; }
940 but this case is considered pathological and causes a warning
941 from a decent compiler. */
943 && local_symbols
->nsyms
> 0)
945 struct symbol
*prev_sym
;
946 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
947 if (SYMBOL_CLASS (prev_sym
) == LOC_ARG
948 && STREQ (SYMBOL_NAME (prev_sym
), SYMBOL_NAME(sym
)))
950 SYMBOL_CLASS (prev_sym
) = LOC_REGPARM
;
951 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
956 add_symbol_to_list (sym
, &local_symbols
);
959 add_symbol_to_list (sym
, &file_symbols
);
963 /* Static symbol at top level of file */
964 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
965 SYMBOL_CLASS (sym
) = LOC_STATIC
;
966 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
967 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
968 add_symbol_to_list (sym
, &file_symbols
);
973 /* See comment where long_kludge_name is declared. */
974 /* Here we save the name of the symbol for read_range_type, which
975 ends up reading in the basic types. In stabs, unfortunately there
976 is no distinction between "int" and "long" types except their
977 names. Until we work out a saner type policy (eliminating most
978 builtin types and using the names specified in the files), we
979 save away the name so that far away from here in read_range_type,
980 we can examine it to decide between "int" and "long". FIXME. */
981 long_kludge_name
= SYMBOL_NAME (sym
);
983 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
985 /* For a nameless type, we don't want a create a symbol, thus we
986 did not use `sym'. Return without further processing. */
987 if (nameless
) return NULL
;
989 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
990 SYMBOL_VALUE (sym
) = valu
;
991 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
992 /* C++ vagaries: we may have a type which is derived from
993 a base type which did not have its name defined when the
994 derived class was output. We fill in the derived class's
995 base part member's name here in that case. */
996 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
997 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
998 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
999 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1002 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1003 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1004 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1005 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1008 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1010 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
1011 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FUNC
)
1013 /* If we are giving a name to a type such as "pointer to
1014 foo" or "function returning foo", we better not set
1015 the TYPE_NAME. If the program contains "typedef char
1016 *caddr_t;", we don't want all variables of type char
1017 * to print as caddr_t. This is not just a
1018 consequence of GDB's type management; PCC and GCC (at
1019 least through version 2.4) both output variables of
1020 either type char * or caddr_t with the type number
1021 defined in the 't' symbol for caddr_t. If a future
1022 compiler cleans this up it GDB is not ready for it
1023 yet, but if it becomes ready we somehow need to
1024 disable this check (without breaking the PCC/GCC2.4
1029 Fortunately, this check seems not to be necessary
1030 for anything except pointers or functions. */
1033 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
1036 add_symbol_to_list (sym
, &file_symbols
);
1040 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1041 by 't' which means we are typedef'ing it as well. */
1042 synonym
= *p
== 't';
1047 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1048 strlen (SYMBOL_NAME (sym
)),
1049 &objfile
-> symbol_obstack
);
1052 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1054 /* For a nameless type, we don't want a create a symbol, thus we
1055 did not use `sym'. Return without further processing. */
1056 if (nameless
) return NULL
;
1058 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1059 SYMBOL_VALUE (sym
) = valu
;
1060 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1061 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym
)) == 0)
1062 TYPE_TAG_NAME (SYMBOL_TYPE (sym
))
1063 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1064 add_symbol_to_list (sym
, &file_symbols
);
1068 /* Clone the sym and then modify it. */
1069 register struct symbol
*typedef_sym
= (struct symbol
*)
1070 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1071 *typedef_sym
= *sym
;
1072 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1073 SYMBOL_VALUE (typedef_sym
) = valu
;
1074 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1075 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1076 TYPE_NAME (SYMBOL_TYPE (sym
))
1077 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1078 add_symbol_to_list (typedef_sym
, &file_symbols
);
1083 /* Static symbol of local scope */
1084 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1085 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1086 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1087 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1088 add_symbol_to_list (sym
, &local_symbols
);
1092 /* Reference parameter */
1093 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1094 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1095 SYMBOL_VALUE (sym
) = valu
;
1096 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1097 add_symbol_to_list (sym
, &local_symbols
);
1101 /* This is used by Sun FORTRAN for "function result value".
1102 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1103 that Pascal uses it too, but when I tried it Pascal used
1104 "x:3" (local symbol) instead. */
1105 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1106 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1107 SYMBOL_VALUE (sym
) = valu
;
1108 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1109 add_symbol_to_list (sym
, &local_symbols
);
1113 SYMBOL_TYPE (sym
) = error_type (&p
);
1114 SYMBOL_CLASS (sym
) = LOC_CONST
;
1115 SYMBOL_VALUE (sym
) = 0;
1116 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1117 add_symbol_to_list (sym
, &file_symbols
);
1121 /* When passing structures to a function, some systems sometimes pass
1122 the address in a register, not the structure itself.
1124 If REG_STRUCT_HAS_ADDR yields non-zero we have to convert LOC_REGPARM
1125 to LOC_REGPARM_ADDR for structures and unions. */
1127 #if !defined (REG_STRUCT_HAS_ADDR)
1128 #define REG_STRUCT_HAS_ADDR(gcc_p) 0
1131 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
1132 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
)
1133 && ( (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
1134 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)))
1135 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1141 /* Skip rest of this symbol and return an error type.
1143 General notes on error recovery: error_type always skips to the
1144 end of the symbol (modulo cretinous dbx symbol name continuation).
1145 Thus code like this:
1147 if (*(*pp)++ != ';')
1148 return error_type (pp);
1150 is wrong because if *pp starts out pointing at '\0' (typically as the
1151 result of an earlier error), it will be incremented to point to the
1152 start of the next symbol, which might produce strange results, at least
1153 if you run off the end of the string table. Instead use
1156 return error_type (pp);
1162 foo = error_type (pp);
1166 And in case it isn't obvious, the point of all this hair is so the compiler
1167 can define new types and new syntaxes, and old versions of the
1168 debugger will be able to read the new symbol tables. */
1170 static struct type
*
1174 complain (&error_type_complaint
);
1177 /* Skip to end of symbol. */
1178 while (**pp
!= '\0')
1183 /* Check for and handle cretinous dbx symbol name continuation! */
1184 if ((*pp
)[-1] == '\\')
1186 *pp
= next_symbol_text ();
1193 return (builtin_type_error
);
1197 /* Read type information or a type definition; return the type. Even
1198 though this routine accepts either type information or a type
1199 definition, the distinction is relevant--some parts of stabsread.c
1200 assume that type information starts with a digit, '-', or '(' in
1201 deciding whether to call read_type. */
1204 read_type (pp
, objfile
)
1206 struct objfile
*objfile
;
1208 register struct type
*type
= 0;
1212 char type_descriptor
;
1214 /* Read type number if present. The type number may be omitted.
1215 for instance in a two-dimensional array declared with type
1216 "ar1;1;10;ar1;1;10;4". */
1217 if ((**pp
>= '0' && **pp
<= '9')
1220 if (read_type_number (pp
, typenums
) != 0)
1221 return error_type (pp
);
1223 /* Type is not being defined here. Either it already exists,
1224 or this is a forward reference to it. dbx_alloc_type handles
1227 return dbx_alloc_type (typenums
, objfile
);
1229 /* Type is being defined here. */
1236 /* It might be a type attribute or a member type. */
1237 if (isdigit (*p
) || *p
== '(' || *p
== '-')
1242 /* Type attributes; skip to the semicolon. */
1243 while (*p
!= ';' && *p
!= '\0')
1247 return error_type (pp
);
1249 /* Skip the semicolon. */
1253 /* Skip the type descriptor, we get it below with (*pp)[-1]. */
1258 /* 'typenums=' not present, type is anonymous. Read and return
1259 the definition, but don't put it in the type vector. */
1260 typenums
[0] = typenums
[1] = -1;
1264 type_descriptor
= (*pp
)[-1];
1265 switch (type_descriptor
)
1269 enum type_code code
;
1271 /* Used to index through file_symbols. */
1272 struct pending
*ppt
;
1275 /* Name including "struct", etc. */
1278 /* Name without "struct", etc. */
1279 char *type_name_only
;
1285 /* Set the type code according to the following letter. */
1289 code
= TYPE_CODE_STRUCT
;
1292 code
= TYPE_CODE_UNION
;
1295 code
= TYPE_CODE_ENUM
;
1298 return error_type (pp
);
1301 to
= type_name
= (char *)
1302 obstack_alloc (&objfile
-> type_obstack
,
1303 (((char *) strchr (*pp
, ':') - (*pp
)) + 1));
1305 /* Copy the name. */
1307 while ((*to
++ = *from
++) != ':')
1311 /* Set the pointer ahead of the name which we just read. */
1315 /* Now check to see whether the type has already been declared. */
1316 /* This is necessary at least in the case where the
1317 program says something like
1319 The compiler puts out a cross-reference; we better find
1320 set the length of the structure correctly so we can
1321 set the length of the array. */
1322 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1323 for (i
= 0; i
< ppt
->nsyms
; i
++)
1325 struct symbol
*sym
= ppt
->symbol
[i
];
1327 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1328 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1329 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1330 && STREQ (SYMBOL_NAME (sym
), type_name
))
1332 obstack_free (&objfile
-> type_obstack
, type_name
);
1333 type
= SYMBOL_TYPE (sym
);
1338 /* Didn't find the type to which this refers, so we must
1339 be dealing with a forward reference. Allocate a type
1340 structure for it, and keep track of it so we can
1341 fill in the rest of the fields when we get the full
1343 type
= dbx_alloc_type (typenums
, objfile
);
1344 TYPE_CODE (type
) = code
;
1345 TYPE_TAG_NAME (type
) = type_name
;
1346 INIT_CPLUS_SPECIFIC(type
);
1347 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1349 add_undefined_type (type
);
1353 case '-': /* RS/6000 built-in type */
1366 /* The type is being defined to another type. When we support
1367 Ada (and arguably for C, so "whatis foo" can give "size_t",
1368 "wchar_t", or whatever it was declared as) we'll need to
1369 allocate a distinct type here rather than returning the
1370 existing one. GCC is currently (deliberately) incapable of
1371 putting out the debugging information to do that, however. */
1374 if (read_type_number (pp
, xtypenums
) != 0)
1375 return error_type (pp
);
1376 if (typenums
[0] == xtypenums
[0] && typenums
[1] == xtypenums
[1])
1377 /* It's being defined as itself. That means it is "void". */
1378 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, objfile
);
1380 type
= *dbx_lookup_type (xtypenums
);
1381 if (typenums
[0] != -1)
1382 *dbx_lookup_type (typenums
) = type
;
1383 /* This can happen if we had '-' followed by a garbage character,
1386 return error_type (pp
);
1389 /* In the following types, we must be sure to overwrite any existing
1390 type that the typenums refer to, rather than allocating a new one
1391 and making the typenums point to the new one. This is because there
1392 may already be pointers to the existing type (if it had been
1393 forward-referenced), and we must change it to a pointer, function,
1394 reference, or whatever, *in-place*. */
1397 type1
= read_type (pp
, objfile
);
1398 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1401 case '&': /* Reference to another type */
1402 type1
= read_type (pp
, objfile
);
1403 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1406 case 'f': /* Function returning another type */
1407 type1
= read_type (pp
, objfile
);
1408 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1411 case 'k': /* Const qualifier on some type (Sun) */
1412 type
= read_type (pp
, objfile
);
1413 /* FIXME! For now, we ignore const and volatile qualifiers. */
1416 case 'B': /* Volatile qual on some type (Sun) */
1417 type
= read_type (pp
, objfile
);
1418 /* FIXME! For now, we ignore const and volatile qualifiers. */
1421 /* FIXME -- we should be doing smash_to_XXX types here. */
1422 case '@': /* Member (class & variable) type */
1424 struct type
*domain
= read_type (pp
, objfile
);
1425 struct type
*memtype
;
1428 /* Invalid member type data format. */
1429 return error_type (pp
);
1432 memtype
= read_type (pp
, objfile
);
1433 type
= dbx_alloc_type (typenums
, objfile
);
1434 smash_to_member_type (type
, domain
, memtype
);
1438 case '#': /* Method (class & fn) type */
1439 if ((*pp
)[0] == '#')
1441 /* We'll get the parameter types from the name. */
1442 struct type
*return_type
;
1445 return_type
= read_type (pp
, objfile
);
1446 if (*(*pp
)++ != ';')
1447 complain (&invalid_member_complaint
, symnum
);
1448 type
= allocate_stub_method (return_type
);
1449 if (typenums
[0] != -1)
1450 *dbx_lookup_type (typenums
) = type
;
1454 struct type
*domain
= read_type (pp
, objfile
);
1455 struct type
*return_type
;
1459 /* Invalid member type data format. */
1460 return error_type (pp
);
1464 return_type
= read_type (pp
, objfile
);
1465 args
= read_args (pp
, ';', objfile
);
1466 type
= dbx_alloc_type (typenums
, objfile
);
1467 smash_to_method_type (type
, domain
, return_type
, args
);
1471 case 'r': /* Range type */
1472 type
= read_range_type (pp
, typenums
, objfile
);
1473 if (typenums
[0] != -1)
1474 *dbx_lookup_type (typenums
) = type
;
1477 case 'b': /* Sun ACC builtin int type */
1478 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
1479 if (typenums
[0] != -1)
1480 *dbx_lookup_type (typenums
) = type
;
1483 case 'R': /* Sun ACC builtin float type */
1484 type
= read_sun_floating_type (pp
, typenums
, objfile
);
1485 if (typenums
[0] != -1)
1486 *dbx_lookup_type (typenums
) = type
;
1489 case 'e': /* Enumeration type */
1490 type
= dbx_alloc_type (typenums
, objfile
);
1491 type
= read_enum_type (pp
, type
, objfile
);
1492 if (typenums
[0] != -1)
1493 *dbx_lookup_type (typenums
) = type
;
1496 case 's': /* Struct type */
1497 case 'u': /* Union type */
1498 type
= dbx_alloc_type (typenums
, objfile
);
1499 if (!TYPE_NAME (type
))
1501 TYPE_NAME (type
) = type_synonym_name
;
1503 type_synonym_name
= NULL
;
1504 switch (type_descriptor
)
1507 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1510 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1513 type
= read_struct_type (pp
, type
, objfile
);
1516 case 'a': /* Array type */
1518 return error_type (pp
);
1521 type
= dbx_alloc_type (typenums
, objfile
);
1522 type
= read_array_type (pp
, type
, objfile
);
1526 --*pp
; /* Go back to the symbol in error */
1527 /* Particularly important if it was \0! */
1528 return error_type (pp
);
1533 warning ("GDB internal error, type is NULL in stabsread.c\n");
1534 return error_type (pp
);
1540 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
1541 Return the proper type node for a given builtin type number. */
1543 static struct type
*
1544 rs6000_builtin_type (typenum
)
1547 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
1548 #define NUMBER_RECOGNIZED 30
1549 /* This includes an empty slot for type number -0. */
1550 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
1551 struct type
*rettype
;
1553 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
1555 complain (&rs6000_builtin_complaint
, typenum
);
1556 return builtin_type_error
;
1558 if (negative_types
[-typenum
] != NULL
)
1559 return negative_types
[-typenum
];
1561 #if TARGET_CHAR_BIT != 8
1562 #error This code wrong for TARGET_CHAR_BIT not 8
1563 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
1564 that if that ever becomes not true, the correct fix will be to
1565 make the size in the struct type to be in bits, not in units of
1572 /* The size of this and all the other types are fixed, defined
1573 by the debugging format. If there is a type called "int" which
1574 is other than 32 bits, then it should use a new negative type
1575 number (or avoid negative type numbers for that case).
1576 See stabs.texinfo. */
1577 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
1580 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
1583 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
1586 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
1589 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
1590 "unsigned char", NULL
);
1593 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
1596 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
1597 "unsigned short", NULL
);
1600 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1601 "unsigned int", NULL
);
1604 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1607 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1608 "unsigned long", NULL
);
1611 rettype
= init_type (TYPE_CODE_VOID
, 0, 0, "void", NULL
);
1614 /* IEEE single precision (32 bit). */
1615 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
1618 /* IEEE double precision (64 bit). */
1619 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
1622 /* This is an IEEE double on the RS/6000, and different machines with
1623 different sizes for "long double" should use different negative
1624 type numbers. See stabs.texinfo. */
1625 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
1628 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
1631 rettype
= init_type (TYPE_CODE_BOOL
, 4, 0, "boolean", NULL
);
1634 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
1637 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
1640 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
1643 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
1647 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
1651 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
1655 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
1659 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
1663 /* Complex type consisting of two IEEE single precision values. */
1664 rettype
= init_type (TYPE_CODE_ERROR
, 8, 0, "complex", NULL
);
1667 /* Complex type consisting of two IEEE double precision values. */
1668 rettype
= init_type (TYPE_CODE_ERROR
, 16, 0, "double complex", NULL
);
1671 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
1674 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
1677 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
1680 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
1683 negative_types
[-typenum
] = rettype
;
1687 /* This page contains subroutines of read_type. */
1689 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1690 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1691 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1693 /* Read member function stabs info for C++ classes. The form of each member
1696 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1698 An example with two member functions is:
1700 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1702 For the case of overloaded operators, the format is op$::*.funcs, where
1703 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1704 name (such as `+=') and `.' marks the end of the operator name.
1706 Returns 1 for success, 0 for failure. */
1709 read_member_functions (fip
, pp
, type
, objfile
)
1710 struct field_info
*fip
;
1713 struct objfile
*objfile
;
1717 /* Total number of member functions defined in this class. If the class
1718 defines two `f' functions, and one `g' function, then this will have
1720 int total_length
= 0;
1724 struct next_fnfield
*next
;
1725 struct fn_field fn_field
;
1727 struct type
*look_ahead_type
;
1728 struct next_fnfieldlist
*new_fnlist
;
1729 struct next_fnfield
*new_sublist
;
1733 /* Process each list until we find something that is not a member function
1734 or find the end of the functions. */
1738 /* We should be positioned at the start of the function name.
1739 Scan forward to find the first ':' and if it is not the
1740 first of a "::" delimiter, then this is not a member function. */
1752 look_ahead_type
= NULL
;
1755 new_fnlist
= (struct next_fnfieldlist
*)
1756 xmalloc (sizeof (struct next_fnfieldlist
));
1757 make_cleanup (free
, new_fnlist
);
1758 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
1760 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
1762 /* This is a completely wierd case. In order to stuff in the
1763 names that might contain colons (the usual name delimiter),
1764 Mike Tiemann defined a different name format which is
1765 signalled if the identifier is "op$". In that case, the
1766 format is "op$::XXXX." where XXXX is the name. This is
1767 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1768 /* This lets the user type "break operator+".
1769 We could just put in "+" as the name, but that wouldn't
1771 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
1772 char *o
= opname
+ 3;
1774 /* Skip past '::'. */
1777 STABS_CONTINUE (pp
);
1783 main_fn_name
= savestring (opname
, o
- opname
);
1789 main_fn_name
= savestring (*pp
, p
- *pp
);
1790 /* Skip past '::'. */
1793 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
1798 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
1799 make_cleanup (free
, new_sublist
);
1800 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
1802 /* Check for and handle cretinous dbx symbol name continuation! */
1803 if (look_ahead_type
== NULL
)
1806 STABS_CONTINUE (pp
);
1808 new_sublist
-> fn_field
.type
= read_type (pp
, objfile
);
1811 /* Invalid symtab info for member function. */
1817 /* g++ version 1 kludge */
1818 new_sublist
-> fn_field
.type
= look_ahead_type
;
1819 look_ahead_type
= NULL
;
1829 /* If this is just a stub, then we don't have the real name here. */
1831 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
1833 if (!TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
))
1834 TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
) = type
;
1835 new_sublist
-> fn_field
.is_stub
= 1;
1837 new_sublist
-> fn_field
.physname
= savestring (*pp
, p
- *pp
);
1840 /* Set this member function's visibility fields. */
1843 case VISIBILITY_PRIVATE
:
1844 new_sublist
-> fn_field
.is_private
= 1;
1846 case VISIBILITY_PROTECTED
:
1847 new_sublist
-> fn_field
.is_protected
= 1;
1851 STABS_CONTINUE (pp
);
1854 case 'A': /* Normal functions. */
1855 new_sublist
-> fn_field
.is_const
= 0;
1856 new_sublist
-> fn_field
.is_volatile
= 0;
1859 case 'B': /* `const' member functions. */
1860 new_sublist
-> fn_field
.is_const
= 1;
1861 new_sublist
-> fn_field
.is_volatile
= 0;
1864 case 'C': /* `volatile' member function. */
1865 new_sublist
-> fn_field
.is_const
= 0;
1866 new_sublist
-> fn_field
.is_volatile
= 1;
1869 case 'D': /* `const volatile' member function. */
1870 new_sublist
-> fn_field
.is_const
= 1;
1871 new_sublist
-> fn_field
.is_volatile
= 1;
1874 case '*': /* File compiled with g++ version 1 -- no info */
1879 complain (&const_vol_complaint
, **pp
);
1888 /* virtual member function, followed by index.
1889 The sign bit is set to distinguish pointers-to-methods
1890 from virtual function indicies. Since the array is
1891 in words, the quantity must be shifted left by 1
1892 on 16 bit machine, and by 2 on 32 bit machine, forcing
1893 the sign bit out, and usable as a valid index into
1894 the array. Remove the sign bit here. */
1895 new_sublist
-> fn_field
.voffset
=
1896 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
1900 STABS_CONTINUE (pp
);
1901 if (**pp
== ';' || **pp
== '\0')
1903 /* Must be g++ version 1. */
1904 new_sublist
-> fn_field
.fcontext
= 0;
1908 /* Figure out from whence this virtual function came.
1909 It may belong to virtual function table of
1910 one of its baseclasses. */
1911 look_ahead_type
= read_type (pp
, objfile
);
1914 /* g++ version 1 overloaded methods. */
1918 new_sublist
-> fn_field
.fcontext
= look_ahead_type
;
1927 look_ahead_type
= NULL
;
1933 /* static member function. */
1934 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
1935 if (strncmp (new_sublist
-> fn_field
.physname
,
1936 main_fn_name
, strlen (main_fn_name
)))
1938 new_sublist
-> fn_field
.is_stub
= 1;
1944 complain (&member_fn_complaint
, (*pp
)[-1]);
1945 /* Fall through into normal member function. */
1948 /* normal member function. */
1949 new_sublist
-> fn_field
.voffset
= 0;
1950 new_sublist
-> fn_field
.fcontext
= 0;
1954 new_sublist
-> next
= sublist
;
1955 sublist
= new_sublist
;
1957 STABS_CONTINUE (pp
);
1959 while (**pp
!= ';' && **pp
!= '\0');
1963 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
1964 obstack_alloc (&objfile
-> type_obstack
,
1965 sizeof (struct fn_field
) * length
);
1966 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
1967 sizeof (struct fn_field
) * length
);
1968 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
1970 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
1973 new_fnlist
-> fn_fieldlist
.length
= length
;
1974 new_fnlist
-> next
= fip
-> fnlist
;
1975 fip
-> fnlist
= new_fnlist
;
1977 total_length
+= length
;
1978 STABS_CONTINUE (pp
);
1983 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1984 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
1985 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
1986 memset (TYPE_FN_FIELDLISTS (type
), 0,
1987 sizeof (struct fn_fieldlist
) * nfn_fields
);
1988 TYPE_NFN_FIELDS (type
) = nfn_fields
;
1989 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
1995 /* Special GNU C++ name.
1997 Returns 1 for success, 0 for failure. "failure" means that we can't
1998 keep parsing and it's time for error_type(). */
2001 read_cpp_abbrev (fip
, pp
, type
, objfile
)
2002 struct field_info
*fip
;
2005 struct objfile
*objfile
;
2011 struct type
*context
;
2021 /* At this point, *pp points to something like "22:23=*22...",
2022 where the type number before the ':' is the "context" and
2023 everything after is a regular type definition. Lookup the
2024 type, find it's name, and construct the field name. */
2026 context
= read_type (pp
, objfile
);
2030 case 'f': /* $vf -- a virtual function table pointer */
2031 fip
->list
->field
.name
=
2032 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
2035 case 'b': /* $vb -- a virtual bsomethingorother */
2036 name
= type_name_no_tag (context
);
2039 complain (&invalid_cpp_type_complaint
, symnum
);
2042 fip
->list
->field
.name
=
2043 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
2047 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2048 fip
->list
->field
.name
=
2049 obconcat (&objfile
->type_obstack
,
2050 "INVALID_CPLUSPLUS_ABBREV", "", "");
2054 /* At this point, *pp points to the ':'. Skip it and read the
2060 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2063 fip
->list
->field
.type
= read_type (pp
, objfile
);
2065 (*pp
)++; /* Skip the comma. */
2071 fip
->list
->field
.bitpos
= read_huge_number (pp
, ';', &nbits
);
2075 /* This field is unpacked. */
2076 fip
->list
->field
.bitsize
= 0;
2077 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
2081 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2082 /* We have no idea what syntax an unrecognized abbrev would have, so
2083 better return 0. If we returned 1, we would need to at least advance
2084 *pp to avoid an infinite loop. */
2091 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
2092 struct field_info
*fip
;
2096 struct objfile
*objfile
;
2098 fip
-> list
-> field
.name
=
2099 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2102 /* This means we have a visibility for a field coming. */
2106 fip
-> list
-> visibility
= *(*pp
)++;
2107 switch (fip
-> list
-> visibility
)
2109 case VISIBILITY_PRIVATE
:
2110 case VISIBILITY_PROTECTED
:
2113 case VISIBILITY_PUBLIC
:
2118 /* Unknown visibility specifier. */
2119 complain (&stabs_general_complaint
,
2120 "unknown visibility specifier");
2127 /* normal dbx-style format, no explicit visibility */
2128 fip
-> list
-> visibility
= VISIBILITY_PUBLIC
;
2131 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
2136 /* Possible future hook for nested types. */
2139 fip
-> list
-> field
.bitpos
= (long)-2; /* nested type */
2145 /* Static class member. */
2146 fip
-> list
-> field
.bitpos
= (long) -1;
2152 fip
-> list
-> field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2156 else if (**pp
!= ',')
2158 /* Bad structure-type format. */
2159 complain (&stabs_general_complaint
, "bad structure-type format");
2163 (*pp
)++; /* Skip the comma. */
2167 fip
-> list
-> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2170 complain (&stabs_general_complaint
, "bad structure-type format");
2173 fip
-> list
-> field
.bitsize
= read_huge_number (pp
, ';', &nbits
);
2176 complain (&stabs_general_complaint
, "bad structure-type format");
2181 /* FIXME-tiemann: Can't the compiler put out something which
2182 lets us distinguish these? (or maybe just not put out anything
2183 for the field). What is the story here? What does the compiler
2184 really do? Also, patch gdb.texinfo for this case; I document
2185 it as a possible problem there. Search for "DBX-style". */
2187 /* This is wrong because this is identical to the symbols
2188 produced for GCC 0-size arrays. For example:
2193 The code which dumped core in such circumstances should be
2194 fixed not to dump core. */
2196 /* g++ -g0 can put out bitpos & bitsize zero for a static
2197 field. This does not give us any way of getting its
2198 class, so we can't know its name. But we can just
2199 ignore the field so we don't dump core and other nasty
2201 if (fip
-> list
-> field
.bitpos
== 0 && fip
-> list
-> field
.bitsize
== 0)
2203 complain (&dbx_class_complaint
);
2204 /* Ignore this field. */
2205 fip
-> list
= fip
-> list
-> next
;
2210 /* Detect an unpacked field and mark it as such.
2211 dbx gives a bit size for all fields.
2212 Note that forward refs cannot be packed,
2213 and treat enums as if they had the width of ints. */
2215 if (TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_INT
2216 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_ENUM
)
2218 fip
-> list
-> field
.bitsize
= 0;
2220 if ((fip
-> list
-> field
.bitsize
2221 == TARGET_CHAR_BIT
* TYPE_LENGTH (fip
-> list
-> field
.type
)
2222 || (TYPE_CODE (fip
-> list
-> field
.type
) == TYPE_CODE_ENUM
2223 && (fip
-> list
-> field
.bitsize
2228 fip
-> list
-> field
.bitpos
% 8 == 0)
2230 fip
-> list
-> field
.bitsize
= 0;
2236 /* Read struct or class data fields. They have the form:
2238 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2240 At the end, we see a semicolon instead of a field.
2242 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2245 The optional VISIBILITY is one of:
2247 '/0' (VISIBILITY_PRIVATE)
2248 '/1' (VISIBILITY_PROTECTED)
2249 '/2' (VISIBILITY_PUBLIC)
2251 or nothing, for C style fields with public visibility.
2253 Returns 1 for success, 0 for failure. */
2256 read_struct_fields (fip
, pp
, type
, objfile
)
2257 struct field_info
*fip
;
2260 struct objfile
*objfile
;
2263 struct nextfield
*new;
2265 /* We better set p right now, in case there are no fields at all... */
2269 /* Read each data member type until we find the terminating ';' at the end of
2270 the data member list, or break for some other reason such as finding the
2271 start of the member function list. */
2275 STABS_CONTINUE (pp
);
2276 /* Get space to record the next field's data. */
2277 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2278 make_cleanup (free
, new);
2279 memset (new, 0, sizeof (struct nextfield
));
2280 new -> next
= fip
-> list
;
2283 /* Get the field name. */
2285 /* If is starts with CPLUS_MARKER it is a special abbreviation, unless
2286 the CPLUS_MARKER is followed by an underscore, in which case it is
2287 just the name of an anonymous type, which we should handle like any
2289 if (*p
== CPLUS_MARKER
&& p
[1] != '_')
2291 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
2296 /* Look for the ':' that separates the field name from the field
2297 values. Data members are delimited by a single ':', while member
2298 functions are delimited by a pair of ':'s. When we hit the member
2299 functions (if any), terminate scan loop and return. */
2301 while (*p
!= ':' && *p
!= '\0')
2308 /* Check to see if we have hit the member functions yet. */
2313 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
2317 /* chill the list of fields: the last entry (at the head) is a
2318 partially constructed entry which we now scrub. */
2319 fip
-> list
= fip
-> list
-> next
;
2324 /* The stabs for C++ derived classes contain baseclass information which
2325 is marked by a '!' character after the total size. This function is
2326 called when we encounter the baseclass marker, and slurps up all the
2327 baseclass information.
2329 Immediately following the '!' marker is the number of base classes that
2330 the class is derived from, followed by information for each base class.
2331 For each base class, there are two visibility specifiers, a bit offset
2332 to the base class information within the derived class, a reference to
2333 the type for the base class, and a terminating semicolon.
2335 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2337 Baseclass information marker __________________|| | | | | | |
2338 Number of baseclasses __________________________| | | | | | |
2339 Visibility specifiers (2) ________________________| | | | | |
2340 Offset in bits from start of class _________________| | | | |
2341 Type number for base class ___________________________| | | |
2342 Visibility specifiers (2) _______________________________| | |
2343 Offset in bits from start of class ________________________| |
2344 Type number of base class ____________________________________|
2346 Return 1 for success, 0 for (error-type-inducing) failure. */
2349 read_baseclasses (fip
, pp
, type
, objfile
)
2350 struct field_info
*fip
;
2353 struct objfile
*objfile
;
2356 struct nextfield
*new;
2364 /* Skip the '!' baseclass information marker. */
2368 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2371 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
2377 /* Some stupid compilers have trouble with the following, so break
2378 it up into simpler expressions. */
2379 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
2380 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
2383 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
2386 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2387 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2391 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
2393 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
2395 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2396 make_cleanup (free
, new);
2397 memset (new, 0, sizeof (struct nextfield
));
2398 new -> next
= fip
-> list
;
2400 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
2402 STABS_CONTINUE (pp
);
2406 /* Nothing to do. */
2409 SET_TYPE_FIELD_VIRTUAL (type
, i
);
2412 /* Bad visibility format. */
2416 new -> visibility
= *(*pp
)++;
2417 switch (new -> visibility
)
2419 case VISIBILITY_PRIVATE
:
2420 case VISIBILITY_PROTECTED
:
2421 case VISIBILITY_PUBLIC
:
2424 /* Bad visibility format. */
2431 /* The remaining value is the bit offset of the portion of the object
2432 corresponding to this baseclass. Always zero in the absence of
2433 multiple inheritance. */
2435 new -> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2440 /* The last piece of baseclass information is the type of the
2441 base class. Read it, and remember it's type name as this
2444 new -> field
.type
= read_type (pp
, objfile
);
2445 new -> field
.name
= type_name_no_tag (new -> field
.type
);
2447 /* skip trailing ';' and bump count of number of fields seen */
2456 /* The tail end of stabs for C++ classes that contain a virtual function
2457 pointer contains a tilde, a %, and a type number.
2458 The type number refers to the base class (possibly this class itself) which
2459 contains the vtable pointer for the current class.
2461 This function is called when we have parsed all the method declarations,
2462 so we can look for the vptr base class info. */
2465 read_tilde_fields (fip
, pp
, type
, objfile
)
2466 struct field_info
*fip
;
2469 struct objfile
*objfile
;
2473 STABS_CONTINUE (pp
);
2475 /* If we are positioned at a ';', then skip it. */
2485 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2487 /* Obsolete flags that used to indicate the presence
2488 of constructors and/or destructors. */
2492 /* Read either a '%' or the final ';'. */
2493 if (*(*pp
)++ == '%')
2495 /* The next number is the type number of the base class
2496 (possibly our own class) which supplies the vtable for
2497 this class. Parse it out, and search that class to find
2498 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
2499 and TYPE_VPTR_FIELDNO. */
2504 t
= read_type (pp
, objfile
);
2506 while (*p
!= '\0' && *p
!= ';')
2512 /* Premature end of symbol. */
2516 TYPE_VPTR_BASETYPE (type
) = t
;
2517 if (type
== t
) /* Our own class provides vtbl ptr */
2519 for (i
= TYPE_NFIELDS (t
) - 1;
2520 i
>= TYPE_N_BASECLASSES (t
);
2523 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2524 sizeof (vptr_name
) - 1))
2526 TYPE_VPTR_FIELDNO (type
) = i
;
2530 /* Virtual function table field not found. */
2531 complain (&vtbl_notfound_complaint
, TYPE_NAME (type
));
2536 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2547 attach_fn_fields_to_type (fip
, type
)
2548 struct field_info
*fip
;
2549 register struct type
*type
;
2553 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2555 if (TYPE_CODE (TYPE_BASECLASS (type
, n
)) == TYPE_CODE_UNDEF
)
2557 /* @@ Memory leak on objfile -> type_obstack? */
2560 TYPE_NFN_FIELDS_TOTAL (type
) +=
2561 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, n
));
2564 for (n
= TYPE_NFN_FIELDS (type
);
2565 fip
-> fnlist
!= NULL
;
2566 fip
-> fnlist
= fip
-> fnlist
-> next
)
2568 --n
; /* Circumvent Sun3 compiler bug */
2569 TYPE_FN_FIELDLISTS (type
)[n
] = fip
-> fnlist
-> fn_fieldlist
;
2574 /* Create the vector of fields, and record how big it is.
2575 We need this info to record proper virtual function table information
2576 for this class's virtual functions. */
2579 attach_fields_to_type (fip
, type
, objfile
)
2580 struct field_info
*fip
;
2581 register struct type
*type
;
2582 struct objfile
*objfile
;
2584 register int nfields
= 0;
2585 register int non_public_fields
= 0;
2586 register struct nextfield
*scan
;
2588 /* Count up the number of fields that we have, as well as taking note of
2589 whether or not there are any non-public fields, which requires us to
2590 allocate and build the private_field_bits and protected_field_bits
2593 for (scan
= fip
-> list
; scan
!= NULL
; scan
= scan
-> next
)
2596 if (scan
-> visibility
!= VISIBILITY_PUBLIC
)
2598 non_public_fields
++;
2602 /* Now we know how many fields there are, and whether or not there are any
2603 non-public fields. Record the field count, allocate space for the
2604 array of fields, and create blank visibility bitfields if necessary. */
2606 TYPE_NFIELDS (type
) = nfields
;
2607 TYPE_FIELDS (type
) = (struct field
*)
2608 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2609 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2611 if (non_public_fields
)
2613 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2615 TYPE_FIELD_PRIVATE_BITS (type
) =
2616 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2617 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2619 TYPE_FIELD_PROTECTED_BITS (type
) =
2620 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2621 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2624 /* Copy the saved-up fields into the field vector. Start from the head
2625 of the list, adding to the tail of the field array, so that they end
2626 up in the same order in the array in which they were added to the list. */
2628 while (nfields
-- > 0)
2630 TYPE_FIELD (type
, nfields
) = fip
-> list
-> field
;
2631 switch (fip
-> list
-> visibility
)
2633 case VISIBILITY_PRIVATE
:
2634 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2637 case VISIBILITY_PROTECTED
:
2638 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2641 case VISIBILITY_PUBLIC
:
2645 /* Should warn about this unknown visibility? */
2648 fip
-> list
= fip
-> list
-> next
;
2653 /* Read the description of a structure (or union type) and return an object
2654 describing the type.
2656 PP points to a character pointer that points to the next unconsumed token
2657 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2658 *PP will point to "4a:1,0,32;;".
2660 TYPE points to an incomplete type that needs to be filled in.
2662 OBJFILE points to the current objfile from which the stabs information is
2663 being read. (Note that it is redundant in that TYPE also contains a pointer
2664 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2667 static struct type
*
2668 read_struct_type (pp
, type
, objfile
)
2671 struct objfile
*objfile
;
2673 struct cleanup
*back_to
;
2674 struct field_info fi
;
2679 back_to
= make_cleanup (null_cleanup
, 0);
2681 INIT_CPLUS_SPECIFIC (type
);
2682 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2684 /* First comes the total size in bytes. */
2688 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
2690 return error_type (pp
);
2693 /* Now read the baseclasses, if any, read the regular C struct or C++
2694 class member fields, attach the fields to the type, read the C++
2695 member functions, attach them to the type, and then read any tilde
2696 field (baseclass specifier for the class holding the main vtable). */
2698 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
2699 || !read_struct_fields (&fi
, pp
, type
, objfile
)
2700 || !attach_fields_to_type (&fi
, type
, objfile
)
2701 || !read_member_functions (&fi
, pp
, type
, objfile
)
2702 || !attach_fn_fields_to_type (&fi
, type
)
2703 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
2705 do_cleanups (back_to
);
2706 return (error_type (pp
));
2709 do_cleanups (back_to
);
2713 /* Read a definition of an array type,
2714 and create and return a suitable type object.
2715 Also creates a range type which represents the bounds of that
2718 static struct type
*
2719 read_array_type (pp
, type
, objfile
)
2721 register struct type
*type
;
2722 struct objfile
*objfile
;
2724 struct type
*index_type
, *element_type
, *range_type
;
2729 /* Format of an array type:
2730 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2733 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2734 for these, produce a type like float[][]. */
2736 index_type
= read_type (pp
, objfile
);
2738 /* Improper format of array type decl. */
2739 return error_type (pp
);
2742 if (!(**pp
>= '0' && **pp
<= '9'))
2747 lower
= read_huge_number (pp
, ';', &nbits
);
2749 return error_type (pp
);
2751 if (!(**pp
>= '0' && **pp
<= '9'))
2756 upper
= read_huge_number (pp
, ';', &nbits
);
2758 return error_type (pp
);
2760 element_type
= read_type (pp
, objfile
);
2769 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
2770 type
= create_array_type (type
, element_type
, range_type
);
2772 /* If we have an array whose element type is not yet known, but whose
2773 bounds *are* known, record it to be adjusted at the end of the file. */
2775 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2777 add_undefined_type (type
);
2784 /* Read a definition of an enumeration type,
2785 and create and return a suitable type object.
2786 Also defines the symbols that represent the values of the type. */
2788 static struct type
*
2789 read_enum_type (pp
, type
, objfile
)
2791 register struct type
*type
;
2792 struct objfile
*objfile
;
2797 register struct symbol
*sym
;
2799 struct pending
**symlist
;
2800 struct pending
*osyms
, *syms
;
2804 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2805 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2806 to do? For now, force all enum values to file scope. */
2807 if (within_function
)
2808 symlist
= &local_symbols
;
2811 symlist
= &file_symbols
;
2813 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2815 /* Read the value-names and their values.
2816 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2817 A semicolon or comma instead of a NAME means the end. */
2818 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2821 STABS_CONTINUE (pp
);
2823 while (*p
!= ':') p
++;
2824 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
2826 n
= read_huge_number (pp
, ',', &nbits
);
2828 return error_type (pp
);
2830 sym
= (struct symbol
*)
2831 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
2832 memset (sym
, 0, sizeof (struct symbol
));
2833 SYMBOL_NAME (sym
) = name
;
2834 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
2835 SYMBOL_CLASS (sym
) = LOC_CONST
;
2836 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2837 SYMBOL_VALUE (sym
) = n
;
2838 add_symbol_to_list (sym
, symlist
);
2843 (*pp
)++; /* Skip the semicolon. */
2845 /* Now fill in the fields of the type-structure. */
2847 TYPE_LENGTH (type
) = sizeof (int);
2848 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2849 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2850 TYPE_NFIELDS (type
) = nsyms
;
2851 TYPE_FIELDS (type
) = (struct field
*)
2852 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
2853 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
2855 /* Find the symbols for the values and put them into the type.
2856 The symbols can be found in the symlist that we put them on
2857 to cause them to be defined. osyms contains the old value
2858 of that symlist; everything up to there was defined by us. */
2859 /* Note that we preserve the order of the enum constants, so
2860 that in something like "enum {FOO, LAST_THING=FOO}" we print
2861 FOO, not LAST_THING. */
2863 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2868 for (; j
< syms
->nsyms
; j
++,n
++)
2870 struct symbol
*xsym
= syms
->symbol
[j
];
2871 SYMBOL_TYPE (xsym
) = type
;
2872 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2873 TYPE_FIELD_VALUE (type
, n
) = 0;
2874 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2875 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2882 /* This screws up perfectly good C programs with enums. FIXME. */
2883 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2884 if(TYPE_NFIELDS(type
) == 2 &&
2885 ((STREQ(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2886 STREQ(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2887 (STREQ(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2888 STREQ(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2889 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2895 /* Sun's ACC uses a somewhat saner method for specifying the builtin
2896 typedefs in every file (for int, long, etc):
2898 type = b <signed> <width>; <offset>; <nbits>
2899 signed = u or s. Possible c in addition to u or s (for char?).
2900 offset = offset from high order bit to start bit of type.
2901 width is # bytes in object of this type, nbits is # bits in type.
2903 The width/offset stuff appears to be for small objects stored in
2904 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
2907 static struct type
*
2908 read_sun_builtin_type (pp
, typenums
, objfile
)
2911 struct objfile
*objfile
;
2926 return error_type (pp
);
2930 /* For some odd reason, all forms of char put a c here. This is strange
2931 because no other type has this honor. We can safely ignore this because
2932 we actually determine 'char'acterness by the number of bits specified in
2938 /* The first number appears to be the number of bytes occupied
2939 by this type, except that unsigned short is 4 instead of 2.
2940 Since this information is redundant with the third number,
2941 we will ignore it. */
2942 read_huge_number (pp
, ';', &nbits
);
2944 return error_type (pp
);
2946 /* The second number is always 0, so ignore it too. */
2947 read_huge_number (pp
, ';', &nbits
);
2949 return error_type (pp
);
2951 /* The third number is the number of bits for this type. */
2952 type_bits
= read_huge_number (pp
, 0, &nbits
);
2954 return error_type (pp
);
2957 /* FIXME. Here we should just be able to make a type of the right
2958 number of bits and signedness. FIXME. */
2960 if (type_bits
== TARGET_LONG_LONG_BIT
)
2961 return (lookup_fundamental_type (objfile
,
2962 signed_type
? FT_LONG_LONG
: FT_UNSIGNED_LONG_LONG
));
2964 if (type_bits
== TARGET_INT_BIT
)
2966 /* FIXME -- the only way to distinguish `int' from `long'
2967 is to look at its name! */
2970 if (long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
2971 return lookup_fundamental_type (objfile
, FT_LONG
);
2973 return lookup_fundamental_type (objfile
, FT_INTEGER
);
2977 if (long_kludge_name
2978 && ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2979 long_kludge_name
[9] == 'l' /* long */)
2980 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2981 return lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
);
2983 return lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
2987 if (type_bits
== TARGET_SHORT_BIT
)
2988 return (lookup_fundamental_type (objfile
,
2989 signed_type
? FT_SHORT
: FT_UNSIGNED_SHORT
));
2991 if (type_bits
== TARGET_CHAR_BIT
)
2992 return (lookup_fundamental_type (objfile
,
2993 signed_type
? FT_CHAR
: FT_UNSIGNED_CHAR
));
2996 return lookup_fundamental_type (objfile
, FT_VOID
);
2998 return error_type (pp
);
3000 return init_type (type_bits
== 0 ? TYPE_CODE_VOID
: TYPE_CODE_INT
,
3001 type_bits
/ TARGET_CHAR_BIT
,
3002 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3007 static struct type
*
3008 read_sun_floating_type (pp
, typenums
, objfile
)
3011 struct objfile
*objfile
;
3017 /* The first number has more details about the type, for example
3019 details
= read_huge_number (pp
, ';', &nbits
);
3021 return error_type (pp
);
3023 /* The second number is the number of bytes occupied by this type */
3024 nbytes
= read_huge_number (pp
, ';', &nbits
);
3026 return error_type (pp
);
3028 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
3029 || details
== NF_COMPLEX32
)
3030 /* This is a type we can't handle, but we do know the size.
3031 We also will be able to give it a name. */
3032 return init_type (TYPE_CODE_ERROR
, nbytes
, 0, NULL
, objfile
);
3034 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
3037 /* Read a number from the string pointed to by *PP.
3038 The value of *PP is advanced over the number.
3039 If END is nonzero, the character that ends the
3040 number must match END, or an error happens;
3041 and that character is skipped if it does match.
3042 If END is zero, *PP is left pointing to that character.
3044 If the number fits in a long, set *BITS to 0 and return the value.
3045 If not, set *BITS to be the number of bits in the number and return 0.
3047 If encounter garbage, set *BITS to -1 and return 0. */
3050 read_huge_number (pp
, end
, bits
)
3070 /* Leading zero means octal. GCC uses this to output values larger
3071 than an int (because that would be hard in decimal). */
3078 upper_limit
= LONG_MAX
/ radix
;
3079 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
3081 if (n
<= upper_limit
)
3084 n
+= c
- '0'; /* FIXME this overflows anyway */
3089 /* This depends on large values being output in octal, which is
3096 /* Ignore leading zeroes. */
3100 else if (c
== '2' || c
== '3')
3126 /* Large decimal constants are an error (because it is hard to
3127 count how many bits are in them). */
3133 /* -0x7f is the same as 0x80. So deal with it by adding one to
3134 the number of bits. */
3146 /* It's *BITS which has the interesting information. */
3150 static struct type
*
3151 read_range_type (pp
, typenums
, objfile
)
3154 struct objfile
*objfile
;
3160 struct type
*result_type
;
3161 struct type
*index_type
;
3163 /* First comes a type we are a subrange of.
3164 In C it is usually 0, 1 or the type being defined. */
3165 /* FIXME: according to stabs.texinfo and AIX doc, this can be a type-id
3166 not just a type number. */
3167 if (read_type_number (pp
, rangenums
) != 0)
3168 return error_type (pp
);
3169 self_subrange
= (rangenums
[0] == typenums
[0] &&
3170 rangenums
[1] == typenums
[1]);
3172 /* A semicolon should now follow; skip it. */
3176 /* The remaining two operands are usually lower and upper bounds
3177 of the range. But in some special cases they mean something else. */
3178 n2
= read_huge_number (pp
, ';', &n2bits
);
3179 n3
= read_huge_number (pp
, ';', &n3bits
);
3181 if (n2bits
== -1 || n3bits
== -1)
3182 return error_type (pp
);
3184 /* If limits are huge, must be large integral type. */
3185 if (n2bits
!= 0 || n3bits
!= 0)
3187 char got_signed
= 0;
3188 char got_unsigned
= 0;
3189 /* Number of bits in the type. */
3192 /* Range from 0 to <large number> is an unsigned large integral type. */
3193 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
3198 /* Range from <large number> to <large number>-1 is a large signed
3200 else if (n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
3206 if (got_signed
|| got_unsigned
)
3208 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
3209 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
3213 return error_type (pp
);
3216 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3217 if (self_subrange
&& n2
== 0 && n3
== 0)
3218 return init_type (TYPE_CODE_VOID
, 0, 0, NULL
, objfile
);
3220 /* If n3 is zero and n2 is not, we want a floating type,
3221 and n2 is the width in bytes.
3223 Fortran programs appear to use this for complex types also,
3224 and they give no way to distinguish between double and single-complex!
3226 GDB does not have complex types.
3228 Just return the complex as a float of that size. It won't work right
3229 for the complex values, but at least it makes the file loadable.
3231 FIXME, we may be able to distinguish these by their names. FIXME. */
3233 if (n3
== 0 && n2
> 0)
3235 return init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
3238 /* If the upper bound is -1, it must really be an unsigned int. */
3240 else if (n2
== 0 && n3
== -1)
3242 /* It is unsigned int or unsigned long. */
3243 /* GCC sometimes uses this for long long too. We could
3244 distinguish it by the name, but we don't. */
3245 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3246 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3249 /* Special case: char is defined (Who knows why) as a subrange of
3250 itself with range 0-127. */
3251 else if (self_subrange
&& n2
== 0 && n3
== 127)
3252 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3254 /* We used to do this only for subrange of self or subrange of int. */
3258 /* n3 actually gives the size. */
3259 return init_type (TYPE_CODE_INT
, - n3
, TYPE_FLAG_UNSIGNED
,
3262 return init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3264 return init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3266 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
3267 "unsigned long", and we already checked for that,
3268 so don't need to test for it here. */
3270 /* I think this is for Convex "long long". Since I don't know whether
3271 Convex sets self_subrange, I also accept that particular size regardless
3272 of self_subrange. */
3273 else if (n3
== 0 && n2
< 0
3275 || n2
== - TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
3276 return init_type (TYPE_CODE_INT
, - n2
, 0, NULL
, objfile
);
3277 else if (n2
== -n3
-1)
3280 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3282 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
3283 if (n3
== 0x7fffffff)
3284 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
3287 /* We have a real range type on our hands. Allocate space and
3288 return a real pointer. */
3290 /* At this point I don't have the faintest idea how to deal with
3291 a self_subrange type; I'm going to assume that this is used
3292 as an idiom, and that all of them are special cases. So . . . */
3294 return error_type (pp
);
3296 index_type
= *dbx_lookup_type (rangenums
);
3297 if (index_type
== NULL
)
3299 /* Does this actually ever happen? Is that why we are worrying
3300 about dealing with it rather than just calling error_type? */
3302 static struct type
*range_type_index
;
3304 complain (&range_type_base_complaint
, rangenums
[1]);
3305 if (range_type_index
== NULL
)
3307 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3308 0, "range type index type", NULL
);
3309 index_type
= range_type_index
;
3312 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
3313 return (result_type
);
3316 /* Read in an argument list. This is a list of types, separated by commas
3317 and terminated with END. Return the list of types read in, or (struct type
3318 **)-1 if there is an error. */
3320 static struct type
**
3321 read_args (pp
, end
, objfile
)
3324 struct objfile
*objfile
;
3326 /* FIXME! Remove this arbitrary limit! */
3327 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3333 /* Invalid argument list: no ','. */
3334 return (struct type
**)-1;
3336 STABS_CONTINUE (pp
);
3337 types
[n
++] = read_type (pp
, objfile
);
3339 (*pp
)++; /* get past `end' (the ':' character) */
3343 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3345 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3347 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3348 memset (rval
+ n
, 0, sizeof (struct type
*));
3352 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3354 memcpy (rval
, types
, n
* sizeof (struct type
*));
3358 /* Add a common block's start address to the offset of each symbol
3359 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3360 the common block name). */
3363 fix_common_block (sym
, valu
)
3367 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
3368 for ( ; next
; next
= next
->next
)
3371 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3372 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3378 /* What about types defined as forward references inside of a small lexical
3380 /* Add a type to the list of undefined types to be checked through
3381 once this file has been read in. */
3384 add_undefined_type (type
)
3387 if (undef_types_length
== undef_types_allocated
)
3389 undef_types_allocated
*= 2;
3390 undef_types
= (struct type
**)
3391 xrealloc ((char *) undef_types
,
3392 undef_types_allocated
* sizeof (struct type
*));
3394 undef_types
[undef_types_length
++] = type
;
3397 /* Go through each undefined type, see if it's still undefined, and fix it
3398 up if possible. We have two kinds of undefined types:
3400 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3401 Fix: update array length using the element bounds
3402 and the target type's length.
3403 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3404 yet defined at the time a pointer to it was made.
3405 Fix: Do a full lookup on the struct/union tag. */
3407 cleanup_undefined_types ()
3411 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
3413 switch (TYPE_CODE (*type
))
3416 case TYPE_CODE_STRUCT
:
3417 case TYPE_CODE_UNION
:
3418 case TYPE_CODE_ENUM
:
3420 /* Check if it has been defined since. */
3421 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
3423 struct pending
*ppt
;
3425 /* Name of the type, without "struct" or "union" */
3426 char *typename
= TYPE_TAG_NAME (*type
);
3428 if (typename
== NULL
)
3430 static struct complaint msg
= {"need a type name", 0, 0};
3434 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
3436 for (i
= 0; i
< ppt
->nsyms
; i
++)
3438 struct symbol
*sym
= ppt
->symbol
[i
];
3440 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3441 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
3442 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
3444 && STREQ (SYMBOL_NAME (sym
), typename
))
3446 memcpy (*type
, SYMBOL_TYPE (sym
),
3447 sizeof (struct type
));
3455 case TYPE_CODE_ARRAY
:
3457 struct type
*range_type
;
3460 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
3462 if (TYPE_NFIELDS (*type
) != 1)
3464 range_type
= TYPE_FIELD_TYPE (*type
, 0);
3465 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
3468 /* Now recompute the length of the array type, based on its
3469 number of elements and the target type's length. */
3470 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
3471 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
3472 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
3473 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
3480 static struct complaint msg
= {"\
3481 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
3482 complain (&msg
, TYPE_CODE (*type
));
3487 undef_types_length
= 0;
3490 /* Scan through all of the global symbols defined in the object file,
3491 assigning values to the debugging symbols that need to be assigned
3492 to. Get these symbols from the minimal symbol table. */
3495 scan_file_globals (objfile
)
3496 struct objfile
*objfile
;
3499 struct minimal_symbol
*msymbol
;
3500 struct symbol
*sym
, *prev
;
3502 if (objfile
->msymbols
== 0) /* Beware the null file. */
3505 for (msymbol
= objfile
-> msymbols
; SYMBOL_NAME (msymbol
) != NULL
; msymbol
++)
3511 /* Get the hash index and check all the symbols
3512 under that hash index. */
3514 hash
= hashname (SYMBOL_NAME (msymbol
));
3516 for (sym
= global_sym_chain
[hash
]; sym
;)
3518 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
3519 STREQ(SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
3521 /* Splice this symbol out of the hash chain and
3522 assign the value we have to it. */
3525 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
3529 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
3532 /* Check to see whether we need to fix up a common block. */
3533 /* Note: this code might be executed several times for
3534 the same symbol if there are multiple references. */
3536 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3538 fix_common_block (sym
, SYMBOL_VALUE_ADDRESS (msymbol
));
3542 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msymbol
);
3547 sym
= SYMBOL_VALUE_CHAIN (prev
);
3551 sym
= global_sym_chain
[hash
];
3557 sym
= SYMBOL_VALUE_CHAIN (sym
);
3563 /* Initialize anything that needs initializing when starting to read
3564 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
3572 /* Initialize anything that needs initializing when a completely new
3573 symbol file is specified (not just adding some symbols from another
3574 file, e.g. a shared library). */
3577 stabsread_new_init ()
3579 /* Empty the hash table of global syms looking for values. */
3580 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
3583 /* Initialize anything that needs initializing at the same time as
3584 start_symtab() is called. */
3588 global_stabs
= NULL
; /* AIX COFF */
3589 /* Leave FILENUM of 0 free for builtin types and this file's types. */
3590 n_this_object_header_files
= 1;
3591 type_vector_length
= 0;
3592 type_vector
= (struct type
**) 0;
3595 /* Call after end_symtab() */
3601 free ((char *) type_vector
);
3604 type_vector_length
= 0;
3605 previous_stab_code
= 0;
3609 finish_global_stabs (objfile
)
3610 struct objfile
*objfile
;
3614 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
3615 free ((PTR
) global_stabs
);
3616 global_stabs
= NULL
;
3620 /* Initializer for this module */
3623 _initialize_stabsread ()
3625 undef_types_allocated
= 20;
3626 undef_types_length
= 0;
3627 undef_types
= (struct type
**)
3628 xmalloc (undef_types_allocated
* sizeof (struct type
*));