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 /* This is used by other symbol readers besides stabs, so for cleanliness
221 should probably be in buildsym.c. */
227 register char *p
= name
;
228 register int total
= p
[0];
243 /* Ensure result is positive. */
246 total
+= (1000 << 6);
248 return (total
% HASHSIZE
);
252 /* Look up a dbx type-number pair. Return the address of the slot
253 where the type for that number-pair is stored.
254 The number-pair is in TYPENUMS.
256 This can be used for finding the type associated with that pair
257 or for associating a new type with the pair. */
260 dbx_lookup_type (typenums
)
263 register int filenum
= typenums
[0];
264 register int index
= typenums
[1];
266 register int real_filenum
;
267 register struct header_file
*f
;
270 if (filenum
== -1) /* -1,-1 is for temporary types. */
273 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
275 static struct complaint msg
= {"\
276 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
278 complain (&msg
, filenum
, index
, symnum
);
286 /* Caller wants address of address of type. We think
287 that negative (rs6k builtin) types will never appear as
288 "lvalues", (nor should they), so we stuff the real type
289 pointer into a temp, and return its address. If referenced,
290 this will do the right thing. */
291 static struct type
*temp_type
;
293 temp_type
= rs6000_builtin_type(index
);
297 /* Type is defined outside of header files.
298 Find it in this object file's type vector. */
299 if (index
>= type_vector_length
)
301 old_len
= type_vector_length
;
304 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
305 type_vector
= (struct type
**)
306 malloc (type_vector_length
* sizeof (struct type
*));
308 while (index
>= type_vector_length
)
310 type_vector_length
*= 2;
312 type_vector
= (struct type
**)
313 xrealloc ((char *) type_vector
,
314 (type_vector_length
* sizeof (struct type
*)));
315 memset (&type_vector
[old_len
], 0,
316 (type_vector_length
- old_len
) * sizeof (struct type
*));
318 return (&type_vector
[index
]);
322 real_filenum
= this_object_header_files
[filenum
];
324 if (real_filenum
>= n_header_files
)
326 struct type
*temp_type
;
327 struct type
**temp_type_p
;
329 warning ("GDB internal error: bad real_filenum");
332 temp_type
= init_type (TYPE_CODE_ERROR
, 0, 0, NULL
, NULL
);
333 temp_type_p
= (struct type
**) xmalloc (sizeof (struct type
*));
334 *temp_type_p
= temp_type
;
338 f
= &header_files
[real_filenum
];
340 f_orig_length
= f
->length
;
341 if (index
>= f_orig_length
)
343 while (index
>= f
->length
)
347 f
->vector
= (struct type
**)
348 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
349 memset (&f
->vector
[f_orig_length
], 0,
350 (f
->length
- f_orig_length
) * sizeof (struct type
*));
352 return (&f
->vector
[index
]);
356 /* Make sure there is a type allocated for type numbers TYPENUMS
357 and return the type object.
358 This can create an empty (zeroed) type object.
359 TYPENUMS may be (-1, -1) to return a new type object that is not
360 put into the type vector, and so may not be referred to by number. */
363 dbx_alloc_type (typenums
, objfile
)
365 struct objfile
*objfile
;
367 register struct type
**type_addr
;
369 if (typenums
[0] == -1)
371 return (alloc_type (objfile
));
374 type_addr
= dbx_lookup_type (typenums
);
376 /* If we are referring to a type not known at all yet,
377 allocate an empty type for it.
378 We will fill it in later if we find out how. */
381 *type_addr
= alloc_type (objfile
);
387 /* for all the stabs in a given stab vector, build appropriate types
388 and fix their symbols in given symbol vector. */
391 patch_block_stabs (symbols
, stabs
, objfile
)
392 struct pending
*symbols
;
393 struct pending_stabs
*stabs
;
394 struct objfile
*objfile
;
404 /* for all the stab entries, find their corresponding symbols and
405 patch their types! */
407 for (ii
= 0; ii
< stabs
->count
; ++ii
)
409 name
= stabs
->stab
[ii
];
410 pp
= (char*) strchr (name
, ':');
411 sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
414 /* On xcoff, if a global is defined and never referenced,
415 ld will remove it from the executable. There is then
416 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
417 sym
= (struct symbol
*)
418 obstack_alloc (&objfile
->symbol_obstack
,
419 sizeof (struct symbol
));
421 memset (sym
, 0, sizeof (struct symbol
));
422 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
423 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
425 obstack_copy0 (&objfile
->symbol_obstack
, name
, pp
- name
);
427 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
429 /* I don't think the linker does this with functions,
430 so as far as I know this is never executed.
431 But it doesn't hurt to check. */
433 lookup_function_type (read_type (&pp
, objfile
));
437 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
439 add_symbol_to_list (sym
, &global_symbols
);
444 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
447 lookup_function_type (read_type (&pp
, objfile
));
451 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
459 /* Read a number by which a type is referred to in dbx data,
460 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
461 Just a single number N is equivalent to (0,N).
462 Return the two numbers by storing them in the vector TYPENUMS.
463 TYPENUMS will then be used as an argument to dbx_lookup_type.
465 Returns 0 for success, -1 for error. */
468 read_type_number (pp
, typenums
)
470 register int *typenums
;
476 typenums
[0] = read_huge_number (pp
, ',', &nbits
);
477 if (nbits
!= 0) return -1;
478 typenums
[1] = read_huge_number (pp
, ')', &nbits
);
479 if (nbits
!= 0) return -1;
484 typenums
[1] = read_huge_number (pp
, 0, &nbits
);
485 if (nbits
!= 0) return -1;
491 /* To handle GNU C++ typename abbreviation, we need to be able to
492 fill in a type's name as soon as space for that type is allocated.
493 `type_synonym_name' is the name of the type being allocated.
494 It is cleared as soon as it is used (lest all allocated types
497 static char *type_synonym_name
;
501 define_symbol (valu
, string
, desc
, type
, objfile
)
506 struct objfile
*objfile
;
508 register struct symbol
*sym
;
509 char *p
= (char *) strchr (string
, ':');
514 /* We would like to eliminate nameless symbols, but keep their types.
515 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
516 to type 2, but, should not create a symbol to address that type. Since
517 the symbol will be nameless, there is no way any user can refer to it. */
521 /* Ignore syms with empty names. */
525 /* Ignore old-style symbols from cc -go */
529 /* If a nameless stab entry, all we need is the type, not the symbol.
530 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
531 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
533 sym
= (struct symbol
*)
534 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
535 memset (sym
, 0, sizeof (struct symbol
));
537 if (processing_gcc_compilation
)
539 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
540 number of bytes occupied by a type or object, which we ignore. */
541 SYMBOL_LINE(sym
) = desc
;
545 SYMBOL_LINE(sym
) = 0; /* unknown */
548 if (string
[0] == CPLUS_MARKER
)
550 /* Special GNU C++ names. */
554 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
555 &objfile
-> symbol_obstack
);
558 case 'v': /* $vtbl_ptr_type */
559 /* Was: SYMBOL_NAME (sym) = "vptr"; */
563 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
564 &objfile
-> symbol_obstack
);
568 /* This was an anonymous type that was never fixed up. */
572 complain (&unrecognized_cplus_name_complaint
, string
);
573 goto normal
; /* Do *something* with it */
579 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
580 SYMBOL_NAME (sym
) = (char *)
581 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
582 /* Open-coded bcopy--saves function call time. */
583 /* FIXME: Does it really? Try replacing with simple strcpy and
584 try it on an executable with a large symbol table. */
586 register char *p1
= string
;
587 register char *p2
= SYMBOL_NAME (sym
);
595 /* If this symbol is from a C++ compilation, then attempt to cache the
596 demangled form for future reference. This is a typical time versus
597 space tradeoff, that was decided in favor of time because it sped up
598 C++ symbol lookups by a factor of about 20. */
600 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
604 /* Determine the type of name being defined. */
606 /* Getting GDB to correctly skip the symbol on an undefined symbol
607 descriptor and not ever dump core is a very dodgy proposition if
608 we do things this way. I say the acorn RISC machine can just
609 fix their compiler. */
610 /* The Acorn RISC machine's compiler can put out locals that don't
611 start with "234=" or "(3,4)=", so assume anything other than the
612 deftypes we know how to handle is a local. */
613 if (!strchr ("cfFGpPrStTvVXCR", *p
))
615 if (isdigit (*p
) || *p
== '(' || *p
== '-')
624 /* c is a special case, not followed by a type-number.
625 SYMBOL:c=iVALUE for an integer constant symbol.
626 SYMBOL:c=rVALUE for a floating constant symbol.
627 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
628 e.g. "b:c=e6,0" for "const b = blob1"
629 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
632 SYMBOL_CLASS (sym
) = LOC_CONST
;
633 SYMBOL_TYPE (sym
) = error_type (&p
);
634 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
635 add_symbol_to_list (sym
, &file_symbols
);
646 /* FIXME: lookup_fundamental_type is a hack. We should be
647 creating a type especially for the type of float constants.
648 Problem is, what type should it be? We currently have to
649 read this in host floating point format, but what type
650 represents a host format "double"?
652 Also, what should the name of this type be? Should we
653 be using 'S' constants (see stabs.texinfo) instead? */
655 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
658 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (double));
659 memcpy (dbl_valu
, &d
, sizeof (double));
660 /* Put it in target byte order, but it's still in host
661 floating point format. */
662 SWAP_TARGET_AND_HOST (dbl_valu
, sizeof (double));
663 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
664 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
669 /* Defining integer constants this way is kind of silly,
670 since 'e' constants allows the compiler to give not
671 only the value, but the type as well. C has at least
672 int, long, unsigned int, and long long as constant
673 types; other languages probably should have at least
674 unsigned as well as signed constants. */
676 /* We just need one int constant type for all objfiles.
677 It doesn't depend on languages or anything (arguably its
678 name should be a language-specific name for a type of
679 that size, but I'm inclined to say that if the compiler
680 wants a nice name for the type, it can use 'e'). */
681 static struct type
*int_const_type
;
683 /* Yes, this is as long as a *host* int. That is because we
685 if (int_const_type
== NULL
)
687 init_type (TYPE_CODE_INT
,
688 sizeof (int) * HOST_CHAR_BIT
/ TARGET_CHAR_BIT
, 0,
690 (struct objfile
*)NULL
);
691 SYMBOL_TYPE (sym
) = int_const_type
;
692 SYMBOL_VALUE (sym
) = atoi (p
);
693 SYMBOL_CLASS (sym
) = LOC_CONST
;
697 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
698 can be represented as integral.
699 e.g. "b:c=e6,0" for "const b = blob1"
700 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
702 SYMBOL_CLASS (sym
) = LOC_CONST
;
703 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
707 SYMBOL_TYPE (sym
) = error_type (&p
);
712 /* If the value is too big to fit in an int (perhaps because
713 it is unsigned), or something like that, we silently get
714 a bogus value. The type and everything else about it is
715 correct. Ideally, we should be using whatever we have
716 available for parsing unsigned and long long values,
718 SYMBOL_VALUE (sym
) = atoi (p
);
723 SYMBOL_CLASS (sym
) = LOC_CONST
;
724 SYMBOL_TYPE (sym
) = error_type (&p
);
727 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
728 add_symbol_to_list (sym
, &file_symbols
);
732 /* The name of a caught exception. */
733 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
734 SYMBOL_CLASS (sym
) = LOC_LABEL
;
735 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
736 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
737 add_symbol_to_list (sym
, &local_symbols
);
741 /* A static function definition. */
742 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
743 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
744 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
745 add_symbol_to_list (sym
, &file_symbols
);
746 /* fall into process_function_types. */
748 process_function_types
:
749 /* Function result types are described as the result type in stabs.
750 We need to convert this to the function-returning-type-X type
751 in GDB. E.g. "int" is converted to "function returning int". */
752 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
755 /* This code doesn't work -- it needs to realloc and can't. */
756 /* Attempt to set up to record a function prototype... */
757 struct type
*new = alloc_type (objfile
);
759 /* Generate a template for the type of this function. The
760 types of the arguments will be added as we read the symbol
762 *new = *lookup_function_type (SYMBOL_TYPE(sym
));
763 SYMBOL_TYPE(sym
) = new;
764 TYPE_OBJFILE (new) = objfile
;
765 in_function_type
= new;
767 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
770 /* fall into process_prototype_types */
772 process_prototype_types
:
773 /* Sun acc puts declared types of arguments here. We don't care
774 about their actual types (FIXME -- we should remember the whole
775 function prototype), but the list may define some new types
776 that we have to remember, so we must scan it now. */
779 read_type (&p
, objfile
);
784 /* A global function definition. */
785 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
786 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
787 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
788 add_symbol_to_list (sym
, &global_symbols
);
789 goto process_function_types
;
792 /* For a class G (global) symbol, it appears that the
793 value is not correct. It is necessary to search for the
794 corresponding linker definition to find the value.
795 These definitions appear at the end of the namelist. */
796 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
797 i
= hashname (SYMBOL_NAME (sym
));
798 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
799 global_sym_chain
[i
] = sym
;
800 SYMBOL_CLASS (sym
) = LOC_STATIC
;
801 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
802 add_symbol_to_list (sym
, &global_symbols
);
805 /* This case is faked by a conditional above,
806 when there is no code letter in the dbx data.
807 Dbx data never actually contains 'l'. */
809 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
810 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
811 SYMBOL_VALUE (sym
) = valu
;
812 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
813 add_symbol_to_list (sym
, &local_symbols
);
818 /* pF is a two-letter code that means a function parameter in Fortran.
819 The type-number specifies the type of the return value.
820 Translate it into a pointer-to-function type. */
824 = lookup_pointer_type
825 (lookup_function_type (read_type (&p
, objfile
)));
828 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
830 /* Normally this is a parameter, a LOC_ARG. On the i960, it
831 can also be a LOC_LOCAL_ARG depending on symbol type. */
832 #ifndef DBX_PARM_SYMBOL_CLASS
833 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
836 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
837 SYMBOL_VALUE (sym
) = valu
;
838 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
840 /* This doesn't work yet. */
841 add_param_to_type (&in_function_type
, sym
);
843 add_symbol_to_list (sym
, &local_symbols
);
845 /* If it's gcc-compiled, if it says `short', believe it. */
846 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
849 #if !BELIEVE_PCC_PROMOTION
851 /* This is the signed type which arguments get promoted to. */
852 static struct type
*pcc_promotion_type
;
853 /* This is the unsigned type which arguments get promoted to. */
854 static struct type
*pcc_unsigned_promotion_type
;
856 /* Call it "int" because this is mainly C lossage. */
857 if (pcc_promotion_type
== NULL
)
859 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
862 if (pcc_unsigned_promotion_type
== NULL
)
863 pcc_unsigned_promotion_type
=
864 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
865 TYPE_FLAG_UNSIGNED
, "unsigned int", NULL
);
867 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
868 /* This macro is defined on machines (e.g. sparc) where
869 we should believe the type of a PCC 'short' argument,
870 but shouldn't believe the address (the address is
871 the address of the corresponding int). Note that
872 this is only different from the BELIEVE_PCC_PROMOTION
873 case on big-endian machines.
875 My guess is that this correction, as opposed to changing
876 the parameter to an 'int' (as done below, for PCC
877 on most machines), is the right thing to do
878 on all machines, but I don't want to risk breaking
879 something that already works. On most PCC machines,
880 the sparc problem doesn't come up because the calling
881 function has to zero the top bytes (not knowing whether
882 the called function wants an int or a short), so there
883 is no practical difference between an int and a short
884 (except perhaps what happens when the GDB user types
885 "print short_arg = 0x10000;").
887 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
888 actually produces the correct address (we don't need to fix it
889 up). I made this code adapt so that it will offset the symbol
890 if it was pointing at an int-aligned location and not
891 otherwise. This way you can use the same gdb for 4.0.x and
894 If the parameter is shorter than an int, and is integral
895 (e.g. char, short, or unsigned equivalent), and is claimed to
896 be passed on an integer boundary, don't believe it! Offset the
897 parameter's address to the tail-end of that integer. */
899 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
900 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
901 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (pcc_promotion_type
))
903 SYMBOL_VALUE (sym
) += TYPE_LENGTH (pcc_promotion_type
)
904 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
908 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
910 /* If PCC says a parameter is a short or a char,
911 it is really an int. */
912 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
913 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
916 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
917 ? pcc_unsigned_promotion_type
918 : pcc_promotion_type
;
922 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
924 #endif /* !BELIEVE_PCC_PROMOTION. */
927 /* acc seems to use P to delare the prototypes of functions that
928 are referenced by this file. gdb is not prepared to deal
929 with this extra information. FIXME, it ought to. */
932 read_type (&p
, objfile
);
933 goto process_prototype_types
;
938 /* Parameter which is in a register. */
939 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
940 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
941 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
942 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
944 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
945 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
947 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
948 add_symbol_to_list (sym
, &local_symbols
);
952 /* Register variable (either global or local). */
953 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
954 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
955 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
956 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
958 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
959 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
961 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
964 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
965 name to represent an argument passed in a register.
966 GCC uses 'P' for the same case. So if we find such a symbol pair
967 we combine it into one 'P' symbol.
968 Note that this code illegally combines
969 main(argc) int argc; { register int argc = 1; }
970 but this case is considered pathological and causes a warning
971 from a decent compiler. */
973 && local_symbols
->nsyms
> 0)
975 struct symbol
*prev_sym
;
976 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
977 if (SYMBOL_CLASS (prev_sym
) == LOC_ARG
978 && STREQ (SYMBOL_NAME (prev_sym
), SYMBOL_NAME(sym
)))
980 SYMBOL_CLASS (prev_sym
) = LOC_REGPARM
;
981 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
986 add_symbol_to_list (sym
, &local_symbols
);
989 add_symbol_to_list (sym
, &file_symbols
);
993 /* Static symbol at top level of file */
994 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
995 SYMBOL_CLASS (sym
) = LOC_STATIC
;
996 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
997 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
998 add_symbol_to_list (sym
, &file_symbols
);
1003 /* See comment where long_kludge_name is declared. */
1004 /* Here we save the name of the symbol for read_range_type, which
1005 ends up reading in the basic types. In stabs, unfortunately there
1006 is no distinction between "int" and "long" types except their
1007 names. Until we work out a saner type policy (eliminating most
1008 builtin types and using the names specified in the files), we
1009 save away the name so that far away from here in read_range_type,
1010 we can examine it to decide between "int" and "long". FIXME. */
1011 long_kludge_name
= SYMBOL_NAME (sym
);
1013 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1015 /* For a nameless type, we don't want a create a symbol, thus we
1016 did not use `sym'. Return without further processing. */
1017 if (nameless
) return NULL
;
1019 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1020 SYMBOL_VALUE (sym
) = valu
;
1021 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1022 /* C++ vagaries: we may have a type which is derived from
1023 a base type which did not have its name defined when the
1024 derived class was output. We fill in the derived class's
1025 base part member's name here in that case. */
1026 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
1027 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1028 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1029 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1032 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1033 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1034 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1035 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1038 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1040 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
)
1042 /* If we are giving a name to a type such as "pointer
1043 to foo", we better not set the TYPE_NAME. If the
1044 program contains "typedef char *caddr_t;", we don't
1045 want all variables of type char * to print as
1046 caddr_t. This is not just a consequence of GDB's
1047 type management; PCC and GCC (at least through
1048 version 2.4) both output variables of either type
1049 char * or caddr_t with the type number defined in
1050 the 't' symbol for caddr_t. If a future compiler
1051 cleans this up it GDB is not ready for it yet, but
1052 if it becomes ready we somehow need to disable this
1053 check (without breaking the PCC/GCC2.4 case).
1057 Fortunately, this check seems not to be necessary
1058 for anything except pointers. */
1061 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
1064 add_symbol_to_list (sym
, &file_symbols
);
1068 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1069 by 't' which means we are typedef'ing it as well. */
1070 synonym
= *p
== 't';
1075 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1076 strlen (SYMBOL_NAME (sym
)),
1077 &objfile
-> symbol_obstack
);
1080 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1082 /* For a nameless type, we don't want a create a symbol, thus we
1083 did not use `sym'. Return without further processing. */
1084 if (nameless
) return NULL
;
1086 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1087 SYMBOL_VALUE (sym
) = valu
;
1088 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1089 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1090 TYPE_NAME (SYMBOL_TYPE (sym
))
1091 = obconcat (&objfile
-> type_obstack
, "",
1092 (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_ENUM
1094 : (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1095 ? "struct " : "union ")),
1097 add_symbol_to_list (sym
, &file_symbols
);
1101 /* Clone the sym and then modify it. */
1102 register struct symbol
*typedef_sym
= (struct symbol
*)
1103 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1104 *typedef_sym
= *sym
;
1105 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1106 SYMBOL_VALUE (typedef_sym
) = valu
;
1107 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1108 add_symbol_to_list (typedef_sym
, &file_symbols
);
1113 /* Static symbol of local scope */
1114 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1115 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1116 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1117 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1118 add_symbol_to_list (sym
, &local_symbols
);
1122 /* Reference parameter */
1123 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1124 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1125 SYMBOL_VALUE (sym
) = valu
;
1126 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1127 add_symbol_to_list (sym
, &local_symbols
);
1131 /* This is used by Sun FORTRAN for "function result value".
1132 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1133 that Pascal uses it too, but when I tried it Pascal used
1134 "x:3" (local symbol) instead. */
1135 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1136 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1137 SYMBOL_VALUE (sym
) = valu
;
1138 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1139 add_symbol_to_list (sym
, &local_symbols
);
1143 SYMBOL_TYPE (sym
) = error_type (&p
);
1144 SYMBOL_CLASS (sym
) = LOC_CONST
;
1145 SYMBOL_VALUE (sym
) = 0;
1146 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1147 add_symbol_to_list (sym
, &file_symbols
);
1151 /* When passing structures to a function, some systems sometimes pass
1152 the address in a register, not the structure itself.
1154 If REG_STRUCT_HAS_ADDR yields non-zero we have to convert LOC_REGPARM
1155 to LOC_REGPARM_ADDR for structures and unions. */
1157 #if !defined (REG_STRUCT_HAS_ADDR)
1158 #define REG_STRUCT_HAS_ADDR(gcc_p) 0
1161 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
1162 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
)
1163 && ( (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
1164 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)))
1165 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1171 /* Skip rest of this symbol and return an error type.
1173 General notes on error recovery: error_type always skips to the
1174 end of the symbol (modulo cretinous dbx symbol name continuation).
1175 Thus code like this:
1177 if (*(*pp)++ != ';')
1178 return error_type (pp);
1180 is wrong because if *pp starts out pointing at '\0' (typically as the
1181 result of an earlier error), it will be incremented to point to the
1182 start of the next symbol, which might produce strange results, at least
1183 if you run off the end of the string table. Instead use
1186 return error_type (pp);
1192 foo = error_type (pp);
1196 And in case it isn't obvious, the point of all this hair is so the compiler
1197 can define new types and new syntaxes, and old versions of the
1198 debugger will be able to read the new symbol tables. */
1200 static struct type
*
1204 complain (&error_type_complaint
);
1207 /* Skip to end of symbol. */
1208 while (**pp
!= '\0')
1213 /* Check for and handle cretinous dbx symbol name continuation! */
1214 if ((*pp
)[-1] == '\\')
1216 *pp
= next_symbol_text ();
1223 return (builtin_type_error
);
1227 /* Read type information or a type definition; return the type. Even
1228 though this routine accepts either type information or a type
1229 definition, the distinction is relevant--some parts of stabsread.c
1230 assume that type information starts with a digit, '-', or '(' in
1231 deciding whether to call read_type. */
1234 read_type (pp
, objfile
)
1236 struct objfile
*objfile
;
1238 register struct type
*type
= 0;
1242 char type_descriptor
;
1244 /* Read type number if present. The type number may be omitted.
1245 for instance in a two-dimensional array declared with type
1246 "ar1;1;10;ar1;1;10;4". */
1247 if ((**pp
>= '0' && **pp
<= '9')
1250 if (read_type_number (pp
, typenums
) != 0)
1251 return error_type (pp
);
1253 /* Type is not being defined here. Either it already exists,
1254 or this is a forward reference to it. dbx_alloc_type handles
1257 return dbx_alloc_type (typenums
, objfile
);
1259 /* Type is being defined here. */
1266 /* It might be a type attribute or a member type. */
1267 if (isdigit (*p
) || *p
== '(' || *p
== '-')
1272 /* Type attributes; skip to the semicolon. */
1273 while (*p
!= ';' && *p
!= '\0')
1277 return error_type (pp
);
1279 /* Skip the semicolon. */
1283 /* Skip the type descriptor, we get it below with (*pp)[-1]. */
1288 /* 'typenums=' not present, type is anonymous. Read and return
1289 the definition, but don't put it in the type vector. */
1290 typenums
[0] = typenums
[1] = -1;
1294 type_descriptor
= (*pp
)[-1];
1295 switch (type_descriptor
)
1299 enum type_code code
;
1301 /* Used to index through file_symbols. */
1302 struct pending
*ppt
;
1305 /* Name including "struct", etc. */
1308 /* Name without "struct", etc. */
1309 char *type_name_only
;
1315 /* Set the type code according to the following letter. */
1319 code
= TYPE_CODE_STRUCT
;
1323 code
= TYPE_CODE_UNION
;
1327 code
= TYPE_CODE_ENUM
;
1331 return error_type (pp
);
1334 to
= type_name
= (char *)
1335 obstack_alloc (&objfile
-> type_obstack
,
1337 ((char *) strchr (*pp
, ':') - (*pp
)) + 1));
1339 /* Copy the prefix. */
1341 while ((*to
++ = *from
++) != '\0')
1345 type_name_only
= to
;
1347 /* Copy the name. */
1349 while ((*to
++ = *from
++) != ':')
1353 /* Set the pointer ahead of the name which we just read. */
1357 /* The following hack is clearly wrong, because it doesn't
1358 check whether we are in a baseclass. I tried to reproduce
1359 the case that it is trying to fix, but I couldn't get
1360 g++ to put out a cross reference to a basetype. Perhaps
1361 it doesn't do it anymore. */
1362 /* Note: for C++, the cross reference may be to a base type which
1363 has not yet been seen. In this case, we skip to the comma,
1364 which will mark the end of the base class name. (The ':'
1365 at the end of the base class name will be skipped as well.)
1366 But sometimes (ie. when the cross ref is the last thing on
1367 the line) there will be no ','. */
1368 from
= (char *) strchr (*pp
, ',');
1374 /* Now check to see whether the type has already been declared. */
1375 /* This is necessary at least in the case where the
1376 program says something like
1378 The compiler puts out a cross-reference; we better find
1379 set the length of the structure correctly so we can
1380 set the length of the array. */
1381 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1382 for (i
= 0; i
< ppt
->nsyms
; i
++)
1384 struct symbol
*sym
= ppt
->symbol
[i
];
1386 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1387 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1388 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1389 && STREQ (SYMBOL_NAME (sym
), type_name_only
))
1391 obstack_free (&objfile
-> type_obstack
, type_name
);
1392 type
= SYMBOL_TYPE (sym
);
1397 /* Didn't find the type to which this refers, so we must
1398 be dealing with a forward reference. Allocate a type
1399 structure for it, and keep track of it so we can
1400 fill in the rest of the fields when we get the full
1402 type
= dbx_alloc_type (typenums
, objfile
);
1403 TYPE_CODE (type
) = code
;
1404 TYPE_NAME (type
) = type_name
;
1405 INIT_CPLUS_SPECIFIC(type
);
1406 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1408 add_undefined_type (type
);
1412 case '-': /* RS/6000 built-in type */
1425 /* The type is being defined to another type. When we support
1426 Ada (and arguably for C, so "whatis foo" can give "size_t",
1427 "wchar_t", or whatever it was declared as) we'll need to
1428 allocate a distinct type here rather than returning the
1429 existing one. GCC is currently (deliberately) incapable of
1430 putting out the debugging information to do that, however. */
1433 if (read_type_number (pp
, xtypenums
) != 0)
1434 return error_type (pp
);
1435 if (typenums
[0] == xtypenums
[0] && typenums
[1] == xtypenums
[1])
1436 /* It's being defined as itself. That means it is "void". */
1437 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, objfile
);
1439 type
= *dbx_lookup_type (xtypenums
);
1440 if (typenums
[0] != -1)
1441 *dbx_lookup_type (typenums
) = type
;
1442 /* This can happen if we had '-' followed by a garbage character,
1445 return error_type (pp
);
1448 /* In the following types, we must be sure to overwrite any existing
1449 type that the typenums refer to, rather than allocating a new one
1450 and making the typenums point to the new one. This is because there
1451 may already be pointers to the existing type (if it had been
1452 forward-referenced), and we must change it to a pointer, function,
1453 reference, or whatever, *in-place*. */
1456 type1
= read_type (pp
, objfile
);
1457 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1460 case '&': /* Reference to another type */
1461 type1
= read_type (pp
, objfile
);
1462 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1465 case 'f': /* Function returning another type */
1466 type1
= read_type (pp
, objfile
);
1467 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1470 case 'k': /* Const qualifier on some type (Sun) */
1471 type
= read_type (pp
, objfile
);
1472 /* FIXME! For now, we ignore const and volatile qualifiers. */
1475 case 'B': /* Volatile qual on some type (Sun) */
1476 type
= read_type (pp
, objfile
);
1477 /* FIXME! For now, we ignore const and volatile qualifiers. */
1480 /* FIXME -- we should be doing smash_to_XXX types here. */
1481 case '@': /* Member (class & variable) type */
1483 struct type
*domain
= read_type (pp
, objfile
);
1484 struct type
*memtype
;
1487 /* Invalid member type data format. */
1488 return error_type (pp
);
1491 memtype
= read_type (pp
, objfile
);
1492 type
= dbx_alloc_type (typenums
, objfile
);
1493 smash_to_member_type (type
, domain
, memtype
);
1497 case '#': /* Method (class & fn) type */
1498 if ((*pp
)[0] == '#')
1500 /* We'll get the parameter types from the name. */
1501 struct type
*return_type
;
1504 return_type
= read_type (pp
, objfile
);
1505 if (*(*pp
)++ != ';')
1506 complain (&invalid_member_complaint
, symnum
);
1507 type
= allocate_stub_method (return_type
);
1508 if (typenums
[0] != -1)
1509 *dbx_lookup_type (typenums
) = type
;
1513 struct type
*domain
= read_type (pp
, objfile
);
1514 struct type
*return_type
;
1518 /* Invalid member type data format. */
1519 return error_type (pp
);
1523 return_type
= read_type (pp
, objfile
);
1524 args
= read_args (pp
, ';', objfile
);
1525 type
= dbx_alloc_type (typenums
, objfile
);
1526 smash_to_method_type (type
, domain
, return_type
, args
);
1530 case 'r': /* Range type */
1531 type
= read_range_type (pp
, typenums
, objfile
);
1532 if (typenums
[0] != -1)
1533 *dbx_lookup_type (typenums
) = type
;
1536 case 'b': /* Sun ACC builtin int type */
1537 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
1538 if (typenums
[0] != -1)
1539 *dbx_lookup_type (typenums
) = type
;
1542 case 'R': /* Sun ACC builtin float type */
1543 type
= read_sun_floating_type (pp
, typenums
, objfile
);
1544 if (typenums
[0] != -1)
1545 *dbx_lookup_type (typenums
) = type
;
1548 case 'e': /* Enumeration type */
1549 type
= dbx_alloc_type (typenums
, objfile
);
1550 type
= read_enum_type (pp
, type
, objfile
);
1551 if (typenums
[0] != -1)
1552 *dbx_lookup_type (typenums
) = type
;
1555 case 's': /* Struct type */
1556 case 'u': /* Union type */
1557 type
= dbx_alloc_type (typenums
, objfile
);
1558 if (!TYPE_NAME (type
))
1560 TYPE_NAME (type
) = type_synonym_name
;
1562 type_synonym_name
= NULL
;
1563 switch (type_descriptor
)
1566 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1569 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1572 type
= read_struct_type (pp
, type
, objfile
);
1575 case 'a': /* Array type */
1577 return error_type (pp
);
1580 type
= dbx_alloc_type (typenums
, objfile
);
1581 type
= read_array_type (pp
, type
, objfile
);
1585 --*pp
; /* Go back to the symbol in error */
1586 /* Particularly important if it was \0! */
1587 return error_type (pp
);
1592 warning ("GDB internal error, type is NULL in stabsread.c\n");
1593 return error_type (pp
);
1599 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
1600 Return the proper type node for a given builtin type number. */
1602 static struct type
*
1603 rs6000_builtin_type (typenum
)
1606 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
1607 #define NUMBER_RECOGNIZED 30
1608 /* This includes an empty slot for type number -0. */
1609 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
1610 struct type
*rettype
;
1612 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
1614 complain (&rs6000_builtin_complaint
, typenum
);
1615 return builtin_type_error
;
1617 if (negative_types
[-typenum
] != NULL
)
1618 return negative_types
[-typenum
];
1620 #if TARGET_CHAR_BIT != 8
1621 #error This code wrong for TARGET_CHAR_BIT not 8
1622 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
1623 that if that ever becomes not true, the correct fix will be to
1624 make the size in the struct type to be in bits, not in units of
1631 /* The size of this and all the other types are fixed, defined
1632 by the debugging format. If there is a type called "int" which
1633 is other than 32 bits, then it should use a new negative type
1634 number (or avoid negative type numbers for that case).
1635 See stabs.texinfo. */
1636 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
1639 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
1642 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
1645 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
1648 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
1649 "unsigned char", NULL
);
1652 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
1655 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
1656 "unsigned short", NULL
);
1659 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1660 "unsigned int", NULL
);
1663 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1666 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1667 "unsigned long", NULL
);
1670 rettype
= init_type (TYPE_CODE_VOID
, 0, 0, "void", NULL
);
1673 /* IEEE single precision (32 bit). */
1674 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
1677 /* IEEE double precision (64 bit). */
1678 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
1681 /* This is an IEEE double on the RS/6000, and different machines with
1682 different sizes for "long double" should use different negative
1683 type numbers. See stabs.texinfo. */
1684 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
1687 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
1690 rettype
= init_type (TYPE_CODE_BOOL
, 4, 0, "boolean", NULL
);
1693 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
1696 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
1699 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
1702 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
1706 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
1710 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
1714 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1718 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1722 /* Complex type consisting of two IEEE single precision values. */
1723 rettype
= init_type (TYPE_CODE_ERROR
, 8, 0, "complex", NULL
);
1726 /* Complex type consisting of two IEEE double precision values. */
1727 rettype
= init_type (TYPE_CODE_ERROR
, 16, 0, "double complex", NULL
);
1730 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
1733 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
1736 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
1739 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
1742 negative_types
[-typenum
] = rettype
;
1746 /* This page contains subroutines of read_type. */
1748 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1749 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1750 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1752 /* Read member function stabs info for C++ classes. The form of each member
1755 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1757 An example with two member functions is:
1759 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1761 For the case of overloaded operators, the format is op$::*.funcs, where
1762 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1763 name (such as `+=') and `.' marks the end of the operator name.
1765 Returns 1 for success, 0 for failure. */
1768 read_member_functions (fip
, pp
, type
, objfile
)
1769 struct field_info
*fip
;
1772 struct objfile
*objfile
;
1776 /* Total number of member functions defined in this class. If the class
1777 defines two `f' functions, and one `g' function, then this will have
1779 int total_length
= 0;
1783 struct next_fnfield
*next
;
1784 struct fn_field fn_field
;
1786 struct type
*look_ahead_type
;
1787 struct next_fnfieldlist
*new_fnlist
;
1788 struct next_fnfield
*new_sublist
;
1792 /* Process each list until we find something that is not a member function
1793 or find the end of the functions. */
1797 /* We should be positioned at the start of the function name.
1798 Scan forward to find the first ':' and if it is not the
1799 first of a "::" delimiter, then this is not a member function. */
1811 look_ahead_type
= NULL
;
1814 new_fnlist
= (struct next_fnfieldlist
*)
1815 xmalloc (sizeof (struct next_fnfieldlist
));
1816 make_cleanup (free
, new_fnlist
);
1817 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
1819 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
1821 /* This is a completely wierd case. In order to stuff in the
1822 names that might contain colons (the usual name delimiter),
1823 Mike Tiemann defined a different name format which is
1824 signalled if the identifier is "op$". In that case, the
1825 format is "op$::XXXX." where XXXX is the name. This is
1826 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1827 /* This lets the user type "break operator+".
1828 We could just put in "+" as the name, but that wouldn't
1830 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
1831 char *o
= opname
+ 3;
1833 /* Skip past '::'. */
1836 STABS_CONTINUE (pp
);
1842 main_fn_name
= savestring (opname
, o
- opname
);
1848 main_fn_name
= savestring (*pp
, p
- *pp
);
1849 /* Skip past '::'. */
1852 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
1857 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
1858 make_cleanup (free
, new_sublist
);
1859 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
1861 /* Check for and handle cretinous dbx symbol name continuation! */
1862 if (look_ahead_type
== NULL
)
1865 STABS_CONTINUE (pp
);
1867 new_sublist
-> fn_field
.type
= read_type (pp
, objfile
);
1870 /* Invalid symtab info for member function. */
1876 /* g++ version 1 kludge */
1877 new_sublist
-> fn_field
.type
= look_ahead_type
;
1878 look_ahead_type
= NULL
;
1888 /* If this is just a stub, then we don't have the real name here. */
1890 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
1892 if (!TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
))
1893 TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
) = type
;
1894 new_sublist
-> fn_field
.is_stub
= 1;
1896 new_sublist
-> fn_field
.physname
= savestring (*pp
, p
- *pp
);
1899 /* Set this member function's visibility fields. */
1902 case VISIBILITY_PRIVATE
:
1903 new_sublist
-> fn_field
.is_private
= 1;
1905 case VISIBILITY_PROTECTED
:
1906 new_sublist
-> fn_field
.is_protected
= 1;
1910 STABS_CONTINUE (pp
);
1913 case 'A': /* Normal functions. */
1914 new_sublist
-> fn_field
.is_const
= 0;
1915 new_sublist
-> fn_field
.is_volatile
= 0;
1918 case 'B': /* `const' member functions. */
1919 new_sublist
-> fn_field
.is_const
= 1;
1920 new_sublist
-> fn_field
.is_volatile
= 0;
1923 case 'C': /* `volatile' member function. */
1924 new_sublist
-> fn_field
.is_const
= 0;
1925 new_sublist
-> fn_field
.is_volatile
= 1;
1928 case 'D': /* `const volatile' member function. */
1929 new_sublist
-> fn_field
.is_const
= 1;
1930 new_sublist
-> fn_field
.is_volatile
= 1;
1933 case '*': /* File compiled with g++ version 1 -- no info */
1938 complain (&const_vol_complaint
, **pp
);
1947 /* virtual member function, followed by index.
1948 The sign bit is set to distinguish pointers-to-methods
1949 from virtual function indicies. Since the array is
1950 in words, the quantity must be shifted left by 1
1951 on 16 bit machine, and by 2 on 32 bit machine, forcing
1952 the sign bit out, and usable as a valid index into
1953 the array. Remove the sign bit here. */
1954 new_sublist
-> fn_field
.voffset
=
1955 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
1959 STABS_CONTINUE (pp
);
1960 if (**pp
== ';' || **pp
== '\0')
1962 /* Must be g++ version 1. */
1963 new_sublist
-> fn_field
.fcontext
= 0;
1967 /* Figure out from whence this virtual function came.
1968 It may belong to virtual function table of
1969 one of its baseclasses. */
1970 look_ahead_type
= read_type (pp
, objfile
);
1973 /* g++ version 1 overloaded methods. */
1977 new_sublist
-> fn_field
.fcontext
= look_ahead_type
;
1986 look_ahead_type
= NULL
;
1992 /* static member function. */
1993 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
1994 if (strncmp (new_sublist
-> fn_field
.physname
,
1995 main_fn_name
, strlen (main_fn_name
)))
1997 new_sublist
-> fn_field
.is_stub
= 1;
2003 complain (&member_fn_complaint
, (*pp
)[-1]);
2004 /* Fall through into normal member function. */
2007 /* normal member function. */
2008 new_sublist
-> fn_field
.voffset
= 0;
2009 new_sublist
-> fn_field
.fcontext
= 0;
2013 new_sublist
-> next
= sublist
;
2014 sublist
= new_sublist
;
2016 STABS_CONTINUE (pp
);
2018 while (**pp
!= ';' && **pp
!= '\0');
2022 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
2023 obstack_alloc (&objfile
-> type_obstack
,
2024 sizeof (struct fn_field
) * length
);
2025 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
2026 sizeof (struct fn_field
) * length
);
2027 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
2029 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
2032 new_fnlist
-> fn_fieldlist
.length
= length
;
2033 new_fnlist
-> next
= fip
-> fnlist
;
2034 fip
-> fnlist
= new_fnlist
;
2036 total_length
+= length
;
2037 STABS_CONTINUE (pp
);
2042 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2043 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2044 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
2045 memset (TYPE_FN_FIELDLISTS (type
), 0,
2046 sizeof (struct fn_fieldlist
) * nfn_fields
);
2047 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2048 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2054 /* Special GNU C++ name.
2056 Returns 1 for success, 0 for failure. "failure" means that we can't
2057 keep parsing and it's time for error_type(). */
2060 read_cpp_abbrev (fip
, pp
, type
, objfile
)
2061 struct field_info
*fip
;
2064 struct objfile
*objfile
;
2070 struct type
*context
;
2080 /* At this point, *pp points to something like "22:23=*22...",
2081 where the type number before the ':' is the "context" and
2082 everything after is a regular type definition. Lookup the
2083 type, find it's name, and construct the field name. */
2085 context
= read_type (pp
, objfile
);
2089 case 'f': /* $vf -- a virtual function table pointer */
2090 fip
->list
->field
.name
=
2091 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
2094 case 'b': /* $vb -- a virtual bsomethingorother */
2095 name
= type_name_no_tag (context
);
2098 complain (&invalid_cpp_type_complaint
, symnum
);
2101 fip
->list
->field
.name
=
2102 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
2106 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2107 fip
->list
->field
.name
=
2108 obconcat (&objfile
->type_obstack
,
2109 "INVALID_CPLUSPLUS_ABBREV", "", "");
2113 /* At this point, *pp points to the ':'. Skip it and read the
2119 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2122 fip
->list
->field
.type
= read_type (pp
, objfile
);
2124 (*pp
)++; /* Skip the comma. */
2130 fip
->list
->field
.bitpos
= read_huge_number (pp
, ';', &nbits
);
2134 /* This field is unpacked. */
2135 fip
->list
->field
.bitsize
= 0;
2136 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
2140 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2141 /* We have no idea what syntax an unrecognized abbrev would have, so
2142 better return 0. If we returned 1, we would need to at least advance
2143 *pp to avoid an infinite loop. */
2150 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
2151 struct field_info
*fip
;
2155 struct objfile
*objfile
;
2157 fip
-> list
-> field
.name
=
2158 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2161 /* This means we have a visibility for a field coming. */
2165 fip
-> list
-> visibility
= *(*pp
)++;
2166 switch (fip
-> list
-> visibility
)
2168 case VISIBILITY_PRIVATE
:
2169 case VISIBILITY_PROTECTED
:
2172 case VISIBILITY_PUBLIC
:
2177 /* Unknown visibility specifier. */
2178 complain (&stabs_general_complaint
,
2179 "unknown visibility specifier");
2186 /* normal dbx-style format, no explicit visibility */
2187 fip
-> list
-> visibility
= VISIBILITY_PUBLIC
;
2190 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
2195 /* Possible future hook for nested types. */
2198 fip
-> list
-> field
.bitpos
= (long)-2; /* nested type */
2204 /* Static class member. */
2205 fip
-> list
-> field
.bitpos
= (long) -1;
2211 fip
-> list
-> field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2215 else if (**pp
!= ',')
2217 /* Bad structure-type format. */
2218 complain (&stabs_general_complaint
, "bad structure-type format");
2222 (*pp
)++; /* Skip the comma. */
2226 fip
-> list
-> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2229 complain (&stabs_general_complaint
, "bad structure-type format");
2232 fip
-> list
-> field
.bitsize
= read_huge_number (pp
, ';', &nbits
);
2235 complain (&stabs_general_complaint
, "bad structure-type format");
2240 /* FIXME-tiemann: Can't the compiler put out something which
2241 lets us distinguish these? (or maybe just not put out anything
2242 for the field). What is the story here? What does the compiler
2243 really do? Also, patch gdb.texinfo for this case; I document
2244 it as a possible problem there. Search for "DBX-style". */
2246 /* This is wrong because this is identical to the symbols
2247 produced for GCC 0-size arrays. For example:
2252 The code which dumped core in such circumstances should be
2253 fixed not to dump core. */
2255 /* g++ -g0 can put out bitpos & bitsize zero for a static
2256 field. This does not give us any way of getting its
2257 class, so we can't know its name. But we can just
2258 ignore the field so we don't dump core and other nasty
2260 if (fip
-> list
-> field
.bitpos
== 0 && fip
-> list
-> field
.bitsize
== 0)
2262 complain (&dbx_class_complaint
);
2263 /* Ignore this field. */
2264 fip
-> list
= fip
-> list
-> next
;
2269 /* Detect an unpacked field and mark it as such.
2270 dbx gives a bit size for all fields.
2271 Note that forward refs cannot be packed,
2272 and treat enums as if they had the width of ints. */
2274 if (TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_INT
2275 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_ENUM
)
2277 fip
-> list
-> field
.bitsize
= 0;
2279 if ((fip
-> list
-> field
.bitsize
2280 == TARGET_CHAR_BIT
* TYPE_LENGTH (fip
-> list
-> field
.type
)
2281 || (TYPE_CODE (fip
-> list
-> field
.type
) == TYPE_CODE_ENUM
2282 && (fip
-> list
-> field
.bitsize
2287 fip
-> list
-> field
.bitpos
% 8 == 0)
2289 fip
-> list
-> field
.bitsize
= 0;
2295 /* Read struct or class data fields. They have the form:
2297 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2299 At the end, we see a semicolon instead of a field.
2301 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2304 The optional VISIBILITY is one of:
2306 '/0' (VISIBILITY_PRIVATE)
2307 '/1' (VISIBILITY_PROTECTED)
2308 '/2' (VISIBILITY_PUBLIC)
2310 or nothing, for C style fields with public visibility.
2312 Returns 1 for success, 0 for failure. */
2315 read_struct_fields (fip
, pp
, type
, objfile
)
2316 struct field_info
*fip
;
2319 struct objfile
*objfile
;
2322 struct nextfield
*new;
2324 /* We better set p right now, in case there are no fields at all... */
2328 /* Read each data member type until we find the terminating ';' at the end of
2329 the data member list, or break for some other reason such as finding the
2330 start of the member function list. */
2334 STABS_CONTINUE (pp
);
2335 /* Get space to record the next field's data. */
2336 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2337 make_cleanup (free
, new);
2338 memset (new, 0, sizeof (struct nextfield
));
2339 new -> next
= fip
-> list
;
2342 /* Get the field name. */
2344 /* If is starts with CPLUS_MARKER it is a special abbreviation, unless
2345 the CPLUS_MARKER is followed by an underscore, in which case it is
2346 just the name of an anonymous type, which we should handle like any
2348 if (*p
== CPLUS_MARKER
&& p
[1] != '_')
2350 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
2355 /* Look for the ':' that separates the field name from the field
2356 values. Data members are delimited by a single ':', while member
2357 functions are delimited by a pair of ':'s. When we hit the member
2358 functions (if any), terminate scan loop and return. */
2360 while (*p
!= ':' && *p
!= '\0')
2367 /* Check to see if we have hit the member functions yet. */
2372 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
2376 /* chill the list of fields: the last entry (at the head) is a
2377 partially constructed entry which we now scrub. */
2378 fip
-> list
= fip
-> list
-> next
;
2383 /* The stabs for C++ derived classes contain baseclass information which
2384 is marked by a '!' character after the total size. This function is
2385 called when we encounter the baseclass marker, and slurps up all the
2386 baseclass information.
2388 Immediately following the '!' marker is the number of base classes that
2389 the class is derived from, followed by information for each base class.
2390 For each base class, there are two visibility specifiers, a bit offset
2391 to the base class information within the derived class, a reference to
2392 the type for the base class, and a terminating semicolon.
2394 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2396 Baseclass information marker __________________|| | | | | | |
2397 Number of baseclasses __________________________| | | | | | |
2398 Visibility specifiers (2) ________________________| | | | | |
2399 Offset in bits from start of class _________________| | | | |
2400 Type number for base class ___________________________| | | |
2401 Visibility specifiers (2) _______________________________| | |
2402 Offset in bits from start of class ________________________| |
2403 Type number of base class ____________________________________|
2405 Return 1 for success, 0 for (error-type-inducing) failure. */
2408 read_baseclasses (fip
, pp
, type
, objfile
)
2409 struct field_info
*fip
;
2412 struct objfile
*objfile
;
2415 struct nextfield
*new;
2423 /* Skip the '!' baseclass information marker. */
2427 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2430 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
2436 /* Some stupid compilers have trouble with the following, so break
2437 it up into simpler expressions. */
2438 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
2439 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
2442 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
2445 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2446 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2450 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
2452 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
2454 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2455 make_cleanup (free
, new);
2456 memset (new, 0, sizeof (struct nextfield
));
2457 new -> next
= fip
-> list
;
2459 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
2461 STABS_CONTINUE (pp
);
2465 /* Nothing to do. */
2468 SET_TYPE_FIELD_VIRTUAL (type
, i
);
2471 /* Bad visibility format. */
2475 new -> visibility
= *(*pp
)++;
2476 switch (new -> visibility
)
2478 case VISIBILITY_PRIVATE
:
2479 case VISIBILITY_PROTECTED
:
2480 case VISIBILITY_PUBLIC
:
2483 /* Bad visibility format. */
2490 /* The remaining value is the bit offset of the portion of the object
2491 corresponding to this baseclass. Always zero in the absence of
2492 multiple inheritance. */
2494 new -> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2499 /* The last piece of baseclass information is the type of the
2500 base class. Read it, and remember it's type name as this
2503 new -> field
.type
= read_type (pp
, objfile
);
2504 new -> field
.name
= type_name_no_tag (new -> field
.type
);
2506 /* skip trailing ';' and bump count of number of fields seen */
2515 /* The tail end of stabs for C++ classes that contain a virtual function
2516 pointer contains a tilde, a %, and a type number.
2517 The type number refers to the base class (possibly this class itself) which
2518 contains the vtable pointer for the current class.
2520 This function is called when we have parsed all the method declarations,
2521 so we can look for the vptr base class info. */
2524 read_tilde_fields (fip
, pp
, type
, objfile
)
2525 struct field_info
*fip
;
2528 struct objfile
*objfile
;
2532 STABS_CONTINUE (pp
);
2534 /* If we are positioned at a ';', then skip it. */
2544 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2546 /* Obsolete flags that used to indicate the presence
2547 of constructors and/or destructors. */
2551 /* Read either a '%' or the final ';'. */
2552 if (*(*pp
)++ == '%')
2554 /* The next number is the type number of the base class
2555 (possibly our own class) which supplies the vtable for
2556 this class. Parse it out, and search that class to find
2557 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
2558 and TYPE_VPTR_FIELDNO. */
2563 t
= read_type (pp
, objfile
);
2565 while (*p
!= '\0' && *p
!= ';')
2571 /* Premature end of symbol. */
2575 TYPE_VPTR_BASETYPE (type
) = t
;
2576 if (type
== t
) /* Our own class provides vtbl ptr */
2578 for (i
= TYPE_NFIELDS (t
) - 1;
2579 i
>= TYPE_N_BASECLASSES (t
);
2582 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2583 sizeof (vptr_name
) - 1))
2585 TYPE_VPTR_FIELDNO (type
) = i
;
2589 /* Virtual function table field not found. */
2590 complain (&vtbl_notfound_complaint
, TYPE_NAME (type
));
2595 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2606 attach_fn_fields_to_type (fip
, type
)
2607 struct field_info
*fip
;
2608 register struct type
*type
;
2612 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2614 if (TYPE_CODE (TYPE_BASECLASS (type
, n
)) == TYPE_CODE_UNDEF
)
2616 /* @@ Memory leak on objfile -> type_obstack? */
2619 TYPE_NFN_FIELDS_TOTAL (type
) +=
2620 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, n
));
2623 for (n
= TYPE_NFN_FIELDS (type
);
2624 fip
-> fnlist
!= NULL
;
2625 fip
-> fnlist
= fip
-> fnlist
-> next
)
2627 --n
; /* Circumvent Sun3 compiler bug */
2628 TYPE_FN_FIELDLISTS (type
)[n
] = fip
-> fnlist
-> fn_fieldlist
;
2633 /* Create the vector of fields, and record how big it is.
2634 We need this info to record proper virtual function table information
2635 for this class's virtual functions. */
2638 attach_fields_to_type (fip
, type
, objfile
)
2639 struct field_info
*fip
;
2640 register struct type
*type
;
2641 struct objfile
*objfile
;
2643 register int nfields
= 0;
2644 register int non_public_fields
= 0;
2645 register struct nextfield
*scan
;
2647 /* Count up the number of fields that we have, as well as taking note of
2648 whether or not there are any non-public fields, which requires us to
2649 allocate and build the private_field_bits and protected_field_bits
2652 for (scan
= fip
-> list
; scan
!= NULL
; scan
= scan
-> next
)
2655 if (scan
-> visibility
!= VISIBILITY_PUBLIC
)
2657 non_public_fields
++;
2661 /* Now we know how many fields there are, and whether or not there are any
2662 non-public fields. Record the field count, allocate space for the
2663 array of fields, and create blank visibility bitfields if necessary. */
2665 TYPE_NFIELDS (type
) = nfields
;
2666 TYPE_FIELDS (type
) = (struct field
*)
2667 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2668 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2670 if (non_public_fields
)
2672 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2674 TYPE_FIELD_PRIVATE_BITS (type
) =
2675 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2676 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2678 TYPE_FIELD_PROTECTED_BITS (type
) =
2679 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2680 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2683 /* Copy the saved-up fields into the field vector. Start from the head
2684 of the list, adding to the tail of the field array, so that they end
2685 up in the same order in the array in which they were added to the list. */
2687 while (nfields
-- > 0)
2689 TYPE_FIELD (type
, nfields
) = fip
-> list
-> field
;
2690 switch (fip
-> list
-> visibility
)
2692 case VISIBILITY_PRIVATE
:
2693 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2696 case VISIBILITY_PROTECTED
:
2697 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2700 case VISIBILITY_PUBLIC
:
2704 /* Should warn about this unknown visibility? */
2707 fip
-> list
= fip
-> list
-> next
;
2712 /* Read the description of a structure (or union type) and return an object
2713 describing the type.
2715 PP points to a character pointer that points to the next unconsumed token
2716 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2717 *PP will point to "4a:1,0,32;;".
2719 TYPE points to an incomplete type that needs to be filled in.
2721 OBJFILE points to the current objfile from which the stabs information is
2722 being read. (Note that it is redundant in that TYPE also contains a pointer
2723 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2726 static struct type
*
2727 read_struct_type (pp
, type
, objfile
)
2730 struct objfile
*objfile
;
2732 struct cleanup
*back_to
;
2733 struct field_info fi
;
2738 back_to
= make_cleanup (null_cleanup
, 0);
2740 INIT_CPLUS_SPECIFIC (type
);
2741 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2743 /* First comes the total size in bytes. */
2747 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
2749 return error_type (pp
);
2752 /* Now read the baseclasses, if any, read the regular C struct or C++
2753 class member fields, attach the fields to the type, read the C++
2754 member functions, attach them to the type, and then read any tilde
2755 field (baseclass specifier for the class holding the main vtable). */
2757 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
2758 || !read_struct_fields (&fi
, pp
, type
, objfile
)
2759 || !attach_fields_to_type (&fi
, type
, objfile
)
2760 || !read_member_functions (&fi
, pp
, type
, objfile
)
2761 || !attach_fn_fields_to_type (&fi
, type
)
2762 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
2764 do_cleanups (back_to
);
2765 return (error_type (pp
));
2768 do_cleanups (back_to
);
2772 /* Read a definition of an array type,
2773 and create and return a suitable type object.
2774 Also creates a range type which represents the bounds of that
2777 static struct type
*
2778 read_array_type (pp
, type
, objfile
)
2780 register struct type
*type
;
2781 struct objfile
*objfile
;
2783 struct type
*index_type
, *element_type
, *range_type
;
2788 /* Format of an array type:
2789 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2792 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2793 for these, produce a type like float[][]. */
2795 index_type
= read_type (pp
, objfile
);
2797 /* Improper format of array type decl. */
2798 return error_type (pp
);
2801 if (!(**pp
>= '0' && **pp
<= '9'))
2806 lower
= read_huge_number (pp
, ';', &nbits
);
2808 return error_type (pp
);
2810 if (!(**pp
>= '0' && **pp
<= '9'))
2815 upper
= read_huge_number (pp
, ';', &nbits
);
2817 return error_type (pp
);
2819 element_type
= read_type (pp
, objfile
);
2828 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
2829 type
= create_array_type (type
, element_type
, range_type
);
2831 /* If we have an array whose element type is not yet known, but whose
2832 bounds *are* known, record it to be adjusted at the end of the file. */
2834 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2836 add_undefined_type (type
);
2843 /* Read a definition of an enumeration type,
2844 and create and return a suitable type object.
2845 Also defines the symbols that represent the values of the type. */
2847 static struct type
*
2848 read_enum_type (pp
, type
, objfile
)
2850 register struct type
*type
;
2851 struct objfile
*objfile
;
2856 register struct symbol
*sym
;
2858 struct pending
**symlist
;
2859 struct pending
*osyms
, *syms
;
2863 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2864 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2865 to do? For now, force all enum values to file scope. */
2866 if (within_function
)
2867 symlist
= &local_symbols
;
2870 symlist
= &file_symbols
;
2872 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2874 /* Read the value-names and their values.
2875 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2876 A semicolon or comma instead of a NAME means the end. */
2877 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2880 STABS_CONTINUE (pp
);
2882 while (*p
!= ':') p
++;
2883 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
2885 n
= read_huge_number (pp
, ',', &nbits
);
2887 return error_type (pp
);
2889 sym
= (struct symbol
*)
2890 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
2891 memset (sym
, 0, sizeof (struct symbol
));
2892 SYMBOL_NAME (sym
) = name
;
2893 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
2894 SYMBOL_CLASS (sym
) = LOC_CONST
;
2895 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2896 SYMBOL_VALUE (sym
) = n
;
2897 add_symbol_to_list (sym
, symlist
);
2902 (*pp
)++; /* Skip the semicolon. */
2904 /* Now fill in the fields of the type-structure. */
2906 TYPE_LENGTH (type
) = sizeof (int);
2907 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2908 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2909 TYPE_NFIELDS (type
) = nsyms
;
2910 TYPE_FIELDS (type
) = (struct field
*)
2911 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
2912 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
2914 /* Find the symbols for the values and put them into the type.
2915 The symbols can be found in the symlist that we put them on
2916 to cause them to be defined. osyms contains the old value
2917 of that symlist; everything up to there was defined by us. */
2918 /* Note that we preserve the order of the enum constants, so
2919 that in something like "enum {FOO, LAST_THING=FOO}" we print
2920 FOO, not LAST_THING. */
2922 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2927 for (; j
< syms
->nsyms
; j
++,n
++)
2929 struct symbol
*xsym
= syms
->symbol
[j
];
2930 SYMBOL_TYPE (xsym
) = type
;
2931 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2932 TYPE_FIELD_VALUE (type
, n
) = 0;
2933 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2934 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2941 /* This screws up perfectly good C programs with enums. FIXME. */
2942 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2943 if(TYPE_NFIELDS(type
) == 2 &&
2944 ((STREQ(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2945 STREQ(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2946 (STREQ(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2947 STREQ(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2948 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2954 /* Sun's ACC uses a somewhat saner method for specifying the builtin
2955 typedefs in every file (for int, long, etc):
2957 type = b <signed> <width>; <offset>; <nbits>
2958 signed = u or s. Possible c in addition to u or s (for char?).
2959 offset = offset from high order bit to start bit of type.
2960 width is # bytes in object of this type, nbits is # bits in type.
2962 The width/offset stuff appears to be for small objects stored in
2963 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
2966 static struct type
*
2967 read_sun_builtin_type (pp
, typenums
, objfile
)
2970 struct objfile
*objfile
;
2985 return error_type (pp
);
2989 /* For some odd reason, all forms of char put a c here. This is strange
2990 because no other type has this honor. We can safely ignore this because
2991 we actually determine 'char'acterness by the number of bits specified in
2997 /* The first number appears to be the number of bytes occupied
2998 by this type, except that unsigned short is 4 instead of 2.
2999 Since this information is redundant with the third number,
3000 we will ignore it. */
3001 read_huge_number (pp
, ';', &nbits
);
3003 return error_type (pp
);
3005 /* The second number is always 0, so ignore it too. */
3006 read_huge_number (pp
, ';', &nbits
);
3008 return error_type (pp
);
3010 /* The third number is the number of bits for this type. */
3011 type_bits
= read_huge_number (pp
, 0, &nbits
);
3013 return error_type (pp
);
3016 /* FIXME. Here we should just be able to make a type of the right
3017 number of bits and signedness. FIXME. */
3019 if (type_bits
== TARGET_LONG_LONG_BIT
)
3020 return (lookup_fundamental_type (objfile
,
3021 signed_type
? FT_LONG_LONG
: FT_UNSIGNED_LONG_LONG
));
3023 if (type_bits
== TARGET_INT_BIT
)
3025 /* FIXME -- the only way to distinguish `int' from `long'
3026 is to look at its name! */
3029 if (long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
3030 return lookup_fundamental_type (objfile
, FT_LONG
);
3032 return lookup_fundamental_type (objfile
, FT_INTEGER
);
3036 if (long_kludge_name
3037 && ((long_kludge_name
[0] == 'u' /* unsigned */ &&
3038 long_kludge_name
[9] == 'l' /* long */)
3039 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
3040 return lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
);
3042 return lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
3046 if (type_bits
== TARGET_SHORT_BIT
)
3047 return (lookup_fundamental_type (objfile
,
3048 signed_type
? FT_SHORT
: FT_UNSIGNED_SHORT
));
3050 if (type_bits
== TARGET_CHAR_BIT
)
3051 return (lookup_fundamental_type (objfile
,
3052 signed_type
? FT_CHAR
: FT_UNSIGNED_CHAR
));
3055 return lookup_fundamental_type (objfile
, FT_VOID
);
3057 return error_type (pp
);
3059 return init_type (type_bits
== 0 ? TYPE_CODE_VOID
: TYPE_CODE_INT
,
3060 type_bits
/ TARGET_CHAR_BIT
,
3061 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3066 static struct type
*
3067 read_sun_floating_type (pp
, typenums
, objfile
)
3070 struct objfile
*objfile
;
3076 /* The first number has more details about the type, for example
3078 details
= read_huge_number (pp
, ';', &nbits
);
3080 return error_type (pp
);
3082 /* The second number is the number of bytes occupied by this type */
3083 nbytes
= read_huge_number (pp
, ';', &nbits
);
3085 return error_type (pp
);
3087 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
3088 || details
== NF_COMPLEX32
)
3089 /* This is a type we can't handle, but we do know the size.
3090 We also will be able to give it a name. */
3091 return init_type (TYPE_CODE_ERROR
, nbytes
, 0, NULL
, objfile
);
3093 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
3096 /* Read a number from the string pointed to by *PP.
3097 The value of *PP is advanced over the number.
3098 If END is nonzero, the character that ends the
3099 number must match END, or an error happens;
3100 and that character is skipped if it does match.
3101 If END is zero, *PP is left pointing to that character.
3103 If the number fits in a long, set *BITS to 0 and return the value.
3104 If not, set *BITS to be the number of bits in the number and return 0.
3106 If encounter garbage, set *BITS to -1 and return 0. */
3109 read_huge_number (pp
, end
, bits
)
3129 /* Leading zero means octal. GCC uses this to output values larger
3130 than an int (because that would be hard in decimal). */
3137 upper_limit
= LONG_MAX
/ radix
;
3138 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
3140 if (n
<= upper_limit
)
3143 n
+= c
- '0'; /* FIXME this overflows anyway */
3148 /* This depends on large values being output in octal, which is
3155 /* Ignore leading zeroes. */
3159 else if (c
== '2' || c
== '3')
3185 /* Large decimal constants are an error (because it is hard to
3186 count how many bits are in them). */
3192 /* -0x7f is the same as 0x80. So deal with it by adding one to
3193 the number of bits. */
3205 /* It's *BITS which has the interesting information. */
3209 static struct type
*
3210 read_range_type (pp
, typenums
, objfile
)
3213 struct objfile
*objfile
;
3219 struct type
*result_type
;
3220 struct type
*index_type
;
3222 /* First comes a type we are a subrange of.
3223 In C it is usually 0, 1 or the type being defined. */
3224 /* FIXME: according to stabs.texinfo and AIX doc, this can be a type-id
3225 not just a type number. */
3226 if (read_type_number (pp
, rangenums
) != 0)
3227 return error_type (pp
);
3228 self_subrange
= (rangenums
[0] == typenums
[0] &&
3229 rangenums
[1] == typenums
[1]);
3231 /* A semicolon should now follow; skip it. */
3235 /* The remaining two operands are usually lower and upper bounds
3236 of the range. But in some special cases they mean something else. */
3237 n2
= read_huge_number (pp
, ';', &n2bits
);
3238 n3
= read_huge_number (pp
, ';', &n3bits
);
3240 if (n2bits
== -1 || n3bits
== -1)
3241 return error_type (pp
);
3243 /* If limits are huge, must be large integral type. */
3244 if (n2bits
!= 0 || n3bits
!= 0)
3246 char got_signed
= 0;
3247 char got_unsigned
= 0;
3248 /* Number of bits in the type. */
3251 /* Range from 0 to <large number> is an unsigned large integral type. */
3252 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
3257 /* Range from <large number> to <large number>-1 is a large signed
3259 else if (n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
3265 if (got_signed
|| got_unsigned
)
3267 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
3268 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
3272 return error_type (pp
);
3275 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3276 if (self_subrange
&& n2
== 0 && n3
== 0)
3277 return init_type (TYPE_CODE_VOID
, 0, 0, NULL
, objfile
);
3279 /* If n3 is zero and n2 is not, we want a floating type,
3280 and n2 is the width in bytes.
3282 Fortran programs appear to use this for complex types also,
3283 and they give no way to distinguish between double and single-complex!
3285 GDB does not have complex types.
3287 Just return the complex as a float of that size. It won't work right
3288 for the complex values, but at least it makes the file loadable.
3290 FIXME, we may be able to distinguish these by their names. FIXME. */
3292 if (n3
== 0 && n2
> 0)
3294 return init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
3297 /* If the upper bound is -1, it must really be an unsigned int. */
3299 else if (n2
== 0 && n3
== -1)
3301 /* It is unsigned int or unsigned long. */
3302 /* GCC sometimes uses this for long long too. We could
3303 distinguish it by the name, but we don't. */
3304 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3305 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3308 /* Special case: char is defined (Who knows why) as a subrange of
3309 itself with range 0-127. */
3310 else if (self_subrange
&& n2
== 0 && n3
== 127)
3311 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3313 /* We used to do this only for subrange of self or subrange of int. */
3317 /* n3 actually gives the size. */
3318 return init_type (TYPE_CODE_INT
, - n3
, TYPE_FLAG_UNSIGNED
,
3321 return init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3323 return init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3325 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
3326 "unsigned long", and we already checked for that,
3327 so don't need to test for it here. */
3329 /* I think this is for Convex "long long". Since I don't know whether
3330 Convex sets self_subrange, I also accept that particular size regardless
3331 of self_subrange. */
3332 else if (n3
== 0 && n2
< 0
3334 || n2
== - TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
3335 return init_type (TYPE_CODE_INT
, - n2
, 0, NULL
, objfile
);
3336 else if (n2
== -n3
-1)
3339 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3341 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
3342 if (n3
== 0x7fffffff)
3343 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
3346 /* We have a real range type on our hands. Allocate space and
3347 return a real pointer. */
3349 /* At this point I don't have the faintest idea how to deal with
3350 a self_subrange type; I'm going to assume that this is used
3351 as an idiom, and that all of them are special cases. So . . . */
3353 return error_type (pp
);
3355 index_type
= *dbx_lookup_type (rangenums
);
3356 if (index_type
== NULL
)
3358 /* Does this actually ever happen? Is that why we are worrying
3359 about dealing with it rather than just calling error_type? */
3361 static struct type
*range_type_index
;
3363 complain (&range_type_base_complaint
, rangenums
[1]);
3364 if (range_type_index
== NULL
)
3366 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3367 0, "range type index type", NULL
);
3368 index_type
= range_type_index
;
3371 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
3372 return (result_type
);
3375 /* Read in an argument list. This is a list of types, separated by commas
3376 and terminated with END. Return the list of types read in, or (struct type
3377 **)-1 if there is an error. */
3379 static struct type
**
3380 read_args (pp
, end
, objfile
)
3383 struct objfile
*objfile
;
3385 /* FIXME! Remove this arbitrary limit! */
3386 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3392 /* Invalid argument list: no ','. */
3393 return (struct type
**)-1;
3395 STABS_CONTINUE (pp
);
3396 types
[n
++] = read_type (pp
, objfile
);
3398 (*pp
)++; /* get past `end' (the ':' character) */
3402 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3404 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3406 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3407 memset (rval
+ n
, 0, sizeof (struct type
*));
3411 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3413 memcpy (rval
, types
, n
* sizeof (struct type
*));
3417 /* Add a common block's start address to the offset of each symbol
3418 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3419 the common block name). */
3422 fix_common_block (sym
, valu
)
3426 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
3427 for ( ; next
; next
= next
->next
)
3430 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3431 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3437 /* What about types defined as forward references inside of a small lexical
3439 /* Add a type to the list of undefined types to be checked through
3440 once this file has been read in. */
3443 add_undefined_type (type
)
3446 if (undef_types_length
== undef_types_allocated
)
3448 undef_types_allocated
*= 2;
3449 undef_types
= (struct type
**)
3450 xrealloc ((char *) undef_types
,
3451 undef_types_allocated
* sizeof (struct type
*));
3453 undef_types
[undef_types_length
++] = type
;
3456 /* Go through each undefined type, see if it's still undefined, and fix it
3457 up if possible. We have two kinds of undefined types:
3459 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3460 Fix: update array length using the element bounds
3461 and the target type's length.
3462 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3463 yet defined at the time a pointer to it was made.
3464 Fix: Do a full lookup on the struct/union tag. */
3466 cleanup_undefined_types ()
3470 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
3472 switch (TYPE_CODE (*type
))
3475 case TYPE_CODE_STRUCT
:
3476 case TYPE_CODE_UNION
:
3477 case TYPE_CODE_ENUM
:
3479 /* Check if it has been defined since. */
3480 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
3482 struct pending
*ppt
;
3484 /* Name of the type, without "struct" or "union" */
3485 char *typename
= type_name_no_tag (*type
);
3487 if (typename
== NULL
)
3489 static struct complaint msg
= {"need a type name", 0, 0};
3493 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
3495 for (i
= 0; i
< ppt
->nsyms
; i
++)
3497 struct symbol
*sym
= ppt
->symbol
[i
];
3499 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3500 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
3501 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
3503 && STREQ (SYMBOL_NAME (sym
), typename
))
3505 memcpy (*type
, SYMBOL_TYPE (sym
),
3506 sizeof (struct type
));
3514 case TYPE_CODE_ARRAY
:
3516 struct type
*range_type
;
3519 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
3521 if (TYPE_NFIELDS (*type
) != 1)
3523 range_type
= TYPE_FIELD_TYPE (*type
, 0);
3524 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
3527 /* Now recompute the length of the array type, based on its
3528 number of elements and the target type's length. */
3529 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
3530 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
3531 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
3532 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
3539 static struct complaint msg
= {"\
3540 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
3541 complain (&msg
, TYPE_CODE (*type
));
3546 undef_types_length
= 0;
3549 /* Scan through all of the global symbols defined in the object file,
3550 assigning values to the debugging symbols that need to be assigned
3551 to. Get these symbols from the minimal symbol table. */
3554 scan_file_globals (objfile
)
3555 struct objfile
*objfile
;
3558 struct minimal_symbol
*msymbol
;
3559 struct symbol
*sym
, *prev
;
3561 if (objfile
->msymbols
== 0) /* Beware the null file. */
3564 for (msymbol
= objfile
-> msymbols
; SYMBOL_NAME (msymbol
) != NULL
; msymbol
++)
3570 /* Get the hash index and check all the symbols
3571 under that hash index. */
3573 hash
= hashname (SYMBOL_NAME (msymbol
));
3575 for (sym
= global_sym_chain
[hash
]; sym
;)
3577 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
3578 STREQ(SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
3580 /* Splice this symbol out of the hash chain and
3581 assign the value we have to it. */
3584 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
3588 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
3591 /* Check to see whether we need to fix up a common block. */
3592 /* Note: this code might be executed several times for
3593 the same symbol if there are multiple references. */
3595 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3597 fix_common_block (sym
, SYMBOL_VALUE_ADDRESS (msymbol
));
3601 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msymbol
);
3606 sym
= SYMBOL_VALUE_CHAIN (prev
);
3610 sym
= global_sym_chain
[hash
];
3616 sym
= SYMBOL_VALUE_CHAIN (sym
);
3622 /* Initialize anything that needs initializing when starting to read
3623 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
3631 /* Initialize anything that needs initializing when a completely new
3632 symbol file is specified (not just adding some symbols from another
3633 file, e.g. a shared library). */
3636 stabsread_new_init ()
3638 /* Empty the hash table of global syms looking for values. */
3639 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
3642 /* Initialize anything that needs initializing at the same time as
3643 start_symtab() is called. */
3647 global_stabs
= NULL
; /* AIX COFF */
3648 /* Leave FILENUM of 0 free for builtin types and this file's types. */
3649 n_this_object_header_files
= 1;
3650 type_vector_length
= 0;
3651 type_vector
= (struct type
**) 0;
3654 /* Call after end_symtab() */
3660 free ((char *) type_vector
);
3663 type_vector_length
= 0;
3664 previous_stab_code
= 0;
3668 finish_global_stabs (objfile
)
3669 struct objfile
*objfile
;
3673 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
3674 free ((PTR
) global_stabs
);
3675 global_stabs
= NULL
;
3679 /* Initializer for this module */
3682 _initialize_stabsread ()
3684 undef_types_allocated
= 20;
3685 undef_types_length
= 0;
3686 undef_types
= (struct type
**)
3687 xmalloc (undef_types_allocated
* sizeof (struct type
*));