1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994
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. */
35 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
37 #include "aout/aout64.h"
38 #include "gdb-stabs.h"
40 #include "complaints.h"
45 /* Ask stabsread.h to define the vars it normally declares `extern'. */
47 #include "stabsread.h" /* Our own declarations */
50 /* The routines that read and process a complete stabs for a C struct or
51 C++ class pass lists of data member fields and lists of member function
52 fields in an instance of a field_info structure, as defined below.
53 This is part of some reorganization of low level C++ support and is
54 expected to eventually go away... (FIXME) */
60 struct nextfield
*next
;
62 /* This is the raw visibility from the stab. It is not checked
63 for being one of the visibilities we recognize, so code which
64 examines this field better be able to deal. */
69 struct next_fnfieldlist
71 struct next_fnfieldlist
*next
;
72 struct fn_fieldlist fn_fieldlist
;
77 dbx_alloc_type
PARAMS ((int [2], struct objfile
*));
79 static long read_huge_number
PARAMS ((char **, int, int *));
81 static struct type
*error_type
PARAMS ((char **));
84 patch_block_stabs
PARAMS ((struct pending
*, struct pending_stabs
*,
88 fix_common_block
PARAMS ((struct symbol
*, int));
91 read_type_number
PARAMS ((char **, int *));
94 read_range_type
PARAMS ((char **, int [2], struct objfile
*));
97 read_sun_builtin_type
PARAMS ((char **, int [2], struct objfile
*));
100 read_sun_floating_type
PARAMS ((char **, int [2], struct objfile
*));
103 read_enum_type
PARAMS ((char **, struct type
*, struct objfile
*));
106 rs6000_builtin_type
PARAMS ((int));
109 read_member_functions
PARAMS ((struct field_info
*, char **, struct type
*,
113 read_struct_fields
PARAMS ((struct field_info
*, char **, struct type
*,
117 read_baseclasses
PARAMS ((struct field_info
*, char **, struct type
*,
121 read_tilde_fields
PARAMS ((struct field_info
*, char **, struct type
*,
125 attach_fn_fields_to_type
PARAMS ((struct field_info
*, struct type
*));
128 attach_fields_to_type
PARAMS ((struct field_info
*, struct type
*,
132 read_struct_type
PARAMS ((char **, struct type
*, struct objfile
*));
135 read_array_type
PARAMS ((char **, struct type
*, struct objfile
*));
137 static struct type
**
138 read_args
PARAMS ((char **, int, struct objfile
*));
141 read_cpp_abbrev
PARAMS ((struct field_info
*, char **, struct type
*,
144 static const char vptr_name
[] = { '_','v','p','t','r',CPLUS_MARKER
,'\0' };
145 static const char vb_name
[] = { '_','v','b',CPLUS_MARKER
,'\0' };
147 /* Define this as 1 if a pcc declaration of a char or short argument
148 gives the correct address. Otherwise assume pcc gives the
149 address of the corresponding int, which is not the same on a
150 big-endian machine. */
152 #ifndef BELIEVE_PCC_PROMOTION
153 #define BELIEVE_PCC_PROMOTION 0
156 struct complaint invalid_cpp_abbrev_complaint
=
157 {"invalid C++ abbreviation `%s'", 0, 0};
159 struct complaint invalid_cpp_type_complaint
=
160 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
162 struct complaint member_fn_complaint
=
163 {"member function type missing, got '%c'", 0, 0};
165 struct complaint const_vol_complaint
=
166 {"const/volatile indicator missing, got '%c'", 0, 0};
168 struct complaint error_type_complaint
=
169 {"debug info mismatch between compiler and debugger", 0, 0};
171 struct complaint invalid_member_complaint
=
172 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
174 struct complaint range_type_base_complaint
=
175 {"base type %d of range type is not defined", 0, 0};
177 struct complaint reg_value_complaint
=
178 {"register number too large in symbol %s", 0, 0};
180 struct complaint vtbl_notfound_complaint
=
181 {"virtual function table pointer not found when defining class `%s'", 0, 0};
183 struct complaint unrecognized_cplus_name_complaint
=
184 {"Unknown C++ symbol name `%s'", 0, 0};
186 struct complaint rs6000_builtin_complaint
=
187 {"Unknown builtin type %d", 0, 0};
189 struct complaint stabs_general_complaint
=
192 /* Make a list of forward references which haven't been defined. */
194 static struct type
**undef_types
;
195 static int undef_types_allocated
;
196 static int undef_types_length
;
198 /* Check for and handle cretinous stabs symbol name continuation! */
199 #define STABS_CONTINUE(pp) \
201 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
202 *(pp) = next_symbol_text (); \
205 /* FIXME: These probably should be our own types (like rs6000_builtin_type
206 has its own types) rather than builtin_type_*. */
207 static struct type
**os9k_type_vector
[] = {
213 &builtin_type_unsigned_char
,
214 &builtin_type_unsigned_short
,
215 &builtin_type_unsigned_long
,
216 &builtin_type_unsigned_int
,
218 &builtin_type_double
,
220 &builtin_type_long_double
223 static void os9k_init_type_vector
PARAMS ((struct type
**));
226 os9k_init_type_vector(tv
)
230 for (i
=0; i
<sizeof(os9k_type_vector
)/sizeof(struct type
**); i
++)
231 tv
[i
] = (os9k_type_vector
[i
] == 0 ? 0 : *(os9k_type_vector
[i
]));
234 /* Look up a dbx type-number pair. Return the address of the slot
235 where the type for that number-pair is stored.
236 The number-pair is in TYPENUMS.
238 This can be used for finding the type associated with that pair
239 or for associating a new type with the pair. */
242 dbx_lookup_type (typenums
)
245 register int filenum
= typenums
[0];
246 register int index
= typenums
[1];
248 register int real_filenum
;
249 register struct header_file
*f
;
252 if (filenum
== -1) /* -1,-1 is for temporary types. */
255 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
257 static struct complaint msg
= {"\
258 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
260 complain (&msg
, filenum
, index
, symnum
);
268 /* Caller wants address of address of type. We think
269 that negative (rs6k builtin) types will never appear as
270 "lvalues", (nor should they), so we stuff the real type
271 pointer into a temp, and return its address. If referenced,
272 this will do the right thing. */
273 static struct type
*temp_type
;
275 temp_type
= rs6000_builtin_type(index
);
279 /* Type is defined outside of header files.
280 Find it in this object file's type vector. */
281 if (index
>= type_vector_length
)
283 old_len
= type_vector_length
;
286 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
287 type_vector
= (struct type
**)
288 malloc (type_vector_length
* sizeof (struct type
*));
290 while (index
>= type_vector_length
)
292 type_vector_length
*= 2;
294 type_vector
= (struct type
**)
295 xrealloc ((char *) type_vector
,
296 (type_vector_length
* sizeof (struct type
*)));
297 memset (&type_vector
[old_len
], 0,
298 (type_vector_length
- old_len
) * sizeof (struct type
*));
301 /* Deal with OS9000 fundamental types. */
302 os9k_init_type_vector (type_vector
);
304 return (&type_vector
[index
]);
308 real_filenum
= this_object_header_files
[filenum
];
310 if (real_filenum
>= n_header_files
)
312 struct type
*temp_type
;
313 struct type
**temp_type_p
;
315 warning ("GDB internal error: bad real_filenum");
318 temp_type
= init_type (TYPE_CODE_ERROR
, 0, 0, NULL
, NULL
);
319 temp_type_p
= (struct type
**) xmalloc (sizeof (struct type
*));
320 *temp_type_p
= temp_type
;
324 f
= &header_files
[real_filenum
];
326 f_orig_length
= f
->length
;
327 if (index
>= f_orig_length
)
329 while (index
>= f
->length
)
333 f
->vector
= (struct type
**)
334 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
335 memset (&f
->vector
[f_orig_length
], 0,
336 (f
->length
- f_orig_length
) * sizeof (struct type
*));
338 return (&f
->vector
[index
]);
342 /* Make sure there is a type allocated for type numbers TYPENUMS
343 and return the type object.
344 This can create an empty (zeroed) type object.
345 TYPENUMS may be (-1, -1) to return a new type object that is not
346 put into the type vector, and so may not be referred to by number. */
349 dbx_alloc_type (typenums
, objfile
)
351 struct objfile
*objfile
;
353 register struct type
**type_addr
;
355 if (typenums
[0] == -1)
357 return (alloc_type (objfile
));
360 type_addr
= dbx_lookup_type (typenums
);
362 /* If we are referring to a type not known at all yet,
363 allocate an empty type for it.
364 We will fill it in later if we find out how. */
367 *type_addr
= alloc_type (objfile
);
373 /* for all the stabs in a given stab vector, build appropriate types
374 and fix their symbols in given symbol vector. */
377 patch_block_stabs (symbols
, stabs
, objfile
)
378 struct pending
*symbols
;
379 struct pending_stabs
*stabs
;
380 struct objfile
*objfile
;
390 /* for all the stab entries, find their corresponding symbols and
391 patch their types! */
393 for (ii
= 0; ii
< stabs
->count
; ++ii
)
395 name
= stabs
->stab
[ii
];
396 pp
= (char*) strchr (name
, ':');
400 pp
= (char *)strchr(pp
, ':');
402 sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
405 /* FIXME-maybe: it would be nice if we noticed whether
406 the variable was defined *anywhere*, not just whether
407 it is defined in this compilation unit. But neither
408 xlc or GCC seem to need such a definition, and until
409 we do psymtabs (so that the minimal symbols from all
410 compilation units are available now), I'm not sure
411 how to get the information. */
413 /* On xcoff, if a global is defined and never referenced,
414 ld will remove it from the executable. There is then
415 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
416 sym
= (struct symbol
*)
417 obstack_alloc (&objfile
->symbol_obstack
,
418 sizeof (struct symbol
));
420 memset (sym
, 0, sizeof (struct symbol
));
421 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
422 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
424 obstack_copy0 (&objfile
->symbol_obstack
, name
, pp
- name
);
426 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
428 /* I don't think the linker does this with functions,
429 so as far as I know this is never executed.
430 But it doesn't hurt to check. */
432 lookup_function_type (read_type (&pp
, objfile
));
436 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
438 add_symbol_to_list (sym
, &global_symbols
);
443 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
446 lookup_function_type (read_type (&pp
, objfile
));
450 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
458 /* Read a number by which a type is referred to in dbx data,
459 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
460 Just a single number N is equivalent to (0,N).
461 Return the two numbers by storing them in the vector TYPENUMS.
462 TYPENUMS will then be used as an argument to dbx_lookup_type.
464 Returns 0 for success, -1 for error. */
467 read_type_number (pp
, typenums
)
469 register int *typenums
;
475 typenums
[0] = read_huge_number (pp
, ',', &nbits
);
476 if (nbits
!= 0) return -1;
477 typenums
[1] = read_huge_number (pp
, ')', &nbits
);
478 if (nbits
!= 0) return -1;
483 typenums
[1] = read_huge_number (pp
, 0, &nbits
);
484 if (nbits
!= 0) return -1;
490 /* To handle GNU C++ typename abbreviation, we need to be able to
491 fill in a type's name as soon as space for that type is allocated.
492 `type_synonym_name' is the name of the type being allocated.
493 It is cleared as soon as it is used (lest all allocated types
496 static char *type_synonym_name
;
498 #if !defined (REG_STRUCT_HAS_ADDR)
499 #define REG_STRUCT_HAS_ADDR(gcc_p,type) 0
504 define_symbol (valu
, string
, desc
, type
, objfile
)
509 struct objfile
*objfile
;
511 register struct symbol
*sym
;
512 char *p
= (char *) strchr (string
, ':');
517 /* We would like to eliminate nameless symbols, but keep their types.
518 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
519 to type 2, but, should not create a symbol to address that type. Since
520 the symbol will be nameless, there is no way any user can refer to it. */
524 /* Ignore syms with empty names. */
528 /* Ignore old-style symbols from cc -go */
538 /* If a nameless stab entry, all we need is the type, not the symbol.
539 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
540 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
542 sym
= (struct symbol
*)
543 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
544 memset (sym
, 0, sizeof (struct symbol
));
546 switch (type
& N_TYPE
)
549 SYMBOL_SECTION(sym
) = SECT_OFF_TEXT
;
552 SYMBOL_SECTION(sym
) = SECT_OFF_DATA
;
555 SYMBOL_SECTION(sym
) = SECT_OFF_BSS
;
559 if (processing_gcc_compilation
)
561 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
562 number of bytes occupied by a type or object, which we ignore. */
563 SYMBOL_LINE(sym
) = desc
;
567 SYMBOL_LINE(sym
) = 0; /* unknown */
570 if (string
[0] == CPLUS_MARKER
)
572 /* Special GNU C++ names. */
576 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
577 &objfile
-> symbol_obstack
);
580 case 'v': /* $vtbl_ptr_type */
581 /* Was: SYMBOL_NAME (sym) = "vptr"; */
585 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
586 &objfile
-> symbol_obstack
);
590 /* This was an anonymous type that was never fixed up. */
594 complain (&unrecognized_cplus_name_complaint
, string
);
595 goto normal
; /* Do *something* with it */
601 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
602 SYMBOL_NAME (sym
) = (char *)
603 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
604 /* Open-coded memcpy--saves function call time. */
605 /* FIXME: Does it really? Try replacing with simple strcpy and
606 try it on an executable with a large symbol table. */
607 /* FIXME: considering that gcc can open code memcpy anyway, I
608 doubt it. xoxorich. */
610 register char *p1
= string
;
611 register char *p2
= SYMBOL_NAME (sym
);
619 /* If this symbol is from a C++ compilation, then attempt to cache the
620 demangled form for future reference. This is a typical time versus
621 space tradeoff, that was decided in favor of time because it sped up
622 C++ symbol lookups by a factor of about 20. */
624 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
628 /* Determine the type of name being defined. */
630 /* Getting GDB to correctly skip the symbol on an undefined symbol
631 descriptor and not ever dump core is a very dodgy proposition if
632 we do things this way. I say the acorn RISC machine can just
633 fix their compiler. */
634 /* The Acorn RISC machine's compiler can put out locals that don't
635 start with "234=" or "(3,4)=", so assume anything other than the
636 deftypes we know how to handle is a local. */
637 if (!strchr ("cfFGpPrStTvVXCR", *p
))
639 if (isdigit (*p
) || *p
== '(' || *p
== '-')
648 /* c is a special case, not followed by a type-number.
649 SYMBOL:c=iVALUE for an integer constant symbol.
650 SYMBOL:c=rVALUE for a floating constant symbol.
651 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
652 e.g. "b:c=e6,0" for "const b = blob1"
653 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
656 SYMBOL_CLASS (sym
) = LOC_CONST
;
657 SYMBOL_TYPE (sym
) = error_type (&p
);
658 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
659 add_symbol_to_list (sym
, &file_symbols
);
670 /* FIXME-if-picky-about-floating-accuracy: Should be using
671 target arithmetic to get the value. real.c in GCC
672 probably has the necessary code. */
674 /* FIXME: lookup_fundamental_type is a hack. We should be
675 creating a type especially for the type of float constants.
676 Problem is, what type should it be?
678 Also, what should the name of this type be? Should we
679 be using 'S' constants (see stabs.texinfo) instead? */
681 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
684 obstack_alloc (&objfile
-> symbol_obstack
,
685 TYPE_LENGTH (SYMBOL_TYPE (sym
)));
686 store_floating (dbl_valu
, TYPE_LENGTH (SYMBOL_TYPE (sym
)), d
);
687 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
688 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
693 /* Defining integer constants this way is kind of silly,
694 since 'e' constants allows the compiler to give not
695 only the value, but the type as well. C has at least
696 int, long, unsigned int, and long long as constant
697 types; other languages probably should have at least
698 unsigned as well as signed constants. */
700 /* We just need one int constant type for all objfiles.
701 It doesn't depend on languages or anything (arguably its
702 name should be a language-specific name for a type of
703 that size, but I'm inclined to say that if the compiler
704 wants a nice name for the type, it can use 'e'). */
705 static struct type
*int_const_type
;
707 /* Yes, this is as long as a *host* int. That is because we
709 if (int_const_type
== NULL
)
711 init_type (TYPE_CODE_INT
,
712 sizeof (int) * HOST_CHAR_BIT
/ TARGET_CHAR_BIT
, 0,
714 (struct objfile
*)NULL
);
715 SYMBOL_TYPE (sym
) = int_const_type
;
716 SYMBOL_VALUE (sym
) = atoi (p
);
717 SYMBOL_CLASS (sym
) = LOC_CONST
;
721 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
722 can be represented as integral.
723 e.g. "b:c=e6,0" for "const b = blob1"
724 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
726 SYMBOL_CLASS (sym
) = LOC_CONST
;
727 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
731 SYMBOL_TYPE (sym
) = error_type (&p
);
736 /* If the value is too big to fit in an int (perhaps because
737 it is unsigned), or something like that, we silently get
738 a bogus value. The type and everything else about it is
739 correct. Ideally, we should be using whatever we have
740 available for parsing unsigned and long long values,
742 SYMBOL_VALUE (sym
) = atoi (p
);
747 SYMBOL_CLASS (sym
) = LOC_CONST
;
748 SYMBOL_TYPE (sym
) = error_type (&p
);
751 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
752 add_symbol_to_list (sym
, &file_symbols
);
756 /* The name of a caught exception. */
757 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
758 SYMBOL_CLASS (sym
) = LOC_LABEL
;
759 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
760 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
761 add_symbol_to_list (sym
, &local_symbols
);
765 /* A static function definition. */
766 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
767 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
768 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
769 add_symbol_to_list (sym
, &file_symbols
);
770 /* fall into process_function_types. */
772 process_function_types
:
773 /* Function result types are described as the result type in stabs.
774 We need to convert this to the function-returning-type-X type
775 in GDB. E.g. "int" is converted to "function returning int". */
776 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
779 /* This code doesn't work -- it needs to realloc and can't. */
780 /* Attempt to set up to record a function prototype... */
781 struct type
*new = alloc_type (objfile
);
783 /* Generate a template for the type of this function. The
784 types of the arguments will be added as we read the symbol
786 *new = *lookup_function_type (SYMBOL_TYPE(sym
));
787 SYMBOL_TYPE(sym
) = new;
788 TYPE_OBJFILE (new) = objfile
;
789 in_function_type
= new;
791 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
794 /* fall into process_prototype_types */
796 process_prototype_types
:
797 /* Sun acc puts declared types of arguments here. We don't care
798 about their actual types (FIXME -- we should remember the whole
799 function prototype), but the list may define some new types
800 that we have to remember, so we must scan it now. */
803 read_type (&p
, objfile
);
808 /* A global function definition. */
809 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
810 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
811 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
812 add_symbol_to_list (sym
, &global_symbols
);
813 goto process_function_types
;
816 /* For a class G (global) symbol, it appears that the
817 value is not correct. It is necessary to search for the
818 corresponding linker definition to find the value.
819 These definitions appear at the end of the namelist. */
820 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
821 i
= hashname (SYMBOL_NAME (sym
));
822 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
823 global_sym_chain
[i
] = sym
;
824 SYMBOL_CLASS (sym
) = LOC_STATIC
;
825 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
826 add_symbol_to_list (sym
, &global_symbols
);
829 /* This case is faked by a conditional above,
830 when there is no code letter in the dbx data.
831 Dbx data never actually contains 'l'. */
834 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
835 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
836 SYMBOL_VALUE (sym
) = valu
;
837 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
838 add_symbol_to_list (sym
, &local_symbols
);
843 /* pF is a two-letter code that means a function parameter in Fortran.
844 The type-number specifies the type of the return value.
845 Translate it into a pointer-to-function type. */
849 = lookup_pointer_type
850 (lookup_function_type (read_type (&p
, objfile
)));
853 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
855 /* Normally this is a parameter, a LOC_ARG. On the i960, it
856 can also be a LOC_LOCAL_ARG depending on symbol type. */
857 #ifndef DBX_PARM_SYMBOL_CLASS
858 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
861 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
862 SYMBOL_VALUE (sym
) = valu
;
863 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
865 /* This doesn't work yet. */
866 add_param_to_type (&in_function_type
, sym
);
868 add_symbol_to_list (sym
, &local_symbols
);
870 #if TARGET_BYTE_ORDER == LITTLE_ENDIAN
871 /* On little-endian machines, this crud is never necessary, and,
872 if the extra bytes contain garbage, is harmful. */
874 #else /* Big endian. */
875 /* If it's gcc-compiled, if it says `short', believe it. */
876 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
879 #if !BELIEVE_PCC_PROMOTION
881 /* This is the signed type which arguments get promoted to. */
882 static struct type
*pcc_promotion_type
;
883 /* This is the unsigned type which arguments get promoted to. */
884 static struct type
*pcc_unsigned_promotion_type
;
886 /* Call it "int" because this is mainly C lossage. */
887 if (pcc_promotion_type
== NULL
)
889 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
892 if (pcc_unsigned_promotion_type
== NULL
)
893 pcc_unsigned_promotion_type
=
894 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
895 TYPE_FLAG_UNSIGNED
, "unsigned int", NULL
);
897 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
898 /* This macro is defined on machines (e.g. sparc) where
899 we should believe the type of a PCC 'short' argument,
900 but shouldn't believe the address (the address is
901 the address of the corresponding int).
903 My guess is that this correction, as opposed to changing
904 the parameter to an 'int' (as done below, for PCC
905 on most machines), is the right thing to do
906 on all machines, but I don't want to risk breaking
907 something that already works. On most PCC machines,
908 the sparc problem doesn't come up because the calling
909 function has to zero the top bytes (not knowing whether
910 the called function wants an int or a short), so there
911 is little practical difference between an int and a short
912 (except perhaps what happens when the GDB user types
913 "print short_arg = 0x10000;").
915 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
916 actually produces the correct address (we don't need to fix it
917 up). I made this code adapt so that it will offset the symbol
918 if it was pointing at an int-aligned location and not
919 otherwise. This way you can use the same gdb for 4.0.x and
922 If the parameter is shorter than an int, and is integral
923 (e.g. char, short, or unsigned equivalent), and is claimed to
924 be passed on an integer boundary, don't believe it! Offset the
925 parameter's address to the tail-end of that integer. */
927 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
928 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
929 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (pcc_promotion_type
))
931 SYMBOL_VALUE (sym
) += TYPE_LENGTH (pcc_promotion_type
)
932 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
936 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
938 /* If PCC says a parameter is a short or a char,
939 it is really an int. */
940 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
941 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
944 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
945 ? pcc_unsigned_promotion_type
946 : pcc_promotion_type
;
950 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
952 #endif /* !BELIEVE_PCC_PROMOTION. */
953 #endif /* Big endian. */
956 /* acc seems to use P to delare the prototypes of functions that
957 are referenced by this file. gdb is not prepared to deal
958 with this extra information. FIXME, it ought to. */
961 read_type (&p
, objfile
);
962 goto process_prototype_types
;
967 /* Parameter which is in a register. */
968 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
969 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
970 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
971 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
973 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
974 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
976 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
977 add_symbol_to_list (sym
, &local_symbols
);
981 /* Register variable (either global or local). */
982 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
983 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
984 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
985 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
987 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
988 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
990 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
993 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
994 name to represent an argument passed in a register.
995 GCC uses 'P' for the same case. So if we find such a symbol pair
996 we combine it into one 'P' symbol. For Sun cc we need to do this
997 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
998 the 'p' symbol even if it never saves the argument onto the stack.
1000 On most machines, we want to preserve both symbols, so that
1001 we can still get information about what is going on with the
1002 stack (VAX for computing args_printed, using stack slots instead
1003 of saved registers in backtraces, etc.).
1005 Note that this code illegally combines
1006 main(argc) struct foo argc; { register struct foo argc; }
1007 but this case is considered pathological and causes a warning
1008 from a decent compiler. */
1011 && local_symbols
->nsyms
> 0
1012 #ifndef USE_REGISTER_NOT_ARG
1013 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1015 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1016 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1020 struct symbol
*prev_sym
;
1021 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
1022 if ((SYMBOL_CLASS (prev_sym
) == LOC_REF_ARG
1023 || SYMBOL_CLASS (prev_sym
) == LOC_ARG
)
1024 && STREQ (SYMBOL_NAME (prev_sym
), SYMBOL_NAME(sym
)))
1026 SYMBOL_CLASS (prev_sym
) = LOC_REGPARM
;
1027 /* Use the type from the LOC_REGISTER; that is the type
1028 that is actually in that register. */
1029 SYMBOL_TYPE (prev_sym
) = SYMBOL_TYPE (sym
);
1030 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
1035 add_symbol_to_list (sym
, &local_symbols
);
1038 add_symbol_to_list (sym
, &file_symbols
);
1042 /* Static symbol at top level of file */
1043 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1044 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1045 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1046 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1047 add_symbol_to_list (sym
, &file_symbols
);
1051 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1053 /* For a nameless type, we don't want a create a symbol, thus we
1054 did not use `sym'. Return without further processing. */
1055 if (nameless
) return NULL
;
1057 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1058 SYMBOL_VALUE (sym
) = valu
;
1059 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1060 /* C++ vagaries: we may have a type which is derived from
1061 a base type which did not have its name defined when the
1062 derived class was output. We fill in the derived class's
1063 base part member's name here in that case. */
1064 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
1065 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1066 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1067 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1070 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1071 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1072 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1073 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1076 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1078 /* gcc-2.6 or later (when using -fvtable-thunks)
1079 emits a unique named type for a vtable entry.
1080 Some gdb code depends on that specific name. */
1081 extern const char vtbl_ptr_name
[];
1083 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
1084 && strcmp (SYMBOL_NAME (sym
), vtbl_ptr_name
))
1085 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FUNC
)
1087 /* If we are giving a name to a type such as "pointer to
1088 foo" or "function returning foo", we better not set
1089 the TYPE_NAME. If the program contains "typedef char
1090 *caddr_t;", we don't want all variables of type char
1091 * to print as caddr_t. This is not just a
1092 consequence of GDB's type management; PCC and GCC (at
1093 least through version 2.4) both output variables of
1094 either type char * or caddr_t with the type number
1095 defined in the 't' symbol for caddr_t. If a future
1096 compiler cleans this up it GDB is not ready for it
1097 yet, but if it becomes ready we somehow need to
1098 disable this check (without breaking the PCC/GCC2.4
1103 Fortunately, this check seems not to be necessary
1104 for anything except pointers or functions. */
1107 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
1110 add_symbol_to_list (sym
, &file_symbols
);
1114 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1115 by 't' which means we are typedef'ing it as well. */
1116 synonym
= *p
== 't';
1121 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1122 strlen (SYMBOL_NAME (sym
)),
1123 &objfile
-> symbol_obstack
);
1125 /* The semantics of C++ state that "struct foo { ... }" also defines
1126 a typedef for "foo". Unfortunately, cfront never makes the typedef
1127 when translating C++ into C. We make the typedef here so that
1128 "ptype foo" works as expected for cfront translated code. */
1129 else if (current_subfile
->language
== language_cplus
)
1132 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1133 strlen (SYMBOL_NAME (sym
)),
1134 &objfile
-> symbol_obstack
);
1137 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1139 /* For a nameless type, we don't want a create a symbol, thus we
1140 did not use `sym'. Return without further processing. */
1141 if (nameless
) return NULL
;
1143 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1144 SYMBOL_VALUE (sym
) = valu
;
1145 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1146 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym
)) == 0)
1147 TYPE_TAG_NAME (SYMBOL_TYPE (sym
))
1148 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1149 add_symbol_to_list (sym
, &file_symbols
);
1153 /* Clone the sym and then modify it. */
1154 register struct symbol
*typedef_sym
= (struct symbol
*)
1155 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1156 *typedef_sym
= *sym
;
1157 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1158 SYMBOL_VALUE (typedef_sym
) = valu
;
1159 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1160 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1161 TYPE_NAME (SYMBOL_TYPE (sym
))
1162 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1163 add_symbol_to_list (typedef_sym
, &file_symbols
);
1168 /* Static symbol of local scope */
1169 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1170 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1171 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1172 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1174 add_symbol_to_list (sym
, &global_symbols
);
1176 add_symbol_to_list (sym
, &local_symbols
);
1180 /* Reference parameter */
1181 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1182 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1183 SYMBOL_VALUE (sym
) = valu
;
1184 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1185 add_symbol_to_list (sym
, &local_symbols
);
1189 /* This is used by Sun FORTRAN for "function result value".
1190 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1191 that Pascal uses it too, but when I tried it Pascal used
1192 "x:3" (local symbol) instead. */
1193 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1194 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1195 SYMBOL_VALUE (sym
) = valu
;
1196 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1197 add_symbol_to_list (sym
, &local_symbols
);
1201 SYMBOL_TYPE (sym
) = error_type (&p
);
1202 SYMBOL_CLASS (sym
) = LOC_CONST
;
1203 SYMBOL_VALUE (sym
) = 0;
1204 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1205 add_symbol_to_list (sym
, &file_symbols
);
1209 /* When passing structures to a function, some systems sometimes pass
1210 the address in a register, not the structure itself.
1212 If REG_STRUCT_HAS_ADDR yields non-zero we have to convert LOC_REGPARM
1213 to LOC_REGPARM_ADDR for structures and unions. */
1215 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
1216 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1218 && ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
1219 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)))
1220 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1222 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th and
1223 subsequent arguments on the sparc, for example). */
1224 if (SYMBOL_CLASS (sym
) == LOC_ARG
1225 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1227 && ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
1228 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)))
1229 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1235 /* Skip rest of this symbol and return an error type.
1237 General notes on error recovery: error_type always skips to the
1238 end of the symbol (modulo cretinous dbx symbol name continuation).
1239 Thus code like this:
1241 if (*(*pp)++ != ';')
1242 return error_type (pp);
1244 is wrong because if *pp starts out pointing at '\0' (typically as the
1245 result of an earlier error), it will be incremented to point to the
1246 start of the next symbol, which might produce strange results, at least
1247 if you run off the end of the string table. Instead use
1250 return error_type (pp);
1256 foo = error_type (pp);
1260 And in case it isn't obvious, the point of all this hair is so the compiler
1261 can define new types and new syntaxes, and old versions of the
1262 debugger will be able to read the new symbol tables. */
1264 static struct type
*
1268 complain (&error_type_complaint
);
1271 /* Skip to end of symbol. */
1272 while (**pp
!= '\0')
1277 /* Check for and handle cretinous dbx symbol name continuation! */
1278 if ((*pp
)[-1] == '\\' || (*pp
)[-1] == '?')
1280 *pp
= next_symbol_text ();
1287 return (builtin_type_error
);
1291 /* Read type information or a type definition; return the type. Even
1292 though this routine accepts either type information or a type
1293 definition, the distinction is relevant--some parts of stabsread.c
1294 assume that type information starts with a digit, '-', or '(' in
1295 deciding whether to call read_type. */
1298 read_type (pp
, objfile
)
1300 struct objfile
*objfile
;
1302 register struct type
*type
= 0;
1306 char type_descriptor
;
1308 /* Size in bits of type if specified by a type attribute, or -1 if
1309 there is no size attribute. */
1312 /* Used to distinguish string and bitstring from char-array and set. */
1315 /* Read type number if present. The type number may be omitted.
1316 for instance in a two-dimensional array declared with type
1317 "ar1;1;10;ar1;1;10;4". */
1318 if ((**pp
>= '0' && **pp
<= '9')
1322 if (read_type_number (pp
, typenums
) != 0)
1323 return error_type (pp
);
1325 /* Type is not being defined here. Either it already exists,
1326 or this is a forward reference to it. dbx_alloc_type handles
1329 return dbx_alloc_type (typenums
, objfile
);
1331 /* Type is being defined here. */
1338 /* It might be a type attribute or a member type. */
1339 if (isdigit (*p
) || *p
== '(' || *p
== '-')
1344 /* Type attributes. */
1347 /* Skip to the semicolon. */
1348 while (*p
!= ';' && *p
!= '\0')
1352 return error_type (pp
);
1354 /* Skip the semicolon. */
1360 type_size
= atoi (attr
+ 1);
1370 /* Ignore unrecognized type attributes, so future compilers
1371 can invent new ones. */
1376 /* Skip the type descriptor, we get it below with (*pp)[-1]. */
1381 /* 'typenums=' not present, type is anonymous. Read and return
1382 the definition, but don't put it in the type vector. */
1383 typenums
[0] = typenums
[1] = -1;
1387 type_descriptor
= (*pp
)[-1];
1388 switch (type_descriptor
)
1392 enum type_code code
;
1394 /* Used to index through file_symbols. */
1395 struct pending
*ppt
;
1398 /* Name including "struct", etc. */
1402 char *from
, *to
, *p
, *q1
, *q2
;
1404 /* Set the type code according to the following letter. */
1408 code
= TYPE_CODE_STRUCT
;
1411 code
= TYPE_CODE_UNION
;
1414 code
= TYPE_CODE_ENUM
;
1418 /* Complain and keep going, so compilers can invent new
1419 cross-reference types. */
1420 static struct complaint msg
=
1421 {"Unrecognized cross-reference type `%c'", 0, 0};
1422 complain (&msg
, (*pp
)[0]);
1423 code
= TYPE_CODE_STRUCT
;
1428 q1
= strchr(*pp
, '<');
1429 p
= strchr(*pp
, ':');
1431 return error_type (pp
);
1432 while (q1
&& p
> q1
&& p
[1] == ':')
1434 q2
= strchr(q1
, '>');
1440 return error_type (pp
);
1443 (char *)obstack_alloc (&objfile
->type_obstack
, p
- *pp
+ 1);
1445 /* Copy the name. */
1451 /* Set the pointer ahead of the name which we just read, and
1456 /* Now check to see whether the type has already been
1457 declared. This was written for arrays of cross-referenced
1458 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
1459 sure it is not necessary anymore. But it might be a good
1460 idea, to save a little memory. */
1462 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1463 for (i
= 0; i
< ppt
->nsyms
; i
++)
1465 struct symbol
*sym
= ppt
->symbol
[i
];
1467 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1468 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1469 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1470 && STREQ (SYMBOL_NAME (sym
), type_name
))
1472 obstack_free (&objfile
-> type_obstack
, type_name
);
1473 type
= SYMBOL_TYPE (sym
);
1478 /* Didn't find the type to which this refers, so we must
1479 be dealing with a forward reference. Allocate a type
1480 structure for it, and keep track of it so we can
1481 fill in the rest of the fields when we get the full
1483 type
= dbx_alloc_type (typenums
, objfile
);
1484 TYPE_CODE (type
) = code
;
1485 TYPE_TAG_NAME (type
) = type_name
;
1486 INIT_CPLUS_SPECIFIC(type
);
1487 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1489 add_undefined_type (type
);
1493 case '-': /* RS/6000 built-in type */
1512 /* Peek ahead at the number to detect void. */
1513 if (read_type_number (pp
, xtypenums
) != 0)
1514 return error_type (pp
);
1516 if (typenums
[0] == xtypenums
[0] && typenums
[1] == xtypenums
[1])
1517 /* It's being defined as itself. That means it is "void". */
1518 type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
1523 /* Go back to the number and have read_type get it. This means
1524 that we can deal with something like t(1,2)=(3,4)=... which
1525 the Lucid compiler uses. */
1527 xtype
= read_type (pp
, objfile
);
1529 /* The type is being defined to another type. So we copy the type.
1530 This loses if we copy a C++ class and so we lose track of how
1531 the names are mangled (but g++ doesn't output stabs like this
1534 type
= alloc_type (objfile
);
1535 memcpy (type
, xtype
, sizeof (struct type
));
1537 /* The idea behind clearing the names is that the only purpose
1538 for defining a type to another type is so that the name of
1539 one can be different. So we probably don't need to worry much
1540 about the case where the compiler doesn't give a name to the
1542 TYPE_NAME (type
) = NULL
;
1543 TYPE_TAG_NAME (type
) = NULL
;
1545 if (typenums
[0] != -1)
1546 *dbx_lookup_type (typenums
) = type
;
1550 /* In the following types, we must be sure to overwrite any existing
1551 type that the typenums refer to, rather than allocating a new one
1552 and making the typenums point to the new one. This is because there
1553 may already be pointers to the existing type (if it had been
1554 forward-referenced), and we must change it to a pointer, function,
1555 reference, or whatever, *in-place*. */
1558 type1
= read_type (pp
, objfile
);
1559 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1562 case '&': /* Reference to another type */
1563 type1
= read_type (pp
, objfile
);
1564 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1567 case 'f': /* Function returning another type */
1568 if (os9k_stabs
&& **pp
== '(')
1570 /* Function prototype; parse it.
1571 We must conditionalize this on os9k_stabs because otherwise
1572 it could be confused with a Sun-style (1,3) typenumber
1578 t
= read_type(pp
, objfile
);
1579 if (**pp
== ',') ++*pp
;
1582 type1
= read_type (pp
, objfile
);
1583 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1586 case 'k': /* Const qualifier on some type (Sun) */
1587 case 'c': /* Const qualifier on some type (OS9000) */
1588 /* Because 'c' means other things to AIX and 'k' is perfectly good,
1589 only accept 'c' in the os9k_stabs case. */
1590 if (type_descriptor
== 'c' && !os9k_stabs
)
1591 return error_type (pp
);
1592 type
= read_type (pp
, objfile
);
1593 /* FIXME! For now, we ignore const and volatile qualifiers. */
1596 case 'B': /* Volatile qual on some type (Sun) */
1597 case 'i': /* Volatile qual on some type (OS9000) */
1598 /* Because 'i' means other things to AIX and 'B' is perfectly good,
1599 only accept 'i' in the os9k_stabs case. */
1600 if (type_descriptor
== 'i' && !os9k_stabs
)
1601 return error_type (pp
);
1602 type
= read_type (pp
, objfile
);
1603 /* FIXME! For now, we ignore const and volatile qualifiers. */
1606 /* FIXME -- we should be doing smash_to_XXX types here. */
1607 case '@': /* Member (class & variable) type */
1609 struct type
*domain
= read_type (pp
, objfile
);
1610 struct type
*memtype
;
1613 /* Invalid member type data format. */
1614 return error_type (pp
);
1617 memtype
= read_type (pp
, objfile
);
1618 type
= dbx_alloc_type (typenums
, objfile
);
1619 smash_to_member_type (type
, domain
, memtype
);
1623 case '#': /* Method (class & fn) type */
1624 if ((*pp
)[0] == '#')
1626 /* We'll get the parameter types from the name. */
1627 struct type
*return_type
;
1630 return_type
= read_type (pp
, objfile
);
1631 if (*(*pp
)++ != ';')
1632 complain (&invalid_member_complaint
, symnum
);
1633 type
= allocate_stub_method (return_type
);
1634 if (typenums
[0] != -1)
1635 *dbx_lookup_type (typenums
) = type
;
1639 struct type
*domain
= read_type (pp
, objfile
);
1640 struct type
*return_type
;
1644 /* Invalid member type data format. */
1645 return error_type (pp
);
1649 return_type
= read_type (pp
, objfile
);
1650 args
= read_args (pp
, ';', objfile
);
1651 type
= dbx_alloc_type (typenums
, objfile
);
1652 smash_to_method_type (type
, domain
, return_type
, args
);
1656 case 'r': /* Range type */
1657 type
= read_range_type (pp
, typenums
, objfile
);
1658 if (typenums
[0] != -1)
1659 *dbx_lookup_type (typenums
) = type
;
1664 /* Const and volatile qualified type. */
1665 type
= read_type (pp
, objfile
);
1668 /* Sun ACC builtin int type */
1669 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
1670 if (typenums
[0] != -1)
1671 *dbx_lookup_type (typenums
) = type
;
1675 case 'R': /* Sun ACC builtin float type */
1676 type
= read_sun_floating_type (pp
, typenums
, objfile
);
1677 if (typenums
[0] != -1)
1678 *dbx_lookup_type (typenums
) = type
;
1681 case 'e': /* Enumeration type */
1682 type
= dbx_alloc_type (typenums
, objfile
);
1683 type
= read_enum_type (pp
, type
, objfile
);
1684 if (typenums
[0] != -1)
1685 *dbx_lookup_type (typenums
) = type
;
1688 case 's': /* Struct type */
1689 case 'u': /* Union type */
1690 type
= dbx_alloc_type (typenums
, objfile
);
1691 if (!TYPE_NAME (type
))
1693 TYPE_NAME (type
) = type_synonym_name
;
1695 type_synonym_name
= NULL
;
1696 switch (type_descriptor
)
1699 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1702 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1705 type
= read_struct_type (pp
, type
, objfile
);
1708 case 'a': /* Array type */
1710 return error_type (pp
);
1713 type
= dbx_alloc_type (typenums
, objfile
);
1714 type
= read_array_type (pp
, type
, objfile
);
1716 TYPE_CODE (type
) = TYPE_CODE_STRING
;
1720 type1
= read_type (pp
, objfile
);
1721 type
= create_set_type ((struct type
*) NULL
, type1
);
1722 if (TYPE_FLAGS (type1
) & TYPE_FLAG_STUB
)
1724 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
1725 add_undefined_type (type
);
1728 TYPE_CODE (type
) = TYPE_CODE_BITSTRING
;
1729 if (typenums
[0] != -1)
1730 *dbx_lookup_type (typenums
) = type
;
1734 --*pp
; /* Go back to the symbol in error */
1735 /* Particularly important if it was \0! */
1736 return error_type (pp
);
1741 warning ("GDB internal error, type is NULL in stabsread.c\n");
1742 return error_type (pp
);
1745 /* Size specified in a type attribute overrides any other size. */
1746 if (type_size
!= -1)
1747 TYPE_LENGTH (type
) = (type_size
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
1752 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
1753 Return the proper type node for a given builtin type number. */
1755 static struct type
*
1756 rs6000_builtin_type (typenum
)
1759 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
1760 #define NUMBER_RECOGNIZED 30
1761 /* This includes an empty slot for type number -0. */
1762 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
1763 struct type
*rettype
= NULL
;
1765 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
1767 complain (&rs6000_builtin_complaint
, typenum
);
1768 return builtin_type_error
;
1770 if (negative_types
[-typenum
] != NULL
)
1771 return negative_types
[-typenum
];
1773 #if TARGET_CHAR_BIT != 8
1774 #error This code wrong for TARGET_CHAR_BIT not 8
1775 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
1776 that if that ever becomes not true, the correct fix will be to
1777 make the size in the struct type to be in bits, not in units of
1784 /* The size of this and all the other types are fixed, defined
1785 by the debugging format. If there is a type called "int" which
1786 is other than 32 bits, then it should use a new negative type
1787 number (or avoid negative type numbers for that case).
1788 See stabs.texinfo. */
1789 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
1792 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
1795 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
1798 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
1801 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
1802 "unsigned char", NULL
);
1805 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
1808 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
1809 "unsigned short", NULL
);
1812 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1813 "unsigned int", NULL
);
1816 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1819 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1820 "unsigned long", NULL
);
1823 rettype
= init_type (TYPE_CODE_VOID
, 1, 0, "void", NULL
);
1826 /* IEEE single precision (32 bit). */
1827 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
1830 /* IEEE double precision (64 bit). */
1831 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
1834 /* This is an IEEE double on the RS/6000, and different machines with
1835 different sizes for "long double" should use different negative
1836 type numbers. See stabs.texinfo. */
1837 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
1840 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
1843 rettype
= init_type (TYPE_CODE_BOOL
, 4, 0, "boolean", NULL
);
1846 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
1849 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
1852 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
1855 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
1859 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
1863 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
1867 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
1871 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
1875 /* Complex type consisting of two IEEE single precision values. */
1876 rettype
= init_type (TYPE_CODE_ERROR
, 8, 0, "complex", NULL
);
1879 /* Complex type consisting of two IEEE double precision values. */
1880 rettype
= init_type (TYPE_CODE_ERROR
, 16, 0, "double complex", NULL
);
1883 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
1886 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
1889 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
1892 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
1895 negative_types
[-typenum
] = rettype
;
1899 /* This page contains subroutines of read_type. */
1901 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1902 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1903 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1904 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
1906 /* Read member function stabs info for C++ classes. The form of each member
1909 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1911 An example with two member functions is:
1913 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1915 For the case of overloaded operators, the format is op$::*.funcs, where
1916 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1917 name (such as `+=') and `.' marks the end of the operator name.
1919 Returns 1 for success, 0 for failure. */
1922 read_member_functions (fip
, pp
, type
, objfile
)
1923 struct field_info
*fip
;
1926 struct objfile
*objfile
;
1930 /* Total number of member functions defined in this class. If the class
1931 defines two `f' functions, and one `g' function, then this will have
1933 int total_length
= 0;
1937 struct next_fnfield
*next
;
1938 struct fn_field fn_field
;
1940 struct type
*look_ahead_type
;
1941 struct next_fnfieldlist
*new_fnlist
;
1942 struct next_fnfield
*new_sublist
;
1946 /* Process each list until we find something that is not a member function
1947 or find the end of the functions. */
1951 /* We should be positioned at the start of the function name.
1952 Scan forward to find the first ':' and if it is not the
1953 first of a "::" delimiter, then this is not a member function. */
1965 look_ahead_type
= NULL
;
1968 new_fnlist
= (struct next_fnfieldlist
*)
1969 xmalloc (sizeof (struct next_fnfieldlist
));
1970 make_cleanup (free
, new_fnlist
);
1971 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
1973 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
1975 /* This is a completely wierd case. In order to stuff in the
1976 names that might contain colons (the usual name delimiter),
1977 Mike Tiemann defined a different name format which is
1978 signalled if the identifier is "op$". In that case, the
1979 format is "op$::XXXX." where XXXX is the name. This is
1980 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1981 /* This lets the user type "break operator+".
1982 We could just put in "+" as the name, but that wouldn't
1984 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
1985 char *o
= opname
+ 3;
1987 /* Skip past '::'. */
1990 STABS_CONTINUE (pp
);
1996 main_fn_name
= savestring (opname
, o
- opname
);
2002 main_fn_name
= savestring (*pp
, p
- *pp
);
2003 /* Skip past '::'. */
2006 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
2011 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
2012 make_cleanup (free
, new_sublist
);
2013 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
2015 /* Check for and handle cretinous dbx symbol name continuation! */
2016 if (look_ahead_type
== NULL
)
2019 STABS_CONTINUE (pp
);
2021 new_sublist
-> fn_field
.type
= read_type (pp
, objfile
);
2024 /* Invalid symtab info for member function. */
2030 /* g++ version 1 kludge */
2031 new_sublist
-> fn_field
.type
= look_ahead_type
;
2032 look_ahead_type
= NULL
;
2042 /* If this is just a stub, then we don't have the real name here. */
2044 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
2046 if (!TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
))
2047 TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
) = type
;
2048 new_sublist
-> fn_field
.is_stub
= 1;
2050 new_sublist
-> fn_field
.physname
= savestring (*pp
, p
- *pp
);
2053 /* Set this member function's visibility fields. */
2056 case VISIBILITY_PRIVATE
:
2057 new_sublist
-> fn_field
.is_private
= 1;
2059 case VISIBILITY_PROTECTED
:
2060 new_sublist
-> fn_field
.is_protected
= 1;
2064 STABS_CONTINUE (pp
);
2067 case 'A': /* Normal functions. */
2068 new_sublist
-> fn_field
.is_const
= 0;
2069 new_sublist
-> fn_field
.is_volatile
= 0;
2072 case 'B': /* `const' member functions. */
2073 new_sublist
-> fn_field
.is_const
= 1;
2074 new_sublist
-> fn_field
.is_volatile
= 0;
2077 case 'C': /* `volatile' member function. */
2078 new_sublist
-> fn_field
.is_const
= 0;
2079 new_sublist
-> fn_field
.is_volatile
= 1;
2082 case 'D': /* `const volatile' member function. */
2083 new_sublist
-> fn_field
.is_const
= 1;
2084 new_sublist
-> fn_field
.is_volatile
= 1;
2087 case '*': /* File compiled with g++ version 1 -- no info */
2092 complain (&const_vol_complaint
, **pp
);
2101 /* virtual member function, followed by index.
2102 The sign bit is set to distinguish pointers-to-methods
2103 from virtual function indicies. Since the array is
2104 in words, the quantity must be shifted left by 1
2105 on 16 bit machine, and by 2 on 32 bit machine, forcing
2106 the sign bit out, and usable as a valid index into
2107 the array. Remove the sign bit here. */
2108 new_sublist
-> fn_field
.voffset
=
2109 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
2113 STABS_CONTINUE (pp
);
2114 if (**pp
== ';' || **pp
== '\0')
2116 /* Must be g++ version 1. */
2117 new_sublist
-> fn_field
.fcontext
= 0;
2121 /* Figure out from whence this virtual function came.
2122 It may belong to virtual function table of
2123 one of its baseclasses. */
2124 look_ahead_type
= read_type (pp
, objfile
);
2127 /* g++ version 1 overloaded methods. */
2131 new_sublist
-> fn_field
.fcontext
= look_ahead_type
;
2140 look_ahead_type
= NULL
;
2146 /* static member function. */
2147 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
2148 if (strncmp (new_sublist
-> fn_field
.physname
,
2149 main_fn_name
, strlen (main_fn_name
)))
2151 new_sublist
-> fn_field
.is_stub
= 1;
2157 complain (&member_fn_complaint
, (*pp
)[-1]);
2158 /* Fall through into normal member function. */
2161 /* normal member function. */
2162 new_sublist
-> fn_field
.voffset
= 0;
2163 new_sublist
-> fn_field
.fcontext
= 0;
2167 new_sublist
-> next
= sublist
;
2168 sublist
= new_sublist
;
2170 STABS_CONTINUE (pp
);
2172 while (**pp
!= ';' && **pp
!= '\0');
2176 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
2177 obstack_alloc (&objfile
-> type_obstack
,
2178 sizeof (struct fn_field
) * length
);
2179 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
2180 sizeof (struct fn_field
) * length
);
2181 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
2183 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
2186 new_fnlist
-> fn_fieldlist
.length
= length
;
2187 new_fnlist
-> next
= fip
-> fnlist
;
2188 fip
-> fnlist
= new_fnlist
;
2190 total_length
+= length
;
2191 STABS_CONTINUE (pp
);
2196 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2197 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2198 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
2199 memset (TYPE_FN_FIELDLISTS (type
), 0,
2200 sizeof (struct fn_fieldlist
) * nfn_fields
);
2201 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2202 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2208 /* Special GNU C++ name.
2210 Returns 1 for success, 0 for failure. "failure" means that we can't
2211 keep parsing and it's time for error_type(). */
2214 read_cpp_abbrev (fip
, pp
, type
, objfile
)
2215 struct field_info
*fip
;
2218 struct objfile
*objfile
;
2223 struct type
*context
;
2233 /* At this point, *pp points to something like "22:23=*22...",
2234 where the type number before the ':' is the "context" and
2235 everything after is a regular type definition. Lookup the
2236 type, find it's name, and construct the field name. */
2238 context
= read_type (pp
, objfile
);
2242 case 'f': /* $vf -- a virtual function table pointer */
2243 fip
->list
->field
.name
=
2244 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
2247 case 'b': /* $vb -- a virtual bsomethingorother */
2248 name
= type_name_no_tag (context
);
2251 complain (&invalid_cpp_type_complaint
, symnum
);
2254 fip
->list
->field
.name
=
2255 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
2259 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2260 fip
->list
->field
.name
=
2261 obconcat (&objfile
->type_obstack
,
2262 "INVALID_CPLUSPLUS_ABBREV", "", "");
2266 /* At this point, *pp points to the ':'. Skip it and read the
2272 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2275 fip
->list
->field
.type
= read_type (pp
, objfile
);
2277 (*pp
)++; /* Skip the comma. */
2283 fip
->list
->field
.bitpos
= read_huge_number (pp
, ';', &nbits
);
2287 /* This field is unpacked. */
2288 fip
->list
->field
.bitsize
= 0;
2289 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
2293 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2294 /* We have no idea what syntax an unrecognized abbrev would have, so
2295 better return 0. If we returned 1, we would need to at least advance
2296 *pp to avoid an infinite loop. */
2303 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
2304 struct field_info
*fip
;
2308 struct objfile
*objfile
;
2310 fip
-> list
-> field
.name
=
2311 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2314 /* This means we have a visibility for a field coming. */
2318 fip
-> list
-> visibility
= *(*pp
)++;
2322 /* normal dbx-style format, no explicit visibility */
2323 fip
-> list
-> visibility
= VISIBILITY_PUBLIC
;
2326 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
2331 /* Possible future hook for nested types. */
2334 fip
-> list
-> field
.bitpos
= (long)-2; /* nested type */
2340 /* Static class member. */
2341 fip
-> list
-> field
.bitpos
= (long) -1;
2347 fip
-> list
-> field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2351 else if (**pp
!= ',')
2353 /* Bad structure-type format. */
2354 complain (&stabs_general_complaint
, "bad structure-type format");
2358 (*pp
)++; /* Skip the comma. */
2362 fip
-> list
-> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2365 complain (&stabs_general_complaint
, "bad structure-type format");
2368 fip
-> list
-> field
.bitsize
= read_huge_number (pp
, ';', &nbits
);
2371 complain (&stabs_general_complaint
, "bad structure-type format");
2376 if (fip
-> list
-> field
.bitpos
== 0 && fip
-> list
-> field
.bitsize
== 0)
2378 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
2379 it is a field which has been optimized out. The correct stab for
2380 this case is to use VISIBILITY_IGNORE, but that is a recent
2381 invention. (2) It is a 0-size array. For example
2382 union { int num; char str[0]; } foo. Printing "<no value>" for
2383 str in "p foo" is OK, since foo.str (and thus foo.str[3])
2384 will continue to work, and a 0-size array as a whole doesn't
2385 have any contents to print.
2387 I suspect this probably could also happen with gcc -gstabs (not
2388 -gstabs+) for static fields, and perhaps other C++ extensions.
2389 Hopefully few people use -gstabs with gdb, since it is intended
2390 for dbx compatibility. */
2392 /* Ignore this field. */
2393 fip
-> list
-> visibility
= VISIBILITY_IGNORE
;
2397 /* Detect an unpacked field and mark it as such.
2398 dbx gives a bit size for all fields.
2399 Note that forward refs cannot be packed,
2400 and treat enums as if they had the width of ints. */
2402 if (TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_INT
2403 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_ENUM
)
2405 fip
-> list
-> field
.bitsize
= 0;
2407 if ((fip
-> list
-> field
.bitsize
2408 == TARGET_CHAR_BIT
* TYPE_LENGTH (fip
-> list
-> field
.type
)
2409 || (TYPE_CODE (fip
-> list
-> field
.type
) == TYPE_CODE_ENUM
2410 && (fip
-> list
-> field
.bitsize
2415 fip
-> list
-> field
.bitpos
% 8 == 0)
2417 fip
-> list
-> field
.bitsize
= 0;
2423 /* Read struct or class data fields. They have the form:
2425 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2427 At the end, we see a semicolon instead of a field.
2429 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2432 The optional VISIBILITY is one of:
2434 '/0' (VISIBILITY_PRIVATE)
2435 '/1' (VISIBILITY_PROTECTED)
2436 '/2' (VISIBILITY_PUBLIC)
2437 '/9' (VISIBILITY_IGNORE)
2439 or nothing, for C style fields with public visibility.
2441 Returns 1 for success, 0 for failure. */
2444 read_struct_fields (fip
, pp
, type
, objfile
)
2445 struct field_info
*fip
;
2448 struct objfile
*objfile
;
2451 struct nextfield
*new;
2453 /* We better set p right now, in case there are no fields at all... */
2457 /* Read each data member type until we find the terminating ';' at the end of
2458 the data member list, or break for some other reason such as finding the
2459 start of the member function list. */
2463 if (os9k_stabs
&& **pp
== ',') break;
2464 STABS_CONTINUE (pp
);
2465 /* Get space to record the next field's data. */
2466 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2467 make_cleanup (free
, new);
2468 memset (new, 0, sizeof (struct nextfield
));
2469 new -> next
= fip
-> list
;
2472 /* Get the field name. */
2475 /* If is starts with CPLUS_MARKER it is a special abbreviation,
2476 unless the CPLUS_MARKER is followed by an underscore, in
2477 which case it is just the name of an anonymous type, which we
2478 should handle like any other type name. We accept either '$'
2479 or '.', because a field name can never contain one of these
2480 characters except as a CPLUS_MARKER (we probably should be
2481 doing that in most parts of GDB). */
2483 if ((*p
== '$' || *p
== '.') && p
[1] != '_')
2485 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
2490 /* Look for the ':' that separates the field name from the field
2491 values. Data members are delimited by a single ':', while member
2492 functions are delimited by a pair of ':'s. When we hit the member
2493 functions (if any), terminate scan loop and return. */
2495 while (*p
!= ':' && *p
!= '\0')
2502 /* Check to see if we have hit the member functions yet. */
2507 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
2509 if (p
[0] == ':' && p
[1] == ':')
2511 /* chill the list of fields: the last entry (at the head) is a
2512 partially constructed entry which we now scrub. */
2513 fip
-> list
= fip
-> list
-> next
;
2518 /* The stabs for C++ derived classes contain baseclass information which
2519 is marked by a '!' character after the total size. This function is
2520 called when we encounter the baseclass marker, and slurps up all the
2521 baseclass information.
2523 Immediately following the '!' marker is the number of base classes that
2524 the class is derived from, followed by information for each base class.
2525 For each base class, there are two visibility specifiers, a bit offset
2526 to the base class information within the derived class, a reference to
2527 the type for the base class, and a terminating semicolon.
2529 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2531 Baseclass information marker __________________|| | | | | | |
2532 Number of baseclasses __________________________| | | | | | |
2533 Visibility specifiers (2) ________________________| | | | | |
2534 Offset in bits from start of class _________________| | | | |
2535 Type number for base class ___________________________| | | |
2536 Visibility specifiers (2) _______________________________| | |
2537 Offset in bits from start of class ________________________| |
2538 Type number of base class ____________________________________|
2540 Return 1 for success, 0 for (error-type-inducing) failure. */
2543 read_baseclasses (fip
, pp
, type
, objfile
)
2544 struct field_info
*fip
;
2547 struct objfile
*objfile
;
2550 struct nextfield
*new;
2558 /* Skip the '!' baseclass information marker. */
2562 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2565 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
2571 /* Some stupid compilers have trouble with the following, so break
2572 it up into simpler expressions. */
2573 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
2574 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
2577 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
2580 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2581 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2585 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
2587 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
2589 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2590 make_cleanup (free
, new);
2591 memset (new, 0, sizeof (struct nextfield
));
2592 new -> next
= fip
-> list
;
2594 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
2596 STABS_CONTINUE (pp
);
2600 /* Nothing to do. */
2603 SET_TYPE_FIELD_VIRTUAL (type
, i
);
2606 /* Unknown character. Complain and treat it as non-virtual. */
2608 static struct complaint msg
= {
2609 "Unknown virtual character `%c' for baseclass", 0, 0};
2610 complain (&msg
, **pp
);
2615 new -> visibility
= *(*pp
)++;
2616 switch (new -> visibility
)
2618 case VISIBILITY_PRIVATE
:
2619 case VISIBILITY_PROTECTED
:
2620 case VISIBILITY_PUBLIC
:
2623 /* Bad visibility format. Complain and treat it as
2626 static struct complaint msg
= {
2627 "Unknown visibility `%c' for baseclass", 0, 0};
2628 complain (&msg
, new -> visibility
);
2629 new -> visibility
= VISIBILITY_PUBLIC
;
2636 /* The remaining value is the bit offset of the portion of the object
2637 corresponding to this baseclass. Always zero in the absence of
2638 multiple inheritance. */
2640 new -> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2645 /* The last piece of baseclass information is the type of the
2646 base class. Read it, and remember it's type name as this
2649 new -> field
.type
= read_type (pp
, objfile
);
2650 new -> field
.name
= type_name_no_tag (new -> field
.type
);
2652 /* skip trailing ';' and bump count of number of fields seen */
2661 /* The tail end of stabs for C++ classes that contain a virtual function
2662 pointer contains a tilde, a %, and a type number.
2663 The type number refers to the base class (possibly this class itself) which
2664 contains the vtable pointer for the current class.
2666 This function is called when we have parsed all the method declarations,
2667 so we can look for the vptr base class info. */
2670 read_tilde_fields (fip
, pp
, type
, objfile
)
2671 struct field_info
*fip
;
2674 struct objfile
*objfile
;
2678 STABS_CONTINUE (pp
);
2680 /* If we are positioned at a ';', then skip it. */
2690 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2692 /* Obsolete flags that used to indicate the presence
2693 of constructors and/or destructors. */
2697 /* Read either a '%' or the final ';'. */
2698 if (*(*pp
)++ == '%')
2700 /* The next number is the type number of the base class
2701 (possibly our own class) which supplies the vtable for
2702 this class. Parse it out, and search that class to find
2703 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
2704 and TYPE_VPTR_FIELDNO. */
2709 t
= read_type (pp
, objfile
);
2711 while (*p
!= '\0' && *p
!= ';')
2717 /* Premature end of symbol. */
2721 TYPE_VPTR_BASETYPE (type
) = t
;
2722 if (type
== t
) /* Our own class provides vtbl ptr */
2724 for (i
= TYPE_NFIELDS (t
) - 1;
2725 i
>= TYPE_N_BASECLASSES (t
);
2728 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2729 sizeof (vptr_name
) - 1))
2731 TYPE_VPTR_FIELDNO (type
) = i
;
2735 /* Virtual function table field not found. */
2736 complain (&vtbl_notfound_complaint
, TYPE_NAME (type
));
2741 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2752 attach_fn_fields_to_type (fip
, type
)
2753 struct field_info
*fip
;
2754 register struct type
*type
;
2758 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2760 if (TYPE_CODE (TYPE_BASECLASS (type
, n
)) == TYPE_CODE_UNDEF
)
2762 /* @@ Memory leak on objfile -> type_obstack? */
2765 TYPE_NFN_FIELDS_TOTAL (type
) +=
2766 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, n
));
2769 for (n
= TYPE_NFN_FIELDS (type
);
2770 fip
-> fnlist
!= NULL
;
2771 fip
-> fnlist
= fip
-> fnlist
-> next
)
2773 --n
; /* Circumvent Sun3 compiler bug */
2774 TYPE_FN_FIELDLISTS (type
)[n
] = fip
-> fnlist
-> fn_fieldlist
;
2779 /* Create the vector of fields, and record how big it is.
2780 We need this info to record proper virtual function table information
2781 for this class's virtual functions. */
2784 attach_fields_to_type (fip
, type
, objfile
)
2785 struct field_info
*fip
;
2786 register struct type
*type
;
2787 struct objfile
*objfile
;
2789 register int nfields
= 0;
2790 register int non_public_fields
= 0;
2791 register struct nextfield
*scan
;
2793 /* Count up the number of fields that we have, as well as taking note of
2794 whether or not there are any non-public fields, which requires us to
2795 allocate and build the private_field_bits and protected_field_bits
2798 for (scan
= fip
-> list
; scan
!= NULL
; scan
= scan
-> next
)
2801 if (scan
-> visibility
!= VISIBILITY_PUBLIC
)
2803 non_public_fields
++;
2807 /* Now we know how many fields there are, and whether or not there are any
2808 non-public fields. Record the field count, allocate space for the
2809 array of fields, and create blank visibility bitfields if necessary. */
2811 TYPE_NFIELDS (type
) = nfields
;
2812 TYPE_FIELDS (type
) = (struct field
*)
2813 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2814 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2816 if (non_public_fields
)
2818 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2820 TYPE_FIELD_PRIVATE_BITS (type
) =
2821 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2822 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2824 TYPE_FIELD_PROTECTED_BITS (type
) =
2825 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2826 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2828 TYPE_FIELD_IGNORE_BITS (type
) =
2829 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2830 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2833 /* Copy the saved-up fields into the field vector. Start from the head
2834 of the list, adding to the tail of the field array, so that they end
2835 up in the same order in the array in which they were added to the list. */
2837 while (nfields
-- > 0)
2839 TYPE_FIELD (type
, nfields
) = fip
-> list
-> field
;
2840 switch (fip
-> list
-> visibility
)
2842 case VISIBILITY_PRIVATE
:
2843 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2846 case VISIBILITY_PROTECTED
:
2847 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2850 case VISIBILITY_IGNORE
:
2851 SET_TYPE_FIELD_IGNORE (type
, nfields
);
2854 case VISIBILITY_PUBLIC
:
2858 /* Unknown visibility. Complain and treat it as public. */
2860 static struct complaint msg
= {
2861 "Unknown visibility `%c' for field", 0, 0};
2862 complain (&msg
, fip
-> list
-> visibility
);
2866 fip
-> list
= fip
-> list
-> next
;
2871 /* Read the description of a structure (or union type) and return an object
2872 describing the type.
2874 PP points to a character pointer that points to the next unconsumed token
2875 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2876 *PP will point to "4a:1,0,32;;".
2878 TYPE points to an incomplete type that needs to be filled in.
2880 OBJFILE points to the current objfile from which the stabs information is
2881 being read. (Note that it is redundant in that TYPE also contains a pointer
2882 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2885 static struct type
*
2886 read_struct_type (pp
, type
, objfile
)
2889 struct objfile
*objfile
;
2891 struct cleanup
*back_to
;
2892 struct field_info fi
;
2897 back_to
= make_cleanup (null_cleanup
, 0);
2899 INIT_CPLUS_SPECIFIC (type
);
2900 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2902 /* First comes the total size in bytes. */
2906 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
2908 return error_type (pp
);
2911 /* Now read the baseclasses, if any, read the regular C struct or C++
2912 class member fields, attach the fields to the type, read the C++
2913 member functions, attach them to the type, and then read any tilde
2914 field (baseclass specifier for the class holding the main vtable). */
2916 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
2917 || !read_struct_fields (&fi
, pp
, type
, objfile
)
2918 || !attach_fields_to_type (&fi
, type
, objfile
)
2919 || !read_member_functions (&fi
, pp
, type
, objfile
)
2920 || !attach_fn_fields_to_type (&fi
, type
)
2921 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
2923 do_cleanups (back_to
);
2924 return (error_type (pp
));
2927 do_cleanups (back_to
);
2931 /* Read a definition of an array type,
2932 and create and return a suitable type object.
2933 Also creates a range type which represents the bounds of that
2936 static struct type
*
2937 read_array_type (pp
, type
, objfile
)
2939 register struct type
*type
;
2940 struct objfile
*objfile
;
2942 struct type
*index_type
, *element_type
, *range_type
;
2947 /* Format of an array type:
2948 "ar<index type>;lower;upper;<array_contents_type>".
2949 OS9000: "arlower,upper;<array_contents_type>".
2951 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2952 for these, produce a type like float[][]. */
2955 index_type
= builtin_type_int
;
2958 index_type
= read_type (pp
, objfile
);
2960 /* Improper format of array type decl. */
2961 return error_type (pp
);
2965 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
2970 lower
= read_huge_number (pp
, os9k_stabs
? ',' : ';', &nbits
);
2972 return error_type (pp
);
2974 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
2979 upper
= read_huge_number (pp
, ';', &nbits
);
2981 return error_type (pp
);
2983 element_type
= read_type (pp
, objfile
);
2992 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
2993 type
= create_array_type (type
, element_type
, range_type
);
2995 /* If we have an array whose element type is not yet known, but whose
2996 bounds *are* known, record it to be adjusted at the end of the file. */
2998 if ((TYPE_FLAGS (element_type
) & TYPE_FLAG_STUB
) && !adjustable
)
3000 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
3001 add_undefined_type (type
);
3008 /* Read a definition of an enumeration type,
3009 and create and return a suitable type object.
3010 Also defines the symbols that represent the values of the type. */
3012 static struct type
*
3013 read_enum_type (pp
, type
, objfile
)
3015 register struct type
*type
;
3016 struct objfile
*objfile
;
3021 register struct symbol
*sym
;
3023 struct pending
**symlist
;
3024 struct pending
*osyms
, *syms
;
3029 /* FIXME! The stabs produced by Sun CC merrily define things that ought
3030 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
3031 to do? For now, force all enum values to file scope. */
3032 if (within_function
)
3033 symlist
= &local_symbols
;
3036 symlist
= &file_symbols
;
3038 o_nsyms
= osyms
? osyms
->nsyms
: 0;
3042 /* Size. Perhaps this does not have to be conditionalized on
3043 os9k_stabs (assuming the name of an enum constant can't start
3045 read_huge_number (pp
, 0, &nbits
);
3047 return error_type (pp
);
3050 /* Read the value-names and their values.
3051 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
3052 A semicolon or comma instead of a NAME means the end. */
3053 while (**pp
&& **pp
!= ';' && **pp
!= ',')
3055 STABS_CONTINUE (pp
);
3057 while (*p
!= ':') p
++;
3058 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
3060 n
= read_huge_number (pp
, ',', &nbits
);
3062 return error_type (pp
);
3064 sym
= (struct symbol
*)
3065 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
3066 memset (sym
, 0, sizeof (struct symbol
));
3067 SYMBOL_NAME (sym
) = name
;
3068 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
3069 SYMBOL_CLASS (sym
) = LOC_CONST
;
3070 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3071 SYMBOL_VALUE (sym
) = n
;
3072 add_symbol_to_list (sym
, symlist
);
3077 (*pp
)++; /* Skip the semicolon. */
3079 /* Now fill in the fields of the type-structure. */
3081 TYPE_LENGTH (type
) = TARGET_INT_BIT
/ HOST_CHAR_BIT
;
3082 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3083 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
3084 TYPE_NFIELDS (type
) = nsyms
;
3085 TYPE_FIELDS (type
) = (struct field
*)
3086 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
3087 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
3089 /* Find the symbols for the values and put them into the type.
3090 The symbols can be found in the symlist that we put them on
3091 to cause them to be defined. osyms contains the old value
3092 of that symlist; everything up to there was defined by us. */
3093 /* Note that we preserve the order of the enum constants, so
3094 that in something like "enum {FOO, LAST_THING=FOO}" we print
3095 FOO, not LAST_THING. */
3097 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
3102 for (; j
< syms
->nsyms
; j
++,n
++)
3104 struct symbol
*xsym
= syms
->symbol
[j
];
3105 SYMBOL_TYPE (xsym
) = type
;
3106 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
3107 TYPE_FIELD_VALUE (type
, n
) = 0;
3108 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
3109 TYPE_FIELD_BITSIZE (type
, n
) = 0;
3118 /* Sun's ACC uses a somewhat saner method for specifying the builtin
3119 typedefs in every file (for int, long, etc):
3121 type = b <signed> <width>; <offset>; <nbits>
3122 signed = u or s. Possible c in addition to u or s (for char?).
3123 offset = offset from high order bit to start bit of type.
3124 width is # bytes in object of this type, nbits is # bits in type.
3126 The width/offset stuff appears to be for small objects stored in
3127 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
3130 static struct type
*
3131 read_sun_builtin_type (pp
, typenums
, objfile
)
3134 struct objfile
*objfile
;
3149 return error_type (pp
);
3153 /* For some odd reason, all forms of char put a c here. This is strange
3154 because no other type has this honor. We can safely ignore this because
3155 we actually determine 'char'acterness by the number of bits specified in
3161 /* The first number appears to be the number of bytes occupied
3162 by this type, except that unsigned short is 4 instead of 2.
3163 Since this information is redundant with the third number,
3164 we will ignore it. */
3165 read_huge_number (pp
, ';', &nbits
);
3167 return error_type (pp
);
3169 /* The second number is always 0, so ignore it too. */
3170 read_huge_number (pp
, ';', &nbits
);
3172 return error_type (pp
);
3174 /* The third number is the number of bits for this type. */
3175 type_bits
= read_huge_number (pp
, 0, &nbits
);
3177 return error_type (pp
);
3178 /* The type *should* end with a semicolon. If it are embedded
3179 in a larger type the semicolon may be the only way to know where
3180 the type ends. If this type is at the end of the stabstring we
3181 can deal with the omitted semicolon (but we don't have to like
3182 it). Don't bother to complain(), Sun's compiler omits the semicolon
3188 return init_type (TYPE_CODE_VOID
, 1,
3189 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3192 return init_type (TYPE_CODE_INT
,
3193 type_bits
/ TARGET_CHAR_BIT
,
3194 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3198 static struct type
*
3199 read_sun_floating_type (pp
, typenums
, objfile
)
3202 struct objfile
*objfile
;
3208 /* The first number has more details about the type, for example
3210 details
= read_huge_number (pp
, ';', &nbits
);
3212 return error_type (pp
);
3214 /* The second number is the number of bytes occupied by this type */
3215 nbytes
= read_huge_number (pp
, ';', &nbits
);
3217 return error_type (pp
);
3219 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
3220 || details
== NF_COMPLEX32
)
3221 /* This is a type we can't handle, but we do know the size.
3222 We also will be able to give it a name. */
3223 return init_type (TYPE_CODE_ERROR
, nbytes
, 0, NULL
, objfile
);
3225 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
3228 /* Read a number from the string pointed to by *PP.
3229 The value of *PP is advanced over the number.
3230 If END is nonzero, the character that ends the
3231 number must match END, or an error happens;
3232 and that character is skipped if it does match.
3233 If END is zero, *PP is left pointing to that character.
3235 If the number fits in a long, set *BITS to 0 and return the value.
3236 If not, set *BITS to be the number of bits in the number and return 0.
3238 If encounter garbage, set *BITS to -1 and return 0. */
3241 read_huge_number (pp
, end
, bits
)
3261 /* Leading zero means octal. GCC uses this to output values larger
3262 than an int (because that would be hard in decimal). */
3270 upper_limit
= ULONG_MAX
/ radix
;
3272 upper_limit
= LONG_MAX
/ radix
;
3274 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
3276 if (n
<= upper_limit
)
3279 n
+= c
- '0'; /* FIXME this overflows anyway */
3284 /* This depends on large values being output in octal, which is
3291 /* Ignore leading zeroes. */
3295 else if (c
== '2' || c
== '3')
3321 /* Large decimal constants are an error (because it is hard to
3322 count how many bits are in them). */
3328 /* -0x7f is the same as 0x80. So deal with it by adding one to
3329 the number of bits. */
3341 /* It's *BITS which has the interesting information. */
3345 static struct type
*
3346 read_range_type (pp
, typenums
, objfile
)
3349 struct objfile
*objfile
;
3355 struct type
*result_type
;
3356 struct type
*index_type
;
3358 /* First comes a type we are a subrange of.
3359 In C it is usually 0, 1 or the type being defined. */
3360 /* FIXME: according to stabs.texinfo and AIX doc, this can be a type-id
3361 not just a type number. */
3362 if (read_type_number (pp
, rangenums
) != 0)
3363 return error_type (pp
);
3364 self_subrange
= (rangenums
[0] == typenums
[0] &&
3365 rangenums
[1] == typenums
[1]);
3367 /* A semicolon should now follow; skip it. */
3371 /* The remaining two operands are usually lower and upper bounds
3372 of the range. But in some special cases they mean something else. */
3373 n2
= read_huge_number (pp
, ';', &n2bits
);
3374 n3
= read_huge_number (pp
, ';', &n3bits
);
3376 if (n2bits
== -1 || n3bits
== -1)
3377 return error_type (pp
);
3379 /* If limits are huge, must be large integral type. */
3380 if (n2bits
!= 0 || n3bits
!= 0)
3382 char got_signed
= 0;
3383 char got_unsigned
= 0;
3384 /* Number of bits in the type. */
3387 /* Range from 0 to <large number> is an unsigned large integral type. */
3388 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
3393 /* Range from <large number> to <large number>-1 is a large signed
3394 integral type. Take care of the case where <large number> doesn't
3395 fit in a long but <large number>-1 does. */
3396 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
3397 || (n2bits
!= 0 && n3bits
== 0
3398 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
3405 if (got_signed
|| got_unsigned
)
3407 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
3408 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
3412 return error_type (pp
);
3415 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3416 if (self_subrange
&& n2
== 0 && n3
== 0)
3417 return init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
3419 /* If n3 is zero and n2 is not, we want a floating type,
3420 and n2 is the width in bytes.
3422 Fortran programs appear to use this for complex types also,
3423 and they give no way to distinguish between double and single-complex!
3425 GDB does not have complex types.
3427 Just return the complex as a float of that size. It won't work right
3428 for the complex values, but at least it makes the file loadable. */
3430 if (n3
== 0 && n2
> 0)
3432 return init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
3435 /* If the upper bound is -1, it must really be an unsigned int. */
3437 else if (n2
== 0 && n3
== -1)
3439 /* It is unsigned int or unsigned long. */
3440 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
3441 compatibility hack. */
3442 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3443 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3446 /* Special case: char is defined (Who knows why) as a subrange of
3447 itself with range 0-127. */
3448 else if (self_subrange
&& n2
== 0 && n3
== 127)
3449 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3451 /* We used to do this only for subrange of self or subrange of int. */
3455 /* n3 actually gives the size. */
3456 return init_type (TYPE_CODE_INT
, - n3
, TYPE_FLAG_UNSIGNED
,
3459 return init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3461 return init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3463 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
3464 "unsigned long", and we already checked for that,
3465 so don't need to test for it here. */
3467 /* I think this is for Convex "long long". Since I don't know whether
3468 Convex sets self_subrange, I also accept that particular size regardless
3469 of self_subrange. */
3470 else if (n3
== 0 && n2
< 0
3472 || n2
== - TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
3473 return init_type (TYPE_CODE_INT
, - n2
, 0, NULL
, objfile
);
3474 else if (n2
== -n3
-1)
3477 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3479 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
3480 if (n3
== 0x7fffffff)
3481 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
3484 /* We have a real range type on our hands. Allocate space and
3485 return a real pointer. */
3487 /* At this point I don't have the faintest idea how to deal with
3488 a self_subrange type; I'm going to assume that this is used
3489 as an idiom, and that all of them are special cases. So . . . */
3491 return error_type (pp
);
3493 index_type
= *dbx_lookup_type (rangenums
);
3494 if (index_type
== NULL
)
3496 /* Does this actually ever happen? Is that why we are worrying
3497 about dealing with it rather than just calling error_type? */
3499 static struct type
*range_type_index
;
3501 complain (&range_type_base_complaint
, rangenums
[1]);
3502 if (range_type_index
== NULL
)
3504 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3505 0, "range type index type", NULL
);
3506 index_type
= range_type_index
;
3509 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
3510 return (result_type
);
3513 /* Read in an argument list. This is a list of types, separated by commas
3514 and terminated with END. Return the list of types read in, or (struct type
3515 **)-1 if there is an error. */
3517 static struct type
**
3518 read_args (pp
, end
, objfile
)
3521 struct objfile
*objfile
;
3523 /* FIXME! Remove this arbitrary limit! */
3524 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3530 /* Invalid argument list: no ','. */
3531 return (struct type
**)-1;
3533 STABS_CONTINUE (pp
);
3534 types
[n
++] = read_type (pp
, objfile
);
3536 (*pp
)++; /* get past `end' (the ':' character) */
3540 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3542 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3544 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3545 memset (rval
+ n
, 0, sizeof (struct type
*));
3549 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3551 memcpy (rval
, types
, n
* sizeof (struct type
*));
3555 /* Common block handling. */
3557 /* List of symbols declared since the last BCOMM. This list is a tail
3558 of local_symbols. When ECOMM is seen, the symbols on the list
3559 are noted so their proper addresses can be filled in later,
3560 using the common block base address gotten from the assembler
3563 static struct pending
*common_block
;
3564 static int common_block_i
;
3566 /* Name of the current common block. We get it from the BCOMM instead of the
3567 ECOMM to match IBM documentation (even though IBM puts the name both places
3568 like everyone else). */
3569 static char *common_block_name
;
3571 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
3572 to remain after this function returns. */
3575 common_block_start (name
, objfile
)
3577 struct objfile
*objfile
;
3579 if (common_block_name
!= NULL
)
3581 static struct complaint msg
= {
3582 "Invalid symbol data: common block within common block",
3586 common_block
= local_symbols
;
3587 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
3588 common_block_name
= obsavestring (name
, strlen (name
),
3589 &objfile
-> symbol_obstack
);
3592 /* Process a N_ECOMM symbol. */
3595 common_block_end (objfile
)
3596 struct objfile
*objfile
;
3598 /* Symbols declared since the BCOMM are to have the common block
3599 start address added in when we know it. common_block and
3600 common_block_i point to the first symbol after the BCOMM in
3601 the local_symbols list; copy the list and hang it off the
3602 symbol for the common block name for later fixup. */
3605 struct pending
*new = 0;
3606 struct pending
*next
;
3609 if (common_block_name
== NULL
)
3611 static struct complaint msg
= {"ECOMM symbol unmatched by BCOMM", 0, 0};
3616 sym
= (struct symbol
*)
3617 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
3618 memset (sym
, 0, sizeof (struct symbol
));
3619 SYMBOL_NAME (sym
) = common_block_name
;
3620 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
3622 /* Now we copy all the symbols which have been defined since the BCOMM. */
3624 /* Copy all the struct pendings before common_block. */
3625 for (next
= local_symbols
;
3626 next
!= NULL
&& next
!= common_block
;
3629 for (j
= 0; j
< next
->nsyms
; j
++)
3630 add_symbol_to_list (next
->symbol
[j
], &new);
3633 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
3634 NULL, it means copy all the local symbols (which we already did
3637 if (common_block
!= NULL
)
3638 for (j
= common_block_i
; j
< common_block
->nsyms
; j
++)
3639 add_symbol_to_list (common_block
->symbol
[j
], &new);
3641 SYMBOL_TYPE (sym
) = (struct type
*) new;
3643 /* Should we be putting local_symbols back to what it was?
3646 i
= hashname (SYMBOL_NAME (sym
));
3647 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
3648 global_sym_chain
[i
] = sym
;
3649 common_block_name
= NULL
;
3652 /* Add a common block's start address to the offset of each symbol
3653 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3654 the common block name). */
3657 fix_common_block (sym
, valu
)
3661 struct pending
*next
= (struct pending
*) SYMBOL_TYPE (sym
);
3662 for ( ; next
; next
= next
->next
)
3665 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3666 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3672 /* What about types defined as forward references inside of a small lexical
3674 /* Add a type to the list of undefined types to be checked through
3675 once this file has been read in. */
3678 add_undefined_type (type
)
3681 if (undef_types_length
== undef_types_allocated
)
3683 undef_types_allocated
*= 2;
3684 undef_types
= (struct type
**)
3685 xrealloc ((char *) undef_types
,
3686 undef_types_allocated
* sizeof (struct type
*));
3688 undef_types
[undef_types_length
++] = type
;
3691 /* Go through each undefined type, see if it's still undefined, and fix it
3692 up if possible. We have two kinds of undefined types:
3694 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3695 Fix: update array length using the element bounds
3696 and the target type's length.
3697 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3698 yet defined at the time a pointer to it was made.
3699 Fix: Do a full lookup on the struct/union tag. */
3701 cleanup_undefined_types ()
3705 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
3707 switch (TYPE_CODE (*type
))
3710 case TYPE_CODE_STRUCT
:
3711 case TYPE_CODE_UNION
:
3712 case TYPE_CODE_ENUM
:
3714 /* Check if it has been defined since. Need to do this here
3715 as well as in check_stub_type to deal with the (legitimate in
3716 C though not C++) case of several types with the same name
3717 in different source files. */
3718 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
3720 struct pending
*ppt
;
3722 /* Name of the type, without "struct" or "union" */
3723 char *typename
= TYPE_TAG_NAME (*type
);
3725 if (typename
== NULL
)
3727 static struct complaint msg
= {"need a type name", 0, 0};
3731 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
3733 for (i
= 0; i
< ppt
->nsyms
; i
++)
3735 struct symbol
*sym
= ppt
->symbol
[i
];
3737 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3738 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
3739 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
3741 && STREQ (SYMBOL_NAME (sym
), typename
))
3743 memcpy (*type
, SYMBOL_TYPE (sym
),
3744 sizeof (struct type
));
3752 case TYPE_CODE_ARRAY
:
3754 /* This is a kludge which is here for historical reasons
3755 because I suspect that check_stub_type does not get
3756 called everywhere it needs to be called for arrays. Even
3757 with this kludge, those places are broken for the case
3758 where the stub type is defined in another compilation
3759 unit, but this kludge at least deals with it for the case
3760 in which it is the same compilation unit.
3762 Don't try to do this by calling check_stub_type; it might
3763 cause symbols to be read in lookup_symbol, and the symbol
3764 reader is not reentrant. */
3766 struct type
*range_type
;
3769 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
3771 if (TYPE_NFIELDS (*type
) != 1)
3773 range_type
= TYPE_FIELD_TYPE (*type
, 0);
3774 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
3777 /* Now recompute the length of the array type, based on its
3778 number of elements and the target type's length. */
3779 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
3780 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
3781 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
3782 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
3784 /* If the target type is not a stub, we could be clearing
3785 TYPE_FLAG_TARGET_STUB for *type. */
3792 static struct complaint msg
= {"\
3793 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
3794 complain (&msg
, TYPE_CODE (*type
));
3800 undef_types_length
= 0;
3803 /* Scan through all of the global symbols defined in the object file,
3804 assigning values to the debugging symbols that need to be assigned
3805 to. Get these symbols from the minimal symbol table. */
3808 scan_file_globals (objfile
)
3809 struct objfile
*objfile
;
3812 struct minimal_symbol
*msymbol
;
3813 struct symbol
*sym
, *prev
;
3815 if (objfile
->msymbols
== 0) /* Beware the null file. */
3818 for (msymbol
= objfile
-> msymbols
; SYMBOL_NAME (msymbol
) != NULL
; msymbol
++)
3822 /* Skip static symbols. */
3823 switch (MSYMBOL_TYPE (msymbol
))
3833 /* Get the hash index and check all the symbols
3834 under that hash index. */
3836 hash
= hashname (SYMBOL_NAME (msymbol
));
3838 for (sym
= global_sym_chain
[hash
]; sym
;)
3840 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
3841 STREQ(SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
3843 /* Splice this symbol out of the hash chain and
3844 assign the value we have to it. */
3847 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
3851 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
3854 /* Check to see whether we need to fix up a common block. */
3855 /* Note: this code might be executed several times for
3856 the same symbol if there are multiple references. */
3858 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3860 fix_common_block (sym
, SYMBOL_VALUE_ADDRESS (msymbol
));
3864 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msymbol
);
3867 SYMBOL_SECTION (sym
) = SYMBOL_SECTION (msymbol
);
3871 sym
= SYMBOL_VALUE_CHAIN (prev
);
3875 sym
= global_sym_chain
[hash
];
3881 sym
= SYMBOL_VALUE_CHAIN (sym
);
3887 /* Initialize anything that needs initializing when starting to read
3888 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
3896 /* Initialize anything that needs initializing when a completely new
3897 symbol file is specified (not just adding some symbols from another
3898 file, e.g. a shared library). */
3901 stabsread_new_init ()
3903 /* Empty the hash table of global syms looking for values. */
3904 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
3907 /* Initialize anything that needs initializing at the same time as
3908 start_symtab() is called. */
3912 global_stabs
= NULL
; /* AIX COFF */
3913 /* Leave FILENUM of 0 free for builtin types and this file's types. */
3914 n_this_object_header_files
= 1;
3915 type_vector_length
= 0;
3916 type_vector
= (struct type
**) 0;
3918 /* FIXME: If common_block_name is not already NULL, we should complain(). */
3919 common_block_name
= NULL
;
3924 /* Call after end_symtab() */
3930 free ((char *) type_vector
);
3933 type_vector_length
= 0;
3934 previous_stab_code
= 0;
3938 finish_global_stabs (objfile
)
3939 struct objfile
*objfile
;
3943 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
3944 free ((PTR
) global_stabs
);
3945 global_stabs
= NULL
;
3949 /* Initializer for this module */
3952 _initialize_stabsread ()
3954 undef_types_allocated
= 20;
3955 undef_types_length
= 0;
3956 undef_types
= (struct type
**)
3957 xmalloc (undef_types_allocated
* sizeof (struct type
*));